@takeshape/purchase-order-chat 1.61.0 → 1.62.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/tailwind.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { d as f, P as b, S as T, c as M, a as P, b as x, i as w, s as O } from "./purchase-order-chat-wrapper-fadhXbv8.js";
2
+ import { d as k, P as v, S as T, c as M, a as O, b as L, i as x, s as P } from "./purchase-order-chat-wrapper-DAVIPBya.js";
3
3
  class I {
4
4
  carts = /* @__PURE__ */ new Map();
5
5
  checkouts = /* @__PURE__ */ new Map();
@@ -76,7 +76,7 @@ class I {
76
76
  */
77
77
  calculateCartTotals(t) {
78
78
  const e = t.reduce(
79
- (s, r) => s + r.extendedSalePrice.value,
79
+ (s, i) => s + i.extendedSalePrice.value,
80
80
  0
81
81
  );
82
82
  return {
@@ -89,12 +89,12 @@ class I {
89
89
  * Helper: Calculate checkout totals
90
90
  */
91
91
  calculateCheckoutTotals(t) {
92
- const e = this.checkoutToCartId.get(t.entityId), r = (e ? this.carts.get(e) : void 0)?.amount.value ?? 0;
93
- let o = 0, n = 0;
94
- t.shippingConsignments && t.shippingConsignments.length > 0 && (o = r * 0.08);
95
- for (const i of t.shippingConsignments ?? [])
96
- i.selectedShippingOption && (n += i.selectedShippingOption.cost.value);
97
- t.subtotal = this.createMoney(r), t.taxTotal = this.createMoney(o), t.shippingCostTotal = this.createMoney(n), t.handlingCostTotal = this.createMoney(0), t.grandTotal = this.createMoney(r + o + n);
92
+ const e = this.checkoutToCartId.get(t.entityId), i = (e ? this.carts.get(e) : void 0)?.amount.value ?? 0;
93
+ let r = 0, a = 0;
94
+ t.shippingConsignments && t.shippingConsignments.length > 0 && (r = i * 0.08);
95
+ for (const n of t.shippingConsignments ?? [])
96
+ n.selectedShippingOption && (a += n.selectedShippingOption.cost.value);
97
+ t.subtotal = this.createMoney(i), t.taxTotal = this.createMoney(r), t.shippingCostTotal = this.createMoney(a), t.handlingCostTotal = this.createMoney(0), t.grandTotal = this.createMoney(i + r + a);
98
98
  }
99
99
  /**
100
100
  * Get an existing cart by ID
@@ -109,33 +109,33 @@ class I {
109
109
  async createCart(t) {
110
110
  if (t.length === 0)
111
111
  throw new Error("Cannot create cart with no line items");
112
- const e = this.generateCartId(), s = this.generateCheckoutId(), r = { utc: (/* @__PURE__ */ new Date()).toISOString() }, o = t.map(
113
- (c) => this.createCartLineItem(c)
114
- ), n = this.calculateCartTotals(o), i = {
112
+ const e = this.generateCartId(), s = this.generateCheckoutId(), i = { utc: (/* @__PURE__ */ new Date()).toISOString() }, r = t.map(
113
+ (l) => this.createCartLineItem(l)
114
+ ), a = this.calculateCartTotals(r), n = {
115
115
  id: e,
116
116
  entityId: e,
117
117
  lineItems: {
118
- physicalItems: o,
118
+ physicalItems: r,
119
119
  digitalItems: []
120
120
  },
121
- amount: n.amount,
122
- baseAmount: n.baseAmount,
123
- discountedAmount: n.discountedAmount,
124
- createdAt: r,
125
- updatedAt: r
121
+ amount: a.amount,
122
+ baseAmount: a.baseAmount,
123
+ discountedAmount: a.discountedAmount,
124
+ createdAt: i,
125
+ updatedAt: i
126
126
  };
127
- this.carts.set(e, i);
128
- const a = {
127
+ this.carts.set(e, n);
128
+ const o = {
129
129
  entityId: s,
130
- subtotal: i.amount,
130
+ subtotal: n.amount,
131
131
  taxTotal: this.createMoney(0),
132
- grandTotal: i.amount,
132
+ grandTotal: n.amount,
133
133
  shippingCostTotal: this.createMoney(0),
134
134
  handlingCostTotal: this.createMoney(0),
135
135
  billingAddress: null,
136
136
  shippingConsignments: null
137
137
  };
138
- return this.checkouts.set(s, a), this.checkoutToCartId.set(s, e), { cart: i, errors: [] };
138
+ return this.checkouts.set(s, o), this.checkoutToCartId.set(s, e), { cart: n, errors: [] };
139
139
  }
140
140
  /**
141
141
  * Add line items to an existing cart
@@ -147,73 +147,73 @@ class I {
147
147
  return { cart: null, errors: [] };
148
148
  if (e.length === 0)
149
149
  return { cart: s, errors: [] };
150
- const r = e.map((a) => this.createCartLineItem(a)), o = [...s.lineItems.physicalItems, ...r], n = this.calculateCartTotals(o), i = {
150
+ const i = e.map((o) => this.createCartLineItem(o)), r = [...s.lineItems.physicalItems, ...i], a = this.calculateCartTotals(r), n = {
151
151
  ...s,
152
152
  lineItems: {
153
153
  ...s.lineItems,
154
- physicalItems: o
154
+ physicalItems: r
155
155
  },
156
- amount: n.amount,
157
- baseAmount: n.baseAmount,
158
- discountedAmount: n.discountedAmount,
156
+ amount: a.amount,
157
+ baseAmount: a.baseAmount,
158
+ discountedAmount: a.discountedAmount,
159
159
  updatedAt: { utc: (/* @__PURE__ */ new Date()).toISOString() }
160
160
  };
161
- this.carts.set(t, i);
162
- for (const [a, c] of this.checkoutToCartId.entries())
163
- if (c === t) {
164
- const u = this.checkouts.get(a);
161
+ this.carts.set(t, n);
162
+ for (const [o, l] of this.checkoutToCartId.entries())
163
+ if (l === t) {
164
+ const u = this.checkouts.get(o);
165
165
  if (u) {
166
- const l = { ...u };
167
- this.calculateCheckoutTotals(l), this.checkouts.set(a, l);
166
+ const c = { ...u };
167
+ this.calculateCheckoutTotals(c), this.checkouts.set(o, c);
168
168
  }
169
169
  break;
170
170
  }
171
- return { cart: i, errors: [] };
171
+ return { cart: n, errors: [] };
172
172
  }
173
173
  /**
174
174
  * Update the quantity of a cart line item
175
175
  */
176
- async updateCartLineItem(t, e, s, r, o) {
177
- const n = this.carts.get(t);
178
- if (!n)
176
+ async updateCartLineItem(t, e, s, i, r) {
177
+ const a = this.carts.get(t);
178
+ if (!a)
179
179
  return null;
180
- const i = n.lineItems.physicalItems.findIndex(
181
- (d) => d.entityId === e
180
+ const n = a.lineItems.physicalItems.findIndex(
181
+ (h) => h.entityId === e
182
182
  );
183
- if (i === -1)
183
+ if (n === -1)
184
184
  return null;
185
- const a = [...n.lineItems.physicalItems], c = a[i];
186
- if (!c)
185
+ const o = [...a.lineItems.physicalItems], l = o[n];
186
+ if (!l)
187
187
  return null;
188
- const l = c.listPrice.value * s;
189
- a[i] = {
190
- ...c,
188
+ const c = l.listPrice.value * s;
189
+ o[n] = {
190
+ ...l,
191
191
  quantity: s,
192
- extendedListPrice: this.createMoney(l),
193
- extendedSalePrice: this.createMoney(l)
192
+ extendedListPrice: this.createMoney(c),
193
+ extendedSalePrice: this.createMoney(c)
194
194
  };
195
- const h = this.calculateCartTotals(a), m = {
196
- ...n,
195
+ const d = this.calculateCartTotals(o), p = {
196
+ ...a,
197
197
  lineItems: {
198
- ...n.lineItems,
199
- physicalItems: a
198
+ ...a.lineItems,
199
+ physicalItems: o
200
200
  },
201
- amount: h.amount,
202
- baseAmount: h.baseAmount,
203
- discountedAmount: h.discountedAmount,
201
+ amount: d.amount,
202
+ baseAmount: d.baseAmount,
203
+ discountedAmount: d.discountedAmount,
204
204
  updatedAt: { utc: (/* @__PURE__ */ new Date()).toISOString() }
205
205
  };
206
- this.carts.set(t, m);
207
- for (const [d, y] of this.checkoutToCartId.entries())
206
+ this.carts.set(t, p);
207
+ for (const [h, y] of this.checkoutToCartId.entries())
208
208
  if (y === t) {
209
- const g = this.checkouts.get(d);
209
+ const g = this.checkouts.get(h);
210
210
  if (g) {
211
211
  const C = { ...g };
212
- this.calculateCheckoutTotals(C), this.checkouts.set(d, C);
212
+ this.calculateCheckoutTotals(C), this.checkouts.set(h, C);
213
213
  }
214
214
  break;
215
215
  }
216
- return m;
216
+ return p;
217
217
  }
218
218
  /**
219
219
  * Remove a line item from the cart
@@ -221,33 +221,33 @@ class I {
221
221
  async deleteCartLineItem(t, e) {
222
222
  const s = this.carts.get(t);
223
223
  if (!s || !s.lineItems.physicalItems.some(
224
- (a) => a.entityId === e
224
+ (o) => o.entityId === e
225
225
  ))
226
226
  return null;
227
- const o = s.lineItems.physicalItems.filter(
228
- (a) => a.entityId !== e
229
- ), n = this.calculateCartTotals(o), i = {
227
+ const r = s.lineItems.physicalItems.filter(
228
+ (o) => o.entityId !== e
229
+ ), a = this.calculateCartTotals(r), n = {
230
230
  ...s,
231
231
  lineItems: {
232
232
  ...s.lineItems,
233
- physicalItems: o
233
+ physicalItems: r
234
234
  },
235
- amount: n.amount,
236
- baseAmount: n.baseAmount,
237
- discountedAmount: n.discountedAmount,
235
+ amount: a.amount,
236
+ baseAmount: a.baseAmount,
237
+ discountedAmount: a.discountedAmount,
238
238
  updatedAt: { utc: (/* @__PURE__ */ new Date()).toISOString() }
239
239
  };
240
- this.carts.set(t, i);
241
- for (const [a, c] of this.checkoutToCartId.entries())
242
- if (c === t) {
243
- const u = this.checkouts.get(a);
240
+ this.carts.set(t, n);
241
+ for (const [o, l] of this.checkoutToCartId.entries())
242
+ if (l === t) {
243
+ const u = this.checkouts.get(o);
244
244
  if (u) {
245
- const l = { ...u };
246
- this.calculateCheckoutTotals(l), this.checkouts.set(a, l);
245
+ const c = { ...u };
246
+ this.calculateCheckoutTotals(c), this.checkouts.set(o, c);
247
247
  }
248
248
  break;
249
249
  }
250
- return i;
250
+ return n;
251
251
  }
252
252
  /**
253
253
  * Delete an entire cart
@@ -256,8 +256,8 @@ class I {
256
256
  if (!this.carts.get(t))
257
257
  return null;
258
258
  this.carts.delete(t);
259
- for (const [s, r] of this.checkoutToCartId.entries())
260
- if (r === t) {
259
+ for (const [s, i] of this.checkoutToCartId.entries())
260
+ if (i === t) {
261
261
  this.checkouts.delete(s), this.checkoutToCartId.delete(s);
262
262
  break;
263
263
  }
@@ -289,10 +289,10 @@ class I {
289
289
  * Add shipping consignments (addresses) to a checkout
290
290
  */
291
291
  async setCheckoutShippingAddress(t, e, s) {
292
- const r = this.checkouts.get(t);
293
- if (!r)
292
+ const i = this.checkouts.get(t);
293
+ if (!i)
294
294
  return null;
295
- const o = this.generateConsignmentId(), n = [
295
+ const r = this.generateConsignmentId(), a = [
296
296
  {
297
297
  entityId: this.generateShippingOptionId(),
298
298
  description: "Standard Shipping",
@@ -311,8 +311,8 @@ class I {
311
311
  type: "shipping_overnight",
312
312
  cost: this.createMoney(25)
313
313
  }
314
- ], i = {
315
- entityId: o,
314
+ ], n = {
315
+ entityId: r,
316
316
  address: {
317
317
  firstName: e.firstName ?? null,
318
318
  lastName: e.lastName ?? null,
@@ -326,18 +326,18 @@ class I {
326
326
  phone: e.phone ?? null,
327
327
  email: e.email ?? null
328
328
  },
329
- availableShippingOptions: n,
329
+ availableShippingOptions: a,
330
330
  selectedShippingOption: null,
331
331
  shippingCost: null,
332
- lineItemIds: s.map((c) => c.lineItemEntityId)
333
- }, a = {
334
- ...r,
332
+ lineItemIds: s.map((l) => l.lineItemEntityId)
333
+ }, o = {
334
+ ...i,
335
335
  shippingConsignments: [
336
- ...r.shippingConsignments ?? [],
337
- i
336
+ ...i.shippingConsignments ?? [],
337
+ n
338
338
  ]
339
339
  };
340
- return this.calculateCheckoutTotals(a), this.checkouts.set(t, a), a;
340
+ return this.calculateCheckoutTotals(o), this.checkouts.set(t, o), o;
341
341
  }
342
342
  /**
343
343
  * Add billing address to a checkout
@@ -388,59 +388,6 @@ class I {
388
388
  "MockBigCommerceClient.request() is not implemented. Use specific methods instead."
389
389
  );
390
390
  }
391
- /**
392
- * Get product paths for building product page URLs
393
- * Returns a map of productEntityId to path
394
- */
395
- async getProductPaths(t) {
396
- const e = /* @__PURE__ */ new Map();
397
- for (const s of t)
398
- e.set(s, `/products/product-${s}/`);
399
- return e;
400
- }
401
- /**
402
- * Get products for display (used by showProducts tool)
403
- * Returns mock product names, images, prices, and variant information
404
- */
405
- async getProductsForDisplay(t) {
406
- return t.map((e) => ({
407
- entityId: e,
408
- name: `Product ${e}`,
409
- sku: `SKU-${e}`,
410
- path: `/products/product-${e}/`,
411
- defaultImage: {
412
- urlTemplate: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/sample.jpg"
413
- },
414
- variants: [
415
- {
416
- entityId: e * 1e3 + 1,
417
- sku: `SKU-${e}-V1`,
418
- isPurchasable: !0,
419
- defaultImage: {
420
- urlTemplate: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/variant1.jpg"
421
- },
422
- prices: { price: { value: 29.99, currencyCode: "USD" } },
423
- inventory: {
424
- isInStock: !0,
425
- aggregated: { availableToSell: 10, warningLevel: 3 }
426
- }
427
- },
428
- {
429
- entityId: e * 1e3 + 2,
430
- sku: `SKU-${e}-V2`,
431
- isPurchasable: !0,
432
- defaultImage: {
433
- urlTemplate: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/variant2.jpg"
434
- },
435
- prices: { price: { value: 34.99, currencyCode: "USD" } },
436
- inventory: {
437
- isInStock: !0,
438
- aggregated: { availableToSell: 5, warningLevel: 3 }
439
- }
440
- }
441
- ]
442
- }));
443
- }
444
391
  /**
445
392
  * Get product variant details for multiple products
446
393
  * Returns mock product options and variants
@@ -598,6 +545,124 @@ class I {
598
545
  ]
599
546
  }));
600
547
  }
548
+ /**
549
+ * Get product display data for caching (unified query).
550
+ * Returns mock products with paths, options, and default variant.
551
+ */
552
+ async getProductDisplayData(t, e) {
553
+ return t.map((s) => {
554
+ const i = {
555
+ entityId: s * 1e3 + 1,
556
+ productEntityId: s,
557
+ sku: `SKU-${s}-S-R`,
558
+ isPurchasable: !0,
559
+ defaultImage: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/variant1.jpg",
560
+ price: 29.99,
561
+ currencyCode: "USD",
562
+ isInStock: !0,
563
+ availableToSell: 10,
564
+ optionValues: {
565
+ [s * 100]: s * 100 + 1,
566
+ // Size: Small
567
+ [s * 100 + 10]: s * 100 + 11
568
+ // Color: Red
569
+ }
570
+ };
571
+ let r = i;
572
+ if (e?.length) {
573
+ const a = e.find(
574
+ (n) => n >= s * 1e3 + 1 && n <= s * 1e3 + 6
575
+ );
576
+ a && a !== i.entityId && (r = {
577
+ ...i,
578
+ entityId: a,
579
+ sku: `SKU-${s}-V${a - s * 1e3}`
580
+ });
581
+ }
582
+ return {
583
+ entityId: s,
584
+ name: `Product ${s}`,
585
+ sku: `SKU-${s}`,
586
+ path: `/products/product-${s}/`,
587
+ defaultImage: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/sample.jpg",
588
+ productOptions: [
589
+ {
590
+ entityId: s * 100,
591
+ displayName: "Size",
592
+ isRequired: !0,
593
+ isVariantOption: !0,
594
+ displayStyle: "DropdownList",
595
+ values: [
596
+ {
597
+ entityId: s * 100 + 1,
598
+ label: "Small",
599
+ isDefault: !0
600
+ },
601
+ {
602
+ entityId: s * 100 + 2,
603
+ label: "Medium",
604
+ isDefault: !1
605
+ },
606
+ {
607
+ entityId: s * 100 + 3,
608
+ label: "Large",
609
+ isDefault: !1
610
+ }
611
+ ]
612
+ },
613
+ {
614
+ entityId: s * 100 + 10,
615
+ displayName: "Color",
616
+ isRequired: !0,
617
+ isVariantOption: !0,
618
+ displayStyle: "DropdownList",
619
+ values: [
620
+ {
621
+ entityId: s * 100 + 11,
622
+ label: "Red",
623
+ isDefault: !0
624
+ },
625
+ {
626
+ entityId: s * 100 + 12,
627
+ label: "Blue",
628
+ isDefault: !1
629
+ }
630
+ ]
631
+ }
632
+ ],
633
+ defaultVariant: r
634
+ };
635
+ });
636
+ }
637
+ /**
638
+ * Get a specific variant by option selections (lazy loading).
639
+ * Returns a mock variant matching the selections.
640
+ */
641
+ async getVariantByOptions(t, e) {
642
+ const s = {};
643
+ for (const { optionEntityId: p, valueEntityId: h } of e)
644
+ s[p] = h;
645
+ const i = t * 100, r = t * 100 + 10, a = s[i], n = s[r], o = {
646
+ [t * 100 + 1]: "S",
647
+ [t * 100 + 2]: "M",
648
+ [t * 100 + 3]: "L"
649
+ }, l = {
650
+ [t * 100 + 11]: "R",
651
+ [t * 100 + 12]: "B"
652
+ }, u = a ? o[a] : "S", c = n ? l[n] : "R", d = (a ? a - (t * 100 + 1) : 0) * 2 + (n ? n - (t * 100 + 11) : 0) + 1;
653
+ return {
654
+ entityId: t * 1e3 + d,
655
+ productEntityId: t,
656
+ sku: `SKU-${t}-${u}-${c}`,
657
+ isPurchasable: !0,
658
+ defaultImage: "https://cdn11.bigcommerce.com/s-abc/images/stencil/200w/products/{:size}/variant.jpg",
659
+ price: 29.99 + (a ? (a - (t * 100 + 1)) * 5 : 0),
660
+ currencyCode: "USD",
661
+ isInStock: !0,
662
+ availableToSell: 10 - d,
663
+ optionValues: s
664
+ };
665
+ }
601
666
  /**
602
667
  * Reset all state (useful for testing)
603
668
  */
@@ -605,19 +670,19 @@ class I {
605
670
  this.carts.clear(), this.checkouts.clear(), this.checkoutToCartId.clear(), this.nextCartId = 1, this.nextCheckoutId = 1, this.nextLineItemId = 1, this.nextConsignmentId = 1, this.nextShippingOptionId = 1;
606
671
  }
607
672
  }
608
- function S(p) {
609
- return new I(p);
673
+ function S(m) {
674
+ return new I(m);
610
675
  }
611
676
  export {
612
677
  I as MockBigCommerceClient,
613
- f as PurchaseOrderChat,
614
- b as PurchaseOrderChatWidget,
678
+ k as PurchaseOrderChat,
679
+ v as PurchaseOrderChatWidget,
615
680
  T as StylesTarget,
616
681
  M as createB2BClient,
617
- P as createBigCommerceClient,
618
- x as createBigCommerceEndpoint,
682
+ O as createBigCommerceClient,
683
+ L as createBigCommerceEndpoint,
619
684
  S as createMockBigCommerceClient,
620
- w as initTracing,
621
- O as stencilB2BJwt
685
+ x as initTracing,
686
+ P as stencilB2BJwt
622
687
  };
623
688
  //# sourceMappingURL=tailwind.js.map