@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/mock.js ADDED
@@ -0,0 +1,305 @@
1
+ import {
2
+ DocmanError
3
+ } from "./chunk-7DJVMOS3.js";
4
+
5
+ // src/mock.ts
6
+ import { randomUUID } from "crypto";
7
+ function now() {
8
+ return (/* @__PURE__ */ new Date()).toISOString();
9
+ }
10
+ function paginate(items, query) {
11
+ const page = query.page ?? 1;
12
+ const limit = query.limit ?? 20;
13
+ const start = (page - 1) * limit;
14
+ return {
15
+ data: items.slice(start, start + limit),
16
+ meta: { total: items.length, page, limit }
17
+ };
18
+ }
19
+ function findOrThrow(map, id, label) {
20
+ const item = map.get(id);
21
+ if (!item) throw new DocmanError(`${label} not found`, 404, "NOT_FOUND");
22
+ return item;
23
+ }
24
+ var MockDocmanClient = class {
25
+ htmlTemplates = /* @__PURE__ */ new Map();
26
+ pdfTemplates = /* @__PURE__ */ new Map();
27
+ templateGroups = /* @__PURE__ */ new Map();
28
+ documents = /* @__PURE__ */ new Map();
29
+ documentVersions = /* @__PURE__ */ new Map();
30
+ /** Reset all in-memory state between tests. */
31
+ reset() {
32
+ this.htmlTemplates.clear();
33
+ this.pdfTemplates.clear();
34
+ this.templateGroups.clear();
35
+ this.documents.clear();
36
+ this.documentVersions.clear();
37
+ }
38
+ // ─── HTML Templates ────────────────────────────────────
39
+ async createHtmlTemplate(options) {
40
+ const template = {
41
+ _id: randomUUID(),
42
+ name: options.name,
43
+ description: options.description,
44
+ org: "mock-org",
45
+ html: options.html,
46
+ landscape: options.landscape ?? false,
47
+ variables: [],
48
+ isSystem: options.isSystem ?? false,
49
+ archived: false,
50
+ createdBy: "mock-user",
51
+ createdAt: now(),
52
+ updatedAt: now()
53
+ };
54
+ this.htmlTemplates.set(template._id, template);
55
+ return template;
56
+ }
57
+ async listHtmlTemplates(query = {}) {
58
+ const archived = query.archived ?? false;
59
+ const items = [...this.htmlTemplates.values()].filter((t) => t.archived === archived);
60
+ return paginate(items, query);
61
+ }
62
+ async getHtmlTemplate(id) {
63
+ return findOrThrow(this.htmlTemplates, id, "HTML template");
64
+ }
65
+ async updateHtmlTemplate(id, options) {
66
+ const existing = findOrThrow(this.htmlTemplates, id, "HTML template");
67
+ const updated = {
68
+ ...existing,
69
+ ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0)),
70
+ updatedAt: now()
71
+ };
72
+ this.htmlTemplates.set(id, updated);
73
+ return updated;
74
+ }
75
+ async deleteHtmlTemplate(id) {
76
+ const existing = findOrThrow(this.htmlTemplates, id, "HTML template");
77
+ const archived = { ...existing, archived: true, updatedAt: now() };
78
+ this.htmlTemplates.set(id, archived);
79
+ return archived;
80
+ }
81
+ // ─── PDF Templates ────────────────────────────────────
82
+ async uploadPdfTemplate(_file, options = {}) {
83
+ const template = {
84
+ _id: randomUUID(),
85
+ name: options.name ?? "mock-template.pdf",
86
+ description: options.description,
87
+ org: "mock-org",
88
+ storageKey: `mock/templates/${randomUUID()}.pdf`,
89
+ fields: [],
90
+ pages: 1,
91
+ coordinates: options.coordinates,
92
+ isSystem: options.isSystem ?? false,
93
+ archived: false,
94
+ createdBy: "mock-user",
95
+ createdAt: now(),
96
+ updatedAt: now()
97
+ };
98
+ this.pdfTemplates.set(template._id, template);
99
+ return template;
100
+ }
101
+ async listPdfTemplates(query = {}) {
102
+ const archived = query.archived ?? false;
103
+ const items = [...this.pdfTemplates.values()].filter((t) => t.archived === archived);
104
+ return paginate(items, query);
105
+ }
106
+ async getPdfTemplate(id) {
107
+ return findOrThrow(this.pdfTemplates, id, "PDF template");
108
+ }
109
+ async getPdfTemplateFields(id) {
110
+ const template = findOrThrow(this.pdfTemplates, id, "PDF template");
111
+ return template.fields;
112
+ }
113
+ async getPdfTemplateDownloadUrl(id) {
114
+ findOrThrow(this.pdfTemplates, id, "PDF template");
115
+ return `https://mock-s3.example.com/templates/${id}.pdf?token=mock`;
116
+ }
117
+ async updatePdfTemplate(id, options, _file) {
118
+ const existing = findOrThrow(this.pdfTemplates, id, "PDF template");
119
+ const updated = {
120
+ ...existing,
121
+ ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0)),
122
+ updatedAt: now()
123
+ };
124
+ this.pdfTemplates.set(id, updated);
125
+ return updated;
126
+ }
127
+ async deletePdfTemplate(id) {
128
+ const existing = findOrThrow(this.pdfTemplates, id, "PDF template");
129
+ const archived = { ...existing, archived: true, updatedAt: now() };
130
+ this.pdfTemplates.set(id, archived);
131
+ return archived;
132
+ }
133
+ // ─── Template Groups ──────────────────────────────────
134
+ async createTemplateGroup(options) {
135
+ const group = {
136
+ _id: randomUUID(),
137
+ name: options.name,
138
+ org: "mock-org",
139
+ templates: options.templates,
140
+ terms: options.terms,
141
+ coordinates: options.coordinates,
142
+ createdBy: "mock-user",
143
+ createdAt: now(),
144
+ updatedAt: now()
145
+ };
146
+ this.templateGroups.set(group._id, group);
147
+ return group;
148
+ }
149
+ async listTemplateGroups(query = {}) {
150
+ const items = [...this.templateGroups.values()];
151
+ return paginate(items, query);
152
+ }
153
+ async getTemplateGroup(id) {
154
+ return findOrThrow(this.templateGroups, id, "Template group");
155
+ }
156
+ async updateTemplateGroup(id, options) {
157
+ const existing = findOrThrow(this.templateGroups, id, "Template group");
158
+ const updated = {
159
+ ...existing,
160
+ ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0)),
161
+ updatedAt: now()
162
+ };
163
+ this.templateGroups.set(id, updated);
164
+ return updated;
165
+ }
166
+ async deleteTemplateGroup(id) {
167
+ if (!this.templateGroups.has(id)) {
168
+ throw new DocmanError("Template group not found", 404, "NOT_FOUND");
169
+ }
170
+ this.templateGroups.delete(id);
171
+ }
172
+ // ─── Documents ────────────────────────────────────────
173
+ async generate(options) {
174
+ const docId = randomUUID();
175
+ const shareToken = randomUUID().replace(/-/g, "");
176
+ const doc = {
177
+ _id: docId,
178
+ name: options.name,
179
+ description: options.description,
180
+ org: "mock-org",
181
+ storageKey: `mock/documents/${docId}/v1.pdf`,
182
+ version: 1,
183
+ sourceTemplates: options.templateIds.map((id) => ({ templateId: id, templateType: "html" })),
184
+ templateData: options.data,
185
+ pages: 1,
186
+ sizeBytes: 1024,
187
+ deliveryMode: "managed",
188
+ shareToken,
189
+ createdBy: "mock-user",
190
+ createdAt: now(),
191
+ updatedAt: now()
192
+ };
193
+ this.documents.set(docId, doc);
194
+ this.documentVersions.set(docId, [{
195
+ _id: docId,
196
+ version: 1,
197
+ pages: 1,
198
+ sizeBytes: 1024,
199
+ createdAt: doc.createdAt,
200
+ createdBy: "mock-user"
201
+ }]);
202
+ return {
203
+ documentId: docId,
204
+ version: 1,
205
+ downloadUrl: `https://mock-s3.example.com/documents/${docId}/v1.pdf?token=mock`,
206
+ publicUrl: `http://localhost:3000/d/${shareToken}`,
207
+ pages: 1,
208
+ sizeBytes: 1024
209
+ };
210
+ }
211
+ async generatePassthrough(_options) {
212
+ return Buffer.from("%PDF-1.4 mock", "utf8");
213
+ }
214
+ async listDocuments(query = {}) {
215
+ const items = [...this.documents.values()].sort(
216
+ (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
217
+ );
218
+ return paginate(items, query);
219
+ }
220
+ async getDocument(id) {
221
+ return findOrThrow(this.documents, id, "Document");
222
+ }
223
+ async downloadUrl(id) {
224
+ findOrThrow(this.documents, id, "Document");
225
+ return `https://mock-s3.example.com/documents/${id}/v1.pdf?token=mock`;
226
+ }
227
+ async getVersions(id) {
228
+ findOrThrow(this.documents, id, "Document");
229
+ return this.documentVersions.get(id) ?? [];
230
+ }
231
+ async regenerate(id) {
232
+ const original = findOrThrow(this.documents, id, "Document");
233
+ const newVersion = original.version + 1;
234
+ const newDocId = randomUUID();
235
+ const shareToken = randomUUID().replace(/-/g, "");
236
+ const newDoc = {
237
+ ...original,
238
+ _id: newDocId,
239
+ version: newVersion,
240
+ shareToken,
241
+ storageKey: `mock/documents/${newDocId}/v${newVersion}.pdf`,
242
+ createdAt: now(),
243
+ updatedAt: now()
244
+ };
245
+ this.documents.set(newDocId, newDoc);
246
+ const versions = this.documentVersions.get(id) ?? [];
247
+ this.documentVersions.set(newDocId, [
248
+ ...versions,
249
+ {
250
+ _id: newDocId,
251
+ version: newVersion,
252
+ pages: original.pages,
253
+ sizeBytes: original.sizeBytes,
254
+ createdAt: newDoc.createdAt,
255
+ createdBy: "mock-user"
256
+ }
257
+ ]);
258
+ return {
259
+ documentId: newDocId,
260
+ version: newVersion,
261
+ downloadUrl: `https://mock-s3.example.com/documents/${newDocId}/v${newVersion}.pdf?token=mock`,
262
+ publicUrl: `http://localhost:3000/d/${shareToken}`,
263
+ pages: original.pages,
264
+ sizeBytes: original.sizeBytes
265
+ };
266
+ }
267
+ // ─── Operations ──────────────────────────────────────
268
+ async merge(buffers) {
269
+ if (buffers.length < 2) {
270
+ throw new DocmanError("At least 2 PDF buffers are required for merge", 400, "VALIDATION_ERROR");
271
+ }
272
+ return Buffer.from("%PDF-1.4 mock-merged", "utf8");
273
+ }
274
+ async split(_buffer, ranges) {
275
+ if (ranges.length === 0) {
276
+ throw new DocmanError("At least 1 page range is required", 400, "VALIDATION_ERROR");
277
+ }
278
+ return ranges.map((range, index) => ({
279
+ index,
280
+ range,
281
+ buffer: Buffer.from(`%PDF-1.4 mock-part-${index}`, "utf8"),
282
+ sizeBytes: 20
283
+ }));
284
+ }
285
+ async pageCount(_buffer) {
286
+ return 1;
287
+ }
288
+ // ─── Test Helpers ────────────────────────────────────
289
+ /** Read all stored documents (for test assertions). */
290
+ getDocuments() {
291
+ return this.documents;
292
+ }
293
+ /** Read all stored HTML templates (for test assertions). */
294
+ getHtmlTemplates() {
295
+ return this.htmlTemplates;
296
+ }
297
+ /** Read all stored PDF templates (for test assertions). */
298
+ getPdfTemplates() {
299
+ return this.pdfTemplates;
300
+ }
301
+ };
302
+ export {
303
+ MockDocmanClient
304
+ };
305
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mock.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\nimport { DocmanError } from './errors.js'\nimport type {\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 PageRange,\n SplitPart,\n} from './types.js'\n\n// ─── Helpers ──────────────────────────────────────────────\n\nfunction now(): string {\n return new Date().toISOString()\n}\n\nfunction paginate<T>(items: readonly T[], query: ListQuery): ListResult<T> {\n const page = query.page ?? 1\n const limit = query.limit ?? 20\n const start = (page - 1) * limit\n return {\n data: items.slice(start, start + limit),\n meta: { total: items.length, page, limit },\n }\n}\n\nfunction findOrThrow<T extends { _id: string }>(\n map: Map<string, T>,\n id: string,\n label: string,\n): T {\n const item = map.get(id)\n if (!item) throw new DocmanError(`${label} not found`, 404, 'NOT_FOUND')\n return item\n}\n\n// ─── MockDocmanClient ────────────────────────────────────\n\n/**\n * In-memory implementation of DocmanClient for use in tests.\n *\n * Import from @insureco/docman/testing:\n * import { MockDocmanClient } from '@insureco/docman/testing'\n *\n * @example\n * const docman = new MockDocmanClient()\n * const template = await docman.createHtmlTemplate({ name: 'Quote', html: '<p>{{name}}</p>' })\n * const result = await docman.generate({ templateIds: [template._id], data: { name: 'Acme' }, name: 'test' })\n * expect(result.pages).toBe(1)\n */\nexport class MockDocmanClient {\n private readonly htmlTemplates = new Map<string, HtmlTemplate>()\n private readonly pdfTemplates = new Map<string, PdfTemplate>()\n private readonly templateGroups = new Map<string, TemplateGroup>()\n private readonly documents = new Map<string, DocmanDocument>()\n private readonly documentVersions = new Map<string, DocumentVersion[]>()\n\n /** Reset all in-memory state between tests. */\n reset(): void {\n this.htmlTemplates.clear()\n this.pdfTemplates.clear()\n this.templateGroups.clear()\n this.documents.clear()\n this.documentVersions.clear()\n }\n\n // ─── HTML Templates ────────────────────────────────────\n\n async createHtmlTemplate(options: CreateHtmlTemplateOptions): Promise<HtmlTemplate> {\n const template: HtmlTemplate = {\n _id: randomUUID(),\n name: options.name,\n description: options.description,\n org: 'mock-org',\n html: options.html,\n landscape: options.landscape ?? false,\n variables: [],\n isSystem: options.isSystem ?? false,\n archived: false,\n createdBy: 'mock-user',\n createdAt: now(),\n updatedAt: now(),\n }\n this.htmlTemplates.set(template._id, template)\n return template\n }\n\n async listHtmlTemplates(query: HtmlTemplateListQuery = {}): Promise<ListResult<HtmlTemplate>> {\n const archived = query.archived ?? false\n const items = [...this.htmlTemplates.values()].filter((t) => t.archived === archived)\n return paginate(items, query)\n }\n\n async getHtmlTemplate(id: string): Promise<HtmlTemplate> {\n return findOrThrow(this.htmlTemplates, id, 'HTML template')\n }\n\n async updateHtmlTemplate(id: string, options: UpdateHtmlTemplateOptions): Promise<HtmlTemplate> {\n const existing = findOrThrow(this.htmlTemplates, id, 'HTML template')\n const updated: HtmlTemplate = {\n ...existing,\n ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined)),\n updatedAt: now(),\n }\n this.htmlTemplates.set(id, updated)\n return updated\n }\n\n async deleteHtmlTemplate(id: string): Promise<HtmlTemplate> {\n const existing = findOrThrow(this.htmlTemplates, id, 'HTML template')\n const archived: HtmlTemplate = { ...existing, archived: true, updatedAt: now() }\n this.htmlTemplates.set(id, archived)\n return archived\n }\n\n // ─── PDF Templates ────────────────────────────────────\n\n async uploadPdfTemplate(\n _file: Buffer | Uint8Array,\n options: CreatePdfTemplateOptions = {},\n ): Promise<PdfTemplate> {\n const template: PdfTemplate = {\n _id: randomUUID(),\n name: options.name ?? 'mock-template.pdf',\n description: options.description,\n org: 'mock-org',\n storageKey: `mock/templates/${randomUUID()}.pdf`,\n fields: [],\n pages: 1,\n coordinates: options.coordinates,\n isSystem: options.isSystem ?? false,\n archived: false,\n createdBy: 'mock-user',\n createdAt: now(),\n updatedAt: now(),\n }\n this.pdfTemplates.set(template._id, template)\n return template\n }\n\n async listPdfTemplates(query: PdfTemplateListQuery = {}): Promise<ListResult<PdfTemplate>> {\n const archived = query.archived ?? false\n const items = [...this.pdfTemplates.values()].filter((t) => t.archived === archived)\n return paginate(items, query)\n }\n\n async getPdfTemplate(id: string): Promise<PdfTemplate> {\n return findOrThrow(this.pdfTemplates, id, 'PDF template')\n }\n\n async getPdfTemplateFields(id: string): Promise<readonly PdfField[]> {\n const template = findOrThrow(this.pdfTemplates, id, 'PDF template')\n return template.fields\n }\n\n async getPdfTemplateDownloadUrl(id: string): Promise<string> {\n findOrThrow(this.pdfTemplates, id, 'PDF template')\n return `https://mock-s3.example.com/templates/${id}.pdf?token=mock`\n }\n\n async updatePdfTemplate(\n id: string,\n options: UpdatePdfTemplateOptions,\n _file?: Buffer | Uint8Array,\n ): Promise<PdfTemplate> {\n const existing = findOrThrow(this.pdfTemplates, id, 'PDF template')\n const updated: PdfTemplate = {\n ...existing,\n ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined)),\n updatedAt: now(),\n }\n this.pdfTemplates.set(id, updated)\n return updated\n }\n\n async deletePdfTemplate(id: string): Promise<PdfTemplate> {\n const existing = findOrThrow(this.pdfTemplates, id, 'PDF template')\n const archived: PdfTemplate = { ...existing, archived: true, updatedAt: now() }\n this.pdfTemplates.set(id, archived)\n return archived\n }\n\n // ─── Template Groups ──────────────────────────────────\n\n async createTemplateGroup(options: CreateTemplateGroupOptions): Promise<TemplateGroup> {\n const group: TemplateGroup = {\n _id: randomUUID(),\n name: options.name,\n org: 'mock-org',\n templates: options.templates,\n terms: options.terms,\n coordinates: options.coordinates,\n createdBy: 'mock-user',\n createdAt: now(),\n updatedAt: now(),\n }\n this.templateGroups.set(group._id, group)\n return group\n }\n\n async listTemplateGroups(query: ListQuery = {}): Promise<ListResult<TemplateGroup>> {\n const items = [...this.templateGroups.values()]\n return paginate(items, query)\n }\n\n async getTemplateGroup(id: string): Promise<TemplateGroup> {\n return findOrThrow(this.templateGroups, id, 'Template group')\n }\n\n async updateTemplateGroup(id: string, options: UpdateTemplateGroupOptions): Promise<TemplateGroup> {\n const existing = findOrThrow(this.templateGroups, id, 'Template group')\n const updated: TemplateGroup = {\n ...existing,\n ...Object.fromEntries(Object.entries(options).filter(([, v]) => v !== undefined)),\n updatedAt: now(),\n }\n this.templateGroups.set(id, updated)\n return updated\n }\n\n async deleteTemplateGroup(id: string): Promise<void> {\n if (!this.templateGroups.has(id)) {\n throw new DocmanError('Template group not found', 404, 'NOT_FOUND')\n }\n this.templateGroups.delete(id)\n }\n\n // ─── Documents ────────────────────────────────────────\n\n async generate(options: GenerateOptions): Promise<GenerateResult> {\n const docId = randomUUID()\n const shareToken = randomUUID().replace(/-/g, '')\n\n const doc: DocmanDocument = {\n _id: docId,\n name: options.name,\n description: options.description,\n org: 'mock-org',\n storageKey: `mock/documents/${docId}/v1.pdf`,\n version: 1,\n sourceTemplates: options.templateIds.map((id) => ({ templateId: id, templateType: 'html' })),\n templateData: options.data,\n pages: 1,\n sizeBytes: 1024,\n deliveryMode: 'managed',\n shareToken,\n createdBy: 'mock-user',\n createdAt: now(),\n updatedAt: now(),\n }\n\n this.documents.set(docId, doc)\n this.documentVersions.set(docId, [{\n _id: docId,\n version: 1,\n pages: 1,\n sizeBytes: 1024,\n createdAt: doc.createdAt,\n createdBy: 'mock-user',\n }])\n\n return {\n documentId: docId,\n version: 1,\n downloadUrl: `https://mock-s3.example.com/documents/${docId}/v1.pdf?token=mock`,\n publicUrl: `http://localhost:3000/d/${shareToken}`,\n pages: 1,\n sizeBytes: 1024,\n }\n }\n\n async generatePassthrough(_options: GenerateOptions): Promise<Buffer> {\n return Buffer.from('%PDF-1.4 mock', 'utf8')\n }\n\n async listDocuments(query: ListQuery = {}): Promise<ListResult<DocmanDocument>> {\n const items = [...this.documents.values()].sort(\n (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),\n )\n return paginate(items, query)\n }\n\n async getDocument(id: string): Promise<DocmanDocument> {\n return findOrThrow(this.documents, id, 'Document')\n }\n\n async downloadUrl(id: string): Promise<string> {\n findOrThrow(this.documents, id, 'Document')\n return `https://mock-s3.example.com/documents/${id}/v1.pdf?token=mock`\n }\n\n async getVersions(id: string): Promise<readonly DocumentVersion[]> {\n findOrThrow(this.documents, id, 'Document')\n return this.documentVersions.get(id) ?? []\n }\n\n async regenerate(id: string): Promise<GenerateResult> {\n const original = findOrThrow(this.documents, id, 'Document')\n const newVersion = original.version + 1\n const newDocId = randomUUID()\n const shareToken = randomUUID().replace(/-/g, '')\n\n const newDoc: DocmanDocument = {\n ...original,\n _id: newDocId,\n version: newVersion,\n shareToken,\n storageKey: `mock/documents/${newDocId}/v${newVersion}.pdf`,\n createdAt: now(),\n updatedAt: now(),\n }\n\n this.documents.set(newDocId, newDoc)\n\n const versions = this.documentVersions.get(id) ?? []\n this.documentVersions.set(newDocId, [\n ...versions,\n {\n _id: newDocId,\n version: newVersion,\n pages: original.pages,\n sizeBytes: original.sizeBytes,\n createdAt: newDoc.createdAt,\n createdBy: 'mock-user',\n },\n ])\n\n return {\n documentId: newDocId,\n version: newVersion,\n downloadUrl: `https://mock-s3.example.com/documents/${newDocId}/v${newVersion}.pdf?token=mock`,\n publicUrl: `http://localhost:3000/d/${shareToken}`,\n pages: original.pages,\n sizeBytes: original.sizeBytes,\n }\n }\n\n // ─── Operations ──────────────────────────────────────\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 return Buffer.from('%PDF-1.4 mock-merged', 'utf8')\n }\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 return ranges.map((range, index) => ({\n index,\n range,\n buffer: Buffer.from(`%PDF-1.4 mock-part-${index}`, 'utf8'),\n sizeBytes: 20,\n }))\n }\n\n async pageCount(_buffer: Buffer | Uint8Array): Promise<number> {\n return 1\n }\n\n // ─── Test Helpers ────────────────────────────────────\n\n /** Read all stored documents (for test assertions). */\n getDocuments(): ReadonlyMap<string, DocmanDocument> {\n return this.documents\n }\n\n /** Read all stored HTML templates (for test assertions). */\n getHtmlTemplates(): ReadonlyMap<string, HtmlTemplate> {\n return this.htmlTemplates\n }\n\n /** Read all stored PDF templates (for test assertions). */\n getPdfTemplates(): ReadonlyMap<string, PdfTemplate> {\n return this.pdfTemplates\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AA2B3B,SAAS,MAAc;AACrB,UAAO,oBAAI,KAAK,GAAE,YAAY;AAChC;AAEA,SAAS,SAAY,OAAqB,OAAiC;AACzE,QAAM,OAAO,MAAM,QAAQ;AAC3B,QAAM,QAAQ,MAAM,SAAS;AAC7B,QAAM,SAAS,OAAO,KAAK;AAC3B,SAAO;AAAA,IACL,MAAM,MAAM,MAAM,OAAO,QAAQ,KAAK;AAAA,IACtC,MAAM,EAAE,OAAO,MAAM,QAAQ,MAAM,MAAM;AAAA,EAC3C;AACF;AAEA,SAAS,YACP,KACA,IACA,OACG;AACH,QAAM,OAAO,IAAI,IAAI,EAAE;AACvB,MAAI,CAAC,KAAM,OAAM,IAAI,YAAY,GAAG,KAAK,cAAc,KAAK,WAAW;AACvE,SAAO;AACT;AAgBO,IAAM,mBAAN,MAAuB;AAAA,EACX,gBAAgB,oBAAI,IAA0B;AAAA,EAC9C,eAAe,oBAAI,IAAyB;AAAA,EAC5C,iBAAiB,oBAAI,IAA2B;AAAA,EAChD,YAAY,oBAAI,IAA4B;AAAA,EAC5C,mBAAmB,oBAAI,IAA+B;AAAA;AAAA,EAGvE,QAAc;AACZ,SAAK,cAAc,MAAM;AACzB,SAAK,aAAa,MAAM;AACxB,SAAK,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AAW,SAAS;AAAA,QACpB,WAAW,OAAO;AAAA,QAClB,WAAW;AAAA,MACb;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,SAAS;AAAA,MACT,aAAa,yCAAyC,QAAQ,KAAK,UAAU;AAAA,MAC7E,WAAW,2BAA2B,UAAU;AAAA,MAChD,OAAO,SAAS;AAAA,MAChB,WAAW,SAAS;AAAA,IACtB;AAAA,EACF;AAAA;AAAA,EAIA,MAAM,MAAM,SAA4D;AACtE,QAAI,QAAQ,SAAS,GAAG;AACtB,YAAM,IAAI,YAAY,iDAAiD,KAAK,kBAAkB;AAAA,IAChG;AACA,WAAO,OAAO,KAAK,wBAAwB,MAAM;AAAA,EACnD;AAAA,EAEA,MAAM,MAAM,SAA8B,QAA6D;AACrG,QAAI,OAAO,WAAW,GAAG;AACvB,YAAM,IAAI,YAAY,qCAAqC,KAAK,kBAAkB;AAAA,IACpF;AACA,WAAO,OAAO,IAAI,CAAC,OAAO,WAAW;AAAA,MACnC;AAAA,MACA;AAAA,MACA,QAAQ,OAAO,KAAK,sBAAsB,KAAK,IAAI,MAAM;AAAA,MACzD,WAAW;AAAA,IACb,EAAE;AAAA,EACJ;AAAA,EAEA,MAAM,UAAU,SAA+C;AAC7D,WAAO;AAAA,EACT;AAAA;AAAA;AAAA,EAKA,eAAoD;AAClD,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,mBAAsD;AACpD,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,kBAAoD;AAClD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,185 @@
1
+ interface DocmanClientConfig {
2
+ /** Base URL of the docman service (e.g. from DOCMAN_URL env var) */
3
+ readonly baseUrl: string;
4
+ /** Async function that returns a valid Bearer token (Bio-ID client_credentials) */
5
+ readonly accessTokenFn?: () => Promise<string>;
6
+ /** Internal service key for service-to-service auth */
7
+ readonly internalKey?: string;
8
+ /** Max retry attempts on network/5xx errors (default: 2) */
9
+ readonly retries?: number;
10
+ /** Request timeout in milliseconds (default: 15000) */
11
+ readonly timeoutMs?: number;
12
+ }
13
+ interface HtmlTemplate {
14
+ readonly _id: string;
15
+ readonly name: string;
16
+ readonly description?: string;
17
+ readonly org: string;
18
+ readonly html: string;
19
+ readonly landscape: boolean;
20
+ readonly variables: readonly string[];
21
+ readonly isSystem: boolean;
22
+ readonly archived: boolean;
23
+ readonly createdBy: string;
24
+ readonly updatedBy?: string;
25
+ readonly createdAt: string;
26
+ readonly updatedAt: string;
27
+ }
28
+ interface CreateHtmlTemplateOptions {
29
+ readonly name: string;
30
+ readonly description?: string;
31
+ readonly html: string;
32
+ readonly landscape?: boolean;
33
+ readonly isSystem?: boolean;
34
+ }
35
+ interface UpdateHtmlTemplateOptions {
36
+ readonly name?: string;
37
+ readonly description?: string;
38
+ readonly html?: string;
39
+ readonly landscape?: boolean;
40
+ readonly isSystem?: boolean;
41
+ }
42
+ interface HtmlTemplateListQuery extends ListQuery {
43
+ readonly archived?: boolean;
44
+ }
45
+ interface PdfField {
46
+ readonly name: string;
47
+ readonly type: string;
48
+ readonly required: boolean;
49
+ }
50
+ interface TemplateCoordinates {
51
+ readonly customer?: string;
52
+ readonly agent?: string;
53
+ }
54
+ interface PdfTemplate {
55
+ readonly _id: string;
56
+ readonly name: string;
57
+ readonly description?: string;
58
+ readonly org: string;
59
+ readonly storageKey: string;
60
+ readonly fields: readonly PdfField[];
61
+ readonly pages: number;
62
+ readonly coordinates?: TemplateCoordinates;
63
+ readonly isSystem: boolean;
64
+ readonly archived: boolean;
65
+ readonly createdBy: string;
66
+ readonly updatedBy?: string;
67
+ readonly createdAt: string;
68
+ readonly updatedAt: string;
69
+ }
70
+ interface CreatePdfTemplateOptions {
71
+ readonly name?: string;
72
+ readonly description?: string;
73
+ readonly coordinates?: TemplateCoordinates;
74
+ readonly isSystem?: boolean;
75
+ }
76
+ interface UpdatePdfTemplateOptions {
77
+ readonly name?: string;
78
+ readonly description?: string;
79
+ readonly coordinates?: TemplateCoordinates;
80
+ readonly isSystem?: boolean;
81
+ }
82
+ interface PdfTemplateListQuery extends ListQuery {
83
+ readonly archived?: boolean;
84
+ }
85
+ interface TemplateGroupItem {
86
+ readonly templateId: string;
87
+ readonly templateType: 'pdf' | 'html';
88
+ }
89
+ interface TemplateGroup {
90
+ readonly _id: string;
91
+ readonly name: string;
92
+ readonly org: string;
93
+ readonly templates: readonly TemplateGroupItem[];
94
+ readonly terms?: string;
95
+ readonly coordinates?: TemplateCoordinates;
96
+ readonly createdBy: string;
97
+ readonly updatedBy?: string;
98
+ readonly createdAt: string;
99
+ readonly updatedAt: string;
100
+ }
101
+ interface CreateTemplateGroupOptions {
102
+ readonly name: string;
103
+ readonly templates: readonly TemplateGroupItem[];
104
+ readonly terms?: string;
105
+ readonly coordinates?: TemplateCoordinates;
106
+ }
107
+ interface UpdateTemplateGroupOptions {
108
+ readonly name?: string;
109
+ readonly templates?: readonly TemplateGroupItem[];
110
+ readonly terms?: string;
111
+ readonly coordinates?: TemplateCoordinates;
112
+ }
113
+ interface SourceTemplate {
114
+ readonly templateId: string;
115
+ readonly templateType: 'pdf' | 'html';
116
+ }
117
+ interface DocmanDocument {
118
+ readonly _id: string;
119
+ readonly name: string;
120
+ readonly description?: string;
121
+ readonly org: string;
122
+ readonly storageKey: string;
123
+ readonly version: number;
124
+ readonly sourceTemplates: readonly SourceTemplate[];
125
+ readonly templateData?: Record<string, unknown>;
126
+ readonly pages: number;
127
+ readonly sizeBytes: number;
128
+ readonly deliveryMode: 'managed' | 'passthrough';
129
+ readonly shareToken: string;
130
+ readonly createdBy: string;
131
+ readonly createdAt: string;
132
+ readonly updatedAt: string;
133
+ }
134
+ interface DocumentVersion {
135
+ readonly _id: string;
136
+ readonly version: number;
137
+ readonly pages: number;
138
+ readonly sizeBytes: number;
139
+ readonly createdAt: string;
140
+ readonly createdBy: string;
141
+ }
142
+ interface GenerateOptions {
143
+ /** Template IDs to render and merge into the final document */
144
+ readonly templateIds: readonly string[];
145
+ /** Data passed to Handlebars templates and PDF form fields */
146
+ readonly data: Record<string, unknown>;
147
+ /** Human-readable document name (used for storage and display) */
148
+ readonly name: string;
149
+ readonly description?: string;
150
+ }
151
+ interface GenerateResult {
152
+ readonly documentId: string;
153
+ readonly version: number;
154
+ /** Presigned S3 URL (1-hour TTL) */
155
+ readonly downloadUrl: string;
156
+ /** Public share URL: /d/:shareToken */
157
+ readonly publicUrl: string;
158
+ readonly pages: number;
159
+ readonly sizeBytes: number;
160
+ }
161
+ interface ListQuery {
162
+ readonly page?: number;
163
+ readonly limit?: number;
164
+ }
165
+ interface ListMeta {
166
+ readonly total: number;
167
+ readonly page: number;
168
+ readonly limit: number;
169
+ }
170
+ interface ListResult<T> {
171
+ readonly data: readonly T[];
172
+ readonly meta: ListMeta;
173
+ }
174
+ interface PageRange {
175
+ readonly start: number;
176
+ readonly end: number;
177
+ }
178
+ interface SplitPart {
179
+ readonly index: number;
180
+ readonly range: PageRange;
181
+ readonly buffer: Buffer;
182
+ readonly sizeBytes: number;
183
+ }
184
+
185
+ export type { CreateHtmlTemplateOptions as C, DocmanClientConfig as D, GenerateOptions as G, HtmlTemplate as H, ListResult as L, PdfTemplate as P, SplitPart as S, TemplateGroup as T, UpdateHtmlTemplateOptions as U, HtmlTemplateListQuery as a, CreatePdfTemplateOptions as b, PdfTemplateListQuery as c, PdfField as d, UpdatePdfTemplateOptions as e, CreateTemplateGroupOptions as f, ListQuery as g, UpdateTemplateGroupOptions as h, GenerateResult as i, DocmanDocument as j, DocumentVersion as k, PageRange as l, ListMeta as m, SourceTemplate as n, TemplateCoordinates as o, TemplateGroupItem as p };