@intra-mart/smartlime 0.0.1-beta

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 (121) hide show
  1. package/.gitattributes +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +7 -0
  4. package/lib/_shared/renderTarget.d.ts +14 -0
  5. package/lib/_shared/renderTarget.js +31 -0
  6. package/lib/index.d.ts +14 -0
  7. package/lib/index.js +18 -0
  8. package/lib/packages/Fetch/IMFecthError.d.ts +4 -0
  9. package/lib/packages/Fetch/IMFecthError.js +10 -0
  10. package/lib/packages/Fetch/index.d.ts +14 -0
  11. package/lib/packages/Fetch/index.js +112 -0
  12. package/lib/packages/Me/Context.d.ts +10 -0
  13. package/lib/packages/Me/Context.js +2 -0
  14. package/lib/packages/Me/IMMeError.d.ts +4 -0
  15. package/lib/packages/Me/IMMeError.js +10 -0
  16. package/lib/packages/Me/hooks/index.d.ts +2 -0
  17. package/lib/packages/Me/hooks/index.js +2 -0
  18. package/lib/packages/Me/hooks/useMe.d.ts +6 -0
  19. package/lib/packages/Me/hooks/useMe.js +11 -0
  20. package/lib/packages/Me/hooks/useMeState.d.ts +2 -0
  21. package/lib/packages/Me/hooks/useMeState.js +21 -0
  22. package/lib/packages/Me/index.d.ts +22 -0
  23. package/lib/packages/Me/index.js +55 -0
  24. package/lib/packages/Me/type.d.ts +85 -0
  25. package/lib/packages/Me/type.js +1 -0
  26. package/lib/packages/OAuth/Context.d.ts +14 -0
  27. package/lib/packages/OAuth/Context.js +2 -0
  28. package/lib/packages/OAuth/IMOAuthError.d.ts +4 -0
  29. package/lib/packages/OAuth/IMOAuthError.js +10 -0
  30. package/lib/packages/OAuth/hooks/index.d.ts +5 -0
  31. package/lib/packages/OAuth/hooks/index.js +5 -0
  32. package/lib/packages/OAuth/hooks/useAuthState.d.ts +2 -0
  33. package/lib/packages/OAuth/hooks/useAuthState.js +25 -0
  34. package/lib/packages/OAuth/hooks/useAuthStateEffect.d.ts +6 -0
  35. package/lib/packages/OAuth/hooks/useAuthStateEffect.js +14 -0
  36. package/lib/packages/OAuth/hooks/useIMOAuth.d.ts +7 -0
  37. package/lib/packages/OAuth/hooks/useIMOAuth.js +13 -0
  38. package/lib/packages/OAuth/hooks/useIMToken.d.ts +2 -0
  39. package/lib/packages/OAuth/hooks/useIMToken.js +21 -0
  40. package/lib/packages/OAuth/hooks/useStartAuth.d.ts +2 -0
  41. package/lib/packages/OAuth/hooks/useStartAuth.js +12 -0
  42. package/lib/packages/OAuth/index.d.ts +39 -0
  43. package/lib/packages/OAuth/index.js +299 -0
  44. package/lib/packages/Search/Context.d.ts +6 -0
  45. package/lib/packages/Search/Context.js +2 -0
  46. package/lib/packages/Search/IMSearchError.d.ts +4 -0
  47. package/lib/packages/Search/IMSearchError.js +10 -0
  48. package/lib/packages/Search/hooks/index.d.ts +11 -0
  49. package/lib/packages/Search/hooks/index.js +11 -0
  50. package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -0
  51. package/lib/packages/Search/hooks/useDepartmentPostSearch.js +48 -0
  52. package/lib/packages/Search/hooks/useDepartmentSerch.d.ts +2 -0
  53. package/lib/packages/Search/hooks/useDepartmentSerch.js +56 -0
  54. package/lib/packages/Search/hooks/useDepartmentTopSerch.d.ts +2 -0
  55. package/lib/packages/Search/hooks/useDepartmentTopSerch.js +47 -0
  56. package/lib/packages/Search/hooks/useIMSearch.d.ts +4 -0
  57. package/lib/packages/Search/hooks/useIMSearch.js +11 -0
  58. package/lib/packages/Search/hooks/usePostSerch.d.ts +2 -0
  59. package/lib/packages/Search/hooks/usePostSerch.js +48 -0
  60. package/lib/packages/Search/hooks/usePublicGroupRoleSerch.d.ts +2 -0
  61. package/lib/packages/Search/hooks/usePublicGroupRoleSerch.js +50 -0
  62. package/lib/packages/Search/hooks/usePublicGroupSerch.d.ts +2 -0
  63. package/lib/packages/Search/hooks/usePublicGroupSerch.js +56 -0
  64. package/lib/packages/Search/hooks/usePublicGroupTopSerch.d.ts +2 -0
  65. package/lib/packages/Search/hooks/usePublicGroupTopSerch.js +47 -0
  66. package/lib/packages/Search/hooks/useRoleSerch.d.ts +2 -0
  67. package/lib/packages/Search/hooks/useRoleSerch.js +50 -0
  68. package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.d.ts +2 -0
  69. package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.js +50 -0
  70. package/lib/packages/Search/hooks/useUserSerch.d.ts +2 -0
  71. package/lib/packages/Search/hooks/useUserSerch.js +68 -0
  72. package/lib/packages/Search/hooks/utils.d.ts +4 -0
  73. package/lib/packages/Search/hooks/utils.js +25 -0
  74. package/lib/packages/Search/index.d.ts +49 -0
  75. package/lib/packages/Search/index.js +72 -0
  76. package/lib/packages/Search/types.d.ts +208 -0
  77. package/lib/packages/Search/types.js +1 -0
  78. package/lib/packages/Session/Context.d.ts +16 -0
  79. package/lib/packages/Session/Context.js +2 -0
  80. package/lib/packages/Session/IMSessionError.d.ts +4 -0
  81. package/lib/packages/Session/IMSessionError.js +10 -0
  82. package/lib/packages/Session/hooks/index.d.ts +2 -0
  83. package/lib/packages/Session/hooks/index.js +2 -0
  84. package/lib/packages/Session/hooks/useSession.d.ts +12 -0
  85. package/lib/packages/Session/hooks/useSession.js +11 -0
  86. package/lib/packages/Session/hooks/useSessionState.d.ts +4 -0
  87. package/lib/packages/Session/hooks/useSessionState.js +24 -0
  88. package/lib/packages/Session/index.d.ts +16 -0
  89. package/lib/packages/Session/index.js +164 -0
  90. package/lib/packages/Session/type.d.ts +5 -0
  91. package/lib/packages/Session/type.js +1 -0
  92. package/lib/packages/Session/utils.d.ts +2 -0
  93. package/lib/packages/Session/utils.js +6 -0
  94. package/lib/packages/Smartlime/NotSearchPropError.d.ts +2 -0
  95. package/lib/packages/Smartlime/NotSearchPropError.js +13 -0
  96. package/lib/packages/Smartlime/index.d.ts +19 -0
  97. package/lib/packages/Smartlime/index.js +23 -0
  98. package/lib/packages/Tenant/Context.d.ts +6 -0
  99. package/lib/packages/Tenant/Context.js +2 -0
  100. package/lib/packages/Tenant/IMTenantError.d.ts +4 -0
  101. package/lib/packages/Tenant/IMTenantError.js +10 -0
  102. package/lib/packages/Tenant/hooks/index.d.ts +1 -0
  103. package/lib/packages/Tenant/hooks/index.js +1 -0
  104. package/lib/packages/Tenant/hooks/useIMBaseUrl.d.ts +2 -0
  105. package/lib/packages/Tenant/hooks/useIMBaseUrl.js +10 -0
  106. package/lib/packages/Tenant/index.d.ts +10 -0
  107. package/lib/packages/Tenant/index.js +19 -0
  108. package/lib/packages/WebView/IMWebViewError.d.ts +4 -0
  109. package/lib/packages/WebView/IMWebViewError.js +10 -0
  110. package/lib/packages/WebView/hooks/index.d.ts +1 -0
  111. package/lib/packages/WebView/hooks/index.js +1 -0
  112. package/lib/packages/WebView/hooks/useHackSearchUI.d.ts +8 -0
  113. package/lib/packages/WebView/hooks/useHackSearchUI.js +49 -0
  114. package/lib/packages/WebView/index.d.ts +11 -0
  115. package/lib/packages/WebView/index.js +166 -0
  116. package/lib/utils/mergeRef.d.ts +1 -0
  117. package/lib/utils/mergeRef.js +14 -0
  118. package/lib/utils/path.d.ts +1 -0
  119. package/lib/utils/path.js +16 -0
  120. package/package.json +87 -0
  121. package/tsconfig.json +36 -0
@@ -0,0 +1,21 @@
1
+ import { useContext, useEffect, useReducer, useRef } from 'react';
2
+ import { Context as DefaultContext } from '../Context';
3
+ import { IMOAuthError } from '../IMOAuthError';
4
+ export const useIMToken = (Context) => {
5
+ const initRef = useRef(true);
6
+ const [, forceRender] = useReducer((s) => s + 1, 0);
7
+ const oauthContext = useContext(Context || DefaultContext);
8
+ if (oauthContext == null) {
9
+ throw new IMOAuthError('useIMToken requires either a Context provide or an ancestor element with a IMOAuthProvider.');
10
+ }
11
+ if (initRef.current) {
12
+ initRef.current = false;
13
+ oauthContext.authStateRenderTarget.addEventListener(forceRender);
14
+ }
15
+ useEffect(() => {
16
+ return () => {
17
+ oauthContext.tokenRenderTarget.removeEventListener(forceRender);
18
+ };
19
+ }, []);
20
+ return oauthContext.getToken();
21
+ };
@@ -0,0 +1,2 @@
1
+ import { Context as DefaultContext } from '../Context';
2
+ export declare const useStartAuth: (Context?: typeof DefaultContext) => () => Promise<import("..").StartAuthResult>;
@@ -0,0 +1,12 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { Context as DefaultContext } from '../Context';
3
+ import { IMOAuthError } from '../IMOAuthError';
4
+ export const useStartAuth = (Context) => {
5
+ const oauthContext = useContext(Context || DefaultContext);
6
+ if (oauthContext == null) {
7
+ throw new IMOAuthError('useStartAuth requires either a Context provide or an ancestor element with a IMOAuthProvider.');
8
+ }
9
+ return useMemo(() => {
10
+ return oauthContext.startAuth;
11
+ }, [oauthContext.startAuth]);
12
+ };
@@ -0,0 +1,39 @@
1
+ /// <reference types="react" />
2
+ import { AuthSessionResult, Prompt } from 'expo-auth-session';
3
+ import { Context as DefaultContext } from './Context';
4
+ export type AuthState = 'initializing' | 'unauthorized' | 'authorized';
5
+ export type TokenState = {
6
+ baseUrl: string;
7
+ accessToken: string;
8
+ refreshToken?: string;
9
+ expirationDate?: number;
10
+ };
11
+ export type StartAuthResult = {
12
+ readonly type: 'cancel' | 'dismiss' | 'opened' | 'locked' | 'error';
13
+ readonly detail: AuthSessionResult;
14
+ } | {
15
+ readonly type: 'success';
16
+ } | {
17
+ readonly type: 'exception';
18
+ readonly exceptionDetail: unknown;
19
+ };
20
+ export declare const IMPrompt: {
21
+ readonly Login: Prompt.Login;
22
+ };
23
+ interface RequestConfig {
24
+ redirectUri: string;
25
+ clientId: string;
26
+ clientSecret: string;
27
+ scopes: string[];
28
+ state?: string;
29
+ prompt?: Prompt.Login;
30
+ }
31
+ interface IMOAuthProps {
32
+ children: JSX.Element;
33
+ requestConfig: RequestConfig;
34
+ remainingTimeToRunRefresh?: number;
35
+ storageKey?: string;
36
+ oauthContext?: typeof DefaultContext;
37
+ }
38
+ export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, storageKey, oauthContext, }: IMOAuthProps) => JSX.Element;
39
+ export {};
@@ -0,0 +1,299 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import { exchangeCodeAsync, loadAsync, Prompt, refreshAsync, } from 'expo-auth-session';
3
+ import { useCallback, useLayoutEffect, useMemo, useRef, } from 'react';
4
+ import { Context as DefaultContext } from './Context';
5
+ import { IMOAuthError } from './IMOAuthError';
6
+ import { useRenderTarget } from '../../_shared/renderTarget';
7
+ import { useIMBaseUrl } from '../..';
8
+ import { join } from '../../utils/path';
9
+ const SUCCESS = 'success';
10
+ const EXCEPTION = 'exception';
11
+ const DEFAULT_STORAGE_KEY = '@example:IMAuthKey';
12
+ const DEFAULT_REMAINING_TIME_TO_RUN_REFRESH = 360000;
13
+ export const IMPrompt = {
14
+ Login: Prompt.Login,
15
+ };
16
+ const baseRequestConfig = {
17
+ responseType: 'code',
18
+ usePKCE: true,
19
+ };
20
+ const useRequestConfig = (userProps) => {
21
+ return useMemo(() => {
22
+ return {
23
+ ...baseRequestConfig,
24
+ ...userProps,
25
+ extraParams: {
26
+ redirect_uri: userProps.redirectUri,
27
+ },
28
+ };
29
+ }, [userProps]);
30
+ };
31
+ const encodeBaseURI = () => {
32
+ const baseUrl = useIMBaseUrl();
33
+ return useMemo(() => {
34
+ return encodeURI(baseUrl);
35
+ }, [baseUrl]);
36
+ };
37
+ const useDiscovery = () => {
38
+ const encodedBaseUrl = encodeBaseURI();
39
+ return useMemo(() => {
40
+ return {
41
+ authorizationEndpoint: join(encodedBaseUrl, '/oauth/authorize'),
42
+ tokenEndpoint: join(encodedBaseUrl, '/oauth/token'),
43
+ };
44
+ }, [encodedBaseUrl]);
45
+ };
46
+ const useStorageKey = (storageKey) => {
47
+ return useMemo(() => {
48
+ return storageKey ? storageKey : DEFAULT_STORAGE_KEY;
49
+ }, [storageKey]);
50
+ };
51
+ const useRemainingTimeToRunRefresh = (remainingTimeToRunRefresh) => {
52
+ return useMemo(() => {
53
+ return remainingTimeToRunRefresh
54
+ ? remainingTimeToRunRefresh
55
+ : DEFAULT_REMAINING_TIME_TO_RUN_REFRESH;
56
+ }, [remainingTimeToRunRefresh]);
57
+ };
58
+ const saveTokenStorage = async (storageKey, baseUrl, accessToken, refreshToken, expirationDate) => {
59
+ const item = {
60
+ baseUrl,
61
+ accessToken,
62
+ refreshToken,
63
+ expirationDate,
64
+ };
65
+ return await AsyncStorage.setItem(storageKey, JSON.stringify(item));
66
+ };
67
+ const deleteTokenStorage = async (tokenStorageKey) => {
68
+ return await AsyncStorage.removeItem(tokenStorageKey);
69
+ };
70
+ const getTokenStorage = async (storageKey) => {
71
+ const state = await AsyncStorage.getItem(storageKey);
72
+ if (state == null)
73
+ return;
74
+ const result = JSON.parse(state);
75
+ return result;
76
+ };
77
+ const useAuthStateRef = (renderTarget) => {
78
+ const ref = useRef('initializing');
79
+ const setter = useCallback((state, silent) => {
80
+ if (ref.current === state)
81
+ return;
82
+ ref.current = state;
83
+ if (!silent)
84
+ renderTarget.dispatch();
85
+ }, []);
86
+ const getter = useCallback(() => ref.current, []);
87
+ return [ref, setter, getter];
88
+ };
89
+ const useTokenRef = (renderTarget) => {
90
+ const ref = useRef(null);
91
+ const setter = useCallback((token, silent) => {
92
+ if (ref.current === token)
93
+ return;
94
+ ref.current = token;
95
+ if (!silent)
96
+ renderTarget.dispatch();
97
+ }, []);
98
+ const getter = useCallback(() => ref.current, []);
99
+ return [ref, setter, getter];
100
+ };
101
+ const createExpirationDate = (expiresIn) => {
102
+ const nowData = new Date().getTime();
103
+ return nowData + expiresIn * 1000;
104
+ };
105
+ const checkExpirationDateOfToken = (expirationDate, remainingTimeToRunRefresh) => {
106
+ const nowData = new Date().getTime();
107
+ if (remainingTimeToRunRefresh > expirationDate - nowData)
108
+ return true;
109
+ return false;
110
+ };
111
+ const useRefresh = (storageKey, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, destroy) => {
112
+ const baseUrl = useIMBaseUrl();
113
+ const lockedRef = useRef(false);
114
+ const waitingLineRef = useRef([]);
115
+ const lock = useCallback(() => {
116
+ lockedRef.current = true;
117
+ }, []);
118
+ const unlock = useCallback((error) => {
119
+ if (error) {
120
+ waitingLineRef.current.forEach((v) => {
121
+ v.reject(error);
122
+ });
123
+ }
124
+ else {
125
+ waitingLineRef.current.forEach((v) => {
126
+ v.resolve();
127
+ });
128
+ }
129
+ waitingLineRef.current = [];
130
+ lockedRef.current = false;
131
+ }, []);
132
+ return useCallback(async () => {
133
+ if (refreshTokenRef.current == null)
134
+ throw new IMOAuthError('refresh token does not exist.');
135
+ if (lockedRef.current === true) {
136
+ return new Promise((resolve, reject) => {
137
+ waitingLineRef.current.push({ resolve, reject });
138
+ });
139
+ }
140
+ else {
141
+ lock();
142
+ try {
143
+ // HACK & WARNING
144
+ // currently (expo-auth-session@3.3.1), clientId and clientSecret are ignored due to a bug, so set them to extraParams and process them once.
145
+ // RefreshTokenRequest's getQueryBody only considers refresh_token and sends only refresh_token.
146
+ // set it to extraParams, it works.
147
+ const tokenResponse = await refreshAsync({
148
+ clientId: requestConfig.clientId,
149
+ // clientSecret: requestConfig.clientSecret,
150
+ refreshToken: refreshTokenRef.current,
151
+ extraParams: {
152
+ // client_id: requestConfig.clientId,
153
+ client_secret: requestConfig.clientSecret,
154
+ },
155
+ }, discovery);
156
+ const { accessToken, refreshToken, expiresIn } = tokenResponse;
157
+ const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
158
+ await saveTokenStorage(storageKey, baseUrl, accessToken, refreshToken, expirationDate);
159
+ refreshTokenRef.current = refreshToken ? refreshToken : null;
160
+ expirationDateRef.current = expirationDate;
161
+ setToken(accessToken);
162
+ unlock();
163
+ }
164
+ catch (e) {
165
+ destroy();
166
+ const error = new IMOAuthError('an exception occurred while refreshing the token.', {
167
+ cause: e instanceof Error ? e : undefined,
168
+ });
169
+ unlock(error);
170
+ throw error;
171
+ }
172
+ }
173
+ }, [storageKey, requestConfig, discovery, destroy]);
174
+ };
175
+ const useStartAuth = (storageKey, remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, refresh, setAuthState) => {
176
+ const currentBaseUrl = useIMBaseUrl();
177
+ useLayoutEffect(() => {
178
+ (async () => {
179
+ const tokenState = await getTokenStorage(storageKey);
180
+ if (tokenState) {
181
+ const { baseUrl, accessToken, refreshToken, expirationDate } = tokenState;
182
+ const expired = checkExpirationDateOfToken(expirationDate ? expirationDate : 0, remainingTimeToRunRefresh);
183
+ refreshTokenRef.current = refreshToken ? refreshToken : null;
184
+ expirationDateRef.current = expirationDate ? expirationDate : null;
185
+ if (currentBaseUrl === baseUrl) {
186
+ if (expired) {
187
+ await refresh(); // NOTE consideration of how users can catch errors thrown here.
188
+ }
189
+ else {
190
+ setToken(accessToken);
191
+ }
192
+ setAuthState('authorized');
193
+ }
194
+ else {
195
+ setAuthState('unauthorized');
196
+ }
197
+ }
198
+ else {
199
+ setAuthState('unauthorized');
200
+ }
201
+ })();
202
+ }, [storageKey, remainingTimeToRunRefresh, refresh]);
203
+ const startAuth = useCallback(async () => {
204
+ const authRequest = await loadAsync({
205
+ ...requestConfig,
206
+ }, discovery);
207
+ try {
208
+ const authSessionResult = await authRequest.promptAsync(discovery);
209
+ if (authSessionResult.type !== SUCCESS) {
210
+ const failedResult = {
211
+ type: authSessionResult.type,
212
+ detail: authSessionResult,
213
+ };
214
+ return failedResult;
215
+ }
216
+ if (authSessionResult.params.code == null ||
217
+ authSessionResult.params.state == null ||
218
+ authRequest.codeVerifier == null) {
219
+ throw new IMOAuthError('required parameter is missing in authSessionResult.');
220
+ }
221
+ const tokenResponse = await exchangeCodeAsync({
222
+ ...requestConfig,
223
+ code: authSessionResult.params.code,
224
+ extraParams: {
225
+ grant_type: 'authorization_code',
226
+ code_verifier: authRequest.codeVerifier,
227
+ },
228
+ }, discovery);
229
+ const { accessToken, refreshToken, expiresIn } = tokenResponse;
230
+ const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
231
+ await saveTokenStorage(storageKey, currentBaseUrl, accessToken, refreshToken, expirationDate);
232
+ refreshTokenRef.current = refreshToken ? refreshToken : null;
233
+ expirationDateRef.current = expirationDate;
234
+ setToken(accessToken);
235
+ setAuthState('authorized');
236
+ const successResult = {
237
+ type: authSessionResult.type,
238
+ };
239
+ return successResult;
240
+ }
241
+ catch (e) {
242
+ const exceptionResult = {
243
+ type: EXCEPTION,
244
+ exceptionDetail: e,
245
+ };
246
+ return exceptionResult;
247
+ }
248
+ }, [requestConfig, discovery]);
249
+ return startAuth;
250
+ };
251
+ const useDestroy = (storageKey, refreshTokenRef, expirationDateRef, setToken, setAuthState) => {
252
+ return useCallback(async () => {
253
+ await deleteTokenStorage(storageKey);
254
+ setToken(null);
255
+ refreshTokenRef.current = null;
256
+ expirationDateRef.current = null;
257
+ setAuthState('unauthorized');
258
+ }, [storageKey, setAuthState]);
259
+ };
260
+ const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh, refresh) => {
261
+ return useCallback(async () => {
262
+ if (expirationDateRef.current != null) {
263
+ const expired = checkExpirationDateOfToken(expirationDateRef.current, remainingTimeToRunRefresh);
264
+ if (expired) {
265
+ await refresh();
266
+ }
267
+ }
268
+ return tokenRef.current;
269
+ }, [refresh]);
270
+ };
271
+ export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, storageKey, oauthContext, }) => {
272
+ const Context = oauthContext || DefaultContext;
273
+ const contextRef = useRef();
274
+ const authStateRenderTarget = useRenderTarget();
275
+ const [, setAuthState, getAuthState] = useAuthStateRef(authStateRenderTarget);
276
+ const tokenRenderTarget = useRenderTarget();
277
+ const [tokenRef, setToken, getToken] = useTokenRef(tokenRenderTarget);
278
+ const refreshTokenRef = useRef(null);
279
+ const expirationDateRef = useRef(null);
280
+ const _storageKey = useStorageKey(storageKey);
281
+ const _remainingTimeToRunRefresh = useRemainingTimeToRunRefresh(remainingTimeToRunRefresh);
282
+ const _requestConfig = useRequestConfig(requestConfig);
283
+ const _discovery = useDiscovery();
284
+ const destroy = useDestroy(_storageKey, refreshTokenRef, expirationDateRef, setToken, setAuthState);
285
+ const refresh = useRefresh(_storageKey, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, destroy);
286
+ const startAuth = useStartAuth(_storageKey, _remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, refresh, setAuthState);
287
+ const getTokenAsync = useGetTokenAsync(tokenRef, expirationDateRef, _remainingTimeToRunRefresh, refresh);
288
+ contextRef.current = {
289
+ getAuthState,
290
+ getToken,
291
+ getTokenAsync,
292
+ refresh,
293
+ destroy,
294
+ startAuth,
295
+ tokenRenderTarget,
296
+ authStateRenderTarget,
297
+ };
298
+ return (<Context.Provider value={contextRef.current}>{children}</Context.Provider>);
299
+ };
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { StartSearchArg, StartSearchResult } from '.';
3
+ export interface SearchContext {
4
+ start: ({ target, type, paramString, }: StartSearchArg) => Promise<StartSearchResult<typeof type>>;
5
+ }
6
+ export declare const Context: import("react").Context<SearchContext | null>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const Context = createContext(null);
@@ -0,0 +1,4 @@
1
+ export declare const errorType = "IMSearchError";
2
+ export declare class IMSearchError extends Error {
3
+ constructor(message: string, options?: ErrorOptions);
4
+ }
@@ -0,0 +1,10 @@
1
+ export const errorType = 'IMSearchError';
2
+ export class IMSearchError extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ if (Error.captureStackTrace) {
6
+ Error.captureStackTrace(this, IMSearchError);
7
+ }
8
+ this.name = errorType;
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ export * from './useIMSearch';
2
+ export * from './useUserSerch';
3
+ export * from './useDepartmentSerch';
4
+ export * from './useDepartmentTopSerch';
5
+ export * from './usePostSerch';
6
+ export * from './usePublicGroupSerch';
7
+ export * from './usePublicGroupTopSerch';
8
+ export * from './useRoleSerch';
9
+ export * from './useUserAdditionalInformationSearch';
10
+ export * from './useDepartmentPostSearch';
11
+ export * from './usePublicGroupRoleSerch';
@@ -0,0 +1,11 @@
1
+ export * from './useIMSearch';
2
+ export * from './useUserSerch';
3
+ export * from './useDepartmentSerch';
4
+ export * from './useDepartmentTopSerch';
5
+ export * from './usePostSerch';
6
+ export * from './usePublicGroupSerch';
7
+ export * from './usePublicGroupTopSerch';
8
+ export * from './useRoleSerch';
9
+ export * from './useUserAdditionalInformationSearch';
10
+ export * from './useDepartmentPostSearch';
11
+ export * from './usePublicGroupRoleSerch';
@@ -0,0 +1,2 @@
1
+ import { DepartmentPostDepartmentSet, DepartmentPostSearchResult } from '../types';
2
+ export declare const useDepartmentPostSearch: (paramString: string) => (departmentSet: DepartmentPostDepartmentSet, init?: RequestInit) => Promise<DepartmentPostSearchResult>;
@@ -0,0 +1,48 @@
1
+ import { useCallback } from 'react';
2
+ import { useIMFetch } from '../../Fetch';
3
+ import { IMSearchError } from '../IMSearchError';
4
+ import { makeParamStringIncludeCriteria, makeParamStringIncludeProp, makeParamStringIncludeTargetDate, } from './utils';
5
+ const getEncodeParams = (parameters, userCriteria) => {
6
+ return `parameters=${encodeURIComponent(parameters)}&userCriteria=${encodeURIComponent(userCriteria)}`;
7
+ };
8
+ export const useDepartmentPostSearch = (paramString) => {
9
+ const imFetch = useIMFetch();
10
+ const search = useCallback(async (departmentSet, init) => {
11
+ try {
12
+ const parameters = makeParamStringIncludeCriteria(makeParamStringIncludeProp(makeParamStringIncludeTargetDate(paramString)));
13
+ const userCriteria = JSON.stringify({ department_set: departmentSet });
14
+ const body = getEncodeParams(parameters, userCriteria);
15
+ const response = await imFetch('api/smacolow/master/search/company_post/tree_with_attached_post/post', {
16
+ ...init,
17
+ headers: {
18
+ ...init?.headers,
19
+ 'Content-Type': 'application/x-www-form-urlencoded',
20
+ Accept: 'application/json',
21
+ },
22
+ method: 'POST',
23
+ body: body,
24
+ });
25
+ if (response.status === 200) {
26
+ const json = await response.json();
27
+ return {
28
+ type: 'success',
29
+ response: json,
30
+ };
31
+ }
32
+ else {
33
+ return {
34
+ type: 'error',
35
+ detail: new IMSearchError('response status other than 200 was returned.'),
36
+ response: response,
37
+ };
38
+ }
39
+ }
40
+ catch (e) {
41
+ return {
42
+ type: 'exception',
43
+ detail: e,
44
+ };
45
+ }
46
+ }, [paramString]);
47
+ return search;
48
+ };
@@ -0,0 +1,2 @@
1
+ import { DepartmentSearcResult } from '../types';
2
+ export declare const useDepartmentSerch: (paramString: string) => (keyword: string, init?: RequestInit) => Promise<DepartmentSearcResult>;
@@ -0,0 +1,56 @@
1
+ import { useCallback } from 'react';
2
+ import { useIMFetch } from '../../Fetch';
3
+ import { IMSearchError } from '../IMSearchError';
4
+ import { makeParamStringIncludeCriteria, makeParamStringIncludeProp, makeParamStringIncludeTargetDate, } from './utils';
5
+ const getEncodeParams = (parameters, userCriteria) => {
6
+ return `parameters=${encodeURIComponent(parameters)}&userCriteria=${encodeURIComponent(userCriteria)}`;
7
+ };
8
+ export const useDepartmentSerch = (paramString) => {
9
+ const imFetch = useIMFetch();
10
+ const search = useCallback(async (keyword, init) => {
11
+ try {
12
+ const parameters = makeParamStringIncludeCriteria(makeParamStringIncludeProp(makeParamStringIncludeTargetDate(paramString)));
13
+ const userCriteria = JSON.stringify({
14
+ keyword: keyword,
15
+ keyword_target: [
16
+ 'department_cd',
17
+ 'department_name',
18
+ 'department_search_name',
19
+ ],
20
+ keyword_type: 'part',
21
+ });
22
+ const body = getEncodeParams(parameters, userCriteria);
23
+ const response = await imFetch('api/smacolow/master/search/department/list', {
24
+ ...init,
25
+ headers: {
26
+ ...init?.headers,
27
+ 'Content-Type': 'application/x-www-form-urlencoded',
28
+ Accept: 'application/json',
29
+ },
30
+ method: 'POST',
31
+ body: body,
32
+ });
33
+ if (response.status === 200) {
34
+ const json = await response.json();
35
+ return {
36
+ type: 'success',
37
+ response: json,
38
+ };
39
+ }
40
+ else {
41
+ return {
42
+ type: 'error',
43
+ detail: new IMSearchError('response status other than 200 was returned.'),
44
+ response: response,
45
+ };
46
+ }
47
+ }
48
+ catch (e) {
49
+ return {
50
+ type: 'exception',
51
+ detail: e,
52
+ };
53
+ }
54
+ }, [paramString]);
55
+ return search;
56
+ };
@@ -0,0 +1,2 @@
1
+ import { DepartmentTopSearcResult } from '../types';
2
+ export declare const useDepartmentTopSerch: (paramString: string) => (init?: RequestInit) => Promise<DepartmentTopSearcResult>;
@@ -0,0 +1,47 @@
1
+ import { useCallback } from 'react';
2
+ import { useIMFetch } from '../../Fetch';
3
+ import { IMSearchError } from '../IMSearchError';
4
+ import { makeParamStringIncludeCriteria, makeParamStringIncludeTargetDate, } from './utils';
5
+ const getEncodeParams = (parameters) => {
6
+ return `parameters=${encodeURIComponent(parameters)}`;
7
+ };
8
+ export const useDepartmentTopSerch = (paramString) => {
9
+ const imFetch = useIMFetch();
10
+ const search = useCallback(async (init) => {
11
+ try {
12
+ const parameters = makeParamStringIncludeCriteria(makeParamStringIncludeCriteria(makeParamStringIncludeTargetDate(paramString)));
13
+ const body = getEncodeParams(parameters);
14
+ const response = await imFetch('api/smacolow/master/search/company_post/tree/department_top', {
15
+ ...init,
16
+ headers: {
17
+ ...init?.headers,
18
+ 'Content-Type': 'application/x-www-form-urlencoded',
19
+ Accept: 'application/json',
20
+ },
21
+ method: 'POST',
22
+ body: body,
23
+ });
24
+ if (response.status === 200) {
25
+ const json = await response.json();
26
+ return {
27
+ type: 'success',
28
+ response: json,
29
+ };
30
+ }
31
+ else {
32
+ return {
33
+ type: 'error',
34
+ detail: new IMSearchError('response status other than 200 was returned.'),
35
+ response: response,
36
+ };
37
+ }
38
+ }
39
+ catch (e) {
40
+ return {
41
+ type: 'exception',
42
+ detail: e,
43
+ };
44
+ }
45
+ }, [paramString]);
46
+ return search;
47
+ };
@@ -0,0 +1,4 @@
1
+ import { Context as DefaultContext } from '../Context';
2
+ export declare const useIMSearch: (Context?: typeof DefaultContext) => {
3
+ startSearch: ({ target, type, paramString, }: import("..").StartSearchArg) => Promise<import("..").StartSearchResult<import("..").SearchType>>;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { useContext } from 'react';
2
+ import { Context as DefaultContext } from '../Context';
3
+ import { IMSearchError } from '../IMSearchError';
4
+ export const useIMSearch = (Context) => {
5
+ const searchContext = useContext(Context || DefaultContext);
6
+ if (searchContext == null) {
7
+ throw new IMSearchError('useIMSearch requires either a Context provide or an ancestor element with a IMSearchProvider');
8
+ }
9
+ const { start } = searchContext;
10
+ return { startSearch: start };
11
+ };
@@ -0,0 +1,2 @@
1
+ import { DepartmentSet, PostSearcResult } from '../types';
2
+ export declare const usePostSerch: (paramString: string) => (departmentSet: DepartmentSet, init?: RequestInit) => Promise<PostSearcResult>;
@@ -0,0 +1,48 @@
1
+ import { useCallback } from 'react';
2
+ import { useIMFetch } from '../../Fetch';
3
+ import { IMSearchError } from '../IMSearchError';
4
+ import { makeParamStringIncludeCriteria, makeParamStringIncludeProp, makeParamStringIncludeTargetDate, } from './utils';
5
+ const getEncodeParams = (parameters, userCriteria) => {
6
+ return `parameters=${encodeURIComponent(parameters)}&userCriteria=${encodeURIComponent(userCriteria)}`;
7
+ };
8
+ export const usePostSerch = (paramString) => {
9
+ const imFetch = useIMFetch();
10
+ const search = useCallback(async (departmentSet, init) => {
11
+ try {
12
+ const parameters = makeParamStringIncludeCriteria(makeParamStringIncludeProp(makeParamStringIncludeTargetDate(paramString)));
13
+ const userCriteria = JSON.stringify({ department_set: departmentSet });
14
+ const body = getEncodeParams(parameters, userCriteria);
15
+ const response = await imFetch('api/smacolow/master/search/company_post/tree/post', {
16
+ ...init,
17
+ headers: {
18
+ ...init?.headers,
19
+ 'Content-Type': 'application/x-www-form-urlencoded',
20
+ Accept: 'application/json',
21
+ },
22
+ method: 'POST',
23
+ body: body,
24
+ });
25
+ if (response.status === 200) {
26
+ const json = await response.json();
27
+ return {
28
+ type: 'success',
29
+ response: json,
30
+ };
31
+ }
32
+ else {
33
+ return {
34
+ type: 'error',
35
+ detail: new IMSearchError('response status other than 200 was returned.'),
36
+ response: response,
37
+ };
38
+ }
39
+ }
40
+ catch (e) {
41
+ return {
42
+ type: 'exception',
43
+ detail: e,
44
+ };
45
+ }
46
+ }, [paramString]);
47
+ return search;
48
+ };