@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,265 @@
1
+ import type { ProblemField } from "@timbro/protocol";
2
+ import type { z } from "zod";
3
+ import type { FiscalAdmissionProblem, ProblemBody, PublicProblemCode } from "./generated/types.gen.ts";
4
+ export type ProblemFailure = "authentication" | "validation" | "admission" | "server_processing";
5
+ export type ProblemCode = PublicProblemCode;
6
+ export type FieldProblem = FiscalAdmissionProblem & ProblemField;
7
+ export type { ProblemCatalogEntry } from "./generated/problem-catalog.ts";
8
+ export { PROBLEM_CATALOG } from "./generated/problem-catalog.ts";
9
+ export type { ProblemBody, PublicProblemCode } from "./generated/types.gen.ts";
10
+ export declare const problemBodySchema: z.ZodObject<{
11
+ code: z.ZodEnum<{
12
+ affected_fiscal_operation_unsupported: "affected_fiscal_operation_unsupported";
13
+ already_a_member: "already_a_member";
14
+ authority_rejected_replacement: "authority_rejected_replacement";
15
+ certificate_custody_binding_conflict: "certificate_custody_binding_conflict";
16
+ certificate_custody_binding_not_found: "certificate_custody_binding_not_found";
17
+ certificate_custody_certificate_version_not_active: "certificate_custody_certificate_version_not_active";
18
+ certificate_p12_password_invalid: "certificate_p12_password_invalid";
19
+ commercial_response_decision_conflict: "commercial_response_decision_conflict";
20
+ commercial_response_motive_invalid: "commercial_response_motive_invalid";
21
+ correction_target_unsettled: "correction_target_unsettled";
22
+ credential_revoked: "credential_revoked";
23
+ custody_certificate_chain_untrusted: "custody_certificate_chain_untrusted";
24
+ custody_certificate_malformed: "custody_certificate_malformed";
25
+ custody_certificate_purpose_unsupported: "custody_certificate_purpose_unsupported";
26
+ custody_certificate_trust_profile_unsupported: "custody_certificate_trust_profile_unsupported";
27
+ custody_signature_algorithm_unsupported: "custody_signature_algorithm_unsupported";
28
+ custody_unavailable: "custody_unavailable";
29
+ delegated_authorization_verifier_forbidden: "delegated_authorization_verifier_forbidden";
30
+ document_type_not_enabled: "document_type_not_enabled";
31
+ email_already_registered: "email_already_registered";
32
+ environment_not_active: "environment_not_active";
33
+ fiscal_artifact_not_found: "fiscal_artifact_not_found";
34
+ fiscal_artifact_unavailable: "fiscal_artifact_unavailable";
35
+ fiscal_artifact_unverified: "fiscal_artifact_unverified";
36
+ fiscal_delivery_not_found: "fiscal_delivery_not_found";
37
+ fiscal_delivery_outcome_conflict: "fiscal_delivery_outcome_conflict";
38
+ fiscal_delivery_unavailable: "fiscal_delivery_unavailable";
39
+ fiscal_intent_rejected: "fiscal_intent_rejected";
40
+ fiscal_issuance_blocked: "fiscal_issuance_blocked";
41
+ fiscal_number_already_used: "fiscal_number_already_used";
42
+ fiscal_number_authorization_changed: "fiscal_number_authorization_changed";
43
+ fiscal_number_authorization_source_record_conflict: "fiscal_number_authorization_source_record_conflict";
44
+ fiscal_operation_not_found: "fiscal_operation_not_found";
45
+ fiscal_receipt_not_found: "fiscal_receipt_not_found";
46
+ fiscal_receipt_not_ready: "fiscal_receipt_not_ready";
47
+ fiscal_receipt_unavailable: "fiscal_receipt_unavailable";
48
+ hosted_tenant_conflict: "hosted_tenant_conflict";
49
+ idempotency_key_conflict: "idempotency_key_conflict";
50
+ insufficient_role: "insufficient_role";
51
+ internal_error: "internal_error";
52
+ invalid_certificate_custody_signer_identity: "invalid_certificate_custody_signer_identity";
53
+ invalid_collection_cursor: "invalid_collection_cursor";
54
+ invalid_collection_query: "invalid_collection_query";
55
+ invalid_credential: "invalid_credential";
56
+ invalid_fiscal_identity: "invalid_fiscal_identity";
57
+ invalid_idempotency_key: "invalid_idempotency_key";
58
+ invalid_login: "invalid_login";
59
+ invalid_replay_scope: "invalid_replay_scope";
60
+ invalid_request: "invalid_request";
61
+ invitation_expired: "invitation_expired";
62
+ invitation_invalid: "invitation_invalid";
63
+ issuer_not_authorized: "issuer_not_authorized";
64
+ legal_issuer_already_registered: "legal_issuer_already_registered";
65
+ legal_issuer_not_found: "legal_issuer_not_found";
66
+ legal_issuer_profile_incomplete: "legal_issuer_profile_incomplete";
67
+ malformed_json: "malformed_json";
68
+ method_not_allowed: "method_not_allowed";
69
+ missing_idempotency_key: "missing_idempotency_key";
70
+ onboarding_legal_issuer_identity_conflict: "onboarding_legal_issuer_identity_conflict";
71
+ organization_not_found: "organization_not_found";
72
+ organization_slug_taken: "organization_slug_taken";
73
+ printed_representation_profile_conflict: "printed_representation_profile_conflict";
74
+ received_document_not_found: "received_document_not_found";
75
+ request_body_timeout: "request_body_timeout";
76
+ request_too_large: "request_too_large";
77
+ route_not_found: "route_not_found";
78
+ service_role_not_permitted: "service_role_not_permitted";
79
+ signed_document_schema_invalid: "signed_document_schema_invalid";
80
+ source_action_conflict: "source_action_conflict";
81
+ source_command_conflict: "source_command_conflict";
82
+ source_connection_activation_conflict: "source_connection_activation_conflict";
83
+ source_connection_activation_verification_rejected: "source_connection_activation_verification_rejected";
84
+ source_connection_creation_conflict: "source_connection_creation_conflict";
85
+ source_connection_not_connected: "source_connection_not_connected";
86
+ source_connection_not_found: "source_connection_not_found";
87
+ source_content_conflict: "source_content_conflict";
88
+ source_history_requires_reconciliation: "source_history_requires_reconciliation";
89
+ source_operation_pending: "source_operation_pending";
90
+ source_outcome_unknown: "source_outcome_unknown";
91
+ source_predecessor_conflict: "source_predecessor_conflict";
92
+ source_provider_authorization_conflict: "source_provider_authorization_conflict";
93
+ source_provider_authorization_not_found: "source_provider_authorization_not_found";
94
+ source_provider_authorization_required: "source_provider_authorization_required";
95
+ source_provider_installation_callback_replayed: "source_provider_installation_callback_replayed";
96
+ source_provider_installation_disabled: "source_provider_installation_disabled";
97
+ source_provider_installation_removed: "source_provider_installation_removed";
98
+ source_provider_installation_request_expired: "source_provider_installation_request_expired";
99
+ source_provider_installation_request_invalid: "source_provider_installation_request_invalid";
100
+ source_provider_outcome_unknown: "source_provider_outcome_unknown";
101
+ source_provider_scope_insufficient: "source_provider_scope_insufficient";
102
+ source_provider_target_access_removed: "source_provider_target_access_removed";
103
+ source_provider_throttled: "source_provider_throttled";
104
+ source_provider_unavailable: "source_provider_unavailable";
105
+ source_record_already_fiscalized: "source_record_already_fiscalized";
106
+ source_version_stale: "source_version_stale";
107
+ unauthenticated: "unauthenticated";
108
+ unsigned_document_schema_invalid: "unsigned_document_schema_invalid";
109
+ unsupported_media_type: "unsupported_media_type";
110
+ unsupported_printed_representation_profile: "unsupported_printed_representation_profile";
111
+ webhook_destination_not_allowed: "webhook_destination_not_allowed";
112
+ webhook_endpoint_deleted: "webhook_endpoint_deleted";
113
+ webhook_endpoint_not_found: "webhook_endpoint_not_found";
114
+ webhook_endpoint_registration_conflict: "webhook_endpoint_registration_conflict";
115
+ webhook_endpoint_suspended: "webhook_endpoint_suspended";
116
+ webhook_event_not_found: "webhook_event_not_found";
117
+ }>;
118
+ fiscal_operation_id: z.ZodOptional<z.ZodString>;
119
+ issuance_blockers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
120
+ authorization_cancelled: "authorization_cancelled";
121
+ authorization_conflicting: "authorization_conflicting";
122
+ authorization_document_type_mismatch: "authorization_document_type_mismatch";
123
+ authorization_exhausted: "authorization_exhausted";
124
+ authorization_expired: "authorization_expired";
125
+ authorization_missing: "authorization_missing";
126
+ authorization_not_observed_on_effective_date: "authorization_not_observed_on_effective_date";
127
+ authorization_range_overlap: "authorization_range_overlap";
128
+ authorization_superseded: "authorization_superseded";
129
+ authorization_suspended: "authorization_suspended";
130
+ central_assignment_requires_verified_authorization: "central_assignment_requires_verified_authorization";
131
+ document_type_not_recognized: "document_type_not_recognized";
132
+ fiscal_number_before_verified_floor: "fiscal_number_before_verified_floor";
133
+ fiscal_number_capacity_exhausted: "fiscal_number_capacity_exhausted";
134
+ fiscal_number_outside_authorized_range: "fiscal_number_outside_authorized_range";
135
+ invalid_fiscal_number: "invalid_fiscal_number";
136
+ invalid_request: "invalid_request";
137
+ invalid_resolved_facts: "invalid_resolved_facts";
138
+ numbering_mode_not_enabled: "numbering_mode_not_enabled";
139
+ numbering_verifier_missing: "numbering_verifier_missing";
140
+ sequence_expiration_mismatch: "sequence_expiration_mismatch";
141
+ unsupported_protocol: "unsupported_protocol";
142
+ unsupported_rules_version: "unsupported_rules_version";
143
+ }>>>;
144
+ problems: z.ZodOptional<z.ZodArray<z.ZodObject<{
145
+ code: z.ZodString;
146
+ message: z.ZodString;
147
+ path: z.ZodString;
148
+ }, z.core.$strict>>>;
149
+ request_id: z.ZodString;
150
+ status: z.ZodInt;
151
+ title: z.ZodString;
152
+ type: z.ZodString;
153
+ }, z.core.$strict>;
154
+ export declare const problemCodeSchema: z.ZodEnum<{
155
+ affected_fiscal_operation_unsupported: "affected_fiscal_operation_unsupported";
156
+ already_a_member: "already_a_member";
157
+ authority_rejected_replacement: "authority_rejected_replacement";
158
+ certificate_custody_binding_conflict: "certificate_custody_binding_conflict";
159
+ certificate_custody_binding_not_found: "certificate_custody_binding_not_found";
160
+ certificate_custody_certificate_version_not_active: "certificate_custody_certificate_version_not_active";
161
+ certificate_p12_password_invalid: "certificate_p12_password_invalid";
162
+ commercial_response_decision_conflict: "commercial_response_decision_conflict";
163
+ commercial_response_motive_invalid: "commercial_response_motive_invalid";
164
+ correction_target_unsettled: "correction_target_unsettled";
165
+ credential_revoked: "credential_revoked";
166
+ custody_certificate_chain_untrusted: "custody_certificate_chain_untrusted";
167
+ custody_certificate_malformed: "custody_certificate_malformed";
168
+ custody_certificate_purpose_unsupported: "custody_certificate_purpose_unsupported";
169
+ custody_certificate_trust_profile_unsupported: "custody_certificate_trust_profile_unsupported";
170
+ custody_signature_algorithm_unsupported: "custody_signature_algorithm_unsupported";
171
+ custody_unavailable: "custody_unavailable";
172
+ delegated_authorization_verifier_forbidden: "delegated_authorization_verifier_forbidden";
173
+ document_type_not_enabled: "document_type_not_enabled";
174
+ email_already_registered: "email_already_registered";
175
+ environment_not_active: "environment_not_active";
176
+ fiscal_artifact_not_found: "fiscal_artifact_not_found";
177
+ fiscal_artifact_unavailable: "fiscal_artifact_unavailable";
178
+ fiscal_artifact_unverified: "fiscal_artifact_unverified";
179
+ fiscal_delivery_not_found: "fiscal_delivery_not_found";
180
+ fiscal_delivery_outcome_conflict: "fiscal_delivery_outcome_conflict";
181
+ fiscal_delivery_unavailable: "fiscal_delivery_unavailable";
182
+ fiscal_intent_rejected: "fiscal_intent_rejected";
183
+ fiscal_issuance_blocked: "fiscal_issuance_blocked";
184
+ fiscal_number_already_used: "fiscal_number_already_used";
185
+ fiscal_number_authorization_changed: "fiscal_number_authorization_changed";
186
+ fiscal_number_authorization_source_record_conflict: "fiscal_number_authorization_source_record_conflict";
187
+ fiscal_operation_not_found: "fiscal_operation_not_found";
188
+ fiscal_receipt_not_found: "fiscal_receipt_not_found";
189
+ fiscal_receipt_not_ready: "fiscal_receipt_not_ready";
190
+ fiscal_receipt_unavailable: "fiscal_receipt_unavailable";
191
+ hosted_tenant_conflict: "hosted_tenant_conflict";
192
+ idempotency_key_conflict: "idempotency_key_conflict";
193
+ insufficient_role: "insufficient_role";
194
+ internal_error: "internal_error";
195
+ invalid_certificate_custody_signer_identity: "invalid_certificate_custody_signer_identity";
196
+ invalid_collection_cursor: "invalid_collection_cursor";
197
+ invalid_collection_query: "invalid_collection_query";
198
+ invalid_credential: "invalid_credential";
199
+ invalid_fiscal_identity: "invalid_fiscal_identity";
200
+ invalid_idempotency_key: "invalid_idempotency_key";
201
+ invalid_login: "invalid_login";
202
+ invalid_replay_scope: "invalid_replay_scope";
203
+ invalid_request: "invalid_request";
204
+ invitation_expired: "invitation_expired";
205
+ invitation_invalid: "invitation_invalid";
206
+ issuer_not_authorized: "issuer_not_authorized";
207
+ legal_issuer_already_registered: "legal_issuer_already_registered";
208
+ legal_issuer_not_found: "legal_issuer_not_found";
209
+ legal_issuer_profile_incomplete: "legal_issuer_profile_incomplete";
210
+ malformed_json: "malformed_json";
211
+ method_not_allowed: "method_not_allowed";
212
+ missing_idempotency_key: "missing_idempotency_key";
213
+ onboarding_legal_issuer_identity_conflict: "onboarding_legal_issuer_identity_conflict";
214
+ organization_not_found: "organization_not_found";
215
+ organization_slug_taken: "organization_slug_taken";
216
+ printed_representation_profile_conflict: "printed_representation_profile_conflict";
217
+ received_document_not_found: "received_document_not_found";
218
+ request_body_timeout: "request_body_timeout";
219
+ request_too_large: "request_too_large";
220
+ route_not_found: "route_not_found";
221
+ service_role_not_permitted: "service_role_not_permitted";
222
+ signed_document_schema_invalid: "signed_document_schema_invalid";
223
+ source_action_conflict: "source_action_conflict";
224
+ source_command_conflict: "source_command_conflict";
225
+ source_connection_activation_conflict: "source_connection_activation_conflict";
226
+ source_connection_activation_verification_rejected: "source_connection_activation_verification_rejected";
227
+ source_connection_creation_conflict: "source_connection_creation_conflict";
228
+ source_connection_not_connected: "source_connection_not_connected";
229
+ source_connection_not_found: "source_connection_not_found";
230
+ source_content_conflict: "source_content_conflict";
231
+ source_history_requires_reconciliation: "source_history_requires_reconciliation";
232
+ source_operation_pending: "source_operation_pending";
233
+ source_outcome_unknown: "source_outcome_unknown";
234
+ source_predecessor_conflict: "source_predecessor_conflict";
235
+ source_provider_authorization_conflict: "source_provider_authorization_conflict";
236
+ source_provider_authorization_not_found: "source_provider_authorization_not_found";
237
+ source_provider_authorization_required: "source_provider_authorization_required";
238
+ source_provider_installation_callback_replayed: "source_provider_installation_callback_replayed";
239
+ source_provider_installation_disabled: "source_provider_installation_disabled";
240
+ source_provider_installation_removed: "source_provider_installation_removed";
241
+ source_provider_installation_request_expired: "source_provider_installation_request_expired";
242
+ source_provider_installation_request_invalid: "source_provider_installation_request_invalid";
243
+ source_provider_outcome_unknown: "source_provider_outcome_unknown";
244
+ source_provider_scope_insufficient: "source_provider_scope_insufficient";
245
+ source_provider_target_access_removed: "source_provider_target_access_removed";
246
+ source_provider_throttled: "source_provider_throttled";
247
+ source_provider_unavailable: "source_provider_unavailable";
248
+ source_record_already_fiscalized: "source_record_already_fiscalized";
249
+ source_version_stale: "source_version_stale";
250
+ unauthenticated: "unauthenticated";
251
+ unsigned_document_schema_invalid: "unsigned_document_schema_invalid";
252
+ unsupported_media_type: "unsupported_media_type";
253
+ unsupported_printed_representation_profile: "unsupported_printed_representation_profile";
254
+ webhook_destination_not_allowed: "webhook_destination_not_allowed";
255
+ webhook_endpoint_deleted: "webhook_endpoint_deleted";
256
+ webhook_endpoint_not_found: "webhook_endpoint_not_found";
257
+ webhook_endpoint_registration_conflict: "webhook_endpoint_registration_conflict";
258
+ webhook_endpoint_suspended: "webhook_endpoint_suspended";
259
+ webhook_event_not_found: "webhook_event_not_found";
260
+ }>;
261
+ export { parseProblemFields } from "@timbro/protocol";
262
+ export declare function isProblemCode(candidate: unknown): candidate is PublicProblemCode;
263
+ export declare function classifyProblemStatus(problem: ProblemBody): ProblemFailure;
264
+ export type ParsedProblemBody = z.infer<typeof problemBodySchema>;
265
+ //# sourceMappingURL=problem-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problem-contract.d.ts","sourceRoot":"","sources":["../src/problem-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,YAAY,GAAG,WAAW,GAAG,mBAAmB,CAAC;AACjG,MAAM,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAC5C,MAAM,MAAM,YAAY,GAAG,sBAAsB,GAAG,YAAY,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE/E,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAe,CAAC;AAC9C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,wBAAgB,aAAa,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI,iBAAiB,CAEhF;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAiB1E;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { zProblemBody, zPublicProblemCode } from "./generated/zod.gen.js";
2
+ // biome-ignore lint/performance/noBarrelFile: This module is the SDK's stable problem-contract entrypoint.
3
+ export { PROBLEM_CATALOG } from "./generated/problem-catalog.js";
4
+ export const problemBodySchema = zProblemBody;
5
+ export const problemCodeSchema = zPublicProblemCode;
6
+ export { parseProblemFields } from "@timbro/protocol";
7
+ export function isProblemCode(candidate) {
8
+ return zPublicProblemCode.safeParse(candidate).success;
9
+ }
10
+ export function classifyProblemStatus(problem) {
11
+ if (problem.status === 401) {
12
+ return "authentication";
13
+ }
14
+ if (problem.status >= 500) {
15
+ return "server_processing";
16
+ }
17
+ if (problem.status === 400 ||
18
+ problem.status === 408 ||
19
+ problem.status === 413 ||
20
+ problem.status === 415 ||
21
+ problem.status === 422) {
22
+ return "validation";
23
+ }
24
+ return "admission";
25
+ }
@@ -0,0 +1,15 @@
1
+ /** Converts one snake_case identifier to the public camelCase spelling. */
2
+ type SnakeToCamelCase<Value extends string> = Value extends `${infer Head}_${infer Tail}` ? `${Head}${SnakeToCamelCase<Capitalize<Tail>>}` : Value;
3
+ /**
4
+ * Projects generated JSON types into the readonly camelCase vocabulary exposed by the task SDK.
5
+ * Generated bindings remain available from `@timbro/invoices/generated` for wire-level consumers.
6
+ */
7
+ export type ReadonlyCamelCase<Value> = Value extends readonly unknown[] ? readonly ReadonlyCamelCase<Value[number]>[] : Value extends object ? {
8
+ readonly [Key in keyof Value as Key extends string ? SnakeToCamelCase<Key> : Key]: ReadonlyCamelCase<Value[Key]>;
9
+ } : Value;
10
+ /** Converts JSON received from the Rust wire contract into a public camelCase value. */
11
+ export declare function toPublicCase(value: unknown): unknown;
12
+ /** Converts one public camelCase JSON value to the generated snake_case wire vocabulary. */
13
+ export declare function toWireCase(value: unknown): unknown;
14
+ export {};
15
+ //# sourceMappingURL=public-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-case.d.ts","sourceRoot":"","sources":["../src/public-case.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,KAAK,gBAAgB,CAAC,KAAK,SAAS,MAAM,IAAI,KAAK,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACrF,GAAG,IAAI,GAAG,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,GAC9C,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,IAAI,KAAK,SAAS,SAAS,OAAO,EAAE,GACnE,SAAS,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,GAC3C,KAAK,SAAS,MAAM,GAClB;IACE,QAAQ,EAAE,GAAG,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS,MAAM,GAC9C,gBAAgB,CAAC,GAAG,CAAC,GACrB,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CACxC,GACD,KAAK,CAAC;AAEZ,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUpD;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAUlD"}
@@ -0,0 +1,26 @@
1
+ /** Converts JSON received from the Rust wire contract into a public camelCase value. */
2
+ export function toPublicCase(value) {
3
+ if (Array.isArray(value)) {
4
+ return value.map(toPublicCase);
5
+ }
6
+ if (value === null || typeof value !== "object") {
7
+ return value;
8
+ }
9
+ return Object.fromEntries(Object.entries(value).map(([key, member]) => [toCamelCase(key), toPublicCase(member)]));
10
+ }
11
+ /** Converts one public camelCase JSON value to the generated snake_case wire vocabulary. */
12
+ export function toWireCase(value) {
13
+ if (Array.isArray(value)) {
14
+ return value.map(toWireCase);
15
+ }
16
+ if (value === null || typeof value !== "object") {
17
+ return value;
18
+ }
19
+ return Object.fromEntries(Object.entries(value).map(([key, member]) => [toSnakeCase(key), toWireCase(member)]));
20
+ }
21
+ function toCamelCase(value) {
22
+ return value.replace(/_([a-z])/gu, (_match, character) => character.toUpperCase());
23
+ }
24
+ function toSnakeCase(value) {
25
+ return value.replace(/[A-Z]/gu, (character) => `_${character.toLowerCase()}`);
26
+ }
@@ -0,0 +1,35 @@
1
+ import { type ReceivedDocumentPage as GeneratedReceivedDocumentPage, type ReceivedDocumentResource as GeneratedReceivedDocumentResource, type ReceivedDocumentRecoveryFilter, type ReceivedDocumentResponseFilter, type ReceivedDocumentStateFilter } from "./generated/index.ts";
2
+ import type { Client } from "./generated-operation-client.ts";
3
+ import { type ReadonlyCamelCase } from "./public-case.ts";
4
+ export type CommercialResponse = {
5
+ readonly decision: "accepted";
6
+ } | {
7
+ readonly decision: "rejected";
8
+ readonly motive: string;
9
+ };
10
+ export type { ReceivedDocumentRecoveryFilter, ReceivedDocumentResponseFilter, ReceivedDocumentStateFilter, } from "./generated/index.ts";
11
+ export type ReceivedDocumentListCommand = {
12
+ readonly cursor?: string;
13
+ readonly limit?: number;
14
+ readonly state?: ReceivedDocumentStateFilter;
15
+ readonly response?: ReceivedDocumentResponseFilter;
16
+ readonly recovery?: ReceivedDocumentRecoveryFilter;
17
+ readonly signal?: AbortSignal;
18
+ };
19
+ export type ReceivedDocumentSummary = ReadonlyCamelCase<GeneratedReceivedDocumentPage["data"][number]>;
20
+ export type ReceivedDocumentPage = Omit<ReadonlyCamelCase<GeneratedReceivedDocumentPage>, "data"> & {
21
+ readonly data: readonly ReceivedDocumentSummary[];
22
+ };
23
+ export type ReceivedDocumentResource = ReadonlyCamelCase<GeneratedReceivedDocumentResource>;
24
+ export type ReceivedDocumentSignedDocumentDownload = {
25
+ readonly bytes: Uint8Array;
26
+ readonly byteLength: number;
27
+ readonly contentSha256: string;
28
+ readonly mediaType: "application/xml";
29
+ readonly fiscalReceptionId: string;
30
+ };
31
+ export declare function listReceivedDocumentResources(client: Client, command?: ReceivedDocumentListCommand): Promise<ReceivedDocumentPage>;
32
+ export declare function getReceivedDocumentResource(client: Client, fiscalReceptionId: string, signal: AbortSignal | undefined): Promise<ReceivedDocumentResource>;
33
+ export declare function respondToReceivedDocument(client: Client, fiscalReceptionId: string, responseBody: CommercialResponse, signal: AbortSignal | undefined): Promise<ReceivedDocumentResource>;
34
+ export declare function downloadReceivedDocumentSignedDocument(client: Client, fiscalReceptionId: string, signal: AbortSignal | undefined): Promise<ReceivedDocumentSignedDocumentDownload>;
35
+ //# sourceMappingURL=received-documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"received-documents.d.ts","sourceRoot":"","sources":["../src/received-documents.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,oBAAoB,IAAI,6BAA6B,EAC1D,KAAK,wBAAwB,IAAI,iCAAiC,EAGlE,KAAK,8BAA8B,EACnC,KAAK,8BAA8B,EACnC,KAAK,2BAA2B,EAEjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,kBAAkB,CAAC;AAGxE,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAA;CAAE,GACjC;IAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,YAAY,EACV,8BAA8B,EAC9B,8BAA8B,EAC9B,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CACrD,6BAA6B,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAC9C,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,iBAAiB,CAAC,6BAA6B,CAAC,EAChD,MAAM,CACP,GAAG;IACF,QAAQ,CAAC,IAAI,EAAE,SAAS,uBAAuB,EAAE,CAAC;CACnD,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,iCAAiC,CAAC,CAAC;AAE5F,MAAM,MAAM,sCAAsC,GAAG;IACnD,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,iBAAiB,CAAC;IACtC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAgB/B;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,wBAAwB,CAAC,CAWnC;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,wBAAwB,CAAC,CAYnC;AAED,wBAAsB,sCAAsC,CAC1D,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,sCAAsC,CAAC,CA8BjD"}
@@ -0,0 +1,83 @@
1
+ import { createArtifactHeaderReader } from "./artifact-headers.js";
2
+ import { downloadSourceReceivedDocumentSignedXml, getSourceReceivedDocument, listSourceReceivedDocuments, respondToReceivedDocument as respondToReceivedDocumentOperation, } from "./generated/index.js";
3
+ import { throwGeneratedProblem } from "./generated-problem.js";
4
+ import { toPublicCase } from "./public-case.js";
5
+ import { digestSha256Hex } from "./sha256.js";
6
+ export async function listReceivedDocumentResources(client, command = {}) {
7
+ const response = await listSourceReceivedDocuments({
8
+ client,
9
+ query: {
10
+ cursor: command.cursor,
11
+ limit: command.limit,
12
+ state: command.state,
13
+ response: command.response,
14
+ recovery: command.recovery,
15
+ },
16
+ ...(command.signal === undefined ? {} : { signal: command.signal }),
17
+ });
18
+ if (response.status !== 200) {
19
+ throwGeneratedProblem(response, "Received document listing failed");
20
+ }
21
+ return toPublicCase(response.body);
22
+ }
23
+ export async function getReceivedDocumentResource(client, fiscalReceptionId, signal) {
24
+ validateReceptionId(fiscalReceptionId);
25
+ const response = await getSourceReceivedDocument({
26
+ client,
27
+ path: { fiscal_reception_id: fiscalReceptionId },
28
+ ...(signal === undefined ? {} : { signal }),
29
+ });
30
+ if (response.status !== 200) {
31
+ throwGeneratedProblem(response, "Received document lookup failed");
32
+ }
33
+ return toPublicCase(response.body);
34
+ }
35
+ export async function respondToReceivedDocument(client, fiscalReceptionId, responseBody, signal) {
36
+ validateReceptionId(fiscalReceptionId);
37
+ const response = await respondToReceivedDocumentOperation({
38
+ client,
39
+ path: { fiscal_reception_id: fiscalReceptionId },
40
+ body: responseBody,
41
+ ...(signal === undefined ? {} : { signal }),
42
+ });
43
+ if (response.status !== 200) {
44
+ throwGeneratedProblem(response, "Received document response failed");
45
+ }
46
+ return toPublicCase(response.body);
47
+ }
48
+ export async function downloadReceivedDocumentSignedDocument(client, fiscalReceptionId, signal) {
49
+ validateReceptionId(fiscalReceptionId);
50
+ const response = await downloadSourceReceivedDocumentSignedXml({
51
+ client,
52
+ path: { fiscal_reception_id: fiscalReceptionId },
53
+ ...(signal === undefined ? {} : { signal }),
54
+ });
55
+ if (response.status !== 200) {
56
+ throwGeneratedProblem(response, "Received document download failed");
57
+ }
58
+ if (!(response.body instanceof Uint8Array)) {
59
+ throw new TypeError("Timbro returned a non-binary received document");
60
+ }
61
+ const artifactHeaders = createArtifactHeaderReader(response.headers, "received document");
62
+ const mediaType = artifactHeaders.required("content-type");
63
+ if (mediaType !== "application/xml") {
64
+ throw new TypeError("Timbro returned a received document with the wrong media type");
65
+ }
66
+ const contentSha256 = artifactHeaders.digest("timbro-artifact-sha256");
67
+ if ((await digestSha256Hex(response.body)) !== contentSha256) {
68
+ throw new TypeError("the received document bytes do not match their SHA-256");
69
+ }
70
+ const byteLength = response.body.byteLength;
71
+ return {
72
+ bytes: response.body,
73
+ byteLength,
74
+ contentSha256,
75
+ mediaType: "application/xml",
76
+ fiscalReceptionId,
77
+ };
78
+ }
79
+ function validateReceptionId(value) {
80
+ if (value.trim() === "") {
81
+ throw new TypeError("fiscalReceptionId must not be blank");
82
+ }
83
+ }
@@ -0,0 +1,2 @@
1
+ export declare function digestSha256Hex(bytes: Uint8Array): Promise<string>;
2
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA,wBAAsB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAKxE"}
package/dist/sha256.js ADDED
@@ -0,0 +1,6 @@
1
+ export async function digestSha256Hex(bytes) {
2
+ const digestInput = new Uint8Array(bytes.byteLength);
3
+ digestInput.set(bytes);
4
+ const digest = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", digestInput));
5
+ return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
6
+ }
@@ -0,0 +1,15 @@
1
+ import type { Client } from "./generated-operation-client.ts";
2
+ export type SignedDocumentDownload = {
3
+ readonly artifactId: string;
4
+ readonly artifactKind: "signed_complete_document";
5
+ readonly byteLength: number;
6
+ readonly bytes: Uint8Array;
7
+ readonly certificateSha256: string;
8
+ readonly contentSha256: string;
9
+ readonly createdAt: string;
10
+ readonly fiscalOperationId: string;
11
+ readonly mediaType: "application/xml";
12
+ readonly securityCode: string;
13
+ };
14
+ export declare function downloadSignedDocumentResource(client: Client, fiscalOperationId: string, signal: AbortSignal | undefined): Promise<SignedDocumentDownload>;
15
+ //# sourceMappingURL=signed-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-document.d.ts","sourceRoot":"","sources":["../src/signed-document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAM9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,0BAA0B,CAAC;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,sBAAsB,CAAC,CAuDjC"}
@@ -0,0 +1,57 @@
1
+ import { createArtifactHeaderReader } from "./artifact-headers.js";
2
+ import { findFiscalArtifact } from "./generated/index.js";
3
+ import { throwGeneratedProblem } from "./generated-problem.js";
4
+ import { digestSha256Hex } from "./sha256.js";
5
+ const RFC3339_MILLISECOND_UTC_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
6
+ export async function downloadSignedDocumentResource(client, fiscalOperationId, signal) {
7
+ if (fiscalOperationId.trim() === "") {
8
+ throw new TypeError("fiscalOperationId must not be blank");
9
+ }
10
+ const response = await findFiscalArtifact({
11
+ client,
12
+ path: { operation_id: fiscalOperationId, artifact_kind: "signed_complete_document" },
13
+ ...(signal === undefined ? {} : { signal }),
14
+ });
15
+ if (response.status !== 200) {
16
+ throwGeneratedProblem(response, "Signed document download failed");
17
+ }
18
+ if (!(response.body instanceof Uint8Array)) {
19
+ throw new TypeError("Timbro returned a non-binary signed document");
20
+ }
21
+ const artifactHeaders = createArtifactHeaderReader(response.headers);
22
+ const mediaType = artifactHeaders.required("content-type");
23
+ if (mediaType !== "application/xml") {
24
+ throw new TypeError("Timbro returned a signed document with the wrong media type");
25
+ }
26
+ const contentSha256 = artifactHeaders.digest("timbro-artifact-sha256");
27
+ if ((await digestSha256Hex(response.body)) !== contentSha256) {
28
+ throw new TypeError("the signed document bytes do not match their SHA-256");
29
+ }
30
+ const byteLength = response.body.byteLength;
31
+ const artifactId = artifactHeaders.uuid("timbro-artifact-id");
32
+ const returnedOperationId = artifactHeaders.uuid("timbro-fiscal-operation-id");
33
+ if (returnedOperationId.toLowerCase() !== fiscalOperationId.toLowerCase()) {
34
+ throw new TypeError("the signed document belongs to another Fiscal operation");
35
+ }
36
+ const certificateSha256 = artifactHeaders.digest("timbro-certificate-sha256");
37
+ const securityCode = artifactHeaders.required("timbro-security-code");
38
+ if (securityCode.length !== 6) {
39
+ throw new TypeError("Timbro returned an invalid signed document security code");
40
+ }
41
+ const createdAt = artifactHeaders.required("timbro-artifact-created-at");
42
+ if (!(RFC3339_MILLISECOND_UTC_PATTERN.test(createdAt) && Number.isFinite(Date.parse(createdAt)))) {
43
+ throw new TypeError("Timbro returned an invalid signed document creation time");
44
+ }
45
+ return {
46
+ artifactId,
47
+ artifactKind: "signed_complete_document",
48
+ byteLength,
49
+ bytes: response.body,
50
+ certificateSha256,
51
+ contentSha256,
52
+ createdAt,
53
+ fiscalOperationId: returnedOperationId,
54
+ mediaType: "application/xml",
55
+ securityCode,
56
+ };
57
+ }
@@ -0,0 +1,3 @@
1
+ import type { FiscalSource } from "./fiscal-operation.ts";
2
+ export declare function validateSource(source: FiscalSource): void;
3
+ //# sourceMappingURL=source-command-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-command-validation.d.ts","sourceRoot":"","sources":["../src/source-command-validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK1D,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAiBzD"}
@@ -0,0 +1,14 @@
1
+ const SOURCE_RECORD_MAX_LENGTH = 128;
2
+ const SOURCE_VERSION_MAX_LENGTH = 128;
3
+ export function validateSource(source) {
4
+ if (source.id.trim() === "" ||
5
+ source.id !== source.id.trim() ||
6
+ Array.from(source.id).length > SOURCE_RECORD_MAX_LENGTH) {
7
+ throw new TypeError("source.id must be 1 to 128 characters without surrounding whitespace");
8
+ }
9
+ if (source.version.trim() === "" ||
10
+ source.version !== source.version.trim() ||
11
+ Array.from(source.version).length > SOURCE_VERSION_MAX_LENGTH) {
12
+ throw new TypeError("source.version must be 1 to 128 characters without surrounding whitespace");
13
+ }
14
+ }
@@ -0,0 +1,18 @@
1
+ import { type CompleteActivationVerificationRequest, type WebhookEventEnvelope } from "./generated/index.ts";
2
+ declare const ACTIVATION_VERIFICATION_EVENT_TYPE = "source_connection.verification_requested";
3
+ type SourceConnectionVerificationRequestEvent = Extract<WebhookEventEnvelope, {
4
+ readonly type: typeof ACTIVATION_VERIFICATION_EVENT_TYPE;
5
+ }>;
6
+ export type SourceConnectionActivationVerificationInput = {
7
+ readonly verificationRequestEvent: SourceConnectionVerificationRequestEvent;
8
+ readonly webhookSecret: string;
9
+ readonly runtimeProviderTargetId: string;
10
+ readonly runtimeProviderDeploymentId: string;
11
+ };
12
+ /**
13
+ * Builds the proof a deployed Source target returns for Timbro's signed activation challenge.
14
+ * Callers must verify the Webhook signature before passing its parsed event here.
15
+ */
16
+ export declare function buildSourceConnectionActivationVerification(input: SourceConnectionActivationVerificationInput): CompleteActivationVerificationRequest;
17
+ export {};
18
+ //# sourceMappingURL=source-connection-activation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-connection-activation.d.ts","sourceRoot":"","sources":["../src/source-connection-activation.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,qCAAqC,EAC1C,KAAK,oBAAoB,EAG1B,MAAM,sBAAsB,CAAC;AAI9B,QAAA,MAAM,kCAAkC,6CAA6C,CAAC;AAGtF,KAAK,wCAAwC,GAAG,OAAO,CACrD,oBAAoB,EACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,kCAAkC,CAAA;CAAE,CAC7D,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,QAAQ,CAAC,wBAAwB,EAAE,wCAAwC,CAAC;IAC5E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAC;CAC9C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,2CAA2C,CACzD,KAAK,EAAE,2CAA2C,GACjD,qCAAqC,CAyBvC"}