@nuwah/vertical-sdk 0.0.0-stage → 0.2.0-rc.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 (239) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +229 -2
  3. package/bin/nuwah-contract-check-rules.d.mts +41 -0
  4. package/bin/nuwah-contract-check-rules.mjs +333 -0
  5. package/bin/nuwah-contract-check.mjs +64 -0
  6. package/dist/accounting.d.ts +1417 -0
  7. package/dist/accounting.js +274 -0
  8. package/dist/active-org.d.ts +13 -0
  9. package/dist/active-org.js +59 -0
  10. package/dist/actors.d.ts +448 -0
  11. package/dist/actors.js +143 -0
  12. package/dist/ai.d.ts +359 -0
  13. package/dist/ai.js +229 -0
  14. package/dist/analytics.d.ts +37 -0
  15. package/dist/analytics.js +8 -0
  16. package/dist/atlas.d.ts +291 -0
  17. package/dist/atlas.js +78 -0
  18. package/dist/audit.d.ts +193 -0
  19. package/dist/audit.js +26 -0
  20. package/dist/authentication.d.ts +119 -0
  21. package/dist/authentication.js +83 -0
  22. package/dist/awards.d.ts +38 -0
  23. package/dist/awards.js +10 -0
  24. package/dist/blueprint/document.d.ts +178 -0
  25. package/dist/blueprint/document.js +17 -0
  26. package/dist/blueprint/index.d.ts +3 -0
  27. package/dist/blueprint/index.js +5 -0
  28. package/dist/blueprint/manifest.d.ts +105 -0
  29. package/dist/blueprint/manifest.js +11 -0
  30. package/dist/blueprint/validate.d.ts +14 -0
  31. package/dist/blueprint/validate.js +416 -0
  32. package/dist/bookings-directory.d.ts +118 -0
  33. package/dist/bookings-directory.js +289 -0
  34. package/dist/bookings-extra.d.ts +1448 -0
  35. package/dist/bookings-extra.js +582 -0
  36. package/dist/bookings.d.ts +1365 -0
  37. package/dist/bookings.js +305 -0
  38. package/dist/builder-code.d.ts +164 -0
  39. package/dist/builder-code.js +12 -0
  40. package/dist/builder-core-gaps.d.ts +83 -0
  41. package/dist/builder-core-gaps.js +8 -0
  42. package/dist/builder-repos.d.ts +73 -0
  43. package/dist/builder-repos.js +37 -0
  44. package/dist/builder.d.ts +730 -0
  45. package/dist/builder.js +105 -0
  46. package/dist/campaigns.d.ts +105 -0
  47. package/dist/campaigns.js +25 -0
  48. package/dist/catalogs.d.ts +188 -0
  49. package/dist/catalogs.js +36 -0
  50. package/dist/commerce-ai.d.ts +182 -0
  51. package/dist/commerce-ai.js +27 -0
  52. package/dist/connections.d.ts +278 -0
  53. package/dist/connections.js +96 -0
  54. package/dist/content-control.d.ts +121 -0
  55. package/dist/content-control.js +23 -0
  56. package/dist/contributions.d.ts +560 -0
  57. package/dist/contributions.js +140 -0
  58. package/dist/conversation-assist.d.ts +154 -0
  59. package/dist/conversation-assist.js +51 -0
  60. package/dist/conversation-info.d.ts +219 -0
  61. package/dist/conversation-info.js +43 -0
  62. package/dist/crm.d.ts +533 -0
  63. package/dist/crm.js +142 -0
  64. package/dist/dashboards.d.ts +119 -0
  65. package/dist/dashboards.js +22 -0
  66. package/dist/delegations.d.ts +161 -0
  67. package/dist/delegations.js +39 -0
  68. package/dist/docs.d.ts +289 -0
  69. package/dist/docs.js +49 -0
  70. package/dist/documents.d.ts +317 -0
  71. package/dist/documents.js +84 -0
  72. package/dist/drafts.d.ts +132 -0
  73. package/dist/drafts.js +56 -0
  74. package/dist/engagements.d.ts +133 -0
  75. package/dist/engagements.js +15 -0
  76. package/dist/event-stream.d.ts +54 -0
  77. package/dist/event-stream.js +228 -0
  78. package/dist/exchanges.d.ts +447 -0
  79. package/dist/exchanges.js +145 -0
  80. package/dist/exports.d.ts +113 -0
  81. package/dist/exports.js +81 -0
  82. package/dist/feeds.d.ts +228 -0
  83. package/dist/feeds.js +52 -0
  84. package/dist/files.d.ts +56 -0
  85. package/dist/files.js +55 -0
  86. package/dist/finance-insights.d.ts +41 -0
  87. package/dist/finance-insights.js +61 -0
  88. package/dist/fixed-assets.d.ts +155 -0
  89. package/dist/fixed-assets.js +28 -0
  90. package/dist/fulfilment-jobs.d.ts +405 -0
  91. package/dist/fulfilment-jobs.js +76 -0
  92. package/dist/fulfilment.d.ts +205 -0
  93. package/dist/fulfilment.js +39 -0
  94. package/dist/hr.d.ts +350 -0
  95. package/dist/hr.js +94 -0
  96. package/dist/http.d.ts +124 -0
  97. package/dist/http.js +392 -0
  98. package/dist/inbox.d.ts +206 -0
  99. package/dist/inbox.js +36 -0
  100. package/dist/index.d.ts +384 -0
  101. package/dist/index.js +294 -0
  102. package/dist/insights.d.ts +176 -0
  103. package/dist/insights.js +52 -0
  104. package/dist/inventory.d.ts +797 -0
  105. package/dist/inventory.js +120 -0
  106. package/dist/list-query.d.ts +211 -0
  107. package/dist/list-query.js +158 -0
  108. package/dist/listings.d.ts +381 -0
  109. package/dist/listings.js +173 -0
  110. package/dist/location-sharing.d.ts +83 -0
  111. package/dist/location-sharing.js +20 -0
  112. package/dist/marketplace.d.ts +268 -0
  113. package/dist/marketplace.js +59 -0
  114. package/dist/matching.d.ts +103 -0
  115. package/dist/matching.js +22 -0
  116. package/dist/media.d.ts +221 -0
  117. package/dist/media.js +239 -0
  118. package/dist/metrics.d.ts +125 -0
  119. package/dist/metrics.js +45 -0
  120. package/dist/moderation.d.ts +240 -0
  121. package/dist/moderation.js +40 -0
  122. package/dist/money.d.ts +41 -0
  123. package/dist/money.js +79 -0
  124. package/dist/my-data.d.ts +266 -0
  125. package/dist/my-data.js +32 -0
  126. package/dist/names.d.ts +14 -0
  127. package/dist/names.js +17 -0
  128. package/dist/occasions.d.ts +256 -0
  129. package/dist/occasions.js +40 -0
  130. package/dist/onboarding.d.ts +88 -0
  131. package/dist/onboarding.js +38 -0
  132. package/dist/pagination.d.ts +204 -0
  133. package/dist/pagination.js +141 -0
  134. package/dist/party-baseline-attributes.d.ts +245 -0
  135. package/dist/party-baseline-attributes.js +36 -0
  136. package/dist/party.d.ts +401 -0
  137. package/dist/party.js +56 -0
  138. package/dist/patient.d.ts +161 -0
  139. package/dist/patient.js +45 -0
  140. package/dist/payroll.d.ts +378 -0
  141. package/dist/payroll.js +60 -0
  142. package/dist/person-addresses.d.ts +88 -0
  143. package/dist/person-addresses.js +18 -0
  144. package/dist/person-cart.d.ts +250 -0
  145. package/dist/person-cart.js +63 -0
  146. package/dist/person-chat-assist.d.ts +47 -0
  147. package/dist/person-chat-assist.js +13 -0
  148. package/dist/person-data-webhooks.d.ts +72 -0
  149. package/dist/person-data-webhooks.js +86 -0
  150. package/dist/person-data.d.ts +212 -0
  151. package/dist/person-data.js +162 -0
  152. package/dist/person-locations.d.ts +54 -0
  153. package/dist/person-locations.js +6 -0
  154. package/dist/person-messaging.d.ts +405 -0
  155. package/dist/person-messaging.js +112 -0
  156. package/dist/person-notifications.d.ts +319 -0
  157. package/dist/person-notifications.js +164 -0
  158. package/dist/personalisation.d.ts +21 -0
  159. package/dist/personalisation.js +8 -0
  160. package/dist/platform.d.ts +63 -0
  161. package/dist/platform.js +45 -0
  162. package/dist/portfolio.d.ts +163 -0
  163. package/dist/portfolio.js +28 -0
  164. package/dist/pos.d.ts +743 -0
  165. package/dist/pos.js +129 -0
  166. package/dist/procurement.d.ts +664 -0
  167. package/dist/procurement.js +157 -0
  168. package/dist/promotions.d.ts +169 -0
  169. package/dist/promotions.js +39 -0
  170. package/dist/publications.d.ts +583 -0
  171. package/dist/publications.js +164 -0
  172. package/dist/ranking.d.ts +43 -0
  173. package/dist/ranking.js +34 -0
  174. package/dist/ratings.d.ts +293 -0
  175. package/dist/ratings.js +109 -0
  176. package/dist/reactions.d.ts +123 -0
  177. package/dist/reactions.js +41 -0
  178. package/dist/recipient-orders.d.ts +294 -0
  179. package/dist/recipient-orders.js +73 -0
  180. package/dist/relationships.d.ts +18 -0
  181. package/dist/relationships.js +8 -0
  182. package/dist/reporting.d.ts +107 -0
  183. package/dist/reporting.js +56 -0
  184. package/dist/sales.d.ts +270 -0
  185. package/dist/sales.js +66 -0
  186. package/dist/shares.d.ts +105 -0
  187. package/dist/shares.js +27 -0
  188. package/dist/shop.d.ts +993 -0
  189. package/dist/shop.js +215 -0
  190. package/dist/shopping-assistant.d.ts +65 -0
  191. package/dist/shopping-assistant.js +14 -0
  192. package/dist/spaces.d.ts +422 -0
  193. package/dist/spaces.js +118 -0
  194. package/dist/stored-value.d.ts +754 -0
  195. package/dist/stored-value.js +177 -0
  196. package/dist/types.d.ts +83 -0
  197. package/dist/types.js +2 -0
  198. package/dist/vault.d.ts +290 -0
  199. package/dist/vault.js +55 -0
  200. package/dist/vertical-runtime.d.ts +17 -0
  201. package/dist/vertical-runtime.js +8 -0
  202. package/dist/vite/build-manifest-plugin.d.ts +42 -0
  203. package/dist/vite/build-manifest-plugin.js +42 -0
  204. package/dist/vite/first-paint-plugin.d.ts +26 -0
  205. package/dist/vite/first-paint-plugin.js +57 -0
  206. package/dist/wishlists.d.ts +591 -0
  207. package/dist/wishlists.js +188 -0
  208. package/dist/workbench.d.ts +114 -0
  209. package/dist/workbench.js +22 -0
  210. package/dist/workspace.d.ts +190 -0
  211. package/dist/workspace.js +41 -0
  212. package/package.json +52 -4
  213. package/templates/extension-image.Dockerfile +38 -0
  214. package/templates/nuwah-vertical.yml +102 -0
  215. package/templates/vertical-app/.env.example +34 -0
  216. package/templates/vertical-app/README.md +108 -0
  217. package/templates/vertical-app/github/workflows/ci.yml +51 -0
  218. package/templates/vertical-app/gitignore +5 -0
  219. package/templates/vertical-app/index.html +12 -0
  220. package/templates/vertical-app/package.json +28 -0
  221. package/templates/vertical-app/src/App.tsx +64 -0
  222. package/templates/vertical-app/src/blueprint/blueprint.ts +45 -0
  223. package/templates/vertical-app/src/blueprint/screens.ts +15 -0
  224. package/templates/vertical-app/src/env.d.ts +18 -0
  225. package/templates/vertical-app/src/index.css +139 -0
  226. package/templates/vertical-app/src/lib/i18n.ts +5 -0
  227. package/templates/vertical-app/src/lib/iam.ts +19 -0
  228. package/templates/vertical-app/src/lib/operations.ts +93 -0
  229. package/templates/vertical-app/src/lib/router.ts +24 -0
  230. package/templates/vertical-app/src/lib/sdk.ts +21 -0
  231. package/templates/vertical-app/src/lib/theme.ts +18 -0
  232. package/templates/vertical-app/src/lib/words.ts +39 -0
  233. package/templates/vertical-app/src/main.tsx +25 -0
  234. package/templates/vertical-app/src/pages/AppScreens.tsx +71 -0
  235. package/templates/vertical-app/src/pages/AuthCallback.tsx +44 -0
  236. package/templates/vertical-app/src/pages/Home.tsx +36 -0
  237. package/templates/vertical-app/tsconfig.json +24 -0
  238. package/templates/vertical-app/vite.config.ts +23 -0
  239. package/templates/vertical-ci.yml +192 -0
@@ -0,0 +1,1417 @@
1
+ import type { QueryValue } from './http.js';
2
+ import type { NuwahClientConfig, Http } from './http.js';
3
+ import type { ListQuery, Paginated, Translatable } from './types.js';
4
+ /**
5
+ * `voided` is what core writes (VoidInvoiceAction); `void` is kept only so an older comparison still
6
+ * compiles — no invoice carries it.
7
+ */
8
+ export type InvoiceStatus = 'draft' | 'confirmed' | 'partially_paid' | 'paid' | 'voided' | 'void';
9
+ /** Nested counterparty summary embedded on an invoice. */
10
+ export interface InvoiceCounterpartyRef {
11
+ id: string;
12
+ code: string | null;
13
+ /** Translatable map `{en, ar}` (raw `getTranslations`). */
14
+ name: Translatable;
15
+ }
16
+ export interface InvoiceCurrencyRef {
17
+ id: string;
18
+ code: string;
19
+ }
20
+ /** Row shape from `GET /invoices` (list projection). */
21
+ export interface InvoiceListItem {
22
+ id: string;
23
+ invoice_number: string;
24
+ invoice_date: string | null;
25
+ due_date: string | null;
26
+ status: InvoiceStatus;
27
+ subtotal: string;
28
+ tax_amount: string;
29
+ total: string;
30
+ amount_paid: string;
31
+ amount_due: string;
32
+ reference: string | null;
33
+ /** When the invoice was sent to its customer (`invoices.send`); null when never sent. */
34
+ sent_at?: string | null;
35
+ counterparty: InvoiceCounterpartyRef | null;
36
+ currency: InvoiceCurrencyRef | null;
37
+ }
38
+ export interface InvoiceLine {
39
+ id: string;
40
+ sort_order: number;
41
+ description: string | null;
42
+ quantity: string;
43
+ unit_price: string;
44
+ discount_percent: string;
45
+ tax_rate_percent: string;
46
+ line_subtotal: string;
47
+ line_tax: string;
48
+ line_total: string;
49
+ account: {
50
+ id: string;
51
+ code: string;
52
+ name: Translatable;
53
+ } | null;
54
+ }
55
+ export interface InvoicePaymentRef {
56
+ id: string;
57
+ payment_number: string;
58
+ payment_date: string | null;
59
+ payment_method: string | null;
60
+ allocated_amount: string;
61
+ }
62
+ /** Full shape from `GET /invoices/{uuid}`. */
63
+ export interface InvoiceDetail extends InvoiceListItem {
64
+ notes: Record<string, unknown> | null;
65
+ voided_at: string | null;
66
+ void_reason: string | null;
67
+ journal_entry: {
68
+ id: string;
69
+ entry_number: string;
70
+ } | null;
71
+ lines: InvoiceLine[];
72
+ payments: InvoicePaymentRef[];
73
+ }
74
+ export interface CreateInvoiceInput {
75
+ counterparty_id?: string | null;
76
+ currency_id?: string | null;
77
+ invoice_date: string;
78
+ due_date?: string | null;
79
+ reference?: string | null;
80
+ notes?: Record<string, unknown> | null;
81
+ }
82
+ /** `POST /invoices/{uuid}/lines` answers only the new line's id (bare, 201) — refetch the invoice for totals. */
83
+ export interface AddInvoiceLineResult {
84
+ id: string;
85
+ }
86
+ /**
87
+ * `POST /invoices/{uuid}/confirm` answers the full invoice detail (bare), as `GET` does: the
88
+ * new number, totals, journal entry and status. It used to answer only
89
+ * `{id, invoice_number, status, total}`, all still present.
90
+ */
91
+ export type ConfirmInvoiceResult = InvoiceDetail;
92
+ /** `POST /invoices/{uuid}/void` answers the full invoice detail (bare). It used to answer `{id, status}`. */
93
+ export type InvoiceStatusResult = InvoiceDetail;
94
+ /** `POST /payments-received` answers only the new payment's id + number (bare, 201). */
95
+ export interface RecordPaymentReceivedResult {
96
+ id: string;
97
+ payment_number: string;
98
+ }
99
+ /** Body for `POST /credit-notes`. `credit_note_date` is required by core. */
100
+ export interface CreateCreditNoteInput {
101
+ invoice_id?: string | null;
102
+ counterparty_id?: string | null;
103
+ currency_id?: string | null;
104
+ /** `YYYY-MM-DD` — required; omitting it is a 422. */
105
+ credit_note_date: string;
106
+ amount: number | string;
107
+ reason?: string | null;
108
+ }
109
+ /** `POST /invoices` returns just the new draft's id + status. */
110
+ export interface CreateInvoiceResult {
111
+ id: string;
112
+ status: InvoiceStatus;
113
+ }
114
+ export interface AddInvoiceLineInput {
115
+ /** Required by core (`required|string|max:500`) — a line with no description is a 422. */
116
+ description: string;
117
+ quantity: number | string;
118
+ unit_price: number | string;
119
+ account_id?: string | null;
120
+ discount_percent?: number | string;
121
+ tax_rate_percent?: number | string;
122
+ sort_order?: number;
123
+ }
124
+ export interface InvoiceListQuery extends ListQuery {
125
+ status?: InvoiceStatus | InvoiceStatus[];
126
+ date_from?: string;
127
+ date_to?: string;
128
+ /** Matches the invoice number, the reference, or the customer's English or Arabic name. */
129
+ search?: string;
130
+ }
131
+ export type CounterpartyType = 'customer' | 'vendor' | 'both';
132
+ export interface Counterparty {
133
+ id: string;
134
+ code: string | null;
135
+ name: Translatable;
136
+ type?: CounterpartyType;
137
+ tax_number?: string | null;
138
+ status?: string;
139
+ /** The cross-plane person id linking a roster row (athlete / patient / member) to its ledger customer. */
140
+ platform_person_id?: string | null;
141
+ [field: string]: unknown;
142
+ }
143
+ export interface CounterpartyListQuery extends ListQuery {
144
+ type?: CounterpartyType;
145
+ status?: string;
146
+ search?: string;
147
+ /** Only the counterparty that mirrors this platform person (exact uuid). */
148
+ platform_person_id?: string;
149
+ }
150
+ export interface PaymentReceived {
151
+ id: string;
152
+ payment_number: string;
153
+ payment_date: string | null;
154
+ payment_method: string | null;
155
+ amount?: string;
156
+ reference?: string | null;
157
+ counterparty?: {
158
+ id: string;
159
+ code: string | null;
160
+ name: Translatable;
161
+ } | null;
162
+ currency?: {
163
+ id: string;
164
+ code: string;
165
+ } | null;
166
+ }
167
+ export type AccountType = 'asset' | 'liability' | 'equity' | 'income' | 'expense';
168
+ export type NormalBalance = 'debit' | 'credit';
169
+ export interface Account {
170
+ id: string;
171
+ code: string;
172
+ name: Translatable;
173
+ description: Translatable | null;
174
+ type: AccountType | string;
175
+ normal_balance: NormalBalance;
176
+ parent_id: string | null;
177
+ allow_posting: boolean;
178
+ is_active: boolean;
179
+ is_system: boolean;
180
+ /** Set on the flat `list` (withCount); null on `tree`/create/show. */
181
+ children_count: number | null;
182
+ /** Nested on the `tree` endpoint only. */
183
+ children: Account[] | null;
184
+ /** Merged in only when `with_balances` is set. */
185
+ current_balance?: string;
186
+ natural_balance?: string;
187
+ balance_side?: 'debit' | 'credit' | 'zero';
188
+ }
189
+ export interface CreateAccountInput {
190
+ code: string;
191
+ name: Translatable;
192
+ description?: Record<string, unknown> | null;
193
+ type: AccountType | string;
194
+ parent_id?: string | null;
195
+ allow_posting?: boolean;
196
+ }
197
+ export type UpdateAccountInput = Partial<CreateAccountInput> & {
198
+ is_active?: boolean;
199
+ };
200
+ export interface AccountActivity {
201
+ account_id: string;
202
+ code: string;
203
+ name: Translatable;
204
+ normal_balance: NormalBalance;
205
+ current_balance: string;
206
+ natural_balance: string;
207
+ balance_side: 'debit' | 'credit' | 'zero';
208
+ recent_lines: Array<{
209
+ entry_id: string;
210
+ entry_number: string;
211
+ entry_date: string;
212
+ description: string | null;
213
+ debit: string;
214
+ credit: string;
215
+ running_balance: string;
216
+ }>;
217
+ }
218
+ export interface JournalLine {
219
+ id: string;
220
+ account_id: string | null;
221
+ account_code: string | null;
222
+ account_name: Translatable | null;
223
+ debit_amount: string;
224
+ credit_amount: string;
225
+ description: string | null;
226
+ counterparty_id: string | null;
227
+ counterparty: {
228
+ id: string;
229
+ code: string;
230
+ name: Translatable;
231
+ } | null;
232
+ }
233
+ export interface JournalEntry {
234
+ id: string;
235
+ entry_number: string;
236
+ entry_date: string | null;
237
+ description: Translatable | null;
238
+ reference: string | null;
239
+ status: string;
240
+ total_debits: string;
241
+ total_credits: string;
242
+ line_count: number | null;
243
+ posted_at: string | null;
244
+ voided_at: string | null;
245
+ void_reason: string | null;
246
+ reversing_entry_id: string | null;
247
+ currency: {
248
+ id: string;
249
+ code: string;
250
+ name: Translatable;
251
+ symbol: string;
252
+ decimal_places: number;
253
+ } | null;
254
+ transaction_type: {
255
+ id: string;
256
+ event_key: string;
257
+ name: Translatable;
258
+ } | null;
259
+ /** Present on show/void (relation loaded); null on list. */
260
+ lines: JournalLine[] | null;
261
+ }
262
+ export interface JournalEntryListQuery extends ListQuery {
263
+ status?: string | string[];
264
+ date_from?: string;
265
+ date_to?: string;
266
+ account_id?: string;
267
+ search?: string;
268
+ }
269
+ /** Body for `POST /events/fire` — the only journal-posting path. */
270
+ export interface FireEventInput {
271
+ event_key: string;
272
+ entry_date: string;
273
+ currency_code?: string | null;
274
+ description?: unknown;
275
+ reference?: string | null;
276
+ amounts: Record<string, number>;
277
+ parties?: Record<string, string> | null;
278
+ }
279
+ export interface TrialBalance {
280
+ as_of: string | null;
281
+ rows: Array<{
282
+ account_id: string;
283
+ code: string;
284
+ name: Translatable;
285
+ type: string | null;
286
+ normal_balance: string | null;
287
+ debit: string;
288
+ credit: string;
289
+ }>;
290
+ total_debit: string;
291
+ total_credit: string;
292
+ is_balanced: boolean;
293
+ }
294
+ export interface StatementLine {
295
+ account_id: string;
296
+ code: string;
297
+ name: Translatable;
298
+ role: string | null;
299
+ amount: string;
300
+ }
301
+ export interface BalanceSheet {
302
+ as_of: string;
303
+ assets: {
304
+ lines: StatementLine[];
305
+ total: string;
306
+ };
307
+ liabilities: {
308
+ lines: StatementLine[];
309
+ total: string;
310
+ };
311
+ equity: {
312
+ lines: StatementLine[];
313
+ accounts_subtotal: string;
314
+ current_year_earnings: string;
315
+ total: string;
316
+ };
317
+ total_liabilities_and_equity: string;
318
+ is_balanced: boolean;
319
+ }
320
+ export interface IncomeStatement {
321
+ from: string;
322
+ to: string;
323
+ revenue: {
324
+ lines: StatementLine[];
325
+ total: string;
326
+ };
327
+ expenses: {
328
+ lines: StatementLine[];
329
+ total: string;
330
+ };
331
+ net_income: string;
332
+ }
333
+ export interface GeneralLedgerReport {
334
+ account_id: string;
335
+ code: string;
336
+ name: Translatable;
337
+ from: string;
338
+ to: string;
339
+ opening_balance: string;
340
+ closing_balance: string;
341
+ lines: Array<{
342
+ entry_id: string;
343
+ entry_number: string;
344
+ entry_date: string;
345
+ description: string | null;
346
+ debit: string;
347
+ credit: string;
348
+ running_balance: string;
349
+ }>;
350
+ }
351
+ export interface CashFlowReport {
352
+ from: string;
353
+ to: string;
354
+ untagged_count: number;
355
+ groups: Array<{
356
+ tag: string | null;
357
+ total: string;
358
+ lines: Array<{
359
+ account_id: string;
360
+ code: string;
361
+ name: Translatable;
362
+ movement: string;
363
+ }>;
364
+ }>;
365
+ }
366
+ export interface AccountBalancesReport {
367
+ as_of: string;
368
+ accounts: Array<{
369
+ uuid: string;
370
+ code: string;
371
+ name: Translatable;
372
+ type: string;
373
+ normal_side: string;
374
+ debit_total: string;
375
+ credit_total: string;
376
+ balance: string;
377
+ }>;
378
+ }
379
+ export interface ReportDateRangeQuery {
380
+ from?: string;
381
+ to?: string;
382
+ [param: string]: string | number | boolean | null | undefined | Array<string | number>;
383
+ }
384
+ /** The five aging buckets, each `{ count, total }` (total is a bcmath string). */
385
+ export type AgingBucketKey = 'current' | '1_to_30' | '31_to_60' | '61_to_90' | 'over_90';
386
+ export type AgingBuckets = Record<AgingBucketKey, {
387
+ count: number;
388
+ total: string;
389
+ }>;
390
+ export interface ArAgingRow {
391
+ id: string;
392
+ invoice_number: string;
393
+ invoice_date: string | null;
394
+ due_date: string | null;
395
+ total: string;
396
+ amount_paid: string;
397
+ amount_due: string;
398
+ days_overdue: number;
399
+ bucket: AgingBucketKey;
400
+ counterparty: {
401
+ id: string;
402
+ code: string | null;
403
+ name: Translatable;
404
+ } | null;
405
+ currency: {
406
+ id: string;
407
+ code: string;
408
+ } | null;
409
+ }
410
+ /** `GET /ar-aging` — buckets + one row per open receivable invoice. */
411
+ export interface ArAgingReport {
412
+ buckets: AgingBuckets;
413
+ rows: ArAgingRow[];
414
+ }
415
+ export interface ApAgingRow {
416
+ id: string;
417
+ bill_number: string | null;
418
+ bill_date: string | null;
419
+ due_date: string | null;
420
+ total: string;
421
+ amount_paid: string;
422
+ amount_due: string;
423
+ days_overdue: number;
424
+ bucket: AgingBucketKey;
425
+ counterparty: {
426
+ id: string;
427
+ code: string | null;
428
+ name: Translatable;
429
+ } | null;
430
+ currency: {
431
+ id: string;
432
+ code: string;
433
+ } | null;
434
+ }
435
+ /** `GET /ap-aging` — buckets + one row per open payable bill. */
436
+ export interface ApAgingReport {
437
+ buckets: AgingBuckets;
438
+ rows: ApAgingRow[];
439
+ }
440
+ export interface CounterpartyLedgerLine {
441
+ date: string;
442
+ document_type: 'invoice' | 'payment' | 'credit_note' | 'bill' | string;
443
+ reference: string;
444
+ /** Bilingual document-type label map. */
445
+ description: Translatable;
446
+ debit: string;
447
+ credit: string;
448
+ running_balance: string;
449
+ }
450
+ /**
451
+ * `GET /reports/counterparty-ledger` — the running statement for one counterparty.
452
+ * With no `counterparty_uuid`, `counterparty` is null and `lines` is empty.
453
+ */
454
+ export interface CounterpartyLedgerReport {
455
+ counterparty: {
456
+ uuid: string;
457
+ name: Translatable;
458
+ type: string;
459
+ } | null;
460
+ period: {
461
+ from: string | null;
462
+ to: string | null;
463
+ };
464
+ opening_balance: string;
465
+ lines: CounterpartyLedgerLine[];
466
+ closing_balance: string;
467
+ total_debit: string;
468
+ total_credit: string;
469
+ }
470
+ export interface CounterpartyLedgerQuery {
471
+ counterparty_uuid?: string;
472
+ from_date?: string;
473
+ to_date?: string;
474
+ [key: string]: QueryValue;
475
+ }
476
+ export type ClaimStatus = 'draft' | 'submitted' | 'adjudicated' | 'paid' | 'rejected' | 'voided';
477
+ export interface ClaimLine {
478
+ id: string;
479
+ tenant_id?: string;
480
+ claim_id: string;
481
+ procedure_code: string | null;
482
+ diagnosis_code: string | null;
483
+ description: string;
484
+ quantity: string;
485
+ unit_price: string;
486
+ billed_amount: string;
487
+ allowed_amount: string | null;
488
+ paid_amount: string | null;
489
+ denial_reason: string | null;
490
+ sequence: number;
491
+ created_at: string;
492
+ updated_at: string;
493
+ }
494
+ /** Raw `Claim` model (no API Resource — passthrough of DB columns). */
495
+ export interface Claim {
496
+ id: string;
497
+ tenant_id?: string;
498
+ insurance_policy_id: string | null;
499
+ session_id: string | null;
500
+ claim_number: string | null;
501
+ status: ClaimStatus;
502
+ submitted_at: string | null;
503
+ adjudicated_at: string | null;
504
+ paid_at: string | null;
505
+ voided_at: string | null;
506
+ billed_amount: string;
507
+ allowed_amount: string | null;
508
+ paid_amount: string | null;
509
+ denial_reason: string | null;
510
+ eob_reference: string | null;
511
+ notes: string | null;
512
+ created_at: string;
513
+ updated_at: string;
514
+ /** Present when loaded (show/create/adjudicate). */
515
+ lines?: ClaimLine[];
516
+ }
517
+ export interface CreateClaimLineInput {
518
+ description: string;
519
+ unit_price: number | string;
520
+ billed_amount: number | string;
521
+ quantity?: number | string;
522
+ procedure_code?: string | null;
523
+ diagnosis_code?: string | null;
524
+ sequence?: number;
525
+ }
526
+ export interface CreateClaimInput {
527
+ billed_amount: number | string;
528
+ insurance_policy_id?: string | null;
529
+ /** The insurer billed directly when there is no policy on file. */
530
+ insurer_counterparty_id?: string | null;
531
+ session_id?: string | null;
532
+ notes?: string | null;
533
+ lines: CreateClaimLineInput[];
534
+ }
535
+ export interface AdjudicateClaimInput {
536
+ allowed_amount: number | string;
537
+ line_adjudications: Array<{
538
+ claim_line_id: string;
539
+ allowed_amount: number | string;
540
+ paid_amount: number | string;
541
+ denial_reason?: string | null;
542
+ }>;
543
+ }
544
+ export interface PayClaimInput {
545
+ paid_amount: number | string;
546
+ eob_reference?: string;
547
+ }
548
+ export interface ClaimListQuery extends ListQuery {
549
+ status?: ClaimStatus;
550
+ insurance_policy_id?: string;
551
+ session_id?: string;
552
+ submitted_at_from?: string;
553
+ submitted_at_to?: string;
554
+ }
555
+ export interface EobBatchLine {
556
+ claim_number: string;
557
+ paid_amount?: number | string;
558
+ denial_reason?: string;
559
+ eob_reference?: string;
560
+ }
561
+ /** `eob-batch` returns `{ results: { [claimNumber]: 'not_found'|'rejected'|'paid'|'error' } }`. */
562
+ export interface EobBatchResult {
563
+ results: Record<string, string>;
564
+ }
565
+ export type BillStatus = 'draft' | 'confirmed' | 'partially_paid' | 'paid' | 'voided';
566
+ export interface BillListItem {
567
+ id: string;
568
+ bill_number: string | null;
569
+ our_reference: string | null;
570
+ bill_date: string | null;
571
+ due_date: string | null;
572
+ status: BillStatus;
573
+ subtotal: string;
574
+ tax_amount: string;
575
+ total: string;
576
+ amount_paid: string;
577
+ amount_due: string;
578
+ counterparty: {
579
+ id: string;
580
+ code: string;
581
+ name: Translatable;
582
+ } | null;
583
+ currency: {
584
+ id: string;
585
+ code: string;
586
+ } | null;
587
+ }
588
+ export interface BillLine {
589
+ id: string;
590
+ sort_order: number;
591
+ description: string;
592
+ quantity: string;
593
+ unit_price: string;
594
+ discount_percent: string;
595
+ tax_rate_percent: string;
596
+ line_subtotal: string;
597
+ line_tax: string;
598
+ line_total: string;
599
+ account: {
600
+ id: string;
601
+ code: string;
602
+ name: Translatable;
603
+ } | null;
604
+ }
605
+ export interface BillDetail extends BillListItem {
606
+ notes: Record<string, unknown> | null;
607
+ voided_at: string | null;
608
+ void_reason: string | null;
609
+ journal_entry: {
610
+ id: string;
611
+ entry_number: string;
612
+ } | null;
613
+ lines: BillLine[];
614
+ payments: Array<{
615
+ id: string;
616
+ payment_number: string;
617
+ payment_date: string | null;
618
+ payment_method: string;
619
+ allocated_amount: string;
620
+ }>;
621
+ }
622
+ export interface CreateBillInput {
623
+ counterparty_id?: string | null;
624
+ currency_id?: string | null;
625
+ bill_number?: string | null;
626
+ our_reference?: string | null;
627
+ bill_date: string;
628
+ due_date?: string | null;
629
+ notes?: Record<string, unknown> | null;
630
+ }
631
+ /** `create`/`confirm`/`void` return only `{ id, status }`. */
632
+ export interface BillMutationResult {
633
+ id: string;
634
+ status: BillStatus;
635
+ }
636
+ export type PaymentMethod = 'cash' | 'bank_transfer' | 'cheque' | 'card' | 'other';
637
+ /** Body for `POST /bills/{uuid}/pay` — record a payment MADE against a bill. */
638
+ export interface RecordBillPaymentInput {
639
+ /** Clamped client-side to `amount_due`; the API rejects any overpay. */
640
+ amount: number | string;
641
+ payment_date: string;
642
+ payment_method: PaymentMethod;
643
+ currency_id?: string | null;
644
+ reference?: string | null;
645
+ notes?: string | null;
646
+ }
647
+ /** `POST /bills/{uuid}/pay` returns the new payment + the bill's refreshed money state. */
648
+ export interface RecordBillPaymentResult {
649
+ payment: {
650
+ id: string;
651
+ payment_number: string;
652
+ payment_date: string | null;
653
+ payment_method: string;
654
+ amount: string;
655
+ };
656
+ bill: {
657
+ id: string;
658
+ status: BillStatus;
659
+ amount_paid: string;
660
+ amount_due: string;
661
+ };
662
+ }
663
+ export interface SetBillLinesInput {
664
+ /** Bulk delete-and-replace — the full desired line set. */
665
+ lines: Array<{
666
+ description: string;
667
+ quantity: number | string;
668
+ unit_price: number | string;
669
+ discount_percent?: number | string;
670
+ tax_rate_percent?: number | string;
671
+ account_id?: string | null;
672
+ }>;
673
+ }
674
+ export interface BillListQuery extends ListQuery {
675
+ status?: BillStatus | BillStatus[];
676
+ date_from?: string;
677
+ date_to?: string;
678
+ counterparty_id?: string;
679
+ search?: string;
680
+ }
681
+ export interface BankAccount {
682
+ id: string;
683
+ name: Translatable;
684
+ bank_name: Translatable;
685
+ account_number: string | null;
686
+ iban: string | null;
687
+ is_default: boolean;
688
+ is_active: boolean;
689
+ opening_balance: string;
690
+ opening_balance_date: string | null;
691
+ currency: {
692
+ id: string;
693
+ code: string;
694
+ } | null;
695
+ gl_account: {
696
+ id: string;
697
+ code: string;
698
+ name: Translatable;
699
+ } | null;
700
+ }
701
+ export interface CreateBankAccountInput {
702
+ name: Translatable;
703
+ bank_name?: Translatable | null;
704
+ account_number?: string | null;
705
+ iban?: string | null;
706
+ currency_id?: string | null;
707
+ gl_account_id?: string | null;
708
+ is_default?: boolean;
709
+ is_active?: boolean;
710
+ opening_balance?: number | null;
711
+ opening_balance_date?: string | null;
712
+ }
713
+ export type UpdateBankAccountInput = Partial<CreateBankAccountInput>;
714
+ export interface BankReconciliation {
715
+ id: string;
716
+ statement_date: string | null;
717
+ opening_balance: string;
718
+ closing_balance: string;
719
+ cleared_deposits: string;
720
+ cleared_withdrawals: string;
721
+ difference: string;
722
+ status: string;
723
+ notes: string | null;
724
+ completed_at: string | null;
725
+ bank_account: {
726
+ id: string;
727
+ name: Translatable;
728
+ } | null;
729
+ }
730
+ export interface CreateBankReconciliationInput {
731
+ bank_account_id: string;
732
+ statement_date: string;
733
+ opening_balance: number | string;
734
+ closing_balance: number | string;
735
+ cleared_deposits?: number | string | null;
736
+ cleared_withdrawals?: number | string | null;
737
+ notes?: string | null;
738
+ }
739
+ /** The closed set of documents the render studio supports. */
740
+ export type DocumentType = 'invoice' | 'bill' | 'credit_note' | 'receipt' | 'statement' | 'quote';
741
+ /** Text/reading direction of a rendered document. */
742
+ export type DocumentDirection = 'ltr' | 'rtl';
743
+ /** The six-section document spine, top-to-bottom, plus the flexible slot types (custom HTML, legal, QR). */
744
+ export type DocumentSectionType = 'header' | 'parties' | 'lines' | 'summary' | 'notes' | 'footer' | 'custom' | 'legal' | 'qr';
745
+ /** Inner-padding token for a section band. */
746
+ export type DocumentPadding = 'sm' | 'md' | 'lg';
747
+ /** Bilingual `{en, ar}` label/name (WRITE + READ; the studio always sends both). */
748
+ export interface DocumentLocalizedName {
749
+ en: string;
750
+ ar: string;
751
+ }
752
+ /**
753
+ * How the render engine resolves a template's LABELS. Mirrors the UI-lib
754
+ * `LanguageMode` (`@nuwah/ui/solid/documents`): `'en'`/`'ar'`/`'bilingual'`/
755
+ * `'locale'`. Absent ⇒ `'en'`.
756
+ */
757
+ export type DocumentLanguageMode = 'en' | 'ar' | 'bilingual' | 'locale';
758
+ /** An authored, localizable label string (English + Arabic). Mirrors UI-lib `LabelPair`. */
759
+ export interface DocumentLabelPair {
760
+ en: string;
761
+ ar: string;
762
+ }
763
+ export interface DocumentSectionStyle {
764
+ /** Background colour for the section band. */
765
+ bg?: string;
766
+ /** Text colour override. */
767
+ text?: string;
768
+ /** Accent colour override (rules, table header, emphasis). */
769
+ accent?: string;
770
+ /** Inner padding size. Default 'md'. */
771
+ padding?: DocumentPadding;
772
+ }
773
+ export interface DocumentSection {
774
+ type: DocumentSectionType;
775
+ enabled: boolean;
776
+ style: DocumentSectionStyle;
777
+ /** Free-form per-section knobs (titles, column visibility, …). */
778
+ config?: Record<string, unknown>;
779
+ }
780
+ export interface DocumentThemeTokens {
781
+ /** Primary brand colour — table header, accents, totals emphasis. */
782
+ primary: string;
783
+ /** Body text colour. */
784
+ text: string;
785
+ /** Secondary accent colour — rules, muted labels. */
786
+ accent: string;
787
+ /** Optional CSS font-family stack. */
788
+ font?: string;
789
+ }
790
+ export interface DocumentPageSpec {
791
+ size: 'A4';
792
+ /** Uniform page margin in millimetres. Default 12. */
793
+ margin_mm?: number;
794
+ }
795
+ export interface DocumentBackgroundSpec {
796
+ url?: string;
797
+ /** 0..1 watermark opacity. Default 1. */
798
+ opacity?: number;
799
+ }
800
+ /**
801
+ * A saved document template — the studio schema + the frozen `html_body`. Shape
802
+ * matches `@nuwah/ui`'s `DocumentTemplate` (plus core-only `id`, `settings`,
803
+ * timestamps). Single-resource responses are the BARE object (JsonResource
804
+ * `->resolve()`, no `{data}` wrapper); only the `list` is paginated.
805
+ */
806
+ export interface DocumentTemplate {
807
+ id: string;
808
+ document_type: DocumentType;
809
+ name: DocumentLocalizedName;
810
+ /** Label-resolution mode across languages. Absent ⇒ `'en'`. */
811
+ language_mode?: DocumentLanguageMode;
812
+ /**
813
+ * Author-overridable localizable label strings, keyed by label id
814
+ * (`'bill_to'`, `'subtotal'`, …). Missing keys fall back to the render
815
+ * engine's `DEFAULT_LABELS`.
816
+ */
817
+ labels?: Record<string, DocumentLabelPair>;
818
+ /** Set when this template was cloned from a platform-gallery template. */
819
+ origin_platform_template_id?: string | null;
820
+ direction: DocumentDirection;
821
+ theme: DocumentThemeTokens;
822
+ logo_url?: string;
823
+ background?: DocumentBackgroundSpec;
824
+ page: DocumentPageSpec;
825
+ sections: DocumentSection[];
826
+ /** Frozen HTML (with `{{tokens}}`) the renderer uses verbatim. */
827
+ html_body?: string;
828
+ /** Core-only free-form knobs bag (not part of the UI-lib shape). */
829
+ settings?: Record<string, unknown> | null;
830
+ is_default?: boolean;
831
+ created_at?: string;
832
+ updated_at?: string;
833
+ }
834
+ /**
835
+ * Body for `POST /document-templates`. `name` may be a plain string or a
836
+ * `{en, ar}` map (core coerces either to a translations map); `html_body` is
837
+ * required on create.
838
+ */
839
+ export interface CreateDocumentTemplateInput {
840
+ document_type: DocumentType;
841
+ name: DocumentLocalizedName | string;
842
+ html_body: string;
843
+ direction?: DocumentDirection;
844
+ theme?: DocumentThemeTokens | null;
845
+ logo_url?: string | null;
846
+ background?: DocumentBackgroundSpec | null;
847
+ page?: DocumentPageSpec | null;
848
+ sections?: DocumentSection[] | null;
849
+ settings?: Record<string, unknown> | null;
850
+ is_default?: boolean;
851
+ }
852
+ export type UpdateDocumentTemplateInput = Partial<CreateDocumentTemplateInput>;
853
+ /** One entry of `GET /document-types` — feeds the studio's type-picker. */
854
+ export interface DocumentTypeCatalogueItem {
855
+ document_type: DocumentType;
856
+ label: DocumentLocalizedName;
857
+ token_groups: string[];
858
+ }
859
+ /**
860
+ * Per-type render config (`GET`/`PUT /document-render-config`). The GET yields
861
+ * one entry per supported type (synthesising a disabled default where no row
862
+ * exists yet); `label` is present on GET, absent from the PUT echo.
863
+ */
864
+ export interface RenderConfig {
865
+ document_type: DocumentType;
866
+ label?: DocumentLocalizedName;
867
+ rendering_enabled: boolean;
868
+ default_template_id: string | null;
869
+ }
870
+ /** Per-tenant billing / settlement behaviour (TenantSettings key "billing.policy"). */
871
+ export interface BillingPolicy {
872
+ settlement_mode: 'strict' | 'immediate_cash' | 'deferred_reconciliation';
873
+ notify_client_on: 'issued' | 'paid' | 'both' | 'never';
874
+ auto_issue_invoice_on_fulfilment: boolean;
875
+ auto_settle_on_point_of_sale: boolean;
876
+ allow_reconciliation_sweep: boolean;
877
+ }
878
+ /**
879
+ * The per-tenant accounting GL settings (GET/PATCH /api/accounting/settings). Flat object; the
880
+ * PATCH accepts a partial. Only the fields consumed by the vertical are typed strictly — the rest
881
+ * (prefixes, renderer, tax defaults, …) round-trip via the index signature.
882
+ */
883
+ export interface AccountingGlSettings {
884
+ /** How strictly postings require an open fiscal period. `flexible` = never blocked. */
885
+ fiscal_period_policy: 'strict' | 'hybrid' | 'flexible';
886
+ /** Auto-create the fiscal year + periods a posting needs (so postings are never blocked). */
887
+ auto_extend_periods: boolean;
888
+ require_memo_on_journal?: boolean;
889
+ zero_amount_lines?: 'skip' | 'allow' | 'reject';
890
+ payment_je_tracking?: boolean;
891
+ }
892
+ export interface UpsertRenderConfigInput {
893
+ document_type: DocumentType;
894
+ rendering_enabled: boolean;
895
+ default_template_id?: string | null;
896
+ }
897
+ /** `GET /documents/{type}/{id}/render` — the substituted HTML + which template it used. */
898
+ export interface RenderedDocument {
899
+ html: string;
900
+ template_id: string;
901
+ }
902
+ /**
903
+ * `GET /documents/{type}/{id}/render.data` — the resolved TokenResolver context,
904
+ * shaped as the UI renderer's `DocumentData`. STRUCTURALLY MIRRORS
905
+ * `@nuwah/ui/solid/documents`'s `DocumentData`, so it can be fed straight into
906
+ * `<DocumentRenderer>` with no adapter.
907
+ *
908
+ * All money fields are DISPLAY-formatted (currency symbol + minor units), exactly
909
+ * like the HTML render's tokens. Each line additionally carries `line_total_raw`
910
+ * (the un-formatted numeric) so the client paginator's carried/brought-forward
911
+ * running subtotals reconcile exactly.
912
+ */
913
+ export interface RenderedDocumentParty {
914
+ name: string;
915
+ address: string;
916
+ phone: string;
917
+ email: string;
918
+ tax_id: string;
919
+ logo_url?: string;
920
+ }
921
+ export interface RenderedDocumentLine {
922
+ description: string;
923
+ quantity: string;
924
+ unit_price: string;
925
+ line_total: string;
926
+ tax: string;
927
+ /** RAW numeric `line_total` for exact client-side carried-forward summing. */
928
+ line_total_raw?: number;
929
+ }
930
+ export interface RenderedDocumentData {
931
+ document: {
932
+ number: string;
933
+ date: string | null;
934
+ due_date: string | null;
935
+ status: string;
936
+ payment_state?: string;
937
+ currency: string | null;
938
+ reference: string;
939
+ };
940
+ issuer: RenderedDocumentParty;
941
+ counterparty: RenderedDocumentParty;
942
+ lines: RenderedDocumentLine[];
943
+ totals: {
944
+ subtotal: string;
945
+ tax_total: string;
946
+ discount_total: string;
947
+ grand_total: string;
948
+ amount_paid: string;
949
+ amount_due: string;
950
+ };
951
+ notes: string;
952
+ terms: string;
953
+ }
954
+ /** Lifecycle of a gallery row: published (browseable) · submitted (review queue) · rejected. */
955
+ export type PlatformTemplateStatus = 'published' | 'submitted' | 'rejected';
956
+ /**
957
+ * A platform-gallery document template — the studio schema plus the gallery/review
958
+ * metadata (`status`, `submitted_by_*`, `category`, `tags`). Structurally a superset
959
+ * of `DocumentTemplate` (same studio fields), so a gallery row can be previewed /
960
+ * cloned into the Studio without an adapter. Single-resource + collection rows are the
961
+ * BARE resolved object (the `list`/`gallery`/`submissions` endpoints wrap in `{data}`).
962
+ */
963
+ export interface PlatformDocumentTemplate {
964
+ id: string;
965
+ /** Always `'platform'` — the fixed gallery scope. */
966
+ scope: string;
967
+ document_type: DocumentType;
968
+ name: DocumentLocalizedName;
969
+ language_mode?: DocumentLanguageMode;
970
+ direction: DocumentDirection;
971
+ theme: DocumentThemeTokens;
972
+ logo_url?: string | null;
973
+ background?: DocumentBackgroundSpec | null;
974
+ page: DocumentPageSpec;
975
+ sections: DocumentSection[];
976
+ html_body?: string | null;
977
+ status: PlatformTemplateStatus;
978
+ /** Tenant that submitted this row back to the gallery (null for platform-authored). */
979
+ submitted_by_tenant_id: string | null;
980
+ /** Free-form submitter identity/label captured at submission time. */
981
+ submitted_by_user: string | null;
982
+ /** Super-admin note left on rejection (or clearing on approval). */
983
+ review_note: string | null;
984
+ category: string | null;
985
+ tags: string[] | null;
986
+ is_active: boolean;
987
+ created_at?: string;
988
+ updated_at?: string;
989
+ }
990
+ /** Filter for the tenant gallery browse (`document-gallery`) — published rows only. */
991
+ export interface DocumentGalleryQuery {
992
+ document_type?: DocumentType;
993
+ category?: string;
994
+ [param: string]: string | number | boolean | null | undefined | Array<string | number>;
995
+ }
996
+ /** Filter for the super-admin gallery listing (all statuses). */
997
+ export interface PlatformTemplateListQuery {
998
+ status?: PlatformTemplateStatus;
999
+ document_type?: DocumentType;
1000
+ [param: string]: string | number | boolean | null | undefined | Array<string | number>;
1001
+ }
1002
+ /**
1003
+ * Body for `POST`/`PUT /api/platform/document-templates`. `name` may be a plain
1004
+ * string or a `{en, ar}` map (core coerces either). Super-admin authored rows are
1005
+ * created `published`.
1006
+ */
1007
+ export interface PlatformDocumentTemplateInput {
1008
+ document_type: DocumentType;
1009
+ name: DocumentLocalizedName | string;
1010
+ html_body?: string | null;
1011
+ language_mode?: DocumentLanguageMode;
1012
+ direction?: DocumentDirection;
1013
+ theme?: DocumentThemeTokens | null;
1014
+ logo_url?: string | null;
1015
+ background?: DocumentBackgroundSpec | null;
1016
+ page?: DocumentPageSpec | null;
1017
+ sections?: DocumentSection[] | null;
1018
+ category?: string | null;
1019
+ tags?: string[] | null;
1020
+ is_active?: boolean;
1021
+ }
1022
+ /** `GET`/`PUT /documents/{type}/{id}/template-override` — the stored per-document choice. */
1023
+ export interface TemplateOverride {
1024
+ /** The chosen template id, or `null` when no override is stored (config default applies). */
1025
+ template_id: string | null;
1026
+ }
1027
+ export interface CoordinatorCollection {
1028
+ id: string;
1029
+ insurer_counterparty_id: string;
1030
+ collected_by_person_id: string | null;
1031
+ /** Server decimal string (never a float). */
1032
+ amount: string;
1033
+ currency_code: string;
1034
+ collected_at: string;
1035
+ received_journal_entry_id: string | null;
1036
+ settled_at: string | null;
1037
+ settlement_journal_entry_id: string | null;
1038
+ status: 'collected' | 'settled' | 'reversed';
1039
+ notes: string | null;
1040
+ created_at: string;
1041
+ }
1042
+ export interface RecordCoordinatorCollectionInput {
1043
+ insurer_counterparty_id: string;
1044
+ claim_ids: string[];
1045
+ collected_by_person_id?: string | null;
1046
+ collected_at?: string;
1047
+ notes?: string | null;
1048
+ }
1049
+ export interface CoordinatorCollectionReportRow {
1050
+ insurer_counterparty_id: string;
1051
+ collected: string;
1052
+ settled: string;
1053
+ outstanding: string;
1054
+ }
1055
+ /** The report types a saved report may target. */
1056
+ export type SavedReportType = 'trial_balance' | 'balance_sheet' | 'income_statement' | 'general_ledger' | 'cash_flow' | 'account_balances' | 'counterparty_ledger' | 'ar_aging' | 'ap_aging';
1057
+ /** A stored report definition (shape from `SavedReport::toApiResponse()`). */
1058
+ export interface SavedReport {
1059
+ uuid: string;
1060
+ report_type: SavedReportType;
1061
+ /** Bilingual name (`en` required, `ar` optional). */
1062
+ name: Translatable;
1063
+ /** The captured report parameters (as_of / from / to / account_id / …). */
1064
+ parameters: Record<string, unknown>;
1065
+ /** Optional bilingual description. */
1066
+ description: Translatable | null;
1067
+ pinned: boolean;
1068
+ /** Stamped whenever the report is opened (`show`). */
1069
+ last_run_at: string | null;
1070
+ }
1071
+ /** Body for `POST /saved-reports`. */
1072
+ export interface CreateSavedReportInput {
1073
+ report_type: SavedReportType;
1074
+ name: Translatable;
1075
+ parameters: Record<string, unknown>;
1076
+ description?: Translatable | null;
1077
+ pinned?: boolean;
1078
+ }
1079
+ /** Body for `PUT /saved-reports/{uuid}` — every field optional. */
1080
+ export interface UpdateSavedReportInput {
1081
+ name?: Translatable;
1082
+ parameters?: Record<string, unknown>;
1083
+ description?: Translatable | null;
1084
+ pinned?: boolean;
1085
+ }
1086
+ export declare function createAccountingNamespace(http: Http, config: NuwahClientConfig): {
1087
+ invoices: {
1088
+ /** GET /api/accounting/invoices */
1089
+ list: (query?: InvoiceListQuery) => Promise<Paginated<InvoiceListItem>>;
1090
+ /** GET /api/accounting/invoices/{uuid} */
1091
+ get: (uuid: string) => Promise<InvoiceDetail>;
1092
+ /** POST /api/accounting/invoices — creates a draft. */
1093
+ create: (input: CreateInvoiceInput) => Promise<CreateInvoiceResult>;
1094
+ /** POST /api/accounting/invoices/{uuid}/lines */
1095
+ addLine: (uuid: string, input: AddInvoiceLineInput) => Promise<AddInvoiceLineResult>;
1096
+ /** DELETE /api/accounting/invoices/{uuid}/lines/{lineUuid} */
1097
+ removeLine: (uuid: string, lineUuid: string) => Promise<void>;
1098
+ /** POST /api/accounting/invoices/{uuid}/confirm — posts the journal entry. */
1099
+ confirm: (uuid: string) => Promise<InvoiceDetail>;
1100
+ /** POST /api/accounting/invoices/{uuid}/void */
1101
+ void: (uuid: string, voidReason: string) => Promise<InvoiceDetail>;
1102
+ /**
1103
+ * DELETE /api/accounting/invoices/{uuid} — DeleteDraftInvoiceAction: a DRAFT only (never
1104
+ * numbered, never posted, no payment). Anything else is refused with a 422 and the
1105
+ * reason; a confirmed invoice is voided or credited instead. Audited.
1106
+ */
1107
+ removeDraft: (uuid: string) => Promise<void>;
1108
+ /**
1109
+ * POST /api/accounting/invoices/{uuid}/send — SendInvoiceAction: hands the invoice to the
1110
+ * customer's linked person through the notification path (email and push by default)
1111
+ * and records `sent_at`. Idempotent: a second send answers the same `sent_at`. Refused
1112
+ * for a draft, a voided invoice, or a customer with no linked account.
1113
+ */
1114
+ send: (uuid: string) => Promise<InvoiceDetail>;
1115
+ };
1116
+ creditNotes: {
1117
+ /** GET /api/accounting/credit-notes — paginated `{data, meta}`. */
1118
+ list: (query?: ListQuery & {
1119
+ invoice_id?: string;
1120
+ }) => Promise<Paginated<{
1121
+ id: string;
1122
+ credit_note_number: string;
1123
+ amount: string;
1124
+ reason: string | null;
1125
+ status: string;
1126
+ }>>;
1127
+ /** POST /api/accounting/credit-notes — issue a credit note against an invoice (posts a reversing JE). */
1128
+ create: (input: CreateCreditNoteInput) => Promise<{
1129
+ id: string;
1130
+ credit_note_number: string;
1131
+ status: string;
1132
+ }>;
1133
+ };
1134
+ paymentsReceived: {
1135
+ /** GET /api/accounting/payments-received */
1136
+ list: (query?: ListQuery) => Promise<Paginated<PaymentReceived>>;
1137
+ /** POST /api/accounting/payments-received */
1138
+ create: (input: Record<string, unknown>) => Promise<RecordPaymentReceivedResult>;
1139
+ };
1140
+ counterparties: {
1141
+ /** GET /api/accounting/counterparties */
1142
+ list: (query?: CounterpartyListQuery) => Promise<Paginated<Counterparty>>;
1143
+ /** GET /api/accounting/counterparties/{uuid} */
1144
+ get: (uuid: string) => Promise<Counterparty>;
1145
+ /** POST /api/accounting/counterparties */
1146
+ create: (input: Record<string, unknown>) => Promise<Counterparty>;
1147
+ /** PUT /api/accounting/counterparties/{uuid} */
1148
+ update: (uuid: string, input: Record<string, unknown>) => Promise<Counterparty>;
1149
+ /** DELETE /api/accounting/counterparties/{uuid} */
1150
+ remove: (uuid: string) => Promise<void>;
1151
+ };
1152
+ accounts: {
1153
+ /** GET /api/accounting/accounts — bare array (pass `with_balances`). */
1154
+ list: (query?: {
1155
+ with_balances?: boolean;
1156
+ }) => Promise<Account[]>;
1157
+ /** GET /api/accounting/accounts/tree — bare array with nested `children`. */
1158
+ tree: (query?: {
1159
+ with_balances?: boolean;
1160
+ }) => Promise<Account[]>;
1161
+ /** GET /api/accounting/accounts/count */
1162
+ count: () => Promise<{
1163
+ count: number;
1164
+ }>;
1165
+ /** GET /api/accounting/accounts/{uuid}/activity */
1166
+ activity: (uuid: string) => Promise<AccountActivity>;
1167
+ /** POST /api/accounting/accounts */
1168
+ create: (input: CreateAccountInput) => Promise<Account>;
1169
+ /** PUT /api/accounting/accounts/{uuid} */
1170
+ update: (uuid: string, input: UpdateAccountInput) => Promise<Account>;
1171
+ /** POST /api/accounting/accounts/{uuid}/deactivate — 204. */
1172
+ deactivate: (uuid: string) => Promise<void>;
1173
+ };
1174
+ journalEntries: {
1175
+ /** GET /api/accounting/journal-entries — paginated `{data, meta}`. */
1176
+ list: (query?: JournalEntryListQuery) => Promise<Paginated<JournalEntry>>;
1177
+ /** GET /api/accounting/journal-entries/{uuid} */
1178
+ get: (uuid: string) => Promise<JournalEntry>;
1179
+ /** POST /api/accounting/journal-entries/{uuid}/void */
1180
+ void: (uuid: string, reason: string) => Promise<JournalEntry>;
1181
+ /**
1182
+ * POST /api/accounting/events/fire — the only journal-posting path.
1183
+ * Returns `{ journal_entry }`.
1184
+ */
1185
+ fire: (input: FireEventInput) => Promise<{
1186
+ journal_entry: JournalEntry;
1187
+ }>;
1188
+ };
1189
+ reports: {
1190
+ /** GET /api/accounting/reports/trial-balance */
1191
+ trialBalance: (query?: {
1192
+ as_of?: string;
1193
+ }) => Promise<TrialBalance>;
1194
+ /** GET /api/accounting/reports/balance-sheet */
1195
+ balanceSheet: (query?: {
1196
+ as_of?: string;
1197
+ }) => Promise<BalanceSheet>;
1198
+ /** GET /api/accounting/reports/income-statement */
1199
+ incomeStatement: (query?: ReportDateRangeQuery) => Promise<IncomeStatement>;
1200
+ /** GET /api/accounting/reports/general-ledger (account_id/from/to required). */
1201
+ generalLedger: (query: {
1202
+ account_id: string;
1203
+ from: string;
1204
+ to: string;
1205
+ }) => Promise<GeneralLedgerReport>;
1206
+ /** GET /api/accounting/reports/cash-flow */
1207
+ cashFlow: (query?: ReportDateRangeQuery) => Promise<CashFlowReport>;
1208
+ /** GET /api/accounting/reports/account-balances */
1209
+ accountBalances: (query?: {
1210
+ as_of?: string;
1211
+ type?: string;
1212
+ }) => Promise<AccountBalancesReport>;
1213
+ /**
1214
+ * GET /api/accounting/reports/counterparty-ledger — the patient/customer
1215
+ * running statement (AR invoices/credit-notes/payments + AP bills/payments).
1216
+ */
1217
+ counterpartyLedger: (query?: CounterpartyLedgerQuery) => Promise<CounterpartyLedgerReport>;
1218
+ };
1219
+ /** Saved report definitions (Report Studio) — `/api/accounting/saved-reports`. */
1220
+ savedReports: {
1221
+ /** GET /api/accounting/saved-reports — pinned first, newest next, capped at 50. */
1222
+ list: () => Promise<SavedReport[]>;
1223
+ /** GET /api/accounting/saved-reports/{uuid} — bare report; stamps `last_run_at`. */
1224
+ show: (uuid: string) => Promise<SavedReport>;
1225
+ /** POST /api/accounting/saved-reports — bare created report (201). */
1226
+ create: (input: CreateSavedReportInput) => Promise<SavedReport>;
1227
+ /** PUT /api/accounting/saved-reports/{uuid} — bare updated report. */
1228
+ update: (uuid: string, input: UpdateSavedReportInput) => Promise<SavedReport>;
1229
+ /** DELETE /api/accounting/saved-reports/{uuid} — `{ message }`. */
1230
+ destroy: (uuid: string) => Promise<{
1231
+ message: string;
1232
+ }>;
1233
+ };
1234
+ /** GET /api/accounting/ar-aging — receivables aging buckets + detail. */
1235
+ arAging: () => Promise<ArAgingReport>;
1236
+ /** GET /api/accounting/ap-aging — payables aging buckets + detail. */
1237
+ apAging: () => Promise<ApAgingReport>;
1238
+ claims: {
1239
+ /** GET /api/accounting/claims — paginated `{data, meta}`. */
1240
+ list: (query?: ClaimListQuery) => Promise<Paginated<Claim>>;
1241
+ /** GET /api/accounting/claims/{id} */
1242
+ get: (id: string) => Promise<Claim>;
1243
+ /** POST /api/accounting/claims */
1244
+ create: (input: CreateClaimInput) => Promise<Claim>;
1245
+ /** POST /api/accounting/claims/{id}/submit */
1246
+ submit: (id: string) => Promise<Claim>;
1247
+ /** POST /api/accounting/claims/{id}/adjudicate */
1248
+ adjudicate: (id: string, input: AdjudicateClaimInput) => Promise<Claim>;
1249
+ /** POST /api/accounting/claims/{id}/pay */
1250
+ pay: (id: string, input: PayClaimInput) => Promise<Claim>;
1251
+ /** POST /api/accounting/claims/{id}/reject */
1252
+ reject: (id: string, denialReason: string) => Promise<Claim>;
1253
+ /** POST /api/accounting/claims/{id}/void */
1254
+ void: (id: string, reason?: string | null) => Promise<Claim>;
1255
+ /** POST /api/accounting/claims/eob-batch */
1256
+ eobBatch: (lines: EobBatchLine[]) => Promise<EobBatchResult>;
1257
+ };
1258
+ coordinatorCollections: {
1259
+ /** GET /api/accounting/coordinator-collections — paginated; optional insurer/status filter. */
1260
+ list: (query?: {
1261
+ insurer_counterparty_id?: string;
1262
+ status?: string;
1263
+ per_page?: number;
1264
+ }) => Promise<Paginated<CoordinatorCollection>>;
1265
+ /** GET /api/accounting/coordinator-collections/report — per-insurer collected/settled/outstanding. */
1266
+ report: () => Promise<{
1267
+ data: CoordinatorCollectionReportRow[];
1268
+ }>;
1269
+ /** POST /api/accounting/coordinator-collections */
1270
+ record: (input: RecordCoordinatorCollectionInput) => Promise<CoordinatorCollection>;
1271
+ /** POST /api/accounting/coordinator-collections/{id}/settle */
1272
+ settle: (id: string) => Promise<CoordinatorCollection>;
1273
+ /** POST /api/accounting/coordinator-collections/{id}/reverse */
1274
+ reverse: (id: string, reason: string) => Promise<CoordinatorCollection>;
1275
+ };
1276
+ bills: {
1277
+ /** GET /api/accounting/bills — paginated `{data, meta}`. */
1278
+ list: (query?: BillListQuery) => Promise<Paginated<BillListItem>>;
1279
+ /** GET /api/accounting/bills/{uuid} */
1280
+ get: (uuid: string) => Promise<BillDetail>;
1281
+ /** POST /api/accounting/bills — returns `{ id, status }`. */
1282
+ create: (input: CreateBillInput) => Promise<BillMutationResult>;
1283
+ /** POST /api/accounting/bills/{uuid}/lines — bulk delete-and-replace. */
1284
+ setLines: (uuid: string, input: SetBillLinesInput) => Promise<{
1285
+ lines_count: number;
1286
+ }>;
1287
+ /** POST /api/accounting/bills/{uuid}/confirm — returns `{ id, status }`. */
1288
+ confirm: (uuid: string) => Promise<BillMutationResult>;
1289
+ /**
1290
+ * POST /api/accounting/bills/{uuid}/pay — record a payment MADE against a
1291
+ * confirmed/partially_paid bill (payables mirror of paymentsReceived). Posts
1292
+ * the GL entry (DR AP 2110 / CR Cash 1110) and advances the bill's status.
1293
+ */
1294
+ pay: (uuid: string, input: RecordBillPaymentInput) => Promise<RecordBillPaymentResult>;
1295
+ /** POST /api/accounting/bills/{uuid}/void — returns `{ id, status }`. */
1296
+ void: (uuid: string, voidReason: string) => Promise<BillMutationResult>;
1297
+ };
1298
+ bankAccounts: {
1299
+ /** GET /api/accounting/bank-accounts — paginated `{data, meta}`. */
1300
+ list: (query?: ListQuery & {
1301
+ is_active?: boolean;
1302
+ }) => Promise<Paginated<BankAccount>>;
1303
+ /** GET /api/accounting/bank-accounts/{uuid} */
1304
+ get: (uuid: string) => Promise<BankAccount>;
1305
+ /** POST /api/accounting/bank-accounts */
1306
+ create: (input: CreateBankAccountInput) => Promise<BankAccount>;
1307
+ /** PUT /api/accounting/bank-accounts/{uuid} */
1308
+ update: (uuid: string, input: UpdateBankAccountInput) => Promise<BankAccount>;
1309
+ };
1310
+ bankReconciliations: {
1311
+ /** GET /api/accounting/bank-reconciliations — paginated `{data, meta}`. */
1312
+ list: (query?: ListQuery & {
1313
+ bank_account_id?: string;
1314
+ status?: string;
1315
+ }) => Promise<Paginated<BankReconciliation>>;
1316
+ /** POST /api/accounting/bank-reconciliations */
1317
+ create: (input: CreateBankReconciliationInput) => Promise<BankReconciliation>;
1318
+ /** PATCH /api/accounting/bank-reconciliations/{uuid}/complete */
1319
+ complete: (uuid: string) => Promise<BankReconciliation>;
1320
+ };
1321
+ /** Document-type registry — feeds the Document Studio type-picker. */
1322
+ documentTypes: {
1323
+ /** GET /api/accounting/document-types — bare catalogue array (`{data}`-unwrapped). */
1324
+ list: () => Promise<DocumentTypeCatalogueItem[]>;
1325
+ };
1326
+ /** Document-template CRUD — the studio schema + frozen `html_body`. */
1327
+ documentTemplates: {
1328
+ /** GET /api/accounting/document-templates — paginated `{data, meta}`. */
1329
+ list: (documentType?: DocumentType) => Promise<Paginated<DocumentTemplate>>;
1330
+ /** GET /api/accounting/document-templates/{id} — bare resource. */
1331
+ get: (id: string) => Promise<DocumentTemplate>;
1332
+ /** POST /api/accounting/document-templates — returns the bare created resource (201). */
1333
+ create: (payload: CreateDocumentTemplateInput) => Promise<DocumentTemplate>;
1334
+ /** PUT /api/accounting/document-templates/{id} — returns the bare updated resource. */
1335
+ update: (id: string, payload: UpdateDocumentTemplateInput) => Promise<DocumentTemplate>;
1336
+ /** DELETE /api/accounting/document-templates/{id} — 204. */
1337
+ remove: (id: string) => Promise<void>;
1338
+ /** POST /api/accounting/document-templates/{id}/set-default — clears sibling defaults. */
1339
+ setDefault: (id: string) => Promise<DocumentTemplate>;
1340
+ /**
1341
+ * POST /api/accounting/document-templates/clone — deep-copy a published
1342
+ * gallery template into an independent tenant template. Returns the BARE
1343
+ * new tenant `DocumentTemplate` (201).
1344
+ */
1345
+ clone: (platformTemplateId: string) => Promise<DocumentTemplate>;
1346
+ /**
1347
+ * POST /api/accounting/document-templates/{id}/submit — submit a tenant
1348
+ * template back to the gallery for super-admin review. Returns the BARE
1349
+ * created submission (`PlatformDocumentTemplate`, status `submitted`, 201).
1350
+ */
1351
+ submit: (id: string) => Promise<PlatformDocumentTemplate>;
1352
+ };
1353
+ /** The published platform gallery a tenant can browse + clone from. */
1354
+ documentGallery: {
1355
+ /**
1356
+ * GET /api/accounting/document-gallery — published, cloneable starter
1357
+ * templates (bare array, `{data}`-unwrapped).
1358
+ */
1359
+ list: (query?: DocumentGalleryQuery) => Promise<PlatformDocumentTemplate[]>;
1360
+ };
1361
+ /** Per-document surface — the stored template override + the PDF URL. */
1362
+ documents: {
1363
+ /** Read/write the per-document template override (keyed by `type` + `id`). */
1364
+ templateOverride: {
1365
+ /**
1366
+ * GET /api/accounting/documents/{type}/{id}/template-override →
1367
+ * `{ template_id | null }`.
1368
+ */
1369
+ get: (type: DocumentType, id: string) => Promise<TemplateOverride>;
1370
+ /**
1371
+ * PUT /api/accounting/documents/{type}/{id}/template-override — set a
1372
+ * template override, or pass `null` to clear it. Echoes `{ template_id }`.
1373
+ */
1374
+ set: (type: DocumentType, id: string, templateId: string | null) => Promise<TemplateOverride>;
1375
+ };
1376
+ /**
1377
+ * The absolute URL for the rendered-document PDF
1378
+ * (`/api/accounting/documents/{type}/{id}/render.pdf`). A bare URL string
1379
+ * (the caller attaches auth / opens it); the PDF route is server-streamed.
1380
+ */
1381
+ pdfUrl: (type: DocumentType, id: string) => string;
1382
+ /**
1383
+ * GET /api/accounting/documents/{type}/{id}/render.data — the resolved
1384
+ * `DocumentData` context (full issuer + counterparty branding + raw line
1385
+ * amounts), ready to feed straight into the SPA's `<DocumentRenderer>`.
1386
+ * Optional `templateId` mirrors the config default → type default
1387
+ * resolution used by `/render`.
1388
+ */
1389
+ renderData: (type: DocumentType, id: string, templateId?: string) => Promise<RenderedDocumentData>;
1390
+ };
1391
+ /** Per-type render config (rendering toggle + default template). */
1392
+ billingPolicy: {
1393
+ /** GET /api/accounting/billing-policy — the per-tenant settlement / notification policy (`{data}`-unwrapped). */
1394
+ get: () => Promise<BillingPolicy>;
1395
+ /** PUT /api/accounting/billing-policy — replace the policy. */
1396
+ update: (input: BillingPolicy) => Promise<BillingPolicy>;
1397
+ };
1398
+ glSettings: {
1399
+ /** GET /api/accounting/settings — the per-tenant GL settings (flat object). */
1400
+ get: () => Promise<AccountingGlSettings>;
1401
+ /** PATCH /api/accounting/settings — partial update (only the sent keys change). */
1402
+ update: (input: Partial<AccountingGlSettings>) => Promise<AccountingGlSettings>;
1403
+ };
1404
+ renderConfig: {
1405
+ /** GET /api/accounting/document-render-config — one entry per type (`{data}`-unwrapped). */
1406
+ list: () => Promise<RenderConfig[]>;
1407
+ /** PUT /api/accounting/document-render-config — upserts a single type's config. */
1408
+ upsert: (input: UpsertRenderConfigInput) => Promise<RenderConfig>;
1409
+ };
1410
+ /**
1411
+ * GET /api/accounting/documents/{type}/{id}/render — resolve the real
1412
+ * document + tokens into a template's `html_body`. Optional `templateId`
1413
+ * overrides the config default → type default resolution.
1414
+ */
1415
+ renderDocument: (type: DocumentType, id: string, templateId?: string) => Promise<RenderedDocument>;
1416
+ };
1417
+ export type AccountingNamespace = ReturnType<typeof createAccountingNamespace>;