@fluid-app/rep-sdk 0.1.2 → 0.1.3
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/ContactsScreen-33AJ5XUB.js +5 -0
- package/dist/{ContactsScreen-BYXF74BO.js.map → ContactsScreen-33AJ5XUB.js.map} +1 -1
- package/dist/ContactsScreen-ATASCZO2.cjs +18 -0
- package/dist/{ContactsScreen-XZOQJVFE.cjs.map → ContactsScreen-ATASCZO2.cjs.map} +1 -1
- package/dist/CustomersScreen-E4HXBKV7.js +5 -0
- package/dist/{CustomersScreen-VS6LGULO.js.map → CustomersScreen-E4HXBKV7.js.map} +1 -1
- package/dist/CustomersScreen-XMPMKSQA.cjs +18 -0
- package/dist/{CustomersScreen-53SXRDDK.cjs.map → CustomersScreen-XMPMKSQA.cjs.map} +1 -1
- package/dist/MessagingScreen-4H7ZBO3V.js +4 -0
- package/dist/{MessagingScreen-O42JEJMW.js.map → MessagingScreen-4H7ZBO3V.js.map} +1 -1
- package/dist/MessagingScreen-UPFXQZV3.cjs +17 -0
- package/dist/{MessagingScreen-UCVLYWZB.cjs.map → MessagingScreen-UPFXQZV3.cjs.map} +1 -1
- package/dist/OrdersScreen-IPPZLEYF.js +5 -0
- package/dist/{OrdersScreen-QQJFTTSS.js.map → OrdersScreen-IPPZLEYF.js.map} +1 -1
- package/dist/OrdersScreen-X7FYUROL.cjs +18 -0
- package/dist/{OrdersScreen-WNT2WDLI.cjs.map → OrdersScreen-X7FYUROL.cjs.map} +1 -1
- package/dist/ProductsScreen-4ZIUQNUU.cjs +18 -0
- package/dist/{ProductsScreen-CTIAKS3Z.cjs.map → ProductsScreen-4ZIUQNUU.cjs.map} +1 -1
- package/dist/ProductsScreen-YTSOZW7B.js +5 -0
- package/dist/{ProductsScreen-TRIT2FE3.js.map → ProductsScreen-YTSOZW7B.js.map} +1 -1
- package/dist/chunk-424PT5DM.js +21 -0
- package/dist/chunk-424PT5DM.js.map +1 -0
- package/dist/{chunk-QUVJ3R4T.cjs → chunk-5UBEM3AX.cjs} +4 -4
- package/dist/{chunk-QUVJ3R4T.cjs.map → chunk-5UBEM3AX.cjs.map} +1 -1
- package/dist/chunk-7JMNKWPN.js +1868 -0
- package/dist/chunk-7JMNKWPN.js.map +1 -0
- package/dist/chunk-B6S6BEPL.cjs +16 -0
- package/dist/chunk-B6S6BEPL.cjs.map +1 -0
- package/dist/{chunk-WH7WZXT6.js → chunk-CMF2FYTD.js} +3 -3
- package/dist/{chunk-WH7WZXT6.js.map → chunk-CMF2FYTD.js.map} +1 -1
- package/dist/{chunk-MEOOAMH2.cjs → chunk-EOXYOOWS.cjs} +4 -4
- package/dist/{chunk-MEOOAMH2.cjs.map → chunk-EOXYOOWS.cjs.map} +1 -1
- package/dist/{chunk-YII3IXF4.cjs → chunk-FG2CI6HA.cjs} +4 -4
- package/dist/{chunk-YII3IXF4.cjs.map → chunk-FG2CI6HA.cjs.map} +1 -1
- package/dist/chunk-HDQ2JUQT.cjs +24 -0
- package/dist/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/{chunk-MBUCXIUN.cjs → chunk-MHPK7YQ2.cjs} +4 -4
- package/dist/{chunk-MBUCXIUN.cjs.map → chunk-MHPK7YQ2.cjs.map} +1 -1
- package/dist/{chunk-2AWTZV3T.js → chunk-QZMWG7EM.js} +3 -3
- package/dist/{chunk-2AWTZV3T.js.map → chunk-QZMWG7EM.js.map} +1 -1
- package/dist/chunk-RS4OSTES.js +14 -0
- package/dist/chunk-RS4OSTES.js.map +1 -0
- package/dist/chunk-V3IMQZIG.cjs +1942 -0
- package/dist/chunk-V3IMQZIG.cjs.map +1 -0
- package/dist/{chunk-PZIHCYDD.js → chunk-WFPYEYC7.js} +3 -3
- package/dist/{chunk-PZIHCYDD.js.map → chunk-WFPYEYC7.js.map} +1 -1
- package/dist/{chunk-CXRJSGO6.js → chunk-WMBD65GH.js} +3 -3
- package/dist/{chunk-CXRJSGO6.js.map → chunk-WMBD65GH.js.map} +1 -1
- package/dist/index.cjs +1596 -1212
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2596 -0
- package/dist/index.d.ts +2596 -0
- package/dist/index.js +1256 -1011
- package/dist/index.js.map +1 -1
- package/package.json +27 -8
- package/dist/ContactsScreen-BYXF74BO.js +0 -4
- package/dist/ContactsScreen-XZOQJVFE.cjs +0 -17
- package/dist/CustomersScreen-53SXRDDK.cjs +0 -17
- package/dist/CustomersScreen-VS6LGULO.js +0 -4
- package/dist/MessagingScreen-O42JEJMW.js +0 -4
- package/dist/MessagingScreen-UCVLYWZB.cjs +0 -17
- package/dist/OrdersScreen-QQJFTTSS.js +0 -4
- package/dist/OrdersScreen-WNT2WDLI.cjs +0 -17
- package/dist/ProductsScreen-CTIAKS3Z.cjs +0 -17
- package/dist/ProductsScreen-TRIT2FE3.js +0 -4
- package/dist/chunk-DEQ3PBVX.cjs +0 -29
- package/dist/chunk-DEQ3PBVX.cjs.map +0 -1
- package/dist/chunk-JZRNKSKT.cjs +0 -19
- package/dist/chunk-JZRNKSKT.cjs.map +0 -1
- package/dist/chunk-LO2HDG6C.js +0 -26
- package/dist/chunk-LO2HDG6C.js.map +0 -1
- package/dist/chunk-PJWPO4BJ.js +0 -16
- package/dist/chunk-PJWPO4BJ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,945 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { themes_exports, useFluidApi, transformManifestToRepAppData, useThemeContext, useFluidAuthContext, MessagingScreen } from './chunk-7JMNKWPN.js';
|
|
2
|
+
export { AUTH_CONSTANTS, ApiError, DEFAULT_AUTH_URL, DEFAULT_SDK_WIDGET_REGISTRY, FluidAuthProvider, FluidProvider, FluidThemeProvider, MessagingScreen, STORAGE_KEYS, URL_PARAMS, USER_TYPES, buildThemeDefinition, cleanTokenFromUrl, clearTokens, createDefaultAuthRedirect, createFluidClient, createFluidFileUploader, decodeToken, extractAllTokensFromUrl, extractCompanyTokenFromUrl, extractTokenFromUrl, getActiveThemeId, getStoredToken, getTokenExpiration, getTokenTimeRemaining, hasStoredToken, hasTokenInUrl, isApiError, isTokenExpired, isUserType, isValidToken, messagingScreenPropertySchema, normalizeComponentTree, storeToken, toNavigationItem, toScreenDefinition, transformManifestToRepAppData, transformThemes, useFluidApi, useFluidAuthContext, useFluidContext, useMessagingAuth, useMessagingConfig, useThemeContext, validateToken } from './chunk-7JMNKWPN.js';
|
|
3
|
+
import { ContactsScreen } from './chunk-CMF2FYTD.js';
|
|
4
|
+
export { ContactsScreen, contactsScreenPropertySchema } from './chunk-CMF2FYTD.js';
|
|
5
|
+
import { OrdersScreen } from './chunk-WFPYEYC7.js';
|
|
6
|
+
export { OrdersScreen, ordersScreenPropertySchema } from './chunk-WFPYEYC7.js';
|
|
7
|
+
import { CustomersScreen } from './chunk-WMBD65GH.js';
|
|
8
|
+
export { CustomersScreen, customersScreenPropertySchema } from './chunk-WMBD65GH.js';
|
|
9
|
+
import { ProductsScreen } from './chunk-QZMWG7EM.js';
|
|
10
|
+
export { ProductsScreen, productsScreenPropertySchema } from './chunk-QZMWG7EM.js';
|
|
11
|
+
import { CoreScreenPlaceholder } from './chunk-RS4OSTES.js';
|
|
12
|
+
import './chunk-424PT5DM.js';
|
|
13
|
+
import { createContext, memo, forwardRef, useContext, useRef, useEffect, useMemo, useState, useCallback } from 'react';
|
|
9
14
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
|
-
import {
|
|
15
|
+
import { useQuery } from '@tanstack/react-query';
|
|
11
16
|
export { WIDGET_TYPE_NAMES, assertDefined, assertNever, isWidgetType, isWidgetTypeName, sectionLayoutConfig } from '@fluid-app/rep-core/types';
|
|
12
|
-
import * as theme_star from '@fluid-app/rep-core/theme';
|
|
13
17
|
export { AlertWidget, CalendarWidget, CarouselWidget, CatchUpWidget, ChartWidget, ContainerWidget, EmbedWidget, ImageWidget, LayoutWidget, ListWidget, MySiteWidget, NestedWidget, QuickShareWidget, RecentActivityWidget, SpacerWidget, TableWidget, TextWidget, ToDoWidget, VideoWidget, alertWidgetPropertySchema, calendarWidgetPropertySchema, carouselWidgetPropertySchema, catchUpWidgetPropertySchema, chartWidgetPropertySchema, containerWidgetPropertySchema, embedWidgetPropertySchema, imageWidgetPropertySchema, layoutWidgetPropertySchema, listWidgetPropertySchema, mySiteWidgetPropertySchema, nestedWidgetPropertySchema, quickShareWidgetPropertySchema, recentActivityWidgetPropertySchema, spacerWidgetPropertySchema, tableWidgetPropertySchema, textWidgetPropertySchema, toDoWidgetPropertySchema, videoWidgetPropertySchema, widgetPropertySchemas } from '@fluid-app/rep-widgets/widgets';
|
|
14
18
|
export { createScreen, createWidgetFromShareable, createWidgetRegistry, groupChildrenByColumn } from '@fluid-app/rep-core/widget-utils';
|
|
15
19
|
export { PROPERTY_FIELD_TYPES, gapValues, isPropertyFieldType } from '@fluid-app/rep-core/registries';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var REDIRECT_COOLDOWN_S = 10;
|
|
31
|
-
function isRedirectLoop() {
|
|
32
|
-
try {
|
|
33
|
-
const ts = sessionStorage.getItem(REDIRECT_TIMESTAMP_KEY);
|
|
34
|
-
if (!ts) return false;
|
|
35
|
-
const elapsed = (Date.now() - Number(ts)) / 1e3;
|
|
36
|
-
return elapsed < REDIRECT_COOLDOWN_S;
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function markRedirect() {
|
|
42
|
-
try {
|
|
43
|
-
sessionStorage.setItem(REDIRECT_TIMESTAMP_KEY, String(Date.now()));
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function createDefaultAuthRedirect(authUrl) {
|
|
48
|
-
return () => {
|
|
49
|
-
if (isRedirectLoop()) {
|
|
50
|
-
console.warn(
|
|
51
|
-
"[FluidAuth] Auth redirect suppressed \u2014 possible redirect loop. Check that your auth server returns a token accepted by the API."
|
|
52
|
-
);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
markRedirect();
|
|
56
|
-
const base = authUrl ?? DEFAULT_AUTH_URL;
|
|
57
|
-
const currentUrl = encodeURIComponent(window.location.href);
|
|
58
|
-
window.location.href = `${base}/?redirect_url=${currentUrl}`;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function resolveAuthFailureHandler(onAuthFailure, authUrl) {
|
|
62
|
-
return onAuthFailure ?? createDefaultAuthRedirect(authUrl);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/client/fluid-client.ts
|
|
66
|
-
var ApiError = class _ApiError extends Error {
|
|
67
|
-
status;
|
|
68
|
-
data;
|
|
69
|
-
constructor(message, status, data) {
|
|
70
|
-
super(message);
|
|
71
|
-
this.name = "ApiError";
|
|
72
|
-
this.status = status;
|
|
73
|
-
this.data = data;
|
|
74
|
-
const errorWithCapture = Error;
|
|
75
|
-
if (errorWithCapture.captureStackTrace) {
|
|
76
|
-
errorWithCapture.captureStackTrace(this, _ApiError);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
toJSON() {
|
|
80
|
-
return {
|
|
81
|
-
name: this.name,
|
|
82
|
-
message: this.message,
|
|
83
|
-
status: this.status,
|
|
84
|
-
data: this.data
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
function isApiError(error) {
|
|
89
|
-
return error instanceof ApiError;
|
|
90
|
-
}
|
|
91
|
-
function isString(value) {
|
|
92
|
-
return typeof value === "string";
|
|
93
|
-
}
|
|
94
|
-
function extractErrorMessage(data, fallback) {
|
|
95
|
-
if ("message" in data && isString(data.message)) {
|
|
96
|
-
return data.message;
|
|
97
|
-
}
|
|
98
|
-
if ("error_message" in data && isString(data.error_message)) {
|
|
99
|
-
return data.error_message;
|
|
100
|
-
}
|
|
101
|
-
if ("error" in data && isString(data.error)) {
|
|
102
|
-
return data.error;
|
|
103
|
-
}
|
|
104
|
-
return fallback;
|
|
105
|
-
}
|
|
106
|
-
function createFluidClient(config) {
|
|
107
|
-
const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {} } = config;
|
|
108
|
-
const effectiveOnAuthError = onAuthError ?? createDefaultAuthRedirect();
|
|
109
|
-
async function buildHeaders(customHeaders) {
|
|
110
|
-
const headers = {
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
...defaultHeaders,
|
|
113
|
-
...customHeaders
|
|
114
|
-
};
|
|
115
|
-
if (getAuthToken) {
|
|
116
|
-
const token = await getAuthToken();
|
|
117
|
-
if (token) {
|
|
118
|
-
headers.Authorization = `Bearer ${token}`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return headers;
|
|
122
|
-
}
|
|
123
|
-
function buildUrl(endpoint, params) {
|
|
124
|
-
const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
125
|
-
const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
126
|
-
const url = new URL(normalizedBase + normalizedEndpoint);
|
|
127
|
-
if (params) {
|
|
128
|
-
for (const [key, value] of Object.entries(params)) {
|
|
129
|
-
if (value === void 0 || value === null) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (Array.isArray(value)) {
|
|
133
|
-
for (const item of value) {
|
|
134
|
-
url.searchParams.append(`${key}[]`, String(item));
|
|
135
|
-
}
|
|
136
|
-
} else if (typeof value === "object") {
|
|
137
|
-
for (const [subKey, subValue] of Object.entries(
|
|
138
|
-
value
|
|
139
|
-
)) {
|
|
140
|
-
if (subValue === void 0 || subValue === null) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (Array.isArray(subValue)) {
|
|
144
|
-
for (const item of subValue) {
|
|
145
|
-
url.searchParams.append(`${key}[${subKey}][]`, String(item));
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
url.searchParams.append(`${key}[${subKey}]`, String(subValue));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
url.searchParams.append(key, String(value));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return url.toString();
|
|
157
|
-
}
|
|
158
|
-
const defaultRequestOptions = {
|
|
159
|
-
method: HTTP_METHODS.GET
|
|
160
|
-
};
|
|
161
|
-
async function request(endpoint, options = {}) {
|
|
162
|
-
const {
|
|
163
|
-
method = defaultRequestOptions.method,
|
|
164
|
-
headers: customHeaders,
|
|
165
|
-
params,
|
|
166
|
-
body,
|
|
167
|
-
signal
|
|
168
|
-
} = options;
|
|
169
|
-
const url = buildUrl(
|
|
170
|
-
endpoint,
|
|
171
|
-
method === HTTP_METHODS.GET ? params : void 0
|
|
172
|
-
);
|
|
173
|
-
const headers = await buildHeaders(customHeaders);
|
|
174
|
-
let response;
|
|
175
|
-
try {
|
|
176
|
-
const fetchOptions = {
|
|
177
|
-
method,
|
|
178
|
-
headers
|
|
179
|
-
};
|
|
180
|
-
if (signal !== void 0) {
|
|
181
|
-
fetchOptions.signal = signal;
|
|
182
|
-
}
|
|
183
|
-
if (body && method !== HTTP_METHODS.GET) {
|
|
184
|
-
fetchOptions.body = JSON.stringify(body);
|
|
185
|
-
}
|
|
186
|
-
response = await fetch(url, fetchOptions);
|
|
187
|
-
} catch (networkError) {
|
|
188
|
-
throw new ApiError(
|
|
189
|
-
`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`,
|
|
190
|
-
0,
|
|
191
|
-
null
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
if (response.status === 401) {
|
|
195
|
-
effectiveOnAuthError();
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
if (!response.ok) {
|
|
199
|
-
try {
|
|
200
|
-
const contentType = response.headers.get("content-type");
|
|
201
|
-
if (contentType?.includes("application/json")) {
|
|
202
|
-
const data = await response.json();
|
|
203
|
-
const errorMessage = extractErrorMessage(
|
|
204
|
-
data,
|
|
205
|
-
`${method} request failed`
|
|
206
|
-
);
|
|
207
|
-
throw new ApiError(
|
|
208
|
-
errorMessage,
|
|
209
|
-
response.status,
|
|
210
|
-
"errors" in data ? data.errors : data
|
|
211
|
-
);
|
|
212
|
-
} else {
|
|
213
|
-
throw new ApiError(
|
|
214
|
-
`${method} request failed with status ${response.status}`,
|
|
215
|
-
response.status,
|
|
216
|
-
null
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
} catch (error) {
|
|
220
|
-
if (isApiError(error)) {
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
throw new ApiError(
|
|
224
|
-
`${method} request failed with status ${response.status}`,
|
|
225
|
-
response.status,
|
|
226
|
-
null
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
try {
|
|
234
|
-
const data = await response.json();
|
|
235
|
-
if (data === null || data === void 0) {
|
|
236
|
-
throw new ApiError(
|
|
237
|
-
"Unexpected null/undefined in JSON response",
|
|
238
|
-
response.status,
|
|
239
|
-
null
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
return data;
|
|
243
|
-
} catch (parseError) {
|
|
244
|
-
if (isApiError(parseError)) {
|
|
245
|
-
throw parseError;
|
|
246
|
-
}
|
|
247
|
-
throw new ApiError(
|
|
248
|
-
"Failed to parse response as JSON",
|
|
249
|
-
response.status,
|
|
250
|
-
null
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
async function requestNullable(endpoint, options = {}) {
|
|
255
|
-
return request(endpoint, options);
|
|
256
|
-
}
|
|
257
|
-
async function safeRequest(endpoint, options = {}) {
|
|
258
|
-
try {
|
|
259
|
-
const data = await request(endpoint, options);
|
|
260
|
-
return { success: true, data };
|
|
261
|
-
} catch (error) {
|
|
262
|
-
if (isApiError(error)) {
|
|
263
|
-
return { success: false, error };
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
success: false,
|
|
267
|
-
error: new ApiError(
|
|
268
|
-
error instanceof Error ? error.message : "Unknown error",
|
|
269
|
-
0,
|
|
270
|
-
null
|
|
271
|
-
)
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function toParams(params) {
|
|
276
|
-
return params;
|
|
277
|
-
}
|
|
278
|
-
const get = (endpoint, params, options) => {
|
|
279
|
-
const baseOptions = {
|
|
280
|
-
...options,
|
|
281
|
-
method: HTTP_METHODS.GET
|
|
282
|
-
};
|
|
283
|
-
const convertedParams = toParams(params);
|
|
284
|
-
const requestOptions = convertedParams !== void 0 ? { ...baseOptions, params: convertedParams } : baseOptions;
|
|
285
|
-
return request(endpoint, requestOptions);
|
|
286
|
-
};
|
|
287
|
-
const post = (endpoint, body, options) => request(endpoint, {
|
|
288
|
-
...options,
|
|
289
|
-
method: HTTP_METHODS.POST,
|
|
290
|
-
body
|
|
291
|
-
});
|
|
292
|
-
const put = (endpoint, body, options) => request(endpoint, {
|
|
293
|
-
...options,
|
|
294
|
-
method: HTTP_METHODS.PUT,
|
|
295
|
-
body
|
|
296
|
-
});
|
|
297
|
-
const patch = (endpoint, body, options) => request(endpoint, {
|
|
298
|
-
...options,
|
|
299
|
-
method: HTTP_METHODS.PATCH,
|
|
300
|
-
body
|
|
301
|
-
});
|
|
302
|
-
const del = (endpoint, options) => request(endpoint, {
|
|
303
|
-
...options,
|
|
304
|
-
method: HTTP_METHODS.DELETE
|
|
305
|
-
});
|
|
306
|
-
return {
|
|
307
|
-
// Low-level methods for custom endpoints
|
|
308
|
-
request,
|
|
309
|
-
requestNullable,
|
|
310
|
-
safeRequest,
|
|
311
|
-
get,
|
|
312
|
-
post,
|
|
313
|
-
put,
|
|
314
|
-
patch,
|
|
315
|
-
delete: del,
|
|
316
|
-
// Products API - matches fluid-admin's /company/v1/products
|
|
317
|
-
products: {
|
|
318
|
-
list: (params) => get(
|
|
319
|
-
"/company/v1/products",
|
|
320
|
-
params
|
|
321
|
-
),
|
|
322
|
-
get: (id) => get(`/company/v1/products/${id}`),
|
|
323
|
-
search: (query, params) => get("/company/v1/products", {
|
|
324
|
-
search_query: query,
|
|
325
|
-
...params
|
|
326
|
-
})
|
|
327
|
-
},
|
|
328
|
-
// Orders API
|
|
329
|
-
orders: {
|
|
330
|
-
list: (params) => get("/orders", params),
|
|
331
|
-
get: (id) => get(`/orders/${id}`),
|
|
332
|
-
create: (data) => post("/orders", data)
|
|
333
|
-
},
|
|
334
|
-
// Reps API
|
|
335
|
-
reps: {
|
|
336
|
-
current: () => get("/reps/me"),
|
|
337
|
-
updateProfile: (data) => patch("/reps/me", data)
|
|
338
|
-
},
|
|
339
|
-
// Profile API (themes, navigation, screens)
|
|
340
|
-
profile: {
|
|
341
|
-
get: () => get("/rep_app/manifest")
|
|
342
|
-
},
|
|
343
|
-
// Permissions API
|
|
344
|
-
permissions: {
|
|
345
|
-
get: () => get("/company/roles/my_permissions")
|
|
346
|
-
},
|
|
347
|
-
// Analytics API
|
|
348
|
-
analytics: {
|
|
349
|
-
dashboard: () => get("/analytics/dashboard"),
|
|
350
|
-
sales: (params) => get("/analytics/sales", params)
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
var ThemeContext = createContext(null);
|
|
355
|
-
function applyThemeVariables(theme, container) {
|
|
356
|
-
const target = container ?? document.documentElement;
|
|
357
|
-
const toRemove = [];
|
|
358
|
-
for (let i = 0; i < target.style.length; i++) {
|
|
359
|
-
const prop = target.style[i];
|
|
360
|
-
if (prop.startsWith("--fluid-")) {
|
|
361
|
-
toRemove.push(prop);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
for (const prop of toRemove) {
|
|
365
|
-
target.style.removeProperty(prop);
|
|
366
|
-
}
|
|
367
|
-
for (const [key, value] of Object.entries(theme.config)) {
|
|
368
|
-
target.style.setProperty(`--fluid-${key}`, value);
|
|
369
|
-
}
|
|
370
|
-
if (theme.mode) {
|
|
371
|
-
target.dataset.fluidThemeMode = theme.mode;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function FluidThemeProvider({
|
|
375
|
-
children,
|
|
376
|
-
initialTheme,
|
|
377
|
-
container
|
|
378
|
-
}) {
|
|
379
|
-
const [currentTheme, setCurrentTheme] = useState(
|
|
380
|
-
initialTheme ?? null
|
|
381
|
-
);
|
|
382
|
-
useEffect(() => {
|
|
383
|
-
if (currentTheme) {
|
|
384
|
-
applyThemeVariables(currentTheme, container ?? null);
|
|
385
|
-
}
|
|
386
|
-
}, [currentTheme, container]);
|
|
387
|
-
const setTheme = useCallback((theme) => {
|
|
388
|
-
setCurrentTheme(theme);
|
|
389
|
-
}, []);
|
|
390
|
-
const setThemeMode = useCallback((mode) => {
|
|
391
|
-
setCurrentTheme((prev) => prev ? { ...prev, mode } : null);
|
|
392
|
-
}, []);
|
|
393
|
-
const value = useMemo(
|
|
394
|
-
() => ({
|
|
395
|
-
currentTheme,
|
|
396
|
-
setTheme,
|
|
397
|
-
setThemeMode
|
|
398
|
-
}),
|
|
399
|
-
[currentTheme, setTheme, setThemeMode]
|
|
400
|
-
);
|
|
401
|
-
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children });
|
|
402
|
-
}
|
|
403
|
-
function useThemeContext() {
|
|
404
|
-
const context = useContext(ThemeContext);
|
|
405
|
-
if (!context) {
|
|
406
|
-
throw new Error("useThemeContext must be used within a FluidThemeProvider");
|
|
407
|
-
}
|
|
408
|
-
return context;
|
|
409
|
-
}
|
|
410
|
-
var FluidContext = createContext(null);
|
|
411
|
-
function FluidProvider({
|
|
412
|
-
config,
|
|
413
|
-
children,
|
|
414
|
-
queryClient,
|
|
415
|
-
initialTheme,
|
|
416
|
-
themeContainer
|
|
417
|
-
}) {
|
|
418
|
-
const defaultQueryClient = useMemo(
|
|
419
|
-
() => new QueryClient({
|
|
420
|
-
defaultOptions: {
|
|
421
|
-
queries: {
|
|
422
|
-
staleTime: 1e3 * 60,
|
|
423
|
-
// 1 minute
|
|
424
|
-
retry: 1
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}),
|
|
428
|
-
[]
|
|
429
|
-
);
|
|
430
|
-
const configRef = useRef(config);
|
|
431
|
-
configRef.current = config;
|
|
432
|
-
const client = useMemo(
|
|
433
|
-
() => createFluidClient({
|
|
434
|
-
...configRef.current,
|
|
435
|
-
getAuthToken: () => configRef.current.getAuthToken?.() ?? null,
|
|
436
|
-
onAuthError: () => configRef.current.onAuthError?.()
|
|
437
|
-
}),
|
|
438
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
439
|
-
[config.baseUrl]
|
|
440
|
-
);
|
|
441
|
-
const contextValue = useMemo(
|
|
442
|
-
() => ({ client, config: configRef.current }),
|
|
443
|
-
[client]
|
|
444
|
-
);
|
|
445
|
-
const themeProviderProps = {
|
|
446
|
-
...initialTheme !== void 0 && { initialTheme },
|
|
447
|
-
...themeContainer !== void 0 && { container: themeContainer }
|
|
448
|
-
};
|
|
449
|
-
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient ?? defaultQueryClient, children: /* @__PURE__ */ jsx(FluidContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(FluidThemeProvider, { ...themeProviderProps, children }) }) });
|
|
450
|
-
}
|
|
451
|
-
function useFluidContext() {
|
|
452
|
-
const context = useContext(FluidContext);
|
|
453
|
-
if (!context) {
|
|
454
|
-
throw new Error("useFluidContext must be used within a FluidProvider");
|
|
455
|
-
}
|
|
456
|
-
return context;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// src/auth/constants.ts
|
|
460
|
-
var AUTH_CONSTANTS = {
|
|
461
|
-
/**
|
|
462
|
-
* Grace period in milliseconds to account for clock skew
|
|
463
|
-
* when checking token expiration. Tokens are considered valid
|
|
464
|
-
* if they expire within this period.
|
|
465
|
-
*/
|
|
466
|
-
TOKEN_GRACE_PERIOD_MS: 30 * 1e3,
|
|
467
|
-
// 30 seconds
|
|
468
|
-
/**
|
|
469
|
-
* Default cookie max age in seconds (9 days).
|
|
470
|
-
* This matches the typical JWT token lifetime from the Fluid API.
|
|
471
|
-
*/
|
|
472
|
-
COOKIE_MAX_AGE: 9 * 24 * 60 * 60
|
|
473
|
-
// 9 days = 777600 seconds
|
|
474
|
-
};
|
|
475
|
-
var STORAGE_KEYS = {
|
|
476
|
-
/** localStorage key for user token */
|
|
477
|
-
USER_TOKEN: "fluidUserToken",
|
|
478
|
-
/** localStorage key for company token (legacy) */
|
|
479
|
-
COMPANY_TOKEN: "fluidCompanyToken",
|
|
480
|
-
/** Cookie name for auth token */
|
|
481
|
-
AUTH_COOKIE: "auth_token"
|
|
482
|
-
};
|
|
483
|
-
var URL_PARAMS = {
|
|
484
|
-
/** URL parameter name for user token */
|
|
485
|
-
USER_TOKEN: "fluidUserToken",
|
|
486
|
-
/** URL parameter name for company token (legacy) */
|
|
487
|
-
COMPANY_TOKEN: "fluidCompanyToken"
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
// src/auth/browser-utils.ts
|
|
491
|
-
function isBrowser() {
|
|
492
|
-
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// src/auth/url-token.ts
|
|
496
|
-
function extractTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
497
|
-
if (!isBrowser()) {
|
|
498
|
-
return null;
|
|
499
|
-
}
|
|
500
|
-
try {
|
|
501
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
502
|
-
return searchParams.get(tokenKey);
|
|
503
|
-
} catch {
|
|
504
|
-
return null;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function extractCompanyTokenFromUrl(tokenKey = URL_PARAMS.COMPANY_TOKEN) {
|
|
508
|
-
if (!isBrowser()) {
|
|
509
|
-
return null;
|
|
510
|
-
}
|
|
511
|
-
try {
|
|
512
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
513
|
-
return searchParams.get(tokenKey);
|
|
514
|
-
} catch {
|
|
515
|
-
return null;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
function cleanTokenFromUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
519
|
-
if (!isBrowser()) {
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
try {
|
|
523
|
-
const url = new URL(window.location.href);
|
|
524
|
-
const hadToken = url.searchParams.has(tokenKey);
|
|
525
|
-
const hadCompanyToken = url.searchParams.has(URL_PARAMS.COMPANY_TOKEN);
|
|
526
|
-
url.searchParams.delete(tokenKey);
|
|
527
|
-
url.searchParams.delete(URL_PARAMS.COMPANY_TOKEN);
|
|
528
|
-
if (hadToken || hadCompanyToken) {
|
|
529
|
-
window.history.replaceState(
|
|
530
|
-
window.history.state,
|
|
531
|
-
document.title,
|
|
532
|
-
url.toString()
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
} catch (error) {
|
|
536
|
-
console.warn("[FluidAuth] Failed to clean token from URL:", error);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
function hasTokenInUrl(tokenKey = URL_PARAMS.USER_TOKEN) {
|
|
540
|
-
if (!isBrowser()) {
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
try {
|
|
544
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
545
|
-
return searchParams.has(tokenKey);
|
|
546
|
-
} catch {
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
function extractAllTokensFromUrl(userTokenKey = URL_PARAMS.USER_TOKEN, companyTokenKey = URL_PARAMS.COMPANY_TOKEN) {
|
|
551
|
-
if (!isBrowser()) {
|
|
552
|
-
return { userToken: null, companyToken: null };
|
|
553
|
-
}
|
|
554
|
-
try {
|
|
555
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
556
|
-
return {
|
|
557
|
-
userToken: searchParams.get(userTokenKey),
|
|
558
|
-
companyToken: searchParams.get(companyTokenKey)
|
|
559
|
-
};
|
|
560
|
-
} catch {
|
|
561
|
-
return { userToken: null, companyToken: null };
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// src/auth/token-storage.ts
|
|
566
|
-
function parseCookies() {
|
|
567
|
-
if (!isBrowser()) {
|
|
568
|
-
return {};
|
|
569
|
-
}
|
|
570
|
-
const cookies = {};
|
|
571
|
-
const cookieString = document.cookie;
|
|
572
|
-
if (!cookieString) {
|
|
573
|
-
return cookies;
|
|
574
|
-
}
|
|
575
|
-
cookieString.split(";").forEach((cookie) => {
|
|
576
|
-
const [name, ...valueParts] = cookie.trim().split("=");
|
|
577
|
-
if (name) {
|
|
578
|
-
cookies[name] = decodeURIComponent(valueParts.join("="));
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
return cookies;
|
|
582
|
-
}
|
|
583
|
-
function setCookie(name, value, options = {}) {
|
|
584
|
-
if (!isBrowser()) {
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const {
|
|
588
|
-
maxAge = AUTH_CONSTANTS.COOKIE_MAX_AGE,
|
|
589
|
-
path = "/",
|
|
590
|
-
sameSite = "lax",
|
|
591
|
-
secure = window.location.protocol === "https:"
|
|
592
|
-
} = options;
|
|
593
|
-
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
|
594
|
-
cookieString += `; path=${path}`;
|
|
595
|
-
cookieString += `; max-age=${maxAge}`;
|
|
596
|
-
cookieString += `; samesite=${sameSite}`;
|
|
597
|
-
if (secure) {
|
|
598
|
-
cookieString += "; secure";
|
|
599
|
-
}
|
|
600
|
-
document.cookie = cookieString;
|
|
601
|
-
}
|
|
602
|
-
function deleteCookie(name, path = "/") {
|
|
603
|
-
if (!isBrowser()) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
document.cookie = `${name}=; path=${path}; max-age=0`;
|
|
607
|
-
}
|
|
608
|
-
function getStoredToken(config) {
|
|
609
|
-
if (!isBrowser()) {
|
|
610
|
-
return null;
|
|
611
|
-
}
|
|
612
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
613
|
-
const localStorageKey = STORAGE_KEYS.USER_TOKEN;
|
|
614
|
-
const cookies = parseCookies();
|
|
615
|
-
const cookieToken = cookies[cookieKey];
|
|
616
|
-
if (cookieToken) {
|
|
617
|
-
return cookieToken;
|
|
618
|
-
}
|
|
619
|
-
try {
|
|
620
|
-
return localStorage.getItem(localStorageKey);
|
|
621
|
-
} catch {
|
|
622
|
-
return null;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
function storeToken(token, config) {
|
|
626
|
-
if (!isBrowser()) {
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
630
|
-
const maxAge = config?.cookieMaxAge ?? AUTH_CONSTANTS.COOKIE_MAX_AGE;
|
|
631
|
-
try {
|
|
632
|
-
setCookie(cookieKey, token, {
|
|
633
|
-
maxAge,
|
|
634
|
-
path: "/",
|
|
635
|
-
// Use 'none' with secure for cross-origin iframe scenarios
|
|
636
|
-
sameSite: window.self !== window.top ? "none" : "lax",
|
|
637
|
-
secure: window.location.protocol === "https:"
|
|
638
|
-
});
|
|
639
|
-
} catch (error) {
|
|
640
|
-
console.warn("[FluidAuth] Failed to store token in cookie:", error);
|
|
641
|
-
}
|
|
642
|
-
try {
|
|
643
|
-
localStorage.setItem(STORAGE_KEYS.USER_TOKEN, token);
|
|
644
|
-
} catch (error) {
|
|
645
|
-
console.warn("[FluidAuth] Failed to store token in localStorage:", error);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function clearTokens(config) {
|
|
649
|
-
if (!isBrowser()) {
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
const cookieKey = config?.cookieKey ?? STORAGE_KEYS.AUTH_COOKIE;
|
|
653
|
-
try {
|
|
654
|
-
deleteCookie(cookieKey);
|
|
655
|
-
} catch {
|
|
656
|
-
}
|
|
657
|
-
try {
|
|
658
|
-
localStorage.removeItem(STORAGE_KEYS.USER_TOKEN);
|
|
659
|
-
localStorage.removeItem(STORAGE_KEYS.COMPANY_TOKEN);
|
|
660
|
-
} catch {
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function hasStoredToken(config) {
|
|
664
|
-
return getStoredToken(config) !== null;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// src/auth/types.ts
|
|
668
|
-
var USER_TYPES = {
|
|
669
|
-
admin: "admin",
|
|
670
|
-
rep: "rep",
|
|
671
|
-
root_admin: "root_admin",
|
|
672
|
-
customer: "customer"
|
|
673
|
-
};
|
|
674
|
-
function isUserType(value) {
|
|
675
|
-
return Object.values(USER_TYPES).includes(value);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// src/auth/token-utils.ts
|
|
679
|
-
function extractPayloadFromJose(decoded) {
|
|
680
|
-
const rawUserType = decoded.user_type;
|
|
681
|
-
const rawOgUserType = decoded.og_user_type;
|
|
682
|
-
return {
|
|
683
|
-
id: typeof decoded.id === "number" ? decoded.id : void 0,
|
|
684
|
-
email: typeof decoded.email === "string" ? decoded.email : void 0,
|
|
685
|
-
full_name: typeof decoded.full_name === "string" ? decoded.full_name : void 0,
|
|
686
|
-
user_type: typeof rawUserType === "string" && isUserType(rawUserType) ? rawUserType : "rep",
|
|
687
|
-
og_user_type: typeof rawOgUserType === "string" && isUserType(rawOgUserType) ? rawOgUserType : void 0,
|
|
688
|
-
company_id: typeof decoded.company_id === "number" ? decoded.company_id : void 0,
|
|
689
|
-
exp: decoded.exp,
|
|
690
|
-
auth_type: typeof decoded.auth_type === "string" ? decoded.auth_type : void 0
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
function decodeToken(token) {
|
|
694
|
-
try {
|
|
695
|
-
const decoded = decodeJwt(token);
|
|
696
|
-
return extractPayloadFromJose(decoded);
|
|
697
|
-
} catch (error) {
|
|
698
|
-
console.error("[FluidAuth] Failed to decode JWT token:", error);
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
function isTokenExpired(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
|
|
703
|
-
try {
|
|
704
|
-
const decoded = decodeJwt(token);
|
|
705
|
-
if (!decoded.exp) {
|
|
706
|
-
return false;
|
|
707
|
-
}
|
|
708
|
-
const expirationTime = decoded.exp * 1e3;
|
|
709
|
-
const currentTime = Date.now();
|
|
710
|
-
return currentTime > expirationTime + gracePeriodMs;
|
|
711
|
-
} catch {
|
|
712
|
-
return true;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
function validateToken(token, gracePeriodMs = AUTH_CONSTANTS.TOKEN_GRACE_PERIOD_MS) {
|
|
716
|
-
if (!token || token.trim() === "") {
|
|
717
|
-
return {
|
|
718
|
-
isValid: false,
|
|
719
|
-
error: "Token is empty or not provided"
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
const payload = decodeToken(token);
|
|
723
|
-
if (!payload) {
|
|
724
|
-
return {
|
|
725
|
-
isValid: false,
|
|
726
|
-
error: "Token has invalid format"
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
if (isTokenExpired(token, gracePeriodMs)) {
|
|
730
|
-
return {
|
|
731
|
-
isValid: false,
|
|
732
|
-
payload,
|
|
733
|
-
error: "Token has expired"
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
return {
|
|
737
|
-
isValid: true,
|
|
738
|
-
payload
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
function isValidToken(result) {
|
|
742
|
-
return result.isValid === true;
|
|
743
|
-
}
|
|
744
|
-
function getTokenExpiration(token) {
|
|
745
|
-
try {
|
|
746
|
-
const decoded = decodeJwt(token);
|
|
747
|
-
if (!decoded.exp) {
|
|
748
|
-
return null;
|
|
749
|
-
}
|
|
750
|
-
return new Date(decoded.exp * 1e3);
|
|
751
|
-
} catch {
|
|
752
|
-
return null;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
function getTokenTimeRemaining(token) {
|
|
756
|
-
try {
|
|
757
|
-
const decoded = decodeJwt(token);
|
|
758
|
-
if (!decoded.exp) {
|
|
759
|
-
return Infinity;
|
|
760
|
-
}
|
|
761
|
-
const expirationTime = decoded.exp * 1e3;
|
|
762
|
-
const remaining = expirationTime - Date.now();
|
|
763
|
-
return Math.max(0, remaining);
|
|
764
|
-
} catch {
|
|
765
|
-
return 0;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
async function verifyToken(token, jwksUrl) {
|
|
769
|
-
try {
|
|
770
|
-
const JWKS = createRemoteJWKSet(new URL(jwksUrl));
|
|
771
|
-
const { payload } = await jwtVerify(token, JWKS);
|
|
772
|
-
const decoded = payload;
|
|
773
|
-
return extractPayloadFromJose(decoded);
|
|
774
|
-
} catch (error) {
|
|
775
|
-
console.error("[FluidAuth] JWT signature verification failed:", error);
|
|
776
|
-
return null;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
// src/auth/dev-utils.ts
|
|
781
|
-
function isDevBypassActive(devBypass) {
|
|
782
|
-
if (!devBypass) return false;
|
|
783
|
-
try {
|
|
784
|
-
return import.meta.env.DEV === true;
|
|
785
|
-
} catch {
|
|
786
|
-
return false;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function createDevUser() {
|
|
790
|
-
return {
|
|
791
|
-
id: 99999,
|
|
792
|
-
// Dev placeholder — avoids falsy 0
|
|
793
|
-
email: "dev@localhost",
|
|
794
|
-
full_name: "Dev User",
|
|
795
|
-
user_type: USER_TYPES.rep,
|
|
796
|
-
og_user_type: void 0,
|
|
797
|
-
company_id: 99999,
|
|
798
|
-
// Dev placeholder — avoids falsy 0
|
|
799
|
-
exp: void 0,
|
|
800
|
-
// Never expires
|
|
801
|
-
auth_type: "dev_bypass"
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
var FluidAuthContext = createContext(null);
|
|
805
|
-
function FluidAuthProvider({
|
|
806
|
-
children,
|
|
807
|
-
config
|
|
808
|
-
}) {
|
|
809
|
-
const configRef = useRef(config);
|
|
810
|
-
configRef.current = config;
|
|
811
|
-
const [isLoading2, setIsLoading] = useState(true);
|
|
812
|
-
const [token, setToken] = useState(null);
|
|
813
|
-
const [user, setUser] = useState(null);
|
|
814
|
-
const [error, setError] = useState(null);
|
|
815
|
-
useEffect(() => {
|
|
816
|
-
const initializeAuth = async () => {
|
|
817
|
-
const handleAuthFailure = () => {
|
|
818
|
-
const current = configRef.current;
|
|
819
|
-
const handler = resolveAuthFailureHandler(current?.onAuthFailure, current?.authUrl);
|
|
820
|
-
handler();
|
|
821
|
-
};
|
|
822
|
-
try {
|
|
823
|
-
if (isDevBypassActive(config?.devBypass)) {
|
|
824
|
-
const envToken = import.meta.env.VITE_DEV_TOKEN;
|
|
825
|
-
if (envToken) {
|
|
826
|
-
const validation = validateToken(envToken, config?.gracePeriodMs);
|
|
827
|
-
if (validation.isValid && validation.payload) {
|
|
828
|
-
storeToken(envToken, config);
|
|
829
|
-
setToken(envToken);
|
|
830
|
-
setUser(validation.payload);
|
|
831
|
-
setError(null);
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
console.warn(
|
|
835
|
-
"[FluidAuth] VITE_DEV_TOKEN is invalid or expired, falling back to mock user"
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
console.warn(
|
|
839
|
-
"[FluidAuth] Dev bypass active - using mock user. API calls will fail without a real token."
|
|
840
|
-
);
|
|
841
|
-
const devUser = createDevUser();
|
|
842
|
-
setToken(null);
|
|
843
|
-
setUser(devUser);
|
|
844
|
-
setError(null);
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
const tokenKey = config?.tokenKey ?? "fluidUserToken";
|
|
848
|
-
let candidateToken = extractTokenFromUrl(tokenKey);
|
|
849
|
-
if (!candidateToken && tokenKey !== AUTH_REDIRECT_TOKEN_KEY) {
|
|
850
|
-
candidateToken = extractTokenFromUrl(AUTH_REDIRECT_TOKEN_KEY);
|
|
851
|
-
}
|
|
852
|
-
cleanTokenFromUrl(tokenKey);
|
|
853
|
-
cleanTokenFromUrl(AUTH_REDIRECT_TOKEN_KEY);
|
|
854
|
-
if (!candidateToken) {
|
|
855
|
-
candidateToken = getStoredToken(config);
|
|
856
|
-
}
|
|
857
|
-
if (candidateToken) {
|
|
858
|
-
let payload = null;
|
|
859
|
-
if (config?.jwksUrl) {
|
|
860
|
-
payload = await verifyToken(candidateToken, config.jwksUrl);
|
|
861
|
-
if (!payload) {
|
|
862
|
-
clearTokens(config);
|
|
863
|
-
setToken(null);
|
|
864
|
-
setUser(null);
|
|
865
|
-
setError(new Error("JWT signature verification failed"));
|
|
866
|
-
handleAuthFailure();
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
if (isTokenExpired(candidateToken, config?.gracePeriodMs)) {
|
|
870
|
-
clearTokens(config);
|
|
871
|
-
setToken(null);
|
|
872
|
-
setUser(null);
|
|
873
|
-
setError(new Error("Token has expired"));
|
|
874
|
-
handleAuthFailure();
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
} else {
|
|
878
|
-
const validation = validateToken(
|
|
879
|
-
candidateToken,
|
|
880
|
-
config?.gracePeriodMs
|
|
881
|
-
);
|
|
882
|
-
if (validation.isValid && validation.payload) {
|
|
883
|
-
payload = validation.payload;
|
|
884
|
-
} else {
|
|
885
|
-
clearTokens(config);
|
|
886
|
-
setToken(null);
|
|
887
|
-
setUser(null);
|
|
888
|
-
setError(new Error(validation.error ?? "Invalid token"));
|
|
889
|
-
handleAuthFailure();
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
storeToken(candidateToken, config);
|
|
894
|
-
setToken(candidateToken);
|
|
895
|
-
setUser(payload);
|
|
896
|
-
setError(null);
|
|
897
|
-
} else {
|
|
898
|
-
setToken(null);
|
|
899
|
-
setUser(null);
|
|
900
|
-
setError(new Error("No authentication token found"));
|
|
901
|
-
handleAuthFailure();
|
|
902
|
-
}
|
|
903
|
-
} catch (err) {
|
|
904
|
-
const error2 = err instanceof Error ? err : new Error("Authentication error");
|
|
905
|
-
setError(error2);
|
|
906
|
-
setToken(null);
|
|
907
|
-
setUser(null);
|
|
908
|
-
handleAuthFailure();
|
|
909
|
-
} finally {
|
|
910
|
-
setIsLoading(false);
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
void initializeAuth();
|
|
914
|
-
}, []);
|
|
915
|
-
const clearAuth = useCallback(() => {
|
|
916
|
-
clearTokens(configRef.current);
|
|
917
|
-
setToken(null);
|
|
918
|
-
setUser(null);
|
|
919
|
-
setError(null);
|
|
920
|
-
}, []);
|
|
921
|
-
const contextValue = useMemo(
|
|
922
|
-
() => ({
|
|
923
|
-
isAuthenticated: user !== null,
|
|
924
|
-
isLoading: isLoading2,
|
|
925
|
-
user,
|
|
926
|
-
token,
|
|
927
|
-
clearAuth,
|
|
928
|
-
error
|
|
929
|
-
}),
|
|
930
|
-
[token, isLoading2, user, clearAuth, error]
|
|
931
|
-
);
|
|
932
|
-
return /* @__PURE__ */ jsx(FluidAuthContext.Provider, { value: contextValue, children });
|
|
933
|
-
}
|
|
934
|
-
function useFluidAuthContext() {
|
|
935
|
-
const context = useContext(FluidAuthContext);
|
|
936
|
-
if (!context) {
|
|
937
|
-
throw new Error(
|
|
938
|
-
"useFluidAuthContext must be used within a FluidAuthProvider. Wrap your app with <FluidAuthProvider> to use authentication features."
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
return context;
|
|
942
|
-
}
|
|
20
|
+
import { AppShellLayout } from '@fluid-app/rep-core/shell/AppShellLayout';
|
|
21
|
+
import { useThemeMode, ThemeModeProvider } from '@fluid-app/rep-core/shell/ThemeModeContext';
|
|
22
|
+
export { ThemeModeProvider, getThemeModeAttribute, useThemeMode } from '@fluid-app/rep-core/shell/ThemeModeContext';
|
|
23
|
+
import { normalizeSlug, getSystemNavigationBySection, isSystemNavigationItem } from '@fluid-app/rep-core/navigation/system-navigation-items';
|
|
24
|
+
import { resolveTheme, applyTheme, removeAllThemes } from '@fluid-app/rep-core/theme';
|
|
25
|
+
import { SidebarMenu, SidebarGroupLabel, SidebarMenuItem, SidebarMenuButton, useSidebar } from '@fluid-app/rep-core/shell/sidebar';
|
|
26
|
+
import { RepIcon } from '@fluid-app/rep-core/components/RepIcon';
|
|
27
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
28
|
+
import { faBars } from '@fortawesome/pro-regular-svg-icons/faBars';
|
|
29
|
+
import { faSun } from '@fortawesome/pro-regular-svg-icons/faSun';
|
|
30
|
+
import { faMoon } from '@fortawesome/pro-regular-svg-icons/faMoon';
|
|
31
|
+
import { faTableCellsLarge } from '@fortawesome/pro-regular-svg-icons/faTableCellsLarge';
|
|
32
|
+
import { DataAwareWidget } from '@fluid-app/rep-core/data-sources/DataAwareWidget';
|
|
33
|
+
import { useRegistry } from '@fluid-app/rep-widgets/contexts';
|
|
943
34
|
|
|
944
35
|
// src/types/page-template.ts
|
|
945
36
|
var PAGE_CATEGORIES = {
|
|
@@ -1181,50 +272,600 @@ function PageTemplateProvider({
|
|
|
1181
272
|
}
|
|
1182
273
|
}
|
|
1183
274
|
}
|
|
1184
|
-
registeredIds.current = registered;
|
|
1185
|
-
return () => {
|
|
1186
|
-
for (const id of registeredIds.current) {
|
|
1187
|
-
PageTemplateRegistry.unregister(id);
|
|
275
|
+
registeredIds.current = registered;
|
|
276
|
+
return () => {
|
|
277
|
+
for (const id of registeredIds.current) {
|
|
278
|
+
PageTemplateRegistry.unregister(id);
|
|
279
|
+
}
|
|
280
|
+
registeredIds.current = [];
|
|
281
|
+
};
|
|
282
|
+
}, [templateKey]);
|
|
283
|
+
const contextValue = useMemo(
|
|
284
|
+
() => ({
|
|
285
|
+
resolvePages: resolveNavigationPages,
|
|
286
|
+
listTemplates: () => PageTemplateRegistry.listAll(),
|
|
287
|
+
getTemplate: (id) => PageTemplateRegistry.get(id),
|
|
288
|
+
hasTemplate: (id) => PageTemplateRegistry.has(id)
|
|
289
|
+
}),
|
|
290
|
+
[]
|
|
291
|
+
);
|
|
292
|
+
return /* @__PURE__ */ jsx(PageTemplateContext.Provider, { value: contextValue, children });
|
|
293
|
+
}
|
|
294
|
+
function usePageTemplates() {
|
|
295
|
+
const context = useContext(PageTemplateContext);
|
|
296
|
+
if (!context) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
"usePageTemplates must be used within a PageTemplateProvider"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
return context;
|
|
302
|
+
}
|
|
303
|
+
function useResolvedPages(navigation) {
|
|
304
|
+
const { resolvePages } = usePageTemplates();
|
|
305
|
+
return useMemo(() => resolvePages(navigation), [resolvePages, navigation]);
|
|
306
|
+
}
|
|
307
|
+
var PROFILE_QUERY_KEY = ["fluid", "profile"];
|
|
308
|
+
function useFluidProfile() {
|
|
309
|
+
const api = useFluidApi();
|
|
310
|
+
return useQuery({
|
|
311
|
+
queryKey: PROFILE_QUERY_KEY,
|
|
312
|
+
queryFn: () => api.profile.get()
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function systemSetTimeoutZero(callback) {
|
|
316
|
+
setTimeout(callback, 0);
|
|
317
|
+
}
|
|
318
|
+
function matchQuery(filters, query) {
|
|
319
|
+
const {
|
|
320
|
+
type = "all",
|
|
321
|
+
exact,
|
|
322
|
+
fetchStatus,
|
|
323
|
+
predicate,
|
|
324
|
+
queryKey,
|
|
325
|
+
stale
|
|
326
|
+
} = filters;
|
|
327
|
+
if (queryKey) {
|
|
328
|
+
if (exact) {
|
|
329
|
+
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
} else if (!partialMatchKey(query.queryKey, queryKey)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (type !== "all") {
|
|
337
|
+
const isActive = query.isActive();
|
|
338
|
+
if (type === "active" && !isActive) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
if (type === "inactive" && isActive) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (typeof stale === "boolean" && query.isStale() !== stale) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
if (predicate && !predicate(query)) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
function hashQueryKeyByOptions(queryKey, options) {
|
|
357
|
+
const hashFn = options?.queryKeyHashFn || hashKey;
|
|
358
|
+
return hashFn(queryKey);
|
|
359
|
+
}
|
|
360
|
+
function hashKey(queryKey) {
|
|
361
|
+
return JSON.stringify(
|
|
362
|
+
queryKey,
|
|
363
|
+
(_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
|
|
364
|
+
result[key] = val[key];
|
|
365
|
+
return result;
|
|
366
|
+
}, {}) : val
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
function partialMatchKey(a, b) {
|
|
370
|
+
if (a === b) {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
if (typeof a !== typeof b) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
377
|
+
return Object.keys(b).every((key) => partialMatchKey(a[key], b[key]));
|
|
378
|
+
}
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
function isPlainObject(o) {
|
|
382
|
+
if (!hasObjectPrototype(o)) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
const ctor = o.constructor;
|
|
386
|
+
if (ctor === void 0) {
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
const prot = ctor.prototype;
|
|
390
|
+
if (!hasObjectPrototype(prot)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
function hasObjectPrototype(o) {
|
|
402
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ../../../node_modules/.pnpm/@tanstack+query-core@5.90.12/node_modules/@tanstack/query-core/build/modern/notifyManager.js
|
|
406
|
+
var defaultScheduler = systemSetTimeoutZero;
|
|
407
|
+
function createNotifyManager() {
|
|
408
|
+
let queue = [];
|
|
409
|
+
let transactions = 0;
|
|
410
|
+
let notifyFn = (callback) => {
|
|
411
|
+
callback();
|
|
412
|
+
};
|
|
413
|
+
let batchNotifyFn = (callback) => {
|
|
414
|
+
callback();
|
|
415
|
+
};
|
|
416
|
+
let scheduleFn = defaultScheduler;
|
|
417
|
+
const schedule = (callback) => {
|
|
418
|
+
if (transactions) {
|
|
419
|
+
queue.push(callback);
|
|
420
|
+
} else {
|
|
421
|
+
scheduleFn(() => {
|
|
422
|
+
notifyFn(callback);
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const flush = () => {
|
|
427
|
+
const originalQueue = queue;
|
|
428
|
+
queue = [];
|
|
429
|
+
if (originalQueue.length) {
|
|
430
|
+
scheduleFn(() => {
|
|
431
|
+
batchNotifyFn(() => {
|
|
432
|
+
originalQueue.forEach((callback) => {
|
|
433
|
+
notifyFn(callback);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
return {
|
|
440
|
+
batch: (callback) => {
|
|
441
|
+
let result;
|
|
442
|
+
transactions++;
|
|
443
|
+
try {
|
|
444
|
+
result = callback();
|
|
445
|
+
} finally {
|
|
446
|
+
transactions--;
|
|
447
|
+
if (!transactions) {
|
|
448
|
+
flush();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return result;
|
|
452
|
+
},
|
|
453
|
+
/**
|
|
454
|
+
* All calls to the wrapped function will be batched.
|
|
455
|
+
*/
|
|
456
|
+
batchCalls: (callback) => {
|
|
457
|
+
return (...args) => {
|
|
458
|
+
schedule(() => {
|
|
459
|
+
callback(...args);
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
},
|
|
463
|
+
schedule,
|
|
464
|
+
/**
|
|
465
|
+
* Use this method to set a custom notify function.
|
|
466
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
467
|
+
*/
|
|
468
|
+
setNotifyFunction: (fn) => {
|
|
469
|
+
notifyFn = fn;
|
|
470
|
+
},
|
|
471
|
+
/**
|
|
472
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
473
|
+
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
474
|
+
*/
|
|
475
|
+
setBatchNotifyFunction: (fn) => {
|
|
476
|
+
batchNotifyFn = fn;
|
|
477
|
+
},
|
|
478
|
+
setScheduler: (fn) => {
|
|
479
|
+
scheduleFn = fn;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
var notifyManager = createNotifyManager();
|
|
484
|
+
|
|
485
|
+
// ../../../node_modules/.pnpm/@tanstack+query-persist-client-core@5.91.11/node_modules/@tanstack/query-persist-client-core/build/modern/createPersister.js
|
|
486
|
+
var PERSISTER_KEY_PREFIX = "tanstack-query";
|
|
487
|
+
function experimental_createQueryPersister({
|
|
488
|
+
storage: storage2,
|
|
489
|
+
buster = "",
|
|
490
|
+
maxAge = 1e3 * 60 * 60 * 24,
|
|
491
|
+
serialize = JSON.stringify,
|
|
492
|
+
deserialize = JSON.parse,
|
|
493
|
+
prefix = PERSISTER_KEY_PREFIX,
|
|
494
|
+
refetchOnRestore = true,
|
|
495
|
+
filters
|
|
496
|
+
}) {
|
|
497
|
+
function isExpiredOrBusted(persistedQuery) {
|
|
498
|
+
if (persistedQuery.state.dataUpdatedAt) {
|
|
499
|
+
const queryAge = Date.now() - persistedQuery.state.dataUpdatedAt;
|
|
500
|
+
const expired = queryAge > maxAge;
|
|
501
|
+
const busted = persistedQuery.buster !== buster;
|
|
502
|
+
if (expired || busted) {
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
async function retrieveQuery(queryHash, afterRestoreMacroTask) {
|
|
510
|
+
if (storage2 != null) {
|
|
511
|
+
const storageKey = `${prefix}-${queryHash}`;
|
|
512
|
+
try {
|
|
513
|
+
const storedData = await storage2.getItem(storageKey);
|
|
514
|
+
if (storedData) {
|
|
515
|
+
const persistedQuery = await deserialize(storedData);
|
|
516
|
+
if (isExpiredOrBusted(persistedQuery)) {
|
|
517
|
+
await storage2.removeItem(storageKey);
|
|
518
|
+
} else {
|
|
519
|
+
if (afterRestoreMacroTask) {
|
|
520
|
+
notifyManager.schedule(
|
|
521
|
+
() => afterRestoreMacroTask(persistedQuery)
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
return persistedQuery.state.data;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
} catch (err) {
|
|
528
|
+
if (process.env.NODE_ENV === "development") {
|
|
529
|
+
console.error(err);
|
|
530
|
+
console.warn(
|
|
531
|
+
"Encountered an error attempting to restore query cache from persisted location."
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
await storage2.removeItem(storageKey);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
async function persistQueryByKey(queryKey, queryClient) {
|
|
540
|
+
if (storage2 != null) {
|
|
541
|
+
const query = queryClient.getQueryCache().find({ queryKey });
|
|
542
|
+
if (query) {
|
|
543
|
+
await persistQuery(query);
|
|
544
|
+
} else {
|
|
545
|
+
if (process.env.NODE_ENV === "development") {
|
|
546
|
+
console.warn(
|
|
547
|
+
"Could not find query to be persisted. QueryKey:",
|
|
548
|
+
JSON.stringify(queryKey)
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async function persistQuery(query) {
|
|
555
|
+
if (storage2 != null) {
|
|
556
|
+
const storageKey = `${prefix}-${query.queryHash}`;
|
|
557
|
+
storage2.setItem(
|
|
558
|
+
storageKey,
|
|
559
|
+
await serialize({
|
|
560
|
+
state: query.state,
|
|
561
|
+
queryKey: query.queryKey,
|
|
562
|
+
queryHash: query.queryHash,
|
|
563
|
+
buster
|
|
564
|
+
})
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
async function persisterFn(queryFn, ctx, query) {
|
|
569
|
+
const matchesFilter = filters ? matchQuery(filters, query) : true;
|
|
570
|
+
if (matchesFilter && query.state.data === void 0 && storage2 != null) {
|
|
571
|
+
const restoredData = await retrieveQuery(
|
|
572
|
+
query.queryHash,
|
|
573
|
+
(persistedQuery) => {
|
|
574
|
+
query.setState({
|
|
575
|
+
dataUpdatedAt: persistedQuery.state.dataUpdatedAt,
|
|
576
|
+
errorUpdatedAt: persistedQuery.state.errorUpdatedAt
|
|
577
|
+
});
|
|
578
|
+
if (refetchOnRestore === "always" || refetchOnRestore === true && query.isStale()) {
|
|
579
|
+
query.fetch();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
);
|
|
583
|
+
if (restoredData !== void 0) {
|
|
584
|
+
return Promise.resolve(restoredData);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const queryFnResult = await queryFn(ctx);
|
|
588
|
+
if (matchesFilter && storage2 != null) {
|
|
589
|
+
notifyManager.schedule(() => {
|
|
590
|
+
persistQuery(query);
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return Promise.resolve(queryFnResult);
|
|
594
|
+
}
|
|
595
|
+
async function persisterGc() {
|
|
596
|
+
if (storage2?.entries) {
|
|
597
|
+
const entries = await storage2.entries();
|
|
598
|
+
for (const [key, value] of entries) {
|
|
599
|
+
if (key.startsWith(prefix)) {
|
|
600
|
+
const persistedQuery = await deserialize(value);
|
|
601
|
+
if (isExpiredOrBusted(persistedQuery)) {
|
|
602
|
+
await storage2.removeItem(key);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
} else if (process.env.NODE_ENV === "development") {
|
|
607
|
+
throw new Error(
|
|
608
|
+
"Provided storage does not implement `entries` method. Garbage collection is not possible without ability to iterate over storage items."
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
async function restoreQueries(queryClient, filters2 = {}) {
|
|
613
|
+
const { exact, queryKey } = filters2;
|
|
614
|
+
if (storage2?.entries) {
|
|
615
|
+
const entries = await storage2.entries();
|
|
616
|
+
for (const [key, value] of entries) {
|
|
617
|
+
if (key.startsWith(prefix)) {
|
|
618
|
+
const persistedQuery = await deserialize(value);
|
|
619
|
+
if (isExpiredOrBusted(persistedQuery)) {
|
|
620
|
+
await storage2.removeItem(key);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (queryKey) {
|
|
624
|
+
if (exact) {
|
|
625
|
+
if (persistedQuery.queryHash !== hashKey(queryKey)) {
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
} else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) {
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
queryClient.setQueryData(
|
|
633
|
+
persistedQuery.queryKey,
|
|
634
|
+
persistedQuery.state.data,
|
|
635
|
+
{
|
|
636
|
+
updatedAt: persistedQuery.state.dataUpdatedAt
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
} else if (process.env.NODE_ENV === "development") {
|
|
642
|
+
throw new Error(
|
|
643
|
+
"Provided storage does not implement `entries` method. Restoration of all stored entries is not possible without ability to iterate over storage items."
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
persisterFn,
|
|
649
|
+
persistQuery,
|
|
650
|
+
persistQueryByKey,
|
|
651
|
+
retrieveQuery,
|
|
652
|
+
persisterGc,
|
|
653
|
+
restoreQueries
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// ../../platform/query-persister/src/persister.ts
|
|
658
|
+
var DB_NAME = "fluid_tanstack_query_cache";
|
|
659
|
+
var STORE_NAME = "fluid_queries";
|
|
660
|
+
var VERSION = 1;
|
|
661
|
+
var dbPromise = null;
|
|
662
|
+
async function deleteDatabase() {
|
|
663
|
+
return new Promise((resolve, reject) => {
|
|
664
|
+
console.warn("[IDB] Deleting database due to error");
|
|
665
|
+
const req = indexedDB.deleteDatabase(DB_NAME);
|
|
666
|
+
req.onsuccess = () => {
|
|
667
|
+
console.log("[IDB] Database deleted successfully");
|
|
668
|
+
resolve();
|
|
669
|
+
};
|
|
670
|
+
req.onerror = () => {
|
|
671
|
+
console.error("[IDB] Failed to delete database:", req.error);
|
|
672
|
+
reject(req.error ?? new Error("deleteDatabase failed"));
|
|
673
|
+
};
|
|
674
|
+
req.onblocked = () => {
|
|
675
|
+
console.warn("[IDB] Delete blocked: close all tabs using this database");
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function openDatabase() {
|
|
680
|
+
return new Promise((resolve, reject) => {
|
|
681
|
+
const req = indexedDB.open(DB_NAME, VERSION);
|
|
682
|
+
req.onupgradeneeded = () => {
|
|
683
|
+
const upgradeDb = req.result;
|
|
684
|
+
if (!upgradeDb.objectStoreNames.contains(STORE_NAME)) {
|
|
685
|
+
upgradeDb.createObjectStore(STORE_NAME);
|
|
1188
686
|
}
|
|
1189
|
-
registeredIds.current = [];
|
|
1190
687
|
};
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
688
|
+
req.onsuccess = () => {
|
|
689
|
+
const conn = req.result;
|
|
690
|
+
conn.onversionchange = () => {
|
|
691
|
+
console.trace("[IDB] version change \u2013 closing connection");
|
|
692
|
+
conn.close();
|
|
693
|
+
dbPromise = null;
|
|
694
|
+
};
|
|
695
|
+
resolve(conn);
|
|
696
|
+
};
|
|
697
|
+
req.onblocked = () => {
|
|
698
|
+
console.warn("[IDB] open blocked: another connection is holding the DB");
|
|
699
|
+
};
|
|
700
|
+
req.onerror = () => {
|
|
701
|
+
reject(
|
|
702
|
+
req.error instanceof Error ? req.error : new Error(`IndexedDB open failed: ${String(req.error)}`)
|
|
703
|
+
);
|
|
704
|
+
};
|
|
705
|
+
});
|
|
1202
706
|
}
|
|
1203
|
-
function
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
707
|
+
async function getDbWithRecovery() {
|
|
708
|
+
try {
|
|
709
|
+
return await openDatabase();
|
|
710
|
+
} catch (err) {
|
|
711
|
+
console.warn("[IDB] Initial open failed, attempting recovery:", err);
|
|
712
|
+
try {
|
|
713
|
+
await deleteDatabase();
|
|
714
|
+
console.log("[IDB] Retrying database open after deletion");
|
|
715
|
+
return await openDatabase();
|
|
716
|
+
} catch (retryErr) {
|
|
717
|
+
console.error("[IDB] Recovery failed:", retryErr);
|
|
718
|
+
throw retryErr;
|
|
719
|
+
}
|
|
1209
720
|
}
|
|
1210
|
-
return context;
|
|
1211
721
|
}
|
|
1212
|
-
function
|
|
1213
|
-
|
|
1214
|
-
|
|
722
|
+
function getDb() {
|
|
723
|
+
if (dbPromise) return dbPromise;
|
|
724
|
+
dbPromise = getDbWithRecovery().catch((err) => {
|
|
725
|
+
dbPromise = null;
|
|
726
|
+
throw err;
|
|
727
|
+
});
|
|
728
|
+
return dbPromise;
|
|
1215
729
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
730
|
+
var storage = {
|
|
731
|
+
async getItem(key) {
|
|
732
|
+
try {
|
|
733
|
+
const db = await getDb();
|
|
734
|
+
return new Promise((res) => {
|
|
735
|
+
try {
|
|
736
|
+
const r = db.transaction(STORE_NAME, "readonly").objectStore(STORE_NAME).get(key);
|
|
737
|
+
r.onsuccess = () => res(r.result);
|
|
738
|
+
r.onerror = () => {
|
|
739
|
+
console.trace("[IDB] getItem error:", r.error);
|
|
740
|
+
res(void 0);
|
|
741
|
+
};
|
|
742
|
+
} catch (txErr) {
|
|
743
|
+
console.trace("[IDB] getItem transaction error:", txErr);
|
|
744
|
+
res(void 0);
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
} catch (err) {
|
|
748
|
+
console.trace("[IDB] getItem getDb error:", err);
|
|
749
|
+
try {
|
|
750
|
+
const db = await getDb();
|
|
751
|
+
return new Promise((res) => {
|
|
752
|
+
try {
|
|
753
|
+
const r = db.transaction(STORE_NAME, "readonly").objectStore(STORE_NAME).get(key);
|
|
754
|
+
r.onsuccess = () => res(r.result);
|
|
755
|
+
r.onerror = () => {
|
|
756
|
+
console.trace("[IDB] getItem retry error:", r.error);
|
|
757
|
+
res(void 0);
|
|
758
|
+
};
|
|
759
|
+
} catch (txErr) {
|
|
760
|
+
console.trace("[IDB] getItem retry transaction error:", txErr);
|
|
761
|
+
res(void 0);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
} catch (recoveryErr) {
|
|
765
|
+
console.trace("[IDB] getItem recovery failed:", recoveryErr);
|
|
766
|
+
}
|
|
767
|
+
return void 0;
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
async setItem(key, value) {
|
|
771
|
+
const cloneableValue = JSON.parse(JSON.stringify(value));
|
|
772
|
+
try {
|
|
773
|
+
const db = await getDb();
|
|
774
|
+
if (!db) return;
|
|
775
|
+
await new Promise((resolve) => {
|
|
776
|
+
try {
|
|
777
|
+
const req = db.transaction(STORE_NAME, "readwrite").objectStore(STORE_NAME).put(cloneableValue, key);
|
|
778
|
+
req.onsuccess = () => resolve();
|
|
779
|
+
req.onerror = () => {
|
|
780
|
+
console.trace("[IDB] setItem error:", req.error);
|
|
781
|
+
resolve();
|
|
782
|
+
};
|
|
783
|
+
} catch (txErr) {
|
|
784
|
+
console.trace("[IDB] setItem transaction error:", txErr);
|
|
785
|
+
resolve();
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
} catch (err) {
|
|
789
|
+
console.trace("[IDB] setItem getDb error:", err);
|
|
790
|
+
try {
|
|
791
|
+
const db = await getDb();
|
|
792
|
+
await new Promise((resolve) => {
|
|
793
|
+
try {
|
|
794
|
+
const req = db.transaction(STORE_NAME, "readwrite").objectStore(STORE_NAME).put(cloneableValue, key);
|
|
795
|
+
req.onsuccess = () => resolve();
|
|
796
|
+
req.onerror = () => {
|
|
797
|
+
console.trace("[IDB] setItem retry error:", req.error);
|
|
798
|
+
resolve();
|
|
799
|
+
};
|
|
800
|
+
} catch (txErr) {
|
|
801
|
+
console.trace("[IDB] setItem retry transaction error:", txErr);
|
|
802
|
+
resolve();
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
} catch (recoveryErr) {
|
|
806
|
+
console.trace("[IDB] setItem recovery failed:", recoveryErr);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
async removeItem(key) {
|
|
811
|
+
try {
|
|
812
|
+
const db = await getDb();
|
|
813
|
+
if (!db) return;
|
|
814
|
+
await new Promise((resolve) => {
|
|
815
|
+
try {
|
|
816
|
+
const req = db.transaction(STORE_NAME, "readwrite").objectStore(STORE_NAME).delete(key);
|
|
817
|
+
req.onsuccess = () => resolve();
|
|
818
|
+
req.onerror = () => {
|
|
819
|
+
console.trace("[IDB] removeItem error:", req.error);
|
|
820
|
+
resolve();
|
|
821
|
+
};
|
|
822
|
+
} catch (txErr) {
|
|
823
|
+
console.trace("[IDB] removeItem transaction error:", txErr);
|
|
824
|
+
resolve();
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
} catch (err) {
|
|
828
|
+
console.trace("[IDB] removeItem getDb error:", err);
|
|
829
|
+
try {
|
|
830
|
+
const db = await getDb();
|
|
831
|
+
await new Promise((resolve) => {
|
|
832
|
+
try {
|
|
833
|
+
const req = db.transaction(STORE_NAME, "readwrite").objectStore(STORE_NAME).delete(key);
|
|
834
|
+
req.onsuccess = () => resolve();
|
|
835
|
+
req.onerror = () => {
|
|
836
|
+
console.trace("[IDB] removeItem retry error:", req.error);
|
|
837
|
+
resolve();
|
|
838
|
+
};
|
|
839
|
+
} catch (txErr) {
|
|
840
|
+
console.trace("[IDB] removeItem retry transaction error:", txErr);
|
|
841
|
+
resolve();
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
} catch (recoveryErr) {
|
|
845
|
+
console.trace("[IDB] removeItem recovery failed:", recoveryErr);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
function createPersister() {
|
|
851
|
+
return experimental_createQueryPersister({
|
|
852
|
+
storage,
|
|
853
|
+
serialize: (persistedQuery) => persistedQuery,
|
|
854
|
+
deserialize: (cached) => cached
|
|
855
|
+
});
|
|
1221
856
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
857
|
+
|
|
858
|
+
// src/hooks/use-fluid-app.ts
|
|
859
|
+
var APP_DATA_QUERY_KEY = ["fluid", "app"];
|
|
860
|
+
var appDataPersister = typeof window !== "undefined" ? createPersister() : void 0;
|
|
861
|
+
function useFluidApp(options) {
|
|
1224
862
|
const api = useFluidApi();
|
|
1225
863
|
return useQuery({
|
|
1226
|
-
queryKey:
|
|
1227
|
-
queryFn: () => api.
|
|
864
|
+
queryKey: APP_DATA_QUERY_KEY,
|
|
865
|
+
queryFn: () => api.app.getRaw(),
|
|
866
|
+
select: transformManifestToRepAppData,
|
|
867
|
+
...appDataPersister && { persister: appDataPersister.persisterFn },
|
|
868
|
+
...options?.enabled !== void 0 && { enabled: options.enabled }
|
|
1228
869
|
});
|
|
1229
870
|
}
|
|
1230
871
|
var PERMISSIONS_QUERY_KEY = ["fluid", "permissions"];
|
|
@@ -1261,12 +902,12 @@ function useFluidPermissions() {
|
|
|
1261
902
|
|
|
1262
903
|
// src/hooks/use-fluid-theme.ts
|
|
1263
904
|
function useFluidTheme() {
|
|
1264
|
-
const { currentTheme, setTheme, setThemeMode } = useThemeContext();
|
|
905
|
+
const { currentTheme, setTheme, setThemeMode, mode } = useThemeContext();
|
|
1265
906
|
return {
|
|
1266
907
|
currentTheme,
|
|
1267
908
|
setTheme,
|
|
1268
909
|
setThemeMode,
|
|
1269
|
-
mode
|
|
910
|
+
mode
|
|
1270
911
|
};
|
|
1271
912
|
}
|
|
1272
913
|
var CURRENT_REP_QUERY_KEY = ["fluid", "currentRep"];
|
|
@@ -2010,17 +1651,13 @@ function RequireAuth({
|
|
|
2010
1651
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2011
1652
|
}
|
|
2012
1653
|
|
|
2013
|
-
// src/themes/index.ts
|
|
2014
|
-
var themes_exports = {};
|
|
2015
|
-
__reExport(themes_exports, theme_star);
|
|
2016
|
-
|
|
2017
1654
|
// src/screens/index.ts
|
|
2018
1655
|
var screenPropertySchemas = {
|
|
2019
|
-
MessagingScreen: () => import('./MessagingScreen-
|
|
2020
|
-
ContactsScreen: () => import('./ContactsScreen-
|
|
2021
|
-
OrdersScreen: () => import('./OrdersScreen-
|
|
2022
|
-
CustomersScreen: () => import('./CustomersScreen-
|
|
2023
|
-
ProductsScreen: () => import('./ProductsScreen-
|
|
1656
|
+
MessagingScreen: () => import('./MessagingScreen-4H7ZBO3V.js').then((m) => m.messagingScreenPropertySchema),
|
|
1657
|
+
ContactsScreen: () => import('./ContactsScreen-33AJ5XUB.js').then((m) => m.contactsScreenPropertySchema),
|
|
1658
|
+
OrdersScreen: () => import('./OrdersScreen-IPPZLEYF.js').then((m) => m.ordersScreenPropertySchema),
|
|
1659
|
+
CustomersScreen: () => import('./CustomersScreen-E4HXBKV7.js').then((m) => m.customersScreenPropertySchema),
|
|
1660
|
+
ProductsScreen: () => import('./ProductsScreen-YTSOZW7B.js').then((m) => m.productsScreenPropertySchema)
|
|
2024
1661
|
};
|
|
2025
1662
|
var CORE_PAGE_IDS = {
|
|
2026
1663
|
MESSAGING: "core-messaging",
|
|
@@ -2122,34 +1759,642 @@ function registerCorePageTemplates() {
|
|
|
2122
1759
|
});
|
|
2123
1760
|
}
|
|
2124
1761
|
registerCorePageTemplates();
|
|
2125
|
-
var
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
1762
|
+
var SPIN_STYLE_ID2 = "fluid-app-shell-loading-spin";
|
|
1763
|
+
function ensureSpinStyle2() {
|
|
1764
|
+
if (typeof document === "undefined") return;
|
|
1765
|
+
if (document.getElementById(SPIN_STYLE_ID2)) return;
|
|
1766
|
+
const style = document.createElement("style");
|
|
1767
|
+
style.id = SPIN_STYLE_ID2;
|
|
1768
|
+
style.textContent = `@keyframes spin { to { transform: rotate(360deg); } }`;
|
|
1769
|
+
document.head.appendChild(style);
|
|
1770
|
+
}
|
|
1771
|
+
function AppShellLoading() {
|
|
1772
|
+
useEffect(() => {
|
|
1773
|
+
ensureSpinStyle2();
|
|
1774
|
+
}, []);
|
|
1775
|
+
return /* @__PURE__ */ jsxs(
|
|
1776
|
+
"div",
|
|
1777
|
+
{
|
|
1778
|
+
style: {
|
|
1779
|
+
display: "flex",
|
|
1780
|
+
flexDirection: "column",
|
|
1781
|
+
alignItems: "center",
|
|
1782
|
+
justifyContent: "center",
|
|
1783
|
+
minHeight: "100vh",
|
|
1784
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
1785
|
+
backgroundColor: "#f9fafb"
|
|
1786
|
+
},
|
|
1787
|
+
children: [
|
|
1788
|
+
/* @__PURE__ */ jsx(
|
|
1789
|
+
"div",
|
|
1790
|
+
{
|
|
1791
|
+
style: {
|
|
1792
|
+
width: "40px",
|
|
1793
|
+
height: "40px",
|
|
1794
|
+
border: "3px solid #e5e7eb",
|
|
1795
|
+
borderTopColor: "#3b82f6",
|
|
1796
|
+
borderRadius: "50%",
|
|
1797
|
+
animation: "spin 1s linear infinite"
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
),
|
|
1801
|
+
/* @__PURE__ */ jsx(
|
|
1802
|
+
"p",
|
|
1803
|
+
{
|
|
1804
|
+
style: {
|
|
1805
|
+
marginTop: "1rem",
|
|
1806
|
+
color: "#6b7280",
|
|
1807
|
+
fontSize: "0.875rem"
|
|
1808
|
+
},
|
|
1809
|
+
children: "Loading..."
|
|
1810
|
+
}
|
|
1811
|
+
)
|
|
1812
|
+
]
|
|
1813
|
+
}
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
function collectNavSlugs(items) {
|
|
1817
|
+
const slugs = [];
|
|
1818
|
+
for (const item of items) {
|
|
1819
|
+
if (item.slug) slugs.push(normalizeSlug(item.slug));
|
|
1820
|
+
for (const child of item.children ?? []) {
|
|
1821
|
+
if (child.slug) slugs.push(normalizeSlug(child.slug));
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return [...slugs].sort((a, b) => b.split("/").length - a.split("/").length);
|
|
1825
|
+
}
|
|
1826
|
+
function matchSlugPrefix(fullSlug, navSlugs) {
|
|
1827
|
+
const normalized = normalizeSlug(fullSlug);
|
|
1828
|
+
if (!normalized) return void 0;
|
|
1829
|
+
for (const navSlug of navSlugs) {
|
|
1830
|
+
if (normalized === navSlug) {
|
|
1831
|
+
return { matchedSlug: navSlug, rest: "" };
|
|
1832
|
+
}
|
|
1833
|
+
if (normalized.startsWith(navSlug + "/")) {
|
|
1834
|
+
return {
|
|
1835
|
+
matchedSlug: navSlug,
|
|
1836
|
+
rest: normalized.slice(navSlug.length + 1)
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return void 0;
|
|
1841
|
+
}
|
|
1842
|
+
function extractSlugFromPathname(pathname, basePath) {
|
|
1843
|
+
if (basePath === "/") {
|
|
1844
|
+
return pathname.replace(/^\//, "");
|
|
1845
|
+
}
|
|
1846
|
+
if (pathname.startsWith(basePath)) {
|
|
1847
|
+
return pathname.slice(basePath.length).replace(/^\//, "");
|
|
1848
|
+
}
|
|
1849
|
+
return pathname.replace(/^\//, "");
|
|
1850
|
+
}
|
|
1851
|
+
function isSlugInSection(item, currentSlug, navSlugs) {
|
|
1852
|
+
const match = matchSlugPrefix(currentSlug, navSlugs);
|
|
1853
|
+
const baseSlug = match?.matchedSlug ?? normalizeSlug(currentSlug);
|
|
1854
|
+
if (normalizeSlug(item.slug) === baseSlug) return true;
|
|
1855
|
+
return item.children?.some((child) => normalizeSlug(child.slug) === baseSlug) ?? false;
|
|
1856
|
+
}
|
|
1857
|
+
function SdkNavigation({
|
|
1858
|
+
navItems,
|
|
1859
|
+
currentSlug,
|
|
1860
|
+
onNavigate,
|
|
1861
|
+
navSlugs
|
|
1862
|
+
}) {
|
|
1863
|
+
return /* @__PURE__ */ jsx(SidebarMenu, { children: navItems.map((item, index) => {
|
|
1864
|
+
if (!item.slug && !item.label) return null;
|
|
1865
|
+
if (!item.slug) {
|
|
1866
|
+
return /* @__PURE__ */ jsx(SidebarGroupLabel, { children: item.label }, item.id ?? `section-${index}`);
|
|
1867
|
+
}
|
|
1868
|
+
const itemSlug = normalizeSlug(item.slug);
|
|
1869
|
+
const isActive = isSlugInSection(item, currentSlug, navSlugs);
|
|
1870
|
+
return /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsxs(
|
|
1871
|
+
SidebarMenuButton,
|
|
1872
|
+
{
|
|
1873
|
+
isActive,
|
|
1874
|
+
onClick: () => onNavigate(itemSlug),
|
|
1875
|
+
children: [
|
|
1876
|
+
item.icon && /* @__PURE__ */ jsx(RepIcon, { name: item.icon }),
|
|
1877
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: item.label })
|
|
1878
|
+
]
|
|
1879
|
+
}
|
|
1880
|
+
) }, item.id ?? itemSlug);
|
|
1881
|
+
}) });
|
|
1882
|
+
}
|
|
1883
|
+
function QuickLinksDropdown({ onNavigate }) {
|
|
1884
|
+
const [open, setOpen] = useState(false);
|
|
1885
|
+
const panelRef = useRef(null);
|
|
1886
|
+
const buttonRef = useRef(null);
|
|
1887
|
+
const close = useCallback(() => setOpen(false), []);
|
|
1888
|
+
useEffect(() => {
|
|
1889
|
+
if (!open) return;
|
|
1890
|
+
const handleMouseDown = (e) => {
|
|
1891
|
+
if (panelRef.current && !panelRef.current.contains(e.target) && buttonRef.current && !buttonRef.current.contains(e.target)) {
|
|
1892
|
+
close();
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
const handleKeyDown = (e) => {
|
|
1896
|
+
if (e.key === "Escape") close();
|
|
1897
|
+
};
|
|
1898
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
1899
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1900
|
+
return () => {
|
|
1901
|
+
document.removeEventListener("mousedown", handleMouseDown);
|
|
1902
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
1903
|
+
};
|
|
1904
|
+
}, [open, close]);
|
|
1905
|
+
const sections = getSystemNavigationBySection();
|
|
1906
|
+
const handleItemClick = (slug) => {
|
|
1907
|
+
onNavigate(slug);
|
|
1908
|
+
close();
|
|
1909
|
+
};
|
|
1910
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
1911
|
+
/* @__PURE__ */ jsx(
|
|
1912
|
+
"button",
|
|
1913
|
+
{
|
|
1914
|
+
ref: buttonRef,
|
|
1915
|
+
type: "button",
|
|
1916
|
+
onClick: () => setOpen((prev) => !prev),
|
|
1917
|
+
className: "flex shrink-0 items-center justify-center rounded-md p-2 text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
1918
|
+
"aria-label": "Quick links",
|
|
1919
|
+
"aria-expanded": open,
|
|
1920
|
+
children: /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faTableCellsLarge, className: "h-4 w-4" })
|
|
1921
|
+
}
|
|
1922
|
+
),
|
|
1923
|
+
open && /* @__PURE__ */ jsx(
|
|
1924
|
+
"div",
|
|
1925
|
+
{
|
|
1926
|
+
ref: panelRef,
|
|
1927
|
+
className: "absolute top-full right-0 z-50 mt-1 w-[700px] max-w-[90vw] overflow-hidden rounded-lg border border-border bg-background shadow-lg",
|
|
1928
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
1929
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b bg-background p-4", children: [
|
|
1930
|
+
/* @__PURE__ */ jsx(
|
|
1931
|
+
FontAwesomeIcon,
|
|
1932
|
+
{
|
|
1933
|
+
icon: faTableCellsLarge,
|
|
1934
|
+
className: "h-5 w-5 text-muted-foreground"
|
|
1935
|
+
}
|
|
1936
|
+
),
|
|
1937
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: "Shortcuts" })
|
|
1938
|
+
] }),
|
|
1939
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-6 bg-muted p-6", children: Object.entries(sections).map(([sectionName, items]) => /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
1940
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold text-foreground", children: sectionName }),
|
|
1941
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-4 gap-2", children: items.map((item) => /* @__PURE__ */ jsxs(
|
|
1942
|
+
"button",
|
|
1943
|
+
{
|
|
1944
|
+
type: "button",
|
|
1945
|
+
onClick: () => handleItemClick(item.slug),
|
|
1946
|
+
className: "flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-sidebar-foreground transition-colors hover:bg-sidebar-primary hover:text-sidebar-primary-foreground",
|
|
1947
|
+
children: [
|
|
1948
|
+
item.icon && /* @__PURE__ */ jsx(
|
|
1949
|
+
RepIcon,
|
|
1950
|
+
{
|
|
1951
|
+
name: item.icon,
|
|
1952
|
+
className: "h-4 w-4 shrink-0 text-muted-foreground"
|
|
1953
|
+
}
|
|
1954
|
+
),
|
|
1955
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: item.label })
|
|
1956
|
+
]
|
|
1957
|
+
},
|
|
1958
|
+
item.slug
|
|
1959
|
+
)) })
|
|
1960
|
+
] }, sectionName)) })
|
|
1961
|
+
] })
|
|
1962
|
+
}
|
|
1963
|
+
)
|
|
1964
|
+
] });
|
|
1965
|
+
}
|
|
1966
|
+
function SdkHeader({
|
|
1967
|
+
tabs,
|
|
1968
|
+
currentSlug,
|
|
1969
|
+
onNavigate,
|
|
1970
|
+
navSlugs
|
|
1971
|
+
}) {
|
|
1972
|
+
const sidebar = useSidebar();
|
|
1973
|
+
const themeMode = useThemeMode();
|
|
1974
|
+
const match = matchSlugPrefix(currentSlug, navSlugs);
|
|
1975
|
+
const baseSlug = match?.matchedSlug ?? normalizeSlug(currentSlug);
|
|
1976
|
+
const themeIcon = themeMode.mode === "dark" ? faMoon : faSun;
|
|
1977
|
+
return /* @__PURE__ */ jsxs("header", { className: "flex h-[52px] shrink-0 items-center gap-2 bg-sidebar px-6", children: [
|
|
1978
|
+
sidebar.isMobile && /* @__PURE__ */ jsx(
|
|
1979
|
+
"button",
|
|
1980
|
+
{
|
|
1981
|
+
type: "button",
|
|
1982
|
+
onClick: sidebar.toggleSidebar,
|
|
1983
|
+
className: "mr-2 flex shrink-0 items-center justify-center rounded-md p-2 text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
1984
|
+
"aria-label": "Toggle sidebar",
|
|
1985
|
+
children: /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faBars, className: "size-5" })
|
|
1986
|
+
}
|
|
1987
|
+
),
|
|
1988
|
+
/* @__PURE__ */ jsx("nav", { className: "scrollbar-none flex flex-1 items-center gap-1 overflow-x-auto", children: tabs.map((tab) => {
|
|
1989
|
+
const tabSlug = normalizeSlug(tab.slug);
|
|
1990
|
+
if (!tabSlug) return null;
|
|
1991
|
+
const isActive = tabSlug === baseSlug;
|
|
1992
|
+
return /* @__PURE__ */ jsx(
|
|
1993
|
+
"button",
|
|
1994
|
+
{
|
|
1995
|
+
type: "button",
|
|
1996
|
+
onClick: () => onNavigate(tabSlug),
|
|
1997
|
+
className: `border-b-2 px-4 py-3 text-sm font-medium whitespace-nowrap transition-colors ${isActive ? "border-primary text-foreground" : "border-transparent text-muted-foreground hover:border-border hover:text-foreground"}`,
|
|
1998
|
+
children: tab.label
|
|
1999
|
+
},
|
|
2000
|
+
tab.id ?? tabSlug
|
|
2001
|
+
);
|
|
2002
|
+
}) }),
|
|
2003
|
+
/* @__PURE__ */ jsx(QuickLinksDropdown, { onNavigate }),
|
|
2004
|
+
/* @__PURE__ */ jsx(
|
|
2005
|
+
"button",
|
|
2006
|
+
{
|
|
2007
|
+
type: "button",
|
|
2008
|
+
onClick: themeMode.cycleMode,
|
|
2009
|
+
className: "ml-2 flex shrink-0 items-center justify-center rounded-md p-2 text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
2010
|
+
"aria-label": `Switch theme (current: ${themeMode.mode})`,
|
|
2011
|
+
children: /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: themeIcon, className: "size-3" })
|
|
2012
|
+
}
|
|
2013
|
+
)
|
|
2014
|
+
] });
|
|
2015
|
+
}
|
|
2016
|
+
function WidgetRenderer({ widget, index }) {
|
|
2017
|
+
const registry = useRegistry();
|
|
2018
|
+
const Component = registry[widget.type];
|
|
2019
|
+
if (!Component) {
|
|
2020
|
+
console.warn(
|
|
2021
|
+
`[BuilderScreenView] Widget type "${String(widget.type)}" not found in registry`
|
|
2022
|
+
);
|
|
2023
|
+
return null;
|
|
2024
|
+
}
|
|
2025
|
+
if (widget.dataSource) {
|
|
2026
|
+
return /* @__PURE__ */ jsx("div", { className: "h-full w-full overflow-x-hidden", children: /* @__PURE__ */ jsx(DataAwareWidget, { widget, Component }) }, widget.id ?? index);
|
|
2027
|
+
}
|
|
2028
|
+
return /* @__PURE__ */ jsx("div", { className: "h-full w-full overflow-x-hidden", children: /* @__PURE__ */ jsx(Component, { ...widget.props }) }, widget.id ?? index);
|
|
2029
|
+
}
|
|
2030
|
+
function BuilderScreenViewImpl({ screen, className }) {
|
|
2031
|
+
const widgets = screen.component_tree;
|
|
2032
|
+
if (!widgets || widgets.length === 0) {
|
|
2033
|
+
return /* @__PURE__ */ jsx("div", { className: className ?? "h-full w-full", children: /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsx("p", { children: "This screen has no content yet." }) }) });
|
|
2034
|
+
}
|
|
2035
|
+
return /* @__PURE__ */ jsx("div", { className: className ?? "h-full w-full", children: widgets.map((widget, index) => {
|
|
2036
|
+
if (!widget) return null;
|
|
2037
|
+
return /* @__PURE__ */ jsx(
|
|
2038
|
+
WidgetRenderer,
|
|
2039
|
+
{
|
|
2040
|
+
widget,
|
|
2041
|
+
index
|
|
2042
|
+
},
|
|
2043
|
+
widget.id ?? index
|
|
2044
|
+
);
|
|
2045
|
+
}) });
|
|
2046
|
+
}
|
|
2047
|
+
var BuilderScreenView = memo(BuilderScreenViewImpl);
|
|
2048
|
+
var SYSTEM_SLUG_SCREEN_MAP = {
|
|
2049
|
+
messages: MessagingScreen,
|
|
2050
|
+
contacts: ContactsScreen,
|
|
2051
|
+
shop: OrdersScreen,
|
|
2052
|
+
customers: CustomersScreen,
|
|
2053
|
+
products: ProductsScreen
|
|
2054
|
+
};
|
|
2055
|
+
function PageRouter({
|
|
2056
|
+
currentSlug,
|
|
2057
|
+
currentNavItem,
|
|
2058
|
+
customPages,
|
|
2059
|
+
screens,
|
|
2060
|
+
baseSlug,
|
|
2061
|
+
restParams
|
|
2062
|
+
}) {
|
|
2063
|
+
const screenById = useMemo(() => {
|
|
2064
|
+
if (!screens || screens.length === 0) return void 0;
|
|
2065
|
+
return new Map(screens.map((s) => [s.id, s]));
|
|
2066
|
+
}, [screens]);
|
|
2067
|
+
const screenBySlug = useMemo(() => {
|
|
2068
|
+
if (!screens || screens.length === 0) return void 0;
|
|
2069
|
+
return new Map(screens.filter((s) => s.slug).map((s) => [s.slug, s]));
|
|
2070
|
+
}, [screens]);
|
|
2071
|
+
const builderScreen = useMemo(() => {
|
|
2072
|
+
if (currentNavItem?.screen_id && screenById) {
|
|
2073
|
+
const byId = screenById.get(currentNavItem.screen_id);
|
|
2074
|
+
if (byId) return byId;
|
|
2075
|
+
}
|
|
2076
|
+
if (screenBySlug) {
|
|
2077
|
+
return screenBySlug.get(currentSlug) ?? screenBySlug.get(baseSlug) ?? void 0;
|
|
2078
|
+
}
|
|
2079
|
+
return void 0;
|
|
2080
|
+
}, [
|
|
2081
|
+
currentNavItem?.screen_id,
|
|
2082
|
+
screenById,
|
|
2083
|
+
screenBySlug,
|
|
2084
|
+
currentSlug,
|
|
2085
|
+
baseSlug
|
|
2086
|
+
]);
|
|
2087
|
+
const SystemScreen = SYSTEM_SLUG_SCREEN_MAP[baseSlug];
|
|
2088
|
+
if (SystemScreen) {
|
|
2089
|
+
return /* @__PURE__ */ jsx(SystemScreen, {});
|
|
2090
|
+
}
|
|
2091
|
+
if (isSystemNavigationItem(baseSlug)) {
|
|
2092
|
+
return /* @__PURE__ */ jsx(CoreScreenPlaceholder, { name: currentNavItem?.label ?? baseSlug });
|
|
2093
|
+
}
|
|
2094
|
+
const ExactCustomPage = customPages?.[currentSlug];
|
|
2095
|
+
if (ExactCustomPage) {
|
|
2096
|
+
return /* @__PURE__ */ jsx(ExactCustomPage, { slug: currentSlug, params: restParams });
|
|
2097
|
+
}
|
|
2098
|
+
if (baseSlug !== currentSlug) {
|
|
2099
|
+
const PrefixCustomPage = customPages?.[baseSlug];
|
|
2100
|
+
if (PrefixCustomPage) {
|
|
2101
|
+
return /* @__PURE__ */ jsx(PrefixCustomPage, { slug: currentSlug, params: restParams });
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
if (builderScreen) {
|
|
2105
|
+
return /* @__PURE__ */ jsx(BuilderScreenView, { screen: builderScreen });
|
|
2106
|
+
}
|
|
2107
|
+
return /* @__PURE__ */ jsx(CoreScreenPlaceholder, { name: currentNavItem?.label ?? currentSlug });
|
|
2108
|
+
}
|
|
2109
|
+
var AppNavigationContext = createContext(
|
|
2110
|
+
null
|
|
2111
|
+
);
|
|
2112
|
+
function AppNavigationProvider({
|
|
2113
|
+
currentSlug,
|
|
2114
|
+
basePath,
|
|
2115
|
+
navigate,
|
|
2116
|
+
children
|
|
2117
|
+
}) {
|
|
2118
|
+
const buildHref = useMemo(() => {
|
|
2119
|
+
return (slug) => {
|
|
2120
|
+
if (basePath === "/") return `/${slug}`;
|
|
2121
|
+
return `${basePath}/${slug}`;
|
|
2122
|
+
};
|
|
2123
|
+
}, [basePath]);
|
|
2124
|
+
const value = useMemo(
|
|
2125
|
+
() => ({ currentSlug, basePath, navigate, buildHref }),
|
|
2126
|
+
[currentSlug, basePath, navigate, buildHref]
|
|
2127
|
+
);
|
|
2128
|
+
return /* @__PURE__ */ jsx(AppNavigationContext.Provider, { value, children });
|
|
2129
|
+
}
|
|
2130
|
+
function useAppNavigation() {
|
|
2131
|
+
const ctx = useContext(AppNavigationContext);
|
|
2132
|
+
if (!ctx) {
|
|
2133
|
+
throw new Error(
|
|
2134
|
+
"useAppNavigation must be used within an <AppShell> or <AppNavigationProvider>"
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
return ctx;
|
|
2138
|
+
}
|
|
2139
|
+
var THEME_STORAGE_KEY = "rep-theme-mode";
|
|
2140
|
+
var DEFAULT_NAVIGATION = [
|
|
2141
|
+
{ label: "We Commerce", children: [] },
|
|
2142
|
+
{ slug: "shop", label: "Shop", icon: "store", children: [] },
|
|
2143
|
+
{ slug: "account", label: "Account", icon: "user-gear", children: [] },
|
|
2144
|
+
{ slug: "messages", label: "Messaging", icon: "comment", children: [] },
|
|
2145
|
+
{ label: "Marketing Assets", children: [] },
|
|
2146
|
+
{
|
|
2147
|
+
slug: "share/products",
|
|
2148
|
+
label: "Products",
|
|
2149
|
+
icon: "boxes-stacked",
|
|
2150
|
+
children: []
|
|
2151
|
+
}
|
|
2152
|
+
];
|
|
2153
|
+
function getInitialThemeMode() {
|
|
2154
|
+
if (typeof window === "undefined") return "light";
|
|
2155
|
+
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
|
2156
|
+
if (stored === "light" || stored === "dark") return stored;
|
|
2157
|
+
return "light";
|
|
2158
|
+
}
|
|
2159
|
+
function findFirstNavigableSlug(items) {
|
|
2160
|
+
for (const item of items) {
|
|
2161
|
+
if (item.slug) return normalizeSlug(item.slug);
|
|
2162
|
+
for (const child of item.children ?? []) {
|
|
2163
|
+
if (child.slug) return normalizeSlug(child.slug);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
return "";
|
|
2167
|
+
}
|
|
2168
|
+
function findCurrentSection(items, slug) {
|
|
2169
|
+
const normalized = normalizeSlug(slug);
|
|
2170
|
+
for (const item of items) {
|
|
2171
|
+
if (normalizeSlug(item.slug) === normalized) return item;
|
|
2172
|
+
if (item.children?.some((child) => normalizeSlug(child.slug) === normalized)) {
|
|
2173
|
+
return item;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return void 0;
|
|
2177
|
+
}
|
|
2178
|
+
function findNavItem(items, slug) {
|
|
2179
|
+
const normalized = normalizeSlug(slug);
|
|
2180
|
+
for (const item of items) {
|
|
2181
|
+
if (normalizeSlug(item.slug) === normalized) return item;
|
|
2182
|
+
for (const child of item.children ?? []) {
|
|
2183
|
+
if (normalizeSlug(child.slug) === normalized) return child;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
return void 0;
|
|
2187
|
+
}
|
|
2188
|
+
function AppShell({
|
|
2189
|
+
appData: appDataProp,
|
|
2190
|
+
navigation: navigationProp,
|
|
2191
|
+
customPages,
|
|
2192
|
+
basePath = "/",
|
|
2193
|
+
currentSlug: controlledSlug,
|
|
2194
|
+
onNavigate: onNavigateProp,
|
|
2195
|
+
sidebarHeader,
|
|
2196
|
+
sidebarFooter,
|
|
2197
|
+
children
|
|
2198
|
+
}) {
|
|
2199
|
+
const normalizedBasePath = useMemo(() => {
|
|
2200
|
+
const stripped = basePath.replace(/^\/|\/$/g, "");
|
|
2201
|
+
return stripped ? `/${stripped}` : "/";
|
|
2202
|
+
}, [basePath]);
|
|
2203
|
+
const { data: fetchedAppData, isLoading: isLoading2 } = useFluidApp({
|
|
2204
|
+
enabled: !appDataProp
|
|
2205
|
+
});
|
|
2206
|
+
const appData = appDataProp ?? fetchedAppData;
|
|
2207
|
+
const activeTheme = useMemo(() => {
|
|
2208
|
+
if (!appData?.profile?.themes?.length) return void 0;
|
|
2209
|
+
const themes = appData.profile.themes;
|
|
2210
|
+
const activeId = appData.profile.activeThemeId;
|
|
2211
|
+
return activeId ? themes.find((t) => t.id === activeId) ?? themes[0] : themes[0];
|
|
2212
|
+
}, [appData?.profile?.themes, appData?.profile?.activeThemeId]);
|
|
2213
|
+
useEffect(() => {
|
|
2214
|
+
if (!activeTheme) return;
|
|
2215
|
+
const resolved = resolveTheme(activeTheme);
|
|
2216
|
+
applyTheme(resolved);
|
|
2217
|
+
return () => {
|
|
2218
|
+
removeAllThemes();
|
|
2219
|
+
};
|
|
2220
|
+
}, [activeTheme]);
|
|
2221
|
+
const navItems = useMemo(() => {
|
|
2222
|
+
if (navigationProp) return navigationProp;
|
|
2223
|
+
const profileNav = appData?.profile?.navigation?.navigation_items;
|
|
2224
|
+
if (profileNav && profileNav.length > 0) return profileNav;
|
|
2225
|
+
return DEFAULT_NAVIGATION;
|
|
2226
|
+
}, [navigationProp, appData?.profile?.navigation?.navigation_items]);
|
|
2227
|
+
const screens = appData?.screens;
|
|
2228
|
+
const navSlugs = useMemo(() => collectNavSlugs(navItems), [navItems]);
|
|
2229
|
+
const [themeMode, setThemeMode] = useState(getInitialThemeMode);
|
|
2230
|
+
const handleThemeModeChange = useCallback((mode) => {
|
|
2231
|
+
setThemeMode(mode);
|
|
2232
|
+
if (typeof window !== "undefined") {
|
|
2233
|
+
localStorage.setItem(THEME_STORAGE_KEY, mode);
|
|
2234
|
+
}
|
|
2235
|
+
}, []);
|
|
2236
|
+
const [pathSlug, setPathSlug] = useState(() => {
|
|
2237
|
+
if (typeof window === "undefined") return "";
|
|
2238
|
+
return extractSlugFromPathname(
|
|
2239
|
+
window.location.pathname,
|
|
2240
|
+
normalizedBasePath
|
|
2241
|
+
);
|
|
2242
|
+
});
|
|
2243
|
+
useEffect(() => {
|
|
2244
|
+
if (controlledSlug !== void 0) return;
|
|
2245
|
+
if (typeof window === "undefined") return;
|
|
2246
|
+
const currentPath = extractSlugFromPathname(
|
|
2247
|
+
window.location.pathname,
|
|
2248
|
+
normalizedBasePath
|
|
2249
|
+
);
|
|
2250
|
+
if (!currentPath) {
|
|
2251
|
+
const firstSlug = findFirstNavigableSlug(navItems);
|
|
2252
|
+
if (firstSlug) {
|
|
2253
|
+
const targetPath = normalizedBasePath === "/" ? `/${firstSlug}` : `${normalizedBasePath}/${firstSlug}`;
|
|
2254
|
+
history.replaceState(null, "", targetPath);
|
|
2255
|
+
setPathSlug(firstSlug);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}, [navItems, controlledSlug, normalizedBasePath]);
|
|
2259
|
+
useEffect(() => {
|
|
2260
|
+
if (controlledSlug !== void 0) return;
|
|
2261
|
+
const handlePopState = () => {
|
|
2262
|
+
const slug = extractSlugFromPathname(
|
|
2263
|
+
window.location.pathname,
|
|
2264
|
+
normalizedBasePath
|
|
2265
|
+
);
|
|
2266
|
+
setPathSlug(slug);
|
|
2267
|
+
};
|
|
2268
|
+
window.addEventListener("popstate", handlePopState);
|
|
2269
|
+
return () => window.removeEventListener("popstate", handlePopState);
|
|
2270
|
+
}, [controlledSlug, normalizedBasePath]);
|
|
2271
|
+
const activeSlug = controlledSlug ?? pathSlug;
|
|
2272
|
+
const handleNavigate = useCallback(
|
|
2273
|
+
(slug) => {
|
|
2274
|
+
if (onNavigateProp) {
|
|
2275
|
+
onNavigateProp(slug);
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
const targetPath = normalizedBasePath === "/" ? `/${slug}` : `${normalizedBasePath}/${slug}`;
|
|
2279
|
+
history.pushState(null, "", targetPath);
|
|
2280
|
+
setPathSlug(slug);
|
|
2281
|
+
},
|
|
2282
|
+
[onNavigateProp, normalizedBasePath]
|
|
2283
|
+
);
|
|
2284
|
+
const slugMatch = useMemo(
|
|
2285
|
+
() => matchSlugPrefix(activeSlug, navSlugs),
|
|
2286
|
+
[activeSlug, navSlugs]
|
|
2287
|
+
);
|
|
2288
|
+
const baseSlug = slugMatch?.matchedSlug ?? normalizeSlug(activeSlug);
|
|
2289
|
+
const restParams = slugMatch?.rest ?? "";
|
|
2290
|
+
const currentSection = findCurrentSection(navItems, baseSlug);
|
|
2291
|
+
const secondLevelTabs = currentSection?.children ?? [];
|
|
2292
|
+
const currentNavItem = findNavItem(navItems, baseSlug);
|
|
2293
|
+
const content = typeof children === "function" ? children({ currentSlug: activeSlug, currentNavItem }) : children ?? /* @__PURE__ */ jsx(
|
|
2294
|
+
PageRouter,
|
|
2295
|
+
{
|
|
2296
|
+
currentSlug: activeSlug,
|
|
2297
|
+
currentNavItem,
|
|
2298
|
+
customPages,
|
|
2299
|
+
screens,
|
|
2300
|
+
baseSlug,
|
|
2301
|
+
restParams
|
|
2302
|
+
}
|
|
2303
|
+
);
|
|
2304
|
+
if (isLoading2 && !appData) {
|
|
2305
|
+
return /* @__PURE__ */ jsx(AppShellLoading, {});
|
|
2306
|
+
}
|
|
2307
|
+
return /* @__PURE__ */ jsx(
|
|
2308
|
+
ThemeModeProvider,
|
|
2309
|
+
{
|
|
2310
|
+
mode: themeMode,
|
|
2311
|
+
onModeChange: handleThemeModeChange,
|
|
2312
|
+
autoModeEnabled: false,
|
|
2313
|
+
children: /* @__PURE__ */ jsx(
|
|
2314
|
+
AppNavigationProvider,
|
|
2315
|
+
{
|
|
2316
|
+
currentSlug: activeSlug,
|
|
2317
|
+
basePath: normalizedBasePath,
|
|
2318
|
+
navigate: handleNavigate,
|
|
2319
|
+
children: /* @__PURE__ */ jsx(
|
|
2320
|
+
"div",
|
|
2321
|
+
{
|
|
2322
|
+
"data-theme": activeTheme?.id,
|
|
2323
|
+
"data-theme-mode": themeMode === "auto" ? void 0 : themeMode,
|
|
2324
|
+
children: /* @__PURE__ */ jsx(
|
|
2325
|
+
AppShellLayout,
|
|
2326
|
+
{
|
|
2327
|
+
sidebarContent: /* @__PURE__ */ jsx(
|
|
2328
|
+
SdkNavigation,
|
|
2329
|
+
{
|
|
2330
|
+
navItems,
|
|
2331
|
+
currentSlug: activeSlug,
|
|
2332
|
+
onNavigate: handleNavigate,
|
|
2333
|
+
navSlugs
|
|
2334
|
+
}
|
|
2335
|
+
),
|
|
2336
|
+
headerContent: /* @__PURE__ */ jsx(
|
|
2337
|
+
SdkHeader,
|
|
2338
|
+
{
|
|
2339
|
+
tabs: secondLevelTabs,
|
|
2340
|
+
currentSlug: activeSlug,
|
|
2341
|
+
onNavigate: handleNavigate,
|
|
2342
|
+
navSlugs
|
|
2343
|
+
}
|
|
2344
|
+
),
|
|
2345
|
+
sidebarHeader,
|
|
2346
|
+
sidebarFooter,
|
|
2347
|
+
children: content
|
|
2348
|
+
}
|
|
2349
|
+
)
|
|
2350
|
+
}
|
|
2351
|
+
)
|
|
2352
|
+
}
|
|
2353
|
+
)
|
|
2354
|
+
}
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2357
|
+
var AppLink = forwardRef(
|
|
2358
|
+
function AppLink2({ to, onClick, children, ...rest }, ref) {
|
|
2359
|
+
const { navigate, buildHref } = useAppNavigation();
|
|
2360
|
+
const handleClick = (e) => {
|
|
2361
|
+
onClick?.(e);
|
|
2362
|
+
if (e.defaultPrevented) return;
|
|
2363
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
2364
|
+
if (e.button !== 0) return;
|
|
2365
|
+
if (rest.target && rest.target !== "_self") return;
|
|
2366
|
+
e.preventDefault();
|
|
2367
|
+
navigate(to);
|
|
2368
|
+
};
|
|
2369
|
+
return /* @__PURE__ */ jsx("a", { ref, href: buildHref(to), onClick: handleClick, ...rest, children });
|
|
2370
|
+
}
|
|
2371
|
+
);
|
|
2372
|
+
var export_DEFAULT_COLORS = themes_exports.DEFAULT_COLORS;
|
|
2373
|
+
var export_DEFAULT_FONT_FAMILIES = themes_exports.DEFAULT_FONT_FAMILIES;
|
|
2374
|
+
var export_DEFAULT_FONT_SIZES = themes_exports.DEFAULT_FONT_SIZES;
|
|
2375
|
+
var export_DEFAULT_RADII = themes_exports.DEFAULT_RADII;
|
|
2376
|
+
var export_DEFAULT_SPACING = themes_exports.DEFAULT_SPACING;
|
|
2377
|
+
var export_DEFAULT_THEME_ID = themes_exports.DEFAULT_THEME_ID;
|
|
2378
|
+
var export_DEFAULT_THEME_NAME = themes_exports.DEFAULT_THEME_NAME;
|
|
2379
|
+
var export_FONT_FAMILY_KEYS = themes_exports.FONT_FAMILY_KEYS;
|
|
2380
|
+
var export_FONT_SIZE_KEYS = themes_exports.FONT_SIZE_KEYS;
|
|
2381
|
+
var export_RADIUS_KEYS = themes_exports.RADIUS_KEYS;
|
|
2382
|
+
var export_SEMANTIC_COLOR_NAMES = themes_exports.SEMANTIC_COLOR_NAMES;
|
|
2383
|
+
var export_SHADE_STEPS = themes_exports.SHADE_STEPS;
|
|
2384
|
+
var export_applyTheme = themes_exports.applyTheme;
|
|
2385
|
+
var export_deriveDarkVariant = themes_exports.deriveDarkVariant;
|
|
2386
|
+
var export_deserialiseTheme = themes_exports.deserialiseTheme;
|
|
2387
|
+
var export_generateShades = themes_exports.generateShades;
|
|
2388
|
+
var export_generateThemeCSS = themes_exports.generateThemeCSS;
|
|
2389
|
+
var export_getDefaultThemeDefinition = themes_exports.getDefaultThemeDefinition;
|
|
2390
|
+
var export_getForegroundColor = themes_exports.getForegroundColor;
|
|
2391
|
+
var export_mergeDarkOverrides = themes_exports.mergeDarkOverrides;
|
|
2392
|
+
var export_parseColor = themes_exports.parseColor;
|
|
2393
|
+
var export_removeAllThemes = themes_exports.removeAllThemes;
|
|
2394
|
+
var export_removeTheme = themes_exports.removeTheme;
|
|
2395
|
+
var export_resolveTheme = themes_exports.resolveTheme;
|
|
2396
|
+
var export_serialiseTheme = themes_exports.serialiseTheme;
|
|
2152
2397
|
|
|
2153
|
-
export { ACTIVITY_SLUGS,
|
|
2398
|
+
export { ACTIVITY_SLUGS, APP_DATA_QUERY_KEY, AppLink, AppNavigationProvider, AppShell, AuthError, AuthLoading, BuilderScreenView, CORE_PAGE_IDS, CURRENT_REP_QUERY_KEY, export_DEFAULT_COLORS as DEFAULT_COLORS, export_DEFAULT_FONT_FAMILIES as DEFAULT_FONT_FAMILIES, export_DEFAULT_FONT_SIZES as DEFAULT_FONT_SIZES, export_DEFAULT_RADII as DEFAULT_RADII, export_DEFAULT_SPACING as DEFAULT_SPACING, export_DEFAULT_THEME_ID as DEFAULT_THEME_ID, export_DEFAULT_THEME_NAME as DEFAULT_THEME_NAME, export_FONT_FAMILY_KEYS as FONT_FAMILY_KEYS, export_FONT_SIZE_KEYS as FONT_SIZE_KEYS, PAGE_CATEGORIES, PERMISSIONS_QUERY_KEY, PROFILE_QUERY_KEY, PageRouter, PageTemplateProvider, PageTemplateRegistry, QuickLinksDropdown, export_RADIUS_KEYS as RADIUS_KEYS, RequireAuth, export_SEMANTIC_COLOR_NAMES as SEMANTIC_COLOR_NAMES, export_SHADE_STEPS as SHADE_STEPS, SdkHeader, SdkNavigation, export_applyTheme as applyTheme, collectNavSlugs, export_deriveDarkVariant as deriveDarkVariant, export_deserialiseTheme as deserialiseTheme, extractSlugFromPathname, export_generateShades as generateShades, export_generateThemeCSS as generateThemeCSS, getAvailablePageTemplates, getCorePageTemplates, export_getDefaultThemeDefinition as getDefaultThemeDefinition, export_getForegroundColor as getForegroundColor, getOptionalPageTemplates, getProperty, hasData, isActivitySlug, isContactStatus, isErrorResult, isIdle, isLoading, isSlugInSection, matchSlugPrefix, export_mergeDarkOverrides as mergeDarkOverrides, export_parseColor as parseColor, export_removeAllThemes as removeAllThemes, export_removeTheme as removeTheme, resolveNavigationPages, export_resolveTheme as resolveTheme, screenPropertySchemas, selectProperty, export_serialiseTheme as serialiseTheme, useActivities, useAppNavigation, useCalendarEvents, useCatchUps, useContact, useContacts, useConversationMessages, useConversations, useCurrentRep, useFluidApp, useFluidAuth, useFluidPermissions, useFluidProfile, useFluidTheme, useMySite, usePageTemplates, useResolvedPages, useTodos, validateNavigationPages };
|
|
2154
2399
|
//# sourceMappingURL=index.js.map
|
|
2155
2400
|
//# sourceMappingURL=index.js.map
|