@nsxbet/admin-sdk 0.1.0
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/README.md +680 -0
- package/dist/auth/client/in-memory.d.ts +27 -0
- package/dist/auth/client/in-memory.d.ts.map +1 -0
- package/dist/auth/client/in-memory.js +242 -0
- package/dist/auth/client/index.d.ts +7 -0
- package/dist/auth/client/index.d.ts.map +1 -0
- package/dist/auth/client/index.js +7 -0
- package/dist/auth/client/interface.d.ts +115 -0
- package/dist/auth/client/interface.d.ts.map +1 -0
- package/dist/auth/client/interface.js +7 -0
- package/dist/auth/client/keycloak.d.ts +19 -0
- package/dist/auth/client/keycloak.d.ts.map +1 -0
- package/dist/auth/client/keycloak.js +126 -0
- package/dist/auth/components/UserSelector.d.ts +19 -0
- package/dist/auth/components/UserSelector.d.ts.map +1 -0
- package/dist/auth/components/UserSelector.js +100 -0
- package/dist/auth/components/index.d.ts +5 -0
- package/dist/auth/components/index.d.ts.map +1 -0
- package/dist/auth/components/index.js +4 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +7 -0
- package/dist/components/AuthProvider.d.ts +48 -0
- package/dist/components/AuthProvider.d.ts.map +1 -0
- package/dist/components/AuthProvider.js +117 -0
- package/dist/hooks/useAuth.d.ts +21 -0
- package/dist/hooks/useAuth.d.ts.map +1 -0
- package/dist/hooks/useAuth.js +34 -0
- package/dist/hooks/useFetch.d.ts +8 -0
- package/dist/hooks/useFetch.d.ts.map +1 -0
- package/dist/hooks/useFetch.js +31 -0
- package/dist/hooks/useI18n.d.ts +46 -0
- package/dist/hooks/useI18n.d.ts.map +1 -0
- package/dist/hooks/useI18n.js +95 -0
- package/dist/hooks/usePlatformAPI.d.ts +12 -0
- package/dist/hooks/usePlatformAPI.d.ts.map +1 -0
- package/dist/hooks/usePlatformAPI.js +10 -0
- package/dist/hooks/useTelemetry.d.ts +17 -0
- package/dist/hooks/useTelemetry.d.ts.map +1 -0
- package/dist/hooks/useTelemetry.js +36 -0
- package/dist/i18n/config.d.ts +26 -0
- package/dist/i18n/config.d.ts.map +1 -0
- package/dist/i18n/config.js +92 -0
- package/dist/i18n/index.d.ts +6 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/locales/en-US.json +144 -0
- package/dist/i18n/locales/es.json +144 -0
- package/dist/i18n/locales/pt-BR.json +144 -0
- package/dist/i18n/locales/ro.json +144 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/registry/AdminShellRegistry.d.ts +140 -0
- package/dist/registry/AdminShellRegistry.d.ts.map +1 -0
- package/dist/registry/AdminShellRegistry.js +237 -0
- package/dist/registry/client/http.d.ts +21 -0
- package/dist/registry/client/http.d.ts.map +1 -0
- package/dist/registry/client/http.js +107 -0
- package/dist/registry/client/in-memory.d.ts +36 -0
- package/dist/registry/client/in-memory.d.ts.map +1 -0
- package/dist/registry/client/in-memory.js +242 -0
- package/dist/registry/client/index.d.ts +7 -0
- package/dist/registry/client/index.d.ts.map +1 -0
- package/dist/registry/client/index.js +5 -0
- package/dist/registry/client/interface.d.ts +96 -0
- package/dist/registry/client/interface.d.ts.map +1 -0
- package/dist/registry/client/interface.js +7 -0
- package/dist/registry/index.d.ts +12 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/types/index.d.ts +9 -0
- package/dist/registry/types/index.d.ts.map +1 -0
- package/dist/registry/types/index.js +6 -0
- package/dist/registry/types/manifest.d.ts +98 -0
- package/dist/registry/types/manifest.d.ts.map +1 -0
- package/dist/registry/types/manifest.js +81 -0
- package/dist/registry/types/module.d.ts +115 -0
- package/dist/registry/types/module.d.ts.map +1 -0
- package/dist/registry/types/module.js +6 -0
- package/dist/router/DynamicModule.d.ts +50 -0
- package/dist/router/DynamicModule.d.ts.map +1 -0
- package/dist/router/DynamicModule.js +141 -0
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +1 -0
- package/dist/shell/AdminShell.d.ts +38 -0
- package/dist/shell/AdminShell.d.ts.map +1 -0
- package/dist/shell/AdminShell.js +299 -0
- package/dist/shell/BackofficeShell.d.ts +38 -0
- package/dist/shell/BackofficeShell.d.ts.map +1 -0
- package/dist/shell/BackofficeShell.js +299 -0
- package/dist/shell/components/CommandPalette.d.ts +8 -0
- package/dist/shell/components/CommandPalette.d.ts.map +1 -0
- package/dist/shell/components/CommandPalette.js +197 -0
- package/dist/shell/components/HomePage.d.ts +2 -0
- package/dist/shell/components/HomePage.d.ts.map +1 -0
- package/dist/shell/components/HomePage.js +32 -0
- package/dist/shell/components/LeftNav.d.ts +7 -0
- package/dist/shell/components/LeftNav.d.ts.map +1 -0
- package/dist/shell/components/LeftNav.js +247 -0
- package/dist/shell/components/MainContent.d.ts +9 -0
- package/dist/shell/components/MainContent.d.ts.map +1 -0
- package/dist/shell/components/MainContent.js +88 -0
- package/dist/shell/components/ModuleOverview.d.ts +7 -0
- package/dist/shell/components/ModuleOverview.d.ts.map +1 -0
- package/dist/shell/components/ModuleOverview.js +40 -0
- package/dist/shell/components/ProfilePage.d.ts +2 -0
- package/dist/shell/components/ProfilePage.d.ts.map +1 -0
- package/dist/shell/components/ProfilePage.js +30 -0
- package/dist/shell/components/RegistryPage.d.ts +8 -0
- package/dist/shell/components/RegistryPage.d.ts.map +1 -0
- package/dist/shell/components/RegistryPage.js +129 -0
- package/dist/shell/components/SettingsPage.d.ts +2 -0
- package/dist/shell/components/SettingsPage.d.ts.map +1 -0
- package/dist/shell/components/SettingsPage.js +60 -0
- package/dist/shell/components/TopBar.d.ts +8 -0
- package/dist/shell/components/TopBar.d.ts.map +1 -0
- package/dist/shell/components/TopBar.js +61 -0
- package/dist/shell/components/index.d.ts +10 -0
- package/dist/shell/components/index.d.ts.map +1 -0
- package/dist/shell/components/index.js +7 -0
- package/dist/shell/components/theme-provider.d.ts +15 -0
- package/dist/shell/components/theme-provider.d.ts.map +1 -0
- package/dist/shell/components/theme-provider.js +39 -0
- package/dist/shell/index.d.ts +9 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +8 -0
- package/dist/shell/search/fuzzy.d.ts +18 -0
- package/dist/shell/search/fuzzy.d.ts.map +1 -0
- package/dist/shell/search/fuzzy.js +121 -0
- package/dist/shell/search/index.d.ts +3 -0
- package/dist/shell/search/index.d.ts.map +1 -0
- package/dist/shell/search/index.js +1 -0
- package/dist/shell/telemetry.d.ts +7 -0
- package/dist/shell/telemetry.d.ts.map +1 -0
- package/dist/shell/telemetry.js +25 -0
- package/dist/shell/types.d.ts +110 -0
- package/dist/shell/types.d.ts.map +1 -0
- package/dist/shell/types.js +4 -0
- package/dist/tailwind/index.d.ts +20 -0
- package/dist/tailwind/index.d.ts.map +1 -0
- package/dist/tailwind/index.js +42 -0
- package/dist/types/keycloak.d.ts +26 -0
- package/dist/types/keycloak.d.ts.map +1 -0
- package/dist/types/keycloak.js +1 -0
- package/dist/types/platform.d.ts +83 -0
- package/dist/types/platform.d.ts.map +1 -0
- package/dist/types/platform.js +5 -0
- package/dist/vite/config.d.ts +71 -0
- package/dist/vite/config.d.ts.map +1 -0
- package/dist/vite/config.js +87 -0
- package/dist/vite/index.d.ts +18 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +17 -0
- package/dist/vite/plugins.d.ts +44 -0
- package/dist/vite/plugins.d.ts.map +1 -0
- package/dist/vite/plugins.js +74 -0
- package/package.json +86 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry Context API
|
|
3
|
+
*
|
|
4
|
+
* Provides a React context for accessing the module registry throughout the app.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* // 1. Create the registry client
|
|
9
|
+
* const registry = createInMemoryRegistryClient({ seed: [...] });
|
|
10
|
+
*
|
|
11
|
+
* // 2. Wrap your app with the provider
|
|
12
|
+
* function App() {
|
|
13
|
+
* return (
|
|
14
|
+
* <AdminShellRegistry store={registry}>
|
|
15
|
+
* <MyApp />
|
|
16
|
+
* </AdminShellRegistry>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // 3. Use the hook in any component
|
|
21
|
+
* function ModuleList() {
|
|
22
|
+
* const { modules, isLoading, deleteModule } = useRegistry();
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { type ReactNode } from 'react';
|
|
28
|
+
import type { RegistryClient } from './client/interface';
|
|
29
|
+
import type { RegisteredModule, UpdateModuleDto, AdminModuleManifest } from './types';
|
|
30
|
+
/**
|
|
31
|
+
* Registry context value
|
|
32
|
+
*/
|
|
33
|
+
export interface RegistryContextValue {
|
|
34
|
+
/** The underlying registry client */
|
|
35
|
+
client: RegistryClient;
|
|
36
|
+
/** List of all registered modules */
|
|
37
|
+
modules: RegisteredModule[];
|
|
38
|
+
/** Whether modules are currently being loaded */
|
|
39
|
+
isLoading: boolean;
|
|
40
|
+
/** Error from the last operation, if any */
|
|
41
|
+
error: Error | null;
|
|
42
|
+
/** Reload modules from the registry */
|
|
43
|
+
reload: () => Promise<void>;
|
|
44
|
+
/** Register a new module from manifest */
|
|
45
|
+
registerModule: (manifest: AdminModuleManifest, baseUrl?: string) => Promise<RegisteredModule>;
|
|
46
|
+
/** Register a new module by URL (fetches admin.module.json) */
|
|
47
|
+
registerModuleByUrl: (baseUrl: string) => Promise<RegisteredModule>;
|
|
48
|
+
/** Update a module */
|
|
49
|
+
updateModule: (id: number, data: UpdateModuleDto) => Promise<RegisteredModule>;
|
|
50
|
+
/** Delete a module */
|
|
51
|
+
deleteModule: (id: number) => Promise<void>;
|
|
52
|
+
/** Reorder modules */
|
|
53
|
+
reorderModules: (order: Array<{
|
|
54
|
+
id: number;
|
|
55
|
+
navOrder: number;
|
|
56
|
+
}>) => Promise<void>;
|
|
57
|
+
/** Get a single module by ID */
|
|
58
|
+
getModule: (id: number) => RegisteredModule | undefined;
|
|
59
|
+
/** Get enabled modules only */
|
|
60
|
+
enabledModules: RegisteredModule[];
|
|
61
|
+
/** Get modules by category */
|
|
62
|
+
getModulesByCategory: (category: string) => RegisteredModule[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Props for AdminShellRegistry provider
|
|
66
|
+
*/
|
|
67
|
+
export interface AdminShellRegistryProps {
|
|
68
|
+
/** The registry client instance */
|
|
69
|
+
store: RegistryClient;
|
|
70
|
+
/** Child components */
|
|
71
|
+
children: ReactNode;
|
|
72
|
+
/** Called when modules change (for external sync) */
|
|
73
|
+
onModulesChange?: (modules: RegisteredModule[]) => void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Registry provider component
|
|
77
|
+
*
|
|
78
|
+
* Wrap your app with this component to provide registry access to all children.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* const registry = createInMemoryRegistryClient({ seed: myModules });
|
|
83
|
+
*
|
|
84
|
+
* function App() {
|
|
85
|
+
* return (
|
|
86
|
+
* <AdminShellRegistry store={registry}>
|
|
87
|
+
* <Router>
|
|
88
|
+
* <Routes />
|
|
89
|
+
* </Router>
|
|
90
|
+
* </AdminShellRegistry>
|
|
91
|
+
* );
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function AdminShellRegistry({ store, children, onModulesChange, }: AdminShellRegistryProps): import("react/jsx-runtime").JSX.Element;
|
|
96
|
+
/**
|
|
97
|
+
* Hook to access the registry context
|
|
98
|
+
*
|
|
99
|
+
* @throws Error if used outside of AdminShellRegistry provider
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* function ModuleList() {
|
|
104
|
+
* const { modules, isLoading, deleteModule } = useRegistry();
|
|
105
|
+
*
|
|
106
|
+
* if (isLoading) return <Loading />;
|
|
107
|
+
*
|
|
108
|
+
* return (
|
|
109
|
+
* <ul>
|
|
110
|
+
* {modules.map((m) => (
|
|
111
|
+
* <li key={m.id}>
|
|
112
|
+
* {m.manifest.title}
|
|
113
|
+
* <button onClick={() => deleteModule(m.id)}>Delete</button>
|
|
114
|
+
* </li>
|
|
115
|
+
* ))}
|
|
116
|
+
* </ul>
|
|
117
|
+
* );
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function useRegistry(): RegistryContextValue;
|
|
122
|
+
/**
|
|
123
|
+
* Hook to access just the registry client
|
|
124
|
+
*
|
|
125
|
+
* Use this when you only need the raw client without the managed state.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* function CustomOperation() {
|
|
130
|
+
* const client = useRegistryClient();
|
|
131
|
+
*
|
|
132
|
+
* const handleCustom = async () => {
|
|
133
|
+
* const catalog = await client.catalog.get();
|
|
134
|
+
* // ...
|
|
135
|
+
* };
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function useRegistryClient(): RegistryClient;
|
|
140
|
+
//# sourceMappingURL=AdminShellRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdminShellRegistry.d.ts","sourceRoot":"","sources":["../../src/registry/AdminShellRegistry.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,MAAM,EAAE,cAAc,CAAC;IAEvB,qCAAqC;IACrC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAE5B,iDAAiD;IACjD,SAAS,EAAE,OAAO,CAAC;IAEnB,4CAA4C;IAC5C,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,uCAAuC;IACvC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,0CAA0C;IAC1C,cAAc,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE/F,+DAA+D;IAC/D,mBAAmB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAEpE,sBAAsB;IACtB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE/E,sBAAsB;IACtB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C,sBAAsB;IACtB,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAElF,gCAAgC;IAChC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS,CAAC;IAExD,+BAA+B;IAC/B,cAAc,EAAE,gBAAgB,EAAE,CAAC;IAEnC,8BAA8B;IAC9B,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,gBAAgB,EAAE,CAAC;CAChE;AAID;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,KAAK,EAAE,cAAc,CAAC;IAEtB,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;IAEpB,qDAAqD;IACrD,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;CACzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,eAAe,GAChB,EAAE,uBAAuB,2CAiKzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,wBAAgB,WAAW,IAAI,oBAAoB,CAMlD;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,iBAAiB,IAAI,cAAc,CAMlD"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Registry Context API
|
|
4
|
+
*
|
|
5
|
+
* Provides a React context for accessing the module registry throughout the app.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // 1. Create the registry client
|
|
10
|
+
* const registry = createInMemoryRegistryClient({ seed: [...] });
|
|
11
|
+
*
|
|
12
|
+
* // 2. Wrap your app with the provider
|
|
13
|
+
* function App() {
|
|
14
|
+
* return (
|
|
15
|
+
* <AdminShellRegistry store={registry}>
|
|
16
|
+
* <MyApp />
|
|
17
|
+
* </AdminShellRegistry>
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // 3. Use the hook in any component
|
|
22
|
+
* function ModuleList() {
|
|
23
|
+
* const { modules, isLoading, deleteModule } = useRegistry();
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { createContext, useContext, useState, useEffect, useCallback, useMemo, } from 'react';
|
|
29
|
+
const RegistryContext = createContext(null);
|
|
30
|
+
/**
|
|
31
|
+
* Registry provider component
|
|
32
|
+
*
|
|
33
|
+
* Wrap your app with this component to provide registry access to all children.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const registry = createInMemoryRegistryClient({ seed: myModules });
|
|
38
|
+
*
|
|
39
|
+
* function App() {
|
|
40
|
+
* return (
|
|
41
|
+
* <AdminShellRegistry store={registry}>
|
|
42
|
+
* <Router>
|
|
43
|
+
* <Routes />
|
|
44
|
+
* </Router>
|
|
45
|
+
* </AdminShellRegistry>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function AdminShellRegistry({ store, children, onModulesChange, }) {
|
|
51
|
+
const [modules, setModules] = useState([]);
|
|
52
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
53
|
+
const [error, setError] = useState(null);
|
|
54
|
+
// Load modules from registry
|
|
55
|
+
const reload = useCallback(async () => {
|
|
56
|
+
setIsLoading(true);
|
|
57
|
+
setError(null);
|
|
58
|
+
try {
|
|
59
|
+
const result = await store.modules.findAll();
|
|
60
|
+
setModules(result);
|
|
61
|
+
onModulesChange?.(result);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
setError(err instanceof Error ? err : new Error('Failed to load modules'));
|
|
65
|
+
console.error('[Registry] Failed to load modules:', err);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
setIsLoading(false);
|
|
69
|
+
}
|
|
70
|
+
}, [store, onModulesChange]);
|
|
71
|
+
// Initial load
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
reload();
|
|
74
|
+
}, [reload]);
|
|
75
|
+
// Register module from manifest
|
|
76
|
+
const registerModule = useCallback(async (manifest, baseUrl) => {
|
|
77
|
+
setError(null);
|
|
78
|
+
try {
|
|
79
|
+
const newModule = await store.modules.registerFromManifest(manifest, baseUrl);
|
|
80
|
+
await reload();
|
|
81
|
+
return newModule;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
const error = err instanceof Error ? err : new Error('Failed to register module');
|
|
85
|
+
setError(error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}, [store, reload]);
|
|
89
|
+
// Register module by URL
|
|
90
|
+
const registerModuleByUrl = useCallback(async (baseUrl) => {
|
|
91
|
+
setError(null);
|
|
92
|
+
try {
|
|
93
|
+
const newModule = await store.modules.register(baseUrl);
|
|
94
|
+
await reload();
|
|
95
|
+
return newModule;
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
const error = err instanceof Error ? err : new Error('Failed to register module');
|
|
99
|
+
setError(error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}, [store, reload]);
|
|
103
|
+
// Update module
|
|
104
|
+
const updateModule = useCallback(async (id, data) => {
|
|
105
|
+
setError(null);
|
|
106
|
+
try {
|
|
107
|
+
const updated = await store.modules.update(id, data);
|
|
108
|
+
await reload();
|
|
109
|
+
return updated;
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
const error = err instanceof Error ? err : new Error('Failed to update module');
|
|
113
|
+
setError(error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}, [store, reload]);
|
|
117
|
+
// Delete module
|
|
118
|
+
const deleteModule = useCallback(async (id) => {
|
|
119
|
+
setError(null);
|
|
120
|
+
try {
|
|
121
|
+
await store.modules.delete(id);
|
|
122
|
+
await reload();
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
const error = err instanceof Error ? err : new Error('Failed to delete module');
|
|
126
|
+
setError(error);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}, [store, reload]);
|
|
130
|
+
// Reorder modules
|
|
131
|
+
const reorderModules = useCallback(async (order) => {
|
|
132
|
+
setError(null);
|
|
133
|
+
try {
|
|
134
|
+
await store.modules.reorder(order);
|
|
135
|
+
await reload();
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
const error = err instanceof Error ? err : new Error('Failed to reorder modules');
|
|
139
|
+
setError(error);
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}, [store, reload]);
|
|
143
|
+
// Get single module
|
|
144
|
+
const getModule = useCallback((id) => modules.find((m) => m.id === id), [modules]);
|
|
145
|
+
// Enabled modules only
|
|
146
|
+
const enabledModules = useMemo(() => modules.filter((m) => m.enabled), [modules]);
|
|
147
|
+
// Get modules by category
|
|
148
|
+
const getModulesByCategory = useCallback((category) => modules.filter((m) => m.manifest.category === category), [modules]);
|
|
149
|
+
const value = useMemo(() => ({
|
|
150
|
+
client: store,
|
|
151
|
+
modules,
|
|
152
|
+
isLoading,
|
|
153
|
+
error,
|
|
154
|
+
reload,
|
|
155
|
+
registerModule,
|
|
156
|
+
registerModuleByUrl,
|
|
157
|
+
updateModule,
|
|
158
|
+
deleteModule,
|
|
159
|
+
reorderModules,
|
|
160
|
+
getModule,
|
|
161
|
+
enabledModules,
|
|
162
|
+
getModulesByCategory,
|
|
163
|
+
}), [
|
|
164
|
+
store,
|
|
165
|
+
modules,
|
|
166
|
+
isLoading,
|
|
167
|
+
error,
|
|
168
|
+
reload,
|
|
169
|
+
registerModule,
|
|
170
|
+
registerModuleByUrl,
|
|
171
|
+
updateModule,
|
|
172
|
+
deleteModule,
|
|
173
|
+
reorderModules,
|
|
174
|
+
getModule,
|
|
175
|
+
enabledModules,
|
|
176
|
+
getModulesByCategory,
|
|
177
|
+
]);
|
|
178
|
+
return _jsx(RegistryContext.Provider, { value: value, children: children });
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Hook to access the registry context
|
|
182
|
+
*
|
|
183
|
+
* @throws Error if used outside of AdminShellRegistry provider
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* function ModuleList() {
|
|
188
|
+
* const { modules, isLoading, deleteModule } = useRegistry();
|
|
189
|
+
*
|
|
190
|
+
* if (isLoading) return <Loading />;
|
|
191
|
+
*
|
|
192
|
+
* return (
|
|
193
|
+
* <ul>
|
|
194
|
+
* {modules.map((m) => (
|
|
195
|
+
* <li key={m.id}>
|
|
196
|
+
* {m.manifest.title}
|
|
197
|
+
* <button onClick={() => deleteModule(m.id)}>Delete</button>
|
|
198
|
+
* </li>
|
|
199
|
+
* ))}
|
|
200
|
+
* </ul>
|
|
201
|
+
* );
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
206
|
+
export function useRegistry() {
|
|
207
|
+
const context = useContext(RegistryContext);
|
|
208
|
+
if (!context) {
|
|
209
|
+
throw new Error('useRegistry must be used within an AdminShellRegistry provider');
|
|
210
|
+
}
|
|
211
|
+
return context;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Hook to access just the registry client
|
|
215
|
+
*
|
|
216
|
+
* Use this when you only need the raw client without the managed state.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* function CustomOperation() {
|
|
221
|
+
* const client = useRegistryClient();
|
|
222
|
+
*
|
|
223
|
+
* const handleCustom = async () => {
|
|
224
|
+
* const catalog = await client.catalog.get();
|
|
225
|
+
* // ...
|
|
226
|
+
* };
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
231
|
+
export function useRegistryClient() {
|
|
232
|
+
const context = useContext(RegistryContext);
|
|
233
|
+
if (!context) {
|
|
234
|
+
throw new Error('useRegistryClient must be used within an AdminShellRegistry provider');
|
|
235
|
+
}
|
|
236
|
+
return context.client;
|
|
237
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Registry Client
|
|
3
|
+
*
|
|
4
|
+
* Implementation of RegistryClient that communicates with the admin-api.
|
|
5
|
+
* Used when running with PostgreSQL backend.
|
|
6
|
+
*/
|
|
7
|
+
import type { RegistryClient } from './interface';
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating an HTTP registry client
|
|
10
|
+
*/
|
|
11
|
+
export interface HttpRegistryOptions {
|
|
12
|
+
/** Base URL of the API (e.g., 'http://localhost:4000/api') */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** Optional fetch options (headers, etc.) */
|
|
15
|
+
fetchOptions?: RequestInit;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create an HTTP registry client
|
|
19
|
+
*/
|
|
20
|
+
export declare function createHttpRegistryClient(options: HttpRegistryOptions): RegistryClient;
|
|
21
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/registry/client/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,aAAa,CAAA;AAEtF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAA;IACf,6CAA6C;IAC7C,YAAY,CAAC,EAAE,WAAW,CAAA;CAC3B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAyHrF"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Registry Client
|
|
3
|
+
*
|
|
4
|
+
* Implementation of RegistryClient that communicates with the admin-api.
|
|
5
|
+
* Used when running with PostgreSQL backend.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create an HTTP registry client
|
|
9
|
+
*/
|
|
10
|
+
export function createHttpRegistryClient(options) {
|
|
11
|
+
const { baseUrl, fetchOptions = {} } = options;
|
|
12
|
+
const defaultHeaders = {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
...fetchOptions.headers,
|
|
15
|
+
};
|
|
16
|
+
async function request(path, init) {
|
|
17
|
+
const url = `${baseUrl}${path}`;
|
|
18
|
+
const response = await fetch(url, {
|
|
19
|
+
...fetchOptions,
|
|
20
|
+
...init,
|
|
21
|
+
headers: {
|
|
22
|
+
...defaultHeaders,
|
|
23
|
+
...init?.headers,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
const error = await response.text();
|
|
28
|
+
throw new Error(`API request failed: ${response.status} - ${error}`);
|
|
29
|
+
}
|
|
30
|
+
// Handle empty responses (e.g., DELETE)
|
|
31
|
+
const text = await response.text();
|
|
32
|
+
if (!text) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return JSON.parse(text);
|
|
36
|
+
}
|
|
37
|
+
// Module operations
|
|
38
|
+
const modules = {
|
|
39
|
+
async findAll(filters) {
|
|
40
|
+
const params = new URLSearchParams();
|
|
41
|
+
if (filters?.enabled !== undefined) {
|
|
42
|
+
params.set('enabled', String(filters.enabled));
|
|
43
|
+
}
|
|
44
|
+
if (filters?.category) {
|
|
45
|
+
params.set('category', filters.category);
|
|
46
|
+
}
|
|
47
|
+
if (filters?.status) {
|
|
48
|
+
params.set('status', filters.status);
|
|
49
|
+
}
|
|
50
|
+
const query = params.toString();
|
|
51
|
+
const path = query ? `/modules?${query}` : '/modules';
|
|
52
|
+
return request(path);
|
|
53
|
+
},
|
|
54
|
+
async find(id) {
|
|
55
|
+
return request(`/modules/${id}`);
|
|
56
|
+
},
|
|
57
|
+
async register(baseUrl) {
|
|
58
|
+
return request('/modules', {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
body: JSON.stringify({ baseUrl }),
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
async registerFromManifest(manifest, baseUrl = '') {
|
|
64
|
+
return request('/modules/manifest', {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
body: JSON.stringify({ manifest, baseUrl }),
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
async update(id, data) {
|
|
70
|
+
return request(`/modules/${id}`, {
|
|
71
|
+
method: 'PATCH',
|
|
72
|
+
body: JSON.stringify(data),
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async delete(id) {
|
|
76
|
+
await request(`/modules/${id}`, {
|
|
77
|
+
method: 'DELETE',
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async reorder(order) {
|
|
81
|
+
await request('/modules/reorder', {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
body: JSON.stringify(order),
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
// Catalog operations
|
|
88
|
+
const catalog = {
|
|
89
|
+
async get() {
|
|
90
|
+
return request('/catalog');
|
|
91
|
+
},
|
|
92
|
+
async getImportMap(_environment) {
|
|
93
|
+
// Generate import map from catalog baseUrl
|
|
94
|
+
const catalogData = await this.get();
|
|
95
|
+
const imports = {};
|
|
96
|
+
for (const m of catalogData.modules) {
|
|
97
|
+
if (m.baseUrl) {
|
|
98
|
+
// Note: This import map is deprecated - DynamicModule fetches manifest at runtime
|
|
99
|
+
const base = m.baseUrl.endsWith('/') ? m.baseUrl.slice(0, -1) : m.baseUrl;
|
|
100
|
+
imports[m.id] = `${base}/module.manifest.json`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { imports };
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
return { modules, catalog };
|
|
107
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-Memory Registry Client
|
|
3
|
+
*
|
|
4
|
+
* Implementation of RegistryClient that stores data in localStorage.
|
|
5
|
+
* Used for local development and testing without a backend.
|
|
6
|
+
*/
|
|
7
|
+
import type { AdminModuleManifest } from '../types';
|
|
8
|
+
import type { RegistryClient } from './interface';
|
|
9
|
+
/**
|
|
10
|
+
* Pre-configured module with baseUrl
|
|
11
|
+
* Note: entry is not stored - DynamicModule fetches module.manifest.json at runtime
|
|
12
|
+
*/
|
|
13
|
+
export interface PreConfiguredModule extends AdminModuleManifest {
|
|
14
|
+
/** Base URL where module is served (e.g., http://localhost:3003) */
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for creating an in-memory registry client
|
|
19
|
+
*/
|
|
20
|
+
export interface InMemoryRegistryOptions {
|
|
21
|
+
/** Seed with manifest JSONs directly (without baseUrl) */
|
|
22
|
+
seed?: AdminModuleManifest[];
|
|
23
|
+
/** Pre-configured modules with baseUrl (for Docker/production setups) */
|
|
24
|
+
initialModules?: PreConfiguredModule[];
|
|
25
|
+
/** localStorage key prefix (defaults to '@nsxbet/registry') */
|
|
26
|
+
storageKey?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create an in-memory registry client
|
|
30
|
+
*/
|
|
31
|
+
export declare function createInMemoryRegistryClient(options?: InMemoryRegistryOptions): RegistryClient;
|
|
32
|
+
/**
|
|
33
|
+
* Clear all registry data from localStorage
|
|
34
|
+
*/
|
|
35
|
+
export declare function clearInMemoryRegistry(storageKey?: string): void;
|
|
36
|
+
//# sourceMappingURL=in-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../src/registry/client/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAQV,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,aAAa,CAAC;AAEvF;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC7B,yEAAyE;IACzE,cAAc,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACvC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAYD;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,uBAA4B,GACpC,cAAc,CA6OhB;AA4BD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,GAAE,MAA4B,GAAG,IAAI,CAEpF"}
|