@intra-mart/smartlime 0.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/lib/_shared/renderTarget.d.ts +14 -0
- package/lib/_shared/renderTarget.js +31 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +18 -0
- package/lib/packages/Fetch/IMFecthError.d.ts +4 -0
- package/lib/packages/Fetch/IMFecthError.js +10 -0
- package/lib/packages/Fetch/index.d.ts +14 -0
- package/lib/packages/Fetch/index.js +112 -0
- package/lib/packages/Me/Context.d.ts +10 -0
- package/lib/packages/Me/Context.js +2 -0
- package/lib/packages/Me/IMMeError.d.ts +4 -0
- package/lib/packages/Me/IMMeError.js +10 -0
- package/lib/packages/Me/hooks/index.d.ts +2 -0
- package/lib/packages/Me/hooks/index.js +2 -0
- package/lib/packages/Me/hooks/useMe.d.ts +6 -0
- package/lib/packages/Me/hooks/useMe.js +11 -0
- package/lib/packages/Me/hooks/useMeState.d.ts +2 -0
- package/lib/packages/Me/hooks/useMeState.js +21 -0
- package/lib/packages/Me/index.d.ts +22 -0
- package/lib/packages/Me/index.js +55 -0
- package/lib/packages/Me/type.d.ts +85 -0
- package/lib/packages/Me/type.js +1 -0
- package/lib/packages/OAuth/Context.d.ts +14 -0
- package/lib/packages/OAuth/Context.js +2 -0
- package/lib/packages/OAuth/IMOAuthError.d.ts +4 -0
- package/lib/packages/OAuth/IMOAuthError.js +10 -0
- package/lib/packages/OAuth/hooks/index.d.ts +5 -0
- package/lib/packages/OAuth/hooks/index.js +5 -0
- package/lib/packages/OAuth/hooks/useAuthState.d.ts +2 -0
- package/lib/packages/OAuth/hooks/useAuthState.js +25 -0
- package/lib/packages/OAuth/hooks/useAuthStateEffect.d.ts +6 -0
- package/lib/packages/OAuth/hooks/useAuthStateEffect.js +14 -0
- package/lib/packages/OAuth/hooks/useIMOAuth.d.ts +7 -0
- package/lib/packages/OAuth/hooks/useIMOAuth.js +13 -0
- package/lib/packages/OAuth/hooks/useIMToken.d.ts +2 -0
- package/lib/packages/OAuth/hooks/useIMToken.js +21 -0
- package/lib/packages/OAuth/hooks/useStartAuth.d.ts +2 -0
- package/lib/packages/OAuth/hooks/useStartAuth.js +12 -0
- package/lib/packages/OAuth/index.d.ts +39 -0
- package/lib/packages/OAuth/index.js +299 -0
- package/lib/packages/Search/Context.d.ts +6 -0
- package/lib/packages/Search/Context.js +2 -0
- package/lib/packages/Search/IMSearchError.d.ts +4 -0
- package/lib/packages/Search/IMSearchError.js +10 -0
- package/lib/packages/Search/hooks/index.d.ts +11 -0
- package/lib/packages/Search/hooks/index.js +11 -0
- package/lib/packages/Search/hooks/useDepartmentPostSearch.d.ts +2 -0
- package/lib/packages/Search/hooks/useDepartmentPostSearch.js +48 -0
- package/lib/packages/Search/hooks/useDepartmentSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/useDepartmentSerch.js +56 -0
- package/lib/packages/Search/hooks/useDepartmentTopSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/useDepartmentTopSerch.js +47 -0
- package/lib/packages/Search/hooks/useIMSearch.d.ts +4 -0
- package/lib/packages/Search/hooks/useIMSearch.js +11 -0
- package/lib/packages/Search/hooks/usePostSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/usePostSerch.js +48 -0
- package/lib/packages/Search/hooks/usePublicGroupRoleSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/usePublicGroupRoleSerch.js +50 -0
- package/lib/packages/Search/hooks/usePublicGroupSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/usePublicGroupSerch.js +56 -0
- package/lib/packages/Search/hooks/usePublicGroupTopSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/usePublicGroupTopSerch.js +47 -0
- package/lib/packages/Search/hooks/useRoleSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/useRoleSerch.js +50 -0
- package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.d.ts +2 -0
- package/lib/packages/Search/hooks/useUserAdditionalInformationSearch.js +50 -0
- package/lib/packages/Search/hooks/useUserSerch.d.ts +2 -0
- package/lib/packages/Search/hooks/useUserSerch.js +68 -0
- package/lib/packages/Search/hooks/utils.d.ts +4 -0
- package/lib/packages/Search/hooks/utils.js +25 -0
- package/lib/packages/Search/index.d.ts +49 -0
- package/lib/packages/Search/index.js +72 -0
- package/lib/packages/Search/types.d.ts +208 -0
- package/lib/packages/Search/types.js +1 -0
- package/lib/packages/Session/Context.d.ts +16 -0
- package/lib/packages/Session/Context.js +2 -0
- package/lib/packages/Session/IMSessionError.d.ts +4 -0
- package/lib/packages/Session/IMSessionError.js +10 -0
- package/lib/packages/Session/hooks/index.d.ts +2 -0
- package/lib/packages/Session/hooks/index.js +2 -0
- package/lib/packages/Session/hooks/useSession.d.ts +12 -0
- package/lib/packages/Session/hooks/useSession.js +11 -0
- package/lib/packages/Session/hooks/useSessionState.d.ts +4 -0
- package/lib/packages/Session/hooks/useSessionState.js +24 -0
- package/lib/packages/Session/index.d.ts +16 -0
- package/lib/packages/Session/index.js +164 -0
- package/lib/packages/Session/type.d.ts +5 -0
- package/lib/packages/Session/type.js +1 -0
- package/lib/packages/Session/utils.d.ts +2 -0
- package/lib/packages/Session/utils.js +6 -0
- package/lib/packages/Smartlime/NotSearchPropError.d.ts +2 -0
- package/lib/packages/Smartlime/NotSearchPropError.js +13 -0
- package/lib/packages/Smartlime/index.d.ts +19 -0
- package/lib/packages/Smartlime/index.js +23 -0
- package/lib/packages/Tenant/Context.d.ts +6 -0
- package/lib/packages/Tenant/Context.js +2 -0
- package/lib/packages/Tenant/IMTenantError.d.ts +4 -0
- package/lib/packages/Tenant/IMTenantError.js +10 -0
- package/lib/packages/Tenant/hooks/index.d.ts +1 -0
- package/lib/packages/Tenant/hooks/index.js +1 -0
- package/lib/packages/Tenant/hooks/useIMBaseUrl.d.ts +2 -0
- package/lib/packages/Tenant/hooks/useIMBaseUrl.js +10 -0
- package/lib/packages/Tenant/index.d.ts +10 -0
- package/lib/packages/Tenant/index.js +19 -0
- package/lib/packages/WebView/IMWebViewError.d.ts +4 -0
- package/lib/packages/WebView/IMWebViewError.js +10 -0
- package/lib/packages/WebView/hooks/index.d.ts +1 -0
- package/lib/packages/WebView/hooks/index.js +1 -0
- package/lib/packages/WebView/hooks/useHackSearchUI.d.ts +8 -0
- package/lib/packages/WebView/hooks/useHackSearchUI.js +49 -0
- package/lib/packages/WebView/index.d.ts +11 -0
- package/lib/packages/WebView/index.js +166 -0
- package/lib/utils/mergeRef.d.ts +1 -0
- package/lib/utils/mergeRef.js +14 -0
- package/lib/utils/path.d.ts +1 -0
- package/lib/utils/path.js +16 -0
- package/package.json +87 -0
- package/tsconfig.json +36 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
export interface SuccessResponse<T> {
|
|
2
|
+
error: false;
|
|
3
|
+
message: string;
|
|
4
|
+
data: T;
|
|
5
|
+
}
|
|
6
|
+
export interface Success<T> {
|
|
7
|
+
readonly type: 'success';
|
|
8
|
+
readonly response: SuccessResponse<T>;
|
|
9
|
+
}
|
|
10
|
+
export interface Error {
|
|
11
|
+
readonly type: 'error';
|
|
12
|
+
readonly detail: unknown;
|
|
13
|
+
readonly response: Response;
|
|
14
|
+
}
|
|
15
|
+
export interface Exception {
|
|
16
|
+
readonly type: 'exception';
|
|
17
|
+
readonly detail: unknown;
|
|
18
|
+
}
|
|
19
|
+
export type SearchResult<T> = Exception | Error | Success<T>;
|
|
20
|
+
export interface UserData {
|
|
21
|
+
user_cd: string;
|
|
22
|
+
user_name: string;
|
|
23
|
+
user_search_name: string;
|
|
24
|
+
email_address1?: string | null;
|
|
25
|
+
delete_flag: number;
|
|
26
|
+
sort1: number;
|
|
27
|
+
sort2: string;
|
|
28
|
+
sort3: string;
|
|
29
|
+
}
|
|
30
|
+
export interface UserSearchRecord {
|
|
31
|
+
type: 'imm_user';
|
|
32
|
+
keyFields: ['user_cd'];
|
|
33
|
+
displayName: string;
|
|
34
|
+
deleteFlag: false;
|
|
35
|
+
data: UserData;
|
|
36
|
+
}
|
|
37
|
+
export type UserSearchResult = SearchResult<UserSearchRecord[]>;
|
|
38
|
+
export type UserSearchResponse = SuccessResponse<UserSearchRecord[]>;
|
|
39
|
+
export interface DepartmentSet {
|
|
40
|
+
company_cd: string;
|
|
41
|
+
department_set_cd: string;
|
|
42
|
+
}
|
|
43
|
+
export interface DepartmentData {
|
|
44
|
+
company_cd: string;
|
|
45
|
+
department_set_cd: string;
|
|
46
|
+
department_cd: string;
|
|
47
|
+
department_name: string;
|
|
48
|
+
delete_flag: number;
|
|
49
|
+
}
|
|
50
|
+
export interface DepartmentInclusion {
|
|
51
|
+
full_path_name: string[];
|
|
52
|
+
}
|
|
53
|
+
export interface DepartmentSearchRecord {
|
|
54
|
+
identifier: string;
|
|
55
|
+
inclusion: DepartmentInclusion;
|
|
56
|
+
displayName: string;
|
|
57
|
+
deleteFlag: false;
|
|
58
|
+
keyFields: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
data: DepartmentData;
|
|
61
|
+
}
|
|
62
|
+
export type DepartmentSearcResult = SearchResult<DepartmentSearchRecord[]>;
|
|
63
|
+
export type DepartmentSearchResponse = SuccessResponse<DepartmentSearchRecord[]>;
|
|
64
|
+
export interface DepartmentTopData {
|
|
65
|
+
company_cd: string;
|
|
66
|
+
department_set_cd: string;
|
|
67
|
+
department_cd: string;
|
|
68
|
+
department_name: string;
|
|
69
|
+
deleted_data: number;
|
|
70
|
+
}
|
|
71
|
+
export interface DepartmentTopInclusion {
|
|
72
|
+
full_path_name: string[];
|
|
73
|
+
}
|
|
74
|
+
export interface DepartmentTopSearchRecord {
|
|
75
|
+
type: string;
|
|
76
|
+
keyFields: string[];
|
|
77
|
+
deleteFlag: false;
|
|
78
|
+
displayName: string;
|
|
79
|
+
data: DepartmentTopData;
|
|
80
|
+
inclusion: DepartmentTopInclusion;
|
|
81
|
+
isParent: false;
|
|
82
|
+
}
|
|
83
|
+
export type DepartmentTopSearcResult = SearchResult<DepartmentTopSearchRecord[]>;
|
|
84
|
+
export type DepartmentTopSearchResponse = SuccessResponse<DepartmentTopSearchRecord[]>;
|
|
85
|
+
export interface PostData {
|
|
86
|
+
company_cd: string;
|
|
87
|
+
department_set_cd: string;
|
|
88
|
+
post_cd: string;
|
|
89
|
+
post_name: string;
|
|
90
|
+
delete_flag: number;
|
|
91
|
+
}
|
|
92
|
+
export interface PostSearchRecord {
|
|
93
|
+
type: string;
|
|
94
|
+
keyFields: string[];
|
|
95
|
+
deleteFlag: false;
|
|
96
|
+
displayName: string;
|
|
97
|
+
data: PostData;
|
|
98
|
+
}
|
|
99
|
+
export type PostSearcResult = SearchResult<PostSearchRecord[]>;
|
|
100
|
+
export type PostSearchResponse = SuccessResponse<PostSearchRecord[]>;
|
|
101
|
+
export interface PublicGroupData {
|
|
102
|
+
public_group_set_cd: string;
|
|
103
|
+
public_group_cd: string;
|
|
104
|
+
public_group_name: string;
|
|
105
|
+
delete_flag: number;
|
|
106
|
+
}
|
|
107
|
+
export interface PublicGroupInclusion {
|
|
108
|
+
full_path_name: string[];
|
|
109
|
+
}
|
|
110
|
+
export interface PublicGroupSearchRecord {
|
|
111
|
+
identifier: string;
|
|
112
|
+
inclusion: PublicGroupInclusion;
|
|
113
|
+
displayName: string;
|
|
114
|
+
deleteFlag: false;
|
|
115
|
+
keyFields: string[];
|
|
116
|
+
type: string;
|
|
117
|
+
data: PublicGroupData;
|
|
118
|
+
}
|
|
119
|
+
export type PublicGroupSearcResult = SearchResult<PublicGroupSearchRecord[]>;
|
|
120
|
+
export type PublicGroupSearcResponse = SuccessResponse<PublicGroupSearchRecord[]>;
|
|
121
|
+
export interface PublicGroupTopData {
|
|
122
|
+
public_group_set_cd: string;
|
|
123
|
+
public_group_cd: string;
|
|
124
|
+
public_group_name: string;
|
|
125
|
+
delete_flag: number;
|
|
126
|
+
}
|
|
127
|
+
export interface PublicGroupTopSearchRecord {
|
|
128
|
+
type: string;
|
|
129
|
+
keyFields: string[];
|
|
130
|
+
deleteFlag: false;
|
|
131
|
+
displayName: string;
|
|
132
|
+
data: PublicGroupTopData;
|
|
133
|
+
isParent: false;
|
|
134
|
+
}
|
|
135
|
+
export type PublicGroupTopSearchResult = SearchResult<PublicGroupTopSearchRecord[]>;
|
|
136
|
+
export type PublicGroupTopSearchResponse = SuccessResponse<PublicGroupTopSearchRecord[]>;
|
|
137
|
+
export interface PublicGroupSet {
|
|
138
|
+
public_group_set_cd: string;
|
|
139
|
+
}
|
|
140
|
+
export interface RoleData {
|
|
141
|
+
public_group_set_cd: string;
|
|
142
|
+
role_cd: string;
|
|
143
|
+
role_name: string;
|
|
144
|
+
delete_flag: number;
|
|
145
|
+
}
|
|
146
|
+
export interface RoleSearchRecord {
|
|
147
|
+
type: string;
|
|
148
|
+
keyFields: string[];
|
|
149
|
+
deleteFlag: false;
|
|
150
|
+
displayName: string;
|
|
151
|
+
data: RoleData;
|
|
152
|
+
}
|
|
153
|
+
export type RoleSearchResult = SearchResult<RoleSearchRecord[]>;
|
|
154
|
+
export type RoleSearchResponse = SuccessResponse<RoleSearchRecord[]>;
|
|
155
|
+
export interface UserAdditionalInformationSearchRecord {
|
|
156
|
+
mainDept: string[];
|
|
157
|
+
othDept: string[];
|
|
158
|
+
}
|
|
159
|
+
export type UserAdditionalInformationSearchResult = SearchResult<UserAdditionalInformationSearchRecord>;
|
|
160
|
+
export type UserAdditionalInformationSearchResponse = SuccessResponse<UserAdditionalInformationSearchRecord>;
|
|
161
|
+
export interface Department {
|
|
162
|
+
department_cd: string;
|
|
163
|
+
}
|
|
164
|
+
export interface DepartmentPostDepartmentSet {
|
|
165
|
+
company_cd: string;
|
|
166
|
+
department_set_cd: string;
|
|
167
|
+
department: Department;
|
|
168
|
+
}
|
|
169
|
+
export interface DepartmentPostData {
|
|
170
|
+
company_cd: string;
|
|
171
|
+
department_set_cd: string;
|
|
172
|
+
post_cd: string;
|
|
173
|
+
post_name: string;
|
|
174
|
+
delete_flag: number;
|
|
175
|
+
department_cd: string;
|
|
176
|
+
}
|
|
177
|
+
export interface DepartmentPostSearchRecord {
|
|
178
|
+
type: string;
|
|
179
|
+
keyFields: string[];
|
|
180
|
+
deleteFlag: false;
|
|
181
|
+
displayName: string;
|
|
182
|
+
data: DepartmentPostData;
|
|
183
|
+
}
|
|
184
|
+
export type DepartmentPostSearchResult = SearchResult<DepartmentPostSearchRecord[]>;
|
|
185
|
+
export type DepartmentPostSearchResponse = SuccessResponse<DepartmentPostSearchRecord[]>;
|
|
186
|
+
export interface PublicGroup {
|
|
187
|
+
public_group_cd: string;
|
|
188
|
+
}
|
|
189
|
+
export interface PublicGroupRoleSet {
|
|
190
|
+
public_group_set_cd: string;
|
|
191
|
+
public_group: PublicGroup;
|
|
192
|
+
}
|
|
193
|
+
export interface PublicGroupRoleData {
|
|
194
|
+
public_group_set_cd: string;
|
|
195
|
+
role_cd: string;
|
|
196
|
+
role_name: string;
|
|
197
|
+
delete_flag: number;
|
|
198
|
+
public_group_cd: string;
|
|
199
|
+
}
|
|
200
|
+
export interface PublicGroupRoleRecord {
|
|
201
|
+
type: string;
|
|
202
|
+
keyFields: string[];
|
|
203
|
+
deleteFlag: false;
|
|
204
|
+
displayName: string;
|
|
205
|
+
data: PublicGroupRoleData;
|
|
206
|
+
}
|
|
207
|
+
export type PublicGroupRoleSearchResult = SearchResult<PublicGroupRoleRecord[]>;
|
|
208
|
+
export type PublicGroupRoleSearchResponse = SuccessResponse<PublicGroupRoleRecord[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ErrorResult, SuccessResult } from '.';
|
|
3
|
+
import { RenderTarget } from '../../_shared/renderTarget';
|
|
4
|
+
import setCookie from 'set-cookie-parser';
|
|
5
|
+
export interface SessionContext {
|
|
6
|
+
getSession: () => {
|
|
7
|
+
cookies: setCookie.Cookie[] | null;
|
|
8
|
+
};
|
|
9
|
+
getSessionAsync: () => Promise<{
|
|
10
|
+
cookies: setCookie.Cookie[] | null;
|
|
11
|
+
}>;
|
|
12
|
+
request: () => Promise<SuccessResult | ErrorResult>;
|
|
13
|
+
destroy: () => void;
|
|
14
|
+
sessionStateRenderTarget: RenderTarget;
|
|
15
|
+
}
|
|
16
|
+
export declare const Context: import("react").Context<SessionContext | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const errorType = 'IMSessionError';
|
|
2
|
+
export class IMSessionError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
if (Error.captureStackTrace) {
|
|
6
|
+
Error.captureStackTrace(this, IMSessionError);
|
|
7
|
+
}
|
|
8
|
+
this.name = errorType;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context as DefaultContext } from '../Context';
|
|
2
|
+
export declare const useSession: (Context?: typeof DefaultContext) => {
|
|
3
|
+
getSession: () => {
|
|
4
|
+
cookies: import("set-cookie-parser").Cookie[] | null;
|
|
5
|
+
};
|
|
6
|
+
getSessionAsync: () => Promise<{
|
|
7
|
+
cookies: import("set-cookie-parser").Cookie[] | null;
|
|
8
|
+
}>;
|
|
9
|
+
request: () => Promise<import("..").SuccessResult | import("..").ErrorResult>;
|
|
10
|
+
update: () => Promise<import("..").SuccessResult | import("..").ErrorResult>;
|
|
11
|
+
destroy: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { Context as DefaultContext } from '../Context';
|
|
3
|
+
import { IMSessionError } from '../IMSessionError';
|
|
4
|
+
export const useSession = (Context) => {
|
|
5
|
+
const meContext = useContext(Context || DefaultContext);
|
|
6
|
+
if (meContext == null) {
|
|
7
|
+
throw new IMSessionError('useSession requires either a Context provide or an ancestor element with a IMSessionProvider.');
|
|
8
|
+
}
|
|
9
|
+
const { getSession, getSessionAsync, request, destroy } = meContext;
|
|
10
|
+
return { getSession, getSessionAsync, request, update: request, destroy };
|
|
11
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useContext, useEffect, useReducer, useRef } from 'react';
|
|
2
|
+
import { Context as DefaultContext } from '../Context';
|
|
3
|
+
import { IMSessionError } from '../IMSessionError';
|
|
4
|
+
export const useSessionState = (Context) => {
|
|
5
|
+
const initRef = useRef(true);
|
|
6
|
+
const [, forceRender] = useReducer((s) => s + 1, 0);
|
|
7
|
+
const meContext = useContext(Context || DefaultContext);
|
|
8
|
+
if (meContext == null) {
|
|
9
|
+
throw new IMSessionError('useSessionState requires either a Context provide or an ancestor element with a IMSessionProvider.');
|
|
10
|
+
}
|
|
11
|
+
const { cookies } = meContext.getSession();
|
|
12
|
+
if (initRef.current) {
|
|
13
|
+
initRef.current = false;
|
|
14
|
+
meContext.sessionStateRenderTarget.addEventListener(forceRender);
|
|
15
|
+
}
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
return () => {
|
|
18
|
+
meContext.sessionStateRenderTarget.removeEventListener(forceRender);
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
return {
|
|
22
|
+
cookies: cookies,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Context as DefaultContext } from './Context';
|
|
3
|
+
export interface SessionResponse {
|
|
4
|
+
error: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface SuccessResult {
|
|
7
|
+
status: 'success';
|
|
8
|
+
}
|
|
9
|
+
export interface ErrorResult {
|
|
10
|
+
status: 'error';
|
|
11
|
+
}
|
|
12
|
+
export interface IMSessionProps {
|
|
13
|
+
children: JSX.Element;
|
|
14
|
+
sessionContext?: typeof DefaultContext;
|
|
15
|
+
}
|
|
16
|
+
export declare const IMSession: ({ children, sessionContext }: IMSessionProps) => JSX.Element;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useRenderTarget } from '../../_shared/renderTarget';
|
|
3
|
+
import { useIMFetch } from '../Fetch';
|
|
4
|
+
import { Context as DefaultContext } from './Context';
|
|
5
|
+
import { IMSessionError } from './IMSessionError';
|
|
6
|
+
import setCookie from 'set-cookie-parser';
|
|
7
|
+
import { makeCookie } from './utils';
|
|
8
|
+
const useSessionStateRef = (renderTarget) => {
|
|
9
|
+
const cookieRef = useRef(null);
|
|
10
|
+
const setter = useCallback((cookie, silent) => {
|
|
11
|
+
if (cookieRef.current === cookie)
|
|
12
|
+
return;
|
|
13
|
+
cookieRef.current = cookie;
|
|
14
|
+
if (!silent)
|
|
15
|
+
renderTarget.dispatch();
|
|
16
|
+
}, []);
|
|
17
|
+
const getter = useCallback(() => {
|
|
18
|
+
const cookie = cookieRef.current;
|
|
19
|
+
if (cookie) {
|
|
20
|
+
const splitCookieHeaders = setCookie.splitCookiesString(cookie);
|
|
21
|
+
const cookies = setCookie.parse(splitCookieHeaders);
|
|
22
|
+
return {
|
|
23
|
+
cookies: cookies,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
cookies: null,
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
cookieRef,
|
|
33
|
+
},
|
|
34
|
+
setter,
|
|
35
|
+
getter,
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
const useLogout = () => {
|
|
39
|
+
const imFetch = useIMFetch({ noValidate: true });
|
|
40
|
+
return useCallback((cookie) => {
|
|
41
|
+
imFetch('/logout', {
|
|
42
|
+
headers: {
|
|
43
|
+
Cookie: cookie,
|
|
44
|
+
},
|
|
45
|
+
method: 'GET',
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
};
|
|
49
|
+
const makeEncodeParams = (clientTypeId = 'pc') => {
|
|
50
|
+
return `${`clientTypeId=${encodeURIComponent(clientTypeId)}`}`;
|
|
51
|
+
};
|
|
52
|
+
const useRequest = (setter, getter) => {
|
|
53
|
+
const imFetch = useIMFetch();
|
|
54
|
+
const logout = useLogout();
|
|
55
|
+
const request = useCallback(async (clientTypeId) => {
|
|
56
|
+
try {
|
|
57
|
+
const currentCookies = getter()?.cookies;
|
|
58
|
+
const params = makeEncodeParams(clientTypeId);
|
|
59
|
+
const response = await imFetch(`api/bearer/smacolow/session?${params}`, {
|
|
60
|
+
headers: {
|
|
61
|
+
Accept: 'application/json',
|
|
62
|
+
'X-Intramart-Session': 'keep', // https://document.intra-mart.jp/library/iap/public/im_web_api_maker/im_web_api_maker_programming_guide/texts/how_to_use_api/index.html#session-management
|
|
63
|
+
},
|
|
64
|
+
method: 'GET',
|
|
65
|
+
});
|
|
66
|
+
if (response.status === 200) {
|
|
67
|
+
const json = await response.json();
|
|
68
|
+
if (!json.error) {
|
|
69
|
+
const cookie = response.headers.get('Set-Cookie');
|
|
70
|
+
if (cookie) {
|
|
71
|
+
setter(cookie);
|
|
72
|
+
if (currentCookies)
|
|
73
|
+
logout(makeCookie(currentCookies));
|
|
74
|
+
return { status: 'success' };
|
|
75
|
+
}
|
|
76
|
+
throw new IMSessionError('could not find sessionid from Set-Cookie in response header.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new IMSessionError('failed to get session.');
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { status: 'error' };
|
|
83
|
+
}
|
|
84
|
+
}, [imFetch]);
|
|
85
|
+
return request;
|
|
86
|
+
};
|
|
87
|
+
const useDestroy = (renderTarget, setter, getter) => {
|
|
88
|
+
const logout = useLogout();
|
|
89
|
+
return useCallback(() => {
|
|
90
|
+
const { cookies } = getter();
|
|
91
|
+
if (cookies) {
|
|
92
|
+
logout(makeCookie(cookies));
|
|
93
|
+
}
|
|
94
|
+
setter(null);
|
|
95
|
+
renderTarget.dispatch();
|
|
96
|
+
}, []);
|
|
97
|
+
};
|
|
98
|
+
const useGetSessionAsync = (request, destroy, getter) => {
|
|
99
|
+
const imFetch = useIMFetch({ noValidate: true });
|
|
100
|
+
const logout = useLogout();
|
|
101
|
+
const reRequest = async (count) => {
|
|
102
|
+
const { status } = await request();
|
|
103
|
+
if (status === 'success') {
|
|
104
|
+
return status;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// retry up to 3 runs
|
|
108
|
+
if (count < 3)
|
|
109
|
+
return await reRequest(count + 1);
|
|
110
|
+
return status;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return useCallback(async () => {
|
|
114
|
+
const { cookies } = getter();
|
|
115
|
+
if (cookies) {
|
|
116
|
+
const response = await imFetch('api/smacolow/session', {
|
|
117
|
+
headers: {
|
|
118
|
+
Cookie: makeCookie(cookies),
|
|
119
|
+
},
|
|
120
|
+
method: 'GET',
|
|
121
|
+
});
|
|
122
|
+
if (response.status === 200) {
|
|
123
|
+
return getter();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
logout(makeCookie(cookies));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const status = await reRequest(0);
|
|
130
|
+
if (status === 'success')
|
|
131
|
+
return getter();
|
|
132
|
+
destroy();
|
|
133
|
+
throw new IMSessionError('failed to get session.');
|
|
134
|
+
}, [request]);
|
|
135
|
+
};
|
|
136
|
+
const unmountEffect = (getter) => {
|
|
137
|
+
const logout = useLogout();
|
|
138
|
+
const { cookies } = getter();
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
return () => {
|
|
141
|
+
// you can't catch APP CLOSE, so you need to deal with it individually.
|
|
142
|
+
if (cookies)
|
|
143
|
+
logout(makeCookie(cookies));
|
|
144
|
+
};
|
|
145
|
+
}, []);
|
|
146
|
+
};
|
|
147
|
+
export const IMSession = ({ children, sessionContext }) => {
|
|
148
|
+
const Context = sessionContext || DefaultContext;
|
|
149
|
+
const contextRef = useRef();
|
|
150
|
+
const sessionStateRenderTarget = useRenderTarget();
|
|
151
|
+
const [, setSession, getSession] = useSessionStateRef(sessionStateRenderTarget);
|
|
152
|
+
const request = useRequest(setSession, getSession);
|
|
153
|
+
const destroy = useDestroy(sessionStateRenderTarget, setSession, getSession);
|
|
154
|
+
const getSessionAsync = useGetSessionAsync(request, destroy, getSession);
|
|
155
|
+
unmountEffect(getSession);
|
|
156
|
+
contextRef.current = {
|
|
157
|
+
getSession,
|
|
158
|
+
getSessionAsync,
|
|
159
|
+
request,
|
|
160
|
+
destroy,
|
|
161
|
+
sessionStateRenderTarget,
|
|
162
|
+
};
|
|
163
|
+
return (<Context.Provider value={contextRef.current}>{children}</Context.Provider>);
|
|
164
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { IMSearchError } from '../Search/IMSearchError';
|
|
4
|
+
export const NotSearchPropError = ({ error }) => {
|
|
5
|
+
const initRef = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!initRef.current) {
|
|
8
|
+
initRef.current = true;
|
|
9
|
+
error(new IMSearchError('SearchComponent is not passed to Smartlime prop.'));
|
|
10
|
+
}
|
|
11
|
+
}, []);
|
|
12
|
+
return <View />;
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IMMe } from '../Me';
|
|
3
|
+
import { IMOAuth } from '../OAuth';
|
|
4
|
+
import { IMSession } from '../Session';
|
|
5
|
+
import { IMSearch } from '../Search';
|
|
6
|
+
interface SmartlimeProps {
|
|
7
|
+
children: JSX.Element;
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/**
|
|
10
|
+
* prop is currently not working.
|
|
11
|
+
*/
|
|
12
|
+
tenantId?: string;
|
|
13
|
+
imoauth: Omit<React.ComponentProps<typeof IMOAuth>, 'children'>;
|
|
14
|
+
imme?: Omit<React.ComponentProps<typeof IMMe>, 'children'>;
|
|
15
|
+
imsession?: Omit<React.ComponentProps<typeof IMSession>, 'children'>;
|
|
16
|
+
imseach?: Omit<React.ComponentProps<typeof IMSearch>, 'children'>;
|
|
17
|
+
}
|
|
18
|
+
export declare const Smartlime: ({ children, baseUrl, tenantId, imoauth, imme, imsession, imseach, }: SmartlimeProps) => JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IMMe } from '../Me';
|
|
2
|
+
import { IMOAuth } from '../OAuth';
|
|
3
|
+
import { IMSession } from '../Session';
|
|
4
|
+
import { IMSearch } from '../Search';
|
|
5
|
+
import { IMTenant } from '../Tenant';
|
|
6
|
+
import { NotSearchPropError } from './NotSearchPropError';
|
|
7
|
+
export const Smartlime = ({ children, baseUrl, tenantId, imoauth, imme, imsession, imseach, }) => {
|
|
8
|
+
const imtenantProps = { baseUrl, tenantId };
|
|
9
|
+
const imseachProps = imseach != null
|
|
10
|
+
? imseach
|
|
11
|
+
: {
|
|
12
|
+
SearchComponent: NotSearchPropError,
|
|
13
|
+
};
|
|
14
|
+
return (<IMTenant {...imtenantProps}>
|
|
15
|
+
<IMOAuth {...imoauth}>
|
|
16
|
+
<IMSession {...imsession}>
|
|
17
|
+
<IMMe {...imme}>
|
|
18
|
+
<IMSearch {...imseachProps}>{children}</IMSearch>
|
|
19
|
+
</IMMe>
|
|
20
|
+
</IMSession>
|
|
21
|
+
</IMOAuth>
|
|
22
|
+
</IMTenant>);
|
|
23
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const errorType = 'IMTenantError';
|
|
2
|
+
export class IMTenantError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
if (Error.captureStackTrace) {
|
|
6
|
+
Error.captureStackTrace(this, IMTenantError);
|
|
7
|
+
}
|
|
8
|
+
this.name = errorType;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIMBaseUrl';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIMBaseUrl';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { Context as DefaultContext } from '../Context';
|
|
3
|
+
import { IMTenantError } from '../IMTenantError';
|
|
4
|
+
export const useIMBaseUrl = (Context) => {
|
|
5
|
+
const tenantContext = useContext(Context || DefaultContext);
|
|
6
|
+
if (tenantContext == null) {
|
|
7
|
+
throw new IMTenantError('useIMBaseUrl requires either a Context provide or an ancestor element with a IMTenantProvider.');
|
|
8
|
+
}
|
|
9
|
+
return tenantContext.getBaseUrl();
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Context as DefaultContext } from './Context';
|
|
3
|
+
interface IMTenantProps {
|
|
4
|
+
children: JSX.Element;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
tenantId?: string;
|
|
7
|
+
tenantContext?: typeof DefaultContext;
|
|
8
|
+
}
|
|
9
|
+
export declare const IMTenant: ({ children, baseUrl, tenantId, tenantContext, }: IMTenantProps) => JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useCallback, useRef } from 'react';
|
|
2
|
+
import { Context as DefaultContext } from './Context';
|
|
3
|
+
const useGetBaseUrl = (baseUrl) => {
|
|
4
|
+
return useCallback(() => baseUrl, [baseUrl]);
|
|
5
|
+
};
|
|
6
|
+
const useGetTenantId = (tenantId) => {
|
|
7
|
+
return useCallback(() => tenantId, [tenantId]);
|
|
8
|
+
};
|
|
9
|
+
export const IMTenant = ({ children, baseUrl, tenantId, tenantContext, }) => {
|
|
10
|
+
const Context = tenantContext || DefaultContext;
|
|
11
|
+
const contextRef = useRef();
|
|
12
|
+
const getBaseUrl = useGetBaseUrl(baseUrl);
|
|
13
|
+
const getTenantId = useGetTenantId(tenantId);
|
|
14
|
+
contextRef.current = {
|
|
15
|
+
getBaseUrl,
|
|
16
|
+
getTenantId,
|
|
17
|
+
};
|
|
18
|
+
return (<Context.Provider value={contextRef.current}>{children}</Context.Provider>);
|
|
19
|
+
};
|