4c6feea64d
* feat(connect): bank sync through the connector operation, with a per-company canary In connector mode the enable-banking sync no longer pages Enable Banking on the instance: it calls POST /api/connect/bank/sync on the hosted service with the session id it holds and the account, and receives booked, normalized rows plus the raw provider pages to archive. Everything downstream is shared with the direct path (stored external ids computed here from booking_date, amount and the account scope; ingest; archive; balance refresh), so a company that moves to the connector produces byte-identical keys. A 410 from the service maps onto the same SessionExpiredError the direct path throws. bankConnectorMode(companyId) gains CONNECT_BANK_CANARY_COMPANIES: listed companies use the connector even while the installation has its own Enable Banking credentials, which is how hosted Accounted moves its bank sync to Connect a few companies at a time before dropping its keys. The contract package gains the bank sync request/response schemas (2026-09-03). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> * fix(connect): calendar-valid dates, body read inside the timeout, service origin as the default Review follow-ups on #2205. The contract validates date_from, date_to and booking_date with z.iso.date() (2026-02-30 and an empty booking date are refused; the installation derives its stored keys from booking_date). The connector sync reads the response body inside the timeout window so a service that stalls the body cannot hold the sync open. DEFAULT_CONNECT_BASE_URL now names the connector service (connect.accounted.se), which is where the sync operation exists; the hosted app's copy of the connector routes is legacy and hosted Accounted itself sets GNUBOK_CONNECT_URL explicitly. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> --------- Signed-off-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
57 lines
2.5 KiB
TypeScript
57 lines
2.5 KiB
TypeScript
import { describe, it, expect, afterEach, vi } from 'vitest'
|
|
import { getConnectorConfig, isConnectorConfigured } from '../config'
|
|
|
|
afterEach(() => vi.unstubAllEnvs())
|
|
|
|
describe('getConnectorConfig', () => {
|
|
it('is null without a key (hosted, or a self-host without a subscription)', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', '')
|
|
expect(getConnectorConfig()).toBeNull()
|
|
expect(isConnectorConfigured()).toBe(false)
|
|
})
|
|
|
|
it('defaults to the connector service origin and strips trailing slashes from an override', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', 'gnubok_ck_x')
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', '')
|
|
expect(getConnectorConfig()).toEqual({ key: 'gnubok_ck_x', baseUrl: 'https://connect.accounted.se' })
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', 'https://connect.example.se/')
|
|
expect(getConnectorConfig()?.baseUrl).toBe('https://connect.example.se')
|
|
})
|
|
|
|
it('rejects non-https and malformed GNUBOK_CONNECT_URL (fail closed: the key is never sent in plaintext)', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', 'gnubok_ck_x')
|
|
for (const bad of ['http://connect.example.se', 'ftp://connect.example.se', 'not a url', 'connect.example.se']) {
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', bad)
|
|
expect(getConnectorConfig(), bad).toBeNull()
|
|
expect(isConnectorConfigured(), bad).toBe(false)
|
|
}
|
|
})
|
|
|
|
it('strips userinfo, query and fragment from the base URL (status echoes it back)', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', 'gnubok_ck_x')
|
|
for (const [dirty, clean] of [
|
|
['https://user:secret@connect.example.se', 'https://connect.example.se'],
|
|
['https://connect.example.se?token=secret', 'https://connect.example.se'],
|
|
['https://connect.example.se/base#fragment', 'https://connect.example.se/base'],
|
|
['https://user:secret@connect.example.se/base/?token=s#f', 'https://connect.example.se/base'],
|
|
]) {
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', dirty)
|
|
expect(getConnectorConfig()?.baseUrl, dirty).toBe(clean)
|
|
}
|
|
})
|
|
|
|
it('keeps a clean override byte-identical (no surprise normalization)', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', 'gnubok_ck_x')
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', 'https://connect.example.se/base')
|
|
expect(getConnectorConfig()?.baseUrl).toBe('https://connect.example.se/base')
|
|
})
|
|
|
|
it('allows plain http for loopback development hosts only', () => {
|
|
vi.stubEnv('GNUBOK_CONNECTOR_KEY', 'gnubok_ck_x')
|
|
for (const ok of ['http://localhost:3000', 'http://127.0.0.1:3000']) {
|
|
vi.stubEnv('GNUBOK_CONNECT_URL', ok)
|
|
expect(getConnectorConfig()?.baseUrl, ok).toBe(ok)
|
|
}
|
|
})
|
|
})
|