@timbro/invoices 0.7.0-next.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +308 -0
- package/dist/artifact-headers.d.ts +9 -0
- package/dist/artifact-headers.d.ts.map +1 -0
- package/dist/artifact-headers.js +43 -0
- package/dist/certificate-custody-import.d.ts +13 -0
- package/dist/certificate-custody-import.d.ts.map +1 -0
- package/dist/certificate-custody-import.js +30 -0
- package/dist/certificate-custody-readiness.d.ts +6 -0
- package/dist/certificate-custody-readiness.d.ts.map +1 -0
- package/dist/certificate-custody-readiness.js +13 -0
- package/dist/collection.d.ts +13 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +21 -0
- package/dist/direct-connection.d.ts +74 -0
- package/dist/direct-connection.d.ts.map +1 -0
- package/dist/direct-connection.js +192 -0
- package/dist/document-node.d.ts +15 -0
- package/dist/document-node.d.ts.map +1 -0
- package/dist/document-node.js +67 -0
- package/dist/document-worker-protocol.d.ts +30 -0
- package/dist/document-worker-protocol.d.ts.map +1 -0
- package/dist/document-worker-protocol.js +103 -0
- package/dist/document-worker.d.ts +2 -0
- package/dist/document-worker.d.ts.map +1 -0
- package/dist/document-worker.js +71 -0
- package/dist/document.d.ts +38 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +204 -0
- package/dist/fiscal-delivery.d.ts +12 -0
- package/dist/fiscal-delivery.d.ts.map +1 -0
- package/dist/fiscal-delivery.js +45 -0
- package/dist/fiscal-engine-runtime.manifest.json +637 -0
- package/dist/fiscal-engine-runtime.provenance.json +1010 -0
- package/dist/fiscal-error.d.ts +23 -0
- package/dist/fiscal-error.d.ts.map +1 -0
- package/dist/fiscal-error.js +36 -0
- package/dist/fiscal-numbering-readiness.d.ts +6 -0
- package/dist/fiscal-numbering-readiness.d.ts.map +1 -0
- package/dist/fiscal-numbering-readiness.js +13 -0
- package/dist/fiscal-operation-timing.d.ts +9 -0
- package/dist/fiscal-operation-timing.d.ts.map +1 -0
- package/dist/fiscal-operation-timing.js +22 -0
- package/dist/fiscal-operation.d.ts +112 -0
- package/dist/fiscal-operation.d.ts.map +1 -0
- package/dist/fiscal-operation.js +193 -0
- package/dist/fiscal-receipt.d.ts +19 -0
- package/dist/fiscal-receipt.d.ts.map +1 -0
- package/dist/fiscal-receipt.js +66 -0
- package/dist/generated/index.d.ts +5 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +4 -0
- package/dist/generated/problem-catalog.d.ts +7 -0
- package/dist/generated/problem-catalog.d.ts.map +1 -0
- package/dist/generated/problem-catalog.js +198 -0
- package/dist/generated/sdk.gen.d.ts +240 -0
- package/dist/generated/sdk.gen.d.ts.map +1 -0
- package/dist/generated/sdk.gen.js +4486 -0
- package/dist/generated/types.gen.d.ts +6906 -0
- package/dist/generated/types.gen.d.ts.map +1 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/generated/zod.gen.d.ts +146666 -0
- package/dist/generated/zod.gen.d.ts.map +1 -0
- package/dist/generated/zod.gen.js +25077 -0
- package/dist/generated-operation-client.d.ts +47 -0
- package/dist/generated-operation-client.d.ts.map +1 -0
- package/dist/generated-operation-client.js +112 -0
- package/dist/generated-problem.d.ts +12 -0
- package/dist/generated-problem.d.ts.map +1 -0
- package/dist/generated-problem.js +37 -0
- package/dist/hosted-tenant.d.ts +38 -0
- package/dist/hosted-tenant.d.ts.map +1 -0
- package/dist/hosted-tenant.js +67 -0
- package/dist/hosted-workspace-transport.d.ts +15 -0
- package/dist/hosted-workspace-transport.d.ts.map +1 -0
- package/dist/hosted-workspace-transport.js +15 -0
- package/dist/idempotency-key.d.ts +3 -0
- package/dist/idempotency-key.d.ts.map +1 -0
- package/dist/idempotency-key.js +11 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/printed-representation.d.ts +23 -0
- package/dist/printed-representation.d.ts.map +1 -0
- package/dist/printed-representation.js +135 -0
- package/dist/problem-contract.d.ts +265 -0
- package/dist/problem-contract.d.ts.map +1 -0
- package/dist/problem-contract.js +25 -0
- package/dist/public-case.d.ts +15 -0
- package/dist/public-case.d.ts.map +1 -0
- package/dist/public-case.js +26 -0
- package/dist/received-documents.d.ts +35 -0
- package/dist/received-documents.d.ts.map +1 -0
- package/dist/received-documents.js +83 -0
- package/dist/sha256.d.ts +2 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +6 -0
- package/dist/signed-document.d.ts +15 -0
- package/dist/signed-document.d.ts.map +1 -0
- package/dist/signed-document.js +57 -0
- package/dist/source-command-validation.d.ts +3 -0
- package/dist/source-command-validation.d.ts.map +1 -0
- package/dist/source-command-validation.js +14 -0
- package/dist/source-connection-activation.d.ts +18 -0
- package/dist/source-connection-activation.d.ts.map +1 -0
- package/dist/source-connection-activation.js +41 -0
- package/dist/source-connection-transport.d.ts +8 -0
- package/dist/source-connection-transport.d.ts.map +1 -0
- package/dist/source-connection-transport.js +8 -0
- package/dist/source-connection.d.ts +18 -0
- package/dist/source-connection.d.ts.map +1 -0
- package/dist/source-connection.js +35 -0
- package/dist/stamp-server-http-transport.d.ts +23 -0
- package/dist/stamp-server-http-transport.d.ts.map +1 -0
- package/dist/stamp-server-http-transport.js +179 -0
- package/dist/timbro-client.d.ts +124 -0
- package/dist/timbro-client.d.ts.map +1 -0
- package/dist/timbro-client.js +72 -0
- package/dist/timbro_fiscal_engine.js +239 -0
- package/dist/timbro_fiscal_engine_bg.wasm +0 -0
- package/dist/transport-contract.d.ts +16 -0
- package/dist/transport-contract.d.ts.map +1 -0
- package/dist/transport-contract.js +1 -0
- package/dist/webhook-delivery.d.ts +14 -0
- package/dist/webhook-delivery.d.ts.map +1 -0
- package/dist/webhook-delivery.js +32 -0
- package/dist/webhook-event.d.ts +2711 -0
- package/dist/webhook-event.d.ts.map +1 -0
- package/dist/webhook-event.js +15 -0
- package/dist/webhook-registration.d.ts +12 -0
- package/dist/webhook-registration.d.ts.map +1 -0
- package/dist/webhook-registration.js +37 -0
- package/dist/webhook-replay.d.ts +12 -0
- package/dist/webhook-replay.d.ts.map +1 -0
- package/dist/webhook-replay.js +27 -0
- package/dist/webhook-verification.d.ts +25 -0
- package/dist/webhook-verification.d.ts.map +1 -0
- package/dist/webhook-verification.js +53 -0
- package/dist/workspace-session-transport.d.ts +8 -0
- package/dist/workspace-session-transport.d.ts.map +1 -0
- package/dist/workspace-session-transport.js +11 -0
- package/dist/workspace.d.ts +74 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +278 -0
- package/package.json +73 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// biome-ignore-all lint/correctness/noNodejsModules: This published SDK subpath is explicitly Node-only.
|
|
2
|
+
import { createHmac } from "node:crypto";
|
|
3
|
+
import { zCompleteActivationVerificationRequest, zWebhookEventEnvelope, } from "./generated/index.js";
|
|
4
|
+
const ACTIVATION_VERIFICATION_TRANSCRIPT_SCHEMA = "timbro.source-connection.activation-verification.v1";
|
|
5
|
+
const ACTIVATION_VERIFICATION_EVENT_TYPE = "source_connection.verification_requested";
|
|
6
|
+
const WEBHOOK_SIGNING_SECRET_PATTERN = /^whsec_[A-Za-z0-9+/]{43}=$/u;
|
|
7
|
+
/**
|
|
8
|
+
* Builds the proof a deployed Source target returns for Timbro's signed activation challenge.
|
|
9
|
+
* Callers must verify the Webhook signature before passing its parsed event here.
|
|
10
|
+
*/
|
|
11
|
+
export function buildSourceConnectionActivationVerification(input) {
|
|
12
|
+
const event = zWebhookEventEnvelope.parse(input.verificationRequestEvent);
|
|
13
|
+
if (event.type !== ACTIVATION_VERIFICATION_EVENT_TYPE) {
|
|
14
|
+
throw new TypeError("verificationRequestEvent.type is invalid");
|
|
15
|
+
}
|
|
16
|
+
const webhookSecret = requireWebhookSecret(input.webhookSecret);
|
|
17
|
+
const transcript = JSON.stringify({
|
|
18
|
+
schema: ACTIVATION_VERIFICATION_TRANSCRIPT_SCHEMA,
|
|
19
|
+
source_connection_id: event.data.source_connection_id,
|
|
20
|
+
activation_attempt_id: event.data.activation_attempt_id,
|
|
21
|
+
challenge: event.data.challenge,
|
|
22
|
+
expected_provider_target_id: event.data.provider_target_id,
|
|
23
|
+
expected_provider_deployment_id: event.data.provider_deployment_id,
|
|
24
|
+
runtime_provider_target_id: input.runtimeProviderTargetId,
|
|
25
|
+
runtime_provider_deployment_id: input.runtimeProviderDeploymentId,
|
|
26
|
+
});
|
|
27
|
+
const proof = createHmac("sha256", webhookSecret).update(transcript, "utf8").digest("base64url");
|
|
28
|
+
return zCompleteActivationVerificationRequest.parse({
|
|
29
|
+
activation_attempt_id: event.data.activation_attempt_id,
|
|
30
|
+
challenge: event.data.challenge,
|
|
31
|
+
proof,
|
|
32
|
+
runtime_provider_deployment_id: input.runtimeProviderDeploymentId,
|
|
33
|
+
runtime_provider_target_id: input.runtimeProviderTargetId,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function requireWebhookSecret(candidate) {
|
|
37
|
+
if (typeof candidate !== "string" || !WEBHOOK_SIGNING_SECRET_PATTERN.test(candidate)) {
|
|
38
|
+
throw new TypeError("webhookSecret is invalid");
|
|
39
|
+
}
|
|
40
|
+
return candidate;
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TimbroTransport } from "./transport-contract.ts";
|
|
2
|
+
export type SourceConnectionTransportOptions = {
|
|
3
|
+
readonly stampServerOrigin: string;
|
|
4
|
+
readonly credential: string;
|
|
5
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
6
|
+
};
|
|
7
|
+
export declare function createSourceConnectionTransport(options: SourceConnectionTransportOptions): TimbroTransport;
|
|
8
|
+
//# sourceMappingURL=source-connection-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-connection-transport.d.ts","sourceRoot":"","sources":["../src/source-connection-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC1C,CAAC;AAEF,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gCAAgC,GACxC,eAAe,CAMjB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createStampServerHttpTransport } from "./stamp-server-http-transport.js";
|
|
2
|
+
export function createSourceConnectionTransport(options) {
|
|
3
|
+
return createStampServerHttpTransport({
|
|
4
|
+
stampServerOrigin: options.stampServerOrigin,
|
|
5
|
+
authentication: { mode: "source_connection", credential: options.credential },
|
|
6
|
+
...(options.fetch === undefined ? {} : { fetch: options.fetch }),
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HostedFiscalTenant } from "./fiscal-operation.ts";
|
|
2
|
+
import { type CompleteActivationVerificationRequest, type HostedSourceCredentialResponse } from "./generated/index.ts";
|
|
3
|
+
import type { Client } from "./generated-operation-client.ts";
|
|
4
|
+
import { type ReadonlyCamelCase } from "./public-case.ts";
|
|
5
|
+
export type SourceConnectionActivationVerificationCommand = {
|
|
6
|
+
readonly sourceConnectionId: string;
|
|
7
|
+
readonly verification: CompleteActivationVerificationRequest;
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
export declare function completeSourceConnectionActivationVerificationResource(client: Client, command: SourceConnectionActivationVerificationCommand): Promise<void>;
|
|
11
|
+
export type HostedSandboxSourceCredentialIssueCommand = {
|
|
12
|
+
readonly hosted: Pick<HostedFiscalTenant, "checkoutTenantId">;
|
|
13
|
+
readonly environment?: HostedFiscalTenant["environment"];
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
export type HostedSandboxSourceCredential = ReadonlyCamelCase<HostedSourceCredentialResponse>;
|
|
17
|
+
export declare function issueHostedSandboxSourceCredentialResource(client: Client, command: HostedSandboxSourceCredentialIssueCommand): Promise<HostedSandboxSourceCredential>;
|
|
18
|
+
//# sourceMappingURL=source-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-connection.d.ts","sourceRoot":"","sources":["../src/source-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EACL,KAAK,qCAAqC,EAE1C,KAAK,8BAA8B,EAEpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,kBAAkB,CAAC;AAExE,MAAM,MAAM,6CAA6C,GAAG;IAC1D,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,qCAAqC,CAAC;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,wBAAsB,sDAAsD,CAC1E,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,6CAA6C,GACrD,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,MAAM,MAAM,yCAAyC,GAAG;IACtD,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;IAC9D,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACzD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;AAE9F,wBAAsB,0CAA0C,CAC9D,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,yCAAyC,GACjD,OAAO,CAAC,6BAA6B,CAAC,CAiBxC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { completeSourceConnectionActivationVerification, issueHostedSandboxSourceCredential, } from "./generated/index.js";
|
|
2
|
+
import { throwGeneratedProblem } from "./generated-problem.js";
|
|
3
|
+
import { toPublicCase } from "./public-case.js";
|
|
4
|
+
export async function completeSourceConnectionActivationVerificationResource(client, command) {
|
|
5
|
+
if (command.sourceConnectionId.trim() === "") {
|
|
6
|
+
throw new TypeError("sourceConnectionId must not be blank");
|
|
7
|
+
}
|
|
8
|
+
const response = await completeSourceConnectionActivationVerification({
|
|
9
|
+
client,
|
|
10
|
+
body: command.verification,
|
|
11
|
+
path: { source_connection_id: command.sourceConnectionId },
|
|
12
|
+
...(command.signal === undefined ? {} : { signal: command.signal }),
|
|
13
|
+
});
|
|
14
|
+
if (response.status !== 204) {
|
|
15
|
+
throwGeneratedProblem(response, "Source connection activation verification failed");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function issueHostedSandboxSourceCredentialResource(client, command) {
|
|
19
|
+
if (command.hosted.checkoutTenantId.trim() === "") {
|
|
20
|
+
throw new TypeError("hosted.checkoutTenantId must not be blank");
|
|
21
|
+
}
|
|
22
|
+
const environment = command.environment ?? "sandbox";
|
|
23
|
+
if (environment !== "sandbox") {
|
|
24
|
+
throw new TypeError("environment must be sandbox");
|
|
25
|
+
}
|
|
26
|
+
const response = await issueHostedSandboxSourceCredential({
|
|
27
|
+
client,
|
|
28
|
+
body: { checkout_tenant_id: command.hosted.checkoutTenantId, environment },
|
|
29
|
+
...(command.signal === undefined ? {} : { signal: command.signal }),
|
|
30
|
+
});
|
|
31
|
+
if (response.status !== 201) {
|
|
32
|
+
throwGeneratedProblem(response, "Sandbox Source credential issuance failed");
|
|
33
|
+
}
|
|
34
|
+
return toPublicCase(response.body);
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TimbroTransport } from "./transport-contract.ts";
|
|
2
|
+
/** Answers one outbound request's bearer token, so a short-lived token is never held across calls. */
|
|
3
|
+
export type StampServerBearerTokenProvider = () => string | Promise<string>;
|
|
4
|
+
export type StampServerHttpAuthentication = {
|
|
5
|
+
readonly mode: "none";
|
|
6
|
+
} | {
|
|
7
|
+
readonly mode: "source_connection";
|
|
8
|
+
readonly credential: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly mode: "bearer";
|
|
11
|
+
readonly token: StampServerBearerTokenProvider;
|
|
12
|
+
} | {
|
|
13
|
+
readonly mode: "workspace_session";
|
|
14
|
+
};
|
|
15
|
+
export type StampServerHttpTransportOptions = {
|
|
16
|
+
readonly stampServerOrigin: string;
|
|
17
|
+
readonly authentication: StampServerHttpAuthentication;
|
|
18
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
19
|
+
/** Maximum bytes retained from a non-JSON response, when set by a caller. */
|
|
20
|
+
readonly maxBinaryResponseBytes?: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function createStampServerHttpTransport(options: StampServerHttpTransportOptions): TimbroTransport;
|
|
23
|
+
//# sourceMappingURL=stamp-server-http-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stamp-server-http-transport.d.ts","sourceRoot":"","sources":["../src/stamp-server-http-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EAGhB,MAAM,yBAAyB,CAAC;AAEjC,sGAAsG;AACtG,MAAM,MAAM,8BAA8B,GAAG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE5E,MAAM,MAAM,6BAA6B,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACnE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,8BAA8B,CAAA;CAAE,GAC3E;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE3C,MAAM,MAAM,+BAA+B,GAAG;IAC5C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,6BAA6B,CAAC;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,6EAA6E;IAC7E,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;CAC1C,CAAC;AAMF,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,eAAe,CAoCjB"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { FiscalError } from "./fiscal-error.js";
|
|
2
|
+
const CONTENT_TYPE_HEADER = "content-type";
|
|
3
|
+
const JSON_MEDIA_TYPE = "application/json";
|
|
4
|
+
const DECIMAL_INTEGER_PATTERN = /^\d+$/;
|
|
5
|
+
export function createStampServerHttpTransport(options) {
|
|
6
|
+
const stampServerOrigin = parseStampServerOrigin(options.stampServerOrigin);
|
|
7
|
+
const sendHttpRequest = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
8
|
+
return {
|
|
9
|
+
async send(request) {
|
|
10
|
+
const url = `${stampServerOrigin}${request.path}`;
|
|
11
|
+
const headers = {
|
|
12
|
+
...(request.body === undefined ? {} : { [CONTENT_TYPE_HEADER]: JSON_MEDIA_TYPE }),
|
|
13
|
+
...callerHeaders(request.headers),
|
|
14
|
+
};
|
|
15
|
+
const authenticatedHeaders = await buildAuthenticatedHeaders(headers, options.authentication);
|
|
16
|
+
try {
|
|
17
|
+
const response = await sendHttpRequest(url, {
|
|
18
|
+
method: request.method,
|
|
19
|
+
headers: authenticatedHeaders,
|
|
20
|
+
credentials: options.authentication.mode === "workspace_session" ? "include" : "omit",
|
|
21
|
+
...(request.body === undefined ? {} : { body: request.body }),
|
|
22
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
status: response.status,
|
|
26
|
+
headers: new Map(response.headers),
|
|
27
|
+
body: await decodeResponseBody(response, options.maxBinaryResponseBytes),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (cause) {
|
|
31
|
+
if (cause instanceof ResponseBodyTooLarge) {
|
|
32
|
+
// biome-ignore lint/style/useErrorCause: FiscalError already exposes the bounded transport failure detail.
|
|
33
|
+
throw new FiscalError(cause.message, { failure: "server_processing" }, { cause });
|
|
34
|
+
}
|
|
35
|
+
throw describeTransportFailure(cause, request.signal, url);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async function buildAuthenticatedHeaders(headers, authentication) {
|
|
41
|
+
if (authentication.mode === "source_connection") {
|
|
42
|
+
return { ...headers, authorization: `Bearer ${authentication.credential}` };
|
|
43
|
+
}
|
|
44
|
+
if (authentication.mode === "bearer") {
|
|
45
|
+
return { ...headers, authorization: `Bearer ${await mintBearerToken(authentication.token)}` };
|
|
46
|
+
}
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
async function mintBearerToken(token) {
|
|
50
|
+
const minted = await token();
|
|
51
|
+
if (typeof minted !== "string" || minted.trim() === "") {
|
|
52
|
+
throw new TypeError("the bearer token provider answered no token");
|
|
53
|
+
}
|
|
54
|
+
return minted;
|
|
55
|
+
}
|
|
56
|
+
function parseStampServerOrigin(stampServerOrigin) {
|
|
57
|
+
let parsedOrigin;
|
|
58
|
+
try {
|
|
59
|
+
parsedOrigin = new URL(stampServerOrigin);
|
|
60
|
+
}
|
|
61
|
+
catch (cause) {
|
|
62
|
+
throw new Error("stampServerOrigin must be an absolute HTTP(S) origin", { cause });
|
|
63
|
+
}
|
|
64
|
+
if ((parsedOrigin.protocol !== "http:" && parsedOrigin.protocol !== "https:") ||
|
|
65
|
+
parsedOrigin.username !== "" ||
|
|
66
|
+
parsedOrigin.password !== "" ||
|
|
67
|
+
parsedOrigin.search !== "" ||
|
|
68
|
+
parsedOrigin.hash !== "" ||
|
|
69
|
+
parsedOrigin.pathname !== "/") {
|
|
70
|
+
throw new Error("stampServerOrigin must use HTTP(S), have no credentials/query/fragment, and have pathname /");
|
|
71
|
+
}
|
|
72
|
+
if (stampServerOrigin !== parsedOrigin.origin &&
|
|
73
|
+
stampServerOrigin !== `${parsedOrigin.origin}/`) {
|
|
74
|
+
throw new Error("stampServerOrigin must be the canonical HTTP(S) origin");
|
|
75
|
+
}
|
|
76
|
+
return parsedOrigin.origin;
|
|
77
|
+
}
|
|
78
|
+
/** One lowercase name per header, so no header reaches the wire twice under two spellings. */
|
|
79
|
+
function callerHeaders(headers) {
|
|
80
|
+
return Object.fromEntries(Object.entries(headers)
|
|
81
|
+
.map(([name, value]) => [name.toLowerCase(), value])
|
|
82
|
+
.filter(([name]) => name !== "authorization"));
|
|
83
|
+
}
|
|
84
|
+
function describeTransportFailure(cause, signal, url) {
|
|
85
|
+
if (signal?.aborted === true && signal.reason?.name === "TimeoutError") {
|
|
86
|
+
return new FiscalError(`the request to ${url} timed out`, { failure: "timeout" }, { cause });
|
|
87
|
+
}
|
|
88
|
+
if (signal?.aborted === true) {
|
|
89
|
+
return new FiscalError(`the request to ${url} was cancelled`, { failure: "cancelled" }, { cause });
|
|
90
|
+
}
|
|
91
|
+
return new FiscalError(`the request to ${url} could not reach Timbro`, { failure: "connectivity" }, { cause });
|
|
92
|
+
}
|
|
93
|
+
async function decodeResponseBody(response, maxBinaryResponseBytes) {
|
|
94
|
+
if (response.status === 204 || response.status === 205) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const contentType = response.headers.get("content-type")?.toLowerCase();
|
|
98
|
+
if (contentType?.includes("json") !== true) {
|
|
99
|
+
return readBinaryResponse(response, maxBinaryResponseBytes);
|
|
100
|
+
}
|
|
101
|
+
if (maxBinaryResponseBytes !== undefined) {
|
|
102
|
+
const bytes = await readBinaryResponse(response, maxBinaryResponseBytes);
|
|
103
|
+
return decodeJsonBody(new TextDecoder().decode(bytes));
|
|
104
|
+
}
|
|
105
|
+
return decodeJsonBody(await response.text());
|
|
106
|
+
}
|
|
107
|
+
async function readBinaryResponse(response, maxBinaryResponseBytes) {
|
|
108
|
+
if (maxBinaryResponseBytes === undefined) {
|
|
109
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
110
|
+
}
|
|
111
|
+
validateBinaryResponseLimit(maxBinaryResponseBytes);
|
|
112
|
+
await rejectDeclaredResponseLength(response, maxBinaryResponseBytes);
|
|
113
|
+
if (response.body === null) {
|
|
114
|
+
return readArrayBufferWithinLimit(response, maxBinaryResponseBytes);
|
|
115
|
+
}
|
|
116
|
+
return readStreamWithinLimit(response.body, maxBinaryResponseBytes);
|
|
117
|
+
}
|
|
118
|
+
function validateBinaryResponseLimit(maxBinaryResponseBytes) {
|
|
119
|
+
if (!Number.isSafeInteger(maxBinaryResponseBytes) || maxBinaryResponseBytes < 1) {
|
|
120
|
+
throw new TypeError("maxBinaryResponseBytes must be a positive safe integer");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function rejectDeclaredResponseLength(response, maxBinaryResponseBytes) {
|
|
124
|
+
const declaredLength = response.headers.get("content-length");
|
|
125
|
+
if (declaredLength === null || !DECIMAL_INTEGER_PATTERN.test(declaredLength)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (BigInt(declaredLength) > BigInt(maxBinaryResponseBytes)) {
|
|
129
|
+
await response.body?.cancel().catch(() => undefined);
|
|
130
|
+
throw new ResponseBodyTooLarge(`the binary response exceeds the configured ${maxBinaryResponseBytes}-byte limit`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function readArrayBufferWithinLimit(response, maxBinaryResponseBytes) {
|
|
134
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
135
|
+
if (bytes.byteLength > maxBinaryResponseBytes) {
|
|
136
|
+
throw new ResponseBodyTooLarge(`the binary response exceeds the configured ${maxBinaryResponseBytes}-byte limit`);
|
|
137
|
+
}
|
|
138
|
+
return bytes;
|
|
139
|
+
}
|
|
140
|
+
async function readStreamWithinLimit(stream, maxBinaryResponseBytes) {
|
|
141
|
+
const reader = stream.getReader();
|
|
142
|
+
const chunks = [];
|
|
143
|
+
let byteLength = 0;
|
|
144
|
+
try {
|
|
145
|
+
for (;;) {
|
|
146
|
+
const result = await reader.read();
|
|
147
|
+
if (result.done) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const chunk = result.value;
|
|
151
|
+
if (byteLength > maxBinaryResponseBytes - chunk.byteLength) {
|
|
152
|
+
await reader.cancel();
|
|
153
|
+
throw new ResponseBodyTooLarge(`the binary response exceeds the configured ${maxBinaryResponseBytes}-byte limit`);
|
|
154
|
+
}
|
|
155
|
+
chunks.push(chunk);
|
|
156
|
+
byteLength += chunk.byteLength;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
reader.releaseLock();
|
|
161
|
+
}
|
|
162
|
+
const bytes = new Uint8Array(byteLength);
|
|
163
|
+
let offset = 0;
|
|
164
|
+
for (const chunk of chunks) {
|
|
165
|
+
bytes.set(chunk, offset);
|
|
166
|
+
offset += chunk.byteLength;
|
|
167
|
+
}
|
|
168
|
+
return bytes;
|
|
169
|
+
}
|
|
170
|
+
class ResponseBodyTooLarge extends Error {
|
|
171
|
+
}
|
|
172
|
+
function decodeJsonBody(text) {
|
|
173
|
+
try {
|
|
174
|
+
return JSON.parse(text);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type CertificateCustodyImportCommand, type CertificateCustodyImportResult } from "./certificate-custody-import.ts";
|
|
2
|
+
import { type CertificateCustodyReadiness } from "./certificate-custody-readiness.ts";
|
|
3
|
+
import { type FiscalDeliveryCreateCommand } from "./fiscal-delivery.ts";
|
|
4
|
+
import { type FiscalNumberingReadiness } from "./fiscal-numbering-readiness.ts";
|
|
5
|
+
import type { FiscalOperationResource } from "./fiscal-operation.ts";
|
|
6
|
+
import { type FiscalDocumentIssueCommand, type FiscalDocumentListCommand, type FiscalDocumentPage, type HostedFiscalTenant } from "./fiscal-operation.ts";
|
|
7
|
+
import { type FiscalOperationTimingReport } from "./fiscal-operation-timing.ts";
|
|
8
|
+
import { type FiscalReceiptCommand, type FiscalReceiptReference, type FiscalReceiptResource } from "./fiscal-receipt.ts";
|
|
9
|
+
import type { FiscalDeliveryResource, WebhookDelivery, WebhookDeliveryPage } from "./generated/index.ts";
|
|
10
|
+
import { type PrintedRepresentationDownload } from "./printed-representation.ts";
|
|
11
|
+
import { type CommercialResponse, type ReceivedDocumentListCommand, type ReceivedDocumentPage, type ReceivedDocumentResource, type ReceivedDocumentSignedDocumentDownload } from "./received-documents.ts";
|
|
12
|
+
import { type SignedDocumentDownload } from "./signed-document.ts";
|
|
13
|
+
import { type HostedSandboxSourceCredential, type HostedSandboxSourceCredentialIssueCommand, type SourceConnectionActivationVerificationCommand } from "./source-connection.ts";
|
|
14
|
+
import { type StampServerBearerTokenProvider } from "./stamp-server-http-transport.ts";
|
|
15
|
+
import { type WebhookDeliveryListCommand } from "./webhook-delivery.ts";
|
|
16
|
+
import type { DeliveredWebhookEvent } from "./webhook-event.ts";
|
|
17
|
+
import { type WebhookRegistration, type WebhookRegistrationCommand } from "./webhook-registration.ts";
|
|
18
|
+
import { type WebhookReplay, type WebhookReplayCommand } from "./webhook-replay.ts";
|
|
19
|
+
import { type WebhookVerificationCommand } from "./webhook-verification.ts";
|
|
20
|
+
export type TimbroClientOptions = {
|
|
21
|
+
readonly baseUrl: string;
|
|
22
|
+
readonly authentication: TimbroClientAuthentication;
|
|
23
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
24
|
+
};
|
|
25
|
+
/** Authentication accepted by the high-level fiscal client.
|
|
26
|
+
*
|
|
27
|
+
* The lower-level HTTP transport also serves Workspace and unauthenticated helper clients.
|
|
28
|
+
*/
|
|
29
|
+
export type TimbroClientAuthentication = {
|
|
30
|
+
readonly mode: "source_connection";
|
|
31
|
+
readonly credential: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly mode: "bearer";
|
|
34
|
+
readonly token: StampServerBearerTokenProvider;
|
|
35
|
+
};
|
|
36
|
+
export type TimbroClient = {
|
|
37
|
+
readonly fiscalDocuments: {
|
|
38
|
+
readonly shareReceipt: (command: {
|
|
39
|
+
readonly fiscalOperationId: string;
|
|
40
|
+
readonly signal?: AbortSignal;
|
|
41
|
+
}) => Promise<FiscalReceiptReference>;
|
|
42
|
+
readonly issue: (command: FiscalDocumentIssueCommand) => Promise<FiscalOperationResource>;
|
|
43
|
+
readonly get: (command: {
|
|
44
|
+
readonly fiscalOperationId: string;
|
|
45
|
+
readonly signal?: AbortSignal;
|
|
46
|
+
}) => Promise<FiscalOperationResource | undefined>;
|
|
47
|
+
readonly list: (command?: FiscalDocumentListCommand) => Promise<FiscalDocumentPage>;
|
|
48
|
+
readonly findBySource: (command: {
|
|
49
|
+
readonly source: {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly version: string;
|
|
52
|
+
};
|
|
53
|
+
readonly hosted?: HostedFiscalTenant;
|
|
54
|
+
readonly signal?: AbortSignal;
|
|
55
|
+
}) => Promise<FiscalOperationResource | undefined>;
|
|
56
|
+
readonly getTiming: (command: {
|
|
57
|
+
readonly fiscalOperationId: string;
|
|
58
|
+
readonly signal?: AbortSignal;
|
|
59
|
+
}) => Promise<FiscalOperationTimingReport | undefined>;
|
|
60
|
+
};
|
|
61
|
+
readonly fiscalNumbering: {
|
|
62
|
+
readonly getReadiness: (command?: {
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
}) => Promise<FiscalNumberingReadiness>;
|
|
65
|
+
};
|
|
66
|
+
readonly certificateCustody: {
|
|
67
|
+
readonly getReadiness: (command?: {
|
|
68
|
+
readonly signal?: AbortSignal;
|
|
69
|
+
}) => Promise<CertificateCustodyReadiness>;
|
|
70
|
+
readonly import: (command: CertificateCustodyImportCommand) => Promise<CertificateCustodyImportResult>;
|
|
71
|
+
};
|
|
72
|
+
readonly fiscalArtifacts: {
|
|
73
|
+
readonly downloadSignedDocument: (command: {
|
|
74
|
+
readonly fiscalOperationId: string;
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
}) => Promise<SignedDocumentDownload>;
|
|
77
|
+
readonly downloadPrintedRepresentation: (command: {
|
|
78
|
+
readonly fiscalOperationId: string;
|
|
79
|
+
readonly signal?: AbortSignal;
|
|
80
|
+
}) => Promise<PrintedRepresentationDownload>;
|
|
81
|
+
};
|
|
82
|
+
readonly fiscalReceipts: {
|
|
83
|
+
readonly get: (command: FiscalReceiptCommand) => Promise<FiscalReceiptResource | undefined>;
|
|
84
|
+
readonly downloadPrintedRepresentation: (command: FiscalReceiptCommand) => Promise<PrintedRepresentationDownload>;
|
|
85
|
+
};
|
|
86
|
+
readonly fiscalDeliveries: {
|
|
87
|
+
readonly create: (command: FiscalDeliveryCreateCommand) => Promise<FiscalDeliveryResource>;
|
|
88
|
+
readonly get: (command: {
|
|
89
|
+
readonly deliveryId: string;
|
|
90
|
+
readonly signal?: AbortSignal;
|
|
91
|
+
}) => Promise<FiscalDeliveryResource | undefined>;
|
|
92
|
+
};
|
|
93
|
+
readonly receivedDocuments: {
|
|
94
|
+
readonly list: (command?: ReceivedDocumentListCommand) => Promise<ReceivedDocumentPage>;
|
|
95
|
+
readonly get: (command: {
|
|
96
|
+
readonly fiscalReceptionId: string;
|
|
97
|
+
readonly signal?: AbortSignal;
|
|
98
|
+
}) => Promise<ReceivedDocumentResource>;
|
|
99
|
+
readonly respond: (command: {
|
|
100
|
+
readonly fiscalReceptionId: string;
|
|
101
|
+
readonly response: CommercialResponse;
|
|
102
|
+
readonly signal?: AbortSignal;
|
|
103
|
+
}) => Promise<ReceivedDocumentResource>;
|
|
104
|
+
readonly downloadSignedDocument: (command: {
|
|
105
|
+
readonly fiscalReceptionId: string;
|
|
106
|
+
readonly signal?: AbortSignal;
|
|
107
|
+
}) => Promise<ReceivedDocumentSignedDocumentDownload>;
|
|
108
|
+
};
|
|
109
|
+
readonly sourceConnections: {
|
|
110
|
+
readonly completeActivationVerification: (command: SourceConnectionActivationVerificationCommand) => Promise<void>;
|
|
111
|
+
readonly issueSandboxCredential: (command: HostedSandboxSourceCredentialIssueCommand) => Promise<HostedSandboxSourceCredential>;
|
|
112
|
+
};
|
|
113
|
+
readonly webhookDeliveries: {
|
|
114
|
+
readonly list: (command: WebhookDeliveryListCommand) => Promise<WebhookDeliveryPage>;
|
|
115
|
+
readonly listAll: (command: WebhookDeliveryListCommand) => AsyncIterable<WebhookDelivery>;
|
|
116
|
+
};
|
|
117
|
+
readonly webhooks: {
|
|
118
|
+
readonly register: (command: WebhookRegistrationCommand) => Promise<WebhookRegistration>;
|
|
119
|
+
readonly replay: (command: WebhookReplayCommand) => Promise<WebhookReplay>;
|
|
120
|
+
readonly verify: (command: WebhookVerificationCommand) => Promise<DeliveredWebhookEvent>;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export declare function createTimbroClient(options: TimbroClientOptions): TimbroClient;
|
|
124
|
+
//# sourceMappingURL=timbro-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timbro-client.d.ts","sourceRoot":"","sources":["../src/timbro-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,8BAA8B,EAEpC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,C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;YACzC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;YACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;SAC/B,KAAK,OAAO,CAAC,sCAAsC,CAAC,CAAC;KACvD,CAAC;IACF,QAAQ,CAAC,iBAAiB,EAAE;QAC1B,QAAQ,CAAC,8BAA8B,EAAE,CACvC,OAAO,EAAE,6CAA6C,KACnD,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,QAAQ,CAAC,sBAAsB,EAAE,CAC/B,OAAO,EAAE,yCAAyC,KAC/C,OAAO,CAAC,6BAA6B,CAAC,CAAC;KAC7C,CAAC;IACF,QAAQ,CAAC,iBAAiB,EAAE;QAC1B,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACrF,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,aAAa,CAAC,eAAe,CAAC,CAAC;KAC3F,CAAC;IACF,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACzF,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;QAC3E,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;KAC1F,CAAC;CACH,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CA8F7E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { importHostedCertificateCustodyResource, } from "./certificate-custody-import.js";
|
|
2
|
+
import { readCertificateCustodyReadinessResource, } from "./certificate-custody-readiness.js";
|
|
3
|
+
import { createFiscalDeliveryResource, getFiscalDeliveryResource, } from "./fiscal-delivery.js";
|
|
4
|
+
import { readFiscalNumberingReadinessResource, } from "./fiscal-numbering-readiness.js";
|
|
5
|
+
import { findFiscalOperationBySourceResource, getFiscalOperationResource, issueFiscalDocumentResource, listFiscalOperationResources, } from "./fiscal-operation.js";
|
|
6
|
+
import { getFiscalOperationTimingResource, } from "./fiscal-operation-timing.js";
|
|
7
|
+
import { downloadFiscalReceiptPrintedRepresentation, getFiscalReceiptResource, shareFiscalReceiptResource, } from "./fiscal-receipt.js";
|
|
8
|
+
import { createGeneratedOperationClient } from "./generated-operation-client.js";
|
|
9
|
+
import { downloadPrintedRepresentationResource, } from "./printed-representation.js";
|
|
10
|
+
import { downloadReceivedDocumentSignedDocument, getReceivedDocumentResource, listReceivedDocumentResources, respondToReceivedDocument, } from "./received-documents.js";
|
|
11
|
+
import { downloadSignedDocumentResource } from "./signed-document.js";
|
|
12
|
+
import { completeSourceConnectionActivationVerificationResource, issueHostedSandboxSourceCredentialResource, } from "./source-connection.js";
|
|
13
|
+
import { createStampServerHttpTransport, } from "./stamp-server-http-transport.js";
|
|
14
|
+
import { readEveryWebhookDelivery, readWebhookDeliveryPage, } from "./webhook-delivery.js";
|
|
15
|
+
import { registerWebhookResource, } from "./webhook-registration.js";
|
|
16
|
+
import { replayWebhookResource, } from "./webhook-replay.js";
|
|
17
|
+
import { verifyWebhookDelivery } from "./webhook-verification.js";
|
|
18
|
+
export function createTimbroClient(options) {
|
|
19
|
+
const operationClient = createGeneratedOperationClient(createStampServerHttpTransport({
|
|
20
|
+
stampServerOrigin: options.baseUrl,
|
|
21
|
+
authentication: options.authentication,
|
|
22
|
+
...(options.fetch === undefined ? {} : { fetch: options.fetch }),
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
fiscalDocuments: {
|
|
26
|
+
shareReceipt: (command) => shareFiscalReceiptResource(operationClient, command.fiscalOperationId, command.signal),
|
|
27
|
+
issue: (command) => issueFiscalDocumentResource(operationClient, command),
|
|
28
|
+
get: (command) => getFiscalOperationResource(operationClient, command.fiscalOperationId, command.signal),
|
|
29
|
+
list: (command) => listFiscalOperationResources(operationClient, command),
|
|
30
|
+
findBySource: (command) => findFiscalOperationBySourceResource(operationClient, command.source, command.hosted, command.signal),
|
|
31
|
+
getTiming: (command) => getFiscalOperationTimingResource(operationClient, command.fiscalOperationId, command.signal),
|
|
32
|
+
},
|
|
33
|
+
fiscalNumbering: {
|
|
34
|
+
getReadiness: (command) => readFiscalNumberingReadinessResource(operationClient, command?.signal),
|
|
35
|
+
},
|
|
36
|
+
certificateCustody: {
|
|
37
|
+
getReadiness: (command) => readCertificateCustodyReadinessResource(operationClient, command?.signal),
|
|
38
|
+
import: (command) => importHostedCertificateCustodyResource(operationClient, command),
|
|
39
|
+
},
|
|
40
|
+
fiscalArtifacts: {
|
|
41
|
+
downloadSignedDocument: (command) => downloadSignedDocumentResource(operationClient, command.fiscalOperationId, command.signal),
|
|
42
|
+
downloadPrintedRepresentation: (command) => downloadPrintedRepresentationResource(operationClient, command.fiscalOperationId, command.signal),
|
|
43
|
+
},
|
|
44
|
+
receivedDocuments: {
|
|
45
|
+
list: (command) => listReceivedDocumentResources(operationClient, command),
|
|
46
|
+
get: (command) => getReceivedDocumentResource(operationClient, command.fiscalReceptionId, command.signal),
|
|
47
|
+
respond: (command) => respondToReceivedDocument(operationClient, command.fiscalReceptionId, command.response, command.signal),
|
|
48
|
+
downloadSignedDocument: (command) => downloadReceivedDocumentSignedDocument(operationClient, command.fiscalReceptionId, command.signal),
|
|
49
|
+
},
|
|
50
|
+
fiscalReceipts: {
|
|
51
|
+
get: (command) => getFiscalReceiptResource(options, command),
|
|
52
|
+
downloadPrintedRepresentation: (command) => downloadFiscalReceiptPrintedRepresentation(options, command),
|
|
53
|
+
},
|
|
54
|
+
fiscalDeliveries: {
|
|
55
|
+
create: (command) => createFiscalDeliveryResource(operationClient, command),
|
|
56
|
+
get: (command) => getFiscalDeliveryResource(operationClient, command.deliveryId, command.signal),
|
|
57
|
+
},
|
|
58
|
+
sourceConnections: {
|
|
59
|
+
completeActivationVerification: (command) => completeSourceConnectionActivationVerificationResource(operationClient, command),
|
|
60
|
+
issueSandboxCredential: (command) => issueHostedSandboxSourceCredentialResource(operationClient, command),
|
|
61
|
+
},
|
|
62
|
+
webhookDeliveries: {
|
|
63
|
+
list: (command) => readWebhookDeliveryPage(operationClient, command),
|
|
64
|
+
listAll: (command) => readEveryWebhookDelivery(operationClient, command),
|
|
65
|
+
},
|
|
66
|
+
webhooks: {
|
|
67
|
+
register: (command) => registerWebhookResource(operationClient, command),
|
|
68
|
+
replay: (command) => replayWebhookResource(operationClient, command),
|
|
69
|
+
verify: (command) => verifyWebhookDelivery(command),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|