dynim-react 1.0.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.
Files changed (47) hide show
  1. package/README.md +447 -0
  2. package/dist/builder/BuilderProvider.d.ts +99 -0
  3. package/dist/builder/BuilderProvider.d.ts.map +1 -0
  4. package/dist/builder/BuilderProvider.js +339 -0
  5. package/dist/builder/ChatContext.d.ts +11 -0
  6. package/dist/builder/ChatContext.d.ts.map +1 -0
  7. package/dist/builder/ChatContext.js +18 -0
  8. package/dist/builder/ChatInput.d.ts +11 -0
  9. package/dist/builder/ChatInput.d.ts.map +1 -0
  10. package/dist/builder/ChatInput.js +20 -0
  11. package/dist/builder/CodeChatPanel.d.ts +24 -0
  12. package/dist/builder/CodeChatPanel.d.ts.map +1 -0
  13. package/dist/builder/CodeChatPanel.js +299 -0
  14. package/dist/builder/EditableZone.d.ts +73 -0
  15. package/dist/builder/EditableZone.d.ts.map +1 -0
  16. package/dist/builder/EditableZone.js +83 -0
  17. package/dist/builder/MessageList.d.ts +14 -0
  18. package/dist/builder/MessageList.d.ts.map +1 -0
  19. package/dist/builder/MessageList.js +23 -0
  20. package/dist/builder/index.d.ts +18 -0
  21. package/dist/builder/index.d.ts.map +1 -0
  22. package/dist/builder/index.js +15 -0
  23. package/dist/builder/useChatbot.d.ts +24 -0
  24. package/dist/builder/useChatbot.d.ts.map +1 -0
  25. package/dist/builder/useChatbot.js +85 -0
  26. package/dist/index.d.ts +14 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +24 -0
  29. package/dist/inference/DynimProvider.d.ts +23 -0
  30. package/dist/inference/DynimProvider.d.ts.map +1 -0
  31. package/dist/inference/DynimProvider.js +231 -0
  32. package/dist/inference/InferenceProvider.d.ts +23 -0
  33. package/dist/inference/InferenceProvider.d.ts.map +1 -0
  34. package/dist/inference/InferenceProvider.js +270 -0
  35. package/dist/inference/createDynimSDK.d.ts +39 -0
  36. package/dist/inference/createDynimSDK.d.ts.map +1 -0
  37. package/dist/inference/createDynimSDK.js +61 -0
  38. package/dist/inference/index.d.ts +7 -0
  39. package/dist/inference/index.d.ts.map +1 -0
  40. package/dist/inference/index.js +7 -0
  41. package/dist/inference/sharedContext.d.ts +39 -0
  42. package/dist/inference/sharedContext.d.ts.map +1 -0
  43. package/dist/inference/sharedContext.js +61 -0
  44. package/dist/inference/types.d.ts +67 -0
  45. package/dist/inference/types.d.ts.map +1 -0
  46. package/dist/inference/types.js +1 -0
  47. package/package.json +30 -0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Inference exports
3
+ */
4
+ export { InferenceProvider, default as InferenceProviderDefault } from './InferenceProvider';
5
+ export { createSharedContext, getSharedContext, isSharedContextReady, } from './sharedContext';
6
+ export type { DynimSDKConfig, InferenceProviderProps, InferenceState, DynimGlobal } from './types';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAG7F,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Inference exports
3
+ */
4
+ // Components
5
+ export { InferenceProvider, default as InferenceProviderDefault } from './InferenceProvider';
6
+ // Shared context utilities
7
+ export { createSharedContext, getSharedContext, isSharedContextReady, } from './sharedContext';
@@ -0,0 +1,39 @@
1
+ import type { DynimSDKConfig, DynimGlobal } from './types';
2
+ /**
3
+ * Creates and registers the shared context on the window object.
4
+ * This makes React, ReactDOM, hooks, and contexts available to tenant bundles.
5
+ *
6
+ * @param config - Configuration object containing React, ReactDOM, hooks, and contexts
7
+ * @returns The created SDK object
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { createSharedContext } from 'dynim-react';
12
+ * import React from 'react';
13
+ * import ReactDOM from 'react-dom';
14
+ * import { useAuth, useNotifications } from './hooks';
15
+ * import { AuthContext, NotificationContext } from './contexts';
16
+ *
17
+ * createSharedContext({
18
+ * React,
19
+ * ReactDOM,
20
+ * hooks: { useAuth, useNotifications },
21
+ * contexts: { AuthContext, NotificationContext }
22
+ * });
23
+ * ```
24
+ */
25
+ export declare function createSharedContext(config: DynimSDKConfig): DynimGlobal;
26
+ /**
27
+ * Gets the current shared context instance from the window object.
28
+ * Useful for tenant bundles to access the SDK.
29
+ *
30
+ * @returns The shared context instance or undefined if not initialized
31
+ */
32
+ export declare function getSharedContext(): DynimGlobal | undefined;
33
+ /**
34
+ * Checks if the shared context has been initialized.
35
+ *
36
+ * @returns true if the shared context is available
37
+ */
38
+ export declare function isSharedContextReady(): boolean;
39
+ //# sourceMappingURL=sharedContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedContext.d.ts","sourceRoot":"","sources":["../../src/inference/sharedContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAqBvE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,GAAG,SAAS,CAK1D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Creates and registers the shared context on the window object.
3
+ * This makes React, ReactDOM, hooks, and contexts available to tenant bundles.
4
+ *
5
+ * @param config - Configuration object containing React, ReactDOM, hooks, and contexts
6
+ * @returns The created SDK object
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { createSharedContext } from 'dynim-react';
11
+ * import React from 'react';
12
+ * import ReactDOM from 'react-dom';
13
+ * import { useAuth, useNotifications } from './hooks';
14
+ * import { AuthContext, NotificationContext } from './contexts';
15
+ *
16
+ * createSharedContext({
17
+ * React,
18
+ * ReactDOM,
19
+ * hooks: { useAuth, useNotifications },
20
+ * contexts: { AuthContext, NotificationContext }
21
+ * });
22
+ * ```
23
+ */
24
+ export function createSharedContext(config) {
25
+ const { React, ReactDOM, hooks = {}, contexts = {}, globals = {} } = config;
26
+ const sdk = {
27
+ React,
28
+ ReactDOM,
29
+ hooks,
30
+ contexts,
31
+ ...globals,
32
+ };
33
+ // Register on window for tenant bundles to access
34
+ if (typeof window !== 'undefined') {
35
+ window.__DYNIM__ = sdk;
36
+ // Also expose React and ReactDOM directly on window for bundles using standard imports
37
+ window.React = React;
38
+ window.ReactDOM = ReactDOM;
39
+ }
40
+ return sdk;
41
+ }
42
+ /**
43
+ * Gets the current shared context instance from the window object.
44
+ * Useful for tenant bundles to access the SDK.
45
+ *
46
+ * @returns The shared context instance or undefined if not initialized
47
+ */
48
+ export function getSharedContext() {
49
+ if (typeof window !== 'undefined') {
50
+ return window.__DYNIM__;
51
+ }
52
+ return undefined;
53
+ }
54
+ /**
55
+ * Checks if the shared context has been initialized.
56
+ *
57
+ * @returns true if the shared context is available
58
+ */
59
+ export function isSharedContextReady() {
60
+ return typeof window !== 'undefined' && window.__DYNIM__ !== undefined;
61
+ }
@@ -0,0 +1,67 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * Configuration for the Dynim SDK registration
4
+ */
5
+ export interface DynimSDKConfig {
6
+ /** React library instance to expose globally */
7
+ React: typeof import('react');
8
+ /** ReactDOM library instance to expose globally */
9
+ ReactDOM: typeof import('react-dom');
10
+ /** Custom hooks to expose to tenant bundles */
11
+ hooks?: Record<string, unknown>;
12
+ /** React contexts to expose to tenant bundles */
13
+ contexts?: Record<string, unknown>;
14
+ /** Additional globals to expose */
15
+ globals?: Record<string, unknown>;
16
+ }
17
+ /**
18
+ * Props for the InferenceProvider component
19
+ */
20
+ export interface InferenceProviderProps {
21
+ /** Current tenant ID, null if no tenant */
22
+ tenantId: string | null;
23
+ /** URL or URL builder function for loading tenant bundles */
24
+ bundleUrl: string | ((tenantId: string) => string);
25
+ /**
26
+ * Temporary token for authenticated bundle fetching (temp_...).
27
+ * When provided, bundles are fetched via fetch() with Authorization header
28
+ * instead of script tag injection.
29
+ */
30
+ bundleToken?: string;
31
+ /** Optional async function to check if tenant has customizations before loading */
32
+ checkCustomizations?: (tenantId: string) => Promise<boolean>;
33
+ /** Custom loading component to show while bundle is loading */
34
+ loadingComponent?: ReactNode;
35
+ /** Show error banner on load failure. Can be boolean or custom ReactNode */
36
+ errorBanner?: boolean | ReactNode;
37
+ /** Callback when bundle fails to load */
38
+ onError?: (error: Error, tenantId: string) => void;
39
+ /** Callback when bundle successfully loads */
40
+ onLoad?: (tenantId: string) => void;
41
+ /** Base app to render (used as fallback when no customizations) */
42
+ children: ReactNode;
43
+ }
44
+ /**
45
+ * Internal state for the InferenceProvider
46
+ */
47
+ export interface InferenceState {
48
+ status: 'idle' | 'checking' | 'loading' | 'loaded' | 'error' | 'no-customization';
49
+ error: Error | null;
50
+ currentTenantId: string | null;
51
+ }
52
+ /**
53
+ * The global SDK object exposed to tenant bundles
54
+ */
55
+ export interface DynimGlobal {
56
+ React: typeof import('react');
57
+ ReactDOM: typeof import('react-dom');
58
+ hooks: Record<string, unknown>;
59
+ contexts: Record<string, unknown>;
60
+ [key: string]: unknown;
61
+ }
62
+ declare global {
63
+ interface Window {
64
+ __DYNIM__?: DynimGlobal;
65
+ }
66
+ }
67
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;IAC7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,IAAI,CAAC;IACpB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,cAAc,OAAO,CAAC,CAAC;IAC9B,QAAQ,EAAE,cAAc,WAAW,CAAC,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,CAAC,EAAE,WAAW,CAAC;KACzB;CACF"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "dynim-react",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "dev": "tsc --watch"
14
+ },
15
+ "dependencies": {
16
+ "dynim-core": "^1.0.0"
17
+ },
18
+ "peerDependencies": {
19
+ "react": ">=17.0.0",
20
+ "react-dom": ">=17.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/react": "^18.3.27",
24
+ "@types/react-dom": "^18.3.7",
25
+ "react": "^19.2.3",
26
+ "react-dom": "^19.2.3",
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "license": "MIT"
30
+ }