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