@shopfront/bridge 1.18.0 → 1.18.3

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.
@@ -1,121 +1,10 @@
1
1
  <component name="ProjectCodeStyleConfiguration">
2
2
  <code_scheme name="Project" version="173">
3
- <DB2CodeStyleSettings version="6">
4
- <option name="USE_GENERAL_STYLE" value="false" />
5
- <option name="KEYWORD_CASE" value="2" />
6
- <option name="IDENTIFIER_CASE" value="1" />
7
- <option name="FROM_INDENT_JOIN" value="false" />
8
- </DB2CodeStyleSettings>
9
- <DerbyCodeStyleSettings version="6">
10
- <option name="USE_GENERAL_STYLE" value="false" />
11
- <option name="KEYWORD_CASE" value="2" />
12
- <option name="IDENTIFIER_CASE" value="1" />
13
- <option name="FROM_INDENT_JOIN" value="false" />
14
- </DerbyCodeStyleSettings>
15
- <H2CodeStyleSettings version="6">
16
- <option name="USE_GENERAL_STYLE" value="false" />
17
- <option name="KEYWORD_CASE" value="2" />
18
- <option name="IDENTIFIER_CASE" value="1" />
19
- <option name="FROM_INDENT_JOIN" value="false" />
20
- </H2CodeStyleSettings>
21
- <H2CodeStyleSettings version="6">
22
- <option name="USE_GENERAL_STYLE" value="false" />
23
- <option name="KEYWORD_CASE" value="2" />
24
- <option name="IDENTIFIER_CASE" value="1" />
25
- <option name="FROM_INDENT_JOIN" value="false" />
26
- </H2CodeStyleSettings>
27
- <HSQLCodeStyleSettings version="6">
28
- <option name="USE_GENERAL_STYLE" value="false" />
29
- <option name="KEYWORD_CASE" value="2" />
30
- <option name="IDENTIFIER_CASE" value="1" />
31
- <option name="FROM_INDENT_JOIN" value="false" />
32
- </HSQLCodeStyleSettings>
33
- <HTMLCodeStyleSettings>
34
- <option name="HTML_ATTRIBUTE_WRAP" value="4" />
35
- <option name="HTML_NEWLINE_BEFORE_FIRST_ATTRIBUTE" value="When multiline" />
36
- <option name="HTML_NEWLINE_AFTER_LAST_ATTRIBUTE" value="When multiline" />
37
- </HTMLCodeStyleSettings>
38
3
  <JSCodeStyleSettings version="0">
39
4
  <option name="FORCE_SEMICOLON_STYLE" value="true" />
40
- <option name="ALIGN_OBJECT_PROPERTIES" value="2" />
41
- <option name="ALIGN_VAR_STATEMENTS" value="2" />
42
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
43
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
44
5
  </JSCodeStyleSettings>
45
- <MSSQLCodeStyleSettings version="6">
46
- <option name="USE_GENERAL_STYLE" value="false" />
47
- <option name="KEYWORD_CASE" value="2" />
48
- <option name="IDENTIFIER_CASE" value="1" />
49
- <option name="FROM_INDENT_JOIN" value="false" />
50
- </MSSQLCodeStyleSettings>
51
- <MySQLCodeStyleSettings version="6">
52
- <option name="USE_GENERAL_STYLE" value="false" />
53
- <option name="KEYWORD_CASE" value="2" />
54
- <option name="IDENTIFIER_CASE" value="1" />
55
- <option name="FROM_INDENT_JOIN" value="false" />
56
- </MySQLCodeStyleSettings>
57
- <OracleCodeStyleSettings version="6">
58
- <option name="USE_GENERAL_STYLE" value="false" />
59
- <option name="KEYWORD_CASE" value="2" />
60
- <option name="IDENTIFIER_CASE" value="1" />
61
- <option name="FROM_INDENT_JOIN" value="false" />
62
- </OracleCodeStyleSettings>
63
- <PostgresCodeStyleSettings version="6">
64
- <option name="USE_GENERAL_STYLE" value="false" />
65
- <option name="KEYWORD_CASE" value="2" />
66
- <option name="IDENTIFIER_CASE" value="1" />
67
- <option name="FROM_INDENT_JOIN" value="false" />
68
- </PostgresCodeStyleSettings>
69
- <SQLiteCodeStyleSettings version="6">
70
- <option name="USE_GENERAL_STYLE" value="false" />
71
- <option name="KEYWORD_CASE" value="2" />
72
- <option name="IDENTIFIER_CASE" value="1" />
73
- <option name="FROM_INDENT_JOIN" value="false" />
74
- </SQLiteCodeStyleSettings>
75
- <SqlCodeStyleSettings version="6">
76
- <option name="KEYWORD_CASE" value="2" />
77
- <option name="IDENTIFIER_CASE" value="1" />
78
- <option name="FROM_INDENT_JOIN" value="false" />
79
- </SqlCodeStyleSettings>
80
- <SybaseCodeStyleSettings version="6">
81
- <option name="USE_GENERAL_STYLE" value="false" />
82
- <option name="KEYWORD_CASE" value="2" />
83
- <option name="IDENTIFIER_CASE" value="1" />
84
- <option name="FROM_INDENT_JOIN" value="false" />
85
- </SybaseCodeStyleSettings>
86
6
  <TypeScriptCodeStyleSettings version="0">
87
7
  <option name="FORCE_SEMICOLON_STYLE" value="true" />
88
- <option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
89
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
90
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
91
8
  </TypeScriptCodeStyleSettings>
92
- <codeStyleSettings language="CSS">
93
- <indentOptions>
94
- <option name="INDENT_SIZE" value="2" />
95
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
96
- <option name="TAB_SIZE" value="2" />
97
- </indentOptions>
98
- </codeStyleSettings>
99
- <codeStyleSettings language="HTML">
100
- <indentOptions>
101
- <option name="CONTINUATION_INDENT_SIZE" value="4" />
102
- </indentOptions>
103
- </codeStyleSettings>
104
- <codeStyleSettings language="JavaScript">
105
- <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
106
- </codeStyleSettings>
107
- <codeStyleSettings language="PHP">
108
- <option name="KEEP_LINE_BREAKS" value="false" />
109
- <option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
110
- <option name="CLASS_BRACE_STYLE" value="1" />
111
- <option name="METHOD_BRACE_STYLE" value="1" />
112
- <option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
113
- </codeStyleSettings>
114
- <codeStyleSettings language="SCSS">
115
- <indentOptions>
116
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
117
- <option name="TAB_SIZE" value="2" />
118
- </indentOptions>
119
- </codeStyleSettings>
120
9
  </code_scheme>
121
10
  </component>
package/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
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>
package/.idea/php.xml ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MessDetectorOptionsConfiguration">
4
+ <option name="transferred" value="true" />
5
+ </component>
6
+ <component name="PHPCSFixerOptionsConfiguration">
7
+ <option name="transferred" value="true" />
8
+ </component>
9
+ <component name="PHPCodeSnifferOptionsConfiguration">
10
+ <option name="transferred" value="true" />
11
+ </component>
12
+ <component name="PhpStanOptionsConfiguration">
13
+ <option name="transferred" value="true" />
14
+ </component>
15
+ <component name="PsalmOptionsConfiguration">
16
+ <option name="transferred" value="true" />
17
+ </component>
18
+ </project>
@@ -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>
@@ -12,6 +12,7 @@ export declare class SalePayment {
12
12
  protected amount: number;
13
13
  protected cashout?: number;
14
14
  protected rounding?: number;
15
+ protected metaData: Record<string, unknown>;
15
16
  constructor(id: string, amount: number, cashout?: number, status?: SalePaymentStatus);
16
17
  /**
17
18
  * Hydrate a sale payment from the SaleState.
@@ -66,4 +67,10 @@ export declare class SalePayment {
66
67
  * @returns {number | undefined}
67
68
  */
68
69
  getRounding(): number | undefined;
70
+ /**
71
+ * Get the metadata attached to this payment method
72
+ *
73
+ * @returns {Record<string, unknown>}
74
+ */
75
+ getMetaData(): Record<string, unknown>;
69
76
  }
@@ -13,6 +13,7 @@ var SalePaymentStatus;
13
13
  })(SalePaymentStatus = exports.SalePaymentStatus || (exports.SalePaymentStatus = {}));
14
14
  class SalePayment {
15
15
  constructor(id, amount, cashout, status) {
16
+ this.metaData = {};
16
17
  this.internalId = UUID_1.default.generate();
17
18
  this.id = id;
18
19
  this.amount = amount;
@@ -51,6 +52,7 @@ class SalePayment {
51
52
  setInternal(data) {
52
53
  this.type = data.type;
53
54
  this.rounding = data.rounding;
55
+ this.metaData = JSON.parse(data.metadata);
54
56
  }
55
57
  /**
56
58
  * Get the ID of the sale payment method.
@@ -100,5 +102,13 @@ class SalePayment {
100
102
  getRounding() {
101
103
  return this.rounding;
102
104
  }
105
+ /**
106
+ * Get the metadata attached to this payment method
107
+ *
108
+ * @returns {Record<string, unknown>}
109
+ */
110
+ getMetaData() {
111
+ return this.metaData;
112
+ }
103
113
  }
104
114
  exports.SalePayment = SalePayment;
@@ -30,6 +30,7 @@ export interface ShopfrontSalePayment {
30
30
  amount: number;
31
31
  cashout: number;
32
32
  rounding: number;
33
+ metadata: string;
33
34
  }
34
35
  export interface ShopfrontSaleState {
35
36
  clientId?: string;
@@ -18,8 +18,14 @@ export interface ShopfrontEmbeddedVerificationToken {
18
18
  loaded: string;
19
19
  };
20
20
  }
21
+ export interface ShopfrontEmbeddedTokenError {
22
+ error: boolean;
23
+ type: string;
24
+ }
21
25
  export declare class ShopfrontTokenDecodingError extends Error {
22
26
  }
27
+ export declare class ShopfrontTokenRequestError extends Error {
28
+ }
23
29
  export declare class Application {
24
30
  protected bridge: Bridge;
25
31
  protected isReady: boolean;
@@ -41,7 +47,8 @@ export declare class Application {
41
47
  protected emit(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, data: Record<string, unknown> | undefined, id: string): void | Promise<void>;
42
48
  addEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
43
49
  addEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
44
- removeEventListener(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, callback: (...args: Array<unknown>) => MaybePromise<void>): void;
50
+ removeEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
51
+ removeEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
45
52
  send(item: BaseEmitableEvent<unknown>): void;
46
53
  send(item: Serializable<unknown>): void;
47
54
  download(file: string): void;
@@ -138,6 +145,7 @@ export declare class Application {
138
145
  };
139
146
  protected generateSigningKey(): Promise<void>;
140
147
  protected decodeToken(signature: BufferSource, data: BufferSource, returnTokenObject?: boolean): Promise<ShopfrontEmbeddedVerificationToken | string>;
148
+ protected tokenDataContainsErrors(data: unknown): data is ShopfrontEmbeddedTokenError;
141
149
  getToken(returnTokenObject: true): Promise<ShopfrontEmbeddedVerificationToken>;
142
150
  getToken(returnTokenObject?: false): Promise<string>;
143
151
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Application = exports.ShopfrontTokenDecodingError = void 0;
6
+ exports.Application = exports.ShopfrontTokenRequestError = exports.ShopfrontTokenDecodingError = void 0;
7
7
  const ApplicationEvents_1 = require("./ApplicationEvents");
8
8
  const Ready_1 = require("./Events/Ready");
9
9
  const Button_1 = require("./Actions/Button");
@@ -34,6 +34,9 @@ const SaleCreate_1 = require("./Utilities/SaleCreate");
34
34
  class ShopfrontTokenDecodingError extends Error {
35
35
  }
36
36
  exports.ShopfrontTokenDecodingError = ShopfrontTokenDecodingError;
37
+ class ShopfrontTokenRequestError extends Error {
38
+ }
39
+ exports.ShopfrontTokenRequestError = ShopfrontTokenRequestError;
37
40
  // noinspection JSUnusedGlobalSymbols
38
41
  class Application {
39
42
  constructor(bridge) {
@@ -595,6 +598,12 @@ class Application {
595
598
  }
596
599
  return decoded.auth;
597
600
  }
601
+ tokenDataContainsErrors(data) {
602
+ if (!data || typeof data !== "object") {
603
+ return false;
604
+ }
605
+ return "error" in data && "type" in data;
606
+ }
598
607
  async getToken(returnTokenObject) {
599
608
  await this.generateSigningKey();
600
609
  const request = `TokenRequest-${Date.now().toString()}`;
@@ -617,7 +626,12 @@ class Application {
617
626
  this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.REQUEST_SECURE_KEY, {
618
627
  requestId: request,
619
628
  });
620
- return this.decodeToken(...(await promise), returnTokenObject);
629
+ const [signature, data] = await promise;
630
+ // Throw the error if there is one
631
+ if (this.tokenDataContainsErrors(data)) {
632
+ throw new ShopfrontTokenRequestError(data.type);
633
+ }
634
+ return this.decodeToken(signature, data, returnTokenObject);
621
635
  }
622
636
  }
623
637
  exports.Application = Application;
@@ -16,6 +16,7 @@ export interface SalePaymentData {
16
16
  status: undefined | ShopfrontSalePaymentStatus;
17
17
  rounding: number;
18
18
  cashout: number;
19
+ metaData: Record<string, unknown>;
19
20
  }
20
21
  export interface SaleData extends BaseSaleData {
21
22
  customer: null | string;
@@ -49,6 +49,7 @@ function buildSaleData(sale) {
49
49
  status: payment.getStatus(),
50
50
  rounding: payment.getRounding() || 0,
51
51
  cashout: payment.getCashout() || 0,
52
+ metaData: payment.getMetaData()
52
53
  })),
53
54
  };
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.18.0",
3
+ "version": "1.18.3",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",
@@ -1,8 +0,0 @@
1
- import { BaseEmitableEvent } from "../BaseEmitableEvent";
2
- import { FulfilmentSale } from "../../APIs/Fulfilment/FulfilmentTypes";
3
- export declare class OrderSaleCreate extends BaseEmitableEvent<{
4
- id: string;
5
- sale: FulfilmentSale;
6
- }> {
7
- constructor(id: string, sale: FulfilmentSale);
8
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrderSaleCreate = void 0;
4
- const BaseEmitableEvent_1 = require("../BaseEmitableEvent");
5
- const ApplicationEvents_1 = require("../../ApplicationEvents");
6
- class OrderSaleCreate extends BaseEmitableEvent_1.BaseEmitableEvent {
7
- constructor(id, sale) {
8
- super(ApplicationEvents_1.ToShopfront.FULFILMENT_CREATE_SALE, {
9
- id,
10
- sale,
11
- });
12
- }
13
- }
14
- exports.OrderSaleCreate = OrderSaleCreate;
@@ -1,31 +0,0 @@
1
- import { BaseEmitableEvent } from "./BaseEmitableEvent";
2
- import { BaseSaleData } from "../APIs/Sale/BaseSale";
3
- import { Sale } from "../APIs/Sale";
4
- import { ShopfrontSalePaymentStatus } from "../APIs/Sale";
5
- export interface SaleProductData {
6
- uuid: string;
7
- caseQuantity: number;
8
- quantity: number;
9
- price: number;
10
- metaData: Record<string, unknown>;
11
- products: Array<SaleProductData>;
12
- note: string;
13
- }
14
- export interface SalePaymentData {
15
- method: string;
16
- type: undefined | string;
17
- amount: number;
18
- status: undefined | ShopfrontSalePaymentStatus;
19
- rounding: number;
20
- cashout: number;
21
- }
22
- export interface SaleData extends BaseSaleData {
23
- customer: null | string;
24
- payments: Array<SalePaymentData>;
25
- products: Array<SaleProductData>;
26
- }
27
- export declare class SaleCreate extends BaseEmitableEvent<{
28
- sale: SaleData;
29
- }> {
30
- constructor(sale: Sale);
31
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SaleCreate = void 0;
4
- const BaseEmitableEvent_1 = require("./BaseEmitableEvent");
5
- const ApplicationEvents_1 = require("../ApplicationEvents");
6
- function buildSaleProductData(product) {
7
- const price = product.getPrice();
8
- if (typeof price !== "number") {
9
- throw new TypeError("Sale Product must have price when creating the sale.");
10
- }
11
- const caseQuantity = product.getCaseQuantity();
12
- if (typeof caseQuantity !== "number") {
13
- throw new TypeError("Sale Product must have case quantity when creating the sale.");
14
- }
15
- return {
16
- uuid: product.getId(),
17
- quantity: product.getQuantity(),
18
- metaData: product.getMetaData(),
19
- products: product.getContains().map(buildSaleProductData),
20
- note: product.getNote(),
21
- caseQuantity,
22
- price,
23
- };
24
- }
25
- function buildSaleData(sale) {
26
- const customer = sale.getCustomer();
27
- return {
28
- clientId: sale.getClientId(),
29
- notes: {
30
- internal: sale.getInternalNote(),
31
- sale: sale.getExternalNote(),
32
- },
33
- totals: {
34
- sale: sale.getSaleTotal(),
35
- paid: sale.getPaidTotal(),
36
- savings: sale.getSavingsTotal(),
37
- discount: sale.getDiscountTotal(),
38
- },
39
- linkedTo: sale.getLinkedTo(),
40
- orderReference: sale.getOrderReference(),
41
- refundReason: sale.getRefundReason(),
42
- priceSet: sale.getPriceSet(),
43
- metaData: sale.getMetaData(),
44
- customer: customer ? customer.getId() : null,
45
- products: sale.getProducts().map(buildSaleProductData),
46
- payments: sale.getPayments().map(payment => ({
47
- method: payment.getId(),
48
- type: payment.getType(),
49
- amount: payment.getAmount(),
50
- status: payment.getStatus(),
51
- rounding: payment.getRounding() || 0,
52
- cashout: payment.getCashout() || 0,
53
- })),
54
- };
55
- }
56
- class SaleCreate extends BaseEmitableEvent_1.BaseEmitableEvent {
57
- constructor(sale) {
58
- super(ApplicationEvents_1.ToShopfront.CREATE_SALE, {
59
- sale: buildSaleData(sale),
60
- });
61
- }
62
- }
63
- exports.SaleCreate = SaleCreate;