@embeddable/sdk 1.0.8 → 1.0.10
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 +111 -28
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAI.d.ts +40 -0
- package/dist/hooks/useAI.d.ts.map +1 -0
- package/dist/hooks/useEmbeddableConfig.d.ts +0 -5
- package/dist/hooks/useEmbeddableConfig.d.ts.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts.map +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +7 -8
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -11
- package/dist/{storage-CRPDfSRn.js → storage-B4eeCFyo.js} +0 -55
- package/dist/storage-EjA7Lhbb.cjs +1 -0
- package/dist/{useVoteAggregations-CTxRxF5Y.js → useVoteAggregations-c6kqMEXe.js} +85 -92
- package/dist/{useVoteAggregations-BuUwX4z6.cjs → useVoteAggregations-sKR_hMwZ.cjs} +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +56 -2
- package/package.json +1 -1
- package/dist/hooks/useApi.d.ts +0 -18
- package/dist/hooks/useApi.d.ts.map +0 -1
- package/dist/storage-3dk6ww91.cjs +0 -1
package/README.md
CHANGED
|
@@ -85,7 +85,6 @@ import { useEmbeddableConfig, useApi } from '@embeddable/sdk';
|
|
|
85
85
|
|
|
86
86
|
function WidgetComponent() {
|
|
87
87
|
const config = useEmbeddableConfig();
|
|
88
|
-
const api = useApi(); // Automatically uses global config
|
|
89
88
|
|
|
90
89
|
return (
|
|
91
90
|
<div>
|
|
@@ -148,33 +147,6 @@ function SearchInput() {
|
|
|
148
147
|
}
|
|
149
148
|
```
|
|
150
149
|
|
|
151
|
-
#### `useApi(config: EmbeddableApiConfig)`
|
|
152
|
-
|
|
153
|
-
A React hook for API calls with loading and error states.
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import { useApi } from '@embeddable/sdk/hooks'
|
|
157
|
-
|
|
158
|
-
function DataComponent() {
|
|
159
|
-
const api = useApi({ apiKey: 'your-api-key', baseUrl: 'https://api.example.com' })
|
|
160
|
-
|
|
161
|
-
const fetchData = async () => {
|
|
162
|
-
const response = await api.get('/users')
|
|
163
|
-
if (response.success) {
|
|
164
|
-
console.log(response.data)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return (
|
|
169
|
-
<div>
|
|
170
|
-
{api.loading && <div>Loading...</div>}
|
|
171
|
-
{api.error && <div>Error: {api.error}</div>}
|
|
172
|
-
<button onClick={fetchData}>Fetch Data</button>
|
|
173
|
-
</div>
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
150
|
#### `useEmbeddableConfig()`
|
|
179
151
|
|
|
180
152
|
A React hook to access the global SDK configuration.
|
|
@@ -579,6 +551,114 @@ interface VoteAggregationData {
|
|
|
579
551
|
|
|
580
552
|
**Note:** This hook must be used within an `EmbeddableProvider` as it automatically retrieves the `widgetId` from the global configuration.
|
|
581
553
|
|
|
554
|
+
#### `useAI(options: UseAIOptions)`
|
|
555
|
+
|
|
556
|
+
A React hook for handling AI API calls with loading states, error handling, and support for multiple AI platforms. Automatically uses the widget ID from the global configuration.
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
import { useAI } from '@embeddable/sdk/hooks';
|
|
560
|
+
|
|
561
|
+
function ChatComponent() {
|
|
562
|
+
const { callAI, loading, error, success, reset } = useAI({
|
|
563
|
+
platform: 'openai' // 'openai' | 'anthropic' | 'gemini'
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
const [messages, setMessages] = useState([]);
|
|
567
|
+
const [input, setInput] = useState('');
|
|
568
|
+
|
|
569
|
+
const handleSendMessage = async () => {
|
|
570
|
+
if (!input.trim()) return;
|
|
571
|
+
|
|
572
|
+
const userMessage = { role: 'user', content: input };
|
|
573
|
+
const newMessages = [...messages, userMessage];
|
|
574
|
+
setMessages(newMessages);
|
|
575
|
+
setInput('');
|
|
576
|
+
|
|
577
|
+
const result = await callAI(input, messages);
|
|
578
|
+
if (result.success && result.data) {
|
|
579
|
+
setMessages(prev => [...prev, {
|
|
580
|
+
role: 'assistant',
|
|
581
|
+
content: result.data.response
|
|
582
|
+
}]);
|
|
583
|
+
|
|
584
|
+
console.log('Tokens used:', result.data.tokensUsed);
|
|
585
|
+
console.log('Model used:', result.metadata?.model);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
return (
|
|
590
|
+
<div>
|
|
591
|
+
<div style={{ height: '400px', overflowY: 'auto', border: '1px solid #ccc', padding: '10px' }}>
|
|
592
|
+
{messages.map((msg, index) => (
|
|
593
|
+
<div key={index} style={{ marginBottom: '10px' }}>
|
|
594
|
+
<strong>{msg.role}:</strong> {msg.content}
|
|
595
|
+
</div>
|
|
596
|
+
))}
|
|
597
|
+
{loading && <div>AI is thinking...</div>}
|
|
598
|
+
</div>
|
|
599
|
+
|
|
600
|
+
<div style={{ marginTop: '10px', display: 'flex', gap: '10px' }}>
|
|
601
|
+
<input
|
|
602
|
+
type="text"
|
|
603
|
+
value={input}
|
|
604
|
+
onChange={(e) => setInput(e.target.value)}
|
|
605
|
+
onKeyPress={(e) => e.key === 'Enter' && handleSendMessage()}
|
|
606
|
+
placeholder="Type your message..."
|
|
607
|
+
style={{ flex: 1, padding: '8px' }}
|
|
608
|
+
disabled={loading}
|
|
609
|
+
/>
|
|
610
|
+
<button onClick={handleSendMessage} disabled={loading || !input.trim()}>
|
|
611
|
+
Send
|
|
612
|
+
</button>
|
|
613
|
+
</div>
|
|
614
|
+
|
|
615
|
+
{error && <p style={{ color: 'red', marginTop: '10px' }}>Error: {error}</p>}
|
|
616
|
+
{success && <p style={{ color: 'green', marginTop: '10px' }}>Message sent successfully!</p>}
|
|
617
|
+
|
|
618
|
+
<button onClick={reset} style={{ marginTop: '10px' }}>Reset Status</button>
|
|
619
|
+
</div>
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
**Options:**
|
|
625
|
+
|
|
626
|
+
- `platform: 'openai' | 'anthropic' | 'gemini'` - The AI platform to use for API calls
|
|
627
|
+
|
|
628
|
+
**Returns:**
|
|
629
|
+
|
|
630
|
+
- `callAI: (prompt: string, history?: Array<ChatMessage>) => Promise<AIResponse>` - Function to make AI API calls
|
|
631
|
+
- `loading: boolean` - Whether an AI request is in progress
|
|
632
|
+
- `error: string | null` - Error message if the request failed
|
|
633
|
+
- `success: boolean` - Whether the last request was successful
|
|
634
|
+
- `reset: () => void` - Function to reset the hook state
|
|
635
|
+
|
|
636
|
+
**Data Structure:**
|
|
637
|
+
|
|
638
|
+
```typescript
|
|
639
|
+
interface ChatMessage {
|
|
640
|
+
role: 'user' | 'assistant';
|
|
641
|
+
content: string;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
interface AIResponse {
|
|
645
|
+
success: boolean;
|
|
646
|
+
message?: string;
|
|
647
|
+
error?: string;
|
|
648
|
+
data?: {
|
|
649
|
+
response: string;
|
|
650
|
+
tokensUsed: number | null;
|
|
651
|
+
};
|
|
652
|
+
metadata?: {
|
|
653
|
+
model: string | null;
|
|
654
|
+
integrationKey: string;
|
|
655
|
+
capabilityId: string;
|
|
656
|
+
executedAt: string;
|
|
657
|
+
[key: string]: any; // Additional metadata fields
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
582
662
|
### Utilities
|
|
583
663
|
|
|
584
664
|
#### `debounce<T>(func: T, wait: number)`
|
|
@@ -648,6 +728,9 @@ import type {
|
|
|
648
728
|
VoteAggregationSummary,
|
|
649
729
|
VoteAggregationData,
|
|
650
730
|
VoteAggregationResponse,
|
|
731
|
+
ChatMessage,
|
|
732
|
+
AIResponse,
|
|
733
|
+
UseAIOptions,
|
|
651
734
|
} from '@embeddable/sdk';
|
|
652
735
|
```
|
|
653
736
|
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useAI } from './useAI';
|
|
2
2
|
export { useDebounce } from './useDebounce';
|
|
3
|
-
export { useEmbeddableConfig
|
|
3
|
+
export { useEmbeddableConfig } from './useEmbeddableConfig';
|
|
4
4
|
export { useEmbeddableData } from './useEmbeddableData';
|
|
5
5
|
export { useFormSubmission } from './useFormSubmission';
|
|
6
6
|
export { useLocalStorage } from './useLocalStorage';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type AIPlatform = 'openai' | 'anthropic' | 'gemini';
|
|
2
|
+
interface ChatMessage {
|
|
3
|
+
role: 'user' | 'assistant';
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
interface AIResponseData {
|
|
7
|
+
response: string;
|
|
8
|
+
tokensUsed: number | null;
|
|
9
|
+
}
|
|
10
|
+
interface AIResponseMetadata {
|
|
11
|
+
model: string | null;
|
|
12
|
+
integrationKey: string;
|
|
13
|
+
capabilityId: string;
|
|
14
|
+
executedAt: string;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}
|
|
17
|
+
interface AIResponse {
|
|
18
|
+
success: boolean;
|
|
19
|
+
message?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
data?: AIResponseData;
|
|
22
|
+
metadata?: AIResponseMetadata;
|
|
23
|
+
}
|
|
24
|
+
interface UseAIOptions {
|
|
25
|
+
platform: AIPlatform;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* React hook for handling AI API calls with loading, error states
|
|
29
|
+
* @param options - Configuration including the AI platform to use
|
|
30
|
+
* @returns Object with AI function and state management
|
|
31
|
+
*/
|
|
32
|
+
export declare function useAI(options: UseAIOptions): {
|
|
33
|
+
callAI: (prompt: string, history?: Array<ChatMessage>) => Promise<AIResponse>;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error: string | null;
|
|
37
|
+
success: boolean;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=useAI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAI.d.ts","sourceRoot":"","sources":["../../src/hooks/useAI.ts"],"names":[],"mappings":"AAIA,KAAK,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEpD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAQD,UAAU,cAAc;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,UAAU;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,UAAU,YAAY;IACpB,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY;qBASxB,MAAM,YAAY,KAAK,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,UAAU,CAAC;;aA5ClE,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EAmHjB"}
|
|
@@ -6,9 +6,4 @@ import { EmbeddableConfig } from '../types';
|
|
|
6
6
|
* @throws Error if used outside of EmbeddableProvider
|
|
7
7
|
*/
|
|
8
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
9
|
//# sourceMappingURL=useEmbeddableConfig.d.ts.map
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAIpD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,EACf,OAAO,GAAE,mBAAwB,GAChC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC,CAgExD"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVoteAggregations-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVoteAggregations-sKR_hMwZ.cjs");exports.useAI=e.useAI,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableData=e.useEmbeddableData,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations;
|
package/dist/hooks.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { a, b, c, d, e, f, g, h
|
|
1
|
+
import { a, b, c, d, e, f, g, h } from "./useVoteAggregations-c6kqMEXe.js";
|
|
2
2
|
export {
|
|
3
|
-
a as
|
|
3
|
+
a as useAI,
|
|
4
4
|
b as useDebounce,
|
|
5
5
|
c as useEmbeddableConfig,
|
|
6
|
-
d as
|
|
7
|
-
e as
|
|
8
|
-
f as
|
|
9
|
-
g as
|
|
10
|
-
h as
|
|
11
|
-
i as useVoteAggregations
|
|
6
|
+
d as useEmbeddableData,
|
|
7
|
+
e as useFormSubmission,
|
|
8
|
+
f as useLocalStorage,
|
|
9
|
+
g as useVote,
|
|
10
|
+
h as useVoteAggregations
|
|
12
11
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVoteAggregations-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVoteAggregations-sKR_hMwZ.cjs"),s=require("./utils.cjs"),o=require("./storage-EjA7Lhbb.cjs");exports.EmbeddableProvider=e.EmbeddableProvider,exports.useAI=e.useAI,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableContext=e.useEmbeddableContext,exports.useEmbeddableData=e.useEmbeddableData,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations,exports.createApiClient=s.createApiClient,exports.debounce=s.debounce,exports.storage=o.storage;
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { E, a, b, c,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { E, a, b, c, u, d, e, f, g, h } from "./useVoteAggregations-c6kqMEXe.js";
|
|
2
|
+
import { createApiClient, debounce } from "./utils.js";
|
|
3
|
+
import { s } from "./storage-B4eeCFyo.js";
|
|
4
4
|
export {
|
|
5
5
|
E as EmbeddableProvider,
|
|
6
|
-
|
|
6
|
+
createApiClient,
|
|
7
7
|
debounce,
|
|
8
8
|
s as storage,
|
|
9
|
-
a as
|
|
9
|
+
a as useAI,
|
|
10
10
|
b as useDebounce,
|
|
11
11
|
c as useEmbeddableConfig,
|
|
12
|
-
d as useEmbeddableConfigSafe,
|
|
13
12
|
u as useEmbeddableContext,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
d as useEmbeddableData,
|
|
14
|
+
e as useFormSubmission,
|
|
15
|
+
f as useLocalStorage,
|
|
16
|
+
g as useVote,
|
|
17
|
+
h as useVoteAggregations
|
|
19
18
|
};
|
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
function createApiClient(config) {
|
|
2
|
-
const baseUrl = config.baseUrl || "https://api.embeddable.com";
|
|
3
|
-
const headers = {
|
|
4
|
-
"Content-Type": "application/json"
|
|
5
|
-
};
|
|
6
|
-
if (config.apiKey) {
|
|
7
|
-
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
8
|
-
}
|
|
9
|
-
const request = async (endpoint, options = {}) => {
|
|
10
|
-
try {
|
|
11
|
-
const url = `${baseUrl}${endpoint}`;
|
|
12
|
-
const response = await fetch(url, {
|
|
13
|
-
...options,
|
|
14
|
-
headers: {
|
|
15
|
-
...headers,
|
|
16
|
-
...options.headers
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const data = await response.json();
|
|
20
|
-
if (!response.ok) {
|
|
21
|
-
return {
|
|
22
|
-
data: null,
|
|
23
|
-
success: false,
|
|
24
|
-
error: data.message || `HTTP ${response.status}`
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
data,
|
|
29
|
-
success: true
|
|
30
|
-
};
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (config.debug) {
|
|
33
|
-
console.error("API Request failed:", error);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
data: null,
|
|
37
|
-
success: false,
|
|
38
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
get: (endpoint) => request(endpoint, { method: "GET" }),
|
|
44
|
-
post: (endpoint, body) => request(endpoint, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
body: body ? JSON.stringify(body) : void 0
|
|
47
|
-
}),
|
|
48
|
-
put: (endpoint, body) => request(endpoint, {
|
|
49
|
-
method: "PUT",
|
|
50
|
-
body: body ? JSON.stringify(body) : void 0
|
|
51
|
-
}),
|
|
52
|
-
delete: (endpoint) => request(endpoint, { method: "DELETE" })
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
1
|
const storage = {
|
|
56
2
|
/**
|
|
57
3
|
* Get an item from localStorage
|
|
@@ -142,6 +88,5 @@ const storage = {
|
|
|
142
88
|
}
|
|
143
89
|
};
|
|
144
90
|
export {
|
|
145
|
-
createApiClient as c,
|
|
146
91
|
storage as s
|
|
147
92
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t={get(t,e={}){try{const{prefix:r="",deserialize:o=JSON.parse}=e,a=r+t,l=localStorage.getItem(a);return null===l?null:o(l)}catch(r){return null}},set(t,e,r={}){try{const{prefix:o="",serialize:a=JSON.stringify}=r,l=o+t,c=a(e);localStorage.setItem(l,c)}catch(o){}},remove(t,e={}){try{const{prefix:r=""}=e,o=r+t;localStorage.removeItem(o)}catch(r){}},clear(t={}){try{const{prefix:e=""}=t;if(!e)return void localStorage.clear();const r=[];for(let t=0;t<localStorage.length;t++){const o=localStorage.key(t);o&&o.startsWith(e)&&r.push(o)}r.forEach((t=>localStorage.removeItem(t)))}catch(e){}},isAvailable(){try{const t="__storage_test__";return localStorage.setItem(t,"test"),localStorage.removeItem(t),!0}catch{return!1}}};exports.storage=t;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import require$$0, { useState, useEffect, createContext, useContext, useCallback } from "react";
|
|
2
|
-
import {
|
|
1
|
+
import require$$0, { useState, useEffect, createContext, useContext, useCallback, useMemo } from "react";
|
|
2
|
+
import { s as storage } from "./storage-B4eeCFyo.js";
|
|
3
3
|
var jsxRuntime = { exports: {} };
|
|
4
4
|
var reactJsxRuntime_production_min = {};
|
|
5
5
|
/**
|
|
@@ -971,85 +971,86 @@ function useEmbeddableContext() {
|
|
|
971
971
|
}
|
|
972
972
|
return context;
|
|
973
973
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
974
|
+
const EVENTS_BASE_URL = "https://events.embeddable.co";
|
|
975
|
+
function useEmbeddableConfig() {
|
|
976
|
+
const { config } = useEmbeddableContext();
|
|
977
|
+
if (!config) {
|
|
977
978
|
throw new Error(
|
|
978
|
-
"No
|
|
979
|
+
"No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config."
|
|
979
980
|
);
|
|
980
981
|
}
|
|
982
|
+
return config;
|
|
983
|
+
}
|
|
984
|
+
function useAI(options) {
|
|
985
|
+
const { widgetId } = useEmbeddableConfig();
|
|
981
986
|
const [state, setState] = useState({
|
|
982
|
-
data: null,
|
|
983
987
|
loading: false,
|
|
984
|
-
error: null
|
|
988
|
+
error: null,
|
|
989
|
+
success: false
|
|
985
990
|
});
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
setState(
|
|
991
|
+
const callAI = useCallback(
|
|
992
|
+
async (prompt, history) => {
|
|
993
|
+
var _a;
|
|
994
|
+
setState({ loading: true, error: null, success: false });
|
|
990
995
|
try {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
throw new Error(`Unsupported method: ${method}`);
|
|
1007
|
-
}
|
|
1008
|
-
setState({
|
|
1009
|
-
data: response.data,
|
|
1010
|
-
loading: false,
|
|
1011
|
-
error: response.success ? null : response.error || "Unknown error"
|
|
996
|
+
const requestData = {
|
|
997
|
+
widgetId,
|
|
998
|
+
capabilityId: "ai_call",
|
|
999
|
+
integrationKey: options.platform,
|
|
1000
|
+
prompt,
|
|
1001
|
+
history: history || []
|
|
1002
|
+
};
|
|
1003
|
+
const response = await fetch(`${EVENTS_BASE_URL}/api/execute/ai`, {
|
|
1004
|
+
method: "POST",
|
|
1005
|
+
headers: {
|
|
1006
|
+
"Content-Type": "application/json"
|
|
1007
|
+
},
|
|
1008
|
+
// Explicitly set credentials to 'omit' for CORS support
|
|
1009
|
+
credentials: "omit",
|
|
1010
|
+
body: JSON.stringify(requestData)
|
|
1012
1011
|
});
|
|
1013
|
-
|
|
1012
|
+
const responseData = await response.json();
|
|
1013
|
+
if (!response.ok) {
|
|
1014
|
+
const errorMessage = responseData.message || responseData.error || `HTTP ${response.status}`;
|
|
1015
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1016
|
+
return {
|
|
1017
|
+
success: false,
|
|
1018
|
+
message: errorMessage
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
if (responseData.success) {
|
|
1022
|
+
setState({ loading: false, error: null, success: true });
|
|
1023
|
+
return {
|
|
1024
|
+
success: true,
|
|
1025
|
+
message: ((_a = responseData.data) == null ? void 0 : _a.response) || "AI call completed successfully",
|
|
1026
|
+
data: responseData.data,
|
|
1027
|
+
metadata: responseData.metadata
|
|
1028
|
+
};
|
|
1029
|
+
} else {
|
|
1030
|
+
const errorMessage = responseData.message || responseData.error || "AI call failed";
|
|
1031
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1032
|
+
return {
|
|
1033
|
+
success: false,
|
|
1034
|
+
message: errorMessage
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1014
1037
|
} catch (error) {
|
|
1015
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1016
|
-
setState({
|
|
1017
|
-
data: null,
|
|
1018
|
-
loading: false,
|
|
1019
|
-
error: errorMessage
|
|
1020
|
-
});
|
|
1038
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1039
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1021
1040
|
return {
|
|
1022
|
-
data: null,
|
|
1023
1041
|
success: false,
|
|
1024
|
-
|
|
1042
|
+
message: errorMessage
|
|
1025
1043
|
};
|
|
1026
1044
|
}
|
|
1027
1045
|
},
|
|
1028
|
-
[
|
|
1029
|
-
);
|
|
1030
|
-
const get = useCallback((endpoint) => request("get", endpoint), [request]);
|
|
1031
|
-
const post = useCallback(
|
|
1032
|
-
(endpoint, body) => request("post", endpoint, body),
|
|
1033
|
-
[request]
|
|
1034
|
-
);
|
|
1035
|
-
const put = useCallback(
|
|
1036
|
-
(endpoint, body) => request("put", endpoint, body),
|
|
1037
|
-
[request]
|
|
1046
|
+
[options.platform, widgetId]
|
|
1038
1047
|
);
|
|
1039
|
-
const del = useCallback((endpoint) => request("delete", endpoint), [request]);
|
|
1040
1048
|
const reset = useCallback(() => {
|
|
1041
|
-
setState({
|
|
1042
|
-
data: null,
|
|
1043
|
-
loading: false,
|
|
1044
|
-
error: null
|
|
1045
|
-
});
|
|
1049
|
+
setState({ loading: false, error: null, success: false });
|
|
1046
1050
|
}, []);
|
|
1047
1051
|
return {
|
|
1048
1052
|
...state,
|
|
1049
|
-
|
|
1050
|
-
post,
|
|
1051
|
-
put,
|
|
1052
|
-
delete: del,
|
|
1053
|
+
callAI,
|
|
1053
1054
|
reset
|
|
1054
1055
|
};
|
|
1055
1056
|
}
|
|
@@ -1065,24 +1066,10 @@ function useDebounce(value, delay) {
|
|
|
1065
1066
|
}, [value, delay]);
|
|
1066
1067
|
return debouncedValue;
|
|
1067
1068
|
}
|
|
1068
|
-
function useEmbeddableConfig() {
|
|
1069
|
-
const { config } = useEmbeddableContext();
|
|
1070
|
-
if (!config) {
|
|
1071
|
-
throw new Error(
|
|
1072
|
-
"No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config."
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
return config;
|
|
1076
|
-
}
|
|
1077
|
-
function useEmbeddableConfigSafe() {
|
|
1078
|
-
const { config } = useEmbeddableContext();
|
|
1079
|
-
return config;
|
|
1080
|
-
}
|
|
1081
1069
|
function useEmbeddableData() {
|
|
1082
1070
|
const { data } = useEmbeddableContext();
|
|
1083
1071
|
return { data };
|
|
1084
1072
|
}
|
|
1085
|
-
const EVENTS_BASE_URL = "https://events.embeddable.co";
|
|
1086
1073
|
function useFormSubmission(options) {
|
|
1087
1074
|
const { widgetId } = useEmbeddableConfig();
|
|
1088
1075
|
const [state, setState] = useState({
|
|
@@ -1164,8 +1151,16 @@ function useFormSubmission(options) {
|
|
|
1164
1151
|
};
|
|
1165
1152
|
}
|
|
1166
1153
|
function useLocalStorage(key, initialValue, options = {}) {
|
|
1154
|
+
const { widgetId } = useEmbeddableConfig();
|
|
1155
|
+
const prefixedOptions = useMemo(
|
|
1156
|
+
() => ({
|
|
1157
|
+
...options,
|
|
1158
|
+
prefix: `embd-${widgetId}-${options.prefix || ""}`
|
|
1159
|
+
}),
|
|
1160
|
+
[widgetId, options]
|
|
1161
|
+
);
|
|
1167
1162
|
const [storedValue, setStoredValue] = useState(() => {
|
|
1168
|
-
const item = storage.get(key,
|
|
1163
|
+
const item = storage.get(key, prefixedOptions);
|
|
1169
1164
|
return item !== null ? item : initialValue;
|
|
1170
1165
|
});
|
|
1171
1166
|
const setValue = useCallback(
|
|
@@ -1173,28 +1168,27 @@ function useLocalStorage(key, initialValue, options = {}) {
|
|
|
1173
1168
|
try {
|
|
1174
1169
|
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
1175
1170
|
setStoredValue(valueToStore);
|
|
1176
|
-
storage.set(key, valueToStore,
|
|
1171
|
+
storage.set(key, valueToStore, prefixedOptions);
|
|
1177
1172
|
} catch (error) {
|
|
1178
1173
|
console.warn(`Error setting localStorage key "${key}":`, error);
|
|
1179
1174
|
}
|
|
1180
1175
|
},
|
|
1181
|
-
[key, storedValue,
|
|
1176
|
+
[key, storedValue, prefixedOptions]
|
|
1182
1177
|
);
|
|
1183
1178
|
const removeValue = useCallback(() => {
|
|
1184
1179
|
try {
|
|
1185
1180
|
setStoredValue(initialValue);
|
|
1186
|
-
storage.remove(key,
|
|
1181
|
+
storage.remove(key, prefixedOptions);
|
|
1187
1182
|
} catch (error) {
|
|
1188
1183
|
console.warn(`Error removing localStorage key "${key}":`, error);
|
|
1189
1184
|
}
|
|
1190
|
-
}, [key, initialValue,
|
|
1185
|
+
}, [key, initialValue, prefixedOptions]);
|
|
1191
1186
|
useEffect(() => {
|
|
1192
1187
|
const handleStorageChange = (e) => {
|
|
1193
|
-
const
|
|
1194
|
-
const fullKey = prefix + key;
|
|
1188
|
+
const fullKey = prefixedOptions.prefix + key;
|
|
1195
1189
|
if (e.key === fullKey && e.newValue !== null) {
|
|
1196
1190
|
try {
|
|
1197
|
-
const { deserialize = JSON.parse } =
|
|
1191
|
+
const { deserialize = JSON.parse } = prefixedOptions;
|
|
1198
1192
|
const newValue = deserialize(e.newValue);
|
|
1199
1193
|
setStoredValue(newValue);
|
|
1200
1194
|
} catch (error) {
|
|
@@ -1204,7 +1198,7 @@ function useLocalStorage(key, initialValue, options = {}) {
|
|
|
1204
1198
|
};
|
|
1205
1199
|
window.addEventListener("storage", handleStorageChange);
|
|
1206
1200
|
return () => window.removeEventListener("storage", handleStorageChange);
|
|
1207
|
-
}, [key,
|
|
1201
|
+
}, [key, prefixedOptions]);
|
|
1208
1202
|
return [storedValue, setValue, removeValue];
|
|
1209
1203
|
}
|
|
1210
1204
|
function useVote(options) {
|
|
@@ -1354,14 +1348,13 @@ function useVoteAggregations(options) {
|
|
|
1354
1348
|
}
|
|
1355
1349
|
export {
|
|
1356
1350
|
EmbeddableProvider as E,
|
|
1357
|
-
|
|
1351
|
+
useAI as a,
|
|
1358
1352
|
useDebounce as b,
|
|
1359
1353
|
useEmbeddableConfig as c,
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
useVoteAggregations as i,
|
|
1354
|
+
useEmbeddableData as d,
|
|
1355
|
+
useFormSubmission as e,
|
|
1356
|
+
useLocalStorage as f,
|
|
1357
|
+
useVote as g,
|
|
1358
|
+
useVoteAggregations as h,
|
|
1366
1359
|
useEmbeddableContext as u
|
|
1367
1360
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const e=require("react"),r=require("./storage-
|
|
1
|
+
"use strict";const e=require("react"),r=require("./storage-EjA7Lhbb.cjs");var t,n={exports:{}},o={};var a,s={};
|
|
2
2
|
/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.development.js
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
*
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var r=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,r,t){var o,a={},l=null,u=null;for(o in void 0!==t&&(l=""+t),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(u=r.ref),r)s.call(r,o)&&!c.hasOwnProperty(o)&&(a[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===a[o]&&(a[o]=r[o]);return{$$typeof:n,type:e,key:l,ref:u,props:a,_owner:i.current}}return o.Fragment=a,o.jsx=l,o.jsxs=l,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var r,t=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),v=Symbol.iterator,b=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case c:return"Profiler";case i:return"StrictMode";case p:return"Suspense";case d:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case l:return w(e._context)+".Provider";case f:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case g:var t=e,n=t._payload,s=t._init;try{return k(s(n))}catch(m){return null}}return null}r=Symbol.for("react.module.reference");var _,E,S,O,j,C,P,R=Object.assign,T=0;function x(){}x.__reactDisabledLog=!0;var $,N=b.ReactCurrentDispatcher;function I(e,r,t){if(void 0===$)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);$=n&&n[1]||""}return"\n"+$+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||F)return"";var t,n=D.get(e);if(void 0!==n)return n;F=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=N.current,N.current=null,function(){if(0===T){_=console.log,E=console.info,S=console.warn,O=console.error,j=console.group,C=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:x,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}T++}();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){t=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){t=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){t=y}e()}}catch(g){if(g&&t&&"string"==typeof g.stack){for(var i=g.stack.split("\n"),c=t.stack.split("\n"),l=i.length-1,u=c.length-1;l>=1&&u>=0&&i[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(i[l]!==c[u]){if(1!==l||1!==u)do{if(l--,--u<0||i[l]!==c[u]){var f="\n"+i[l].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,f),f}}while(l>=1&&u>=0);break}}}finally{F=!1,N.current=o,function(){if(0===--T){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},e,{value:_}),info:R({},e,{value:E}),warn:R({},e,{value:S}),error:R({},e,{value:O}),group:R({},e,{value:j}),groupCollapsed:R({},e,{value:C}),groupEnd:R({},e,{value:P})})}T<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",d=p?I(p):"";return"function"==typeof e&&D.set(e,d),d}function A(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return I(e);switch(e){case p:return I("Suspense");case d:return I("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return U(e.render,!1);case y:return A(e.type,r,t);case g:var o=e,a=o._payload,s=o._init;try{return A(s(a),r,t)}catch(i){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,W={},z=b.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);z.setExtraStackFrame(t)}else z.setExtraStackFrame(null)}var M=Array.isArray;function J(e){return M(e)}function Y(e){return""+e}function q(e){if(function(e){try{return Y(e),!1}catch(r){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Y(e)}var H,K,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,t,o,a){var s,i={},c=null,l=null;for(s in void 0!==t&&(q(t),c=""+t),function(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(q(r.key),c=""+r.key),function(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(l=r.ref,function(e){"string"==typeof e.ref&&X.current}(r)),r)V.call(r,s)&&!G.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var u=e.defaultProps;for(s in u)void 0===i[s]&&(i[s]=u[s])}if(c||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){H||(H=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,f),l&&function(e,r){var t=function(){K||(K=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,f)}return function(e,r,t,o,a,s,i){var c={$$typeof:n,type:e,key:r,ref:t,props:i,_owner:s,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,l,a,o,X.current,i)}var Z,ee=b.ReactCurrentOwner,re=b.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function se(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function ie(e,r){if("object"==typeof e)if(J(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&se(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,s=o.call(e);!(a=s.next()).done;)ne(a.value)&&se(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==f&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(V);for(var s in e)if(a(e,s)){var i=void 0;try{if("function"!=typeof e[s]){var c=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){i=l}!i||i instanceof Error||(B(o),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,s,typeof i),B(null)),i instanceof Error&&!(i.message in W)&&(W[i.message]=!0,B(o),h("Failed %s type: %s",t,i.message),B(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function ue(e,t,o,s,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===c||e===i||e===p||e===d||e===m||"object"==typeof e&&null!==e&&(e.$$typeof===g||e.$$typeof===y||e.$$typeof===l||e.$$typeof===u||e.$$typeof===f||e.$$typeof===r||void 0!==e.getModuleId)}(e);if(!w){var _,E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),E+=oe(),null===e?_="null":J(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,E)}var S=Q(e,t,o,v,b);if(null==S)return S;if(w){var O=t.children;if(void 0!==O)if(s)if(J(O)){for(var j=0;j<O.length;j++)ie(O[j],e);Object.freeze&&Object.freeze(O)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ie(O,e)}if(V.call(t,"key")){var C=k(e),P=Object.keys(t).filter((function(e){return"key"!==e})),R=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";le[C+R]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',R,C,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",C),le[C+R]=!0)}return e===a?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(S):ce(S),S}var fe=function(e,r,t){return ue(e,r,t,!1)},pe=function(e,r,t){return ue(e,r,t,!0)};s.Fragment=a,s.jsx=fe,s.jsxs=pe}()),s);var i=n.exports;const c={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},l=e.createContext({config:{...c},setConfig:()=>{},data:{},setData:()=>{}});function u(){const r=e.useContext(l);if(!r)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return r}function f(){const{config:e}=u();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}const p="https://events.embeddable.co";exports.EmbeddableProvider=function({config:r,data:t,children:n}){const[o,a]=e.useState(c),[s,u]=e.useState(t||{});return e.useEffect((()=>{a({...c,...r})}),[r]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&u(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),i.jsx(l.Provider,{value:{config:o,setConfig:a,data:s,setData:u},children:n})},exports.useApi=function(t){const n=t;if(!n)throw new Error("No API configuration provided. Either pass a config parameter or wrap your app with EmbeddableProvider.");const[o,a]=e.useState({data:null,loading:!1,error:null}),s=r.createApiClient(n),i=e.useCallback((async(e,r,t)=>{a((e=>({...e,loading:!0,error:null})));try{let n;switch(e){case"get":n=await s.get(r);break;case"post":n=await s.post(r,t);break;case"put":n=await s.put(r,t);break;case"delete":n=await s.delete(r);break;default:throw new Error(`Unsupported method: ${e}`)}return a({data:n.data,loading:!1,error:n.success?null:n.error||"Unknown error"}),n}catch(n){const e=n instanceof Error?n.message:"Unknown error";return a({data:null,loading:!1,error:e}),{data:null,success:!1,error:e}}}),[s]);return{...o,get:e.useCallback((e=>i("get",e)),[i]),post:e.useCallback(((e,r)=>i("post",e,r)),[i]),put:e.useCallback(((e,r)=>i("put",e,r)),[i]),delete:e.useCallback((e=>i("delete",e)),[i]),reset:e.useCallback((()=>{a({data:null,loading:!1,error:null})}),[])}},exports.useDebounce=function(r,t){const[n,o]=e.useState(r);return e.useEffect((()=>{const e=setTimeout((()=>{o(r)}),t);return()=>{clearTimeout(e)}}),[r,t]),n},exports.useEmbeddableConfig=f,exports.useEmbeddableConfigSafe=function(){const{config:e}=u();return e},exports.useEmbeddableContext=u,exports.useEmbeddableData=function(){const{data:e}=u();return{data:e}},exports.useFormSubmission=function(r){const{widgetId:t}=f(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{if(null==r?void 0:r.validatePayload){const t=r.validatePayload(e);if(t)return o({loading:!1,error:t,success:!1}),{success:!1,message:t}}const i={payload:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"submissions"},c=await fetch(`${p}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Submission successful"};{const e=l.message||l.error||"Submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useLocalStorage=function(t,n,o={}){const[a,s]=e.useState((()=>{const e=r.storage.get(t,o);return null!==e?e:n})),i=e.useCallback((e=>{try{const n=e instanceof Function?e(a):e;s(n),r.storage.set(t,n,o)}catch(n){}}),[t,a,o]),c=e.useCallback((()=>{try{s(n),r.storage.remove(t,o)}catch(e){}}),[t,n,o]);return e.useEffect((()=>{const e=e=>{const{prefix:r=""}=o,n=r+t;if(e.key===n&&null!==e.newValue)try{const{deserialize:r=JSON.parse}=o,t=r(e.newValue);s(t)}catch(a){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,o]),[a,i,c]},exports.useVote=function(r){const{widgetId:t}=f(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{const i={voteFor:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"votes"},c=await fetch(`${p}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Vote submitted successfully"};{const e=l.message||l.error||"Vote submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useVoteAggregations=function(r){const{widgetId:t}=f(),[n,o]=e.useState({data:null,loading:!1,error:null}),a=e.useCallback((async()=>{if(!t)return o({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};o((e=>({...e,loading:!0,error:null})));try{const e=(null==r?void 0:r.collectionName)||"votes",n=new URL(`${p}/api/votes/aggregations`);n.searchParams.append("widgetId",t),n.searchParams.append("collectionName",e);const a=await fetch(n.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return o({data:s.data,loading:!1,error:null}),s}catch(e){const r=e instanceof Error?e.message:"Unknown error occurred";return o({data:null,loading:!1,error:r}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}}),[t,null==r?void 0:r.collectionName]),s=e.useCallback((()=>a()),[a]),i=e.useCallback((()=>{o({data:null,loading:!1,error:null})}),[]);return e.useEffect((()=>{!1!==(null==r?void 0:r.autoFetch)&&t&&a()}),[a,null==r?void 0:r.autoFetch,t]),e.useEffect((()=>{if((null==r?void 0:r.refetchInterval)&&r.refetchInterval>0&&t){const e=setInterval((()=>{a()}),r.refetchInterval);return()=>clearInterval(e)}}),[a,null==r?void 0:r.refetchInterval,t]),{...n,fetch:a,refetch:s,reset:i}};
|
|
10
|
+
*/"production"===process.env.NODE_ENV?n.exports=function(){if(t)return o;t=1;var r=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,r,t){var o,a={},l=null,u=null;for(o in void 0!==t&&(l=""+t),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(u=r.ref),r)s.call(r,o)&&!c.hasOwnProperty(o)&&(a[o]=r[o]);if(e&&e.defaultProps)for(o in r=e.defaultProps)void 0===a[o]&&(a[o]=r[o]);return{$$typeof:n,type:e,key:l,ref:u,props:a,_owner:i.current}}return o.Fragment=a,o.jsx=l,o.jsxs=l,o}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var r,t=e,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),v=Symbol.iterator,b=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case c:return"Profiler";case i:return"StrictMode";case d:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case l:return w(e._context)+".Provider";case f:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:k(e.type)||"Memo";case g:var t=e,n=t._payload,s=t._init;try{return k(s(n))}catch(m){return null}}return null}r=Symbol.for("react.module.reference");var _,S,E,O,j,T,P,x=Object.assign,C=0;function R(){}R.__reactDisabledLog=!0;var I,$=b.ReactCurrentDispatcher;function N(e,r,t){if(void 0===I)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);I=n&&n[1]||""}return"\n"+I+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,r){if(!e||F)return"";var t,n=D.get(e);if(void 0!==n)return n;F=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=$.current,$.current=null,function(){if(0===C){_=console.log,S=console.info,E=console.warn,O=console.error,j=console.group,T=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:R,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}C++}();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){t=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){t=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){t=y}e()}}catch(g){if(g&&t&&"string"==typeof g.stack){for(var i=g.stack.split("\n"),c=t.stack.split("\n"),l=i.length-1,u=c.length-1;l>=1&&u>=0&&i[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(i[l]!==c[u]){if(1!==l||1!==u)do{if(l--,--u<0||i[l]!==c[u]){var f="\n"+i[l].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,f),f}}while(l>=1&&u>=0);break}}}finally{F=!1,$.current=o,function(){if(0===--C){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:_}),info:x({},e,{value:S}),warn:x({},e,{value:E}),error:x({},e,{value:O}),group:x({},e,{value:j}),groupCollapsed:x({},e,{value:T}),groupEnd:x({},e,{value:P})})}C<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var d=e?e.displayName||e.name:"",p=d?N(d):"";return"function"==typeof e&&D.set(e,p),p}function A(e,r,t){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case d:return N("Suspense");case p:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case f:return U(e.render,!1);case y:return A(e.type,r,t);case g:var o=e,a=o._payload,s=o._init;try{return A(s(a),r,t)}catch(i){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,W={},z=b.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);z.setExtraStackFrame(t)}else z.setExtraStackFrame(null)}var B=Array.isArray;function J(e){return B(e)}function Y(e){return""+e}function q(e){if(function(e){try{return Y(e),!1}catch(r){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Y(e)}var H,K,X=b.ReactCurrentOwner,G={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,r,t,o,a){var s,i={},c=null,l=null;for(s in void 0!==t&&(q(t),c=""+t),function(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(q(r.key),c=""+r.key),function(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(l=r.ref,function(e){"string"==typeof e.ref&&X.current}(r)),r)V.call(r,s)&&!G.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var u=e.defaultProps;for(s in u)void 0===i[s]&&(i[s]=u[s])}if(c||l){var f="function"==typeof e?e.displayName||e.name||"Unknown":e;c&&function(e,r){var t=function(){H||(H=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,f),l&&function(e,r){var t=function(){K||(K=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,f)}return function(e,r,t,o,a,s,i){var c={$$typeof:n,type:e,key:r,ref:t,props:i,_owner:s,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(e,c,l,a,o,X.current,i)}var Z,ee=b.ReactCurrentOwner,re=b.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,t=A(e.type,e._source,r?r.type:null);re.setExtraStackFrame(t)}else re.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function se(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=oe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ae[t]){ae[t]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),te(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),te(null)}}}function ie(e,r){if("object"==typeof e)if(J(e))for(var t=0;t<e.length;t++){var n=e[t];ne(n)&&se(n,r)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e["@@iterator"];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,s=o.call(e);!(a=s.next()).done;)ne(a.value)&&se(a.value,r)}}function ce(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==f&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=k(t);!function(e,r,t,n,o){var a=Function.call.bind(V);for(var s in e)if(a(e,s)){var i=void 0;try{if("function"!=typeof e[s]){var c=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){i=l}!i||i instanceof Error||(M(o),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,s,typeof i),M(null)),i instanceof Error&&!(i.message in W)&&(W[i.message]=!0,M(o),h("Failed %s type: %s",t,i.message),M(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function ue(e,t,o,s,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===c||e===i||e===d||e===p||e===m||"object"==typeof e&&null!==e&&(e.$$typeof===g||e.$$typeof===y||e.$$typeof===l||e.$$typeof===u||e.$$typeof===f||e.$$typeof===r||void 0!==e.getModuleId)}(e);if(!w){var _,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=oe(),null===e?_="null":J(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,S)}var E=Q(e,t,o,v,b);if(null==E)return E;if(w){var O=t.children;if(void 0!==O)if(s)if(J(O)){for(var j=0;j<O.length;j++)ie(O[j],e);Object.freeze&&Object.freeze(O)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ie(O,e)}if(V.call(t,"key")){var T=k(e),P=Object.keys(t).filter((function(e){return"key"!==e})),x=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";le[T+x]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',x,T,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",T),le[T+x]=!0)}return e===a?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){te(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),te(null);break}}null!==e.ref&&(te(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}(E):ce(E),E}var fe=function(e,r,t){return ue(e,r,t,!1)},de=function(e,r,t){return ue(e,r,t,!0)};s.Fragment=a,s.jsx=fe,s.jsxs=de}()),s);var i=n.exports;const c={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},l=e.createContext({config:{...c},setConfig:()=>{},data:{},setData:()=>{}});function u(){const r=e.useContext(l);if(!r)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return r}const f="https://events.embeddable.co";function d(){const{config:e}=u();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}exports.EmbeddableProvider=function({config:r,data:t,children:n}){const[o,a]=e.useState(c),[s,u]=e.useState(t||{});return e.useEffect((()=>{a({...c,...r})}),[r]),e.useEffect((()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&u(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[]),i.jsx(l.Provider,{value:{config:o,setConfig:a,data:s,setData:u},children:n})},exports.useAI=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,callAI:e.useCallback((async(e,n)=>{var a;o({loading:!0,error:null,success:!1});try{const s={widgetId:t,capabilityId:"ai_call",integrationKey:r.platform,prompt:e,history:n||[]},i=await fetch(`${f}/api/execute/ai`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(s)}),c=await i.json();if(!i.ok){const e=c.message||c.error||`HTTP ${i.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(c.success)return o({loading:!1,error:null,success:!0}),{success:!0,message:(null==(a=c.data)?void 0:a.response)||"AI call completed successfully",data:c.data,metadata:c.metadata};{const e=c.message||c.error||"AI call failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(s){const e=s instanceof Error?s.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r.platform,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useDebounce=function(r,t){const[n,o]=e.useState(r);return e.useEffect((()=>{const e=setTimeout((()=>{o(r)}),t);return()=>{clearTimeout(e)}}),[r,t]),n},exports.useEmbeddableConfig=d,exports.useEmbeddableContext=u,exports.useEmbeddableData=function(){const{data:e}=u();return{data:e}},exports.useFormSubmission=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{if(null==r?void 0:r.validatePayload){const t=r.validatePayload(e);if(t)return o({loading:!1,error:t,success:!1}),{success:!1,message:t}}const i={payload:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"submissions"},c=await fetch(`${f}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Submission successful"};{const e=l.message||l.error||"Submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useLocalStorage=function(t,n,o={}){const{widgetId:a}=d(),s=e.useMemo((()=>({...o,prefix:`embd-${a}-${o.prefix||""}`})),[a,o]),[i,c]=e.useState((()=>{const e=r.storage.get(t,s);return null!==e?e:n})),l=e.useCallback((e=>{try{const n=e instanceof Function?e(i):e;c(n),r.storage.set(t,n,s)}catch(n){}}),[t,i,s]),u=e.useCallback((()=>{try{c(n),r.storage.remove(t,s)}catch(e){}}),[t,n,s]);return e.useEffect((()=>{const e=e=>{const r=s.prefix+t;if(e.key===r&&null!==e.newValue)try{const{deserialize:r=JSON.parse}=s,t=r(e.newValue);c(t)}catch(n){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)}),[t,s]),[i,l,u]},exports.useVote=function(r){const{widgetId:t}=d(),[n,o]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback((async e=>{var n,a,s;o({loading:!0,error:null,success:!1});try{const i={voteFor:e,widgetId:t,collectionName:(null==r?void 0:r.collectionName)||"votes"},c=await fetch(`${f}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(i)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return o({loading:!1,error:null,success:!0}),{id:(null==(n=l.data)?void 0:n.id)||(null==(a=l.data)?void 0:a._id),success:!0,message:(null==(s=l.data)?void 0:s.message)||"Vote submitted successfully"};{const e=l.message||l.error||"Vote submission failed";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(i){const e=i instanceof Error?i.message:"Unknown error occurred";return o({loading:!1,error:e,success:!1}),{success:!1,message:e}}}),[r,t]),reset:e.useCallback((()=>{o({loading:!1,error:null,success:!1})}),[])}},exports.useVoteAggregations=function(r){const{widgetId:t}=d(),[n,o]=e.useState({data:null,loading:!1,error:null}),a=e.useCallback((async()=>{if(!t)return o({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};o((e=>({...e,loading:!0,error:null})));try{const e=(null==r?void 0:r.collectionName)||"votes",n=new URL(`${f}/api/votes/aggregations`);n.searchParams.append("widgetId",t),n.searchParams.append("collectionName",e);const a=await fetch(n.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return o({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return o({data:s.data,loading:!1,error:null}),s}catch(e){const r=e instanceof Error?e.message:"Unknown error occurred";return o({data:null,loading:!1,error:r}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}}),[t,null==r?void 0:r.collectionName]),s=e.useCallback((()=>a()),[a]),i=e.useCallback((()=>{o({data:null,loading:!1,error:null})}),[]);return e.useEffect((()=>{!1!==(null==r?void 0:r.autoFetch)&&t&&a()}),[a,null==r?void 0:r.autoFetch,t]),e.useEffect((()=>{if((null==r?void 0:r.refetchInterval)&&r.refetchInterval>0&&t){const e=setInterval((()=>{a()}),r.refetchInterval);return()=>clearInterval(e)}}),[a,null==r?void 0:r.refetchInterval,t]),{...n,fetch:a,refetch:s,reset:i}};
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./storage-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./storage-EjA7Lhbb.cjs");exports.storage=e.storage,exports.createApiClient=function(e){const t=e.baseUrl||"https://api.embeddable.com",o={"Content-Type":"application/json"};e.apiKey&&(o.Authorization=`Bearer ${e.apiKey}`);const r=async(r,s={})=>{try{const e=`${t}${r}`,a=await fetch(e,{...s,headers:{...o,...s.headers}}),n=await a.json();return a.ok?{data:n,success:!0}:{data:null,success:!1,error:n.message||`HTTP ${a.status}`}}catch(a){return e.debug,{data:null,success:!1,error:a instanceof Error?a.message:"Unknown error"}}};return{get:e=>r(e,{method:"GET"}),post:(e,t)=>r(e,{method:"POST",body:t?JSON.stringify(t):void 0}),put:(e,t)=>r(e,{method:"PUT",body:t?JSON.stringify(t):void 0}),delete:e=>r(e,{method:"DELETE"})}},exports.debounce=function(e,t){let o;return function(...r){void 0!==o&&clearTimeout(o),o=setTimeout((()=>{o=void 0,e(...r)}),t)}};
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s } from "./storage-B4eeCFyo.js";
|
|
2
|
+
function createApiClient(config) {
|
|
3
|
+
const baseUrl = config.baseUrl || "https://api.embeddable.com";
|
|
4
|
+
const headers = {
|
|
5
|
+
"Content-Type": "application/json"
|
|
6
|
+
};
|
|
7
|
+
if (config.apiKey) {
|
|
8
|
+
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
9
|
+
}
|
|
10
|
+
const request = async (endpoint, options = {}) => {
|
|
11
|
+
try {
|
|
12
|
+
const url = `${baseUrl}${endpoint}`;
|
|
13
|
+
const response = await fetch(url, {
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
...headers,
|
|
17
|
+
...options.headers
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
return {
|
|
23
|
+
data: null,
|
|
24
|
+
success: false,
|
|
25
|
+
error: data.message || `HTTP ${response.status}`
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
data,
|
|
30
|
+
success: true
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (config.debug) {
|
|
34
|
+
console.error("API Request failed:", error);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
data: null,
|
|
38
|
+
success: false,
|
|
39
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
get: (endpoint) => request(endpoint, { method: "GET" }),
|
|
45
|
+
post: (endpoint, body) => request(endpoint, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: body ? JSON.stringify(body) : void 0
|
|
48
|
+
}),
|
|
49
|
+
put: (endpoint, body) => request(endpoint, {
|
|
50
|
+
method: "PUT",
|
|
51
|
+
body: body ? JSON.stringify(body) : void 0
|
|
52
|
+
}),
|
|
53
|
+
delete: (endpoint) => request(endpoint, { method: "DELETE" })
|
|
54
|
+
};
|
|
55
|
+
}
|
|
2
56
|
function debounce(func, wait) {
|
|
3
57
|
let timeoutId;
|
|
4
58
|
return function debounced(...args) {
|
|
@@ -13,7 +67,7 @@ function debounce(func, wait) {
|
|
|
13
67
|
};
|
|
14
68
|
}
|
|
15
69
|
export {
|
|
16
|
-
|
|
70
|
+
createApiClient,
|
|
17
71
|
debounce,
|
|
18
72
|
s as storage
|
|
19
73
|
};
|
package/package.json
CHANGED
package/dist/hooks/useApi.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ApiResponse, EmbeddableApiConfig } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* React hook for API calls with loading and error states
|
|
5
|
-
* @param config - API configuration (optional, will use global config if not provided)
|
|
6
|
-
* @returns API client with state management
|
|
7
|
-
*/
|
|
8
|
-
export declare function useApi(config?: EmbeddableApiConfig): {
|
|
9
|
-
get: <T = any>(endpoint: string) => Promise<ApiResponse<T>>;
|
|
10
|
-
post: <T = any>(endpoint: string, body?: any) => Promise<ApiResponse<T>>;
|
|
11
|
-
put: <T = any>(endpoint: string, body?: any) => Promise<ApiResponse<T>>;
|
|
12
|
-
delete: <T = any>(endpoint: string) => Promise<ApiResponse<T>>;
|
|
13
|
-
reset: () => void;
|
|
14
|
-
data: any;
|
|
15
|
-
loading: boolean;
|
|
16
|
-
error: string | null;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=useApi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e={get(e,t={}){try{const{prefix:r="",deserialize:o=JSON.parse}=t,a=r+e,s=localStorage.getItem(a);return null===s?null:o(s)}catch(r){return null}},set(e,t,r={}){try{const{prefix:o="",serialize:a=JSON.stringify}=r,s=o+e,c=a(t);localStorage.setItem(s,c)}catch(o){}},remove(e,t={}){try{const{prefix:r=""}=t,o=r+e;localStorage.removeItem(o)}catch(r){}},clear(e={}){try{const{prefix:t=""}=e;if(!t)return void localStorage.clear();const r=[];for(let e=0;e<localStorage.length;e++){const o=localStorage.key(e);o&&o.startsWith(t)&&r.push(o)}r.forEach((e=>localStorage.removeItem(e)))}catch(t){}},isAvailable(){try{const e="__storage_test__";return localStorage.setItem(e,"test"),localStorage.removeItem(e),!0}catch{return!1}}};exports.createApiClient=function(e){const t=e.baseUrl||"https://api.embeddable.com",r={"Content-Type":"application/json"};e.apiKey&&(r.Authorization=`Bearer ${e.apiKey}`);const o=async(o,a={})=>{try{const e=`${t}${o}`,s=await fetch(e,{...a,headers:{...r,...a.headers}}),c=await s.json();return s.ok?{data:c,success:!0}:{data:null,success:!1,error:c.message||`HTTP ${s.status}`}}catch(s){return e.debug,{data:null,success:!1,error:s instanceof Error?s.message:"Unknown error"}}};return{get:e=>o(e,{method:"GET"}),post:(e,t)=>o(e,{method:"POST",body:t?JSON.stringify(t):void 0}),put:(e,t)=>o(e,{method:"PUT",body:t?JSON.stringify(t):void 0}),delete:e=>o(e,{method:"DELETE"})}},exports.storage=e;
|