@cimplify/sdk 0.89.0 → 0.92.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.
Files changed (69) hide show
  1. package/dist/advanced.d.mts +3 -3
  2. package/dist/advanced.d.ts +3 -3
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-JHJTXAPS.js → chunk-3MBMIEWT.js} +4 -4
  6. package/dist/{chunk-DENWOZEA.mjs → chunk-3XD2FVP4.mjs} +163 -43
  7. package/dist/{chunk-M4ALCELT.mjs → chunk-54H2YYIW.mjs} +2 -2
  8. package/dist/{chunk-T2CJ67QV.js → chunk-DCRN67NO.js} +201 -78
  9. package/dist/{chunk-T7Z25EY4.js → chunk-HKN3YG76.js} +84 -0
  10. package/dist/{chunk-GHFDYM5K.js → chunk-IVJEUGWF.js} +10 -1
  11. package/dist/{chunk-ROBTTS3Q.js → chunk-OAHSF542.js} +40 -1
  12. package/dist/{chunk-APBLFZ2I.mjs → chunk-PYBFTMHI.mjs} +40 -1
  13. package/dist/{chunk-OZDDHSIB.mjs → chunk-RRBY35TJ.mjs} +80 -1
  14. package/dist/{chunk-ZU4ZRYUR.mjs → chunk-T7LDBZZZ.mjs} +10 -1
  15. package/dist/chunk-U4MW6PYU.mjs +23 -0
  16. package/dist/chunk-XREIZ56K.js +26 -0
  17. package/dist/{client-CqZgdUtw.d.ts → client-BQbSKlHS.d.mts} +165 -11
  18. package/dist/{client-CAY2NbRG.d.mts → client-Bw4HtLP1.d.mts} +2 -2
  19. package/dist/{client-D8ZFs-sq.d.mts → client-CeW3acve.d.ts} +165 -11
  20. package/dist/{client-CUbwb6Om.d.ts → client-Otzv_rgP.d.ts} +2 -2
  21. package/dist/{index-CmWOz9bi.d.mts → index-CmIboQjl.d.mts} +3 -3
  22. package/dist/{index-Bc5qUxAt.d.ts → index-DgoRwz8l.d.ts} +3 -3
  23. package/dist/index.d.mts +49 -7
  24. package/dist/index.d.ts +49 -7
  25. package/dist/index.js +109 -82
  26. package/dist/index.mjs +11 -5
  27. package/dist/mock/cli.mjs +61 -1
  28. package/dist/mock/library.js +61 -1
  29. package/dist/mock/library.mjs +61 -1
  30. package/dist/mock/msw.js +61 -1
  31. package/dist/mock/msw.mjs +61 -1
  32. package/dist/{payment-Dcgb9n1n.d.mts → payment-BFtLqiG2.d.mts} +1 -1
  33. package/dist/{payment-Xq0WDZXh.d.ts → payment-Cq8FT1B6.d.ts} +1 -1
  34. package/dist/{price-DAAjKgAp.d.ts → price-DaFXT-Lr.d.ts} +1 -1
  35. package/dist/{price--Ma_WO5_.d.mts → price-DleDWk_s.d.mts} +1 -1
  36. package/dist/{product-BakHcsP2.d.ts → product-bZ8G5Z8D.d.mts} +95 -2
  37. package/dist/{product-BakHcsP2.d.mts → product-bZ8G5Z8D.d.ts} +95 -2
  38. package/dist/react.d.mts +471 -8
  39. package/dist/react.d.ts +471 -8
  40. package/dist/react.js +2787 -402
  41. package/dist/react.mjs +2699 -337
  42. package/dist/{server-Bk_hlefX.d.mts → server-D-iK-bNt.d.mts} +8 -1
  43. package/dist/{server-Bei5lBrc.d.ts → server-DwsY9hlX.d.ts} +8 -1
  44. package/dist/server.d.mts +4 -4
  45. package/dist/server.d.ts +4 -4
  46. package/dist/server.js +7 -7
  47. package/dist/server.mjs +2 -2
  48. package/dist/styles.css +1 -1
  49. package/dist/testing/msw.d.mts +2 -2
  50. package/dist/testing/msw.d.ts +2 -2
  51. package/dist/testing/msw.js +3 -2
  52. package/dist/testing/msw.mjs +2 -1
  53. package/dist/testing/suite.d.mts +6 -6
  54. package/dist/testing/suite.d.ts +6 -6
  55. package/dist/testing/suite.js +24 -23
  56. package/dist/testing/suite.mjs +5 -4
  57. package/dist/testing.d.mts +5 -5
  58. package/dist/testing.d.ts +5 -5
  59. package/dist/testing.js +80 -79
  60. package/dist/testing.mjs +6 -5
  61. package/dist/utils.d.mts +4 -4
  62. package/dist/utils.d.ts +4 -4
  63. package/package.json +4 -1
  64. package/registry/booking-page.json +1 -1
  65. package/registry/chat-widget.json +1 -1
  66. package/registry/customer-input-fields.json +1 -1
  67. package/registry/date-slot-picker.json +1 -1
  68. package/registry/product-customizer.json +1 -1
  69. package/registry/rental-service-card.json +1 -1
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var chunkXREIZ56K_js = require('./chunk-XREIZ56K.js');
3
4
  var chunkAETVRBKI_js = require('./chunk-AETVRBKI.js');
4
5
  var chunkOWW5GUSB_js = require('./chunk-OWW5GUSB.js');
5
6
 
@@ -2485,13 +2486,30 @@ function buildV1(deps) {
2485
2486
  const body = await c.req.json().catch(() => ({}));
2486
2487
  return tryRoute(
2487
2488
  c,
2488
- () => deps.support.sendMessage(body.conversation_id ?? "", { content: body.content ?? "", content_type: body.content_type, sender_type: body.sender_type })
2489
+ () => deps.support.sendMessage(body.conversation_id ?? "", { content: body.content ?? "", content_type: body.content_type, sender_type: body.sender_type, reply_to_message_id: body.reply_to_message_id })
2489
2490
  );
2490
2491
  });
2491
2492
  app.get(
2492
2493
  "/support/conversation/messages",
2493
2494
  (c) => tryRoute(c, () => deps.support.listMessages(c.req.query("conversation_id") ?? "", { limit: getQueryNum(c, "limit") }))
2494
2495
  );
2496
+ app.post("/support/conversation/messages/:messageId/reactions", async (c) => {
2497
+ const body = await c.req.json().catch(() => ({}));
2498
+ return tryRoute(c, () => deps.support.react(c.req.param("messageId"), body.emoji ?? ""));
2499
+ });
2500
+ app.post("/support/conversation/handoff", (c) => c.json({ data: { requested: true } }));
2501
+ app.post("/support/conversation/claim", async (c) => {
2502
+ const body = await c.req.json().catch(() => ({}));
2503
+ if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
2504
+ const session = c.var.session;
2505
+ return c.json({
2506
+ data: {
2507
+ session_token: session.token,
2508
+ thread_id: null,
2509
+ customer_name: session.customer_name ?? "Test User"
2510
+ }
2511
+ });
2512
+ });
2495
2513
  app.get(
2496
2514
  "/support/conversation/ws",
2497
2515
  (c) => c.json({ note: "WebSocket connection \u2014 connect via ws:// at the same path", supported: false }, 426)
@@ -5465,12 +5483,14 @@ function createSupportService(opts) {
5465
5483
  sendMessage(conversationId, body) {
5466
5484
  const conv = registry.conversations.get(conversationId);
5467
5485
  if (!conv) throw notFound(`Conversation ${conversationId} not found`);
5486
+ const target = body.reply_to_message_id ? conv.messages.find((m) => m.id === body.reply_to_message_id) : void 0;
5468
5487
  const msg = {
5469
5488
  id: ids.message(),
5470
5489
  conversation_id: conversationId,
5471
5490
  sender_type: body.sender_type ?? "customer",
5472
5491
  content_type: body.content_type ?? "text",
5473
5492
  content: body.content,
5493
+ reply_to: target ? { id: target.id, sender_type: target.sender_type, preview: chunkXREIZ56K_js.messagePreview(target.content) } : void 0,
5474
5494
  created_at: clock.iso()
5475
5495
  };
5476
5496
  conv.messages.push(msg);
@@ -5492,6 +5512,25 @@ function createSupportService(opts) {
5492
5512
  }
5493
5513
  return msg;
5494
5514
  },
5515
+ react(messageId, emoji) {
5516
+ for (const conv of registry.conversations.values()) {
5517
+ const target = conv.messages.find((m) => m.id === messageId);
5518
+ if (!target) continue;
5519
+ const reaction = {
5520
+ id: ids.message(),
5521
+ conversation_id: conv.id,
5522
+ sender_type: "customer",
5523
+ content_type: "text",
5524
+ content: emoji,
5525
+ reply_to: { id: target.id, sender_type: target.sender_type, preview: chunkXREIZ56K_js.messagePreview(target.content) },
5526
+ created_at: clock.iso()
5527
+ };
5528
+ conv.messages.push(reaction);
5529
+ registry.conversations.put(conv.id, conv);
5530
+ return reaction;
5531
+ }
5532
+ throw notFound(`Message ${messageId} not found`);
5533
+ },
5495
5534
  listMessages(conversationId, opts2) {
5496
5535
  const conv = registry.conversations.get(conversationId);
5497
5536
  if (!conv) throw notFound(`Conversation ${conversationId} not found`);
@@ -1,3 +1,4 @@
1
+ import { messagePreview } from './chunk-U4MW6PYU.mjs';
1
2
  import { ErrorCode } from './chunk-K5EN2W2Q.mjs';
2
3
  import { __publicField, __privateAdd, __privateSet, __privateGet, __privateMethod, __privateWrapper } from './chunk-3G6RQLXK.mjs';
3
4
 
@@ -2483,13 +2484,30 @@ function buildV1(deps) {
2483
2484
  const body = await c.req.json().catch(() => ({}));
2484
2485
  return tryRoute(
2485
2486
  c,
2486
- () => deps.support.sendMessage(body.conversation_id ?? "", { content: body.content ?? "", content_type: body.content_type, sender_type: body.sender_type })
2487
+ () => deps.support.sendMessage(body.conversation_id ?? "", { content: body.content ?? "", content_type: body.content_type, sender_type: body.sender_type, reply_to_message_id: body.reply_to_message_id })
2487
2488
  );
2488
2489
  });
2489
2490
  app.get(
2490
2491
  "/support/conversation/messages",
2491
2492
  (c) => tryRoute(c, () => deps.support.listMessages(c.req.query("conversation_id") ?? "", { limit: getQueryNum(c, "limit") }))
2492
2493
  );
2494
+ app.post("/support/conversation/messages/:messageId/reactions", async (c) => {
2495
+ const body = await c.req.json().catch(() => ({}));
2496
+ return tryRoute(c, () => deps.support.react(c.req.param("messageId"), body.emoji ?? ""));
2497
+ });
2498
+ app.post("/support/conversation/handoff", (c) => c.json({ data: { requested: true } }));
2499
+ app.post("/support/conversation/claim", async (c) => {
2500
+ const body = await c.req.json().catch(() => ({}));
2501
+ if (!body.access_token) return c.json({ error: "access_token is required" }, 400);
2502
+ const session = c.var.session;
2503
+ return c.json({
2504
+ data: {
2505
+ session_token: session.token,
2506
+ thread_id: null,
2507
+ customer_name: session.customer_name ?? "Test User"
2508
+ }
2509
+ });
2510
+ });
2493
2511
  app.get(
2494
2512
  "/support/conversation/ws",
2495
2513
  (c) => c.json({ note: "WebSocket connection \u2014 connect via ws:// at the same path", supported: false }, 426)
@@ -5463,12 +5481,14 @@ function createSupportService(opts) {
5463
5481
  sendMessage(conversationId, body) {
5464
5482
  const conv = registry.conversations.get(conversationId);
5465
5483
  if (!conv) throw notFound(`Conversation ${conversationId} not found`);
5484
+ const target = body.reply_to_message_id ? conv.messages.find((m) => m.id === body.reply_to_message_id) : void 0;
5466
5485
  const msg = {
5467
5486
  id: ids.message(),
5468
5487
  conversation_id: conversationId,
5469
5488
  sender_type: body.sender_type ?? "customer",
5470
5489
  content_type: body.content_type ?? "text",
5471
5490
  content: body.content,
5491
+ reply_to: target ? { id: target.id, sender_type: target.sender_type, preview: messagePreview(target.content) } : void 0,
5472
5492
  created_at: clock.iso()
5473
5493
  };
5474
5494
  conv.messages.push(msg);
@@ -5490,6 +5510,25 @@ function createSupportService(opts) {
5490
5510
  }
5491
5511
  return msg;
5492
5512
  },
5513
+ react(messageId, emoji) {
5514
+ for (const conv of registry.conversations.values()) {
5515
+ const target = conv.messages.find((m) => m.id === messageId);
5516
+ if (!target) continue;
5517
+ const reaction = {
5518
+ id: ids.message(),
5519
+ conversation_id: conv.id,
5520
+ sender_type: "customer",
5521
+ content_type: "text",
5522
+ content: emoji,
5523
+ reply_to: { id: target.id, sender_type: target.sender_type, preview: messagePreview(target.content) },
5524
+ created_at: clock.iso()
5525
+ };
5526
+ conv.messages.push(reaction);
5527
+ registry.conversations.put(conv.id, conv);
5528
+ return reaction;
5529
+ }
5530
+ throw notFound(`Message ${messageId} not found`);
5531
+ },
5493
5532
  listMessages(conversationId, opts2) {
5494
5533
  const conv = registry.conversations.get(conversationId);
5495
5534
  if (!conv) throw notFound(`Conversation ${conversationId} not found`);
@@ -72,6 +72,85 @@ function getVariantDisplayName(variant, productName) {
72
72
  return productName || (variant.is_default ? "Default" : "Option");
73
73
  }
74
74
 
75
+ // src/utils/price-basis.ts
76
+ var MULTI_DAY_UNITS = /* @__PURE__ */ new Set([
77
+ "days",
78
+ "nights",
79
+ "weeks",
80
+ "months",
81
+ "years"
82
+ ]);
83
+ var PERIOD_LABELS = {
84
+ minutes: "session",
85
+ hours: "session",
86
+ days: "day",
87
+ nights: "night",
88
+ weeks: "week",
89
+ months: "month",
90
+ years: "year"
91
+ };
92
+ function isMultiDayService(product) {
93
+ if ((product.type || "product") !== "service") return false;
94
+ if (product.scheduling_mode) return product.scheduling_mode === "multi_day";
95
+ return product.duration_unit != null && MULTI_DAY_UNITS.has(product.duration_unit);
96
+ }
97
+ function priceBasisLabel(product) {
98
+ if ((product.type || "product") !== "service") return null;
99
+ const basis = product.price_basis ?? (isMultiDayService(product) ? "per_duration_unit" : null);
100
+ if (basis === null || basis === "flat") return null;
101
+ if (basis === "per_person") return "person";
102
+ return PERIOD_LABELS[product.duration_unit ?? "nights"];
103
+ }
104
+ var DAY_MS = 864e5;
105
+ function utcDateParts(iso) {
106
+ const date = new Date(iso);
107
+ if (Number.isNaN(date.getTime())) return null;
108
+ return { year: date.getUTCFullYear(), month: date.getUTCMonth() + 1, day: date.getUTCDate() };
109
+ }
110
+ function stayPeriods(scheduledStart, scheduledEnd, durationUnit) {
111
+ const start = utcDateParts(scheduledStart);
112
+ const end = utcDateParts(scheduledEnd);
113
+ if (!start || !end) return 1;
114
+ const days = Math.max(
115
+ 1,
116
+ Math.round(
117
+ (Date.UTC(end.year, end.month - 1, end.day) - Date.UTC(start.year, start.month - 1, start.day)) / DAY_MS
118
+ )
119
+ );
120
+ switch (durationUnit) {
121
+ case "weeks":
122
+ return Math.max(1, Math.ceil(days / 7));
123
+ case "months": {
124
+ let months = (end.year - start.year) * 12 + (end.month - start.month);
125
+ if (end.day > start.day) months += 1;
126
+ return Math.max(1, months);
127
+ }
128
+ case "years": {
129
+ let years = end.year - start.year;
130
+ if (end.month > start.month || end.month === start.month && end.day > start.day) {
131
+ years += 1;
132
+ }
133
+ return Math.max(1, years);
134
+ }
135
+ default:
136
+ return days;
137
+ }
138
+ }
139
+ function stayLength(scheduledStart, scheduledEnd, durationUnit) {
140
+ const periods = stayPeriods(scheduledStart, scheduledEnd, durationUnit);
141
+ const label = PERIOD_LABELS[durationUnit ?? "nights"];
142
+ return `${periods} ${label}${periods === 1 ? "" : "s"}`;
143
+ }
144
+ function serviceBillingMultiplier(product, selection) {
145
+ if ((product.type || "product") !== "service") return null;
146
+ const basis = product.price_basis ?? (isMultiDayService(product) ? "per_duration_unit" : "per_person");
147
+ const units = Math.max(1, selection.units ?? 1);
148
+ if (basis === "flat") return units;
149
+ if (basis === "per_person") return Math.max(1, selection.quantity) * units;
150
+ const periods = selection.scheduledStart && selection.scheduledEnd ? stayPeriods(selection.scheduledStart, selection.scheduledEnd, product.duration_unit) : 1;
151
+ return periods * units;
152
+ }
153
+
75
154
  // src/types/product.ts
76
155
  var PRODUCT_TYPE = {
77
156
  Product: "product",
@@ -161,4 +240,4 @@ function appendTransform(url, t) {
161
240
  return `${url}${url.includes("?") ? "&" : "?"}${query}`;
162
241
  }
163
242
 
164
- export { BOUNDARY_KIND, CIMPLIFY_CDN_HOSTS, DEFAULT_CDN_BASE_URL, DURATION_UNIT, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT, allGalleryImages, assetUrl, getVariantDisplayName, isCimplifyAsset, resolveGallery };
243
+ export { BOUNDARY_KIND, CIMPLIFY_CDN_HOSTS, DEFAULT_CDN_BASE_URL, DURATION_UNIT, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT, allGalleryImages, assetUrl, getVariantDisplayName, isCimplifyAsset, isMultiDayService, priceBasisLabel, resolveGallery, serviceBillingMultiplier, stayLength, stayPeriods };
@@ -1671,7 +1671,10 @@ var CheckoutService = class {
1671
1671
  idempotency_key: data.idempotency_key || generateIdempotencyKey(),
1672
1672
  metadata: data.metadata,
1673
1673
  pay_currency: data.pay_currency,
1674
- fx_quote_id: data.fx_quote_id
1674
+ fx_quote_id: data.fx_quote_id,
1675
+ use_store_credit: data.use_store_credit,
1676
+ voucher_code: data.voucher_code,
1677
+ pay_deposit: data.pay_deposit
1675
1678
  };
1676
1679
  const baseCurrency = currencyCode(
1677
1680
  (cart.pricing.currency || checkoutData.pay_currency || "GHS").toUpperCase()
@@ -1802,6 +1805,7 @@ var LinkService = class {
1802
1805
  );
1803
1806
  if (result.ok && result.value.session_token) {
1804
1807
  this.client.setAccessToken(result.value.session_token);
1808
+ this.client.autoClaimChatIdentity();
1805
1809
  }
1806
1810
  return result;
1807
1811
  }
@@ -1813,6 +1817,7 @@ var LinkService = class {
1813
1817
  );
1814
1818
  if (result.ok && result.value.session_token) {
1815
1819
  this.client.setAccessToken(result.value.session_token);
1820
+ this.client.autoClaimChatIdentity();
1816
1821
  }
1817
1822
  return result;
1818
1823
  }
@@ -1998,6 +2003,7 @@ var AuthService = class {
1998
2003
  );
1999
2004
  if (result.ok && result.value.session_token) {
2000
2005
  this.client.setAccessToken(result.value.session_token);
2006
+ this.client.autoClaimChatIdentity();
2001
2007
  }
2002
2008
  return result;
2003
2009
  }
@@ -2151,6 +2157,7 @@ var SchedulingService = class {
2151
2157
  service_id: input.service_id,
2152
2158
  date: input.date,
2153
2159
  participant_count: input.participant_count,
2160
+ units: input.units,
2154
2161
  variant_id: input.variant_id
2155
2162
  });
2156
2163
  return safe(this.client.get(path));
@@ -2171,6 +2178,7 @@ var SchedulingService = class {
2171
2178
  end_date: params.end_date,
2172
2179
  location_id: params.location_id,
2173
2180
  participant_count: params.participant_count,
2181
+ units: params.units,
2174
2182
  variant_id: params.variant_id
2175
2183
  });
2176
2184
  return safe(this.client.get(path));
@@ -3143,6 +3151,7 @@ var CimplifyElements = class {
3143
3151
  this.accessToken = token;
3144
3152
  this.accountId = decodeJwtSub(token);
3145
3153
  this.client.setAccessToken(token);
3154
+ this.client.autoClaimChatIdentity();
3146
3155
  await this.hydrateCustomerData();
3147
3156
  return {
3148
3157
  accountId: this.accountId ?? "",
@@ -0,0 +1,23 @@
1
+ // src/genui/segments.ts
2
+ var FENCE_PATTERN = /```genui\s*\n([\s\S]*?)(?:```|$)/g;
3
+ function splitGenUIContent(content) {
4
+ const segments = [];
5
+ let cursor = 0;
6
+ for (const match of content.matchAll(FENCE_PATTERN)) {
7
+ const prose = content.slice(cursor, match.index).trim();
8
+ if (prose) segments.push({ kind: "prose", text: prose });
9
+ const source = match[1].trim();
10
+ if (source) segments.push({ kind: "program", source });
11
+ cursor = match.index + match[0].length;
12
+ }
13
+ const tail = content.slice(cursor).trim();
14
+ if (tail) segments.push({ kind: "prose", text: tail });
15
+ return segments;
16
+ }
17
+ function messagePreview(content, max = 90) {
18
+ const prose = splitGenUIContent(content).filter((segment) => segment.kind === "prose").map((segment) => segment.text).join(" ").replace(/\s+/g, " ").trim();
19
+ if (!prose) return "Structured answer";
20
+ return prose.length > max ? `${prose.slice(0, max)}\u2026` : prose;
21
+ }
22
+
23
+ export { messagePreview, splitGenUIContent };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // src/genui/segments.ts
4
+ var FENCE_PATTERN = /```genui\s*\n([\s\S]*?)(?:```|$)/g;
5
+ function splitGenUIContent(content) {
6
+ const segments = [];
7
+ let cursor = 0;
8
+ for (const match of content.matchAll(FENCE_PATTERN)) {
9
+ const prose = content.slice(cursor, match.index).trim();
10
+ if (prose) segments.push({ kind: "prose", text: prose });
11
+ const source = match[1].trim();
12
+ if (source) segments.push({ kind: "program", source });
13
+ cursor = match.index + match[0].length;
14
+ }
15
+ const tail = content.slice(cursor).trim();
16
+ if (tail) segments.push({ kind: "prose", text: tail });
17
+ return segments;
18
+ }
19
+ function messagePreview(content, max = 90) {
20
+ const prose = splitGenUIContent(content).filter((segment) => segment.kind === "prose").map((segment) => segment.text).join(" ").replace(/\s+/g, " ").trim();
21
+ if (!prose) return "Structured answer";
22
+ return prose.length > max ? `${prose.slice(0, max)}\u2026` : prose;
23
+ }
24
+
25
+ exports.messagePreview = messagePreview;
26
+ exports.splitGenUIContent = splitGenUIContent;