@entrolytics/shared 2.0.1 → 2.0.2

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