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