@arcforgelabs/flow 2026.10.21 → 2026.10.23
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.
- package/README.md +2 -1
- package/VISION.md +40 -9
- package/npm-shrinkwrap.json +2 -414
- package/package.json +6 -1
- package/server/app.js +7 -0
- package/server/core/links.js +166 -0
- package/server/core/outbox.js +129 -0
- package/server/core/queue.js +142 -0
- package/server/core/review.js +92 -0
- package/server/core/secrets.js +74 -0
- package/server/db/migrations/0005_data_spine.sql +99 -0
- package/server/db/migrations/0006_prior_links.sql +18 -0
- package/server/db/migrations/0007_integration_settings.sql +23 -0
- package/server/db/migrations/meta/0005_snapshot.json +2145 -0
- package/server/db/migrations/meta/0006_snapshot.json +2306 -0
- package/server/db/migrations/meta/0007_snapshot.json +2473 -0
- package/server/db/migrations/meta/_journal.json +21 -0
- package/server/db/schema.js +187 -1
- package/server/import/at-start.js +69 -1
- package/server/index.js +28 -8
- package/server/integrations/index.js +9 -3
- package/server/integrations/port.js +101 -9
- package/server/integrations/seazona/index.js +25 -3
- package/server/integrations/setup.js +234 -0
- package/server/integrations/xero/client.js +13 -0
- package/server/integrations/xero/import.js +116 -0
- package/server/integrations/xero/index.js +45 -5
- package/server/integrations/xero/migrations/0004_xero_mirror.sql +96 -0
- package/server/integrations/xero/migrations/meta/_journal.json +7 -0
- package/server/integrations/xero/mirror.js +295 -0
- package/server/integrations/xero/routes.js +26 -1
- package/server/integrations/xero/settings.js +8 -0
- package/server/ui/app-page.js +1 -1
- package/server/ui/app.js +142 -0
- package/server/ui/routes.js +9 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
CREATE TABLE "background_jobs" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"organisation_id" uuid NOT NULL,
|
|
4
|
+
"kind" text NOT NULL,
|
|
5
|
+
"dedupe_key" text DEFAULT '' NOT NULL,
|
|
6
|
+
"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
7
|
+
"state" text DEFAULT 'queued' NOT NULL,
|
|
8
|
+
"run_after" timestamp with time zone DEFAULT now() NOT NULL,
|
|
9
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
10
|
+
"max_attempts" integer DEFAULT 8 NOT NULL,
|
|
11
|
+
"locked_by" text,
|
|
12
|
+
"locked_until" timestamp with time zone,
|
|
13
|
+
"result" jsonb,
|
|
14
|
+
"last_error" text,
|
|
15
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
16
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
17
|
+
CONSTRAINT "background_jobs_state_valid" CHECK (state in ('queued', 'running', 'succeeded', 'failed', 'dead')),
|
|
18
|
+
CONSTRAINT "background_jobs_attempts_valid" CHECK ("background_jobs"."attempts" >= 0 and "background_jobs"."max_attempts" > 0)
|
|
19
|
+
);
|
|
20
|
+
--> statement-breakpoint
|
|
21
|
+
CREATE TABLE "external_links" (
|
|
22
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
23
|
+
"organisation_id" uuid NOT NULL,
|
|
24
|
+
"entity" text NOT NULL,
|
|
25
|
+
"flow_id" uuid NOT NULL,
|
|
26
|
+
"system" text NOT NULL,
|
|
27
|
+
"external_id" text NOT NULL,
|
|
28
|
+
"matched_by" text NOT NULL,
|
|
29
|
+
"state" text NOT NULL,
|
|
30
|
+
"confirmed_by" uuid,
|
|
31
|
+
"confirmed_at" timestamp with time zone,
|
|
32
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
33
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
34
|
+
CONSTRAINT "external_links_org_id" UNIQUE("organisation_id","id"),
|
|
35
|
+
CONSTRAINT "external_links_entity_valid" CHECK (entity in ('contact', 'price_item', 'obligation', 'invoice', 'payment', 'credit_note')),
|
|
36
|
+
CONSTRAINT "external_links_matched_by_valid" CHECK (matched_by in ('created_by_flow', 'exact_id', 'imported', 'name', 'person')),
|
|
37
|
+
CONSTRAINT "external_links_state_valid" CHECK (state in ('active', 'proposed', 'superseded')),
|
|
38
|
+
CONSTRAINT "external_links_name_needs_person" CHECK ("external_links"."matched_by" <> 'name' or "external_links"."state" <> 'active' or "external_links"."confirmed_at" is not null)
|
|
39
|
+
);
|
|
40
|
+
--> statement-breakpoint
|
|
41
|
+
CREATE TABLE "outbox" (
|
|
42
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
43
|
+
"organisation_id" uuid NOT NULL,
|
|
44
|
+
"system" text NOT NULL,
|
|
45
|
+
"action" text NOT NULL,
|
|
46
|
+
"entity" text NOT NULL,
|
|
47
|
+
"flow_id" uuid NOT NULL,
|
|
48
|
+
"idempotency_key" text NOT NULL,
|
|
49
|
+
"request" jsonb NOT NULL,
|
|
50
|
+
"state" text DEFAULT 'pending' NOT NULL,
|
|
51
|
+
"external_id" text,
|
|
52
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
53
|
+
"last_error" text,
|
|
54
|
+
"created_by" text NOT NULL,
|
|
55
|
+
"sent_at" timestamp with time zone,
|
|
56
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
57
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
58
|
+
CONSTRAINT "outbox_org_id" UNIQUE("organisation_id","id"),
|
|
59
|
+
CONSTRAINT "outbox_idempotency_key" UNIQUE("idempotency_key"),
|
|
60
|
+
CONSTRAINT "outbox_state_valid" CHECK (state in ('pending', 'sending', 'ambiguous', 'sent', 'failed', 'cancelled')),
|
|
61
|
+
CONSTRAINT "outbox_sent_has_id" CHECK ("outbox"."state" <> 'sent' or "outbox"."external_id" is not null)
|
|
62
|
+
);
|
|
63
|
+
--> statement-breakpoint
|
|
64
|
+
CREATE TABLE "review_items" (
|
|
65
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
66
|
+
"organisation_id" uuid NOT NULL,
|
|
67
|
+
"kind" text NOT NULL,
|
|
68
|
+
"entity" text NOT NULL,
|
|
69
|
+
"flow_id" uuid NOT NULL,
|
|
70
|
+
"systems" text[] DEFAULT '{}'::text[] NOT NULL,
|
|
71
|
+
"evidence" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
72
|
+
"money_at_risk_cents" bigint DEFAULT 0 NOT NULL,
|
|
73
|
+
"state" text DEFAULT 'open' NOT NULL,
|
|
74
|
+
"seen_count" integer DEFAULT 1 NOT NULL,
|
|
75
|
+
"resolution" text,
|
|
76
|
+
"note" text,
|
|
77
|
+
"resolved_by" text,
|
|
78
|
+
"resolved_at" timestamp with time zone,
|
|
79
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
80
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
81
|
+
CONSTRAINT "review_items_org_id" UNIQUE("organisation_id","id"),
|
|
82
|
+
CONSTRAINT "review_items_state_valid" CHECK (state in ('open', 'resolved', 'dismissed')),
|
|
83
|
+
CONSTRAINT "review_items_money_not_negative" CHECK ("review_items"."money_at_risk_cents" >= 0),
|
|
84
|
+
CONSTRAINT "review_items_closed_has_resolution" CHECK ("review_items"."state" = 'open' or ("review_items"."resolution" is not null and "review_items"."resolved_by" is not null and "review_items"."resolved_at" is not null))
|
|
85
|
+
);
|
|
86
|
+
--> statement-breakpoint
|
|
87
|
+
ALTER TABLE "background_jobs" ADD CONSTRAINT "background_jobs_organisation_id_organisations_id_fk" FOREIGN KEY ("organisation_id") REFERENCES "public"."organisations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
88
|
+
ALTER TABLE "external_links" ADD CONSTRAINT "external_links_organisation_id_organisations_id_fk" FOREIGN KEY ("organisation_id") REFERENCES "public"."organisations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
89
|
+
ALTER TABLE "external_links" ADD CONSTRAINT "external_links_confirmed_by_people_id_fk" FOREIGN KEY ("confirmed_by") REFERENCES "public"."people"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
90
|
+
ALTER TABLE "outbox" ADD CONSTRAINT "outbox_organisation_id_organisations_id_fk" FOREIGN KEY ("organisation_id") REFERENCES "public"."organisations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
91
|
+
ALTER TABLE "review_items" ADD CONSTRAINT "review_items_organisation_id_organisations_id_fk" FOREIGN KEY ("organisation_id") REFERENCES "public"."organisations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
92
|
+
CREATE UNIQUE INDEX "background_jobs_one_open" ON "background_jobs" USING btree ("organisation_id","kind","dedupe_key") WHERE state in ('queued', 'running');--> statement-breakpoint
|
|
93
|
+
CREATE INDEX "background_jobs_due" ON "background_jobs" USING btree ("state","run_after");--> statement-breakpoint
|
|
94
|
+
CREATE UNIQUE INDEX "external_links_active_external" ON "external_links" USING btree ("organisation_id","system","entity","external_id") WHERE state = 'active';--> statement-breakpoint
|
|
95
|
+
CREATE UNIQUE INDEX "external_links_active_flow" ON "external_links" USING btree ("organisation_id","system","entity","flow_id") WHERE state = 'active';--> statement-breakpoint
|
|
96
|
+
CREATE INDEX "external_links_flow" ON "external_links" USING btree ("organisation_id","entity","flow_id");--> statement-breakpoint
|
|
97
|
+
CREATE INDEX "outbox_pending" ON "outbox" USING btree ("system","state","created_at");--> statement-breakpoint
|
|
98
|
+
CREATE UNIQUE INDEX "review_items_one_open" ON "review_items" USING btree ("organisation_id","kind","entity","flow_id") WHERE state = 'open';--> statement-breakpoint
|
|
99
|
+
CREATE INDEX "review_items_queue" ON "review_items" USING btree ("organisation_id","state","money_at_risk_cents");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CREATE TABLE "prior_links" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"organisation_id" uuid NOT NULL,
|
|
4
|
+
"source_system" text NOT NULL,
|
|
5
|
+
"source_job_ref" text NOT NULL,
|
|
6
|
+
"system" text NOT NULL,
|
|
7
|
+
"external_id" text NOT NULL,
|
|
8
|
+
"external_number" text,
|
|
9
|
+
"matched_by" text NOT NULL,
|
|
10
|
+
"matched_at" timestamp with time zone,
|
|
11
|
+
"origin" text NOT NULL,
|
|
12
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
13
|
+
CONSTRAINT "prior_links_matched_by_valid" CHECK (matched_by in ('person', 'imported'))
|
|
14
|
+
);
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "prior_links" ADD CONSTRAINT "prior_links_organisation_id_organisations_id_fk" FOREIGN KEY ("organisation_id") REFERENCES "public"."organisations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
17
|
+
CREATE UNIQUE INDEX "prior_links_job" ON "prior_links" USING btree ("organisation_id","source_system","source_job_ref","system");--> statement-breakpoint
|
|
18
|
+
CREATE INDEX "prior_links_external" ON "prior_links" USING btree ("organisation_id","system","external_id");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
CREATE TABLE "integration_setting_events" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"adapter_id" text NOT NULL,
|
|
4
|
+
"kind" text NOT NULL,
|
|
5
|
+
"settings" text[] DEFAULT '{}'::text[] NOT NULL,
|
|
6
|
+
"actor" uuid,
|
|
7
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
8
|
+
CONSTRAINT "integration_setting_events_kind_valid" CHECK (kind in ('turned_on', 'turned_off', 'setting_changed', 'secret_set', 'secret_removed'))
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
CREATE TABLE "integration_settings" (
|
|
12
|
+
"adapter_id" text PRIMARY KEY NOT NULL,
|
|
13
|
+
"enabled" boolean DEFAULT false NOT NULL,
|
|
14
|
+
"config" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
15
|
+
"secrets" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
16
|
+
"updated_by" uuid,
|
|
17
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
18
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
19
|
+
);
|
|
20
|
+
--> statement-breakpoint
|
|
21
|
+
ALTER TABLE "integration_setting_events" ADD CONSTRAINT "integration_setting_events_actor_people_id_fk" FOREIGN KEY ("actor") REFERENCES "public"."people"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
22
|
+
ALTER TABLE "integration_settings" ADD CONSTRAINT "integration_settings_updated_by_people_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."people"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
23
|
+
CREATE INDEX "integration_setting_events_adapter" ON "integration_setting_events" USING btree ("adapter_id","created_at");
|