@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.
Files changed (144) hide show
  1. package/README.md +308 -0
  2. package/dist/artifact-headers.d.ts +9 -0
  3. package/dist/artifact-headers.d.ts.map +1 -0
  4. package/dist/artifact-headers.js +43 -0
  5. package/dist/certificate-custody-import.d.ts +13 -0
  6. package/dist/certificate-custody-import.d.ts.map +1 -0
  7. package/dist/certificate-custody-import.js +30 -0
  8. package/dist/certificate-custody-readiness.d.ts +6 -0
  9. package/dist/certificate-custody-readiness.d.ts.map +1 -0
  10. package/dist/certificate-custody-readiness.js +13 -0
  11. package/dist/collection.d.ts +13 -0
  12. package/dist/collection.d.ts.map +1 -0
  13. package/dist/collection.js +21 -0
  14. package/dist/direct-connection.d.ts +74 -0
  15. package/dist/direct-connection.d.ts.map +1 -0
  16. package/dist/direct-connection.js +192 -0
  17. package/dist/document-node.d.ts +15 -0
  18. package/dist/document-node.d.ts.map +1 -0
  19. package/dist/document-node.js +67 -0
  20. package/dist/document-worker-protocol.d.ts +30 -0
  21. package/dist/document-worker-protocol.d.ts.map +1 -0
  22. package/dist/document-worker-protocol.js +103 -0
  23. package/dist/document-worker.d.ts +2 -0
  24. package/dist/document-worker.d.ts.map +1 -0
  25. package/dist/document-worker.js +71 -0
  26. package/dist/document.d.ts +38 -0
  27. package/dist/document.d.ts.map +1 -0
  28. package/dist/document.js +204 -0
  29. package/dist/fiscal-delivery.d.ts +12 -0
  30. package/dist/fiscal-delivery.d.ts.map +1 -0
  31. package/dist/fiscal-delivery.js +45 -0
  32. package/dist/fiscal-engine-runtime.manifest.json +637 -0
  33. package/dist/fiscal-engine-runtime.provenance.json +1010 -0
  34. package/dist/fiscal-error.d.ts +23 -0
  35. package/dist/fiscal-error.d.ts.map +1 -0
  36. package/dist/fiscal-error.js +36 -0
  37. package/dist/fiscal-numbering-readiness.d.ts +6 -0
  38. package/dist/fiscal-numbering-readiness.d.ts.map +1 -0
  39. package/dist/fiscal-numbering-readiness.js +13 -0
  40. package/dist/fiscal-operation-timing.d.ts +9 -0
  41. package/dist/fiscal-operation-timing.d.ts.map +1 -0
  42. package/dist/fiscal-operation-timing.js +22 -0
  43. package/dist/fiscal-operation.d.ts +112 -0
  44. package/dist/fiscal-operation.d.ts.map +1 -0
  45. package/dist/fiscal-operation.js +193 -0
  46. package/dist/fiscal-receipt.d.ts +19 -0
  47. package/dist/fiscal-receipt.d.ts.map +1 -0
  48. package/dist/fiscal-receipt.js +66 -0
  49. package/dist/generated/index.d.ts +5 -0
  50. package/dist/generated/index.d.ts.map +1 -0
  51. package/dist/generated/index.js +4 -0
  52. package/dist/generated/problem-catalog.d.ts +7 -0
  53. package/dist/generated/problem-catalog.d.ts.map +1 -0
  54. package/dist/generated/problem-catalog.js +198 -0
  55. package/dist/generated/sdk.gen.d.ts +240 -0
  56. package/dist/generated/sdk.gen.d.ts.map +1 -0
  57. package/dist/generated/sdk.gen.js +4486 -0
  58. package/dist/generated/types.gen.d.ts +6906 -0
  59. package/dist/generated/types.gen.d.ts.map +1 -0
  60. package/dist/generated/types.gen.js +2 -0
  61. package/dist/generated/zod.gen.d.ts +146666 -0
  62. package/dist/generated/zod.gen.d.ts.map +1 -0
  63. package/dist/generated/zod.gen.js +25077 -0
  64. package/dist/generated-operation-client.d.ts +47 -0
  65. package/dist/generated-operation-client.d.ts.map +1 -0
  66. package/dist/generated-operation-client.js +112 -0
  67. package/dist/generated-problem.d.ts +12 -0
  68. package/dist/generated-problem.d.ts.map +1 -0
  69. package/dist/generated-problem.js +37 -0
  70. package/dist/hosted-tenant.d.ts +38 -0
  71. package/dist/hosted-tenant.d.ts.map +1 -0
  72. package/dist/hosted-tenant.js +67 -0
  73. package/dist/hosted-workspace-transport.d.ts +15 -0
  74. package/dist/hosted-workspace-transport.d.ts.map +1 -0
  75. package/dist/hosted-workspace-transport.js +15 -0
  76. package/dist/idempotency-key.d.ts +3 -0
  77. package/dist/idempotency-key.d.ts.map +1 -0
  78. package/dist/idempotency-key.js +11 -0
  79. package/dist/index.d.ts +42 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +14 -0
  82. package/dist/printed-representation.d.ts +23 -0
  83. package/dist/printed-representation.d.ts.map +1 -0
  84. package/dist/printed-representation.js +135 -0
  85. package/dist/problem-contract.d.ts +265 -0
  86. package/dist/problem-contract.d.ts.map +1 -0
  87. package/dist/problem-contract.js +25 -0
  88. package/dist/public-case.d.ts +15 -0
  89. package/dist/public-case.d.ts.map +1 -0
  90. package/dist/public-case.js +26 -0
  91. package/dist/received-documents.d.ts +35 -0
  92. package/dist/received-documents.d.ts.map +1 -0
  93. package/dist/received-documents.js +83 -0
  94. package/dist/sha256.d.ts +2 -0
  95. package/dist/sha256.d.ts.map +1 -0
  96. package/dist/sha256.js +6 -0
  97. package/dist/signed-document.d.ts +15 -0
  98. package/dist/signed-document.d.ts.map +1 -0
  99. package/dist/signed-document.js +57 -0
  100. package/dist/source-command-validation.d.ts +3 -0
  101. package/dist/source-command-validation.d.ts.map +1 -0
  102. package/dist/source-command-validation.js +14 -0
  103. package/dist/source-connection-activation.d.ts +18 -0
  104. package/dist/source-connection-activation.d.ts.map +1 -0
  105. package/dist/source-connection-activation.js +41 -0
  106. package/dist/source-connection-transport.d.ts +8 -0
  107. package/dist/source-connection-transport.d.ts.map +1 -0
  108. package/dist/source-connection-transport.js +8 -0
  109. package/dist/source-connection.d.ts +18 -0
  110. package/dist/source-connection.d.ts.map +1 -0
  111. package/dist/source-connection.js +35 -0
  112. package/dist/stamp-server-http-transport.d.ts +23 -0
  113. package/dist/stamp-server-http-transport.d.ts.map +1 -0
  114. package/dist/stamp-server-http-transport.js +179 -0
  115. package/dist/timbro-client.d.ts +124 -0
  116. package/dist/timbro-client.d.ts.map +1 -0
  117. package/dist/timbro-client.js +72 -0
  118. package/dist/timbro_fiscal_engine.js +239 -0
  119. package/dist/timbro_fiscal_engine_bg.wasm +0 -0
  120. package/dist/transport-contract.d.ts +16 -0
  121. package/dist/transport-contract.d.ts.map +1 -0
  122. package/dist/transport-contract.js +1 -0
  123. package/dist/webhook-delivery.d.ts +14 -0
  124. package/dist/webhook-delivery.d.ts.map +1 -0
  125. package/dist/webhook-delivery.js +32 -0
  126. package/dist/webhook-event.d.ts +2711 -0
  127. package/dist/webhook-event.d.ts.map +1 -0
  128. package/dist/webhook-event.js +15 -0
  129. package/dist/webhook-registration.d.ts +12 -0
  130. package/dist/webhook-registration.d.ts.map +1 -0
  131. package/dist/webhook-registration.js +37 -0
  132. package/dist/webhook-replay.d.ts +12 -0
  133. package/dist/webhook-replay.d.ts.map +1 -0
  134. package/dist/webhook-replay.js +27 -0
  135. package/dist/webhook-verification.d.ts +25 -0
  136. package/dist/webhook-verification.d.ts.map +1 -0
  137. package/dist/webhook-verification.js +53 -0
  138. package/dist/workspace-session-transport.d.ts +8 -0
  139. package/dist/workspace-session-transport.d.ts.map +1 -0
  140. package/dist/workspace-session-transport.js +11 -0
  141. package/dist/workspace.d.ts +74 -0
  142. package/dist/workspace.d.ts.map +1 -0
  143. package/dist/workspace.js +278 -0
  144. package/package.json +73 -0
@@ -0,0 +1,47 @@
1
+ import type { TimbroTransport, TimbroTransportResponse } from "./transport-contract.ts";
2
+ export type TDataShape = {
3
+ readonly body?: unknown;
4
+ readonly headers?: Readonly<Record<string, string | undefined>>;
5
+ readonly path?: unknown;
6
+ readonly query?: unknown;
7
+ readonly url: string;
8
+ };
9
+ export type ClientMeta = Record<string, never>;
10
+ export type Options<TData extends TDataShape, _Response> = Omit<TData, "headers" | "url"> & {
11
+ readonly headers?: Readonly<Record<string, string | undefined>>;
12
+ readonly signal?: AbortSignal;
13
+ };
14
+ export type RequestResult<Responses, Errors> = Promise<GeneratedTransportResponse<Responses, Errors>>;
15
+ type ResponseStatus<Responses> = Extract<keyof Responses, number>;
16
+ type ErrorStatus<Errors> = Extract<keyof Errors, number>;
17
+ type KnownResponse<Responses> = {
18
+ [Status in ResponseStatus<Responses>]: Omit<TimbroTransportResponse, "body" | "status"> & {
19
+ readonly status: Status;
20
+ readonly body: Responses[Status];
21
+ };
22
+ }[ResponseStatus<Responses>];
23
+ type KnownError<Errors> = {
24
+ [Status in ErrorStatus<Errors>]: Omit<TimbroTransportResponse, "body" | "status"> & {
25
+ readonly status: Status;
26
+ readonly body: Errors[Status];
27
+ };
28
+ }[ErrorStatus<Errors>];
29
+ type UnexpectedResponse = Omit<TimbroTransportResponse, "body" | "status"> & {
30
+ readonly status: "unexpected";
31
+ readonly status_code: number;
32
+ readonly body: unknown;
33
+ };
34
+ type GeneratedTransportResponse<Responses, Errors> = KnownResponse<Responses> | KnownError<Errors> | UnexpectedResponse;
35
+ type GeneratedRequest<TData extends TDataShape, Responses, Errors> = Options<TData, unknown> & {
36
+ readonly url: TData["url"];
37
+ readonly response_decoder: (response: TimbroTransportResponse) => GeneratedTransportResponse<Responses, Errors>;
38
+ };
39
+ export type Client = {
40
+ readonly get: <Responses, Errors>(request: GeneratedRequest<TDataShape, Responses, Errors>) => RequestResult<Responses, Errors>;
41
+ readonly post: <Responses, Errors>(request: GeneratedRequest<TDataShape, Responses, Errors>) => RequestResult<Responses, Errors>;
42
+ readonly put: <Responses, Errors>(request: GeneratedRequest<TDataShape, Responses, Errors>) => RequestResult<Responses, Errors>;
43
+ readonly delete: <Responses, Errors>(request: GeneratedRequest<TDataShape, Responses, Errors>) => RequestResult<Responses, Errors>;
44
+ };
45
+ export declare function createGeneratedOperationClient(transport: TimbroTransport): Client;
46
+ export {};
47
+ //# sourceMappingURL=generated-operation-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-operation-client.d.ts","sourceRoot":"","sources":["../src/generated-operation-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EAEf,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAA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AE,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,KACrD,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,EAC9B,OAAO,EAAE,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,KACrD,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EACjC,OAAO,EAAE,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,KACrD,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAWjF"}
@@ -0,0 +1,112 @@
1
+ import { FiscalError } from "./fiscal-error.js";
2
+ import { readRetryAfterSeconds } from "./generated-problem.js";
3
+ export function createGeneratedOperationClient(transport) {
4
+ return {
5
+ get: (request) => sendGeneratedRequest(transport, "GET", request),
6
+ post: (request) => sendGeneratedRequest(transport, "POST", request),
7
+ put: (request) => sendGeneratedRequest(transport, "PUT", request),
8
+ delete: (request) => sendGeneratedRequest(transport, "DELETE", request),
9
+ };
10
+ }
11
+ function sendGeneratedRequest(transport, method, request) {
12
+ return transport
13
+ .send({
14
+ method,
15
+ path: appendQuery(interpolatePath(request.url, request.path), request.query),
16
+ headers: toHeaders(request.headers),
17
+ body: request.body === undefined ? undefined : JSON.stringify(request.body),
18
+ signal: request.signal,
19
+ })
20
+ .then((response) => {
21
+ try {
22
+ return request.response_decoder(response);
23
+ }
24
+ catch (error) {
25
+ // biome-ignore lint/style/useErrorCause: the custom error keeps the generated failure detail in the second argument
26
+ throw new FiscalError("Timbro returned a response outside the generated contract", {
27
+ failure: "server_processing",
28
+ status: response.status,
29
+ retryAfterSeconds: readRetryAfterSeconds(response.headers),
30
+ }, { cause: error });
31
+ }
32
+ });
33
+ }
34
+ function interpolatePath(template, path) {
35
+ if (path === undefined) {
36
+ return template;
37
+ }
38
+ if (!isUnknownRecord(path)) {
39
+ throw new TypeError("generated operation path parameters must be an object");
40
+ }
41
+ return template.replaceAll(/\{([^}]+)\}/g, (_placeholder, name) => {
42
+ const parameter = path[name];
43
+ if (typeof parameter !== "string" &&
44
+ typeof parameter !== "number" &&
45
+ typeof parameter !== "bigint") {
46
+ throw new TypeError(`generated operation path parameter ${name} must be a string or integer`);
47
+ }
48
+ if (typeof parameter === "number" && !Number.isSafeInteger(parameter)) {
49
+ throw new TypeError(`generated operation path parameter ${name} must be a safe integer`);
50
+ }
51
+ return encodeURIComponent(String(parameter));
52
+ });
53
+ }
54
+ function appendQuery(path, query) {
55
+ if (query === undefined) {
56
+ return path;
57
+ }
58
+ if (!isUnknownRecord(query)) {
59
+ throw new TypeError("generated operation query parameters must be an object");
60
+ }
61
+ const parameters = new URLSearchParams();
62
+ for (const [name, parameter] of Object.entries(query)) {
63
+ appendQueryParameter(parameters, name, parameter);
64
+ }
65
+ return `${path}?${parameters.toString()}`;
66
+ }
67
+ function appendQueryParameter(parameters, name, parameter) {
68
+ if (parameter === undefined) {
69
+ return;
70
+ }
71
+ if (Array.isArray(parameter)) {
72
+ for (const element of parameter) {
73
+ if (!isQueryPrimitive(element)) {
74
+ throw new TypeError(`generated operation query parameter ${name} must contain only primitive values`);
75
+ }
76
+ parameters.append(name, String(element));
77
+ }
78
+ return;
79
+ }
80
+ if (!isQueryPrimitive(parameter)) {
81
+ throw new TypeError(`generated operation query parameter ${name} must be a primitive or primitive array`);
82
+ }
83
+ parameters.set(name, String(parameter));
84
+ }
85
+ function isQueryPrimitive(candidate) {
86
+ return (typeof candidate === "string" ||
87
+ typeof candidate === "number" ||
88
+ typeof candidate === "boolean" ||
89
+ typeof candidate === "bigint");
90
+ }
91
+ function toHeaders(headers) {
92
+ if (headers === undefined) {
93
+ return {};
94
+ }
95
+ if (!isUnknownRecord(headers)) {
96
+ throw new TypeError("generated operation headers must be an object");
97
+ }
98
+ const result = {};
99
+ for (const [name, header] of Object.entries(headers)) {
100
+ if (header === undefined) {
101
+ continue;
102
+ }
103
+ if (typeof header !== "string") {
104
+ throw new TypeError(`generated operation header ${name} must be a string`);
105
+ }
106
+ result[name] = header;
107
+ }
108
+ return result;
109
+ }
110
+ function isUnknownRecord(candidate) {
111
+ return typeof candidate === "object" && candidate !== null && !Array.isArray(candidate);
112
+ }
@@ -0,0 +1,12 @@
1
+ import type { PublicProblemCode } from "./generated/types.gen.ts";
2
+ type GeneratedProblemResponse = {
3
+ readonly status: number | "unexpected";
4
+ readonly status_code?: number;
5
+ readonly headers?: ReadonlyMap<string, string>;
6
+ readonly body: unknown;
7
+ };
8
+ export declare function throwGeneratedProblem(response: GeneratedProblemResponse, message: string): never;
9
+ export declare function isExpectedNotFoundProblem(response: GeneratedProblemResponse, expectedCode: Extract<PublicProblemCode, "fiscal_operation_not_found" | "fiscal_delivery_not_found" | "fiscal_receipt_not_found">, message: string): boolean;
10
+ export declare function readRetryAfterSeconds(headers: ReadonlyMap<string, string> | undefined, nowMilliseconds?: number): number | undefined;
11
+ export {};
12
+ //# sourceMappingURL=generated-problem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-problem.d.ts","sourceRoot":"","sources":["../src/generated-problem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,wBAAwB,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAwBhG;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,OAAO,CACnB,iBAAiB,EACjB,4BAA4B,GAAG,2BAA2B,GAAG,0BAA0B,CACxF,EACD,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAChD,eAAe,GAAE,MAAmB,GACnC,MAAM,GAAG,SAAS,CAEpB"}
@@ -0,0 +1,37 @@
1
+ import { parseProblemFields, parseRetryAfter } from "@timbro/protocol";
2
+ import { FiscalError } from "./fiscal-error.js";
3
+ import { zProblemBody } from "./generated/zod.gen.js";
4
+ import { classifyProblemStatus } from "./problem-contract.js";
5
+ export function throwGeneratedProblem(response, message) {
6
+ const retryAfterSeconds = readRetryAfterSeconds(response.headers);
7
+ if (response.status === "unexpected") {
8
+ throw new FiscalError(message, {
9
+ failure: "server_processing",
10
+ status: response.status_code,
11
+ retryAfterSeconds,
12
+ });
13
+ }
14
+ const parsed = zProblemBody.safeParse(response.body);
15
+ if (!parsed.success) {
16
+ throw new FiscalError(message, { failure: "server_processing", status: response.status, retryAfterSeconds }, { cause: parsed.error });
17
+ }
18
+ const problemFields = parseProblemFields(parsed.data.problems);
19
+ throw new FiscalError(message, {
20
+ failure: classifyProblemStatus(parsed.data),
21
+ problem: problemFields === undefined ? parsed.data : { ...parsed.data, problems: [...problemFields] },
22
+ retryAfterSeconds,
23
+ });
24
+ }
25
+ export function isExpectedNotFoundProblem(response, expectedCode, message) {
26
+ if (response.status !== 404) {
27
+ return false;
28
+ }
29
+ const parsed = zProblemBody.safeParse(response.body);
30
+ if (parsed.success && parsed.data.code === expectedCode) {
31
+ return true;
32
+ }
33
+ throwGeneratedProblem(response, message);
34
+ }
35
+ export function readRetryAfterSeconds(headers, nowMilliseconds = Date.now()) {
36
+ return parseRetryAfter(headers?.get("retry-after"), nowMilliseconds);
37
+ }
@@ -0,0 +1,38 @@
1
+ import { type CreateHostedTenantRequest, type HostedWebhookSecretRotation as GeneratedHostedWebhookSecretRotation, type ReleasedHostedTenant as GeneratedReleasedHostedTenant, type HostedTenantResource } from "./generated/index.ts";
2
+ import { type ReadonlyCamelCase } from "./public-case.ts";
3
+ import { type StampServerBearerTokenProvider } from "./stamp-server-http-transport.ts";
4
+ export type HostedTenantEnvironment = CreateHostedTenantRequest["environment"];
5
+ export type HostedTenantCreateCommand = {
6
+ readonly checkoutTenantId: string;
7
+ readonly environment: HostedTenantEnvironment;
8
+ readonly rnc: string;
9
+ readonly signal?: AbortSignal;
10
+ };
11
+ export type HostedTenantWebhookSecretRotationCommand = {
12
+ readonly sourceConnectionId: string;
13
+ readonly idempotencyKey?: string;
14
+ readonly signal?: AbortSignal;
15
+ };
16
+ export type HostedTenantReleaseCommand = {
17
+ readonly checkoutTenantId: string;
18
+ readonly hostedTenantBindingId: string;
19
+ readonly environment: HostedTenantEnvironment;
20
+ readonly idempotencyKey: string;
21
+ readonly signal?: AbortSignal;
22
+ };
23
+ export type HostedTenant = ReadonlyCamelCase<HostedTenantResource>;
24
+ export type HostedTenantRelease = ReadonlyCamelCase<GeneratedReleasedHostedTenant>;
25
+ export type HostedWebhookSecretRotation = ReadonlyCamelCase<GeneratedHostedWebhookSecretRotation>;
26
+ export type HostedTenantClientOptions = {
27
+ readonly baseUrl: string;
28
+ readonly bearerToken: string | StampServerBearerTokenProvider;
29
+ readonly fetch?: typeof globalThis.fetch;
30
+ };
31
+ export type HostedTenantClient = {
32
+ readonly create: (command: HostedTenantCreateCommand) => Promise<HostedTenant>;
33
+ readonly release: (command: HostedTenantReleaseCommand) => Promise<HostedTenantRelease>;
34
+ readonly rotateWebhookSecret: (command: HostedTenantWebhookSecretRotationCommand) => Promise<HostedWebhookSecretRotation>;
35
+ };
36
+ /** Creates the owner-authenticated client for hosted Checkout tenant bindings. */
37
+ export declare function createHostedTenantClient(options: HostedTenantClientOptions): HostedTenantClient;
38
+ //# sourceMappingURL=hosted-tenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-tenant.d.ts","sourceRoot":"","sources":["../src/hosted-tenant.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,yBAAyB,EAG9B,KAAK,2BAA2B,IAAI,oCAAoC,EACxE,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,EAG1B,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,kCAAkC,CAAC;AAE1C,MAAM,MAAM,uBAAuB,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC;AAE/E,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,uBAAuB,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,wCAAwC,GAAG;IACrD,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,uBAAuB,CAAC;IAC9C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;AACnE,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,6BAA6B,CAAC,CAAC;AACnF,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;AAElG,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,8BAA8B,CAAC;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/E,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACxF,QAAQ,CAAC,mBAAmB,EAAE,CAC5B,OAAO,EAAE,wCAAwC,KAC9C,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC3C,CAAC;AAEF,kFAAkF;AAClF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CAkB/F"}
@@ -0,0 +1,67 @@
1
+ import { createHostedTenant, createHostedTenantWebhookSecretRotation, releaseHostedTenant, } from "./generated/index.js";
2
+ import { createGeneratedOperationClient } from "./generated-operation-client.js";
3
+ import { throwGeneratedProblem } from "./generated-problem.js";
4
+ import { toPublicCase } from "./public-case.js";
5
+ import { createStampServerHttpTransport, } from "./stamp-server-http-transport.js";
6
+ /** Creates the owner-authenticated client for hosted Checkout tenant bindings. */
7
+ export function createHostedTenantClient(options) {
8
+ const token = typeof options.bearerToken === "string"
9
+ ? () => options.bearerToken
10
+ : options.bearerToken;
11
+ const client = createGeneratedOperationClient(createStampServerHttpTransport({
12
+ stampServerOrigin: options.baseUrl,
13
+ authentication: { mode: "bearer", token },
14
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
15
+ }));
16
+ return {
17
+ create: (command) => createHostedTenantResource(client, command),
18
+ release: (command) => releaseHostedTenantBinding(client, command),
19
+ rotateWebhookSecret: (command) => rotateHostedTenantWebhookSecret(client, command),
20
+ };
21
+ }
22
+ async function createHostedTenantResource(client, command) {
23
+ const response = await createHostedTenant({
24
+ client,
25
+ body: {
26
+ checkout_tenant_id: command.checkoutTenantId,
27
+ environment: command.environment,
28
+ rnc: command.rnc,
29
+ },
30
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
31
+ });
32
+ if (response.status !== 200 && response.status !== 201) {
33
+ throwGeneratedProblem(response, "Hosted tenant creation failed");
34
+ }
35
+ return toPublicCase(response.body);
36
+ }
37
+ async function releaseHostedTenantBinding(client, command) {
38
+ const body = {
39
+ checkout_tenant_id: command.checkoutTenantId,
40
+ hosted_tenant_binding_id: command.hostedTenantBindingId,
41
+ environment: command.environment,
42
+ };
43
+ const response = await releaseHostedTenant({
44
+ client,
45
+ body,
46
+ headers: { "Idempotency-Key": command.idempotencyKey },
47
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
48
+ });
49
+ if (response.status !== 200) {
50
+ throwGeneratedProblem(response, "Hosted tenant release failed");
51
+ }
52
+ return toPublicCase(response.body);
53
+ }
54
+ async function rotateHostedTenantWebhookSecret(client, command) {
55
+ const response = await createHostedTenantWebhookSecretRotation({
56
+ client,
57
+ path: { source_connection_id: command.sourceConnectionId },
58
+ ...(command.idempotencyKey === undefined
59
+ ? {}
60
+ : { headers: { "Idempotency-Key": command.idempotencyKey } }),
61
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
62
+ });
63
+ if (response.status !== 200 && response.status !== 201) {
64
+ throwGeneratedProblem(response, "Hosted tenant Webhook secret rotation failed");
65
+ }
66
+ return toPublicCase(response.body);
67
+ }
@@ -0,0 +1,15 @@
1
+ import { type StampServerBearerTokenProvider } from "./stamp-server-http-transport.ts";
2
+ import type { TimbroTransport } from "./transport-contract.ts";
3
+ export type HostedWorkspaceTransportOptions = {
4
+ /** Stamp-server origin the Checkout BFF reaches from its server runtime. */
5
+ readonly stampServerOrigin: string;
6
+ /** Hosted Workspace bearer, resolved for each request so sessions can rotate. */
7
+ readonly bearerToken: string | StampServerBearerTokenProvider;
8
+ readonly fetch?: typeof globalThis.fetch;
9
+ };
10
+ /**
11
+ * Creates the official bearer transport for Checkout's hosted Workspace passthrough.
12
+ * This transport deliberately has no Source connection credential option.
13
+ */
14
+ export declare function createHostedWorkspaceTransport(options: HostedWorkspaceTransportOptions): TimbroTransport;
15
+ //# sourceMappingURL=hosted-workspace-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-workspace-transport.d.ts","sourceRoot":"","sources":["../src/hosted-workspace-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,4EAA4E;IAC5E,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,iFAAiF;IACjF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,8BAA8B,CAAC;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC1C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,eAAe,CAUjB"}
@@ -0,0 +1,15 @@
1
+ import { createStampServerHttpTransport, } from "./stamp-server-http-transport.js";
2
+ /**
3
+ * Creates the official bearer transport for Checkout's hosted Workspace passthrough.
4
+ * This transport deliberately has no Source connection credential option.
5
+ */
6
+ export function createHostedWorkspaceTransport(options) {
7
+ const token = typeof options.bearerToken === "string"
8
+ ? () => options.bearerToken
9
+ : options.bearerToken;
10
+ return createStampServerHttpTransport({
11
+ stampServerOrigin: options.stampServerOrigin,
12
+ authentication: { mode: "bearer", token },
13
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
14
+ });
15
+ }
@@ -0,0 +1,3 @@
1
+ export declare function isValidIdempotencyKey(candidate: string): boolean;
2
+ export declare function createIdempotencyKey(): string;
3
+ //# sourceMappingURL=idempotency-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency-key.d.ts","sourceRoot":"","sources":["../src/idempotency-key.ts"],"names":[],"mappings":"AAIA,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAMhE;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C"}
@@ -0,0 +1,11 @@
1
+ const MIN_IDEMPOTENCY_KEY_LENGTH = 16;
2
+ const MAX_IDEMPOTENCY_KEY_LENGTH = 255;
3
+ const IDEMPOTENCY_KEY_PATTERN = /^[A-Za-z0-9._:-]+$/;
4
+ export function isValidIdempotencyKey(candidate) {
5
+ const isWithinLength = candidate.length >= MIN_IDEMPOTENCY_KEY_LENGTH &&
6
+ candidate.length <= MAX_IDEMPOTENCY_KEY_LENGTH;
7
+ return isWithinLength && IDEMPOTENCY_KEY_PATTERN.test(candidate);
8
+ }
9
+ export function createIdempotencyKey() {
10
+ return globalThis.crypto.randomUUID();
11
+ }
@@ -0,0 +1,42 @@
1
+ export type { CertificateCustodyImportCommand, CertificateCustodyImportResult, } from "./certificate-custody-import.ts";
2
+ export type { CertificateCustodyReadiness } from "./certificate-custody-readiness.ts";
3
+ export type { CollectionPage } from "./collection.ts";
4
+ export { walkCollectionPages } from "./collection.ts";
5
+ export type { DirectConnectionApproval, DirectConnectionApprovalCommand, DirectConnectionClient, DirectConnectionClientOptions, DirectConnectionConfirmation, DirectConnectionCreateCommand, DirectConnectionEnvironment, DirectConnectionPoll, DirectConnectionPreview, DirectConnectionRequest, DirectConnectionRequestCommand, } from "./direct-connection.ts";
6
+ export { createDirectConnectionClient, generateDirectConnectionCredential, } from "./direct-connection.ts";
7
+ export type { FiscalDeliveryCreateCommand } from "./fiscal-delivery.ts";
8
+ export type { FiscalErrorDetail, FiscalFailure } from "./fiscal-error.ts";
9
+ export { FiscalError } from "./fiscal-error.ts";
10
+ export type { FiscalNumberingReadiness } from "./fiscal-numbering-readiness.ts";
11
+ export type { FiscalDocument, FiscalDocumentAction, FiscalDocumentIssueCommand, FiscalDocumentListCommand, FiscalDocumentNumberingInstruction, FiscalDocumentPage, FiscalOperationResource, FiscalOriginalSource, FiscalSource, HostedFiscalTenant, SourceType31Snapshot, SourceType32Snapshot, SourceType33Snapshot, SourceType34Snapshot, SourceType41Snapshot, SourceType43Snapshot, SourceType44Snapshot, SourceType45Snapshot, SourceType46Snapshot, SourceType47Snapshot, } from "./fiscal-operation.ts";
12
+ export { toFiscalDocumentSnapshot } from "./fiscal-operation.ts";
13
+ export type { FiscalOperationTimingReport, TimingStageId } from "./fiscal-operation-timing.ts";
14
+ export { TIMING_STAGE_IDS } from "./fiscal-operation-timing.ts";
15
+ export type { FiscalReceiptCommand, FiscalReceiptReference, FiscalReceiptResource, } from "./fiscal-receipt.ts";
16
+ export type { FiscalDeliveryResource, FiscalOperationOutcomeResource, PrintedRepresentationProfile, SourceCreditNoteCorrection, SourceDebitNoteCorrection, SourceFiscalAction, WebhookDelivery, WebhookDeliveryPage, WebhookDeliveryState, } from "./generated/index.ts";
17
+ export type { HostedTenant, HostedTenantClient, HostedTenantClientOptions, HostedTenantCreateCommand, HostedTenantEnvironment, HostedTenantRelease, HostedTenantReleaseCommand, HostedTenantWebhookSecretRotationCommand, HostedWebhookSecretRotation, } from "./hosted-tenant.ts";
18
+ export { createHostedTenantClient } from "./hosted-tenant.ts";
19
+ export type { HostedWorkspaceTransportOptions } from "./hosted-workspace-transport.ts";
20
+ export { createHostedWorkspaceTransport } from "./hosted-workspace-transport.ts";
21
+ export type { PrintedRepresentationDownload } from "./printed-representation.ts";
22
+ export type { ProblemBody, ProblemCatalogEntry, ProblemCode, ProblemFailure, PublicProblemCode, } from "./problem-contract.ts";
23
+ export { PROBLEM_CATALOG } from "./problem-contract.ts";
24
+ export { toWireCase } from "./public-case.ts";
25
+ export type { CommercialResponse, ReceivedDocumentListCommand, ReceivedDocumentPage, ReceivedDocumentRecoveryFilter, ReceivedDocumentResource, ReceivedDocumentResponseFilter, ReceivedDocumentSignedDocumentDownload, ReceivedDocumentStateFilter, ReceivedDocumentSummary, } from "./received-documents.ts";
26
+ export { digestSha256Hex } from "./sha256.ts";
27
+ export type { SignedDocumentDownload } from "./signed-document.ts";
28
+ export type { HostedSandboxSourceCredential, HostedSandboxSourceCredentialIssueCommand, SourceConnectionActivationVerificationCommand, } from "./source-connection.ts";
29
+ export type { SourceConnectionTransportOptions } from "./source-connection-transport.ts";
30
+ export type { StampServerBearerTokenProvider, StampServerHttpAuthentication, } from "./stamp-server-http-transport.ts";
31
+ export type { TimbroClient, TimbroClientAuthentication, TimbroClientOptions, } from "./timbro-client.ts";
32
+ export { createTimbroClient } from "./timbro-client.ts";
33
+ export type { WebhookDeliveryListCommand } from "./webhook-delivery.ts";
34
+ export type { DeliveredWebhookEvent, ReceptionWebhookEvent, WebhookEvent, } from "./webhook-event.ts";
35
+ export { parseDeliveredWebhookEvent, parseWebhookEvent, } from "./webhook-event.ts";
36
+ export type { WebhookRegistration, WebhookRegistrationCommand } from "./webhook-registration.ts";
37
+ export type { WebhookReplay, WebhookReplayCommand } from "./webhook-replay.ts";
38
+ export type { WebhookDeliveryHeaders, WebhookVerificationCommand, WebhookVerificationRejection, } from "./webhook-verification.ts";
39
+ export { verifyWebhookDelivery, WebhookVerificationError } from "./webhook-verification.ts";
40
+ export type { WorkspaceClient, WorkspaceClientOptions } from "./workspace.ts";
41
+ export { createWorkspaceClient } from "./workspace.ts";
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"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,CAAC;AACzF,YAAY,EACV,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EACV,YAAY,EACZ,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACxE,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACjG,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,YAAY,EACV,sBAAsB,EACtB,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export { walkCollectionPages } from "./collection.js";
2
+ export { createDirectConnectionClient, generateDirectConnectionCredential, } from "./direct-connection.js";
3
+ export { FiscalError } from "./fiscal-error.js";
4
+ export { toFiscalDocumentSnapshot } from "./fiscal-operation.js";
5
+ export { TIMING_STAGE_IDS } from "./fiscal-operation-timing.js";
6
+ export { createHostedTenantClient } from "./hosted-tenant.js";
7
+ export { createHostedWorkspaceTransport } from "./hosted-workspace-transport.js";
8
+ export { PROBLEM_CATALOG } from "./problem-contract.js";
9
+ export { toWireCase } from "./public-case.js";
10
+ export { digestSha256Hex } from "./sha256.js";
11
+ export { createTimbroClient } from "./timbro-client.js";
12
+ export { parseDeliveredWebhookEvent, parseWebhookEvent, } from "./webhook-event.js";
13
+ export { verifyWebhookDelivery, WebhookVerificationError } from "./webhook-verification.js";
14
+ export { createWorkspaceClient } from "./workspace.js";
@@ -0,0 +1,23 @@
1
+ import { type ElectronicFiscalDocumentType, type PrintedRepresentationProfile } from "./generated/index.ts";
2
+ import type { Client } from "./generated-operation-client.ts";
3
+ export declare function isCanonicalRfc3339MillisecondUtc(value: string): boolean;
4
+ export type PrintedRepresentationDownload = {
5
+ readonly artifactId: string;
6
+ readonly bytes: Uint8Array;
7
+ readonly byteLength: number;
8
+ readonly contentSha256: string;
9
+ readonly createdAt: string;
10
+ readonly fiscalDocumentType: ElectronicFiscalDocumentType;
11
+ readonly fiscalNumber: string;
12
+ readonly fiscalOperationId: string;
13
+ readonly mediaType: "application/pdf";
14
+ readonly pageCount: number;
15
+ readonly paginationPlanSha256: string;
16
+ readonly profile: PrintedRepresentationProfile;
17
+ readonly profileVersion: "a4.v1" | "receipt_80mm.v1";
18
+ readonly rendererIdentity: string;
19
+ readonly signedSourceSha256: string;
20
+ };
21
+ export declare function downloadPrintedRepresentationResource(client: Client, fiscalOperationId: string, signal: AbortSignal | undefined): Promise<PrintedRepresentationDownload>;
22
+ export declare function decodePrintedRepresentation(response: Pick<import("./transport-contract.ts").TimbroTransportResponse, "body" | "headers">, fiscalOperationId: string): Promise<PrintedRepresentationDownload>;
23
+ //# sourceMappingURL=printed-representation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printed-representation.d.ts","sourceRoot":"","sources":["../src/printed-representation.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,4BAA4B,EAEjC,KAAK,4BAA4B,EAElC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAO9D,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAsBvE;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,kBAAkB,EAAE,4BAA4B,CAAC;IAC1D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAC/C,QAAQ,CAAC,cAAc,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACrD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAsB,qCAAqC,CACzD,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,6BAA6B,CAAC,CAaxC;AAED,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,IAAI,CAAC,OAAO,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC,EAC7F,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,6BAA6B,CAAC,CAgFxC"}
@@ -0,0 +1,135 @@
1
+ import { createArtifactHeaderReader } from "./artifact-headers.js";
2
+ import { FiscalError } from "./fiscal-error.js";
3
+ import { findFiscalArtifact, zElectronicFiscalDocumentType, } from "./generated/index.js";
4
+ import { throwGeneratedProblem } from "./generated-problem.js";
5
+ import { digestSha256Hex } from "./sha256.js";
6
+ const FISCAL_NUMBER_PATTERN = /^E(?:31|32|33|34|41|43|44|45|46|47)[0-9]{10}$/;
7
+ const RFC3339_MILLISECOND_UTC_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
8
+ export function isCanonicalRfc3339MillisecondUtc(value) {
9
+ if (!RFC3339_MILLISECOND_UTC_PATTERN.test(value)) {
10
+ return false;
11
+ }
12
+ const year = Number(value.slice(0, 4));
13
+ const month = Number(value.slice(5, 7));
14
+ const day = Number(value.slice(8, 10));
15
+ const hours = Number(value.slice(11, 13));
16
+ const minutes = Number(value.slice(14, 16));
17
+ const seconds = Number(value.slice(17, 19));
18
+ const milliseconds = Number(value.slice(20, 23));
19
+ const instant = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds, milliseconds));
20
+ return (Number.isFinite(instant.getTime()) &&
21
+ instant.getUTCFullYear() === year &&
22
+ instant.getUTCMonth() === month - 1 &&
23
+ instant.getUTCDate() === day &&
24
+ instant.getUTCHours() === hours &&
25
+ instant.getUTCMinutes() === minutes &&
26
+ instant.getUTCSeconds() === seconds &&
27
+ instant.getUTCMilliseconds() === milliseconds);
28
+ }
29
+ export async function downloadPrintedRepresentationResource(client, fiscalOperationId, signal) {
30
+ if (fiscalOperationId.trim() === "") {
31
+ throw new TypeError("fiscalOperationId must not be blank");
32
+ }
33
+ const response = await findFiscalArtifact({
34
+ client,
35
+ path: { operation_id: fiscalOperationId, artifact_kind: "printed_representation" },
36
+ ...(signal === undefined ? {} : { signal }),
37
+ });
38
+ if (response.status !== 200) {
39
+ throwGeneratedProblem(response, "Printed representation download failed");
40
+ }
41
+ return decodePrintedRepresentation(response, fiscalOperationId);
42
+ }
43
+ export async function decodePrintedRepresentation(response, fiscalOperationId) {
44
+ if (!(response.body instanceof Uint8Array)) {
45
+ throwArtifactFailure("Timbro returned a non-binary printed representation");
46
+ }
47
+ const artifactHeaders = createArtifactHeaderReader(response.headers, "artifact", throwArtifactFailure);
48
+ const mediaType = artifactHeaders.required("content-type");
49
+ if (mediaType !== "application/pdf") {
50
+ throwArtifactFailure("Timbro returned a printed representation with the wrong media type");
51
+ }
52
+ const artifactDigest = artifactHeaders.digest("timbro-artifact-sha256");
53
+ const pdfDigest = artifactHeaders.digest("timbro-pdf-sha256");
54
+ if (artifactDigest !== pdfDigest) {
55
+ throwArtifactFailure("Timbro returned mismatched artifact and PDF digests");
56
+ }
57
+ if ((await digestSha256Hex(response.body)) !== pdfDigest) {
58
+ throwArtifactFailure("the printed representation bytes do not match their SHA-256");
59
+ }
60
+ const byteLength = response.body.byteLength;
61
+ const artifactId = artifactHeaders.uuid("timbro-artifact-id");
62
+ const returnedOperationId = artifactHeaders.uuid("timbro-fiscal-operation-id");
63
+ if (returnedOperationId.toLowerCase() !== fiscalOperationId.toLowerCase()) {
64
+ throwArtifactFailure("the printed representation belongs to another Fiscal operation");
65
+ }
66
+ const fiscalDocumentType = artifactHeaders.required("timbro-fiscal-document-type");
67
+ const parsedFiscalDocumentType = zElectronicFiscalDocumentType.safeParse(fiscalDocumentType);
68
+ if (!parsedFiscalDocumentType.success) {
69
+ throwArtifactFailure("Timbro returned an unsupported fiscal document type header");
70
+ }
71
+ const typedFiscalDocumentType = parsedFiscalDocumentType.data;
72
+ const fiscalNumber = artifactHeaders.required("timbro-fiscal-number");
73
+ if (!FISCAL_NUMBER_PATTERN.test(fiscalNumber)) {
74
+ throwArtifactFailure("Timbro returned an invalid fiscal number header");
75
+ }
76
+ if (fiscalNumber.slice(1, 3) !== typedFiscalDocumentType) {
77
+ throwArtifactFailure("Timbro returned a fiscal number for another document type");
78
+ }
79
+ const signedSourceSha256 = artifactHeaders.digest("timbro-signed-source-sha256");
80
+ const paginationPlanSha256 = artifactHeaders.digest("timbro-pagination-plan-sha256");
81
+ const printedRepresentationProfile = requiredProfileHeader(artifactHeaders);
82
+ const printedRepresentationProfileVersion = requiredProfileVersionHeader(artifactHeaders);
83
+ const rendererIdentity = artifactHeaders.required("timbro-renderer-identity");
84
+ if (rendererIdentity.trim() === "" ||
85
+ rendererIdentity !== rendererIdentity.trim() ||
86
+ rendererIdentity.length > 200) {
87
+ throwArtifactFailure("Timbro returned an invalid renderer identity header");
88
+ }
89
+ const pageCount = artifactHeaders.positiveInteger("timbro-page-count");
90
+ if (pageCount > 100) {
91
+ throwArtifactFailure("Timbro returned a page count above the supported bound");
92
+ }
93
+ const createdAt = artifactHeaders.required("timbro-artifact-created-at");
94
+ if (!isCanonicalRfc3339MillisecondUtc(createdAt)) {
95
+ throwArtifactFailure("Timbro returned an invalid artifact creation time");
96
+ }
97
+ return {
98
+ artifactId,
99
+ bytes: response.body,
100
+ byteLength,
101
+ contentSha256: pdfDigest,
102
+ createdAt,
103
+ fiscalDocumentType: typedFiscalDocumentType,
104
+ fiscalNumber,
105
+ fiscalOperationId: returnedOperationId,
106
+ mediaType: "application/pdf",
107
+ pageCount,
108
+ paginationPlanSha256,
109
+ profile: printedRepresentationProfile,
110
+ profileVersion: printedRepresentationProfileVersion,
111
+ rendererIdentity,
112
+ signedSourceSha256,
113
+ };
114
+ }
115
+ function requiredProfileHeader(headers) {
116
+ const profile = headers.required("timbro-printed-representation-profile");
117
+ if (profile !== "receipt_80mm" && profile !== "a4") {
118
+ throwArtifactFailure("Timbro returned an unsupported printed representation profile");
119
+ }
120
+ return profile;
121
+ }
122
+ function requiredProfileVersionHeader(headers) {
123
+ const profile = requiredProfileHeader(headers);
124
+ const version = headers.required("timbro-printed-representation-profile-version");
125
+ if (version === "a4.v1" && profile === "a4") {
126
+ return version;
127
+ }
128
+ if (version === "receipt_80mm.v1" && profile === "receipt_80mm") {
129
+ return version;
130
+ }
131
+ throwArtifactFailure("Timbro returned a profile version that does not match its profile");
132
+ }
133
+ function throwArtifactFailure(message) {
134
+ throw new FiscalError(message, { failure: "server_processing" });
135
+ }