@walkeros/transformer-validator 4.0.0 → 4.0.1-next-1778068549946

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/dev.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
+ import { Flow } from '@walkeros/core';
2
3
 
3
4
  /**
4
5
  * Partial JSON Schema type - we auto-add type: 'object'.
5
- * Can include: required, properties, additionalProperties, etc.
6
6
  */
7
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
8
8
 
@@ -12,6 +12,22 @@ type JsonSchema = Partial<JSONSchemaType<unknown>>;
12
12
  */
13
13
  declare const formatSchema: JsonSchema;
14
14
 
15
+ declare const validEvent: Flow.StepExample;
16
+ declare const invalidFormat: Flow.StepExample;
17
+ declare const contractValidationPass: Flow.StepExample;
18
+
19
+ declare const step_contractValidationPass: typeof contractValidationPass;
20
+ declare const step_invalidFormat: typeof invalidFormat;
21
+ declare const step_validEvent: typeof validEvent;
22
+ declare namespace step {
23
+ export { step_contractValidationPass as contractValidationPass, step_invalidFormat as invalidFormat, step_validEvent as validEvent };
24
+ }
25
+
26
+ declare const index_step: typeof step;
27
+ declare namespace index {
28
+ export { index_step as step };
29
+ }
30
+
15
31
  /**
16
32
  * Development exports for transformer-validator
17
33
  * Used by website documentation and examples
@@ -26,4 +42,4 @@ declare const schemas: {
26
42
  settings: JsonSchema;
27
43
  };
28
44
 
29
- export { formatSchema, schemas, settingsSchema };
45
+ export { index as examples, formatSchema, schemas, settingsSchema };
package/dist/dev.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JSONSchemaType } from 'ajv';
2
+ import { Flow } from '@walkeros/core';
2
3
 
3
4
  /**
4
5
  * Partial JSON Schema type - we auto-add type: 'object'.
5
- * Can include: required, properties, additionalProperties, etc.
6
6
  */
7
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
8
8
 
@@ -12,6 +12,22 @@ type JsonSchema = Partial<JSONSchemaType<unknown>>;
12
12
  */
13
13
  declare const formatSchema: JsonSchema;
14
14
 
15
+ declare const validEvent: Flow.StepExample;
16
+ declare const invalidFormat: Flow.StepExample;
17
+ declare const contractValidationPass: Flow.StepExample;
18
+
19
+ declare const step_contractValidationPass: typeof contractValidationPass;
20
+ declare const step_invalidFormat: typeof invalidFormat;
21
+ declare const step_validEvent: typeof validEvent;
22
+ declare namespace step {
23
+ export { step_contractValidationPass as contractValidationPass, step_invalidFormat as invalidFormat, step_validEvent as validEvent };
24
+ }
25
+
26
+ declare const index_step: typeof step;
27
+ declare namespace index {
28
+ export { index_step as step };
29
+ }
30
+
15
31
  /**
16
32
  * Development exports for transformer-validator
17
33
  * Used by website documentation and examples
@@ -26,4 +42,4 @@ declare const schemas: {
26
42
  settings: JsonSchema;
27
43
  };
28
44
 
29
- export { formatSchema, schemas, settingsSchema };
45
+ export { index as examples, formatSchema, schemas, settingsSchema };
package/dist/dev.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,n={};((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(n,{formatSchema:()=>p,schemas:()=>c,settingsSchema:()=>s}),module.exports=(e=n,((e,n,p,s)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let c of o(n))i.call(e,c)||c===p||t(e,c,{get:()=>n[c],enumerable:!(s=r(n,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var p={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},s={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},c={format:p,settings:s};//# sourceMappingURL=dev.js.map
1
+ "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,i=(e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})},n={};i(n,{examples:()=>s,formatSchema:()=>p,schemas:()=>b,settingsSchema:()=>y}),module.exports=(e=n,((e,i,n,p)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let s of o(i))a.call(e,s)||s===n||t(e,s,{get:()=>i[s],enumerable:!(p=r(i,s))||p.enumerable});return e})(t({},"__esModule",{value:!0}),e));var p={type:"object",required:["name","entity","action","data","globals","custom","user","consent","id","trigger","timestamp","timing","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},source:{type:"object",required:["type"],properties:{type:{type:"string"},platform:{type:"string"},url:{type:"string"},referrer:{type:"string"},schema:{type:"string"},version:{type:"string"},count:{type:"number"},trace:{type:"string"},tool:{type:"string"},command:{type:"string"}}}}},s={};i(s,{step:()=>c});var c={};i(c,{contractValidationPass:()=>u,invalidFormat:()=>l,validEvent:()=>d});var m=require("@walkeros/core"),d={title:"Valid event",description:"A well-formed product view passes validation and is returned unchanged for downstream destinations.",in:(0,m.getEvent)("product view",{id:"ev-1700000700",timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"browser",platform:"web",url:"https://example.com/"}}),out:[["return",(0,m.getEvent)("product view",{id:"ev-1700000700",timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"browser",platform:"web",url:"https://example.com/"}})]]},l={public:!1,in:{name:"invalid",data:{}},out:[["return",!1]]},u={title:"Contract validation",description:"Contract validation passes when event data matches the entity.action JSON Schema",in:(0,m.getEvent)("order complete",{id:"ev-1700000800",timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"browser",platform:"web",url:"https://shop.example.com/"}}),out:[["return",(0,m.getEvent)("order complete",{id:"ev-1700000800",timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"browser",platform:"web",url:"https://shop.example.com/"}})]]},y={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},b={format:p,settings:y};//# sourceMappingURL=dev.js.map
package/dist/dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dev.ts","../src/format-schema.ts"],"sourcesContent":["/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,EAAE,MAAM,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU,CAAC,QAAQ,MAAM,aAAa;AAAA,MACtC,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,IAAI,EAAE,MAAM,SAAS;AAAA,QACrB,aAAa,EAAE,MAAM,SAAS;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AACF;;;ADnDO,IAAM,iBAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
1
+ {"version":3,"sources":["../src/dev.ts","../src/format-schema.ts","../src/examples/index.ts","../src/examples/step.ts"],"sourcesContent":["/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n\nexport * as examples from './examples';\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'globals',\n 'custom',\n 'user',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n source: {\n type: 'object',\n required: ['type'],\n properties: {\n type: { type: 'string' },\n platform: { type: 'string' },\n url: { type: 'string' },\n referrer: { type: 'string' },\n schema: { type: 'string' },\n version: { type: 'string' },\n count: { type: 'number' },\n trace: { type: 'string' },\n tool: { type: 'string' },\n command: { type: 'string' },\n },\n },\n },\n};\n","export * as step from './step';\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\nexport const validEvent: Flow.StepExample = {\n title: 'Valid event',\n description:\n 'A well-formed product view passes validation and is returned unchanged for downstream destinations.',\n in: getEvent('product view', {\n id: 'ev-1700000700',\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'browser', platform: 'web', url: 'https://example.com/' },\n }),\n out: [\n [\n 'return',\n getEvent('product view', {\n id: 'ev-1700000700',\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://example.com/',\n },\n }),\n ],\n ],\n};\n\nexport const invalidFormat: Flow.StepExample = {\n public: false,\n in: {\n name: 'invalid',\n data: {},\n },\n out: [['return', false]],\n};\n\nexport const contractValidationPass: Flow.StepExample = {\n title: 'Contract validation',\n description:\n 'Contract validation passes when event data matches the entity.action JSON Schema',\n in: getEvent('order complete', {\n id: 'ev-1700000800',\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://shop.example.com/',\n },\n }),\n out: [\n [\n 'return',\n getEvent('order complete', {\n id: 'ev-1700000800',\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://shop.example.com/',\n },\n }),\n ],\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA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AQ;AAAA,EACR,UAAU;AACZ;","names":[]}
package/dist/dev.mjs CHANGED
@@ -1 +1 @@
1
- var t={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},e={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},r={format:t,settings:e};export{t as formatSchema,r as schemas,e as settingsSchema};//# sourceMappingURL=dev.mjs.map
1
+ var t=Object.defineProperty,e=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},r={type:"object",required:["name","entity","action","data","globals","custom","user","consent","id","trigger","timestamp","timing","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},source:{type:"object",required:["type"],properties:{type:{type:"string"},platform:{type:"string"},url:{type:"string"},referrer:{type:"string"},schema:{type:"string"},version:{type:"string"},count:{type:"number"},trace:{type:"string"},tool:{type:"string"},command:{type:"string"}}}}},i={};e(i,{step:()=>a});var a={};e(a,{contractValidationPass:()=>s,invalidFormat:()=>p,validEvent:()=>n});import{getEvent as o}from"@walkeros/core";var n={title:"Valid event",description:"A well-formed product view passes validation and is returned unchanged for downstream destinations.",in:o("product view",{id:"ev-1700000700",timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"browser",platform:"web",url:"https://example.com/"}}),out:[["return",o("product view",{id:"ev-1700000700",timestamp:1700000700,data:{id:"SKU-100",name:"Trail Runner Pro",price:129.99},source:{type:"browser",platform:"web",url:"https://example.com/"}})]]},p={public:!1,in:{name:"invalid",data:{}},out:[["return",!1]]},s={title:"Contract validation",description:"Contract validation passes when event data matches the entity.action JSON Schema",in:o("order complete",{id:"ev-1700000800",timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"browser",platform:"web",url:"https://shop.example.com/"}}),out:[["return",o("order complete",{id:"ev-1700000800",timestamp:1700000800,data:{id:"0rd3r1d",total:555,currency:"EUR"},source:{type:"browser",platform:"web",url:"https://shop.example.com/"}})]]},c={type:"object",properties:{format:{type:"boolean",description:"Validate full WalkerOS.Event structure. Pre-compiled at init.",default:!0},contract:{type:"object",description:"Event-specific validation rules. Entity/action keyed, supports wildcards."}}},d={format:r,settings:c};export{i as examples,r as formatSchema,d as schemas,c as settingsSchema};//# sourceMappingURL=dev.mjs.map
package/dist/dev.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/format-schema.ts","../src/dev.ts"],"sourcesContent":["import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n","/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n"],"mappings":";AAMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,EAAE,MAAM,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU,CAAC,QAAQ,MAAM,aAAa;AAAA,MACtC,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,IAAI,EAAE,MAAM,SAAS;AAAA,QACrB,aAAa,EAAE,MAAM,SAAS;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AACF;;;ACnDO,IAAM,iBAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,aACE;AAAA,MACF,SAAS;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAGO,IAAM,UAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,UAAU;AACZ;","names":[]}
1
+ {"version":3,"sources":["../src/format-schema.ts","../src/examples/index.ts","../src/examples/step.ts","../src/dev.ts"],"sourcesContent":["import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'globals',\n 'custom',\n 'user',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n source: {\n type: 'object',\n required: ['type'],\n properties: {\n type: { type: 'string' },\n platform: { type: 'string' },\n url: { type: 'string' },\n referrer: { type: 'string' },\n schema: { type: 'string' },\n version: { type: 'string' },\n count: { type: 'number' },\n trace: { type: 'string' },\n tool: { type: 'string' },\n command: { type: 'string' },\n },\n },\n },\n};\n","export * as step from './step';\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\nexport const validEvent: Flow.StepExample = {\n title: 'Valid event',\n description:\n 'A well-formed product view passes validation and is returned unchanged for downstream destinations.',\n in: getEvent('product view', {\n id: 'ev-1700000700',\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: { type: 'browser', platform: 'web', url: 'https://example.com/' },\n }),\n out: [\n [\n 'return',\n getEvent('product view', {\n id: 'ev-1700000700',\n timestamp: 1700000700,\n data: { id: 'SKU-100', name: 'Trail Runner Pro', price: 129.99 },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://example.com/',\n },\n }),\n ],\n ],\n};\n\nexport const invalidFormat: Flow.StepExample = {\n public: false,\n in: {\n name: 'invalid',\n data: {},\n },\n out: [['return', false]],\n};\n\nexport const contractValidationPass: Flow.StepExample = {\n title: 'Contract validation',\n description:\n 'Contract validation passes when event data matches the entity.action JSON Schema',\n in: getEvent('order complete', {\n id: 'ev-1700000800',\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://shop.example.com/',\n },\n }),\n out: [\n [\n 'return',\n getEvent('order complete', {\n id: 'ev-1700000800',\n timestamp: 1700000800,\n data: { id: '0rd3r1d', total: 555, currency: 'EUR' },\n source: {\n type: 'browser',\n platform: 'web',\n url: 'https://shop.example.com/',\n },\n }),\n ],\n ],\n};\n","/**\n * Development exports for transformer-validator\n * Used by website documentation and examples\n */\nimport { formatSchema } from './format-schema';\nimport type { JsonSchema } from './types';\n\nexport { formatSchema };\n\n/**\n * JSON Schema describing ValidatorSettings for documentation.\n */\nexport const settingsSchema: JsonSchema = {\n type: 'object',\n properties: {\n format: {\n type: 'boolean',\n description:\n 'Validate full WalkerOS.Event structure. Pre-compiled at init.',\n default: true,\n },\n contract: {\n type: 'object',\n description:\n 'Event-specific validation rules. Entity/action keyed, supports wildcards.',\n },\n },\n};\n\n// Re-export for convenience\nexport const schemas: { format: JsonSchema; settings: JsonSchema } = {\n format: formatSchema,\n settings: settingsSchema,\n};\n\nexport * as examples from './examples';\n"],"mappings":";;;;;;;AAMO,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SA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;","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,59 +1,43 @@
1
- import { Mapping, WalkerOS, Transformer } from '@walkeros/core';
1
+ import { Transformer } from '@walkeros/core';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
 
4
4
  /**
5
5
  * Partial JSON Schema type - we auto-add type: 'object'.
6
- * Can include: required, properties, additionalProperties, etc.
7
6
  */
8
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
9
8
  /**
10
- * Contract rule for event-specific validation.
11
- * Extends the shape expected by getMappingEvent.
9
+ * Contract event rules entity → action → JSON Schema.
10
+ * The validator matches events by entity-action and validates
11
+ * against the corresponding schema.
12
12
  */
13
- interface ContractRule {
14
- /**
15
- * Condition function - first matching rule wins.
16
- * MUST be synchronous. getMappingEvent uses .find() which doesn't await.
17
- * For async checks, validate in the schema or use a separate transformer.
18
- */
19
- condition?: (event: WalkerOS.DeepPartialEvent) => boolean;
20
- /**
21
- * JSON Schema (partial) - we auto-add type: 'object'.
22
- * Can include: required, properties, additionalProperties, etc.
23
- */
24
- schema: JsonSchema;
25
- }
26
- /**
27
- * Contract extends Mapping.Rules for type compatibility with getMappingEvent.
28
- * This avoids `as any` casting and ensures strict typing.
29
- */
30
- type Contract = Mapping.Rules<ContractRule>;
13
+ type ContractEvents = Record<string, Record<string, JsonSchema>>;
31
14
  /**
32
15
  * Validator transformer settings.
33
16
  */
34
17
  interface ValidatorSettings {
35
18
  /**
36
19
  * Validate full WalkerOS.Event structure.
37
- * Pre-compiled at transformer init, runs on every event.
38
- * Validates all fields exist with correct types.
39
20
  * @default true
40
21
  */
41
22
  format?: boolean;
42
23
  /**
43
- * Event-specific validation rules.
44
- * Entity/action keyed, supports wildcards and conditions.
45
- * Schemas lazy-compiled on first match.
24
+ * Entity-action event validation schemas.
25
+ * Resolved from $contract.name.events.
26
+ * Supports wildcards via findEventSchema.
46
27
  */
47
- contract?: Contract;
28
+ events?: ContractEvents;
29
+ /** JSON Schema for event.globals — validates on every event. */
30
+ globals?: JsonSchema;
31
+ /** JSON Schema for event.context — validates on every event. */
32
+ context?: JsonSchema;
33
+ /** JSON Schema for event.custom — validates on every event. */
34
+ custom?: JsonSchema;
35
+ /** JSON Schema for event.user — validates on every event. */
36
+ user?: JsonSchema;
37
+ /** JSON Schema for event.consent — validates on every event. */
38
+ consent?: JsonSchema;
48
39
  }
49
40
 
50
- /**
51
- * Event validation transformer using AJV with JSON Schema.
52
- *
53
- * Two validation modes:
54
- * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)
55
- * - contract: Entity/action keyed business rules with lazy compilation
56
- */
57
41
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
42
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
43
+ export { type ContractEvents, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
package/dist/index.d.ts CHANGED
@@ -1,59 +1,43 @@
1
- import { Mapping, WalkerOS, Transformer } from '@walkeros/core';
1
+ import { Transformer } from '@walkeros/core';
2
2
  import { JSONSchemaType } from 'ajv';
3
3
 
4
4
  /**
5
5
  * Partial JSON Schema type - we auto-add type: 'object'.
6
- * Can include: required, properties, additionalProperties, etc.
7
6
  */
8
7
  type JsonSchema = Partial<JSONSchemaType<unknown>>;
9
8
  /**
10
- * Contract rule for event-specific validation.
11
- * Extends the shape expected by getMappingEvent.
9
+ * Contract event rules entity → action → JSON Schema.
10
+ * The validator matches events by entity-action and validates
11
+ * against the corresponding schema.
12
12
  */
13
- interface ContractRule {
14
- /**
15
- * Condition function - first matching rule wins.
16
- * MUST be synchronous. getMappingEvent uses .find() which doesn't await.
17
- * For async checks, validate in the schema or use a separate transformer.
18
- */
19
- condition?: (event: WalkerOS.DeepPartialEvent) => boolean;
20
- /**
21
- * JSON Schema (partial) - we auto-add type: 'object'.
22
- * Can include: required, properties, additionalProperties, etc.
23
- */
24
- schema: JsonSchema;
25
- }
26
- /**
27
- * Contract extends Mapping.Rules for type compatibility with getMappingEvent.
28
- * This avoids `as any` casting and ensures strict typing.
29
- */
30
- type Contract = Mapping.Rules<ContractRule>;
13
+ type ContractEvents = Record<string, Record<string, JsonSchema>>;
31
14
  /**
32
15
  * Validator transformer settings.
33
16
  */
34
17
  interface ValidatorSettings {
35
18
  /**
36
19
  * Validate full WalkerOS.Event structure.
37
- * Pre-compiled at transformer init, runs on every event.
38
- * Validates all fields exist with correct types.
39
20
  * @default true
40
21
  */
41
22
  format?: boolean;
42
23
  /**
43
- * Event-specific validation rules.
44
- * Entity/action keyed, supports wildcards and conditions.
45
- * Schemas lazy-compiled on first match.
24
+ * Entity-action event validation schemas.
25
+ * Resolved from $contract.name.events.
26
+ * Supports wildcards via findEventSchema.
46
27
  */
47
- contract?: Contract;
28
+ events?: ContractEvents;
29
+ /** JSON Schema for event.globals — validates on every event. */
30
+ globals?: JsonSchema;
31
+ /** JSON Schema for event.context — validates on every event. */
32
+ context?: JsonSchema;
33
+ /** JSON Schema for event.custom — validates on every event. */
34
+ custom?: JsonSchema;
35
+ /** JSON Schema for event.user — validates on every event. */
36
+ user?: JsonSchema;
37
+ /** JSON Schema for event.consent — validates on every event. */
38
+ consent?: JsonSchema;
48
39
  }
49
40
 
50
- /**
51
- * Event validation transformer using AJV with JSON Schema.
52
- *
53
- * Two validation modes:
54
- * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)
55
- * - contract: Entity/action keyed business rules with lazy compilation
56
- */
57
41
  declare const transformerValidator: Transformer.Init<Transformer.Types<ValidatorSettings>>;
58
42
 
59
- export { type Contract, type ContractRule, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
43
+ export { type ContractEvents, type JsonSchema, type ValidatorSettings, transformerValidator as default, transformerValidator };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.create,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,i=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,i,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let p of n(t))s.call(e,p)||p===i||r(e,p,{get:()=>t[p],enumerable:!(a=o(t,p))||a.enumerable});return e},p={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(p,{default:()=>y,transformerValidator:()=>y}),module.exports=(e=p,a(r({},"__esModule",{value:!0}),e));var c=((e,o,n)=>(n=null!=e?t(i(e)):{},a(!o&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)))(require("ajv")),u=require("@walkeros/core"),g={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},y=e=>{const{config:t}=e,r=t.settings||{},{format:o=!0,contract:n}=r,i=new c.default({allErrors:!0,strict:!1}),s=o?i.compile(g):null,a=new WeakMap;return{type:"validator",config:t,async push(e,t){const{logger:r}=t;if(s&&!s(e))return r.error("Event format invalid",{errors:i.errorsText(s.errors)}),!1;if(n){const{eventMapping:t,mappingKey:o}=await(0,u.getMappingEvent)(e,n),s=t;if(null==s?void 0:s.schema){const t=function(e){if(!a.has(e)){const t={type:"object",...e};a.set(e,i.compile(t))}return a.get(e)}(s.schema);if(!t(e))return r.error("Contract validation failed",{rule:o,errors:i.errorsText(t.errors)}),!1;r.debug("Contract validation passed",{rule:o})}}return e}}};//# sourceMappingURL=index.js.map
1
+ "use strict";var e,t=Object.create,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty,a=(e,t,s,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of n(t))i.call(e,c)||c===s||r(e,c,{get:()=>t[c],enumerable:!(a=o(t,c))||a.enumerable});return e},c={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(c,{default:()=>l,transformerValidator:()=>l}),module.exports=(e=c,a(r({},"__esModule",{value:!0}),e));var p=((e,o,n)=>(n=null!=e?t(s(e)):{},a(!o&&e&&e.__esModule?n:r(n,"default",{value:e,enumerable:!0}),e)))(require("ajv")),y={type:"object",required:["name","entity","action","data","globals","custom","user","consent","id","trigger","timestamp","timing","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},source:{type:"object",required:["type"],properties:{type:{type:"string"},platform:{type:"string"},url:{type:"string"},referrer:{type:"string"},schema:{type:"string"},version:{type:"string"},count:{type:"number"},trace:{type:"string"},tool:{type:"string"},command:{type:"string"}}}}},l=e=>{const{config:t}=e,r=t.settings||{},{format:o=!0,events:n,globals:s,context:i,custom:a,user:c,consent:l}=r,u=new p.default({allErrors:!0,strict:!1}),m=o?u.compile(y):null,g=[],f={globals:s,context:i,custom:a,user:c,consent:l};for(const[e,t]of Object.entries(f))t&&g.push({name:e,field:e,validate:u.compile({type:"object",...t})});const b=new Map;return{type:"validator",config:t,async push(e,t){const{logger:r}=t;if(m&&!m(e))return r.error("Event format invalid",{errors:u.errorsText(m.errors)}),!1;for(const{name:t,field:o,validate:n}of g){if(!n(e[o]))return r.error(`${t} validation failed`,{errors:u.errorsText(n.errors)}),!1}if(n&&e.entity&&e.action){const t=function(e,t){if(n)return n[e]?.[t]?{schema:n[e][t],key:`${e} ${t}`}:n[e]?.["*"]?{schema:n[e]["*"],key:`${e} *`}:n["*"]?.[t]?{schema:n["*"][t],key:`* ${t}`}:n["*"]?.["*"]?{schema:n["*"]["*"],key:"* *"}:void 0}(e.entity,e.action);if(t){const o=function(e,t,r){const o=`${e}.${t}`;return b.has(o)||b.set(o,u.compile({type:"object",...r})),b.get(o)}(e.entity,e.action,t.schema);if(!o(e))return r.error("Contract validation failed",{rule:t.key,errors:u.errorsText(o.errors)}),!1;r.debug("Contract validation passed",{rule:t.key})}}return{event:e}}}};//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["export { transformerValidator } from './transformer';\nexport type {\n ValidatorSettings,\n Contract,\n ContractRule,\n JsonSchema,\n} from './types';\n\nexport { transformerValidator as default } from './transformer';\n","import Ajv, { ValidateFunction } from 'ajv';\nimport { getMappingEvent } from '@walkeros/core';\nimport type { Mapping, Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, ContractRule, JsonSchema } from './types';\n\n/**\n * Event validation transformer using AJV with JSON Schema.\n *\n * Two validation modes:\n * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)\n * - contract: Entity/action keyed business rules with lazy compilation\n */\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const { format = true, contract } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator (runs on every event)\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Lazy-compiled contract validators - keyed by schema reference\n // Using WeakMap to cache by schema object, handling array rules with conditions\n const contractValidators = new WeakMap<JsonSchema, ValidateFunction>();\n\n function getContractValidator(schema: JsonSchema) {\n if (!contractValidators.has(schema)) {\n // Auto-wrap with type: 'object'\n const fullSchema = { type: 'object', ...schema };\n contractValidators.set(schema, ajv.compile(fullSchema));\n }\n return contractValidators.get(schema)!;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Contract validation (lazy compiled)\n if (contract) {\n // Contract is typed as Mapping.Rules<ContractRule> - cast needed for getMappingEvent\n const { eventMapping: rule, mappingKey } = await getMappingEvent(\n event,\n contract as Mapping.Rules,\n );\n\n // Type assertion: we know our rules have schema\n const contractRule = rule as ContractRule | undefined;\n\n if (contractRule?.schema) {\n const validator = getContractValidator(contractRule.schema);\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: mappingKey,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: mappingKey });\n }\n }\n\n return event;\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAsC;AACtC,kBAAgC;;;ACKzB,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;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B,YAAI,6CAAc,QAAQ;AACxB,gBAAM,YAAY,qBAAqB,aAAa,MAAM;AAE1D,cAAI,CAAC,UAAU,KAAK,GAAG;AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM;AAAA,cACN,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAAA,QACjE;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["Ajv","context"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["export { transformerValidator } from './transformer';\nexport type { ValidatorSettings, ContractEvents, JsonSchema } from './types';\n\nexport { transformerValidator as default } from './transformer';\n","import Ajv, { ValidateFunction } from 'ajv';\nimport type { Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, JsonSchema } from './types';\n\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const {\n format = true,\n events,\n globals,\n context: ctx,\n custom,\n user,\n consent,\n } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Pre-compile section validators (run on every event)\n const sectionValidators: Array<{\n name: string;\n field: string;\n validate: ValidateFunction;\n }> = [];\n\n const sectionSchemas = { globals, context: ctx, custom, user, consent };\n for (const [name, schema] of Object.entries(sectionSchemas)) {\n if (schema) {\n sectionValidators.push({\n name,\n field: name,\n validate: ajv.compile({ type: 'object', ...schema }),\n });\n }\n }\n\n // Lazy-compiled event validators\n const eventValidators = new Map<string, ValidateFunction>();\n\n function getEventValidator(\n entity: string,\n action: string,\n schema: JsonSchema,\n ) {\n const key = `${entity}.${action}`;\n if (!eventValidators.has(key)) {\n eventValidators.set(key, ajv.compile({ type: 'object', ...schema }));\n }\n return eventValidators.get(key)!;\n }\n\n /**\n * Find matching event schema using wildcard fallback.\n * Checks: entity.action → entity.* → *.action → *.*\n */\n function findEventSchema(\n entity: string,\n action: string,\n ): { schema: JsonSchema; key: string } | undefined {\n if (!events) return undefined;\n\n // Direct match\n if (events[entity]?.[action]) {\n return { schema: events[entity][action], key: `${entity} ${action}` };\n }\n // Entity wildcard\n if (events[entity]?.['*']) {\n return { schema: events[entity]['*'], key: `${entity} *` };\n }\n // Action wildcard\n if (events['*']?.[action]) {\n return { schema: events['*'][action], key: `* ${action}` };\n }\n // Global wildcard\n if (events['*']?.['*']) {\n return { schema: events['*']['*'], key: '* *' };\n }\n return undefined;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Section validation (pre-compiled, runs on every event)\n for (const { name, field, validate } of sectionValidators) {\n const value = (event as Record<string, unknown>)[field];\n if (!validate(value)) {\n logger.error(`${name} validation failed`, {\n errors: ajv.errorsText(validate.errors),\n });\n return false;\n }\n }\n\n // 3. Event validation (lazy compiled)\n if (events && event.entity && event.action) {\n const match = findEventSchema(event.entity, event.action);\n\n if (match) {\n const validator = getEventValidator(\n event.entity,\n event.action,\n match.schema,\n );\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: match.key,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: match.key });\n }\n }\n\n return { event };\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'globals',\n 'custom',\n 'user',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n source: {\n type: 'object',\n required: ['type'],\n properties: {\n type: { type: 'string' },\n platform: { type: 'string' },\n url: { type: 'string' },\n referrer: { type: 'string' },\n schema: { type: 'string' },\n version: { type: 'string' },\n count: { type: 'number' },\n trace: { type: 'string' },\n tool: { type: 'string' },\n command: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAsC;;;ACM/B,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,M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T;AAGA,iBAAW,EAAE,MAAM,OAAO,SAAS,KAAK,mBAAmB;AACzD,cAAM,QAAS,MAAkC,KAAK;AACtD,YAAI,CAAC,SAAS,KAAK,GAAG;AACpB,iBAAO,MAAM,GAAG,IAAI,sBAAsB;AAAA,YACxC,QAAQ,IAAI,WAAW,SAAS,MAAM;AAAA,UACxC,CAAC;AACD,iBAAO;AAAA,QACT;AAAA,MACF;AAGA,UAAI,UAAU,MAAM,UAAU,MAAM,QAAQ;AAC1C,cAAM,QAAQ,gBAAgB,MAAM,QAAQ,MAAM,MAAM;AAExD,YAAI,OAAO;AACT,gBAAM,YAAY;AAAA,YAChB,MAAM;AAAA,YACN,MAAM;AAAA,YACN,MAAM;AAAA,UACR;AAEA,cAAI,CAAC,UAAU,KAAK,GAAG;AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM,MAAM;AAAA,cACZ,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,MAAM,IAAI,CAAC;AAAA,QAChE;AAAA,MACF;AAEA,aAAO,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["Ajv","context"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e from"ajv";import{getMappingEvent as t}from"@walkeros/core";var r={type:"object",required:["name","entity","action","data","context","globals","custom","user","nested","consent","id","trigger","timestamp","timing","group","count","version","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},group:{type:"string"},count:{type:"number"},version:{type:"object",required:["source","tagging"],properties:{source:{type:"string"},tagging:{type:"number"}}},source:{type:"object",required:["type","id","previous_id"],properties:{type:{type:"string"},id:{type:"string"},previous_id:{type:"string"}}}}},o=o=>{const{config:n}=o,i=n.settings||{},{format:s=!0,contract:p}=i,a=new e({allErrors:!0,strict:!1}),c=s?a.compile(r):null,g=new WeakMap;return{type:"validator",config:n,async push(e,r){const{logger:o}=r;if(c&&!c(e))return o.error("Event format invalid",{errors:a.errorsText(c.errors)}),!1;if(p){const{eventMapping:r,mappingKey:n}=await t(e,p),i=r;if(null==i?void 0:i.schema){const t=function(e){if(!g.has(e)){const t={type:"object",...e};g.set(e,a.compile(t))}return g.get(e)}(i.schema);if(!t(e))return o.error("Contract validation failed",{rule:n,errors:a.errorsText(t.errors)}),!1;o.debug("Contract validation passed",{rule:n})}}return e}}};export{o as default,o as transformerValidator};//# sourceMappingURL=index.mjs.map
1
+ import e from"ajv";var t={type:"object",required:["name","entity","action","data","globals","custom","user","consent","id","trigger","timestamp","timing","source"],properties:{name:{type:"string",pattern:"^\\S+ \\S+$"},entity:{type:"string"},action:{type:"string"},data:{type:"object"},context:{type:"object"},globals:{type:"object"},custom:{type:"object"},user:{type:"object"},nested:{type:"array"},consent:{type:"object"},id:{type:"string"},trigger:{type:"string"},timestamp:{type:"number"},timing:{type:"number"},source:{type:"object",required:["type"],properties:{type:{type:"string"},platform:{type:"string"},url:{type:"string"},referrer:{type:"string"},schema:{type:"string"},version:{type:"string"},count:{type:"number"},trace:{type:"string"},tool:{type:"string"},command:{type:"string"}}}}},r=r=>{const{config:n}=r,o=n.settings||{},{format:s=!0,events:i,globals:a,context:c,custom:p,user:y,consent:l}=o,m=new e({allErrors:!0,strict:!1}),u=s?m.compile(t):null,g=[],f={globals:a,context:c,custom:p,user:y,consent:l};for(const[e,t]of Object.entries(f))t&&g.push({name:e,field:e,validate:m.compile({type:"object",...t})});const d=new Map;return{type:"validator",config:n,async push(e,t){const{logger:r}=t;if(u&&!u(e))return r.error("Event format invalid",{errors:m.errorsText(u.errors)}),!1;for(const{name:t,field:n,validate:o}of g){if(!o(e[n]))return r.error(`${t} validation failed`,{errors:m.errorsText(o.errors)}),!1}if(i&&e.entity&&e.action){const t=function(e,t){if(i)return i[e]?.[t]?{schema:i[e][t],key:`${e} ${t}`}:i[e]?.["*"]?{schema:i[e]["*"],key:`${e} *`}:i["*"]?.[t]?{schema:i["*"][t],key:`* ${t}`}:i["*"]?.["*"]?{schema:i["*"]["*"],key:"* *"}:void 0}(e.entity,e.action);if(t){const n=function(e,t,r){const n=`${e}.${t}`;return d.has(n)||d.set(n,m.compile({type:"object",...r})),d.get(n)}(e.entity,e.action,t.schema);if(!n(e))return r.error("Contract validation failed",{rule:t.key,errors:m.errorsText(n.errors)}),!1;r.debug("Contract validation passed",{rule:t.key})}}return{event:e}}}};export{r as default,r as transformerValidator};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["import Ajv, { ValidateFunction } from 'ajv';\nimport { getMappingEvent } from '@walkeros/core';\nimport type { Mapping, Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, ContractRule, JsonSchema } from './types';\n\n/**\n * Event validation transformer using AJV with JSON Schema.\n *\n * Two validation modes:\n * - format: Pre-compiled WalkerOS.Event structure validation (runs on every event)\n * - contract: Entity/action keyed business rules with lazy compilation\n */\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const { format = true, contract } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator (runs on every event)\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Lazy-compiled contract validators - keyed by schema reference\n // Using WeakMap to cache by schema object, handling array rules with conditions\n const contractValidators = new WeakMap<JsonSchema, ValidateFunction>();\n\n function getContractValidator(schema: JsonSchema) {\n if (!contractValidators.has(schema)) {\n // Auto-wrap with type: 'object'\n const fullSchema = { type: 'object', ...schema };\n contractValidators.set(schema, ajv.compile(fullSchema));\n }\n return contractValidators.get(schema)!;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Contract validation (lazy compiled)\n if (contract) {\n // Contract is typed as Mapping.Rules<ContractRule> - cast needed for getMappingEvent\n const { eventMapping: rule, mappingKey } = await getMappingEvent(\n event,\n contract as Mapping.Rules,\n );\n\n // Type assertion: we know our rules have schema\n const contractRule = rule as ContractRule | undefined;\n\n if (contractRule?.schema) {\n const validator = getContractValidator(contractRule.schema);\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: mappingKey,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: mappingKey });\n }\n }\n\n return event;\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'context',\n 'globals',\n 'custom',\n 'user',\n 'nested',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'group',\n 'count',\n 'version',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n group: { type: 'string' },\n count: { type: 'number' },\n version: {\n type: 'object',\n required: ['source', 'tagging'],\n properties: {\n source: { type: 'string' },\n tagging: { type: 'number' },\n },\n },\n source: {\n type: 'object',\n required: ['type', 'id', 'previous_id'],\n properties: {\n type: { type: 'string' },\n id: { type: 'string' },\n previous_id: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";AAAA,OAAO,SAA+B;AACtC,SAAS,uBAAuB;;;ACKzB,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,OAAO,EAAE,MAAM,SAAS;AAAA,IACxB,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU,CAAC,UAAU,SAAS;AAAA,MAC9B,YAAY;AAAA,QACV,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,SAAS,EAAE,MAAM,SAAS;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,QAAQ;AAAA,MACN,MAA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AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM;AAAA,cACN,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAAA,QACjE;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["context"]}
1
+ {"version":3,"sources":["../src/transformer.ts","../src/format-schema.ts"],"sourcesContent":["import Ajv, { ValidateFunction } from 'ajv';\nimport type { Transformer } from '@walkeros/core';\nimport { formatSchema } from './format-schema';\nimport type { ValidatorSettings, JsonSchema } from './types';\n\nexport const transformerValidator: Transformer.Init<\n Transformer.Types<ValidatorSettings>\n> = (context) => {\n const { config } = context;\n const settings = config.settings || {};\n const {\n format = true,\n events,\n globals,\n context: ctx,\n custom,\n user,\n consent,\n } = settings;\n\n const ajv = new Ajv({ allErrors: true, strict: false });\n\n // Pre-compile format validator\n const formatValidator = format ? ajv.compile(formatSchema) : null;\n\n // Pre-compile section validators (run on every event)\n const sectionValidators: Array<{\n name: string;\n field: string;\n validate: ValidateFunction;\n }> = [];\n\n const sectionSchemas = { globals, context: ctx, custom, user, consent };\n for (const [name, schema] of Object.entries(sectionSchemas)) {\n if (schema) {\n sectionValidators.push({\n name,\n field: name,\n validate: ajv.compile({ type: 'object', ...schema }),\n });\n }\n }\n\n // Lazy-compiled event validators\n const eventValidators = new Map<string, ValidateFunction>();\n\n function getEventValidator(\n entity: string,\n action: string,\n schema: JsonSchema,\n ) {\n const key = `${entity}.${action}`;\n if (!eventValidators.has(key)) {\n eventValidators.set(key, ajv.compile({ type: 'object', ...schema }));\n }\n return eventValidators.get(key)!;\n }\n\n /**\n * Find matching event schema using wildcard fallback.\n * Checks: entity.action → entity.* → *.action → *.*\n */\n function findEventSchema(\n entity: string,\n action: string,\n ): { schema: JsonSchema; key: string } | undefined {\n if (!events) return undefined;\n\n // Direct match\n if (events[entity]?.[action]) {\n return { schema: events[entity][action], key: `${entity} ${action}` };\n }\n // Entity wildcard\n if (events[entity]?.['*']) {\n return { schema: events[entity]['*'], key: `${entity} *` };\n }\n // Action wildcard\n if (events['*']?.[action]) {\n return { schema: events['*'][action], key: `* ${action}` };\n }\n // Global wildcard\n if (events['*']?.['*']) {\n return { schema: events['*']['*'], key: '* *' };\n }\n return undefined;\n }\n\n return {\n type: 'validator',\n config,\n\n async push(event, context) {\n const { logger } = context;\n\n // 1. Format validation (pre-compiled, fast)\n if (formatValidator && !formatValidator(event)) {\n logger.error('Event format invalid', {\n errors: ajv.errorsText(formatValidator.errors),\n });\n return false;\n }\n\n // 2. Section validation (pre-compiled, runs on every event)\n for (const { name, field, validate } of sectionValidators) {\n const value = (event as Record<string, unknown>)[field];\n if (!validate(value)) {\n logger.error(`${name} validation failed`, {\n errors: ajv.errorsText(validate.errors),\n });\n return false;\n }\n }\n\n // 3. Event validation (lazy compiled)\n if (events && event.entity && event.action) {\n const match = findEventSchema(event.entity, event.action);\n\n if (match) {\n const validator = getEventValidator(\n event.entity,\n event.action,\n match.schema,\n );\n\n if (!validator(event)) {\n logger.error('Contract validation failed', {\n rule: match.key,\n errors: ajv.errorsText(validator.errors),\n });\n return false;\n }\n\n logger.debug('Contract validation passed', { rule: match.key });\n }\n }\n\n return { event };\n },\n };\n};\n","import type { JsonSchema } from './types';\n\n/**\n * Pre-compiled JSON Schema for WalkerOS.Event structure validation.\n * Validates that all required fields exist with correct types.\n */\nexport const formatSchema: JsonSchema = {\n type: 'object',\n required: [\n 'name',\n 'entity',\n 'action',\n 'data',\n 'globals',\n 'custom',\n 'user',\n 'consent',\n 'id',\n 'trigger',\n 'timestamp',\n 'timing',\n 'source',\n ],\n properties: {\n name: { type: 'string', pattern: '^\\\\S+ \\\\S+$' }, // \"entity action\"\n entity: { type: 'string' },\n action: { type: 'string' },\n data: { type: 'object' },\n context: { type: 'object' },\n globals: { type: 'object' },\n custom: { type: 'object' },\n user: { type: 'object' },\n nested: { type: 'array' },\n consent: { type: 'object' },\n id: { type: 'string' },\n trigger: { type: 'string' },\n timestamp: { type: 'number' },\n timing: { type: 'number' },\n source: {\n type: 'object',\n required: ['type'],\n properties: {\n type: { type: 'string' },\n platform: { type: 'string' },\n url: { type: 'string' },\n referrer: { type: 'string' },\n schema: { type: 'string' },\n version: { type: 'string' },\n count: { type: 'number' },\n trace: { type: 'string' },\n tool: { type: 'string' },\n command: { type: 'string' },\n },\n },\n },\n};\n"],"mappings":";AAAA,OAAO,SAA+B;;;ACM/B,IAAM,eAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,UAAU,SAAS,cAAc;AAAA;AAAA,IAC/C,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,MAAM,EAAE,MAAM,SAAS;AAAA,IACvB,QAAQ,EAAE,MAAM,QAAQ;AAAA,IACxB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,IAAI,EAAE,MAAM,SAAS;AAAA,IACrB,SAAS,EAAE,MAAM,SAAS;AAAA,IAC1B,WAAW,EAAE,MAAM,SAAS;AAAA,IAC5B,QAAQ,EAAE,MAAM,SAAS;AAAA,IACzB,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU,CAAC,MAAM;AAAA,MACjB,YAAY;AAAA,QACV,MAAM,EAAE,MAAM,SAAS;AAAA,QACvB,UAAU,EAAE,MAAM,S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,UAAU,MAAM,QAAQ;AAC1C,cAAM,QAAQ,gBAAgB,MAAM,QAAQ,MAAM,MAAM;AAExD,YAAI,OAAO;AACT,gBAAM,YAAY;AAAA,YAChB,MAAM;AAAA,YACN,MAAM;AAAA,YACN,MAAM;AAAA,UACR;AAEA,cAAI,CAAC,UAAU,KAAK,GAAG;AACrB,mBAAO,MAAM,8BAA8B;AAAA,cACzC,MAAM,MAAM;AAAA,cACZ,QAAQ,IAAI,WAAW,UAAU,MAAM;AAAA,YACzC,CAAC;AACD,mBAAO;AAAA,UACT;AAEA,iBAAO,MAAM,8BAA8B,EAAE,MAAM,MAAM,IAAI,CAAC;AAAA,QAChE;AAAA,MACF;AAEA,aAAO,EAAE,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":["context"]}
@@ -0,0 +1,419 @@
1
+ {
2
+ "$meta": {
3
+ "package": "@walkeros/transformer-validator",
4
+ "version": "4.0.1-next-1778068549946",
5
+ "type": "transformer",
6
+ "platform": [
7
+ "web",
8
+ "server"
9
+ ],
10
+ "docs": "https://www.walkeros.io/docs/transformers/validator",
11
+ "source": "https://github.com/elbwalker/walkerOS/tree/main/packages/transformers/validator/src"
12
+ },
13
+ "schemas": {
14
+ "format": {
15
+ "type": "object",
16
+ "required": [
17
+ "name",
18
+ "entity",
19
+ "action",
20
+ "data",
21
+ "globals",
22
+ "custom",
23
+ "user",
24
+ "consent",
25
+ "id",
26
+ "trigger",
27
+ "timestamp",
28
+ "timing",
29
+ "source"
30
+ ],
31
+ "properties": {
32
+ "name": {
33
+ "type": "string",
34
+ "pattern": "^\\S+ \\S+$"
35
+ },
36
+ "entity": {
37
+ "type": "string"
38
+ },
39
+ "action": {
40
+ "type": "string"
41
+ },
42
+ "data": {
43
+ "type": "object"
44
+ },
45
+ "context": {
46
+ "type": "object"
47
+ },
48
+ "globals": {
49
+ "type": "object"
50
+ },
51
+ "custom": {
52
+ "type": "object"
53
+ },
54
+ "user": {
55
+ "type": "object"
56
+ },
57
+ "nested": {
58
+ "type": "array"
59
+ },
60
+ "consent": {
61
+ "type": "object"
62
+ },
63
+ "id": {
64
+ "type": "string"
65
+ },
66
+ "trigger": {
67
+ "type": "string"
68
+ },
69
+ "timestamp": {
70
+ "type": "number"
71
+ },
72
+ "timing": {
73
+ "type": "number"
74
+ },
75
+ "source": {
76
+ "type": "object",
77
+ "required": [
78
+ "type"
79
+ ],
80
+ "properties": {
81
+ "type": {
82
+ "type": "string"
83
+ },
84
+ "platform": {
85
+ "type": "string"
86
+ },
87
+ "url": {
88
+ "type": "string"
89
+ },
90
+ "referrer": {
91
+ "type": "string"
92
+ },
93
+ "schema": {
94
+ "type": "string"
95
+ },
96
+ "version": {
97
+ "type": "string"
98
+ },
99
+ "count": {
100
+ "type": "number"
101
+ },
102
+ "trace": {
103
+ "type": "string"
104
+ },
105
+ "tool": {
106
+ "type": "string"
107
+ },
108
+ "command": {
109
+ "type": "string"
110
+ }
111
+ }
112
+ }
113
+ }
114
+ },
115
+ "settings": {
116
+ "type": "object",
117
+ "properties": {
118
+ "format": {
119
+ "type": "boolean",
120
+ "description": "Validate full WalkerOS.Event structure. Pre-compiled at init.",
121
+ "default": true
122
+ },
123
+ "contract": {
124
+ "type": "object",
125
+ "description": "Event-specific validation rules. Entity/action keyed, supports wildcards."
126
+ }
127
+ }
128
+ }
129
+ },
130
+ "examples": {
131
+ "step": {
132
+ "contractValidationPass": {
133
+ "title": "Contract validation",
134
+ "description": "Contract validation passes when event data matches the entity.action JSON Schema",
135
+ "in": {
136
+ "name": "order complete",
137
+ "data": {
138
+ "id": "0rd3r1d",
139
+ "total": 555,
140
+ "currency": "EUR"
141
+ },
142
+ "context": {
143
+ "shopping": [
144
+ "complete",
145
+ 0
146
+ ]
147
+ },
148
+ "globals": {
149
+ "pagegroup": "shop"
150
+ },
151
+ "custom": {
152
+ "completely": "random"
153
+ },
154
+ "user": {
155
+ "id": "us3r",
156
+ "device": "c00k13",
157
+ "session": "s3ss10n"
158
+ },
159
+ "nested": [
160
+ {
161
+ "entity": "product",
162
+ "data": {
163
+ "id": "ers",
164
+ "name": "Everyday Ruck Snack",
165
+ "color": "black",
166
+ "size": "l",
167
+ "price": 420
168
+ },
169
+ "context": {
170
+ "shopping": [
171
+ "complete",
172
+ 0
173
+ ]
174
+ },
175
+ "nested": []
176
+ },
177
+ {
178
+ "entity": "product",
179
+ "data": {
180
+ "id": "cc",
181
+ "name": "Cool Cap",
182
+ "size": "one size",
183
+ "price": 42
184
+ },
185
+ "context": {
186
+ "shopping": [
187
+ "complete",
188
+ 0
189
+ ]
190
+ },
191
+ "nested": []
192
+ },
193
+ {
194
+ "entity": "gift",
195
+ "data": {
196
+ "name": "Surprise"
197
+ },
198
+ "context": {
199
+ "shopping": [
200
+ "complete",
201
+ 0
202
+ ]
203
+ },
204
+ "nested": []
205
+ }
206
+ ],
207
+ "consent": {
208
+ "functional": true
209
+ },
210
+ "id": "ev-1700000800",
211
+ "trigger": "load",
212
+ "entity": "order",
213
+ "action": "complete",
214
+ "timestamp": 1700000800,
215
+ "timing": 3.14,
216
+ "source": {
217
+ "type": "browser",
218
+ "platform": "web",
219
+ "url": "https://shop.example.com/"
220
+ }
221
+ },
222
+ "out": [
223
+ [
224
+ "return",
225
+ {
226
+ "name": "order complete",
227
+ "data": {
228
+ "id": "0rd3r1d",
229
+ "total": 555,
230
+ "currency": "EUR"
231
+ },
232
+ "context": {
233
+ "shopping": [
234
+ "complete",
235
+ 0
236
+ ]
237
+ },
238
+ "globals": {
239
+ "pagegroup": "shop"
240
+ },
241
+ "custom": {
242
+ "completely": "random"
243
+ },
244
+ "user": {
245
+ "id": "us3r",
246
+ "device": "c00k13",
247
+ "session": "s3ss10n"
248
+ },
249
+ "nested": [
250
+ {
251
+ "entity": "product",
252
+ "data": {
253
+ "id": "ers",
254
+ "name": "Everyday Ruck Snack",
255
+ "color": "black",
256
+ "size": "l",
257
+ "price": 420
258
+ },
259
+ "context": {
260
+ "shopping": [
261
+ "complete",
262
+ 0
263
+ ]
264
+ },
265
+ "nested": []
266
+ },
267
+ {
268
+ "entity": "product",
269
+ "data": {
270
+ "id": "cc",
271
+ "name": "Cool Cap",
272
+ "size": "one size",
273
+ "price": 42
274
+ },
275
+ "context": {
276
+ "shopping": [
277
+ "complete",
278
+ 0
279
+ ]
280
+ },
281
+ "nested": []
282
+ },
283
+ {
284
+ "entity": "gift",
285
+ "data": {
286
+ "name": "Surprise"
287
+ },
288
+ "context": {
289
+ "shopping": [
290
+ "complete",
291
+ 0
292
+ ]
293
+ },
294
+ "nested": []
295
+ }
296
+ ],
297
+ "consent": {
298
+ "functional": true
299
+ },
300
+ "id": "ev-1700000800",
301
+ "trigger": "load",
302
+ "entity": "order",
303
+ "action": "complete",
304
+ "timestamp": 1700000800,
305
+ "timing": 3.14,
306
+ "source": {
307
+ "type": "browser",
308
+ "platform": "web",
309
+ "url": "https://shop.example.com/"
310
+ }
311
+ }
312
+ ]
313
+ ]
314
+ },
315
+ "invalidFormat": {
316
+ "public": false,
317
+ "in": {
318
+ "name": "invalid",
319
+ "data": {}
320
+ },
321
+ "out": [
322
+ [
323
+ "return",
324
+ false
325
+ ]
326
+ ]
327
+ },
328
+ "validEvent": {
329
+ "title": "Valid event",
330
+ "description": "A well-formed product view passes validation and is returned unchanged for downstream destinations.",
331
+ "in": {
332
+ "name": "product view",
333
+ "data": {
334
+ "id": "SKU-100",
335
+ "name": "Trail Runner Pro",
336
+ "price": 129.99
337
+ },
338
+ "context": {
339
+ "shopping": [
340
+ "detail",
341
+ 0
342
+ ]
343
+ },
344
+ "globals": {
345
+ "pagegroup": "shop"
346
+ },
347
+ "custom": {
348
+ "completely": "random"
349
+ },
350
+ "user": {
351
+ "id": "us3r",
352
+ "device": "c00k13",
353
+ "session": "s3ss10n"
354
+ },
355
+ "nested": [],
356
+ "consent": {
357
+ "functional": true
358
+ },
359
+ "id": "ev-1700000700",
360
+ "trigger": "load",
361
+ "entity": "product",
362
+ "action": "view",
363
+ "timestamp": 1700000700,
364
+ "timing": 3.14,
365
+ "source": {
366
+ "type": "browser",
367
+ "platform": "web",
368
+ "url": "https://example.com/"
369
+ }
370
+ },
371
+ "out": [
372
+ [
373
+ "return",
374
+ {
375
+ "name": "product view",
376
+ "data": {
377
+ "id": "SKU-100",
378
+ "name": "Trail Runner Pro",
379
+ "price": 129.99
380
+ },
381
+ "context": {
382
+ "shopping": [
383
+ "detail",
384
+ 0
385
+ ]
386
+ },
387
+ "globals": {
388
+ "pagegroup": "shop"
389
+ },
390
+ "custom": {
391
+ "completely": "random"
392
+ },
393
+ "user": {
394
+ "id": "us3r",
395
+ "device": "c00k13",
396
+ "session": "s3ss10n"
397
+ },
398
+ "nested": [],
399
+ "consent": {
400
+ "functional": true
401
+ },
402
+ "id": "ev-1700000700",
403
+ "trigger": "load",
404
+ "entity": "product",
405
+ "action": "view",
406
+ "timestamp": 1700000700,
407
+ "timing": 3.14,
408
+ "source": {
409
+ "type": "browser",
410
+ "platform": "web",
411
+ "url": "https://example.com/"
412
+ }
413
+ }
414
+ ]
415
+ ]
416
+ }
417
+ }
418
+ }
419
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/transformer-validator",
3
3
  "description": "Event validation transformer for walkerOS using AJV and JSON Schema",
4
- "version": "4.0.0",
4
+ "version": "4.0.1-next-1778068549946",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -16,7 +16,8 @@
16
16
  "types": "./dist/dev.d.ts",
17
17
  "import": "./dist/dev.mjs",
18
18
  "require": "./dist/dev.js"
19
- }
19
+ },
20
+ "./walkerOS.json": "./dist/walkerOS.json"
20
21
  },
21
22
  "files": [
22
23
  "dist/**"
@@ -25,18 +26,17 @@
25
26
  "build": "tsup --silent",
26
27
  "clean": "rm -rf .turbo && rm -rf dist",
27
28
  "dev": "jest --watchAll --colors",
28
- "lint": "tsc --noEmit && eslint \"**/*.ts*\"",
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "eslint \"**/*.ts*\"",
29
31
  "test": "jest",
30
32
  "update": "npx npm-check-updates -u && npm update"
31
33
  },
32
34
  "dependencies": {
33
- "ajv": "^8.17.1"
34
- },
35
- "peerDependencies": {
36
- "@walkeros/core": "^1.3.0"
35
+ "ajv": "^8.17.1",
36
+ "@walkeros/core": "4.0.1-next-1778068549946"
37
37
  },
38
38
  "devDependencies": {
39
- "@walkeros/core": "1.3.0"
39
+ "@walkeros/core": "4.0.1-next-1778068549946"
40
40
  },
41
41
  "repository": {
42
42
  "url": "git+https://github.com/elbwalker/walkerOS.git",
@@ -47,13 +47,22 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/elbwalker/walkerOS/issues"
49
49
  },
50
+ "walkerOS": {
51
+ "type": "transformer",
52
+ "docs": "https://www.walkeros.io/docs/transformers/validator",
53
+ "platform": [
54
+ "web",
55
+ "server"
56
+ ]
57
+ },
50
58
  "keywords": [
51
- "walker",
52
59
  "walkerOS",
60
+ "walkerOS-transformer",
53
61
  "transformer",
54
62
  "validator",
55
63
  "ajv",
56
- "json-schema"
64
+ "json-schema",
65
+ "analytics"
57
66
  ],
58
67
  "funding": [
59
68
  {