@cimplify/sdk 0.2.5 → 0.3.1

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.js CHANGED
@@ -66,7 +66,91 @@ function isRetryableError(error) {
66
66
  return false;
67
67
  }
68
68
 
69
+ // src/types/result.ts
70
+ function ok(value) {
71
+ return { ok: true, value };
72
+ }
73
+ function err(error) {
74
+ return { ok: false, error };
75
+ }
76
+ function isOk(result) {
77
+ return result.ok === true;
78
+ }
79
+ function isErr(result) {
80
+ return result.ok === false;
81
+ }
82
+ function mapResult(result, fn) {
83
+ return result.ok ? ok(fn(result.value)) : result;
84
+ }
85
+ function mapError(result, fn) {
86
+ return result.ok ? result : err(fn(result.error));
87
+ }
88
+ function flatMap(result, fn) {
89
+ return result.ok ? fn(result.value) : result;
90
+ }
91
+ function getOrElse(result, defaultFn) {
92
+ return result.ok ? result.value : defaultFn();
93
+ }
94
+ function unwrap(result) {
95
+ if (result.ok) {
96
+ return result.value;
97
+ }
98
+ throw result.error;
99
+ }
100
+ function toNullable(result) {
101
+ return result.ok ? result.value : void 0;
102
+ }
103
+ async function fromPromise(promise, mapError2) {
104
+ try {
105
+ const value = await promise;
106
+ return ok(value);
107
+ } catch (error) {
108
+ return err(mapError2(error));
109
+ }
110
+ }
111
+ function tryCatch(fn, mapError2) {
112
+ try {
113
+ return ok(fn());
114
+ } catch (error) {
115
+ return err(mapError2(error));
116
+ }
117
+ }
118
+ function combine(results) {
119
+ const values = [];
120
+ for (const result of results) {
121
+ if (!result.ok) {
122
+ return result;
123
+ }
124
+ values.push(result.value);
125
+ }
126
+ return ok(values);
127
+ }
128
+ function combineObject(results) {
129
+ const values = {};
130
+ for (const [key, result] of Object.entries(results)) {
131
+ if (!result.ok) {
132
+ return result;
133
+ }
134
+ values[key] = result.value;
135
+ }
136
+ return ok(values);
137
+ }
138
+
69
139
  // src/catalogue.ts
140
+ function toCimplifyError(error) {
141
+ if (error instanceof CimplifyError) return error;
142
+ if (error instanceof Error) {
143
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
144
+ }
145
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
146
+ }
147
+ async function safe(promise) {
148
+ try {
149
+ return ok(await promise);
150
+ } catch (error) {
151
+ return err(toCimplifyError(error));
152
+ }
153
+ }
70
154
  var CatalogueQueries = class {
71
155
  constructor(client) {
72
156
  this.client = client;
@@ -107,111 +191,125 @@ var CatalogueQueries = class {
107
191
  if (options?.offset) {
108
192
  query2 += `#offset(${options.offset})`;
109
193
  }
110
- return this.client.query(query2);
194
+ return safe(this.client.query(query2));
111
195
  }
112
196
  async getProduct(id) {
113
- return this.client.query(`products.${id}`);
197
+ return safe(this.client.query(`products.${id}`));
114
198
  }
115
199
  async getProductBySlug(slug) {
116
- const products = await this.client.query(
117
- `products[?(@.slug=='${slug}')]`
200
+ const result = await safe(
201
+ this.client.query(`products[?(@.slug=='${slug}')]`)
118
202
  );
119
- if (!products.length) {
120
- throw new Error(`Product not found: ${slug}`);
203
+ if (!result.ok) return result;
204
+ if (!result.value.length) {
205
+ return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
121
206
  }
122
- return products[0];
207
+ return ok(result.value[0]);
123
208
  }
124
209
  // --------------------------------------------------------------------------
125
210
  // VARIANTS
126
211
  // --------------------------------------------------------------------------
127
212
  async getVariants(productId) {
128
- return this.client.query(`products.${productId}.variants`);
213
+ return safe(this.client.query(`products.${productId}.variants`));
129
214
  }
130
215
  async getVariantAxes(productId) {
131
- return this.client.query(`products.${productId}.variant_axes`);
216
+ return safe(this.client.query(`products.${productId}.variant_axes`));
132
217
  }
133
218
  /**
134
219
  * Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
135
220
  * Returns the matching variant or null if no match found.
136
221
  */
137
222
  async getVariantByAxisSelections(productId, selections) {
138
- return this.client.query(`products.${productId}.variant`, {
139
- axis_selections: selections
140
- });
223
+ return safe(
224
+ this.client.query(`products.${productId}.variant`, {
225
+ axis_selections: selections
226
+ })
227
+ );
141
228
  }
142
229
  /**
143
230
  * Get a specific variant by its ID
144
231
  */
145
232
  async getVariantById(productId, variantId) {
146
- return this.client.query(`products.${productId}.variant.${variantId}`);
233
+ return safe(this.client.query(`products.${productId}.variant.${variantId}`));
147
234
  }
148
235
  // --------------------------------------------------------------------------
149
236
  // ADD-ONS
150
237
  // --------------------------------------------------------------------------
151
238
  async getAddOns(productId) {
152
- return this.client.query(`products.${productId}.add_ons`);
239
+ return safe(this.client.query(`products.${productId}.add_ons`));
153
240
  }
154
241
  // --------------------------------------------------------------------------
155
242
  // CATEGORIES
156
243
  // --------------------------------------------------------------------------
157
244
  async getCategories() {
158
- return this.client.query("categories");
245
+ return safe(this.client.query("categories"));
159
246
  }
160
247
  async getCategory(id) {
161
- return this.client.query(`categories.${id}`);
248
+ return safe(this.client.query(`categories.${id}`));
162
249
  }
163
250
  async getCategoryBySlug(slug) {
164
- const categories = await this.client.query(`categories[?(@.slug=='${slug}')]`);
165
- if (!categories.length) {
166
- throw new Error(`Category not found: ${slug}`);
251
+ const result = await safe(
252
+ this.client.query(`categories[?(@.slug=='${slug}')]`)
253
+ );
254
+ if (!result.ok) return result;
255
+ if (!result.value.length) {
256
+ return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
167
257
  }
168
- return categories[0];
258
+ return ok(result.value[0]);
169
259
  }
170
260
  async getCategoryProducts(categoryId) {
171
- return this.client.query(`products[?(@.category_id=='${categoryId}')]`);
261
+ return safe(this.client.query(`products[?(@.category_id=='${categoryId}')]`));
172
262
  }
173
263
  // --------------------------------------------------------------------------
174
264
  // COLLECTIONS
175
265
  // --------------------------------------------------------------------------
176
266
  async getCollections() {
177
- return this.client.query("collections");
267
+ return safe(this.client.query("collections"));
178
268
  }
179
269
  async getCollection(id) {
180
- return this.client.query(`collections.${id}`);
270
+ return safe(this.client.query(`collections.${id}`));
181
271
  }
182
272
  async getCollectionBySlug(slug) {
183
- const collections = await this.client.query(`collections[?(@.slug=='${slug}')]`);
184
- if (!collections.length) {
185
- throw new Error(`Collection not found: ${slug}`);
273
+ const result = await safe(
274
+ this.client.query(`collections[?(@.slug=='${slug}')]`)
275
+ );
276
+ if (!result.ok) return result;
277
+ if (!result.value.length) {
278
+ return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
186
279
  }
187
- return collections[0];
280
+ return ok(result.value[0]);
188
281
  }
189
282
  async getCollectionProducts(collectionId) {
190
- return this.client.query(`collections.${collectionId}.products`);
283
+ return safe(this.client.query(`collections.${collectionId}.products`));
191
284
  }
192
285
  async searchCollections(query2, limit = 20) {
193
- return this.client.query(
194
- `collections[?(@.name contains '${query2}')]#limit(${limit})`
286
+ return safe(
287
+ this.client.query(`collections[?(@.name contains '${query2}')]#limit(${limit})`)
195
288
  );
196
289
  }
197
290
  // --------------------------------------------------------------------------
198
291
  // BUNDLES
199
292
  // --------------------------------------------------------------------------
200
293
  async getBundles() {
201
- return this.client.query("bundles");
294
+ return safe(this.client.query("bundles"));
202
295
  }
203
296
  async getBundle(id) {
204
- return this.client.query(`bundles.${id}`);
297
+ return safe(this.client.query(`bundles.${id}`));
205
298
  }
206
299
  async getBundleBySlug(slug) {
207
- const bundles = await this.client.query(`bundles[?(@.slug=='${slug}')]`);
208
- if (!bundles.length) {
209
- throw new Error(`Bundle not found: ${slug}`);
300
+ const result = await safe(
301
+ this.client.query(`bundles[?(@.slug=='${slug}')]`)
302
+ );
303
+ if (!result.ok) return result;
304
+ if (!result.value.length) {
305
+ return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
210
306
  }
211
- return bundles[0];
307
+ return ok(result.value[0]);
212
308
  }
213
309
  async searchBundles(query2, limit = 20) {
214
- return this.client.query(`bundles[?(@.name contains '${query2}')]#limit(${limit})`);
310
+ return safe(
311
+ this.client.query(`bundles[?(@.name contains '${query2}')]#limit(${limit})`)
312
+ );
215
313
  }
216
314
  // --------------------------------------------------------------------------
217
315
  // COMPOSITES (Build-Your-Own)
@@ -221,20 +319,22 @@ var CatalogueQueries = class {
221
319
  if (options?.limit) {
222
320
  query2 += `#limit(${options.limit})`;
223
321
  }
224
- return this.client.query(query2);
322
+ return safe(this.client.query(query2));
225
323
  }
226
324
  async getComposite(id) {
227
- return this.client.query(`composites.${id}`);
325
+ return safe(this.client.query(`composites.${id}`));
228
326
  }
229
327
  async getCompositeByProductId(productId) {
230
- return this.client.query(`composites.by_product.${productId}`);
328
+ return safe(this.client.query(`composites.by_product.${productId}`));
231
329
  }
232
330
  async calculateCompositePrice(compositeId, selections, locationId) {
233
- return this.client.call("composite.calculatePrice", {
234
- composite_id: compositeId,
235
- selections,
236
- location_id: locationId
237
- });
331
+ return safe(
332
+ this.client.call("composite.calculatePrice", {
333
+ composite_id: compositeId,
334
+ selections,
335
+ location_id: locationId
336
+ })
337
+ );
238
338
  }
239
339
  // --------------------------------------------------------------------------
240
340
  // SEARCH
@@ -246,14 +346,16 @@ var CatalogueQueries = class {
246
346
  searchQuery = `products[?(@.name contains '${query2}' && @.category_id=='${options.category}')]`;
247
347
  }
248
348
  searchQuery += `#limit(${limit})`;
249
- return this.client.query(searchQuery);
349
+ return safe(this.client.query(searchQuery));
250
350
  }
251
351
  async searchProducts(query2, options) {
252
- return this.client.call("catalogue.search", {
253
- query: query2,
254
- limit: options?.limit ?? 20,
255
- category: options?.category
256
- });
352
+ return safe(
353
+ this.client.call("catalogue.search", {
354
+ query: query2,
355
+ limit: options?.limit ?? 20,
356
+ category: options?.category
357
+ })
358
+ );
257
359
  }
258
360
  // --------------------------------------------------------------------------
259
361
  // MENU (Restaurant-specific)
@@ -266,17 +368,31 @@ var CatalogueQueries = class {
266
368
  if (options?.limit) {
267
369
  query2 += `#limit(${options.limit})`;
268
370
  }
269
- return this.client.query(query2);
371
+ return safe(this.client.query(query2));
270
372
  }
271
373
  async getMenuCategory(categoryId) {
272
- return this.client.query(`menu.category.${categoryId}`);
374
+ return safe(this.client.query(`menu.category.${categoryId}`));
273
375
  }
274
376
  async getMenuItem(itemId) {
275
- return this.client.query(`menu.${itemId}`);
377
+ return safe(this.client.query(`menu.${itemId}`));
276
378
  }
277
379
  };
278
380
 
279
381
  // src/cart.ts
382
+ function toCimplifyError2(error) {
383
+ if (error instanceof CimplifyError) return error;
384
+ if (error instanceof Error) {
385
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
386
+ }
387
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
388
+ }
389
+ async function safe2(promise) {
390
+ try {
391
+ return ok(await promise);
392
+ } catch (error) {
393
+ return err(toCimplifyError2(error));
394
+ }
395
+ }
280
396
  var CartOperations = class {
281
397
  constructor(client) {
282
398
  this.client = client;
@@ -289,23 +405,25 @@ var CartOperations = class {
289
405
  * This is the main method for storefront display.
290
406
  */
291
407
  async get() {
292
- return this.client.query("cart#enriched");
408
+ return safe2(this.client.query("cart#enriched"));
293
409
  }
294
410
  async getRaw() {
295
- return this.client.query("cart");
411
+ return safe2(this.client.query("cart"));
296
412
  }
297
413
  async getItems() {
298
- return this.client.query("cart_items");
414
+ return safe2(this.client.query("cart_items"));
299
415
  }
300
416
  async getCount() {
301
- return this.client.query("cart#count");
417
+ return safe2(this.client.query("cart#count"));
302
418
  }
303
419
  async getTotal() {
304
- return this.client.query("cart#total");
420
+ return safe2(this.client.query("cart#total"));
305
421
  }
306
422
  async getSummary() {
307
- const cart = await this.get();
308
- return {
423
+ const cartResult = await this.get();
424
+ if (!cartResult.ok) return cartResult;
425
+ const cart = cartResult.value;
426
+ return ok({
309
427
  item_count: cart.items.length,
310
428
  total_items: cart.items.reduce((sum, item) => sum + item.quantity, 0),
311
429
  subtotal: cart.pricing.subtotal,
@@ -313,55 +431,89 @@ var CartOperations = class {
313
431
  tax_amount: cart.pricing.tax_amount,
314
432
  total: cart.pricing.total_price,
315
433
  currency: cart.pricing.currency
316
- };
434
+ });
317
435
  }
318
436
  // --------------------------------------------------------------------------
319
437
  // CART MUTATIONS
320
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
+ */
321
463
  async addItem(input) {
322
- return this.client.call("cart.addItem", input);
464
+ return safe2(this.client.call("cart.addItem", input));
323
465
  }
324
466
  async updateItem(cartItemId, updates) {
325
- return this.client.call("cart.updateItem", {
326
- cart_item_id: cartItemId,
327
- ...updates
328
- });
467
+ return safe2(
468
+ this.client.call("cart.updateItem", {
469
+ cart_item_id: cartItemId,
470
+ ...updates
471
+ })
472
+ );
329
473
  }
330
474
  async updateQuantity(cartItemId, quantity) {
331
- return this.client.call("cart.updateItemQuantity", {
332
- cart_item_id: cartItemId,
333
- quantity
334
- });
475
+ return safe2(
476
+ this.client.call("cart.updateItemQuantity", {
477
+ cart_item_id: cartItemId,
478
+ quantity
479
+ })
480
+ );
335
481
  }
336
482
  async removeItem(cartItemId) {
337
- return this.client.call("cart.removeItem", {
338
- cart_item_id: cartItemId
339
- });
483
+ return safe2(
484
+ this.client.call("cart.removeItem", {
485
+ cart_item_id: cartItemId
486
+ })
487
+ );
340
488
  }
341
489
  async clear() {
342
- return this.client.call("cart.clearCart");
490
+ return safe2(this.client.call("cart.clearCart"));
343
491
  }
344
492
  // --------------------------------------------------------------------------
345
493
  // COUPONS & DISCOUNTS
346
494
  // --------------------------------------------------------------------------
347
495
  async applyCoupon(code) {
348
- return this.client.call("cart.applyCoupon", {
349
- coupon_code: code
350
- });
496
+ return safe2(
497
+ this.client.call("cart.applyCoupon", {
498
+ coupon_code: code
499
+ })
500
+ );
351
501
  }
352
502
  async removeCoupon() {
353
- return this.client.call("cart.removeCoupon");
503
+ return safe2(this.client.call("cart.removeCoupon"));
354
504
  }
355
505
  // --------------------------------------------------------------------------
356
506
  // CONVENIENCE METHODS
357
507
  // --------------------------------------------------------------------------
358
508
  async isEmpty() {
359
- const count = await this.getCount();
360
- return count === 0;
509
+ const countResult = await this.getCount();
510
+ if (!countResult.ok) return countResult;
511
+ return ok(countResult.value === 0);
361
512
  }
362
513
  async hasItem(productId, variantId) {
363
- const items = await this.getItems();
364
- return items.some((item) => {
514
+ const itemsResult = await this.getItems();
515
+ if (!itemsResult.ok) return itemsResult;
516
+ const found = itemsResult.value.some((item) => {
365
517
  const matchesProduct = item.item_id === productId;
366
518
  if (!variantId) return matchesProduct;
367
519
  const config = item.configuration;
@@ -370,10 +522,12 @@ var CartOperations = class {
370
522
  }
371
523
  return matchesProduct;
372
524
  });
525
+ return ok(found);
373
526
  }
374
527
  async findItem(productId, variantId) {
375
- const items = await this.getItems();
376
- return items.find((item) => {
528
+ const itemsResult = await this.getItems();
529
+ if (!itemsResult.ok) return itemsResult;
530
+ const found = itemsResult.value.find((item) => {
377
531
  const matchesProduct = item.item_id === productId;
378
532
  if (!variantId) return matchesProduct;
379
533
  const config = item.configuration;
@@ -382,6 +536,7 @@ var CartOperations = class {
382
536
  }
383
537
  return matchesProduct;
384
538
  });
539
+ return ok(found);
385
540
  }
386
541
  };
387
542
 
@@ -476,41 +631,106 @@ var DEFAULT_CURRENCY = "GHS";
476
631
  var DEFAULT_COUNTRY = "GHA";
477
632
 
478
633
  // src/checkout.ts
634
+ function toCimplifyError3(error) {
635
+ if (error instanceof CimplifyError) return error;
636
+ if (error instanceof Error) {
637
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
638
+ }
639
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
640
+ }
641
+ async function safe3(promise) {
642
+ try {
643
+ return ok(await promise);
644
+ } catch (error) {
645
+ return err(toCimplifyError3(error));
646
+ }
647
+ }
479
648
  var CheckoutService = class {
480
649
  constructor(client) {
481
650
  this.client = client;
482
651
  }
652
+ /**
653
+ * Process checkout with cart data.
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const result = await client.checkout.process({
658
+ * cart_id: cart.id,
659
+ * customer: { name, email, phone, save_details: true },
660
+ * order_type: "pickup",
661
+ * payment_method: "mobile_money",
662
+ * mobile_money_details: { phone_number, provider: "mtn" },
663
+ * });
664
+ *
665
+ * if (!result.ok) {
666
+ * switch (result.error.code) {
667
+ * case ErrorCode.CART_EMPTY:
668
+ * toast.error("Your cart is empty");
669
+ * break;
670
+ * case ErrorCode.PAYMENT_FAILED:
671
+ * toast.error("Payment failed. Please try again.");
672
+ * break;
673
+ * }
674
+ * }
675
+ * ```
676
+ */
483
677
  async process(data) {
484
- return this.client.call(CHECKOUT_MUTATION.PROCESS, {
485
- checkout_data: data
486
- });
678
+ return safe3(
679
+ this.client.call(CHECKOUT_MUTATION.PROCESS, {
680
+ checkout_data: data
681
+ })
682
+ );
487
683
  }
488
684
  async initializePayment(orderId, method) {
489
- return this.client.call("order.initializePayment", {
490
- order_id: orderId,
491
- payment_method: method
492
- });
685
+ return safe3(
686
+ this.client.call("order.initializePayment", {
687
+ order_id: orderId,
688
+ payment_method: method
689
+ })
690
+ );
493
691
  }
494
692
  async submitAuthorization(input) {
495
- return this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input);
693
+ return safe3(
694
+ this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
695
+ );
496
696
  }
497
697
  async pollPaymentStatus(orderId) {
498
- return this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId);
698
+ return safe3(
699
+ this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
700
+ );
499
701
  }
500
702
  async updateOrderCustomer(orderId, customer) {
501
- return this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
502
- order_id: orderId,
503
- ...customer
504
- });
703
+ return safe3(
704
+ this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
705
+ order_id: orderId,
706
+ ...customer
707
+ })
708
+ );
505
709
  }
506
710
  async verifyPayment(orderId) {
507
- return this.client.call("order.verifyPayment", {
508
- order_id: orderId
509
- });
711
+ return safe3(
712
+ this.client.call("order.verifyPayment", {
713
+ order_id: orderId
714
+ })
715
+ );
510
716
  }
511
717
  };
512
718
 
513
719
  // src/orders.ts
720
+ function toCimplifyError4(error) {
721
+ if (error instanceof CimplifyError) return error;
722
+ if (error instanceof Error) {
723
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
724
+ }
725
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
726
+ }
727
+ async function safe4(promise) {
728
+ try {
729
+ return ok(await promise);
730
+ } catch (error) {
731
+ return err(toCimplifyError4(error));
732
+ }
733
+ }
514
734
  var OrderQueries = class {
515
735
  constructor(client) {
516
736
  this.client = client;
@@ -527,141 +747,213 @@ var OrderQueries = class {
527
747
  if (options?.offset) {
528
748
  query2 += `#offset(${options.offset})`;
529
749
  }
530
- return this.client.query(query2);
750
+ return safe4(this.client.query(query2));
531
751
  }
532
752
  async get(orderId) {
533
- return this.client.query(`orders.${orderId}`);
753
+ return safe4(this.client.query(`orders.${orderId}`));
534
754
  }
535
755
  async getRecent(limit = 5) {
536
- return this.client.query(`orders#sort(created_at,desc)#limit(${limit})`);
756
+ return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
537
757
  }
538
758
  async getByStatus(status) {
539
- return this.client.query(`orders[?(@.status=='${status}')]`);
759
+ return safe4(this.client.query(`orders[?(@.status=='${status}')]`));
540
760
  }
541
761
  async cancel(orderId, reason) {
542
- return this.client.call("order.cancelOrder", {
543
- order_id: orderId,
544
- reason
545
- });
762
+ return safe4(
763
+ this.client.call("order.cancelOrder", {
764
+ order_id: orderId,
765
+ reason
766
+ })
767
+ );
546
768
  }
547
769
  };
548
770
 
549
771
  // src/link.ts
772
+ function toCimplifyError5(error) {
773
+ if (error instanceof CimplifyError) return error;
774
+ if (error instanceof Error) {
775
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
776
+ }
777
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
778
+ }
779
+ async function safe5(promise) {
780
+ try {
781
+ return ok(await promise);
782
+ } catch (error) {
783
+ return err(toCimplifyError5(error));
784
+ }
785
+ }
550
786
  var LinkService = class {
551
787
  constructor(client) {
552
788
  this.client = client;
553
789
  }
790
+ // --------------------------------------------------------------------------
791
+ // AUTHENTICATION
792
+ // --------------------------------------------------------------------------
554
793
  async requestOtp(input) {
555
- return this.client.linkPost("/v1/link/auth/request-otp", input);
794
+ return safe5(this.client.linkPost("/v1/link/auth/request-otp", input));
556
795
  }
557
796
  async verifyOtp(input) {
558
- const response = await this.client.linkPost("/v1/link/auth/verify-otp", input);
559
- if (response.session_token) {
560
- this.client.setSessionToken(response.session_token);
797
+ const result = await safe5(
798
+ this.client.linkPost("/v1/link/auth/verify-otp", input)
799
+ );
800
+ if (result.ok && result.value.session_token) {
801
+ this.client.setSessionToken(result.value.session_token);
561
802
  }
562
- return response;
803
+ return result;
563
804
  }
564
805
  async logout() {
565
- const result = await this.client.linkPost("/v1/link/auth/logout");
566
- this.client.clearSession();
806
+ const result = await safe5(this.client.linkPost("/v1/link/auth/logout"));
807
+ if (result.ok) {
808
+ this.client.clearSession();
809
+ }
567
810
  return result;
568
811
  }
812
+ // --------------------------------------------------------------------------
813
+ // STATUS & DATA
814
+ // --------------------------------------------------------------------------
569
815
  async checkStatus(contact) {
570
- return this.client.call(LINK_MUTATION.CHECK_STATUS, {
571
- contact
572
- });
816
+ return safe5(
817
+ this.client.call(LINK_MUTATION.CHECK_STATUS, {
818
+ contact
819
+ })
820
+ );
573
821
  }
574
822
  async getLinkData() {
575
- return this.client.query(LINK_QUERY.DATA);
823
+ return safe5(this.client.query(LINK_QUERY.DATA));
576
824
  }
577
825
  async getAddresses() {
578
- return this.client.query(LINK_QUERY.ADDRESSES);
826
+ return safe5(this.client.query(LINK_QUERY.ADDRESSES));
579
827
  }
580
828
  async getMobileMoney() {
581
- return this.client.query(LINK_QUERY.MOBILE_MONEY);
829
+ return safe5(this.client.query(LINK_QUERY.MOBILE_MONEY));
582
830
  }
583
831
  async getPreferences() {
584
- return this.client.query(LINK_QUERY.PREFERENCES);
832
+ return safe5(this.client.query(LINK_QUERY.PREFERENCES));
585
833
  }
834
+ // --------------------------------------------------------------------------
835
+ // ENROLLMENT
836
+ // --------------------------------------------------------------------------
586
837
  async enroll(data) {
587
- return this.client.call(LINK_MUTATION.ENROLL, data);
838
+ return safe5(this.client.call(LINK_MUTATION.ENROLL, data));
588
839
  }
589
840
  async enrollAndLinkOrder(data) {
590
- return this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data);
841
+ return safe5(
842
+ this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data)
843
+ );
591
844
  }
845
+ // --------------------------------------------------------------------------
846
+ // PREFERENCES
847
+ // --------------------------------------------------------------------------
592
848
  async updatePreferences(preferences) {
593
- return this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences);
849
+ return safe5(this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences));
594
850
  }
851
+ // --------------------------------------------------------------------------
852
+ // ADDRESSES
853
+ // --------------------------------------------------------------------------
595
854
  async createAddress(input) {
596
- return this.client.call(LINK_MUTATION.CREATE_ADDRESS, input);
855
+ return safe5(this.client.call(LINK_MUTATION.CREATE_ADDRESS, input));
597
856
  }
598
857
  async updateAddress(input) {
599
- return this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input);
858
+ return safe5(this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input));
600
859
  }
601
860
  async deleteAddress(addressId) {
602
- return this.client.call(LINK_MUTATION.DELETE_ADDRESS, addressId);
861
+ return safe5(this.client.call(LINK_MUTATION.DELETE_ADDRESS, addressId));
603
862
  }
604
863
  async setDefaultAddress(addressId) {
605
- return this.client.call(LINK_MUTATION.SET_DEFAULT_ADDRESS, addressId);
864
+ return safe5(this.client.call(LINK_MUTATION.SET_DEFAULT_ADDRESS, addressId));
606
865
  }
607
866
  async trackAddressUsage(addressId) {
608
- return this.client.call(LINK_MUTATION.TRACK_ADDRESS_USAGE, {
609
- address_id: addressId
610
- });
867
+ return safe5(
868
+ this.client.call(LINK_MUTATION.TRACK_ADDRESS_USAGE, {
869
+ address_id: addressId
870
+ })
871
+ );
611
872
  }
873
+ // --------------------------------------------------------------------------
874
+ // MOBILE MONEY
875
+ // --------------------------------------------------------------------------
612
876
  async createMobileMoney(input) {
613
- return this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input);
877
+ return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
614
878
  }
615
879
  async deleteMobileMoney(mobileMoneyId) {
616
- return this.client.call(LINK_MUTATION.DELETE_MOBILE_MONEY, mobileMoneyId);
880
+ return safe5(this.client.call(LINK_MUTATION.DELETE_MOBILE_MONEY, mobileMoneyId));
617
881
  }
618
882
  async setDefaultMobileMoney(mobileMoneyId) {
619
- return this.client.call(LINK_MUTATION.SET_DEFAULT_MOBILE_MONEY, mobileMoneyId);
883
+ return safe5(
884
+ this.client.call(LINK_MUTATION.SET_DEFAULT_MOBILE_MONEY, mobileMoneyId)
885
+ );
620
886
  }
621
887
  async trackMobileMoneyUsage(mobileMoneyId) {
622
- return this.client.call(LINK_MUTATION.TRACK_MOBILE_MONEY_USAGE, {
623
- mobile_money_id: mobileMoneyId
624
- });
888
+ return safe5(
889
+ this.client.call(LINK_MUTATION.TRACK_MOBILE_MONEY_USAGE, {
890
+ mobile_money_id: mobileMoneyId
891
+ })
892
+ );
625
893
  }
626
894
  async verifyMobileMoney(mobileMoneyId) {
627
- return this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId);
895
+ return safe5(
896
+ this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId)
897
+ );
628
898
  }
899
+ // --------------------------------------------------------------------------
900
+ // SESSIONS
901
+ // --------------------------------------------------------------------------
629
902
  async getSessions() {
630
- return this.client.linkGet("/v1/link/sessions");
903
+ return safe5(this.client.linkGet("/v1/link/sessions"));
631
904
  }
632
905
  async revokeSession(sessionId) {
633
- return this.client.linkDelete(`/v1/link/sessions/${sessionId}`);
906
+ return safe5(this.client.linkDelete(`/v1/link/sessions/${sessionId}`));
634
907
  }
635
908
  async revokeAllSessions() {
636
- return this.client.linkDelete("/v1/link/sessions");
909
+ return safe5(this.client.linkDelete("/v1/link/sessions"));
637
910
  }
911
+ // --------------------------------------------------------------------------
912
+ // REST ALTERNATIVES (for direct API access)
913
+ // --------------------------------------------------------------------------
638
914
  async getAddressesRest() {
639
- return this.client.linkGet("/v1/link/addresses");
915
+ return safe5(this.client.linkGet("/v1/link/addresses"));
640
916
  }
641
917
  async createAddressRest(input) {
642
- return this.client.linkPost("/v1/link/addresses", input);
918
+ return safe5(this.client.linkPost("/v1/link/addresses", input));
643
919
  }
644
920
  async deleteAddressRest(addressId) {
645
- return this.client.linkDelete(`/v1/link/addresses/${addressId}`);
921
+ return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
646
922
  }
647
923
  async setDefaultAddressRest(addressId) {
648
- return this.client.linkPost(`/v1/link/addresses/${addressId}/default`);
924
+ return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
649
925
  }
650
926
  async getMobileMoneyRest() {
651
- return this.client.linkGet("/v1/link/mobile-money");
927
+ return safe5(this.client.linkGet("/v1/link/mobile-money"));
652
928
  }
653
929
  async createMobileMoneyRest(input) {
654
- return this.client.linkPost("/v1/link/mobile-money", input);
930
+ return safe5(this.client.linkPost("/v1/link/mobile-money", input));
655
931
  }
656
932
  async deleteMobileMoneyRest(mobileMoneyId) {
657
- return this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`);
933
+ return safe5(this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`));
658
934
  }
659
935
  async setDefaultMobileMoneyRest(mobileMoneyId) {
660
- return this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`);
936
+ return safe5(
937
+ this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
938
+ );
661
939
  }
662
940
  };
663
941
 
664
942
  // src/auth.ts
943
+ function toCimplifyError6(error) {
944
+ if (error instanceof CimplifyError) return error;
945
+ if (error instanceof Error) {
946
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
947
+ }
948
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
949
+ }
950
+ async function safe6(promise) {
951
+ try {
952
+ return ok(await promise);
953
+ } catch (error) {
954
+ return err(toCimplifyError6(error));
955
+ }
956
+ }
665
957
  var AuthService = class {
666
958
  constructor(client) {
667
959
  this.client = client;
@@ -670,52 +962,72 @@ var AuthService = class {
670
962
  // STATUS & USER
671
963
  // --------------------------------------------------------------------------
672
964
  async getStatus() {
673
- return this.client.query("auth");
965
+ return safe6(this.client.query("auth"));
674
966
  }
675
967
  async getCurrentUser() {
676
- const status = await this.getStatus();
677
- return status.customer || null;
968
+ const result = await this.getStatus();
969
+ if (!result.ok) return result;
970
+ return ok(result.value.customer || null);
678
971
  }
679
972
  async isAuthenticated() {
680
- const status = await this.getStatus();
681
- return status.is_authenticated;
973
+ const result = await this.getStatus();
974
+ if (!result.ok) return result;
975
+ return ok(result.value.is_authenticated);
682
976
  }
683
977
  // --------------------------------------------------------------------------
684
978
  // OTP AUTHENTICATION
685
979
  // --------------------------------------------------------------------------
686
980
  async requestOtp(contact, contactType) {
687
- await this.client.call(AUTH_MUTATION.REQUEST_OTP, {
688
- contact,
689
- contact_type: contactType
690
- });
981
+ return safe6(
982
+ this.client.call(AUTH_MUTATION.REQUEST_OTP, {
983
+ contact,
984
+ contact_type: contactType
985
+ })
986
+ );
691
987
  }
692
988
  async verifyOtp(code, contact) {
693
- return this.client.call(AUTH_MUTATION.VERIFY_OTP, {
694
- otp_code: code,
695
- contact
696
- });
989
+ return safe6(
990
+ this.client.call(AUTH_MUTATION.VERIFY_OTP, {
991
+ otp_code: code,
992
+ contact
993
+ })
994
+ );
697
995
  }
698
996
  // --------------------------------------------------------------------------
699
997
  // SESSION MANAGEMENT
700
998
  // --------------------------------------------------------------------------
701
999
  async logout() {
702
- return this.client.call("auth.logout");
1000
+ return safe6(this.client.call("auth.logout"));
703
1001
  }
704
1002
  // --------------------------------------------------------------------------
705
1003
  // PROFILE MANAGEMENT
706
1004
  // --------------------------------------------------------------------------
707
1005
  async updateProfile(input) {
708
- return this.client.call("auth.update_profile", input);
1006
+ return safe6(this.client.call("auth.update_profile", input));
709
1007
  }
710
1008
  async changePassword(input) {
711
- return this.client.call("auth.change_password", input);
1009
+ return safe6(this.client.call("auth.change_password", input));
712
1010
  }
713
1011
  async resetPassword(email) {
714
- return this.client.call("auth.reset_password", { email });
1012
+ return safe6(this.client.call("auth.reset_password", { email }));
715
1013
  }
716
1014
  };
717
1015
 
718
1016
  // src/business.ts
1017
+ function toCimplifyError7(error) {
1018
+ if (error instanceof CimplifyError) return error;
1019
+ if (error instanceof Error) {
1020
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
1021
+ }
1022
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
1023
+ }
1024
+ async function safe7(promise) {
1025
+ try {
1026
+ return ok(await promise);
1027
+ } catch (error) {
1028
+ return err(toCimplifyError7(error));
1029
+ }
1030
+ }
719
1031
  var BusinessService = class {
720
1032
  constructor(client) {
721
1033
  this.client = client;
@@ -724,49 +1036,55 @@ var BusinessService = class {
724
1036
  // BUSINESS INFO
725
1037
  // --------------------------------------------------------------------------
726
1038
  async getInfo() {
727
- return this.client.query("business.info");
1039
+ return safe7(this.client.query("business.info"));
728
1040
  }
729
1041
  async getByHandle(handle) {
730
- return this.client.query(`business.handle.${handle}`);
1042
+ return safe7(this.client.query(`business.handle.${handle}`));
731
1043
  }
732
1044
  async getByDomain(domain) {
733
- return this.client.query("business.domain", { domain });
1045
+ return safe7(this.client.query("business.domain", { domain }));
734
1046
  }
735
1047
  async getSettings() {
736
- return this.client.query("business.settings");
1048
+ return safe7(this.client.query("business.settings"));
737
1049
  }
738
1050
  async getTheme() {
739
- return this.client.query("business.theme");
1051
+ return safe7(this.client.query("business.theme"));
740
1052
  }
741
1053
  // --------------------------------------------------------------------------
742
1054
  // LOCATIONS
743
1055
  // --------------------------------------------------------------------------
744
1056
  async getLocations() {
745
- return this.client.query("business.locations");
1057
+ return safe7(this.client.query("business.locations"));
746
1058
  }
747
1059
  async getLocation(locationId) {
748
- return this.client.query(`business.locations.${locationId}`);
1060
+ return safe7(this.client.query(`business.locations.${locationId}`));
749
1061
  }
750
1062
  // --------------------------------------------------------------------------
751
1063
  // HOURS
752
1064
  // --------------------------------------------------------------------------
753
1065
  async getHours() {
754
- return this.client.query("business.hours");
1066
+ return safe7(this.client.query("business.hours"));
755
1067
  }
756
1068
  async getLocationHours(locationId) {
757
- return this.client.query(`business.locations.${locationId}.hours`);
1069
+ return safe7(this.client.query(`business.locations.${locationId}.hours`));
758
1070
  }
759
1071
  // --------------------------------------------------------------------------
760
1072
  // BOOTSTRAP (for storefront initialization)
761
1073
  // --------------------------------------------------------------------------
762
1074
  async getBootstrap() {
763
- const [business, locations, categories] = await Promise.all([
1075
+ const [businessResult, locationsResult, categoriesResult] = await Promise.all([
764
1076
  this.getInfo(),
765
1077
  this.getLocations(),
766
- this.client.query("categories#select(id,name,slug)")
1078
+ safe7(this.client.query("categories#select(id,name,slug)"))
767
1079
  ]);
1080
+ if (!businessResult.ok) return businessResult;
1081
+ if (!locationsResult.ok) return locationsResult;
1082
+ if (!categoriesResult.ok) return categoriesResult;
1083
+ const business = businessResult.value;
1084
+ const locations = locationsResult.value;
1085
+ const categories = categoriesResult.value;
768
1086
  const defaultLocation = locations[0];
769
- return {
1087
+ return ok({
770
1088
  business,
771
1089
  location: defaultLocation,
772
1090
  locations,
@@ -774,11 +1092,25 @@ var BusinessService = class {
774
1092
  currency: business.default_currency,
775
1093
  is_open: defaultLocation?.accepts_online_orders ?? false,
776
1094
  accepts_orders: defaultLocation?.accepts_online_orders ?? false
777
- };
1095
+ });
778
1096
  }
779
1097
  };
780
1098
 
781
1099
  // src/inventory.ts
1100
+ function toCimplifyError8(error) {
1101
+ if (error instanceof CimplifyError) return error;
1102
+ if (error instanceof Error) {
1103
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
1104
+ }
1105
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
1106
+ }
1107
+ async function safe8(promise) {
1108
+ try {
1109
+ return ok(await promise);
1110
+ } catch (error) {
1111
+ return err(toCimplifyError8(error));
1112
+ }
1113
+ }
782
1114
  var InventoryService = class {
783
1115
  constructor(client) {
784
1116
  this.client = client;
@@ -787,41 +1119,51 @@ var InventoryService = class {
787
1119
  // STOCK QUERIES
788
1120
  // --------------------------------------------------------------------------
789
1121
  async getStockLevels() {
790
- return this.client.query("inventory.stock_levels");
1122
+ return safe8(this.client.query("inventory.stock_levels"));
791
1123
  }
792
1124
  async getProductStock(productId, locationId) {
793
1125
  if (locationId) {
794
- return this.client.query("inventory.product", {
795
- product_id: productId,
796
- location_id: locationId
797
- });
1126
+ return safe8(
1127
+ this.client.query("inventory.product", {
1128
+ product_id: productId,
1129
+ location_id: locationId
1130
+ })
1131
+ );
798
1132
  }
799
- return this.client.query("inventory.product", {
800
- product_id: productId
801
- });
1133
+ return safe8(
1134
+ this.client.query("inventory.product", {
1135
+ product_id: productId
1136
+ })
1137
+ );
802
1138
  }
803
1139
  async getVariantStock(variantId, locationId) {
804
- return this.client.query("inventory.variant", {
805
- variant_id: variantId,
806
- location_id: locationId
807
- });
1140
+ return safe8(
1141
+ this.client.query("inventory.variant", {
1142
+ variant_id: variantId,
1143
+ location_id: locationId
1144
+ })
1145
+ );
808
1146
  }
809
1147
  // --------------------------------------------------------------------------
810
1148
  // AVAILABILITY CHECKS
811
1149
  // --------------------------------------------------------------------------
812
1150
  async checkProductAvailability(productId, quantity, locationId) {
813
- return this.client.query("inventory.check_availability", {
814
- product_id: productId,
815
- quantity,
816
- location_id: locationId
817
- });
1151
+ return safe8(
1152
+ this.client.query("inventory.check_availability", {
1153
+ product_id: productId,
1154
+ quantity,
1155
+ location_id: locationId
1156
+ })
1157
+ );
818
1158
  }
819
1159
  async checkVariantAvailability(variantId, quantity, locationId) {
820
- return this.client.query("inventory.check_availability", {
821
- variant_id: variantId,
822
- quantity,
823
- location_id: locationId
824
- });
1160
+ return safe8(
1161
+ this.client.query("inventory.check_availability", {
1162
+ variant_id: variantId,
1163
+ quantity,
1164
+ location_id: locationId
1165
+ })
1166
+ );
825
1167
  }
826
1168
  async checkMultipleAvailability(items, locationId) {
827
1169
  const results = await Promise.all(
@@ -829,28 +1171,47 @@ var InventoryService = class {
829
1171
  (item) => item.variant_id ? this.checkVariantAvailability(item.variant_id, item.quantity, locationId) : this.checkProductAvailability(item.product_id, item.quantity, locationId)
830
1172
  )
831
1173
  );
832
- return results;
1174
+ for (const result of results) {
1175
+ if (!result.ok) return result;
1176
+ }
1177
+ return ok(results.map((r) => r.value));
833
1178
  }
834
1179
  // --------------------------------------------------------------------------
835
1180
  // SUMMARY
836
1181
  // --------------------------------------------------------------------------
837
1182
  async getSummary() {
838
- return this.client.query("inventory.summary");
1183
+ return safe8(this.client.query("inventory.summary"));
839
1184
  }
840
1185
  // --------------------------------------------------------------------------
841
1186
  // CONVENIENCE METHODS
842
1187
  // --------------------------------------------------------------------------
843
1188
  async isInStock(productId, locationId) {
844
1189
  const result = await this.checkProductAvailability(productId, 1, locationId);
845
- return result.is_available;
1190
+ if (!result.ok) return result;
1191
+ return ok(result.value.is_available);
846
1192
  }
847
1193
  async getAvailableQuantity(productId, locationId) {
848
- const stock = await this.getProductStock(productId, locationId);
849
- return stock.available_quantity;
1194
+ const result = await this.getProductStock(productId, locationId);
1195
+ if (!result.ok) return result;
1196
+ return ok(result.value.available_quantity);
850
1197
  }
851
1198
  };
852
1199
 
853
1200
  // src/scheduling.ts
1201
+ function toCimplifyError9(error) {
1202
+ if (error instanceof CimplifyError) return error;
1203
+ if (error instanceof Error) {
1204
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
1205
+ }
1206
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
1207
+ }
1208
+ async function safe9(promise) {
1209
+ try {
1210
+ return ok(await promise);
1211
+ } catch (error) {
1212
+ return err(toCimplifyError9(error));
1213
+ }
1214
+ }
854
1215
  var SchedulingService = class {
855
1216
  constructor(client) {
856
1217
  this.client = client;
@@ -859,86 +1220,113 @@ var SchedulingService = class {
859
1220
  // SERVICES
860
1221
  // --------------------------------------------------------------------------
861
1222
  async getServices() {
862
- return this.client.query("scheduling.services");
1223
+ return safe9(this.client.query("scheduling.services"));
863
1224
  }
864
1225
  /**
865
1226
  * Get a specific service by ID
866
1227
  * Note: Filters from all services client-side (no single-service endpoint)
867
1228
  */
868
1229
  async getService(serviceId) {
869
- const services = await this.getServices();
870
- return services.find((s) => s.id === serviceId) || null;
1230
+ const result = await this.getServices();
1231
+ if (!result.ok) return result;
1232
+ return ok(result.value.find((s) => s.id === serviceId) || null);
871
1233
  }
872
1234
  // --------------------------------------------------------------------------
873
1235
  // AVAILABILITY
874
1236
  // --------------------------------------------------------------------------
875
1237
  async getAvailableSlots(input) {
876
- return this.client.query(
877
- "scheduling.slots",
878
- input
1238
+ return safe9(
1239
+ this.client.query(
1240
+ "scheduling.slots",
1241
+ input
1242
+ )
879
1243
  );
880
1244
  }
881
1245
  async checkSlotAvailability(input) {
882
- return this.client.query(
883
- "scheduling.check_availability",
884
- input
1246
+ return safe9(
1247
+ this.client.query(
1248
+ "scheduling.check_availability",
1249
+ input
1250
+ )
885
1251
  );
886
1252
  }
887
1253
  async getServiceAvailability(params) {
888
- return this.client.query(
889
- "scheduling.availability",
890
- params
1254
+ return safe9(
1255
+ this.client.query(
1256
+ "scheduling.availability",
1257
+ params
1258
+ )
891
1259
  );
892
1260
  }
893
1261
  // --------------------------------------------------------------------------
894
1262
  // BOOKINGS
895
1263
  // --------------------------------------------------------------------------
896
1264
  async getBooking(bookingId) {
897
- return this.client.query(`scheduling.${bookingId}`);
1265
+ return safe9(this.client.query(`scheduling.${bookingId}`));
898
1266
  }
899
1267
  async getCustomerBookings() {
900
- return this.client.query("scheduling");
1268
+ return safe9(this.client.query("scheduling"));
901
1269
  }
902
1270
  async getUpcomingBookings() {
903
- return this.client.query(
904
- "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
1271
+ return safe9(
1272
+ this.client.query(
1273
+ "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
1274
+ )
905
1275
  );
906
1276
  }
907
1277
  async getPastBookings(limit = 10) {
908
- return this.client.query(
909
- `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
1278
+ return safe9(
1279
+ this.client.query(
1280
+ `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
1281
+ )
910
1282
  );
911
1283
  }
912
1284
  // --------------------------------------------------------------------------
913
1285
  // BOOKING MANAGEMENT
914
1286
  // --------------------------------------------------------------------------
915
1287
  async cancelBooking(input) {
916
- return this.client.call("scheduling.cancel_booking", input);
1288
+ return safe9(this.client.call("scheduling.cancel_booking", input));
917
1289
  }
918
1290
  async rescheduleBooking(input) {
919
- return this.client.call("scheduling.reschedule_booking", input);
1291
+ return safe9(this.client.call("scheduling.reschedule_booking", input));
920
1292
  }
921
1293
  // --------------------------------------------------------------------------
922
1294
  // CONVENIENCE METHODS
923
1295
  // --------------------------------------------------------------------------
924
1296
  async getNextAvailableSlot(serviceId, fromDate) {
925
1297
  const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
926
- const slots = await this.getAvailableSlots({
1298
+ const result = await this.getAvailableSlots({
927
1299
  service_id: serviceId,
928
1300
  date
929
1301
  });
930
- return slots.find((slot) => slot.is_available) || null;
1302
+ if (!result.ok) return result;
1303
+ return ok(result.value.find((slot) => slot.is_available) || null);
931
1304
  }
932
1305
  async hasAvailabilityOn(serviceId, date) {
933
- const slots = await this.getAvailableSlots({
1306
+ const result = await this.getAvailableSlots({
934
1307
  service_id: serviceId,
935
1308
  date
936
1309
  });
937
- return slots.some((slot) => slot.is_available);
1310
+ if (!result.ok) return result;
1311
+ return ok(result.value.some((slot) => slot.is_available));
938
1312
  }
939
1313
  };
940
1314
 
941
1315
  // src/lite.ts
1316
+ function toCimplifyError10(error) {
1317
+ if (error instanceof CimplifyError) return error;
1318
+ if (error instanceof Error) {
1319
+ return new CimplifyError("UNKNOWN_ERROR", error.message, false);
1320
+ }
1321
+ return new CimplifyError("UNKNOWN_ERROR", String(error), false);
1322
+ }
1323
+ async function safe10(promise) {
1324
+ try {
1325
+ return ok(await promise);
1326
+ } catch (error) {
1327
+ return err(toCimplifyError10(error));
1328
+ }
1329
+ }
942
1330
  var LiteService = class {
943
1331
  constructor(client) {
944
1332
  this.client = client;
@@ -947,48 +1335,56 @@ var LiteService = class {
947
1335
  // BOOTSTRAP
948
1336
  // --------------------------------------------------------------------------
949
1337
  async getBootstrap() {
950
- return this.client.query("lite.bootstrap");
1338
+ return safe10(this.client.query("lite.bootstrap"));
951
1339
  }
952
1340
  // --------------------------------------------------------------------------
953
1341
  // TABLE MANAGEMENT
954
1342
  // --------------------------------------------------------------------------
955
1343
  async getTable(tableId) {
956
- return this.client.query(`lite.table.${tableId}`);
1344
+ return safe10(this.client.query(`lite.table.${tableId}`));
957
1345
  }
958
1346
  async getTableByNumber(tableNumber, locationId) {
959
- return this.client.query("lite.table_by_number", {
960
- table_number: tableNumber,
961
- location_id: locationId
962
- });
1347
+ return safe10(
1348
+ this.client.query("lite.table_by_number", {
1349
+ table_number: tableNumber,
1350
+ location_id: locationId
1351
+ })
1352
+ );
963
1353
  }
964
1354
  // --------------------------------------------------------------------------
965
1355
  // KITCHEN ORDERS
966
1356
  // --------------------------------------------------------------------------
967
1357
  async sendToKitchen(tableId, items) {
968
- return this.client.call("lite.send_to_kitchen", {
969
- table_id: tableId,
970
- items
971
- });
1358
+ return safe10(
1359
+ this.client.call("lite.send_to_kitchen", {
1360
+ table_id: tableId,
1361
+ items
1362
+ })
1363
+ );
972
1364
  }
973
1365
  async callWaiter(tableId, reason) {
974
- return this.client.call("lite.call_waiter", {
975
- table_id: tableId,
976
- reason
977
- });
1366
+ return safe10(
1367
+ this.client.call("lite.call_waiter", {
1368
+ table_id: tableId,
1369
+ reason
1370
+ })
1371
+ );
978
1372
  }
979
1373
  async requestBill(tableId) {
980
- return this.client.call("lite.request_bill", {
981
- table_id: tableId
982
- });
1374
+ return safe10(
1375
+ this.client.call("lite.request_bill", {
1376
+ table_id: tableId
1377
+ })
1378
+ );
983
1379
  }
984
1380
  // --------------------------------------------------------------------------
985
1381
  // MENU (optimized for lite/QR experience)
986
1382
  // --------------------------------------------------------------------------
987
1383
  async getMenu() {
988
- return this.client.query("lite.menu");
1384
+ return safe10(this.client.query("lite.menu"));
989
1385
  }
990
1386
  async getMenuByCategory(categoryId) {
991
- return this.client.query(`lite.menu.category.${categoryId}`);
1387
+ return safe10(this.client.query(`lite.menu.category.${categoryId}`));
992
1388
  }
993
1389
  };
994
1390
 
@@ -1818,27 +2214,41 @@ exports.PICKUP_TIME_TYPE = PICKUP_TIME_TYPE;
1818
2214
  exports.QueryBuilder = QueryBuilder;
1819
2215
  exports.SchedulingService = SchedulingService;
1820
2216
  exports.categorizePaymentError = categorizePaymentError;
2217
+ exports.combine = combine;
2218
+ exports.combineObject = combineObject;
1821
2219
  exports.createCimplifyClient = createCimplifyClient;
1822
2220
  exports.detectMobileMoneyProvider = detectMobileMoneyProvider;
2221
+ exports.err = err;
1823
2222
  exports.extractPriceInfo = extractPriceInfo;
2223
+ exports.flatMap = flatMap;
1824
2224
  exports.formatMoney = formatMoney;
1825
2225
  exports.formatNumberCompact = formatNumberCompact;
1826
2226
  exports.formatPrice = formatPrice;
1827
2227
  exports.formatPriceAdjustment = formatPriceAdjustment;
1828
2228
  exports.formatPriceCompact = formatPriceCompact;
1829
2229
  exports.formatProductPrice = formatProductPrice;
2230
+ exports.fromPromise = fromPromise;
1830
2231
  exports.getBasePrice = getBasePrice;
1831
2232
  exports.getCurrencySymbol = getCurrencySymbol;
1832
2233
  exports.getDiscountPercentage = getDiscountPercentage;
1833
2234
  exports.getDisplayPrice = getDisplayPrice;
1834
2235
  exports.getMarkupPercentage = getMarkupPercentage;
2236
+ exports.getOrElse = getOrElse;
1835
2237
  exports.getProductCurrency = getProductCurrency;
1836
2238
  exports.isCimplifyError = isCimplifyError;
2239
+ exports.isErr = isErr;
2240
+ exports.isOk = isOk;
1837
2241
  exports.isOnSale = isOnSale;
1838
2242
  exports.isRetryableError = isRetryableError;
2243
+ exports.mapError = mapError;
2244
+ exports.mapResult = mapResult;
1839
2245
  exports.normalizePaymentResponse = normalizePaymentResponse;
1840
2246
  exports.normalizeStatusResponse = normalizeStatusResponse;
2247
+ exports.ok = ok;
1841
2248
  exports.parsePrice = parsePrice;
1842
2249
  exports.parsePricePath = parsePricePath;
1843
2250
  exports.parsedPriceToPriceInfo = parsedPriceToPriceInfo;
1844
2251
  exports.query = query;
2252
+ exports.toNullable = toNullable;
2253
+ exports.tryCatch = tryCatch;
2254
+ exports.unwrap = unwrap;