@getuserfeedback/protocol 2.2.0 → 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/app-event.d.ts +1 -1
- package/dist/app-event.d.ts.map +1 -1
- package/dist/app-event.js +1 -0
- package/dist/command-kinds.d.ts +53 -0
- package/dist/command-kinds.d.ts.map +1 -0
- package/dist/command-kinds.js +37 -0
- 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/flow-assignments.d.ts +0 -18
- package/dist/flow-assignments.d.ts.map +1 -1
- package/dist/flow-assignments.js +0 -3
- package/dist/flow-display.d.ts +0 -3
- package/dist/flow-display.d.ts.map +1 -1
- package/dist/host/command-envelope-schema.d.ts +12 -12
- package/dist/host/host-event-contract.d.ts +16 -0
- package/dist/host/host-event-contract.d.ts.map +1 -1
- package/dist/host/host-event-contract.js +16 -0
- package/dist/host/host-event-schemas.d.ts +138 -0
- package/dist/host/host-event-schemas.d.ts.map +1 -0
- package/dist/host/host-event-schemas.js +94 -0
- 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 +12 -12
- package/dist/widget-config.d.ts +15 -15
- package/package.json +7 -2
- package/src/app-event.ts +1 -0
- package/src/command-kinds.ts +42 -0
- package/src/core-command-envelope.ts +27 -0
- package/src/core-commands.ts +164 -0
- package/src/flow-assignments.ts +0 -3
- package/src/host/host-event-contract.ts +31 -0
- package/src/host/host-event-schemas.ts +135 -0
- package/src/index.ts +9 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas that validate the host event detail contract.
|
|
3
|
+
* Paired with host-event-contract.ts, which defines the types and lightweight guards.
|
|
4
|
+
*/
|
|
5
|
+
import * as z from "zod/mini";
|
|
6
|
+
import { allCommandKindSchema } from "../command-kinds.js";
|
|
7
|
+
import {
|
|
8
|
+
HANDLE_INVALIDATED_REASON_CODES,
|
|
9
|
+
HANDLE_INVALIDATED_SOURCES,
|
|
10
|
+
} from "./host-event-contract.js";
|
|
11
|
+
|
|
12
|
+
const nonEmptyStringSchema = z.string().check(z.trim(), z.minLength(1));
|
|
13
|
+
|
|
14
|
+
const commandErrorSchema = z.strictObject({
|
|
15
|
+
message: nonEmptyStringSchema,
|
|
16
|
+
code: z.optional(nonEmptyStringSchema),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const commandSettledDetailBase = {
|
|
20
|
+
requestId: nonEmptyStringSchema,
|
|
21
|
+
instanceId: z.nullable(nonEmptyStringSchema),
|
|
22
|
+
kind: allCommandKindSchema,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Canonical shape when a command (open, prerender, prefetch) settles and core
|
|
27
|
+
* has allocated a flow handle. flowRunId is present for open/prerender, absent for prefetch.
|
|
28
|
+
*/
|
|
29
|
+
export const flowHandleSettlementResultSchema = z.strictObject({
|
|
30
|
+
flowHandleId: nonEmptyStringSchema,
|
|
31
|
+
flowRunId: z.optional(nonEmptyStringSchema),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type FlowHandleSettlementResult = z.output<
|
|
35
|
+
typeof flowHandleSettlementResultSchema
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
const commandSettledSuccessDetailSchema = z.strictObject({
|
|
39
|
+
...commandSettledDetailBase,
|
|
40
|
+
ok: z.literal(true),
|
|
41
|
+
result: z.optional(z.unknown()),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const commandSettledFailureDetailSchema = z.strictObject({
|
|
45
|
+
...commandSettledDetailBase,
|
|
46
|
+
ok: z.literal(false),
|
|
47
|
+
error: commandErrorSchema,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const commandSettledDetailSchema = z.discriminatedUnion("ok", [
|
|
51
|
+
commandSettledSuccessDetailSchema,
|
|
52
|
+
commandSettledFailureDetailSchema,
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
export type { CommandSettledDetail } from "./host-event-contract.js";
|
|
56
|
+
|
|
57
|
+
const flowStateChangedBase = {
|
|
58
|
+
instanceId: nonEmptyStringSchema,
|
|
59
|
+
isOpen: z.boolean(),
|
|
60
|
+
isLoading: z.boolean(),
|
|
61
|
+
width: z.optional(z.number()),
|
|
62
|
+
height: z.optional(z.number()),
|
|
63
|
+
} as const;
|
|
64
|
+
|
|
65
|
+
export const flowStateChangedDetailSchema = z.strictObject({
|
|
66
|
+
...flowStateChangedBase,
|
|
67
|
+
flowHandleId: nonEmptyStringSchema,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export type { FlowStateChangedDetail } from "./host-event-contract.js";
|
|
71
|
+
|
|
72
|
+
export const instanceFlowStateChangedDetailSchema = z.strictObject({
|
|
73
|
+
...flowStateChangedBase,
|
|
74
|
+
flowHandleId: z.optional(nonEmptyStringSchema),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export type { InstanceFlowStateChangedDetail } from "./host-event-contract.js";
|
|
78
|
+
|
|
79
|
+
export const openRequestedDetailSchema = z.strictObject({
|
|
80
|
+
instanceId: nonEmptyStringSchema,
|
|
81
|
+
source: z.enum(["command", "targeting"]),
|
|
82
|
+
flowId: nonEmptyStringSchema,
|
|
83
|
+
flowHandleId: z.optional(nonEmptyStringSchema),
|
|
84
|
+
hideCloseButton: z.optional(z.boolean()),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export type { OpenRequestedDetail } from "./host-event-contract.js";
|
|
88
|
+
|
|
89
|
+
export const handleInvalidatedDetailSchema = z.strictObject({
|
|
90
|
+
instanceId: nonEmptyStringSchema,
|
|
91
|
+
handleKind: nonEmptyStringSchema,
|
|
92
|
+
handleId: nonEmptyStringSchema,
|
|
93
|
+
reasonCode: z.enum(HANDLE_INVALIDATED_REASON_CODES),
|
|
94
|
+
reasonMessage: z.optional(nonEmptyStringSchema),
|
|
95
|
+
relatedRequestId: z.optional(nonEmptyStringSchema),
|
|
96
|
+
source: z.enum(HANDLE_INVALIDATED_SOURCES),
|
|
97
|
+
at: z.number(),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export type { HandleInvalidatedDetail } from "./host-event-contract.js";
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Parse unknown result into FlowHandleSettlementResult. Returns null if invalid.
|
|
104
|
+
*/
|
|
105
|
+
export function parseFlowHandleSettlementResult(
|
|
106
|
+
result: unknown,
|
|
107
|
+
): FlowHandleSettlementResult | null {
|
|
108
|
+
const parsed = flowHandleSettlementResultSchema.safeParse(result);
|
|
109
|
+
return parsed.success ? parsed.data : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Extract flow handle from a successful command settlement when the command
|
|
114
|
+
* is one that can return a handle (open, prerender, prefetch). Returns null
|
|
115
|
+
* if detail is not ok, kind is not one of those, or result does not match
|
|
116
|
+
* flowHandleSettlementResultSchema.
|
|
117
|
+
*/
|
|
118
|
+
export function getFlowHandleFromSettlementDetail(detail: {
|
|
119
|
+
ok: boolean;
|
|
120
|
+
kind: string;
|
|
121
|
+
result?: unknown;
|
|
122
|
+
}): FlowHandleSettlementResult | null {
|
|
123
|
+
if (
|
|
124
|
+
!detail.ok ||
|
|
125
|
+
(detail.kind !== "open" &&
|
|
126
|
+
detail.kind !== "prerender" &&
|
|
127
|
+
detail.kind !== "prefetch")
|
|
128
|
+
) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return parseFlowHandleSettlementResult(detail.result);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type { FlowHandleAllocationFromSettlement } from "./host-event-contract.js";
|
|
135
|
+
export { getFlowHandleAllocationFromSettlement } from "./host-event-contract.js";
|
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 {
|