@storewatch/schema 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/chunk-MEHWUFJG.js +71 -0
- package/dist/constants.cjs +103 -0
- package/dist/constants.d.cts +43 -0
- package/dist/constants.d.ts +43 -0
- package/dist/constants.js +22 -0
- package/dist/envelope.d.cts +114 -0
- package/dist/envelope.d.ts +114 -0
- package/dist/events.d.cts +135 -0
- package/dist/events.d.ts +135 -0
- package/dist/index.cjs +312 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +217 -0
- package/dist/primitives.d.cts +16 -0
- package/dist/primitives.d.ts +16 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edin Skeja
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @storewatch/schema
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Storewatch event contract: canonical commerce events, their property
|
|
4
|
+
schemas (Zod) and the money helpers every Storewatch SDK shares.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { validateEvent } from "@storewatch/schema";
|
|
8
|
+
import { money, toMajor } from "@storewatch/schema/constants";
|
|
9
|
+
|
|
10
|
+
money(1249, "SEK"); // { amount: 124900, currency: "SEK" }: integer minor units
|
|
11
|
+
validateEvent(event); // { ok: true, event } | { ok: false, issues }
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You rarely need this package directly: the browser, React, Next.js, Node and
|
|
15
|
+
Medusa SDKs depend on it.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var CANONICAL_EVENTS = [
|
|
3
|
+
"page_viewed",
|
|
4
|
+
"product_viewed",
|
|
5
|
+
"collection_viewed",
|
|
6
|
+
"search_performed",
|
|
7
|
+
"add_to_cart",
|
|
8
|
+
"remove_from_cart",
|
|
9
|
+
"cart_updated",
|
|
10
|
+
"checkout_started",
|
|
11
|
+
"checkout_step_viewed",
|
|
12
|
+
"customer_information_entered",
|
|
13
|
+
"shipping_selected",
|
|
14
|
+
"payment_started",
|
|
15
|
+
"payment_failed",
|
|
16
|
+
"payment_authorized",
|
|
17
|
+
"order_completed",
|
|
18
|
+
"order_cancelled",
|
|
19
|
+
"refund_created",
|
|
20
|
+
"session_heartbeat"
|
|
21
|
+
];
|
|
22
|
+
var canonicalSet = new Set(CANONICAL_EVENTS);
|
|
23
|
+
function isCanonicalEvent(name) {
|
|
24
|
+
return canonicalSet.has(name);
|
|
25
|
+
}
|
|
26
|
+
var SERVER_AUTHORITATIVE_EVENTS = /* @__PURE__ */ new Set([
|
|
27
|
+
"payment_failed",
|
|
28
|
+
"payment_authorized",
|
|
29
|
+
"order_completed",
|
|
30
|
+
"order_cancelled",
|
|
31
|
+
"refund_created"
|
|
32
|
+
]);
|
|
33
|
+
var EPHEMERAL_EVENTS = /* @__PURE__ */ new Set(["session_heartbeat"]);
|
|
34
|
+
var LIMITS = {
|
|
35
|
+
batchMaxEvents: 100,
|
|
36
|
+
batchMaxBytes: 256 * 1024,
|
|
37
|
+
propertiesMaxBytes: 4 * 1024,
|
|
38
|
+
propertiesMaxDepth: 4,
|
|
39
|
+
stringMaxLength: 1024,
|
|
40
|
+
urlMaxLength: 2048,
|
|
41
|
+
idMaxLength: 128,
|
|
42
|
+
sessionIdMaxLength: 64,
|
|
43
|
+
eventNameMaxLength: 64,
|
|
44
|
+
searchQueryMaxLength: 100,
|
|
45
|
+
orderMaxItems: 100
|
|
46
|
+
};
|
|
47
|
+
var EVENT_NAME_PATTERN = /^[a-z][a-z0-9_.]{0,63}$/;
|
|
48
|
+
function currencyExponent(currency) {
|
|
49
|
+
const digits = new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
|
|
50
|
+
return digits ?? 2;
|
|
51
|
+
}
|
|
52
|
+
function money(major, currency) {
|
|
53
|
+
const code = currency.toUpperCase();
|
|
54
|
+
const factor = 10 ** currencyExponent(code);
|
|
55
|
+
return { amount: Math.round(major * factor), currency: code };
|
|
56
|
+
}
|
|
57
|
+
function toMajor(value) {
|
|
58
|
+
return value.amount / 10 ** currencyExponent(value.currency);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
CANONICAL_EVENTS,
|
|
63
|
+
isCanonicalEvent,
|
|
64
|
+
SERVER_AUTHORITATIVE_EVENTS,
|
|
65
|
+
EPHEMERAL_EVENTS,
|
|
66
|
+
LIMITS,
|
|
67
|
+
EVENT_NAME_PATTERN,
|
|
68
|
+
currencyExponent,
|
|
69
|
+
money,
|
|
70
|
+
toMajor
|
|
71
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/constants.ts
|
|
21
|
+
var constants_exports = {};
|
|
22
|
+
__export(constants_exports, {
|
|
23
|
+
CANONICAL_EVENTS: () => CANONICAL_EVENTS,
|
|
24
|
+
EPHEMERAL_EVENTS: () => EPHEMERAL_EVENTS,
|
|
25
|
+
EVENT_NAME_PATTERN: () => EVENT_NAME_PATTERN,
|
|
26
|
+
LIMITS: () => LIMITS,
|
|
27
|
+
SERVER_AUTHORITATIVE_EVENTS: () => SERVER_AUTHORITATIVE_EVENTS,
|
|
28
|
+
currencyExponent: () => currencyExponent,
|
|
29
|
+
isCanonicalEvent: () => isCanonicalEvent,
|
|
30
|
+
money: () => money,
|
|
31
|
+
toMajor: () => toMajor
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(constants_exports);
|
|
34
|
+
var CANONICAL_EVENTS = [
|
|
35
|
+
"page_viewed",
|
|
36
|
+
"product_viewed",
|
|
37
|
+
"collection_viewed",
|
|
38
|
+
"search_performed",
|
|
39
|
+
"add_to_cart",
|
|
40
|
+
"remove_from_cart",
|
|
41
|
+
"cart_updated",
|
|
42
|
+
"checkout_started",
|
|
43
|
+
"checkout_step_viewed",
|
|
44
|
+
"customer_information_entered",
|
|
45
|
+
"shipping_selected",
|
|
46
|
+
"payment_started",
|
|
47
|
+
"payment_failed",
|
|
48
|
+
"payment_authorized",
|
|
49
|
+
"order_completed",
|
|
50
|
+
"order_cancelled",
|
|
51
|
+
"refund_created",
|
|
52
|
+
"session_heartbeat"
|
|
53
|
+
];
|
|
54
|
+
var canonicalSet = new Set(CANONICAL_EVENTS);
|
|
55
|
+
function isCanonicalEvent(name) {
|
|
56
|
+
return canonicalSet.has(name);
|
|
57
|
+
}
|
|
58
|
+
var SERVER_AUTHORITATIVE_EVENTS = /* @__PURE__ */ new Set([
|
|
59
|
+
"payment_failed",
|
|
60
|
+
"payment_authorized",
|
|
61
|
+
"order_completed",
|
|
62
|
+
"order_cancelled",
|
|
63
|
+
"refund_created"
|
|
64
|
+
]);
|
|
65
|
+
var EPHEMERAL_EVENTS = /* @__PURE__ */ new Set(["session_heartbeat"]);
|
|
66
|
+
var LIMITS = {
|
|
67
|
+
batchMaxEvents: 100,
|
|
68
|
+
batchMaxBytes: 256 * 1024,
|
|
69
|
+
propertiesMaxBytes: 4 * 1024,
|
|
70
|
+
propertiesMaxDepth: 4,
|
|
71
|
+
stringMaxLength: 1024,
|
|
72
|
+
urlMaxLength: 2048,
|
|
73
|
+
idMaxLength: 128,
|
|
74
|
+
sessionIdMaxLength: 64,
|
|
75
|
+
eventNameMaxLength: 64,
|
|
76
|
+
searchQueryMaxLength: 100,
|
|
77
|
+
orderMaxItems: 100
|
|
78
|
+
};
|
|
79
|
+
var EVENT_NAME_PATTERN = /^[a-z][a-z0-9_.]{0,63}$/;
|
|
80
|
+
function currencyExponent(currency) {
|
|
81
|
+
const digits = new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits;
|
|
82
|
+
return digits ?? 2;
|
|
83
|
+
}
|
|
84
|
+
function money(major, currency) {
|
|
85
|
+
const code = currency.toUpperCase();
|
|
86
|
+
const factor = 10 ** currencyExponent(code);
|
|
87
|
+
return { amount: Math.round(major * factor), currency: code };
|
|
88
|
+
}
|
|
89
|
+
function toMajor(value) {
|
|
90
|
+
return value.amount / 10 ** currencyExponent(value.currency);
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
CANONICAL_EVENTS,
|
|
95
|
+
EPHEMERAL_EVENTS,
|
|
96
|
+
EVENT_NAME_PATTERN,
|
|
97
|
+
LIMITS,
|
|
98
|
+
SERVER_AUTHORITATIVE_EVENTS,
|
|
99
|
+
currencyExponent,
|
|
100
|
+
isCanonicalEvent,
|
|
101
|
+
money,
|
|
102
|
+
toMajor
|
|
103
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod-free part of the event contract. Safe to import from the browser SDK:
|
|
3
|
+
* it must stay dependency-free so the SDK stays under its size budget.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CANONICAL_EVENTS: readonly ["page_viewed", "product_viewed", "collection_viewed", "search_performed", "add_to_cart", "remove_from_cart", "cart_updated", "checkout_started", "checkout_step_viewed", "customer_information_entered", "shipping_selected", "payment_started", "payment_failed", "payment_authorized", "order_completed", "order_cancelled", "refund_created", "session_heartbeat"];
|
|
6
|
+
export type CanonicalEventName = (typeof CANONICAL_EVENTS)[number];
|
|
7
|
+
export declare function isCanonicalEvent(name: string): name is CanonicalEventName;
|
|
8
|
+
/**
|
|
9
|
+
* Events that move or confirm money. Only server (secret-key) ingestion may
|
|
10
|
+
* produce authoritative versions; from a browser key they are recorded with
|
|
11
|
+
* source = "browser" and treated as hints.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SERVER_AUTHORITATIVE_EVENTS: ReadonlySet<CanonicalEventName>;
|
|
14
|
+
/** Ephemeral events that update live presence but are never persisted. */
|
|
15
|
+
export declare const EPHEMERAL_EVENTS: ReadonlySet<CanonicalEventName>;
|
|
16
|
+
export declare const LIMITS: {
|
|
17
|
+
readonly batchMaxEvents: 100;
|
|
18
|
+
readonly batchMaxBytes: number;
|
|
19
|
+
readonly propertiesMaxBytes: number;
|
|
20
|
+
readonly propertiesMaxDepth: 4;
|
|
21
|
+
readonly stringMaxLength: 1024;
|
|
22
|
+
readonly urlMaxLength: 2048;
|
|
23
|
+
readonly idMaxLength: 128;
|
|
24
|
+
readonly sessionIdMaxLength: 64;
|
|
25
|
+
readonly eventNameMaxLength: 64;
|
|
26
|
+
readonly searchQueryMaxLength: 100;
|
|
27
|
+
readonly orderMaxItems: 100;
|
|
28
|
+
};
|
|
29
|
+
export declare const EVENT_NAME_PATTERN: RegExp;
|
|
30
|
+
/** Money in integer minor units (öre, cents) with an explicit ISO-4217 code. */
|
|
31
|
+
export type Money = {
|
|
32
|
+
amount: number;
|
|
33
|
+
currency: string;
|
|
34
|
+
};
|
|
35
|
+
/** Number of minor-unit digits for a currency (SEK → 2, JPY → 0, KWD → 3). */
|
|
36
|
+
export declare function currencyExponent(currency: string): number;
|
|
37
|
+
/**
|
|
38
|
+
* Build a Money value from a *major*-unit amount, e.g. `money(1249, "SEK")`
|
|
39
|
+
* → `{ amount: 124900, currency: "SEK" }`. Throws on an unknown currency.
|
|
40
|
+
*/
|
|
41
|
+
export declare function money(major: number, currency: string): Money;
|
|
42
|
+
/** Inverse of `money()`: minor units → major-unit number, for display. */
|
|
43
|
+
export declare function toMajor(value: Money): number;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod-free part of the event contract. Safe to import from the browser SDK:
|
|
3
|
+
* it must stay dependency-free so the SDK stays under its size budget.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CANONICAL_EVENTS: readonly ["page_viewed", "product_viewed", "collection_viewed", "search_performed", "add_to_cart", "remove_from_cart", "cart_updated", "checkout_started", "checkout_step_viewed", "customer_information_entered", "shipping_selected", "payment_started", "payment_failed", "payment_authorized", "order_completed", "order_cancelled", "refund_created", "session_heartbeat"];
|
|
6
|
+
export type CanonicalEventName = (typeof CANONICAL_EVENTS)[number];
|
|
7
|
+
export declare function isCanonicalEvent(name: string): name is CanonicalEventName;
|
|
8
|
+
/**
|
|
9
|
+
* Events that move or confirm money. Only server (secret-key) ingestion may
|
|
10
|
+
* produce authoritative versions; from a browser key they are recorded with
|
|
11
|
+
* source = "browser" and treated as hints.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SERVER_AUTHORITATIVE_EVENTS: ReadonlySet<CanonicalEventName>;
|
|
14
|
+
/** Ephemeral events that update live presence but are never persisted. */
|
|
15
|
+
export declare const EPHEMERAL_EVENTS: ReadonlySet<CanonicalEventName>;
|
|
16
|
+
export declare const LIMITS: {
|
|
17
|
+
readonly batchMaxEvents: 100;
|
|
18
|
+
readonly batchMaxBytes: number;
|
|
19
|
+
readonly propertiesMaxBytes: number;
|
|
20
|
+
readonly propertiesMaxDepth: 4;
|
|
21
|
+
readonly stringMaxLength: 1024;
|
|
22
|
+
readonly urlMaxLength: 2048;
|
|
23
|
+
readonly idMaxLength: 128;
|
|
24
|
+
readonly sessionIdMaxLength: 64;
|
|
25
|
+
readonly eventNameMaxLength: 64;
|
|
26
|
+
readonly searchQueryMaxLength: 100;
|
|
27
|
+
readonly orderMaxItems: 100;
|
|
28
|
+
};
|
|
29
|
+
export declare const EVENT_NAME_PATTERN: RegExp;
|
|
30
|
+
/** Money in integer minor units (öre, cents) with an explicit ISO-4217 code. */
|
|
31
|
+
export type Money = {
|
|
32
|
+
amount: number;
|
|
33
|
+
currency: string;
|
|
34
|
+
};
|
|
35
|
+
/** Number of minor-unit digits for a currency (SEK → 2, JPY → 0, KWD → 3). */
|
|
36
|
+
export declare function currencyExponent(currency: string): number;
|
|
37
|
+
/**
|
|
38
|
+
* Build a Money value from a *major*-unit amount, e.g. `money(1249, "SEK")`
|
|
39
|
+
* → `{ amount: 124900, currency: "SEK" }`. Throws on an unknown currency.
|
|
40
|
+
*/
|
|
41
|
+
export declare function money(major: number, currency: string): Money;
|
|
42
|
+
/** Inverse of `money()`: minor units → major-unit number, for display. */
|
|
43
|
+
export declare function toMajor(value: Money): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CANONICAL_EVENTS,
|
|
3
|
+
EPHEMERAL_EVENTS,
|
|
4
|
+
EVENT_NAME_PATTERN,
|
|
5
|
+
LIMITS,
|
|
6
|
+
SERVER_AUTHORITATIVE_EVENTS,
|
|
7
|
+
currencyExponent,
|
|
8
|
+
isCanonicalEvent,
|
|
9
|
+
money,
|
|
10
|
+
toMajor
|
|
11
|
+
} from "./chunk-MEHWUFJG.js";
|
|
12
|
+
export {
|
|
13
|
+
CANONICAL_EVENTS,
|
|
14
|
+
EPHEMERAL_EVENTS,
|
|
15
|
+
EVENT_NAME_PATTERN,
|
|
16
|
+
LIMITS,
|
|
17
|
+
SERVER_AUTHORITATIVE_EVENTS,
|
|
18
|
+
currencyExponent,
|
|
19
|
+
isCanonicalEvent,
|
|
20
|
+
money,
|
|
21
|
+
toMajor
|
|
22
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type CanonicalEventName } from "./constants.cjs";
|
|
3
|
+
import { type CanonicalProperties } from "./events.cjs";
|
|
4
|
+
import { type Json } from "./primitives.cjs";
|
|
5
|
+
export declare const ContextSchema: z.ZodObject<{
|
|
6
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
path: z.ZodOptional<z.ZodString>;
|
|
9
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
10
|
+
title: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
utm: z.ZodOptional<z.ZodObject<{
|
|
13
|
+
source: z.ZodOptional<z.ZodString>;
|
|
14
|
+
medium: z.ZodOptional<z.ZodString>;
|
|
15
|
+
campaign: z.ZodOptional<z.ZodString>;
|
|
16
|
+
term: z.ZodOptional<z.ZodString>;
|
|
17
|
+
content: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
20
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
21
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
22
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
width: z.ZodNumber;
|
|
24
|
+
height: z.ZodNumber;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
trace: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
traceId: z.ZodString;
|
|
28
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
library: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
consent: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
denied: "denied";
|
|
36
|
+
granted: "granted";
|
|
37
|
+
pending: "pending";
|
|
38
|
+
}>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/** Envelope fields. Tenant fields (org/project/environment) are deliberately absent. */
|
|
41
|
+
export declare const WireEventSchema: z.ZodObject<{
|
|
42
|
+
eventId: z.ZodUUID;
|
|
43
|
+
name: z.ZodString;
|
|
44
|
+
timestamp: z.ZodISODateTime;
|
|
45
|
+
sessionId: z.ZodString;
|
|
46
|
+
anonymousId: z.ZodOptional<z.ZodString>;
|
|
47
|
+
customerId: z.ZodOptional<z.ZodString>;
|
|
48
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>>;
|
|
49
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
url: z.ZodOptional<z.ZodString>;
|
|
52
|
+
path: z.ZodOptional<z.ZodString>;
|
|
53
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
54
|
+
title: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
utm: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
source: z.ZodOptional<z.ZodString>;
|
|
58
|
+
medium: z.ZodOptional<z.ZodString>;
|
|
59
|
+
campaign: z.ZodOptional<z.ZodString>;
|
|
60
|
+
term: z.ZodOptional<z.ZodString>;
|
|
61
|
+
content: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
64
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
65
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
66
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
width: z.ZodNumber;
|
|
68
|
+
height: z.ZodNumber;
|
|
69
|
+
}, z.core.$strip>>;
|
|
70
|
+
trace: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
traceId: z.ZodString;
|
|
72
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
library: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
name: z.ZodString;
|
|
76
|
+
version: z.ZodString;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
consent: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
denied: "denied";
|
|
80
|
+
granted: "granted";
|
|
81
|
+
pending: "pending";
|
|
82
|
+
}>>;
|
|
83
|
+
}, z.core.$strip>>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
export declare const WireBatchSchema: z.ZodObject<{
|
|
86
|
+
sentAt: z.ZodOptional<z.ZodISODateTime>;
|
|
87
|
+
key: z.ZodOptional<z.ZodString>;
|
|
88
|
+
batch: z.ZodArray<z.ZodUnknown>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export type WireEvent = z.infer<typeof WireEventSchema>;
|
|
91
|
+
export type WireBatch = z.infer<typeof WireBatchSchema>;
|
|
92
|
+
export type EventContext = z.infer<typeof ContextSchema>;
|
|
93
|
+
export type ValidatedEvent = (Omit<WireEvent, "name" | "properties"> & {
|
|
94
|
+
kind: "canonical";
|
|
95
|
+
name: CanonicalEventName;
|
|
96
|
+
properties: CanonicalProperties[CanonicalEventName];
|
|
97
|
+
}) | (Omit<WireEvent, "properties"> & {
|
|
98
|
+
kind: "custom";
|
|
99
|
+
properties: Record<string, Json>;
|
|
100
|
+
});
|
|
101
|
+
export type ValidationIssue = {
|
|
102
|
+
path: string;
|
|
103
|
+
message: string;
|
|
104
|
+
};
|
|
105
|
+
export type ValidationResult = {
|
|
106
|
+
ok: true;
|
|
107
|
+
event: ValidatedEvent;
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
eventId: string | undefined;
|
|
111
|
+
issues: ValidationIssue[];
|
|
112
|
+
};
|
|
113
|
+
/** Validate one raw event: envelope first, then canonical properties by name. */
|
|
114
|
+
export declare function validateEvent(raw: unknown): ValidationResult;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type CanonicalEventName } from "./constants.js";
|
|
3
|
+
import { type CanonicalProperties } from "./events.js";
|
|
4
|
+
import { type Json } from "./primitives.js";
|
|
5
|
+
export declare const ContextSchema: z.ZodObject<{
|
|
6
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
path: z.ZodOptional<z.ZodString>;
|
|
9
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
10
|
+
title: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
utm: z.ZodOptional<z.ZodObject<{
|
|
13
|
+
source: z.ZodOptional<z.ZodString>;
|
|
14
|
+
medium: z.ZodOptional<z.ZodString>;
|
|
15
|
+
campaign: z.ZodOptional<z.ZodString>;
|
|
16
|
+
term: z.ZodOptional<z.ZodString>;
|
|
17
|
+
content: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
20
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
21
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
22
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
width: z.ZodNumber;
|
|
24
|
+
height: z.ZodNumber;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
trace: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
traceId: z.ZodString;
|
|
28
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
library: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
consent: z.ZodOptional<z.ZodEnum<{
|
|
35
|
+
denied: "denied";
|
|
36
|
+
granted: "granted";
|
|
37
|
+
pending: "pending";
|
|
38
|
+
}>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
/** Envelope fields. Tenant fields (org/project/environment) are deliberately absent. */
|
|
41
|
+
export declare const WireEventSchema: z.ZodObject<{
|
|
42
|
+
eventId: z.ZodUUID;
|
|
43
|
+
name: z.ZodString;
|
|
44
|
+
timestamp: z.ZodISODateTime;
|
|
45
|
+
sessionId: z.ZodString;
|
|
46
|
+
anonymousId: z.ZodOptional<z.ZodString>;
|
|
47
|
+
customerId: z.ZodOptional<z.ZodString>;
|
|
48
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>>;
|
|
49
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
50
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
url: z.ZodOptional<z.ZodString>;
|
|
52
|
+
path: z.ZodOptional<z.ZodString>;
|
|
53
|
+
referrer: z.ZodOptional<z.ZodString>;
|
|
54
|
+
title: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
utm: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
source: z.ZodOptional<z.ZodString>;
|
|
58
|
+
medium: z.ZodOptional<z.ZodString>;
|
|
59
|
+
campaign: z.ZodOptional<z.ZodString>;
|
|
60
|
+
term: z.ZodOptional<z.ZodString>;
|
|
61
|
+
content: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
64
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
65
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
66
|
+
screen: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
width: z.ZodNumber;
|
|
68
|
+
height: z.ZodNumber;
|
|
69
|
+
}, z.core.$strip>>;
|
|
70
|
+
trace: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
traceId: z.ZodString;
|
|
72
|
+
spanId: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
library: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
name: z.ZodString;
|
|
76
|
+
version: z.ZodString;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
consent: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
denied: "denied";
|
|
80
|
+
granted: "granted";
|
|
81
|
+
pending: "pending";
|
|
82
|
+
}>>;
|
|
83
|
+
}, z.core.$strip>>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
export declare const WireBatchSchema: z.ZodObject<{
|
|
86
|
+
sentAt: z.ZodOptional<z.ZodISODateTime>;
|
|
87
|
+
key: z.ZodOptional<z.ZodString>;
|
|
88
|
+
batch: z.ZodArray<z.ZodUnknown>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export type WireEvent = z.infer<typeof WireEventSchema>;
|
|
91
|
+
export type WireBatch = z.infer<typeof WireBatchSchema>;
|
|
92
|
+
export type EventContext = z.infer<typeof ContextSchema>;
|
|
93
|
+
export type ValidatedEvent = (Omit<WireEvent, "name" | "properties"> & {
|
|
94
|
+
kind: "canonical";
|
|
95
|
+
name: CanonicalEventName;
|
|
96
|
+
properties: CanonicalProperties[CanonicalEventName];
|
|
97
|
+
}) | (Omit<WireEvent, "properties"> & {
|
|
98
|
+
kind: "custom";
|
|
99
|
+
properties: Record<string, Json>;
|
|
100
|
+
});
|
|
101
|
+
export type ValidationIssue = {
|
|
102
|
+
path: string;
|
|
103
|
+
message: string;
|
|
104
|
+
};
|
|
105
|
+
export type ValidationResult = {
|
|
106
|
+
ok: true;
|
|
107
|
+
event: ValidatedEvent;
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
eventId: string | undefined;
|
|
111
|
+
issues: ValidationIssue[];
|
|
112
|
+
};
|
|
113
|
+
/** Validate one raw event: envelope first, then canonical properties by name. */
|
|
114
|
+
export declare function validateEvent(raw: unknown): ValidationResult;
|