@embeddable/sdk 1.0.0 โ†’ 1.0.2

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 CHANGED
@@ -12,7 +12,6 @@ A TypeScript/JavaScript SDK with React utilities and hooks for embeddable applic
12
12
  - ๐Ÿ“ฆ **TypeScript**: Full TypeScript support with type definitions
13
13
  - โš›๏ธ **React Hooks**: Custom hooks for common patterns
14
14
  - ๐Ÿ› ๏ธ **Utilities**: Useful utility functions
15
- - ๐ŸŽจ **Theme Support**: Built-in theme management
16
15
  - ๐Ÿ“ฑ **Storage**: Enhanced localStorage utilities
17
16
  - ๐ŸŒ **API Client**: Type-safe API client with error handling
18
17
  - ๐Ÿงช **Well Tested**: Comprehensive test coverage
@@ -45,6 +44,55 @@ import { useLocalStorage } from '@embeddable/sdk/hooks';
45
44
  import { debounce } from '@embeddable/sdk/utils';
46
45
  ```
47
46
 
47
+ ## Global Configuration
48
+
49
+ The SDK supports global configuration through the `EmbeddableProvider` context. This allows you to set a `widgetId` and `version` and `mode` once and access them throughout your application.
50
+
51
+ ### Setup
52
+
53
+ Wrap your application with the `EmbeddableProvider`:
54
+
55
+ ```typescript
56
+ import { EmbeddableProvider } from '@embeddable/sdk';
57
+ import type { EmbeddableConfig } from '@embeddable/sdk';
58
+
59
+ function App() {
60
+ const config: EmbeddableConfig = {
61
+ widgetId: 'my-widget-123',
62
+ version: '1.0.0', // 'dev' | 'latest' | string
63
+ mode: 'embeddable', // 'embeddable' | 'standalone' | 'preview'
64
+ };
65
+
66
+ return (
67
+ <EmbeddableProvider config={config}>
68
+ <YourAppComponents />
69
+ </EmbeddableProvider>
70
+ );
71
+ }
72
+ ```
73
+
74
+ ### Using Global Configuration
75
+
76
+ Access the global configuration in any component:
77
+
78
+ ```typescript
79
+ import { useEmbeddableConfig, useApi } from '@embeddable/sdk';
80
+
81
+ function WidgetComponent() {
82
+ const config = useEmbeddableConfig();
83
+ const api = useApi(); // Automatically uses global config
84
+
85
+ return (
86
+ <div>
87
+ <h2>Widget: {config.widgetId}</h2>
88
+ <p>Version: {config.version}</p>
89
+ <p>Mode: {config.mode}</p>
90
+ {/* Your widget content */}
91
+ </div>
92
+ );
93
+ }
94
+ ```
95
+
48
96
  ## API Reference
49
97
 
50
98
  ### Hooks
@@ -119,6 +167,28 @@ function DataComponent() {
119
167
  }
120
168
  ```
121
169
 
170
+ #### `useEmbeddableConfig()`
171
+
172
+ A React hook to access the global SDK configuration.
173
+
174
+ ```typescript
175
+ import { useEmbeddableConfig } from '@embeddable/sdk/hooks';
176
+
177
+ function MyWidget() {
178
+ const config = useEmbeddableConfig();
179
+
180
+ return (
181
+ <div>
182
+ <h3>Widget ID: {config.widgetId}</h3>
183
+ <p>Version: {config.version}</p>
184
+ <p>Mode: {config.mode}</p>
185
+ </div>
186
+ );
187
+ }
188
+ ```
189
+
190
+ **Note:** This hook must be used within an `EmbeddableProvider`.
191
+
122
192
  ### Utilities
123
193
 
124
194
  #### `debounce<T>(func: T, wait: number)`
@@ -174,10 +244,9 @@ The SDK exports TypeScript types for better development experience:
174
244
 
175
245
  ```typescript
176
246
  import type {
247
+ EmbeddableConfig,
177
248
  EmbeddableApiConfig,
178
249
  ApiResponse,
179
- Theme,
180
- ThemeConfig,
181
250
  LocalStorageOptions,
182
251
  } from '@embeddable/sdk';
183
252
  ```
@@ -0,0 +1,14 @@
1
+ import { ReactNode } from 'react';
2
+ import { EmbeddableConfig } from '../types';
3
+
4
+ interface EmbeddableContextType {
5
+ config: EmbeddableConfig | null;
6
+ }
7
+ interface EmbeddableProviderProps {
8
+ config: EmbeddableConfig;
9
+ children: ReactNode;
10
+ }
11
+ export declare function EmbeddableProvider({ config, children }: EmbeddableProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function useEmbeddableContext(): EmbeddableContextType;
13
+ export {};
14
+ //# sourceMappingURL=EmbeddableProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbeddableProvider.d.ts","sourceRoot":"","sources":["../../src/context/EmbeddableProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,SAAS,EAAc,MAAM,OAAO,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,qBAAqB;IAC7B,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC;AAiBD,UAAU,uBAAuB;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,uBAAuB,2CAM/E;AAED,wBAAgB,oBAAoB,IAAI,qBAAqB,CAM5D"}
@@ -1,4 +1,5 @@
1
1
  export { useApi } from './useApi';
2
2
  export { useDebounce } from './useDebounce';
3
+ export { useEmbeddableConfig, useEmbeddableConfigSafe } from './useEmbeddableConfig';
3
4
  export { useLocalStorage } from './useLocalStorage';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -2,10 +2,10 @@ import { ApiResponse, EmbeddableApiConfig } from '../types';
2
2
 
3
3
  /**
4
4
  * React hook for API calls with loading and error states
5
- * @param config - API configuration
5
+ * @param config - API configuration (optional, will use global config if not provided)
6
6
  * @returns API client with state management
7
7
  */
8
- export declare function useApi(config: EmbeddableApiConfig): {
8
+ export declare function useApi(config?: EmbeddableApiConfig): {
9
9
  get: <T = any>(endpoint: string) => Promise<ApiResponse<T>>;
10
10
  post: <T = any>(endpoint: string, body?: any) => Promise<ApiResponse<T>>;
11
11
  put: <T = any>(endpoint: string, body?: any) => Promise<ApiResponse<T>>;
@@ -1 +1 @@
1
- {"version":3,"file":"useApi.d.ts","sourceRoot":"","sources":["../../src/hooks/useApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AASjE;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,mBAAmB;UA8DvB,CAAC,kBAAkB,MAAM;WAG/C,CAAC,kBAAkB,MAAM,SAAS,GAAG;UAKrC,CAAC,kBAAkB,MAAM,SAAS,GAAG;aAIf,CAAC,kBAAkB,MAAM;;;aAnFzC,OAAO;WACT,MAAM,GAAG,IAAI;EAoGrB"}
1
+ {"version":3,"file":"useApi.d.ts","sourceRoot":"","sources":["../../src/hooks/useApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AASjE;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,mBAAmB;UAsExB,CAAC,kBAAkB,MAAM;WAG/C,CAAC,kBAAkB,MAAM,SAAS,GAAG;UAKrC,CAAC,kBAAkB,MAAM,SAAS,GAAG;aAIf,CAAC,kBAAkB,MAAM;;;aA3FzC,OAAO;WACT,MAAM,GAAG,IAAI;EA4GrB"}
@@ -0,0 +1,14 @@
1
+ import { EmbeddableConfig } from '../types';
2
+
3
+ /**
4
+ * Hook to access the global Embeddable SDK configuration
5
+ * @returns The current SDK configuration
6
+ * @throws Error if used outside of EmbeddableProvider
7
+ */
8
+ export declare function useEmbeddableConfig(): EmbeddableConfig;
9
+ /**
10
+ * Hook to safely access the global Embeddable SDK configuration
11
+ * @returns The current SDK configuration or null if not available
12
+ */
13
+ export declare function useEmbeddableConfigSafe(): EmbeddableConfig | null;
14
+ //# sourceMappingURL=useEmbeddableConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEmbeddableConfig.d.ts","sourceRoot":"","sources":["../../src/hooks/useEmbeddableConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAUtD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,gBAAgB,GAAG,IAAI,CAGjE"}
package/dist/hooks.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useLocalStorage-C4q-PhVk.cjs");exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useLocalStorage=e.useLocalStorage;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useLocalStorage-DrXEgrK7.cjs");exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableConfigSafe=e.useEmbeddableConfigSafe,exports.useLocalStorage=e.useLocalStorage;
package/dist/hooks.js CHANGED
@@ -1,6 +1,8 @@
1
- import { u, a, b } from "./useLocalStorage-BYg8a4Ry.js";
1
+ import { a, b, c, d, e } from "./useLocalStorage-DHUi0T4S.js";
2
2
  export {
3
- u as useApi,
4
- a as useDebounce,
5
- b as useLocalStorage
3
+ a as useApi,
4
+ b as useDebounce,
5
+ c as useEmbeddableConfig,
6
+ d as useEmbeddableConfigSafe,
7
+ e as useLocalStorage
6
8
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useLocalStorage-C4q-PhVk.cjs"),o=require("./storage-3dk6ww91.cjs"),r=require("./utils.cjs");exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useLocalStorage=e.useLocalStorage,exports.createApiClient=o.createApiClient,exports.storage=o.storage,exports.debounce=r.debounce;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useLocalStorage-DrXEgrK7.cjs"),o=require("./storage-3dk6ww91.cjs"),s=require("./utils.cjs");exports.EmbeddableProvider=e.EmbeddableProvider,exports.useApi=e.useApi,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableConfigSafe=e.useEmbeddableConfigSafe,exports.useEmbeddableContext=e.useEmbeddableContext,exports.useLocalStorage=e.useLocalStorage,exports.createApiClient=o.createApiClient,exports.storage=o.storage,exports.debounce=s.debounce;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './context/EmbeddableProvider';
1
2
  export * from './hooks';
2
3
  export * from './utils';
3
4
  export type * from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,mBAAmB,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,mBAAmB,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,15 @@
1
- import { u, a, b } from "./useLocalStorage-BYg8a4Ry.js";
2
- import { c, s } from "./storage-CRPDfSRn.js";
1
+ import { E, a, b, c, d, u, e } from "./useLocalStorage-DHUi0T4S.js";
2
+ import { c as c2, s } from "./storage-CRPDfSRn.js";
3
3
  import { debounce } from "./utils.js";
4
4
  export {
5
- c as createApiClient,
5
+ E as EmbeddableProvider,
6
+ c2 as createApiClient,
6
7
  debounce,
7
8
  s as storage,
8
- u as useApi,
9
- a as useDebounce,
10
- b as useLocalStorage
9
+ a as useApi,
10
+ b as useDebounce,
11
+ c as useEmbeddableConfig,
12
+ d as useEmbeddableConfigSafe,
13
+ u as useEmbeddableContext,
14
+ e as useLocalStorage
11
15
  };
@@ -14,14 +14,15 @@ export interface LocalStorageOptions {
14
14
  serialize?: (value: any) => string;
15
15
  deserialize?: (value: string) => any;
16
16
  }
17
- export type Theme = 'light' | 'dark' | 'auto';
18
- export interface ThemeConfig {
19
- theme: Theme;
20
- colors?: {
21
- primary?: string;
22
- secondary?: string;
23
- background?: string;
24
- text?: string;
25
- };
17
+ export type EmbeddableMode = 'embeddable' | 'standalone' | 'preview';
18
+ export interface EmbeddableConfig {
19
+ widgetId: string;
20
+ version: 'dev' | 'latest' | string;
21
+ mode: EmbeddableMode;
22
+ ignoreCache: boolean;
23
+ lazyLoad: boolean;
24
+ loader: boolean;
25
+ _containerId?: string;
26
+ _shadowRoot?: ShadowRoot;
26
27
  }
27
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,E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