@cimplify/sdk 0.3.0 → 0.3.2
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/index.d.mts +393 -262
- package/dist/index.d.ts +393 -262
- package/dist/index.js +548 -299
- package/dist/index.mjs +548 -299
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -66,7 +66,91 @@ function isRetryableError(error) {
|
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// src/types/result.ts
|
|
70
|
+
function ok(value) {
|
|
71
|
+
return { ok: true, value };
|
|
72
|
+
}
|
|
73
|
+
function err(error) {
|
|
74
|
+
return { ok: false, error };
|
|
75
|
+
}
|
|
76
|
+
function isOk(result) {
|
|
77
|
+
return result.ok === true;
|
|
78
|
+
}
|
|
79
|
+
function isErr(result) {
|
|
80
|
+
return result.ok === false;
|
|
81
|
+
}
|
|
82
|
+
function mapResult(result, fn) {
|
|
83
|
+
return result.ok ? ok(fn(result.value)) : result;
|
|
84
|
+
}
|
|
85
|
+
function mapError(result, fn) {
|
|
86
|
+
return result.ok ? result : err(fn(result.error));
|
|
87
|
+
}
|
|
88
|
+
function flatMap(result, fn) {
|
|
89
|
+
return result.ok ? fn(result.value) : result;
|
|
90
|
+
}
|
|
91
|
+
function getOrElse(result, defaultFn) {
|
|
92
|
+
return result.ok ? result.value : defaultFn();
|
|
93
|
+
}
|
|
94
|
+
function unwrap(result) {
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
return result.value;
|
|
97
|
+
}
|
|
98
|
+
throw result.error;
|
|
99
|
+
}
|
|
100
|
+
function toNullable(result) {
|
|
101
|
+
return result.ok ? result.value : void 0;
|
|
102
|
+
}
|
|
103
|
+
async function fromPromise(promise, mapError2) {
|
|
104
|
+
try {
|
|
105
|
+
const value = await promise;
|
|
106
|
+
return ok(value);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return err(mapError2(error));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function tryCatch(fn, mapError2) {
|
|
112
|
+
try {
|
|
113
|
+
return ok(fn());
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return err(mapError2(error));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function combine(results) {
|
|
119
|
+
const values = [];
|
|
120
|
+
for (const result of results) {
|
|
121
|
+
if (!result.ok) {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
values.push(result.value);
|
|
125
|
+
}
|
|
126
|
+
return ok(values);
|
|
127
|
+
}
|
|
128
|
+
function combineObject(results) {
|
|
129
|
+
const values = {};
|
|
130
|
+
for (const [key, result] of Object.entries(results)) {
|
|
131
|
+
if (!result.ok) {
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
values[key] = result.value;
|
|
135
|
+
}
|
|
136
|
+
return ok(values);
|
|
137
|
+
}
|
|
138
|
+
|
|
69
139
|
// src/catalogue.ts
|
|
140
|
+
function toCimplifyError(error) {
|
|
141
|
+
if (error instanceof CimplifyError) return error;
|
|
142
|
+
if (error instanceof Error) {
|
|
143
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
144
|
+
}
|
|
145
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
146
|
+
}
|
|
147
|
+
async function safe(promise) {
|
|
148
|
+
try {
|
|
149
|
+
return ok(await promise);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return err(toCimplifyError(error));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
70
154
|
var CatalogueQueries = class {
|
|
71
155
|
constructor(client) {
|
|
72
156
|
this.client = client;
|
|
@@ -107,111 +191,125 @@ var CatalogueQueries = class {
|
|
|
107
191
|
if (options?.offset) {
|
|
108
192
|
query2 += `#offset(${options.offset})`;
|
|
109
193
|
}
|
|
110
|
-
return this.client.query(query2);
|
|
194
|
+
return safe(this.client.query(query2));
|
|
111
195
|
}
|
|
112
196
|
async getProduct(id) {
|
|
113
|
-
return this.client.query(`products.${id}`);
|
|
197
|
+
return safe(this.client.query(`products.${id}`));
|
|
114
198
|
}
|
|
115
199
|
async getProductBySlug(slug) {
|
|
116
|
-
const
|
|
117
|
-
`products[?(@.slug=='${slug}')]`
|
|
200
|
+
const result = await safe(
|
|
201
|
+
this.client.query(`products[?(@.slug=='${slug}')]`)
|
|
118
202
|
);
|
|
119
|
-
if (!
|
|
120
|
-
|
|
203
|
+
if (!result.ok) return result;
|
|
204
|
+
if (!result.value.length) {
|
|
205
|
+
return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
|
|
121
206
|
}
|
|
122
|
-
return
|
|
207
|
+
return ok(result.value[0]);
|
|
123
208
|
}
|
|
124
209
|
// --------------------------------------------------------------------------
|
|
125
210
|
// VARIANTS
|
|
126
211
|
// --------------------------------------------------------------------------
|
|
127
212
|
async getVariants(productId) {
|
|
128
|
-
return this.client.query(`products.${productId}.variants`);
|
|
213
|
+
return safe(this.client.query(`products.${productId}.variants`));
|
|
129
214
|
}
|
|
130
215
|
async getVariantAxes(productId) {
|
|
131
|
-
return this.client.query(`products.${productId}.variant_axes`);
|
|
216
|
+
return safe(this.client.query(`products.${productId}.variant_axes`));
|
|
132
217
|
}
|
|
133
218
|
/**
|
|
134
219
|
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
135
220
|
* Returns the matching variant or null if no match found.
|
|
136
221
|
*/
|
|
137
222
|
async getVariantByAxisSelections(productId, selections) {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
223
|
+
return safe(
|
|
224
|
+
this.client.query(`products.${productId}.variant`, {
|
|
225
|
+
axis_selections: selections
|
|
226
|
+
})
|
|
227
|
+
);
|
|
141
228
|
}
|
|
142
229
|
/**
|
|
143
230
|
* Get a specific variant by its ID
|
|
144
231
|
*/
|
|
145
232
|
async getVariantById(productId, variantId) {
|
|
146
|
-
return this.client.query(`products.${productId}.variant.${variantId}`);
|
|
233
|
+
return safe(this.client.query(`products.${productId}.variant.${variantId}`));
|
|
147
234
|
}
|
|
148
235
|
// --------------------------------------------------------------------------
|
|
149
236
|
// ADD-ONS
|
|
150
237
|
// --------------------------------------------------------------------------
|
|
151
238
|
async getAddOns(productId) {
|
|
152
|
-
return this.client.query(`products.${productId}.add_ons`);
|
|
239
|
+
return safe(this.client.query(`products.${productId}.add_ons`));
|
|
153
240
|
}
|
|
154
241
|
// --------------------------------------------------------------------------
|
|
155
242
|
// CATEGORIES
|
|
156
243
|
// --------------------------------------------------------------------------
|
|
157
244
|
async getCategories() {
|
|
158
|
-
return this.client.query("categories");
|
|
245
|
+
return safe(this.client.query("categories"));
|
|
159
246
|
}
|
|
160
247
|
async getCategory(id) {
|
|
161
|
-
return this.client.query(`categories.${id}`);
|
|
248
|
+
return safe(this.client.query(`categories.${id}`));
|
|
162
249
|
}
|
|
163
250
|
async getCategoryBySlug(slug) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
251
|
+
const result = await safe(
|
|
252
|
+
this.client.query(`categories[?(@.slug=='${slug}')]`)
|
|
253
|
+
);
|
|
254
|
+
if (!result.ok) return result;
|
|
255
|
+
if (!result.value.length) {
|
|
256
|
+
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
167
257
|
}
|
|
168
|
-
return
|
|
258
|
+
return ok(result.value[0]);
|
|
169
259
|
}
|
|
170
260
|
async getCategoryProducts(categoryId) {
|
|
171
|
-
return this.client.query(`products[?(@.category_id=='${categoryId}')]`);
|
|
261
|
+
return safe(this.client.query(`products[?(@.category_id=='${categoryId}')]`));
|
|
172
262
|
}
|
|
173
263
|
// --------------------------------------------------------------------------
|
|
174
264
|
// COLLECTIONS
|
|
175
265
|
// --------------------------------------------------------------------------
|
|
176
266
|
async getCollections() {
|
|
177
|
-
return this.client.query("collections");
|
|
267
|
+
return safe(this.client.query("collections"));
|
|
178
268
|
}
|
|
179
269
|
async getCollection(id) {
|
|
180
|
-
return this.client.query(`collections.${id}`);
|
|
270
|
+
return safe(this.client.query(`collections.${id}`));
|
|
181
271
|
}
|
|
182
272
|
async getCollectionBySlug(slug) {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
273
|
+
const result = await safe(
|
|
274
|
+
this.client.query(`collections[?(@.slug=='${slug}')]`)
|
|
275
|
+
);
|
|
276
|
+
if (!result.ok) return result;
|
|
277
|
+
if (!result.value.length) {
|
|
278
|
+
return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
|
|
186
279
|
}
|
|
187
|
-
return
|
|
280
|
+
return ok(result.value[0]);
|
|
188
281
|
}
|
|
189
282
|
async getCollectionProducts(collectionId) {
|
|
190
|
-
return this.client.query(`collections.${collectionId}.products`);
|
|
283
|
+
return safe(this.client.query(`collections.${collectionId}.products`));
|
|
191
284
|
}
|
|
192
285
|
async searchCollections(query2, limit = 20) {
|
|
193
|
-
return
|
|
194
|
-
`collections[?(@.name contains '${query2}')]#limit(${limit})`
|
|
286
|
+
return safe(
|
|
287
|
+
this.client.query(`collections[?(@.name contains '${query2}')]#limit(${limit})`)
|
|
195
288
|
);
|
|
196
289
|
}
|
|
197
290
|
// --------------------------------------------------------------------------
|
|
198
291
|
// BUNDLES
|
|
199
292
|
// --------------------------------------------------------------------------
|
|
200
293
|
async getBundles() {
|
|
201
|
-
return this.client.query("bundles");
|
|
294
|
+
return safe(this.client.query("bundles"));
|
|
202
295
|
}
|
|
203
296
|
async getBundle(id) {
|
|
204
|
-
return this.client.query(`bundles.${id}`);
|
|
297
|
+
return safe(this.client.query(`bundles.${id}`));
|
|
205
298
|
}
|
|
206
299
|
async getBundleBySlug(slug) {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
300
|
+
const result = await safe(
|
|
301
|
+
this.client.query(`bundles[?(@.slug=='${slug}')]`)
|
|
302
|
+
);
|
|
303
|
+
if (!result.ok) return result;
|
|
304
|
+
if (!result.value.length) {
|
|
305
|
+
return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
|
|
210
306
|
}
|
|
211
|
-
return
|
|
307
|
+
return ok(result.value[0]);
|
|
212
308
|
}
|
|
213
309
|
async searchBundles(query2, limit = 20) {
|
|
214
|
-
return
|
|
310
|
+
return safe(
|
|
311
|
+
this.client.query(`bundles[?(@.name contains '${query2}')]#limit(${limit})`)
|
|
312
|
+
);
|
|
215
313
|
}
|
|
216
314
|
// --------------------------------------------------------------------------
|
|
217
315
|
// COMPOSITES (Build-Your-Own)
|
|
@@ -221,20 +319,22 @@ var CatalogueQueries = class {
|
|
|
221
319
|
if (options?.limit) {
|
|
222
320
|
query2 += `#limit(${options.limit})`;
|
|
223
321
|
}
|
|
224
|
-
return this.client.query(query2);
|
|
322
|
+
return safe(this.client.query(query2));
|
|
225
323
|
}
|
|
226
324
|
async getComposite(id) {
|
|
227
|
-
return this.client.query(`composites.${id}`);
|
|
325
|
+
return safe(this.client.query(`composites.${id}`));
|
|
228
326
|
}
|
|
229
327
|
async getCompositeByProductId(productId) {
|
|
230
|
-
return this.client.query(`composites.by_product.${productId}`);
|
|
328
|
+
return safe(this.client.query(`composites.by_product.${productId}`));
|
|
231
329
|
}
|
|
232
330
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
331
|
+
return safe(
|
|
332
|
+
this.client.call("composite.calculatePrice", {
|
|
333
|
+
composite_id: compositeId,
|
|
334
|
+
selections,
|
|
335
|
+
location_id: locationId
|
|
336
|
+
})
|
|
337
|
+
);
|
|
238
338
|
}
|
|
239
339
|
// --------------------------------------------------------------------------
|
|
240
340
|
// SEARCH
|
|
@@ -246,14 +346,16 @@ var CatalogueQueries = class {
|
|
|
246
346
|
searchQuery = `products[?(@.name contains '${query2}' && @.category_id=='${options.category}')]`;
|
|
247
347
|
}
|
|
248
348
|
searchQuery += `#limit(${limit})`;
|
|
249
|
-
return this.client.query(searchQuery);
|
|
349
|
+
return safe(this.client.query(searchQuery));
|
|
250
350
|
}
|
|
251
351
|
async searchProducts(query2, options) {
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
352
|
+
return safe(
|
|
353
|
+
this.client.call("catalogue.search", {
|
|
354
|
+
query: query2,
|
|
355
|
+
limit: options?.limit ?? 20,
|
|
356
|
+
category: options?.category
|
|
357
|
+
})
|
|
358
|
+
);
|
|
257
359
|
}
|
|
258
360
|
// --------------------------------------------------------------------------
|
|
259
361
|
// MENU (Restaurant-specific)
|
|
@@ -266,99 +368,29 @@ var CatalogueQueries = class {
|
|
|
266
368
|
if (options?.limit) {
|
|
267
369
|
query2 += `#limit(${options.limit})`;
|
|
268
370
|
}
|
|
269
|
-
return this.client.query(query2);
|
|
371
|
+
return safe(this.client.query(query2));
|
|
270
372
|
}
|
|
271
373
|
async getMenuCategory(categoryId) {
|
|
272
|
-
return this.client.query(`menu.category.${categoryId}`);
|
|
374
|
+
return safe(this.client.query(`menu.category.${categoryId}`));
|
|
273
375
|
}
|
|
274
376
|
async getMenuItem(itemId) {
|
|
275
|
-
return this.client.query(`menu.${itemId}`);
|
|
377
|
+
return safe(this.client.query(`menu.${itemId}`));
|
|
276
378
|
}
|
|
277
379
|
};
|
|
278
380
|
|
|
279
|
-
// src/types/result.ts
|
|
280
|
-
function ok(value) {
|
|
281
|
-
return { ok: true, value };
|
|
282
|
-
}
|
|
283
|
-
function err(error) {
|
|
284
|
-
return { ok: false, error };
|
|
285
|
-
}
|
|
286
|
-
function isOk(result) {
|
|
287
|
-
return result.ok === true;
|
|
288
|
-
}
|
|
289
|
-
function isErr(result) {
|
|
290
|
-
return result.ok === false;
|
|
291
|
-
}
|
|
292
|
-
function mapResult(result, fn) {
|
|
293
|
-
return result.ok ? ok(fn(result.value)) : result;
|
|
294
|
-
}
|
|
295
|
-
function mapError(result, fn) {
|
|
296
|
-
return result.ok ? result : err(fn(result.error));
|
|
297
|
-
}
|
|
298
|
-
function flatMap(result, fn) {
|
|
299
|
-
return result.ok ? fn(result.value) : result;
|
|
300
|
-
}
|
|
301
|
-
function getOrElse(result, defaultFn) {
|
|
302
|
-
return result.ok ? result.value : defaultFn();
|
|
303
|
-
}
|
|
304
|
-
function unwrap(result) {
|
|
305
|
-
if (result.ok) {
|
|
306
|
-
return result.value;
|
|
307
|
-
}
|
|
308
|
-
throw result.error;
|
|
309
|
-
}
|
|
310
|
-
function toNullable(result) {
|
|
311
|
-
return result.ok ? result.value : void 0;
|
|
312
|
-
}
|
|
313
|
-
async function fromPromise(promise, mapError2) {
|
|
314
|
-
try {
|
|
315
|
-
const value = await promise;
|
|
316
|
-
return ok(value);
|
|
317
|
-
} catch (error) {
|
|
318
|
-
return err(mapError2(error));
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function tryCatch(fn, mapError2) {
|
|
322
|
-
try {
|
|
323
|
-
return ok(fn());
|
|
324
|
-
} catch (error) {
|
|
325
|
-
return err(mapError2(error));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
function combine(results) {
|
|
329
|
-
const values = [];
|
|
330
|
-
for (const result of results) {
|
|
331
|
-
if (!result.ok) {
|
|
332
|
-
return result;
|
|
333
|
-
}
|
|
334
|
-
values.push(result.value);
|
|
335
|
-
}
|
|
336
|
-
return ok(values);
|
|
337
|
-
}
|
|
338
|
-
function combineObject(results) {
|
|
339
|
-
const values = {};
|
|
340
|
-
for (const [key, result] of Object.entries(results)) {
|
|
341
|
-
if (!result.ok) {
|
|
342
|
-
return result;
|
|
343
|
-
}
|
|
344
|
-
values[key] = result.value;
|
|
345
|
-
}
|
|
346
|
-
return ok(values);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
381
|
// src/cart.ts
|
|
350
|
-
function
|
|
382
|
+
function toCimplifyError2(error) {
|
|
351
383
|
if (error instanceof CimplifyError) return error;
|
|
352
384
|
if (error instanceof Error) {
|
|
353
385
|
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
354
386
|
}
|
|
355
387
|
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
356
388
|
}
|
|
357
|
-
async function
|
|
389
|
+
async function safe2(promise) {
|
|
358
390
|
try {
|
|
359
391
|
return ok(await promise);
|
|
360
392
|
} catch (error) {
|
|
361
|
-
return err(
|
|
393
|
+
return err(toCimplifyError2(error));
|
|
362
394
|
}
|
|
363
395
|
}
|
|
364
396
|
var CartOperations = class {
|
|
@@ -373,19 +405,19 @@ var CartOperations = class {
|
|
|
373
405
|
* This is the main method for storefront display.
|
|
374
406
|
*/
|
|
375
407
|
async get() {
|
|
376
|
-
return
|
|
408
|
+
return safe2(this.client.query("cart#enriched"));
|
|
377
409
|
}
|
|
378
410
|
async getRaw() {
|
|
379
|
-
return
|
|
411
|
+
return safe2(this.client.query("cart"));
|
|
380
412
|
}
|
|
381
413
|
async getItems() {
|
|
382
|
-
return
|
|
414
|
+
return safe2(this.client.query("cart_items"));
|
|
383
415
|
}
|
|
384
416
|
async getCount() {
|
|
385
|
-
return
|
|
417
|
+
return safe2(this.client.query("cart#count"));
|
|
386
418
|
}
|
|
387
419
|
async getTotal() {
|
|
388
|
-
return
|
|
420
|
+
return safe2(this.client.query("cart#total"));
|
|
389
421
|
}
|
|
390
422
|
async getSummary() {
|
|
391
423
|
const cartResult = await this.get();
|
|
@@ -429,10 +461,10 @@ var CartOperations = class {
|
|
|
429
461
|
* ```
|
|
430
462
|
*/
|
|
431
463
|
async addItem(input) {
|
|
432
|
-
return
|
|
464
|
+
return safe2(this.client.call("cart.addItem", input));
|
|
433
465
|
}
|
|
434
466
|
async updateItem(cartItemId, updates) {
|
|
435
|
-
return
|
|
467
|
+
return safe2(
|
|
436
468
|
this.client.call("cart.updateItem", {
|
|
437
469
|
cart_item_id: cartItemId,
|
|
438
470
|
...updates
|
|
@@ -440,7 +472,7 @@ var CartOperations = class {
|
|
|
440
472
|
);
|
|
441
473
|
}
|
|
442
474
|
async updateQuantity(cartItemId, quantity) {
|
|
443
|
-
return
|
|
475
|
+
return safe2(
|
|
444
476
|
this.client.call("cart.updateItemQuantity", {
|
|
445
477
|
cart_item_id: cartItemId,
|
|
446
478
|
quantity
|
|
@@ -448,27 +480,27 @@ var CartOperations = class {
|
|
|
448
480
|
);
|
|
449
481
|
}
|
|
450
482
|
async removeItem(cartItemId) {
|
|
451
|
-
return
|
|
483
|
+
return safe2(
|
|
452
484
|
this.client.call("cart.removeItem", {
|
|
453
485
|
cart_item_id: cartItemId
|
|
454
486
|
})
|
|
455
487
|
);
|
|
456
488
|
}
|
|
457
489
|
async clear() {
|
|
458
|
-
return
|
|
490
|
+
return safe2(this.client.call("cart.clearCart"));
|
|
459
491
|
}
|
|
460
492
|
// --------------------------------------------------------------------------
|
|
461
493
|
// COUPONS & DISCOUNTS
|
|
462
494
|
// --------------------------------------------------------------------------
|
|
463
495
|
async applyCoupon(code) {
|
|
464
|
-
return
|
|
496
|
+
return safe2(
|
|
465
497
|
this.client.call("cart.applyCoupon", {
|
|
466
498
|
coupon_code: code
|
|
467
499
|
})
|
|
468
500
|
);
|
|
469
501
|
}
|
|
470
502
|
async removeCoupon() {
|
|
471
|
-
return
|
|
503
|
+
return safe2(this.client.call("cart.removeCoupon"));
|
|
472
504
|
}
|
|
473
505
|
// --------------------------------------------------------------------------
|
|
474
506
|
// CONVENIENCE METHODS
|
|
@@ -599,18 +631,18 @@ var DEFAULT_CURRENCY = "GHS";
|
|
|
599
631
|
var DEFAULT_COUNTRY = "GHA";
|
|
600
632
|
|
|
601
633
|
// src/checkout.ts
|
|
602
|
-
function
|
|
634
|
+
function toCimplifyError3(error) {
|
|
603
635
|
if (error instanceof CimplifyError) return error;
|
|
604
636
|
if (error instanceof Error) {
|
|
605
637
|
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
606
638
|
}
|
|
607
639
|
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
608
640
|
}
|
|
609
|
-
async function
|
|
641
|
+
async function safe3(promise) {
|
|
610
642
|
try {
|
|
611
643
|
return ok(await promise);
|
|
612
644
|
} catch (error) {
|
|
613
|
-
return err(
|
|
645
|
+
return err(toCimplifyError3(error));
|
|
614
646
|
}
|
|
615
647
|
}
|
|
616
648
|
var CheckoutService = class {
|
|
@@ -643,14 +675,14 @@ var CheckoutService = class {
|
|
|
643
675
|
* ```
|
|
644
676
|
*/
|
|
645
677
|
async process(data) {
|
|
646
|
-
return
|
|
678
|
+
return safe3(
|
|
647
679
|
this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
648
680
|
checkout_data: data
|
|
649
681
|
})
|
|
650
682
|
);
|
|
651
683
|
}
|
|
652
684
|
async initializePayment(orderId, method) {
|
|
653
|
-
return
|
|
685
|
+
return safe3(
|
|
654
686
|
this.client.call("order.initializePayment", {
|
|
655
687
|
order_id: orderId,
|
|
656
688
|
payment_method: method
|
|
@@ -658,17 +690,17 @@ var CheckoutService = class {
|
|
|
658
690
|
);
|
|
659
691
|
}
|
|
660
692
|
async submitAuthorization(input) {
|
|
661
|
-
return
|
|
693
|
+
return safe3(
|
|
662
694
|
this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
663
695
|
);
|
|
664
696
|
}
|
|
665
697
|
async pollPaymentStatus(orderId) {
|
|
666
|
-
return
|
|
698
|
+
return safe3(
|
|
667
699
|
this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
668
700
|
);
|
|
669
701
|
}
|
|
670
702
|
async updateOrderCustomer(orderId, customer) {
|
|
671
|
-
return
|
|
703
|
+
return safe3(
|
|
672
704
|
this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
673
705
|
order_id: orderId,
|
|
674
706
|
...customer
|
|
@@ -676,7 +708,7 @@ var CheckoutService = class {
|
|
|
676
708
|
);
|
|
677
709
|
}
|
|
678
710
|
async verifyPayment(orderId) {
|
|
679
|
-
return
|
|
711
|
+
return safe3(
|
|
680
712
|
this.client.call("order.verifyPayment", {
|
|
681
713
|
order_id: orderId
|
|
682
714
|
})
|
|
@@ -685,6 +717,20 @@ var CheckoutService = class {
|
|
|
685
717
|
};
|
|
686
718
|
|
|
687
719
|
// src/orders.ts
|
|
720
|
+
function toCimplifyError4(error) {
|
|
721
|
+
if (error instanceof CimplifyError) return error;
|
|
722
|
+
if (error instanceof Error) {
|
|
723
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
724
|
+
}
|
|
725
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
726
|
+
}
|
|
727
|
+
async function safe4(promise) {
|
|
728
|
+
try {
|
|
729
|
+
return ok(await promise);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
return err(toCimplifyError4(error));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
688
734
|
var OrderQueries = class {
|
|
689
735
|
constructor(client) {
|
|
690
736
|
this.client = client;
|
|
@@ -701,38 +747,40 @@ var OrderQueries = class {
|
|
|
701
747
|
if (options?.offset) {
|
|
702
748
|
query2 += `#offset(${options.offset})`;
|
|
703
749
|
}
|
|
704
|
-
return this.client.query(query2);
|
|
750
|
+
return safe4(this.client.query(query2));
|
|
705
751
|
}
|
|
706
752
|
async get(orderId) {
|
|
707
|
-
return this.client.query(`orders.${orderId}`);
|
|
753
|
+
return safe4(this.client.query(`orders.${orderId}`));
|
|
708
754
|
}
|
|
709
755
|
async getRecent(limit = 5) {
|
|
710
|
-
return this.client.query(`orders#sort(created_at,desc)#limit(${limit})`);
|
|
756
|
+
return safe4(this.client.query(`orders#sort(created_at,desc)#limit(${limit})`));
|
|
711
757
|
}
|
|
712
758
|
async getByStatus(status) {
|
|
713
|
-
return this.client.query(`orders[?(@.status=='${status}')]`);
|
|
759
|
+
return safe4(this.client.query(`orders[?(@.status=='${status}')]`));
|
|
714
760
|
}
|
|
715
761
|
async cancel(orderId, reason) {
|
|
716
|
-
return
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
762
|
+
return safe4(
|
|
763
|
+
this.client.call("order.cancelOrder", {
|
|
764
|
+
order_id: orderId,
|
|
765
|
+
reason
|
|
766
|
+
})
|
|
767
|
+
);
|
|
720
768
|
}
|
|
721
769
|
};
|
|
722
770
|
|
|
723
771
|
// src/link.ts
|
|
724
|
-
function
|
|
772
|
+
function toCimplifyError5(error) {
|
|
725
773
|
if (error instanceof CimplifyError) return error;
|
|
726
774
|
if (error instanceof Error) {
|
|
727
775
|
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
728
776
|
}
|
|
729
777
|
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
730
778
|
}
|
|
731
|
-
async function
|
|
779
|
+
async function safe5(promise) {
|
|
732
780
|
try {
|
|
733
781
|
return ok(await promise);
|
|
734
782
|
} catch (error) {
|
|
735
|
-
return err(
|
|
783
|
+
return err(toCimplifyError5(error));
|
|
736
784
|
}
|
|
737
785
|
}
|
|
738
786
|
var LinkService = class {
|
|
@@ -743,10 +791,10 @@ var LinkService = class {
|
|
|
743
791
|
// AUTHENTICATION
|
|
744
792
|
// --------------------------------------------------------------------------
|
|
745
793
|
async requestOtp(input) {
|
|
746
|
-
return
|
|
794
|
+
return safe5(this.client.linkPost("/v1/link/auth/request-otp", input));
|
|
747
795
|
}
|
|
748
796
|
async verifyOtp(input) {
|
|
749
|
-
const result = await
|
|
797
|
+
const result = await safe5(
|
|
750
798
|
this.client.linkPost("/v1/link/auth/verify-otp", input)
|
|
751
799
|
);
|
|
752
800
|
if (result.ok && result.value.session_token) {
|
|
@@ -755,7 +803,7 @@ var LinkService = class {
|
|
|
755
803
|
return result;
|
|
756
804
|
}
|
|
757
805
|
async logout() {
|
|
758
|
-
const result = await
|
|
806
|
+
const result = await safe5(this.client.linkPost("/v1/link/auth/logout"));
|
|
759
807
|
if (result.ok) {
|
|
760
808
|
this.client.clearSession();
|
|
761
809
|
}
|
|
@@ -765,32 +813,32 @@ var LinkService = class {
|
|
|
765
813
|
// STATUS & DATA
|
|
766
814
|
// --------------------------------------------------------------------------
|
|
767
815
|
async checkStatus(contact) {
|
|
768
|
-
return
|
|
816
|
+
return safe5(
|
|
769
817
|
this.client.call(LINK_MUTATION.CHECK_STATUS, {
|
|
770
818
|
contact
|
|
771
819
|
})
|
|
772
820
|
);
|
|
773
821
|
}
|
|
774
822
|
async getLinkData() {
|
|
775
|
-
return
|
|
823
|
+
return safe5(this.client.query(LINK_QUERY.DATA));
|
|
776
824
|
}
|
|
777
825
|
async getAddresses() {
|
|
778
|
-
return
|
|
826
|
+
return safe5(this.client.query(LINK_QUERY.ADDRESSES));
|
|
779
827
|
}
|
|
780
828
|
async getMobileMoney() {
|
|
781
|
-
return
|
|
829
|
+
return safe5(this.client.query(LINK_QUERY.MOBILE_MONEY));
|
|
782
830
|
}
|
|
783
831
|
async getPreferences() {
|
|
784
|
-
return
|
|
832
|
+
return safe5(this.client.query(LINK_QUERY.PREFERENCES));
|
|
785
833
|
}
|
|
786
834
|
// --------------------------------------------------------------------------
|
|
787
835
|
// ENROLLMENT
|
|
788
836
|
// --------------------------------------------------------------------------
|
|
789
837
|
async enroll(data) {
|
|
790
|
-
return
|
|
838
|
+
return safe5(this.client.call(LINK_MUTATION.ENROLL, data));
|
|
791
839
|
}
|
|
792
840
|
async enrollAndLinkOrder(data) {
|
|
793
|
-
return
|
|
841
|
+
return safe5(
|
|
794
842
|
this.client.call(LINK_MUTATION.ENROLL_AND_LINK_ORDER, data)
|
|
795
843
|
);
|
|
796
844
|
}
|
|
@@ -798,25 +846,25 @@ var LinkService = class {
|
|
|
798
846
|
// PREFERENCES
|
|
799
847
|
// --------------------------------------------------------------------------
|
|
800
848
|
async updatePreferences(preferences) {
|
|
801
|
-
return
|
|
849
|
+
return safe5(this.client.call(LINK_MUTATION.UPDATE_PREFERENCES, preferences));
|
|
802
850
|
}
|
|
803
851
|
// --------------------------------------------------------------------------
|
|
804
852
|
// ADDRESSES
|
|
805
853
|
// --------------------------------------------------------------------------
|
|
806
854
|
async createAddress(input) {
|
|
807
|
-
return
|
|
855
|
+
return safe5(this.client.call(LINK_MUTATION.CREATE_ADDRESS, input));
|
|
808
856
|
}
|
|
809
857
|
async updateAddress(input) {
|
|
810
|
-
return
|
|
858
|
+
return safe5(this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input));
|
|
811
859
|
}
|
|
812
860
|
async deleteAddress(addressId) {
|
|
813
|
-
return
|
|
861
|
+
return safe5(this.client.call(LINK_MUTATION.DELETE_ADDRESS, addressId));
|
|
814
862
|
}
|
|
815
863
|
async setDefaultAddress(addressId) {
|
|
816
|
-
return
|
|
864
|
+
return safe5(this.client.call(LINK_MUTATION.SET_DEFAULT_ADDRESS, addressId));
|
|
817
865
|
}
|
|
818
866
|
async trackAddressUsage(addressId) {
|
|
819
|
-
return
|
|
867
|
+
return safe5(
|
|
820
868
|
this.client.call(LINK_MUTATION.TRACK_ADDRESS_USAGE, {
|
|
821
869
|
address_id: addressId
|
|
822
870
|
})
|
|
@@ -826,25 +874,25 @@ var LinkService = class {
|
|
|
826
874
|
// MOBILE MONEY
|
|
827
875
|
// --------------------------------------------------------------------------
|
|
828
876
|
async createMobileMoney(input) {
|
|
829
|
-
return
|
|
877
|
+
return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
|
|
830
878
|
}
|
|
831
879
|
async deleteMobileMoney(mobileMoneyId) {
|
|
832
|
-
return
|
|
880
|
+
return safe5(this.client.call(LINK_MUTATION.DELETE_MOBILE_MONEY, mobileMoneyId));
|
|
833
881
|
}
|
|
834
882
|
async setDefaultMobileMoney(mobileMoneyId) {
|
|
835
|
-
return
|
|
883
|
+
return safe5(
|
|
836
884
|
this.client.call(LINK_MUTATION.SET_DEFAULT_MOBILE_MONEY, mobileMoneyId)
|
|
837
885
|
);
|
|
838
886
|
}
|
|
839
887
|
async trackMobileMoneyUsage(mobileMoneyId) {
|
|
840
|
-
return
|
|
888
|
+
return safe5(
|
|
841
889
|
this.client.call(LINK_MUTATION.TRACK_MOBILE_MONEY_USAGE, {
|
|
842
890
|
mobile_money_id: mobileMoneyId
|
|
843
891
|
})
|
|
844
892
|
);
|
|
845
893
|
}
|
|
846
894
|
async verifyMobileMoney(mobileMoneyId) {
|
|
847
|
-
return
|
|
895
|
+
return safe5(
|
|
848
896
|
this.client.call(LINK_MUTATION.VERIFY_MOBILE_MONEY, mobileMoneyId)
|
|
849
897
|
);
|
|
850
898
|
}
|
|
@@ -852,46 +900,60 @@ var LinkService = class {
|
|
|
852
900
|
// SESSIONS
|
|
853
901
|
// --------------------------------------------------------------------------
|
|
854
902
|
async getSessions() {
|
|
855
|
-
return
|
|
903
|
+
return safe5(this.client.linkGet("/v1/link/sessions"));
|
|
856
904
|
}
|
|
857
905
|
async revokeSession(sessionId) {
|
|
858
|
-
return
|
|
906
|
+
return safe5(this.client.linkDelete(`/v1/link/sessions/${sessionId}`));
|
|
859
907
|
}
|
|
860
908
|
async revokeAllSessions() {
|
|
861
|
-
return
|
|
909
|
+
return safe5(this.client.linkDelete("/v1/link/sessions"));
|
|
862
910
|
}
|
|
863
911
|
// --------------------------------------------------------------------------
|
|
864
912
|
// REST ALTERNATIVES (for direct API access)
|
|
865
913
|
// --------------------------------------------------------------------------
|
|
866
914
|
async getAddressesRest() {
|
|
867
|
-
return
|
|
915
|
+
return safe5(this.client.linkGet("/v1/link/addresses"));
|
|
868
916
|
}
|
|
869
917
|
async createAddressRest(input) {
|
|
870
|
-
return
|
|
918
|
+
return safe5(this.client.linkPost("/v1/link/addresses", input));
|
|
871
919
|
}
|
|
872
920
|
async deleteAddressRest(addressId) {
|
|
873
|
-
return
|
|
921
|
+
return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
|
|
874
922
|
}
|
|
875
923
|
async setDefaultAddressRest(addressId) {
|
|
876
|
-
return
|
|
924
|
+
return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
|
|
877
925
|
}
|
|
878
926
|
async getMobileMoneyRest() {
|
|
879
|
-
return
|
|
927
|
+
return safe5(this.client.linkGet("/v1/link/mobile-money"));
|
|
880
928
|
}
|
|
881
929
|
async createMobileMoneyRest(input) {
|
|
882
|
-
return
|
|
930
|
+
return safe5(this.client.linkPost("/v1/link/mobile-money", input));
|
|
883
931
|
}
|
|
884
932
|
async deleteMobileMoneyRest(mobileMoneyId) {
|
|
885
|
-
return
|
|
933
|
+
return safe5(this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`));
|
|
886
934
|
}
|
|
887
935
|
async setDefaultMobileMoneyRest(mobileMoneyId) {
|
|
888
|
-
return
|
|
936
|
+
return safe5(
|
|
889
937
|
this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
|
|
890
938
|
);
|
|
891
939
|
}
|
|
892
940
|
};
|
|
893
941
|
|
|
894
942
|
// src/auth.ts
|
|
943
|
+
function toCimplifyError6(error) {
|
|
944
|
+
if (error instanceof CimplifyError) return error;
|
|
945
|
+
if (error instanceof Error) {
|
|
946
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
947
|
+
}
|
|
948
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
949
|
+
}
|
|
950
|
+
async function safe6(promise) {
|
|
951
|
+
try {
|
|
952
|
+
return ok(await promise);
|
|
953
|
+
} catch (error) {
|
|
954
|
+
return err(toCimplifyError6(error));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
895
957
|
var AuthService = class {
|
|
896
958
|
constructor(client) {
|
|
897
959
|
this.client = client;
|
|
@@ -900,52 +962,72 @@ var AuthService = class {
|
|
|
900
962
|
// STATUS & USER
|
|
901
963
|
// --------------------------------------------------------------------------
|
|
902
964
|
async getStatus() {
|
|
903
|
-
return this.client.query("auth");
|
|
965
|
+
return safe6(this.client.query("auth"));
|
|
904
966
|
}
|
|
905
967
|
async getCurrentUser() {
|
|
906
|
-
const
|
|
907
|
-
|
|
968
|
+
const result = await this.getStatus();
|
|
969
|
+
if (!result.ok) return result;
|
|
970
|
+
return ok(result.value.customer || null);
|
|
908
971
|
}
|
|
909
972
|
async isAuthenticated() {
|
|
910
|
-
const
|
|
911
|
-
return
|
|
973
|
+
const result = await this.getStatus();
|
|
974
|
+
if (!result.ok) return result;
|
|
975
|
+
return ok(result.value.is_authenticated);
|
|
912
976
|
}
|
|
913
977
|
// --------------------------------------------------------------------------
|
|
914
978
|
// OTP AUTHENTICATION
|
|
915
979
|
// --------------------------------------------------------------------------
|
|
916
980
|
async requestOtp(contact, contactType) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
981
|
+
return safe6(
|
|
982
|
+
this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
983
|
+
contact,
|
|
984
|
+
contact_type: contactType
|
|
985
|
+
})
|
|
986
|
+
);
|
|
921
987
|
}
|
|
922
988
|
async verifyOtp(code, contact) {
|
|
923
|
-
return
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
989
|
+
return safe6(
|
|
990
|
+
this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
991
|
+
otp_code: code,
|
|
992
|
+
contact
|
|
993
|
+
})
|
|
994
|
+
);
|
|
927
995
|
}
|
|
928
996
|
// --------------------------------------------------------------------------
|
|
929
997
|
// SESSION MANAGEMENT
|
|
930
998
|
// --------------------------------------------------------------------------
|
|
931
999
|
async logout() {
|
|
932
|
-
return this.client.call("auth.logout");
|
|
1000
|
+
return safe6(this.client.call("auth.logout"));
|
|
933
1001
|
}
|
|
934
1002
|
// --------------------------------------------------------------------------
|
|
935
1003
|
// PROFILE MANAGEMENT
|
|
936
1004
|
// --------------------------------------------------------------------------
|
|
937
1005
|
async updateProfile(input) {
|
|
938
|
-
return this.client.call("auth.update_profile", input);
|
|
1006
|
+
return safe6(this.client.call("auth.update_profile", input));
|
|
939
1007
|
}
|
|
940
1008
|
async changePassword(input) {
|
|
941
|
-
return this.client.call("auth.change_password", input);
|
|
1009
|
+
return safe6(this.client.call("auth.change_password", input));
|
|
942
1010
|
}
|
|
943
1011
|
async resetPassword(email) {
|
|
944
|
-
return this.client.call("auth.reset_password", { email });
|
|
1012
|
+
return safe6(this.client.call("auth.reset_password", { email }));
|
|
945
1013
|
}
|
|
946
1014
|
};
|
|
947
1015
|
|
|
948
1016
|
// src/business.ts
|
|
1017
|
+
function toCimplifyError7(error) {
|
|
1018
|
+
if (error instanceof CimplifyError) return error;
|
|
1019
|
+
if (error instanceof Error) {
|
|
1020
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1021
|
+
}
|
|
1022
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1023
|
+
}
|
|
1024
|
+
async function safe7(promise) {
|
|
1025
|
+
try {
|
|
1026
|
+
return ok(await promise);
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
return err(toCimplifyError7(error));
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
949
1031
|
var BusinessService = class {
|
|
950
1032
|
constructor(client) {
|
|
951
1033
|
this.client = client;
|
|
@@ -954,49 +1036,55 @@ var BusinessService = class {
|
|
|
954
1036
|
// BUSINESS INFO
|
|
955
1037
|
// --------------------------------------------------------------------------
|
|
956
1038
|
async getInfo() {
|
|
957
|
-
return this.client.query("business.info");
|
|
1039
|
+
return safe7(this.client.query("business.info"));
|
|
958
1040
|
}
|
|
959
1041
|
async getByHandle(handle) {
|
|
960
|
-
return this.client.query(`business.handle.${handle}`);
|
|
1042
|
+
return safe7(this.client.query(`business.handle.${handle}`));
|
|
961
1043
|
}
|
|
962
1044
|
async getByDomain(domain) {
|
|
963
|
-
return this.client.query("business.domain", { domain });
|
|
1045
|
+
return safe7(this.client.query("business.domain", { domain }));
|
|
964
1046
|
}
|
|
965
1047
|
async getSettings() {
|
|
966
|
-
return this.client.query("business.settings");
|
|
1048
|
+
return safe7(this.client.query("business.settings"));
|
|
967
1049
|
}
|
|
968
1050
|
async getTheme() {
|
|
969
|
-
return this.client.query("business.theme");
|
|
1051
|
+
return safe7(this.client.query("business.theme"));
|
|
970
1052
|
}
|
|
971
1053
|
// --------------------------------------------------------------------------
|
|
972
1054
|
// LOCATIONS
|
|
973
1055
|
// --------------------------------------------------------------------------
|
|
974
1056
|
async getLocations() {
|
|
975
|
-
return this.client.query("business.locations");
|
|
1057
|
+
return safe7(this.client.query("business.locations"));
|
|
976
1058
|
}
|
|
977
1059
|
async getLocation(locationId) {
|
|
978
|
-
return this.client.query(`business.locations.${locationId}`);
|
|
1060
|
+
return safe7(this.client.query(`business.locations.${locationId}`));
|
|
979
1061
|
}
|
|
980
1062
|
// --------------------------------------------------------------------------
|
|
981
1063
|
// HOURS
|
|
982
1064
|
// --------------------------------------------------------------------------
|
|
983
1065
|
async getHours() {
|
|
984
|
-
return this.client.query("business.hours");
|
|
1066
|
+
return safe7(this.client.query("business.hours"));
|
|
985
1067
|
}
|
|
986
1068
|
async getLocationHours(locationId) {
|
|
987
|
-
return this.client.query(`business.locations.${locationId}.hours`);
|
|
1069
|
+
return safe7(this.client.query(`business.locations.${locationId}.hours`));
|
|
988
1070
|
}
|
|
989
1071
|
// --------------------------------------------------------------------------
|
|
990
1072
|
// BOOTSTRAP (for storefront initialization)
|
|
991
1073
|
// --------------------------------------------------------------------------
|
|
992
1074
|
async getBootstrap() {
|
|
993
|
-
const [
|
|
1075
|
+
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
994
1076
|
this.getInfo(),
|
|
995
1077
|
this.getLocations(),
|
|
996
|
-
this.client.query("categories#select(id,name,slug)")
|
|
1078
|
+
safe7(this.client.query("categories#select(id,name,slug)"))
|
|
997
1079
|
]);
|
|
1080
|
+
if (!businessResult.ok) return businessResult;
|
|
1081
|
+
if (!locationsResult.ok) return locationsResult;
|
|
1082
|
+
if (!categoriesResult.ok) return categoriesResult;
|
|
1083
|
+
const business = businessResult.value;
|
|
1084
|
+
const locations = locationsResult.value;
|
|
1085
|
+
const categories = categoriesResult.value;
|
|
998
1086
|
const defaultLocation = locations[0];
|
|
999
|
-
return {
|
|
1087
|
+
return ok({
|
|
1000
1088
|
business,
|
|
1001
1089
|
location: defaultLocation,
|
|
1002
1090
|
locations,
|
|
@@ -1004,11 +1092,25 @@ var BusinessService = class {
|
|
|
1004
1092
|
currency: business.default_currency,
|
|
1005
1093
|
is_open: defaultLocation?.accepts_online_orders ?? false,
|
|
1006
1094
|
accepts_orders: defaultLocation?.accepts_online_orders ?? false
|
|
1007
|
-
};
|
|
1095
|
+
});
|
|
1008
1096
|
}
|
|
1009
1097
|
};
|
|
1010
1098
|
|
|
1011
1099
|
// src/inventory.ts
|
|
1100
|
+
function toCimplifyError8(error) {
|
|
1101
|
+
if (error instanceof CimplifyError) return error;
|
|
1102
|
+
if (error instanceof Error) {
|
|
1103
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1104
|
+
}
|
|
1105
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1106
|
+
}
|
|
1107
|
+
async function safe8(promise) {
|
|
1108
|
+
try {
|
|
1109
|
+
return ok(await promise);
|
|
1110
|
+
} catch (error) {
|
|
1111
|
+
return err(toCimplifyError8(error));
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1012
1114
|
var InventoryService = class {
|
|
1013
1115
|
constructor(client) {
|
|
1014
1116
|
this.client = client;
|
|
@@ -1017,41 +1119,51 @@ var InventoryService = class {
|
|
|
1017
1119
|
// STOCK QUERIES
|
|
1018
1120
|
// --------------------------------------------------------------------------
|
|
1019
1121
|
async getStockLevels() {
|
|
1020
|
-
return this.client.query("inventory.stock_levels");
|
|
1122
|
+
return safe8(this.client.query("inventory.stock_levels"));
|
|
1021
1123
|
}
|
|
1022
1124
|
async getProductStock(productId, locationId) {
|
|
1023
1125
|
if (locationId) {
|
|
1024
|
-
return
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1126
|
+
return safe8(
|
|
1127
|
+
this.client.query("inventory.product", {
|
|
1128
|
+
product_id: productId,
|
|
1129
|
+
location_id: locationId
|
|
1130
|
+
})
|
|
1131
|
+
);
|
|
1028
1132
|
}
|
|
1029
|
-
return
|
|
1030
|
-
|
|
1031
|
-
|
|
1133
|
+
return safe8(
|
|
1134
|
+
this.client.query("inventory.product", {
|
|
1135
|
+
product_id: productId
|
|
1136
|
+
})
|
|
1137
|
+
);
|
|
1032
1138
|
}
|
|
1033
1139
|
async getVariantStock(variantId, locationId) {
|
|
1034
|
-
return
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1140
|
+
return safe8(
|
|
1141
|
+
this.client.query("inventory.variant", {
|
|
1142
|
+
variant_id: variantId,
|
|
1143
|
+
location_id: locationId
|
|
1144
|
+
})
|
|
1145
|
+
);
|
|
1038
1146
|
}
|
|
1039
1147
|
// --------------------------------------------------------------------------
|
|
1040
1148
|
// AVAILABILITY CHECKS
|
|
1041
1149
|
// --------------------------------------------------------------------------
|
|
1042
1150
|
async checkProductAvailability(productId, quantity, locationId) {
|
|
1043
|
-
return
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1151
|
+
return safe8(
|
|
1152
|
+
this.client.query("inventory.check_availability", {
|
|
1153
|
+
product_id: productId,
|
|
1154
|
+
quantity,
|
|
1155
|
+
location_id: locationId
|
|
1156
|
+
})
|
|
1157
|
+
);
|
|
1048
1158
|
}
|
|
1049
1159
|
async checkVariantAvailability(variantId, quantity, locationId) {
|
|
1050
|
-
return
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1160
|
+
return safe8(
|
|
1161
|
+
this.client.query("inventory.check_availability", {
|
|
1162
|
+
variant_id: variantId,
|
|
1163
|
+
quantity,
|
|
1164
|
+
location_id: locationId
|
|
1165
|
+
})
|
|
1166
|
+
);
|
|
1055
1167
|
}
|
|
1056
1168
|
async checkMultipleAvailability(items, locationId) {
|
|
1057
1169
|
const results = await Promise.all(
|
|
@@ -1059,28 +1171,47 @@ var InventoryService = class {
|
|
|
1059
1171
|
(item) => item.variant_id ? this.checkVariantAvailability(item.variant_id, item.quantity, locationId) : this.checkProductAvailability(item.product_id, item.quantity, locationId)
|
|
1060
1172
|
)
|
|
1061
1173
|
);
|
|
1062
|
-
|
|
1174
|
+
for (const result of results) {
|
|
1175
|
+
if (!result.ok) return result;
|
|
1176
|
+
}
|
|
1177
|
+
return ok(results.map((r) => r.value));
|
|
1063
1178
|
}
|
|
1064
1179
|
// --------------------------------------------------------------------------
|
|
1065
1180
|
// SUMMARY
|
|
1066
1181
|
// --------------------------------------------------------------------------
|
|
1067
1182
|
async getSummary() {
|
|
1068
|
-
return this.client.query("inventory.summary");
|
|
1183
|
+
return safe8(this.client.query("inventory.summary"));
|
|
1069
1184
|
}
|
|
1070
1185
|
// --------------------------------------------------------------------------
|
|
1071
1186
|
// CONVENIENCE METHODS
|
|
1072
1187
|
// --------------------------------------------------------------------------
|
|
1073
1188
|
async isInStock(productId, locationId) {
|
|
1074
1189
|
const result = await this.checkProductAvailability(productId, 1, locationId);
|
|
1075
|
-
return result
|
|
1190
|
+
if (!result.ok) return result;
|
|
1191
|
+
return ok(result.value.is_available);
|
|
1076
1192
|
}
|
|
1077
1193
|
async getAvailableQuantity(productId, locationId) {
|
|
1078
|
-
const
|
|
1079
|
-
return
|
|
1194
|
+
const result = await this.getProductStock(productId, locationId);
|
|
1195
|
+
if (!result.ok) return result;
|
|
1196
|
+
return ok(result.value.available_quantity);
|
|
1080
1197
|
}
|
|
1081
1198
|
};
|
|
1082
1199
|
|
|
1083
1200
|
// src/scheduling.ts
|
|
1201
|
+
function toCimplifyError9(error) {
|
|
1202
|
+
if (error instanceof CimplifyError) return error;
|
|
1203
|
+
if (error instanceof Error) {
|
|
1204
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1205
|
+
}
|
|
1206
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1207
|
+
}
|
|
1208
|
+
async function safe9(promise) {
|
|
1209
|
+
try {
|
|
1210
|
+
return ok(await promise);
|
|
1211
|
+
} catch (error) {
|
|
1212
|
+
return err(toCimplifyError9(error));
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1084
1215
|
var SchedulingService = class {
|
|
1085
1216
|
constructor(client) {
|
|
1086
1217
|
this.client = client;
|
|
@@ -1089,86 +1220,113 @@ var SchedulingService = class {
|
|
|
1089
1220
|
// SERVICES
|
|
1090
1221
|
// --------------------------------------------------------------------------
|
|
1091
1222
|
async getServices() {
|
|
1092
|
-
return this.client.query("scheduling.services");
|
|
1223
|
+
return safe9(this.client.query("scheduling.services"));
|
|
1093
1224
|
}
|
|
1094
1225
|
/**
|
|
1095
1226
|
* Get a specific service by ID
|
|
1096
1227
|
* Note: Filters from all services client-side (no single-service endpoint)
|
|
1097
1228
|
*/
|
|
1098
1229
|
async getService(serviceId) {
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1230
|
+
const result = await this.getServices();
|
|
1231
|
+
if (!result.ok) return result;
|
|
1232
|
+
return ok(result.value.find((s) => s.id === serviceId) || null);
|
|
1101
1233
|
}
|
|
1102
1234
|
// --------------------------------------------------------------------------
|
|
1103
1235
|
// AVAILABILITY
|
|
1104
1236
|
// --------------------------------------------------------------------------
|
|
1105
1237
|
async getAvailableSlots(input) {
|
|
1106
|
-
return
|
|
1107
|
-
|
|
1108
|
-
|
|
1238
|
+
return safe9(
|
|
1239
|
+
this.client.query(
|
|
1240
|
+
"scheduling.slots",
|
|
1241
|
+
input
|
|
1242
|
+
)
|
|
1109
1243
|
);
|
|
1110
1244
|
}
|
|
1111
1245
|
async checkSlotAvailability(input) {
|
|
1112
|
-
return
|
|
1113
|
-
|
|
1114
|
-
|
|
1246
|
+
return safe9(
|
|
1247
|
+
this.client.query(
|
|
1248
|
+
"scheduling.check_availability",
|
|
1249
|
+
input
|
|
1250
|
+
)
|
|
1115
1251
|
);
|
|
1116
1252
|
}
|
|
1117
1253
|
async getServiceAvailability(params) {
|
|
1118
|
-
return
|
|
1119
|
-
|
|
1120
|
-
|
|
1254
|
+
return safe9(
|
|
1255
|
+
this.client.query(
|
|
1256
|
+
"scheduling.availability",
|
|
1257
|
+
params
|
|
1258
|
+
)
|
|
1121
1259
|
);
|
|
1122
1260
|
}
|
|
1123
1261
|
// --------------------------------------------------------------------------
|
|
1124
1262
|
// BOOKINGS
|
|
1125
1263
|
// --------------------------------------------------------------------------
|
|
1126
1264
|
async getBooking(bookingId) {
|
|
1127
|
-
return this.client.query(`scheduling.${bookingId}`);
|
|
1265
|
+
return safe9(this.client.query(`scheduling.${bookingId}`));
|
|
1128
1266
|
}
|
|
1129
1267
|
async getCustomerBookings() {
|
|
1130
|
-
return this.client.query("scheduling");
|
|
1268
|
+
return safe9(this.client.query("scheduling"));
|
|
1131
1269
|
}
|
|
1132
1270
|
async getUpcomingBookings() {
|
|
1133
|
-
return
|
|
1134
|
-
|
|
1271
|
+
return safe9(
|
|
1272
|
+
this.client.query(
|
|
1273
|
+
"scheduling[?(@.status!='completed' && @.status!='cancelled')]#sort(start_time,asc)"
|
|
1274
|
+
)
|
|
1135
1275
|
);
|
|
1136
1276
|
}
|
|
1137
1277
|
async getPastBookings(limit = 10) {
|
|
1138
|
-
return
|
|
1139
|
-
|
|
1278
|
+
return safe9(
|
|
1279
|
+
this.client.query(
|
|
1280
|
+
`scheduling[?(@.status=='completed')]#sort(start_time,desc)#limit(${limit})`
|
|
1281
|
+
)
|
|
1140
1282
|
);
|
|
1141
1283
|
}
|
|
1142
1284
|
// --------------------------------------------------------------------------
|
|
1143
1285
|
// BOOKING MANAGEMENT
|
|
1144
1286
|
// --------------------------------------------------------------------------
|
|
1145
1287
|
async cancelBooking(input) {
|
|
1146
|
-
return this.client.call("scheduling.cancel_booking", input);
|
|
1288
|
+
return safe9(this.client.call("scheduling.cancel_booking", input));
|
|
1147
1289
|
}
|
|
1148
1290
|
async rescheduleBooking(input) {
|
|
1149
|
-
return this.client.call("scheduling.reschedule_booking", input);
|
|
1291
|
+
return safe9(this.client.call("scheduling.reschedule_booking", input));
|
|
1150
1292
|
}
|
|
1151
1293
|
// --------------------------------------------------------------------------
|
|
1152
1294
|
// CONVENIENCE METHODS
|
|
1153
1295
|
// --------------------------------------------------------------------------
|
|
1154
1296
|
async getNextAvailableSlot(serviceId, fromDate) {
|
|
1155
1297
|
const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
1156
|
-
const
|
|
1298
|
+
const result = await this.getAvailableSlots({
|
|
1157
1299
|
service_id: serviceId,
|
|
1158
1300
|
date
|
|
1159
1301
|
});
|
|
1160
|
-
|
|
1302
|
+
if (!result.ok) return result;
|
|
1303
|
+
return ok(result.value.find((slot) => slot.is_available) || null);
|
|
1161
1304
|
}
|
|
1162
1305
|
async hasAvailabilityOn(serviceId, date) {
|
|
1163
|
-
const
|
|
1306
|
+
const result = await this.getAvailableSlots({
|
|
1164
1307
|
service_id: serviceId,
|
|
1165
1308
|
date
|
|
1166
1309
|
});
|
|
1167
|
-
|
|
1310
|
+
if (!result.ok) return result;
|
|
1311
|
+
return ok(result.value.some((slot) => slot.is_available));
|
|
1168
1312
|
}
|
|
1169
1313
|
};
|
|
1170
1314
|
|
|
1171
1315
|
// src/lite.ts
|
|
1316
|
+
function toCimplifyError10(error) {
|
|
1317
|
+
if (error instanceof CimplifyError) return error;
|
|
1318
|
+
if (error instanceof Error) {
|
|
1319
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1320
|
+
}
|
|
1321
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1322
|
+
}
|
|
1323
|
+
async function safe10(promise) {
|
|
1324
|
+
try {
|
|
1325
|
+
return ok(await promise);
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
return err(toCimplifyError10(error));
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1172
1330
|
var LiteService = class {
|
|
1173
1331
|
constructor(client) {
|
|
1174
1332
|
this.client = client;
|
|
@@ -1177,54 +1335,107 @@ var LiteService = class {
|
|
|
1177
1335
|
// BOOTSTRAP
|
|
1178
1336
|
// --------------------------------------------------------------------------
|
|
1179
1337
|
async getBootstrap() {
|
|
1180
|
-
return this.client.query("lite.bootstrap");
|
|
1338
|
+
return safe10(this.client.query("lite.bootstrap"));
|
|
1181
1339
|
}
|
|
1182
1340
|
// --------------------------------------------------------------------------
|
|
1183
1341
|
// TABLE MANAGEMENT
|
|
1184
1342
|
// --------------------------------------------------------------------------
|
|
1185
1343
|
async getTable(tableId) {
|
|
1186
|
-
return this.client.query(`lite.table.${tableId}`);
|
|
1344
|
+
return safe10(this.client.query(`lite.table.${tableId}`));
|
|
1187
1345
|
}
|
|
1188
1346
|
async getTableByNumber(tableNumber, locationId) {
|
|
1189
|
-
return
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1347
|
+
return safe10(
|
|
1348
|
+
this.client.query("lite.table_by_number", {
|
|
1349
|
+
table_number: tableNumber,
|
|
1350
|
+
location_id: locationId
|
|
1351
|
+
})
|
|
1352
|
+
);
|
|
1193
1353
|
}
|
|
1194
1354
|
// --------------------------------------------------------------------------
|
|
1195
1355
|
// KITCHEN ORDERS
|
|
1196
1356
|
// --------------------------------------------------------------------------
|
|
1197
1357
|
async sendToKitchen(tableId, items) {
|
|
1198
|
-
return
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1358
|
+
return safe10(
|
|
1359
|
+
this.client.call("lite.send_to_kitchen", {
|
|
1360
|
+
table_id: tableId,
|
|
1361
|
+
items
|
|
1362
|
+
})
|
|
1363
|
+
);
|
|
1202
1364
|
}
|
|
1203
1365
|
async callWaiter(tableId, reason) {
|
|
1204
|
-
return
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1366
|
+
return safe10(
|
|
1367
|
+
this.client.call("lite.call_waiter", {
|
|
1368
|
+
table_id: tableId,
|
|
1369
|
+
reason
|
|
1370
|
+
})
|
|
1371
|
+
);
|
|
1208
1372
|
}
|
|
1209
1373
|
async requestBill(tableId) {
|
|
1210
|
-
return
|
|
1211
|
-
|
|
1212
|
-
|
|
1374
|
+
return safe10(
|
|
1375
|
+
this.client.call("lite.request_bill", {
|
|
1376
|
+
table_id: tableId
|
|
1377
|
+
})
|
|
1378
|
+
);
|
|
1213
1379
|
}
|
|
1214
1380
|
// --------------------------------------------------------------------------
|
|
1215
1381
|
// MENU (optimized for lite/QR experience)
|
|
1216
1382
|
// --------------------------------------------------------------------------
|
|
1217
1383
|
async getMenu() {
|
|
1218
|
-
return this.client.query("lite.menu");
|
|
1384
|
+
return safe10(this.client.query("lite.menu"));
|
|
1219
1385
|
}
|
|
1220
1386
|
async getMenuByCategory(categoryId) {
|
|
1221
|
-
return this.client.query(`lite.menu.category.${categoryId}`);
|
|
1387
|
+
return safe10(this.client.query(`lite.menu.category.${categoryId}`));
|
|
1222
1388
|
}
|
|
1223
1389
|
};
|
|
1224
1390
|
|
|
1225
1391
|
// src/client.ts
|
|
1226
1392
|
var SESSION_TOKEN_HEADER = "x-session-token";
|
|
1227
1393
|
var SESSION_STORAGE_KEY = "cimplify_session_token";
|
|
1394
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
1395
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
1396
|
+
var DEFAULT_RETRY_DELAY_MS = 1e3;
|
|
1397
|
+
function sleep(ms) {
|
|
1398
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1399
|
+
}
|
|
1400
|
+
function isRetryable(error) {
|
|
1401
|
+
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
1402
|
+
return true;
|
|
1403
|
+
}
|
|
1404
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1405
|
+
return true;
|
|
1406
|
+
}
|
|
1407
|
+
if (error instanceof CimplifyError) {
|
|
1408
|
+
return error.retryable;
|
|
1409
|
+
}
|
|
1410
|
+
if (error instanceof CimplifyError && error.code === "SERVER_ERROR") {
|
|
1411
|
+
return true;
|
|
1412
|
+
}
|
|
1413
|
+
return false;
|
|
1414
|
+
}
|
|
1415
|
+
function toNetworkError(error) {
|
|
1416
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1417
|
+
return new CimplifyError(
|
|
1418
|
+
ErrorCode.TIMEOUT,
|
|
1419
|
+
"Request timed out. Please check your connection and try again.",
|
|
1420
|
+
true
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
1424
|
+
return new CimplifyError(
|
|
1425
|
+
ErrorCode.NETWORK_ERROR,
|
|
1426
|
+
"Network error. Please check your internet connection.",
|
|
1427
|
+
true
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
if (error instanceof CimplifyError) {
|
|
1431
|
+
return error;
|
|
1432
|
+
}
|
|
1433
|
+
return new CimplifyError(
|
|
1434
|
+
ErrorCode.UNKNOWN_ERROR,
|
|
1435
|
+
error instanceof Error ? error.message : "An unknown error occurred",
|
|
1436
|
+
false
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1228
1439
|
function deriveUrls() {
|
|
1229
1440
|
const hostname = typeof window !== "undefined" ? window.location.hostname : "";
|
|
1230
1441
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
@@ -1247,6 +1458,9 @@ var CimplifyClient = class {
|
|
|
1247
1458
|
this.baseUrl = urls.baseUrl;
|
|
1248
1459
|
this.linkApiUrl = urls.linkApiUrl;
|
|
1249
1460
|
this.credentials = config.credentials || "include";
|
|
1461
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
1462
|
+
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1463
|
+
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
1250
1464
|
this.sessionToken = this.loadSessionToken();
|
|
1251
1465
|
}
|
|
1252
1466
|
getSessionToken() {
|
|
@@ -1292,12 +1506,47 @@ var CimplifyClient = class {
|
|
|
1292
1506
|
this.saveSessionToken(newToken);
|
|
1293
1507
|
}
|
|
1294
1508
|
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Resilient fetch with timeout and automatic retries for network errors.
|
|
1511
|
+
* Uses exponential backoff: 1s, 2s, 4s between retries.
|
|
1512
|
+
*/
|
|
1513
|
+
async resilientFetch(url, options) {
|
|
1514
|
+
let lastError;
|
|
1515
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
1516
|
+
try {
|
|
1517
|
+
const controller = new AbortController();
|
|
1518
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
1519
|
+
const response = await fetch(url, {
|
|
1520
|
+
...options,
|
|
1521
|
+
signal: controller.signal
|
|
1522
|
+
});
|
|
1523
|
+
clearTimeout(timeoutId);
|
|
1524
|
+
if (response.ok || response.status >= 400 && response.status < 500) {
|
|
1525
|
+
return response;
|
|
1526
|
+
}
|
|
1527
|
+
if (response.status >= 500 && attempt < this.maxRetries) {
|
|
1528
|
+
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
1529
|
+
await sleep(delay);
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
return response;
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
lastError = error;
|
|
1535
|
+
if (!isRetryable(error) || attempt >= this.maxRetries) {
|
|
1536
|
+
throw toNetworkError(error);
|
|
1537
|
+
}
|
|
1538
|
+
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
1539
|
+
await sleep(delay);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
throw toNetworkError(lastError);
|
|
1543
|
+
}
|
|
1295
1544
|
async query(query2, variables) {
|
|
1296
1545
|
const body = { query: query2 };
|
|
1297
1546
|
if (variables) {
|
|
1298
1547
|
body.variables = variables;
|
|
1299
1548
|
}
|
|
1300
|
-
const response = await
|
|
1549
|
+
const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
|
|
1301
1550
|
method: "POST",
|
|
1302
1551
|
credentials: this.credentials,
|
|
1303
1552
|
headers: this.getHeaders(),
|
|
@@ -1311,7 +1560,7 @@ var CimplifyClient = class {
|
|
|
1311
1560
|
method,
|
|
1312
1561
|
args: args !== void 0 ? [args] : []
|
|
1313
1562
|
};
|
|
1314
|
-
const response = await
|
|
1563
|
+
const response = await this.resilientFetch(`${this.baseUrl}/api/m`, {
|
|
1315
1564
|
method: "POST",
|
|
1316
1565
|
credentials: this.credentials,
|
|
1317
1566
|
headers: this.getHeaders(),
|
|
@@ -1321,7 +1570,7 @@ var CimplifyClient = class {
|
|
|
1321
1570
|
return this.handleResponse(response);
|
|
1322
1571
|
}
|
|
1323
1572
|
async get(path) {
|
|
1324
|
-
const response = await
|
|
1573
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
1325
1574
|
method: "GET",
|
|
1326
1575
|
credentials: this.credentials,
|
|
1327
1576
|
headers: this.getHeaders()
|
|
@@ -1330,7 +1579,7 @@ var CimplifyClient = class {
|
|
|
1330
1579
|
return this.handleRestResponse(response);
|
|
1331
1580
|
}
|
|
1332
1581
|
async post(path, body) {
|
|
1333
|
-
const response = await
|
|
1582
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
1334
1583
|
method: "POST",
|
|
1335
1584
|
credentials: this.credentials,
|
|
1336
1585
|
headers: this.getHeaders(),
|
|
@@ -1340,7 +1589,7 @@ var CimplifyClient = class {
|
|
|
1340
1589
|
return this.handleRestResponse(response);
|
|
1341
1590
|
}
|
|
1342
1591
|
async delete(path) {
|
|
1343
|
-
const response = await
|
|
1592
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
1344
1593
|
method: "DELETE",
|
|
1345
1594
|
credentials: this.credentials,
|
|
1346
1595
|
headers: this.getHeaders()
|
|
@@ -1349,7 +1598,7 @@ var CimplifyClient = class {
|
|
|
1349
1598
|
return this.handleRestResponse(response);
|
|
1350
1599
|
}
|
|
1351
1600
|
async linkGet(path) {
|
|
1352
|
-
const response = await
|
|
1601
|
+
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
1353
1602
|
method: "GET",
|
|
1354
1603
|
credentials: this.credentials,
|
|
1355
1604
|
headers: this.getHeaders()
|
|
@@ -1358,7 +1607,7 @@ var CimplifyClient = class {
|
|
|
1358
1607
|
return this.handleRestResponse(response);
|
|
1359
1608
|
}
|
|
1360
1609
|
async linkPost(path, body) {
|
|
1361
|
-
const response = await
|
|
1610
|
+
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
1362
1611
|
method: "POST",
|
|
1363
1612
|
credentials: this.credentials,
|
|
1364
1613
|
headers: this.getHeaders(),
|
|
@@ -1368,7 +1617,7 @@ var CimplifyClient = class {
|
|
|
1368
1617
|
return this.handleRestResponse(response);
|
|
1369
1618
|
}
|
|
1370
1619
|
async linkDelete(path) {
|
|
1371
|
-
const response = await
|
|
1620
|
+
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
1372
1621
|
method: "DELETE",
|
|
1373
1622
|
credentials: this.credentials,
|
|
1374
1623
|
headers: this.getHeaders()
|