@cimplify/sdk 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +383 -784
- package/dist/advanced.mjs +383 -784
- package/dist/{client-CSH0xyto.d.mts → client-B0f__K5x.d.mts} +144 -269
- package/dist/{client-C082Zp8J.d.ts → client-C9aOFBo_.d.ts} +144 -269
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +506 -910
- package/dist/index.mjs +506 -910
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +339 -777
- package/dist/react.mjs +339 -777
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -835,11 +835,6 @@ function err(error) {
|
|
|
835
835
|
return { ok: false, error };
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
-
// src/query/builder.ts
|
|
839
|
-
function escapeQueryValue(value) {
|
|
840
|
-
return value.replace(/'/g, "\\'");
|
|
841
|
-
}
|
|
842
|
-
|
|
843
838
|
// src/catalogue.ts
|
|
844
839
|
function toCimplifyError(error) {
|
|
845
840
|
if (error instanceof CimplifyError) return enrichError(error);
|
|
@@ -855,14 +850,6 @@ async function safe(promise) {
|
|
|
855
850
|
return err(toCimplifyError(error));
|
|
856
851
|
}
|
|
857
852
|
}
|
|
858
|
-
async function safeWithFallback(primary, fallback) {
|
|
859
|
-
const primaryResult = await safe(primary());
|
|
860
|
-
if (primaryResult.ok) return primaryResult;
|
|
861
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
862
|
-
return primaryResult;
|
|
863
|
-
}
|
|
864
|
-
return safe(fallback());
|
|
865
|
-
}
|
|
866
853
|
function withQuery(path, params) {
|
|
867
854
|
const query = new URLSearchParams();
|
|
868
855
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -924,22 +911,6 @@ function normalizeCatalogueProductPayload(product) {
|
|
|
924
911
|
}
|
|
925
912
|
return normalized;
|
|
926
913
|
}
|
|
927
|
-
function findProductBySlug(products, slug) {
|
|
928
|
-
return products.find((product) => {
|
|
929
|
-
const value = product["slug"];
|
|
930
|
-
return typeof value === "string" && value === slug;
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
function findCategoryBySlug(categories, slug) {
|
|
934
|
-
return categories.find((category) => {
|
|
935
|
-
const value = category["slug"];
|
|
936
|
-
return typeof value === "string" && value === slug;
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
function hasCategorySlug(category) {
|
|
940
|
-
const value = category["slug"];
|
|
941
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
942
|
-
}
|
|
943
914
|
function toFiniteNumber(value) {
|
|
944
915
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
945
916
|
return value;
|
|
@@ -1027,53 +998,11 @@ var CatalogueQueries = class {
|
|
|
1027
998
|
this.client = client;
|
|
1028
999
|
}
|
|
1029
1000
|
async getCatalogue() {
|
|
1030
|
-
const result = await
|
|
1031
|
-
() => this.client.get("/api/v1/catalogue"),
|
|
1032
|
-
() => this.client.query("catalogue")
|
|
1033
|
-
);
|
|
1001
|
+
const result = await safe(this.client.get("/api/v1/catalogue"));
|
|
1034
1002
|
if (!result.ok) return result;
|
|
1035
1003
|
return ok(normalizeCatalogueSnapshot(result.value));
|
|
1036
1004
|
}
|
|
1037
1005
|
async getProducts(options) {
|
|
1038
|
-
let query = "products";
|
|
1039
|
-
const filters = [];
|
|
1040
|
-
if (options?.category) {
|
|
1041
|
-
filters.push(`@.category_id=='${escapeQueryValue(options.category)}'`);
|
|
1042
|
-
}
|
|
1043
|
-
if (options?.featured !== void 0) {
|
|
1044
|
-
filters.push(`@.featured==${options.featured}`);
|
|
1045
|
-
}
|
|
1046
|
-
if (options?.in_stock !== void 0) {
|
|
1047
|
-
filters.push(`@.in_stock==${options.in_stock}`);
|
|
1048
|
-
}
|
|
1049
|
-
if (options?.search) {
|
|
1050
|
-
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
1051
|
-
}
|
|
1052
|
-
if (options?.tags?.length) {
|
|
1053
|
-
for (const tag of options.tags) {
|
|
1054
|
-
if (tag.trim().length > 0) {
|
|
1055
|
-
filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
if (options?.min_price !== void 0) {
|
|
1060
|
-
filters.push(`@.price>=${options.min_price}`);
|
|
1061
|
-
}
|
|
1062
|
-
if (options?.max_price !== void 0) {
|
|
1063
|
-
filters.push(`@.price<=${options.max_price}`);
|
|
1064
|
-
}
|
|
1065
|
-
if (filters.length > 0) {
|
|
1066
|
-
query += `[?(${filters.join(" && ")})]`;
|
|
1067
|
-
}
|
|
1068
|
-
if (options?.sort_by) {
|
|
1069
|
-
query += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
|
|
1070
|
-
}
|
|
1071
|
-
if (options?.limit !== void 0) {
|
|
1072
|
-
query += `#limit(${options.limit})`;
|
|
1073
|
-
}
|
|
1074
|
-
if (options?.offset !== void 0) {
|
|
1075
|
-
query += `#offset(${options.offset})`;
|
|
1076
|
-
}
|
|
1077
1006
|
const path = withQuery("/api/v1/catalogue/products", {
|
|
1078
1007
|
category_id: options?.category,
|
|
1079
1008
|
search: options?.search,
|
|
@@ -1089,325 +1018,145 @@ var CatalogueQueries = class {
|
|
|
1089
1018
|
offset: options?.offset,
|
|
1090
1019
|
cursor: options?.cursor
|
|
1091
1020
|
});
|
|
1092
|
-
const result = await
|
|
1093
|
-
() => this.client.get(path),
|
|
1094
|
-
() => this.client.query(query)
|
|
1095
|
-
);
|
|
1021
|
+
const result = await safe(this.client.get(path));
|
|
1096
1022
|
if (!result.ok) return result;
|
|
1097
1023
|
return ok(normalizeCatalogueResult(result.value));
|
|
1098
1024
|
}
|
|
1099
1025
|
async getProduct(id) {
|
|
1100
1026
|
const encodedId = encodeURIComponent(id);
|
|
1101
|
-
const result = await
|
|
1102
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
|
|
1103
|
-
() => this.client.query(`products.${id}`)
|
|
1104
|
-
);
|
|
1027
|
+
const result = await safe(this.client.get(`/api/v1/catalogue/products/${encodedId}`));
|
|
1105
1028
|
if (!result.ok) return result;
|
|
1106
1029
|
return ok(normalizeCatalogueProductPayload(result.value));
|
|
1107
1030
|
}
|
|
1108
1031
|
async getProductBySlug(slug) {
|
|
1109
1032
|
const encodedSlug = encodeURIComponent(slug);
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1112
|
-
);
|
|
1113
|
-
if (restResult.ok) {
|
|
1114
|
-
return ok(normalizeCatalogueProductPayload(restResult.value));
|
|
1115
|
-
}
|
|
1116
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1117
|
-
return restResult;
|
|
1118
|
-
}
|
|
1119
|
-
const filteredResult = await safe(
|
|
1120
|
-
this.client.query(
|
|
1121
|
-
`products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
|
|
1122
|
-
)
|
|
1123
|
-
);
|
|
1124
|
-
if (!filteredResult.ok) return filteredResult;
|
|
1125
|
-
const exactMatch = findProductBySlug(filteredResult.value, slug);
|
|
1126
|
-
if (exactMatch) {
|
|
1127
|
-
return ok(normalizeCatalogueProductPayload(exactMatch));
|
|
1128
|
-
}
|
|
1129
|
-
if (filteredResult.value.length === 1) {
|
|
1130
|
-
return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
|
|
1131
|
-
}
|
|
1132
|
-
const unfilteredResult = await safe(
|
|
1133
|
-
this.client.query("products#limit(200)")
|
|
1134
|
-
);
|
|
1135
|
-
if (!unfilteredResult.ok) return unfilteredResult;
|
|
1136
|
-
const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
|
|
1137
|
-
if (!fallbackMatch) {
|
|
1138
|
-
return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
|
|
1139
|
-
}
|
|
1140
|
-
return ok(normalizeCatalogueProductPayload(fallbackMatch));
|
|
1033
|
+
const result = await safe(this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`));
|
|
1034
|
+
if (!result.ok) return result;
|
|
1035
|
+
return ok(normalizeCatalogueProductPayload(result.value));
|
|
1141
1036
|
}
|
|
1142
1037
|
async getVariants(productId) {
|
|
1143
1038
|
const encodedId = encodeURIComponent(productId);
|
|
1144
|
-
return
|
|
1145
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
|
|
1146
|
-
() => this.client.query(`products.${productId}.variants`)
|
|
1147
|
-
);
|
|
1039
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`));
|
|
1148
1040
|
}
|
|
1149
1041
|
async getVariantAxes(productId) {
|
|
1150
1042
|
const encodedId = encodeURIComponent(productId);
|
|
1151
|
-
return
|
|
1152
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
|
|
1153
|
-
() => this.client.query(`products.${productId}.variant_axes`)
|
|
1154
|
-
);
|
|
1043
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`));
|
|
1155
1044
|
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
1158
|
-
* Returns the matching variant or null if no match found.
|
|
1159
|
-
*/
|
|
1160
1045
|
async getVariantByAxisSelections(productId, selections) {
|
|
1161
1046
|
const encodedId = encodeURIComponent(productId);
|
|
1162
|
-
return
|
|
1163
|
-
|
|
1047
|
+
return safe(
|
|
1048
|
+
this.client.post(
|
|
1164
1049
|
`/api/v1/catalogue/products/${encodedId}/variants/find`,
|
|
1165
1050
|
{
|
|
1166
1051
|
axis_selections: selections
|
|
1167
1052
|
}
|
|
1168
|
-
)
|
|
1169
|
-
() => this.client.query(`products.${productId}.variant`, {
|
|
1170
|
-
axis_selections: selections
|
|
1171
|
-
})
|
|
1053
|
+
)
|
|
1172
1054
|
);
|
|
1173
1055
|
}
|
|
1174
|
-
/**
|
|
1175
|
-
* Get a specific variant by its ID
|
|
1176
|
-
*/
|
|
1177
1056
|
async getVariantById(productId, variantId) {
|
|
1178
1057
|
const encodedProductId = encodeURIComponent(productId);
|
|
1179
1058
|
const encodedVariantId = encodeURIComponent(variantId);
|
|
1180
|
-
return
|
|
1181
|
-
|
|
1059
|
+
return safe(
|
|
1060
|
+
this.client.get(
|
|
1182
1061
|
`/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
|
|
1183
|
-
)
|
|
1184
|
-
() => this.client.query(`products.${productId}.variant.${variantId}`)
|
|
1062
|
+
)
|
|
1185
1063
|
);
|
|
1186
1064
|
}
|
|
1187
1065
|
async getAddOns(productId) {
|
|
1188
1066
|
const encodedId = encodeURIComponent(productId);
|
|
1189
|
-
return
|
|
1190
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
|
|
1191
|
-
() => this.client.query(`products.${productId}.add_ons`)
|
|
1192
|
-
);
|
|
1067
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`));
|
|
1193
1068
|
}
|
|
1194
1069
|
async getCategories() {
|
|
1195
|
-
|
|
1196
|
-
() => this.client.get("/api/v1/catalogue/categories"),
|
|
1197
|
-
() => this.client.query("categories")
|
|
1198
|
-
);
|
|
1199
|
-
if (!result.ok) return result;
|
|
1200
|
-
if (result.value.some(hasCategorySlug)) {
|
|
1201
|
-
return result;
|
|
1202
|
-
}
|
|
1203
|
-
const catalogueResult = await safe(
|
|
1204
|
-
this.client.query("catalogue#limit(1)")
|
|
1205
|
-
);
|
|
1206
|
-
if (!catalogueResult.ok) {
|
|
1207
|
-
return result;
|
|
1208
|
-
}
|
|
1209
|
-
const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
|
|
1210
|
-
return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
|
|
1070
|
+
return safe(this.client.get("/api/v1/catalogue/categories"));
|
|
1211
1071
|
}
|
|
1212
1072
|
async getCategory(id) {
|
|
1213
1073
|
const encodedId = encodeURIComponent(id);
|
|
1214
|
-
return
|
|
1215
|
-
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
|
|
1216
|
-
() => this.client.query(`categories.${id}`)
|
|
1217
|
-
);
|
|
1074
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}`));
|
|
1218
1075
|
}
|
|
1219
1076
|
async getCategoryBySlug(slug) {
|
|
1220
1077
|
const encodedSlug = encodeURIComponent(slug);
|
|
1221
|
-
|
|
1222
|
-
if (restResult.ok) {
|
|
1223
|
-
return restResult;
|
|
1224
|
-
}
|
|
1225
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1226
|
-
return restResult;
|
|
1227
|
-
}
|
|
1228
|
-
const result = await safe(
|
|
1229
|
-
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
1230
|
-
);
|
|
1231
|
-
if (!result.ok) return result;
|
|
1232
|
-
const exactMatch = findCategoryBySlug(result.value, slug);
|
|
1233
|
-
if (exactMatch) {
|
|
1234
|
-
return ok(exactMatch);
|
|
1235
|
-
}
|
|
1236
|
-
const categoriesResult = await this.getCategories();
|
|
1237
|
-
if (!categoriesResult.ok) {
|
|
1238
|
-
return categoriesResult;
|
|
1239
|
-
}
|
|
1240
|
-
const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
|
|
1241
|
-
if (!fallbackMatch) {
|
|
1242
|
-
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
1243
|
-
}
|
|
1244
|
-
return ok(fallbackMatch);
|
|
1078
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
|
|
1245
1079
|
}
|
|
1246
1080
|
async getCategoryProducts(categoryId) {
|
|
1247
1081
|
const encodedId = encodeURIComponent(categoryId);
|
|
1248
|
-
return
|
|
1249
|
-
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
|
|
1250
|
-
() => this.client.query(
|
|
1251
|
-
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
1252
|
-
)
|
|
1253
|
-
);
|
|
1082
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`));
|
|
1254
1083
|
}
|
|
1255
1084
|
async getCollections() {
|
|
1256
|
-
return
|
|
1257
|
-
() => this.client.get("/api/v1/catalogue/collections"),
|
|
1258
|
-
() => this.client.query("collections")
|
|
1259
|
-
);
|
|
1085
|
+
return safe(this.client.get("/api/v1/catalogue/collections"));
|
|
1260
1086
|
}
|
|
1261
1087
|
async getCollection(id) {
|
|
1262
1088
|
const encodedId = encodeURIComponent(id);
|
|
1263
|
-
return
|
|
1264
|
-
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
|
|
1265
|
-
() => this.client.query(`collections.${id}`)
|
|
1266
|
-
);
|
|
1089
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}`));
|
|
1267
1090
|
}
|
|
1268
1091
|
async getCollectionBySlug(slug) {
|
|
1269
1092
|
const encodedSlug = encodeURIComponent(slug);
|
|
1270
|
-
|
|
1271
|
-
this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
|
|
1272
|
-
);
|
|
1273
|
-
if (restResult.ok) return restResult;
|
|
1274
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1275
|
-
return restResult;
|
|
1276
|
-
}
|
|
1277
|
-
const result = await safe(
|
|
1278
|
-
this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
1279
|
-
);
|
|
1280
|
-
if (!result.ok) return result;
|
|
1281
|
-
if (!result.value.length) {
|
|
1282
|
-
return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
|
|
1283
|
-
}
|
|
1284
|
-
return ok(result.value[0]);
|
|
1093
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`));
|
|
1285
1094
|
}
|
|
1286
1095
|
async getCollectionProducts(collectionId) {
|
|
1287
1096
|
const encodedId = encodeURIComponent(collectionId);
|
|
1288
|
-
return
|
|
1289
|
-
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
|
|
1290
|
-
() => this.client.query(`collections.${collectionId}.products`)
|
|
1291
|
-
);
|
|
1097
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`));
|
|
1292
1098
|
}
|
|
1293
1099
|
async searchCollections(query, limit = 20) {
|
|
1294
1100
|
const path = withQuery("/api/v1/catalogue/collections", { search: query, limit });
|
|
1295
|
-
return
|
|
1296
|
-
() => this.client.get(path),
|
|
1297
|
-
() => this.client.query(
|
|
1298
|
-
`collections[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
|
|
1299
|
-
)
|
|
1300
|
-
);
|
|
1101
|
+
return safe(this.client.get(path));
|
|
1301
1102
|
}
|
|
1302
1103
|
async getBundles() {
|
|
1303
|
-
return
|
|
1304
|
-
() => this.client.get("/api/v1/catalogue/bundles"),
|
|
1305
|
-
() => this.client.query("bundles")
|
|
1306
|
-
);
|
|
1104
|
+
return safe(this.client.get("/api/v1/catalogue/bundles"));
|
|
1307
1105
|
}
|
|
1308
1106
|
async getBundle(id) {
|
|
1309
1107
|
const encodedId = encodeURIComponent(id);
|
|
1310
|
-
return
|
|
1311
|
-
() => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
|
|
1312
|
-
() => this.client.query(`bundles.${id}`)
|
|
1313
|
-
);
|
|
1108
|
+
return safe(this.client.get(`/api/v1/catalogue/bundles/${encodedId}`));
|
|
1314
1109
|
}
|
|
1315
1110
|
async getBundleBySlug(slug) {
|
|
1316
1111
|
const encodedSlug = encodeURIComponent(slug);
|
|
1317
|
-
|
|
1318
|
-
this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
|
|
1319
|
-
);
|
|
1320
|
-
if (restResult.ok) return restResult;
|
|
1321
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
1322
|
-
return restResult;
|
|
1323
|
-
}
|
|
1324
|
-
const result = await safe(
|
|
1325
|
-
this.client.query(
|
|
1326
|
-
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
1327
|
-
)
|
|
1328
|
-
);
|
|
1329
|
-
if (!result.ok) return result;
|
|
1330
|
-
if (!result.value.length) {
|
|
1331
|
-
return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
|
|
1332
|
-
}
|
|
1333
|
-
return ok(result.value[0]);
|
|
1112
|
+
return safe(this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`));
|
|
1334
1113
|
}
|
|
1335
1114
|
async searchBundles(query, limit = 20) {
|
|
1336
1115
|
const path = withQuery("/api/v1/catalogue/bundles", { search: query, limit });
|
|
1337
|
-
return
|
|
1338
|
-
() => this.client.get(path),
|
|
1339
|
-
() => this.client.query(
|
|
1340
|
-
`bundles[?(@.name contains '${escapeQueryValue(query)}')]#limit(${limit})`
|
|
1341
|
-
)
|
|
1342
|
-
);
|
|
1116
|
+
return safe(this.client.get(path));
|
|
1343
1117
|
}
|
|
1344
1118
|
async getComposites(options) {
|
|
1345
|
-
let query = "composites";
|
|
1346
|
-
if (options?.limit) {
|
|
1347
|
-
query += `#limit(${options.limit})`;
|
|
1348
|
-
}
|
|
1349
1119
|
const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
|
|
1350
|
-
return
|
|
1351
|
-
() => this.client.get(path),
|
|
1352
|
-
() => this.client.query(query)
|
|
1353
|
-
);
|
|
1120
|
+
return safe(this.client.get(path));
|
|
1354
1121
|
}
|
|
1355
1122
|
async getComposite(id) {
|
|
1356
1123
|
const encodedId = encodeURIComponent(id);
|
|
1357
|
-
return
|
|
1358
|
-
() => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
|
|
1359
|
-
() => this.client.query(`composites.${id}`)
|
|
1360
|
-
);
|
|
1124
|
+
return safe(this.client.get(`/api/v1/catalogue/composites/${encodedId}`));
|
|
1361
1125
|
}
|
|
1362
1126
|
async getCompositeByProductId(productId) {
|
|
1363
1127
|
const encodedId = encodeURIComponent(productId);
|
|
1364
|
-
return
|
|
1365
|
-
|
|
1128
|
+
return safe(
|
|
1129
|
+
this.client.get(
|
|
1366
1130
|
`/api/v1/catalogue/composites/by-product/${encodedId}`
|
|
1367
|
-
)
|
|
1368
|
-
() => this.client.query(`composites.by_product.${productId}`)
|
|
1131
|
+
)
|
|
1369
1132
|
);
|
|
1370
1133
|
}
|
|
1371
1134
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
1372
1135
|
const encodedId = encodeURIComponent(compositeId);
|
|
1373
|
-
return
|
|
1374
|
-
|
|
1136
|
+
return safe(
|
|
1137
|
+
this.client.post(
|
|
1375
1138
|
`/api/v1/catalogue/composites/${encodedId}/calculate-price`,
|
|
1376
1139
|
{
|
|
1377
1140
|
selections,
|
|
1378
1141
|
location_id: locationId
|
|
1379
1142
|
}
|
|
1380
|
-
)
|
|
1381
|
-
() => this.client.call("composite.calculatePrice", {
|
|
1382
|
-
composite_id: compositeId,
|
|
1383
|
-
selections,
|
|
1384
|
-
location_id: locationId
|
|
1385
|
-
})
|
|
1143
|
+
)
|
|
1386
1144
|
);
|
|
1387
1145
|
}
|
|
1388
1146
|
async fetchQuote(input) {
|
|
1389
|
-
return
|
|
1390
|
-
() => this.client.post("/api/v1/catalogue/quotes", input),
|
|
1391
|
-
() => this.client.call("catalogue.createQuote", input)
|
|
1392
|
-
);
|
|
1147
|
+
return safe(this.client.post("/api/v1/catalogue/quotes", input));
|
|
1393
1148
|
}
|
|
1394
1149
|
async getQuote(quoteId) {
|
|
1395
1150
|
const encodedQuoteId = encodeURIComponent(quoteId);
|
|
1396
|
-
return
|
|
1397
|
-
() => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
|
|
1398
|
-
() => this.client.call("catalogue.getQuote", {
|
|
1399
|
-
quote_id: quoteId
|
|
1400
|
-
})
|
|
1401
|
-
);
|
|
1151
|
+
return safe(this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`));
|
|
1402
1152
|
}
|
|
1403
1153
|
async refreshQuote(input) {
|
|
1404
1154
|
const encodedQuoteId = encodeURIComponent(input.quote_id);
|
|
1405
|
-
return
|
|
1406
|
-
|
|
1155
|
+
return safe(
|
|
1156
|
+
this.client.post(
|
|
1407
1157
|
`/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
|
|
1408
1158
|
input
|
|
1409
|
-
)
|
|
1410
|
-
() => this.client.call("catalogue.refreshQuote", input)
|
|
1159
|
+
)
|
|
1411
1160
|
);
|
|
1412
1161
|
}
|
|
1413
1162
|
async search(query, options) {
|
|
@@ -1423,35 +1172,19 @@ var CatalogueQueries = class {
|
|
|
1423
1172
|
return this.search(query, options);
|
|
1424
1173
|
}
|
|
1425
1174
|
async getMenu(options) {
|
|
1426
|
-
let query = "menu";
|
|
1427
|
-
if (options?.category) {
|
|
1428
|
-
query = `menu[?(@.category=='${escapeQueryValue(options.category)}')]`;
|
|
1429
|
-
}
|
|
1430
|
-
if (options?.limit) {
|
|
1431
|
-
query += `#limit(${options.limit})`;
|
|
1432
|
-
}
|
|
1433
1175
|
const path = withQuery("/api/v1/catalogue/menu", {
|
|
1434
1176
|
category_id: options?.category,
|
|
1435
1177
|
limit: options?.limit
|
|
1436
1178
|
});
|
|
1437
|
-
return
|
|
1438
|
-
() => this.client.get(path),
|
|
1439
|
-
() => this.client.query(query)
|
|
1440
|
-
);
|
|
1179
|
+
return safe(this.client.get(path));
|
|
1441
1180
|
}
|
|
1442
1181
|
async getMenuCategory(categoryId) {
|
|
1443
1182
|
const encodedId = encodeURIComponent(categoryId);
|
|
1444
|
-
return
|
|
1445
|
-
() => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
|
|
1446
|
-
() => this.client.query(`menu.category.${categoryId}`)
|
|
1447
|
-
);
|
|
1183
|
+
return safe(this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`));
|
|
1448
1184
|
}
|
|
1449
1185
|
async getMenuItem(itemId) {
|
|
1450
1186
|
const encodedId = encodeURIComponent(itemId);
|
|
1451
|
-
return
|
|
1452
|
-
() => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
|
|
1453
|
-
() => this.client.query(`menu.${itemId}`)
|
|
1454
|
-
);
|
|
1187
|
+
return safe(this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`));
|
|
1455
1188
|
}
|
|
1456
1189
|
};
|
|
1457
1190
|
|
|
@@ -1470,14 +1203,6 @@ async function safe2(promise) {
|
|
|
1470
1203
|
return err(toCimplifyError2(error));
|
|
1471
1204
|
}
|
|
1472
1205
|
}
|
|
1473
|
-
async function safeWithFallback2(primary, fallback) {
|
|
1474
|
-
const primaryResult = await safe2(primary());
|
|
1475
|
-
if (primaryResult.ok) return primaryResult;
|
|
1476
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1477
|
-
return primaryResult;
|
|
1478
|
-
}
|
|
1479
|
-
return safe2(fallback());
|
|
1480
|
-
}
|
|
1481
1206
|
function isUICartResponse(value) {
|
|
1482
1207
|
return "cart" in value;
|
|
1483
1208
|
}
|
|
@@ -1489,36 +1214,21 @@ var CartOperations = class {
|
|
|
1489
1214
|
this.client = client;
|
|
1490
1215
|
}
|
|
1491
1216
|
async get() {
|
|
1492
|
-
const result = await
|
|
1493
|
-
() => this.client.get("/api/v1/cart"),
|
|
1494
|
-
() => this.client.query("cart#enriched")
|
|
1495
|
-
);
|
|
1217
|
+
const result = await safe2(this.client.get("/api/v1/cart"));
|
|
1496
1218
|
if (!result.ok) return result;
|
|
1497
1219
|
return ok(unwrapEnrichedCart(result.value));
|
|
1498
1220
|
}
|
|
1499
1221
|
async getRaw() {
|
|
1500
|
-
return
|
|
1501
|
-
() => this.client.get("/api/v1/cart"),
|
|
1502
|
-
() => this.client.query("cart")
|
|
1503
|
-
);
|
|
1222
|
+
return safe2(this.client.get("/api/v1/cart"));
|
|
1504
1223
|
}
|
|
1505
1224
|
async getItems() {
|
|
1506
|
-
return
|
|
1507
|
-
() => this.client.get("/api/v1/cart/items"),
|
|
1508
|
-
() => this.client.query("cart_items")
|
|
1509
|
-
);
|
|
1225
|
+
return safe2(this.client.get("/api/v1/cart/items"));
|
|
1510
1226
|
}
|
|
1511
1227
|
async getCount() {
|
|
1512
|
-
return
|
|
1513
|
-
() => this.client.get("/api/v1/cart/count"),
|
|
1514
|
-
() => this.client.query("cart#count")
|
|
1515
|
-
);
|
|
1228
|
+
return safe2(this.client.get("/api/v1/cart/count"));
|
|
1516
1229
|
}
|
|
1517
1230
|
async getTotal() {
|
|
1518
|
-
return
|
|
1519
|
-
() => this.client.get("/api/v1/cart/total"),
|
|
1520
|
-
() => this.client.query("cart#total")
|
|
1521
|
-
);
|
|
1231
|
+
return safe2(this.client.get("/api/v1/cart/total"));
|
|
1522
1232
|
}
|
|
1523
1233
|
async getSummary() {
|
|
1524
1234
|
const cartResult = await this.get();
|
|
@@ -1535,66 +1245,39 @@ var CartOperations = class {
|
|
|
1535
1245
|
});
|
|
1536
1246
|
}
|
|
1537
1247
|
async addItem(input) {
|
|
1538
|
-
return
|
|
1539
|
-
() => this.client.post("/api/v1/cart/items", input),
|
|
1540
|
-
() => this.client.call("cart.addItem", input)
|
|
1541
|
-
);
|
|
1248
|
+
return safe2(this.client.post("/api/v1/cart/items", input));
|
|
1542
1249
|
}
|
|
1543
1250
|
async updateItem(cartItemId, updates) {
|
|
1544
1251
|
if (typeof updates.quantity === "number") {
|
|
1545
1252
|
return this.updateQuantity(cartItemId, updates.quantity);
|
|
1546
1253
|
}
|
|
1547
1254
|
const encodedId = encodeURIComponent(cartItemId);
|
|
1548
|
-
return
|
|
1549
|
-
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
|
|
1550
|
-
() => this.client.call("cart.updateItem", {
|
|
1551
|
-
cart_item_id: cartItemId,
|
|
1552
|
-
...updates
|
|
1553
|
-
})
|
|
1554
|
-
);
|
|
1255
|
+
return safe2(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
|
|
1555
1256
|
}
|
|
1556
1257
|
async updateQuantity(cartItemId, quantity) {
|
|
1557
1258
|
const encodedId = encodeURIComponent(cartItemId);
|
|
1558
|
-
return
|
|
1559
|
-
|
|
1560
|
-
quantity
|
|
1561
|
-
}),
|
|
1562
|
-
() => this.client.call("cart.updateItemQuantity", {
|
|
1563
|
-
cart_item_id: cartItemId,
|
|
1259
|
+
return safe2(
|
|
1260
|
+
this.client.patch(`/api/v1/cart/items/${encodedId}`, {
|
|
1564
1261
|
quantity
|
|
1565
1262
|
})
|
|
1566
1263
|
);
|
|
1567
1264
|
}
|
|
1568
1265
|
async removeItem(cartItemId) {
|
|
1569
1266
|
const encodedId = encodeURIComponent(cartItemId);
|
|
1570
|
-
return
|
|
1571
|
-
() => this.client.delete(`/api/v1/cart/items/${encodedId}`),
|
|
1572
|
-
() => this.client.call("cart.removeItem", {
|
|
1573
|
-
cart_item_id: cartItemId
|
|
1574
|
-
})
|
|
1575
|
-
);
|
|
1267
|
+
return safe2(this.client.delete(`/api/v1/cart/items/${encodedId}`));
|
|
1576
1268
|
}
|
|
1577
1269
|
async clear() {
|
|
1578
|
-
return
|
|
1579
|
-
() => this.client.delete("/api/v1/cart"),
|
|
1580
|
-
() => this.client.call("cart.clearCart")
|
|
1581
|
-
);
|
|
1270
|
+
return safe2(this.client.delete("/api/v1/cart"));
|
|
1582
1271
|
}
|
|
1583
1272
|
async applyCoupon(code) {
|
|
1584
|
-
return
|
|
1585
|
-
|
|
1586
|
-
coupon_code: code
|
|
1587
|
-
}),
|
|
1588
|
-
() => this.client.call("cart.applyCoupon", {
|
|
1273
|
+
return safe2(
|
|
1274
|
+
this.client.post("/api/v1/cart/coupons", {
|
|
1589
1275
|
coupon_code: code
|
|
1590
1276
|
})
|
|
1591
1277
|
);
|
|
1592
1278
|
}
|
|
1593
1279
|
async removeCoupon() {
|
|
1594
|
-
return
|
|
1595
|
-
() => this.client.delete("/api/v1/cart/coupons/current"),
|
|
1596
|
-
() => this.client.call("cart.removeCoupon")
|
|
1597
|
-
);
|
|
1280
|
+
return safe2(this.client.delete("/api/v1/cart/coupons/current"));
|
|
1598
1281
|
}
|
|
1599
1282
|
async isEmpty() {
|
|
1600
1283
|
const countResult = await this.getCount();
|
|
@@ -1631,35 +1314,6 @@ var CartOperations = class {
|
|
|
1631
1314
|
}
|
|
1632
1315
|
};
|
|
1633
1316
|
|
|
1634
|
-
// src/constants.ts
|
|
1635
|
-
var LINK_QUERY = {
|
|
1636
|
-
PREFERENCES: "link.preferences"};
|
|
1637
|
-
var LINK_MUTATION = {
|
|
1638
|
-
CHECK_STATUS: "link.check_status",
|
|
1639
|
-
ENROLL: "link.enroll",
|
|
1640
|
-
ENROLL_AND_LINK_ORDER: "link.enroll_and_link_order",
|
|
1641
|
-
UPDATE_PREFERENCES: "link.update_preferences",
|
|
1642
|
-
CREATE_ADDRESS: "link.create_address",
|
|
1643
|
-
UPDATE_ADDRESS: "link.update_address",
|
|
1644
|
-
TRACK_ADDRESS_USAGE: "link.track_address_usage",
|
|
1645
|
-
CREATE_MOBILE_MONEY: "link.create_mobile_money",
|
|
1646
|
-
TRACK_MOBILE_MONEY_USAGE: "link.track_mobile_money_usage",
|
|
1647
|
-
VERIFY_MOBILE_MONEY: "link.verify_mobile_money"};
|
|
1648
|
-
var AUTH_MUTATION = {
|
|
1649
|
-
REQUEST_OTP: "auth.request_otp",
|
|
1650
|
-
VERIFY_OTP: "auth.verify_otp"
|
|
1651
|
-
};
|
|
1652
|
-
var CHECKOUT_MUTATION = {
|
|
1653
|
-
PROCESS: "checkout.process"
|
|
1654
|
-
};
|
|
1655
|
-
var PAYMENT_MUTATION = {
|
|
1656
|
-
SUBMIT_AUTHORIZATION: "payment.submit_authorization",
|
|
1657
|
-
CHECK_STATUS: "order.poll_payment_status"
|
|
1658
|
-
};
|
|
1659
|
-
var ORDER_MUTATION = {
|
|
1660
|
-
UPDATE_CUSTOMER: "order.update_order_customer"
|
|
1661
|
-
};
|
|
1662
|
-
|
|
1663
1317
|
// src/utils/price.ts
|
|
1664
1318
|
function parsePrice(value) {
|
|
1665
1319
|
if (value === void 0 || value === null) {
|
|
@@ -2367,14 +2021,6 @@ async function safe3(promise) {
|
|
|
2367
2021
|
return err(toCimplifyError3(error));
|
|
2368
2022
|
}
|
|
2369
2023
|
}
|
|
2370
|
-
async function safeWithFallback3(primary, fallback) {
|
|
2371
|
-
const primaryResult = await safe3(primary());
|
|
2372
|
-
if (primaryResult.ok) return primaryResult;
|
|
2373
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2374
|
-
return primaryResult;
|
|
2375
|
-
}
|
|
2376
|
-
return safe3(fallback());
|
|
2377
|
-
}
|
|
2378
2024
|
function toTerminalFailure(code, message, recoverable) {
|
|
2379
2025
|
return {
|
|
2380
2026
|
success: false,
|
|
@@ -2397,57 +2043,51 @@ var CheckoutService = class {
|
|
|
2397
2043
|
constructor(client) {
|
|
2398
2044
|
this.client = client;
|
|
2399
2045
|
}
|
|
2046
|
+
orderTokenParam(orderId) {
|
|
2047
|
+
const token = this.client.getOrderToken(orderId);
|
|
2048
|
+
return token ? `?token=${encodeURIComponent(token)}` : "";
|
|
2049
|
+
}
|
|
2400
2050
|
async process(data) {
|
|
2401
2051
|
const checkoutData = {
|
|
2402
2052
|
...data,
|
|
2403
2053
|
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
2404
2054
|
};
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
checkout_data: checkoutData
|
|
2408
|
-
}),
|
|
2409
|
-
() => this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
2055
|
+
const result = await safe3(
|
|
2056
|
+
this.client.post("/api/v1/checkout", {
|
|
2410
2057
|
checkout_data: checkoutData
|
|
2411
2058
|
})
|
|
2412
2059
|
);
|
|
2060
|
+
if (result.ok && result.value.bill_token) {
|
|
2061
|
+
this.client.setOrderToken(result.value.order_id, result.value.bill_token);
|
|
2062
|
+
}
|
|
2063
|
+
return result;
|
|
2413
2064
|
}
|
|
2414
|
-
async initializePayment(
|
|
2415
|
-
return
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2065
|
+
async initializePayment(_orderId, _method) {
|
|
2066
|
+
return err(
|
|
2067
|
+
new CimplifyError(
|
|
2068
|
+
"NOT_IMPLEMENTED",
|
|
2069
|
+
"initializePayment is not available in REST mode.",
|
|
2070
|
+
false
|
|
2071
|
+
)
|
|
2420
2072
|
);
|
|
2421
2073
|
}
|
|
2422
2074
|
async submitAuthorization(input) {
|
|
2423
|
-
return
|
|
2424
|
-
() => this.client.post("/api/v1/payments/authorization", input),
|
|
2425
|
-
() => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
2426
|
-
);
|
|
2075
|
+
return safe3(this.client.post("/api/v1/payments/authorization", input));
|
|
2427
2076
|
}
|
|
2428
2077
|
async pollPaymentStatus(orderId) {
|
|
2429
2078
|
const encodedId = encodeURIComponent(orderId);
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
() => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
2433
|
-
);
|
|
2079
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
2080
|
+
return safe3(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
|
|
2434
2081
|
}
|
|
2435
2082
|
async updateOrderCustomer(orderId, customer) {
|
|
2436
2083
|
const encodedId = encodeURIComponent(orderId);
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
() => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
2440
|
-
order_id: orderId,
|
|
2441
|
-
...customer
|
|
2442
|
-
})
|
|
2443
|
-
);
|
|
2084
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
2085
|
+
return safe3(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
|
|
2444
2086
|
}
|
|
2445
2087
|
async verifyPayment(orderId) {
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
})
|
|
2450
|
-
);
|
|
2088
|
+
const encodedId = encodeURIComponent(orderId);
|
|
2089
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
2090
|
+
return safe3(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
|
|
2451
2091
|
}
|
|
2452
2092
|
async processAndResolve(data) {
|
|
2453
2093
|
data.on_status_change?.("preparing", {});
|
|
@@ -2566,61 +2206,38 @@ async function safe4(promise) {
|
|
|
2566
2206
|
return err(toCimplifyError4(error));
|
|
2567
2207
|
}
|
|
2568
2208
|
}
|
|
2569
|
-
async function safeWithFallback4(primary, fallback) {
|
|
2570
|
-
const primaryResult = await safe4(primary());
|
|
2571
|
-
if (primaryResult.ok) return primaryResult;
|
|
2572
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2573
|
-
return primaryResult;
|
|
2574
|
-
}
|
|
2575
|
-
return safe4(fallback());
|
|
2576
|
-
}
|
|
2577
2209
|
var OrderQueries = class {
|
|
2578
2210
|
constructor(client) {
|
|
2579
2211
|
this.client = client;
|
|
2580
2212
|
}
|
|
2213
|
+
orderTokenParam(orderId) {
|
|
2214
|
+
const token = this.client.getOrderToken(orderId);
|
|
2215
|
+
return token ? `?token=${encodeURIComponent(token)}` : "";
|
|
2216
|
+
}
|
|
2581
2217
|
async list(options) {
|
|
2582
|
-
let query = "orders";
|
|
2583
|
-
if (options?.status) {
|
|
2584
|
-
query += `[?(@.status=='${options.status}')]`;
|
|
2585
|
-
}
|
|
2586
|
-
query += "#sort(created_at,desc)";
|
|
2587
|
-
if (options?.limit) {
|
|
2588
|
-
query += `#limit(${options.limit})`;
|
|
2589
|
-
}
|
|
2590
|
-
if (options?.offset) {
|
|
2591
|
-
query += `#offset(${options.offset})`;
|
|
2592
|
-
}
|
|
2593
2218
|
const params = new URLSearchParams();
|
|
2594
2219
|
if (options?.status) params.set("status", options.status);
|
|
2595
2220
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
2596
2221
|
if (options?.offset) params.set("offset", String(options.offset));
|
|
2597
2222
|
const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
|
|
2598
|
-
return
|
|
2599
|
-
() => this.client.get(path),
|
|
2600
|
-
() => this.client.query(query)
|
|
2601
|
-
);
|
|
2223
|
+
return safe4(this.client.get(path));
|
|
2602
2224
|
}
|
|
2603
2225
|
async get(orderId) {
|
|
2604
2226
|
const encodedId = encodeURIComponent(orderId);
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
() => this.client.query(`orders.${orderId}`)
|
|
2608
|
-
);
|
|
2227
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
2228
|
+
return safe4(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
2609
2229
|
}
|
|
2610
2230
|
async getRecent(limit = 5) {
|
|
2611
|
-
return
|
|
2231
|
+
return this.list({ limit });
|
|
2612
2232
|
}
|
|
2613
2233
|
async getByStatus(status) {
|
|
2614
2234
|
return this.list({ status });
|
|
2615
2235
|
}
|
|
2616
2236
|
async cancel(orderId, reason) {
|
|
2617
2237
|
const encodedId = encodeURIComponent(orderId);
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
}),
|
|
2622
|
-
() => this.client.call("order.cancelOrder", {
|
|
2623
|
-
order_id: orderId,
|
|
2238
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
2239
|
+
return safe4(
|
|
2240
|
+
this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
|
|
2624
2241
|
reason
|
|
2625
2242
|
})
|
|
2626
2243
|
);
|
|
@@ -2642,6 +2259,38 @@ async function safe5(promise) {
|
|
|
2642
2259
|
return err(toCimplifyError5(error));
|
|
2643
2260
|
}
|
|
2644
2261
|
}
|
|
2262
|
+
function encodePathSegment(value) {
|
|
2263
|
+
return encodeURIComponent(value);
|
|
2264
|
+
}
|
|
2265
|
+
function toCreateAddressPayload(input) {
|
|
2266
|
+
return {
|
|
2267
|
+
label: input.label,
|
|
2268
|
+
street_address: input.address_line1,
|
|
2269
|
+
apartment: input.address_line2,
|
|
2270
|
+
city: input.city,
|
|
2271
|
+
region: input.state ?? "",
|
|
2272
|
+
postal_code: input.postal_code,
|
|
2273
|
+
country: input.country
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
function toUpdateAddressPayload(input) {
|
|
2277
|
+
return {
|
|
2278
|
+
label: input.label,
|
|
2279
|
+
street_address: input.address_line1,
|
|
2280
|
+
apartment: input.address_line2,
|
|
2281
|
+
city: input.city,
|
|
2282
|
+
region: input.state,
|
|
2283
|
+
postal_code: input.postal_code,
|
|
2284
|
+
country: input.country
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
function toCreateMobileMoneyPayload(input) {
|
|
2288
|
+
return {
|
|
2289
|
+
phone_number: input.phone_number,
|
|
2290
|
+
provider: input.provider,
|
|
2291
|
+
label: input.account_name
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2645
2294
|
var LinkService = class {
|
|
2646
2295
|
constructor(client) {
|
|
2647
2296
|
this.client = client;
|
|
@@ -2669,11 +2318,7 @@ var LinkService = class {
|
|
|
2669
2318
|
return result;
|
|
2670
2319
|
}
|
|
2671
2320
|
async checkStatus(contact) {
|
|
2672
|
-
return safe5(
|
|
2673
|
-
this.client.call(LINK_MUTATION.CHECK_STATUS, {
|
|
2674
|
-
contact
|
|
2675
|
-
})
|
|
2676
|
-
);
|
|
2321
|
+
return safe5(this.client.linkPost("/v1/link/check-status", { contact }));
|
|
2677
2322
|
}
|
|
2678
2323
|
async getLinkData() {
|
|
2679
2324
|
return safe5(this.client.linkGet("/v1/link/data"));
|
|
@@ -2685,61 +2330,85 @@ var LinkService = class {
|
|
|
2685
2330
|
return safe5(this.client.linkGet("/v1/link/mobile-money"));
|
|
2686
2331
|
}
|
|
2687
2332
|
async getPreferences() {
|
|
2688
|
-
return safe5(this.client.
|
|
2333
|
+
return safe5(this.client.linkGet("/v1/link/preferences"));
|
|
2689
2334
|
}
|
|
2690
2335
|
async enroll(data) {
|
|
2691
|
-
return safe5(this.client.
|
|
2336
|
+
return safe5(this.client.linkPost("/v1/link/enroll", data));
|
|
2692
2337
|
}
|
|
2693
2338
|
async enrollAndLinkOrder(data) {
|
|
2694
2339
|
return safe5(
|
|
2695
|
-
this.client.
|
|
2340
|
+
this.client.linkPost("/v1/link/enroll-and-link-order", data)
|
|
2696
2341
|
);
|
|
2697
2342
|
}
|
|
2698
2343
|
async updatePreferences(preferences) {
|
|
2699
|
-
return safe5(this.client.
|
|
2344
|
+
return safe5(this.client.linkPost("/v1/link/preferences", preferences));
|
|
2700
2345
|
}
|
|
2701
2346
|
async createAddress(input) {
|
|
2702
|
-
return safe5(
|
|
2347
|
+
return safe5(
|
|
2348
|
+
this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
|
|
2349
|
+
);
|
|
2703
2350
|
}
|
|
2704
2351
|
async updateAddress(input) {
|
|
2705
|
-
return safe5(
|
|
2352
|
+
return safe5(
|
|
2353
|
+
this.client.linkPost(
|
|
2354
|
+
`/v1/link/addresses/${encodePathSegment(input.address_id)}`,
|
|
2355
|
+
toUpdateAddressPayload(input)
|
|
2356
|
+
)
|
|
2357
|
+
);
|
|
2706
2358
|
}
|
|
2707
2359
|
async deleteAddress(addressId) {
|
|
2708
|
-
return safe5(
|
|
2360
|
+
return safe5(
|
|
2361
|
+
this.client.linkDelete(`/v1/link/addresses/${encodePathSegment(addressId)}`)
|
|
2362
|
+
);
|
|
2709
2363
|
}
|
|
2710
2364
|
async setDefaultAddress(addressId) {
|
|
2711
|
-
return safe5(
|
|
2365
|
+
return safe5(
|
|
2366
|
+
this.client.linkPost(
|
|
2367
|
+
`/v1/link/addresses/${encodePathSegment(addressId)}/default`
|
|
2368
|
+
)
|
|
2369
|
+
);
|
|
2712
2370
|
}
|
|
2713
2371
|
async trackAddressUsage(addressId) {
|
|
2714
2372
|
return safe5(
|
|
2715
|
-
this.client.
|
|
2716
|
-
|
|
2717
|
-
|
|
2373
|
+
this.client.linkPost(
|
|
2374
|
+
`/v1/link/addresses/${encodePathSegment(addressId)}/track-usage`
|
|
2375
|
+
)
|
|
2718
2376
|
);
|
|
2719
2377
|
}
|
|
2720
2378
|
async createMobileMoney(input) {
|
|
2721
|
-
return safe5(
|
|
2379
|
+
return safe5(
|
|
2380
|
+
this.client.linkPost(
|
|
2381
|
+
"/v1/link/mobile-money",
|
|
2382
|
+
toCreateMobileMoneyPayload(input)
|
|
2383
|
+
)
|
|
2384
|
+
);
|
|
2722
2385
|
}
|
|
2723
2386
|
async deleteMobileMoney(mobileMoneyId) {
|
|
2724
2387
|
return safe5(
|
|
2725
|
-
this.client.linkDelete(
|
|
2388
|
+
this.client.linkDelete(
|
|
2389
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}`
|
|
2390
|
+
)
|
|
2726
2391
|
);
|
|
2727
2392
|
}
|
|
2728
2393
|
async setDefaultMobileMoney(mobileMoneyId) {
|
|
2729
2394
|
return safe5(
|
|
2730
|
-
this.client.linkPost(
|
|
2395
|
+
this.client.linkPost(
|
|
2396
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/default`
|
|
2397
|
+
)
|
|
2731
2398
|
);
|
|
2732
2399
|
}
|
|
2733
2400
|
async trackMobileMoneyUsage(mobileMoneyId) {
|
|
2734
2401
|
return safe5(
|
|
2735
|
-
this.client.
|
|
2736
|
-
|
|
2737
|
-
|
|
2402
|
+
this.client.linkPost(
|
|
2403
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/track-usage`
|
|
2404
|
+
)
|
|
2738
2405
|
);
|
|
2739
2406
|
}
|
|
2740
2407
|
async verifyMobileMoney(mobileMoneyId) {
|
|
2741
2408
|
return safe5(
|
|
2742
|
-
this.client.
|
|
2409
|
+
this.client.linkPost(
|
|
2410
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
|
|
2411
|
+
)
|
|
2743
2412
|
);
|
|
2744
2413
|
}
|
|
2745
2414
|
async getSessions() {
|
|
@@ -2752,30 +2421,28 @@ var LinkService = class {
|
|
|
2752
2421
|
return safe5(this.client.linkDelete("/v1/link/sessions"));
|
|
2753
2422
|
}
|
|
2754
2423
|
async getAddressesRest() {
|
|
2755
|
-
return
|
|
2424
|
+
return this.getAddresses();
|
|
2756
2425
|
}
|
|
2757
2426
|
async createAddressRest(input) {
|
|
2758
|
-
return
|
|
2427
|
+
return this.createAddress(input);
|
|
2759
2428
|
}
|
|
2760
2429
|
async deleteAddressRest(addressId) {
|
|
2761
|
-
return
|
|
2430
|
+
return this.deleteAddress(addressId);
|
|
2762
2431
|
}
|
|
2763
2432
|
async setDefaultAddressRest(addressId) {
|
|
2764
|
-
return
|
|
2433
|
+
return this.setDefaultAddress(addressId);
|
|
2765
2434
|
}
|
|
2766
2435
|
async getMobileMoneyRest() {
|
|
2767
|
-
return
|
|
2436
|
+
return this.getMobileMoney();
|
|
2768
2437
|
}
|
|
2769
2438
|
async createMobileMoneyRest(input) {
|
|
2770
|
-
return
|
|
2439
|
+
return this.createMobileMoney(input);
|
|
2771
2440
|
}
|
|
2772
2441
|
async deleteMobileMoneyRest(mobileMoneyId) {
|
|
2773
|
-
return
|
|
2442
|
+
return this.deleteMobileMoney(mobileMoneyId);
|
|
2774
2443
|
}
|
|
2775
2444
|
async setDefaultMobileMoneyRest(mobileMoneyId) {
|
|
2776
|
-
return
|
|
2777
|
-
this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
|
|
2778
|
-
);
|
|
2445
|
+
return this.setDefaultMobileMoney(mobileMoneyId);
|
|
2779
2446
|
}
|
|
2780
2447
|
};
|
|
2781
2448
|
|
|
@@ -2794,23 +2461,12 @@ async function safe6(promise) {
|
|
|
2794
2461
|
return err(toCimplifyError6(error));
|
|
2795
2462
|
}
|
|
2796
2463
|
}
|
|
2797
|
-
async function safeWithFallback5(primary, fallback) {
|
|
2798
|
-
const primaryResult = await safe6(primary());
|
|
2799
|
-
if (primaryResult.ok) return primaryResult;
|
|
2800
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2801
|
-
return primaryResult;
|
|
2802
|
-
}
|
|
2803
|
-
return safe6(fallback());
|
|
2804
|
-
}
|
|
2805
2464
|
var AuthService = class {
|
|
2806
2465
|
constructor(client) {
|
|
2807
2466
|
this.client = client;
|
|
2808
2467
|
}
|
|
2809
2468
|
async getStatus() {
|
|
2810
|
-
return
|
|
2811
|
-
() => this.client.get("/api/v1/auth/status"),
|
|
2812
|
-
() => this.client.query("auth")
|
|
2813
|
-
);
|
|
2469
|
+
return safe6(this.client.get("/api/v1/auth/status"));
|
|
2814
2470
|
}
|
|
2815
2471
|
async getCurrentUser() {
|
|
2816
2472
|
const result = await this.getStatus();
|
|
@@ -2823,43 +2479,26 @@ var AuthService = class {
|
|
|
2823
2479
|
return ok(result.value.is_authenticated);
|
|
2824
2480
|
}
|
|
2825
2481
|
async requestOtp(contact, contactType) {
|
|
2826
|
-
return
|
|
2827
|
-
|
|
2828
|
-
contact,
|
|
2829
|
-
contact_type: contactType
|
|
2830
|
-
}),
|
|
2831
|
-
() => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
2482
|
+
return safe6(
|
|
2483
|
+
this.client.post("/api/v1/auth/request-otp", {
|
|
2832
2484
|
contact,
|
|
2833
2485
|
contact_type: contactType
|
|
2834
2486
|
})
|
|
2835
2487
|
);
|
|
2836
2488
|
}
|
|
2837
2489
|
async verifyOtp(code, contact) {
|
|
2838
|
-
return
|
|
2839
|
-
|
|
2840
|
-
otp_code: code,
|
|
2841
|
-
contact
|
|
2842
|
-
}),
|
|
2843
|
-
() => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
2490
|
+
return safe6(
|
|
2491
|
+
this.client.post("/api/v1/auth/verify-otp", {
|
|
2844
2492
|
otp_code: code,
|
|
2845
2493
|
contact
|
|
2846
2494
|
})
|
|
2847
2495
|
);
|
|
2848
2496
|
}
|
|
2849
2497
|
async logout() {
|
|
2850
|
-
return
|
|
2851
|
-
() => this.client.post("/api/v1/auth/logout"),
|
|
2852
|
-
() => this.client.call("auth.logout")
|
|
2853
|
-
);
|
|
2498
|
+
return safe6(this.client.post("/api/v1/auth/logout"));
|
|
2854
2499
|
}
|
|
2855
2500
|
async updateProfile(input) {
|
|
2856
|
-
return safe6(this.client.
|
|
2857
|
-
}
|
|
2858
|
-
async changePassword(input) {
|
|
2859
|
-
return safe6(this.client.call("auth.change_password", input));
|
|
2860
|
-
}
|
|
2861
|
-
async resetPassword(email) {
|
|
2862
|
-
return safe6(this.client.call("auth.reset_password", { email }));
|
|
2501
|
+
return safe6(this.client.post("/api/v1/auth/profile", input));
|
|
2863
2502
|
}
|
|
2864
2503
|
};
|
|
2865
2504
|
|
|
@@ -2878,47 +2517,29 @@ async function safe7(promise) {
|
|
|
2878
2517
|
return err(toCimplifyError7(error));
|
|
2879
2518
|
}
|
|
2880
2519
|
}
|
|
2881
|
-
async function safeWithFallback6(primary, fallback) {
|
|
2882
|
-
const primaryResult = await safe7(primary());
|
|
2883
|
-
if (primaryResult.ok) return primaryResult;
|
|
2884
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2885
|
-
return primaryResult;
|
|
2886
|
-
}
|
|
2887
|
-
return safe7(fallback());
|
|
2888
|
-
}
|
|
2889
2520
|
var BusinessService = class {
|
|
2890
2521
|
constructor(client) {
|
|
2891
2522
|
this.client = client;
|
|
2892
2523
|
}
|
|
2893
2524
|
async getInfo() {
|
|
2894
|
-
return
|
|
2895
|
-
() => this.client.get("/api/v1/business"),
|
|
2896
|
-
() => this.client.query("business.info")
|
|
2897
|
-
);
|
|
2525
|
+
return safe7(this.client.get("/api/v1/business"));
|
|
2898
2526
|
}
|
|
2899
2527
|
async getByHandle(handle) {
|
|
2900
|
-
|
|
2528
|
+
const encodedHandle = encodeURIComponent(handle);
|
|
2529
|
+
return safe7(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
|
|
2901
2530
|
}
|
|
2902
2531
|
async getByDomain(domain) {
|
|
2903
|
-
|
|
2532
|
+
const encodedDomain = encodeURIComponent(domain);
|
|
2533
|
+
return safe7(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
|
|
2904
2534
|
}
|
|
2905
2535
|
async getSettings() {
|
|
2906
|
-
return
|
|
2907
|
-
() => this.client.get("/api/v1/business/settings"),
|
|
2908
|
-
() => this.client.query("business.settings")
|
|
2909
|
-
);
|
|
2536
|
+
return safe7(this.client.get("/api/v1/business/settings"));
|
|
2910
2537
|
}
|
|
2911
2538
|
async getTheme() {
|
|
2912
|
-
return
|
|
2913
|
-
() => this.client.get("/api/v1/business/theme"),
|
|
2914
|
-
() => this.client.query("business.theme")
|
|
2915
|
-
);
|
|
2539
|
+
return safe7(this.client.get("/api/v1/business/theme"));
|
|
2916
2540
|
}
|
|
2917
2541
|
async getLocations() {
|
|
2918
|
-
return
|
|
2919
|
-
() => this.client.get("/api/v1/business/locations"),
|
|
2920
|
-
() => this.client.query("business.locations")
|
|
2921
|
-
);
|
|
2542
|
+
return safe7(this.client.get("/api/v1/business/locations"));
|
|
2922
2543
|
}
|
|
2923
2544
|
async getLocation(locationId) {
|
|
2924
2545
|
const result = await this.getLocations();
|
|
@@ -2930,10 +2551,7 @@ var BusinessService = class {
|
|
|
2930
2551
|
return ok(location);
|
|
2931
2552
|
}
|
|
2932
2553
|
async getHours() {
|
|
2933
|
-
return
|
|
2934
|
-
() => this.client.get("/api/v1/business/hours"),
|
|
2935
|
-
() => this.client.query("business.hours")
|
|
2936
|
-
);
|
|
2554
|
+
return safe7(this.client.get("/api/v1/business/hours"));
|
|
2937
2555
|
}
|
|
2938
2556
|
async getLocationHours(locationId) {
|
|
2939
2557
|
const result = await this.getHours();
|
|
@@ -2941,31 +2559,7 @@ var BusinessService = class {
|
|
|
2941
2559
|
return ok(result.value.filter((hour) => hour.location_id === locationId));
|
|
2942
2560
|
}
|
|
2943
2561
|
async getBootstrap() {
|
|
2944
|
-
|
|
2945
|
-
if (restBootstrap.ok) {
|
|
2946
|
-
return restBootstrap;
|
|
2947
|
-
}
|
|
2948
|
-
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
2949
|
-
this.getInfo(),
|
|
2950
|
-
this.getLocations(),
|
|
2951
|
-
safe7(this.client.query("categories#select(id,name,slug)"))
|
|
2952
|
-
]);
|
|
2953
|
-
if (!businessResult.ok) return businessResult;
|
|
2954
|
-
if (!locationsResult.ok) return locationsResult;
|
|
2955
|
-
if (!categoriesResult.ok) return categoriesResult;
|
|
2956
|
-
const business = businessResult.value;
|
|
2957
|
-
const locations = locationsResult.value;
|
|
2958
|
-
const categories = categoriesResult.value;
|
|
2959
|
-
const defaultLocation = locations[0];
|
|
2960
|
-
return ok({
|
|
2961
|
-
business,
|
|
2962
|
-
location: defaultLocation,
|
|
2963
|
-
locations,
|
|
2964
|
-
categories,
|
|
2965
|
-
currency: business.default_currency,
|
|
2966
|
-
is_open: defaultLocation?.accepts_online_orders ?? false,
|
|
2967
|
-
accepts_orders: defaultLocation?.accepts_online_orders ?? false
|
|
2968
|
-
});
|
|
2562
|
+
return safe7(this.client.get("/api/v1/bootstrap"));
|
|
2969
2563
|
}
|
|
2970
2564
|
};
|
|
2971
2565
|
|
|
@@ -2988,49 +2582,47 @@ var InventoryService = class {
|
|
|
2988
2582
|
constructor(client) {
|
|
2989
2583
|
this.client = client;
|
|
2990
2584
|
}
|
|
2585
|
+
withQuery(path, params) {
|
|
2586
|
+
const searchParams = new URLSearchParams();
|
|
2587
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2588
|
+
if (value === void 0) continue;
|
|
2589
|
+
searchParams.set(key, String(value));
|
|
2590
|
+
}
|
|
2591
|
+
const query = searchParams.toString();
|
|
2592
|
+
return query ? `${path}?${query}` : path;
|
|
2593
|
+
}
|
|
2991
2594
|
async getStockLevels() {
|
|
2992
|
-
return safe8(this.client.
|
|
2595
|
+
return safe8(this.client.get("/api/v1/inventory/stock-levels"));
|
|
2993
2596
|
}
|
|
2994
2597
|
async getProductStock(productId, locationId) {
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
})
|
|
3001
|
-
);
|
|
3002
|
-
}
|
|
3003
|
-
return safe8(
|
|
3004
|
-
this.client.query("inventory.product", {
|
|
3005
|
-
product_id: productId
|
|
3006
|
-
})
|
|
3007
|
-
);
|
|
2598
|
+
const encodedId = encodeURIComponent(productId);
|
|
2599
|
+
const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
|
|
2600
|
+
location_id: locationId
|
|
2601
|
+
});
|
|
2602
|
+
return safe8(this.client.get(path));
|
|
3008
2603
|
}
|
|
3009
2604
|
async getVariantStock(variantId, locationId) {
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
);
|
|
2605
|
+
const encodedId = encodeURIComponent(variantId);
|
|
2606
|
+
const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/stock`, {
|
|
2607
|
+
location_id: locationId
|
|
2608
|
+
});
|
|
2609
|
+
return safe8(this.client.get(path));
|
|
3016
2610
|
}
|
|
3017
2611
|
async checkProductAvailability(productId, quantity, locationId) {
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
);
|
|
2612
|
+
const encodedId = encodeURIComponent(productId);
|
|
2613
|
+
const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/availability`, {
|
|
2614
|
+
quantity,
|
|
2615
|
+
location_id: locationId
|
|
2616
|
+
});
|
|
2617
|
+
return safe8(this.client.get(path));
|
|
3025
2618
|
}
|
|
3026
2619
|
async checkVariantAvailability(variantId, quantity, locationId) {
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
);
|
|
2620
|
+
const encodedId = encodeURIComponent(variantId);
|
|
2621
|
+
const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/availability`, {
|
|
2622
|
+
quantity,
|
|
2623
|
+
location_id: locationId
|
|
2624
|
+
});
|
|
2625
|
+
return safe8(this.client.get(path));
|
|
3034
2626
|
}
|
|
3035
2627
|
async checkMultipleAvailability(items, locationId) {
|
|
3036
2628
|
const results = await Promise.all(
|
|
@@ -3044,7 +2636,7 @@ var InventoryService = class {
|
|
|
3044
2636
|
return ok(results.map((r) => r.value));
|
|
3045
2637
|
}
|
|
3046
2638
|
async getSummary() {
|
|
3047
|
-
return safe8(this.client.
|
|
2639
|
+
return safe8(this.client.get("/api/v1/inventory/summary"));
|
|
3048
2640
|
}
|
|
3049
2641
|
async isInStock(productId, locationId) {
|
|
3050
2642
|
const result = await this.checkProductAvailability(productId, 1, locationId);
|
|
@@ -3059,9 +2651,6 @@ var InventoryService = class {
|
|
|
3059
2651
|
};
|
|
3060
2652
|
|
|
3061
2653
|
// src/scheduling.ts
|
|
3062
|
-
function toVariables(input) {
|
|
3063
|
-
return Object.fromEntries(Object.entries(input));
|
|
3064
|
-
}
|
|
3065
2654
|
function toCimplifyError9(error) {
|
|
3066
2655
|
if (error instanceof CimplifyError) return error;
|
|
3067
2656
|
if (error instanceof Error) {
|
|
@@ -3076,68 +2665,110 @@ async function safe9(promise) {
|
|
|
3076
2665
|
return err(toCimplifyError9(error));
|
|
3077
2666
|
}
|
|
3078
2667
|
}
|
|
2668
|
+
function withQuery2(path, params) {
|
|
2669
|
+
const searchParams = new URLSearchParams();
|
|
2670
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2671
|
+
if (value === void 0) continue;
|
|
2672
|
+
searchParams.set(key, String(value));
|
|
2673
|
+
}
|
|
2674
|
+
const query = searchParams.toString();
|
|
2675
|
+
return query ? `${path}?${query}` : path;
|
|
2676
|
+
}
|
|
2677
|
+
function normalizeServiceAvailability(result) {
|
|
2678
|
+
if (Array.isArray(result.days) && result.days.length > 0) {
|
|
2679
|
+
return result;
|
|
2680
|
+
}
|
|
2681
|
+
const days = Array.isArray(result.availability) ? result.availability.map((day) => ({
|
|
2682
|
+
...day,
|
|
2683
|
+
is_fully_booked: day.is_fully_booked ?? (typeof day.has_availability === "boolean" ? !day.has_availability : void 0)
|
|
2684
|
+
})) : [];
|
|
2685
|
+
return { ...result, days };
|
|
2686
|
+
}
|
|
2687
|
+
function firstScheduledTime(booking) {
|
|
2688
|
+
return booking.service_items.find((item) => typeof item.scheduled_start === "string")?.scheduled_start || booking.created_at;
|
|
2689
|
+
}
|
|
3079
2690
|
var SchedulingService = class {
|
|
3080
2691
|
constructor(client) {
|
|
3081
2692
|
this.client = client;
|
|
3082
2693
|
}
|
|
3083
2694
|
async getServices() {
|
|
3084
|
-
return safe9(this.client.
|
|
2695
|
+
return safe9(this.client.get("/api/v1/scheduling/services"));
|
|
3085
2696
|
}
|
|
3086
2697
|
/**
|
|
3087
|
-
* Get a specific service by ID
|
|
3088
|
-
* Note: Filters from all services client-side (no single-service endpoint)
|
|
2698
|
+
* Get a specific service by ID.
|
|
3089
2699
|
*/
|
|
3090
2700
|
async getService(serviceId) {
|
|
3091
2701
|
const result = await this.getServices();
|
|
3092
2702
|
if (!result.ok) return result;
|
|
3093
|
-
return ok(result.value.find((
|
|
2703
|
+
return ok(result.value.find((service) => service.id === serviceId) || null);
|
|
3094
2704
|
}
|
|
3095
2705
|
async getAvailableSlots(input) {
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
2706
|
+
const path = withQuery2("/api/v1/scheduling/slots", {
|
|
2707
|
+
service_id: input.service_id,
|
|
2708
|
+
date: input.date,
|
|
2709
|
+
participant_count: input.participant_count,
|
|
2710
|
+
duration_minutes: input.duration_minutes
|
|
2711
|
+
});
|
|
2712
|
+
return safe9(this.client.get(path));
|
|
3099
2713
|
}
|
|
3100
2714
|
async checkSlotAvailability(input) {
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
);
|
|
2715
|
+
const path = withQuery2("/api/v1/scheduling/slots/check", {
|
|
2716
|
+
service_id: input.service_id,
|
|
2717
|
+
slot_time: input.slot_time,
|
|
2718
|
+
duration_minutes: input.duration_minutes,
|
|
2719
|
+
participant_count: input.participant_count
|
|
2720
|
+
});
|
|
2721
|
+
return safe9(this.client.get(path));
|
|
3107
2722
|
}
|
|
3108
2723
|
async getServiceAvailability(params) {
|
|
2724
|
+
const path = withQuery2("/api/v1/scheduling/availability", {
|
|
2725
|
+
service_id: params.service_id,
|
|
2726
|
+
start_date: params.start_date,
|
|
2727
|
+
end_date: params.end_date,
|
|
2728
|
+
location_id: params.location_id,
|
|
2729
|
+
participant_count: params.participant_count
|
|
2730
|
+
});
|
|
3109
2731
|
return safe9(
|
|
3110
|
-
this.client.
|
|
3111
|
-
"scheduling.availability",
|
|
3112
|
-
toVariables(params)
|
|
3113
|
-
)
|
|
2732
|
+
this.client.get(path).then((result) => normalizeServiceAvailability(result))
|
|
3114
2733
|
);
|
|
3115
2734
|
}
|
|
3116
2735
|
async getBooking(bookingId) {
|
|
3117
|
-
|
|
2736
|
+
const encodedId = encodeURIComponent(bookingId);
|
|
2737
|
+
return safe9(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
|
|
3118
2738
|
}
|
|
3119
|
-
async getCustomerBookings() {
|
|
3120
|
-
|
|
2739
|
+
async getCustomerBookings(customerId) {
|
|
2740
|
+
const path = withQuery2("/api/v1/scheduling/bookings", {
|
|
2741
|
+
customer_id: customerId
|
|
2742
|
+
});
|
|
2743
|
+
return safe9(this.client.get(path));
|
|
3121
2744
|
}
|
|
3122
2745
|
async getUpcomingBookings() {
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
)
|
|
3127
|
-
|
|
2746
|
+
const result = await this.getCustomerBookings();
|
|
2747
|
+
if (!result.ok) return result;
|
|
2748
|
+
const upcoming = result.value.filter((booking) => {
|
|
2749
|
+
const status = String(booking.status).toLowerCase();
|
|
2750
|
+
return status !== "completed" && status !== "cancelled";
|
|
2751
|
+
}).sort((a, b) => firstScheduledTime(a).localeCompare(firstScheduledTime(b)));
|
|
2752
|
+
return ok(upcoming);
|
|
3128
2753
|
}
|
|
3129
2754
|
async getPastBookings(limit = 10) {
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
);
|
|
2755
|
+
const result = await this.getCustomerBookings();
|
|
2756
|
+
if (!result.ok) return result;
|
|
2757
|
+
const past = result.value.filter((booking) => String(booking.status).toLowerCase() === "completed").sort((a, b) => firstScheduledTime(b).localeCompare(firstScheduledTime(a))).slice(0, Math.max(0, limit));
|
|
2758
|
+
return ok(past);
|
|
3135
2759
|
}
|
|
3136
2760
|
async cancelBooking(input) {
|
|
3137
|
-
|
|
2761
|
+
const encodedId = encodeURIComponent(input.booking_id);
|
|
2762
|
+
return safe9(
|
|
2763
|
+
this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
|
|
2764
|
+
reason: input.reason
|
|
2765
|
+
})
|
|
2766
|
+
);
|
|
3138
2767
|
}
|
|
3139
2768
|
async rescheduleBooking(input) {
|
|
3140
|
-
return safe9(
|
|
2769
|
+
return safe9(
|
|
2770
|
+
this.client.post("/api/v1/scheduling/bookings/reschedule", input)
|
|
2771
|
+
);
|
|
3141
2772
|
}
|
|
3142
2773
|
async getNextAvailableSlot(serviceId, fromDate) {
|
|
3143
2774
|
const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
@@ -3156,6 +2787,12 @@ var SchedulingService = class {
|
|
|
3156
2787
|
if (!result.ok) return result;
|
|
3157
2788
|
return ok(result.value.some((slot) => slot.is_available));
|
|
3158
2789
|
}
|
|
2790
|
+
// Compatibility alias for callers typed against the older Booking shape.
|
|
2791
|
+
async getBookingLegacy(bookingId) {
|
|
2792
|
+
const result = await this.getBooking(bookingId);
|
|
2793
|
+
if (!result.ok) return result;
|
|
2794
|
+
return ok(result.value);
|
|
2795
|
+
}
|
|
3159
2796
|
};
|
|
3160
2797
|
|
|
3161
2798
|
// src/lite.ts
|
|
@@ -3178,47 +2815,18 @@ var LiteService = class {
|
|
|
3178
2815
|
this.client = client;
|
|
3179
2816
|
}
|
|
3180
2817
|
async getBootstrap() {
|
|
3181
|
-
return safe10(this.client.
|
|
2818
|
+
return safe10(this.client.get("/api/v1/lite/bootstrap"));
|
|
3182
2819
|
}
|
|
3183
2820
|
async getTable(tableId) {
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
async getTableByNumber(tableNumber, locationId) {
|
|
3187
|
-
return safe10(
|
|
3188
|
-
this.client.query("lite.table_by_number", {
|
|
3189
|
-
table_number: tableNumber,
|
|
3190
|
-
location_id: locationId
|
|
3191
|
-
})
|
|
3192
|
-
);
|
|
3193
|
-
}
|
|
3194
|
-
async sendToKitchen(tableId, items) {
|
|
3195
|
-
return safe10(
|
|
3196
|
-
this.client.call("lite.send_to_kitchen", {
|
|
3197
|
-
table_id: tableId,
|
|
3198
|
-
items
|
|
3199
|
-
})
|
|
3200
|
-
);
|
|
3201
|
-
}
|
|
3202
|
-
async callWaiter(tableId, reason) {
|
|
3203
|
-
return safe10(
|
|
3204
|
-
this.client.call("lite.call_waiter", {
|
|
3205
|
-
table_id: tableId,
|
|
3206
|
-
reason
|
|
3207
|
-
})
|
|
3208
|
-
);
|
|
3209
|
-
}
|
|
3210
|
-
async requestBill(tableId) {
|
|
3211
|
-
return safe10(
|
|
3212
|
-
this.client.call("lite.request_bill", {
|
|
3213
|
-
table_id: tableId
|
|
3214
|
-
})
|
|
3215
|
-
);
|
|
2821
|
+
const encodedId = encodeURIComponent(tableId);
|
|
2822
|
+
return safe10(this.client.get(`/api/v1/lite/tables/${encodedId}`));
|
|
3216
2823
|
}
|
|
3217
2824
|
async getMenu() {
|
|
3218
|
-
return safe10(this.client.
|
|
2825
|
+
return safe10(this.client.get("/api/v1/lite/menu"));
|
|
3219
2826
|
}
|
|
3220
2827
|
async getMenuByCategory(categoryId) {
|
|
3221
|
-
|
|
2828
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
2829
|
+
return safe10(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
|
|
3222
2830
|
}
|
|
3223
2831
|
};
|
|
3224
2832
|
|
|
@@ -3237,30 +2845,16 @@ async function safe11(promise) {
|
|
|
3237
2845
|
return err(toCimplifyError11(error));
|
|
3238
2846
|
}
|
|
3239
2847
|
}
|
|
3240
|
-
async function safeWithFallback7(primary, fallback) {
|
|
3241
|
-
const primaryResult = await safe11(primary());
|
|
3242
|
-
if (primaryResult.ok) return primaryResult;
|
|
3243
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
3244
|
-
return primaryResult;
|
|
3245
|
-
}
|
|
3246
|
-
return safe11(fallback());
|
|
3247
|
-
}
|
|
3248
2848
|
var FxService = class {
|
|
3249
2849
|
constructor(client) {
|
|
3250
2850
|
this.client = client;
|
|
3251
2851
|
}
|
|
3252
2852
|
async getRate(from, to) {
|
|
3253
2853
|
const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
|
|
3254
|
-
return
|
|
3255
|
-
() => this.client.get(path),
|
|
3256
|
-
() => this.client.call("fx.getRate", { from, to })
|
|
3257
|
-
);
|
|
2854
|
+
return safe11(this.client.get(path));
|
|
3258
2855
|
}
|
|
3259
2856
|
async lockQuote(request) {
|
|
3260
|
-
return
|
|
3261
|
-
() => this.client.post("/api/v1/fx/quotes", request),
|
|
3262
|
-
() => this.client.call("fx.lockQuote", request)
|
|
3263
|
-
);
|
|
2857
|
+
return safe11(this.client.post("/api/v1/fx/quotes", request));
|
|
3264
2858
|
}
|
|
3265
2859
|
};
|
|
3266
2860
|
|
|
@@ -3832,6 +3426,7 @@ function createElements(client, businessId, options) {
|
|
|
3832
3426
|
|
|
3833
3427
|
// src/client.ts
|
|
3834
3428
|
var ACCESS_TOKEN_STORAGE_KEY = "cimplify_access_token";
|
|
3429
|
+
var ORDER_TOKEN_PREFIX = "cimplify_ot_";
|
|
3835
3430
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
3836
3431
|
var DEFAULT_MAX_RETRIES = 3;
|
|
3837
3432
|
var DEFAULT_RETRY_DELAY_MS = 1e3;
|
|
@@ -3973,7 +3568,29 @@ var CimplifyClient = class {
|
|
|
3973
3568
|
source: "clear"
|
|
3974
3569
|
});
|
|
3975
3570
|
}
|
|
3976
|
-
|
|
3571
|
+
setOrderToken(orderId, token) {
|
|
3572
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
3573
|
+
localStorage.setItem(`${ORDER_TOKEN_PREFIX}${orderId}`, token);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
getOrderToken(orderId) {
|
|
3577
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
3578
|
+
return localStorage.getItem(`${ORDER_TOKEN_PREFIX}${orderId}`);
|
|
3579
|
+
}
|
|
3580
|
+
return null;
|
|
3581
|
+
}
|
|
3582
|
+
clearOrderTokens() {
|
|
3583
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
3584
|
+
const keysToRemove = [];
|
|
3585
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
3586
|
+
const key = localStorage.key(i);
|
|
3587
|
+
if (key?.startsWith(ORDER_TOKEN_PREFIX)) {
|
|
3588
|
+
keysToRemove.push(key);
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
keysToRemove.forEach((k) => localStorage.removeItem(k));
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3977
3594
|
setLocationId(locationId) {
|
|
3978
3595
|
if (locationId) {
|
|
3979
3596
|
this.context.location_id = locationId;
|
|
@@ -4174,41 +3791,6 @@ var CimplifyClient = class {
|
|
|
4174
3791
|
this.inflightRequests.set(key, request);
|
|
4175
3792
|
return request;
|
|
4176
3793
|
}
|
|
4177
|
-
async query(query, variables) {
|
|
4178
|
-
const body = { query };
|
|
4179
|
-
if (variables) {
|
|
4180
|
-
body.variables = variables;
|
|
4181
|
-
}
|
|
4182
|
-
if (Object.keys(this.context).length > 0) {
|
|
4183
|
-
body.context = this.context;
|
|
4184
|
-
}
|
|
4185
|
-
const key = this.getDedupeKey("query", body);
|
|
4186
|
-
return this.deduplicatedRequest(key, async () => {
|
|
4187
|
-
const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
|
|
4188
|
-
method: "POST",
|
|
4189
|
-
credentials: this.credentials,
|
|
4190
|
-
headers: this.getHeaders(),
|
|
4191
|
-
body: JSON.stringify(body)
|
|
4192
|
-
});
|
|
4193
|
-
return this.handleResponse(response);
|
|
4194
|
-
});
|
|
4195
|
-
}
|
|
4196
|
-
async call(method, args) {
|
|
4197
|
-
const body = {
|
|
4198
|
-
method,
|
|
4199
|
-
args: args !== void 0 ? [args] : []
|
|
4200
|
-
};
|
|
4201
|
-
if (Object.keys(this.context).length > 0) {
|
|
4202
|
-
body.context = this.context;
|
|
4203
|
-
}
|
|
4204
|
-
const response = await this.resilientFetch(`${this.baseUrl}/api/m`, {
|
|
4205
|
-
method: "POST",
|
|
4206
|
-
credentials: this.credentials,
|
|
4207
|
-
headers: this.getHeaders(),
|
|
4208
|
-
body: JSON.stringify(body)
|
|
4209
|
-
});
|
|
4210
|
-
return this.handleResponse(response);
|
|
4211
|
-
}
|
|
4212
3794
|
async get(path) {
|
|
4213
3795
|
const key = this.getDedupeKey("get", path);
|
|
4214
3796
|
return this.deduplicatedRequest(key, async () => {
|
|
@@ -4311,26 +3893,6 @@ var CimplifyClient = class {
|
|
|
4311
3893
|
}
|
|
4312
3894
|
return json;
|
|
4313
3895
|
}
|
|
4314
|
-
async handleResponse(response) {
|
|
4315
|
-
const json = await response.json();
|
|
4316
|
-
if (!json.success || json.error) {
|
|
4317
|
-
const error = enrichError(
|
|
4318
|
-
new CimplifyError(
|
|
4319
|
-
json.error?.code || "UNKNOWN_ERROR",
|
|
4320
|
-
json.error?.message || "An unknown error occurred",
|
|
4321
|
-
json.error?.retryable || false
|
|
4322
|
-
),
|
|
4323
|
-
{ isTestMode: this.isTestMode() }
|
|
4324
|
-
);
|
|
4325
|
-
if (response.status === 401 || error.code === ErrorCode.UNAUTHORIZED) {
|
|
4326
|
-
console.warn(
|
|
4327
|
-
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
4328
|
-
);
|
|
4329
|
-
}
|
|
4330
|
-
throw error;
|
|
4331
|
-
}
|
|
4332
|
-
return json.data;
|
|
4333
|
-
}
|
|
4334
3896
|
get catalogue() {
|
|
4335
3897
|
if (!this._catalogue) {
|
|
4336
3898
|
this._catalogue = new CatalogueQueries(this);
|