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