@cimplify/sdk 0.6.7 → 0.6.9
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 +127 -98
- package/dist/advanced.mjs +127 -98
- package/dist/{client-B4etj3AD.d.mts → client-COpV6Yuu.d.ts} +39 -34
- package/dist/{client-CYVVuP5J.d.ts → client-vmXPt1j0.d.mts} +39 -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 +165 -99
- package/dist/index.mjs +162 -100
- 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 +845 -39
- package/dist/react.mjs +840 -40
- 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", {});
|
|
@@ -1986,6 +2083,9 @@ var LinkService = class {
|
|
|
1986
2083
|
constructor(client) {
|
|
1987
2084
|
this.client = client;
|
|
1988
2085
|
}
|
|
2086
|
+
async getProfile() {
|
|
2087
|
+
return safe5(this.client.linkGet("/v1/link/profile"));
|
|
2088
|
+
}
|
|
1989
2089
|
async requestOtp(input) {
|
|
1990
2090
|
return safe5(this.client.linkPost("/v1/link/auth/request-otp", input));
|
|
1991
2091
|
}
|
|
@@ -2013,13 +2113,13 @@ var LinkService = class {
|
|
|
2013
2113
|
);
|
|
2014
2114
|
}
|
|
2015
2115
|
async getLinkData() {
|
|
2016
|
-
return safe5(this.client.
|
|
2116
|
+
return safe5(this.client.linkGet("/v1/link/data"));
|
|
2017
2117
|
}
|
|
2018
2118
|
async getAddresses() {
|
|
2019
|
-
return safe5(this.client.
|
|
2119
|
+
return safe5(this.client.linkGet("/v1/link/addresses"));
|
|
2020
2120
|
}
|
|
2021
2121
|
async getMobileMoney() {
|
|
2022
|
-
return safe5(this.client.
|
|
2122
|
+
return safe5(this.client.linkGet("/v1/link/mobile-money"));
|
|
2023
2123
|
}
|
|
2024
2124
|
async getPreferences() {
|
|
2025
2125
|
return safe5(this.client.query(LINK_QUERY.PREFERENCES));
|
|
@@ -2042,10 +2142,10 @@ var LinkService = class {
|
|
|
2042
2142
|
return safe5(this.client.call(LINK_MUTATION.UPDATE_ADDRESS, input));
|
|
2043
2143
|
}
|
|
2044
2144
|
async deleteAddress(addressId) {
|
|
2045
|
-
return safe5(this.client.
|
|
2145
|
+
return safe5(this.client.linkDelete(`/v1/link/addresses/${addressId}`));
|
|
2046
2146
|
}
|
|
2047
2147
|
async setDefaultAddress(addressId) {
|
|
2048
|
-
return safe5(this.client.
|
|
2148
|
+
return safe5(this.client.linkPost(`/v1/link/addresses/${addressId}/default`));
|
|
2049
2149
|
}
|
|
2050
2150
|
async trackAddressUsage(addressId) {
|
|
2051
2151
|
return safe5(
|
|
@@ -2058,11 +2158,13 @@ var LinkService = class {
|
|
|
2058
2158
|
return safe5(this.client.call(LINK_MUTATION.CREATE_MOBILE_MONEY, input));
|
|
2059
2159
|
}
|
|
2060
2160
|
async deleteMobileMoney(mobileMoneyId) {
|
|
2061
|
-
return safe5(
|
|
2161
|
+
return safe5(
|
|
2162
|
+
this.client.linkDelete(`/v1/link/mobile-money/${mobileMoneyId}`)
|
|
2163
|
+
);
|
|
2062
2164
|
}
|
|
2063
2165
|
async setDefaultMobileMoney(mobileMoneyId) {
|
|
2064
2166
|
return safe5(
|
|
2065
|
-
this.client.
|
|
2167
|
+
this.client.linkPost(`/v1/link/mobile-money/${mobileMoneyId}/default`)
|
|
2066
2168
|
);
|
|
2067
2169
|
}
|
|
2068
2170
|
async trackMobileMoneyUsage(mobileMoneyId) {
|
|
@@ -3227,7 +3329,7 @@ var CimplifyClient = class {
|
|
|
3227
3329
|
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
3228
3330
|
this.hooks = config.hooks ?? {};
|
|
3229
3331
|
this.accessToken = this.loadAccessToken();
|
|
3230
|
-
if (!this.publicKey) {
|
|
3332
|
+
if (!this.publicKey && !config.suppressPublicKeyWarning) {
|
|
3231
3333
|
console.warn(
|
|
3232
3334
|
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "pk_..." } to createCimplifyClient().'
|
|
3233
3335
|
);
|
|
@@ -3340,9 +3442,12 @@ var CimplifyClient = class {
|
|
|
3340
3442
|
}
|
|
3341
3443
|
getHeaders() {
|
|
3342
3444
|
const headers = {
|
|
3343
|
-
"Content-Type": "application/json"
|
|
3344
|
-
"X-API-Key": this.publicKey
|
|
3445
|
+
"Content-Type": "application/json"
|
|
3345
3446
|
};
|
|
3447
|
+
const trimmedPublicKey = this.publicKey.trim();
|
|
3448
|
+
if (trimmedPublicKey) {
|
|
3449
|
+
headers["X-API-Key"] = trimmedPublicKey;
|
|
3450
|
+
}
|
|
3346
3451
|
if (this.accessToken) {
|
|
3347
3452
|
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
3348
3453
|
}
|
|
@@ -3371,7 +3476,7 @@ var CimplifyClient = class {
|
|
|
3371
3476
|
signal: controller.signal
|
|
3372
3477
|
});
|
|
3373
3478
|
clearTimeout(timeoutId);
|
|
3374
|
-
if (response.ok
|
|
3479
|
+
if (response.ok) {
|
|
3375
3480
|
this.hooks.onRequestSuccess?.({
|
|
3376
3481
|
...context,
|
|
3377
3482
|
status: response.status,
|
|
@@ -3379,6 +3484,21 @@ var CimplifyClient = class {
|
|
|
3379
3484
|
});
|
|
3380
3485
|
return response;
|
|
3381
3486
|
}
|
|
3487
|
+
if (response.status >= 400 && response.status < 500) {
|
|
3488
|
+
this.hooks.onRequestError?.({
|
|
3489
|
+
...context,
|
|
3490
|
+
error: new CimplifyError(
|
|
3491
|
+
`HTTP_${response.status}`,
|
|
3492
|
+
`Request failed with status ${response.status}`,
|
|
3493
|
+
false
|
|
3494
|
+
),
|
|
3495
|
+
status: response.status,
|
|
3496
|
+
durationMs: Date.now() - startTime,
|
|
3497
|
+
retryCount,
|
|
3498
|
+
retryable: false
|
|
3499
|
+
});
|
|
3500
|
+
return response;
|
|
3501
|
+
}
|
|
3382
3502
|
if (response.status >= 500 && attempt < this.maxRetries) {
|
|
3383
3503
|
retryCount++;
|
|
3384
3504
|
const delay = this.retryDelay * Math.pow(2, attempt);
|
|
@@ -3391,10 +3511,17 @@ var CimplifyClient = class {
|
|
|
3391
3511
|
await sleep(delay);
|
|
3392
3512
|
continue;
|
|
3393
3513
|
}
|
|
3394
|
-
this.hooks.
|
|
3514
|
+
this.hooks.onRequestError?.({
|
|
3395
3515
|
...context,
|
|
3516
|
+
error: new CimplifyError(
|
|
3517
|
+
"SERVER_ERROR",
|
|
3518
|
+
`Server error ${response.status} after ${retryCount} retries`,
|
|
3519
|
+
false
|
|
3520
|
+
),
|
|
3396
3521
|
status: response.status,
|
|
3397
|
-
durationMs: Date.now() - startTime
|
|
3522
|
+
durationMs: Date.now() - startTime,
|
|
3523
|
+
retryCount,
|
|
3524
|
+
retryable: false
|
|
3398
3525
|
});
|
|
3399
3526
|
return response;
|
|
3400
3527
|
} catch (error) {
|
|
@@ -3668,69 +3795,4 @@ function createCimplifyClient(config = {}) {
|
|
|
3668
3795
|
return new CimplifyClient(config);
|
|
3669
3796
|
}
|
|
3670
3797
|
|
|
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 };
|
|
3798
|
+
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 };
|