@getuserfeedback/protocol 0.5.0 → 0.5.1

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,23 +1,7 @@
1
1
  import * as z from "zod";
2
- export declare const appEventIdentityTypeSchema: z.ZodEnum<{
3
- anonymousId: "anonymousId";
4
- userId: "userId";
5
- "traits.email": "traits.email";
6
- "traits.phone": "traits.phone";
7
- "context.device.id": "context.device.id";
8
- "context.device.advertisingId": "context.device.advertisingId";
9
- "context.device.token": "context.device.token";
10
- }>;
2
+ export { appEventIdentityTypeSchema } from "./identity-type.js";
11
3
  export declare const appEventIdentitySchema: z.ZodObject<{
12
- type: z.ZodEnum<{
13
- anonymousId: "anonymousId";
14
- userId: "userId";
15
- "traits.email": "traits.email";
16
- "traits.phone": "traits.phone";
17
- "context.device.id": "context.device.id";
18
- "context.device.advertisingId": "context.device.advertisingId";
19
- "context.device.token": "context.device.token";
20
- }>;
4
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
21
5
  value: z.ZodString;
22
6
  }, z.core.$strip>;
23
7
  export declare const appEventContextSchema: z.ZodObject<{
@@ -32,15 +16,7 @@ export declare const appEventContextSchema: z.ZodObject<{
32
16
  export declare const appEventBaseSchema: z.ZodObject<{
33
17
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
18
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
35
- type: z.ZodEnum<{
36
- anonymousId: "anonymousId";
37
- userId: "userId";
38
- "traits.email": "traits.email";
39
- "traits.phone": "traits.phone";
40
- "context.device.id": "context.device.id";
41
- "context.device.advertisingId": "context.device.advertisingId";
42
- "context.device.token": "context.device.token";
43
- }>;
19
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
44
20
  value: z.ZodString;
45
21
  }, z.core.$strip>>>;
46
22
  context: z.ZodOptional<z.ZodObject<{
@@ -58,15 +34,7 @@ export declare const appEventBaseSchema: z.ZodObject<{
58
34
  export declare const appEventSurveyViewedSchema: z.ZodObject<{
59
35
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
60
36
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
61
- type: z.ZodEnum<{
62
- anonymousId: "anonymousId";
63
- userId: "userId";
64
- "traits.email": "traits.email";
65
- "traits.phone": "traits.phone";
66
- "context.device.id": "context.device.id";
67
- "context.device.advertisingId": "context.device.advertisingId";
68
- "context.device.token": "context.device.token";
69
- }>;
37
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
70
38
  value: z.ZodString;
71
39
  }, z.core.$strip>>>;
72
40
  context: z.ZodOptional<z.ZodObject<{
@@ -88,15 +56,7 @@ export declare const appEventSurveyViewedSchema: z.ZodObject<{
88
56
  export declare const appEventFlowDismissedSchema: z.ZodObject<{
89
57
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
58
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
91
- type: z.ZodEnum<{
92
- anonymousId: "anonymousId";
93
- userId: "userId";
94
- "traits.email": "traits.email";
95
- "traits.phone": "traits.phone";
96
- "context.device.id": "context.device.id";
97
- "context.device.advertisingId": "context.device.advertisingId";
98
- "context.device.token": "context.device.token";
99
- }>;
59
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
100
60
  value: z.ZodString;
101
61
  }, z.core.$strip>>>;
102
62
  context: z.ZodOptional<z.ZodObject<{
@@ -118,15 +78,7 @@ export declare const appEventFlowDismissedSchema: z.ZodObject<{
118
78
  export declare const appEventTrackSchema: z.ZodObject<{
119
79
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
120
80
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
121
- type: z.ZodEnum<{
122
- anonymousId: "anonymousId";
123
- userId: "userId";
124
- "traits.email": "traits.email";
125
- "traits.phone": "traits.phone";
126
- "context.device.id": "context.device.id";
127
- "context.device.advertisingId": "context.device.advertisingId";
128
- "context.device.token": "context.device.token";
129
- }>;
81
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
130
82
  value: z.ZodString;
131
83
  }, z.core.$strip>>>;
132
84
  context: z.ZodOptional<z.ZodObject<{
@@ -151,15 +103,7 @@ export declare const appEventTrackSchema: z.ZodObject<{
151
103
  export declare const appEventPayloadSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
152
104
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
153
105
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
154
- type: z.ZodEnum<{
155
- anonymousId: "anonymousId";
156
- userId: "userId";
157
- "traits.email": "traits.email";
158
- "traits.phone": "traits.phone";
159
- "context.device.id": "context.device.id";
160
- "context.device.advertisingId": "context.device.advertisingId";
161
- "context.device.token": "context.device.token";
162
- }>;
106
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
163
107
  value: z.ZodString;
164
108
  }, z.core.$strip>>>;
165
109
  context: z.ZodOptional<z.ZodObject<{
@@ -180,15 +124,7 @@ export declare const appEventPayloadSchema: z.ZodDiscriminatedUnion<[z.ZodObject
180
124
  }, z.core.$strip>, z.ZodObject<{
181
125
  traits: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
182
126
  identities: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
- type: z.ZodEnum<{
184
- anonymousId: "anonymousId";
185
- userId: "userId";
186
- "traits.email": "traits.email";
187
- "traits.phone": "traits.phone";
188
- "context.device.id": "context.device.id";
189
- "context.device.advertisingId": "context.device.advertisingId";
190
- "context.device.token": "context.device.token";
191
- }>;
127
+ type: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
192
128
  value: z.ZodString;
193
129
  }, z.core.$strip>>>;
194
130
  context: z.ZodOptional<z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"app-event.d.ts","sourceRoot":"","sources":["../src/app-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,0BAA0B;;;;;;;;EAQrC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;iBAGjC,CAAC;AAQH,eAAO,MAAM,qBAAqB;;;;;;;;iBAIhC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;iBAM7B,CAAC;AAMH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGrC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGtC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAG9B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAGhC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACtE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"app-event.d.ts","sourceRoot":"","sources":["../src/app-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAGzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAQH,eAAO,MAAM,qBAAqB;;;;;;;;iBAIhC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;iBAM7B,CAAC;AAMH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;iBAGrC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;iBAGtC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;iBAG9B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAGhC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACtE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
package/dist/app-event.js CHANGED
@@ -1,13 +1,6 @@
1
1
  import * as z from "zod";
2
- export const appEventIdentityTypeSchema = z.enum([
3
- "anonymousId",
4
- "userId",
5
- "traits.email",
6
- "traits.phone",
7
- "context.device.id",
8
- "context.device.advertisingId",
9
- "context.device.token",
10
- ]);
2
+ import { appEventIdentityTypeSchema } from "./identity-type.js";
3
+ export { appEventIdentityTypeSchema } from "./identity-type.js";
11
4
  export const appEventIdentitySchema = z.object({
12
5
  type: appEventIdentityTypeSchema,
13
6
  value: z.string().trim().min(1),
@@ -0,0 +1,8 @@
1
+ import * as z from "zod";
2
+ export declare const IDENTITY_TYPE_VALUES: readonly ["anonymousId", "userId", "traits.email", "traits.phone", "context.device.id", "context.device.advertisingId", "context.device.token"];
3
+ export type IdentityTypeValue = (typeof IDENTITY_TYPE_VALUES)[number];
4
+ export declare const isIdentityTypeValue: (value: string) => value is IdentityTypeValue;
5
+ export declare const getIdentityTypeSuggestion: (value: string) => IdentityTypeValue | null;
6
+ export declare const buildIdentityTypeGuidanceMessage: (value: string) => string;
7
+ export declare const appEventIdentityTypeSchema: z.ZodPipe<z.ZodString, z.ZodTransform<"anonymousId" | "userId" | "traits.email" | "traits.phone" | "context.device.id" | "context.device.advertisingId" | "context.device.token", string>>;
8
+ //# sourceMappingURL=identity-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-type.d.ts","sourceRoot":"","sources":["../src/identity-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,oBAAoB,iJAQvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAsBtE,eAAO,MAAM,mBAAmB,GAC/B,OAAO,MAAM,KACX,KAAK,IAAI,iBACkD,CAAC;AAK/D,eAAO,MAAM,yBAAyB,GACrC,OAAO,MAAM,KACX,iBAAiB,GAAG,IACuD,CAAC;AAE/E,eAAO,MAAM,gCAAgC,GAAI,OAAO,MAAM,KAAG,MAehE,CAAC;AAEF,eAAO,MAAM,0BAA0B,4LAqBpC,CAAC"}
@@ -0,0 +1,59 @@
1
+ import * as z from "zod";
2
+ export const IDENTITY_TYPE_VALUES = [
3
+ "anonymousId",
4
+ "userId",
5
+ "traits.email",
6
+ "traits.phone",
7
+ "context.device.id",
8
+ "context.device.advertisingId",
9
+ "context.device.token",
10
+ ];
11
+ const IDENTITY_TYPE_ALIAS_SUGGESTIONS = {
12
+ advertising_id: "context.device.advertisingId",
13
+ anonymous_id: "anonymousId",
14
+ device_id: "context.device.id",
15
+ device_token: "context.device.token",
16
+ email: "traits.email",
17
+ phone: "traits.phone",
18
+ phone_number: "traits.phone",
19
+ user_id: "userId",
20
+ };
21
+ const COMMON_IDENTITY_TYPE_MAPPINGS = [
22
+ ["email", "traits.email"],
23
+ ["phone", "traits.phone"],
24
+ ["user_id", "userId"],
25
+ ];
26
+ const normalizeIdentityTypeAliasKey = (value) => value.trim().toLowerCase().replace(/-/g, "_");
27
+ export const isIdentityTypeValue = (value) => IDENTITY_TYPE_VALUES.some((candidate) => candidate === value);
28
+ const parseIdentityTypeValue = (value) => isIdentityTypeValue(value) ? value : null;
29
+ export const getIdentityTypeSuggestion = (value) => IDENTITY_TYPE_ALIAS_SUGGESTIONS[normalizeIdentityTypeAliasKey(value)] ?? null;
30
+ export const buildIdentityTypeGuidanceMessage = (value) => {
31
+ const normalizedValue = value.trim();
32
+ const displayValue = normalizedValue.length > 0 ? `"${normalizedValue}"` : "that value";
33
+ const suggestion = getIdentityTypeSuggestion(value);
34
+ if (suggestion) {
35
+ return `Unsupported identity type ${displayValue}. Use "${suggestion}" instead.`;
36
+ }
37
+ const mappingExamples = COMMON_IDENTITY_TYPE_MAPPINGS.map(([from, to]) => `${from} -> ${to}`).join(", ");
38
+ return `Unsupported identity type ${displayValue}. Use one of: ${IDENTITY_TYPE_VALUES.join(", ")}. Common mappings: ${mappingExamples}.`;
39
+ };
40
+ export const appEventIdentityTypeSchema = z
41
+ .string()
42
+ .trim()
43
+ .min(1, "Identity type is required.")
44
+ .superRefine((value, ctx) => {
45
+ if (!isIdentityTypeValue(value)) {
46
+ ctx.addIssue({
47
+ code: "custom",
48
+ fatal: true,
49
+ message: buildIdentityTypeGuidanceMessage(value),
50
+ });
51
+ }
52
+ })
53
+ .transform((value) => {
54
+ const parsed = parseIdentityTypeValue(value);
55
+ if (parsed === null) {
56
+ throw new Error(`Identity type should have been validated before transform: ${value}`);
57
+ }
58
+ return parsed;
59
+ });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { type AppEventPayload, type AppEventTrackInput, appEventBaseSchema, appEventContextSchema, appEventFlowDismissedSchema, appEventIdentitySchema, appEventIdentityTypeSchema, appEventPayloadSchema, appEventSurveyViewedSchema, appEventTrackSchema, } from "./app-event.js";
2
2
  export { type ClientMeta, clientMetaSchema, } from "./client-meta.js";
3
3
  export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
4
+ export { buildIdentityTypeGuidanceMessage, getIdentityTypeSuggestion, IDENTITY_TYPE_VALUES, type IdentityTypeValue, isIdentityTypeValue, } from "./identity-type.js";
4
5
  export { getScopeMeta, isScope, listScopes, SCOPE_IDS, type Scope, scopeIdSchema, } from "./scopes.js";
5
6
  export { type FlowVersionResolution, flowVersionResolutionSchema, type ThemeVersionResolution, themeVersionResolutionSchema, } from "./version-resolution.js";
6
7
  export { type PublicCommandPayload, parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,KAAK,UAAU,EACf,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,sCAAsC,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACN,YAAY,EACZ,OAAO,EACP,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,0B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,gBAAgB,EACrB,wBAAwB,GACxB,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { appEventBaseSchema, appEventContextSchema, appEventFlowDismissedSchema, appEventIdentitySchema, appEventIdentityTypeSchema, appEventPayloadSchema, appEventSurveyViewedSchema, appEventTrackSchema, } from "./app-event.js";
2
2
  export { clientMetaSchema, } from "./client-meta.js";
3
3
  export { DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS } from "./defaults.js";
4
+ export { buildIdentityTypeGuidanceMessage, getIdentityTypeSuggestion, IDENTITY_TYPE_VALUES, isIdentityTypeValue, } from "./identity-type.js";
4
5
  export { getScopeMeta, isScope, listScopes, SCOPE_IDS, scopeIdSchema, } from "./scopes.js";
5
6
  export { flowVersionResolutionSchema, themeVersionResolutionSchema, } from "./version-resolution.js";
6
7
  export { parseConfigureOptions, parseInitOptions, parsePublicCommand, publicCommandPayloadSchema, } from "./widget-commands.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/protocol",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "getuserfeedback widget protocol — host surface and (later) wire protocol",
5
5
  "keywords": [
6
6
  "getuserfeedback",