deepspotscreen-sdk 0.0.1

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 (41) hide show
  1. package/README.md +485 -0
  2. package/dist/DeepspotSDK-CyX06_c2.js +1486 -0
  3. package/dist/DeepspotSDK-g7o9tAip.cjs +546 -0
  4. package/dist/_commonjsHelpers-MeVG4QFm.cjs +1 -0
  5. package/dist/_commonjsHelpers-bAxELxBV.js +8 -0
  6. package/dist/apexcharts.common-DGzslxI3.cjs +808 -0
  7. package/dist/apexcharts.common-k3hLWpB8.js +8956 -0
  8. package/dist/components/DashboardElement.d.ts +18 -0
  9. package/dist/components/ReportElement.d.ts +15 -0
  10. package/dist/core/ApiClient.d.ts +41 -0
  11. package/dist/core/DeepspotSDK.d.ts +11 -0
  12. package/dist/core/EmbedInstance.d.ts +46 -0
  13. package/dist/deepspot-sdk.esm.js +1704 -0
  14. package/dist/deepspot-sdk.js +1655 -0
  15. package/dist/html2canvas.esm-CzwMv54K.js +4870 -0
  16. package/dist/html2canvas.esm-EoNFmhrp.cjs +22 -0
  17. package/dist/index.d.ts +146 -0
  18. package/dist/index.es-C-ai08UC.js +5632 -0
  19. package/dist/index.es-ELJ1Oc0z.cjs +18 -0
  20. package/dist/index.es-TiU5c3LF.js +5632 -0
  21. package/dist/jspdf.es.min-D6GjoB2T.cjs +243 -0
  22. package/dist/jspdf.es.min-Ge0fRUwj.js +8107 -0
  23. package/dist/jspdf.es.min-d9hlG26J.js +8107 -0
  24. package/dist/layout/GridLayout.d.ts +25 -0
  25. package/dist/purify.es-CuxL4pit.js +471 -0
  26. package/dist/purify.es-D_pYQKft.cjs +3 -0
  27. package/dist/react/index.cjs +1 -0
  28. package/dist/react/index.d.ts +33 -0
  29. package/dist/react/index.mjs +188 -0
  30. package/dist/renderer/CardRenderer.d.ts +6 -0
  31. package/dist/renderer/ChartRenderer.d.ts +19 -0
  32. package/dist/renderer/DashboardRenderer.d.ts +64 -0
  33. package/dist/renderer/FilterRenderer.d.ts +20 -0
  34. package/dist/renderer/ReportRenderer.d.ts +14 -0
  35. package/dist/renderer/TableRenderer.d.ts +8 -0
  36. package/dist/types.d.ts +140 -0
  37. package/dist/utils.d.ts +4 -0
  38. package/dist/vue/index.cjs +1 -0
  39. package/dist/vue/index.d.ts +212 -0
  40. package/dist/vue/index.mjs +138 -0
  41. package/package.json +69 -0
package/README.md ADDED
@@ -0,0 +1,485 @@
1
+ # Deepspot Embedded Analytics SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/deepspotscreen-sdk?color=blue&label=npm)](https://www.npmjs.com/package/deepspotscreen-sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue?logo=typescript)](https://www.typescriptlang.org/)
6
+ [![Vite](https://img.shields.io/badge/Built%20with-Vite-646cff?logo=vite)](https://vitejs.dev/)
7
+
8
+ Embed Deepspot dashboards and reports into **any website or framework** — React, Next.js, Vue, Angular, Svelte, or plain HTML — with a single import or script tag.
9
+
10
+ ---
11
+
12
+ ## Why Deepspot SDK?
13
+
14
+ | Feature | Details |
15
+ |---|---|
16
+ | **No iframe** | Renders directly in your page DOM — full CSS control |
17
+ | **Self-contained** | ApexCharts, html2canvas, jsPDF all bundled in |
18
+ | **Lazy loading** | Only the active tab's SQL queries execute |
19
+ | **Row-level security** | Pass a `userId` to scope data per end-user |
20
+ | **React & Vue** | Drop-in components with full TypeScript types |
21
+ | **Next.js ready** | SSR-safe, works with App Router and Pages Router |
22
+ | **CDN friendly** | Single UMD file — works with a `<script>` tag |
23
+
24
+ ---
25
+
26
+ ## Table of Contents
27
+
28
+ - [Installation](#installation)
29
+ - [Quick Start](#quick-start)
30
+ - [React / Next.js (App Router)](#react--nextjs-app-router)
31
+ - [Next.js (Pages Router)](#nextjs-pages-router)
32
+ - [Vue 3 / Nuxt](#vue-3--nuxt)
33
+ - [Plain HTML (CDN)](#plain-html-cdn)
34
+ - [Angular / Svelte / Vanilla JS](#angular--svelte--vanilla-js)
35
+ - [API Reference](#api-reference)
36
+ - [React Props](#react-component-props)
37
+ - [Vue Props](#vue-component-props)
38
+ - [Web Component Attributes](#html-web-component-attributes)
39
+ - [JavaScript API](#javascript-api-programmatic-control)
40
+ - [Embed Levels](#embed-levels)
41
+ - [Supported Component Types](#supported-component-types)
42
+ - [Environment Variables](#environment-variables-nextjs)
43
+ - [Security](#security)
44
+ - [Building from Source](#building-from-source)
45
+ - [Troubleshooting](#troubleshooting)
46
+ - [License](#license)
47
+
48
+ ---
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ # npm
54
+ npm install deepspotscreen-sdk
55
+
56
+ # pnpm
57
+ pnpm add deepspotscreen-sdk
58
+
59
+ # yarn
60
+ yarn add deepspotscreen-sdk
61
+ ```
62
+
63
+ > **Peer dependencies** — React and Vue are optional peer deps. Install only what your project uses.
64
+
65
+ ---
66
+
67
+ ## Quick Start
68
+
69
+ ### React / Next.js (App Router)
70
+
71
+ ```tsx
72
+ 'use client' // required for Next.js App Router
73
+ import { DeepspotDashboard } from 'deepspotscreen-sdk/react'
74
+
75
+ export default function AnalyticsPage() {
76
+ return (
77
+ <DeepspotDashboard
78
+ apiKey="sk_live_b74c55..."
79
+ baseUrl="https://api.deepspot.ai"
80
+ dashboardId="dashboard_123"
81
+ embedLevel="dashboard"
82
+ userId="user_456"
83
+ theme="light"
84
+ height="600px"
85
+ onReady={() => console.log('Dashboard loaded')}
86
+ onFilterChange={(filters) => console.log('Filters changed:', filters)}
87
+ onError={(err) => console.error('Embed error:', err)}
88
+ />
89
+ )
90
+ }
91
+ ```
92
+
93
+ ### Next.js (Pages Router)
94
+
95
+ ```tsx
96
+ import dynamic from 'next/dynamic'
97
+
98
+ // SSR must be disabled — the SDK uses browser APIs
99
+ const DeepspotDashboard = dynamic(
100
+ () => import('deepspotscreen-sdk/react').then(m => m.DeepspotDashboard),
101
+ { ssr: false }
102
+ )
103
+
104
+ export default function Page() {
105
+ return (
106
+ <DeepspotDashboard
107
+ apiKey={process.env.NEXT_PUBLIC_DEEPSPOT_API_KEY!}
108
+ baseUrl={process.env.NEXT_PUBLIC_DEEPSPOT_BASE_URL!}
109
+ dashboardId={process.env.NEXT_PUBLIC_DEEPSPOT_DASHBOARD_ID!}
110
+ embedLevel="dashboard"
111
+ userId="user_456"
112
+ height="600px"
113
+ />
114
+ )
115
+ }
116
+ ```
117
+
118
+ ### Vue 3 / Nuxt
119
+
120
+ ```vue
121
+ <script setup lang="ts">
122
+ import { DeepspotDashboard } from 'deepspotscreen-sdk/vue'
123
+ </script>
124
+
125
+ <template>
126
+ <DeepspotDashboard
127
+ api-key="sk_live_b74c55..."
128
+ base-url="https://api.deepspot.ai"
129
+ dashboard-id="dashboard_123"
130
+ embed-level="dashboard"
131
+ :user-id="currentUser.id"
132
+ theme="light"
133
+ height="600px"
134
+ @ready="onLoaded"
135
+ @filter-change="onFiltersChanged"
136
+ @error="onError"
137
+ />
138
+ </template>
139
+ ```
140
+
141
+ ### Plain HTML (CDN)
142
+
143
+ ```html
144
+ <!-- Load once in <head> — pinned to the version you tested with -->
145
+ <script src="https://unpkg.com/deepspotscreen-sdk@0.0.1/dist/deepspot-sdk.js"></script>
146
+
147
+ <!-- Place the element where the dashboard should appear -->
148
+ <deepspot-dashboard
149
+ dashboard-id="dashboard_123"
150
+ api-key="sk_live_b74c55..."
151
+ base-url="https://api.deepspot.ai"
152
+ user-id="user_456"
153
+ embed-level="dashboard"
154
+ theme="light"
155
+ height="600px"
156
+ ></deepspot-dashboard>
157
+ ```
158
+
159
+ ### Angular / Svelte / Vanilla JS
160
+
161
+ ```typescript
162
+ import { DeepspotSDK } from 'deepspotscreen-sdk'
163
+
164
+ const sdk = new DeepspotSDK({
165
+ apiKey: 'sk_live_b74c55...',
166
+ baseUrl: 'https://api.deepspot.ai',
167
+ })
168
+
169
+ const dash = await sdk.embedDashboard({
170
+ dashboardId: 'dashboard_123',
171
+ container: document.getElementById('analytics')!,
172
+ userId: currentUser.id,
173
+ theme: 'light',
174
+ height: '600px',
175
+ })
176
+ ```
177
+
178
+ ---
179
+
180
+ ## API Reference
181
+
182
+ ### React Component Props
183
+
184
+ #### `<DeepspotDashboard>`
185
+
186
+ | Prop | Type | Required | Default | Description |
187
+ |---|---|---|---|---|
188
+ | `apiKey` | `string` | ✅ | — | `sk_live_...` key from Embed & Share page |
189
+ | `baseUrl` | `string` | ✅ | — | Your Deepspot backend URL |
190
+ | `dashboardId` | `string` | ✅ | — | Dashboard ID from Deepspot |
191
+ | `embedLevel` | `string` | | `"dashboard"` | `"dashboard"` / `"page"` / `"tab"` / `"report"` |
192
+ | `userId` | `string` | | `""` | End-user ID for row-level security |
193
+ | `tenantId` | `string` | | — | Tenant ID for multi-tenant apps |
194
+ | `pageId` | `string` | | first page | Starting page ID |
195
+ | `tabId` | `string` | | first tab | Starting tab ID |
196
+ | `theme` | `string` | | `"light"` | `"light"` or `"dark"` |
197
+ | `height` | `string` | | `"600px"` | CSS height value (e.g. `"800px"`, `"100vh"`) |
198
+ | `hideFilters` | `boolean` | | `false` | Hide the filter bar |
199
+ | `hideExport` | `boolean` | | `false` | Hide export buttons |
200
+ | `filters` | `object` | | `{}` | Initial filter values |
201
+ | `className` | `string` | | — | CSS class for the wrapper `div` |
202
+ | `style` | `CSSProperties` | | — | Inline styles for the wrapper `div` |
203
+ | `loadingNode` | `ReactElement` | | built-in spinner | Custom loading indicator |
204
+ | `onReady` | `() => void` | | — | Fires when dashboard finishes loading |
205
+ | `onFilterChange` | `(filters: object) => void` | | — | Fires when user changes a filter |
206
+ | `onTabSwitch` | `(pageId: string, tabId: string) => void` | | — | Fires when user switches tab |
207
+ | `onError` | `(message: string) => void` | | — | Fires on any load error |
208
+
209
+ #### `<DeepspotReport>` (Single Component)
210
+
211
+ Same as `<DeepspotDashboard>` but instead of `embedLevel` / `pageId` / `tabId`, pass:
212
+
213
+ | Prop | Type | Required | Description |
214
+ |---|---|---|---|
215
+ | `componentId` | `string` | ✅ | ID of the specific chart / table / KPI to embed |
216
+
217
+ ---
218
+
219
+ ### Vue Component Props
220
+
221
+ Same props as React but in **kebab-case** (`dashboard-id`, `api-key`, `base-url`, etc.).
222
+
223
+ Events emitted via `v-on` / `@`:
224
+
225
+ | Event | Payload | Description |
226
+ |---|---|---|
227
+ | `@ready` | — | Dashboard loaded successfully |
228
+ | `@filter-change` | `filters: object` | User changed a filter |
229
+ | `@tab-switch` | `{ pageId, tabId }` | User switched tab |
230
+ | `@error` | `message: string` | Load error occurred |
231
+
232
+ ---
233
+
234
+ ### HTML Web Component Attributes
235
+
236
+ #### `<deepspot-dashboard>`
237
+
238
+ | Attribute | Required | Default | Description |
239
+ |---|---|---|---|
240
+ | `dashboard-id` | ✅ | — | Dashboard ID |
241
+ | `api-key` | ✅ | — | `sk_live_...` key |
242
+ | `base-url` | ✅ | — | Backend URL |
243
+ | `user-id` | | `""` | End-user ID |
244
+ | `embed-level` | | `"dashboard"` | `"dashboard"` / `"page"` / `"tab"` / `"report"` |
245
+ | `page-id` | | first page | Starting page |
246
+ | `tab-id` | | first tab | Starting tab |
247
+ | `theme` | | `"light"` | `"light"` or `"dark"` |
248
+ | `height` | | `"600px"` | CSS height |
249
+ | `hide-filters` | | `"false"` | Set to `"true"` to hide filter bar |
250
+ | `hide-export` | | `"false"` | Set to `"true"` to hide export buttons |
251
+
252
+ #### `<deepspot-report>`
253
+
254
+ | Attribute | Required | Description |
255
+ |---|---|---|
256
+ | `dashboard-id` | ✅ | Dashboard that owns this component |
257
+ | `component-id` | ✅ | ID of the specific component to embed |
258
+ | `api-key` | ✅ | API key |
259
+ | `base-url` | ✅ | Backend URL |
260
+ | `user-id` | | End-user ID |
261
+ | `theme` | | `"light"` or `"dark"` |
262
+ | `height` | | CSS height |
263
+
264
+ ---
265
+
266
+ ### JavaScript API (Programmatic Control)
267
+
268
+ ```typescript
269
+ import { DeepspotSDK } from 'deepspotscreen-sdk'
270
+
271
+ const sdk = new DeepspotSDK({
272
+ apiKey: 'sk_live_b74c55...',
273
+ baseUrl: 'https://api.deepspot.ai',
274
+ })
275
+
276
+ // Embed a full dashboard — returns an EmbedInstance
277
+ const dash = await sdk.embedDashboard({
278
+ dashboardId: 'dashboard_123',
279
+ container: '#analytics-section', // CSS selector or HTMLElement ref
280
+ userId: currentUser.id,
281
+ theme: 'dark',
282
+ filters: { region: 'US' },
283
+ onReady: () => console.log('ready'),
284
+ onFilterChange: (f) => console.log(f),
285
+ })
286
+
287
+ // Embed a single chart / KPI card
288
+ const report = await sdk.embedReport({
289
+ dashboardId: 'dashboard_123',
290
+ componentId: 'comp_revenue_chart',
291
+ container: '#revenue-widget',
292
+ userId: currentUser.id,
293
+ })
294
+
295
+ // ── EmbedInstance methods ──────────────────────────────────────────────────
296
+ dash.setFilter('region', 'EU') // apply one filter → re-fetches
297
+ dash.setFilters({ region: 'EU', year: '2024' }) // apply multiple at once
298
+ dash.goToPage('page_2') // navigate to a page
299
+ dash.goToTab('page_2', 'tab_q1') // navigate to a specific tab
300
+ dash.refresh() // force re-fetch current tab
301
+ dash.exportPDF() // download dashboard as PDF
302
+ dash.destroy() // remove from DOM and clean up
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Embed Levels
308
+
309
+ | Level | What renders | Navigation shown |
310
+ |---|---|---|
311
+ | `"report"` | 1 chart / table / KPI card | None |
312
+ | `"tab"` | All components on 1 tab | None |
313
+ | `"page"` | All tabs on 1 page | Tab switcher |
314
+ | `"dashboard"` | Full dashboard, all pages | Page nav + Tab switcher |
315
+
316
+ > All levels lazy-load — other tabs only execute SQL when the user clicks them.
317
+
318
+ ---
319
+
320
+ ## Supported Component Types
321
+
322
+ | Type | Rendered as |
323
+ |---|---|
324
+ | `bar` | Bar chart (ApexCharts) |
325
+ | `line` | Line chart (ApexCharts) |
326
+ | `area` | Area chart (ApexCharts) |
327
+ | `pie` | Pie chart (ApexCharts) |
328
+ | `donut` | Donut chart (ApexCharts) |
329
+ | `table` | Paginated HTML data table |
330
+ | `number-card` | KPI / metric card |
331
+ | `filter` | Dropdown / date-range / multi-select filter |
332
+ | `text` | Static text block |
333
+
334
+ ---
335
+
336
+ ## Environment Variables (Next.js)
337
+
338
+ Store your configuration in `.env.local` — never commit this file.
339
+
340
+ ```env
341
+ # .env.local
342
+ NEXT_PUBLIC_DEEPSPOT_API_KEY=sk_live_b74c55...
343
+ NEXT_PUBLIC_DEEPSPOT_BASE_URL=https://api.deepspot.ai
344
+ NEXT_PUBLIC_DEEPSPOT_DASHBOARD_ID=dashboard_123
345
+ NEXT_PUBLIC_DEEPSPOT_EMBED_LEVEL=dashboard
346
+ NEXT_PUBLIC_DEEPSPOT_THEME=light
347
+ NEXT_PUBLIC_DEEPSPOT_HEIGHT=600px
348
+ ```
349
+
350
+ > For production, rotate your `apiKey` regularly and prefer the [server-side token exchange](#production-best-practice) pattern.
351
+
352
+ ---
353
+
354
+ ## Security
355
+
356
+ ### Auth Flow
357
+
358
+ ```
359
+ Your website
360
+ │ POST /embed-token { apiKey, dashboardId, userId }
361
+
362
+ Deepspot Backend ──→ short-lived JWT (1-hour TTL)
363
+
364
+ │ GET /embed/:id/render { x-embed-token: <JWT> }
365
+
366
+ SQL executes server-side → pre-computed rows returned
367
+ (No SQL, no DB credentials ever reach the browser)
368
+ ```
369
+
370
+ ### Production Best Practice
371
+
372
+ Avoid exposing your `apiKey` in public HTML. Exchange it for a short-lived token on your backend:
373
+
374
+ ```typescript
375
+ // YOUR backend endpoint — e.g. POST /api/embed-token
376
+ const response = await fetch(`${DEEPSPOT_URL}/dashboard-builder/embed-token`, {
377
+ method: 'POST',
378
+ headers: {
379
+ 'Content-Type': 'application/json',
380
+ 'x-deepspot-api-key': process.env.DEEPSPOT_API_KEY, // server-side only!
381
+ },
382
+ body: JSON.stringify({ dashboardId, embedType: 'dashboard', userId }),
383
+ })
384
+ const { data: { token } } = await response.json()
385
+ // Return token to your frontend — expires in 1 hour
386
+ ```
387
+
388
+ ---
389
+
390
+ ## Building from Source
391
+
392
+ ### Prerequisites
393
+
394
+ - Node.js >= 18
395
+ - npm / pnpm / yarn
396
+
397
+ ```bash
398
+ git clone https://github.com/your-org/deepspot-sdk.git
399
+ cd deepspot-sdk
400
+
401
+ # Install dependencies
402
+ npm install
403
+
404
+ # Build main SDK bundle (UMD + ESM)
405
+ npm run build:sdk
406
+
407
+ # Build React + Vue framework wrappers
408
+ npm run build:frameworks
409
+
410
+ # Build everything in one command
411
+ npm run build
412
+
413
+ # Watch mode — rebuilds on every file change
414
+ npm run dev
415
+
416
+ # TypeScript type-check (no output)
417
+ npm run typecheck
418
+ ```
419
+
420
+ ### Build Output
421
+
422
+ ```
423
+ dist/
424
+ ├── deepspot-sdk.js ← UMD (CDN / <script> tag / CommonJS require)
425
+ ├── deepspot-sdk.esm.js ← ESM (bundler / import)
426
+ ├── index.d.ts ← TypeScript declarations (single rolled-up file)
427
+ ├── react/
428
+ │ ├── index.mjs ← ESM React wrapper
429
+ │ ├── index.cjs ← CJS React wrapper
430
+ │ └── index.d.ts
431
+ └── vue/
432
+ ├── index.mjs ← ESM Vue wrapper
433
+ ├── index.cjs ← CJS Vue wrapper
434
+ └── index.d.ts
435
+ ```
436
+
437
+ ---
438
+
439
+ ## Troubleshooting
440
+
441
+ ### Dashboard renders with a transparent / unstyled background
442
+
443
+ The SDK inlines `embed.css` at build time. If you're building from source, ensure the build completed without errors — the styles are only present in `dist/`.
444
+
445
+ ### `ReferenceError: __DS_EMBED_CSS__ is not defined`
446
+
447
+ This means the framework wrapper was built without the `define` block from [vite.frameworks.config.ts](vite.frameworks.config.ts). Both config files must include the `define: { __DS_EMBED_CSS__ }` block.
448
+
449
+ ### Next.js App Router: "document is not defined"
450
+
451
+ Add `'use client'` at the top of any file that imports from `deepspotscreen-sdk/react`. The SDK uses browser APIs and cannot run on the server.
452
+
453
+ ### Next.js Pages Router: hydration errors
454
+
455
+ Use `dynamic(..., { ssr: false })` as shown in the [Pages Router example](#nextjs-pages-router).
456
+
457
+ ### TypeScript: cannot find module `deepspotscreen-sdk/react`
458
+
459
+ Ensure `moduleResolution` in your `tsconfig.json` is set to `"bundler"`, `"node16"`, or `"nodenext"` — these modes support the `exports` field in `package.json`.
460
+
461
+ ---
462
+
463
+ ## Get Your API Key
464
+
465
+ 1. Open the Deepspot Dashboard Builder
466
+ 2. Navigate to **Publish → Embed & Share**
467
+ 3. Click **Generate Key**
468
+ 4. Copy the `sk_live_...` key — it is scoped to that specific dashboard
469
+
470
+ ---
471
+
472
+ ## Contributing
473
+
474
+ 1. Fork the repository
475
+ 2. Create a feature branch: `git checkout -b feat/my-feature`
476
+ 3. Make your changes in `src/`
477
+ 4. Run `npm run typecheck` to verify TypeScript
478
+ 5. Run `npm run build` to verify the build succeeds
479
+ 6. Open a pull request
480
+
481
+ ---
482
+
483
+ ## License
484
+
485
+ [MIT](LICENSE)