@cimplify/sdk 0.6.10 → 0.6.12

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
@@ -752,6 +752,10 @@ var ERROR_SUGGESTIONS = {
752
752
  CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
753
753
  DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
754
754
  CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
755
+ QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
756
+ QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
757
+ QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
758
+ QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
755
759
  PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
756
760
  PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
757
761
  INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
@@ -853,6 +857,23 @@ async function safe(promise) {
853
857
  return err(toCimplifyError(error));
854
858
  }
855
859
  }
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
+ function withQuery(path, params) {
869
+ const query = new URLSearchParams();
870
+ for (const [key, value] of Object.entries(params)) {
871
+ if (value === void 0) continue;
872
+ query.set(key, String(value));
873
+ }
874
+ const queryString = query.toString();
875
+ return queryString ? `${path}?${queryString}` : path;
876
+ }
856
877
  function isRecord(value) {
857
878
  return typeof value === "object" && value !== null;
858
879
  }
@@ -910,11 +931,79 @@ function findProductBySlug(products, slug) {
910
931
  return typeof value === "string" && value === slug;
911
932
  });
912
933
  }
934
+ function findCategoryBySlug(categories, slug) {
935
+ return categories.find((category) => {
936
+ const value = category["slug"];
937
+ return typeof value === "string" && value === slug;
938
+ });
939
+ }
940
+ function hasCategorySlug(category) {
941
+ const value = category["slug"];
942
+ return typeof value === "string" && value.trim().length > 0;
943
+ }
944
+ function toFiniteNumber(value) {
945
+ if (typeof value === "number" && Number.isFinite(value)) {
946
+ return value;
947
+ }
948
+ if (typeof value === "string" && value.trim().length > 0) {
949
+ const parsed = Number(value);
950
+ if (Number.isFinite(parsed)) {
951
+ return parsed;
952
+ }
953
+ }
954
+ return void 0;
955
+ }
956
+ function normalizePagination(value) {
957
+ if (!isRecord(value)) {
958
+ return void 0;
959
+ }
960
+ const totalCount = toFiniteNumber(value.total_count);
961
+ const currentPage = toFiniteNumber(value.current_page);
962
+ const pageSize = toFiniteNumber(value.page_size);
963
+ const totalPages = toFiniteNumber(value.total_pages);
964
+ if (totalCount === void 0 || currentPage === void 0 || pageSize === void 0 || totalPages === void 0) {
965
+ return void 0;
966
+ }
967
+ return {
968
+ total_count: totalCount,
969
+ current_page: currentPage,
970
+ page_size: pageSize,
971
+ total_pages: totalPages,
972
+ has_more: value.has_more === true,
973
+ next_cursor: typeof value.next_cursor === "string" ? value.next_cursor : void 0
974
+ };
975
+ }
976
+ function normalizeCatalogueResult(payload) {
977
+ if (Array.isArray(payload)) {
978
+ return {
979
+ items: payload.map((product) => normalizeCatalogueProductPayload(product)),
980
+ is_complete: true
981
+ };
982
+ }
983
+ if (!isRecord(payload)) {
984
+ return {
985
+ items: [],
986
+ is_complete: true
987
+ };
988
+ }
989
+ const rawItems = Array.isArray(payload.products) ? payload.products : Array.isArray(payload.items) ? payload.items : [];
990
+ return {
991
+ items: rawItems.map((product) => normalizeCatalogueProductPayload(product)),
992
+ is_complete: typeof payload.is_complete === "boolean" ? payload.is_complete : true,
993
+ total_available: toFiniteNumber(payload.total_available),
994
+ pagination: normalizePagination(payload.pagination)
995
+ };
996
+ }
913
997
  var CatalogueQueries = class {
914
998
  constructor(client) {
915
999
  this.client = client;
916
1000
  }
917
1001
  async getProducts(options) {
1002
+ const result = await this.getProductsWithMeta(options);
1003
+ if (!result.ok) return result;
1004
+ return ok(result.value.items);
1005
+ }
1006
+ async getProductsWithMeta(options) {
918
1007
  let query = "products";
919
1008
  const filters = [];
920
1009
  if (options?.category) {
@@ -929,6 +1018,13 @@ var CatalogueQueries = class {
929
1018
  if (options?.search) {
930
1019
  filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
931
1020
  }
1021
+ if (options?.tags?.length) {
1022
+ for (const tag of options.tags) {
1023
+ if (tag.trim().length > 0) {
1024
+ filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
1025
+ }
1026
+ }
1027
+ }
932
1028
  if (options?.min_price !== void 0) {
933
1029
  filters.push(`@.price>=${options.min_price}`);
934
1030
  }
@@ -941,25 +1037,57 @@ var CatalogueQueries = class {
941
1037
  if (options?.sort_by) {
942
1038
  query += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
943
1039
  }
944
- if (options?.limit) {
1040
+ if (options?.limit !== void 0) {
945
1041
  query += `#limit(${options.limit})`;
946
1042
  }
947
- if (options?.offset) {
1043
+ if (options?.offset !== void 0) {
948
1044
  query += `#offset(${options.offset})`;
949
1045
  }
950
- const result = await safe(this.client.query(query));
1046
+ const path = withQuery("/api/v1/catalogue/products", {
1047
+ category_id: options?.category,
1048
+ search: options?.search,
1049
+ page: options?.page,
1050
+ tags: options?.tags?.join(","),
1051
+ featured: options?.featured,
1052
+ in_stock: options?.in_stock,
1053
+ min_price: options?.min_price,
1054
+ max_price: options?.max_price,
1055
+ sort_by: options?.sort_by,
1056
+ sort_order: options?.sort_order,
1057
+ limit: options?.limit,
1058
+ offset: options?.offset,
1059
+ cursor: options?.cursor
1060
+ });
1061
+ const result = await safeWithFallback(
1062
+ () => this.client.get(path),
1063
+ () => this.client.query(query)
1064
+ );
951
1065
  if (!result.ok) return result;
952
- return ok(result.value.map((product) => normalizeCatalogueProductPayload(product)));
1066
+ return ok(normalizeCatalogueResult(result.value));
953
1067
  }
954
1068
  async getProduct(id) {
955
- const result = await safe(this.client.query(`products.${id}`));
1069
+ const encodedId = encodeURIComponent(id);
1070
+ const result = await safeWithFallback(
1071
+ () => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
1072
+ () => this.client.query(`products.${id}`)
1073
+ );
956
1074
  if (!result.ok) return result;
957
1075
  return ok(normalizeCatalogueProductPayload(result.value));
958
1076
  }
959
1077
  async getProductBySlug(slug) {
1078
+ const encodedSlug = encodeURIComponent(slug);
1079
+ const restResult = await safe(
1080
+ this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
1081
+ );
1082
+ if (restResult.ok) {
1083
+ return ok(normalizeCatalogueProductPayload(restResult.value));
1084
+ }
1085
+ if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1086
+ return restResult;
1087
+ }
960
1088
  const filteredResult = await safe(
961
1089
  this.client.query(
962
- `products[?(@.slug=='${escapeQueryValue(slug)}')]`
1090
+ `products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
963
1091
  )
964
1092
  );
965
1093
  if (!filteredResult.ok) return filteredResult;
@@ -970,7 +1098,9 @@ var CatalogueQueries = class {
970
1098
  if (filteredResult.value.length === 1) {
971
1099
  return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
972
1100
  }
973
- const unfilteredResult = await safe(this.client.query("products"));
1101
+ const unfilteredResult = await safe(
1102
+ this.client.query("products#limit(200)")
1103
+ );
974
1104
  if (!unfilteredResult.ok) return unfilteredResult;
975
1105
  const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
976
1106
  if (!fallbackMatch) {
@@ -979,18 +1109,33 @@ var CatalogueQueries = class {
979
1109
  return ok(normalizeCatalogueProductPayload(fallbackMatch));
980
1110
  }
981
1111
  async getVariants(productId) {
982
- return safe(this.client.query(`products.${productId}.variants`));
1112
+ const encodedId = encodeURIComponent(productId);
1113
+ return safeWithFallback(
1114
+ () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
1115
+ () => this.client.query(`products.${productId}.variants`)
1116
+ );
983
1117
  }
984
1118
  async getVariantAxes(productId) {
985
- return safe(this.client.query(`products.${productId}.variant_axes`));
1119
+ const encodedId = encodeURIComponent(productId);
1120
+ return safeWithFallback(
1121
+ () => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
1122
+ () => this.client.query(`products.${productId}.variant_axes`)
1123
+ );
986
1124
  }
987
1125
  /**
988
1126
  * Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
989
1127
  * Returns the matching variant or null if no match found.
990
1128
  */
991
1129
  async getVariantByAxisSelections(productId, selections) {
992
- return safe(
993
- this.client.query(`products.${productId}.variant`, {
1130
+ const encodedId = encodeURIComponent(productId);
1131
+ return safeWithFallback(
1132
+ () => this.client.post(
1133
+ `/api/v1/catalogue/products/${encodedId}/variants/find`,
1134
+ {
1135
+ axis_selections: selections
1136
+ }
1137
+ ),
1138
+ () => this.client.query(`products.${productId}.variant`, {
994
1139
  axis_selections: selections
995
1140
  })
996
1141
  );
@@ -999,45 +1144,107 @@ var CatalogueQueries = class {
999
1144
  * Get a specific variant by its ID
1000
1145
  */
1001
1146
  async getVariantById(productId, variantId) {
1002
- return safe(this.client.query(`products.${productId}.variant.${variantId}`));
1147
+ const encodedProductId = encodeURIComponent(productId);
1148
+ const encodedVariantId = encodeURIComponent(variantId);
1149
+ return safeWithFallback(
1150
+ () => this.client.get(
1151
+ `/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
1152
+ ),
1153
+ () => this.client.query(`products.${productId}.variant.${variantId}`)
1154
+ );
1003
1155
  }
1004
1156
  async getAddOns(productId) {
1005
- return safe(this.client.query(`products.${productId}.add_ons`));
1157
+ const encodedId = encodeURIComponent(productId);
1158
+ return safeWithFallback(
1159
+ () => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
1160
+ () => this.client.query(`products.${productId}.add_ons`)
1161
+ );
1006
1162
  }
1007
1163
  async getCategories() {
1008
- return safe(this.client.query("categories"));
1164
+ const result = await safeWithFallback(
1165
+ () => this.client.get("/api/v1/catalogue/categories"),
1166
+ () => this.client.query("categories")
1167
+ );
1168
+ if (!result.ok) return result;
1169
+ if (result.value.some(hasCategorySlug)) {
1170
+ return result;
1171
+ }
1172
+ const catalogueResult = await safe(
1173
+ this.client.query("catalogue#limit(1)")
1174
+ );
1175
+ if (!catalogueResult.ok) {
1176
+ return result;
1177
+ }
1178
+ const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
1179
+ return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
1009
1180
  }
1010
1181
  async getCategory(id) {
1011
- return safe(this.client.query(`categories.${id}`));
1182
+ const encodedId = encodeURIComponent(id);
1183
+ return safeWithFallback(
1184
+ () => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
1185
+ () => this.client.query(`categories.${id}`)
1186
+ );
1012
1187
  }
1013
1188
  async getCategoryBySlug(slug) {
1189
+ const encodedSlug = encodeURIComponent(slug);
1190
+ const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
1191
+ if (restResult.ok) {
1192
+ return restResult;
1193
+ }
1194
+ if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1195
+ return restResult;
1196
+ }
1014
1197
  const result = await safe(
1015
1198
  this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
1016
1199
  );
1017
1200
  if (!result.ok) return result;
1018
- if (!result.value.length) {
1201
+ const exactMatch = findCategoryBySlug(result.value, slug);
1202
+ if (exactMatch) {
1203
+ return ok(exactMatch);
1204
+ }
1205
+ const categoriesResult = await this.getCategories();
1206
+ if (!categoriesResult.ok) {
1207
+ return categoriesResult;
1208
+ }
1209
+ const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
1210
+ if (!fallbackMatch) {
1019
1211
  return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
1020
1212
  }
1021
- return ok(result.value[0]);
1213
+ return ok(fallbackMatch);
1022
1214
  }
1023
1215
  async getCategoryProducts(categoryId) {
1024
- return safe(
1025
- this.client.query(
1216
+ const encodedId = encodeURIComponent(categoryId);
1217
+ return safeWithFallback(
1218
+ () => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
1219
+ () => this.client.query(
1026
1220
  `products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
1027
1221
  )
1028
1222
  );
1029
1223
  }
1030
1224
  async getCollections() {
1031
- return safe(this.client.query("collections"));
1225
+ return safeWithFallback(
1226
+ () => this.client.get("/api/v1/catalogue/collections"),
1227
+ () => this.client.query("collections")
1228
+ );
1032
1229
  }
1033
1230
  async getCollection(id) {
1034
- return safe(this.client.query(`collections.${id}`));
1231
+ const encodedId = encodeURIComponent(id);
1232
+ return safeWithFallback(
1233
+ () => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
1234
+ () => this.client.query(`collections.${id}`)
1235
+ );
1035
1236
  }
1036
1237
  async getCollectionBySlug(slug) {
1238
+ const encodedSlug = encodeURIComponent(slug);
1239
+ const restResult = await safe(
1240
+ this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
1241
+ );
1242
+ if (restResult.ok) return restResult;
1243
+ if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1244
+ return restResult;
1245
+ }
1037
1246
  const result = await safe(
1038
- this.client.query(
1039
- `collections[?(@.slug=='${escapeQueryValue(slug)}')]`
1040
- )
1247
+ this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
1041
1248
  );
1042
1249
  if (!result.ok) return result;
1043
1250
  if (!result.value.length) {
@@ -1046,22 +1253,43 @@ var CatalogueQueries = class {
1046
1253
  return ok(result.value[0]);
1047
1254
  }
1048
1255
  async getCollectionProducts(collectionId) {
1049
- return safe(this.client.query(`collections.${collectionId}.products`));
1256
+ const encodedId = encodeURIComponent(collectionId);
1257
+ return safeWithFallback(
1258
+ () => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
1259
+ () => this.client.query(`collections.${collectionId}.products`)
1260
+ );
1050
1261
  }
1051
1262
  async searchCollections(query, limit = 20) {
1052
- return safe(
1053
- this.client.query(
1263
+ const path = withQuery("/api/v1/catalogue/collections", { search: query, limit });
1264
+ return safeWithFallback(
1265
+ () => this.client.get(path),
1266
+ () => this.client.query(
1054
1267
  `collections[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
1055
1268
  )
1056
1269
  );
1057
1270
  }
1058
1271
  async getBundles() {
1059
- return safe(this.client.query("bundles"));
1272
+ return safeWithFallback(
1273
+ () => this.client.get("/api/v1/catalogue/bundles"),
1274
+ () => this.client.query("bundles")
1275
+ );
1060
1276
  }
1061
1277
  async getBundle(id) {
1062
- return safe(this.client.query(`bundles.${id}`));
1278
+ const encodedId = encodeURIComponent(id);
1279
+ return safeWithFallback(
1280
+ () => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
1281
+ () => this.client.query(`bundles.${id}`)
1282
+ );
1063
1283
  }
1064
1284
  async getBundleBySlug(slug) {
1285
+ const encodedSlug = encodeURIComponent(slug);
1286
+ const restResult = await safe(
1287
+ this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
1288
+ );
1289
+ if (restResult.ok) return restResult;
1290
+ if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
1291
+ return restResult;
1292
+ }
1065
1293
  const result = await safe(
1066
1294
  this.client.query(
1067
1295
  `bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
@@ -1074,8 +1302,10 @@ var CatalogueQueries = class {
1074
1302
  return ok(result.value[0]);
1075
1303
  }
1076
1304
  async searchBundles(query, limit = 20) {
1077
- return safe(
1078
- this.client.query(
1305
+ const path = withQuery("/api/v1/catalogue/bundles", { search: query, limit });
1306
+ return safeWithFallback(
1307
+ () => this.client.get(path),
1308
+ () => this.client.query(
1079
1309
  `bundles[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
1080
1310
  )
1081
1311
  );
@@ -1085,17 +1315,39 @@ var CatalogueQueries = class {
1085
1315
  if (options?.limit) {
1086
1316
  query += `#limit(${options.limit})`;
1087
1317
  }
1088
- return safe(this.client.query(query));
1318
+ const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
1319
+ return safeWithFallback(
1320
+ () => this.client.get(path),
1321
+ () => this.client.query(query)
1322
+ );
1089
1323
  }
1090
1324
  async getComposite(id) {
1091
- return safe(this.client.query(`composites.${id}`));
1325
+ const encodedId = encodeURIComponent(id);
1326
+ return safeWithFallback(
1327
+ () => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
1328
+ () => this.client.query(`composites.${id}`)
1329
+ );
1092
1330
  }
1093
1331
  async getCompositeByProductId(productId) {
1094
- return safe(this.client.query(`composites.by_product.${productId}`));
1332
+ const encodedId = encodeURIComponent(productId);
1333
+ return safeWithFallback(
1334
+ () => this.client.get(
1335
+ `/api/v1/catalogue/composites/by-product/${encodedId}`
1336
+ ),
1337
+ () => this.client.query(`composites.by_product.${productId}`)
1338
+ );
1095
1339
  }
1096
1340
  async calculateCompositePrice(compositeId, selections, locationId) {
1097
- return safe(
1098
- this.client.call("composite.calculatePrice", {
1341
+ const encodedId = encodeURIComponent(compositeId);
1342
+ return safeWithFallback(
1343
+ () => this.client.post(
1344
+ `/api/v1/catalogue/composites/${encodedId}/calculate-price`,
1345
+ {
1346
+ selections,
1347
+ location_id: locationId
1348
+ }
1349
+ ),
1350
+ () => this.client.call("composite.calculatePrice", {
1099
1351
  composite_id: compositeId,
1100
1352
  selections,
1101
1353
  location_id: locationId
@@ -1103,35 +1355,41 @@ var CatalogueQueries = class {
1103
1355
  );
1104
1356
  }
1105
1357
  async fetchQuote(input) {
1106
- return safe(this.client.call("catalogue.createQuote", input));
1358
+ return safeWithFallback(
1359
+ () => this.client.post("/api/v1/catalogue/quotes", input),
1360
+ () => this.client.call("catalogue.createQuote", input)
1361
+ );
1107
1362
  }
1108
1363
  async getQuote(quoteId) {
1109
- return safe(
1110
- this.client.call("catalogue.getQuote", {
1364
+ const encodedQuoteId = encodeURIComponent(quoteId);
1365
+ return safeWithFallback(
1366
+ () => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
1367
+ () => this.client.call("catalogue.getQuote", {
1111
1368
  quote_id: quoteId
1112
1369
  })
1113
1370
  );
1114
1371
  }
1115
1372
  async refreshQuote(input) {
1116
- return safe(this.client.call("catalogue.refreshQuote", input));
1373
+ const encodedQuoteId = encodeURIComponent(input.quote_id);
1374
+ return safeWithFallback(
1375
+ () => this.client.post(
1376
+ `/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
1377
+ input
1378
+ ),
1379
+ () => this.client.call("catalogue.refreshQuote", input)
1380
+ );
1117
1381
  }
1118
1382
  async search(query, options) {
1119
- const limit = options?.limit ?? 20;
1120
- let searchQuery = `products[?(@.name contains '${escapeQueryValue(query)}')]`;
1121
- if (options?.category) {
1122
- searchQuery = `products[?(@.name contains '${escapeQueryValue(query)}' && @.category_id=='${escapeQueryValue(options.category)}')]`;
1123
- }
1124
- searchQuery += `#limit(${limit})`;
1125
- return safe(this.client.query(searchQuery));
1383
+ const result = await this.getProducts({
1384
+ search: query,
1385
+ category: options?.category,
1386
+ limit: options?.limit ?? 20
1387
+ });
1388
+ if (!result.ok) return result;
1389
+ return ok(result.value);
1126
1390
  }
1127
1391
  async searchProducts(query, options) {
1128
- return safe(
1129
- this.client.call("catalogue.search", {
1130
- query,
1131
- limit: options?.limit ?? 20,
1132
- category: options?.category
1133
- })
1134
- );
1392
+ return this.search(query, options);
1135
1393
  }
1136
1394
  async getMenu(options) {
1137
1395
  let query = "menu";
@@ -1141,13 +1399,28 @@ var CatalogueQueries = class {
1141
1399
  if (options?.limit) {
1142
1400
  query += `#limit(${options.limit})`;
1143
1401
  }
1144
- return safe(this.client.query(query));
1402
+ const path = withQuery("/api/v1/catalogue/menu", {
1403
+ category_id: options?.category,
1404
+ limit: options?.limit
1405
+ });
1406
+ return safeWithFallback(
1407
+ () => this.client.get(path),
1408
+ () => this.client.query(query)
1409
+ );
1145
1410
  }
1146
1411
  async getMenuCategory(categoryId) {
1147
- return safe(this.client.query(`menu.category.${categoryId}`));
1412
+ const encodedId = encodeURIComponent(categoryId);
1413
+ return safeWithFallback(
1414
+ () => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
1415
+ () => this.client.query(`menu.category.${categoryId}`)
1416
+ );
1148
1417
  }
1149
1418
  async getMenuItem(itemId) {
1150
- return safe(this.client.query(`menu.${itemId}`));
1419
+ const encodedId = encodeURIComponent(itemId);
1420
+ return safeWithFallback(
1421
+ () => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
1422
+ () => this.client.query(`menu.${itemId}`)
1423
+ );
1151
1424
  }
1152
1425
  };
1153
1426
 
@@ -1166,6 +1439,14 @@ async function safe2(promise) {
1166
1439
  return err(toCimplifyError2(error));
1167
1440
  }
1168
1441
  }
1442
+ async function safeWithFallback2(primary, fallback) {
1443
+ const primaryResult = await safe2(primary());
1444
+ if (primaryResult.ok) return primaryResult;
1445
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
1446
+ return primaryResult;
1447
+ }
1448
+ return safe2(fallback());
1449
+ }
1169
1450
  function isUICartResponse(value) {
1170
1451
  return "cart" in value;
1171
1452
  }
@@ -1177,21 +1458,36 @@ var CartOperations = class {
1177
1458
  this.client = client;
1178
1459
  }
1179
1460
  async get() {
1180
- const result = await safe2(this.client.query("cart#enriched"));
1461
+ const result = await safeWithFallback2(
1462
+ () => this.client.get("/api/v1/cart"),
1463
+ () => this.client.query("cart#enriched")
1464
+ );
1181
1465
  if (!result.ok) return result;
1182
1466
  return ok(unwrapEnrichedCart(result.value));
1183
1467
  }
1184
1468
  async getRaw() {
1185
- return safe2(this.client.query("cart"));
1469
+ return safeWithFallback2(
1470
+ () => this.client.get("/api/v1/cart"),
1471
+ () => this.client.query("cart")
1472
+ );
1186
1473
  }
1187
1474
  async getItems() {
1188
- return safe2(this.client.query("cart_items"));
1475
+ return safeWithFallback2(
1476
+ () => this.client.get("/api/v1/cart/items"),
1477
+ () => this.client.query("cart_items")
1478
+ );
1189
1479
  }
1190
1480
  async getCount() {
1191
- return safe2(this.client.query("cart#count"));
1481
+ return safeWithFallback2(
1482
+ () => this.client.get("/api/v1/cart/count"),
1483
+ () => this.client.query("cart#count")
1484
+ );
1192
1485
  }
1193
1486
  async getTotal() {
1194
- return safe2(this.client.query("cart#total"));
1487
+ return safeWithFallback2(
1488
+ () => this.client.get("/api/v1/cart/total"),
1489
+ () => this.client.query("cart#total")
1490
+ );
1195
1491
  }
1196
1492
  async getSummary() {
1197
1493
  const cartResult = await this.get();
@@ -1208,43 +1504,66 @@ var CartOperations = class {
1208
1504
  });
1209
1505
  }
1210
1506
  async addItem(input) {
1211
- return safe2(this.client.call("cart.addItem", input));
1507
+ return safeWithFallback2(
1508
+ () => this.client.post("/api/v1/cart/items", input),
1509
+ () => this.client.call("cart.addItem", input)
1510
+ );
1212
1511
  }
1213
1512
  async updateItem(cartItemId, updates) {
1214
- return safe2(
1215
- this.client.call("cart.updateItem", {
1513
+ if (typeof updates.quantity === "number") {
1514
+ return this.updateQuantity(cartItemId, updates.quantity);
1515
+ }
1516
+ const encodedId = encodeURIComponent(cartItemId);
1517
+ return safeWithFallback2(
1518
+ () => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
1519
+ () => this.client.call("cart.updateItem", {
1216
1520
  cart_item_id: cartItemId,
1217
1521
  ...updates
1218
1522
  })
1219
1523
  );
1220
1524
  }
1221
1525
  async updateQuantity(cartItemId, quantity) {
1222
- return safe2(
1223
- this.client.call("cart.updateItemQuantity", {
1526
+ const encodedId = encodeURIComponent(cartItemId);
1527
+ return safeWithFallback2(
1528
+ () => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
1529
+ quantity
1530
+ }),
1531
+ () => this.client.call("cart.updateItemQuantity", {
1224
1532
  cart_item_id: cartItemId,
1225
1533
  quantity
1226
1534
  })
1227
1535
  );
1228
1536
  }
1229
1537
  async removeItem(cartItemId) {
1230
- return safe2(
1231
- this.client.call("cart.removeItem", {
1538
+ const encodedId = encodeURIComponent(cartItemId);
1539
+ return safeWithFallback2(
1540
+ () => this.client.delete(`/api/v1/cart/items/${encodedId}`),
1541
+ () => this.client.call("cart.removeItem", {
1232
1542
  cart_item_id: cartItemId
1233
1543
  })
1234
1544
  );
1235
1545
  }
1236
1546
  async clear() {
1237
- return safe2(this.client.call("cart.clearCart"));
1547
+ return safeWithFallback2(
1548
+ () => this.client.delete("/api/v1/cart"),
1549
+ () => this.client.call("cart.clearCart")
1550
+ );
1238
1551
  }
1239
1552
  async applyCoupon(code) {
1240
- return safe2(
1241
- this.client.call("cart.applyCoupon", {
1553
+ return safeWithFallback2(
1554
+ () => this.client.post("/api/v1/cart/coupons", {
1555
+ coupon_code: code
1556
+ }),
1557
+ () => this.client.call("cart.applyCoupon", {
1242
1558
  coupon_code: code
1243
1559
  })
1244
1560
  );
1245
1561
  }
1246
1562
  async removeCoupon() {
1247
- return safe2(this.client.call("cart.removeCoupon"));
1563
+ return safeWithFallback2(
1564
+ () => this.client.delete("/api/v1/cart/coupons/current"),
1565
+ () => this.client.call("cart.removeCoupon")
1566
+ );
1248
1567
  }
1249
1568
  async isEmpty() {
1250
1569
  const countResult = await this.getCount();
@@ -2017,6 +2336,14 @@ async function safe3(promise) {
2017
2336
  return err(toCimplifyError3(error));
2018
2337
  }
2019
2338
  }
2339
+ async function safeWithFallback3(primary, fallback) {
2340
+ const primaryResult = await safe3(primary());
2341
+ if (primaryResult.ok) return primaryResult;
2342
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2343
+ return primaryResult;
2344
+ }
2345
+ return safe3(fallback());
2346
+ }
2020
2347
  function toTerminalFailure(code, message, recoverable) {
2021
2348
  return {
2022
2349
  success: false,
@@ -2044,8 +2371,11 @@ var CheckoutService = class {
2044
2371
  ...data,
2045
2372
  idempotency_key: data.idempotency_key || generateIdempotencyKey()
2046
2373
  };
2047
- return safe3(
2048
- this.client.call(CHECKOUT_MUTATION.PROCESS, {
2374
+ return safeWithFallback3(
2375
+ () => this.client.post("/api/v1/checkout", {
2376
+ checkout_data: checkoutData
2377
+ }),
2378
+ () => this.client.call(CHECKOUT_MUTATION.PROCESS, {
2049
2379
  checkout_data: checkoutData
2050
2380
  })
2051
2381
  );
@@ -2059,18 +2389,23 @@ var CheckoutService = class {
2059
2389
  );
2060
2390
  }
2061
2391
  async submitAuthorization(input) {
2062
- return safe3(
2063
- this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
2392
+ return safeWithFallback3(
2393
+ () => this.client.post("/api/v1/payments/authorization", input),
2394
+ () => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
2064
2395
  );
2065
2396
  }
2066
2397
  async pollPaymentStatus(orderId) {
2067
- return safe3(
2068
- this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
2398
+ const encodedId = encodeURIComponent(orderId);
2399
+ return safeWithFallback3(
2400
+ () => this.client.get(`/api/v1/orders/${encodedId}/payment-status`),
2401
+ () => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
2069
2402
  );
2070
2403
  }
2071
2404
  async updateOrderCustomer(orderId, customer) {
2072
- return safe3(
2073
- this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
2405
+ const encodedId = encodeURIComponent(orderId);
2406
+ return safeWithFallback3(
2407
+ () => this.client.post(`/api/v1/orders/${encodedId}/customer`, customer),
2408
+ () => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
2074
2409
  order_id: orderId,
2075
2410
  ...customer
2076
2411
  })
@@ -2200,6 +2535,14 @@ async function safe4(promise) {
2200
2535
  return err(toCimplifyError4(error));
2201
2536
  }
2202
2537
  }
2538
+ async function safeWithFallback4(primary, fallback) {
2539
+ const primaryResult = await safe4(primary());
2540
+ if (primaryResult.ok) return primaryResult;
2541
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2542
+ return primaryResult;
2543
+ }
2544
+ return safe4(fallback());
2545
+ }
2203
2546
  var OrderQueries = class {
2204
2547
  constructor(client) {
2205
2548
  this.client = client;
@@ -2216,20 +2559,36 @@ var OrderQueries = class {
2216
2559
  if (options?.offset) {
2217
2560
  query += `#offset(${options.offset})`;
2218
2561
  }
2219
- return safe4(this.client.query(query));
2562
+ const params = new URLSearchParams();
2563
+ if (options?.status) params.set("status", options.status);
2564
+ if (options?.limit) params.set("limit", String(options.limit));
2565
+ if (options?.offset) params.set("offset", String(options.offset));
2566
+ const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
2567
+ return safeWithFallback4(
2568
+ () => this.client.get(path),
2569
+ () => this.client.query(query)
2570
+ );
2220
2571
  }
2221
2572
  async get(orderId) {
2222
- return safe4(this.client.query(`orders.${orderId}`));
2573
+ const encodedId = encodeURIComponent(orderId);
2574
+ return safeWithFallback4(
2575
+ () => this.client.get(`/api/v1/orders/${encodedId}`),
2576
+ () => this.client.query(`orders.${orderId}`)
2577
+ );
2223
2578
  }
2224
2579
  async getRecent(limit = 5) {
2225
2580
  return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
2226
2581
  }
2227
2582
  async getByStatus(status) {
2228
- return safe4(this.client.query(`orders[?(@.status=='${status}')]`));
2583
+ return this.list({ status });
2229
2584
  }
2230
2585
  async cancel(orderId, reason) {
2231
- return safe4(
2232
- this.client.call("order.cancelOrder", {
2586
+ const encodedId = encodeURIComponent(orderId);
2587
+ return safeWithFallback4(
2588
+ () => this.client.post(`/api/v1/orders/${encodedId}/cancel`, {
2589
+ reason
2590
+ }),
2591
+ () => this.client.call("order.cancelOrder", {
2233
2592
  order_id: orderId,
2234
2593
  reason
2235
2594
  })
@@ -2404,12 +2763,23 @@ async function safe6(promise) {
2404
2763
  return err(toCimplifyError6(error));
2405
2764
  }
2406
2765
  }
2766
+ async function safeWithFallback5(primary, fallback) {
2767
+ const primaryResult = await safe6(primary());
2768
+ if (primaryResult.ok) return primaryResult;
2769
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2770
+ return primaryResult;
2771
+ }
2772
+ return safe6(fallback());
2773
+ }
2407
2774
  var AuthService = class {
2408
2775
  constructor(client) {
2409
2776
  this.client = client;
2410
2777
  }
2411
2778
  async getStatus() {
2412
- return safe6(this.client.query("auth"));
2779
+ return safeWithFallback5(
2780
+ () => this.client.get("/api/v1/auth/status"),
2781
+ () => this.client.query("auth")
2782
+ );
2413
2783
  }
2414
2784
  async getCurrentUser() {
2415
2785
  const result = await this.getStatus();
@@ -2422,23 +2792,34 @@ var AuthService = class {
2422
2792
  return ok(result.value.is_authenticated);
2423
2793
  }
2424
2794
  async requestOtp(contact, contactType) {
2425
- return safe6(
2426
- this.client.call(AUTH_MUTATION.REQUEST_OTP, {
2795
+ return safeWithFallback5(
2796
+ () => this.client.post("/api/v1/auth/request-otp", {
2797
+ contact,
2798
+ contact_type: contactType
2799
+ }),
2800
+ () => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
2427
2801
  contact,
2428
2802
  contact_type: contactType
2429
2803
  })
2430
2804
  );
2431
2805
  }
2432
2806
  async verifyOtp(code, contact) {
2433
- return safe6(
2434
- this.client.call(AUTH_MUTATION.VERIFY_OTP, {
2807
+ return safeWithFallback5(
2808
+ () => this.client.post("/api/v1/auth/verify-otp", {
2809
+ otp_code: code,
2810
+ contact
2811
+ }),
2812
+ () => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
2435
2813
  otp_code: code,
2436
2814
  contact
2437
2815
  })
2438
2816
  );
2439
2817
  }
2440
2818
  async logout() {
2441
- return safe6(this.client.call("auth.logout"));
2819
+ return safeWithFallback5(
2820
+ () => this.client.post("/api/v1/auth/logout"),
2821
+ () => this.client.call("auth.logout")
2822
+ );
2442
2823
  }
2443
2824
  async updateProfile(input) {
2444
2825
  return safe6(this.client.call("auth.update_profile", input));
@@ -2466,12 +2847,23 @@ async function safe7(promise) {
2466
2847
  return err(toCimplifyError7(error));
2467
2848
  }
2468
2849
  }
2850
+ async function safeWithFallback6(primary, fallback) {
2851
+ const primaryResult = await safe7(primary());
2852
+ if (primaryResult.ok) return primaryResult;
2853
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
2854
+ return primaryResult;
2855
+ }
2856
+ return safe7(fallback());
2857
+ }
2469
2858
  var BusinessService = class {
2470
2859
  constructor(client) {
2471
2860
  this.client = client;
2472
2861
  }
2473
2862
  async getInfo() {
2474
- return safe7(this.client.query("business.info"));
2863
+ return safeWithFallback6(
2864
+ () => this.client.get("/api/v1/business"),
2865
+ () => this.client.query("business.info")
2866
+ );
2475
2867
  }
2476
2868
  async getByHandle(handle) {
2477
2869
  return safe7(this.client.query(`business.handle.${handle}`));
@@ -2480,24 +2872,48 @@ var BusinessService = class {
2480
2872
  return safe7(this.client.query("business.domain", { domain }));
2481
2873
  }
2482
2874
  async getSettings() {
2483
- return safe7(this.client.query("business.settings"));
2875
+ return safeWithFallback6(
2876
+ () => this.client.get("/api/v1/business/settings"),
2877
+ () => this.client.query("business.settings")
2878
+ );
2484
2879
  }
2485
2880
  async getTheme() {
2486
- return safe7(this.client.query("business.theme"));
2881
+ return safeWithFallback6(
2882
+ () => this.client.get("/api/v1/business/theme"),
2883
+ () => this.client.query("business.theme")
2884
+ );
2487
2885
  }
2488
2886
  async getLocations() {
2489
- return safe7(this.client.query("business.locations"));
2887
+ return safeWithFallback6(
2888
+ () => this.client.get("/api/v1/business/locations"),
2889
+ () => this.client.query("business.locations")
2890
+ );
2490
2891
  }
2491
2892
  async getLocation(locationId) {
2492
- return safe7(this.client.query(`business.locations.${locationId}`));
2893
+ const result = await this.getLocations();
2894
+ if (!result.ok) return err(result.error);
2895
+ const location = result.value.find((item) => item.id === locationId);
2896
+ if (!location) {
2897
+ return err(new CimplifyError(ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
2898
+ }
2899
+ return ok(location);
2493
2900
  }
2494
2901
  async getHours() {
2495
- return safe7(this.client.query("business.hours"));
2902
+ return safeWithFallback6(
2903
+ () => this.client.get("/api/v1/business/hours"),
2904
+ () => this.client.query("business.hours")
2905
+ );
2496
2906
  }
2497
2907
  async getLocationHours(locationId) {
2498
- return safe7(this.client.query(`business.locations.${locationId}.hours`));
2908
+ const result = await this.getHours();
2909
+ if (!result.ok) return result;
2910
+ return ok(result.value.filter((hour) => hour.location_id === locationId));
2499
2911
  }
2500
2912
  async getBootstrap() {
2913
+ const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
2914
+ if (restBootstrap.ok) {
2915
+ return restBootstrap;
2916
+ }
2501
2917
  const [businessResult, locationsResult, categoriesResult] = await Promise.all([
2502
2918
  this.getInfo(),
2503
2919
  this.getLocations(),
@@ -2790,15 +3206,30 @@ async function safe11(promise) {
2790
3206
  return err(toCimplifyError11(error));
2791
3207
  }
2792
3208
  }
3209
+ async function safeWithFallback7(primary, fallback) {
3210
+ const primaryResult = await safe11(primary());
3211
+ if (primaryResult.ok) return primaryResult;
3212
+ if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
3213
+ return primaryResult;
3214
+ }
3215
+ return safe11(fallback());
3216
+ }
2793
3217
  var FxService = class {
2794
3218
  constructor(client) {
2795
3219
  this.client = client;
2796
3220
  }
2797
3221
  async getRate(from, to) {
2798
- return safe11(this.client.call("fx.getRate", { from, to }));
3222
+ const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
3223
+ return safeWithFallback7(
3224
+ () => this.client.get(path),
3225
+ () => this.client.call("fx.getRate", { from, to })
3226
+ );
2799
3227
  }
2800
3228
  async lockQuote(request) {
2801
- return safe11(this.client.call("fx.lockQuote", request));
3229
+ return safeWithFallback7(
3230
+ () => this.client.post("/api/v1/fx/quotes", request),
3231
+ () => this.client.call("fx.lockQuote", request)
3232
+ );
2802
3233
  }
2803
3234
  };
2804
3235
 
@@ -3767,6 +4198,15 @@ var CimplifyClient = class {
3767
4198
  });
3768
4199
  return this.handleRestResponse(response);
3769
4200
  }
4201
+ async patch(path, body) {
4202
+ const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
4203
+ method: "PATCH",
4204
+ credentials: this.credentials,
4205
+ headers: this.getHeaders(),
4206
+ body: body ? JSON.stringify(body) : void 0
4207
+ });
4208
+ return this.handleRestResponse(response);
4209
+ }
3770
4210
  async delete(path) {
3771
4211
  const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
3772
4212
  method: "DELETE",
@@ -3806,11 +4246,14 @@ var CimplifyClient = class {
3806
4246
  async handleRestResponse(response) {
3807
4247
  const json = await response.json();
3808
4248
  if (!response.ok) {
4249
+ const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || "API_ERROR";
4250
+ const errorMessage = typeof json.error === "object" && json.error?.error_message || typeof json.error === "object" && json.error?.message || typeof json.error === "string" && json.error || typeof json.message === "string" && json.message || "An error occurred";
4251
+ const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
3809
4252
  const error = enrichError(
3810
4253
  new CimplifyError(
3811
- json.error?.error_code || "API_ERROR",
3812
- json.error?.error_message || "An error occurred",
3813
- false
4254
+ errorCode,
4255
+ errorMessage,
4256
+ retryable
3814
4257
  ),
3815
4258
  { isTestMode: this.isTestMode() }
3816
4259
  );
@@ -3821,7 +4264,21 @@ var CimplifyClient = class {
3821
4264
  }
3822
4265
  throw error;
3823
4266
  }
3824
- return json.data;
4267
+ if (json?.success === false || json?.error?.code || json?.error?.message) {
4268
+ const error = enrichError(
4269
+ new CimplifyError(
4270
+ json.error?.code || "API_ERROR",
4271
+ json.error?.message || "An error occurred",
4272
+ json.error?.retryable || false
4273
+ ),
4274
+ { isTestMode: this.isTestMode() }
4275
+ );
4276
+ throw error;
4277
+ }
4278
+ if (json?.data !== void 0) {
4279
+ return json.data;
4280
+ }
4281
+ return json;
3825
4282
  }
3826
4283
  async handleResponse(response) {
3827
4284
  const json = await response.json();