@intra-mart/smartlime 2.0.0-dev.20241125 → 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.
Files changed (73) hide show
  1. package/eslint.config.mjs +50 -0
  2. package/lib/_shared/renderTarget.d.ts +1 -1
  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/Me/Context.d.ts +0 -1
  18. package/lib/packages/Me/index.d.ts +3 -3
  19. package/lib/packages/Me/index.js +1 -1
  20. package/lib/packages/Me/type.d.ts +1 -0
  21. package/lib/packages/OAuth/Context.d.ts +0 -1
  22. package/lib/packages/OAuth/hooks/index.d.ts +1 -1
  23. package/lib/packages/OAuth/hooks/index.js +1 -1
  24. package/lib/packages/OAuth/hooks/useAuthInitError.d.ts +3 -0
  25. package/lib/packages/OAuth/hooks/useAuthInitError.js +24 -0
  26. package/lib/packages/OAuth/index.d.ts +2 -2
  27. package/lib/packages/OAuth/index.js +10 -10
  28. package/lib/packages/Search/Context.d.ts +0 -1
  29. package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -1
  30. package/lib/packages/Search/hooks/useDepartmentSearch.d.ts +2 -1
  31. package/lib/packages/Search/hooks/useDepartmentTopSearch.d.ts +2 -1
  32. package/lib/packages/Search/hooks/useIMSearch.d.ts +1 -1
  33. package/lib/packages/Search/hooks/usePostSearch.d.ts +2 -1
  34. package/lib/packages/Search/hooks/usePublicGroupRoleSearch.d.ts +2 -1
  35. package/lib/packages/Search/hooks/usePublicGroupSearch.d.ts +2 -1
  36. package/lib/packages/Search/hooks/usePublicGroupTopSearch.d.ts +2 -1
  37. package/lib/packages/Search/hooks/useRoleSearch.d.ts +2 -1
  38. package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.d.ts +2 -1
  39. package/lib/packages/Search/hooks/useUserSearch.d.ts +2 -1
  40. package/lib/packages/Search/index.d.ts +3 -3
  41. package/lib/packages/Search/index.js +1 -1
  42. package/lib/packages/Search/types.d.ts +2 -1
  43. package/lib/packages/Session/Context.d.ts +0 -1
  44. package/lib/packages/Session/hooks/useSession.d.ts +0 -1
  45. package/lib/packages/Session/hooks/useSessionState.d.ts +0 -1
  46. package/lib/packages/Session/index.d.ts +2 -2
  47. package/lib/packages/Session/index.js +29 -24
  48. package/lib/packages/Smartlime/NotSearchPropError.d.ts +0 -1
  49. package/lib/packages/Smartlime/index.d.ts +2 -2
  50. package/lib/packages/Tenant/Context.d.ts +13 -6
  51. package/lib/packages/Tenant/constants.d.ts +2 -0
  52. package/lib/packages/Tenant/constants.js +4 -0
  53. package/lib/packages/Tenant/hooks/index.d.ts +2 -2
  54. package/lib/packages/Tenant/hooks/index.js +2 -2
  55. package/lib/packages/Tenant/hooks/useIMModules.d.ts +6 -0
  56. package/lib/packages/Tenant/hooks/useIMModules.js +79 -0
  57. package/lib/packages/Tenant/hooks/useIMModulesState.d.ts +2 -0
  58. package/lib/packages/Tenant/hooks/{useIMFetchModuleState.js → useIMModulesState.js} +3 -4
  59. package/lib/packages/Tenant/index.d.ts +4 -16
  60. package/lib/packages/Tenant/index.js +16 -83
  61. package/lib/packages/Tenant/modulesType.d.ts +1522 -2
  62. package/lib/packages/Tenant/modulesType.js +1522 -2
  63. package/lib/packages/WebView/InternalIMWebView.d.ts +1 -1
  64. package/lib/packages/WebView/InternalIMWebView.js +6 -6
  65. package/lib/packages/WebView/hooks/useHackSearchUI.d.ts +1 -2
  66. package/lib/packages/WebView/index.js +8 -8
  67. package/lib/utils/mergeRef.d.ts +1 -2
  68. package/package.json +29 -34
  69. package/lib/packages/OAuth/hooks/useAuthError.d.ts +0 -2
  70. package/lib/packages/OAuth/hooks/useAuthError.js +0 -15
  71. package/lib/packages/Tenant/hooks/useIMFetchModuleState.d.ts +0 -2
  72. package/lib/packages/Tenant/hooks/useIMModuleInfo.d.ts +0 -6
  73. package/lib/packages/Tenant/hooks/useIMModuleInfo.js +0 -13
@@ -0,0 +1,50 @@
1
+ import tsParser from '@typescript-eslint/parser';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import js from '@eslint/js';
5
+ import { FlatCompat } from '@eslint/eslintrc';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const compat = new FlatCompat({
10
+ baseDirectory: __dirname,
11
+ recommendedConfig: js.configs.recommended,
12
+ allConfig: js.configs.all,
13
+ });
14
+
15
+ export default [
16
+ ...compat.extends(
17
+ 'plugin:react/recommended',
18
+ 'plugin:@typescript-eslint/recommended',
19
+ 'prettier'
20
+ ),
21
+ {
22
+ languageOptions: {
23
+ parser: tsParser,
24
+ ecmaVersion: 2020,
25
+ sourceType: 'module',
26
+
27
+ parserOptions: {
28
+ ecmaFeatures: {
29
+ jsx: true,
30
+ },
31
+ },
32
+ },
33
+
34
+ settings: {
35
+ react: {
36
+ version: 'detect',
37
+ },
38
+ },
39
+
40
+ rules: {
41
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
42
+ '@typescript-eslint/ban-ts-comment': 'off',
43
+ '@typescript-eslint/no-empty-function': 'off',
44
+ 'react/react-in-jsx-scope': 'off',
45
+ 'react/prop-types': 'off',
46
+ 'react/display-name': 'off',
47
+ 'react/jsx-key': 'off',
48
+ },
49
+ },
50
+ ];
@@ -2,7 +2,7 @@ type ForceRender<T> = (args?: T) => void;
2
2
  export declare const createRenderTarget: <T = undefined>() => {
3
3
  addEventListener: (callback: ForceRender<T>) => void;
4
4
  removeEventListener: (callback: ForceRender<T>) => void;
5
- dispatch: (args?: T | undefined) => void;
5
+ dispatch: (args?: T) => void;
6
6
  };
7
7
  export type CreateRenderTarget<T = undefined> = typeof createRenderTarget<T>;
8
8
  export type RenderTarget<T = undefined> = ReturnType<CreateRenderTarget<T>>;
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,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ErrorResult, SuccessResult } from '.';
3
2
  import { RenderTarget } from '../../_shared/renderTarget';
4
3
  import { Me } from './type';
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { JSX } from 'react';
2
2
  import { RenderTarget } from '../../_shared/renderTarget';
3
3
  import { Context as DefaultContext } from './Context';
4
4
  import { Me } from './type';
@@ -14,10 +14,10 @@ export interface ErrorResult {
14
14
  couse?: unknown;
15
15
  }
16
16
  export declare const useRequestIMMe: (setter: ReturnType<typeof useMeStateRef>[1]) => () => Promise<SuccessResult | ErrorResult>;
17
- declare const useMeStateRef: (renderTarget: RenderTarget) => readonly [import("react").MutableRefObject<Me | null>, (state: Me, silent?: boolean) => void, () => Me | null];
17
+ declare const useMeStateRef: (renderTarget: RenderTarget) => readonly [import("react").RefObject<Me | null>, (state: Me, silent?: boolean) => void, () => Me | null];
18
18
  export interface IMMeProps {
19
19
  children: JSX.Element;
20
20
  meContext?: typeof DefaultContext;
21
21
  }
22
- export declare const IMMe: ({ children, meContext }: IMMeProps) => import("react").JSX.Element;
22
+ export declare const IMMe: ({ children, meContext }: IMMeProps) => JSX.Element;
23
23
  export {};
@@ -42,7 +42,7 @@ const useMeStateRef = (renderTarget) => {
42
42
  };
43
43
  export const IMMe = ({ children, meContext }) => {
44
44
  const Context = meContext || DefaultContext;
45
- const contextRef = useRef();
45
+ const contextRef = useRef(null);
46
46
  const meStateRenderTarget = useRenderTarget();
47
47
  const [, setMe, getMe] = useMeStateRef(meStateRenderTarget);
48
48
  const request = useRequestIMMe(setMe);
@@ -54,6 +54,7 @@ export interface Me {
54
54
  calendarId: string;
55
55
  firstDayOfWeek: 1 | 2 | 3 | 4 | 5 | 6 | 7;
56
56
  locale: string;
57
+ roleIds: string[];
57
58
  tenantId: string;
58
59
  timeZone: string;
59
60
  userCd: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { RenderTarget } from '../../_shared/renderTarget';
3
2
  import { AuthSessionResult } from 'expo-auth-session';
4
3
  import { IMOAuthError } from './IMOAuthError';
@@ -3,4 +3,4 @@ export * from './useIMToken';
3
3
  export * from './useStartAuth';
4
4
  export * from './useAuthState';
5
5
  export * from './useAuthStateEffect';
6
- export * from './useAuthError';
6
+ export * from './useAuthInitError';
@@ -3,4 +3,4 @@ export * from './useIMToken';
3
3
  export * from './useStartAuth';
4
4
  export * from './useAuthState';
5
5
  export * from './useAuthStateEffect';
6
- export * from './useAuthError';
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,6 +1,6 @@
1
- /// <reference types="react" />
2
1
  import { Prompt } from 'expo-auth-session';
3
2
  import * as SecureStore from 'expo-secure-store';
3
+ import { JSX } from 'react';
4
4
  import { Context as DefaultContext } from './Context';
5
5
  export type TokenState = {
6
6
  baseUrl: string;
@@ -31,5 +31,5 @@ interface IMOAuthProps {
31
31
  secureStore?: SecureStoreConfig;
32
32
  oauthContext?: typeof DefaultContext;
33
33
  }
34
- export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }: IMOAuthProps) => import("react").JSX.Element;
34
+ export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }: IMOAuthProps) => JSX.Element;
35
35
  export {};
@@ -10,7 +10,7 @@ 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,
@@ -56,7 +56,7 @@ const useStoreConfig = (secureStore) => {
56
56
  const keychainAccessible = secureStore?.keychainAccessible;
57
57
  return useMemo(() => {
58
58
  return {
59
- storeKey: storeKey ? storeKey : DEFAULT_STORAGE_KEY,
59
+ storeKey: storeKey ? storeKey : DEFAULT_STORE_KEY,
60
60
  keychainAccessible: keychainAccessible !== void 0
61
61
  ? keychainAccessible
62
62
  : SecureStore.WHEN_UNLOCKED,
@@ -70,7 +70,7 @@ const useRemainingTimeToRunRefresh = (remainingTimeToRunRefresh) => {
70
70
  : DEFAULT_REMAINING_TIME_TO_RUN_REFRESH;
71
71
  }, [remainingTimeToRunRefresh]);
72
72
  };
73
- const saveTokenStorage = async (storeConfig, baseUrl, accessToken, refreshToken, expirationDate) => {
73
+ const saveTokenStore = async (storeConfig, baseUrl, accessToken, refreshToken, expirationDate) => {
74
74
  const item = {
75
75
  baseUrl,
76
76
  accessToken,
@@ -81,12 +81,12 @@ const saveTokenStorage = async (storeConfig, baseUrl, accessToken, refreshToken,
81
81
  keychainAccessible: storeConfig.keychainAccessible,
82
82
  });
83
83
  };
84
- const deleteTokenStorage = async (storeConfig) => {
84
+ const deleteTokenStore = async (storeConfig) => {
85
85
  return await SecureStore.deleteItemAsync(storeConfig.storeKey, {
86
86
  keychainAccessible: storeConfig.keychainAccessible,
87
87
  });
88
88
  };
89
- const getTokenStorage = async (storeConfig) => {
89
+ const getTokenStore = async (storeConfig) => {
90
90
  const state = await SecureStore.getItemAsync(storeConfig.storeKey, {
91
91
  keychainAccessible: storeConfig.keychainAccessible,
92
92
  });
@@ -176,7 +176,7 @@ const useRefresh = (storeConfig, refreshTokenRef, expirationDateRef, requestConf
176
176
  }, discovery);
177
177
  const { accessToken, refreshToken, expiresIn } = tokenResponse;
178
178
  const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
179
- await saveTokenStorage(storeConfig, baseUrl, accessToken, refreshToken, expirationDate);
179
+ await saveTokenStore(storeConfig, baseUrl, accessToken, refreshToken, expirationDate);
180
180
  refreshTokenRef.current = refreshToken ? refreshToken : null;
181
181
  expirationDateRef.current = expirationDate;
182
182
  setToken(accessToken);
@@ -198,7 +198,7 @@ const useStartAuth = (storeConfig, remainingTimeToRunRefresh, refreshTokenRef, e
198
198
  useEffect(() => {
199
199
  (async () => {
200
200
  try {
201
- const tokenState = await getTokenStorage(storeConfig);
201
+ const tokenState = await getTokenStore(storeConfig);
202
202
  if (tokenState) {
203
203
  const { baseUrl, accessToken, refreshToken, expirationDate } = tokenState;
204
204
  const expired = checkExpirationDateOfToken(expirationDate ? expirationDate : 0, remainingTimeToRunRefresh);
@@ -262,7 +262,7 @@ const useStartAuth = (storeConfig, remainingTimeToRunRefresh, refreshTokenRef, e
262
262
  }, discovery);
263
263
  const { accessToken, refreshToken, expiresIn } = tokenResponse;
264
264
  const expirationDate = expiresIn ? createExpirationDate(expiresIn) : 0;
265
- await saveTokenStorage(storeConfig, currentBaseUrl, accessToken, refreshToken, expirationDate);
265
+ await saveTokenStore(storeConfig, currentBaseUrl, accessToken, refreshToken, expirationDate);
266
266
  refreshTokenRef.current = refreshToken ? refreshToken : null;
267
267
  expirationDateRef.current = expirationDate;
268
268
  setToken(accessToken);
@@ -284,7 +284,7 @@ const useStartAuth = (storeConfig, remainingTimeToRunRefresh, refreshTokenRef, e
284
284
  };
285
285
  const useDestroy = (storeConfig, refreshTokenRef, expirationDateRef, setToken, setAuthState) => {
286
286
  return useCallback(async () => {
287
- await deleteTokenStorage(storeConfig);
287
+ await deleteTokenStore(storeConfig);
288
288
  setToken(null);
289
289
  refreshTokenRef.current = null;
290
290
  expirationDateRef.current = null;
@@ -304,7 +304,7 @@ const useGetTokenAsync = (tokenRef, expirationDateRef, remainingTimeToRunRefresh
304
304
  };
305
305
  export const IMOAuth = ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }) => {
306
306
  const Context = oauthContext || DefaultContext;
307
- const contextRef = useRef();
307
+ const contextRef = useRef(null);
308
308
  const authStateRenderTarget = useRenderTarget();
309
309
  const [, setAuthState, getAuthState] = useAuthStateRef(authStateRenderTarget);
310
310
  const tokenRenderTarget = useRenderTarget();
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { StartSearchArg, StartSearchResult } from '.';
3
2
  export interface SearchContext {
4
3
  start: ({ target, type, paramString, }: StartSearchArg) => Promise<StartSearchResult<typeof type>>;
@@ -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>;