@getuserfeedback/sdk 0.19.12 → 0.20.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.
@@ -0,0 +1,224 @@
1
+ import { AppEventJsonInputValue, ListInstanceFeedbackMineRequest, ListInstanceFeedbackMineResponse, CaptureInstanceFeedbackRequest, CaptureInstanceFeedbackResponse } from '@getuserfeedback/protocol';
2
+ import { TrackOptions, OpenRequestedDetail, ContainerPolicy, FlowRenderState, WidgetLayoutTransitionPolicy, ResponseMetadataInput, ConfigureOptions, IdentifyOptions, AppEventIdentity } from '@getuserfeedback/protocol/host';
3
+
4
+ type EventProperties = Record<string, AppEventJsonInputValue>;
5
+ type EventOptions = TrackOptions;
6
+
7
+ type OpenRequestedPayload = OpenRequestedDetail;
8
+ type OpenRequestedSource = OpenRequestedPayload["source"];
9
+ type OpenRequestedEvent$1 = {
10
+ /**
11
+ * Origin of this open request.
12
+ * - `"command"`: requested by an explicit open command, e.g. when you call `client.flow(flowId).open()`.
13
+ * - `"targeting"`: requested by targeting plan evaluation.
14
+ */
15
+ readonly source: OpenRequestedSource;
16
+ /** Flow identifier that is about to be opened. */
17
+ readonly flowId: string;
18
+ readonly defaultPrevented: boolean;
19
+ preventDefault: () => void;
20
+ };
21
+
22
+ /** Feedback captured as an evaluation of the current app or a specific target. */
23
+ type FeedbackInput = CaptureInstanceFeedbackRequest;
24
+ /** Receipt returned after feedback has been accepted. */
25
+ type SubmitFeedbackResult = CaptureInstanceFeedbackResponse;
26
+ /** Selectors used to read the current authenticated user's feedback. */
27
+ type FetchFeedbackInput = ListInstanceFeedbackMineRequest;
28
+ /** Feedback matching each requested selector, in selector order. */
29
+ type FetchFeedbackResult = ListInstanceFeedbackMineResponse;
30
+ /** Operations for submitting and reading feedback through the current SDK client. */
31
+ type FeedbackOperations = {
32
+ /**
33
+ * Read feedback matching each selector for the JWT-authenticated user.
34
+ * Requires `auth.jwt` configuration; `identify()` alone does not authorize readback.
35
+ */
36
+ fetch: (input: FetchFeedbackInput) => Promise<FetchFeedbackResult>;
37
+ submit: (input: FeedbackInput) => Promise<SubmitFeedbackResult>;
38
+ };
39
+ /** One endpoint in a directed relationship observation. Use `identities` for a user without a stable user ID. */
40
+ type GraphEndpointIdentity = AppEventIdentity | {
41
+ type: `externalId.users.none.${string}`;
42
+ value: string;
43
+ };
44
+ type GraphRelationshipRef = {
45
+ collection: string;
46
+ id: string;
47
+ identities?: never;
48
+ } | {
49
+ collection: "user";
50
+ identities: GraphEndpointIdentity[];
51
+ id?: never;
52
+ };
53
+ /** A directed relationship observation recorded through the analytics pipeline. */
54
+ type GraphRelationship = {
55
+ from: GraphRelationshipRef;
56
+ to: GraphRelationshipRef;
57
+ };
58
+ /** Operations for recording relationship observations as product events. */
59
+ type GraphOperations = {
60
+ connect: (relationship: GraphRelationship) => Promise<void>;
61
+ disconnect: (relationship: GraphRelationship) => Promise<void>;
62
+ };
63
+
64
+ /** Current flow state (open/loading and dimensions when known). */
65
+ interface FlowState extends FlowRenderState {
66
+ /**
67
+ * @deprecated Stop reading this field. SDK state snapshots and subscriptions
68
+ * never populate it, and there is no replacement SDK state field.
69
+ */
70
+ transitionPolicy?: WidgetLayoutTransitionPolicy;
71
+ }
72
+ /** Callback invoked when flow state changes. */
73
+ type FlowStateCallback = (state: FlowState) => void;
74
+ type IdentifyTraits = Record<string, unknown>;
75
+ type OpenRequestedEvent = OpenRequestedEvent$1;
76
+ type OpenRequestedCallback = (event: OpenRequestedEvent) => void;
77
+ /** Options for opening a flow run. */
78
+ type OpenFlowOptions = {
79
+ /** Host container used for this open request. Omit to use default floating mounting; pass null to wait for a custom container. */
80
+ container?: HTMLElement | null;
81
+ /**
82
+ * Optional response metadata to preserve with the eventual submission.
83
+ * These tags are attached when the flow is opened and do not affect prerendering.
84
+ */
85
+ metadata?: ResponseMetadataInput;
86
+ /**
87
+ * When `true`, the flow view does not show a close button.
88
+ * Useful for mobile or embedded contexts where the host handles dismissal (e.g. via a drawer or back gesture).
89
+ */
90
+ hideCloseButton?: boolean;
91
+ };
92
+ /** Options for prerendering a flow run. */
93
+ type PrerenderFlowOptions = {
94
+ /**
95
+ * When `true`, the prerendered view does not show a close button.
96
+ */
97
+ hideCloseButton?: boolean;
98
+ };
99
+ /** Options for subscribing to flow state updates. */
100
+ type SubscribeFlowStateOptions = {
101
+ /** Emit the current snapshot immediately. Default `true`. */
102
+ emitInitial?: boolean;
103
+ /** Auto-unsubscribe when the signal is aborted. */
104
+ signal?: AbortSignal;
105
+ };
106
+ /** Instance for a specific flow: open, prefetch, prerender, close, and subscribe to flow state. */
107
+ type FlowRun = {
108
+ /** The flow/survey ID this instance refers to. */
109
+ flowId: string;
110
+ /** Open the flow. Immediately reports loading until the open settles or close/reset clears its intent. */
111
+ open: (options?: OpenFlowOptions) => Promise<void>;
112
+ /** Prefetch the flow so it opens faster when you call `open()`. */
113
+ prefetch: () => Promise<void>;
114
+ /** Prerender the flow into a container (e.g. for a custom dialog). */
115
+ prerender: (options?: PrerenderFlowOptions) => Promise<void>;
116
+ /** Attach or detach this flow to a specific host container. */
117
+ setContainer: (element: HTMLElement | null) => void;
118
+ /** Close this flow. */
119
+ close: () => Promise<void>;
120
+ /** Return the latest known flow state snapshot. */
121
+ getFlowState: () => FlowState;
122
+ /** Subscribe to open/loading/dimensions; returns an unsubscribe function. */
123
+ subscribeFlowState: (callback: FlowStateCallback, options?: SubscribeFlowStateOptions) => () => void;
124
+ };
125
+ /**
126
+ * getuserfeedback client for loading the widget, opening flows, configuring
127
+ * consent/auth, identifying users, and tracking events.
128
+ *
129
+ * @see https://getuserfeedback.com/docs/reference/javascript-sdk-reference
130
+ */
131
+ type Client = {
132
+ /** Load the widget script. Call when you created the client with `disableAutoLoad: true`. */
133
+ load: () => void;
134
+ /** Set how this instance should choose default containers for flows. */
135
+ setDefaultContainerPolicy: (policy: ContainerPolicy) => void;
136
+ /** Return the latest known instance-level flow state snapshot. */
137
+ getFlowState: () => FlowState;
138
+ /** Subscribe to instance-level flow state updates (eg targeting-triggered opens). */
139
+ subscribeFlowState: (callback: FlowStateCallback, options?: SubscribeFlowStateOptions) => () => void;
140
+ /** Return a flow instance; call .open(), .prefetch(), .prerender(), .close() on it. */
141
+ flow: (flowId: string) => FlowRun;
142
+ /** Close all open flows. */
143
+ close: () => Promise<void>;
144
+ /** Close all open flows, clear JWT authentication, and reset user identity. */
145
+ reset: () => Promise<void>;
146
+ /**
147
+ * Update color scheme, consent, or auth. Pass a fresh JWT here after login
148
+ * and whenever your auth provider refreshes the session token. Await the
149
+ * returned promise or handle its rejection when applying runtime updates.
150
+ *
151
+ * When using `disableAutoLoad`, call `load()` first. Calls made before `load()`
152
+ * resolve without applying the update. Provide the initial color scheme,
153
+ * default consent, and properties to `createClient()`; configure auth after
154
+ * `load()`.
155
+ *
156
+ * @see https://getuserfeedback.com/docs/security-and-privacy/jwt-auth
157
+ */
158
+ configure: (updates: ConfigureOptions) => Promise<void>;
159
+ /**
160
+ * Associate the current user with a user ID, traits, and optional external IDs.
161
+ *
162
+ * Use `options.externalIds` for Segment-compatible identifiers from another
163
+ * system. Without a user ID, pass options as `client.identify(traits, options)`,
164
+ * or use `client.identify(traits, undefined, options)` when your call site needs
165
+ * the explicit three-argument form. Do not put Segment-shaped `externalIds` in
166
+ * traits. Some invalid arguments throw synchronously; other validation or
167
+ * command-processing failures reject the returned promise.
168
+ *
169
+ * @see https://getuserfeedback.com/docs/guides/identity-resolution
170
+ */
171
+ identify: {
172
+ (userId: string, traits?: IdentifyTraits, options?: IdentifyOptions): Promise<void>;
173
+ (traits: IdentifyTraits, placeholder: undefined, options?: IdentifyOptions): Promise<void>;
174
+ (traits: IdentifyTraits, options?: IdentifyOptions): Promise<void>;
175
+ };
176
+ /**
177
+ * Track a product event from the browser.
178
+ *
179
+ * Use `options.externalIds` when the event carries a Segment-compatible
180
+ * identifier from another system. Do not put Segment-shaped `externalIds` in
181
+ * properties. Some invalid arguments throw synchronously; other validation or
182
+ * command-processing failures reject the returned promise.
183
+ *
184
+ * @see https://getuserfeedback.com/docs/reference/events
185
+ */
186
+ track: (eventName: string, properties?: EventProperties, options?: EventOptions) => Promise<void>;
187
+ /**
188
+ * Record the current browser page or a named page location. Some invalid
189
+ * arguments throw synchronously; other validation or command-processing
190
+ * failures reject the returned promise.
191
+ */
192
+ page: (name?: string, properties?: EventProperties, options?: EventOptions) => Promise<void>;
193
+ /** Record directed relationship observations through the analytics pipeline. */
194
+ graph: GraphOperations;
195
+ /** Submit feedback or read the authenticated user's matching feedback. */
196
+ feedback: FeedbackOperations;
197
+ /** Subscribe to explicit SDK and client-side targeting open requests, or suppress them — for example if you know the user should not be interrupted.
198
+ * For example, when the user is filling out a form, or is in the middle of a multi-step flow.
199
+ * Prevention applies only to that presentation attempt; it does not create a
200
+ * public retry schedule.
201
+ *
202
+ * @example — suppress open flow requests if the user is busy
203
+ * ```ts
204
+ * client.onOpenRequested((event) => {
205
+ * if (userIsBusy()) {
206
+ * event.preventDefault();
207
+ * }
208
+ * });
209
+ * ```
210
+ */
211
+ onOpenRequested: (callback: OpenRequestedCallback) => () => void;
212
+ };
213
+
214
+ type ReactContainerTarget = Pick<Client, "getFlowState" | "subscribeFlowState" | "close">;
215
+ declare const createReactContainerOwner: () => string;
216
+ /** Unsupported React host-presence bridge. Public SDK container semantics stay imperative. */
217
+ type ReactContainerBridge = {
218
+ register: (ownerId: string, host: HTMLElement | null) => void;
219
+ };
220
+ declare const attachReactContainerBridge: (target: ReactContainerTarget, bridge: ReactContainerBridge) => void;
221
+ declare const registerReactContainer: (target: ReactContainerTarget, ownerId: string, host: HTMLElement | null) => void;
222
+
223
+ export { attachReactContainerBridge, createReactContainerOwner, registerReactContainer };
224
+ export type { ReactContainerBridge };
@@ -0,0 +1,4 @@
1
+ function i(e){if(typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID==="function")return globalThis.crypto.randomUUID();let t=`${Date.now()}_${Math.random().toString(36).slice(2)}`;return e?`${e}_${t}`:t}var o=()=>i("req");var k=()=>o(),n=Symbol.for("@getuserfeedback/sdk/internal/react-container/1"),S=(e,t)=>{Object.defineProperty(e,n,{value:t})},v=(e,t,a)=>{let r=n in e?e[n]:void 0;if(typeof r!=="object"||r===null||!("register"in r)||typeof r.register!=="function")throw Error("React containers require a compatible @getuserfeedback/sdk client.");r.register(t,a)};export{S as attachReactContainerBridge,k as createReactContainerOwner,v as registerReactContainer};
2
+
3
+ //# debugId=C2459AAF3CD5D60D64756E2164756E21
4
+ //# sourceMappingURL=react-container.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../protocol/dist/host/unique-id.js", "../../../protocol/dist/host/request-id.js", "../../src/internal/react-container.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Generates a unique string ID. Uses crypto.randomUUID when available,\n * otherwise falls back to a timestamp + random string.\n *\n * @param prefix - Optional prefix for the fallback format (e.g. \"req\", \"err\").\n * Only affects fallback; UUIDs have no prefix.\n */\nexport function createUniqueId(prefix) {\n if (typeof globalThis.crypto !== \"undefined\" &&\n typeof globalThis.crypto.randomUUID === \"function\") {\n return globalThis.crypto.randomUUID();\n }\n const fallback = `${Date.now()}_${Math.random().toString(36).slice(2)}`;\n return prefix ? `${prefix}_${fallback}` : fallback;\n}\n",
6
+ "import { createUniqueId } from \"./unique-id.js\";\nexport const createCommandRequestId = () => createUniqueId(\"req\");\n",
7
+ "import { createCommandRequestId } from \"@getuserfeedback/protocol/host\";\n\nimport type { Client } from \"../client\";\n\ntype ReactContainerTarget = Pick<\n\tClient,\n\t\"getFlowState\" | \"subscribeFlowState\" | \"close\"\n>;\n\nexport const createReactContainerOwner = (): string => createCommandRequestId();\n\n/** Unsupported React host-presence bridge. Public SDK container semantics stay imperative. */\nexport type ReactContainerBridge = {\n\tregister: (ownerId: string, host: HTMLElement | null) => void;\n};\n// Separate package entry bundles share this same-window lifecycle bridge.\n// The owner identity is lifecycle metadata, not caller authorization.\nconst bridgeSymbol = Symbol.for(\n\t\"@getuserfeedback/sdk/internal/react-container/1\",\n);\nexport const attachReactContainerBridge = (\n\ttarget: ReactContainerTarget,\n\tbridge: ReactContainerBridge,\n): void => {\n\tObject.defineProperty(target, bridgeSymbol, { value: bridge });\n};\nexport const registerReactContainer = (\n\ttarget: ReactContainerTarget,\n\townerId: string,\n\thost: HTMLElement | null,\n): void => {\n\tconst bridge = bridgeSymbol in target ? target[bridgeSymbol] : undefined;\n\tif (\n\t\ttypeof bridge !== \"object\" ||\n\t\tbridge === null ||\n\t\t!(\"register\" in bridge) ||\n\t\ttypeof bridge.register !== \"function\"\n\t)\n\t\tthrow new Error(\n\t\t\t\"React containers require a compatible @getuserfeedback/sdk client.\",\n\t\t);\n\tbridge.register(ownerId, host);\n};\n"
8
+ ],
9
+ "mappings": "AAOO,SAAS,CAAc,CAAC,EAAQ,CACnC,GAAI,OAAO,WAAW,OAAW,KAC7B,OAAO,WAAW,OAAO,aAAe,WACxC,OAAO,WAAW,OAAO,WAAW,EAExC,IAAM,EAAW,GAAG,KAAK,IAAI,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,IACpE,OAAO,EAAS,GAAG,KAAU,IAAa,ECZvC,IAAM,EAAyB,IAAM,EAAe,KAAK,ECQzD,IAAM,EAA4B,IAAc,EAAuB,EAQxE,EAAe,OAAO,IAC3B,iDACD,EACa,EAA6B,CACzC,EACA,IACU,CACV,OAAO,eAAe,EAAQ,EAAc,CAAE,MAAO,CAAO,CAAC,GAEjD,EAAyB,CACrC,EACA,EACA,IACU,CACV,IAAM,EAAS,KAAgB,EAAS,EAAO,GAAgB,OAC/D,GACC,OAAO,IAAW,UAClB,IAAW,MACX,EAAE,aAAc,IAChB,OAAO,EAAO,WAAa,WAE3B,MAAU,MACT,oEACD,EACD,EAAO,SAAS,EAAS,CAAI",
10
+ "debugId": "C2459AAF3CD5D60D64756E2164756E21",
11
+ "names": []
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/sdk",
3
- "version": "0.19.12",
3
+ "version": "0.20.0",
4
4
  "description": "getuserfeedback Typescript SDK",
5
5
  "keywords": [
6
6
  "getuserfeedback",
@@ -55,13 +55,17 @@
55
55
  "./internal/link-router": {
56
56
  "import": "./dist/internal/link-router.js",
57
57
  "types": "./dist/internal/link-router.d.ts"
58
+ },
59
+ "./internal/react-container": {
60
+ "import": "./dist/internal/react-container.js",
61
+ "types": "./dist/internal/react-container.d.ts"
58
62
  }
59
63
  },
60
64
  "files": [
61
65
  "dist"
62
66
  ],
63
67
  "dependencies": {
64
- "@getuserfeedback/protocol": "^6.1.1"
68
+ "@getuserfeedback/protocol": "^7.0.0"
65
69
  },
66
70
  "devDependencies": {
67
71
  "@typescript/typescript6": "^6.0.2",
@@ -77,7 +81,6 @@
77
81
  "build": "bun ../../scripts/clean-build-output.ts dist tsconfig.tsbuildinfo && bun run scripts/build.ts && bun x rollup -c rollup.dts.config.mjs && bun run scripts/verify-internal-build.ts",
78
82
  "typecheck": "tsc -p tsconfig.json --noEmit --composite false --incremental false",
79
83
  "test": "bun test --dots src __tests__",
80
- "test:changed": "bun test --changed=${TEST_CHANGED_BASE:-HEAD} --pass-with-no-tests --dots",
81
- "lint": "biome check ."
84
+ "lint": "oxlint --threads=2 -c ../../oxlint.config.ts ."
82
85
  }
83
86
  }