@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.
Files changed (184) hide show
  1. package/README.md +509 -0
  2. package/dist/ai-YMnynb-t.mjs +3347 -0
  3. package/dist/ai-YMnynb-t.mjs.map +1 -0
  4. package/dist/chunk-DQk6qfdC.mjs +18 -0
  5. package/dist/client-CTzJVFU5.mjs +9 -0
  6. package/dist/client-CTzJVFU5.mjs.map +1 -0
  7. package/dist/client-CcFTauAh.mjs +54 -0
  8. package/dist/client-CcFTauAh.mjs.map +1 -0
  9. package/dist/client-CeOLjbac.mjs +281 -0
  10. package/dist/client-CeOLjbac.mjs.map +1 -0
  11. package/dist/client-D339NFJS.mjs +267 -0
  12. package/dist/client-D339NFJS.mjs.map +1 -0
  13. package/dist/client-next.d.mts +62 -0
  14. package/dist/client-next.d.mts.map +1 -0
  15. package/dist/client-next.mjs +525 -0
  16. package/dist/client-next.mjs.map +1 -0
  17. package/dist/client.d.mts +30 -0
  18. package/dist/client.d.mts.map +1 -0
  19. package/dist/client.mjs +186 -0
  20. package/dist/client.mjs.map +1 -0
  21. package/dist/config-DPS6bSYo.d.mts +34 -0
  22. package/dist/config-DPS6bSYo.d.mts.map +1 -0
  23. package/dist/config-P6P5adJg.mjs +287 -0
  24. package/dist/config-P6P5adJg.mjs.map +1 -0
  25. package/dist/console-8bND3mMU.mjs +128 -0
  26. package/dist/console-8bND3mMU.mjs.map +1 -0
  27. package/dist/ecommerce-Cgu4wlux.mjs +993 -0
  28. package/dist/ecommerce-Cgu4wlux.mjs.map +1 -0
  29. package/dist/emitters-6-nKo8i-.mjs +208 -0
  30. package/dist/emitters-6-nKo8i-.mjs.map +1 -0
  31. package/dist/emitters-DldkVSPp.d.mts +12 -0
  32. package/dist/emitters-DldkVSPp.d.mts.map +1 -0
  33. package/dist/index-BfNWgfa5.d.mts +1494 -0
  34. package/dist/index-BfNWgfa5.d.mts.map +1 -0
  35. package/dist/index-BkIWe--N.d.mts +953 -0
  36. package/dist/index-BkIWe--N.d.mts.map +1 -0
  37. package/dist/index-jPzXRn52.d.mts +184 -0
  38. package/dist/index-jPzXRn52.d.mts.map +1 -0
  39. package/dist/manager-DvRRjza6.d.mts +76 -0
  40. package/dist/manager-DvRRjza6.d.mts.map +1 -0
  41. package/dist/posthog-bootstrap-CYfIy_WS.mjs +1769 -0
  42. package/dist/posthog-bootstrap-CYfIy_WS.mjs.map +1 -0
  43. package/dist/posthog-bootstrap-DWxFrxlt.d.mts +81 -0
  44. package/dist/posthog-bootstrap-DWxFrxlt.d.mts.map +1 -0
  45. package/dist/providers-http-client.d.mts +37 -0
  46. package/dist/providers-http-client.d.mts.map +1 -0
  47. package/dist/providers-http-client.mjs +320 -0
  48. package/dist/providers-http-client.mjs.map +1 -0
  49. package/dist/providers-http-server.d.mts +31 -0
  50. package/dist/providers-http-server.d.mts.map +1 -0
  51. package/dist/providers-http-server.mjs +297 -0
  52. package/dist/providers-http-server.mjs.map +1 -0
  53. package/dist/providers-http.d.mts +46 -0
  54. package/dist/providers-http.d.mts.map +1 -0
  55. package/dist/providers-http.mjs +4 -0
  56. package/dist/server-edge.d.mts +9 -0
  57. package/dist/server-edge.d.mts.map +1 -0
  58. package/dist/server-edge.mjs +373 -0
  59. package/dist/server-edge.mjs.map +1 -0
  60. package/dist/server-next.d.mts +67 -0
  61. package/dist/server-next.d.mts.map +1 -0
  62. package/dist/server-next.mjs +193 -0
  63. package/dist/server-next.mjs.map +1 -0
  64. package/dist/server.d.mts +10 -0
  65. package/dist/server.mjs +7 -0
  66. package/dist/service-cYtBBL8x.mjs +945 -0
  67. package/dist/service-cYtBBL8x.mjs.map +1 -0
  68. package/dist/shared.d.mts +16 -0
  69. package/dist/shared.d.mts.map +1 -0
  70. package/dist/shared.mjs +93 -0
  71. package/dist/shared.mjs.map +1 -0
  72. package/dist/types-BxBnNQ0V.d.mts +354 -0
  73. package/dist/types-BxBnNQ0V.d.mts.map +1 -0
  74. package/dist/types-CBvxUEaF.d.mts +216 -0
  75. package/dist/types-CBvxUEaF.d.mts.map +1 -0
  76. package/dist/types.d.mts +4 -0
  77. package/dist/types.mjs +0 -0
  78. package/dist/vercel-types-lwakUfoI.d.mts +102 -0
  79. package/dist/vercel-types-lwakUfoI.d.mts.map +1 -0
  80. package/package.json +129 -0
  81. package/src/client/index.ts +164 -0
  82. package/src/client/manager.ts +71 -0
  83. package/src/client/next/components.tsx +270 -0
  84. package/src/client/next/hooks.ts +217 -0
  85. package/src/client/next/manager.ts +141 -0
  86. package/src/client/next.ts +144 -0
  87. package/src/client-next.ts +101 -0
  88. package/src/client.ts +89 -0
  89. package/src/examples/ai-sdk-patterns.ts +583 -0
  90. package/src/examples/emitter-patterns.ts +476 -0
  91. package/src/examples/nextjs-emitter-patterns.tsx +403 -0
  92. package/src/next/app-router.tsx +564 -0
  93. package/src/next/client.ts +419 -0
  94. package/src/next/index.ts +84 -0
  95. package/src/next/middleware.ts +429 -0
  96. package/src/next/rsc.tsx +300 -0
  97. package/src/next/server.ts +253 -0
  98. package/src/next/types.d.ts +220 -0
  99. package/src/providers/base-provider.ts +419 -0
  100. package/src/providers/console/client.ts +10 -0
  101. package/src/providers/console/index.ts +152 -0
  102. package/src/providers/console/server.ts +6 -0
  103. package/src/providers/console/types.ts +15 -0
  104. package/src/providers/http/client.ts +464 -0
  105. package/src/providers/http/index.ts +30 -0
  106. package/src/providers/http/server.ts +396 -0
  107. package/src/providers/http/types.ts +135 -0
  108. package/src/providers/posthog/client.ts +518 -0
  109. package/src/providers/posthog/index.ts +11 -0
  110. package/src/providers/posthog/server.ts +329 -0
  111. package/src/providers/posthog/types.ts +104 -0
  112. package/src/providers/segment/client.ts +113 -0
  113. package/src/providers/segment/index.ts +11 -0
  114. package/src/providers/segment/server.ts +115 -0
  115. package/src/providers/segment/types.ts +51 -0
  116. package/src/providers/vercel/client.ts +102 -0
  117. package/src/providers/vercel/index.ts +11 -0
  118. package/src/providers/vercel/server.ts +89 -0
  119. package/src/providers/vercel/types.ts +27 -0
  120. package/src/server/index.ts +103 -0
  121. package/src/server/manager.ts +62 -0
  122. package/src/server/next.ts +210 -0
  123. package/src/server-edge.ts +442 -0
  124. package/src/server-next.ts +39 -0
  125. package/src/server.ts +106 -0
  126. package/src/shared/emitters/ai/README.md +981 -0
  127. package/src/shared/emitters/ai/events/agent.ts +130 -0
  128. package/src/shared/emitters/ai/events/artifacts.ts +167 -0
  129. package/src/shared/emitters/ai/events/chat.ts +126 -0
  130. package/src/shared/emitters/ai/events/chatbot-ecommerce.ts +133 -0
  131. package/src/shared/emitters/ai/events/completion.ts +103 -0
  132. package/src/shared/emitters/ai/events/content-generation.ts +347 -0
  133. package/src/shared/emitters/ai/events/conversation.ts +332 -0
  134. package/src/shared/emitters/ai/events/product-features.ts +1402 -0
  135. package/src/shared/emitters/ai/events/streaming.ts +114 -0
  136. package/src/shared/emitters/ai/events/tool.ts +93 -0
  137. package/src/shared/emitters/ai/index.ts +69 -0
  138. package/src/shared/emitters/ai/track-ai-sdk.ts +74 -0
  139. package/src/shared/emitters/ai/track-ai.ts +50 -0
  140. package/src/shared/emitters/ai/types.ts +1041 -0
  141. package/src/shared/emitters/ai/utils.ts +468 -0
  142. package/src/shared/emitters/ecommerce/events/cart-checkout.ts +106 -0
  143. package/src/shared/emitters/ecommerce/events/coupon.ts +49 -0
  144. package/src/shared/emitters/ecommerce/events/engagement.ts +61 -0
  145. package/src/shared/emitters/ecommerce/events/marketplace.ts +119 -0
  146. package/src/shared/emitters/ecommerce/events/order.ts +199 -0
  147. package/src/shared/emitters/ecommerce/events/product.ts +205 -0
  148. package/src/shared/emitters/ecommerce/events/registry.ts +123 -0
  149. package/src/shared/emitters/ecommerce/events/wishlist-sharing.ts +140 -0
  150. package/src/shared/emitters/ecommerce/index.ts +46 -0
  151. package/src/shared/emitters/ecommerce/track-ecommerce.ts +53 -0
  152. package/src/shared/emitters/ecommerce/types.ts +314 -0
  153. package/src/shared/emitters/ecommerce/utils.ts +216 -0
  154. package/src/shared/emitters/emitter-types.ts +974 -0
  155. package/src/shared/emitters/emitters.ts +292 -0
  156. package/src/shared/emitters/helpers.ts +419 -0
  157. package/src/shared/emitters/index.ts +66 -0
  158. package/src/shared/index.ts +142 -0
  159. package/src/shared/ingestion/index.ts +66 -0
  160. package/src/shared/ingestion/schemas.ts +386 -0
  161. package/src/shared/ingestion/service.ts +628 -0
  162. package/src/shared/node22-features.ts +848 -0
  163. package/src/shared/providers/console-provider.ts +160 -0
  164. package/src/shared/types/base-types.ts +54 -0
  165. package/src/shared/types/console-types.ts +19 -0
  166. package/src/shared/types/posthog-types.ts +131 -0
  167. package/src/shared/types/segment-types.ts +15 -0
  168. package/src/shared/types/types.ts +397 -0
  169. package/src/shared/types/vercel-types.ts +19 -0
  170. package/src/shared/utils/config-client.ts +19 -0
  171. package/src/shared/utils/config.ts +250 -0
  172. package/src/shared/utils/emitter-adapter.ts +212 -0
  173. package/src/shared/utils/manager.test.ts +36 -0
  174. package/src/shared/utils/manager.ts +1322 -0
  175. package/src/shared/utils/posthog-bootstrap.ts +136 -0
  176. package/src/shared/utils/posthog-client-utils.ts +48 -0
  177. package/src/shared/utils/posthog-next-utils.ts +282 -0
  178. package/src/shared/utils/posthog-server-utils.ts +210 -0
  179. package/src/shared/utils/rate-limit.ts +289 -0
  180. package/src/shared/utils/security.ts +545 -0
  181. package/src/shared/utils/validation-client.ts +161 -0
  182. package/src/shared/utils/validation.ts +399 -0
  183. package/src/shared.ts +155 -0
  184. 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
+ }