@infosoftas/s4-orders-js-sdk 0.1.16 → 0.1.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "scripts": {
5
5
  "build": "rimraf lib && webpack --mode production",
6
6
  "release": "release-it"
package/src/App.tsx CHANGED
@@ -100,6 +100,7 @@ const App: FC<ConfigType> = ({
100
100
  useEffect(() => {
101
101
  if (apiKey) {
102
102
  sessionStorage.setItem('sdk_api_key', apiKey);
103
+ localStorage.setItem('sdk_api_key', apiKey);
103
104
  }
104
105
  }, [apiKey]);
105
106
 
@@ -1,4 +1,4 @@
1
- import fetcher from '../utils/fetcher';
1
+ import fetcher, { getSdkApiKey } from '../utils/fetcher';
2
2
 
3
3
  type RequestInvoiceLookupType = {
4
4
  network: string;
@@ -17,7 +17,7 @@ export const invoiceLookup = (
17
17
  method: 'POST',
18
18
  url: '/invoicelookup',
19
19
  headers: {
20
- 'S4-ORDERS-API-KEY': sessionStorage.getItem('sdk_api_key') || '',
20
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
21
21
  },
22
22
  body,
23
23
  }) as Promise<InvoiceLookupResponseType>;
@@ -1,6 +1,6 @@
1
1
  import { CreateSubscriberRequestType } from '../types/api';
2
2
  import { AgreementsType } from '../types/order';
3
- import fetcher from '../utils/fetcher';
3
+ import fetcher, { getSdkApiKey } from '../utils/fetcher';
4
4
 
5
5
  type RequestOrderStartType = {
6
6
  subscriberId?: string;
@@ -30,7 +30,7 @@ export const orderStart = (
30
30
  method: 'POST',
31
31
  url: '/order',
32
32
  headers: {
33
- 'S4-ORDERS-API-KEY': sessionStorage.getItem('sdk_api_key') || '',
33
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
34
34
  },
35
35
  body,
36
36
  }) as Promise<OrderResponseType>;
@@ -43,7 +43,7 @@ export const orderComplete = (
43
43
  method: 'POST',
44
44
  url: `/order/${id}/complete`,
45
45
  headers: {
46
- 'S4-ORDERS-API-KEY': sessionStorage.getItem('sdk_api_key') || '',
46
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
47
47
  },
48
48
  body: body || null,
49
49
  }) as Promise<OrderResponseType>;
@@ -53,7 +53,7 @@ export const orderDelete = (id: string): Promise<OrderResponseType> =>
53
53
  method: 'DELETE',
54
54
  url: `/order/${id}`,
55
55
  headers: {
56
- 'S4-ORDERS-API-KEY': sessionStorage.getItem('sdk_api_key') || '',
56
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
57
57
  },
58
58
  body: null,
59
59
  }) as Promise<OrderResponseType>;
@@ -1,4 +1,4 @@
1
- import fetcher from '../utils/fetcher';
1
+ import fetcher, { getSdkApiKey } from '../utils/fetcher';
2
2
  import { CreateSubscriberRequestType } from '../types/api';
3
3
 
4
4
  type CreateSubscriberResponseType = {
@@ -12,7 +12,7 @@ export const createSubscriber = (
12
12
  method: 'POST',
13
13
  url: '/subscriber',
14
14
  headers: {
15
- 'S4-ORDERS-API-KEY': sessionStorage.getItem('sdk_api_key') || '',
15
+ 'S4-ORDERS-API-KEY': getSdkApiKey(),
16
16
  },
17
17
  body,
18
18
  }) as Promise<CreateSubscriberResponseType>;
@@ -19,6 +19,22 @@ type Fetcher<T> = {
19
19
  body?: T;
20
20
  };
21
21
 
22
+ export const getSdkApiKey = (): string => {
23
+ return (
24
+ sessionStorage.getItem('sdk_api_key') ||
25
+ localStorage.getItem('sdk_api_key') ||
26
+ ''
27
+ );
28
+ };
29
+
30
+ export const getSdkApiUrl = (): string => {
31
+ return (
32
+ sessionStorage.getItem('sdk_api_url') ||
33
+ localStorage.getItem('sdk_api_url') ||
34
+ BASE_API
35
+ );
36
+ };
37
+
22
38
  function createHeader<T>(options: Fetcher<T>): Fetcher<T> {
23
39
  const accessToken = localStorage.getItem('authTokenKey') || '';
24
40
 
@@ -42,7 +58,7 @@ async function fetcher<ResponseType, BodyType = void>(
42
58
  ): Promise<ApiResponseType<ResponseType> | ResponseType> {
43
59
  const { url, method, headers, body, params } = createHeader(options);
44
60
 
45
- const apiUrl = sessionStorage.getItem('sdk_api_url');
61
+ const apiUrl = getSdkApiUrl();
46
62
  const endpoint = new URL(`${apiUrl || BASE_API}${url}`);
47
63
 
48
64
  if (params) {