@getuserfeedback/protocol 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core-command-envelope.d.ts +749 -0
- package/dist/core-command-envelope.d.ts.map +1 -0
- package/dist/core-command-envelope.js +15 -0
- package/dist/core-commands.d.ts +698 -0
- package/dist/core-commands.d.ts.map +1 -0
- package/dist/core-commands.js +129 -0
- package/dist/host/command-envelope-schema.d.ts +12 -12
- package/dist/host/host-event-schemas.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/scopes.d.ts +2 -2
- package/dist/webview-transport.d.ts +14 -14
- package/dist/widget-commands.d.ts +6 -6
- package/dist/widget-config.d.ts +15 -15
- package/package.json +1 -1
- package/src/core-command-envelope.ts +27 -0
- package/src/core-commands.ts +164 -0
- package/src/index.ts +9 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
import {
|
|
3
|
+
appEventCustomerTrackSchema,
|
|
4
|
+
appEventExternalIdSchema,
|
|
5
|
+
appEventSystemTrackSchema,
|
|
6
|
+
} from "./app-event.js";
|
|
7
|
+
import { ErrorEventSchema } from "./errors.js";
|
|
8
|
+
import { responseMetadataInputSchema } from "./response-metadata.js";
|
|
9
|
+
import { configureOptionsSchema, initOptionsSchema } from "./widget-config.js";
|
|
10
|
+
|
|
11
|
+
const flowHandleIdSchema = z.string().check(z.trim(), z.minLength(1));
|
|
12
|
+
const flowIdSchema = z.string().check(z.trim(), z.minLength(1));
|
|
13
|
+
|
|
14
|
+
const identifyTraitsSchema = z.record(z.string(), z.unknown());
|
|
15
|
+
const identifyOptionsSchema = z.strictObject({
|
|
16
|
+
externalIds: z.optional(
|
|
17
|
+
z.array(appEventExternalIdSchema).check(z.maxLength(20)),
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const identifyPayloadSchema = z.union([
|
|
22
|
+
z.strictObject({
|
|
23
|
+
kind: z.literal("identify"),
|
|
24
|
+
traits: identifyTraitsSchema,
|
|
25
|
+
options: z.optional(identifyOptionsSchema),
|
|
26
|
+
}),
|
|
27
|
+
z.strictObject({
|
|
28
|
+
kind: z.literal("identify"),
|
|
29
|
+
userId: z.string().check(z.trim(), z.minLength(1)),
|
|
30
|
+
traits: z.optional(identifyTraitsSchema),
|
|
31
|
+
options: z.optional(identifyOptionsSchema),
|
|
32
|
+
}),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const legacySystemTrackPayloadSchema = z.pipe(
|
|
36
|
+
z.extend(appEventSystemTrackSchema, {
|
|
37
|
+
kind: z.literal("track"),
|
|
38
|
+
origin: z.optional(z.literal("system")),
|
|
39
|
+
}),
|
|
40
|
+
z.transform(({ origin: _origin, ...rest }) => ({
|
|
41
|
+
...rest,
|
|
42
|
+
origin: "system" as const,
|
|
43
|
+
})),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const customerTrackPayloadSchema = z.extend(appEventCustomerTrackSchema, {
|
|
47
|
+
kind: z.literal("track"),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const trackPayloadSchema = z.union([
|
|
51
|
+
legacySystemTrackPayloadSchema,
|
|
52
|
+
customerTrackPayloadSchema,
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const prefetchPayloadSchema = z.strictObject({
|
|
56
|
+
kind: z.literal("prefetch"),
|
|
57
|
+
flowId: flowIdSchema,
|
|
58
|
+
flowHandleId: z.optional(flowHandleIdSchema),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const openCorePayloadSchema = z.strictObject({
|
|
62
|
+
kind: z.literal("open"),
|
|
63
|
+
flowId: flowIdSchema,
|
|
64
|
+
flowHandleId: z.optional(flowHandleIdSchema),
|
|
65
|
+
metadata: z.optional(responseMetadataInputSchema),
|
|
66
|
+
hideCloseButton: z.optional(z.boolean()),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const prerenderCorePayloadSchema = z.strictObject({
|
|
70
|
+
kind: z.literal("prerender"),
|
|
71
|
+
flowId: flowIdSchema,
|
|
72
|
+
flowHandleId: z.optional(flowHandleIdSchema),
|
|
73
|
+
hideCloseButton: z.optional(z.boolean()),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const closeCorePayloadSchema = z.object({
|
|
77
|
+
kind: z.literal("close"),
|
|
78
|
+
flowHandleId: z.optional(flowHandleIdSchema),
|
|
79
|
+
reasonCode: z.optional(z.enum(["CLOSED", "RESET"])),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const hostContextUpdatedPayloadSchema = z.object({
|
|
83
|
+
kind: z.literal("hostContextUpdated"),
|
|
84
|
+
context: z.object({
|
|
85
|
+
url: z.string().check(z.url()),
|
|
86
|
+
env: z.optional(z.record(z.string(), z.string())),
|
|
87
|
+
storage: z.optional(z.record(z.string(), z.string())),
|
|
88
|
+
page: z.optional(
|
|
89
|
+
z.object({
|
|
90
|
+
path: z.optional(z.string()),
|
|
91
|
+
referrer: z.optional(z.string()),
|
|
92
|
+
search: z.optional(z.string()),
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const hostSignalPayloadSchema = z.object({
|
|
99
|
+
kind: z.literal("hostSignal"),
|
|
100
|
+
name: z.string(),
|
|
101
|
+
data: z.optional(z.unknown()),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const setTargetingPlanPayloadSchema = z.object({
|
|
105
|
+
kind: z.literal("setTargetingPlan"),
|
|
106
|
+
plan: z.object({
|
|
107
|
+
strategy: z.optional(z.enum(["firstMatch"])),
|
|
108
|
+
candidates: z.array(
|
|
109
|
+
z.object({
|
|
110
|
+
action: z.enum(["open", "prefetch"]),
|
|
111
|
+
flowId: flowIdSchema,
|
|
112
|
+
rules: z.array(z.unknown()),
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const telemetryPayloadSchema = z.object({
|
|
119
|
+
kind: z.literal("telemetry"),
|
|
120
|
+
name: z.string(),
|
|
121
|
+
props: z.optional(z.record(z.string(), z.unknown())),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const errorPayloadSchema = z.object({
|
|
125
|
+
kind: z.literal("error"),
|
|
126
|
+
event: ErrorEventSchema,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const configureCorePayloadSchema = z.object({
|
|
130
|
+
kind: z.literal("configure"),
|
|
131
|
+
opts: configureOptionsSchema,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const initCorePayloadSchema = z.strictObject({
|
|
135
|
+
kind: z.literal("init"),
|
|
136
|
+
opts: initOptionsSchema,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const resetPayloadSchema = z.object({
|
|
140
|
+
kind: z.literal("reset"),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const coreCommandPayloadWithoutIdentifySchema = z.discriminatedUnion("kind", [
|
|
144
|
+
openCorePayloadSchema,
|
|
145
|
+
prefetchPayloadSchema,
|
|
146
|
+
prerenderCorePayloadSchema,
|
|
147
|
+
hostContextUpdatedPayloadSchema,
|
|
148
|
+
hostSignalPayloadSchema,
|
|
149
|
+
setTargetingPlanPayloadSchema,
|
|
150
|
+
telemetryPayloadSchema,
|
|
151
|
+
configureCorePayloadSchema,
|
|
152
|
+
initCorePayloadSchema,
|
|
153
|
+
closeCorePayloadSchema,
|
|
154
|
+
resetPayloadSchema,
|
|
155
|
+
errorPayloadSchema,
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
export const coreCommandPayloadSchema = z.union([
|
|
159
|
+
coreCommandPayloadWithoutIdentifySchema,
|
|
160
|
+
identifyPayloadSchema,
|
|
161
|
+
trackPayloadSchema,
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
export type CoreCommandPayload = z.output<typeof coreCommandPayloadSchema>;
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,15 @@ export {
|
|
|
26
26
|
type ClientMeta,
|
|
27
27
|
clientMetaSchema,
|
|
28
28
|
} from "./client-meta.js";
|
|
29
|
+
export {
|
|
30
|
+
type CommandContext,
|
|
31
|
+
type CoreCommandEnvelope,
|
|
32
|
+
coreCommandEnvelopeSchema,
|
|
33
|
+
} from "./core-command-envelope.js";
|
|
34
|
+
export {
|
|
35
|
+
type CoreCommandPayload,
|
|
36
|
+
coreCommandPayloadSchema,
|
|
37
|
+
} from "./core-commands.js";
|
|
29
38
|
export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
|
|
30
39
|
export type { ErrorEvent, ProtocolErrorCode } from "./errors.js";
|
|
31
40
|
export {
|