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