@formepdf/sdk 0.9.0 → 0.9.1

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/README.md CHANGED
@@ -41,12 +41,55 @@ new Forme(apiKey: string, options?: { baseUrl?: string })
41
41
 
42
42
  ## Methods
43
43
 
44
- ### `render(slug, data?)`
44
+ ### `render(slug, data?, options?)`
45
45
 
46
46
  Render a template to PDF bytes.
47
47
 
48
48
  - **slug** — Template identifier
49
49
  - **data** — Template data (sent as JSON body, defaults to `{}`)
50
+ - **options.s3** — Optional S3 upload config (`{ bucket, key, accessKeyId, secretAccessKey, region?, endpoint? }`)
51
+ - **Returns** `Promise<Uint8Array>` (or `Promise<{ url: string }>` when `s3` is provided)
52
+
53
+ ### `renderAsync(slug, data?, options?)`
54
+
55
+ Start an async render job.
56
+
57
+ - **options.webhookUrl** — URL to receive a POST when the job completes
58
+ - **Returns** `Promise<{ jobId: string; status: string }>`
59
+
60
+ ### `getJob(jobId)`
61
+
62
+ Poll an async job's status.
63
+
64
+ - **Returns** `Promise<JobResult>` — includes `pdfBase64` when complete
65
+
66
+ ### `merge(pdfs)`
67
+
68
+ Merge multiple PDFs into one.
69
+
70
+ - **pdfs** — Array of `Uint8Array` (2–20 PDFs)
71
+ - **Returns** `Promise<Uint8Array>`
72
+
73
+ ### `certify(pdf, options)`
74
+
75
+ Certify a PDF with an X.509 digital certificate.
76
+
77
+ - **pdf** — PDF file bytes
78
+ - **options.certificate** — PEM-encoded certificate string
79
+ - **options.privateKey** — PEM-encoded private key string
80
+ - **options.certificateId** — Or use a saved certificate ID (instead of raw PEM)
81
+ - **options.reason** / **options.location** / **options.contact** — Optional metadata
82
+ - **Returns** `Promise<Uint8Array>`
83
+
84
+ ### `redact(pdf, options)`
85
+
86
+ Redact sensitive content from a PDF.
87
+
88
+ - **pdf** — PDF file bytes
89
+ - **options.patterns** — Array of `{ pattern, pattern_type: 'Literal' | 'Regex' }`
90
+ - **options.presets** — Built-in presets like `['ssn', 'email', 'phone']`
91
+ - **options.template** — Saved redaction template slug
92
+ - **options.redactions** — Explicit regions `{ page, x, y, width, height }[]`
50
93
  - **Returns** `Promise<Uint8Array>`
51
94
 
52
95
  ### `extract(pdf)`
package/dist/index.d.ts CHANGED
@@ -15,6 +15,31 @@ export interface RenderOptions {
15
15
  export interface AsyncRenderOptions {
16
16
  webhookUrl?: string;
17
17
  }
18
+ export interface CertifyOptions {
19
+ certificate?: string;
20
+ privateKey?: string;
21
+ certificateId?: string;
22
+ reason?: string;
23
+ location?: string;
24
+ contact?: string;
25
+ }
26
+ export interface RedactionPattern {
27
+ pattern: string;
28
+ pattern_type: 'Literal' | 'Regex';
29
+ }
30
+ export interface RedactionRegion {
31
+ page: number;
32
+ x: number;
33
+ y: number;
34
+ width: number;
35
+ height: number;
36
+ }
37
+ export interface RedactOptions {
38
+ redactions?: RedactionRegion[];
39
+ patterns?: RedactionPattern[];
40
+ presets?: string[];
41
+ template?: string;
42
+ }
18
43
  export interface JobResult {
19
44
  id: string;
20
45
  status: string;
@@ -38,5 +63,8 @@ export declare class Forme {
38
63
  status: string;
39
64
  }>;
40
65
  getJob(jobId: string): Promise<JobResult>;
66
+ merge(pdfs: Uint8Array[]): Promise<Uint8Array>;
67
+ certify(pdf: Uint8Array, options: CertifyOptions): Promise<Uint8Array>;
68
+ redact(pdf: Uint8Array, options: RedactOptions): Promise<Uint8Array>;
41
69
  extract(pdf: Uint8Array): Promise<unknown | null>;
42
70
  }
package/dist/index.js CHANGED
@@ -66,6 +66,72 @@ export class Forme {
66
66
  }
67
67
  return res.json();
68
68
  }
69
+ async merge(pdfs) {
70
+ const res = await fetch(`${this.baseUrl}/v1/merge`, {
71
+ method: 'POST',
72
+ headers: {
73
+ 'Authorization': `Bearer ${this.apiKey}`,
74
+ 'Content-Type': 'application/json',
75
+ },
76
+ body: JSON.stringify({
77
+ pdfs: pdfs.map((p) => uint8ArrayToBase64(p)),
78
+ }),
79
+ });
80
+ if (!res.ok) {
81
+ const message = await parseErrorMessage(res);
82
+ throw new FormeError(res.status, message);
83
+ }
84
+ return new Uint8Array(await res.arrayBuffer());
85
+ }
86
+ async certify(pdf, options) {
87
+ const body = {
88
+ pdf: uint8ArrayToBase64(pdf),
89
+ };
90
+ if (options.certificateId) {
91
+ body.certificateId = options.certificateId;
92
+ }
93
+ else {
94
+ body.certificate = options.certificate;
95
+ body.privateKey = options.privateKey;
96
+ }
97
+ if (options.reason)
98
+ body.reason = options.reason;
99
+ if (options.location)
100
+ body.location = options.location;
101
+ if (options.contact)
102
+ body.contact = options.contact;
103
+ const res = await fetch(`${this.baseUrl}/v1/certify`, {
104
+ method: 'POST',
105
+ headers: {
106
+ 'Authorization': `Bearer ${this.apiKey}`,
107
+ 'Content-Type': 'application/json',
108
+ },
109
+ body: JSON.stringify(body),
110
+ });
111
+ if (!res.ok) {
112
+ const message = await parseErrorMessage(res);
113
+ throw new FormeError(res.status, message);
114
+ }
115
+ return new Uint8Array(await res.arrayBuffer());
116
+ }
117
+ async redact(pdf, options) {
118
+ const res = await fetch(`${this.baseUrl}/v1/redact`, {
119
+ method: 'POST',
120
+ headers: {
121
+ 'Authorization': `Bearer ${this.apiKey}`,
122
+ 'Content-Type': 'application/json',
123
+ },
124
+ body: JSON.stringify({
125
+ pdf: uint8ArrayToBase64(pdf),
126
+ ...options,
127
+ }),
128
+ });
129
+ if (!res.ok) {
130
+ const message = await parseErrorMessage(res);
131
+ throw new FormeError(res.status, message);
132
+ }
133
+ return new Uint8Array(await res.arrayBuffer());
134
+ }
69
135
  async extract(pdf) {
70
136
  const res = await fetch(`${this.baseUrl}/v1/extract`, {
71
137
  method: 'POST',
@@ -90,6 +156,16 @@ export class Forme {
90
156
  return body.data;
91
157
  }
92
158
  }
159
+ function uint8ArrayToBase64(bytes) {
160
+ if (typeof Buffer !== 'undefined') {
161
+ return Buffer.from(bytes).toString('base64');
162
+ }
163
+ let binary = '';
164
+ for (let i = 0; i < bytes.length; i++) {
165
+ binary += String.fromCharCode(bytes[i]);
166
+ }
167
+ return btoa(binary);
168
+ }
93
169
  async function parseErrorMessage(res) {
94
170
  try {
95
171
  const body = await res.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formepdf/sdk",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "TypeScript client for the Forme hosted PDF API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",