@iota-uz/sdk 0.3.3 → 0.4.7
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/applet/core.cjs +251 -0
- package/dist/applet/core.cjs.map +1 -0
- package/dist/applet/core.d.cts +172 -0
- package/dist/applet/core.d.ts +172 -0
- package/dist/applet/core.mjs +237 -0
- package/dist/applet/core.mjs.map +1 -0
- package/dist/applet/devtools.cjs +131 -0
- package/dist/applet/devtools.cjs.map +1 -0
- package/dist/applet/devtools.d.cts +7 -0
- package/dist/applet/devtools.d.ts +7 -0
- package/dist/applet/devtools.mjs +128 -0
- package/dist/applet/devtools.mjs.map +1 -0
- package/dist/applet/host.cjs +256 -0
- package/dist/applet/host.cjs.map +1 -0
- package/dist/applet/host.d.cts +62 -0
- package/dist/applet/host.d.ts +62 -0
- package/dist/applet/host.mjs +251 -0
- package/dist/applet/host.mjs.map +1 -0
- package/dist/bichat/index.cjs +352 -409
- package/dist/bichat/index.cjs.map +1 -1
- package/dist/bichat/index.d.cts +8 -116
- package/dist/bichat/index.d.ts +8 -116
- package/dist/bichat/index.mjs +354 -403
- package/dist/bichat/index.mjs.map +1 -1
- package/dist/fonts/Actay/Actay-Regular.otf +0 -0
- package/dist/fonts/Actay/Actay-RegularItalic.otf +0 -0
- package/dist/fonts/Actay/ActayCondensed-Thin.otf +0 -0
- package/dist/fonts/Actay/ActayCondensed-ThinItalic.otf +0 -0
- package/dist/fonts/Actay/ActayWide-Bold.otf +0 -0
- package/dist/fonts/Actay/ActayWide-BoldItalic.otf +0 -0
- package/dist/fonts/Gilroy/Gilroy-Black.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-BlackItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Bold.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-BoldItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Extrabold.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-ExtraboldItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Heavy.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-HeavyItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Light.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-LightItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Medium.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-MediumItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Regular.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-RegularItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Semibold.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-SemiboldItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-Thin.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-ThinItalic.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-UltraLight.woff2 +0 -0
- package/dist/fonts/Gilroy/Gilroy-UltraLightItalic.woff2 +0 -0
- package/dist/fonts/Inter.var.woff2 +0 -0
- package/dist/{index-B73-BCi-.d.cts → index-Cs_xWkhC.d.cts} +1 -1
- package/dist/{index-B73-BCi-.d.ts → index-Cs_xWkhC.d.ts} +1 -1
- package/dist/index.cjs +52 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -232
- package/dist/index.d.ts +6 -232
- package/dist/index.mjs +52 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +44 -13
- package/tailwind/compiled.css +1 -1
- package/tailwind/create-config.cjs +16 -135
- package/tailwind/sdk-theme.cjs +99 -0
- package/LICENSE +0 -201
- package/README.MD +0 -166
package/dist/index.d.cts
CHANGED
|
@@ -1,232 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
windowKey: string;
|
|
9
|
-
context?: InitialContext;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* AppletProvider reads context from window global and provides it to hooks.
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* <AppletProvider windowKey="__BICHAT_CONTEXT__">
|
|
16
|
-
* <App />
|
|
17
|
-
* </AppletProvider>
|
|
18
|
-
*/
|
|
19
|
-
declare function AppletProvider({ children, windowKey, context }: AppletProviderProps): react_jsx_runtime.JSX.Element;
|
|
20
|
-
/**
|
|
21
|
-
* useAppletContext provides access to the full applet context.
|
|
22
|
-
* Use specialized hooks (useUser, useConfig, etc.) for specific context parts.
|
|
23
|
-
*/
|
|
24
|
-
declare function useAppletContext$1<T = InitialContext>(): T;
|
|
25
|
-
|
|
26
|
-
interface ConfigProviderProps {
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
config: InitialContext;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* ConfigProvider accepts context configuration via props.
|
|
32
|
-
*
|
|
33
|
-
* Usage:
|
|
34
|
-
* <ConfigProvider config={initialContext}>
|
|
35
|
-
* <App />
|
|
36
|
-
* </ConfigProvider>
|
|
37
|
-
*/
|
|
38
|
-
declare function ConfigProvider({ children, config }: ConfigProviderProps): react_jsx_runtime.JSX.Element;
|
|
39
|
-
/**
|
|
40
|
-
* useConfigContext provides access to the applet context when using ConfigProvider.
|
|
41
|
-
*/
|
|
42
|
-
declare function useConfigContext<T = InitialContext>(): T;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* useAppletContext provides direct access to the window global context.
|
|
46
|
-
* This is a standalone version that doesn't require AppletProvider.
|
|
47
|
-
*
|
|
48
|
-
* Usage:
|
|
49
|
-
* const context = useAppletContext('__BICHAT_CONTEXT__')
|
|
50
|
-
*
|
|
51
|
-
* Note: Prefer using AppletProvider + context hooks for better type safety
|
|
52
|
-
* and testability. Use this hook only when provider setup is not possible.
|
|
53
|
-
*/
|
|
54
|
-
declare function useAppletContext<T = InitialContext>(windowKey: string): T;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* useConfig provides access to applet configuration (endpoints, etc.)
|
|
58
|
-
*
|
|
59
|
-
* Usage:
|
|
60
|
-
* const { graphQLEndpoint, streamEndpoint } = useConfig()
|
|
61
|
-
*/
|
|
62
|
-
declare function useConfig(): AppConfig;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* useUser provides access to current user information.
|
|
66
|
-
*
|
|
67
|
-
* Usage:
|
|
68
|
-
* const { id, email, firstName, lastName, permissions } = useUser()
|
|
69
|
-
*/
|
|
70
|
-
declare function useUser(): UserContext;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* usePermissions provides permission checking utilities.
|
|
74
|
-
* All user permissions are automatically passed from backend.
|
|
75
|
-
*
|
|
76
|
-
* Usage:
|
|
77
|
-
* const { hasPermission, hasAnyPermission } = usePermissions()
|
|
78
|
-
*
|
|
79
|
-
* if (hasPermission('bichat.access')) {
|
|
80
|
-
* // User has bichat access
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
* if (hasAnyPermission('finance.view', 'finance.edit')) {
|
|
84
|
-
* // User has at least one of these permissions
|
|
85
|
-
* }
|
|
86
|
-
*/
|
|
87
|
-
declare function usePermissions(): PermissionsHook;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* useTranslation provides i18n translation utilities.
|
|
91
|
-
* All translations are automatically passed from backend locale bundle.
|
|
92
|
-
*
|
|
93
|
-
* Usage:
|
|
94
|
-
* const { t, language } = useTranslation()
|
|
95
|
-
*
|
|
96
|
-
* // Simple translation
|
|
97
|
-
* t('BiChat.Title') // Returns translated text
|
|
98
|
-
*
|
|
99
|
-
* // Translation with interpolation
|
|
100
|
-
* t('Common.WelcomeMessage', { name: 'John' })
|
|
101
|
-
* // If translation is "Welcome {name}!" -> Returns "Welcome John!"
|
|
102
|
-
*
|
|
103
|
-
* React uses same keys as Go backend:
|
|
104
|
-
* Go: pageCtx.T("BiChat.Title")
|
|
105
|
-
* React: t("BiChat.Title")
|
|
106
|
-
*/
|
|
107
|
-
declare function useTranslation(): TranslationHook;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* useSession provides session and authentication handling utilities.
|
|
111
|
-
*
|
|
112
|
-
* Usage:
|
|
113
|
-
* const { isExpiringSoon, refreshSession, csrfToken } = useSession()
|
|
114
|
-
*
|
|
115
|
-
* // Check if session is expiring soon (5 min buffer)
|
|
116
|
-
* if (isExpiringSoon) {
|
|
117
|
-
* await refreshSession()
|
|
118
|
-
* }
|
|
119
|
-
*
|
|
120
|
-
* // Include CSRF token in requests
|
|
121
|
-
* fetch('/api/endpoint', {
|
|
122
|
-
* headers: { 'X-CSRF-Token': csrfToken }
|
|
123
|
-
* })
|
|
124
|
-
*/
|
|
125
|
-
declare function useSession(): SessionHook;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* useRoute provides access to the current route context.
|
|
129
|
-
* Route context is initialized from the backend and includes path, params, and query.
|
|
130
|
-
*
|
|
131
|
-
* Usage:
|
|
132
|
-
* const { path, params, query } = useRoute()
|
|
133
|
-
*
|
|
134
|
-
* // Example values:
|
|
135
|
-
* // path: "/sessions/123"
|
|
136
|
-
* // params: { id: "123" }
|
|
137
|
-
* // query: { tab: "history" }
|
|
138
|
-
*/
|
|
139
|
-
declare function useRoute(): RouteContext;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* useStreaming provides SSE (Server-Sent Events) streaming utilities with cancellation support.
|
|
143
|
-
*
|
|
144
|
-
* Usage:
|
|
145
|
-
* const { isStreaming, processStream, cancel, reset } = useStreaming()
|
|
146
|
-
*
|
|
147
|
-
* // Process async generator stream
|
|
148
|
-
* await processStream(messageStream, (chunk) => {
|
|
149
|
-
* console.log('Received:', chunk)
|
|
150
|
-
* })
|
|
151
|
-
*
|
|
152
|
-
* // Cancel ongoing stream
|
|
153
|
-
* cancel()
|
|
154
|
-
*
|
|
155
|
-
* // Reset state after stream completion
|
|
156
|
-
* reset()
|
|
157
|
-
*/
|
|
158
|
-
declare function useStreaming(): StreamingHook;
|
|
159
|
-
|
|
160
|
-
type ShellMode$1 = 'embedded' | 'standalone';
|
|
161
|
-
interface AppletRuntime {
|
|
162
|
-
basePath: string;
|
|
163
|
-
assetsBasePath: string;
|
|
164
|
-
rpcEndpoint?: string;
|
|
165
|
-
shellMode?: ShellMode$1;
|
|
166
|
-
}
|
|
167
|
-
declare function useAppletRuntime(): AppletRuntime;
|
|
168
|
-
|
|
169
|
-
type RouterMode$1 = 'url' | 'memory';
|
|
170
|
-
type ShellMode = 'embedded' | 'standalone';
|
|
171
|
-
interface AppletHostConfig {
|
|
172
|
-
basePath: string;
|
|
173
|
-
shellMode?: ShellMode;
|
|
174
|
-
routerMode: RouterMode$1;
|
|
175
|
-
attrs: Record<string, string>;
|
|
176
|
-
}
|
|
177
|
-
interface DefineReactAppletElementOptions {
|
|
178
|
-
tagName: string;
|
|
179
|
-
styles?: string | (() => string);
|
|
180
|
-
render: (host: AppletHostConfig) => react__default.ReactElement;
|
|
181
|
-
observedAttributes?: string[];
|
|
182
|
-
observeDarkMode?: boolean;
|
|
183
|
-
}
|
|
184
|
-
declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
|
|
185
|
-
|
|
186
|
-
interface AppletRPCError {
|
|
187
|
-
code: string;
|
|
188
|
-
message: string;
|
|
189
|
-
details?: unknown;
|
|
190
|
-
}
|
|
191
|
-
declare class AppletRPCException extends Error {
|
|
192
|
-
code: string;
|
|
193
|
-
details?: unknown;
|
|
194
|
-
cause?: unknown;
|
|
195
|
-
constructor(args: {
|
|
196
|
-
code: string;
|
|
197
|
-
message: string;
|
|
198
|
-
details?: unknown;
|
|
199
|
-
cause?: unknown;
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
type AppletRPCSchema = Record<string, {
|
|
203
|
-
params: unknown;
|
|
204
|
-
result: unknown;
|
|
205
|
-
}>;
|
|
206
|
-
interface CreateAppletRPCClientOptions {
|
|
207
|
-
endpoint: string;
|
|
208
|
-
fetcher?: typeof fetch;
|
|
209
|
-
}
|
|
210
|
-
declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
|
|
211
|
-
call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
|
|
212
|
-
callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
type RouterMode = 'url' | 'memory';
|
|
216
|
-
interface CreateAppletRouterOptions {
|
|
217
|
-
mode: RouterMode;
|
|
218
|
-
basePath?: string;
|
|
219
|
-
BrowserRouter: react__default.ComponentType<any>;
|
|
220
|
-
MemoryRouter: react__default.ComponentType<any>;
|
|
221
|
-
}
|
|
222
|
-
declare function createAppletRouter(options: CreateAppletRouterOptions): {
|
|
223
|
-
Router: react__default.FC<{
|
|
224
|
-
children?: react__default.ReactNode | undefined;
|
|
225
|
-
}>;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
declare function shouldEnableAppletDevtools(): boolean;
|
|
229
|
-
|
|
230
|
-
declare function AppletDevtoolsOverlay(): react_jsx_runtime.JSX.Element;
|
|
231
|
-
|
|
232
|
-
export { AppConfig, AppletDevtoolsOverlay, AppletProvider, type AppletRPCError, AppletRPCException, type AppletRPCSchema, ConfigProvider, InitialContext, PermissionsHook, RouteContext, type RouterMode, SessionHook, StreamingHook, TranslationHook, UserContext, createAppletRPCClient, createAppletRouter, defineReactAppletElement, shouldEnableAppletDevtools, useAppletContext$1 as useAppletContext, useAppletContext as useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser };
|
|
1
|
+
export { AppletProvider, ConfigProvider, useAppletContext, useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser } from './applet/core.cjs';
|
|
2
|
+
export { A as AppConfig, I as InitialContext, L as LocaleContext, P as PermissionsHook, R as RouteContext, S as SessionContext, a as SessionHook, b as StreamingHook, T as TenantContext, c as TranslationHook, U as UserContext } from './index-Cs_xWkhC.cjs';
|
|
3
|
+
export { AppletRPCError, AppletRPCException, AppletRPCSchema, RouterMode, createAppletRPCClient, createAppletRouter, defineReactAppletElement } from './applet/host.cjs';
|
|
4
|
+
export { AppletDevtoolsOverlay, shouldEnableAppletDevtools } from './applet/devtools.cjs';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,232 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
windowKey: string;
|
|
9
|
-
context?: InitialContext;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* AppletProvider reads context from window global and provides it to hooks.
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* <AppletProvider windowKey="__BICHAT_CONTEXT__">
|
|
16
|
-
* <App />
|
|
17
|
-
* </AppletProvider>
|
|
18
|
-
*/
|
|
19
|
-
declare function AppletProvider({ children, windowKey, context }: AppletProviderProps): react_jsx_runtime.JSX.Element;
|
|
20
|
-
/**
|
|
21
|
-
* useAppletContext provides access to the full applet context.
|
|
22
|
-
* Use specialized hooks (useUser, useConfig, etc.) for specific context parts.
|
|
23
|
-
*/
|
|
24
|
-
declare function useAppletContext$1<T = InitialContext>(): T;
|
|
25
|
-
|
|
26
|
-
interface ConfigProviderProps {
|
|
27
|
-
children: ReactNode;
|
|
28
|
-
config: InitialContext;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* ConfigProvider accepts context configuration via props.
|
|
32
|
-
*
|
|
33
|
-
* Usage:
|
|
34
|
-
* <ConfigProvider config={initialContext}>
|
|
35
|
-
* <App />
|
|
36
|
-
* </ConfigProvider>
|
|
37
|
-
*/
|
|
38
|
-
declare function ConfigProvider({ children, config }: ConfigProviderProps): react_jsx_runtime.JSX.Element;
|
|
39
|
-
/**
|
|
40
|
-
* useConfigContext provides access to the applet context when using ConfigProvider.
|
|
41
|
-
*/
|
|
42
|
-
declare function useConfigContext<T = InitialContext>(): T;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* useAppletContext provides direct access to the window global context.
|
|
46
|
-
* This is a standalone version that doesn't require AppletProvider.
|
|
47
|
-
*
|
|
48
|
-
* Usage:
|
|
49
|
-
* const context = useAppletContext('__BICHAT_CONTEXT__')
|
|
50
|
-
*
|
|
51
|
-
* Note: Prefer using AppletProvider + context hooks for better type safety
|
|
52
|
-
* and testability. Use this hook only when provider setup is not possible.
|
|
53
|
-
*/
|
|
54
|
-
declare function useAppletContext<T = InitialContext>(windowKey: string): T;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* useConfig provides access to applet configuration (endpoints, etc.)
|
|
58
|
-
*
|
|
59
|
-
* Usage:
|
|
60
|
-
* const { graphQLEndpoint, streamEndpoint } = useConfig()
|
|
61
|
-
*/
|
|
62
|
-
declare function useConfig(): AppConfig;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* useUser provides access to current user information.
|
|
66
|
-
*
|
|
67
|
-
* Usage:
|
|
68
|
-
* const { id, email, firstName, lastName, permissions } = useUser()
|
|
69
|
-
*/
|
|
70
|
-
declare function useUser(): UserContext;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* usePermissions provides permission checking utilities.
|
|
74
|
-
* All user permissions are automatically passed from backend.
|
|
75
|
-
*
|
|
76
|
-
* Usage:
|
|
77
|
-
* const { hasPermission, hasAnyPermission } = usePermissions()
|
|
78
|
-
*
|
|
79
|
-
* if (hasPermission('bichat.access')) {
|
|
80
|
-
* // User has bichat access
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
* if (hasAnyPermission('finance.view', 'finance.edit')) {
|
|
84
|
-
* // User has at least one of these permissions
|
|
85
|
-
* }
|
|
86
|
-
*/
|
|
87
|
-
declare function usePermissions(): PermissionsHook;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* useTranslation provides i18n translation utilities.
|
|
91
|
-
* All translations are automatically passed from backend locale bundle.
|
|
92
|
-
*
|
|
93
|
-
* Usage:
|
|
94
|
-
* const { t, language } = useTranslation()
|
|
95
|
-
*
|
|
96
|
-
* // Simple translation
|
|
97
|
-
* t('BiChat.Title') // Returns translated text
|
|
98
|
-
*
|
|
99
|
-
* // Translation with interpolation
|
|
100
|
-
* t('Common.WelcomeMessage', { name: 'John' })
|
|
101
|
-
* // If translation is "Welcome {name}!" -> Returns "Welcome John!"
|
|
102
|
-
*
|
|
103
|
-
* React uses same keys as Go backend:
|
|
104
|
-
* Go: pageCtx.T("BiChat.Title")
|
|
105
|
-
* React: t("BiChat.Title")
|
|
106
|
-
*/
|
|
107
|
-
declare function useTranslation(): TranslationHook;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* useSession provides session and authentication handling utilities.
|
|
111
|
-
*
|
|
112
|
-
* Usage:
|
|
113
|
-
* const { isExpiringSoon, refreshSession, csrfToken } = useSession()
|
|
114
|
-
*
|
|
115
|
-
* // Check if session is expiring soon (5 min buffer)
|
|
116
|
-
* if (isExpiringSoon) {
|
|
117
|
-
* await refreshSession()
|
|
118
|
-
* }
|
|
119
|
-
*
|
|
120
|
-
* // Include CSRF token in requests
|
|
121
|
-
* fetch('/api/endpoint', {
|
|
122
|
-
* headers: { 'X-CSRF-Token': csrfToken }
|
|
123
|
-
* })
|
|
124
|
-
*/
|
|
125
|
-
declare function useSession(): SessionHook;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* useRoute provides access to the current route context.
|
|
129
|
-
* Route context is initialized from the backend and includes path, params, and query.
|
|
130
|
-
*
|
|
131
|
-
* Usage:
|
|
132
|
-
* const { path, params, query } = useRoute()
|
|
133
|
-
*
|
|
134
|
-
* // Example values:
|
|
135
|
-
* // path: "/sessions/123"
|
|
136
|
-
* // params: { id: "123" }
|
|
137
|
-
* // query: { tab: "history" }
|
|
138
|
-
*/
|
|
139
|
-
declare function useRoute(): RouteContext;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* useStreaming provides SSE (Server-Sent Events) streaming utilities with cancellation support.
|
|
143
|
-
*
|
|
144
|
-
* Usage:
|
|
145
|
-
* const { isStreaming, processStream, cancel, reset } = useStreaming()
|
|
146
|
-
*
|
|
147
|
-
* // Process async generator stream
|
|
148
|
-
* await processStream(messageStream, (chunk) => {
|
|
149
|
-
* console.log('Received:', chunk)
|
|
150
|
-
* })
|
|
151
|
-
*
|
|
152
|
-
* // Cancel ongoing stream
|
|
153
|
-
* cancel()
|
|
154
|
-
*
|
|
155
|
-
* // Reset state after stream completion
|
|
156
|
-
* reset()
|
|
157
|
-
*/
|
|
158
|
-
declare function useStreaming(): StreamingHook;
|
|
159
|
-
|
|
160
|
-
type ShellMode$1 = 'embedded' | 'standalone';
|
|
161
|
-
interface AppletRuntime {
|
|
162
|
-
basePath: string;
|
|
163
|
-
assetsBasePath: string;
|
|
164
|
-
rpcEndpoint?: string;
|
|
165
|
-
shellMode?: ShellMode$1;
|
|
166
|
-
}
|
|
167
|
-
declare function useAppletRuntime(): AppletRuntime;
|
|
168
|
-
|
|
169
|
-
type RouterMode$1 = 'url' | 'memory';
|
|
170
|
-
type ShellMode = 'embedded' | 'standalone';
|
|
171
|
-
interface AppletHostConfig {
|
|
172
|
-
basePath: string;
|
|
173
|
-
shellMode?: ShellMode;
|
|
174
|
-
routerMode: RouterMode$1;
|
|
175
|
-
attrs: Record<string, string>;
|
|
176
|
-
}
|
|
177
|
-
interface DefineReactAppletElementOptions {
|
|
178
|
-
tagName: string;
|
|
179
|
-
styles?: string | (() => string);
|
|
180
|
-
render: (host: AppletHostConfig) => react__default.ReactElement;
|
|
181
|
-
observedAttributes?: string[];
|
|
182
|
-
observeDarkMode?: boolean;
|
|
183
|
-
}
|
|
184
|
-
declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
|
|
185
|
-
|
|
186
|
-
interface AppletRPCError {
|
|
187
|
-
code: string;
|
|
188
|
-
message: string;
|
|
189
|
-
details?: unknown;
|
|
190
|
-
}
|
|
191
|
-
declare class AppletRPCException extends Error {
|
|
192
|
-
code: string;
|
|
193
|
-
details?: unknown;
|
|
194
|
-
cause?: unknown;
|
|
195
|
-
constructor(args: {
|
|
196
|
-
code: string;
|
|
197
|
-
message: string;
|
|
198
|
-
details?: unknown;
|
|
199
|
-
cause?: unknown;
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
type AppletRPCSchema = Record<string, {
|
|
203
|
-
params: unknown;
|
|
204
|
-
result: unknown;
|
|
205
|
-
}>;
|
|
206
|
-
interface CreateAppletRPCClientOptions {
|
|
207
|
-
endpoint: string;
|
|
208
|
-
fetcher?: typeof fetch;
|
|
209
|
-
}
|
|
210
|
-
declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
|
|
211
|
-
call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
|
|
212
|
-
callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
type RouterMode = 'url' | 'memory';
|
|
216
|
-
interface CreateAppletRouterOptions {
|
|
217
|
-
mode: RouterMode;
|
|
218
|
-
basePath?: string;
|
|
219
|
-
BrowserRouter: react__default.ComponentType<any>;
|
|
220
|
-
MemoryRouter: react__default.ComponentType<any>;
|
|
221
|
-
}
|
|
222
|
-
declare function createAppletRouter(options: CreateAppletRouterOptions): {
|
|
223
|
-
Router: react__default.FC<{
|
|
224
|
-
children?: react__default.ReactNode | undefined;
|
|
225
|
-
}>;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
declare function shouldEnableAppletDevtools(): boolean;
|
|
229
|
-
|
|
230
|
-
declare function AppletDevtoolsOverlay(): react_jsx_runtime.JSX.Element;
|
|
231
|
-
|
|
232
|
-
export { AppConfig, AppletDevtoolsOverlay, AppletProvider, type AppletRPCError, AppletRPCException, type AppletRPCSchema, ConfigProvider, InitialContext, PermissionsHook, RouteContext, type RouterMode, SessionHook, StreamingHook, TranslationHook, UserContext, createAppletRPCClient, createAppletRouter, defineReactAppletElement, shouldEnableAppletDevtools, useAppletContext$1 as useAppletContext, useAppletContext as useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser };
|
|
1
|
+
export { AppletProvider, ConfigProvider, useAppletContext, useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser } from './applet/core.js';
|
|
2
|
+
export { A as AppConfig, I as InitialContext, L as LocaleContext, P as PermissionsHook, R as RouteContext, S as SessionContext, a as SessionHook, b as StreamingHook, T as TenantContext, c as TranslationHook, U as UserContext } from './index-Cs_xWkhC.js';
|
|
3
|
+
export { AppletRPCError, AppletRPCException, AppletRPCSchema, RouterMode, createAppletRPCClient, createAppletRouter, defineReactAppletElement } from './applet/host.js';
|
|
4
|
+
export { AppletDevtoolsOverlay, shouldEnableAppletDevtools } from './applet/devtools.js';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import 'react';
|
package/dist/index.mjs
CHANGED
|
@@ -4,11 +4,58 @@ import { createRoot } from 'react-dom/client';
|
|
|
4
4
|
|
|
5
5
|
// ui/src/applet-core/context/AppletContext.tsx
|
|
6
6
|
var AppletContext = createContext(null);
|
|
7
|
+
var REQUIRED_KEYS = ["user", "tenant", "locale", "config", "route", "session"];
|
|
8
|
+
function validateInitialContext(value, windowKey) {
|
|
9
|
+
if (!value || typeof value !== "object") {
|
|
10
|
+
throw new Error(`${windowKey}: expected an object, got ${typeof value}`);
|
|
11
|
+
}
|
|
12
|
+
const obj = value;
|
|
13
|
+
const missing = REQUIRED_KEYS.filter((k) => !(k in obj));
|
|
14
|
+
if (missing.length > 0) {
|
|
15
|
+
throw new Error(`${windowKey}: missing required keys: ${missing.join(", ")}`);
|
|
16
|
+
}
|
|
17
|
+
const user = obj.user;
|
|
18
|
+
if (!user || typeof user !== "object") {
|
|
19
|
+
throw new Error(`${windowKey}.user: expected an object, got ${typeof user}`);
|
|
20
|
+
}
|
|
21
|
+
if (typeof user.id !== "number") {
|
|
22
|
+
throw new Error(`${windowKey}.user.id: expected number, got ${typeof user.id}`);
|
|
23
|
+
}
|
|
24
|
+
if (!Array.isArray(user.permissions)) {
|
|
25
|
+
throw new Error(`${windowKey}.user.permissions: expected array, got ${typeof user.permissions}`);
|
|
26
|
+
}
|
|
27
|
+
const tenant = obj.tenant;
|
|
28
|
+
if (!tenant || typeof tenant !== "object") {
|
|
29
|
+
throw new Error(`${windowKey}.tenant: expected an object, got ${typeof tenant}`);
|
|
30
|
+
}
|
|
31
|
+
if (typeof tenant.id !== "string") {
|
|
32
|
+
throw new Error(`${windowKey}.tenant.id: expected string, got ${typeof tenant.id}`);
|
|
33
|
+
}
|
|
34
|
+
const session = obj.session;
|
|
35
|
+
if (!session || typeof session !== "object") {
|
|
36
|
+
throw new Error(`${windowKey}.session: expected an object, got ${typeof session}`);
|
|
37
|
+
}
|
|
38
|
+
if (typeof session.csrfToken !== "string") {
|
|
39
|
+
throw new Error(`${windowKey}.session.csrfToken: expected string, got ${typeof session.csrfToken}`);
|
|
40
|
+
}
|
|
41
|
+
if (typeof session.expiresAt !== "number") {
|
|
42
|
+
throw new Error(`${windowKey}.session.expiresAt: expected number, got ${typeof session.expiresAt}`);
|
|
43
|
+
}
|
|
44
|
+
if (typeof session.refreshURL !== "string") {
|
|
45
|
+
throw new Error(`${windowKey}.session.refreshURL: expected string, got ${typeof session.refreshURL}`);
|
|
46
|
+
}
|
|
47
|
+
const config = obj.config;
|
|
48
|
+
if (!config || typeof config !== "object") {
|
|
49
|
+
throw new Error(`${windowKey}.config: expected object, got ${typeof config}`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
7
53
|
function AppletProvider({ children, windowKey, context }) {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
54
|
+
const raw = context ?? window[windowKey];
|
|
55
|
+
if (!raw) {
|
|
10
56
|
throw new Error(`${windowKey} not found on window. Ensure backend context injection is working.`);
|
|
11
57
|
}
|
|
58
|
+
const initialContext = validateInitialContext(raw, windowKey);
|
|
12
59
|
return /* @__PURE__ */ jsx(AppletContext.Provider, { value: initialContext, children });
|
|
13
60
|
}
|
|
14
61
|
function useAppletContext() {
|
|
@@ -84,8 +131,9 @@ function useTranslation() {
|
|
|
84
131
|
language: locale.language
|
|
85
132
|
};
|
|
86
133
|
}
|
|
87
|
-
function useSession() {
|
|
134
|
+
function useSession(options) {
|
|
88
135
|
const { session } = useAppletContext();
|
|
136
|
+
const loginPath = options?.loginPath ?? "/login";
|
|
89
137
|
const isExpiringSoon = useMemo(() => {
|
|
90
138
|
const bufferMs = 5 * 60 * 1e3;
|
|
91
139
|
return session.expiresAt - Date.now() < bufferMs;
|
|
@@ -99,7 +147,7 @@ function useSession() {
|
|
|
99
147
|
});
|
|
100
148
|
if (!response.ok) {
|
|
101
149
|
const returnUrl = encodeURIComponent(window.location.pathname);
|
|
102
|
-
window.location.href =
|
|
150
|
+
window.location.href = `${loginPath}?redirect=${returnUrl}`;
|
|
103
151
|
return;
|
|
104
152
|
}
|
|
105
153
|
const newToken = response.headers.get("X-CSRF-Token");
|