@intentai/react 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,80 +1,189 @@
1
- import React from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
2
3
 
3
- interface WidgetConfig {
4
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
5
- primaryColor?: string;
6
- accentColor?: string;
7
- theme?: 'light' | 'dark' | 'auto';
8
- categories?: Category[];
9
- allowVoice?: boolean;
10
- allowText?: boolean;
11
- allowScreenshot?: boolean;
12
- maxRecordingDuration?: number;
13
- onSubmit?: (feedback: FeedbackData) => Promise<void>;
14
- onOpen?: () => void;
15
- onClose?: () => void;
16
- }
17
- interface Category {
4
+ /**
5
+ * User identity for feedback attribution
6
+ */
7
+ interface UserIdentity {
8
+ /** Unique user identifier */
18
9
  id: string;
19
- label: string;
20
- icon: string;
10
+ /** User email address */
11
+ email?: string;
12
+ /** User display name */
13
+ name?: string;
14
+ /** User avatar URL */
15
+ avatar?: string;
16
+ /** Subscription plan */
17
+ plan?: string;
18
+ /** Company name */
19
+ company?: string;
20
+ /** Custom properties */
21
+ [key: string]: string | number | boolean | undefined;
21
22
  }
23
+ /**
24
+ * Widget position on screen
25
+ */
26
+ type WidgetPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
27
+ /**
28
+ * Widget color theme
29
+ */
30
+ type WidgetTheme = 'light' | 'dark' | 'auto';
31
+ /**
32
+ * Feedback type categories
33
+ */
34
+ type FeedbackType = 'bug' | 'feature' | 'question' | 'praise' | 'other';
35
+ /**
36
+ * Sentiment analysis result
37
+ */
38
+ type Sentiment = 'positive' | 'neutral' | 'negative';
39
+ /**
40
+ * Data returned when feedback is submitted
41
+ */
22
42
  interface FeedbackData {
23
- type: 'voice' | 'text';
43
+ /** Feedback ID */
44
+ id: string;
45
+ /** Type of feedback */
46
+ type: FeedbackType;
47
+ /** Text content */
24
48
  content: string;
25
- audioBlob?: Blob;
26
- transcription?: string;
27
- category: string;
49
+ /** Voice recording URL */
50
+ voiceUrl?: string;
51
+ /** Screenshot data URL */
28
52
  screenshot?: string;
29
- sentiment?: string;
53
+ /** AI-analyzed sentiment */
54
+ sentiment?: Sentiment;
55
+ /** Submission timestamp */
56
+ createdAt: string;
57
+ }
58
+ /**
59
+ * Options for opening the widget
60
+ */
61
+ interface OpenOptions {
62
+ /** Pre-select feedback type */
63
+ type?: FeedbackType;
64
+ /** Prefill text content */
65
+ prefill?: {
66
+ text?: string;
67
+ };
68
+ /** Additional metadata for this feedback */
30
69
  metadata?: Record<string, unknown>;
31
70
  }
32
- declare const PremiumVoiceWidget: React.FC<WidgetConfig>;
33
-
34
- interface IntentAIProviderConfig {
35
- /** Your Intent AI API key (required) */
36
- apiKey: string;
37
- /** API URL (defaults to production) */
38
- apiUrl?: string;
39
- /** User information for identifying feedback */
40
- user?: IntentAIUser$1;
41
- /** Additional metadata to attach to all feedback */
71
+ /**
72
+ * Configuration options for the Intent AI widget
73
+ */
74
+ interface IntentAIConfig {
75
+ /**
76
+ * Your Intent AI public key (pk_live_* or pk_test_*)
77
+ * Can also be set via environment variables:
78
+ * - NEXT_PUBLIC_INTENT_AI_KEY
79
+ * - REACT_APP_INTENT_AI_KEY
80
+ * - VITE_INTENT_AI_KEY
81
+ */
82
+ apiKey?: string;
83
+ /**
84
+ * Widget position on screen
85
+ * @default "bottom-right"
86
+ */
87
+ position?: WidgetPosition;
88
+ /**
89
+ * Color theme
90
+ * @default "auto"
91
+ */
92
+ theme?: WidgetTheme;
93
+ /**
94
+ * Primary brand color (hex)
95
+ * @default "#6366f1"
96
+ */
97
+ primaryColor?: string;
98
+ /**
99
+ * Show widget button automatically
100
+ * @default true
101
+ */
102
+ autoShow?: boolean;
103
+ /**
104
+ * Initial user identification
105
+ */
106
+ user?: UserIdentity;
107
+ /**
108
+ * Custom metadata attached to all feedback
109
+ */
42
110
  metadata?: Record<string, unknown>;
111
+ /**
112
+ * Callback when widget is ready
113
+ */
114
+ onReady?: () => void;
115
+ /**
116
+ * Callback when widget opens
117
+ */
118
+ onOpen?: () => void;
119
+ /**
120
+ * Callback when widget closes
121
+ */
122
+ onClose?: () => void;
123
+ /**
124
+ * Callback when feedback is submitted
125
+ */
126
+ onSubmit?: (feedback: FeedbackData) => void;
127
+ /**
128
+ * Callback when an error occurs
129
+ */
130
+ onError?: (error: Error) => void;
43
131
  }
44
- interface IntentAIUser$1 {
45
- id?: string;
46
- email?: string;
47
- name?: string;
48
- [key: string]: unknown;
132
+ /**
133
+ * Props for IntentAIProvider component
134
+ */
135
+ interface IntentAIProviderProps extends IntentAIConfig {
136
+ children: React.ReactNode;
49
137
  }
138
+ /**
139
+ * Context value for IntentAI provider
140
+ */
50
141
  interface IntentAIContextValue {
51
- /** Identify the current user */
52
- identify: (user: IntentAIUser$1) => void;
53
- /** Set metadata to attach to feedback */
142
+ /** Whether the widget is loaded and ready */
143
+ isReady: boolean;
144
+ /** Error if widget failed to load */
145
+ error: Error | null;
146
+ /** Open the feedback widget */
147
+ open: (options?: OpenOptions) => void;
148
+ /** Close the feedback widget */
149
+ close: () => void;
150
+ /** Identify a user */
151
+ identify: (user: UserIdentity) => void;
152
+ /** Track a custom event */
153
+ track: (event: string, properties?: Record<string, unknown>) => void;
154
+ /** Set custom metadata */
54
155
  setMetadata: (metadata: Record<string, unknown>) => void;
55
- /** Clear the current user */
56
- clearUser: () => void;
57
- /** Whether the provider is configured */
58
- isConfigured: boolean;
59
156
  }
60
157
  /**
61
- * Hook to access Intent AI context for user identification and metadata
158
+ * Intent AI widget instance methods
62
159
  */
63
- declare function useIntentAI(): IntentAIContextValue;
64
- interface IntentAIProviderProps extends IntentAIProviderConfig {
65
- /** Widget configuration options */
66
- widgetConfig?: Omit<WidgetConfig, 'onSubmit'>;
67
- /** Children components */
68
- children?: React.ReactNode;
69
- /** Disable the widget (only provide context) */
70
- disableWidget?: boolean;
71
- /** Callback when feedback is submitted successfully */
72
- onFeedbackSubmitted?: () => void;
73
- /** Callback when there's an error */
74
- onError?: (error: Error) => void;
160
+ interface IntentAIInstance {
161
+ open: (options?: OpenOptions) => void;
162
+ close: () => void;
163
+ identify: (user: UserIdentity) => void;
164
+ track: (event: string, properties?: Record<string, unknown>) => void;
165
+ setMetadata: (metadata: Record<string, unknown>) => void;
166
+ destroy: () => void;
167
+ }
168
+ /**
169
+ * Window augmentation for Intent AI global
170
+ */
171
+ declare global {
172
+ interface Window {
173
+ IntentAI?: IntentAIInstance;
174
+ IntentAIConfig?: IntentAIConfig;
175
+ }
176
+ interface WindowEventMap {
177
+ 'intentai:ready': CustomEvent;
178
+ 'intentai:open': CustomEvent;
179
+ 'intentai:close': CustomEvent;
180
+ 'intentai:submit': CustomEvent<FeedbackData>;
181
+ 'intentai:error': CustomEvent<Error>;
182
+ }
75
183
  }
184
+
76
185
  /**
77
- * Intent AI Provider - Wraps your app with feedback collection capabilities
186
+ * Provider component for Intent AI widget
78
187
  *
79
188
  * @example
80
189
  * ```tsx
@@ -82,193 +191,189 @@ interface IntentAIProviderProps extends IntentAIProviderConfig {
82
191
  *
83
192
  * function App() {
84
193
  * return (
85
- * <IntentAIProvider
86
- * apiKey="your-api-key"
87
- * user={{ id: 'user-123', email: 'user@example.com' }}
88
- * >
194
+ * <IntentAIProvider apiKey="pk_live_xxxxx">
89
195
  * <YourApp />
90
196
  * </IntentAIProvider>
91
197
  * );
92
198
  * }
93
199
  * ```
94
200
  */
95
- declare function IntentAIProvider({ apiKey, apiUrl, user: initialUser, metadata: initialMetadata, widgetConfig, children, disableWidget, onFeedbackSubmitted, onError, }: IntentAIProviderProps): React.ReactElement;
201
+ declare function IntentAIProvider({ children, apiKey, user, position, theme, primaryColor, autoShow, metadata, onReady, onOpen, onClose, onSubmit, onError, }: IntentAIProviderProps): react_jsx_runtime.JSX.Element;
96
202
  /**
97
- * Hook to identify users - convenience wrapper around useIntentAI
203
+ * Hook to access Intent AI widget controls
98
204
  *
99
205
  * @example
100
206
  * ```tsx
101
- * function UserProfile({ user }) {
102
- * const identify = useIdentify();
207
+ * import { useIntentAI } from '@intentai/react';
103
208
  *
104
- * useEffect(() => {
105
- * identify({ id: user.id, email: user.email, name: user.name });
106
- * }, [user]);
209
+ * function FeedbackButton() {
210
+ * const { open, isReady } = useIntentAI();
107
211
  *
108
- * return <div>...</div>;
212
+ * return (
213
+ * <button onClick={() => open()} disabled={!isReady}>
214
+ * Give Feedback
215
+ * </button>
216
+ * );
109
217
  * }
110
218
  * ```
111
219
  */
112
- declare function useIdentify(): (user: IntentAIUser$1) => void;
220
+ declare function useIntentAI(): IntentAIContextValue;
113
221
  /**
114
- * Hook to set metadata - convenience wrapper around useIntentAI
222
+ * Hook to automatically identify a user when they're available
115
223
  *
116
224
  * @example
117
225
  * ```tsx
118
- * function Dashboard({ plan }) {
119
- * const setMetadata = useSetMetadata();
120
- *
121
- * useEffect(() => {
122
- * setMetadata({ plan, feature: 'dashboard' });
123
- * }, [plan]);
226
+ * import { useIdentify } from '@intentai/react';
124
227
  *
228
+ * function Profile({ user }) {
229
+ * useIdentify(user ? { id: user.id, email: user.email } : null);
125
230
  * return <div>...</div>;
126
231
  * }
127
232
  * ```
128
233
  */
129
- declare function useSetMetadata(): (metadata: Record<string, unknown>) => void;
234
+ declare function useIdentify(user: UserIdentity | null | undefined): void;
130
235
 
131
- interface FeedbackButtonProps {
132
- /** Button variant style */
133
- variant?: 'primary' | 'secondary' | 'ghost' | 'minimal';
134
- /** Button size */
135
- size?: 'sm' | 'md' | 'lg';
136
- /** Show icon */
137
- showIcon?: boolean;
138
- /** Custom icon (React element) */
139
- icon?: React.ReactNode;
140
- /** Button label */
141
- label?: string;
142
- /** Additional class name */
143
- className?: string;
144
- /** Custom styles */
145
- style?: React.CSSProperties;
146
- /** Primary color */
147
- primaryColor?: string;
148
- /** Click handler - if provided, will be called instead of opening widget */
149
- onClick?: () => void;
150
- /** Disabled state */
151
- disabled?: boolean;
236
+ /**
237
+ * Props for FeedbackButton component
238
+ */
239
+ interface FeedbackButtonProps extends React$1.ButtonHTMLAttributes<HTMLButtonElement> {
240
+ /** Options to pass when opening the widget */
241
+ openOptions?: OpenOptions;
242
+ /** Custom children to render */
243
+ children?: React$1.ReactNode;
152
244
  }
153
245
  /**
154
- * Customizable feedback button that can trigger the widget or custom actions
246
+ * Pre-built button component to open the feedback widget
155
247
  *
156
248
  * @example
157
249
  * ```tsx
158
- * // Basic usage - triggers widget
159
- * <FeedbackButton />
160
- *
161
- * // Custom label and style
162
- * <FeedbackButton
163
- * label="Give Feedback"
164
- * variant="secondary"
165
- * size="lg"
166
- * />
250
+ * import { FeedbackButton } from '@intentai/react';
167
251
  *
168
- * // With custom click handler
169
- * <FeedbackButton
170
- * label="Report Issue"
171
- * onClick={() => console.log('clicked')}
172
- * />
252
+ * function App() {
253
+ * return (
254
+ * <FeedbackButton className="my-custom-class">
255
+ * Send Feedback
256
+ * </FeedbackButton>
257
+ * );
258
+ * }
173
259
  * ```
174
260
  */
175
- declare function FeedbackButton({ variant, size, showIcon, icon, label, className, style, primaryColor, onClick, disabled, }: FeedbackButtonProps): React.ReactElement;
176
-
177
- interface IntentAIUser {
178
- id?: string;
179
- email?: string;
180
- name?: string;
181
- }
182
- interface IntentAIConfig {
183
- /** Your Intent AI API key (required) */
184
- apiKey: string;
185
- /** API URL for feedback submission (required for production) */
186
- apiUrl: string;
187
- /** Widget script URL (required for production) */
188
- widgetUrl: string;
189
- /** Widget position on screen */
190
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
191
- /** Widget theme */
192
- theme?: 'light' | 'dark';
193
- /** Primary color for the widget */
194
- primaryColor?: string;
195
- /** Enable/disable voice feedback */
196
- allowVoice?: boolean;
197
- /** Enable/disable text feedback */
198
- allowText?: boolean;
199
- /** Enable/disable screenshot capture */
200
- allowScreenshot?: boolean;
201
- /** Custom metadata to attach to feedback */
202
- customMetadata?: Record<string, any>;
203
- /** User information */
204
- user?: IntentAIUser;
205
- }
206
- interface IntentAIProps extends IntentAIConfig {
207
- /** Called when widget is opened */
208
- onOpen?: () => void;
209
- /** Called when widget is closed */
210
- onClose?: () => void;
211
- /** Called when feedback is submitted successfully */
212
- onFeedbackSubmitted?: () => void;
213
- /** Called when there's an error */
214
- onError?: (error: Error) => void;
215
- }
216
- interface FeedbackIQInstance {
217
- open: () => void;
218
- close: () => void;
219
- identify: (user: IntentAIUser) => void;
220
- setMetadata: (metadata: Record<string, any>) => void;
221
- destroy: () => void;
222
- }
223
- declare global {
224
- interface Window {
225
- FeedbackIQ: new (config: IntentAIConfig) => FeedbackIQInstance;
226
- }
261
+ declare const FeedbackButton: React$1.ForwardRefExoticComponent<FeedbackButtonProps & React$1.RefAttributes<HTMLButtonElement>>;
262
+ /**
263
+ * Props for FeedbackTrigger component
264
+ */
265
+ interface FeedbackTriggerProps {
266
+ /** Render function or element */
267
+ children: React$1.ReactElement | ((props: {
268
+ open: (options?: OpenOptions) => void;
269
+ isReady: boolean;
270
+ error: Error | null;
271
+ }) => React$1.ReactElement);
272
+ /** Options to pass when opening */
273
+ openOptions?: OpenOptions;
227
274
  }
228
275
  /**
229
- * Intent AI Feedback Widget for React
276
+ * Headless component for custom feedback triggers
230
277
  *
231
278
  * @example
232
279
  * ```tsx
233
- * import { IntentAIWidget } from '@intent-ai/react';
280
+ * import { FeedbackTrigger } from '@intentai/react';
234
281
  *
235
282
  * function App() {
236
283
  * return (
237
- * <IntentAIWidget
238
- * apiKey="your-api-key"
239
- * position="bottom-right"
240
- * theme="dark"
241
- * />
284
+ * <FeedbackTrigger>
285
+ * {({ open, isReady }) => (
286
+ * <MyCustomButton onClick={() => open()} disabled={!isReady}>
287
+ * Feedback
288
+ * </MyCustomButton>
289
+ * )}
290
+ * </FeedbackTrigger>
291
+ * );
292
+ * }
293
+ * ```
294
+ */
295
+ declare function FeedbackTrigger({ children, openOptions }: FeedbackTriggerProps): React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>;
296
+ /**
297
+ * Props for IdentifyUser component
298
+ */
299
+ interface IdentifyUserProps {
300
+ /** User to identify */
301
+ user: UserIdentity | null | undefined;
302
+ /** Children to render */
303
+ children?: React$1.ReactNode;
304
+ }
305
+ /**
306
+ * Component to identify a user declaratively
307
+ *
308
+ * @example
309
+ * ```tsx
310
+ * import { IdentifyUser } from '@intentai/react';
311
+ *
312
+ * function App({ user }) {
313
+ * return (
314
+ * <IdentifyUser user={user ? { id: user.id, email: user.email } : null}>
315
+ * <YourApp />
316
+ * </IdentifyUser>
242
317
  * );
243
318
  * }
244
319
  * ```
245
320
  */
246
- declare function IntentAIWidget({ apiKey, apiUrl, widgetUrl, position, theme, primaryColor, allowVoice, allowText, allowScreenshot, customMetadata, user, onOpen: _onOpen, onClose: _onClose, onFeedbackSubmitted: _onFeedbackSubmitted, onError, }: IntentAIProps): null;
321
+ declare function IdentifyUser({ user, children }: IdentifyUserProps): react_jsx_runtime.JSX.Element;
322
+ /**
323
+ * Props for SetMetadata component
324
+ */
325
+ interface SetMetadataProps {
326
+ /** Metadata to set */
327
+ metadata: Record<string, unknown>;
328
+ /** Children to render */
329
+ children?: React$1.ReactNode;
330
+ }
247
331
  /**
248
- * Hook to control the script-tag widget programmatically
249
- * @deprecated Use useIntentAI from IntentAIProvider instead for React apps
332
+ * Component to set metadata declaratively
250
333
  *
251
334
  * @example
252
335
  * ```tsx
253
- * import { IntentAIWidget, useWidgetControls } from '@intentai/react';
336
+ * import { SetMetadata } from '@intentai/react';
254
337
  *
255
- * function App() {
256
- * const { open, close, identify } = useWidgetControls();
338
+ * function PricingPage() {
339
+ * return (
340
+ * <SetMetadata metadata={{ page: 'pricing', plan: 'pro' }}>
341
+ * <PricingContent />
342
+ * </SetMetadata>
343
+ * );
344
+ * }
345
+ * ```
346
+ */
347
+ declare function SetMetadata({ metadata, children }: SetMetadataProps): react_jsx_runtime.JSX.Element;
348
+ /**
349
+ * Props for TrackEvent component
350
+ */
351
+ interface TrackEventProps {
352
+ /** Event name to track */
353
+ event: string;
354
+ /** Event properties */
355
+ properties?: Record<string, unknown>;
356
+ /** When to track: 'mount' (default) or 'render' */
357
+ trigger?: 'mount' | 'render';
358
+ /** Children to render */
359
+ children?: React$1.ReactNode;
360
+ }
361
+ /**
362
+ * Component to track events declaratively
257
363
  *
364
+ * @example
365
+ * ```tsx
366
+ * import { TrackEvent } from '@intentai/react';
367
+ *
368
+ * function CheckoutPage() {
258
369
  * return (
259
- * <>
260
- * <IntentAIWidget apiKey="your-api-key" widgetUrl="..." apiUrl="..." />
261
- * <button onClick={open}>Open Feedback</button>
262
- * </>
370
+ * <TrackEvent event="checkout_viewed" properties={{ items: 3 }}>
371
+ * <CheckoutContent />
372
+ * </TrackEvent>
263
373
  * );
264
374
  * }
265
375
  * ```
266
376
  */
267
- declare function useWidgetControls(): {
268
- open: () => void;
269
- close: () => void;
270
- identify: (user: IntentAIUser) => void;
271
- setMetadata: (metadata: Record<string, any>) => void;
272
- };
377
+ declare function TrackEvent({ event, properties, trigger, children, }: TrackEventProps): react_jsx_runtime.JSX.Element;
273
378
 
274
- export { FeedbackButton, type FeedbackButtonProps, type IntentAIConfig, type IntentAIContextValue, type IntentAIProps, IntentAIProvider, type IntentAIProviderConfig, type IntentAIProviderProps, type IntentAIUser, IntentAIWidget, PremiumVoiceWidget, type WidgetConfig as PremiumWidgetConfig, IntentAIWidget as default, useIdentify, useIntentAI, useSetMetadata, useWidgetControls };
379
+ export { FeedbackButton, type FeedbackButtonProps, type FeedbackData, FeedbackTrigger, type FeedbackTriggerProps, type FeedbackType, IdentifyUser, type IdentifyUserProps, type IntentAIConfig, type IntentAIContextValue, type IntentAIInstance, IntentAIProvider, type IntentAIProviderProps, type OpenOptions, type Sentiment, SetMetadata, type SetMetadataProps, TrackEvent, type TrackEventProps, type UserIdentity, type WidgetPosition, type WidgetTheme, useIdentify, useIntentAI };