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