dynim-react 1.0.41 → 1.0.43
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/DynimProvider.d.ts.map +1 -1
- package/dist/DynimProvider.js +41 -11
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DynimProvider.d.ts","sourceRoot":"","sources":["../src/DynimProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAc,EAQZ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAKV,WAAW,EAEZ,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;IACzC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,qBAAqB;IACrB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,0CAA0C;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,yBAAyB;IACzB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,oCAAoC;IACpC,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,yDAAyD;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,cAAc,EAAE,OAAO,CAAC;IACxB,gCAAgC;IAChC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAID,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,MAAW,GACZ,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAmalC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
|
package/dist/DynimProvider.js
CHANGED
|
@@ -9,7 +9,7 @@ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-run
|
|
|
9
9
|
*/
|
|
10
10
|
import React, { createContext, useContext, useEffect, useRef, useCallback, useMemo, useState, } from 'react';
|
|
11
11
|
import ReactDOM from 'react-dom';
|
|
12
|
-
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, BundleNotFoundError, } from 'dynim-core';
|
|
12
|
+
import { createBuilderClient, createBuilder, createCodeClient, createBundleLoader, BundleNotFoundError, BundleAuthError, } from 'dynim-core';
|
|
13
13
|
import { createSharedContext, updateSharedContext, isSharedContextReady } from './inference/sharedContext';
|
|
14
14
|
import { generateThemeCSS } from './theme';
|
|
15
15
|
const DynimContext = createContext(null);
|
|
@@ -51,6 +51,8 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
51
51
|
// Cached auth token
|
|
52
52
|
const cachedTokenRef = useRef(null);
|
|
53
53
|
const tokenPromiseRef = useRef(null);
|
|
54
|
+
// Flag to skip stale sessionToken from config after 401
|
|
55
|
+
const sessionTokenInvalidRef = useRef(false);
|
|
54
56
|
// Bundle load signal
|
|
55
57
|
const [bundleLoadSignal, setBundleLoadSignal] = useState(0);
|
|
56
58
|
const pendingBundleProjectIdRef = useRef(null);
|
|
@@ -89,13 +91,13 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
89
91
|
// Get auth token
|
|
90
92
|
const getAuthToken = useCallback(async () => {
|
|
91
93
|
const { sessionToken, getSession } = configRef.current;
|
|
92
|
-
// Fast path:
|
|
93
|
-
if (sessionToken) {
|
|
94
|
-
return sessionToken;
|
|
95
|
-
}
|
|
96
|
-
// Fast path: return cached token
|
|
94
|
+
// Fast path: return cached token (fresh from getSession)
|
|
97
95
|
if (cachedTokenRef.current)
|
|
98
96
|
return cachedTokenRef.current;
|
|
97
|
+
// Fast path: static token from config (skip if known invalid)
|
|
98
|
+
if (sessionToken && !sessionTokenInvalidRef.current) {
|
|
99
|
+
return sessionToken;
|
|
100
|
+
}
|
|
99
101
|
// Reuse in-flight promise if one exists
|
|
100
102
|
if (tokenPromiseRef.current)
|
|
101
103
|
return tokenPromiseRef.current;
|
|
@@ -204,6 +206,35 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
204
206
|
setIsBundleLoaded(false);
|
|
205
207
|
return;
|
|
206
208
|
}
|
|
209
|
+
// 401 = token expired - refresh via getSession and retry
|
|
210
|
+
if (error instanceof BundleAuthError) {
|
|
211
|
+
cachedTokenRef.current = null; // Clear stale token
|
|
212
|
+
sessionTokenInvalidRef.current = true; // Skip config sessionToken on retry
|
|
213
|
+
const { getSession } = configRef.current;
|
|
214
|
+
if (getSession) {
|
|
215
|
+
try {
|
|
216
|
+
const session = await getSession();
|
|
217
|
+
cachedTokenRef.current = session.token;
|
|
218
|
+
// Retry with fresh token
|
|
219
|
+
const { App, cleanup } = await loader.load(bundleUrl);
|
|
220
|
+
setTenantApp(() => App);
|
|
221
|
+
setIsBundleLoaded(true);
|
|
222
|
+
cleanup();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
catch (retryError) {
|
|
226
|
+
if (retryError instanceof BundleNotFoundError) {
|
|
227
|
+
setTenantApp(null);
|
|
228
|
+
setIsBundleLoaded(false);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// Retry also failed - show children
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
setTenantApp(null);
|
|
235
|
+
setIsBundleLoaded(false);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
207
238
|
setBundleError(error);
|
|
208
239
|
}
|
|
209
240
|
finally {
|
|
@@ -242,15 +273,14 @@ export function DynimProvider({ children, config = {}, }) {
|
|
|
242
273
|
console.warn('[DynimProvider] Failed to fetch theme:', error);
|
|
243
274
|
}
|
|
244
275
|
}, [getAuthToken]);
|
|
245
|
-
// Auto-load saved bundle on mount if
|
|
246
|
-
// This avoids HTTP calls (getSession) while still loading saved bundles
|
|
276
|
+
// Auto-load saved bundle on mount if auth is available
|
|
247
277
|
useEffect(() => {
|
|
248
278
|
if (hasAttemptedInitialLoadRef.current)
|
|
249
279
|
return;
|
|
250
280
|
hasAttemptedInitialLoadRef.current = true;
|
|
251
|
-
const { sessionToken } = configRef.current;
|
|
252
|
-
// No
|
|
253
|
-
if (!sessionToken) {
|
|
281
|
+
const { sessionToken, getSession } = configRef.current;
|
|
282
|
+
// No auth configured = skip bundle load
|
|
283
|
+
if (!sessionToken && !getSession) {
|
|
254
284
|
setIsInitialLoadComplete(true);
|
|
255
285
|
return;
|
|
256
286
|
}
|