@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,23 @@
1
+ import type { FiscalAdmissionProblem, IssuanceBlocker, ProblemBody, PublicProblemCode } from "./generated/types.gen.ts";
2
+ import type { ProblemFailure } from "./problem-contract.ts";
3
+ export type FiscalFailure = ProblemFailure | "connectivity" | "timeout" | "cancelled";
4
+ export type FiscalErrorDetail = {
5
+ readonly failure: FiscalFailure;
6
+ readonly status?: number | undefined;
7
+ readonly problem?: ProblemBody;
8
+ readonly retryAfterSeconds?: number | undefined;
9
+ };
10
+ export declare class FiscalError extends Error {
11
+ readonly failure: FiscalFailure;
12
+ readonly status: number | undefined;
13
+ readonly problem: ProblemBody | undefined;
14
+ readonly retryAfterSeconds: number | undefined;
15
+ constructor(message: string, detail: FiscalErrorDetail, options?: ErrorOptions);
16
+ get code(): PublicProblemCode | undefined;
17
+ get title(): string | undefined;
18
+ get requestId(): string | undefined;
19
+ get problems(): readonly FiscalAdmissionProblem[];
20
+ get issuanceBlockers(): readonly IssuanceBlocker[];
21
+ get isRetryable(): boolean;
22
+ }
23
+ //# sourceMappingURL=fiscal-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal-error.d.ts","sourceRoot":"","sources":["../src/fiscal-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjD,CAAC;AAIF,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/C,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,YAAY,EAO7E;IAED,IAAI,IAAI,IAAI,iBAAiB,GAAG,SAAS,CAExC;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,IAAI,QAAQ,IAAI,SAAS,sBAAsB,EAAE,CAEhD;IAED,IAAI,gBAAgB,IAAI,SAAS,eAAe,EAAE,CAEjD;IAED,IAAI,WAAW,IAAI,OAAO,CAKzB;CACF"}
@@ -0,0 +1,36 @@
1
+ const RETRYABLE_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
2
+ export class FiscalError extends Error {
3
+ failure;
4
+ status;
5
+ problem;
6
+ retryAfterSeconds;
7
+ constructor(message, detail, options) {
8
+ super(message, options);
9
+ this.name = "FiscalError";
10
+ this.failure = detail.failure;
11
+ this.status = detail.problem?.status ?? detail.status;
12
+ this.problem = detail.problem;
13
+ this.retryAfterSeconds = detail.retryAfterSeconds;
14
+ }
15
+ get code() {
16
+ return this.problem?.code;
17
+ }
18
+ get title() {
19
+ return this.problem?.title;
20
+ }
21
+ get requestId() {
22
+ return this.problem?.request_id;
23
+ }
24
+ get problems() {
25
+ return this.problem?.problems ?? [];
26
+ }
27
+ get issuanceBlockers() {
28
+ return this.problem?.issuance_blockers ?? [];
29
+ }
30
+ get isRetryable() {
31
+ if (this.failure === "connectivity" || this.failure === "timeout") {
32
+ return true;
33
+ }
34
+ return this.status !== undefined && RETRYABLE_STATUSES.has(this.status);
35
+ }
36
+ }
@@ -0,0 +1,6 @@
1
+ import { type FiscalNumberAuthorizationReadiness } from "./generated/index.ts";
2
+ import type { Client } from "./generated-operation-client.ts";
3
+ import { type ReadonlyCamelCase } from "./public-case.ts";
4
+ export type FiscalNumberingReadiness = ReadonlyCamelCase<FiscalNumberAuthorizationReadiness>;
5
+ export declare function readFiscalNumberingReadinessResource(client: Client, signal: AbortSignal | undefined): Promise<FiscalNumberingReadiness>;
6
+ //# sourceMappingURL=fiscal-numbering-readiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal-numbering-readiness.d.ts","sourceRoot":"","sources":["../src/fiscal-numbering-readiness.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kCAAkC,EAExC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,kBAAkB,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,kCAAkC,CAAC,CAAC;AAE7F,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,wBAAwB,CAAC,CASnC"}
@@ -0,0 +1,13 @@
1
+ import { readFiscalNumberAuthorizationReadiness, } from "./generated/index.js";
2
+ import { throwGeneratedProblem } from "./generated-problem.js";
3
+ import { toPublicCase } from "./public-case.js";
4
+ export async function readFiscalNumberingReadinessResource(client, signal) {
5
+ const response = await readFiscalNumberAuthorizationReadiness({
6
+ client,
7
+ ...(signal === undefined ? {} : { signal }),
8
+ });
9
+ if (response.status !== 200) {
10
+ throwGeneratedProblem(response, "Fiscal-number readiness read failed");
11
+ }
12
+ return toPublicCase(response.body);
13
+ }
@@ -0,0 +1,9 @@
1
+ import { type FiscalOperationTimingReport as GeneratedFiscalOperationTimingReport } from "./generated/index.ts";
2
+ import type { Client } from "./generated-operation-client.ts";
3
+ import { type ReadonlyCamelCase } from "./public-case.ts";
4
+ export type { TimingStageId } from "./generated/index.ts";
5
+ export type FiscalOperationTimingReport = ReadonlyCamelCase<GeneratedFiscalOperationTimingReport>;
6
+ /** Every stage id the operation timing contract publishes. */
7
+ export declare const TIMING_STAGE_IDS: ("timbro.activation_drain" | "timbro.admission.authenticate" | "timbro.admission.commit" | "timbro.admission.evaluate" | "timbro.admission.prepare" | "timbro.admission_request" | "timbro.dgii.authenticate" | "timbro.dgii.inquiry.consumer_summary" | "timbro.dgii.inquiry.fiscal_identity" | "timbro.dgii.inquiry.track_id" | "timbro.dgii.lease_wait" | "timbro.dgii.seed_request" | "timbro.dgii.seed_validate" | "timbro.dgii.submit.complete_ecf" | "timbro.dgii.submit.consumer_summary" | "timbro.inline_drain" | "timbro.operation_terminal" | "timbro.render.printed_representation" | "timbro.sign.complete_document" | "timbro.sign.consumer_summary" | "timbro.sign.dgii_authentication_seed" | "timbro.signer.call" | "timbro.vault.get.printed_representation" | "timbro.vault.get.signed_complete_document" | "timbro.vault.get.signed_consumer_summary" | "timbro.vault.put.printed_representation" | "timbro.vault.put.signed_complete_document" | "timbro.vault.put.signed_consumer_summary" | "timbro.vault.verify.printed_representation" | "timbro.vault.verify.signed_complete_document" | "timbro.vault.verify.signed_consumer_summary" | "timbro.webhook.authority_accepted" | "timbro.webhook.authority_accepted_with_findings" | "timbro.webhook.authority_rejected" | "timbro.webhook.commercially_accepted" | "timbro.webhook.commercially_rejected" | "timbro.webhook.fiscal_document.artifacts_updated" | "timbro.webhook.fiscal_document.ready" | "timbro.webhook.intervention_required" | "timbro.webhook.processing" | "timbro.webhook.rejected" | "timbro.webhook.submission_outcome_unknown" | "timbro.work.claim" | "timbro.work.pickup")[];
8
+ export declare function getFiscalOperationTimingResource(client: Client, fiscalOperationId: string, signal: AbortSignal | undefined): Promise<FiscalOperationTimingReport | undefined>;
9
+ //# sourceMappingURL=fiscal-operation-timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal-operation-timing.d.ts","sourceRoot":"","sources":["../src/fiscal-operation-timing.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,2BAA2B,IAAI,oCAAoC,EAEzE,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,kBAAkB,CAAC;AAExE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;AAElG,8DAA8D;AAC9D,eAAO,MAAM,gBAAgB,olDAAyB,CAAC;AAEvD,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAoBlD"}
@@ -0,0 +1,22 @@
1
+ import { validateIdentity } from "./fiscal-operation.js";
2
+ import { readFiscalOperationTiming, } from "./generated/index.js";
3
+ import { zTimingStageId } from "./generated/zod.gen.js";
4
+ import { isExpectedNotFoundProblem, throwGeneratedProblem } from "./generated-problem.js";
5
+ import { toPublicCase } from "./public-case.js";
6
+ /** Every stage id the operation timing contract publishes. */
7
+ export const TIMING_STAGE_IDS = zTimingStageId.options;
8
+ export async function getFiscalOperationTimingResource(client, fiscalOperationId, signal) {
9
+ validateIdentity(fiscalOperationId, "fiscalOperationId");
10
+ const response = await readFiscalOperationTiming({
11
+ client,
12
+ path: { operation_id: fiscalOperationId },
13
+ ...(signal === undefined ? {} : { signal }),
14
+ });
15
+ if (isExpectedNotFoundProblem(response, "fiscal_operation_not_found", "Fiscal operation timing lookup failed")) {
16
+ return;
17
+ }
18
+ if (response.status !== 200) {
19
+ throwGeneratedProblem(response, "Fiscal operation timing lookup failed");
20
+ }
21
+ return toPublicCase(response.body);
22
+ }
@@ -0,0 +1,112 @@
1
+ import { type FiscalEnvironment, type FiscalIntent, type SourceFiscalOperationPage as GeneratedFiscalOperationPage, type FiscalOperationResource as GeneratedFiscalOperationResource, type SourceType31Snapshot as GeneratedSourceType31Snapshot, type SourceType32Snapshot as GeneratedSourceType32Snapshot, type SourceType33Snapshot as GeneratedSourceType33Snapshot, type SourceType34Snapshot as GeneratedSourceType34Snapshot, type SourceType41Snapshot as GeneratedSourceType41Snapshot, type SourceType43Snapshot as GeneratedSourceType43Snapshot, type SourceType44Snapshot as GeneratedSourceType44Snapshot, type SourceType45Snapshot as GeneratedSourceType45Snapshot, type SourceType46Snapshot as GeneratedSourceType46Snapshot, type SourceType47Snapshot as GeneratedSourceType47Snapshot, type PrintedRepresentationProfile } from "./generated/index.ts";
2
+ import type { Client } from "./generated-operation-client.ts";
3
+ import { type ReadonlyCamelCase } from "./public-case.ts";
4
+ export type FiscalSource = {
5
+ readonly id: string;
6
+ readonly version: string;
7
+ };
8
+ export type SourceType31Snapshot = ReadonlyCamelCase<GeneratedSourceType31Snapshot>;
9
+ export type SourceType32Snapshot = ReadonlyCamelCase<GeneratedSourceType32Snapshot>;
10
+ export type SourceType33Snapshot = ReadonlyCamelCase<GeneratedSourceType33Snapshot>;
11
+ export type SourceType34Snapshot = ReadonlyCamelCase<GeneratedSourceType34Snapshot>;
12
+ export type SourceType41Snapshot = ReadonlyCamelCase<GeneratedSourceType41Snapshot>;
13
+ export type SourceType43Snapshot = ReadonlyCamelCase<GeneratedSourceType43Snapshot>;
14
+ export type SourceType44Snapshot = ReadonlyCamelCase<GeneratedSourceType44Snapshot>;
15
+ export type SourceType45Snapshot = ReadonlyCamelCase<GeneratedSourceType45Snapshot>;
16
+ export type SourceType46Snapshot = ReadonlyCamelCase<GeneratedSourceType46Snapshot>;
17
+ export type SourceType47Snapshot = ReadonlyCamelCase<GeneratedSourceType47Snapshot>;
18
+ /** One caller-owned immutable document snapshot for every supported e-CF family. */
19
+ export type FiscalDocument = {
20
+ readonly kind: "type31";
21
+ readonly snapshot: SourceType31Snapshot;
22
+ } | {
23
+ readonly kind: "type32";
24
+ readonly snapshot: SourceType32Snapshot;
25
+ } | {
26
+ readonly kind: "type33";
27
+ readonly snapshot: SourceType33Snapshot;
28
+ } | {
29
+ readonly kind: "type34";
30
+ readonly snapshot: SourceType34Snapshot;
31
+ } | {
32
+ readonly kind: "type41";
33
+ readonly snapshot: SourceType41Snapshot;
34
+ } | {
35
+ readonly kind: "type43";
36
+ readonly snapshot: SourceType43Snapshot;
37
+ } | {
38
+ readonly kind: "type44";
39
+ readonly snapshot: SourceType44Snapshot;
40
+ } | {
41
+ readonly kind: "type45";
42
+ readonly snapshot: SourceType45Snapshot;
43
+ } | {
44
+ readonly kind: "type46";
45
+ readonly snapshot: SourceType46Snapshot;
46
+ } | {
47
+ readonly kind: "type47";
48
+ readonly snapshot: SourceType47Snapshot;
49
+ };
50
+ /** Wraps one generated Fiscal intent as a caller-owned immutable Source snapshot. */
51
+ export declare function toFiscalDocumentSnapshot(intent: FiscalIntent): FiscalDocument;
52
+ export type FiscalOriginalSource = FiscalSource;
53
+ export type FiscalDocumentNumberingInstruction = {
54
+ readonly kind: "centralAssignment";
55
+ } | {
56
+ readonly fiscalNumber: string;
57
+ readonly kind: "externalAssignment";
58
+ readonly sequenceExpiresOn?: string | null;
59
+ };
60
+ export type FiscalDocumentAction = {
61
+ readonly kind: "issue";
62
+ } | {
63
+ readonly affectedFiscalOperationId: string;
64
+ readonly correction: "cancel" | "correctText" | "correctAmounts";
65
+ readonly kind: "creditNote";
66
+ readonly originalSource: FiscalOriginalSource;
67
+ readonly reason: string;
68
+ } | {
69
+ readonly affectedFiscalOperationId: string;
70
+ readonly correction: "correctText" | "correctAmounts";
71
+ readonly kind: "debitNote";
72
+ readonly originalSource: FiscalOriginalSource;
73
+ readonly reason: string;
74
+ };
75
+ type FiscalDocumentCommandFields = {
76
+ /** Timbro assigns from the verified central range when omitted. */
77
+ readonly numberingInstruction?: FiscalDocumentNumberingInstruction;
78
+ readonly printedRepresentation: {
79
+ readonly profile: PrintedRepresentationProfile;
80
+ };
81
+ readonly signal?: AbortSignal;
82
+ readonly source: FiscalSource;
83
+ };
84
+ export type FiscalDocumentIssueCommand = FiscalDocumentCommandFields & {
85
+ readonly action?: FiscalDocumentAction;
86
+ readonly predecessorOperationId?: string;
87
+ readonly document: FiscalDocument;
88
+ readonly hosted?: HostedFiscalTenant;
89
+ };
90
+ /** The hosted Checkout tenant and Fiscal environment a first-party service submits through. */
91
+ export type HostedFiscalTenant = {
92
+ readonly checkoutTenantId: string;
93
+ readonly environment: FiscalEnvironment;
94
+ };
95
+ export type FiscalDocumentListCommand = {
96
+ readonly cursor?: string;
97
+ readonly limit?: number;
98
+ readonly signal?: AbortSignal;
99
+ };
100
+ export type FiscalOperationResource = Omit<ReadonlyCamelCase<GeneratedFiscalOperationResource>, "id"> & {
101
+ readonly fiscalOperationId: string;
102
+ };
103
+ export type FiscalDocumentPage = Omit<ReadonlyCamelCase<GeneratedFiscalOperationPage>, "data"> & {
104
+ readonly data: readonly FiscalOperationResource[];
105
+ };
106
+ export declare function issueFiscalDocumentResource(client: Client, command: FiscalDocumentIssueCommand): Promise<FiscalOperationResource>;
107
+ export declare function listFiscalOperationResources(client: Client, command?: FiscalDocumentListCommand): Promise<FiscalDocumentPage>;
108
+ export declare function getFiscalOperationResource(client: Client, fiscalOperationId: string, signal: AbortSignal | undefined): Promise<FiscalOperationResource | undefined>;
109
+ export declare function findFiscalOperationBySourceResource(client: Client, source: FiscalSource, hosted: HostedFiscalTenant | undefined, signal: AbortSignal | undefined): Promise<FiscalOperationResource | undefined>;
110
+ export declare function validateIdentity(identity: string, name: string): void;
111
+ export {};
112
+ //# sourceMappingURL=fiscal-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal-operation.d.ts","sourceRoot":"","sources":["../src/fiscal-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAIjB,KAAK,yBAAyB,IAAI,4BAA4B,EAC9D,KAAK,uBAAuB,IAAI,gCAAgC,EAChE,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,oBAAoB,IAAI,6BAA6B,EAE1D,KAAK,4BA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 +1,193 @@
1
+ import { createFiscalOperation, findFiscalOperation, findFiscalOperationBySource, listFiscalOperations, zFiscalOperationSubmission, zSourceFiscalOperationRequest, } from "./generated/index.js";
2
+ import { isExpectedNotFoundProblem, throwGeneratedProblem } from "./generated-problem.js";
3
+ import { toPublicCase, toWireCase } from "./public-case.js";
4
+ import { validateSource } from "./source-command-validation.js";
5
+ /** Wraps one generated Fiscal intent as a caller-owned immutable Source snapshot. */
6
+ export function toFiscalDocumentSnapshot(intent) {
7
+ const { document_type: _documentType, issuer: _issuer, issued_on: _issuedOn, signed_at: _signedAt, schema_version: _schemaVersion, ...snapshot } = intent;
8
+ return toPublicCase({
9
+ kind: `type${intent.document_type}`,
10
+ snapshot,
11
+ });
12
+ }
13
+ async function createFiscalOperationResource(client, command) {
14
+ validateSource(command.source);
15
+ const body = toFiscalOperationSubmission(command);
16
+ const response = await createFiscalOperation({
17
+ client,
18
+ body,
19
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
20
+ });
21
+ switch (response.status) {
22
+ case 200:
23
+ case 202:
24
+ return toFiscalOperationResource(response.body);
25
+ default:
26
+ throwGeneratedProblem(response, "Fiscal operation creation failed");
27
+ }
28
+ }
29
+ export function issueFiscalDocumentResource(client, command) {
30
+ return createFiscalOperationResource(client, command);
31
+ }
32
+ export async function listFiscalOperationResources(client, command = {}) {
33
+ const response = await listFiscalOperations({
34
+ client,
35
+ ...(command.cursor === undefined && command.limit === undefined
36
+ ? {}
37
+ : { query: { cursor: command.cursor, limit: command.limit } }),
38
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
39
+ });
40
+ if (response.status !== 200) {
41
+ throwGeneratedProblem(response, "Fiscal operation listing failed");
42
+ }
43
+ return toFiscalDocumentPage(response.body);
44
+ }
45
+ export async function getFiscalOperationResource(client, fiscalOperationId, signal) {
46
+ const response = await requestFiscalOperation(client, fiscalOperationId, signal);
47
+ if (isExpectedNotFoundProblem(response, "fiscal_operation_not_found", "Fiscal operation lookup failed")) {
48
+ return;
49
+ }
50
+ if (response.status !== 200) {
51
+ throwGeneratedProblem(response, "Fiscal operation lookup failed");
52
+ }
53
+ return toFiscalOperationResource(response.body);
54
+ }
55
+ function requestFiscalOperation(client, fiscalOperationId, signal) {
56
+ validateIdentity(fiscalOperationId, "fiscalOperationId");
57
+ return findFiscalOperation({
58
+ client,
59
+ path: { operation_id: fiscalOperationId },
60
+ ...(signal === undefined ? {} : { signal }),
61
+ });
62
+ }
63
+ export async function findFiscalOperationBySourceResource(client, source, hosted, signal) {
64
+ validateSource(source);
65
+ const response = await findFiscalOperationBySource({
66
+ client,
67
+ path: { source_id: source.id, source_version: source.version },
68
+ ...(hosted === undefined
69
+ ? {}
70
+ : {
71
+ query: {
72
+ checkout_tenant_id: hosted.checkoutTenantId,
73
+ environment: hosted.environment,
74
+ },
75
+ }),
76
+ ...(signal === undefined ? {} : { signal }),
77
+ });
78
+ if (isExpectedNotFoundProblem(response, "fiscal_operation_not_found", "Fiscal operation source lookup failed")) {
79
+ return;
80
+ }
81
+ if (response.status !== 200) {
82
+ throwGeneratedProblem(response, "Fiscal operation source lookup failed");
83
+ }
84
+ return toFiscalOperationResource(response.body);
85
+ }
86
+ function toSourceFiscalOperationRequest(command) {
87
+ const parsed = zSourceFiscalOperationRequest.safeParse({
88
+ action: toWireAction(command.action ?? { kind: "issue" }),
89
+ document: toWireCase(command.document),
90
+ printed_representation_profile: command.printedRepresentation.profile,
91
+ numbering_instruction: toWireNumberingInstruction(command.numberingInstruction),
92
+ id: command.source.id,
93
+ version: command.source.version,
94
+ ...(command.predecessorOperationId === undefined
95
+ ? {}
96
+ : { predecessor_operation_id: command.predecessorOperationId }),
97
+ });
98
+ if (!parsed.success) {
99
+ throw new TypeError("the Source Fiscal operation command does not satisfy Timbro's contract");
100
+ }
101
+ return parsed.data;
102
+ }
103
+ function toFiscalOperationSubmission(command) {
104
+ const request = toSourceFiscalOperationRequest(command);
105
+ if (command.hosted === undefined) {
106
+ return request;
107
+ }
108
+ const parsed = zFiscalOperationSubmission.safeParse({
109
+ checkout_tenant_id: command.hosted.checkoutTenantId,
110
+ environment: command.hosted.environment,
111
+ request,
112
+ });
113
+ if (!parsed.success) {
114
+ throw new TypeError("the hosted Fiscal operation submission does not satisfy Timbro's contract");
115
+ }
116
+ return parsed.data;
117
+ }
118
+ function toWireNumberingInstruction(numberingInstruction) {
119
+ if (numberingInstruction === undefined || numberingInstruction.kind === "centralAssignment") {
120
+ return { kind: "central_assignment" };
121
+ }
122
+ return {
123
+ fiscal_number: numberingInstruction.fiscalNumber,
124
+ kind: "external_assignment",
125
+ sequence_expires_on: numberingInstruction.sequenceExpiresOn ?? null,
126
+ };
127
+ }
128
+ function toWireAction(action) {
129
+ switch (action.kind) {
130
+ case "issue":
131
+ return { kind: "issue" };
132
+ case "creditNote":
133
+ return {
134
+ affected_fiscal_operation_id: action.affectedFiscalOperationId,
135
+ correction: toWireCreditCorrection(action.correction),
136
+ kind: "credit_note",
137
+ original_source: action.originalSource,
138
+ reason: action.reason,
139
+ };
140
+ case "debitNote":
141
+ return {
142
+ affected_fiscal_operation_id: action.affectedFiscalOperationId,
143
+ correction: toWireDebitCorrection(action.correction),
144
+ kind: "debit_note",
145
+ original_source: action.originalSource,
146
+ reason: action.reason,
147
+ };
148
+ default:
149
+ throw new Error("the Fiscal operation action vocabulary is incomplete");
150
+ }
151
+ }
152
+ function toWireCreditCorrection(correction) {
153
+ switch (correction) {
154
+ case "cancel":
155
+ return "cancel";
156
+ case "correctText":
157
+ return "correct_text";
158
+ case "correctAmounts":
159
+ return "correct_amounts";
160
+ default:
161
+ throw new Error("the credit-note correction vocabulary is incomplete");
162
+ }
163
+ }
164
+ function toWireDebitCorrection(correction) {
165
+ switch (correction) {
166
+ case "correctText":
167
+ return "correct_text";
168
+ case "correctAmounts":
169
+ return "correct_amounts";
170
+ default:
171
+ throw new Error("the debit-note correction vocabulary is incomplete");
172
+ }
173
+ }
174
+ function toFiscalOperationResource(resource) {
175
+ const publicResource = toPublicCase(resource);
176
+ const { id, ...rest } = publicResource;
177
+ return {
178
+ ...rest,
179
+ fiscalOperationId: id,
180
+ };
181
+ }
182
+ function toFiscalDocumentPage(page) {
183
+ const publicPage = toPublicCase(page);
184
+ return {
185
+ ...publicPage,
186
+ data: page.data.map(toFiscalOperationResource),
187
+ };
188
+ }
189
+ export function validateIdentity(identity, name) {
190
+ if (identity.trim() === "") {
191
+ throw new TypeError(`${name} must not be blank`);
192
+ }
193
+ }
@@ -0,0 +1,19 @@
1
+ import { type FiscalReceiptReference as WireReceiptReference, type FiscalReceiptResource as WireReceiptResource } from "./generated/index.ts";
2
+ import { type Client } from "./generated-operation-client.ts";
3
+ import { type PrintedRepresentationDownload } from "./printed-representation.ts";
4
+ import { type ReadonlyCamelCase } from "./public-case.ts";
5
+ export type FiscalReceiptReference = ReadonlyCamelCase<WireReceiptReference>;
6
+ export type FiscalReceiptResource = ReadonlyCamelCase<WireReceiptResource>;
7
+ export type FiscalReceiptCommand = {
8
+ readonly receipt: FiscalReceiptReference;
9
+ readonly signal?: AbortSignal;
10
+ };
11
+ type ReceiptTransportOptions = {
12
+ readonly baseUrl: string;
13
+ readonly fetch?: typeof globalThis.fetch;
14
+ };
15
+ export declare function shareFiscalReceiptResource(client: Client, fiscalOperationId: string, signal: AbortSignal | undefined): Promise<FiscalReceiptReference>;
16
+ export declare function getFiscalReceiptResource(options: ReceiptTransportOptions, command: FiscalReceiptCommand): Promise<FiscalReceiptResource | undefined>;
17
+ export declare function downloadFiscalReceiptPrintedRepresentation(options: ReceiptTransportOptions, command: FiscalReceiptCommand): Promise<PrintedRepresentationDownload>;
18
+ export {};
19
+ //# sourceMappingURL=fiscal-receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiscal-receipt.d.ts","sourceRoot":"","sources":["../src/fiscal-receipt.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,sBAAsB,IAAI,oBAAoB,EACnD,KAAK,qBAAqB,IAAI,mBAAmB,EAElD,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,MAAM,EAAkC,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,iBAAiB,EAA4B,MAAM,kBAAkB,CAAC;AAGpF,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;AAC7E,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;AAC3E,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAC1C,CAAC;AAEF,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,sBAAsB,CAAC,CAkBjC;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAwB5C;AAED,wBAAsB,0CAA0C,CAC9D,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,6BAA6B,CAAC,CAUxC"}
@@ -0,0 +1,66 @@
1
+ import { FiscalError } from "./fiscal-error.js";
2
+ import { retrieveFiscalReceipt, retrieveFiscalReceiptPrintedRepresentation, shareFiscalReceipt, zFiscalReceiptReference, } from "./generated/index.js";
3
+ import { createGeneratedOperationClient } from "./generated-operation-client.js";
4
+ import { isExpectedNotFoundProblem, throwGeneratedProblem } from "./generated-problem.js";
5
+ import { decodePrintedRepresentation, } from "./printed-representation.js";
6
+ import { toPublicCase, toWireCase } from "./public-case.js";
7
+ import { createStampServerHttpTransport } from "./stamp-server-http-transport.js";
8
+ export async function shareFiscalReceiptResource(client, fiscalOperationId, signal) {
9
+ if (fiscalOperationId.trim() === "") {
10
+ throw new TypeError("fiscalOperationId must not be blank");
11
+ }
12
+ const response = await shareFiscalReceipt({
13
+ client,
14
+ path: { operation_id: fiscalOperationId },
15
+ ...(signal === undefined ? {} : { signal }),
16
+ });
17
+ if (response.status !== 200) {
18
+ throwGeneratedProblem(response, "Fiscal receipt sharing failed");
19
+ }
20
+ if (response.body.fiscal_operation_id.toLowerCase() !== fiscalOperationId.toLowerCase()) {
21
+ throw new FiscalError("Timbro returned a receipt for another Fiscal operation", {
22
+ failure: "server_processing",
23
+ });
24
+ }
25
+ return toPublicCase(response.body);
26
+ }
27
+ export async function getFiscalReceiptResource(options, command) {
28
+ const response = await retrieveFiscalReceipt({
29
+ client: receiptClient(options, command.receipt),
30
+ path: { receipt_id: command.receipt.id },
31
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
32
+ });
33
+ if (isExpectedNotFoundProblem(response, "fiscal_receipt_not_found", "Fiscal receipt lookup failed")) {
34
+ return;
35
+ }
36
+ if (response.status !== 200) {
37
+ throwGeneratedProblem(response, "Fiscal receipt lookup failed");
38
+ }
39
+ if (response.body.id.toLowerCase() !== command.receipt.id.toLowerCase() ||
40
+ response.body.fiscal_operation_id.toLowerCase() !==
41
+ command.receipt.fiscalOperationId.toLowerCase()) {
42
+ throw new FiscalError("Timbro returned another shared receipt", {
43
+ failure: "server_processing",
44
+ });
45
+ }
46
+ return toPublicCase(response.body);
47
+ }
48
+ export async function downloadFiscalReceiptPrintedRepresentation(options, command) {
49
+ const response = await retrieveFiscalReceiptPrintedRepresentation({
50
+ client: receiptClient(options, command.receipt),
51
+ path: { receipt_id: command.receipt.id },
52
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
53
+ });
54
+ if (response.status !== 200) {
55
+ throwGeneratedProblem(response, "Fiscal receipt PDF download failed");
56
+ }
57
+ return decodePrintedRepresentation(response, command.receipt.fiscalOperationId);
58
+ }
59
+ function receiptClient(options, receipt) {
60
+ const wire = zFiscalReceiptReference.parse(toWireCase(receipt));
61
+ return createGeneratedOperationClient(createStampServerHttpTransport({
62
+ stampServerOrigin: options.baseUrl,
63
+ authentication: { mode: "bearer", token: () => wire.access_token },
64
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
65
+ }));
66
+ }