@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.
Files changed (65) hide show
  1. package/dist/applet/core.cjs +251 -0
  2. package/dist/applet/core.cjs.map +1 -0
  3. package/dist/applet/core.d.cts +172 -0
  4. package/dist/applet/core.d.ts +172 -0
  5. package/dist/applet/core.mjs +237 -0
  6. package/dist/applet/core.mjs.map +1 -0
  7. package/dist/applet/devtools.cjs +131 -0
  8. package/dist/applet/devtools.cjs.map +1 -0
  9. package/dist/applet/devtools.d.cts +7 -0
  10. package/dist/applet/devtools.d.ts +7 -0
  11. package/dist/applet/devtools.mjs +128 -0
  12. package/dist/applet/devtools.mjs.map +1 -0
  13. package/dist/applet/host.cjs +256 -0
  14. package/dist/applet/host.cjs.map +1 -0
  15. package/dist/applet/host.d.cts +62 -0
  16. package/dist/applet/host.d.ts +62 -0
  17. package/dist/applet/host.mjs +251 -0
  18. package/dist/applet/host.mjs.map +1 -0
  19. package/dist/bichat/index.cjs +352 -409
  20. package/dist/bichat/index.cjs.map +1 -1
  21. package/dist/bichat/index.d.cts +8 -116
  22. package/dist/bichat/index.d.ts +8 -116
  23. package/dist/bichat/index.mjs +354 -403
  24. package/dist/bichat/index.mjs.map +1 -1
  25. package/dist/fonts/Actay/Actay-Regular.otf +0 -0
  26. package/dist/fonts/Actay/Actay-RegularItalic.otf +0 -0
  27. package/dist/fonts/Actay/ActayCondensed-Thin.otf +0 -0
  28. package/dist/fonts/Actay/ActayCondensed-ThinItalic.otf +0 -0
  29. package/dist/fonts/Actay/ActayWide-Bold.otf +0 -0
  30. package/dist/fonts/Actay/ActayWide-BoldItalic.otf +0 -0
  31. package/dist/fonts/Gilroy/Gilroy-Black.woff2 +0 -0
  32. package/dist/fonts/Gilroy/Gilroy-BlackItalic.woff2 +0 -0
  33. package/dist/fonts/Gilroy/Gilroy-Bold.woff2 +0 -0
  34. package/dist/fonts/Gilroy/Gilroy-BoldItalic.woff2 +0 -0
  35. package/dist/fonts/Gilroy/Gilroy-Extrabold.woff2 +0 -0
  36. package/dist/fonts/Gilroy/Gilroy-ExtraboldItalic.woff2 +0 -0
  37. package/dist/fonts/Gilroy/Gilroy-Heavy.woff2 +0 -0
  38. package/dist/fonts/Gilroy/Gilroy-HeavyItalic.woff2 +0 -0
  39. package/dist/fonts/Gilroy/Gilroy-Light.woff2 +0 -0
  40. package/dist/fonts/Gilroy/Gilroy-LightItalic.woff2 +0 -0
  41. package/dist/fonts/Gilroy/Gilroy-Medium.woff2 +0 -0
  42. package/dist/fonts/Gilroy/Gilroy-MediumItalic.woff2 +0 -0
  43. package/dist/fonts/Gilroy/Gilroy-Regular.woff2 +0 -0
  44. package/dist/fonts/Gilroy/Gilroy-RegularItalic.woff2 +0 -0
  45. package/dist/fonts/Gilroy/Gilroy-Semibold.woff2 +0 -0
  46. package/dist/fonts/Gilroy/Gilroy-SemiboldItalic.woff2 +0 -0
  47. package/dist/fonts/Gilroy/Gilroy-Thin.woff2 +0 -0
  48. package/dist/fonts/Gilroy/Gilroy-ThinItalic.woff2 +0 -0
  49. package/dist/fonts/Gilroy/Gilroy-UltraLight.woff2 +0 -0
  50. package/dist/fonts/Gilroy/Gilroy-UltraLightItalic.woff2 +0 -0
  51. package/dist/fonts/Inter.var.woff2 +0 -0
  52. package/dist/{index-B73-BCi-.d.cts → index-Cs_xWkhC.d.cts} +1 -1
  53. package/dist/{index-B73-BCi-.d.ts → index-Cs_xWkhC.d.ts} +1 -1
  54. package/dist/index.cjs +52 -4
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +6 -232
  57. package/dist/index.d.ts +6 -232
  58. package/dist/index.mjs +52 -4
  59. package/dist/index.mjs.map +1 -1
  60. package/package.json +44 -13
  61. package/tailwind/compiled.css +1 -1
  62. package/tailwind/create-config.cjs +16 -135
  63. package/tailwind/sdk-theme.cjs +99 -0
  64. package/LICENSE +0 -201
  65. package/README.MD +0 -166
package/dist/index.d.cts CHANGED
@@ -1,232 +1,6 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import react__default, { ReactNode } from 'react';
3
- import { I as InitialContext, A as AppConfig, U as UserContext, P as PermissionsHook, T as TranslationHook, S as SessionHook, R as RouteContext, a as StreamingHook } from './index-B73-BCi-.cjs';
4
- export { L as LocaleContext, b as SessionContext, c as TenantContext } from './index-B73-BCi-.cjs';
5
-
6
- interface AppletProviderProps {
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
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import react__default, { ReactNode } from 'react';
3
- import { I as InitialContext, A as AppConfig, U as UserContext, P as PermissionsHook, T as TranslationHook, S as SessionHook, R as RouteContext, a as StreamingHook } from './index-B73-BCi-.js';
4
- export { L as LocaleContext, b as SessionContext, c as TenantContext } from './index-B73-BCi-.js';
5
-
6
- interface AppletProviderProps {
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 initialContext = context ?? window[windowKey];
9
- if (!initialContext) {
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 = `/login?redirect=${returnUrl}`;
150
+ window.location.href = `${loginPath}?redirect=${returnUrl}`;
103
151
  return;
104
152
  }
105
153
  const newToken = response.headers.get("X-CSRF-Token");