@entrolytics/shared 2.3.3 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics-types.d.ts +104 -0
- package/dist/analytics-types.d.ts.map +1 -0
- package/dist/analytics-types.js +2 -0
- package/dist/event-protocol.d.ts +82 -0
- package/dist/event-protocol.d.ts.map +1 -0
- package/dist/event-protocol.js +17 -0
- package/dist/index.d.ts +562 -721
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +665 -610
- package/dist/sdk-validation.test.d.ts +8 -0
- package/dist/sdk-validation.test.d.ts.map +1 -0
- package/dist/sdk-validation.test.js +96 -0
- package/package.json +2 -2
- package/dist/index.cjs +0 -726
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -896
- package/dist/index.d.cts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,685 +1,740 @@
|
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
+
},
|
|
113
92
|
};
|
|
114
93
|
/**
|
|
115
|
-
* Plan feature names for display
|
|
116
|
-
*/
|
|
117
|
-
const PLAN_FEATURES = {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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",
|
|
127
106
|
};
|
|
128
107
|
/**
|
|
129
|
-
* Usage warning thresholds (percentages)
|
|
130
|
-
*/
|
|
131
|
-
const USAGE_THRESHOLDS = {
|
|
132
|
-
|
|
133
|
-
|
|
108
|
+
* Usage warning thresholds (percentages)
|
|
109
|
+
*/
|
|
110
|
+
export const USAGE_THRESHOLDS = {
|
|
111
|
+
warning: 90,
|
|
112
|
+
critical: 95,
|
|
134
113
|
};
|
|
135
114
|
/**
|
|
136
|
-
* Billing-related error codes
|
|
137
|
-
*/
|
|
138
|
-
const BILLING_ERRORS = {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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",
|
|
144
123
|
};
|
|
145
124
|
/**
|
|
146
|
-
* API endpoint configuration
|
|
147
|
-
*/
|
|
148
|
-
const API_ENDPOINTS = {
|
|
149
|
-
|
|
150
|
-
|
|
125
|
+
* API endpoint configuration
|
|
126
|
+
*/
|
|
127
|
+
export const API_ENDPOINTS = {
|
|
128
|
+
production: "https://api.entrolytics.click",
|
|
129
|
+
development: "http://localhost:3001",
|
|
151
130
|
};
|
|
152
131
|
/**
|
|
153
|
-
* Default API host
|
|
154
|
-
*/
|
|
155
|
-
const DEFAULT_API_HOST =
|
|
156
|
-
/**
|
|
157
|
-
* Environment variable naming conventions by framework
|
|
158
|
-
*/
|
|
159
|
-
const ENV_VAR_NAMES = {
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
},
|
|
214
194
|
};
|
|
215
195
|
/**
|
|
216
|
-
* CLI configuration constants
|
|
217
|
-
*/
|
|
218
|
-
const CLI_CONFIG = {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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",
|
|
224
204
|
};
|
|
225
205
|
/**
|
|
226
|
-
* Core event types - matches backend protocol values exactly
|
|
227
|
-
* Used by: API Server, SDKs, CLI, worker processes
|
|
228
|
-
* See: entrolytics/packages/protocol/src/events.ts
|
|
229
|
-
*/
|
|
230
|
-
const EVENT_TYPES = {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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",
|
|
234
214
|
};
|
|
235
215
|
/**
|
|
236
|
-
* Extended event types for SDK-level semantics
|
|
237
|
-
* These are higher-level event categories used by SDKs
|
|
238
|
-
* They map to the core EVENT_TYPES when sent to the backend
|
|
239
|
-
*/
|
|
240
|
-
const SDK_EVENT_TYPES = {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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",
|
|
247
227
|
};
|
|
248
228
|
/**
|
|
249
|
-
* Web Vitals metric types (Phase 2)
|
|
250
|
-
* Core Web Vitals: LCP, INP, CLS
|
|
251
|
-
* Additional: TTFB, FCP
|
|
252
|
-
*/
|
|
253
|
-
const VITAL_TYPES = {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
|
259
239
|
};
|
|
260
240
|
/**
|
|
261
|
-
* Web Vitals rating thresholds
|
|
262
|
-
*/
|
|
263
|
-
const VITAL_RATINGS = {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
241
|
+
* Web Vitals rating thresholds
|
|
242
|
+
*/
|
|
243
|
+
export const VITAL_RATINGS = {
|
|
244
|
+
good: "good",
|
|
245
|
+
needsImprovement: "needs-improvement",
|
|
246
|
+
poor: "poor",
|
|
267
247
|
};
|
|
268
248
|
/**
|
|
269
|
-
* Web Vitals thresholds by metric (in milliseconds, except CLS which is unitless)
|
|
270
|
-
*/
|
|
271
|
-
const VITAL_THRESHOLDS = {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
good: 200,
|
|
278
|
-
poor: 500
|
|
279
|
-
},
|
|
280
|
-
CLS: {
|
|
281
|
-
good: .1,
|
|
282
|
-
poor: .25
|
|
283
|
-
},
|
|
284
|
-
TTFB: {
|
|
285
|
-
good: 800,
|
|
286
|
-
poor: 1800
|
|
287
|
-
},
|
|
288
|
-
FCP: {
|
|
289
|
-
good: 1800,
|
|
290
|
-
poor: 3e3
|
|
291
|
-
}
|
|
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 },
|
|
292
257
|
};
|
|
293
258
|
/**
|
|
294
|
-
* Navigation types for Web Vitals context
|
|
295
|
-
*/
|
|
296
|
-
const NAVIGATION_TYPES = {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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",
|
|
303
268
|
};
|
|
304
269
|
/**
|
|
305
|
-
* Form event types (Phase 2)
|
|
306
|
-
*/
|
|
307
|
-
const FORM_EVENT_TYPES = {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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)
|
|
314
279
|
};
|
|
315
280
|
/**
|
|
316
|
-
* Form field types
|
|
317
|
-
*/
|
|
318
|
-
const FORM_FIELD_TYPES = {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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",
|
|
334
299
|
};
|
|
335
300
|
/**
|
|
336
|
-
* Deployment platform sources (Phase 2)
|
|
337
|
-
*/
|
|
338
|
-
const DEPLOYMENT_SOURCES = {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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",
|
|
350
315
|
};
|
|
351
316
|
/**
|
|
352
|
-
* Deployment environment variables by platform
|
|
353
|
-
*/
|
|
354
|
-
const DEPLOYMENT_ENV_VARS = {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
+
},
|
|
373
338
|
};
|
|
374
339
|
/**
|
|
375
|
-
* HTTP status codes
|
|
376
|
-
*/
|
|
377
|
-
const HTTP_STATUS = {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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,
|
|
390
355
|
};
|
|
391
356
|
/**
|
|
392
|
-
* API route paths
|
|
393
|
-
*/
|
|
394
|
-
const API_ROUTES = {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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",
|
|
430
419
|
};
|
|
431
420
|
/**
|
|
432
|
-
* Onboarding step identifiers
|
|
433
|
-
*/
|
|
434
|
-
const ONBOARDING_STEPS = {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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",
|
|
441
430
|
};
|
|
442
431
|
/**
|
|
443
|
-
* CLI token statuses
|
|
444
|
-
*/
|
|
445
|
-
const CLI_TOKEN_STATUS = {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
432
|
+
* CLI token statuses
|
|
433
|
+
*/
|
|
434
|
+
export const CLI_TOKEN_STATUS = {
|
|
435
|
+
pending: "pending",
|
|
436
|
+
used: "used",
|
|
437
|
+
expired: "expired",
|
|
438
|
+
revoked: "revoked",
|
|
450
439
|
};
|
|
451
440
|
/**
|
|
452
|
-
* User roles
|
|
453
|
-
*/
|
|
454
|
-
const USER_ROLES = {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
441
|
+
* User roles
|
|
442
|
+
*/
|
|
443
|
+
export const USER_ROLES = {
|
|
444
|
+
admin: "admin",
|
|
445
|
+
user: "user",
|
|
446
|
+
viewer: "viewer",
|
|
458
447
|
};
|
|
459
448
|
/**
|
|
460
|
-
* Framework package names
|
|
461
|
-
*/
|
|
462
|
-
const FRAMEWORK_PACKAGES = {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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",
|
|
469
458
|
};
|
|
470
459
|
/**
|
|
471
|
-
* Framework detection patterns
|
|
472
|
-
*/
|
|
473
|
-
const FRAMEWORK_PATTERNS = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
astro: {
|
|
495
|
-
files: ["astro.config.mjs", "astro.config.ts"],
|
|
496
|
-
dependencies: ["astro"]
|
|
497
|
-
}
|
|
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
|
+
},
|
|
498
483
|
};
|
|
499
484
|
/**
|
|
500
|
-
* Rate limiting configuration
|
|
501
|
-
* Updated to match server-side implementation
|
|
502
|
-
*/
|
|
503
|
-
const RATE_LIMITS = {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
+
},
|
|
536
522
|
};
|
|
537
523
|
/**
|
|
538
|
-
* Error messages
|
|
539
|
-
*/
|
|
540
|
-
const ERROR_MESSAGES = {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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",
|
|
568
561
|
};
|
|
569
562
|
/**
|
|
570
|
-
* Success messages
|
|
571
|
-
*/
|
|
572
|
-
const SUCCESS_MESSAGES = {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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",
|
|
582
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
|
+
}
|
|
583
614
|
/**
|
|
584
|
-
* Utility functions
|
|
585
|
-
*/
|
|
586
|
-
function getEnvVarNames(framework) {
|
|
587
|
-
|
|
615
|
+
* Utility functions
|
|
616
|
+
*/
|
|
617
|
+
export function getEnvVarNames(framework) {
|
|
618
|
+
return ENV_VAR_NAMES[framework];
|
|
588
619
|
}
|
|
589
|
-
function getFrameworkPackage(framework) {
|
|
590
|
-
|
|
620
|
+
export function getFrameworkPackage(framework) {
|
|
621
|
+
return FRAMEWORK_PACKAGES[framework] || null;
|
|
591
622
|
}
|
|
592
|
-
function isValidFramework(framework) {
|
|
593
|
-
|
|
623
|
+
export function isValidFramework(framework) {
|
|
624
|
+
return framework in ENV_VAR_NAMES;
|
|
594
625
|
}
|
|
595
|
-
function getApiRoute(route, ...args) {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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;
|
|
599
632
|
}
|
|
600
633
|
/**
|
|
601
|
-
* Get plan by ID
|
|
602
|
-
*/
|
|
603
|
-
function getPlan(planId) {
|
|
604
|
-
|
|
634
|
+
* Get plan by ID
|
|
635
|
+
*/
|
|
636
|
+
export function getPlan(planId) {
|
|
637
|
+
return PLANS[planId];
|
|
605
638
|
}
|
|
606
639
|
/**
|
|
607
|
-
* Check if a feature is available for a plan
|
|
608
|
-
*/
|
|
609
|
-
function isPlanFeatureEnabled(planId, feature) {
|
|
610
|
-
|
|
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;
|
|
611
645
|
}
|
|
612
646
|
/**
|
|
613
|
-
* Get plan limit value (-1 means unlimited)
|
|
614
|
-
*/
|
|
615
|
-
function getPlanLimit(planId, limit) {
|
|
616
|
-
|
|
647
|
+
* Get plan limit value (-1 means unlimited)
|
|
648
|
+
*/
|
|
649
|
+
export function getPlanLimit(planId, limit) {
|
|
650
|
+
return PLANS[planId]?.limits?.[limit] ?? 0;
|
|
617
651
|
}
|
|
618
652
|
/**
|
|
619
|
-
* Check if usage is at warning threshold
|
|
620
|
-
*/
|
|
621
|
-
function isUsageWarning(current, limit) {
|
|
622
|
-
|
|
623
|
-
|
|
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;
|
|
624
659
|
}
|
|
625
660
|
/**
|
|
626
|
-
* Check if usage is at critical threshold
|
|
627
|
-
*/
|
|
628
|
-
function isUsageCritical(current, limit) {
|
|
629
|
-
|
|
630
|
-
|
|
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;
|
|
631
667
|
}
|
|
632
668
|
/**
|
|
633
|
-
* Calculate Web Vital rating from value (Phase 2)
|
|
634
|
-
*/
|
|
635
|
-
function getVitalRating(metric, value) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
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";
|
|
640
678
|
}
|
|
641
679
|
/**
|
|
642
|
-
* Detect deployment context from environment variables (Phase 2)
|
|
643
|
-
* Works in Node.js environments only - returns null in browser
|
|
644
|
-
*/
|
|
645
|
-
function detectDeploymentContext() {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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;
|
|
670
719
|
}
|
|
671
720
|
/**
|
|
672
|
-
* Safe environment variable access (works in browser and Node.js)
|
|
673
|
-
*/
|
|
721
|
+
* Safe environment variable access (works in browser and Node.js)
|
|
722
|
+
*/
|
|
674
723
|
function getEnv() {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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
|
+
}
|
|
681
736
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
737
|
+
// Export analytics types
|
|
738
|
+
export * from "./analytics-types";
|
|
739
|
+
// Export event protocol types (canonical event structures)
|
|
740
|
+
export * from "./event-protocol";
|