@entrolytics/shared 2.2.1 → 2.3.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 DELETED
@@ -1,629 +0,0 @@
1
- 'use strict';
2
-
3
- // src/event-protocol.ts
4
- var EventType = {
5
- PageView: "pageview",
6
- Custom: "custom_event",
7
- Click: "click"
8
- };
9
-
10
- // src/index.ts
11
- var PLANS = {
12
- starter: {
13
- id: "starter",
14
- name: "Starter",
15
- price: 0,
16
- limits: {
17
- pageviewsPerMonth: 25e3,
18
- websites: 2,
19
- retentionDays: 30,
20
- seats: 1
21
- },
22
- features: {
23
- funnels: false,
24
- attribution: false,
25
- revenue: false,
26
- customDashboards: false,
27
- apiAccess: false,
28
- weeklyReports: true,
29
- support: "community"
30
- }
31
- },
32
- pro: {
33
- id: "pro",
34
- name: "Pro",
35
- price: 29,
36
- limits: {
37
- pageviewsPerMonth: 25e4,
38
- websites: 10,
39
- retentionDays: 365,
40
- seats: 5
41
- },
42
- features: {
43
- funnels: true,
44
- attribution: true,
45
- revenue: true,
46
- customDashboards: false,
47
- apiAccess: true,
48
- weeklyReports: true,
49
- support: "email"
50
- }
51
- },
52
- business: {
53
- id: "business",
54
- name: "Business",
55
- price: 99,
56
- limits: {
57
- pageviewsPerMonth: 1e6,
58
- websites: -1,
59
- // unlimited
60
- retentionDays: 730,
61
- // 2 years
62
- seats: -1
63
- // unlimited
64
- },
65
- features: {
66
- funnels: true,
67
- attribution: true,
68
- revenue: true,
69
- customDashboards: true,
70
- apiAccess: true,
71
- weeklyReports: true,
72
- support: "priority"
73
- }
74
- },
75
- enterprise: {
76
- id: "enterprise",
77
- name: "Enterprise",
78
- price: -1,
79
- // custom
80
- limits: {
81
- pageviewsPerMonth: -1,
82
- // custom
83
- websites: -1,
84
- retentionDays: -1,
85
- // custom
86
- seats: -1
87
- },
88
- features: {
89
- funnels: true,
90
- attribution: true,
91
- revenue: true,
92
- customDashboards: true,
93
- apiAccess: true,
94
- weeklyReports: true,
95
- support: "dedicated",
96
- sso: true,
97
- auditLogs: true,
98
- customRetention: true
99
- }
100
- }
101
- };
102
- var PLAN_FEATURES = {
103
- funnels: "Funnel Analytics",
104
- attribution: "Attribution Reports",
105
- revenue: "Revenue Tracking",
106
- customDashboards: "Custom Dashboards",
107
- apiAccess: "API Access",
108
- weeklyReports: "Weekly Email Reports",
109
- sso: "SSO/SAML",
110
- auditLogs: "Audit Logs",
111
- customRetention: "Custom Data Retention"
112
- };
113
- var USAGE_THRESHOLDS = {
114
- warning: 90,
115
- critical: 95
116
- };
117
- var BILLING_ERRORS = {
118
- quotaExceeded: "QUOTA_EXCEEDED",
119
- planRequired: "PLAN_REQUIRED",
120
- featureNotAvailable: "FEATURE_NOT_AVAILABLE",
121
- subscriptionInactive: "SUBSCRIPTION_INACTIVE",
122
- paymentFailed: "PAYMENT_FAILED"
123
- };
124
- var API_ENDPOINTS = {
125
- production: "https://entrolytics.click",
126
- development: "http://localhost:3000"
127
- };
128
- var DEFAULT_API_HOST = process.env.NODE_ENV === "production" ? API_ENDPOINTS.production : API_ENDPOINTS.development;
129
- var ENV_VAR_NAMES = {
130
- nextjs: {
131
- websiteId: "NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID",
132
- host: "NEXT_PUBLIC_ENTROLYTICS_HOST",
133
- envFile: ".env.local"
134
- },
135
- react: {
136
- websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
137
- host: "VITE_ENTROLYTICS_HOST",
138
- envFile: ".env",
139
- fallback: {
140
- // CRA fallback
141
- websiteId: "REACT_APP_ENTROLYTICS_WEBSITE_ID",
142
- host: "REACT_APP_ENTROLYTICS_HOST"
143
- }
144
- },
145
- vue: {
146
- websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
147
- host: "VITE_ENTROLYTICS_HOST",
148
- envFile: ".env"
149
- },
150
- svelte: {
151
- websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
152
- host: "PUBLIC_ENTROLYTICS_HOST",
153
- envFile: ".env"
154
- },
155
- astro: {
156
- websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
157
- host: "PUBLIC_ENTROLYTICS_HOST",
158
- envFile: ".env"
159
- },
160
- html: {
161
- websiteId: "ENTROLYTICS_WEBSITE_ID",
162
- host: "ENTROLYTICS_HOST",
163
- envFile: ".env"
164
- },
165
- node: {
166
- websiteId: "ENTROLYTICS_WEBSITE_ID",
167
- host: "ENTROLYTICS_HOST",
168
- envFile: ".env"
169
- },
170
- php: {
171
- websiteId: "ENTROLYTICS_WEBSITE_ID",
172
- host: "ENTROLYTICS_HOST",
173
- envFile: ".env"
174
- },
175
- python: {
176
- websiteId: "ENTROLYTICS_WEBSITE_ID",
177
- host: "ENTROLYTICS_HOST",
178
- envFile: ".env"
179
- },
180
- go: {
181
- websiteId: "ENTROLYTICS_WEBSITE_ID",
182
- host: "ENTROLYTICS_HOST",
183
- envFile: ".env"
184
- }
185
- };
186
- var CLI_CONFIG = {
187
- tokenExpiryMinutes: 15,
188
- maxTokensPerUser: 10,
189
- pollIntervalMs: 2e3,
190
- setupTimeoutMs: 3e5,
191
- // 5 minutes
192
- minCliVersion: "1.0.0"
193
- };
194
- var EVENT_TYPES = {
195
- pageView: "pageview",
196
- custom: "custom_event",
197
- click: "click"
198
- };
199
- var SDK_EVENT_TYPES = {
200
- pageView: "pageview",
201
- click: "click",
202
- formSubmit: "form_submit",
203
- custom: "custom_event",
204
- error: "error",
205
- performance: "performance"
206
- };
207
- var VITAL_TYPES = {
208
- LCP: "LCP",
209
- // Largest Contentful Paint
210
- INP: "INP",
211
- // Interaction to Next Paint (replaced FID)
212
- CLS: "CLS",
213
- // Cumulative Layout Shift
214
- TTFB: "TTFB",
215
- // Time to First Byte
216
- FCP: "FCP"
217
- // First Contentful Paint
218
- };
219
- var VITAL_RATINGS = {
220
- good: "good",
221
- needsImprovement: "needs-improvement",
222
- poor: "poor"
223
- };
224
- var VITAL_THRESHOLDS = {
225
- LCP: { good: 2500, poor: 4e3 },
226
- INP: { good: 200, poor: 500 },
227
- CLS: { good: 0.1, poor: 0.25 },
228
- TTFB: { good: 800, poor: 1800 },
229
- FCP: { good: 1800, poor: 3e3 }
230
- };
231
- var NAVIGATION_TYPES = {
232
- navigate: "navigate",
233
- reload: "reload",
234
- backForward: "back-forward",
235
- backForwardCache: "back-forward-cache",
236
- prerender: "prerender",
237
- restore: "restore"
238
- };
239
- var FORM_EVENT_TYPES = {
240
- start: "start",
241
- // Form interaction started
242
- fieldFocus: "field_focus",
243
- // Field received focus
244
- fieldBlur: "field_blur",
245
- // Field lost focus
246
- fieldError: "field_error",
247
- // Field validation error
248
- submit: "submit",
249
- // Form submitted
250
- abandon: "abandon"
251
- // Form abandoned (left page)
252
- };
253
- var FORM_FIELD_TYPES = {
254
- text: "text",
255
- email: "email",
256
- password: "password",
257
- tel: "tel",
258
- number: "number",
259
- url: "url",
260
- textarea: "textarea",
261
- select: "select",
262
- checkbox: "checkbox",
263
- radio: "radio",
264
- date: "date",
265
- file: "file",
266
- hidden: "hidden",
267
- submit: "submit",
268
- other: "other"
269
- };
270
- var DEPLOYMENT_SOURCES = {
271
- vercel: "vercel",
272
- netlify: "netlify",
273
- cloudflare: "cloudflare",
274
- railway: "railway",
275
- render: "render",
276
- fly: "fly",
277
- heroku: "heroku",
278
- aws: "aws",
279
- gcp: "gcp",
280
- azure: "azure",
281
- custom: "custom"
282
- };
283
- var DEPLOYMENT_ENV_VARS = {
284
- vercel: {
285
- deployId: "VERCEL_DEPLOYMENT_ID",
286
- gitSha: "VERCEL_GIT_COMMIT_SHA",
287
- gitBranch: "VERCEL_GIT_COMMIT_REF",
288
- url: "VERCEL_URL"
289
- },
290
- netlify: {
291
- deployId: "DEPLOY_ID",
292
- gitSha: "COMMIT_REF",
293
- gitBranch: "BRANCH",
294
- url: "DEPLOY_URL"
295
- },
296
- cloudflare: {
297
- deployId: "CF_PAGES_COMMIT_SHA",
298
- gitSha: "CF_PAGES_COMMIT_SHA",
299
- gitBranch: "CF_PAGES_BRANCH",
300
- url: "CF_PAGES_URL"
301
- }
302
- };
303
- var HTTP_STATUS = {
304
- ok: 200,
305
- created: 201,
306
- accepted: 202,
307
- noContent: 204,
308
- badRequest: 400,
309
- unauthorized: 401,
310
- forbidden: 403,
311
- notFound: 404,
312
- conflict: 409,
313
- tooManyRequests: 429,
314
- internalServerError: 500,
315
- serviceUnavailable: 503
316
- };
317
- var API_ROUTES = {
318
- // CLI Auth routes
319
- cliAuthToken: "/api/auth/cli/token",
320
- cliAuthTokens: "/api/auth/cli/tokens",
321
- cliValidate: "/api/auth/cli/validate",
322
- cliToken: "/api/cli/token",
323
- // Legacy - deprecated
324
- // Share routes
325
- shareToken: (shareId) => `/api/share/${shareId}`,
326
- // Links routes
327
- links: "/api/links",
328
- linkRedirect: (slug) => `/q/${slug}`,
329
- // Website routes
330
- websites: "/api/websites",
331
- websiteById: (id) => `/api/websites/${id}`,
332
- websiteEvents: (id) => `/api/websites/${id}/events`,
333
- websiteRecentEvents: (id) => `/api/websites/${id}/recent-events`,
334
- // User routes
335
- userOnboarding: "/api/user/onboarding",
336
- userProfile: "/api/user/profile",
337
- userEmailPreferences: "/api/me/email-preferences",
338
- // Billing routes
339
- billingUsage: "/api/billing/usage",
340
- billingCheckout: "/api/billing/checkout",
341
- billingPortal: "/api/billing/portal",
342
- billingWebhook: "/api/billing/webhook",
343
- // Analytics routes (REST)
344
- analyticsOverview: (websiteId) => `/api/analytics/${websiteId}/overview`,
345
- analyticsTimeseries: (websiteId) => `/api/analytics/${websiteId}/timeseries`,
346
- analyticsTopPages: (websiteId) => `/api/analytics/${websiteId}/top-pages`,
347
- analyticsTopReferrers: (websiteId) => `/api/analytics/${websiteId}/top-referrers`,
348
- analyticsGeography: (websiteId) => `/api/analytics/${websiteId}/geography`,
349
- analyticsDevices: (websiteId) => `/api/analytics/${websiteId}/devices`,
350
- // Event collection
351
- collect: "/api/collect",
352
- collectBatch: "/api/collect/batch",
353
- send: "/api/send",
354
- // Phase 2: Web Vitals, Forms, Deployments
355
- collectVitals: "/api/collect/vitals",
356
- collectVitalsBatch: "/api/collect/vitals/batch",
357
- collectForms: "/api/collect/forms",
358
- websiteVitals: (id) => `/api/websites/${id}/vitals`,
359
- websiteForms: (id) => `/api/websites/${id}/forms`,
360
- websiteDeployments: (id) => `/api/websites/${id}/deployments`,
361
- // Health checks
362
- health: "/api/health",
363
- healthIntegrations: "/api/health/integrations"
364
- };
365
- var ONBOARDING_STEPS = {
366
- welcome: "welcome",
367
- createWebsite: "create-website",
368
- installTracking: "install-tracking",
369
- verify: "verify",
370
- complete: "complete",
371
- skipped: "skipped"
372
- };
373
- var CLI_TOKEN_STATUS = {
374
- pending: "pending",
375
- used: "used",
376
- expired: "expired",
377
- revoked: "revoked"
378
- };
379
- var USER_ROLES = {
380
- admin: "admin",
381
- user: "user",
382
- viewer: "viewer"
383
- };
384
- var FRAMEWORK_PACKAGES = {
385
- nextjs: "@entrolytics/nextjs-sdk",
386
- react: "@entrolytics/react-sdk",
387
- vue: "@entrolytics/vue-sdk",
388
- svelte: "@entrolytics/svelte-sdk",
389
- astro: "@entrolytics/astro-sdk",
390
- node: "@entrolytics/node-sdk"
391
- };
392
- var FRAMEWORK_PATTERNS = {
393
- nextjs: {
394
- files: ["next.config.js", "next.config.mjs", "next.config.ts"],
395
- dependencies: ["next"]
396
- },
397
- react: {
398
- files: ["vite.config.js", "vite.config.ts"],
399
- dependencies: ["react", "vite"]
400
- },
401
- vue: {
402
- files: ["vite.config.js", "vite.config.ts"],
403
- dependencies: ["vue", "vite"]
404
- },
405
- svelte: {
406
- files: ["svelte.config.js", "svelte.config.ts"],
407
- dependencies: ["svelte"]
408
- },
409
- astro: {
410
- files: ["astro.config.mjs", "astro.config.ts"],
411
- dependencies: ["astro"]
412
- }
413
- };
414
- var RATE_LIMITS = {
415
- cliTokenExchange: {
416
- windowSeconds: 60,
417
- // 1 minute
418
- maxRequests: 5
419
- },
420
- shareTokenGeneration: {
421
- windowSeconds: 60,
422
- // 1 minute
423
- maxRequests: 10
424
- },
425
- linkCreation: {
426
- windowSeconds: 60,
427
- // 1 minute
428
- maxRequests: 20
429
- },
430
- linkRedirect: {
431
- windowSeconds: 60,
432
- // 1 minute
433
- maxRequests: 100
434
- },
435
- apiGeneral: {
436
- windowSeconds: 60,
437
- // 1 minute
438
- maxRequests: 100
439
- },
440
- // Legacy (deprecated but kept for backwards compatibility)
441
- cliTokenGeneration: {
442
- windowMs: 36e5,
443
- // 1 hour
444
- maxRequests: 10
445
- },
446
- cliValidation: {
447
- windowMs: 36e5,
448
- // 1 hour
449
- maxRequests: 100
450
- },
451
- eventCollection: {
452
- windowMs: 6e4,
453
- // 1 minute
454
- maxRequests: 1e3
455
- }
456
- };
457
- var ERROR_MESSAGES = {
458
- // Authentication
459
- unauthorized: "Unauthorized access",
460
- forbidden: "Access forbidden",
461
- tokenExpired: "Token has expired",
462
- tokenInvalid: "Invalid token",
463
- tokenNotFound: "Token not found",
464
- tokenAlreadyUsed: "Token has already been used",
465
- tokenRevoked: "Token has been revoked",
466
- tokenMissingJti: "Token missing JTI - please re-authenticate",
467
- userBanned: "User account has been banned",
468
- userDeleted: "User account has been deleted",
469
- // Share tokens
470
- shareTokenExpired: "Share token has expired",
471
- shareTokenRevoked: "Share has been revoked",
472
- shareTokenInvalid: "Invalid share token",
473
- // URL Validation
474
- invalidUrl: "Invalid URL provided",
475
- invalidUrlProtocol: "URL must use http or https protocol",
476
- openRedirectBlocked: "Open redirect attempt blocked",
477
- // Validation
478
- invalidInput: "Invalid input provided",
479
- missingRequired: "Missing required fields",
480
- invalidFormat: "Invalid format",
481
- // Resources
482
- notFound: "Resource not found",
483
- websiteNotFound: "Website not found",
484
- userNotFound: "User not found",
485
- linkNotFound: "Link not found",
486
- // Rate limiting
487
- tooManyRequests: "Too many requests. Please try again later.",
488
- rateLimitExceeded: "Rate limit exceeded",
489
- // Server
490
- internalError: "Internal server error",
491
- serviceUnavailable: "Service temporarily unavailable"
492
- };
493
- var SUCCESS_MESSAGES = {
494
- tokenGenerated: "Setup token generated successfully",
495
- tokenValidated: "Token validated successfully",
496
- tokenRevoked: "Token revoked successfully",
497
- allTokensRevoked: "All tokens revoked successfully",
498
- websiteCreated: "Website created successfully",
499
- linkCreated: "Link created successfully",
500
- shareCreated: "Share created successfully",
501
- onboardingComplete: "Onboarding completed successfully",
502
- setupComplete: "Setup completed successfully"
503
- };
504
- function getEnvVarNames(framework) {
505
- return ENV_VAR_NAMES[framework];
506
- }
507
- function getFrameworkPackage(framework) {
508
- return FRAMEWORK_PACKAGES[framework] || null;
509
- }
510
- function isValidFramework(framework) {
511
- return framework in ENV_VAR_NAMES;
512
- }
513
- function getApiRoute(route, ...args) {
514
- const routeFn = API_ROUTES[route];
515
- if (typeof routeFn === "function") {
516
- return routeFn(...args);
517
- }
518
- return routeFn;
519
- }
520
- function getPlan(planId) {
521
- return PLANS[planId];
522
- }
523
- function isPlanFeatureEnabled(planId, feature) {
524
- const plan = PLANS[planId];
525
- return plan?.features?.[feature] === true;
526
- }
527
- function getPlanLimit(planId, limit) {
528
- return PLANS[planId]?.limits?.[limit] ?? 0;
529
- }
530
- function isUsageWarning(current, limit) {
531
- if (limit <= 0) return false;
532
- return current / limit * 100 >= USAGE_THRESHOLDS.warning;
533
- }
534
- function isUsageCritical(current, limit) {
535
- if (limit <= 0) return false;
536
- return current / limit * 100 >= USAGE_THRESHOLDS.critical;
537
- }
538
- function getVitalRating(metric, value) {
539
- const thresholds = VITAL_THRESHOLDS[metric];
540
- if (value <= thresholds.good) return "good";
541
- if (value <= thresholds.poor) return "needs-improvement";
542
- return "poor";
543
- }
544
- function detectDeploymentContext() {
545
- const env = getEnv();
546
- if (!env) return null;
547
- if (env.VERCEL_DEPLOYMENT_ID) {
548
- return {
549
- deployId: env.VERCEL_DEPLOYMENT_ID,
550
- gitSha: env.VERCEL_GIT_COMMIT_SHA,
551
- gitBranch: env.VERCEL_GIT_COMMIT_REF,
552
- deployUrl: env.VERCEL_URL ? `https://${env.VERCEL_URL}` : void 0,
553
- source: "vercel"
554
- };
555
- }
556
- if (env.DEPLOY_ID) {
557
- return {
558
- deployId: env.DEPLOY_ID,
559
- gitSha: env.COMMIT_REF,
560
- gitBranch: env.BRANCH,
561
- deployUrl: env.DEPLOY_URL,
562
- source: "netlify"
563
- };
564
- }
565
- if (env.CF_PAGES_COMMIT_SHA) {
566
- return {
567
- deployId: env.CF_PAGES_COMMIT_SHA,
568
- gitSha: env.CF_PAGES_COMMIT_SHA,
569
- gitBranch: env.CF_PAGES_BRANCH,
570
- deployUrl: env.CF_PAGES_URL,
571
- source: "cloudflare"
572
- };
573
- }
574
- return null;
575
- }
576
- function getEnv() {
577
- try {
578
- if (typeof globalThis !== "undefined" && "process" in globalThis) {
579
- const proc = globalThis.process;
580
- return proc?.env ?? null;
581
- }
582
- return null;
583
- } catch {
584
- return null;
585
- }
586
- }
587
-
588
- exports.API_ENDPOINTS = API_ENDPOINTS;
589
- exports.API_ROUTES = API_ROUTES;
590
- exports.BILLING_ERRORS = BILLING_ERRORS;
591
- exports.CLI_CONFIG = CLI_CONFIG;
592
- exports.CLI_TOKEN_STATUS = CLI_TOKEN_STATUS;
593
- exports.DEFAULT_API_HOST = DEFAULT_API_HOST;
594
- exports.DEPLOYMENT_ENV_VARS = DEPLOYMENT_ENV_VARS;
595
- exports.DEPLOYMENT_SOURCES = DEPLOYMENT_SOURCES;
596
- exports.ENV_VAR_NAMES = ENV_VAR_NAMES;
597
- exports.ERROR_MESSAGES = ERROR_MESSAGES;
598
- exports.EVENT_TYPES = EVENT_TYPES;
599
- exports.EventType = EventType;
600
- exports.FORM_EVENT_TYPES = FORM_EVENT_TYPES;
601
- exports.FORM_FIELD_TYPES = FORM_FIELD_TYPES;
602
- exports.FRAMEWORK_PACKAGES = FRAMEWORK_PACKAGES;
603
- exports.FRAMEWORK_PATTERNS = FRAMEWORK_PATTERNS;
604
- exports.HTTP_STATUS = HTTP_STATUS;
605
- exports.NAVIGATION_TYPES = NAVIGATION_TYPES;
606
- exports.ONBOARDING_STEPS = ONBOARDING_STEPS;
607
- exports.PLANS = PLANS;
608
- exports.PLAN_FEATURES = PLAN_FEATURES;
609
- exports.RATE_LIMITS = RATE_LIMITS;
610
- exports.SDK_EVENT_TYPES = SDK_EVENT_TYPES;
611
- exports.SUCCESS_MESSAGES = SUCCESS_MESSAGES;
612
- exports.USAGE_THRESHOLDS = USAGE_THRESHOLDS;
613
- exports.USER_ROLES = USER_ROLES;
614
- exports.VITAL_RATINGS = VITAL_RATINGS;
615
- exports.VITAL_THRESHOLDS = VITAL_THRESHOLDS;
616
- exports.VITAL_TYPES = VITAL_TYPES;
617
- exports.detectDeploymentContext = detectDeploymentContext;
618
- exports.getApiRoute = getApiRoute;
619
- exports.getEnvVarNames = getEnvVarNames;
620
- exports.getFrameworkPackage = getFrameworkPackage;
621
- exports.getPlan = getPlan;
622
- exports.getPlanLimit = getPlanLimit;
623
- exports.getVitalRating = getVitalRating;
624
- exports.isPlanFeatureEnabled = isPlanFeatureEnabled;
625
- exports.isUsageCritical = isUsageCritical;
626
- exports.isUsageWarning = isUsageWarning;
627
- exports.isValidFramework = isValidFramework;
628
- //# sourceMappingURL=index.cjs.map
629
- //# sourceMappingURL=index.cjs.map