@cimplify/sdk 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +367 -784
- package/dist/advanced.mjs +367 -784
- package/dist/{client-Djde3IXh.d.ts → client-CIvQ1ZLZ.d.ts} +141 -268
- package/dist/{client-4qOxssTq.d.mts → client-DvoI0EIX.d.mts} +141 -268
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +499 -909
- package/dist/index.mjs +499 -909
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +332 -776
- package/dist/react.mjs +332 -776
- package/package.json +1 -1
package/dist/advanced.js
CHANGED
|
@@ -122,74 +122,6 @@ function enrichError(error, options = {}) {
|
|
|
122
122
|
return error;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// src/query/builder.ts
|
|
126
|
-
function escapeQueryValue(value) {
|
|
127
|
-
return value.replace(/'/g, "\\'");
|
|
128
|
-
}
|
|
129
|
-
var QueryBuilder = class {
|
|
130
|
-
constructor(entity) {
|
|
131
|
-
this.filters = [];
|
|
132
|
-
this.modifiers = [];
|
|
133
|
-
this.pathSegments = [];
|
|
134
|
-
this.entity = entity;
|
|
135
|
-
}
|
|
136
|
-
path(segment) {
|
|
137
|
-
this.pathSegments.push(segment);
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
where(field, op, value) {
|
|
141
|
-
const v = typeof value === "string" ? `'${escapeQueryValue(value)}'` : value;
|
|
142
|
-
if (op === "contains" || op === "startsWith") {
|
|
143
|
-
this.filters.push(`@.${field} ${op} ${v}`);
|
|
144
|
-
} else {
|
|
145
|
-
this.filters.push(`@.${field}${op}${v}`);
|
|
146
|
-
}
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
and(field, op, value) {
|
|
150
|
-
return this.where(field, op, value);
|
|
151
|
-
}
|
|
152
|
-
sort(field, order = "asc") {
|
|
153
|
-
this.modifiers.push(`sort(${field},${order})`);
|
|
154
|
-
return this;
|
|
155
|
-
}
|
|
156
|
-
limit(n) {
|
|
157
|
-
this.modifiers.push(`limit(${n})`);
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
offset(n) {
|
|
161
|
-
this.modifiers.push(`offset(${n})`);
|
|
162
|
-
return this;
|
|
163
|
-
}
|
|
164
|
-
count() {
|
|
165
|
-
this.modifiers.push("count");
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
enriched() {
|
|
169
|
-
this.modifiers.push("enriched");
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
build() {
|
|
173
|
-
let query2 = this.entity;
|
|
174
|
-
if (this.pathSegments.length > 0) {
|
|
175
|
-
query2 += "." + this.pathSegments.join(".");
|
|
176
|
-
}
|
|
177
|
-
if (this.filters.length > 0) {
|
|
178
|
-
query2 += `[?(${this.filters.join(" && ")})]`;
|
|
179
|
-
}
|
|
180
|
-
for (const mod of this.modifiers) {
|
|
181
|
-
query2 += `#${mod}`;
|
|
182
|
-
}
|
|
183
|
-
return query2;
|
|
184
|
-
}
|
|
185
|
-
toString() {
|
|
186
|
-
return this.build();
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
function query(entity) {
|
|
190
|
-
return new QueryBuilder(entity);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
125
|
// src/catalogue.ts
|
|
194
126
|
function toCimplifyError(error) {
|
|
195
127
|
if (error instanceof CimplifyError) return enrichError(error);
|
|
@@ -205,14 +137,6 @@ async function safe(promise) {
|
|
|
205
137
|
return err(toCimplifyError(error));
|
|
206
138
|
}
|
|
207
139
|
}
|
|
208
|
-
async function safeWithFallback(primary, fallback) {
|
|
209
|
-
const primaryResult = await safe(primary());
|
|
210
|
-
if (primaryResult.ok) return primaryResult;
|
|
211
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
212
|
-
return primaryResult;
|
|
213
|
-
}
|
|
214
|
-
return safe(fallback());
|
|
215
|
-
}
|
|
216
140
|
function withQuery(path, params) {
|
|
217
141
|
const query2 = new URLSearchParams();
|
|
218
142
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -274,22 +198,6 @@ function normalizeCatalogueProductPayload(product) {
|
|
|
274
198
|
}
|
|
275
199
|
return normalized;
|
|
276
200
|
}
|
|
277
|
-
function findProductBySlug(products, slug) {
|
|
278
|
-
return products.find((product) => {
|
|
279
|
-
const value = product["slug"];
|
|
280
|
-
return typeof value === "string" && value === slug;
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
function findCategoryBySlug(categories, slug) {
|
|
284
|
-
return categories.find((category) => {
|
|
285
|
-
const value = category["slug"];
|
|
286
|
-
return typeof value === "string" && value === slug;
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
function hasCategorySlug(category) {
|
|
290
|
-
const value = category["slug"];
|
|
291
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
292
|
-
}
|
|
293
201
|
function toFiniteNumber(value) {
|
|
294
202
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
295
203
|
return value;
|
|
@@ -377,53 +285,11 @@ var CatalogueQueries = class {
|
|
|
377
285
|
this.client = client;
|
|
378
286
|
}
|
|
379
287
|
async getCatalogue() {
|
|
380
|
-
const result = await
|
|
381
|
-
() => this.client.get("/api/v1/catalogue"),
|
|
382
|
-
() => this.client.query("catalogue")
|
|
383
|
-
);
|
|
288
|
+
const result = await safe(this.client.get("/api/v1/catalogue"));
|
|
384
289
|
if (!result.ok) return result;
|
|
385
290
|
return ok(normalizeCatalogueSnapshot(result.value));
|
|
386
291
|
}
|
|
387
292
|
async getProducts(options) {
|
|
388
|
-
let query2 = "products";
|
|
389
|
-
const filters = [];
|
|
390
|
-
if (options?.category) {
|
|
391
|
-
filters.push(`@.category_id=='${escapeQueryValue(options.category)}'`);
|
|
392
|
-
}
|
|
393
|
-
if (options?.featured !== void 0) {
|
|
394
|
-
filters.push(`@.featured==${options.featured}`);
|
|
395
|
-
}
|
|
396
|
-
if (options?.in_stock !== void 0) {
|
|
397
|
-
filters.push(`@.in_stock==${options.in_stock}`);
|
|
398
|
-
}
|
|
399
|
-
if (options?.search) {
|
|
400
|
-
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
401
|
-
}
|
|
402
|
-
if (options?.tags?.length) {
|
|
403
|
-
for (const tag of options.tags) {
|
|
404
|
-
if (tag.trim().length > 0) {
|
|
405
|
-
filters.push(`@.tags contains '${escapeQueryValue(tag)}'`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (options?.min_price !== void 0) {
|
|
410
|
-
filters.push(`@.price>=${options.min_price}`);
|
|
411
|
-
}
|
|
412
|
-
if (options?.max_price !== void 0) {
|
|
413
|
-
filters.push(`@.price<=${options.max_price}`);
|
|
414
|
-
}
|
|
415
|
-
if (filters.length > 0) {
|
|
416
|
-
query2 += `[?(${filters.join(" && ")})]`;
|
|
417
|
-
}
|
|
418
|
-
if (options?.sort_by) {
|
|
419
|
-
query2 += `#sort(${options.sort_by},${options.sort_order || "asc"})`;
|
|
420
|
-
}
|
|
421
|
-
if (options?.limit !== void 0) {
|
|
422
|
-
query2 += `#limit(${options.limit})`;
|
|
423
|
-
}
|
|
424
|
-
if (options?.offset !== void 0) {
|
|
425
|
-
query2 += `#offset(${options.offset})`;
|
|
426
|
-
}
|
|
427
293
|
const path = withQuery("/api/v1/catalogue/products", {
|
|
428
294
|
category_id: options?.category,
|
|
429
295
|
search: options?.search,
|
|
@@ -439,325 +305,145 @@ var CatalogueQueries = class {
|
|
|
439
305
|
offset: options?.offset,
|
|
440
306
|
cursor: options?.cursor
|
|
441
307
|
});
|
|
442
|
-
const result = await
|
|
443
|
-
() => this.client.get(path),
|
|
444
|
-
() => this.client.query(query2)
|
|
445
|
-
);
|
|
308
|
+
const result = await safe(this.client.get(path));
|
|
446
309
|
if (!result.ok) return result;
|
|
447
310
|
return ok(normalizeCatalogueResult(result.value));
|
|
448
311
|
}
|
|
449
312
|
async getProduct(id) {
|
|
450
313
|
const encodedId = encodeURIComponent(id);
|
|
451
|
-
const result = await
|
|
452
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}`),
|
|
453
|
-
() => this.client.query(`products.${id}`)
|
|
454
|
-
);
|
|
314
|
+
const result = await safe(this.client.get(`/api/v1/catalogue/products/${encodedId}`));
|
|
455
315
|
if (!result.ok) return result;
|
|
456
316
|
return ok(normalizeCatalogueProductPayload(result.value));
|
|
457
317
|
}
|
|
458
318
|
async getProductBySlug(slug) {
|
|
459
319
|
const encodedSlug = encodeURIComponent(slug);
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
);
|
|
463
|
-
if (restResult.ok) {
|
|
464
|
-
return ok(normalizeCatalogueProductPayload(restResult.value));
|
|
465
|
-
}
|
|
466
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
467
|
-
return restResult;
|
|
468
|
-
}
|
|
469
|
-
const filteredResult = await safe(
|
|
470
|
-
this.client.query(
|
|
471
|
-
`products[?(@.slug=='${escapeQueryValue(slug)}')]#limit(50)`
|
|
472
|
-
)
|
|
473
|
-
);
|
|
474
|
-
if (!filteredResult.ok) return filteredResult;
|
|
475
|
-
const exactMatch = findProductBySlug(filteredResult.value, slug);
|
|
476
|
-
if (exactMatch) {
|
|
477
|
-
return ok(normalizeCatalogueProductPayload(exactMatch));
|
|
478
|
-
}
|
|
479
|
-
if (filteredResult.value.length === 1) {
|
|
480
|
-
return ok(normalizeCatalogueProductPayload(filteredResult.value[0]));
|
|
481
|
-
}
|
|
482
|
-
const unfilteredResult = await safe(
|
|
483
|
-
this.client.query("products#limit(200)")
|
|
484
|
-
);
|
|
485
|
-
if (!unfilteredResult.ok) return unfilteredResult;
|
|
486
|
-
const fallbackMatch = findProductBySlug(unfilteredResult.value, slug);
|
|
487
|
-
if (!fallbackMatch) {
|
|
488
|
-
return err(new CimplifyError("NOT_FOUND", `Product not found: ${slug}`, false));
|
|
489
|
-
}
|
|
490
|
-
return ok(normalizeCatalogueProductPayload(fallbackMatch));
|
|
320
|
+
const result = await safe(this.client.get(`/api/v1/catalogue/products/slug/${encodedSlug}`));
|
|
321
|
+
if (!result.ok) return result;
|
|
322
|
+
return ok(normalizeCatalogueProductPayload(result.value));
|
|
491
323
|
}
|
|
492
324
|
async getVariants(productId) {
|
|
493
325
|
const encodedId = encodeURIComponent(productId);
|
|
494
|
-
return
|
|
495
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`),
|
|
496
|
-
() => this.client.query(`products.${productId}.variants`)
|
|
497
|
-
);
|
|
326
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variants`));
|
|
498
327
|
}
|
|
499
328
|
async getVariantAxes(productId) {
|
|
500
329
|
const encodedId = encodeURIComponent(productId);
|
|
501
|
-
return
|
|
502
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`),
|
|
503
|
-
() => this.client.query(`products.${productId}.variant_axes`)
|
|
504
|
-
);
|
|
330
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/variant-axes`));
|
|
505
331
|
}
|
|
506
|
-
/**
|
|
507
|
-
* Find a variant by axis selections (e.g., { "Size": "Large", "Color": "Red" })
|
|
508
|
-
* Returns the matching variant or null if no match found.
|
|
509
|
-
*/
|
|
510
332
|
async getVariantByAxisSelections(productId, selections) {
|
|
511
333
|
const encodedId = encodeURIComponent(productId);
|
|
512
|
-
return
|
|
513
|
-
|
|
334
|
+
return safe(
|
|
335
|
+
this.client.post(
|
|
514
336
|
`/api/v1/catalogue/products/${encodedId}/variants/find`,
|
|
515
337
|
{
|
|
516
338
|
axis_selections: selections
|
|
517
339
|
}
|
|
518
|
-
)
|
|
519
|
-
() => this.client.query(`products.${productId}.variant`, {
|
|
520
|
-
axis_selections: selections
|
|
521
|
-
})
|
|
340
|
+
)
|
|
522
341
|
);
|
|
523
342
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Get a specific variant by its ID
|
|
526
|
-
*/
|
|
527
343
|
async getVariantById(productId, variantId) {
|
|
528
344
|
const encodedProductId = encodeURIComponent(productId);
|
|
529
345
|
const encodedVariantId = encodeURIComponent(variantId);
|
|
530
|
-
return
|
|
531
|
-
|
|
346
|
+
return safe(
|
|
347
|
+
this.client.get(
|
|
532
348
|
`/api/v1/catalogue/products/${encodedProductId}/variants/${encodedVariantId}`
|
|
533
|
-
)
|
|
534
|
-
() => this.client.query(`products.${productId}.variant.${variantId}`)
|
|
349
|
+
)
|
|
535
350
|
);
|
|
536
351
|
}
|
|
537
352
|
async getAddOns(productId) {
|
|
538
353
|
const encodedId = encodeURIComponent(productId);
|
|
539
|
-
return
|
|
540
|
-
() => this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`),
|
|
541
|
-
() => this.client.query(`products.${productId}.add_ons`)
|
|
542
|
-
);
|
|
354
|
+
return safe(this.client.get(`/api/v1/catalogue/products/${encodedId}/add-ons`));
|
|
543
355
|
}
|
|
544
356
|
async getCategories() {
|
|
545
|
-
|
|
546
|
-
() => this.client.get("/api/v1/catalogue/categories"),
|
|
547
|
-
() => this.client.query("categories")
|
|
548
|
-
);
|
|
549
|
-
if (!result.ok) return result;
|
|
550
|
-
if (result.value.some(hasCategorySlug)) {
|
|
551
|
-
return result;
|
|
552
|
-
}
|
|
553
|
-
const catalogueResult = await safe(
|
|
554
|
-
this.client.query("catalogue#limit(1)")
|
|
555
|
-
);
|
|
556
|
-
if (!catalogueResult.ok) {
|
|
557
|
-
return result;
|
|
558
|
-
}
|
|
559
|
-
const fallbackCategories = Array.isArray(catalogueResult.value.categories) ? catalogueResult.value.categories : [];
|
|
560
|
-
return fallbackCategories.length > 0 ? ok(fallbackCategories) : result;
|
|
357
|
+
return safe(this.client.get("/api/v1/catalogue/categories"));
|
|
561
358
|
}
|
|
562
359
|
async getCategory(id) {
|
|
563
360
|
const encodedId = encodeURIComponent(id);
|
|
564
|
-
return
|
|
565
|
-
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}`),
|
|
566
|
-
() => this.client.query(`categories.${id}`)
|
|
567
|
-
);
|
|
361
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}`));
|
|
568
362
|
}
|
|
569
363
|
async getCategoryBySlug(slug) {
|
|
570
364
|
const encodedSlug = encodeURIComponent(slug);
|
|
571
|
-
|
|
572
|
-
if (restResult.ok) {
|
|
573
|
-
return restResult;
|
|
574
|
-
}
|
|
575
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
576
|
-
return restResult;
|
|
577
|
-
}
|
|
578
|
-
const result = await safe(
|
|
579
|
-
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
580
|
-
);
|
|
581
|
-
if (!result.ok) return result;
|
|
582
|
-
const exactMatch = findCategoryBySlug(result.value, slug);
|
|
583
|
-
if (exactMatch) {
|
|
584
|
-
return ok(exactMatch);
|
|
585
|
-
}
|
|
586
|
-
const categoriesResult = await this.getCategories();
|
|
587
|
-
if (!categoriesResult.ok) {
|
|
588
|
-
return categoriesResult;
|
|
589
|
-
}
|
|
590
|
-
const fallbackMatch = findCategoryBySlug(categoriesResult.value, slug);
|
|
591
|
-
if (!fallbackMatch) {
|
|
592
|
-
return err(new CimplifyError("NOT_FOUND", `Category not found: ${slug}`, false));
|
|
593
|
-
}
|
|
594
|
-
return ok(fallbackMatch);
|
|
365
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/slug/${encodedSlug}`));
|
|
595
366
|
}
|
|
596
367
|
async getCategoryProducts(categoryId) {
|
|
597
368
|
const encodedId = encodeURIComponent(categoryId);
|
|
598
|
-
return
|
|
599
|
-
() => this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`),
|
|
600
|
-
() => this.client.query(
|
|
601
|
-
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
602
|
-
)
|
|
603
|
-
);
|
|
369
|
+
return safe(this.client.get(`/api/v1/catalogue/categories/${encodedId}/products`));
|
|
604
370
|
}
|
|
605
371
|
async getCollections() {
|
|
606
|
-
return
|
|
607
|
-
() => this.client.get("/api/v1/catalogue/collections"),
|
|
608
|
-
() => this.client.query("collections")
|
|
609
|
-
);
|
|
372
|
+
return safe(this.client.get("/api/v1/catalogue/collections"));
|
|
610
373
|
}
|
|
611
374
|
async getCollection(id) {
|
|
612
375
|
const encodedId = encodeURIComponent(id);
|
|
613
|
-
return
|
|
614
|
-
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}`),
|
|
615
|
-
() => this.client.query(`collections.${id}`)
|
|
616
|
-
);
|
|
376
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}`));
|
|
617
377
|
}
|
|
618
378
|
async getCollectionBySlug(slug) {
|
|
619
379
|
const encodedSlug = encodeURIComponent(slug);
|
|
620
|
-
|
|
621
|
-
this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`)
|
|
622
|
-
);
|
|
623
|
-
if (restResult.ok) return restResult;
|
|
624
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
625
|
-
return restResult;
|
|
626
|
-
}
|
|
627
|
-
const result = await safe(
|
|
628
|
-
this.client.query(`collections[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
629
|
-
);
|
|
630
|
-
if (!result.ok) return result;
|
|
631
|
-
if (!result.value.length) {
|
|
632
|
-
return err(new CimplifyError("NOT_FOUND", `Collection not found: ${slug}`, false));
|
|
633
|
-
}
|
|
634
|
-
return ok(result.value[0]);
|
|
380
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/slug/${encodedSlug}`));
|
|
635
381
|
}
|
|
636
382
|
async getCollectionProducts(collectionId) {
|
|
637
383
|
const encodedId = encodeURIComponent(collectionId);
|
|
638
|
-
return
|
|
639
|
-
() => this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`),
|
|
640
|
-
() => this.client.query(`collections.${collectionId}.products`)
|
|
641
|
-
);
|
|
384
|
+
return safe(this.client.get(`/api/v1/catalogue/collections/${encodedId}/products`));
|
|
642
385
|
}
|
|
643
386
|
async searchCollections(query2, limit = 20) {
|
|
644
387
|
const path = withQuery("/api/v1/catalogue/collections", { search: query2, limit });
|
|
645
|
-
return
|
|
646
|
-
() => this.client.get(path),
|
|
647
|
-
() => this.client.query(
|
|
648
|
-
`collections[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
649
|
-
)
|
|
650
|
-
);
|
|
388
|
+
return safe(this.client.get(path));
|
|
651
389
|
}
|
|
652
390
|
async getBundles() {
|
|
653
|
-
return
|
|
654
|
-
() => this.client.get("/api/v1/catalogue/bundles"),
|
|
655
|
-
() => this.client.query("bundles")
|
|
656
|
-
);
|
|
391
|
+
return safe(this.client.get("/api/v1/catalogue/bundles"));
|
|
657
392
|
}
|
|
658
393
|
async getBundle(id) {
|
|
659
394
|
const encodedId = encodeURIComponent(id);
|
|
660
|
-
return
|
|
661
|
-
() => this.client.get(`/api/v1/catalogue/bundles/${encodedId}`),
|
|
662
|
-
() => this.client.query(`bundles.${id}`)
|
|
663
|
-
);
|
|
395
|
+
return safe(this.client.get(`/api/v1/catalogue/bundles/${encodedId}`));
|
|
664
396
|
}
|
|
665
397
|
async getBundleBySlug(slug) {
|
|
666
398
|
const encodedSlug = encodeURIComponent(slug);
|
|
667
|
-
|
|
668
|
-
this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`)
|
|
669
|
-
);
|
|
670
|
-
if (restResult.ok) return restResult;
|
|
671
|
-
if (restResult.error.code !== "HTTP_404" && restResult.error.code !== "API_ERROR") {
|
|
672
|
-
return restResult;
|
|
673
|
-
}
|
|
674
|
-
const result = await safe(
|
|
675
|
-
this.client.query(
|
|
676
|
-
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
677
|
-
)
|
|
678
|
-
);
|
|
679
|
-
if (!result.ok) return result;
|
|
680
|
-
if (!result.value.length) {
|
|
681
|
-
return err(new CimplifyError("NOT_FOUND", `Bundle not found: ${slug}`, false));
|
|
682
|
-
}
|
|
683
|
-
return ok(result.value[0]);
|
|
399
|
+
return safe(this.client.get(`/api/v1/catalogue/bundles/slug/${encodedSlug}`));
|
|
684
400
|
}
|
|
685
401
|
async searchBundles(query2, limit = 20) {
|
|
686
402
|
const path = withQuery("/api/v1/catalogue/bundles", { search: query2, limit });
|
|
687
|
-
return
|
|
688
|
-
() => this.client.get(path),
|
|
689
|
-
() => this.client.query(
|
|
690
|
-
`bundles[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
691
|
-
)
|
|
692
|
-
);
|
|
403
|
+
return safe(this.client.get(path));
|
|
693
404
|
}
|
|
694
405
|
async getComposites(options) {
|
|
695
|
-
let query2 = "composites";
|
|
696
|
-
if (options?.limit) {
|
|
697
|
-
query2 += `#limit(${options.limit})`;
|
|
698
|
-
}
|
|
699
406
|
const path = withQuery("/api/v1/catalogue/composites", { limit: options?.limit });
|
|
700
|
-
return
|
|
701
|
-
() => this.client.get(path),
|
|
702
|
-
() => this.client.query(query2)
|
|
703
|
-
);
|
|
407
|
+
return safe(this.client.get(path));
|
|
704
408
|
}
|
|
705
409
|
async getComposite(id) {
|
|
706
410
|
const encodedId = encodeURIComponent(id);
|
|
707
|
-
return
|
|
708
|
-
() => this.client.get(`/api/v1/catalogue/composites/${encodedId}`),
|
|
709
|
-
() => this.client.query(`composites.${id}`)
|
|
710
|
-
);
|
|
411
|
+
return safe(this.client.get(`/api/v1/catalogue/composites/${encodedId}`));
|
|
711
412
|
}
|
|
712
413
|
async getCompositeByProductId(productId) {
|
|
713
414
|
const encodedId = encodeURIComponent(productId);
|
|
714
|
-
return
|
|
715
|
-
|
|
415
|
+
return safe(
|
|
416
|
+
this.client.get(
|
|
716
417
|
`/api/v1/catalogue/composites/by-product/${encodedId}`
|
|
717
|
-
)
|
|
718
|
-
() => this.client.query(`composites.by_product.${productId}`)
|
|
418
|
+
)
|
|
719
419
|
);
|
|
720
420
|
}
|
|
721
421
|
async calculateCompositePrice(compositeId, selections, locationId) {
|
|
722
422
|
const encodedId = encodeURIComponent(compositeId);
|
|
723
|
-
return
|
|
724
|
-
|
|
423
|
+
return safe(
|
|
424
|
+
this.client.post(
|
|
725
425
|
`/api/v1/catalogue/composites/${encodedId}/calculate-price`,
|
|
726
426
|
{
|
|
727
427
|
selections,
|
|
728
428
|
location_id: locationId
|
|
729
429
|
}
|
|
730
|
-
)
|
|
731
|
-
() => this.client.call("composite.calculatePrice", {
|
|
732
|
-
composite_id: compositeId,
|
|
733
|
-
selections,
|
|
734
|
-
location_id: locationId
|
|
735
|
-
})
|
|
430
|
+
)
|
|
736
431
|
);
|
|
737
432
|
}
|
|
738
433
|
async fetchQuote(input) {
|
|
739
|
-
return
|
|
740
|
-
() => this.client.post("/api/v1/catalogue/quotes", input),
|
|
741
|
-
() => this.client.call("catalogue.createQuote", input)
|
|
742
|
-
);
|
|
434
|
+
return safe(this.client.post("/api/v1/catalogue/quotes", input));
|
|
743
435
|
}
|
|
744
436
|
async getQuote(quoteId) {
|
|
745
437
|
const encodedQuoteId = encodeURIComponent(quoteId);
|
|
746
|
-
return
|
|
747
|
-
() => this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`),
|
|
748
|
-
() => this.client.call("catalogue.getQuote", {
|
|
749
|
-
quote_id: quoteId
|
|
750
|
-
})
|
|
751
|
-
);
|
|
438
|
+
return safe(this.client.get(`/api/v1/catalogue/quotes/${encodedQuoteId}`));
|
|
752
439
|
}
|
|
753
440
|
async refreshQuote(input) {
|
|
754
441
|
const encodedQuoteId = encodeURIComponent(input.quote_id);
|
|
755
|
-
return
|
|
756
|
-
|
|
442
|
+
return safe(
|
|
443
|
+
this.client.post(
|
|
757
444
|
`/api/v1/catalogue/quotes/${encodedQuoteId}/refresh`,
|
|
758
445
|
input
|
|
759
|
-
)
|
|
760
|
-
() => this.client.call("catalogue.refreshQuote", input)
|
|
446
|
+
)
|
|
761
447
|
);
|
|
762
448
|
}
|
|
763
449
|
async search(query2, options) {
|
|
@@ -773,35 +459,19 @@ var CatalogueQueries = class {
|
|
|
773
459
|
return this.search(query2, options);
|
|
774
460
|
}
|
|
775
461
|
async getMenu(options) {
|
|
776
|
-
let query2 = "menu";
|
|
777
|
-
if (options?.category) {
|
|
778
|
-
query2 = `menu[?(@.category=='${escapeQueryValue(options.category)}')]`;
|
|
779
|
-
}
|
|
780
|
-
if (options?.limit) {
|
|
781
|
-
query2 += `#limit(${options.limit})`;
|
|
782
|
-
}
|
|
783
462
|
const path = withQuery("/api/v1/catalogue/menu", {
|
|
784
463
|
category_id: options?.category,
|
|
785
464
|
limit: options?.limit
|
|
786
465
|
});
|
|
787
|
-
return
|
|
788
|
-
() => this.client.get(path),
|
|
789
|
-
() => this.client.query(query2)
|
|
790
|
-
);
|
|
466
|
+
return safe(this.client.get(path));
|
|
791
467
|
}
|
|
792
468
|
async getMenuCategory(categoryId) {
|
|
793
469
|
const encodedId = encodeURIComponent(categoryId);
|
|
794
|
-
return
|
|
795
|
-
() => this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`),
|
|
796
|
-
() => this.client.query(`menu.category.${categoryId}`)
|
|
797
|
-
);
|
|
470
|
+
return safe(this.client.get(`/api/v1/catalogue/menu/categories/${encodedId}`));
|
|
798
471
|
}
|
|
799
472
|
async getMenuItem(itemId) {
|
|
800
473
|
const encodedId = encodeURIComponent(itemId);
|
|
801
|
-
return
|
|
802
|
-
() => this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`),
|
|
803
|
-
() => this.client.query(`menu.${itemId}`)
|
|
804
|
-
);
|
|
474
|
+
return safe(this.client.get(`/api/v1/catalogue/menu/items/${encodedId}`));
|
|
805
475
|
}
|
|
806
476
|
};
|
|
807
477
|
|
|
@@ -820,14 +490,6 @@ async function safe2(promise) {
|
|
|
820
490
|
return err(toCimplifyError2(error));
|
|
821
491
|
}
|
|
822
492
|
}
|
|
823
|
-
async function safeWithFallback2(primary, fallback) {
|
|
824
|
-
const primaryResult = await safe2(primary());
|
|
825
|
-
if (primaryResult.ok) return primaryResult;
|
|
826
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
827
|
-
return primaryResult;
|
|
828
|
-
}
|
|
829
|
-
return safe2(fallback());
|
|
830
|
-
}
|
|
831
493
|
function isUICartResponse(value) {
|
|
832
494
|
return "cart" in value;
|
|
833
495
|
}
|
|
@@ -839,36 +501,21 @@ var CartOperations = class {
|
|
|
839
501
|
this.client = client;
|
|
840
502
|
}
|
|
841
503
|
async get() {
|
|
842
|
-
const result = await
|
|
843
|
-
() => this.client.get("/api/v1/cart"),
|
|
844
|
-
() => this.client.query("cart#enriched")
|
|
845
|
-
);
|
|
504
|
+
const result = await safe2(this.client.get("/api/v1/cart"));
|
|
846
505
|
if (!result.ok) return result;
|
|
847
506
|
return ok(unwrapEnrichedCart(result.value));
|
|
848
507
|
}
|
|
849
508
|
async getRaw() {
|
|
850
|
-
return
|
|
851
|
-
() => this.client.get("/api/v1/cart"),
|
|
852
|
-
() => this.client.query("cart")
|
|
853
|
-
);
|
|
509
|
+
return safe2(this.client.get("/api/v1/cart"));
|
|
854
510
|
}
|
|
855
511
|
async getItems() {
|
|
856
|
-
return
|
|
857
|
-
() => this.client.get("/api/v1/cart/items"),
|
|
858
|
-
() => this.client.query("cart_items")
|
|
859
|
-
);
|
|
512
|
+
return safe2(this.client.get("/api/v1/cart/items"));
|
|
860
513
|
}
|
|
861
514
|
async getCount() {
|
|
862
|
-
return
|
|
863
|
-
() => this.client.get("/api/v1/cart/count"),
|
|
864
|
-
() => this.client.query("cart#count")
|
|
865
|
-
);
|
|
515
|
+
return safe2(this.client.get("/api/v1/cart/count"));
|
|
866
516
|
}
|
|
867
517
|
async getTotal() {
|
|
868
|
-
return
|
|
869
|
-
() => this.client.get("/api/v1/cart/total"),
|
|
870
|
-
() => this.client.query("cart#total")
|
|
871
|
-
);
|
|
518
|
+
return safe2(this.client.get("/api/v1/cart/total"));
|
|
872
519
|
}
|
|
873
520
|
async getSummary() {
|
|
874
521
|
const cartResult = await this.get();
|
|
@@ -885,66 +532,39 @@ var CartOperations = class {
|
|
|
885
532
|
});
|
|
886
533
|
}
|
|
887
534
|
async addItem(input) {
|
|
888
|
-
return
|
|
889
|
-
() => this.client.post("/api/v1/cart/items", input),
|
|
890
|
-
() => this.client.call("cart.addItem", input)
|
|
891
|
-
);
|
|
535
|
+
return safe2(this.client.post("/api/v1/cart/items", input));
|
|
892
536
|
}
|
|
893
537
|
async updateItem(cartItemId, updates) {
|
|
894
538
|
if (typeof updates.quantity === "number") {
|
|
895
539
|
return this.updateQuantity(cartItemId, updates.quantity);
|
|
896
540
|
}
|
|
897
541
|
const encodedId = encodeURIComponent(cartItemId);
|
|
898
|
-
return
|
|
899
|
-
() => this.client.patch(`/api/v1/cart/items/${encodedId}`, updates),
|
|
900
|
-
() => this.client.call("cart.updateItem", {
|
|
901
|
-
cart_item_id: cartItemId,
|
|
902
|
-
...updates
|
|
903
|
-
})
|
|
904
|
-
);
|
|
542
|
+
return safe2(this.client.patch(`/api/v1/cart/items/${encodedId}`, updates));
|
|
905
543
|
}
|
|
906
544
|
async updateQuantity(cartItemId, quantity) {
|
|
907
545
|
const encodedId = encodeURIComponent(cartItemId);
|
|
908
|
-
return
|
|
909
|
-
|
|
910
|
-
quantity
|
|
911
|
-
}),
|
|
912
|
-
() => this.client.call("cart.updateItemQuantity", {
|
|
913
|
-
cart_item_id: cartItemId,
|
|
546
|
+
return safe2(
|
|
547
|
+
this.client.patch(`/api/v1/cart/items/${encodedId}`, {
|
|
914
548
|
quantity
|
|
915
549
|
})
|
|
916
550
|
);
|
|
917
551
|
}
|
|
918
552
|
async removeItem(cartItemId) {
|
|
919
553
|
const encodedId = encodeURIComponent(cartItemId);
|
|
920
|
-
return
|
|
921
|
-
() => this.client.delete(`/api/v1/cart/items/${encodedId}`),
|
|
922
|
-
() => this.client.call("cart.removeItem", {
|
|
923
|
-
cart_item_id: cartItemId
|
|
924
|
-
})
|
|
925
|
-
);
|
|
554
|
+
return safe2(this.client.delete(`/api/v1/cart/items/${encodedId}`));
|
|
926
555
|
}
|
|
927
556
|
async clear() {
|
|
928
|
-
return
|
|
929
|
-
() => this.client.delete("/api/v1/cart"),
|
|
930
|
-
() => this.client.call("cart.clearCart")
|
|
931
|
-
);
|
|
557
|
+
return safe2(this.client.delete("/api/v1/cart"));
|
|
932
558
|
}
|
|
933
559
|
async applyCoupon(code) {
|
|
934
|
-
return
|
|
935
|
-
|
|
936
|
-
coupon_code: code
|
|
937
|
-
}),
|
|
938
|
-
() => this.client.call("cart.applyCoupon", {
|
|
560
|
+
return safe2(
|
|
561
|
+
this.client.post("/api/v1/cart/coupons", {
|
|
939
562
|
coupon_code: code
|
|
940
563
|
})
|
|
941
564
|
);
|
|
942
565
|
}
|
|
943
566
|
async removeCoupon() {
|
|
944
|
-
return
|
|
945
|
-
() => this.client.delete("/api/v1/cart/coupons/current"),
|
|
946
|
-
() => this.client.call("cart.removeCoupon")
|
|
947
|
-
);
|
|
567
|
+
return safe2(this.client.delete("/api/v1/cart/coupons/current"));
|
|
948
568
|
}
|
|
949
569
|
async isEmpty() {
|
|
950
570
|
const countResult = await this.getCount();
|
|
@@ -981,35 +601,6 @@ var CartOperations = class {
|
|
|
981
601
|
}
|
|
982
602
|
};
|
|
983
603
|
|
|
984
|
-
// src/constants.ts
|
|
985
|
-
var LINK_QUERY = {
|
|
986
|
-
PREFERENCES: "link.preferences"};
|
|
987
|
-
var LINK_MUTATION = {
|
|
988
|
-
CHECK_STATUS: "link.check_status",
|
|
989
|
-
ENROLL: "link.enroll",
|
|
990
|
-
ENROLL_AND_LINK_ORDER: "link.enroll_and_link_order",
|
|
991
|
-
UPDATE_PREFERENCES: "link.update_preferences",
|
|
992
|
-
CREATE_ADDRESS: "link.create_address",
|
|
993
|
-
UPDATE_ADDRESS: "link.update_address",
|
|
994
|
-
TRACK_ADDRESS_USAGE: "link.track_address_usage",
|
|
995
|
-
CREATE_MOBILE_MONEY: "link.create_mobile_money",
|
|
996
|
-
TRACK_MOBILE_MONEY_USAGE: "link.track_mobile_money_usage",
|
|
997
|
-
VERIFY_MOBILE_MONEY: "link.verify_mobile_money"};
|
|
998
|
-
var AUTH_MUTATION = {
|
|
999
|
-
REQUEST_OTP: "auth.request_otp",
|
|
1000
|
-
VERIFY_OTP: "auth.verify_otp"
|
|
1001
|
-
};
|
|
1002
|
-
var CHECKOUT_MUTATION = {
|
|
1003
|
-
PROCESS: "checkout.process"
|
|
1004
|
-
};
|
|
1005
|
-
var PAYMENT_MUTATION = {
|
|
1006
|
-
SUBMIT_AUTHORIZATION: "payment.submit_authorization",
|
|
1007
|
-
CHECK_STATUS: "order.poll_payment_status"
|
|
1008
|
-
};
|
|
1009
|
-
var ORDER_MUTATION = {
|
|
1010
|
-
UPDATE_CUSTOMER: "order.update_order_customer"
|
|
1011
|
-
};
|
|
1012
|
-
|
|
1013
604
|
// src/utils/payment.ts
|
|
1014
605
|
var PAYMENT_SUCCESS_STATUSES = /* @__PURE__ */ new Set([
|
|
1015
606
|
"success",
|
|
@@ -1704,14 +1295,6 @@ async function safe3(promise) {
|
|
|
1704
1295
|
return err(toCimplifyError3(error));
|
|
1705
1296
|
}
|
|
1706
1297
|
}
|
|
1707
|
-
async function safeWithFallback3(primary, fallback) {
|
|
1708
|
-
const primaryResult = await safe3(primary());
|
|
1709
|
-
if (primaryResult.ok) return primaryResult;
|
|
1710
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1711
|
-
return primaryResult;
|
|
1712
|
-
}
|
|
1713
|
-
return safe3(fallback());
|
|
1714
|
-
}
|
|
1715
1298
|
function toTerminalFailure(code, message, recoverable) {
|
|
1716
1299
|
return {
|
|
1717
1300
|
success: false,
|
|
@@ -1743,11 +1326,8 @@ var CheckoutService = class {
|
|
|
1743
1326
|
...data,
|
|
1744
1327
|
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
1745
1328
|
};
|
|
1746
|
-
const result = await
|
|
1747
|
-
|
|
1748
|
-
checkout_data: checkoutData
|
|
1749
|
-
}),
|
|
1750
|
-
() => this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
1329
|
+
const result = await safe3(
|
|
1330
|
+
this.client.post("/api/v1/checkout", {
|
|
1751
1331
|
checkout_data: checkoutData
|
|
1752
1332
|
})
|
|
1753
1333
|
);
|
|
@@ -1756,45 +1336,32 @@ var CheckoutService = class {
|
|
|
1756
1336
|
}
|
|
1757
1337
|
return result;
|
|
1758
1338
|
}
|
|
1759
|
-
async initializePayment(
|
|
1760
|
-
return
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1339
|
+
async initializePayment(_orderId, _method) {
|
|
1340
|
+
return err(
|
|
1341
|
+
new CimplifyError(
|
|
1342
|
+
"NOT_IMPLEMENTED",
|
|
1343
|
+
"initializePayment is not available in REST mode.",
|
|
1344
|
+
false
|
|
1345
|
+
)
|
|
1765
1346
|
);
|
|
1766
1347
|
}
|
|
1767
1348
|
async submitAuthorization(input) {
|
|
1768
|
-
return
|
|
1769
|
-
() => this.client.post("/api/v1/payments/authorization", input),
|
|
1770
|
-
() => this.client.call(PAYMENT_MUTATION.SUBMIT_AUTHORIZATION, input)
|
|
1771
|
-
);
|
|
1349
|
+
return safe3(this.client.post("/api/v1/payments/authorization", input));
|
|
1772
1350
|
}
|
|
1773
1351
|
async pollPaymentStatus(orderId) {
|
|
1774
1352
|
const encodedId = encodeURIComponent(orderId);
|
|
1775
1353
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1776
|
-
return
|
|
1777
|
-
() => this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`),
|
|
1778
|
-
() => this.client.call(PAYMENT_MUTATION.CHECK_STATUS, orderId)
|
|
1779
|
-
);
|
|
1354
|
+
return safe3(this.client.get(`/api/v1/orders/${encodedId}/payment-status${tokenParam}`));
|
|
1780
1355
|
}
|
|
1781
1356
|
async updateOrderCustomer(orderId, customer) {
|
|
1782
1357
|
const encodedId = encodeURIComponent(orderId);
|
|
1783
1358
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1784
|
-
return
|
|
1785
|
-
() => this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer),
|
|
1786
|
-
() => this.client.call(ORDER_MUTATION.UPDATE_CUSTOMER, {
|
|
1787
|
-
order_id: orderId,
|
|
1788
|
-
...customer
|
|
1789
|
-
})
|
|
1790
|
-
);
|
|
1359
|
+
return safe3(this.client.post(`/api/v1/orders/${encodedId}/customer${tokenParam}`, customer));
|
|
1791
1360
|
}
|
|
1792
1361
|
async verifyPayment(orderId) {
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
})
|
|
1797
|
-
);
|
|
1362
|
+
const encodedId = encodeURIComponent(orderId);
|
|
1363
|
+
const tokenParam = this.orderTokenParam(orderId);
|
|
1364
|
+
return safe3(this.client.post(`/api/v1/orders/${encodedId}/verify-payment${tokenParam}`));
|
|
1798
1365
|
}
|
|
1799
1366
|
async processAndResolve(data) {
|
|
1800
1367
|
data.on_status_change?.("preparing", {});
|
|
@@ -1913,14 +1480,6 @@ async function safe4(promise) {
|
|
|
1913
1480
|
return err(toCimplifyError4(error));
|
|
1914
1481
|
}
|
|
1915
1482
|
}
|
|
1916
|
-
async function safeWithFallback4(primary, fallback) {
|
|
1917
|
-
const primaryResult = await safe4(primary());
|
|
1918
|
-
if (primaryResult.ok) return primaryResult;
|
|
1919
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
1920
|
-
return primaryResult;
|
|
1921
|
-
}
|
|
1922
|
-
return safe4(fallback());
|
|
1923
|
-
}
|
|
1924
1483
|
var OrderQueries = class {
|
|
1925
1484
|
constructor(client) {
|
|
1926
1485
|
this.client = client;
|
|
@@ -1930,37 +1489,20 @@ var OrderQueries = class {
|
|
|
1930
1489
|
return token ? `?token=${encodeURIComponent(token)}` : "";
|
|
1931
1490
|
}
|
|
1932
1491
|
async list(options) {
|
|
1933
|
-
let query2 = "orders";
|
|
1934
|
-
if (options?.status) {
|
|
1935
|
-
query2 += `[?(@.status=='${options.status}')]`;
|
|
1936
|
-
}
|
|
1937
|
-
query2 += "#sort(created_at,desc)";
|
|
1938
|
-
if (options?.limit) {
|
|
1939
|
-
query2 += `#limit(${options.limit})`;
|
|
1940
|
-
}
|
|
1941
|
-
if (options?.offset) {
|
|
1942
|
-
query2 += `#offset(${options.offset})`;
|
|
1943
|
-
}
|
|
1944
1492
|
const params = new URLSearchParams();
|
|
1945
1493
|
if (options?.status) params.set("status", options.status);
|
|
1946
1494
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
1947
1495
|
if (options?.offset) params.set("offset", String(options.offset));
|
|
1948
1496
|
const path = params.toString() ? `/api/v1/orders?${params.toString()}` : "/api/v1/orders";
|
|
1949
|
-
return
|
|
1950
|
-
() => this.client.get(path),
|
|
1951
|
-
() => this.client.query(query2)
|
|
1952
|
-
);
|
|
1497
|
+
return safe4(this.client.get(path));
|
|
1953
1498
|
}
|
|
1954
1499
|
async get(orderId) {
|
|
1955
1500
|
const encodedId = encodeURIComponent(orderId);
|
|
1956
1501
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1957
|
-
return
|
|
1958
|
-
() => this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`),
|
|
1959
|
-
() => this.client.query(`orders.${orderId}`)
|
|
1960
|
-
);
|
|
1502
|
+
return safe4(this.client.get(`/api/v1/orders/${encodedId}${tokenParam}`));
|
|
1961
1503
|
}
|
|
1962
1504
|
async getRecent(limit = 5) {
|
|
1963
|
-
return
|
|
1505
|
+
return this.list({ limit });
|
|
1964
1506
|
}
|
|
1965
1507
|
async getByStatus(status) {
|
|
1966
1508
|
return this.list({ status });
|
|
@@ -1968,12 +1510,8 @@ var OrderQueries = class {
|
|
|
1968
1510
|
async cancel(orderId, reason) {
|
|
1969
1511
|
const encodedId = encodeURIComponent(orderId);
|
|
1970
1512
|
const tokenParam = this.orderTokenParam(orderId);
|
|
1971
|
-
return
|
|
1972
|
-
|
|
1973
|
-
reason
|
|
1974
|
-
}),
|
|
1975
|
-
() => this.client.call("order.cancelOrder", {
|
|
1976
|
-
order_id: orderId,
|
|
1513
|
+
return safe4(
|
|
1514
|
+
this.client.post(`/api/v1/orders/${encodedId}/cancel${tokenParam}`, {
|
|
1977
1515
|
reason
|
|
1978
1516
|
})
|
|
1979
1517
|
);
|
|
@@ -1995,6 +1533,38 @@ async function safe5(promise) {
|
|
|
1995
1533
|
return err(toCimplifyError5(error));
|
|
1996
1534
|
}
|
|
1997
1535
|
}
|
|
1536
|
+
function encodePathSegment(value) {
|
|
1537
|
+
return encodeURIComponent(value);
|
|
1538
|
+
}
|
|
1539
|
+
function toCreateAddressPayload(input) {
|
|
1540
|
+
return {
|
|
1541
|
+
label: input.label,
|
|
1542
|
+
street_address: input.address_line1,
|
|
1543
|
+
apartment: input.address_line2,
|
|
1544
|
+
city: input.city,
|
|
1545
|
+
region: input.state ?? "",
|
|
1546
|
+
postal_code: input.postal_code,
|
|
1547
|
+
country: input.country
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
function toUpdateAddressPayload(input) {
|
|
1551
|
+
return {
|
|
1552
|
+
label: input.label,
|
|
1553
|
+
street_address: input.address_line1,
|
|
1554
|
+
apartment: input.address_line2,
|
|
1555
|
+
city: input.city,
|
|
1556
|
+
region: input.state,
|
|
1557
|
+
postal_code: input.postal_code,
|
|
1558
|
+
country: input.country
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
function toCreateMobileMoneyPayload(input) {
|
|
1562
|
+
return {
|
|
1563
|
+
phone_number: input.phone_number,
|
|
1564
|
+
provider: input.provider,
|
|
1565
|
+
label: input.account_name
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1998
1568
|
var LinkService = class {
|
|
1999
1569
|
constructor(client) {
|
|
2000
1570
|
this.client = client;
|
|
@@ -2022,11 +1592,7 @@ var LinkService = class {
|
|
|
2022
1592
|
return result;
|
|
2023
1593
|
}
|
|
2024
1594
|
async checkStatus(contact) {
|
|
2025
|
-
return safe5(
|
|
2026
|
-
this.client.call(LINK_MUTATION.CHECK_STATUS, {
|
|
2027
|
-
contact
|
|
2028
|
-
})
|
|
2029
|
-
);
|
|
1595
|
+
return safe5(this.client.linkPost("/v1/link/check-status", { contact }));
|
|
2030
1596
|
}
|
|
2031
1597
|
async getLinkData() {
|
|
2032
1598
|
return safe5(this.client.linkGet("/v1/link/data"));
|
|
@@ -2038,61 +1604,85 @@ var LinkService = class {
|
|
|
2038
1604
|
return safe5(this.client.linkGet("/v1/link/mobile-money"));
|
|
2039
1605
|
}
|
|
2040
1606
|
async getPreferences() {
|
|
2041
|
-
return safe5(this.client.
|
|
1607
|
+
return safe5(this.client.linkGet("/v1/link/preferences"));
|
|
2042
1608
|
}
|
|
2043
1609
|
async enroll(data) {
|
|
2044
|
-
return safe5(this.client.
|
|
1610
|
+
return safe5(this.client.linkPost("/v1/link/enroll", data));
|
|
2045
1611
|
}
|
|
2046
1612
|
async enrollAndLinkOrder(data) {
|
|
2047
1613
|
return safe5(
|
|
2048
|
-
this.client.
|
|
1614
|
+
this.client.linkPost("/v1/link/enroll-and-link-order", data)
|
|
2049
1615
|
);
|
|
2050
1616
|
}
|
|
2051
1617
|
async updatePreferences(preferences) {
|
|
2052
|
-
return safe5(this.client.
|
|
1618
|
+
return safe5(this.client.linkPost("/v1/link/preferences", preferences));
|
|
2053
1619
|
}
|
|
2054
1620
|
async createAddress(input) {
|
|
2055
|
-
return safe5(
|
|
1621
|
+
return safe5(
|
|
1622
|
+
this.client.linkPost("/v1/link/addresses", toCreateAddressPayload(input))
|
|
1623
|
+
);
|
|
2056
1624
|
}
|
|
2057
1625
|
async updateAddress(input) {
|
|
2058
|
-
return safe5(
|
|
1626
|
+
return safe5(
|
|
1627
|
+
this.client.linkPost(
|
|
1628
|
+
`/v1/link/addresses/${encodePathSegment(input.address_id)}`,
|
|
1629
|
+
toUpdateAddressPayload(input)
|
|
1630
|
+
)
|
|
1631
|
+
);
|
|
2059
1632
|
}
|
|
2060
1633
|
async deleteAddress(addressId) {
|
|
2061
|
-
return safe5(
|
|
1634
|
+
return safe5(
|
|
1635
|
+
this.client.linkDelete(`/v1/link/addresses/${encodePathSegment(addressId)}`)
|
|
1636
|
+
);
|
|
2062
1637
|
}
|
|
2063
1638
|
async setDefaultAddress(addressId) {
|
|
2064
|
-
return safe5(
|
|
1639
|
+
return safe5(
|
|
1640
|
+
this.client.linkPost(
|
|
1641
|
+
`/v1/link/addresses/${encodePathSegment(addressId)}/default`
|
|
1642
|
+
)
|
|
1643
|
+
);
|
|
2065
1644
|
}
|
|
2066
1645
|
async trackAddressUsage(addressId) {
|
|
2067
1646
|
return safe5(
|
|
2068
|
-
this.client.
|
|
2069
|
-
|
|
2070
|
-
|
|
1647
|
+
this.client.linkPost(
|
|
1648
|
+
`/v1/link/addresses/${encodePathSegment(addressId)}/track-usage`
|
|
1649
|
+
)
|
|
2071
1650
|
);
|
|
2072
1651
|
}
|
|
2073
1652
|
async createMobileMoney(input) {
|
|
2074
|
-
return safe5(
|
|
1653
|
+
return safe5(
|
|
1654
|
+
this.client.linkPost(
|
|
1655
|
+
"/v1/link/mobile-money",
|
|
1656
|
+
toCreateMobileMoneyPayload(input)
|
|
1657
|
+
)
|
|
1658
|
+
);
|
|
2075
1659
|
}
|
|
2076
1660
|
async deleteMobileMoney(mobileMoneyId) {
|
|
2077
1661
|
return safe5(
|
|
2078
|
-
this.client.linkDelete(
|
|
1662
|
+
this.client.linkDelete(
|
|
1663
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}`
|
|
1664
|
+
)
|
|
2079
1665
|
);
|
|
2080
1666
|
}
|
|
2081
1667
|
async setDefaultMobileMoney(mobileMoneyId) {
|
|
2082
1668
|
return safe5(
|
|
2083
|
-
this.client.linkPost(
|
|
1669
|
+
this.client.linkPost(
|
|
1670
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/default`
|
|
1671
|
+
)
|
|
2084
1672
|
);
|
|
2085
1673
|
}
|
|
2086
1674
|
async trackMobileMoneyUsage(mobileMoneyId) {
|
|
2087
1675
|
return safe5(
|
|
2088
|
-
this.client.
|
|
2089
|
-
|
|
2090
|
-
|
|
1676
|
+
this.client.linkPost(
|
|
1677
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/track-usage`
|
|
1678
|
+
)
|
|
2091
1679
|
);
|
|
2092
1680
|
}
|
|
2093
1681
|
async verifyMobileMoney(mobileMoneyId) {
|
|
2094
1682
|
return safe5(
|
|
2095
|
-
this.client.
|
|
1683
|
+
this.client.linkPost(
|
|
1684
|
+
`/v1/link/mobile-money/${encodePathSegment(mobileMoneyId)}/verify`
|
|
1685
|
+
)
|
|
2096
1686
|
);
|
|
2097
1687
|
}
|
|
2098
1688
|
async getSessions() {
|
|
@@ -2105,30 +1695,28 @@ var LinkService = class {
|
|
|
2105
1695
|
return safe5(this.client.linkDelete("/v1/link/sessions"));
|
|
2106
1696
|
}
|
|
2107
1697
|
async getAddressesRest() {
|
|
2108
|
-
return
|
|
1698
|
+
return this.getAddresses();
|
|
2109
1699
|
}
|
|
2110
1700
|
async createAddressRest(input) {
|
|
2111
|
-
return
|
|
1701
|
+
return this.createAddress(input);
|
|
2112
1702
|
}
|
|
2113
1703
|
async deleteAddressRest(addressId) {
|
|
2114
|
-
return
|
|
1704
|
+
return this.deleteAddress(addressId);
|
|
2115
1705
|
}
|
|
2116
1706
|
async setDefaultAddressRest(addressId) {
|
|
2117
|
-
return
|
|
1707
|
+
return this.setDefaultAddress(addressId);
|
|
2118
1708
|
}
|
|
2119
1709
|
async getMobileMoneyRest() {
|
|
2120
|
-
return
|
|
1710
|
+
return this.getMobileMoney();
|
|
2121
1711
|
}
|
|
2122
1712
|
async createMobileMoneyRest(input) {
|
|
2123
|
-
return
|
|
1713
|
+
return this.createMobileMoney(input);
|
|
2124
1714
|
}
|
|
2125
1715
|
async deleteMobileMoneyRest(mobileMoneyId) {
|
|
2126
|
-
return
|
|
1716
|
+
return this.deleteMobileMoney(mobileMoneyId);
|
|
2127
1717
|
}
|
|
2128
1718
|
async setDefaultMobileMoneyRest(mobileMoneyId) {
|
|
2129
|
-
return
|
|
2130
|
-
this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
|
|
2131
|
-
);
|
|
1719
|
+
return this.setDefaultMobileMoney(mobileMoneyId);
|
|
2132
1720
|
}
|
|
2133
1721
|
};
|
|
2134
1722
|
|
|
@@ -2147,23 +1735,12 @@ async function safe6(promise) {
|
|
|
2147
1735
|
return err(toCimplifyError6(error));
|
|
2148
1736
|
}
|
|
2149
1737
|
}
|
|
2150
|
-
async function safeWithFallback5(primary, fallback) {
|
|
2151
|
-
const primaryResult = await safe6(primary());
|
|
2152
|
-
if (primaryResult.ok) return primaryResult;
|
|
2153
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2154
|
-
return primaryResult;
|
|
2155
|
-
}
|
|
2156
|
-
return safe6(fallback());
|
|
2157
|
-
}
|
|
2158
1738
|
var AuthService = class {
|
|
2159
1739
|
constructor(client) {
|
|
2160
1740
|
this.client = client;
|
|
2161
1741
|
}
|
|
2162
1742
|
async getStatus() {
|
|
2163
|
-
return
|
|
2164
|
-
() => this.client.get("/api/v1/auth/status"),
|
|
2165
|
-
() => this.client.query("auth")
|
|
2166
|
-
);
|
|
1743
|
+
return safe6(this.client.get("/api/v1/auth/status"));
|
|
2167
1744
|
}
|
|
2168
1745
|
async getCurrentUser() {
|
|
2169
1746
|
const result = await this.getStatus();
|
|
@@ -2176,43 +1753,26 @@ var AuthService = class {
|
|
|
2176
1753
|
return ok(result.value.is_authenticated);
|
|
2177
1754
|
}
|
|
2178
1755
|
async requestOtp(contact, contactType) {
|
|
2179
|
-
return
|
|
2180
|
-
|
|
2181
|
-
contact,
|
|
2182
|
-
contact_type: contactType
|
|
2183
|
-
}),
|
|
2184
|
-
() => this.client.call(AUTH_MUTATION.REQUEST_OTP, {
|
|
1756
|
+
return safe6(
|
|
1757
|
+
this.client.post("/api/v1/auth/request-otp", {
|
|
2185
1758
|
contact,
|
|
2186
1759
|
contact_type: contactType
|
|
2187
1760
|
})
|
|
2188
1761
|
);
|
|
2189
1762
|
}
|
|
2190
1763
|
async verifyOtp(code, contact) {
|
|
2191
|
-
return
|
|
2192
|
-
|
|
2193
|
-
otp_code: code,
|
|
2194
|
-
contact
|
|
2195
|
-
}),
|
|
2196
|
-
() => this.client.call(AUTH_MUTATION.VERIFY_OTP, {
|
|
1764
|
+
return safe6(
|
|
1765
|
+
this.client.post("/api/v1/auth/verify-otp", {
|
|
2197
1766
|
otp_code: code,
|
|
2198
1767
|
contact
|
|
2199
1768
|
})
|
|
2200
1769
|
);
|
|
2201
1770
|
}
|
|
2202
1771
|
async logout() {
|
|
2203
|
-
return
|
|
2204
|
-
() => this.client.post("/api/v1/auth/logout"),
|
|
2205
|
-
() => this.client.call("auth.logout")
|
|
2206
|
-
);
|
|
1772
|
+
return safe6(this.client.post("/api/v1/auth/logout"));
|
|
2207
1773
|
}
|
|
2208
1774
|
async updateProfile(input) {
|
|
2209
|
-
return safe6(this.client.
|
|
2210
|
-
}
|
|
2211
|
-
async changePassword(input) {
|
|
2212
|
-
return safe6(this.client.call("auth.change_password", input));
|
|
2213
|
-
}
|
|
2214
|
-
async resetPassword(email) {
|
|
2215
|
-
return safe6(this.client.call("auth.reset_password", { email }));
|
|
1775
|
+
return safe6(this.client.post("/api/v1/auth/profile", input));
|
|
2216
1776
|
}
|
|
2217
1777
|
};
|
|
2218
1778
|
|
|
@@ -2231,47 +1791,29 @@ async function safe7(promise) {
|
|
|
2231
1791
|
return err(toCimplifyError7(error));
|
|
2232
1792
|
}
|
|
2233
1793
|
}
|
|
2234
|
-
async function safeWithFallback6(primary, fallback) {
|
|
2235
|
-
const primaryResult = await safe7(primary());
|
|
2236
|
-
if (primaryResult.ok) return primaryResult;
|
|
2237
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2238
|
-
return primaryResult;
|
|
2239
|
-
}
|
|
2240
|
-
return safe7(fallback());
|
|
2241
|
-
}
|
|
2242
1794
|
var BusinessService = class {
|
|
2243
1795
|
constructor(client) {
|
|
2244
1796
|
this.client = client;
|
|
2245
1797
|
}
|
|
2246
1798
|
async getInfo() {
|
|
2247
|
-
return
|
|
2248
|
-
() => this.client.get("/api/v1/business"),
|
|
2249
|
-
() => this.client.query("business.info")
|
|
2250
|
-
);
|
|
1799
|
+
return safe7(this.client.get("/api/v1/business"));
|
|
2251
1800
|
}
|
|
2252
1801
|
async getByHandle(handle) {
|
|
2253
|
-
|
|
1802
|
+
const encodedHandle = encodeURIComponent(handle);
|
|
1803
|
+
return safe7(this.client.get(`/api/v1/business/by-handle/${encodedHandle}`));
|
|
2254
1804
|
}
|
|
2255
1805
|
async getByDomain(domain) {
|
|
2256
|
-
|
|
1806
|
+
const encodedDomain = encodeURIComponent(domain);
|
|
1807
|
+
return safe7(this.client.get(`/api/v1/business/by-domain?domain=${encodedDomain}`));
|
|
2257
1808
|
}
|
|
2258
1809
|
async getSettings() {
|
|
2259
|
-
return
|
|
2260
|
-
() => this.client.get("/api/v1/business/settings"),
|
|
2261
|
-
() => this.client.query("business.settings")
|
|
2262
|
-
);
|
|
1810
|
+
return safe7(this.client.get("/api/v1/business/settings"));
|
|
2263
1811
|
}
|
|
2264
1812
|
async getTheme() {
|
|
2265
|
-
return
|
|
2266
|
-
() => this.client.get("/api/v1/business/theme"),
|
|
2267
|
-
() => this.client.query("business.theme")
|
|
2268
|
-
);
|
|
1813
|
+
return safe7(this.client.get("/api/v1/business/theme"));
|
|
2269
1814
|
}
|
|
2270
1815
|
async getLocations() {
|
|
2271
|
-
return
|
|
2272
|
-
() => this.client.get("/api/v1/business/locations"),
|
|
2273
|
-
() => this.client.query("business.locations")
|
|
2274
|
-
);
|
|
1816
|
+
return safe7(this.client.get("/api/v1/business/locations"));
|
|
2275
1817
|
}
|
|
2276
1818
|
async getLocation(locationId) {
|
|
2277
1819
|
const result = await this.getLocations();
|
|
@@ -2283,10 +1825,7 @@ var BusinessService = class {
|
|
|
2283
1825
|
return ok(location);
|
|
2284
1826
|
}
|
|
2285
1827
|
async getHours() {
|
|
2286
|
-
return
|
|
2287
|
-
() => this.client.get("/api/v1/business/hours"),
|
|
2288
|
-
() => this.client.query("business.hours")
|
|
2289
|
-
);
|
|
1828
|
+
return safe7(this.client.get("/api/v1/business/hours"));
|
|
2290
1829
|
}
|
|
2291
1830
|
async getLocationHours(locationId) {
|
|
2292
1831
|
const result = await this.getHours();
|
|
@@ -2294,31 +1833,7 @@ var BusinessService = class {
|
|
|
2294
1833
|
return ok(result.value.filter((hour) => hour.location_id === locationId));
|
|
2295
1834
|
}
|
|
2296
1835
|
async getBootstrap() {
|
|
2297
|
-
|
|
2298
|
-
if (restBootstrap.ok) {
|
|
2299
|
-
return restBootstrap;
|
|
2300
|
-
}
|
|
2301
|
-
const [businessResult, locationsResult, categoriesResult] = await Promise.all([
|
|
2302
|
-
this.getInfo(),
|
|
2303
|
-
this.getLocations(),
|
|
2304
|
-
safe7(this.client.query("categories#select(id,name,slug)"))
|
|
2305
|
-
]);
|
|
2306
|
-
if (!businessResult.ok) return businessResult;
|
|
2307
|
-
if (!locationsResult.ok) return locationsResult;
|
|
2308
|
-
if (!categoriesResult.ok) return categoriesResult;
|
|
2309
|
-
const business = businessResult.value;
|
|
2310
|
-
const locations = locationsResult.value;
|
|
2311
|
-
const categories = categoriesResult.value;
|
|
2312
|
-
const defaultLocation = locations[0];
|
|
2313
|
-
return ok({
|
|
2314
|
-
business,
|
|
2315
|
-
location: defaultLocation,
|
|
2316
|
-
locations,
|
|
2317
|
-
categories,
|
|
2318
|
-
currency: business.default_currency,
|
|
2319
|
-
is_open: defaultLocation?.accepts_online_orders ?? false,
|
|
2320
|
-
accepts_orders: defaultLocation?.accepts_online_orders ?? false
|
|
2321
|
-
});
|
|
1836
|
+
return safe7(this.client.get("/api/v1/bootstrap"));
|
|
2322
1837
|
}
|
|
2323
1838
|
};
|
|
2324
1839
|
|
|
@@ -2341,49 +1856,47 @@ var InventoryService = class {
|
|
|
2341
1856
|
constructor(client) {
|
|
2342
1857
|
this.client = client;
|
|
2343
1858
|
}
|
|
1859
|
+
withQuery(path, params) {
|
|
1860
|
+
const searchParams = new URLSearchParams();
|
|
1861
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1862
|
+
if (value === void 0) continue;
|
|
1863
|
+
searchParams.set(key, String(value));
|
|
1864
|
+
}
|
|
1865
|
+
const query2 = searchParams.toString();
|
|
1866
|
+
return query2 ? `${path}?${query2}` : path;
|
|
1867
|
+
}
|
|
2344
1868
|
async getStockLevels() {
|
|
2345
|
-
return safe8(this.client.
|
|
1869
|
+
return safe8(this.client.get("/api/v1/inventory/stock-levels"));
|
|
2346
1870
|
}
|
|
2347
1871
|
async getProductStock(productId, locationId) {
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
})
|
|
2354
|
-
);
|
|
2355
|
-
}
|
|
2356
|
-
return safe8(
|
|
2357
|
-
this.client.query("inventory.product", {
|
|
2358
|
-
product_id: productId
|
|
2359
|
-
})
|
|
2360
|
-
);
|
|
1872
|
+
const encodedId = encodeURIComponent(productId);
|
|
1873
|
+
const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/stock`, {
|
|
1874
|
+
location_id: locationId
|
|
1875
|
+
});
|
|
1876
|
+
return safe8(this.client.get(path));
|
|
2361
1877
|
}
|
|
2362
1878
|
async getVariantStock(variantId, locationId) {
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
);
|
|
1879
|
+
const encodedId = encodeURIComponent(variantId);
|
|
1880
|
+
const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/stock`, {
|
|
1881
|
+
location_id: locationId
|
|
1882
|
+
});
|
|
1883
|
+
return safe8(this.client.get(path));
|
|
2369
1884
|
}
|
|
2370
1885
|
async checkProductAvailability(productId, quantity, locationId) {
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
);
|
|
1886
|
+
const encodedId = encodeURIComponent(productId);
|
|
1887
|
+
const path = this.withQuery(`/api/v1/inventory/products/${encodedId}/availability`, {
|
|
1888
|
+
quantity,
|
|
1889
|
+
location_id: locationId
|
|
1890
|
+
});
|
|
1891
|
+
return safe8(this.client.get(path));
|
|
2378
1892
|
}
|
|
2379
1893
|
async checkVariantAvailability(variantId, quantity, locationId) {
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
);
|
|
1894
|
+
const encodedId = encodeURIComponent(variantId);
|
|
1895
|
+
const path = this.withQuery(`/api/v1/inventory/variants/${encodedId}/availability`, {
|
|
1896
|
+
quantity,
|
|
1897
|
+
location_id: locationId
|
|
1898
|
+
});
|
|
1899
|
+
return safe8(this.client.get(path));
|
|
2387
1900
|
}
|
|
2388
1901
|
async checkMultipleAvailability(items, locationId) {
|
|
2389
1902
|
const results = await Promise.all(
|
|
@@ -2397,7 +1910,7 @@ var InventoryService = class {
|
|
|
2397
1910
|
return ok(results.map((r) => r.value));
|
|
2398
1911
|
}
|
|
2399
1912
|
async getSummary() {
|
|
2400
|
-
return safe8(this.client.
|
|
1913
|
+
return safe8(this.client.get("/api/v1/inventory/summary"));
|
|
2401
1914
|
}
|
|
2402
1915
|
async isInStock(productId, locationId) {
|
|
2403
1916
|
const result = await this.checkProductAvailability(productId, 1, locationId);
|
|
@@ -2412,9 +1925,6 @@ var InventoryService = class {
|
|
|
2412
1925
|
};
|
|
2413
1926
|
|
|
2414
1927
|
// src/scheduling.ts
|
|
2415
|
-
function toVariables(input) {
|
|
2416
|
-
return Object.fromEntries(Object.entries(input));
|
|
2417
|
-
}
|
|
2418
1928
|
function toCimplifyError9(error) {
|
|
2419
1929
|
if (error instanceof CimplifyError) return error;
|
|
2420
1930
|
if (error instanceof Error) {
|
|
@@ -2429,68 +1939,110 @@ async function safe9(promise) {
|
|
|
2429
1939
|
return err(toCimplifyError9(error));
|
|
2430
1940
|
}
|
|
2431
1941
|
}
|
|
1942
|
+
function withQuery2(path, params) {
|
|
1943
|
+
const searchParams = new URLSearchParams();
|
|
1944
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1945
|
+
if (value === void 0) continue;
|
|
1946
|
+
searchParams.set(key, String(value));
|
|
1947
|
+
}
|
|
1948
|
+
const query2 = searchParams.toString();
|
|
1949
|
+
return query2 ? `${path}?${query2}` : path;
|
|
1950
|
+
}
|
|
1951
|
+
function normalizeServiceAvailability(result) {
|
|
1952
|
+
if (Array.isArray(result.days) && result.days.length > 0) {
|
|
1953
|
+
return result;
|
|
1954
|
+
}
|
|
1955
|
+
const days = Array.isArray(result.availability) ? result.availability.map((day) => ({
|
|
1956
|
+
...day,
|
|
1957
|
+
is_fully_booked: day.is_fully_booked ?? (typeof day.has_availability === "boolean" ? !day.has_availability : void 0)
|
|
1958
|
+
})) : [];
|
|
1959
|
+
return { ...result, days };
|
|
1960
|
+
}
|
|
1961
|
+
function firstScheduledTime(booking) {
|
|
1962
|
+
return booking.service_items.find((item) => typeof item.scheduled_start === "string")?.scheduled_start || booking.created_at;
|
|
1963
|
+
}
|
|
2432
1964
|
var SchedulingService = class {
|
|
2433
1965
|
constructor(client) {
|
|
2434
1966
|
this.client = client;
|
|
2435
1967
|
}
|
|
2436
1968
|
async getServices() {
|
|
2437
|
-
return safe9(this.client.
|
|
1969
|
+
return safe9(this.client.get("/api/v1/scheduling/services"));
|
|
2438
1970
|
}
|
|
2439
1971
|
/**
|
|
2440
|
-
* Get a specific service by ID
|
|
2441
|
-
* Note: Filters from all services client-side (no single-service endpoint)
|
|
1972
|
+
* Get a specific service by ID.
|
|
2442
1973
|
*/
|
|
2443
1974
|
async getService(serviceId) {
|
|
2444
1975
|
const result = await this.getServices();
|
|
2445
1976
|
if (!result.ok) return result;
|
|
2446
|
-
return ok(result.value.find((
|
|
1977
|
+
return ok(result.value.find((service) => service.id === serviceId) || null);
|
|
2447
1978
|
}
|
|
2448
1979
|
async getAvailableSlots(input) {
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
1980
|
+
const path = withQuery2("/api/v1/scheduling/slots", {
|
|
1981
|
+
service_id: input.service_id,
|
|
1982
|
+
date: input.date,
|
|
1983
|
+
participant_count: input.participant_count,
|
|
1984
|
+
duration_minutes: input.duration_minutes
|
|
1985
|
+
});
|
|
1986
|
+
return safe9(this.client.get(path));
|
|
2452
1987
|
}
|
|
2453
1988
|
async checkSlotAvailability(input) {
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
);
|
|
1989
|
+
const path = withQuery2("/api/v1/scheduling/slots/check", {
|
|
1990
|
+
service_id: input.service_id,
|
|
1991
|
+
slot_time: input.slot_time,
|
|
1992
|
+
duration_minutes: input.duration_minutes,
|
|
1993
|
+
participant_count: input.participant_count
|
|
1994
|
+
});
|
|
1995
|
+
return safe9(this.client.get(path));
|
|
2460
1996
|
}
|
|
2461
1997
|
async getServiceAvailability(params) {
|
|
1998
|
+
const path = withQuery2("/api/v1/scheduling/availability", {
|
|
1999
|
+
service_id: params.service_id,
|
|
2000
|
+
start_date: params.start_date,
|
|
2001
|
+
end_date: params.end_date,
|
|
2002
|
+
location_id: params.location_id,
|
|
2003
|
+
participant_count: params.participant_count
|
|
2004
|
+
});
|
|
2462
2005
|
return safe9(
|
|
2463
|
-
this.client.
|
|
2464
|
-
"scheduling.availability",
|
|
2465
|
-
toVariables(params)
|
|
2466
|
-
)
|
|
2006
|
+
this.client.get(path).then((result) => normalizeServiceAvailability(result))
|
|
2467
2007
|
);
|
|
2468
2008
|
}
|
|
2469
2009
|
async getBooking(bookingId) {
|
|
2470
|
-
|
|
2010
|
+
const encodedId = encodeURIComponent(bookingId);
|
|
2011
|
+
return safe9(this.client.get(`/api/v1/scheduling/bookings/${encodedId}`));
|
|
2471
2012
|
}
|
|
2472
|
-
async getCustomerBookings() {
|
|
2473
|
-
|
|
2013
|
+
async getCustomerBookings(customerId) {
|
|
2014
|
+
const path = withQuery2("/api/v1/scheduling/bookings", {
|
|
2015
|
+
customer_id: customerId
|
|
2016
|
+
});
|
|
2017
|
+
return safe9(this.client.get(path));
|
|
2474
2018
|
}
|
|
2475
2019
|
async getUpcomingBookings() {
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
)
|
|
2480
|
-
|
|
2020
|
+
const result = await this.getCustomerBookings();
|
|
2021
|
+
if (!result.ok) return result;
|
|
2022
|
+
const upcoming = result.value.filter((booking) => {
|
|
2023
|
+
const status = String(booking.status).toLowerCase();
|
|
2024
|
+
return status !== "completed" && status !== "cancelled";
|
|
2025
|
+
}).sort((a, b) => firstScheduledTime(a).localeCompare(firstScheduledTime(b)));
|
|
2026
|
+
return ok(upcoming);
|
|
2481
2027
|
}
|
|
2482
2028
|
async getPastBookings(limit = 10) {
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
);
|
|
2029
|
+
const result = await this.getCustomerBookings();
|
|
2030
|
+
if (!result.ok) return result;
|
|
2031
|
+
const past = result.value.filter((booking) => String(booking.status).toLowerCase() === "completed").sort((a, b) => firstScheduledTime(b).localeCompare(firstScheduledTime(a))).slice(0, Math.max(0, limit));
|
|
2032
|
+
return ok(past);
|
|
2488
2033
|
}
|
|
2489
2034
|
async cancelBooking(input) {
|
|
2490
|
-
|
|
2035
|
+
const encodedId = encodeURIComponent(input.booking_id);
|
|
2036
|
+
return safe9(
|
|
2037
|
+
this.client.post(`/api/v1/scheduling/bookings/${encodedId}/cancel`, {
|
|
2038
|
+
reason: input.reason
|
|
2039
|
+
})
|
|
2040
|
+
);
|
|
2491
2041
|
}
|
|
2492
2042
|
async rescheduleBooking(input) {
|
|
2493
|
-
return safe9(
|
|
2043
|
+
return safe9(
|
|
2044
|
+
this.client.post("/api/v1/scheduling/bookings/reschedule", input)
|
|
2045
|
+
);
|
|
2494
2046
|
}
|
|
2495
2047
|
async getNextAvailableSlot(serviceId, fromDate) {
|
|
2496
2048
|
const date = fromDate || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
@@ -2509,6 +2061,12 @@ var SchedulingService = class {
|
|
|
2509
2061
|
if (!result.ok) return result;
|
|
2510
2062
|
return ok(result.value.some((slot) => slot.is_available));
|
|
2511
2063
|
}
|
|
2064
|
+
// Compatibility alias for callers typed against the older Booking shape.
|
|
2065
|
+
async getBookingLegacy(bookingId) {
|
|
2066
|
+
const result = await this.getBooking(bookingId);
|
|
2067
|
+
if (!result.ok) return result;
|
|
2068
|
+
return ok(result.value);
|
|
2069
|
+
}
|
|
2512
2070
|
};
|
|
2513
2071
|
|
|
2514
2072
|
// src/lite.ts
|
|
@@ -2531,47 +2089,18 @@ var LiteService = class {
|
|
|
2531
2089
|
this.client = client;
|
|
2532
2090
|
}
|
|
2533
2091
|
async getBootstrap() {
|
|
2534
|
-
return safe10(this.client.
|
|
2092
|
+
return safe10(this.client.get("/api/v1/lite/bootstrap"));
|
|
2535
2093
|
}
|
|
2536
2094
|
async getTable(tableId) {
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
async getTableByNumber(tableNumber, locationId) {
|
|
2540
|
-
return safe10(
|
|
2541
|
-
this.client.query("lite.table_by_number", {
|
|
2542
|
-
table_number: tableNumber,
|
|
2543
|
-
location_id: locationId
|
|
2544
|
-
})
|
|
2545
|
-
);
|
|
2546
|
-
}
|
|
2547
|
-
async sendToKitchen(tableId, items) {
|
|
2548
|
-
return safe10(
|
|
2549
|
-
this.client.call("lite.send_to_kitchen", {
|
|
2550
|
-
table_id: tableId,
|
|
2551
|
-
items
|
|
2552
|
-
})
|
|
2553
|
-
);
|
|
2554
|
-
}
|
|
2555
|
-
async callWaiter(tableId, reason) {
|
|
2556
|
-
return safe10(
|
|
2557
|
-
this.client.call("lite.call_waiter", {
|
|
2558
|
-
table_id: tableId,
|
|
2559
|
-
reason
|
|
2560
|
-
})
|
|
2561
|
-
);
|
|
2562
|
-
}
|
|
2563
|
-
async requestBill(tableId) {
|
|
2564
|
-
return safe10(
|
|
2565
|
-
this.client.call("lite.request_bill", {
|
|
2566
|
-
table_id: tableId
|
|
2567
|
-
})
|
|
2568
|
-
);
|
|
2095
|
+
const encodedId = encodeURIComponent(tableId);
|
|
2096
|
+
return safe10(this.client.get(`/api/v1/lite/tables/${encodedId}`));
|
|
2569
2097
|
}
|
|
2570
2098
|
async getMenu() {
|
|
2571
|
-
return safe10(this.client.
|
|
2099
|
+
return safe10(this.client.get("/api/v1/lite/menu"));
|
|
2572
2100
|
}
|
|
2573
2101
|
async getMenuByCategory(categoryId) {
|
|
2574
|
-
|
|
2102
|
+
const encodedId = encodeURIComponent(categoryId);
|
|
2103
|
+
return safe10(this.client.get(`/api/v1/lite/menu/categories/${encodedId}`));
|
|
2575
2104
|
}
|
|
2576
2105
|
};
|
|
2577
2106
|
|
|
@@ -2590,30 +2119,16 @@ async function safe11(promise) {
|
|
|
2590
2119
|
return err(toCimplifyError11(error));
|
|
2591
2120
|
}
|
|
2592
2121
|
}
|
|
2593
|
-
async function safeWithFallback7(primary, fallback) {
|
|
2594
|
-
const primaryResult = await safe11(primary());
|
|
2595
|
-
if (primaryResult.ok) return primaryResult;
|
|
2596
|
-
if (primaryResult.error.code !== "HTTP_404" && primaryResult.error.code !== "API_ERROR") {
|
|
2597
|
-
return primaryResult;
|
|
2598
|
-
}
|
|
2599
|
-
return safe11(fallback());
|
|
2600
|
-
}
|
|
2601
2122
|
var FxService = class {
|
|
2602
2123
|
constructor(client) {
|
|
2603
2124
|
this.client = client;
|
|
2604
2125
|
}
|
|
2605
2126
|
async getRate(from, to) {
|
|
2606
2127
|
const path = `/api/v1/fx/rate?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`;
|
|
2607
|
-
return
|
|
2608
|
-
() => this.client.get(path),
|
|
2609
|
-
() => this.client.call("fx.getRate", { from, to })
|
|
2610
|
-
);
|
|
2128
|
+
return safe11(this.client.get(path));
|
|
2611
2129
|
}
|
|
2612
2130
|
async lockQuote(request) {
|
|
2613
|
-
return
|
|
2614
|
-
() => this.client.post("/api/v1/fx/quotes", request),
|
|
2615
|
-
() => this.client.call("fx.lockQuote", request)
|
|
2616
|
-
);
|
|
2131
|
+
return safe11(this.client.post("/api/v1/fx/quotes", request));
|
|
2617
2132
|
}
|
|
2618
2133
|
};
|
|
2619
2134
|
|
|
@@ -3222,6 +2737,74 @@ function createElements(client, businessId, options) {
|
|
|
3222
2737
|
return new CimplifyElements(client, businessId, options);
|
|
3223
2738
|
}
|
|
3224
2739
|
|
|
2740
|
+
// src/query/builder.ts
|
|
2741
|
+
function escapeQueryValue(value) {
|
|
2742
|
+
return value.replace(/'/g, "\\'");
|
|
2743
|
+
}
|
|
2744
|
+
var QueryBuilder = class {
|
|
2745
|
+
constructor(entity) {
|
|
2746
|
+
this.filters = [];
|
|
2747
|
+
this.modifiers = [];
|
|
2748
|
+
this.pathSegments = [];
|
|
2749
|
+
this.entity = entity;
|
|
2750
|
+
}
|
|
2751
|
+
path(segment) {
|
|
2752
|
+
this.pathSegments.push(segment);
|
|
2753
|
+
return this;
|
|
2754
|
+
}
|
|
2755
|
+
where(field, op, value) {
|
|
2756
|
+
const v = typeof value === "string" ? `'${escapeQueryValue(value)}'` : value;
|
|
2757
|
+
if (op === "contains" || op === "startsWith") {
|
|
2758
|
+
this.filters.push(`@.${field} ${op} ${v}`);
|
|
2759
|
+
} else {
|
|
2760
|
+
this.filters.push(`@.${field}${op}${v}`);
|
|
2761
|
+
}
|
|
2762
|
+
return this;
|
|
2763
|
+
}
|
|
2764
|
+
and(field, op, value) {
|
|
2765
|
+
return this.where(field, op, value);
|
|
2766
|
+
}
|
|
2767
|
+
sort(field, order = "asc") {
|
|
2768
|
+
this.modifiers.push(`sort(${field},${order})`);
|
|
2769
|
+
return this;
|
|
2770
|
+
}
|
|
2771
|
+
limit(n) {
|
|
2772
|
+
this.modifiers.push(`limit(${n})`);
|
|
2773
|
+
return this;
|
|
2774
|
+
}
|
|
2775
|
+
offset(n) {
|
|
2776
|
+
this.modifiers.push(`offset(${n})`);
|
|
2777
|
+
return this;
|
|
2778
|
+
}
|
|
2779
|
+
count() {
|
|
2780
|
+
this.modifiers.push("count");
|
|
2781
|
+
return this;
|
|
2782
|
+
}
|
|
2783
|
+
enriched() {
|
|
2784
|
+
this.modifiers.push("enriched");
|
|
2785
|
+
return this;
|
|
2786
|
+
}
|
|
2787
|
+
build() {
|
|
2788
|
+
let query2 = this.entity;
|
|
2789
|
+
if (this.pathSegments.length > 0) {
|
|
2790
|
+
query2 += "." + this.pathSegments.join(".");
|
|
2791
|
+
}
|
|
2792
|
+
if (this.filters.length > 0) {
|
|
2793
|
+
query2 += `[?(${this.filters.join(" && ")})]`;
|
|
2794
|
+
}
|
|
2795
|
+
for (const mod of this.modifiers) {
|
|
2796
|
+
query2 += `#${mod}`;
|
|
2797
|
+
}
|
|
2798
|
+
return query2;
|
|
2799
|
+
}
|
|
2800
|
+
toString() {
|
|
2801
|
+
return this.build();
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
function query(entity) {
|
|
2805
|
+
return new QueryBuilder(entity);
|
|
2806
|
+
}
|
|
2807
|
+
|
|
3225
2808
|
exports.AuthService = AuthService;
|
|
3226
2809
|
exports.BusinessService = BusinessService;
|
|
3227
2810
|
exports.CartOperations = CartOperations;
|