@happyvertical/smrt-commerce 0.62.4 → 0.62.6
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/AGENTS.md +1 -0
- package/agents/accounting-connection.md +76 -0
- package/agents/accounting-live-gate.md +40 -0
- package/agents/accounting-mapping.md +60 -0
- package/agents/accounting-payment-sync.md +76 -0
- package/agents/ordinary-accounting.md +3 -0
- package/dist/accounting-connection.d.ts +179 -0
- package/dist/accounting-connection.d.ts.map +1 -0
- package/dist/accounting-live-gate.d.ts +50 -0
- package/dist/accounting-live-gate.d.ts.map +1 -0
- package/dist/accounting-mapping.d.ts +189 -0
- package/dist/accounting-mapping.d.ts.map +1 -0
- package/dist/accounting-payment-sync.d.ts +233 -0
- package/dist/accounting-payment-sync.d.ts.map +1 -0
- package/dist/chunks/{InvoiceCollection-Cc-fJrHy.js → InvoiceCollection-xooQnUwq.js} +10 -10
- package/dist/chunks/{InvoiceCollection-Cc-fJrHy.js.map → InvoiceCollection-xooQnUwq.js.map} +1 -1
- package/dist/chunks/{allocation-integrity-CvXQm3wK.js → allocation-integrity-C4SZJcao.js} +6 -6
- package/dist/chunks/{allocation-integrity-CvXQm3wK.js.map → allocation-integrity-C4SZJcao.js.map} +1 -1
- package/dist/chunks/{contract-money-BoKHNfV6.js → contract-money-ATacxU6t.js} +4 -7
- package/dist/chunks/{contract-money-BoKHNfV6.js.map → contract-money-ATacxU6t.js.map} +1 -1
- package/dist/chunks/{invoice-posting-DlR_-TG1.js → invoice-posting-CDfxug3Q.js} +4 -5
- package/dist/chunks/{invoice-posting-DlR_-TG1.js.map → invoice-posting-CDfxug3Q.js.map} +1 -1
- package/dist/chunks/retention-accounting-BA4wXUQc.js +8710 -0
- package/dist/chunks/retention-accounting-BA4wXUQc.js.map +1 -0
- package/dist/chunks/{tenant-money-barrier-Bmu4YiID.js → tenant-money-barrier-BdyXIVT5.js} +3 -3
- package/dist/chunks/{tenant-money-barrier-Bmu4YiID.js.map → tenant-money-barrier-BdyXIVT5.js.map} +1 -1
- package/dist/collections/AccountingConnectionCollection.d.ts +27 -0
- package/dist/collections/AccountingConnectionCollection.d.ts.map +1 -0
- package/dist/collections/AccountingMappingCollection.d.ts +24 -0
- package/dist/collections/AccountingMappingCollection.d.ts.map +1 -0
- package/dist/collections/AccountingSyncRecordCollections.d.ts +27 -0
- package/dist/collections/AccountingSyncRecordCollections.d.ts.map +1 -0
- package/dist/collections/index.d.ts +3 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1532 -21
- package/dist/index.js.map +1 -1
- package/dist/invoice-accounting-sync.d.ts +6 -0
- package/dist/invoice-accounting-sync.d.ts.map +1 -1
- package/dist/invoices.js +1 -1
- package/dist/manifest.json +6303 -3740
- package/dist/models/AccountingConnection.d.ts +101 -0
- package/dist/models/AccountingConnection.d.ts.map +1 -0
- package/dist/models/AccountingMapping.d.ts +85 -0
- package/dist/models/AccountingMapping.d.ts.map +1 -0
- package/dist/models/AccountingSyncRecords.d.ts +95 -0
- package/dist/models/AccountingSyncRecords.d.ts.map +1 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/ordinary-accounting.d.ts +1 -0
- package/dist/ordinary-accounting.d.ts.map +1 -1
- package/dist/recipes.d.ts +1 -1
- package/dist/retention-accounting.d.ts +1 -0
- package/dist/retention-accounting.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +1327 -99
- package/dist/smrt-knowledge.okf.md +55 -23
- package/package.json +15 -15
- package/dist/chunks/ContractLineItemCollection-BKHy-nR8.js +0 -260
- package/dist/chunks/ContractLineItemCollection-BKHy-nR8.js.map +0 -1
- package/dist/chunks/DocumentTaxCollection-BRebznXF.js +0 -4649
- package/dist/chunks/DocumentTaxCollection-BRebznXF.js.map +0 -1
- package/dist/chunks/TaxCodeCollection-BBqCugs5.js +0 -155
- package/dist/chunks/TaxCodeCollection-BBqCugs5.js.map +0 -1
- package/dist/chunks/TaxComponentCollection-BHJjbQxq.js +0 -134
- package/dist/chunks/TaxComponentCollection-BHJjbQxq.js.map +0 -1
- package/dist/chunks/credit-allocation-yspz0Lab.js +0 -121
- package/dist/chunks/credit-allocation-yspz0Lab.js.map +0 -1
- package/dist/chunks/retention-accounting-D0KzSw3f.js +0 -3069
- package/dist/chunks/retention-accounting-D0KzSw3f.js.map +0 -1
- package/dist/chunks/retention-accounting-internal-DNxLLVvK.js +0 -30
- package/dist/chunks/retention-accounting-internal-DNxLLVvK.js.map +0 -1
- package/dist/chunks/units-8ElbjVZK.js +0 -60
- package/dist/chunks/units-8ElbjVZK.js.map +0 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounting mapping commands and customer resolution (#5137).
|
|
3
|
+
*
|
|
4
|
+
* Mapping records are scoped by tenant, provider, realm and environment. They
|
|
5
|
+
* give the sync functions what an app would otherwise hand-roll: the provider
|
|
6
|
+
* customer id, and the {@link FrozenQuickBooksTaxMapping} (item, tax code and
|
|
7
|
+
* tax-rate references per line and component). A caller passes only the tenant
|
|
8
|
+
* and invoice; the realm and environment come from the tenant's
|
|
9
|
+
* {@link AccountingConnection}.
|
|
10
|
+
*
|
|
11
|
+
* Customer resolution never silently creates a duplicate: use the mapping,
|
|
12
|
+
* else find in the provider, else (only when nothing matches) create. An
|
|
13
|
+
* ambiguous match is returned for an operator to confirm.
|
|
14
|
+
*
|
|
15
|
+
* See `agents/accounting-mapping.md`.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
20
|
+
import { type AccountingMappingScope } from './collections/AccountingMappingCollection.js';
|
|
21
|
+
import type { QuickBooksFrozenInvoiceMapping } from './invoice-accounting-sync.js';
|
|
22
|
+
import { type AccountingMapping, type AccountingMappingKind } from './models/AccountingMapping.js';
|
|
23
|
+
export type { AccountingMappingScope } from './collections/AccountingMappingCollection.js';
|
|
24
|
+
/** Why a mapping command refused. */
|
|
25
|
+
export type AccountingMappingErrorCode = 'INVALID_INPUT' | 'NOT_CONNECTED' | 'MAPPING_INCOMPLETE' | 'CUSTOMER_NEEDS_CONFIRMATION' | 'CUSTOMER_NOT_A_CANDIDATE';
|
|
26
|
+
/** A required mapping that is missing. */
|
|
27
|
+
export interface MissingAccountingMapping {
|
|
28
|
+
readonly kind: AccountingMappingKind;
|
|
29
|
+
readonly localId: string;
|
|
30
|
+
}
|
|
31
|
+
/** Typed refusal from an accounting-mapping command. */
|
|
32
|
+
export declare class AccountingMappingError extends Error {
|
|
33
|
+
readonly code: AccountingMappingErrorCode;
|
|
34
|
+
readonly missing: readonly MissingAccountingMapping[];
|
|
35
|
+
constructor(code: AccountingMappingErrorCode, message: string, missing?: readonly MissingAccountingMapping[]);
|
|
36
|
+
}
|
|
37
|
+
/** Ordered provider tax rates of a `tax_code` mapping, for compound tax. */
|
|
38
|
+
export interface AccountingTaxCodeDetails {
|
|
39
|
+
readonly taxComponents?: readonly {
|
|
40
|
+
readonly taxRateRef: string;
|
|
41
|
+
readonly compound: boolean;
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The scope of the tenant's connected company. A tenant that is not connected
|
|
46
|
+
* (or must reconnect) has no scope: its mappings are not used.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getAccountingMappingScope(deps: {
|
|
49
|
+
db: DatabaseInterface;
|
|
50
|
+
}, tenantId: string): Promise<AccountingMappingScope>;
|
|
51
|
+
/** Input of {@link setAccountingMapping}. */
|
|
52
|
+
export interface SetAccountingMappingInput {
|
|
53
|
+
readonly kind: AccountingMappingKind;
|
|
54
|
+
readonly localId: string;
|
|
55
|
+
readonly externalId: string;
|
|
56
|
+
readonly externalName?: string;
|
|
57
|
+
/** For `tax_code`: the ordered provider tax rates (compound tax). */
|
|
58
|
+
readonly details?: AccountingTaxCodeDetails;
|
|
59
|
+
readonly confirmedBy?: string;
|
|
60
|
+
readonly now?: Date;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create or replace the mapping for one local key in a scope. Reactivates an
|
|
64
|
+
* invalidated mapping with the new reference.
|
|
65
|
+
*/
|
|
66
|
+
export declare function setAccountingMapping(deps: {
|
|
67
|
+
db: DatabaseInterface;
|
|
68
|
+
}, scope: AccountingMappingScope, input: SetAccountingMappingInput): Promise<AccountingMapping>;
|
|
69
|
+
/** Remove one mapping (an operator unlinking a record). */
|
|
70
|
+
export declare function removeAccountingMapping(deps: {
|
|
71
|
+
db: DatabaseInterface;
|
|
72
|
+
}, scope: AccountingMappingScope, kind: AccountingMappingKind, localId: string): Promise<boolean>;
|
|
73
|
+
/** The active mappings in a scope, optionally of one kind. */
|
|
74
|
+
export declare function listAccountingMappings(deps: {
|
|
75
|
+
db: DatabaseInterface;
|
|
76
|
+
}, scope: AccountingMappingScope, kind?: AccountingMappingKind): Promise<AccountingMapping[]>;
|
|
77
|
+
/** The active provider id for one local key, or `null`. */
|
|
78
|
+
export declare function getAccountingMapping(deps: {
|
|
79
|
+
db: DatabaseInterface;
|
|
80
|
+
}, scope: AccountingMappingScope, kind: AccountingMappingKind, localId: string): Promise<AccountingMapping | null>;
|
|
81
|
+
/**
|
|
82
|
+
* Mark a tenant's active mappings that do not belong to `keep` as invalidated.
|
|
83
|
+
* Called when the connection is rebound to another company or environment; the
|
|
84
|
+
* rows stay for history but are never used (lookups are also scope-keyed).
|
|
85
|
+
*/
|
|
86
|
+
export declare function invalidateAccountingMappingsOutside(deps: {
|
|
87
|
+
db: DatabaseInterface;
|
|
88
|
+
}, keep: AccountingMappingScope, at?: Date): Promise<number>;
|
|
89
|
+
/** Input of {@link buildFrozenInvoiceMapping}. */
|
|
90
|
+
export interface BuildFrozenInvoiceMappingInput {
|
|
91
|
+
readonly db: DatabaseInterface;
|
|
92
|
+
readonly tenantId: string;
|
|
93
|
+
/** The frozen invoice or credit note to map. */
|
|
94
|
+
readonly invoiceId: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build the sync mapping for one invoice or credit note from the tenant's
|
|
98
|
+
* mapping records, in the company and environment of its connection, so sync
|
|
99
|
+
* callers pass only the tenant and document. Throws `MAPPING_INCOMPLETE`
|
|
100
|
+
* listing every missing mapping (never a guess), so a UI can ask for them all.
|
|
101
|
+
*
|
|
102
|
+
* Sets `customerRef` from the customer mapping; the sync uses it instead of the
|
|
103
|
+
* flat, unscoped `Invoice.customerExternalId`.
|
|
104
|
+
*/
|
|
105
|
+
export declare function buildFrozenInvoiceMapping(input: BuildFrozenInvoiceMappingInput): Promise<QuickBooksFrozenInvoiceMapping>;
|
|
106
|
+
/** A provider customer that may be the commerce customer. */
|
|
107
|
+
export interface AccountingCustomerCandidate {
|
|
108
|
+
readonly externalId: string;
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly email?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The provider's customer lookup and creation (happyvertical/sdk#1539: customer
|
|
114
|
+
* find and find-or-create). The host adapts the SDK to this port; smrt tests use
|
|
115
|
+
* fakes.
|
|
116
|
+
*/
|
|
117
|
+
export interface AccountingCustomerDirectory {
|
|
118
|
+
/** Customers matching the name or email, any number. */
|
|
119
|
+
find(query: {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly email?: string;
|
|
122
|
+
}): Promise<readonly AccountingCustomerCandidate[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Create the customer. `requestId` is stable per (customer, realm,
|
|
125
|
+
* environment) so a retry cannot create a second one.
|
|
126
|
+
*/
|
|
127
|
+
create(input: {
|
|
128
|
+
readonly name: string;
|
|
129
|
+
readonly email?: string;
|
|
130
|
+
readonly requestId: string;
|
|
131
|
+
}): Promise<{
|
|
132
|
+
readonly externalId: string;
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
/** The commerce customer as the provider should see it. */
|
|
136
|
+
export interface AccountingCustomerFacts {
|
|
137
|
+
readonly customerId: string;
|
|
138
|
+
readonly name: string;
|
|
139
|
+
readonly email?: string;
|
|
140
|
+
}
|
|
141
|
+
/** Outcome of {@link resolveAccountingCustomer}. */
|
|
142
|
+
export type AccountingCustomerResolution = {
|
|
143
|
+
readonly status: 'mapped';
|
|
144
|
+
readonly externalId: string;
|
|
145
|
+
/** `mapping` was already there; `found` linked a single exact match; `created` made a new one. */
|
|
146
|
+
readonly source: 'mapping' | 'found' | 'created';
|
|
147
|
+
} | {
|
|
148
|
+
readonly status: 'needs_confirmation';
|
|
149
|
+
/** Operator must pick one, or explicitly choose to create a new customer. */
|
|
150
|
+
readonly candidates: readonly AccountingCustomerCandidate[];
|
|
151
|
+
};
|
|
152
|
+
/** Input of {@link resolveAccountingCustomer}. */
|
|
153
|
+
export interface ResolveAccountingCustomerInput {
|
|
154
|
+
readonly db: DatabaseInterface;
|
|
155
|
+
readonly tenantId: string;
|
|
156
|
+
readonly customer: AccountingCustomerFacts;
|
|
157
|
+
readonly directory: AccountingCustomerDirectory;
|
|
158
|
+
readonly confirmedBy?: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolve the provider customer for a commerce customer, in the tenant's
|
|
162
|
+
* connected company.
|
|
163
|
+
*
|
|
164
|
+
* 1. An active mapping wins (no provider call).
|
|
165
|
+
* 2. Otherwise look the customer up. Exactly one match with the same email
|
|
166
|
+
* (or, without an email, the same name) is linked and recorded.
|
|
167
|
+
* 3. Several matches, or a single match that agrees on neither email nor name,
|
|
168
|
+
* return `needs_confirmation` and change nothing.
|
|
169
|
+
* 4. No match creates the customer (stable request id) and records it.
|
|
170
|
+
*
|
|
171
|
+
* Never silently creates a duplicate: the lookup always precedes a create, and
|
|
172
|
+
* an ambiguous lookup stops. Confirm with {@link confirmAccountingCustomer}.
|
|
173
|
+
*/
|
|
174
|
+
export declare function resolveAccountingCustomer(input: ResolveAccountingCustomerInput): Promise<AccountingCustomerResolution>;
|
|
175
|
+
/** Input of {@link confirmAccountingCustomer}. */
|
|
176
|
+
export interface ConfirmAccountingCustomerInput extends ResolveAccountingCustomerInput {
|
|
177
|
+
/**
|
|
178
|
+
* The operator's decision: link this provider customer (it must still be
|
|
179
|
+
* among the provider's matches), or `'create'` a new one on purpose.
|
|
180
|
+
*/
|
|
181
|
+
readonly choice: {
|
|
182
|
+
readonly externalId: string;
|
|
183
|
+
} | 'create';
|
|
184
|
+
}
|
|
185
|
+
/** Record an operator's decision on an ambiguous customer match. */
|
|
186
|
+
export declare function confirmAccountingCustomer(input: ConfirmAccountingCustomerInput): Promise<Extract<AccountingCustomerResolution, {
|
|
187
|
+
status: 'mapped';
|
|
188
|
+
}>>;
|
|
189
|
+
//# sourceMappingURL=accounting-mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounting-mapping.d.ts","sourceRoot":"","sources":["../src/accounting-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAI7E,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,8CAA8C,CAAC;AAGtD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAE3B,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AAE3F,qCAAqC;AACrC,MAAM,MAAM,0BAA0B,GAClC,eAAe,GACf,eAAe,GACf,oBAAoB,GACpB,6BAA6B,GAC7B,0BAA0B,CAAC;AAE/B,0CAA0C;AAC1C,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,wDAAwD;AACxD,qBAAa,sBAAuB,SAAQ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,uBAAuB,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;IAChD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,4BAA4B,CAAC,CAgEvC;AAED,kDAAkD;AAClD,MAAM,WAAW,8BACf,SAAQ,8BAA8B;IACtC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,CAAC;CAC7D;AAED,oEAAoE;AACpE,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,OAAO,CAAC,4BAA4B,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,CA8CtE"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment sync to the accounting provider, readback of ordinary frozen
|
|
3
|
+
* invoices, and the bounded batch entry points an app job calls (#5139).
|
|
4
|
+
*
|
|
5
|
+
* - {@link syncPaymentToAccounting} pushes one recorded payment, applied to its
|
|
6
|
+
* synced invoice(s) and deposited to the mapped clearing account, exactly
|
|
7
|
+
* once: the request id is persisted before the push, an unknown outcome stops
|
|
8
|
+
* and waits for {@link reconcileAccountingPaymentSync}, as the invoice path.
|
|
9
|
+
* - {@link readbackInvoice} reads the provider document, stores the projection
|
|
10
|
+
* and a status (`in_step` | `drift` | `needs_reconciliation`), including
|
|
11
|
+
* payments recorded only in the provider.
|
|
12
|
+
* - {@link syncPending} and {@link readbackDue} take a tenant and a bound, so an
|
|
13
|
+
* app job only schedules and locks.
|
|
14
|
+
*
|
|
15
|
+
* Provider payment creation (happyvertical/sdk#1540) and invoice readback are
|
|
16
|
+
* injected ports; smrt never calls the provider SDK for them directly. See
|
|
17
|
+
* `agents/accounting-payment-sync.md`.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
import type { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
22
|
+
import { type AccountingCustomerDirectory, type AccountingCustomerFacts } from './accounting-mapping.js';
|
|
23
|
+
import { type SyncFrozenInvoiceToAccountingInput } from './invoice-accounting-sync.js';
|
|
24
|
+
import { type AccountingPaymentSync, type AccountingReadbackStatus } from './models/AccountingSyncRecords.js';
|
|
25
|
+
import { projectQuickBooksPilotEvidence, type QuickBooksPilotInvoiceEvidence } from './quickbooks-pilot-evidence.js';
|
|
26
|
+
/** Why a payment sync or readback command refused. */
|
|
27
|
+
export type AccountingPaymentSyncErrorCode = 'PAYMENT_NOT_SYNCABLE' | 'INVOICE_NOT_SYNCED' | 'SYNC_IN_PROGRESS' | 'RECONCILIATION_REQUIRED' | 'INVALID_INPUT';
|
|
28
|
+
/** Typed refusal from a payment sync or readback command. */
|
|
29
|
+
export declare class AccountingPaymentSyncError extends Error {
|
|
30
|
+
readonly code: AccountingPaymentSyncErrorCode;
|
|
31
|
+
constructor(code: AccountingPaymentSyncErrorCode, message: string);
|
|
32
|
+
}
|
|
33
|
+
/** The exact facts pushed for one payment. */
|
|
34
|
+
export interface AccountingPaymentRequest {
|
|
35
|
+
/** Stable provider idempotency id, persisted before the push. */
|
|
36
|
+
readonly requestId: string;
|
|
37
|
+
readonly payloadHash: string;
|
|
38
|
+
readonly realmId: string;
|
|
39
|
+
readonly environment: 'sandbox' | 'production';
|
|
40
|
+
/** Local payment id. */
|
|
41
|
+
readonly paymentId: string;
|
|
42
|
+
/** Provider customer id from the mapping. */
|
|
43
|
+
readonly customerExternalId: string;
|
|
44
|
+
/** Provider clearing/deposit account id from the mapping. */
|
|
45
|
+
readonly depositAccountRef: string;
|
|
46
|
+
readonly currency: string;
|
|
47
|
+
/** Payment amount in minor units; equals the sum of the applications. */
|
|
48
|
+
readonly amountMinor: number;
|
|
49
|
+
readonly paidAt: Date;
|
|
50
|
+
/** The rail's transaction reference (for example a Stripe charge id). */
|
|
51
|
+
readonly transactionId?: string;
|
|
52
|
+
/** The synced invoices the payment is applied to. */
|
|
53
|
+
readonly applications: readonly {
|
|
54
|
+
readonly invoiceId: string;
|
|
55
|
+
readonly invoiceExternalId: string;
|
|
56
|
+
readonly amountMinor: number;
|
|
57
|
+
}[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Provider payment creation (happyvertical/sdk#1540). `create` must treat
|
|
61
|
+
* `requestId` as an idempotency key. Throw with `outcome: 'rejected'` when the
|
|
62
|
+
* provider definitely refused; any other failure leaves the outcome unknown.
|
|
63
|
+
*/
|
|
64
|
+
export interface AccountingPaymentPort {
|
|
65
|
+
create(request: AccountingPaymentRequest): Promise<{
|
|
66
|
+
readonly externalId: string;
|
|
67
|
+
readonly syncedAt: Date;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The provider's invoice document with its linked transactions, read in full
|
|
72
|
+
* (same shape the pilot's fixture evidence uses, for any environment).
|
|
73
|
+
*/
|
|
74
|
+
export type AccountingInvoiceEvidence = Omit<QuickBooksPilotInvoiceEvidence, 'environment'> & {
|
|
75
|
+
readonly environment: 'sandbox' | 'production';
|
|
76
|
+
};
|
|
77
|
+
/** Reads one provider invoice and all its linked transactions. */
|
|
78
|
+
export interface AccountingInvoiceReader {
|
|
79
|
+
readInvoice(externalId: string): Promise<AccountingInvoiceEvidence>;
|
|
80
|
+
}
|
|
81
|
+
/** Input of {@link syncPaymentToAccounting}. */
|
|
82
|
+
export interface SyncPaymentToAccountingInput {
|
|
83
|
+
readonly db: DatabaseInterface;
|
|
84
|
+
/** Must be the active tenant. */
|
|
85
|
+
readonly tenantId: string;
|
|
86
|
+
readonly paymentId: string;
|
|
87
|
+
readonly payments: AccountingPaymentPort;
|
|
88
|
+
/** The provider, so the live-mode gate can see its environment. */
|
|
89
|
+
readonly provider?: object;
|
|
90
|
+
}
|
|
91
|
+
/** Outcome of a payment push. */
|
|
92
|
+
export interface AccountingPaymentSyncResult {
|
|
93
|
+
readonly status: 'synced' | 'unchanged';
|
|
94
|
+
readonly externalId: string;
|
|
95
|
+
readonly requestId: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Push one recorded payment to the provider exactly once.
|
|
99
|
+
*
|
|
100
|
+
* Needs a connected company, the customer and `deposit_account:default`
|
|
101
|
+
* mappings, and every invoice the payment applies to already synced to that
|
|
102
|
+
* company. The request id and exact facts are persisted before the push; a
|
|
103
|
+
* rejected push (or a dead grant, which sent nothing) may be retried; any other
|
|
104
|
+
* failure is `unknown` and stops until {@link reconcileAccountingPaymentSync}.
|
|
105
|
+
* Production needs live mode (#5138). Run it inside the tenant context.
|
|
106
|
+
*/
|
|
107
|
+
export declare function syncPaymentToAccounting(input: SyncPaymentToAccountingInput): Promise<AccountingPaymentSyncResult>;
|
|
108
|
+
/** Input of {@link reconcileAccountingPaymentSync}. */
|
|
109
|
+
export interface ReconcileAccountingPaymentSyncInput {
|
|
110
|
+
readonly db: DatabaseInterface;
|
|
111
|
+
readonly tenantId: string;
|
|
112
|
+
readonly paymentId: string;
|
|
113
|
+
/** The request id observed before looking the payment up at the provider. */
|
|
114
|
+
readonly requestId: string;
|
|
115
|
+
/** The unresolved attempt observed with it. */
|
|
116
|
+
readonly attemptId: string;
|
|
117
|
+
/** Required for an interrupted `in_flight` row: its owner can no longer finish. */
|
|
118
|
+
readonly confirmInterruptedOwnerStopped?: true;
|
|
119
|
+
/** The authoritative provider lookup of that request. */
|
|
120
|
+
readonly outcome: {
|
|
121
|
+
readonly status: 'found';
|
|
122
|
+
readonly externalId: string;
|
|
123
|
+
readonly syncedAt: Date;
|
|
124
|
+
} | {
|
|
125
|
+
readonly status: 'absent';
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Resolve an unknown or interrupted payment push with an authoritative provider
|
|
130
|
+
* lookup. `found` records the payment as synced; `absent` (the provider
|
|
131
|
+
* confirmed nothing was created) makes the push retryable.
|
|
132
|
+
*/
|
|
133
|
+
export declare function reconcileAccountingPaymentSync(input: ReconcileAccountingPaymentSyncInput): Promise<AccountingPaymentSync>;
|
|
134
|
+
/** Input of {@link readbackInvoice}. */
|
|
135
|
+
export interface ReadbackInvoiceInput {
|
|
136
|
+
readonly db: DatabaseInterface;
|
|
137
|
+
readonly tenantId: string;
|
|
138
|
+
readonly invoiceId: string;
|
|
139
|
+
readonly reader: AccountingInvoiceReader;
|
|
140
|
+
readonly now?: Date;
|
|
141
|
+
}
|
|
142
|
+
/** Stored outcome of a readback. */
|
|
143
|
+
export interface AccountingReadbackResult {
|
|
144
|
+
readonly invoiceId: string;
|
|
145
|
+
readonly externalId: string;
|
|
146
|
+
readonly status: AccountingReadbackStatus;
|
|
147
|
+
/** Why it is `drift` or `needs_reconciliation`; empty when `in_step`. */
|
|
148
|
+
readonly reason: string;
|
|
149
|
+
readonly localPaidMinor: number;
|
|
150
|
+
readonly projection: ReturnType<typeof projectQuickBooksPilotEvidence> | null;
|
|
151
|
+
/** Provider payment ids with no local counterpart. */
|
|
152
|
+
readonly providerOnlyPayments: readonly string[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Read the provider document of one synced ordinary invoice and store the
|
|
156
|
+
* projection and a status. Provider reads are authoritative: an incomplete or
|
|
157
|
+
* inconsistent read is `needs_reconciliation`; a provider that disagrees with
|
|
158
|
+
* Commerce on paid amounts, a voided document, or a payment recorded only in
|
|
159
|
+
* the provider is `drift`. Reads only; it never writes to the provider.
|
|
160
|
+
*/
|
|
161
|
+
export declare function readbackInvoice(input: ReadbackInvoiceInput): Promise<AccountingReadbackResult>;
|
|
162
|
+
/** What one batch did to one item. */
|
|
163
|
+
export interface AccountingBatchItem {
|
|
164
|
+
readonly kind: 'invoice' | 'credit_note' | 'payment' | 'readback';
|
|
165
|
+
readonly id: string;
|
|
166
|
+
readonly outcome: 'synced' | 'unchanged' | 'skipped' | 'failed' | string;
|
|
167
|
+
/** Short code for `skipped` and `failed`. */
|
|
168
|
+
readonly reason?: string;
|
|
169
|
+
}
|
|
170
|
+
/** Result of a batch entry point. */
|
|
171
|
+
export interface AccountingBatchResult {
|
|
172
|
+
readonly items: readonly AccountingBatchItem[];
|
|
173
|
+
/**
|
|
174
|
+
* Opaque position after the last row examined; pass it back as `cursor` to
|
|
175
|
+
* continue. `null` when the sweep reached the end (the next call without a
|
|
176
|
+
* cursor starts a new sweep).
|
|
177
|
+
*/
|
|
178
|
+
readonly nextCursor: string | null;
|
|
179
|
+
}
|
|
180
|
+
/** Input of {@link syncPending}. */
|
|
181
|
+
export interface SyncPendingInput {
|
|
182
|
+
readonly db: DatabaseInterface;
|
|
183
|
+
/** Must be the active tenant. */
|
|
184
|
+
readonly tenantId: string;
|
|
185
|
+
readonly provider: SyncFrozenInvoiceToAccountingInput['provider'];
|
|
186
|
+
readonly payments: AccountingPaymentPort;
|
|
187
|
+
/** Most items to push in this call (default 25, at most 100). */
|
|
188
|
+
readonly limit?: number;
|
|
189
|
+
/** Position from the previous call's `nextCursor`. */
|
|
190
|
+
readonly cursor?: string;
|
|
191
|
+
/**
|
|
192
|
+
* Resolve a missing customer mapping instead of skipping the invoice. An
|
|
193
|
+
* ambiguous match is skipped (`customer_needs_confirmation`), never created.
|
|
194
|
+
*/
|
|
195
|
+
readonly customers?: {
|
|
196
|
+
readonly directory: AccountingCustomerDirectory;
|
|
197
|
+
readonly describe: (customerId: string) => Promise<AccountingCustomerFacts>;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Push the tenant's pending frozen invoices and credit notes, then their
|
|
202
|
+
* recorded payments: at most `limit` pushes and at most {@link SCAN_CAP} rows
|
|
203
|
+
* examined per call, resumable through `cursor`. Each item is independent: a
|
|
204
|
+
* missing mapping, an unsynced source or a provider failure is reported on the
|
|
205
|
+
* item and the batch continues. A closed live-mode gate or a dead connection
|
|
206
|
+
* stops the batch (it would fail every item). Items already in flight or of
|
|
207
|
+
* unknown outcome are reported as skipped (`in_flight`, `reconciliation`) so a
|
|
208
|
+
* stuck push surfaces. Idempotent: re-running pushes nothing already synced.
|
|
209
|
+
* The app job only schedules and locks.
|
|
210
|
+
*/
|
|
211
|
+
export declare function syncPending(input: SyncPendingInput): Promise<AccountingBatchResult>;
|
|
212
|
+
/** Input of {@link readbackDue}. */
|
|
213
|
+
export interface ReadbackDueInput {
|
|
214
|
+
readonly db: DatabaseInterface;
|
|
215
|
+
/** Must be the active tenant. */
|
|
216
|
+
readonly tenantId: string;
|
|
217
|
+
readonly reader: AccountingInvoiceReader;
|
|
218
|
+
/** Most invoices to read in this call (default 25, at most 100). */
|
|
219
|
+
readonly limit?: number;
|
|
220
|
+
/** Re-read invoices last read at or before this instant (default: 15 minutes ago). */
|
|
221
|
+
readonly olderThan?: Date;
|
|
222
|
+
/** Position from the previous call's `nextCursor`. */
|
|
223
|
+
readonly cursor?: string;
|
|
224
|
+
readonly now?: Date;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Read back the tenant's synced invoices that have never been read, or were last
|
|
228
|
+
* read before `olderThan`: at most `limit` reads and {@link SCAN_CAP} rows
|
|
229
|
+
* examined per call, resumable through `cursor`. A failing read is recorded on
|
|
230
|
+
* the invoice (`needs_reconciliation`) and the batch continues.
|
|
231
|
+
*/
|
|
232
|
+
export declare function readbackDue(input: ReadbackDueInput): Promise<AccountingBatchResult>;
|
|
233
|
+
//# sourceMappingURL=accounting-payment-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounting-payment-sync.d.ts","sourceRoot":"","sources":["../src/accounting-payment-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAI7E,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAO7B,MAA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SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;QAChD,QAAQ,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;KAC7E,CAAC;CACH;AAkBD;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,qBAAqB,CAAC,CAmLhC;AAED,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,sFAAsF;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,qBAAqB,CAAC,CAuEhC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { s as InvoiceStatus } from "./types-Bbm0Xflc.js";
|
|
3
|
-
import { i as claimAllocationParent, r as assertAllocationParent } from "./allocation-integrity-CvXQm3wK.js";
|
|
4
2
|
import { MoneyValidationError, assertIntegerMinorUnits } from "../money.js";
|
|
5
3
|
import { a as assertCommerceMoneySchemaCurrent, f as DOCUMENT_MONEY_READ_REBIND, p as DOCUMENT_MONEY_WRITE } from "./detect-DAE-_NAk.js";
|
|
6
|
-
import {
|
|
4
|
+
import { i as claimAllocationParent, r as assertAllocationParent } from "./allocation-integrity-C4SZJcao.js";
|
|
5
|
+
import { s as InvoiceStatus } from "./types-Bbm0Xflc.js";
|
|
6
|
+
import { n as withTenantMoneyCollectionRead } from "./tenant-money-barrier-BdyXIVT5.js";
|
|
7
7
|
import { SmrtCollection, SmrtObject, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
|
|
8
8
|
import { TenantScoped, getTenantId, queryGlobal, queryWithGlobals, tenantId } from "@happyvertical/smrt-tenancy";
|
|
9
9
|
//#region src/retention-money.ts
|
|
@@ -348,7 +348,7 @@ var Invoice = class extends SmrtObject {
|
|
|
348
348
|
* - **Status transitions** are validated against the prior persisted status.
|
|
349
349
|
*/
|
|
350
350
|
async save(options) {
|
|
351
|
-
const { saveInvoice } = await import("./
|
|
351
|
+
const { saveInvoice } = await import("./retention-accounting-BA4wXUQc.js").then((n) => n.Q);
|
|
352
352
|
return await saveInvoice(this, options);
|
|
353
353
|
}
|
|
354
354
|
/** @internal Aggregate persistence only. */
|
|
@@ -382,7 +382,7 @@ var Invoice = class extends SmrtObject {
|
|
|
382
382
|
return result;
|
|
383
383
|
}
|
|
384
384
|
async delete(options = {}) {
|
|
385
|
-
const { deleteInvoice } = await import("./
|
|
385
|
+
const { deleteInvoice } = await import("./retention-accounting-BA4wXUQc.js").then((n) => n.Q);
|
|
386
386
|
await deleteInvoice(this, options);
|
|
387
387
|
}
|
|
388
388
|
/** @internal Aggregate persistence only. */
|
|
@@ -407,7 +407,7 @@ var Invoice = class extends SmrtObject {
|
|
|
407
407
|
return loadedInvoiceStatus.get(this);
|
|
408
408
|
}
|
|
409
409
|
async recomputeAmountPaid() {
|
|
410
|
-
const { PaymentAllocationCollection } = await import("./retention-accounting-
|
|
410
|
+
const { PaymentAllocationCollection } = await import("./retention-accounting-BA4wXUQc.js").then((n) => n.ln);
|
|
411
411
|
const allocationCollection = await PaymentAllocationCollection.create({
|
|
412
412
|
...this.options,
|
|
413
413
|
db: this.db
|
|
@@ -614,7 +614,7 @@ var Invoice = class extends SmrtObject {
|
|
|
614
614
|
}
|
|
615
615
|
/** Cancel a posted invoice with an exact atomic journal reversal. */
|
|
616
616
|
async cancelWithRevenueReversal(options) {
|
|
617
|
-
const { cancelInvoiceWithRevenueReversal, rebindJournal } = await import("./invoice-posting-
|
|
617
|
+
const { cancelInvoiceWithRevenueReversal, rebindJournal } = await import("./invoice-posting-CDfxug3Q.js");
|
|
618
618
|
return rebindJournal(this.db, await cancelInvoiceWithRevenueReversal(this, options));
|
|
619
619
|
}
|
|
620
620
|
/**
|
|
@@ -645,7 +645,7 @@ var Invoice = class extends SmrtObject {
|
|
|
645
645
|
* ```
|
|
646
646
|
*/
|
|
647
647
|
async recognizeRevenue(options) {
|
|
648
|
-
const { recognizeInvoiceRevenue, rebindJournal } = await import("./invoice-posting-
|
|
648
|
+
const { recognizeInvoiceRevenue, rebindJournal } = await import("./invoice-posting-CDfxug3Q.js");
|
|
649
649
|
return rebindJournal(this.db, await recognizeInvoiceRevenue(this, options));
|
|
650
650
|
}
|
|
651
651
|
/**
|
|
@@ -683,7 +683,7 @@ var Invoice = class extends SmrtObject {
|
|
|
683
683
|
async toAccountingInput(options) {
|
|
684
684
|
if (!options) throw new MoneyValidationError("INVALID_MONEY_INPUT", "Accounting conversion requires explicit realm mapping");
|
|
685
685
|
if (!this.id || !this.tenantId) throw new MoneyValidationError("INVALID_MONEY_INPUT", "Accounting conversion requires a persisted tenant invoice");
|
|
686
|
-
const { toFrozenInvoiceAccountingInput } = await import("./retention-accounting-
|
|
686
|
+
const { toFrozenInvoiceAccountingInput } = await import("./retention-accounting-BA4wXUQc.js").then((n) => n.C);
|
|
687
687
|
return toFrozenInvoiceAccountingInput({
|
|
688
688
|
db: this.db,
|
|
689
689
|
tenantId: this.tenantId,
|
|
@@ -1067,4 +1067,4 @@ var InvoiceCollection = class extends SmrtCollection {
|
|
|
1067
1067
|
//#endregion
|
|
1068
1068
|
export { assertRetentionMinor as a, validateRetentionEvidence as c, Invoice as i, InvoiceCollection_exports as n, calculateInvoicePayable as o, UNPAID_STATUSES as r, parseInvoiceRetention as s, InvoiceCollection as t };
|
|
1069
1069
|
|
|
1070
|
-
//# sourceMappingURL=InvoiceCollection-
|
|
1070
|
+
//# sourceMappingURL=InvoiceCollection-xooQnUwq.js.map
|