@shopfront/bridge 3.0.13 → 3.0.14

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.
@@ -2,8 +2,8 @@ import type { SaleCustomer } from "./SaleCustomer.js";
2
2
  import type { SalePayment } from "./SalePayment.js";
3
3
  import type { SaleProduct } from "./SaleProduct.js";
4
4
  export interface BaseSaleData {
5
+ internalId: string;
5
6
  register: string | undefined;
6
- clientId: string | undefined;
7
7
  notes: {
8
8
  internal: string;
9
9
  sale: string;
@@ -54,7 +54,7 @@ export declare abstract class BaseSale {
54
54
  /**
55
55
  * Get the client id.
56
56
  */
57
- getClientId(): string | undefined;
57
+ getClientId(): string;
58
58
  /**
59
59
  * Get the current sale total on the sale.
60
60
  */
@@ -40,8 +40,8 @@ export interface ShopfrontSalePayment {
40
40
  metadata: string;
41
41
  }
42
42
  export interface ShopfrontSaleState {
43
+ internalId: string;
43
44
  status?: ShopfrontSaleStatus;
44
- clientId?: string;
45
45
  register?: string;
46
46
  products: Array<ShopfrontSaleProduct>;
47
47
  customer: false | ShopfrontSaleCustomer;
package/lib/index.mjs CHANGED
@@ -65,7 +65,7 @@ class se {
65
65
  this.events = {};
66
66
  }
67
67
  }
68
- const S = new se();
68
+ const _ = new se();
69
69
  function re() {
70
70
  return (r) => {
71
71
  };
@@ -120,7 +120,7 @@ let c = class extends te {
120
120
  addEventListener(r, e) {
121
121
  super.addEventListener(r, e);
122
122
  const t = `${Date.now()}-${r}-${Math.random()}`;
123
- S.add(t, this), this.events.push({
123
+ _.add(t, this), this.events.push({
124
124
  id: t,
125
125
  callback: e,
126
126
  type: r
@@ -135,7 +135,7 @@ let c = class extends te {
135
135
  if (this.events[t].type !== r || this.events[t].callback !== e)
136
136
  continue;
137
137
  const i = this.events[t].id;
138
- S.remove(i), this.events = [
138
+ _.remove(i), this.events = [
139
139
  ...this.events.slice(0, t),
140
140
  ...this.events.slice(t + 1)
141
141
  ];
@@ -157,7 +157,7 @@ ue(c, "serializedRegistry", {});
157
157
  c = oe([
158
158
  re()
159
159
  ], c);
160
- class _ extends c {
160
+ class R extends c {
161
161
  supportedEvents = ["click"];
162
162
  label;
163
163
  icon;
@@ -166,7 +166,7 @@ class _ extends c {
166
166
  properties: [e, t],
167
167
  events: {},
168
168
  type: "Button"
169
- } : e, _), typeof t > "u" && typeof e != "string" ? (this.label = e.properties[0], this.icon = e.properties[1]) : (this.label = e, typeof t > "u" ? this.icon = "" : this.icon = t);
169
+ } : e, R), typeof t > "u" && typeof e != "string" ? (this.label = e.properties[0], this.icon = e.properties[1]) : (this.label = e, typeof t > "u" ? this.icon = "" : this.icon = t);
170
170
  }
171
171
  }
172
172
  class b extends c {
@@ -210,7 +210,7 @@ const qe = {
210
210
  InternalRedirect: w,
211
211
  ExternalRedirect: D
212
212
  };
213
- class T extends c {
213
+ class m extends c {
214
214
  supportedEvents = ["click"];
215
215
  id;
216
216
  name;
@@ -219,7 +219,7 @@ class T extends c {
219
219
  properties: [e, t],
220
220
  events: {},
221
221
  type: "Button"
222
- } : e, T), typeof t > "u" && typeof e != "string" ? (this.id = e.properties[0], this.name = e.properties[1]) : (this.id = e, typeof t > "u" ? this.name = "" : this.name = t);
222
+ } : e, m), typeof t > "u" && typeof e != "string" ? (this.id = e.properties[0], this.name = e.properties[1]) : (this.id = e, typeof t > "u" ? this.name = "" : this.name = t);
223
223
  }
224
224
  }
225
225
  class v extends c {
@@ -276,7 +276,7 @@ class x {
276
276
  * Get the client id.
277
277
  */
278
278
  getClientId() {
279
- return this.sale.clientId;
279
+ return this.sale.internalId;
280
280
  }
281
281
  /**
282
282
  * Get the current sale total on the sale.
@@ -363,7 +363,7 @@ class de {
363
363
  * @license MIT
364
364
  * {@link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136}
365
365
  */
366
- class A {
366
+ class S {
367
367
  lut;
368
368
  constructor() {
369
369
  this.lut = [];
@@ -382,7 +382,7 @@ class A {
382
382
  * Static method for generating a UUID
383
383
  */
384
384
  static generate() {
385
- return typeof self?.crypto?.randomUUID == "function" ? self.crypto.randomUUID() : new A().generate();
385
+ return typeof self?.crypto?.randomUUID == "function" ? self.crypto.randomUUID() : new S().generate();
386
386
  }
387
387
  }
388
388
  var ce = /* @__PURE__ */ ((r) => (r.APPROVED = "completed", r.DECLINED = "failed", r.CANCELLED = "cancelled", r))(ce || {});
@@ -397,7 +397,7 @@ class L {
397
397
  metaData = {};
398
398
  options;
399
399
  constructor(e, t, s, i, n) {
400
- this.internalId = A.generate(), this.id = e, this.amount = t, this.cashout = s, this.status = i, this.options = n;
400
+ this.internalId = S.generate(), this.id = e, this.amount = t, this.cashout = s, this.status = i, this.options = n;
401
401
  }
402
402
  /**
403
403
  * Hydrate a sale payment from the SaleState.
@@ -474,7 +474,7 @@ class L {
474
474
  return this.options;
475
475
  }
476
476
  }
477
- class R {
477
+ class y {
478
478
  internalId;
479
479
  id;
480
480
  quantity;
@@ -494,14 +494,14 @@ class R {
494
494
  priceModified;
495
495
  metaDataModified;
496
496
  constructor(e, t, s, i) {
497
- this.internalId = A.generate(), this.id = e, this.quantity = t, this.price = s, this.indexAddress = i || [], this.contains = [], this.edited = typeof s < "u", this.note = "", this.quantityModified = !1, this.priceModified = !1, this.metaDataModified = !1;
497
+ this.internalId = S.generate(), this.id = e, this.quantity = t, this.price = s, this.indexAddress = i || [], this.contains = [], this.edited = typeof s < "u", this.note = "", this.quantityModified = !1, this.priceModified = !1, this.metaDataModified = !1;
498
498
  }
499
499
  /**
500
500
  * Hydrate a sale product from the SaleState.
501
501
  * @internal
502
502
  */
503
503
  static HydrateFromState(e, t) {
504
- const s = new R(e.uuid, e.quantity, e.prices.price, t);
504
+ const s = new y(e.uuid, e.quantity, e.prices.price, t);
505
505
  return s.setInternal(e, t), s;
506
506
  }
507
507
  /**
@@ -519,7 +519,7 @@ class R {
519
519
  setInternal(e, t) {
520
520
  this.name = e.name, this.type = e.type, this.taxRateAmount = e.tax?.amount || 0, this.note = e.note, this.edited = e.edited, this.caseQuantity = e.caseQuantity, this.promotions = e.promotions, this.metaData = e.metaData, this.mapped = e.mapped;
521
521
  for (let s = 0, i = e.products.length; s < i; s++)
522
- this.appendProduct(R.HydrateFromState(e.products[s], [
522
+ this.appendProduct(y.HydrateFromState(e.products[s], [
523
523
  ...t,
524
524
  s
525
525
  ]));
@@ -762,8 +762,8 @@ class O extends x {
762
762
  */
763
763
  static buildSaleData(e) {
764
764
  return {
765
+ internalId: e.internalId,
765
766
  register: e.register,
766
- clientId: e.clientId,
767
767
  notes: e.notes,
768
768
  totals: e.totals,
769
769
  linkedTo: e.linkedTo,
@@ -773,7 +773,7 @@ class O extends x {
773
773
  metaData: e.metaData,
774
774
  customer: e.customer ? new de(e.customer.uuid) : null,
775
775
  payments: e.payments.map(L.HydrateFromState),
776
- products: e.products.map((t, s) => R.HydrateFromState(t, [s]))
776
+ products: e.products.map((t, s) => y.HydrateFromState(t, [s]))
777
777
  };
778
778
  }
779
779
  }
@@ -1050,7 +1050,7 @@ class j extends d {
1050
1050
  let t = await this.callback(e.location, e.context);
1051
1051
  Array.isArray(t) || (t = [t]);
1052
1052
  for (let s = 0, i = t.length; s < i; s++)
1053
- if (!(t[s] instanceof _))
1053
+ if (!(t[s] instanceof R))
1054
1054
  throw new TypeError("You must return an instance of Button");
1055
1055
  return t;
1056
1056
  }
@@ -1060,7 +1060,7 @@ class j extends d {
1060
1060
  static async respond(e, t, s) {
1061
1061
  const i = [];
1062
1062
  for (let n = 0, o = t.length; n < o; n++) {
1063
- if (!(t[n] instanceof _))
1063
+ if (!(t[n] instanceof R))
1064
1064
  throw new TypeError("Invalid response returned, expected button");
1065
1065
  i.push(t[n].serialize());
1066
1066
  }
@@ -1118,7 +1118,7 @@ class H extends d {
1118
1118
  let e = await this.callback(void 0, void 0);
1119
1119
  Array.isArray(e) || (e = [e]);
1120
1120
  for (let t = 0, s = e.length; t < s; t++)
1121
- if (!(e[t] instanceof T))
1121
+ if (!(e[t] instanceof m))
1122
1122
  throw new TypeError("You must return an instance of SaleKey");
1123
1123
  return e;
1124
1124
  }
@@ -1128,7 +1128,7 @@ class H extends d {
1128
1128
  static async respond(e, t, s) {
1129
1129
  const i = [];
1130
1130
  for (let n = 0, o = t.length; n < o; n++) {
1131
- if (!(t[n] instanceof T))
1131
+ if (!(t[n] instanceof m))
1132
1132
  throw new TypeError("Invalid response returned, expected SaleKey");
1133
1133
  i.push(t[n].serialize());
1134
1134
  }
@@ -1448,13 +1448,13 @@ class me extends J {
1448
1448
  */
1449
1449
  async callMethod(e, t, s) {
1450
1450
  const i = `DatabaseRequest-${Math.random()}-${Date.now()}`, n = new Promise((o, u) => {
1451
- const E = (p, y) => {
1452
- if (p === "RESPONSE_DATABASE_REQUEST" && y.requestId === i) {
1453
- if (this.bridge.removeEventListener(E), y.error) {
1454
- u(y.error);
1451
+ const E = (p, T) => {
1452
+ if (p === "RESPONSE_DATABASE_REQUEST" && T.requestId === i) {
1453
+ if (this.bridge.removeEventListener(E), T.error) {
1454
+ u(T.error);
1455
1455
  return;
1456
1456
  }
1457
- o(y.results);
1457
+ o(T.results);
1458
1458
  }
1459
1459
  };
1460
1460
  this.bridge.addEventListener(E);
@@ -1776,7 +1776,7 @@ const Ce = [
1776
1776
  "SALE_ADD_CUSTOMER",
1777
1777
  "SALE_REMOVE_CUSTOMER",
1778
1778
  "SALE_CLEAR"
1779
- ], m = (r) => Ce.includes(r);
1779
+ ], A = (r) => Ce.includes(r);
1780
1780
  class W extends d {
1781
1781
  constructor(e) {
1782
1782
  super(e);
@@ -1852,7 +1852,7 @@ class Z {
1852
1852
  * Register a listener for a Shopfront event
1853
1853
  */
1854
1854
  addEventListener(e, t) {
1855
- if (m(e)) {
1855
+ if (A(e)) {
1856
1856
  let i;
1857
1857
  switch (e) {
1858
1858
  case "SALE_ADD_PRODUCT":
@@ -1974,7 +1974,7 @@ class Z {
1974
1974
  * Removed a registered listener for a Shopfront event
1975
1975
  */
1976
1976
  removeEventListener(e, t) {
1977
- if (m(e)) {
1977
+ if (A(e)) {
1978
1978
  this.directListeners[e].delete(t);
1979
1979
  return;
1980
1980
  }
@@ -2022,8 +2022,8 @@ function X(r) {
2022
2022
  function Ue(r) {
2023
2023
  const e = r.getCustomer();
2024
2024
  return {
2025
+ internalId: r.getClientId(),
2025
2026
  register: r.getRegister(),
2026
- clientId: r.getClientId(),
2027
2027
  notes: {
2028
2028
  internal: r.getInternalNote(),
2029
2029
  sale: r.getExternalNote()
@@ -2090,7 +2090,7 @@ class be extends Z {
2090
2090
  this.key = t.key;
2091
2091
  return;
2092
2092
  } else if (e === "LOCATION_CHANGED") {
2093
- S.clear();
2093
+ _.clear();
2094
2094
  return;
2095
2095
  } else if (e === "RESPONSE_CURRENT_SALE" || e === "RESPONSE_DATABASE_REQUEST" || e === "RESPONSE_LOCATION" || e === "RESPONSE_OPTION" || e === "RESPONSE_AUDIO_REQUEST" || e === "RESPONSE_SECURE_KEY" || e === "RESPONSE_CREATE_SALE")
2096
2096
  return;
@@ -2100,7 +2100,7 @@ class be extends Z {
2100
2100
  * Calls any registered listeners for the received event
2101
2101
  */
2102
2102
  emit(e, t = {}, s) {
2103
- if (m(e)) {
2103
+ if (A(e)) {
2104
2104
  const n = this.directListeners[e];
2105
2105
  if (typeof n > "u")
2106
2106
  return this.bridge.sendMessage(a.NOT_LISTENING_TO_EVENT);
@@ -2148,7 +2148,7 @@ class be extends Z {
2148
2148
  * @inheritDoc
2149
2149
  */
2150
2150
  send(e) {
2151
- if (e instanceof _)
2151
+ if (e instanceof R)
2152
2152
  throw new TypeError("You cannot send Buttons to Shopfront without Shopfront requesting them");
2153
2153
  if (e instanceof h)
2154
2154
  this.bridge.sendMessage(e.getEvent(), e.getData());
@@ -2185,7 +2185,7 @@ class be extends Z {
2185
2185
  if (typeof e.id > "u")
2186
2186
  return;
2187
2187
  const t = e.id;
2188
- S.fire(t, e.data);
2188
+ _.fire(t, e.data);
2189
2189
  }
2190
2190
  /**
2191
2191
  * Updates the cached location data
@@ -2700,7 +2700,7 @@ class ee extends Z {
2700
2700
  vendor: t.vendor
2701
2701
  }), e !== "CALLBACK" && e !== "CYCLE_KEY") {
2702
2702
  if (e === "LOCATION_CHANGED") {
2703
- S.clear();
2703
+ _.clear();
2704
2704
  return;
2705
2705
  } else if (e === "RESPONSE_CURRENT_SALE" || e === "RESPONSE_DATABASE_REQUEST" || e === "RESPONSE_LOCATION" || e === "RESPONSE_OPTION" || e === "RESPONSE_AUDIO_REQUEST" || e === "RESPONSE_SECURE_KEY" || e === "RESPONSE_CREATE_SALE")
2706
2706
  return;
@@ -2711,7 +2711,7 @@ class ee extends Z {
2711
2711
  * Calls any registered listeners for the received event
2712
2712
  */
2713
2713
  async emit(e, t = {}, s) {
2714
- if (m(e)) {
2714
+ if (A(e)) {
2715
2715
  const o = this.directListeners[e];
2716
2716
  if (typeof o > "u")
2717
2717
  return this.bridge.sendMessage(a.NOT_LISTENING_TO_EVENT);
@@ -2931,7 +2931,7 @@ class ee extends Z {
2931
2931
  }
2932
2932
  }
2933
2933
  const Ge = {
2934
- clientId: void 0,
2934
+ internalId: "",
2935
2935
  register: void 0,
2936
2936
  products: [],
2937
2937
  customer: !1,
@@ -2954,7 +2954,10 @@ const Ge = {
2954
2954
  };
2955
2955
  class Qe extends k {
2956
2956
  constructor(e, t) {
2957
- super(e, t ?? Ge);
2957
+ super(e, t ?? {
2958
+ ...Ge,
2959
+ internalId: S.generate()
2960
+ });
2958
2961
  }
2959
2962
  /**
2960
2963
  * Fires the event trigger
@@ -3179,7 +3182,7 @@ class Qe extends k {
3179
3182
  * Clones a sale product so it can be added to the sale
3180
3183
  */
3181
3184
  cloneProduct(e) {
3182
- const t = new R(
3185
+ const t = new y(
3183
3186
  e.getId(),
3184
3187
  e.getQuantity(),
3185
3188
  e.getPrice(),
@@ -3254,8 +3257,8 @@ class Qe extends k {
3254
3257
  */
3255
3258
  clearSale() {
3256
3259
  this.products.length = 0, this.products.push(), this.payments.length = 0, this.payments.push(), this.customer = null, this.sale = {
3260
+ internalId: S.generate(),
3257
3261
  register: void 0,
3258
- clientId: void 0,
3259
3262
  notes: {
3260
3263
  sale: "",
3261
3264
  internal: ""
@@ -3288,7 +3291,7 @@ export {
3288
3291
  k as BaseCurrentSale,
3289
3292
  x as BaseSale,
3290
3293
  M as Bridge,
3291
- _ as Button,
3294
+ R as Button,
3292
3295
  b as Dialog,
3293
3296
  Ye as Exceptions,
3294
3297
  ve as InternalMessage,
@@ -3306,17 +3309,17 @@ export {
3306
3309
  $e as RegisterIntent,
3307
3310
  O as Sale,
3308
3311
  de as SaleCustomer,
3309
- T as SaleKey,
3312
+ m as SaleKey,
3310
3313
  L as SalePayment,
3311
3314
  ce as SalePaymentStatus,
3312
- R as SaleProduct,
3315
+ y as SaleProduct,
3313
3316
  ze as SellScreenOption,
3314
3317
  Je as SellScreenPromotionApplicable,
3315
3318
  I as ShopfrontTokenDecodingError,
3316
3319
  Me as ShopfrontTokenRequestError,
3317
3320
  We as TableUpdate,
3318
3321
  v as Toast,
3319
- A as UUID,
3322
+ S as UUID,
3320
3323
  Ze as mockApplication
3321
3324
  };
3322
3325
  //# sourceMappingURL=index.mjs.map