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