dynim-react 1.0.26 → 1.0.27
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InferenceProvider.d.ts","sourceRoot":"","sources":["../../src/inference/InferenceProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"InferenceProvider.d.ts","sourceRoot":"","sources":["../../src/inference/InferenceProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAgC,MAAM,SAAS,CAAC;AAkFpF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAmB,EACnB,OAAO,EACP,MAAM,EACN,QAAQ,GACT,EAAE,sBAAsB,GAAG,GAAG,CAAC,OAAO,CA0LtC;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useCallback
|
|
2
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Default loading component shown while bundle is loading
|
|
5
5
|
*/
|
|
@@ -25,39 +25,17 @@ function DefaultErrorBanner({ error }) {
|
|
|
25
25
|
}, children: [_jsx("strong", { children: "Customization Error:" }), " ", error.message] }));
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Loads a bundle module via fetch and dynamic import
|
|
29
|
+
* Uses blob URL to allow importing fetched JavaScript as an ES module
|
|
29
30
|
*/
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Check if script already exists
|
|
39
|
-
const existingScript = document.querySelector(`script[src="${url}"]`);
|
|
40
|
-
if (existingScript) {
|
|
41
|
-
resolve();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const script = document.createElement('script');
|
|
45
|
-
script.src = url;
|
|
46
|
-
script.async = true;
|
|
47
|
-
script.onload = () => resolve();
|
|
48
|
-
script.onerror = () => reject(new Error(`Failed to load bundle from ${url}`));
|
|
49
|
-
document.head.appendChild(script);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Loads a script from a URL with authentication and returns a promise
|
|
54
|
-
*/
|
|
55
|
-
async function loadScriptWithAuth(url, token) {
|
|
56
|
-
const response = await fetch(url, {
|
|
57
|
-
headers: {
|
|
58
|
-
Authorization: `Bearer ${token}`,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
31
|
+
async function loadBundleModule(url, token) {
|
|
32
|
+
const headers = {
|
|
33
|
+
Accept: 'application/javascript',
|
|
34
|
+
};
|
|
35
|
+
if (token) {
|
|
36
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
37
|
+
}
|
|
38
|
+
const response = await fetch(url, { headers });
|
|
61
39
|
if (!response.ok) {
|
|
62
40
|
if (response.status === 401) {
|
|
63
41
|
throw new Error('Bundle token is invalid or expired');
|
|
@@ -67,27 +45,20 @@ async function loadScriptWithAuth(url, token) {
|
|
|
67
45
|
}
|
|
68
46
|
throw new Error(`Failed to load bundle: ${response.status} ${response.statusText}`);
|
|
69
47
|
}
|
|
70
|
-
const
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
function removeScript(url) {
|
|
81
|
-
// Try src attribute first (script tag injection)
|
|
82
|
-
let script = document.querySelector(`script[src="${url}"]`);
|
|
83
|
-
if (script) {
|
|
84
|
-
script.remove();
|
|
85
|
-
return;
|
|
48
|
+
const code = await response.text();
|
|
49
|
+
// Create blob URL for dynamic import
|
|
50
|
+
const blob = new Blob([code], { type: 'application/javascript' });
|
|
51
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
52
|
+
try {
|
|
53
|
+
const module = await import(/* @vite-ignore */ blobUrl);
|
|
54
|
+
return {
|
|
55
|
+
App: module.App || module.default,
|
|
56
|
+
cleanup: () => URL.revokeObjectURL(blobUrl),
|
|
57
|
+
};
|
|
86
58
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
script.remove();
|
|
59
|
+
catch (err) {
|
|
60
|
+
URL.revokeObjectURL(blobUrl);
|
|
61
|
+
throw err;
|
|
91
62
|
}
|
|
92
63
|
}
|
|
93
64
|
/**
|
|
@@ -115,7 +86,7 @@ export function InferenceProvider({ tenantId, bundleUrl, bundleToken, checkCusto
|
|
|
115
86
|
error: null,
|
|
116
87
|
currentTenantId: null,
|
|
117
88
|
});
|
|
118
|
-
const
|
|
89
|
+
const [bundleModule, setBundleModule] = useState(null);
|
|
119
90
|
/**
|
|
120
91
|
* Resolves the bundle URL for a given tenant ID
|
|
121
92
|
*/
|
|
@@ -127,19 +98,14 @@ export function InferenceProvider({ tenantId, bundleUrl, bundleToken, checkCusto
|
|
|
127
98
|
return bundleUrl.replace('{tenantId}', id);
|
|
128
99
|
}, [bundleUrl]);
|
|
129
100
|
/**
|
|
130
|
-
* Cleans up previously loaded bundle
|
|
101
|
+
* Cleans up previously loaded bundle module
|
|
131
102
|
*/
|
|
132
103
|
const cleanup = useCallback(() => {
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
loadedUrlRef.current = null;
|
|
104
|
+
if (bundleModule?.cleanup) {
|
|
105
|
+
bundleModule.cleanup();
|
|
136
106
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (root) {
|
|
140
|
-
root.innerHTML = '';
|
|
141
|
-
}
|
|
142
|
-
}, []);
|
|
107
|
+
setBundleModule(null);
|
|
108
|
+
}, [bundleModule]);
|
|
143
109
|
/**
|
|
144
110
|
* Main effect to handle tenant bundle loading
|
|
145
111
|
*/
|
|
@@ -182,18 +148,13 @@ export function InferenceProvider({ tenantId, bundleUrl, bundleToken, checkCusto
|
|
|
182
148
|
// Clean up previous bundle
|
|
183
149
|
cleanup();
|
|
184
150
|
const url = resolveBundleUrl(tenantId);
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
await loadScriptWithAuth(url, bundleToken);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
await loadScript(url);
|
|
191
|
-
}
|
|
151
|
+
// Load bundle via fetch + dynamic import
|
|
152
|
+
const module = await loadBundleModule(url, bundleToken);
|
|
192
153
|
if (cancelled) {
|
|
193
|
-
|
|
154
|
+
module.cleanup();
|
|
194
155
|
return;
|
|
195
156
|
}
|
|
196
|
-
|
|
157
|
+
setBundleModule(module);
|
|
197
158
|
setState({
|
|
198
159
|
status: 'loaded',
|
|
199
160
|
error: null,
|
|
@@ -253,8 +214,13 @@ export function InferenceProvider({ tenantId, bundleUrl, bundleToken, checkCusto
|
|
|
253
214
|
case 'loading':
|
|
254
215
|
return loadingComponent ?? _jsx(DefaultLoadingComponent, {});
|
|
255
216
|
case 'loaded':
|
|
256
|
-
//
|
|
257
|
-
|
|
217
|
+
// Render the loaded App component directly
|
|
218
|
+
if (bundleModule?.App) {
|
|
219
|
+
const TenantApp = bundleModule.App;
|
|
220
|
+
return _jsx(TenantApp, {});
|
|
221
|
+
}
|
|
222
|
+
// Fallback if no App component found
|
|
223
|
+
return children;
|
|
258
224
|
case 'error':
|
|
259
225
|
// Show children as fallback with optional error banner
|
|
260
226
|
return (_jsxs(_Fragment, { children: [renderErrorBanner(), children] }));
|
|
@@ -51,6 +51,15 @@ export interface InferenceState {
|
|
|
51
51
|
error: Error | null;
|
|
52
52
|
currentTenantId: string | null;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Module loaded from a tenant bundle via dynamic import
|
|
56
|
+
*/
|
|
57
|
+
export interface BundleModule {
|
|
58
|
+
/** The App component exported by the bundle */
|
|
59
|
+
App: React.ComponentType<unknown>;
|
|
60
|
+
/** Cleanup function to revoke the blob URL */
|
|
61
|
+
cleanup: () => void;
|
|
62
|
+
}
|
|
54
63
|
/**
|
|
55
64
|
* The global SDK object exposed to tenant bundles
|
|
56
65
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/inference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,KAAK,EAAE,cAAc,OAAO,CAAC,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,EAAE,cAAc,WAAW,CAAC,CAAC;IACrC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACnD;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7D,+DAA+D;IAC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