@rfc0/patty 0.0.0-stage → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (465) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +214 -2
  3. package/dist/adapters/access-tokens.js +7 -0
  4. package/dist/adapters/accounts.js +37 -0
  5. package/dist/adapters/auth.js +11 -0
  6. package/dist/adapters/bills.js +32 -0
  7. package/dist/adapters/budgets.js +29 -0
  8. package/dist/adapters/categories.js +32 -0
  9. package/dist/adapters/client-grants.js +7 -0
  10. package/dist/adapters/credit-cards.js +33 -0
  11. package/dist/adapters/currencies.js +2 -0
  12. package/dist/adapters/currency-rates.js +18 -0
  13. package/dist/adapters/dashboards.js +43 -0
  14. package/dist/adapters/demo.js +13 -0
  15. package/dist/adapters/instance-settings.js +7 -0
  16. package/dist/adapters/invites.js +7 -0
  17. package/dist/adapters/recurring.js +55 -0
  18. package/dist/adapters/sessions.js +7 -0
  19. package/dist/adapters/settings.js +4 -0
  20. package/dist/adapters/setup-codes.js +7 -0
  21. package/dist/adapters/tags.js +9 -0
  22. package/dist/adapters/transactions.js +95 -0
  23. package/dist/adapters/users.js +7 -0
  24. package/dist/common/build-version.js +5 -0
  25. package/dist/common/errors.js +118 -0
  26. package/dist/common/net.js +71 -0
  27. package/dist/common/result.js +7 -0
  28. package/dist/composition/auth.js +106 -0
  29. package/dist/composition/boot.js +27 -0
  30. package/dist/composition/cli.js +86 -0
  31. package/dist/composition/demo/seed.js +92 -0
  32. package/dist/composition/demo/shell.js +107 -0
  33. package/dist/composition/export.js +89 -0
  34. package/dist/composition/http.js +110 -0
  35. package/dist/composition/import.js +55 -0
  36. package/dist/composition/lazy-modules.js +2 -0
  37. package/dist/composition/runtime.js +115 -0
  38. package/dist/composition/sign-in/interpreter.js +154 -0
  39. package/dist/composition/sign-in/server.js +36 -0
  40. package/dist/composition/sign-in/wiring.js +23 -0
  41. package/dist/composition/stdio.js +69 -0
  42. package/dist/config.js +136 -0
  43. package/dist/controllers/account/account.js +88 -0
  44. package/dist/controllers/account/transaction.js +119 -0
  45. package/dist/controllers/account/transfer.js +34 -0
  46. package/dist/controllers/aggregate.js +40 -0
  47. package/dist/controllers/auth/access-tokens.js +61 -0
  48. package/dist/controllers/auth/grants.js +136 -0
  49. package/dist/controllers/auth/key-export.js +20 -0
  50. package/dist/controllers/auth/owner.js +80 -0
  51. package/dist/controllers/auth/password.js +35 -0
  52. package/dist/controllers/auth/session.js +50 -0
  53. package/dist/controllers/auth/step-up.js +8 -0
  54. package/dist/controllers/auth/users.js +183 -0
  55. package/dist/controllers/budgets.js +87 -0
  56. package/dist/controllers/categories.js +67 -0
  57. package/dist/controllers/correlations.js +112 -0
  58. package/dist/controllers/credit-card/bill.js +105 -0
  59. package/dist/controllers/credit-card/credit-card.js +129 -0
  60. package/dist/controllers/credit-card/transaction.js +181 -0
  61. package/dist/controllers/currencies.js +1 -0
  62. package/dist/controllers/currency-rates.js +40 -0
  63. package/dist/controllers/dashboards.js +68 -0
  64. package/dist/controllers/demo/seed.js +31 -0
  65. package/dist/controllers/demo/tour.js +12 -0
  66. package/dist/controllers/deps.js +6 -0
  67. package/dist/controllers/instance.js +6 -0
  68. package/dist/controllers/merchants.js +12 -0
  69. package/dist/controllers/recurring.js +70 -0
  70. package/dist/controllers/resolve.js +37 -0
  71. package/dist/controllers/settings.js +47 -0
  72. package/dist/controllers/status.js +19 -0
  73. package/dist/controllers/summary.js +21 -0
  74. package/dist/controllers/tags.js +19 -0
  75. package/dist/controllers/transaction/bulk.js +6 -0
  76. package/dist/controllers/transaction/core.js +49 -0
  77. package/dist/controllers/transaction/read.js +28 -0
  78. package/dist/diplomat/auth/credentials.js +58 -0
  79. package/dist/diplomat/auth/sign-in-store.js +18 -0
  80. package/dist/diplomat/cli/commands/auth.js +100 -0
  81. package/dist/diplomat/cli/commands/db.js +72 -0
  82. package/dist/diplomat/cli/commands/demo.js +68 -0
  83. package/dist/diplomat/cli/commands/key.js +119 -0
  84. package/dist/diplomat/cli/commands/login.js +151 -0
  85. package/dist/diplomat/cli/commands/setup.js +132 -0
  86. package/dist/diplomat/cli/commands/users.js +123 -0
  87. package/dist/diplomat/cli/commands.js +61 -0
  88. package/dist/diplomat/cli/export-file.js +37 -0
  89. package/dist/diplomat/cli/import-file.js +44 -0
  90. package/dist/diplomat/cli/io.js +61 -0
  91. package/dist/diplomat/cli/key-export-approval.js +37 -0
  92. package/dist/diplomat/cli/messages.js +96 -0
  93. package/dist/diplomat/cli/prompt.js +74 -0
  94. package/dist/diplomat/cli/terminal.js +81 -0
  95. package/dist/diplomat/client-config/clients.js +150 -0
  96. package/dist/diplomat/client-config/merge.js +41 -0
  97. package/dist/diplomat/db/bootstrap.js +98 -0
  98. package/dist/diplomat/db/database-files.js +147 -0
  99. package/dist/diplomat/db/driver.js +167 -0
  100. package/dist/diplomat/db/effects.js +101 -0
  101. package/dist/diplomat/db/engine.js +9 -0
  102. package/dist/diplomat/db/export.js +22 -0
  103. package/dist/diplomat/db/file-lock.js +82 -0
  104. package/dist/diplomat/db/key-lock.js +14 -0
  105. package/dist/diplomat/db/locale-cache.js +23 -0
  106. package/dist/diplomat/db/migration-barrier.js +57 -0
  107. package/dist/diplomat/db/migration-journal.js +18 -0
  108. package/dist/diplomat/db/migration-lock.js +15 -0
  109. package/dist/diplomat/db/migrations.js +11 -0
  110. package/dist/diplomat/db/present.js +17 -0
  111. package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
  112. package/dist/diplomat/db/queries/filters.js +59 -0
  113. package/dist/diplomat/db/queries/fts.js +18 -0
  114. package/dist/diplomat/db/queries/scope.js +8 -0
  115. package/dist/diplomat/db/queries/transaction-select.js +26 -0
  116. package/dist/diplomat/db/queries/tx-predicates.js +13 -0
  117. package/dist/diplomat/db/repos/access-tokens.js +27 -0
  118. package/dist/diplomat/db/repos/accounts.js +91 -0
  119. package/dist/diplomat/db/repos/bills.js +93 -0
  120. package/dist/diplomat/db/repos/budgets.js +72 -0
  121. package/dist/diplomat/db/repos/categories.js +53 -0
  122. package/dist/diplomat/db/repos/client-grants.js +67 -0
  123. package/dist/diplomat/db/repos/correlations.js +66 -0
  124. package/dist/diplomat/db/repos/credit-cards.js +67 -0
  125. package/dist/diplomat/db/repos/currencies.js +8 -0
  126. package/dist/diplomat/db/repos/currency-rates.js +40 -0
  127. package/dist/diplomat/db/repos/dashboards.js +123 -0
  128. package/dist/diplomat/db/repos/health.js +12 -0
  129. package/dist/diplomat/db/repos/instance-settings.js +14 -0
  130. package/dist/diplomat/db/repos/instance.js +58 -0
  131. package/dist/diplomat/db/repos/invites.js +43 -0
  132. package/dist/diplomat/db/repos/merchants.js +121 -0
  133. package/dist/diplomat/db/repos/recurring.js +29 -0
  134. package/dist/diplomat/db/repos/sessions.js +19 -0
  135. package/dist/diplomat/db/repos/settings.js +41 -0
  136. package/dist/diplomat/db/repos/setup-codes.js +28 -0
  137. package/dist/diplomat/db/repos/sub-categories.js +67 -0
  138. package/dist/diplomat/db/repos/tags.js +51 -0
  139. package/dist/diplomat/db/repos/transaction-tags.js +57 -0
  140. package/dist/diplomat/db/repos/transactions.js +163 -0
  141. package/dist/diplomat/db/repos/users.js +47 -0
  142. package/dist/diplomat/db/safety-copy.js +87 -0
  143. package/dist/diplomat/db/schema.js +348 -0
  144. package/dist/diplomat/db/seed/categories.js +112 -0
  145. package/dist/diplomat/db/seed/currencies.js +9 -0
  146. package/dist/diplomat/db/seed/demo/br.js +98 -0
  147. package/dist/diplomat/db/seed/demo/co.js +89 -0
  148. package/dist/diplomat/db/seed/demo/index.js +12 -0
  149. package/dist/diplomat/db/seed/demo/mx.js +90 -0
  150. package/dist/diplomat/db/seed/demo/shared.js +39 -0
  151. package/dist/diplomat/db/seed/demo/us.js +90 -0
  152. package/dist/diplomat/db/seed/merchant-rules.js +188 -0
  153. package/dist/diplomat/db/sqlite-errors.js +40 -0
  154. package/dist/diplomat/db/tenancy-integrity.js +45 -0
  155. package/dist/diplomat/db/version-guard.js +16 -0
  156. package/dist/diplomat/http/auth-pages.js +41 -0
  157. package/dist/diplomat/http/auth-paths.js +46 -0
  158. package/dist/diplomat/http/bearer.js +15 -0
  159. package/dist/diplomat/http/connect-pages.js +51 -0
  160. package/dist/diplomat/http/context.js +17 -0
  161. package/dist/diplomat/http/cookies.js +27 -0
  162. package/dist/diplomat/http/form-pages.js +38 -0
  163. package/dist/diplomat/http/hooks/auth.js +106 -0
  164. package/dist/diplomat/http/hooks/demo-marker.js +59 -0
  165. package/dist/diplomat/http/openapi.js +73 -0
  166. package/dist/diplomat/http/principal.js +1 -0
  167. package/dist/diplomat/http/rate-limiter.js +78 -0
  168. package/dist/diplomat/http/remedy.js +26 -0
  169. package/dist/diplomat/http/respond.js +50 -0
  170. package/dist/diplomat/http/routes/account.js +226 -0
  171. package/dist/diplomat/http/routes/aggregate.js +28 -0
  172. package/dist/diplomat/http/routes/auth.js +105 -0
  173. package/dist/diplomat/http/routes/budget.js +34 -0
  174. package/dist/diplomat/http/routes/category.js +109 -0
  175. package/dist/diplomat/http/routes/connect.js +124 -0
  176. package/dist/diplomat/http/routes/credit-card.js +263 -0
  177. package/dist/diplomat/http/routes/currency-rates.js +60 -0
  178. package/dist/diplomat/http/routes/currency.js +16 -0
  179. package/dist/diplomat/http/routes/dashboard.js +93 -0
  180. package/dist/diplomat/http/routes/invite.js +63 -0
  181. package/dist/diplomat/http/routes/recurring.js +65 -0
  182. package/dist/diplomat/http/routes/settings.js +38 -0
  183. package/dist/diplomat/http/routes/summary.js +23 -0
  184. package/dist/diplomat/http/routes/system.js +29 -0
  185. package/dist/diplomat/http/routes/tag.js +51 -0
  186. package/dist/diplomat/http/routes/tokens.js +72 -0
  187. package/dist/diplomat/http/routes/transaction.js +55 -0
  188. package/dist/diplomat/http/routes/transfer.js +35 -0
  189. package/dist/diplomat/http/routes/ui.js +110 -0
  190. package/dist/diplomat/http/routes/users.js +156 -0
  191. package/dist/diplomat/http/routes/well-known.js +26 -0
  192. package/dist/diplomat/http/routes.js +85 -0
  193. package/dist/diplomat/http/session.js +34 -0
  194. package/dist/diplomat/http/token-pages.js +75 -0
  195. package/dist/diplomat/http/ui-files.js +21 -0
  196. package/dist/diplomat/http/user-pages.js +93 -0
  197. package/dist/diplomat/mcp/annotations.js +8 -0
  198. package/dist/diplomat/mcp/auth-info.js +20 -0
  199. package/dist/diplomat/mcp/context.js +14 -0
  200. package/dist/diplomat/mcp/definition.js +3 -0
  201. package/dist/diplomat/mcp/gate.js +15 -0
  202. package/dist/diplomat/mcp/instructions.js +19 -0
  203. package/dist/diplomat/mcp/prompts.js +125 -0
  204. package/dist/diplomat/mcp/register.js +12 -0
  205. package/dist/diplomat/mcp/remedy.js +17 -0
  206. package/dist/diplomat/mcp/resources.js +93 -0
  207. package/dist/diplomat/mcp/respond.js +20 -0
  208. package/dist/diplomat/mcp/route.js +62 -0
  209. package/dist/diplomat/mcp/scopes.js +53 -0
  210. package/dist/diplomat/mcp/server.js +26 -0
  211. package/dist/diplomat/mcp/shared.js +5 -0
  212. package/dist/diplomat/mcp/stdio-session.js +94 -0
  213. package/dist/diplomat/mcp/stdio.js +23 -0
  214. package/dist/diplomat/mcp/tool-name.js +59 -0
  215. package/dist/diplomat/mcp/tools/account.js +218 -0
  216. package/dist/diplomat/mcp/tools/aggregate.js +32 -0
  217. package/dist/diplomat/mcp/tools/budget.js +99 -0
  218. package/dist/diplomat/mcp/tools/category.js +103 -0
  219. package/dist/diplomat/mcp/tools/correlations.js +70 -0
  220. package/dist/diplomat/mcp/tools/credit-card.js +239 -0
  221. package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
  222. package/dist/diplomat/mcp/tools/dashboard.js +75 -0
  223. package/dist/diplomat/mcp/tools/index.js +31 -0
  224. package/dist/diplomat/mcp/tools/recurring.js +62 -0
  225. package/dist/diplomat/mcp/tools/summary.js +30 -0
  226. package/dist/diplomat/mcp/tools/system.js +83 -0
  227. package/dist/diplomat/mcp/tools/tag.js +48 -0
  228. package/dist/diplomat/mcp/tools/transaction.js +53 -0
  229. package/dist/diplomat/mcp/tools/transfer.js +28 -0
  230. package/dist/diplomat/mcp/tour.js +87 -0
  231. package/dist/logic/account.js +79 -0
  232. package/dist/logic/aggregate.js +37 -0
  233. package/dist/logic/auth/bearer.js +35 -0
  234. package/dist/logic/auth/grant.js +126 -0
  235. package/dist/logic/auth/key-export.js +10 -0
  236. package/dist/logic/auth/keychain.js +3 -0
  237. package/dist/logic/auth/message.js +22 -0
  238. package/dist/logic/auth/origin.js +57 -0
  239. package/dist/logic/auth/owner.js +22 -0
  240. package/dist/logic/auth/password.js +3 -0
  241. package/dist/logic/auth/redact.js +25 -0
  242. package/dist/logic/auth/revoke.js +28 -0
  243. package/dist/logic/auth/scope.js +17 -0
  244. package/dist/logic/auth/session.js +30 -0
  245. package/dist/logic/auth/sign-in-flow.js +305 -0
  246. package/dist/logic/auth/time.js +2 -0
  247. package/dist/logic/auth/token.js +74 -0
  248. package/dist/logic/auth/user-plans.js +84 -0
  249. package/dist/logic/auth/users.js +78 -0
  250. package/dist/logic/balance.js +2 -0
  251. package/dist/logic/bill.js +74 -0
  252. package/dist/logic/budget.js +78 -0
  253. package/dist/logic/category.js +37 -0
  254. package/dist/logic/classify.js +21 -0
  255. package/dist/logic/correlations.js +147 -0
  256. package/dist/logic/credit-card.js +2 -0
  257. package/dist/logic/currency-rate.js +69 -0
  258. package/dist/logic/dashboard.js +40 -0
  259. package/dist/logic/demo/database.js +30 -0
  260. package/dist/logic/demo/plan.js +308 -0
  261. package/dist/logic/demo/tour.js +33 -0
  262. package/dist/logic/export-destination.js +12 -0
  263. package/dist/logic/key-import.js +15 -0
  264. package/dist/logic/locale.js +5 -0
  265. package/dist/logic/localize.js +12 -0
  266. package/dist/logic/merchant.js +31 -0
  267. package/dist/logic/migration.js +1 -0
  268. package/dist/logic/money.js +12 -0
  269. package/dist/logic/period.js +45 -0
  270. package/dist/logic/persistence.js +48 -0
  271. package/dist/logic/recurring.js +51 -0
  272. package/dist/logic/resolve.js +44 -0
  273. package/dist/logic/summary.js +29 -0
  274. package/dist/logic/tag.js +13 -0
  275. package/dist/logic/transaction.js +197 -0
  276. package/dist/main.js +42 -0
  277. package/dist/models/account.js +197 -0
  278. package/dist/models/aggregate.js +61 -0
  279. package/dist/models/auth/bearer.js +11 -0
  280. package/dist/models/auth/entity.js +17 -0
  281. package/dist/models/auth/errors.js +42 -0
  282. package/dist/models/auth/grant.js +58 -0
  283. package/dist/models/auth/key-export.js +11 -0
  284. package/dist/models/auth/message.js +50 -0
  285. package/dist/models/auth/mode.js +7 -0
  286. package/dist/models/auth/origin.js +16 -0
  287. package/dist/models/auth/owner.js +36 -0
  288. package/dist/models/auth/password.js +24 -0
  289. package/dist/models/auth/principal.js +26 -0
  290. package/dist/models/auth/redact.js +4 -0
  291. package/dist/models/auth/scope.js +9 -0
  292. package/dist/models/auth/session.js +19 -0
  293. package/dist/models/auth/sign-in-flow.js +102 -0
  294. package/dist/models/auth/sign-in.js +41 -0
  295. package/dist/models/auth/time.js +5 -0
  296. package/dist/models/auth/token.js +50 -0
  297. package/dist/models/auth/users.js +52 -0
  298. package/dist/models/bill.js +55 -0
  299. package/dist/models/budget.js +106 -0
  300. package/dist/models/category.js +52 -0
  301. package/dist/models/client-config.js +18 -0
  302. package/dist/models/correlations.js +215 -0
  303. package/dist/models/credit-card.js +156 -0
  304. package/dist/models/currency-rate.js +83 -0
  305. package/dist/models/dashboard.js +54 -0
  306. package/dist/models/database.js +16 -0
  307. package/dist/models/date.js +8 -0
  308. package/dist/models/demo/core.js +58 -0
  309. package/dist/models/demo/tour.js +41 -0
  310. package/dist/models/encryption-key.js +2 -0
  311. package/dist/models/error.js +13 -0
  312. package/dist/models/export.js +9 -0
  313. package/dist/models/id.js +2 -0
  314. package/dist/models/instance.js +7 -0
  315. package/dist/models/key-import.js +6 -0
  316. package/dist/models/locale.js +25 -0
  317. package/dist/models/merchant.js +12 -0
  318. package/dist/models/money.js +14 -0
  319. package/dist/models/package.js +12 -0
  320. package/dist/models/page.js +56 -0
  321. package/dist/models/persistence.js +1 -0
  322. package/dist/models/prompts.js +5 -0
  323. package/dist/models/recurring.js +54 -0
  324. package/dist/models/remedy.js +17 -0
  325. package/dist/models/resolution.js +1 -0
  326. package/dist/models/startup.js +7 -0
  327. package/dist/models/summary.js +24 -0
  328. package/dist/models/tag.js +14 -0
  329. package/dist/models/tenancy.js +10 -0
  330. package/dist/models/transaction-tag.js +6 -0
  331. package/dist/models/transaction.js +275 -0
  332. package/dist/wire/db/access-tokens.js +1 -0
  333. package/dist/wire/db/accounts.js +7 -0
  334. package/dist/wire/db/aggregate.js +16 -0
  335. package/dist/wire/db/bills.js +14 -0
  336. package/dist/wire/db/budgets.js +33 -0
  337. package/dist/wire/db/categories.js +14 -0
  338. package/dist/wire/db/client-grants.js +1 -0
  339. package/dist/wire/db/correlations.js +49 -0
  340. package/dist/wire/db/credit-cards.js +1 -0
  341. package/dist/wire/db/currencies.js +1 -0
  342. package/dist/wire/db/currency-rates.js +1 -0
  343. package/dist/wire/db/dashboards.js +1 -0
  344. package/dist/wire/db/instance-settings.js +1 -0
  345. package/dist/wire/db/invites.js +1 -0
  346. package/dist/wire/db/merchants.js +18 -0
  347. package/dist/wire/db/recurring.js +19 -0
  348. package/dist/wire/db/sessions.js +1 -0
  349. package/dist/wire/db/settings.js +1 -0
  350. package/dist/wire/db/setup-codes.js +1 -0
  351. package/dist/wire/db/tags.js +1 -0
  352. package/dist/wire/db/tenancy.js +1 -0
  353. package/dist/wire/db/transactions.js +89 -0
  354. package/dist/wire/db/users.js +1 -0
  355. package/dist/wire/in/accounts.js +26 -0
  356. package/dist/wire/in/aggregate.js +10 -0
  357. package/dist/wire/in/auth.js +107 -0
  358. package/dist/wire/in/bills.js +11 -0
  359. package/dist/wire/in/budgets.js +11 -0
  360. package/dist/wire/in/categories.js +9 -0
  361. package/dist/wire/in/cli.js +106 -0
  362. package/dist/wire/in/coerce.js +6 -0
  363. package/dist/wire/in/common.js +17 -0
  364. package/dist/wire/in/credit-cards.js +16 -0
  365. package/dist/wire/in/currency-rates.js +8 -0
  366. package/dist/wire/in/period.js +7 -0
  367. package/dist/wire/in/recurring.js +6 -0
  368. package/dist/wire/in/settings.js +5 -0
  369. package/dist/wire/in/summary.js +5 -0
  370. package/dist/wire/in/tags.js +2 -0
  371. package/dist/wire/in/transactions.js +31 -0
  372. package/dist/wire/out/bills.js +9 -0
  373. package/dist/wire/out/budgets.js +10 -0
  374. package/dist/wire/out/client-config.js +2 -0
  375. package/dist/wire/out/common.js +4 -0
  376. package/dist/wire/out/credit-cards.js +15 -0
  377. package/dist/wire/out/currency-rates.js +11 -0
  378. package/dist/wire/out/errors.js +58 -0
  379. package/dist/wire/out/recurring.js +6 -0
  380. package/dist/wire/out/status.js +10 -0
  381. package/dist/wire/out/summary.js +9 -0
  382. package/dist/wire/out/transactions.js +52 -0
  383. package/drizzle/0000_futuristic_umar.sql +124 -0
  384. package/drizzle/0001_fts5_search.sql +23 -0
  385. package/drizzle/0002_rename_graph_to_history.sql +7 -0
  386. package/drizzle/0003_lyrical_hairball.sql +2 -0
  387. package/drizzle/0004_misty_ikaris.sql +7 -0
  388. package/drizzle/0005_credit-liability-accounts.sql +14 -0
  389. package/drizzle/0006_smart_aqueduct.sql +1 -0
  390. package/drizzle/0007_add_dashboards.sql +5 -0
  391. package/drizzle/0008_yummy_madripoor.sql +1 -0
  392. package/drizzle/0009_version_groundwork.sql +9 -0
  393. package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
  394. package/drizzle/0011_dashboard_id_normalization.sql +16 -0
  395. package/drizzle/0012_hot_the_spike.sql +12 -0
  396. package/drizzle/0013_recurring_rules_merchant.sql +1 -0
  397. package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
  398. package/drizzle/0015_currencies_decimals.sql +1 -0
  399. package/drizzle/0016_unusual_zaran.sql +13 -0
  400. package/drizzle/0017_premium_blur.sql +1 -0
  401. package/drizzle/0018_auth_identity.sql +39 -0
  402. package/drizzle/0019_access_tokens.sql +16 -0
  403. package/drizzle/0020_stdio_sign_in.sql +27 -0
  404. package/drizzle/0021_tenancy_data.sql +289 -0
  405. package/drizzle/0022_user_management.sql +17 -0
  406. package/drizzle/0023_instance_settings_row.sql +2 -0
  407. package/drizzle/0024_credentials_changed_at.sql +2 -0
  408. package/drizzle/0025_instance_kind.sql +2 -0
  409. package/drizzle/0026_demo_seeded_at.sql +2 -0
  410. package/drizzle/0027_demo_country.sql +2 -0
  411. package/drizzle/0028_reset_sign_ins.sql +2 -0
  412. package/drizzle/meta/0000_snapshot.json +894 -0
  413. package/drizzle/meta/0003_snapshot.json +910 -0
  414. package/drizzle/meta/0004_snapshot.json +951 -0
  415. package/drizzle/meta/0005_snapshot.json +991 -0
  416. package/drizzle/meta/0006_snapshot.json +998 -0
  417. package/drizzle/meta/0007_snapshot.json +1029 -0
  418. package/drizzle/meta/0008_snapshot.json +1049 -0
  419. package/drizzle/meta/0009_snapshot.json +1121 -0
  420. package/drizzle/meta/0010_snapshot.json +1121 -0
  421. package/drizzle/meta/0011_snapshot.json +1136 -0
  422. package/drizzle/meta/0012_snapshot.json +1227 -0
  423. package/drizzle/meta/0013_snapshot.json +1247 -0
  424. package/drizzle/meta/0014_snapshot.json +1267 -0
  425. package/drizzle/meta/0015_snapshot.json +1275 -0
  426. package/drizzle/meta/0016_snapshot.json +1371 -0
  427. package/drizzle/meta/0017_snapshot.json +1392 -0
  428. package/drizzle/meta/0018_snapshot.json +1603 -0
  429. package/drizzle/meta/0019_snapshot.json +1713 -0
  430. package/drizzle/meta/0020_snapshot.json +1904 -0
  431. package/drizzle/meta/0021_snapshot.json +2186 -0
  432. package/drizzle/meta/0022_snapshot.json +2311 -0
  433. package/drizzle/meta/0023_snapshot.json +2311 -0
  434. package/drizzle/meta/0024_snapshot.json +2318 -0
  435. package/drizzle/meta/0025_snapshot.json +2326 -0
  436. package/drizzle/meta/0026_snapshot.json +2333 -0
  437. package/drizzle/meta/0027_snapshot.json +2340 -0
  438. package/drizzle/meta/0028_snapshot.json +2340 -0
  439. package/drizzle/meta/_journal.json +209 -0
  440. package/package.json +106 -4
  441. package/skills/dashboard-building/SKILL.md +201 -0
  442. package/skills/patty-tour/SKILL.md +34 -0
  443. package/ui/app.css +758 -0
  444. package/ui/app.js +543 -0
  445. package/ui/connect-result.html +16 -0
  446. package/ui/connect.html +53 -0
  447. package/ui/dashboards/accounts.html +3189 -0
  448. package/ui/dashboards/budget.html +1734 -0
  449. package/ui/dashboards/cards.html +4032 -0
  450. package/ui/dashboards/categories.html +4694 -0
  451. package/ui/dashboards/comparative.html +2475 -0
  452. package/ui/dashboards/dashboards.html +839 -0
  453. package/ui/dashboards/overview.html +2405 -0
  454. package/ui/dashboards/pending.html +2973 -0
  455. package/ui/dashboards/projections.html +2528 -0
  456. package/ui/dashboards/tags.html +1365 -0
  457. package/ui/invite.html +44 -0
  458. package/ui/login.html +26 -0
  459. package/ui/money.js +175 -0
  460. package/ui/setup.html +29 -0
  461. package/ui/shell.html +96 -0
  462. package/ui/token-created.html +24 -0
  463. package/ui/tokens.html +58 -0
  464. package/ui/user-invited.html +27 -0
  465. package/ui/users.html +60 -0
@@ -0,0 +1,839 @@
1
+ <style>
2
+ /* Tooltip styling */
3
+ .sidebar-menu a[data-tooltip]::after,
4
+ .sidebar-more-container[data-tooltip]::after {
5
+ content: attr(data-tooltip);
6
+ position: absolute;
7
+ left: 80px;
8
+ top: 50%;
9
+ transform: translateY(-50%) translateX(-10px);
10
+ background: #11131e;
11
+ color: #fff;
12
+ padding: 0.4rem 0.75rem;
13
+ border-radius: 6px;
14
+ font-size: 0.75rem;
15
+ font-weight: 600;
16
+ white-space: nowrap;
17
+ opacity: 0;
18
+ pointer-events: none;
19
+ transition: all 0.2s ease;
20
+ box-shadow: 0 4px 12px rgba(0,0,0,0.5);
21
+ border: 1px solid var(--panel-border);
22
+ }
23
+
24
+ .sidebar-menu a[data-tooltip]:hover::after,
25
+ .sidebar-more-container:hover::after {
26
+ opacity: 1;
27
+ transform: translateY(-50%) translateX(0);
28
+ }
29
+
30
+ header h1 {
31
+ font-size: 1.6rem;
32
+ font-weight: 700;
33
+ display: flex;
34
+ align-items: center;
35
+ gap: 0.75rem;
36
+ }
37
+
38
+ header h1 i {
39
+ color: var(--accent-primary);
40
+ }
41
+
42
+ header p {
43
+ font-size: 0.85rem;
44
+ color: var(--text-muted);
45
+ margin-top: 0.25rem;
46
+ }
47
+
48
+ /* Page Grid Layout */
49
+ .grid-container {
50
+ display: grid;
51
+ grid-template-columns: 1.3fr 1fr;
52
+ gap: 2rem;
53
+ align-items: start;
54
+ }
55
+
56
+ @media (max-width: 1024px) {
57
+ .grid-container {
58
+ grid-template-columns: 1fr;
59
+ }
60
+ }
61
+
62
+ /* Panel Styling */
63
+ /* base: ui/app.css (#164) */
64
+ .panel {
65
+ padding: 1.5rem;
66
+ position: relative;
67
+ }
68
+
69
+ .panel-title {
70
+ font-size: 1.1rem;
71
+ font-weight: 600;
72
+ margin-bottom: 1.5rem;
73
+ display: flex;
74
+ align-items: center;
75
+ gap: 0.5rem;
76
+ border-bottom: 1px solid var(--panel-border);
77
+ padding-bottom: 0.75rem;
78
+ }
79
+
80
+ .panel-title i {
81
+ color: var(--accent-primary);
82
+ }
83
+
84
+ /* Forms Styling */
85
+ .form-group {
86
+ margin-bottom: 1.25rem;
87
+ }
88
+
89
+ .form-label {
90
+ display: block;
91
+ font-size: 0.8rem;
92
+ font-weight: 600;
93
+ color: var(--text-muted);
94
+ margin-bottom: 0.5rem;
95
+ text-transform: uppercase;
96
+ letter-spacing: 0.5px;
97
+ }
98
+
99
+ /* base: ui/app.css (#164) */
100
+ .form-control {
101
+ background: rgba(255, 255, 255, 0.03);
102
+ border-radius: 12px;
103
+ padding: 0.75rem 1rem;
104
+ color: #fff;
105
+ font-family: inherit;
106
+ font-size: 0.9rem;
107
+ }
108
+
109
+ .form-control:focus {
110
+ outline: none;
111
+ background: rgba(255, 255, 255, 0.06);
112
+ box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
113
+ }
114
+
115
+ .btn-submit {
116
+ width: 100%;
117
+ background: var(--accent-primary);
118
+ color: #fff;
119
+ border: none;
120
+ border-radius: 12px;
121
+ padding: 0.75rem;
122
+ font-size: 0.9rem;
123
+ font-weight: 700;
124
+ cursor: pointer;
125
+ transition: var(--transition-smooth);
126
+ display: flex;
127
+ align-items: center;
128
+ justify-content: center;
129
+ gap: 0.5rem;
130
+ }
131
+
132
+ .btn-submit:hover {
133
+ background: var(--accent-secondary);
134
+ transform: translateY(-2px);
135
+ box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
136
+ }
137
+
138
+ /* List Styling */
139
+ .dashboard-list {
140
+ display: flex;
141
+ flex-direction: column;
142
+ gap: 1rem;
143
+ max-height: 70vh;
144
+ overflow-y: auto;
145
+ padding-right: 0.5rem;
146
+ }
147
+
148
+ .dashboard-item-card {
149
+ background: rgba(255, 255, 255, 0.015);
150
+ border: 1px solid var(--panel-border);
151
+ border-radius: 16px;
152
+ padding: 1.25rem;
153
+ display: flex;
154
+ justify-content: space-between;
155
+ align-items: center;
156
+ transition: var(--transition-smooth);
157
+ }
158
+
159
+ .dashboard-item-card:hover {
160
+ border-color: rgba(255, 255, 255, 0.12);
161
+ background: rgba(255, 255, 255, 0.03);
162
+ }
163
+
164
+ .dashboard-info {
165
+ display: flex;
166
+ flex-direction: column;
167
+ gap: 0.35rem;
168
+ }
169
+
170
+ .dashboard-name {
171
+ font-weight: 600;
172
+ font-size: 1rem;
173
+ text-transform: capitalize;
174
+ }
175
+
176
+ .dashboard-meta {
177
+ font-size: 0.78rem;
178
+ color: var(--text-muted);
179
+ display: flex;
180
+ align-items: center;
181
+ gap: 0.5rem;
182
+ }
183
+
184
+ .dashboard-actions {
185
+ display: flex;
186
+ gap: 0.5rem;
187
+ }
188
+
189
+ .btn-action {
190
+ background: rgba(255,255,255,0.03);
191
+ border: 1px solid var(--panel-border);
192
+ color: var(--text-main);
193
+ padding: 0.5rem 0.75rem;
194
+ border-radius: 8px;
195
+ font-size: 0.8rem;
196
+ font-weight: 600;
197
+ cursor: pointer;
198
+ transition: var(--transition-smooth);
199
+ display: flex;
200
+ align-items: center;
201
+ gap: 0.35rem;
202
+ }
203
+
204
+ .btn-action:hover {
205
+ background: rgba(139, 92, 246, 0.12);
206
+ color: var(--accent-secondary);
207
+ border-color: rgba(139, 92, 246, 0.3);
208
+ }
209
+
210
+ .btn-action.danger:hover {
211
+ background: rgba(244, 63, 94, 0.12);
212
+ color: var(--expense-color);
213
+ border-color: rgba(244, 63, 94, 0.3);
214
+ }
215
+
216
+ /* File Upload Area */
217
+ .upload-area {
218
+ border: 2px dashed var(--panel-border);
219
+ border-radius: 16px;
220
+ padding: 2rem;
221
+ text-align: center;
222
+ cursor: pointer;
223
+ transition: var(--transition-smooth);
224
+ margin-bottom: 1.25rem;
225
+ display: flex;
226
+ flex-direction: column;
227
+ align-items: center;
228
+ gap: 0.75rem;
229
+ }
230
+
231
+ .upload-area:hover {
232
+ border-color: var(--accent-primary);
233
+ background: rgba(139, 92, 246, 0.02);
234
+ }
235
+
236
+ .upload-area i {
237
+ font-size: 2rem;
238
+ color: var(--text-dark);
239
+ transition: var(--transition-smooth);
240
+ }
241
+
242
+ .upload-area:hover i {
243
+ color: var(--accent-secondary);
244
+ }
245
+
246
+ .upload-filename {
247
+ font-size: 0.85rem;
248
+ font-weight: 600;
249
+ color: var(--accent-secondary);
250
+ margin-top: 0.25rem;
251
+ display: none;
252
+ }
253
+
254
+ /* Modals (.modal-overlay/.modal-title base: ui/app.css, #164 — this dashboard's own
255
+ .modal-card/.modal-header/.btn-close-modal have no shared-base counterpart) */
256
+ .modal-overlay {
257
+ right: 0; bottom: 0;
258
+ background: rgba(5, 5, 8, 0.85);
259
+ z-index: 10000;
260
+ display: flex;
261
+ pointer-events: none;
262
+ transition: var(--transition-smooth);
263
+ }
264
+
265
+ .modal-overlay.open {
266
+ pointer-events: all;
267
+ }
268
+
269
+ .modal-card {
270
+ background: #0f111e;
271
+ border: 1px solid var(--panel-border);
272
+ border-radius: 24px;
273
+ padding: 1.75rem;
274
+ width: 90%;
275
+ max-width: 800px;
276
+ max-height: 85vh;
277
+ display: flex;
278
+ flex-direction: column;
279
+ box-shadow: 0 20px 50px rgba(0,0,0,0.6);
280
+ transform: scale(0.95);
281
+ transition: var(--transition-smooth);
282
+ }
283
+
284
+ .modal-overlay.open .modal-card {
285
+ transform: scale(1);
286
+ }
287
+
288
+ .modal-header {
289
+ display: flex;
290
+ justify-content: space-between;
291
+ align-items: center;
292
+ border-bottom: 1px solid var(--panel-border);
293
+ padding-bottom: 1rem;
294
+ margin-bottom: 1.25rem;
295
+ }
296
+
297
+ .modal-title {
298
+ font-size: 1.15rem;
299
+ }
300
+
301
+ .btn-close-modal {
302
+ background: none;
303
+ border: none;
304
+ color: var(--text-dark);
305
+ font-size: 1.2rem;
306
+ cursor: pointer;
307
+ transition: var(--transition-smooth);
308
+ }
309
+
310
+ .btn-close-modal:hover {
311
+ color: #fff;
312
+ }
313
+
314
+ .code-area {
315
+ background: #06070a;
316
+ border: 1px solid var(--panel-border);
317
+ border-radius: 12px;
318
+ padding: 1rem;
319
+ color: #10b981;
320
+ font-family: 'Courier New', Courier, monospace;
321
+ font-size: 0.8rem;
322
+ line-height: 1.4;
323
+ overflow: auto;
324
+ flex: 1;
325
+ min-height: 350px;
326
+ white-space: pre-wrap;
327
+ user-select: text;
328
+ }
329
+
330
+ /* Loading Spinner Overlay (.loading-overlay/.spinner base: ui/app.css, #164) */
331
+ .loading-overlay {
332
+ width: 100%; height: 100%;
333
+ background: rgba(12, 14, 23, 0.85);
334
+ z-index: 100;
335
+ border-radius: 24px;
336
+ opacity: 0; pointer-events: none;
337
+ transition: opacity 0.25s ease;
338
+ }
339
+
340
+ .loading-overlay.active {
341
+ opacity: 1;
342
+ pointer-events: all;
343
+ }
344
+
345
+ /* Toast notifications (.toast-container/.toast base: ui/app.css, #164) */
346
+ .toast-container {
347
+ z-index: 9999;
348
+ }
349
+
350
+ .toast {
351
+ background: #111322;
352
+ padding: 1rem 1.25rem;
353
+ font-size: 0.85rem;
354
+ font-weight: 500;
355
+ transform: translateY(20px);
356
+ opacity: 0;
357
+ animation: toastIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
358
+ min-width: 280px;
359
+ }
360
+
361
+ .toast.success { border-left: 4px solid var(--income-color); }
362
+ .toast.error { border-left: 4px solid var(--expense-color); }
363
+
364
+ .toast i { font-size: 1.1rem; }
365
+ .toast.success i { color: var(--income-color); }
366
+ .toast.error i { color: var(--expense-color); }
367
+
368
+ @keyframes toastIn {
369
+ to { transform: translateY(0); opacity: 1; }
370
+ }
371
+
372
+ @keyframes fadeOut {
373
+ to { opacity: 0; transform: translateY(20px); }
374
+ }
375
+
376
+ /* Custom Select component styling */
377
+ .select-container-custom {
378
+ position: relative;
379
+ display: inline-block;
380
+ min-width: 120px;
381
+ user-select: none;
382
+ }
383
+
384
+ .select-trigger-custom {
385
+ background: rgba(255, 255, 255, 0.05);
386
+ border: 1px solid var(--panel-border);
387
+ color: var(--text-main);
388
+ padding: 0.5rem 2.2rem 0.5rem 0.75rem;
389
+ border-radius: 8px;
390
+ cursor: pointer;
391
+ font-size: 0.85rem;
392
+ font-weight: 600;
393
+ display: flex;
394
+ align-items: center;
395
+ justify-content: space-between;
396
+ transition: var(--transition-smooth);
397
+ min-height: 36px;
398
+ box-sizing: border-box;
399
+ }
400
+
401
+ .select-trigger-custom:hover {
402
+ border-color: rgba(255, 255, 255, 0.15);
403
+ background: rgba(255, 255, 255, 0.08);
404
+ }
405
+
406
+ .select-container-custom.open .select-trigger-custom {
407
+ border-color: var(--accent-primary);
408
+ box-shadow: 0 0 0 2px var(--accent-primary-glow);
409
+ }
410
+
411
+ .select-trigger-custom::after {
412
+ content: '\f078';
413
+ font-family: 'Font Awesome 6 Free';
414
+ font-weight: 900;
415
+ font-size: 0.7rem;
416
+ color: var(--text-muted);
417
+ position: absolute;
418
+ right: 12px;
419
+ transition: transform 0.3s ease;
420
+ }
421
+
422
+ .select-container-custom.open .select-trigger-custom::after {
423
+ transform: rotate(180deg);
424
+ color: var(--accent-primary);
425
+ }
426
+
427
+ .select-options-custom {
428
+ display: none;
429
+ position: absolute;
430
+ top: calc(100% + 6px);
431
+ left: 0;
432
+ width: 100%;
433
+ background: rgba(22, 22, 34, 0.98); /* Opaque dark background to prevent bleed-through */
434
+ border: 1px solid var(--panel-border);
435
+ border-radius: 12px;
436
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
437
+ z-index: 1000;
438
+ max-height: 250px;
439
+ overflow-y: auto;
440
+ padding: 4px;
441
+ backdrop-filter: blur(20px);
442
+ box-sizing: border-box;
443
+ animation: selectFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
444
+ }
445
+
446
+ @keyframes selectFadeIn {
447
+ from { opacity: 0; transform: translateY(-8px); }
448
+ to { opacity: 1; transform: translateY(0); }
449
+ }
450
+
451
+ .select-container-custom.open .select-options-custom {
452
+ display: block;
453
+ }
454
+
455
+ .select-option-custom {
456
+ padding: 0.5rem 0.75rem;
457
+ color: var(--text-muted); /* Highly readable text color on dark backgrounds */
458
+ font-size: 0.82rem;
459
+ font-weight: 500;
460
+ border-radius: 6px;
461
+ cursor: pointer;
462
+ transition: var(--transition-smooth);
463
+ }
464
+
465
+ .select-option-custom:hover {
466
+ background: rgba(255, 255, 255, 0.08);
467
+ color: #fff;
468
+ }
469
+
470
+ .select-option-custom.selected {
471
+ background: var(--accent-primary-glow);
472
+ color: var(--accent-primary);
473
+ font-weight: 700;
474
+ }
475
+
476
+ .select-options-custom::-webkit-scrollbar {
477
+ width: 6px;
478
+ }
479
+ .select-options-custom::-webkit-scrollbar-track {
480
+ background: transparent;
481
+ }
482
+ .select-options-custom::-webkit-scrollbar-thumb {
483
+ background: rgba(255, 255, 255, 0.1);
484
+ border-radius: 3px;
485
+ }
486
+ </style>
487
+
488
+ <header>
489
+ <div class="header-title-area">
490
+ <h1><i class="fa-solid fa-folder-open"></i> Gerenciamento de Dashboards</h1>
491
+ <p>Monitore, visualize ou envie novos layouts de dashboards para a plataforma PATTY</p>
492
+ </div>
493
+ </header>
494
+
495
+ <div class="grid-container">
496
+ <!-- Left Panel: Active Dashboards -->
497
+ <section class="panel">
498
+ <div class="loading-overlay" id="list-loading">
499
+ <div class="spinner"></div>
500
+ </div>
501
+ <div class="panel-title">
502
+ <i class="fa-solid fa-rectangle-list"></i> Dashboards Ativos
503
+ </div>
504
+ <div class="dashboard-list" id="dashboard-list">
505
+ <!-- Dynamic list cards -->
506
+ </div>
507
+ </section>
508
+
509
+ <!-- Right Panel: Upload / Save Dashboard -->
510
+ <section class="panel">
511
+ <div class="loading-overlay" id="form-loading">
512
+ <div class="spinner"></div>
513
+ </div>
514
+ <div class="panel-title">
515
+ <i class="fa-solid fa-cloud-arrow-up"></i> Registrar/Atualizar Dashboard
516
+ </div>
517
+ <form id="upload-form" onsubmit="handleUploadDashboard(event)">
518
+ <div class="form-group">
519
+ <label class="form-label" for="dash-name">Nome do Dashboard</label>
520
+ <input type="text" id="dash-name" class="form-control" placeholder="Ex: overview, projecoes, comparativo" required>
521
+ <span style="font-size:0.75rem; color:var(--text-dark); margin-top:0.25rem; display:block;">Use letras minúsculas sem espaços ou acentos.</span>
522
+ </div>
523
+
524
+ <!-- Upload Area -->
525
+ <div class="form-group">
526
+ <label class="form-label">Arquivo do Layout (.html)</label>
527
+ <div class="upload-area" onclick="document.getElementById('dash-file').click()">
528
+ <i class="fa-solid fa-file-code"></i>
529
+ <span style="font-size:0.85rem; font-weight:600;">Clique para escolher o arquivo HTML</span>
530
+ <span style="font-size:0.75rem; color:var(--text-dark);">Tamanho máximo recomendado: 500KB</span>
531
+ <div class="upload-filename" id="upload-filename">Nenhum arquivo selecionado</div>
532
+ </div>
533
+ <input type="file" id="dash-file" style="display:none;" accept=".html" onchange="handleFileChange(event)">
534
+ </div>
535
+
536
+ <button type="submit" class="btn-submit">
537
+ <i class="fa-solid fa-cloud-arrow-up"></i> Enviar Dashboard
538
+ </button>
539
+ </form>
540
+ </section>
541
+ </div>
542
+
543
+ <div class="toast-container" id="toast-container"></div>
544
+
545
+ <!-- View Dashboard HTML source code modal -->
546
+ <div class="modal-overlay" id="modal-view-code">
547
+ <div class="modal-card" style="max-width: 900px;">
548
+ <div class="modal-header">
549
+ <span class="modal-title" id="modal-code-title"></span>
550
+ <button type="button" class="btn-close-modal" onclick="closeModal('modal-view-code')">
551
+ <i class="fa-solid fa-xmark"></i>
552
+ </button>
553
+ </div>
554
+ <pre id="modal-code-viewer" style="margin: 0; overflow: auto; max-height: 60vh; padding: 1rem; background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border); border-radius: 12px; color: var(--text-dark); font-family: monospace; font-size: 0.85rem; white-space: pre-wrap; word-break: break-all;"></pre>
555
+ </div>
556
+ </div>
557
+
558
+ <script>
559
+ // State
560
+ var dashboards = [];
561
+ var uploadedHtmlContent = "";
562
+
563
+ // Elements
564
+ var listLoading = document.getElementById('list-loading');
565
+ var formLoading = document.getElementById('form-loading');
566
+ var dashboardList = document.getElementById('dashboard-list');
567
+ var uploadFilename = document.getElementById('upload-filename');
568
+
569
+ // Toast Helper
570
+ function showToast(message, type = "success") {
571
+ const container = document.getElementById('toast-container');
572
+ const toast = document.createElement('div');
573
+ toast.className = `toast ${type}`;
574
+ toast.innerHTML = `
575
+ <i class="fa-solid ${type === 'success' ? 'fa-circle-check' : 'fa-circle-exclamation'}"></i>
576
+ <span>${escapeHtml(message)}</span>
577
+ `;
578
+ container.appendChild(toast);
579
+
580
+ setTimeout(() => {
581
+ toast.style.animation = "fadeOut 0.4s ease forwards";
582
+ setTimeout(() => toast.remove(), 400);
583
+ }, 3500);
584
+ }
585
+
586
+ // Open/Close Modal Helper
587
+ function openModal(id) {
588
+ document.getElementById(id).classList.add('open');
589
+ }
590
+
591
+ function closeModal(id) {
592
+ document.getElementById(id).classList.remove('open');
593
+ }
594
+
595
+ // Close modal on ESC key
596
+ document.addEventListener('keydown', (e) => {
597
+ if (e.key === 'Escape') {
598
+ const activeModal = document.querySelector('.modal-overlay.open');
599
+ if (activeModal) {
600
+ closeModal(activeModal.id);
601
+ }
602
+ }
603
+ });
604
+
605
+ // Load dashboards from API
606
+ async function loadDashboards() {
607
+ listLoading.classList.add('active');
608
+ try {
609
+ const res = await fetch('/api/dashboards');
610
+ if (res.ok) {
611
+ dashboards = await res.json();
612
+ // Sort by name
613
+ dashboards.sort((a, b) => a.name.localeCompare(b.name));
614
+ renderDashboardList();
615
+ } else {
616
+ showToast("Erro ao buscar a lista de dashboards.", "error");
617
+ }
618
+ } catch (err) {
619
+ console.error("Error fetching dashboards:", err);
620
+ showToast("Erro de conexão ao buscar dashboards.", "error");
621
+ } finally {
622
+ listLoading.classList.remove('active');
623
+ }
624
+ }
625
+
626
+ // Render Dashboard item cards
627
+ function renderDashboardList() {
628
+ dashboardList.innerHTML = '';
629
+
630
+ if (dashboards.length === 0) {
631
+ dashboardList.innerHTML = '<div style="text-align:center; padding:3rem 0; color:var(--text-dark); font-style:italic;">Nenhum dashboard ativo.</div>';
632
+ return;
633
+ }
634
+
635
+ dashboards.forEach(d => {
636
+ const card = document.createElement('div');
637
+ card.className = 'dashboard-item-card';
638
+
639
+ const updateDate = d.updatedAt ? new Date(d.updatedAt).toLocaleString('pt-BR') : 'Desconhecida';
640
+
641
+ card.innerHTML = `
642
+ <div class="dashboard-info">
643
+ <span class="dashboard-name">${escapeHtml(d.name)}</span>
644
+ <div class="dashboard-meta">
645
+ <i class="fa-regular fa-clock"></i>
646
+ <span>Atualizado em: ${updateDate}</span>
647
+ </div>
648
+ </div>
649
+ <div class="dashboard-actions">
650
+ <button type="button" class="btn-action" onclick="viewDashboardHtml('${escapeJsAttr(d.name)}')">
651
+ <i class="fa-solid fa-code"></i> Ver Código
652
+ </button>
653
+ <button type="button" class="btn-action" onclick="downloadDashboard('${escapeJsAttr(d.name)}')">
654
+ <i class="fa-solid fa-circle-down"></i> Baixar
655
+ </button>
656
+ <button type="button" class="btn-action danger" onclick="deleteDashboard('${escapeJsAttr(d.name)}')">
657
+ <i class="fa-solid fa-trash-can"></i> Excluir
658
+ </button>
659
+ </div>
660
+ `;
661
+
662
+ dashboardList.appendChild(card);
663
+ });
664
+ }
665
+
666
+ // Handle File Select
667
+ function handleFileChange(e) {
668
+ const file = e.target.files[0];
669
+ if (!file) return;
670
+
671
+ // Automatically pre-fill name from filename (without extension)
672
+ const nameField = document.getElementById('dash-name');
673
+ const nameWithoutExt = file.name.replace(/\.html$/i, '').toLowerCase();
674
+ nameField.value = nameWithoutExt;
675
+
676
+ uploadFilename.textContent = file.name;
677
+ uploadFilename.style.display = 'block';
678
+
679
+ // Read HTML content
680
+ const reader = new FileReader();
681
+ reader.onload = function(evt) {
682
+ uploadedHtmlContent = evt.target.result;
683
+ };
684
+ reader.readAsText(file);
685
+ }
686
+
687
+ // Handle Dashboard Upload
688
+ async function handleUploadDashboard(e) {
689
+ e.preventDefault();
690
+ const nameField = document.getElementById('dash-name');
691
+ const name = nameField.value.trim().toLowerCase();
692
+
693
+ if (!name) return;
694
+ if (!uploadedHtmlContent) {
695
+ showToast("Por favor, selecione um arquivo HTML válido.", "error");
696
+ return;
697
+ }
698
+
699
+ formLoading.classList.add('active');
700
+ try {
701
+ const res = await fetch('/api/dashboards', {
702
+ method: 'POST',
703
+ headers: { 'Content-Type': 'application/json' },
704
+ body: JSON.stringify({ name, html: uploadedHtmlContent })
705
+ });
706
+
707
+ if (res.ok) {
708
+ showToast(`Dashboard "${name}" atualizado com sucesso!`);
709
+ // Reset fields
710
+ nameField.value = '';
711
+ uploadFilename.textContent = 'Nenhum arquivo selecionado';
712
+ uploadFilename.style.display = 'none';
713
+ document.getElementById('dash-file').value = '';
714
+ uploadedHtmlContent = '';
715
+ await loadDashboards();
716
+ } else {
717
+ showToast("Erro ao registrar o dashboard no servidor.", "error");
718
+ }
719
+ } catch (err) {
720
+ console.error("Error uploading dashboard:", err);
721
+ showToast("Erro de conexão ao enviar o dashboard.", "error");
722
+ } finally {
723
+ formLoading.classList.remove('active');
724
+ }
725
+ }
726
+
727
+ // View Dashboard HTML source code inside modal
728
+ async function viewDashboardHtml(name) {
729
+ // GET /ui/:name always serves the shell (same HTML for every dashboard, the client
730
+ // resolves :name itself) — the dashboard's own fragment lives in GET /api/dashboards/:name's
731
+ // `html` field instead.
732
+ listLoading.classList.add('active');
733
+ try {
734
+ const res = await fetch(`/api/dashboards/${name}`);
735
+ if (res.ok) {
736
+ const { html } = await res.json();
737
+ document.getElementById('modal-code-title').innerHTML = `<i class="fa-solid fa-code"></i> Código Fonte: ${escapeHtml(name)}.html`;
738
+ document.getElementById('modal-code-viewer').textContent = html;
739
+ openModal('modal-view-code');
740
+ } else {
741
+ showToast("Não foi possível carregar o código fonte do dashboard.", "error");
742
+ }
743
+ } catch (err) {
744
+ console.error("Error reading dashboard code:", err);
745
+ showToast("Erro de conexão ao ler código.", "error");
746
+ } finally {
747
+ listLoading.classList.remove('active');
748
+ }
749
+ }
750
+
751
+ // Send request to delete dashboard
752
+ async function deleteDashboard(name) {
753
+ if (!confirm(`Deseja realmente excluir o dashboard "${name}"?`)) {
754
+ return;
755
+ }
756
+ listLoading.classList.add('active');
757
+ try {
758
+ const res = await fetch(`/api/dashboards/${name}`, {
759
+ method: 'DELETE'
760
+ });
761
+ if (res.ok) {
762
+ showToast(`Dashboard "${name}" excluído com sucesso!`);
763
+ await loadDashboards();
764
+ } else {
765
+ const data = await res.json().catch(() => ({}));
766
+ const errMsg = data.error || "Erro ao excluir o dashboard.";
767
+ showToast(errMsg, "error");
768
+ }
769
+ } catch (err) {
770
+ console.error("Error deleting dashboard:", err);
771
+ showToast("Erro de rede ao excluir o dashboard.", "error");
772
+ } finally {
773
+ listLoading.classList.remove('active');
774
+ }
775
+ }
776
+
777
+ // Trigger dynamic file download in browser
778
+ async function downloadDashboard(name) {
779
+ // Same reasoning as viewDashboardHtml: GET /ui/:name serves the shell, not this
780
+ // dashboard's own fragment — read GET /api/dashboards/:name's `html` field instead.
781
+ listLoading.classList.add('active');
782
+ try {
783
+ const res = await fetch(`/api/dashboards/${name}`);
784
+ if (res.ok) {
785
+ const { html } = await res.json();
786
+ const blob = new Blob([html], { type: 'text/html' });
787
+ const link = document.createElement('a');
788
+ link.href = URL.createObjectURL(blob);
789
+ link.download = `${name}.html`;
790
+ link.click();
791
+ URL.revokeObjectURL(link.href);
792
+ showToast(`Download de "${name}.html" iniciado!`);
793
+ } else {
794
+ showToast("Erro ao baixar o layout do dashboard.", "error");
795
+ }
796
+ } catch (err) {
797
+ console.error("Error downloading file:", err);
798
+ showToast("Erro de rede ao baixar.", "error");
799
+ } finally {
800
+ listLoading.classList.remove('active');
801
+ }
802
+ }
803
+
804
+ // HTML escaping
805
+ function escapeHtml(str) {
806
+ if (!str) return '';
807
+ return str.replace(/&/g, "&amp;")
808
+ .replace(/</g, "&lt;")
809
+ .replace(/>/g, "&gt;")
810
+ .replace(/"/g, "&quot;")
811
+ .replace(/'/g, "&#039;");
812
+ }
813
+
814
+ // Escapes a value for safe embedding as a single-quoted JS string literal *inside* an
815
+ // HTML attribute (e.g. onclick="fn('${escapeJsAttr(value)}')"). escapeHtml() alone is not
816
+ // enough here: the browser HTML-decodes the attribute before the JS parser reads it, so an
817
+ // HTML-escaped quote round-trips back into a real quote and still breaks out of the string.
818
+ // Escaping backslash+quote for the JS layer first, then HTML-escaping the result for the
819
+ // attribute layer, survives that decode step correctly for both layers.
820
+ function escapeJsAttr(str) {
821
+ if (!str) return '';
822
+ return escapeHtml(String(str).replace(/\\/g, '\\\\').replace(/'/g, "\\'"));
823
+ }
824
+
825
+ // Bootstrap load
826
+ loadDashboards();
827
+
828
+ // ADR-027 Live-update listener
829
+ window.onAppDataChanged = function(entities) {
830
+ var affected = entities.some(function(tag) {
831
+ return ['dashboard'].indexOf(tag) !== -1;
832
+ });
833
+ if (affected) {
834
+ console.log("dashboards refetching due to entity change:", entities);
835
+ loadDashboards();
836
+ }
837
+ };
838
+
839
+ </script>