@shopfront/bridge 1.16.0 → 1.18.2

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.
Files changed (63) hide show
  1. package/.idea/codeStyles/Project.xml +10 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/modules.xml +1 -1
  4. package/.idea/php.xml +18 -0
  5. package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +1 -3
  6. package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +43 -0
  7. package/lib/APIs/Fulfilment/FulfilmentTypes.js +2 -0
  8. package/lib/APIs/Sale/BaseSale.d.ts +147 -0
  9. package/lib/APIs/Sale/BaseSale.js +152 -0
  10. package/lib/APIs/Sale/CurrentSale.d.ts +132 -0
  11. package/lib/APIs/Sale/CurrentSale.js +210 -0
  12. package/lib/APIs/Sale/Exceptions.d.ts +6 -0
  13. package/lib/APIs/Sale/Exceptions.js +15 -0
  14. package/lib/APIs/Sale/Sale.d.ts +34 -0
  15. package/lib/APIs/Sale/Sale.js +116 -0
  16. package/lib/APIs/Sale/SaleCustomer.d.ts +10 -0
  17. package/lib/APIs/Sale/SaleCustomer.js +17 -0
  18. package/lib/APIs/Sale/SalePayment.d.ts +76 -0
  19. package/lib/APIs/Sale/SalePayment.js +114 -0
  20. package/lib/APIs/Sale/SaleProduct.d.ts +129 -0
  21. package/lib/APIs/Sale/SaleProduct.js +181 -0
  22. package/lib/APIs/Sale/ShopfrontSaleState.d.ts +57 -0
  23. package/lib/APIs/Sale/ShopfrontSaleState.js +2 -0
  24. package/lib/APIs/Sale/index.d.ts +9 -0
  25. package/lib/APIs/Sale/index.js +39 -0
  26. package/lib/Actions/SaleUpdate.d.ts +1 -1
  27. package/lib/Application.d.ts +21 -5
  28. package/lib/Application.js +88 -4
  29. package/lib/ApplicationEvents.d.ts +50 -2
  30. package/lib/ApplicationEvents.js +11 -0
  31. package/lib/EmitableEvents/Fulfilment/Options.d.ts +7 -0
  32. package/lib/EmitableEvents/Fulfilment/Options.js +11 -0
  33. package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +6 -0
  34. package/lib/EmitableEvents/Fulfilment/OrderCancel.js +13 -0
  35. package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +7 -0
  36. package/lib/EmitableEvents/Fulfilment/OrderCreate.js +13 -0
  37. package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +7 -0
  38. package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +13 -0
  39. package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +8 -0
  40. package/lib/EmitableEvents/Fulfilment/OrdersSync.js +14 -0
  41. package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +11 -0
  42. package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +17 -0
  43. package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -0
  44. package/lib/EmitableEvents/Fulfilment/index.js +15 -0
  45. package/lib/Events/FulfilmentCollectOrder.d.ts +6 -0
  46. package/lib/Events/FulfilmentCollectOrder.js +13 -0
  47. package/lib/Events/FulfilmentCompleteOrder.d.ts +6 -0
  48. package/lib/Events/FulfilmentCompleteOrder.js +13 -0
  49. package/lib/Events/FulfilmentGetOrder.d.ts +10 -0
  50. package/lib/Events/FulfilmentGetOrder.js +17 -0
  51. package/lib/Events/FulfilmentOrderApproval.d.ts +6 -0
  52. package/lib/Events/FulfilmentOrderApproval.js +13 -0
  53. package/lib/Events/FulfilmentProcessOrder.d.ts +14 -0
  54. package/lib/Events/FulfilmentProcessOrder.js +17 -0
  55. package/lib/Events/FulfilmentVoidOrder.d.ts +6 -0
  56. package/lib/Events/FulfilmentVoidOrder.js +13 -0
  57. package/lib/Utilities/SaleCreate.d.ts +26 -0
  58. package/lib/Utilities/SaleCreate.js +56 -0
  59. package/lib/Utilities/UUID.d.ts +12 -0
  60. package/lib/Utilities/UUID.js +46 -0
  61. package/lib/index.d.ts +3 -1
  62. package/lib/index.js +3 -2
  63. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <JSCodeStyleSettings version="0">
4
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
5
+ </JSCodeStyleSettings>
6
+ <TypeScriptCodeStyleSettings version="0">
7
+ <option name="FORCE_SEMICOLON_STYLE" value="true" />
8
+ </TypeScriptCodeStyleSettings>
9
+ </code_scheme>
10
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
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 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>
@@ -0,0 +1,43 @@
1
+ export declare type OrderStatus = "PENDING_APPROVAL" | "WAITING_FOR_PACKING" | "PACKED" | "COLLECTED" | "COMPLETED";
2
+ export interface OrderSummaryDetails {
3
+ id: string;
4
+ customer: {
5
+ name: string;
6
+ phone: string;
7
+ };
8
+ courier?: {
9
+ icon?: string;
10
+ name: string;
11
+ phone: string;
12
+ };
13
+ comment?: string;
14
+ totalPrice: number;
15
+ expiry?: string | Date;
16
+ status: OrderStatus;
17
+ finalLabel?: string;
18
+ createdAt: string;
19
+ }
20
+ export declare type OrderCreateDetails = Omit<OrderSummaryDetails, "status"> & Partial<Pick<OrderSummaryDetails, "status">>;
21
+ export interface OrderDetails extends OrderSummaryDetails {
22
+ items: Array<OrderItem>;
23
+ }
24
+ export interface OrderItem {
25
+ id: string;
26
+ image?: string;
27
+ name: string;
28
+ quantity: number;
29
+ packSize: number;
30
+ price: number;
31
+ comment?: string;
32
+ match?: OrderItemMatch;
33
+ }
34
+ export interface OrderItemMatch {
35
+ id?: string;
36
+ barcodes?: Array<string>;
37
+ mdbId?: number;
38
+ supplier?: {
39
+ id?: string;
40
+ mdbId?: number;
41
+ };
42
+ supplierCodes?: Array<string>;
43
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,147 @@
1
+ import { SaleCustomer } from "./SaleCustomer";
2
+ import { SalePayment } from "./SalePayment";
3
+ import { SaleProduct } from "./SaleProduct";
4
+ export interface BaseSaleData {
5
+ register: string | undefined;
6
+ clientId: string | undefined;
7
+ notes: {
8
+ internal: string;
9
+ sale: string;
10
+ };
11
+ totals: {
12
+ sale: number;
13
+ paid: number;
14
+ savings: number;
15
+ discount: number;
16
+ };
17
+ linkedTo: string;
18
+ orderReference: string;
19
+ refundReason: string;
20
+ priceSet: string | null;
21
+ metaData: Record<string, unknown>;
22
+ }
23
+ export interface SaleData extends BaseSaleData {
24
+ customer: null | SaleCustomer;
25
+ payments: Array<SalePayment>;
26
+ products: Array<SaleProduct>;
27
+ }
28
+ export declare abstract class BaseSale {
29
+ protected sale: BaseSaleData;
30
+ protected customer: null | SaleCustomer;
31
+ protected payments: Array<SalePayment>;
32
+ protected products: Array<SaleProduct>;
33
+ protected constructor({ customer, payments, products, ...sale }: SaleData);
34
+ /**
35
+ * Updates the sale data to be inline with the new sale
36
+ *
37
+ * @param {BaseSale} sale
38
+ * @protected
39
+ */
40
+ protected hydrate(sale: BaseSale): void;
41
+ /**
42
+ * Get the products that are currently on the sale.
43
+ *
44
+ * @returns {Array<SaleProduct>}
45
+ */
46
+ getProducts(): Array<SaleProduct>;
47
+ /**
48
+ * Get the payments that are currently on the sale.
49
+ *
50
+ * @returns {Array<SalePayment>}
51
+ */
52
+ getPayments(): Array<SalePayment>;
53
+ /**
54
+ * Get the current customer on the sale.
55
+ *
56
+ * @returns {SaleCustomer | null}
57
+ */
58
+ getCustomer(): null | SaleCustomer;
59
+ /**
60
+ * Get the register.
61
+ *
62
+ * @returns {string | undefined}
63
+ */
64
+ getRegister(): string | undefined;
65
+ /**
66
+ * Get the client id.
67
+ *
68
+ * @returns {string | null}
69
+ */
70
+ getClientId(): string | undefined;
71
+ /**
72
+ * Get the current sale total on the sale.
73
+ *
74
+ * @returns {number}
75
+ */
76
+ getSaleTotal(): number;
77
+ /**
78
+ * Get the current paid total on the sale.
79
+ *
80
+ * @returns {number}
81
+ */
82
+ getPaidTotal(): number;
83
+ /**
84
+ * Get the current savings total on the sale.
85
+ *
86
+ * @returns {number}
87
+ */
88
+ getSavingsTotal(): number;
89
+ /**
90
+ * Get the current discount total on the sale.
91
+ *
92
+ * @returns {number}
93
+ */
94
+ getDiscountTotal(): number;
95
+ /**
96
+ * Get the linked to value on the sale.
97
+ *
98
+ * @returns {string}
99
+ */
100
+ getLinkedTo(): string;
101
+ /**
102
+ * Get the refund reason on the sale.
103
+ *
104
+ * @returns {string}
105
+ */
106
+ getRefundReason(): string;
107
+ /**
108
+ * Get the price set on the sale.
109
+ *
110
+ * @returns {string | null}
111
+ */
112
+ getPriceSet(): string | null;
113
+ /**
114
+ * Get the external sale note (visible to the customer).
115
+ *
116
+ * @returns {string}
117
+ */
118
+ getExternalNote(): string;
119
+ /**
120
+ * Get the internal sale note.
121
+ *
122
+ * @returns {string}
123
+ */
124
+ getInternalNote(): string;
125
+ /**
126
+ * Get the order reference (visible to the customer).
127
+ *
128
+ * @returns {string}
129
+ */
130
+ getOrderReference(): string;
131
+ /**
132
+ * Get the current meta data for the sale
133
+ *
134
+ * @returns {Record<string, unknown>}
135
+ */
136
+ getMetaData(): Record<string, unknown>;
137
+ abstract addProduct(product: SaleProduct): Promise<void>;
138
+ abstract removeProduct(product: SaleProduct): Promise<void>;
139
+ abstract addPayment(payment: SalePayment): Promise<void>;
140
+ abstract addCustomer(customer: SaleCustomer): Promise<void>;
141
+ abstract removeCustomer(): Promise<void>;
142
+ abstract setExternalNote(note: string, append?: boolean): Promise<void>;
143
+ abstract setInternalNote(note: string, append?: boolean): Promise<void>;
144
+ abstract setOrderReference(reference: string): Promise<void>;
145
+ abstract setMetaData(metaData: Record<string, unknown>): Promise<void>;
146
+ abstract updateProduct(product: SaleProduct): Promise<void>;
147
+ }
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSale = void 0;
4
+ class BaseSale {
5
+ constructor({ customer, payments, products, ...sale }) {
6
+ this.sale = sale;
7
+ this.customer = customer;
8
+ this.payments = payments;
9
+ this.products = products;
10
+ }
11
+ /**
12
+ * Updates the sale data to be inline with the new sale
13
+ *
14
+ * @param {BaseSale} sale
15
+ * @protected
16
+ */
17
+ hydrate(sale) {
18
+ this.sale = sale.sale;
19
+ this.customer = sale.customer;
20
+ this.payments = sale.payments;
21
+ this.products = sale.products;
22
+ }
23
+ /**
24
+ * Get the products that are currently on the sale.
25
+ *
26
+ * @returns {Array<SaleProduct>}
27
+ */
28
+ getProducts() {
29
+ return this.products;
30
+ }
31
+ /**
32
+ * Get the payments that are currently on the sale.
33
+ *
34
+ * @returns {Array<SalePayment>}
35
+ */
36
+ getPayments() {
37
+ return this.payments;
38
+ }
39
+ /**
40
+ * Get the current customer on the sale.
41
+ *
42
+ * @returns {SaleCustomer | null}
43
+ */
44
+ getCustomer() {
45
+ return this.customer;
46
+ }
47
+ /**
48
+ * Get the register.
49
+ *
50
+ * @returns {string | undefined}
51
+ */
52
+ getRegister() {
53
+ return this.sale.register;
54
+ }
55
+ /**
56
+ * Get the client id.
57
+ *
58
+ * @returns {string | null}
59
+ */
60
+ getClientId() {
61
+ return this.sale.clientId;
62
+ }
63
+ /**
64
+ * Get the current sale total on the sale.
65
+ *
66
+ * @returns {number}
67
+ */
68
+ getSaleTotal() {
69
+ return this.sale.totals.sale;
70
+ }
71
+ /**
72
+ * Get the current paid total on the sale.
73
+ *
74
+ * @returns {number}
75
+ */
76
+ getPaidTotal() {
77
+ return this.sale.totals.paid;
78
+ }
79
+ /**
80
+ * Get the current savings total on the sale.
81
+ *
82
+ * @returns {number}
83
+ */
84
+ getSavingsTotal() {
85
+ return this.sale.totals.savings;
86
+ }
87
+ /**
88
+ * Get the current discount total on the sale.
89
+ *
90
+ * @returns {number}
91
+ */
92
+ getDiscountTotal() {
93
+ return this.sale.totals.discount;
94
+ }
95
+ /**
96
+ * Get the linked to value on the sale.
97
+ *
98
+ * @returns {string}
99
+ */
100
+ getLinkedTo() {
101
+ return this.sale.linkedTo;
102
+ }
103
+ /**
104
+ * Get the refund reason on the sale.
105
+ *
106
+ * @returns {string}
107
+ */
108
+ getRefundReason() {
109
+ return this.sale.refundReason;
110
+ }
111
+ /**
112
+ * Get the price set on the sale.
113
+ *
114
+ * @returns {string | null}
115
+ */
116
+ getPriceSet() {
117
+ return this.sale.priceSet;
118
+ }
119
+ /**
120
+ * Get the external sale note (visible to the customer).
121
+ *
122
+ * @returns {string}
123
+ */
124
+ getExternalNote() {
125
+ return this.sale.notes.sale;
126
+ }
127
+ /**
128
+ * Get the internal sale note.
129
+ *
130
+ * @returns {string}
131
+ */
132
+ getInternalNote() {
133
+ return this.sale.notes.internal;
134
+ }
135
+ /**
136
+ * Get the order reference (visible to the customer).
137
+ *
138
+ * @returns {string}
139
+ */
140
+ getOrderReference() {
141
+ return this.sale.orderReference;
142
+ }
143
+ /**
144
+ * Get the current meta data for the sale
145
+ *
146
+ * @returns {Record<string, unknown>}
147
+ */
148
+ getMetaData() {
149
+ return this.sale.metaData;
150
+ }
151
+ }
152
+ exports.BaseSale = BaseSale;
@@ -0,0 +1,132 @@
1
+ import { BaseSale } from "./BaseSale";
2
+ import { ShopfrontSaleState } from "./ShopfrontSaleState";
3
+ import { SalePayment } from "./SalePayment";
4
+ import { SaleProduct } from "./SaleProduct";
5
+ import { SaleCustomer } from "./SaleCustomer";
6
+ import { Application } from "../../Application";
7
+ import { SaleUpdate, SaleUpdateChanges } from "../../Actions/SaleUpdate";
8
+ export declare class CurrentSale extends BaseSale {
9
+ protected application: Application;
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} saleState
17
+ */
18
+ constructor(application: Application, saleState: ShopfrontSaleState);
19
+ /**
20
+ * Update the sale to be the latest sale that exists on the sell screen.
21
+ *
22
+ * @returns {Promise<void>}
23
+ */
24
+ refreshSale(): Promise<void>;
25
+ /**
26
+ * Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
27
+ *
28
+ * @protected
29
+ */
30
+ protected checkIfCancelled(): void;
31
+ /**
32
+ * Send a sale update to Shopfront.
33
+ *
34
+ * @protected
35
+ * @param {SaleUpdate} update
36
+ * @returns {Promise<void>}
37
+ */
38
+ protected sendSaleUpdate(update: SaleUpdate<keyof SaleUpdateChanges>): Promise<void>;
39
+ /**
40
+ * Cancel the current sale in progress.
41
+ *
42
+ * @returns {Promise<void>}
43
+ */
44
+ cancelSale(): Promise<void>;
45
+ /**
46
+ * Add a product to the sale.
47
+ *
48
+ * @param {SaleProduct} product
49
+ * @returns {Promise<void>}
50
+ */
51
+ addProduct(product: SaleProduct): Promise<void>;
52
+ /**
53
+ * Remove a product from the sale.
54
+ * It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
55
+ *
56
+ * @param {SaleProduct} product
57
+ * @returns {Promise<void>}
58
+ */
59
+ removeProduct(product: SaleProduct): Promise<void>;
60
+ /**
61
+ * Add a payment to the sell screen.
62
+ *
63
+ * If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
64
+ * user takes money from the customer).
65
+ *
66
+ * If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
67
+ * cashout (from the payment method settings).
68
+ *
69
+ * @param {SalePayment} payment
70
+ * @returns {Promise<void>}
71
+ */
72
+ addPayment(payment: SalePayment): Promise<void>;
73
+ /**
74
+ * Reverse a payment on the sell screen.
75
+ *
76
+ * This is used to issue a refund to the customer. The sale payment amount should be positive.
77
+ *
78
+ * @param {SalePayment} payment
79
+ * @returns {Promise<void>}
80
+ */
81
+ reversePayment(payment: SalePayment): Promise<void>;
82
+ /**
83
+ * Add a customer to the sale.
84
+ * If there is already a customer on the sale this will override that customer.
85
+ *
86
+ * @param {SaleCustomer} customer
87
+ * @returns {Promise<void>}
88
+ */
89
+ addCustomer(customer: SaleCustomer): Promise<void>;
90
+ /**
91
+ * Remove the customer from the current sale.
92
+ * If there is no customer currently on the sale this will be ignored.
93
+ * If there are "on account" or loyalty payments still on the sale, this will be ignored.
94
+ *
95
+ * @returns {Promise<void>}
96
+ */
97
+ removeCustomer(): Promise<void>;
98
+ /**
99
+ * Set the external note for the sale.
100
+ *
101
+ * @param {string} note The note to set.
102
+ * @param {boolean} append Whether to append the note to the current sale note.
103
+ * @returns {Promise<void>}
104
+ */
105
+ setExternalNote(note: string, append?: boolean): Promise<void>;
106
+ /**
107
+ * Set the internal note for the sale.
108
+ *
109
+ * @param {string} note The note to set.
110
+ * @param {boolean} append Whether to append the note to the current sale note.
111
+ * @returns {Promise<void>}
112
+ */
113
+ setInternalNote(note: string, append?: boolean): Promise<void>;
114
+ /**
115
+ * Set the order reference to the provided string.
116
+ *
117
+ * @param {string} reference
118
+ * @returns {Promise<void>}
119
+ */
120
+ setOrderReference(reference: string): Promise<void>;
121
+ /**
122
+ * Set the meta data of the sale, this will override the previous meta data.
123
+ *
124
+ * @param metaData
125
+ */
126
+ setMetaData(metaData: Record<string, unknown>): Promise<void>;
127
+ /**
128
+ * Update a product's details, currently this only updates the top-level meta data
129
+ * @param product
130
+ */
131
+ updateProduct(product: SaleProduct): Promise<void>;
132
+ }