@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.
@@ -0,0 +1,4 @@
1
+ export { MessagingScreen, messagingScreenPropertySchema } from './chunk-O47ODLEF.js';
2
+ import './chunk-424PT5DM.js';
3
+ //# sourceMappingURL=MessagingScreen-BBINFP67.js.map
4
+ //# sourceMappingURL=MessagingScreen-BBINFP67.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"MessagingScreen-4H7ZBO3V.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"MessagingScreen-BBINFP67.js"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var chunkW37C774B_cjs = require('./chunk-W37C774B.cjs');
4
+ require('./chunk-HDQ2JUQT.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "MessagingScreen", {
9
+ enumerable: true,
10
+ get: function () { return chunkW37C774B_cjs.MessagingScreen; }
11
+ });
12
+ Object.defineProperty(exports, "messagingScreenPropertySchema", {
13
+ enumerable: true,
14
+ get: function () { return chunkW37C774B_cjs.messagingScreenPropertySchema; }
15
+ });
16
+ //# sourceMappingURL=MessagingScreen-PLRU75YQ.cjs.map
17
+ //# sourceMappingURL=MessagingScreen-PLRU75YQ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"MessagingScreen-UPFXQZV3.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"MessagingScreen-PLRU75YQ.cjs"}
@@ -4,7 +4,8 @@ import { MessagingApp } from '@fluid-app/fluid-messaging-ui/app';
4
4
  import { extractEmoji, formatMessageChannelName } from '@fluid-app/fluid-messaging-ui';
5
5
  import { listConnectedRecipients, searchConversations } from '@fluid-app/fluid-messaging-api-client';
6
6
  import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
7
- import { decodeJwt, createRemoteJWKSet, jwtVerify } from 'jose';
7
+ import { clearTokens, createDefaultAuthRedirect, isDevBypassActive, validateToken, storeToken, createDevUser, extractTokenFromUrl, AUTH_REDIRECT_TOKEN_KEY, cleanTokenFromUrl, getStoredToken, verifyToken, isTokenExpired, resolveAuthFailureHandler } from '@fluid-app/auth';
8
+ export { DEFAULT_AUTH_URL, createDefaultAuthRedirect } from '@fluid-app/auth';
8
9
  import { jsx, jsxs } from 'react/jsx-runtime';
9
10
  import * as theme_star from '@fluid-app/rep-core/theme';
10
11
  import { getActiveThemeId, transformThemes } from '@fluid-app/rep-core/theme';
@@ -15,393 +16,6 @@ import { createWidgetRegistry } from '@fluid-app/rep-core/widget-utils';
15
16
  import { VideoWidget, ToDoWidget, TextWidget, TableWidget, SpacerWidget, RecentActivityWidget, QuickShareWidget, NestedWidget, MySiteWidget, ListWidget, LayoutWidget, ImageWidget, EmbedWidget, ContainerWidget, ChartWidget, CatchUpWidget, CarouselWidget, CalendarWidget, AlertWidget } from '@fluid-app/rep-widgets/widgets';
16
17
  import { getFileTypeFromMimetype } from '@fluid-app/fluid-messaging-core';
17
18
 
18
- // src/auth/constants.ts
19
- var AUTH_CONSTANTS = {
20
- /**
21
- * Grace period in milliseconds to account for clock skew
22
- * when checking token expiration. Tokens are considered valid
23
- * if they expire within this period.
24
- */
25
- TOKEN_GRACE_PERIOD_MS: 30 * 1e3,
26
- // 30 seconds
27
- /**
28
- * Default cookie max age in seconds (9 days).
29
- * This matches the typical JWT token lifetime from the Fluid API.
30
- */
31
- COOKIE_MAX_AGE: 9 * 24 * 60 * 60
32
- // 9 days = 777600 seconds
33
- };
34
- var STORAGE_KEYS = {
35
- /** localStorage key for user token */
36
- USER_TOKEN: "fluidUserToken",
37
- /** localStorage key for company token (legacy) */
38
- COMPANY_TOKEN: "fluidCompanyToken",
39
- /** Cookie name for auth token */
40
- AUTH_COOKIE: "auth_token"
41
- };
42
- var URL_PARAMS = {
43
- /** URL parameter name for user token */
44
- USER_TOKEN: "fluidUserToken",
45
- /** URL parameter name for company token (legacy) */
46
- COMPANY_TOKEN: "fluidCompanyToken"
47
- };
48
-
49
- // src/auth/browser-utils.ts
50
- function isBrowser() {
51
- return typeof window !== "undefined" && typeof document !== "undefined";
52
- }
53
-
54
- // src/auth/url-token.ts
55
- function extractTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
56
- if (!isBrowser()) {
57
- return null;
58
- }
59
- try {
60
- const searchParams = new URLSearchParams(window.location.search);
61
- return searchParams.get(tokenKey);
62
- } catch {
63
- return null;
64
- }
65
- }
66
- function extractCompanyTokenFromUrl(tokenKey = URL_PARAMS.COMPANY_TOKEN) {
67
- if (!isBrowser()) {
68
- return null;
69
- }
70
- try {
71
- const searchParams = new URLSearchParams(window.location.search);
72
- return searchParams.get(tokenKey);
73
- } catch {
74
- return null;
75
- }
76
- }
77
- function cleanTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
78
- if (!isBrowser()) {
79
- return;
80
- }
81
- try {
82
- const url = new URL(window.location.href);
83
- const hadToken = url.searchParams.has(tokenKey);
84
- const hadCompanyToken = url.searchParams.has(URL_PARAMS.COMPANY_TOKEN);
85
- url.searchParams.delete(tokenKey);
86
- url.searchParams.delete(URL_PARAMS.COMPANY_TOKEN);
87
- if (hadToken || hadCompanyToken) {
88
- window.history.replaceState(
89
- window.history.state,
90
- document.title,
91
- url.toString()
92
- );
93
- }
94
- } catch (error) {
95
- console.warn("[FluidAuth] Failed to clean token from URL:", error);
96
- }
97
- }
98
- function hasTokenInUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
99
- if (!isBrowser()) {
100
- return false;
101
- }
102
- try {
103
- const searchParams = new URLSearchParams(window.location.search);
104
- return searchParams.has(tokenKey);
105
- } catch {
106
- return false;
107
- }
108
- }
109
- function extractAllTokensFromUrl(userTokenKey = URL_PARAMS.USER_TOKEN, companyTokenKey = URL_PARAMS.COMPANY_TOKEN) {
110
- if (!isBrowser()) {
111
- return { userToken: null, companyToken: null };
112
- }
113
- try {
114
- const searchParams = new URLSearchParams(window.location.search);
115
- return {
116
- userToken: searchParams.get(userTokenKey),
117
- companyToken: searchParams.get(companyTokenKey)
118
- };
119
- } catch {
120
- return { userToken: null, companyToken: null };
121
- }
122
- }
123
-
124
- // src/auth/token-storage.ts
125
- function parseCookies() {
126
- if (!isBrowser()) {
127
- return {};
128
- }
129
- const cookies = {};
130
- const cookieString = document.cookie;
131
- if (!cookieString) {
132
- return cookies;
133
- }
134
- cookieString.split(";").forEach((cookie) => {
135
- const [name, ...valueParts] = cookie.trim().split("=");
136
- if (name) {
137
- cookies[name] = decodeURIComponent(valueParts.join("="));
138
- }
139
- });
140
- return cookies;
141
- }
142
- function setCookie(name, value, options = {}) {
143
- if (!isBrowser()) {
144
- return;
145
- }
146
- const {
147
- maxAge = AUTH_CONSTANTS.COOKIE_MAX_AGE,
148
- path = "/",
149
- sameSite = "lax",
150
- secure = window.location.protocol === "https:"
151
- } = options;
152
- let cookieString = `${name}=${encodeURIComponent(value)}`;
153
- cookieString += `; path=${path}`;
154
- cookieString += `; max-age=${maxAge}`;
155
- cookieString += `; samesite=${sameSite}`;
156
- if (secure) {
157
- cookieString += "; secure";
158
- }
159
- document.cookie = cookieString;
160
- }
161
- function deleteCookie(name, path = "/") {
162
- if (!isBrowser()) {
163
- return;
164
- }
165
- document.cookie = `${name}=; path=${path}; max-age=0`;
166
- }
167
- function getStoredToken(config) {
168
- if (!isBrowser()) {
169
- return null;
170
- }
171
- const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
172
- const localStorageKey = STORAGE_KEYS.USER_TOKEN;
173
- const cookies = parseCookies();
174
- const cookieToken = cookies[cookieKey];
175
- if (cookieToken) {
176
- return cookieToken;
177
- }
178
- try {
179
- return localStorage.getItem(localStorageKey);
180
- } catch {
181
- return null;
182
- }
183
- }
184
- function storeToken(token, config) {
185
- if (!isBrowser()) {
186
- return;
187
- }
188
- const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
189
- const maxAge = config?.cookieMaxAge ?? AUTH_CONSTANTS.COOKIE_MAX_AGE;
190
- try {
191
- const inIframe = window.self !== window.top;
192
- const sameSite = inIframe ? "none" : "lax";
193
- setCookie(cookieKey, token, {
194
- maxAge,
195
- path: "/",
196
- sameSite,
197
- // SameSite=None requires Secure per RFC 6265bis; browsers silently
198
- // reject the cookie otherwise (e.g. HTTP localhost in an iframe).
199
- secure: sameSite === "none" || window.location.protocol === "https:"
200
- });
201
- } catch (error) {
202
- console.warn("[FluidAuth] Failed to store token in cookie:", error);
203
- }
204
- try {
205
- localStorage.setItem(STORAGE_KEYS.USER_TOKEN, token);
206
- } catch (error) {
207
- console.warn("[FluidAuth] Failed to store token in localStorage:", error);
208
- }
209
- }
210
- function clearTokens(config) {
211
- if (!isBrowser()) {
212
- return;
213
- }
214
- const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
215
- try {
216
- deleteCookie(cookieKey);
217
- } catch {
218
- }
219
- try {
220
- localStorage.removeItem(STORAGE_KEYS.USER_TOKEN);
221
- localStorage.removeItem(STORAGE_KEYS.COMPANY_TOKEN);
222
- } catch {
223
- }
224
- }
225
- function hasStoredToken(config) {
226
- return getStoredToken(config) !== null;
227
- }
228
-
229
- // src/auth/types.ts
230
- var USER_TYPES = {
231
- admin: "admin",
232
- rep: "rep",
233
- root_admin: "root_admin",
234
- customer: "customer"
235
- };
236
- function isUserType(value) {
237
- return Object.values(USER_TYPES).includes(value);
238
- }
239
-
240
- // src/auth/token-utils.ts
241
- function extractPayloadFromJose(decoded) {
242
- const rawUserType = decoded.user_type;
243
- const rawOgUserType = decoded.og_user_type;
244
- return {
245
- id: typeof decoded.id === "number" ? decoded.id : void 0,
246
- email: typeof decoded.email === "string" ? decoded.email : void 0,
247
- full_name: typeof decoded.full_name === "string" ? decoded.full_name : void 0,
248
- user_type: typeof rawUserType === "string" && isUserType(rawUserType) ? rawUserType : "rep",
249
- og_user_type: typeof rawOgUserType === "string" && isUserType(rawOgUserType) ? rawOgUserType : void 0,
250
- company_id: typeof decoded.company_id === "number" ? decoded.company_id : void 0,
251
- exp: decoded.exp,
252
- auth_type: typeof decoded.auth_type === "string" ? decoded.auth_type : void 0
253
- };
254
- }
255
- function decodeToken(token) {
256
- try {
257
- const decoded = decodeJwt(token);
258
- return extractPayloadFromJose(decoded);
259
- } catch (error) {
260
- console.error("[FluidAuth] Failed to decode JWT token:", error);
261
- return null;
262
- }
263
- }
264
- function isTokenExpired(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
265
- try {
266
- const decoded = decodeJwt(token);
267
- if (!decoded.exp) {
268
- return false;
269
- }
270
- const expirationTime = decoded.exp * 1e3;
271
- const currentTime = Date.now();
272
- return currentTime > expirationTime + gracePeriodMs;
273
- } catch {
274
- return true;
275
- }
276
- }
277
- function validateToken(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
278
- if (!token || token.trim() === "") {
279
- return {
280
- isValid: false,
281
- error: "Token is empty or not provided"
282
- };
283
- }
284
- const payload = decodeToken(token);
285
- if (!payload) {
286
- return {
287
- isValid: false,
288
- error: "Token has invalid format"
289
- };
290
- }
291
- if (isTokenExpired(token, gracePeriodMs)) {
292
- return {
293
- isValid: false,
294
- payload,
295
- error: "Token has expired"
296
- };
297
- }
298
- return {
299
- isValid: true,
300
- payload
301
- };
302
- }
303
- function isValidToken(result) {
304
- return result.isValid === true;
305
- }
306
- function getTokenExpiration(token) {
307
- try {
308
- const decoded = decodeJwt(token);
309
- if (!decoded.exp) {
310
- return null;
311
- }
312
- return new Date(decoded.exp * 1e3);
313
- } catch {
314
- return null;
315
- }
316
- }
317
- function getTokenTimeRemaining(token) {
318
- try {
319
- const decoded = decodeJwt(token);
320
- if (!decoded.exp) {
321
- return Infinity;
322
- }
323
- const expirationTime = decoded.exp * 1e3;
324
- const remaining = expirationTime - Date.now();
325
- return Math.max(0, remaining);
326
- } catch {
327
- return 0;
328
- }
329
- }
330
- async function verifyToken(token, jwksUrl) {
331
- try {
332
- const JWKS = createRemoteJWKSet(new URL(jwksUrl));
333
- const { payload } = await jwtVerify(token, JWKS);
334
- const decoded = payload;
335
- return extractPayloadFromJose(decoded);
336
- } catch (error) {
337
- console.error("[FluidAuth] JWT signature verification failed:", error);
338
- return null;
339
- }
340
- }
341
-
342
- // src/auth/dev-utils.ts
343
- function isDevBypassActive(devBypass) {
344
- if (!devBypass) return false;
345
- try {
346
- return import.meta.env.DEV === true;
347
- } catch {
348
- return false;
349
- }
350
- }
351
- function createDevUser() {
352
- return {
353
- id: 99999,
354
- // Dev placeholder — avoids falsy 0
355
- email: "dev@localhost",
356
- full_name: "Dev User",
357
- user_type: USER_TYPES.rep,
358
- og_user_type: void 0,
359
- company_id: 99999,
360
- // Dev placeholder — avoids falsy 0
361
- exp: void 0,
362
- // Never expires
363
- auth_type: "dev_bypass"
364
- };
365
- }
366
-
367
- // src/auth/auth-redirect.ts
368
- var DEFAULT_AUTH_URL = "https://auth.fluid.app";
369
- var AUTH_REDIRECT_TOKEN_KEY = "jwt";
370
- var REDIRECT_TIMESTAMP_KEY = "__fluid_auth_redirect_ts";
371
- var REDIRECT_COOLDOWN_S = 10;
372
- function isRedirectLoop() {
373
- try {
374
- const ts = sessionStorage.getItem(REDIRECT_TIMESTAMP_KEY);
375
- if (!ts) return false;
376
- const elapsed = (Date.now() - Number(ts)) / 1e3;
377
- return elapsed < REDIRECT_COOLDOWN_S;
378
- } catch {
379
- return false;
380
- }
381
- }
382
- function markRedirect() {
383
- try {
384
- sessionStorage.setItem(REDIRECT_TIMESTAMP_KEY, String(Date.now()));
385
- } catch {
386
- }
387
- }
388
- function createDefaultAuthRedirect(authUrl) {
389
- return () => {
390
- if (isRedirectLoop()) {
391
- console.warn(
392
- "[FluidAuth] Auth redirect suppressed \u2014 possible redirect loop. Check that your auth server returns a token accepted by the API."
393
- );
394
- return;
395
- }
396
- markRedirect();
397
- const base = authUrl ?? DEFAULT_AUTH_URL;
398
- const currentUrl = encodeURIComponent(window.location.href);
399
- window.location.href = `${base}/?redirect_url=${currentUrl}`;
400
- };
401
- }
402
- function resolveAuthFailureHandler(onAuthFailure, authUrl) {
403
- return onAuthFailure ?? createDefaultAuthRedirect(authUrl);
404
- }
405
19
  var FluidAuthContext = createContext(null);
406
20
  function FluidAuthProvider({
407
21
  children,
@@ -1026,6 +640,10 @@ function transformManifestToRepAppData(response) {
1026
640
  toNavigationItem
1027
641
  );
1028
642
  const nav = rawProfile?.navigation;
643
+ const mobileNav = rawProfile?.mobile_navigation;
644
+ const mobileNavigationItems = (mobileNav?.navigation_items ?? []).map(
645
+ toNavigationItem
646
+ );
1029
647
  const activeThemeId = getActiveThemeId(rawThemes);
1030
648
  return {
1031
649
  definition_id: manifest.definition_id,
@@ -1043,7 +661,16 @@ function transformManifestToRepAppData(response) {
1043
661
  name: nav?.name ?? "Main Navigation",
1044
662
  navigation_items: navigationItems,
1045
663
  screens
1046
- }
664
+ },
665
+ ...mobileNav ? {
666
+ mobile_navigation: {
667
+ definition_id: mobileNav.definition_id ?? manifest.definition_id,
668
+ id: mobileNav.id ?? 0,
669
+ name: mobileNav.name ?? "Mobile Navigation",
670
+ navigation_items: mobileNavigationItems,
671
+ screens
672
+ }
673
+ } : {}
1047
674
  }
1048
675
  };
1049
676
  }
@@ -1863,6 +1490,6 @@ var messagingScreenPropertySchema = {
1863
1490
  fields: []
1864
1491
  };
1865
1492
 
1866
- export { AUTH_CONSTANTS, ApiError2 as ApiError, DEFAULT_AUTH_URL, DEFAULT_SDK_WIDGET_REGISTRY, FluidAuthProvider, FluidProvider, FluidThemeProvider, MessagingScreen, STORAGE_KEYS, URL_PARAMS, USER_TYPES, cleanTokenFromUrl, clearTokens, createDefaultAuthRedirect, createFluidClient, createFluidFileUploader, decodeToken, extractAllTokensFromUrl, extractCompanyTokenFromUrl, extractTokenFromUrl, getStoredToken, getTokenExpiration, getTokenTimeRemaining, hasStoredToken, hasTokenInUrl, isApiError2 as isApiError, isTokenExpired, isUserType, isValidToken, messagingScreenPropertySchema, normalizeComponentTree, storeToken, themes_exports, toNavigationItem, toScreenDefinition, transformManifestToRepAppData, useFluidApi, useFluidAuthContext, useFluidContext, useMessagingAuth, useMessagingConfig, useThemeContext, validateToken };
1867
- //# sourceMappingURL=chunk-7JMNKWPN.js.map
1868
- //# sourceMappingURL=chunk-7JMNKWPN.js.map
1493
+ export { ApiError2 as ApiError, DEFAULT_SDK_WIDGET_REGISTRY, FluidAuthProvider, FluidProvider, FluidThemeProvider, MessagingScreen, createFluidClient, createFluidFileUploader, isApiError2 as isApiError, messagingScreenPropertySchema, normalizeComponentTree, themes_exports, toNavigationItem, toScreenDefinition, transformManifestToRepAppData, useFluidApi, useFluidAuthContext, useFluidContext, useMessagingAuth, useMessagingConfig, useThemeContext };
1494
+ //# sourceMappingURL=chunk-O47ODLEF.js.map
1495
+ //# sourceMappingURL=chunk-O47ODLEF.js.map