@getuserfeedback/protocol 0.2.0 → 0.2.2

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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # `@getuserfeedback/protocol`
2
+
3
+ Public contract surface for host integrations that load and control the getuserfeedback widget.
4
+
5
+ ## Lifecycle contract
6
+
7
+ This package defines the public shapes for:
8
+
9
+ - init-time widget configuration
10
+ - post-load widget commands
11
+ - host SDK types and settlement helpers
12
+
13
+ ## What hosts can do after init
14
+
15
+ After the widget has been initialized, a public host integration may:
16
+
17
+ - identify the current user with `identify`
18
+ - update consent with `configure({ consent })`
19
+ - update theme with `configure({ colorScheme })`
20
+ - update auth with `configure({ auth })`
21
+ - open, prefetch, prerender, close, or reset flows
22
+
23
+ ## Identification
24
+
25
+ Public identification is already supported.
26
+
27
+ Use one of these public command shapes:
28
+
29
+ - `{ kind: "identify", userId, traits? }`
30
+ - `{ kind: "identify", traits }`
31
+
32
+ `identify` is a post-init lifecycle operation. The public root contract does not currently accept identity inside `init` or `configure`.
33
+
34
+ ## Navigation updates
35
+
36
+ Explicit public navigation update commands are not part of the current public contract.
37
+
38
+ There is no public `navigate`, `updatePage`, or `hostContextUpdated` command in `@getuserfeedback/protocol`. Hosts should not invent private navigation bridges on top of internal loader or core commands.
39
+
40
+ Loader-driven integrations may still observe browser URL changes internally for targeting and telemetry, but that behavior is internal runtime behavior, not a stable public contract yet.
41
+
42
+ ## GTM and other adapters
43
+
44
+ Adapters built on top of this package should only bridge capabilities that exist in this public contract.
45
+
46
+ - Use `identify` only because it is public and supported.
47
+ - Keep consent and theme updates mapped to `configure`.
48
+ - Do not expose custom navigation-update fields until this package defines a public navigation contract.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",