@fayz-ai/plugin-banking-br 0.9.1 → 0.10.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.
package/README.md CHANGED
@@ -23,13 +23,36 @@ Addon scope: it contributes a connector into its host (`plugin-financial`) and
23
23
  surfaces under **Financial → settings → Integrations**. No left-nav entry of its own.
24
24
 
25
25
  ## What it owns
26
- - **DB**: `public.bank_integrations` (connection + credentials) and
27
- `public.bank_integration_sync_log` (run audit). See `src/schema/` + `src/migrations/`.
28
- - **Edge function** (deployed by the app): `supabase/functions/plugbank-sync` — calls
29
- the PlugBank API, normalizes lines, imports into `public.plg_financial_movements`
30
- tagged `external_source='plugbank'` (idempotent via the financial
31
- `uq_financial_movements_external` index).
32
- - **UI**: connect/test/save, fetch a statement, import selected lines, view history.
26
+ - **DB**: none of its own — the connection is a `plg_connections` row and the
27
+ history is `plg_sync_runs` (migration `003_onto_connections`). The legacy
28
+ `bank_integrations` / `bank_integration_sync_log` tables still stand on the
29
+ live pool (with a plaintext `api_token`) until FAY-1360 retires them.
30
+ - **RPC**: `plugbank_import_movements(p_payload jsonb)` — the door the import
31
+ passes through. Takes the tenant from the integration row, never from the
32
+ request body, and is idempotent on the financial plugin's
33
+ `uq_plg_financial_movements_external` index.
34
+ - **Edge function** (declared in `functions[]`, deployed by the app):
35
+ `plugbank-sync` — calls the PlugBank API, normalizes lines, imports through the
36
+ RPC into `public.plg_financial_movements` tagged `external_source='plugbank'`.
37
+ - **Fact**: `financial.movement.imported`, emitted by a trigger on the ledger so
38
+ it exists whoever wrote the row.
39
+ - **UI**: connect/disconnect, fetch a statement, import selected lines, run history.
40
+
41
+ ## Where the credential lives
42
+
43
+ **Today (verified 2026-08-12): still in the pool.** The live pool's
44
+ `bank_integrations.api_token` holds the PlugBank token in plaintext — migration
45
+ `002`, which drops the `api_token` / `cnpj` columns `001` created, is in this
46
+ repo but unapplied there, and the deployed `plugbank-sync` (v6) still reads the
47
+ column. The destination is the Fayz platform's encrypted store, redeemed by the
48
+ edge function per call — that move is FAY-1360, and the redeem path it needs is
49
+ FAY-1389. The reason the columns must go: `bank_integrations` is read from the
50
+ browser under tenant RLS, so any member of the tenant can read them — and a pool
51
+ is one Supabase project serving N tenants, so anything there holding
52
+ `service_role` reads every tenant's at once.
53
+
54
+ If a pool ever stored those values, **rotate them**. `DROP COLUMN` is a catalog
55
+ change; the old bytes leave the heap only at the next table rewrite.
33
56
 
34
57
  ## How it composes with the SDK
35
58
  - Depends on `@fayz-ai/plugin-financial`. Imported lines are reconciled in
@@ -39,11 +62,16 @@ surfaces under **Financial → settings → Integrations**. No left-nav entry of
39
62
  `matched_movement_id`) live in the SDK financial migration `007_reconciliation.sql`.
40
63
 
41
64
  ## Deploy
42
- 1. Apply the SDK financial migration `007_reconciliation.sql` and this plugin's
43
- `src/migrations/001_openbanking.sql`.
65
+ 1. Apply the SDK financial migration `007_reconciliation.sql`, the core
66
+ `027_domain_events.sql` (it ships `plg_emit_event`), then this plugin's
67
+ `001_openbanking.sql` and `002_credential_and_facts.sql`.
44
68
  2. `supabase functions deploy plugbank-sync` with secrets
45
69
  `PLUGBANK_BASE_URL`, plus the standard `SUPABASE_URL` / `SUPABASE_SERVICE_ROLE_KEY`.
70
+ The per-tenant token is **not** a function secret: a secret is per-pool and a
71
+ pool serves N tenants with N different bank accounts.
46
72
  3. Register `createOpenBankingPlugin()` in the app config and enable the
47
73
  financial `reconciliation` module.
48
- 4. (Optional, "runs in backend") schedule a daily `import_transactions` via
49
- `pg_cron` + `pg_net` to the function for hands-off sync.
74
+
75
+ The period picker in the import panel is deliberate, not a missing feature —
76
+ whoever reconciles wants to choose the window. Scheduled pulls belong to the Fayz
77
+ SCHEDULE worker (FAY-1347), which owns the clock for every connector.
@@ -1,3 +1,3 @@
1
- import type { ConnectorDefinition } from '@fayz-ai/core';
1
+ import { type ConnectorDefinition } from '@fayz-ai/core';
2
2
  export declare const openBankingConnector: ConnectorDefinition;
3
3
  //# sourceMappingURL=connectorDef.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectorDef.d.ts","sourceRoot":"","sources":["../../src/connectors/connectorDef.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAoHxD,eAAO,MAAM,oBAAoB,EAAE,mBAkBlC,CAAA"}
1
+ {"version":3,"file":"connectorDef.d.ts","sourceRoot":"","sources":["../../src/connectors/connectorDef.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAA2C,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAiIjG,eAAO,MAAM,oBAAoB,EAAE,mBAsGlC,CAAA"}
@@ -1,12 +1,18 @@
1
- import type { BankIntegration, SaveIntegrationInput, SyncLogEntry, TestConnectionResult, FetchStatementResult, ImportResult, BankLine } from '../types';
1
+ import type { ConnectionConfig, SyncRun } from '@fayz-ai/core';
2
+ import type { BankIntegration, SaveIntegrationInput, BankSyncRun, FetchStatementResult, ImportResult, BankLine } from '../types';
3
+ export declare const PLUGBANK_CONNECTOR_ID = "plugbank";
4
+ export declare function toIntegration(connection: ConnectionConfig): BankIntegration;
5
+ /**
6
+ * The audit row, read as the connector contract's SyncRun. The three facts a
7
+ * MANUAL statement import has and a generic run does not — the period the
8
+ * operator picked, and the duplicates a re-import of that period produces by
9
+ * design — live in `stats`, which is the column that exists for exactly this.
10
+ */
11
+ export declare function toSyncRun(run: SyncRun): BankSyncRun;
2
12
  export interface OpenBankingProvider {
3
13
  getIntegration(bankAccountId?: string): Promise<BankIntegration | null>;
4
- saveIntegration(input: SaveIntegrationInput): Promise<BankIntegration>;
5
- testConnection(input: {
6
- apiToken: string;
7
- cnpj: string;
8
- environment?: string;
9
- }): Promise<TestConnectionResult>;
14
+ saveIntegration(input?: SaveIntegrationInput): Promise<BankIntegration>;
15
+ disconnect(bankAccountId?: string): Promise<void>;
10
16
  fetchStatement(input: {
11
17
  integrationId: string;
12
18
  from: string;
@@ -19,7 +25,7 @@ export interface OpenBankingProvider {
19
25
  to: string;
20
26
  lines: BankLine[];
21
27
  }): Promise<ImportResult>;
22
- getSyncLog(integrationId: string): Promise<SyncLogEntry[]>;
28
+ getSyncRuns(bankAccountId?: string): Promise<BankSyncRun[]>;
23
29
  }
24
30
  export declare function createOpenBankingProvider(): OpenBankingProvider;
25
31
  //# sourceMappingURL=supabase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,eAAe,EAAE,oBAAoB,EAAE,YAAY,EACnD,oBAAoB,EAAE,oBAAoB,EAAE,YAAY,EAAE,QAAQ,EACnE,MAAM,UAAU,CAAA;AAuBjB,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;IACvE,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACtE,cAAc,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC9G,cAAc,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACzG,kBAAkB,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACh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AAO,CAAC,YAAY,CAAC,CAAA;IAChJ,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;CAC5D;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CA2D/D"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PluginManifest } from '@fayz-ai/core';
2
2
  export { createOpenBankingProvider } from './data/supabase';
3
3
  export { openBankingConnector } from './connectors/connectorDef';
4
+ export { buildBankingDomainEvents, MOVEMENT_IMPORTED_FIELDS } from './lib/banking-events';
4
5
  export * from './schema';
5
6
  export * from './types';
6
7
  export declare function createOpenBankingPlugin(): PluginManifest;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAKvB,wBAAgB,uBAAuB,IAAI,cAAc,CAaxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAKnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AACzF,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAKvB,wBAAgB,uBAAuB,IAAI,cAAc,CAqFxD"}