@dainamite/billing 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +658 -0
  2. package/LICENSE +21 -0
  3. package/README.md +77 -0
  4. package/dist/modules/billing/acl.js +20 -0
  5. package/dist/modules/billing/acl.js.map +7 -0
  6. package/dist/modules/billing/api/accounts/route.js +182 -0
  7. package/dist/modules/billing/api/accounts/route.js.map +7 -0
  8. package/dist/modules/billing/api/export/account/[id]/route.js +170 -0
  9. package/dist/modules/billing/api/export/account/[id]/route.js.map +7 -0
  10. package/dist/modules/billing/api/invoices/[id]/route.js +85 -0
  11. package/dist/modules/billing/api/invoices/[id]/route.js.map +7 -0
  12. package/dist/modules/billing/api/invoices/add-line/route.js +69 -0
  13. package/dist/modules/billing/api/invoices/add-line/route.js.map +7 -0
  14. package/dist/modules/billing/api/invoices/edit-line/route.js +78 -0
  15. package/dist/modules/billing/api/invoices/edit-line/route.js.map +7 -0
  16. package/dist/modules/billing/api/invoices/post/route.js +74 -0
  17. package/dist/modules/billing/api/invoices/post/route.js.map +7 -0
  18. package/dist/modules/billing/api/invoices/remove-line/route.js +69 -0
  19. package/dist/modules/billing/api/invoices/remove-line/route.js.map +7 -0
  20. package/dist/modules/billing/api/invoices/route.js +109 -0
  21. package/dist/modules/billing/api/invoices/route.js.map +7 -0
  22. package/dist/modules/billing/api/items/bulk/route.js +74 -0
  23. package/dist/modules/billing/api/items/bulk/route.js.map +7 -0
  24. package/dist/modules/billing/api/items/route.js +224 -0
  25. package/dist/modules/billing/api/items/route.js.map +7 -0
  26. package/dist/modules/billing/api/openapi.js +25 -0
  27. package/dist/modules/billing/api/openapi.js.map +7 -0
  28. package/dist/modules/billing/api/run-outcomes/route.js +122 -0
  29. package/dist/modules/billing/api/run-outcomes/route.js.map +7 -0
  30. package/dist/modules/billing/api/runs/retry-failed/route.js +70 -0
  31. package/dist/modules/billing/api/runs/retry-failed/route.js.map +7 -0
  32. package/dist/modules/billing/api/runs/route.js +143 -0
  33. package/dist/modules/billing/api/runs/route.js.map +7 -0
  34. package/dist/modules/billing/api/test-invoices/wipe/route.js +65 -0
  35. package/dist/modules/billing/api/test-invoices/wipe/route.js.map +7 -0
  36. package/dist/modules/billing/api/usage/route.js +138 -0
  37. package/dist/modules/billing/api/usage/route.js.map +7 -0
  38. package/dist/modules/billing/backend/billing/accounts/[id]/page.js +402 -0
  39. package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +7 -0
  40. package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js +25 -0
  41. package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js.map +7 -0
  42. package/dist/modules/billing/backend/billing/accounts/create/page.js +82 -0
  43. package/dist/modules/billing/backend/billing/accounts/create/page.js.map +7 -0
  44. package/dist/modules/billing/backend/billing/accounts/create/page.meta.js +25 -0
  45. package/dist/modules/billing/backend/billing/accounts/create/page.meta.js.map +7 -0
  46. package/dist/modules/billing/backend/billing/accounts/page.js +173 -0
  47. package/dist/modules/billing/backend/billing/accounts/page.js.map +7 -0
  48. package/dist/modules/billing/backend/billing/accounts/page.meta.js +18 -0
  49. package/dist/modules/billing/backend/billing/accounts/page.meta.js.map +7 -0
  50. package/dist/modules/billing/backend/billing/invoices/[id]/page.js +500 -0
  51. package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +7 -0
  52. package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js +25 -0
  53. package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js.map +7 -0
  54. package/dist/modules/billing/backend/billing/invoices/page.js +187 -0
  55. package/dist/modules/billing/backend/billing/invoices/page.js.map +7 -0
  56. package/dist/modules/billing/backend/billing/invoices/page.meta.js +18 -0
  57. package/dist/modules/billing/backend/billing/invoices/page.meta.js.map +7 -0
  58. package/dist/modules/billing/backend/billing/items/[id]/page.js +265 -0
  59. package/dist/modules/billing/backend/billing/items/[id]/page.js.map +7 -0
  60. package/dist/modules/billing/backend/billing/items/[id]/page.meta.js +25 -0
  61. package/dist/modules/billing/backend/billing/items/[id]/page.meta.js.map +7 -0
  62. package/dist/modules/billing/backend/billing/items/create/page.js +90 -0
  63. package/dist/modules/billing/backend/billing/items/create/page.js.map +7 -0
  64. package/dist/modules/billing/backend/billing/items/create/page.meta.js +25 -0
  65. package/dist/modules/billing/backend/billing/items/create/page.meta.js.map +7 -0
  66. package/dist/modules/billing/backend/billing/items/page.js +208 -0
  67. package/dist/modules/billing/backend/billing/items/page.js.map +7 -0
  68. package/dist/modules/billing/backend/billing/items/page.meta.js +18 -0
  69. package/dist/modules/billing/backend/billing/items/page.meta.js.map +7 -0
  70. package/dist/modules/billing/backend/billing/runs/[id]/page.js +293 -0
  71. package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +7 -0
  72. package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js +21 -0
  73. package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js.map +7 -0
  74. package/dist/modules/billing/backend/billing/runs/page.js +341 -0
  75. package/dist/modules/billing/backend/billing/runs/page.js.map +7 -0
  76. package/dist/modules/billing/backend/billing/runs/page.meta.js +18 -0
  77. package/dist/modules/billing/backend/billing/runs/page.meta.js.map +7 -0
  78. package/dist/modules/billing/backend/billing/usage/create/page.js +100 -0
  79. package/dist/modules/billing/backend/billing/usage/create/page.js.map +7 -0
  80. package/dist/modules/billing/backend/billing/usage/create/page.meta.js +25 -0
  81. package/dist/modules/billing/backend/billing/usage/create/page.meta.js.map +7 -0
  82. package/dist/modules/billing/ce.js +56 -0
  83. package/dist/modules/billing/ce.js.map +7 -0
  84. package/dist/modules/billing/cli.js +67 -0
  85. package/dist/modules/billing/cli.js.map +7 -0
  86. package/dist/modules/billing/commands/accounts.js +157 -0
  87. package/dist/modules/billing/commands/accounts.js.map +7 -0
  88. package/dist/modules/billing/commands/index.js +6 -0
  89. package/dist/modules/billing/commands/index.js.map +7 -0
  90. package/dist/modules/billing/commands/invoices.js +401 -0
  91. package/dist/modules/billing/commands/invoices.js.map +7 -0
  92. package/dist/modules/billing/commands/items.js +317 -0
  93. package/dist/modules/billing/commands/items.js.map +7 -0
  94. package/dist/modules/billing/commands/runs.js +123 -0
  95. package/dist/modules/billing/commands/runs.js.map +7 -0
  96. package/dist/modules/billing/commands/usage.js +88 -0
  97. package/dist/modules/billing/commands/usage.js.map +7 -0
  98. package/dist/modules/billing/components/AccountForm.js +420 -0
  99. package/dist/modules/billing/components/AccountForm.js.map +7 -0
  100. package/dist/modules/billing/components/DetailFields.js +37 -0
  101. package/dist/modules/billing/components/DetailFields.js.map +7 -0
  102. package/dist/modules/billing/components/ItemForm.js +440 -0
  103. package/dist/modules/billing/components/ItemForm.js.map +7 -0
  104. package/dist/modules/billing/components/LineFormDialog.js +195 -0
  105. package/dist/modules/billing/components/LineFormDialog.js.map +7 -0
  106. package/dist/modules/billing/components/UsageForm.js +262 -0
  107. package/dist/modules/billing/components/UsageForm.js.map +7 -0
  108. package/dist/modules/billing/data/entities.js +433 -0
  109. package/dist/modules/billing/data/entities.js.map +7 -0
  110. package/dist/modules/billing/data/entityIds.js +12 -0
  111. package/dist/modules/billing/data/entityIds.js.map +7 -0
  112. package/dist/modules/billing/data/validators.js +396 -0
  113. package/dist/modules/billing/data/validators.js.map +7 -0
  114. package/dist/modules/billing/di.js +6 -0
  115. package/dist/modules/billing/di.js.map +7 -0
  116. package/dist/modules/billing/events.js +35 -0
  117. package/dist/modules/billing/events.js.map +7 -0
  118. package/dist/modules/billing/i18n/en.json +336 -0
  119. package/dist/modules/billing/i18n/pl.json +336 -0
  120. package/dist/modules/billing/index.js +17 -0
  121. package/dist/modules/billing/index.js.map +7 -0
  122. package/dist/modules/billing/lib/billPeriod.js +101 -0
  123. package/dist/modules/billing/lib/billPeriod.js.map +7 -0
  124. package/dist/modules/billing/lib/billRunEngine.js +256 -0
  125. package/dist/modules/billing/lib/billRunEngine.js.map +7 -0
  126. package/dist/modules/billing/lib/billRunLabel.js +8 -0
  127. package/dist/modules/billing/lib/billRunLabel.js.map +7 -0
  128. package/dist/modules/billing/lib/idempotency.js +13 -0
  129. package/dist/modules/billing/lib/idempotency.js.map +7 -0
  130. package/dist/modules/billing/lib/invoiceStatus.js +38 -0
  131. package/dist/modules/billing/lib/invoiceStatus.js.map +7 -0
  132. package/dist/modules/billing/lib/invoiceWriter.js +153 -0
  133. package/dist/modules/billing/lib/invoiceWriter.js.map +7 -0
  134. package/dist/modules/billing/lib/itemSelector.js +77 -0
  135. package/dist/modules/billing/lib/itemSelector.js.map +7 -0
  136. package/dist/modules/billing/lib/seeds/demo.js +130 -0
  137. package/dist/modules/billing/lib/seeds/demo.js.map +7 -0
  138. package/dist/modules/billing/lib/tenantLock.js +32 -0
  139. package/dist/modules/billing/lib/tenantLock.js.map +7 -0
  140. package/dist/modules/billing/lib/usageRater.js +150 -0
  141. package/dist/modules/billing/lib/usageRater.js.map +7 -0
  142. package/dist/modules/billing/lib/usageRunner.js +82 -0
  143. package/dist/modules/billing/lib/usageRunner.js.map +7 -0
  144. package/dist/modules/billing/migrations/Migration20260519000000_billing.js +144 -0
  145. package/dist/modules/billing/migrations/Migration20260519000000_billing.js.map +7 -0
  146. package/dist/modules/billing/setup.js +190 -0
  147. package/dist/modules/billing/setup.js.map +7 -0
  148. package/dist/modules/billing/subscribers/payment-captured-to-paid.js +47 -0
  149. package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +7 -0
  150. package/dist/modules/billing/translations.js +5 -0
  151. package/dist/modules/billing/translations.js.map +7 -0
  152. package/dist/modules/billing/workers/reap-stale-bill-runs.js +31 -0
  153. package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +7 -0
  154. package/package.json +148 -0
  155. package/src/modules/billing/__integration__/TC-BILL-001.spec.ts +116 -0
  156. package/src/modules/billing/__integration__/TC-BILL-002.spec.ts +169 -0
  157. package/src/modules/billing/__integration__/TC-BILL-003.spec.ts +28 -0
  158. package/src/modules/billing/__integration__/meta.ts +4 -0
  159. package/src/modules/billing/__tests__/commands/invoices.test.ts +464 -0
  160. package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +284 -0
  161. package/src/modules/billing/__tests__/lib/billPeriod.test.ts +131 -0
  162. package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +561 -0
  163. package/src/modules/billing/__tests__/lib/idempotency.test.ts +81 -0
  164. package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +97 -0
  165. package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +119 -0
  166. package/src/modules/billing/__tests__/lib/itemSelector.test.ts +192 -0
  167. package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +86 -0
  168. package/src/modules/billing/__tests__/lib/tenantLock.test.ts +126 -0
  169. package/src/modules/billing/__tests__/lib/usageRater.test.ts +190 -0
  170. package/src/modules/billing/__tests__/package-isolation.test.ts +223 -0
  171. package/src/modules/billing/__tests__/setup.test.ts +107 -0
  172. package/src/modules/billing/__tests__/validators.test.ts +594 -0
  173. package/src/modules/billing/acl.ts +16 -0
  174. package/src/modules/billing/api/accounts/route.ts +198 -0
  175. package/src/modules/billing/api/export/account/[id]/route.ts +233 -0
  176. package/src/modules/billing/api/invoices/[id]/route.ts +143 -0
  177. package/src/modules/billing/api/invoices/add-line/route.ts +74 -0
  178. package/src/modules/billing/api/invoices/edit-line/route.ts +97 -0
  179. package/src/modules/billing/api/invoices/post/route.ts +97 -0
  180. package/src/modules/billing/api/invoices/remove-line/route.ts +75 -0
  181. package/src/modules/billing/api/invoices/route.ts +167 -0
  182. package/src/modules/billing/api/items/bulk/route.ts +92 -0
  183. package/src/modules/billing/api/items/route.ts +255 -0
  184. package/src/modules/billing/api/openapi.ts +33 -0
  185. package/src/modules/billing/api/run-outcomes/route.ts +149 -0
  186. package/src/modules/billing/api/runs/retry-failed/route.ts +88 -0
  187. package/src/modules/billing/api/runs/route.ts +170 -0
  188. package/src/modules/billing/api/test-invoices/wipe/route.ts +87 -0
  189. package/src/modules/billing/api/usage/route.ts +148 -0
  190. package/src/modules/billing/backend/billing/accounts/[id]/page.meta.ts +23 -0
  191. package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +574 -0
  192. package/src/modules/billing/backend/billing/accounts/create/page.meta.ts +23 -0
  193. package/src/modules/billing/backend/billing/accounts/create/page.tsx +101 -0
  194. package/src/modules/billing/backend/billing/accounts/page.meta.ts +16 -0
  195. package/src/modules/billing/backend/billing/accounts/page.tsx +222 -0
  196. package/src/modules/billing/backend/billing/invoices/[id]/page.meta.ts +23 -0
  197. package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +613 -0
  198. package/src/modules/billing/backend/billing/invoices/page.meta.ts +16 -0
  199. package/src/modules/billing/backend/billing/invoices/page.tsx +245 -0
  200. package/src/modules/billing/backend/billing/items/[id]/page.meta.ts +23 -0
  201. package/src/modules/billing/backend/billing/items/[id]/page.tsx +366 -0
  202. package/src/modules/billing/backend/billing/items/create/page.meta.ts +23 -0
  203. package/src/modules/billing/backend/billing/items/create/page.tsx +110 -0
  204. package/src/modules/billing/backend/billing/items/page.meta.ts +16 -0
  205. package/src/modules/billing/backend/billing/items/page.tsx +272 -0
  206. package/src/modules/billing/backend/billing/runs/[id]/page.meta.ts +19 -0
  207. package/src/modules/billing/backend/billing/runs/[id]/page.tsx +404 -0
  208. package/src/modules/billing/backend/billing/runs/page.meta.ts +16 -0
  209. package/src/modules/billing/backend/billing/runs/page.tsx +426 -0
  210. package/src/modules/billing/backend/billing/usage/create/page.meta.ts +23 -0
  211. package/src/modules/billing/backend/billing/usage/create/page.tsx +120 -0
  212. package/src/modules/billing/ce.ts +74 -0
  213. package/src/modules/billing/cli.ts +89 -0
  214. package/src/modules/billing/commands/accounts.ts +205 -0
  215. package/src/modules/billing/commands/index.ts +13 -0
  216. package/src/modules/billing/commands/invoices.ts +542 -0
  217. package/src/modules/billing/commands/items.ts +438 -0
  218. package/src/modules/billing/commands/runs.ts +166 -0
  219. package/src/modules/billing/commands/usage.ts +118 -0
  220. package/src/modules/billing/components/AccountForm.tsx +517 -0
  221. package/src/modules/billing/components/DetailFields.tsx +60 -0
  222. package/src/modules/billing/components/ItemForm.tsx +558 -0
  223. package/src/modules/billing/components/LineFormDialog.tsx +253 -0
  224. package/src/modules/billing/components/UsageForm.tsx +326 -0
  225. package/src/modules/billing/data/entities.ts +533 -0
  226. package/src/modules/billing/data/entityIds.ts +25 -0
  227. package/src/modules/billing/data/validators.ts +562 -0
  228. package/src/modules/billing/di.ts +14 -0
  229. package/src/modules/billing/events.ts +47 -0
  230. package/src/modules/billing/i18n/en.json +336 -0
  231. package/src/modules/billing/i18n/pl.json +336 -0
  232. package/src/modules/billing/index.ts +22 -0
  233. package/src/modules/billing/lib/billPeriod.ts +181 -0
  234. package/src/modules/billing/lib/billRunEngine.ts +416 -0
  235. package/src/modules/billing/lib/billRunLabel.ts +14 -0
  236. package/src/modules/billing/lib/idempotency.ts +46 -0
  237. package/src/modules/billing/lib/invoiceStatus.ts +61 -0
  238. package/src/modules/billing/lib/invoiceWriter.ts +260 -0
  239. package/src/modules/billing/lib/itemSelector.ts +154 -0
  240. package/src/modules/billing/lib/seeds/demo.ts +199 -0
  241. package/src/modules/billing/lib/tenantLock.ts +87 -0
  242. package/src/modules/billing/lib/usageRater.ts +250 -0
  243. package/src/modules/billing/lib/usageRunner.ts +189 -0
  244. package/src/modules/billing/migrations/Migration20260519000000_billing.ts +175 -0
  245. package/src/modules/billing/setup.ts +252 -0
  246. package/src/modules/billing/subscribers/payment-captured-to-paid.ts +89 -0
  247. package/src/modules/billing/translations.ts +9 -0
  248. package/src/modules/billing/workers/reap-stale-bill-runs.ts +57 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/modules/billing/backend/billing/accounts/create/page.meta.ts"],
4
+ "sourcesContent": ["import React from 'react'\nimport { Building2 } from 'lucide-react'\n\nconst accountIcon = React.createElement(Building2, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.account.manage'],\n pageTitle: 'Create Billing Account',\n pageTitleKey: 'billing.accounts.create.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n navHidden: true,\n icon: accountIcon,\n breadcrumb: [\n {\n label: 'Billing Accounts',\n labelKey: 'billing.accounts.title',\n href: '/backend/billing/accounts',\n },\n { label: 'Create', labelKey: 'billing.accounts.create.title' },\n ],\n} as const\n"],
5
+ "mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAE1B,MAAM,cAAc,MAAM,cAAc,WAAW,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,wBAAwB;AAAA,EAC1C,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,IACV;AAAA,MACE,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,IACR;AAAA,IACA,EAAE,OAAO,UAAU,UAAU,gCAAgC;AAAA,EAC/D;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,173 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import Link from "next/link";
5
+ import { useRouter } from "next/navigation";
6
+ import { Plus } from "lucide-react";
7
+ import { useT } from "@open-mercato/shared/lib/i18n/context";
8
+ import { Page, PageBody } from "@open-mercato/ui/backend/Page";
9
+ import { DataTable } from "@open-mercato/ui/backend/DataTable";
10
+ import { Tag } from "@open-mercato/ui/primitives/tag";
11
+ import { Button } from "@open-mercato/ui/primitives/button";
12
+ import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
13
+ function formatDate(value) {
14
+ if (!value) return "\u2014";
15
+ const parsed = new Date(value);
16
+ return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString();
17
+ }
18
+ function BillingAccountsListPage() {
19
+ const t = useT();
20
+ const router = useRouter();
21
+ const [rows, setRows] = React.useState([]);
22
+ const [page, setPage] = React.useState(1);
23
+ const [pageSize] = React.useState(25);
24
+ const [filters, setFilters] = React.useState({});
25
+ const [search, setSearch] = React.useState("");
26
+ const [total, setTotal] = React.useState(0);
27
+ const [totalPages, setTotalPages] = React.useState(1);
28
+ const [loading, setLoading] = React.useState(true);
29
+ const filterDefs = React.useMemo(
30
+ () => [
31
+ {
32
+ id: "billCycle",
33
+ label: t("billing.accounts.filters.cycle", "Bill cycle"),
34
+ type: "select",
35
+ options: [
36
+ { value: "weekly", label: t("billing.cycle.weekly", "Weekly") },
37
+ { value: "monthly", label: t("billing.cycle.monthly", "Monthly") },
38
+ { value: "quarterly", label: t("billing.cycle.quarterly", "Quarterly") },
39
+ { value: "annually", label: t("billing.cycle.annually", "Annually") }
40
+ ]
41
+ },
42
+ {
43
+ id: "currencyCode",
44
+ label: t("billing.accounts.filters.currency", "Currency"),
45
+ type: "text"
46
+ },
47
+ {
48
+ id: "isActive",
49
+ label: t("billing.accounts.filters.active", "Active"),
50
+ type: "select",
51
+ options: [
52
+ { value: "true", label: t("billing.common.active", "Active") },
53
+ { value: "false", label: t("billing.common.inactive", "Inactive") }
54
+ ]
55
+ }
56
+ ],
57
+ [t]
58
+ );
59
+ const loadRows = React.useCallback(async () => {
60
+ setLoading(true);
61
+ try {
62
+ const params = new URLSearchParams({
63
+ page: String(page),
64
+ pageSize: String(pageSize),
65
+ sortField: "createdAt",
66
+ sortDir: "desc"
67
+ });
68
+ if (search.trim()) params.set("search", search.trim());
69
+ if (typeof filters.billCycle === "string" && filters.billCycle) {
70
+ params.set("billCycle", filters.billCycle);
71
+ }
72
+ if (typeof filters.currencyCode === "string" && filters.currencyCode.trim()) {
73
+ params.set("currencyCode", filters.currencyCode.trim().toUpperCase());
74
+ }
75
+ if (filters.isActive === "true") params.set("isActive", "true");
76
+ if (filters.isActive === "false") params.set("isActive", "false");
77
+ const result = await readApiResultOrThrow(
78
+ `/api/billing/accounts?${params.toString()}`
79
+ );
80
+ setRows(result.items ?? []);
81
+ setTotal(result.total ?? 0);
82
+ setTotalPages(result.totalPages ?? 1);
83
+ } finally {
84
+ setLoading(false);
85
+ }
86
+ }, [filters.billCycle, filters.currencyCode, filters.isActive, page, pageSize, search]);
87
+ React.useEffect(() => {
88
+ void loadRows();
89
+ }, [loadRows]);
90
+ const columns = React.useMemo(
91
+ () => [
92
+ {
93
+ accessorKey: "name",
94
+ header: t("billing.accounts.columns.name", "Name"),
95
+ cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: row.original.name })
96
+ },
97
+ {
98
+ accessorKey: "customer_id",
99
+ header: t("billing.accounts.columns.customer", "Customer"),
100
+ cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.original.customer_id })
101
+ },
102
+ {
103
+ accessorKey: "currency_code",
104
+ header: t("billing.accounts.columns.currency", "Currency")
105
+ },
106
+ {
107
+ accessorKey: "bill_cycle",
108
+ header: t("billing.accounts.columns.cycle", "Cycle"),
109
+ cell: ({ row }) => /* @__PURE__ */ jsxs("span", { children: [
110
+ row.original.bill_cycle,
111
+ /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
112
+ " \xB7 ",
113
+ row.original.bill_cycle_anchor
114
+ ] })
115
+ ] })
116
+ },
117
+ {
118
+ accessorKey: "next_bill_date",
119
+ header: t("billing.accounts.columns.next_bill", "Next bill"),
120
+ cell: ({ row }) => formatDate(row.original.next_bill_date)
121
+ },
122
+ {
123
+ accessorKey: "last_bill_date",
124
+ header: t("billing.accounts.columns.last_bill", "Last bill"),
125
+ cell: ({ row }) => formatDate(row.original.last_bill_date)
126
+ },
127
+ {
128
+ accessorKey: "is_active",
129
+ header: t("billing.accounts.columns.status", "Status"),
130
+ cell: ({ row }) => row.original.is_active ? /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.common.active", "Active") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.common.inactive", "Inactive") })
131
+ }
132
+ ],
133
+ [t]
134
+ );
135
+ return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
136
+ DataTable,
137
+ {
138
+ title: t("billing.accounts.title", "Billing Accounts"),
139
+ actions: /* @__PURE__ */ jsx(Button, { asChild: true, children: /* @__PURE__ */ jsxs(Link, { href: "/backend/billing/accounts/create", children: [
140
+ /* @__PURE__ */ jsx(Plus, { size: 16 }),
141
+ t("billing.accounts.create.action", "New account")
142
+ ] }) }),
143
+ refreshButton: {
144
+ label: t("billing.common.refresh", "Refresh"),
145
+ onRefresh: loadRows,
146
+ isRefreshing: loading
147
+ },
148
+ columnChooser: { auto: true },
149
+ perspective: { tableId: "billing-accounts" },
150
+ columns,
151
+ data: rows,
152
+ onRowClick: (row) => router.push(`/backend/billing/accounts/${row.id}`),
153
+ isLoading: loading,
154
+ pagination: {
155
+ page,
156
+ pageSize,
157
+ total,
158
+ totalPages,
159
+ onPageChange: setPage
160
+ },
161
+ filters: filterDefs,
162
+ filterValues: filters,
163
+ onFiltersApply: setFilters,
164
+ onFiltersClear: () => setFilters({}),
165
+ searchValue: search,
166
+ onSearchChange: setSearch
167
+ }
168
+ ) }) });
169
+ }
170
+ export {
171
+ BillingAccountsListPage as default
172
+ };
173
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/modules/billing/backend/billing/accounts/page.tsx"],
4
+ "sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Plus } from 'lucide-react'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\n\n/**\n * Billing Accounts admin list.\n *\n * Search + filter by bill cycle / currency / active state. The\n * \"New account\" CTA opens the create page; rows link into the detail\n * page for inspect + edit + soft-delete.\n */\n\n// API list rows are snake_case \u2014 the billing list endpoints project\n// raw column names (see `api/accounts/route.ts` `fields`).\ntype BillingAccountRow = {\n id: string\n customer_id: string\n name: string\n currency_code: string\n bill_cycle: 'monthly' | 'quarterly' | 'annually' | 'weekly'\n bill_cycle_anchor: string\n invoice_email: string\n next_bill_date: string\n last_bill_date: string | null\n is_active: boolean\n created_at: string\n}\n\ntype ListResponse = {\n items: BillingAccountRow[]\n total: number\n totalPages: number\n}\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const parsed = new Date(value)\n return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString()\n}\n\nexport default function BillingAccountsListPage() {\n const t = useT()\n const router = useRouter()\n const [rows, setRows] = React.useState<BillingAccountRow[]>([])\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(25)\n const [filters, setFilters] = React.useState<FilterValues>({})\n const [search, setSearch] = React.useState('')\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n\n const filterDefs = React.useMemo<FilterDef[]>(\n () => [\n {\n id: 'billCycle',\n label: t('billing.accounts.filters.cycle', 'Bill cycle'),\n type: 'select',\n options: [\n { value: 'weekly', label: t('billing.cycle.weekly', 'Weekly') },\n { value: 'monthly', label: t('billing.cycle.monthly', 'Monthly') },\n { value: 'quarterly', label: t('billing.cycle.quarterly', 'Quarterly') },\n { value: 'annually', label: t('billing.cycle.annually', 'Annually') },\n ],\n },\n {\n id: 'currencyCode',\n label: t('billing.accounts.filters.currency', 'Currency'),\n type: 'text',\n },\n {\n id: 'isActive',\n label: t('billing.accounts.filters.active', 'Active'),\n type: 'select',\n options: [\n { value: 'true', label: t('billing.common.active', 'Active') },\n { value: 'false', label: t('billing.common.inactive', 'Inactive') },\n ],\n },\n ],\n [t],\n )\n\n const loadRows = React.useCallback(async () => {\n setLoading(true)\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n sortField: 'createdAt',\n sortDir: 'desc',\n })\n if (search.trim()) params.set('search', search.trim())\n if (typeof filters.billCycle === 'string' && filters.billCycle) {\n params.set('billCycle', filters.billCycle)\n }\n if (typeof filters.currencyCode === 'string' && filters.currencyCode.trim()) {\n params.set('currencyCode', filters.currencyCode.trim().toUpperCase())\n }\n if (filters.isActive === 'true') params.set('isActive', 'true')\n if (filters.isActive === 'false') params.set('isActive', 'false')\n const result = await readApiResultOrThrow<ListResponse>(\n `/api/billing/accounts?${params.toString()}`,\n )\n setRows(result.items ?? [])\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n } finally {\n setLoading(false)\n }\n }, [filters.billCycle, filters.currencyCode, filters.isActive, page, pageSize, search])\n\n React.useEffect(() => {\n void loadRows()\n }, [loadRows])\n\n const columns = React.useMemo<ColumnDef<BillingAccountRow>[]>(\n () => [\n {\n accessorKey: 'name',\n header: t('billing.accounts.columns.name', 'Name'),\n cell: ({ row }) => (\n <span className=\"text-sm font-medium text-primary\">{row.original.name}</span>\n ),\n },\n {\n accessorKey: 'customer_id',\n header: t('billing.accounts.columns.customer', 'Customer'),\n cell: ({ row }) => (\n <span className=\"font-mono text-xs\">{row.original.customer_id}</span>\n ),\n },\n {\n accessorKey: 'currency_code',\n header: t('billing.accounts.columns.currency', 'Currency'),\n },\n {\n accessorKey: 'bill_cycle',\n header: t('billing.accounts.columns.cycle', 'Cycle'),\n cell: ({ row }) => (\n <span>\n {row.original.bill_cycle}\n <span className=\"text-muted-foreground\"> \u00B7 {row.original.bill_cycle_anchor}</span>\n </span>\n ),\n },\n {\n accessorKey: 'next_bill_date',\n header: t('billing.accounts.columns.next_bill', 'Next bill'),\n cell: ({ row }) => formatDate(row.original.next_bill_date),\n },\n {\n accessorKey: 'last_bill_date',\n header: t('billing.accounts.columns.last_bill', 'Last bill'),\n cell: ({ row }) => formatDate(row.original.last_bill_date),\n },\n {\n accessorKey: 'is_active',\n header: t('billing.accounts.columns.status', 'Status'),\n cell: ({ row }) =>\n row.original.is_active ? (\n <Tag variant=\"success\">{t('billing.common.active', 'Active')}</Tag>\n ) : (\n <Tag variant=\"default\">{t('billing.common.inactive', 'Inactive')}</Tag>\n ),\n },\n ],\n [t],\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable\n title={t('billing.accounts.title', 'Billing Accounts')}\n actions={\n <Button asChild>\n <Link href=\"/backend/billing/accounts/create\">\n <Plus size={16} />\n {t('billing.accounts.create.action', 'New account')}\n </Link>\n </Button>\n }\n refreshButton={{\n label: t('billing.common.refresh', 'Refresh'),\n onRefresh: loadRows,\n isRefreshing: loading,\n }}\n columnChooser={{ auto: true }}\n perspective={{ tableId: 'billing-accounts' }}\n columns={columns}\n data={rows}\n onRowClick={(row) => router.push(`/backend/billing/accounts/${row.id}`)}\n isLoading={loading}\n pagination={{\n page,\n pageSize,\n total,\n totalPages,\n onPageChange: setPage,\n }}\n filters={filterDefs}\n filterValues={filters}\n onFiltersApply={setFilters}\n onFiltersClear={() => setFilters({})}\n searchValue={search}\n onSearchChange={setSearch}\n />\n </PageBody>\n </Page>\n )\n}\n"],
5
+ "mappings": ";AAoIU,cAoBE,YApBF;AAnIV,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AAErB,SAAS,YAAY;AAErB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,4BAA4B;AAgCrC,SAAS,WAAW,OAA0C;AAC5D,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,SAAS,IAAI,KAAK,KAAK;AAC7B,SAAO,OAAO,MAA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J;AAEA,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,0BAA0B,kBAAkB;AAAA,MACrD,SACE,oBAAC,UAAO,SAAO,MACb,+BAAC,QAAK,MAAK,oCACT;AAAA,4BAAC,QAAK,MAAM,IAAI;AAAA,QACf,EAAE,kCAAkC,aAAa;AAAA,SACpD,GACF;AAAA,MAEF,eAAe;AAAA,QACb,OAAO,EAAE,0BAA0B,SAAS;AAAA,QAC5C,WAAW;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,MACA,eAAe,EAAE,MAAM,KAAK;AAAA,MAC5B,aAAa,EAAE,SAAS,mBAAmB;AAAA,MAC3C;AAAA,MACA,MAAM;AAAA,MACN,YAAY,CAAC,QAAQ,OAAO,KAAK,6BAA6B,IAAI,EAAE,EAAE;AAAA,MACtE,WAAW;AAAA,MACX,YAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc;AAAA,MAChB;AAAA,MACA,SAAS;AAAA,MACT,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,gBAAgB,MAAM,WAAW,CAAC,CAAC;AAAA,MACnC,aAAa;AAAA,MACb,gBAAgB;AAAA;AAAA,EAClB,GACF,GACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { Building2 } from "lucide-react";
3
+ const accountsIcon = React.createElement(Building2, { size: 16 });
4
+ const metadata = {
5
+ requireAuth: true,
6
+ requireFeatures: ["billing.account.view"],
7
+ pageTitle: "Billing Accounts",
8
+ pageTitleKey: "billing.accounts.title",
9
+ pageGroup: "Billing",
10
+ pageGroupKey: "billing.nav.group",
11
+ pageOrder: 10,
12
+ icon: accountsIcon,
13
+ breadcrumb: [{ label: "Billing Accounts", labelKey: "billing.accounts.title" }]
14
+ };
15
+ export {
16
+ metadata
17
+ };
18
+ //# sourceMappingURL=page.meta.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/modules/billing/backend/billing/accounts/page.meta.ts"],
4
+ "sourcesContent": ["import React from 'react'\nimport { Building2 } from 'lucide-react'\n\nconst accountsIcon = React.createElement(Building2, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.account.view'],\n pageTitle: 'Billing Accounts',\n pageTitleKey: 'billing.accounts.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n pageOrder: 10,\n icon: accountsIcon,\n breadcrumb: [{ label: 'Billing Accounts', labelKey: 'billing.accounts.title' }],\n} as const\n"],
5
+ "mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAE1B,MAAM,eAAe,MAAM,cAAc,WAAW,EAAE,MAAM,GAAG,CAAC;AAEzD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,sBAAsB;AAAA,EACxC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY,CAAC,EAAE,OAAO,oBAAoB,UAAU,yBAAyB,CAAC;AAChF;",
6
+ "names": []
7
+ }