@cimplify/sdk 0.3.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -519,6 +519,15 @@ var AUTHORIZATION_TYPE = {
519
519
  BIRTHDAY: "birthday",
520
520
  ADDRESS: "address"
521
521
  };
522
+ var DEVICE_TYPE = {
523
+ MOBILE: "mobile",
524
+ DESKTOP: "desktop",
525
+ TABLET: "tablet"
526
+ };
527
+ var CONTACT_TYPE = {
528
+ PHONE: "phone",
529
+ EMAIL: "email"
530
+ };
522
531
  var LINK_QUERY = {
523
532
  DATA: "link.data",
524
533
  ADDRESSES: "link.addresses",
@@ -1056,6 +1065,9 @@ var InventoryService = class {
1056
1065
  };
1057
1066
 
1058
1067
  // src/scheduling.ts
1068
+ function toVariables(input) {
1069
+ return Object.fromEntries(Object.entries(input));
1070
+ }
1059
1071
  function toCimplifyError9(error) {
1060
1072
  if (error instanceof CimplifyError) return error;
1061
1073
  if (error instanceof Error) {
@@ -1088,17 +1100,14 @@ var SchedulingService = class {
1088
1100
  }
1089
1101
  async getAvailableSlots(input) {
1090
1102
  return safe9(
1091
- this.client.query(
1092
- "scheduling.slots",
1093
- input
1094
- )
1103
+ this.client.query("scheduling.slots", toVariables(input))
1095
1104
  );
1096
1105
  }
1097
1106
  async checkSlotAvailability(input) {
1098
1107
  return safe9(
1099
1108
  this.client.query(
1100
1109
  "scheduling.check_availability",
1101
- input
1110
+ toVariables(input)
1102
1111
  )
1103
1112
  );
1104
1113
  }
@@ -1106,7 +1115,7 @@ var SchedulingService = class {
1106
1115
  return safe9(
1107
1116
  this.client.query(
1108
1117
  "scheduling.availability",
1109
- params
1118
+ toVariables(params)
1110
1119
  )
1111
1120
  );
1112
1121
  }
@@ -1219,9 +1228,359 @@ var LiteService = class {
1219
1228
  }
1220
1229
  };
1221
1230
 
1231
+ // src/types/elements.ts
1232
+ var ELEMENT_TYPES = {
1233
+ AUTH: "auth",
1234
+ ADDRESS: "address",
1235
+ PAYMENT: "payment"
1236
+ };
1237
+ var MESSAGE_TYPES = {
1238
+ // Parent → Iframe
1239
+ INIT: "init",
1240
+ SET_TOKEN: "set_token",
1241
+ GET_DATA: "get_data",
1242
+ REFRESH_TOKEN: "refresh_token",
1243
+ LOGOUT: "logout",
1244
+ // Iframe → Parent
1245
+ READY: "ready",
1246
+ HEIGHT_CHANGE: "height_change",
1247
+ AUTHENTICATED: "authenticated",
1248
+ REQUIRES_OTP: "requires_otp",
1249
+ ERROR: "error",
1250
+ ADDRESS_CHANGED: "address_changed",
1251
+ ADDRESS_SELECTED: "address_selected",
1252
+ PAYMENT_METHOD_SELECTED: "payment_method_selected",
1253
+ TOKEN_REFRESHED: "token_refreshed",
1254
+ LOGOUT_COMPLETE: "logout_complete"
1255
+ };
1256
+ var EVENT_TYPES = {
1257
+ READY: "ready",
1258
+ AUTHENTICATED: "authenticated",
1259
+ REQUIRES_OTP: "requires_otp",
1260
+ ERROR: "error",
1261
+ CHANGE: "change",
1262
+ BLUR: "blur",
1263
+ FOCUS: "focus"
1264
+ };
1265
+
1266
+ // src/elements.ts
1267
+ function mapOrderType(orderType) {
1268
+ if (orderType === "dine_in") return "dine-in";
1269
+ return orderType ?? "delivery";
1270
+ }
1271
+ function toCheckoutFormData(data) {
1272
+ return {
1273
+ cart_id: data.cart_id,
1274
+ customer: {
1275
+ name: "",
1276
+ email: "",
1277
+ phone: "",
1278
+ save_details: false
1279
+ },
1280
+ order_type: mapOrderType(data.order_type),
1281
+ address_info: data.address ? {
1282
+ street_address: data.address.street_address,
1283
+ apartment: data.address.apartment,
1284
+ city: data.address.city,
1285
+ region: data.address.region,
1286
+ postal_code: data.address.postal_code,
1287
+ country: data.address.country,
1288
+ delivery_instructions: data.address.delivery_instructions,
1289
+ phone_for_delivery: data.address.phone_for_delivery
1290
+ } : {},
1291
+ payment_method: data.payment_method?.type ?? "mobile_money",
1292
+ mobile_money_details: data.payment_method?.type === "mobile_money" && data.payment_method.phone_number ? {
1293
+ phone_number: data.payment_method.phone_number,
1294
+ provider: data.payment_method.provider ?? "mtn"
1295
+ } : void 0,
1296
+ special_instructions: data.notes,
1297
+ link_address_id: data.address?.id,
1298
+ link_payment_method_id: data.payment_method?.id
1299
+ };
1300
+ }
1301
+ var DEFAULT_LINK_URL = "https://link.cimplify.io";
1302
+ function isAllowedOrigin(origin) {
1303
+ try {
1304
+ const url = new URL(origin);
1305
+ const hostname = url.hostname;
1306
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
1307
+ return true;
1308
+ }
1309
+ if (url.protocol !== "https:") {
1310
+ return false;
1311
+ }
1312
+ return hostname === "cimplify.io" || hostname.endsWith(".cimplify.io");
1313
+ } catch {
1314
+ return false;
1315
+ }
1316
+ }
1317
+ var CimplifyElements = class {
1318
+ constructor(client, businessId, options = {}) {
1319
+ this.elements = /* @__PURE__ */ new Map();
1320
+ this.accessToken = null;
1321
+ this.accountId = null;
1322
+ this.customerId = null;
1323
+ this.addressData = null;
1324
+ this.paymentData = null;
1325
+ this.client = client;
1326
+ this.businessId = businessId;
1327
+ this.linkUrl = options.linkUrl || DEFAULT_LINK_URL;
1328
+ this.options = options;
1329
+ this.boundHandleMessage = this.handleMessage.bind(this);
1330
+ if (typeof window !== "undefined") {
1331
+ window.addEventListener("message", this.boundHandleMessage);
1332
+ }
1333
+ }
1334
+ create(type, options = {}) {
1335
+ const existing = this.elements.get(type);
1336
+ if (existing) return existing;
1337
+ const element = new CimplifyElement(type, this.businessId, this.linkUrl, options, this);
1338
+ this.elements.set(type, element);
1339
+ return element;
1340
+ }
1341
+ getElement(type) {
1342
+ return this.elements.get(type);
1343
+ }
1344
+ destroy() {
1345
+ this.elements.forEach((element) => element.destroy());
1346
+ this.elements.clear();
1347
+ if (typeof window !== "undefined") {
1348
+ window.removeEventListener("message", this.boundHandleMessage);
1349
+ }
1350
+ }
1351
+ async submitCheckout(data) {
1352
+ const addressElement = this.elements.get(ELEMENT_TYPES.ADDRESS);
1353
+ if (addressElement) await addressElement.getData();
1354
+ const paymentElement = this.elements.get(ELEMENT_TYPES.PAYMENT);
1355
+ if (paymentElement) await paymentElement.getData();
1356
+ const internalData = {
1357
+ ...data,
1358
+ customer: this.accountId ? { account_id: this.accountId, customer_id: this.customerId } : void 0,
1359
+ address: this.addressData,
1360
+ payment_method: this.paymentData
1361
+ };
1362
+ const checkoutFormData = toCheckoutFormData(internalData);
1363
+ const result = await this.client.checkout.process(checkoutFormData);
1364
+ if (result.ok) {
1365
+ return {
1366
+ success: true,
1367
+ order: {
1368
+ id: result.value.order_id,
1369
+ status: result.value.payment_status,
1370
+ total: ""
1371
+ // Total is not returned by checkout result
1372
+ }
1373
+ };
1374
+ }
1375
+ return {
1376
+ success: false,
1377
+ error: {
1378
+ code: result.error.code || "CHECKOUT_FAILED",
1379
+ message: result.error.message || "Checkout failed"
1380
+ }
1381
+ };
1382
+ }
1383
+ isAuthenticated() {
1384
+ return this.accessToken !== null;
1385
+ }
1386
+ getAccessToken() {
1387
+ return this.accessToken;
1388
+ }
1389
+ handleMessage(event) {
1390
+ if (!isAllowedOrigin(event.origin)) {
1391
+ return;
1392
+ }
1393
+ const message = event.data;
1394
+ if (!message?.type) return;
1395
+ switch (message.type) {
1396
+ case MESSAGE_TYPES.AUTHENTICATED:
1397
+ this.accessToken = message.token;
1398
+ this.accountId = message.accountId;
1399
+ this.customerId = message.customerId;
1400
+ this.elements.forEach((element, type) => {
1401
+ if (type !== ELEMENT_TYPES.AUTH) {
1402
+ element.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token: message.token });
1403
+ }
1404
+ });
1405
+ break;
1406
+ case MESSAGE_TYPES.TOKEN_REFRESHED:
1407
+ this.accessToken = message.token;
1408
+ break;
1409
+ case MESSAGE_TYPES.ADDRESS_CHANGED:
1410
+ case MESSAGE_TYPES.ADDRESS_SELECTED:
1411
+ this.addressData = message.address;
1412
+ break;
1413
+ case MESSAGE_TYPES.PAYMENT_METHOD_SELECTED:
1414
+ this.paymentData = message.method;
1415
+ break;
1416
+ case MESSAGE_TYPES.LOGOUT_COMPLETE:
1417
+ this.accessToken = null;
1418
+ this.accountId = null;
1419
+ this.customerId = null;
1420
+ this.addressData = null;
1421
+ this.paymentData = null;
1422
+ break;
1423
+ }
1424
+ }
1425
+ _setAddressData(data) {
1426
+ this.addressData = data;
1427
+ }
1428
+ _setPaymentData(data) {
1429
+ this.paymentData = data;
1430
+ }
1431
+ };
1432
+ var CimplifyElement = class {
1433
+ constructor(type, businessId, linkUrl, options, parent) {
1434
+ this.iframe = null;
1435
+ this.container = null;
1436
+ this.mounted = false;
1437
+ this.eventHandlers = /* @__PURE__ */ new Map();
1438
+ this.resolvers = /* @__PURE__ */ new Map();
1439
+ this.type = type;
1440
+ this.businessId = businessId;
1441
+ this.linkUrl = linkUrl;
1442
+ this.options = options;
1443
+ this.parent = parent;
1444
+ this.boundHandleMessage = this.handleMessage.bind(this);
1445
+ if (typeof window !== "undefined") {
1446
+ window.addEventListener("message", this.boundHandleMessage);
1447
+ }
1448
+ }
1449
+ mount(container) {
1450
+ if (this.mounted) {
1451
+ console.warn(`Element ${this.type} is already mounted`);
1452
+ return;
1453
+ }
1454
+ const target = typeof container === "string" ? document.querySelector(container) : container;
1455
+ if (!target) {
1456
+ console.error(`Container not found: ${container}`);
1457
+ return;
1458
+ }
1459
+ this.container = target;
1460
+ this.createIframe();
1461
+ this.mounted = true;
1462
+ }
1463
+ destroy() {
1464
+ if (this.iframe) {
1465
+ this.iframe.remove();
1466
+ this.iframe = null;
1467
+ }
1468
+ this.container = null;
1469
+ this.mounted = false;
1470
+ this.eventHandlers.clear();
1471
+ if (typeof window !== "undefined") {
1472
+ window.removeEventListener("message", this.boundHandleMessage);
1473
+ }
1474
+ }
1475
+ on(event, handler) {
1476
+ if (!this.eventHandlers.has(event)) {
1477
+ this.eventHandlers.set(event, /* @__PURE__ */ new Set());
1478
+ }
1479
+ this.eventHandlers.get(event).add(handler);
1480
+ }
1481
+ off(event, handler) {
1482
+ this.eventHandlers.get(event)?.delete(handler);
1483
+ }
1484
+ async getData() {
1485
+ return new Promise((resolve) => {
1486
+ const id = Math.random().toString(36).slice(2);
1487
+ this.resolvers.set(id, resolve);
1488
+ this.sendMessage({ type: MESSAGE_TYPES.GET_DATA });
1489
+ setTimeout(() => {
1490
+ if (this.resolvers.has(id)) {
1491
+ this.resolvers.delete(id);
1492
+ resolve(null);
1493
+ }
1494
+ }, 5e3);
1495
+ });
1496
+ }
1497
+ sendMessage(message) {
1498
+ if (this.iframe?.contentWindow) {
1499
+ this.iframe.contentWindow.postMessage(message, this.linkUrl);
1500
+ }
1501
+ }
1502
+ createIframe() {
1503
+ if (!this.container) return;
1504
+ const iframe = document.createElement("iframe");
1505
+ const url = new URL(`${this.linkUrl}/elements/${this.type}`);
1506
+ url.searchParams.set("businessId", this.businessId);
1507
+ if (this.options.prefillEmail) url.searchParams.set("email", this.options.prefillEmail);
1508
+ if (this.options.mode) url.searchParams.set("mode", this.options.mode);
1509
+ iframe.src = url.toString();
1510
+ iframe.style.border = "none";
1511
+ iframe.style.width = "100%";
1512
+ iframe.style.display = "block";
1513
+ iframe.style.overflow = "hidden";
1514
+ iframe.setAttribute("allowtransparency", "true");
1515
+ iframe.setAttribute("frameborder", "0");
1516
+ iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-popups");
1517
+ this.iframe = iframe;
1518
+ this.container.appendChild(iframe);
1519
+ iframe.onload = () => {
1520
+ this.sendMessage({
1521
+ type: MESSAGE_TYPES.INIT,
1522
+ businessId: this.businessId,
1523
+ prefillEmail: this.options.prefillEmail
1524
+ });
1525
+ const token = this.parent.getAccessToken();
1526
+ if (token && this.type !== ELEMENT_TYPES.AUTH) {
1527
+ this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
1528
+ }
1529
+ };
1530
+ }
1531
+ handleMessage(event) {
1532
+ if (!isAllowedOrigin(event.origin)) {
1533
+ return;
1534
+ }
1535
+ const message = event.data;
1536
+ if (!message?.type) return;
1537
+ switch (message.type) {
1538
+ case MESSAGE_TYPES.READY:
1539
+ this.emit(EVENT_TYPES.READY, { height: message.height });
1540
+ break;
1541
+ case MESSAGE_TYPES.HEIGHT_CHANGE:
1542
+ if (this.iframe) this.iframe.style.height = `${message.height}px`;
1543
+ break;
1544
+ case MESSAGE_TYPES.AUTHENTICATED:
1545
+ this.emit(EVENT_TYPES.AUTHENTICATED, {
1546
+ accountId: message.accountId,
1547
+ customerId: message.customerId,
1548
+ token: message.token
1549
+ });
1550
+ break;
1551
+ case MESSAGE_TYPES.REQUIRES_OTP:
1552
+ this.emit(EVENT_TYPES.REQUIRES_OTP, { contactMasked: message.contactMasked });
1553
+ break;
1554
+ case MESSAGE_TYPES.ERROR:
1555
+ this.emit(EVENT_TYPES.ERROR, { code: message.code, message: message.message });
1556
+ break;
1557
+ case MESSAGE_TYPES.ADDRESS_CHANGED:
1558
+ case MESSAGE_TYPES.ADDRESS_SELECTED:
1559
+ this.parent._setAddressData(message.address);
1560
+ this.emit(EVENT_TYPES.CHANGE, { address: message.address });
1561
+ this.resolveData(message.address);
1562
+ break;
1563
+ case MESSAGE_TYPES.PAYMENT_METHOD_SELECTED:
1564
+ this.parent._setPaymentData(message.method);
1565
+ this.emit(EVENT_TYPES.CHANGE, { paymentMethod: message.method });
1566
+ this.resolveData(message.method);
1567
+ break;
1568
+ }
1569
+ }
1570
+ emit(event, data) {
1571
+ this.eventHandlers.get(event)?.forEach((handler) => handler(data));
1572
+ }
1573
+ resolveData(data) {
1574
+ this.resolvers.forEach((resolve) => resolve(data));
1575
+ this.resolvers.clear();
1576
+ }
1577
+ };
1578
+ function createElements(client, businessId, options) {
1579
+ return new CimplifyElements(client, businessId, options);
1580
+ }
1581
+
1222
1582
  // src/client.ts
1223
- var SESSION_TOKEN_HEADER = "x-session-token";
1224
- var SESSION_STORAGE_KEY = "cimplify_session_token";
1583
+ var ACCESS_TOKEN_STORAGE_KEY = "cimplify_access_token";
1225
1584
  var DEFAULT_TIMEOUT_MS = 3e4;
1226
1585
  var DEFAULT_MAX_RETRIES = 3;
1227
1586
  var DEFAULT_RETRY_DELAY_MS = 1e3;
@@ -1283,7 +1642,7 @@ function deriveUrls() {
1283
1642
  }
1284
1643
  var CimplifyClient = class {
1285
1644
  constructor(config = {}) {
1286
- this.sessionToken = null;
1645
+ this.accessToken = null;
1287
1646
  this.inflightRequests = /* @__PURE__ */ new Map();
1288
1647
  this.publicKey = config.publicKey || "";
1289
1648
  const urls = deriveUrls();
@@ -1294,15 +1653,23 @@ var CimplifyClient = class {
1294
1653
  this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
1295
1654
  this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
1296
1655
  this.hooks = config.hooks ?? {};
1297
- this.sessionToken = this.loadSessionToken();
1656
+ this.accessToken = this.loadAccessToken();
1298
1657
  }
1658
+ /** @deprecated Use getAccessToken() instead */
1299
1659
  getSessionToken() {
1300
- return this.sessionToken;
1660
+ return this.accessToken;
1301
1661
  }
1662
+ /** @deprecated Use setAccessToken() instead */
1302
1663
  setSessionToken(token) {
1303
- const previous = this.sessionToken;
1304
- this.sessionToken = token;
1305
- this.saveSessionToken(token);
1664
+ this.setAccessToken(token);
1665
+ }
1666
+ getAccessToken() {
1667
+ return this.accessToken;
1668
+ }
1669
+ setAccessToken(token) {
1670
+ const previous = this.accessToken;
1671
+ this.accessToken = token;
1672
+ this.saveAccessToken(token);
1306
1673
  this.hooks.onSessionChange?.({
1307
1674
  previousToken: previous,
1308
1675
  newToken: token,
@@ -1310,27 +1677,27 @@ var CimplifyClient = class {
1310
1677
  });
1311
1678
  }
1312
1679
  clearSession() {
1313
- const previous = this.sessionToken;
1314
- this.sessionToken = null;
1315
- this.saveSessionToken(null);
1680
+ const previous = this.accessToken;
1681
+ this.accessToken = null;
1682
+ this.saveAccessToken(null);
1316
1683
  this.hooks.onSessionChange?.({
1317
1684
  previousToken: previous,
1318
1685
  newToken: null,
1319
1686
  source: "clear"
1320
1687
  });
1321
1688
  }
1322
- loadSessionToken() {
1689
+ loadAccessToken() {
1323
1690
  if (typeof window !== "undefined" && window.localStorage) {
1324
- return localStorage.getItem(SESSION_STORAGE_KEY);
1691
+ return localStorage.getItem(ACCESS_TOKEN_STORAGE_KEY);
1325
1692
  }
1326
1693
  return null;
1327
1694
  }
1328
- saveSessionToken(token) {
1695
+ saveAccessToken(token) {
1329
1696
  if (typeof window !== "undefined" && window.localStorage) {
1330
1697
  if (token) {
1331
- localStorage.setItem(SESSION_STORAGE_KEY, token);
1698
+ localStorage.setItem(ACCESS_TOKEN_STORAGE_KEY, token);
1332
1699
  } else {
1333
- localStorage.removeItem(SESSION_STORAGE_KEY);
1700
+ localStorage.removeItem(ACCESS_TOKEN_STORAGE_KEY);
1334
1701
  }
1335
1702
  }
1336
1703
  }
@@ -1339,24 +1706,11 @@ var CimplifyClient = class {
1339
1706
  "Content-Type": "application/json",
1340
1707
  "X-API-Key": this.publicKey
1341
1708
  };
1342
- if (this.sessionToken) {
1343
- headers[SESSION_TOKEN_HEADER] = this.sessionToken;
1709
+ if (this.accessToken) {
1710
+ headers["Authorization"] = `Bearer ${this.accessToken}`;
1344
1711
  }
1345
1712
  return headers;
1346
1713
  }
1347
- updateSessionFromResponse(response) {
1348
- const newToken = response.headers.get(SESSION_TOKEN_HEADER);
1349
- if (newToken && newToken !== this.sessionToken) {
1350
- const previous = this.sessionToken;
1351
- this.sessionToken = newToken;
1352
- this.saveSessionToken(newToken);
1353
- this.hooks.onSessionChange?.({
1354
- previousToken: previous,
1355
- newToken,
1356
- source: "response"
1357
- });
1358
- }
1359
- }
1360
1714
  async resilientFetch(url, options) {
1361
1715
  const method = options.method || "GET";
1362
1716
  const path = url.replace(this.baseUrl, "").replace(this.linkApiUrl, "");
@@ -1468,7 +1822,6 @@ var CimplifyClient = class {
1468
1822
  headers: this.getHeaders(),
1469
1823
  body: JSON.stringify(body)
1470
1824
  });
1471
- this.updateSessionFromResponse(response);
1472
1825
  return this.handleResponse(response);
1473
1826
  });
1474
1827
  }
@@ -1483,7 +1836,6 @@ var CimplifyClient = class {
1483
1836
  headers: this.getHeaders(),
1484
1837
  body: JSON.stringify(body)
1485
1838
  });
1486
- this.updateSessionFromResponse(response);
1487
1839
  return this.handleResponse(response);
1488
1840
  }
1489
1841
  async get(path) {
@@ -1494,7 +1846,6 @@ var CimplifyClient = class {
1494
1846
  credentials: this.credentials,
1495
1847
  headers: this.getHeaders()
1496
1848
  });
1497
- this.updateSessionFromResponse(response);
1498
1849
  return this.handleRestResponse(response);
1499
1850
  });
1500
1851
  }
@@ -1505,7 +1856,6 @@ var CimplifyClient = class {
1505
1856
  headers: this.getHeaders(),
1506
1857
  body: body ? JSON.stringify(body) : void 0
1507
1858
  });
1508
- this.updateSessionFromResponse(response);
1509
1859
  return this.handleRestResponse(response);
1510
1860
  }
1511
1861
  async delete(path) {
@@ -1514,7 +1864,6 @@ var CimplifyClient = class {
1514
1864
  credentials: this.credentials,
1515
1865
  headers: this.getHeaders()
1516
1866
  });
1517
- this.updateSessionFromResponse(response);
1518
1867
  return this.handleRestResponse(response);
1519
1868
  }
1520
1869
  async linkGet(path) {
@@ -1525,7 +1874,6 @@ var CimplifyClient = class {
1525
1874
  credentials: this.credentials,
1526
1875
  headers: this.getHeaders()
1527
1876
  });
1528
- this.updateSessionFromResponse(response);
1529
1877
  return this.handleRestResponse(response);
1530
1878
  });
1531
1879
  }
@@ -1536,7 +1884,6 @@ var CimplifyClient = class {
1536
1884
  headers: this.getHeaders(),
1537
1885
  body: body ? JSON.stringify(body) : void 0
1538
1886
  });
1539
- this.updateSessionFromResponse(response);
1540
1887
  return this.handleRestResponse(response);
1541
1888
  }
1542
1889
  async linkDelete(path) {
@@ -1545,7 +1892,6 @@ var CimplifyClient = class {
1545
1892
  credentials: this.credentials,
1546
1893
  headers: this.getHeaders()
1547
1894
  });
1548
- this.updateSessionFromResponse(response);
1549
1895
  return this.handleRestResponse(response);
1550
1896
  }
1551
1897
  async handleRestResponse(response) {
@@ -1630,6 +1976,23 @@ var CimplifyClient = class {
1630
1976
  }
1631
1977
  return this._lite;
1632
1978
  }
1979
+ /**
1980
+ * Create a CimplifyElements instance for embedding checkout components.
1981
+ * Like Stripe's stripe.elements().
1982
+ *
1983
+ * @param businessId - The business ID for checkout context
1984
+ * @param options - Optional configuration for elements
1985
+ *
1986
+ * @example
1987
+ * ```ts
1988
+ * const elements = client.elements('bus_xxx');
1989
+ * const authElement = elements.create('auth');
1990
+ * authElement.mount('#auth-container');
1991
+ * ```
1992
+ */
1993
+ elements(businessId, options) {
1994
+ return createElements(this, businessId, options);
1995
+ }
1633
1996
  };
1634
1997
  function createCimplifyClient(config) {
1635
1998
  return new CimplifyClient(config);
@@ -2186,4 +2549,4 @@ function detectMobileMoneyProvider(phoneNumber) {
2186
2549
  return null;
2187
2550
  }
2188
2551
 
2189
- export { AUTHORIZATION_TYPE, AUTH_MUTATION, AuthService, BusinessService, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyClient, CimplifyError, DEFAULT_COUNTRY, DEFAULT_CURRENCY, ErrorCode, InventoryService, LINK_MUTATION, LINK_QUERY, LinkService, LiteService, 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, detectMobileMoneyProvider, err, extractPriceInfo, 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, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
2552
+ 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, extractPriceInfo, 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, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };