@getuserfeedback/react 0.1.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/README.md ADDED
@@ -0,0 +1,495 @@
1
+ # @getuserfeedback/react
2
+
3
+ A secure and performant SDK for [getuserfeedback.com](https://getuserfeedback.com).
4
+
5
+ `@getuserfeedback/react` lets you easily add in-app messaging and micro-surveys optimized to help you connect with users, build trust, guide development, and avoid building in a vacuum.
6
+
7
+ > Using plain JavaScript or another framework? Check out [@getuserfeedback/sdk](https://www.npmjs.com/package/@getuserfeedback/sdk).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @getuserfeedback/react
13
+ ```
14
+
15
+ Requires `react >= 18`.
16
+
17
+ ## Get started
18
+
19
+ ### 1. Get an API key
20
+ Sign up on [getuserfeedback.com](https://getuserfeedback.com) and grab your key in Settings.
21
+
22
+ ### 2. Add the provider
23
+
24
+ ```tsx
25
+ import { GetUserFeedbackProvider } from "@getuserfeedback/react";
26
+
27
+ export function App() {
28
+ return (
29
+ <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
30
+ <AppRoutes />
31
+ </GetUserFeedbackProvider>
32
+ );
33
+ }
34
+ ```
35
+
36
+ ### 3. Start collecting responses
37
+
38
+ Pick one of our curated templates on [getuserfeedback.com/templates](https://getuserfeedback.com/templates) — from a post-signup welcome message to customer satisfaction surveys, feedback forms, and more. You can also customize everything or start from scratch.
39
+
40
+ ### 4. Get feedback — improve product — repeat
41
+ Our widgets are optimized to get you *more* responses. Polished UI, crafted copy, templates, and a million subtle tricks. Result — you get more responses, make better roadmap calls, and find product-market fit faster.
42
+
43
+ ### Bonus
44
+ Our AI-powered theme editor allows a complete overhaul of the widget look and feel with a single prompt. Demo: [getuserfeedback.com/themes](https://getuserfeedback.com/themes).
45
+
46
+ ## Advanced use cases
47
+ ### Feedback form
48
+ You can call flows imperatively, e.g., open a feedback form when the user clicks a dedicated button in your UI.
49
+
50
+ ```tsx
51
+ import { useFlow } from "@getuserfeedback/react";
52
+
53
+ const FEEDBACK_FLOW_ID = "YOUR_FLOW_ID";
54
+
55
+ export function FeedbackButton() {
56
+ const { open } = useFlow({ flowId: FEEDBACK_FLOW_ID });
57
+
58
+ return (
59
+ <button type="button" onClick={() => open()}>
60
+ Give feedback
61
+ </button>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ### Bring your own UI
67
+ By default, flows are displayed in a floating container and [themed](https://getuserfeedback.com/themes) accordingly. Beyond that, you can replace the default floating container with your own. This gives you unprecedented customization options for a seamless user experience.
68
+
69
+ For example, if you're using shadcn/ui dialogs throughout your product, our widgets can be seamlessly rendered into them and appear just like any other part of your app.
70
+
71
+ ```tsx
72
+ import { useFlowContainer } from "@getuserfeedback/react";
73
+ import { Button, Dialog, DialogContent } from "ui";
74
+
75
+ export function FeedbackDialog() {
76
+ const {
77
+ isLoading,
78
+ setOpen,
79
+ shouldRenderContainer,
80
+ containerRef,
81
+ width,
82
+ height
83
+ } = useFlowContainer({ flowId: "YOUR_FLOW_ID" });
84
+
85
+ return (
86
+ <>
87
+ <Button
88
+ type="button"
89
+ onClick={() => setOpen(true)}
90
+ disabled={isLoading}
91
+ >
92
+ Open feedback
93
+ </Button>
94
+ <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>
95
+ <DialogContent
96
+ ref={containerRef}
97
+ style={{ width, height }}
98
+ />
99
+ </Dialog>
100
+ </>
101
+ );
102
+ }
103
+ ```
104
+
105
+ ## API Overview
106
+
107
+ - `GetUserFeedbackProvider`
108
+ - `useGetUserFeedback()`
109
+ - `useFlow({ flowId, prefetchOnMount? })`
110
+ - `useFlowContainer({ flowId, prefetchOnMount? })`
111
+ - `useDefaultFlowContainer()`
112
+
113
+ ## `GetUserFeedbackProvider`
114
+
115
+ Initialize the SDK client.
116
+
117
+ ```tsx
118
+ import { GetUserFeedbackProvider } from "@getuserfeedback/react";
119
+
120
+ export function App() {
121
+ return (
122
+ <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
123
+ <AppRoutes />
124
+ </GetUserFeedbackProvider>
125
+ );
126
+ }
127
+ ```
128
+
129
+ ### Options
130
+
131
+ Pass SDK options via `clientOptions`:
132
+
133
+ - `apiKey` (`string`, required): your project API key.
134
+ - `colorScheme` (`"light" | "dark" | "system" | { autoDetectColorScheme: string[] }`, optional):
135
+ controls widget theme mode. See [Dark mode](#dark-mode).
136
+ - `disableAutoLoad` (`boolean`, optional): if `true`, call `client.load()` manually.
137
+ - `disableTelemetry` (`boolean`, optional): disables anonymous telemetry used for performance and error monitoring.
138
+
139
+ ### Delay widget load
140
+
141
+ If you want to manually control when the widget starts loading:
142
+
143
+ ```tsx
144
+ import { useEffect } from "react";
145
+ import {
146
+ GetUserFeedbackProvider,
147
+ useGetUserFeedback,
148
+ } from "@getuserfeedback/react";
149
+
150
+ function LoadWidget() {
151
+ const client = useGetUserFeedback();
152
+
153
+ useEffect(() => {
154
+ client.load();
155
+ }, [client]);
156
+
157
+ return null;
158
+ }
159
+
160
+ export function App() {
161
+ return (
162
+ <GetUserFeedbackProvider
163
+ clientOptions={{ apiKey: "YOUR_API_KEY", disableAutoLoad: true }}
164
+ >
165
+ <AppRoutes />
166
+ <LoadWidget />
167
+ </GetUserFeedbackProvider>
168
+ );
169
+ }
170
+ ```
171
+
172
+ ## Identify users
173
+
174
+ Use identity to unlock cohort targeting and attach responses to user profiles.
175
+
176
+ ### `client.identify(userId, traits?)` or `client.identify(traits)`
177
+
178
+ ```tsx
179
+ import { useEffect } from "react";
180
+ import { useGetUserFeedback } from "@getuserfeedback/react";
181
+
182
+ type User = {
183
+ id: string;
184
+ email?: string;
185
+ firstName?: string;
186
+ lastName?: string;
187
+ };
188
+
189
+ export function FeedbackIdentity({ user }: { user: User | null }) {
190
+ const client = useGetUserFeedback();
191
+
192
+ useEffect(() => {
193
+ if (!user) {
194
+ return;
195
+ }
196
+
197
+ client.identify(user.id, {
198
+ email: user.email,
199
+ firstName: user.firstName,
200
+ lastName: user.lastName,
201
+ });
202
+ }, [client, user]);
203
+
204
+ return null;
205
+ }
206
+ ```
207
+
208
+ ### `client.reset()`
209
+
210
+ Call this on logout to clear active identity state and auth (if you use auth):
211
+
212
+ ```tsx
213
+ import { useGetUserFeedback } from "@getuserfeedback/react";
214
+
215
+ export function LogoutButton() {
216
+ const client = useGetUserFeedback();
217
+
218
+ return (
219
+ <button type="button" onClick={() => client.reset()}>
220
+ Log out
221
+ </button>
222
+ );
223
+ }
224
+ ```
225
+
226
+ ## Dark mode
227
+
228
+ If you're using industry-standard ways to indicate when dark mode is *on*, the widget will pick it up and automatically keep itself in sync. If you only have light mode, the widget will stay in light mode.
229
+
230
+ Default behavior:
231
+ - The widget observes `class` and `data-theme` attributes on both `html` and `body`.
232
+ - `class="dark"` / `data-theme="dark"` enables dark mode.
233
+ - `class="light"` / `data-theme="light"` enables light mode.
234
+ - `class="system"` / `data-theme="system"` follows the user's system preference (`prefers-color-scheme`).
235
+ - If nothing is detected, it falls back to `"light"`.
236
+
237
+ You can control the behavior using the `colorScheme` option when creating a client, and you can also update it later.
238
+
239
+ ### Set a static color scheme at startup
240
+
241
+ ```tsx
242
+ import { GetUserFeedbackProvider } from "@getuserfeedback/react";
243
+
244
+ export function App() {
245
+ return (
246
+ <GetUserFeedbackProvider
247
+ clientOptions={{
248
+ apiKey: "YOUR_API_KEY",
249
+ colorScheme: "dark", // set to a static value
250
+ }}
251
+ >
252
+ <AppRoutes />
253
+ </GetUserFeedbackProvider>
254
+ );
255
+ }
256
+ ```
257
+
258
+ `colorScheme` supports:
259
+ - `{ autoDetectColorScheme: string[] }`
260
+ - `"light" | "dark" | "system"`
261
+
262
+ ### Update color scheme at runtime
263
+
264
+ ```tsx
265
+ import { useGetUserFeedback } from "@getuserfeedback/react";
266
+
267
+ export function ThemeButton() {
268
+ const client = useGetUserFeedback();
269
+
270
+ return (
271
+ <button
272
+ type="button"
273
+ onClick={() => client.configure({ colorScheme: "system" })}
274
+ >
275
+ Follow system
276
+ </button>
277
+ );
278
+ }
279
+ ```
280
+
281
+ You can also switch runtime behavior back to host-driven auto-detection:
282
+
283
+ ```tsx
284
+ import { useGetUserFeedback } from "@getuserfeedback/react";
285
+
286
+ export function ThemeAutoDetectButton() {
287
+ const client = useGetUserFeedback();
288
+
289
+ return (
290
+ <button
291
+ type="button"
292
+ onClick={() =>
293
+ client.configure({
294
+ colorScheme: {
295
+ autoDetectColorScheme: ["class", "data-theme"], // default
296
+ },
297
+ })
298
+ }
299
+ >
300
+ Use host theme
301
+ </button>
302
+ );
303
+ }
304
+ ```
305
+
306
+ ## Auth (optional)
307
+
308
+ You can run the SDK without auth. This is standard industry practice for client-side widgets like ours, so it is not enforced by default. However, we encourage you to implement auth for stricter controls.
309
+
310
+ Enable JWT validation in your workspace settings and pass a signed token from your app.
311
+
312
+ ### Clerk example: set, refresh, and clear auth token
313
+
314
+ ```tsx
315
+ import { useEffect } from "react";
316
+ import { useAuth } from "@clerk/clerk-react";
317
+ import { useGetUserFeedback } from "@getuserfeedback/react";
318
+
319
+ const AUTH_REFRESH_INTERVAL_MS = 5 * 60 * 1000;
320
+
321
+ // Mount once inside both <ClerkProvider> and <GetUserFeedbackProvider>.
322
+ export function GetUserFeedbackClerkAuth() {
323
+ const client = useGetUserFeedback();
324
+ const { isLoaded, userId, sessionId, getToken } = useAuth();
325
+
326
+ useEffect(() => {
327
+ if (!isLoaded) {
328
+ return;
329
+ }
330
+
331
+ let isDisposed = false;
332
+
333
+ const syncAuthToken = async () => {
334
+ // Signed out: clear auth token.
335
+ if (!userId) {
336
+ await client.configure({ auth: { jwt: null } });
337
+ return;
338
+ }
339
+
340
+ // Signed in: fetch/refresh Clerk JWT and pass it to the SDK.
341
+ const token = await getToken({ template: "getuserfeedback" });
342
+ if (isDisposed) {
343
+ return;
344
+ }
345
+
346
+ if (!token) {
347
+ await client.configure({ auth: { jwt: null } });
348
+ return;
349
+ }
350
+
351
+ await client.configure({ auth: { jwt: { token } } });
352
+ };
353
+
354
+ syncAuthToken();
355
+ const refreshTimer = window.setInterval(() => {
356
+ syncAuthToken();
357
+ }, AUTH_REFRESH_INTERVAL_MS);
358
+
359
+ return () => {
360
+ isDisposed = true;
361
+ window.clearInterval(refreshTimer);
362
+ };
363
+ }, [client, getToken, isLoaded, sessionId, userId]);
364
+
365
+ return null;
366
+ }
367
+ ```
368
+
369
+ ## Privacy and consent (GDPR, CCPA, etc)
370
+
371
+ Consent settings control non-essential data scopes: analytics, storage, personalization, ads.
372
+
373
+ By default, the widget starts with `granted` consent. For compliance with privacy regulations like GDPR and CCPA, you may want to choose a different default.
374
+
375
+ ### Set default consent to `pending`
376
+ ```tsx
377
+ import { GetUserFeedbackProvider } from "@getuserfeedback/react";
378
+
379
+ export function App() {
380
+ return (
381
+ <GetUserFeedbackProvider
382
+ clientOptions={{
383
+ apiKey: "YOUR_API_KEY",
384
+ defaultConsent: "pending", // set to `pending`
385
+ }}
386
+ >
387
+ <AppRoutes />
388
+ </GetUserFeedbackProvider>
389
+ );
390
+ }
391
+ ```
392
+ With `pending` consent set by default, all non-essential data scopes are considered effectively denied.
393
+
394
+ ### Update consent at runtime
395
+
396
+ ```tsx
397
+ import { useGetUserFeedback } from "@getuserfeedback/react";
398
+
399
+ export function ConsentGrantedButton() {
400
+ const client = useGetUserFeedback();
401
+
402
+ return (
403
+ <button
404
+ type="button"
405
+ onClick={() => client.configure({ consent: "granted" })}
406
+ >
407
+ Grant consent
408
+ </button>
409
+ );
410
+ }
411
+ ```
412
+
413
+ You can also pass explicit granted scopes instead:
414
+
415
+ ```tsx
416
+ import { useGetUserFeedback } from "@getuserfeedback/react";
417
+
418
+ export function ConsentScopesButton() {
419
+ const client = useGetUserFeedback();
420
+
421
+ return (
422
+ <button
423
+ type="button"
424
+ onClick={() =>
425
+ client.configure({
426
+ consent: ["analytics.measurement", "analytics.storage"],
427
+ })
428
+ }
429
+ >
430
+ Grant analytics scopes
431
+ </button>
432
+ );
433
+ }
434
+
435
+ ```
436
+ `defaultConsent` supports:
437
+ - `"pending" | "granted" (default) | "denied" | "revoked"`
438
+ - or a granted-scope list like `["analytics.measurement", "analytics.storage"]`
439
+
440
+ ### Impact of different consent settings
441
+
442
+ - Response collection: never affected.
443
+ - Imperative flow display: never affected.
444
+ - Cohort targeting: rules that depend on persisted activity, identity continuity, or storage-backed signals require both `analytics.measurement` and `analytics.storage`.
445
+ - Context targeting: rules based on current-page context (URL, referrer, timing, host signals) require `analytics.measurement` only.
446
+
447
+ ## Advanced — control flows imperatively
448
+
449
+ ### Open a flow
450
+
451
+ ```tsx
452
+ import { useFlow } from "@getuserfeedback/react";
453
+
454
+ export function OpenFlowButton() {
455
+ const { open } = useFlow({ flowId: "YOUR_FLOW_ID" });
456
+
457
+ return (
458
+ <button type="button" onClick={() => open()}>
459
+ Open flow
460
+ </button>
461
+ );
462
+ }
463
+ ```
464
+
465
+ ### Prefetch and prerender
466
+
467
+ Prefetching loads flow resources over the network, prerendering warms up the UI.
468
+
469
+ ```tsx
470
+ import { useFlow } from "@getuserfeedback/react";
471
+
472
+ export function FeedbackButton() {
473
+ const { prerender, open } = useFlow({
474
+ flowId: "YOUR_FLOW_ID",
475
+ prefetchOnMount: true,
476
+ });
477
+
478
+ return (
479
+ <button
480
+ type="button"
481
+ onMouseEnter={() => prerender()}
482
+ onFocus={() => prerender()}
483
+ onClick={() => open()}
484
+ >
485
+ Give feedback
486
+ </button>
487
+ );
488
+ }
489
+ ```
490
+
491
+ ## Links
492
+
493
+ - Docs: [getuserfeedback.com/docs](https://getuserfeedback.com/docs)
494
+ - Package versions (release history): [npm versions for `@getuserfeedback/react`](https://www.npmjs.com/package/@getuserfeedback/react?activeTab=versions)
495
+ - Report issues / support: [hello@getuserfeedback.com](mailto:hello@getuserfeedback.com)
@@ -0,0 +1,216 @@
1
+ import { ClientOptions, Client } from '@getuserfeedback/sdk';
2
+ import { ReactNode, ReactElement } from 'react';
3
+
4
+ /**
5
+ * Options for useFlow().
6
+ */
7
+ interface UseFlowOptions {
8
+ /** The flow/survey ID to control. */
9
+ flowId: string;
10
+ /** Prefetch the flow resources on mount so it opens faster. Default `false`. */
11
+ prefetchOnMount?: boolean;
12
+ }
13
+ /**
14
+ * Return value for useFlow(): state and callbacks to show the default floating flow.
15
+ */
16
+ interface UseFlowReturn {
17
+ /** True when the flow is visible. */
18
+ isOpen: boolean;
19
+ /** True when the flow is loading. */
20
+ isLoading: boolean;
21
+ /** Open the flow. */
22
+ open: () => Promise<void>;
23
+ /** Close the flow. */
24
+ close: () => Promise<void>;
25
+ /** Prerendering warms up the flow for instant display later. */
26
+ prerender: () => Promise<void>;
27
+ /** Flow width in pixels (when known). */
28
+ width?: number;
29
+ /** Flow height in pixels (when known). */
30
+ height?: number;
31
+ }
32
+ /**
33
+ * Return value for useFlowContainer(): state and callbacks for host-managed container flows.
34
+ */
35
+ interface UseFlowContainerReturn {
36
+ /** True when the flow is visible. */
37
+ isOpen: boolean;
38
+ /** True when the flow is loading. */
39
+ isLoading: boolean;
40
+ /** True when your host UI should render the custom container element. */
41
+ shouldRenderContainer: boolean;
42
+ /** Open the flow when `true`, close when `false`. */
43
+ setOpen: (next: boolean) => Promise<void>;
44
+ /** Prerendering warms up the flow for instant display later. */
45
+ prerender: () => Promise<void>;
46
+ /** Ref callback: attach this to the container element where the flow should render. */
47
+ containerRef: (element: HTMLDivElement | null) => void;
48
+ /** Flow width in pixels (when known). */
49
+ width?: number;
50
+ /** Flow height in pixels (when known). */
51
+ height?: number;
52
+ }
53
+ /**
54
+ * Return value for useDefaultFlowContainer(): container ref and aggregate flow state
55
+ * for all flows in the same provider subtree (including targeting-engine opens).
56
+ */
57
+ interface UseDefaultFlowContainerReturn {
58
+ /** True when any flow is visible. */
59
+ isOpen: boolean;
60
+ /** True when any flow is loading. */
61
+ isLoading: boolean;
62
+ /** True when your host UI should render the default flow container. */
63
+ shouldRenderContainer: boolean;
64
+ /** Active flow width in pixels (when known). */
65
+ width?: number;
66
+ /** Active flow height in pixels (when known). */
67
+ height?: number;
68
+ /** Close currently displayed flows when `false`; opening is flow-driven. */
69
+ setOpen: (next: boolean) => Promise<void>;
70
+ /** Ref callback for the default flow container element. */
71
+ containerRef: (element: HTMLDivElement | null) => void;
72
+ }
73
+ interface GetUserFeedbackProviderProps {
74
+ /** Application subtree that can use getuserfeedback hooks. */
75
+ children: ReactNode;
76
+ /** Core SDK client options used to create/reuse the underlying client. */
77
+ clientOptions: ClientOptions;
78
+ }
79
+ /**
80
+ * Provider for getuserfeedback React hooks.
81
+ * Wrap your app (or a subtree) so `useFlow`, `useFlowContainer`,
82
+ * `useDefaultFlowContainer`, and `useGetUserFeedback` can access a client
83
+ * created from `clientOptions`.
84
+ *
85
+ * If your app uses `useDefaultFlowContainer()`, all flows in this subtree
86
+ * (including targeting-engine opens) target that container.
87
+ * If the container ref is not mounted yet, loader keeps flows parked until it is.
88
+ *
89
+ * @example Basic usage
90
+ * ```tsx
91
+ * function App() {
92
+ * return (
93
+ * <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
94
+ * <Routes />
95
+ * </GetUserFeedbackProvider>
96
+ * );
97
+ * }
98
+ * ```
99
+ *
100
+ * @example Display *any* flow in your own dialog (a shadcn/ui dialog in this example):
101
+ * ```tsx
102
+ * function DefaultFlowContainer() {
103
+ * const { containerRef, shouldRenderContainer, width, height, setOpen } = useDefaultFlowContainer();
104
+ *
105
+ * return (
106
+ * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>
107
+ * <DialogContent ref={containerRef} style={{ width, height }} />
108
+ * </Dialog>
109
+ * );
110
+ * }
111
+ *
112
+ * function App() {
113
+ * return (
114
+ * <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
115
+ * <AppRoutes />
116
+ * <DefaultFlowContainer /> // Flows will be triggered by the targeting engine and displayed in your own dialog
117
+ * </GetUserFeedbackProvider>
118
+ * );
119
+ * }
120
+ * ```
121
+ */
122
+ declare function GetUserFeedbackProvider({ children, clientOptions, }: GetUserFeedbackProviderProps): ReactElement;
123
+ /**
124
+ * @name useFlow
125
+ * @description Imperatively display a flow.
126
+ * @example Basic usage
127
+ * ```tsx
128
+ * function FeedbackButton() {
129
+ * const { open, isLoading } = useFlow({ flowId: "sur_123" });
130
+ * return <Button onClick={() => open()} disabled={isLoading}>Feedback</Button>;
131
+ * }
132
+ * ```
133
+ */
134
+ declare function useFlow(flow: UseFlowOptions): UseFlowReturn;
135
+ /**
136
+ * @name useFlowContainer
137
+ * @description Imperatively display a flow in your own container element.
138
+ * @example In a custom dialog
139
+ * ```tsx
140
+ * function FlowContainerDialog() {
141
+ * const { containerRef, shouldRenderContainer, width, height, setOpen, isLoading } =
142
+ * useFlowContainer({ flowId: "sur_123" });
143
+ *
144
+ * return (
145
+ * <>
146
+ * <Button onClick={() => setOpen(true)} loading={isLoading}>
147
+ * Feedback
148
+ * </Button>
149
+ * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>
150
+ * <DialogContent ref={containerRef} style={{ width, height }} />
151
+ * </Dialog>
152
+ * </>
153
+ * );
154
+ * }
155
+ *
156
+ * function App() {
157
+ * return (
158
+ * <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
159
+ * <FlowContainerDialog />
160
+ * </GetUserFeedbackProvider>
161
+ * );
162
+ * }
163
+ * ```
164
+ */
165
+ declare function useFlowContainer(flow: UseFlowOptions): UseFlowContainerReturn;
166
+ /**
167
+ * @name useDefaultFlowContainer
168
+ * @description Register and control a default flow container for all flows in this provider subtree.
169
+ * @example Display any flow in your own dialog
170
+ * ```tsx
171
+ * function DefaultFlowContainer() {
172
+ * const { containerRef, shouldRenderContainer, width, height, setOpen } = useDefaultFlowContainer();
173
+ * return (
174
+ * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>
175
+ * <DialogContent ref={containerRef} style={{ width, height }} />
176
+ * </Dialog>
177
+ * );
178
+ * }
179
+ *
180
+ * function App() {
181
+ * return (
182
+ * <GetUserFeedbackProvider clientOptions={{ apiKey: "YOUR_API_KEY" }}>
183
+ * <AppRoutes />
184
+ * <DefaultFlowContainer />
185
+ * </GetUserFeedbackProvider>
186
+ * );
187
+ * }
188
+ * ```
189
+ */
190
+ declare function useDefaultFlowContainer(): UseDefaultFlowContainerReturn;
191
+ /**
192
+ * Hook for accessing the getuserfeedback client instance.
193
+ *
194
+ * @example Basic usage
195
+ * ```tsx
196
+ * const client = useGetUserFeedback();
197
+ *
198
+ * // on login
199
+ * client.identify('user-123', { email: 'user@example.com' });
200
+ *
201
+ * // on logout
202
+ * client.reset();
203
+ * ```
204
+ *
205
+ * @example Override color scheme
206
+ * ```tsx
207
+ * const client = useGetUserFeedback();
208
+ * await client.configure({ colorScheme: "dark" });
209
+ * ```
210
+ */
211
+ declare function useGetUserFeedback(): Client;
212
+
213
+ declare const REACT_SDK_VERSION: string;
214
+
215
+ export { GetUserFeedbackProvider, REACT_SDK_VERSION, useDefaultFlowContainer, useFlow, useFlowContainer, useGetUserFeedback };
216
+ export type { GetUserFeedbackProviderProps, UseDefaultFlowContainerReturn, UseFlowContainerReturn, UseFlowOptions, UseFlowReturn };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ import{createClient as M}from"@getuserfeedback/sdk";import{createContext as Q,useCallback as _,useContext as q,useEffect as O,useMemo as h,useRef as y,useState as z}from"react";import{jsx as r}from"react/jsx-runtime";var W={isOpen:!1,isLoading:!1,shouldRenderContainer:!1,width:void 0,height:void 0},T=Q(null);function X({children:G,clientOptions:U}){let p=M(U),A=y(null),P=y(0),[R,v]=z(()=>({...p.getFlowState()})),b=_((E)=>{if(A.current=E,P.current===0)return;p.setDefaultContainerPolicy({kind:"hostContainer",host:E,sharing:"perFlowRun"})},[p]),F=_(()=>{if(P.current+=1,P.current===1)p.setDefaultContainerPolicy({kind:"hostContainer",host:A.current,sharing:"perFlowRun"});return()=>{if(P.current=Math.max(0,P.current-1),P.current===0)p.setDefaultContainerPolicy({kind:"floating"})}},[p]);O(()=>p.subscribeFlowState((E)=>{v({isOpen:E.isOpen,isLoading:E.isLoading,width:E.width,height:E.height})},{emitInitial:!0}),[p]);let K=h(()=>{if(!R.isOpen&&!R.isLoading)return W;return{isOpen:R.isOpen,isLoading:R.isLoading,shouldRenderContainer:!0,width:R.width,height:R.height}},[R]),N=h(()=>({client:p,apiKey:U.apiKey,setDefaultFlowContainer:b,registerDefaultFlowContainerConsumer:F,defaultFlowContainerState:K}),[p,U.apiKey,K,F,b]);return r(T.Provider,{value:N,children:G})}var B=(G)=>{let U=q(T);if(!U)throw Error("useFlow must be used within a GetUserFeedbackProvider");let{client:p}=U,{flowId:A,prefetchOnMount:P=!1}=G.flow,R=h(()=>p.flow(A),[p,A]),v=G.mode==="container",[b,F]=z(()=>R.getFlowState()),K=_(()=>{return R.open(v?{containerRequirement:"hostOnly"}:void 0)},[R,v]),N=_(()=>R.close(),[R]),E=_((I)=>I?K():N(),[N,K]),J=_((I)=>{if(!v)return;R.setContainer(I)},[R,v]),L=v&&(b.isLoading||b.isOpen);return O(()=>R.subscribeFlowState((I)=>F({isOpen:I.isOpen,isLoading:I.isLoading,width:I.width,height:I.height}),{emitInitial:!1}),[R]),O(()=>{if(!P)return;R.prefetch()},[R,P]),{isOpen:b.isOpen,isLoading:b.isLoading,width:b.width,height:b.height,shouldRenderContainer:L,setOpen:E,open:K,close:N,prerender:()=>R.prerender(),containerRef:J}};function Y(G){let U=B({flow:G,mode:"default"});return{isOpen:U.isOpen,isLoading:U.isLoading,width:U.width,height:U.height,open:U.open,close:U.close,prerender:U.prerender}}function Z(G){let U=B({flow:G,mode:"container"});return{isOpen:U.isOpen,isLoading:U.isLoading,width:U.width,height:U.height,shouldRenderContainer:U.shouldRenderContainer,setOpen:U.setOpen,prerender:U.prerender,containerRef:U.containerRef}}function $(){let G=q(T);if(!G)throw Error("useDefaultFlowContainer must be used within a GetUserFeedbackProvider");let{client:U,defaultFlowContainerState:p,registerDefaultFlowContainerConsumer:A,setDefaultFlowContainer:P}=G;O(()=>A(),[A]);let R=_((F)=>{P(F)},[P]),v=_(()=>U.close(),[U]),b=_((F)=>{if(F)return Promise.resolve();return v()},[v]);return{isOpen:p.isOpen,isLoading:p.isLoading,shouldRenderContainer:p.shouldRenderContainer,width:p.width,height:p.height,setOpen:b,containerRef:R}}function j(){let G=q(T);if(!G)throw Error("useGetUserFeedback must be used within a GetUserFeedbackProvider");return G.client}var H="0.1.0".trim(),D=H.length>0?H:"0.0.0-local";export{j as useGetUserFeedback,Z as useFlowContainer,Y as useFlow,$ as useDefaultFlowContainer,D as REACT_SDK_VERSION,X as GetUserFeedbackProvider};
3
+
4
+ //# debugId=F70E7BF3F345A4F164756E2164756E21
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/client.tsx", "../src/version.ts"],
4
+ "sourcesContent": [
5
+ "\"use client\";\n\nimport {\n\ttype Client,\n\ttype ClientOptions,\n\tcreateClient,\n\ttype FlowState,\n} from \"@getuserfeedback/sdk\";\nimport type { ReactElement, ReactNode } from \"react\";\nimport {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\n\n/**\n * Options for useFlow().\n */\nexport interface UseFlowOptions {\n\t/** The flow/survey ID to control. */\n\tflowId: string;\n\t/** Prefetch the flow resources on mount so it opens faster. Default `false`. */\n\tprefetchOnMount?: boolean;\n}\n\n/**\n * Return value for useFlow(): state and callbacks to show the default floating flow.\n */\nexport interface UseFlowReturn {\n\t/** True when the flow is visible. */\n\tisOpen: boolean;\n\t/** True when the flow is loading. */\n\tisLoading: boolean;\n\t/** Open the flow. */\n\topen: () => Promise<void>;\n\t/** Close the flow. */\n\tclose: () => Promise<void>;\n\t/** Prerendering warms up the flow for instant display later. */\n\tprerender: () => Promise<void>;\n\t/** Flow width in pixels (when known). */\n\twidth?: number;\n\t/** Flow height in pixels (when known). */\n\theight?: number;\n}\n\n/**\n * Return value for useFlowContainer(): state and callbacks for host-managed container flows.\n */\nexport interface UseFlowContainerReturn {\n\t/** True when the flow is visible. */\n\tisOpen: boolean;\n\t/** True when the flow is loading. */\n\tisLoading: boolean;\n\t/** True when your host UI should render the custom container element. */\n\tshouldRenderContainer: boolean;\n\t/** Open the flow when `true`, close when `false`. */\n\tsetOpen: (next: boolean) => Promise<void>;\n\t/** Prerendering warms up the flow for instant display later. */\n\tprerender: () => Promise<void>;\n\t/** Ref callback: attach this to the container element where the flow should render. */\n\tcontainerRef: (element: HTMLDivElement | null) => void;\n\t/** Flow width in pixels (when known). */\n\twidth?: number;\n\t/** Flow height in pixels (when known). */\n\theight?: number;\n}\n\n/**\n * Return value for useDefaultFlowContainer(): container ref and aggregate flow state\n * for all flows in the same provider subtree (including targeting-engine opens).\n */\nexport interface UseDefaultFlowContainerReturn {\n\t/** True when any flow is visible. */\n\tisOpen: boolean;\n\t/** True when any flow is loading. */\n\tisLoading: boolean;\n\t/** True when your host UI should render the default flow container. */\n\tshouldRenderContainer: boolean;\n\t/** Active flow width in pixels (when known). */\n\twidth?: number;\n\t/** Active flow height in pixels (when known). */\n\theight?: number;\n\t/** Close currently displayed flows when `false`; opening is flow-driven. */\n\tsetOpen: (next: boolean) => Promise<void>;\n\t/** Ref callback for the default flow container element. */\n\tcontainerRef: (element: HTMLDivElement | null) => void;\n}\n\ntype InstanceFlowRenderState = {\n\tisOpen: boolean;\n\tisLoading: boolean;\n\twidth?: number;\n\theight?: number;\n};\n\ntype DefaultFlowContainerState = {\n\tisOpen: boolean;\n\tisLoading: boolean;\n\tshouldRenderContainer: boolean;\n\twidth?: number;\n\theight?: number;\n};\n\nconst DEFAULT_FLOW_CONTAINER_STATE: DefaultFlowContainerState = {\n\tisOpen: false,\n\tisLoading: false,\n\tshouldRenderContainer: false,\n\twidth: undefined,\n\theight: undefined,\n};\n\ntype GetUserFeedbackContextValue = {\n\tclient: Client;\n\tapiKey: string;\n\tsetDefaultFlowContainer: (element: HTMLElement | null) => void;\n\tregisterDefaultFlowContainerConsumer: () => () => void;\n\tdefaultFlowContainerState: DefaultFlowContainerState;\n};\n\nconst GetUserFeedbackContext =\n\tcreateContext<GetUserFeedbackContextValue | null>(null);\n\nexport interface GetUserFeedbackProviderProps {\n\t/** Application subtree that can use getuserfeedback hooks. */\n\tchildren: ReactNode;\n\t/** Core SDK client options used to create/reuse the underlying client. */\n\tclientOptions: ClientOptions;\n}\n\n/**\n * Provider for getuserfeedback React hooks.\n * Wrap your app (or a subtree) so `useFlow`, `useFlowContainer`,\n * `useDefaultFlowContainer`, and `useGetUserFeedback` can access a client\n * created from `clientOptions`.\n *\n * If your app uses `useDefaultFlowContainer()`, all flows in this subtree\n * (including targeting-engine opens) target that container.\n * If the container ref is not mounted yet, loader keeps flows parked until it is.\n *\n * @example Basic usage\n * ```tsx\n * function App() {\n * return (\n * <GetUserFeedbackProvider clientOptions={{ apiKey: \"YOUR_API_KEY\" }}>\n * <Routes />\n * </GetUserFeedbackProvider>\n * );\n * }\n * ```\n *\n * @example Display *any* flow in your own dialog (a shadcn/ui dialog in this example):\n * ```tsx\n * function DefaultFlowContainer() {\n * const { containerRef, shouldRenderContainer, width, height, setOpen } = useDefaultFlowContainer();\n *\n * return (\n * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>\n * <DialogContent ref={containerRef} style={{ width, height }} />\n * </Dialog>\n * );\n * }\n *\n * function App() {\n * return (\n * <GetUserFeedbackProvider clientOptions={{ apiKey: \"YOUR_API_KEY\" }}>\n * <AppRoutes />\n * <DefaultFlowContainer /> // Flows will be triggered by the targeting engine and displayed in your own dialog\n * </GetUserFeedbackProvider>\n * );\n * }\n * ```\n */\nexport function GetUserFeedbackProvider({\n\tchildren,\n\tclientOptions,\n}: GetUserFeedbackProviderProps): ReactElement {\n\tconst client = createClient(clientOptions);\n\tconst defaultFlowContainerRef = useRef<HTMLElement | null>(null);\n\tconst defaultFlowContainerConsumerCountRef = useRef(0);\n\tconst [instanceFlowState, setInstanceFlowState] =\n\t\tuseState<InstanceFlowRenderState>(() => ({\n\t\t\t...client.getFlowState(),\n\t\t}));\n\n\tconst setDefaultFlowContainer = useCallback(\n\t\t(element: HTMLElement | null) => {\n\t\t\tdefaultFlowContainerRef.current = element;\n\t\t\tif (defaultFlowContainerConsumerCountRef.current === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tclient.setDefaultContainerPolicy({\n\t\t\t\tkind: \"hostContainer\",\n\t\t\t\thost: element,\n\t\t\t\tsharing: \"perFlowRun\",\n\t\t\t});\n\t\t},\n\t\t[client],\n\t);\n\n\tconst registerDefaultFlowContainerConsumer = useCallback(() => {\n\t\tdefaultFlowContainerConsumerCountRef.current += 1;\n\t\tif (defaultFlowContainerConsumerCountRef.current === 1) {\n\t\t\tclient.setDefaultContainerPolicy({\n\t\t\t\tkind: \"hostContainer\",\n\t\t\t\thost: defaultFlowContainerRef.current,\n\t\t\t\tsharing: \"perFlowRun\",\n\t\t\t});\n\t\t}\n\t\treturn () => {\n\t\t\tdefaultFlowContainerConsumerCountRef.current = Math.max(\n\t\t\t\t0,\n\t\t\t\tdefaultFlowContainerConsumerCountRef.current - 1,\n\t\t\t);\n\t\t\tif (defaultFlowContainerConsumerCountRef.current === 0) {\n\t\t\t\tclient.setDefaultContainerPolicy({ kind: \"floating\" });\n\t\t\t}\n\t\t};\n\t}, [client]);\n\n\tuseEffect(\n\t\t() =>\n\t\t\tclient.subscribeFlowState(\n\t\t\t\t(state) => {\n\t\t\t\t\tsetInstanceFlowState({\n\t\t\t\t\t\tisOpen: state.isOpen,\n\t\t\t\t\t\tisLoading: state.isLoading,\n\t\t\t\t\t\twidth: state.width,\n\t\t\t\t\t\theight: state.height,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\temitInitial: true,\n\t\t\t\t},\n\t\t\t),\n\t\t[client],\n\t);\n\n\tconst defaultFlowContainerState = useMemo<DefaultFlowContainerState>(() => {\n\t\tif (!instanceFlowState.isOpen && !instanceFlowState.isLoading) {\n\t\t\treturn DEFAULT_FLOW_CONTAINER_STATE;\n\t\t}\n\t\treturn {\n\t\t\tisOpen: instanceFlowState.isOpen,\n\t\t\tisLoading: instanceFlowState.isLoading,\n\t\t\tshouldRenderContainer: true,\n\t\t\twidth: instanceFlowState.width,\n\t\t\theight: instanceFlowState.height,\n\t\t};\n\t}, [instanceFlowState]);\n\n\tconst contextValue = useMemo(\n\t\t() => ({\n\t\t\tclient,\n\t\t\tapiKey: clientOptions.apiKey,\n\t\t\tsetDefaultFlowContainer,\n\t\t\tregisterDefaultFlowContainerConsumer,\n\t\t\tdefaultFlowContainerState,\n\t\t}),\n\t\t[\n\t\t\tclient,\n\t\t\tclientOptions.apiKey,\n\t\t\tdefaultFlowContainerState,\n\t\t\tregisterDefaultFlowContainerConsumer,\n\t\t\tsetDefaultFlowContainer,\n\t\t],\n\t);\n\n\treturn (\n\t\t<GetUserFeedbackContext.Provider value={contextValue}>\n\t\t\t{children}\n\t\t</GetUserFeedbackContext.Provider>\n\t);\n}\n\ntype UseFlowControllerOptions = {\n\tflow: UseFlowOptions;\n\tmode: \"default\" | \"container\";\n};\n\ntype UseFlowControllerReturn = {\n\tisOpen: boolean;\n\tisLoading: boolean;\n\twidth?: number;\n\theight?: number;\n\tshouldRenderContainer: boolean;\n\tsetOpen: (next: boolean) => Promise<void>;\n\topen: () => Promise<void>;\n\tclose: () => Promise<void>;\n\tprerender: () => Promise<void>;\n\tcontainerRef: (element: HTMLDivElement | null) => void;\n};\n\nconst useFlowController = (\n\toptions: UseFlowControllerOptions,\n): UseFlowControllerReturn => {\n\tconst ctx = useContext(GetUserFeedbackContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useFlow must be used within a GetUserFeedbackProvider\");\n\t}\n\tconst { client } = ctx;\n\tconst { flowId, prefetchOnMount = false } = options.flow;\n\tconst flowRun = useMemo(() => client.flow(flowId), [client, flowId]);\n\tconst requiresContainer = options.mode === \"container\";\n\n\t/** Flow state from loader events; open/loading + dimensions. */\n\tconst [flowState, setFlowState] = useState<FlowState>(() =>\n\t\tflowRun.getFlowState(),\n\t);\n\n\tconst open = useCallback((): Promise<void> => {\n\t\treturn flowRun.open(\n\t\t\trequiresContainer ? { containerRequirement: \"hostOnly\" } : undefined,\n\t\t);\n\t}, [flowRun, requiresContainer]);\n\n\tconst close = useCallback((): Promise<void> => flowRun.close(), [flowRun]);\n\n\tconst setOpen = useCallback(\n\t\t(next: boolean): Promise<void> => (next ? open() : close()),\n\t\t[close, open],\n\t);\n\n\tconst containerRef = useCallback(\n\t\t(element: HTMLDivElement | null): void => {\n\t\t\tif (!requiresContainer) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tflowRun.setContainer(element);\n\t\t},\n\t\t[flowRun, requiresContainer],\n\t);\n\n\tconst shouldRenderContainer =\n\t\trequiresContainer && (flowState.isLoading || flowState.isOpen);\n\n\tuseEffect(\n\t\t() =>\n\t\t\tflowRun.subscribeFlowState(\n\t\t\t\t(state) =>\n\t\t\t\t\tsetFlowState({\n\t\t\t\t\t\tisOpen: state.isOpen,\n\t\t\t\t\t\tisLoading: state.isLoading,\n\t\t\t\t\t\twidth: state.width,\n\t\t\t\t\t\theight: state.height,\n\t\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\temitInitial: false,\n\t\t\t\t},\n\t\t\t),\n\t\t[flowRun],\n\t);\n\n\tuseEffect(() => {\n\t\tif (!prefetchOnMount) {\n\t\t\treturn;\n\t\t}\n\t\tflowRun.prefetch();\n\t}, [flowRun, prefetchOnMount]);\n\n\treturn {\n\t\tisOpen: flowState.isOpen,\n\t\tisLoading: flowState.isLoading,\n\t\twidth: flowState.width,\n\t\theight: flowState.height,\n\t\tshouldRenderContainer,\n\t\tsetOpen,\n\t\topen,\n\t\tclose,\n\t\tprerender: () => flowRun.prerender(),\n\t\tcontainerRef,\n\t};\n};\n\n/**\n * @name useFlow\n * @description Imperatively display a flow.\n * @example Basic usage\n * ```tsx\n * function FeedbackButton() {\n * const { open, isLoading } = useFlow({ flowId: \"sur_123\" });\n * return <Button onClick={() => open()} disabled={isLoading}>Feedback</Button>;\n * }\n * ```\n */\nexport function useFlow(flow: UseFlowOptions): UseFlowReturn {\n\tconst controller = useFlowController({ flow, mode: \"default\" });\n\treturn {\n\t\tisOpen: controller.isOpen,\n\t\tisLoading: controller.isLoading,\n\t\twidth: controller.width,\n\t\theight: controller.height,\n\t\topen: controller.open,\n\t\tclose: controller.close,\n\t\tprerender: controller.prerender,\n\t};\n}\n\n/**\n * @name useFlowContainer\n * @description Imperatively display a flow in your own container element.\n * @example In a custom dialog\n * ```tsx\n * function FlowContainerDialog() {\n * const { containerRef, shouldRenderContainer, width, height, setOpen, isLoading } =\n * useFlowContainer({ flowId: \"sur_123\" });\n *\n * return (\n * <>\n * <Button onClick={() => setOpen(true)} loading={isLoading}>\n * Feedback\n * </Button>\n * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>\n * <DialogContent ref={containerRef} style={{ width, height }} />\n * </Dialog>\n * </>\n * );\n * }\n *\n * function App() {\n * return (\n * <GetUserFeedbackProvider clientOptions={{ apiKey: \"YOUR_API_KEY\" }}>\n * <FlowContainerDialog />\n * </GetUserFeedbackProvider>\n * );\n * }\n * ```\n */\nexport function useFlowContainer(flow: UseFlowOptions): UseFlowContainerReturn {\n\tconst controller = useFlowController({ flow, mode: \"container\" });\n\treturn {\n\t\tisOpen: controller.isOpen,\n\t\tisLoading: controller.isLoading,\n\t\twidth: controller.width,\n\t\theight: controller.height,\n\t\tshouldRenderContainer: controller.shouldRenderContainer,\n\t\tsetOpen: controller.setOpen,\n\t\tprerender: controller.prerender,\n\t\tcontainerRef: controller.containerRef,\n\t};\n}\n\n/**\n * @name useDefaultFlowContainer\n * @description Register and control a default flow container for all flows in this provider subtree.\n * @example Display any flow in your own dialog\n * ```tsx\n * function DefaultFlowContainer() {\n * const { containerRef, shouldRenderContainer, width, height, setOpen } = useDefaultFlowContainer();\n * return (\n * <Dialog open={shouldRenderContainer} onOpenChange={setOpen}>\n * <DialogContent ref={containerRef} style={{ width, height }} />\n * </Dialog>\n * );\n * }\n *\n * function App() {\n * return (\n * <GetUserFeedbackProvider clientOptions={{ apiKey: \"YOUR_API_KEY\" }}>\n * <AppRoutes />\n * <DefaultFlowContainer />\n * </GetUserFeedbackProvider>\n * );\n * }\n * ```\n */\nexport function useDefaultFlowContainer(): UseDefaultFlowContainerReturn {\n\tconst ctx = useContext(GetUserFeedbackContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t\"useDefaultFlowContainer must be used within a GetUserFeedbackProvider\",\n\t\t);\n\t}\n\n\tconst {\n\t\tclient,\n\t\tdefaultFlowContainerState,\n\t\tregisterDefaultFlowContainerConsumer,\n\t\tsetDefaultFlowContainer,\n\t} = ctx;\n\n\tuseEffect(\n\t\t() => registerDefaultFlowContainerConsumer(),\n\t\t[registerDefaultFlowContainerConsumer],\n\t);\n\n\tconst containerRef = useCallback(\n\t\t(element: HTMLDivElement | null): void => {\n\t\t\tsetDefaultFlowContainer(element);\n\t\t},\n\t\t[setDefaultFlowContainer],\n\t);\n\n\tconst close = useCallback((): Promise<void> => client.close(), [client]);\n\n\tconst setOpen = useCallback(\n\t\t(next: boolean): Promise<void> => {\n\t\t\tif (next) {\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\treturn close();\n\t\t},\n\t\t[close],\n\t);\n\n\treturn {\n\t\tisOpen: defaultFlowContainerState.isOpen,\n\t\tisLoading: defaultFlowContainerState.isLoading,\n\t\tshouldRenderContainer: defaultFlowContainerState.shouldRenderContainer,\n\t\twidth: defaultFlowContainerState.width,\n\t\theight: defaultFlowContainerState.height,\n\t\tsetOpen,\n\t\tcontainerRef,\n\t};\n}\n\n/**\n * Hook for accessing the getuserfeedback client instance.\n *\n * @example Basic usage\n * ```tsx\n * const client = useGetUserFeedback();\n *\n * // on login\n * client.identify('user-123', { email: 'user@example.com' });\n *\n * // on logout\n * client.reset();\n * ```\n *\n * @example Override color scheme\n * ```tsx\n * const client = useGetUserFeedback();\n * await client.configure({ colorScheme: \"dark\" });\n * ```\n */\nexport function useGetUserFeedback(): Client {\n\tconst ctx = useContext(GetUserFeedbackContext);\n\tif (!ctx) {\n\t\tthrow new Error(\n\t\t\t\"useGetUserFeedback must be used within a GetUserFeedbackProvider\",\n\t\t);\n\t}\n\treturn ctx.client;\n}\n",
6
+ "declare const __GX_REACT_SDK_VERSION__: string | undefined;\n\nconst reactSdkVersion =\n\ttypeof __GX_REACT_SDK_VERSION__ === \"string\"\n\t\t? __GX_REACT_SDK_VERSION__.trim()\n\t\t: \"\";\n\n// Build scripts inject __GX_REACT_SDK_VERSION__ for published artifacts.\n// Source-linked workspace usage may not inject defines, so keep a safe fallback.\nexport const REACT_SDK_VERSION =\n\treactSdkVersion.length > 0 ? reactSdkVersion : \"0.0.0-local\";\n"
7
+ ],
8
+ "mappings": "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",
9
+ "debugId": "F70E7BF3F345A4F164756E2164756E21",
10
+ "names": []
11
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@getuserfeedback/react",
3
+ "version": "0.1.0",
4
+ "description": "getuserfeedback React SDK",
5
+ "keywords": [
6
+ "getuserfeedback",
7
+ "feedback",
8
+ "widget",
9
+ "react"
10
+ ],
11
+ "license": "MIT",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "prepack": "node scripts/prepack.cjs",
29
+ "postpack": "node scripts/postpack.cjs",
30
+ "build": "bun x rimraf dist tsconfig.tsbuildinfo && bun run scripts/build.ts && bun x rollup -c rollup.dts.config.mjs",
31
+ "typecheck": "tsc -b tsconfig.json",
32
+ "test": "bun test"
33
+ },
34
+ "dependencies": {
35
+ "@getuserfeedback/sdk": "^0.1.0"
36
+ },
37
+ "peerDependencies": {
38
+ "react": ">=18.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "rimraf": "^6.0.0",
42
+ "rollup": "^4.57.1",
43
+ "rollup-plugin-dts": "^6.3.0"
44
+ }
45
+ }