@getuserfeedback/protocol 0.1.0 → 0.2.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,39 @@
1
+ import * as z from "zod";
2
+ export declare const clientMetaSchema: z.ZodObject<{
3
+ loader: z.ZodEnum<{
4
+ sdk: "sdk";
5
+ gtm: "gtm";
6
+ segment: "segment";
7
+ rudderstack: "rudderstack";
8
+ tealium: "tealium";
9
+ custom: "custom";
10
+ }>;
11
+ clientName: z.ZodOptional<z.ZodString>;
12
+ clientVersion: z.ZodOptional<z.ZodString>;
13
+ integrator: z.ZodOptional<z.ZodObject<{
14
+ name: z.ZodOptional<z.ZodString>;
15
+ version: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strip>>;
17
+ transport: z.ZodOptional<z.ZodEnum<{
18
+ loader: "loader";
19
+ "script-tag": "script-tag";
20
+ esm: "esm";
21
+ "tag-manager": "tag-manager";
22
+ snippet: "snippet";
23
+ }>>;
24
+ runtime: z.ZodOptional<z.ZodObject<{
25
+ framework: z.ZodOptional<z.ZodEnum<{
26
+ next: "next";
27
+ vite: "vite";
28
+ webpack: "webpack";
29
+ plain: "plain";
30
+ }>>;
31
+ runtime: z.ZodOptional<z.ZodEnum<{
32
+ browser: "browser";
33
+ edge: "edge";
34
+ }>>;
35
+ }, z.core.$strip>>;
36
+ notes: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strip>;
38
+ export type ClientMeta = z.output<typeof clientMetaSchema>;
39
+ //# sourceMappingURL=client-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-meta.d.ts","sourceRoot":"","sources":["../src/client-meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoB3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import * as z from "zod";
2
+ export const clientMetaSchema = z.object({
3
+ loader: z.enum(["sdk", "gtm", "segment", "rudderstack", "tealium", "custom"]),
4
+ clientName: z.optional(z.string().trim().min(1)),
5
+ clientVersion: z.optional(z.string().trim().min(1)),
6
+ integrator: z.optional(z.object({
7
+ name: z.optional(z.string().trim().min(1)),
8
+ version: z.optional(z.string().trim().min(1)),
9
+ })),
10
+ transport: z.optional(z.enum(["script-tag", "esm", "loader", "tag-manager", "snippet"])),
11
+ runtime: z.optional(z.object({
12
+ framework: z.optional(z.enum(["next", "vite", "webpack", "plain"])),
13
+ runtime: z.optional(z.enum(["browser", "edge"])),
14
+ })),
15
+ notes: z.optional(z.string().trim().min(1)),
16
+ });
@@ -0,0 +1,5 @@
1
+ export declare const DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS: readonly [
2
+ "class",
3
+ "data-theme"
4
+ ];
5
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sCAAsC,EAAE,SAAS;IAC7D,OAAO;IACP,YAAY;CACc,CAAC"}
@@ -0,0 +1 @@
1
+ export const DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS = ["class", "data-theme"];
@@ -1 +1 @@
1
- {"version":3,"file":"command-settlement.d.ts","sourceRoot":"","sources":["../../src/host/command-settlement.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,oBAAoB,EAEzB,MAAM,0BAA0B,CAAC;AAElC,KAAK,6BAA6B,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,eAAO,MAAM,+BAA+B,EAC3C,4BAAqC,CAAC;AAEvC,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEvB,KAAK,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd;CAUD;AAED,KAAK,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAEhF,eAAO,MAAM,wBAAwB,GACpC,QAAQ,2BAA2B,KACjC,sBAUF,CAAC;AAEF,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,QAAQ,CAAC,IAAI,+BAAmC;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM;CAK7B;AASD,eAAO,MAAM,wBAAwB,GACpC,OAAO,6BAA6B,KAClC,OAAO,CAAC,oBAAoB,CAgD9B,CAAC"}
1
+ {"version":3,"file":"command-settlement.d.ts","sourceRoot":"","sources":["../../src/host/command-settlement.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,oBAAoB,EAEzB,MAAM,0BAA0B,CAAC;AAElC,KAAK,6BAA6B,GAAG;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,eAAO,MAAM,+BAA+B,EAC3C,4BAAqC,CAAC;AAEvC,qBAAa,sBAAuB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEvB,KAAK,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACd;CAUD;AAED,KAAK,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,EAAE;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAEhF,eAAO,MAAM,wBAAwB,GACpC,QAAQ,2BAA2B,KACjC,sBAUF,CAAC;AAEF,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,QAAQ,CAAC,IAAI,+BAAmC;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM;CAK7B;AAKD,eAAO,MAAM,wBAAwB,GACpC,OAAO,6BAA6B,KAClC,OAAO,CAAC,oBAAoB,CAgD9B,CAAC"}
@@ -37,12 +37,7 @@ export class CommandSettlementTimeoutError extends Error {
37
37
  this.requestId = requestId;
38
38
  }
39
39
  }
40
- const eventHasDetail = (event) => {
41
- if (typeof CustomEvent !== "undefined") {
42
- return event instanceof CustomEvent;
43
- }
44
- return typeof event === "object" && event !== null && "detail" in event;
45
- };
40
+ const eventHasDetail = (event) => typeof event === "object" && event !== null && "detail" in event;
46
41
  export const waitForCommandSettlement = (input) => {
47
42
  const requestId = input.requestId;
48
43
  if (!requestId) {
@@ -0,0 +1,5 @@
1
+ export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
2
+ export { getScopeMeta, listScopes, SCOPE_IDS, type Scope, scopeIdSchema, } from "./scopes.js";
3
+ export { type PublicCommandPayload, parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
4
+ export { type ConfigureOptions, colorSchemeConfigInputSchema, configureOptionsSchema, consentConfigInputSchema, type InitOptions, initOptionsSchema, } from "./widget-config.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACN,YAAY,EACZ,UAAU,EACV,SAAS,EACT,KAAK,KAAK,EACV,aAAa,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,oBAAoB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,KAAK,gBAAgB,EACrB,4BAA4B,EAC5B,sBAAsB,EACtB,wBAAwB,EACxB,KAAK,WAAW,EAChB,iBAAiB,GACjB,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
2
+ export { getScopeMeta, listScopes, SCOPE_IDS, scopeIdSchema, } from "./scopes.js";
3
+ export { parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
4
+ export { colorSchemeConfigInputSchema, configureOptionsSchema, consentConfigInputSchema, initOptionsSchema, } from "./widget-config.js";
@@ -0,0 +1,7 @@
1
+ import * as z from "zod";
2
+ export declare const runtimeEndpointsSchema: z.ZodObject<{
3
+ apiUrl: z.ZodOptional<z.ZodString>;
4
+ coreUrl: z.ZodOptional<z.ZodString>;
5
+ }, z.core.$strict>;
6
+ export type RuntimeEndpoints = z.output<typeof runtimeEndpointsSchema>;
7
+ //# sourceMappingURL=runtime-endpoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-endpoints.d.ts","sourceRoot":"","sources":["../src/runtime-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,sBAAsB;;;kBAKzB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as z from "zod";
2
+ const absoluteUrlSchema = z.string().trim().url();
3
+ export const runtimeEndpointsSchema = z
4
+ .object({
5
+ apiUrl: z.optional(absoluteUrlSchema),
6
+ coreUrl: z.optional(absoluteUrlSchema),
7
+ })
8
+ .strict();
@@ -0,0 +1,30 @@
1
+ import * as z from "zod";
2
+ export declare const SCOPE_IDS: readonly [
3
+ "functionality.storage",
4
+ "security.storage",
5
+ "analytics.storage",
6
+ "analytics.measurement",
7
+ "personalization.storage",
8
+ "ads.storage",
9
+ "ads.user_data",
10
+ "ads.personalization"
11
+ ];
12
+ export declare const scopeIdSchema: z.ZodEnum<{
13
+ "functionality.storage": "functionality.storage";
14
+ "security.storage": "security.storage";
15
+ "analytics.storage": "analytics.storage";
16
+ "analytics.measurement": "analytics.measurement";
17
+ "personalization.storage": "personalization.storage";
18
+ "ads.storage": "ads.storage";
19
+ "ads.user_data": "ads.user_data";
20
+ "ads.personalization": "ads.personalization";
21
+ }>;
22
+ export type Scope = (typeof SCOPE_IDS)[number];
23
+ export type ScopeMeta = {
24
+ description: string;
25
+ };
26
+ export declare function getScopeMeta(id: Scope): ScopeMeta;
27
+ export declare function listScopes(): ReadonlyArray<{
28
+ id: Scope;
29
+ } & ScopeMeta>;
30
+ //# sourceMappingURL=scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../src/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,SAAS,EAAE,SAAS;IAChC,uBAAuB;IACvB,kBAAkB;IAClB,mBAAmB;IACnB,uBAAuB;IACvB,yBAAyB;IACzB,aAAa;IACb,eAAe;IACf,qBAAqB;CAUrB,CAAC;AAEF,eAAO,MAAM,aAAa;;;;;;;;;EAAoB,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAqCF,wBAAgB,YAAY,CAAC,EAAE,EAAE,KAAK,GAAG,SAAS,CAEjD;AAED,wBAAgB,UAAU,IAAI,aAAa,CAAC;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,GAAG,SAAS,CAAC,CAKrE"}
package/dist/scopes.js ADDED
@@ -0,0 +1,47 @@
1
+ import * as z from "zod";
2
+ export const SCOPE_IDS = [
3
+ "functionality.storage",
4
+ "security.storage",
5
+ "analytics.storage",
6
+ "analytics.measurement",
7
+ "personalization.storage",
8
+ "ads.storage",
9
+ "ads.user_data",
10
+ "ads.personalization",
11
+ ];
12
+ export const scopeIdSchema = z.enum(SCOPE_IDS);
13
+ const scopeMetaById = {
14
+ "functionality.storage": {
15
+ description: "Allow essential storage for core widget behavior (e.g., frequency capping, dismissals, draft answers).",
16
+ },
17
+ "security.storage": {
18
+ description: "Allow storage used for fraud/abuse prevention and integrity checks.",
19
+ },
20
+ "analytics.storage": {
21
+ description: "Allow storage for analytics identifiers enabling consistent cross-session measurement.",
22
+ },
23
+ "analytics.measurement": {
24
+ description: "Allow sending analytics events; can operate without storage when needed.",
25
+ },
26
+ "personalization.storage": {
27
+ description: "Allow storage used to personalize the widget UI/targeting (non-ads).",
28
+ },
29
+ "ads.storage": {
30
+ description: "Allow storage for advertising identifiers and conversion cookies.",
31
+ },
32
+ "ads.user_data": {
33
+ description: "Allow sending user data to ad platforms when legally permitted.",
34
+ },
35
+ "ads.personalization": {
36
+ description: "Allow personalized advertising signals and interest-based targeting.",
37
+ },
38
+ };
39
+ export function getScopeMeta(id) {
40
+ return scopeMetaById[id];
41
+ }
42
+ export function listScopes() {
43
+ return SCOPE_IDS.map((id) => ({
44
+ id,
45
+ ...getScopeMeta(id),
46
+ }));
47
+ }
@@ -0,0 +1,163 @@
1
+ import * as z from "zod";
2
+ import { type ConfigureOptions, type InitOptions } from "./widget-config.js";
3
+ export declare const containerPolicySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ kind: z.ZodLiteral<"floating">;
5
+ }, z.core.$strict>, z.ZodObject<{
6
+ kind: z.ZodLiteral<"hostContainer">;
7
+ host: z.ZodCustom<HTMLElement | null, HTMLElement | null>;
8
+ sharing: z.ZodEnum<{
9
+ shared: "shared";
10
+ perFlowRun: "perFlowRun";
11
+ }>;
12
+ }, z.core.$strict>], "kind">;
13
+ export declare const publicCommandPayloadSchema: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
14
+ kind: z.ZodLiteral<"open">;
15
+ flowId: z.ZodString;
16
+ flowHandleId: z.ZodOptional<z.ZodString>;
17
+ container: z.ZodOptional<z.ZodCustom<HTMLElement, HTMLElement>>;
18
+ containerRequirement: z.ZodOptional<z.ZodEnum<{
19
+ any: "any";
20
+ hostOnly: "hostOnly";
21
+ }>>;
22
+ hideCloseButton: z.ZodOptional<z.ZodBoolean>;
23
+ }, z.core.$strict>, z.ZodObject<{
24
+ kind: z.ZodLiteral<"prefetch">;
25
+ flowId: z.ZodString;
26
+ flowHandleId: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strict>, z.ZodObject<{
28
+ kind: z.ZodLiteral<"prerender">;
29
+ flowId: z.ZodString;
30
+ flowHandleId: z.ZodOptional<z.ZodString>;
31
+ hideCloseButton: z.ZodOptional<z.ZodBoolean>;
32
+ }, z.core.$strict>, z.ZodObject<{
33
+ kind: z.ZodLiteral<"setContainer">;
34
+ flowHandleId: z.ZodString;
35
+ container: z.ZodCustom<HTMLElement | null, HTMLElement | null>;
36
+ }, z.core.$strict>, z.ZodObject<{
37
+ kind: z.ZodLiteral<"setDefaultContainerPolicy">;
38
+ policy: z.ZodDiscriminatedUnion<[z.ZodObject<{
39
+ kind: z.ZodLiteral<"floating">;
40
+ }, z.core.$strict>, z.ZodObject<{
41
+ kind: z.ZodLiteral<"hostContainer">;
42
+ host: z.ZodCustom<HTMLElement | null, HTMLElement | null>;
43
+ sharing: z.ZodEnum<{
44
+ shared: "shared";
45
+ perFlowRun: "perFlowRun";
46
+ }>;
47
+ }, z.core.$strict>], "kind">;
48
+ }, z.core.$strict>, z.ZodObject<{
49
+ kind: z.ZodLiteral<"configure">;
50
+ opts: z.ZodObject<{
51
+ colorScheme: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
52
+ autoDetectColorScheme: z.ZodArray<z.ZodString>;
53
+ }, z.core.$strict>, z.ZodEnum<{
54
+ light: "light";
55
+ dark: "dark";
56
+ system: "system";
57
+ }>]>>;
58
+ consent: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
59
+ granted: "granted";
60
+ denied: "denied";
61
+ pending: "pending";
62
+ revoked: "revoked";
63
+ }>, z.ZodArray<z.ZodEnum<{
64
+ "analytics.storage": "analytics.storage";
65
+ "analytics.measurement": "analytics.measurement";
66
+ "personalization.storage": "personalization.storage";
67
+ "ads.storage": "ads.storage";
68
+ "ads.user_data": "ads.user_data";
69
+ "ads.personalization": "ads.personalization";
70
+ }>>]>>;
71
+ auth: z.ZodOptional<z.ZodObject<{
72
+ jwt: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
73
+ token: z.ZodString;
74
+ }, z.core.$strip>, z.ZodNull]>>;
75
+ }, z.core.$strip>>;
76
+ }, z.core.$strict>;
77
+ }, z.core.$strict>, z.ZodObject<{
78
+ kind: z.ZodLiteral<"init">;
79
+ opts: z.ZodObject<{
80
+ apiKey: z.ZodString;
81
+ colorScheme: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
82
+ autoDetectColorScheme: z.ZodArray<z.ZodString>;
83
+ }, z.core.$strict>, z.ZodEnum<{
84
+ light: "light";
85
+ dark: "dark";
86
+ system: "system";
87
+ }>]>>;
88
+ disableTelemetry: z.ZodOptional<z.ZodBoolean>;
89
+ enableDebug: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>>;
90
+ defaultConsent: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
91
+ granted: "granted";
92
+ denied: "denied";
93
+ pending: "pending";
94
+ revoked: "revoked";
95
+ }>, z.ZodArray<z.ZodEnum<{
96
+ "analytics.storage": "analytics.storage";
97
+ "analytics.measurement": "analytics.measurement";
98
+ "personalization.storage": "personalization.storage";
99
+ "ads.storage": "ads.storage";
100
+ "ads.user_data": "ads.user_data";
101
+ "ads.personalization": "ads.personalization";
102
+ }>>]>>;
103
+ clientMeta: z.ZodOptional<z.ZodObject<{
104
+ loader: z.ZodEnum<{
105
+ sdk: "sdk";
106
+ gtm: "gtm";
107
+ segment: "segment";
108
+ rudderstack: "rudderstack";
109
+ tealium: "tealium";
110
+ custom: "custom";
111
+ }>;
112
+ clientName: z.ZodOptional<z.ZodString>;
113
+ clientVersion: z.ZodOptional<z.ZodString>;
114
+ integrator: z.ZodOptional<z.ZodObject<{
115
+ name: z.ZodOptional<z.ZodString>;
116
+ version: z.ZodOptional<z.ZodString>;
117
+ }, z.core.$strip>>;
118
+ transport: z.ZodOptional<z.ZodEnum<{
119
+ loader: "loader";
120
+ "script-tag": "script-tag";
121
+ esm: "esm";
122
+ "tag-manager": "tag-manager";
123
+ snippet: "snippet";
124
+ }>>;
125
+ runtime: z.ZodOptional<z.ZodObject<{
126
+ framework: z.ZodOptional<z.ZodEnum<{
127
+ next: "next";
128
+ vite: "vite";
129
+ webpack: "webpack";
130
+ plain: "plain";
131
+ }>>;
132
+ runtime: z.ZodOptional<z.ZodEnum<{
133
+ browser: "browser";
134
+ edge: "edge";
135
+ }>>;
136
+ }, z.core.$strip>>;
137
+ notes: z.ZodOptional<z.ZodString>;
138
+ }, z.core.$strip>>;
139
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
140
+ runtimeEndpoints: z.ZodOptional<z.ZodObject<{
141
+ apiUrl: z.ZodOptional<z.ZodString>;
142
+ coreUrl: z.ZodOptional<z.ZodString>;
143
+ }, z.core.$strict>>;
144
+ }, z.core.$strict>;
145
+ }, z.core.$strict>, z.ZodObject<{
146
+ kind: z.ZodLiteral<"close">;
147
+ flowHandleId: z.ZodOptional<z.ZodString>;
148
+ }, z.core.$strict>, z.ZodObject<{
149
+ kind: z.ZodLiteral<"reset">;
150
+ }, z.core.$strict>], "kind">, z.ZodUnion<readonly [z.ZodObject<{
151
+ kind: z.ZodLiteral<"identify">;
152
+ traits: z.ZodRecord<z.ZodString, z.ZodUnknown>;
153
+ }, z.core.$strict>, z.ZodObject<{
154
+ kind: z.ZodLiteral<"identify">;
155
+ userId: z.ZodString;
156
+ traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
157
+ }, z.core.$strict>]>]>;
158
+ export type PublicCommandPayload = z.output<typeof publicCommandPayloadSchema>;
159
+ export type ContainerPolicy = z.output<typeof containerPolicySchema>;
160
+ export declare function parseInitOptions(input: unknown): InitOptions;
161
+ export declare function parseConfigureOptions(input: unknown): ConfigureOptions;
162
+ export declare function parsePublicCommand(input: unknown): PublicCommandPayload;
163
+ //# sourceMappingURL=widget-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-commands.d.ts","sourceRoot":"","sources":["../src/widget-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,WAAW,EAEhB,MAAM,oBAAoB,CAAC;AAkD5B,eAAO,MAAM,qBAAqB;;;;;;;;;4BAahC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAiErC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE/E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAErE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAE5D;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAEtE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAEvE"}
@@ -0,0 +1,130 @@
1
+ import * as z from "zod";
2
+ import { configureOptionsSchema, initOptionsSchema, } from "./widget-config.js";
3
+ const flowHandleIdSchema = z.string().trim().min(1);
4
+ const flowIdSchema = z.string().trim().min(1);
5
+ const isHTMLElementLike = (value) => {
6
+ if (typeof value !== "object" || value === null) {
7
+ return false;
8
+ }
9
+ if (typeof HTMLElement !== "undefined" && value instanceof HTMLElement) {
10
+ return true;
11
+ }
12
+ if (!("nodeType" in value) || !("appendChild" in value)) {
13
+ return false;
14
+ }
15
+ const nodeType = Reflect.get(value, "nodeType");
16
+ const appendChild = Reflect.get(value, "appendChild");
17
+ return nodeType === 1 && typeof appendChild === "function";
18
+ };
19
+ const htmlElementSchema = z.custom(isHTMLElementLike, {
20
+ message: "Container must be an HTMLElement with nodeType=1",
21
+ });
22
+ const htmlElementOrNullSchema = z.custom((value) => value === null || isHTMLElementLike(value), {
23
+ message: "Container must be null or an HTMLElement with nodeType=1",
24
+ });
25
+ const identifyTraitsSchema = z.record(z.string(), z.unknown());
26
+ const identifyPayloadSchema = z.union([
27
+ z
28
+ .object({
29
+ kind: z.literal("identify"),
30
+ traits: identifyTraitsSchema,
31
+ })
32
+ .strict(),
33
+ z
34
+ .object({
35
+ kind: z.literal("identify"),
36
+ userId: z.string().trim().min(1),
37
+ traits: z.optional(identifyTraitsSchema),
38
+ })
39
+ .strict(),
40
+ ]);
41
+ const legacyContainerRequirementSchema = z.enum(["any", "hostOnly"]);
42
+ export const containerPolicySchema = z.discriminatedUnion("kind", [
43
+ z
44
+ .object({
45
+ kind: z.literal("floating"),
46
+ })
47
+ .strict(),
48
+ z
49
+ .object({
50
+ kind: z.literal("hostContainer"),
51
+ host: htmlElementOrNullSchema,
52
+ sharing: z.enum(["shared", "perFlowRun"]),
53
+ })
54
+ .strict(),
55
+ ]);
56
+ export const publicCommandPayloadSchema = z.union([
57
+ z.discriminatedUnion("kind", [
58
+ z
59
+ .object({
60
+ kind: z.literal("open"),
61
+ flowId: flowIdSchema,
62
+ flowHandleId: z.optional(flowHandleIdSchema),
63
+ container: z.optional(htmlElementSchema),
64
+ containerRequirement: z.optional(legacyContainerRequirementSchema),
65
+ hideCloseButton: z.optional(z.boolean()),
66
+ })
67
+ .strict(),
68
+ z
69
+ .object({
70
+ kind: z.literal("prefetch"),
71
+ flowId: flowIdSchema,
72
+ flowHandleId: z.optional(flowHandleIdSchema),
73
+ })
74
+ .strict(),
75
+ z
76
+ .object({
77
+ kind: z.literal("prerender"),
78
+ flowId: flowIdSchema,
79
+ flowHandleId: z.optional(flowHandleIdSchema),
80
+ hideCloseButton: z.optional(z.boolean()),
81
+ })
82
+ .strict(),
83
+ z
84
+ .object({
85
+ kind: z.literal("setContainer"),
86
+ flowHandleId: flowHandleIdSchema,
87
+ container: htmlElementOrNullSchema,
88
+ })
89
+ .strict(),
90
+ z
91
+ .object({
92
+ kind: z.literal("setDefaultContainerPolicy"),
93
+ policy: containerPolicySchema,
94
+ })
95
+ .strict(),
96
+ z
97
+ .object({
98
+ kind: z.literal("configure"),
99
+ opts: configureOptionsSchema,
100
+ })
101
+ .strict(),
102
+ z
103
+ .object({
104
+ kind: z.literal("init"),
105
+ opts: initOptionsSchema,
106
+ })
107
+ .strict(),
108
+ z
109
+ .object({
110
+ kind: z.literal("close"),
111
+ flowHandleId: z.optional(flowHandleIdSchema),
112
+ })
113
+ .strict(),
114
+ z
115
+ .object({
116
+ kind: z.literal("reset"),
117
+ })
118
+ .strict(),
119
+ ]),
120
+ identifyPayloadSchema,
121
+ ]);
122
+ export function parseInitOptions(input) {
123
+ return initOptionsSchema.parse(input);
124
+ }
125
+ export function parseConfigureOptions(input) {
126
+ return configureOptionsSchema.parse(input);
127
+ }
128
+ export function parsePublicCommand(input) {
129
+ return publicCommandPayloadSchema.parse(input);
130
+ }
@@ -0,0 +1,126 @@
1
+ import * as z from "zod";
2
+ export declare const colorSchemeConfigInputSchema: z.ZodUnion<readonly [z.ZodObject<{
3
+ autoDetectColorScheme: z.ZodArray<z.ZodString>;
4
+ }, z.core.$strict>, z.ZodEnum<{
5
+ light: "light";
6
+ dark: "dark";
7
+ system: "system";
8
+ }>]>;
9
+ export type ColorSchemeConfigInput = z.output<typeof colorSchemeConfigInputSchema>;
10
+ export declare const consentConfigInputSchema: z.ZodUnion<readonly [z.ZodEnum<{
11
+ granted: "granted";
12
+ denied: "denied";
13
+ pending: "pending";
14
+ revoked: "revoked";
15
+ }>, z.ZodArray<z.ZodEnum<{
16
+ "analytics.storage": "analytics.storage";
17
+ "analytics.measurement": "analytics.measurement";
18
+ "personalization.storage": "personalization.storage";
19
+ "ads.storage": "ads.storage";
20
+ "ads.user_data": "ads.user_data";
21
+ "ads.personalization": "ads.personalization";
22
+ }>>]>;
23
+ export type ConsentConfigInput = z.output<typeof consentConfigInputSchema>;
24
+ export declare const debugInputSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>;
25
+ export declare const authConfigInputSchema: z.ZodObject<{
26
+ jwt: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
27
+ token: z.ZodString;
28
+ }, z.core.$strip>, z.ZodNull]>>;
29
+ }, z.core.$strip>;
30
+ export declare const configureOptionsSchema: z.ZodObject<{
31
+ colorScheme: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
32
+ autoDetectColorScheme: z.ZodArray<z.ZodString>;
33
+ }, z.core.$strict>, z.ZodEnum<{
34
+ light: "light";
35
+ dark: "dark";
36
+ system: "system";
37
+ }>]>>;
38
+ consent: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
39
+ granted: "granted";
40
+ denied: "denied";
41
+ pending: "pending";
42
+ revoked: "revoked";
43
+ }>, z.ZodArray<z.ZodEnum<{
44
+ "analytics.storage": "analytics.storage";
45
+ "analytics.measurement": "analytics.measurement";
46
+ "personalization.storage": "personalization.storage";
47
+ "ads.storage": "ads.storage";
48
+ "ads.user_data": "ads.user_data";
49
+ "ads.personalization": "ads.personalization";
50
+ }>>]>>;
51
+ auth: z.ZodOptional<z.ZodObject<{
52
+ jwt: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
53
+ token: z.ZodString;
54
+ }, z.core.$strip>, z.ZodNull]>>;
55
+ }, z.core.$strip>>;
56
+ }, z.core.$strict>;
57
+ export type ConfigureOptions = z.output<typeof configureOptionsSchema>;
58
+ export declare const initOptionsSchema: z.ZodObject<{
59
+ apiKey: z.ZodString;
60
+ colorScheme: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
61
+ autoDetectColorScheme: z.ZodArray<z.ZodString>;
62
+ }, z.core.$strict>, z.ZodEnum<{
63
+ light: "light";
64
+ dark: "dark";
65
+ system: "system";
66
+ }>]>>;
67
+ disableTelemetry: z.ZodOptional<z.ZodBoolean>;
68
+ enableDebug: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString, z.ZodArray<z.ZodString>]>>;
69
+ defaultConsent: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
70
+ granted: "granted";
71
+ denied: "denied";
72
+ pending: "pending";
73
+ revoked: "revoked";
74
+ }>, z.ZodArray<z.ZodEnum<{
75
+ "analytics.storage": "analytics.storage";
76
+ "analytics.measurement": "analytics.measurement";
77
+ "personalization.storage": "personalization.storage";
78
+ "ads.storage": "ads.storage";
79
+ "ads.user_data": "ads.user_data";
80
+ "ads.personalization": "ads.personalization";
81
+ }>>]>>;
82
+ clientMeta: z.ZodOptional<z.ZodObject<{
83
+ loader: z.ZodEnum<{
84
+ sdk: "sdk";
85
+ gtm: "gtm";
86
+ segment: "segment";
87
+ rudderstack: "rudderstack";
88
+ tealium: "tealium";
89
+ custom: "custom";
90
+ }>;
91
+ clientName: z.ZodOptional<z.ZodString>;
92
+ clientVersion: z.ZodOptional<z.ZodString>;
93
+ integrator: z.ZodOptional<z.ZodObject<{
94
+ name: z.ZodOptional<z.ZodString>;
95
+ version: z.ZodOptional<z.ZodString>;
96
+ }, z.core.$strip>>;
97
+ transport: z.ZodOptional<z.ZodEnum<{
98
+ loader: "loader";
99
+ "script-tag": "script-tag";
100
+ esm: "esm";
101
+ "tag-manager": "tag-manager";
102
+ snippet: "snippet";
103
+ }>>;
104
+ runtime: z.ZodOptional<z.ZodObject<{
105
+ framework: z.ZodOptional<z.ZodEnum<{
106
+ next: "next";
107
+ vite: "vite";
108
+ webpack: "webpack";
109
+ plain: "plain";
110
+ }>>;
111
+ runtime: z.ZodOptional<z.ZodEnum<{
112
+ browser: "browser";
113
+ edge: "edge";
114
+ }>>;
115
+ }, z.core.$strip>>;
116
+ notes: z.ZodOptional<z.ZodString>;
117
+ }, z.core.$strip>>;
118
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
119
+ runtimeEndpoints: z.ZodOptional<z.ZodObject<{
120
+ apiUrl: z.ZodOptional<z.ZodString>;
121
+ coreUrl: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strict>>;
123
+ }, z.core.$strict>;
124
+ export type InitOptions = z.output<typeof initOptionsSchema>;
125
+ export declare const DEFAULT_COLOR_SCHEME_CONFIG: ColorSchemeConfigInput;
126
+ //# sourceMappingURL=widget-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-config.d.ts","sourceRoot":"","sources":["../src/widget-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AA6BzB,eAAO,MAAM,4BAA4B;;;;;;IAOvC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAC5C,OAAO,4BAA4B,CACnC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;KAGnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE3E,eAAO,MAAM,gBAAgB,2EAI3B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;iBAShC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;kBAMzB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEvE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAWpB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7D,eAAO,MAAM,2BAA2B,EAAE,sBAEzC,CAAC"}
@@ -0,0 +1,64 @@
1
+ import * as z from "zod";
2
+ import { clientMetaSchema } from "./client-meta.js";
3
+ import { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
4
+ import { runtimeEndpointsSchema } from "./runtime-endpoints.js";
5
+ const colorSchemeValueSchema = z.enum(["light", "dark", "system"]);
6
+ const autoDetectColorSchemeArraySchema = z
7
+ .array(z.string().trim().min(1))
8
+ .min(1);
9
+ const publicGrantScopeIds = [
10
+ "analytics.storage",
11
+ "analytics.measurement",
12
+ "personalization.storage",
13
+ "ads.storage",
14
+ "ads.user_data",
15
+ "ads.personalization",
16
+ ];
17
+ const publicGrantScopeIdSchema = z.enum(publicGrantScopeIds);
18
+ export const colorSchemeConfigInputSchema = z.union([
19
+ z
20
+ .object({
21
+ autoDetectColorScheme: autoDetectColorSchemeArraySchema,
22
+ })
23
+ .strict(),
24
+ colorSchemeValueSchema,
25
+ ]);
26
+ export const consentConfigInputSchema = z.union([
27
+ z.enum(["granted", "denied", "pending", "revoked"]),
28
+ z.array(publicGrantScopeIdSchema),
29
+ ]);
30
+ export const debugInputSchema = z.union([
31
+ z.boolean(),
32
+ z.string(),
33
+ z.array(z.string()),
34
+ ]);
35
+ export const authConfigInputSchema = z.object({
36
+ jwt: z.optional(z.union([
37
+ z.object({
38
+ token: z.string().trim().min(1),
39
+ }),
40
+ z.null(),
41
+ ])),
42
+ });
43
+ export const configureOptionsSchema = z
44
+ .object({
45
+ colorScheme: z.optional(colorSchemeConfigInputSchema),
46
+ consent: z.optional(consentConfigInputSchema),
47
+ auth: z.optional(authConfigInputSchema),
48
+ })
49
+ .strict();
50
+ export const initOptionsSchema = z
51
+ .object({
52
+ apiKey: z.string().trim().min(1),
53
+ colorScheme: z.optional(colorSchemeConfigInputSchema),
54
+ disableTelemetry: z.optional(z.boolean()),
55
+ enableDebug: z.optional(debugInputSchema),
56
+ defaultConsent: z.optional(consentConfigInputSchema),
57
+ clientMeta: z.optional(clientMetaSchema),
58
+ capabilities: z.optional(z.array(z.string())),
59
+ runtimeEndpoints: z.optional(runtimeEndpointsSchema),
60
+ })
61
+ .strict();
62
+ export const DEFAULT_COLOR_SCHEME_CONFIG = {
63
+ autoDetectColorScheme: [...DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS],
64
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",
@@ -17,6 +17,10 @@
17
17
  "dist"
18
18
  ],
19
19
  "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
20
24
  "./host": {
21
25
  "types": "./dist/host/index.d.ts",
22
26
  "import": "./dist/host/index.js"
@@ -62,10 +66,14 @@
62
66
  "lint": "ultracite check .",
63
67
  "build": "bun x rimraf dist tsconfig.tsbuildinfo && tsc -b tsconfig.json",
64
68
  "typecheck": "tsc -b tsconfig.json",
69
+ "test": "bun test --dots",
65
70
  "pack:verify": "node ../../scripts/pack-and-verify.cjs",
66
71
  "publish:dry-run": "node ../../scripts/publish-package.cjs . -- --dry-run",
67
72
  "publish:npm": "node ../../scripts/publish-package.cjs ."
68
73
  },
74
+ "dependencies": {
75
+ "zod": "^4.2.1"
76
+ },
69
77
  "devDependencies": {
70
78
  "rimraf": "^6.0.0",
71
79
  "typescript": "^5.8.3"