@drivemetadata-ai/sdk 0.1.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +241 -0
  4. package/dist/angular/index.cjs +1675 -0
  5. package/dist/angular/index.cjs.map +1 -0
  6. package/dist/angular/index.d.cts +26 -0
  7. package/dist/angular/index.d.ts +26 -0
  8. package/dist/angular/index.js +1649 -0
  9. package/dist/angular/index.js.map +1 -0
  10. package/dist/browser/index.cjs +1635 -0
  11. package/dist/browser/index.cjs.map +1 -0
  12. package/dist/browser/index.d.cts +21 -0
  13. package/dist/browser/index.d.ts +21 -0
  14. package/dist/browser/index.js +1595 -0
  15. package/dist/browser/index.js.map +1 -0
  16. package/dist/next/index.cjs +1693 -0
  17. package/dist/next/index.cjs.map +1 -0
  18. package/dist/next/index.d.cts +18 -0
  19. package/dist/next/index.d.ts +18 -0
  20. package/dist/next/index.js +1650 -0
  21. package/dist/next/index.js.map +1 -0
  22. package/dist/node/index.cjs +384 -0
  23. package/dist/node/index.cjs.map +1 -0
  24. package/dist/node/index.d.cts +91 -0
  25. package/dist/node/index.d.ts +91 -0
  26. package/dist/node/index.js +354 -0
  27. package/dist/node/index.js.map +1 -0
  28. package/dist/react/index.cjs +1721 -0
  29. package/dist/react/index.cjs.map +1 -0
  30. package/dist/react/index.d.cts +26 -0
  31. package/dist/react/index.d.ts +26 -0
  32. package/dist/react/index.js +1674 -0
  33. package/dist/react/index.js.map +1 -0
  34. package/dist/types-mgbdL1V7.d.cts +123 -0
  35. package/dist/types-mgbdL1V7.d.ts +123 -0
  36. package/docs/angular-integration.md +106 -0
  37. package/docs/architecture.md +109 -0
  38. package/docs/index.md +18 -0
  39. package/docs/integration.md +520 -0
  40. package/docs/node-server-integration.md +147 -0
  41. package/docs/npm-browser-sdk.md +143 -0
  42. package/docs/react-next-integration.md +168 -0
  43. package/docs/security-privacy.md +128 -0
  44. package/package.json +101 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Added npm package foundation.
6
+ - Added browser SDK facade.
7
+ - Added React adapter.
8
+ - Added Next.js adapter.
9
+ - Added Angular adapter.
10
+ - Added Node/server SDK.
11
+ - Added diagnostics and release validation.
12
+ - Preserved existing JavaScript/CDN SDK compatibility.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DriveMetaData
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # DriveMetaData SDK
2
+
3
+ Enterprise-grade analytics, behavior intelligence, and customer data collection SDK for browser apps, React, Next.js, Angular, and Node.js.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @drivemetadata-ai/sdk
9
+ ```
10
+
11
+ For private beta installs, pin the beta tag:
12
+
13
+ ```bash
14
+ npm install @drivemetadata-ai/sdk@beta
15
+ ```
16
+
17
+ ## Runtime Entries
18
+
19
+ | Runtime | Import path | Use for |
20
+ |---|---|---|
21
+ | Browser | `@drivemetadata-ai/sdk/browser` | Plain JavaScript and browser applications |
22
+ | React | `@drivemetadata-ai/sdk/react` | React provider and hooks |
23
+ | Next.js | `@drivemetadata-ai/sdk/next` | App Router and Pages Router client helpers |
24
+ | Angular | `@drivemetadata-ai/sdk/angular` | Angular provider and injectable service |
25
+ | Node.js | `@drivemetadata-ai/sdk/node` | Backend/server events only |
26
+
27
+ Do not import `@drivemetadata-ai/sdk/node` from frontend bundles. Browser, React, Next.js, and Angular integrations use public browser tokens. Node integrations use server tokens from backend-only environment variables.
28
+
29
+ ## Required Browser Config
30
+
31
+ Use camelCase config keys in npm integrations:
32
+
33
+ ```ts
34
+ const config = {
35
+ clientId: 'client_xxx',
36
+ workspaceId: 'workspace_xxx',
37
+ appId: 'app_xxx',
38
+ token: 'public_browser_token',
39
+ consent: { analytics: 'pending', advertising: 'denied' }
40
+ };
41
+ ```
42
+
43
+ `token` is the public browser write key. It is sent to the backend as `metaData.token`.
44
+
45
+ ## Browser Quick Start
46
+
47
+ ```ts
48
+ import { consent, flush, getDmdHealth, identify, initDmdSDK, page, track } from '@drivemetadata-ai/sdk/browser';
49
+
50
+ initDmdSDK({
51
+ clientId: 'client_xxx',
52
+ workspaceId: 'workspace_xxx',
53
+ appId: 'app_xxx',
54
+ token: 'public_browser_token',
55
+ consent: {
56
+ analytics: 'pending',
57
+ advertising: 'denied',
58
+ personalization: 'denied',
59
+ functional: 'granted',
60
+ saleOfData: 'denied'
61
+ }
62
+ });
63
+
64
+ consent.update({ analytics: 'granted' });
65
+
66
+ identify('user_123', { plan: 'enterprise' });
67
+ page('Product Page');
68
+ track('Product Viewed', { productId: 'sku_123' });
69
+
70
+ await flush();
71
+ console.log(getDmdHealth());
72
+ ```
73
+
74
+ Browser events automatically include backend `metaData` fields such as `requestId`, `anonymousId`, `sessionId`, timestamps, attribution/UTM enrichment, and page context.
75
+
76
+ ## React
77
+
78
+ ```tsx
79
+ import { DmdProvider, useDmdConsent, useDmdFlush, useIdentify, useTrackEvent } from '@drivemetadata-ai/sdk/react';
80
+
81
+ function ProductButton() {
82
+ const track = useTrackEvent();
83
+ const identify = useIdentify();
84
+ const flush = useDmdFlush();
85
+ const consent = useDmdConsent();
86
+
87
+ async function onClick() {
88
+ consent({ analytics: 'granted' });
89
+ identify('user_123', { plan: 'enterprise' });
90
+ track('Product Clicked', { productId: 'sku_123' });
91
+ await flush();
92
+ }
93
+
94
+ return <button onClick={onClick}>Track</button>;
95
+ }
96
+
97
+ export function App() {
98
+ return (
99
+ <DmdProvider
100
+ config={{
101
+ clientId: 'client_xxx',
102
+ workspaceId: 'workspace_xxx',
103
+ appId: 'app_xxx',
104
+ token: 'public_browser_token',
105
+ consent: { analytics: 'pending', advertising: 'denied' }
106
+ }}
107
+ >
108
+ <ProductButton />
109
+ </DmdProvider>
110
+ );
111
+ }
112
+ ```
113
+
114
+ ## Next.js
115
+
116
+ Use `@drivemetadata-ai/sdk/next` from a client component.
117
+
118
+ ```tsx
119
+ 'use client';
120
+
121
+ import { DmdProvider, useDmdAppRouterPageTracking } from '@drivemetadata-ai/sdk/next';
122
+ import { usePathname, useSearchParams } from 'next/navigation';
123
+ import type { ReactNode } from 'react';
124
+
125
+ function RouteTracking() {
126
+ const pathname = usePathname();
127
+ const searchParams = useSearchParams();
128
+ useDmdAppRouterPageTracking(pathname, searchParams.toString());
129
+ return null;
130
+ }
131
+
132
+ export function AnalyticsProvider({ children }: { children: ReactNode }) {
133
+ return (
134
+ <DmdProvider
135
+ config={{
136
+ clientId: process.env.NEXT_PUBLIC_DMD_CLIENT_ID!,
137
+ workspaceId: process.env.NEXT_PUBLIC_DMD_WORKSPACE_ID!,
138
+ appId: process.env.NEXT_PUBLIC_DMD_APP_ID!,
139
+ token: process.env.NEXT_PUBLIC_DMD_TOKEN!,
140
+ consent: { analytics: 'pending', advertising: 'denied' }
141
+ }}
142
+ >
143
+ <RouteTracking />
144
+ {children}
145
+ </DmdProvider>
146
+ );
147
+ }
148
+ ```
149
+
150
+ ## Angular
151
+
152
+ ```ts
153
+ import { DmdAnalyticsService, provideDmdAnalytics } from '@drivemetadata-ai/sdk/angular';
154
+
155
+ export const appConfig = {
156
+ providers: [
157
+ provideDmdAnalytics({
158
+ clientId: 'client_xxx',
159
+ workspaceId: 'workspace_xxx',
160
+ appId: 'app_xxx',
161
+ token: 'public_browser_token',
162
+ consent: { analytics: 'pending', advertising: 'denied' }
163
+ })
164
+ ]
165
+ };
166
+ ```
167
+
168
+ Call `DmdAnalyticsService.init()` only in the browser when using Angular Universal/SSR.
169
+
170
+ ## Node.js
171
+
172
+ ```ts
173
+ import { createDmdServerClient } from '@drivemetadata-ai/sdk/node';
174
+
175
+ const dmd = createDmdServerClient({
176
+ clientId: 'client_xxx',
177
+ workspaceId: 'workspace_xxx',
178
+ appId: 'app_xxx',
179
+ token: process.env.DMD_SERVER_TOKEN!,
180
+ timeoutMs: 5000,
181
+ retry: {
182
+ attempts: 3,
183
+ minDelayMs: 250,
184
+ maxDelayMs: 2000
185
+ }
186
+ });
187
+
188
+ await dmd.track({
189
+ userId: 'user_123',
190
+ event: 'Order Completed',
191
+ idempotencyKey: 'order_123',
192
+ properties: {
193
+ amount: 500,
194
+ currency: 'USD'
195
+ }
196
+ });
197
+ ```
198
+
199
+ ## Default Page Context
200
+
201
+ Browser, React, Next.js, and Angular integrations automatically add page context to each collector payload:
202
+
203
+ ```json
204
+ {
205
+ "metaData": {
206
+ "page": {
207
+ "url": "https://example.com/products/sku-123?utm_source=paid",
208
+ "path": "/products/sku-123",
209
+ "search": "?utm_source=paid",
210
+ "title": "Product Detail",
211
+ "referrer": "https://google.com/search?q=%5BREDACTED%5D"
212
+ }
213
+ }
214
+ }
215
+ ```
216
+
217
+ Query strings in `search` and `referrer` are redacted by default except common attribution parameters.
218
+
219
+ ## Diagnostics
220
+
221
+ ```ts
222
+ import { flush, getDmdHealth } from '@drivemetadata-ai/sdk/browser';
223
+
224
+ console.log(getDmdHealth());
225
+ await flush();
226
+ ```
227
+
228
+ Useful drop reasons include `consent_denied`, `payload_too_large`, `queue_limit_exceeded`, and `queue_ttl_expired`.
229
+
230
+ ## Documentation
231
+
232
+ - Complete integration guide: `docs/integration.md`
233
+ - Browser npm SDK: `docs/npm-browser-sdk.md`
234
+ - React and Next.js: `docs/react-next-integration.md`
235
+ - Angular: `docs/angular-integration.md`
236
+ - Node/server: `docs/node-server-integration.md`
237
+ - Security and privacy: `docs/security-privacy.md`
238
+
239
+ ## License
240
+
241
+ MIT