@intra-mart/smartlime 2.0.0-dev.20241210 → 2.0.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 (38) hide show
  1. package/lib/_shared/renderTarget.d.ts +11 -11
  2. package/lib/_shared/renderTarget.js +2 -2
  3. package/lib/index.d.ts +1 -0
  4. package/lib/index.js +1 -0
  5. package/lib/packages/Copilot/IMCopilotError.d.ts +4 -0
  6. package/lib/packages/Copilot/IMCopilotError.js +10 -0
  7. package/lib/packages/Copilot/hooks/index.d.ts +1 -0
  8. package/lib/packages/Copilot/hooks/index.js +1 -0
  9. package/lib/packages/Copilot/hooks/useAssistant/index.d.ts +47 -0
  10. package/lib/packages/Copilot/hooks/useAssistant/index.js +194 -0
  11. package/lib/packages/Copilot/hooks/useAssistant/jsonParse.d.ts +2 -0
  12. package/lib/packages/Copilot/hooks/useAssistant/jsonParse.js +18 -0
  13. package/lib/packages/Copilot/hooks/useAssistant/types.d.ts +52 -0
  14. package/lib/packages/Copilot/hooks/useAssistant/types.js +1 -0
  15. package/lib/packages/Fetch/index.d.ts +4 -2
  16. package/lib/packages/Fetch/index.js +1 -0
  17. package/lib/packages/OAuth/Context.d.ts +13 -1
  18. package/lib/packages/OAuth/hooks/index.d.ts +1 -0
  19. package/lib/packages/OAuth/hooks/index.js +1 -0
  20. package/lib/packages/OAuth/hooks/useAuthInitError.d.ts +3 -0
  21. package/lib/packages/OAuth/hooks/useAuthInitError.js +24 -0
  22. package/lib/packages/OAuth/hooks/useAuthState.d.ts +1 -1
  23. package/lib/packages/OAuth/hooks/useAuthStateEffect.d.ts +1 -1
  24. package/lib/packages/OAuth/hooks/useStartAuth.d.ts +1 -1
  25. package/lib/packages/OAuth/index.d.ts +8 -13
  26. package/lib/packages/OAuth/index.js +71 -43
  27. package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -1
  28. package/lib/packages/Search/hooks/useDepartmentSearch.d.ts +2 -1
  29. package/lib/packages/Search/hooks/useDepartmentTopSearch.d.ts +2 -1
  30. package/lib/packages/Search/hooks/usePostSearch.d.ts +2 -1
  31. package/lib/packages/Search/hooks/usePublicGroupRoleSearch.d.ts +2 -1
  32. package/lib/packages/Search/hooks/usePublicGroupSearch.d.ts +2 -1
  33. package/lib/packages/Search/hooks/usePublicGroupTopSearch.d.ts +2 -1
  34. package/lib/packages/Search/hooks/useRoleSearch.d.ts +2 -1
  35. package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.d.ts +2 -1
  36. package/lib/packages/Search/hooks/useUserSearch.d.ts +2 -1
  37. package/lib/packages/Search/types.d.ts +2 -1
  38. package/package.json +6 -9
@@ -1,14 +1,14 @@
1
- type ForceRender = () => void;
2
- export declare const createRenderTarget: () => {
3
- addEventListener: (callback: ForceRender) => void;
4
- removeEventListener: (callback: ForceRender) => void;
5
- dispatch: () => void;
1
+ type ForceRender<T> = (args?: T) => void;
2
+ export declare const createRenderTarget: <T = undefined>() => {
3
+ addEventListener: (callback: ForceRender<T>) => void;
4
+ removeEventListener: (callback: ForceRender<T>) => void;
5
+ dispatch: (args?: T) => void;
6
6
  };
7
- export type CreateRenderTarget = typeof createRenderTarget;
8
- export type RenderTarget = ReturnType<CreateRenderTarget>;
9
- export declare const useRenderTarget: () => {
10
- addEventListener: (callback: ForceRender) => void;
11
- removeEventListener: (callback: ForceRender) => void;
12
- dispatch: () => void;
7
+ export type CreateRenderTarget<T = undefined> = typeof createRenderTarget<T>;
8
+ export type RenderTarget<T = undefined> = ReturnType<CreateRenderTarget<T>>;
9
+ export declare const useRenderTarget: <T = undefined>() => {
10
+ addEventListener: (callback: ForceRender<T>) => void;
11
+ removeEventListener: (callback: ForceRender<T>) => void;
12
+ dispatch: (args?: T | undefined) => void;
13
13
  };
14
14
  export {};
@@ -12,11 +12,11 @@ export const createRenderTarget = () => {
12
12
  }
13
13
  }
14
14
  };
15
- const dispatch = () => {
15
+ const dispatch = (args) => {
16
16
  for (let i = 0, l = listenerList.length; i < l; i++) {
17
17
  const listener = listenerList[i];
18
18
  if (listener)
19
- listener();
19
+ listener(args);
20
20
  }
21
21
  };
22
22
  return {
package/lib/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export { IMSearch } from './packages/Search';
13
13
  export * from './packages/Search/hooks';
14
14
  export { IMWebView } from './packages/WebView';
15
15
  export * from './packages/WebView/hooks';
16
+ export * from './packages/Copilot/hooks';
package/lib/index.js CHANGED
@@ -16,3 +16,4 @@ export { IMSearch } from './packages/Search';
16
16
  export * from './packages/Search/hooks';
17
17
  export { IMWebView } from './packages/WebView';
18
18
  export * from './packages/WebView/hooks';
19
+ export * from './packages/Copilot/hooks';
@@ -0,0 +1,4 @@
1
+ export declare const errorType = "IMCopilotError";
2
+ export declare class IMCopilotError extends Error {
3
+ constructor(message: string, options?: ErrorOptions);
4
+ }
@@ -0,0 +1,10 @@
1
+ export const errorType = 'IMCopilotError';
2
+ export class IMCopilotError extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ if (Error.captureStackTrace) {
6
+ Error.captureStackTrace(this, IMCopilotError);
7
+ }
8
+ this.name = errorType;
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ export * from './useAssistant';
@@ -0,0 +1 @@
1
+ export * from './useAssistant';
@@ -0,0 +1,47 @@
1
+ import { AssistantHistory, AssistantMetaData, AssistantRequest, ResponseMessage } from './types';
2
+ export interface AssistantSuccess {
3
+ type: 'success';
4
+ }
5
+ export interface AssistantError {
6
+ type: 'error';
7
+ error: Error;
8
+ }
9
+ export interface DeleteThreadSuccess {
10
+ type: 'success';
11
+ }
12
+ export interface DeleteThreadError {
13
+ type: 'error';
14
+ error: Error;
15
+ }
16
+ export interface GetAssistantMetaDataSuccess<T = unknown> {
17
+ type: 'success';
18
+ metaData: AssistantMetaData<T>;
19
+ }
20
+ export interface GetAssistantMetaDataError {
21
+ type: 'error';
22
+ error: Error;
23
+ }
24
+ export interface GetAssistantsMetaDataSuccess<T = unknown> {
25
+ type: 'success';
26
+ metaDataList: AssistantMetaData<T>[];
27
+ }
28
+ export interface GetAssistantsMetaDataError {
29
+ type: 'error';
30
+ error: Error;
31
+ }
32
+ export interface GetAssistantHistorySuccess<T = unknown> {
33
+ type: 'success';
34
+ history: AssistantHistory<T>[];
35
+ }
36
+ export interface GetAssistantHistoryError {
37
+ type: 'error';
38
+ error: Error;
39
+ }
40
+ export type AssistantCallback = (message: ResponseMessage, finish: boolean) => void;
41
+ export declare const useAssistantt: (assistantId: string, threadId?: string) => {
42
+ run: (message: AssistantRequest, callback: AssistantCallback) => Promise<AssistantSuccess | AssistantError>;
43
+ deleteThread: () => Promise<DeleteThreadSuccess | DeleteThreadError>;
44
+ getAssistantMetaData: <T = unknown>() => Promise<GetAssistantMetaDataSuccess<T> | GetAssistantMetaDataError>;
45
+ getAssistantsMetaData: <T = unknown>() => Promise<GetAssistantsMetaDataSuccess<T> | GetAssistantsMetaDataError>;
46
+ getThreadHistory: <T = unknown>() => Promise<GetAssistantHistorySuccess<T> | GetAssistantHistoryError>;
47
+ };
@@ -0,0 +1,194 @@
1
+ import { randomUUID } from 'expo-crypto';
2
+ import { useMemo } from 'react';
3
+ import { join } from '../../../../utils/path';
4
+ import { useIMFetch } from '../../../Fetch';
5
+ import { IMCopilotError } from '../../IMCopilotError';
6
+ import { jsonParse } from './jsonParse';
7
+ const hasFinishMessage = (message) => {
8
+ if (Object.hasOwn(message, 'finishReason'))
9
+ return true;
10
+ return false;
11
+ };
12
+ const isFinishMessage = (message) => {
13
+ return message.finishReason === 'stop' ? true : false;
14
+ };
15
+ const ASSISTANT_PATH = 'api/copilot/assistant';
16
+ const DELETE_PATH = 'api/copilot/message/history';
17
+ const ASSISTANT_METADATA_PATH = 'api/copilot/assistant';
18
+ const ASSISTANTS_METADATA_PATH = 'api/copilot/assistants';
19
+ const ASSISTANT_HISTORY_PATH = 'api/copilot/message/history';
20
+ export const useAssistantt = (assistantId, threadId) => {
21
+ const imFetch = useIMFetch();
22
+ const intternalThreadId = useMemo(() => (threadId ? threadId : randomUUID()), [threadId]);
23
+ const run = async (message, callback) => {
24
+ try {
25
+ const assistantUrl = join(ASSISTANT_PATH, assistantId);
26
+ const response = await imFetch(assistantUrl, {
27
+ method: 'POST',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ // Accept: 'text/event-stream',
31
+ },
32
+ body: JSON.stringify({
33
+ threadId: intternalThreadId,
34
+ message: message.message,
35
+ additional: '',
36
+ }),
37
+ });
38
+ if (response.status !== 200) {
39
+ throw new Error('Proofread API Error');
40
+ }
41
+ if (!response.body) {
42
+ throw new Error('ReadableStream not supported in this environment');
43
+ }
44
+ const reader = response.body.getReader();
45
+ const decoder = new TextDecoder();
46
+ while (true) {
47
+ const { done, value } = await reader.read();
48
+ if (done) {
49
+ break;
50
+ }
51
+ const jsonText = decoder.decode(value, { stream: true });
52
+ const jsonList = jsonParse(jsonText);
53
+ jsonList.forEach((json) => {
54
+ if (hasFinishMessage(json)) {
55
+ const message = json.message;
56
+ const isFinish = isFinishMessage(json);
57
+ callback(message, isFinish);
58
+ }
59
+ else {
60
+ console.warn('Unexpected message', json);
61
+ }
62
+ });
63
+ }
64
+ return {
65
+ type: 'success',
66
+ };
67
+ }
68
+ catch (e) {
69
+ if (e instanceof Error) {
70
+ return {
71
+ type: 'error',
72
+ error: new IMCopilotError('Exception thrown while running the assistant.', { cause: e }),
73
+ };
74
+ }
75
+ throw e;
76
+ }
77
+ };
78
+ const deleteThread = async () => {
79
+ try {
80
+ const deleteThreadUrl = join(DELETE_PATH, intternalThreadId);
81
+ const response = await imFetch(deleteThreadUrl, {
82
+ method: 'DELETE',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ },
86
+ });
87
+ if (response.status !== 200) {
88
+ throw new Error('Proofread API Error');
89
+ }
90
+ return {
91
+ type: 'success',
92
+ };
93
+ }
94
+ catch (e) {
95
+ if (e instanceof Error) {
96
+ return {
97
+ type: 'error',
98
+ error: new IMCopilotError('Exception thrown while attempting to delete the thread.', { cause: e }),
99
+ };
100
+ }
101
+ throw e;
102
+ }
103
+ };
104
+ const getAssistantMetaData = async () => {
105
+ try {
106
+ const metaDataUrl = join(ASSISTANT_METADATA_PATH, assistantId);
107
+ const response = await imFetch(metaDataUrl, {
108
+ method: 'GET',
109
+ headers: {
110
+ 'Content-Type': 'application/json',
111
+ },
112
+ });
113
+ if (response.status !== 200) {
114
+ throw new Error('Proofread API Error');
115
+ }
116
+ const json = await response.json();
117
+ return {
118
+ type: 'success',
119
+ metaData: json.data,
120
+ };
121
+ }
122
+ catch (e) {
123
+ if (e instanceof Error) {
124
+ return {
125
+ type: 'error',
126
+ error: new IMCopilotError('Exception thrown while attempting to get metadata.', { cause: e }),
127
+ };
128
+ }
129
+ throw e;
130
+ }
131
+ };
132
+ const getAssistantsMetaData = async () => {
133
+ try {
134
+ const response = await imFetch(ASSISTANTS_METADATA_PATH, {
135
+ method: 'GET',
136
+ headers: {
137
+ 'Content-Type': 'application/json',
138
+ },
139
+ });
140
+ if (response.status !== 200) {
141
+ throw new Error('Proofread API Error');
142
+ }
143
+ const json = await response.json();
144
+ return {
145
+ type: 'success',
146
+ metaDataList: json.data,
147
+ };
148
+ }
149
+ catch (e) {
150
+ if (e instanceof Error) {
151
+ return {
152
+ type: 'error',
153
+ error: new IMCopilotError('Exception thrown while attempting to get metadata.', { cause: e }),
154
+ };
155
+ }
156
+ throw e;
157
+ }
158
+ };
159
+ const getThreadHistory = async () => {
160
+ try {
161
+ const historyUrl = join(ASSISTANT_HISTORY_PATH, intternalThreadId);
162
+ const response = await imFetch(historyUrl, {
163
+ method: 'GET',
164
+ headers: {
165
+ 'Content-Type': 'application/json',
166
+ },
167
+ });
168
+ if (response.status !== 200) {
169
+ throw new Error('Proofread API Error');
170
+ }
171
+ const json = await response.json();
172
+ return {
173
+ type: 'success',
174
+ history: json.data,
175
+ };
176
+ }
177
+ catch (e) {
178
+ if (e instanceof Error) {
179
+ return {
180
+ type: 'error',
181
+ error: new IMCopilotError('Exception thrown while attempting to get history.', { cause: e }),
182
+ };
183
+ }
184
+ throw e;
185
+ }
186
+ };
187
+ return {
188
+ run,
189
+ deleteThread,
190
+ getAssistantMetaData,
191
+ getAssistantsMetaData,
192
+ getThreadHistory,
193
+ };
194
+ };
@@ -0,0 +1,2 @@
1
+ import { AssistantResponse } from './types';
2
+ export declare const jsonParse: (text: string) => AssistantResponse[];
@@ -0,0 +1,18 @@
1
+ export const jsonParse = (text) => {
2
+ const result = [];
3
+ try {
4
+ const json = JSON.parse(text);
5
+ result.push(json);
6
+ return result;
7
+ }
8
+ catch {
9
+ const jsonLines = text.split('\n');
10
+ for (const jsonLine of jsonLines) {
11
+ if (jsonLine !== '') {
12
+ const json = JSON.parse(jsonLine);
13
+ result.push(json);
14
+ }
15
+ }
16
+ return result;
17
+ }
18
+ };
@@ -0,0 +1,52 @@
1
+ export interface AssistantMetaData<T = unknown> {
2
+ assistantClass: string;
3
+ assistantType: string;
4
+ description: string;
5
+ name: string;
6
+ parameter: T;
7
+ listEnable: boolean;
8
+ storeMessage: boolean;
9
+ }
10
+ export interface AssistantHistory<T = unknown> {
11
+ role: string;
12
+ contents: string;
13
+ toolCalls: [
14
+ {
15
+ id: string;
16
+ type: string;
17
+ function: {
18
+ name: string;
19
+ arguments: string;
20
+ };
21
+ }
22
+ ];
23
+ additional: T[];
24
+ }
25
+ export interface ResponseMessage {
26
+ role: string;
27
+ contents: string | null;
28
+ toolCalls: unknown | null;
29
+ additional: unknown | null;
30
+ }
31
+ export interface AssistantResponse {
32
+ finishReason?: null | 'stop';
33
+ message: ResponseMessage;
34
+ }
35
+ export interface RequestMessage {
36
+ role: string;
37
+ contents: string | null;
38
+ toolCalls?: unknown;
39
+ additional?: unknown;
40
+ }
41
+ export interface AssistantRequest {
42
+ message: RequestMessage;
43
+ }
44
+ export interface AssistantMetaDataResponse<T = unknown> {
45
+ data: AssistantMetaData<T>;
46
+ }
47
+ export interface AssistantsMetaDataResponse<T = unknown> {
48
+ data: AssistantMetaData<T>[];
49
+ }
50
+ export interface AssistantHistoryResponse<T = unknown> {
51
+ data: AssistantHistory<T>[];
52
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,16 @@
1
1
  import { Context as DefaultContext } from '../OAuth/Context';
2
+ import { FetchRequestInit } from 'expo/fetch';
3
+ import { FetchResponse } from 'expo/build/winter/fetch/FetchResponse';
2
4
  export type IMJson = {
3
5
  error?: boolean;
4
6
  errorMessage?: string;
5
7
  data?: Record<string, unknown>;
6
8
  };
7
- interface IMResponse<T> extends Response {
9
+ interface IMResponse<T> extends FetchResponse {
8
10
  json: () => Promise<T extends IMJson ? T & IMJson : undefined extends T ? IMJson : T>;
9
11
  }
10
12
  type UseIMFetch = (option?: {
11
13
  noValidate?: boolean;
12
- }, context?: typeof DefaultContext) => <T>(input: string, init?: RequestInit) => Promise<IMResponse<T>>;
14
+ }, context?: typeof DefaultContext) => <T>(input: string, init?: FetchRequestInit) => Promise<IMResponse<T>>;
13
15
  export declare const useIMFetch: UseIMFetch;
14
16
  export {};
@@ -4,6 +4,7 @@ import { join } from '../../utils/path';
4
4
  import { Context as DefaultContext } from '../OAuth/Context';
5
5
  import { IMOAuthError } from '../OAuth/IMOAuthError';
6
6
  import { IMFecthError } from './IMFecthError';
7
+ import { fetch } from 'expo/fetch';
7
8
  const fetchWrapper = async (token, input, init = {}) => {
8
9
  const response = await fetch(input, {
9
10
  credentials: 'omit',
@@ -1,5 +1,16 @@
1
- import { AuthState, StartAuthResult } from '.';
2
1
  import { RenderTarget } from '../../_shared/renderTarget';
2
+ import { AuthSessionResult } from 'expo-auth-session';
3
+ import { IMOAuthError } from './IMOAuthError';
4
+ export type AuthState = 'initializing' | 'unauthorized' | 'authorized';
5
+ export type StartAuthResult = {
6
+ readonly type: 'cancel' | 'dismiss' | 'opened' | 'locked' | 'error';
7
+ readonly detail: AuthSessionResult;
8
+ } | {
9
+ readonly type: 'success';
10
+ } | {
11
+ readonly type: 'exception';
12
+ readonly exceptionDetail: unknown;
13
+ };
3
14
  export interface OAuthContext {
4
15
  getAuthState: () => AuthState;
5
16
  getToken: () => string | null;
@@ -9,5 +20,6 @@ export interface OAuthContext {
9
20
  startAuth: () => Promise<StartAuthResult>;
10
21
  tokenRenderTarget: RenderTarget;
11
22
  authStateRenderTarget: RenderTarget;
23
+ authErrorRenderTarget: RenderTarget<IMOAuthError>;
12
24
  }
13
25
  export declare const Context: import("react").Context<OAuthContext | null>;
@@ -3,3 +3,4 @@ export * from './useIMToken';
3
3
  export * from './useStartAuth';
4
4
  export * from './useAuthState';
5
5
  export * from './useAuthStateEffect';
6
+ export * from './useAuthInitError';
@@ -3,3 +3,4 @@ export * from './useIMToken';
3
3
  export * from './useStartAuth';
4
4
  export * from './useAuthState';
5
5
  export * from './useAuthStateEffect';
6
+ export * from './useAuthInitError';
@@ -0,0 +1,3 @@
1
+ import { DependencyList } from 'react';
2
+ import { IMOAuthError } from '../IMOAuthError';
3
+ export declare const useAuthInitError: (callBack: (error?: IMOAuthError) => void, deps?: DependencyList) => void;
@@ -0,0 +1,24 @@
1
+ import { useContext, useEffect, useRef } from 'react';
2
+ import { Context as DefaultContext } from '../Context';
3
+ import { IMOAuthError } from '../IMOAuthError';
4
+ export const useAuthInitError = (callBack, deps) => {
5
+ const initRef = useRef(true);
6
+ const firstEffectRef = useRef(true);
7
+ const oauthContext = useContext(DefaultContext);
8
+ if (oauthContext == null) {
9
+ throw new IMOAuthError('useAuthInitError requires either a Context provide or an ancestor element with a IMOAuthProvider.');
10
+ }
11
+ if (initRef.current) {
12
+ initRef.current = false;
13
+ oauthContext.authErrorRenderTarget.addEventListener(callBack);
14
+ }
15
+ useEffect(() => {
16
+ if (firstEffectRef.current)
17
+ firstEffectRef.current = false;
18
+ else
19
+ oauthContext.authErrorRenderTarget.addEventListener(callBack);
20
+ return () => {
21
+ oauthContext.authErrorRenderTarget.removeEventListener(callBack);
22
+ };
23
+ }, deps);
24
+ };
@@ -1,2 +1,2 @@
1
1
  import { Context as DefaultContext } from '../Context';
2
- export declare const useAuthState: (Context?: typeof DefaultContext) => import("..").AuthState;
2
+ export declare const useAuthState: (Context?: typeof DefaultContext) => import("../Context").AuthState;
@@ -1,4 +1,4 @@
1
- import { AuthState } from '..';
1
+ import { AuthState } from '../Context';
2
2
  /**
3
3
  * sugar syntax that sets the return value of "useAuthState" to the deps of "useEffect"
4
4
  * this may be deprecated in the future
@@ -1,2 +1,2 @@
1
1
  import { Context as DefaultContext } from '../Context';
2
- export declare const useStartAuth: (Context?: typeof DefaultContext) => () => Promise<import("..").StartAuthResult>;
2
+ export declare const useStartAuth: (Context?: typeof DefaultContext) => () => Promise<import("../Context").StartAuthResult>;
@@ -1,21 +1,12 @@
1
- import { AuthSessionResult, Prompt } from 'expo-auth-session';
1
+ import { Prompt } from 'expo-auth-session';
2
+ import * as SecureStore from 'expo-secure-store';
2
3
  import { Context as DefaultContext } from './Context';
3
- export type AuthState = 'initializing' | 'unauthorized' | 'authorized';
4
4
  export type TokenState = {
5
5
  baseUrl: string;
6
6
  accessToken: string;
7
7
  refreshToken?: string;
8
8
  expirationDate?: number;
9
9
  };
10
- export type StartAuthResult = {
11
- readonly type: 'cancel' | 'dismiss' | 'opened' | 'locked' | 'error';
12
- readonly detail: AuthSessionResult;
13
- } | {
14
- readonly type: 'success';
15
- } | {
16
- readonly type: 'exception';
17
- readonly exceptionDetail: unknown;
18
- };
19
10
  export declare const IMPrompt: {
20
11
  readonly Login: Prompt.Login;
21
12
  readonly None: Prompt.None;
@@ -28,12 +19,16 @@ interface RequestConfig {
28
19
  state?: string;
29
20
  prompt?: Prompt.Login | Prompt.None;
30
21
  }
22
+ interface SecureStoreConfig {
23
+ storeKey?: string;
24
+ keychainAccessible?: SecureStore.KeychainAccessibilityConstant;
25
+ }
31
26
  interface IMOAuthProps {
32
27
  children: JSX.Element;
33
28
  requestConfig: RequestConfig;
34
29
  remainingTimeToRunRefresh?: number;
35
- storageKey?: string;
30
+ secureStore?: SecureStoreConfig;
36
31
  oauthContext?: typeof DefaultContext;
37
32
  }
38
- export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, storageKey, oauthContext, }: IMOAuthProps) => import("react").JSX.Element;
33
+ export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }: IMOAuthProps) => import("react").JSX.Element;
39
34
  export {};
@@ -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 { useCallback, useLayoutEffect, useMemo, useRef, } from 'react';
4
- import { Context as DefaultContext } from './Context';
5
- import { IMOAuthError } from './IMOAuthError';
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 * as WebBrowser from 'expo-web-browser';
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 DEFAULT_STORAGE_KEY = '_example_IMAuthKey';
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 useStorageKey = (storageKey) => {
54
+ const useStoreConfig = (secureStore) => {
55
+ const storeKey = secureStore?.storeKey;
56
+ const keychainAccessible = secureStore?.keychainAccessible;
55
57
  return useMemo(() => {
56
- return storageKey ? storageKey : DEFAULT_STORAGE_KEY;
57
- }, [storageKey]);
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 saveTokenStorage = async (storageKey, baseUrl, accessToken, refreshToken, expirationDate) => {
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(storageKey, JSON.stringify(item));
80
+ return await SecureStore.setItemAsync(storeConfig.storeKey, JSON.stringify(item), {
81
+ keychainAccessible: storeConfig.keychainAccessible,
82
+ });
74
83
  };
75
- const deleteTokenStorage = async (tokenStorageKey) => {
76
- return await SecureStore.deleteItemAsync(tokenStorageKey);
84
+ const deleteTokenStore = async (storeConfig) => {
85
+ return await SecureStore.deleteItemAsync(storeConfig.storeKey, {
86
+ keychainAccessible: storeConfig.keychainAccessible,
87
+ });
77
88
  };
78
- const getTokenStorage = async (storageKey) => {
79
- const state = await SecureStore.getItemAsync(storageKey);
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 = (storageKey, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, destroy) => {
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 saveTokenStorage(storageKey, baseUrl, accessToken, refreshToken, expirationDate);
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
- }, [storageKey, requestConfig, discovery, destroy]);
194
+ }, [storeConfig, requestConfig, discovery, destroy]);
182
195
  };
183
- const useStartAuth = (storageKey, remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, refresh, setAuthState) => {
196
+ const useStartAuth = (storeConfig, remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, requestConfig, discovery, setToken, refresh, setAuthState, authErrorRenderTarget) => {
184
197
  const currentBaseUrl = useIMBaseUrl();
185
- useLayoutEffect(() => {
198
+ useEffect(() => {
186
199
  (async () => {
187
- const tokenState = await getTokenStorage(storageKey);
188
- if (tokenState) {
189
- const { baseUrl, accessToken, refreshToken, expirationDate } = tokenState;
190
- const expired = checkExpirationDateOfToken(expirationDate ? expirationDate : 0, remainingTimeToRunRefresh);
191
- refreshTokenRef.current = refreshToken ? refreshToken : null;
192
- expirationDateRef.current = expirationDate ? expirationDate : null;
193
- if (currentBaseUrl === baseUrl) {
194
- if (expired) {
195
- await refresh(); // NOTE consideration of how users can catch errors thrown here.
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
- setToken(accessToken);
217
+ setAuthState('unauthorized');
199
218
  }
200
- setAuthState('authorized');
201
219
  }
202
220
  else {
203
221
  setAuthState('unauthorized');
204
222
  }
205
223
  }
206
- else {
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
- }, [storageKey, remainingTimeToRunRefresh, refresh]);
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 saveTokenStorage(storageKey, currentBaseUrl, accessToken, refreshToken, expirationDate);
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 = (storageKey, refreshTokenRef, expirationDateRef, setToken, setAuthState) => {
285
+ const useDestroy = (storeConfig, refreshTokenRef, expirationDateRef, setToken, setAuthState) => {
260
286
  return useCallback(async () => {
261
- await deleteTokenStorage(storageKey);
287
+ await deleteTokenStore(storeConfig);
262
288
  setToken(null);
263
289
  refreshTokenRef.current = null;
264
290
  expirationDateRef.current = null;
265
291
  setAuthState('unauthorized');
266
- }, [storageKey, setAuthState]);
292
+ }, [storeConfig, setAuthState]);
267
293
  };
268
294
  const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh, refresh) => {
269
295
  return useCallback(async () => {
@@ -276,7 +302,7 @@ const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh
276
302
  return tokenRef.current;
277
303
  }, [refresh]);
278
304
  };
279
- export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, storageKey, oauthContext, }) => {
305
+ export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }) => {
280
306
  const Context = oauthContext || DefaultContext;
281
307
  const contextRef = useRef();
282
308
  const authStateRenderTarget = useRenderTarget();
@@ -285,13 +311,14 @@ export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, st
285
311
  const [tokenRef, setToken, getToken] = useTokenRef(tokenRenderTarget);
286
312
  const refreshTokenRef = useRef(null);
287
313
  const expirationDateRef = useRef(null);
288
- const _storageKey = useStorageKey(storageKey);
314
+ const storeConfig = useStoreConfig(secureStore);
289
315
  const _remainingTimeToRunRefresh = useRemainingTimeToRunRefresh(remainingTimeToRunRefresh);
290
316
  const _requestConfig = useRequestConfig(requestConfig);
291
317
  const _discovery = useDiscovery();
292
- const destroy = useDestroy(_storageKey, refreshTokenRef, expirationDateRef, setToken, setAuthState);
293
- const refresh = useRefresh(_storageKey, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, destroy);
294
- const startAuth = useStartAuth(_storageKey, _remainingTimeToRunRefresh, refreshTokenRef, expirationDateRef, _requestConfig, _discovery, setToken, refresh, setAuthState);
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
- export declare const useDepartmentPostSearch: (paramString: string) => (departmentSet: DepartmentPostDepartmentSet, init?: RequestInit) => Promise<DepartmentPostSearchResult>;
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
- export declare const useDepartmentSearch: (paramString: string) => (keyword: string, init?: RequestInit) => Promise<DepartmentSearcResult>;
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
- export declare const useDepartmentTopSearch: (paramString: string) => (init?: RequestInit) => Promise<DepartmentTopSearcResult>;
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
- export declare const usePostSearch: (paramString: string) => (departmentSet: DepartmentSet, init?: RequestInit) => Promise<PostSearcResult>;
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
- export declare const usePublicGroupRoleSearch: (paramString: string) => (publicGroupSet: PublicGroupRoleSet, init?: RequestInit) => Promise<PublicGroupRoleSearchResult>;
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
- export declare const usePublicGroupSearch: (paramString: string) => (keyword: string, init?: RequestInit) => Promise<PublicGroupSearcResult>;
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
- export declare const usePublicGroupTopSearch: (paramString: string) => (init?: RequestInit) => Promise<PublicGroupTopSearchResult>;
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
- export declare const useRoleSearch: (paramString: string) => (publicGroupSet: PublicGroupSet, init?: RequestInit) => Promise<RoleSearchResult>;
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
- export declare const useUserAdditionalInformationSearch: (paramString: string) => (userCd: string, init?: RequestInit) => Promise<UserAdditionalInformationSearchResult>;
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
- export declare const useUserSearch: (paramString: string) => (keyword: string, init?: RequestInit) => Promise<UserSearchResult>;
2
+ import { FetchRequestInit } from 'expo/fetch';
3
+ export declare const useUserSearch: (paramString: string) => (keyword: string, init?: FetchRequestInit) => Promise<UserSearchResult>;
@@ -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: Response;
14
+ readonly response: FetchResponse;
14
15
  }
15
16
  export interface Exception {
16
17
  readonly type: 'exception';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intra-mart/smartlime",
3
3
  "description": "expoで使用できるintra mart accelplatform SDK",
4
- "version": "2.0.0-dev.20241210",
4
+ "version": "2.0.0",
5
5
  "keywords": [
6
6
  "intra-mart",
7
7
  "AccelPlatform",
@@ -42,7 +42,7 @@
42
42
  "type": "tsc --noEmit"
43
43
  },
44
44
  "peerDependencies": {
45
- "expo": "^52.0.17",
45
+ "expo": "^52.0.20",
46
46
  "react": "18.3.1"
47
47
  },
48
48
  "dependencies": {
@@ -66,22 +66,19 @@
66
66
  "eslint": "^9.16.0",
67
67
  "eslint-config-prettier": "^9.1.0",
68
68
  "eslint-plugin-react": "^7.37.2",
69
- "expo": "^52.0.17",
69
+ "expo": "~52.0.20",
70
70
  "jest": "^29.7.0",
71
71
  "jest-expo": "^52.0.2",
72
72
  "prettier": "^3.4.2",
73
73
  "react": "18.3.1",
74
74
  "react-dom": "18.3.1",
75
- "react-native": "0.76.3",
75
+ "react-native": "0.76.5",
76
76
  "react-test-renderer": "18.2.0",
77
77
  "ts-jest": "^29.2.5",
78
78
  "typescript": "^5.7.2"
79
79
  },
80
- "resolutions": {
81
- "@types/react": "^18.2.79"
82
- },
83
- "packageManager": "yarn@1.22.19",
84
80
  "engines": {
85
- "node": ">= 16.9.0"
81
+ "node": ">= 22.0.0"
86
82
  }
87
83
  }
84
+