@kubuild/schema 0.6.0 → 0.7.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.
package/dist/index.js CHANGED
@@ -16,69 +16,51 @@ var TrackingProviderTypeSchema = z.enum([
16
16
  var TrackingDeliverySchema = z.enum(["both", "client_only", "server_only"]);
17
17
  var MetaTrackingProviderConfigSchema = z.object({
18
18
  enabled: z.boolean().default(true),
19
- /** Optional linked account/workspace credential ID */
19
+ /** Host credential id; the server resolves the CAPI access token from it. */
20
20
  credentialId: z.string().optional(),
21
- /** Meta Pixel ID (e.g. 123456789012345) */
21
+ /** Meta Pixel ID (e.g. 123456789012345) — public */
22
22
  pixelId: z.string().optional().default(""),
23
- /** Enable Server-Side Conversions API */
23
+ /** Enable Server-Side Conversions API (delivered through the host relay) */
24
24
  capiEnabled: z.boolean().optional().default(false),
25
- /**
26
- * System User Access Token for Meta Graph API.
27
- * Note: For security in production, prefer configuring tokens on your server backend
28
- * or proxying via `serverRelayUrl`.
29
- */
30
- capiAccessToken: z.string().optional().default(""),
31
- /** Test Event Code from Meta Events Manager (e.g. "TEST12345") */
32
- testEventCode: z.string().optional().default(""),
33
- /**
34
- * Host Server Relay URL (e.g. "/api/tracking/meta").
35
- * Recommended for browser clients to post CAPI events safely without exposing the secret token.
36
- */
37
- serverRelayUrl: z.string().optional().default("")
25
+ /** Test Event Code from Meta Events Manager (e.g. "TEST12345") — not a secret */
26
+ testEventCode: z.string().optional().default("")
38
27
  });
39
28
  var GoogleTrackingProviderConfigSchema = z.object({
40
29
  enabled: z.boolean().default(true),
41
- /** Optional linked account/workspace credential ID */
30
+ /** Host credential id; the server resolves the Measurement Protocol API secret from it. */
42
31
  credentialId: z.string().optional(),
43
- /** GA4 Measurement ID (e.g. "G-XXXXXXXXXX") */
44
- measurementId: z.string().optional().default(""),
45
- /** GA4 Measurement Protocol API Secret (for server-side events) */
46
- measurementProtocolSecret: z.string().optional().default(""),
47
- /** Host Server Relay URL (e.g. "/api/tracking/ga4") */
48
- serverRelayUrl: z.string().optional().default("")
32
+ /** GA4 Measurement ID (e.g. "G-XXXXXXXXXX") — public */
33
+ measurementId: z.string().optional().default("")
49
34
  });
50
35
  var GtmTrackingProviderConfigSchema = z.object({
51
36
  enabled: z.boolean().default(true),
52
37
  /** Optional linked account/workspace credential ID */
53
38
  credentialId: z.string().optional(),
54
- /** GTM Container ID (e.g. "GTM-XXXXXXX") */
55
- containerId: z.string().optional().default(""),
56
- /** Host Server Relay URL */
57
- serverRelayUrl: z.string().optional().default("")
39
+ /** GTM Container ID (e.g. "GTM-XXXXXXX") — public */
40
+ containerId: z.string().optional().default("")
58
41
  });
59
42
  var TikTokTrackingProviderConfigSchema = z.object({
60
43
  enabled: z.boolean().default(true),
61
- /** Optional linked account/workspace credential ID */
44
+ /** Host credential id; the server resolves the Events API access token from it. */
62
45
  credentialId: z.string().optional(),
63
- /** TikTok Pixel ID (e.g. "C1234567890") */
46
+ /** TikTok Pixel ID (e.g. "C1234567890") — public */
64
47
  pixelId: z.string().optional().default(""),
65
- /** Enable TikTok Events API (server-side) */
48
+ /** Enable TikTok Events API (server-side, delivered through the host relay) */
66
49
  eventsApiEnabled: z.boolean().optional().default(false),
67
- /** Long-term Access Token for TikTok Events API */
68
- accessToken: z.string().optional().default(""),
69
- /** Test Event Code from TikTok Event Manager */
70
- testEventCode: z.string().optional().default(""),
71
- /** Host Server Relay URL (e.g. "/api/tracking/tiktok") */
72
- serverRelayUrl: z.string().optional().default("")
50
+ /** Test Event Code from TikTok Event Manager — not a secret */
51
+ testEventCode: z.string().optional().default("")
73
52
  });
74
53
  var CustomTrackingProviderConfigSchema = z.object({
75
54
  enabled: z.boolean().default(true),
76
- /** Optional linked account/workspace credential ID */
77
- credentialId: z.string().optional(),
78
- /** Custom Webhook endpoint URL */
79
- endpointUrl: z.string().optional().default(""),
80
- /** Optional headers sent with the webhook POST request */
81
- headers: z.record(z.string(), z.string()).optional().default({})
55
+ /** Host credential id; the server resolves the webhook `endpointUrl` + `headers` from it. */
56
+ credentialId: z.string().optional()
57
+ });
58
+ var LEGACY_TRACKING_SECRET_KEYS = Object.freeze({
59
+ meta: ["capiAccessToken", "serverRelayUrl"],
60
+ google: ["measurementProtocolSecret", "serverRelayUrl"],
61
+ gtm: ["serverRelayUrl"],
62
+ tiktok: ["accessToken", "serverRelayUrl"],
63
+ custom: ["endpointUrl", "headers"]
82
64
  });
83
65
  var TrackingConfigSchema = z.object({
84
66
  /** Master toggle: dynamically enables or disables all tracking operations */
@@ -98,6 +80,22 @@ var TrackingConfigSchema = z.object({
98
80
  custom: CustomTrackingProviderConfigSchema.optional()
99
81
  }).optional().default({})
100
82
  });
83
+ var MetaTrackingSecretsSchema = z.object({
84
+ /** System User access token for the Meta Graph API. */
85
+ capiAccessToken: z.string().min(1)
86
+ });
87
+ var GoogleTrackingSecretsSchema = z.object({
88
+ /** Measurement Protocol `api_secret`. */
89
+ measurementProtocolSecret: z.string().min(1)
90
+ });
91
+ var TikTokTrackingSecretsSchema = z.object({
92
+ /** Long-term Events API access token. */
93
+ accessToken: z.string().min(1)
94
+ });
95
+ var CustomTrackingSecretsSchema = z.object({
96
+ endpointUrl: z.string().url(),
97
+ headers: z.record(z.string(), z.string()).optional()
98
+ });
101
99
  var StandardTrackingEventSchema = z.enum([
102
100
  "PageView",
103
101
  "ViewContent",
@@ -112,13 +110,17 @@ var StandardTrackingEventSchema = z.enum([
112
110
  "SubmitApplication",
113
111
  "Schedule"
114
112
  ]);
113
+ var TrackEventProviderSchema = z.enum(["all", "meta", "google", "gtm", "tiktok", "custom"]);
115
114
  var TrackEventStepPayloadSchema = z.object({
116
115
  /** Event name: e.g. "Purchase", "Lead", or custom string */
117
116
  eventName: z.string().min(1, "Event name cannot be empty"),
118
117
  /** Standard event vs custom event identifier */
119
118
  eventType: z.enum(["standard", "custom"]).optional().default("standard"),
120
- /** Target provider: 'all' or a specific provider */
121
- provider: z.enum(["all", "meta", "google", "tiktok", "custom"]).optional().default("all"),
119
+ /**
120
+ * Target provider: 'all' or a specific provider.
121
+ * 'gtm' pushes the event to `window.dataLayer` (client-side only).
122
+ */
123
+ provider: TrackEventProviderSchema.optional().default("all"),
122
124
  /** Delivery channel: 'both', 'client_only', or 'server_only' */
123
125
  delivery: TrackingDeliverySchema.optional().default("both"),
124
126
  /**
@@ -140,12 +142,66 @@ var TrackEventStepPayloadSchema = z.object({
140
142
  /** Step-level active toggle */
141
143
  enabled: z.boolean().optional().default(true)
142
144
  });
145
+ var TRACKING_RELAY_PROTOCOL_VERSION = 1;
146
+ var ServerTrackingEventSchema = z.object({
147
+ eventName: z.string().min(1).max(256),
148
+ eventType: z.enum(["standard", "custom"]).optional(),
149
+ eventId: z.string().max(256).optional(),
150
+ /** Unix epoch seconds. */
151
+ eventTime: z.number().int().nonnegative().optional(),
152
+ eventSourceUrl: z.string().max(4096).optional(),
153
+ actionSource: z.enum(["website", "app", "system_generated"]).optional(),
154
+ params: z.record(z.string(), z.unknown()).optional(),
155
+ /** Raw (unhashed) user data; the relay hashes PII per provider spec before forwarding. */
156
+ userData: z.record(z.string(), z.unknown()).optional(),
157
+ customData: z.record(z.string(), z.unknown()).optional()
158
+ });
159
+ var TrackingRelayRequestSchema = z.object({
160
+ version: z.literal(TRACKING_RELAY_PROTOCOL_VERSION),
161
+ event: ServerTrackingEventSchema,
162
+ provider: TrackEventProviderSchema.optional().default("all"),
163
+ /** Optional hint only; the relay uses the credentialId from its trusted config. */
164
+ credentialId: z.string().max(256).optional(),
165
+ /** Host document/page id so the relay can look up the trusted tracking config. */
166
+ documentId: z.string().max(256).optional()
167
+ });
168
+ var TrackingRelayProviderResultSchema = z.object({
169
+ provider: z.string(),
170
+ success: z.boolean(),
171
+ status: z.number().int().optional(),
172
+ skipped: z.boolean().optional(),
173
+ reason: z.string().optional(),
174
+ error: z.string().optional()
175
+ });
176
+ var TrackingRelayErrorCodeSchema = z.enum([
177
+ "INVALID_REQUEST",
178
+ "UNSUPPORTED_VERSION",
179
+ "FORBIDDEN_ORIGIN",
180
+ "METHOD_NOT_ALLOWED",
181
+ "CONFIG_NOT_FOUND",
182
+ "INTERNAL_ERROR"
183
+ ]);
184
+ var TrackingRelayResponseSchema = z.object({
185
+ version: z.literal(TRACKING_RELAY_PROTOCOL_VERSION),
186
+ success: z.boolean(),
187
+ eventId: z.string().optional(),
188
+ skipped: z.boolean().optional(),
189
+ reason: z.string().optional(),
190
+ results: z.record(z.string(), TrackingRelayProviderResultSchema).optional(),
191
+ error: z.object({
192
+ code: TrackingRelayErrorCodeSchema,
193
+ message: z.string()
194
+ }).optional()
195
+ });
143
196
  function isTrackingConfig(value) {
144
197
  return TrackingConfigSchema.safeParse(value).success;
145
198
  }
146
199
  function isTrackEventStepPayload(value) {
147
200
  return TrackEventStepPayloadSchema.safeParse(value).success;
148
201
  }
202
+ function isTrackingRelayRequest(value) {
203
+ return TrackingRelayRequestSchema.safeParse(value).success;
204
+ }
149
205
 
150
206
  // src/actions.ts
151
207
  var ActionTriggerTypeSchema = z2.enum([
@@ -165,6 +221,7 @@ var ActionStepTypeSchema = z2.enum([
165
221
  "show_toast",
166
222
  "open_modal",
167
223
  "close_modal",
224
+ "toggle_modal",
168
225
  "copy_clipboard",
169
226
  "custom_event",
170
227
  "track_event"
@@ -247,6 +304,19 @@ var CloseModalStepPayloadSchema = z2.object({
247
304
  modalId: z2.string().optional(),
248
305
  modalNodeId: z2.string().optional()
249
306
  });
307
+ var ToggleModalStepPayloadSchema = z2.object({
308
+ modalId: z2.string().optional(),
309
+ modalNodeId: z2.string().optional(),
310
+ targetNodeId: z2.string().optional(),
311
+ nodeId: z2.string().optional()
312
+ }).refine(
313
+ (data) => [data.modalId, data.modalNodeId, data.targetNodeId, data.nodeId].some(
314
+ (id) => typeof id === "string" && id.trim().length > 0
315
+ ),
316
+ {
317
+ message: "Modal ID or Modal Node ID cannot be empty"
318
+ }
319
+ );
250
320
  var CopyClipboardStepPayloadSchema = z2.object({
251
321
  text: z2.string().optional(),
252
322
  value: z2.unknown().optional(),
@@ -267,6 +337,7 @@ var StepPayloadSchemas = {
267
337
  show_toast: ShowToastStepPayloadSchema,
268
338
  open_modal: OpenModalStepPayloadSchema,
269
339
  close_modal: CloseModalStepPayloadSchema,
340
+ toggle_modal: ToggleModalStepPayloadSchema,
270
341
  copy_clipboard: CopyClipboardStepPayloadSchema,
271
342
  custom_event: CustomEventStepPayloadSchema,
272
343
  track_event: TrackEventStepPayloadSchema
@@ -461,7 +532,7 @@ function isFormConfig(value) {
461
532
 
462
533
  // src/document.ts
463
534
  var SCHEMA_NAME = "stora.page";
464
- var CURRENT_SCHEMA_VERSION = "1.0.0";
535
+ var CURRENT_SCHEMA_VERSION = "1.1.0";
465
536
  var AssetReferenceSchema = z4.object({
466
537
  type: z4.literal("asset"),
467
538
  assetId: z4.string().min(1, "Asset ID cannot be empty"),
@@ -741,7 +812,7 @@ function isSafeThumbnail(value) {
741
812
  // src/fixtures/starter-page.json
742
813
  var starter_page_default = {
743
814
  schema: "stora.page",
744
- version: "1.0.0",
815
+ version: "1.1.0",
745
816
  metadata: {
746
817
  title: "Welcome to KUBUILD",
747
818
  description: "A starter template built with KUBUILD portable web builder",
@@ -900,6 +971,7 @@ var starter_page_default = {
900
971
  var starterPageFixture = starter_page_default;
901
972
 
902
973
  // src/json-schema.ts
974
+ import { z as z7 } from "zod";
903
975
  var PAGE_DOCUMENT_JSON_SCHEMA_V1 = {
904
976
  $schema: "http://json-schema.org/draft-07/schema#",
905
977
  $id: "https://schema.stora.page/v1/page.json",
@@ -918,16 +990,84 @@ var PAGE_DOCUMENT_JSON_SCHEMA_V1 = {
918
990
  type: "string",
919
991
  pattern: "^\\d+(\\.\\d+)*$",
920
992
  description: "Schema version of the document",
921
- default: "1.0.0"
993
+ default: "1.1.0"
922
994
  },
923
995
  metadata: {
924
996
  $ref: "#/definitions/documentMetadata"
925
997
  },
926
998
  document: {
927
999
  $ref: "#/definitions/rootPageNode"
1000
+ },
1001
+ tracking: {
1002
+ $ref: "#/definitions/trackingConfig"
928
1003
  }
929
1004
  },
930
1005
  definitions: {
1006
+ trackingConfig: {
1007
+ type: "object",
1008
+ description: "Tracking configuration. Contains only public ids, flags and opaque credential ids \u2014 secrets are host-owned.",
1009
+ properties: {
1010
+ enabled: { type: "boolean", default: true },
1011
+ debugMode: { type: "boolean", default: false },
1012
+ autoPageView: { type: "boolean", default: true },
1013
+ defaultDelivery: { type: "string", enum: ["both", "client_only", "server_only"], default: "both" },
1014
+ providers: {
1015
+ type: "object",
1016
+ properties: {
1017
+ meta: {
1018
+ type: "object",
1019
+ properties: {
1020
+ enabled: { type: "boolean" },
1021
+ credentialId: { type: "string" },
1022
+ pixelId: { type: "string" },
1023
+ capiEnabled: { type: "boolean" },
1024
+ testEventCode: { type: "string" }
1025
+ },
1026
+ additionalProperties: false
1027
+ },
1028
+ google: {
1029
+ type: "object",
1030
+ properties: {
1031
+ enabled: { type: "boolean" },
1032
+ credentialId: { type: "string" },
1033
+ measurementId: { type: "string" }
1034
+ },
1035
+ additionalProperties: false
1036
+ },
1037
+ gtm: {
1038
+ type: "object",
1039
+ properties: {
1040
+ enabled: { type: "boolean" },
1041
+ credentialId: { type: "string" },
1042
+ containerId: { type: "string" }
1043
+ },
1044
+ additionalProperties: false
1045
+ },
1046
+ tiktok: {
1047
+ type: "object",
1048
+ properties: {
1049
+ enabled: { type: "boolean" },
1050
+ credentialId: { type: "string" },
1051
+ pixelId: { type: "string" },
1052
+ eventsApiEnabled: { type: "boolean" },
1053
+ testEventCode: { type: "string" }
1054
+ },
1055
+ additionalProperties: false
1056
+ },
1057
+ custom: {
1058
+ type: "object",
1059
+ properties: {
1060
+ enabled: { type: "boolean" },
1061
+ credentialId: { type: "string" }
1062
+ },
1063
+ additionalProperties: false
1064
+ }
1065
+ },
1066
+ additionalProperties: false
1067
+ }
1068
+ },
1069
+ additionalProperties: false
1070
+ },
931
1071
  styleValue: {
932
1072
  type: ["string", "number", "boolean", "null"],
933
1073
  description: "A CSS property or design token value"
@@ -1067,8 +1207,10 @@ var PAGE_DOCUMENT_JSON_SCHEMA_V1 = {
1067
1207
  "show_toast",
1068
1208
  "open_modal",
1069
1209
  "close_modal",
1210
+ "toggle_modal",
1070
1211
  "copy_clipboard",
1071
- "custom_event"
1212
+ "custom_event",
1213
+ "track_event"
1072
1214
  ]
1073
1215
  },
1074
1216
  label: { type: "string" },
@@ -1589,8 +1731,10 @@ var ACTION_PIPELINE_JSON_SCHEMA_V1 = {
1589
1731
  "show_toast",
1590
1732
  "open_modal",
1591
1733
  "close_modal",
1734
+ "toggle_modal",
1592
1735
  "copy_clipboard",
1593
- "custom_event"
1736
+ "custom_event",
1737
+ "track_event"
1594
1738
  ]
1595
1739
  },
1596
1740
  label: { type: "string" },
@@ -1757,6 +1901,48 @@ var FORM_FIELD_BINDING_JSON_SCHEMA_V1 = {
1757
1901
  function getFormFieldBindingJsonSchema() {
1758
1902
  return FORM_FIELD_BINDING_JSON_SCHEMA_V1;
1759
1903
  }
1904
+ function toDraft7(schema, id, title, io) {
1905
+ return {
1906
+ ...z7.toJSONSchema(schema, { target: "draft-7", io }),
1907
+ $id: id,
1908
+ title
1909
+ };
1910
+ }
1911
+ var trackingRelayRequestJsonSchema;
1912
+ var trackingRelayResponseJsonSchema;
1913
+ var trackingProviderSecretsJsonSchema;
1914
+ function getTrackingRelayRequestJsonSchema() {
1915
+ trackingRelayRequestJsonSchema ??= toDraft7(
1916
+ TrackingRelayRequestSchema,
1917
+ "https://schema.stora.page/v1/tracking-relay-request.json",
1918
+ "StoraTrackingRelayRequest",
1919
+ "input"
1920
+ );
1921
+ return trackingRelayRequestJsonSchema;
1922
+ }
1923
+ function getTrackingRelayResponseJsonSchema() {
1924
+ trackingRelayResponseJsonSchema ??= toDraft7(
1925
+ TrackingRelayResponseSchema,
1926
+ "https://schema.stora.page/v1/tracking-relay-response.json",
1927
+ "StoraTrackingRelayResponse",
1928
+ "output"
1929
+ );
1930
+ return trackingRelayResponseJsonSchema;
1931
+ }
1932
+ function getTrackingProviderSecretsJsonSchema() {
1933
+ trackingProviderSecretsJsonSchema ??= toDraft7(
1934
+ z7.object({
1935
+ meta: MetaTrackingSecretsSchema.optional(),
1936
+ google: GoogleTrackingSecretsSchema.optional(),
1937
+ tiktok: TikTokTrackingSecretsSchema.optional(),
1938
+ custom: CustomTrackingSecretsSchema.optional()
1939
+ }),
1940
+ "https://schema.stora.page/v1/tracking-provider-secrets.json",
1941
+ "StoraTrackingProviderSecrets",
1942
+ "input"
1943
+ );
1944
+ return trackingProviderSecretsJsonSchema;
1945
+ }
1760
1946
  export {
1761
1947
  ACTION_PIPELINE_JSON_SCHEMA_V1,
1762
1948
  ARTBOARD_REFERENCE_NODE_TYPE,
@@ -1779,6 +1965,7 @@ export {
1779
1965
  CopyClipboardStepPayloadSchema,
1780
1966
  CustomEventStepPayloadSchema,
1781
1967
  CustomTrackingProviderConfigSchema,
1968
+ CustomTrackingSecretsSchema,
1782
1969
  DEFAULT_ANIMATION_CONFIG,
1783
1970
  DocumentMetadataSchema,
1784
1971
  FORM_CONFIG_JSON_SCHEMA_V1,
@@ -1786,11 +1973,14 @@ export {
1786
1973
  FormConfigSchema,
1787
1974
  FormFieldBindingSchema,
1788
1975
  GoogleTrackingProviderConfigSchema,
1976
+ GoogleTrackingSecretsSchema,
1789
1977
  GtmTrackingProviderConfigSchema,
1978
+ LEGACY_TRACKING_SECRET_KEYS,
1790
1979
  MANIFEST_JSON_SCHEMA_V1,
1791
1980
  ManifestAssetItemSchema,
1792
1981
  ManifestSchema,
1793
1982
  MetaTrackingProviderConfigSchema,
1983
+ MetaTrackingSecretsSchema,
1794
1984
  NavigateStepPayloadSchema,
1795
1985
  NodeSchema,
1796
1986
  OpenModalStepPayloadSchema,
@@ -1806,6 +1996,7 @@ export {
1806
1996
  SafeThumbnailObjectSchema,
1807
1997
  SafeThumbnailSchema,
1808
1998
  SafeThumbnailUrlSchema,
1999
+ ServerTrackingEventSchema,
1809
2000
  SetStateStepPayloadSchema,
1810
2001
  ShowToastStepPayloadSchema,
1811
2002
  StandardTrackingEventSchema,
@@ -1813,14 +2004,22 @@ export {
1813
2004
  StyleDefinitionSchema,
1814
2005
  StyleValueSchema,
1815
2006
  TEMPLATE_RECORD_JSON_SCHEMA_V1,
2007
+ TRACKING_RELAY_PROTOCOL_VERSION,
1816
2008
  TemplatePackageRefSchema,
1817
2009
  TemplateRecordSchema,
1818
2010
  TemplateRequirementsSchema,
1819
2011
  TikTokTrackingProviderConfigSchema,
2012
+ TikTokTrackingSecretsSchema,
2013
+ ToggleModalStepPayloadSchema,
2014
+ TrackEventProviderSchema,
1820
2015
  TrackEventStepPayloadSchema,
1821
2016
  TrackingConfigSchema,
1822
2017
  TrackingDeliverySchema,
1823
2018
  TrackingProviderTypeSchema,
2019
+ TrackingRelayErrorCodeSchema,
2020
+ TrackingRelayProviderResultSchema,
2021
+ TrackingRelayRequestSchema,
2022
+ TrackingRelayResponseSchema,
1824
2023
  ValidateOnEventSchema,
1825
2024
  ValidationRuleSchema,
1826
2025
  ValidationRuleTypeSchema,
@@ -1833,6 +2032,9 @@ export {
1833
2032
  getManifestJsonSchema,
1834
2033
  getPageDocumentJsonSchema,
1835
2034
  getTemplateRecordJsonSchema,
2035
+ getTrackingProviderSecretsJsonSchema,
2036
+ getTrackingRelayRequestJsonSchema,
2037
+ getTrackingRelayResponseJsonSchema,
1836
2038
  isActionBinding,
1837
2039
  isActionPipeline,
1838
2040
  isActionStep,
@@ -1853,6 +2055,7 @@ export {
1853
2055
  isTemplateRecord,
1854
2056
  isTrackEventStepPayload,
1855
2057
  isTrackingConfig,
2058
+ isTrackingRelayRequest,
1856
2059
  isValidateOnEvent,
1857
2060
  isValidationRule,
1858
2061
  isValidationRuleType,