@planningcenter/chat-react-native 4.8.0-qa-staging.11 → 4.8.0-qa-staging.12
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/build/contexts/chat_context.d.ts +2 -2
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +1 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +143 -338
- package/build/contexts/session_context.js.map +1 -1
- package/build/utils/client/client.d.ts +9 -5
- package/build/utils/client/client.d.ts.map +1 -1
- package/build/utils/client/client.js +95 -78
- package/build/utils/client/client.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/contexts/session_context.tsx +46 -0
- package/src/__tests__/utils/client.ts +36 -0
- package/src/contexts/chat_context.tsx +2 -2
- package/src/contexts/session_context.tsx +19 -14
- package/src/utils/client/client.ts +95 -52
|
@@ -2,15 +2,15 @@ import React from 'react';
|
|
|
2
2
|
import { ColorSchemeName } from 'react-native';
|
|
3
3
|
import { AgeCheckContactInfo } from '../screens/age_check/screen_props';
|
|
4
4
|
import { DeepPartial } from '../types';
|
|
5
|
-
import { FailedResponse } from '../types';
|
|
6
5
|
import { ENV, OauthType, PartialToken, Session } from '../utils';
|
|
6
|
+
import { OnUnauthorizedResponse } from '../utils/client/client';
|
|
7
7
|
import { ChatTheme, DefaultTheme } from '../utils/theme';
|
|
8
8
|
export interface ChatProviderProps {
|
|
9
9
|
env?: ENV;
|
|
10
10
|
prototypeName?: string;
|
|
11
11
|
giphyApiKey?: string;
|
|
12
12
|
onAgeDisqualification?: (params: AgeCheckContactInfo) => void;
|
|
13
|
-
onUnauthorizedResponse:
|
|
13
|
+
onUnauthorizedResponse: OnUnauthorizedResponse;
|
|
14
14
|
token?: PartialToken;
|
|
15
15
|
tokenType?: OauthType;
|
|
16
16
|
theme: CreateChatThemeProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEtE,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;IAC7D,sBAAsB,EAAE,sBAAsB,CAAA;IAC9C,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACxE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,SAAS,CAAA;IAChB,qBAAqB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAA;CAC7D;AAED,eAAO,MAAM,WAAW,iCAUtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,2CAmC5F;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,cAAc,wBAE1B,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,sDAGhC,oBAAoB,KAAG,SAYzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.js","names":["merge","React","createContext","useMemo","useColorScheme","Session","setLiquidGlassCapability","defaultTheme","jsx","_jsx","ChatContext","env","undefined","giphyApiKey","onAgeDisqualification","_params","onUnauthorizedResponse","session","theme","token","edgeToEdge","liquidGlassEnabled","ChatProvider","t0","$","_c","children","value","prototypeName","t1","tokenType","t2","t3","_temp","t4","useCreateChatTheme","t5","type","t6","contextValue","t7","Provider","useChatContext","useContext","colorScheme","appColorScheme","customTheme","internalColorScheme","colors"],"sources":["../../src/contexts/chat_context.tsx"],"sourcesContent":["import { merge } from 'lodash'\nimport React, { createContext, useMemo } from 'react'\nimport { ColorSchemeName, useColorScheme } from 'react-native'\nimport { AgeCheckContactInfo } from '../screens/age_check/screen_props'\nimport { DeepPartial } from '../types'\nimport {
|
|
1
|
+
{"version":3,"file":"chat_context.js","names":["merge","React","createContext","useMemo","useColorScheme","Session","setLiquidGlassCapability","defaultTheme","jsx","_jsx","ChatContext","env","undefined","giphyApiKey","onAgeDisqualification","_params","onUnauthorizedResponse","session","theme","token","edgeToEdge","liquidGlassEnabled","ChatProvider","t0","$","_c","children","value","prototypeName","t1","tokenType","t2","t3","_temp","t4","useCreateChatTheme","t5","type","t6","contextValue","t7","Provider","useChatContext","useContext","colorScheme","appColorScheme","customTheme","internalColorScheme","colors"],"sources":["../../src/contexts/chat_context.tsx"],"sourcesContent":["import { merge } from 'lodash'\nimport React, { createContext, useMemo } from 'react'\nimport { ColorSchemeName, useColorScheme } from 'react-native'\nimport { AgeCheckContactInfo } from '../screens/age_check/screen_props'\nimport { DeepPartial } from '../types'\nimport { ENV, OauthType, PartialToken, Session } from '../utils'\nimport { OnUnauthorizedResponse } from '../utils/client/client'\nimport { setLiquidGlassCapability } from '../utils/liquid_glass'\nimport { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'\n\nexport interface ChatProviderProps {\n env?: ENV\n prototypeName?: string\n giphyApiKey?: string\n onAgeDisqualification?: (params: AgeCheckContactInfo) => void\n onUnauthorizedResponse: OnUnauthorizedResponse\n token?: PartialToken\n tokenType?: OauthType\n theme: CreateChatThemeProps\n edgeToEdge?: boolean\n liquidGlassEnabled?: boolean\n}\n\nexport interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {\n session: Session\n theme: ChatTheme\n onAgeDisqualification: (params: AgeCheckContactInfo) => void\n}\n\nexport const ChatContext = createContext<ChatContextValue>({\n env: undefined,\n giphyApiKey: undefined,\n onAgeDisqualification: (_params: AgeCheckContactInfo) => {},\n onUnauthorizedResponse: () => {},\n session: new Session(),\n theme: defaultTheme('light'),\n token: undefined,\n edgeToEdge: true,\n liquidGlassEnabled: false,\n})\n\nexport function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {\n const {\n env,\n prototypeName,\n token,\n onAgeDisqualification = (_params: AgeCheckContactInfo) => {},\n onUnauthorizedResponse,\n giphyApiKey,\n tokenType,\n edgeToEdge = true,\n liquidGlassEnabled = false,\n } = value\n // Set during render, not in an effect — navigator options factories read it\n // before effects would run.\n setLiquidGlassCapability(liquidGlassEnabled)\n const theme = useCreateChatTheme(value.theme || {})\n const session = useMemo(\n () => new Session({ token, env, prototypeName, type: tokenType }),\n [env, prototypeName, token, tokenType]\n )\n\n const contextValue: ChatContextValue = {\n ...value,\n edgeToEdge,\n liquidGlassEnabled,\n env,\n giphyApiKey,\n onAgeDisqualification,\n onUnauthorizedResponse,\n session,\n theme,\n token,\n }\n\n return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>\n}\n\nexport interface CreateChatThemeProps {\n theme?: DeepPartial<DefaultTheme>\n colorScheme?: ColorSchemeName\n}\n\nexport const useChatContext = () => {\n return React.useContext(ChatContext)\n}\n\nexport const useCreateChatTheme = ({\n theme: customTheme = {},\n colorScheme: appColorScheme,\n}: CreateChatThemeProps): ChatTheme => {\n const internalColorScheme = useColorScheme() || 'light'\n const colorScheme = appColorScheme || internalColorScheme\n\n const theme = {\n ...merge({}, defaultTheme(colorScheme), customTheme),\n colors: {\n ...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),\n },\n }\n\n return theme\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,QAAQ;AAC9B,OAAOC,KAAK,IAAIC,aAAa,EAAEC,OAAO,QAAQ,OAAO;AACrD,SAA0BC,cAAc,QAAQ,cAAc;AAG9D,SAAuCC,OAAO,QAAQ,UAAU;AAEhE,SAASC,wBAAwB,QAAQ,uBAAuB;AAChE,SAAoBC,YAAY,QAAsB,gBAAgB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAqBtE,OAAO,MAAMC,WAAW,GAAGR,aAAa,CAAmB;EACzDS,GAAG,EAAEC,SAAS;EACdC,WAAW,EAAED,SAAS;EACtBE,qBAAqB,EAAGC,OAA4B,IAAK,CAAC,CAAC;EAC3DC,sBAAsB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAChCC,OAAO,EAAE,IAAIZ,OAAO,CAAC,CAAC;EACtBa,KAAK,EAAEX,YAAY,CAAC,OAAO,CAAC;EAC5BY,K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A;EAAA;IAAAA,EAAA,GAAAV,CAAA;EAAA;EAAA,IAAAY,EAAA;EAAA,IAAAZ,CAAA,QAAAO,EAAA,IAAAP,CAAA,QAAAU,EAAA;IAJWE,EAAA;MAAA,GACTL,EAAiD;MAAAiB,MAAA,EAC5Cd;IAGV,CAAC;IAAAV,CAAA,MAAAO,EAAA;IAAAP,CAAA,MAAAU,EAAA;IAAAV,CAAA,MAAAY,EAAA;EAAA;IAAAA,EAAA,GAAAZ,CAAA;EAAA;EALD,MAAAN,KAAA,GAAckB,EAKb;EAAA,OAEMlB,KAAK;AAAA,CACb","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export type SessionContextValue = {
|
|
|
10
10
|
session: Session;
|
|
11
11
|
sessions: Sessions;
|
|
12
12
|
token: OAuthToken | undefined;
|
|
13
|
-
handleUnauthorizedResponse: (_response: FailedResponse) =>
|
|
13
|
+
handleUnauthorizedResponse: (_response: FailedResponse) => Promise<OAuthToken | undefined>;
|
|
14
14
|
logout: () => void;
|
|
15
15
|
setToken: (_token: OAuthToken) => void;
|
|
16
16
|
switchSession: (_sessionId: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_context.d.ts","sourceRoot":"","sources":["../../src/contexts/session_context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,EAEZ,iBAAiB,
|
|
1
|
+
{"version":3,"file":"session_context.d.ts","sourceRoot":"","sources":["../../src/contexts/session_context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,uBAAuB,CAAA;AAChE,OAAO,KAAK,EAAE,EAEZ,iBAAiB,EAMlB,MAAM,OAAO,CAAA;AAMd,OAAO,EAAyB,cAAc,EAAE,UAAU,EAAwB,MAAM,UAAU,CAAA;AAElG,OAAO,EAAE,GAAG,EAAgB,OAAO,EAA8B,MAAM,UAAU,CAAA;AACjF,OAAO,EAAE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CAAC,EAAE,MAAM,CAAA;QAChB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF,CAAA;AAgCD,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,WAAW,EACX,MAAM,GACP,EAAE,iBAAiB,CAAC;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAC,2CAqN/E"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { c as _c } from "react/compiler-runtime";
|
|
2
1
|
import { useMutation } from '@tanstack/react-query';
|
|
3
|
-
import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import React, { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
3
|
import { Alert } from 'react-native';
|
|
5
4
|
import { currentPersonQueryKey } from '../hooks/use_current_person';
|
|
6
5
|
import { organizationRequestArgs } from '../hooks/use_organization';
|
|
@@ -19,7 +18,7 @@ export const SessionContext = createContext({
|
|
|
19
18
|
session: new Session(),
|
|
20
19
|
sessions: {},
|
|
21
20
|
token: undefined,
|
|
22
|
-
handleUnauthorizedResponse: () =>
|
|
21
|
+
handleUnauthorizedResponse: () => Promise.resolve(undefined),
|
|
23
22
|
logout: () => null,
|
|
24
23
|
setToken: () => null,
|
|
25
24
|
switchSession: () => null,
|
|
@@ -59,369 +58,175 @@ const decorateSession = async session => {
|
|
|
59
58
|
}
|
|
60
59
|
return session;
|
|
61
60
|
};
|
|
62
|
-
export function SessionContextProvider(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
config
|
|
68
|
-
} = t0;
|
|
61
|
+
export function SessionContextProvider({
|
|
62
|
+
children,
|
|
63
|
+
queryClient,
|
|
64
|
+
config
|
|
65
|
+
}) {
|
|
69
66
|
const {
|
|
70
67
|
secureStorage,
|
|
71
68
|
refreshTokenFn,
|
|
72
69
|
onLogout,
|
|
73
|
-
storageKeys
|
|
74
|
-
alertConfig
|
|
70
|
+
storageKeys = {},
|
|
71
|
+
alertConfig = {}
|
|
75
72
|
} = config;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$[0] = t1;
|
|
80
|
-
$[1] = t3;
|
|
81
|
-
} else {
|
|
82
|
-
t3 = $[1];
|
|
83
|
-
}
|
|
84
|
-
const storageKeys = t3;
|
|
85
|
-
let t4;
|
|
86
|
-
if ($[2] !== t2) {
|
|
87
|
-
t4 = t2 === undefined ? {} : t2;
|
|
88
|
-
$[2] = t2;
|
|
89
|
-
$[3] = t4;
|
|
90
|
-
} else {
|
|
91
|
-
t4 = $[3];
|
|
92
|
-
}
|
|
93
|
-
const alertConfig = t4;
|
|
94
|
-
const sessionsKey = storageKeys.sessions || "sessions-storage";
|
|
95
|
-
const [managerString, setManagerString] = useStorage(secureStorage, sessionsKey, "");
|
|
96
|
-
let t5;
|
|
97
|
-
if ($[4] !== managerString) {
|
|
98
|
-
t5 = SessionManager.hydrate(managerString);
|
|
99
|
-
$[4] = managerString;
|
|
100
|
-
$[5] = t5;
|
|
101
|
-
} else {
|
|
102
|
-
t5 = $[5];
|
|
103
|
-
}
|
|
104
|
-
const sessionManager = t5;
|
|
73
|
+
const sessionsKey = storageKeys.sessions || 'sessions-storage';
|
|
74
|
+
const [managerString, setManagerString] = useStorage(secureStorage, sessionsKey, '');
|
|
75
|
+
const sessionManager = useMemo(() => SessionManager.hydrate(managerString), [managerString]);
|
|
105
76
|
const sessions = sessionManager.sessions;
|
|
106
77
|
const currentSession = sessionManager.currentSession;
|
|
107
78
|
const [alertShown, setAlertShown] = useState(false);
|
|
108
79
|
const {
|
|
109
80
|
token
|
|
110
81
|
} = currentSession;
|
|
111
|
-
const t6 = token?.refresh_token;
|
|
112
|
-
let t7;
|
|
113
|
-
if ($[6] !== t6) {
|
|
114
|
-
t7 = ["refresh-token", t6];
|
|
115
|
-
$[6] = t6;
|
|
116
|
-
$[7] = t7;
|
|
117
|
-
} else {
|
|
118
|
-
t7 = $[7];
|
|
119
|
-
}
|
|
120
82
|
const {
|
|
121
83
|
mutate: refreshToken,
|
|
122
|
-
|
|
84
|
+
mutateAsync: refreshTokenAsync,
|
|
123
85
|
isError: isRefreshError
|
|
124
86
|
} = useMutation({
|
|
125
|
-
mutationKey:
|
|
87
|
+
mutationKey: ['refresh-token', token?.refresh_token],
|
|
126
88
|
mutationFn: () => {
|
|
127
89
|
if (!token?.refresh_token) {
|
|
128
|
-
return Promise.reject(new Error(
|
|
90
|
+
return Promise.reject(new Error('Refresh token is required'));
|
|
129
91
|
}
|
|
130
92
|
return refreshTokenFn({
|
|
131
93
|
refresh_token: token.refresh_token,
|
|
132
94
|
env: currentSession.env,
|
|
133
95
|
prototypeName: currentSession.prototypeName
|
|
134
|
-
}).then(
|
|
96
|
+
}).then(async refreshedToken => {
|
|
97
|
+
await handleTokenUpdate(refreshedToken);
|
|
98
|
+
return refreshedToken;
|
|
99
|
+
});
|
|
135
100
|
},
|
|
136
101
|
onError: t => {
|
|
137
102
|
handleRefreshFailed(t);
|
|
138
103
|
}
|
|
139
104
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const sameEnvironment = _env === session.env && _prototypeName === session.prototypeName;
|
|
160
|
-
if (sameEnvironment) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const productionEnvironments = ["production", "staging"];
|
|
164
|
-
const switchingToDevelopment = _env === "development" && productionEnvironments.includes(session.env);
|
|
165
|
-
const switchingToProduction = _env === "production" && session.env === "development";
|
|
166
|
-
const switchingPrototype = _env === "prototype" || session.env === "prototype";
|
|
167
|
-
if (switchingToDevelopment || switchingToProduction || switchingPrototype) {
|
|
168
|
-
const newSession = new Session({
|
|
169
|
-
env: _env,
|
|
170
|
-
prototypeName: _prototypeName
|
|
171
|
-
});
|
|
172
|
-
updatedManager.upsertSession(newSession);
|
|
173
|
-
}
|
|
174
|
-
updatedManager.setEnv(_env, _prototypeName);
|
|
175
|
-
await setManagerString(updatedManager.toString());
|
|
176
|
-
};
|
|
177
|
-
$[10] = managerString;
|
|
178
|
-
$[11] = setManagerString;
|
|
179
|
-
$[12] = t9;
|
|
180
|
-
} else {
|
|
181
|
-
t9 = $[12];
|
|
182
|
-
}
|
|
183
|
-
const handleSetEnv = t9;
|
|
184
|
-
let t10;
|
|
185
|
-
if ($[13] !== managerString || $[14] !== setManagerString) {
|
|
186
|
-
t10 = async session_0 => {
|
|
187
|
-
const updatedManager_0 = SessionManager.hydrate(managerString);
|
|
188
|
-
updatedManager_0.sessions[session_0.id] = session_0.toString();
|
|
189
|
-
updatedManager_0.currentSessionId = session_0.id;
|
|
190
|
-
await setManagerString(updatedManager_0.toString());
|
|
191
|
-
};
|
|
192
|
-
$[13] = managerString;
|
|
193
|
-
$[14] = setManagerString;
|
|
194
|
-
$[15] = t10;
|
|
195
|
-
} else {
|
|
196
|
-
t10 = $[15];
|
|
197
|
-
}
|
|
198
|
-
const handleCreateSession = t10;
|
|
199
|
-
let t11;
|
|
200
|
-
if ($[16] !== managerString || $[17] !== setManagerString) {
|
|
201
|
-
t11 = async sessionId => {
|
|
202
|
-
const updatedManager_1 = SessionManager.hydrate(managerString);
|
|
203
|
-
;
|
|
204
|
-
try {
|
|
205
|
-
updatedManager_1.switchSession(sessionId);
|
|
206
|
-
} catch (t12) {
|
|
207
|
-
Alert.alert("Error", "Session is not authenticated");
|
|
208
|
-
}
|
|
209
|
-
await setManagerString(updatedManager_1.toString());
|
|
210
|
-
};
|
|
211
|
-
$[16] = managerString;
|
|
212
|
-
$[17] = setManagerString;
|
|
213
|
-
$[18] = t11;
|
|
214
|
-
} else {
|
|
215
|
-
t11 = $[18];
|
|
216
|
-
}
|
|
217
|
-
const handleSwitchSession = t11;
|
|
218
|
-
let t12;
|
|
219
|
-
if ($[19] !== handleClearQueryClient || $[20] !== managerString || $[21] !== onLogout || $[22] !== setManagerString) {
|
|
220
|
-
t12 = async () => {
|
|
221
|
-
handleClearQueryClient();
|
|
222
|
-
const manager = SessionManager.hydrate(managerString);
|
|
223
|
-
if (manager.currentSessionId) {
|
|
224
|
-
manager.removeSession(manager.currentSessionId);
|
|
225
|
-
await setManagerString(manager.toString());
|
|
226
|
-
}
|
|
227
|
-
return onLogout();
|
|
228
|
-
};
|
|
229
|
-
$[19] = handleClearQueryClient;
|
|
230
|
-
$[20] = managerString;
|
|
231
|
-
$[21] = onLogout;
|
|
232
|
-
$[22] = setManagerString;
|
|
233
|
-
$[23] = t12;
|
|
234
|
-
} else {
|
|
235
|
-
t12 = $[23];
|
|
236
|
-
}
|
|
237
|
-
const handleLogout = t12;
|
|
238
|
-
let t13;
|
|
239
|
-
if ($[24] !== managerString || $[25] !== setManagerString) {
|
|
240
|
-
t13 = async t_0 => {
|
|
241
|
-
const updatedManager_2 = SessionManager.hydrate(managerString);
|
|
242
|
-
updatedManager_2.updateCurrentToken(t_0);
|
|
243
|
-
await setManagerString(updatedManager_2.toString());
|
|
244
|
-
};
|
|
245
|
-
$[24] = managerString;
|
|
246
|
-
$[25] = setManagerString;
|
|
247
|
-
$[26] = t13;
|
|
248
|
-
} else {
|
|
249
|
-
t13 = $[26];
|
|
250
|
-
}
|
|
251
|
-
const handleTokenUpdate = t13;
|
|
252
|
-
let t14;
|
|
253
|
-
if ($[27] !== handleLogout) {
|
|
254
|
-
t14 = t_1 => {
|
|
255
|
-
if (t_1.status !== 401) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const {
|
|
259
|
-
errors: t15
|
|
260
|
-
} = t_1;
|
|
261
|
-
const errors = t15 === undefined ? [] : t15;
|
|
262
|
-
const isForcedLogout = errors.some(_temp);
|
|
263
|
-
if (isForcedLogout) {
|
|
264
|
-
handleLogout();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
$[27] = handleLogout;
|
|
268
|
-
$[28] = t14;
|
|
269
|
-
} else {
|
|
270
|
-
t14 = $[28];
|
|
271
|
-
}
|
|
272
|
-
const handleRefreshFailed = t14;
|
|
273
|
-
let t15;
|
|
274
|
-
if ($[29] !== isRefreshingToken || $[30] !== refreshToken) {
|
|
275
|
-
t15 = async response => {
|
|
276
|
-
const {
|
|
277
|
-
errors: t16
|
|
278
|
-
} = response;
|
|
279
|
-
const errors_0 = t16 === undefined ? [] : t16;
|
|
280
|
-
const isUnauthorized = errors_0.some(_temp2);
|
|
281
|
-
if (isUnauthorized) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const isForcedLogout_0 = errors_0.some(_temp3);
|
|
285
|
-
const isExpiredToken = errors_0.some(_temp4);
|
|
286
|
-
if (!isRefreshingToken || isExpiredToken || isForcedLogout_0) {
|
|
287
|
-
refreshToken();
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
$[29] = isRefreshingToken;
|
|
291
|
-
$[30] = refreshToken;
|
|
292
|
-
$[31] = t15;
|
|
293
|
-
} else {
|
|
294
|
-
t15 = $[31];
|
|
295
|
-
}
|
|
296
|
-
const handleUnauthorizedResponse = t15;
|
|
297
|
-
const t16 = currentSession.token;
|
|
298
|
-
let t17;
|
|
299
|
-
if ($[32] !== currentSession || $[33] !== handleCreateSession || $[34] !== handleLogout || $[35] !== handleSetEnv || $[36] !== handleSwitchSession || $[37] !== handleTokenUpdate || $[38] !== handleUnauthorizedResponse || $[39] !== sessions || $[40] !== t16) {
|
|
300
|
-
t17 = {
|
|
301
|
-
env: currentSession.env,
|
|
302
|
-
token: t16,
|
|
303
|
-
session: currentSession,
|
|
304
|
-
sessions,
|
|
305
|
-
logout: handleLogout,
|
|
306
|
-
setToken: handleTokenUpdate,
|
|
307
|
-
handleUnauthorizedResponse,
|
|
308
|
-
setEnv: handleSetEnv,
|
|
309
|
-
switchSession: handleSwitchSession,
|
|
310
|
-
createSession: handleCreateSession
|
|
311
|
-
};
|
|
312
|
-
$[32] = currentSession;
|
|
313
|
-
$[33] = handleCreateSession;
|
|
314
|
-
$[34] = handleLogout;
|
|
315
|
-
$[35] = handleSetEnv;
|
|
316
|
-
$[36] = handleSwitchSession;
|
|
317
|
-
$[37] = handleTokenUpdate;
|
|
318
|
-
$[38] = handleUnauthorizedResponse;
|
|
319
|
-
$[39] = sessions;
|
|
320
|
-
$[40] = t16;
|
|
321
|
-
$[41] = t17;
|
|
322
|
-
} else {
|
|
323
|
-
t17 = $[41];
|
|
324
|
-
}
|
|
325
|
-
const sessionContextValue = t17;
|
|
326
|
-
const alertTitle = alertConfig.title || "Oops";
|
|
327
|
-
const alertMessage = alertConfig.message || "Something went wrong with your login!";
|
|
328
|
-
const retryText = alertConfig.retryText || "Keep trying";
|
|
329
|
-
const logoutText = alertConfig.logoutText || "Logout";
|
|
330
|
-
let t18;
|
|
331
|
-
if ($[42] !== alertMessage || $[43] !== alertShown || $[44] !== alertTitle || $[45] !== handleLogout || $[46] !== isRefreshError || $[47] !== logoutText || $[48] !== refreshToken || $[49] !== retryText || $[50] !== token?.refresh_token) {
|
|
332
|
-
t18 = () => {
|
|
333
|
-
if (isRefreshError && !alertShown && token?.refresh_token) {
|
|
334
|
-
setAlertShown(true);
|
|
335
|
-
Alert.alert(alertTitle, alertMessage, [{
|
|
336
|
-
text: retryText,
|
|
337
|
-
onPress: () => {
|
|
338
|
-
refreshToken();
|
|
339
|
-
setAlertShown(false);
|
|
340
|
-
}
|
|
341
|
-
}, {
|
|
342
|
-
text: logoutText,
|
|
343
|
-
onPress: () => handleLogout()
|
|
344
|
-
}]);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
$[42] = alertMessage;
|
|
348
|
-
$[43] = alertShown;
|
|
349
|
-
$[44] = alertTitle;
|
|
350
|
-
$[45] = handleLogout;
|
|
351
|
-
$[46] = isRefreshError;
|
|
352
|
-
$[47] = logoutText;
|
|
353
|
-
$[48] = refreshToken;
|
|
354
|
-
$[49] = retryText;
|
|
355
|
-
$[50] = token?.refresh_token;
|
|
356
|
-
$[51] = t18;
|
|
357
|
-
} else {
|
|
358
|
-
t18 = $[51];
|
|
359
|
-
}
|
|
360
|
-
const t19 = token?.refresh_token;
|
|
361
|
-
let t20;
|
|
362
|
-
if ($[52] !== alertMessage || $[53] !== alertShown || $[54] !== alertTitle || $[55] !== handleLogout || $[56] !== isRefreshError || $[57] !== logoutText || $[58] !== refreshToken || $[59] !== retryText || $[60] !== t19) {
|
|
363
|
-
t20 = [isRefreshError, handleLogout, alertShown, refreshToken, t19, alertTitle, alertMessage, retryText, logoutText];
|
|
364
|
-
$[52] = alertMessage;
|
|
365
|
-
$[53] = alertShown;
|
|
366
|
-
$[54] = alertTitle;
|
|
367
|
-
$[55] = handleLogout;
|
|
368
|
-
$[56] = isRefreshError;
|
|
369
|
-
$[57] = logoutText;
|
|
370
|
-
$[58] = refreshToken;
|
|
371
|
-
$[59] = retryText;
|
|
372
|
-
$[60] = t19;
|
|
373
|
-
$[61] = t20;
|
|
374
|
-
} else {
|
|
375
|
-
t20 = $[61];
|
|
376
|
-
}
|
|
377
|
-
useEffect(t18, t20);
|
|
378
|
-
let t21;
|
|
379
|
-
let t22;
|
|
380
|
-
if ($[62] !== managerString || $[63] !== setManagerString) {
|
|
381
|
-
t21 = () => {
|
|
382
|
-
const manager_0 = SessionManager.hydrate(managerString);
|
|
383
|
-
if (manager_0.currentSessionId === UNAUTHENTICATED_SESSION_ID) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
decorateSession(manager_0.currentSession).then(async decoratedSession => {
|
|
387
|
-
manager_0.upsertSession(decoratedSession);
|
|
388
|
-
await setManagerString(manager_0.toString());
|
|
105
|
+
const handleClearQueryClient = useCallback(() => {
|
|
106
|
+
cancelThrottledRefreshes(chatQueryClient);
|
|
107
|
+
cancelThrottledRefreshes(queryClient);
|
|
108
|
+
chatQueryClient.clear();
|
|
109
|
+
queryClient.clear();
|
|
110
|
+
}, [queryClient]);
|
|
111
|
+
const handleSetEnv = useCallback(async (_env, _prototypeName) => {
|
|
112
|
+
const updatedManager = SessionManager.hydrate(managerString);
|
|
113
|
+
const session = updatedManager.currentSession;
|
|
114
|
+
const sameEnvironment = _env === session.env && _prototypeName === session.prototypeName;
|
|
115
|
+
if (sameEnvironment) return;
|
|
116
|
+
const productionEnvironments = ['production', 'staging'];
|
|
117
|
+
const switchingToDevelopment = _env === 'development' && productionEnvironments.includes(session.env);
|
|
118
|
+
const switchingToProduction = _env === 'production' && session.env === 'development';
|
|
119
|
+
const switchingPrototype = _env === 'prototype' || session.env === 'prototype';
|
|
120
|
+
if (switchingToDevelopment || switchingToProduction || switchingPrototype) {
|
|
121
|
+
const newSession = new Session({
|
|
122
|
+
env: _env,
|
|
123
|
+
prototypeName: _prototypeName
|
|
389
124
|
});
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
125
|
+
updatedManager.upsertSession(newSession);
|
|
126
|
+
}
|
|
127
|
+
updatedManager.setEnv(_env, _prototypeName);
|
|
128
|
+
await setManagerString(updatedManager.toString());
|
|
129
|
+
}, [managerString, setManagerString]);
|
|
130
|
+
const handleCreateSession = useCallback(async session_0 => {
|
|
131
|
+
const updatedManager_0 = SessionManager.hydrate(managerString);
|
|
132
|
+
updatedManager_0.sessions[session_0.id] = session_0.toString();
|
|
133
|
+
updatedManager_0.currentSessionId = session_0.id;
|
|
134
|
+
await setManagerString(updatedManager_0.toString());
|
|
135
|
+
}, [managerString, setManagerString]);
|
|
136
|
+
const handleSwitchSession = useCallback(async sessionId => {
|
|
137
|
+
const updatedManager_1 = SessionManager.hydrate(managerString);
|
|
138
|
+
try {
|
|
139
|
+
updatedManager_1.switchSession(sessionId);
|
|
140
|
+
} catch (_error) {
|
|
141
|
+
Alert.alert('Error', 'Session is not authenticated');
|
|
142
|
+
}
|
|
143
|
+
await setManagerString(updatedManager_1.toString());
|
|
144
|
+
}, [managerString, setManagerString]);
|
|
145
|
+
const handleLogout = useCallback(async () => {
|
|
146
|
+
handleClearQueryClient();
|
|
147
|
+
const manager = SessionManager.hydrate(managerString);
|
|
148
|
+
|
|
149
|
+
// Clear the current session ID
|
|
150
|
+
if (manager.currentSessionId) {
|
|
151
|
+
manager.removeSession(manager.currentSessionId);
|
|
152
|
+
await setManagerString(manager.toString());
|
|
153
|
+
}
|
|
154
|
+
return onLogout();
|
|
155
|
+
}, [managerString, setManagerString, handleClearQueryClient, onLogout]);
|
|
156
|
+
const handleTokenUpdate = useCallback(async t_0 => {
|
|
157
|
+
const updatedManager_2 = SessionManager.hydrate(managerString);
|
|
158
|
+
updatedManager_2.updateCurrentToken(t_0);
|
|
159
|
+
await setManagerString(updatedManager_2.toString());
|
|
160
|
+
}, [managerString, setManagerString]);
|
|
161
|
+
const handleRefreshFailed = useCallback(t_1 => {
|
|
162
|
+
if (t_1.status !== 401) return;
|
|
163
|
+
// If we didn't fail because of an unauthorized response ( 401 ),
|
|
164
|
+
// it could be because we were unable to store the token.
|
|
165
|
+
// Do not log out.
|
|
166
|
+
|
|
167
|
+
const {
|
|
168
|
+
errors = []
|
|
169
|
+
} = t_1;
|
|
170
|
+
// The code for a forced logout is "capuchin"
|
|
171
|
+
const isForcedLogout = errors.some(e => /capuchin/i.test(e.detail || ''));
|
|
172
|
+
if (isForcedLogout) {
|
|
173
|
+
handleLogout();
|
|
174
|
+
}
|
|
175
|
+
}, [handleLogout]);
|
|
176
|
+
const refreshInFlight = useRef(undefined);
|
|
177
|
+
const handleUnauthorizedResponse = useCallback(response => {
|
|
178
|
+
const {
|
|
179
|
+
errors: errors_0 = []
|
|
180
|
+
} = response;
|
|
181
|
+
const isUnauthorized = errors_0.some(e_0 => /TRASH_PANDA/i.test(e_0.detail || ''));
|
|
182
|
+
if (isUnauthorized) return Promise.resolve(undefined);
|
|
183
|
+
refreshInFlight.current ??= refreshTokenAsync().catch(() => undefined).finally(() => {
|
|
184
|
+
refreshInFlight.current = undefined;
|
|
406
185
|
});
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
186
|
+
return refreshInFlight.current;
|
|
187
|
+
}, [refreshTokenAsync]);
|
|
188
|
+
const sessionContextValue = {
|
|
189
|
+
env: currentSession.env,
|
|
190
|
+
token: currentSession.token,
|
|
191
|
+
session: currentSession,
|
|
192
|
+
sessions,
|
|
193
|
+
logout: handleLogout,
|
|
194
|
+
setToken: handleTokenUpdate,
|
|
195
|
+
handleUnauthorizedResponse,
|
|
196
|
+
setEnv: handleSetEnv,
|
|
197
|
+
switchSession: handleSwitchSession,
|
|
198
|
+
createSession: handleCreateSession
|
|
199
|
+
};
|
|
200
|
+
const alertTitle = alertConfig.title || 'Oops';
|
|
201
|
+
const alertMessage = alertConfig.message || 'Something went wrong with your login!';
|
|
202
|
+
const retryText = alertConfig.retryText || 'Keep trying';
|
|
203
|
+
const logoutText = alertConfig.logoutText || 'Logout';
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (isRefreshError && !alertShown && token?.refresh_token) {
|
|
206
|
+
setAlertShown(true);
|
|
207
|
+
Alert.alert(alertTitle, alertMessage, [{
|
|
208
|
+
text: retryText,
|
|
209
|
+
onPress: () => {
|
|
210
|
+
refreshToken();
|
|
211
|
+
setAlertShown(false);
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
text: logoutText,
|
|
215
|
+
onPress: () => handleLogout()
|
|
216
|
+
}]);
|
|
217
|
+
}
|
|
218
|
+
}, [isRefreshError, handleLogout, alertShown, refreshToken, token?.refresh_token, alertTitle, alertMessage, retryText, logoutText]);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
const manager_0 = SessionManager.hydrate(managerString);
|
|
221
|
+
if (manager_0.currentSessionId === UNAUTHENTICATED_SESSION_ID) return;
|
|
222
|
+
decorateSession(manager_0.currentSession).then(async decoratedSession => {
|
|
223
|
+
manager_0.upsertSession(decoratedSession);
|
|
224
|
+
await setManagerString(manager_0.toString());
|
|
225
|
+
});
|
|
226
|
+
}, [managerString, setManagerString]);
|
|
227
|
+
return /*#__PURE__*/_jsx(SessionContext.Provider, {
|
|
228
|
+
value: sessionContextValue,
|
|
229
|
+
children: children
|
|
230
|
+
});
|
|
426
231
|
}
|
|
427
232
|
//# sourceMappingURL=session_context.js.map
|