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