@cimplify/sdk 0.7.2 → 0.7.4

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/react.mjs CHANGED
@@ -835,11 +835,6 @@ function err(error) {
835
835
  return { ok: false, error };
836
836
  }
837
837
 
838
- // src/query/builder.ts
839
- function escapeQueryValue(value) {
840
- return value.replace(/'/g, "\\'");
841
- }
842
-
843
838
  // src/catalogue.ts
844
839
  function toCimplifyError(error) {
845
840
  if (error instanceof CimplifyError) return enrichError(error);
@@ -855,14 +850,6 @@ async function safe(promise) {
855
850
  return err(toCimplifyError(error));
856
851
  }
857
852
  }
858
- async function safeWithFallback(primary, fallback) {
859
- const primaryResult = await safe(primary());
860
- if (primaryResult.ok) return primaryResult;
861
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
862
- return primaryResult;
863
- }
864
- return safe(fallback());
865
- }
866
853
  function withQuery(path, params) {
867
854
  const query = new URLSearchParams();
868
855
  for (const [key, value] of Object.entries(params)) {
@@ -924,22 +911,6 @@ function normalizeCatalogueProductPayload(product) {
924
911
  }
925
912
  return normalized;
926
913
  }
927
- function findProductBySlug(products, slug) {
928
- return products.find((product) => {
929
- const value = product["slug"];
930
- return typeof value === "string" && value === slug;
931
- });
932
- }
933
- function findCategoryBySlug(categories, slug) {
934
- return categories.find((category) => {
935
- const value = category["slug"];
936
- return typeof value === "string" && value === slug;
937
- });
938
- }
939
- function hasCategorySlug(category) {
940
- const value = category["slug"];
941
- return typeof value === "string" && value.trim().length > 0;
942
- }
943
914
  function toFiniteNumber(value) {
944
915
  if (typeof value === "number" && Number.isFinite(value)) {
945
916
  return value;
@@ -1027,53 +998,11 @@ var CatalogueQueries = class {
1027
998
  this.client = client;
1028
999
  }
1029
1000
  async getCatalogue() {
1030
- const result = await safeWithFallback(
1031
- () => this.client.get("/api/v1/catalogue"),
1032
- () => this.client.query("catalogue")
1033
- );
1001
+ const result = await safe(this.client.get("/api/v1/catalogue"));
1034
1002
  if (!result.ok) return result;
1035
1003
  return ok(normalizeCatalogueSnapshot(result.value));
1036
1004
  }
1037
1005
  async getProducts(options) {
1038
- let query = "products";
1039
- const filters = [];
1040
- if (options?.category) {
1041
- filters.push(`@.category_id=='${escapeQueryValue(options.category)}'`);
1042
- }
1043
- if (options?.featured !== void 0) {
1044
- filters.push(`@.featured==${options.featured}`);
1045
- }
1046
- if (options?.in_stock !== void 0) {
1047
- filters.push(`@.in_stock==${options.in_stock}`);
1048
- }
1049
- if (options?.search) {
1050
- filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
1051
- }
1052
- if (options?.tags?.length) {
1053
- for (const tag of options.tags) {
1054
- if (tag.trim().length > 0) {
1055
- filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
1056
- }
1057
- }
1058
- }
1059
- if (options?.min_price !== void 0) {
1060
- filters.push(`@.price>=${options.min_price}`);
1061
- }
1062
- if (options?.max_price !== void 0) {
1063
- filters.push(`@.price<=${options.max_price}`);
1064
- }
1065
- if (filters.length > 0) {
1066
- query += `[?(${filters.join(" && ")})]`;
1067
- }
1068
- if (options?.sort_by) {
1069
- query += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
1070
- }
1071
- if (options?.limit !== void 0) {
1072
- query += `#limit(${options.limit})`;
1073
- }
1074
- if (options?.offset !== void 0) {
1075
- query += `#offset(${options.offset})`;
1076
- }
1077
1006
  const path = withQuery("/api/v1/catalogue/products", {
1078
1007
  category_id: options?.category,
1079
1008
  search: options?.search,
@@ -1089,325 +1018,145 @@ var CatalogueQueries = class {
1089
1018
  offset: options?.offset,
1090
1019
  cursor: options?.cursor
1091
1020
  });
1092
- const result = await safeWithFallback(
1093
- () => this.client.get(path),
1094
- () => this.client.query(query)
1095
- );
1021
+ const result = await safe(this.client.get(path));
1096
1022
  if (!result.ok) return result;
1097
1023
  return ok(normalizeCatalogueResult(result.value));
1098
1024
  }
1099
1025
  async getProduct(id) {
1100
1026
  const encodedId = encodeURIComponent(id);
1101
- const result = await safeWithFallback(
1102
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
1103
- () => this.client.query(`products.${id}`)
1104
- );
1027
+ const result = await safe(this.client.get(`/api/v1/catalogue/products/${encodedId}`));
1105
1028
  if (!result.ok) return result;
1106
1029
  return ok(normalizeCatalogueProductPayload(result.value));
1107
1030
  }
1108
1031
  async getProductBySlug(slug) {
1109
1032
  const encodedSlug = encodeURIComponent(slug);
1110
- const restResult = await safe(
1111
- this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
1112
- );
1113
- if (restResult.ok) {
1114
- return ok(normalizeCatalogueProductPayload(restResult.value));
1115
- }
1116
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1117
- return restResult;
1118
- }
1119
- const filteredResult = await safe(
1120
- this.client.query(
1121
- `products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
1122
- )
1123
- );
1124
- if (!filteredResult.ok) return filteredResult;
1125
- const exactMatch = findProductBySlug(filteredResult.value, slug);
1126
- if (exactMatch) {
1127
- return ok(normalizeCatalogueProductPayload(exactMatch));
1128
- }
1129
- if (filteredResult.value.length === 1) {
1130
- return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
1131
- }
1132
- const unfilteredResult = await safe(
1133
- this.client.query("products#limit(200)")
1134
- );
1135
- if (!unfilteredResult.ok) return unfilteredResult;
1136
- const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
1137
- if (!fallbackMatch) {
1138
- return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
1139
- }
1140
- return ok(normalizeCatalogueProductPayload(fallbackMatch));
1033
+ const result = await safe(this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`));
1034
+ if (!result.ok) return result;
1035
+ return ok(normalizeCatalogueProductPayload(result.value));
1141
1036
  }
1142
1037
  async getVariants(productId) {
1143
1038
  const encodedId = encodeURIComponent(productId);
1144
- return safeWithFallback(
1145
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
1146
- () => this.client.query(`products.${productId}.variants`)
1147
- );
1039
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`));
1148
1040
  }
1149
1041
  async getVariantAxes(productId) {
1150
1042
  const encodedId = encodeURIComponent(productId);
1151
- return safeWithFallback(
1152
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
1153
- () => this.client.query(`products.${productId}.variant_axes`)
1154
- );
1043
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`));
1155
1044
  }
1156
- /**
1157
- * Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
1158
- * Returns the matching variant or null if no match found.
1159
- */
1160
1045
  async getVariantByAxisSelections(productId, selections) {
1161
1046
  const encodedId = encodeURIComponent(productId);
1162
- return safeWithFallback(
1163
- () => this.client.post(
1047
+ return safe(
1048
+ this.client.post(
1164
1049
  `/api/v1/catalogue/products/${encodedId}/variants/find`,
1165
1050
  {
1166
1051
  axis_selections: selections
1167
1052
  }
1168
- ),
1169
- () => this.client.query(`products.${productId}.variant`, {
1170
- axis_selections: selections
1171
- })
1053
+ )
1172
1054
  );
1173
1055
  }
1174
- /**
1175
- * Get a specific variant by its ID
1176
- */
1177
1056
  async getVariantById(productId, variantId) {
1178
1057
  const encodedProductId = encodeURIComponent(productId);
1179
1058
  const encodedVariantId = encodeURIComponent(variantId);
1180
- return safeWithFallback(
1181
- () => this.client.get(
1059
+ return safe(
1060
+ this.client.get(
1182
1061
  `/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
1183
- ),
1184
- () => this.client.query(`products.${productId}.variant.${variantId}`)
1062
+ )
1185
1063
  );
1186
1064
  }
1187
1065
  async getAddOns(productId) {
1188
1066
  const encodedId = encodeURIComponent(productId);
1189
- return safeWithFallback(
1190
- () => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
1191
- () => this.client.query(`products.${productId}.add_ons`)
1192
- );
1067
+ return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`));
1193
1068
  }
1194
1069
  async getCategories() {
1195
- const result = await safeWithFallback(
1196
- () => this.client.get("/api/v1/catalogue/categories"),
1197
- () => this.client.query("categories")
1198
- );
1199
- if (!result.ok) return result;
1200
- if (result.value.some(hasCategorySlug)) {
1201
- return result;
1202
- }
1203
- const catalogueResult = await safe(
1204
- this.client.query("catalogue#limit(1)")
1205
- );
1206
- if (!catalogueResult.ok) {
1207
- return result;
1208
- }
1209
- const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
1210
- return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
1070
+ return safe(this.client.get("/api/v1/catalogue/categories"));
1211
1071
  }
1212
1072
  async getCategory(id) {
1213
1073
  const encodedId = encodeURIComponent(id);
1214
- return safeWithFallback(
1215
- () => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
1216
- () => this.client.query(`categories.${id}`)
1217
- );
1074
+ return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}`));
1218
1075
  }
1219
1076
  async getCategoryBySlug(slug) {
1220
1077
  const encodedSlug = encodeURIComponent(slug);
1221
- const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
1222
- if (restResult.ok) {
1223
- return restResult;
1224
- }
1225
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1226
- return restResult;
1227
- }
1228
- const result = await safe(
1229
- this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
1230
- );
1231
- if (!result.ok) return result;
1232
- const exactMatch = findCategoryBySlug(result.value, slug);
1233
- if (exactMatch) {
1234
- return ok(exactMatch);
1235
- }
1236
- const categoriesResult = await this.getCategories();
1237
- if (!categoriesResult.ok) {
1238
- return categoriesResult;
1239
- }
1240
- const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
1241
- if (!fallbackMatch) {
1242
- return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
1243
- }
1244
- return ok(fallbackMatch);
1078
+ return safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
1245
1079
  }
1246
1080
  async getCategoryProducts(categoryId) {
1247
1081
  const encodedId = encodeURIComponent(categoryId);
1248
- return safeWithFallback(
1249
- () => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
1250
- () => this.client.query(
1251
- `products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
1252
- )
1253
- );
1082
+ return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`));
1254
1083
  }
1255
1084
  async getCollections() {
1256
- return safeWithFallback(
1257
- () => this.client.get("/api/v1/catalogue/collections"),
1258
- () => this.client.query("collections")
1259
- );
1085
+ return safe(this.client.get("/api/v1/catalogue/collections"));
1260
1086
  }
1261
1087
  async getCollection(id) {
1262
1088
  const encodedId = encodeURIComponent(id);
1263
- return safeWithFallback(
1264
- () => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
1265
- () => this.client.query(`collections.${id}`)
1266
- );
1089
+ return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}`));
1267
1090
  }
1268
1091
  async getCollectionBySlug(slug) {
1269
1092
  const encodedSlug = encodeURIComponent(slug);
1270
- const restResult = await safe(
1271
- this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
1272
- );
1273
- if (restResult.ok) return restResult;
1274
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1275
- return restResult;
1276
- }
1277
- const result = await safe(
1278
- this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
1279
- );
1280
- if (!result.ok) return result;
1281
- if (!result.value.length) {
1282
- return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
1283
- }
1284
- return ok(result.value[0]);
1093
+ return safe(this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`));
1285
1094
  }
1286
1095
  async getCollectionProducts(collectionId) {
1287
1096
  const encodedId = encodeURIComponent(collectionId);
1288
- return safeWithFallback(
1289
- () => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
1290
- () => this.client.query(`collections.${collectionId}.products`)
1291
- );
1097
+ return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`));
1292
1098
  }
1293
1099
  async searchCollections(query, limit = 20) {
1294
1100
  const path = withQuery("/api/v1/catalogue/collections", { search: query, limit });
1295
- return safeWithFallback(
1296
- () => this.client.get(path),
1297
- () => this.client.query(
1298
- `collections[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
1299
- )
1300
- );
1101
+ return safe(this.client.get(path));
1301
1102
  }
1302
1103
  async getBundles() {
1303
- return safeWithFallback(
1304
- () => this.client.get("/api/v1/catalogue/bundles"),
1305
- () => this.client.query("bundles")
1306
- );
1104
+ return safe(this.client.get("/api/v1/catalogue/bundles"));
1307
1105
  }
1308
1106
  async getBundle(id) {
1309
1107
  const encodedId = encodeURIComponent(id);
1310
- return safeWithFallback(
1311
- () => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
1312
- () => this.client.query(`bundles.${id}`)
1313
- );
1108
+ return safe(this.client.get(`/api/v1/catalogue/bundles/${encodedId}`));
1314
1109
  }
1315
1110
  async getBundleBySlug(slug) {
1316
1111
  const encodedSlug = encodeURIComponent(slug);
1317
- const restResult = await safe(
1318
- this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
1319
- );
1320
- if (restResult.ok) return restResult;
1321
- if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1322
- return restResult;
1323
- }
1324
- const result = await safe(
1325
- this.client.query(
1326
- `bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
1327
- )
1328
- );
1329
- if (!result.ok) return result;
1330
- if (!result.value.length) {
1331
- return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
1332
- }
1333
- return ok(result.value[0]);
1112
+ return safe(this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`));
1334
1113
  }
1335
1114
  async searchBundles(query, limit = 20) {
1336
1115
  const path = withQuery("/api/v1/catalogue/bundles", { search: query, limit });
1337
- return safeWithFallback(
1338
- () => this.client.get(path),
1339
- () => this.client.query(
1340
- `bundles[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
1341
- )
1342
- );
1116
+ return safe(this.client.get(path));
1343
1117
  }
1344
1118
  async getComposites(options) {
1345
- let query = "composites";
1346
- if (options?.limit) {
1347
- query += `#limit(${options.limit})`;
1348
- }
1349
1119
  const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
1350
- return safeWithFallback(
1351
- () => this.client.get(path),
1352
- () => this.client.query(query)
1353
- );
1120
+ return safe(this.client.get(path));
1354
1121
  }
1355
1122
  async getComposite(id) {
1356
1123
  const encodedId = encodeURIComponent(id);
1357
- return safeWithFallback(
1358
- () => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
1359
- () => this.client.query(`composites.${id}`)
1360
- );
1124
+ return safe(this.client.get(`/api/v1/catalogue/composites/${encodedId}`));
1361
1125
  }
1362
1126
  async getCompositeByProductId(productId) {
1363
1127
  const encodedId = encodeURIComponent(productId);
1364
- return safeWithFallback(
1365
- () => this.client.get(
1128
+ return safe(
1129
+ this.client.get(
1366
1130
  `/api/v1/catalogue/composites/by-product/${encodedId}`
1367
- ),
1368
- () => this.client.query(`composites.by_product.${productId}`)
1131
+ )
1369
1132
  );
1370
1133
  }
1371
1134
  async calculateCompositePrice(compositeId, selections, locationId) {
1372
1135
  const encodedId = encodeURIComponent(compositeId);
1373
- return safeWithFallback(
1374
- () => this.client.post(
1136
+ return safe(
1137
+ this.client.post(
1375
1138
  `/api/v1/catalogue/composites/${encodedId}/calculate-price`,
1376
1139
  {
1377
1140
  selections,
1378
1141
  location_id: locationId
1379
1142
  }
1380
- ),
1381
- () => this.client.call("composite.calculatePrice", {
1382
- composite_id: compositeId,
1383
- selections,
1384
- location_id: locationId
1385
- })
1143
+ )
1386
1144
  );
1387
1145
  }
1388
1146
  async fetchQuote(input) {
1389
- return safeWithFallback(
1390
- () => this.client.post("/api/v1/catalogue/quotes", input),
1391
- () => this.client.call("catalogue.createQuote", input)
1392
- );
1147
+ return safe(this.client.post("/api/v1/catalogue/quotes", input));
1393
1148
  }
1394
1149
  async getQuote(quoteId) {
1395
1150
  const encodedQuoteId = encodeURIComponent(quoteId);
1396
- return safeWithFallback(
1397
- () => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
1398
- () => this.client.call("catalogue.getQuote", {
1399
- quote_id: quoteId
1400
- })
1401
- );
1151
+ return safe(this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`));
1402
1152
  }
1403
1153
  async refreshQuote(input) {
1404
1154
  const encodedQuoteId = encodeURIComponent(input.quote_id);
1405
- return safeWithFallback(
1406
- () => this.client.post(
1155
+ return safe(
1156
+ this.client.post(
1407
1157
  `/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
1408
1158
  input
1409
- ),
1410
- () => this.client.call("catalogue.refreshQuote", input)
1159
+ )
1411
1160
  );
1412
1161
  }
1413
1162
  async search(query, options) {
@@ -1423,35 +1172,19 @@ var CatalogueQueries = class {
1423
1172
  return this.search(query, options);
1424
1173
  }
1425
1174
  async getMenu(options) {
1426
- let query = "menu";
1427
- if (options?.category) {
1428
- query = `menu[?(@.category=='${escapeQueryValue(options.category)}')]`;
1429
- }
1430
- if (options?.limit) {
1431
- query += `#limit(${options.limit})`;
1432
- }
1433
1175
  const path = withQuery("/api/v1/catalogue/menu", {
1434
1176
  category_id: options?.category,
1435
1177
  limit: options?.limit
1436
1178
  });
1437
- return safeWithFallback(
1438
- () => this.client.get(path),
1439
- () => this.client.query(query)
1440
- );
1179
+ return safe(this.client.get(path));
1441
1180
  }
1442
1181
  async getMenuCategory(categoryId) {
1443
1182
  const encodedId = encodeURIComponent(categoryId);
1444
- return safeWithFallback(
1445
- () => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
1446
- () => this.client.query(`menu.category.${categoryId}`)
1447
- );
1183
+ return safe(this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`));
1448
1184
  }
1449
1185
  async getMenuItem(itemId) {
1450
1186
  const encodedId = encodeURIComponent(itemId);
1451
- return safeWithFallback(
1452
- () => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
1453
- () => this.client.query(`menu.${itemId}`)
1454
- );
1187
+ return safe(this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`));
1455
1188
  }
1456
1189
  };
1457
1190
 
@@ -1470,14 +1203,6 @@ async function safe2(promise) {
1470
1203
  return err(toCimplifyError2(error));
1471
1204
  }
1472
1205
  }
1473
- async function safeWithFallback2(primary, fallback) {
1474
- const primaryResult = await safe2(primary());
1475
- if (primaryResult.ok) return primaryResult;
1476
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
1477
- return primaryResult;
1478
- }
1479
- return safe2(fallback());
1480
- }
1481
1206
  function isUICartResponse(value) {
1482
1207
  return "cart" in value;
1483
1208
  }
@@ -1489,36 +1214,21 @@ var CartOperations = class {
1489
1214
  this.client = client;
1490
1215
  }
1491
1216
  async get() {
1492
- const result = await safeWithFallback2(
1493
- () => this.client.get("/api/v1/cart"),
1494
- () => this.client.query("cart#enriched")
1495
- );
1217
+ const result = await safe2(this.client.get("/api/v1/cart"));
1496
1218
  if (!result.ok) return result;
1497
1219
  return ok(unwrapEnrichedCart(result.value));
1498
1220
  }
1499
1221
  async getRaw() {
1500
- return safeWithFallback2(
1501
- () => this.client.get("/api/v1/cart"),
1502
- () => this.client.query("cart")
1503
- );
1222
+ return safe2(this.client.get("/api/v1/cart"));
1504
1223
  }
1505
1224
  async getItems() {
1506
- return safeWithFallback2(
1507
- () => this.client.get("/api/v1/cart/items"),
1508
- () => this.client.query("cart_items")
1509
- );
1225
+ return safe2(this.client.get("/api/v1/cart/items"));
1510
1226
  }
1511
1227
  async getCount() {
1512
- return safeWithFallback2(
1513
- () => this.client.get("/api/v1/cart/count"),
1514
- () => this.client.query("cart#count")
1515
- );
1228
+ return safe2(this.client.get("/api/v1/cart/count"));
1516
1229
  }
1517
1230
  async getTotal() {
1518
- return safeWithFallback2(
1519
- () => this.client.get("/api/v1/cart/total"),
1520
- () => this.client.query("cart#total")
1521
- );
1231
+ return safe2(this.client.get("/api/v1/cart/total"));
1522
1232
  }
1523
1233
  async getSummary() {
1524
1234
  const cartResult = await this.get();
@@ -1535,66 +1245,39 @@ var CartOperations = class {
1535
1245
  });
1536
1246
  }
1537
1247
  async addItem(input) {
1538
- return safeWithFallback2(
1539
- () => this.client.post("/api/v1/cart/items", input),
1540
- () => this.client.call("cart.addItem", input)
1541
- );
1248
+ return safe2(this.client.post("/api/v1/cart/items", input));
1542
1249
  }
1543
1250
  async updateItem(cartItemId, updates) {
1544
1251
  if (typeof updates.quantity === "number") {
1545
1252
  return this.updateQuantity(cartItemId, updates.quantity);
1546
1253
  }
1547
1254
  const encodedId = encodeURIComponent(cartItemId);
1548
- return safeWithFallback2(
1549
- () => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
1550
- () => this.client.call("cart.updateItem", {
1551
- cart_item_id: cartItemId,
1552
- ...updates
1553
- })
1554
- );
1255
+ return safe2(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
1555
1256
  }
1556
1257
  async updateQuantity(cartItemId, quantity) {
1557
1258
  const encodedId = encodeURIComponent(cartItemId);
1558
- return safeWithFallback2(
1559
- () => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
1560
- quantity
1561
- }),
1562
- () => this.client.call("cart.updateItemQuantity", {
1563
- cart_item_id: cartItemId,
1259
+ return safe2(
1260
+ this.client.patch(`/api/v1/cart/items/${encodedId}`, {
1564
1261
  quantity
1565
1262
  })
1566
1263
  );
1567
1264
  }
1568
1265
  async removeItem(cartItemId) {
1569
1266
  const encodedId = encodeURIComponent(cartItemId);
1570
- return safeWithFallback2(
1571
- () => this.client.delete(`/api/v1/cart/items/${encodedId}`),
1572
- () => this.client.call("cart.removeItem", {
1573
- cart_item_id: cartItemId
1574
- })
1575
- );
1267
+ return safe2(this.client.delete(`/api/v1/cart/items/${encodedId}`));
1576
1268
  }
1577
1269
  async clear() {
1578
- return safeWithFallback2(
1579
- () => this.client.delete("/api/v1/cart"),
1580
- () => this.client.call("cart.clearCart")
1581
- );
1270
+ return safe2(this.client.delete("/api/v1/cart"));
1582
1271
  }
1583
1272
  async applyCoupon(code) {
1584
- return safeWithFallback2(
1585
- () => this.client.post("/api/v1/cart/coupons", {
1586
- coupon_code: code
1587
- }),
1588
- () => this.client.call("cart.applyCoupon", {
1273
+ return safe2(
1274
+ this.client.post("/api/v1/cart/coupons", {
1589
1275
  coupon_code: code
1590
1276
  })
1591
1277
  );
1592
1278
  }
1593
1279
  async removeCoupon() {
1594
- return safeWithFallback2(
1595
- () => this.client.delete("/api/v1/cart/coupons/current"),
1596
- () => this.client.call("cart.removeCoupon")
1597
- );
1280
+ return safe2(this.client.delete("/api/v1/cart/coupons/current"));
1598
1281
  }
1599
1282
  async isEmpty() {
1600
1283
  const countResult = await this.getCount();
@@ -1631,35 +1314,6 @@ var CartOperations = class {
1631
1314
  }
1632
1315
  };
1633
1316
 
1634
- // src/constants.ts
1635
- var LINK_QUERY = {
1636
- PREFERENCES: "link.preferences"};
1637
- var LINK_MUTATION = {
1638
- CHECK_STATUS: "link.check_status",
1639
- ENROLL: "link.enroll",
1640
- ENROLL_AND_LINK_ORDER: "link.enroll_and_link_order",
1641
- UPDATE_PREFERENCES: "link.update_preferences",
1642
- CREATE_ADDRESS: "link.create_address",
1643
- UPDATE_ADDRESS: "link.update_address",
1644
- TRACK_ADDRESS_USAGE: "link.track_address_usage",
1645
- CREATE_MOBILE_MONEY: "link.create_mobile_money",
1646
- TRACK_MOBILE_MONEY_USAGE: "link.track_mobile_money_usage",
1647
- VERIFY_MOBILE_MONEY: "link.verify_mobile_money"};
1648
- var AUTH_MUTATION = {
1649
- REQUEST_OTP: "auth.request_otp",
1650
- VERIFY_OTP: "auth.verify_otp"
1651
- };
1652
- var CHECKOUT_MUTATION = {
1653
- PROCESS: "checkout.process"
1654
- };
1655
- var PAYMENT_MUTATION = {
1656
- SUBMIT_AUTHORIZATION: "payment.submit_authorization",
1657
- CHECK_STATUS: "order.poll_payment_status"
1658
- };
1659
- var ORDER_MUTATION = {
1660
- UPDATE_CUSTOMER: "order.update_order_customer"
1661
- };
1662
-
1663
1317
  // src/utils/price.ts
1664
1318
  function parsePrice(value) {
1665
1319
  if (value === void 0 || value === null) {
@@ -2367,14 +2021,6 @@ async function safe3(promise) {
2367
2021
  return err(toCimplifyError3(error));
2368
2022
  }
2369
2023
  }
2370
- async function safeWithFallback3(primary, fallback) {
2371
- const primaryResult = await safe3(primary());
2372
- if (primaryResult.ok) return primaryResult;
2373
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2374
- return primaryResult;
2375
- }
2376
- return safe3(fallback());
2377
- }
2378
2024
  function toTerminalFailure(code, message, recoverable) {
2379
2025
  return {
2380
2026
  success: false,
@@ -2406,11 +2052,8 @@ var CheckoutService = class {
2406
2052
  ...data,
2407
2053
  idempotency_key: data.idempotency_key || generateIdempotencyKey()
2408
2054
  };
2409
- const result = await safeWithFallback3(
2410
- () => this.client.post("/api/v1/checkout", {
2411
- checkout_data: checkoutData
2412
- }),
2413
- () => this.client.call(CHECKOUT_MUTATION.PROCESS, {
2055
+ const result = await safe3(
2056
+ this.client.post("/api/v1/checkout", {
2414
2057
  checkout_data: checkoutData
2415
2058
  })
2416
2059
  );
@@ -2419,45 +2062,32 @@ var CheckoutService = class {
2419
2062
  }
2420
2063
  return result;
2421
2064
  }
2422
- async initializePayment(orderId, method) {
2423
- return safe3(
2424
- this.client.call("order.initializePayment", {
2425
- order_id: orderId,
2426
- payment_method: method
2427
- })
2065
+ async initializePayment(_orderId, _method) {
2066
+ return err(
2067
+ new CimplifyError(
2068
+ "NOT_IMPLEMENTED",
2069
+ "initializePayment is not available in REST mode.",
2070
+ false
2071
+ )
2428
2072
  );
2429
2073
  }
2430
2074
  async submitAuthorization(input) {
2431
- return safeWithFallback3(
2432
- () => this.client.post("/api/v1/payments/authorization", input),
2433
- () => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
2434
- );
2075
+ return safe3(this.client.post("/api/v1/payments/authorization", input));
2435
2076
  }
2436
2077
  async pollPaymentStatus(orderId) {
2437
2078
  const encodedId = encodeURIComponent(orderId);
2438
2079
  const tokenParam = this.orderTokenParam(orderId);
2439
- return safeWithFallback3(
2440
- () => this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`),
2441
- () => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
2442
- );
2080
+ return safe3(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
2443
2081
  }
2444
2082
  async updateOrderCustomer(orderId, customer) {
2445
2083
  const encodedId = encodeURIComponent(orderId);
2446
2084
  const tokenParam = this.orderTokenParam(orderId);
2447
- return safeWithFallback3(
2448
- () => this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer),
2449
- () => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
2450
- order_id: orderId,
2451
- ...customer
2452
- })
2453
- );
2085
+ return safe3(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
2454
2086
  }
2455
2087
  async verifyPayment(orderId) {
2456
- return safe3(
2457
- this.client.call("order.verifyPayment", {
2458
- order_id: orderId
2459
- })
2460
- );
2088
+ const encodedId = encodeURIComponent(orderId);
2089
+ const tokenParam = this.orderTokenParam(orderId);
2090
+ return safe3(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
2461
2091
  }
2462
2092
  async processAndResolve(data) {
2463
2093
  data.on_status_change?.("preparing", {});
@@ -2576,14 +2206,6 @@ async function safe4(promise) {
2576
2206
  return err(toCimplifyError4(error));
2577
2207
  }
2578
2208
  }
2579
- async function safeWithFallback4(primary, fallback) {
2580
- const primaryResult = await safe4(primary());
2581
- if (primaryResult.ok) return primaryResult;
2582
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2583
- return primaryResult;
2584
- }
2585
- return safe4(fallback());
2586
- }
2587
2209
  var OrderQueries = class {
2588
2210
  constructor(client) {
2589
2211
  this.client = client;
@@ -2593,37 +2215,20 @@ var OrderQueries = class {
2593
2215
  return token ? `?token=${encodeURIComponent(token)}` : "";
2594
2216
  }
2595
2217
  async list(options) {
2596
- let query = "orders";
2597
- if (options?.status) {
2598
- query += `[?(@.status=='${options.status}')]`;
2599
- }
2600
- query += "#sort(created_at,desc)";
2601
- if (options?.limit) {
2602
- query += `#limit(${options.limit})`;
2603
- }
2604
- if (options?.offset) {
2605
- query += `#offset(${options.offset})`;
2606
- }
2607
2218
  const params = new URLSearchParams();
2608
2219
  if (options?.status) params.set("status", options.status);
2609
2220
  if (options?.limit) params.set("limit", String(options.limit));
2610
2221
  if (options?.offset) params.set("offset", String(options.offset));
2611
2222
  const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
2612
- return safeWithFallback4(
2613
- () => this.client.get(path),
2614
- () => this.client.query(query)
2615
- );
2223
+ return safe4(this.client.get(path));
2616
2224
  }
2617
2225
  async get(orderId) {
2618
2226
  const encodedId = encodeURIComponent(orderId);
2619
2227
  const tokenParam = this.orderTokenParam(orderId);
2620
- return safeWithFallback4(
2621
- () => this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`),
2622
- () => this.client.query(`orders.${orderId}`)
2623
- );
2228
+ return safe4(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
2624
2229
  }
2625
2230
  async getRecent(limit = 5) {
2626
- return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
2231
+ return this.list({ limit });
2627
2232
  }
2628
2233
  async getByStatus(status) {
2629
2234
  return this.list({ status });
@@ -2631,12 +2236,8 @@ var OrderQueries = class {
2631
2236
  async cancel(orderId, reason) {
2632
2237
  const encodedId = encodeURIComponent(orderId);
2633
2238
  const tokenParam = this.orderTokenParam(orderId);
2634
- return safeWithFallback4(
2635
- () => this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
2636
- reason
2637
- }),
2638
- () => this.client.call("order.cancelOrder", {
2639
- order_id: orderId,
2239
+ return safe4(
2240
+ this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
2640
2241
  reason
2641
2242
  })
2642
2243
  );
@@ -2658,6 +2259,38 @@ async function safe5(promise) {
2658
2259
  return err(toCimplifyError5(error));
2659
2260
  }
2660
2261
  }
2262
+ function encodePathSegment(value) {
2263
+ return encodeURIComponent(value);
2264
+ }
2265
+ function toCreateAddressPayload(input) {
2266
+ return {
2267
+ label: input.label,
2268
+ street_address: input.address_line1,
2269
+ apartment: input.address_line2,
2270
+ city: input.city,
2271
+ region: input.state ?? "",
2272
+ postal_code: input.postal_code,
2273
+ country: input.country
2274
+ };
2275
+ }
2276
+ function toUpdateAddressPayload(input) {
2277
+ return {
2278
+ label: input.label,
2279
+ street_address: input.address_line1,
2280
+ apartment: input.address_line2,
2281
+ city: input.city,
2282
+ region: input.state,
2283
+ postal_code: input.postal_code,
2284
+ country: input.country
2285
+ };
2286
+ }
2287
+ function toCreateMobileMoneyPayload(input) {
2288
+ return {
2289
+ phone_number: input.phone_number,
2290
+ provider: input.provider,
2291
+ label: input.account_name
2292
+ };
2293
+ }
2661
2294
  var LinkService = class {
2662
2295
  constructor(client) {
2663
2296
  this.client = client;
@@ -2685,11 +2318,7 @@ var LinkService = class {
2685
2318
  return result;
2686
2319
  }
2687
2320
  async checkStatus(contact) {
2688
- return safe5(
2689
- this.client.call(LINK_MUTATION.CHECK_STATUS, {
2690
- contact
2691
- })
2692
- );
2321
+ return safe5(this.client.linkPost("/v1/link/check-status", { contact }));
2693
2322
  }
2694
2323
  async getLinkData() {
2695
2324
  return safe5(this.client.linkGet("/v1/link/data"));
@@ -2701,61 +2330,85 @@ var LinkService = class {
2701
2330
  return safe5(this.client.linkGet("/v1/link/mobile-money"));
2702
2331
  }
2703
2332
  async getPreferences() {
2704
- return safe5(this.client.query(LINK_QUERY.PREFERENCES));
2333
+ return safe5(this.client.linkGet("/v1/link/preferences"));
2705
2334
  }
2706
2335
  async enroll(data) {
2707
- return safe5(this.client.call(LINK_MUTATION.ENROLL, data));
2336
+ return safe5(this.client.linkPost("/v1/link/enroll", data));
2708
2337
  }
2709
2338
  async enrollAndLinkOrder(data) {
2710
2339
  return safe5(
2711
- this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data)
2340
+ this.client.linkPost("/v1/link/enroll-and-link-order", data)
2712
2341
  );
2713
2342
  }
2714
2343
  async updatePreferences(preferences) {
2715
- return safe5(this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences));
2344
+ return safe5(this.client.linkPost("/v1/link/preferences", preferences));
2716
2345
  }
2717
2346
  async createAddress(input) {
2718
- return safe5(this.client.call(LINK_MUTATION.CREATE_ADDRESS, input));
2347
+ return safe5(
2348
+ this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
2349
+ );
2719
2350
  }
2720
2351
  async updateAddress(input) {
2721
- return safe5(this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input));
2352
+ return safe5(
2353
+ this.client.linkPost(
2354
+ `/v1/link/addresses/${encodePathSegment(input.address_id)}`,
2355
+ toUpdateAddressPayload(input)
2356
+ )
2357
+ );
2722
2358
  }
2723
2359
  async deleteAddress(addressId) {
2724
- return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
2360
+ return safe5(
2361
+ this.client.linkDelete(`/v1/link/addresses/${encodePathSegment(addressId)}`)
2362
+ );
2725
2363
  }
2726
2364
  async setDefaultAddress(addressId) {
2727
- return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
2365
+ return safe5(
2366
+ this.client.linkPost(
2367
+ `/v1/link/addresses/${encodePathSegment(addressId)}/default`
2368
+ )
2369
+ );
2728
2370
  }
2729
2371
  async trackAddressUsage(addressId) {
2730
2372
  return safe5(
2731
- this.client.call(LINK_MUTATION.TRACK_ADDRESS_USAGE, {
2732
- address_id: addressId
2733
- })
2373
+ this.client.linkPost(
2374
+ `/v1/link/addresses/${encodePathSegment(addressId)}/track-usage`
2375
+ )
2734
2376
  );
2735
2377
  }
2736
2378
  async createMobileMoney(input) {
2737
- return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
2379
+ return safe5(
2380
+ this.client.linkPost(
2381
+ "/v1/link/mobile-money",
2382
+ toCreateMobileMoneyPayload(input)
2383
+ )
2384
+ );
2738
2385
  }
2739
2386
  async deleteMobileMoney(mobileMoneyId) {
2740
2387
  return safe5(
2741
- this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`)
2388
+ this.client.linkDelete(
2389
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}`
2390
+ )
2742
2391
  );
2743
2392
  }
2744
2393
  async setDefaultMobileMoney(mobileMoneyId) {
2745
2394
  return safe5(
2746
- this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
2395
+ this.client.linkPost(
2396
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/default`
2397
+ )
2747
2398
  );
2748
2399
  }
2749
2400
  async trackMobileMoneyUsage(mobileMoneyId) {
2750
2401
  return safe5(
2751
- this.client.call(LINK_MUTATION.TRACK_MOBILE_MONEY_USAGE, {
2752
- mobile_money_id: mobileMoneyId
2753
- })
2402
+ this.client.linkPost(
2403
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/track-usage`
2404
+ )
2754
2405
  );
2755
2406
  }
2756
2407
  async verifyMobileMoney(mobileMoneyId) {
2757
2408
  return safe5(
2758
- this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId)
2409
+ this.client.linkPost(
2410
+ `/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
2411
+ )
2759
2412
  );
2760
2413
  }
2761
2414
  async getSessions() {
@@ -2768,30 +2421,28 @@ var LinkService = class {
2768
2421
  return safe5(this.client.linkDelete("/v1/link/sessions"));
2769
2422
  }
2770
2423
  async getAddressesRest() {
2771
- return safe5(this.client.linkGet("/v1/link/addresses"));
2424
+ return this.getAddresses();
2772
2425
  }
2773
2426
  async createAddressRest(input) {
2774
- return safe5(this.client.linkPost("/v1/link/addresses", input));
2427
+ return this.createAddress(input);
2775
2428
  }
2776
2429
  async deleteAddressRest(addressId) {
2777
- return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
2430
+ return this.deleteAddress(addressId);
2778
2431
  }
2779
2432
  async setDefaultAddressRest(addressId) {
2780
- return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
2433
+ return this.setDefaultAddress(addressId);
2781
2434
  }
2782
2435
  async getMobileMoneyRest() {
2783
- return safe5(this.client.linkGet("/v1/link/mobile-money"));
2436
+ return this.getMobileMoney();
2784
2437
  }
2785
2438
  async createMobileMoneyRest(input) {
2786
- return safe5(this.client.linkPost("/v1/link/mobile-money", input));
2439
+ return this.createMobileMoney(input);
2787
2440
  }
2788
2441
  async deleteMobileMoneyRest(mobileMoneyId) {
2789
- return safe5(this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`));
2442
+ return this.deleteMobileMoney(mobileMoneyId);
2790
2443
  }
2791
2444
  async setDefaultMobileMoneyRest(mobileMoneyId) {
2792
- return safe5(
2793
- this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
2794
- );
2445
+ return this.setDefaultMobileMoney(mobileMoneyId);
2795
2446
  }
2796
2447
  };
2797
2448
 
@@ -2810,23 +2461,12 @@ async function safe6(promise) {
2810
2461
  return err(toCimplifyError6(error));
2811
2462
  }
2812
2463
  }
2813
- async function safeWithFallback5(primary, fallback) {
2814
- const primaryResult = await safe6(primary());
2815
- if (primaryResult.ok) return primaryResult;
2816
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2817
- return primaryResult;
2818
- }
2819
- return safe6(fallback());
2820
- }
2821
2464
  var AuthService = class {
2822
2465
  constructor(client) {
2823
2466
  this.client = client;
2824
2467
  }
2825
2468
  async getStatus() {
2826
- return safeWithFallback5(
2827
- () => this.client.get("/api/v1/auth/status"),
2828
- () => this.client.query("auth")
2829
- );
2469
+ return safe6(this.client.get("/api/v1/auth/status"));
2830
2470
  }
2831
2471
  async getCurrentUser() {
2832
2472
  const result = await this.getStatus();
@@ -2839,43 +2479,26 @@ var AuthService = class {
2839
2479
  return ok(result.value.is_authenticated);
2840
2480
  }
2841
2481
  async requestOtp(contact, contactType) {
2842
- return safeWithFallback5(
2843
- () => this.client.post("/api/v1/auth/request-otp", {
2844
- contact,
2845
- contact_type: contactType
2846
- }),
2847
- () => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
2482
+ return safe6(
2483
+ this.client.post("/api/v1/auth/request-otp", {
2848
2484
  contact,
2849
2485
  contact_type: contactType
2850
2486
  })
2851
2487
  );
2852
2488
  }
2853
2489
  async verifyOtp(code, contact) {
2854
- return safeWithFallback5(
2855
- () => this.client.post("/api/v1/auth/verify-otp", {
2856
- otp_code: code,
2857
- contact
2858
- }),
2859
- () => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
2490
+ return safe6(
2491
+ this.client.post("/api/v1/auth/verify-otp", {
2860
2492
  otp_code: code,
2861
2493
  contact
2862
2494
  })
2863
2495
  );
2864
2496
  }
2865
2497
  async logout() {
2866
- return safeWithFallback5(
2867
- () => this.client.post("/api/v1/auth/logout"),
2868
- () => this.client.call("auth.logout")
2869
- );
2498
+ return safe6(this.client.post("/api/v1/auth/logout"));
2870
2499
  }
2871
2500
  async updateProfile(input) {
2872
- return safe6(this.client.call("auth.update_profile", input));
2873
- }
2874
- async changePassword(input) {
2875
- return safe6(this.client.call("auth.change_password", input));
2876
- }
2877
- async resetPassword(email) {
2878
- return safe6(this.client.call("auth.reset_password", { email }));
2501
+ return safe6(this.client.post("/api/v1/auth/profile", input));
2879
2502
  }
2880
2503
  };
2881
2504
 
@@ -2894,47 +2517,29 @@ async function safe7(promise) {
2894
2517
  return err(toCimplifyError7(error));
2895
2518
  }
2896
2519
  }
2897
- async function safeWithFallback6(primary, fallback) {
2898
- const primaryResult = await safe7(primary());
2899
- if (primaryResult.ok) return primaryResult;
2900
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2901
- return primaryResult;
2902
- }
2903
- return safe7(fallback());
2904
- }
2905
2520
  var BusinessService = class {
2906
2521
  constructor(client) {
2907
2522
  this.client = client;
2908
2523
  }
2909
2524
  async getInfo() {
2910
- return safeWithFallback6(
2911
- () => this.client.get("/api/v1/business"),
2912
- () => this.client.query("business.info")
2913
- );
2525
+ return safe7(this.client.get("/api/v1/business"));
2914
2526
  }
2915
2527
  async getByHandle(handle) {
2916
- return safe7(this.client.query(`business.handle.${handle}`));
2528
+ const encodedHandle = encodeURIComponent(handle);
2529
+ return safe7(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
2917
2530
  }
2918
2531
  async getByDomain(domain) {
2919
- return safe7(this.client.query("business.domain", { domain }));
2532
+ const encodedDomain = encodeURIComponent(domain);
2533
+ return safe7(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
2920
2534
  }
2921
2535
  async getSettings() {
2922
- return safeWithFallback6(
2923
- () => this.client.get("/api/v1/business/settings"),
2924
- () => this.client.query("business.settings")
2925
- );
2536
+ return safe7(this.client.get("/api/v1/business/settings"));
2926
2537
  }
2927
2538
  async getTheme() {
2928
- return safeWithFallback6(
2929
- () => this.client.get("/api/v1/business/theme"),
2930
- () => this.client.query("business.theme")
2931
- );
2539
+ return safe7(this.client.get("/api/v1/business/theme"));
2932
2540
  }
2933
2541
  async getLocations() {
2934
- return safeWithFallback6(
2935
- () => this.client.get("/api/v1/business/locations"),
2936
- () => this.client.query("business.locations")
2937
- );
2542
+ return safe7(this.client.get("/api/v1/business/locations"));
2938
2543
  }
2939
2544
  async getLocation(locationId) {
2940
2545
  const result = await this.getLocations();
@@ -2946,10 +2551,7 @@ var BusinessService = class {
2946
2551
  return ok(location);
2947
2552
  }
2948
2553
  async getHours() {
2949
- return safeWithFallback6(
2950
- () => this.client.get("/api/v1/business/hours"),
2951
- () => this.client.query("business.hours")
2952
- );
2554
+ return safe7(this.client.get("/api/v1/business/hours"));
2953
2555
  }
2954
2556
  async getLocationHours(locationId) {
2955
2557
  const result = await this.getHours();
@@ -2957,31 +2559,7 @@ var BusinessService = class {
2957
2559
  return ok(result.value.filter((hour) => hour.location_id === locationId));
2958
2560
  }
2959
2561
  async getBootstrap() {
2960
- const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
2961
- if (restBootstrap.ok) {
2962
- return restBootstrap;
2963
- }
2964
- const [businessResult, locationsResult, categoriesResult] = await Promise.all([
2965
- this.getInfo(),
2966
- this.getLocations(),
2967
- safe7(this.client.query("categories#select(id,name,slug)"))
2968
- ]);
2969
- if (!businessResult.ok) return businessResult;
2970
- if (!locationsResult.ok) return locationsResult;
2971
- if (!categoriesResult.ok) return categoriesResult;
2972
- const business = businessResult.value;
2973
- const locations = locationsResult.value;
2974
- const categories = categoriesResult.value;
2975
- const defaultLocation = locations[0];
2976
- return ok({
2977
- business,
2978
- location: defaultLocation,
2979
- locations,
2980
- categories,
2981
- currency: business.default_currency,
2982
- is_open: defaultLocation?.accepts_online_orders ?? false,
2983
- accepts_orders: defaultLocation?.accepts_online_orders ?? false
2984
- });
2562
+ return safe7(this.client.get("/api/v1/bootstrap"));
2985
2563
  }
2986
2564
  };
2987
2565
 
@@ -3004,49 +2582,47 @@ var InventoryService = class {
3004
2582
  constructor(client) {
3005
2583
  this.client = client;
3006
2584
  }
2585
+ withQuery(path, params) {
2586
+ const searchParams = new URLSearchParams();
2587
+ for (const [key, value] of Object.entries(params)) {
2588
+ if (value === void 0) continue;
2589
+ searchParams.set(key, String(value));
2590
+ }
2591
+ const query = searchParams.toString();
2592
+ return query ? `${path}?${query}` : path;
2593
+ }
3007
2594
  async getStockLevels() {
3008
- return safe8(this.client.query("inventory.stock_levels"));
2595
+ return safe8(this.client.get("/api/v1/inventory/stock-levels"));
3009
2596
  }
3010
2597
  async getProductStock(productId, locationId) {
3011
- if (locationId) {
3012
- return safe8(
3013
- this.client.query("inventory.product", {
3014
- product_id: productId,
3015
- location_id: locationId
3016
- })
3017
- );
3018
- }
3019
- return safe8(
3020
- this.client.query("inventory.product", {
3021
- product_id: productId
3022
- })
3023
- );
2598
+ const encodedId = encodeURIComponent(productId);
2599
+ const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
2600
+ location_id: locationId
2601
+ });
2602
+ return safe8(this.client.get(path));
3024
2603
  }
3025
2604
  async getVariantStock(variantId, locationId) {
3026
- return safe8(
3027
- this.client.query("inventory.variant", {
3028
- variant_id: variantId,
3029
- location_id: locationId
3030
- })
3031
- );
2605
+ const encodedId = encodeURIComponent(variantId);
2606
+ const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/stock`, {
2607
+ location_id: locationId
2608
+ });
2609
+ return safe8(this.client.get(path));
3032
2610
  }
3033
2611
  async checkProductAvailability(productId, quantity, locationId) {
3034
- return safe8(
3035
- this.client.query("inventory.check_availability", {
3036
- product_id: productId,
3037
- quantity,
3038
- location_id: locationId
3039
- })
3040
- );
2612
+ const encodedId = encodeURIComponent(productId);
2613
+ const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/availability`, {
2614
+ quantity,
2615
+ location_id: locationId
2616
+ });
2617
+ return safe8(this.client.get(path));
3041
2618
  }
3042
2619
  async checkVariantAvailability(variantId, quantity, locationId) {
3043
- return safe8(
3044
- this.client.query("inventory.check_availability", {
3045
- variant_id: variantId,
3046
- quantity,
3047
- location_id: locationId
3048
- })
3049
- );
2620
+ const encodedId = encodeURIComponent(variantId);
2621
+ const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/availability`, {
2622
+ quantity,
2623
+ location_id: locationId
2624
+ });
2625
+ return safe8(this.client.get(path));
3050
2626
  }
3051
2627
  async checkMultipleAvailability(items, locationId) {
3052
2628
  const results = await Promise.all(
@@ -3060,7 +2636,7 @@ var InventoryService = class {
3060
2636
  return ok(results.map((r) => r.value));
3061
2637
  }
3062
2638
  async getSummary() {
3063
- return safe8(this.client.query("inventory.summary"));
2639
+ return safe8(this.client.get("/api/v1/inventory/summary"));
3064
2640
  }
3065
2641
  async isInStock(productId, locationId) {
3066
2642
  const result = await this.checkProductAvailability(productId, 1, locationId);
@@ -3075,9 +2651,6 @@ var InventoryService = class {
3075
2651
  };
3076
2652
 
3077
2653
  // src/scheduling.ts
3078
- function toVariables(input) {
3079
- return Object.fromEntries(Object.entries(input));
3080
- }
3081
2654
  function toCimplifyError9(error) {
3082
2655
  if (error instanceof CimplifyError) return error;
3083
2656
  if (error instanceof Error) {
@@ -3092,68 +2665,110 @@ async function safe9(promise) {
3092
2665
  return err(toCimplifyError9(error));
3093
2666
  }
3094
2667
  }
2668
+ function withQuery2(path, params) {
2669
+ const searchParams = new URLSearchParams();
2670
+ for (const [key, value] of Object.entries(params)) {
2671
+ if (value === void 0) continue;
2672
+ searchParams.set(key, String(value));
2673
+ }
2674
+ const query = searchParams.toString();
2675
+ return query ? `${path}?${query}` : path;
2676
+ }
2677
+ function normalizeServiceAvailability(result) {
2678
+ if (Array.isArray(result.days) && result.days.length > 0) {
2679
+ return result;
2680
+ }
2681
+ const days = Array.isArray(result.availability) ? result.availability.map((day) => ({
2682
+ ...day,
2683
+ is_fully_booked: day.is_fully_booked ?? (typeof day.has_availability === "boolean" ? !day.has_availability : void 0)
2684
+ })) : [];
2685
+ return { ...result, days };
2686
+ }
2687
+ function firstScheduledTime(booking) {
2688
+ return booking.service_items.find((item) => typeof item.scheduled_start === "string")?.scheduled_start || booking.created_at;
2689
+ }
3095
2690
  var SchedulingService = class {
3096
2691
  constructor(client) {
3097
2692
  this.client = client;
3098
2693
  }
3099
2694
  async getServices() {
3100
- return safe9(this.client.query("scheduling.services"));
2695
+ return safe9(this.client.get("/api/v1/scheduling/services"));
3101
2696
  }
3102
2697
  /**
3103
- * Get a specific service by ID
3104
- * Note: Filters from all services client-side (no single-service endpoint)
2698
+ * Get a specific service by ID.
3105
2699
  */
3106
2700
  async getService(serviceId) {
3107
2701
  const result = await this.getServices();
3108
2702
  if (!result.ok) return result;
3109
- return ok(result.value.find((s) => s.id === serviceId) || null);
2703
+ return ok(result.value.find((service) => service.id === serviceId) || null);
3110
2704
  }
3111
2705
  async getAvailableSlots(input) {
3112
- return safe9(
3113
- this.client.query("scheduling.slots", toVariables(input))
3114
- );
2706
+ const path = withQuery2("/api/v1/scheduling/slots", {
2707
+ service_id: input.service_id,
2708
+ date: input.date,
2709
+ participant_count: input.participant_count,
2710
+ duration_minutes: input.duration_minutes
2711
+ });
2712
+ return safe9(this.client.get(path));
3115
2713
  }
3116
2714
  async checkSlotAvailability(input) {
3117
- return safe9(
3118
- this.client.query(
3119
- "scheduling.check_availability",
3120
- toVariables(input)
3121
- )
3122
- );
2715
+ const path = withQuery2("/api/v1/scheduling/slots/check", {
2716
+ service_id: input.service_id,
2717
+ slot_time: input.slot_time,
2718
+ duration_minutes: input.duration_minutes,
2719
+ participant_count: input.participant_count
2720
+ });
2721
+ return safe9(this.client.get(path));
3123
2722
  }
3124
2723
  async getServiceAvailability(params) {
2724
+ const path = withQuery2("/api/v1/scheduling/availability", {
2725
+ service_id: params.service_id,
2726
+ start_date: params.start_date,
2727
+ end_date: params.end_date,
2728
+ location_id: params.location_id,
2729
+ participant_count: params.participant_count
2730
+ });
3125
2731
  return safe9(
3126
- this.client.query(
3127
- "scheduling.availability",
3128
- toVariables(params)
3129
- )
2732
+ this.client.get(path).then((result) => normalizeServiceAvailability(result))
3130
2733
  );
3131
2734
  }
3132
2735
  async getBooking(bookingId) {
3133
- return safe9(this.client.query(`scheduling.${bookingId}`));
2736
+ const encodedId = encodeURIComponent(bookingId);
2737
+ return safe9(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
3134
2738
  }
3135
- async getCustomerBookings() {
3136
- return safe9(this.client.query("scheduling"));
2739
+ async getCustomerBookings(customerId) {
2740
+ const path = withQuery2("/api/v1/scheduling/bookings", {
2741
+ customer_id: customerId
2742
+ });
2743
+ return safe9(this.client.get(path));
3137
2744
  }
3138
2745
  async getUpcomingBookings() {
3139
- return safe9(
3140
- this.client.query(
3141
- "scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
3142
- )
3143
- );
2746
+ const result = await this.getCustomerBookings();
2747
+ if (!result.ok) return result;
2748
+ const upcoming = result.value.filter((booking) => {
2749
+ const status = String(booking.status).toLowerCase();
2750
+ return status !== "completed" && status !== "cancelled";
2751
+ }).sort((a, b) => firstScheduledTime(a).localeCompare(firstScheduledTime(b)));
2752
+ return ok(upcoming);
3144
2753
  }
3145
2754
  async getPastBookings(limit = 10) {
3146
- return safe9(
3147
- this.client.query(
3148
- `scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
3149
- )
3150
- );
2755
+ const result = await this.getCustomerBookings();
2756
+ if (!result.ok) return result;
2757
+ const past = result.value.filter((booking) => String(booking.status).toLowerCase() === "completed").sort((a, b) => firstScheduledTime(b).localeCompare(firstScheduledTime(a))).slice(0, Math.max(0, limit));
2758
+ return ok(past);
3151
2759
  }
3152
2760
  async cancelBooking(input) {
3153
- return safe9(this.client.call("scheduling.cancel_booking", input));
2761
+ const encodedId = encodeURIComponent(input.booking_id);
2762
+ return safe9(
2763
+ this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
2764
+ reason: input.reason
2765
+ })
2766
+ );
3154
2767
  }
3155
2768
  async rescheduleBooking(input) {
3156
- return safe9(this.client.call("scheduling.reschedule_booking", input));
2769
+ return safe9(
2770
+ this.client.post("/api/v1/scheduling/bookings/reschedule", input)
2771
+ );
3157
2772
  }
3158
2773
  async getNextAvailableSlot(serviceId, fromDate) {
3159
2774
  const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
@@ -3172,6 +2787,12 @@ var SchedulingService = class {
3172
2787
  if (!result.ok) return result;
3173
2788
  return ok(result.value.some((slot) => slot.is_available));
3174
2789
  }
2790
+ // Compatibility alias for callers typed against the older Booking shape.
2791
+ async getBookingLegacy(bookingId) {
2792
+ const result = await this.getBooking(bookingId);
2793
+ if (!result.ok) return result;
2794
+ return ok(result.value);
2795
+ }
3175
2796
  };
3176
2797
 
3177
2798
  // src/lite.ts
@@ -3194,47 +2815,18 @@ var LiteService = class {
3194
2815
  this.client = client;
3195
2816
  }
3196
2817
  async getBootstrap() {
3197
- return safe10(this.client.query("lite.bootstrap"));
2818
+ return safe10(this.client.get("/api/v1/lite/bootstrap"));
3198
2819
  }
3199
2820
  async getTable(tableId) {
3200
- return safe10(this.client.query(`lite.table.${tableId}`));
3201
- }
3202
- async getTableByNumber(tableNumber, locationId) {
3203
- return safe10(
3204
- this.client.query("lite.table_by_number", {
3205
- table_number: tableNumber,
3206
- location_id: locationId
3207
- })
3208
- );
3209
- }
3210
- async sendToKitchen(tableId, items) {
3211
- return safe10(
3212
- this.client.call("lite.send_to_kitchen", {
3213
- table_id: tableId,
3214
- items
3215
- })
3216
- );
3217
- }
3218
- async callWaiter(tableId, reason) {
3219
- return safe10(
3220
- this.client.call("lite.call_waiter", {
3221
- table_id: tableId,
3222
- reason
3223
- })
3224
- );
3225
- }
3226
- async requestBill(tableId) {
3227
- return safe10(
3228
- this.client.call("lite.request_bill", {
3229
- table_id: tableId
3230
- })
3231
- );
2821
+ const encodedId = encodeURIComponent(tableId);
2822
+ return safe10(this.client.get(`/api/v1/lite/tables/${encodedId}`));
3232
2823
  }
3233
2824
  async getMenu() {
3234
- return safe10(this.client.query("lite.menu"));
2825
+ return safe10(this.client.get("/api/v1/lite/menu"));
3235
2826
  }
3236
2827
  async getMenuByCategory(categoryId) {
3237
- return safe10(this.client.query(`lite.menu.category.${categoryId}`));
2828
+ const encodedId = encodeURIComponent(categoryId);
2829
+ return safe10(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
3238
2830
  }
3239
2831
  };
3240
2832
 
@@ -3253,30 +2845,16 @@ async function safe11(promise) {
3253
2845
  return err(toCimplifyError11(error));
3254
2846
  }
3255
2847
  }
3256
- async function safeWithFallback7(primary, fallback) {
3257
- const primaryResult = await safe11(primary());
3258
- if (primaryResult.ok) return primaryResult;
3259
- if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
3260
- return primaryResult;
3261
- }
3262
- return safe11(fallback());
3263
- }
3264
2848
  var FxService = class {
3265
2849
  constructor(client) {
3266
2850
  this.client = client;
3267
2851
  }
3268
2852
  async getRate(from, to) {
3269
2853
  const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
3270
- return safeWithFallback7(
3271
- () => this.client.get(path),
3272
- () => this.client.call("fx.getRate", { from, to })
3273
- );
2854
+ return safe11(this.client.get(path));
3274
2855
  }
3275
2856
  async lockQuote(request) {
3276
- return safeWithFallback7(
3277
- () => this.client.post("/api/v1/fx/quotes", request),
3278
- () => this.client.call("fx.lockQuote", request)
3279
- );
2857
+ return safe11(this.client.post("/api/v1/fx/quotes", request));
3280
2858
  }
3281
2859
  };
3282
2860
 
@@ -3848,7 +3426,9 @@ function createElements(client, businessId, options) {
3848
3426
 
3849
3427
  // src/client.ts
3850
3428
  var ACCESS_TOKEN_STORAGE_KEY = "cimplify_access_token";
3429
+ var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
3851
3430
  var ORDER_TOKEN_PREFIX = "cimplify_ot_";
3431
+ var SESSION_TOKEN_HEADER = "x-session-token";
3852
3432
  var DEFAULT_TIMEOUT_MS = 3e4;
3853
3433
  var DEFAULT_MAX_RETRIES = 3;
3854
3434
  var DEFAULT_RETRY_DELAY_MS = 1e3;
@@ -3933,6 +3513,7 @@ function getEnvPublicKey() {
3933
3513
  var CimplifyClient = class {
3934
3514
  constructor(config = {}) {
3935
3515
  this.accessToken = null;
3516
+ this.sessionToken = null;
3936
3517
  this.context = {};
3937
3518
  this.businessId = null;
3938
3519
  this.businessIdResolvePromise = null;
@@ -3947,6 +3528,7 @@ var CimplifyClient = class {
3947
3528
  this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
3948
3529
  this.hooks = config.hooks ?? {};
3949
3530
  this.accessToken = this.loadAccessToken();
3531
+ this.sessionToken = this.loadSessionToken();
3950
3532
  if (!this.publicKey && !config.suppressPublicKeyWarning) {
3951
3533
  console.warn(
3952
3534
  '[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "pk_..." } to createCimplifyClient().'
@@ -3983,7 +3565,11 @@ var CimplifyClient = class {
3983
3565
  clearSession() {
3984
3566
  const previous = this.accessToken;
3985
3567
  this.accessToken = null;
3568
+ this.sessionToken = null;
3986
3569
  this.saveAccessToken(null);
3570
+ if (typeof window !== "undefined" && window.localStorage) {
3571
+ localStorage.removeItem(SESSION_TOKEN_STORAGE_KEY);
3572
+ }
3987
3573
  this.hooks.onSessionChange?.({
3988
3574
  previousToken: previous,
3989
3575
  newToken: null,
@@ -4080,6 +3666,27 @@ var CimplifyClient = class {
4080
3666
  }
4081
3667
  }
4082
3668
  }
3669
+ loadSessionToken() {
3670
+ if (typeof window !== "undefined" && window.localStorage) {
3671
+ return localStorage.getItem(SESSION_TOKEN_STORAGE_KEY);
3672
+ }
3673
+ return null;
3674
+ }
3675
+ saveSessionToken(token) {
3676
+ if (typeof window !== "undefined" && window.localStorage) {
3677
+ try {
3678
+ localStorage.setItem(SESSION_TOKEN_STORAGE_KEY, token);
3679
+ } catch {
3680
+ }
3681
+ }
3682
+ }
3683
+ captureSessionToken(response) {
3684
+ const token = response.headers.get(SESSION_TOKEN_HEADER);
3685
+ if (token && token !== this.sessionToken) {
3686
+ this.sessionToken = token;
3687
+ this.saveSessionToken(token);
3688
+ }
3689
+ }
4083
3690
  getHeaders() {
4084
3691
  const headers = {
4085
3692
  "Content-Type": "application/json"
@@ -4091,6 +3698,9 @@ var CimplifyClient = class {
4091
3698
  if (this.accessToken) {
4092
3699
  headers["Authorization"] = `Bearer ${this.accessToken}`;
4093
3700
  }
3701
+ if (this.sessionToken) {
3702
+ headers[SESSION_TOKEN_HEADER] = this.sessionToken;
3703
+ }
4094
3704
  return headers;
4095
3705
  }
4096
3706
  async resilientFetch(url, options) {
@@ -4116,6 +3726,7 @@ var CimplifyClient = class {
4116
3726
  signal: controller.signal
4117
3727
  });
4118
3728
  clearTimeout(timeoutId);
3729
+ this.captureSessionToken(response);
4119
3730
  if (response.ok) {
4120
3731
  this.hooks.onRequestSuccess?.({
4121
3732
  ...context,
@@ -4213,41 +3824,6 @@ var CimplifyClient = class {
4213
3824
  this.inflightRequests.set(key, request);
4214
3825
  return request;
4215
3826
  }
4216
- async query(query, variables) {
4217
- const body = { query };
4218
- if (variables) {
4219
- body.variables = variables;
4220
- }
4221
- if (Object.keys(this.context).length > 0) {
4222
- body.context = this.context;
4223
- }
4224
- const key = this.getDedupeKey("query", body);
4225
- return this.deduplicatedRequest(key, async () => {
4226
- const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
4227
- method: "POST",
4228
- credentials: this.credentials,
4229
- headers: this.getHeaders(),
4230
- body: JSON.stringify(body)
4231
- });
4232
- return this.handleResponse(response);
4233
- });
4234
- }
4235
- async call(method, args) {
4236
- const body = {
4237
- method,
4238
- args: args !== void 0 ? [args] : []
4239
- };
4240
- if (Object.keys(this.context).length > 0) {
4241
- body.context = this.context;
4242
- }
4243
- const response = await this.resilientFetch(`${this.baseUrl}/api/m`, {
4244
- method: "POST",
4245
- credentials: this.credentials,
4246
- headers: this.getHeaders(),
4247
- body: JSON.stringify(body)
4248
- });
4249
- return this.handleResponse(response);
4250
- }
4251
3827
  async get(path) {
4252
3828
  const key = this.getDedupeKey("get", path);
4253
3829
  return this.deduplicatedRequest(key, async () => {
@@ -4350,26 +3926,6 @@ var CimplifyClient = class {
4350
3926
  }
4351
3927
  return json;
4352
3928
  }
4353
- async handleResponse(response) {
4354
- const json = await response.json();
4355
- if (!json.success || json.error) {
4356
- const error = enrichError(
4357
- new CimplifyError(
4358
- json.error?.code || "UNKNOWN_ERROR",
4359
- json.error?.message || "An unknown error occurred",
4360
- json.error?.retryable || false
4361
- ),
4362
- { isTestMode: this.isTestMode() }
4363
- );
4364
- if (response.status === 401 || error.code === ErrorCode.UNAUTHORIZED) {
4365
- console.warn(
4366
- "[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
4367
- );
4368
- }
4369
- throw error;
4370
- }
4371
- return json.data;
4372
- }
4373
3929
  get catalogue() {
4374
3930
  if (!this._catalogue) {
4375
3931
  this._catalogue = new CatalogueQueries(this);