@shopfront/bridge 1.20.2 → 1.20.5

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,29 @@
1
+ name: Pack and Distribute
2
+ on:
3
+ release:
4
+ types: [created]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v4
10
+ - uses: actions/setup-node@v3
11
+ with:
12
+ node-version: '20.x'
13
+ - run: npm ci
14
+ - run: npm run-script build
15
+ publish-npm:
16
+ needs: build
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ id-token: write
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - uses: actions/setup-node@v3
23
+ with:
24
+ node-version: '20.x'
25
+ registry-url: 'https://registry.npmjs.org/'
26
+ - run: npm ci
27
+ - run: npm publish --provenance --access public
28
+ env:
29
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.idea/modules.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/embedded-bridge.iml" />
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" />
6
6
  </modules>
7
7
  </component>
8
8
  </project>
package/.idea/php.xml CHANGED
@@ -7,6 +7,7 @@
7
7
  <option name="transferred" value="true" />
8
8
  </component>
9
9
  <component name="PHPCodeSnifferOptionsConfiguration">
10
+ <option name="highlightLevel" value="WARNING" />
10
11
  <option name="transferred" value="true" />
11
12
  </component>
12
13
  <component name="PhpStanOptionsConfiguration">
@@ -1,9 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <module type="WEB_MODULE" version="4">
3
3
  <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/lib" />
6
- </content>
4
+ <content url="file://$MODULE_DIR$" />
7
5
  <orderEntry type="inheritedJdk" />
8
6
  <orderEntry type="sourceFolder" forTests="false" />
9
7
  </component>
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
4
+ <mapping directory="" vcs="Git" />
5
5
  </component>
6
6
  </project>
@@ -30,7 +30,7 @@ export interface OrderItem {
30
30
  id?: number;
31
31
  barcode?: "auto" | number;
32
32
  mdbId?: number;
33
- supplierCodes?: number;
33
+ supplierCode?: number;
34
34
  defaultTo: number;
35
35
  };
36
36
  price: number;
@@ -32,6 +32,7 @@ const FulfilmentCompleteOrder_1 = require("./Events/FulfilmentCompleteOrder");
32
32
  const CurrentSale_1 = require("./APIs/Sale/CurrentSale");
33
33
  const SaleCreate_1 = require("./Utilities/SaleCreate");
34
34
  const AudioReady_1 = require("./Events/AudioReady");
35
+ const GiftCardCodeCheck_1 = require("./Events/GiftCardCodeCheck");
35
36
  class ShopfrontTokenDecodingError extends Error {
36
37
  }
37
38
  exports.ShopfrontTokenDecodingError = ShopfrontTokenDecodingError;
@@ -63,6 +64,7 @@ class Application {
63
64
  FULFILMENT_ORDER_APPROVAL: new Map(),
64
65
  FULFILMENT_ORDER_COLLECTED: new Map(),
65
66
  FULFILMENT_ORDER_COMPLETED: new Map(),
67
+ GIFT_CARD_CODE_CHECK: new Map(),
66
68
  };
67
69
  this.directListeners = {};
68
70
  this.handleEvent = (event, data, id) => {
@@ -188,6 +190,12 @@ class Application {
188
190
  .then(res => {
189
191
  return UIPipeline_1.UIPipeline.respond(this.bridge, res.flat(), id);
190
192
  });
193
+ case "GIFT_CARD_CODE_CHECK":
194
+ results = results;
195
+ return Promise.all(results)
196
+ .then(res => {
197
+ return GiftCardCodeCheck_1.GiftCardCodeCheck.respond(this.bridge, res[0], id);
198
+ });
191
199
  case "PAYMENT_METHODS_ENABLED":
192
200
  results = results;
193
201
  return Promise.all(results)
@@ -303,6 +311,10 @@ class Application {
303
311
  c = new FulfilmentCompleteOrder_1.FulfilmentCompleteOrder(callback);
304
312
  this.listeners[event].set(callback, c);
305
313
  break;
314
+ case "GIFT_CARD_CODE_CHECK":
315
+ c = new GiftCardCodeCheck_1.GiftCardCodeCheck(callback);
316
+ this.listeners[event].set(callback, c);
317
+ break;
306
318
  }
307
319
  if (typeof c === "undefined") {
308
320
  throw new TypeError(`${event} has not been defined`);
@@ -27,6 +27,7 @@ import { FulfilmentCollectOrder } from "./Events/FulfilmentCollectOrder";
27
27
  import { FulfilmentCompleteOrder } from "./Events/FulfilmentCompleteOrder";
28
28
  import { Sale } from "./APIs/Sale";
29
29
  import { AudioReady } from "./Events/AudioReady";
30
+ import { GiftCardCodeCheck } from "./Events/GiftCardCodeCheck";
30
31
  export declare enum ToShopfront {
31
32
  READY = "READY",
32
33
  SERIALIZED = "SERIALIZED",
@@ -48,6 +49,7 @@ export declare enum ToShopfront {
48
49
  REDIRECT = "REDIRECT",
49
50
  GET_OPTION = "GET_OPTION",
50
51
  RESPONSE_UI_PIPELINE = "RESPONSE_UI_PIPELINE",
52
+ RESPONSE_GIFT_CARD_CODE_CHECK = "RESPONSE_GIFT_CARD_CODE_CHECK",
51
53
  REQUEST_SECURE_KEY = "REQUEST_SECURE_KEY",
52
54
  ROTATE_SIGNING_KEY = "ROTATE_SIGNING_KEY",
53
55
  AUDIO_REQUEST_PERMISSION = "AUDIO_REQUEST_PERMISSION",
@@ -129,6 +131,10 @@ export interface FromShopfrontReturns {
129
131
  success: boolean;
130
132
  message?: string;
131
133
  };
134
+ GIFT_CARD_CODE_CHECK: {
135
+ code: string;
136
+ message: string | null;
137
+ };
132
138
  }
133
139
  export interface InternalPageMessageEvent {
134
140
  method: "REQUEST_SETTINGS" | "REQUEST_SELL_SCREEN_OPTIONS" | "EXTERNAL_APPLICATION";
@@ -141,6 +147,10 @@ export interface RegisterChangedEvent {
141
147
  outlet: null | string;
142
148
  user: null | string;
143
149
  }
150
+ export interface GiftCardCodeCheckEvent {
151
+ code: string;
152
+ message: string | null;
153
+ }
144
154
  export interface FormatIntegratedProductEvent {
145
155
  product: FormattedSaleProduct;
146
156
  }
@@ -205,6 +215,7 @@ export interface FromShopfrontCallbacks {
205
215
  FULFILMENT_ORDER_APPROVAL: (event: FulfilmentApprovalEvent) => MaybePromise<FromShopfrontReturns["FULFILMENT_ORDER_APPROVAL"]>;
206
216
  FULFILMENT_ORDER_COLLECTED: (id: string) => MaybePromise<FromShopfrontReturns["FULFILMENT_ORDER_COLLECTED"]>;
207
217
  FULFILMENT_ORDER_COMPLETED: (id: string) => MaybePromise<FromShopfrontReturns["FULFILMENT_ORDER_COMPLETED"]>;
218
+ GIFT_CARD_CODE_CHECK: (event: GiftCardCodeCheckEvent, context: unknown) => MaybePromise<FromShopfrontReturns["GIFT_CARD_CODE_CHECK"]>;
208
219
  }
209
220
  export interface FromShopfront {
210
221
  READY: Ready;
@@ -229,6 +240,7 @@ export interface FromShopfront {
229
240
  FULFILMENT_ORDER_APPROVAL: FulfilmentOrderApproval;
230
241
  FULFILMENT_ORDER_COLLECTED: FulfilmentCollectOrder;
231
242
  FULFILMENT_ORDER_COMPLETED: FulfilmentCompleteOrder;
243
+ GIFT_CARD_CODE_CHECK: GiftCardCodeCheck;
232
244
  }
233
245
  export declare const directShopfrontEvents: readonly ["SALE_ADD_PRODUCT", "SALE_REMOVE_PRODUCT", "SALE_UPDATE_PRODUCTS", "SALE_CHANGE_QUANTITY", "SALE_ADD_CUSTOMER", "SALE_REMOVE_CUSTOMER", "SALE_CLEAR"];
234
246
  export declare type DirectShopfrontEvent = typeof directShopfrontEvents[number];
@@ -23,6 +23,7 @@ var ToShopfront;
23
23
  ToShopfront["REDIRECT"] = "REDIRECT";
24
24
  ToShopfront["GET_OPTION"] = "GET_OPTION";
25
25
  ToShopfront["RESPONSE_UI_PIPELINE"] = "RESPONSE_UI_PIPELINE";
26
+ ToShopfront["RESPONSE_GIFT_CARD_CODE_CHECK"] = "RESPONSE_GIFT_CARD_CODE_CHECK";
26
27
  ToShopfront["REQUEST_SECURE_KEY"] = "REQUEST_SECURE_KEY";
27
28
  ToShopfront["ROTATE_SIGNING_KEY"] = "ROTATE_SIGNING_KEY";
28
29
  // Audio Events
@@ -0,0 +1,14 @@
1
+ import { BaseEvent } from "./BaseEvent";
2
+ import { FromShopfrontCallbacks, FromShopfrontReturns, CheckGiftCardCodeCollisionEvent } from "../ApplicationEvents";
3
+ import { Bridge } from "../Bridge";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class CheckGiftCardCollision extends BaseEvent<{
6
+ data: CheckGiftCardCodeCollisionEvent;
7
+ }, MaybePromise<FromShopfrontReturns["GIFT_CARD_CODE_CHECK"]>, FromShopfrontReturns["GIFT_CARD_CODE_CHECK"], CheckGiftCardCodeCollisionEvent> {
8
+ constructor(callback: FromShopfrontCallbacks["GIFT_CARD_CODE_CHECK"]);
9
+ emit(data: {
10
+ data: CheckGiftCardCodeCollisionEvent;
11
+ context: undefined;
12
+ }): Promise<FromShopfrontReturns["GIFT_CARD_CODE_CHECK"]>;
13
+ static respond(bridge: Bridge, data: FromShopfrontReturns["GIFT_CARD_CODE_CHECK"], id: string): Promise<void>;
14
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckGiftCardCollision = void 0;
4
+ const BaseEvent_1 = require("./BaseEvent");
5
+ const ApplicationEvents_1 = require("../ApplicationEvents");
6
+ class CheckGiftCardCollision extends BaseEvent_1.BaseEvent {
7
+ constructor(callback) {
8
+ super(callback);
9
+ }
10
+ async emit(data) {
11
+ console.log("About to start Emit in Bridge" + Date.now());
12
+ const result = await this.callback(data.data, data.context);
13
+ console.log("Finished Emit" + Date.now());
14
+ if (typeof result !== "object") {
15
+ throw new TypeError("Callback must return an object");
16
+ }
17
+ return result;
18
+ }
19
+ static async respond(bridge, data, id) {
20
+ console.log("About to start Response in Bridge" + Date.now());
21
+ bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_CHECK_GIFT_CODE_COLLISION, data, id);
22
+ console.log("Finished Response" + Date.now());
23
+ }
24
+ }
25
+ exports.CheckGiftCardCollision = CheckGiftCardCollision;
@@ -0,0 +1,14 @@
1
+ import { BaseEvent } from "./BaseEvent";
2
+ import { FromShopfrontCallbacks, FromShopfrontReturns, GiftCardCodeCheckEvent } from "../ApplicationEvents";
3
+ import { Bridge } from "../Bridge";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class GiftCardCodeCheck extends BaseEvent<{
6
+ data: GiftCardCodeCheckEvent;
7
+ }, MaybePromise<FromShopfrontReturns["GIFT_CARD_CODE_CHECK"]>, FromShopfrontReturns["GIFT_CARD_CODE_CHECK"], GiftCardCodeCheckEvent> {
8
+ constructor(callback: FromShopfrontCallbacks["GIFT_CARD_CODE_CHECK"]);
9
+ emit(data: {
10
+ data: GiftCardCodeCheckEvent;
11
+ context: undefined;
12
+ }): Promise<FromShopfrontReturns["GIFT_CARD_CODE_CHECK"]>;
13
+ static respond(bridge: Bridge, data: FromShopfrontReturns["GIFT_CARD_CODE_CHECK"], id: string): Promise<void>;
14
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GiftCardCodeCheck = void 0;
4
+ const BaseEvent_1 = require("./BaseEvent");
5
+ const ApplicationEvents_1 = require("../ApplicationEvents");
6
+ class GiftCardCodeCheck extends BaseEvent_1.BaseEvent {
7
+ constructor(callback) {
8
+ super(callback);
9
+ }
10
+ async emit(data) {
11
+ const result = await this.callback(data.data, data.context);
12
+ if (typeof result !== "object") {
13
+ throw new TypeError("Callback must return an object");
14
+ }
15
+ return result;
16
+ }
17
+ static async respond(bridge, data, id) {
18
+ bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_GIFT_CARD_CODE_CHECK, data, id);
19
+ }
20
+ }
21
+ exports.GiftCardCodeCheck = GiftCardCodeCheck;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.20.2",
3
+ "version": "1.20.5",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",
7
7
  "homepage": "https://developer.onshopfront.com/documentation/Embedded/Introduction",
8
- "bugs": "https://bitbucket.org/sasonline/shopfront-embedded-bridge/issues",
8
+ "bugs": "https://github.com/onshopfront/shopfront-embedded-bridge/issues",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://bitbucket.org/sasonline/shopfront-embedded-bridge.git"
11
+ "url": "https://github.com/onshopfront/shopfront-embedded-bridge.git"
12
12
  },
13
13
  "author": "Shopfront <api@shopfront.com.au> (https://shopfront.com.au)",
14
14
  "contributors": [
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="TaskProjectConfiguration">
4
- <server type="JIRA" url="https://onshopfront.atlassian.net" />
5
- </component>
6
- </project>
@@ -1,6 +0,0 @@
1
- export declare class SaleCancelledError extends Error {
2
- constructor();
3
- }
4
- export declare class InvalidSaleDeviceError extends Error {
5
- constructor();
6
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidSaleDeviceError = exports.SaleCancelledError = void 0;
4
- class SaleCancelledError extends Error {
5
- constructor() {
6
- super("The sale is no longer active.");
7
- }
8
- }
9
- exports.SaleCancelledError = SaleCancelledError;
10
- class InvalidSaleDeviceError extends Error {
11
- constructor() {
12
- super("This device is no longer a register able to perform a sale.");
13
- }
14
- }
15
- exports.InvalidSaleDeviceError = InvalidSaleDeviceError;
@@ -1,182 +0,0 @@
1
- import { Application } from "../../Application";
2
- import { ShopfrontSaleState } from "./ShopfrontSaleState";
3
- import { SaleUpdate, SaleUpdateChanges } from "../../Actions/SaleUpdate";
4
- import { SaleProduct } from "./SaleProduct";
5
- import { SalePayment } from "./SalePayment";
6
- import { SaleCustomer } from "./SaleCustomer";
7
- export declare class Sale {
8
- protected application: Application;
9
- protected sale: ShopfrontSaleState;
10
- protected cancelled: boolean;
11
- /**
12
- * Create a sale from a sale state.
13
- * It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
14
- *
15
- * @param {Application} application
16
- * @param {ShopfrontSaleState} sale
17
- */
18
- constructor(application: Application, sale: ShopfrontSaleState);
19
- /**
20
- * Get the raw state of the sale, it is highly recommend that you DO NOT use this method as the
21
- * returned data may be quite volatile.
22
- *
23
- * @internal
24
- * @returns {ShopfrontSaleState}
25
- */
26
- getRawState(): ShopfrontSaleState;
27
- /**
28
- * Update the sale to be the latest sale that exists on the sell screen.
29
- *
30
- * @returns {Promise<void>}
31
- */
32
- refreshSale(): Promise<void>;
33
- /**
34
- * Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
35
- *
36
- * @protected
37
- */
38
- protected checkIfCancelled(): void;
39
- /**
40
- * Send a sale update to Shopfront.
41
- *
42
- * @protected
43
- * @param {SaleUpdate} update
44
- * @returns {Promise<void>}
45
- */
46
- protected sendSaleUpdate(update: SaleUpdate<keyof SaleUpdateChanges>): Promise<void>;
47
- /**
48
- * Get the products that are currently on the sale.
49
- *
50
- * @returns {Array<SaleProduct>}
51
- */
52
- getProducts(): Array<SaleProduct>;
53
- /**
54
- * Get the payments that are currently on the sale.
55
- *
56
- * @returns {Array<SalePayment>}
57
- */
58
- getPayments(): Array<SalePayment>;
59
- /**
60
- * Get the current customer on the sale.
61
- *
62
- * @returns {SaleCustomer | null}
63
- */
64
- getCustomer(): null | SaleCustomer;
65
- /**
66
- * Get the external sale note (visible to the customer).
67
- *
68
- * @returns {string}
69
- */
70
- getExternalNote(): string;
71
- /**
72
- * Get the internal sale note.
73
- *
74
- * @returns {string}
75
- */
76
- getInternalNote(): string;
77
- /**
78
- * Get the order reference (visible to the customer).
79
- *
80
- * @returns {string}
81
- */
82
- getOrderReference(): string;
83
- /**
84
- * Get the current meta data for the sale
85
- *
86
- * @returns {Record<string, unknown>}
87
- */
88
- getMetaData(): Record<string, unknown>;
89
- /**
90
- * Cancel the current sale in progress.
91
- *
92
- * @returns {Promise<void>}
93
- */
94
- cancelSale(): Promise<void>;
95
- /**
96
- * Add a product to the sale.
97
- *
98
- * @param {SaleProduct} product
99
- * @returns {Promise<void>}
100
- */
101
- addProduct(product: SaleProduct): Promise<void>;
102
- /**
103
- * Remove a product from the sale.
104
- * It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
105
- *
106
- * @param {SaleProduct} product
107
- * @returns {Promise<void>}
108
- */
109
- removeProduct(product: SaleProduct): Promise<void>;
110
- /**
111
- * Add a payment to the sell screen.
112
- *
113
- * If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
114
- * user takes money from the customer).
115
- *
116
- * If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
117
- * cashout (from the payment method settings).
118
- *
119
- * @param {SalePayment} payment
120
- * @returns {Promise<void>}
121
- */
122
- addPayment(payment: SalePayment): Promise<void>;
123
- /**
124
- * Reverse a payment on the sell screen.
125
- *
126
- * This is used to issue a refund to the customer. The sale payment amount should be positive.
127
- *
128
- * @param {SalePayment} payment
129
- * @returns {Promise<void>}
130
- */
131
- reversePayment(payment: SalePayment): Promise<void>;
132
- /**
133
- * Add a customer to the sale.
134
- * If there is already a customer on the sale this will override that customer.
135
- *
136
- * @param {SaleCustomer} customer
137
- * @returns {Promise<void>}
138
- */
139
- addCustomer(customer: SaleCustomer): Promise<void>;
140
- /**
141
- * Remove the customer from the current sale.
142
- * If there is no customer currently on the sale this will be ignored.
143
- * If there are "on account" or loyalty payments still on the sale, this will be ignored.
144
- *
145
- * @returns {Promise<void>}
146
- */
147
- removeCustomer(): Promise<void>;
148
- /**
149
- * Set the external note for the sale.
150
- *
151
- * @param {string} note The note to set.
152
- * @param {boolean} append Whether to append the note to the current sale note.
153
- * @returns {Promise<void>}
154
- */
155
- setExternalNote(note: string, append?: boolean): Promise<void>;
156
- /**
157
- * Set the internal note for the sale.
158
- *
159
- * @param {string} note The note to set.
160
- * @param {boolean} append Whether to append the note to the current sale note.
161
- * @returns {Promise<void>}
162
- */
163
- setInternalNote(note: string, append?: boolean): Promise<void>;
164
- /**
165
- * Set the order reference to the provided string.
166
- *
167
- * @param {string} reference
168
- * @returns {Promise<void>}
169
- */
170
- setOrderReference(reference: string): Promise<void>;
171
- /**
172
- * Set the meta data of the sale, this will override the previous meta data.
173
- *
174
- * @param metaData
175
- */
176
- setMetaData(metaData: Record<string, unknown>): Promise<void>;
177
- /**
178
- * Update a product's details, currently this only updates the top-level meta data
179
- * @param product
180
- */
181
- updateProduct(product: SaleProduct): Promise<void>;
182
- }