@cimplify/sdk 0.16.1 → 0.16.3

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
@@ -285,7 +285,7 @@ function combineObject(results) {
285
285
  return ok(values);
286
286
  }
287
287
 
288
- // src/catalogue.ts
288
+ // src/internal/safe.ts
289
289
  function toCimplifyError(error) {
290
290
  if (error instanceof CimplifyError) return enrichError(error);
291
291
  if (error instanceof Error) {
@@ -300,6 +300,8 @@ async function safe(promise) {
300
300
  return err(toCimplifyError(error));
301
301
  }
302
302
  }
303
+
304
+ // src/catalogue.ts
303
305
  function withQuery(path, params) {
304
306
  const query2 = new URLSearchParams();
305
307
  for (const [key, value] of Object.entries(params)) {
@@ -669,20 +671,6 @@ var CatalogueQueries = class {
669
671
  };
670
672
 
671
673
  // src/cart.ts
672
- function toCimplifyError2(error) {
673
- if (error instanceof CimplifyError) return enrichError(error);
674
- if (error instanceof Error) {
675
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, error.message, false));
676
- }
677
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, String(error), false));
678
- }
679
- async function safe2(promise) {
680
- try {
681
- return ok(await promise);
682
- } catch (error) {
683
- return err(toCimplifyError2(error));
684
- }
685
- }
686
674
  function isUICartResponse(value) {
687
675
  return "cart" in value;
688
676
  }
@@ -694,21 +682,21 @@ var CartOperations = class {
694
682
  this.client = client;
695
683
  }
696
684
  async get() {
697
- const result = await safe2(this.client.get("/api/v1/cart"));
685
+ const result = await safe(this.client.get("/api/v1/cart"));
698
686
  if (!result.ok) return result;
699
687
  return ok(unwrapEnrichedCart(result.value));
700
688
  }
701
689
  async getRaw() {
702
- return safe2(this.client.get("/api/v1/cart"));
690
+ return safe(this.client.get("/api/v1/cart"));
703
691
  }
704
692
  async getItems() {
705
- return safe2(this.client.get("/api/v1/cart/items"));
693
+ return safe(this.client.get("/api/v1/cart/items"));
706
694
  }
707
695
  async getCount() {
708
- return safe2(this.client.get("/api/v1/cart/count"));
696
+ return safe(this.client.get("/api/v1/cart/count"));
709
697
  }
710
698
  async getTotal() {
711
- return safe2(this.client.get("/api/v1/cart/total"));
699
+ return safe(this.client.get("/api/v1/cart/total"));
712
700
  }
713
701
  async getSummary() {
714
702
  const cartResult = await this.get();
@@ -725,18 +713,18 @@ var CartOperations = class {
725
713
  });
726
714
  }
727
715
  async addItem(input) {
728
- return safe2(this.client.post("/api/v1/cart/items", input));
716
+ return safe(this.client.post("/api/v1/cart/items", input));
729
717
  }
730
718
  async updateItem(cartItemId, updates) {
731
719
  if (typeof updates.quantity === "number") {
732
720
  return this.updateQuantity(cartItemId, updates.quantity);
733
721
  }
734
722
  const encodedId = encodeURIComponent(cartItemId);
735
- return safe2(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
723
+ return safe(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
736
724
  }
737
725
  async updateQuantity(cartItemId, quantity) {
738
726
  const encodedId = encodeURIComponent(cartItemId);
739
- return safe2(
727
+ return safe(
740
728
  this.client.patch(`/api/v1/cart/items/${encodedId}`, {
741
729
  quantity
742
730
  })
@@ -744,20 +732,20 @@ var CartOperations = class {
744
732
  }
745
733
  async removeItem(cartItemId) {
746
734
  const encodedId = encodeURIComponent(cartItemId);
747
- return safe2(this.client.delete(`/api/v1/cart/items/${encodedId}`));
735
+ return safe(this.client.delete(`/api/v1/cart/items/${encodedId}`));
748
736
  }
749
737
  async clear() {
750
- return safe2(this.client.delete("/api/v1/cart"));
738
+ return safe(this.client.delete("/api/v1/cart"));
751
739
  }
752
740
  async applyCoupon(code) {
753
- return safe2(
741
+ return safe(
754
742
  this.client.post("/api/v1/cart/coupons", {
755
743
  coupon_code: code
756
744
  })
757
745
  );
758
746
  }
759
747
  async removeCoupon() {
760
- return safe2(this.client.delete("/api/v1/cart/coupons/current"));
748
+ return safe(this.client.delete("/api/v1/cart/coupons/current"));
761
749
  }
762
750
  async isEmpty() {
763
751
  const countResult = await this.getCount();
@@ -1181,9 +1169,10 @@ function normalizePaymentResponse(response) {
1181
1169
  };
1182
1170
  }
1183
1171
  if (isWebPaymentResponse(response)) {
1184
- const authType = response.authorization_type?.toLowerCase();
1185
- const validStringAuthTypes = ["otp", "pin", "phone", "birthday"];
1186
- const safeAuthType = authType && validStringAuthTypes.includes(authType) ? authType : void 0;
1172
+ const objectAuthType = response.authorization_type && typeof response.authorization_type === "object" && "address" in response.authorization_type ? "address" : void 0;
1173
+ const authType = typeof response.authorization_type === "string" ? response.authorization_type.trim().toLowerCase().replace(/[\s-]+/g, "_") : void 0;
1174
+ const validStringAuthTypes = ["otp", "pin", "phone", "birthday", "address"];
1175
+ const safeAuthType = objectAuthType || (authType && validStringAuthTypes.includes(authType) ? authType : void 0);
1187
1176
  return {
1188
1177
  provider: response.transaction.provider_type?.toLowerCase() || "unknown",
1189
1178
  requires_action: response.requires_action || false,
@@ -1465,9 +1454,16 @@ function isValidMobileMoneyProvider(value) {
1465
1454
  return VALID_MOBILE_MONEY_PROVIDERS.has(value);
1466
1455
  }
1467
1456
  function normalizeAuthorizationType(value) {
1457
+ if (value && typeof value === "object" && "address" in value) {
1458
+ return "address";
1459
+ }
1468
1460
  if (typeof value !== "string") return void 0;
1469
- const lower = value.toLowerCase();
1470
- return lower === "otp" || lower === "pin" ? lower : void 0;
1461
+ const normalized = value.trim().toLowerCase().replace(/[\s-]+/g, "_");
1462
+ if (normalized === "otp" || normalized === "pin") return normalized;
1463
+ if (normalized === "phone" || normalized === "birthday" || normalized === "address") {
1464
+ return normalized;
1465
+ }
1466
+ return void 0;
1471
1467
  }
1472
1468
  function formatMoney2(value) {
1473
1469
  if (typeof value === "number" && Number.isFinite(value)) {
@@ -2038,20 +2034,6 @@ var CheckoutResolver = class {
2038
2034
  };
2039
2035
 
2040
2036
  // src/checkout.ts
2041
- function toCimplifyError3(error) {
2042
- if (error instanceof CimplifyError) return enrichError(error);
2043
- if (error instanceof Error) {
2044
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, error.message, false));
2045
- }
2046
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, String(error), false));
2047
- }
2048
- async function safe3(promise) {
2049
- try {
2050
- return ok(await promise);
2051
- } catch (error) {
2052
- return err(toCimplifyError3(error));
2053
- }
2054
- }
2055
2037
  function toTerminalFailure(code, message, recoverable) {
2056
2038
  return {
2057
2039
  success: false,
@@ -2083,7 +2065,7 @@ var CheckoutService = class {
2083
2065
  ...data,
2084
2066
  idempotency_key: data.idempotency_key || generateIdempotencyKey()
2085
2067
  };
2086
- const result = await safe3(
2068
+ const result = await safe(
2087
2069
  this.client.post("/api/v1/checkout", {
2088
2070
  checkout_data: checkoutData
2089
2071
  })
@@ -2103,22 +2085,22 @@ var CheckoutService = class {
2103
2085
  );
2104
2086
  }
2105
2087
  async submitAuthorization(input) {
2106
- return safe3(this.client.post("/api/v1/payments/authorization", input));
2088
+ return safe(this.client.post("/api/v1/payments/authorization", input));
2107
2089
  }
2108
2090
  async pollPaymentStatus(orderId) {
2109
2091
  const encodedId = encodeURIComponent(orderId);
2110
2092
  const tokenParam = this.orderTokenParam(orderId);
2111
- return safe3(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
2093
+ return safe(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
2112
2094
  }
2113
2095
  async updateOrderCustomer(orderId, customer) {
2114
2096
  const encodedId = encodeURIComponent(orderId);
2115
2097
  const tokenParam = this.orderTokenParam(orderId);
2116
- return safe3(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
2098
+ return safe(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
2117
2099
  }
2118
2100
  async verifyPayment(orderId) {
2119
2101
  const encodedId = encodeURIComponent(orderId);
2120
2102
  const tokenParam = this.orderTokenParam(orderId);
2121
- return safe3(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
2103
+ return safe(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
2122
2104
  }
2123
2105
  async processAndResolve(data) {
2124
2106
  data.on_status_change?.("preparing", {});
@@ -2223,20 +2205,6 @@ var CheckoutService = class {
2223
2205
  };
2224
2206
 
2225
2207
  // src/orders.ts
2226
- function toCimplifyError4(error) {
2227
- if (error instanceof CimplifyError) return enrichError(error);
2228
- if (error instanceof Error) {
2229
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, error.message, false));
2230
- }
2231
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, String(error), false));
2232
- }
2233
- async function safe4(promise) {
2234
- try {
2235
- return ok(await promise);
2236
- } catch (error) {
2237
- return err(toCimplifyError4(error));
2238
- }
2239
- }
2240
2208
  var OrderQueries = class {
2241
2209
  constructor(client) {
2242
2210
  this.client = client;
@@ -2251,12 +2219,12 @@ var OrderQueries = class {
2251
2219
  if (options?.limit) params.set("limit", String(options.limit));
2252
2220
  if (options?.offset) params.set("offset", String(options.offset));
2253
2221
  const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
2254
- return safe4(this.client.get(path));
2222
+ return safe(this.client.get(path));
2255
2223
  }
2256
2224
  async get(orderId) {
2257
2225
  const encodedId = encodeURIComponent(orderId);
2258
2226
  const tokenParam = this.orderTokenParam(orderId);
2259
- return safe4(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
2227
+ return safe(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
2260
2228
  }
2261
2229
  async getRecent(limit = 5) {
2262
2230
  return this.list({ limit });
@@ -2267,7 +2235,7 @@ var OrderQueries = class {
2267
2235
  async cancel(orderId, reason) {
2268
2236
  const encodedId = encodeURIComponent(orderId);
2269
2237
  const tokenParam = this.orderTokenParam(orderId);
2270
- return safe4(
2238
+ return safe(
2271
2239
  this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
2272
2240
  reason
2273
2241
  })
@@ -2276,20 +2244,6 @@ var OrderQueries = class {
2276
2244
  };
2277
2245
 
2278
2246
  // src/link.ts
2279
- function toCimplifyError5(error) {
2280
- if (error instanceof CimplifyError) return error;
2281
- if (error instanceof Error) {
2282
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2283
- }
2284
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2285
- }
2286
- async function safe5(promise) {
2287
- try {
2288
- return ok(await promise);
2289
- } catch (error) {
2290
- return err(toCimplifyError5(error));
2291
- }
2292
- }
2293
2247
  function encodePathSegment(value) {
2294
2248
  return encodeURIComponent(value);
2295
2249
  }
@@ -2327,13 +2281,13 @@ var LinkService = class {
2327
2281
  this.client = client;
2328
2282
  }
2329
2283
  async getProfile() {
2330
- return safe5(this.client.linkGet("/v1/link/profile"));
2284
+ return safe(this.client.linkGet("/v1/link/profile"));
2331
2285
  }
2332
2286
  async requestOtp(input) {
2333
- return safe5(this.client.linkPost("/v1/link/auth/request-otp", input));
2287
+ return safe(this.client.linkPost("/v1/link/auth/request-otp", input));
2334
2288
  }
2335
2289
  async verifyOtp(input) {
2336
- const result = await safe5(
2290
+ const result = await safe(
2337
2291
  this.client.linkPost("/v1/link/auth/verify-otp", input)
2338
2292
  );
2339
2293
  if (result.ok && result.value.session_token) {
@@ -2342,45 +2296,45 @@ var LinkService = class {
2342
2296
  return result;
2343
2297
  }
2344
2298
  async logout() {
2345
- const result = await safe5(this.client.linkPost("/v1/link/auth/logout"));
2299
+ const result = await safe(this.client.linkPost("/v1/link/auth/logout"));
2346
2300
  if (result.ok) {
2347
2301
  this.client.clearSession();
2348
2302
  }
2349
2303
  return result;
2350
2304
  }
2351
2305
  async checkStatus(contact) {
2352
- return safe5(this.client.linkPost("/v1/link/check-status", { contact }));
2306
+ return safe(this.client.linkPost("/v1/link/check-status", { contact }));
2353
2307
  }
2354
2308
  async getLinkData() {
2355
- return safe5(this.client.linkGet("/v1/link/data"));
2309
+ return safe(this.client.linkGet("/v1/link/data"));
2356
2310
  }
2357
2311
  async getAddresses() {
2358
- return safe5(this.client.linkGet("/v1/link/addresses"));
2312
+ return safe(this.client.linkGet("/v1/link/addresses"));
2359
2313
  }
2360
2314
  async getMobileMoney() {
2361
- return safe5(this.client.linkGet("/v1/link/mobile-money"));
2315
+ return safe(this.client.linkGet("/v1/link/mobile-money"));
2362
2316
  }
2363
2317
  async getPreferences() {
2364
- return safe5(this.client.linkGet("/v1/link/preferences"));
2318
+ return safe(this.client.linkGet("/v1/link/preferences"));
2365
2319
  }
2366
2320
  async enroll(data) {
2367
- return safe5(this.client.linkPost("/v1/link/enroll", data));
2321
+ return safe(this.client.linkPost("/v1/link/enroll", data));
2368
2322
  }
2369
2323
  async enrollAndLinkOrder(data) {
2370
- return safe5(
2324
+ return safe(
2371
2325
  this.client.linkPost("/v1/link/enroll-and-link-order", data)
2372
2326
  );
2373
2327
  }
2374
2328
  async updatePreferences(preferences) {
2375
- return safe5(this.client.linkPost("/v1/link/preferences", preferences));
2329
+ return safe(this.client.linkPost("/v1/link/preferences", preferences));
2376
2330
  }
2377
2331
  async createAddress(input) {
2378
- return safe5(
2332
+ return safe(
2379
2333
  this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
2380
2334
  );
2381
2335
  }
2382
2336
  async updateAddress(input) {
2383
- return safe5(
2337
+ return safe(
2384
2338
  this.client.linkPost(
2385
2339
  `/v1/link/addresses/${encodePathSegment(input.address_id)}`,
2386
2340
  toUpdateAddressPayload(input)
@@ -2388,26 +2342,26 @@ var LinkService = class {
2388
2342
  );
2389
2343
  }
2390
2344
  async deleteAddress(addressId) {
2391
- return safe5(
2345
+ return safe(
2392
2346
  this.client.linkDelete(`/v1/link/addresses/${encodePathSegment(addressId)}`)
2393
2347
  );
2394
2348
  }
2395
2349
  async setDefaultAddress(addressId) {
2396
- return safe5(
2350
+ return safe(
2397
2351
  this.client.linkPost(
2398
2352
  `/v1/link/addresses/${encodePathSegment(addressId)}/default`
2399
2353
  )
2400
2354
  );
2401
2355
  }
2402
2356
  async trackAddressUsage(addressId) {
2403
- return safe5(
2357
+ return safe(
2404
2358
  this.client.linkPost(
2405
2359
  `/v1/link/addresses/${encodePathSegment(addressId)}/track-usage`
2406
2360
  )
2407
2361
  );
2408
2362
  }
2409
2363
  async createMobileMoney(input) {
2410
- return safe5(
2364
+ return safe(
2411
2365
  this.client.linkPost(
2412
2366
  "/v1/link/mobile-money",
2413
2367
  toCreateMobileMoneyPayload(input)
@@ -2415,65 +2369,51 @@ var LinkService = class {
2415
2369
  );
2416
2370
  }
2417
2371
  async deleteMobileMoney(mobileMoneyId) {
2418
- return safe5(
2372
+ return safe(
2419
2373
  this.client.linkDelete(
2420
2374
  `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}`
2421
2375
  )
2422
2376
  );
2423
2377
  }
2424
2378
  async setDefaultMobileMoney(mobileMoneyId) {
2425
- return safe5(
2379
+ return safe(
2426
2380
  this.client.linkPost(
2427
2381
  `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/default`
2428
2382
  )
2429
2383
  );
2430
2384
  }
2431
2385
  async trackMobileMoneyUsage(mobileMoneyId) {
2432
- return safe5(
2386
+ return safe(
2433
2387
  this.client.linkPost(
2434
2388
  `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/track-usage`
2435
2389
  )
2436
2390
  );
2437
2391
  }
2438
2392
  async verifyMobileMoney(mobileMoneyId) {
2439
- return safe5(
2393
+ return safe(
2440
2394
  this.client.linkPost(
2441
2395
  `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
2442
2396
  )
2443
2397
  );
2444
2398
  }
2445
2399
  async getSessions() {
2446
- return safe5(this.client.linkGet("/v1/link/sessions"));
2400
+ return safe(this.client.linkGet("/v1/link/sessions"));
2447
2401
  }
2448
2402
  async revokeSession(sessionId) {
2449
- return safe5(this.client.linkDelete(`/v1/link/sessions/${sessionId}`));
2403
+ return safe(this.client.linkDelete(`/v1/link/sessions/${sessionId}`));
2450
2404
  }
2451
2405
  async revokeAllSessions() {
2452
- return safe5(this.client.linkDelete("/v1/link/sessions"));
2406
+ return safe(this.client.linkDelete("/v1/link/sessions"));
2453
2407
  }
2454
2408
  };
2455
2409
 
2456
2410
  // src/auth.ts
2457
- function toCimplifyError6(error) {
2458
- if (error instanceof CimplifyError) return error;
2459
- if (error instanceof Error) {
2460
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2461
- }
2462
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2463
- }
2464
- async function safe6(promise) {
2465
- try {
2466
- return ok(await promise);
2467
- } catch (error) {
2468
- return err(toCimplifyError6(error));
2469
- }
2470
- }
2471
2411
  var AuthService = class {
2472
2412
  constructor(client) {
2473
2413
  this.client = client;
2474
2414
  }
2475
2415
  async getStatus() {
2476
- return safe6(this.client.get("/api/v1/auth/status"));
2416
+ return safe(this.client.get("/api/v1/auth/status"));
2477
2417
  }
2478
2418
  async getCurrentUser() {
2479
2419
  const result = await this.getStatus();
@@ -2486,7 +2426,7 @@ var AuthService = class {
2486
2426
  return ok(result.value.is_authenticated);
2487
2427
  }
2488
2428
  async requestOtp(contact, contactType) {
2489
- return safe6(
2429
+ return safe(
2490
2430
  this.client.post("/api/v1/auth/request-otp", {
2491
2431
  contact,
2492
2432
  contact_type: contactType
@@ -2494,7 +2434,7 @@ var AuthService = class {
2494
2434
  );
2495
2435
  }
2496
2436
  async verifyOtp(code, contact) {
2497
- return safe6(
2437
+ return safe(
2498
2438
  this.client.post("/api/v1/auth/verify-otp", {
2499
2439
  otp_code: code,
2500
2440
  contact
@@ -2502,48 +2442,34 @@ var AuthService = class {
2502
2442
  );
2503
2443
  }
2504
2444
  async logout() {
2505
- return safe6(this.client.post("/api/v1/auth/logout"));
2445
+ return safe(this.client.post("/api/v1/auth/logout"));
2506
2446
  }
2507
2447
  async updateProfile(input) {
2508
- return safe6(this.client.post("/api/v1/auth/profile", input));
2448
+ return safe(this.client.post("/api/v1/auth/profile", input));
2509
2449
  }
2510
2450
  };
2511
2451
 
2512
2452
  // src/business.ts
2513
- function toCimplifyError7(error) {
2514
- if (error instanceof CimplifyError) return enrichError(error);
2515
- if (error instanceof Error) {
2516
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, error.message, false));
2517
- }
2518
- return enrichError(new CimplifyError(ErrorCode.UNKNOWN_ERROR, String(error), false));
2519
- }
2520
- async function safe7(promise) {
2521
- try {
2522
- return ok(await promise);
2523
- } catch (error) {
2524
- return err(toCimplifyError7(error));
2525
- }
2526
- }
2527
2453
  var BusinessService = class {
2528
2454
  constructor(client) {
2529
2455
  this.client = client;
2530
2456
  }
2531
2457
  async getInfo() {
2532
- return safe7(this.client.get("/api/v1/business"));
2458
+ return safe(this.client.get("/api/v1/business"));
2533
2459
  }
2534
2460
  async getByHandle(handle) {
2535
2461
  const encodedHandle = encodeURIComponent(handle);
2536
- return safe7(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
2462
+ return safe(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
2537
2463
  }
2538
2464
  async getByDomain(domain) {
2539
2465
  const encodedDomain = encodeURIComponent(domain);
2540
- return safe7(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
2466
+ return safe(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
2541
2467
  }
2542
2468
  async getSettings() {
2543
- return safe7(this.client.get("/api/v1/business/settings"));
2469
+ return safe(this.client.get("/api/v1/business/settings"));
2544
2470
  }
2545
2471
  async getLocations() {
2546
- return safe7(this.client.get("/api/v1/business/locations"));
2472
+ return safe(this.client.get("/api/v1/business/locations"));
2547
2473
  }
2548
2474
  async getLocation(locationId) {
2549
2475
  const result = await this.getLocations();
@@ -2555,7 +2481,7 @@ var BusinessService = class {
2555
2481
  return ok(location);
2556
2482
  }
2557
2483
  async getHours() {
2558
- return safe7(this.client.get("/api/v1/business/hours"));
2484
+ return safe(this.client.get("/api/v1/business/hours"));
2559
2485
  }
2560
2486
  async getLocationHours(locationId) {
2561
2487
  const result = await this.getHours();
@@ -2563,25 +2489,11 @@ var BusinessService = class {
2563
2489
  return ok(result.value.filter((hour) => hour.location_id === locationId));
2564
2490
  }
2565
2491
  async getBootstrap() {
2566
- return safe7(this.client.get("/api/v1/bootstrap"));
2492
+ return safe(this.client.get("/api/v1/bootstrap"));
2567
2493
  }
2568
2494
  };
2569
2495
 
2570
2496
  // src/inventory.ts
2571
- function toCimplifyError8(error) {
2572
- if (error instanceof CimplifyError) return error;
2573
- if (error instanceof Error) {
2574
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2575
- }
2576
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2577
- }
2578
- async function safe8(promise) {
2579
- try {
2580
- return ok(await promise);
2581
- } catch (error) {
2582
- return err(toCimplifyError8(error));
2583
- }
2584
- }
2585
2497
  var InventoryService = class {
2586
2498
  constructor(client) {
2587
2499
  this.client = client;
@@ -2600,14 +2512,14 @@ var InventoryService = class {
2600
2512
  const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
2601
2513
  location_id: locationId
2602
2514
  });
2603
- return safe8(this.client.get(path));
2515
+ return safe(this.client.get(path));
2604
2516
  }
2605
2517
  async getVariantStock(variantId, locationId) {
2606
2518
  const encodedId = encodeURIComponent(variantId);
2607
2519
  const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/stock`, {
2608
2520
  location_id: locationId
2609
2521
  });
2610
- return safe8(this.client.get(path));
2522
+ return safe(this.client.get(path));
2611
2523
  }
2612
2524
  async checkProductAvailability(productId, quantity, locationId) {
2613
2525
  const encodedId = encodeURIComponent(productId);
@@ -2615,7 +2527,7 @@ var InventoryService = class {
2615
2527
  quantity,
2616
2528
  location_id: locationId
2617
2529
  });
2618
- return safe8(this.client.get(path));
2530
+ return safe(this.client.get(path));
2619
2531
  }
2620
2532
  async checkVariantAvailability(variantId, quantity, locationId) {
2621
2533
  const encodedId = encodeURIComponent(variantId);
@@ -2623,7 +2535,7 @@ var InventoryService = class {
2623
2535
  quantity,
2624
2536
  location_id: locationId
2625
2537
  });
2626
- return safe8(this.client.get(path));
2538
+ return safe(this.client.get(path));
2627
2539
  }
2628
2540
  async checkMultipleAvailability(items, locationId) {
2629
2541
  const results = await Promise.all(
@@ -2649,20 +2561,6 @@ var InventoryService = class {
2649
2561
  };
2650
2562
 
2651
2563
  // src/scheduling.ts
2652
- function toCimplifyError9(error) {
2653
- if (error instanceof CimplifyError) return error;
2654
- if (error instanceof Error) {
2655
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2656
- }
2657
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2658
- }
2659
- async function safe9(promise) {
2660
- try {
2661
- return ok(await promise);
2662
- } catch (error) {
2663
- return err(toCimplifyError9(error));
2664
- }
2665
- }
2666
2564
  function withQuery2(path, params) {
2667
2565
  const searchParams = new URLSearchParams();
2668
2566
  for (const [key, value] of Object.entries(params)) {
@@ -2680,11 +2578,11 @@ var SchedulingService = class {
2680
2578
  this.client = client;
2681
2579
  }
2682
2580
  async getServices() {
2683
- return safe9(this.client.get("/api/v1/scheduling/services"));
2581
+ return safe(this.client.get("/api/v1/scheduling/services"));
2684
2582
  }
2685
2583
  async getService(serviceId) {
2686
2584
  const encodedId = encodeURIComponent(serviceId);
2687
- return safe9(this.client.get(`/api/v1/scheduling/services/${encodedId}`));
2585
+ return safe(this.client.get(`/api/v1/scheduling/services/${encodedId}`));
2688
2586
  }
2689
2587
  async getAvailableSlots(input) {
2690
2588
  const path = withQuery2("/api/v1/scheduling/slots", {
@@ -2693,7 +2591,7 @@ var SchedulingService = class {
2693
2591
  participant_count: input.participant_count,
2694
2592
  duration_minutes: input.duration_minutes
2695
2593
  });
2696
- return safe9(this.client.get(path));
2594
+ return safe(this.client.get(path));
2697
2595
  }
2698
2596
  async checkSlotAvailability(input) {
2699
2597
  const path = withQuery2("/api/v1/scheduling/slots/check", {
@@ -2702,7 +2600,7 @@ var SchedulingService = class {
2702
2600
  duration_minutes: input.duration_minutes,
2703
2601
  participant_count: input.participant_count
2704
2602
  });
2705
- return safe9(this.client.get(path));
2603
+ return safe(this.client.get(path));
2706
2604
  }
2707
2605
  async getServiceAvailability(params) {
2708
2606
  const path = withQuery2("/api/v1/scheduling/availability", {
@@ -2712,17 +2610,17 @@ var SchedulingService = class {
2712
2610
  location_id: params.location_id,
2713
2611
  participant_count: params.participant_count
2714
2612
  });
2715
- return safe9(this.client.get(path));
2613
+ return safe(this.client.get(path));
2716
2614
  }
2717
2615
  async getBooking(bookingId) {
2718
2616
  const encodedId = encodeURIComponent(bookingId);
2719
- return safe9(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
2617
+ return safe(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
2720
2618
  }
2721
2619
  async getCustomerBookings(customerId) {
2722
2620
  const path = withQuery2("/api/v1/scheduling/bookings", {
2723
2621
  customer_id: customerId
2724
2622
  });
2725
- return safe9(this.client.get(path));
2623
+ return safe(this.client.get(path));
2726
2624
  }
2727
2625
  async getUpcomingBookings() {
2728
2626
  const result = await this.getCustomerBookings();
@@ -2741,14 +2639,14 @@ var SchedulingService = class {
2741
2639
  }
2742
2640
  async cancelBooking(input) {
2743
2641
  const encodedId = encodeURIComponent(input.booking_id);
2744
- return safe9(
2642
+ return safe(
2745
2643
  this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
2746
2644
  reason: input.reason
2747
2645
  })
2748
2646
  );
2749
2647
  }
2750
2648
  async rescheduleBooking(input) {
2751
- return safe9(
2649
+ return safe(
2752
2650
  this.client.post("/api/v1/scheduling/bookings/reschedule", input)
2753
2651
  );
2754
2652
  }
@@ -2772,65 +2670,37 @@ var SchedulingService = class {
2772
2670
  };
2773
2671
 
2774
2672
  // src/lite.ts
2775
- function toCimplifyError10(error) {
2776
- if (error instanceof CimplifyError) return error;
2777
- if (error instanceof Error) {
2778
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2779
- }
2780
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2781
- }
2782
- async function safe10(promise) {
2783
- try {
2784
- return ok(await promise);
2785
- } catch (error) {
2786
- return err(toCimplifyError10(error));
2787
- }
2788
- }
2789
2673
  var LiteService = class {
2790
2674
  constructor(client) {
2791
2675
  this.client = client;
2792
2676
  }
2793
2677
  async getBootstrap() {
2794
- return safe10(this.client.get("/api/v1/lite/bootstrap"));
2678
+ return safe(this.client.get("/api/v1/lite/bootstrap"));
2795
2679
  }
2796
2680
  async getTable(tableId) {
2797
2681
  const encodedId = encodeURIComponent(tableId);
2798
- return safe10(this.client.get(`/api/v1/lite/tables/${encodedId}`));
2682
+ return safe(this.client.get(`/api/v1/lite/tables/${encodedId}`));
2799
2683
  }
2800
2684
  async getMenu() {
2801
- return safe10(this.client.get("/api/v1/lite/menu"));
2685
+ return safe(this.client.get("/api/v1/lite/menu"));
2802
2686
  }
2803
2687
  async getMenuByCategory(categoryId) {
2804
2688
  const encodedId = encodeURIComponent(categoryId);
2805
- return safe10(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
2689
+ return safe(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
2806
2690
  }
2807
2691
  };
2808
2692
 
2809
2693
  // src/fx.ts
2810
- function toCimplifyError11(error) {
2811
- if (error instanceof CimplifyError) return error;
2812
- if (error instanceof Error) {
2813
- return new CimplifyError("UNKNOWN_ERROR", error.message, false);
2814
- }
2815
- return new CimplifyError("UNKNOWN_ERROR", String(error), false);
2816
- }
2817
- async function safe11(promise) {
2818
- try {
2819
- return ok(await promise);
2820
- } catch (error) {
2821
- return err(toCimplifyError11(error));
2822
- }
2823
- }
2824
2694
  var FxService = class {
2825
2695
  constructor(client) {
2826
2696
  this.client = client;
2827
2697
  }
2828
2698
  async getRate(from, to) {
2829
2699
  const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
2830
- return safe11(this.client.get(path));
2700
+ return safe(this.client.get(path));
2831
2701
  }
2832
2702
  async lockQuote(request) {
2833
- return safe11(this.client.post("/api/v1/fx/quotes", request));
2703
+ return safe(this.client.post("/api/v1/fx/quotes", request));
2834
2704
  }
2835
2705
  };
2836
2706
 
@@ -2985,6 +2855,11 @@ var CimplifyElements = class {
2985
2855
  window.addEventListener("message", this.boundHandleMessage);
2986
2856
  }
2987
2857
  }
2858
+ debug(...args) {
2859
+ if (this.client.isTestMode()) {
2860
+ console.debug(...args);
2861
+ }
2862
+ }
2988
2863
  create(type, options = {}) {
2989
2864
  const existing = this.elements.get(type);
2990
2865
  if (existing) return existing;
@@ -3039,9 +2914,9 @@ var CimplifyElements = class {
3039
2914
  processCheckout(options) {
3040
2915
  let abortFn = null;
3041
2916
  const task = (async () => {
3042
- console.debug("[cimplify:checkout] processCheckout called", { cart_id: options.cart_id, order_type: options.order_type, location_id: options.location_id });
2917
+ this.debug("[cimplify:checkout] processCheckout called", { cart_id: options.cart_id, order_type: options.order_type, location_id: options.location_id });
3043
2918
  if (this.checkoutInProgress) {
3044
- console.debug("[cimplify:checkout] BLOCKED: already processing");
2919
+ this.debug("[cimplify:checkout] BLOCKED: already processing");
3045
2920
  return toCheckoutError(
3046
2921
  "ALREADY_PROCESSING",
3047
2922
  "Checkout is already in progress.",
@@ -3050,7 +2925,7 @@ var CimplifyElements = class {
3050
2925
  }
3051
2926
  this.checkoutInProgress = true;
3052
2927
  if (!options.cart_id) {
3053
- console.debug("[cimplify:checkout] BLOCKED: no cart_id");
2928
+ this.debug("[cimplify:checkout] BLOCKED: no cart_id");
3054
2929
  this.checkoutInProgress = false;
3055
2930
  return toCheckoutError(
3056
2931
  "INVALID_CART",
@@ -3059,7 +2934,7 @@ var CimplifyElements = class {
3059
2934
  );
3060
2935
  }
3061
2936
  if (!options.order_type) {
3062
- console.debug("[cimplify:checkout] BLOCKED: no order_type");
2937
+ this.debug("[cimplify:checkout] BLOCKED: no order_type");
3063
2938
  this.checkoutInProgress = false;
3064
2939
  return toCheckoutError(
3065
2940
  "ORDER_TYPE_REQUIRED",
@@ -3069,7 +2944,7 @@ var CimplifyElements = class {
3069
2944
  }
3070
2945
  const checkoutElement = this.elements.get(ELEMENT_TYPES.CHECKOUT) || this.elements.get(ELEMENT_TYPES.PAYMENT);
3071
2946
  if (!checkoutElement) {
3072
- console.debug("[cimplify:checkout] BLOCKED: no checkout element");
2947
+ this.debug("[cimplify:checkout] BLOCKED: no checkout element");
3073
2948
  this.checkoutInProgress = false;
3074
2949
  return toCheckoutError(
3075
2950
  "NO_PAYMENT_ELEMENT",
@@ -3078,7 +2953,7 @@ var CimplifyElements = class {
3078
2953
  );
3079
2954
  }
3080
2955
  if (!checkoutElement.isMounted()) {
3081
- console.debug("[cimplify:checkout] BLOCKED: checkout element not mounted");
2956
+ this.debug("[cimplify:checkout] BLOCKED: checkout element not mounted");
3082
2957
  this.checkoutInProgress = false;
3083
2958
  return toCheckoutError(
3084
2959
  "PAYMENT_NOT_MOUNTED",
@@ -3090,7 +2965,7 @@ var CimplifyElements = class {
3090
2965
  if (!isUnifiedCheckout) {
3091
2966
  const authElement = this.elements.get(ELEMENT_TYPES.AUTH);
3092
2967
  if (authElement && !this.accessToken) {
3093
- console.debug("[cimplify:checkout] BLOCKED: auth incomplete");
2968
+ this.debug("[cimplify:checkout] BLOCKED: auth incomplete");
3094
2969
  this.checkoutInProgress = false;
3095
2970
  return toCheckoutError(
3096
2971
  "AUTH_INCOMPLETE",
@@ -3100,13 +2975,13 @@ var CimplifyElements = class {
3100
2975
  }
3101
2976
  const addressElement = this.elements.get(ELEMENT_TYPES.ADDRESS);
3102
2977
  if (addressElement) {
3103
- console.debug("[cimplify:checkout] getting address data...");
2978
+ this.debug("[cimplify:checkout] getting address data...");
3104
2979
  await addressElement.getData();
3105
- console.debug("[cimplify:checkout] address data resolved", this.addressData);
2980
+ this.debug("[cimplify:checkout] address data resolved", this.addressData);
3106
2981
  }
3107
2982
  await this.hydrateCustomerData();
3108
2983
  }
3109
- console.debug("[cimplify:checkout] customer data hydrated", { customerData: this.customerData, accountId: this.accountId, isUnifiedCheckout });
2984
+ this.debug("[cimplify:checkout] customer data hydrated", { customerData: this.customerData, accountId: this.accountId, isUnifiedCheckout });
3110
2985
  const processMessage = {
3111
2986
  type: MESSAGE_TYPES.PROCESS_CHECKOUT,
3112
2987
  cart_id: options.cart_id,
@@ -3182,7 +3057,7 @@ var CimplifyElements = class {
3182
3057
  return;
3183
3058
  }
3184
3059
  if (message.type === MESSAGE_TYPES.CHECKOUT_COMPLETE) {
3185
- console.debug("[cimplify:checkout] received checkout_complete", { success: message.success, error: message.error });
3060
+ this.debug("[cimplify:checkout] received checkout_complete", { success: message.success, error: message.error });
3186
3061
  settle({
3187
3062
  success: message.success,
3188
3063
  order: message.order,
@@ -3205,9 +3080,9 @@ var CimplifyElements = class {
3205
3080
  );
3206
3081
  };
3207
3082
  this.activeCheckoutAbort = abortFn;
3208
- console.debug("[cimplify:checkout] sending process_checkout to checkout iframe", { cart_id: processMessage.cart_id, order_type: processMessage.order_type, hasCustomer: !!processMessage.customer, hasAddress: !!processMessage.address, isUnifiedCheckout });
3083
+ this.debug("[cimplify:checkout] sending process_checkout to checkout iframe", { cart_id: processMessage.cart_id, order_type: processMessage.order_type, hasCustomer: !!processMessage.customer, hasAddress: !!processMessage.address, isUnifiedCheckout });
3209
3084
  checkoutElement.sendMessage(processMessage);
3210
- console.debug("[cimplify:checkout] postMessage sent, waiting for checkout_complete...");
3085
+ this.debug("[cimplify:checkout] postMessage sent, waiting for checkout_complete...");
3211
3086
  });
3212
3087
  })();
3213
3088
  const abortable = task;