@infosoftas/s4-orders-js-sdk 0.1.21 → 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,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;
@@ -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>;
@@ -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
- ): Promise<OrderResponseType> =>
42
- fetcher<OrderResponseType, OrderCompleteRequestType | null>({
43
- method: 'POST',
44
- url: `/order/${id}/complete`,
45
- headers: {
46
- 'S4-ORDERS-API-KEY': getSdkApiKey(),
47
- },
48
- body: body || null,
49
- }) as Promise<OrderResponseType>;
50
-
51
- export const orderDelete = (id: string): Promise<OrderResponseType> =>
52
- fetcher<OrderResponseType, null>({
53
- method: 'DELETE',
54
- url: `/order/${id}`,
55
- headers: {
56
- 'S4-ORDERS-API-KEY': getSdkApiKey(),
57
- },
58
- body: null,
59
- }) as Promise<OrderResponseType>;
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>;
@@ -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;