@myparcel-dev/pdk-checkout-common 1.7.0
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.
- package/CHANGELOG.md +122 -0
- package/dist/__tests__/constants.d.ts +15 -0
- package/dist/__tests__/getMockCheckoutContext.d.ts +2 -0
- package/dist/__tests__/getMockDeliveryOptionsConfig.d.ts +2 -0
- package/dist/__tests__/getMockFormData.d.ts +3 -0
- package/dist/__tests__/getMockPdkCheckoutConfig.d.ts +2 -0
- package/dist/__tests__/index.d.ts +9 -0
- package/dist/__tests__/mockDeliveryOptionsElement.d.ts +1 -0
- package/dist/__tests__/mockPdkCheckout.d.ts +2 -0
- package/dist/__tests__/mockShippingMethod.d.ts +1 -0
- package/dist/__tests__/spies.d.ts +7 -0
- package/dist/constants.d.ts +1 -0
- package/dist/createPdkCheckout.d.ts +2 -0
- package/dist/data/address.d.ts +15 -0
- package/dist/data/events.d.ts +20 -0
- package/dist/data/index.d.ts +4 -0
- package/dist/data/store.d.ts +3 -0
- package/dist/data/utils.d.ts +13 -0
- package/dist/defaults/defaultFormChange.d.ts +1 -0
- package/dist/defaults/defaultGetAddressType.d.ts +2 -0
- package/dist/defaults/defaultGetFormData.d.ts +3 -0
- package/dist/defaults/defaultHasDeliveryOptions.d.ts +1 -0
- package/dist/defaults/index.d.ts +4 -0
- package/dist/globals.d.ts +13 -0
- package/dist/index.d.ts +11 -0
- package/dist/init/addFormListeners.d.ts +1 -0
- package/dist/init/createConfig.d.ts +2 -0
- package/dist/init/index.d.ts +4 -0
- package/dist/init/initializeCheckoutStore.d.ts +1 -0
- package/dist/init/setupGlobals.d.ts +2 -0
- package/dist/listeners/index.d.ts +2 -0
- package/dist/listeners/updateAddressType.d.ts +2 -0
- package/dist/listeners/updateCheckoutForm.d.ts +1 -0
- package/dist/store/createCheckoutStore.d.ts +2 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/logStoreDebugInfo.d.ts +3 -0
- package/dist/store/realCreateStore.d.ts +3 -0
- package/dist/types/address.types.d.ts +2 -0
- package/dist/types/checkout.types.d.ts +70 -0
- package/dist/types/endpoints.types.d.ts +20 -0
- package/dist/types/global.types.d.ts +42 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/store.types.d.ts +34 -0
- package/dist/utils/getEnabledShippingMethods.d.ts +1 -0
- package/dist/utils/getFrontendContext.d.ts +2 -0
- package/dist/utils/global/doRequest.d.ts +5 -0
- package/dist/utils/global/fieldsEqual.d.ts +8 -0
- package/dist/utils/global/getAddressField.d.ts +5 -0
- package/dist/utils/global/getAddressFieldValue.d.ts +2 -0
- package/dist/utils/global/getAddressType.d.ts +2 -0
- package/dist/utils/global/getElement.d.ts +1 -0
- package/dist/utils/global/getFieldValue.d.ts +8 -0
- package/dist/utils/global/index.d.ts +9 -0
- package/dist/utils/global/setFieldValue.d.ts +2 -0
- package/dist/utils/global/triggerEvent.d.ts +4 -0
- package/dist/utils/hasAddressType.d.ts +2 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/realUseUtil.d.ts +2 -0
- package/dist/utils/useCheckoutStore.d.ts +1 -0
- package/dist/utils/useConfig.d.ts +1 -0
- package/dist/utils/useEvent.d.ts +3 -0
- package/dist/utils/usePdkCheckout.d.ts +2 -0
- package/dist/utils/useSettings.d.ts +2 -0
- package/dist/utils/useUtil.d.ts +2 -0
- package/package.json +50 -0
- package/src/__tests__/__snapshots__/exports.spec.ts.snap +62 -0
- package/src/__tests__/constants.ts +17 -0
- package/src/__tests__/exports.spec.ts +8 -0
- package/src/__tests__/getMockCheckoutContext.ts +44 -0
- package/src/__tests__/getMockDeliveryOptionsConfig.ts +27 -0
- package/src/__tests__/getMockFormData.ts +29 -0
- package/src/__tests__/getMockPdkCheckoutConfig.ts +46 -0
- package/src/__tests__/index.ts +9 -0
- package/src/__tests__/mockDeliveryOptionsElement.ts +20 -0
- package/src/__tests__/mockPdkCheckout.ts +32 -0
- package/src/__tests__/mockShippingMethod.ts +8 -0
- package/src/__tests__/spies.ts +16 -0
- package/src/constants.ts +1 -0
- package/src/createPdkCheckout.ts +32 -0
- package/src/data/address.ts +17 -0
- package/src/data/events.ts +38 -0
- package/src/data/index.ts +4 -0
- package/src/data/store.ts +3 -0
- package/src/data/utils.ts +13 -0
- package/src/defaults/defaultFormChange.ts +9 -0
- package/src/defaults/defaultGetAddressType.ts +4 -0
- package/src/defaults/defaultGetFormData.ts +11 -0
- package/src/defaults/defaultHasDeliveryOptions.ts +8 -0
- package/src/defaults/index.ts +4 -0
- package/src/globals.ts +18 -0
- package/src/index.ts +11 -0
- package/src/init/addFormListeners.ts +10 -0
- package/src/init/createConfig.ts +15 -0
- package/src/init/index.ts +4 -0
- package/src/init/initializeCheckoutStore.ts +5 -0
- package/src/init/setupGlobals.ts +75 -0
- package/src/listeners/index.ts +2 -0
- package/src/listeners/updateAddressType.ts +13 -0
- package/src/listeners/updateCheckoutForm.ts +38 -0
- package/src/store/createCheckoutStore.ts +27 -0
- package/src/store/index.ts +3 -0
- package/src/store/logStoreDebugInfo.ts +19 -0
- package/src/store/realCreateStore.ts +64 -0
- package/src/types/address.types.ts +3 -0
- package/src/types/checkout.types.ts +89 -0
- package/src/types/endpoints.types.ts +31 -0
- package/src/types/global.types.ts +56 -0
- package/src/types/index.ts +5 -0
- package/src/types/store.types.ts +43 -0
- package/src/utils/getEnabledShippingMethods.ts +9 -0
- package/src/utils/getFrontendContext.ts +22 -0
- package/src/utils/global/doRequest.spec.ts +18 -0
- package/src/utils/global/doRequest.ts +25 -0
- package/src/utils/global/fieldsEqual.spec.ts +83 -0
- package/src/utils/global/fieldsEqual.ts +29 -0
- package/src/utils/global/getAddressField.ts +20 -0
- package/src/utils/global/getAddressFieldValue.ts +6 -0
- package/src/utils/global/getAddressType.ts +10 -0
- package/src/utils/global/getElement.spec.ts +28 -0
- package/src/utils/global/getElement.ts +10 -0
- package/src/utils/global/getFieldValue.ts +24 -0
- package/src/utils/global/index.ts +9 -0
- package/src/utils/global/setFieldValue.ts +24 -0
- package/src/utils/global/triggerEvent.spec.ts +29 -0
- package/src/utils/global/triggerEvent.ts +23 -0
- package/src/utils/hasAddressType.spec.ts +22 -0
- package/src/utils/hasAddressType.ts +8 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/realUseUtil.ts +11 -0
- package/src/utils/useCheckoutStore.ts +2 -0
- package/src/utils/useConfig.ts +2 -0
- package/src/utils/useEvent.ts +9 -0
- package/src/utils/usePdkCheckout.ts +5 -0
- package/src/utils/useSettings.ts +5 -0
- package/src/utils/useUtil.ts +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!-- MONOWEAVE:BELOW -->
|
|
4
|
+
|
|
5
|
+
## [1.7.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-dev/pdk-checkout-common@1.6.0...@myparcel-dev/pdk-checkout-common@1.7.0) "@myparcel-dev/pdk-checkout-common" (2025-12-23)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* migrate to [@myparcel-dev](https://github.com/myparcel-dev) scope ([#289](https://github.com/myparcelnl/js-pdk/issues/289)) ([ca169be](https://github.com/myparcelnl/js-pdk/commit/ca169bec42dcf7174ce20b1bfb392ae620b6c7fd))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [1.6.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.5.0...@myparcel-pdk/checkout-common@1.6.0) "@myparcel-pdk/checkout-common" (2025-11-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## [1.3.3](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.3.2...@myparcel-pdk/checkout-common@1.3.3) "@myparcel-pdk/checkout-common" (2025-06-16)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **checkout:** fix pdk checkout form type to allow additional fields ([#234](https://github.com/myparcelnl/js-pdk/issues/234)) ([78a9f3c](https://github.com/myparcelnl/js-pdk/commit/78a9f3cdcd1cdcfbc847b2a3de92f198def9c9d9))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [1.1.5](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.1.3...@myparcel-pdk/checkout-common@1.1.5) "@myparcel-pdk/checkout-common" (2024-10-24)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## [1.1.3](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.1.2...@myparcel-pdk/checkout-common@1.1.3) "@myparcel-pdk/checkout-common" (2024-10-24)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## [1.1.1](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.1.0...@myparcel-pdk/checkout-common@1.1.1) "@myparcel-pdk/checkout-common" (2024-10-04)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## [1.1.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.3...@myparcel-pdk/checkout-common@1.1.0) "@myparcel-pdk/checkout-common" (2024-09-26)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* **checkout:** improve shipping logic and expose default methods ([#216](https://github.com/myparcelnl/js-pdk/issues/216)) ([e860ba2](https://github.com/myparcelnl/js-pdk/commit/e860ba2bf14dc3dbffd7fb599bad514087c4667e))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## [1.0.3](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.2...@myparcel-pdk/checkout-common@1.0.3) "@myparcel-pdk/checkout-common" (2024-07-04)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## [1.0.2](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.1...@myparcel-pdk/checkout-common@1.0.2) "@myparcel-pdk/checkout-common" (2024-07-03)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Bug Fixes
|
|
64
|
+
|
|
65
|
+
* **checkout:** correctly switch package type based on shipping methods ([#212](https://github.com/myparcelnl/js-pdk/issues/212)) ([f25ebed](https://github.com/myparcelnl/js-pdk/commit/f25ebedbb0f6e9d5601af3d4c46f995fc08019ef))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## [1.0.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.1...@myparcel-pdk/checkout-common@1.0.0) "@myparcel-pdk/checkout-common" (2024-04-11)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### ⚠ BREAKING CHANGES
|
|
74
|
+
|
|
75
|
+
* update node requirement to 20
|
|
76
|
+
|
|
77
|
+
### Miscellaneous Chores
|
|
78
|
+
|
|
79
|
+
* update node requirement to 20 ([e3f867f](https://github.com/myparcelnl/js-pdk/commit/e3f867fd3e19245154748a6858dbad4b56673fa3))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## [1.0.0-beta.3](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-beta.2...@myparcel-pdk/checkout-common@1.0.0-beta.3) "@myparcel-pdk/checkout-common" (2024-03-14)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Features
|
|
88
|
+
|
|
89
|
+
* **deps:** upgrade to new delivery options ([28c6c22](https://github.com/myparcelnl/js-pdk/commit/28c6c22fc2e13a3fe422a63e023b0b78b7637dd3))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## [1.0.0-beta.1](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-beta.0...@myparcel-pdk/checkout-common@1.0.0-beta.1) "@myparcel-pdk/checkout-common" (2024-03-13)
|
|
95
|
+
|
|
96
|
+
### Features
|
|
97
|
+
|
|
98
|
+
- **deps:** upgrade to new delivery options ([28c6c22](https://github.com/myparcelnl/js-pdk/commit/28c6c22fc2e13a3fe422a63e023b0b78b7637dd3))
|
|
99
|
+
|
|
100
|
+
## [1.0.0-beta.0](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.1...@myparcel-pdk/checkout-common@1.0.0-beta.0) "@myparcel-pdk/checkout-common" (2024-03-06)
|
|
101
|
+
|
|
102
|
+
### Features
|
|
103
|
+
|
|
104
|
+
- update @myparcelnl/constants to v2.0.0 ([022c980](https://github.com/myparcelnl/js-pdk/commit/022c980950dd37b6e750c04f65e57c6435f01279))
|
|
105
|
+
|
|
106
|
+
## [1.0.0-alpha.9](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.8...@myparcel-pdk/checkout-common@1.0.0-alpha.9) "@myparcel-pdk/checkout-common" (2023-11-02)
|
|
107
|
+
|
|
108
|
+
## [1.0.0-alpha.6](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.5...@myparcel-pdk/checkout-common@1.0.0-alpha.6) "@myparcel-pdk/checkout-common" (2023-10-13)
|
|
109
|
+
|
|
110
|
+
## [1.0.0-alpha.5](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.4...@myparcel-pdk/checkout-common@1.0.0-alpha.5) "@myparcel-pdk/checkout-common" (2023-10-09)
|
|
111
|
+
|
|
112
|
+
### Bug Fixes
|
|
113
|
+
|
|
114
|
+
- **checkout:** include address2 in delivery options ([#195](https://github.com/myparcelnl/js-pdk/issues/195)) ([b9590f4](https://github.com/myparcelnl/js-pdk/commit/b9590f4603054e08190c3b8befb0f184a375fc8e))
|
|
115
|
+
|
|
116
|
+
## [1.0.0-alpha.4](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.3...@myparcel-pdk/checkout-common@1.0.0-alpha.4) "@myparcel-pdk/checkout-common" (2023-10-03)
|
|
117
|
+
|
|
118
|
+
### Bug Fixes
|
|
119
|
+
|
|
120
|
+
- **checkout:** export more values ([cc6721f](https://github.com/myparcelnl/js-pdk/commit/cc6721fb9a6f3552c0ab406959860c313de1adde))
|
|
121
|
+
|
|
122
|
+
## [1.0.0-alpha.1](https://github.com/myparcelnl/js-pdk/compare/@myparcel-pdk/checkout-common@1.0.0-alpha.0...@myparcel-pdk/checkout-common@1.0.0-alpha.1) "@myparcel-pdk/checkout-common" (2023-09-06)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AddressType } from '../data';
|
|
2
|
+
export declare const DEFAULT_MOCK_FORM_DATA: Readonly<{
|
|
3
|
+
'address-type': AddressType;
|
|
4
|
+
'b-address1': string;
|
|
5
|
+
'b-address2': string;
|
|
6
|
+
'b-city': string;
|
|
7
|
+
'b-country': string;
|
|
8
|
+
'b-postal-code': string;
|
|
9
|
+
's-address1': string;
|
|
10
|
+
's-address2': string;
|
|
11
|
+
's-city': string;
|
|
12
|
+
's-country': string;
|
|
13
|
+
's-postal-code': string;
|
|
14
|
+
'shipping-method': string;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './getMockCheckoutContext';
|
|
3
|
+
export * from './getMockDeliveryOptionsConfig';
|
|
4
|
+
export * from './getMockFormData';
|
|
5
|
+
export * from './getMockPdkCheckoutConfig';
|
|
6
|
+
export * from './mockDeliveryOptionsElement';
|
|
7
|
+
export * from './mockPdkCheckout';
|
|
8
|
+
export * from './mockShippingMethod';
|
|
9
|
+
export * from './spies';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mockDeliveryOptionsElement: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mockShippingMethod: (shippingMethod: string) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PdkFormData } from '../types';
|
|
2
|
+
export declare const doRequestSpy: import("vitest").Mock<(...args: any[]) => any>;
|
|
3
|
+
export declare const getFormSpy: import("vitest").Mock<() => HTMLFormElement>;
|
|
4
|
+
export declare const getFormDataSpy: import("vitest").Mock<() => PdkFormData>;
|
|
5
|
+
export declare const hasAddressTypeSpy: import("vitest").Mock<() => boolean>;
|
|
6
|
+
export declare const initializeSpy: import("vitest").Mock<() => Promise<void>>;
|
|
7
|
+
export declare const toggleFieldSpy: import("vitest").Mock<(...args: any[]) => any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ATTRIBUTE_CONTEXT = "data-context";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum AddressType {
|
|
2
|
+
Billing = "billing",
|
|
3
|
+
Shipping = "shipping"
|
|
4
|
+
}
|
|
5
|
+
export declare enum AddressField {
|
|
6
|
+
Address1 = "address1",
|
|
7
|
+
Address2 = "address2",
|
|
8
|
+
City = "city",
|
|
9
|
+
Country = "country",
|
|
10
|
+
PostalCode = "postalCode"
|
|
11
|
+
}
|
|
12
|
+
export declare enum PdkField {
|
|
13
|
+
AddressType = "addressType",
|
|
14
|
+
ShippingMethod = "shippingMethod"
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum PdkEvent {
|
|
2
|
+
CheckoutUpdate = "checkoutUpdate",
|
|
3
|
+
CheckoutUpdated = "checkoutUpdated",
|
|
4
|
+
StoreInitialize = "storeInitialize",
|
|
5
|
+
StoreInitialized = "storeInitialized"
|
|
6
|
+
}
|
|
7
|
+
export declare const EVENT_STORE = "store";
|
|
8
|
+
export declare const EVENT_DELIVERY_OPTIONS = "deliveryOptions";
|
|
9
|
+
export declare const EVENT_CHECKOUT = "checkout";
|
|
10
|
+
export declare const EVENT_PDK = "pdk";
|
|
11
|
+
export declare const EVENT_TYPE_INITIALIZE = "initialize";
|
|
12
|
+
export declare const EVENT_TYPE_INITIALIZED = "initialized";
|
|
13
|
+
export declare const EVENT_TYPE_SYNCHRONIZE = "synchronize";
|
|
14
|
+
export declare const EVENT_TYPE_SYNCHRONIZED = "synchronized";
|
|
15
|
+
export declare const EVENT_TYPE_UPDATE = "update";
|
|
16
|
+
export declare const EVENT_TYPE_UPDATED = "updated";
|
|
17
|
+
export declare const createEventName: (...names: string[]) => string;
|
|
18
|
+
export declare const eventCheckoutUpdate: string;
|
|
19
|
+
export declare const eventCheckoutUpdated: string;
|
|
20
|
+
export declare const eventStoreInitialize: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum PdkUtil {
|
|
2
|
+
CreateStore = "createStore",
|
|
3
|
+
DoRequest = "doRequest",
|
|
4
|
+
FieldsEqual = "fieldsEqual",
|
|
5
|
+
GetAddressField = "getAddressField",
|
|
6
|
+
GetAddressFieldValue = "getAddressFieldValue",
|
|
7
|
+
GetElement = "getElement",
|
|
8
|
+
GetFieldValue = "getFieldValue",
|
|
9
|
+
IsEnumValue = "isEnumValue",
|
|
10
|
+
IsOfType = "isOfType",
|
|
11
|
+
SetFieldValue = "setFieldValue",
|
|
12
|
+
TriggerEvent = "triggerEvent"
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const defaultFormChange: (callback: () => void) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const defaultHasDeliveryOptions: (shippingMethod: string) => boolean;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * as tests from './__tests__';
|
|
2
|
+
export * from './constants';
|
|
3
|
+
export * from './createPdkCheckout';
|
|
4
|
+
export * from './data';
|
|
5
|
+
export * from './defaults';
|
|
6
|
+
export * as globals from './globals';
|
|
7
|
+
export * from './init';
|
|
8
|
+
export * from './listeners';
|
|
9
|
+
export * from './store';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addFormListeners: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initializeCheckoutStore: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const updateCheckoutForm: () => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Keyable } from '@myparcel-dev/pdk-common';
|
|
2
|
+
import { type InitialStoreData, type StoreData, type StoreState } from '../types';
|
|
3
|
+
export declare const realCreateStore: <S extends StoreState = StoreState, N extends Keyable = Keyable>(name: N, initialData: () => InitialStoreData<S>) => (() => StoreData<S, N>[N]);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type FrontendEndpoint } from '@myparcel-dev/pdk-common';
|
|
2
|
+
import { type PromiseOr } from '@myparcel-dev/ts-utils';
|
|
3
|
+
import { type AddressType, type PdkField } from '../data';
|
|
4
|
+
import { type FrontendEndpointData, type FrontendEndpointResponse } from './endpoints.types';
|
|
5
|
+
import { type AddressFields } from './address.types';
|
|
6
|
+
export type PdkFormData = Record<string, FormDataEntryValue | undefined>;
|
|
7
|
+
export type PdkCheckoutConfigInput = Omit<PdkCheckoutConfig, 'selectors' | 'formChange' | 'getFormData' | 'getAddressType' | 'hasDeliveryOptions'> & {
|
|
8
|
+
formChange?(callback: () => void): void;
|
|
9
|
+
getAddressType?(value: unknown): AddressType;
|
|
10
|
+
getFormData?(): PdkFormData;
|
|
11
|
+
hasDeliveryOptions?(shippingMethod: string): PromiseOr<boolean>;
|
|
12
|
+
selectors: Omit<PdkCheckoutConfig['selectors'], 'deliveryOptions'> & {
|
|
13
|
+
deliveryOptions?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Includes our own address fields, and any additional fields described by optional packages.
|
|
18
|
+
*/
|
|
19
|
+
export type PdkCheckoutForm = Record<PdkField, string> & {
|
|
20
|
+
[AddressType.Billing]: AddressFields & Record<string, string>;
|
|
21
|
+
[AddressType.Shipping]: AddressFields & Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
export interface PdkCheckoutConfig {
|
|
24
|
+
fields: PdkCheckoutForm;
|
|
25
|
+
formData: PdkCheckoutForm;
|
|
26
|
+
selectors: {
|
|
27
|
+
deliveryOptions: string;
|
|
28
|
+
deliveryOptionsWrapper: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Do a request to the backend.
|
|
32
|
+
*/
|
|
33
|
+
doRequest<E extends FrontendEndpoint>(endpoint: FrontendEndpointData<E>): Promise<FrontendEndpointResponse<E>>;
|
|
34
|
+
/**
|
|
35
|
+
* The handler for the form change event.
|
|
36
|
+
*/
|
|
37
|
+
formChange(callback: () => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get the address type that is currently active.
|
|
40
|
+
*/
|
|
41
|
+
getAddressType(value: unknown): AddressType;
|
|
42
|
+
/**
|
|
43
|
+
* Get the form element.
|
|
44
|
+
*/
|
|
45
|
+
getForm(): HTMLFormElement;
|
|
46
|
+
/**
|
|
47
|
+
* Get the form data.
|
|
48
|
+
*/
|
|
49
|
+
getFormData(): PdkFormData;
|
|
50
|
+
/**
|
|
51
|
+
* Check if the address type is available.
|
|
52
|
+
*/
|
|
53
|
+
hasAddressType(addressType: AddressType): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if the delivery options are available for the shipping method.
|
|
56
|
+
*/
|
|
57
|
+
hasDeliveryOptions(shippingMethod: string): PromiseOr<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Callback that is called when the checkout is initialized.
|
|
60
|
+
*/
|
|
61
|
+
initialize(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Toggle showing/hiding a field.
|
|
64
|
+
*/
|
|
65
|
+
toggleField(field: HTMLInputElement, show: boolean): void;
|
|
66
|
+
}
|
|
67
|
+
export type InitializeCallback = () => void;
|
|
68
|
+
export interface PdkCheckout {
|
|
69
|
+
onInitialize(callback: InitializeCallback): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type EndpointObject, type FrontendEndpoint, type PdkEndpointDefinition, type PdkEndpointParameters, type PdkEndpointResponse, type Plugin } from '@myparcel-dev/pdk-common';
|
|
2
|
+
export type FrontendPdkEndpointObject = EndpointObject<FrontendEndpoint>;
|
|
3
|
+
export type FrontendEndpointData<E extends FrontendEndpoint> = FrontendPdkEndpointObject[E] & {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
};
|
|
6
|
+
export type FrontendEndpointResponse<E extends FrontendEndpoint> = PdkEndpointResponse<E, FrontendEndpointDefinition>;
|
|
7
|
+
export type FrontendEndpointParameters<E extends FrontendEndpoint> = PdkEndpointParameters<E, FrontendEndpointDefinition>;
|
|
8
|
+
interface FetchCheckoutContextDefinition extends PdkEndpointDefinition {
|
|
9
|
+
name: FrontendEndpoint.FetchCheckoutContext;
|
|
10
|
+
parameters: {
|
|
11
|
+
shippingMethod?: string;
|
|
12
|
+
};
|
|
13
|
+
response: {
|
|
14
|
+
data: {
|
|
15
|
+
context: [Plugin.ModelContextContextBag];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export type FrontendEndpointDefinition = FetchCheckoutContextDefinition;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type isEnumValue, type isOfType, type PromiseOr } from '@myparcel-dev/ts-utils';
|
|
2
|
+
import { type doRequest, type fieldsEqual, type getAddressField, type getAddressFieldValue, type getElement, type getFieldValue, type setFieldValue, type triggerEvent } from '../utils';
|
|
3
|
+
import { type realCreateStore } from '../store';
|
|
4
|
+
import { type PdkEvent, type PdkUtil } from '../data';
|
|
5
|
+
import { type CheckoutStore, type StoreData } from './store.types';
|
|
6
|
+
import { type PdkCheckout, type PdkCheckoutConfig } from './checkout.types';
|
|
7
|
+
export interface PdkEvents extends AdditionalEvents {
|
|
8
|
+
[PdkEvent.CheckoutUpdate]: string;
|
|
9
|
+
[PdkEvent.CheckoutUpdated]: string;
|
|
10
|
+
[PdkEvent.StoreInitialize]: string;
|
|
11
|
+
[PdkEvent.StoreInitialized]: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PdkStores extends AdditionalStores {
|
|
14
|
+
checkout: CheckoutStore;
|
|
15
|
+
}
|
|
16
|
+
export interface PdkUtils extends AdditionalUtils {
|
|
17
|
+
[PdkUtil.CreateStore]: typeof realCreateStore;
|
|
18
|
+
[PdkUtil.DoRequest]: typeof doRequest;
|
|
19
|
+
[PdkUtil.FieldsEqual]: typeof fieldsEqual;
|
|
20
|
+
[PdkUtil.GetAddressFieldValue]: typeof getAddressFieldValue;
|
|
21
|
+
[PdkUtil.GetAddressField]: typeof getAddressField;
|
|
22
|
+
[PdkUtil.GetElement]: typeof getElement;
|
|
23
|
+
[PdkUtil.GetFieldValue]: typeof getFieldValue;
|
|
24
|
+
[PdkUtil.IsEnumValue]: typeof isEnumValue;
|
|
25
|
+
[PdkUtil.IsOfType]: typeof isOfType;
|
|
26
|
+
[PdkUtil.SetFieldValue]: typeof setFieldValue;
|
|
27
|
+
[PdkUtil.TriggerEvent]: typeof triggerEvent;
|
|
28
|
+
}
|
|
29
|
+
export interface MyParcelPdk {
|
|
30
|
+
config: PdkCheckoutConfig;
|
|
31
|
+
events: PdkEvents;
|
|
32
|
+
initializeCallbacks: (() => PromiseOr<void>)[];
|
|
33
|
+
initialized: boolean;
|
|
34
|
+
instance: PdkCheckout;
|
|
35
|
+
storedState: StoreData;
|
|
36
|
+
stores: PdkStores;
|
|
37
|
+
utils: PdkUtils;
|
|
38
|
+
/**
|
|
39
|
+
* Pull in a util from the window object.
|
|
40
|
+
*/
|
|
41
|
+
useUtil<N extends PdkUtil>(name: N): PdkUtils[N];
|
|
42
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Keyable, type Plugin } from '@myparcel-dev/pdk-common';
|
|
2
|
+
import { type PromiseOr } from '@myparcel-dev/ts-utils';
|
|
3
|
+
import { type AddressType, type StoreListener } from '../data';
|
|
4
|
+
import { type PdkCheckoutForm } from './checkout.types';
|
|
5
|
+
type StoreListeners<T extends StoreState> = {
|
|
6
|
+
[StoreListener.Update]: StoreCallbackUpdate<T>;
|
|
7
|
+
};
|
|
8
|
+
export type StoreState = Record<string, unknown>;
|
|
9
|
+
export type StoreListenerObject<S extends StoreState> = {
|
|
10
|
+
[L in StoreListener]?: StoreListeners<S>[L][];
|
|
11
|
+
};
|
|
12
|
+
export type StoreCallbackUpdate<T extends StoreState = StoreState> = (newState: T, oldState?: T) => PromiseOr<void | T>;
|
|
13
|
+
export type StoreData<S extends StoreState = StoreState, N extends Keyable = Keyable> = Record<N, Store<S>>;
|
|
14
|
+
export type InitialStoreData<S extends StoreState = StoreState> = {
|
|
15
|
+
state: S;
|
|
16
|
+
listeners?: StoreListenerObject<S>;
|
|
17
|
+
};
|
|
18
|
+
export type Store<S extends StoreState = StoreState> = {
|
|
19
|
+
readonly set: (newState: Partial<S>) => PromiseOr<void>;
|
|
20
|
+
readonly state: S;
|
|
21
|
+
readonly listeners: StoreListenerObject<S>;
|
|
22
|
+
readonly on: <L extends StoreListener>(listener: L, callback: StoreListeners<S>[L]) => void;
|
|
23
|
+
};
|
|
24
|
+
export type CheckoutStoreState = {
|
|
25
|
+
addressType: AddressType;
|
|
26
|
+
addressTypes: AddressType[];
|
|
27
|
+
context: Plugin.ModelContextCheckoutContext;
|
|
28
|
+
form: PdkCheckoutForm;
|
|
29
|
+
};
|
|
30
|
+
export type CheckoutStore = Store<CheckoutStoreState>;
|
|
31
|
+
export interface Stores {
|
|
32
|
+
checkout: CheckoutStore;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getEnabledShippingMethods: () => string[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FrontendEndpoint } from '@myparcel-dev/pdk-common';
|
|
2
|
+
import { type FrontendEndpointParameters, type FrontendEndpointResponse } from '../../types';
|
|
3
|
+
type DoRequest = <E extends FrontendEndpoint>(endpoint: E, parameters?: FrontendEndpointParameters<E>) => Promise<FrontendEndpointResponse<E>>;
|
|
4
|
+
export declare const doRequest: DoRequest;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PdkCheckoutForm } from '../../types';
|
|
2
|
+
import { type AddressField, type AddressType, PdkField } from '../../data';
|
|
3
|
+
type FieldsEqual = {
|
|
4
|
+
(newFields: PdkCheckoutForm, oldFields: PdkCheckoutForm, addressFieldName: AddressField | string, addressType?: AddressType): boolean;
|
|
5
|
+
(newFields: PdkCheckoutForm, oldFields: PdkCheckoutForm, fieldName: PdkField, arg4?: never): boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const fieldsEqual: FieldsEqual;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AddressField, type AddressType } from '../../data';
|
|
2
|
+
/**
|
|
3
|
+
* Get field by name. Will return element with selector: "#<billing|shipping>_<name>".
|
|
4
|
+
*/
|
|
5
|
+
export declare const getAddressField: (name: AddressField | string, addressType?: AddressType, warn?: boolean) => HTMLInputElement | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getElement: <E extends Element = Element>(selector: string, warn?: boolean) => null | E;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PdkCheckoutForm } from '../../types';
|
|
2
|
+
import { type AddressField, type AddressType, PdkField } from '../../data';
|
|
3
|
+
type GetFieldValue = {
|
|
4
|
+
(field: AddressField | string, addressType?: AddressType, fields?: PdkCheckoutForm): undefined | string;
|
|
5
|
+
(field: PdkField | string, fields?: PdkCheckoutForm, arg3?: never): undefined | string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getFieldValue: GetFieldValue;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './doRequest';
|
|
2
|
+
export * from './fieldsEqual';
|
|
3
|
+
export * from './getAddressField';
|
|
4
|
+
export * from './getAddressFieldValue';
|
|
5
|
+
export * from './getAddressType';
|
|
6
|
+
export * from './getElement';
|
|
7
|
+
export * from './getFieldValue';
|
|
8
|
+
export * from './setFieldValue';
|
|
9
|
+
export * from './triggerEvent';
|