@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.
- package/.editorconfig +8 -8
- package/.release-it.json +10 -10
- package/README.md +565 -471
- package/package.json +62 -58
- package/src/App.completion.test.tsx +738 -0
- package/src/App.tsx +753 -639
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +18 -18
- package/src/bundle.ts +4 -4
- package/src/components/Alert/Alert.tsx +23 -23
- package/src/components/Button/Button.tsx +39 -39
- package/src/components/EHFForm/EHFForm.tsx +253 -253
- package/src/components/FormFields/AddressField.tsx +55 -55
- package/src/components/FormFields/EmailField.tsx +53 -53
- package/src/components/FormFields/FormFields.helper.ts +34 -34
- package/src/components/FormFields/FormFieldsMapper.ts +34 -34
- package/src/components/FormFields/InputField.tsx +52 -52
- package/src/components/FormFields/NameField.tsx +52 -52
- package/src/components/FormFields/PhoneField.tsx +53 -53
- package/src/components/FormFields/TermsCheckbox.tsx +70 -70
- package/src/components/FormFields/ToggleFiled.tsx +52 -52
- package/src/components/FormFields/fieldValidators.ts +71 -71
- package/src/components/MainIframe/MainIframe.tsx +42 -42
- package/src/components/OIOForm/OIOForm.tsx +307 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +420 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
- package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
- package/src/components/OrderForm/orderFormState.ts +171 -171
- package/src/components/OrderForm/useSlotElement.tsx +89 -89
- package/src/constants/index.ts +13 -13
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +40 -40
- package/src/hooks/useIframe.tsx +59 -59
- package/src/hooks/useMessageEvent.tsx +194 -194
- package/src/hooks/useOrderForm.tsx +403 -403
- package/src/hooks/useQueryParams.ts +5 -5
- package/src/index.tsx +30 -30
- package/src/lib/utils.ts +1 -1
- package/src/types/api.ts +28 -28
- package/src/types/general.ts +154 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.ts +272 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +38 -38
package/src/ErrorBoundary.tsx
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import React, { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
interface Props {
|
|
4
|
-
children?: ReactNode;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface State {
|
|
8
|
-
hasError: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class ErrorBoundary extends Component<Props, State> {
|
|
12
|
-
public state: State = {
|
|
13
|
-
hasError: false,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
public static getDerivedStateFromError(): State {
|
|
17
|
-
// Update state so the next render will show the fallback UI.
|
|
18
|
-
return { hasError: true };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
22
|
-
console.error('Uncaught error:', error, errorInfo);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public render() {
|
|
26
|
-
if (this.state.hasError) {
|
|
27
|
-
return (
|
|
28
|
-
<div className="layout-wrapper">
|
|
29
|
-
<h1>
|
|
30
|
-
Something went wrong. Please reload the page and try
|
|
31
|
-
again.
|
|
32
|
-
</h1>
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.props.children;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default ErrorBoundary;
|
|
1
|
+
import React, { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface State {
|
|
8
|
+
hasError: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class ErrorBoundary extends Component<Props, State> {
|
|
12
|
+
public state: State = {
|
|
13
|
+
hasError: false,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
public static getDerivedStateFromError(): State {
|
|
17
|
+
// Update state so the next render will show the fallback UI.
|
|
18
|
+
return { hasError: true };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
22
|
+
console.error('Uncaught error:', error, errorInfo);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public render() {
|
|
26
|
+
if (this.state.hasError) {
|
|
27
|
+
return (
|
|
28
|
+
<div className="layout-wrapper">
|
|
29
|
+
<h1>
|
|
30
|
+
Something went wrong. Please reload the page and try
|
|
31
|
+
again.
|
|
32
|
+
</h1>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this.props.children;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default ErrorBoundary;
|
package/src/api/InvoiceApi.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
2
|
-
|
|
3
|
-
type RequestInvoiceLookupType = {
|
|
4
|
-
network: string;
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type InvoiceLookupResponseType = {
|
|
9
|
-
receivesInvoice: boolean;
|
|
10
|
-
recievesInvoice: boolean; // TODO: Should be deleted in the future (misspelled), use "receivesInvoice" instead of this.
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const invoiceLookup = (
|
|
14
|
-
body: RequestInvoiceLookupType
|
|
15
|
-
): Promise<InvoiceLookupResponseType> =>
|
|
16
|
-
fetcher<InvoiceLookupResponseType, RequestInvoiceLookupType>({
|
|
17
|
-
method: 'POST',
|
|
18
|
-
url: '/invoicelookup',
|
|
19
|
-
headers: {
|
|
20
|
-
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
21
|
-
},
|
|
22
|
-
body,
|
|
23
|
-
}) as Promise<InvoiceLookupResponseType>;
|
|
1
|
+
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
2
|
+
|
|
3
|
+
type RequestInvoiceLookupType = {
|
|
4
|
+
network: string;
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type InvoiceLookupResponseType = {
|
|
9
|
+
receivesInvoice: boolean;
|
|
10
|
+
recievesInvoice: boolean; // TODO: Should be deleted in the future (misspelled), use "receivesInvoice" instead of this.
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const invoiceLookup = (
|
|
14
|
+
body: RequestInvoiceLookupType
|
|
15
|
+
): Promise<InvoiceLookupResponseType> =>
|
|
16
|
+
fetcher<InvoiceLookupResponseType, RequestInvoiceLookupType>({
|
|
17
|
+
method: 'POST',
|
|
18
|
+
url: '/invoicelookup',
|
|
19
|
+
headers: {
|
|
20
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
21
|
+
},
|
|
22
|
+
body,
|
|
23
|
+
}) as Promise<InvoiceLookupResponseType>;
|
package/src/api/OrdersApi.ts
CHANGED
|
@@ -1,59 +1,74 @@
|
|
|
1
|
-
import type { CreateSubscriberRequestType } from '../types/api';
|
|
2
|
-
import type { AgreementsType } from '../types/order';
|
|
3
|
-
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
4
|
-
|
|
5
|
-
type RequestOrderStartType = {
|
|
6
|
-
subscriberId?: string;
|
|
7
|
-
subscriptionPlan?: {
|
|
8
|
-
organizationId?: string;
|
|
9
|
-
templateSubscriptionPlanId?: string;
|
|
10
|
-
};
|
|
11
|
-
paymentAgreement: AgreementsType;
|
|
12
|
-
invoiceContact?: CreateSubscriberRequestType;
|
|
13
|
-
orderReference?: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type OrderCompleteRequestType = {
|
|
17
|
-
userId: string;
|
|
18
|
-
identityProviderId: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type OrderResponseType = {
|
|
22
|
-
terminalRedirectUrl: string | null;
|
|
23
|
-
id: string | null;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const orderStart = (
|
|
27
|
-
body: RequestOrderStartType
|
|
28
|
-
): Promise<OrderResponseType> =>
|
|
29
|
-
fetcher<OrderResponseType, RequestOrderStartType>({
|
|
30
|
-
method: 'POST',
|
|
31
|
-
url: '/order',
|
|
32
|
-
headers: {
|
|
33
|
-
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
34
|
-
},
|
|
35
|
-
body,
|
|
36
|
-
}) as Promise<OrderResponseType>;
|
|
37
|
-
|
|
38
|
-
export const orderComplete = (
|
|
39
|
-
id: string,
|
|
40
|
-
body?: OrderCompleteRequestType
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import type { CreateSubscriberRequestType } from '../types/api';
|
|
2
|
+
import type { AgreementsType, OrderStatusResponseType } from '../types/order';
|
|
3
|
+
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
4
|
+
|
|
5
|
+
type RequestOrderStartType = {
|
|
6
|
+
subscriberId?: string;
|
|
7
|
+
subscriptionPlan?: {
|
|
8
|
+
organizationId?: string;
|
|
9
|
+
templateSubscriptionPlanId?: string;
|
|
10
|
+
};
|
|
11
|
+
paymentAgreement: AgreementsType;
|
|
12
|
+
invoiceContact?: CreateSubscriberRequestType;
|
|
13
|
+
orderReference?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type OrderCompleteRequestType = {
|
|
17
|
+
userId: string;
|
|
18
|
+
identityProviderId: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type OrderResponseType = {
|
|
22
|
+
terminalRedirectUrl: string | null;
|
|
23
|
+
id: string | null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const orderStart = (
|
|
27
|
+
body: RequestOrderStartType
|
|
28
|
+
): Promise<OrderResponseType> =>
|
|
29
|
+
fetcher<OrderResponseType, RequestOrderStartType>({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
url: '/order',
|
|
32
|
+
headers: {
|
|
33
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
34
|
+
},
|
|
35
|
+
body,
|
|
36
|
+
}) as Promise<OrderResponseType>;
|
|
37
|
+
|
|
38
|
+
export const orderComplete = (
|
|
39
|
+
id: string,
|
|
40
|
+
body?: OrderCompleteRequestType,
|
|
41
|
+
signal?: AbortSignal
|
|
42
|
+
): Promise<OrderResponseType> =>
|
|
43
|
+
fetcher<OrderResponseType, OrderCompleteRequestType | null>({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
url: `/order/${id}/complete`,
|
|
46
|
+
headers: {
|
|
47
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
48
|
+
},
|
|
49
|
+
body: body || null,
|
|
50
|
+
signal,
|
|
51
|
+
}) as Promise<OrderResponseType>;
|
|
52
|
+
|
|
53
|
+
export const getOrderStatus = (
|
|
54
|
+
id: string,
|
|
55
|
+
signal: AbortSignal
|
|
56
|
+
): Promise<OrderStatusResponseType> =>
|
|
57
|
+
fetcher<OrderStatusResponseType>({
|
|
58
|
+
url: `/order/${encodeURIComponent(id)}`,
|
|
59
|
+
headers: {
|
|
60
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
61
|
+
},
|
|
62
|
+
signal,
|
|
63
|
+
cache: 'no-store',
|
|
64
|
+
}) as Promise<OrderStatusResponseType>;
|
|
65
|
+
|
|
66
|
+
export const orderDelete = (id: string): Promise<OrderResponseType> =>
|
|
67
|
+
fetcher<OrderResponseType, null>({
|
|
68
|
+
method: 'DELETE',
|
|
69
|
+
url: `/order/${id}`,
|
|
70
|
+
headers: {
|
|
71
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
72
|
+
},
|
|
73
|
+
body: null,
|
|
74
|
+
}) as Promise<OrderResponseType>;
|
package/src/api/SubscribeApi.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
2
|
-
import type { CreateSubscriberRequestType } from '../types/api';
|
|
3
|
-
|
|
4
|
-
type CreateSubscriberResponseType = {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const createSubscriber = (
|
|
9
|
-
body: CreateSubscriberRequestType
|
|
10
|
-
): Promise<CreateSubscriberResponseType> =>
|
|
11
|
-
fetcher<CreateSubscriberResponseType, CreateSubscriberRequestType>({
|
|
12
|
-
method: 'POST',
|
|
13
|
-
url: '/subscriber',
|
|
14
|
-
headers: {
|
|
15
|
-
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
16
|
-
},
|
|
17
|
-
body,
|
|
18
|
-
}) as Promise<CreateSubscriberResponseType>;
|
|
1
|
+
import fetcher, { getSdkApiKey } from '../utils/fetcher';
|
|
2
|
+
import type { CreateSubscriberRequestType } from '../types/api';
|
|
3
|
+
|
|
4
|
+
type CreateSubscriberResponseType = {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const createSubscriber = (
|
|
9
|
+
body: CreateSubscriberRequestType
|
|
10
|
+
): Promise<CreateSubscriberResponseType> =>
|
|
11
|
+
fetcher<CreateSubscriberResponseType, CreateSubscriberRequestType>({
|
|
12
|
+
method: 'POST',
|
|
13
|
+
url: '/subscriber',
|
|
14
|
+
headers: {
|
|
15
|
+
'S4-ORDERS-API-KEY': getSdkApiKey(),
|
|
16
|
+
},
|
|
17
|
+
body,
|
|
18
|
+
}) as Promise<CreateSubscriberResponseType>;
|
package/src/bundle.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Bundle-only entry: apps compiling src/ directly can't process this raw Tailwind CSS.
|
|
2
|
-
import './App.css';
|
|
3
|
-
|
|
4
|
-
export * from './index';
|
|
1
|
+
// Bundle-only entry: apps compiling src/ directly can't process this raw Tailwind CSS.
|
|
2
|
+
import './App.css';
|
|
3
|
+
|
|
4
|
+
export * from './index';
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Alert as UIAlert, AlertDescription } from '../ui/alert';
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
msg?: string;
|
|
7
|
-
type?: 'danger' | 'success';
|
|
8
|
-
className?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const Alert: FC<Props> = ({ msg, type = 'danger', className }) => {
|
|
12
|
-
return msg ? (
|
|
13
|
-
<UIAlert
|
|
14
|
-
variant={type === 'danger' ? 'destructive' : 'default'}
|
|
15
|
-
className={className}
|
|
16
|
-
data-testid="sdk-alert-id"
|
|
17
|
-
>
|
|
18
|
-
<AlertDescription>{msg}</AlertDescription>
|
|
19
|
-
</UIAlert>
|
|
20
|
-
) : null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default Alert;
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Alert as UIAlert, AlertDescription } from '../ui/alert';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
msg?: string;
|
|
7
|
+
type?: 'danger' | 'success';
|
|
8
|
+
className?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const Alert: FC<Props> = ({ msg, type = 'danger', className }) => {
|
|
12
|
+
return msg ? (
|
|
13
|
+
<UIAlert
|
|
14
|
+
variant={type === 'danger' ? 'destructive' : 'default'}
|
|
15
|
+
className={className}
|
|
16
|
+
data-testid="sdk-alert-id"
|
|
17
|
+
>
|
|
18
|
+
<AlertDescription>{msg}</AlertDescription>
|
|
19
|
+
</UIAlert>
|
|
20
|
+
) : null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default Alert;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import type { FC, MouseEvent } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Button as UIButton } from '../ui/button';
|
|
4
|
-
import { Spinner } from '../ui/spinner';
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
-
type?: 'button' | 'submit' | 'reset';
|
|
9
|
-
btnType?: 'primary' | 'default';
|
|
10
|
-
buttonText?: string;
|
|
11
|
-
loading?: boolean;
|
|
12
|
-
disable?: boolean;
|
|
13
|
-
className?: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const Button: FC<Props> = ({
|
|
17
|
-
onClick,
|
|
18
|
-
type = 'button',
|
|
19
|
-
btnType = 'primary',
|
|
20
|
-
buttonText = 'Start',
|
|
21
|
-
loading = false,
|
|
22
|
-
disable = false,
|
|
23
|
-
className,
|
|
24
|
-
}) => (
|
|
25
|
-
<UIButton
|
|
26
|
-
data-testid="sdk-button-id"
|
|
27
|
-
type={type}
|
|
28
|
-
variant={btnType === 'primary' ? 'default' : 'ghost'}
|
|
29
|
-
disabled={loading || disable}
|
|
30
|
-
aria-busy={loading || undefined}
|
|
31
|
-
className={className}
|
|
32
|
-
onClick={onClick}
|
|
33
|
-
>
|
|
34
|
-
{loading && <Spinner data-icon="inline-start" />}
|
|
35
|
-
{buttonText}
|
|
36
|
-
</UIButton>
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export default Button;
|
|
1
|
+
import type { FC, MouseEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button as UIButton } from '../ui/button';
|
|
4
|
+
import { Spinner } from '../ui/spinner';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
+
type?: 'button' | 'submit' | 'reset';
|
|
9
|
+
btnType?: 'primary' | 'default';
|
|
10
|
+
buttonText?: string;
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
disable?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const Button: FC<Props> = ({
|
|
17
|
+
onClick,
|
|
18
|
+
type = 'button',
|
|
19
|
+
btnType = 'primary',
|
|
20
|
+
buttonText = 'Start',
|
|
21
|
+
loading = false,
|
|
22
|
+
disable = false,
|
|
23
|
+
className,
|
|
24
|
+
}) => (
|
|
25
|
+
<UIButton
|
|
26
|
+
data-testid="sdk-button-id"
|
|
27
|
+
type={type}
|
|
28
|
+
variant={btnType === 'primary' ? 'default' : 'ghost'}
|
|
29
|
+
disabled={loading || disable}
|
|
30
|
+
aria-busy={loading || undefined}
|
|
31
|
+
className={className}
|
|
32
|
+
onClick={onClick}
|
|
33
|
+
>
|
|
34
|
+
{loading && <Spinner data-icon="inline-start" />}
|
|
35
|
+
{buttonText}
|
|
36
|
+
</UIButton>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export default Button;
|