@cimplify/sdk 0.3.4 → 0.3.6
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 +96 -154
- package/dist/index.d.ts +96 -154
- package/dist/index.js +75 -207
- package/dist/index.mjs +75 -207
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -155,9 +155,6 @@ var CatalogueQueries = class {
|
|
|
155
155
|
constructor(client) {
|
|
156
156
|
this.client = client;
|
|
157
157
|
}
|
|
158
|
-
// --------------------------------------------------------------------------
|
|
159
|
-
// PRODUCTS
|
|
160
|
-
// --------------------------------------------------------------------------
|
|
161
158
|
async getProducts(options) {
|
|
162
159
|
let query2 = "products";
|
|
163
160
|
const filters = [];
|
|
@@ -206,9 +203,6 @@ var CatalogueQueries = class {
|
|
|
206
203
|
}
|
|
207
204
|
return ok(result.value[0]);
|
|
208
205
|
}
|
|
209
|
-
// --------------------------------------------------------------------------
|
|
210
|
-
// VARIANTS
|
|
211
|
-
// --------------------------------------------------------------------------
|
|
212
206
|
async getVariants(productId) {
|
|
213
207
|
return safe(this.client.query(`products.${productId}.variants`));
|
|
214
208
|
}
|
|
@@ -232,15 +226,9 @@ var CatalogueQueries = class {
|
|
|
232
226
|
async getVariantById(productId, variantId) {
|
|
233
227
|
return safe(this.client.query(`products.${productId}.variant.${variantId}`));
|
|
234
228
|
}
|
|
235
|
-
// --------------------------------------------------------------------------
|
|
236
|
-
// ADD-ONS
|
|
237
|
-
// --------------------------------------------------------------------------
|
|
238
229
|
async getAddOns(productId) {
|
|
239
230
|
return safe(this.client.query(`products.${productId}.add_ons`));
|
|
240
231
|
}
|
|
241
|
-
// --------------------------------------------------------------------------
|
|
242
|
-
// CATEGORIES
|
|
243
|
-
// --------------------------------------------------------------------------
|
|
244
232
|
async getCategories() {
|
|
245
233
|
return safe(this.client.query("categories"));
|
|
246
234
|
}
|
|
@@ -260,9 +248,6 @@ var CatalogueQueries = class {
|
|
|
260
248
|
async getCategoryProducts(categoryId) {
|
|
261
249
|
return safe(this.client.query(`products[?(@.category_id=='${categoryId}')]`));
|
|
262
250
|
}
|
|
263
|
-
// --------------------------------------------------------------------------
|
|
264
|
-
// COLLECTIONS
|
|
265
|
-
// --------------------------------------------------------------------------
|
|
266
251
|
async getCollections() {
|
|
267
252
|
return safe(this.client.query("collections"));
|
|
268
253
|
}
|
|
@@ -287,9 +272,6 @@ var CatalogueQueries = class {
|
|
|
287
272
|
this.client.query(`collections[?(@.name contains '${query2}')]#limit(${limit})`)
|
|
288
273
|
);
|
|
289
274
|
}
|
|
290
|
-
// --------------------------------------------------------------------------
|
|
291
|
-
// BUNDLES
|
|
292
|
-
// --------------------------------------------------------------------------
|
|
293
275
|
async getBundles() {
|
|
294
276
|
return safe(this.client.query("bundles"));
|
|
295
277
|
}
|
|
@@ -311,9 +293,6 @@ var CatalogueQueries = class {
|
|
|
311
293
|
this.client.query(`bundles[?(@.name contains '${query2}')]#limit(${limit})`)
|
|
312
294
|
);
|
|
313
295
|
}
|
|
314
|
-
// --------------------------------------------------------------------------
|
|
315
|
-
// COMPOSITES (Build-Your-Own)
|
|
316
|
-
// --------------------------------------------------------------------------
|
|
317
296
|
async getComposites(options) {
|
|
318
297
|
let query2 = "composites";
|
|
319
298
|
if (options?.limit) {
|
|
@@ -336,9 +315,6 @@ var CatalogueQueries = class {
|
|
|
336
315
|
})
|
|
337
316
|
);
|
|
338
317
|
}
|
|
339
|
-
// --------------------------------------------------------------------------
|
|
340
|
-
// SEARCH
|
|
341
|
-
// --------------------------------------------------------------------------
|
|
342
318
|
async search(query2, options) {
|
|
343
319
|
const limit = options?.limit ?? 20;
|
|
344
320
|
let searchQuery = `products[?(@.name contains '${query2}')]`;
|
|
@@ -357,9 +333,6 @@ var CatalogueQueries = class {
|
|
|
357
333
|
})
|
|
358
334
|
);
|
|
359
335
|
}
|
|
360
|
-
// --------------------------------------------------------------------------
|
|
361
|
-
// MENU (Restaurant-specific)
|
|
362
|
-
// --------------------------------------------------------------------------
|
|
363
336
|
async getMenu(options) {
|
|
364
337
|
let query2 = "menu";
|
|
365
338
|
if (options?.category) {
|
|
@@ -397,13 +370,6 @@ var CartOperations = class {
|
|
|
397
370
|
constructor(client) {
|
|
398
371
|
this.client = client;
|
|
399
372
|
}
|
|
400
|
-
// --------------------------------------------------------------------------
|
|
401
|
-
// CART QUERIES
|
|
402
|
-
// --------------------------------------------------------------------------
|
|
403
|
-
/**
|
|
404
|
-
* Get the enriched cart with product names, images, and details.
|
|
405
|
-
* This is the main method for storefront display.
|
|
406
|
-
*/
|
|
407
373
|
async get() {
|
|
408
374
|
return safe2(this.client.query("cart#enriched"));
|
|
409
375
|
}
|
|
@@ -433,33 +399,6 @@ var CartOperations = class {
|
|
|
433
399
|
currency: cart.pricing.currency
|
|
434
400
|
});
|
|
435
401
|
}
|
|
436
|
-
// --------------------------------------------------------------------------
|
|
437
|
-
// CART MUTATIONS
|
|
438
|
-
// --------------------------------------------------------------------------
|
|
439
|
-
/**
|
|
440
|
-
* Add an item to the cart.
|
|
441
|
-
*
|
|
442
|
-
* @example
|
|
443
|
-
* ```typescript
|
|
444
|
-
* const result = await client.cart.addItem({
|
|
445
|
-
* item_id: "prod_burger",
|
|
446
|
-
* quantity: 2,
|
|
447
|
-
* variant_id: "var_large",
|
|
448
|
-
* add_on_options: ["addon_cheese", "addon_bacon"],
|
|
449
|
-
* });
|
|
450
|
-
*
|
|
451
|
-
* if (!result.ok) {
|
|
452
|
-
* switch (result.error.code) {
|
|
453
|
-
* case ErrorCode.ITEM_UNAVAILABLE:
|
|
454
|
-
* toast.error("Item no longer available");
|
|
455
|
-
* break;
|
|
456
|
-
* case ErrorCode.VARIANT_OUT_OF_STOCK:
|
|
457
|
-
* toast.error("Selected option is out of stock");
|
|
458
|
-
* break;
|
|
459
|
-
* }
|
|
460
|
-
* }
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
402
|
async addItem(input) {
|
|
464
403
|
return safe2(this.client.call("cart.addItem", input));
|
|
465
404
|
}
|
|
@@ -489,9 +428,6 @@ var CartOperations = class {
|
|
|
489
428
|
async clear() {
|
|
490
429
|
return safe2(this.client.call("cart.clearCart"));
|
|
491
430
|
}
|
|
492
|
-
// --------------------------------------------------------------------------
|
|
493
|
-
// COUPONS & DISCOUNTS
|
|
494
|
-
// --------------------------------------------------------------------------
|
|
495
431
|
async applyCoupon(code) {
|
|
496
432
|
return safe2(
|
|
497
433
|
this.client.call("cart.applyCoupon", {
|
|
@@ -502,9 +438,6 @@ var CartOperations = class {
|
|
|
502
438
|
async removeCoupon() {
|
|
503
439
|
return safe2(this.client.call("cart.removeCoupon"));
|
|
504
440
|
}
|
|
505
|
-
// --------------------------------------------------------------------------
|
|
506
|
-
// CONVENIENCE METHODS
|
|
507
|
-
// --------------------------------------------------------------------------
|
|
508
441
|
async isEmpty() {
|
|
509
442
|
const countResult = await this.getCount();
|
|
510
443
|
if (!countResult.ok) return countResult;
|
|
@@ -657,35 +590,6 @@ var CheckoutService = class {
|
|
|
657
590
|
constructor(client) {
|
|
658
591
|
this.client = client;
|
|
659
592
|
}
|
|
660
|
-
/**
|
|
661
|
-
* Process checkout with cart data.
|
|
662
|
-
*
|
|
663
|
-
* Automatically generates an idempotency key if not provided to ensure
|
|
664
|
-
* payment safety. The same key is used across retries, preventing
|
|
665
|
-
* duplicate charges if a network error occurs after payment processing.
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```typescript
|
|
669
|
-
* const result = await client.checkout.process({
|
|
670
|
-
* cart_id: cart.id,
|
|
671
|
-
* customer: { name, email, phone, save_details: true },
|
|
672
|
-
* order_type: "pickup",
|
|
673
|
-
* payment_method: "mobile_money",
|
|
674
|
-
* mobile_money_details: { phone_number, provider: "mtn" },
|
|
675
|
-
* });
|
|
676
|
-
*
|
|
677
|
-
* if (!result.ok) {
|
|
678
|
-
* switch (result.error.code) {
|
|
679
|
-
* case ErrorCode.CART_EMPTY:
|
|
680
|
-
* toast.error("Your cart is empty");
|
|
681
|
-
* break;
|
|
682
|
-
* case ErrorCode.PAYMENT_FAILED:
|
|
683
|
-
* toast.error("Payment failed. Please try again.");
|
|
684
|
-
* break;
|
|
685
|
-
* }
|
|
686
|
-
* }
|
|
687
|
-
* ```
|
|
688
|
-
*/
|
|
689
593
|
async process(data) {
|
|
690
594
|
const checkoutData = {
|
|
691
595
|
...data,
|
|
@@ -803,9 +707,6 @@ var LinkService = class {
|
|
|
803
707
|
constructor(client) {
|
|
804
708
|
this.client = client;
|
|
805
709
|
}
|
|
806
|
-
// --------------------------------------------------------------------------
|
|
807
|
-
// AUTHENTICATION
|
|
808
|
-
// --------------------------------------------------------------------------
|
|
809
710
|
async requestOtp(input) {
|
|
810
711
|
return safe5(this.client.linkPost("/v1/link/auth/request-otp", input));
|
|
811
712
|
}
|
|
@@ -825,9 +726,6 @@ var LinkService = class {
|
|
|
825
726
|
}
|
|
826
727
|
return result;
|
|
827
728
|
}
|
|
828
|
-
// --------------------------------------------------------------------------
|
|
829
|
-
// STATUS & DATA
|
|
830
|
-
// --------------------------------------------------------------------------
|
|
831
729
|
async checkStatus(contact) {
|
|
832
730
|
return safe5(
|
|
833
731
|
this.client.call(LINK_MUTATION.CHECK_STATUS, {
|
|
@@ -847,9 +745,6 @@ var LinkService = class {
|
|
|
847
745
|
async getPreferences() {
|
|
848
746
|
return safe5(this.client.query(LINK_QUERY.PREFERENCES));
|
|
849
747
|
}
|
|
850
|
-
// --------------------------------------------------------------------------
|
|
851
|
-
// ENROLLMENT
|
|
852
|
-
// --------------------------------------------------------------------------
|
|
853
748
|
async enroll(data) {
|
|
854
749
|
return safe5(this.client.call(LINK_MUTATION.ENROLL, data));
|
|
855
750
|
}
|
|
@@ -858,15 +753,9 @@ var LinkService = class {
|
|
|
858
753
|
this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data)
|
|
859
754
|
);
|
|
860
755
|
}
|
|
861
|
-
// --------------------------------------------------------------------------
|
|
862
|
-
// PREFERENCES
|
|
863
|
-
// --------------------------------------------------------------------------
|
|
864
756
|
async updatePreferences(preferences) {
|
|
865
757
|
return safe5(this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences));
|
|
866
758
|
}
|
|
867
|
-
// --------------------------------------------------------------------------
|
|
868
|
-
// ADDRESSES
|
|
869
|
-
// --------------------------------------------------------------------------
|
|
870
759
|
async createAddress(input) {
|
|
871
760
|
return safe5(this.client.call(LINK_MUTATION.CREATE_ADDRESS, input));
|
|
872
761
|
}
|
|
@@ -886,9 +775,6 @@ var LinkService = class {
|
|
|
886
775
|
})
|
|
887
776
|
);
|
|
888
777
|
}
|
|
889
|
-
// --------------------------------------------------------------------------
|
|
890
|
-
// MOBILE MONEY
|
|
891
|
-
// --------------------------------------------------------------------------
|
|
892
778
|
async createMobileMoney(input) {
|
|
893
779
|
return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
|
|
894
780
|
}
|
|
@@ -912,9 +798,6 @@ var LinkService = class {
|
|
|
912
798
|
this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId)
|
|
913
799
|
);
|
|
914
800
|
}
|
|
915
|
-
// --------------------------------------------------------------------------
|
|
916
|
-
// SESSIONS
|
|
917
|
-
// --------------------------------------------------------------------------
|
|
918
801
|
async getSessions() {
|
|
919
802
|
return safe5(this.client.linkGet("/v1/link/sessions"));
|
|
920
803
|
}
|
|
@@ -924,9 +807,6 @@ var LinkService = class {
|
|
|
924
807
|
async revokeAllSessions() {
|
|
925
808
|
return safe5(this.client.linkDelete("/v1/link/sessions"));
|
|
926
809
|
}
|
|
927
|
-
// --------------------------------------------------------------------------
|
|
928
|
-
// REST ALTERNATIVES (for direct API access)
|
|
929
|
-
// --------------------------------------------------------------------------
|
|
930
810
|
async getAddressesRest() {
|
|
931
811
|
return safe5(this.client.linkGet("/v1/link/addresses"));
|
|
932
812
|
}
|
|
@@ -974,9 +854,6 @@ var AuthService = class {
|
|
|
974
854
|
constructor(client) {
|
|
975
855
|
this.client = client;
|
|
976
856
|
}
|
|
977
|
-
// --------------------------------------------------------------------------
|
|
978
|
-
// STATUS & USER
|
|
979
|
-
// --------------------------------------------------------------------------
|
|
980
857
|
async getStatus() {
|
|
981
858
|
return safe6(this.client.query("auth"));
|
|
982
859
|
}
|
|
@@ -990,9 +867,6 @@ var AuthService = class {
|
|
|
990
867
|
if (!result.ok) return result;
|
|
991
868
|
return ok(result.value.is_authenticated);
|
|
992
869
|
}
|
|
993
|
-
// --------------------------------------------------------------------------
|
|
994
|
-
// OTP AUTHENTICATION
|
|
995
|
-
// --------------------------------------------------------------------------
|
|
996
870
|
async requestOtp(contact, contactType) {
|
|
997
871
|
return safe6(
|
|
998
872
|
this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
@@ -1009,15 +883,9 @@ var AuthService = class {
|
|
|
1009
883
|
})
|
|
1010
884
|
);
|
|
1011
885
|
}
|
|
1012
|
-
// --------------------------------------------------------------------------
|
|
1013
|
-
// SESSION MANAGEMENT
|
|
1014
|
-
// --------------------------------------------------------------------------
|
|
1015
886
|
async logout() {
|
|
1016
887
|
return safe6(this.client.call("auth.logout"));
|
|
1017
888
|
}
|
|
1018
|
-
// --------------------------------------------------------------------------
|
|
1019
|
-
// PROFILE MANAGEMENT
|
|
1020
|
-
// --------------------------------------------------------------------------
|
|
1021
889
|
async updateProfile(input) {
|
|
1022
890
|
return safe6(this.client.call("auth.update_profile", input));
|
|
1023
891
|
}
|
|
@@ -1048,9 +916,6 @@ var BusinessService = class {
|
|
|
1048
916
|
constructor(client) {
|
|
1049
917
|
this.client = client;
|
|
1050
918
|
}
|
|
1051
|
-
// --------------------------------------------------------------------------
|
|
1052
|
-
// BUSINESS INFO
|
|
1053
|
-
// --------------------------------------------------------------------------
|
|
1054
919
|
async getInfo() {
|
|
1055
920
|
return safe7(this.client.query("business.info"));
|
|
1056
921
|
}
|
|
@@ -1066,27 +931,18 @@ var BusinessService = class {
|
|
|
1066
931
|
async getTheme() {
|
|
1067
932
|
return safe7(this.client.query("business.theme"));
|
|
1068
933
|
}
|
|
1069
|
-
// --------------------------------------------------------------------------
|
|
1070
|
-
// LOCATIONS
|
|
1071
|
-
// --------------------------------------------------------------------------
|
|
1072
934
|
async getLocations() {
|
|
1073
935
|
return safe7(this.client.query("business.locations"));
|
|
1074
936
|
}
|
|
1075
937
|
async getLocation(locationId) {
|
|
1076
938
|
return safe7(this.client.query(`business.locations.${locationId}`));
|
|
1077
939
|
}
|
|
1078
|
-
// --------------------------------------------------------------------------
|
|
1079
|
-
// HOURS
|
|
1080
|
-
// --------------------------------------------------------------------------
|
|
1081
940
|
async getHours() {
|
|
1082
941
|
return safe7(this.client.query("business.hours"));
|
|
1083
942
|
}
|
|
1084
943
|
async getLocationHours(locationId) {
|
|
1085
944
|
return safe7(this.client.query(`business.locations.${locationId}.hours`));
|
|
1086
945
|
}
|
|
1087
|
-
// --------------------------------------------------------------------------
|
|
1088
|
-
// BOOTSTRAP (for storefront initialization)
|
|
1089
|
-
// --------------------------------------------------------------------------
|
|
1090
946
|
async getBootstrap() {
|
|
1091
947
|
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
1092
948
|
this.getInfo(),
|
|
@@ -1131,9 +987,6 @@ var InventoryService = class {
|
|
|
1131
987
|
constructor(client) {
|
|
1132
988
|
this.client = client;
|
|
1133
989
|
}
|
|
1134
|
-
// --------------------------------------------------------------------------
|
|
1135
|
-
// STOCK QUERIES
|
|
1136
|
-
// --------------------------------------------------------------------------
|
|
1137
990
|
async getStockLevels() {
|
|
1138
991
|
return safe8(this.client.query("inventory.stock_levels"));
|
|
1139
992
|
}
|
|
@@ -1160,9 +1013,6 @@ var InventoryService = class {
|
|
|
1160
1013
|
})
|
|
1161
1014
|
);
|
|
1162
1015
|
}
|
|
1163
|
-
// --------------------------------------------------------------------------
|
|
1164
|
-
// AVAILABILITY CHECKS
|
|
1165
|
-
// --------------------------------------------------------------------------
|
|
1166
1016
|
async checkProductAvailability(productId, quantity, locationId) {
|
|
1167
1017
|
return safe8(
|
|
1168
1018
|
this.client.query("inventory.check_availability", {
|
|
@@ -1192,15 +1042,9 @@ var InventoryService = class {
|
|
|
1192
1042
|
}
|
|
1193
1043
|
return ok(results.map((r) => r.value));
|
|
1194
1044
|
}
|
|
1195
|
-
// --------------------------------------------------------------------------
|
|
1196
|
-
// SUMMARY
|
|
1197
|
-
// --------------------------------------------------------------------------
|
|
1198
1045
|
async getSummary() {
|
|
1199
1046
|
return safe8(this.client.query("inventory.summary"));
|
|
1200
1047
|
}
|
|
1201
|
-
// --------------------------------------------------------------------------
|
|
1202
|
-
// CONVENIENCE METHODS
|
|
1203
|
-
// --------------------------------------------------------------------------
|
|
1204
1048
|
async isInStock(productId, locationId) {
|
|
1205
1049
|
const result = await this.checkProductAvailability(productId, 1, locationId);
|
|
1206
1050
|
if (!result.ok) return result;
|
|
@@ -1232,9 +1076,6 @@ var SchedulingService = class {
|
|
|
1232
1076
|
constructor(client) {
|
|
1233
1077
|
this.client = client;
|
|
1234
1078
|
}
|
|
1235
|
-
// --------------------------------------------------------------------------
|
|
1236
|
-
// SERVICES
|
|
1237
|
-
// --------------------------------------------------------------------------
|
|
1238
1079
|
async getServices() {
|
|
1239
1080
|
return safe9(this.client.query("scheduling.services"));
|
|
1240
1081
|
}
|
|
@@ -1247,9 +1088,6 @@ var SchedulingService = class {
|
|
|
1247
1088
|
if (!result.ok) return result;
|
|
1248
1089
|
return ok(result.value.find((s) => s.id === serviceId) || null);
|
|
1249
1090
|
}
|
|
1250
|
-
// --------------------------------------------------------------------------
|
|
1251
|
-
// AVAILABILITY
|
|
1252
|
-
// --------------------------------------------------------------------------
|
|
1253
1091
|
async getAvailableSlots(input) {
|
|
1254
1092
|
return safe9(
|
|
1255
1093
|
this.client.query(
|
|
@@ -1274,9 +1112,6 @@ var SchedulingService = class {
|
|
|
1274
1112
|
)
|
|
1275
1113
|
);
|
|
1276
1114
|
}
|
|
1277
|
-
// --------------------------------------------------------------------------
|
|
1278
|
-
// BOOKINGS
|
|
1279
|
-
// --------------------------------------------------------------------------
|
|
1280
1115
|
async getBooking(bookingId) {
|
|
1281
1116
|
return safe9(this.client.query(`scheduling.${bookingId}`));
|
|
1282
1117
|
}
|
|
@@ -1297,18 +1132,12 @@ var SchedulingService = class {
|
|
|
1297
1132
|
)
|
|
1298
1133
|
);
|
|
1299
1134
|
}
|
|
1300
|
-
// --------------------------------------------------------------------------
|
|
1301
|
-
// BOOKING MANAGEMENT
|
|
1302
|
-
// --------------------------------------------------------------------------
|
|
1303
1135
|
async cancelBooking(input) {
|
|
1304
1136
|
return safe9(this.client.call("scheduling.cancel_booking", input));
|
|
1305
1137
|
}
|
|
1306
1138
|
async rescheduleBooking(input) {
|
|
1307
1139
|
return safe9(this.client.call("scheduling.reschedule_booking", input));
|
|
1308
1140
|
}
|
|
1309
|
-
// --------------------------------------------------------------------------
|
|
1310
|
-
// CONVENIENCE METHODS
|
|
1311
|
-
// --------------------------------------------------------------------------
|
|
1312
1141
|
async getNextAvailableSlot(serviceId, fromDate) {
|
|
1313
1142
|
const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
1314
1143
|
const result = await this.getAvailableSlots({
|
|
@@ -1347,15 +1176,9 @@ var LiteService = class {
|
|
|
1347
1176
|
constructor(client) {
|
|
1348
1177
|
this.client = client;
|
|
1349
1178
|
}
|
|
1350
|
-
// --------------------------------------------------------------------------
|
|
1351
|
-
// BOOTSTRAP
|
|
1352
|
-
// --------------------------------------------------------------------------
|
|
1353
1179
|
async getBootstrap() {
|
|
1354
1180
|
return safe10(this.client.query("lite.bootstrap"));
|
|
1355
1181
|
}
|
|
1356
|
-
// --------------------------------------------------------------------------
|
|
1357
|
-
// TABLE MANAGEMENT
|
|
1358
|
-
// --------------------------------------------------------------------------
|
|
1359
1182
|
async getTable(tableId) {
|
|
1360
1183
|
return safe10(this.client.query(`lite.table.${tableId}`));
|
|
1361
1184
|
}
|
|
@@ -1367,9 +1190,6 @@ var LiteService = class {
|
|
|
1367
1190
|
})
|
|
1368
1191
|
);
|
|
1369
1192
|
}
|
|
1370
|
-
// --------------------------------------------------------------------------
|
|
1371
|
-
// KITCHEN ORDERS
|
|
1372
|
-
// --------------------------------------------------------------------------
|
|
1373
1193
|
async sendToKitchen(tableId, items) {
|
|
1374
1194
|
return safe10(
|
|
1375
1195
|
this.client.call("lite.send_to_kitchen", {
|
|
@@ -1393,9 +1213,6 @@ var LiteService = class {
|
|
|
1393
1213
|
})
|
|
1394
1214
|
);
|
|
1395
1215
|
}
|
|
1396
|
-
// --------------------------------------------------------------------------
|
|
1397
|
-
// MENU (optimized for lite/QR experience)
|
|
1398
|
-
// --------------------------------------------------------------------------
|
|
1399
1216
|
async getMenu() {
|
|
1400
1217
|
return safe10(this.client.query("lite.menu"));
|
|
1401
1218
|
}
|
|
@@ -1469,7 +1286,6 @@ function deriveUrls() {
|
|
|
1469
1286
|
var CimplifyClient = class {
|
|
1470
1287
|
constructor(config = {}) {
|
|
1471
1288
|
this.sessionToken = null;
|
|
1472
|
-
/** In-flight request deduplication map */
|
|
1473
1289
|
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
1474
1290
|
this.publicKey = config.publicKey || "";
|
|
1475
1291
|
const urls = deriveUrls();
|
|
@@ -1479,18 +1295,31 @@ var CimplifyClient = class {
|
|
|
1479
1295
|
this.timeout = config.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
1480
1296
|
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1481
1297
|
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
1298
|
+
this.hooks = config.hooks ?? {};
|
|
1482
1299
|
this.sessionToken = this.loadSessionToken();
|
|
1483
1300
|
}
|
|
1484
1301
|
getSessionToken() {
|
|
1485
1302
|
return this.sessionToken;
|
|
1486
1303
|
}
|
|
1487
1304
|
setSessionToken(token) {
|
|
1305
|
+
const previous = this.sessionToken;
|
|
1488
1306
|
this.sessionToken = token;
|
|
1489
1307
|
this.saveSessionToken(token);
|
|
1308
|
+
this.hooks.onSessionChange?.({
|
|
1309
|
+
previousToken: previous,
|
|
1310
|
+
newToken: token,
|
|
1311
|
+
source: "manual"
|
|
1312
|
+
});
|
|
1490
1313
|
}
|
|
1491
1314
|
clearSession() {
|
|
1315
|
+
const previous = this.sessionToken;
|
|
1492
1316
|
this.sessionToken = null;
|
|
1493
1317
|
this.saveSessionToken(null);
|
|
1318
|
+
this.hooks.onSessionChange?.({
|
|
1319
|
+
previousToken: previous,
|
|
1320
|
+
newToken: null,
|
|
1321
|
+
source: "clear"
|
|
1322
|
+
});
|
|
1494
1323
|
}
|
|
1495
1324
|
loadSessionToken() {
|
|
1496
1325
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
@@ -1520,15 +1349,29 @@ var CimplifyClient = class {
|
|
|
1520
1349
|
updateSessionFromResponse(response) {
|
|
1521
1350
|
const newToken = response.headers.get(SESSION_TOKEN_HEADER);
|
|
1522
1351
|
if (newToken && newToken !== this.sessionToken) {
|
|
1352
|
+
const previous = this.sessionToken;
|
|
1523
1353
|
this.sessionToken = newToken;
|
|
1524
1354
|
this.saveSessionToken(newToken);
|
|
1355
|
+
this.hooks.onSessionChange?.({
|
|
1356
|
+
previousToken: previous,
|
|
1357
|
+
newToken,
|
|
1358
|
+
source: "response"
|
|
1359
|
+
});
|
|
1525
1360
|
}
|
|
1526
1361
|
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Resilient fetch with timeout and automatic retries for network errors.
|
|
1529
|
-
* Uses exponential backoff: 1s, 2s, 4s between retries.
|
|
1530
|
-
*/
|
|
1531
1362
|
async resilientFetch(url, options) {
|
|
1363
|
+
const method = options.method || "GET";
|
|
1364
|
+
const path = url.replace(this.baseUrl, "").replace(this.linkApiUrl, "");
|
|
1365
|
+
const startTime = Date.now();
|
|
1366
|
+
let retryCount = 0;
|
|
1367
|
+
const context = {
|
|
1368
|
+
method,
|
|
1369
|
+
path,
|
|
1370
|
+
url,
|
|
1371
|
+
body: options.body ? JSON.parse(options.body) : void 0,
|
|
1372
|
+
startTime
|
|
1373
|
+
};
|
|
1374
|
+
this.hooks.onRequestStart?.(context);
|
|
1532
1375
|
let lastError;
|
|
1533
1376
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
1534
1377
|
try {
|
|
@@ -1540,37 +1383,69 @@ var CimplifyClient = class {
|
|
|
1540
1383
|
});
|
|
1541
1384
|
clearTimeout(timeoutId);
|
|
1542
1385
|
if (response.ok || response.status >= 400 && response.status < 500) {
|
|
1386
|
+
this.hooks.onRequestSuccess?.({
|
|
1387
|
+
...context,
|
|
1388
|
+
status: response.status,
|
|
1389
|
+
durationMs: Date.now() - startTime
|
|
1390
|
+
});
|
|
1543
1391
|
return response;
|
|
1544
1392
|
}
|
|
1545
1393
|
if (response.status >= 500 && attempt < this.maxRetries) {
|
|
1394
|
+
retryCount++;
|
|
1546
1395
|
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
1396
|
+
this.hooks.onRetry?.({
|
|
1397
|
+
...context,
|
|
1398
|
+
attempt: retryCount,
|
|
1399
|
+
delayMs: delay,
|
|
1400
|
+
error: new Error(`Server error: ${response.status}`)
|
|
1401
|
+
});
|
|
1547
1402
|
await sleep(delay);
|
|
1548
1403
|
continue;
|
|
1549
1404
|
}
|
|
1405
|
+
this.hooks.onRequestSuccess?.({
|
|
1406
|
+
...context,
|
|
1407
|
+
status: response.status,
|
|
1408
|
+
durationMs: Date.now() - startTime
|
|
1409
|
+
});
|
|
1550
1410
|
return response;
|
|
1551
1411
|
} catch (error) {
|
|
1552
1412
|
lastError = error;
|
|
1553
|
-
|
|
1554
|
-
|
|
1413
|
+
const networkError = toNetworkError(error);
|
|
1414
|
+
const errorRetryable = isRetryable(error);
|
|
1415
|
+
if (!errorRetryable || attempt >= this.maxRetries) {
|
|
1416
|
+
this.hooks.onRequestError?.({
|
|
1417
|
+
...context,
|
|
1418
|
+
error: networkError,
|
|
1419
|
+
durationMs: Date.now() - startTime,
|
|
1420
|
+
retryCount,
|
|
1421
|
+
retryable: errorRetryable
|
|
1422
|
+
});
|
|
1423
|
+
throw networkError;
|
|
1555
1424
|
}
|
|
1425
|
+
retryCount++;
|
|
1556
1426
|
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
1427
|
+
this.hooks.onRetry?.({
|
|
1428
|
+
...context,
|
|
1429
|
+
attempt: retryCount,
|
|
1430
|
+
delayMs: delay,
|
|
1431
|
+
error: networkError
|
|
1432
|
+
});
|
|
1557
1433
|
await sleep(delay);
|
|
1558
1434
|
}
|
|
1559
1435
|
}
|
|
1560
|
-
|
|
1436
|
+
const finalError = toNetworkError(lastError);
|
|
1437
|
+
this.hooks.onRequestError?.({
|
|
1438
|
+
...context,
|
|
1439
|
+
error: finalError,
|
|
1440
|
+
durationMs: Date.now() - startTime,
|
|
1441
|
+
retryCount,
|
|
1442
|
+
retryable: false
|
|
1443
|
+
});
|
|
1444
|
+
throw finalError;
|
|
1561
1445
|
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Generate a deduplication key for a request.
|
|
1564
|
-
* Same query + variables = same key = deduplicated.
|
|
1565
|
-
*/
|
|
1566
1446
|
getDedupeKey(type, payload) {
|
|
1567
1447
|
return `${type}:${JSON.stringify(payload)}`;
|
|
1568
1448
|
}
|
|
1569
|
-
/**
|
|
1570
|
-
* Execute a request with deduplication.
|
|
1571
|
-
* If an identical request is already in-flight, return the same promise.
|
|
1572
|
-
* This prevents redundant network calls when multiple components request the same data.
|
|
1573
|
-
*/
|
|
1574
1449
|
async deduplicatedRequest(key, requestFn) {
|
|
1575
1450
|
const existing = this.inflightRequests.get(key);
|
|
1576
1451
|
if (existing) {
|
|
@@ -1582,10 +1457,6 @@ var CimplifyClient = class {
|
|
|
1582
1457
|
this.inflightRequests.set(key, request);
|
|
1583
1458
|
return request;
|
|
1584
1459
|
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Execute a query with deduplication.
|
|
1587
|
-
* Multiple identical queries made simultaneously will share a single network request.
|
|
1588
|
-
*/
|
|
1589
1460
|
async query(query2, variables) {
|
|
1590
1461
|
const body = { query: query2 };
|
|
1591
1462
|
if (variables) {
|
|
@@ -1603,9 +1474,6 @@ var CimplifyClient = class {
|
|
|
1603
1474
|
return this.handleResponse(response);
|
|
1604
1475
|
});
|
|
1605
1476
|
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Execute a mutation. NOT deduplicated - mutations have side effects.
|
|
1608
|
-
*/
|
|
1609
1477
|
async call(method, args) {
|
|
1610
1478
|
const body = {
|
|
1611
1479
|
method,
|