@lightdash-tools/mcp 0.7.0 → 0.9.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 (308) hide show
  1. package/README.md +113 -170
  2. package/dist/audit/server-persona.d.ts +10 -0
  3. package/dist/audit/server-persona.js +19 -0
  4. package/dist/auth/oauth-broker/pending-store.d.ts +69 -19
  5. package/dist/auth/oauth-broker/pending-store.js +52 -26
  6. package/dist/auth/oauth-broker/pending-store.test.d.ts +5 -0
  7. package/dist/auth/oauth-broker/pending-store.test.js +109 -0
  8. package/dist/auth/oauth-broker/routes.d.ts +6 -2
  9. package/dist/auth/oauth-broker/routes.js +25 -20
  10. package/dist/auth/oauth-broker/routes.test.js +33 -28
  11. package/dist/auth/request-state-key.d.ts +19 -0
  12. package/dist/auth/request-state-key.js +49 -0
  13. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +0 -2
  14. package/dist/auth/resource-server/lightdash-oauth-middleware.js +0 -19
  15. package/dist/auth/resource-server/www-authenticate.test.js +12 -8
  16. package/dist/bin.js +30 -2
  17. package/dist/config/env.d.ts +5 -8
  18. package/dist/config/env.js +6 -9
  19. package/dist/config/load-mcp-config.d.ts +0 -4
  20. package/dist/config/load-mcp-config.js +8 -5
  21. package/dist/config/load-mcp-config.test.js +7 -0
  22. package/dist/config/normalize-url.test.js +16 -7
  23. package/dist/config/runtime.d.ts +3 -3
  24. package/dist/config/runtime.js +19 -23
  25. package/dist/config/runtime.test.js +23 -9
  26. package/dist/config/test-mcp-http-config.js +1 -1
  27. package/dist/destructive/capability.d.ts +13 -0
  28. package/dist/destructive/capability.js +37 -0
  29. package/dist/destructive/capability.test.js +46 -0
  30. package/dist/destructive/confirmation.d.ts +58 -0
  31. package/dist/destructive/confirmation.js +99 -0
  32. package/dist/destructive/confirmation.test.d.ts +1 -0
  33. package/dist/destructive/confirmation.test.js +75 -0
  34. package/dist/destructive/content-promote.d.ts +8 -0
  35. package/dist/destructive/content-promote.js +150 -0
  36. package/dist/destructive/content-soft-delete.d.ts +7 -0
  37. package/dist/destructive/content-soft-delete.js +106 -0
  38. package/dist/destructive/destructive-contract.test.d.ts +1 -0
  39. package/dist/destructive/destructive-contract.test.js +269 -0
  40. package/dist/destructive/precondition.d.ts +14 -0
  41. package/dist/destructive/precondition.js +31 -0
  42. package/dist/destructive/precondition.test.d.ts +1 -0
  43. package/dist/destructive/precondition.test.js +72 -0
  44. package/dist/destructive/promote-contract.test.d.ts +1 -0
  45. package/dist/destructive/promote-contract.test.js +398 -0
  46. package/dist/destructive/register-destructive-tool.d.ts +54 -0
  47. package/dist/destructive/register-destructive-tool.js +283 -0
  48. package/dist/destructive/request-state.d.ts +12 -0
  49. package/dist/destructive/request-state.js +41 -0
  50. package/dist/destructive/types.d.ts +65 -0
  51. package/dist/destructive/types.js +10 -0
  52. package/dist/governance/available-projects.d.ts +37 -0
  53. package/dist/governance/available-projects.js +132 -0
  54. package/dist/governance/available-projects.test.d.ts +4 -0
  55. package/dist/governance/available-projects.test.js +107 -0
  56. package/dist/governance/client-capabilities-cache.d.ts +44 -0
  57. package/dist/governance/client-capabilities-cache.js +142 -0
  58. package/dist/governance/client-capabilities-cache.test.d.ts +1 -0
  59. package/dist/governance/client-capabilities-cache.test.js +148 -0
  60. package/dist/governance/mcp-client-session.d.ts +10 -0
  61. package/dist/governance/mcp-client-session.js +31 -0
  62. package/dist/governance/mcp-client-session.test.d.ts +1 -0
  63. package/dist/governance/mcp-client-session.test.js +31 -0
  64. package/dist/governance/project-scope.d.ts +24 -0
  65. package/dist/governance/project-scope.js +71 -0
  66. package/dist/governance/project-scope.test.d.ts +4 -0
  67. package/dist/governance/project-scope.test.js +80 -0
  68. package/dist/governance/promote-allowlist.d.ts +18 -0
  69. package/dist/governance/promote-allowlist.js +66 -0
  70. package/dist/governance/promote-allowlist.test.d.ts +4 -0
  71. package/dist/governance/promote-allowlist.test.js +87 -0
  72. package/dist/http.integration.test.js +151 -262
  73. package/dist/http.test.js +0 -12
  74. package/dist/index.integration.test.js +0 -4
  75. package/dist/index.js +3 -1
  76. package/dist/personas/ai-agent-ops/v1/index.d.ts +8 -0
  77. package/dist/personas/ai-agent-ops/v1/index.js +41 -0
  78. package/dist/personas/ai-agent-ops/v1/prompts.d.ts +5 -0
  79. package/dist/personas/ai-agent-ops/v1/prompts.js +141 -0
  80. package/dist/personas/ai-agent-ops/v1/prompts.test.d.ts +4 -0
  81. package/dist/personas/ai-agent-ops/v1/prompts.test.js +26 -0
  82. package/dist/personas/ai-agent-ops/v1/resources/playbooks/core.md +39 -0
  83. package/dist/personas/ai-agent-ops/v1/resources/playbooks/evaluation.md +25 -0
  84. package/dist/personas/ai-agent-ops/v1/resources/playbooks/index.md +14 -0
  85. package/dist/personas/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +28 -0
  86. package/dist/personas/ai-agent-ops/v1/resources/playbooks/release-gate.md +22 -0
  87. package/dist/personas/ai-agent-ops/v1/resources/playbooks.d.ts +10 -0
  88. package/dist/personas/ai-agent-ops/v1/resources/playbooks.js +41 -0
  89. package/dist/personas/content-developer/v1/index.d.ts +10 -0
  90. package/dist/personas/content-developer/v1/index.js +52 -0
  91. package/dist/personas/content-developer/v1/prompts.d.ts +8 -0
  92. package/dist/personas/content-developer/v1/prompts.js +157 -0
  93. package/dist/personas/content-developer/v1/prompts.test.d.ts +4 -0
  94. package/dist/personas/content-developer/v1/prompts.test.js +231 -0
  95. package/dist/personas/content-developer/v1/resources/playbooks/chart-types.md +123 -0
  96. package/dist/personas/content-developer/v1/resources/playbooks/content-move.md +22 -0
  97. package/dist/personas/content-developer/v1/resources/playbooks/core.md +105 -0
  98. package/dist/personas/content-developer/v1/resources/playbooks/dashboard-design.md +153 -0
  99. package/dist/personas/content-developer/v1/resources/playbooks/dashboards.md +103 -0
  100. package/dist/personas/content-developer/v1/resources/playbooks/index.md +15 -0
  101. package/dist/personas/content-developer/v1/resources/playbooks.d.ts +10 -0
  102. package/dist/personas/content-developer/v1/resources/playbooks.js +63 -0
  103. package/dist/personas/content-governance/v1/index.d.ts +9 -0
  104. package/dist/personas/content-governance/v1/index.js +29 -0
  105. package/dist/personas/content-governance/v1/prompts.d.ts +5 -0
  106. package/dist/personas/content-governance/v1/prompts.js +87 -0
  107. package/dist/personas/content-governance/v1/prompts.test.d.ts +4 -0
  108. package/dist/personas/content-governance/v1/prompts.test.js +75 -0
  109. package/dist/personas/content-governance/v1/resources/playbooks/charts.md +29 -0
  110. package/dist/personas/content-governance/v1/resources/playbooks/core.md +52 -0
  111. package/dist/personas/content-governance/v1/resources/playbooks/dashboards.md +48 -0
  112. package/dist/personas/content-governance/v1/resources/playbooks/index.md +13 -0
  113. package/dist/personas/content-governance/v1/resources/playbooks.d.ts +10 -0
  114. package/dist/personas/content-governance/v1/resources/playbooks.js +41 -0
  115. package/dist/personas/content-reader/v1/index.d.ts +8 -0
  116. package/dist/personas/content-reader/v1/index.js +38 -0
  117. package/dist/personas/content-reader/v1/prompts.d.ts +5 -0
  118. package/dist/personas/content-reader/v1/prompts.js +162 -0
  119. package/dist/personas/content-reader/v1/prompts.test.d.ts +4 -0
  120. package/dist/personas/content-reader/v1/prompts.test.js +25 -0
  121. package/dist/personas/content-reader/v1/resources/playbooks/compare.md +36 -0
  122. package/dist/personas/content-reader/v1/resources/playbooks/core.md +67 -0
  123. package/dist/personas/content-reader/v1/resources/playbooks/discover.md +35 -0
  124. package/dist/personas/content-reader/v1/resources/playbooks/explain-run.md +49 -0
  125. package/dist/personas/content-reader/v1/resources/playbooks/index.md +14 -0
  126. package/dist/personas/content-reader/v1/resources/playbooks.d.ts +10 -0
  127. package/dist/personas/content-reader/v1/resources/playbooks.js +49 -0
  128. package/dist/personas/index.d.ts +4 -0
  129. package/dist/personas/index.js +31 -10
  130. package/dist/personas/index.test.js +92 -26
  131. package/dist/personas/lib/playbook-resources.d.ts +80 -0
  132. package/dist/personas/lib/playbook-resources.js +169 -0
  133. package/dist/personas/organization-audit/v1/index.js +2 -2
  134. package/dist/personas/organization-audit/v1/prompts.js +79 -66
  135. package/dist/personas/organization-audit/v1/prompts.test.js +4 -4
  136. package/dist/personas/organization-audit/v1/resources/playbooks/access.md +21 -0
  137. package/dist/personas/organization-audit/v1/resources/playbooks/content.md +19 -0
  138. package/dist/personas/organization-audit/v1/resources/playbooks/core.md +69 -0
  139. package/dist/personas/organization-audit/v1/resources/playbooks/deliveries.md +14 -0
  140. package/dist/personas/organization-audit/v1/resources/playbooks/index.md +14 -0
  141. package/dist/personas/organization-audit/v1/resources/playbooks.d.ts +10 -0
  142. package/dist/personas/organization-audit/v1/resources/playbooks.js +41 -0
  143. package/dist/personas/persona.parity.test.d.ts +1 -0
  144. package/dist/personas/persona.parity.test.js +30 -0
  145. package/dist/personas/semantic-layer/v1/index.js +2 -2
  146. package/dist/personas/semantic-layer/v1/prompts.js +56 -67
  147. package/dist/personas/semantic-layer/v1/prompts.test.d.ts +4 -0
  148. package/dist/personas/semantic-layer/v1/prompts.test.js +19 -0
  149. package/dist/personas/semantic-layer/v1/resources/playbooks/compose-compile.md +60 -0
  150. package/dist/personas/semantic-layer/v1/resources/playbooks/core.md +71 -0
  151. package/dist/personas/semantic-layer/v1/resources/playbooks/explore.md +79 -0
  152. package/dist/personas/semantic-layer/v1/resources/playbooks/index.md +13 -0
  153. package/dist/personas/semantic-layer/v1/resources/playbooks.d.ts +13 -0
  154. package/dist/personas/semantic-layer/v1/resources/playbooks.js +39 -0
  155. package/dist/personas/types.d.ts +1 -1
  156. package/dist/policy/content-developer.d.ts +35 -0
  157. package/dist/policy/content-developer.js +91 -0
  158. package/dist/policy/content-developer.test.d.ts +4 -0
  159. package/dist/policy/content-developer.test.js +54 -0
  160. package/dist/policy/content-reader.d.ts +28 -0
  161. package/dist/policy/content-reader.js +67 -0
  162. package/dist/policy/content-reader.test.d.ts +4 -0
  163. package/dist/policy/content-reader.test.js +23 -0
  164. package/dist/policy/envelope.d.ts +31 -0
  165. package/dist/policy/envelope.js +24 -0
  166. package/dist/policy/preview-ledger-fault.test.d.ts +1 -0
  167. package/dist/policy/preview-ledger-fault.test.js +202 -0
  168. package/dist/policy/preview-ledger.d.ts +82 -0
  169. package/dist/policy/preview-ledger.js +165 -0
  170. package/dist/policy/preview-ledger.test.d.ts +1 -0
  171. package/dist/policy/preview-ledger.test.js +393 -0
  172. package/dist/policy/result-limits.d.ts +32 -0
  173. package/dist/policy/result-limits.js +106 -0
  174. package/dist/policy/result-limits.test.d.ts +4 -0
  175. package/dist/policy/result-limits.test.js +37 -0
  176. package/dist/server/capabilities.js +3 -1
  177. package/dist/server/capabilities.test.js +5 -1
  178. package/dist/server/server.js +16 -1
  179. package/dist/server/upstream-errors.d.ts +17 -0
  180. package/dist/server/upstream-errors.js +60 -0
  181. package/dist/server/upstream-errors.test.d.ts +1 -0
  182. package/dist/server/upstream-errors.test.js +50 -0
  183. package/dist/stdio.process.test.js +150 -0
  184. package/dist/tools/ai-agents/agents.d.ts +7 -0
  185. package/dist/tools/ai-agents/agents.js +32 -0
  186. package/dist/tools/ai-agents/agents.test.d.ts +1 -0
  187. package/dist/tools/ai-agents/agents.test.js +176 -0
  188. package/dist/tools/ai-agents/discovery.d.ts +9 -0
  189. package/dist/tools/ai-agents/discovery.js +73 -0
  190. package/dist/tools/ai-agents/evaluations.d.ts +14 -0
  191. package/dist/tools/ai-agents/evaluations.js +177 -0
  192. package/dist/tools/ai-agents/helpers.d.ts +64 -0
  193. package/dist/tools/ai-agents/helpers.js +323 -0
  194. package/dist/tools/ai-agents/threads.d.ts +7 -0
  195. package/dist/tools/ai-agents/threads.js +40 -0
  196. package/dist/tools/composition/explain-content.d.ts +6 -0
  197. package/dist/tools/composition/explain-content.js +108 -0
  198. package/dist/tools/lib/api-errors.d.ts +2 -0
  199. package/dist/tools/lib/api-errors.js +5 -0
  200. package/dist/tools/lib/stable-stringify.d.ts +9 -0
  201. package/dist/tools/lib/stable-stringify.js +35 -0
  202. package/dist/tools/organization/inventory.js +2 -1
  203. package/dist/tools/project/content.js +5 -1
  204. package/dist/tools/project/delete-chart.d.ts +4 -0
  205. package/dist/tools/project/delete-chart.js +8 -0
  206. package/dist/tools/project/delete-dashboard.d.ts +4 -0
  207. package/dist/tools/project/delete-dashboard.js +8 -0
  208. package/dist/tools/project/developer-content-preview.d.ts +13 -0
  209. package/dist/tools/project/developer-content-preview.js +291 -0
  210. package/dist/tools/project/developer-content-shared.d.ts +24 -0
  211. package/dist/tools/project/developer-content-shared.js +50 -0
  212. package/dist/tools/project/developer-content-shared.test.d.ts +1 -0
  213. package/dist/tools/project/developer-content-shared.test.js +25 -0
  214. package/dist/tools/project/developer-content.d.ts +38 -0
  215. package/dist/tools/project/developer-content.js +589 -0
  216. package/dist/tools/project/developer-get-chart-as-code.d.ts +9 -0
  217. package/dist/tools/project/developer-get-chart-as-code.js +39 -0
  218. package/dist/tools/project/developer-get-chart-as-code.test.d.ts +4 -0
  219. package/dist/tools/project/developer-get-chart-as-code.test.js +70 -0
  220. package/dist/tools/project/developer-helpers.d.ts +180 -0
  221. package/dist/tools/project/developer-helpers.js +484 -0
  222. package/dist/tools/project/developer-helpers.test.d.ts +1 -0
  223. package/dist/tools/project/developer-helpers.test.js +509 -0
  224. package/dist/tools/project/get-dashboard-promote-diff.d.ts +6 -0
  225. package/dist/tools/project/get-dashboard-promote-diff.js +52 -0
  226. package/dist/tools/project/invariants.test.d.ts +4 -0
  227. package/dist/tools/project/invariants.test.js +44 -0
  228. package/dist/tools/project/parameters.d.ts +7 -0
  229. package/dist/tools/project/parameters.js +74 -0
  230. package/dist/tools/project/projects.d.ts +4 -1
  231. package/dist/tools/project/projects.js +68 -6
  232. package/dist/tools/project/projects.test.js +77 -1
  233. package/dist/tools/project/promote-dashboard.d.ts +4 -0
  234. package/dist/tools/project/promote-dashboard.js +8 -0
  235. package/dist/tools/project/reader-content.d.ts +9 -0
  236. package/dist/tools/project/reader-content.js +208 -0
  237. package/dist/tools/project/reader-execution.d.ts +7 -0
  238. package/dist/tools/project/reader-execution.js +214 -0
  239. package/dist/tools/project/reader-export-chart-image.d.ts +6 -0
  240. package/dist/tools/project/reader-export-chart-image.js +78 -0
  241. package/dist/tools/project/reader-export-chart-image.test.d.ts +4 -0
  242. package/dist/tools/project/reader-export-chart-image.test.js +149 -0
  243. package/dist/tools/project/schemas/chart-upsert.d.ts +33 -0
  244. package/dist/tools/project/schemas/chart-upsert.js +66 -0
  245. package/dist/tools/project/schemas/dashboard-tile.d.ts +29 -0
  246. package/dist/tools/project/schemas/dashboard-tile.js +57 -0
  247. package/dist/tools/project/schemas/dashboard.d.ts +70 -0
  248. package/dist/tools/project/schemas/dashboard.js +101 -0
  249. package/dist/tools/project/schemas/duplicate.d.ts +30 -0
  250. package/dist/tools/project/schemas/duplicate.js +86 -0
  251. package/dist/tools/project/schemas/index.d.ts +7 -0
  252. package/dist/tools/project/schemas/index.js +26 -0
  253. package/dist/tools/project/schemas/parse-helpers.d.ts +14 -0
  254. package/dist/tools/project/schemas/parse-helpers.js +34 -0
  255. package/dist/tools/project/schemas/payload-schemas.test.d.ts +1 -0
  256. package/dist/tools/project/schemas/payload-schemas.test.js +204 -0
  257. package/dist/tools/project/spaces.d.ts +7 -0
  258. package/dist/tools/project/spaces.js +101 -0
  259. package/dist/tools/query/bounded-saved-query.d.ts +37 -0
  260. package/dist/tools/query/bounded-saved-query.js +80 -0
  261. package/dist/tools/query/bounded-saved-query.test.d.ts +4 -0
  262. package/dist/tools/query/bounded-saved-query.test.js +82 -0
  263. package/dist/tools/query/chart-source.d.ts +10 -0
  264. package/dist/tools/query/chart-source.js +36 -0
  265. package/dist/tools/query/chart-source.test.d.ts +1 -0
  266. package/dist/tools/query/chart-source.test.js +62 -0
  267. package/dist/tools/query/filter-overrides.d.ts +34 -0
  268. package/dist/tools/query/filter-overrides.js +75 -0
  269. package/dist/tools/query/filter-overrides.test.d.ts +1 -0
  270. package/dist/tools/query/filter-overrides.test.js +21 -0
  271. package/dist/tools/query/lifecycle.d.ts +7 -0
  272. package/dist/tools/query/lifecycle.js +104 -0
  273. package/dist/tools/query/query-ledger.d.ts +41 -0
  274. package/dist/tools/query/query-ledger.js +92 -0
  275. package/dist/tools/query/query-ledger.test.d.ts +1 -0
  276. package/dist/tools/query/query-ledger.test.js +75 -0
  277. package/dist/tools/query/reader-tool-helpers.d.ts +12 -0
  278. package/dist/tools/query/reader-tool-helpers.js +57 -0
  279. package/dist/tools/query/reader-tool-helpers.test.d.ts +1 -0
  280. package/dist/tools/query/reader-tool-helpers.test.js +53 -0
  281. package/dist/tools/query/result-normalizer.d.ts +27 -0
  282. package/dist/tools/query/result-normalizer.js +133 -0
  283. package/dist/tools/query/result-normalizer.test.d.ts +1 -0
  284. package/dist/tools/query/result-normalizer.test.js +41 -0
  285. package/dist/tools/query/wait-for-async.d.ts +10 -0
  286. package/dist/tools/query/wait-for-async.js +46 -0
  287. package/dist/tools/query/wait-for-async.test.d.ts +1 -0
  288. package/dist/tools/query/wait-for-async.test.js +45 -0
  289. package/dist/tools/registry.d.ts +187 -3
  290. package/dist/tools/registry.js +89 -7
  291. package/dist/tools/shared.d.ts +52 -10
  292. package/dist/tools/shared.js +127 -41
  293. package/dist/tools/shared.test.js +103 -3
  294. package/dist/transports/streamable-http.js +47 -198
  295. package/dist/transports/streamable-http.test.js +21 -9
  296. package/package.json +5 -5
  297. package/dist/personas/organization-audit/v1/resources/playbook.d.ts +0 -11
  298. package/dist/personas/organization-audit/v1/resources/playbook.js +0 -40
  299. package/dist/personas/organization-audit/v1/resources/playbook.md +0 -52
  300. package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +0 -12
  301. package/dist/personas/semantic-layer/v1/resources/playbook.js +0 -42
  302. package/dist/personas/semantic-layer/v1/resources/playbook.md +0 -153
  303. package/dist/transports/http-request-utils.d.ts +0 -2
  304. package/dist/transports/http-request-utils.js +0 -13
  305. package/dist/transports/session-store.d.ts +0 -40
  306. package/dist/transports/session-store.js +0 -88
  307. package/dist/transports/session-store.test.js +0 -111
  308. /package/dist/{transports/session-store.test.d.ts → destructive/capability.test.d.ts} +0 -0
@@ -0,0 +1,484 @@
1
+ "use strict";
2
+ /**
3
+ * Pure helpers for content-developer diffing and dashboard tile-array composition
4
+ * (ADR-0014). No I/O except optional injected getters; safe to unit test without mocks.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TileNotFoundError = exports.stableStringify = void 0;
8
+ exports.shallowDiff = shallowDiff;
9
+ exports.applyTileAdd = applyTileAdd;
10
+ exports.applyTileMove = applyTileMove;
11
+ exports.applyTileRemove = applyTileRemove;
12
+ exports.applyTileResize = applyTileResize;
13
+ exports.buildDashboardUpdateBody = buildDashboardUpdateBody;
14
+ exports.resolveCompareVersionIds = resolveCompareVersionIds;
15
+ exports.assertMoveContentLengths = assertMoveContentLengths;
16
+ exports.buildMoveContentResourceKey = buildMoveContentResourceKey;
17
+ exports.buildMoveContentProposal = buildMoveContentProposal;
18
+ exports.buildMoveContentItem = buildMoveContentItem;
19
+ exports.sortByUuidStable = sortByUuidStable;
20
+ exports.buildMoveContentManifest = buildMoveContentManifest;
21
+ exports.moveContentItemFromSummary = moveContentItemFromSummary;
22
+ exports.moveContentTargetSpaceFromRecord = moveContentTargetSpaceFromRecord;
23
+ exports.matchMoveContentResolved = matchMoveContentResolved;
24
+ exports.baselineFromMoveContentManifest = baselineFromMoveContentManifest;
25
+ exports.resolveMoveContentManifest = resolveMoveContentManifest;
26
+ exports.resolveConcurrentLookups = resolveConcurrentLookups;
27
+ exports.baselineFromResource = baselineFromResource;
28
+ exports.resolveChartPreviewCurrent = resolveChartPreviewCurrent;
29
+ exports.fetchChartBaselineOptional = fetchChartBaselineOptional;
30
+ const stable_stringify_js_1 = require("../lib/stable-stringify.js");
31
+ Object.defineProperty(exports, "stableStringify", { enumerable: true, get: function () { return stable_stringify_js_1.stableStringify; } });
32
+ /** Top-level key diff between two objects (added/removed/changed keys). */
33
+ function shallowDiff(before, after) {
34
+ const beforeRecord = (0, stable_stringify_js_1.isRecord)(before) ? before : {};
35
+ const afterRecord = (0, stable_stringify_js_1.isRecord)(after) ? after : {};
36
+ const beforeKeys = new Set(Object.keys(beforeRecord));
37
+ const afterKeys = new Set(Object.keys(afterRecord));
38
+ const added = [];
39
+ const changed = [];
40
+ for (const key of afterKeys) {
41
+ if (!beforeKeys.has(key)) {
42
+ added.push(key);
43
+ }
44
+ else if (
45
+ // eslint-disable-next-line security/detect-object-injection -- key comes from Object.keys of the same record
46
+ (0, stable_stringify_js_1.stableStringify)(beforeRecord[key]) !== (0, stable_stringify_js_1.stableStringify)(afterRecord[key])) {
47
+ changed.push(key);
48
+ }
49
+ }
50
+ const removed = [];
51
+ for (const key of beforeKeys) {
52
+ if (!afterKeys.has(key)) {
53
+ removed.push(key);
54
+ }
55
+ }
56
+ return { added: added.sort(), removed: removed.sort(), changed: changed.sort() };
57
+ }
58
+ /** Dashboard tiles are identified by `uuid` or the legacy `tileUuid` alias. */
59
+ function tileUuidOf(tile) {
60
+ var _a;
61
+ const uuid = (_a = tile.uuid) !== null && _a !== void 0 ? _a : tile.tileUuid;
62
+ return typeof uuid === 'string' ? uuid : undefined;
63
+ }
64
+ class TileNotFoundError extends Error {
65
+ constructor(tileUuid) {
66
+ super(`Tile '${tileUuid}' was not found in the dashboard's tile array`);
67
+ this.name = 'TileNotFoundError';
68
+ }
69
+ }
70
+ exports.TileNotFoundError = TileNotFoundError;
71
+ /** Append a new tile to the tile array. */
72
+ function applyTileAdd(tiles, tile) {
73
+ return [...tiles, tile];
74
+ }
75
+ /** Return a new tile array with `x`/`y` updated on the matching tile. Throws if not found. */
76
+ function applyTileMove(tiles, tileUuid, x, y) {
77
+ let found = false;
78
+ const next = tiles.map((tile) => {
79
+ if (tileUuidOf(tile) !== tileUuid) {
80
+ return tile;
81
+ }
82
+ found = true;
83
+ return Object.assign(Object.assign(Object.assign({}, tile), (x !== undefined ? { x } : {})), (y !== undefined ? { y } : {}));
84
+ });
85
+ if (!found) {
86
+ throw new TileNotFoundError(tileUuid);
87
+ }
88
+ return next;
89
+ }
90
+ /** Return a new tile array with the matching tile removed. Throws if not found. */
91
+ function applyTileRemove(tiles, tileUuid) {
92
+ const next = tiles.filter((tile) => tileUuidOf(tile) !== tileUuid);
93
+ if (next.length === tiles.length) {
94
+ throw new TileNotFoundError(tileUuid);
95
+ }
96
+ return next;
97
+ }
98
+ /** Return a new tile array with `w`/`h` updated on the matching tile. Throws if not found. */
99
+ function applyTileResize(tiles, tileUuid, w, h) {
100
+ let found = false;
101
+ const next = tiles.map((tile) => {
102
+ if (tileUuidOf(tile) !== tileUuid) {
103
+ return tile;
104
+ }
105
+ found = true;
106
+ return Object.assign(Object.assign(Object.assign({}, tile), (w !== undefined ? { w } : {})), (h !== undefined ? { h } : {}));
107
+ });
108
+ if (!found) {
109
+ throw new TileNotFoundError(tileUuid);
110
+ }
111
+ return next;
112
+ }
113
+ /** Merge dashboard field overrides (e.g. `{ tiles }`) onto the current dashboard's editable fields. */
114
+ function buildDashboardUpdateBody(current, overrides) {
115
+ return Object.assign({ name: current.name, description: current.description, tiles: current.tiles, filters: current.filters, tabs: current.tabs, parameters: current.parameters }, overrides);
116
+ }
117
+ /**
118
+ * Resolve two version UUIDs to compare: explicit args when both are given, otherwise
119
+ * the two most recent entries in the version history (descending by `createdAt`).
120
+ * Providing only one of versionUuidA/versionUuidB is rejected.
121
+ */
122
+ function resolveCompareVersionIds(history, versionUuidA, versionUuidB) {
123
+ const hasA = versionUuidA != null && versionUuidA !== '';
124
+ const hasB = versionUuidB != null && versionUuidB !== '';
125
+ if (hasA !== hasB) {
126
+ throw new Error('versionUuidA and versionUuidB must both be provided when specifying explicit versions');
127
+ }
128
+ if (hasA && hasB && versionUuidA && versionUuidB) {
129
+ return [versionUuidA, versionUuidB];
130
+ }
131
+ const sorted = [...history].sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
132
+ const [latest, previous] = sorted;
133
+ if (!latest || !previous) {
134
+ throw new Error('At least two version-history entries are required to compare when versionUuidA/versionUuidB are not both provided');
135
+ }
136
+ return [latest.versionUuid, previous.versionUuid];
137
+ }
138
+ /** Throws when `contentTypes` (required) or `chartSources` (when provided) don't line up 1:1 with `itemUuids`. */
139
+ function assertMoveContentLengths(itemUuids, contentTypes, chartSources) {
140
+ if (contentTypes.length !== itemUuids.length) {
141
+ throw new Error('itemUuids and contentTypes must have the same length');
142
+ }
143
+ if (chartSources && chartSources.length !== itemUuids.length) {
144
+ throw new Error('itemUuids and chartSources must have the same length');
145
+ }
146
+ }
147
+ /** Stable preview/apply `resourceKey` for a content-move (sorted UUIDs, comma-joined). */
148
+ function buildMoveContentResourceKey(itemUuids) {
149
+ return [...itemUuids].sort().join(',');
150
+ }
151
+ /**
152
+ * Build the canonical proposal object hashed into the previewToken contentHash for a content move.
153
+ * Both `preview_content_move` and `move_content` must hash the same shape — including
154
+ * required `contentTypes` and optional `chartSources` — so an apply cannot silently change
155
+ * item types or chart sources versus what was previewed and validated.
156
+ */
157
+ function buildMoveContentProposal(input) {
158
+ var _a;
159
+ return {
160
+ itemUuids: input.itemUuids,
161
+ targetSpaceUuid: input.targetSpaceUuid,
162
+ contentTypes: input.contentTypes,
163
+ chartSources: (_a = input.chartSources) !== null && _a !== void 0 ? _a : null,
164
+ };
165
+ }
166
+ /** Build a single `ItemPayload`-shaped entry for the content bulk-move API. */
167
+ function buildMoveContentItem(uuid, contentType, chartSource) {
168
+ switch (contentType) {
169
+ case 'chart':
170
+ return { contentType: 'chart', uuid, source: chartSource !== null && chartSource !== void 0 ? chartSource : 'dbt_explore' };
171
+ case 'dashboard':
172
+ return { contentType: 'dashboard', uuid };
173
+ case 'data_app':
174
+ return { contentType: 'data_app', uuid };
175
+ default: {
176
+ const exhaustive = contentType;
177
+ throw new Error(`Unsupported content type: ${String(exhaustive)}`);
178
+ }
179
+ }
180
+ }
181
+ const MOVE_CONTENT_TYPE_SET = new Set(['chart', 'dashboard', 'data_app']);
182
+ const MOVE_CHART_SOURCE_SET = new Set(['dbt_explore', 'sql']);
183
+ /** Sort records by `uuid` for hash-stable manifests (localeCompare, ascending). */
184
+ function sortByUuidStable(items) {
185
+ return [...items].sort((a, b) => a.uuid.localeCompare(b.uuid));
186
+ }
187
+ /**
188
+ * Build the canonical move-content baseline manifest (sorted by item UUID).
189
+ * Preview and apply must produce identical shapes for the same server facts.
190
+ */
191
+ function buildMoveContentManifest(input) {
192
+ return {
193
+ items: sortByUuidStable(input.items),
194
+ targetSpace: {
195
+ uuid: input.targetSpace.uuid,
196
+ name: input.targetSpace.name,
197
+ },
198
+ };
199
+ }
200
+ function optionalStringField(record, key) {
201
+ if (!record) {
202
+ return undefined;
203
+ }
204
+ // eslint-disable-next-line security/detect-object-injection -- key is a fixed field name from callers
205
+ const value = record[key];
206
+ return typeof value === 'string' ? value : undefined;
207
+ }
208
+ function chartSourceFromSummary(item) {
209
+ const rawSource = optionalStringField(item, 'source');
210
+ if (rawSource != null && MOVE_CHART_SOURCE_SET.has(rawSource)) {
211
+ return rawSource;
212
+ }
213
+ return 'dbt_explore';
214
+ }
215
+ /**
216
+ * Extract a manifest item from a content-search / SummaryContent-shaped record.
217
+ * Returns null when uuid/contentType are missing or unsupported for bulk move.
218
+ */
219
+ function moveContentItemFromSummary(item) {
220
+ var _a, _b, _c, _d;
221
+ const uuid = optionalStringField(item, 'uuid');
222
+ const contentType = optionalStringField(item, 'contentType');
223
+ if (uuid == null || contentType == null || !MOVE_CONTENT_TYPE_SET.has(contentType)) {
224
+ return null;
225
+ }
226
+ const space = (0, stable_stringify_js_1.isRecord)(item.space) ? item.space : undefined;
227
+ const spaceUuid = (_b = (_a = optionalStringField(space, 'uuid')) !== null && _a !== void 0 ? _a : optionalStringField(item, 'spaceUuid')) !== null && _b !== void 0 ? _b : null;
228
+ const updatedAt = (_d = (_c = optionalStringField(item, 'lastUpdatedAt')) !== null && _c !== void 0 ? _c : optionalStringField(item, 'updatedAt')) !== null && _d !== void 0 ? _d : null;
229
+ return {
230
+ uuid,
231
+ contentType: contentType,
232
+ spaceUuid,
233
+ updatedAt,
234
+ source: contentType === 'chart' ? chartSourceFromSummary(item) : null,
235
+ };
236
+ }
237
+ /** Normalize target-space identity for the move-content baseline. */
238
+ function moveContentTargetSpaceFromRecord(targetSpaceUuid, space) {
239
+ var _a, _b;
240
+ if (targetSpaceUuid == null) {
241
+ return { uuid: null, name: null };
242
+ }
243
+ return {
244
+ uuid: (_a = optionalStringField(space !== null && space !== void 0 ? space : undefined, 'uuid')) !== null && _a !== void 0 ? _a : targetSpaceUuid,
245
+ name: (_b = optionalStringField(space !== null && space !== void 0 ? space : undefined, 'name')) !== null && _b !== void 0 ? _b : null,
246
+ };
247
+ }
248
+ function matchChartSourceAtIndex(uuid, index, resolved, chartSources) {
249
+ var _a, _b;
250
+ // eslint-disable-next-line security/detect-object-injection -- index bound by caller itemUuids.length
251
+ const expectedSource = (_a = chartSources === null || chartSources === void 0 ? void 0 : chartSources[index]) !== null && _a !== void 0 ? _a : 'dbt_explore';
252
+ const actualSource = (_b = resolved.source) !== null && _b !== void 0 ? _b : 'dbt_explore';
253
+ if (actualSource === expectedSource) {
254
+ return null;
255
+ }
256
+ return {
257
+ code: 'INVALID_ARGUMENT',
258
+ message: `Chart '${uuid}' has source '${actualSource}' but chartSources[${String(index)}] ` +
259
+ `is '${expectedSource}'`,
260
+ };
261
+ }
262
+ /**
263
+ * Reject caller contentTypes/chartSources that disagree with resolved server facts.
264
+ * Length checks should already have run via `assertMoveContentLengths`.
265
+ */
266
+ function matchMoveContentResolved(input) {
267
+ const byUuid = new Map(input.resolvedItems.map((item) => [item.uuid, item]));
268
+ for (let index = 0; index < input.itemUuids.length; index += 1) {
269
+ // eslint-disable-next-line security/detect-object-injection -- index bound by itemUuids.length
270
+ const uuid = input.itemUuids[index];
271
+ // eslint-disable-next-line security/detect-object-injection -- index bound by itemUuids.length
272
+ const expectedType = input.contentTypes[index];
273
+ const resolved = byUuid.get(uuid);
274
+ if (!resolved) {
275
+ return {
276
+ code: 'CONTENT_NOT_FOUND',
277
+ message: `Content '${uuid}' was not found while building the move baseline`,
278
+ };
279
+ }
280
+ if (resolved.contentType !== expectedType) {
281
+ return {
282
+ code: 'INVALID_ARGUMENT',
283
+ message: `Content '${uuid}' is type '${resolved.contentType}' but contentTypes[${String(index)}] ` +
284
+ `is '${expectedType}'`,
285
+ };
286
+ }
287
+ if (expectedType === 'chart') {
288
+ const sourceErr = matchChartSourceAtIndex(uuid, index, resolved, input.chartSources);
289
+ if (sourceErr) {
290
+ return sourceErr;
291
+ }
292
+ }
293
+ }
294
+ return null;
295
+ }
296
+ /**
297
+ * Ledger baseline for content-move: `updatedAt` is a fingerprint of the sorted
298
+ * manifest so `assertBaselineStillValid` detects item/space drift on apply.
299
+ */
300
+ function baselineFromMoveContentManifest(manifest) {
301
+ return {
302
+ updatedAt: (0, stable_stringify_js_1.hashStableValue)(manifest),
303
+ uuid: buildMoveContentResourceKey(manifest.items.map((item) => item.uuid)),
304
+ };
305
+ }
306
+ async function resolveMoveItems(itemUuids, findContentByUuid) {
307
+ const summaries = await Promise.all(itemUuids.map((uuid) => findContentByUuid(uuid)));
308
+ const resolvedItems = [];
309
+ for (let index = 0; index < itemUuids.length; index += 1) {
310
+ // eslint-disable-next-line security/detect-object-injection -- index bound by itemUuids.length
311
+ const uuid = itemUuids[index];
312
+ // eslint-disable-next-line security/detect-object-injection -- index bound by Promise.all result
313
+ const summary = summaries[index];
314
+ if (!summary) {
315
+ return {
316
+ kind: 'error',
317
+ error: { code: 'CONTENT_NOT_FOUND', message: `Content '${uuid}' was not found` },
318
+ };
319
+ }
320
+ const item = moveContentItemFromSummary(summary);
321
+ if (!item) {
322
+ return {
323
+ kind: 'error',
324
+ error: {
325
+ code: 'INVALID_ARGUMENT',
326
+ message: `Content '${uuid}' is not a movable chart/dashboard/data_app`,
327
+ },
328
+ };
329
+ }
330
+ if (item.uuid !== uuid) {
331
+ return {
332
+ kind: 'error',
333
+ error: {
334
+ code: 'PREVIEW_STALE',
335
+ message: `Content lookup for '${uuid}' resolved to a different uuid '${item.uuid}'`,
336
+ },
337
+ };
338
+ }
339
+ resolvedItems.push(item);
340
+ }
341
+ return { kind: 'ok', items: resolvedItems };
342
+ }
343
+ async function resolveMoveTargetSpace(input) {
344
+ var _a;
345
+ if (input.targetSpaceUuid == null) {
346
+ return { kind: 'ok', targetSpace: { uuid: null, name: null } };
347
+ }
348
+ try {
349
+ const space = await input.getSpace(input.targetSpaceUuid);
350
+ const targetSpace = moveContentTargetSpaceFromRecord(input.targetSpaceUuid, space);
351
+ if (targetSpace.uuid !== input.targetSpaceUuid) {
352
+ return {
353
+ kind: 'error',
354
+ error: {
355
+ code: 'PREVIEW_STALE',
356
+ message: `Target space '${input.targetSpaceUuid}' resolved to a different uuid ` +
357
+ `'${(_a = targetSpace.uuid) !== null && _a !== void 0 ? _a : 'null'}'`,
358
+ },
359
+ };
360
+ }
361
+ return { kind: 'ok', targetSpace };
362
+ }
363
+ catch (err) {
364
+ if (input.isNotFound(err)) {
365
+ return {
366
+ kind: 'error',
367
+ error: {
368
+ code: 'CONTENT_NOT_FOUND',
369
+ message: `Target space '${input.targetSpaceUuid}' was not found`,
370
+ },
371
+ };
372
+ }
373
+ throw err;
374
+ }
375
+ }
376
+ /**
377
+ * Resolve content + target-space facts into a hard move baseline.
378
+ * `findContentByUuid` / `getSpace` are injected so unit tests need no network.
379
+ */
380
+ async function resolveMoveContentManifest(input) {
381
+ assertMoveContentLengths(input.itemUuids, input.contentTypes, input.chartSources);
382
+ const [itemsResult, targetResult] = await Promise.all([
383
+ resolveMoveItems(input.itemUuids, input.findContentByUuid),
384
+ resolveMoveTargetSpace({
385
+ targetSpaceUuid: input.targetSpaceUuid,
386
+ getSpace: input.getSpace,
387
+ isNotFound: input.isNotFound,
388
+ }),
389
+ ]);
390
+ if (itemsResult.kind === 'error') {
391
+ return itemsResult;
392
+ }
393
+ const mismatch = matchMoveContentResolved({
394
+ itemUuids: input.itemUuids,
395
+ contentTypes: input.contentTypes,
396
+ chartSources: input.chartSources,
397
+ resolvedItems: itemsResult.items,
398
+ });
399
+ if (mismatch) {
400
+ return { kind: 'error', error: mismatch };
401
+ }
402
+ if (targetResult.kind === 'error') {
403
+ return targetResult;
404
+ }
405
+ return {
406
+ kind: 'ok',
407
+ manifest: buildMoveContentManifest({
408
+ items: itemsResult.items,
409
+ targetSpace: targetResult.targetSpace,
410
+ }),
411
+ };
412
+ }
413
+ /**
414
+ * Resolve concurrent source/target lookups while preserving source-not-found precedence.
415
+ * Callers can map `source_not_found` to their resource-specific response.
416
+ */
417
+ function resolveConcurrentLookups(sourceSettled, targetSettled, isNotFound) {
418
+ if (sourceSettled.status === 'rejected') {
419
+ if (isNotFound(sourceSettled.reason)) {
420
+ return { kind: 'source_not_found' };
421
+ }
422
+ return { kind: 'throw', error: sourceSettled.reason };
423
+ }
424
+ if (targetSettled.status === 'rejected') {
425
+ return { kind: 'throw', error: targetSettled.reason };
426
+ }
427
+ return { kind: 'ok', source: sourceSettled.value, target: targetSettled.value };
428
+ }
429
+ /** Extract preview/apply baseline fields from a saved resource record. */
430
+ function baselineFromResource(resource) {
431
+ if (!resource) {
432
+ return undefined;
433
+ }
434
+ const updatedAt = typeof resource.updatedAt === 'string' ? resource.updatedAt : undefined;
435
+ const uuid = typeof resource.uuid === 'string' ? resource.uuid : undefined;
436
+ const slug = typeof resource.slug === 'string' ? resource.slug : undefined;
437
+ if (updatedAt == null && uuid == null && slug == null) {
438
+ return undefined;
439
+ }
440
+ return { updatedAt, uuid, slug };
441
+ }
442
+ /**
443
+ * Resolve the saved chart for a preview: update path uses chartUuidOrSlug;
444
+ * create path (slug only) rejects when that slug already exists.
445
+ * `getSavedChart` / `isNotFound` are injected so unit tests need no network.
446
+ */
447
+ async function resolveChartPreviewCurrent(input) {
448
+ if (input.chartUuidOrSlug) {
449
+ return { kind: 'ok', current: await input.getSavedChart(input.chartUuidOrSlug) };
450
+ }
451
+ if (input.slug == null || input.slug === '') {
452
+ return { kind: 'ok', current: null };
453
+ }
454
+ try {
455
+ await input.getSavedChart(input.slug);
456
+ return {
457
+ kind: 'error',
458
+ code: 'CHART_SLUG_EXISTS',
459
+ message: `Chart slug '${input.slug}' already exists; pass chartUuidOrSlug and use the update path ` +
460
+ '(preview_chart_changes → confirm_preview → update_chart)',
461
+ };
462
+ }
463
+ catch (err) {
464
+ if (input.isNotFound(err)) {
465
+ return { kind: 'ok', current: null };
466
+ }
467
+ throw err;
468
+ }
469
+ }
470
+ /**
471
+ * Apply-time optional chart baseline: 404 → undefined (create still free);
472
+ * found → baseline for PREVIEW_STALE race / update drift checks.
473
+ */
474
+ async function fetchChartBaselineOptional(input) {
475
+ try {
476
+ return baselineFromResource(await input.getSavedChart(input.chartUuidOrSlug));
477
+ }
478
+ catch (err) {
479
+ if (input.isNotFound(err)) {
480
+ return undefined;
481
+ }
482
+ throw err;
483
+ }
484
+ }
@@ -0,0 +1 @@
1
+ export {};