@infosoftas/s4-orders-js-sdk 0.1.21-3 → 0.2.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.
Files changed (51) hide show
  1. package/.editorconfig +8 -8
  2. package/.release-it.json +10 -10
  3. package/README.md +565 -471
  4. package/package.json +62 -58
  5. package/src/App.completion.test.tsx +738 -0
  6. package/src/App.tsx +753 -639
  7. package/src/ErrorBoundary.tsx +41 -41
  8. package/src/api/InvoiceApi.ts +23 -23
  9. package/src/api/OrdersApi.ts +74 -59
  10. package/src/api/SubscribeApi.ts +18 -18
  11. package/src/bundle.ts +4 -4
  12. package/src/components/Alert/Alert.tsx +23 -23
  13. package/src/components/Button/Button.tsx +39 -39
  14. package/src/components/EHFForm/EHFForm.tsx +253 -253
  15. package/src/components/FormFields/AddressField.tsx +55 -55
  16. package/src/components/FormFields/EmailField.tsx +53 -53
  17. package/src/components/FormFields/FormFields.helper.ts +34 -34
  18. package/src/components/FormFields/FormFieldsMapper.ts +34 -34
  19. package/src/components/FormFields/InputField.tsx +52 -52
  20. package/src/components/FormFields/NameField.tsx +52 -52
  21. package/src/components/FormFields/PhoneField.tsx +53 -53
  22. package/src/components/FormFields/TermsCheckbox.tsx +70 -70
  23. package/src/components/FormFields/ToggleFiled.tsx +52 -52
  24. package/src/components/FormFields/fieldValidators.ts +71 -71
  25. package/src/components/MainIframe/MainIframe.tsx +42 -42
  26. package/src/components/OIOForm/OIOForm.tsx +307 -307
  27. package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
  28. package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
  29. package/src/components/OrderForm/OrderForm.tsx +420 -420
  30. package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
  31. package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
  32. package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
  33. package/src/components/OrderForm/orderFormState.ts +171 -171
  34. package/src/components/OrderForm/useSlotElement.tsx +89 -89
  35. package/src/constants/index.ts +13 -13
  36. package/src/enums/api.ts +5 -5
  37. package/src/enums/general.ts +40 -40
  38. package/src/hooks/useIframe.tsx +59 -59
  39. package/src/hooks/useMessageEvent.tsx +194 -194
  40. package/src/hooks/useOrderForm.tsx +403 -403
  41. package/src/hooks/useQueryParams.ts +5 -5
  42. package/src/index.tsx +30 -30
  43. package/src/lib/utils.ts +1 -1
  44. package/src/types/api.ts +28 -28
  45. package/src/types/general.ts +154 -136
  46. package/src/types/order.ts +91 -70
  47. package/src/utils/fetcher.ts +131 -113
  48. package/src/utils/helper.ts +78 -78
  49. package/src/utils/order.helper.ts +272 -272
  50. package/src/utils/waitForOrderCompletion.ts +125 -0
  51. package/tsconfig.json +38 -38
@@ -1,5 +1,5 @@
1
- function useQueryParams(): URLSearchParams {
2
- return new URLSearchParams(location.search);
3
- }
4
-
5
- export default useQueryParams;
1
+ function useQueryParams(): URLSearchParams {
2
+ return new URLSearchParams(location.search);
3
+ }
4
+
5
+ export default useQueryParams;
package/src/index.tsx CHANGED
@@ -1,30 +1,30 @@
1
- import { createRoot, type Root } from 'react-dom/client';
2
- import { createElement } from 'react';
3
-
4
- import type { ConfigType } from './types/general';
5
- import { createSubscriber } from './api/SubscribeApi';
6
- import App from './App';
7
-
8
- export const orderComponent = {
9
- root: null as Root | null,
10
- init: function (config: ConfigType) {
11
- if (!config.apiKey) {
12
- console.error('"apiKey" should be set');
13
- }
14
-
15
- if (!config.apiUrl) {
16
- console.error('"apiUrl" should be set');
17
- }
18
-
19
- const domNode = document.getElementById(config.domElementId);
20
- orderComponent.root = createRoot(
21
- domNode || document.createElement('div')
22
- );
23
- const reactElement = createElement(App, config);
24
- orderComponent.root.render(reactElement);
25
- },
26
- remove: function () {
27
- (orderComponent.root as Root)?.unmount();
28
- },
29
- createSubscriber,
30
- };
1
+ import { createRoot, type Root } from 'react-dom/client';
2
+ import { createElement } from 'react';
3
+
4
+ import type { ConfigType } from './types/general';
5
+ import { createSubscriber } from './api/SubscribeApi';
6
+ import App from './App';
7
+
8
+ export const orderComponent = {
9
+ root: null as Root | null,
10
+ init: function (config: ConfigType) {
11
+ if (!config.apiKey) {
12
+ console.error('"apiKey" should be set');
13
+ }
14
+
15
+ if (!config.apiUrl) {
16
+ console.error('"apiUrl" should be set');
17
+ }
18
+
19
+ const domNode = document.getElementById(config.domElementId);
20
+ orderComponent.root = createRoot(
21
+ domNode || document.createElement('div')
22
+ );
23
+ const reactElement = createElement(App, config);
24
+ orderComponent.root.render(reactElement);
25
+ },
26
+ remove: function () {
27
+ (orderComponent.root as Root)?.unmount();
28
+ },
29
+ createSubscriber,
30
+ };
package/src/lib/utils.ts CHANGED
@@ -1 +1 @@
1
- export { cn } from 'cn';
1
+ export { cn } from 'cn';
package/src/types/api.ts CHANGED
@@ -1,28 +1,28 @@
1
- import { HttpStatusCode } from '../enums/api';
2
-
3
- export interface ApiResponseType<T> {
4
- status: HttpStatusCode;
5
- text: string;
6
- error: string;
7
- code: HttpStatusCode;
8
- timestamp: string;
9
- data: T;
10
- query: string;
11
- url: string;
12
- }
13
-
14
- export type CreateSubscriberRequestType = {
15
- name?: string;
16
- email?: string;
17
- phone?: string;
18
- country?: string;
19
- city?: string;
20
- addressLines?: string[];
21
- zip?: string;
22
- careOf?: string;
23
- buyerReference?: string;
24
- gln?: string;
25
- organizationNumber?: string;
26
- identityProviderId?: string;
27
- userId?: string;
28
- };
1
+ import { HttpStatusCode } from '../enums/api';
2
+
3
+ export interface ApiResponseType<T> {
4
+ status: HttpStatusCode;
5
+ text: string;
6
+ error: string;
7
+ code: HttpStatusCode;
8
+ timestamp: string;
9
+ data: T;
10
+ query: string;
11
+ url: string;
12
+ }
13
+
14
+ export type CreateSubscriberRequestType = {
15
+ name?: string;
16
+ email?: string;
17
+ phone?: string;
18
+ country?: string;
19
+ city?: string;
20
+ addressLines?: string[];
21
+ zip?: string;
22
+ careOf?: string;
23
+ buyerReference?: string;
24
+ gln?: string;
25
+ organizationNumber?: string;
26
+ identityProviderId?: string;
27
+ userId?: string;
28
+ };
@@ -1,136 +1,154 @@
1
- import type { ReactNode } from 'react';
2
-
3
- import { PaymentMethodEnum, UserActionEnum } from '../enums/general';
4
- import type { OrderFormInputsType } from './order';
5
-
6
- declare global {
7
- interface Window {
8
- sdkOrderCallback: () => void;
9
- }
10
- }
11
-
12
- export type OrderFormFieldType = {
13
- name: string;
14
- required?: boolean;
15
- readOnly?: boolean;
16
- label?: string;
17
- };
18
-
19
- export type PaymentMethodSettingsType = {
20
- [key in PaymentMethodEnum]?: {
21
- generateSubscriberContact?: boolean;
22
- accountId?: string;
23
- orderFormFields?: OrderFormFieldType[];
24
- paymentInvoiceFields?: OrderFormFieldType[] | never[] | null;
25
- };
26
- };
27
-
28
- export type ContactRequestType = {
29
- addressLines?: Array<string> | undefined;
30
- name?: string;
31
- email?: string;
32
- phone?: string;
33
- country?: string;
34
- city?: string;
35
- zip?: string;
36
- careOf?: string;
37
- organizationNumber?: string;
38
- gln?: string;
39
- };
40
-
41
- export type OrderDenialFallbackOfferType = {
42
- title?: string;
43
- description?: string;
44
- price?: string;
45
- templatePackageId?: string;
46
- };
47
-
48
- export type PaymentIconType = {
49
- src: string;
50
- alt?: string;
51
- className?: string;
52
- };
53
-
54
- export type PaymentMethodOptionType = {
55
- label: string;
56
- value: PaymentMethodEnum;
57
- description?: string;
58
- icons?: PaymentIconType[];
59
- };
60
-
61
- export type SubmitConfirmationType = {
62
- title: string;
63
- description?: string;
64
- confirmText: string;
65
- cancelText: string;
66
- };
67
-
68
- export type ConfigType = {
69
- submitStartCallback?: (subscriberId: string) => void;
70
- userActionCallback?: (
71
- action: UserActionEnum,
72
- args: object | null | undefined
73
- ) => void;
74
- setContactCallback?: (contactInfo: ContactRequestType) => void;
75
- cancelVippsCallback?: () => void;
76
- domElementId: string;
77
- moduleTitle?: string;
78
- templatePackageId: string;
79
- subscriberId: string;
80
- userId: string;
81
- identityProviderId: string;
82
- organizationId: string;
83
- apiKey?: string;
84
- apiUrl?: string;
85
- redirectUrl?: string;
86
- showIframe?: boolean;
87
- availablePaymentMethods?: PaymentMethodOptionType[];
88
- allowedPaymentMethods?: PaymentMethodEnum[];
89
- paymentMethodsOptions?: PaymentMethodSettingsType;
90
- requireTermsAcceptance?: boolean;
91
- language?: string;
92
- merchantAgreementUrl?: string;
93
- invoiceAddressSelection?: {
94
- enabled?: boolean;
95
- label?: string;
96
- fields?: OrderFormFieldType[];
97
- };
98
- settings?: {
99
- successText?: string;
100
- failureText?: string;
101
- submitButtonText?: string;
102
- backButtonText?: string;
103
- verifyButtonText?: string;
104
- orderDenialCloseButtonText?: string;
105
- orderDenialContinueButtonText?: string;
106
- organizationNumberLabel?: string;
107
- cvrLabel?: string;
108
- glnLabel?: string;
109
- orderDefaultValues?: OrderFormInputsType;
110
- paymentMethodLabel?: string;
111
- contactDetailsLabel?: string;
112
- paymentMethodElementId?: string;
113
- contactDetailsElementId?: string;
114
- errorReqMsg?: string;
115
- errorInvalidEmailMsg?: string;
116
- errorInvalidPhoneMsg?: string;
117
- errorTermsMsg?: string;
118
- paymentMethodNotAllowedMsg?: string;
119
- invoiceLookupNotFoundText?: string;
120
- errorValidationTitleMsg?: string;
121
- errorValidationDenialOrderBlockingMsg?: string;
122
- errorValidationBlockingOffersMsg?: string;
123
- orderDenialOfferBaseText?: string;
124
- orderDenialOfferWithFallbackText?: string;
125
- orderDenialAmountText?: string;
126
- fetchDenialFallbackOffer?: (
127
- organizationId: string
128
- ) => Promise<OrderDenialFallbackOfferType | undefined>;
129
- termsAndConditionsText?: string | ReactNode;
130
- submitConfirmation?: SubmitConfirmationType;
131
- };
132
- };
133
-
134
- export type ErrorsMsg = {
135
- [key: string]: string[];
136
- };
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { PaymentMethodEnum, UserActionEnum } from '../enums/general';
4
+ import type {
5
+ OrderCompletionEventType,
6
+ OrderCompletionDelayedEventType,
7
+ OrderCompletionFailedEventType,
8
+ OrderFormInputsType,
9
+ } from './order';
10
+
11
+ declare global {
12
+ interface Window {
13
+ sdkOrderCallback: () => void;
14
+ }
15
+ }
16
+
17
+ export type OrderFormFieldType = {
18
+ name: string;
19
+ required?: boolean;
20
+ readOnly?: boolean;
21
+ label?: string;
22
+ };
23
+
24
+ export type PaymentMethodSettingsType = {
25
+ [key in PaymentMethodEnum]?: {
26
+ generateSubscriberContact?: boolean;
27
+ accountId?: string;
28
+ orderFormFields?: OrderFormFieldType[];
29
+ paymentInvoiceFields?: OrderFormFieldType[] | never[] | null;
30
+ };
31
+ };
32
+
33
+ export type ContactRequestType = {
34
+ addressLines?: Array<string> | undefined;
35
+ name?: string;
36
+ email?: string;
37
+ phone?: string;
38
+ country?: string;
39
+ city?: string;
40
+ zip?: string;
41
+ careOf?: string;
42
+ organizationNumber?: string;
43
+ gln?: string;
44
+ };
45
+
46
+ export type OrderDenialFallbackOfferType = {
47
+ title?: string;
48
+ description?: string;
49
+ price?: string;
50
+ templatePackageId?: string;
51
+ };
52
+
53
+ export type PaymentIconType = {
54
+ src: string;
55
+ alt?: string;
56
+ className?: string;
57
+ };
58
+
59
+ export type PaymentMethodOptionType = {
60
+ label: string;
61
+ value: PaymentMethodEnum;
62
+ description?: string;
63
+ icons?: PaymentIconType[];
64
+ };
65
+
66
+ export type SubmitConfirmationType = {
67
+ title: string;
68
+ description?: string;
69
+ confirmText: string;
70
+ cancelText: string;
71
+ };
72
+
73
+ export type ConfigType = {
74
+ /** SDK polling is the default. External mode delegates confirmation to the host. */
75
+ completionMode?: 'sdk' | 'external';
76
+ orderAcceptedCallback?: (event: OrderCompletionEventType) => void;
77
+ orderCompletedCallback?: (event: OrderCompletionEventType) => void;
78
+ orderCompletionDelayedCallback?: (
79
+ event: OrderCompletionDelayedEventType
80
+ ) => void;
81
+ orderCompletionFailedCallback?: (
82
+ event: OrderCompletionFailedEventType
83
+ ) => void;
84
+ submitStartCallback?: (subscriberId: string) => void;
85
+ userActionCallback?: (
86
+ action: UserActionEnum,
87
+ args: object | null | undefined
88
+ ) => void;
89
+ setContactCallback?: (contactInfo: ContactRequestType) => void;
90
+ cancelVippsCallback?: () => void;
91
+ domElementId: string;
92
+ moduleTitle?: string;
93
+ templatePackageId: string;
94
+ subscriberId: string;
95
+ userId: string;
96
+ identityProviderId: string;
97
+ organizationId: string;
98
+ apiKey?: string;
99
+ apiUrl?: string;
100
+ redirectUrl?: string;
101
+ showIframe?: boolean;
102
+ availablePaymentMethods?: PaymentMethodOptionType[];
103
+ allowedPaymentMethods?: PaymentMethodEnum[];
104
+ paymentMethodsOptions?: PaymentMethodSettingsType;
105
+ requireTermsAcceptance?: boolean;
106
+ language?: string;
107
+ merchantAgreementUrl?: string;
108
+ invoiceAddressSelection?: {
109
+ enabled?: boolean;
110
+ label?: string;
111
+ fields?: OrderFormFieldType[];
112
+ };
113
+ settings?: {
114
+ successText?: string;
115
+ orderProcessingText?: string;
116
+ orderReceivedText?: string;
117
+ orderDelayedText?: string;
118
+ failureText?: string;
119
+ submitButtonText?: string;
120
+ backButtonText?: string;
121
+ verifyButtonText?: string;
122
+ orderDenialCloseButtonText?: string;
123
+ orderDenialContinueButtonText?: string;
124
+ organizationNumberLabel?: string;
125
+ cvrLabel?: string;
126
+ glnLabel?: string;
127
+ orderDefaultValues?: OrderFormInputsType;
128
+ paymentMethodLabel?: string;
129
+ contactDetailsLabel?: string;
130
+ paymentMethodElementId?: string;
131
+ contactDetailsElementId?: string;
132
+ errorReqMsg?: string;
133
+ errorInvalidEmailMsg?: string;
134
+ errorInvalidPhoneMsg?: string;
135
+ errorTermsMsg?: string;
136
+ paymentMethodNotAllowedMsg?: string;
137
+ invoiceLookupNotFoundText?: string;
138
+ errorValidationTitleMsg?: string;
139
+ errorValidationDenialOrderBlockingMsg?: string;
140
+ errorValidationBlockingOffersMsg?: string;
141
+ orderDenialOfferBaseText?: string;
142
+ orderDenialOfferWithFallbackText?: string;
143
+ orderDenialAmountText?: string;
144
+ fetchDenialFallbackOffer?: (
145
+ organizationId: string
146
+ ) => Promise<OrderDenialFallbackOfferType | undefined>;
147
+ termsAndConditionsText?: string | ReactNode;
148
+ submitConfirmation?: SubmitConfirmationType;
149
+ };
150
+ };
151
+
152
+ export type ErrorsMsg = {
153
+ [key: string]: string[];
154
+ };
@@ -1,70 +1,91 @@
1
- import { PaymentMethodEnum } from '../enums/general';
2
-
3
- export type OrderFormInputsType = {
4
- name?: string;
5
- email?: string;
6
- phoneNumber?: string;
7
- paymentMethod?: PaymentMethodEnum;
8
- country?: string;
9
- city?: string;
10
- address?: string;
11
- zip?: string;
12
- careOf?: string;
13
- organizationNumber?: string;
14
- invoiceAddressSelection?: boolean;
15
- orderReference?: string;
16
- invoiceName?: string;
17
- invoiceEmail?: string;
18
- invoicePhoneNumber?: string;
19
- invoiceCountry?: string;
20
- invoiceCity?: string;
21
- invoiceAddress?: string;
22
- invoiceZip?: string;
23
- invoiceCareOf?: string;
24
- invoiceBuyerReference?: string;
25
- gln?: string;
26
- cvr?: string;
27
- termsAccept?: boolean;
28
- };
29
-
30
- export type VippsMobilePay = {
31
- phoneNumber?: string;
32
- merchantRedirectUrl: string;
33
- merchantAgreementUrl: string;
34
- generateSubscriberContact?: boolean;
35
- accountId?: string;
36
- };
37
-
38
- export type SwedbankPay = {
39
- accountId?: string;
40
- completeUrl: string;
41
- cancelUrl: string;
42
- language?: string;
43
- };
44
-
45
- export type Mollie = {
46
- accountId?: string;
47
- returnUrl: string;
48
- cancelUrl?: string;
49
- language?: string;
50
- };
51
-
52
- export type AgreementsType = {
53
- paymentProvider: PaymentMethodEnum;
54
- vippsMobilePay?: VippsMobilePay;
55
- swedbankPay?: SwedbankPay;
56
- mollie?: Mollie;
57
- };
58
-
59
- export type OrderInfoType = {
60
- subscriberId: string;
61
- paymentMethod: string;
62
- orderId: string;
63
- };
64
-
65
- export type CompleteOrderParamsType = {
66
- orderId: string;
67
- agreementId: string;
68
- orderInfo: OrderInfoType | null;
69
- paymentMethod?: PaymentMethodEnum | null;
70
- };
1
+ import { PaymentMethodEnum } from '../enums/general';
2
+
3
+ export type OrderFormInputsType = {
4
+ name?: string;
5
+ email?: string;
6
+ phoneNumber?: string;
7
+ paymentMethod?: PaymentMethodEnum;
8
+ country?: string;
9
+ city?: string;
10
+ address?: string;
11
+ zip?: string;
12
+ careOf?: string;
13
+ organizationNumber?: string;
14
+ invoiceAddressSelection?: boolean;
15
+ orderReference?: string;
16
+ invoiceName?: string;
17
+ invoiceEmail?: string;
18
+ invoicePhoneNumber?: string;
19
+ invoiceCountry?: string;
20
+ invoiceCity?: string;
21
+ invoiceAddress?: string;
22
+ invoiceZip?: string;
23
+ invoiceCareOf?: string;
24
+ invoiceBuyerReference?: string;
25
+ gln?: string;
26
+ cvr?: string;
27
+ termsAccept?: boolean;
28
+ };
29
+
30
+ export type VippsMobilePay = {
31
+ phoneNumber?: string;
32
+ merchantRedirectUrl: string;
33
+ merchantAgreementUrl: string;
34
+ generateSubscriberContact?: boolean;
35
+ accountId?: string;
36
+ };
37
+
38
+ export type SwedbankPay = {
39
+ accountId?: string;
40
+ completeUrl: string;
41
+ cancelUrl: string;
42
+ language?: string;
43
+ };
44
+
45
+ export type Mollie = {
46
+ accountId?: string;
47
+ returnUrl: string;
48
+ cancelUrl?: string;
49
+ language?: string;
50
+ };
51
+
52
+ export type AgreementsType = {
53
+ paymentProvider: PaymentMethodEnum;
54
+ vippsMobilePay?: VippsMobilePay;
55
+ swedbankPay?: SwedbankPay;
56
+ mollie?: Mollie;
57
+ };
58
+
59
+ export type OrderInfoType = {
60
+ subscriberId: string;
61
+ paymentMethod: string;
62
+ orderId: string;
63
+ };
64
+
65
+ export type OrderStatusResponseType = {
66
+ id: string;
67
+ status: string;
68
+ orderCreated?: string | null;
69
+ orderCompleted?: string | null;
70
+ orderCancelled?: string | null;
71
+ };
72
+
73
+ export type OrderCompletionEventType = {
74
+ orderId: string;
75
+ orderInfo: OrderInfoType | null;
76
+ };
77
+
78
+ export type OrderCompletionDelayedEventType = OrderCompletionEventType & {
79
+ reason: 'timeout' | 'statusUnavailable';
80
+ };
81
+
82
+ export type OrderCompletionFailedEventType = OrderCompletionEventType & {
83
+ status: 'Cancelled' | 'Rejected';
84
+ };
85
+
86
+ export type CompleteOrderParamsType = {
87
+ orderId: string;
88
+ agreementId: string;
89
+ orderInfo: OrderInfoType | null;
90
+ paymentMethod?: PaymentMethodEnum | null;
91
+ };