@cimplify/sdk 0.6.7 → 0.6.8
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/README.md +19 -0
- package/dist/advanced.d.mts +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +115 -84
- package/dist/advanced.mjs +115 -84
- package/dist/{client-B4etj3AD.d.mts → client-D4vA6FY_.d.ts} +36 -34
- package/dist/{client-CYVVuP5J.d.ts → client-FQUyv41r.d.mts} +36 -34
- package/dist/{index-DzNb32O3.d.mts → index-DaKJxoEh.d.mts} +13 -12
- package/dist/{index-BOYF-efj.d.ts → index-pztT_bcJ.d.ts} +13 -12
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +147 -89
- package/dist/index.mjs +144 -90
- package/dist/{payment-pjpfIKX8.d.mts → payment-Cu75tmUc.d.mts} +22 -7
- package/dist/{payment-pjpfIKX8.d.ts → payment-Cu75tmUc.d.ts} +22 -7
- package/dist/react.d.mts +99 -4
- package/dist/react.d.ts +99 -4
- package/dist/react.js +827 -22
- package/dist/react.mjs +822 -23
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +76 -4
- package/dist/utils.mjs +76 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
// src/types/common.ts
|
|
2
|
+
function money(value) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
function moneyFromNumber(value) {
|
|
6
|
+
return value.toFixed(2);
|
|
7
|
+
}
|
|
8
|
+
var ZERO = "0.00";
|
|
9
|
+
function currencyCode(value) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
2
12
|
var ErrorCode = {
|
|
3
13
|
// General
|
|
4
14
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
@@ -217,6 +227,74 @@ function combineObject(results) {
|
|
|
217
227
|
return ok(values);
|
|
218
228
|
}
|
|
219
229
|
|
|
230
|
+
// src/query/builder.ts
|
|
231
|
+
function escapeQueryValue(value) {
|
|
232
|
+
return value.replace(/'/g, "\\'");
|
|
233
|
+
}
|
|
234
|
+
var QueryBuilder = class {
|
|
235
|
+
constructor(entity) {
|
|
236
|
+
this.filters = [];
|
|
237
|
+
this.modifiers = [];
|
|
238
|
+
this.pathSegments = [];
|
|
239
|
+
this.entity = entity;
|
|
240
|
+
}
|
|
241
|
+
path(segment) {
|
|
242
|
+
this.pathSegments.push(segment);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
where(field, op, value) {
|
|
246
|
+
const v = typeof value === "string" ? `'${escapeQueryValue(value)}'` : value;
|
|
247
|
+
if (op === "contains" || op === "startsWith") {
|
|
248
|
+
this.filters.push(`@.${field} ${op} ${v}`);
|
|
249
|
+
} else {
|
|
250
|
+
this.filters.push(`@.${field}${op}${v}`);
|
|
251
|
+
}
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
and(field, op, value) {
|
|
255
|
+
return this.where(field, op, value);
|
|
256
|
+
}
|
|
257
|
+
sort(field, order = "asc") {
|
|
258
|
+
this.modifiers.push(`sort(${field},${order})`);
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
limit(n) {
|
|
262
|
+
this.modifiers.push(`limit(${n})`);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
offset(n) {
|
|
266
|
+
this.modifiers.push(`offset(${n})`);
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
count() {
|
|
270
|
+
this.modifiers.push("count");
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
enriched() {
|
|
274
|
+
this.modifiers.push("enriched");
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
build() {
|
|
278
|
+
let query2 = this.entity;
|
|
279
|
+
if (this.pathSegments.length > 0) {
|
|
280
|
+
query2 += "." + this.pathSegments.join(".");
|
|
281
|
+
}
|
|
282
|
+
if (this.filters.length > 0) {
|
|
283
|
+
query2 += `[?(${this.filters.join(" && ")})]`;
|
|
284
|
+
}
|
|
285
|
+
for (const mod of this.modifiers) {
|
|
286
|
+
query2 += `#${mod}`;
|
|
287
|
+
}
|
|
288
|
+
return query2;
|
|
289
|
+
}
|
|
290
|
+
toString() {
|
|
291
|
+
return this.build();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
function query(entity) {
|
|
295
|
+
return new QueryBuilder(entity);
|
|
296
|
+
}
|
|
297
|
+
|
|
220
298
|
// src/catalogue.ts
|
|
221
299
|
function toCimplifyError(error) {
|
|
222
300
|
if (error instanceof CimplifyError) return enrichError(error);
|
|
@@ -297,7 +375,7 @@ var CatalogueQueries = class {
|
|
|
297
375
|
let query2 = "products";
|
|
298
376
|
const filters = [];
|
|
299
377
|
if (options?.category) {
|
|
300
|
-
filters.push(`@.category_id=='${options.category}'`);
|
|
378
|
+
filters.push(`@.category_id=='${escapeQueryValue(options.category)}'`);
|
|
301
379
|
}
|
|
302
380
|
if (options?.featured !== void 0) {
|
|
303
381
|
filters.push(`@.featured==${options.featured}`);
|
|
@@ -306,7 +384,7 @@ var CatalogueQueries = class {
|
|
|
306
384
|
filters.push(`@.in_stock==${options.in_stock}`);
|
|
307
385
|
}
|
|
308
386
|
if (options?.search) {
|
|
309
|
-
filters.push(`@.name contains '${options.search}'`);
|
|
387
|
+
filters.push(`@.name contains '${escapeQueryValue(options.search)}'`);
|
|
310
388
|
}
|
|
311
389
|
if (options?.min_price !== void 0) {
|
|
312
390
|
filters.push(`@.price>=${options.min_price}`);
|
|
@@ -337,7 +415,9 @@ var CatalogueQueries = class {
|
|
|
337
415
|
}
|
|
338
416
|
async getProductBySlug(slug) {
|
|
339
417
|
const filteredResult = await safe(
|
|
340
|
-
this.client.query(
|
|
418
|
+
this.client.query(
|
|
419
|
+
`products[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
420
|
+
)
|
|
341
421
|
);
|
|
342
422
|
if (!filteredResult.ok) return filteredResult;
|
|
343
423
|
const exactMatch = findProductBySlug(filteredResult.value, slug);
|
|
@@ -389,7 +469,7 @@ var CatalogueQueries = class {
|
|
|
389
469
|
}
|
|
390
470
|
async getCategoryBySlug(slug) {
|
|
391
471
|
const result = await safe(
|
|
392
|
-
this.client.query(`categories[?(@.slug=='${slug}')]`)
|
|
472
|
+
this.client.query(`categories[?(@.slug=='${escapeQueryValue(slug)}')]`)
|
|
393
473
|
);
|
|
394
474
|
if (!result.ok) return result;
|
|
395
475
|
if (!result.value.length) {
|
|
@@ -398,7 +478,11 @@ var CatalogueQueries = class {
|
|
|
398
478
|
return ok(result.value[0]);
|
|
399
479
|
}
|
|
400
480
|
async getCategoryProducts(categoryId) {
|
|
401
|
-
return safe(
|
|
481
|
+
return safe(
|
|
482
|
+
this.client.query(
|
|
483
|
+
`products[?(@.category_id=='${escapeQueryValue(categoryId)}')]`
|
|
484
|
+
)
|
|
485
|
+
);
|
|
402
486
|
}
|
|
403
487
|
async getCollections() {
|
|
404
488
|
return safe(this.client.query("collections"));
|
|
@@ -408,7 +492,9 @@ var CatalogueQueries = class {
|
|
|
408
492
|
}
|
|
409
493
|
async getCollectionBySlug(slug) {
|
|
410
494
|
const result = await safe(
|
|
411
|
-
this.client.query(
|
|
495
|
+
this.client.query(
|
|
496
|
+
`collections[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
497
|
+
)
|
|
412
498
|
);
|
|
413
499
|
if (!result.ok) return result;
|
|
414
500
|
if (!result.value.length) {
|
|
@@ -421,7 +507,9 @@ var CatalogueQueries = class {
|
|
|
421
507
|
}
|
|
422
508
|
async searchCollections(query2, limit = 20) {
|
|
423
509
|
return safe(
|
|
424
|
-
this.client.query(
|
|
510
|
+
this.client.query(
|
|
511
|
+
`collections[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
512
|
+
)
|
|
425
513
|
);
|
|
426
514
|
}
|
|
427
515
|
async getBundles() {
|
|
@@ -432,7 +520,9 @@ var CatalogueQueries = class {
|
|
|
432
520
|
}
|
|
433
521
|
async getBundleBySlug(slug) {
|
|
434
522
|
const result = await safe(
|
|
435
|
-
this.client.query(
|
|
523
|
+
this.client.query(
|
|
524
|
+
`bundles[?(@.slug=='${escapeQueryValue(slug)}')]`
|
|
525
|
+
)
|
|
436
526
|
);
|
|
437
527
|
if (!result.ok) return result;
|
|
438
528
|
if (!result.value.length) {
|
|
@@ -442,7 +532,9 @@ var CatalogueQueries = class {
|
|
|
442
532
|
}
|
|
443
533
|
async searchBundles(query2, limit = 20) {
|
|
444
534
|
return safe(
|
|
445
|
-
this.client.query(
|
|
535
|
+
this.client.query(
|
|
536
|
+
`bundles[?(@.name contains '${escapeQueryValue(query2)}')]#limit(${limit})`
|
|
537
|
+
)
|
|
446
538
|
);
|
|
447
539
|
}
|
|
448
540
|
async getComposites(options) {
|
|
@@ -482,9 +574,9 @@ var CatalogueQueries = class {
|
|
|
482
574
|
}
|
|
483
575
|
async search(query2, options) {
|
|
484
576
|
const limit = options?.limit ?? 20;
|
|
485
|
-
let searchQuery = `products[?(@.name contains '${query2}')]`;
|
|
577
|
+
let searchQuery = `products[?(@.name contains '${escapeQueryValue(query2)}')]`;
|
|
486
578
|
if (options?.category) {
|
|
487
|
-
searchQuery = `products[?(@.name contains '${query2}' && @.category_id=='${options.category}')]`;
|
|
579
|
+
searchQuery = `products[?(@.name contains '${escapeQueryValue(query2)}' && @.category_id=='${escapeQueryValue(options.category)}')]`;
|
|
488
580
|
}
|
|
489
581
|
searchQuery += `#limit(${limit})`;
|
|
490
582
|
return safe(this.client.query(searchQuery));
|
|
@@ -501,7 +593,7 @@ var CatalogueQueries = class {
|
|
|
501
593
|
async getMenu(options) {
|
|
502
594
|
let query2 = "menu";
|
|
503
595
|
if (options?.category) {
|
|
504
|
-
query2 = `menu[?(@.category=='${options.category}')]`;
|
|
596
|
+
query2 = `menu[?(@.category=='${escapeQueryValue(options.category)}')]`;
|
|
505
597
|
}
|
|
506
598
|
if (options?.limit) {
|
|
507
599
|
query2 += `#limit(${options.limit})`;
|
|
@@ -818,8 +910,8 @@ var CURRENCY_SYMBOLS = {
|
|
|
818
910
|
KMF: "CF",
|
|
819
911
|
BIF: "FBu"
|
|
820
912
|
};
|
|
821
|
-
function getCurrencySymbol(
|
|
822
|
-
return CURRENCY_SYMBOLS[
|
|
913
|
+
function getCurrencySymbol(currencyCode2) {
|
|
914
|
+
return CURRENCY_SYMBOLS[currencyCode2.toUpperCase()] || currencyCode2;
|
|
823
915
|
}
|
|
824
916
|
function formatNumberCompact(value, decimals = 1) {
|
|
825
917
|
const absValue = Math.abs(value);
|
|
@@ -1143,6 +1235,8 @@ function normalizeStatusResponse(response) {
|
|
|
1143
1235
|
}
|
|
1144
1236
|
const res = response;
|
|
1145
1237
|
const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
|
|
1238
|
+
const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : void 0;
|
|
1239
|
+
const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? currencyCode(res.currency) : void 0;
|
|
1146
1240
|
const paidValue = res.paid === true;
|
|
1147
1241
|
const derivedPaid = paidValue || [
|
|
1148
1242
|
"success",
|
|
@@ -1155,8 +1249,8 @@ function normalizeStatusResponse(response) {
|
|
|
1155
1249
|
return {
|
|
1156
1250
|
status: normalizedStatus,
|
|
1157
1251
|
paid: derivedPaid,
|
|
1158
|
-
amount:
|
|
1159
|
-
currency:
|
|
1252
|
+
amount: normalizedAmount,
|
|
1253
|
+
currency: normalizedCurrency,
|
|
1160
1254
|
reference: res.reference,
|
|
1161
1255
|
message: res.message || ""
|
|
1162
1256
|
};
|
|
@@ -1863,14 +1957,17 @@ var CheckoutService = class {
|
|
|
1863
1957
|
pay_currency: data.pay_currency,
|
|
1864
1958
|
fx_quote_id: data.fx_quote_id
|
|
1865
1959
|
};
|
|
1866
|
-
const baseCurrency = (
|
|
1960
|
+
const baseCurrency = currencyCode(
|
|
1961
|
+
(cart.pricing.currency || checkoutData.pay_currency || "GHS").toUpperCase()
|
|
1962
|
+
);
|
|
1867
1963
|
const payCurrency = data.pay_currency?.trim().toUpperCase();
|
|
1964
|
+
const payCurrencyCode = payCurrency ? currencyCode(payCurrency) : void 0;
|
|
1868
1965
|
const cartTotalAmount = Number.parseFloat(cart.pricing.total_price || "0");
|
|
1869
|
-
if (
|
|
1966
|
+
if (payCurrencyCode && payCurrencyCode !== baseCurrency && !checkoutData.fx_quote_id && Number.isFinite(cartTotalAmount) && cartTotalAmount > 0) {
|
|
1870
1967
|
const fxQuoteResult = await this.client.fx.lockQuote({
|
|
1871
1968
|
from: baseCurrency,
|
|
1872
|
-
to:
|
|
1873
|
-
amount:
|
|
1969
|
+
to: payCurrencyCode,
|
|
1970
|
+
amount: cart.pricing.total_price
|
|
1874
1971
|
});
|
|
1875
1972
|
if (!fxQuoteResult.ok) {
|
|
1876
1973
|
return ok(
|
|
@@ -1881,7 +1978,7 @@ var CheckoutService = class {
|
|
|
1881
1978
|
)
|
|
1882
1979
|
);
|
|
1883
1980
|
}
|
|
1884
|
-
checkoutData.pay_currency =
|
|
1981
|
+
checkoutData.pay_currency = payCurrencyCode;
|
|
1885
1982
|
checkoutData.fx_quote_id = fxQuoteResult.value.id;
|
|
1886
1983
|
}
|
|
1887
1984
|
data.on_status_change?.("processing", {});
|
|
@@ -3371,7 +3468,7 @@ var CimplifyClient = class {
|
|
|
3371
3468
|
signal: controller.signal
|
|
3372
3469
|
});
|
|
3373
3470
|
clearTimeout(timeoutId);
|
|
3374
|
-
if (response.ok
|
|
3471
|
+
if (response.ok) {
|
|
3375
3472
|
this.hooks.onRequestSuccess?.({
|
|
3376
3473
|
...context,
|
|
3377
3474
|
status: response.status,
|
|
@@ -3379,6 +3476,21 @@ var CimplifyClient = class {
|
|
|
3379
3476
|
});
|
|
3380
3477
|
return response;
|
|
3381
3478
|
}
|
|
3479
|
+
if (response.status >= 400 && response.status < 500) {
|
|
3480
|
+
this.hooks.onRequestError?.({
|
|
3481
|
+
...context,
|
|
3482
|
+
error: new CimplifyError(
|
|
3483
|
+
`HTTP_${response.status}`,
|
|
3484
|
+
`Request failed with status ${response.status}`,
|
|
3485
|
+
false
|
|
3486
|
+
),
|
|
3487
|
+
status: response.status,
|
|
3488
|
+
durationMs: Date.now() - startTime,
|
|
3489
|
+
retryCount,
|
|
3490
|
+
retryable: false
|
|
3491
|
+
});
|
|
3492
|
+
return response;
|
|
3493
|
+
}
|
|
3382
3494
|
if (response.status >= 500 && attempt < this.maxRetries) {
|
|
3383
3495
|
retryCount++;
|
|
3384
3496
|
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
@@ -3391,10 +3503,17 @@ var CimplifyClient = class {
|
|
|
3391
3503
|
await sleep(delay);
|
|
3392
3504
|
continue;
|
|
3393
3505
|
}
|
|
3394
|
-
this.hooks.
|
|
3506
|
+
this.hooks.onRequestError?.({
|
|
3395
3507
|
...context,
|
|
3508
|
+
error: new CimplifyError(
|
|
3509
|
+
"SERVER_ERROR",
|
|
3510
|
+
`Server error ${response.status} after ${retryCount} retries`,
|
|
3511
|
+
false
|
|
3512
|
+
),
|
|
3396
3513
|
status: response.status,
|
|
3397
|
-
durationMs: Date.now() - startTime
|
|
3514
|
+
durationMs: Date.now() - startTime,
|
|
3515
|
+
retryCount,
|
|
3516
|
+
retryable: false
|
|
3398
3517
|
});
|
|
3399
3518
|
return response;
|
|
3400
3519
|
} catch (error) {
|
|
@@ -3668,69 +3787,4 @@ function createCimplifyClient(config = {}) {
|
|
|
3668
3787
|
return new CimplifyClient(config);
|
|
3669
3788
|
}
|
|
3670
3789
|
|
|
3671
|
-
|
|
3672
|
-
var QueryBuilder = class {
|
|
3673
|
-
constructor(entity) {
|
|
3674
|
-
this.filters = [];
|
|
3675
|
-
this.modifiers = [];
|
|
3676
|
-
this.pathSegments = [];
|
|
3677
|
-
this.entity = entity;
|
|
3678
|
-
}
|
|
3679
|
-
path(segment) {
|
|
3680
|
-
this.pathSegments.push(segment);
|
|
3681
|
-
return this;
|
|
3682
|
-
}
|
|
3683
|
-
where(field, op, value) {
|
|
3684
|
-
const v = typeof value === "string" ? `'${value}'` : value;
|
|
3685
|
-
if (op === "contains" || op === "startsWith") {
|
|
3686
|
-
this.filters.push(`@.${field} ${op} ${v}`);
|
|
3687
|
-
} else {
|
|
3688
|
-
this.filters.push(`@.${field}${op}${v}`);
|
|
3689
|
-
}
|
|
3690
|
-
return this;
|
|
3691
|
-
}
|
|
3692
|
-
and(field, op, value) {
|
|
3693
|
-
return this.where(field, op, value);
|
|
3694
|
-
}
|
|
3695
|
-
sort(field, order = "asc") {
|
|
3696
|
-
this.modifiers.push(`sort(${field},${order})`);
|
|
3697
|
-
return this;
|
|
3698
|
-
}
|
|
3699
|
-
limit(n) {
|
|
3700
|
-
this.modifiers.push(`limit(${n})`);
|
|
3701
|
-
return this;
|
|
3702
|
-
}
|
|
3703
|
-
offset(n) {
|
|
3704
|
-
this.modifiers.push(`offset(${n})`);
|
|
3705
|
-
return this;
|
|
3706
|
-
}
|
|
3707
|
-
count() {
|
|
3708
|
-
this.modifiers.push("count");
|
|
3709
|
-
return this;
|
|
3710
|
-
}
|
|
3711
|
-
enriched() {
|
|
3712
|
-
this.modifiers.push("enriched");
|
|
3713
|
-
return this;
|
|
3714
|
-
}
|
|
3715
|
-
build() {
|
|
3716
|
-
let query2 = this.entity;
|
|
3717
|
-
if (this.pathSegments.length > 0) {
|
|
3718
|
-
query2 += "." + this.pathSegments.join(".");
|
|
3719
|
-
}
|
|
3720
|
-
if (this.filters.length > 0) {
|
|
3721
|
-
query2 += `[?(${this.filters.join(" && ")})]`;
|
|
3722
|
-
}
|
|
3723
|
-
for (const mod of this.modifiers) {
|
|
3724
|
-
query2 += `#${mod}`;
|
|
3725
|
-
}
|
|
3726
|
-
return query2;
|
|
3727
|
-
}
|
|
3728
|
-
toString() {
|
|
3729
|
-
return this.build();
|
|
3730
|
-
}
|
|
3731
|
-
};
|
|
3732
|
-
function query(entity) {
|
|
3733
|
-
return new QueryBuilder(entity);
|
|
3734
|
-
}
|
|
3735
|
-
|
|
3736
|
-
export { AUTHORIZATION_TYPE, AUTH_MUTATION, AuthService, BusinessService, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CONTACT_TYPE, CURRENCY_SYMBOLS, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyClient, CimplifyElement, CimplifyElements, CimplifyError, DEFAULT_COUNTRY, DEFAULT_CURRENCY, DEVICE_TYPE, ELEMENT_TYPES, ERROR_HINTS, EVENT_TYPES, ErrorCode, FxService, InventoryService, LINK_MUTATION, LINK_QUERY, LinkService, LiteService, MESSAGE_TYPES, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, ORDER_MUTATION, ORDER_TYPE, OrderQueries, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, QueryBuilder, SchedulingService, categorizePaymentError, combine, combineObject, createCimplifyClient, createElements, detectMobileMoneyProvider, enrichError, err, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getErrorHint, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, query, toNullable, tryCatch, unwrap };
|
|
3790
|
+
export { AUTHORIZATION_TYPE, AUTH_MUTATION, AuthService, BusinessService, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CONTACT_TYPE, CURRENCY_SYMBOLS, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyClient, CimplifyElement, CimplifyElements, CimplifyError, DEFAULT_COUNTRY, DEFAULT_CURRENCY, DEVICE_TYPE, ELEMENT_TYPES, ERROR_HINTS, EVENT_TYPES, ErrorCode, FxService, InventoryService, LINK_MUTATION, LINK_QUERY, LinkService, LiteService, MESSAGE_TYPES, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, ORDER_MUTATION, ORDER_TYPE, OrderQueries, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, QueryBuilder, SchedulingService, ZERO, categorizePaymentError, combine, combineObject, createCimplifyClient, createElements, currencyCode, detectMobileMoneyProvider, enrichError, err, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getErrorHint, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isRetryableError, mapError, mapResult, money, moneyFromNumber, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, query, toNullable, tryCatch, unwrap };
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare const __money: unique symbol;
|
|
2
|
+
/** Decimal monetary amount as a string (e.g. "29.99"). Branded to prevent mixing with plain strings. */
|
|
3
|
+
type Money = string & {
|
|
4
|
+
readonly [__money]: true;
|
|
5
|
+
};
|
|
6
|
+
/** Create a Money value from a string decimal. */
|
|
7
|
+
declare function money(value: string): Money;
|
|
8
|
+
/** Create a Money value from a number. Converts to a 2-decimal string. */
|
|
9
|
+
declare function moneyFromNumber(value: number): Money;
|
|
10
|
+
/** Zero money constant. */
|
|
11
|
+
declare const ZERO: Money;
|
|
12
|
+
/** ISO 4217 currency codes supported by the platform */
|
|
13
|
+
type CurrencyCode = "USD" | "EUR" | "GBP" | "JPY" | "CNY" | "CHF" | "CAD" | "AUD" | "GHS" | "NGN" | "KES" | "ZAR" | "XOF" | "XAF" | "EGP" | "TZS" | "UGX" | "RWF" | "ETB" | "ZMW" | "BWP" | "MUR" | "NAD" | "MWK" | "AOA" | "CDF" | "GMD" | "GNF" | "LRD" | "SLL" | "MZN" | "BIF" | "INR" | "BRL" | "MXN" | "KRW" | "TRY" | "THB" | "MYR" | "PHP" | "IDR" | "VND" | "SGD" | "HKD" | "TWD" | "AED" | "SAR" | "ILS";
|
|
14
|
+
/** Assert a string as CurrencyCode at API boundaries. */
|
|
15
|
+
declare function currencyCode(value: string): CurrencyCode;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `CurrencyCode` instead. Kept for backward compatibility.
|
|
18
|
+
*/
|
|
19
|
+
type Currency = CurrencyCode;
|
|
5
20
|
/** Pagination parameters */
|
|
6
21
|
interface PaginationParams {
|
|
7
22
|
page?: number;
|
|
@@ -121,7 +136,7 @@ interface Payment {
|
|
|
121
136
|
order_id: string;
|
|
122
137
|
business_id: string;
|
|
123
138
|
amount: Money;
|
|
124
|
-
currency:
|
|
139
|
+
currency: CurrencyCode;
|
|
125
140
|
payment_method: PaymentMethod;
|
|
126
141
|
status: PaymentStatus;
|
|
127
142
|
provider: PaymentProvider;
|
|
@@ -162,7 +177,7 @@ interface PaymentStatusResponse {
|
|
|
162
177
|
status: PaymentStatus;
|
|
163
178
|
paid: boolean;
|
|
164
179
|
amount?: Money;
|
|
165
|
-
currency?:
|
|
180
|
+
currency?: CurrencyCode;
|
|
166
181
|
reference?: string;
|
|
167
182
|
message?: string;
|
|
168
183
|
}
|
|
@@ -178,4 +193,4 @@ interface SubmitAuthorizationInput {
|
|
|
178
193
|
value: string;
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
export { type ApiError as A, type
|
|
196
|
+
export { type ApiError as A, type CurrencyCode as C, ErrorCode as E, type InitializePaymentResult as I, type Money as M, type PaginationParams as P, type SubmitAuthorizationInput as S, ZERO as Z, moneyFromNumber as a, type Currency as b, currencyCode as c, type Pagination as d, type ErrorCodeType as e, type ErrorHint as f, ERROR_HINTS as g, CimplifyError as h, isCimplifyError as i, getErrorHint as j, enrichError as k, isRetryableError as l, money as m, type PaymentStatus as n, type PaymentProvider as o, type PaymentMethodType as p, type AuthorizationType as q, type PaymentProcessingState as r, type PaymentMethod as s, type Payment as t, type PaymentResponse as u, type PaymentStatusResponse as v, type PaymentErrorDetails as w };
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare const __money: unique symbol;
|
|
2
|
+
/** Decimal monetary amount as a string (e.g. "29.99"). Branded to prevent mixing with plain strings. */
|
|
3
|
+
type Money = string & {
|
|
4
|
+
readonly [__money]: true;
|
|
5
|
+
};
|
|
6
|
+
/** Create a Money value from a string decimal. */
|
|
7
|
+
declare function money(value: string): Money;
|
|
8
|
+
/** Create a Money value from a number. Converts to a 2-decimal string. */
|
|
9
|
+
declare function moneyFromNumber(value: number): Money;
|
|
10
|
+
/** Zero money constant. */
|
|
11
|
+
declare const ZERO: Money;
|
|
12
|
+
/** ISO 4217 currency codes supported by the platform */
|
|
13
|
+
type CurrencyCode = "USD" | "EUR" | "GBP" | "JPY" | "CNY" | "CHF" | "CAD" | "AUD" | "GHS" | "NGN" | "KES" | "ZAR" | "XOF" | "XAF" | "EGP" | "TZS" | "UGX" | "RWF" | "ETB" | "ZMW" | "BWP" | "MUR" | "NAD" | "MWK" | "AOA" | "CDF" | "GMD" | "GNF" | "LRD" | "SLL" | "MZN" | "BIF" | "INR" | "BRL" | "MXN" | "KRW" | "TRY" | "THB" | "MYR" | "PHP" | "IDR" | "VND" | "SGD" | "HKD" | "TWD" | "AED" | "SAR" | "ILS";
|
|
14
|
+
/** Assert a string as CurrencyCode at API boundaries. */
|
|
15
|
+
declare function currencyCode(value: string): CurrencyCode;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `CurrencyCode` instead. Kept for backward compatibility.
|
|
18
|
+
*/
|
|
19
|
+
type Currency = CurrencyCode;
|
|
5
20
|
/** Pagination parameters */
|
|
6
21
|
interface PaginationParams {
|
|
7
22
|
page?: number;
|
|
@@ -121,7 +136,7 @@ interface Payment {
|
|
|
121
136
|
order_id: string;
|
|
122
137
|
business_id: string;
|
|
123
138
|
amount: Money;
|
|
124
|
-
currency:
|
|
139
|
+
currency: CurrencyCode;
|
|
125
140
|
payment_method: PaymentMethod;
|
|
126
141
|
status: PaymentStatus;
|
|
127
142
|
provider: PaymentProvider;
|
|
@@ -162,7 +177,7 @@ interface PaymentStatusResponse {
|
|
|
162
177
|
status: PaymentStatus;
|
|
163
178
|
paid: boolean;
|
|
164
179
|
amount?: Money;
|
|
165
|
-
currency?:
|
|
180
|
+
currency?: CurrencyCode;
|
|
166
181
|
reference?: string;
|
|
167
182
|
message?: string;
|
|
168
183
|
}
|
|
@@ -178,4 +193,4 @@ interface SubmitAuthorizationInput {
|
|
|
178
193
|
value: string;
|
|
179
194
|
}
|
|
180
195
|
|
|
181
|
-
export { type ApiError as A, type
|
|
196
|
+
export { type ApiError as A, type CurrencyCode as C, ErrorCode as E, type InitializePaymentResult as I, type Money as M, type PaginationParams as P, type SubmitAuthorizationInput as S, ZERO as Z, moneyFromNumber as a, type Currency as b, currencyCode as c, type Pagination as d, type ErrorCodeType as e, type ErrorHint as f, ERROR_HINTS as g, CimplifyError as h, isCimplifyError as i, getErrorHint as j, enrichError as k, isRetryableError as l, money as m, type PaymentStatus as n, type PaymentProvider as o, type PaymentMethodType as p, type AuthorizationType as q, type PaymentProcessingState as r, type PaymentMethod as s, type Payment as t, type PaymentResponse as u, type PaymentStatusResponse as v, type PaymentErrorDetails as w };
|
package/dist/react.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as CimplifyClient, _ as ProcessCheckoutResult, a0 as CheckoutStatus, a1 as CheckoutStatusContext, cT as Location, cQ as Business, aL as Product, aM as ProductWithDetails, a_ as Category, bH as BundleSelectionInput, bi as ComponentSelectionInput, cj as Order, u as CimplifyElements, y as ElementsOptions, eh as AuthenticatedData, ed as AddressInfo, ee as PaymentMethodInfo, ej as ElementsCheckoutResult, Z as ProcessCheckoutOptions } from './client-
|
|
1
|
+
import { C as CimplifyClient, _ as ProcessCheckoutResult, a0 as CheckoutStatus, a1 as CheckoutStatusContext, cT as Location, cQ as Business, aL as Product, aM as ProductWithDetails, a_ as Category, bH as BundleSelectionInput, bi as ComponentSelectionInput, cj as Order, b0 as Collection, b7 as BundleWithDetails, be as CompositeWithDetails, bj as CompositePriceResult, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, P as PriceQuote, g as QuoteUiMessage, u as CimplifyElements, y as ElementsOptions, eh as AuthenticatedData, ed as AddressInfo, ee as PaymentMethodInfo, ej as ElementsCheckoutResult, Z as ProcessCheckoutOptions } from './client-FQUyv41r.mjs';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
|
+
import { h as CimplifyError, C as CurrencyCode } from './payment-Cu75tmUc.mjs';
|
|
3
4
|
import { A as AdSlot, a as AdPosition, e as AdContextValue } from './ads-t3FBTU8p.mjs';
|
|
4
5
|
export { c as AdConfig } from './ads-t3FBTU8p.mjs';
|
|
5
|
-
import { e as CimplifyError } from './payment-pjpfIKX8.mjs';
|
|
6
6
|
|
|
7
7
|
interface UserIdentity {
|
|
8
8
|
uid: string;
|
|
@@ -221,6 +221,101 @@ interface UseLocationsResult {
|
|
|
221
221
|
}
|
|
222
222
|
declare function useLocations(options?: UseLocationsOptions): UseLocationsResult;
|
|
223
223
|
|
|
224
|
+
interface UseCollectionsOptions {
|
|
225
|
+
client?: CimplifyClient;
|
|
226
|
+
enabled?: boolean;
|
|
227
|
+
}
|
|
228
|
+
interface UseCollectionsResult {
|
|
229
|
+
collections: Collection[];
|
|
230
|
+
isLoading: boolean;
|
|
231
|
+
error: CimplifyError | null;
|
|
232
|
+
refetch: () => Promise<void>;
|
|
233
|
+
}
|
|
234
|
+
declare function useCollections(options?: UseCollectionsOptions): UseCollectionsResult;
|
|
235
|
+
|
|
236
|
+
interface UseCollectionOptions {
|
|
237
|
+
client?: CimplifyClient;
|
|
238
|
+
enabled?: boolean;
|
|
239
|
+
}
|
|
240
|
+
interface UseCollectionResult {
|
|
241
|
+
collection: Collection | null;
|
|
242
|
+
products: Product[];
|
|
243
|
+
isLoading: boolean;
|
|
244
|
+
error: CimplifyError | null;
|
|
245
|
+
refetch: () => Promise<void>;
|
|
246
|
+
}
|
|
247
|
+
declare function useCollection(idOrSlug: string | null | undefined, options?: UseCollectionOptions): UseCollectionResult;
|
|
248
|
+
|
|
249
|
+
interface UseBundleOptions {
|
|
250
|
+
client?: CimplifyClient;
|
|
251
|
+
enabled?: boolean;
|
|
252
|
+
}
|
|
253
|
+
interface UseBundleResult {
|
|
254
|
+
bundle: BundleWithDetails | null;
|
|
255
|
+
isLoading: boolean;
|
|
256
|
+
error: CimplifyError | null;
|
|
257
|
+
refetch: () => Promise<void>;
|
|
258
|
+
}
|
|
259
|
+
declare function useBundle(idOrSlug: string | null | undefined, options?: UseBundleOptions): UseBundleResult;
|
|
260
|
+
|
|
261
|
+
interface UseCompositeOptions {
|
|
262
|
+
client?: CimplifyClient;
|
|
263
|
+
enabled?: boolean;
|
|
264
|
+
byProductId?: boolean;
|
|
265
|
+
}
|
|
266
|
+
interface UseCompositeResult {
|
|
267
|
+
composite: CompositeWithDetails | null;
|
|
268
|
+
isLoading: boolean;
|
|
269
|
+
error: CimplifyError | null;
|
|
270
|
+
refetch: () => Promise<void>;
|
|
271
|
+
calculatePrice: (selections: ComponentSelectionInput[], locationId?: string) => Promise<CompositePriceResult | null>;
|
|
272
|
+
priceResult: CompositePriceResult | null;
|
|
273
|
+
isPriceLoading: boolean;
|
|
274
|
+
}
|
|
275
|
+
declare function useComposite(idOrProductId: string | null | undefined, options?: UseCompositeOptions): UseCompositeResult;
|
|
276
|
+
|
|
277
|
+
interface UseSearchOptions {
|
|
278
|
+
client?: CimplifyClient;
|
|
279
|
+
minLength?: number;
|
|
280
|
+
debounceMs?: number;
|
|
281
|
+
limit?: number;
|
|
282
|
+
category?: string;
|
|
283
|
+
}
|
|
284
|
+
interface UseSearchResult {
|
|
285
|
+
results: Product[];
|
|
286
|
+
isLoading: boolean;
|
|
287
|
+
error: CimplifyError | null;
|
|
288
|
+
query: string;
|
|
289
|
+
setQuery: (query: string) => void;
|
|
290
|
+
clear: () => void;
|
|
291
|
+
}
|
|
292
|
+
declare function useSearch(options?: UseSearchOptions): UseSearchResult;
|
|
293
|
+
|
|
294
|
+
interface UseQuoteOptions {
|
|
295
|
+
client?: CimplifyClient;
|
|
296
|
+
enabled?: boolean;
|
|
297
|
+
autoRefresh?: boolean;
|
|
298
|
+
refreshBeforeExpiryMs?: number;
|
|
299
|
+
}
|
|
300
|
+
interface UseQuoteInput {
|
|
301
|
+
productId: string;
|
|
302
|
+
variantId?: string;
|
|
303
|
+
locationId?: string;
|
|
304
|
+
quantity?: number;
|
|
305
|
+
addOnOptionIds?: string[];
|
|
306
|
+
bundleSelections?: QuoteBundleSelectionInput[];
|
|
307
|
+
compositeSelections?: QuoteCompositeSelectionInput[];
|
|
308
|
+
}
|
|
309
|
+
interface UseQuoteResult {
|
|
310
|
+
quote: PriceQuote | null;
|
|
311
|
+
isLoading: boolean;
|
|
312
|
+
error: CimplifyError | null;
|
|
313
|
+
refresh: () => Promise<void>;
|
|
314
|
+
isExpired: boolean;
|
|
315
|
+
messages: QuoteUiMessage[];
|
|
316
|
+
}
|
|
317
|
+
declare function useQuote(input: UseQuoteInput | null | undefined, options?: UseQuoteOptions): UseQuoteResult;
|
|
318
|
+
|
|
224
319
|
declare function useElements(): CimplifyElements | null;
|
|
225
320
|
declare function useElementsReady(): boolean;
|
|
226
321
|
interface ElementsProviderProps {
|
|
@@ -257,7 +352,7 @@ interface AddressElementProps extends BaseElementProps {
|
|
|
257
352
|
declare function AddressElement({ className, style, mode, onReady, onChange, onError, }: AddressElementProps): React.ReactElement | null;
|
|
258
353
|
interface PaymentElementProps extends BaseElementProps {
|
|
259
354
|
amount?: number;
|
|
260
|
-
currency?:
|
|
355
|
+
currency?: CurrencyCode;
|
|
261
356
|
onChange?: (data: {
|
|
262
357
|
paymentMethod: PaymentMethodInfo;
|
|
263
358
|
saveToLink: boolean;
|
|
@@ -277,4 +372,4 @@ declare function useCheckout(): {
|
|
|
277
372
|
isLoading: boolean;
|
|
278
373
|
};
|
|
279
374
|
|
|
280
|
-
export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, type AddToCartOptions, AddressElement, AuthElement, CimplifyCheckout, type CimplifyCheckoutProps, type CimplifyContextValue, CimplifyProvider, type CimplifyProviderProps, ElementsProvider, PaymentElement, type UseCartItem, type UseCartOptions, type UseCartResult, type UseCategoriesOptions, type UseCategoriesResult, type UseLocationsOptions, type UseLocationsResult, type UseOrderOptions, type UseOrderResult, type UseProductOptions, type UseProductResult, type UseProductsOptions, type UseProductsResult, useAds, useCart, useCategories, useCheckout, useCimplify, useElements, useElementsReady, useLocations, useOptionalCimplify, useOrder, useProduct, useProducts };
|
|
375
|
+
export { Ad, AdPosition, type AdProps, AdProvider, AdSlot, type AddToCartOptions, AddressElement, AuthElement, CimplifyCheckout, type CimplifyCheckoutProps, type CimplifyContextValue, CimplifyProvider, type CimplifyProviderProps, ElementsProvider, PaymentElement, type UseBundleOptions, type UseBundleResult, type UseCartItem, type UseCartOptions, type UseCartResult, type UseCategoriesOptions, type UseCategoriesResult, type UseCollectionOptions, type UseCollectionResult, type UseCollectionsOptions, type UseCollectionsResult, type UseCompositeOptions, type UseCompositeResult, type UseLocationsOptions, type UseLocationsResult, type UseOrderOptions, type UseOrderResult, type UseProductOptions, type UseProductResult, type UseProductsOptions, type UseProductsResult, type UseQuoteInput, type UseQuoteOptions, type UseQuoteResult, type UseSearchOptions, type UseSearchResult, useAds, useBundle, useCart, useCategories, useCheckout, useCimplify, useCollection, useCollections, useComposite, useElements, useElementsReady, useLocations, useOptionalCimplify, useOrder, useProduct, useProducts, useQuote, useSearch };
|