@perspective-ai/sdk 1.0.0-alpha.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 +333 -0
- package/dist/browser.cjs +1939 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +213 -0
- package/dist/browser.d.ts +213 -0
- package/dist/browser.js +1900 -0
- package/dist/browser.js.map +1 -0
- package/dist/cdn/perspective.global.js +406 -0
- package/dist/cdn/perspective.global.js.map +1 -0
- package/dist/constants.cjs +142 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +104 -0
- package/dist/constants.d.ts +104 -0
- package/dist/constants.js +127 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +1596 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +155 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.js +1579 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
- package/src/browser.test.ts +388 -0
- package/src/browser.ts +509 -0
- package/src/config.test.ts +81 -0
- package/src/config.ts +95 -0
- package/src/constants.ts +214 -0
- package/src/float.test.ts +332 -0
- package/src/float.ts +231 -0
- package/src/fullpage.test.ts +224 -0
- package/src/fullpage.ts +126 -0
- package/src/iframe.test.ts +1037 -0
- package/src/iframe.ts +421 -0
- package/src/index.ts +61 -0
- package/src/loading.ts +90 -0
- package/src/popup.test.ts +344 -0
- package/src/popup.ts +157 -0
- package/src/slider.test.ts +277 -0
- package/src/slider.ts +158 -0
- package/src/styles.ts +395 -0
- package/src/types.ts +148 -0
- package/src/utils.test.ts +162 -0
- package/src/utils.ts +86 -0
- package/src/widget.test.ts +375 -0
- package/src/widget.ts +195 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
declare const ERROR_CODES: {
|
|
2
|
+
readonly SDK_OUTDATED: "SDK_OUTDATED";
|
|
3
|
+
readonly INVALID_RESEARCH: "INVALID_RESEARCH";
|
|
4
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
5
|
+
};
|
|
6
|
+
type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
7
|
+
declare const THEME_VALUES: {
|
|
8
|
+
readonly dark: "dark";
|
|
9
|
+
readonly light: "light";
|
|
10
|
+
readonly system: "system";
|
|
11
|
+
};
|
|
12
|
+
type ThemeValue = (typeof THEME_VALUES)[keyof typeof THEME_VALUES];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definitions for the Perspective Embed SDK
|
|
16
|
+
* This file is TYPE-ONLY - no runtime value imports or exports
|
|
17
|
+
* SSR-safe by design
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
type EmbedType = "widget" | "popup" | "slider" | "float" | "fullpage" | "chat";
|
|
21
|
+
/** Brand colors that can be passed via embed code */
|
|
22
|
+
interface BrandColors {
|
|
23
|
+
/** Primary accent color (buttons, links, focus states) */
|
|
24
|
+
primary?: string;
|
|
25
|
+
/** Secondary accent color */
|
|
26
|
+
secondary?: string;
|
|
27
|
+
/** Background color of the embed */
|
|
28
|
+
bg?: string;
|
|
29
|
+
/** Primary text color */
|
|
30
|
+
text?: string;
|
|
31
|
+
}
|
|
32
|
+
interface EmbedConfig {
|
|
33
|
+
researchId: string;
|
|
34
|
+
type?: EmbedType;
|
|
35
|
+
/** Custom button text for popup/slider triggers */
|
|
36
|
+
buttonText?: string;
|
|
37
|
+
/** Custom params to pass to the interview (for tracking/attribution) */
|
|
38
|
+
params?: Record<string, string>;
|
|
39
|
+
/** Brand colors to override Research settings */
|
|
40
|
+
brand?: {
|
|
41
|
+
light?: BrandColors;
|
|
42
|
+
dark?: BrandColors;
|
|
43
|
+
};
|
|
44
|
+
/** Force theme mode: 'dark', 'light', or 'system' (default) */
|
|
45
|
+
theme?: ThemeValue;
|
|
46
|
+
/** Override the default host (defaults to https://getperspective.ai) */
|
|
47
|
+
host?: string;
|
|
48
|
+
/** Callback when embed is ready */
|
|
49
|
+
onReady?: () => void;
|
|
50
|
+
/** Callback when interview is submitted/completed */
|
|
51
|
+
onSubmit?: (data: {
|
|
52
|
+
researchId: string;
|
|
53
|
+
}) => void;
|
|
54
|
+
/** Callback when embed wants to navigate. If provided, parent handles navigation; otherwise SDK navigates via window.location.href */
|
|
55
|
+
onNavigate?: (url: string) => void;
|
|
56
|
+
/** Callback when embed is closed */
|
|
57
|
+
onClose?: () => void;
|
|
58
|
+
/** Callback on any error */
|
|
59
|
+
onError?: (error: EmbedError) => void;
|
|
60
|
+
}
|
|
61
|
+
/** Embed error with code for programmatic handling */
|
|
62
|
+
interface EmbedError extends Error {
|
|
63
|
+
code?: ErrorCode;
|
|
64
|
+
}
|
|
65
|
+
/** Handle returned by embed creation functions */
|
|
66
|
+
interface EmbedHandle {
|
|
67
|
+
unmount: () => void;
|
|
68
|
+
update: (options: Partial<Pick<EmbedConfig, "onReady" | "onSubmit" | "onNavigate" | "onClose" | "onError">>) => void;
|
|
69
|
+
/** @deprecated Use unmount() instead */
|
|
70
|
+
destroy: () => void;
|
|
71
|
+
/** @deprecated For legacy compatibility */
|
|
72
|
+
readonly researchId: string;
|
|
73
|
+
/** @deprecated For legacy compatibility */
|
|
74
|
+
readonly type: EmbedType;
|
|
75
|
+
/** @deprecated For legacy compatibility - may be null on server */
|
|
76
|
+
readonly iframe: HTMLIFrameElement | null;
|
|
77
|
+
/** @deprecated For legacy compatibility - may be null on server */
|
|
78
|
+
readonly container: HTMLElement | null;
|
|
79
|
+
}
|
|
80
|
+
/** Handle for float bubble with open/close control (persistent UI element) */
|
|
81
|
+
interface FloatHandle extends Omit<EmbedHandle, "type"> {
|
|
82
|
+
open: () => void;
|
|
83
|
+
close: () => void;
|
|
84
|
+
toggle: () => void;
|
|
85
|
+
readonly isOpen: boolean;
|
|
86
|
+
readonly type: "float";
|
|
87
|
+
}
|
|
88
|
+
/** Theme configuration from API */
|
|
89
|
+
interface ThemeConfig {
|
|
90
|
+
primaryColor: string;
|
|
91
|
+
textColor: string;
|
|
92
|
+
darkPrimaryColor: string;
|
|
93
|
+
darkTextColor: string;
|
|
94
|
+
}
|
|
95
|
+
/** SDK global configuration */
|
|
96
|
+
interface SDKConfig {
|
|
97
|
+
/** Override the default host */
|
|
98
|
+
host?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Inline widget embed - renders directly in a container element
|
|
103
|
+
* SSR-safe - returns no-op handle on server
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
declare function createWidget(container: HTMLElement | null, config: EmbedConfig): EmbedHandle;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Popup/modal embed - opens in a centered modal overlay
|
|
110
|
+
* SSR-safe - returns no-op handle on server
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
declare function openPopup(config: EmbedConfig): EmbedHandle;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Slider/drawer embed - slides in from the right
|
|
117
|
+
* SSR-safe - returns no-op handle on server
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
declare function openSlider(config: EmbedConfig): EmbedHandle;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Floating bubble embed - floating button that opens a chat window
|
|
124
|
+
* SSR-safe - returns no-op handle on server
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
type FloatConfig = EmbedConfig & {
|
|
128
|
+
_themeConfig?: ThemeConfig;
|
|
129
|
+
};
|
|
130
|
+
declare function createFloatBubble(config: FloatConfig): FloatHandle;
|
|
131
|
+
/** @deprecated Use createFloatBubble instead */
|
|
132
|
+
declare const createChatBubble: typeof createFloatBubble;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Fullpage embed - takes over entire viewport
|
|
136
|
+
* SSR-safe - returns no-op handle on server
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
declare function createFullpage(config: EmbedConfig): EmbedHandle;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Embed SDK configuration
|
|
143
|
+
* SSR-safe - DOM access is guarded and lazy
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Configure the SDK globally
|
|
148
|
+
* Call this before creating any embeds if you need to override defaults
|
|
149
|
+
*/
|
|
150
|
+
declare function configure(config: SDKConfig): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get the current SDK configuration
|
|
153
|
+
*/
|
|
154
|
+
declare function getConfig(): SDKConfig;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Perspective Embed SDK - Browser Entry
|
|
158
|
+
*
|
|
159
|
+
* CDN/Script Tag Entry Point - auto-init, attaches to window.Perspective
|
|
160
|
+
*
|
|
161
|
+
* Usage:
|
|
162
|
+
* <script src="https://getperspective.ai/v1/perspective.js"></script>
|
|
163
|
+
*
|
|
164
|
+
* <!-- Auto-init with data attributes -->
|
|
165
|
+
* <div data-perspective-widget="research_xxx"></div>
|
|
166
|
+
* <button data-perspective-popup="research_xxx">Open Survey</button>
|
|
167
|
+
*
|
|
168
|
+
* <!-- Or programmatic -->
|
|
169
|
+
* <script>
|
|
170
|
+
* Perspective.openPopup({ researchId: 'xxx' });
|
|
171
|
+
* </script>
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Initialize an embed programmatically
|
|
176
|
+
*/
|
|
177
|
+
declare function init(config: EmbedConfig): EmbedHandle | FloatHandle;
|
|
178
|
+
/**
|
|
179
|
+
* Mount a widget into a container element
|
|
180
|
+
*/
|
|
181
|
+
declare function mount(container: HTMLElement | string, config: EmbedConfig): EmbedHandle;
|
|
182
|
+
/**
|
|
183
|
+
* Destroy an embed instance
|
|
184
|
+
*/
|
|
185
|
+
declare function destroy(researchId: string): void;
|
|
186
|
+
declare function destroyAll(): void;
|
|
187
|
+
/**
|
|
188
|
+
* Auto-initialize embeds from data attributes
|
|
189
|
+
*/
|
|
190
|
+
declare function autoInit(): void;
|
|
191
|
+
declare const Perspective: {
|
|
192
|
+
configure: typeof configure;
|
|
193
|
+
getConfig: typeof getConfig;
|
|
194
|
+
init: typeof init;
|
|
195
|
+
mount: typeof mount;
|
|
196
|
+
destroy: typeof destroy;
|
|
197
|
+
destroyAll: typeof destroyAll;
|
|
198
|
+
autoInit: typeof autoInit;
|
|
199
|
+
createWidget: typeof createWidget;
|
|
200
|
+
openPopup: typeof openPopup;
|
|
201
|
+
openSlider: typeof openSlider;
|
|
202
|
+
createFloatBubble: typeof createFloatBubble;
|
|
203
|
+
createFullpage: typeof createFullpage;
|
|
204
|
+
createChatBubble: typeof createFloatBubble;
|
|
205
|
+
};
|
|
206
|
+
declare global {
|
|
207
|
+
interface Window {
|
|
208
|
+
__PERSPECTIVE_SDK_INITIALIZED__?: boolean;
|
|
209
|
+
Perspective?: typeof Perspective;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { autoInit, configure, createChatBubble, createFloatBubble, createFullpage, createWidget, Perspective as default, destroy, destroyAll, getConfig, init, mount, openPopup, openSlider };
|