@entrolytics/shared 2.4.0 → 2.4.1
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 +6 -5
- package/dist/analytics-types.d.ts +0 -104
- package/dist/analytics-types.d.ts.map +0 -1
- package/dist/analytics-types.js +0 -2
- package/dist/event-protocol.d.ts +0 -82
- package/dist/event-protocol.d.ts.map +0 -1
- package/dist/event-protocol.js +0 -17
- package/dist/index.d.ts +0 -737
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -740
- package/dist/sdk-validation.test.d.ts +0 -8
- package/dist/sdk-validation.test.d.ts.map +0 -1
- package/dist/sdk-validation.test.js +0 -96
package/dist/index.js
DELETED
|
@@ -1,740 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared constants across Entrolytics ecosystem
|
|
3
|
-
* Used by: CLI, SDKs, Dashboard, Integrations
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Plan definitions and limits
|
|
7
|
-
*/
|
|
8
|
-
export const PLANS = {
|
|
9
|
-
starter: {
|
|
10
|
-
id: "starter",
|
|
11
|
-
name: "Starter",
|
|
12
|
-
price: 0,
|
|
13
|
-
limits: {
|
|
14
|
-
pageviewsPerMonth: 25_000,
|
|
15
|
-
websites: 2,
|
|
16
|
-
retentionDays: 30,
|
|
17
|
-
seats: 1,
|
|
18
|
-
},
|
|
19
|
-
features: {
|
|
20
|
-
funnels: false,
|
|
21
|
-
attribution: false,
|
|
22
|
-
revenue: false,
|
|
23
|
-
customDashboards: false,
|
|
24
|
-
apiAccess: false,
|
|
25
|
-
weeklyReports: true,
|
|
26
|
-
support: "community",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
pro: {
|
|
30
|
-
id: "pro",
|
|
31
|
-
name: "Pro",
|
|
32
|
-
price: 29,
|
|
33
|
-
limits: {
|
|
34
|
-
pageviewsPerMonth: 250_000,
|
|
35
|
-
websites: 10,
|
|
36
|
-
retentionDays: 365,
|
|
37
|
-
seats: 5,
|
|
38
|
-
},
|
|
39
|
-
features: {
|
|
40
|
-
funnels: true,
|
|
41
|
-
attribution: true,
|
|
42
|
-
revenue: true,
|
|
43
|
-
customDashboards: false,
|
|
44
|
-
apiAccess: true,
|
|
45
|
-
weeklyReports: true,
|
|
46
|
-
support: "email",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
business: {
|
|
50
|
-
id: "business",
|
|
51
|
-
name: "Business",
|
|
52
|
-
price: 99,
|
|
53
|
-
limits: {
|
|
54
|
-
pageviewsPerMonth: 1_000_000,
|
|
55
|
-
websites: -1, // unlimited
|
|
56
|
-
retentionDays: 730, // 2 years
|
|
57
|
-
seats: -1, // unlimited
|
|
58
|
-
},
|
|
59
|
-
features: {
|
|
60
|
-
funnels: true,
|
|
61
|
-
attribution: true,
|
|
62
|
-
revenue: true,
|
|
63
|
-
customDashboards: true,
|
|
64
|
-
apiAccess: true,
|
|
65
|
-
weeklyReports: true,
|
|
66
|
-
support: "priority",
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
enterprise: {
|
|
70
|
-
id: "enterprise",
|
|
71
|
-
name: "Enterprise",
|
|
72
|
-
price: -1, // custom
|
|
73
|
-
limits: {
|
|
74
|
-
pageviewsPerMonth: -1, // custom
|
|
75
|
-
websites: -1,
|
|
76
|
-
retentionDays: -1, // custom
|
|
77
|
-
seats: -1,
|
|
78
|
-
},
|
|
79
|
-
features: {
|
|
80
|
-
funnels: true,
|
|
81
|
-
attribution: true,
|
|
82
|
-
revenue: true,
|
|
83
|
-
customDashboards: true,
|
|
84
|
-
apiAccess: true,
|
|
85
|
-
weeklyReports: true,
|
|
86
|
-
support: "dedicated",
|
|
87
|
-
sso: true,
|
|
88
|
-
auditLogs: true,
|
|
89
|
-
customRetention: true,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Plan feature names for display
|
|
95
|
-
*/
|
|
96
|
-
export const PLAN_FEATURES = {
|
|
97
|
-
funnels: "Funnel Analytics",
|
|
98
|
-
attribution: "Attribution Reports",
|
|
99
|
-
revenue: "Revenue Tracking",
|
|
100
|
-
customDashboards: "Custom Dashboards",
|
|
101
|
-
apiAccess: "API Access",
|
|
102
|
-
weeklyReports: "Weekly Email Reports",
|
|
103
|
-
sso: "SSO/SAML",
|
|
104
|
-
auditLogs: "Audit Logs",
|
|
105
|
-
customRetention: "Custom Data Retention",
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Usage warning thresholds (percentages)
|
|
109
|
-
*/
|
|
110
|
-
export const USAGE_THRESHOLDS = {
|
|
111
|
-
warning: 90,
|
|
112
|
-
critical: 95,
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Billing-related error codes
|
|
116
|
-
*/
|
|
117
|
-
export const 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
|
-
/**
|
|
125
|
-
* API endpoint configuration
|
|
126
|
-
*/
|
|
127
|
-
export const API_ENDPOINTS = {
|
|
128
|
-
production: "https://api.entrolytics.click",
|
|
129
|
-
development: "http://localhost:3001",
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Default API host
|
|
133
|
-
*/
|
|
134
|
-
export const DEFAULT_API_HOST = getEnv()?.NODE_ENV === "production" ? API_ENDPOINTS.production : API_ENDPOINTS.development;
|
|
135
|
-
/**
|
|
136
|
-
* Environment variable naming conventions by framework
|
|
137
|
-
*/
|
|
138
|
-
export const ENV_VAR_NAMES = {
|
|
139
|
-
nextjs: {
|
|
140
|
-
websiteId: "NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID",
|
|
141
|
-
host: "NEXT_PUBLIC_ENTROLYTICS_HOST",
|
|
142
|
-
envFile: ".env.local",
|
|
143
|
-
},
|
|
144
|
-
react: {
|
|
145
|
-
websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
|
|
146
|
-
host: "VITE_ENTROLYTICS_HOST",
|
|
147
|
-
envFile: ".env",
|
|
148
|
-
fallback: {
|
|
149
|
-
// CRA fallback
|
|
150
|
-
websiteId: "REACT_APP_ENTROLYTICS_WEBSITE_ID",
|
|
151
|
-
host: "REACT_APP_ENTROLYTICS_HOST",
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
vue: {
|
|
155
|
-
websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
|
|
156
|
-
host: "VITE_ENTROLYTICS_HOST",
|
|
157
|
-
envFile: ".env",
|
|
158
|
-
},
|
|
159
|
-
svelte: {
|
|
160
|
-
websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
|
|
161
|
-
host: "PUBLIC_ENTROLYTICS_HOST",
|
|
162
|
-
envFile: ".env",
|
|
163
|
-
},
|
|
164
|
-
astro: {
|
|
165
|
-
websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
|
|
166
|
-
host: "PUBLIC_ENTROLYTICS_HOST",
|
|
167
|
-
envFile: ".env",
|
|
168
|
-
},
|
|
169
|
-
html: {
|
|
170
|
-
websiteId: "ENTROLYTICS_WEBSITE_ID",
|
|
171
|
-
host: "ENTROLYTICS_HOST",
|
|
172
|
-
envFile: ".env",
|
|
173
|
-
},
|
|
174
|
-
node: {
|
|
175
|
-
websiteId: "ENTROLYTICS_WEBSITE_ID",
|
|
176
|
-
host: "ENTROLYTICS_HOST",
|
|
177
|
-
envFile: ".env",
|
|
178
|
-
},
|
|
179
|
-
php: {
|
|
180
|
-
websiteId: "ENTROLYTICS_WEBSITE_ID",
|
|
181
|
-
host: "ENTROLYTICS_HOST",
|
|
182
|
-
envFile: ".env",
|
|
183
|
-
},
|
|
184
|
-
python: {
|
|
185
|
-
websiteId: "ENTROLYTICS_WEBSITE_ID",
|
|
186
|
-
host: "ENTROLYTICS_HOST",
|
|
187
|
-
envFile: ".env",
|
|
188
|
-
},
|
|
189
|
-
go: {
|
|
190
|
-
websiteId: "ENTROLYTICS_WEBSITE_ID",
|
|
191
|
-
host: "ENTROLYTICS_HOST",
|
|
192
|
-
envFile: ".env",
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* CLI configuration constants
|
|
197
|
-
*/
|
|
198
|
-
export const CLI_CONFIG = {
|
|
199
|
-
tokenExpiryMinutes: 15,
|
|
200
|
-
maxTokensPerUser: 10,
|
|
201
|
-
pollIntervalMs: 2000,
|
|
202
|
-
setupTimeoutMs: 300000, // 5 minutes
|
|
203
|
-
minCliVersion: "1.0.0",
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* Core event types - matches backend protocol values exactly
|
|
207
|
-
* Used by: API Server, SDKs, CLI, worker processes
|
|
208
|
-
* See: entrolytics/packages/protocol/src/events.ts
|
|
209
|
-
*/
|
|
210
|
-
export const EVENT_TYPES = {
|
|
211
|
-
pageView: "pageview",
|
|
212
|
-
custom: "custom_event",
|
|
213
|
-
click: "click",
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Extended event types for SDK-level semantics
|
|
217
|
-
* These are higher-level event categories used by SDKs
|
|
218
|
-
* They map to the core EVENT_TYPES when sent to the backend
|
|
219
|
-
*/
|
|
220
|
-
export const SDK_EVENT_TYPES = {
|
|
221
|
-
pageView: "pageview",
|
|
222
|
-
click: "click",
|
|
223
|
-
formSubmit: "form_submit",
|
|
224
|
-
custom: "custom_event",
|
|
225
|
-
error: "error",
|
|
226
|
-
performance: "performance",
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* Web Vitals metric types (Phase 2)
|
|
230
|
-
* Core Web Vitals: LCP, INP, CLS
|
|
231
|
-
* Additional: TTFB, FCP
|
|
232
|
-
*/
|
|
233
|
-
export const VITAL_TYPES = {
|
|
234
|
-
LCP: "LCP", // Largest Contentful Paint
|
|
235
|
-
INP: "INP", // Interaction to Next Paint (replaced FID)
|
|
236
|
-
CLS: "CLS", // Cumulative Layout Shift
|
|
237
|
-
TTFB: "TTFB", // Time to First Byte
|
|
238
|
-
FCP: "FCP", // First Contentful Paint
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Web Vitals rating thresholds
|
|
242
|
-
*/
|
|
243
|
-
export const VITAL_RATINGS = {
|
|
244
|
-
good: "good",
|
|
245
|
-
needsImprovement: "needs-improvement",
|
|
246
|
-
poor: "poor",
|
|
247
|
-
};
|
|
248
|
-
/**
|
|
249
|
-
* Web Vitals thresholds by metric (in milliseconds, except CLS which is unitless)
|
|
250
|
-
*/
|
|
251
|
-
export const VITAL_THRESHOLDS = {
|
|
252
|
-
LCP: { good: 2500, poor: 4000 },
|
|
253
|
-
INP: { good: 200, poor: 500 },
|
|
254
|
-
CLS: { good: 0.1, poor: 0.25 },
|
|
255
|
-
TTFB: { good: 800, poor: 1800 },
|
|
256
|
-
FCP: { good: 1800, poor: 3000 },
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Navigation types for Web Vitals context
|
|
260
|
-
*/
|
|
261
|
-
export const NAVIGATION_TYPES = {
|
|
262
|
-
navigate: "navigate",
|
|
263
|
-
reload: "reload",
|
|
264
|
-
backForward: "back-forward",
|
|
265
|
-
backForwardCache: "back-forward-cache",
|
|
266
|
-
prerender: "prerender",
|
|
267
|
-
restore: "restore",
|
|
268
|
-
};
|
|
269
|
-
/**
|
|
270
|
-
* Form event types (Phase 2)
|
|
271
|
-
*/
|
|
272
|
-
export const FORM_EVENT_TYPES = {
|
|
273
|
-
start: "start", // Form interaction started
|
|
274
|
-
fieldFocus: "field_focus", // Field received focus
|
|
275
|
-
fieldBlur: "field_blur", // Field lost focus
|
|
276
|
-
fieldError: "field_error", // Field validation error
|
|
277
|
-
submit: "submit", // Form submitted
|
|
278
|
-
abandon: "abandon", // Form abandoned (left page)
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* Form field types
|
|
282
|
-
*/
|
|
283
|
-
export const FORM_FIELD_TYPES = {
|
|
284
|
-
text: "text",
|
|
285
|
-
email: "email",
|
|
286
|
-
password: "password",
|
|
287
|
-
tel: "tel",
|
|
288
|
-
number: "number",
|
|
289
|
-
url: "url",
|
|
290
|
-
textarea: "textarea",
|
|
291
|
-
select: "select",
|
|
292
|
-
checkbox: "checkbox",
|
|
293
|
-
radio: "radio",
|
|
294
|
-
date: "date",
|
|
295
|
-
file: "file",
|
|
296
|
-
hidden: "hidden",
|
|
297
|
-
submit: "submit",
|
|
298
|
-
other: "other",
|
|
299
|
-
};
|
|
300
|
-
/**
|
|
301
|
-
* Deployment platform sources (Phase 2)
|
|
302
|
-
*/
|
|
303
|
-
export const DEPLOYMENT_SOURCES = {
|
|
304
|
-
vercel: "vercel",
|
|
305
|
-
netlify: "netlify",
|
|
306
|
-
cloudflare: "cloudflare",
|
|
307
|
-
railway: "railway",
|
|
308
|
-
render: "render",
|
|
309
|
-
fly: "fly",
|
|
310
|
-
heroku: "heroku",
|
|
311
|
-
aws: "aws",
|
|
312
|
-
gcp: "gcp",
|
|
313
|
-
azure: "azure",
|
|
314
|
-
custom: "custom",
|
|
315
|
-
};
|
|
316
|
-
/**
|
|
317
|
-
* Deployment environment variables by platform
|
|
318
|
-
*/
|
|
319
|
-
export const DEPLOYMENT_ENV_VARS = {
|
|
320
|
-
vercel: {
|
|
321
|
-
deployId: "VERCEL_DEPLOYMENT_ID",
|
|
322
|
-
gitSha: "VERCEL_GIT_COMMIT_SHA",
|
|
323
|
-
gitBranch: "VERCEL_GIT_COMMIT_REF",
|
|
324
|
-
url: "VERCEL_URL",
|
|
325
|
-
},
|
|
326
|
-
netlify: {
|
|
327
|
-
deployId: "DEPLOY_ID",
|
|
328
|
-
gitSha: "COMMIT_REF",
|
|
329
|
-
gitBranch: "BRANCH",
|
|
330
|
-
url: "DEPLOY_URL",
|
|
331
|
-
},
|
|
332
|
-
cloudflare: {
|
|
333
|
-
deployId: "CF_PAGES_COMMIT_SHA",
|
|
334
|
-
gitSha: "CF_PAGES_COMMIT_SHA",
|
|
335
|
-
gitBranch: "CF_PAGES_BRANCH",
|
|
336
|
-
url: "CF_PAGES_URL",
|
|
337
|
-
},
|
|
338
|
-
};
|
|
339
|
-
/**
|
|
340
|
-
* HTTP status codes
|
|
341
|
-
*/
|
|
342
|
-
export const HTTP_STATUS = {
|
|
343
|
-
ok: 200,
|
|
344
|
-
created: 201,
|
|
345
|
-
accepted: 202,
|
|
346
|
-
noContent: 204,
|
|
347
|
-
badRequest: 400,
|
|
348
|
-
unauthorized: 401,
|
|
349
|
-
forbidden: 403,
|
|
350
|
-
notFound: 404,
|
|
351
|
-
conflict: 409,
|
|
352
|
-
tooManyRequests: 429,
|
|
353
|
-
internalServerError: 500,
|
|
354
|
-
serviceUnavailable: 503,
|
|
355
|
-
};
|
|
356
|
-
/**
|
|
357
|
-
* API route paths
|
|
358
|
-
*/
|
|
359
|
-
export const API_ROUTES = {
|
|
360
|
-
// CLI Auth routes
|
|
361
|
-
cliAuthToken: "/api/auth/cli/token",
|
|
362
|
-
cliAuthTokens: "/api/auth/cli/tokens",
|
|
363
|
-
cliValidate: "/api/auth/cli/validate",
|
|
364
|
-
cliToken: "/api/cli/token", // Legacy - deprecated
|
|
365
|
-
// Share routes
|
|
366
|
-
shareToken: (shareId) => `/api/share/${shareId}`,
|
|
367
|
-
// Links routes
|
|
368
|
-
links: "/api/links",
|
|
369
|
-
linkRedirect: (slug) => `/q/${slug}`,
|
|
370
|
-
// Website routes
|
|
371
|
-
websites: "/api/websites",
|
|
372
|
-
websiteById: (id) => `/api/websites/${id}`,
|
|
373
|
-
websiteEvents: (id) => `/api/websites/${id}/events`,
|
|
374
|
-
websiteRecentEvents: (id) => `/api/websites/${id}/recent-events`,
|
|
375
|
-
// User routes
|
|
376
|
-
userOnboarding: "/api/user/onboarding",
|
|
377
|
-
userProfile: "/api/user/profile",
|
|
378
|
-
userEmailPreferences: "/api/me/email-preferences",
|
|
379
|
-
// Billing routes
|
|
380
|
-
billingUsage: "/api/billing/usage",
|
|
381
|
-
billingCheckout: "/api/billing/checkout",
|
|
382
|
-
billingPortal: "/api/billing/portal",
|
|
383
|
-
billingWebhook: "/api/billing/webhook",
|
|
384
|
-
// Analytics routes (REST)
|
|
385
|
-
analyticsOverview: (websiteId) => `/api/analytics/${websiteId}/overview`,
|
|
386
|
-
analyticsTimeseries: (websiteId) => `/api/analytics/${websiteId}/timeseries`,
|
|
387
|
-
analyticsTopPages: (websiteId) => `/api/analytics/${websiteId}/top-pages`,
|
|
388
|
-
analyticsTopReferrers: (websiteId) => `/api/analytics/${websiteId}/top-referrers`,
|
|
389
|
-
analyticsGeography: (websiteId) => `/api/analytics/${websiteId}/geography`,
|
|
390
|
-
analyticsDevices: (websiteId) => `/api/analytics/${websiteId}/devices`,
|
|
391
|
-
// Event collection
|
|
392
|
-
collect: "/collect",
|
|
393
|
-
collectBatch: "/collect/batch",
|
|
394
|
-
send: "/collect",
|
|
395
|
-
// Phase 2: Web Vitals, Forms, Deployments
|
|
396
|
-
collectVitals: "/api/collect/vitals",
|
|
397
|
-
collectVitalsBatch: "/api/collect/vitals/batch",
|
|
398
|
-
collectForms: "/api/collect/forms",
|
|
399
|
-
collectFormsBatch: "/api/collect/forms/batch",
|
|
400
|
-
vitalsOverview: "/api/vitals/overview",
|
|
401
|
-
vitalsByPage: "/api/vitals/by-page",
|
|
402
|
-
vitalsTrend: "/api/vitals/trend",
|
|
403
|
-
vitalsRecent: "/api/vitals/recent",
|
|
404
|
-
vitalsPageBreakdown: "/api/vitals/page-breakdown",
|
|
405
|
-
formsConversions: "/api/forms/conversions",
|
|
406
|
-
formsFieldMetrics: "/api/forms/field-metrics",
|
|
407
|
-
formsFunnel: "/api/forms/funnel",
|
|
408
|
-
formsRecent: "/api/forms/recent",
|
|
409
|
-
deployments: "/api/deployments",
|
|
410
|
-
deploymentByWebsite: (id) => `/api/deployments/${id}`,
|
|
411
|
-
deploymentLatest: (id) => `/api/deployments/${id}/latest`,
|
|
412
|
-
// Backwards-compatible aliases for legacy website-scoped helpers
|
|
413
|
-
websiteVitals: (id) => `/api/vitals/overview?websiteId=${encodeURIComponent(id)}`,
|
|
414
|
-
websiteForms: (id) => `/api/forms/conversions?websiteId=${encodeURIComponent(id)}`,
|
|
415
|
-
websiteDeployments: (id) => `/api/deployments/${encodeURIComponent(id)}`,
|
|
416
|
-
// Health checks
|
|
417
|
-
health: "/api/health",
|
|
418
|
-
healthIntegrations: "/api/health/integrations",
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Onboarding step identifiers
|
|
422
|
-
*/
|
|
423
|
-
export const ONBOARDING_STEPS = {
|
|
424
|
-
welcome: "welcome",
|
|
425
|
-
createWebsite: "create-website",
|
|
426
|
-
installTracking: "install-tracking",
|
|
427
|
-
verify: "verify",
|
|
428
|
-
complete: "complete",
|
|
429
|
-
skipped: "skipped",
|
|
430
|
-
};
|
|
431
|
-
/**
|
|
432
|
-
* CLI token statuses
|
|
433
|
-
*/
|
|
434
|
-
export const CLI_TOKEN_STATUS = {
|
|
435
|
-
pending: "pending",
|
|
436
|
-
used: "used",
|
|
437
|
-
expired: "expired",
|
|
438
|
-
revoked: "revoked",
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* User roles
|
|
442
|
-
*/
|
|
443
|
-
export const USER_ROLES = {
|
|
444
|
-
admin: "admin",
|
|
445
|
-
user: "user",
|
|
446
|
-
viewer: "viewer",
|
|
447
|
-
};
|
|
448
|
-
/**
|
|
449
|
-
* Framework package names
|
|
450
|
-
*/
|
|
451
|
-
export const FRAMEWORK_PACKAGES = {
|
|
452
|
-
nextjs: "@entrolytics/nextjs-sdk",
|
|
453
|
-
react: "@entrolytics/react-sdk",
|
|
454
|
-
vue: "@entrolytics/vue-sdk",
|
|
455
|
-
svelte: "@entrolytics/svelte-sdk",
|
|
456
|
-
astro: "@entrolytics/astro-sdk",
|
|
457
|
-
node: "@entrolytics/node-sdk",
|
|
458
|
-
};
|
|
459
|
-
/**
|
|
460
|
-
* Framework detection patterns
|
|
461
|
-
*/
|
|
462
|
-
export const FRAMEWORK_PATTERNS = {
|
|
463
|
-
nextjs: {
|
|
464
|
-
files: ["next.config.js", "next.config.mjs", "next.config.ts"],
|
|
465
|
-
dependencies: ["next"],
|
|
466
|
-
},
|
|
467
|
-
react: {
|
|
468
|
-
files: ["vite.config.js", "vite.config.ts"],
|
|
469
|
-
dependencies: ["react", "vite"],
|
|
470
|
-
},
|
|
471
|
-
vue: {
|
|
472
|
-
files: ["vite.config.js", "vite.config.ts"],
|
|
473
|
-
dependencies: ["vue", "vite"],
|
|
474
|
-
},
|
|
475
|
-
svelte: {
|
|
476
|
-
files: ["svelte.config.js", "svelte.config.ts"],
|
|
477
|
-
dependencies: ["svelte"],
|
|
478
|
-
},
|
|
479
|
-
astro: {
|
|
480
|
-
files: ["astro.config.mjs", "astro.config.ts"],
|
|
481
|
-
dependencies: ["astro"],
|
|
482
|
-
},
|
|
483
|
-
};
|
|
484
|
-
/**
|
|
485
|
-
* Rate limiting configuration
|
|
486
|
-
* Updated to match server-side implementation
|
|
487
|
-
*/
|
|
488
|
-
export const RATE_LIMITS = {
|
|
489
|
-
cliTokenExchange: {
|
|
490
|
-
windowSeconds: 60, // 1 minute
|
|
491
|
-
maxRequests: 5,
|
|
492
|
-
},
|
|
493
|
-
shareTokenGeneration: {
|
|
494
|
-
windowSeconds: 60, // 1 minute
|
|
495
|
-
maxRequests: 10,
|
|
496
|
-
},
|
|
497
|
-
linkCreation: {
|
|
498
|
-
windowSeconds: 60, // 1 minute
|
|
499
|
-
maxRequests: 20,
|
|
500
|
-
},
|
|
501
|
-
linkRedirect: {
|
|
502
|
-
windowSeconds: 60, // 1 minute
|
|
503
|
-
maxRequests: 100,
|
|
504
|
-
},
|
|
505
|
-
apiGeneral: {
|
|
506
|
-
windowSeconds: 60, // 1 minute
|
|
507
|
-
maxRequests: 100,
|
|
508
|
-
},
|
|
509
|
-
// Legacy (deprecated but kept for backwards compatibility)
|
|
510
|
-
cliTokenGeneration: {
|
|
511
|
-
windowMs: 3600000, // 1 hour
|
|
512
|
-
maxRequests: 10,
|
|
513
|
-
},
|
|
514
|
-
cliValidation: {
|
|
515
|
-
windowMs: 3600000, // 1 hour
|
|
516
|
-
maxRequests: 100,
|
|
517
|
-
},
|
|
518
|
-
eventCollection: {
|
|
519
|
-
windowMs: 60000, // 1 minute
|
|
520
|
-
maxRequests: 1000,
|
|
521
|
-
},
|
|
522
|
-
};
|
|
523
|
-
/**
|
|
524
|
-
* Error messages
|
|
525
|
-
*/
|
|
526
|
-
export const ERROR_MESSAGES = {
|
|
527
|
-
// Authentication
|
|
528
|
-
unauthorized: "Unauthorized access",
|
|
529
|
-
forbidden: "Access forbidden",
|
|
530
|
-
tokenExpired: "Token has expired",
|
|
531
|
-
tokenInvalid: "Invalid token",
|
|
532
|
-
tokenNotFound: "Token not found",
|
|
533
|
-
tokenAlreadyUsed: "Token has already been used",
|
|
534
|
-
tokenRevoked: "Token has been revoked",
|
|
535
|
-
tokenMissingJti: "Token missing JTI - please re-authenticate",
|
|
536
|
-
userBanned: "User account has been banned",
|
|
537
|
-
userDeleted: "User account has been deleted",
|
|
538
|
-
// Share tokens
|
|
539
|
-
shareTokenExpired: "Share token has expired",
|
|
540
|
-
shareTokenRevoked: "Share has been revoked",
|
|
541
|
-
shareTokenInvalid: "Invalid share token",
|
|
542
|
-
// URL Validation
|
|
543
|
-
invalidUrl: "Invalid URL provided",
|
|
544
|
-
invalidUrlProtocol: "URL must use http or https protocol",
|
|
545
|
-
openRedirectBlocked: "Open redirect attempt blocked",
|
|
546
|
-
// Validation
|
|
547
|
-
invalidInput: "Invalid input provided",
|
|
548
|
-
missingRequired: "Missing required fields",
|
|
549
|
-
invalidFormat: "Invalid format",
|
|
550
|
-
// Resources
|
|
551
|
-
notFound: "Resource not found",
|
|
552
|
-
websiteNotFound: "Website not found",
|
|
553
|
-
userNotFound: "User not found",
|
|
554
|
-
linkNotFound: "Link not found",
|
|
555
|
-
// Rate limiting
|
|
556
|
-
tooManyRequests: "Too many requests. Please try again later.",
|
|
557
|
-
rateLimitExceeded: "Rate limit exceeded",
|
|
558
|
-
// Server
|
|
559
|
-
internalError: "Internal server error",
|
|
560
|
-
serviceUnavailable: "Service temporarily unavailable",
|
|
561
|
-
};
|
|
562
|
-
/**
|
|
563
|
-
* Success messages
|
|
564
|
-
*/
|
|
565
|
-
export const SUCCESS_MESSAGES = {
|
|
566
|
-
tokenGenerated: "Setup token generated successfully",
|
|
567
|
-
tokenValidated: "Token validated successfully",
|
|
568
|
-
tokenRevoked: "Token revoked successfully",
|
|
569
|
-
allTokensRevoked: "All tokens revoked successfully",
|
|
570
|
-
websiteCreated: "Website created successfully",
|
|
571
|
-
linkCreated: "Link created successfully",
|
|
572
|
-
shareCreated: "Share created successfully",
|
|
573
|
-
onboardingComplete: "Onboarding completed successfully",
|
|
574
|
-
setupComplete: "Setup completed successfully",
|
|
575
|
-
};
|
|
576
|
-
export const EVENT_TYPE_VALUES = Object.values(EVENT_TYPES);
|
|
577
|
-
export const SDK_EVENT_TYPE_VALUES = Object.values(SDK_EVENT_TYPES);
|
|
578
|
-
export const VITAL_TYPE_VALUES = Object.values(VITAL_TYPES);
|
|
579
|
-
export const VITAL_RATING_VALUES = Object.values(VITAL_RATINGS);
|
|
580
|
-
export const NAVIGATION_TYPE_VALUES = Object.values(NAVIGATION_TYPES);
|
|
581
|
-
export const FORM_EVENT_TYPE_VALUES = Object.values(FORM_EVENT_TYPES);
|
|
582
|
-
export const FORM_FIELD_TYPE_VALUES = Object.values(FORM_FIELD_TYPES);
|
|
583
|
-
export const DEPLOYMENT_SOURCE_VALUES = Object.values(DEPLOYMENT_SOURCES);
|
|
584
|
-
export function isEventType(value) {
|
|
585
|
-
return EVENT_TYPE_VALUES.includes(value);
|
|
586
|
-
}
|
|
587
|
-
export function isSdkEventType(value) {
|
|
588
|
-
return SDK_EVENT_TYPE_VALUES.includes(value);
|
|
589
|
-
}
|
|
590
|
-
export function isVitalType(value) {
|
|
591
|
-
return VITAL_TYPE_VALUES.includes(value);
|
|
592
|
-
}
|
|
593
|
-
export function isVitalRating(value) {
|
|
594
|
-
return VITAL_RATING_VALUES.includes(value);
|
|
595
|
-
}
|
|
596
|
-
export function isNavigationType(value) {
|
|
597
|
-
return NAVIGATION_TYPE_VALUES.includes(value);
|
|
598
|
-
}
|
|
599
|
-
export function isFormEventType(value) {
|
|
600
|
-
return FORM_EVENT_TYPE_VALUES.includes(value);
|
|
601
|
-
}
|
|
602
|
-
export function isFormFieldType(value) {
|
|
603
|
-
return FORM_FIELD_TYPE_VALUES.includes(value);
|
|
604
|
-
}
|
|
605
|
-
export function isDeploymentSource(value) {
|
|
606
|
-
return DEPLOYMENT_SOURCE_VALUES.includes(value);
|
|
607
|
-
}
|
|
608
|
-
export function normalizeDeploymentSource(value) {
|
|
609
|
-
if (!value) {
|
|
610
|
-
return "custom";
|
|
611
|
-
}
|
|
612
|
-
return isDeploymentSource(value) ? value : "custom";
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* Utility functions
|
|
616
|
-
*/
|
|
617
|
-
export function getEnvVarNames(framework) {
|
|
618
|
-
return ENV_VAR_NAMES[framework];
|
|
619
|
-
}
|
|
620
|
-
export function getFrameworkPackage(framework) {
|
|
621
|
-
return FRAMEWORK_PACKAGES[framework] || null;
|
|
622
|
-
}
|
|
623
|
-
export function isValidFramework(framework) {
|
|
624
|
-
return framework in ENV_VAR_NAMES;
|
|
625
|
-
}
|
|
626
|
-
export function getApiRoute(route, ...args) {
|
|
627
|
-
const routeFn = API_ROUTES[route];
|
|
628
|
-
if (typeof routeFn === "function") {
|
|
629
|
-
return routeFn(...args);
|
|
630
|
-
}
|
|
631
|
-
return routeFn;
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Get plan by ID
|
|
635
|
-
*/
|
|
636
|
-
export function getPlan(planId) {
|
|
637
|
-
return PLANS[planId];
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Check if a feature is available for a plan
|
|
641
|
-
*/
|
|
642
|
-
export function isPlanFeatureEnabled(planId, feature) {
|
|
643
|
-
const plan = PLANS[planId];
|
|
644
|
-
return plan?.features?.[feature] === true;
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Get plan limit value (-1 means unlimited)
|
|
648
|
-
*/
|
|
649
|
-
export function getPlanLimit(planId, limit) {
|
|
650
|
-
return PLANS[planId]?.limits?.[limit] ?? 0;
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Check if usage is at warning threshold
|
|
654
|
-
*/
|
|
655
|
-
export function isUsageWarning(current, limit) {
|
|
656
|
-
if (limit <= 0)
|
|
657
|
-
return false; // unlimited
|
|
658
|
-
return (current / limit) * 100 >= USAGE_THRESHOLDS.warning;
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* Check if usage is at critical threshold
|
|
662
|
-
*/
|
|
663
|
-
export function isUsageCritical(current, limit) {
|
|
664
|
-
if (limit <= 0)
|
|
665
|
-
return false; // unlimited
|
|
666
|
-
return (current / limit) * 100 >= USAGE_THRESHOLDS.critical;
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Calculate Web Vital rating from value (Phase 2)
|
|
670
|
-
*/
|
|
671
|
-
export function getVitalRating(metric, value) {
|
|
672
|
-
const thresholds = VITAL_THRESHOLDS[metric];
|
|
673
|
-
if (value <= thresholds.good)
|
|
674
|
-
return "good";
|
|
675
|
-
if (value <= thresholds.poor)
|
|
676
|
-
return "needs-improvement";
|
|
677
|
-
return "poor";
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Detect deployment context from environment variables (Phase 2)
|
|
681
|
-
* Works in Node.js environments only - returns null in browser
|
|
682
|
-
*/
|
|
683
|
-
export function detectDeploymentContext() {
|
|
684
|
-
// Safe access to process.env in any environment
|
|
685
|
-
const env = getEnv();
|
|
686
|
-
if (!env)
|
|
687
|
-
return null;
|
|
688
|
-
// Vercel
|
|
689
|
-
if (env.VERCEL_DEPLOYMENT_ID) {
|
|
690
|
-
return {
|
|
691
|
-
deployId: env.VERCEL_DEPLOYMENT_ID,
|
|
692
|
-
gitSha: env.VERCEL_GIT_COMMIT_SHA,
|
|
693
|
-
gitBranch: env.VERCEL_GIT_COMMIT_REF,
|
|
694
|
-
deployUrl: env.VERCEL_URL ? `https://${env.VERCEL_URL}` : undefined,
|
|
695
|
-
source: "vercel",
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
// Netlify
|
|
699
|
-
if (env.DEPLOY_ID) {
|
|
700
|
-
return {
|
|
701
|
-
deployId: env.DEPLOY_ID,
|
|
702
|
-
gitSha: env.COMMIT_REF,
|
|
703
|
-
gitBranch: env.BRANCH,
|
|
704
|
-
deployUrl: env.DEPLOY_URL,
|
|
705
|
-
source: "netlify",
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
// Cloudflare Pages
|
|
709
|
-
if (env.CF_PAGES_COMMIT_SHA) {
|
|
710
|
-
return {
|
|
711
|
-
deployId: env.CF_PAGES_COMMIT_SHA,
|
|
712
|
-
gitSha: env.CF_PAGES_COMMIT_SHA,
|
|
713
|
-
gitBranch: env.CF_PAGES_BRANCH,
|
|
714
|
-
deployUrl: env.CF_PAGES_URL,
|
|
715
|
-
source: "cloudflare",
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
return null;
|
|
719
|
-
}
|
|
720
|
-
/**
|
|
721
|
-
* Safe environment variable access (works in browser and Node.js)
|
|
722
|
-
*/
|
|
723
|
-
function getEnv() {
|
|
724
|
-
try {
|
|
725
|
-
// Check if we're in a Node.js-like environment
|
|
726
|
-
if (typeof globalThis !== "undefined" && "process" in globalThis) {
|
|
727
|
-
const proc = globalThis
|
|
728
|
-
.process;
|
|
729
|
-
return proc?.env ?? null;
|
|
730
|
-
}
|
|
731
|
-
return null;
|
|
732
|
-
}
|
|
733
|
-
catch {
|
|
734
|
-
return null;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
// Export analytics types
|
|
738
|
-
export * from "./analytics-types";
|
|
739
|
-
// Export event protocol types (canonical event structures)
|
|
740
|
-
export * from "./event-protocol";
|