diff --git a/core/i18n/package.json b/core/i18n/package.json index 226d37b2f..5287a957b 100644 --- a/core/i18n/package.json +++ b/core/i18n/package.json @@ -36,5 +36,8 @@ "@alwatr/logger": "^0.27.0", "@alwatr/signal": "^0.27.0", "tslib": "^2.4.1" + }, + "devDependencies": { + "@alwatr/type": "^0.27.0" } } diff --git a/core/i18n/src/i18n.ts b/core/i18n/src/i18n.ts index b0a6d99a2..a74b9789b 100644 --- a/core/i18n/src/i18n.ts +++ b/core/i18n/src/i18n.ts @@ -4,6 +4,8 @@ import {SignalInterface} from '@alwatr/signal'; import type {I18nConfig, L10Resource, Locale} from './type.js'; +export * from './type.js'; + const logger = createLogger('alwatr/i18n'); globalAlwatr.registeredList.push({ diff --git a/core/i18n/src/type.ts b/core/i18n/src/type.ts index b61e33c15..04c8a6f61 100644 --- a/core/i18n/src/type.ts +++ b/core/i18n/src/type.ts @@ -1,3 +1,7 @@ +import type {L10Resource, Locale} from '@alwatr/type'; + +export {L10Resource, Locale}; + declare global { interface AlwatrSignals { 'locale-change': Locale; @@ -9,29 +13,6 @@ declare global { } } -export type LocalCode = `${Lowercase}-${Uppercase}`; - -export type L10Resource = Record & { - _code: LocalCode; -}; - -export type Locale = { - /** - * fa-IR, en-US, ... - */ - code: LocalCode; - - /** - * fa, en, ... - */ - language: Lowercase; - - /** - * ltr, rtl - */ - direction: 'rtl' | 'ltr'; -}; - export type I18nConfig = { /** * Automatically fetch the localization resource from `resourcePath/localCode.json`. diff --git a/core/i18n/tsconfig.json b/core/i18n/tsconfig.json index 891f4a867..3ed144cb7 100644 --- a/core/i18n/tsconfig.json +++ b/core/i18n/tsconfig.json @@ -10,6 +10,7 @@ "include": ["src/**/*.ts"], "exclude": [], "references": [ + {"path": "../type"}, {"path": "../logger"}, {"path": "../signal"}, {"path": "../fetch"} diff --git a/core/type/src/customer-order-management.ts b/core/type/src/customer-order-management.ts new file mode 100644 index 000000000..cd69744f4 --- /dev/null +++ b/core/type/src/customer-order-management.ts @@ -0,0 +1,82 @@ +import {i18nString} from './i18n.js'; +import {Photo} from './photo.js'; + +import type {AlwatrDocumentObject} from './storage.js'; + +export type Product = AlwatrDocumentObject & { + /** + * Product global ID + * + * like product unique code + */ + id: string; + + /** + * Product title + */ + title: i18nString; + + /** + * Product image + */ + image: Photo; +}; + +export type ProductPrice = AlwatrDocumentObject & { + /** + * Displayed price before discount + */ + price: number; + + /** + * Final price after any discount + */ + finalPrice: number; +} + +export type Order = AlwatrDocumentObject & { + /** + * Order unique code + * + * customerId-orderId + */ + id: `${number}-${number}`; + + /** + * Products list with price and qty + */ + itemList: Array; + + /** + * Delivery info + */ + delivery: OrderDelivery; + + discount: number; + discountType: typeof discountTypeCS[number]; + + totalPrice: number; + shippingPrice: number; + finalPrice: number; +}; + +// FIXME: name and values +export const shipmentTypeCS = ['x', 'y'] as const; +export const carTypeCS = ['x', 'y'] as const; +export const timePeriodCS = ['1-2w', '2-3w', '3-4w'] as const; +export const discountTypeCS = ['number', 'percent'] as const; + +export type OrderDelivery = { + recipientName: string; + recipientNationalCode: string; + address: string; + shipmentType: typeof shipmentTypeCS[number]; + carType: typeof carTypeCS[number]; + timePeriod: typeof timePeriodCS[number]; +} + +export type OrderItem = { + productId: string; + price: ProductPrice; + qty: number; +}; diff --git a/core/type/src/i18n.ts b/core/type/src/i18n.ts new file mode 100644 index 000000000..fc28fee3e --- /dev/null +++ b/core/type/src/i18n.ts @@ -0,0 +1,29 @@ +export type LocalCode = `${Lowercase}-${Uppercase}`; + +export type L10Resource = Record & { + _code: LocalCode; +}; + +export type Locale = { + /** + * fa-IR, en-US, ... + */ + code: LocalCode; + + /** + * fa, en, ... + */ + language: Lowercase; + + /** + * ltr, rtl + */ + direction: 'rtl' | 'ltr'; +}; + +/** + * Multi language string + * + * {fa: 'سلام', en: 'hello'} + */ +export type i18nString = Record, string>; diff --git a/core/type/src/index.ts b/core/type/src/index.ts index 8d17fadec..96a3e6360 100644 --- a/core/type/src/index.ts +++ b/core/type/src/index.ts @@ -2,6 +2,7 @@ export * from './chat.js'; export * from './service-response.js'; export * from './storage.js'; export * from './global.js'; +export * from './i18n.js'; export * from './type-helper.js'; Alwatr.registeredList.push({ diff --git a/core/type/src/photo.ts b/core/type/src/photo.ts new file mode 100644 index 000000000..d32b26ebb --- /dev/null +++ b/core/type/src/photo.ts @@ -0,0 +1,15 @@ +import {AlwatrDocumentObject} from './storage.js'; + +export type Photo = AlwatrDocumentObject & { + /** + * Primary Photo ID + * + * like full relative path (include extension) to image CDN (temporary) + */ + id: string; // path/file-name.png + + /** + * Photo extra meta information for future maintenances + */ + meta: Record; // meta: {order: 1233, customer: 1334} +} diff --git a/core/type/src/storage.ts b/core/type/src/storage.ts index 7a6589bbc..744972763 100644 --- a/core/type/src/storage.ts +++ b/core/type/src/storage.ts @@ -9,7 +9,7 @@ export type AlwatrDocumentObject = { }; }; -export type AlwatrDocumentMeta = { +export type AlwatrStorageMeta = { formatVersion: number; reversion: number; lastUpdated: number; @@ -17,6 +17,6 @@ export type AlwatrDocumentMeta = { }; export type AlwatrDocumentStorage = Omit< - AlwatrServiceResponseSuccessWithMeta, AlwatrDocumentMeta>, + AlwatrServiceResponseSuccessWithMeta, AlwatrStorageMeta>, 'statusCode' | 'errorCode' >; diff --git a/core/type/src/user.ts b/core/type/src/user.ts new file mode 100644 index 000000000..cb53e0703 --- /dev/null +++ b/core/type/src/user.ts @@ -0,0 +1,21 @@ +import type {AlwatrDocumentObject} from './storage.js'; + +export const genderCS = ['male', 'female'] as const; +export type Gender = typeof genderCS[number]; + +export type User = AlwatrDocumentObject & { + /** + * User global unique id (verifiable) + */ + id: string; + + /** + * User full name + */ + fullName: string; + + gender?: Gender; + + email?: string; + phoneNumber?: string; +};