fix(api): stabilize report pagination + declare real { data, meta } envelope on v1 single/write endpoints (#811)

* fix(reports): stabilize fetchAllRows paging to stop doubled/dropped balances (#790, #791)

PostgREST `.range()` paging is only correct when the underlying query has a
stable TOTAL order. Several aggregating report queries (general ledger, trial
balance, grundbok, supplier/AR ledgers, etc.) paginated without `.order()`, so
on datasets larger than one 1000-row page Postgres could return rows in a
different order between requests — silently DUPLICATING or SKIPPING rows on a
page boundary and doubling or dropping financial totals.

- fetch-all.ts: document the ordering invariant and add an optional
  `dedupeBy` defense-in-depth that drops cross-page duplicates and warns when
  it fires (surfaces a missing `.order()` in logs instead of corrupting money).
- Add a stable `.order()` (line PK or account_number) to every paginated query
  in lib/reports/ and the account-balances route; pass `dedupeBy` on the
  money-aggregating line queries.
- Add fetch-all unit tests and update report test fixtures to carry row ids.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(api): declare the real { data, meta } envelope on v1 single/write/204 endpoints (#794)

The OpenAPI generator derives each endpoint's documented body purely from its
registered `response.success` Zod schema, and that schema is never validated at
runtime — so a route could advertise a shape its handler never sends. #802
fixed this for list endpoints; the same drift was latent on single-resource and
write endpoints, which declared the bare resource schema instead of the
`{ data, meta }` envelope the handlers actually return.

- registry.ts: extend `ResponseMetaSchema` with the optional `audit` block and
  `partial_expansions` list that writes/expansions emit; add the `NoBodyResponse`
  sentinel so 204 DELETE handlers document a bare 204 instead of a phantom 200.
- Wrap every single/write endpoint's `response.success` in `dataEnvelope(...)`
  (or `NoBodyResponse` for 204s) across the v1 routes.
- Add a response-envelope contract test that fails CI if any JSON endpoint
  forgets to wrap its schema, with binary downloads and 204s as the only
  exemptions.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(reports): extend paging dedupeBy to rc-basis-gaps and opening-balances

Address PR review: these two money-aggregating line queries already had the
stable `.order('id')` (so paging was correct) but didn't carry `id` in the
select, so they couldn't use the `dedupeBy` defense-in-depth that general-ledger
and trial-balance got. Select `id` and pass `dedupeBy: r => r.id` so the whole
report layer applies the ordering invariant consistently.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
Jakob Wennberg
2026-06-28 13:42:50 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent ae17b304d7
commit fce6faff2c
103 changed files with 738 additions and 334 deletions
@@ -120,7 +120,8 @@ export async function GET(request: Request) {
query = query.neq('journal_entry_id', obEntryId) query = query.neq('journal_entry_id', obEntryId)
} }
return query.range(from, to) // Stable total order for correct paging (see fetch-all.ts).
return query.order('id', { ascending: true }).range(from, to)
}) })
} catch (err) { } catch (err) {
log.error('period activity lookup failed', { log.error('period activity lookup failed', {
@@ -20,7 +20,7 @@
import { z } from 'zod' import { z } from 'zod'
import type { SupabaseClient } from '@supabase/supabase-js' import type { SupabaseClient } from '@supabase/supabase-js'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period' import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period'
@@ -234,7 +234,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: ComplianceCheckResponse }, response: { success: dataEnvelope(ComplianceCheckResponse) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -16,7 +16,7 @@ import { z } from 'zod'
import { noContent, ok } from '@/lib/api/v1/response' import { noContent, ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { parseExpand } from '@/lib/api/v1/expand' import { parseExpand } from '@/lib/api/v1/expand'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope, NoBodyResponse } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { UpdateCustomerSchema } from '@/lib/api/schemas' import { UpdateCustomerSchema } from '@/lib/api/schemas'
@@ -100,7 +100,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: CustomerDetail }, response: { success: dataEnvelope(CustomerDetail) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -244,7 +244,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: UpdateCustomerSchema }, request: { body: UpdateCustomerSchema },
response: { success: CustomerDetail }, response: { success: dataEnvelope(CustomerDetail) },
}) })
const CUSTOMER_UPDATE_RESPONSE_COLUMNS = CUSTOMER_DETAIL_COLUMNS const CUSTOMER_UPDATE_RESPONSE_COLUMNS = CUSTOMER_DETAIL_COLUMNS
@@ -438,7 +438,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
response: { success: z.object({}) }, response: { success: NoBodyResponse },
}) })
export const DELETE = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const DELETE = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -17,7 +17,7 @@ import { z } from 'zod'
import type { SupabaseClient } from '@supabase/supabase-js' import type { SupabaseClient } from '@supabase/supabase-js'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { CreateCustomerSchema } from '@/lib/api/schemas' import { CreateCustomerSchema } from '@/lib/api/schemas'
@@ -99,7 +99,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: BulkCreateRequest }, request: { body: BulkCreateRequest },
response: { success: BulkCreateResponse }, response: { success: dataEnvelope(BulkCreateResponse) },
}) })
interface ResultItem { interface ResultItem {
@@ -16,7 +16,7 @@ import {
encodeDefaultCursor, encodeDefaultCursor,
parsePaginationParams, parsePaginationParams,
} from '@/lib/api/v1/pagination' } from '@/lib/api/v1/pagination'
import { registerEndpoint, listEnvelope } from '@/lib/api/v1/registry' import { registerEndpoint, listEnvelope, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { CreateCustomerSchema } from '@/lib/api/schemas' import { CreateCustomerSchema } from '@/lib/api/schemas'
@@ -301,7 +301,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: CreateCustomerSchema }, request: { body: CreateCustomerSchema },
response: { success: CustomerCreated }, response: { success: dataEnvelope(CustomerCreated) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -13,7 +13,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { eventBus } from '@/lib/events' import { eventBus } from '@/lib/events'
@@ -77,7 +77,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: DocumentDownloadResponse }, response: { success: dataEnvelope(DocumentDownloadResponse) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -18,7 +18,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { linkToJournalEntry } from '@/lib/core/documents/document-service' import { linkToJournalEntry } from '@/lib/core/documents/document-service'
@@ -71,7 +71,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
request: { body: Body }, request: { body: Body },
response: { success: DocumentLinkedResponse }, response: { success: dataEnvelope(DocumentLinkedResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -31,7 +31,7 @@
import { z } from 'zod' import { z } from 'zod'
import { created } from '@/lib/api/v1/response' import { created } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { import {
@@ -110,7 +110,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
request: { body: MultipartBodySchema, contentType: 'multipart/form-data' }, request: { body: MultipartBodySchema, contentType: 'multipart/form-data' },
response: { success: DocumentUploaded }, response: { success: dataEnvelope(DocumentUploaded) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -20,7 +20,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok, noContent } from '@/lib/api/v1/response' import { ok, noContent } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope, NoBodyResponse } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { UpdateEmployeeSchema } from '@/lib/api/schemas' import { UpdateEmployeeSchema } from '@/lib/api/schemas'
@@ -136,7 +136,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: EmployeeDetail }, response: { success: dataEnvelope(EmployeeDetail) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -201,7 +201,7 @@ registerEndpoint({
request: { body: UpdateEmployeeSchema }, request: { body: UpdateEmployeeSchema },
// Write responses mask personnummer (GDPR Art.5(1)(c)) — only the GET // Write responses mask personnummer (GDPR Art.5(1)(c)) — only the GET
// drill-in returns the full value. Symmetric with the POST response. // drill-in returns the full value. Symmetric with the POST response.
response: { success: EmployeeWriteResponse }, response: { success: dataEnvelope(EmployeeWriteResponse) },
}) })
export const PATCH = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const PATCH = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -402,7 +402,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
response: { success: z.object({}) }, response: { success: NoBodyResponse },
}) })
export const DELETE = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const DELETE = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -24,7 +24,7 @@ import {
encodeDefaultCursor, encodeDefaultCursor,
parsePaginationParams, parsePaginationParams,
} from '@/lib/api/v1/pagination' } from '@/lib/api/v1/pagination'
import { registerEndpoint, listEnvelope } from '@/lib/api/v1/registry' import { registerEndpoint, listEnvelope, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { CreateEmployeeSchema } from '@/lib/api/schemas' import { CreateEmployeeSchema } from '@/lib/api/schemas'
@@ -318,7 +318,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: CreateEmployeeSchema }, request: { body: CreateEmployeeSchema },
response: { success: EmployeeCreated }, response: { success: dataEnvelope(EmployeeCreated) },
}) })
const EMPLOYEE_RESPONSE_COLUMNS = const EMPLOYEE_RESPONSE_COLUMNS =
@@ -11,7 +11,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { closePeriod } from '@/lib/core/bookkeeping/period-service' import { closePeriod } from '@/lib/core/bookkeeping/period-service'
@@ -49,7 +49,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: PeriodClosedResponse }, response: { success: dataEnvelope(PeriodClosedResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -12,7 +12,7 @@
import { z } from 'zod' import { z } from 'zod'
import { accepted } from '@/lib/api/v1/response' import { accepted } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period' import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period'
@@ -59,7 +59,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: false, dryRunSupported: false,
request: { body: Body }, request: { body: Body },
response: { success: RevaluationAccepted }, response: { success: dataEnvelope(RevaluationAccepted) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -8,7 +8,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { lockPeriod } from '@/lib/core/bookkeeping/period-service' import { lockPeriod } from '@/lib/core/bookkeeping/period-service'
@@ -46,7 +46,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: true, reversible: true,
dryRunSupported: false, dryRunSupported: false,
response: { success: PeriodLockedResponse }, response: { success: dataEnvelope(PeriodLockedResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -12,7 +12,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period' import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period'
@@ -56,7 +56,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: false, dryRunSupported: false,
request: { body: Body }, request: { body: Body },
response: { success: OpeningBalancesResponse }, response: { success: dataEnvelope(OpeningBalancesResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -15,7 +15,7 @@
import { z } from 'zod' import { z } from 'zod'
import { accepted } from '@/lib/api/v1/response' import { accepted } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period' import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period'
@@ -62,7 +62,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: YearEndAcceptedResponse }, response: { success: dataEnvelope(YearEndAcceptedResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -21,7 +21,7 @@
import { z } from 'zod' import { z } from 'zod'
import { accepted } from '@/lib/api/v1/response' import { accepted } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { import {
@@ -83,7 +83,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
request: { contentType: 'multipart/form-data' }, request: { contentType: 'multipart/form-data' },
response: { success: BankImportAccepted }, response: { success: dataEnvelope(BankImportAccepted) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -24,7 +24,7 @@
import { z } from 'zod' import { z } from 'zod'
import { accepted } from '@/lib/api/v1/response' import { accepted } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { import {
@@ -94,7 +94,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
request: { contentType: 'multipart/form-data' }, request: { contentType: 'multipart/form-data' },
response: { success: SieImportAccepted }, response: { success: dataEnvelope(SieImportAccepted) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -27,7 +27,7 @@
import { z } from 'zod' import { z } from 'zod'
import { created } from '@/lib/api/v1/response' import { created } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { createCreditNoteJournalEntry } from '@/lib/bookkeeping/invoice-entries' import { createCreditNoteJournalEntry } from '@/lib/bookkeeping/invoice-entries'
@@ -96,7 +96,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
request: { body: CreditNoteRequest }, request: { body: CreditNoteRequest },
response: { success: CreditNoteCreated }, response: { success: dataEnvelope(CreditNoteCreated) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -29,7 +29,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { MarkInvoicePaidSchema } from '@/lib/api/schemas' import { MarkInvoicePaidSchema } from '@/lib/api/schemas'
@@ -99,7 +99,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
request: { body: MarkInvoicePaidSchema }, request: { body: MarkInvoicePaidSchema },
response: { success: InvoiceMarkPaidResponse }, response: { success: dataEnvelope(InvoiceMarkPaidResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -36,7 +36,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { createInvoiceJournalEntry } from '@/lib/bookkeeping/invoice-entries' import { createInvoiceJournalEntry } from '@/lib/bookkeeping/invoice-entries'
@@ -97,7 +97,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
response: { success: InvoiceMarkSentResponse }, response: { success: dataEnvelope(InvoiceMarkSentResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -16,7 +16,7 @@ import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { parseExpand } from '@/lib/api/v1/expand' import { parseExpand } from '@/lib/api/v1/expand'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
@@ -108,7 +108,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: InvoiceDetail }, response: { success: dataEnvelope(InvoiceDetail) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -210,7 +210,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: V1PatchDraftInvoiceSchema }, request: { body: V1PatchDraftInvoiceSchema },
response: { success: InvoiceDetail }, response: { success: dataEnvelope(InvoiceDetail) },
}) })
const INVOICE_PATCH_RESPONSE_COLUMNS = const INVOICE_PATCH_RESPONSE_COLUMNS =
@@ -39,7 +39,7 @@ import { z } from 'zod'
import { renderToBuffer } from '@react-pdf/renderer' import { renderToBuffer } from '@react-pdf/renderer'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { InvoicePDF } from '@/lib/invoices/pdf-template' import { InvoicePDF } from '@/lib/invoices/pdf-template'
@@ -113,7 +113,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
response: { success: InvoiceSendResponse }, response: { success: dataEnvelope(InvoiceSendResponse) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -36,7 +36,7 @@ import { z } from 'zod'
import type { SupabaseClient } from '@supabase/supabase-js' import type { SupabaseClient } from '@supabase/supabase-js'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { CreateInvoiceSchema } from '@/lib/api/schemas' import { CreateInvoiceSchema } from '@/lib/api/schemas'
@@ -128,7 +128,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: BulkCreateRequest }, request: { body: BulkCreateRequest },
response: { success: BulkCreateResponse }, response: { success: dataEnvelope(BulkCreateResponse) },
}) })
interface ResultItem { interface ResultItem {
@@ -23,7 +23,7 @@ import {
parsePaginationParams, parsePaginationParams,
} from '@/lib/api/v1/pagination' } from '@/lib/api/v1/pagination'
import { parseExpand } from '@/lib/api/v1/expand' import { parseExpand } from '@/lib/api/v1/expand'
import { registerEndpoint, listEnvelope } from '@/lib/api/v1/registry' import { registerEndpoint, listEnvelope, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { CreateInvoiceSchema } from '@/lib/api/schemas' import { CreateInvoiceSchema } from '@/lib/api/schemas'
@@ -372,7 +372,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: CreateInvoiceSchema }, request: { body: CreateInvoiceSchema },
response: { success: InvoiceCreated }, response: { success: dataEnvelope(InvoiceCreated) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(
@@ -15,7 +15,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { commitEntry, getNextVoucherNumber } from '@/lib/bookkeeping/engine' import { commitEntry, getNextVoucherNumber } from '@/lib/bookkeeping/engine'
@@ -59,7 +59,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
response: { success: JournalEntryCommitted }, response: { success: dataEnvelope(JournalEntryCommitted) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -16,7 +16,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { checkPeriodLock } from '@/lib/api/v1/check-period-lock' import { checkPeriodLock } from '@/lib/api/v1/check-period-lock'
@@ -76,7 +76,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
request: { body: CorrectJournalEntrySchema }, request: { body: CorrectJournalEntrySchema },
response: { success: JournalEntryCorrected }, response: { success: dataEnvelope(JournalEntryCorrected) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -14,7 +14,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { checkPeriodLock } from '@/lib/api/v1/check-period-lock' import { checkPeriodLock } from '@/lib/api/v1/check-period-lock'
@@ -68,7 +68,7 @@ registerEndpoint({
reversible: false, reversible: false,
dryRunSupported: true, dryRunSupported: true,
request: { body: ReverseRequest }, request: { body: ReverseRequest },
response: { success: JournalEntryReversed }, response: { success: dataEnvelope(JournalEntryReversed) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -7,7 +7,7 @@
import { z } from 'zod' import { z } from 'zod'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
@@ -86,7 +86,7 @@ registerEndpoint({
idempotent: true, idempotent: true,
reversible: false, reversible: false,
dryRunSupported: false, dryRunSupported: false,
response: { success: JournalEntryDetail }, response: { success: dataEnvelope(JournalEntryDetail) },
}) })
export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>( export const GET = withApiV1<{ params: Promise<{ companyId: string; id: string }> }>(
@@ -17,7 +17,7 @@ import { z } from 'zod'
import type { SupabaseClient } from '@supabase/supabase-js' import type { SupabaseClient } from '@supabase/supabase-js'
import { ok } from '@/lib/api/v1/response' import { ok } from '@/lib/api/v1/response'
import { dryRunPreview } from '@/lib/api/v1/dry-run' import { dryRunPreview } from '@/lib/api/v1/dry-run'
import { registerEndpoint } from '@/lib/api/v1/registry' import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period' import { ownsFiscalPeriod } from '@/lib/api/v1/owns-fiscal-period'
@@ -89,7 +89,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: BulkRequest }, request: { body: BulkRequest },
response: { success: BulkResponse }, response: { success: dataEnvelope(BulkResponse) },
}) })
interface ResultItem { interface ResultItem {
@@ -21,7 +21,7 @@ import {
encodeDefaultCursor, encodeDefaultCursor,
parsePaginationParams, parsePaginationParams,
} from '@/lib/api/v1/pagination' } from '@/lib/api/v1/pagination'
import { registerEndpoint, listEnvelope } from '@/lib/api/v1/registry' import { registerEndpoint, listEnvelope, dataEnvelope } from '@/lib/api/v1/registry'
import { withApiV1 } from '@/lib/api/v1/with-api-v1' import { withApiV1 } from '@/lib/api/v1/with-api-v1'
import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors' import { v1ErrorResponse, v1ErrorResponseFromCode } from '@/lib/api/v1/errors'
import { checkPeriodLock } from '@/lib/api/v1/check-period-lock' import { checkPeriodLock } from '@/lib/api/v1/check-period-lock'
@@ -246,7 +246,7 @@ registerEndpoint({
reversible: true, reversible: true,
dryRunSupported: true, dryRunSupported: true,
request: { body: CreateJournalEntrySchema }, request: { body: CreateJournalEntrySchema },
response: { success: JournalEntryDetail }, response: { success: dataEnvelope(JournalEntryDetail) },
}) })
export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>( export const POST = withApiV1<{ params: Promise<{ companyId: string }> }>(

Some files were not shown because too many files have changed in this diff Show More