@sygnl/event-schema 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +573 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +16326 -0
- package/dist/index.d.ts +16326 -0
- package/dist/index.js +517 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/base.ts
|
|
6
|
+
var BaseEventMetadataSchema = zod.z.object({
|
|
7
|
+
/** Unique event identifier */
|
|
8
|
+
event_id: zod.z.string(),
|
|
9
|
+
/** ISO timestamp when event occurred */
|
|
10
|
+
timestamp: zod.z.number().int().positive(),
|
|
11
|
+
/** Event source */
|
|
12
|
+
source: zod.z.enum(["pixel", "server", "webhook", "api"]),
|
|
13
|
+
/** User's anonymous identifier */
|
|
14
|
+
anonymous_id: zod.z.string().optional(),
|
|
15
|
+
/** User's authenticated identifier */
|
|
16
|
+
user_id: zod.z.string().optional(),
|
|
17
|
+
/** Session identifier */
|
|
18
|
+
session_id: zod.z.string().optional()
|
|
19
|
+
});
|
|
20
|
+
var MoneySchema = zod.z.object({
|
|
21
|
+
/** Amount in the specified currency */
|
|
22
|
+
amount: zod.z.number(),
|
|
23
|
+
/** ISO 4217 currency code */
|
|
24
|
+
currency: zod.z.string().length(3).toUpperCase()
|
|
25
|
+
});
|
|
26
|
+
var ProductSchema = zod.z.object({
|
|
27
|
+
/** Unique product identifier */
|
|
28
|
+
product_id: zod.z.string(),
|
|
29
|
+
/** Product name */
|
|
30
|
+
name: zod.z.string(),
|
|
31
|
+
/** Product SKU */
|
|
32
|
+
sku: zod.z.string().optional(),
|
|
33
|
+
/** Product category */
|
|
34
|
+
category: zod.z.string().optional(),
|
|
35
|
+
/** Product brand */
|
|
36
|
+
brand: zod.z.string().optional(),
|
|
37
|
+
/** Product variant (size, color, etc.) */
|
|
38
|
+
variant: zod.z.string().optional(),
|
|
39
|
+
/** Unit price */
|
|
40
|
+
price: zod.z.number(),
|
|
41
|
+
/** Quantity */
|
|
42
|
+
quantity: zod.z.number().int().positive().default(1),
|
|
43
|
+
/** Currency code */
|
|
44
|
+
currency: zod.z.string().length(3).toUpperCase().default("USD"),
|
|
45
|
+
/** Product image URL */
|
|
46
|
+
image_url: zod.z.string().url().optional(),
|
|
47
|
+
/** Product URL */
|
|
48
|
+
url: zod.z.string().url().optional()
|
|
49
|
+
});
|
|
50
|
+
var CartSchema = zod.z.object({
|
|
51
|
+
/** Cart identifier */
|
|
52
|
+
cart_id: zod.z.string().optional(),
|
|
53
|
+
/** Products in cart */
|
|
54
|
+
products: zod.z.array(ProductSchema).min(1),
|
|
55
|
+
/** Cart total */
|
|
56
|
+
total: MoneySchema,
|
|
57
|
+
/** Subtotal (before tax/shipping) */
|
|
58
|
+
subtotal: MoneySchema.optional(),
|
|
59
|
+
/** Tax amount */
|
|
60
|
+
tax: MoneySchema.optional(),
|
|
61
|
+
/** Shipping amount */
|
|
62
|
+
shipping: MoneySchema.optional(),
|
|
63
|
+
/** Discount amount */
|
|
64
|
+
discount: MoneySchema.optional(),
|
|
65
|
+
/** Coupon code used */
|
|
66
|
+
coupon: zod.z.string().optional()
|
|
67
|
+
});
|
|
68
|
+
var PageContextSchema = zod.z.object({
|
|
69
|
+
/** Current page URL */
|
|
70
|
+
url: zod.z.string().url().optional(),
|
|
71
|
+
/** Page path */
|
|
72
|
+
path: zod.z.string().optional(),
|
|
73
|
+
/** Page title */
|
|
74
|
+
title: zod.z.string().optional(),
|
|
75
|
+
/** Referrer URL */
|
|
76
|
+
referrer: zod.z.string().url().optional(),
|
|
77
|
+
/** Search query (if applicable) */
|
|
78
|
+
search: zod.z.string().optional()
|
|
79
|
+
});
|
|
80
|
+
var UserTraitsSchema = zod.z.object({
|
|
81
|
+
/** Email address */
|
|
82
|
+
email: zod.z.string().email().optional(),
|
|
83
|
+
/** Phone number */
|
|
84
|
+
phone: zod.z.string().optional(),
|
|
85
|
+
/** First name */
|
|
86
|
+
first_name: zod.z.string().optional(),
|
|
87
|
+
/** Last name */
|
|
88
|
+
last_name: zod.z.string().optional(),
|
|
89
|
+
/** Company name */
|
|
90
|
+
company: zod.z.string().optional(),
|
|
91
|
+
/** Job title */
|
|
92
|
+
title: zod.z.string().optional(),
|
|
93
|
+
/** Address city */
|
|
94
|
+
city: zod.z.string().optional(),
|
|
95
|
+
/** Address state/region */
|
|
96
|
+
state: zod.z.string().optional(),
|
|
97
|
+
/** Address country */
|
|
98
|
+
country: zod.z.string().optional(),
|
|
99
|
+
/** Postal code */
|
|
100
|
+
postal_code: zod.z.string().optional(),
|
|
101
|
+
/** Avatar/profile image URL */
|
|
102
|
+
avatar: zod.z.string().url().optional()
|
|
103
|
+
});
|
|
104
|
+
var ProductViewedEventSchema = BaseEventMetadataSchema.extend({
|
|
105
|
+
event_type: zod.z.literal("product_viewed"),
|
|
106
|
+
product: ProductSchema,
|
|
107
|
+
page: PageContextSchema.optional()
|
|
108
|
+
});
|
|
109
|
+
var ProductListViewedEventSchema = BaseEventMetadataSchema.extend({
|
|
110
|
+
event_type: zod.z.literal("product_list_viewed"),
|
|
111
|
+
list_id: zod.z.string().optional(),
|
|
112
|
+
list_name: zod.z.string().optional(),
|
|
113
|
+
category: zod.z.string().optional(),
|
|
114
|
+
products: zod.z.array(ProductSchema),
|
|
115
|
+
page: PageContextSchema.optional()
|
|
116
|
+
});
|
|
117
|
+
var ProductAddedEventSchema = BaseEventMetadataSchema.extend({
|
|
118
|
+
event_type: zod.z.literal("product_added"),
|
|
119
|
+
product: ProductSchema,
|
|
120
|
+
cart: CartSchema.optional()
|
|
121
|
+
});
|
|
122
|
+
var ProductRemovedEventSchema = BaseEventMetadataSchema.extend({
|
|
123
|
+
event_type: zod.z.literal("product_removed"),
|
|
124
|
+
product: ProductSchema,
|
|
125
|
+
cart: CartSchema.optional()
|
|
126
|
+
});
|
|
127
|
+
var CartViewedEventSchema = BaseEventMetadataSchema.extend({
|
|
128
|
+
event_type: zod.z.literal("cart_viewed"),
|
|
129
|
+
cart: CartSchema
|
|
130
|
+
});
|
|
131
|
+
var CheckoutStartedEventSchema = BaseEventMetadataSchema.extend({
|
|
132
|
+
event_type: zod.z.literal("checkout_started"),
|
|
133
|
+
cart: CartSchema,
|
|
134
|
+
checkout_id: zod.z.string().optional()
|
|
135
|
+
});
|
|
136
|
+
var CheckoutStepCompletedEventSchema = BaseEventMetadataSchema.extend({
|
|
137
|
+
event_type: zod.z.literal("checkout_step_completed"),
|
|
138
|
+
checkout_id: zod.z.string(),
|
|
139
|
+
step: zod.z.number().int().positive(),
|
|
140
|
+
step_name: zod.z.string().optional(),
|
|
141
|
+
shipping_method: zod.z.string().optional(),
|
|
142
|
+
payment_method: zod.z.string().optional()
|
|
143
|
+
});
|
|
144
|
+
var PaymentInfoEnteredEventSchema = BaseEventMetadataSchema.extend({
|
|
145
|
+
event_type: zod.z.literal("payment_info_entered"),
|
|
146
|
+
checkout_id: zod.z.string(),
|
|
147
|
+
payment_method: zod.z.string(),
|
|
148
|
+
cart: CartSchema.optional()
|
|
149
|
+
});
|
|
150
|
+
var OrderCompletedEventSchema = BaseEventMetadataSchema.extend({
|
|
151
|
+
event_type: zod.z.literal("order_completed"),
|
|
152
|
+
order_id: zod.z.string(),
|
|
153
|
+
checkout_id: zod.z.string().optional(),
|
|
154
|
+
total: MoneySchema,
|
|
155
|
+
subtotal: MoneySchema.optional(),
|
|
156
|
+
revenue: MoneySchema,
|
|
157
|
+
tax: MoneySchema.optional(),
|
|
158
|
+
shipping: MoneySchema.optional(),
|
|
159
|
+
discount: MoneySchema.optional(),
|
|
160
|
+
coupon: zod.z.string().optional(),
|
|
161
|
+
products: zod.z.array(ProductSchema),
|
|
162
|
+
payment_method: zod.z.string().optional(),
|
|
163
|
+
shipping_method: zod.z.string().optional()
|
|
164
|
+
});
|
|
165
|
+
var OrderUpdatedEventSchema = BaseEventMetadataSchema.extend({
|
|
166
|
+
event_type: zod.z.literal("order_updated"),
|
|
167
|
+
order_id: zod.z.string(),
|
|
168
|
+
total: MoneySchema.optional(),
|
|
169
|
+
status: zod.z.string().optional(),
|
|
170
|
+
products: zod.z.array(ProductSchema).optional()
|
|
171
|
+
});
|
|
172
|
+
var OrderRefundedEventSchema = BaseEventMetadataSchema.extend({
|
|
173
|
+
event_type: zod.z.literal("order_refunded"),
|
|
174
|
+
order_id: zod.z.string(),
|
|
175
|
+
refund_amount: MoneySchema,
|
|
176
|
+
refund_reason: zod.z.string().optional(),
|
|
177
|
+
products: zod.z.array(ProductSchema).optional()
|
|
178
|
+
});
|
|
179
|
+
var OrderCancelledEventSchema = BaseEventMetadataSchema.extend({
|
|
180
|
+
event_type: zod.z.literal("order_cancelled"),
|
|
181
|
+
order_id: zod.z.string(),
|
|
182
|
+
cancel_reason: zod.z.string().optional()
|
|
183
|
+
});
|
|
184
|
+
var EcommerceEventSchema = zod.z.discriminatedUnion("event_type", [
|
|
185
|
+
ProductViewedEventSchema,
|
|
186
|
+
ProductListViewedEventSchema,
|
|
187
|
+
ProductAddedEventSchema,
|
|
188
|
+
ProductRemovedEventSchema,
|
|
189
|
+
CartViewedEventSchema,
|
|
190
|
+
CheckoutStartedEventSchema,
|
|
191
|
+
CheckoutStepCompletedEventSchema,
|
|
192
|
+
PaymentInfoEnteredEventSchema,
|
|
193
|
+
OrderCompletedEventSchema,
|
|
194
|
+
OrderUpdatedEventSchema,
|
|
195
|
+
OrderRefundedEventSchema,
|
|
196
|
+
OrderCancelledEventSchema
|
|
197
|
+
]);
|
|
198
|
+
var SubscriptionPlanSchema = zod.z.object({
|
|
199
|
+
plan_id: zod.z.string(),
|
|
200
|
+
plan_name: zod.z.string(),
|
|
201
|
+
plan_type: zod.z.enum(["free", "trial", "paid"]).optional(),
|
|
202
|
+
billing_period: zod.z.enum(["monthly", "yearly", "quarterly", "lifetime"]).optional(),
|
|
203
|
+
price: MoneySchema.optional()
|
|
204
|
+
});
|
|
205
|
+
var UserSignedUpEventSchema = BaseEventMetadataSchema.extend({
|
|
206
|
+
event_type: zod.z.literal("user_signed_up"),
|
|
207
|
+
user_traits: UserTraitsSchema.optional(),
|
|
208
|
+
signup_method: zod.z.enum(["email", "google", "github", "sso", "other"]).optional(),
|
|
209
|
+
referral_code: zod.z.string().optional()
|
|
210
|
+
});
|
|
211
|
+
var UserInvitedEventSchema = BaseEventMetadataSchema.extend({
|
|
212
|
+
event_type: zod.z.literal("user_invited"),
|
|
213
|
+
invited_email: zod.z.string().email(),
|
|
214
|
+
inviter_id: zod.z.string(),
|
|
215
|
+
role: zod.z.string().optional(),
|
|
216
|
+
team_id: zod.z.string().optional()
|
|
217
|
+
});
|
|
218
|
+
var UserLoggedInEventSchema = BaseEventMetadataSchema.extend({
|
|
219
|
+
event_type: zod.z.literal("user_logged_in"),
|
|
220
|
+
login_method: zod.z.enum(["email", "google", "github", "sso", "other"]).optional()
|
|
221
|
+
});
|
|
222
|
+
var UserLoggedOutEventSchema = BaseEventMetadataSchema.extend({
|
|
223
|
+
event_type: zod.z.literal("user_logged_out")
|
|
224
|
+
});
|
|
225
|
+
var AccountCreatedEventSchema = BaseEventMetadataSchema.extend({
|
|
226
|
+
event_type: zod.z.literal("account_created"),
|
|
227
|
+
account_id: zod.z.string(),
|
|
228
|
+
account_name: zod.z.string(),
|
|
229
|
+
plan: SubscriptionPlanSchema.optional()
|
|
230
|
+
});
|
|
231
|
+
var AccountDeletedEventSchema = BaseEventMetadataSchema.extend({
|
|
232
|
+
event_type: zod.z.literal("account_deleted"),
|
|
233
|
+
account_id: zod.z.string(),
|
|
234
|
+
delete_reason: zod.z.string().optional()
|
|
235
|
+
});
|
|
236
|
+
var TrialStartedEventSchema = BaseEventMetadataSchema.extend({
|
|
237
|
+
event_type: zod.z.literal("trial_started"),
|
|
238
|
+
plan: SubscriptionPlanSchema,
|
|
239
|
+
trial_days: zod.z.number().int().positive(),
|
|
240
|
+
trial_end_date: zod.z.number().int().positive()
|
|
241
|
+
});
|
|
242
|
+
var TrialConvertedEventSchema = BaseEventMetadataSchema.extend({
|
|
243
|
+
event_type: zod.z.literal("trial_converted"),
|
|
244
|
+
from_plan: SubscriptionPlanSchema,
|
|
245
|
+
to_plan: SubscriptionPlanSchema
|
|
246
|
+
});
|
|
247
|
+
var TrialEndedEventSchema = BaseEventMetadataSchema.extend({
|
|
248
|
+
event_type: zod.z.literal("trial_ended"),
|
|
249
|
+
plan: SubscriptionPlanSchema,
|
|
250
|
+
converted: zod.z.boolean()
|
|
251
|
+
});
|
|
252
|
+
var SubscriptionStartedEventSchema = BaseEventMetadataSchema.extend({
|
|
253
|
+
event_type: zod.z.literal("subscription_started"),
|
|
254
|
+
subscription_id: zod.z.string(),
|
|
255
|
+
plan: SubscriptionPlanSchema,
|
|
256
|
+
billing_period_start: zod.z.number().int().positive(),
|
|
257
|
+
billing_period_end: zod.z.number().int().positive()
|
|
258
|
+
});
|
|
259
|
+
var SubscriptionUpgradedEventSchema = BaseEventMetadataSchema.extend({
|
|
260
|
+
event_type: zod.z.literal("subscription_upgraded"),
|
|
261
|
+
subscription_id: zod.z.string(),
|
|
262
|
+
from_plan: SubscriptionPlanSchema,
|
|
263
|
+
to_plan: SubscriptionPlanSchema,
|
|
264
|
+
prorated_amount: MoneySchema.optional()
|
|
265
|
+
});
|
|
266
|
+
var SubscriptionDowngradedEventSchema = BaseEventMetadataSchema.extend({
|
|
267
|
+
event_type: zod.z.literal("subscription_downgraded"),
|
|
268
|
+
subscription_id: zod.z.string(),
|
|
269
|
+
from_plan: SubscriptionPlanSchema,
|
|
270
|
+
to_plan: SubscriptionPlanSchema,
|
|
271
|
+
effective_date: zod.z.number().int().positive().optional()
|
|
272
|
+
});
|
|
273
|
+
var SubscriptionCancelledEventSchema = BaseEventMetadataSchema.extend({
|
|
274
|
+
event_type: zod.z.literal("subscription_cancelled"),
|
|
275
|
+
subscription_id: zod.z.string(),
|
|
276
|
+
plan: SubscriptionPlanSchema,
|
|
277
|
+
cancel_reason: zod.z.string().optional(),
|
|
278
|
+
cancel_at_period_end: zod.z.boolean().default(true),
|
|
279
|
+
effective_date: zod.z.number().int().positive().optional()
|
|
280
|
+
});
|
|
281
|
+
var SubscriptionRenewedEventSchema = BaseEventMetadataSchema.extend({
|
|
282
|
+
event_type: zod.z.literal("subscription_renewed"),
|
|
283
|
+
subscription_id: zod.z.string(),
|
|
284
|
+
plan: SubscriptionPlanSchema,
|
|
285
|
+
billing_period_start: zod.z.number().int().positive(),
|
|
286
|
+
billing_period_end: zod.z.number().int().positive()
|
|
287
|
+
});
|
|
288
|
+
var SubscriptionPausedEventSchema = BaseEventMetadataSchema.extend({
|
|
289
|
+
event_type: zod.z.literal("subscription_paused"),
|
|
290
|
+
subscription_id: zod.z.string(),
|
|
291
|
+
pause_reason: zod.z.string().optional()
|
|
292
|
+
});
|
|
293
|
+
var SubscriptionResumedEventSchema = BaseEventMetadataSchema.extend({
|
|
294
|
+
event_type: zod.z.literal("subscription_resumed"),
|
|
295
|
+
subscription_id: zod.z.string()
|
|
296
|
+
});
|
|
297
|
+
var PaymentSucceededEventSchema = BaseEventMetadataSchema.extend({
|
|
298
|
+
event_type: zod.z.literal("payment_succeeded"),
|
|
299
|
+
payment_id: zod.z.string(),
|
|
300
|
+
subscription_id: zod.z.string().optional(),
|
|
301
|
+
invoice_id: zod.z.string().optional(),
|
|
302
|
+
amount: MoneySchema,
|
|
303
|
+
payment_method: zod.z.string().optional()
|
|
304
|
+
});
|
|
305
|
+
var PaymentFailedEventSchema = BaseEventMetadataSchema.extend({
|
|
306
|
+
event_type: zod.z.literal("payment_failed"),
|
|
307
|
+
payment_id: zod.z.string().optional(),
|
|
308
|
+
subscription_id: zod.z.string().optional(),
|
|
309
|
+
invoice_id: zod.z.string().optional(),
|
|
310
|
+
amount: MoneySchema,
|
|
311
|
+
failure_reason: zod.z.string().optional(),
|
|
312
|
+
retry_attempt: zod.z.number().int().nonnegative().optional()
|
|
313
|
+
});
|
|
314
|
+
var InvoiceCreatedEventSchema = BaseEventMetadataSchema.extend({
|
|
315
|
+
event_type: zod.z.literal("invoice_created"),
|
|
316
|
+
invoice_id: zod.z.string(),
|
|
317
|
+
subscription_id: zod.z.string().optional(),
|
|
318
|
+
amount: MoneySchema,
|
|
319
|
+
due_date: zod.z.number().int().positive().optional()
|
|
320
|
+
});
|
|
321
|
+
var InvoicePaidEventSchema = BaseEventMetadataSchema.extend({
|
|
322
|
+
event_type: zod.z.literal("invoice_paid"),
|
|
323
|
+
invoice_id: zod.z.string(),
|
|
324
|
+
subscription_id: zod.z.string().optional(),
|
|
325
|
+
amount: MoneySchema,
|
|
326
|
+
paid_at: zod.z.number().int().positive()
|
|
327
|
+
});
|
|
328
|
+
var FeatureUsedEventSchema = BaseEventMetadataSchema.extend({
|
|
329
|
+
event_type: zod.z.literal("feature_used"),
|
|
330
|
+
feature_name: zod.z.string(),
|
|
331
|
+
feature_id: zod.z.string().optional(),
|
|
332
|
+
usage_count: zod.z.number().int().nonnegative().optional(),
|
|
333
|
+
metadata: zod.z.record(zod.z.unknown()).optional()
|
|
334
|
+
});
|
|
335
|
+
var LimitReachedEventSchema = BaseEventMetadataSchema.extend({
|
|
336
|
+
event_type: zod.z.literal("limit_reached"),
|
|
337
|
+
limit_type: zod.z.string(),
|
|
338
|
+
current_usage: zod.z.number(),
|
|
339
|
+
limit_value: zod.z.number(),
|
|
340
|
+
plan: SubscriptionPlanSchema.optional()
|
|
341
|
+
});
|
|
342
|
+
var QuotaExceededEventSchema = BaseEventMetadataSchema.extend({
|
|
343
|
+
event_type: zod.z.literal("quota_exceeded"),
|
|
344
|
+
quota_type: zod.z.string(),
|
|
345
|
+
current_usage: zod.z.number(),
|
|
346
|
+
quota_limit: zod.z.number(),
|
|
347
|
+
plan: SubscriptionPlanSchema.optional()
|
|
348
|
+
});
|
|
349
|
+
var SaasEventSchema = zod.z.discriminatedUnion("event_type", [
|
|
350
|
+
UserSignedUpEventSchema,
|
|
351
|
+
UserInvitedEventSchema,
|
|
352
|
+
UserLoggedInEventSchema,
|
|
353
|
+
UserLoggedOutEventSchema,
|
|
354
|
+
AccountCreatedEventSchema,
|
|
355
|
+
AccountDeletedEventSchema,
|
|
356
|
+
TrialStartedEventSchema,
|
|
357
|
+
TrialConvertedEventSchema,
|
|
358
|
+
TrialEndedEventSchema,
|
|
359
|
+
SubscriptionStartedEventSchema,
|
|
360
|
+
SubscriptionUpgradedEventSchema,
|
|
361
|
+
SubscriptionDowngradedEventSchema,
|
|
362
|
+
SubscriptionCancelledEventSchema,
|
|
363
|
+
SubscriptionRenewedEventSchema,
|
|
364
|
+
SubscriptionPausedEventSchema,
|
|
365
|
+
SubscriptionResumedEventSchema,
|
|
366
|
+
PaymentSucceededEventSchema,
|
|
367
|
+
PaymentFailedEventSchema,
|
|
368
|
+
InvoiceCreatedEventSchema,
|
|
369
|
+
InvoicePaidEventSchema,
|
|
370
|
+
FeatureUsedEventSchema,
|
|
371
|
+
LimitReachedEventSchema,
|
|
372
|
+
QuotaExceededEventSchema
|
|
373
|
+
]);
|
|
374
|
+
var CustomEventSchema = BaseEventMetadataSchema.extend({
|
|
375
|
+
/** Custom event type (user-defined) */
|
|
376
|
+
event_type: zod.z.string(),
|
|
377
|
+
/** Custom event properties (user-defined) */
|
|
378
|
+
properties: zod.z.record(zod.z.unknown()).optional()
|
|
379
|
+
});
|
|
380
|
+
function createCustomEventSchema(eventType, propertiesSchema) {
|
|
381
|
+
return BaseEventMetadataSchema.extend({
|
|
382
|
+
event_type: zod.z.literal(eventType),
|
|
383
|
+
properties: propertiesSchema
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
var CoreEventSchema = zod.z.union([EcommerceEventSchema, SaasEventSchema]);
|
|
387
|
+
var AnyEventSchema = zod.z.union([
|
|
388
|
+
EcommerceEventSchema,
|
|
389
|
+
SaasEventSchema,
|
|
390
|
+
CustomEventSchema
|
|
391
|
+
]);
|
|
392
|
+
function validateEvent(data) {
|
|
393
|
+
try {
|
|
394
|
+
const parsed = AnyEventSchema.parse(data);
|
|
395
|
+
return {
|
|
396
|
+
success: true,
|
|
397
|
+
data: parsed,
|
|
398
|
+
error: null
|
|
399
|
+
};
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (error instanceof zod.z.ZodError) {
|
|
402
|
+
return {
|
|
403
|
+
success: false,
|
|
404
|
+
data: null,
|
|
405
|
+
error
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function validateEcommerceEvent(data) {
|
|
412
|
+
try {
|
|
413
|
+
const parsed = EcommerceEventSchema.parse(data);
|
|
414
|
+
return {
|
|
415
|
+
success: true,
|
|
416
|
+
data: parsed,
|
|
417
|
+
error: null
|
|
418
|
+
};
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (error instanceof zod.z.ZodError) {
|
|
421
|
+
return {
|
|
422
|
+
success: false,
|
|
423
|
+
data: null,
|
|
424
|
+
error
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function validateSaasEvent(data) {
|
|
431
|
+
try {
|
|
432
|
+
const parsed = SaasEventSchema.parse(data);
|
|
433
|
+
return {
|
|
434
|
+
success: true,
|
|
435
|
+
data: parsed,
|
|
436
|
+
error: null
|
|
437
|
+
};
|
|
438
|
+
} catch (error) {
|
|
439
|
+
if (error instanceof zod.z.ZodError) {
|
|
440
|
+
return {
|
|
441
|
+
success: false,
|
|
442
|
+
data: null,
|
|
443
|
+
error
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function validateCustomEvent(data) {
|
|
450
|
+
try {
|
|
451
|
+
const parsed = CustomEventSchema.parse(data);
|
|
452
|
+
return {
|
|
453
|
+
success: true,
|
|
454
|
+
data: parsed,
|
|
455
|
+
error: null
|
|
456
|
+
};
|
|
457
|
+
} catch (error) {
|
|
458
|
+
if (error instanceof zod.z.ZodError) {
|
|
459
|
+
return {
|
|
460
|
+
success: false,
|
|
461
|
+
data: null,
|
|
462
|
+
error
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
throw error;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function isEcommerceEvent(event) {
|
|
469
|
+
const ecommerceTypes = [
|
|
470
|
+
"product_viewed",
|
|
471
|
+
"product_list_viewed",
|
|
472
|
+
"product_added",
|
|
473
|
+
"product_removed",
|
|
474
|
+
"cart_viewed",
|
|
475
|
+
"checkout_started",
|
|
476
|
+
"checkout_step_completed",
|
|
477
|
+
"payment_info_entered",
|
|
478
|
+
"order_completed",
|
|
479
|
+
"order_updated",
|
|
480
|
+
"order_refunded",
|
|
481
|
+
"order_cancelled"
|
|
482
|
+
];
|
|
483
|
+
return ecommerceTypes.includes(event.event_type);
|
|
484
|
+
}
|
|
485
|
+
function isSaasEvent(event) {
|
|
486
|
+
const saasTypes = [
|
|
487
|
+
"user_signed_up",
|
|
488
|
+
"user_invited",
|
|
489
|
+
"user_logged_in",
|
|
490
|
+
"user_logged_out",
|
|
491
|
+
"account_created",
|
|
492
|
+
"account_deleted",
|
|
493
|
+
"trial_started",
|
|
494
|
+
"trial_converted",
|
|
495
|
+
"trial_ended",
|
|
496
|
+
"subscription_started",
|
|
497
|
+
"subscription_upgraded",
|
|
498
|
+
"subscription_downgraded",
|
|
499
|
+
"subscription_cancelled",
|
|
500
|
+
"subscription_renewed",
|
|
501
|
+
"subscription_paused",
|
|
502
|
+
"subscription_resumed",
|
|
503
|
+
"payment_succeeded",
|
|
504
|
+
"payment_failed",
|
|
505
|
+
"invoice_created",
|
|
506
|
+
"invoice_paid",
|
|
507
|
+
"feature_used",
|
|
508
|
+
"limit_reached",
|
|
509
|
+
"quota_exceeded"
|
|
510
|
+
];
|
|
511
|
+
return saasTypes.includes(event.event_type);
|
|
512
|
+
}
|
|
513
|
+
function isCustomEvent(event) {
|
|
514
|
+
return !isEcommerceEvent(event) && !isSaasEvent(event);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
exports.AccountCreatedEventSchema = AccountCreatedEventSchema;
|
|
518
|
+
exports.AccountDeletedEventSchema = AccountDeletedEventSchema;
|
|
519
|
+
exports.AnyEventSchema = AnyEventSchema;
|
|
520
|
+
exports.BaseEventMetadataSchema = BaseEventMetadataSchema;
|
|
521
|
+
exports.CartSchema = CartSchema;
|
|
522
|
+
exports.CartViewedEventSchema = CartViewedEventSchema;
|
|
523
|
+
exports.CheckoutStartedEventSchema = CheckoutStartedEventSchema;
|
|
524
|
+
exports.CheckoutStepCompletedEventSchema = CheckoutStepCompletedEventSchema;
|
|
525
|
+
exports.CoreEventSchema = CoreEventSchema;
|
|
526
|
+
exports.CustomEventSchema = CustomEventSchema;
|
|
527
|
+
exports.EcommerceEventSchema = EcommerceEventSchema;
|
|
528
|
+
exports.FeatureUsedEventSchema = FeatureUsedEventSchema;
|
|
529
|
+
exports.InvoiceCreatedEventSchema = InvoiceCreatedEventSchema;
|
|
530
|
+
exports.InvoicePaidEventSchema = InvoicePaidEventSchema;
|
|
531
|
+
exports.LimitReachedEventSchema = LimitReachedEventSchema;
|
|
532
|
+
exports.MoneySchema = MoneySchema;
|
|
533
|
+
exports.OrderCancelledEventSchema = OrderCancelledEventSchema;
|
|
534
|
+
exports.OrderCompletedEventSchema = OrderCompletedEventSchema;
|
|
535
|
+
exports.OrderRefundedEventSchema = OrderRefundedEventSchema;
|
|
536
|
+
exports.OrderUpdatedEventSchema = OrderUpdatedEventSchema;
|
|
537
|
+
exports.PageContextSchema = PageContextSchema;
|
|
538
|
+
exports.PaymentFailedEventSchema = PaymentFailedEventSchema;
|
|
539
|
+
exports.PaymentInfoEnteredEventSchema = PaymentInfoEnteredEventSchema;
|
|
540
|
+
exports.PaymentSucceededEventSchema = PaymentSucceededEventSchema;
|
|
541
|
+
exports.ProductAddedEventSchema = ProductAddedEventSchema;
|
|
542
|
+
exports.ProductListViewedEventSchema = ProductListViewedEventSchema;
|
|
543
|
+
exports.ProductRemovedEventSchema = ProductRemovedEventSchema;
|
|
544
|
+
exports.ProductSchema = ProductSchema;
|
|
545
|
+
exports.ProductViewedEventSchema = ProductViewedEventSchema;
|
|
546
|
+
exports.QuotaExceededEventSchema = QuotaExceededEventSchema;
|
|
547
|
+
exports.SaasEventSchema = SaasEventSchema;
|
|
548
|
+
exports.SubscriptionCancelledEventSchema = SubscriptionCancelledEventSchema;
|
|
549
|
+
exports.SubscriptionDowngradedEventSchema = SubscriptionDowngradedEventSchema;
|
|
550
|
+
exports.SubscriptionPausedEventSchema = SubscriptionPausedEventSchema;
|
|
551
|
+
exports.SubscriptionPlanSchema = SubscriptionPlanSchema;
|
|
552
|
+
exports.SubscriptionRenewedEventSchema = SubscriptionRenewedEventSchema;
|
|
553
|
+
exports.SubscriptionResumedEventSchema = SubscriptionResumedEventSchema;
|
|
554
|
+
exports.SubscriptionStartedEventSchema = SubscriptionStartedEventSchema;
|
|
555
|
+
exports.SubscriptionUpgradedEventSchema = SubscriptionUpgradedEventSchema;
|
|
556
|
+
exports.TrialConvertedEventSchema = TrialConvertedEventSchema;
|
|
557
|
+
exports.TrialEndedEventSchema = TrialEndedEventSchema;
|
|
558
|
+
exports.TrialStartedEventSchema = TrialStartedEventSchema;
|
|
559
|
+
exports.UserInvitedEventSchema = UserInvitedEventSchema;
|
|
560
|
+
exports.UserLoggedInEventSchema = UserLoggedInEventSchema;
|
|
561
|
+
exports.UserLoggedOutEventSchema = UserLoggedOutEventSchema;
|
|
562
|
+
exports.UserSignedUpEventSchema = UserSignedUpEventSchema;
|
|
563
|
+
exports.UserTraitsSchema = UserTraitsSchema;
|
|
564
|
+
exports.createCustomEventSchema = createCustomEventSchema;
|
|
565
|
+
exports.isCustomEvent = isCustomEvent;
|
|
566
|
+
exports.isEcommerceEvent = isEcommerceEvent;
|
|
567
|
+
exports.isSaasEvent = isSaasEvent;
|
|
568
|
+
exports.validateCustomEvent = validateCustomEvent;
|
|
569
|
+
exports.validateEcommerceEvent = validateEcommerceEvent;
|
|
570
|
+
exports.validateEvent = validateEvent;
|
|
571
|
+
exports.validateSaasEvent = validateSaasEvent;
|
|
572
|
+
//# sourceMappingURL=index.cjs.map
|
|
573
|
+
//# sourceMappingURL=index.cjs.map
|