@proveanything/smartlinks 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/ai.js CHANGED
@@ -1,19 +1,6 @@
1
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
2
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
3
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
5
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
6
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
7
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
8
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
9
- function fulfill(value) { resume("next", value); }
10
- function reject(value) { resume("throw", value); }
11
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
12
- };
13
1
  // src/api/ai.ts
14
2
  // AI endpoints: public and admin helpers
15
- import { post, request, del, getBaseURL, getApiHeaders } from "../http";
16
- import { SmartlinksApiError } from "../types/error";
3
+ import { post, request, del, requestStream } from "../http";
17
4
  function encodeQueryParams(params) {
18
5
  if (!params)
19
6
  return '';
@@ -25,89 +12,6 @@ function encodeQueryParams(params) {
25
12
  const search = query.toString();
26
13
  return search ? `?${search}` : '';
27
14
  }
28
- async function createSseStream(path, body) {
29
- var _a, _b, _c;
30
- const baseURL = getBaseURL();
31
- if (!baseURL) {
32
- throw new Error('HTTP client is not initialized. Call initializeApi(...) first.');
33
- }
34
- const url = `${baseURL}${path}`;
35
- const headers = Object.assign({ Accept: 'text/event-stream', 'Content-Type': 'application/json' }, getApiHeaders());
36
- const response = await fetch(url, {
37
- method: 'POST',
38
- headers,
39
- body: JSON.stringify(body),
40
- });
41
- if (!response.ok) {
42
- let responseBody;
43
- try {
44
- responseBody = await response.json();
45
- }
46
- catch (_d) {
47
- responseBody = null;
48
- }
49
- const code = response.status;
50
- const message = (responseBody === null || responseBody === void 0 ? void 0 : responseBody.message) || ((_a = responseBody === null || responseBody === void 0 ? void 0 : responseBody.error) === null || _a === void 0 ? void 0 : _a.message) || `Request failed with status ${code}`;
51
- throw new SmartlinksApiError(`Error ${code}: ${message}`, code, {
52
- code,
53
- errorCode: ((_b = responseBody === null || responseBody === void 0 ? void 0 : responseBody.error) === null || _b === void 0 ? void 0 : _b.code) || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.errorCode),
54
- message,
55
- details: ((_c = responseBody === null || responseBody === void 0 ? void 0 : responseBody.error) === null || _c === void 0 ? void 0 : _c.details) || (responseBody === null || responseBody === void 0 ? void 0 : responseBody.details),
56
- }, url);
57
- }
58
- if (!response.body) {
59
- throw new Error('Streaming response body is unavailable in this environment');
60
- }
61
- return parseSseStream(response.body);
62
- }
63
- function parseSseStream(stream) {
64
- return __asyncGenerator(this, arguments, function* parseSseStream_1() {
65
- const reader = stream.getReader();
66
- const decoder = new TextDecoder();
67
- let buffer = '';
68
- let dataLines = [];
69
- while (true) {
70
- const { done, value } = yield __await(reader.read());
71
- if (done)
72
- break;
73
- buffer += decoder.decode(value, { stream: true });
74
- const lines = buffer.split(/\r?\n/);
75
- buffer = lines.pop() || '';
76
- for (const rawLine of lines) {
77
- const line = rawLine.trimEnd();
78
- if (!line) {
79
- if (!dataLines.length)
80
- continue;
81
- const payload = dataLines.join('\n');
82
- dataLines = [];
83
- if (payload === '[DONE]')
84
- return yield __await(void 0);
85
- try {
86
- yield yield __await(JSON.parse(payload));
87
- }
88
- catch (_a) {
89
- continue;
90
- }
91
- continue;
92
- }
93
- if (line.startsWith('data:')) {
94
- dataLines.push(line.slice(5).trimStart());
95
- }
96
- }
97
- }
98
- if (dataLines.length) {
99
- const payload = dataLines.join('\n');
100
- if (payload !== '[DONE]') {
101
- try {
102
- yield yield __await(JSON.parse(payload));
103
- }
104
- catch (_b) {
105
- return yield __await(void 0);
106
- }
107
- }
108
- }
109
- });
110
- }
111
15
  var aiInternal;
112
16
  (function (aiInternal) {
113
17
  // ============================================================================
@@ -126,7 +30,7 @@ var aiInternal;
126
30
  async function create(collectionId, request) {
127
31
  const path = `/admin/collection/${encodeURIComponent(collectionId)}/ai/v1/responses`;
128
32
  if (request.stream) {
129
- return createSseStream(path, request);
33
+ return requestStream(path, { method: 'POST', body: request });
130
34
  }
131
35
  return post(path, request);
132
36
  }
@@ -143,7 +47,7 @@ var aiInternal;
143
47
  async function create(collectionId, request) {
144
48
  const path = `/admin/collection/${encodeURIComponent(collectionId)}/ai/v1/chat/completions`;
145
49
  if (request.stream) {
146
- return createSseStream(path, request);
50
+ return requestStream(path, { method: 'POST', body: request });
147
51
  }
148
52
  return post(path, request);
149
53
  }
@@ -1,5 +1,5 @@
1
- import type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest } from "../types/analytics";
2
- export type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest, };
1
+ import type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, AnalyticsSessionId, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest } from "../types/analytics";
2
+ export type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, AnalyticsSessionId, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest, };
3
3
  export declare namespace analytics {
4
4
  namespace collection {
5
5
  /**
@@ -17,7 +17,7 @@ export declare namespace analytics {
17
17
  }
18
18
  namespace browser {
19
19
  function configure(config: AnalyticsBrowserConfig): void;
20
- function getSessionId(): string | undefined;
20
+ function getSessionId(): AnalyticsSessionId | undefined;
21
21
  function getVisitorId(): string | undefined;
22
22
  function setVisitorId(visitorId: string, options?: AnalyticsVisitorIdOptions): string;
23
23
  function clearVisitorId(options?: Pick<AnalyticsVisitorIdOptions, 'storage' | 'storageKey'>): void;
@@ -39,8 +39,15 @@ const defaultCampaignParamMap = {
39
39
  qrCodeId: 'qrCodeId',
40
40
  scanMethod: ['scanMethod', 'scan_method'],
41
41
  };
42
+ const promotedAnalyticsKeys = new Set([
43
+ 'visitorId',
44
+ 'referrerHost',
45
+ 'pageId',
46
+ 'entryType',
47
+ 'scanMethod',
48
+ ]);
42
49
  function createSessionId() {
43
- return `${Date.now()}_${Math.floor(Math.random() * 1000000)}`;
50
+ return Date.now() * 1000 + Math.floor(Math.random() * 1000);
44
51
  }
45
52
  function createVisitorId() {
46
53
  return `visitor_${Date.now()}_${Math.floor(Math.random() * 1000000)}`;
@@ -56,6 +63,33 @@ function getStorage(mode) {
56
63
  }
57
64
  return undefined;
58
65
  }
66
+ function parseStoredSessionId(value) {
67
+ if (/^\d+$/.test(value)) {
68
+ const parsed = Number(value);
69
+ if (Number.isSafeInteger(parsed))
70
+ return parsed;
71
+ }
72
+ return undefined;
73
+ }
74
+ function assertValidSessionId(sessionId) {
75
+ if (sessionId === undefined || sessionId === null)
76
+ return undefined;
77
+ if (typeof sessionId !== 'number' || !Number.isSafeInteger(sessionId)) {
78
+ throw new Error('analytics sessionId must be a safe integer number.');
79
+ }
80
+ return sessionId;
81
+ }
82
+ function prunePromotedMetadataKeys(metadata) {
83
+ if (!metadata)
84
+ return undefined;
85
+ const entries = Object.entries(metadata).filter(([key]) => !promotedAnalyticsKeys.has(key));
86
+ if (entries.length === 0)
87
+ return undefined;
88
+ return Object.fromEntries(entries);
89
+ }
90
+ function normalizeAnalyticsEvent(event) {
91
+ return Object.assign(Object.assign({}, event), { sessionId: assertValidSessionId(event.sessionId), metadata: prunePromotedMetadataKeys(event.metadata) });
92
+ }
59
93
  function getOrCreateSessionId() {
60
94
  var _a, _b, _c, _d;
61
95
  if (analyticsBrowserState.sessionId)
@@ -64,14 +98,17 @@ function getOrCreateSessionId() {
64
98
  const storage = getStorage('session');
65
99
  const existing = key ? storage === null || storage === void 0 ? void 0 : storage.getItem(key) : undefined;
66
100
  if (existing) {
67
- analyticsBrowserState.sessionId = existing;
68
- return existing;
101
+ const parsed = parseStoredSessionId(existing);
102
+ if (parsed !== undefined) {
103
+ analyticsBrowserState.sessionId = parsed;
104
+ return parsed;
105
+ }
69
106
  }
70
- const generated = (_d = (_c = (_b = analyticsBrowserState.config).sessionIdFactory) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : createSessionId();
107
+ const generated = assertValidSessionId((_d = (_c = (_b = analyticsBrowserState.config).sessionIdFactory) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : createSessionId());
71
108
  analyticsBrowserState.sessionId = generated;
72
109
  if (key) {
73
110
  try {
74
- storage === null || storage === void 0 ? void 0 : storage.setItem(key, generated);
111
+ storage === null || storage === void 0 ? void 0 : storage.setItem(key, String(generated));
75
112
  }
76
113
  catch (_e) {
77
114
  }
@@ -201,21 +238,21 @@ function getResolvedLocation() {
201
238
  return undefined;
202
239
  }
203
240
  function mergeCollectionEventDefaults(event) {
204
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
241
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
205
242
  const configuredDefaults = (_a = analyticsBrowserState.config.defaultCollectionEvent) !== null && _a !== void 0 ? _a : {};
206
243
  const dynamicDefaults = (_d = (_c = (_b = analyticsBrowserState.config).getCollectionDefaults) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : {};
207
244
  const campaignFields = analyticsBrowserState.config.autoCaptureCampaignParams === false ? {} : getCampaignFields();
208
245
  const path = (_e = event.path) !== null && _e !== void 0 ? _e : getCurrentPath();
209
246
  const visitorId = (_f = event.visitorId) !== null && _f !== void 0 ? _f : getOrCreateVisitorId();
210
247
  const href = (_h = (_g = event.href) !== null && _g !== void 0 ? _g : dynamicDefaults.href) !== null && _h !== void 0 ? _h : configuredDefaults.href;
211
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), campaignFields), getCurrentReferrerFields()), { visitorId, sessionId: getOrCreateSessionId(), deviceType: detectDeviceType(), path, pagePath: (_k = (_j = event.pagePath) !== null && _j !== void 0 ? _j : campaignFields.pagePath) !== null && _k !== void 0 ? _k : path, destinationDomain: (_l = event.destinationDomain) !== null && _l !== void 0 ? _l : getDestinationDomain(href), location: getResolvedLocation(), eventType: 'page_view' }), event), { metadata: Object.assign(Object.assign(Object.assign(Object.assign({}, ((_m = configuredDefaults.metadata) !== null && _m !== void 0 ? _m : {})), ((_o = dynamicDefaults.metadata) !== null && _o !== void 0 ? _o : {})), (visitorId ? { visitorId } : {})), ((_p = event.metadata) !== null && _p !== void 0 ? _p : {})) });
248
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), campaignFields), getCurrentReferrerFields()), { visitorId, sessionId: assertValidSessionId((_j = event.sessionId) !== null && _j !== void 0 ? _j : getOrCreateSessionId()), deviceType: detectDeviceType(), path, pagePath: (_l = (_k = event.pagePath) !== null && _k !== void 0 ? _k : campaignFields.pagePath) !== null && _l !== void 0 ? _l : path, destinationDomain: (_m = event.destinationDomain) !== null && _m !== void 0 ? _m : getDestinationDomain(href), location: getResolvedLocation(), eventType: 'page_view' }), event), { metadata: prunePromotedMetadataKeys(Object.assign(Object.assign(Object.assign({}, ((_o = configuredDefaults.metadata) !== null && _o !== void 0 ? _o : {})), ((_p = dynamicDefaults.metadata) !== null && _p !== void 0 ? _p : {})), ((_q = event.metadata) !== null && _q !== void 0 ? _q : {}))) });
212
249
  }
213
250
  function mergeTagEventDefaults(event) {
214
- var _a, _b, _c, _d, _e, _f, _g, _h;
251
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
215
252
  const configuredDefaults = (_a = analyticsBrowserState.config.defaultTagEvent) !== null && _a !== void 0 ? _a : {};
216
253
  const dynamicDefaults = (_d = (_c = (_b = analyticsBrowserState.config).getTagDefaults) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : {};
217
254
  const visitorId = (_e = event.visitorId) !== null && _e !== void 0 ? _e : getOrCreateVisitorId();
218
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), { visitorId, sessionId: getOrCreateSessionId(), deviceType: detectDeviceType(), location: getResolvedLocation(), eventType: 'scan_tag' }), event), { metadata: Object.assign(Object.assign(Object.assign(Object.assign({}, ((_f = configuredDefaults.metadata) !== null && _f !== void 0 ? _f : {})), ((_g = dynamicDefaults.metadata) !== null && _g !== void 0 ? _g : {})), (visitorId ? { visitorId } : {})), ((_h = event.metadata) !== null && _h !== void 0 ? _h : {})) });
255
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), { visitorId, sessionId: assertValidSessionId((_f = event.sessionId) !== null && _f !== void 0 ? _f : getOrCreateSessionId()), deviceType: detectDeviceType(), location: getResolvedLocation(), eventType: 'scan_tag' }), event), { metadata: prunePromotedMetadataKeys(Object.assign(Object.assign(Object.assign({}, ((_g = configuredDefaults.metadata) !== null && _g !== void 0 ? _g : {})), ((_h = dynamicDefaults.metadata) !== null && _h !== void 0 ? _h : {})), ((_j = event.metadata) !== null && _j !== void 0 ? _j : {}))) });
219
256
  }
220
257
  function isExternalHref(href) {
221
258
  if (typeof window === 'undefined')
@@ -267,7 +304,7 @@ export var analytics;
267
304
  * Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
268
305
  */
269
306
  function track(event, options) {
270
- return queueAnalytics('/public/analytics/collection', event, options);
307
+ return queueAnalytics('/public/analytics/collection', normalizeAnalyticsEvent(event), options);
271
308
  }
272
309
  collection.track = track;
273
310
  })(collection = analytics.collection || (analytics.collection = {}));
@@ -278,7 +315,7 @@ export var analytics;
278
315
  * Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
279
316
  */
280
317
  function track(event, options) {
281
- return queueAnalytics('/public/analytics/tag', event, options);
318
+ return queueAnalytics('/public/analytics/tag', normalizeAnalyticsEvent(event), options);
282
319
  }
283
320
  tag.track = track;
284
321
  })(tag = analytics.tag || (analytics.tag = {}));
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.8.0 | Generated: 2026-03-12T19:37:47.506Z
3
+ Version: 1.8.2 | Generated: 2026-03-14T10:21:47.666Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -166,6 +166,14 @@ Internal helper that performs a PATCH request to `${baseURL}${path}`, injecting
166
166
  options: RequestInit) → `Promise<T>`
167
167
  Internal helper that performs a request to `${baseURL}${path}` with custom options, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
168
168
 
169
+ **requestStream**(path: string,
170
+ options?: {
171
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
172
+ body?: any
173
+ headers?: Record<string, string>
174
+ }) → `Promise<AsyncIterable<T>>`
175
+ Internal helper that performs a streaming request using the shared auth and proxy transport. The response is expected to be `text/event-stream` with JSON payloads in `data:` frames.
176
+
169
177
  **del**(path: string,
170
178
  extraHeaders?: Record<string, string>) → `Promise<T>`
171
179
  Internal helper that performs a DELETE request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
@@ -938,9 +946,9 @@ interface AnalyticsLocation {
938
946
  }
939
947
  ```
940
948
 
941
- **AnalyticsStandardMetadataFields** (interface)
949
+ **AnalyticsStandardEventFields** (interface)
942
950
  ```typescript
943
- interface AnalyticsStandardMetadataFields {
951
+ interface AnalyticsStandardEventFields {
944
952
  visitorId?: string
945
953
  referrer?: string
946
954
  referrerHost?: string
@@ -977,13 +985,13 @@ interface AnalyticsTrackOptions {
977
985
  ```typescript
978
986
  interface AnalyticsBrowserConfig {
979
987
  sessionStorageKey?: string
980
- sessionIdFactory?: () => string
988
+ sessionIdFactory?: () => AnalyticsSessionId
981
989
  visitorId?: string
982
990
  visitorStorage?: AnalyticsStorageMode
983
991
  visitorStorageKey?: string
984
992
  visitorIdFactory?: () => string
985
993
  autoCaptureCampaignParams?: boolean
986
- campaignParamMap?: Partial<Record<keyof AnalyticsStandardMetadataFields, string | string[]>>
994
+ campaignParamMap?: Partial<Record<keyof AnalyticsStandardEventFields, string | string[]>>
987
995
  defaultCollectionEvent?: Partial<CollectionAnalyticsEvent>
988
996
  defaultTagEvent?: Partial<TagAnalyticsEvent>
989
997
  getCollectionDefaults?: () => Partial<CollectionAnalyticsEvent> | undefined
@@ -1048,8 +1056,8 @@ interface AnalyticsFilterRequest {
1048
1056
  batchIds?: string[]
1049
1057
  variantId?: string
1050
1058
  variantIds?: string[]
1051
- sessionId?: string
1052
- sessionIds?: string[]
1059
+ sessionId?: AnalyticsSessionId
1060
+ sessionIds?: AnalyticsSessionId[]
1053
1061
  country?: string
1054
1062
  countries?: string[]
1055
1063
  metadata?: Record<string, any>
@@ -1256,6 +1264,8 @@ interface AnalyticsTagsResponse {
1256
1264
 
1257
1265
  **AnalyticsStorageMode** = `'local' | 'session' | false`
1258
1266
 
1267
+ **AnalyticsSessionId** = `number`
1268
+
1259
1269
  **EventAnalyticsDimension** = ``
1260
1270
 
1261
1271
  **TagAnalyticsDimension** = ``
@@ -4203,6 +4213,38 @@ interface ProxyResponse {
4203
4213
  }
4204
4214
  ```
4205
4215
 
4216
+ **ProxyStreamRequest** (interface)
4217
+ ```typescript
4218
+ interface ProxyStreamRequest {
4219
+ _smartlinksProxyStreamRequest: true;
4220
+ id: string;
4221
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4222
+ path: string;
4223
+ body?: any;
4224
+ headers?: Record<string, string>;
4225
+ }
4226
+ ```
4227
+
4228
+ **ProxyStreamAbortMessage** (interface)
4229
+ ```typescript
4230
+ interface ProxyStreamAbortMessage {
4231
+ _smartlinksProxyStreamAbort: true;
4232
+ id: string;
4233
+ }
4234
+ ```
4235
+
4236
+ **ProxyStreamMessage** (interface)
4237
+ ```typescript
4238
+ interface ProxyStreamMessage {
4239
+ _smartlinksProxyStream: true;
4240
+ id: string;
4241
+ phase: 'open' | 'event' | 'end' | 'error';
4242
+ data?: any;
4243
+ error?: string;
4244
+ status?: number;
4245
+ }
4246
+ ```
4247
+
4206
4248
  **UploadStartMessage** (interface)
4207
4249
  ```typescript
4208
4250
  interface UploadStartMessage {
@@ -5789,7 +5831,7 @@ Fire-and-forget tag analytics event. Uses `navigator.sendBeacon()` when availabl
5789
5831
  **configure**(config: AnalyticsBrowserConfig) → `void`
5790
5832
  Fire-and-forget tag analytics event. Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
5791
5833
 
5792
- **getSessionId**() → `string | undefined`
5834
+ **getSessionId**() → `AnalyticsSessionId | undefined`
5793
5835
  Fire-and-forget tag analytics event. Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
5794
5836
 
5795
5837
  **getVisitorId**() → `string | undefined`
@@ -1,26 +1,31 @@
1
1
  # Analytics Metadata Conventions
2
2
 
3
- Use these as the recommended standard keys for analytics event metadata.
3
+ Use these as the recommended standard analytics keys.
4
4
 
5
- You can put them in `metadata` directly today. The public analytics ingestion endpoints also accept these as top-level convenience fields and mirror them into `metadata` on the backend.
5
+ Some of these are now promoted top-level analytics fields. Others remain good metadata keys for custom dimensions.
6
6
 
7
7
  ---
8
8
 
9
9
  ## Recommended Keys
10
10
 
11
- ### Traffic and attribution
11
+ ### Promoted top-level fields
12
12
 
13
- - `referrer`
13
+ - `visitorId`
14
14
  - `referrerHost`
15
+ - `entryType`
16
+ - `pageId`
17
+ - `scanMethod`
18
+
19
+ These should be sent as top-level analytics fields, not inside `metadata`.
20
+
21
+ ### Metadata-friendly keys
22
+
23
+ - `referrer`
15
24
  - `utmSource`
16
25
  - `utmMedium`
17
26
  - `utmCampaign`
18
27
  - `utmContent`
19
28
  - `utmTerm`
20
- - `entryType` — for example `direct`, `qr`, `nfc`, `social`, `email`, `paid`, or `organic`
21
-
22
- ### Link-tree and page analytics
23
-
24
29
  - `group`
25
30
  - `tag`
26
31
  - `campaign`
@@ -31,13 +36,8 @@ You can put them in `metadata` directly today. The public analytics ingestion en
31
36
  - `linkTitle`
32
37
  - `destinationDomain`
33
38
  - `pagePath`
34
- - `pageId`
35
39
  - `qrCodeId`
36
40
 
37
- ### Physical scan analytics
38
-
39
- - `scanMethod` — for example `nfc` or `qr`
40
-
41
41
  ---
42
42
 
43
43
  ## Why These Matter
@@ -56,6 +56,7 @@ These keys give teams a shared vocabulary for:
56
56
 
57
57
  - Treat these as reserved standard keys.
58
58
  - Prefer these names before inventing custom alternatives.
59
+ - Send promoted fields at top level.
59
60
  - Keep values flat and scalar where possible so they are easier to filter and break down later.
60
61
  - Promote a field to a first-class backend column only when it becomes a hot platform-wide dimension.
61
62
 
@@ -65,14 +66,17 @@ These keys give teams a shared vocabulary for:
65
66
 
66
67
  ```typescript
67
68
  analytics.collection.track({
68
- sessionId: 'sess_123',
69
+ sessionId: 1234567890,
69
70
  eventType: 'click_link',
70
71
  collectionId: 'demo-collection',
72
+ visitorId: 'visitor_123',
71
73
  linkId: 'hero-cta',
72
74
  href: 'https://example.com/buy',
75
+ referrerHost: 'instagram.com',
73
76
  placement: 'hero',
74
77
  campaign: 'summer-launch',
75
78
  utmSource: 'email',
79
+ pageId: 'QR123',
76
80
  metadata: {
77
81
  pagePath: '/c/demo-collection',
78
82
  },
@@ -44,7 +44,7 @@ There are two analytics domains:
44
44
  | Collection events | `/public/analytics/collection` | Page views, clicks, app navigation, landing pages |
45
45
  | Tag events | `/public/analytics/tag` | NFC / QR scans, claim/code activity, suspicious scan monitoring |
46
46
 
47
- The backend stores custom analytics dimensions in `metadata`. For the most common attribution and placement keys, the public ingestion endpoints also accept standard top-level convenience fields and mirror them into `metadata` automatically.
47
+ The backend stores custom analytics dimensions in `metadata`, but promoted analytics fields now belong at top level and are queried from real columns.
48
48
 
49
49
  See [docs/analytics-metadata-conventions.md](analytics-metadata-conventions.md) for the recommended key set.
50
50
 
@@ -60,7 +60,7 @@ import { initializeApi, analytics } from '@proveanything/smartlinks'
60
60
  initializeApi({ baseURL: 'https://smartlinks.app/api/v1' })
61
61
 
62
62
  analytics.collection.track({
63
- sessionId: 'sess_123',
63
+ sessionId: 1234567890,
64
64
  eventType: 'page_view',
65
65
  collectionId: 'demo-collection',
66
66
  productId: 'product_1',
@@ -74,7 +74,7 @@ analytics.collection.track({
74
74
 
75
75
  ```typescript
76
76
  analytics.collection.track({
77
- sessionId: 'sess_123',
77
+ sessionId: 1234567890,
78
78
  eventType: 'click_link',
79
79
  collectionId: 'demo-collection',
80
80
  productId: 'product_1',
@@ -91,7 +91,7 @@ analytics.collection.track({
91
91
 
92
92
  ```typescript
93
93
  analytics.tag.track({
94
- sessionId: 'sess_123',
94
+ sessionId: 1234567890,
95
95
  eventType: 'scan_tag',
96
96
  collectionId: 'demo-collection',
97
97
  productId: 'product_1',
@@ -298,15 +298,13 @@ Tracks generic collection analytics events such as:
298
298
  - internal navigation
299
299
  - outbound link activity
300
300
 
301
- Supported top-level fields include the core event fields plus standard convenience metadata fields such as `referrer`, `utmSource`, `group`, `placement`, `linkTitle`, `pagePath`, and `qrCodeId`.
302
-
303
- `visitorId` is also supported as a standard top-level field and is mirrored into `metadata` by the backend for backward compatibility.
301
+ Supported top-level fields include the core event fields plus promoted analytics columns such as `visitorId`, `referrerHost`, `pageId`, and `entryType`, along with custom metadata dimensions like `group`, `placement`, `pagePath`, and `qrCodeId`.
304
302
 
305
303
  Example:
306
304
 
307
305
  ```typescript
308
306
  analytics.collection.track({
309
- sessionId: 'sess_123',
307
+ sessionId: 1234567890,
310
308
  eventType: 'page_view',
311
309
  collectionId: 'demo-collection',
312
310
  productId: 'product_1',
@@ -322,6 +320,7 @@ analytics.collection.track({
322
320
  utmCampaign: 'summer-launch',
323
321
  group: 'summer-launch',
324
322
  placement: 'hero',
323
+ pageId: 'QR123',
325
324
  metadata: { pagePath: '/c/demo-collection?pageId=QR123' },
326
325
  })
327
326
  ```
@@ -335,15 +334,13 @@ Tracks physical scan analytics such as:
335
334
  - claim/code activity
336
335
  - admin vs customer scan behavior
337
336
 
338
- Supported top-level fields include the core scan fields plus the same standard convenience metadata fields, especially `entryType`, `scanMethod`, `group`, `tag`, and campaign or attribution keys when relevant.
339
-
340
- Like collection events, tag events also accept `visitorId` as a standard top-level field.
337
+ Supported top-level fields include the core scan fields plus promoted analytics columns such as `visitorId`, `entryType`, and `scanMethod`, along with custom metadata dimensions like `group`, `tag`, and campaign extras.
341
338
 
342
339
  Example:
343
340
 
344
341
  ```typescript
345
342
  analytics.tag.track({
346
- sessionId: 'sess_123',
343
+ sessionId: 1234567890,
347
344
  eventType: 'scan_tag',
348
345
  collectionId: 'demo-collection',
349
346
  productId: 'product_1',
@@ -374,6 +371,8 @@ Notes:
374
371
 
375
372
  Top-level scalar metadata values are the most query-friendly today. You can filter them with `metadata` and break them down with `dimension: 'metadata'` plus `metadataKey`.
376
373
 
374
+ Promoted fields such as `visitorId`, `referrerHost`, `pageId`, `entryType`, and `scanMethod` should be sent and queried as top-level fields, not inside `metadata`.
375
+
377
376
  ```typescript
378
377
  const grouped = await analytics.admin.breakdown('demo-collection', {
379
378
  source: 'tag',
@@ -528,7 +527,7 @@ const traffic = await analytics.admin.timeseries('demo-collection', {
528
527
  })
529
528
  ```
530
529
 
531
- `uniqueVisitors` now works in generic analytics queries. The backend uses `visitorId` when present and falls back to `sessionId` for older events that do not include it yet.
530
+ `uniqueVisitors` now works in generic analytics queries. The backend uses the top-level `visitorId` column when present and falls back to numeric `sessionId` for older events that do not include it yet.
532
531
 
533
532
  ### Breakdown
534
533
 
@@ -579,7 +578,7 @@ Most admin analytics queries support combinations of:
579
578
  - `proofId` or `proofIds[]`
580
579
  - `batchId` or `batchIds[]`
581
580
  - `variantId` or `variantIds[]`
582
- - `sessionId` or `sessionIds[]`
581
+ - `sessionId` or `sessionIds[]` as numbers
583
582
  - `country` or `countries[]`
584
583
  - `metadata` for top-level JSON equality matching
585
584
 
@@ -626,11 +625,9 @@ Analytics metadata filtering currently works best with top-level scalar keys suc
626
625
  - `campaign`
627
626
  - `group`
628
627
  - `tag`
629
- - `referrerHost`
630
628
  - `utmSource`
631
629
  - `utmCampaign`
632
630
  - `pagePath`
633
- - `scanMethod`
634
631
 
635
632
  See [docs/analytics-metadata-conventions.md](analytics-metadata-conventions.md) for the recommended shared vocabulary.
636
633
 
@@ -645,7 +642,7 @@ Use `/summary`, `/timeseries`, `/breakdown`, and `/events` when you are building
645
642
  ```typescript
646
643
  function trackAndNavigate(href: string) {
647
644
  analytics.collection.track({
648
- sessionId: 'sess_123',
645
+ sessionId: 1234567890,
649
646
  eventType: 'click_link',
650
647
  collectionId: 'demo-collection',
651
648
  linkId: 'buy-now',