@fluid-app/rep-sdk 0.1.3 → 0.1.5
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/dist/MessagingScreen-BBINFP67.js +4 -0
- package/dist/{MessagingScreen-4H7ZBO3V.js.map → MessagingScreen-BBINFP67.js.map} +1 -1
- package/dist/MessagingScreen-PLRU75YQ.cjs +17 -0
- package/dist/{MessagingScreen-UPFXQZV3.cjs.map → MessagingScreen-PLRU75YQ.cjs.map} +1 -1
- package/dist/{chunk-7JMNKWPN.js → chunk-O47ODLEF.js} +19 -392
- package/dist/chunk-O47ODLEF.js.map +1 -0
- package/dist/{chunk-V3IMQZIG.cjs → chunk-W37C774B.cjs} +45 -433
- package/dist/chunk-W37C774B.cjs.map +1 -0
- package/dist/index.cjs +326 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -461
- package/dist/index.d.ts +11 -461
- package/dist/index.js +138 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/MessagingScreen-4H7ZBO3V.js +0 -4
- package/dist/MessagingScreen-UPFXQZV3.cjs +0 -17
- package/dist/chunk-7JMNKWPN.js.map +0 -1
- package/dist/chunk-V3IMQZIG.cjs.map +0 -1
|
@@ -6,7 +6,7 @@ var app = require('@fluid-app/fluid-messaging-ui/app');
|
|
|
6
6
|
var fluidMessagingUi = require('@fluid-app/fluid-messaging-ui');
|
|
7
7
|
var fluidMessagingApiClient = require('@fluid-app/fluid-messaging-api-client');
|
|
8
8
|
var reactQuery = require('@tanstack/react-query');
|
|
9
|
-
var
|
|
9
|
+
var auth = require('@fluid-app/auth');
|
|
10
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
11
|
var theme_star = require('@fluid-app/rep-core/theme');
|
|
12
12
|
var registryContext = require('@fluid-app/rep-core/data-sources/registry-context');
|
|
@@ -35,393 +35,6 @@ function _interopNamespace(e) {
|
|
|
35
35
|
|
|
36
36
|
var theme_star__namespace = /*#__PURE__*/_interopNamespace(theme_star);
|
|
37
37
|
|
|
38
|
-
// src/auth/constants.ts
|
|
39
|
-
var AUTH_CONSTANTS = {
|
|
40
|
-
/**
|
|
41
|
-
* Grace period in milliseconds to account for clock skew
|
|
42
|
-
* when checking token expiration. Tokens are considered valid
|
|
43
|
-
* if they expire within this period.
|
|
44
|
-
*/
|
|
45
|
-
TOKEN_GRACE_PERIOD_MS: 30 * 1e3,
|
|
46
|
-
// 30 seconds
|
|
47
|
-
/**
|
|
48
|
-
* Default cookie max age in seconds (9 days).
|
|
49
|
-
* This matches the typical JWT token lifetime from the Fluid API.
|
|
50
|
-
*/
|
|
51
|
-
COOKIE_MAX_AGE: 9 * 24 * 60 * 60
|
|
52
|
-
// 9 days = 777600 seconds
|
|
53
|
-
};
|
|
54
|
-
var STORAGE_KEYS = {
|
|
55
|
-
/** localStorage key for user token */
|
|
56
|
-
USER_TOKEN: "fluidUserToken",
|
|
57
|
-
/** localStorage key for company token (legacy) */
|
|
58
|
-
COMPANY_TOKEN: "fluidCompanyToken",
|
|
59
|
-
/** Cookie name for auth token */
|
|
60
|
-
AUTH_COOKIE: "auth_token"
|
|
61
|
-
};
|
|
62
|
-
var URL_PARAMS = {
|
|
63
|
-
/** URL parameter name for user token */
|
|
64
|
-
USER_TOKEN: "fluidUserToken",
|
|
65
|
-
/** URL parameter name for company token (legacy) */
|
|
66
|
-
COMPANY_TOKEN: "fluidCompanyToken"
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/auth/browser-utils.ts
|
|
70
|
-
function isBrowser() {
|
|
71
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// src/auth/url-token.ts
|
|
75
|
-
function extractTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
76
|
-
if (!isBrowser()) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
81
|
-
return searchParams.get(tokenKey);
|
|
82
|
-
} catch {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function extractCompanyTokenFromUrl(tokenKey = URL_PARAMS.COMPANY_TOKEN) {
|
|
87
|
-
if (!isBrowser()) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
92
|
-
return searchParams.get(tokenKey);
|
|
93
|
-
} catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function cleanTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
98
|
-
if (!isBrowser()) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const url = new URL(window.location.href);
|
|
103
|
-
const hadToken = url.searchParams.has(tokenKey);
|
|
104
|
-
const hadCompanyToken = url.searchParams.has(URL_PARAMS.COMPANY_TOKEN);
|
|
105
|
-
url.searchParams.delete(tokenKey);
|
|
106
|
-
url.searchParams.delete(URL_PARAMS.COMPANY_TOKEN);
|
|
107
|
-
if (hadToken || hadCompanyToken) {
|
|
108
|
-
window.history.replaceState(
|
|
109
|
-
window.history.state,
|
|
110
|
-
document.title,
|
|
111
|
-
url.toString()
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.warn("[FluidAuth] Failed to clean token from URL:", error);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function hasTokenInUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
119
|
-
if (!isBrowser()) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
124
|
-
return searchParams.has(tokenKey);
|
|
125
|
-
} catch {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function extractAllTokensFromUrl(userTokenKey = URL_PARAMS.USER_TOKEN, companyTokenKey = URL_PARAMS.COMPANY_TOKEN) {
|
|
130
|
-
if (!isBrowser()) {
|
|
131
|
-
return { userToken: null, companyToken: null };
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
135
|
-
return {
|
|
136
|
-
userToken: searchParams.get(userTokenKey),
|
|
137
|
-
companyToken: searchParams.get(companyTokenKey)
|
|
138
|
-
};
|
|
139
|
-
} catch {
|
|
140
|
-
return { userToken: null, companyToken: null };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// src/auth/token-storage.ts
|
|
145
|
-
function parseCookies() {
|
|
146
|
-
if (!isBrowser()) {
|
|
147
|
-
return {};
|
|
148
|
-
}
|
|
149
|
-
const cookies = {};
|
|
150
|
-
const cookieString = document.cookie;
|
|
151
|
-
if (!cookieString) {
|
|
152
|
-
return cookies;
|
|
153
|
-
}
|
|
154
|
-
cookieString.split(";").forEach((cookie) => {
|
|
155
|
-
const [name, ...valueParts] = cookie.trim().split("=");
|
|
156
|
-
if (name) {
|
|
157
|
-
cookies[name] = decodeURIComponent(valueParts.join("="));
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return cookies;
|
|
161
|
-
}
|
|
162
|
-
function setCookie(name, value, options = {}) {
|
|
163
|
-
if (!isBrowser()) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const {
|
|
167
|
-
maxAge = AUTH_CONSTANTS.COOKIE_MAX_AGE,
|
|
168
|
-
path = "/",
|
|
169
|
-
sameSite = "lax",
|
|
170
|
-
secure = window.location.protocol === "https:"
|
|
171
|
-
} = options;
|
|
172
|
-
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
|
173
|
-
cookieString += `; path=${path}`;
|
|
174
|
-
cookieString += `; max-age=${maxAge}`;
|
|
175
|
-
cookieString += `; samesite=${sameSite}`;
|
|
176
|
-
if (secure) {
|
|
177
|
-
cookieString += "; secure";
|
|
178
|
-
}
|
|
179
|
-
document.cookie = cookieString;
|
|
180
|
-
}
|
|
181
|
-
function deleteCookie(name, path = "/") {
|
|
182
|
-
if (!isBrowser()) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
document.cookie = `${name}=; path=${path}; max-age=0`;
|
|
186
|
-
}
|
|
187
|
-
function getStoredToken(config) {
|
|
188
|
-
if (!isBrowser()) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
192
|
-
const localStorageKey = STORAGE_KEYS.USER_TOKEN;
|
|
193
|
-
const cookies = parseCookies();
|
|
194
|
-
const cookieToken = cookies[cookieKey];
|
|
195
|
-
if (cookieToken) {
|
|
196
|
-
return cookieToken;
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
return localStorage.getItem(localStorageKey);
|
|
200
|
-
} catch {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
function storeToken(token, config) {
|
|
205
|
-
if (!isBrowser()) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
209
|
-
const maxAge = config?.cookieMaxAge ?? AUTH_CONSTANTS.COOKIE_MAX_AGE;
|
|
210
|
-
try {
|
|
211
|
-
const inIframe = window.self !== window.top;
|
|
212
|
-
const sameSite = inIframe ? "none" : "lax";
|
|
213
|
-
setCookie(cookieKey, token, {
|
|
214
|
-
maxAge,
|
|
215
|
-
path: "/",
|
|
216
|
-
sameSite,
|
|
217
|
-
// SameSite=None requires Secure per RFC 6265bis; browsers silently
|
|
218
|
-
// reject the cookie otherwise (e.g. HTTP localhost in an iframe).
|
|
219
|
-
secure: sameSite === "none" || window.location.protocol === "https:"
|
|
220
|
-
});
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.warn("[FluidAuth] Failed to store token in cookie:", error);
|
|
223
|
-
}
|
|
224
|
-
try {
|
|
225
|
-
localStorage.setItem(STORAGE_KEYS.USER_TOKEN, token);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
console.warn("[FluidAuth] Failed to store token in localStorage:", error);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function clearTokens(config) {
|
|
231
|
-
if (!isBrowser()) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
235
|
-
try {
|
|
236
|
-
deleteCookie(cookieKey);
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
localStorage.removeItem(STORAGE_KEYS.USER_TOKEN);
|
|
241
|
-
localStorage.removeItem(STORAGE_KEYS.COMPANY_TOKEN);
|
|
242
|
-
} catch {
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function hasStoredToken(config) {
|
|
246
|
-
return getStoredToken(config) !== null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// src/auth/types.ts
|
|
250
|
-
var USER_TYPES = {
|
|
251
|
-
admin: "admin",
|
|
252
|
-
rep: "rep",
|
|
253
|
-
root_admin: "root_admin",
|
|
254
|
-
customer: "customer"
|
|
255
|
-
};
|
|
256
|
-
function isUserType(value) {
|
|
257
|
-
return Object.values(USER_TYPES).includes(value);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// src/auth/token-utils.ts
|
|
261
|
-
function extractPayloadFromJose(decoded) {
|
|
262
|
-
const rawUserType = decoded.user_type;
|
|
263
|
-
const rawOgUserType = decoded.og_user_type;
|
|
264
|
-
return {
|
|
265
|
-
id: typeof decoded.id === "number" ? decoded.id : void 0,
|
|
266
|
-
email: typeof decoded.email === "string" ? decoded.email : void 0,
|
|
267
|
-
full_name: typeof decoded.full_name === "string" ? decoded.full_name : void 0,
|
|
268
|
-
user_type: typeof rawUserType === "string" && isUserType(rawUserType) ? rawUserType : "rep",
|
|
269
|
-
og_user_type: typeof rawOgUserType === "string" && isUserType(rawOgUserType) ? rawOgUserType : void 0,
|
|
270
|
-
company_id: typeof decoded.company_id === "number" ? decoded.company_id : void 0,
|
|
271
|
-
exp: decoded.exp,
|
|
272
|
-
auth_type: typeof decoded.auth_type === "string" ? decoded.auth_type : void 0
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function decodeToken(token) {
|
|
276
|
-
try {
|
|
277
|
-
const decoded = jose.decodeJwt(token);
|
|
278
|
-
return extractPayloadFromJose(decoded);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
console.error("[FluidAuth] Failed to decode JWT token:", error);
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
function isTokenExpired(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
|
|
285
|
-
try {
|
|
286
|
-
const decoded = jose.decodeJwt(token);
|
|
287
|
-
if (!decoded.exp) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
const expirationTime = decoded.exp * 1e3;
|
|
291
|
-
const currentTime = Date.now();
|
|
292
|
-
return currentTime > expirationTime + gracePeriodMs;
|
|
293
|
-
} catch {
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function validateToken(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
|
|
298
|
-
if (!token || token.trim() === "") {
|
|
299
|
-
return {
|
|
300
|
-
isValid: false,
|
|
301
|
-
error: "Token is empty or not provided"
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
const payload = decodeToken(token);
|
|
305
|
-
if (!payload) {
|
|
306
|
-
return {
|
|
307
|
-
isValid: false,
|
|
308
|
-
error: "Token has invalid format"
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (isTokenExpired(token, gracePeriodMs)) {
|
|
312
|
-
return {
|
|
313
|
-
isValid: false,
|
|
314
|
-
payload,
|
|
315
|
-
error: "Token has expired"
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
isValid: true,
|
|
320
|
-
payload
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
function isValidToken(result) {
|
|
324
|
-
return result.isValid === true;
|
|
325
|
-
}
|
|
326
|
-
function getTokenExpiration(token) {
|
|
327
|
-
try {
|
|
328
|
-
const decoded = jose.decodeJwt(token);
|
|
329
|
-
if (!decoded.exp) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
return new Date(decoded.exp * 1e3);
|
|
333
|
-
} catch {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function getTokenTimeRemaining(token) {
|
|
338
|
-
try {
|
|
339
|
-
const decoded = jose.decodeJwt(token);
|
|
340
|
-
if (!decoded.exp) {
|
|
341
|
-
return Infinity;
|
|
342
|
-
}
|
|
343
|
-
const expirationTime = decoded.exp * 1e3;
|
|
344
|
-
const remaining = expirationTime - Date.now();
|
|
345
|
-
return Math.max(0, remaining);
|
|
346
|
-
} catch {
|
|
347
|
-
return 0;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
async function verifyToken(token, jwksUrl) {
|
|
351
|
-
try {
|
|
352
|
-
const JWKS = jose.createRemoteJWKSet(new URL(jwksUrl));
|
|
353
|
-
const { payload } = await jose.jwtVerify(token, JWKS);
|
|
354
|
-
const decoded = payload;
|
|
355
|
-
return extractPayloadFromJose(decoded);
|
|
356
|
-
} catch (error) {
|
|
357
|
-
console.error("[FluidAuth] JWT signature verification failed:", error);
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// src/auth/dev-utils.ts
|
|
363
|
-
function isDevBypassActive(devBypass) {
|
|
364
|
-
if (!devBypass) return false;
|
|
365
|
-
try {
|
|
366
|
-
return undefined.DEV === true;
|
|
367
|
-
} catch {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function createDevUser() {
|
|
372
|
-
return {
|
|
373
|
-
id: 99999,
|
|
374
|
-
// Dev placeholder — avoids falsy 0
|
|
375
|
-
email: "dev@localhost",
|
|
376
|
-
full_name: "Dev User",
|
|
377
|
-
user_type: USER_TYPES.rep,
|
|
378
|
-
og_user_type: void 0,
|
|
379
|
-
company_id: 99999,
|
|
380
|
-
// Dev placeholder — avoids falsy 0
|
|
381
|
-
exp: void 0,
|
|
382
|
-
// Never expires
|
|
383
|
-
auth_type: "dev_bypass"
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// src/auth/auth-redirect.ts
|
|
388
|
-
var DEFAULT_AUTH_URL = "https://auth.fluid.app";
|
|
389
|
-
var AUTH_REDIRECT_TOKEN_KEY = "jwt";
|
|
390
|
-
var REDIRECT_TIMESTAMP_KEY = "__fluid_auth_redirect_ts";
|
|
391
|
-
var REDIRECT_COOLDOWN_S = 10;
|
|
392
|
-
function isRedirectLoop() {
|
|
393
|
-
try {
|
|
394
|
-
const ts = sessionStorage.getItem(REDIRECT_TIMESTAMP_KEY);
|
|
395
|
-
if (!ts) return false;
|
|
396
|
-
const elapsed = (Date.now() - Number(ts)) / 1e3;
|
|
397
|
-
return elapsed < REDIRECT_COOLDOWN_S;
|
|
398
|
-
} catch {
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
function markRedirect() {
|
|
403
|
-
try {
|
|
404
|
-
sessionStorage.setItem(REDIRECT_TIMESTAMP_KEY, String(Date.now()));
|
|
405
|
-
} catch {
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function createDefaultAuthRedirect(authUrl) {
|
|
409
|
-
return () => {
|
|
410
|
-
if (isRedirectLoop()) {
|
|
411
|
-
console.warn(
|
|
412
|
-
"[FluidAuth] Auth redirect suppressed \u2014 possible redirect loop. Check that your auth server returns a token accepted by the API."
|
|
413
|
-
);
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
markRedirect();
|
|
417
|
-
const base = authUrl ?? DEFAULT_AUTH_URL;
|
|
418
|
-
const currentUrl = encodeURIComponent(window.location.href);
|
|
419
|
-
window.location.href = `${base}/?redirect_url=${currentUrl}`;
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
function resolveAuthFailureHandler(onAuthFailure, authUrl) {
|
|
423
|
-
return onAuthFailure ?? createDefaultAuthRedirect(authUrl);
|
|
424
|
-
}
|
|
425
38
|
var FluidAuthContext = react.createContext(null);
|
|
426
39
|
function FluidAuthProvider({
|
|
427
40
|
children,
|
|
@@ -437,19 +50,19 @@ function FluidAuthProvider({
|
|
|
437
50
|
const initializeAuth = async () => {
|
|
438
51
|
const handleAuthFailure = () => {
|
|
439
52
|
const current = configRef.current;
|
|
440
|
-
const handler = resolveAuthFailureHandler(
|
|
53
|
+
const handler = auth.resolveAuthFailureHandler(
|
|
441
54
|
current?.onAuthFailure,
|
|
442
55
|
current?.authUrl
|
|
443
56
|
);
|
|
444
57
|
handler();
|
|
445
58
|
};
|
|
446
59
|
try {
|
|
447
|
-
if (isDevBypassActive(config?.devBypass)) {
|
|
60
|
+
if (auth.isDevBypassActive(config?.devBypass)) {
|
|
448
61
|
const envToken = undefined.VITE_DEV_TOKEN;
|
|
449
62
|
if (envToken) {
|
|
450
|
-
const validation = validateToken(envToken, config?.gracePeriodMs);
|
|
63
|
+
const validation = auth.validateToken(envToken, config?.gracePeriodMs);
|
|
451
64
|
if (validation.isValid && validation.payload) {
|
|
452
|
-
storeToken(envToken, config);
|
|
65
|
+
auth.storeToken(envToken, config);
|
|
453
66
|
setToken(envToken);
|
|
454
67
|
setUser(validation.payload);
|
|
455
68
|
setError(null);
|
|
@@ -462,36 +75,36 @@ function FluidAuthProvider({
|
|
|
462
75
|
console.warn(
|
|
463
76
|
"[FluidAuth] Dev bypass active - using mock user. API calls will fail without a real token."
|
|
464
77
|
);
|
|
465
|
-
const devUser = createDevUser();
|
|
78
|
+
const devUser = auth.createDevUser();
|
|
466
79
|
setToken(null);
|
|
467
80
|
setUser(devUser);
|
|
468
81
|
setError(null);
|
|
469
82
|
return;
|
|
470
83
|
}
|
|
471
84
|
const tokenKey = config?.tokenKey ?? "fluidUserToken";
|
|
472
|
-
let candidateToken = extractTokenFromUrl(tokenKey);
|
|
473
|
-
if (!candidateToken && tokenKey !== AUTH_REDIRECT_TOKEN_KEY) {
|
|
474
|
-
candidateToken = extractTokenFromUrl(AUTH_REDIRECT_TOKEN_KEY);
|
|
85
|
+
let candidateToken = auth.extractTokenFromUrl(tokenKey);
|
|
86
|
+
if (!candidateToken && tokenKey !== auth.AUTH_REDIRECT_TOKEN_KEY) {
|
|
87
|
+
candidateToken = auth.extractTokenFromUrl(auth.AUTH_REDIRECT_TOKEN_KEY);
|
|
475
88
|
}
|
|
476
|
-
cleanTokenFromUrl(tokenKey);
|
|
477
|
-
cleanTokenFromUrl(AUTH_REDIRECT_TOKEN_KEY);
|
|
89
|
+
auth.cleanTokenFromUrl(tokenKey);
|
|
90
|
+
auth.cleanTokenFromUrl(auth.AUTH_REDIRECT_TOKEN_KEY);
|
|
478
91
|
if (!candidateToken) {
|
|
479
|
-
candidateToken = getStoredToken(config);
|
|
92
|
+
candidateToken = auth.getStoredToken(config);
|
|
480
93
|
}
|
|
481
94
|
if (candidateToken) {
|
|
482
95
|
let payload = null;
|
|
483
96
|
if (config?.jwksUrl) {
|
|
484
|
-
payload = await verifyToken(candidateToken, config.jwksUrl);
|
|
97
|
+
payload = await auth.verifyToken(candidateToken, config.jwksUrl);
|
|
485
98
|
if (!payload) {
|
|
486
|
-
clearTokens(config);
|
|
99
|
+
auth.clearTokens(config);
|
|
487
100
|
setToken(null);
|
|
488
101
|
setUser(null);
|
|
489
102
|
setError(new Error("JWT signature verification failed"));
|
|
490
103
|
handleAuthFailure();
|
|
491
104
|
return;
|
|
492
105
|
}
|
|
493
|
-
if (isTokenExpired(candidateToken, config?.gracePeriodMs)) {
|
|
494
|
-
clearTokens(config);
|
|
106
|
+
if (auth.isTokenExpired(candidateToken, config?.gracePeriodMs)) {
|
|
107
|
+
auth.clearTokens(config);
|
|
495
108
|
setToken(null);
|
|
496
109
|
setUser(null);
|
|
497
110
|
setError(new Error("Token has expired"));
|
|
@@ -499,14 +112,14 @@ function FluidAuthProvider({
|
|
|
499
112
|
return;
|
|
500
113
|
}
|
|
501
114
|
} else {
|
|
502
|
-
const validation = validateToken(
|
|
115
|
+
const validation = auth.validateToken(
|
|
503
116
|
candidateToken,
|
|
504
117
|
config?.gracePeriodMs
|
|
505
118
|
);
|
|
506
119
|
if (validation.isValid && validation.payload) {
|
|
507
120
|
payload = validation.payload;
|
|
508
121
|
} else {
|
|
509
|
-
clearTokens(config);
|
|
122
|
+
auth.clearTokens(config);
|
|
510
123
|
setToken(null);
|
|
511
124
|
setUser(null);
|
|
512
125
|
setError(new Error(validation.error ?? "Invalid token"));
|
|
@@ -514,7 +127,7 @@ function FluidAuthProvider({
|
|
|
514
127
|
return;
|
|
515
128
|
}
|
|
516
129
|
}
|
|
517
|
-
storeToken(candidateToken, config);
|
|
130
|
+
auth.storeToken(candidateToken, config);
|
|
518
131
|
setToken(candidateToken);
|
|
519
132
|
setUser(payload);
|
|
520
133
|
setError(null);
|
|
@@ -537,7 +150,7 @@ function FluidAuthProvider({
|
|
|
537
150
|
void initializeAuth();
|
|
538
151
|
}, []);
|
|
539
152
|
const clearAuth = react.useCallback(() => {
|
|
540
|
-
clearTokens(configRef.current);
|
|
153
|
+
auth.clearTokens(configRef.current);
|
|
541
154
|
setToken(null);
|
|
542
155
|
setUser(null);
|
|
543
156
|
setError(null);
|
|
@@ -1046,6 +659,10 @@ function transformManifestToRepAppData(response) {
|
|
|
1046
659
|
toNavigationItem
|
|
1047
660
|
);
|
|
1048
661
|
const nav = rawProfile?.navigation;
|
|
662
|
+
const mobileNav = rawProfile?.mobile_navigation;
|
|
663
|
+
const mobileNavigationItems = (mobileNav?.navigation_items ?? []).map(
|
|
664
|
+
toNavigationItem
|
|
665
|
+
);
|
|
1049
666
|
const activeThemeId = theme_star.getActiveThemeId(rawThemes);
|
|
1050
667
|
return {
|
|
1051
668
|
definition_id: manifest.definition_id,
|
|
@@ -1063,7 +680,16 @@ function transformManifestToRepAppData(response) {
|
|
|
1063
680
|
name: nav?.name ?? "Main Navigation",
|
|
1064
681
|
navigation_items: navigationItems,
|
|
1065
682
|
screens
|
|
1066
|
-
}
|
|
683
|
+
},
|
|
684
|
+
...mobileNav ? {
|
|
685
|
+
mobile_navigation: {
|
|
686
|
+
definition_id: mobileNav.definition_id ?? manifest.definition_id,
|
|
687
|
+
id: mobileNav.id ?? 0,
|
|
688
|
+
name: mobileNav.name ?? "Mobile Navigation",
|
|
689
|
+
navigation_items: mobileNavigationItems,
|
|
690
|
+
screens
|
|
691
|
+
}
|
|
692
|
+
} : {}
|
|
1067
693
|
}
|
|
1068
694
|
};
|
|
1069
695
|
}
|
|
@@ -1111,7 +737,7 @@ function extractErrorMessage(data, fallback) {
|
|
|
1111
737
|
}
|
|
1112
738
|
function createFluidClient(config) {
|
|
1113
739
|
const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {} } = config;
|
|
1114
|
-
const effectiveOnAuthError = onAuthError ?? createDefaultAuthRedirect();
|
|
740
|
+
const effectiveOnAuthError = onAuthError ?? auth.createDefaultAuthRedirect();
|
|
1115
741
|
const fetchClient = createFetchClient({
|
|
1116
742
|
baseUrl,
|
|
1117
743
|
...getAuthToken ? { getAuthToken } : {},
|
|
@@ -1883,6 +1509,14 @@ var messagingScreenPropertySchema = {
|
|
|
1883
1509
|
fields: []
|
|
1884
1510
|
};
|
|
1885
1511
|
|
|
1512
|
+
Object.defineProperty(exports, "DEFAULT_AUTH_URL", {
|
|
1513
|
+
enumerable: true,
|
|
1514
|
+
get: function () { return auth.DEFAULT_AUTH_URL; }
|
|
1515
|
+
});
|
|
1516
|
+
Object.defineProperty(exports, "createDefaultAuthRedirect", {
|
|
1517
|
+
enumerable: true,
|
|
1518
|
+
get: function () { return auth.createDefaultAuthRedirect; }
|
|
1519
|
+
});
|
|
1886
1520
|
Object.defineProperty(exports, "buildThemeDefinition", {
|
|
1887
1521
|
enumerable: true,
|
|
1888
1522
|
get: function () { return theme_star.buildThemeDefinition; }
|
|
@@ -1895,38 +1529,17 @@ Object.defineProperty(exports, "transformThemes", {
|
|
|
1895
1529
|
enumerable: true,
|
|
1896
1530
|
get: function () { return theme_star.transformThemes; }
|
|
1897
1531
|
});
|
|
1898
|
-
exports.AUTH_CONSTANTS = AUTH_CONSTANTS;
|
|
1899
1532
|
exports.ApiError = ApiError2;
|
|
1900
|
-
exports.DEFAULT_AUTH_URL = DEFAULT_AUTH_URL;
|
|
1901
1533
|
exports.DEFAULT_SDK_WIDGET_REGISTRY = DEFAULT_SDK_WIDGET_REGISTRY;
|
|
1902
1534
|
exports.FluidAuthProvider = FluidAuthProvider;
|
|
1903
1535
|
exports.FluidProvider = FluidProvider;
|
|
1904
1536
|
exports.FluidThemeProvider = FluidThemeProvider;
|
|
1905
1537
|
exports.MessagingScreen = MessagingScreen;
|
|
1906
|
-
exports.STORAGE_KEYS = STORAGE_KEYS;
|
|
1907
|
-
exports.URL_PARAMS = URL_PARAMS;
|
|
1908
|
-
exports.USER_TYPES = USER_TYPES;
|
|
1909
|
-
exports.cleanTokenFromUrl = cleanTokenFromUrl;
|
|
1910
|
-
exports.clearTokens = clearTokens;
|
|
1911
|
-
exports.createDefaultAuthRedirect = createDefaultAuthRedirect;
|
|
1912
1538
|
exports.createFluidClient = createFluidClient;
|
|
1913
1539
|
exports.createFluidFileUploader = createFluidFileUploader;
|
|
1914
|
-
exports.decodeToken = decodeToken;
|
|
1915
|
-
exports.extractAllTokensFromUrl = extractAllTokensFromUrl;
|
|
1916
|
-
exports.extractCompanyTokenFromUrl = extractCompanyTokenFromUrl;
|
|
1917
|
-
exports.extractTokenFromUrl = extractTokenFromUrl;
|
|
1918
|
-
exports.getStoredToken = getStoredToken;
|
|
1919
|
-
exports.getTokenExpiration = getTokenExpiration;
|
|
1920
|
-
exports.getTokenTimeRemaining = getTokenTimeRemaining;
|
|
1921
|
-
exports.hasStoredToken = hasStoredToken;
|
|
1922
|
-
exports.hasTokenInUrl = hasTokenInUrl;
|
|
1923
1540
|
exports.isApiError = isApiError2;
|
|
1924
|
-
exports.isTokenExpired = isTokenExpired;
|
|
1925
|
-
exports.isUserType = isUserType;
|
|
1926
|
-
exports.isValidToken = isValidToken;
|
|
1927
1541
|
exports.messagingScreenPropertySchema = messagingScreenPropertySchema;
|
|
1928
1542
|
exports.normalizeComponentTree = normalizeComponentTree;
|
|
1929
|
-
exports.storeToken = storeToken;
|
|
1930
1543
|
exports.themes_exports = themes_exports;
|
|
1931
1544
|
exports.toNavigationItem = toNavigationItem;
|
|
1932
1545
|
exports.toScreenDefinition = toScreenDefinition;
|
|
@@ -1937,6 +1550,5 @@ exports.useFluidContext = useFluidContext;
|
|
|
1937
1550
|
exports.useMessagingAuth = useMessagingAuth;
|
|
1938
1551
|
exports.useMessagingConfig = useMessagingConfig;
|
|
1939
1552
|
exports.useThemeContext = useThemeContext;
|
|
1940
|
-
|
|
1941
|
-
//# sourceMappingURL=chunk-
|
|
1942
|
-
//# sourceMappingURL=chunk-V3IMQZIG.cjs.map
|
|
1553
|
+
//# sourceMappingURL=chunk-W37C774B.cjs.map
|
|
1554
|
+
//# sourceMappingURL=chunk-W37C774B.cjs.map
|