@insureco/docman 1.0.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/dist/chunk-7DJVMOS3.js +15 -0
- package/dist/chunk-7DJVMOS3.js.map +1 -0
- package/dist/index.cjs +478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +443 -0
- package/dist/index.js.map +1 -0
- package/dist/mock.cjs +339 -0
- package/dist/mock.cjs.map +1 -0
- package/dist/mock.d.cts +58 -0
- package/dist/mock.d.ts +58 -0
- package/dist/mock.js +305 -0
- package/dist/mock.js.map +1 -0
- package/dist/types-xbeSIrNB.d.cts +185 -0
- package/dist/types-xbeSIrNB.d.ts +185 -0
- package/package.json +44 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var DocmanError = class extends Error {
|
|
3
|
+
constructor(message, statusCode, code, details) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.statusCode = statusCode;
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.details = details;
|
|
8
|
+
this.name = "DocmanError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
DocmanError
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-7DJVMOS3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["export class DocmanError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number,\n public readonly code?: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message)\n this.name = 'DocmanError'\n }\n}\n"],"mappings":";AAAO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YACA,MACA,SAChB;AACA,UAAM,OAAO;AAJG;AACA;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
DocmanClient: () => DocmanClient,
|
|
24
|
+
DocmanError: () => DocmanError
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/errors.ts
|
|
29
|
+
var DocmanError = class extends Error {
|
|
30
|
+
constructor(message, statusCode, code, details) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.statusCode = statusCode;
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.details = details;
|
|
35
|
+
this.name = "DocmanError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/client.ts
|
|
40
|
+
var DEFAULT_RETRIES = 2;
|
|
41
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
42
|
+
var TOKEN_BUFFER_SECONDS = 30;
|
|
43
|
+
function sleep(ms) {
|
|
44
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
45
|
+
}
|
|
46
|
+
function backoff(attempt) {
|
|
47
|
+
const base = Math.min(1e3 * 2 ** attempt, 5e3);
|
|
48
|
+
return base * (0.5 + Math.random() * 0.5);
|
|
49
|
+
}
|
|
50
|
+
function isTokenExpired(token, bufferSeconds = TOKEN_BUFFER_SECONDS) {
|
|
51
|
+
try {
|
|
52
|
+
const parts = token.split(".");
|
|
53
|
+
if (parts.length !== 3) return true;
|
|
54
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
|
|
55
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
56
|
+
return (payload.exp ?? 0) <= now + bufferSeconds;
|
|
57
|
+
} catch {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function extractError(envelope) {
|
|
62
|
+
const err = envelope.error;
|
|
63
|
+
if (typeof err === "object" && err !== null) return err;
|
|
64
|
+
return { code: "REQUEST_ERROR", message: err ?? "Request failed" };
|
|
65
|
+
}
|
|
66
|
+
var DocmanClient = class _DocmanClient {
|
|
67
|
+
baseUrl;
|
|
68
|
+
accessTokenFn;
|
|
69
|
+
internalKey;
|
|
70
|
+
retries;
|
|
71
|
+
timeoutMs;
|
|
72
|
+
cachedToken = null;
|
|
73
|
+
constructor(config) {
|
|
74
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
75
|
+
this.accessTokenFn = config.accessTokenFn;
|
|
76
|
+
this.internalKey = config.internalKey;
|
|
77
|
+
this.retries = config.retries ?? DEFAULT_RETRIES;
|
|
78
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a client from environment variables.
|
|
82
|
+
*
|
|
83
|
+
* Reads DOCMAN_URL (injected automatically when you declare docman as an
|
|
84
|
+
* internalDependency in catalog-info.yaml). Auth priority:
|
|
85
|
+
* 1. BIO_CLIENT_ID + BIO_CLIENT_SECRET → client_credentials token
|
|
86
|
+
* 2. INTERNAL_SERVICE_KEY → internal key header
|
|
87
|
+
* 3. No auth → local dev / testing
|
|
88
|
+
*
|
|
89
|
+
* catalog-info.yaml:
|
|
90
|
+
* spec:
|
|
91
|
+
* internalDependencies:
|
|
92
|
+
* - service: docman
|
|
93
|
+
* port: 3000
|
|
94
|
+
*/
|
|
95
|
+
static fromEnv() {
|
|
96
|
+
const baseUrl = process.env.DOCMAN_URL;
|
|
97
|
+
if (!baseUrl) {
|
|
98
|
+
throw new DocmanError(
|
|
99
|
+
"DOCMAN_URL is not set. Add docman as an internalDependency in catalog-info.yaml",
|
|
100
|
+
500,
|
|
101
|
+
"CONFIG_ERROR"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const clientId = process.env.BIO_CLIENT_ID;
|
|
105
|
+
const clientSecret = process.env.BIO_CLIENT_SECRET;
|
|
106
|
+
const bioIdUrl = process.env.BIO_ID_URL ?? "https://bio.tawa.insureco.io";
|
|
107
|
+
if (clientId && clientSecret) {
|
|
108
|
+
return new _DocmanClient({
|
|
109
|
+
baseUrl,
|
|
110
|
+
accessTokenFn: async () => {
|
|
111
|
+
const res = await fetch(`${bioIdUrl}/api/oauth/token`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
grant_type: "client_credentials",
|
|
116
|
+
client_id: clientId,
|
|
117
|
+
client_secret: clientSecret
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
throw new DocmanError("Failed to obtain Bio-ID access token", res.status, "AUTH_ERROR");
|
|
122
|
+
}
|
|
123
|
+
const data = await res.json();
|
|
124
|
+
return data.access_token;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const internalKey = process.env.INTERNAL_SERVICE_KEY;
|
|
129
|
+
if (internalKey) {
|
|
130
|
+
return new _DocmanClient({ baseUrl, internalKey });
|
|
131
|
+
}
|
|
132
|
+
return new _DocmanClient({ baseUrl });
|
|
133
|
+
}
|
|
134
|
+
// ─── Auth ────────────────────────────────────────────────
|
|
135
|
+
async authHeaders() {
|
|
136
|
+
if (this.accessTokenFn) {
|
|
137
|
+
if (!this.cachedToken || isTokenExpired(this.cachedToken)) {
|
|
138
|
+
this.cachedToken = await this.accessTokenFn();
|
|
139
|
+
}
|
|
140
|
+
return { Authorization: `Bearer ${this.cachedToken}` };
|
|
141
|
+
}
|
|
142
|
+
if (this.internalKey) {
|
|
143
|
+
return { "X-Internal-Key": this.internalKey };
|
|
144
|
+
}
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
// ─── Core fetch ──────────────────────────────────────────
|
|
148
|
+
async rawFetch(method, path, body, attempt = 0) {
|
|
149
|
+
const headers = await this.authHeaders();
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
152
|
+
let response;
|
|
153
|
+
try {
|
|
154
|
+
response = await fetch(`${this.baseUrl}${path}`, {
|
|
155
|
+
method,
|
|
156
|
+
headers: body !== void 0 ? { ...headers, "Content-Type": "application/json" } : headers,
|
|
157
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
158
|
+
signal: controller.signal
|
|
159
|
+
});
|
|
160
|
+
} catch (err) {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
if (attempt < this.retries) {
|
|
163
|
+
await sleep(backoff(attempt));
|
|
164
|
+
return this.rawFetch(method, path, body, attempt + 1);
|
|
165
|
+
}
|
|
166
|
+
throw new DocmanError(`Network error: ${err.message}`, 0, "NETWORK_ERROR");
|
|
167
|
+
} finally {
|
|
168
|
+
clearTimeout(timer);
|
|
169
|
+
}
|
|
170
|
+
if (response.status >= 500 && attempt < this.retries) {
|
|
171
|
+
await sleep(backoff(attempt));
|
|
172
|
+
return this.rawFetch(method, path, body, attempt + 1);
|
|
173
|
+
}
|
|
174
|
+
const envelope = await response.json();
|
|
175
|
+
if (!response.ok || !envelope.success) {
|
|
176
|
+
const { code, message } = extractError(envelope);
|
|
177
|
+
throw new DocmanError(message, response.status, code);
|
|
178
|
+
}
|
|
179
|
+
return envelope;
|
|
180
|
+
}
|
|
181
|
+
async fetchData(method, path, body) {
|
|
182
|
+
const envelope = await this.rawFetch(method, path, body);
|
|
183
|
+
return envelope.data;
|
|
184
|
+
}
|
|
185
|
+
async fetchList(path) {
|
|
186
|
+
const envelope = await this.rawFetch("GET", path);
|
|
187
|
+
return {
|
|
188
|
+
data: envelope.data ?? [],
|
|
189
|
+
meta: envelope.meta ?? { total: 0, page: 1, limit: 20 }
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
buildQuery(params) {
|
|
193
|
+
const pairs = Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
|
|
194
|
+
return pairs.length > 0 ? `?${pairs.join("&")}` : "";
|
|
195
|
+
}
|
|
196
|
+
/** Fetch with FormData body (multipart), return raw binary buffer. */
|
|
197
|
+
async fetchBinary(method, path, formData, attempt = 0) {
|
|
198
|
+
const headers = await this.authHeaders();
|
|
199
|
+
const controller = new AbortController();
|
|
200
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
201
|
+
let response;
|
|
202
|
+
try {
|
|
203
|
+
response = await fetch(`${this.baseUrl}${path}`, {
|
|
204
|
+
method,
|
|
205
|
+
headers,
|
|
206
|
+
body: formData,
|
|
207
|
+
signal: controller.signal
|
|
208
|
+
});
|
|
209
|
+
} catch (err) {
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
if (attempt < this.retries) {
|
|
212
|
+
await sleep(backoff(attempt));
|
|
213
|
+
return this.fetchBinary(method, path, formData, attempt + 1);
|
|
214
|
+
}
|
|
215
|
+
throw new DocmanError(`Network error: ${err.message}`, 0, "NETWORK_ERROR");
|
|
216
|
+
} finally {
|
|
217
|
+
clearTimeout(timer);
|
|
218
|
+
}
|
|
219
|
+
if (response.status >= 500 && attempt < this.retries) {
|
|
220
|
+
await sleep(backoff(attempt));
|
|
221
|
+
return this.fetchBinary(method, path, formData, attempt + 1);
|
|
222
|
+
}
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
const envelope = await response.json();
|
|
225
|
+
const { code, message } = extractError(envelope);
|
|
226
|
+
throw new DocmanError(message, response.status, code);
|
|
227
|
+
}
|
|
228
|
+
return Buffer.from(await response.arrayBuffer());
|
|
229
|
+
}
|
|
230
|
+
/** POST multipart form and parse the JSON response envelope. */
|
|
231
|
+
async fetchMultipartJson(path, formData) {
|
|
232
|
+
const headers = await this.authHeaders();
|
|
233
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
234
|
+
method: "POST",
|
|
235
|
+
headers,
|
|
236
|
+
body: formData
|
|
237
|
+
});
|
|
238
|
+
const envelope = await response.json();
|
|
239
|
+
if (!response.ok || !envelope.success) {
|
|
240
|
+
const { code, message } = extractError(envelope);
|
|
241
|
+
throw new DocmanError(message, response.status, code);
|
|
242
|
+
}
|
|
243
|
+
return envelope.data;
|
|
244
|
+
}
|
|
245
|
+
/** PUT multipart form and parse the JSON response envelope. */
|
|
246
|
+
async putMultipartJson(path, formData) {
|
|
247
|
+
const headers = await this.authHeaders();
|
|
248
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
249
|
+
method: "PUT",
|
|
250
|
+
headers,
|
|
251
|
+
body: formData
|
|
252
|
+
});
|
|
253
|
+
const envelope = await response.json();
|
|
254
|
+
if (!response.ok || !envelope.success) {
|
|
255
|
+
const { code, message } = extractError(envelope);
|
|
256
|
+
throw new DocmanError(message, response.status, code);
|
|
257
|
+
}
|
|
258
|
+
return envelope.data;
|
|
259
|
+
}
|
|
260
|
+
// ─── HTML Templates ──────────────────────────────────────
|
|
261
|
+
async createHtmlTemplate(options) {
|
|
262
|
+
return this.fetchData("POST", "/templates/html", options);
|
|
263
|
+
}
|
|
264
|
+
async listHtmlTemplates(query = {}) {
|
|
265
|
+
return this.fetchList(`/templates/html${this.buildQuery(query)}`);
|
|
266
|
+
}
|
|
267
|
+
async getHtmlTemplate(id) {
|
|
268
|
+
return this.fetchData("GET", `/templates/html/${encodeURIComponent(id)}`);
|
|
269
|
+
}
|
|
270
|
+
async updateHtmlTemplate(id, options) {
|
|
271
|
+
return this.fetchData("PUT", `/templates/html/${encodeURIComponent(id)}`, options);
|
|
272
|
+
}
|
|
273
|
+
async deleteHtmlTemplate(id) {
|
|
274
|
+
return this.fetchData("DELETE", `/templates/html/${encodeURIComponent(id)}`);
|
|
275
|
+
}
|
|
276
|
+
// ─── PDF Templates ───────────────────────────────────────
|
|
277
|
+
/**
|
|
278
|
+
* Upload a PDF form template.
|
|
279
|
+
* @param file Raw PDF bytes (Buffer or Uint8Array)
|
|
280
|
+
* @param options Name, description, and optional coordinates/isSystem flags
|
|
281
|
+
*/
|
|
282
|
+
async uploadPdfTemplate(file, options = {}) {
|
|
283
|
+
const form = new FormData();
|
|
284
|
+
const filename = options.name ?? "template.pdf";
|
|
285
|
+
form.append("file", new Blob([file], { type: "application/pdf" }), filename);
|
|
286
|
+
if (options.name) form.append("name", options.name);
|
|
287
|
+
if (options.description) form.append("description", options.description);
|
|
288
|
+
if (options.coordinates) form.append("coordinates", JSON.stringify(options.coordinates));
|
|
289
|
+
if (options.isSystem !== void 0) form.append("isSystem", String(options.isSystem));
|
|
290
|
+
return this.fetchMultipartJson("/templates/pdf", form);
|
|
291
|
+
}
|
|
292
|
+
async listPdfTemplates(query = {}) {
|
|
293
|
+
return this.fetchList(`/templates/pdf${this.buildQuery(query)}`);
|
|
294
|
+
}
|
|
295
|
+
async getPdfTemplate(id) {
|
|
296
|
+
return this.fetchData("GET", `/templates/pdf/${encodeURIComponent(id)}`);
|
|
297
|
+
}
|
|
298
|
+
async getPdfTemplateFields(id) {
|
|
299
|
+
return this.fetchData("GET", `/templates/pdf/${encodeURIComponent(id)}/fields`);
|
|
300
|
+
}
|
|
301
|
+
async getPdfTemplateDownloadUrl(id) {
|
|
302
|
+
const data = await this.fetchData("GET", `/templates/pdf/${encodeURIComponent(id)}/download`);
|
|
303
|
+
return data.url;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Update a PDF template's metadata, and optionally replace the PDF file.
|
|
307
|
+
* @param file If provided, replaces the stored PDF and re-extracts form fields
|
|
308
|
+
*/
|
|
309
|
+
async updatePdfTemplate(id, options, file) {
|
|
310
|
+
if (file) {
|
|
311
|
+
const form = new FormData();
|
|
312
|
+
form.append("file", new Blob([file], { type: "application/pdf" }), "template.pdf");
|
|
313
|
+
if (options.name) form.append("name", options.name);
|
|
314
|
+
if (options.description) form.append("description", options.description);
|
|
315
|
+
if (options.coordinates) form.append("coordinates", JSON.stringify(options.coordinates));
|
|
316
|
+
return this.putMultipartJson(`/templates/pdf/${encodeURIComponent(id)}`, form);
|
|
317
|
+
}
|
|
318
|
+
return this.fetchData("PUT", `/templates/pdf/${encodeURIComponent(id)}`, options);
|
|
319
|
+
}
|
|
320
|
+
async deletePdfTemplate(id) {
|
|
321
|
+
return this.fetchData("DELETE", `/templates/pdf/${encodeURIComponent(id)}`);
|
|
322
|
+
}
|
|
323
|
+
// ─── Template Groups ─────────────────────────────────────
|
|
324
|
+
async createTemplateGroup(options) {
|
|
325
|
+
return this.fetchData("POST", "/template-groups", options);
|
|
326
|
+
}
|
|
327
|
+
async listTemplateGroups(query = {}) {
|
|
328
|
+
return this.fetchList(`/template-groups${this.buildQuery(query)}`);
|
|
329
|
+
}
|
|
330
|
+
async getTemplateGroup(id) {
|
|
331
|
+
return this.fetchData("GET", `/template-groups/${encodeURIComponent(id)}`);
|
|
332
|
+
}
|
|
333
|
+
async updateTemplateGroup(id, options) {
|
|
334
|
+
return this.fetchData("PUT", `/template-groups/${encodeURIComponent(id)}`, options);
|
|
335
|
+
}
|
|
336
|
+
async deleteTemplateGroup(id) {
|
|
337
|
+
await this.fetchData("DELETE", `/template-groups/${encodeURIComponent(id)}`);
|
|
338
|
+
}
|
|
339
|
+
// ─── Document Generation ─────────────────────────────────
|
|
340
|
+
/**
|
|
341
|
+
* Generate a document and store it in S3.
|
|
342
|
+
* Returns a presigned download URL and a public share URL.
|
|
343
|
+
*/
|
|
344
|
+
async generate(options) {
|
|
345
|
+
return this.fetchData("POST", "/documents/generate", {
|
|
346
|
+
templateIds: options.templateIds,
|
|
347
|
+
templateData: options.data,
|
|
348
|
+
name: options.name,
|
|
349
|
+
description: options.description
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Generate a document and stream the PDF buffer directly.
|
|
354
|
+
* Nothing is stored — useful for previews or on-the-fly delivery.
|
|
355
|
+
*/
|
|
356
|
+
async generatePassthrough(options) {
|
|
357
|
+
const headers = await this.authHeaders();
|
|
358
|
+
const controller = new AbortController();
|
|
359
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
360
|
+
let response;
|
|
361
|
+
try {
|
|
362
|
+
response = await fetch(`${this.baseUrl}/documents/generate/passthrough`, {
|
|
363
|
+
method: "POST",
|
|
364
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
365
|
+
body: JSON.stringify({
|
|
366
|
+
templateIds: options.templateIds,
|
|
367
|
+
templateData: options.data,
|
|
368
|
+
name: options.name,
|
|
369
|
+
description: options.description
|
|
370
|
+
}),
|
|
371
|
+
signal: controller.signal
|
|
372
|
+
});
|
|
373
|
+
} catch (err) {
|
|
374
|
+
clearTimeout(timer);
|
|
375
|
+
throw new DocmanError(`Network error: ${err.message}`, 0, "NETWORK_ERROR");
|
|
376
|
+
} finally {
|
|
377
|
+
clearTimeout(timer);
|
|
378
|
+
}
|
|
379
|
+
if (!response.ok) {
|
|
380
|
+
const envelope = await response.json();
|
|
381
|
+
const { code, message } = extractError(envelope);
|
|
382
|
+
throw new DocmanError(message, response.status, code);
|
|
383
|
+
}
|
|
384
|
+
return Buffer.from(await response.arrayBuffer());
|
|
385
|
+
}
|
|
386
|
+
async listDocuments(query = {}) {
|
|
387
|
+
return this.fetchList(`/documents${this.buildQuery(query)}`);
|
|
388
|
+
}
|
|
389
|
+
async getDocument(id) {
|
|
390
|
+
return this.fetchData("GET", `/documents/${encodeURIComponent(id)}`);
|
|
391
|
+
}
|
|
392
|
+
/** Get a presigned S3 download URL for a stored document (1-hour TTL). */
|
|
393
|
+
async downloadUrl(id) {
|
|
394
|
+
const data = await this.fetchData("GET", `/documents/${encodeURIComponent(id)}/download`);
|
|
395
|
+
return data.url;
|
|
396
|
+
}
|
|
397
|
+
async getVersions(id) {
|
|
398
|
+
return this.fetchData("GET", `/documents/${encodeURIComponent(id)}/versions`);
|
|
399
|
+
}
|
|
400
|
+
/** Re-render a stored document using the original template data. */
|
|
401
|
+
async regenerate(id) {
|
|
402
|
+
return this.fetchData("POST", `/documents/${encodeURIComponent(id)}/regenerate`);
|
|
403
|
+
}
|
|
404
|
+
// ─── PDF Operations ──────────────────────────────────────
|
|
405
|
+
/**
|
|
406
|
+
* Merge two or more PDF buffers into a single PDF.
|
|
407
|
+
* Returns the merged PDF as a Buffer.
|
|
408
|
+
*/
|
|
409
|
+
async merge(buffers) {
|
|
410
|
+
if (buffers.length < 2) {
|
|
411
|
+
throw new DocmanError("At least 2 PDF buffers are required for merge", 400, "VALIDATION_ERROR");
|
|
412
|
+
}
|
|
413
|
+
const form = new FormData();
|
|
414
|
+
for (const buf of buffers) {
|
|
415
|
+
form.append("files", new Blob([buf], { type: "application/pdf" }), "file.pdf");
|
|
416
|
+
}
|
|
417
|
+
return this.fetchBinary("POST", "/operations/merge", form);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Split a PDF into parts by page ranges.
|
|
421
|
+
* Returns an array of SplitPart with buffer, range, and size info.
|
|
422
|
+
*/
|
|
423
|
+
async split(buffer, ranges) {
|
|
424
|
+
if (ranges.length === 0) {
|
|
425
|
+
throw new DocmanError("At least 1 page range is required", 400, "VALIDATION_ERROR");
|
|
426
|
+
}
|
|
427
|
+
const form = new FormData();
|
|
428
|
+
form.append("file", new Blob([buffer], { type: "application/pdf" }), "file.pdf");
|
|
429
|
+
form.append("ranges", JSON.stringify(ranges));
|
|
430
|
+
const headers = await this.authHeaders();
|
|
431
|
+
const response = await fetch(`${this.baseUrl}/operations/split`, {
|
|
432
|
+
method: "POST",
|
|
433
|
+
headers,
|
|
434
|
+
body: form
|
|
435
|
+
});
|
|
436
|
+
if (!response.ok) {
|
|
437
|
+
const envelope = await response.json();
|
|
438
|
+
const { code, message } = extractError(envelope);
|
|
439
|
+
throw new DocmanError(message, response.status, code);
|
|
440
|
+
}
|
|
441
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
442
|
+
if (contentType.includes("application/json")) {
|
|
443
|
+
const json = await response.json();
|
|
444
|
+
return json.data.map((part) => ({
|
|
445
|
+
index: part.index,
|
|
446
|
+
range: part.range,
|
|
447
|
+
buffer: Buffer.from(part.base64, "base64"),
|
|
448
|
+
sizeBytes: part.sizeBytes
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
const buf = Buffer.from(await response.arrayBuffer());
|
|
452
|
+
return [{ index: 0, range: ranges[0], buffer: buf, sizeBytes: buf.length }];
|
|
453
|
+
}
|
|
454
|
+
/** Get the page count of a PDF buffer. */
|
|
455
|
+
async pageCount(buffer) {
|
|
456
|
+
const form = new FormData();
|
|
457
|
+
form.append("file", new Blob([buffer], { type: "application/pdf" }), "file.pdf");
|
|
458
|
+
const headers = await this.authHeaders();
|
|
459
|
+
const response = await fetch(`${this.baseUrl}/operations/page-count`, {
|
|
460
|
+
method: "POST",
|
|
461
|
+
headers,
|
|
462
|
+
body: form
|
|
463
|
+
});
|
|
464
|
+
if (!response.ok) {
|
|
465
|
+
const envelope = await response.json();
|
|
466
|
+
const { code, message } = extractError(envelope);
|
|
467
|
+
throw new DocmanError(message, response.status, code);
|
|
468
|
+
}
|
|
469
|
+
const json = await response.json();
|
|
470
|
+
return json.data.pages;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
474
|
+
0 && (module.exports = {
|
|
475
|
+
DocmanClient,
|
|
476
|
+
DocmanError
|
|
477
|
+
});
|
|
478
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { DocmanClient } from './client.js'\nexport { DocmanError } from './errors.js'\nexport type {\n DocmanClientConfig,\n // HTML Templates\n HtmlTemplate,\n CreateHtmlTemplateOptions,\n UpdateHtmlTemplateOptions,\n HtmlTemplateListQuery,\n // PDF Templates\n PdfTemplate,\n PdfField,\n TemplateCoordinates,\n CreatePdfTemplateOptions,\n UpdatePdfTemplateOptions,\n PdfTemplateListQuery,\n // Template Groups\n TemplateGroup,\n TemplateGroupItem,\n CreateTemplateGroupOptions,\n UpdateTemplateGroupOptions,\n // Documents\n DocmanDocument,\n DocumentVersion,\n SourceTemplate,\n GenerateOptions,\n GenerateResult,\n // Lists\n ListQuery,\n ListMeta,\n ListResult,\n // Operations\n PageRange,\n SplitPart,\n} from './types.js'\n","export class DocmanError extends Error {\n constructor(\n message: string,\n public readonly statusCode: number,\n public readonly code?: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message)\n this.name = 'DocmanError'\n }\n}\n","import { DocmanError } from './errors.js'\nimport type {\n DocmanClientConfig,\n HtmlTemplate,\n CreateHtmlTemplateOptions,\n UpdateHtmlTemplateOptions,\n HtmlTemplateListQuery,\n PdfTemplate,\n PdfField,\n CreatePdfTemplateOptions,\n UpdatePdfTemplateOptions,\n PdfTemplateListQuery,\n TemplateGroup,\n CreateTemplateGroupOptions,\n UpdateTemplateGroupOptions,\n DocmanDocument,\n DocumentVersion,\n GenerateOptions,\n GenerateResult,\n ListQuery,\n ListResult,\n ListMeta,\n PageRange,\n SplitPart,\n} from './types.js'\n\n// ─── Internal ────────────────────────────────────────────\n\nconst DEFAULT_RETRIES = 2\nconst DEFAULT_TIMEOUT_MS = 15_000\nconst TOKEN_BUFFER_SECONDS = 30\n\ninterface ApiEnvelope<T> {\n readonly success: boolean\n readonly data?: T\n readonly error?: { code: string; message: string } | string\n readonly meta?: ListMeta\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nfunction backoff(attempt: number): number {\n const base = Math.min(1000 * 2 ** attempt, 5_000)\n return base * (0.5 + Math.random() * 0.5)\n}\n\nfunction isTokenExpired(token: string, bufferSeconds = TOKEN_BUFFER_SECONDS): boolean {\n try {\n const parts = token.split('.')\n if (parts.length !== 3) return true\n const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString()) as { exp?: number }\n const now = Math.floor(Date.now() / 1000)\n return (payload.exp ?? 0) <= now + bufferSeconds\n } catch {\n return true\n }\n}\n\nfunction extractError(envelope: ApiEnvelope<unknown>): { code: string; message: string } {\n const err = envelope.error\n if (typeof err === 'object' && err !== null) return err\n return { code: 'REQUEST_ERROR', message: err ?? 'Request failed' }\n}\n\n// ─── DocmanClient ─────────────────────────────────────────\n\nexport class DocmanClient {\n private readonly baseUrl: string\n private readonly accessTokenFn?: () => Promise<string>\n private readonly internalKey?: string\n private readonly retries: number\n private readonly timeoutMs: number\n private cachedToken: string | null = null\n\n constructor(config: DocmanClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '')\n this.accessTokenFn = config.accessTokenFn\n this.internalKey = config.internalKey\n this.retries = config.retries ?? DEFAULT_RETRIES\n this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS\n }\n\n /**\n * Create a client from environment variables.\n *\n * Reads DOCMAN_URL (injected automatically when you declare docman as an\n * internalDependency in catalog-info.yaml). Auth priority:\n * 1. BIO_CLIENT_ID + BIO_CLIENT_SECRET → client_credentials token\n * 2. INTERNAL_SERVICE_KEY → internal key header\n * 3. No auth → local dev / testing\n *\n * catalog-info.yaml:\n * spec:\n * internalDependencies:\n * - service: docman\n * port: 3000\n */\n static fromEnv(): DocmanClient {\n const baseUrl = process.env.DOCMAN_URL\n if (!baseUrl) {\n throw new DocmanError(\n 'DOCMAN_URL is not set. Add docman as an internalDependency in catalog-info.yaml',\n 500,\n 'CONFIG_ERROR',\n )\n }\n\n const clientId = process.env.BIO_CLIENT_ID\n const clientSecret = process.env.BIO_CLIENT_SECRET\n const bioIdUrl = process.env.BIO_ID_URL ?? 'https://bio.tawa.insureco.io'\n\n if (clientId && clientSecret) {\n return new DocmanClient({\n baseUrl,\n accessTokenFn: async () => {\n const res = await fetch(`${bioIdUrl}/api/oauth/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'client_credentials',\n client_id: clientId,\n client_secret: clientSecret,\n }),\n })\n if (!res.ok) {\n throw new DocmanError('Failed to obtain Bio-ID access token', res.status, 'AUTH_ERROR')\n }\n const data = await res.json() as { access_token: string }\n return data.access_token\n },\n })\n }\n\n const internalKey = process.env.INTERNAL_SERVICE_KEY\n if (internalKey) {\n return new DocmanClient({ baseUrl, internalKey })\n }\n\n return new DocmanClient({ baseUrl })\n }\n\n // ─── Auth ────────────────────────────────────────────────\n\n private async authHeaders(): Promise<Record<string, string>> {\n if (this.accessTokenFn) {\n if (!this.cachedToken || isTokenExpired(this.cachedToken)) {\n this.cachedToken = await this.accessTokenFn()\n }\n return { Authorization: `Bearer ${this.cachedToken}` }\n }\n\n if (this.internalKey) {\n return { 'X-Internal-Key': this.internalKey }\n }\n\n return {}\n }\n\n // ─── Core fetch ──────────────────────────────────────────\n\n private async rawFetch<T>(\n method: string,\n path: string,\n body?: unknown,\n attempt = 0,\n ): Promise<ApiEnvelope<T>> {\n const headers = await this.authHeaders()\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), this.timeoutMs)\n\n let response: Response\n try {\n response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: body !== undefined\n ? { ...headers, 'Content-Type': 'application/json' }\n : headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n })\n } catch (err) {\n clearTimeout(timer)\n if (attempt < this.retries) {\n await sleep(backoff(attempt))\n return this.rawFetch<T>(method, path, body, attempt + 1)\n }\n throw new DocmanError(`Network error: ${(err as Error).message}`, 0, 'NETWORK_ERROR')\n } finally {\n clearTimeout(timer)\n }\n\n if (response.status >= 500 && attempt < this.retries) {\n await sleep(backoff(attempt))\n return this.rawFetch<T>(method, path, body, attempt + 1)\n }\n\n const envelope = await response.json() as ApiEnvelope<T>\n\n if (!response.ok || !envelope.success) {\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n return envelope\n }\n\n private async fetchData<T>(method: string, path: string, body?: unknown): Promise<T> {\n const envelope = await this.rawFetch<T>(method, path, body)\n return envelope.data as T\n }\n\n private async fetchList<T>(path: string): Promise<ListResult<T>> {\n const envelope = await this.rawFetch<T[]>('GET', path)\n return {\n data: envelope.data ?? [],\n meta: envelope.meta ?? { total: 0, page: 1, limit: 20 },\n }\n }\n\n private buildQuery<T extends object>(params: T): string {\n const pairs = Object.entries(params)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)\n return pairs.length > 0 ? `?${pairs.join('&')}` : ''\n }\n\n /** Fetch with FormData body (multipart), return raw binary buffer. */\n private async fetchBinary(\n method: string,\n path: string,\n formData: FormData,\n attempt = 0,\n ): Promise<Buffer> {\n const headers = await this.authHeaders()\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), this.timeoutMs)\n\n let response: Response\n try {\n response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: formData,\n signal: controller.signal,\n })\n } catch (err) {\n clearTimeout(timer)\n if (attempt < this.retries) {\n await sleep(backoff(attempt))\n return this.fetchBinary(method, path, formData, attempt + 1)\n }\n throw new DocmanError(`Network error: ${(err as Error).message}`, 0, 'NETWORK_ERROR')\n } finally {\n clearTimeout(timer)\n }\n\n if (response.status >= 500 && attempt < this.retries) {\n await sleep(backoff(attempt))\n return this.fetchBinary(method, path, formData, attempt + 1)\n }\n\n if (!response.ok) {\n const envelope = await response.json() as ApiEnvelope<never>\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n return Buffer.from(await response.arrayBuffer())\n }\n\n /** POST multipart form and parse the JSON response envelope. */\n private async fetchMultipartJson<T>(path: string, formData: FormData): Promise<T> {\n const headers = await this.authHeaders()\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers,\n body: formData,\n })\n\n const envelope = await response.json() as ApiEnvelope<T>\n if (!response.ok || !envelope.success) {\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n return envelope.data as T\n }\n\n /** PUT multipart form and parse the JSON response envelope. */\n private async putMultipartJson<T>(path: string, formData: FormData): Promise<T> {\n const headers = await this.authHeaders()\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'PUT',\n headers,\n body: formData,\n })\n\n const envelope = await response.json() as ApiEnvelope<T>\n if (!response.ok || !envelope.success) {\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n return envelope.data as T\n }\n\n // ─── HTML Templates ──────────────────────────────────────\n\n async createHtmlTemplate(options: CreateHtmlTemplateOptions): Promise<HtmlTemplate> {\n return this.fetchData<HtmlTemplate>('POST', '/templates/html', options)\n }\n\n async listHtmlTemplates(query: HtmlTemplateListQuery = {}): Promise<ListResult<HtmlTemplate>> {\n return this.fetchList<HtmlTemplate>(`/templates/html${this.buildQuery(query)}`)\n }\n\n async getHtmlTemplate(id: string): Promise<HtmlTemplate> {\n return this.fetchData<HtmlTemplate>('GET', `/templates/html/${encodeURIComponent(id)}`)\n }\n\n async updateHtmlTemplate(id: string, options: UpdateHtmlTemplateOptions): Promise<HtmlTemplate> {\n return this.fetchData<HtmlTemplate>('PUT', `/templates/html/${encodeURIComponent(id)}`, options)\n }\n\n async deleteHtmlTemplate(id: string): Promise<HtmlTemplate> {\n return this.fetchData<HtmlTemplate>('DELETE', `/templates/html/${encodeURIComponent(id)}`)\n }\n\n // ─── PDF Templates ───────────────────────────────────────\n\n /**\n * Upload a PDF form template.\n * @param file Raw PDF bytes (Buffer or Uint8Array)\n * @param options Name, description, and optional coordinates/isSystem flags\n */\n async uploadPdfTemplate(\n file: Buffer | Uint8Array,\n options: CreatePdfTemplateOptions = {},\n ): Promise<PdfTemplate> {\n const form = new FormData()\n const filename = options.name ?? 'template.pdf'\n form.append('file', new Blob([file], { type: 'application/pdf' }), filename)\n if (options.name) form.append('name', options.name)\n if (options.description) form.append('description', options.description)\n if (options.coordinates) form.append('coordinates', JSON.stringify(options.coordinates))\n if (options.isSystem !== undefined) form.append('isSystem', String(options.isSystem))\n\n return this.fetchMultipartJson<PdfTemplate>('/templates/pdf', form)\n }\n\n async listPdfTemplates(query: PdfTemplateListQuery = {}): Promise<ListResult<PdfTemplate>> {\n return this.fetchList<PdfTemplate>(`/templates/pdf${this.buildQuery(query)}`)\n }\n\n async getPdfTemplate(id: string): Promise<PdfTemplate> {\n return this.fetchData<PdfTemplate>('GET', `/templates/pdf/${encodeURIComponent(id)}`)\n }\n\n async getPdfTemplateFields(id: string): Promise<readonly PdfField[]> {\n return this.fetchData<PdfField[]>('GET', `/templates/pdf/${encodeURIComponent(id)}/fields`)\n }\n\n async getPdfTemplateDownloadUrl(id: string): Promise<string> {\n const data = await this.fetchData<{ url: string }>('GET', `/templates/pdf/${encodeURIComponent(id)}/download`)\n return data.url\n }\n\n /**\n * Update a PDF template's metadata, and optionally replace the PDF file.\n * @param file If provided, replaces the stored PDF and re-extracts form fields\n */\n async updatePdfTemplate(\n id: string,\n options: UpdatePdfTemplateOptions,\n file?: Buffer | Uint8Array,\n ): Promise<PdfTemplate> {\n if (file) {\n const form = new FormData()\n form.append('file', new Blob([file], { type: 'application/pdf' }), 'template.pdf')\n if (options.name) form.append('name', options.name)\n if (options.description) form.append('description', options.description)\n if (options.coordinates) form.append('coordinates', JSON.stringify(options.coordinates))\n\n return this.putMultipartJson<PdfTemplate>(`/templates/pdf/${encodeURIComponent(id)}`, form)\n }\n\n return this.fetchData<PdfTemplate>('PUT', `/templates/pdf/${encodeURIComponent(id)}`, options)\n }\n\n async deletePdfTemplate(id: string): Promise<PdfTemplate> {\n return this.fetchData<PdfTemplate>('DELETE', `/templates/pdf/${encodeURIComponent(id)}`)\n }\n\n // ─── Template Groups ─────────────────────────────────────\n\n async createTemplateGroup(options: CreateTemplateGroupOptions): Promise<TemplateGroup> {\n return this.fetchData<TemplateGroup>('POST', '/template-groups', options)\n }\n\n async listTemplateGroups(query: ListQuery = {}): Promise<ListResult<TemplateGroup>> {\n return this.fetchList<TemplateGroup>(`/template-groups${this.buildQuery(query)}`)\n }\n\n async getTemplateGroup(id: string): Promise<TemplateGroup> {\n return this.fetchData<TemplateGroup>('GET', `/template-groups/${encodeURIComponent(id)}`)\n }\n\n async updateTemplateGroup(id: string, options: UpdateTemplateGroupOptions): Promise<TemplateGroup> {\n return this.fetchData<TemplateGroup>('PUT', `/template-groups/${encodeURIComponent(id)}`, options)\n }\n\n async deleteTemplateGroup(id: string): Promise<void> {\n await this.fetchData<{ deleted: boolean }>('DELETE', `/template-groups/${encodeURIComponent(id)}`)\n }\n\n // ─── Document Generation ─────────────────────────────────\n\n /**\n * Generate a document and store it in S3.\n * Returns a presigned download URL and a public share URL.\n */\n async generate(options: GenerateOptions): Promise<GenerateResult> {\n return this.fetchData<GenerateResult>('POST', '/documents/generate', {\n templateIds: options.templateIds,\n templateData: options.data,\n name: options.name,\n description: options.description,\n })\n }\n\n /**\n * Generate a document and stream the PDF buffer directly.\n * Nothing is stored — useful for previews or on-the-fly delivery.\n */\n async generatePassthrough(options: GenerateOptions): Promise<Buffer> {\n const headers = await this.authHeaders()\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), this.timeoutMs)\n\n let response: Response\n try {\n response = await fetch(`${this.baseUrl}/documents/generate/passthrough`, {\n method: 'POST',\n headers: { ...headers, 'Content-Type': 'application/json' },\n body: JSON.stringify({\n templateIds: options.templateIds,\n templateData: options.data,\n name: options.name,\n description: options.description,\n }),\n signal: controller.signal,\n })\n } catch (err) {\n clearTimeout(timer)\n throw new DocmanError(`Network error: ${(err as Error).message}`, 0, 'NETWORK_ERROR')\n } finally {\n clearTimeout(timer)\n }\n\n if (!response.ok) {\n const envelope = await response.json() as ApiEnvelope<never>\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n return Buffer.from(await response.arrayBuffer())\n }\n\n async listDocuments(query: ListQuery = {}): Promise<ListResult<DocmanDocument>> {\n return this.fetchList<DocmanDocument>(`/documents${this.buildQuery(query)}`)\n }\n\n async getDocument(id: string): Promise<DocmanDocument> {\n return this.fetchData<DocmanDocument>('GET', `/documents/${encodeURIComponent(id)}`)\n }\n\n /** Get a presigned S3 download URL for a stored document (1-hour TTL). */\n async downloadUrl(id: string): Promise<string> {\n const data = await this.fetchData<{ url: string }>('GET', `/documents/${encodeURIComponent(id)}/download`)\n return data.url\n }\n\n async getVersions(id: string): Promise<readonly DocumentVersion[]> {\n return this.fetchData<DocumentVersion[]>('GET', `/documents/${encodeURIComponent(id)}/versions`)\n }\n\n /** Re-render a stored document using the original template data. */\n async regenerate(id: string): Promise<GenerateResult> {\n return this.fetchData<GenerateResult>('POST', `/documents/${encodeURIComponent(id)}/regenerate`)\n }\n\n // ─── PDF Operations ──────────────────────────────────────\n\n /**\n * Merge two or more PDF buffers into a single PDF.\n * Returns the merged PDF as a Buffer.\n */\n async merge(buffers: readonly (Buffer | Uint8Array)[]): Promise<Buffer> {\n if (buffers.length < 2) {\n throw new DocmanError('At least 2 PDF buffers are required for merge', 400, 'VALIDATION_ERROR')\n }\n const form = new FormData()\n for (const buf of buffers) {\n form.append('files', new Blob([buf], { type: 'application/pdf' }), 'file.pdf')\n }\n return this.fetchBinary('POST', '/operations/merge', form)\n }\n\n /**\n * Split a PDF into parts by page ranges.\n * Returns an array of SplitPart with buffer, range, and size info.\n */\n async split(buffer: Buffer | Uint8Array, ranges: readonly PageRange[]): Promise<readonly SplitPart[]> {\n if (ranges.length === 0) {\n throw new DocmanError('At least 1 page range is required', 400, 'VALIDATION_ERROR')\n }\n\n const form = new FormData()\n form.append('file', new Blob([buffer], { type: 'application/pdf' }), 'file.pdf')\n form.append('ranges', JSON.stringify(ranges))\n\n const headers = await this.authHeaders()\n const response = await fetch(`${this.baseUrl}/operations/split`, {\n method: 'POST',\n headers,\n body: form,\n })\n\n if (!response.ok) {\n const envelope = await response.json() as ApiEnvelope<never>\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n const contentType = response.headers.get('content-type') ?? ''\n\n if (contentType.includes('application/json')) {\n type SplitResponse = {\n success: true\n data: Array<{ index: number; range: PageRange; base64: string; sizeBytes: number }>\n }\n const json = await response.json() as SplitResponse\n return json.data.map((part) => ({\n index: part.index,\n range: part.range,\n buffer: Buffer.from(part.base64, 'base64'),\n sizeBytes: part.sizeBytes,\n }))\n }\n\n // Single range — binary response\n const buf = Buffer.from(await response.arrayBuffer())\n return [{ index: 0, range: ranges[0], buffer: buf, sizeBytes: buf.length }]\n }\n\n /** Get the page count of a PDF buffer. */\n async pageCount(buffer: Buffer | Uint8Array): Promise<number> {\n const form = new FormData()\n form.append('file', new Blob([buffer], { type: 'application/pdf' }), 'file.pdf')\n\n const headers = await this.authHeaders()\n const response = await fetch(`${this.baseUrl}/operations/page-count`, {\n method: 'POST',\n headers,\n body: form,\n })\n\n if (!response.ok) {\n const envelope = await response.json() as ApiEnvelope<never>\n const { code, message } = extractError(envelope)\n throw new DocmanError(message, response.status, code)\n }\n\n const json = await response.json() as { success: true; data: { pages: number } }\n return json.data.pages\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAN,cAA0B,MAAM;AAAA,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