@arcforgelabs/flow 2026.10.18 → 2026.10.19-beta.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 (65) hide show
  1. package/README.md +3 -0
  2. package/SECURITY.md +4 -1
  3. package/npm-shrinkwrap.json +32 -3
  4. package/package.json +3 -2
  5. package/server/app.js +26 -3
  6. package/server/auth/routes.js +27 -12
  7. package/server/auth/session.js +6 -3
  8. package/server/auth/settings.js +26 -7
  9. package/server/auth/sign-in.html +17 -6
  10. package/server/core/invoices.js +6 -3
  11. package/server/core/ledger.js +420 -0
  12. package/server/db/migrations/0003_billing_ledger.sql +84 -0
  13. package/server/db/migrations/0004_ledger_events_append_only.sql +5 -0
  14. package/server/db/migrations/meta/0003_snapshot.json +1327 -0
  15. package/server/db/migrations/meta/0004_snapshot.json +1327 -0
  16. package/server/db/migrations/meta/_journal.json +14 -0
  17. package/server/db/schema.js +137 -0
  18. package/server/import/earlier-flow.js +230 -0
  19. package/server/import-earlier-flow.js +66 -0
  20. package/server/index.js +16 -4
  21. package/server/integrations/adapters.js +6 -0
  22. package/server/integrations/health.js +21 -0
  23. package/server/integrations/index.js +26 -0
  24. package/server/integrations/port.js +154 -6
  25. package/server/integrations/remove-tables.js +31 -0
  26. package/server/integrations/schema.js +62 -0
  27. package/server/integrations/seazona/client.js +196 -0
  28. package/server/integrations/seazona/drizzle.config.js +9 -0
  29. package/server/integrations/seazona/feed.js +104 -0
  30. package/server/integrations/seazona/governor.js +174 -0
  31. package/server/integrations/seazona/index.js +84 -0
  32. package/server/integrations/seazona/lanes.js +431 -0
  33. package/server/integrations/seazona/ledger.js +66 -0
  34. package/server/integrations/seazona/map.js +229 -0
  35. package/server/integrations/seazona/migrations/0000_api_governor.sql +20 -0
  36. package/server/integrations/seazona/migrations/0001_mirror.sql +106 -0
  37. package/server/integrations/seazona/migrations/meta/0000_snapshot.json +149 -0
  38. package/server/integrations/seazona/migrations/meta/0001_snapshot.json +793 -0
  39. package/server/integrations/seazona/migrations/meta/_journal.json +20 -0
  40. package/server/integrations/seazona/replay.js +79 -0
  41. package/server/integrations/seazona/scheduler.js +78 -0
  42. package/server/integrations/seazona/schema.js +157 -0
  43. package/server/integrations/seazona/settings.js +161 -0
  44. package/server/integrations/seazona/store.js +219 -0
  45. package/server/integrations/seazona/sync-once.js +44 -0
  46. package/server/integrations/seazona/tables.js +17 -0
  47. package/server/integrations/xero/catalogue.js +184 -0
  48. package/server/integrations/xero/client.js +253 -0
  49. package/server/integrations/xero/connections.js +104 -0
  50. package/server/integrations/xero/drafts.js +525 -0
  51. package/server/integrations/xero/fixtures/replay.json +45 -0
  52. package/server/integrations/xero/governor.js +275 -0
  53. package/server/integrations/xero/index.js +56 -0
  54. package/server/integrations/xero/ledger.js +269 -0
  55. package/server/integrations/xero/migrations/0000_xero_connections.sql +17 -0
  56. package/server/integrations/xero/migrations/0001_xero_catalogue.sql +49 -0
  57. package/server/integrations/xero/migrations/0002_xero_invoice_pushes.sql +32 -0
  58. package/server/integrations/xero/migrations/0003_xero_payment_cursors.sql +7 -0
  59. package/server/integrations/xero/migrations/meta/_journal.json +34 -0
  60. package/server/integrations/xero/oauth.js +143 -0
  61. package/server/integrations/xero/replay.js +83 -0
  62. package/server/integrations/xero/routes.js +234 -0
  63. package/server/integrations/xero/runtime.js +135 -0
  64. package/server/integrations/xero/settings.js +170 -0
  65. package/server/rate-limit.js +13 -19
@@ -0,0 +1,1327 @@
1
+ {
2
+ "id": "11870dae-2aeb-484b-ab41-cdf9defe3f8e",
3
+ "prevId": "183ebec4-2090-443e-ace1-90e8ff733dae",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.billing_obligations": {
8
+ "name": "billing_obligations",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "organisation_id": {
19
+ "name": "organisation_id",
20
+ "type": "uuid",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "source_system": {
25
+ "name": "source_system",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "source_job_ref": {
31
+ "name": "source_job_ref",
32
+ "type": "text",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "source_invoice_ref": {
37
+ "name": "source_invoice_ref",
38
+ "type": "text",
39
+ "primaryKey": false,
40
+ "notNull": false
41
+ },
42
+ "case_ref": {
43
+ "name": "case_ref",
44
+ "type": "text",
45
+ "primaryKey": false,
46
+ "notNull": false
47
+ },
48
+ "contact_id": {
49
+ "name": "contact_id",
50
+ "type": "uuid",
51
+ "primaryKey": false,
52
+ "notNull": false
53
+ },
54
+ "practitioner": {
55
+ "name": "practitioner",
56
+ "type": "text",
57
+ "primaryKey": false,
58
+ "notNull": false
59
+ },
60
+ "shipped_on": {
61
+ "name": "shipped_on",
62
+ "type": "date",
63
+ "primaryKey": false,
64
+ "notNull": false
65
+ },
66
+ "lines": {
67
+ "name": "lines",
68
+ "type": "jsonb",
69
+ "primaryKey": false,
70
+ "notNull": true,
71
+ "default": "'[]'::jsonb"
72
+ },
73
+ "line_fingerprint": {
74
+ "name": "line_fingerprint",
75
+ "type": "text",
76
+ "primaryKey": false,
77
+ "notNull": true
78
+ },
79
+ "subtotal_cents": {
80
+ "name": "subtotal_cents",
81
+ "type": "integer",
82
+ "primaryKey": false,
83
+ "notNull": true
84
+ },
85
+ "tax_cents": {
86
+ "name": "tax_cents",
87
+ "type": "integer",
88
+ "primaryKey": false,
89
+ "notNull": true
90
+ },
91
+ "total_cents": {
92
+ "name": "total_cents",
93
+ "type": "integer",
94
+ "primaryKey": false,
95
+ "notNull": true
96
+ },
97
+ "mapping_complete": {
98
+ "name": "mapping_complete",
99
+ "type": "boolean",
100
+ "primaryKey": false,
101
+ "notNull": true
102
+ },
103
+ "source_seen_at": {
104
+ "name": "source_seen_at",
105
+ "type": "timestamp with time zone",
106
+ "primaryKey": false,
107
+ "notNull": true
108
+ },
109
+ "hold_state": {
110
+ "name": "hold_state",
111
+ "type": "text",
112
+ "primaryKey": false,
113
+ "notNull": true,
114
+ "default": "'none'"
115
+ },
116
+ "hold_reason": {
117
+ "name": "hold_reason",
118
+ "type": "text",
119
+ "primaryKey": false,
120
+ "notNull": false
121
+ },
122
+ "invoice_id": {
123
+ "name": "invoice_id",
124
+ "type": "uuid",
125
+ "primaryKey": false,
126
+ "notNull": false
127
+ },
128
+ "accounting_state": {
129
+ "name": "accounting_state",
130
+ "type": "text",
131
+ "primaryKey": false,
132
+ "notNull": true,
133
+ "default": "'unknown'"
134
+ },
135
+ "accounting_ref": {
136
+ "name": "accounting_ref",
137
+ "type": "text",
138
+ "primaryKey": false,
139
+ "notNull": false
140
+ },
141
+ "accounting_url": {
142
+ "name": "accounting_url",
143
+ "type": "text",
144
+ "primaryKey": false,
145
+ "notNull": false
146
+ },
147
+ "accounting_matched_by": {
148
+ "name": "accounting_matched_by",
149
+ "type": "text",
150
+ "primaryKey": false,
151
+ "notNull": false
152
+ },
153
+ "accounting_checked_at": {
154
+ "name": "accounting_checked_at",
155
+ "type": "timestamp with time zone",
156
+ "primaryKey": false,
157
+ "notNull": false
158
+ },
159
+ "paid_cents": {
160
+ "name": "paid_cents",
161
+ "type": "integer",
162
+ "primaryKey": false,
163
+ "notNull": true,
164
+ "default": 0
165
+ },
166
+ "created_at": {
167
+ "name": "created_at",
168
+ "type": "timestamp with time zone",
169
+ "primaryKey": false,
170
+ "notNull": true,
171
+ "default": "now()"
172
+ },
173
+ "updated_at": {
174
+ "name": "updated_at",
175
+ "type": "timestamp with time zone",
176
+ "primaryKey": false,
177
+ "notNull": true,
178
+ "default": "now()"
179
+ }
180
+ },
181
+ "indexes": {},
182
+ "foreignKeys": {
183
+ "billing_obligations_organisation_id_organisations_id_fk": {
184
+ "name": "billing_obligations_organisation_id_organisations_id_fk",
185
+ "tableFrom": "billing_obligations",
186
+ "tableTo": "organisations",
187
+ "columnsFrom": [
188
+ "organisation_id"
189
+ ],
190
+ "columnsTo": [
191
+ "id"
192
+ ],
193
+ "onDelete": "no action",
194
+ "onUpdate": "no action"
195
+ },
196
+ "billing_obligations_contact_same_org": {
197
+ "name": "billing_obligations_contact_same_org",
198
+ "tableFrom": "billing_obligations",
199
+ "tableTo": "contacts",
200
+ "columnsFrom": [
201
+ "organisation_id",
202
+ "contact_id"
203
+ ],
204
+ "columnsTo": [
205
+ "organisation_id",
206
+ "id"
207
+ ],
208
+ "onDelete": "no action",
209
+ "onUpdate": "no action"
210
+ },
211
+ "billing_obligations_invoice_same_org": {
212
+ "name": "billing_obligations_invoice_same_org",
213
+ "tableFrom": "billing_obligations",
214
+ "tableTo": "invoices",
215
+ "columnsFrom": [
216
+ "organisation_id",
217
+ "invoice_id"
218
+ ],
219
+ "columnsTo": [
220
+ "organisation_id",
221
+ "id"
222
+ ],
223
+ "onDelete": "no action",
224
+ "onUpdate": "no action"
225
+ }
226
+ },
227
+ "compositePrimaryKeys": {},
228
+ "uniqueConstraints": {
229
+ "billing_obligations_org_id": {
230
+ "name": "billing_obligations_org_id",
231
+ "nullsNotDistinct": false,
232
+ "columns": [
233
+ "organisation_id",
234
+ "id"
235
+ ]
236
+ },
237
+ "billing_obligations_source_job": {
238
+ "name": "billing_obligations_source_job",
239
+ "nullsNotDistinct": false,
240
+ "columns": [
241
+ "organisation_id",
242
+ "source_system",
243
+ "source_job_ref"
244
+ ]
245
+ },
246
+ "billing_obligations_invoice": {
247
+ "name": "billing_obligations_invoice",
248
+ "nullsNotDistinct": false,
249
+ "columns": [
250
+ "organisation_id",
251
+ "invoice_id"
252
+ ]
253
+ }
254
+ },
255
+ "policies": {},
256
+ "checkConstraints": {
257
+ "billing_obligations_hold_state_valid": {
258
+ "name": "billing_obligations_hold_state_valid",
259
+ "value": "hold_state in ('none', 'held', 'review')"
260
+ },
261
+ "billing_obligations_accounting_state_valid": {
262
+ "name": "billing_obligations_accounting_state_valid",
263
+ "value": "accounting_state in ('unknown', 'not_found', 'drafted', 'authorised', 'part_paid', 'paid', 'voided', 'deleted', 'ambiguous', 'conflict')"
264
+ },
265
+ "billing_obligations_paid_not_negative": {
266
+ "name": "billing_obligations_paid_not_negative",
267
+ "value": "\"billing_obligations\".\"paid_cents\" >= 0"
268
+ }
269
+ },
270
+ "isRLSEnabled": false
271
+ },
272
+ "public.contacts": {
273
+ "name": "contacts",
274
+ "schema": "",
275
+ "columns": {
276
+ "id": {
277
+ "name": "id",
278
+ "type": "uuid",
279
+ "primaryKey": true,
280
+ "notNull": true,
281
+ "default": "gen_random_uuid()"
282
+ },
283
+ "organisation_id": {
284
+ "name": "organisation_id",
285
+ "type": "uuid",
286
+ "primaryKey": false,
287
+ "notNull": true
288
+ },
289
+ "kind": {
290
+ "name": "kind",
291
+ "type": "text",
292
+ "primaryKey": false,
293
+ "notNull": true
294
+ },
295
+ "name": {
296
+ "name": "name",
297
+ "type": "text",
298
+ "primaryKey": false,
299
+ "notNull": true
300
+ },
301
+ "email": {
302
+ "name": "email",
303
+ "type": "text",
304
+ "primaryKey": false,
305
+ "notNull": false
306
+ },
307
+ "created_at": {
308
+ "name": "created_at",
309
+ "type": "timestamp with time zone",
310
+ "primaryKey": false,
311
+ "notNull": true,
312
+ "default": "now()"
313
+ }
314
+ },
315
+ "indexes": {},
316
+ "foreignKeys": {
317
+ "contacts_organisation_id_organisations_id_fk": {
318
+ "name": "contacts_organisation_id_organisations_id_fk",
319
+ "tableFrom": "contacts",
320
+ "tableTo": "organisations",
321
+ "columnsFrom": [
322
+ "organisation_id"
323
+ ],
324
+ "columnsTo": [
325
+ "id"
326
+ ],
327
+ "onDelete": "no action",
328
+ "onUpdate": "no action"
329
+ }
330
+ },
331
+ "compositePrimaryKeys": {},
332
+ "uniqueConstraints": {
333
+ "contacts_org_id": {
334
+ "name": "contacts_org_id",
335
+ "nullsNotDistinct": false,
336
+ "columns": [
337
+ "organisation_id",
338
+ "id"
339
+ ]
340
+ },
341
+ "contacts_org_kind_name": {
342
+ "name": "contacts_org_kind_name",
343
+ "nullsNotDistinct": false,
344
+ "columns": [
345
+ "organisation_id",
346
+ "kind",
347
+ "name"
348
+ ]
349
+ }
350
+ },
351
+ "policies": {},
352
+ "checkConstraints": {
353
+ "contacts_kind_valid": {
354
+ "name": "contacts_kind_valid",
355
+ "value": "\"contacts\".\"kind\" in ('customer', 'supplier')"
356
+ }
357
+ },
358
+ "isRLSEnabled": false
359
+ },
360
+ "public.invoice_lines": {
361
+ "name": "invoice_lines",
362
+ "schema": "",
363
+ "columns": {
364
+ "id": {
365
+ "name": "id",
366
+ "type": "uuid",
367
+ "primaryKey": true,
368
+ "notNull": true,
369
+ "default": "gen_random_uuid()"
370
+ },
371
+ "organisation_id": {
372
+ "name": "organisation_id",
373
+ "type": "uuid",
374
+ "primaryKey": false,
375
+ "notNull": true
376
+ },
377
+ "invoice_id": {
378
+ "name": "invoice_id",
379
+ "type": "uuid",
380
+ "primaryKey": false,
381
+ "notNull": true
382
+ },
383
+ "position": {
384
+ "name": "position",
385
+ "type": "integer",
386
+ "primaryKey": false,
387
+ "notNull": true
388
+ },
389
+ "price_item_id": {
390
+ "name": "price_item_id",
391
+ "type": "uuid",
392
+ "primaryKey": false,
393
+ "notNull": false
394
+ },
395
+ "description": {
396
+ "name": "description",
397
+ "type": "text",
398
+ "primaryKey": false,
399
+ "notNull": true
400
+ },
401
+ "quantity": {
402
+ "name": "quantity",
403
+ "type": "integer",
404
+ "primaryKey": false,
405
+ "notNull": true
406
+ },
407
+ "unit_amount_cents": {
408
+ "name": "unit_amount_cents",
409
+ "type": "integer",
410
+ "primaryKey": false,
411
+ "notNull": true
412
+ },
413
+ "tax_code": {
414
+ "name": "tax_code",
415
+ "type": "text",
416
+ "primaryKey": false,
417
+ "notNull": true
418
+ },
419
+ "line_amount_cents": {
420
+ "name": "line_amount_cents",
421
+ "type": "integer",
422
+ "primaryKey": false,
423
+ "notNull": true
424
+ },
425
+ "tax_cents": {
426
+ "name": "tax_cents",
427
+ "type": "integer",
428
+ "primaryKey": false,
429
+ "notNull": true
430
+ }
431
+ },
432
+ "indexes": {},
433
+ "foreignKeys": {
434
+ "invoice_lines_invoice_same_org": {
435
+ "name": "invoice_lines_invoice_same_org",
436
+ "tableFrom": "invoice_lines",
437
+ "tableTo": "invoices",
438
+ "columnsFrom": [
439
+ "organisation_id",
440
+ "invoice_id"
441
+ ],
442
+ "columnsTo": [
443
+ "organisation_id",
444
+ "id"
445
+ ],
446
+ "onDelete": "cascade",
447
+ "onUpdate": "no action"
448
+ },
449
+ "invoice_lines_price_item_same_org": {
450
+ "name": "invoice_lines_price_item_same_org",
451
+ "tableFrom": "invoice_lines",
452
+ "tableTo": "price_items",
453
+ "columnsFrom": [
454
+ "organisation_id",
455
+ "price_item_id"
456
+ ],
457
+ "columnsTo": [
458
+ "organisation_id",
459
+ "id"
460
+ ],
461
+ "onDelete": "no action",
462
+ "onUpdate": "no action"
463
+ }
464
+ },
465
+ "compositePrimaryKeys": {},
466
+ "uniqueConstraints": {
467
+ "invoice_lines_invoice_position": {
468
+ "name": "invoice_lines_invoice_position",
469
+ "nullsNotDistinct": false,
470
+ "columns": [
471
+ "invoice_id",
472
+ "position"
473
+ ]
474
+ }
475
+ },
476
+ "policies": {},
477
+ "checkConstraints": {
478
+ "invoice_lines_quantity_positive": {
479
+ "name": "invoice_lines_quantity_positive",
480
+ "value": "\"invoice_lines\".\"quantity\" > 0"
481
+ },
482
+ "invoice_lines_tax_code_valid": {
483
+ "name": "invoice_lines_tax_code_valid",
484
+ "value": "\"invoice_lines\".\"tax_code\" in ('GST', 'GST_FREE')"
485
+ }
486
+ },
487
+ "isRLSEnabled": false
488
+ },
489
+ "public.invoice_versions": {
490
+ "name": "invoice_versions",
491
+ "schema": "",
492
+ "columns": {
493
+ "id": {
494
+ "name": "id",
495
+ "type": "uuid",
496
+ "primaryKey": true,
497
+ "notNull": true,
498
+ "default": "gen_random_uuid()"
499
+ },
500
+ "organisation_id": {
501
+ "name": "organisation_id",
502
+ "type": "uuid",
503
+ "primaryKey": false,
504
+ "notNull": true
505
+ },
506
+ "invoice_id": {
507
+ "name": "invoice_id",
508
+ "type": "uuid",
509
+ "primaryKey": false,
510
+ "notNull": true
511
+ },
512
+ "version": {
513
+ "name": "version",
514
+ "type": "integer",
515
+ "primaryKey": false,
516
+ "notNull": true
517
+ },
518
+ "issued_at": {
519
+ "name": "issued_at",
520
+ "type": "timestamp with time zone",
521
+ "primaryKey": false,
522
+ "notNull": true,
523
+ "default": "now()"
524
+ },
525
+ "issued_by": {
526
+ "name": "issued_by",
527
+ "type": "text",
528
+ "primaryKey": false,
529
+ "notNull": true
530
+ },
531
+ "document": {
532
+ "name": "document",
533
+ "type": "jsonb",
534
+ "primaryKey": false,
535
+ "notNull": true
536
+ }
537
+ },
538
+ "indexes": {},
539
+ "foreignKeys": {
540
+ "invoice_versions_invoice_same_org": {
541
+ "name": "invoice_versions_invoice_same_org",
542
+ "tableFrom": "invoice_versions",
543
+ "tableTo": "invoices",
544
+ "columnsFrom": [
545
+ "organisation_id",
546
+ "invoice_id"
547
+ ],
548
+ "columnsTo": [
549
+ "organisation_id",
550
+ "id"
551
+ ],
552
+ "onDelete": "no action",
553
+ "onUpdate": "no action"
554
+ }
555
+ },
556
+ "compositePrimaryKeys": {},
557
+ "uniqueConstraints": {
558
+ "invoice_versions_invoice_version": {
559
+ "name": "invoice_versions_invoice_version",
560
+ "nullsNotDistinct": false,
561
+ "columns": [
562
+ "invoice_id",
563
+ "version"
564
+ ]
565
+ }
566
+ },
567
+ "policies": {},
568
+ "checkConstraints": {
569
+ "invoice_versions_version_positive": {
570
+ "name": "invoice_versions_version_positive",
571
+ "value": "\"invoice_versions\".\"version\" > 0"
572
+ }
573
+ },
574
+ "isRLSEnabled": false
575
+ },
576
+ "public.invoices": {
577
+ "name": "invoices",
578
+ "schema": "",
579
+ "columns": {
580
+ "id": {
581
+ "name": "id",
582
+ "type": "uuid",
583
+ "primaryKey": true,
584
+ "notNull": true,
585
+ "default": "gen_random_uuid()"
586
+ },
587
+ "organisation_id": {
588
+ "name": "organisation_id",
589
+ "type": "uuid",
590
+ "primaryKey": false,
591
+ "notNull": true
592
+ },
593
+ "contact_id": {
594
+ "name": "contact_id",
595
+ "type": "uuid",
596
+ "primaryKey": false,
597
+ "notNull": true
598
+ },
599
+ "number": {
600
+ "name": "number",
601
+ "type": "text",
602
+ "primaryKey": false,
603
+ "notNull": false
604
+ },
605
+ "status": {
606
+ "name": "status",
607
+ "type": "text",
608
+ "primaryKey": false,
609
+ "notNull": true,
610
+ "default": "'draft'"
611
+ },
612
+ "issued_version": {
613
+ "name": "issued_version",
614
+ "type": "integer",
615
+ "primaryKey": false,
616
+ "notNull": true,
617
+ "default": 0
618
+ },
619
+ "reference": {
620
+ "name": "reference",
621
+ "type": "text",
622
+ "primaryKey": false,
623
+ "notNull": false
624
+ },
625
+ "currency": {
626
+ "name": "currency",
627
+ "type": "text",
628
+ "primaryKey": false,
629
+ "notNull": true,
630
+ "default": "'AUD'"
631
+ },
632
+ "issue_date": {
633
+ "name": "issue_date",
634
+ "type": "date",
635
+ "primaryKey": false,
636
+ "notNull": false
637
+ },
638
+ "due_date": {
639
+ "name": "due_date",
640
+ "type": "date",
641
+ "primaryKey": false,
642
+ "notNull": false
643
+ },
644
+ "subtotal_cents": {
645
+ "name": "subtotal_cents",
646
+ "type": "integer",
647
+ "primaryKey": false,
648
+ "notNull": true,
649
+ "default": 0
650
+ },
651
+ "tax_cents": {
652
+ "name": "tax_cents",
653
+ "type": "integer",
654
+ "primaryKey": false,
655
+ "notNull": true,
656
+ "default": 0
657
+ },
658
+ "total_cents": {
659
+ "name": "total_cents",
660
+ "type": "integer",
661
+ "primaryKey": false,
662
+ "notNull": true,
663
+ "default": 0
664
+ },
665
+ "created_at": {
666
+ "name": "created_at",
667
+ "type": "timestamp with time zone",
668
+ "primaryKey": false,
669
+ "notNull": true,
670
+ "default": "now()"
671
+ },
672
+ "updated_at": {
673
+ "name": "updated_at",
674
+ "type": "timestamp with time zone",
675
+ "primaryKey": false,
676
+ "notNull": true,
677
+ "default": "now()"
678
+ }
679
+ },
680
+ "indexes": {},
681
+ "foreignKeys": {
682
+ "invoices_organisation_id_organisations_id_fk": {
683
+ "name": "invoices_organisation_id_organisations_id_fk",
684
+ "tableFrom": "invoices",
685
+ "tableTo": "organisations",
686
+ "columnsFrom": [
687
+ "organisation_id"
688
+ ],
689
+ "columnsTo": [
690
+ "id"
691
+ ],
692
+ "onDelete": "no action",
693
+ "onUpdate": "no action"
694
+ },
695
+ "invoices_contact_same_org": {
696
+ "name": "invoices_contact_same_org",
697
+ "tableFrom": "invoices",
698
+ "tableTo": "contacts",
699
+ "columnsFrom": [
700
+ "organisation_id",
701
+ "contact_id"
702
+ ],
703
+ "columnsTo": [
704
+ "organisation_id",
705
+ "id"
706
+ ],
707
+ "onDelete": "no action",
708
+ "onUpdate": "no action"
709
+ }
710
+ },
711
+ "compositePrimaryKeys": {},
712
+ "uniqueConstraints": {
713
+ "invoices_org_id": {
714
+ "name": "invoices_org_id",
715
+ "nullsNotDistinct": false,
716
+ "columns": [
717
+ "organisation_id",
718
+ "id"
719
+ ]
720
+ },
721
+ "invoices_org_number": {
722
+ "name": "invoices_org_number",
723
+ "nullsNotDistinct": false,
724
+ "columns": [
725
+ "organisation_id",
726
+ "number"
727
+ ]
728
+ }
729
+ },
730
+ "policies": {},
731
+ "checkConstraints": {
732
+ "invoices_status_valid": {
733
+ "name": "invoices_status_valid",
734
+ "value": "\"invoices\".\"status\" in ('draft', 'issued', 'void')"
735
+ },
736
+ "invoices_issued_has_number": {
737
+ "name": "invoices_issued_has_number",
738
+ "value": "\"invoices\".\"status\" = 'draft' or \"invoices\".\"number\" is not null"
739
+ }
740
+ },
741
+ "isRLSEnabled": false
742
+ },
743
+ "public.obligation_events": {
744
+ "name": "obligation_events",
745
+ "schema": "",
746
+ "columns": {
747
+ "id": {
748
+ "name": "id",
749
+ "type": "uuid",
750
+ "primaryKey": true,
751
+ "notNull": true,
752
+ "default": "gen_random_uuid()"
753
+ },
754
+ "organisation_id": {
755
+ "name": "organisation_id",
756
+ "type": "uuid",
757
+ "primaryKey": false,
758
+ "notNull": true
759
+ },
760
+ "obligation_id": {
761
+ "name": "obligation_id",
762
+ "type": "uuid",
763
+ "primaryKey": false,
764
+ "notNull": true
765
+ },
766
+ "kind": {
767
+ "name": "kind",
768
+ "type": "text",
769
+ "primaryKey": false,
770
+ "notNull": true
771
+ },
772
+ "actor": {
773
+ "name": "actor",
774
+ "type": "text",
775
+ "primaryKey": false,
776
+ "notNull": true
777
+ },
778
+ "evidence": {
779
+ "name": "evidence",
780
+ "type": "jsonb",
781
+ "primaryKey": false,
782
+ "notNull": true,
783
+ "default": "'{}'::jsonb"
784
+ },
785
+ "created_at": {
786
+ "name": "created_at",
787
+ "type": "timestamp with time zone",
788
+ "primaryKey": false,
789
+ "notNull": true,
790
+ "default": "now()"
791
+ }
792
+ },
793
+ "indexes": {},
794
+ "foreignKeys": {
795
+ "obligation_events_obligation_same_org": {
796
+ "name": "obligation_events_obligation_same_org",
797
+ "tableFrom": "obligation_events",
798
+ "tableTo": "billing_obligations",
799
+ "columnsFrom": [
800
+ "organisation_id",
801
+ "obligation_id"
802
+ ],
803
+ "columnsTo": [
804
+ "organisation_id",
805
+ "id"
806
+ ],
807
+ "onDelete": "no action",
808
+ "onUpdate": "no action"
809
+ }
810
+ },
811
+ "compositePrimaryKeys": {},
812
+ "uniqueConstraints": {},
813
+ "policies": {},
814
+ "checkConstraints": {},
815
+ "isRLSEnabled": false
816
+ },
817
+ "public.obligation_payments": {
818
+ "name": "obligation_payments",
819
+ "schema": "",
820
+ "columns": {
821
+ "id": {
822
+ "name": "id",
823
+ "type": "uuid",
824
+ "primaryKey": true,
825
+ "notNull": true,
826
+ "default": "gen_random_uuid()"
827
+ },
828
+ "organisation_id": {
829
+ "name": "organisation_id",
830
+ "type": "uuid",
831
+ "primaryKey": false,
832
+ "notNull": true
833
+ },
834
+ "obligation_id": {
835
+ "name": "obligation_id",
836
+ "type": "uuid",
837
+ "primaryKey": false,
838
+ "notNull": true
839
+ },
840
+ "payment_ref": {
841
+ "name": "payment_ref",
842
+ "type": "text",
843
+ "primaryKey": false,
844
+ "notNull": true
845
+ },
846
+ "paid_on": {
847
+ "name": "paid_on",
848
+ "type": "date",
849
+ "primaryKey": false,
850
+ "notNull": true
851
+ },
852
+ "amount_cents": {
853
+ "name": "amount_cents",
854
+ "type": "integer",
855
+ "primaryKey": false,
856
+ "notNull": true
857
+ },
858
+ "reference": {
859
+ "name": "reference",
860
+ "type": "text",
861
+ "primaryKey": false,
862
+ "notNull": false
863
+ },
864
+ "reconciled": {
865
+ "name": "reconciled",
866
+ "type": "boolean",
867
+ "primaryKey": false,
868
+ "notNull": true
869
+ },
870
+ "accounting_url": {
871
+ "name": "accounting_url",
872
+ "type": "text",
873
+ "primaryKey": false,
874
+ "notNull": false
875
+ },
876
+ "observed_at": {
877
+ "name": "observed_at",
878
+ "type": "timestamp with time zone",
879
+ "primaryKey": false,
880
+ "notNull": true,
881
+ "default": "now()"
882
+ }
883
+ },
884
+ "indexes": {},
885
+ "foreignKeys": {
886
+ "obligation_payments_obligation_same_org": {
887
+ "name": "obligation_payments_obligation_same_org",
888
+ "tableFrom": "obligation_payments",
889
+ "tableTo": "billing_obligations",
890
+ "columnsFrom": [
891
+ "organisation_id",
892
+ "obligation_id"
893
+ ],
894
+ "columnsTo": [
895
+ "organisation_id",
896
+ "id"
897
+ ],
898
+ "onDelete": "no action",
899
+ "onUpdate": "no action"
900
+ }
901
+ },
902
+ "compositePrimaryKeys": {},
903
+ "uniqueConstraints": {
904
+ "obligation_payments_ref": {
905
+ "name": "obligation_payments_ref",
906
+ "nullsNotDistinct": false,
907
+ "columns": [
908
+ "organisation_id",
909
+ "obligation_id",
910
+ "payment_ref"
911
+ ]
912
+ }
913
+ },
914
+ "policies": {},
915
+ "checkConstraints": {
916
+ "obligation_payments_amount_positive": {
917
+ "name": "obligation_payments_amount_positive",
918
+ "value": "\"obligation_payments\".\"amount_cents\" > 0"
919
+ }
920
+ },
921
+ "isRLSEnabled": false
922
+ },
923
+ "public.obligation_writebacks": {
924
+ "name": "obligation_writebacks",
925
+ "schema": "",
926
+ "columns": {
927
+ "id": {
928
+ "name": "id",
929
+ "type": "uuid",
930
+ "primaryKey": true,
931
+ "notNull": true,
932
+ "default": "gen_random_uuid()"
933
+ },
934
+ "organisation_id": {
935
+ "name": "organisation_id",
936
+ "type": "uuid",
937
+ "primaryKey": false,
938
+ "notNull": true
939
+ },
940
+ "obligation_id": {
941
+ "name": "obligation_id",
942
+ "type": "uuid",
943
+ "primaryKey": false,
944
+ "notNull": true
945
+ },
946
+ "target_system": {
947
+ "name": "target_system",
948
+ "type": "text",
949
+ "primaryKey": false,
950
+ "notNull": true
951
+ },
952
+ "status": {
953
+ "name": "status",
954
+ "type": "text",
955
+ "primaryKey": false,
956
+ "notNull": true
957
+ },
958
+ "state": {
959
+ "name": "state",
960
+ "type": "text",
961
+ "primaryKey": false,
962
+ "notNull": true,
963
+ "default": "'pending'"
964
+ },
965
+ "evidence": {
966
+ "name": "evidence",
967
+ "type": "jsonb",
968
+ "primaryKey": false,
969
+ "notNull": true
970
+ },
971
+ "attempts": {
972
+ "name": "attempts",
973
+ "type": "integer",
974
+ "primaryKey": false,
975
+ "notNull": true,
976
+ "default": 0
977
+ },
978
+ "last_error": {
979
+ "name": "last_error",
980
+ "type": "text",
981
+ "primaryKey": false,
982
+ "notNull": false
983
+ },
984
+ "sent_at": {
985
+ "name": "sent_at",
986
+ "type": "timestamp with time zone",
987
+ "primaryKey": false,
988
+ "notNull": false
989
+ },
990
+ "created_at": {
991
+ "name": "created_at",
992
+ "type": "timestamp with time zone",
993
+ "primaryKey": false,
994
+ "notNull": true,
995
+ "default": "now()"
996
+ },
997
+ "updated_at": {
998
+ "name": "updated_at",
999
+ "type": "timestamp with time zone",
1000
+ "primaryKey": false,
1001
+ "notNull": true,
1002
+ "default": "now()"
1003
+ }
1004
+ },
1005
+ "indexes": {},
1006
+ "foreignKeys": {
1007
+ "obligation_writebacks_obligation_same_org": {
1008
+ "name": "obligation_writebacks_obligation_same_org",
1009
+ "tableFrom": "obligation_writebacks",
1010
+ "tableTo": "billing_obligations",
1011
+ "columnsFrom": [
1012
+ "organisation_id",
1013
+ "obligation_id"
1014
+ ],
1015
+ "columnsTo": [
1016
+ "organisation_id",
1017
+ "id"
1018
+ ],
1019
+ "onDelete": "no action",
1020
+ "onUpdate": "no action"
1021
+ }
1022
+ },
1023
+ "compositePrimaryKeys": {},
1024
+ "uniqueConstraints": {
1025
+ "obligation_writebacks_status": {
1026
+ "name": "obligation_writebacks_status",
1027
+ "nullsNotDistinct": false,
1028
+ "columns": [
1029
+ "organisation_id",
1030
+ "obligation_id",
1031
+ "status"
1032
+ ]
1033
+ }
1034
+ },
1035
+ "policies": {},
1036
+ "checkConstraints": {
1037
+ "obligation_writebacks_state_valid": {
1038
+ "name": "obligation_writebacks_state_valid",
1039
+ "value": "state in ('pending', 'sent', 'failed', 'not_supported')"
1040
+ }
1041
+ },
1042
+ "isRLSEnabled": false
1043
+ },
1044
+ "public.organisations": {
1045
+ "name": "organisations",
1046
+ "schema": "",
1047
+ "columns": {
1048
+ "id": {
1049
+ "name": "id",
1050
+ "type": "uuid",
1051
+ "primaryKey": true,
1052
+ "notNull": true,
1053
+ "default": "gen_random_uuid()"
1054
+ },
1055
+ "name": {
1056
+ "name": "name",
1057
+ "type": "text",
1058
+ "primaryKey": false,
1059
+ "notNull": true
1060
+ },
1061
+ "invoice_prefix": {
1062
+ "name": "invoice_prefix",
1063
+ "type": "text",
1064
+ "primaryKey": false,
1065
+ "notNull": true,
1066
+ "default": "'INV-'"
1067
+ },
1068
+ "next_invoice_number": {
1069
+ "name": "next_invoice_number",
1070
+ "type": "integer",
1071
+ "primaryKey": false,
1072
+ "notNull": true,
1073
+ "default": 1
1074
+ },
1075
+ "created_at": {
1076
+ "name": "created_at",
1077
+ "type": "timestamp with time zone",
1078
+ "primaryKey": false,
1079
+ "notNull": true,
1080
+ "default": "now()"
1081
+ }
1082
+ },
1083
+ "indexes": {},
1084
+ "foreignKeys": {},
1085
+ "compositePrimaryKeys": {},
1086
+ "uniqueConstraints": {},
1087
+ "policies": {},
1088
+ "checkConstraints": {
1089
+ "organisations_next_invoice_number_positive": {
1090
+ "name": "organisations_next_invoice_number_positive",
1091
+ "value": "\"organisations\".\"next_invoice_number\" > 0"
1092
+ }
1093
+ },
1094
+ "isRLSEnabled": false
1095
+ },
1096
+ "public.people": {
1097
+ "name": "people",
1098
+ "schema": "",
1099
+ "columns": {
1100
+ "id": {
1101
+ "name": "id",
1102
+ "type": "uuid",
1103
+ "primaryKey": true,
1104
+ "notNull": true,
1105
+ "default": "gen_random_uuid()"
1106
+ },
1107
+ "email": {
1108
+ "name": "email",
1109
+ "type": "text",
1110
+ "primaryKey": false,
1111
+ "notNull": true
1112
+ },
1113
+ "name": {
1114
+ "name": "name",
1115
+ "type": "text",
1116
+ "primaryKey": false,
1117
+ "notNull": false
1118
+ },
1119
+ "role": {
1120
+ "name": "role",
1121
+ "type": "text",
1122
+ "primaryKey": false,
1123
+ "notNull": true
1124
+ },
1125
+ "status": {
1126
+ "name": "status",
1127
+ "type": "text",
1128
+ "primaryKey": false,
1129
+ "notNull": true,
1130
+ "default": "'active'"
1131
+ },
1132
+ "clerk_user_id": {
1133
+ "name": "clerk_user_id",
1134
+ "type": "text",
1135
+ "primaryKey": false,
1136
+ "notNull": false
1137
+ },
1138
+ "invited_by": {
1139
+ "name": "invited_by",
1140
+ "type": "uuid",
1141
+ "primaryKey": false,
1142
+ "notNull": false
1143
+ },
1144
+ "linked_at": {
1145
+ "name": "linked_at",
1146
+ "type": "timestamp with time zone",
1147
+ "primaryKey": false,
1148
+ "notNull": false
1149
+ },
1150
+ "created_at": {
1151
+ "name": "created_at",
1152
+ "type": "timestamp with time zone",
1153
+ "primaryKey": false,
1154
+ "notNull": true,
1155
+ "default": "now()"
1156
+ },
1157
+ "updated_at": {
1158
+ "name": "updated_at",
1159
+ "type": "timestamp with time zone",
1160
+ "primaryKey": false,
1161
+ "notNull": true,
1162
+ "default": "now()"
1163
+ }
1164
+ },
1165
+ "indexes": {},
1166
+ "foreignKeys": {
1167
+ "people_invited_by_people_id_fk": {
1168
+ "name": "people_invited_by_people_id_fk",
1169
+ "tableFrom": "people",
1170
+ "tableTo": "people",
1171
+ "columnsFrom": [
1172
+ "invited_by"
1173
+ ],
1174
+ "columnsTo": [
1175
+ "id"
1176
+ ],
1177
+ "onDelete": "set null",
1178
+ "onUpdate": "no action"
1179
+ }
1180
+ },
1181
+ "compositePrimaryKeys": {},
1182
+ "uniqueConstraints": {
1183
+ "people_email": {
1184
+ "name": "people_email",
1185
+ "nullsNotDistinct": false,
1186
+ "columns": [
1187
+ "email"
1188
+ ]
1189
+ },
1190
+ "people_clerk_user_id": {
1191
+ "name": "people_clerk_user_id",
1192
+ "nullsNotDistinct": false,
1193
+ "columns": [
1194
+ "clerk_user_id"
1195
+ ]
1196
+ }
1197
+ },
1198
+ "policies": {},
1199
+ "checkConstraints": {
1200
+ "people_email_lower": {
1201
+ "name": "people_email_lower",
1202
+ "value": "\"people\".\"email\" = lower(\"people\".\"email\")"
1203
+ },
1204
+ "people_role_valid": {
1205
+ "name": "people_role_valid",
1206
+ "value": "\"people\".\"role\" in ('owner', 'admin', 'staff')"
1207
+ },
1208
+ "people_status_valid": {
1209
+ "name": "people_status_valid",
1210
+ "value": "\"people\".\"status\" in ('active', 'pending', 'disabled')"
1211
+ }
1212
+ },
1213
+ "isRLSEnabled": false
1214
+ },
1215
+ "public.price_items": {
1216
+ "name": "price_items",
1217
+ "schema": "",
1218
+ "columns": {
1219
+ "id": {
1220
+ "name": "id",
1221
+ "type": "uuid",
1222
+ "primaryKey": true,
1223
+ "notNull": true,
1224
+ "default": "gen_random_uuid()"
1225
+ },
1226
+ "organisation_id": {
1227
+ "name": "organisation_id",
1228
+ "type": "uuid",
1229
+ "primaryKey": false,
1230
+ "notNull": true
1231
+ },
1232
+ "code": {
1233
+ "name": "code",
1234
+ "type": "text",
1235
+ "primaryKey": false,
1236
+ "notNull": true
1237
+ },
1238
+ "name": {
1239
+ "name": "name",
1240
+ "type": "text",
1241
+ "primaryKey": false,
1242
+ "notNull": true
1243
+ },
1244
+ "unit_amount_cents": {
1245
+ "name": "unit_amount_cents",
1246
+ "type": "integer",
1247
+ "primaryKey": false,
1248
+ "notNull": true
1249
+ },
1250
+ "tax_code": {
1251
+ "name": "tax_code",
1252
+ "type": "text",
1253
+ "primaryKey": false,
1254
+ "notNull": true,
1255
+ "default": "'GST'"
1256
+ },
1257
+ "archived_at": {
1258
+ "name": "archived_at",
1259
+ "type": "timestamp with time zone",
1260
+ "primaryKey": false,
1261
+ "notNull": false
1262
+ },
1263
+ "created_at": {
1264
+ "name": "created_at",
1265
+ "type": "timestamp with time zone",
1266
+ "primaryKey": false,
1267
+ "notNull": true,
1268
+ "default": "now()"
1269
+ }
1270
+ },
1271
+ "indexes": {},
1272
+ "foreignKeys": {
1273
+ "price_items_organisation_id_organisations_id_fk": {
1274
+ "name": "price_items_organisation_id_organisations_id_fk",
1275
+ "tableFrom": "price_items",
1276
+ "tableTo": "organisations",
1277
+ "columnsFrom": [
1278
+ "organisation_id"
1279
+ ],
1280
+ "columnsTo": [
1281
+ "id"
1282
+ ],
1283
+ "onDelete": "no action",
1284
+ "onUpdate": "no action"
1285
+ }
1286
+ },
1287
+ "compositePrimaryKeys": {},
1288
+ "uniqueConstraints": {
1289
+ "price_items_org_id": {
1290
+ "name": "price_items_org_id",
1291
+ "nullsNotDistinct": false,
1292
+ "columns": [
1293
+ "organisation_id",
1294
+ "id"
1295
+ ]
1296
+ },
1297
+ "price_items_org_code": {
1298
+ "name": "price_items_org_code",
1299
+ "nullsNotDistinct": false,
1300
+ "columns": [
1301
+ "organisation_id",
1302
+ "code"
1303
+ ]
1304
+ }
1305
+ },
1306
+ "policies": {},
1307
+ "checkConstraints": {
1308
+ "price_items_tax_code_valid": {
1309
+ "name": "price_items_tax_code_valid",
1310
+ "value": "\"price_items\".\"tax_code\" in ('GST', 'GST_FREE')"
1311
+ }
1312
+ },
1313
+ "isRLSEnabled": false
1314
+ }
1315
+ },
1316
+ "enums": {},
1317
+ "schemas": {},
1318
+ "sequences": {},
1319
+ "roles": {},
1320
+ "policies": {},
1321
+ "views": {},
1322
+ "_meta": {
1323
+ "columns": {},
1324
+ "schemas": {},
1325
+ "tables": {}
1326
+ }
1327
+ }