@od-oneapp/analytics 2026.1.1301
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +509 -0
- package/dist/ai-YMnynb-t.mjs +3347 -0
- package/dist/ai-YMnynb-t.mjs.map +1 -0
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/client-CTzJVFU5.mjs +9 -0
- package/dist/client-CTzJVFU5.mjs.map +1 -0
- package/dist/client-CcFTauAh.mjs +54 -0
- package/dist/client-CcFTauAh.mjs.map +1 -0
- package/dist/client-CeOLjbac.mjs +281 -0
- package/dist/client-CeOLjbac.mjs.map +1 -0
- package/dist/client-D339NFJS.mjs +267 -0
- package/dist/client-D339NFJS.mjs.map +1 -0
- package/dist/client-next.d.mts +62 -0
- package/dist/client-next.d.mts.map +1 -0
- package/dist/client-next.mjs +525 -0
- package/dist/client-next.mjs.map +1 -0
- package/dist/client.d.mts +30 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +186 -0
- package/dist/client.mjs.map +1 -0
- package/dist/config-DPS6bSYo.d.mts +34 -0
- package/dist/config-DPS6bSYo.d.mts.map +1 -0
- package/dist/config-P6P5adJg.mjs +287 -0
- package/dist/config-P6P5adJg.mjs.map +1 -0
- package/dist/console-8bND3mMU.mjs +128 -0
- package/dist/console-8bND3mMU.mjs.map +1 -0
- package/dist/ecommerce-Cgu4wlux.mjs +993 -0
- package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
- package/dist/emitters-6-nKo8i-.mjs +208 -0
- package/dist/emitters-6-nKo8i-.mjs.map +1 -0
- package/dist/emitters-DldkVSPp.d.mts +12 -0
- package/dist/emitters-DldkVSPp.d.mts.map +1 -0
- package/dist/index-BfNWgfa5.d.mts +1494 -0
- package/dist/index-BfNWgfa5.d.mts.map +1 -0
- package/dist/index-BkIWe--N.d.mts +953 -0
- package/dist/index-BkIWe--N.d.mts.map +1 -0
- package/dist/index-jPzXRn52.d.mts +184 -0
- package/dist/index-jPzXRn52.d.mts.map +1 -0
- package/dist/manager-DvRRjza6.d.mts +76 -0
- package/dist/manager-DvRRjza6.d.mts.map +1 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
- package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
- package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
- package/dist/providers-http-client.d.mts +37 -0
- package/dist/providers-http-client.d.mts.map +1 -0
- package/dist/providers-http-client.mjs +320 -0
- package/dist/providers-http-client.mjs.map +1 -0
- package/dist/providers-http-server.d.mts +31 -0
- package/dist/providers-http-server.d.mts.map +1 -0
- package/dist/providers-http-server.mjs +297 -0
- package/dist/providers-http-server.mjs.map +1 -0
- package/dist/providers-http.d.mts +46 -0
- package/dist/providers-http.d.mts.map +1 -0
- package/dist/providers-http.mjs +4 -0
- package/dist/server-edge.d.mts +9 -0
- package/dist/server-edge.d.mts.map +1 -0
- package/dist/server-edge.mjs +373 -0
- package/dist/server-edge.mjs.map +1 -0
- package/dist/server-next.d.mts +67 -0
- package/dist/server-next.d.mts.map +1 -0
- package/dist/server-next.mjs +193 -0
- package/dist/server-next.mjs.map +1 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +7 -0
- package/dist/service-cYtBBL8x.mjs +945 -0
- package/dist/service-cYtBBL8x.mjs.map +1 -0
- package/dist/shared.d.mts +16 -0
- package/dist/shared.d.mts.map +1 -0
- package/dist/shared.mjs +93 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/types-BxBnNQ0V.d.mts +354 -0
- package/dist/types-BxBnNQ0V.d.mts.map +1 -0
- package/dist/types-CBvxUEaF.d.mts +216 -0
- package/dist/types-CBvxUEaF.d.mts.map +1 -0
- package/dist/types.d.mts +4 -0
- package/dist/types.mjs +0 -0
- package/dist/vercel-types-lwakUfoI.d.mts +102 -0
- package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
- package/package.json +129 -0
- package/src/client/index.ts +164 -0
- package/src/client/manager.ts +71 -0
- package/src/client/next/components.tsx +270 -0
- package/src/client/next/hooks.ts +217 -0
- package/src/client/next/manager.ts +141 -0
- package/src/client/next.ts +144 -0
- package/src/client-next.ts +101 -0
- package/src/client.ts +89 -0
- package/src/examples/ai-sdk-patterns.ts +583 -0
- package/src/examples/emitter-patterns.ts +476 -0
- package/src/examples/nextjs-emitter-patterns.tsx +403 -0
- package/src/next/app-router.tsx +564 -0
- package/src/next/client.ts +419 -0
- package/src/next/index.ts +84 -0
- package/src/next/middleware.ts +429 -0
- package/src/next/rsc.tsx +300 -0
- package/src/next/server.ts +253 -0
- package/src/next/types.d.ts +220 -0
- package/src/providers/base-provider.ts +419 -0
- package/src/providers/console/client.ts +10 -0
- package/src/providers/console/index.ts +152 -0
- package/src/providers/console/server.ts +6 -0
- package/src/providers/console/types.ts +15 -0
- package/src/providers/http/client.ts +464 -0
- package/src/providers/http/index.ts +30 -0
- package/src/providers/http/server.ts +396 -0
- package/src/providers/http/types.ts +135 -0
- package/src/providers/posthog/client.ts +518 -0
- package/src/providers/posthog/index.ts +11 -0
- package/src/providers/posthog/server.ts +329 -0
- package/src/providers/posthog/types.ts +104 -0
- package/src/providers/segment/client.ts +113 -0
- package/src/providers/segment/index.ts +11 -0
- package/src/providers/segment/server.ts +115 -0
- package/src/providers/segment/types.ts +51 -0
- package/src/providers/vercel/client.ts +102 -0
- package/src/providers/vercel/index.ts +11 -0
- package/src/providers/vercel/server.ts +89 -0
- package/src/providers/vercel/types.ts +27 -0
- package/src/server/index.ts +103 -0
- package/src/server/manager.ts +62 -0
- package/src/server/next.ts +210 -0
- package/src/server-edge.ts +442 -0
- package/src/server-next.ts +39 -0
- package/src/server.ts +106 -0
- package/src/shared/emitters/ai/README.md +981 -0
- package/src/shared/emitters/ai/events/agent.ts +130 -0
- package/src/shared/emitters/ai/events/artifacts.ts +167 -0
- package/src/shared/emitters/ai/events/chat.ts +126 -0
- package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
- package/src/shared/emitters/ai/events/completion.ts +103 -0
- package/src/shared/emitters/ai/events/content-generation.ts +347 -0
- package/src/shared/emitters/ai/events/conversation.ts +332 -0
- package/src/shared/emitters/ai/events/product-features.ts +1402 -0
- package/src/shared/emitters/ai/events/streaming.ts +114 -0
- package/src/shared/emitters/ai/events/tool.ts +93 -0
- package/src/shared/emitters/ai/index.ts +69 -0
- package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
- package/src/shared/emitters/ai/track-ai.ts +50 -0
- package/src/shared/emitters/ai/types.ts +1041 -0
- package/src/shared/emitters/ai/utils.ts +468 -0
- package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
- package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
- package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
- package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
- package/src/shared/emitters/ecommerce/events/order.ts +199 -0
- package/src/shared/emitters/ecommerce/events/product.ts +205 -0
- package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
- package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
- package/src/shared/emitters/ecommerce/index.ts +46 -0
- package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
- package/src/shared/emitters/ecommerce/types.ts +314 -0
- package/src/shared/emitters/ecommerce/utils.ts +216 -0
- package/src/shared/emitters/emitter-types.ts +974 -0
- package/src/shared/emitters/emitters.ts +292 -0
- package/src/shared/emitters/helpers.ts +419 -0
- package/src/shared/emitters/index.ts +66 -0
- package/src/shared/index.ts +142 -0
- package/src/shared/ingestion/index.ts +66 -0
- package/src/shared/ingestion/schemas.ts +386 -0
- package/src/shared/ingestion/service.ts +628 -0
- package/src/shared/node22-features.ts +848 -0
- package/src/shared/providers/console-provider.ts +160 -0
- package/src/shared/types/base-types.ts +54 -0
- package/src/shared/types/console-types.ts +19 -0
- package/src/shared/types/posthog-types.ts +131 -0
- package/src/shared/types/segment-types.ts +15 -0
- package/src/shared/types/types.ts +397 -0
- package/src/shared/types/vercel-types.ts +19 -0
- package/src/shared/utils/config-client.ts +19 -0
- package/src/shared/utils/config.ts +250 -0
- package/src/shared/utils/emitter-adapter.ts +212 -0
- package/src/shared/utils/manager.test.ts +36 -0
- package/src/shared/utils/manager.ts +1322 -0
- package/src/shared/utils/posthog-bootstrap.ts +136 -0
- package/src/shared/utils/posthog-client-utils.ts +48 -0
- package/src/shared/utils/posthog-next-utils.ts +282 -0
- package/src/shared/utils/posthog-server-utils.ts +210 -0
- package/src/shared/utils/rate-limit.ts +289 -0
- package/src/shared/utils/security.ts +545 -0
- package/src/shared/utils/validation-client.ts +161 -0
- package/src/shared/utils/validation.ts +399 -0
- package/src/shared.ts +155 -0
- package/src/types/index.ts +62 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utilities for normalizing and validating ecommerce event properties
|
|
3
|
+
* Utilities for normalizing and validating ecommerce event properties
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { BaseProductProperties, EcommerceEventProperties } from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Input product type for normalization functions
|
|
10
|
+
* Accepts various property naming conventions
|
|
11
|
+
*/
|
|
12
|
+
interface ProductInput {
|
|
13
|
+
// ID variations
|
|
14
|
+
product_id?: string;
|
|
15
|
+
productId?: string;
|
|
16
|
+
id?: string;
|
|
17
|
+
// Name variations
|
|
18
|
+
name?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
productName?: string;
|
|
21
|
+
// Image URL variations
|
|
22
|
+
image_url?: string;
|
|
23
|
+
imageUrl?: string;
|
|
24
|
+
image?: string;
|
|
25
|
+
// URL variations
|
|
26
|
+
url?: string;
|
|
27
|
+
link?: string;
|
|
28
|
+
product_url?: string;
|
|
29
|
+
// Other properties
|
|
30
|
+
brand?: string;
|
|
31
|
+
manufacturer?: string;
|
|
32
|
+
category?: string;
|
|
33
|
+
coupon?: string;
|
|
34
|
+
couponCode?: string;
|
|
35
|
+
coupon_code?: string;
|
|
36
|
+
position?: number | string;
|
|
37
|
+
price?: number | string;
|
|
38
|
+
quantity?: number | string;
|
|
39
|
+
variant?: string;
|
|
40
|
+
variation?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes product properties to ensure consistent naming
|
|
46
|
+
* Handles common variations like productId vs product_id
|
|
47
|
+
*/
|
|
48
|
+
export function normalizeProductProperties(
|
|
49
|
+
product?: ProductInput | unknown,
|
|
50
|
+
): BaseProductProperties {
|
|
51
|
+
if (!product || typeof product !== 'object') {
|
|
52
|
+
throw new Error('Product properties are required');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const p = product as ProductInput;
|
|
56
|
+
|
|
57
|
+
// Normalize product ID (required) - using ES2022 nullish coalescing
|
|
58
|
+
const product_id = p.product_id ?? p.productId ?? p.id;
|
|
59
|
+
if (!product_id) {
|
|
60
|
+
throw new Error('Product must have an id (product_id, productId, or id)');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const normalized = {
|
|
64
|
+
product_id,
|
|
65
|
+
name: p.name ?? p.title ?? p.productName,
|
|
66
|
+
image_url: p.image_url ?? p.imageUrl ?? p.image,
|
|
67
|
+
url: p.url ?? p.link ?? p.product_url,
|
|
68
|
+
brand: p.brand ?? p.manufacturer,
|
|
69
|
+
category: p.category,
|
|
70
|
+
coupon: p.coupon ?? p.couponCode ?? p.coupon_code,
|
|
71
|
+
position: normalizePosition(p.position),
|
|
72
|
+
price: normalizePrice(p.price),
|
|
73
|
+
quantity: normalizeQuantity(p.quantity),
|
|
74
|
+
variant: p.variant ?? p.variation,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Remove undefined and null values - using ES2022 Object.hasOwn
|
|
78
|
+
const result: BaseProductProperties = { product_id };
|
|
79
|
+
Object.entries(normalized).forEach(([key, value]) => {
|
|
80
|
+
if (
|
|
81
|
+
value !== undefined &&
|
|
82
|
+
value !== null &&
|
|
83
|
+
Object.hasOwn(normalized, key) &&
|
|
84
|
+
key !== 'product_id'
|
|
85
|
+
) {
|
|
86
|
+
// Cast to any to allow dynamic property assignment
|
|
87
|
+
(result as any)[key] = value;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Normalizes an array of products
|
|
96
|
+
*/
|
|
97
|
+
export function normalizeProducts(products: unknown[]): BaseProductProperties[] {
|
|
98
|
+
if (!Array.isArray(products)) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
return products.map(product => normalizeProductProperties(product as ProductInput));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* ES2022 enhanced product validation with Error.cause
|
|
106
|
+
*/
|
|
107
|
+
export function validateProductWithContext(product: unknown, context?: string): void {
|
|
108
|
+
try {
|
|
109
|
+
normalizeProductProperties(product as ProductInput);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error(`Product validation failed${context ? ` in ${context}` : ''}`, {
|
|
112
|
+
cause: error,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Normalizes price to a number
|
|
119
|
+
*/
|
|
120
|
+
function normalizePrice(price: unknown): number | undefined {
|
|
121
|
+
if (price === undefined || price === null) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
const normalized = typeof price === 'string' ? Number.parseFloat(price) : Number(price);
|
|
125
|
+
return Number.isNaN(normalized) ? undefined : normalized;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Normalizes quantity to a positive integer
|
|
130
|
+
*/
|
|
131
|
+
function normalizeQuantity(quantity: unknown): number | undefined {
|
|
132
|
+
if (quantity === undefined || quantity === null) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
const normalized = Number.parseInt(String(quantity), 10);
|
|
136
|
+
return Number.isNaN(normalized) || normalized < 0 ? undefined : normalized;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Normalizes position to a positive integer
|
|
141
|
+
*/
|
|
142
|
+
function normalizePosition(position: unknown): number | undefined {
|
|
143
|
+
if (position === undefined || position === null) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const normalized = Number.parseInt(String(position), 10);
|
|
147
|
+
return Number.isNaN(normalized) || normalized < 0 ? undefined : normalized;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Validates required properties for an event
|
|
152
|
+
*/
|
|
153
|
+
export function validateRequiredProperties<T extends Record<string, any>>(
|
|
154
|
+
properties: T,
|
|
155
|
+
required: (keyof T)[],
|
|
156
|
+
): void {
|
|
157
|
+
const missing = required.filter(prop => {
|
|
158
|
+
const value = properties[prop];
|
|
159
|
+
return value === undefined || value === null || value === '';
|
|
160
|
+
});
|
|
161
|
+
if (missing.length > 0) {
|
|
162
|
+
throw new Error(`Missing required properties: ${missing.join(', ')}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Removes undefined values from an object
|
|
168
|
+
*/
|
|
169
|
+
export function cleanProperties<T extends Record<string, any>>(obj: T): Partial<T> {
|
|
170
|
+
const cleaned: Partial<T> = {};
|
|
171
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
172
|
+
if (value !== undefined) {
|
|
173
|
+
cleaned[key as keyof T] = value;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return cleaned;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Merges common fields with event-specific properties
|
|
181
|
+
*/
|
|
182
|
+
export function mergeEventProperties(
|
|
183
|
+
specific: EcommerceEventProperties,
|
|
184
|
+
common?: Record<string, any>,
|
|
185
|
+
): EcommerceEventProperties {
|
|
186
|
+
return {
|
|
187
|
+
...common,
|
|
188
|
+
...specific,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Validates currency code (ISO 4217)
|
|
194
|
+
*/
|
|
195
|
+
export function validateCurrency(currency?: string): string | undefined {
|
|
196
|
+
if (!currency || typeof currency !== 'string') return undefined;
|
|
197
|
+
|
|
198
|
+
// Basic validation - should be 3 uppercase letters
|
|
199
|
+
const normalized = currency.toUpperCase();
|
|
200
|
+
if (!/^[A-Z]{3}$/.test(normalized)) {
|
|
201
|
+
// Invalid currency code - return undefined
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return normalized;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Creates a consistent context object for ecommerce events
|
|
210
|
+
*/
|
|
211
|
+
export function createEcommerceContext(additionalContext?: Record<string, any>) {
|
|
212
|
+
return {
|
|
213
|
+
...additionalContext,
|
|
214
|
+
category: 'ecommerce',
|
|
215
|
+
};
|
|
216
|
+
}
|