@getuserfeedback/protocol 0.2.1 → 0.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"command-dispatch.d.ts","sourceRoot":"","sources":["../../src/host/command-dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,oBAAoB,SAAS,MAAM,CAAC,GAC5D,CAAC,SAAS,oBAAoB,GAC7B,CAAC,GACD,KAAK,GACN,KAAK,CAAC;AAET,KAAK,eAAe,GAAG;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,KACvC,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAgBpE,CAAC"}
1
+ {"version":3,"file":"command-dispatch.d.ts","sourceRoot":"","sources":["../../src/host/command-dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,oBAAoB,SAAS,MAAM,CAAC,GAC5D,CAAC,SAAS,oBAAoB,GAC7B,CAAC,GACD,KAAK,GACN,KAAK,CAAC;AAET,KAAK,eAAe,GAAG;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,KACvC,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAapE,CAAC"}
@@ -1,5 +1,5 @@
1
+ import { createCommandEnvelope } from "./command-envelope.js";
1
2
  import { waitForCommandSettlement } from "./command-settlement.js";
2
- import { createCommandRequestId } from "./request-id.js";
3
3
  /**
4
4
  * Creates a dispatch function that wraps a command payload in an envelope,
5
5
  * pushes it into the queue, and returns a promise that settles when the
@@ -15,16 +15,12 @@ import { createCommandRequestId } from "./request-id.js";
15
15
  */
16
16
  export const createCommandDispatch = (push) => {
17
17
  return async (input, options) => {
18
- const requestId = createCommandRequestId();
19
- const idempotencyKey = resolveIdempotencyKey(options?.idempotencyKey);
20
- const envelope = {
21
- version: "1",
22
- requestId,
23
- idempotencyKey: idempotencyKey ?? requestId,
18
+ const envelope = createCommandEnvelope({
24
19
  command: input,
25
- };
20
+ idempotencyKey: resolveIdempotencyKey(options?.idempotencyKey) ?? undefined,
21
+ });
26
22
  push(envelope);
27
- await waitForCommandSettlement({ requestId });
23
+ await waitForCommandSettlement({ requestId: envelope.requestId });
28
24
  };
29
25
  };
30
26
  const resolveIdempotencyKey = (value) => {
@@ -0,0 +1,10 @@
1
+ import type { ClientMeta, CommandEnvelope, PublicCommandPayload } from "./sdk-types.js";
2
+ export type CreateCommandEnvelopeInput = {
3
+ command: PublicCommandPayload;
4
+ requestId?: string | undefined;
5
+ idempotencyKey?: string | undefined;
6
+ instanceId?: string | undefined;
7
+ clientMeta?: ClientMeta | undefined;
8
+ };
9
+ export declare const createCommandEnvelope: (input: CreateCommandEnvelopeInput) => CommandEnvelope;
10
+ //# sourceMappingURL=command-envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-envelope.d.ts","sourceRoot":"","sources":["../../src/host/command-envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,0BAA0B,GAAG;IACxC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACpC,CAAC;AAUF,eAAO,MAAM,qBAAqB,GACjC,OAAO,0BAA0B,KAC/B,eAeF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { createCommandRequestId } from "./request-id.js";
2
+ const normalizeOptionalString = (value) => {
3
+ if (value === undefined) {
4
+ return undefined;
5
+ }
6
+ const normalized = value.trim();
7
+ return normalized.length > 0 ? normalized : undefined;
8
+ };
9
+ export const createCommandEnvelope = (input) => {
10
+ const requestId = normalizeOptionalString(input.requestId) ?? createCommandRequestId();
11
+ const idempotencyKey = normalizeOptionalString(input.idempotencyKey) ?? requestId;
12
+ const instanceId = normalizeOptionalString(input.instanceId);
13
+ return {
14
+ version: "1",
15
+ command: input.command,
16
+ requestId,
17
+ idempotencyKey,
18
+ ...(instanceId !== undefined ? { instanceId } : {}),
19
+ ...(input.clientMeta !== undefined ? { clientMeta: input.clientMeta } : {}),
20
+ };
21
+ };
@@ -2,6 +2,7 @@
2
2
  * Host-page / npm SDK protocol surface (Zod-free).
3
3
  */
4
4
  export * from "./command-dispatch.js";
5
+ export * from "./command-envelope.js";
5
6
  export * from "./command-settlement.js";
6
7
  export * from "./constants.js";
7
8
  export * from "./host-event-contract.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
@@ -2,6 +2,7 @@
2
2
  * Host-page / npm SDK protocol surface (Zod-free).
3
3
  */
4
4
  export * from "./command-dispatch.js";
5
+ export * from "./command-envelope.js";
5
6
  export * from "./command-settlement.js";
6
7
  export * from "./constants.js";
7
8
  export * from "./host-event-contract.js";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
2
2
  export { getScopeMeta, listScopes, SCOPE_IDS, type Scope, scopeIdSchema, } from "./scopes.js";
3
+ export { type FlowVersionResolution, flowVersionResolutionSchema, type ThemeVersionResolution, themeVersionResolutionSchema, } from "./version-resolution.js";
3
4
  export { type PublicCommandPayload, parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
4
5
  export { type ConfigureOptions, colorSchemeConfigInputSchema, configureOptionsSchema, consentConfigInputSchema, type InitOptions, initOptionsSchema, } from "./widget-config.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,sBAAsB,EAC3B,4BAA4B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,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 CHANGED
@@ -1,4 +1,5 @@
1
1
  export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
2
2
  export { getScopeMeta, listScopes, SCOPE_IDS, scopeIdSchema, } from "./scopes.js";
3
+ export { flowVersionResolutionSchema, themeVersionResolutionSchema, } from "./version-resolution.js";
3
4
  export { parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
4
5
  export { colorSchemeConfigInputSchema, configureOptionsSchema, consentConfigInputSchema, initOptionsSchema, } from "./widget-config.js";
@@ -0,0 +1,10 @@
1
+ import * as z from "zod";
2
+ export declare const flowVersionResolutionSchema: z.ZodObject<{
3
+ flowVersionId: z.ZodString;
4
+ }, z.core.$strip>;
5
+ export declare const themeVersionResolutionSchema: z.ZodObject<{
6
+ themeVersionId: z.ZodString;
7
+ }, z.core.$strip>;
8
+ export type FlowVersionResolution = z.output<typeof flowVersionResolutionSchema>;
9
+ export type ThemeVersionResolution = z.output<typeof themeVersionResolutionSchema>;
10
+ //# sourceMappingURL=version-resolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-resolution.d.ts","sourceRoot":"","sources":["../src/version-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAIzB,eAAO,MAAM,2BAA2B;;iBAEtC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;iBAEvC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAC3C,OAAO,2BAA2B,CAClC,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAC5C,OAAO,4BAA4B,CACnC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as z from "zod";
2
+ const versionIdSchema = z.string().trim().min(1);
3
+ export const flowVersionResolutionSchema = z.object({
4
+ flowVersionId: versionIdSchema,
5
+ });
6
+ export const themeVersionResolutionSchema = z.object({
7
+ themeVersionId: versionIdSchema,
8
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",
@@ -60,6 +60,10 @@
60
60
  "./host/lazy-handle-client": {
61
61
  "types": "./dist/host/lazy-handle-client.d.ts",
62
62
  "import": "./dist/host/lazy-handle-client.js"
63
+ },
64
+ "./version-resolution": {
65
+ "types": "./dist/version-resolution.d.ts",
66
+ "import": "./dist/version-resolution.js"
63
67
  }
64
68
  },
65
69
  "scripts": {