@shopfront/bridge 1.18.4 → 1.20.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.
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GitToolBoxProjectSettings">
4
+ <option name="commitMessageIssueKeyValidationOverride">
5
+ <BoolValueOverride>
6
+ <option name="enabled" value="true" />
7
+ </BoolValueOverride>
8
+ </option>
9
+ <option name="commitMessageValidationEnabledOverride">
10
+ <BoolValueOverride>
11
+ <option name="enabled" value="true" />
12
+ </BoolValueOverride>
13
+ </option>
14
+ </component>
15
+ </project>
@@ -125,7 +125,7 @@ export declare class CurrentSale extends BaseSale {
125
125
  */
126
126
  setMetaData(metaData: Record<string, unknown>): Promise<void>;
127
127
  /**
128
- * Update a product's details, currently this only updates the top-level meta data
128
+ * Update a product's details, currently this can update quantity, price and metadata
129
129
  * @param product
130
130
  */
131
131
  updateProduct(product: SaleProduct): Promise<void>;
@@ -196,15 +196,25 @@ class CurrentSale extends BaseSale_1.BaseSale {
196
196
  }));
197
197
  }
198
198
  /**
199
- * Update a product's details, currently this only updates the top-level meta data
199
+ * Update a product's details, currently this can update quantity, price and metadata
200
200
  * @param product
201
201
  */
202
202
  updateProduct(product) {
203
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", {
203
+ const updateData = {
204
204
  id: product.getId(),
205
- indexAddress: product.getIndexAddress(),
206
- metaData: product.getMetaData(),
207
- }));
205
+ indexAddress: product.getIndexAddress()
206
+ };
207
+ if (product.wasQuantityModified()) {
208
+ updateData.quantity = product.getQuantity();
209
+ }
210
+ if (product.wasPriceModified()) {
211
+ updateData.price = product.getPrice();
212
+ }
213
+ if (product.wasMetaDataModified()) {
214
+ updateData.metaData = product.getMetaData();
215
+ }
216
+ product.clearModificationFlags();
217
+ return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", updateData));
208
218
  }
209
219
  }
210
220
  exports.CurrentSale = CurrentSale;
@@ -1,4 +1,4 @@
1
- import { ShopfrontSaleProduct, ShopfrontSaleProductType } from "./ShopfrontSaleState";
1
+ import { ShopfrontSaleProduct, ShopfrontSaleProductPromotions, ShopfrontSaleProductType } from "./ShopfrontSaleState";
2
2
  export declare class SaleProduct {
3
3
  readonly internalId: string;
4
4
  protected id: string;
@@ -12,8 +12,12 @@ export declare class SaleProduct {
12
12
  protected contains: Array<SaleProduct>;
13
13
  protected edited: boolean;
14
14
  protected caseQuantity?: number;
15
+ protected promotions: ShopfrontSaleProductPromotions;
15
16
  protected metaData: Record<string, unknown>;
16
17
  protected mapped?: string;
18
+ protected quantityModified: boolean;
19
+ protected priceModified: boolean;
20
+ protected metaDataModified: boolean;
17
21
  constructor(id: string, quantity: number, price?: number, indexAddress?: Array<number>);
18
22
  /**
19
23
  * Hydrate a sale product from the SaleState.
@@ -57,11 +61,19 @@ export declare class SaleProduct {
57
61
  * @returns {number}
58
62
  */
59
63
  getQuantity(): number;
64
+ /**
65
+ * Sets the current sale quantity of the product
66
+ */
67
+ setQuantity(quantity: number): void;
60
68
  /**
61
69
  * Get the current price of the product.
62
70
  * @returns {number | undefined}
63
71
  */
64
72
  getPrice(): number | undefined;
73
+ /**
74
+ * Sets the current price of the product
75
+ */
76
+ setPrice(price: number): void;
65
77
  /**
66
78
  * Get the index address of the product.
67
79
  * This is the internal address of where the product is in the sale.
@@ -114,6 +126,12 @@ export declare class SaleProduct {
114
126
  * @returns {number | undefined}
115
127
  */
116
128
  getCaseQuantity(): number | undefined;
129
+ /**
130
+ * Get the current active promotions for the product.
131
+ *
132
+ * @returns {ShopfrontSaleProductPromotions}
133
+ */
134
+ getPromotions(): ShopfrontSaleProductPromotions;
117
135
  /**
118
136
  * Get the meta data for the product.
119
137
  *
@@ -126,4 +144,28 @@ export declare class SaleProduct {
126
144
  * @param value
127
145
  */
128
146
  setMetaData(key: string, value: unknown): void;
147
+ /**
148
+ * Returns whether the product's quantity was modified externally
149
+ *
150
+ * @internal
151
+ */
152
+ wasQuantityModified(): boolean;
153
+ /**
154
+ * Returns whether the product's price was modified externally
155
+ *
156
+ * @internal
157
+ */
158
+ wasPriceModified(): boolean;
159
+ /**
160
+ * Returns whether the product's metaData was modified externally
161
+ *
162
+ * @internal
163
+ */
164
+ wasMetaDataModified(): boolean;
165
+ /**
166
+ * Sets a product's modification flags to false
167
+ *
168
+ * @internal
169
+ */
170
+ clearModificationFlags(): void;
129
171
  }
@@ -7,6 +7,7 @@ exports.SaleProduct = void 0;
7
7
  const UUID_1 = __importDefault(require("../../Utilities/UUID"));
8
8
  class SaleProduct {
9
9
  constructor(id, quantity, price, indexAddress) {
10
+ this.promotions = {};
10
11
  this.metaData = {};
11
12
  this.internalId = UUID_1.default.generate();
12
13
  this.id = id;
@@ -16,6 +17,9 @@ class SaleProduct {
16
17
  this.contains = [];
17
18
  this.edited = typeof price !== "undefined";
18
19
  this.note = "";
20
+ this.quantityModified = false;
21
+ this.priceModified = false;
22
+ this.metaDataModified = false;
19
23
  }
20
24
  /**
21
25
  * Hydrate a sale product from the SaleState.
@@ -55,6 +59,7 @@ class SaleProduct {
55
59
  this.note = data.note;
56
60
  this.edited = data.edited;
57
61
  this.caseQuantity = data.caseQuantity;
62
+ this.promotions = data.promotions;
58
63
  this.metaData = data.metaData;
59
64
  this.mapped = data.mapped;
60
65
  for (let i = 0, l = data.products.length; i < l; i++) {
@@ -86,6 +91,13 @@ class SaleProduct {
86
91
  getQuantity() {
87
92
  return this.quantity;
88
93
  }
94
+ /**
95
+ * Sets the current sale quantity of the product
96
+ */
97
+ setQuantity(quantity) {
98
+ this.quantity = quantity;
99
+ this.quantityModified = true;
100
+ }
89
101
  /**
90
102
  * Get the current price of the product.
91
103
  * @returns {number | undefined}
@@ -93,6 +105,13 @@ class SaleProduct {
93
105
  getPrice() {
94
106
  return this.price;
95
107
  }
108
+ /**
109
+ * Sets the current price of the product
110
+ */
111
+ setPrice(price) {
112
+ this.price = price;
113
+ this.priceModified = true;
114
+ }
96
115
  /**
97
116
  * Get the index address of the product.
98
117
  * This is the internal address of where the product is in the sale.
@@ -161,6 +180,14 @@ class SaleProduct {
161
180
  getCaseQuantity() {
162
181
  return this.caseQuantity;
163
182
  }
183
+ /**
184
+ * Get the current active promotions for the product.
185
+ *
186
+ * @returns {ShopfrontSaleProductPromotions}
187
+ */
188
+ getPromotions() {
189
+ return this.promotions;
190
+ }
164
191
  /**
165
192
  * Get the meta data for the product.
166
193
  *
@@ -176,6 +203,41 @@ class SaleProduct {
176
203
  */
177
204
  setMetaData(key, value) {
178
205
  this.metaData[key] = value;
206
+ this.metaDataModified = true;
207
+ }
208
+ /**
209
+ * Returns whether the product's quantity was modified externally
210
+ *
211
+ * @internal
212
+ */
213
+ wasQuantityModified() {
214
+ return this.quantityModified;
215
+ }
216
+ /**
217
+ * Returns whether the product's price was modified externally
218
+ *
219
+ * @internal
220
+ */
221
+ wasPriceModified() {
222
+ return this.priceModified;
223
+ }
224
+ /**
225
+ * Returns whether the product's metaData was modified externally
226
+ *
227
+ * @internal
228
+ */
229
+ wasMetaDataModified() {
230
+ return this.metaDataModified;
231
+ }
232
+ /**
233
+ * Sets a product's modification flags to false
234
+ *
235
+ * @internal
236
+ */
237
+ clearModificationFlags() {
238
+ this.quantityModified = false;
239
+ this.priceModified = false;
240
+ this.metaDataModified = false;
179
241
  }
180
242
  }
181
243
  exports.SaleProduct = SaleProduct;
@@ -1,5 +1,12 @@
1
1
  export declare type ShopfrontSalePaymentStatus = "completed" | "cancelled" | "failed";
2
2
  export declare type ShopfrontSaleProductType = "Normal" | "Basket" | "Package" | "Component" | "Voucher";
3
+ export interface ShopfrontSaleProductPromotions {
4
+ [id: string]: {
5
+ name: string;
6
+ active: boolean;
7
+ quantity: number;
8
+ };
9
+ }
3
10
  export interface ShopfrontSaleProduct {
4
11
  uuid: string;
5
12
  type: ShopfrontSaleProductType;
@@ -15,6 +22,7 @@ export interface ShopfrontSaleProduct {
15
22
  };
16
23
  note: string;
17
24
  products: Array<ShopfrontSaleProduct>;
25
+ promotions: ShopfrontSaleProductPromotions;
18
26
  edited: boolean;
19
27
  caseQuantity: number;
20
28
  metaData: Record<string, unknown>;
@@ -48,7 +48,9 @@ export interface SaleUpdateChanges {
48
48
  PRODUCT_UPDATE: {
49
49
  id: string;
50
50
  indexAddress: Array<number>;
51
- metaData: Record<string, unknown>;
51
+ quantity?: number;
52
+ price?: number;
53
+ metaData?: Record<string, unknown>;
52
54
  };
53
55
  }
54
56
  export declare class SaleUpdate<K extends keyof SaleUpdateChanges> extends BaseAction<SaleUpdate<K>> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.18.4",
3
+ "version": "1.20.1",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",