@intra-mart/smartlime 2.0.0-dev.20241210 → 2.0.0-dev.20251017

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) 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/Me/index.d.ts +3 -2
  18. package/lib/packages/Me/index.js +1 -1
  19. package/lib/packages/Me/type.d.ts +1 -0
  20. package/lib/packages/OAuth/Context.d.ts +13 -1
  21. package/lib/packages/OAuth/hooks/index.d.ts +1 -0
  22. package/lib/packages/OAuth/hooks/index.js +1 -0
  23. package/lib/packages/OAuth/hooks/useAuthInitError.d.ts +3 -0
  24. package/lib/packages/OAuth/hooks/useAuthInitError.js +24 -0
  25. package/lib/packages/OAuth/hooks/useAuthState.d.ts +1 -1
  26. package/lib/packages/OAuth/hooks/useAuthStateEffect.d.ts +1 -1
  27. package/lib/packages/OAuth/hooks/useStartAuth.d.ts +1 -1
  28. package/lib/packages/OAuth/index.d.ts +9 -13
  29. package/lib/packages/OAuth/index.js +72 -44
  30. package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -1
  31. package/lib/packages/Search/hooks/useDepartmentSearch.d.ts +2 -1
  32. package/lib/packages/Search/hooks/useDepartmentTopSearch.d.ts +2 -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 -2
  41. package/lib/packages/Search/index.js +1 -1
  42. package/lib/packages/Search/types.d.ts +2 -1
  43. package/lib/packages/Session/index.d.ts +2 -1
  44. package/lib/packages/Session/index.js +29 -24
  45. package/lib/packages/Smartlime/index.d.ts +2 -1
  46. package/lib/packages/Tenant/Context.d.ts +13 -5
  47. package/lib/packages/Tenant/constants.d.ts +2 -0
  48. package/lib/packages/Tenant/constants.js +4 -0
  49. package/lib/packages/Tenant/hooks/index.d.ts +2 -2
  50. package/lib/packages/Tenant/hooks/index.js +2 -2
  51. package/lib/packages/Tenant/hooks/useIMModules.d.ts +6 -0
  52. package/lib/packages/Tenant/hooks/useIMModules.js +79 -0
  53. package/lib/packages/Tenant/hooks/useIMModulesState.d.ts +2 -0
  54. package/lib/packages/Tenant/hooks/{useIMFetchModuleState.js → useIMModulesState.js} +3 -4
  55. package/lib/packages/Tenant/index.d.ts +4 -15
  56. package/lib/packages/Tenant/index.js +16 -83
  57. package/lib/packages/Tenant/modulesType.d.ts +1522 -2
  58. package/lib/packages/Tenant/modulesType.js +1522 -2
  59. package/lib/packages/WebView/InternalIMWebView.d.ts +1 -1
  60. package/lib/packages/WebView/InternalIMWebView.js +6 -6
  61. package/lib/packages/WebView/hooks/useHackSearchUI.d.ts +1 -1
  62. package/lib/packages/WebView/index.js +8 -8
  63. package/package.json +27 -32
  64. package/lib/packages/Tenant/hooks/useIMFetchModuleState.d.ts +0 -2
  65. package/lib/packages/Tenant/hooks/useIMModuleInfo.d.ts +0 -6
  66. package/lib/packages/Tenant/hooks/useIMModuleInfo.js +0 -13
@@ -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,3 +1,4 @@
1
+ import { JSX } from 'react';
1
2
  import { RenderTarget } from '../../_shared/renderTarget';
2
3
  import { Context as DefaultContext } from './Context';
3
4
  import { Me } from './type';
@@ -13,10 +14,10 @@ export interface ErrorResult {
13
14
  couse?: unknown;
14
15
  }
15
16
  export declare const useRequestIMMe: (setter: ReturnType<typeof useMeStateRef>[1]) => () => Promise<SuccessResult | ErrorResult>;
16
- 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];
17
18
  export interface IMMeProps {
18
19
  children: JSX.Element;
19
20
  meContext?: typeof DefaultContext;
20
21
  }
21
- export declare const IMMe: ({ children, meContext }: IMMeProps) => import("react").JSX.Element;
22
+ export declare const IMMe: ({ children, meContext }: IMMeProps) => JSX.Element;
22
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,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,13 @@
1
- import { AuthSessionResult, Prompt } from 'expo-auth-session';
1
+ import { Prompt } from 'expo-auth-session';
2
+ import * as SecureStore from 'expo-secure-store';
3
+ import { JSX } from 'react';
2
4
  import { Context as DefaultContext } from './Context';
3
- export type AuthState = 'initializing' | 'unauthorized' | 'authorized';
4
5
  export type TokenState = {
5
6
  baseUrl: string;
6
7
  accessToken: string;
7
8
  refreshToken?: string;
8
9
  expirationDate?: number;
9
10
  };
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
11
  export declare const IMPrompt: {
20
12
  readonly Login: Prompt.Login;
21
13
  readonly None: Prompt.None;
@@ -28,12 +20,16 @@ interface RequestConfig {
28
20
  state?: string;
29
21
  prompt?: Prompt.Login | Prompt.None;
30
22
  }
23
+ interface SecureStoreConfig {
24
+ storeKey?: string;
25
+ keychainAccessible?: SecureStore.KeychainAccessibilityConstant;
26
+ }
31
27
  interface IMOAuthProps {
32
28
  children: JSX.Element;
33
29
  requestConfig: RequestConfig;
34
30
  remainingTimeToRunRefresh?: number;
35
- storageKey?: string;
31
+ secureStore?: SecureStoreConfig;
36
32
  oauthContext?: typeof DefaultContext;
37
33
  }
38
- export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, storageKey, oauthContext, }: IMOAuthProps) => import("react").JSX.Element;
34
+ export declare const IMOAuth: ({ children, requestConfig, remainingTimeToRunRefresh, secureStore, oauthContext, }: IMOAuthProps) => JSX.Element;
39
35
  export {};