@outlit/core 1.5.2 → 3.0.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/index.d.ts CHANGED
@@ -1,14 +1,187 @@
1
- type EventType = "pageview" | "form" | "identify" | "custom" | "calendar" | "engagement" | "stage" | "billing";
2
- type ExplicitJourneyStage = "activated" | "engaged" | "inactive";
3
- type BillingStatus = "trialing" | "paid" | "churned";
4
- type CalendarProvider = "cal.com" | "calendly" | "unknown";
5
- type SourceType = "client" | "server" | "integration";
1
+ type GeneratedIngestPayload = {
2
+ visitorId?: string;
3
+ fingerprint?: string;
4
+ source?: "client" | "server" | "integration";
5
+ events: Array<{
6
+ uuid?: string;
7
+ type: "pageview";
8
+ timestamp: number;
9
+ url: string;
10
+ path: string;
11
+ referrer?: string;
12
+ utm?: {
13
+ source?: string;
14
+ medium?: string;
15
+ campaign?: string;
16
+ term?: string;
17
+ content?: string;
18
+ ref?: string;
19
+ };
20
+ customerId?: string;
21
+ customerTraits?: Record<string, string | number | boolean | null>;
22
+ title?: string;
23
+ } | {
24
+ uuid?: string;
25
+ type: "form";
26
+ timestamp: number;
27
+ url: string;
28
+ path: string;
29
+ referrer?: string;
30
+ utm?: {
31
+ source?: string;
32
+ medium?: string;
33
+ campaign?: string;
34
+ term?: string;
35
+ content?: string;
36
+ ref?: string;
37
+ };
38
+ customerId?: string;
39
+ customerTraits?: Record<string, string | number | boolean | null>;
40
+ formId?: string;
41
+ formFields?: Record<string, string>;
42
+ } | {
43
+ uuid?: string;
44
+ type: "identify";
45
+ timestamp: number;
46
+ url: string;
47
+ path: string;
48
+ referrer?: string;
49
+ utm?: {
50
+ source?: string;
51
+ medium?: string;
52
+ campaign?: string;
53
+ term?: string;
54
+ content?: string;
55
+ ref?: string;
56
+ };
57
+ email?: string;
58
+ userId?: string;
59
+ fingerprint?: string;
60
+ customerId?: string;
61
+ customerTraits?: Record<string, string | number | boolean | null>;
62
+ traits?: Record<string, string | number | boolean | null>;
63
+ } | {
64
+ uuid?: string;
65
+ type: "custom";
66
+ timestamp: number;
67
+ url: string;
68
+ path: string;
69
+ referrer?: string;
70
+ utm?: {
71
+ source?: string;
72
+ medium?: string;
73
+ campaign?: string;
74
+ term?: string;
75
+ content?: string;
76
+ ref?: string;
77
+ };
78
+ customerId?: string;
79
+ customerTraits?: Record<string, string | number | boolean | null>;
80
+ email?: string;
81
+ userId?: string;
82
+ fingerprint?: string;
83
+ eventName: string;
84
+ properties?: Record<string, unknown>;
85
+ } | {
86
+ uuid?: string;
87
+ type: "calendar";
88
+ timestamp: number;
89
+ url: string;
90
+ path: string;
91
+ referrer?: string;
92
+ utm?: {
93
+ source?: string;
94
+ medium?: string;
95
+ campaign?: string;
96
+ term?: string;
97
+ content?: string;
98
+ ref?: string;
99
+ };
100
+ customerId?: string;
101
+ customerTraits?: Record<string, string | number | boolean | null>;
102
+ provider: "cal.com" | "calendly" | "unknown";
103
+ eventType?: string;
104
+ startTime?: string;
105
+ endTime?: string;
106
+ duration?: number;
107
+ isRecurring?: boolean;
108
+ inviteeEmail?: string;
109
+ inviteeName?: string;
110
+ } | {
111
+ uuid?: string;
112
+ type: "engagement";
113
+ timestamp: number;
114
+ url: string;
115
+ path: string;
116
+ referrer?: string;
117
+ utm?: {
118
+ source?: string;
119
+ medium?: string;
120
+ campaign?: string;
121
+ term?: string;
122
+ content?: string;
123
+ ref?: string;
124
+ };
125
+ customerId?: string;
126
+ customerTraits?: Record<string, string | number | boolean | null>;
127
+ activeTimeMs: number;
128
+ totalTimeMs: number;
129
+ sessionId: string;
130
+ }>;
131
+ sessionId?: string;
132
+ userIdentity?: {
133
+ email?: string;
134
+ userId?: string;
135
+ fingerprint?: string;
136
+ traits?: Record<string, string | number | boolean | null>;
137
+ };
138
+ customerIdentity?: {
139
+ customerId?: string;
140
+ customerTraits?: Record<string, string | number | boolean | null>;
141
+ };
142
+ };
143
+ type GeneratedIngestResponse = {
144
+ success: boolean;
145
+ processed: number;
146
+ errors?: Array<{
147
+ index: number;
148
+ message: string;
149
+ }>;
150
+ };
151
+
152
+ type IngestPayload = GeneratedIngestPayload;
153
+ type IngestResponse = GeneratedIngestResponse;
154
+ type TrackerEvent = IngestPayload["events"][number];
155
+ type EventType = TrackerEvent["type"];
156
+ type SourceType = NonNullable<IngestPayload["source"]>;
157
+ type PageviewEvent = Extract<TrackerEvent, {
158
+ type: "pageview";
159
+ }>;
160
+ type FormEvent = Extract<TrackerEvent, {
161
+ type: "form";
162
+ }>;
163
+ type IdentifyEvent = Extract<TrackerEvent, {
164
+ type: "identify";
165
+ }>;
166
+ type CustomEvent = Extract<TrackerEvent, {
167
+ type: "custom";
168
+ }>;
169
+ type CalendarEvent = Extract<TrackerEvent, {
170
+ type: "calendar";
171
+ }>;
172
+ type EngagementEvent = Extract<TrackerEvent, {
173
+ type: "engagement";
174
+ }>;
175
+ type CalendarProvider = CalendarEvent["provider"];
176
+ type PayloadUserIdentity = NonNullable<IngestPayload["userIdentity"]>;
177
+ type PayloadCustomerIdentity = NonNullable<IngestPayload["customerIdentity"]>;
6
178
  interface UtmParams {
7
179
  source?: string;
8
180
  medium?: string;
9
181
  campaign?: string;
10
182
  term?: string;
11
183
  content?: string;
184
+ ref?: string;
12
185
  }
13
186
  interface TrackerConfig {
14
187
  publicKey: string;
@@ -63,173 +236,30 @@ interface IdentifyTraits {
63
236
  /** User-level traits */
64
237
  [key: string]: string | number | boolean | null | undefined;
65
238
  }
66
- interface ServerTrackOptions extends ServerIdentity, CustomerAttribution {
67
- eventName: string;
68
- properties?: Record<string, string | number | boolean | null>;
69
- timestamp?: number;
70
- }
71
- interface ServerIdentifyOptions extends ServerIdentity, CustomerAttribution {
72
- traits?: IdentifyTraits;
73
- customerTraits?: CustomerTraits;
74
- }
75
- /**
76
- * Customer identity for SDK billing methods.
77
- * Public billing calls should use `customerId`.
78
- */
79
- interface CustomerIdentifier extends CustomerAttribution {
80
- /**
81
- * @deprecated Stripe customer identifier.
82
- * Billing attribution should use `customerId` publicly.
83
- */
84
- stripeCustomerId?: string;
85
- }
86
- interface BaseEvent {
87
- uuid?: string;
88
- type: EventType;
89
- timestamp: number;
90
- url: string;
91
- path: string;
92
- referrer?: string;
93
- utm?: UtmParams;
94
- }
95
- interface PageviewEvent extends BaseEvent {
96
- type: "pageview";
97
- title?: string;
98
- }
99
- interface FormEvent extends BaseEvent {
100
- type: "form";
101
- formId?: string;
102
- formFields?: Record<string, string>;
103
- }
104
- interface IdentifyEvent extends BaseEvent {
105
- type: "identify";
106
- email?: string;
107
- userId?: string;
108
- fingerprint?: string;
109
- customerId?: string;
110
- customerTraits?: CustomerTraits;
111
- traits?: IdentifyTraits;
112
- }
113
- interface CustomEvent extends BaseEvent {
114
- type: "custom";
115
- eventName: string;
116
- email?: string;
117
- userId?: string;
118
- fingerprint?: string;
119
- customerId?: string;
120
- properties?: Record<string, string | number | boolean | null>;
121
- }
122
- interface CalendarEvent extends BaseEvent {
123
- type: "calendar";
124
- provider: CalendarProvider;
125
- eventType?: string;
126
- startTime?: string;
127
- endTime?: string;
128
- duration?: number;
129
- isRecurring?: boolean;
130
- /** Available when identity is passed via webhooks or manual integration */
131
- inviteeEmail?: string;
132
- inviteeName?: string;
133
- }
134
- interface EngagementEvent extends BaseEvent {
135
- type: "engagement";
136
- /** Time in milliseconds the user was actively engaged (visible tab + user interactions) */
137
- activeTimeMs: number;
138
- /** Total wall-clock time in milliseconds on the page */
139
- totalTimeMs: number;
140
- /** Session ID for grouping engagement events. Resets after 30 min of inactivity or tab close. */
141
- sessionId: string;
142
- }
143
- interface StageEvent extends BaseEvent {
144
- type: "stage";
145
- /** Stage event value. New SDK callers should only send "activated". */
146
- stage: ExplicitJourneyStage;
147
- /** Optional properties for context */
148
- properties?: Record<string, string | number | boolean | null>;
149
- }
150
- interface BillingEvent extends BaseEvent {
151
- type: "billing";
152
- /** The billing status to set for a customer */
153
- status: BillingStatus;
154
- /** Optional customer identifiers */
155
- customerId?: string;
156
- stripeCustomerId?: string;
157
- /** Optional properties for context */
158
- properties?: Record<string, string | number | boolean | null>;
159
- }
160
- type TrackerEvent = PageviewEvent | FormEvent | IdentifyEvent | CustomEvent | CalendarEvent | EngagementEvent | StageEvent | BillingEvent;
161
239
  /**
162
- * User identity for payload-level resolution.
163
- * Used by browser SDK when user is logged in (via setUser).
164
- * Customer attribution is carried separately in `customerIdentity`.
240
+ * Input accepted by the payload builder. Deprecated customer fields are lifted
241
+ * into the wire-level `customerIdentity` object and are never sent in `userIdentity`.
165
242
  */
166
- interface PayloadUserIdentity {
167
- email?: string;
168
- /** Your system-owned user/contact ID. */
169
- userId?: string;
243
+ type PayloadUserIdentityInput = Omit<PayloadUserIdentity, "traits"> & {
170
244
  /** User/contact traits. */
171
245
  traits?: IdentifyTraits;
172
- /**
173
- * @deprecated Use payload-level `customerIdentity.customerId` instead.
174
- * Kept for one compatibility window while callers migrate.
175
- */
246
+ /** @deprecated Pass `customerIdentity.customerId` to the payload builder instead. */
176
247
  customerId?: string;
177
- /**
178
- * @deprecated Use payload-level `customerIdentity.customerTraits` instead.
179
- * Kept for one compatibility window while callers migrate.
180
- */
248
+ /** @deprecated Pass `customerIdentity.customerTraits` to the payload builder instead. */
181
249
  customerTraits?: CustomerTraits;
182
- }
183
- /**
184
- * Customer identity for payload-level attribution.
185
- * Used by browser SDK to attach account/workspace context to a batch.
186
- * `customerId`-only attribution is valid and remains provisional until a later
187
- * identify(email, customerId) call links that external account/workspace to a resolved customer.
188
- */
189
- interface PayloadCustomerIdentity extends CustomerAttribution {
250
+ };
251
+ interface PayloadCustomerIdentityInput extends CustomerAttribution {
190
252
  /** Customer/account traits. */
191
253
  customerTraits?: CustomerTraits;
192
254
  }
193
- interface IngestPayload {
194
- visitorId?: string;
195
- source: SourceType;
196
- events: TrackerEvent[];
197
- /**
198
- * Device identifier for anonymous tracking.
199
- * Events with fingerprint can be linked to users later via identify.
200
- * Only present for server-side events.
201
- */
202
- fingerprint?: string;
203
- /**
204
- * Session ID for grouping all events in this batch.
205
- * Only present for browser (client) source events.
206
- * Used to correlate pageviews, forms, custom events, and engagement
207
- * within the same browsing session.
208
- */
209
- sessionId?: string;
210
- /**
211
- * User identity for this batch of events.
212
- * When present, the server can resolve directly to CustomerContact
213
- * instead of relying on anonymous visitor flow.
214
- *
215
- * This is set by the browser SDK when setUser() has been called,
216
- * allowing immediate identity resolution for SPA/React apps.
217
- */
218
- userIdentity?: PayloadUserIdentity;
219
- /**
220
- * Customer/account identity for this batch of events.
221
- * Used to attribute browser batches to a customer/workspace even when
222
- * the customer fields are not present on every event.
223
- */
224
- customerIdentity?: PayloadCustomerIdentity;
255
+ interface ServerTrackOptions extends ServerIdentity, CustomerAttribution {
256
+ eventName: string;
257
+ properties?: Record<string, string | number | boolean | null>;
258
+ timestamp?: number;
225
259
  }
226
- interface IngestResponse {
227
- success: boolean;
228
- processed: number;
229
- errors?: Array<{
230
- index: number;
231
- message: string;
232
- }>;
260
+ interface ServerIdentifyOptions extends ServerIdentity, CustomerAttribution {
261
+ traits?: IdentifyTraits;
262
+ customerTraits?: CustomerTraits;
233
263
  }
234
264
  declare const DEFAULT_API_HOST = "https://app.outlit.ai";
235
265
 
@@ -297,27 +327,6 @@ declare function buildEngagementEvent(params: BaseEventParams & {
297
327
  totalTimeMs: number;
298
328
  sessionId: string;
299
329
  }): EngagementEvent;
300
- /**
301
- * Build a stage event.
302
- * Used to explicitly send customer journey stage events.
303
- * New SDK callers should only send activated; engaged and inactive are derived
304
- * by Outlit from tracked activity but remain accepted for wire compatibility.
305
- * discovered/signed_up stages are inferred from identify calls.
306
- */
307
- declare function buildStageEvent(params: BaseEventParams & {
308
- stage: ExplicitJourneyStage;
309
- properties?: Record<string, string | number | boolean | null>;
310
- }): StageEvent;
311
- /**
312
- * Build a billing event.
313
- * Used to set customer billing status (trialing, paid, churned).
314
- */
315
- declare function buildBillingEvent(params: BaseEventParams & {
316
- status: BillingStatus;
317
- customerId?: string;
318
- stripeCustomerId?: string;
319
- properties?: Record<string, string | number | boolean | null>;
320
- }): BillingEvent;
321
330
  /**
322
331
  * Build an ingest payload from events.
323
332
  *
@@ -331,16 +340,20 @@ declare function buildBillingEvent(params: BaseEventParams & {
331
340
  * batches are valid and remain provisional until a later identify(email, customerId) call
332
341
  * links that external account/workspace to a resolved customer.
333
342
  */
334
- declare function buildIngestPayload(visitorId: string, source: SourceType, events: TrackerEvent[], userIdentity?: PayloadUserIdentity, sessionId?: string, fingerprint?: string, customerIdentity?: PayloadCustomerIdentity): IngestPayload;
343
+ declare function buildIngestPayload(visitorId: string, source: SourceType, events: TrackerEvent[], userIdentity?: PayloadUserIdentityInput, sessionId?: string, fingerprint?: string, customerIdentity?: PayloadCustomerIdentityInput): IngestPayload;
335
344
  /**
336
345
  * Maximum number of events in a single batch.
337
346
  */
338
- declare const MAX_BATCH_SIZE = 100;
347
+ declare const MAX_BATCH_SIZE: 100;
339
348
  /**
340
349
  * Split events into batches of MAX_BATCH_SIZE.
341
350
  */
342
351
  declare function batchEvents(events: TrackerEvent[]): TrackerEvent[][];
343
352
 
353
+ declare const INGEST_METHOD: "POST";
354
+ declare const INGEST_EVENT_TYPES: readonly ["pageview", "form", "identify", "custom", "calendar", "engagement"];
355
+ declare function buildIngestUrl(apiHost: string, publicKey: string): string;
356
+
344
357
  /**
345
358
  * Extract UTM parameters from a URL.
346
359
  */
@@ -369,10 +382,6 @@ declare function sanitizeFormFields(fields: Record<string, string> | undefined,
369
382
  * - customerId: Your system-owned customer/account/workspace ID
370
383
  */
371
384
  declare function validateServerIdentity(fingerprint?: string, email?: string, userId?: string, customerId?: string): void;
372
- /**
373
- * Validate that at least one customer identifier is provided for billing calls.
374
- */
375
- declare function validateCustomerIdentity(customerId?: string, stripeCustomerId?: string): void;
376
385
  /**
377
386
  * Validate that a string looks like a valid email address.
378
387
  */
@@ -428,4 +437,4 @@ interface ExtractedIdentity {
428
437
  */
429
438
  declare function extractIdentityFromForm(fields: Record<string, string>, inputTypes?: Map<string, string>): ExtractedIdentity | undefined;
430
439
 
431
- 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 };
440
+ export { type BrowserIdentifyOptions, type BrowserTrackOptions, type CalendarEvent, type CalendarProvider, type CustomEvent, type CustomerAttribution, type CustomerTraits, DEFAULT_API_HOST, DEFAULT_DENIED_FORM_FIELDS, type EngagementEvent, type EventType, type ExtractedIdentity, type FormEvent, INGEST_EVENT_TYPES, INGEST_METHOD, type IdentifyEvent, type IdentifyTraits, type IngestPayload, type IngestResponse, MAX_BATCH_SIZE, type PageviewEvent, type PayloadCustomerIdentity, type PayloadCustomerIdentityInput, type PayloadUserIdentity, type PayloadUserIdentityInput, type ServerIdentifyOptions, type ServerIdentity, type ServerTrackOptions, type SourceType, type TrackerConfig, type TrackerEvent, type UtmParams, batchEvents, buildCalendarEvent, buildCustomEvent, buildEngagementEvent, buildFormEvent, buildIdentifyEvent, buildIngestPayload, buildIngestUrl, buildPageviewEvent, extractIdentityFromForm, extractPathFromUrl, extractUtmParams, findEmailField, findNameFields, isFieldDenied, isValidEmail, sanitizeFormFields, validateServerIdentity };
package/dist/index.js CHANGED
@@ -22,17 +22,18 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  DEFAULT_API_HOST: () => DEFAULT_API_HOST,
24
24
  DEFAULT_DENIED_FORM_FIELDS: () => DEFAULT_DENIED_FORM_FIELDS,
25
+ INGEST_EVENT_TYPES: () => INGEST_EVENT_TYPES,
26
+ INGEST_METHOD: () => INGEST_METHOD,
25
27
  MAX_BATCH_SIZE: () => MAX_BATCH_SIZE,
26
28
  batchEvents: () => batchEvents,
27
- buildBillingEvent: () => buildBillingEvent,
28
29
  buildCalendarEvent: () => buildCalendarEvent,
29
30
  buildCustomEvent: () => buildCustomEvent,
30
31
  buildEngagementEvent: () => buildEngagementEvent,
31
32
  buildFormEvent: () => buildFormEvent,
32
33
  buildIdentifyEvent: () => buildIdentifyEvent,
33
34
  buildIngestPayload: () => buildIngestPayload,
35
+ buildIngestUrl: () => buildIngestUrl,
34
36
  buildPageviewEvent: () => buildPageviewEvent,
35
- buildStageEvent: () => buildStageEvent,
36
37
  extractIdentityFromForm: () => extractIdentityFromForm,
37
38
  extractPathFromUrl: () => extractPathFromUrl,
38
39
  extractUtmParams: () => extractUtmParams,
@@ -41,7 +42,6 @@ __export(src_exports, {
41
42
  isFieldDenied: () => isFieldDenied,
42
43
  isValidEmail: () => isValidEmail,
43
44
  sanitizeFormFields: () => sanitizeFormFields,
44
- validateCustomerIdentity: () => validateCustomerIdentity,
45
45
  validateServerIdentity: () => validateServerIdentity
46
46
  });
47
47
  module.exports = __toCommonJS(src_exports);
@@ -49,6 +49,14 @@ module.exports = __toCommonJS(src_exports);
49
49
  // src/payload.ts
50
50
  var import_uuid = require("uuid");
51
51
 
52
+ // src/generated/ingest-contract.ts
53
+ var ingestTransport = {
54
+ method: "POST",
55
+ pathTemplate: "/api/i/v1/{publicKey}/events",
56
+ maxBatchSize: 100,
57
+ eventTypes: ["pageview", "form", "identify", "custom", "calendar", "engagement"]
58
+ };
59
+
52
60
  // src/types.ts
53
61
  var DEFAULT_API_HOST = "https://app.outlit.ai";
54
62
  var DEFAULT_DENIED_FORM_FIELDS = [
@@ -158,15 +166,6 @@ function validateServerIdentity(fingerprint, email, userId, customerId) {
158
166
  );
159
167
  }
160
168
  }
161
- function validateCustomerIdentity(customerId, stripeCustomerId) {
162
- const hasCustomerId = customerId && customerId.trim().length > 0;
163
- const hasStripeCustomerId = stripeCustomerId && stripeCustomerId.trim().length > 0;
164
- if (!hasCustomerId && !hasStripeCustomerId) {
165
- throw new Error(
166
- "Billing methods require customerId or stripeCustomerId. Use customerId for your system-owned account ID."
167
- );
168
- }
169
- }
170
169
  function isValidEmail(value) {
171
170
  if (!value || typeof value !== "string") return false;
172
171
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -276,6 +275,14 @@ function extractIdentityFromForm(fields, inputTypes) {
276
275
  }
277
276
 
278
277
  // src/payload.ts
278
+ function normalizeTraits(traits) {
279
+ if (!traits) return void 0;
280
+ const normalized = {};
281
+ for (const [key, value] of Object.entries(traits)) {
282
+ if (value !== void 0) normalized[key] = value;
283
+ }
284
+ return Object.keys(normalized).length > 0 ? normalized : void 0;
285
+ }
279
286
  function buildPageviewEvent(params) {
280
287
  const { url, referrer, timestamp, title } = params;
281
288
  return {
@@ -327,8 +334,8 @@ function buildIdentifyEvent(params) {
327
334
  userId,
328
335
  fingerprint,
329
336
  customerId,
330
- customerTraits,
331
- traits
337
+ customerTraits: normalizeTraits(customerTraits),
338
+ traits: normalizeTraits(traits)
332
339
  };
333
340
  }
334
341
  function buildCustomEvent(params) {
@@ -406,36 +413,6 @@ function buildEngagementEvent(params) {
406
413
  sessionId
407
414
  };
408
415
  }
409
- function buildStageEvent(params) {
410
- const { url, referrer, timestamp, stage, properties } = params;
411
- return {
412
- uuid: (0, import_uuid.v7)(),
413
- type: "stage",
414
- timestamp: timestamp ?? Date.now(),
415
- url,
416
- path: extractPathFromUrl(url),
417
- referrer,
418
- utm: extractUtmParams(url),
419
- stage,
420
- properties
421
- };
422
- }
423
- function buildBillingEvent(params) {
424
- const { url, referrer, timestamp, status, customerId, stripeCustomerId, properties } = params;
425
- return {
426
- uuid: (0, import_uuid.v7)(),
427
- type: "billing",
428
- timestamp: timestamp ?? Date.now(),
429
- url,
430
- path: extractPathFromUrl(url),
431
- referrer,
432
- utm: extractUtmParams(url),
433
- status,
434
- customerId,
435
- stripeCustomerId,
436
- properties
437
- };
438
- }
439
416
  function buildIngestPayload(visitorId, source, events, userIdentity, sessionId, fingerprint, customerIdentity) {
440
417
  const payload = {
441
418
  visitorId,
@@ -447,32 +424,33 @@ function buildIngestPayload(visitorId, source, events, userIdentity, sessionId,
447
424
  ...userIdentity.customerTraits && { customerTraits: userIdentity.customerTraits }
448
425
  } : void 0;
449
426
  const resolvedCustomerIdentity = customerIdentity ?? legacyCustomerIdentity;
427
+ const userTraits = normalizeTraits(userIdentity?.traits);
428
+ const customerTraits = normalizeTraits(resolvedCustomerIdentity?.customerTraits);
450
429
  if (fingerprint) {
451
430
  payload.fingerprint = fingerprint;
452
431
  }
453
432
  if (sessionId) {
454
433
  payload.sessionId = sessionId;
455
434
  }
456
- if (userIdentity && (userIdentity.email || userIdentity.userId || userIdentity.traits)) {
435
+ if (userIdentity && (userIdentity.email || userIdentity.userId || userIdentity.fingerprint || userTraits)) {
457
436
  payload.userIdentity = {
458
437
  ...userIdentity.email && { email: userIdentity.email },
459
438
  ...userIdentity.userId && { userId: userIdentity.userId },
460
- ...userIdentity.traits && { traits: userIdentity.traits }
439
+ ...userIdentity.fingerprint && { fingerprint: userIdentity.fingerprint },
440
+ ...userTraits && { traits: userTraits }
461
441
  };
462
442
  }
463
- if (resolvedCustomerIdentity && (resolvedCustomerIdentity.customerId || resolvedCustomerIdentity.customerTraits)) {
443
+ if (resolvedCustomerIdentity && (resolvedCustomerIdentity.customerId || customerTraits)) {
464
444
  payload.customerIdentity = {
465
445
  ...resolvedCustomerIdentity.customerId && {
466
446
  customerId: resolvedCustomerIdentity.customerId
467
447
  },
468
- ...resolvedCustomerIdentity.customerTraits && {
469
- customerTraits: resolvedCustomerIdentity.customerTraits
470
- }
448
+ ...customerTraits && { customerTraits }
471
449
  };
472
450
  }
473
451
  return payload;
474
452
  }
475
- var MAX_BATCH_SIZE = 100;
453
+ var MAX_BATCH_SIZE = ingestTransport.maxBatchSize;
476
454
  function batchEvents(events) {
477
455
  const batches = [];
478
456
  for (let i = 0; i < events.length; i += MAX_BATCH_SIZE) {
@@ -480,21 +458,30 @@ function batchEvents(events) {
480
458
  }
481
459
  return batches;
482
460
  }
461
+
462
+ // src/transport.ts
463
+ var INGEST_METHOD = ingestTransport.method;
464
+ var INGEST_EVENT_TYPES = ingestTransport.eventTypes;
465
+ function buildIngestUrl(apiHost, publicKey) {
466
+ const path = ingestTransport.pathTemplate.replace("{publicKey}", encodeURIComponent(publicKey));
467
+ return `${apiHost.replace(/\/$/, "")}${path}`;
468
+ }
483
469
  // Annotate the CommonJS export names for ESM import in node:
484
470
  0 && (module.exports = {
485
471
  DEFAULT_API_HOST,
486
472
  DEFAULT_DENIED_FORM_FIELDS,
473
+ INGEST_EVENT_TYPES,
474
+ INGEST_METHOD,
487
475
  MAX_BATCH_SIZE,
488
476
  batchEvents,
489
- buildBillingEvent,
490
477
  buildCalendarEvent,
491
478
  buildCustomEvent,
492
479
  buildEngagementEvent,
493
480
  buildFormEvent,
494
481
  buildIdentifyEvent,
495
482
  buildIngestPayload,
483
+ buildIngestUrl,
496
484
  buildPageviewEvent,
497
- buildStageEvent,
498
485
  extractIdentityFromForm,
499
486
  extractPathFromUrl,
500
487
  extractUtmParams,
@@ -503,7 +490,6 @@ function batchEvents(events) {
503
490
  isFieldDenied,
504
491
  isValidEmail,
505
492
  sanitizeFormFields,
506
- validateCustomerIdentity,
507
493
  validateServerIdentity
508
494
  });
509
495
  //# sourceMappingURL=index.js.map