@aghamdi/shared-types 0.2.16 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -26,12 +26,39 @@ interface TopicNotification extends Notification {
26
26
  interface SmsNotification extends Notification {
27
27
  mobile: string;
28
28
  }
29
+ interface PrintLine {
30
+ text: string;
31
+ alignment: 'left' | 'center' | 'right';
32
+ size: 'normal' | 'large' | 'small';
33
+ weight: 'normal' | 'bold';
34
+ }
35
+ interface OperateOrderNotificationPayload {
36
+ orderId: string;
37
+ serveTo: string | null;
38
+ items: Array<{
39
+ name: string;
40
+ quantity: number;
41
+ price: number;
42
+ description: string | null;
43
+ }>;
44
+ notes: string | null;
45
+ lines: PrintLine[];
46
+ }
47
+ interface OperateOrderNotification {
48
+ brandId: string;
49
+ branchId: string;
50
+ title: string;
51
+ body: string;
52
+ order: OperateOrderNotificationPayload;
53
+ }
29
54
  declare class MiaNotifications {
30
55
  static sendtoDevice(message: DeviceNotification): Promise<void>;
31
56
  static sendtoUserDevices(message: UserNotification): Promise<void>;
32
57
  static sendtoTopic(message: TopicNotification): Promise<void>;
33
58
  static sendtoSms(message: SmsNotification): Promise<void>;
59
+ static sendOperateOrderNotification(message: OperateOrderNotification): Promise<void>;
34
60
  static topicFormatter: (topic: string) => string;
61
+ static operateOrderTopicFormatter: (brandId: string, branchId: string) => string;
35
62
  }
36
63
 
37
64
  declare class MessagingBus {
@@ -222,4 +249,4 @@ declare function validateSelectedAttributes(selected: OrderItemAttributes, defin
222
249
  errors: string[];
223
250
  };
224
251
 
225
- export { type AttributeValue, type CustomerActionMessage, type CustomerAddTagMessage, type CustomerMobileVerifiedMessage, type CustomerUpdateNotesMessage, type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, MicrogemsCustomer, type MultilanguageString, type Notification, type OrderAttribute, type OrderItemAttributes, type SelectedOrderAttribute, type SmsNotification, type TopicNotification, type UserNotification, calculateAttributesPrice, createMultilanguageString, getLocalizedText, validateSelectedAttributes };
252
+ export { type AttributeValue, type CustomerActionMessage, type CustomerAddTagMessage, type CustomerMobileVerifiedMessage, type CustomerUpdateNotesMessage, type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, MicrogemsCustomer, type MultilanguageString, type Notification, type OperateOrderNotification, type OperateOrderNotificationPayload, type OrderAttribute, type OrderItemAttributes, type PrintLine, type SelectedOrderAttribute, type SmsNotification, type TopicNotification, type UserNotification, calculateAttributesPrice, createMultilanguageString, getLocalizedText, validateSelectedAttributes };
package/dist/index.d.ts CHANGED
@@ -26,12 +26,39 @@ interface TopicNotification extends Notification {
26
26
  interface SmsNotification extends Notification {
27
27
  mobile: string;
28
28
  }
29
+ interface PrintLine {
30
+ text: string;
31
+ alignment: 'left' | 'center' | 'right';
32
+ size: 'normal' | 'large' | 'small';
33
+ weight: 'normal' | 'bold';
34
+ }
35
+ interface OperateOrderNotificationPayload {
36
+ orderId: string;
37
+ serveTo: string | null;
38
+ items: Array<{
39
+ name: string;
40
+ quantity: number;
41
+ price: number;
42
+ description: string | null;
43
+ }>;
44
+ notes: string | null;
45
+ lines: PrintLine[];
46
+ }
47
+ interface OperateOrderNotification {
48
+ brandId: string;
49
+ branchId: string;
50
+ title: string;
51
+ body: string;
52
+ order: OperateOrderNotificationPayload;
53
+ }
29
54
  declare class MiaNotifications {
30
55
  static sendtoDevice(message: DeviceNotification): Promise<void>;
31
56
  static sendtoUserDevices(message: UserNotification): Promise<void>;
32
57
  static sendtoTopic(message: TopicNotification): Promise<void>;
33
58
  static sendtoSms(message: SmsNotification): Promise<void>;
59
+ static sendOperateOrderNotification(message: OperateOrderNotification): Promise<void>;
34
60
  static topicFormatter: (topic: string) => string;
61
+ static operateOrderTopicFormatter: (brandId: string, branchId: string) => string;
35
62
  }
36
63
 
37
64
  declare class MessagingBus {
@@ -222,4 +249,4 @@ declare function validateSelectedAttributes(selected: OrderItemAttributes, defin
222
249
  errors: string[];
223
250
  };
224
251
 
225
- export { type AttributeValue, type CustomerActionMessage, type CustomerAddTagMessage, type CustomerMobileVerifiedMessage, type CustomerUpdateNotesMessage, type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, MicrogemsCustomer, type MultilanguageString, type Notification, type OrderAttribute, type OrderItemAttributes, type SelectedOrderAttribute, type SmsNotification, type TopicNotification, type UserNotification, calculateAttributesPrice, createMultilanguageString, getLocalizedText, validateSelectedAttributes };
252
+ export { type AttributeValue, type CustomerActionMessage, type CustomerAddTagMessage, type CustomerMobileVerifiedMessage, type CustomerUpdateNotesMessage, type DeviceNotification, MessagingBus, MiaNotifications, MiaServerResponse, MicrogemsCustomer, type MultilanguageString, type Notification, type OperateOrderNotification, type OperateOrderNotificationPayload, type OrderAttribute, type OrderItemAttributes, type PrintLine, type SelectedOrderAttribute, type SmsNotification, type TopicNotification, type UserNotification, calculateAttributesPrice, createMultilanguageString, getLocalizedText, validateSelectedAttributes };
package/dist/index.js CHANGED
@@ -1,11 +1,28 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
10
  var __knownSymbol = (name, symbol) => {
7
11
  return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
12
  };
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9
26
  var __export = (target, all) => {
10
27
  for (var name in all)
11
28
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -151,8 +168,16 @@ var MiaNotifications = class {
151
168
  yield MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || "general"}`, message);
152
169
  });
153
170
  }
171
+ static sendOperateOrderNotification(message) {
172
+ return __async(this, null, function* () {
173
+ yield MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || "general"}`, __spreadProps(__spreadValues({}, message), {
174
+ type: "operateOrder"
175
+ }));
176
+ });
177
+ }
154
178
  };
155
179
  MiaNotifications.topicFormatter = (topic) => "/topics/" + topic.replace(/\//g, "~");
180
+ MiaNotifications.operateOrderTopicFormatter = (brandId, branchId) => `~operate~orders~${brandId}~${branchId}`;
156
181
 
157
182
  // src/customers.ts
158
183
  var MicrogemsCustomer = class {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts","../src/customers.ts","../src/multilanguage.ts","../src/order-attributes.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'\nexport * from './messaging-bus'\nexport * from './customers'\nexport * from './multilanguage'\nexport * from './order-attributes'\n","export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\nexport interface SmsNotification extends Notification {\n mobile: string,\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\n}","import { MessagingBus } from \"./messaging-bus\";\n\nexport interface CustomerMobileVerifiedMessage {\n brandId: string;\n customer: any;\n isVerified: boolean;\n}\n\nexport interface CustomerActionMessage {\n brandId: string;\n type: string;\n customer: any;\n payload: any;\n}\n\nexport interface CustomerAddTagMessage {\n brandId: string;\n customer: any;\n tag: string;\n remove: boolean;\n}\n\nexport interface CustomerUpdateNotesMessage {\n brandId: string;\n customer: any;\n newNotes: string;\n}\n\nexport class MicrogemsCustomer {\n static async mobileVerified(message: CustomerMobileVerifiedMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async action(message: CustomerActionMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async addTag(message: CustomerAddTagMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async updateNotes(message: CustomerUpdateNotesMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n}","/**\n * Multilanguage String Type\n *\n * Represents text content that can be displayed in multiple languages.\n * Used across services for internationalization support.\n */\n\nexport interface MultilanguageString {\n /**\n * English text (required)\n */\n en: string;\n\n /**\n * Arabic text (optional)\n */\n ar?: string;\n}\n\n/**\n * Helper function to get text in preferred language with fallback\n *\n * @param text - Multilanguage string object\n * @param language - Preferred language ('en' | 'ar')\n * @returns Text in preferred language, or English if not available\n */\nexport function getLocalizedText(\n text: MultilanguageString,\n language: 'en' | 'ar' = 'en'\n): string {\n if (language === 'ar' && text.ar) {\n return text.ar;\n }\n return text.en;\n}\n\n/**\n * Helper function to create a multilanguage string from a plain string\n *\n * @param enText - English text\n * @param arText - Optional Arabic text\n * @returns MultilanguageString object\n */\nexport function createMultilanguageString(\n enText: string,\n arText?: string\n): MultilanguageString {\n const result: MultilanguageString = { en: enText };\n if (arText) {\n result.ar = arText;\n }\n return result;\n}\n","/**\n * Order Item Attributes\n *\n * Shared types for order item customization attributes used across:\n * - menu API (for menu item attributes)\n * - schedule API (for appointment service attributes)\n * - transactions API (for order item attributes)\n */\n\n/**\n * Single attribute value option\n */\nexport interface AttributeValue {\n /**\n * Unique identifier for this value option\n */\n id: string;\n\n /**\n * Display name of the value\n */\n name: string;\n\n /**\n * Additional price for selecting this value (0 if no extra cost)\n */\n price: number;\n\n /**\n * Whether this value is available/in-stock\n */\n isAvailable?: boolean;\n}\n\n/**\n * Attribute definition (e.g., \"Size\", \"Color\", \"Extras\")\n */\nexport interface OrderAttribute {\n /**\n * Unique identifier for this attribute\n */\n id: string;\n\n /**\n * Attribute name (e.g., \"Size\", \"Toppings\")\n */\n name: string;\n\n /**\n * Available values for this attribute\n */\n values: AttributeValue[];\n\n /**\n * Whether customer must select a value for this attribute\n */\n required?: boolean;\n\n /**\n * Allow multiple values to be selected (e.g., multiple toppings)\n */\n allowMultiple?: boolean;\n\n /**\n * Minimum number of selections (if allowMultiple = true)\n */\n minSelections?: number;\n\n /**\n * Maximum number of selections (if allowMultiple = true)\n */\n maxSelections?: number;\n}\n\n/**\n * Selected attribute for an order item\n * (What the customer actually selected)\n */\nexport interface SelectedOrderAttribute {\n /**\n * Reference to the attribute definition\n */\n attributeId: string;\n\n /**\n * Attribute name (denormalized for display)\n */\n attributeName: string;\n\n /**\n * Selected value(s)\n */\n selectedValues: {\n /**\n * Value ID\n */\n id: string;\n\n /**\n * Value name (denormalized for display)\n */\n name: string;\n\n /**\n * Price of this selected value\n */\n price: number;\n }[];\n\n /**\n * Total price for this attribute (sum of all selected values)\n */\n totalPrice: number;\n}\n\n/**\n * Array of selected attributes for an order item\n * This is what gets stored in Appointment.orderItemAttributes or Order.items[].attributes\n */\nexport type OrderItemAttributes = SelectedOrderAttribute[];\n\n/**\n * Helper function to calculate total price from selected attributes\n *\n * @param attributes - Array of selected attributes\n * @returns Total additional price from all attributes\n */\nexport function calculateAttributesPrice(\n attributes: OrderItemAttributes\n): number {\n return attributes.reduce((total, attr) => total + attr.totalPrice, 0);\n}\n\n/**\n * Helper function to validate selected attributes against definitions\n *\n * @param selected - Selected attributes\n * @param definitions - Attribute definitions\n * @returns Validation result with any errors\n */\nexport function validateSelectedAttributes(\n selected: OrderItemAttributes,\n definitions: OrderAttribute[]\n): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n // Check required attributes\n for (const def of definitions) {\n if (def.required) {\n const selectedAttr = selected.find((s) => s.attributeId === def.id);\n if (!selectedAttr || selectedAttr.selectedValues.length === 0) {\n errors.push(`Attribute \"${def.name}\" is required`);\n }\n }\n }\n\n // Check selection counts\n for (const selectedAttr of selected) {\n const def = definitions.find((d) => d.id === selectedAttr.attributeId);\n if (!def) {\n errors.push(`Unknown attribute: ${selectedAttr.attributeName}`);\n continue;\n }\n\n const count = selectedAttr.selectedValues.length;\n\n if (!def.allowMultiple && count > 1) {\n errors.push(`Attribute \"${def.name}\" allows only one selection`);\n }\n\n if (def.minSelections && count < def.minSelections) {\n errors.push(\n `Attribute \"${def.name}\" requires at least ${def.minSelections} selections`\n );\n }\n\n if (def.maxSelections && count > def.maxSelections) {\n errors.push(\n `Attribute \"${def.name}\" allows at most ${def.maxSelections} selections`\n );\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;A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,YACQ;AACR,SAAO,WAAW,OAAO,CAAC,OAAO,SAAS,QAAQ,KAAK,YAAY,CAAC;AACtE;AASO,SAAS,2BACd,UACA,aACsC;AACtC,QAAM,SAAmB,CAAC;AAG1B,aAAW,OAAO,aAAa;AAC7B,QAAI,IAAI,UAAU;AAChB,YAAM,eAAe,SAAS,KAAK,CAAC,MAAM,EAAE,gBAAgB,IAAI,EAAE;AAClE,UAAI,CAAC,gBAAgB,aAAa,eAAe,WAAW,GAAG;AAC7D,eAAO,KAAK,cAAc,IAAI,IAAI,eAAe;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAGA,aAAW,gBAAgB,UAAU;AACnC,UAAM,MAAM,YAAY,KAAK,CAAC,MAAM,EAAE,OAAO,aAAa,WAAW;AACrE,QAAI,CAAC,KAAK;AACR,aAAO,KAAK,sBAAsB,aAAa,aAAa,EAAE;AAC9D;AAAA,IACF;AAEA,UAAM,QAAQ,aAAa,eAAe;AAE1C,QAAI,CAAC,IAAI,iBAAiB,QAAQ,GAAG;AACnC,aAAO,KAAK,cAAc,IAAI,IAAI,6BAA6B;AAAA,IACjE;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,uBAAuB,IAAI,aAAa;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,oBAAoB,IAAI,aAAa;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts","../src/customers.ts","../src/multilanguage.ts","../src/order-attributes.ts"],"sourcesContent":["export * from './mia-server-response'\nexport * from './notifications'\nexport * from './messaging-bus'\nexport * from './customers'\nexport * from './multilanguage'\nexport * from './order-attributes'\n","export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\nexport interface SmsNotification extends Notification {\n mobile: string,\n}\n\nexport interface PrintLine {\n text: string,\n alignment: 'left' | 'center' | 'right',\n size: 'normal' | 'large' | 'small',\n weight: 'normal' | 'bold'\n}\n\nexport interface OperateOrderNotificationPayload {\n orderId: string,\n serveTo: string | null,\n items: Array<{\n name: string,\n quantity: number,\n price: number,\n description: string | null\n }>,\n notes: string | null,\n lines: PrintLine[]\n}\n\nexport interface OperateOrderNotification {\n brandId: string,\n branchId: string,\n title: string,\n body: string,\n order: OperateOrderNotificationPayload\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendOperateOrderNotification(message: OperateOrderNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, {\n ...message,\n type: 'operateOrder'\n });\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\n static operateOrderTopicFormatter = (brandId: string, branchId: string) =>\n `~operate~orders~${brandId}~${branchId}`\n}","import { MessagingBus } from \"./messaging-bus\";\n\nexport interface CustomerMobileVerifiedMessage {\n brandId: string;\n customer: any;\n isVerified: boolean;\n}\n\nexport interface CustomerActionMessage {\n brandId: string;\n type: string;\n customer: any;\n payload: any;\n}\n\nexport interface CustomerAddTagMessage {\n brandId: string;\n customer: any;\n tag: string;\n remove: boolean;\n}\n\nexport interface CustomerUpdateNotesMessage {\n brandId: string;\n customer: any;\n newNotes: string;\n}\n\nexport class MicrogemsCustomer {\n static async mobileVerified(message: CustomerMobileVerifiedMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async action(message: CustomerActionMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async addTag(message: CustomerAddTagMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async updateNotes(message: CustomerUpdateNotesMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n}","/**\n * Multilanguage String Type\n *\n * Represents text content that can be displayed in multiple languages.\n * Used across services for internationalization support.\n */\n\nexport interface MultilanguageString {\n /**\n * English text (required)\n */\n en: string;\n\n /**\n * Arabic text (optional)\n */\n ar?: string;\n}\n\n/**\n * Helper function to get text in preferred language with fallback\n *\n * @param text - Multilanguage string object\n * @param language - Preferred language ('en' | 'ar')\n * @returns Text in preferred language, or English if not available\n */\nexport function getLocalizedText(\n text: MultilanguageString,\n language: 'en' | 'ar' = 'en'\n): string {\n if (language === 'ar' && text.ar) {\n return text.ar;\n }\n return text.en;\n}\n\n/**\n * Helper function to create a multilanguage string from a plain string\n *\n * @param enText - English text\n * @param arText - Optional Arabic text\n * @returns MultilanguageString object\n */\nexport function createMultilanguageString(\n enText: string,\n arText?: string\n): MultilanguageString {\n const result: MultilanguageString = { en: enText };\n if (arText) {\n result.ar = arText;\n }\n return result;\n}\n","/**\n * Order Item Attributes\n *\n * Shared types for order item customization attributes used across:\n * - menu API (for menu item attributes)\n * - schedule API (for appointment service attributes)\n * - transactions API (for order item attributes)\n */\n\n/**\n * Single attribute value option\n */\nexport interface AttributeValue {\n /**\n * Unique identifier for this value option\n */\n id: string;\n\n /**\n * Display name of the value\n */\n name: string;\n\n /**\n * Additional price for selecting this value (0 if no extra cost)\n */\n price: number;\n\n /**\n * Whether this value is available/in-stock\n */\n isAvailable?: boolean;\n}\n\n/**\n * Attribute definition (e.g., \"Size\", \"Color\", \"Extras\")\n */\nexport interface OrderAttribute {\n /**\n * Unique identifier for this attribute\n */\n id: string;\n\n /**\n * Attribute name (e.g., \"Size\", \"Toppings\")\n */\n name: string;\n\n /**\n * Available values for this attribute\n */\n values: AttributeValue[];\n\n /**\n * Whether customer must select a value for this attribute\n */\n required?: boolean;\n\n /**\n * Allow multiple values to be selected (e.g., multiple toppings)\n */\n allowMultiple?: boolean;\n\n /**\n * Minimum number of selections (if allowMultiple = true)\n */\n minSelections?: number;\n\n /**\n * Maximum number of selections (if allowMultiple = true)\n */\n maxSelections?: number;\n}\n\n/**\n * Selected attribute for an order item\n * (What the customer actually selected)\n */\nexport interface SelectedOrderAttribute {\n /**\n * Reference to the attribute definition\n */\n attributeId: string;\n\n /**\n * Attribute name (denormalized for display)\n */\n attributeName: string;\n\n /**\n * Selected value(s)\n */\n selectedValues: {\n /**\n * Value ID\n */\n id: string;\n\n /**\n * Value name (denormalized for display)\n */\n name: string;\n\n /**\n * Price of this selected value\n */\n price: number;\n }[];\n\n /**\n * Total price for this attribute (sum of all selected values)\n */\n totalPrice: number;\n}\n\n/**\n * Array of selected attributes for an order item\n * This is what gets stored in Appointment.orderItemAttributes or Order.items[].attributes\n */\nexport type OrderItemAttributes = SelectedOrderAttribute[];\n\n/**\n * Helper function to calculate total price from selected attributes\n *\n * @param attributes - Array of selected attributes\n * @returns Total additional price from all attributes\n */\nexport function calculateAttributesPrice(\n attributes: OrderItemAttributes\n): number {\n return attributes.reduce((total, attr) => total + attr.totalPrice, 0);\n}\n\n/**\n * Helper function to validate selected attributes against definitions\n *\n * @param selected - Selected attributes\n * @param definitions - Attribute definitions\n * @returns Validation result with any errors\n */\nexport function validateSelectedAttributes(\n selected: OrderItemAttributes,\n definitions: OrderAttribute[]\n): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n // Check required attributes\n for (const def of definitions) {\n if (def.required) {\n const selectedAttr = selected.find((s) => s.attributeId === def.id);\n if (!selectedAttr || selectedAttr.selectedValues.length === 0) {\n errors.push(`Attribute \"${def.name}\" is required`);\n }\n }\n }\n\n // Check selection counts\n for (const selectedAttr of selected) {\n const def = definitions.find((d) => d.id === selectedAttr.attributeId);\n if (!def) {\n errors.push(`Unknown attribute: ${selectedAttr.attributeName}`);\n continue;\n }\n\n const count = selectedAttr.selectedValues.length;\n\n if (!def.allowMultiple && count > 1) {\n errors.push(`Attribute \"${def.name}\" allows only one selection`);\n }\n\n if (def.minSelections && count < def.minSelections) {\n errors.push(\n `Attribute \"${def.name}\" requires at least ${def.minSelections} selections`\n );\n }\n\n if (def.maxSelections && count > def.maxSelections) {\n errors.push(\n `Attribute \"${def.name}\" allows at most ${def.maxSelections} selections`\n );\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,kBAAmC;AAE5B,IAAM,eAAN,MAAmB;AAAA,EACxB,OAAa,UAAU,SAAiB,OAAe,WAAqB;AAAA;AAC1E,UAAI,CAAC,QAAQ,IAAI,WAAW;AAC1B,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AACA,YAAM,KAAK,UAAM,qBAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,SAAK,uBAAU;AACrB,YAAM,eAAe,GAAG,UAAU,SAAS,EAAE,MAAa,CAAC;AAE3D,OAAC,CAAO,QAAQ;AAEd,gBAAQ,IAAI,iBAAiB,IAA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AAW,OAAO,aAAa;AAC7B,QAAI,IAAI,UAAU;AAChB,YAAM,eAAe,SAAS,KAAK,CAAC,MAAM,EAAE,gBAAgB,IAAI,EAAE;AAClE,UAAI,CAAC,gBAAgB,aAAa,eAAe,WAAW,GAAG;AAC7D,eAAO,KAAK,cAAc,IAAI,IAAI,eAAe;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAGA,aAAW,gBAAgB,UAAU;AACnC,UAAM,MAAM,YAAY,KAAK,CAAC,MAAM,EAAE,OAAO,aAAa,WAAW;AACrE,QAAI,CAAC,KAAK;AACR,aAAO,KAAK,sBAAsB,aAAa,aAAa,EAAE;AAC9D;AAAA,IACF;AAEA,UAAM,QAAQ,aAAa,eAAe;AAE1C,QAAI,CAAC,IAAI,iBAAiB,QAAQ,GAAG;AACnC,aAAO,KAAK,cAAc,IAAI,IAAI,6BAA6B;AAAA,IACjE;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,uBAAuB,IAAI,aAAa;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,oBAAoB,IAAI,aAAa;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1
7
  var __knownSymbol = (name, symbol) => {
2
8
  return (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
3
9
  };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
4
23
  var __async = (__this, __arguments, generator) => {
5
24
  return new Promise((resolve, reject) => {
6
25
  var fulfilled = (value) => {
@@ -119,8 +138,16 @@ var MiaNotifications = class {
119
138
  yield MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || "general"}`, message);
120
139
  });
121
140
  }
141
+ static sendOperateOrderNotification(message) {
142
+ return __async(this, null, function* () {
143
+ yield MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || "general"}`, __spreadProps(__spreadValues({}, message), {
144
+ type: "operateOrder"
145
+ }));
146
+ });
147
+ }
122
148
  };
123
149
  MiaNotifications.topicFormatter = (topic) => "/topics/" + topic.replace(/\//g, "~");
150
+ MiaNotifications.operateOrderTopicFormatter = (brandId, branchId) => `~operate~orders~${brandId}~${branchId}`;
124
151
 
125
152
  // src/customers.ts
126
153
  var MicrogemsCustomer = class {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts","../src/customers.ts","../src/multilanguage.ts","../src/order-attributes.ts"],"sourcesContent":["export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\nexport interface SmsNotification extends Notification {\n mobile: string,\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\n}","import { MessagingBus } from \"./messaging-bus\";\n\nexport interface CustomerMobileVerifiedMessage {\n brandId: string;\n customer: any;\n isVerified: boolean;\n}\n\nexport interface CustomerActionMessage {\n brandId: string;\n type: string;\n customer: any;\n payload: any;\n}\n\nexport interface CustomerAddTagMessage {\n brandId: string;\n customer: any;\n tag: string;\n remove: boolean;\n}\n\nexport interface CustomerUpdateNotesMessage {\n brandId: string;\n customer: any;\n newNotes: string;\n}\n\nexport class MicrogemsCustomer {\n static async mobileVerified(message: CustomerMobileVerifiedMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async action(message: CustomerActionMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async addTag(message: CustomerAddTagMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async updateNotes(message: CustomerUpdateNotesMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n}","/**\n * Multilanguage String Type\n *\n * Represents text content that can be displayed in multiple languages.\n * Used across services for internationalization support.\n */\n\nexport interface MultilanguageString {\n /**\n * English text (required)\n */\n en: string;\n\n /**\n * Arabic text (optional)\n */\n ar?: string;\n}\n\n/**\n * Helper function to get text in preferred language with fallback\n *\n * @param text - Multilanguage string object\n * @param language - Preferred language ('en' | 'ar')\n * @returns Text in preferred language, or English if not available\n */\nexport function getLocalizedText(\n text: MultilanguageString,\n language: 'en' | 'ar' = 'en'\n): string {\n if (language === 'ar' && text.ar) {\n return text.ar;\n }\n return text.en;\n}\n\n/**\n * Helper function to create a multilanguage string from a plain string\n *\n * @param enText - English text\n * @param arText - Optional Arabic text\n * @returns MultilanguageString object\n */\nexport function createMultilanguageString(\n enText: string,\n arText?: string\n): MultilanguageString {\n const result: MultilanguageString = { en: enText };\n if (arText) {\n result.ar = arText;\n }\n return result;\n}\n","/**\n * Order Item Attributes\n *\n * Shared types for order item customization attributes used across:\n * - menu API (for menu item attributes)\n * - schedule API (for appointment service attributes)\n * - transactions API (for order item attributes)\n */\n\n/**\n * Single attribute value option\n */\nexport interface AttributeValue {\n /**\n * Unique identifier for this value option\n */\n id: string;\n\n /**\n * Display name of the value\n */\n name: string;\n\n /**\n * Additional price for selecting this value (0 if no extra cost)\n */\n price: number;\n\n /**\n * Whether this value is available/in-stock\n */\n isAvailable?: boolean;\n}\n\n/**\n * Attribute definition (e.g., \"Size\", \"Color\", \"Extras\")\n */\nexport interface OrderAttribute {\n /**\n * Unique identifier for this attribute\n */\n id: string;\n\n /**\n * Attribute name (e.g., \"Size\", \"Toppings\")\n */\n name: string;\n\n /**\n * Available values for this attribute\n */\n values: AttributeValue[];\n\n /**\n * Whether customer must select a value for this attribute\n */\n required?: boolean;\n\n /**\n * Allow multiple values to be selected (e.g., multiple toppings)\n */\n allowMultiple?: boolean;\n\n /**\n * Minimum number of selections (if allowMultiple = true)\n */\n minSelections?: number;\n\n /**\n * Maximum number of selections (if allowMultiple = true)\n */\n maxSelections?: number;\n}\n\n/**\n * Selected attribute for an order item\n * (What the customer actually selected)\n */\nexport interface SelectedOrderAttribute {\n /**\n * Reference to the attribute definition\n */\n attributeId: string;\n\n /**\n * Attribute name (denormalized for display)\n */\n attributeName: string;\n\n /**\n * Selected value(s)\n */\n selectedValues: {\n /**\n * Value ID\n */\n id: string;\n\n /**\n * Value name (denormalized for display)\n */\n name: string;\n\n /**\n * Price of this selected value\n */\n price: number;\n }[];\n\n /**\n * Total price for this attribute (sum of all selected values)\n */\n totalPrice: number;\n}\n\n/**\n * Array of selected attributes for an order item\n * This is what gets stored in Appointment.orderItemAttributes or Order.items[].attributes\n */\nexport type OrderItemAttributes = SelectedOrderAttribute[];\n\n/**\n * Helper function to calculate total price from selected attributes\n *\n * @param attributes - Array of selected attributes\n * @returns Total additional price from all attributes\n */\nexport function calculateAttributesPrice(\n attributes: OrderItemAttributes\n): number {\n return attributes.reduce((total, attr) => total + attr.totalPrice, 0);\n}\n\n/**\n * Helper function to validate selected attributes against definitions\n *\n * @param selected - Selected attributes\n * @param definitions - Attribute definitions\n * @returns Validation result with any errors\n */\nexport function validateSelectedAttributes(\n selected: OrderItemAttributes,\n definitions: OrderAttribute[]\n): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n // Check required attributes\n for (const def of definitions) {\n if (def.required) {\n const selectedAttr = selected.find((s) => s.attributeId === def.id);\n if (!selectedAttr || selectedAttr.selectedValues.length === 0) {\n errors.push(`Attribute \"${def.name}\" is required`);\n }\n }\n }\n\n // Check selection counts\n for (const selectedAttr of selected) {\n const def = definitions.find((d) => d.id === selectedAttr.attributeId);\n if (!def) {\n errors.push(`Unknown attribute: ${selectedAttr.attributeName}`);\n continue;\n }\n\n const count = selectedAttr.selectedValues.length;\n\n if (!def.allowMultiple && count > 1) {\n errors.push(`Attribute \"${def.name}\" allows only one selection`);\n }\n\n if (def.minSelections && count < def.minSelections) {\n errors.push(\n `Attribute \"${def.name}\" requires at least ${def.minSelections} selections`\n );\n }\n\n if (def.maxSelections && count > def.maxSelections) {\n errors.push(\n `Attribute \"${def.name}\" allows at most ${def.maxSelections} selections`\n );\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;A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AC2EO,SAAS,yBACd,YACQ;AACR,SAAO,WAAW,OAAO,CAAC,OAAO,SAAS,QAAQ,KAAK,YAAY,CAAC;AACtE;AASO,SAAS,2BACd,UACA,aACsC;AACtC,QAAM,SAAmB,CAAC;AAG1B,aAAW,OAAO,aAAa;AAC7B,QAAI,IAAI,UAAU;AAChB,YAAM,eAAe,SAAS,KAAK,CAAC,MAAM,EAAE,gBAAgB,IAAI,EAAE;AAClE,UAAI,CAAC,gBAAgB,aAAa,eAAe,WAAW,GAAG;AAC7D,eAAO,KAAK,cAAc,IAAI,IAAI,eAAe;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAGA,aAAW,gBAAgB,UAAU;AACnC,UAAM,MAAM,YAAY,KAAK,CAAC,MAAM,EAAE,OAAO,aAAa,WAAW;AACrE,QAAI,CAAC,KAAK;AACR,aAAO,KAAK,sBAAsB,aAAa,aAAa,EAAE;AAC9D;AAAA,IACF;AAEA,UAAM,QAAQ,aAAa,eAAe;AAE1C,QAAI,CAAC,IAAI,iBAAiB,QAAQ,GAAG;AACnC,aAAO,KAAK,cAAc,IAAI,IAAI,6BAA6B;AAAA,IACjE;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,uBAAuB,IAAI,aAAa;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,oBAAoB,IAAI,aAAa;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/mia-server-response.ts","../src/messaging-bus.ts","../src/notifications.ts","../src/customers.ts","../src/multilanguage.ts","../src/order-attributes.ts"],"sourcesContent":["export class MiaServerResponse {\n status?: number;\n message?: string;\n data: any;\n\n static send = (status: number, message: string, data: any) => {\n const response: MiaServerResponse = {\n status: status,\n message: message,\n data: data\n };\n return response;\n }\n static sendData = (data: any, status: number = 200) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Success\",\n data: data\n };\n return response;\n }\n static sendError = (error: any, status: number = 400) => {\n const response: MiaServerResponse = {\n status: status,\n message: \"Failed\",\n data: error\n };\n return response;\n }\n}\n","import { connect, JSONCodec } from \"nats\";\n\nexport class MessagingBus {\n static async subscribe(channel: string, queue: string, onMessage: Function) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const sc = JSONCodec();\n const subscription = nc.subscribe(channel, { queue: queue });\n\n (async (sub) => {\n\n console.log(`listening for ${sub.getSubject()} requests...`);\n\n for await (const m of sub) {\n const msg = sc.decode(m.data);\n onMessage(msg);\n }\n\n console.log(`subscription ${sub.getSubject()} drained.`);\n })(subscription);\n }\n\n static async publish(channel: string, message: any) {\n if (!process.env.NATS_HOST) {\n throw new Error(\"NATS_HOST ENV is not defined\");\n }\n const nc = await connect({ servers: process.env.NATS_HOST });\n const jc = JSONCodec();\n nc.publish(channel, jc.encode(message));\n await nc.drain();\n }\n}\n","import { MessagingBus } from \"./messaging-bus\";\nexport interface Notification {\n title?: string,\n body: string,\n badge?: number,\n payload?: any,\n target?: string\n}\nexport interface UserNotification extends Notification {\n userId: string\n}\nexport interface DeviceNotification extends Notification {\n deviceId: string\n}\nexport interface TopicNotification extends Notification {\n topic: string,\n}\nexport interface SmsNotification extends Notification {\n mobile: string,\n}\n\nexport interface PrintLine {\n text: string,\n alignment: 'left' | 'center' | 'right',\n size: 'normal' | 'large' | 'small',\n weight: 'normal' | 'bold'\n}\n\nexport interface OperateOrderNotificationPayload {\n orderId: string,\n serveTo: string | null,\n items: Array<{\n name: string,\n quantity: number,\n price: number,\n description: string | null\n }>,\n notes: string | null,\n lines: PrintLine[]\n}\n\nexport interface OperateOrderNotification {\n brandId: string,\n branchId: string,\n title: string,\n body: string,\n order: OperateOrderNotificationPayload\n}\n\nexport class MiaNotifications {\n static async sendtoDevice(message: DeviceNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoUserDevices(message: UserNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoTopic(message: TopicNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendtoSms(message: SmsNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, message);\n }\n static async sendOperateOrderNotification(message: OperateOrderNotification) {\n await MessagingBus.publish(`mia.notifications.${process.env.HOSTNAME || \"general\"}`, {\n ...message,\n type: 'operateOrder'\n });\n }\n static topicFormatter = (topic: string) => \"/topics/\" + topic.replace(/\\//g, \"~\")\n static operateOrderTopicFormatter = (brandId: string, branchId: string) =>\n `~operate~orders~${brandId}~${branchId}`\n}","import { MessagingBus } from \"./messaging-bus\";\n\nexport interface CustomerMobileVerifiedMessage {\n brandId: string;\n customer: any;\n isVerified: boolean;\n}\n\nexport interface CustomerActionMessage {\n brandId: string;\n type: string;\n customer: any;\n payload: any;\n}\n\nexport interface CustomerAddTagMessage {\n brandId: string;\n customer: any;\n tag: string;\n remove: boolean;\n}\n\nexport interface CustomerUpdateNotesMessage {\n brandId: string;\n customer: any;\n newNotes: string;\n}\n\nexport class MicrogemsCustomer {\n static async mobileVerified(message: CustomerMobileVerifiedMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async action(message: CustomerActionMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async addTag(message: CustomerAddTagMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n\n static async updateNotes(message: CustomerUpdateNotesMessage) {\n await MessagingBus.publish(`mia.customers.${process.env.HOSTNAME || \"general\"}`, message);\n }\n}","/**\n * Multilanguage String Type\n *\n * Represents text content that can be displayed in multiple languages.\n * Used across services for internationalization support.\n */\n\nexport interface MultilanguageString {\n /**\n * English text (required)\n */\n en: string;\n\n /**\n * Arabic text (optional)\n */\n ar?: string;\n}\n\n/**\n * Helper function to get text in preferred language with fallback\n *\n * @param text - Multilanguage string object\n * @param language - Preferred language ('en' | 'ar')\n * @returns Text in preferred language, or English if not available\n */\nexport function getLocalizedText(\n text: MultilanguageString,\n language: 'en' | 'ar' = 'en'\n): string {\n if (language === 'ar' && text.ar) {\n return text.ar;\n }\n return text.en;\n}\n\n/**\n * Helper function to create a multilanguage string from a plain string\n *\n * @param enText - English text\n * @param arText - Optional Arabic text\n * @returns MultilanguageString object\n */\nexport function createMultilanguageString(\n enText: string,\n arText?: string\n): MultilanguageString {\n const result: MultilanguageString = { en: enText };\n if (arText) {\n result.ar = arText;\n }\n return result;\n}\n","/**\n * Order Item Attributes\n *\n * Shared types for order item customization attributes used across:\n * - menu API (for menu item attributes)\n * - schedule API (for appointment service attributes)\n * - transactions API (for order item attributes)\n */\n\n/**\n * Single attribute value option\n */\nexport interface AttributeValue {\n /**\n * Unique identifier for this value option\n */\n id: string;\n\n /**\n * Display name of the value\n */\n name: string;\n\n /**\n * Additional price for selecting this value (0 if no extra cost)\n */\n price: number;\n\n /**\n * Whether this value is available/in-stock\n */\n isAvailable?: boolean;\n}\n\n/**\n * Attribute definition (e.g., \"Size\", \"Color\", \"Extras\")\n */\nexport interface OrderAttribute {\n /**\n * Unique identifier for this attribute\n */\n id: string;\n\n /**\n * Attribute name (e.g., \"Size\", \"Toppings\")\n */\n name: string;\n\n /**\n * Available values for this attribute\n */\n values: AttributeValue[];\n\n /**\n * Whether customer must select a value for this attribute\n */\n required?: boolean;\n\n /**\n * Allow multiple values to be selected (e.g., multiple toppings)\n */\n allowMultiple?: boolean;\n\n /**\n * Minimum number of selections (if allowMultiple = true)\n */\n minSelections?: number;\n\n /**\n * Maximum number of selections (if allowMultiple = true)\n */\n maxSelections?: number;\n}\n\n/**\n * Selected attribute for an order item\n * (What the customer actually selected)\n */\nexport interface SelectedOrderAttribute {\n /**\n * Reference to the attribute definition\n */\n attributeId: string;\n\n /**\n * Attribute name (denormalized for display)\n */\n attributeName: string;\n\n /**\n * Selected value(s)\n */\n selectedValues: {\n /**\n * Value ID\n */\n id: string;\n\n /**\n * Value name (denormalized for display)\n */\n name: string;\n\n /**\n * Price of this selected value\n */\n price: number;\n }[];\n\n /**\n * Total price for this attribute (sum of all selected values)\n */\n totalPrice: number;\n}\n\n/**\n * Array of selected attributes for an order item\n * This is what gets stored in Appointment.orderItemAttributes or Order.items[].attributes\n */\nexport type OrderItemAttributes = SelectedOrderAttribute[];\n\n/**\n * Helper function to calculate total price from selected attributes\n *\n * @param attributes - Array of selected attributes\n * @returns Total additional price from all attributes\n */\nexport function calculateAttributesPrice(\n attributes: OrderItemAttributes\n): number {\n return attributes.reduce((total, attr) => total + attr.totalPrice, 0);\n}\n\n/**\n * Helper function to validate selected attributes against definitions\n *\n * @param selected - Selected attributes\n * @param definitions - Attribute definitions\n * @returns Validation result with any errors\n */\nexport function validateSelectedAttributes(\n selected: OrderItemAttributes,\n definitions: OrderAttribute[]\n): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n // Check required attributes\n for (const def of definitions) {\n if (def.required) {\n const selectedAttr = selected.find((s) => s.attributeId === def.id);\n if (!selectedAttr || selectedAttr.selectedValues.length === 0) {\n errors.push(`Attribute \"${def.name}\" is required`);\n }\n }\n }\n\n // Check selection counts\n for (const selectedAttr of selected) {\n const def = definitions.find((d) => d.id === selectedAttr.attributeId);\n if (!def) {\n errors.push(`Unknown attribute: ${selectedAttr.attributeName}`);\n continue;\n }\n\n const count = selectedAttr.selectedValues.length;\n\n if (!def.allowMultiple && count > 1) {\n errors.push(`Attribute \"${def.name}\" allows only one selection`);\n }\n\n if (def.minSelections && count < def.minSelections) {\n errors.push(\n `Attribute \"${def.name}\" requires at least ${def.minSelections} selections`\n );\n }\n\n if (def.maxSelections && count > def.maxSelections) {\n errors.push(\n `Attribute \"${def.name}\" allows at most ${def.maxSelections} selections`\n );\n }\n }\n\n return {\n valid: errors.length === 0,\n errors,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,oBAAN,MAAwB;AA6B/B;AA7Ba,kBAKJ,OAAO,CAAC,QAAgB,SAAiB,SAAc;AAC5D,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AACT;AAZW,kBAaJ,WAAW,CAAC,MAAW,SAAiB,QAAQ;AACrD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AApBW,kBAqBJ,YAAY,CAAC,OAAY,SAAiB,QAAQ;AACvD,QAAM,WAA8B;AAAA,IAClC;AAAA,IACA,SAAS;AAAA,IACT,MAAM;AAAA,EACR;AACA,SAAO;AACT;;;AC5BF,SAAS,SAAS,iBAAiB;AAE5B,IAAM,eAAN,MAAmB;AAAA,EACxB,OAAa,UAAU,SAAiB,OAAe,WAAqB;AAAA;AAC1E,UAAI,CAAC,QAAQ,IAAI,WAAW;AAC1B,cAAM,IAAI,MAAM,8BAA8B;AAAA,MAChD;AACA,YAAM,KAAK,MAAM,QAAQ,EAAE,SAAS,QAAQ,IAAI,UAAU,CAAC;AAC3D,YAAM,KAAK,UAAU;AACrB,YAAM,eAAe,GAAG,UAAU,SAAS,EAAE,MAAa,CAAC;AAE3D,OAAC,CAAO,QAAQ;AAEd,gBAAQ,IAAI,iBAAiB,IAAI,WAAW,CAAC,cAAc;AAE3D;AAAA,qCAAsB,MAAtB,0EAA2B;AAAhB,kBAAM,IAAjB;AACE,kBAAM,MAAM,GAAG,OAAO,EAAE,IAAI;AAC5B,sBAAU,GAAG;AAAA,UACf;AAAA,iBAHA,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eAAO,KAAK,cAAc,IAAI,IAAI,eAAe;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAGA,aAAW,gBAAgB,UAAU;AACnC,UAAM,MAAM,YAAY,KAAK,CAAC,MAAM,EAAE,OAAO,aAAa,WAAW;AACrE,QAAI,CAAC,KAAK;AACR,aAAO,KAAK,sBAAsB,aAAa,aAAa,EAAE;AAC9D;AAAA,IACF;AAEA,UAAM,QAAQ,aAAa,eAAe;AAE1C,QAAI,CAAC,IAAI,iBAAiB,QAAQ,GAAG;AACnC,aAAO,KAAK,cAAc,IAAI,IAAI,6BAA6B;AAAA,IACjE;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,uBAAuB,IAAI,aAAa;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,IAAI,iBAAiB,QAAQ,IAAI,eAAe;AAClD,aAAO;AAAA,QACL,cAAc,IAAI,IAAI,oBAAoB,IAAI,aAAa;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,OAAO,WAAW;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aghamdi/shared-types",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "Provide typescript interfaces for common types and some classes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.js",
@@ -25,4 +25,4 @@
25
25
  "dependencies": {
26
26
  "nats": "^2.26.0"
27
27
  }
28
- }
28
+ }