@outlit/core 1.1.0 → 1.4.5
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.d.mts +177 -108
- package/dist/index.d.ts +177 -108
- package/dist/index.js +96 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -201
package/dist/index.d.ts
CHANGED
|
@@ -18,29 +18,36 @@ interface BrowserTrackOptions {
|
|
|
18
18
|
eventName: string;
|
|
19
19
|
properties?: Record<string, string | number | boolean | null>;
|
|
20
20
|
}
|
|
21
|
-
interface BrowserIdentifyOptions {
|
|
21
|
+
interface BrowserIdentifyOptions extends CustomerAttribution {
|
|
22
22
|
email?: string;
|
|
23
|
+
/** Your system-owned user/contact ID. */
|
|
23
24
|
userId?: string;
|
|
25
|
+
/** User/contact traits. */
|
|
24
26
|
traits?: IdentifyTraits;
|
|
27
|
+
/** Customer/account-level traits. */
|
|
28
|
+
customerTraits?: CustomerTraits;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* Base server-side user identity.
|
|
32
|
+
* Track calls may use customerId/customerDomain without these fields.
|
|
33
|
+
* Identify calls still require email or userId at runtime.
|
|
30
34
|
*
|
|
31
35
|
* - fingerprint: Device identifier for anonymous tracking (can be linked later)
|
|
32
36
|
* - email: User's email address (definitive identity, resolves immediately)
|
|
33
|
-
* - userId:
|
|
37
|
+
* - userId: Your system-owned user/contact ID
|
|
34
38
|
*/
|
|
35
39
|
interface ServerIdentity {
|
|
36
40
|
fingerprint?: string;
|
|
37
41
|
email?: string;
|
|
42
|
+
/** Your system-owned user/contact ID. */
|
|
38
43
|
userId?: string;
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*/
|
|
45
|
+
interface CustomerAttribution {
|
|
46
|
+
/** Your system-owned customer/account/workspace ID. */
|
|
47
|
+
customerId?: string;
|
|
48
|
+
/** Public customer/account domain used for billing and attribution. */
|
|
49
|
+
customerDomain?: string;
|
|
50
|
+
}
|
|
44
51
|
interface CustomerTraits {
|
|
45
52
|
/** Customer's billing plan */
|
|
46
53
|
plan?: string;
|
|
@@ -48,33 +55,36 @@ interface CustomerTraits {
|
|
|
48
55
|
[key: string]: string | number | boolean | null | undefined;
|
|
49
56
|
}
|
|
50
57
|
/**
|
|
51
|
-
* Traits for identify calls
|
|
52
|
-
*
|
|
58
|
+
* Traits for identify calls.
|
|
59
|
+
* These are user/contact traits, not customer/account traits.
|
|
53
60
|
*/
|
|
54
61
|
interface IdentifyTraits {
|
|
55
|
-
/** Nested customer/account-level traits */
|
|
56
|
-
customer?: CustomerTraits;
|
|
57
62
|
/** User-level traits */
|
|
58
|
-
[key: string]: string | number | boolean | null |
|
|
63
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
59
64
|
}
|
|
60
|
-
interface ServerTrackOptions extends ServerIdentity {
|
|
65
|
+
interface ServerTrackOptions extends ServerIdentity, CustomerAttribution {
|
|
61
66
|
eventName: string;
|
|
62
67
|
properties?: Record<string, string | number | boolean | null>;
|
|
63
68
|
timestamp?: number;
|
|
64
69
|
}
|
|
65
|
-
interface ServerIdentifyOptions extends ServerIdentity {
|
|
70
|
+
interface ServerIdentifyOptions extends ServerIdentity, CustomerAttribution {
|
|
66
71
|
traits?: IdentifyTraits;
|
|
72
|
+
customerTraits?: CustomerTraits;
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
75
|
* Customer identity for SDK billing methods.
|
|
70
|
-
*
|
|
76
|
+
* Public billing calls should use `customerId` and/or `customerDomain`.
|
|
71
77
|
*/
|
|
72
|
-
interface CustomerIdentifier {
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
interface CustomerIdentifier extends CustomerAttribution {
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `customerDomain` instead.
|
|
81
|
+
* Legacy alias kept for backward compatibility.
|
|
82
|
+
*/
|
|
83
|
+
domain?: string;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Stripe customer identifier.
|
|
86
|
+
* Billing attribution should use `customerId` and/or `customerDomain` publicly.
|
|
87
|
+
*/
|
|
78
88
|
stripeCustomerId?: string;
|
|
79
89
|
}
|
|
80
90
|
interface BaseEvent {
|
|
@@ -99,11 +109,19 @@ interface IdentifyEvent extends BaseEvent {
|
|
|
99
109
|
email?: string;
|
|
100
110
|
userId?: string;
|
|
101
111
|
fingerprint?: string;
|
|
112
|
+
customerId?: string;
|
|
113
|
+
customerDomain?: string;
|
|
114
|
+
customerTraits?: CustomerTraits;
|
|
102
115
|
traits?: IdentifyTraits;
|
|
103
116
|
}
|
|
104
117
|
interface CustomEvent extends BaseEvent {
|
|
105
118
|
type: "custom";
|
|
106
119
|
eventName: string;
|
|
120
|
+
email?: string;
|
|
121
|
+
userId?: string;
|
|
122
|
+
fingerprint?: string;
|
|
123
|
+
customerId?: string;
|
|
124
|
+
customerDomain?: string;
|
|
107
125
|
properties?: Record<string, string | number | boolean | null>;
|
|
108
126
|
}
|
|
109
127
|
interface CalendarEvent extends BaseEvent {
|
|
@@ -140,8 +158,10 @@ interface BillingEvent extends BaseEvent {
|
|
|
140
158
|
status: BillingStatus;
|
|
141
159
|
/** Optional customer identifiers */
|
|
142
160
|
customerId?: string;
|
|
143
|
-
|
|
161
|
+
customerDomain?: string;
|
|
162
|
+
/** @deprecated Legacy alias for `customerDomain`. */
|
|
144
163
|
domain?: string;
|
|
164
|
+
stripeCustomerId?: string;
|
|
145
165
|
/** Optional properties for context */
|
|
146
166
|
properties?: Record<string, string | number | boolean | null>;
|
|
147
167
|
}
|
|
@@ -149,10 +169,37 @@ type TrackerEvent = PageviewEvent | FormEvent | IdentifyEvent | CustomEvent | Ca
|
|
|
149
169
|
/**
|
|
150
170
|
* User identity for payload-level resolution.
|
|
151
171
|
* Used by browser SDK when user is logged in (via setUser).
|
|
172
|
+
* Customer attribution is carried separately in `customerIdentity`.
|
|
152
173
|
*/
|
|
153
174
|
interface PayloadUserIdentity {
|
|
154
175
|
email?: string;
|
|
176
|
+
/** Your system-owned user/contact ID. */
|
|
155
177
|
userId?: string;
|
|
178
|
+
/** User/contact traits. */
|
|
179
|
+
traits?: IdentifyTraits;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use payload-level `customerIdentity.customerId` instead.
|
|
182
|
+
* Kept for one compatibility window while callers migrate.
|
|
183
|
+
*/
|
|
184
|
+
customerId?: string;
|
|
185
|
+
/**
|
|
186
|
+
* @deprecated Use payload-level `customerIdentity.customerDomain` instead.
|
|
187
|
+
* Kept for one compatibility window while callers migrate.
|
|
188
|
+
*/
|
|
189
|
+
customerDomain?: string;
|
|
190
|
+
/**
|
|
191
|
+
* @deprecated Use payload-level `customerIdentity.customerTraits` instead.
|
|
192
|
+
* Kept for one compatibility window while callers migrate.
|
|
193
|
+
*/
|
|
194
|
+
customerTraits?: CustomerTraits;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Customer identity for payload-level attribution.
|
|
198
|
+
* Used by browser SDK to attach account/workspace context to a batch.
|
|
199
|
+
*/
|
|
200
|
+
interface PayloadCustomerIdentity extends CustomerAttribution {
|
|
201
|
+
/** Customer/account traits. */
|
|
202
|
+
customerTraits?: CustomerTraits;
|
|
156
203
|
}
|
|
157
204
|
interface IngestPayload {
|
|
158
205
|
visitorId?: string;
|
|
@@ -180,6 +227,12 @@ interface IngestPayload {
|
|
|
180
227
|
* allowing immediate identity resolution for SPA/React apps.
|
|
181
228
|
*/
|
|
182
229
|
userIdentity?: PayloadUserIdentity;
|
|
230
|
+
/**
|
|
231
|
+
* Customer/account identity for this batch of events.
|
|
232
|
+
* Used to attribute browser batches to a customer/workspace even when
|
|
233
|
+
* the customer fields are not present on every event.
|
|
234
|
+
*/
|
|
235
|
+
customerIdentity?: PayloadCustomerIdentity;
|
|
183
236
|
}
|
|
184
237
|
interface IngestResponse {
|
|
185
238
|
success: boolean;
|
|
@@ -193,88 +246,6 @@ declare const DEFAULT_API_HOST = "https://app.outlit.ai";
|
|
|
193
246
|
|
|
194
247
|
declare const DEFAULT_DENIED_FORM_FIELDS: string[];
|
|
195
248
|
|
|
196
|
-
/**
|
|
197
|
-
* Extract UTM parameters from a URL.
|
|
198
|
-
*/
|
|
199
|
-
declare function extractUtmParams(url: string): UtmParams | undefined;
|
|
200
|
-
/**
|
|
201
|
-
* Extract path from a URL.
|
|
202
|
-
*/
|
|
203
|
-
declare function extractPathFromUrl(url: string): string;
|
|
204
|
-
/**
|
|
205
|
-
* Check if a field name should be denied (case-insensitive).
|
|
206
|
-
*/
|
|
207
|
-
declare function isFieldDenied(fieldName: string, denylist: string[]): boolean;
|
|
208
|
-
/**
|
|
209
|
-
* Sanitize form fields by removing sensitive data.
|
|
210
|
-
* Returns a new object with denied fields removed.
|
|
211
|
-
*/
|
|
212
|
-
declare function sanitizeFormFields(fields: Record<string, string> | undefined, customDenylist?: string[]): Record<string, string> | undefined;
|
|
213
|
-
/**
|
|
214
|
-
* Validate that at least one identity field is provided.
|
|
215
|
-
* Used by the server SDK to enforce identity requirements.
|
|
216
|
-
*
|
|
217
|
-
* Valid identities:
|
|
218
|
-
* - fingerprint: Device identifier (for anonymous tracking, can be linked later)
|
|
219
|
-
* - email: User's email (definitive identity)
|
|
220
|
-
* - userId: App's internal user ID
|
|
221
|
-
*/
|
|
222
|
-
declare function validateServerIdentity(fingerprint?: string, email?: string, userId?: string): void;
|
|
223
|
-
/**
|
|
224
|
-
* Validate that a string looks like a valid email address.
|
|
225
|
-
*/
|
|
226
|
-
declare function isValidEmail(value: string): boolean;
|
|
227
|
-
/**
|
|
228
|
-
* Find an email value from form fields.
|
|
229
|
-
*
|
|
230
|
-
* Priority:
|
|
231
|
-
* 1. Fields with input type="email" (if inputTypes map provided)
|
|
232
|
-
* 2. Field names matching email patterns
|
|
233
|
-
* 3. Any field with a value that looks like an email
|
|
234
|
-
*
|
|
235
|
-
* @param fields - Form field key-value pairs
|
|
236
|
-
* @param inputTypes - Optional map of field names to input types
|
|
237
|
-
* @returns The email value if found, undefined otherwise
|
|
238
|
-
*/
|
|
239
|
-
declare function findEmailField(fields: Record<string, string>, inputTypes?: Map<string, string>): string | undefined;
|
|
240
|
-
/**
|
|
241
|
-
* Extract name fields from form data.
|
|
242
|
-
*
|
|
243
|
-
* Looks for:
|
|
244
|
-
* - Full name fields (name, full_name, etc.)
|
|
245
|
-
* - First name fields (first_name, fname, etc.)
|
|
246
|
-
* - Last name fields (last_name, lname, etc.)
|
|
247
|
-
*
|
|
248
|
-
* If only first/last names are found, combines them into a full name.
|
|
249
|
-
*
|
|
250
|
-
* @param fields - Form field key-value pairs
|
|
251
|
-
* @returns Object with name, firstName, and/or lastName if found
|
|
252
|
-
*/
|
|
253
|
-
declare function findNameFields(fields: Record<string, string>): {
|
|
254
|
-
name?: string;
|
|
255
|
-
firstName?: string;
|
|
256
|
-
lastName?: string;
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Identity extracted from a form submission.
|
|
260
|
-
*/
|
|
261
|
-
interface ExtractedIdentity {
|
|
262
|
-
email: string;
|
|
263
|
-
name?: string;
|
|
264
|
-
firstName?: string;
|
|
265
|
-
lastName?: string;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Extract identity information (email + name) from form fields.
|
|
269
|
-
*
|
|
270
|
-
* Returns undefined if no valid email is found (email is required for identification).
|
|
271
|
-
*
|
|
272
|
-
* @param fields - Form field key-value pairs
|
|
273
|
-
* @param inputTypes - Optional map of field names to input types
|
|
274
|
-
* @returns Extracted identity with email and optional name fields, or undefined
|
|
275
|
-
*/
|
|
276
|
-
declare function extractIdentityFromForm(fields: Record<string, string>, inputTypes?: Map<string, string>): ExtractedIdentity | undefined;
|
|
277
|
-
|
|
278
249
|
interface BaseEventParams {
|
|
279
250
|
url: string;
|
|
280
251
|
referrer?: string;
|
|
@@ -301,6 +272,9 @@ declare function buildIdentifyEvent(params: BaseEventParams & {
|
|
|
301
272
|
userId?: string;
|
|
302
273
|
fingerprint?: string;
|
|
303
274
|
traits?: IdentifyTraits;
|
|
275
|
+
customerId?: string;
|
|
276
|
+
customerDomain?: string;
|
|
277
|
+
customerTraits?: CustomerTraits;
|
|
304
278
|
}): IdentifyEvent;
|
|
305
279
|
/**
|
|
306
280
|
* Build a custom event.
|
|
@@ -308,6 +282,11 @@ declare function buildIdentifyEvent(params: BaseEventParams & {
|
|
|
308
282
|
declare function buildCustomEvent(params: BaseEventParams & {
|
|
309
283
|
eventName: string;
|
|
310
284
|
properties?: Record<string, string | number | boolean | null>;
|
|
285
|
+
email?: string;
|
|
286
|
+
userId?: string;
|
|
287
|
+
fingerprint?: string;
|
|
288
|
+
customerId?: string;
|
|
289
|
+
customerDomain?: string;
|
|
311
290
|
}): CustomEvent;
|
|
312
291
|
/**
|
|
313
292
|
* Build a calendar booking event.
|
|
@@ -347,6 +326,7 @@ declare function buildStageEvent(params: BaseEventParams & {
|
|
|
347
326
|
declare function buildBillingEvent(params: BaseEventParams & {
|
|
348
327
|
status: BillingStatus;
|
|
349
328
|
customerId?: string;
|
|
329
|
+
customerDomain?: string;
|
|
350
330
|
stripeCustomerId?: string;
|
|
351
331
|
domain?: string;
|
|
352
332
|
properties?: Record<string, string | number | boolean | null>;
|
|
@@ -360,8 +340,9 @@ declare function buildBillingEvent(params: BaseEventParams & {
|
|
|
360
340
|
* @param userIdentity - Optional user identity for immediate resolution (from setUser in SPA)
|
|
361
341
|
* @param sessionId - Optional session ID for grouping events (browser SDK only)
|
|
362
342
|
* @param fingerprint - Optional device identifier for server-side anonymous tracking
|
|
343
|
+
* @param customerIdentity - Optional customer identity for batch attribution
|
|
363
344
|
*/
|
|
364
|
-
declare function buildIngestPayload(visitorId: string, source: SourceType, events: TrackerEvent[], userIdentity?: PayloadUserIdentity, sessionId?: string, fingerprint?: string): IngestPayload;
|
|
345
|
+
declare function buildIngestPayload(visitorId: string, source: SourceType, events: TrackerEvent[], userIdentity?: PayloadUserIdentity, sessionId?: string, fingerprint?: string, customerIdentity?: PayloadCustomerIdentity): IngestPayload;
|
|
365
346
|
/**
|
|
366
347
|
* Maximum number of events in a single batch.
|
|
367
348
|
*/
|
|
@@ -371,4 +352,92 @@ declare const MAX_BATCH_SIZE = 100;
|
|
|
371
352
|
*/
|
|
372
353
|
declare function batchEvents(events: TrackerEvent[]): TrackerEvent[][];
|
|
373
354
|
|
|
374
|
-
|
|
355
|
+
/**
|
|
356
|
+
* Extract UTM parameters from a URL.
|
|
357
|
+
*/
|
|
358
|
+
declare function extractUtmParams(url: string): UtmParams | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* Extract path from a URL.
|
|
361
|
+
*/
|
|
362
|
+
declare function extractPathFromUrl(url: string): string;
|
|
363
|
+
/**
|
|
364
|
+
* Check if a field name should be denied (case-insensitive).
|
|
365
|
+
*/
|
|
366
|
+
declare function isFieldDenied(fieldName: string, denylist: string[]): boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Sanitize form fields by removing sensitive data.
|
|
369
|
+
* Returns a new object with denied fields removed.
|
|
370
|
+
*/
|
|
371
|
+
declare function sanitizeFormFields(fields: Record<string, string> | undefined, customDenylist?: string[]): Record<string, string> | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* Validate that at least one identity field is provided.
|
|
374
|
+
* Used by the server SDK to enforce identity requirements.
|
|
375
|
+
*
|
|
376
|
+
* Valid identities:
|
|
377
|
+
* - fingerprint: Device identifier (for anonymous tracking, can be linked later)
|
|
378
|
+
* - email: User's email (definitive identity)
|
|
379
|
+
* - userId: Your system-owned user/contact ID
|
|
380
|
+
* - customerId: Your system-owned customer/account/workspace ID
|
|
381
|
+
* - customerDomain: Public customer/account domain used for billing and attribution
|
|
382
|
+
*/
|
|
383
|
+
declare function validateServerIdentity(fingerprint?: string, email?: string, userId?: string, customerId?: string, customerDomain?: string): void;
|
|
384
|
+
/**
|
|
385
|
+
* Validate that at least one customer identifier is provided for billing calls.
|
|
386
|
+
*/
|
|
387
|
+
declare function validateCustomerIdentity(customerId?: string, customerDomain?: string, domain?: string, stripeCustomerId?: string): void;
|
|
388
|
+
/**
|
|
389
|
+
* Validate that a string looks like a valid email address.
|
|
390
|
+
*/
|
|
391
|
+
declare function isValidEmail(value: string): boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Find an email value from form fields.
|
|
394
|
+
*
|
|
395
|
+
* Priority:
|
|
396
|
+
* 1. Fields with input type="email" (if inputTypes map provided)
|
|
397
|
+
* 2. Field names matching email patterns
|
|
398
|
+
* 3. Any field with a value that looks like an email
|
|
399
|
+
*
|
|
400
|
+
* @param fields - Form field key-value pairs
|
|
401
|
+
* @param inputTypes - Optional map of field names to input types
|
|
402
|
+
* @returns The email value if found, undefined otherwise
|
|
403
|
+
*/
|
|
404
|
+
declare function findEmailField(fields: Record<string, string>, inputTypes?: Map<string, string>): string | undefined;
|
|
405
|
+
/**
|
|
406
|
+
* Extract name fields from form data.
|
|
407
|
+
*
|
|
408
|
+
* Looks for:
|
|
409
|
+
* - Full name fields (name, full_name, etc.)
|
|
410
|
+
* - First name fields (first_name, fname, etc.)
|
|
411
|
+
* - Last name fields (last_name, lname, etc.)
|
|
412
|
+
*
|
|
413
|
+
* If only first/last names are found, combines them into a full name.
|
|
414
|
+
*
|
|
415
|
+
* @param fields - Form field key-value pairs
|
|
416
|
+
* @returns Object with name, firstName, and/or lastName if found
|
|
417
|
+
*/
|
|
418
|
+
declare function findNameFields(fields: Record<string, string>): {
|
|
419
|
+
name?: string;
|
|
420
|
+
firstName?: string;
|
|
421
|
+
lastName?: string;
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Identity extracted from a form submission.
|
|
425
|
+
*/
|
|
426
|
+
interface ExtractedIdentity {
|
|
427
|
+
email: string;
|
|
428
|
+
name?: string;
|
|
429
|
+
firstName?: string;
|
|
430
|
+
lastName?: string;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Extract identity information (email + name) from form fields.
|
|
434
|
+
*
|
|
435
|
+
* Returns undefined if no valid email is found (email is required for identification).
|
|
436
|
+
*
|
|
437
|
+
* @param fields - Form field key-value pairs
|
|
438
|
+
* @param inputTypes - Optional map of field names to input types
|
|
439
|
+
* @returns Extracted identity with email and optional name fields, or undefined
|
|
440
|
+
*/
|
|
441
|
+
declare function extractIdentityFromForm(fields: Record<string, string>, inputTypes?: Map<string, string>): ExtractedIdentity | undefined;
|
|
442
|
+
|
|
443
|
+
export { type BillingEvent, type BillingStatus, type BrowserIdentifyOptions, type BrowserTrackOptions, type CalendarEvent, type CalendarProvider, type CustomEvent, type CustomerAttribution, type CustomerIdentifier, type CustomerTraits, DEFAULT_API_HOST, DEFAULT_DENIED_FORM_FIELDS, type EngagementEvent, type EventType, type ExplicitJourneyStage, type ExtractedIdentity, type FormEvent, type IdentifyEvent, type IdentifyTraits, type IngestPayload, type IngestResponse, MAX_BATCH_SIZE, type PageviewEvent, type PayloadCustomerIdentity, type PayloadUserIdentity, type ServerIdentifyOptions, type ServerIdentity, type ServerTrackOptions, type SourceType, type StageEvent, type TrackerConfig, type TrackerEvent, type UtmParams, batchEvents, buildBillingEvent, buildCalendarEvent, buildCustomEvent, buildEngagementEvent, buildFormEvent, buildIdentifyEvent, buildIngestPayload, buildPageviewEvent, buildStageEvent, extractIdentityFromForm, extractPathFromUrl, extractUtmParams, findEmailField, findNameFields, isFieldDenied, isValidEmail, sanitizeFormFields, validateCustomerIdentity, validateServerIdentity };
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(src_exports, {
|
|
|
41
41
|
isFieldDenied: () => isFieldDenied,
|
|
42
42
|
isValidEmail: () => isValidEmail,
|
|
43
43
|
sanitizeFormFields: () => sanitizeFormFields,
|
|
44
|
+
validateCustomerIdentity: () => validateCustomerIdentity,
|
|
44
45
|
validateServerIdentity: () => validateServerIdentity
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -95,7 +96,16 @@ function extractUtmParams(url) {
|
|
|
95
96
|
function extractPathFromUrl(url) {
|
|
96
97
|
try {
|
|
97
98
|
const urlObj = new URL(url);
|
|
98
|
-
|
|
99
|
+
let path = urlObj.pathname;
|
|
100
|
+
const hash = urlObj.hash;
|
|
101
|
+
if (hash && hash.length > 1 && (!urlObj.hostname || urlObj.protocol === "file:")) {
|
|
102
|
+
path = hash.replace(/^#/, "");
|
|
103
|
+
} else if (hash.startsWith("#/") && (urlObj.pathname === "/" || urlObj.pathname.endsWith("/index.html"))) {
|
|
104
|
+
path = hash.slice(1);
|
|
105
|
+
}
|
|
106
|
+
if (!path) return "/";
|
|
107
|
+
if (!path.startsWith("/")) return `/${path}`;
|
|
108
|
+
return path;
|
|
99
109
|
} catch (error) {
|
|
100
110
|
console.warn(
|
|
101
111
|
`[Outlit] Failed to parse URL for path extraction: "${url}", defaulting to "/"`,
|
|
@@ -134,13 +144,26 @@ function sanitizeFormFields(fields, customDenylist) {
|
|
|
134
144
|
}
|
|
135
145
|
return Object.keys(sanitized).length > 0 ? sanitized : void 0;
|
|
136
146
|
}
|
|
137
|
-
function validateServerIdentity(fingerprint, email, userId) {
|
|
147
|
+
function validateServerIdentity(fingerprint, email, userId, customerId, customerDomain) {
|
|
138
148
|
const hasFingerprint = fingerprint && fingerprint.trim().length > 0;
|
|
139
149
|
const hasEmail = email && email.trim().length > 0;
|
|
140
150
|
const hasUserId = userId && userId.trim().length > 0;
|
|
141
|
-
|
|
151
|
+
const hasCustomerId = customerId && customerId.trim().length > 0;
|
|
152
|
+
const hasCustomerDomain = customerDomain && customerDomain.trim().length > 0;
|
|
153
|
+
if (!hasFingerprint && !hasEmail && !hasUserId && !hasCustomerId && !hasCustomerDomain) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"Server SDK requires at least one of: fingerprint, email, userId, customerId, or customerDomain for track calls. Use fingerprint/email/userId for user-scoped tracking or customerId/customerDomain for customer-only tracking."
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function validateCustomerIdentity(customerId, customerDomain, domain, stripeCustomerId) {
|
|
160
|
+
const hasCustomerId = customerId && customerId.trim().length > 0;
|
|
161
|
+
const hasCustomerDomain = customerDomain && customerDomain.trim().length > 0;
|
|
162
|
+
const hasDomain = domain && domain.trim().length > 0;
|
|
163
|
+
const hasStripeCustomerId = stripeCustomerId && stripeCustomerId.trim().length > 0;
|
|
164
|
+
if (!hasCustomerId && !hasCustomerDomain && !hasDomain && !hasStripeCustomerId) {
|
|
142
165
|
throw new Error(
|
|
143
|
-
"
|
|
166
|
+
"Billing methods require customerId or customerDomain. Use customerId for your system-owned account ID and customerDomain for the public account domain."
|
|
144
167
|
);
|
|
145
168
|
}
|
|
146
169
|
}
|
|
@@ -279,7 +302,18 @@ function buildFormEvent(params) {
|
|
|
279
302
|
};
|
|
280
303
|
}
|
|
281
304
|
function buildIdentifyEvent(params) {
|
|
282
|
-
const {
|
|
305
|
+
const {
|
|
306
|
+
url,
|
|
307
|
+
referrer,
|
|
308
|
+
timestamp,
|
|
309
|
+
email,
|
|
310
|
+
userId,
|
|
311
|
+
fingerprint,
|
|
312
|
+
traits,
|
|
313
|
+
customerId,
|
|
314
|
+
customerDomain,
|
|
315
|
+
customerTraits
|
|
316
|
+
} = params;
|
|
283
317
|
return {
|
|
284
318
|
type: "identify",
|
|
285
319
|
timestamp: timestamp ?? Date.now(),
|
|
@@ -290,11 +324,25 @@ function buildIdentifyEvent(params) {
|
|
|
290
324
|
email,
|
|
291
325
|
userId,
|
|
292
326
|
fingerprint,
|
|
327
|
+
customerId,
|
|
328
|
+
customerDomain,
|
|
329
|
+
customerTraits,
|
|
293
330
|
traits
|
|
294
331
|
};
|
|
295
332
|
}
|
|
296
333
|
function buildCustomEvent(params) {
|
|
297
|
-
const {
|
|
334
|
+
const {
|
|
335
|
+
url,
|
|
336
|
+
referrer,
|
|
337
|
+
timestamp,
|
|
338
|
+
eventName,
|
|
339
|
+
properties,
|
|
340
|
+
email,
|
|
341
|
+
userId,
|
|
342
|
+
fingerprint,
|
|
343
|
+
customerId,
|
|
344
|
+
customerDomain
|
|
345
|
+
} = params;
|
|
298
346
|
return {
|
|
299
347
|
type: "custom",
|
|
300
348
|
timestamp: timestamp ?? Date.now(),
|
|
@@ -303,6 +351,11 @@ function buildCustomEvent(params) {
|
|
|
303
351
|
referrer,
|
|
304
352
|
utm: extractUtmParams(url),
|
|
305
353
|
eventName,
|
|
354
|
+
email,
|
|
355
|
+
userId,
|
|
356
|
+
fingerprint,
|
|
357
|
+
customerId,
|
|
358
|
+
customerDomain,
|
|
306
359
|
properties
|
|
307
360
|
};
|
|
308
361
|
}
|
|
@@ -365,7 +418,17 @@ function buildStageEvent(params) {
|
|
|
365
418
|
};
|
|
366
419
|
}
|
|
367
420
|
function buildBillingEvent(params) {
|
|
368
|
-
const {
|
|
421
|
+
const {
|
|
422
|
+
url,
|
|
423
|
+
referrer,
|
|
424
|
+
timestamp,
|
|
425
|
+
status,
|
|
426
|
+
customerId,
|
|
427
|
+
customerDomain,
|
|
428
|
+
stripeCustomerId,
|
|
429
|
+
domain,
|
|
430
|
+
properties
|
|
431
|
+
} = params;
|
|
369
432
|
return {
|
|
370
433
|
type: "billing",
|
|
371
434
|
timestamp: timestamp ?? Date.now(),
|
|
@@ -375,27 +438,48 @@ function buildBillingEvent(params) {
|
|
|
375
438
|
utm: extractUtmParams(url),
|
|
376
439
|
status,
|
|
377
440
|
customerId,
|
|
441
|
+
customerDomain: customerDomain ?? domain,
|
|
442
|
+
domain: domain ?? customerDomain,
|
|
378
443
|
stripeCustomerId,
|
|
379
|
-
domain,
|
|
380
444
|
properties
|
|
381
445
|
};
|
|
382
446
|
}
|
|
383
|
-
function buildIngestPayload(visitorId, source, events, userIdentity, sessionId, fingerprint) {
|
|
447
|
+
function buildIngestPayload(visitorId, source, events, userIdentity, sessionId, fingerprint, customerIdentity) {
|
|
384
448
|
const payload = {
|
|
385
449
|
visitorId,
|
|
386
450
|
source,
|
|
387
451
|
events
|
|
388
452
|
};
|
|
453
|
+
const legacyCustomerIdentity = customerIdentity === void 0 && userIdentity && (userIdentity.customerId || userIdentity.customerDomain || userIdentity.customerTraits) ? {
|
|
454
|
+
...userIdentity.customerId && { customerId: userIdentity.customerId },
|
|
455
|
+
...userIdentity.customerDomain && { customerDomain: userIdentity.customerDomain },
|
|
456
|
+
...userIdentity.customerTraits && { customerTraits: userIdentity.customerTraits }
|
|
457
|
+
} : void 0;
|
|
458
|
+
const resolvedCustomerIdentity = customerIdentity ?? legacyCustomerIdentity;
|
|
389
459
|
if (fingerprint) {
|
|
390
460
|
payload.fingerprint = fingerprint;
|
|
391
461
|
}
|
|
392
462
|
if (sessionId) {
|
|
393
463
|
payload.sessionId = sessionId;
|
|
394
464
|
}
|
|
395
|
-
if (userIdentity && (userIdentity.email || userIdentity.userId)) {
|
|
465
|
+
if (userIdentity && (userIdentity.email || userIdentity.userId || userIdentity.traits)) {
|
|
396
466
|
payload.userIdentity = {
|
|
397
467
|
...userIdentity.email && { email: userIdentity.email },
|
|
398
|
-
...userIdentity.userId && { userId: userIdentity.userId }
|
|
468
|
+
...userIdentity.userId && { userId: userIdentity.userId },
|
|
469
|
+
...userIdentity.traits && { traits: userIdentity.traits }
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (resolvedCustomerIdentity && (resolvedCustomerIdentity.customerId || resolvedCustomerIdentity.customerDomain || resolvedCustomerIdentity.customerTraits)) {
|
|
473
|
+
payload.customerIdentity = {
|
|
474
|
+
...resolvedCustomerIdentity.customerId && {
|
|
475
|
+
customerId: resolvedCustomerIdentity.customerId
|
|
476
|
+
},
|
|
477
|
+
...resolvedCustomerIdentity.customerDomain && {
|
|
478
|
+
customerDomain: resolvedCustomerIdentity.customerDomain
|
|
479
|
+
},
|
|
480
|
+
...resolvedCustomerIdentity.customerTraits && {
|
|
481
|
+
customerTraits: resolvedCustomerIdentity.customerTraits
|
|
482
|
+
}
|
|
399
483
|
};
|
|
400
484
|
}
|
|
401
485
|
return payload;
|
|
@@ -431,6 +515,7 @@ function batchEvents(events) {
|
|
|
431
515
|
isFieldDenied,
|
|
432
516
|
isValidEmail,
|
|
433
517
|
sanitizeFormFields,
|
|
518
|
+
validateCustomerIdentity,
|
|
434
519
|
validateServerIdentity
|
|
435
520
|
});
|
|
436
521
|
//# sourceMappingURL=index.js.map
|