@intra-mart/smartlime 2.0.0-dev.20241210 → 2.0.0-dev.20251017
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/lib/_shared/renderTarget.d.ts +11 -11
- package/lib/_shared/renderTarget.js +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/packages/Copilot/IMCopilotError.d.ts +4 -0
- package/lib/packages/Copilot/IMCopilotError.js +10 -0
- package/lib/packages/Copilot/hooks/index.d.ts +1 -0
- package/lib/packages/Copilot/hooks/index.js +1 -0
- package/lib/packages/Copilot/hooks/useAssistant/index.d.ts +47 -0
- package/lib/packages/Copilot/hooks/useAssistant/index.js +194 -0
- package/lib/packages/Copilot/hooks/useAssistant/jsonParse.d.ts +2 -0
- package/lib/packages/Copilot/hooks/useAssistant/jsonParse.js +18 -0
- package/lib/packages/Copilot/hooks/useAssistant/types.d.ts +52 -0
- package/lib/packages/Copilot/hooks/useAssistant/types.js +1 -0
- package/lib/packages/Fetch/index.d.ts +4 -2
- package/lib/packages/Fetch/index.js +1 -0
- package/lib/packages/Me/index.d.ts +3 -2
- package/lib/packages/Me/index.js +1 -1
- package/lib/packages/Me/type.d.ts +1 -0
- package/lib/packages/OAuth/Context.d.ts +13 -1
- package/lib/packages/OAuth/hooks/index.d.ts +1 -0
- package/lib/packages/OAuth/hooks/index.js +1 -0
- package/lib/packages/OAuth/hooks/useAuthInitError.d.ts +3 -0
- package/lib/packages/OAuth/hooks/useAuthInitError.js +24 -0
- package/lib/packages/OAuth/hooks/useAuthState.d.ts +1 -1
- package/lib/packages/OAuth/hooks/useAuthStateEffect.d.ts +1 -1
- package/lib/packages/OAuth/hooks/useStartAuth.d.ts +1 -1
- package/lib/packages/OAuth/index.d.ts +9 -13
- package/lib/packages/OAuth/index.js +72 -44
- package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/useDepartmentSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/useDepartmentTopSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/usePostSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/usePublicGroupRoleSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/usePublicGroupSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/usePublicGroupTopSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/useRoleSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.d.ts +2 -1
- package/lib/packages/Search/hooks/useUserSearch.d.ts +2 -1
- package/lib/packages/Search/index.d.ts +3 -2
- package/lib/packages/Search/index.js +1 -1
- package/lib/packages/Search/types.d.ts +2 -1
- package/lib/packages/Session/index.d.ts +2 -1
- package/lib/packages/Session/index.js +29 -24
- package/lib/packages/Smartlime/index.d.ts +2 -1
- package/lib/packages/Tenant/Context.d.ts +13 -5
- package/lib/packages/Tenant/constants.d.ts +2 -0
- package/lib/packages/Tenant/constants.js +4 -0
- package/lib/packages/Tenant/hooks/index.d.ts +2 -2
- package/lib/packages/Tenant/hooks/index.js +2 -2
- package/lib/packages/Tenant/hooks/useIMModules.d.ts +6 -0
- package/lib/packages/Tenant/hooks/useIMModules.js +79 -0
- package/lib/packages/Tenant/hooks/useIMModulesState.d.ts +2 -0
- package/lib/packages/Tenant/hooks/{useIMFetchModuleState.js → useIMModulesState.js} +3 -4
- package/lib/packages/Tenant/index.d.ts +4 -15
- package/lib/packages/Tenant/index.js +16 -83
- package/lib/packages/Tenant/modulesType.d.ts +1522 -2
- package/lib/packages/Tenant/modulesType.js +1522 -2
- package/lib/packages/WebView/InternalIMWebView.d.ts +1 -1
- package/lib/packages/WebView/InternalIMWebView.js +6 -6
- package/lib/packages/WebView/hooks/useHackSearchUI.d.ts +1 -1
- package/lib/packages/WebView/index.js +8 -8
- package/package.json +27 -32
- package/lib/packages/Tenant/hooks/useIMFetchModuleState.d.ts +0 -2
- package/lib/packages/Tenant/hooks/useIMModuleInfo.d.ts +0 -6
- package/lib/packages/Tenant/hooks/useIMModuleInfo.js +0 -13
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as SecureStore from 'expo-secure-store';
|
|
2
1
|
import { exchangeCodeAsync, loadAsync, Prompt, refreshAsync, } from 'expo-auth-session';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { useRenderTarget } from '../../_shared/renderTarget';
|
|
2
|
+
import * as SecureStore from 'expo-secure-store';
|
|
3
|
+
import * as WebBrowser from 'expo-web-browser';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, } from 'react';
|
|
7
5
|
import { useIMBaseUrl } from '../..';
|
|
6
|
+
import { useRenderTarget } from '../../_shared/renderTarget';
|
|
8
7
|
import { join } from '../../utils/path';
|
|
9
|
-
import
|
|
8
|
+
import { Context as DefaultContext, } from './Context';
|
|
9
|
+
import { IMOAuthError } from './IMOAuthError';
|
|
10
10
|
WebBrowser.maybeCompleteAuthSession();
|
|
11
11
|
const SUCCESS = 'success';
|
|
12
12
|
const EXCEPTION = 'exception';
|
|
13
|
-
const
|
|
13
|
+
const DEFAULT_STORE_KEY = '_example_IMAuthKey';
|
|
14
14
|
const DEFAULT_REMAINING_TIME_TO_RUN_REFRESH = 360000;
|
|
15
15
|
export const IMPrompt = {
|
|
16
16
|
Login: Prompt.Login,
|
|
@@ -51,10 +51,17 @@ const useDiscovery = () => {
|
|
|
51
51
|
};
|
|
52
52
|
}, [encodedBaseUrl]);
|
|
53
53
|
};
|
|
54
|
-
const
|
|
54
|
+
const useStoreConfig = (secureStore) => {
|
|
55
|
+
const storeKey = secureStore?.storeKey;
|
|
56
|
+
const keychainAccessible = secureStore?.keychainAccessible;
|
|
55
57
|
return useMemo(() => {
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
+
return {
|
|
59
|
+
storeKey: storeKey ? storeKey : DEFAULT_STORE_KEY,
|
|
60
|
+
keychainAccessible: keychainAccessible !== void 0
|
|
61
|
+
? keychainAccessible
|
|
62
|
+
: SecureStore.WHEN_UNLOCKED,
|
|
63
|
+
};
|
|
64
|
+
}, [storeKey, keychainAccessible]);
|
|
58
65
|
};
|
|
59
66
|
const useRemainingTimeToRunRefresh = (remainingTimeToRunRefresh) => {
|
|
60
67
|
return useMemo(() => {
|
|
@@ -63,20 +70,26 @@ const useRemainingTimeToRunRefresh = (remainingTimeToRunRefresh) => {
|
|
|
63
70
|
: DEFAULT_REMAINING_TIME_TO_RUN_REFRESH;
|
|
64
71
|
}, [remainingTimeToRunRefresh]);
|
|
65
72
|
};
|
|
66
|
-
const
|
|
73
|
+
const saveTokenStore = async (storeConfig, baseUrl, accessToken, refreshToken, expirationDate) => {
|
|
67
74
|
const item = {
|
|
68
75
|
baseUrl,
|
|
69
76
|
accessToken,
|
|
70
77
|
refreshToken,
|
|
71
78
|
expirationDate,
|
|
72
79
|
};
|
|
73
|
-
return await SecureStore.setItemAsync(
|
|
80
|
+
return await SecureStore.setItemAsync(storeConfig.storeKey, JSON.stringify(item), {
|
|
81
|
+
keychainAccessible: storeConfig.keychainAccessible,
|
|
82
|
+
});
|
|
74
83
|
};
|
|
75
|
-
const
|
|
76
|
-
return await SecureStore.deleteItemAsync(
|
|
84
|
+
const deleteTokenStore = async (storeConfig) => {
|
|
85
|
+
return await SecureStore.deleteItemAsync(storeConfig.storeKey, {
|
|
86
|
+
keychainAccessible: storeConfig.keychainAccessible,
|
|
87
|
+
});
|
|
77
88
|
};
|
|
78
|
-
const
|
|
79
|
-
const state = await SecureStore.getItemAsync(
|
|
89
|
+
const getTokenStore = async (storeConfig) => {
|
|
90
|
+
const state = await SecureStore.getItemAsync(storeConfig.storeKey, {
|
|
91
|
+
keychainAccessible: storeConfig.keychainAccessible,
|
|
92
|
+
});
|
|
80
93
|
if (state == null)
|
|
81
94
|
return;
|
|
82
95
|
const result = JSON.parse(state);
|
|
@@ -116,7 +129,7 @@ const checkExpirationDateOfToken = (expirationDate, remainingTimeToRunRefresh) =
|
|
|
116
129
|
return true;
|
|
117
130
|
return false;
|
|
118
131
|
};
|
|
119
|
-
const useRefresh = (
|
|
132
|
+
const useRefresh = (storeConfig, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, destroy) => {
|
|
120
133
|
const baseUrl = useIMBaseUrl();
|
|
121
134
|
const lockedRef = useRef(false);
|
|
122
135
|
const waitingLineRef = useRef([]);
|
|
@@ -163,7 +176,7 @@ const useRefresh = (storageKey, refreshTokenRef, expirationDateRef, requestConfi
|
|
|
163
176
|
}, discovery);
|
|
164
177
|
const { accessToken, refreshToken, expiresIn } = tokenResponse;
|
|
165
178
|
const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
|
|
166
|
-
await
|
|
179
|
+
await saveTokenStore(storeConfig, baseUrl, accessToken, refreshToken, expirationDate);
|
|
167
180
|
refreshTokenRef.current = refreshToken ? refreshToken : null;
|
|
168
181
|
expirationDateRef.current = expirationDate;
|
|
169
182
|
setToken(accessToken);
|
|
@@ -178,36 +191,49 @@ const useRefresh = (storageKey, refreshTokenRef, expirationDateRef, requestConfi
|
|
|
178
191
|
throw error;
|
|
179
192
|
}
|
|
180
193
|
}
|
|
181
|
-
}, [
|
|
194
|
+
}, [storeConfig, requestConfig, discovery, destroy]);
|
|
182
195
|
};
|
|
183
|
-
const useStartAuth = (
|
|
196
|
+
const useStartAuth = (storeConfig, remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, refresh, setAuthState, authErrorRenderTarget) => {
|
|
184
197
|
const currentBaseUrl = useIMBaseUrl();
|
|
185
|
-
|
|
198
|
+
useEffect(() => {
|
|
186
199
|
(async () => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
200
|
+
try {
|
|
201
|
+
const tokenState = await getTokenStore(storeConfig);
|
|
202
|
+
if (tokenState) {
|
|
203
|
+
const { baseUrl, accessToken, refreshToken, expirationDate } = tokenState;
|
|
204
|
+
const expired = checkExpirationDateOfToken(expirationDate ? expirationDate : 0, remainingTimeToRunRefresh);
|
|
205
|
+
refreshTokenRef.current = refreshToken ? refreshToken : null;
|
|
206
|
+
expirationDateRef.current = expirationDate ? expirationDate : null;
|
|
207
|
+
if (currentBaseUrl === baseUrl) {
|
|
208
|
+
if (expired) {
|
|
209
|
+
await refresh(); // NOTE consideration of how users can catch errors thrown here.
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
setToken(accessToken);
|
|
213
|
+
}
|
|
214
|
+
setAuthState('authorized');
|
|
196
215
|
}
|
|
197
216
|
else {
|
|
198
|
-
|
|
217
|
+
setAuthState('unauthorized');
|
|
199
218
|
}
|
|
200
|
-
setAuthState('authorized');
|
|
201
219
|
}
|
|
202
220
|
else {
|
|
203
221
|
setAuthState('unauthorized');
|
|
204
222
|
}
|
|
205
223
|
}
|
|
206
|
-
|
|
224
|
+
catch (e) {
|
|
207
225
|
setAuthState('unauthorized');
|
|
226
|
+
authErrorRenderTarget.dispatch(new IMOAuthError('an exception occurred while checking the token state.', {
|
|
227
|
+
cause: e,
|
|
228
|
+
}));
|
|
208
229
|
}
|
|
209
230
|
})();
|
|
210
|
-
}, [
|
|
231
|
+
}, [
|
|
232
|
+
storeConfig.storeKey,
|
|
233
|
+
storeConfig.keychainAccessible,
|
|
234
|
+
remainingTimeToRunRefresh,
|
|
235
|
+
refresh,
|
|
236
|
+
]);
|
|
211
237
|
const startAuth = useCallback(async () => {
|
|
212
238
|
const authRequest = await loadAsync({
|
|
213
239
|
...requestConfig,
|
|
@@ -236,7 +262,7 @@ const useStartAuth = (storageKey, remainingTimeToRunRefresh, refreshTokenRef, ex
|
|
|
236
262
|
}, discovery);
|
|
237
263
|
const { accessToken, refreshToken, expiresIn } = tokenResponse;
|
|
238
264
|
const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
|
|
239
|
-
await
|
|
265
|
+
await saveTokenStore(storeConfig, currentBaseUrl, accessToken, refreshToken, expirationDate);
|
|
240
266
|
refreshTokenRef.current = refreshToken ? refreshToken : null;
|
|
241
267
|
expirationDateRef.current = expirationDate;
|
|
242
268
|
setToken(accessToken);
|
|
@@ -256,14 +282,14 @@ const useStartAuth = (storageKey, remainingTimeToRunRefresh, refreshTokenRef, ex
|
|
|
256
282
|
}, [requestConfig, discovery]);
|
|
257
283
|
return startAuth;
|
|
258
284
|
};
|
|
259
|
-
const useDestroy = (
|
|
285
|
+
const useDestroy = (storeConfig, refreshTokenRef, expirationDateRef, setToken, setAuthState) => {
|
|
260
286
|
return useCallback(async () => {
|
|
261
|
-
await
|
|
287
|
+
await deleteTokenStore(storeConfig);
|
|
262
288
|
setToken(null);
|
|
263
289
|
refreshTokenRef.current = null;
|
|
264
290
|
expirationDateRef.current = null;
|
|
265
291
|
setAuthState('unauthorized');
|
|
266
|
-
}, [
|
|
292
|
+
}, [storeConfig, setAuthState]);
|
|
267
293
|
};
|
|
268
294
|
const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh, refresh) => {
|
|
269
295
|
return useCallback(async () => {
|
|
@@ -276,22 +302,23 @@ const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh
|
|
|
276
302
|
return tokenRef.current;
|
|
277
303
|
}, [refresh]);
|
|
278
304
|
};
|
|
279
|
-
export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh,
|
|
305
|
+
export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }) => {
|
|
280
306
|
const Context = oauthContext || DefaultContext;
|
|
281
|
-
const contextRef = useRef();
|
|
307
|
+
const contextRef = useRef(null);
|
|
282
308
|
const authStateRenderTarget = useRenderTarget();
|
|
283
309
|
const [, setAuthState, getAuthState] = useAuthStateRef(authStateRenderTarget);
|
|
284
310
|
const tokenRenderTarget = useRenderTarget();
|
|
285
311
|
const [tokenRef, setToken, getToken] = useTokenRef(tokenRenderTarget);
|
|
286
312
|
const refreshTokenRef = useRef(null);
|
|
287
313
|
const expirationDateRef = useRef(null);
|
|
288
|
-
const
|
|
314
|
+
const storeConfig = useStoreConfig(secureStore);
|
|
289
315
|
const _remainingTimeToRunRefresh = useRemainingTimeToRunRefresh(remainingTimeToRunRefresh);
|
|
290
316
|
const _requestConfig = useRequestConfig(requestConfig);
|
|
291
317
|
const _discovery = useDiscovery();
|
|
292
|
-
const
|
|
293
|
-
const
|
|
294
|
-
const
|
|
318
|
+
const authErrorRenderTarget = useRenderTarget();
|
|
319
|
+
const destroy = useDestroy(storeConfig, refreshTokenRef, expirationDateRef, setToken, setAuthState);
|
|
320
|
+
const refresh = useRefresh(storeConfig, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, destroy);
|
|
321
|
+
const startAuth = useStartAuth(storeConfig, _remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, refresh, setAuthState, authErrorRenderTarget);
|
|
295
322
|
const getTokenAsync = useGetTokenAsync(tokenRef, expirationDateRef, _remainingTimeToRunRefresh, refresh);
|
|
296
323
|
contextRef.current = {
|
|
297
324
|
getAuthState,
|
|
@@ -302,6 +329,7 @@ export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, st
|
|
|
302
329
|
startAuth,
|
|
303
330
|
tokenRenderTarget,
|
|
304
331
|
authStateRenderTarget,
|
|
332
|
+
authErrorRenderTarget,
|
|
305
333
|
};
|
|
306
334
|
return (<Context.Provider value={contextRef.current}>{children}</Context.Provider>);
|
|
307
335
|
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DepartmentPostDepartmentSet, DepartmentPostSearchResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useDepartmentPostSearch: (paramString: string) => (departmentSet: DepartmentPostDepartmentSet, init?: FetchRequestInit) => Promise<DepartmentPostSearchResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DepartmentSearcResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useDepartmentSearch: (paramString: string) => (keyword: string, init?: FetchRequestInit) => Promise<DepartmentSearcResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DepartmentTopSearcResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useDepartmentTopSearch: (paramString: string) => (init?: FetchRequestInit) => Promise<DepartmentTopSearcResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DepartmentSet, PostSearcResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const usePostSearch: (paramString: string) => (departmentSet: DepartmentSet, init?: FetchRequestInit) => Promise<PostSearcResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { PublicGroupRoleSearchResult, PublicGroupRoleSet } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const usePublicGroupRoleSearch: (paramString: string) => (publicGroupSet: PublicGroupRoleSet, init?: FetchRequestInit) => Promise<PublicGroupRoleSearchResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { PublicGroupSearcResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const usePublicGroupSearch: (paramString: string) => (keyword: string, init?: FetchRequestInit) => Promise<PublicGroupSearcResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { PublicGroupTopSearchResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const usePublicGroupTopSearch: (paramString: string) => (init?: FetchRequestInit) => Promise<PublicGroupTopSearchResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { PublicGroupSet, RoleSearchResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useRoleSearch: (paramString: string) => (publicGroupSet: PublicGroupSet, init?: FetchRequestInit) => Promise<RoleSearchResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { UserAdditionalInformationSearchResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useUserAdditionalInformationSearch: (paramString: string) => (userCd: string, init?: FetchRequestInit) => Promise<UserAdditionalInformationSearchResult>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { UserSearchResult } from '../types';
|
|
2
|
-
|
|
2
|
+
import { FetchRequestInit } from 'expo/fetch';
|
|
3
|
+
export declare const useUserSearch: (paramString: string) => (keyword: string, init?: FetchRequestInit) => Promise<UserSearchResult>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
1
2
|
import { Context as DefaultContext } from './Context';
|
|
2
3
|
import { DepartmentPostSearchRecord, DepartmentSearchRecord, PostSearchRecord, PublicGroupSearchRecord, RoleSearchRecord, UserSearchRecord } from './types';
|
|
3
4
|
export type SearchTarget = 'jp.co.intra_mart.master.search.user' | 'jp.co.intra_mart.master.search.company' | 'jp.co.intra_mart.master.search.company_post' | 'jp.co.intra_mart.master.search.department' | 'jp.co.intra_mart.master.search.public_group' | 'jp.co.intra_mart.master.search.private_group' | 'jp.co.intra_mart.master.search.public_group_role' | 'jp.co.intra_mart.master.search.role' | 'jp.co.intra_mart.master.search.attached_department_post' | 'jp.co.intra_mart.master.search.attached_public_group_role' | undefined;
|
|
4
5
|
export type SearchType = 'single' | 'multiple';
|
|
5
|
-
declare const useLock: () => import("react").
|
|
6
|
+
declare const useLock: () => import("react").RefObject<boolean>;
|
|
6
7
|
declare const useVisible: () => [boolean, import("react").Dispatch<import("react").SetStateAction<boolean>>];
|
|
7
8
|
declare const useSearchTarget: () => [SearchTarget, import("react").Dispatch<import("react").SetStateAction<SearchTarget>>];
|
|
8
9
|
declare const useSearchType: () => [SearchType, import("react").Dispatch<import("react").SetStateAction<SearchType>>];
|
|
@@ -44,5 +45,5 @@ interface IMSearchProps {
|
|
|
44
45
|
searchContext?: typeof DefaultContext;
|
|
45
46
|
SearchComponent: (props: SelectSearchProps) => JSX.Element;
|
|
46
47
|
}
|
|
47
|
-
export declare const IMSearch: ({ children, searchContext, SearchComponent, }: IMSearchProps) =>
|
|
48
|
+
export declare const IMSearch: ({ children, searchContext, SearchComponent, }: IMSearchProps) => JSX.Element;
|
|
48
49
|
export {};
|
|
@@ -53,7 +53,7 @@ const useSearch = (setIsVisible, setSearchTarget, setSearchType, setParamString,
|
|
|
53
53
|
};
|
|
54
54
|
export const IMSearch = ({ children, searchContext, SearchComponent, }) => {
|
|
55
55
|
const Context = searchContext || DefaultContext;
|
|
56
|
-
const contextRef = useRef();
|
|
56
|
+
const contextRef = useRef(null);
|
|
57
57
|
const lockRef = useLock();
|
|
58
58
|
const [isVisible, setIsVisible] = useVisible();
|
|
59
59
|
const [searchTarget, setSearchTarget] = useSearchTarget();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetchResponse } from 'expo/build/winter/fetch/FetchResponse';
|
|
1
2
|
export interface SuccessResponse<T> {
|
|
2
3
|
error: false;
|
|
3
4
|
message: string;
|
|
@@ -10,7 +11,7 @@ export interface Success<T> {
|
|
|
10
11
|
export interface Error {
|
|
11
12
|
readonly type: 'error';
|
|
12
13
|
readonly detail: unknown;
|
|
13
|
-
readonly response:
|
|
14
|
+
readonly response: FetchResponse;
|
|
14
15
|
}
|
|
15
16
|
export interface Exception {
|
|
16
17
|
readonly type: 'exception';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
1
2
|
import { Context as DefaultContext } from './Context';
|
|
2
3
|
export interface SessionResponse {
|
|
3
4
|
error: boolean;
|
|
@@ -13,4 +14,4 @@ export interface IMSessionProps {
|
|
|
13
14
|
children: JSX.Element;
|
|
14
15
|
sessionContext?: typeof DefaultContext;
|
|
15
16
|
}
|
|
16
|
-
export declare const IMSession: ({ children, sessionContext }: IMSessionProps) =>
|
|
17
|
+
export declare const IMSession: ({ children, sessionContext }: IMSessionProps) => JSX.Element;
|
|
@@ -37,26 +37,33 @@ const useSessionStateRef = (renderTarget) => {
|
|
|
37
37
|
};
|
|
38
38
|
const useLogout = () => {
|
|
39
39
|
const imFetch = useIMFetch({ noValidate: true });
|
|
40
|
-
return useCallback((cookie) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
return useCallback(async (cookie) => {
|
|
41
|
+
const headers = cookie
|
|
42
|
+
? { Cookie: cookie }
|
|
43
|
+
: {};
|
|
44
|
+
await imFetch('/logout', {
|
|
45
|
+
credentials: 'include',
|
|
46
|
+
headers: headers,
|
|
45
47
|
method: 'GET',
|
|
46
48
|
});
|
|
47
|
-
}, []);
|
|
49
|
+
}, [imFetch]);
|
|
48
50
|
};
|
|
49
51
|
const makeEncodeParams = (clientTypeId = 'pc') => {
|
|
50
52
|
return `${`clientTypeId=${encodeURIComponent(clientTypeId)}`}`;
|
|
51
53
|
};
|
|
52
|
-
const useRequest = (setter, getter) => {
|
|
54
|
+
const useRequest = (setter, getter, logout) => {
|
|
53
55
|
const imFetch = useIMFetch();
|
|
54
|
-
const logout = useLogout();
|
|
55
56
|
const request = useCallback(async (clientTypeId) => {
|
|
56
57
|
try {
|
|
57
58
|
const currentCookies = getter()?.cookies;
|
|
59
|
+
const cookie = currentCookies ? makeCookie(currentCookies) : null;
|
|
60
|
+
// previous session may still be active, so execute the logout process
|
|
61
|
+
await logout();
|
|
62
|
+
if (cookie)
|
|
63
|
+
await logout(cookie);
|
|
58
64
|
const params = makeEncodeParams(clientTypeId);
|
|
59
65
|
const response = await imFetch(`api/bearer/smacolow/session?${params}`, {
|
|
66
|
+
credentials: 'include',
|
|
60
67
|
headers: {
|
|
61
68
|
Accept: 'application/json',
|
|
62
69
|
'X-Intramart-Session': 'keep', // https://document.intra-mart.jp/library/iap/public/im_web_api_maker/im_web_api_maker_programming_guide/texts/how_to_use_api/index.html#session-management
|
|
@@ -69,8 +76,6 @@ const useRequest = (setter, getter) => {
|
|
|
69
76
|
const cookie = response.headers.get('Set-Cookie');
|
|
70
77
|
if (cookie) {
|
|
71
78
|
setter(cookie);
|
|
72
|
-
if (currentCookies)
|
|
73
|
-
logout(makeCookie(currentCookies));
|
|
74
79
|
return { status: 'success' };
|
|
75
80
|
}
|
|
76
81
|
throw new IMSessionError('could not find sessionid from Set-Cookie in response header.');
|
|
@@ -84,20 +89,18 @@ const useRequest = (setter, getter) => {
|
|
|
84
89
|
}, [imFetch]);
|
|
85
90
|
return request;
|
|
86
91
|
};
|
|
87
|
-
const useDestroy = (renderTarget, setter, getter) => {
|
|
88
|
-
|
|
89
|
-
return useCallback(() => {
|
|
92
|
+
const useDestroy = (renderTarget, setter, getter, logout) => {
|
|
93
|
+
return useCallback(async () => {
|
|
90
94
|
const { cookies } = getter();
|
|
91
95
|
if (cookies) {
|
|
92
|
-
logout(makeCookie(cookies));
|
|
96
|
+
await logout(makeCookie(cookies));
|
|
93
97
|
}
|
|
94
98
|
setter(null);
|
|
95
99
|
renderTarget.dispatch();
|
|
96
100
|
}, []);
|
|
97
101
|
};
|
|
98
|
-
const useGetSessionAsync = (request, destroy, getter) => {
|
|
102
|
+
const useGetSessionAsync = (request, destroy, getter, logout) => {
|
|
99
103
|
const imFetch = useIMFetch({ noValidate: true });
|
|
100
|
-
const logout = useLogout();
|
|
101
104
|
const reRequest = async (count) => {
|
|
102
105
|
const { status } = await request();
|
|
103
106
|
if (status === 'success') {
|
|
@@ -114,8 +117,10 @@ const useGetSessionAsync = (request, destroy, getter) => {
|
|
|
114
117
|
const { cookies } = getter();
|
|
115
118
|
if (cookies) {
|
|
116
119
|
const response = await imFetch('api/smacolow/session', {
|
|
120
|
+
credentials: 'include',
|
|
117
121
|
headers: {
|
|
118
122
|
Cookie: makeCookie(cookies),
|
|
123
|
+
'X-Intramart-Session': 'keep', // https://document.intra-mart.jp/library/iap/public/im_web_api_maker/im_web_api_maker_programming_guide/texts/how_to_use_api/index.html#session-management
|
|
119
124
|
},
|
|
120
125
|
method: 'GET',
|
|
121
126
|
});
|
|
@@ -123,7 +128,7 @@ const useGetSessionAsync = (request, destroy, getter) => {
|
|
|
123
128
|
return getter();
|
|
124
129
|
}
|
|
125
130
|
else {
|
|
126
|
-
logout(makeCookie(cookies));
|
|
131
|
+
await logout(makeCookie(cookies));
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
const status = await reRequest(0);
|
|
@@ -133,8 +138,7 @@ const useGetSessionAsync = (request, destroy, getter) => {
|
|
|
133
138
|
throw new IMSessionError('failed to get session.');
|
|
134
139
|
}, [request]);
|
|
135
140
|
};
|
|
136
|
-
const unmountEffect = (getter) => {
|
|
137
|
-
const logout = useLogout();
|
|
141
|
+
const unmountEffect = (getter, logout) => {
|
|
138
142
|
const { cookies } = getter();
|
|
139
143
|
useEffect(() => {
|
|
140
144
|
return () => {
|
|
@@ -146,13 +150,14 @@ const unmountEffect = (getter) => {
|
|
|
146
150
|
};
|
|
147
151
|
export const IMSession = ({ children, sessionContext }) => {
|
|
148
152
|
const Context = sessionContext || DefaultContext;
|
|
149
|
-
const contextRef = useRef();
|
|
153
|
+
const contextRef = useRef(null);
|
|
150
154
|
const sessionStateRenderTarget = useRenderTarget();
|
|
151
155
|
const [, setSession, getSession] = useSessionStateRef(sessionStateRenderTarget);
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
+
const logout = useLogout();
|
|
157
|
+
const request = useRequest(setSession, getSession, logout);
|
|
158
|
+
const destroy = useDestroy(sessionStateRenderTarget, setSession, getSession, logout);
|
|
159
|
+
const getSessionAsync = useGetSessionAsync(request, destroy, getSession, logout);
|
|
160
|
+
unmountEffect(getSession, logout);
|
|
156
161
|
contextRef.current = {
|
|
157
162
|
getSession,
|
|
158
163
|
getSessionAsync,
|
|
@@ -3,6 +3,7 @@ import { IMOAuth } from '../OAuth';
|
|
|
3
3
|
import { IMSession } from '../Session';
|
|
4
4
|
import { IMSearch } from '../Search';
|
|
5
5
|
import { IMTenant } from '../Tenant';
|
|
6
|
+
import { JSX } from 'react';
|
|
6
7
|
interface SmartlimeProps {
|
|
7
8
|
children: JSX.Element;
|
|
8
9
|
baseUrl: string;
|
|
@@ -16,5 +17,5 @@ interface SmartlimeProps {
|
|
|
16
17
|
imsession?: Omit<React.ComponentProps<typeof IMSession>, 'children'>;
|
|
17
18
|
imseach?: Omit<React.ComponentProps<typeof IMSearch>, 'children'>;
|
|
18
19
|
}
|
|
19
|
-
export declare const Smartlime: ({ children, baseUrl, tenantId, imtenant, imoauth, imme, imsession, imseach, }: SmartlimeProps) =>
|
|
20
|
+
export declare const Smartlime: ({ children, baseUrl, tenantId, imtenant, imoauth, imme, imsession, imseach, }: SmartlimeProps) => JSX.Element;
|
|
20
21
|
export {};
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { FetchModuleState, Moudles } from '.';
|
|
2
1
|
import { RenderTarget } from '../../_shared/renderTarget';
|
|
2
|
+
import { ModuleIds } from './modulesType';
|
|
3
|
+
export interface IMModule {
|
|
4
|
+
moduleId: ModuleIds[number];
|
|
5
|
+
version: string;
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
others: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type IMModules = {
|
|
10
|
+
[key in ModuleIds[number]]: IMModule;
|
|
11
|
+
};
|
|
3
12
|
export interface TenantContext {
|
|
4
13
|
getBaseUrl: () => string;
|
|
5
14
|
getTenantId: () => string | undefined;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fetchModuleInfo: () => Promise<void>;
|
|
15
|
+
getModules: () => IMModules | undefined;
|
|
16
|
+
setModules: (state: IMModules, silent?: boolean) => void;
|
|
17
|
+
destroyModule: () => Promise<void>;
|
|
10
18
|
modulesStateRenderTarget: RenderTarget;
|
|
11
19
|
}
|
|
12
20
|
export declare const Context: import("react").Context<TenantContext | null>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './useIMBaseUrl';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './useIMModules';
|
|
3
|
+
export * from './useIMModulesState';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './useIMBaseUrl';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './useIMModules';
|
|
3
|
+
export * from './useIMModulesState';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { useIMFetch } from '../../Fetch';
|
|
4
|
+
import { createStorageKey } from '../constants';
|
|
5
|
+
import { Context as DefaultContext } from '../Context';
|
|
6
|
+
import { IMTenantError } from '../IMTenantError';
|
|
7
|
+
import { MODULE_IDS } from '../modulesType';
|
|
8
|
+
const saveModuleStorage = async (storageKey, Modules) => {
|
|
9
|
+
return await AsyncStorage.setItem(storageKey, JSON.stringify(Modules));
|
|
10
|
+
};
|
|
11
|
+
const getModuleStorage = async (storageKey) => {
|
|
12
|
+
const state = await AsyncStorage.getItem(storageKey);
|
|
13
|
+
if (state == null)
|
|
14
|
+
return;
|
|
15
|
+
const result = JSON.parse(state);
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const createInitialModules = () => {
|
|
19
|
+
const initState = MODULE_IDS.reduce((acc, moduleId) => {
|
|
20
|
+
acc[moduleId] = {
|
|
21
|
+
moduleId: moduleId,
|
|
22
|
+
version: '',
|
|
23
|
+
enabled: false,
|
|
24
|
+
others: {},
|
|
25
|
+
};
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
return initState;
|
|
29
|
+
};
|
|
30
|
+
const useRequestModule = (baseUrl, setModules) => {
|
|
31
|
+
const IMFetch = useIMFetch();
|
|
32
|
+
return async () => {
|
|
33
|
+
const storageKey = createStorageKey(baseUrl);
|
|
34
|
+
const storageState = await getModuleStorage(storageKey);
|
|
35
|
+
if (storageState) {
|
|
36
|
+
setModules(storageState);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const response = await IMFetch('api/smacolow/modules');
|
|
40
|
+
if (response.status === 404) {
|
|
41
|
+
const state = createInitialModules();
|
|
42
|
+
saveModuleStorage(storageKey, state);
|
|
43
|
+
setModules(state);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (response.status !== 200) {
|
|
47
|
+
throw new IMTenantError('failed to fetch module status.');
|
|
48
|
+
}
|
|
49
|
+
const result = await response.json();
|
|
50
|
+
const state = result.data.modules.reduce((acc, module) => {
|
|
51
|
+
const { moduleId, moduleVersion } = module;
|
|
52
|
+
acc[moduleId] = {
|
|
53
|
+
moduleId: moduleId,
|
|
54
|
+
version: moduleVersion,
|
|
55
|
+
enabled: true,
|
|
56
|
+
others: {},
|
|
57
|
+
};
|
|
58
|
+
return acc;
|
|
59
|
+
}, createInitialModules());
|
|
60
|
+
saveModuleStorage(storageKey, state);
|
|
61
|
+
setModules(state);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export const useIMModules = (Context) => {
|
|
66
|
+
const tenantContext = useContext(Context || DefaultContext);
|
|
67
|
+
if (tenantContext == null) {
|
|
68
|
+
throw new IMTenantError('useIMModules requires either a Context provide or an ancestor element with a IMTenantProvider.');
|
|
69
|
+
}
|
|
70
|
+
const requestModule = useRequestModule(tenantContext.getBaseUrl(), tenantContext.setModules);
|
|
71
|
+
return useMemo(() => {
|
|
72
|
+
const { getModules, destroyModule } = tenantContext;
|
|
73
|
+
return {
|
|
74
|
+
request: requestModule,
|
|
75
|
+
getModules,
|
|
76
|
+
destroy: destroyModule,
|
|
77
|
+
};
|
|
78
|
+
}, [tenantContext]);
|
|
79
|
+
};
|