@drivemetadata-ai/sdk 0.1.1-beta.1 → 0.1.1-beta.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.
Files changed (42) hide show
  1. package/README.md +18 -15
  2. package/dist/angular/index.cjs +118 -115
  3. package/dist/angular/index.cjs.map +1 -1
  4. package/dist/angular/index.d.cts +2 -2
  5. package/dist/angular/index.d.ts +2 -2
  6. package/dist/angular/index.js +118 -115
  7. package/dist/angular/index.js.map +1 -1
  8. package/dist/browser/index.cjs +119 -116
  9. package/dist/browser/index.cjs.map +1 -1
  10. package/dist/browser/index.d.cts +5 -68
  11. package/dist/browser/index.d.ts +5 -68
  12. package/dist/browser/index.js +119 -116
  13. package/dist/browser/index.js.map +1 -1
  14. package/dist/next/index.cjs +119 -115
  15. package/dist/next/index.cjs.map +1 -1
  16. package/dist/next/index.d.cts +1 -1
  17. package/dist/next/index.d.ts +1 -1
  18. package/dist/next/index.js +119 -115
  19. package/dist/next/index.js.map +1 -1
  20. package/dist/node/index.cjs +80 -7
  21. package/dist/node/index.cjs.map +1 -1
  22. package/dist/node/index.d.cts +7 -1
  23. package/dist/node/index.d.ts +7 -1
  24. package/dist/node/index.js +80 -7
  25. package/dist/node/index.js.map +1 -1
  26. package/dist/react/index.cjs +119 -115
  27. package/dist/react/index.cjs.map +1 -1
  28. package/dist/react/index.d.cts +2 -2
  29. package/dist/react/index.d.ts +2 -2
  30. package/dist/react/index.js +119 -115
  31. package/dist/react/index.js.map +1 -1
  32. package/dist/{types-BwtS0ZDu.d.cts → types--V8TVIqT.d.cts} +7 -3
  33. package/dist/{types-BwtS0ZDu.d.ts → types--V8TVIqT.d.ts} +7 -3
  34. package/docs/angular-integration.md +6 -6
  35. package/docs/index.md +4 -6
  36. package/docs/integration.md +322 -0
  37. package/docs/node-server-integration.md +16 -7
  38. package/docs/npm-browser-sdk.md +4 -8
  39. package/docs/react-next-integration.md +9 -9
  40. package/docs/security-privacy.md +11 -11
  41. package/package.json +4 -5
  42. package/docs/migration-cdn-to-npm.md +0 -99
@@ -20,6 +20,61 @@ var DmdServerRequestError = class extends DmdServerSdkError {
20
20
  }
21
21
  };
22
22
 
23
+ // src/core/backend-payload.ts
24
+ function formatUtcTimestamp(value) {
25
+ if (typeof value !== "string") return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
26
+ const date = new Date(value);
27
+ if (Number.isNaN(date.getTime())) return value;
28
+ return date.toISOString().replace("T", " ").slice(0, 19);
29
+ }
30
+ function cleanObject(value) {
31
+ if (Array.isArray(value)) {
32
+ const cleaned = value.map((item) => cleanObject(item)).filter((item) => item !== null && item !== void 0 && item !== "");
33
+ return cleaned.length > 0 ? cleaned : void 0;
34
+ }
35
+ if (value && typeof value === "object") {
36
+ const cleaned = Object.fromEntries(
37
+ Object.entries(value).map(([key, item]) => [key, cleanObject(item)]).filter(([, item]) => {
38
+ if (item === null || item === void 0 || item === "") return false;
39
+ if (typeof item === "object" && !Array.isArray(item) && Object.keys(item).length === 0) return false;
40
+ return true;
41
+ })
42
+ );
43
+ return Object.keys(cleaned).length > 0 ? cleaned : void 0;
44
+ }
45
+ return value;
46
+ }
47
+ function createBackendCollectorPayload(input) {
48
+ const eventData = input.eventData && typeof input.eventData === "object" ? input.eventData : {};
49
+ const page = eventData.page && typeof eventData.page === "object" ? eventData.page : {};
50
+ const timestamp = formatUtcTimestamp(eventData.timestamp ?? input.timestamp);
51
+ const normalizedEventData = {
52
+ ...eventData,
53
+ timestamp,
54
+ requestSentAt: formatUtcTimestamp(eventData.requestSentAt ?? input.requestSentAt ?? timestamp),
55
+ requestReceivedAt: formatUtcTimestamp(eventData.requestReceivedAt ?? input.requestReceivedAt ?? timestamp)
56
+ };
57
+ const metaData = {
58
+ ...normalizedEventData,
59
+ requestId: input.requestId,
60
+ timestamp,
61
+ eventType: input.eventType,
62
+ requestFrom: input.requestFrom ?? "3",
63
+ clientId: input.clientId,
64
+ workspaceId: input.workspaceId,
65
+ token: input.token,
66
+ anonymousId: eventData.anonymousId ?? input.anonymousId,
67
+ sessionId: eventData.sessionId ?? input.sessionId,
68
+ ua: input.ua,
69
+ appDetails: { app_id: input.appId },
70
+ page: { ...page, url: page.url ?? input.pageUrl },
71
+ requestSentAt: normalizedEventData.requestSentAt,
72
+ requestReceivedAt: normalizedEventData.requestReceivedAt
73
+ };
74
+ const payload = { metaData };
75
+ return cleanObject(payload);
76
+ }
77
+
23
78
  // src/node/retry.ts
24
79
  function isRetryableStatus(status) {
25
80
  return status === 408 || status === 429 || status >= 500;
@@ -42,7 +97,7 @@ function requireString(value, message) {
42
97
  return value;
43
98
  }
44
99
  function validateServerConfig(config) {
45
- requireString(config.writeKey, "DMD server SDK config writeKey is required");
100
+ requireString(config.writeKey || config.token, "DMD server SDK config writeKey or token is required");
46
101
  }
47
102
  function validateTrackPayload(payload) {
48
103
  requireString(payload.event, "DMD server SDK track event is required");
@@ -103,6 +158,28 @@ function withBatchItemTimestamp(item) {
103
158
  if (item.type === "alias") return { type: item.type, payload: withTimestamp(item.payload) };
104
159
  return { type: item.type, payload: withTimestamp(item.payload) };
105
160
  }
161
+ function toCollectorPayload(config, type, payload, token) {
162
+ const basePayload = payload;
163
+ const properties = "properties" in payload && payload.properties ? payload.properties : {};
164
+ return createBackendCollectorPayload({
165
+ requestId: payload.messageId ?? `${type}_${Date.now()}`,
166
+ timestamp: payload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
167
+ eventType: type === "track" ? basePayload.event : type,
168
+ requestFrom: config.requestFrom ?? "3",
169
+ clientId: config.clientId,
170
+ workspaceId: config.workspaceId,
171
+ token,
172
+ anonymousId: basePayload.anonymousId,
173
+ sessionId: basePayload.sessionId,
174
+ appId: config.appId,
175
+ eventData: {
176
+ ...properties,
177
+ anonymousId: basePayload.anonymousId,
178
+ sessionId: basePayload.sessionId,
179
+ timestamp: payload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
180
+ }
181
+ });
182
+ }
106
183
  function createTimeoutController(timeoutMs) {
107
184
  if (!timeoutMs) {
108
185
  return { cleanup: () => void 0 };
@@ -118,6 +195,7 @@ function createDmdServerClient(config) {
118
195
  validateServerConfig(config);
119
196
  const endpoint = config.endpoint ?? DEFAULT_ENDPOINT;
120
197
  const fetchImpl = config.fetch ?? globalThis.fetch;
198
+ const authorizationToken = config.writeKey || config.token;
121
199
  if (typeof fetchImpl !== "function") {
122
200
  throw new Error("DMD server SDK requires fetch. Use Node.js 18+ or pass config.fetch.");
123
201
  }
@@ -129,7 +207,6 @@ function createDmdServerClient(config) {
129
207
  const requestInit = {
130
208
  method: "POST",
131
209
  headers: {
132
- Authorization: `Bearer ${config.writeKey}`,
133
210
  "Content-Type": "application/json"
134
211
  },
135
212
  body: JSON.stringify(requestPayload)
@@ -160,11 +237,7 @@ function createDmdServerClient(config) {
160
237
  throw new DmdServerRequestError("DMD server SDK request failed", void 0, lastError);
161
238
  }
162
239
  function envelope(type, payload) {
163
- return {
164
- type,
165
- payload,
166
- sentAt: (/* @__PURE__ */ new Date()).toISOString()
167
- };
240
+ return toCollectorPayload(config, type, payload, authorizationToken);
168
241
  }
169
242
  return {
170
243
  async track(payload) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/node/errors.ts","../../src/node/retry.ts","../../src/node/validation.ts","../../src/node/client.ts"],"sourcesContent":["export class DmdServerSdkError extends Error {\n constructor(message: string, public readonly cause?: unknown) {\n super(message);\n this.name = 'DmdServerSdkError';\n }\n}\n\nexport class DmdServerValidationError extends DmdServerSdkError {\n constructor(message: string) {\n super(message);\n this.name = 'DmdServerValidationError';\n }\n}\n\nexport class DmdServerRequestError extends DmdServerSdkError {\n constructor(message: string, public readonly status?: number, cause?: unknown) {\n super(message, cause);\n this.name = 'DmdServerRequestError';\n }\n}\n","import type { DmdServerRetryConfig } from './types';\n\nexport function isRetryableStatus(status: number): boolean {\n return status === 408 || status === 429 || status >= 500;\n}\n\nexport function getRetryDelayMs(attemptIndex: number, retry: DmdServerRetryConfig = {}): number {\n const minDelayMs = retry.minDelayMs ?? 250;\n const maxDelayMs = retry.maxDelayMs ?? 2000;\n const exponentialDelay = minDelayMs * 2 ** attemptIndex;\n\n return Math.min(exponentialDelay, maxDelayMs);\n}\n\nexport function getRetryAttempts(retry: DmdServerRetryConfig | undefined): number {\n return retry?.attempts ?? 0;\n}\n","import { DmdServerValidationError } from './errors';\nimport type {\n DmdServerAliasPayload,\n DmdServerBatchItem,\n DmdServerConfig,\n DmdServerGroupPayload,\n DmdServerIdentifyPayload,\n DmdServerPagePayload,\n DmdServerTrackPayload\n} from './types';\n\nfunction requireString(value: string | undefined, message: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new DmdServerValidationError(message);\n }\n\n return value;\n}\n\nexport function validateServerConfig(config: DmdServerConfig): void {\n requireString(config.writeKey, 'DMD server SDK config writeKey is required');\n}\n\nexport function validateTrackPayload(payload: DmdServerTrackPayload): void {\n requireString(payload.event, 'DMD server SDK track event is required');\n\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK track requires userId or anonymousId');\n }\n}\n\nexport function validateIdentifyPayload(payload: DmdServerIdentifyPayload): void {\n requireString(payload.userId, 'DMD server SDK identify requires userId');\n}\n\nexport function validatePagePayload(payload: DmdServerPagePayload): void {\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK page requires userId or anonymousId');\n }\n}\n\nexport function validateAliasPayload(payload: DmdServerAliasPayload): void {\n const hasPreviousId = typeof payload.previousId === 'string' && payload.previousId.trim() !== '';\n const hasUserId = typeof payload.userId === 'string' && payload.userId.trim() !== '';\n if (!hasPreviousId || !hasUserId) {\n throw new DmdServerValidationError('DMD server SDK alias requires previousId and userId');\n }\n}\n\nexport function validateGroupPayload(payload: DmdServerGroupPayload): void {\n requireString(payload.groupId, 'DMD server SDK group requires groupId');\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK group requires userId or anonymousId');\n }\n}\n\nexport function validateBatchPayload(items: DmdServerBatchItem[]): void {\n if (!Array.isArray(items) || items.length === 0) {\n throw new DmdServerValidationError('DMD server SDK batch requires at least one item');\n }\n\n for (const item of items) {\n if (item.type === 'track') validateTrackPayload(item.payload);\n else if (item.type === 'identify') validateIdentifyPayload(item.payload);\n else if (item.type === 'page') validatePagePayload(item.payload);\n else if (item.type === 'alias') validateAliasPayload(item.payload);\n else if (item.type === 'group') validateGroupPayload(item.payload);\n else throw new DmdServerValidationError('DMD server SDK batch item has invalid type');\n }\n}\n","import { DmdServerRequestError } from './errors';\nimport { getRetryAttempts, getRetryDelayMs, isRetryableStatus } from './retry';\nimport type {\n DmdServerAliasPayload,\n DmdServerBatchItem,\n DmdServerClient,\n DmdServerConfig,\n DmdServerGroupPayload,\n DmdServerIdentifyPayload,\n DmdServerPagePayload,\n DmdServerRequestPayload,\n DmdServerSingleRequestPayload,\n DmdServerTrackPayload\n} from './types';\nimport {\n validateAliasPayload,\n validateBatchPayload,\n validateGroupPayload,\n validateIdentifyPayload,\n validatePagePayload,\n validateServerConfig,\n validateTrackPayload\n} from './validation';\n\nconst DEFAULT_ENDPOINT = 'https://sdk.drivemetadata.com/v2/data-collector';\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nfunction withTimestamp<T extends { timestamp?: string }>(payload: T): T {\n return {\n ...payload,\n timestamp: payload.timestamp ?? new Date().toISOString()\n };\n}\n\nfunction withBatchItemTimestamp(item: DmdServerBatchItem): DmdServerBatchItem {\n if (item.type === 'track') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'identify') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'page') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'alias') return { type: item.type, payload: withTimestamp(item.payload) };\n return { type: item.type, payload: withTimestamp(item.payload) };\n}\n\nfunction createTimeoutController(timeoutMs: number | undefined): { signal?: AbortSignal; cleanup: () => void } {\n if (!timeoutMs) {\n return { cleanup: () => undefined };\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n return {\n signal: controller.signal,\n cleanup: () => clearTimeout(timer)\n };\n}\n\nexport function createDmdServerClient(config: DmdServerConfig): DmdServerClient {\n validateServerConfig(config);\n\n const endpoint = config.endpoint ?? DEFAULT_ENDPOINT;\n const fetchImpl = config.fetch ?? globalThis.fetch;\n\n if (typeof fetchImpl !== 'function') {\n throw new Error('DMD server SDK requires fetch. Use Node.js 18+ or pass config.fetch.');\n }\n\n async function send(requestPayload: DmdServerRequestPayload): Promise<void> {\n const attempts = getRetryAttempts(config.retry);\n let lastError: unknown;\n\n for (let attemptIndex = 0; attemptIndex <= attempts; attemptIndex += 1) {\n try {\n const requestInit: RequestInit = {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${config.writeKey}`,\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(requestPayload)\n };\n const timeout = createTimeoutController(config.timeoutMs);\n if (timeout.signal !== undefined) {\n requestInit.signal = timeout.signal;\n }\n\n const response = await fetchImpl(endpoint, requestInit).finally(timeout.cleanup);\n\n if (response.ok) {\n return;\n }\n\n if (!isRetryableStatus(response.status) || attemptIndex === attempts) {\n throw new DmdServerRequestError(\n `DMD server SDK request failed with status ${response.status}`,\n response.status\n );\n }\n\n await sleep(getRetryDelayMs(attemptIndex, config.retry));\n } catch (error) {\n lastError = error;\n\n if (error instanceof DmdServerRequestError || attemptIndex === attempts) {\n throw error;\n }\n\n await sleep(getRetryDelayMs(attemptIndex, config.retry));\n }\n }\n\n throw new DmdServerRequestError('DMD server SDK request failed', undefined, lastError);\n }\n\n function envelope(type: DmdServerSingleRequestPayload['type'], payload: DmdServerSingleRequestPayload['payload']) {\n return {\n type,\n payload,\n sentAt: new Date().toISOString()\n };\n }\n\n return {\n async track(payload: DmdServerTrackPayload) {\n validateTrackPayload(payload);\n await send(envelope('track', withTimestamp(payload)));\n },\n async identify(payload: DmdServerIdentifyPayload) {\n validateIdentifyPayload(payload);\n await send(envelope('identify', withTimestamp(payload)));\n },\n async page(payload: DmdServerPagePayload) {\n validatePagePayload(payload);\n await send(envelope('page', withTimestamp(payload)));\n },\n async alias(payload: DmdServerAliasPayload) {\n validateAliasPayload(payload);\n await send(envelope('alias', withTimestamp(payload)));\n },\n async group(payload: DmdServerGroupPayload) {\n validateGroupPayload(payload);\n await send(envelope('group', withTimestamp(payload)));\n },\n async batch(items: DmdServerBatchItem[]) {\n validateBatchPayload(items);\n await send({\n type: 'batch',\n batch: items.map(withBatchItemTimestamp),\n sentAt: new Date().toISOString()\n });\n },\n async flush() {\n return Promise.resolve();\n }\n };\n}\n"],"mappings":";AAAO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAiC,OAAiB;AAC5D,UAAM,OAAO;AAD8B;AAE3C,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,2BAAN,cAAuC,kBAAkB;AAAA,EAC9D,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,wBAAN,cAAoC,kBAAkB;AAAA,EAC3D,YAAY,SAAiC,QAAiB,OAAiB;AAC7E,UAAM,SAAS,KAAK;AADuB;AAE3C,SAAK,OAAO;AAAA,EACd;AACF;;;ACjBO,SAAS,kBAAkB,QAAyB;AACzD,SAAO,WAAW,OAAO,WAAW,OAAO,UAAU;AACvD;AAEO,SAAS,gBAAgB,cAAsB,QAA8B,CAAC,GAAW;AAC9F,QAAM,aAAa,MAAM,cAAc;AACvC,QAAM,aAAa,MAAM,cAAc;AACvC,QAAM,mBAAmB,aAAa,KAAK;AAE3C,SAAO,KAAK,IAAI,kBAAkB,UAAU;AAC9C;AAEO,SAAS,iBAAiB,OAAiD;AAChF,SAAO,OAAO,YAAY;AAC5B;;;ACLA,SAAS,cAAc,OAA2B,SAAyB;AACzE,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;AACpD,UAAM,IAAI,yB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AM,SAAgC;AAC1C,2BAAqB,OAAO;AAC5B,YAAM,KAAK,SAAS,SAAS,cAAc,OAAO,CAAC,CAAC;AAAA,IACtD;AAAA,IACA,MAAM,SAAS,SAAmC;AAChD,8BAAwB,OAAO;AAC/B,YAAM,KAAK,SAAS,YAAY,cAAc,OAAO,CAAC,CAAC;AAAA,IACzD;AAAA,IACA,MAAM,KAAK,SAA+B;AACxC,0BAAoB,OAAO;AAC3B,YAAM,KAAK,SAAS,QAAQ,cAAc,OAAO,CAAC,CAAC;AAAA,IACrD;AAAA,IACA,MAAM,MAAM,SAAgC;AAC1C,2BAAqB,OAAO;AAC5B,YAAM,KAAK,SAAS,SAAS,cAAc,OAAO,CAAC,CAAC;AAAA,IACtD;AAAA,IACA,MAAM,MAAM,SAAgC;AAC1C,2BAAqB,OAAO;AAC5B,YAAM,KAAK,SAAS,SAAS,cAAc,OAAO,CAAC,CAAC;AAAA,IACtD;AAAA,IACA,MAAM,MAAM,OAA6B;AACvC,2BAAqB,KAAK;AAC1B,YAAM,KAAK;AAAA,QACT,MAAM;AAAA,QACN,OAAO,MAAM,IAAI,sBAAsB;AAAA,QACvC,SAAQ,oBAAI,KAAK,GAAE,YAAY;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,IACA,MAAM,QAAQ;AACZ,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/node/errors.ts","../../src/core/backend-payload.ts","../../src/node/retry.ts","../../src/node/validation.ts","../../src/node/client.ts"],"sourcesContent":["export class DmdServerSdkError extends Error {\n constructor(message: string, public readonly cause?: unknown) {\n super(message);\n this.name = 'DmdServerSdkError';\n }\n}\n\nexport class DmdServerValidationError extends DmdServerSdkError {\n constructor(message: string) {\n super(message);\n this.name = 'DmdServerValidationError';\n }\n}\n\nexport class DmdServerRequestError extends DmdServerSdkError {\n constructor(message: string, public readonly status?: number, cause?: unknown) {\n super(message, cause);\n this.name = 'DmdServerRequestError';\n }\n}\n","function formatUtcTimestamp(value: unknown): string {\n if (typeof value !== 'string') return new Date().toISOString().replace('T', ' ').slice(0, 19);\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) return value;\n return date.toISOString().replace('T', ' ').slice(0, 19);\n}\n\nfunction cleanObject(value: unknown): unknown {\n if (Array.isArray(value)) {\n const cleaned = value\n .map(item => cleanObject(item))\n .filter(item => item !== null && item !== undefined && item !== '');\n return cleaned.length > 0 ? cleaned : undefined;\n }\n\n if (value && typeof value === 'object') {\n const cleaned = Object.fromEntries(\n Object.entries(value as Record<string, unknown>)\n .map(([key, item]) => [key, cleanObject(item)])\n .filter(([, item]) => {\n if (item === null || item === undefined || item === '') return false;\n if (typeof item === 'object' && !Array.isArray(item) && Object.keys(item).length === 0) return false;\n return true;\n })\n );\n return Object.keys(cleaned).length > 0 ? cleaned : undefined;\n }\n\n return value;\n}\n\nexport function createBackendCollectorPayload(input: Record<string, unknown>): Record<string, unknown> {\n const eventData = input.eventData && typeof input.eventData === 'object'\n ? input.eventData as Record<string, unknown>\n : {};\n const page = eventData.page && typeof eventData.page === 'object'\n ? eventData.page as Record<string, unknown>\n : {};\n const timestamp = formatUtcTimestamp(eventData.timestamp ?? input.timestamp);\n const normalizedEventData = {\n ...eventData,\n timestamp,\n requestSentAt: formatUtcTimestamp(eventData.requestSentAt ?? input.requestSentAt ?? timestamp),\n requestReceivedAt: formatUtcTimestamp(eventData.requestReceivedAt ?? input.requestReceivedAt ?? timestamp)\n };\n\n const metaData: Record<string, unknown> = {\n ...normalizedEventData,\n requestId: input.requestId,\n timestamp,\n eventType: input.eventType,\n requestFrom: input.requestFrom ?? '3',\n clientId: input.clientId,\n workspaceId: input.workspaceId,\n token: input.token,\n anonymousId: eventData.anonymousId ?? input.anonymousId,\n sessionId: eventData.sessionId ?? input.sessionId,\n ua: input.ua,\n appDetails: { app_id: input.appId },\n page: { ...page, url: page.url ?? input.pageUrl },\n requestSentAt: normalizedEventData.requestSentAt,\n requestReceivedAt: normalizedEventData.requestReceivedAt\n };\n\n const payload = { metaData };\n\n return cleanObject(payload) as Record<string, unknown>;\n}\n","import type { DmdServerRetryConfig } from './types';\n\nexport function isRetryableStatus(status: number): boolean {\n return status === 408 || status === 429 || status >= 500;\n}\n\nexport function getRetryDelayMs(attemptIndex: number, retry: DmdServerRetryConfig = {}): number {\n const minDelayMs = retry.minDelayMs ?? 250;\n const maxDelayMs = retry.maxDelayMs ?? 2000;\n const exponentialDelay = minDelayMs * 2 ** attemptIndex;\n\n return Math.min(exponentialDelay, maxDelayMs);\n}\n\nexport function getRetryAttempts(retry: DmdServerRetryConfig | undefined): number {\n return retry?.attempts ?? 0;\n}\n","import { DmdServerValidationError } from './errors';\nimport type {\n DmdServerAliasPayload,\n DmdServerBatchItem,\n DmdServerConfig,\n DmdServerGroupPayload,\n DmdServerIdentifyPayload,\n DmdServerPagePayload,\n DmdServerTrackPayload\n} from './types';\n\nfunction requireString(value: string | undefined, message: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new DmdServerValidationError(message);\n }\n\n return value;\n}\n\nexport function validateServerConfig(config: DmdServerConfig): void {\n requireString(config.writeKey || config.token, 'DMD server SDK config writeKey or token is required');\n}\n\nexport function validateTrackPayload(payload: DmdServerTrackPayload): void {\n requireString(payload.event, 'DMD server SDK track event is required');\n\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK track requires userId or anonymousId');\n }\n}\n\nexport function validateIdentifyPayload(payload: DmdServerIdentifyPayload): void {\n requireString(payload.userId, 'DMD server SDK identify requires userId');\n}\n\nexport function validatePagePayload(payload: DmdServerPagePayload): void {\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK page requires userId or anonymousId');\n }\n}\n\nexport function validateAliasPayload(payload: DmdServerAliasPayload): void {\n const hasPreviousId = typeof payload.previousId === 'string' && payload.previousId.trim() !== '';\n const hasUserId = typeof payload.userId === 'string' && payload.userId.trim() !== '';\n if (!hasPreviousId || !hasUserId) {\n throw new DmdServerValidationError('DMD server SDK alias requires previousId and userId');\n }\n}\n\nexport function validateGroupPayload(payload: DmdServerGroupPayload): void {\n requireString(payload.groupId, 'DMD server SDK group requires groupId');\n if (!payload.userId && !payload.anonymousId) {\n throw new DmdServerValidationError('DMD server SDK group requires userId or anonymousId');\n }\n}\n\nexport function validateBatchPayload(items: DmdServerBatchItem[]): void {\n if (!Array.isArray(items) || items.length === 0) {\n throw new DmdServerValidationError('DMD server SDK batch requires at least one item');\n }\n\n for (const item of items) {\n if (item.type === 'track') validateTrackPayload(item.payload);\n else if (item.type === 'identify') validateIdentifyPayload(item.payload);\n else if (item.type === 'page') validatePagePayload(item.payload);\n else if (item.type === 'alias') validateAliasPayload(item.payload);\n else if (item.type === 'group') validateGroupPayload(item.payload);\n else throw new DmdServerValidationError('DMD server SDK batch item has invalid type');\n }\n}\n","import { DmdServerRequestError } from './errors';\nimport { createBackendCollectorPayload } from '../core/backend-payload';\nimport { getRetryAttempts, getRetryDelayMs, isRetryableStatus } from './retry';\nimport type {\n DmdServerAliasPayload,\n DmdServerBatchItem,\n DmdServerClient,\n DmdServerConfig,\n DmdServerGroupPayload,\n DmdServerIdentifyPayload,\n DmdServerPagePayload,\n DmdServerSingleRequestPayload,\n DmdServerTrackPayload\n} from './types';\nimport {\n validateAliasPayload,\n validateBatchPayload,\n validateGroupPayload,\n validateIdentifyPayload,\n validatePagePayload,\n validateServerConfig,\n validateTrackPayload\n} from './validation';\n\nconst DEFAULT_ENDPOINT = 'https://sdk.drivemetadata.com/v2/data-collector';\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nfunction withTimestamp<T extends { timestamp?: string }>(payload: T): T {\n return {\n ...payload,\n timestamp: payload.timestamp ?? new Date().toISOString()\n };\n}\n\nfunction withBatchItemTimestamp(item: DmdServerBatchItem): DmdServerBatchItem {\n if (item.type === 'track') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'identify') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'page') return { type: item.type, payload: withTimestamp(item.payload) };\n if (item.type === 'alias') return { type: item.type, payload: withTimestamp(item.payload) };\n return { type: item.type, payload: withTimestamp(item.payload) };\n}\n\nfunction toCollectorPayload(\n config: DmdServerConfig,\n type: DmdServerSingleRequestPayload['type'],\n payload: DmdServerSingleRequestPayload['payload'],\n token: string | undefined\n) {\n const basePayload = payload as DmdServerTrackPayload & { anonymousId?: string; sessionId?: string };\n const properties = 'properties' in payload && payload.properties ? payload.properties : {};\n return createBackendCollectorPayload({\n requestId: payload.messageId ?? `${type}_${Date.now()}`,\n timestamp: payload.timestamp ?? new Date().toISOString(),\n eventType: type === 'track' ? basePayload.event : type,\n requestFrom: config.requestFrom ?? '3',\n clientId: config.clientId,\n workspaceId: config.workspaceId,\n token,\n anonymousId: basePayload.anonymousId,\n sessionId: basePayload.sessionId,\n appId: config.appId,\n eventData: {\n ...properties,\n anonymousId: basePayload.anonymousId,\n sessionId: basePayload.sessionId,\n timestamp: payload.timestamp ?? new Date().toISOString()\n }\n });\n}\n\nfunction createTimeoutController(timeoutMs: number | undefined): { signal?: AbortSignal; cleanup: () => void } {\n if (!timeoutMs) {\n return { cleanup: () => undefined };\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n return {\n signal: controller.signal,\n cleanup: () => clearTimeout(timer)\n };\n}\n\nexport function createDmdServerClient(config: DmdServerConfig): DmdServerClient {\n validateServerConfig(config);\n\n const endpoint = config.endpoint ?? DEFAULT_ENDPOINT;\n const fetchImpl = config.fetch ?? globalThis.fetch;\n const authorizationToken = config.writeKey || config.token;\n\n if (typeof fetchImpl !== 'function') {\n throw new Error('DMD server SDK requires fetch. Use Node.js 18+ or pass config.fetch.');\n }\n\n async function send(requestPayload: Record<string, unknown>): Promise<void> {\n const attempts = getRetryAttempts(config.retry);\n let lastError: unknown;\n\n for (let attemptIndex = 0; attemptIndex <= attempts; attemptIndex += 1) {\n try {\n const requestInit: RequestInit = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(requestPayload)\n };\n const timeout = createTimeoutController(config.timeoutMs);\n if (timeout.signal !== undefined) {\n requestInit.signal = timeout.signal;\n }\n\n const response = await fetchImpl(endpoint, requestInit).finally(timeout.cleanup);\n\n if (response.ok) {\n return;\n }\n\n if (!isRetryableStatus(response.status) || attemptIndex === attempts) {\n throw new DmdServerRequestError(\n `DMD server SDK request failed with status ${response.status}`,\n response.status\n );\n }\n\n await sleep(getRetryDelayMs(attemptIndex, config.retry));\n } catch (error) {\n lastError = error;\n\n if (error instanceof DmdServerRequestError || attemptIndex === attempts) {\n throw error;\n }\n\n await sleep(getRetryDelayMs(attemptIndex, config.retry));\n }\n }\n\n throw new DmdServerRequestError('DMD server SDK request failed', undefined, lastError);\n }\n\n function envelope(type: DmdServerSingleRequestPayload['type'], payload: DmdServerSingleRequestPayload['payload']) {\n return toCollectorPayload(config, type, payload, authorizationToken);\n }\n\n return {\n async track(payload: DmdServerTrackPayload) {\n validateTrackPayload(payload);\n await send(envelope('track', withTimestamp(payload)));\n },\n async identify(payload: DmdServerIdentifyPayload) {\n validateIdentifyPayload(payload);\n await send(envelope('identify', withTimestamp(payload)));\n },\n async page(payload: DmdServerPagePayload) {\n validatePagePayload(payload);\n await send(envelope('page', withTimestamp(payload)));\n },\n async alias(payload: DmdServerAliasPayload) {\n validateAliasPayload(payload);\n await send(envelope('alias', withTimestamp(payload)));\n },\n async group(payload: DmdServerGroupPayload) {\n validateGroupPayload(payload);\n await send(envelope('group', withTimestamp(payload)));\n },\n async batch(items: DmdServerBatchItem[]) {\n validateBatchPayload(items);\n await send({\n type: 'batch',\n batch: items.map(withBatchItemTimestamp),\n sentAt: new Date().toISOString()\n });\n },\n async flush() {\n return Promise.resolve();\n }\n };\n}\n"],"mappings":";AAAO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,SAAiC,OAAiB;AAC5D,UAAM,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C;AAC1C,2BAAqB,OAAO;AAC5B,YAAM,KAAK,SAAS,SAAS,cAAc,OAAO,CAAC,CAAC;AAAA,IACtD;AAAA,IACA,MAAM,MAAM,SAAgC;AAC1C,2BAAqB,OAAO;AAC5B,YAAM,KAAK,SAAS,SAAS,cAAc,OAAO,CAAC,CAAC;AAAA,IACtD;AAAA,IACA,MAAM,MAAM,OAA6B;AACvC,2BAAqB,KAAK;AAC1B,YAAM,KAAK;AAAA,QACT,MAAM;AAAA,QACN,OAAO,MAAM,IAAI,sBAAsB;AAAA,QACvC,SAAQ,oBAAI,KAAK,GAAE,YAAY;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,IACA,MAAM,QAAQ;AACZ,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
@@ -47,53 +47,62 @@ module.exports = __toCommonJS(react_exports);
47
47
  // src/react/DmdProvider.tsx
48
48
  var import_react = __toESM(require("react"), 1);
49
49
 
50
- // src/core/config.ts
51
- function requireString(value, field) {
52
- if (typeof value !== "string" || value.trim() === "") {
53
- throw new Error(`DMD SDK config ${field} is required`);
50
+ // src/core/backend-payload.ts
51
+ function formatUtcTimestamp(value) {
52
+ if (typeof value !== "string") return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
53
+ const date = new Date(value);
54
+ if (Number.isNaN(date.getTime())) return value;
55
+ return date.toISOString().replace("T", " ").slice(0, 19);
56
+ }
57
+ function cleanObject(value) {
58
+ if (Array.isArray(value)) {
59
+ const cleaned = value.map((item) => cleanObject(item)).filter((item) => item !== null && item !== void 0 && item !== "");
60
+ return cleaned.length > 0 ? cleaned : void 0;
61
+ }
62
+ if (value && typeof value === "object") {
63
+ const cleaned = Object.fromEntries(
64
+ Object.entries(value).map(([key, item]) => [key, cleanObject(item)]).filter(([, item]) => {
65
+ if (item === null || item === void 0 || item === "") return false;
66
+ if (typeof item === "object" && !Array.isArray(item) && Object.keys(item).length === 0) return false;
67
+ return true;
68
+ })
69
+ );
70
+ return Object.keys(cleaned).length > 0 ? cleaned : void 0;
54
71
  }
55
72
  return value;
56
73
  }
57
- function normalizeBrowserConfig(config) {
58
- const writeKey = config.writeKey || config.token;
59
- const legacyConfig = {
60
- client_id: requireString(config.clientId, "clientId"),
61
- workspace_id: requireString(config.workspaceId, "workspaceId"),
62
- app_id: requireString(config.appId, "appId"),
63
- token: requireString(writeKey, "writeKey")
74
+ function createBackendCollectorPayload(input) {
75
+ const eventData = input.eventData && typeof input.eventData === "object" ? input.eventData : {};
76
+ const page2 = eventData.page && typeof eventData.page === "object" ? eventData.page : {};
77
+ const timestamp = formatUtcTimestamp(eventData.timestamp ?? input.timestamp);
78
+ const normalizedEventData = {
79
+ ...eventData,
80
+ timestamp,
81
+ requestSentAt: formatUtcTimestamp(eventData.requestSentAt ?? input.requestSentAt ?? timestamp),
82
+ requestReceivedAt: formatUtcTimestamp(eventData.requestReceivedAt ?? input.requestReceivedAt ?? timestamp)
83
+ };
84
+ const metaData = {
85
+ ...normalizedEventData,
86
+ requestId: input.requestId,
87
+ timestamp,
88
+ eventType: input.eventType,
89
+ requestFrom: input.requestFrom ?? "3",
90
+ clientId: input.clientId,
91
+ workspaceId: input.workspaceId,
92
+ token: input.token,
93
+ anonymousId: eventData.anonymousId ?? input.anonymousId,
94
+ sessionId: eventData.sessionId ?? input.sessionId,
95
+ ua: input.ua,
96
+ appDetails: { app_id: input.appId },
97
+ page: { ...page2, url: page2.url ?? input.pageUrl },
98
+ requestSentAt: normalizedEventData.requestSentAt,
99
+ requestReceivedAt: normalizedEventData.requestReceivedAt
64
100
  };
65
- if (config.apiHost !== void 0) legacyConfig.api_host = config.apiHost;
66
- if (config.uiHost !== void 0) legacyConfig.ui_host = config.uiHost;
67
- if (config.deeplink !== void 0) legacyConfig.deeplink = config.deeplink;
68
- if (config.debug !== void 0) legacyConfig.debug = config.debug;
69
- if (config.consent !== void 0) legacyConfig.consent = config.consent;
70
- if (config.gdprConsent !== void 0) legacyConfig.gdprConsent = config.gdprConsent;
71
- if (config.autocapture !== void 0) legacyConfig.autocapture = config.autocapture;
72
- if (config.capturePageview !== void 0) legacyConfig.capture_pageview = config.capturePageview;
73
- if (config.capturePageleave !== void 0) legacyConfig.capture_pageleave = config.capturePageleave;
74
- if (config.captureDeadClicks !== void 0) legacyConfig.capture_dead_clicks = config.captureDeadClicks;
75
- if (config.crossSubdomainCookie !== void 0) legacyConfig.cross_subdomain_cookie = config.crossSubdomainCookie;
76
- if (config.disablePersistence !== void 0) legacyConfig.disable_persistence = config.disablePersistence;
77
- if (config.disableSurveys !== void 0) legacyConfig.disable_surveys = config.disableSurveys;
78
- if (config.disableSessionRecording !== void 0) legacyConfig.disable_session_recording = config.disableSessionRecording;
79
- if (config.enableHeatmaps !== void 0) legacyConfig.enable_heatmaps = config.enableHeatmaps;
80
- if (config.maskAllText !== void 0) legacyConfig.mask_all_text = config.maskAllText;
81
- if (config.maskAllElementAttributes !== void 0) {
82
- legacyConfig.mask_all_element_attributes = config.maskAllElementAttributes;
83
- }
84
- if (config.persistence !== void 0) legacyConfig.persistence = config.persistence;
85
- if (config.propertyDenylist !== void 0) legacyConfig.property_denylist = config.propertyDenylist;
86
- if (config.sessionIdleTimeoutSeconds !== void 0) {
87
- legacyConfig.session_idle_timeout_seconds = config.sessionIdleTimeoutSeconds;
88
- }
89
- if (config.beforeSend !== void 0) legacyConfig.before_send = config.beforeSend;
90
- return legacyConfig;
101
+ const payload = { metaData };
102
+ return cleanObject(payload);
91
103
  }
92
104
 
93
105
  // src/core/environment.ts
94
- function isBrowserRuntime() {
95
- return typeof window !== "undefined" && typeof document !== "undefined";
96
- }
97
106
  function getBrowserWindow() {
98
107
  return typeof window === "undefined" ? void 0 : window;
99
108
  }
@@ -153,8 +162,9 @@ function stableStringify(value) {
153
162
  );
154
163
  }
155
164
  function createIdempotencyKey(payload, messageId) {
156
- const event = String(payload.event ?? payload.type ?? "event");
157
- const properties = payload.properties;
165
+ const metaData = payload.metaData;
166
+ const event = String(metaData?.eventType ?? payload.event ?? payload.type ?? "event");
167
+ const properties = metaData ?? payload.properties;
158
168
  const orderId = properties?.orderId ?? properties?.order_id ?? properties?.transaction_id;
159
169
  if (orderId !== void 0) return `${event}:${String(orderId)}`;
160
170
  return `${event}:${stableStringify(properties ?? {}) || messageId}`;
@@ -255,7 +265,17 @@ function createDeliveryManager(config) {
255
265
  persistQueue();
256
266
  }
257
267
  function withEnvelope(payload) {
258
- const messageId = String(payload.messageId ?? createId("msg"));
268
+ const metaData = payload.metaData;
269
+ const messageId = String(metaData?.requestId ?? payload.messageId ?? createId("msg"));
270
+ if (metaData) {
271
+ return {
272
+ ...payload,
273
+ metaData: {
274
+ ...metaData,
275
+ requestId: messageId
276
+ }
277
+ };
278
+ }
259
279
  return {
260
280
  ...payload,
261
281
  messageId,
@@ -281,7 +301,7 @@ function createDeliveryManager(config) {
281
301
  const body = withEnvelope(payload);
282
302
  if (payloadByteLength(body) > maxPayloadBytes) {
283
303
  recordDrop({
284
- messageId: String(body.messageId),
304
+ messageId: String(body.metaData?.requestId ?? body.messageId),
285
305
  reason: "payload_too_large",
286
306
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
287
307
  });
@@ -294,7 +314,7 @@ function createDeliveryManager(config) {
294
314
  const deliveryError = error instanceof Error ? error : new Error(String(error));
295
315
  recordError(deliveryError);
296
316
  enqueue({
297
- messageId: String(body.messageId),
317
+ messageId: String(body.metaData?.requestId ?? body.messageId),
298
318
  savedAt: Date.now(),
299
319
  attempts: 1,
300
320
  lastError: deliveryError.message,
@@ -469,6 +489,12 @@ function endpointFromConfig(config) {
469
489
  const host = config.apiHost ?? "https://sdk.drivemetadata.com/v2";
470
490
  return `${host.replace(/\/$/, "")}/data-collector`;
471
491
  }
492
+ function requireConfigString(value, field) {
493
+ if (typeof value !== "string" || value.trim() === "") {
494
+ throw new Error(`DMD SDK config ${field} is required`);
495
+ }
496
+ return value;
497
+ }
472
498
  function getBrowserStorage() {
473
499
  const browserWindow = getBrowserWindow();
474
500
  try {
@@ -483,6 +509,10 @@ var DriveMetaDataSDK = class {
483
509
  this.queue = [];
484
510
  this.offline = false;
485
511
  this.droppedEvents = 0;
512
+ requireConfigString(config.clientId, "clientId");
513
+ requireConfigString(config.workspaceId, "workspaceId");
514
+ requireConfigString(config.appId, "appId");
515
+ requireConfigString(config.writeKey || config.token, "writeKey or token");
486
516
  this.config = config;
487
517
  this.endpoint = endpointFromConfig(config);
488
518
  const storage = getBrowserStorage();
@@ -506,6 +536,7 @@ var DriveMetaDataSDK = class {
506
536
  this.maxRetryDelayMs = config.delivery?.maxRetryDelayMs ?? 3e4;
507
537
  this.writeKey = config.writeKey || config.token || "";
508
538
  this.identity = { anonymousId: createId2("anon") };
539
+ this.sessionId = createId2("session");
509
540
  this.consentState = normalizeConsent(config.gdprConsent ?? config.consent);
510
541
  this.gdprConsent = this.consentState.analytics;
511
542
  if (!config.delivery?.disableLifecycleFlush) {
@@ -651,7 +682,8 @@ var DriveMetaDataSDK = class {
651
682
  workspaceId: this.config.workspaceId,
652
683
  appId: this.config.appId,
653
684
  writeKey: this.writeKey,
654
- consent: this.consentState
685
+ consent: this.consentState,
686
+ sessionId: this.sessionId
655
687
  };
656
688
  if (this.identity.userId !== void 0) prepared.userId = this.identity.userId;
657
689
  if (this.identity.groupId !== void 0) prepared.groupId = this.identity.groupId;
@@ -675,7 +707,31 @@ var DriveMetaDataSDK = class {
675
707
  if (!validation.ok) {
676
708
  this.lastError = `DMD SDK schema warning: ${validation.errors.join(", ")}`;
677
709
  }
678
- this.sendEvent(prepared);
710
+ this.sendEvent(this.toCollectorPayload(prepared));
711
+ }
712
+ toCollectorPayload(prepared) {
713
+ const browserWindow = getBrowserWindow();
714
+ return createBackendCollectorPayload({
715
+ requestId: prepared.messageId,
716
+ timestamp: prepared.timestamp,
717
+ eventType: prepared.event,
718
+ clientId: prepared.clientId,
719
+ workspaceId: prepared.workspaceId,
720
+ token: prepared.writeKey,
721
+ anonymousId: prepared.anonymousId,
722
+ sessionId: prepared.sessionId,
723
+ ua: browserWindow?.navigator?.userAgent,
724
+ appId: prepared.appId,
725
+ pageUrl: browserWindow?.location?.href,
726
+ eventData: {
727
+ ...prepared.properties,
728
+ anonymousId: prepared.anonymousId,
729
+ sessionId: prepared.sessionId,
730
+ timestamp: prepared.timestamp,
731
+ requestSentAt: prepared.timestamp,
732
+ requestReceivedAt: prepared.timestamp
733
+ }
734
+ });
679
735
  }
680
736
  recordDrop(type, reason, event) {
681
737
  this.droppedEvents += 1;
@@ -689,22 +745,6 @@ var DriveMetaDataSDK = class {
689
745
  }
690
746
  };
691
747
 
692
- // src/browser/legacy-loader.ts
693
- function getLegacySdkInstanceFromWindow() {
694
- const browserWindow = getBrowserWindow();
695
- return browserWindow?.__DriveMetaDataSDKInstance;
696
- }
697
- function ensureLegacySdkLoaded() {
698
- if (!isBrowserRuntime()) {
699
- throw new Error("DMD legacy SDK is only available in a browser runtime");
700
- }
701
- const browserWindow = getBrowserWindow();
702
- if (!browserWindow?.DriveMetaDataSDK) {
703
- throw new Error("DMD legacy SDK constructor is missing from window.DriveMetaDataSDK");
704
- }
705
- return browserWindow.DriveMetaDataSDK;
706
- }
707
-
708
748
  // src/browser/client.ts
709
749
  var singleton;
710
750
  var publicSingleton;
@@ -713,56 +753,34 @@ var lastError;
713
753
  var lastDroppedEvent;
714
754
  function createPublicClient(instance) {
715
755
  return {
716
- __legacy: instance,
717
756
  track(event, properties, options) {
718
- if (instance.trackEvent) {
719
- instance.trackEvent(event, properties, options);
720
- return;
721
- }
722
- instance.sendEvent?.({ eventName: event, event, properties, options });
757
+ instance.trackEvent(event, properties, options);
723
758
  },
724
759
  identify(userId, traits, options) {
725
- if (instance.identify) {
726
- instance.identify(userId, traits, options);
727
- return;
728
- }
729
- instance.identifyUser?.(userId, traits);
760
+ instance.identify(userId, traits, options);
730
761
  },
731
762
  page(name, properties, options) {
732
- if (instance.page) {
733
- instance.page(name, properties, options);
734
- return;
735
- }
736
- instance.trackPageview?.();
763
+ instance.page(name, properties, options);
737
764
  },
738
765
  group(groupId, traits, options) {
739
- instance.group?.(groupId, traits, options);
766
+ instance.group(groupId, traits, options);
740
767
  },
741
768
  alias(previousId, userId, options) {
742
- instance.alias?.(previousId, userId, options);
769
+ instance.alias(previousId, userId, options);
743
770
  },
744
771
  async flush() {
745
- await instance.flush?.();
772
+ await instance.flush();
746
773
  },
747
774
  reset() {
748
- instance.reset?.();
775
+ instance.reset();
749
776
  singleton = void 0;
750
777
  publicSingleton = void 0;
751
778
  },
752
779
  setConsent(consent) {
753
- if (instance.setConsent) {
754
- instance.setConsent(consent);
755
- return;
756
- }
757
- if (typeof consent === "string") {
758
- instance.gdprConsent = consent;
759
- }
780
+ instance.setConsent(consent);
760
781
  },
761
782
  getHealth() {
762
- if (instance.getHealth) {
763
- return instance.getHealth();
764
- }
765
- return getDmdHealth();
783
+ return instance.getHealth();
766
784
  }
767
785
  };
768
786
  }
@@ -787,23 +805,8 @@ function initDmdSDK(config) {
787
805
  if (publicSingleton) {
788
806
  return publicSingleton;
789
807
  }
790
- const legacyConfig = normalizeBrowserConfig(config);
791
- const existingInstance = getLegacySdkInstanceFromWindow();
792
- if (existingInstance) {
793
- return setSingleton(existingInstance);
794
- }
795
808
  try {
796
- let instance;
797
- try {
798
- const LegacySdk = ensureLegacySdkLoaded();
799
- instance = new LegacySdk(legacyConfig);
800
- } catch (error) {
801
- if (error instanceof Error && error.message.includes("constructor is missing")) {
802
- instance = new DriveMetaDataSDK(config);
803
- } else {
804
- throw error;
805
- }
806
- }
809
+ const instance = new DriveMetaDataSDK(config);
807
810
  return setSingleton(instance);
808
811
  } catch (error) {
809
812
  lastError = error instanceof Error ? error.message : String(error);
@@ -870,14 +873,14 @@ function setConsent(consent) {
870
873
  getDmdSDK()?.setConsent(consent);
871
874
  }
872
875
  function getDmdHealth() {
873
- if (singleton?.getHealth) {
876
+ if (singleton) {
874
877
  return singleton.getHealth();
875
878
  }
876
879
  const health = {
877
- initialized: Boolean(singleton?.initialized ?? singleton),
878
- consent: singleton?.gdprConsent ?? "pending",
879
- queueSize: singleton?.queue?.length ?? 0,
880
- offline: Boolean(singleton?.offline),
880
+ initialized: false,
881
+ consent: "pending",
882
+ queueSize: 0,
883
+ offline: false,
881
884
  droppedEvents
882
885
  };
883
886
  if (lastError !== void 0) {
@@ -920,6 +923,7 @@ function DmdProvider({
920
923
  config.workspaceId,
921
924
  config.appId,
922
925
  config.writeKey,
926
+ config.token,
923
927
  config.apiHost,
924
928
  config.consent,
925
929
  config.gdprConsent,