ekwo-os 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +873 -0
  2. package/dist/args.d.ts +57 -0
  3. package/dist/args.d.ts.map +1 -0
  4. package/dist/args.js +134 -0
  5. package/dist/args.js.map +1 -0
  6. package/dist/assets/expected-objects.json +9432 -0
  7. package/dist/assets/migrations/20260911120000_core_companies.sql +260 -0
  8. package/dist/assets/migrations/20260911120100_accounts_journals.sql +211 -0
  9. package/dist/assets/migrations/20260911120200_contacts.sql +90 -0
  10. package/dist/assets/migrations/20260911120300_taxes.sql +146 -0
  11. package/dist/assets/migrations/20260911120400_entries.sql +338 -0
  12. package/dist/assets/migrations/20260911120500_documents.sql +279 -0
  13. package/dist/assets/migrations/20260911120600_payments_reconciliation.sql +251 -0
  14. package/dist/assets/migrations/20260911120700_bank.sql +178 -0
  15. package/dist/assets/migrations/20260911120800_analytics_attachments.sql +128 -0
  16. package/dist/assets/migrations/20260911120900_post_document.sql +279 -0
  17. package/dist/assets/migrations/20260911121000_reporting.sql +235 -0
  18. package/dist/assets/migrations/20260911121100_country_templates.sql +226 -0
  19. package/dist/assets/migrations/20260911121200_fec.sql +71 -0
  20. package/dist/assets/migrations/20260911130000_instance.sql +77 -0
  21. package/dist/assets/migrations/20260911130100_instance_members.sql +224 -0
  22. package/dist/assets/migrations/20260911140000_instance_admins.sql +112 -0
  23. package/dist/assets/migrations/20260911160000_tax_posting_templates_unique.sql +17 -0
  24. package/dist/assets/migrations/20260911170000_document_amount_paid.sql +82 -0
  25. package/dist/assets/migrations/20260911173000_post_payment.sql +122 -0
  26. package/dist/assets/migrations/20260911173100_sequence_counters_under_rls.sql +84 -0
  27. package/dist/assets/migrations/20260911183000_country_journal_defaults.sql +143 -0
  28. package/dist/assets/migrations/20260911193853_line_account_defaults.sql +274 -0
  29. package/dist/assets/migrations/20260911195054_products.sql +221 -0
  30. package/dist/assets/migrations/20260911210131_anon_surface.sql +85 -0
  31. package/dist/assets/migrations/20260912074712_country_packs.sql +318 -0
  32. package/dist/assets/migrations/20260912080311_report_code_and_region.sql +198 -0
  33. package/dist/assets/migrations/20260912081014_pack_certification_maintained.sql +31 -0
  34. package/dist/assets/migrations/20260912081015_pack_certification_backfill.sql +16 -0
  35. package/dist/assets/migrations/20260912090407_tax_report_boxes.sql +329 -0
  36. package/dist/assets/migrations/20260912091917_tax_on_base_value.sql +25 -0
  37. package/dist/assets/migrations/20260912091918_tax_engine_columns.sql +776 -0
  38. package/dist/assets/migrations/20260912094412_opening_and_closing.sql +759 -0
  39. package/dist/assets/migrations/20260912095825_charts_of_accounts.sql +326 -0
  40. package/dist/assets/migrations/20260912100412_financial_statements.sql +632 -0
  41. package/dist/assets/migrations/20260912104719_one_formula_evaluator.sql +209 -0
  42. package/dist/assets/migrations/20260912105720_entry_kind_appropriation.sql +26 -0
  43. package/dist/assets/migrations/20260912105721_appropriation_entry_kind.sql +444 -0
  44. package/dist/assets/migrations/20260912111751_document_rules.sql +274 -0
  45. package/dist/assets/migrations/20260912112132_cash_basis_vat_and_fx.sql +1189 -0
  46. package/dist/assets/migrations/20260913074512_modules.sql +493 -0
  47. package/dist/assets/migrations/20260913075903_asset_disposal_roles.sql +47 -0
  48. package/dist/assets/migrations/20260913083216_capabilities.sql +637 -0
  49. package/dist/assets/migrations/20260913083901_company_invitations.sql +262 -0
  50. package/dist/assets/migrations/20260913084402_user_preferences.sql +376 -0
  51. package/dist/assets/migrations/20260913084847_company_profile.sql +261 -0
  52. package/dist/assets/migrations/20260913085436_numbering_reads_the_pack.sql +235 -0
  53. package/dist/assets/migrations/20260913085932_api_keys.sql +303 -0
  54. package/dist/assets/migrations/20260913090216_fiscal_year_bounds.sql +159 -0
  55. package/dist/assets/migrations/20260913092527_entries_import.sql +219 -0
  56. package/dist/assets/migrations/20260913101536_null_safe_guards.sql +188 -0
  57. package/dist/assets/migrations/20260913102115_installer_is_named.sql +462 -0
  58. package/dist/assets/migrations/20260913102758_no_currency_default.sql +138 -0
  59. package/dist/assets/migrations/20260913103355_cash_basis_needs_a_box.sql +453 -0
  60. package/dist/assets/migrations/20260913104014_aged_balance_named_group.sql +79 -0
  61. package/dist/assets/migrations/20260913104232_foreign_key_indexes.sql +144 -0
  62. package/dist/assets/migrations/20260913105120_declared_no_reader.sql +41 -0
  63. package/dist/assets/migrations/20260913111407_pack_languages.sql +223 -0
  64. package/dist/assets/migrations/20260913112233_schema_comments_for_a_reader.sql +27 -0
  65. package/dist/assets/migrations/20260913114535_fec_opening_balances.sql +307 -0
  66. package/dist/assets/migrations/20260914103412_audit_log.sql +509 -0
  67. package/dist/assets/migrations/20260914111907_pack_upgrade.sql +428 -0
  68. package/dist/assets/migrations/20260914120500_rounding_reads_the_currency.sql +206 -0
  69. package/dist/assets/migrations/20260914121200_amounts_round_at_the_currency.sql +2403 -0
  70. package/dist/assets/migrations/20260914134325_schema_version_0_2_0.sql +36 -0
  71. package/dist/assets/migrations/20260914143915_accounts_in_use.sql +428 -0
  72. package/dist/assets/migrations/20260914144731_account_code_frozen.sql +99 -0
  73. package/dist/assets/migrations/20260914151207_schema_grants_its_own_rights.sql +284 -0
  74. package/dist/assets/migrations/20260914152840_pack_upgrade_records_its_own_line.sql +237 -0
  75. package/dist/assets/migrations/20260914163943_declaration_periodicity.sql +349 -0
  76. package/dist/assets/migrations/20260915094000_foreign_services_received.sql +37 -0
  77. package/dist/assets/migrations/20260915094500_mentions_read_a_foreign_service.sql +72 -0
  78. package/dist/assets/migrations/20260915153000_document_shares.sql +568 -0
  79. package/dist/assets/migrations/20260915160000_ec_sales_list.sql +181 -0
  80. package/dist/assets/migrations/20260915161842_pack_sources.sql +56 -0
  81. package/dist/assets/migrations/20260915170500_schema_version_0_3_0.sql +45 -0
  82. package/dist/assets/migrations/20260915174500_a_vat_category_is_a_code.sql +177 -0
  83. package/dist/assets/migrations/20260915180000_document_rule_references.sql +85 -0
  84. package/dist/assets/migrations/20260915181000_territories.sql +342 -0
  85. package/dist/assets/migrations/20260915181500_ec_sales_list_reads_the_territories.sql +222 -0
  86. package/dist/assets/migrations/20260915182000_intracom_triangular.sql +53 -0
  87. package/dist/assets/migrations/20260915182500_a_triangular_supply_says_reverse_charge.sql +99 -0
  88. package/dist/assets/migrations/20260915191200_a_document_knows_its_language.sql +633 -0
  89. package/dist/assets/migrations/20260915195000_a_price_that_holds_its_tax.sql +649 -0
  90. package/dist/assets/migrations/20260915200000_a_posting_names_its_boxes.sql +1004 -0
  91. package/dist/assets/migrations/20260916094500_a_company_files_more_than_one_declaration.sql +795 -0
  92. package/dist/assets/migrations/20260916103000_a_ledger_line_names_its_posting.sql +902 -0
  93. package/dist/assets/migrations/20260916123000_a_vocabulary_for_a_tax_that_is_not_a_vat.sql +144 -0
  94. package/dist/assets/migrations/20260916124000_a_box_can_be_a_rate_of_a_box.sql +525 -0
  95. package/dist/assets/migrations/20260916125000_a_tax_follows_the_territory.sql +1318 -0
  96. package/dist/assets/migrations/20260916126000_a_tax_point_and_its_exception.sql +1211 -0
  97. package/dist/assets/migrations/20260917090000_a_counterparty_that_learns.sql +561 -0
  98. package/dist/assets/migrations/20260917120000_what_the_money_pays.sql +545 -0
  99. package/dist/assets/migrations/20260917150000_a_filing_is_a_row.sql +488 -0
  100. package/dist/assets/migrations/20260917170000_when_it_is_due.sql +194 -0
  101. package/dist/assets/migrations/20260917180000_a_box_is_a_number_and_a_kind.sql +213 -0
  102. package/dist/assets/migrations/20260917190000_what_a_declaration_owes.sql +486 -0
  103. package/dist/assets/migrations/20260917200000_what_moved_after_it_went.sql +227 -0
  104. package/dist/assets/migrations/20260918090000_a_form_names_its_file.sql +27 -0
  105. package/dist/assets/migrations/20260918110000_a_deposit_and_what_came_back.sql +286 -0
  106. package/dist/assets/migrations/20260918113741_a_fourth_preset_is_named.sql +9 -0
  107. package/dist/assets/migrations/20260918113807_a_client_reads_and_hands_over.sql +96 -0
  108. package/dist/assets/migrations/20260918114322_two_definer_functions_check_their_caller.sql +75 -0
  109. package/dist/assets/migrations/20260918130000_every_company_somebody_keeps.sql +177 -0
  110. package/dist/assets/migrations/20260918140000_a_session_nobody_prepared.sql +40 -0
  111. package/dist/assets/migrations/20260918141107_a_line_keeps_the_tax_it_was_posted_with.sql +256 -0
  112. package/dist/assets/migrations/20260918141342_a_company_has_an_electronic_address.sql +66 -0
  113. package/dist/assets/migrations/20260918141605_an_invoice_reads_whole_from_the_views.sql +313 -0
  114. package/dist/assets/migrations/20260918141627_a_policy_asks_once.sql +132 -0
  115. package/dist/assets/migrations/20260918143352_a_suggestion_reads_the_words_once.sql +204 -0
  116. package/dist/assets/migrations/20260918143417_a_reference_of_the_caller_and_a_rehearsal.sql +115 -0
  117. package/dist/assets/migrations/20260918150712_a_company_leaves_with_its_books.sql +1119 -0
  118. package/dist/assets/migrations/20260918150931_a_statement_is_imported_once.sql +654 -0
  119. package/dist/assets/migrations/20260918161204_a_posted_document_does_not_move.sql +437 -0
  120. package/dist/assets/migrations/20260918161538_a_posted_entry_does_not_move.sql +252 -0
  121. package/dist/assets/migrations/20260918171946_an_entry_is_posted_by_post_entry.sql +289 -0
  122. package/dist/assets/migrations/20260918174312_schema_version_0_4_0.sql +53 -0
  123. package/dist/assets/modules/assets/module.json +13 -0
  124. package/dist/assets/modules/assets/supabase/migrations/20260913081447_assets.sql +1190 -0
  125. package/dist/assets/modules/assets/supabase/migrations/20260913104234_foreign_key_indexes.sql +47 -0
  126. package/dist/assets/modules/assets/supabase/migrations/20260913104500_assets_capabilities.sql +145 -0
  127. package/dist/assets/modules/assets/supabase/migrations/20260914122100_assets_round_at_the_currency.sql +564 -0
  128. package/dist/assets/modules/assets/supabase/migrations/20260914145012_assets_accounts_in_use.sql +37 -0
  129. package/dist/assets/modules/assets/supabase/migrations/20260914151530_assets_grants_its_own_rights.sql +63 -0
  130. package/dist/assets/modules/assets/supabase/migrations/20260918113912_assets_client_reads.sql +20 -0
  131. package/dist/assets/modules/assets/supabase/migrations/20260918150801_assets_leave_with_the_company.sql +41 -0
  132. package/dist/assets/modules/budgets/module.json +12 -0
  133. package/dist/assets/modules/budgets/supabase/migrations/20260913083012_budgets.sql +210 -0
  134. package/dist/assets/modules/budgets/supabase/migrations/20260913104233_foreign_key_indexes.sql +37 -0
  135. package/dist/assets/modules/budgets/supabase/migrations/20260913104501_budgets_capabilities.sql +72 -0
  136. package/dist/assets/modules/budgets/supabase/migrations/20260914122400_budgets_round_at_the_currency.sql +68 -0
  137. package/dist/assets/modules/budgets/supabase/migrations/20260914145048_budgets_accounts_in_use.sql +30 -0
  138. package/dist/assets/modules/budgets/supabase/migrations/20260914151812_budgets_grants_its_own_rights.sql +31 -0
  139. package/dist/assets/modules/budgets/supabase/migrations/20260918113954_budgets_client_reads.sql +20 -0
  140. package/dist/assets/modules/budgets/supabase/migrations/20260918150823_budgets_leave_with_the_company.sql +37 -0
  141. package/dist/assets/modules/schema/module.1.json +69 -0
  142. package/dist/assets/seed/00_currencies.sql +15 -0
  143. package/dist/assets/seed/00_territories.sql +280 -0
  144. package/dist/assets/seed/05_framework_generic.sql +110 -0
  145. package/dist/assets/seed/10_pack_be.sql +1284 -0
  146. package/dist/assets/seed/11_pack_fr.sql +1112 -0
  147. package/dist/assets/seed/12_pack_lu.sql +2484 -0
  148. package/dist/assets/seed/13_pack_ee.sql +733 -0
  149. package/dist/assets/seed/14_pack_gb.sql +796 -0
  150. package/dist/assets/seed/15_pack_us.sql +751 -0
  151. package/dist/assets/seed/90_demo_company.sql +368 -0
  152. package/dist/assets/seed/modules/assets/10_pack_be.sql +58 -0
  153. package/dist/assets/seed/modules/assets/11_pack_fr.sql +57 -0
  154. package/dist/assets/seed/modules/assets/14_pack_gb.sql +58 -0
  155. package/dist/assets/seed/modules/assets/15_pack_us.sql +60 -0
  156. package/dist/auth.d.ts +59 -0
  157. package/dist/auth.d.ts.map +1 -0
  158. package/dist/auth.js +134 -0
  159. package/dist/auth.js.map +1 -0
  160. package/dist/bin.d.ts +6 -0
  161. package/dist/bin.d.ts.map +1 -0
  162. package/dist/bin.js +8 -0
  163. package/dist/bin.js.map +1 -0
  164. package/dist/books.d.ts +60 -0
  165. package/dist/books.d.ts.map +1 -0
  166. package/dist/books.js +168 -0
  167. package/dist/books.js.map +1 -0
  168. package/dist/bootstrap.d.ts +236 -0
  169. package/dist/bootstrap.d.ts.map +1 -0
  170. package/dist/bootstrap.js +459 -0
  171. package/dist/bootstrap.js.map +1 -0
  172. package/dist/bundle.d.ts +27 -0
  173. package/dist/bundle.d.ts.map +1 -0
  174. package/dist/bundle.js +47 -0
  175. package/dist/bundle.js.map +1 -0
  176. package/dist/checklist.d.ts +35 -0
  177. package/dist/checklist.d.ts.map +1 -0
  178. package/dist/checklist.js +64 -0
  179. package/dist/checklist.js.map +1 -0
  180. package/dist/cli.d.ts +14 -0
  181. package/dist/cli.d.ts.map +1 -0
  182. package/dist/cli.js +318 -0
  183. package/dist/cli.js.map +1 -0
  184. package/dist/commands/company.d.ts +59 -0
  185. package/dist/commands/company.d.ts.map +1 -0
  186. package/dist/commands/company.js +287 -0
  187. package/dist/commands/company.js.map +1 -0
  188. package/dist/commands/contact.d.ts +9 -0
  189. package/dist/commands/contact.d.ts.map +1 -0
  190. package/dist/commands/contact.js +82 -0
  191. package/dist/commands/contact.js.map +1 -0
  192. package/dist/commands/demo.d.ts +19 -0
  193. package/dist/commands/demo.d.ts.map +1 -0
  194. package/dist/commands/demo.js +72 -0
  195. package/dist/commands/demo.js.map +1 -0
  196. package/dist/commands/doctor.d.ts +12 -0
  197. package/dist/commands/doctor.d.ts.map +1 -0
  198. package/dist/commands/doctor.js +68 -0
  199. package/dist/commands/doctor.js.map +1 -0
  200. package/dist/commands/document.d.ts +17 -0
  201. package/dist/commands/document.d.ts.map +1 -0
  202. package/dist/commands/document.js +217 -0
  203. package/dist/commands/document.js.map +1 -0
  204. package/dist/commands/init.d.ts +31 -0
  205. package/dist/commands/init.d.ts.map +1 -0
  206. package/dist/commands/init.js +535 -0
  207. package/dist/commands/init.js.map +1 -0
  208. package/dist/commands/login.d.ts +24 -0
  209. package/dist/commands/login.d.ts.map +1 -0
  210. package/dist/commands/login.js +128 -0
  211. package/dist/commands/login.js.map +1 -0
  212. package/dist/commands/migrate.d.ts +30 -0
  213. package/dist/commands/migrate.d.ts.map +1 -0
  214. package/dist/commands/migrate.js +115 -0
  215. package/dist/commands/migrate.js.map +1 -0
  216. package/dist/commands/module.d.ts +32 -0
  217. package/dist/commands/module.d.ts.map +1 -0
  218. package/dist/commands/module.js +285 -0
  219. package/dist/commands/module.js.map +1 -0
  220. package/dist/commands/pack.d.ts +22 -0
  221. package/dist/commands/pack.d.ts.map +1 -0
  222. package/dist/commands/pack.js +481 -0
  223. package/dist/commands/pack.js.map +1 -0
  224. package/dist/commands/payment.d.ts +15 -0
  225. package/dist/commands/payment.d.ts.map +1 -0
  226. package/dist/commands/payment.js +97 -0
  227. package/dist/commands/payment.js.map +1 -0
  228. package/dist/commands/register.d.ts +20 -0
  229. package/dist/commands/register.d.ts.map +1 -0
  230. package/dist/commands/register.js +134 -0
  231. package/dist/commands/register.js.map +1 -0
  232. package/dist/commands/status.d.ts +8 -0
  233. package/dist/commands/status.d.ts.map +1 -0
  234. package/dist/commands/status.js +134 -0
  235. package/dist/commands/status.js.map +1 -0
  236. package/dist/commands/whoami.d.ts +21 -0
  237. package/dist/commands/whoami.d.ts.map +1 -0
  238. package/dist/commands/whoami.js +133 -0
  239. package/dist/commands/whoami.js.map +1 -0
  240. package/dist/company.d.ts +16 -0
  241. package/dist/company.d.ts.map +1 -0
  242. package/dist/company.js +26 -0
  243. package/dist/company.js.map +1 -0
  244. package/dist/config.d.ts +24 -0
  245. package/dist/config.d.ts.map +1 -0
  246. package/dist/config.js +50 -0
  247. package/dist/config.js.map +1 -0
  248. package/dist/connection.d.ts +79 -0
  249. package/dist/connection.d.ts.map +1 -0
  250. package/dist/connection.js +116 -0
  251. package/dist/connection.js.map +1 -0
  252. package/dist/context.d.ts +47 -0
  253. package/dist/context.d.ts.map +1 -0
  254. package/dist/context.js +93 -0
  255. package/dist/context.js.map +1 -0
  256. package/dist/doctor.d.ts +45 -0
  257. package/dist/doctor.d.ts.map +1 -0
  258. package/dist/doctor.js +448 -0
  259. package/dist/doctor.js.map +1 -0
  260. package/dist/grants.d.ts +88 -0
  261. package/dist/grants.d.ts.map +1 -0
  262. package/dist/grants.js +174 -0
  263. package/dist/grants.js.map +1 -0
  264. package/dist/identity.d.ts +54 -0
  265. package/dist/identity.d.ts.map +1 -0
  266. package/dist/identity.js +132 -0
  267. package/dist/identity.js.map +1 -0
  268. package/dist/index.d.ts +44 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +43 -0
  271. package/dist/index.js.map +1 -0
  272. package/dist/inventory.d.ts +155 -0
  273. package/dist/inventory.d.ts.map +1 -0
  274. package/dist/inventory.js +303 -0
  275. package/dist/inventory.js.map +1 -0
  276. package/dist/migrations.d.ts +76 -0
  277. package/dist/migrations.d.ts.map +1 -0
  278. package/dist/migrations.js +226 -0
  279. package/dist/migrations.js.map +1 -0
  280. package/dist/module/read.d.ts +91 -0
  281. package/dist/module/read.d.ts.map +1 -0
  282. package/dist/module/read.js +172 -0
  283. package/dist/module/read.js.map +1 -0
  284. package/dist/output.d.ts +110 -0
  285. package/dist/output.d.ts.map +1 -0
  286. package/dist/output.js +173 -0
  287. package/dist/output.js.map +1 -0
  288. package/dist/pack/certification.d.ts +27 -0
  289. package/dist/pack/certification.d.ts.map +1 -0
  290. package/dist/pack/certification.js +38 -0
  291. package/dist/pack/certification.js.map +1 -0
  292. package/dist/pack/compile.d.ts +75 -0
  293. package/dist/pack/compile.d.ts.map +1 -0
  294. package/dist/pack/compile.js +801 -0
  295. package/dist/pack/compile.js.map +1 -0
  296. package/dist/pack/filing.d.ts +48 -0
  297. package/dist/pack/filing.d.ts.map +1 -0
  298. package/dist/pack/filing.js +56 -0
  299. package/dist/pack/filing.js.map +1 -0
  300. package/dist/pack/read.d.ts +766 -0
  301. package/dist/pack/read.d.ts.map +1 -0
  302. package/dist/pack/read.js +2336 -0
  303. package/dist/pack/read.js.map +1 -0
  304. package/dist/pack/schema.d.ts +26 -0
  305. package/dist/pack/schema.d.ts.map +1 -0
  306. package/dist/pack/schema.js +181 -0
  307. package/dist/pack/schema.js.map +1 -0
  308. package/dist/pack/territories.d.ts +98 -0
  309. package/dist/pack/territories.d.ts.map +1 -0
  310. package/dist/pack/territories.js +0 -0
  311. package/dist/pack/territories.js.map +1 -0
  312. package/dist/pack/upgrade.d.ts +86 -0
  313. package/dist/pack/upgrade.d.ts.map +1 -0
  314. package/dist/pack/upgrade.js +76 -0
  315. package/dist/pack/upgrade.js.map +1 -0
  316. package/dist/pack/vat-codes.d.ts +273 -0
  317. package/dist/pack/vat-codes.d.ts.map +1 -0
  318. package/dist/pack/vat-codes.js +513 -0
  319. package/dist/pack/vat-codes.js.map +1 -0
  320. package/dist/profiles.d.ts +67 -0
  321. package/dist/profiles.d.ts.map +1 -0
  322. package/dist/profiles.js +187 -0
  323. package/dist/profiles.js.map +1 -0
  324. package/dist/prompt.d.ts +40 -0
  325. package/dist/prompt.d.ts.map +1 -0
  326. package/dist/prompt.js +120 -0
  327. package/dist/prompt.js.map +1 -0
  328. package/dist/registry.d.ts +84 -0
  329. package/dist/registry.d.ts.map +1 -0
  330. package/dist/registry.js +104 -0
  331. package/dist/registry.js.map +1 -0
  332. package/dist/rest.d.ts +81 -0
  333. package/dist/rest.d.ts.map +1 -0
  334. package/dist/rest.js +245 -0
  335. package/dist/rest.js.map +1 -0
  336. package/dist/schema.d.ts +15 -0
  337. package/dist/schema.d.ts.map +1 -0
  338. package/dist/schema.js +15 -0
  339. package/dist/schema.js.map +1 -0
  340. package/dist/seeds.d.ts +27 -0
  341. package/dist/seeds.d.ts.map +1 -0
  342. package/dist/seeds.js +47 -0
  343. package/dist/seeds.js.map +1 -0
  344. package/dist/session.d.ts +39 -0
  345. package/dist/session.d.ts.map +1 -0
  346. package/dist/session.js +92 -0
  347. package/dist/session.js.map +1 -0
  348. package/dist/sql.d.ts +48 -0
  349. package/dist/sql.d.ts.map +1 -0
  350. package/dist/sql.js +112 -0
  351. package/dist/sql.js.map +1 -0
  352. package/dist/status.d.ts +94 -0
  353. package/dist/status.d.ts.map +1 -0
  354. package/dist/status.js +120 -0
  355. package/dist/status.js.map +1 -0
  356. package/dist/ui.d.ts +55 -0
  357. package/dist/ui.d.ts.map +1 -0
  358. package/dist/ui.js +114 -0
  359. package/dist/ui.js.map +1 -0
  360. package/package.json +29 -0
  361. package/schema/output.1.json +613 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAmC,MAAM,eAAe,CAAC;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAsC,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAKnH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kFAAkF;IAClF,SAAS,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IACpE,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,CAA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ostgREST, with that person's token.
3
+ *
4
+ * Everything a bookkeeping command does goes through here, and nothing here
5
+ * holds a privilege: the `apikey` is the publishable one, the bearer is the
6
+ * session of whoever signed in, and row level security decides the rest —
7
+ * exactly as it does for the MCP server, which calls the same functions.
8
+ *
9
+ * **A refusal keeps its SQLSTATE over this route.** PostgREST answers an error
10
+ * of the database with the fields Postgres gave it — `code`, `message`,
11
+ * `details`, `hint` — so the error thrown here carries `code`, `detail` and
12
+ * `hint` the way both SQL drivers do, and `output.ts` reads a locked period
13
+ * off it as exit code 3 without knowing which route it came over. An error of
14
+ * PostgREST's own is `PGRST…`, which is not an SQLSTATE and stays a failure.
15
+ *
16
+ * **A token that stopped working is renewed once, and the call is made
17
+ * again.** An access token lasts an hour and a terminal stays open for a day.
18
+ * It is renewed ahead of time when it is about to lapse, and after the fact
19
+ * when the instance answers 401 anyway — a clock that drifted, a session the
20
+ * instance ended early. The renewed session is handed to whoever keeps it;
21
+ * a session that cannot be renewed is `session_expired`, never a retry loop.
22
+ */
23
+ import { UsageError } from './args.js';
24
+ import { AuthError, baseUrl, refreshSession } from './session.js';
25
+ /** Renew when this close to the end, in seconds. */
26
+ const RENEW_BEFORE = 60;
27
+ /** What the database, or PostgREST in front of it, answered. Shaped like a driver error. */
28
+ export class RestError extends Error {
29
+ code;
30
+ detail;
31
+ hint;
32
+ constructor(message, fields) {
33
+ super(message);
34
+ this.code = fields.code;
35
+ this.detail = fields.detail;
36
+ this.hint = fields.hint;
37
+ }
38
+ }
39
+ function text(value) {
40
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
41
+ }
42
+ export class UserClient {
43
+ options;
44
+ accessToken;
45
+ refreshToken;
46
+ expiresAt;
47
+ constructor(options) {
48
+ this.options = options;
49
+ this.accessToken = options.accessToken;
50
+ this.refreshToken = options.refreshToken;
51
+ this.expiresAt = options.expiresAt;
52
+ }
53
+ get instance() {
54
+ return this.options.instance;
55
+ }
56
+ now() {
57
+ return this.options.now?.() ?? Math.floor(Date.now() / 1000);
58
+ }
59
+ expired() {
60
+ return new UsageError(`session_expired: the session is over and could not be renewed. ${this.options.signInAgain}`);
61
+ }
62
+ async renew() {
63
+ if (this.refreshToken === undefined)
64
+ throw this.expired();
65
+ let renewed;
66
+ try {
67
+ renewed = await refreshSession(this.options.fetchImpl, this.options.instance, this.refreshToken);
68
+ }
69
+ catch (error) {
70
+ // The instance declined the refresh token: revoked, used twice, too old.
71
+ // Anything else — no network — is a failure and says so itself.
72
+ if (error instanceof AuthError && error.status >= 400 && error.status < 500)
73
+ throw this.expired();
74
+ throw error;
75
+ }
76
+ this.accessToken = renewed.session.access_token;
77
+ this.refreshToken = renewed.session.refresh_token;
78
+ this.expiresAt = renewed.session.expires_at;
79
+ await this.options.onRenewed?.(renewed.session);
80
+ }
81
+ /** One request as the user; renewed and made again, once, on a 401. */
82
+ async request(path, init) {
83
+ if (this.refreshToken !== undefined &&
84
+ this.expiresAt !== undefined &&
85
+ this.expiresAt - this.now() <= RENEW_BEFORE) {
86
+ await this.renew();
87
+ }
88
+ const send = () => this.options.fetchImpl(`${baseUrl(this.options.instance.supabaseUrl)}${path}`, {
89
+ ...init,
90
+ headers: {
91
+ ...init.headers,
92
+ apikey: this.options.instance.anonKey,
93
+ Authorization: `Bearer ${this.accessToken}`,
94
+ },
95
+ });
96
+ const first = await send();
97
+ if (first.status !== 401)
98
+ return first;
99
+ await this.renew();
100
+ const second = await send();
101
+ if (second.status === 401)
102
+ throw this.expired();
103
+ return second;
104
+ }
105
+ async answer(response, what) {
106
+ let body;
107
+ try {
108
+ body = (await response.json());
109
+ }
110
+ catch {
111
+ body = undefined;
112
+ }
113
+ if (response.ok)
114
+ return body;
115
+ const record = (typeof body === 'object' && body !== null ? body : {});
116
+ throw new RestError(text(record['message']) ?? `${what}: the instance answered ${response.status}`, {
117
+ code: text(record['code']),
118
+ detail: text(record['details']),
119
+ hint: text(record['hint']),
120
+ });
121
+ }
122
+ /** Calls a function of the schema. Rows, whatever the function returns. */
123
+ async rpc(fn, args = {}) {
124
+ const response = await this.request(`/rest/v1/rpc/${encodeURIComponent(fn)}`, {
125
+ method: 'POST',
126
+ headers: { 'Content-Type': 'application/json' },
127
+ body: JSON.stringify(args),
128
+ });
129
+ const data = await this.answer(response, fn);
130
+ return (Array.isArray(data) ? data : [data]);
131
+ }
132
+ /** Reads what the policies let this person see of a table. */
133
+ async select(table, options) {
134
+ const query = new URLSearchParams({ select: options.columns.join(',') });
135
+ if (options.order !== undefined)
136
+ query.set('order', options.order);
137
+ const response = await this.request(`/rest/v1/${encodeURIComponent(table)}?${query.toString()}`, {
138
+ method: 'GET',
139
+ });
140
+ return this.answer(response, `select from ${table}`);
141
+ }
142
+ /** Who the instance says this token is. Also the cheapest way to learn it stopped working. */
143
+ async user() {
144
+ const response = await this.request('/auth/v1/user', { method: 'GET' });
145
+ const body = await this.answer(response, 'reading the user');
146
+ const id = text(body['id']);
147
+ if (id === undefined)
148
+ throw new Error('unknown_user: the instance answered without a user');
149
+ return { id, email: text(body['email']) };
150
+ }
151
+ token() {
152
+ return this.accessToken;
153
+ }
154
+ /**
155
+ * This client as the `Backend` the bookkeeping functions of the core are
156
+ * written against — the interface the MCP server implements over
157
+ * `@supabase/supabase-js`. Same five operations, same functions on top.
158
+ */
159
+ backend(actingAs) {
160
+ const profile = (schema, write) => schema === undefined ? {} : { [write ? 'Content-Profile' : 'Accept-Profile']: schema };
161
+ const call = async (fn, args, schema) => {
162
+ const response = await this.request(`/rest/v1/rpc/${encodeURIComponent(fn)}`, {
163
+ method: 'POST',
164
+ headers: { 'Content-Type': 'application/json', ...profile(schema, true) },
165
+ body: JSON.stringify(args),
166
+ });
167
+ return this.answer(response, fn);
168
+ };
169
+ return {
170
+ mode: 'postgrest',
171
+ actingAs,
172
+ rpc: async (fn, args = {}, schema) => {
173
+ const data = await call(fn, args, schema);
174
+ return (Array.isArray(data) ? data : [data]);
175
+ },
176
+ rpcVoid: async (fn, args = {}, schema) => {
177
+ await call(fn, args, schema);
178
+ },
179
+ select: async (query) => {
180
+ const params = filterParams(query.where);
181
+ params.set('select', query.columns.join(','));
182
+ if (query.order !== undefined && query.order.length > 0) {
183
+ params.set('order', query.order.map((o) => `${o.column}.${o.ascending === false ? 'desc' : 'asc'}`).join(','));
184
+ }
185
+ if (query.limit !== undefined)
186
+ params.set('limit', String(query.limit));
187
+ const response = await this.request(`/rest/v1/${encodeURIComponent(query.table)}?${params.toString()}`, {
188
+ method: 'GET',
189
+ headers: profile(query.schema, false),
190
+ });
191
+ return this.answer(response, `select from ${query.table}`);
192
+ },
193
+ insert: async (table, rows, returning = ['*'], schema) => {
194
+ const params = new URLSearchParams({ select: returning.join(',') });
195
+ const response = await this.request(`/rest/v1/${encodeURIComponent(table)}?${params.toString()}`, {
196
+ method: 'POST',
197
+ headers: { 'Content-Type': 'application/json', Prefer: 'return=representation', ...profile(schema, true) },
198
+ body: JSON.stringify(rows),
199
+ });
200
+ return this.answer(response, `insert into ${table}`);
201
+ },
202
+ update: async (table, patch, where, returning = ['*'], schema) => {
203
+ const params = filterParams(where);
204
+ params.set('select', returning.join(','));
205
+ const response = await this.request(`/rest/v1/${encodeURIComponent(table)}?${params.toString()}`, {
206
+ method: 'PATCH',
207
+ headers: { 'Content-Type': 'application/json', Prefer: 'return=representation', ...profile(schema, true) },
208
+ body: JSON.stringify(patch),
209
+ });
210
+ return this.answer(response, `update ${table}`);
211
+ },
212
+ remove: async (table, where, schema) => {
213
+ const response = await this.request(`/rest/v1/${encodeURIComponent(table)}?${filterParams(where).toString()}`, {
214
+ method: 'DELETE',
215
+ headers: profile(schema, true),
216
+ });
217
+ if (!response.ok)
218
+ await this.answer(response, `delete from ${table}`);
219
+ },
220
+ close: async () => { },
221
+ };
222
+ }
223
+ }
224
+ /** A value inside `in.(…)`: quoted, so a comma or a parenthesis in it is text. */
225
+ function listed(value) {
226
+ return value === null ? 'null' : `"${String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
227
+ }
228
+ /** Filters, in the spelling PostgREST reads from a query string. */
229
+ function filterParams(filters) {
230
+ const params = new URLSearchParams();
231
+ for (const filter of filters ?? []) {
232
+ switch (filter.op) {
233
+ case 'is':
234
+ params.append(filter.column, 'is.null');
235
+ break;
236
+ case 'in':
237
+ params.append(filter.column, `in.(${filter.value.map(listed).join(',')})`);
238
+ break;
239
+ default:
240
+ params.append(filter.column, `${filter.op}.${String(filter.value)}`);
241
+ }
242
+ }
243
+ return params;
244
+ }
245
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAmD,MAAM,cAAc,CAAC;AAEnH,oDAAoD;AACpD,MAAM,YAAY,GAAG,EAAE,CAAC;AAqBxB,4FAA4F;AAC5F,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,IAAI,CAAqB;IACzB,MAAM,CAAqB;IAC3B,IAAI,CAAqB;IACzB,YAAY,OAAe,EAAE,MAA6F;QACxH,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF;AAED,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC;AAED,MAAM,OAAO,UAAU;IAKQ;IAJrB,WAAW,CAAS;IACpB,YAAY,CAAqB;IACjC,SAAS,CAAqB;IAEtC,YAA6B,OA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AM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The schema version this CLI is written against.
3
+ *
4
+ * It is the one package of the three that also *carries* the migrations, so
5
+ * the number below is a floor and not a requirement it could fail: `ekwo
6
+ * migrate` moves a database up to what this release defines. What it buys is
7
+ * an installation that was set up by a much older release being named as such
8
+ * by `ekwo status`, instead of failing later in a query nobody can place.
9
+ *
10
+ * Declared in `package.json` under `ekwo.schemaMin` and repeated here, as in
11
+ * every package of this repository; `tests/cli/package.test.ts` keeps the two
12
+ * equal.
13
+ */
14
+ export declare const SCHEMA_MIN = "0.4.0";
15
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,UAAU,UAAU,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The schema version this CLI is written against.
3
+ *
4
+ * It is the one package of the three that also *carries* the migrations, so
5
+ * the number below is a floor and not a requirement it could fail: `ekwo
6
+ * migrate` moves a database up to what this release defines. What it buys is
7
+ * an installation that was set up by a much older release being named as such
8
+ * by `ekwo status`, instead of failing later in a query nobody can place.
9
+ *
10
+ * Declared in `package.json` under `ekwo.schemaMin` and repeated here, as in
11
+ * every package of this repository; `tests/cli/package.test.ts` keeps the two
12
+ * equal.
13
+ */
14
+ export const SCHEMA_MIN = '0.4.0';
15
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Reference data.
3
+ *
4
+ * `supabase/seed/*.sql` fills the template tables — currencies, the Belgian
5
+ * and French charts of accounts, their VAT codes — from which
6
+ * `install_country_template()` gives each company its own copy. Every file is
7
+ * written with `on conflict do nothing`, so applying them twice changes
8
+ * nothing, and they are deliberately *not* recorded in the migration history:
9
+ * they are data a new release may legitimately re-apply.
10
+ *
11
+ * `90_demo_company.sql` is not reference data and never runs here. It is
12
+ * sample data, it invents a company and a fictional administrator, and it
13
+ * only ever runs through `ekwo demo`.
14
+ */
15
+ import type { SqlClient } from './sql.js';
16
+ export interface Seed {
17
+ file: string;
18
+ path: string;
19
+ }
20
+ /** The reference seeds, in order, with the demo file left out. */
21
+ export declare function listSeeds(dir: string): Promise<Seed[]>;
22
+ export declare function applySeed(db: SqlClient, seed: Seed): Promise<void>;
23
+ /** Applies every reference seed, reporting each as it lands. */
24
+ export declare function applySeeds(db: SqlClient, dir: string, onApplied?: (seed: Seed) => void): Promise<Seed[]>;
25
+ /** The demo company, on explicit request only. */
26
+ export declare function applyDemoSeed(db: SqlClient, dir: string): Promise<void>;
27
+ //# sourceMappingURL=seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.d.ts","sourceRoot":"","sources":["../src/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,kEAAkE;AAClE,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAK5D;AAED,wBAAsB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED,gEAAgE;AAChE,wBAAsB,UAAU,CAC9B,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAC/B,OAAO,CAAC,IAAI,EAAE,CAAC,CAOjB;AAED,kDAAkD;AAClD,wBAAsB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7E"}
package/dist/seeds.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Reference data.
3
+ *
4
+ * `supabase/seed/*.sql` fills the template tables — currencies, the Belgian
5
+ * and French charts of accounts, their VAT codes — from which
6
+ * `install_country_template()` gives each company its own copy. Every file is
7
+ * written with `on conflict do nothing`, so applying them twice changes
8
+ * nothing, and they are deliberately *not* recorded in the migration history:
9
+ * they are data a new release may legitimately re-apply.
10
+ *
11
+ * `90_demo_company.sql` is not reference data and never runs here. It is
12
+ * sample data, it invents a company and a fictional administrator, and it
13
+ * only ever runs through `ekwo demo`.
14
+ */
15
+ import { readFile, readdir } from 'node:fs/promises';
16
+ import { join } from 'node:path';
17
+ import { DEMO_SEED } from './bundle.js';
18
+ /** The reference seeds, in order, with the demo file left out. */
19
+ export async function listSeeds(dir) {
20
+ const files = (await readdir(dir))
21
+ .filter((f) => f.endsWith('.sql') && f !== DEMO_SEED)
22
+ .sort();
23
+ return files.map((file) => ({ file, path: join(dir, file) }));
24
+ }
25
+ export async function applySeed(db, seed) {
26
+ const sql = await readFile(seed.path, 'utf8');
27
+ try {
28
+ await db.exec(sql);
29
+ }
30
+ catch (error) {
31
+ throw new Error(`seed_failed: ${seed.file} — ${error.message}`);
32
+ }
33
+ }
34
+ /** Applies every reference seed, reporting each as it lands. */
35
+ export async function applySeeds(db, dir, onApplied) {
36
+ const seeds = await listSeeds(dir);
37
+ for (const seed of seeds) {
38
+ await applySeed(db, seed);
39
+ onApplied?.(seed);
40
+ }
41
+ return seeds;
42
+ }
43
+ /** The demo company, on explicit request only. */
44
+ export async function applyDemoSeed(db, dir) {
45
+ await applySeed(db, { file: DEMO_SEED, path: join(dir, DEMO_SEED) });
46
+ }
47
+ //# sourceMappingURL=seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.js","sourceRoot":"","sources":["../src/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQxC,kEAAkE;AAClE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW;IACzC,MAAM,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;SAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;SACpD,IAAI,EAAE,CAAC;IACV,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAAa,EAAE,IAAU;IACvD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,IAAI,MAAO,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,EAAa,EACb,GAAW,EACX,SAAgC;IAEhC,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1B,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,kDAAkD;AAClD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,EAAa,EAAE,GAAW;IAC5D,MAAM,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Signing in, and staying signed in — over `fetch`, by hand.
3
+ *
4
+ * The MCP server uses `@supabase/supabase-js` for this and says why: a library
5
+ * known to work beats code of ours that is merely untested. The command line
6
+ * answers the other way, for the reason `args.ts` gives: it is handed a
7
+ * password, and every package it loads is a package that could read it. The
8
+ * whole exchange is three requests to the instance's auth endpoint — a
9
+ * password grant, a refresh grant, and "who is this token" — so it is written
10
+ * out here, and `tests/cli/login.test.ts` runs each of them, the refresh of a
11
+ * lost token included.
12
+ */
13
+ import type { StoredSession } from './profiles.js';
14
+ export type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
15
+ export interface Instance {
16
+ supabaseUrl: string;
17
+ anonKey: string;
18
+ }
19
+ export interface SessionUser {
20
+ id: string;
21
+ email: string | undefined;
22
+ }
23
+ export interface SignedIn {
24
+ session: StoredSession;
25
+ user: SessionUser;
26
+ }
27
+ /** The instance's auth service said no. `status` is what it answered with. */
28
+ export declare class AuthError extends Error {
29
+ readonly status: number;
30
+ constructor(message: string, status: number);
31
+ }
32
+ export declare function baseUrl(supabaseUrl: string): string;
33
+ /** The password goes to the instance once and is kept nowhere. */
34
+ export declare function signIn(fetchImpl: FetchLike, instance: Instance, email: string, password: string): Promise<SignedIn>;
35
+ /** The instance rotates the refresh token: what comes back replaces what was sent. */
36
+ export declare function refreshSession(fetchImpl: FetchLike, instance: Instance, refreshToken: string): Promise<SignedIn>;
37
+ /** Tells the instance the session is over. Best effort: the local copy goes either way. */
38
+ export declare function signOut(fetchImpl: FetchLike, instance: Instance, accessToken: string): Promise<boolean>;
39
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE/E,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,8EAA8E;AAC9E,qBAAa,SAAU,SAAQ,KAAK;IAGhC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;CAI1B;AAED,wBAAgB,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEnD;AAyDD,kEAAkE;AAClE,wBAAgB,MAAM,CACpB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,CAAC,CAEnB;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAC5B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,QAAQ,CAAC,CAEnB;AAED,2FAA2F;AAC3F,wBAAsB,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAU7G"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Signing in, and staying signed in — over `fetch`, by hand.
3
+ *
4
+ * The MCP server uses `@supabase/supabase-js` for this and says why: a library
5
+ * known to work beats code of ours that is merely untested. The command line
6
+ * answers the other way, for the reason `args.ts` gives: it is handed a
7
+ * password, and every package it loads is a package that could read it. The
8
+ * whole exchange is three requests to the instance's auth endpoint — a
9
+ * password grant, a refresh grant, and "who is this token" — so it is written
10
+ * out here, and `tests/cli/login.test.ts` runs each of them, the refresh of a
11
+ * lost token included.
12
+ */
13
+ /** The instance's auth service said no. `status` is what it answered with. */
14
+ export class AuthError extends Error {
15
+ status;
16
+ constructor(message, status) {
17
+ super(message);
18
+ this.status = status;
19
+ }
20
+ }
21
+ export function baseUrl(supabaseUrl) {
22
+ return supabaseUrl.replace(/\/+$/, '');
23
+ }
24
+ function said(body, fallback) {
25
+ if (typeof body !== 'object' || body === null)
26
+ return fallback;
27
+ const record = body;
28
+ for (const key of ['msg', 'error_description', 'message', 'error']) {
29
+ const value = record[key];
30
+ if (typeof value === 'string' && value.length > 0)
31
+ return value;
32
+ }
33
+ return fallback;
34
+ }
35
+ async function bodyOf(response) {
36
+ try {
37
+ return (await response.json());
38
+ }
39
+ catch {
40
+ return undefined;
41
+ }
42
+ }
43
+ function signedIn(body, now) {
44
+ const record = (body ?? {});
45
+ const access = record['access_token'];
46
+ const refresh = record['refresh_token'];
47
+ const user = (record['user'] ?? {});
48
+ if (typeof access !== 'string' || typeof refresh !== 'string' || typeof user['id'] !== 'string') {
49
+ throw new AuthError('sign_in_failed: the instance answered without a session', 502);
50
+ }
51
+ const expiresAt = typeof record['expires_at'] === 'number'
52
+ ? record['expires_at']
53
+ : now + (typeof record['expires_in'] === 'number' ? record['expires_in'] : 0);
54
+ return {
55
+ session: { access_token: access, refresh_token: refresh, expires_at: expiresAt },
56
+ user: { id: user['id'], email: typeof user['email'] === 'string' ? user['email'] : undefined },
57
+ };
58
+ }
59
+ async function grant(fetchImpl, instance, type, body, failure) {
60
+ const response = await fetchImpl(`${baseUrl(instance.supabaseUrl)}/auth/v1/token?grant_type=${type}`, {
61
+ method: 'POST',
62
+ headers: { apikey: instance.anonKey, 'Content-Type': 'application/json' },
63
+ body: JSON.stringify(body),
64
+ });
65
+ const answer = await bodyOf(response);
66
+ if (!response.ok) {
67
+ throw new AuthError(`${failure}: ${said(answer, `the instance answered ${response.status}`)}`, response.status);
68
+ }
69
+ return signedIn(answer, Math.floor(Date.now() / 1000));
70
+ }
71
+ /** The password goes to the instance once and is kept nowhere. */
72
+ export function signIn(fetchImpl, instance, email, password) {
73
+ return grant(fetchImpl, instance, 'password', { email, password }, 'sign_in_failed');
74
+ }
75
+ /** The instance rotates the refresh token: what comes back replaces what was sent. */
76
+ export function refreshSession(fetchImpl, instance, refreshToken) {
77
+ return grant(fetchImpl, instance, 'refresh_token', { refresh_token: refreshToken }, 'refresh_failed');
78
+ }
79
+ /** Tells the instance the session is over. Best effort: the local copy goes either way. */
80
+ export async function signOut(fetchImpl, instance, accessToken) {
81
+ try {
82
+ const response = await fetchImpl(`${baseUrl(instance.supabaseUrl)}/auth/v1/logout?scope=local`, {
83
+ method: 'POST',
84
+ headers: { apikey: instance.anonKey, Authorization: `Bearer ${accessToken}` },
85
+ });
86
+ return response.ok;
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ //# sourceMappingURL=session.js.map
@@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AC,CAAC;QACH,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/dist/sql.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The only way this CLI talks to Postgres.
3
+ *
4
+ * Everything above this file is written against `SqlClient`, so the same
5
+ * migration runner, bootstrap and checks can run against a real Supabase
6
+ * project (the `postgres` driver, below) and against PGlite in the tests.
7
+ * No command imports a driver directly.
8
+ */
9
+ /** A Postgres connection, reduced to what this CLI needs. */
10
+ export interface SqlClient {
11
+ /** Multi-statement SQL with no parameters, sent as one command string. */
12
+ exec(sql: string): Promise<void>;
13
+ /** One parameterised statement (`$1`, `$2`, …), returning its rows. */
14
+ query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
15
+ /** Runs `fn` inside a transaction; a throw rolls the whole thing back. */
16
+ transaction<T>(fn: (tx: SqlClient) => Promise<T>): Promise<T>;
17
+ /** Closes the connection. Calling it twice is harmless. */
18
+ close(): Promise<void>;
19
+ }
20
+ /** One row, or `undefined` when the query returned none. */
21
+ export declare function first<T = Record<string, unknown>>(db: SqlClient, sql: string, params?: unknown[]): Promise<T | undefined>;
22
+ /** One scalar, or `undefined`. */
23
+ export declare function scalar<T>(db: SqlClient, sql: string, params?: unknown[]): Promise<T | undefined>;
24
+ /**
25
+ * Connects to Postgres with the `postgres` driver.
26
+ *
27
+ * Imported lazily so that the tests — which plug PGlite into `SqlClient` —
28
+ * never load a network driver, and so `ekwo --help` costs nothing.
29
+ *
30
+ * `prepare: false` because Supabase's transaction-mode pooler (port 6543)
31
+ * rejects prepared statements; the CLI works on either port with it off.
32
+ */
33
+ export declare function connect(connectionString: string): Promise<SqlClient>;
34
+ /**
35
+ * Runs `fn` with `auth.uid()` answering `userId`.
36
+ *
37
+ * The CLI holds a superuser connection, so row level security is bypassed —
38
+ * but the guards written *inside* the schema's functions (`register_instance`
39
+ * refusing anyone who is not an instance administrator, for one) read
40
+ * `auth.uid()` and would refuse the installer. Setting the request claim the
41
+ * way PostgREST does makes those functions see the administrator the CLI is
42
+ * acting for, so the rule is satisfied rather than circumvented.
43
+ *
44
+ * The connection pool is capped at one, so the setting and the call land on
45
+ * the same backend.
46
+ */
47
+ export declare function asUser<T>(db: SqlClient, userId: string, fn: () => Promise<T>): Promise<T>;
48
+ //# sourceMappingURL=sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,SAAS;IACxB,0EAA0E;IAC1E,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,uEAAuE;IACvE,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAClF,0EAA0E;IAC1E,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9D,2DAA2D;IAC3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,4DAA4D;AAC5D,wBAAsB,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrD,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAO,EAAO,GACrB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAGxB;AAED,kCAAkC;AAClC,wBAAsB,MAAM,CAAC,CAAC,EAC5B,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,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