@openlup/platform 0.22.0 → 0.23.0
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/CHANGELOG.md +222 -99
- package/README.md +59 -589
- package/dist/fulfillment/adapterConformance.js +1 -1
- package/dist/fulfillment/bindings.js +1 -1
- package/dist/fulfillment/contracts/conformance.d.ts +3 -1
- package/dist/fulfillment/contracts/dispatch.d.ts +41 -3
- package/dist/fulfillment/contracts/index.d.ts +3 -3
- package/dist/fulfillment/contracts/observation.d.ts +21 -1
- package/dist/fulfillment/contracts/readback.d.ts +21 -0
- package/dist/fulfillment/contracts/store.d.ts +3 -0
- package/dist/fulfillment/contracts/sync.d.ts +58 -2
- package/dist/fulfillment/dispatchProjection.d.ts +20 -1
- package/dist/fulfillment/dispatchProjection.js +95 -6
- package/dist/fulfillment/index.d.ts +3 -2
- package/dist/fulfillment/index.js +2 -2
- package/dist/fulfillment/migrations.d.ts +5 -0
- package/dist/fulfillment/migrations.js +1 -0
- package/dist/fulfillment/observationProjection.d.ts +24 -3
- package/dist/fulfillment/observationProjection.js +65 -12
- package/dist/fulfillment/omnipack/client.d.ts +3 -1
- package/dist/fulfillment/omnipack/client.js +17 -7
- package/dist/fulfillment/omnipack/index.d.ts +4 -1
- package/dist/fulfillment/omnipack/index.js +104 -45
- package/dist/fulfillment/omnipack/mappers.d.ts +7 -1
- package/dist/fulfillment/omnipack/mappers.js +24 -2
- package/dist/fulfillment/omnipack/observation.d.ts +11 -4
- package/dist/fulfillment/omnipack/observation.js +44 -29
- package/dist/fulfillment/omnipack/reconciliation.d.ts +15 -0
- package/dist/fulfillment/omnipack/reconciliation.js +55 -0
- package/dist/fulfillment/postgresDispatchStore.js +1 -1
- package/dist/fulfillment/postgresShipmentSpine.d.ts +8 -1
- package/dist/fulfillment/postgresShipmentSpine.js +17 -3
- package/dist/fulfillment/postgresStockSyncPort.js +6 -3
- package/dist/fulfillment/providerDispatchAcceptance.d.ts +1 -0
- package/dist/fulfillment/providerDispatchAcceptance.js +8 -2
- package/dist/fulfillment/providerDispatchWorker.d.ts +13 -0
- package/dist/fulfillment/providerDispatchWorker.js +47 -20
- package/dist/fulfillment/providerReconciliationWorker.d.ts +27 -19
- package/dist/fulfillment/providerReconciliationWorker.js +75 -19
- package/dist/fulfillment/providerStockSyncWorker.d.ts +5 -1
- package/dist/fulfillment/providerStockSyncWorker.js +229 -120
- package/dist/fulfillment/providerTrackingReferences.d.ts +3 -2
- package/dist/fulfillment/verifiedIngress.d.ts +38 -11
- package/dist/fulfillment/verifiedIngress.js +36 -8
- package/dist/invoicing/capabilities.d.ts +11 -0
- package/dist/invoicing/capabilities.js +10 -0
- package/dist/invoicing/contracts/capabilities.d.ts +40 -0
- package/dist/invoicing/contracts/capabilities.js +1 -0
- package/dist/invoicing/contracts/companyLookup.d.ts +49 -0
- package/dist/invoicing/contracts/companyLookup.js +1 -0
- package/dist/invoicing/contracts/delivery.d.ts +74 -0
- package/dist/invoicing/contracts/delivery.js +1 -0
- package/dist/invoicing/contracts/facts.d.ts +100 -0
- package/dist/invoicing/contracts/facts.js +1 -0
- package/dist/invoicing/contracts/host.d.ts +246 -0
- package/dist/invoicing/contracts/host.js +1 -0
- package/dist/invoicing/contracts/index.d.ts +16 -0
- package/dist/invoicing/contracts/index.js +1 -0
- package/dist/invoicing/contracts/provider.d.ts +126 -0
- package/dist/invoicing/contracts/provider.js +1 -0
- package/dist/invoicing/contracts/settlement.d.ts +66 -0
- package/dist/invoicing/contracts/settlement.js +1 -0
- package/dist/invoicing/contracts/store.d.ts +267 -0
- package/dist/invoicing/contracts/store.js +1 -0
- package/dist/invoicing/index.d.ts +1 -0
- package/dist/invoicing/index.js +1 -0
- package/dist/subscriptions/automaticRenewal.d.ts +44 -0
- package/dist/subscriptions/automaticRenewal.js +81 -0
- package/dist/subscriptions/automaticRenewalExecution.d.ts +21 -0
- package/dist/subscriptions/automaticRenewalExecution.js +44 -0
- package/dist/subscriptions/contracts/commands.d.ts +115 -0
- package/dist/subscriptions/contracts/commands.js +1 -0
- package/dist/subscriptions/contracts/dunning.d.ts +133 -0
- package/dist/subscriptions/contracts/dunning.js +1 -0
- package/dist/subscriptions/contracts/index.d.ts +6 -0
- package/dist/subscriptions/contracts/index.js +1 -0
- package/dist/subscriptions/contracts/messages.d.ts +43 -0
- package/dist/subscriptions/contracts/messages.js +1 -0
- package/dist/subscriptions/contracts/renewal.d.ts +533 -0
- package/dist/subscriptions/contracts/renewal.js +1 -0
- package/dist/subscriptions/contracts/stockWait.d.ts +73 -0
- package/dist/subscriptions/contracts/stockWait.js +1 -0
- package/dist/subscriptions/index.d.ts +39 -0
- package/dist/subscriptions/index.js +17 -0
- package/dist/subscriptions/paymentOutcomes.d.ts +8 -0
- package/dist/subscriptions/paymentOutcomes.js +27 -0
- package/dist/subscriptions/postgresRenewalStore.d.ts +20 -0
- package/dist/subscriptions/postgresRenewalStore.js +61 -0
- package/dist/subscriptions/postgresRetryStore.d.ts +78 -0
- package/dist/subscriptions/postgresRetryStore.js +142 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.d.ts +34 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.js +79 -0
- package/dist/subscriptions/renewalCycleMechanism.d.ts +46 -0
- package/dist/subscriptions/renewalCycleMechanism.js +157 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.d.ts +41 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.js +160 -0
- package/dist/subscriptions/renewalIdentity.d.ts +3 -0
- package/dist/subscriptions/renewalIdentity.js +4 -0
- package/package.json +22 -2
- package/release-gates.json +56 -3
- package/sql/20261022160000_subscription_retry_lifecycle.sql +328 -0
- package/sql/20261022165000_fulfillment_stock_evidence_replay_reopen.sql +30 -0
- package/src/fulfillment/adapterConformance.ts +1 -1
- package/src/fulfillment/bindings.ts +1 -1
- package/src/fulfillment/contracts/conformance.ts +3 -1
- package/src/fulfillment/contracts/dispatch.ts +20 -5
- package/src/fulfillment/contracts/index.ts +3 -3
- package/src/fulfillment/contracts/observation.ts +11 -3
- package/src/fulfillment/contracts/readback.ts +13 -0
- package/src/fulfillment/contracts/store.ts +1 -0
- package/src/fulfillment/contracts/sync.ts +13 -2
- package/src/fulfillment/dispatchProjection.ts +92 -7
- package/src/fulfillment/index.ts +3 -2
- package/src/fulfillment/migrations.ts +1 -0
- package/src/fulfillment/observationProjection.ts +64 -13
- package/src/fulfillment/omnipack/client.ts +19 -7
- package/src/fulfillment/omnipack/index.ts +96 -39
- package/src/fulfillment/omnipack/mappers.ts +23 -2
- package/src/fulfillment/omnipack/observation.ts +45 -27
- package/src/fulfillment/omnipack/reconciliation.ts +56 -0
- package/src/fulfillment/postgresDispatchStore.ts +1 -1
- package/src/fulfillment/postgresShipmentSpine.ts +21 -4
- package/src/fulfillment/postgresStockSyncPort.ts +6 -3
- package/src/fulfillment/providerDispatchAcceptance.ts +9 -3
- package/src/fulfillment/providerDispatchWorker.ts +48 -20
- package/src/fulfillment/providerReconciliationWorker.ts +81 -25
- package/src/fulfillment/providerStockSyncWorker.ts +222 -126
- package/src/fulfillment/providerTrackingReferences.ts +3 -2
- package/src/fulfillment/verifiedIngress.ts +44 -11
- package/src/invoicing/capabilities.ts +9 -0
- package/src/invoicing/contracts/capabilities.ts +15 -0
- package/src/invoicing/contracts/companyLookup.ts +13 -0
- package/src/invoicing/contracts/delivery.ts +24 -0
- package/src/invoicing/contracts/facts.ts +60 -0
- package/src/invoicing/contracts/host.ts +85 -0
- package/src/invoicing/contracts/index.ts +16 -0
- package/src/invoicing/contracts/provider.ts +78 -0
- package/src/invoicing/contracts/settlement.ts +39 -0
- package/src/invoicing/contracts/store.ts +98 -0
- package/src/invoicing/index.ts +1 -0
- package/src/subscriptions/automaticRenewal.ts +87 -0
- package/src/subscriptions/automaticRenewalExecution.ts +39 -0
- package/src/subscriptions/contracts/commands.ts +46 -0
- package/src/subscriptions/contracts/dunning.ts +48 -0
- package/src/subscriptions/contracts/index.ts +6 -0
- package/src/subscriptions/contracts/messages.ts +18 -0
- package/src/subscriptions/contracts/renewal.ts +325 -0
- package/src/subscriptions/contracts/stockWait.ts +34 -0
- package/src/subscriptions/index.ts +24 -0
- package/src/subscriptions/paymentOutcomes.ts +23 -0
- package/src/subscriptions/postgresRenewalStore.ts +76 -0
- package/src/subscriptions/postgresRetryStore.ts +174 -0
- package/src/subscriptions/renewalCycleFailureMechanism.ts +119 -0
- package/src/subscriptions/renewalCycleMechanism.ts +225 -0
- package/src/subscriptions/renewalCycleRefusalMechanism.ts +215 -0
- package/src/subscriptions/renewalIdentity.ts +5 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FulfillmentObservation, FulfillmentObservationPort, FulfillmentRefusal } from "./contracts/index.js";
|
|
1
|
+
import type { FulfillmentObservation, FulfillmentObservationCodecs, FulfillmentObservationPort, FulfillmentRefusal } from "./contracts/index.js";
|
|
2
2
|
import { applyFulfillmentObservationEffects } from "./fulfillmentObservationEffects.js";
|
|
3
3
|
type EffectInput = Parameters<typeof applyFulfillmentObservationEffects<FulfillmentObservation["fact"]["canonicalStatus"], "in_transit" | "delivered">>[0];
|
|
4
4
|
type DispatchRef = {
|
|
@@ -7,20 +7,54 @@ type DispatchRef = {
|
|
|
7
7
|
dispatchRef: string;
|
|
8
8
|
externalRef: string | null;
|
|
9
9
|
};
|
|
10
|
+
export interface FulfillmentIngressCounts {
|
|
11
|
+
invalidTimestamps: number;
|
|
12
|
+
rejectedCorrelationRefs: number;
|
|
13
|
+
rejectedTrackingRefs: number;
|
|
14
|
+
rejectedTrackingUrls: number;
|
|
15
|
+
}
|
|
16
|
+
export type FulfillmentIngressResult = {
|
|
17
|
+
counts: FulfillmentIngressCounts;
|
|
18
|
+
} & ({
|
|
19
|
+
kind: "refused";
|
|
20
|
+
receiptId: null;
|
|
21
|
+
refusal: FulfillmentRefusal;
|
|
22
|
+
diagnostics?: {
|
|
23
|
+
invalidTimestamp?: true;
|
|
24
|
+
rejectedCorrelationRefs?: number;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
kind: "processed" | "ignored" | "superseded";
|
|
28
|
+
receiptId: string;
|
|
29
|
+
observation: FulfillmentObservation;
|
|
30
|
+
replayed: boolean;
|
|
31
|
+
trackingRefs: number;
|
|
32
|
+
trackingReadBacks: number;
|
|
33
|
+
supersededCause?: string;
|
|
34
|
+
});
|
|
35
|
+
/** Safe response classes only; the host owns HTTP and localized message text. */
|
|
36
|
+
export declare function fulfillmentIngressHttpResult(result: FulfillmentIngressResult): {
|
|
37
|
+
status: 200 | 400 | 403 | 503;
|
|
38
|
+
messageClass: "accepted" | "bad_request" | "forbidden" | "upstream_unavailable";
|
|
39
|
+
};
|
|
10
40
|
/** Adapter verification owns auth-before-parse; the host owns durable replay. */
|
|
11
41
|
export declare function verifyAndNormalizeFulfillmentObservation(input: {
|
|
12
42
|
enabled: boolean;
|
|
43
|
+
approveTrackingUrl?(url: string): boolean;
|
|
44
|
+
observationCodecs?: FulfillmentObservationCodecs;
|
|
13
45
|
provider: FulfillmentObservationPort;
|
|
14
46
|
verification: Parameters<FulfillmentObservationPort["verifyAndNormalize"]>[0];
|
|
15
47
|
localPersistence: {
|
|
16
48
|
/** G17: atomic insert by eventKey; retries keep the first stored firstReceivedAt. */
|
|
17
49
|
recordObservation(observation: FulfillmentObservation): Promise<{
|
|
18
50
|
replayed: boolean;
|
|
51
|
+
receiptId?: string;
|
|
19
52
|
}>;
|
|
20
53
|
/** Idempotent; only called after completion or a classified superseding conflict. */
|
|
21
54
|
markProcessed(eventKey: string, outcome: {
|
|
22
55
|
status: "processed" | "ignored";
|
|
23
56
|
refusal?: FulfillmentRefusal;
|
|
57
|
+
supersededCause?: string;
|
|
24
58
|
}): Promise<void>;
|
|
25
59
|
};
|
|
26
60
|
lifecycle: {
|
|
@@ -36,17 +70,10 @@ export declare function verifyAndNormalizeFulfillmentObservation(input: {
|
|
|
36
70
|
tracking(eventKey: string, number: string): string;
|
|
37
71
|
};
|
|
38
72
|
issueAccountingInvoice?(ref: string): Promise<void>;
|
|
73
|
+
/** Return a machine identity, never exception prose. */
|
|
74
|
+
supersededCause?(error: unknown): string | null;
|
|
39
75
|
classifyFailure(error: unknown): "stock_contention" | "state_conflict" | "other";
|
|
40
76
|
annotateStockContention?(eventKey: string, fulfillmentRef: string): Promise<void>;
|
|
41
77
|
};
|
|
42
|
-
}): Promise<
|
|
43
|
-
kind: "refused";
|
|
44
|
-
refusal: FulfillmentRefusal;
|
|
45
|
-
} | {
|
|
46
|
-
kind: "processed" | "ignored" | "superseded";
|
|
47
|
-
observation: FulfillmentObservation;
|
|
48
|
-
replayed: boolean;
|
|
49
|
-
trackingRefs: number;
|
|
50
|
-
trackingReadBacks: number;
|
|
51
|
-
}>;
|
|
78
|
+
}): Promise<FulfillmentIngressResult>;
|
|
52
79
|
export {};
|
|
@@ -1,19 +1,44 @@
|
|
|
1
|
+
import { safeDiagnosticCode } from "./dispatchProjection.js";
|
|
1
2
|
import { applyFulfillmentObservationEffects } from "./fulfillmentObservationEffects.js";
|
|
2
3
|
import { observationStatusPolicy, projectObservation } from "./observationProjection.js";
|
|
3
4
|
import { uniqueTrackingReferences } from "./providerTrackingReferences.js";
|
|
5
|
+
/** Safe response classes only; the host owns HTTP and localized message text. */
|
|
6
|
+
export function fulfillmentIngressHttpResult(result) {
|
|
7
|
+
if (result.kind !== "refused")
|
|
8
|
+
return { status: 200, messageClass: "accepted" };
|
|
9
|
+
if (result.refusal.reason === "untrusted")
|
|
10
|
+
return { status: 403, messageClass: "forbidden" };
|
|
11
|
+
if (result.refusal.reason === "disabled" || result.refusal.reason === "not_ready" || result.refusal.retryable)
|
|
12
|
+
return { status: 503, messageClass: "upstream_unavailable" };
|
|
13
|
+
return { status: 400, messageClass: "bad_request" };
|
|
14
|
+
}
|
|
4
15
|
/** Adapter verification owns auth-before-parse; the host owns durable replay. */
|
|
5
16
|
export async function verifyAndNormalizeFulfillmentObservation(input) {
|
|
17
|
+
const counts = { invalidTimestamps: 0, rejectedCorrelationRefs: 0, rejectedTrackingRefs: 0, rejectedTrackingUrls: 0 };
|
|
6
18
|
if (!input.enabled)
|
|
7
|
-
return { kind: "refused", refusal: { reason: "disabled", phase: "verify", retryable: false } };
|
|
19
|
+
return { kind: "refused", receiptId: null, counts, refusal: { reason: "disabled", phase: "verify", retryable: false } };
|
|
8
20
|
const verified = await input.provider.verifyAndNormalize(input.verification);
|
|
9
|
-
if (verified.kind === "refused")
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
if (verified.kind === "refused") {
|
|
22
|
+
if (verified.diagnostics?.invalidTimestamp)
|
|
23
|
+
counts.invalidTimestamps++;
|
|
24
|
+
const rejected = verified.diagnostics?.rejectedCorrelationRefs;
|
|
25
|
+
if (typeof rejected === "number" && Number.isSafeInteger(rejected) && rejected > 0)
|
|
26
|
+
counts.rejectedCorrelationRefs = rejected;
|
|
27
|
+
return { kind: "refused", receiptId: null, refusal: verified.refusal, counts,
|
|
28
|
+
...(counts.invalidTimestamps || counts.rejectedCorrelationRefs ? { diagnostics: {
|
|
29
|
+
...(counts.invalidTimestamps ? { invalidTimestamp: true } : {}),
|
|
30
|
+
...(counts.rejectedCorrelationRefs ? { rejectedCorrelationRefs: counts.rejectedCorrelationRefs } : {}),
|
|
31
|
+
} } : {}) };
|
|
32
|
+
}
|
|
33
|
+
const observation = projectObservation(verified.observation, input.approveTrackingUrl, input.observationCodecs);
|
|
34
|
+
counts.rejectedTrackingRefs = observation.diagnostics?.admission?.rejectedTrackingRefs ?? 0;
|
|
35
|
+
counts.rejectedTrackingUrls = observation.diagnostics?.admission?.rejectedTrackingUrls ?? 0;
|
|
12
36
|
const inbound = await input.localPersistence.recordObservation(observation);
|
|
37
|
+
const receiptId = inbound.receiptId ?? observation.eventKey;
|
|
13
38
|
const ref = await input.lifecycle.findDispatchRef(observation);
|
|
14
39
|
if (!ref) {
|
|
15
40
|
await input.localPersistence.markProcessed(observation.eventKey, { status: "ignored", refusal: { reason: "local_missing", phase: "apply", retryable: false } });
|
|
16
|
-
return { kind: "ignored", observation, replayed: inbound.replayed, trackingRefs: 0, trackingReadBacks: 0 };
|
|
41
|
+
return { kind: "ignored", receiptId, counts, observation, replayed: inbound.replayed, trackingRefs: 0, trackingReadBacks: 0 };
|
|
17
42
|
}
|
|
18
43
|
const externalRef = observation.correlation.externalRef?.trim() || ref.externalRef?.trim();
|
|
19
44
|
if (!externalRef)
|
|
@@ -57,10 +82,13 @@ export async function verifyAndNormalizeFulfillmentObservation(input) {
|
|
|
57
82
|
catch (error) {
|
|
58
83
|
if (input.lifecycle.classifyFailure(error) !== "state_conflict")
|
|
59
84
|
throw error;
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
const cause = input.lifecycle.supersededCause ? input.lifecycle.supersededCause(error)
|
|
86
|
+
: error && typeof error === "object" && "reason" in error ? error.reason : null;
|
|
87
|
+
const supersededCause = safeDiagnosticCode(cause) ?? "fulfillment_state_conflict";
|
|
88
|
+
await input.localPersistence.markProcessed(observation.eventKey, { status: "processed", supersededCause });
|
|
89
|
+
return { kind: "superseded", receiptId, counts, supersededCause, observation, replayed: inbound.replayed || statusEvidence.replayed, trackingRefs, trackingReadBacks };
|
|
62
90
|
}
|
|
63
91
|
}
|
|
64
92
|
await input.localPersistence.markProcessed(observation.eventKey, { status: "processed" });
|
|
65
|
-
return { kind: "processed", observation, replayed: inbound.replayed || statusEvidence.replayed, trackingRefs, trackingReadBacks };
|
|
93
|
+
return { kind: "processed", receiptId, counts, observation, replayed: inbound.replayed || statusEvidence.replayed, trackingRefs, trackingReadBacks };
|
|
66
94
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InvoiceCapabilities, InvoiceCapabilitySelection } from "./contracts/capabilities.js";
|
|
2
|
+
/** @consumer Host readiness / installed cold consumer. Default off and explicit
|
|
3
|
+
* provider selection precede capability use; construction never selects a provider.
|
|
4
|
+
*/
|
|
5
|
+
export declare function readInvoiceCapabilities(input: {
|
|
6
|
+
readonly enabled?: boolean;
|
|
7
|
+
readonly selection: {
|
|
8
|
+
readonly providerRef: string;
|
|
9
|
+
} | null;
|
|
10
|
+
readonly capability: InvoiceCapabilities | null;
|
|
11
|
+
}): InvoiceCapabilitySelection;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @consumer Host readiness / installed cold consumer. Default off and explicit
|
|
2
|
+
* provider selection precede capability use; construction never selects a provider.
|
|
3
|
+
*/
|
|
4
|
+
export function readInvoiceCapabilities(input) {
|
|
5
|
+
if (input.enabled !== true)
|
|
6
|
+
return { kind: "refused", code: "disabled", retryable: false, effectMayHaveSucceeded: false };
|
|
7
|
+
if (!input.selection || !input.capability || input.selection.providerRef !== input.capability.providerRef)
|
|
8
|
+
return { kind: "refused", code: "selection_required", retryable: false, effectMayHaveSucceeded: false };
|
|
9
|
+
return { kind: "ready", capability: input.capability };
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { InvoiceDiagnosticCode, InvoiceUnsupported } from "./provider.js";
|
|
2
|
+
export interface InvoiceCapabilities {
|
|
3
|
+
readonly version: "invoicing.capabilities.v1";
|
|
4
|
+
readonly providerRef: string;
|
|
5
|
+
readonly fiscalScope: {
|
|
6
|
+
readonly scopeRef: string;
|
|
7
|
+
readonly version: string;
|
|
8
|
+
};
|
|
9
|
+
readonly policies: {
|
|
10
|
+
readonly identifierRef: string;
|
|
11
|
+
readonly taxRef: string;
|
|
12
|
+
readonly roundingRef: string;
|
|
13
|
+
};
|
|
14
|
+
readonly documentKinds: readonly string[];
|
|
15
|
+
readonly correctionKinds: readonly "full_reversal"[];
|
|
16
|
+
readonly numberingOwner: "provider";
|
|
17
|
+
readonly sellerTiming: "execution" | "first_claim";
|
|
18
|
+
readonly operations: Readonly<Record<"issue" | "correction" | "recovery" | "readback" | "exactAbsence" | "artifact" | "clearance" | "settlement" | "companyLookup", {
|
|
19
|
+
readonly supported: true;
|
|
20
|
+
} | {
|
|
21
|
+
readonly supported: false;
|
|
22
|
+
readonly reason: "host_required" | "not_implemented" | "not_exposed";
|
|
23
|
+
}>> & {
|
|
24
|
+
readonly remoteVoid: {
|
|
25
|
+
readonly supported: false;
|
|
26
|
+
readonly reason: "not_implemented";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly defaultOff: true;
|
|
30
|
+
}
|
|
31
|
+
/** Interpretation only: no environment discovery, activation, writes or provider calls. */
|
|
32
|
+
export type InvoiceCapabilitySelection = InvoiceUnsupported | {
|
|
33
|
+
readonly kind: "ready";
|
|
34
|
+
readonly capability: InvoiceCapabilities;
|
|
35
|
+
} | {
|
|
36
|
+
readonly kind: "refused";
|
|
37
|
+
readonly code: Extract<InvoiceDiagnosticCode, "disabled" | "selection_required">;
|
|
38
|
+
readonly retryable: false;
|
|
39
|
+
readonly effectMayHaveSucceeded: false;
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { InvoiceProof, InvoiceUnsupported } from "./provider.js";
|
|
2
|
+
/** Injected registry seam. Host owns identifier validation, freshness and fallback;
|
|
3
|
+
* lookup evidence never overwrites checkout truth or becomes a renewal prerequisite.
|
|
4
|
+
* Carrier: accountingControlContracts lookup fields, generalized per A5 fit probe.
|
|
5
|
+
*/
|
|
6
|
+
export interface InvoiceCompanyLookupPort {
|
|
7
|
+
lookup(input: {
|
|
8
|
+
readonly identifier: {
|
|
9
|
+
readonly scheme: string;
|
|
10
|
+
readonly value: string;
|
|
11
|
+
readonly country?: string;
|
|
12
|
+
};
|
|
13
|
+
readonly asOf: string;
|
|
14
|
+
readonly sourceRef: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
readonly kind: "found" | "partial";
|
|
17
|
+
readonly identifier: {
|
|
18
|
+
readonly scheme: string;
|
|
19
|
+
readonly value: string;
|
|
20
|
+
readonly country?: string;
|
|
21
|
+
};
|
|
22
|
+
readonly legalName: string | null;
|
|
23
|
+
readonly registrationIds: readonly {
|
|
24
|
+
readonly scheme: string;
|
|
25
|
+
readonly value: string;
|
|
26
|
+
}[];
|
|
27
|
+
readonly address: {
|
|
28
|
+
readonly line1: string;
|
|
29
|
+
readonly postalCode: string;
|
|
30
|
+
readonly city: string;
|
|
31
|
+
readonly country: string;
|
|
32
|
+
} | null;
|
|
33
|
+
readonly taxRegistrations: readonly {
|
|
34
|
+
readonly scheme: string;
|
|
35
|
+
readonly status: "active" | "not_registered" | "exempt" | "unknown";
|
|
36
|
+
}[];
|
|
37
|
+
readonly sourceRef: string;
|
|
38
|
+
readonly proof: InvoiceProof;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "not_found";
|
|
41
|
+
readonly identifier: Parameters<InvoiceCompanyLookupPort["lookup"]>[0]["identifier"];
|
|
42
|
+
readonly sourceRef: string;
|
|
43
|
+
readonly proof: InvoiceProof;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "unknown";
|
|
46
|
+
readonly sourceRef: string;
|
|
47
|
+
readonly code: "unknown";
|
|
48
|
+
} | InvoiceUnsupported>;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { InvoiceDocumentIdentity, InvoiceProof, InvoiceUnsupported } from "./provider.js";
|
|
2
|
+
/** Durable opaque references; signed URLs and downloaded bytes are transient. */
|
|
3
|
+
export type InvoiceArtifactResult = {
|
|
4
|
+
readonly kind: "found";
|
|
5
|
+
readonly identity: InvoiceDocumentIdentity;
|
|
6
|
+
readonly artifact: {
|
|
7
|
+
readonly kind: "pdf" | "structured_document" | "clearance_receipt";
|
|
8
|
+
readonly ref: string;
|
|
9
|
+
readonly owner: "provider" | "host_storage";
|
|
10
|
+
readonly mediaType: string;
|
|
11
|
+
readonly proof: InvoiceProof;
|
|
12
|
+
};
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "absent";
|
|
15
|
+
readonly identity: InvoiceDocumentIdentity;
|
|
16
|
+
readonly evidence: InvoiceProof & {
|
|
17
|
+
readonly exact: true;
|
|
18
|
+
readonly complete: true;
|
|
19
|
+
readonly scope: {
|
|
20
|
+
readonly identity: InvoiceDocumentIdentity;
|
|
21
|
+
readonly kind: "pdf" | "structured_document" | "clearance_receipt";
|
|
22
|
+
readonly artifactRef: string | null;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "unknown";
|
|
27
|
+
readonly identity: InvoiceDocumentIdentity;
|
|
28
|
+
readonly code: "unknown";
|
|
29
|
+
} | InvoiceUnsupported;
|
|
30
|
+
/** Observation only; unsupported is never not_required. No clearance submission. */
|
|
31
|
+
export type InvoiceClearanceObservation = {
|
|
32
|
+
readonly proof: InvoiceProof;
|
|
33
|
+
} & ({
|
|
34
|
+
readonly state: "accepted";
|
|
35
|
+
readonly reference: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly state: "not_submitted" | "pending" | "rejected" | "not_required" | "unsupported";
|
|
38
|
+
readonly reference: string | null;
|
|
39
|
+
});
|
|
40
|
+
export interface InvoiceDeliveryPort {
|
|
41
|
+
/** Host M04 content/transport; provider acceptance is not inbox delivery.
|
|
42
|
+
* Preserve delivery/request keys, recipient, filename and bytes. Validate PDF
|
|
43
|
+
* type, size and signature before send; uncertain send must never repeat sending.
|
|
44
|
+
*/
|
|
45
|
+
send(input: {
|
|
46
|
+
readonly deliveryRef: string;
|
|
47
|
+
readonly requestKey: string;
|
|
48
|
+
readonly attemptCount: number;
|
|
49
|
+
readonly documentRef: string;
|
|
50
|
+
readonly orderId: string;
|
|
51
|
+
readonly orderRef: string;
|
|
52
|
+
readonly invoiceRef: string;
|
|
53
|
+
readonly providerDocumentRef: string;
|
|
54
|
+
readonly clientRef: string | null;
|
|
55
|
+
readonly recipient: string;
|
|
56
|
+
readonly source: string | null;
|
|
57
|
+
readonly providerDocumentNumber: string | null;
|
|
58
|
+
readonly filename: string;
|
|
59
|
+
readonly content: Uint8Array;
|
|
60
|
+
readonly contentType: string;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
readonly kind: "provider_accepted";
|
|
63
|
+
readonly receiptRef: string;
|
|
64
|
+
readonly proof: InvoiceProof;
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "failed_before_send";
|
|
67
|
+
readonly retryable: boolean;
|
|
68
|
+
readonly code: "retryable" | "invalid_artifact";
|
|
69
|
+
} | {
|
|
70
|
+
readonly kind: "uncertain";
|
|
71
|
+
readonly code: "uncertain_delivery";
|
|
72
|
+
readonly receiptRef: string | null;
|
|
73
|
+
} | InvoiceUnsupported>;
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Frozen host facts; no catalogue, registry or country-policy reread on retry.
|
|
2
|
+
* Carrier: donor providerPorts snapshot and invoiceContracts LocalInvoiceSnapshot;
|
|
3
|
+
* native invoicing_install_facts adds dates/refs/policyVersion and explicit totals.
|
|
4
|
+
*/
|
|
5
|
+
export interface InvoiceSeller {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly address: {
|
|
8
|
+
readonly line1: string;
|
|
9
|
+
readonly postalCode: string;
|
|
10
|
+
readonly city: string;
|
|
11
|
+
};
|
|
12
|
+
readonly taxIdentifier: {
|
|
13
|
+
readonly scheme: string;
|
|
14
|
+
readonly value: string;
|
|
15
|
+
};
|
|
16
|
+
readonly registrationIds?: readonly {
|
|
17
|
+
readonly scheme: string;
|
|
18
|
+
readonly value: string;
|
|
19
|
+
}[];
|
|
20
|
+
readonly bankAccount: string | null;
|
|
21
|
+
/** Opaque host routing reference, interpreted only by the selected adapter. */
|
|
22
|
+
readonly routingRef: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface InvoiceBuyer {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly email: string | null;
|
|
27
|
+
readonly taxIdentifier: {
|
|
28
|
+
readonly scheme: string;
|
|
29
|
+
readonly value: string;
|
|
30
|
+
} | null;
|
|
31
|
+
readonly companyName: string | null;
|
|
32
|
+
readonly address: {
|
|
33
|
+
readonly line1: string | null;
|
|
34
|
+
readonly postalCode: string | null;
|
|
35
|
+
readonly city: string | null;
|
|
36
|
+
readonly country: string | null;
|
|
37
|
+
} | null;
|
|
38
|
+
}
|
|
39
|
+
/** Safe integer minor amounts; taxRateBps is a rate, never a fiscal-support claim.
|
|
40
|
+
* Preserve array order and quantityUnit; no inferred shipping residual or FX.
|
|
41
|
+
*/
|
|
42
|
+
export interface InvoiceLine {
|
|
43
|
+
readonly description: string;
|
|
44
|
+
readonly quantity: number;
|
|
45
|
+
readonly quantityUnit?: string;
|
|
46
|
+
readonly unitNetMinor: number;
|
|
47
|
+
readonly unitGrossMinor: number;
|
|
48
|
+
readonly totalNetMinor: number;
|
|
49
|
+
readonly totalTaxMinor: number;
|
|
50
|
+
readonly totalGrossMinor: number;
|
|
51
|
+
readonly taxRateBps: number;
|
|
52
|
+
readonly taxRateLabel?: string;
|
|
53
|
+
readonly positionKind: "item" | "delivery" | null;
|
|
54
|
+
readonly catalogTotalGrossMinor: number | null;
|
|
55
|
+
readonly discountAllocatedMinor: number | null;
|
|
56
|
+
readonly shippingGrossMinor: number | null;
|
|
57
|
+
readonly shippingDiscountMinor: number | null;
|
|
58
|
+
}
|
|
59
|
+
export interface InvoiceFacts {
|
|
60
|
+
readonly factRevision: string;
|
|
61
|
+
readonly policyVersion: string;
|
|
62
|
+
readonly refs: {
|
|
63
|
+
readonly orderId: string;
|
|
64
|
+
readonly orderRef: string;
|
|
65
|
+
readonly invoiceRef: string;
|
|
66
|
+
};
|
|
67
|
+
readonly dates: {
|
|
68
|
+
readonly issueDate: string;
|
|
69
|
+
readonly sellDate: string;
|
|
70
|
+
readonly handedOverAt: string | null;
|
|
71
|
+
readonly paymentCompletedAt: string | null;
|
|
72
|
+
};
|
|
73
|
+
/** Host-defined kind selected through the identifier/tax seam, never guessed. */
|
|
74
|
+
readonly documentKind: string;
|
|
75
|
+
readonly clearanceRequired: boolean;
|
|
76
|
+
readonly currency: string;
|
|
77
|
+
readonly buyer: InvoiceBuyer;
|
|
78
|
+
/** Supplied separately for execution; P8 freezes it at first claim before provider I/O. */
|
|
79
|
+
readonly seller?: InvoiceSeller;
|
|
80
|
+
readonly payment: {
|
|
81
|
+
readonly intentRef: string;
|
|
82
|
+
readonly providerRef: string | null;
|
|
83
|
+
readonly providerPaymentRef: string | null;
|
|
84
|
+
readonly amountMinor: number;
|
|
85
|
+
readonly currency: string;
|
|
86
|
+
readonly localSettlementState: "matched" | "unavailable";
|
|
87
|
+
};
|
|
88
|
+
readonly orderMoney: {
|
|
89
|
+
readonly subtotalMinor: number;
|
|
90
|
+
readonly discountMinor: number;
|
|
91
|
+
readonly shippingMinor: number;
|
|
92
|
+
readonly shippingDiscountMinor: number;
|
|
93
|
+
readonly totalMinor: number;
|
|
94
|
+
} | null;
|
|
95
|
+
readonly lines: readonly InvoiceLine[];
|
|
96
|
+
readonly totalNetMinor: number;
|
|
97
|
+
readonly totalTaxMinor: number;
|
|
98
|
+
readonly totalGrossMinor: number;
|
|
99
|
+
readonly chargedTotalGrossMinor: number;
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|