@cimplify/sdk 0.5.3 → 0.6.1
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 +5 -0
- package/dist/{ads-BZbkhijm.d.mts → ads-DRfobDQ9.d.mts} +341 -216
- package/dist/{ads-BZbkhijm.d.ts → ads-DRfobDQ9.d.ts} +341 -216
- package/dist/index.d.mts +25 -92
- package/dist/index.d.ts +25 -92
- package/dist/index.js +75 -165
- package/dist/index.mjs +75 -163
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -315,6 +315,19 @@ var CatalogueQueries = class {
|
|
|
315
315
|
})
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
|
+
async fetchQuote(input) {
|
|
319
|
+
return safe(this.client.call("catalogue.createQuote", input));
|
|
320
|
+
}
|
|
321
|
+
async getQuote(quoteId) {
|
|
322
|
+
return safe(
|
|
323
|
+
this.client.call("catalogue.getQuote", {
|
|
324
|
+
quote_id: quoteId
|
|
325
|
+
})
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
async refreshQuote(input) {
|
|
329
|
+
return safe(this.client.call("catalogue.refreshQuote", input));
|
|
330
|
+
}
|
|
318
331
|
async search(query2, options) {
|
|
319
332
|
const limit = options?.limit ?? 20;
|
|
320
333
|
let searchQuery = `products[?(@.name contains '${query2}')]`;
|
|
@@ -366,12 +379,20 @@ async function safe2(promise) {
|
|
|
366
379
|
return err(toCimplifyError2(error));
|
|
367
380
|
}
|
|
368
381
|
}
|
|
382
|
+
function isUICartResponse(value) {
|
|
383
|
+
return "cart" in value;
|
|
384
|
+
}
|
|
385
|
+
function unwrapEnrichedCart(value) {
|
|
386
|
+
return isUICartResponse(value) ? value.cart : value;
|
|
387
|
+
}
|
|
369
388
|
var CartOperations = class {
|
|
370
389
|
constructor(client) {
|
|
371
390
|
this.client = client;
|
|
372
391
|
}
|
|
373
392
|
async get() {
|
|
374
|
-
|
|
393
|
+
const result = await safe2(this.client.query("cart#enriched"));
|
|
394
|
+
if (!result.ok) return result;
|
|
395
|
+
return ok(unwrapEnrichedCart(result.value));
|
|
375
396
|
}
|
|
376
397
|
async getRaw() {
|
|
377
398
|
return safe2(this.client.query("cart"));
|
|
@@ -1230,6 +1251,33 @@ var LiteService = class {
|
|
|
1230
1251
|
}
|
|
1231
1252
|
};
|
|
1232
1253
|
|
|
1254
|
+
// src/fx.ts
|
|
1255
|
+
function toCimplifyError11(error) {
|
|
1256
|
+
if (error instanceof CimplifyError) return error;
|
|
1257
|
+
if (error instanceof Error) {
|
|
1258
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1259
|
+
}
|
|
1260
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1261
|
+
}
|
|
1262
|
+
async function safe11(promise) {
|
|
1263
|
+
try {
|
|
1264
|
+
return ok(await promise);
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
return err(toCimplifyError11(error));
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
var FxService = class {
|
|
1270
|
+
constructor(client) {
|
|
1271
|
+
this.client = client;
|
|
1272
|
+
}
|
|
1273
|
+
async getRate(from, to) {
|
|
1274
|
+
return safe11(this.client.call("fx.getRate", { from, to }));
|
|
1275
|
+
}
|
|
1276
|
+
async lockQuote(request) {
|
|
1277
|
+
return safe11(this.client.call("fx.lockQuote", request));
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1233
1281
|
// src/types/elements.ts
|
|
1234
1282
|
var ELEMENT_TYPES = {
|
|
1235
1283
|
AUTH: "auth",
|
|
@@ -2010,6 +2058,12 @@ var CimplifyClient = class {
|
|
|
2010
2058
|
}
|
|
2011
2059
|
return this._lite;
|
|
2012
2060
|
}
|
|
2061
|
+
get fx() {
|
|
2062
|
+
if (!this._fx) {
|
|
2063
|
+
this._fx = new FxService(this);
|
|
2064
|
+
}
|
|
2065
|
+
return this._fx;
|
|
2066
|
+
}
|
|
2013
2067
|
/**
|
|
2014
2068
|
* Create a CimplifyElements instance for embedding checkout components.
|
|
2015
2069
|
* Like Stripe's stripe.elements().
|
|
@@ -2242,169 +2296,27 @@ function parsePrice(value) {
|
|
|
2242
2296
|
const parsed = parseFloat(cleaned);
|
|
2243
2297
|
return isNaN(parsed) ? 0 : parsed;
|
|
2244
2298
|
}
|
|
2245
|
-
function
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
if (parts.length < 4 || parts[0] !== "T") {
|
|
2249
|
-
return void 0;
|
|
2250
|
-
}
|
|
2251
|
-
const taxRate = parseFloat(parts[1]);
|
|
2252
|
-
const taxAmount = parseFloat(parts[2]);
|
|
2253
|
-
const isInclusive = parts[3] === "I";
|
|
2254
|
-
const components = [];
|
|
2255
|
-
if (parts.length > 4 && parts[4]) {
|
|
2256
|
-
const componentPairs = parts[4].split(",");
|
|
2257
|
-
for (const pair of componentPairs) {
|
|
2258
|
-
const [name, rateStr] = pair.split(":");
|
|
2259
|
-
if (name && rateStr) {
|
|
2260
|
-
components.push({
|
|
2261
|
-
name: name.trim(),
|
|
2262
|
-
rate: parseFloat(rateStr)
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
return {
|
|
2268
|
-
taxRate,
|
|
2269
|
-
taxAmount,
|
|
2270
|
-
isInclusive,
|
|
2271
|
-
components
|
|
2272
|
-
};
|
|
2273
|
-
} catch {
|
|
2274
|
-
return void 0;
|
|
2299
|
+
function getDisplayPrice(product) {
|
|
2300
|
+
if (product.price_info) {
|
|
2301
|
+
return parsePrice(product.price_info.final_price);
|
|
2275
2302
|
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
if (!signedPricePath) {
|
|
2279
|
-
return {
|
|
2280
|
-
basePrice: 0,
|
|
2281
|
-
finalPrice: 0,
|
|
2282
|
-
currency: "GHS",
|
|
2283
|
-
decisionPath: "",
|
|
2284
|
-
isValid: false,
|
|
2285
|
-
isExpired: false
|
|
2286
|
-
};
|
|
2303
|
+
if (product.final_price !== void 0 && product.final_price !== null) {
|
|
2304
|
+
return parsePrice(product.final_price);
|
|
2287
2305
|
}
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
if (parts.length !== 3) {
|
|
2291
|
-
return {
|
|
2292
|
-
basePrice: 0,
|
|
2293
|
-
finalPrice: 0,
|
|
2294
|
-
currency: "GHS",
|
|
2295
|
-
decisionPath: "",
|
|
2296
|
-
isValid: false,
|
|
2297
|
-
isExpired: false
|
|
2298
|
-
};
|
|
2299
|
-
}
|
|
2300
|
-
const [pricePath, expiryStr, signature] = parts;
|
|
2301
|
-
const expiryTimestamp = parseInt(expiryStr, 10);
|
|
2302
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
2303
|
-
const isExpired = now > expiryTimestamp;
|
|
2304
|
-
const priceComponents = pricePath.split("|");
|
|
2305
|
-
if (priceComponents.length < 5) {
|
|
2306
|
-
return {
|
|
2307
|
-
basePrice: 0,
|
|
2308
|
-
finalPrice: 0,
|
|
2309
|
-
currency: "GHS",
|
|
2310
|
-
decisionPath: "",
|
|
2311
|
-
isValid: false,
|
|
2312
|
-
isExpired
|
|
2313
|
-
};
|
|
2314
|
-
}
|
|
2315
|
-
const basePrice = parseFloat(priceComponents[0]);
|
|
2316
|
-
const finalPrice = parseFloat(priceComponents[1]);
|
|
2317
|
-
const currency = priceComponents[2];
|
|
2318
|
-
const taxInfoStr = priceComponents[3];
|
|
2319
|
-
const decisionPath = priceComponents.slice(4).join("|");
|
|
2320
|
-
let taxInfo;
|
|
2321
|
-
if (taxInfoStr && taxInfoStr.startsWith("T:")) {
|
|
2322
|
-
taxInfo = parseTaxInfo(taxInfoStr);
|
|
2323
|
-
} else if (taxInfoStr === "0" || !taxInfoStr) {
|
|
2324
|
-
taxInfo = {
|
|
2325
|
-
taxRate: 0,
|
|
2326
|
-
taxAmount: 0,
|
|
2327
|
-
isInclusive: false,
|
|
2328
|
-
components: []
|
|
2329
|
-
};
|
|
2330
|
-
}
|
|
2331
|
-
let markupPercentage;
|
|
2332
|
-
let markupAmount;
|
|
2333
|
-
let discountPercentage;
|
|
2334
|
-
if (decisionPath) {
|
|
2335
|
-
const pathParts = decisionPath.split(":");
|
|
2336
|
-
if (pathParts.length > 1 && pathParts[1]) {
|
|
2337
|
-
const adjustments = pathParts[1].split(",");
|
|
2338
|
-
for (const adj of adjustments) {
|
|
2339
|
-
const adjParts = adj.split("|");
|
|
2340
|
-
if (adjParts[0] && adjParts[0].startsWith("ch")) {
|
|
2341
|
-
markupAmount = parseFloat(adjParts[1]) || 0;
|
|
2342
|
-
markupPercentage = parseFloat(adjParts[2]) || 0;
|
|
2343
|
-
break;
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
if (markupAmount === void 0 && finalPrice > basePrice) {
|
|
2349
|
-
markupAmount = finalPrice - basePrice;
|
|
2350
|
-
markupPercentage = basePrice > 0 ? markupAmount / basePrice * 100 : 0;
|
|
2351
|
-
} else if (basePrice > finalPrice) {
|
|
2352
|
-
discountPercentage = basePrice > 0 ? (basePrice - finalPrice) / basePrice * 100 : 0;
|
|
2353
|
-
}
|
|
2354
|
-
return {
|
|
2355
|
-
basePrice,
|
|
2356
|
-
finalPrice,
|
|
2357
|
-
currency,
|
|
2358
|
-
decisionPath,
|
|
2359
|
-
discountPercentage,
|
|
2360
|
-
markupPercentage,
|
|
2361
|
-
markupAmount,
|
|
2362
|
-
taxInfo,
|
|
2363
|
-
isValid: !isExpired && signature.length > 0,
|
|
2364
|
-
isExpired,
|
|
2365
|
-
expiryTimestamp
|
|
2366
|
-
};
|
|
2367
|
-
} catch {
|
|
2368
|
-
return {
|
|
2369
|
-
basePrice: 0,
|
|
2370
|
-
finalPrice: 0,
|
|
2371
|
-
currency: "GHS",
|
|
2372
|
-
decisionPath: "",
|
|
2373
|
-
isValid: false,
|
|
2374
|
-
isExpired: false
|
|
2375
|
-
};
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
function parsedPriceToPriceInfo(parsedPrice) {
|
|
2379
|
-
return {
|
|
2380
|
-
base_price: parsedPrice.basePrice,
|
|
2381
|
-
final_price: parsedPrice.finalPrice,
|
|
2382
|
-
markup_percentage: parsedPrice.markupPercentage,
|
|
2383
|
-
markup_amount: parsedPrice.markupAmount,
|
|
2384
|
-
currency: parsedPrice.currency,
|
|
2385
|
-
tax_info: parsedPrice.taxInfo,
|
|
2386
|
-
decision_path: parsedPrice.decisionPath
|
|
2387
|
-
};
|
|
2388
|
-
}
|
|
2389
|
-
function extractPriceInfo(signedPricePath) {
|
|
2390
|
-
const parsed = parsePricePath(signedPricePath);
|
|
2391
|
-
return parsedPriceToPriceInfo(parsed);
|
|
2392
|
-
}
|
|
2393
|
-
function getDisplayPrice(product) {
|
|
2394
|
-
if (product.price_path) {
|
|
2395
|
-
const priceInfo = extractPriceInfo(product.price_path);
|
|
2396
|
-
return priceInfo.final_price;
|
|
2397
|
-
} else if (product.price_info) {
|
|
2398
|
-
return product.price_info.final_price;
|
|
2306
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
2307
|
+
return parsePrice(product.default_price);
|
|
2399
2308
|
}
|
|
2400
2309
|
return 0;
|
|
2401
2310
|
}
|
|
2402
2311
|
function getBasePrice(product) {
|
|
2403
|
-
if (product.
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
return product.
|
|
2312
|
+
if (product.price_info) {
|
|
2313
|
+
return parsePrice(product.price_info.base_price);
|
|
2314
|
+
}
|
|
2315
|
+
if (product.base_price !== void 0 && product.base_price !== null) {
|
|
2316
|
+
return parsePrice(product.base_price);
|
|
2317
|
+
}
|
|
2318
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
2319
|
+
return parsePrice(product.default_price);
|
|
2408
2320
|
}
|
|
2409
2321
|
return 0;
|
|
2410
2322
|
}
|
|
@@ -2430,12 +2342,12 @@ function getMarkupPercentage(product) {
|
|
|
2430
2342
|
return 0;
|
|
2431
2343
|
}
|
|
2432
2344
|
function getProductCurrency(product) {
|
|
2433
|
-
if (product.
|
|
2434
|
-
const parsed = parsePricePath(product.price_path);
|
|
2435
|
-
return parsed.currency || "GHS";
|
|
2436
|
-
} else if (product.price_info?.currency) {
|
|
2345
|
+
if (product.price_info?.currency) {
|
|
2437
2346
|
return product.price_info.currency;
|
|
2438
2347
|
}
|
|
2348
|
+
if (product.currency) {
|
|
2349
|
+
return product.currency;
|
|
2350
|
+
}
|
|
2439
2351
|
return "GHS";
|
|
2440
2352
|
}
|
|
2441
2353
|
function formatProductPrice(product, locale = "en-US") {
|
|
@@ -2606,6 +2518,7 @@ exports.DEVICE_TYPE = DEVICE_TYPE;
|
|
|
2606
2518
|
exports.ELEMENT_TYPES = ELEMENT_TYPES;
|
|
2607
2519
|
exports.EVENT_TYPES = EVENT_TYPES;
|
|
2608
2520
|
exports.ErrorCode = ErrorCode;
|
|
2521
|
+
exports.FxService = FxService;
|
|
2609
2522
|
exports.InventoryService = InventoryService;
|
|
2610
2523
|
exports.LINK_MUTATION = LINK_MUTATION;
|
|
2611
2524
|
exports.LINK_QUERY = LINK_QUERY;
|
|
@@ -2630,7 +2543,6 @@ exports.createCimplifyClient = createCimplifyClient;
|
|
|
2630
2543
|
exports.createElements = createElements;
|
|
2631
2544
|
exports.detectMobileMoneyProvider = detectMobileMoneyProvider;
|
|
2632
2545
|
exports.err = err;
|
|
2633
|
-
exports.extractPriceInfo = extractPriceInfo;
|
|
2634
2546
|
exports.flatMap = flatMap;
|
|
2635
2547
|
exports.formatMoney = formatMoney;
|
|
2636
2548
|
exports.formatNumberCompact = formatNumberCompact;
|
|
@@ -2658,8 +2570,6 @@ exports.normalizePaymentResponse = normalizePaymentResponse;
|
|
|
2658
2570
|
exports.normalizeStatusResponse = normalizeStatusResponse;
|
|
2659
2571
|
exports.ok = ok;
|
|
2660
2572
|
exports.parsePrice = parsePrice;
|
|
2661
|
-
exports.parsePricePath = parsePricePath;
|
|
2662
|
-
exports.parsedPriceToPriceInfo = parsedPriceToPriceInfo;
|
|
2663
2573
|
exports.query = query;
|
|
2664
2574
|
exports.toNullable = toNullable;
|
|
2665
2575
|
exports.tryCatch = tryCatch;
|
package/dist/index.mjs
CHANGED
|
@@ -313,6 +313,19 @@ var CatalogueQueries = class {
|
|
|
313
313
|
})
|
|
314
314
|
);
|
|
315
315
|
}
|
|
316
|
+
async fetchQuote(input) {
|
|
317
|
+
return safe(this.client.call("catalogue.createQuote", input));
|
|
318
|
+
}
|
|
319
|
+
async getQuote(quoteId) {
|
|
320
|
+
return safe(
|
|
321
|
+
this.client.call("catalogue.getQuote", {
|
|
322
|
+
quote_id: quoteId
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
async refreshQuote(input) {
|
|
327
|
+
return safe(this.client.call("catalogue.refreshQuote", input));
|
|
328
|
+
}
|
|
316
329
|
async search(query2, options) {
|
|
317
330
|
const limit = options?.limit ?? 20;
|
|
318
331
|
let searchQuery = `products[?(@.name contains '${query2}')]`;
|
|
@@ -364,12 +377,20 @@ async function safe2(promise) {
|
|
|
364
377
|
return err(toCimplifyError2(error));
|
|
365
378
|
}
|
|
366
379
|
}
|
|
380
|
+
function isUICartResponse(value) {
|
|
381
|
+
return "cart" in value;
|
|
382
|
+
}
|
|
383
|
+
function unwrapEnrichedCart(value) {
|
|
384
|
+
return isUICartResponse(value) ? value.cart : value;
|
|
385
|
+
}
|
|
367
386
|
var CartOperations = class {
|
|
368
387
|
constructor(client) {
|
|
369
388
|
this.client = client;
|
|
370
389
|
}
|
|
371
390
|
async get() {
|
|
372
|
-
|
|
391
|
+
const result = await safe2(this.client.query("cart#enriched"));
|
|
392
|
+
if (!result.ok) return result;
|
|
393
|
+
return ok(unwrapEnrichedCart(result.value));
|
|
373
394
|
}
|
|
374
395
|
async getRaw() {
|
|
375
396
|
return safe2(this.client.query("cart"));
|
|
@@ -1228,6 +1249,33 @@ var LiteService = class {
|
|
|
1228
1249
|
}
|
|
1229
1250
|
};
|
|
1230
1251
|
|
|
1252
|
+
// src/fx.ts
|
|
1253
|
+
function toCimplifyError11(error) {
|
|
1254
|
+
if (error instanceof CimplifyError) return error;
|
|
1255
|
+
if (error instanceof Error) {
|
|
1256
|
+
return new CimplifyError("UNKNOWN_ERROR", error.message, false);
|
|
1257
|
+
}
|
|
1258
|
+
return new CimplifyError("UNKNOWN_ERROR", String(error), false);
|
|
1259
|
+
}
|
|
1260
|
+
async function safe11(promise) {
|
|
1261
|
+
try {
|
|
1262
|
+
return ok(await promise);
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
return err(toCimplifyError11(error));
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
var FxService = class {
|
|
1268
|
+
constructor(client) {
|
|
1269
|
+
this.client = client;
|
|
1270
|
+
}
|
|
1271
|
+
async getRate(from, to) {
|
|
1272
|
+
return safe11(this.client.call("fx.getRate", { from, to }));
|
|
1273
|
+
}
|
|
1274
|
+
async lockQuote(request) {
|
|
1275
|
+
return safe11(this.client.call("fx.lockQuote", request));
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1231
1279
|
// src/types/elements.ts
|
|
1232
1280
|
var ELEMENT_TYPES = {
|
|
1233
1281
|
AUTH: "auth",
|
|
@@ -2008,6 +2056,12 @@ var CimplifyClient = class {
|
|
|
2008
2056
|
}
|
|
2009
2057
|
return this._lite;
|
|
2010
2058
|
}
|
|
2059
|
+
get fx() {
|
|
2060
|
+
if (!this._fx) {
|
|
2061
|
+
this._fx = new FxService(this);
|
|
2062
|
+
}
|
|
2063
|
+
return this._fx;
|
|
2064
|
+
}
|
|
2011
2065
|
/**
|
|
2012
2066
|
* Create a CimplifyElements instance for embedding checkout components.
|
|
2013
2067
|
* Like Stripe's stripe.elements().
|
|
@@ -2240,169 +2294,27 @@ function parsePrice(value) {
|
|
|
2240
2294
|
const parsed = parseFloat(cleaned);
|
|
2241
2295
|
return isNaN(parsed) ? 0 : parsed;
|
|
2242
2296
|
}
|
|
2243
|
-
function
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
if (parts.length < 4 || parts[0] !== "T") {
|
|
2247
|
-
return void 0;
|
|
2248
|
-
}
|
|
2249
|
-
const taxRate = parseFloat(parts[1]);
|
|
2250
|
-
const taxAmount = parseFloat(parts[2]);
|
|
2251
|
-
const isInclusive = parts[3] === "I";
|
|
2252
|
-
const components = [];
|
|
2253
|
-
if (parts.length > 4 && parts[4]) {
|
|
2254
|
-
const componentPairs = parts[4].split(",");
|
|
2255
|
-
for (const pair of componentPairs) {
|
|
2256
|
-
const [name, rateStr] = pair.split(":");
|
|
2257
|
-
if (name && rateStr) {
|
|
2258
|
-
components.push({
|
|
2259
|
-
name: name.trim(),
|
|
2260
|
-
rate: parseFloat(rateStr)
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
return {
|
|
2266
|
-
taxRate,
|
|
2267
|
-
taxAmount,
|
|
2268
|
-
isInclusive,
|
|
2269
|
-
components
|
|
2270
|
-
};
|
|
2271
|
-
} catch {
|
|
2272
|
-
return void 0;
|
|
2297
|
+
function getDisplayPrice(product) {
|
|
2298
|
+
if (product.price_info) {
|
|
2299
|
+
return parsePrice(product.price_info.final_price);
|
|
2273
2300
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
if (!signedPricePath) {
|
|
2277
|
-
return {
|
|
2278
|
-
basePrice: 0,
|
|
2279
|
-
finalPrice: 0,
|
|
2280
|
-
currency: "GHS",
|
|
2281
|
-
decisionPath: "",
|
|
2282
|
-
isValid: false,
|
|
2283
|
-
isExpired: false
|
|
2284
|
-
};
|
|
2301
|
+
if (product.final_price !== void 0 && product.final_price !== null) {
|
|
2302
|
+
return parsePrice(product.final_price);
|
|
2285
2303
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
if (parts.length !== 3) {
|
|
2289
|
-
return {
|
|
2290
|
-
basePrice: 0,
|
|
2291
|
-
finalPrice: 0,
|
|
2292
|
-
currency: "GHS",
|
|
2293
|
-
decisionPath: "",
|
|
2294
|
-
isValid: false,
|
|
2295
|
-
isExpired: false
|
|
2296
|
-
};
|
|
2297
|
-
}
|
|
2298
|
-
const [pricePath, expiryStr, signature] = parts;
|
|
2299
|
-
const expiryTimestamp = parseInt(expiryStr, 10);
|
|
2300
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
2301
|
-
const isExpired = now > expiryTimestamp;
|
|
2302
|
-
const priceComponents = pricePath.split("|");
|
|
2303
|
-
if (priceComponents.length < 5) {
|
|
2304
|
-
return {
|
|
2305
|
-
basePrice: 0,
|
|
2306
|
-
finalPrice: 0,
|
|
2307
|
-
currency: "GHS",
|
|
2308
|
-
decisionPath: "",
|
|
2309
|
-
isValid: false,
|
|
2310
|
-
isExpired
|
|
2311
|
-
};
|
|
2312
|
-
}
|
|
2313
|
-
const basePrice = parseFloat(priceComponents[0]);
|
|
2314
|
-
const finalPrice = parseFloat(priceComponents[1]);
|
|
2315
|
-
const currency = priceComponents[2];
|
|
2316
|
-
const taxInfoStr = priceComponents[3];
|
|
2317
|
-
const decisionPath = priceComponents.slice(4).join("|");
|
|
2318
|
-
let taxInfo;
|
|
2319
|
-
if (taxInfoStr && taxInfoStr.startsWith("T:")) {
|
|
2320
|
-
taxInfo = parseTaxInfo(taxInfoStr);
|
|
2321
|
-
} else if (taxInfoStr === "0" || !taxInfoStr) {
|
|
2322
|
-
taxInfo = {
|
|
2323
|
-
taxRate: 0,
|
|
2324
|
-
taxAmount: 0,
|
|
2325
|
-
isInclusive: false,
|
|
2326
|
-
components: []
|
|
2327
|
-
};
|
|
2328
|
-
}
|
|
2329
|
-
let markupPercentage;
|
|
2330
|
-
let markupAmount;
|
|
2331
|
-
let discountPercentage;
|
|
2332
|
-
if (decisionPath) {
|
|
2333
|
-
const pathParts = decisionPath.split(":");
|
|
2334
|
-
if (pathParts.length > 1 && pathParts[1]) {
|
|
2335
|
-
const adjustments = pathParts[1].split(",");
|
|
2336
|
-
for (const adj of adjustments) {
|
|
2337
|
-
const adjParts = adj.split("|");
|
|
2338
|
-
if (adjParts[0] && adjParts[0].startsWith("ch")) {
|
|
2339
|
-
markupAmount = parseFloat(adjParts[1]) || 0;
|
|
2340
|
-
markupPercentage = parseFloat(adjParts[2]) || 0;
|
|
2341
|
-
break;
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
if (markupAmount === void 0 && finalPrice > basePrice) {
|
|
2347
|
-
markupAmount = finalPrice - basePrice;
|
|
2348
|
-
markupPercentage = basePrice > 0 ? markupAmount / basePrice * 100 : 0;
|
|
2349
|
-
} else if (basePrice > finalPrice) {
|
|
2350
|
-
discountPercentage = basePrice > 0 ? (basePrice - finalPrice) / basePrice * 100 : 0;
|
|
2351
|
-
}
|
|
2352
|
-
return {
|
|
2353
|
-
basePrice,
|
|
2354
|
-
finalPrice,
|
|
2355
|
-
currency,
|
|
2356
|
-
decisionPath,
|
|
2357
|
-
discountPercentage,
|
|
2358
|
-
markupPercentage,
|
|
2359
|
-
markupAmount,
|
|
2360
|
-
taxInfo,
|
|
2361
|
-
isValid: !isExpired && signature.length > 0,
|
|
2362
|
-
isExpired,
|
|
2363
|
-
expiryTimestamp
|
|
2364
|
-
};
|
|
2365
|
-
} catch {
|
|
2366
|
-
return {
|
|
2367
|
-
basePrice: 0,
|
|
2368
|
-
finalPrice: 0,
|
|
2369
|
-
currency: "GHS",
|
|
2370
|
-
decisionPath: "",
|
|
2371
|
-
isValid: false,
|
|
2372
|
-
isExpired: false
|
|
2373
|
-
};
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
function parsedPriceToPriceInfo(parsedPrice) {
|
|
2377
|
-
return {
|
|
2378
|
-
base_price: parsedPrice.basePrice,
|
|
2379
|
-
final_price: parsedPrice.finalPrice,
|
|
2380
|
-
markup_percentage: parsedPrice.markupPercentage,
|
|
2381
|
-
markup_amount: parsedPrice.markupAmount,
|
|
2382
|
-
currency: parsedPrice.currency,
|
|
2383
|
-
tax_info: parsedPrice.taxInfo,
|
|
2384
|
-
decision_path: parsedPrice.decisionPath
|
|
2385
|
-
};
|
|
2386
|
-
}
|
|
2387
|
-
function extractPriceInfo(signedPricePath) {
|
|
2388
|
-
const parsed = parsePricePath(signedPricePath);
|
|
2389
|
-
return parsedPriceToPriceInfo(parsed);
|
|
2390
|
-
}
|
|
2391
|
-
function getDisplayPrice(product) {
|
|
2392
|
-
if (product.price_path) {
|
|
2393
|
-
const priceInfo = extractPriceInfo(product.price_path);
|
|
2394
|
-
return priceInfo.final_price;
|
|
2395
|
-
} else if (product.price_info) {
|
|
2396
|
-
return product.price_info.final_price;
|
|
2304
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
2305
|
+
return parsePrice(product.default_price);
|
|
2397
2306
|
}
|
|
2398
2307
|
return 0;
|
|
2399
2308
|
}
|
|
2400
2309
|
function getBasePrice(product) {
|
|
2401
|
-
if (product.
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
return product.
|
|
2310
|
+
if (product.price_info) {
|
|
2311
|
+
return parsePrice(product.price_info.base_price);
|
|
2312
|
+
}
|
|
2313
|
+
if (product.base_price !== void 0 && product.base_price !== null) {
|
|
2314
|
+
return parsePrice(product.base_price);
|
|
2315
|
+
}
|
|
2316
|
+
if (product.default_price !== void 0 && product.default_price !== null) {
|
|
2317
|
+
return parsePrice(product.default_price);
|
|
2406
2318
|
}
|
|
2407
2319
|
return 0;
|
|
2408
2320
|
}
|
|
@@ -2428,12 +2340,12 @@ function getMarkupPercentage(product) {
|
|
|
2428
2340
|
return 0;
|
|
2429
2341
|
}
|
|
2430
2342
|
function getProductCurrency(product) {
|
|
2431
|
-
if (product.
|
|
2432
|
-
const parsed = parsePricePath(product.price_path);
|
|
2433
|
-
return parsed.currency || "GHS";
|
|
2434
|
-
} else if (product.price_info?.currency) {
|
|
2343
|
+
if (product.price_info?.currency) {
|
|
2435
2344
|
return product.price_info.currency;
|
|
2436
2345
|
}
|
|
2346
|
+
if (product.currency) {
|
|
2347
|
+
return product.currency;
|
|
2348
|
+
}
|
|
2437
2349
|
return "GHS";
|
|
2438
2350
|
}
|
|
2439
2351
|
function formatProductPrice(product, locale = "en-US") {
|
|
@@ -2581,4 +2493,4 @@ function detectMobileMoneyProvider(phoneNumber) {
|
|
|
2581
2493
|
return null;
|
|
2582
2494
|
}
|
|
2583
2495
|
|
|
2584
|
-
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, EVENT_TYPES, ErrorCode, 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, err,
|
|
2496
|
+
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, 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, err, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, query, toNullable, tryCatch, unwrap };
|
package/dist/react.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { eB as AdSlot, eC as AdPosition, eG as AdContextValue, y as CimplifyElements, C as CimplifyClient, J as ElementsOptions, ev as AuthenticatedData, et as AddressInfo, eu as PaymentMethodInfo, ex as ElementsCheckoutResult } from './ads-DRfobDQ9.mjs';
|
|
2
|
+
export { eE as AdConfig } from './ads-DRfobDQ9.mjs';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
interface UserIdentity {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { eB as AdSlot, eC as AdPosition, eG as AdContextValue, y as CimplifyElements, C as CimplifyClient, J as ElementsOptions, ev as AuthenticatedData, et as AddressInfo, eu as PaymentMethodInfo, ex as ElementsCheckoutResult } from './ads-DRfobDQ9.js';
|
|
2
|
+
export { eE as AdConfig } from './ads-DRfobDQ9.js';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
interface UserIdentity {
|