@managesome/eposmatic-toolkit 0.2.357 → 0.2.359

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.
@@ -1,3 +1,4 @@
1
- import { IOrder } from '../../schemas';
1
+ import { IOrder, IPrinterSettings } from '../../schemas';
2
+ export declare function syncPrinterSettingsFields(printerSettings: IPrinterSettings): IPrinterSettings;
2
3
  export declare function splitStringByLength(inputString: string, maxLength: number): string[];
3
4
  export declare function getSingleQuantityTicketOrders(order: IOrder, singleQuantityTicket: boolean | undefined): IOrder[];
@@ -1,8 +1,234 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncPrinterSettingsFields = syncPrinterSettingsFields;
3
4
  exports.splitStringByLength = splitStringByLength;
4
5
  exports.getSingleQuantityTicketOrders = getSingleQuantityTicketOrders;
6
+ const constants_1 = require("../../constants");
5
7
  const store_1 = require("../store");
8
+ function isObjectRecord(value) {
9
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
10
+ }
11
+ function getStringValue(value, fallback) {
12
+ return typeof value === 'string' ? value : fallback;
13
+ }
14
+ function getNullableStringValue(value, fallback) {
15
+ if (typeof value === 'string')
16
+ return value;
17
+ if (value === null)
18
+ return null;
19
+ return fallback;
20
+ }
21
+ function getBooleanValue(value, fallback) {
22
+ return typeof value === 'boolean' ? value : fallback;
23
+ }
24
+ function getNumberValue(value, fallback) {
25
+ if (typeof value === 'number' && Number.isFinite(value))
26
+ return value;
27
+ if (typeof value === 'string') {
28
+ const normalizedValue = value.trim();
29
+ if (normalizedValue.length === 0)
30
+ return fallback;
31
+ const convertedValue = Number(normalizedValue);
32
+ if (Number.isFinite(convertedValue))
33
+ return convertedValue;
34
+ }
35
+ return fallback;
36
+ }
37
+ function getDateValue(value) {
38
+ if (value instanceof Date && !Number.isNaN(value.getTime()))
39
+ return value;
40
+ if (typeof value === 'string' || typeof value === 'number') {
41
+ const dateValue = new Date(value);
42
+ if (!Number.isNaN(dateValue.getTime()))
43
+ return dateValue;
44
+ }
45
+ return new Date();
46
+ }
47
+ function getReceiptTypes(value) {
48
+ const validReceiptTypes = new Set(constants_1.ALL_RECEIPT_TYPES);
49
+ if (!Array.isArray(value))
50
+ return [...constants_1.ALL_RECEIPT_TYPES];
51
+ const receiptTypes = Array.from(new Set(value.filter((receiptType) => typeof receiptType === 'string' && validReceiptTypes.has(receiptType))));
52
+ return receiptTypes.length > 0 ? receiptTypes : [...constants_1.ALL_RECEIPT_TYPES];
53
+ }
54
+ function getInterfaceType(value) {
55
+ const validInterfaces = new Set(constants_1.ALL_PRINTER_INTERFACES);
56
+ if (typeof value === 'string' && validInterfaces.has(value)) {
57
+ return value;
58
+ }
59
+ return constants_1.PRINTER_INTERFACE_ENUM.LAN;
60
+ }
61
+ function getPrintingPreference(value) {
62
+ const validPreferences = new Set(constants_1.ALL_PRINTING_PREFERENCES);
63
+ if (typeof value === 'string' && validPreferences.has(value)) {
64
+ return value;
65
+ }
66
+ return constants_1.PRINTING_PREFERENCE_ENUM.DEFAULT;
67
+ }
68
+ function getKitchenDocketFontType(value) {
69
+ const validFontTypes = new Set(constants_1.ALL_KITCHEN_DOCKET_FONT_TYPES);
70
+ if (typeof value === 'string' && validFontTypes.has(value)) {
71
+ return value;
72
+ }
73
+ return constants_1.KITCHEN_DOCKET_FONT_TYPE_ENUM.DEFAULT;
74
+ }
75
+ function getQuantityByOrderType(value) {
76
+ const quantityByOrderType = {};
77
+ const quantityRecord = isObjectRecord(value) ? value : {};
78
+ for (const orderType of constants_1.ALL_ORDER_TYPE_NAMES) {
79
+ quantityByOrderType[orderType] = getNumberValue(quantityRecord[orderType], 1);
80
+ }
81
+ return quantityByOrderType;
82
+ }
83
+ function getSelectedPlatforms(value) {
84
+ const validPlatforms = new Set(constants_1.ALL_PLATFORMS);
85
+ if (!Array.isArray(value))
86
+ return [...constants_1.ALL_PLATFORMS];
87
+ const selectedPlatforms = Array.from(new Set(value.filter((platform) => typeof platform === 'string' && validPlatforms.has(platform))));
88
+ return selectedPlatforms.length > 0 ? selectedPlatforms : [...constants_1.ALL_PLATFORMS];
89
+ }
90
+ function getPartialDinein(value) {
91
+ if (!isObjectRecord(value))
92
+ return {};
93
+ const partialDinein = {};
94
+ const entries = Object.entries(value);
95
+ for (let i = 0; i < entries.length; i++) {
96
+ const [key, entryValue] = entries[i];
97
+ partialDinein[key] = Array.isArray(entryValue)
98
+ ? entryValue.filter((item) => typeof item === 'string')
99
+ : [];
100
+ }
101
+ return partialDinein;
102
+ }
103
+ function getIncludedItemsMap(value) {
104
+ if (!isObjectRecord(value))
105
+ return {};
106
+ const includedItemsMap = {};
107
+ const entries = Object.entries(value);
108
+ for (let i = 0; i < entries.length; i++) {
109
+ const [itemId, itemValue] = entries[i];
110
+ const item = isObjectRecord(itemValue) ? itemValue : {};
111
+ includedItemsMap[itemId] = {
112
+ sortId: getNumberValue(item.sortId, i),
113
+ };
114
+ }
115
+ return includedItemsMap;
116
+ }
117
+ function getIncludedCategoriesMap(value) {
118
+ if (!isObjectRecord(value))
119
+ return {};
120
+ const includedCategoriesMap = {};
121
+ const entries = Object.entries(value);
122
+ for (let i = 0; i < entries.length; i++) {
123
+ const [categoryId, categoryValue] = entries[i];
124
+ const category = isObjectRecord(categoryValue) ? categoryValue : {};
125
+ includedCategoriesMap[categoryId] = {
126
+ sortId: getNumberValue(category.sortId, i),
127
+ includedItemsMap: getIncludedItemsMap(category.includedItemsMap),
128
+ };
129
+ }
130
+ return includedCategoriesMap;
131
+ }
132
+ function getGeneralBoolSettings(value) {
133
+ const boolSettings = isObjectRecord(value) ? value : {};
134
+ return {
135
+ isActive: getBooleanValue(boolSettings.isActive, true),
136
+ syncWithCloud: getBooleanValue(boolSettings.syncWithCloud, true),
137
+ experimentalFastPrinting: getBooleanValue(boolSettings.experimentalFastPrinting, false),
138
+ printReviews: getBooleanValue(boolSettings.printReviews, false),
139
+ rasterOnlyReceipt: getBooleanValue(boolSettings.rasterOnlyReceipt, false),
140
+ };
141
+ }
142
+ function getKitchenBoolSettings(value) {
143
+ const boolSettings = isObjectRecord(value) ? value : {};
144
+ const kitchenBoolSettings = {
145
+ displayCurrency: getBooleanValue(boolSettings.displayCurrency, false),
146
+ displayModifiersOnSeparateLines: getBooleanValue(boolSettings.displayModifiersOnSeparateLines, true),
147
+ hideModifierName: getBooleanValue(boolSettings.hideModifierName, false),
148
+ displayItemPrice: getBooleanValue(boolSettings.displayItemPrice, false),
149
+ displayStaffName: getBooleanValue(boolSettings.displayStaffName, true),
150
+ displayDeliveryInstructions: getBooleanValue(boolSettings.displayDeliveryInstructions, true),
151
+ displayOldItems: getBooleanValue(boolSettings.displayOldItems, false),
152
+ keepConcise: getBooleanValue(boolSettings.keepConcise, true),
153
+ addExtraSpaceOnTop: getBooleanValue(boolSettings.addExtraSpaceOnTop, false),
154
+ beepOnPrint: getBooleanValue(boolSettings.beepOnPrint, false),
155
+ };
156
+ if (typeof boolSettings.singleQuantityTickets === 'boolean') {
157
+ kitchenBoolSettings.singleQuantityTickets = boolSettings.singleQuantityTickets;
158
+ }
159
+ return kitchenBoolSettings;
160
+ }
161
+ function getCustomerBoolSettings(value) {
162
+ const boolSettings = isObjectRecord(value) ? value : {};
163
+ return {
164
+ displayCurrency: getBooleanValue(boolSettings.displayCurrency, true),
165
+ displayModifiersOnSeparateLines: getBooleanValue(boolSettings.displayModifiersOnSeparateLines, true),
166
+ hideModifierName: getBooleanValue(boolSettings.hideModifierName, false),
167
+ displayStoreImage: getBooleanValue(boolSettings.displayStoreImage, true),
168
+ displayStoreEmail: getBooleanValue(boolSettings.displayStoreEmail, true),
169
+ displayQRCode: getBooleanValue(boolSettings.displayQRCode, true),
170
+ displayDeliveryInstructions: getBooleanValue(boolSettings.displayDeliveryInstructions, true),
171
+ displayStaffName: getBooleanValue(boolSettings.displayStaffName, true),
172
+ displayItemModifiers: getBooleanValue(boolSettings.displayItemModifiers, true),
173
+ displayItemInstructions: getBooleanValue(boolSettings.displayItemInstructions, true),
174
+ displayOrderInstructions: getBooleanValue(boolSettings.displayOrderInstructions, true),
175
+ displayUnitItemPrice: getBooleanValue(boolSettings.displayUnitItemPrice, true),
176
+ displayMetadata: getBooleanValue(boolSettings.displayMetadata, false),
177
+ };
178
+ }
179
+ function getKitchenSettings(value) {
180
+ const kitchenSettings = isObjectRecord(value) ? value : {};
181
+ const partialMenusInput = Array.isArray(kitchenSettings.partialMenus) ? kitchenSettings.partialMenus : [];
182
+ return {
183
+ quantityByOrderType: getQuantityByOrderType(kitchenSettings.quantityByOrderType),
184
+ selectedPlatforms: getSelectedPlatforms(kitchenSettings.selectedPlatforms),
185
+ menuPreference: getPrintingPreference(kitchenSettings.menuPreference),
186
+ partialMenus: partialMenusInput.map((partialMenu) => {
187
+ const partialMenuValue = isObjectRecord(partialMenu) ? partialMenu : {};
188
+ return {
189
+ _id: getStringValue(partialMenuValue._id, ''),
190
+ name: getStringValue(partialMenuValue.name, ''),
191
+ dineinPreference: getPrintingPreference(partialMenuValue.dineinPreference),
192
+ partialDinein: getPartialDinein(partialMenuValue.partialDinein),
193
+ includedCategoriesMap: getIncludedCategoriesMap(partialMenuValue.includedCategoriesMap),
194
+ };
195
+ }),
196
+ dineinPreference: getPrintingPreference(kitchenSettings.dineinPreference),
197
+ partialDinein: getPartialDinein(kitchenSettings.partialDinein),
198
+ fontType: getKitchenDocketFontType(kitchenSettings.fontType),
199
+ boolSettings: getKitchenBoolSettings(kitchenSettings.boolSettings),
200
+ };
201
+ }
202
+ function getCustomerSettings(value) {
203
+ const customerSettings = isObjectRecord(value) ? value : {};
204
+ return {
205
+ quantityByOrderType: getQuantityByOrderType(customerSettings.quantityByOrderType),
206
+ selectedPlatforms: getSelectedPlatforms(customerSettings.selectedPlatforms),
207
+ boolSettings: getCustomerBoolSettings(customerSettings.boolSettings),
208
+ customMessage: getNullableStringValue(customerSettings.customMessage, null),
209
+ };
210
+ }
211
+ function syncPrinterSettingsFields(printerSettings) {
212
+ const settings = isObjectRecord(printerSettings) ? printerSettings : {};
213
+ return {
214
+ _id: getStringValue(settings._id, ''),
215
+ tenant_id: getStringValue(settings.tenant_id, ''),
216
+ target: getStringValue(settings.target, ''),
217
+ mac_address: getNullableStringValue(settings.mac_address, null),
218
+ interface_type: getInterfaceType(settings.interface_type),
219
+ name: getStringValue(settings.name, ''),
220
+ staff_id: getStringValue(settings.staff_id, ''),
221
+ drawer_connected: getBooleanValue(settings.drawer_connected, false),
222
+ backup_printer_target: getNullableStringValue(settings.backup_printer_target, null),
223
+ num_of_columns: getNumberValue(settings.num_of_columns, 48),
224
+ receiptTypes: getReceiptTypes(settings.receiptTypes),
225
+ boolSettings: getGeneralBoolSettings(settings.boolSettings),
226
+ [constants_1.RECEIPT_TYPE_ENUM.KITCHEN]: getKitchenSettings(settings[constants_1.RECEIPT_TYPE_ENUM.KITCHEN]),
227
+ [constants_1.RECEIPT_TYPE_ENUM.CUSTOMER]: getCustomerSettings(settings[constants_1.RECEIPT_TYPE_ENUM.CUSTOMER]),
228
+ createdAt: getDateValue(settings.createdAt),
229
+ updatedAt: getDateValue(settings.updatedAt),
230
+ };
231
+ }
6
232
  function splitStringByLength(inputString, maxLength) {
7
233
  const words = inputString.split(' ');
8
234
  const result = [];
@@ -64,6 +64,7 @@ export declare const PrinterSettingsSchema: Schema<any, import("mongoose").Model
64
64
  singleQuantityTickets?: boolean | null | undefined;
65
65
  } | null | undefined;
66
66
  } | null | undefined;
67
+ mac_address?: string | null | undefined;
67
68
  backup_printer_target?: string | null | undefined;
68
69
  boolSettings?: {
69
70
  isActive: boolean;
@@ -132,6 +133,7 @@ export declare const PrinterSettingsSchema: Schema<any, import("mongoose").Model
132
133
  singleQuantityTickets?: boolean | null | undefined;
133
134
  } | null | undefined;
134
135
  } | null | undefined;
136
+ mac_address?: string | null | undefined;
135
137
  backup_printer_target?: string | null | undefined;
136
138
  boolSettings?: {
137
139
  isActive: boolean;
@@ -200,6 +202,7 @@ export declare const PrinterSettingsSchema: Schema<any, import("mongoose").Model
200
202
  singleQuantityTickets?: boolean | null | undefined;
201
203
  } | null | undefined;
202
204
  } | null | undefined;
205
+ mac_address?: string | null | undefined;
203
206
  backup_printer_target?: string | null | undefined;
204
207
  boolSettings?: {
205
208
  isActive: boolean;
@@ -19,6 +19,10 @@ exports.PrinterSettingsSchema = new mongoose_1.Schema({
19
19
  type: String,
20
20
  required: true,
21
21
  },
22
+ mac_address: {
23
+ type: String,
24
+ required: false,
25
+ },
22
26
  interface_type: {
23
27
  type: String,
24
28
  enum: constants_1.ALL_PRINTER_INTERFACES,
@@ -52,6 +52,7 @@ export interface IPrinterSettings {
52
52
  _id: string;
53
53
  tenant_id: string;
54
54
  target: string;
55
+ mac_address?: string | null;
55
56
  interface_type: PRINTER_INTERFACE_ENUM;
56
57
  name: string;
57
58
  staff_id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.357",
3
+ "version": "0.2.359",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",