@databricks/appkit 0.1.4 → 0.2.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 (163) hide show
  1. package/AGENTS.md +89 -12
  2. package/CLAUDE.md +89 -12
  3. package/NOTICE.md +4 -0
  4. package/README.md +21 -15
  5. package/bin/appkit-lint.js +129 -0
  6. package/dist/analytics/analytics.d.ts +33 -8
  7. package/dist/analytics/analytics.d.ts.map +1 -1
  8. package/dist/analytics/analytics.js +67 -27
  9. package/dist/analytics/analytics.js.map +1 -1
  10. package/dist/analytics/defaults.js.map +1 -1
  11. package/dist/analytics/query.js +12 -6
  12. package/dist/analytics/query.js.map +1 -1
  13. package/dist/app/index.d.ts.map +1 -1
  14. package/dist/app/index.js +7 -5
  15. package/dist/app/index.js.map +1 -1
  16. package/dist/appkit/package.js +1 -1
  17. package/dist/cache/defaults.js.map +1 -1
  18. package/dist/cache/index.d.ts +1 -0
  19. package/dist/cache/index.d.ts.map +1 -1
  20. package/dist/cache/index.js +25 -5
  21. package/dist/cache/index.js.map +1 -1
  22. package/dist/cache/storage/memory.js.map +1 -1
  23. package/dist/cache/storage/persistent.js +12 -6
  24. package/dist/cache/storage/persistent.js.map +1 -1
  25. package/dist/connectors/lakebase/client.js +31 -21
  26. package/dist/connectors/lakebase/client.js.map +1 -1
  27. package/dist/connectors/lakebase/defaults.js.map +1 -1
  28. package/dist/connectors/sql-warehouse/client.js +68 -28
  29. package/dist/connectors/sql-warehouse/client.js.map +1 -1
  30. package/dist/connectors/sql-warehouse/defaults.js.map +1 -1
  31. package/dist/context/execution-context.js +75 -0
  32. package/dist/context/execution-context.js.map +1 -0
  33. package/dist/context/index.js +27 -0
  34. package/dist/context/index.js.map +1 -0
  35. package/dist/context/service-context.js +154 -0
  36. package/dist/context/service-context.js.map +1 -0
  37. package/dist/context/user-context.js +15 -0
  38. package/dist/context/user-context.js.map +1 -0
  39. package/dist/core/appkit.d.ts +3 -0
  40. package/dist/core/appkit.d.ts.map +1 -1
  41. package/dist/core/appkit.js +7 -0
  42. package/dist/core/appkit.js.map +1 -1
  43. package/dist/errors/authentication.d.ts +38 -0
  44. package/dist/errors/authentication.d.ts.map +1 -0
  45. package/dist/errors/authentication.js +48 -0
  46. package/dist/errors/authentication.js.map +1 -0
  47. package/dist/errors/base.d.ts +58 -0
  48. package/dist/errors/base.d.ts.map +1 -0
  49. package/dist/errors/base.js +70 -0
  50. package/dist/errors/base.js.map +1 -0
  51. package/dist/errors/configuration.d.ts +38 -0
  52. package/dist/errors/configuration.d.ts.map +1 -0
  53. package/dist/errors/configuration.js +45 -0
  54. package/dist/errors/configuration.js.map +1 -0
  55. package/dist/errors/connection.d.ts +42 -0
  56. package/dist/errors/connection.d.ts.map +1 -0
  57. package/dist/errors/connection.js +54 -0
  58. package/dist/errors/connection.js.map +1 -0
  59. package/dist/errors/execution.d.ts +42 -0
  60. package/dist/errors/execution.d.ts.map +1 -0
  61. package/dist/errors/execution.js +51 -0
  62. package/dist/errors/execution.js.map +1 -0
  63. package/dist/errors/index.js +28 -0
  64. package/dist/errors/index.js.map +1 -0
  65. package/dist/errors/initialization.d.ts +34 -0
  66. package/dist/errors/initialization.d.ts.map +1 -0
  67. package/dist/errors/initialization.js +42 -0
  68. package/dist/errors/initialization.js.map +1 -0
  69. package/dist/errors/server.d.ts +38 -0
  70. package/dist/errors/server.d.ts.map +1 -0
  71. package/dist/errors/server.js +45 -0
  72. package/dist/errors/server.js.map +1 -0
  73. package/dist/errors/tunnel.d.ts +38 -0
  74. package/dist/errors/tunnel.d.ts.map +1 -0
  75. package/dist/errors/tunnel.js +51 -0
  76. package/dist/errors/tunnel.js.map +1 -0
  77. package/dist/errors/validation.d.ts +36 -0
  78. package/dist/errors/validation.d.ts.map +1 -0
  79. package/dist/errors/validation.js +45 -0
  80. package/dist/errors/validation.js.map +1 -0
  81. package/dist/index.d.ts +12 -4
  82. package/dist/index.js +12 -4
  83. package/dist/index.js.map +1 -1
  84. package/dist/logging/logger.js +179 -0
  85. package/dist/logging/logger.js.map +1 -0
  86. package/dist/logging/sampling.js +56 -0
  87. package/dist/logging/sampling.js.map +1 -0
  88. package/dist/logging/wide-event-emitter.js +108 -0
  89. package/dist/logging/wide-event-emitter.js.map +1 -0
  90. package/dist/logging/wide-event.js +167 -0
  91. package/dist/logging/wide-event.js.map +1 -0
  92. package/dist/plugin/dev-reader.d.ts.map +1 -1
  93. package/dist/plugin/dev-reader.js +8 -3
  94. package/dist/plugin/dev-reader.js.map +1 -1
  95. package/dist/plugin/interceptors/cache.js.map +1 -1
  96. package/dist/plugin/interceptors/retry.js +10 -2
  97. package/dist/plugin/interceptors/retry.js.map +1 -1
  98. package/dist/plugin/interceptors/telemetry.js +24 -9
  99. package/dist/plugin/interceptors/telemetry.js.map +1 -1
  100. package/dist/plugin/interceptors/timeout.js +4 -0
  101. package/dist/plugin/interceptors/timeout.js.map +1 -1
  102. package/dist/plugin/plugin.d.ts +38 -4
  103. package/dist/plugin/plugin.d.ts.map +1 -1
  104. package/dist/plugin/plugin.js +86 -5
  105. package/dist/plugin/plugin.js.map +1 -1
  106. package/dist/plugin/to-plugin.d.ts +4 -0
  107. package/dist/plugin/to-plugin.d.ts.map +1 -1
  108. package/dist/plugin/to-plugin.js +3 -0
  109. package/dist/plugin/to-plugin.js.map +1 -1
  110. package/dist/server/index.d.ts +3 -0
  111. package/dist/server/index.d.ts.map +1 -1
  112. package/dist/server/index.js +25 -21
  113. package/dist/server/index.js.map +1 -1
  114. package/dist/server/remote-tunnel/remote-tunnel-controller.js +4 -2
  115. package/dist/server/remote-tunnel/remote-tunnel-controller.js.map +1 -1
  116. package/dist/server/remote-tunnel/remote-tunnel-manager.js +10 -8
  117. package/dist/server/remote-tunnel/remote-tunnel-manager.js.map +1 -1
  118. package/dist/server/utils.js.map +1 -1
  119. package/dist/server/vite-dev-server.js +8 -5
  120. package/dist/server/vite-dev-server.js.map +1 -1
  121. package/dist/shared/src/sql/helpers.js.map +1 -1
  122. package/dist/stream/arrow-stream-processor.js +13 -6
  123. package/dist/stream/arrow-stream-processor.js.map +1 -1
  124. package/dist/stream/buffers.js +5 -1
  125. package/dist/stream/buffers.js.map +1 -1
  126. package/dist/stream/sse-writer.js.map +1 -1
  127. package/dist/stream/stream-manager.d.ts.map +1 -1
  128. package/dist/stream/stream-manager.js +47 -36
  129. package/dist/stream/stream-manager.js.map +1 -1
  130. package/dist/stream/stream-registry.js.map +1 -1
  131. package/dist/stream/types.js.map +1 -1
  132. package/dist/telemetry/index.d.ts +2 -2
  133. package/dist/telemetry/index.js +2 -2
  134. package/dist/telemetry/instrumentations.js +14 -10
  135. package/dist/telemetry/instrumentations.js.map +1 -1
  136. package/dist/telemetry/telemetry-manager.js +8 -6
  137. package/dist/telemetry/telemetry-manager.js.map +1 -1
  138. package/dist/telemetry/trace-sampler.js +33 -0
  139. package/dist/telemetry/trace-sampler.js.map +1 -0
  140. package/dist/type-generator/index.js +4 -2
  141. package/dist/type-generator/index.js.map +1 -1
  142. package/dist/type-generator/query-registry.js +4 -2
  143. package/dist/type-generator/query-registry.js.map +1 -1
  144. package/dist/type-generator/types.js.map +1 -1
  145. package/dist/type-generator/vite-plugin.d.ts.map +1 -1
  146. package/dist/type-generator/vite-plugin.js +5 -3
  147. package/dist/type-generator/vite-plugin.js.map +1 -1
  148. package/dist/utils/env-validator.js +5 -5
  149. package/dist/utils/env-validator.js.map +1 -1
  150. package/dist/utils/merge.js +1 -5
  151. package/dist/utils/merge.js.map +1 -1
  152. package/dist/utils/path-exclusions.js +66 -0
  153. package/dist/utils/path-exclusions.js.map +1 -0
  154. package/dist/utils/vite-config-merge.js +1 -5
  155. package/dist/utils/vite-config-merge.js.map +1 -1
  156. package/llms.txt +89 -12
  157. package/package.json +6 -1
  158. package/dist/utils/databricks-client-middleware.d.ts +0 -17
  159. package/dist/utils/databricks-client-middleware.d.ts.map +0 -1
  160. package/dist/utils/databricks-client-middleware.js +0 -117
  161. package/dist/utils/databricks-client-middleware.js.map +0 -1
  162. package/dist/utils/index.js +0 -26
  163. package/dist/utils/index.js.map +0 -1
@@ -0,0 +1,66 @@
1
+ //#region src/utils/path-exclusions.ts
2
+ /**
3
+ * Paths and patterns to exclude from tracing and logging.
4
+ * Requests matching these will not create spans or WideEvents.
5
+ */
6
+ const EXCLUDED_PATH_PREFIXES = [
7
+ "/@fs/",
8
+ "/@vite/",
9
+ "/@id/",
10
+ "/@react-refresh",
11
+ "/src/",
12
+ "/node_modules/",
13
+ "/favicon.ico",
14
+ "/_next/",
15
+ "/static/",
16
+ "/health",
17
+ "/metrics"
18
+ ];
19
+ /**
20
+ * File extensions to exclude from tracing.
21
+ * These are typically static assets that don't need tracing.
22
+ */
23
+ const EXCLUDED_EXTENSIONS = [
24
+ ".svg",
25
+ ".png",
26
+ ".jpg",
27
+ ".jpeg",
28
+ ".gif",
29
+ ".webp",
30
+ ".ico",
31
+ ".css",
32
+ ".woff",
33
+ ".woff2",
34
+ ".ttf",
35
+ ".eot",
36
+ ".map",
37
+ ".js"
38
+ ];
39
+ /**
40
+ * Check if a request should be ignored for tracing.
41
+ * This is the primary filter used by HttpInstrumentation.
42
+ */
43
+ function shouldIgnoreRequest(request) {
44
+ const url = request.url;
45
+ if (!url) return false;
46
+ const path = url.split("?")[0];
47
+ return shouldExcludePath(path);
48
+ }
49
+ /**
50
+ * Check if a path should be excluded from tracing/logging.
51
+ * Returns true if path should be excluded, false otherwise.
52
+ */
53
+ function shouldExcludePath(path) {
54
+ if (typeof path !== "string") return false;
55
+ const cleanPath = path.split("?")[0];
56
+ const lowerPath = cleanPath.toLowerCase();
57
+ for (const prefix of EXCLUDED_PATH_PREFIXES) if (cleanPath.includes(prefix)) return true;
58
+ if (!cleanPath.startsWith("/api/")) {
59
+ for (const ext of EXCLUDED_EXTENSIONS) if (lowerPath.endsWith(ext)) return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+ //#endregion
65
+ export { shouldExcludePath, shouldIgnoreRequest };
66
+ //# sourceMappingURL=path-exclusions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-exclusions.js","names":[],"sources":["../../src/utils/path-exclusions.ts"],"sourcesContent":["import type { IncomingMessage } from \"node:http\";\n\n/**\n * Paths and patterns to exclude from tracing and logging.\n * Requests matching these will not create spans or WideEvents.\n */\nexport const EXCLUDED_PATH_PREFIXES = [\n // Vite dev server internals\n \"/@fs/\",\n \"/@vite/\",\n \"/@id/\",\n \"/@react-refresh\",\n \"/src/\", // Vite HMR source files\n \"/node_modules/\",\n\n // Static assets and common paths\n \"/favicon.ico\",\n \"/_next/\",\n \"/static/\",\n\n // Health checks\n \"/health\",\n \"/metrics\",\n];\n\n/**\n * File extensions to exclude from tracing.\n * These are typically static assets that don't need tracing.\n */\nexport const EXCLUDED_EXTENSIONS = [\n \".svg\",\n \".png\",\n \".jpg\",\n \".jpeg\",\n \".gif\",\n \".webp\",\n \".ico\",\n \".css\",\n \".woff\",\n \".woff2\",\n \".ttf\",\n \".eot\",\n \".map\", // Source maps\n \".js\", // Static JS files (not API endpoints)\n];\n\n/**\n * Check if a request should be ignored for tracing.\n * This is the primary filter used by HttpInstrumentation.\n */\nexport function shouldIgnoreRequest(request: IncomingMessage): boolean {\n const url = request.url;\n if (!url) return false;\n\n // Remove query string for path matching\n const path = url.split(\"?\")[0];\n\n return shouldExcludePath(path);\n}\n\n/**\n * Check if a path should be excluded from tracing/logging.\n * Returns true if path should be excluded, false otherwise.\n */\nexport function shouldExcludePath(path: string | undefined): boolean {\n if (typeof path !== \"string\") return false;\n\n // Remove query string\n const cleanPath = path.split(\"?\")[0];\n const lowerPath = cleanPath.toLowerCase();\n\n // Check path prefixes\n for (const prefix of EXCLUDED_PATH_PREFIXES) {\n if (cleanPath.includes(prefix)) {\n return true;\n }\n }\n\n // Check file extensions (but not for /api/ routes)\n if (!cleanPath.startsWith(\"/api/\")) {\n for (const ext of EXCLUDED_EXTENSIONS) {\n if (lowerPath.endsWith(ext)) {\n return true;\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;AAMA,MAAa,yBAAyB;CAEpC;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CAGA;CACA;CACD;;;;;AAMD,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAMD,SAAgB,oBAAoB,SAAmC;CACrE,MAAM,MAAM,QAAQ;AACpB,KAAI,CAAC,IAAK,QAAO;CAGjB,MAAM,OAAO,IAAI,MAAM,IAAI,CAAC;AAE5B,QAAO,kBAAkB,KAAK;;;;;;AAOhC,SAAgB,kBAAkB,MAAmC;AACnE,KAAI,OAAO,SAAS,SAAU,QAAO;CAGrC,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;CAClC,MAAM,YAAY,UAAU,aAAa;AAGzC,MAAK,MAAM,UAAU,uBACnB,KAAI,UAAU,SAAS,OAAO,CAC5B,QAAO;AAKX,KAAI,CAAC,UAAU,WAAW,QAAQ,EAChC;OAAK,MAAM,OAAO,oBAChB,KAAI,UAAU,SAAS,IAAI,CACzB,QAAO;;AAKb,QAAO"}
@@ -1,5 +1,3 @@
1
- import { __esmMin } from "../_virtual/rolldown_runtime.js";
2
-
3
1
  //#region src/utils/vite-config-merge.ts
4
2
  function mergeConfigDedup(base, override, mergeFn) {
5
3
  const merged = mergeFn(base, override);
@@ -14,9 +12,7 @@ function mergeConfigDedup(base, override, mergeFn) {
14
12
  }
15
13
  return merged;
16
14
  }
17
- var init_vite_config_merge = __esmMin((() => {}));
18
15
 
19
16
  //#endregion
20
- init_vite_config_merge();
21
- export { init_vite_config_merge, mergeConfigDedup };
17
+ export { mergeConfigDedup };
22
18
  //# sourceMappingURL=vite-config-merge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-config-merge.js","names":[],"sources":["../../src/utils/vite-config-merge.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\nexport function mergeConfigDedup(\n base: any,\n override: any,\n mergeFn: (a: any, b: any) => any,\n) {\n const merged = mergeFn(base, override);\n if (base.plugins && override.plugins) {\n const seen = new Set<string>();\n merged.plugins = [...base.plugins, ...override.plugins].filter(\n (p: Plugin) => {\n const name = p.name;\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n },\n );\n }\n return merged;\n}\n"],"mappings":";;;AAEA,SAAgB,iBACd,MACA,UACA,SACA;CACA,MAAM,SAAS,QAAQ,MAAM,SAAS;AACtC,KAAI,KAAK,WAAW,SAAS,SAAS;EACpC,MAAM,uBAAO,IAAI,KAAa;AAC9B,SAAO,UAAU,CAAC,GAAG,KAAK,SAAS,GAAG,SAAS,QAAQ,CAAC,QACrD,MAAc;GACb,MAAM,OAAO,EAAE;AACf,OAAI,KAAK,IAAI,KAAK,CAAE,QAAO;AAC3B,QAAK,IAAI,KAAK;AACd,UAAO;IAEV;;AAEH,QAAO"}
1
+ {"version":3,"file":"vite-config-merge.js","names":[],"sources":["../../src/utils/vite-config-merge.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\nexport function mergeConfigDedup(\n base: any,\n override: any,\n mergeFn: (a: any, b: any) => any,\n) {\n const merged = mergeFn(base, override);\n if (base.plugins && override.plugins) {\n const seen = new Set<string>();\n merged.plugins = [...base.plugins, ...override.plugins].filter(\n (p: Plugin) => {\n const name = p.name;\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n },\n );\n }\n return merged;\n}\n"],"mappings":";AAEA,SAAgB,iBACd,MACA,UACA,SACA;CACA,MAAM,SAAS,QAAQ,MAAM,SAAS;AACtC,KAAI,KAAK,WAAW,SAAS,SAAS;EACpC,MAAM,uBAAO,IAAI,KAAa;AAC9B,SAAO,UAAU,CAAC,GAAG,KAAK,SAAS,GAAG,SAAS,QAAQ,CAAC,QACrD,MAAc;GACb,MAAM,OAAO,EAAE;AACf,OAAI,KAAK,IAAI,KAAK,CAAE,QAAO;AAC3B,QAAK,IAAI,KAAK;AACd,UAAO;IAEV;;AAEH,QAAO"}
package/llms.txt CHANGED
@@ -440,23 +440,49 @@ Formats:
440
440
  - `format: "JSON"` (default) returns JSON rows
441
441
  - `format: "ARROW"` returns an Arrow “statement_id” payload over SSE, then the client fetches binary Arrow from `/api/analytics/arrow-result/:jobId`
442
442
 
443
- ### Request context (`getRequestContext()`)
443
+ ### Execution context and `asUser(req)`
444
444
 
445
- If a plugin sets `requiresDatabricksClient = true`, AppKit adds middleware that provides request context.
445
+ AppKit manages Databricks authentication via two contexts:
446
446
 
447
- Headers used:
447
+ - **ServiceContext** (singleton): Initialized at app startup with service principal credentials
448
+ - **ExecutionContext**: Determined at runtime - either service principal or user context
449
+
450
+ **Headers used for user context:**
448
451
 
449
452
  - `x-forwarded-user`: required in production; identifies the user
450
- - `x-forwarded-access-token`: optional; enables **user token passthrough** if `DATABRICKS_HOST` is set
453
+ - `x-forwarded-access-token`: required for user token passthrough
454
+
455
+ **Using `asUser(req)` for user-scoped operations:**
456
+
457
+ The `asUser(req)` pattern allows plugins to execute operations using the requesting user's credentials:
458
+
459
+ ```ts
460
+ // In a custom plugin route handler
461
+ router.post("/users/me/data", async (req, res) => {
462
+ // Execute as the user (uses their Databricks permissions)
463
+ const result = await this.asUser(req).query("SELECT ...");
464
+ res.json(result);
465
+ });
466
+
467
+ // Service principal execution (default)
468
+ router.post("/system/data", async (req, res) => {
469
+ const result = await this.query("SELECT ...");
470
+ res.json(result);
471
+ });
472
+ ```
473
+
474
+ **Context helper functions (exported from `@databricks/appkit`):**
451
475
 
452
- Context fields (real behavior):
476
+ - `getExecutionContext()`: Returns current context (user or service)
477
+ - `getCurrentUserId()`: Returns user ID in user context, service user ID otherwise
478
+ - `getWorkspaceClient()`: Returns the appropriate WorkspaceClient for current context
479
+ - `getWarehouseId()`: `Promise<string>` (from `DATABRICKS_WAREHOUSE_ID` or auto-selected in dev)
480
+ - `getWorkspaceId()`: `Promise<string>` (from `DATABRICKS_WORKSPACE_ID` or fetched)
481
+ - `isInUserContext()`: Returns `true` if currently executing in user context
453
482
 
454
- - `userId`: derived from `x-forwarded-user` (in development it falls back to `serviceUserId`)
455
- - `serviceUserId`: service principal/user ID
456
- - `warehouseId`: `Promise<string>` (from `DATABRICKS_WAREHOUSE_ID`, or auto-selected in development)
457
- - `workspaceId`: `Promise<string>` (from `DATABRICKS_WORKSPACE_ID` or fetched)
458
- - `userDatabricksClient`: present only when passthrough is available (or in dev it equals service client)
459
- - `serviceDatabricksClient`: always present
483
+ **Development mode behavior:**
484
+
485
+ In local development (`NODE_ENV=development`), if `asUser(req)` is called without a user token, it logs a warning and falls back to the service principal.
460
486
 
461
487
  ### Custom plugins (backend)
462
488
 
@@ -469,7 +495,6 @@ import type express from "express";
469
495
  class MyPlugin extends Plugin {
470
496
  name = "my-plugin";
471
497
  envVars = []; // list required env vars here
472
- requiresDatabricksClient = false; // set true if you need getRequestContext()
473
498
 
474
499
  injectRoutes(router: express.Router) {
475
500
  this.route(router, {
@@ -643,6 +668,56 @@ export function SpendChart() {
643
668
  }
644
669
  ```
645
670
 
671
+ **Chart props reference (important):**
672
+
673
+ Charts are **self-contained ECharts components**. Configure via props, NOT children:
674
+
675
+ ```tsx
676
+ // ✅ Correct: use props for customization
677
+ <BarChart
678
+ queryKey="sales_by_region"
679
+ parameters={{}}
680
+ xKey="region" // X-axis field
681
+ yKey={["revenue", "expenses"]} // Y-axis field(s) - string or string[]
682
+ colors={['#40d1f5', '#4462c9']} // Custom colors
683
+ stacked // Stack bars (BarChart, AreaChart)
684
+ orientation="horizontal" // "vertical" (default) | "horizontal"
685
+ showLegend // Show legend
686
+ height={400} // Height in pixels (default: 300)
687
+ />
688
+
689
+ <LineChart
690
+ queryKey="trend_data"
691
+ parameters={{}}
692
+ xKey="date"
693
+ yKey="value"
694
+ smooth // Smooth curves (default: true)
695
+ showSymbol={false} // Hide data point markers
696
+ />
697
+ ```
698
+
699
+ **❌ CRITICAL: Charts do NOT accept Recharts children**
700
+
701
+ ```tsx
702
+ // ❌ WRONG - AppKit charts are NOT Recharts wrappers
703
+ import { BarChart } from "@databricks/appkit-ui/react";
704
+ import { Bar, XAxis, YAxis, CartesianGrid } from "recharts";
705
+
706
+ <BarChart queryKey="data" parameters={{}}>
707
+ <CartesianGrid /> // ❌ This will cause TypeScript errors
708
+ <XAxis dataKey="x" /> // ❌ Not supported
709
+ <Bar dataKey="y" /> // ❌ Not supported
710
+ </BarChart>
711
+
712
+ // ✅ CORRECT - use props instead
713
+ <BarChart
714
+ queryKey="data"
715
+ parameters={{}}
716
+ xKey="x"
717
+ yKey="y"
718
+ />
719
+ ```
720
+
646
721
  ### SQL helpers (`sql.*`)
647
722
 
648
723
  Use these to build typed parameters (they return marker objects: `{ __sql_type, value }`):
@@ -1144,6 +1219,7 @@ env:
1144
1219
  - `useMemo` wraps parameters objects
1145
1220
  - Loading/error/empty states are explicit
1146
1221
  - Charts use `format="auto"` unless you have a reason to force `"json"`/`"arrow"`
1222
+ - Charts use props (`xKey`, `yKey`, `colors`) NOT children (they're ECharts-based, not Recharts)
1147
1223
  - If using tooltips: root is wrapped with `<TooltipProvider>`
1148
1224
 
1149
1225
  - **Never**
@@ -1151,4 +1227,5 @@ env:
1151
1227
  - Don't pass untyped raw params for annotated queries
1152
1228
  - Don't ignore `createApp()`'s promise
1153
1229
  - Don't invent UI components not listed in this file
1230
+ - Don't pass Recharts children (`<Bar>`, `<XAxis>`, etc.) to AppKit chart components
1154
1231
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@databricks/appkit",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "packageManager": "pnpm@10.21.0",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "bin": {
28
28
  "appkit-generate-types": "./bin/generate-types.js",
29
+ "appkit-lint": "./bin/appkit-lint.js",
29
30
  "appkit-setup": "./bin/setup-claude.js"
30
31
  },
31
32
  "scripts": {
@@ -39,6 +40,7 @@
39
40
  "postinstall": "node scripts/postinstall.js"
40
41
  },
41
42
  "dependencies": {
43
+ "@ast-grep/napi": "^0.37.0",
42
44
  "@databricks/sdk-experimental": "^0.15.0",
43
45
  "@opentelemetry/api": "^1.9.0",
44
46
  "@opentelemetry/api-logs": "^0.208.0",
@@ -54,9 +56,12 @@
54
56
  "@opentelemetry/sdk-metrics": "^2.2.0",
55
57
  "@opentelemetry/sdk-node": "^0.208.0",
56
58
  "@opentelemetry/semantic-conventions": "^1.38.0",
59
+ "@types/semver": "^7.7.1",
57
60
  "dotenv": "^16.6.1",
58
61
  "express": "^4.22.0",
62
+ "obug": "^2.1.1",
59
63
  "pg": "^8.16.3",
64
+ "semver": "^7.7.3",
60
65
  "vite": "npm:rolldown-vite@7.1.14",
61
66
  "ws": "^8.18.3",
62
67
  "zod-to-ts": "^2.0.0"
@@ -1,17 +0,0 @@
1
- import { WorkspaceClient } from "@databricks/sdk-experimental";
2
- import express from "express";
3
-
4
- //#region src/utils/databricks-client-middleware.d.ts
5
- type RequestContext = {
6
- userDatabricksClient?: WorkspaceClient;
7
- serviceDatabricksClient: WorkspaceClient;
8
- userId: string;
9
- userName?: string;
10
- serviceUserId: string;
11
- warehouseId: Promise<string>;
12
- workspaceId: Promise<string>;
13
- };
14
- declare function getRequestContext(): RequestContext;
15
- //#endregion
16
- export { getRequestContext };
17
- //# sourceMappingURL=databricks-client-middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"databricks-client-middleware.d.ts","names":[],"sources":["../../src/utils/databricks-client-middleware.ts"],"sourcesContent":[],"mappings":";;;;KAYY,cAAA;yBACa;EADb,uBAAc,EAEC,eAFD;EAAA,MAAA,EAAA,MAAA;UACD,CAAA,EAAA,MAAA;eACE,EAAA,MAAA;aAIZ,EAAA,OAAA,CAAA,MAAA,CAAA;aACA,EAAA,OAAA,CAAA,MAAA,CAAA;CAAO;iBA4EN,iBAAA,CAAA,GAAqB"}
@@ -1,117 +0,0 @@
1
- import { __esmMin } from "../_virtual/rolldown_runtime.js";
2
- import { name, version } from "../appkit/package.js";
3
- import { WorkspaceClient } from "@databricks/sdk-experimental";
4
- import { AsyncLocalStorage } from "node:async_hooks";
5
-
6
- //#region src/utils/databricks-client-middleware.ts
7
- function getClientOptions() {
8
- const isDev = process.env.NODE_ENV === "development";
9
- return {
10
- product: name,
11
- productVersion: version.split(".").slice(0, 3).join("."),
12
- ...isDev && { userAgentExtra: { mode: "dev" } }
13
- };
14
- }
15
- async function databricksClientMiddleware() {
16
- const serviceDatabricksClient = new WorkspaceClient({}, getClientOptions());
17
- const warehouseId = getWarehouseId(serviceDatabricksClient);
18
- const workspaceId = getWorkspaceId(serviceDatabricksClient);
19
- const serviceUserId = (await serviceDatabricksClient.currentUser.me()).id;
20
- if (!serviceUserId) throw new Error("Service user ID not found");
21
- return async (req, res, next) => {
22
- const userToken = req.headers["x-forwarded-access-token"];
23
- let userDatabricksClient;
24
- const host = process.env.DATABRICKS_HOST;
25
- if (userToken && host) userDatabricksClient = new WorkspaceClient({
26
- token: userToken,
27
- host,
28
- authType: "pat"
29
- }, getClientOptions());
30
- else if (process.env.NODE_ENV === "development") userDatabricksClient = serviceDatabricksClient;
31
- let userName = req.headers["x-forwarded-user"];
32
- if (!userName && process.env.NODE_ENV !== "development") {
33
- res.status(401).json({ error: "Unauthorized" });
34
- return;
35
- } else userName = serviceUserId;
36
- return asyncLocalStorage.run({
37
- userDatabricksClient,
38
- serviceDatabricksClient,
39
- warehouseId,
40
- workspaceId,
41
- userId: userName,
42
- serviceUserId
43
- }, async () => {
44
- return next();
45
- });
46
- };
47
- }
48
- function getRequestContext() {
49
- const store = asyncLocalStorage.getStore();
50
- if (!store) throw new Error("Request context not found");
51
- return store;
52
- }
53
- /**
54
- * Get the appropriate WorkspaceClient based on whether the request
55
- * should be executed as the user or as the service principal.
56
- *
57
- * @param asUser - If true, returns user's WorkspaceClient (requires token passthrough)
58
- * @throws Error if asUser is true but user token passthrough is not enabled
59
- */
60
- function getWorkspaceClient(asUser) {
61
- const context = getRequestContext();
62
- if (asUser) {
63
- if (!context.userDatabricksClient) throw new Error(`User token passthrough is not enabled for this workspace.`);
64
- return context.userDatabricksClient;
65
- }
66
- return context.serviceDatabricksClient;
67
- }
68
- async function getWorkspaceId(workspaceClient) {
69
- if (process.env.DATABRICKS_WORKSPACE_ID) return process.env.DATABRICKS_WORKSPACE_ID;
70
- const response = await workspaceClient.apiClient.request({
71
- path: "/api/2.0/preview/scim/v2/Me",
72
- method: "GET",
73
- headers: new Headers(),
74
- raw: false,
75
- query: {},
76
- responseHeaders: ["x-databricks-org-id"]
77
- });
78
- if (!response["x-databricks-org-id"]) throw new Error("Workspace ID not found");
79
- return response["x-databricks-org-id"];
80
- }
81
- async function getWarehouseId(workspaceClient) {
82
- if (process.env.DATABRICKS_WAREHOUSE_ID) return process.env.DATABRICKS_WAREHOUSE_ID;
83
- if (process.env.NODE_ENV === "development") {
84
- const response = await workspaceClient.apiClient.request({
85
- path: "/api/2.0/sql/warehouses",
86
- method: "GET",
87
- headers: new Headers(),
88
- raw: false,
89
- query: { skip_cannot_use: "true" }
90
- });
91
- const priorities = {
92
- RUNNING: 0,
93
- STOPPED: 1,
94
- STARTING: 2,
95
- STOPPING: 3,
96
- DELETED: 99,
97
- DELETING: 99
98
- };
99
- const warehouses = (response.warehouses || []).sort((a, b) => {
100
- return priorities[a.state] - priorities[b.state];
101
- });
102
- if (response.warehouses.length === 0) throw new Error("Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.");
103
- const firstWarehouse = warehouses[0];
104
- if (firstWarehouse.state === "DELETED" || firstWarehouse.state === "DELETING" || !firstWarehouse.id) throw new Error("Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.");
105
- return firstWarehouse.id;
106
- }
107
- throw new Error("Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.");
108
- }
109
- var asyncLocalStorage;
110
- var init_databricks_client_middleware = __esmMin((() => {
111
- asyncLocalStorage = new AsyncLocalStorage();
112
- }));
113
-
114
- //#endregion
115
- init_databricks_client_middleware();
116
- export { databricksClientMiddleware, getRequestContext, getWorkspaceClient, init_databricks_client_middleware };
117
- //# sourceMappingURL=databricks-client-middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"databricks-client-middleware.js","names":["productName","productVersion","userDatabricksClient: WorkspaceClient | undefined","priorities: Record<sql.State, number>"],"sources":["../../src/utils/databricks-client-middleware.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport {\n type ClientOptions,\n type sql,\n WorkspaceClient,\n} from \"@databricks/sdk-experimental\";\nimport type express from \"express\";\nimport {\n name as productName,\n version as productVersion,\n} from \"../../package.json\";\n\nexport type RequestContext = {\n userDatabricksClient?: WorkspaceClient;\n serviceDatabricksClient: WorkspaceClient;\n userId: string;\n userName?: string;\n serviceUserId: string;\n warehouseId: Promise<string>;\n workspaceId: Promise<string>;\n};\n\nconst asyncLocalStorage = new AsyncLocalStorage<RequestContext>();\n\nfunction getClientOptions(): ClientOptions {\n const isDev = process.env.NODE_ENV === \"development\";\n const normalizedVersion = productVersion\n .split(\".\")\n .slice(0, 3)\n .join(\".\") as ClientOptions[\"productVersion\"];\n\n return {\n product: productName,\n productVersion: normalizedVersion,\n ...(isDev && { userAgentExtra: { mode: \"dev\" } }),\n };\n}\n\nexport async function databricksClientMiddleware(): Promise<express.RequestHandler> {\n const serviceDatabricksClient = new WorkspaceClient({}, getClientOptions());\n const warehouseId = getWarehouseId(serviceDatabricksClient);\n const workspaceId = getWorkspaceId(serviceDatabricksClient);\n const serviceUserId = (await serviceDatabricksClient.currentUser.me()).id;\n\n if (!serviceUserId) {\n throw new Error(\"Service user ID not found\");\n }\n\n return async (\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n ) => {\n const userToken = req.headers[\"x-forwarded-access-token\"] as string;\n let userDatabricksClient: WorkspaceClient | undefined;\n const host = process.env.DATABRICKS_HOST;\n if (userToken && host) {\n userDatabricksClient = new WorkspaceClient(\n {\n token: userToken,\n host,\n authType: \"pat\",\n },\n getClientOptions(),\n );\n } else if (process.env.NODE_ENV === \"development\") {\n // in local development service and no user token are the same\n // TODO: use `databricks apps run-local` to fix this\n userDatabricksClient = serviceDatabricksClient;\n }\n\n let userName = req.headers[\"x-forwarded-user\"] as string;\n if (!userName && process.env.NODE_ENV !== \"development\") {\n res.status(401).json({ error: \"Unauthorized\" });\n return;\n } else {\n userName = serviceUserId;\n }\n\n return asyncLocalStorage.run(\n {\n userDatabricksClient,\n serviceDatabricksClient,\n warehouseId,\n workspaceId,\n userId: userName,\n serviceUserId,\n },\n async () => {\n return next();\n },\n );\n };\n}\n\nexport function getRequestContext(): RequestContext {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\"Request context not found\");\n }\n return store;\n}\n\n/**\n * Get the appropriate WorkspaceClient based on whether the request\n * should be executed as the user or as the service principal.\n *\n * @param asUser - If true, returns user's WorkspaceClient (requires token passthrough)\n * @throws Error if asUser is true but user token passthrough is not enabled\n */\nexport function getWorkspaceClient(asUser: boolean): WorkspaceClient {\n const context = getRequestContext();\n\n if (asUser) {\n if (!context.userDatabricksClient) {\n throw new Error(\n `User token passthrough is not enabled for this workspace.`,\n );\n }\n return context.userDatabricksClient;\n }\n\n return context.serviceDatabricksClient;\n}\n\nasync function getWorkspaceId(\n workspaceClient: WorkspaceClient,\n): Promise<string> {\n if (process.env.DATABRICKS_WORKSPACE_ID) {\n return process.env.DATABRICKS_WORKSPACE_ID;\n }\n\n const response = (await workspaceClient.apiClient.request({\n path: \"/api/2.0/preview/scim/v2/Me\",\n method: \"GET\",\n headers: new Headers(),\n raw: false,\n query: {},\n responseHeaders: [\"x-databricks-org-id\"],\n })) as { \"x-databricks-org-id\": string };\n\n if (!response[\"x-databricks-org-id\"]) {\n throw new Error(\"Workspace ID not found\");\n }\n\n return response[\"x-databricks-org-id\"];\n}\n\nasync function getWarehouseId(\n workspaceClient: WorkspaceClient,\n): Promise<string> {\n if (process.env.DATABRICKS_WAREHOUSE_ID) {\n return process.env.DATABRICKS_WAREHOUSE_ID;\n }\n\n if (process.env.NODE_ENV === \"development\") {\n const response = (await workspaceClient.apiClient.request({\n path: \"/api/2.0/sql/warehouses\",\n method: \"GET\",\n headers: new Headers(),\n raw: false,\n query: {\n skip_cannot_use: \"true\",\n },\n })) as { warehouses: sql.EndpointInfo[] };\n\n const priorities: Record<sql.State, number> = {\n RUNNING: 0,\n STOPPED: 1,\n STARTING: 2,\n STOPPING: 3,\n DELETED: 99,\n DELETING: 99,\n };\n\n const warehouses = (response.warehouses || []).sort((a, b) => {\n return (\n priorities[a.state as sql.State] - priorities[b.state as sql.State]\n );\n });\n\n if (response.warehouses.length === 0) {\n throw new Error(\n \"Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.\",\n );\n }\n\n const firstWarehouse = warehouses[0];\n if (\n firstWarehouse.state === \"DELETED\" ||\n firstWarehouse.state === \"DELETING\" ||\n !firstWarehouse.id\n ) {\n throw new Error(\n \"Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.\",\n );\n }\n\n return firstWarehouse.id;\n }\n\n throw new Error(\n \"Warehouse ID not found. Please configure the DATABRICKS_WAREHOUSE_ID environment variable.\",\n );\n}\n\nexport type Request = express.Request;\nexport type Response = express.Response;\n"],"mappings":";;;;;;AAwBA,SAAS,mBAAkC;CACzC,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAMvC,QAAO;EACL,SAASA;EACT,gBAPwBC,QACvB,MAAM,IAAI,CACV,MAAM,GAAG,EAAE,CACX,KAAK,IAAI;EAKV,GAAI,SAAS,EAAE,gBAAgB,EAAE,MAAM,OAAO,EAAE;EACjD;;AAGH,eAAsB,6BAA8D;CAClF,MAAM,0BAA0B,IAAI,gBAAgB,EAAE,EAAE,kBAAkB,CAAC;CAC3E,MAAM,cAAc,eAAe,wBAAwB;CAC3D,MAAM,cAAc,eAAe,wBAAwB;CAC3D,MAAM,iBAAiB,MAAM,wBAAwB,YAAY,IAAI,EAAE;AAEvE,KAAI,CAAC,cACH,OAAM,IAAI,MAAM,4BAA4B;AAG9C,QAAO,OACL,KACA,KACA,SACG;EACH,MAAM,YAAY,IAAI,QAAQ;EAC9B,IAAIC;EACJ,MAAM,OAAO,QAAQ,IAAI;AACzB,MAAI,aAAa,KACf,wBAAuB,IAAI,gBACzB;GACE,OAAO;GACP;GACA,UAAU;GACX,EACD,kBAAkB,CACnB;WACQ,QAAQ,IAAI,aAAa,cAGlC,wBAAuB;EAGzB,IAAI,WAAW,IAAI,QAAQ;AAC3B,MAAI,CAAC,YAAY,QAAQ,IAAI,aAAa,eAAe;AACvD,OAAI,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,gBAAgB,CAAC;AAC/C;QAEA,YAAW;AAGb,SAAO,kBAAkB,IACvB;GACE;GACA;GACA;GACA;GACA,QAAQ;GACR;GACD,EACD,YAAY;AACV,UAAO,MAAM;IAEhB;;;AAIL,SAAgB,oBAAoC;CAClD,MAAM,QAAQ,kBAAkB,UAAU;AAC1C,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,4BAA4B;AAE9C,QAAO;;;;;;;;;AAUT,SAAgB,mBAAmB,QAAkC;CACnE,MAAM,UAAU,mBAAmB;AAEnC,KAAI,QAAQ;AACV,MAAI,CAAC,QAAQ,qBACX,OAAM,IAAI,MACR,4DACD;AAEH,SAAO,QAAQ;;AAGjB,QAAO,QAAQ;;AAGjB,eAAe,eACb,iBACiB;AACjB,KAAI,QAAQ,IAAI,wBACd,QAAO,QAAQ,IAAI;CAGrB,MAAM,WAAY,MAAM,gBAAgB,UAAU,QAAQ;EACxD,MAAM;EACN,QAAQ;EACR,SAAS,IAAI,SAAS;EACtB,KAAK;EACL,OAAO,EAAE;EACT,iBAAiB,CAAC,sBAAsB;EACzC,CAAC;AAEF,KAAI,CAAC,SAAS,uBACZ,OAAM,IAAI,MAAM,yBAAyB;AAG3C,QAAO,SAAS;;AAGlB,eAAe,eACb,iBACiB;AACjB,KAAI,QAAQ,IAAI,wBACd,QAAO,QAAQ,IAAI;AAGrB,KAAI,QAAQ,IAAI,aAAa,eAAe;EAC1C,MAAM,WAAY,MAAM,gBAAgB,UAAU,QAAQ;GACxD,MAAM;GACN,QAAQ;GACR,SAAS,IAAI,SAAS;GACtB,KAAK;GACL,OAAO,EACL,iBAAiB,QAClB;GACF,CAAC;EAEF,MAAMC,aAAwC;GAC5C,SAAS;GACT,SAAS;GACT,UAAU;GACV,UAAU;GACV,SAAS;GACT,UAAU;GACX;EAED,MAAM,cAAc,SAAS,cAAc,EAAE,EAAE,MAAM,GAAG,MAAM;AAC5D,UACE,WAAW,EAAE,SAAsB,WAAW,EAAE;IAElD;AAEF,MAAI,SAAS,WAAW,WAAW,EACjC,OAAM,IAAI,MACR,6FACD;EAGH,MAAM,iBAAiB,WAAW;AAClC,MACE,eAAe,UAAU,aACzB,eAAe,UAAU,cACzB,CAAC,eAAe,GAEhB,OAAM,IAAI,MACR,6FACD;AAGH,SAAO,eAAe;;AAGxB,OAAM,IAAI,MACR,6FACD;;;;CArLG,oBAAoB,IAAI,mBAAmC"}
@@ -1,26 +0,0 @@
1
- import { __esmMin, __exportAll } from "../_virtual/rolldown_runtime.js";
2
- import { databricksClientMiddleware, getRequestContext, getWorkspaceClient, init_databricks_client_middleware } from "./databricks-client-middleware.js";
3
- import { init_env_validator, validateEnv } from "./env-validator.js";
4
- import { deepMerge, init_merge } from "./merge.js";
5
- import { init_vite_config_merge, mergeConfigDedup } from "./vite-config-merge.js";
6
-
7
- //#region src/utils/index.ts
8
- var utils_exports = /* @__PURE__ */ __exportAll({
9
- databricksClientMiddleware: () => databricksClientMiddleware,
10
- deepMerge: () => deepMerge,
11
- getRequestContext: () => getRequestContext,
12
- getWorkspaceClient: () => getWorkspaceClient,
13
- mergeConfigDedup: () => mergeConfigDedup,
14
- validateEnv: () => validateEnv
15
- });
16
- var init_utils = __esmMin((() => {
17
- init_databricks_client_middleware();
18
- init_env_validator();
19
- init_merge();
20
- init_vite_config_merge();
21
- }));
22
-
23
- //#endregion
24
- init_utils();
25
- export { init_utils, utils_exports };
26
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./databricks-client-middleware\";\nexport * from \"./env-validator\";\nexport * from \"./merge\";\nexport * from \"./vite-config-merge\";\n"],"mappings":""}