@aranova/tracking-next 0.27.0 → 1.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/blog-server.d.mts +2 -1
- package/dist/blog-server.d.ts +2 -1
- package/dist/blog-server.js +121 -98
- package/dist/blog-server.js.map +1 -1
- package/dist/blog-server.mjs +86 -63
- package/dist/blog-server.mjs.map +1 -1
- package/dist/blog.d.mts +651 -1755
- package/dist/blog.d.ts +651 -1755
- package/dist/blog.js +121 -98
- package/dist/blog.js.map +1 -1
- package/dist/blog.mjs +86 -63
- package/dist/blog.mjs.map +1 -1
- package/dist/calendar-server.d.mts +2 -2
- package/dist/calendar-server.d.ts +2 -2
- package/dist/calendar-server.js +0 -26
- package/dist/calendar-server.js.map +1 -1
- package/dist/calendar-server.mjs +0 -26
- package/dist/calendar-server.mjs.map +1 -1
- package/dist/calendar.d.mts +3 -3
- package/dist/calendar.d.ts +3 -3
- package/dist/calendar.js +227 -126
- package/dist/calendar.js.map +1 -1
- package/dist/calendar.mjs +216 -125
- package/dist/calendar.mjs.map +1 -1
- package/dist/client.d.mts +4 -3
- package/dist/client.d.ts +4 -3
- package/dist/client.js +185 -277
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +157 -249
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +482 -484
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +471 -484
- package/dist/index.mjs.map +1 -1
- package/dist/ingest-typed-BdKmlouW.d.ts +791 -0
- package/dist/ingest-typed-Bo7WPmpU.d.mts +791 -0
- package/dist/middleware.js +0 -467
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +0 -467
- package/dist/middleware.mjs.map +1 -1
- package/dist/{phone-utils-BVzSNBf1.d.mts → phone-utils-CubQif9Z.d.mts} +18 -78
- package/dist/{phone-utils-BVzSNBf1.d.ts → phone-utils-CubQif9Z.d.ts} +18 -78
- package/dist/phone.d.mts +2 -2
- package/dist/phone.d.ts +2 -2
- package/dist/phone.js +0 -464
- package/dist/phone.js.map +1 -1
- package/dist/phone.mjs +0 -464
- package/dist/phone.mjs.map +1 -1
- package/dist/{sales-DQGzXSgL.d.mts → sales-D7KstKA-.d.mts} +89 -328
- package/dist/{sales-IGC2tq4J.d.ts → sales-DG150g3o.d.ts} +89 -328
- package/dist/sales.d.mts +2 -2
- package/dist/sales.d.ts +2 -2
- package/dist/sales.js +265 -127
- package/dist/sales.js.map +1 -1
- package/dist/sales.mjs +254 -127
- package/dist/sales.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +0 -467
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +0 -467
- package/dist/server.mjs.map +1 -1
- package/dist/transport-CDmGOiCq.d.ts +253 -0
- package/dist/transport-I_cMSFQ6.d.mts +253 -0
- package/package.json +2 -2
- package/dist/ingest-typed-BxLFlZ7N.d.mts +0 -1371
- package/dist/ingest-typed-ByQVRMvP.d.ts +0 -1371
- package/dist/transport-C-_rFSR4.d.ts +0 -721
- package/dist/transport-yUF5Wize.d.mts +0 -721
package/dist/middleware.js
CHANGED
|
@@ -26,9 +26,6 @@ module.exports = __toCommonJS(middleware_exports);
|
|
|
26
26
|
var import_server_only = require("server-only");
|
|
27
27
|
var import_server = require("next/server");
|
|
28
28
|
|
|
29
|
-
// ../tracking-core/src/phone.ts
|
|
30
|
-
var import_libphonenumber_js = require("libphonenumber-js");
|
|
31
|
-
|
|
32
29
|
// ../tracking-core/src/tracking.ts
|
|
33
30
|
var TRACKING_PARAM_KEYS = [
|
|
34
31
|
"gclid",
|
|
@@ -56,470 +53,6 @@ function getTrackingQueryValues(searchParams) {
|
|
|
56
53
|
}, {});
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
// ../tracking-core/src/resources/tracking-config-runtime.ts
|
|
60
|
-
var RETRY_MAX_MS = 5 * 6e4;
|
|
61
|
-
|
|
62
|
-
// ../tracking-core/src/session.ts
|
|
63
|
-
var SESSION_IDLE_MS = 30 * 60 * 1e3;
|
|
64
|
-
|
|
65
|
-
// ../tracking-core/src/events/page-view.ts
|
|
66
|
-
var import_zod = require("zod");
|
|
67
|
-
var pageViewMetadataSchema = import_zod.z.object({
|
|
68
|
-
page: import_zod.z.object({
|
|
69
|
-
title: import_zod.z.string().nullable(),
|
|
70
|
-
path: import_zod.z.string(),
|
|
71
|
-
search: import_zod.z.string(),
|
|
72
|
-
hash: import_zod.z.string()
|
|
73
|
-
}).strict(),
|
|
74
|
-
referrer: import_zod.z.string().nullable(),
|
|
75
|
-
// `.nullable().optional()` — absent (undefined) OR explicit null OR a
|
|
76
|
-
// real viewport object. Mirrors Pydantic's `_Viewport | None = None`
|
|
77
|
-
// on the backend side so the drift test stays clean.
|
|
78
|
-
viewport: import_zod.z.object({
|
|
79
|
-
w: import_zod.z.number(),
|
|
80
|
-
h: import_zod.z.number()
|
|
81
|
-
}).strict().nullable().optional()
|
|
82
|
-
}).strict();
|
|
83
|
-
var pageViewConfigSchema = import_zod.z.object({}).strict();
|
|
84
|
-
|
|
85
|
-
// ../tracking-core/src/events/cta-click.ts
|
|
86
|
-
var import_zod2 = require("zod");
|
|
87
|
-
var ctaClickMetadataSchema = import_zod2.z.object({
|
|
88
|
-
cta_name: import_zod2.z.string(),
|
|
89
|
-
page: import_zod2.z.object({
|
|
90
|
-
path: import_zod2.z.string()
|
|
91
|
-
}).strict(),
|
|
92
|
-
section: import_zod2.z.string().nullable().optional(),
|
|
93
|
-
destination_url: import_zod2.z.string().nullable().optional(),
|
|
94
|
-
// Set by auto-capture (and available to manual callers): the link target
|
|
95
|
-
// and a short element descriptor (tag#id) for tying clicks to specific UI.
|
|
96
|
-
href: import_zod2.z.string().nullable().optional(),
|
|
97
|
-
element: import_zod2.z.string().nullable().optional()
|
|
98
|
-
}).strict();
|
|
99
|
-
var ctaClickConfigSchema = import_zod2.z.object({
|
|
100
|
-
autoCapture: import_zod2.z.object({
|
|
101
|
-
selector: import_zod2.z.string().optional()
|
|
102
|
-
}).strict().optional()
|
|
103
|
-
}).strict();
|
|
104
|
-
|
|
105
|
-
// ../tracking-core/src/events/sdk-heartbeat.ts
|
|
106
|
-
var import_zod3 = require("zod");
|
|
107
|
-
var sdkHeartbeatTriggersSchema = import_zod3.z.object({
|
|
108
|
-
automatic: import_zod3.z.array(import_zod3.z.string()),
|
|
109
|
-
manual: import_zod3.z.array(import_zod3.z.string())
|
|
110
|
-
}).strict();
|
|
111
|
-
var sdkHeartbeatMetadataSchema = import_zod3.z.object({
|
|
112
|
-
sdk_version: import_zod3.z.string(),
|
|
113
|
-
package_name: import_zod3.z.string().nullable(),
|
|
114
|
-
surface: import_zod3.z.enum(["next", "react", "script"]),
|
|
115
|
-
triggers: sdkHeartbeatTriggersSchema,
|
|
116
|
-
trigger_config: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown())).nullable().optional(),
|
|
117
|
-
configured_gtag_ids: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).nullable().optional(),
|
|
118
|
-
// Site whose config object the SDK resolves; null on a legacy business ref.
|
|
119
|
-
config_site_id: import_zod3.z.string().uuid().nullable().optional()
|
|
120
|
-
}).strict();
|
|
121
|
-
var sdkHeartbeatConfigSchema = import_zod3.z.object({}).strict();
|
|
122
|
-
|
|
123
|
-
// ../tracking-core/src/events/form-start.ts
|
|
124
|
-
var import_zod4 = require("zod");
|
|
125
|
-
var formStartMetadataSchema = import_zod4.z.object({
|
|
126
|
-
form: import_zod4.z.object({
|
|
127
|
-
id: import_zod4.z.string(),
|
|
128
|
-
action: import_zod4.z.string().nullable()
|
|
129
|
-
}).strict(),
|
|
130
|
-
page: import_zod4.z.object({
|
|
131
|
-
path: import_zod4.z.string()
|
|
132
|
-
}).strict()
|
|
133
|
-
}).strict();
|
|
134
|
-
var formStartConfigSchema = import_zod4.z.object({
|
|
135
|
-
selector: import_zod4.z.string().optional()
|
|
136
|
-
}).strict();
|
|
137
|
-
|
|
138
|
-
// ../tracking-core/src/events/form-submit.ts
|
|
139
|
-
var import_zod5 = require("zod");
|
|
140
|
-
var jsonValueSchema = import_zod5.z.lazy(
|
|
141
|
-
() => import_zod5.z.union([
|
|
142
|
-
import_zod5.z.string(),
|
|
143
|
-
import_zod5.z.number().finite(),
|
|
144
|
-
import_zod5.z.boolean(),
|
|
145
|
-
import_zod5.z.null(),
|
|
146
|
-
import_zod5.z.array(jsonValueSchema),
|
|
147
|
-
import_zod5.z.record(jsonValueSchema)
|
|
148
|
-
])
|
|
149
|
-
);
|
|
150
|
-
var formSubmitMetadataSchema = import_zod5.z.object({
|
|
151
|
-
form: import_zod5.z.object({
|
|
152
|
-
id: import_zod5.z.string(),
|
|
153
|
-
action: import_zod5.z.string().nullable(),
|
|
154
|
-
fields: import_zod5.z.array(
|
|
155
|
-
import_zod5.z.object({
|
|
156
|
-
name: import_zod5.z.string(),
|
|
157
|
-
type: import_zod5.z.string(),
|
|
158
|
-
label: import_zod5.z.string().nullable(),
|
|
159
|
-
value: jsonValueSchema
|
|
160
|
-
}).strict()
|
|
161
|
-
).optional()
|
|
162
|
-
}).strict(),
|
|
163
|
-
page: import_zod5.z.object({
|
|
164
|
-
path: import_zod5.z.string()
|
|
165
|
-
}).strict()
|
|
166
|
-
}).strict();
|
|
167
|
-
var formSubmitConfigSchema = import_zod5.z.object({}).strict();
|
|
168
|
-
|
|
169
|
-
// ../tracking-core/src/events/multi-page-session.ts
|
|
170
|
-
var import_zod6 = require("zod");
|
|
171
|
-
var multiPageSessionMetadataSchema = import_zod6.z.object({
|
|
172
|
-
page_count: import_zod6.z.number().int().min(2),
|
|
173
|
-
page: import_zod6.z.object({
|
|
174
|
-
path: import_zod6.z.string()
|
|
175
|
-
}).strict()
|
|
176
|
-
}).strict();
|
|
177
|
-
var multiPageSessionConfigSchema = import_zod6.z.object({
|
|
178
|
-
pageThreshold: import_zod6.z.number().int().min(2)
|
|
179
|
-
}).strict();
|
|
180
|
-
|
|
181
|
-
// ../tracking-core/src/events/page-exit.ts
|
|
182
|
-
var import_zod7 = require("zod");
|
|
183
|
-
var pageExitMetadataSchema = import_zod7.z.object({
|
|
184
|
-
dwell_ms: import_zod7.z.number().int().min(0),
|
|
185
|
-
// null = left without any scroll signal; floor is 0 so a valid 0% is never
|
|
186
|
-
// rejected (a single bad field 422s the whole keepalive beacon batch).
|
|
187
|
-
max_scroll_percent: import_zod7.z.number().int().min(0).max(100).nullable(),
|
|
188
|
-
// The gating baseline: the fraction of the page visible at load with
|
|
189
|
-
// zero scrolling — or, for pages that grew after the post-paint snapshot
|
|
190
|
-
// (skeleton/streaming renders), the first-scroll position that
|
|
191
|
-
// established it. null = page had no scrollable range, or the segment
|
|
192
|
-
// ended before the snapshot. `.optional()` is load-bearing: SDK builds
|
|
193
|
-
// predating this field keep POSTing page_exit without the key —
|
|
194
|
-
// requiring it would 422 whole keepalive beacon batches.
|
|
195
|
-
scroll_baseline_percent: import_zod7.z.number().int().min(0).max(100).nullable().optional(),
|
|
196
|
-
page: import_zod7.z.object({
|
|
197
|
-
path: import_zod7.z.string()
|
|
198
|
-
}).strict()
|
|
199
|
-
}).strict();
|
|
200
|
-
var pageExitConfigSchema = import_zod7.z.object({}).strict();
|
|
201
|
-
|
|
202
|
-
// ../tracking-core/src/events/phone-click.ts
|
|
203
|
-
var import_zod8 = require("zod");
|
|
204
|
-
var phoneClickMetadataSchema = import_zod8.z.object({
|
|
205
|
-
phone_number: import_zod8.z.string(),
|
|
206
|
-
page: import_zod8.z.object({
|
|
207
|
-
path: import_zod8.z.string()
|
|
208
|
-
}).strict(),
|
|
209
|
-
section: import_zod8.z.string().nullable().optional()
|
|
210
|
-
}).strict();
|
|
211
|
-
var phoneClickConfigSchema = import_zod8.z.object({
|
|
212
|
-
autoCapture: import_zod8.z.object({
|
|
213
|
-
selector: import_zod8.z.string().optional()
|
|
214
|
-
}).strict().optional()
|
|
215
|
-
}).strict();
|
|
216
|
-
|
|
217
|
-
// ../tracking-core/src/events/scroll-depth.ts
|
|
218
|
-
var import_zod9 = require("zod");
|
|
219
|
-
var scrollDepthMetadataSchema = import_zod9.z.object({
|
|
220
|
-
depth_percent: import_zod9.z.number().int().min(1).max(100),
|
|
221
|
-
page: import_zod9.z.object({
|
|
222
|
-
path: import_zod9.z.string()
|
|
223
|
-
}).strict()
|
|
224
|
-
}).strict();
|
|
225
|
-
var scrollDepthConfigSchema = import_zod9.z.object({
|
|
226
|
-
thresholds: import_zod9.z.array(import_zod9.z.number().int().min(1).max(100)).min(1)
|
|
227
|
-
}).strict();
|
|
228
|
-
|
|
229
|
-
// ../tracking-core/src/events/specific-page-visit.ts
|
|
230
|
-
var import_zod10 = require("zod");
|
|
231
|
-
var PAGE_IDENTITY_MAX_LENGTH = 64;
|
|
232
|
-
var PAGE_IDENTITY_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
233
|
-
var pageIdentitySchema = import_zod10.z.string().max(PAGE_IDENTITY_MAX_LENGTH).regex(PAGE_IDENTITY_PATTERN, {
|
|
234
|
-
message: "page identity must be lowercase snake_case, start with a letter, and contain at most 64 characters"
|
|
235
|
-
});
|
|
236
|
-
var specificPageNameSchema = pageIdentitySchema;
|
|
237
|
-
var specificPageVisitMetadataSchema = import_zod10.z.object({
|
|
238
|
-
page_name: specificPageNameSchema,
|
|
239
|
-
page: import_zod10.z.object({
|
|
240
|
-
path: import_zod10.z.string()
|
|
241
|
-
}).strict()
|
|
242
|
-
}).strict();
|
|
243
|
-
var specificPageVisitConfigSchema = import_zod10.z.object({
|
|
244
|
-
pages: import_zod10.z.array(
|
|
245
|
-
import_zod10.z.object({
|
|
246
|
-
name: specificPageNameSchema,
|
|
247
|
-
pathPattern: import_zod10.z.custom((value) => value instanceof RegExp, {
|
|
248
|
-
message: "pathPattern must be a RegExp"
|
|
249
|
-
})
|
|
250
|
-
}).strict()
|
|
251
|
-
).min(1)
|
|
252
|
-
}).strict();
|
|
253
|
-
|
|
254
|
-
// ../tracking-core/src/events/time-on-site.ts
|
|
255
|
-
var import_zod11 = require("zod");
|
|
256
|
-
var timeOnSiteMetadataSchema = import_zod11.z.object({
|
|
257
|
-
duration_ms: import_zod11.z.number().int().nonnegative(),
|
|
258
|
-
page: import_zod11.z.object({
|
|
259
|
-
path: import_zod11.z.string()
|
|
260
|
-
}).strict()
|
|
261
|
-
}).strict();
|
|
262
|
-
var timeOnSiteConfigSchema = import_zod11.z.object({
|
|
263
|
-
thresholdSeconds: import_zod11.z.number().int().positive()
|
|
264
|
-
}).strict();
|
|
265
|
-
|
|
266
|
-
// ../tracking-core/src/events/semantics.ts
|
|
267
|
-
var EVENT_SEMANTICS = {
|
|
268
|
-
page_view: {
|
|
269
|
-
label: "Page view",
|
|
270
|
-
category: "page",
|
|
271
|
-
outcomeRole: "navigation",
|
|
272
|
-
clientVisibility: "simple"
|
|
273
|
-
},
|
|
274
|
-
time_on_site: {
|
|
275
|
-
label: "Time on site",
|
|
276
|
-
category: "engagement",
|
|
277
|
-
outcomeRole: "engagement",
|
|
278
|
-
clientVisibility: "detailed"
|
|
279
|
-
},
|
|
280
|
-
specific_page_visit: {
|
|
281
|
-
label: "Key page visit",
|
|
282
|
-
category: "engagement",
|
|
283
|
-
outcomeRole: "engagement",
|
|
284
|
-
clientVisibility: "detailed"
|
|
285
|
-
},
|
|
286
|
-
scroll_depth: {
|
|
287
|
-
label: "Scroll depth",
|
|
288
|
-
category: "engagement",
|
|
289
|
-
outcomeRole: "engagement",
|
|
290
|
-
clientVisibility: "detailed"
|
|
291
|
-
},
|
|
292
|
-
multi_page_session: {
|
|
293
|
-
label: "Multi-page session",
|
|
294
|
-
category: "engagement",
|
|
295
|
-
outcomeRole: "engagement",
|
|
296
|
-
clientVisibility: "detailed"
|
|
297
|
-
},
|
|
298
|
-
form_start: {
|
|
299
|
-
label: "Form started",
|
|
300
|
-
category: "engagement",
|
|
301
|
-
outcomeRole: "engagement",
|
|
302
|
-
clientVisibility: "simple"
|
|
303
|
-
},
|
|
304
|
-
sdk_heartbeat: {
|
|
305
|
-
label: "SDK heartbeat",
|
|
306
|
-
category: "system",
|
|
307
|
-
outcomeRole: "diagnostic",
|
|
308
|
-
clientVisibility: "hidden"
|
|
309
|
-
},
|
|
310
|
-
page_exit: {
|
|
311
|
-
label: "Page exit",
|
|
312
|
-
category: "engagement",
|
|
313
|
-
outcomeRole: "diagnostic",
|
|
314
|
-
clientVisibility: "detailed"
|
|
315
|
-
},
|
|
316
|
-
form_submit: {
|
|
317
|
-
label: "Form submitted",
|
|
318
|
-
category: "lead",
|
|
319
|
-
outcomeRole: "lead",
|
|
320
|
-
clientVisibility: "simple"
|
|
321
|
-
},
|
|
322
|
-
phone_click: {
|
|
323
|
-
label: "Phone click",
|
|
324
|
-
category: "lead",
|
|
325
|
-
outcomeRole: "lead",
|
|
326
|
-
clientVisibility: "simple"
|
|
327
|
-
},
|
|
328
|
-
cta_click: {
|
|
329
|
-
label: "CTA click",
|
|
330
|
-
category: "engagement",
|
|
331
|
-
outcomeRole: "engagement",
|
|
332
|
-
clientVisibility: "simple"
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
// ../tracking-core/src/events/registry.ts
|
|
337
|
-
var EVENT_REGISTRY = {
|
|
338
|
-
// --- automatic triggers ---
|
|
339
|
-
page_view: {
|
|
340
|
-
kind: "automatic",
|
|
341
|
-
semantics: EVENT_SEMANTICS.page_view,
|
|
342
|
-
metadataSchema: pageViewMetadataSchema,
|
|
343
|
-
configSchema: pageViewConfigSchema
|
|
344
|
-
},
|
|
345
|
-
time_on_site: {
|
|
346
|
-
kind: "automatic",
|
|
347
|
-
semantics: EVENT_SEMANTICS.time_on_site,
|
|
348
|
-
metadataSchema: timeOnSiteMetadataSchema,
|
|
349
|
-
configSchema: timeOnSiteConfigSchema
|
|
350
|
-
},
|
|
351
|
-
specific_page_visit: {
|
|
352
|
-
kind: "automatic",
|
|
353
|
-
semantics: EVENT_SEMANTICS.specific_page_visit,
|
|
354
|
-
metadataSchema: specificPageVisitMetadataSchema,
|
|
355
|
-
configSchema: specificPageVisitConfigSchema
|
|
356
|
-
},
|
|
357
|
-
scroll_depth: {
|
|
358
|
-
kind: "automatic",
|
|
359
|
-
semantics: EVENT_SEMANTICS.scroll_depth,
|
|
360
|
-
metadataSchema: scrollDepthMetadataSchema,
|
|
361
|
-
configSchema: scrollDepthConfigSchema
|
|
362
|
-
},
|
|
363
|
-
multi_page_session: {
|
|
364
|
-
kind: "automatic",
|
|
365
|
-
semantics: EVENT_SEMANTICS.multi_page_session,
|
|
366
|
-
metadataSchema: multiPageSessionMetadataSchema,
|
|
367
|
-
configSchema: multiPageSessionConfigSchema
|
|
368
|
-
},
|
|
369
|
-
form_start: {
|
|
370
|
-
kind: "automatic",
|
|
371
|
-
semantics: EVENT_SEMANTICS.form_start,
|
|
372
|
-
metadataSchema: formStartMetadataSchema,
|
|
373
|
-
configSchema: formStartConfigSchema
|
|
374
|
-
},
|
|
375
|
-
// --- SDK-internal automatic (not consumer-configurable) ---
|
|
376
|
-
sdk_heartbeat: {
|
|
377
|
-
kind: "automatic",
|
|
378
|
-
semantics: EVENT_SEMANTICS.sdk_heartbeat,
|
|
379
|
-
metadataSchema: sdkHeartbeatMetadataSchema,
|
|
380
|
-
configSchema: sdkHeartbeatConfigSchema
|
|
381
|
-
},
|
|
382
|
-
page_exit: {
|
|
383
|
-
kind: "automatic",
|
|
384
|
-
semantics: EVENT_SEMANTICS.page_exit,
|
|
385
|
-
metadataSchema: pageExitMetadataSchema,
|
|
386
|
-
configSchema: pageExitConfigSchema
|
|
387
|
-
},
|
|
388
|
-
// --- manual triggers ---
|
|
389
|
-
form_submit: {
|
|
390
|
-
kind: "manual",
|
|
391
|
-
semantics: EVENT_SEMANTICS.form_submit,
|
|
392
|
-
metadataSchema: formSubmitMetadataSchema,
|
|
393
|
-
configSchema: formSubmitConfigSchema
|
|
394
|
-
},
|
|
395
|
-
phone_click: {
|
|
396
|
-
kind: "manual",
|
|
397
|
-
semantics: EVENT_SEMANTICS.phone_click,
|
|
398
|
-
metadataSchema: phoneClickMetadataSchema,
|
|
399
|
-
configSchema: phoneClickConfigSchema
|
|
400
|
-
},
|
|
401
|
-
cta_click: {
|
|
402
|
-
kind: "manual",
|
|
403
|
-
semantics: EVENT_SEMANTICS.cta_click,
|
|
404
|
-
metadataSchema: ctaClickMetadataSchema,
|
|
405
|
-
configSchema: ctaClickConfigSchema
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
var ALL_AUTOMATIC_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "automatic").map(([name]) => name);
|
|
409
|
-
var ALL_MANUAL_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.kind === "manual").map(([name]) => name);
|
|
410
|
-
var ALL_LEAD_EVENT_NAMES = Object.entries(EVENT_REGISTRY).filter(([, def]) => def.semantics.outcomeRole === "lead").map(([name]) => name);
|
|
411
|
-
|
|
412
|
-
// ../tracking-core/src/resources/sales/schema.ts
|
|
413
|
-
var import_zod12 = require("zod");
|
|
414
|
-
var SUPPORTED_CURRENCIES = ["USD", "CAD"];
|
|
415
|
-
var TRACKING_ENVIRONMENTS = ["production", "development"];
|
|
416
|
-
var currencySchema = import_zod12.z.enum(SUPPORTED_CURRENCIES);
|
|
417
|
-
var centsSchema = import_zod12.z.number().int().nonnegative();
|
|
418
|
-
var quantitySchema = import_zod12.z.string().regex(/^\d+(\.\d{1,3})?$/);
|
|
419
|
-
var metadataSchema = import_zod12.z.record(import_zod12.z.unknown());
|
|
420
|
-
var saleItemSchema = import_zod12.z.object({
|
|
421
|
-
external_item_id: import_zod12.z.string().nullable().optional(),
|
|
422
|
-
name: import_zod12.z.string().nullable().optional(),
|
|
423
|
-
category: import_zod12.z.string().nullable().optional(),
|
|
424
|
-
quantity: quantitySchema,
|
|
425
|
-
unit_price_cents: centsSchema,
|
|
426
|
-
// Non-negativity validated on the wire — same contract as the other cents
|
|
427
|
-
// fields — and backstopped by the DB CHECK.
|
|
428
|
-
unit_cost_cents: centsSchema.nullable().optional()
|
|
429
|
-
}).strict();
|
|
430
|
-
var saleServiceSchema = import_zod12.z.object({
|
|
431
|
-
service: import_zod12.z.string(),
|
|
432
|
-
amount_cents: centsSchema
|
|
433
|
-
}).strict();
|
|
434
|
-
var customerNameSchema = import_zod12.z.string().max(200);
|
|
435
|
-
var customerPhoneSchema = import_zod12.z.string().max(64);
|
|
436
|
-
var customerEmailSchema = import_zod12.z.string().max(320).email();
|
|
437
|
-
function refineServiceXor(val, ctx, { requireAmount }) {
|
|
438
|
-
if (val.services != null) {
|
|
439
|
-
if (val.service != null) {
|
|
440
|
-
ctx.addIssue({
|
|
441
|
-
code: import_zod12.z.ZodIssueCode.custom,
|
|
442
|
-
message: "pass either `service` or `services`, not both",
|
|
443
|
-
path: ["services"]
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
if (val.services.length === 0) {
|
|
447
|
-
ctx.addIssue({
|
|
448
|
-
code: import_zod12.z.ZodIssueCode.custom,
|
|
449
|
-
message: "`services` must not be empty",
|
|
450
|
-
path: ["services"]
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
const keys = val.services.map((s) => s.service);
|
|
454
|
-
if (new Set(keys).size !== keys.length) {
|
|
455
|
-
ctx.addIssue({
|
|
456
|
-
code: import_zod12.z.ZodIssueCode.custom,
|
|
457
|
-
message: "`services` must not list the same service more than once",
|
|
458
|
-
path: ["services"]
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
if (val.amount_total_cents != null) {
|
|
462
|
-
const sum = val.services.reduce((acc, s) => acc + s.amount_cents, 0);
|
|
463
|
-
if (val.amount_total_cents !== sum) {
|
|
464
|
-
ctx.addIssue({
|
|
465
|
-
code: import_zod12.z.ZodIssueCode.custom,
|
|
466
|
-
message: "amount_total_cents must equal the sum of the services amounts (omit it to derive it automatically)",
|
|
467
|
-
path: ["amount_total_cents"]
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
} else if (requireAmount && val.amount_total_cents == null) {
|
|
472
|
-
ctx.addIssue({
|
|
473
|
-
code: import_zod12.z.ZodIssueCode.custom,
|
|
474
|
-
message: "amount_total_cents is required unless `services` is provided",
|
|
475
|
-
path: ["amount_total_cents"]
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
var saleCreateSchema = import_zod12.z.object({
|
|
480
|
-
external_id: import_zod12.z.string().nullable().optional(),
|
|
481
|
-
description: import_zod12.z.string().nullable().optional(),
|
|
482
|
-
service: import_zod12.z.string().nullable().optional(),
|
|
483
|
-
services: import_zod12.z.array(saleServiceSchema).nullable().optional(),
|
|
484
|
-
currency: currencySchema,
|
|
485
|
-
// Optional only because the plural `services` form derives it from the sum
|
|
486
|
-
// (see refineServiceXor); the singular/serviceless path still requires it.
|
|
487
|
-
amount_total_cents: centsSchema.nullable().optional(),
|
|
488
|
-
occurred_at: import_zod12.z.string().datetime(),
|
|
489
|
-
environment: import_zod12.z.enum(TRACKING_ENVIRONMENTS).default("production"),
|
|
490
|
-
items: import_zod12.z.array(saleItemSchema).default([]),
|
|
491
|
-
metadata: metadataSchema.nullable().optional(),
|
|
492
|
-
customer_name: customerNameSchema.nullable().optional(),
|
|
493
|
-
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
494
|
-
customer_email: customerEmailSchema.nullable().optional(),
|
|
495
|
-
// CASL consent attestation: the customer agreed to receive SMS. Recorded
|
|
496
|
-
// with a timestamp server-side; every SMS send path gates on it.
|
|
497
|
-
//
|
|
498
|
-
// Tri-state: omit it (or send null) to let the server apply the business's
|
|
499
|
-
// configured default-opt-in policy, honouring a returning customer's
|
|
500
|
-
// remembered preference. Send an explicit boolean to assert consent state
|
|
501
|
-
// yourself — `false` records a deliberate opt-out.
|
|
502
|
-
sms_consent: import_zod12.z.boolean().nullable().optional()
|
|
503
|
-
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: true }));
|
|
504
|
-
var saleUpdateSchema = import_zod12.z.object({
|
|
505
|
-
description: import_zod12.z.string().nullable().optional(),
|
|
506
|
-
service: import_zod12.z.string().nullable().optional(),
|
|
507
|
-
services: import_zod12.z.array(saleServiceSchema).nullable().optional(),
|
|
508
|
-
currency: currencySchema.optional(),
|
|
509
|
-
amount_total_cents: centsSchema.optional(),
|
|
510
|
-
occurred_at: import_zod12.z.string().datetime().optional(),
|
|
511
|
-
items: import_zod12.z.array(saleItemSchema).optional(),
|
|
512
|
-
metadata: metadataSchema.nullable().optional(),
|
|
513
|
-
customer_name: customerNameSchema.nullable().optional(),
|
|
514
|
-
// Re-attest when changing a filler-looking name; the server clears the
|
|
515
|
-
// prior attestation whenever `customer_name` changes.
|
|
516
|
-
customer_name_placeholder_confirmed: import_zod12.z.boolean().optional(),
|
|
517
|
-
customer_phone: customerPhoneSchema.nullable().optional(),
|
|
518
|
-
customer_email: customerEmailSchema.nullable().optional(),
|
|
519
|
-
// NOT NULL server-side: omit to leave unchanged (explicit null is rejected).
|
|
520
|
-
sms_consent: import_zod12.z.boolean().optional()
|
|
521
|
-
}).strict().superRefine((val, ctx) => refineServiceXor(val, ctx, { requireAmount: false }));
|
|
522
|
-
|
|
523
56
|
// src/middleware.ts
|
|
524
57
|
function createTrackingMiddleware() {
|
|
525
58
|
return (request) => {
|