@cimplify/sdk 0.6.11 → 0.7.0
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/README.md +8 -3
- package/dist/advanced.d.mts +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +529 -102
- package/dist/advanced.mjs +529 -102
- package/dist/{client-DM3-ZG29.d.ts → client-CyBNao15.d.ts} +15 -927
- package/dist/{client-BngAGN0v.d.mts → client-hccS_JMl.d.mts} +15 -927
- package/dist/{index-DaKJxoEh.d.mts → index-B_JHO-ER.d.ts} +29 -35
- package/dist/{index-pztT_bcJ.d.ts → index-mrKi_VbR.d.mts} +29 -35
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +585 -105
- package/dist/index.mjs +582 -106
- package/dist/payment-CLIWNMaP.d.mts +1133 -0
- package/dist/payment-CLIWNMaP.d.ts +1133 -0
- package/dist/react.d.mts +5 -2
- package/dist/react.d.ts +5 -2
- package/dist/react.js +582 -108
- package/dist/react.mjs +582 -108
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +27 -0
- package/dist/utils.mjs +24 -1
- package/package.json +1 -1
- package/dist/payment-Cu75tmUc.d.mts +0 -196
- package/dist/payment-Cu75tmUc.d.ts +0 -196
package/dist/react.mjs
CHANGED
|
@@ -750,6 +750,10 @@ var ERROR_SUGGESTIONS = {
|
|
|
750
750
|
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
751
751
|
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
752
752
|
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
753
|
+
QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
|
|
754
|
+
QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
|
|
755
|
+
QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
|
|
756
|
+
QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
|
|
753
757
|
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
754
758
|
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
755
759
|
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
@@ -851,6 +855,23 @@ async function safe(promise) {
|
|
|
851
855
|
return err(toCimplifyError(error));
|
|
852
856
|
}
|
|
853
857
|
}
|
|
858
|
+
async function safeWithFallback(primary, fallback) {
|
|
859
|
+
const primaryResult = await safe(primary());
|
|
860
|
+
if (primaryResult.ok) return primaryResult;
|
|
861
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
862
|
+
return primaryResult;
|
|
863
|
+
}
|
|
864
|
+
return safe(fallback());
|
|
865
|
+
}
|
|
866
|
+
function withQuery(path, params) {
|
|
867
|
+
const query = new URLSearchParams();
|
|
868
|
+
for (const [key, value] of Object.entries(params)) {
|
|
869
|
+
if (value === void 0) continue;
|
|
870
|
+
query.set(key, String(value));
|
|
871
|
+
}
|
|
872
|
+
const queryString = query.toString();
|
|
873
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
874
|
+
}
|
|
854
875
|
function isRecord(value) {
|
|
855
876
|
return typeof value === "object" && value !== null;
|
|
856
877
|
}
|
|
@@ -908,6 +929,69 @@ function findProductBySlug(products, slug) {
|
|
|
908
929
|
return typeof value === "string" && value === slug;
|
|
909
930
|
});
|
|
910
931
|
}
|
|
932
|
+
function findCategoryBySlug(categories, slug) {
|
|
933
|
+
return categories.find((category) => {
|
|
934
|
+
const value = category["slug"];
|
|
935
|
+
return typeof value === "string" && value === slug;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
function hasCategorySlug(category) {
|
|
939
|
+
const value = category["slug"];
|
|
940
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
941
|
+
}
|
|
942
|
+
function toFiniteNumber(value) {
|
|
943
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
944
|
+
return value;
|
|
945
|
+
}
|
|
946
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
947
|
+
const parsed = Number(value);
|
|
948
|
+
if (Number.isFinite(parsed)) {
|
|
949
|
+
return parsed;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return void 0;
|
|
953
|
+
}
|
|
954
|
+
function normalizePagination(value) {
|
|
955
|
+
if (!isRecord(value)) {
|
|
956
|
+
return void 0;
|
|
957
|
+
}
|
|
958
|
+
const totalCount = toFiniteNumber(value.total_count);
|
|
959
|
+
const currentPage = toFiniteNumber(value.current_page);
|
|
960
|
+
const pageSize = toFiniteNumber(value.page_size);
|
|
961
|
+
const totalPages = toFiniteNumber(value.total_pages);
|
|
962
|
+
if (totalCount === void 0 || currentPage === void 0 || pageSize === void 0 || totalPages === void 0) {
|
|
963
|
+
return void 0;
|
|
964
|
+
}
|
|
965
|
+
return {
|
|
966
|
+
total_count: totalCount,
|
|
967
|
+
current_page: currentPage,
|
|
968
|
+
page_size: pageSize,
|
|
969
|
+
total_pages: totalPages,
|
|
970
|
+
has_more: value.has_more === true,
|
|
971
|
+
next_cursor: typeof value.next_cursor === "string" ? value.next_cursor : void 0
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function normalizeCatalogueResult(payload) {
|
|
975
|
+
if (Array.isArray(payload)) {
|
|
976
|
+
return {
|
|
977
|
+
items: payload.map((product) => normalizeCatalogueProductPayload(product)),
|
|
978
|
+
is_complete: true
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
if (!isRecord(payload)) {
|
|
982
|
+
return {
|
|
983
|
+
items: [],
|
|
984
|
+
is_complete: true
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
const rawItems = Array.isArray(payload.products) ? payload.products : Array.isArray(payload.items) ? payload.items : [];
|
|
988
|
+
return {
|
|
989
|
+
items: rawItems.map((product) => normalizeCatalogueProductPayload(product)),
|
|
990
|
+
is_complete: typeof payload.is_complete === "boolean" ? payload.is_complete : true,
|
|
991
|
+
total_available: toFiniteNumber(payload.total_available),
|
|
992
|
+
pagination: normalizePagination(payload.pagination)
|
|
993
|
+
};
|
|
994
|
+
}
|
|
911
995
|
var CatalogueQueries = class {
|
|
912
996
|
constructor(client) {
|
|
913
997
|
this.client = client;
|
|
@@ -927,6 +1011,13 @@ var CatalogueQueries = class {
|
|
|
927
1011
|
if (options?.search) {
|
|
928
1012
|
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
929
1013
|
}
|
|
1014
|
+
if (options?.tags?.length) {
|
|
1015
|
+
for (const tag of options.tags) {
|
|
1016
|
+
if (tag.trim().length > 0) {
|
|
1017
|
+
filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
930
1021
|
if (options?.min_price !== void 0) {
|
|
931
1022
|
filters.push(`@.price>=${options.min_price}`);
|
|
932
1023
|
}
|
|
@@ -939,25 +1030,57 @@ var CatalogueQueries = class {
|
|
|
939
1030
|
if (options?.sort_by) {
|
|
940
1031
|
query += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
|
|
941
1032
|
}
|
|
942
|
-
if (options?.limit) {
|
|
1033
|
+
if (options?.limit !== void 0) {
|
|
943
1034
|
query += `#limit(${options.limit})`;
|
|
944
1035
|
}
|
|
945
|
-
if (options?.offset) {
|
|
1036
|
+
if (options?.offset !== void 0) {
|
|
946
1037
|
query += `#offset(${options.offset})`;
|
|
947
1038
|
}
|
|
948
|
-
const
|
|
1039
|
+
const path = withQuery("/api/v1/catalogue/products", {
|
|
1040
|
+
category_id: options?.category,
|
|
1041
|
+
search: options?.search,
|
|
1042
|
+
page: options?.page,
|
|
1043
|
+
tags: options?.tags?.join(","),
|
|
1044
|
+
featured: options?.featured,
|
|
1045
|
+
in_stock: options?.in_stock,
|
|
1046
|
+
min_price: options?.min_price,
|
|
1047
|
+
max_price: options?.max_price,
|
|
1048
|
+
sort_by: options?.sort_by,
|
|
1049
|
+
sort_order: options?.sort_order,
|
|
1050
|
+
limit: options?.limit,
|
|
1051
|
+
offset: options?.offset,
|
|
1052
|
+
cursor: options?.cursor
|
|
1053
|
+
});
|
|
1054
|
+
const result = await safeWithFallback(
|
|
1055
|
+
() => this.client.get(path),
|
|
1056
|
+
() => this.client.query(query)
|
|
1057
|
+
);
|
|
949
1058
|
if (!result.ok) return result;
|
|
950
|
-
return ok(result.value
|
|
1059
|
+
return ok(normalizeCatalogueResult(result.value));
|
|
951
1060
|
}
|
|
952
1061
|
async getProduct(id) {
|
|
953
|
-
const
|
|
1062
|
+
const encodedId = encodeURIComponent(id);
|
|
1063
|
+
const result = await safeWithFallback(
|
|
1064
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
|
|
1065
|
+
() => this.client.query(`products.${id}`)
|
|
1066
|
+
);
|
|
954
1067
|
if (!result.ok) return result;
|
|
955
1068
|
return ok(normalizeCatalogueProductPayload(result.value));
|
|
956
1069
|
}
|
|
957
1070
|
async getProductBySlug(slug) {
|
|
1071
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
1072
|
+
const restResult = await safe(
|
|
1073
|
+
this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`)
|
|
1074
|
+
);
|
|
1075
|
+
if (restResult.ok) {
|
|
1076
|
+
return ok(normalizeCatalogueProductPayload(restResult.value));
|
|
1077
|
+
}
|
|
1078
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1079
|
+
return restResult;
|
|
1080
|
+
}
|
|
958
1081
|
const filteredResult = await safe(
|
|
959
1082
|
this.client.query(
|
|
960
|
-
`products[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
1083
|
+
`products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
|
|
961
1084
|
)
|
|
962
1085
|
);
|
|
963
1086
|
if (!filteredResult.ok) return filteredResult;
|
|
@@ -968,7 +1091,9 @@ var CatalogueQueries = class {
|
|
|
968
1091
|
if (filteredResult.value.length === 1) {
|
|
969
1092
|
return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
|
|
970
1093
|
}
|
|
971
|
-
const unfilteredResult = await safe(
|
|
1094
|
+
const unfilteredResult = await safe(
|
|
1095
|
+
this.client.query("products#limit(200)")
|
|
1096
|
+
);
|
|
972
1097
|
if (!unfilteredResult.ok) return unfilteredResult;
|
|
973
1098
|
const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
|
|
974
1099
|
if (!fallbackMatch) {
|
|
@@ -977,18 +1102,33 @@ var CatalogueQueries = class {
|
|
|
977
1102
|
return ok(normalizeCatalogueProductPayload(fallbackMatch));
|
|
978
1103
|
}
|
|
979
1104
|
async getVariants(productId) {
|
|
980
|
-
|
|
1105
|
+
const encodedId = encodeURIComponent(productId);
|
|
1106
|
+
return safeWithFallback(
|
|
1107
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
|
|
1108
|
+
() => this.client.query(`products.${productId}.variants`)
|
|
1109
|
+
);
|
|
981
1110
|
}
|
|
982
1111
|
async getVariantAxes(productId) {
|
|
983
|
-
|
|
1112
|
+
const encodedId = encodeURIComponent(productId);
|
|
1113
|
+
return safeWithFallback(
|
|
1114
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
|
|
1115
|
+
() => this.client.query(`products.${productId}.variant_axes`)
|
|
1116
|
+
);
|
|
984
1117
|
}
|
|
985
1118
|
/**
|
|
986
1119
|
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
987
1120
|
* Returns the matching variant or null if no match found.
|
|
988
1121
|
*/
|
|
989
1122
|
async getVariantByAxisSelections(productId, selections) {
|
|
990
|
-
|
|
991
|
-
|
|
1123
|
+
const encodedId = encodeURIComponent(productId);
|
|
1124
|
+
return safeWithFallback(
|
|
1125
|
+
() => this.client.post(
|
|
1126
|
+
`/api/v1/catalogue/products/${encodedId}/variants/find`,
|
|
1127
|
+
{
|
|
1128
|
+
axis_selections: selections
|
|
1129
|
+
}
|
|
1130
|
+
),
|
|
1131
|
+
() => this.client.query(`products.${productId}.variant`, {
|
|
992
1132
|
axis_selections: selections
|
|
993
1133
|
})
|
|
994
1134
|
);
|
|
@@ -997,45 +1137,107 @@ var CatalogueQueries = class {
|
|
|
997
1137
|
* Get a specific variant by its ID
|
|
998
1138
|
*/
|
|
999
1139
|
async getVariantById(productId, variantId) {
|
|
1000
|
-
|
|
1140
|
+
const encodedProductId = encodeURIComponent(productId);
|
|
1141
|
+
const encodedVariantId = encodeURIComponent(variantId);
|
|
1142
|
+
return safeWithFallback(
|
|
1143
|
+
() => this.client.get(
|
|
1144
|
+
`/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
|
|
1145
|
+
),
|
|
1146
|
+
() => this.client.query(`products.${productId}.variant.${variantId}`)
|
|
1147
|
+
);
|
|
1001
1148
|
}
|
|
1002
1149
|
async getAddOns(productId) {
|
|
1003
|
-
|
|
1150
|
+
const encodedId = encodeURIComponent(productId);
|
|
1151
|
+
return safeWithFallback(
|
|
1152
|
+
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
|
|
1153
|
+
() => this.client.query(`products.${productId}.add_ons`)
|
|
1154
|
+
);
|
|
1004
1155
|
}
|
|
1005
1156
|
async getCategories() {
|
|
1006
|
-
|
|
1157
|
+
const result = await safeWithFallback(
|
|
1158
|
+
() => this.client.get("/api/v1/catalogue/categories"),
|
|
1159
|
+
() => this.client.query("categories")
|
|
1160
|
+
);
|
|
1161
|
+
if (!result.ok) return result;
|
|
1162
|
+
if (result.value.some(hasCategorySlug)) {
|
|
1163
|
+
return result;
|
|
1164
|
+
}
|
|
1165
|
+
const catalogueResult = await safe(
|
|
1166
|
+
this.client.query("catalogue#limit(1)")
|
|
1167
|
+
);
|
|
1168
|
+
if (!catalogueResult.ok) {
|
|
1169
|
+
return result;
|
|
1170
|
+
}
|
|
1171
|
+
const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
|
|
1172
|
+
return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
|
|
1007
1173
|
}
|
|
1008
1174
|
async getCategory(id) {
|
|
1009
|
-
|
|
1175
|
+
const encodedId = encodeURIComponent(id);
|
|
1176
|
+
return safeWithFallback(
|
|
1177
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
|
|
1178
|
+
() => this.client.query(`categories.${id}`)
|
|
1179
|
+
);
|
|
1010
1180
|
}
|
|
1011
1181
|
async getCategoryBySlug(slug) {
|
|
1182
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
1183
|
+
const restResult = await safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
|
|
1184
|
+
if (restResult.ok) {
|
|
1185
|
+
return restResult;
|
|
1186
|
+
}
|
|
1187
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1188
|
+
return restResult;
|
|
1189
|
+
}
|
|
1012
1190
|
const result = await safe(
|
|
1013
1191
|
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
1014
1192
|
);
|
|
1015
1193
|
if (!result.ok) return result;
|
|
1016
|
-
|
|
1194
|
+
const exactMatch = findCategoryBySlug(result.value, slug);
|
|
1195
|
+
if (exactMatch) {
|
|
1196
|
+
return ok(exactMatch);
|
|
1197
|
+
}
|
|
1198
|
+
const categoriesResult = await this.getCategories();
|
|
1199
|
+
if (!categoriesResult.ok) {
|
|
1200
|
+
return categoriesResult;
|
|
1201
|
+
}
|
|
1202
|
+
const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
|
|
1203
|
+
if (!fallbackMatch) {
|
|
1017
1204
|
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
1018
1205
|
}
|
|
1019
|
-
return ok(
|
|
1206
|
+
return ok(fallbackMatch);
|
|
1020
1207
|
}
|
|
1021
1208
|
async getCategoryProducts(categoryId) {
|
|
1022
|
-
|
|
1023
|
-
|
|
1209
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
1210
|
+
return safeWithFallback(
|
|
1211
|
+
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
|
|
1212
|
+
() => this.client.query(
|
|
1024
1213
|
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
1025
1214
|
)
|
|
1026
1215
|
);
|
|
1027
1216
|
}
|
|
1028
1217
|
async getCollections() {
|
|
1029
|
-
return
|
|
1218
|
+
return safeWithFallback(
|
|
1219
|
+
() => this.client.get("/api/v1/catalogue/collections"),
|
|
1220
|
+
() => this.client.query("collections")
|
|
1221
|
+
);
|
|
1030
1222
|
}
|
|
1031
1223
|
async getCollection(id) {
|
|
1032
|
-
|
|
1224
|
+
const encodedId = encodeURIComponent(id);
|
|
1225
|
+
return safeWithFallback(
|
|
1226
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
|
|
1227
|
+
() => this.client.query(`collections.${id}`)
|
|
1228
|
+
);
|
|
1033
1229
|
}
|
|
1034
1230
|
async getCollectionBySlug(slug) {
|
|
1231
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
1232
|
+
const restResult = await safe(
|
|
1233
|
+
this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
|
|
1234
|
+
);
|
|
1235
|
+
if (restResult.ok) return restResult;
|
|
1236
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1237
|
+
return restResult;
|
|
1238
|
+
}
|
|
1035
1239
|
const result = await safe(
|
|
1036
|
-
this.client.query(
|
|
1037
|
-
`collections[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
1038
|
-
)
|
|
1240
|
+
this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
1039
1241
|
);
|
|
1040
1242
|
if (!result.ok) return result;
|
|
1041
1243
|
if (!result.value.length) {
|
|
@@ -1044,22 +1246,43 @@ var CatalogueQueries = class {
|
|
|
1044
1246
|
return ok(result.value[0]);
|
|
1045
1247
|
}
|
|
1046
1248
|
async getCollectionProducts(collectionId) {
|
|
1047
|
-
|
|
1249
|
+
const encodedId = encodeURIComponent(collectionId);
|
|
1250
|
+
return safeWithFallback(
|
|
1251
|
+
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
|
|
1252
|
+
() => this.client.query(`collections.${collectionId}.products`)
|
|
1253
|
+
);
|
|
1048
1254
|
}
|
|
1049
1255
|
async searchCollections(query, limit = 20) {
|
|
1050
|
-
|
|
1051
|
-
|
|
1256
|
+
const path = withQuery("/api/v1/catalogue/collections", { search: query, limit });
|
|
1257
|
+
return safeWithFallback(
|
|
1258
|
+
() => this.client.get(path),
|
|
1259
|
+
() => this.client.query(
|
|
1052
1260
|
`collections[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
|
|
1053
1261
|
)
|
|
1054
1262
|
);
|
|
1055
1263
|
}
|
|
1056
1264
|
async getBundles() {
|
|
1057
|
-
return
|
|
1265
|
+
return safeWithFallback(
|
|
1266
|
+
() => this.client.get("/api/v1/catalogue/bundles"),
|
|
1267
|
+
() => this.client.query("bundles")
|
|
1268
|
+
);
|
|
1058
1269
|
}
|
|
1059
1270
|
async getBundle(id) {
|
|
1060
|
-
|
|
1271
|
+
const encodedId = encodeURIComponent(id);
|
|
1272
|
+
return safeWithFallback(
|
|
1273
|
+
() => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
|
|
1274
|
+
() => this.client.query(`bundles.${id}`)
|
|
1275
|
+
);
|
|
1061
1276
|
}
|
|
1062
1277
|
async getBundleBySlug(slug) {
|
|
1278
|
+
const encodedSlug = encodeURIComponent(slug);
|
|
1279
|
+
const restResult = await safe(
|
|
1280
|
+
this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
|
|
1281
|
+
);
|
|
1282
|
+
if (restResult.ok) return restResult;
|
|
1283
|
+
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1284
|
+
return restResult;
|
|
1285
|
+
}
|
|
1063
1286
|
const result = await safe(
|
|
1064
1287
|
this.client.query(
|
|
1065
1288
|
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
@@ -1072,8 +1295,10 @@ var CatalogueQueries = class {
|
|
|
1072
1295
|
return ok(result.value[0]);
|
|
1073
1296
|
}
|
|
1074
1297
|
async searchBundles(query, limit = 20) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1298
|
+
const path = withQuery("/api/v1/catalogue/bundles", { search: query, limit });
|
|
1299
|
+
return safeWithFallback(
|
|
1300
|
+
() => this.client.get(path),
|
|
1301
|
+
() => this.client.query(
|
|
1077
1302
|
`bundles[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
|
|
1078
1303
|
)
|
|
1079
1304
|
);
|
|
@@ -1083,17 +1308,39 @@ var CatalogueQueries = class {
|
|
|
1083
1308
|
if (options?.limit) {
|
|
1084
1309
|
query += `#limit(${options.limit})`;
|
|
1085
1310
|
}
|
|
1086
|
-
|
|
1311
|
+
const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
|
|
1312
|
+
return safeWithFallback(
|
|
1313
|
+
() => this.client.get(path),
|
|
1314
|
+
() => this.client.query(query)
|
|
1315
|
+
);
|
|
1087
1316
|
}
|
|
1088
1317
|
async getComposite(id) {
|
|
1089
|
-
|
|
1318
|
+
const encodedId = encodeURIComponent(id);
|
|
1319
|
+
return safeWithFallback(
|
|
1320
|
+
() => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
|
|
1321
|
+
() => this.client.query(`composites.${id}`)
|
|
1322
|
+
);
|
|
1090
1323
|
}
|
|
1091
1324
|
async getCompositeByProductId(productId) {
|
|
1092
|
-
|
|
1325
|
+
const encodedId = encodeURIComponent(productId);
|
|
1326
|
+
return safeWithFallback(
|
|
1327
|
+
() => this.client.get(
|
|
1328
|
+
`/api/v1/catalogue/composites/by-product/${encodedId}`
|
|
1329
|
+
),
|
|
1330
|
+
() => this.client.query(`composites.by_product.${productId}`)
|
|
1331
|
+
);
|
|
1093
1332
|
}
|
|
1094
1333
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
1095
|
-
|
|
1096
|
-
|
|
1334
|
+
const encodedId = encodeURIComponent(compositeId);
|
|
1335
|
+
return safeWithFallback(
|
|
1336
|
+
() => this.client.post(
|
|
1337
|
+
`/api/v1/catalogue/composites/${encodedId}/calculate-price`,
|
|
1338
|
+
{
|
|
1339
|
+
selections,
|
|
1340
|
+
location_id: locationId
|
|
1341
|
+
}
|
|
1342
|
+
),
|
|
1343
|
+
() => this.client.call("composite.calculatePrice", {
|
|
1097
1344
|
composite_id: compositeId,
|
|
1098
1345
|
selections,
|
|
1099
1346
|
location_id: locationId
|
|
@@ -1101,35 +1348,41 @@ var CatalogueQueries = class {
|
|
|
1101
1348
|
);
|
|
1102
1349
|
}
|
|
1103
1350
|
async fetchQuote(input) {
|
|
1104
|
-
return
|
|
1351
|
+
return safeWithFallback(
|
|
1352
|
+
() => this.client.post("/api/v1/catalogue/quotes", input),
|
|
1353
|
+
() => this.client.call("catalogue.createQuote", input)
|
|
1354
|
+
);
|
|
1105
1355
|
}
|
|
1106
1356
|
async getQuote(quoteId) {
|
|
1107
|
-
|
|
1108
|
-
|
|
1357
|
+
const encodedQuoteId = encodeURIComponent(quoteId);
|
|
1358
|
+
return safeWithFallback(
|
|
1359
|
+
() => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
|
|
1360
|
+
() => this.client.call("catalogue.getQuote", {
|
|
1109
1361
|
quote_id: quoteId
|
|
1110
1362
|
})
|
|
1111
1363
|
);
|
|
1112
1364
|
}
|
|
1113
1365
|
async refreshQuote(input) {
|
|
1114
|
-
|
|
1366
|
+
const encodedQuoteId = encodeURIComponent(input.quote_id);
|
|
1367
|
+
return safeWithFallback(
|
|
1368
|
+
() => this.client.post(
|
|
1369
|
+
`/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
|
|
1370
|
+
input
|
|
1371
|
+
),
|
|
1372
|
+
() => this.client.call("catalogue.refreshQuote", input)
|
|
1373
|
+
);
|
|
1115
1374
|
}
|
|
1116
1375
|
async search(query, options) {
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
return
|
|
1376
|
+
const result = await this.getProducts({
|
|
1377
|
+
search: query,
|
|
1378
|
+
category: options?.category,
|
|
1379
|
+
limit: options?.limit ?? 20
|
|
1380
|
+
});
|
|
1381
|
+
if (!result.ok) return result;
|
|
1382
|
+
return ok(result.value.items);
|
|
1124
1383
|
}
|
|
1125
1384
|
async searchProducts(query, options) {
|
|
1126
|
-
return
|
|
1127
|
-
this.client.call("catalogue.search", {
|
|
1128
|
-
query,
|
|
1129
|
-
limit: options?.limit ?? 20,
|
|
1130
|
-
category: options?.category
|
|
1131
|
-
})
|
|
1132
|
-
);
|
|
1385
|
+
return this.search(query, options);
|
|
1133
1386
|
}
|
|
1134
1387
|
async getMenu(options) {
|
|
1135
1388
|
let query = "menu";
|
|
@@ -1139,13 +1392,28 @@ var CatalogueQueries = class {
|
|
|
1139
1392
|
if (options?.limit) {
|
|
1140
1393
|
query += `#limit(${options.limit})`;
|
|
1141
1394
|
}
|
|
1142
|
-
|
|
1395
|
+
const path = withQuery("/api/v1/catalogue/menu", {
|
|
1396
|
+
category_id: options?.category,
|
|
1397
|
+
limit: options?.limit
|
|
1398
|
+
});
|
|
1399
|
+
return safeWithFallback(
|
|
1400
|
+
() => this.client.get(path),
|
|
1401
|
+
() => this.client.query(query)
|
|
1402
|
+
);
|
|
1143
1403
|
}
|
|
1144
1404
|
async getMenuCategory(categoryId) {
|
|
1145
|
-
|
|
1405
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
1406
|
+
return safeWithFallback(
|
|
1407
|
+
() => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
|
|
1408
|
+
() => this.client.query(`menu.category.${categoryId}`)
|
|
1409
|
+
);
|
|
1146
1410
|
}
|
|
1147
1411
|
async getMenuItem(itemId) {
|
|
1148
|
-
|
|
1412
|
+
const encodedId = encodeURIComponent(itemId);
|
|
1413
|
+
return safeWithFallback(
|
|
1414
|
+
() => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
|
|
1415
|
+
() => this.client.query(`menu.${itemId}`)
|
|
1416
|
+
);
|
|
1149
1417
|
}
|
|
1150
1418
|
};
|
|
1151
1419
|
|
|
@@ -1164,6 +1432,14 @@ async function safe2(promise) {
|
|
|
1164
1432
|
return err(toCimplifyError2(error));
|
|
1165
1433
|
}
|
|
1166
1434
|
}
|
|
1435
|
+
async function safeWithFallback2(primary, fallback) {
|
|
1436
|
+
const primaryResult = await safe2(primary());
|
|
1437
|
+
if (primaryResult.ok) return primaryResult;
|
|
1438
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1439
|
+
return primaryResult;
|
|
1440
|
+
}
|
|
1441
|
+
return safe2(fallback());
|
|
1442
|
+
}
|
|
1167
1443
|
function isUICartResponse(value) {
|
|
1168
1444
|
return "cart" in value;
|
|
1169
1445
|
}
|
|
@@ -1175,21 +1451,36 @@ var CartOperations = class {
|
|
|
1175
1451
|
this.client = client;
|
|
1176
1452
|
}
|
|
1177
1453
|
async get() {
|
|
1178
|
-
const result = await
|
|
1454
|
+
const result = await safeWithFallback2(
|
|
1455
|
+
() => this.client.get("/api/v1/cart"),
|
|
1456
|
+
() => this.client.query("cart#enriched")
|
|
1457
|
+
);
|
|
1179
1458
|
if (!result.ok) return result;
|
|
1180
1459
|
return ok(unwrapEnrichedCart(result.value));
|
|
1181
1460
|
}
|
|
1182
1461
|
async getRaw() {
|
|
1183
|
-
return
|
|
1462
|
+
return safeWithFallback2(
|
|
1463
|
+
() => this.client.get("/api/v1/cart"),
|
|
1464
|
+
() => this.client.query("cart")
|
|
1465
|
+
);
|
|
1184
1466
|
}
|
|
1185
1467
|
async getItems() {
|
|
1186
|
-
return
|
|
1468
|
+
return safeWithFallback2(
|
|
1469
|
+
() => this.client.get("/api/v1/cart/items"),
|
|
1470
|
+
() => this.client.query("cart_items")
|
|
1471
|
+
);
|
|
1187
1472
|
}
|
|
1188
1473
|
async getCount() {
|
|
1189
|
-
return
|
|
1474
|
+
return safeWithFallback2(
|
|
1475
|
+
() => this.client.get("/api/v1/cart/count"),
|
|
1476
|
+
() => this.client.query("cart#count")
|
|
1477
|
+
);
|
|
1190
1478
|
}
|
|
1191
1479
|
async getTotal() {
|
|
1192
|
-
return
|
|
1480
|
+
return safeWithFallback2(
|
|
1481
|
+
() => this.client.get("/api/v1/cart/total"),
|
|
1482
|
+
() => this.client.query("cart#total")
|
|
1483
|
+
);
|
|
1193
1484
|
}
|
|
1194
1485
|
async getSummary() {
|
|
1195
1486
|
const cartResult = await this.get();
|
|
@@ -1206,43 +1497,66 @@ var CartOperations = class {
|
|
|
1206
1497
|
});
|
|
1207
1498
|
}
|
|
1208
1499
|
async addItem(input) {
|
|
1209
|
-
return
|
|
1500
|
+
return safeWithFallback2(
|
|
1501
|
+
() => this.client.post("/api/v1/cart/items", input),
|
|
1502
|
+
() => this.client.call("cart.addItem", input)
|
|
1503
|
+
);
|
|
1210
1504
|
}
|
|
1211
1505
|
async updateItem(cartItemId, updates) {
|
|
1212
|
-
|
|
1213
|
-
this.
|
|
1506
|
+
if (typeof updates.quantity === "number") {
|
|
1507
|
+
return this.updateQuantity(cartItemId, updates.quantity);
|
|
1508
|
+
}
|
|
1509
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
1510
|
+
return safeWithFallback2(
|
|
1511
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
|
|
1512
|
+
() => this.client.call("cart.updateItem", {
|
|
1214
1513
|
cart_item_id: cartItemId,
|
|
1215
1514
|
...updates
|
|
1216
1515
|
})
|
|
1217
1516
|
);
|
|
1218
1517
|
}
|
|
1219
1518
|
async updateQuantity(cartItemId, quantity) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1519
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
1520
|
+
return safeWithFallback2(
|
|
1521
|
+
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, {
|
|
1522
|
+
quantity
|
|
1523
|
+
}),
|
|
1524
|
+
() => this.client.call("cart.updateItemQuantity", {
|
|
1222
1525
|
cart_item_id: cartItemId,
|
|
1223
1526
|
quantity
|
|
1224
1527
|
})
|
|
1225
1528
|
);
|
|
1226
1529
|
}
|
|
1227
1530
|
async removeItem(cartItemId) {
|
|
1228
|
-
|
|
1229
|
-
|
|
1531
|
+
const encodedId = encodeURIComponent(cartItemId);
|
|
1532
|
+
return safeWithFallback2(
|
|
1533
|
+
() => this.client.delete(`/api/v1/cart/items/${encodedId}`),
|
|
1534
|
+
() => this.client.call("cart.removeItem", {
|
|
1230
1535
|
cart_item_id: cartItemId
|
|
1231
1536
|
})
|
|
1232
1537
|
);
|
|
1233
1538
|
}
|
|
1234
1539
|
async clear() {
|
|
1235
|
-
return
|
|
1540
|
+
return safeWithFallback2(
|
|
1541
|
+
() => this.client.delete("/api/v1/cart"),
|
|
1542
|
+
() => this.client.call("cart.clearCart")
|
|
1543
|
+
);
|
|
1236
1544
|
}
|
|
1237
1545
|
async applyCoupon(code) {
|
|
1238
|
-
return
|
|
1239
|
-
this.client.
|
|
1546
|
+
return safeWithFallback2(
|
|
1547
|
+
() => this.client.post("/api/v1/cart/coupons", {
|
|
1548
|
+
coupon_code: code
|
|
1549
|
+
}),
|
|
1550
|
+
() => this.client.call("cart.applyCoupon", {
|
|
1240
1551
|
coupon_code: code
|
|
1241
1552
|
})
|
|
1242
1553
|
);
|
|
1243
1554
|
}
|
|
1244
1555
|
async removeCoupon() {
|
|
1245
|
-
return
|
|
1556
|
+
return safeWithFallback2(
|
|
1557
|
+
() => this.client.delete("/api/v1/cart/coupons/current"),
|
|
1558
|
+
() => this.client.call("cart.removeCoupon")
|
|
1559
|
+
);
|
|
1246
1560
|
}
|
|
1247
1561
|
async isEmpty() {
|
|
1248
1562
|
const countResult = await this.getCount();
|
|
@@ -2015,6 +2329,14 @@ async function safe3(promise) {
|
|
|
2015
2329
|
return err(toCimplifyError3(error));
|
|
2016
2330
|
}
|
|
2017
2331
|
}
|
|
2332
|
+
async function safeWithFallback3(primary, fallback) {
|
|
2333
|
+
const primaryResult = await safe3(primary());
|
|
2334
|
+
if (primaryResult.ok) return primaryResult;
|
|
2335
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2336
|
+
return primaryResult;
|
|
2337
|
+
}
|
|
2338
|
+
return safe3(fallback());
|
|
2339
|
+
}
|
|
2018
2340
|
function toTerminalFailure(code, message, recoverable) {
|
|
2019
2341
|
return {
|
|
2020
2342
|
success: false,
|
|
@@ -2042,8 +2364,11 @@ var CheckoutService = class {
|
|
|
2042
2364
|
...data,
|
|
2043
2365
|
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
2044
2366
|
};
|
|
2045
|
-
return
|
|
2046
|
-
this.client.
|
|
2367
|
+
return safeWithFallback3(
|
|
2368
|
+
() => this.client.post("/api/v1/checkout", {
|
|
2369
|
+
checkout_data: checkoutData
|
|
2370
|
+
}),
|
|
2371
|
+
() => this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
2047
2372
|
checkout_data: checkoutData
|
|
2048
2373
|
})
|
|
2049
2374
|
);
|
|
@@ -2057,18 +2382,23 @@ var CheckoutService = class {
|
|
|
2057
2382
|
);
|
|
2058
2383
|
}
|
|
2059
2384
|
async submitAuthorization(input) {
|
|
2060
|
-
return
|
|
2061
|
-
this.client.
|
|
2385
|
+
return safeWithFallback3(
|
|
2386
|
+
() => this.client.post("/api/v1/payments/authorization", input),
|
|
2387
|
+
() => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
2062
2388
|
);
|
|
2063
2389
|
}
|
|
2064
2390
|
async pollPaymentStatus(orderId) {
|
|
2065
|
-
|
|
2066
|
-
|
|
2391
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2392
|
+
return safeWithFallback3(
|
|
2393
|
+
() => this.client.get(`/api/v1/orders/${encodedId}/payment-status`),
|
|
2394
|
+
() => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
2067
2395
|
);
|
|
2068
2396
|
}
|
|
2069
2397
|
async updateOrderCustomer(orderId, customer) {
|
|
2070
|
-
|
|
2071
|
-
|
|
2398
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2399
|
+
return safeWithFallback3(
|
|
2400
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/customer`, customer),
|
|
2401
|
+
() => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
2072
2402
|
order_id: orderId,
|
|
2073
2403
|
...customer
|
|
2074
2404
|
})
|
|
@@ -2198,6 +2528,14 @@ async function safe4(promise) {
|
|
|
2198
2528
|
return err(toCimplifyError4(error));
|
|
2199
2529
|
}
|
|
2200
2530
|
}
|
|
2531
|
+
async function safeWithFallback4(primary, fallback) {
|
|
2532
|
+
const primaryResult = await safe4(primary());
|
|
2533
|
+
if (primaryResult.ok) return primaryResult;
|
|
2534
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2535
|
+
return primaryResult;
|
|
2536
|
+
}
|
|
2537
|
+
return safe4(fallback());
|
|
2538
|
+
}
|
|
2201
2539
|
var OrderQueries = class {
|
|
2202
2540
|
constructor(client) {
|
|
2203
2541
|
this.client = client;
|
|
@@ -2214,20 +2552,36 @@ var OrderQueries = class {
|
|
|
2214
2552
|
if (options?.offset) {
|
|
2215
2553
|
query += `#offset(${options.offset})`;
|
|
2216
2554
|
}
|
|
2217
|
-
|
|
2555
|
+
const params = new URLSearchParams();
|
|
2556
|
+
if (options?.status) params.set("status", options.status);
|
|
2557
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
2558
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
2559
|
+
const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
|
|
2560
|
+
return safeWithFallback4(
|
|
2561
|
+
() => this.client.get(path),
|
|
2562
|
+
() => this.client.query(query)
|
|
2563
|
+
);
|
|
2218
2564
|
}
|
|
2219
2565
|
async get(orderId) {
|
|
2220
|
-
|
|
2566
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2567
|
+
return safeWithFallback4(
|
|
2568
|
+
() => this.client.get(`/api/v1/orders/${encodedId}`),
|
|
2569
|
+
() => this.client.query(`orders.${orderId}`)
|
|
2570
|
+
);
|
|
2221
2571
|
}
|
|
2222
2572
|
async getRecent(limit = 5) {
|
|
2223
2573
|
return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
|
|
2224
2574
|
}
|
|
2225
2575
|
async getByStatus(status) {
|
|
2226
|
-
return
|
|
2576
|
+
return this.list({ status });
|
|
2227
2577
|
}
|
|
2228
2578
|
async cancel(orderId, reason) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2579
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2580
|
+
return safeWithFallback4(
|
|
2581
|
+
() => this.client.post(`/api/v1/orders/${encodedId}/cancel`, {
|
|
2582
|
+
reason
|
|
2583
|
+
}),
|
|
2584
|
+
() => this.client.call("order.cancelOrder", {
|
|
2231
2585
|
order_id: orderId,
|
|
2232
2586
|
reason
|
|
2233
2587
|
})
|
|
@@ -2402,12 +2756,23 @@ async function safe6(promise) {
|
|
|
2402
2756
|
return err(toCimplifyError6(error));
|
|
2403
2757
|
}
|
|
2404
2758
|
}
|
|
2759
|
+
async function safeWithFallback5(primary, fallback) {
|
|
2760
|
+
const primaryResult = await safe6(primary());
|
|
2761
|
+
if (primaryResult.ok) return primaryResult;
|
|
2762
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2763
|
+
return primaryResult;
|
|
2764
|
+
}
|
|
2765
|
+
return safe6(fallback());
|
|
2766
|
+
}
|
|
2405
2767
|
var AuthService = class {
|
|
2406
2768
|
constructor(client) {
|
|
2407
2769
|
this.client = client;
|
|
2408
2770
|
}
|
|
2409
2771
|
async getStatus() {
|
|
2410
|
-
return
|
|
2772
|
+
return safeWithFallback5(
|
|
2773
|
+
() => this.client.get("/api/v1/auth/status"),
|
|
2774
|
+
() => this.client.query("auth")
|
|
2775
|
+
);
|
|
2411
2776
|
}
|
|
2412
2777
|
async getCurrentUser() {
|
|
2413
2778
|
const result = await this.getStatus();
|
|
@@ -2420,23 +2785,34 @@ var AuthService = class {
|
|
|
2420
2785
|
return ok(result.value.is_authenticated);
|
|
2421
2786
|
}
|
|
2422
2787
|
async requestOtp(contact, contactType) {
|
|
2423
|
-
return
|
|
2424
|
-
this.client.
|
|
2788
|
+
return safeWithFallback5(
|
|
2789
|
+
() => this.client.post("/api/v1/auth/request-otp", {
|
|
2790
|
+
contact,
|
|
2791
|
+
contact_type: contactType
|
|
2792
|
+
}),
|
|
2793
|
+
() => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
2425
2794
|
contact,
|
|
2426
2795
|
contact_type: contactType
|
|
2427
2796
|
})
|
|
2428
2797
|
);
|
|
2429
2798
|
}
|
|
2430
2799
|
async verifyOtp(code, contact) {
|
|
2431
|
-
return
|
|
2432
|
-
this.client.
|
|
2800
|
+
return safeWithFallback5(
|
|
2801
|
+
() => this.client.post("/api/v1/auth/verify-otp", {
|
|
2802
|
+
otp_code: code,
|
|
2803
|
+
contact
|
|
2804
|
+
}),
|
|
2805
|
+
() => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
2433
2806
|
otp_code: code,
|
|
2434
2807
|
contact
|
|
2435
2808
|
})
|
|
2436
2809
|
);
|
|
2437
2810
|
}
|
|
2438
2811
|
async logout() {
|
|
2439
|
-
return
|
|
2812
|
+
return safeWithFallback5(
|
|
2813
|
+
() => this.client.post("/api/v1/auth/logout"),
|
|
2814
|
+
() => this.client.call("auth.logout")
|
|
2815
|
+
);
|
|
2440
2816
|
}
|
|
2441
2817
|
async updateProfile(input) {
|
|
2442
2818
|
return safe6(this.client.call("auth.update_profile", input));
|
|
@@ -2464,12 +2840,23 @@ async function safe7(promise) {
|
|
|
2464
2840
|
return err(toCimplifyError7(error));
|
|
2465
2841
|
}
|
|
2466
2842
|
}
|
|
2843
|
+
async function safeWithFallback6(primary, fallback) {
|
|
2844
|
+
const primaryResult = await safe7(primary());
|
|
2845
|
+
if (primaryResult.ok) return primaryResult;
|
|
2846
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2847
|
+
return primaryResult;
|
|
2848
|
+
}
|
|
2849
|
+
return safe7(fallback());
|
|
2850
|
+
}
|
|
2467
2851
|
var BusinessService = class {
|
|
2468
2852
|
constructor(client) {
|
|
2469
2853
|
this.client = client;
|
|
2470
2854
|
}
|
|
2471
2855
|
async getInfo() {
|
|
2472
|
-
return
|
|
2856
|
+
return safeWithFallback6(
|
|
2857
|
+
() => this.client.get("/api/v1/business"),
|
|
2858
|
+
() => this.client.query("business.info")
|
|
2859
|
+
);
|
|
2473
2860
|
}
|
|
2474
2861
|
async getByHandle(handle) {
|
|
2475
2862
|
return safe7(this.client.query(`business.handle.${handle}`));
|
|
@@ -2478,24 +2865,48 @@ var BusinessService = class {
|
|
|
2478
2865
|
return safe7(this.client.query("business.domain", { domain }));
|
|
2479
2866
|
}
|
|
2480
2867
|
async getSettings() {
|
|
2481
|
-
return
|
|
2868
|
+
return safeWithFallback6(
|
|
2869
|
+
() => this.client.get("/api/v1/business/settings"),
|
|
2870
|
+
() => this.client.query("business.settings")
|
|
2871
|
+
);
|
|
2482
2872
|
}
|
|
2483
2873
|
async getTheme() {
|
|
2484
|
-
return
|
|
2874
|
+
return safeWithFallback6(
|
|
2875
|
+
() => this.client.get("/api/v1/business/theme"),
|
|
2876
|
+
() => this.client.query("business.theme")
|
|
2877
|
+
);
|
|
2485
2878
|
}
|
|
2486
2879
|
async getLocations() {
|
|
2487
|
-
return
|
|
2880
|
+
return safeWithFallback6(
|
|
2881
|
+
() => this.client.get("/api/v1/business/locations"),
|
|
2882
|
+
() => this.client.query("business.locations")
|
|
2883
|
+
);
|
|
2488
2884
|
}
|
|
2489
2885
|
async getLocation(locationId) {
|
|
2490
|
-
|
|
2886
|
+
const result = await this.getLocations();
|
|
2887
|
+
if (!result.ok) return err(result.error);
|
|
2888
|
+
const location = result.value.find((item) => item.id === locationId);
|
|
2889
|
+
if (!location) {
|
|
2890
|
+
return err(new CimplifyError(ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
|
|
2891
|
+
}
|
|
2892
|
+
return ok(location);
|
|
2491
2893
|
}
|
|
2492
2894
|
async getHours() {
|
|
2493
|
-
return
|
|
2895
|
+
return safeWithFallback6(
|
|
2896
|
+
() => this.client.get("/api/v1/business/hours"),
|
|
2897
|
+
() => this.client.query("business.hours")
|
|
2898
|
+
);
|
|
2494
2899
|
}
|
|
2495
2900
|
async getLocationHours(locationId) {
|
|
2496
|
-
|
|
2901
|
+
const result = await this.getHours();
|
|
2902
|
+
if (!result.ok) return result;
|
|
2903
|
+
return ok(result.value.filter((hour) => hour.location_id === locationId));
|
|
2497
2904
|
}
|
|
2498
2905
|
async getBootstrap() {
|
|
2906
|
+
const restBootstrap = await safe7(this.client.get("/api/v1/bootstrap"));
|
|
2907
|
+
if (restBootstrap.ok) {
|
|
2908
|
+
return restBootstrap;
|
|
2909
|
+
}
|
|
2499
2910
|
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
2500
2911
|
this.getInfo(),
|
|
2501
2912
|
this.getLocations(),
|
|
@@ -2788,15 +3199,30 @@ async function safe11(promise) {
|
|
|
2788
3199
|
return err(toCimplifyError11(error));
|
|
2789
3200
|
}
|
|
2790
3201
|
}
|
|
3202
|
+
async function safeWithFallback7(primary, fallback) {
|
|
3203
|
+
const primaryResult = await safe11(primary());
|
|
3204
|
+
if (primaryResult.ok) return primaryResult;
|
|
3205
|
+
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
3206
|
+
return primaryResult;
|
|
3207
|
+
}
|
|
3208
|
+
return safe11(fallback());
|
|
3209
|
+
}
|
|
2791
3210
|
var FxService = class {
|
|
2792
3211
|
constructor(client) {
|
|
2793
3212
|
this.client = client;
|
|
2794
3213
|
}
|
|
2795
3214
|
async getRate(from, to) {
|
|
2796
|
-
|
|
3215
|
+
const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
|
|
3216
|
+
return safeWithFallback7(
|
|
3217
|
+
() => this.client.get(path),
|
|
3218
|
+
() => this.client.call("fx.getRate", { from, to })
|
|
3219
|
+
);
|
|
2797
3220
|
}
|
|
2798
3221
|
async lockQuote(request) {
|
|
2799
|
-
return
|
|
3222
|
+
return safeWithFallback7(
|
|
3223
|
+
() => this.client.post("/api/v1/fx/quotes", request),
|
|
3224
|
+
() => this.client.call("fx.lockQuote", request)
|
|
3225
|
+
);
|
|
2800
3226
|
}
|
|
2801
3227
|
};
|
|
2802
3228
|
|
|
@@ -3765,6 +4191,15 @@ var CimplifyClient = class {
|
|
|
3765
4191
|
});
|
|
3766
4192
|
return this.handleRestResponse(response);
|
|
3767
4193
|
}
|
|
4194
|
+
async patch(path, body) {
|
|
4195
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
4196
|
+
method: "PATCH",
|
|
4197
|
+
credentials: this.credentials,
|
|
4198
|
+
headers: this.getHeaders(),
|
|
4199
|
+
body: body ? JSON.stringify(body) : void 0
|
|
4200
|
+
});
|
|
4201
|
+
return this.handleRestResponse(response);
|
|
4202
|
+
}
|
|
3768
4203
|
async delete(path) {
|
|
3769
4204
|
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
3770
4205
|
method: "DELETE",
|
|
@@ -3804,11 +4239,14 @@ var CimplifyClient = class {
|
|
|
3804
4239
|
async handleRestResponse(response) {
|
|
3805
4240
|
const json = await response.json();
|
|
3806
4241
|
if (!response.ok) {
|
|
4242
|
+
const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || "API_ERROR";
|
|
4243
|
+
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";
|
|
4244
|
+
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
3807
4245
|
const error = enrichError(
|
|
3808
4246
|
new CimplifyError(
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
4247
|
+
errorCode,
|
|
4248
|
+
errorMessage,
|
|
4249
|
+
retryable
|
|
3812
4250
|
),
|
|
3813
4251
|
{ isTestMode: this.isTestMode() }
|
|
3814
4252
|
);
|
|
@@ -3819,7 +4257,21 @@ var CimplifyClient = class {
|
|
|
3819
4257
|
}
|
|
3820
4258
|
throw error;
|
|
3821
4259
|
}
|
|
3822
|
-
|
|
4260
|
+
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
4261
|
+
const error = enrichError(
|
|
4262
|
+
new CimplifyError(
|
|
4263
|
+
json.error?.code || "API_ERROR",
|
|
4264
|
+
json.error?.message || "An error occurred",
|
|
4265
|
+
json.error?.retryable || false
|
|
4266
|
+
),
|
|
4267
|
+
{ isTestMode: this.isTestMode() }
|
|
4268
|
+
);
|
|
4269
|
+
throw error;
|
|
4270
|
+
}
|
|
4271
|
+
if (json?.data !== void 0) {
|
|
4272
|
+
return json.data;
|
|
4273
|
+
}
|
|
4274
|
+
return json;
|
|
3823
4275
|
}
|
|
3824
4276
|
async handleResponse(response) {
|
|
3825
4277
|
const json = await response.json();
|
|
@@ -4123,6 +4575,9 @@ function useProducts(options = {}) {
|
|
|
4123
4575
|
);
|
|
4124
4576
|
const cached = productsCache.get(cacheKey);
|
|
4125
4577
|
const [products, setProducts] = useState(cached?.products ?? []);
|
|
4578
|
+
const [isComplete, setIsComplete] = useState(cached?.is_complete ?? true);
|
|
4579
|
+
const [totalAvailable, setTotalAvailable] = useState(cached?.total_available);
|
|
4580
|
+
const [pagination, setPagination] = useState(cached?.pagination);
|
|
4126
4581
|
const [isLoading, setIsLoading] = useState(enabled && !cached);
|
|
4127
4582
|
const [error, setError] = useState(null);
|
|
4128
4583
|
useEffect(() => {
|
|
@@ -4144,6 +4599,9 @@ function useProducts(options = {}) {
|
|
|
4144
4599
|
const cacheEntry = productsCache.get(cacheKey);
|
|
4145
4600
|
if (cacheEntry) {
|
|
4146
4601
|
setProducts(cacheEntry.products);
|
|
4602
|
+
setIsComplete(cacheEntry.is_complete);
|
|
4603
|
+
setTotalAvailable(cacheEntry.total_available);
|
|
4604
|
+
setPagination(cacheEntry.pagination);
|
|
4147
4605
|
setIsLoading(false);
|
|
4148
4606
|
return;
|
|
4149
4607
|
}
|
|
@@ -4167,9 +4625,17 @@ function useProducts(options = {}) {
|
|
|
4167
4625
|
);
|
|
4168
4626
|
}
|
|
4169
4627
|
const value = await promise;
|
|
4170
|
-
productsCache.set(cacheKey, {
|
|
4628
|
+
productsCache.set(cacheKey, {
|
|
4629
|
+
products: value.items,
|
|
4630
|
+
is_complete: value.is_complete,
|
|
4631
|
+
total_available: value.total_available,
|
|
4632
|
+
pagination: value.pagination
|
|
4633
|
+
});
|
|
4171
4634
|
if (nextRequestId === requestIdRef.current) {
|
|
4172
|
-
setProducts(value);
|
|
4635
|
+
setProducts(value.items);
|
|
4636
|
+
setIsComplete(value.is_complete);
|
|
4637
|
+
setTotalAvailable(value.total_available);
|
|
4638
|
+
setPagination(value.pagination);
|
|
4173
4639
|
setError(null);
|
|
4174
4640
|
}
|
|
4175
4641
|
} catch (loadError) {
|
|
@@ -4191,7 +4657,15 @@ function useProducts(options = {}) {
|
|
|
4191
4657
|
productsCache.delete(cacheKey);
|
|
4192
4658
|
await load(true);
|
|
4193
4659
|
}, [cacheKey, load]);
|
|
4194
|
-
return {
|
|
4660
|
+
return {
|
|
4661
|
+
products,
|
|
4662
|
+
is_complete: isComplete,
|
|
4663
|
+
total_available: totalAvailable,
|
|
4664
|
+
pagination,
|
|
4665
|
+
isLoading,
|
|
4666
|
+
error,
|
|
4667
|
+
refetch
|
|
4668
|
+
};
|
|
4195
4669
|
}
|
|
4196
4670
|
var productCache = /* @__PURE__ */ new Map();
|
|
4197
4671
|
var productInflight = /* @__PURE__ */ new Map();
|