@papierapi/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +450 -0
- package/dist/chunk-JDUUPLUG.js +984 -0
- package/dist/chunk-JDUUPLUG.js.map +7 -0
- package/dist/client.d.ts +469 -0
- package/dist/errors.d.ts +20 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +343 -0
- package/dist/index.js.map +7 -0
- package/dist/internal/contracts/common.d.ts +108 -0
- package/dist/internal/contracts/dispatch.d.ts +979 -0
- package/dist/internal/contracts/fax.d.ts +49 -0
- package/dist/internal/contracts/index.d.ts +7 -0
- package/dist/internal/contracts/letter.d.ts +292 -0
- package/dist/internal/contracts/mcp.d.ts +395 -0
- package/dist/internal/contracts/platform.d.ts +424 -0
- package/dist/internal/contracts/rest.d.ts +1656 -0
- package/dist/operations.d.ts +1563 -0
- package/dist/operations.js +7 -0
- package/dist/operations.js.map +7 -0
- package/examples/get-dispatch.ts +13 -0
- package/package.json +68 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiErrorSchema,
|
|
3
|
+
DirectPaymentIdSchema,
|
|
4
|
+
DispatchIdSchema,
|
|
5
|
+
DraftIdSchema,
|
|
6
|
+
IdempotencyKeySchema,
|
|
7
|
+
papierApiOperations
|
|
8
|
+
} from "./chunk-JDUUPLUG.js";
|
|
9
|
+
|
|
10
|
+
// src/errors.ts
|
|
11
|
+
var PapierApiError = class extends Error {
|
|
12
|
+
status;
|
|
13
|
+
requestId;
|
|
14
|
+
code;
|
|
15
|
+
retryable;
|
|
16
|
+
suggestedAction;
|
|
17
|
+
fieldPath;
|
|
18
|
+
constructor(status, response) {
|
|
19
|
+
super(response.error.message);
|
|
20
|
+
this.name = "PapierApiError";
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.requestId = response.request_id;
|
|
23
|
+
this.code = response.error.code;
|
|
24
|
+
this.retryable = response.error.retryable;
|
|
25
|
+
this.suggestedAction = response.error.suggested_action;
|
|
26
|
+
this.fieldPath = response.error.field_path;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var PapierApiContractError = class extends Error {
|
|
30
|
+
operationId;
|
|
31
|
+
status;
|
|
32
|
+
constructor(message, operationId, status) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "PapierApiContractError";
|
|
35
|
+
this.operationId = operationId;
|
|
36
|
+
this.status = status;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var PapierApiTransportError = class extends Error {
|
|
40
|
+
reason;
|
|
41
|
+
retryable = true;
|
|
42
|
+
constructor(reason) {
|
|
43
|
+
super(reason === "timeout" ? "Papier API request timed out" : "Papier API is unreachable");
|
|
44
|
+
this.name = "PapierApiTransportError";
|
|
45
|
+
this.reason = reason;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/client.ts
|
|
50
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
51
|
+
var DEFAULT_MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
52
|
+
var MAX_PDF_BYTES = 20 * 1024 * 1024;
|
|
53
|
+
function boundedInteger(value, fallback, min, max) {
|
|
54
|
+
const resolved = value ?? fallback;
|
|
55
|
+
if (!Number.isInteger(resolved) || resolved < min || resolved > max) {
|
|
56
|
+
throw new TypeError(`Expected an integer between ${min} and ${max}`);
|
|
57
|
+
}
|
|
58
|
+
return resolved;
|
|
59
|
+
}
|
|
60
|
+
function normalizeBaseUrl(value) {
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = new URL(value);
|
|
64
|
+
} catch {
|
|
65
|
+
throw new TypeError("baseUrl must be an absolute URL");
|
|
66
|
+
}
|
|
67
|
+
const local = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
|
|
68
|
+
if (parsed.protocol !== "https:" && !(local && parsed.protocol === "http:")) {
|
|
69
|
+
throw new TypeError("baseUrl must use HTTPS except for localhost");
|
|
70
|
+
}
|
|
71
|
+
if (parsed.username !== "" || parsed.password !== "" || parsed.search !== "" || parsed.hash !== "" || parsed.pathname !== "" && parsed.pathname !== "/") {
|
|
72
|
+
throw new TypeError("baseUrl must contain only an origin");
|
|
73
|
+
}
|
|
74
|
+
return parsed.origin;
|
|
75
|
+
}
|
|
76
|
+
function validateToken(token) {
|
|
77
|
+
const hasControlOrWhitespace = Array.from(token).some((character) => {
|
|
78
|
+
const code = character.charCodeAt(0);
|
|
79
|
+
return code <= 32 || code === 127;
|
|
80
|
+
});
|
|
81
|
+
if (token.length < 8 || token.length > 8192 || hasControlOrWhitespace) {
|
|
82
|
+
throw new TypeError("accessToken is invalid");
|
|
83
|
+
}
|
|
84
|
+
return token;
|
|
85
|
+
}
|
|
86
|
+
function pdfBody(document) {
|
|
87
|
+
const size = document instanceof Blob ? document.size : document.byteLength;
|
|
88
|
+
if (size < 1 || size > MAX_PDF_BYTES) {
|
|
89
|
+
throw new TypeError(`PDF must contain between 1 and ${MAX_PDF_BYTES} bytes`);
|
|
90
|
+
}
|
|
91
|
+
if (document instanceof Blob) return document;
|
|
92
|
+
if (document instanceof Uint8Array) {
|
|
93
|
+
const copy = new Uint8Array(document.byteLength);
|
|
94
|
+
copy.set(document);
|
|
95
|
+
return new Blob([copy.buffer], { type: "application/pdf" });
|
|
96
|
+
}
|
|
97
|
+
return new Blob([document], { type: "application/pdf" });
|
|
98
|
+
}
|
|
99
|
+
async function boundedResponseText(response, maxBytes, operationId) {
|
|
100
|
+
const contentLength = response.headers.get("Content-Length");
|
|
101
|
+
if (contentLength !== null) {
|
|
102
|
+
const parsed = Number(contentLength);
|
|
103
|
+
if (Number.isFinite(parsed) && parsed > maxBytes) {
|
|
104
|
+
throw new PapierApiContractError(
|
|
105
|
+
"Papier API response exceeded the configured size limit",
|
|
106
|
+
operationId,
|
|
107
|
+
response.status
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (response.body === null) return "";
|
|
112
|
+
const reader = response.body.getReader();
|
|
113
|
+
const decoder = new TextDecoder();
|
|
114
|
+
let bytesRead = 0;
|
|
115
|
+
let text = "";
|
|
116
|
+
while (true) {
|
|
117
|
+
const chunk = await reader.read();
|
|
118
|
+
if (chunk.done) break;
|
|
119
|
+
bytesRead += chunk.value.byteLength;
|
|
120
|
+
if (bytesRead > maxBytes) {
|
|
121
|
+
await reader.cancel().catch(() => void 0);
|
|
122
|
+
throw new PapierApiContractError(
|
|
123
|
+
"Papier API response exceeded the configured size limit",
|
|
124
|
+
operationId,
|
|
125
|
+
response.status
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
text += decoder.decode(chunk.value, { stream: true });
|
|
129
|
+
}
|
|
130
|
+
return text + decoder.decode();
|
|
131
|
+
}
|
|
132
|
+
function parseJson(text, operationId, status) {
|
|
133
|
+
try {
|
|
134
|
+
return JSON.parse(text);
|
|
135
|
+
} catch {
|
|
136
|
+
throw new PapierApiContractError("Papier API returned invalid JSON", operationId, status);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
var PapierApiClient = class {
|
|
140
|
+
baseUrl;
|
|
141
|
+
accessToken;
|
|
142
|
+
fetcher;
|
|
143
|
+
timeoutMs;
|
|
144
|
+
maxResponseBytes;
|
|
145
|
+
constructor(options) {
|
|
146
|
+
this.baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
147
|
+
this.accessToken = options.accessToken;
|
|
148
|
+
const fetcher = options.fetcher ?? globalThis.fetch;
|
|
149
|
+
if (typeof fetcher !== "function") throw new TypeError("A fetch implementation is required");
|
|
150
|
+
this.fetcher = fetcher.bind(globalThis);
|
|
151
|
+
this.timeoutMs = boundedInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, 1, 12e4);
|
|
152
|
+
this.maxResponseBytes = boundedInteger(
|
|
153
|
+
options.maxResponseBytes,
|
|
154
|
+
DEFAULT_MAX_RESPONSE_BYTES,
|
|
155
|
+
256,
|
|
156
|
+
10 * 1024 * 1024
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
async token() {
|
|
160
|
+
const value = typeof this.accessToken === "function" ? await this.accessToken() : this.accessToken;
|
|
161
|
+
return validateToken(value);
|
|
162
|
+
}
|
|
163
|
+
async execute(name, options = {}) {
|
|
164
|
+
const operation = papierApiOperations[name];
|
|
165
|
+
let path = operation.path;
|
|
166
|
+
for (const [parameterName, parameterSchema] of Object.entries(operation.pathParameters)) {
|
|
167
|
+
const parsed2 = parameterSchema.parse(options.pathParameters?.[parameterName]);
|
|
168
|
+
path = path.replace(`{${parameterName}}`, encodeURIComponent(String(parsed2)));
|
|
169
|
+
}
|
|
170
|
+
if (path.includes("{")) {
|
|
171
|
+
throw new PapierApiContractError(
|
|
172
|
+
"REST operation has an unresolved path",
|
|
173
|
+
operation.operationId
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
177
|
+
for (const [parameterName, parameterSchema] of Object.entries(operation.queryParameters)) {
|
|
178
|
+
const parsed2 = parameterSchema.parse(options.queryParameters?.[parameterName]);
|
|
179
|
+
if (parsed2 !== void 0) url.searchParams.set(parameterName, String(parsed2));
|
|
180
|
+
}
|
|
181
|
+
const headers = new Headers({
|
|
182
|
+
Accept: "application/json",
|
|
183
|
+
Authorization: `Bearer ${await this.token()}`
|
|
184
|
+
});
|
|
185
|
+
let body;
|
|
186
|
+
if (operation.request.kind === "json") {
|
|
187
|
+
headers.set("Content-Type", "application/json");
|
|
188
|
+
body = JSON.stringify(operation.request.schema.parse(options.json));
|
|
189
|
+
} else if (operation.request.kind === "pdf") {
|
|
190
|
+
headers.set("Content-Type", "application/pdf");
|
|
191
|
+
if (options.pdf === void 0) throw new TypeError("A PDF document is required");
|
|
192
|
+
body = pdfBody(options.pdf);
|
|
193
|
+
}
|
|
194
|
+
if (operation.requiresIdempotencyKey) {
|
|
195
|
+
headers.set("Idempotency-Key", IdempotencyKeySchema.parse(options.idempotencyKey));
|
|
196
|
+
}
|
|
197
|
+
const controller = new AbortController();
|
|
198
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
199
|
+
let response;
|
|
200
|
+
try {
|
|
201
|
+
const requestInit = {
|
|
202
|
+
method: operation.method,
|
|
203
|
+
headers,
|
|
204
|
+
signal: controller.signal,
|
|
205
|
+
...body === void 0 ? {} : { body }
|
|
206
|
+
};
|
|
207
|
+
response = await this.fetcher(url, requestInit);
|
|
208
|
+
} catch {
|
|
209
|
+
throw new PapierApiTransportError(controller.signal.aborted ? "timeout" : "network");
|
|
210
|
+
} finally {
|
|
211
|
+
clearTimeout(timeout);
|
|
212
|
+
}
|
|
213
|
+
const parsed = parseJson(
|
|
214
|
+
await boundedResponseText(response, this.maxResponseBytes, operation.operationId),
|
|
215
|
+
operation.operationId,
|
|
216
|
+
response.status
|
|
217
|
+
);
|
|
218
|
+
if (!response.ok) {
|
|
219
|
+
const apiError = ApiErrorSchema.safeParse(parsed);
|
|
220
|
+
if (!apiError.success) {
|
|
221
|
+
throw new PapierApiContractError(
|
|
222
|
+
"Papier API returned a malformed error response",
|
|
223
|
+
operation.operationId,
|
|
224
|
+
response.status
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
throw new PapierApiError(response.status, apiError.data);
|
|
228
|
+
}
|
|
229
|
+
const validated = operation.responseSchema.safeParse(parsed);
|
|
230
|
+
if (!validated.success) {
|
|
231
|
+
throw new PapierApiContractError(
|
|
232
|
+
"Papier API response did not match the published contract",
|
|
233
|
+
operation.operationId,
|
|
234
|
+
response.status
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
return validated.data;
|
|
238
|
+
}
|
|
239
|
+
uploadDocument(document) {
|
|
240
|
+
return this.execute("uploadDocument", { pdf: document });
|
|
241
|
+
}
|
|
242
|
+
createLetterDraft(input) {
|
|
243
|
+
return this.execute("createLetterDraft", { json: input });
|
|
244
|
+
}
|
|
245
|
+
createFaxDraft(input) {
|
|
246
|
+
return this.execute("createFaxDraft", { json: input });
|
|
247
|
+
}
|
|
248
|
+
getDraft(draftId) {
|
|
249
|
+
return this.execute("getDraft", { pathParameters: { draftId: DraftIdSchema.parse(draftId) } });
|
|
250
|
+
}
|
|
251
|
+
quoteDraft(draftId) {
|
|
252
|
+
return this.execute("quoteDraft", {
|
|
253
|
+
pathParameters: { draftId: DraftIdSchema.parse(draftId) }
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
requestApproval(draftId, input) {
|
|
257
|
+
return this.execute("requestApproval", {
|
|
258
|
+
pathParameters: { draftId: DraftIdSchema.parse(draftId) },
|
|
259
|
+
json: input
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** Wallet-only dispatch after a human approval. Reuse the key only for an identical retry. */
|
|
263
|
+
createDispatch(draftId, input, idempotencyKey) {
|
|
264
|
+
return this.execute("createDispatch", {
|
|
265
|
+
pathParameters: { draftId: DraftIdSchema.parse(draftId) },
|
|
266
|
+
json: input,
|
|
267
|
+
idempotencyKey
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** Creates a user-controlled Checkout after human approval; opening it does not dispatch. */
|
|
271
|
+
createDirectPaymentSession(draftId, input, idempotencyKey) {
|
|
272
|
+
return this.execute("createDirectPaymentSession", {
|
|
273
|
+
pathParameters: { draftId: DraftIdSchema.parse(draftId) },
|
|
274
|
+
json: input,
|
|
275
|
+
idempotencyKey
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/** Tracks server-confirmed payment and the resulting dispatch; checkout_open is not paid. */
|
|
279
|
+
getDirectPayment(directPaymentId) {
|
|
280
|
+
return this.execute("getDirectPayment", {
|
|
281
|
+
pathParameters: {
|
|
282
|
+
directPaymentId: DirectPaymentIdSchema.parse(directPaymentId)
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
listDispatches(limit = 25) {
|
|
287
|
+
return this.execute("listDispatches", { queryParameters: { limit } });
|
|
288
|
+
}
|
|
289
|
+
getDispatch(dispatchId) {
|
|
290
|
+
return this.execute("getDispatch", {
|
|
291
|
+
pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) }
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
getDispatchSummary(dispatchId) {
|
|
295
|
+
return this.execute("getDispatchSummary", {
|
|
296
|
+
pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) }
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
getDispatchEvents(dispatchId) {
|
|
300
|
+
return this.execute("getDispatchEvents", {
|
|
301
|
+
pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) }
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
getDispatchProof(dispatchId) {
|
|
305
|
+
return this.execute("getDispatchProof", {
|
|
306
|
+
pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) }
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
cancelDispatch(dispatchId) {
|
|
310
|
+
return this.execute("cancelDispatch", {
|
|
311
|
+
pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) }
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
getWallet() {
|
|
315
|
+
return this.execute("getWallet");
|
|
316
|
+
}
|
|
317
|
+
async prepareLetterForReview(input, approvalExpiresInSeconds = 3600) {
|
|
318
|
+
const draft = await this.createLetterDraft(input);
|
|
319
|
+
const quote = await this.quoteDraft(draft.data.id);
|
|
320
|
+
const approval = await this.requestApproval(draft.data.id, {
|
|
321
|
+
quote_id: quote.data.id,
|
|
322
|
+
expires_in_seconds: approvalExpiresInSeconds
|
|
323
|
+
});
|
|
324
|
+
return { draft: draft.data, quote: quote.data, approval: approval.data };
|
|
325
|
+
}
|
|
326
|
+
async prepareFaxForReview(input, approvalExpiresInSeconds = 3600) {
|
|
327
|
+
const draft = await this.createFaxDraft(input);
|
|
328
|
+
const quote = await this.quoteDraft(draft.data.id);
|
|
329
|
+
const approval = await this.requestApproval(draft.data.id, {
|
|
330
|
+
quote_id: quote.data.id,
|
|
331
|
+
expires_in_seconds: approvalExpiresInSeconds
|
|
332
|
+
});
|
|
333
|
+
return { draft: draft.data, quote: quote.data, approval: approval.data };
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
export {
|
|
337
|
+
PapierApiClient,
|
|
338
|
+
PapierApiContractError,
|
|
339
|
+
PapierApiError,
|
|
340
|
+
PapierApiTransportError,
|
|
341
|
+
papierApiOperations
|
|
342
|
+
};
|
|
343
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts", "../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ApiError, ErrorCode } from \"@papierapi/contracts\";\n\nexport class PapierApiError extends Error {\n readonly status: number;\n readonly requestId: string;\n readonly code: ErrorCode;\n readonly retryable: boolean;\n readonly suggestedAction: string;\n readonly fieldPath: string | undefined;\n\n constructor(status: number, response: ApiError) {\n super(response.error.message);\n this.name = \"PapierApiError\";\n this.status = status;\n this.requestId = response.request_id;\n this.code = response.error.code;\n this.retryable = response.error.retryable;\n this.suggestedAction = response.error.suggested_action;\n this.fieldPath = response.error.field_path;\n }\n}\n\nexport class PapierApiContractError extends Error {\n readonly operationId: string;\n readonly status: number | undefined;\n\n constructor(message: string, operationId: string, status?: number) {\n super(message);\n this.name = \"PapierApiContractError\";\n this.operationId = operationId;\n this.status = status;\n }\n}\n\nexport class PapierApiTransportError extends Error {\n readonly reason: \"network\" | \"timeout\";\n readonly retryable = true;\n\n constructor(reason: \"network\" | \"timeout\") {\n super(reason === \"timeout\" ? \"Papier API request timed out\" : \"Papier API is unreachable\");\n this.name = \"PapierApiTransportError\";\n this.reason = reason;\n }\n}\n", "import {\n ApiErrorSchema,\n type ApprovalRequestSchema,\n type CreateApprovalRequestSchema,\n type CreateDirectPaymentSessionSchema,\n type CreateDispatchSchema,\n type CreateFaxDraftSchema,\n type CreateLetterDraftSchema,\n DirectPaymentIdSchema,\n DispatchIdSchema,\n type DispatchSchema,\n DraftIdSchema,\n type DraftSchema,\n IdempotencyKeySchema,\n type QuoteSchema,\n} from \"@papierapi/contracts\";\nimport type { z } from \"zod\";\nimport { PapierApiContractError, PapierApiError, PapierApiTransportError } from \"./errors\";\nimport {\n type PapierApiOperationName,\n type PapierApiOperationResponse,\n papierApiOperations,\n} from \"./operations\";\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst DEFAULT_MAX_RESPONSE_BYTES = 2 * 1024 * 1024;\nconst MAX_PDF_BYTES = 20 * 1024 * 1024;\n\ntype MaybePromise<T> = T | Promise<T>;\n\nexport type PapierApiAccessToken = string | (() => MaybePromise<string>);\nexport type PapierApiFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;\nexport type PdfDocument = Blob | ArrayBuffer | Uint8Array;\n\nexport type CreateLetterDraftInput = z.input<typeof CreateLetterDraftSchema>;\nexport type CreateFaxDraftInput = z.input<typeof CreateFaxDraftSchema>;\nexport type CreateApprovalRequestInput = z.input<typeof CreateApprovalRequestSchema>;\nexport type CreateDispatchInput = z.input<typeof CreateDispatchSchema>;\nexport type CreateDirectPaymentSessionInput = z.input<typeof CreateDirectPaymentSessionSchema>;\n\nexport type ReviewPackage = {\n draft: z.infer<typeof DraftSchema>;\n quote: z.infer<typeof QuoteSchema>;\n approval: z.infer<typeof ApprovalRequestSchema>;\n};\n\nexport type DispatchResult = z.infer<typeof DispatchSchema>;\n\nexport type PapierApiClientOptions = {\n baseUrl: string;\n accessToken: PapierApiAccessToken;\n fetcher?: PapierApiFetch;\n timeoutMs?: number;\n maxResponseBytes?: number;\n};\n\ntype ExecuteOptions = {\n pathParameters?: Record<string, unknown>;\n queryParameters?: Record<string, unknown>;\n json?: unknown;\n pdf?: PdfDocument;\n idempotencyKey?: string;\n};\n\nfunction boundedInteger(value: number | undefined, fallback: number, min: number, max: number) {\n const resolved = value ?? fallback;\n if (!Number.isInteger(resolved) || resolved < min || resolved > max) {\n throw new TypeError(`Expected an integer between ${min} and ${max}`);\n }\n return resolved;\n}\n\nfunction normalizeBaseUrl(value: string): string {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n throw new TypeError(\"baseUrl must be an absolute URL\");\n }\n\n const local = parsed.hostname === \"localhost\" || parsed.hostname === \"127.0.0.1\";\n if (parsed.protocol !== \"https:\" && !(local && parsed.protocol === \"http:\")) {\n throw new TypeError(\"baseUrl must use HTTPS except for localhost\");\n }\n if (\n parsed.username !== \"\" ||\n parsed.password !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n (parsed.pathname !== \"\" && parsed.pathname !== \"/\")\n ) {\n throw new TypeError(\"baseUrl must contain only an origin\");\n }\n return parsed.origin;\n}\n\nfunction validateToken(token: string): string {\n const hasControlOrWhitespace = Array.from(token).some((character) => {\n const code = character.charCodeAt(0);\n return code <= 32 || code === 127;\n });\n if (token.length < 8 || token.length > 8_192 || hasControlOrWhitespace) {\n throw new TypeError(\"accessToken is invalid\");\n }\n return token;\n}\n\nfunction pdfBody(document: PdfDocument): Blob {\n const size = document instanceof Blob ? document.size : document.byteLength;\n if (size < 1 || size > MAX_PDF_BYTES) {\n throw new TypeError(`PDF must contain between 1 and ${MAX_PDF_BYTES} bytes`);\n }\n if (document instanceof Blob) return document;\n if (document instanceof Uint8Array) {\n const copy = new Uint8Array(document.byteLength);\n copy.set(document);\n return new Blob([copy.buffer], { type: \"application/pdf\" });\n }\n return new Blob([document], { type: \"application/pdf\" });\n}\n\nasync function boundedResponseText(\n response: Response,\n maxBytes: number,\n operationId: string,\n): Promise<string> {\n const contentLength = response.headers.get(\"Content-Length\");\n if (contentLength !== null) {\n const parsed = Number(contentLength);\n if (Number.isFinite(parsed) && parsed > maxBytes) {\n throw new PapierApiContractError(\n \"Papier API response exceeded the configured size limit\",\n operationId,\n response.status,\n );\n }\n }\n\n if (response.body === null) return \"\";\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let bytesRead = 0;\n let text = \"\";\n\n while (true) {\n const chunk = await reader.read();\n if (chunk.done) break;\n bytesRead += chunk.value.byteLength;\n if (bytesRead > maxBytes) {\n await reader.cancel().catch(() => undefined);\n throw new PapierApiContractError(\n \"Papier API response exceeded the configured size limit\",\n operationId,\n response.status,\n );\n }\n text += decoder.decode(chunk.value, { stream: true });\n }\n return text + decoder.decode();\n}\n\nfunction parseJson(text: string, operationId: string, status: number): unknown {\n try {\n return JSON.parse(text);\n } catch {\n throw new PapierApiContractError(\"Papier API returned invalid JSON\", operationId, status);\n }\n}\n\nexport class PapierApiClient {\n readonly baseUrl: string;\n private readonly accessToken: PapierApiAccessToken;\n private readonly fetcher: PapierApiFetch;\n private readonly timeoutMs: number;\n private readonly maxResponseBytes: number;\n\n constructor(options: PapierApiClientOptions) {\n this.baseUrl = normalizeBaseUrl(options.baseUrl);\n this.accessToken = options.accessToken;\n const fetcher = options.fetcher ?? globalThis.fetch;\n if (typeof fetcher !== \"function\") throw new TypeError(\"A fetch implementation is required\");\n this.fetcher = fetcher.bind(globalThis);\n this.timeoutMs = boundedInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, 1, 120_000);\n this.maxResponseBytes = boundedInteger(\n options.maxResponseBytes,\n DEFAULT_MAX_RESPONSE_BYTES,\n 256,\n 10 * 1024 * 1024,\n );\n }\n\n private async token(): Promise<string> {\n const value =\n typeof this.accessToken === \"function\" ? await this.accessToken() : this.accessToken;\n return validateToken(value);\n }\n\n private async execute<Name extends PapierApiOperationName>(\n name: Name,\n options: ExecuteOptions = {},\n ): Promise<PapierApiOperationResponse<Name>> {\n const operation = papierApiOperations[name];\n let path: string = operation.path;\n for (const [parameterName, parameterSchema] of Object.entries(operation.pathParameters)) {\n const parsed = parameterSchema.parse(options.pathParameters?.[parameterName]);\n path = path.replace(`{${parameterName}}`, encodeURIComponent(String(parsed)));\n }\n if (path.includes(\"{\")) {\n throw new PapierApiContractError(\n \"REST operation has an unresolved path\",\n operation.operationId,\n );\n }\n\n const url = new URL(`${this.baseUrl}${path}`);\n for (const [parameterName, parameterSchema] of Object.entries(operation.queryParameters)) {\n const parsed = parameterSchema.parse(options.queryParameters?.[parameterName]);\n if (parsed !== undefined) url.searchParams.set(parameterName, String(parsed));\n }\n\n const headers = new Headers({\n Accept: \"application/json\",\n Authorization: `Bearer ${await this.token()}`,\n });\n let body: BodyInit | undefined;\n if (operation.request.kind === \"json\") {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(operation.request.schema.parse(options.json));\n } else if (operation.request.kind === \"pdf\") {\n headers.set(\"Content-Type\", \"application/pdf\");\n if (options.pdf === undefined) throw new TypeError(\"A PDF document is required\");\n body = pdfBody(options.pdf);\n }\n\n if (operation.requiresIdempotencyKey) {\n headers.set(\"Idempotency-Key\", IdempotencyKeySchema.parse(options.idempotencyKey));\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.timeoutMs);\n let response: Response;\n try {\n const requestInit: RequestInit = {\n method: operation.method,\n headers,\n signal: controller.signal,\n ...(body === undefined ? {} : { body }),\n };\n response = await this.fetcher(url, requestInit);\n } catch {\n throw new PapierApiTransportError(controller.signal.aborted ? \"timeout\" : \"network\");\n } finally {\n clearTimeout(timeout);\n }\n\n const parsed = parseJson(\n await boundedResponseText(response, this.maxResponseBytes, operation.operationId),\n operation.operationId,\n response.status,\n );\n if (!response.ok) {\n const apiError = ApiErrorSchema.safeParse(parsed);\n if (!apiError.success) {\n throw new PapierApiContractError(\n \"Papier API returned a malformed error response\",\n operation.operationId,\n response.status,\n );\n }\n throw new PapierApiError(response.status, apiError.data);\n }\n\n const validated = operation.responseSchema.safeParse(parsed);\n if (!validated.success) {\n throw new PapierApiContractError(\n \"Papier API response did not match the published contract\",\n operation.operationId,\n response.status,\n );\n }\n return validated.data as PapierApiOperationResponse<Name>;\n }\n\n uploadDocument(document: PdfDocument) {\n return this.execute(\"uploadDocument\", { pdf: document });\n }\n\n createLetterDraft(input: CreateLetterDraftInput) {\n return this.execute(\"createLetterDraft\", { json: input });\n }\n\n createFaxDraft(input: CreateFaxDraftInput) {\n return this.execute(\"createFaxDraft\", { json: input });\n }\n\n getDraft(draftId: string) {\n return this.execute(\"getDraft\", { pathParameters: { draftId: DraftIdSchema.parse(draftId) } });\n }\n\n quoteDraft(draftId: string) {\n return this.execute(\"quoteDraft\", {\n pathParameters: { draftId: DraftIdSchema.parse(draftId) },\n });\n }\n\n requestApproval(draftId: string, input: CreateApprovalRequestInput) {\n return this.execute(\"requestApproval\", {\n pathParameters: { draftId: DraftIdSchema.parse(draftId) },\n json: input,\n });\n }\n\n /** Wallet-only dispatch after a human approval. Reuse the key only for an identical retry. */\n createDispatch(draftId: string, input: CreateDispatchInput, idempotencyKey: string) {\n return this.execute(\"createDispatch\", {\n pathParameters: { draftId: DraftIdSchema.parse(draftId) },\n json: input,\n idempotencyKey,\n });\n }\n\n /** Creates a user-controlled Checkout after human approval; opening it does not dispatch. */\n createDirectPaymentSession(\n draftId: string,\n input: CreateDirectPaymentSessionInput,\n idempotencyKey: string,\n ) {\n return this.execute(\"createDirectPaymentSession\", {\n pathParameters: { draftId: DraftIdSchema.parse(draftId) },\n json: input,\n idempotencyKey,\n });\n }\n\n /** Tracks server-confirmed payment and the resulting dispatch; checkout_open is not paid. */\n getDirectPayment(directPaymentId: string) {\n return this.execute(\"getDirectPayment\", {\n pathParameters: {\n directPaymentId: DirectPaymentIdSchema.parse(directPaymentId),\n },\n });\n }\n\n listDispatches(limit = 25) {\n return this.execute(\"listDispatches\", { queryParameters: { limit } });\n }\n\n getDispatch(dispatchId: string) {\n return this.execute(\"getDispatch\", {\n pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) },\n });\n }\n\n getDispatchSummary(dispatchId: string) {\n return this.execute(\"getDispatchSummary\", {\n pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) },\n });\n }\n\n getDispatchEvents(dispatchId: string) {\n return this.execute(\"getDispatchEvents\", {\n pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) },\n });\n }\n\n getDispatchProof(dispatchId: string) {\n return this.execute(\"getDispatchProof\", {\n pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) },\n });\n }\n\n cancelDispatch(dispatchId: string) {\n return this.execute(\"cancelDispatch\", {\n pathParameters: { dispatchId: DispatchIdSchema.parse(dispatchId) },\n });\n }\n\n getWallet() {\n return this.execute(\"getWallet\");\n }\n\n async prepareLetterForReview(\n input: CreateLetterDraftInput,\n approvalExpiresInSeconds = 3_600,\n ): Promise<ReviewPackage> {\n const draft = await this.createLetterDraft(input);\n const quote = await this.quoteDraft(draft.data.id);\n const approval = await this.requestApproval(draft.data.id, {\n quote_id: quote.data.id,\n expires_in_seconds: approvalExpiresInSeconds,\n });\n return { draft: draft.data, quote: quote.data, approval: approval.data };\n }\n\n async prepareFaxForReview(\n input: CreateFaxDraftInput,\n approvalExpiresInSeconds = 3_600,\n ): Promise<ReviewPackage> {\n const draft = await this.createFaxDraft(input);\n const quote = await this.quoteDraft(draft.data.id);\n const approval = await this.requestApproval(draft.data.id, {\n quote_id: quote.data.id,\n expires_in_seconds: approvalExpiresInSeconds,\n });\n return { draft: draft.data, quote: quote.data, approval: approval.data };\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAEO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,UAAoB;AAC9C,UAAM,SAAS,MAAM,OAAO;AAC5B,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,YAAY,SAAS;AAC1B,SAAK,OAAO,SAAS,MAAM;AAC3B,SAAK,YAAY,SAAS,MAAM;AAChC,SAAK,kBAAkB,SAAS,MAAM;AACtC,SAAK,YAAY,SAAS,MAAM;AAAA,EAClC;AACF;AAEO,IAAM,y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
|
|
6
|
+
"names": ["parsed"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CurrencySchema: z.ZodLiteral<"EUR">;
|
|
3
|
+
export type Currency = z.infer<typeof CurrencySchema>;
|
|
4
|
+
export declare const IsoDateSchema: z.ZodISODate;
|
|
5
|
+
export declare const IsoDateTimeSchema: z.ZodISODateTime;
|
|
6
|
+
export declare const IdempotencyKeySchema: z.ZodString;
|
|
7
|
+
export declare function prefixedId(prefix: string): z.ZodString;
|
|
8
|
+
export declare const OrganizationIdSchema: z.ZodString;
|
|
9
|
+
export declare const WorkspaceIdSchema: z.ZodString;
|
|
10
|
+
export declare const SenderProfileIdSchema: z.ZodString;
|
|
11
|
+
export declare const DocumentIdSchema: z.ZodString;
|
|
12
|
+
export declare const DraftIdSchema: z.ZodString;
|
|
13
|
+
export declare const VerificationRunIdSchema: z.ZodString;
|
|
14
|
+
export declare const QuoteIdSchema: z.ZodString;
|
|
15
|
+
export declare const ApprovalRequestIdSchema: z.ZodString;
|
|
16
|
+
export declare const ApprovalIdSchema: z.ZodString;
|
|
17
|
+
export declare const DirectPaymentIdSchema: z.ZodString;
|
|
18
|
+
export declare const DispatchIdSchema: z.ZodString;
|
|
19
|
+
export declare const EventIdSchema: z.ZodString;
|
|
20
|
+
export declare const WebhookEndpointIdSchema: z.ZodString;
|
|
21
|
+
export declare const RequestIdSchema: z.ZodString;
|
|
22
|
+
export declare const MoneySchema: z.ZodObject<{
|
|
23
|
+
amount_cents: z.ZodInt;
|
|
24
|
+
currency: z.ZodLiteral<"EUR">;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export type Money = z.infer<typeof MoneySchema>;
|
|
27
|
+
export declare const MetadataSchema: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
28
|
+
export declare const NextActionSchema: z.ZodObject<{
|
|
29
|
+
action: z.ZodString;
|
|
30
|
+
method: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
GET: "GET";
|
|
32
|
+
POST: "POST";
|
|
33
|
+
PATCH: "PATCH";
|
|
34
|
+
DELETE: "DELETE";
|
|
35
|
+
}>>;
|
|
36
|
+
href: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type NextAction = z.infer<typeof NextActionSchema>;
|
|
39
|
+
export declare const PaginationQuerySchema: z.ZodObject<{
|
|
40
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
41
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
export declare const PaginatedMetaSchema: z.ZodObject<{
|
|
44
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
45
|
+
has_more: z.ZodBoolean;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
export declare const Sha256Schema: z.ZodString;
|
|
48
|
+
export declare const VerificationViolationSchema: z.ZodObject<{
|
|
49
|
+
code: z.ZodString;
|
|
50
|
+
field_path: z.ZodOptional<z.ZodString>;
|
|
51
|
+
page: z.ZodOptional<z.ZodInt>;
|
|
52
|
+
rule: z.ZodString;
|
|
53
|
+
message: z.ZodString;
|
|
54
|
+
suggested_action: z.ZodString;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
export type VerificationViolation = z.infer<typeof VerificationViolationSchema>;
|
|
57
|
+
export declare const VerificationCheckSchema: z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
version: z.ZodString;
|
|
60
|
+
status: z.ZodEnum<{
|
|
61
|
+
passed: "passed";
|
|
62
|
+
warning: "warning";
|
|
63
|
+
failed: "failed";
|
|
64
|
+
skipped: "skipped";
|
|
65
|
+
}>;
|
|
66
|
+
rule: z.ZodString;
|
|
67
|
+
evidence: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
68
|
+
violations: z.ZodArray<z.ZodObject<{
|
|
69
|
+
code: z.ZodString;
|
|
70
|
+
field_path: z.ZodOptional<z.ZodString>;
|
|
71
|
+
page: z.ZodOptional<z.ZodInt>;
|
|
72
|
+
rule: z.ZodString;
|
|
73
|
+
message: z.ZodString;
|
|
74
|
+
suggested_action: z.ZodString;
|
|
75
|
+
}, z.core.$strict>>;
|
|
76
|
+
duration_ms: z.ZodInt;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type VerificationCheck = z.infer<typeof VerificationCheckSchema>;
|
|
79
|
+
export declare const VerificationSummarySchema: z.ZodObject<{
|
|
80
|
+
status: z.ZodEnum<{
|
|
81
|
+
passed: "passed";
|
|
82
|
+
warning: "warning";
|
|
83
|
+
failed: "failed";
|
|
84
|
+
}>;
|
|
85
|
+
checks: z.ZodArray<z.ZodObject<{
|
|
86
|
+
id: z.ZodString;
|
|
87
|
+
version: z.ZodString;
|
|
88
|
+
status: z.ZodEnum<{
|
|
89
|
+
passed: "passed";
|
|
90
|
+
warning: "warning";
|
|
91
|
+
failed: "failed";
|
|
92
|
+
skipped: "skipped";
|
|
93
|
+
}>;
|
|
94
|
+
rule: z.ZodString;
|
|
95
|
+
evidence: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
96
|
+
violations: z.ZodArray<z.ZodObject<{
|
|
97
|
+
code: z.ZodString;
|
|
98
|
+
field_path: z.ZodOptional<z.ZodString>;
|
|
99
|
+
page: z.ZodOptional<z.ZodInt>;
|
|
100
|
+
rule: z.ZodString;
|
|
101
|
+
message: z.ZodString;
|
|
102
|
+
suggested_action: z.ZodString;
|
|
103
|
+
}, z.core.$strict>>;
|
|
104
|
+
duration_ms: z.ZodInt;
|
|
105
|
+
}, z.core.$strict>>;
|
|
106
|
+
verifier_version: z.ZodString;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
export type VerificationSummary = z.infer<typeof VerificationSummarySchema>;
|