@pdfcraft-dev/pdf 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/LICENSE +21 -0
- package/README.md +207 -0
- package/dist/cjs/client.js +107 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/contract/errors.js +91 -0
- package/dist/cjs/contract/errors.js.map +1 -0
- package/dist/cjs/contract/index.js +23 -0
- package/dist/cjs/contract/index.js.map +1 -0
- package/dist/cjs/contract/render-options.js +111 -0
- package/dist/cjs/contract/render-options.js.map +1 -0
- package/dist/cjs/contract/request.js +43 -0
- package/dist/cjs/contract/request.js.map +1 -0
- package/dist/cjs/errors.js +31 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/client.d.ts +36 -0
- package/dist/esm/client.js +103 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/contract/errors.d.ts +75 -0
- package/dist/esm/contract/errors.js +87 -0
- package/dist/esm/contract/errors.js.map +1 -0
- package/dist/esm/contract/index.d.ts +3 -0
- package/dist/esm/contract/index.js +7 -0
- package/dist/esm/contract/index.js.map +1 -0
- package/dist/esm/contract/render-options.d.ts +191 -0
- package/dist/esm/contract/render-options.js +108 -0
- package/dist/esm/contract/render-options.js.map +1 -0
- package/dist/esm/contract/request.d.ts +121 -0
- package/dist/esm/contract/request.js +40 -0
- package/dist/esm/contract/request.js.map +1 -0
- package/dist/esm/errors.d.ts +10 -0
- package/dist/esm/errors.js +26 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
export type OptionKind = {
|
|
2
|
+
readonly kind: 'enum';
|
|
3
|
+
readonly values: readonly string[];
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: 'boolean';
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'number';
|
|
8
|
+
readonly min: number;
|
|
9
|
+
readonly max: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'integer';
|
|
12
|
+
readonly min: number;
|
|
13
|
+
readonly max: number;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'string';
|
|
16
|
+
readonly maxLength: number;
|
|
17
|
+
readonly pattern?: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'css-length';
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'object';
|
|
22
|
+
readonly fields: readonly OptionField[];
|
|
23
|
+
};
|
|
24
|
+
export interface OptionField {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly type: OptionKind;
|
|
27
|
+
readonly default?: string | number | boolean;
|
|
28
|
+
readonly description: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const PAGE_FORMATS: readonly ["A4", "A3", "A5", "Letter", "Legal", "Tabloid"];
|
|
31
|
+
export declare const EMULATE_MEDIA: readonly ["print", "screen"];
|
|
32
|
+
export declare const MAX_TIMEOUT_MS = 120000;
|
|
33
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
34
|
+
export declare const MAX_HTML_BYTES = 5000000;
|
|
35
|
+
export declare const RENDER_OPTIONS_SPEC: readonly [{
|
|
36
|
+
readonly name: "format";
|
|
37
|
+
readonly type: {
|
|
38
|
+
readonly kind: "enum";
|
|
39
|
+
readonly values: readonly ["A4", "A3", "A5", "Letter", "Legal", "Tabloid"];
|
|
40
|
+
};
|
|
41
|
+
readonly default: "A4";
|
|
42
|
+
readonly description: "Paper size. Ignored if the page CSS declares its own @page size.";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "landscape";
|
|
45
|
+
readonly type: {
|
|
46
|
+
readonly kind: "boolean";
|
|
47
|
+
};
|
|
48
|
+
readonly default: false;
|
|
49
|
+
readonly description: "Rotate the paper to landscape orientation.";
|
|
50
|
+
}, {
|
|
51
|
+
readonly name: "margin";
|
|
52
|
+
readonly type: {
|
|
53
|
+
readonly kind: "object";
|
|
54
|
+
readonly fields: readonly [{
|
|
55
|
+
readonly name: "top";
|
|
56
|
+
readonly type: {
|
|
57
|
+
readonly kind: "css-length";
|
|
58
|
+
};
|
|
59
|
+
readonly description: "e.g. \"20mm\", \"1in\", \"72px\".";
|
|
60
|
+
}, {
|
|
61
|
+
readonly name: "right";
|
|
62
|
+
readonly type: {
|
|
63
|
+
readonly kind: "css-length";
|
|
64
|
+
};
|
|
65
|
+
readonly description: "e.g. \"15mm\".";
|
|
66
|
+
}, {
|
|
67
|
+
readonly name: "bottom";
|
|
68
|
+
readonly type: {
|
|
69
|
+
readonly kind: "css-length";
|
|
70
|
+
};
|
|
71
|
+
readonly description: "e.g. \"20mm\".";
|
|
72
|
+
}, {
|
|
73
|
+
readonly name: "left";
|
|
74
|
+
readonly type: {
|
|
75
|
+
readonly kind: "css-length";
|
|
76
|
+
};
|
|
77
|
+
readonly description: "e.g. \"15mm\".";
|
|
78
|
+
}];
|
|
79
|
+
};
|
|
80
|
+
readonly description: "Page margins. Any side may be omitted; omitted sides default to 0.";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "scale";
|
|
83
|
+
readonly type: {
|
|
84
|
+
readonly kind: "number";
|
|
85
|
+
readonly min: 0.1;
|
|
86
|
+
readonly max: 2;
|
|
87
|
+
};
|
|
88
|
+
readonly default: 1;
|
|
89
|
+
readonly description: "Rendering scale factor.";
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: "printBackground";
|
|
92
|
+
readonly type: {
|
|
93
|
+
readonly kind: "boolean";
|
|
94
|
+
};
|
|
95
|
+
readonly default: true;
|
|
96
|
+
readonly description: "Print background colours and images. Off by default in browsers; on by default here.";
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: "pageRanges";
|
|
99
|
+
readonly type: {
|
|
100
|
+
readonly kind: "string";
|
|
101
|
+
readonly maxLength: 100;
|
|
102
|
+
readonly pattern: "^[0-9,\\-\\s]+$";
|
|
103
|
+
};
|
|
104
|
+
readonly description: "Subset of pages to keep, e.g. \"1-5\" or \"1,4,7-9\". Empty means all pages.";
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "headerHtml";
|
|
107
|
+
readonly type: {
|
|
108
|
+
readonly kind: "string";
|
|
109
|
+
readonly maxLength: 50000;
|
|
110
|
+
};
|
|
111
|
+
readonly description: "HTML for the running header. Supports Chromium print classes: date, title, url, pageNumber, totalPages. Needs a top margin to be visible.";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "footerHtml";
|
|
114
|
+
readonly type: {
|
|
115
|
+
readonly kind: "string";
|
|
116
|
+
readonly maxLength: 50000;
|
|
117
|
+
};
|
|
118
|
+
readonly description: "HTML for the running footer. Same classes as headerHtml; needs a bottom margin.";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "waitFor";
|
|
121
|
+
readonly type: {
|
|
122
|
+
readonly kind: "object";
|
|
123
|
+
readonly fields: readonly [{
|
|
124
|
+
readonly name: "selector";
|
|
125
|
+
readonly type: {
|
|
126
|
+
readonly kind: "string";
|
|
127
|
+
readonly maxLength: 500;
|
|
128
|
+
};
|
|
129
|
+
readonly description: "Wait until this CSS selector is attached to the DOM.";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "networkIdle";
|
|
132
|
+
readonly type: {
|
|
133
|
+
readonly kind: "boolean";
|
|
134
|
+
};
|
|
135
|
+
readonly default: false;
|
|
136
|
+
readonly description: "Wait until there have been no network connections for 500 ms.";
|
|
137
|
+
}, {
|
|
138
|
+
readonly name: "delayMs";
|
|
139
|
+
readonly type: {
|
|
140
|
+
readonly kind: "integer";
|
|
141
|
+
readonly min: 0;
|
|
142
|
+
readonly max: 30000;
|
|
143
|
+
};
|
|
144
|
+
readonly default: 0;
|
|
145
|
+
readonly description: "Fixed pause after the other wait conditions are satisfied.";
|
|
146
|
+
}];
|
|
147
|
+
};
|
|
148
|
+
readonly description: "Conditions to satisfy before the PDF is taken. All of them apply, in order.";
|
|
149
|
+
}, {
|
|
150
|
+
readonly name: "emulateMedia";
|
|
151
|
+
readonly type: {
|
|
152
|
+
readonly kind: "enum";
|
|
153
|
+
readonly values: readonly ["print", "screen"];
|
|
154
|
+
};
|
|
155
|
+
readonly default: "print";
|
|
156
|
+
readonly description: "Which CSS media type the page sees.";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "timeoutMs";
|
|
159
|
+
readonly type: {
|
|
160
|
+
readonly kind: "integer";
|
|
161
|
+
readonly min: 1000;
|
|
162
|
+
readonly max: 120000;
|
|
163
|
+
};
|
|
164
|
+
readonly default: 30000;
|
|
165
|
+
readonly description: "Hard ceiling on the whole render. Exceeding it returns 408 render_timeout.";
|
|
166
|
+
}];
|
|
167
|
+
export interface Margin {
|
|
168
|
+
top?: string;
|
|
169
|
+
right?: string;
|
|
170
|
+
bottom?: string;
|
|
171
|
+
left?: string;
|
|
172
|
+
}
|
|
173
|
+
export interface WaitFor {
|
|
174
|
+
selector?: string;
|
|
175
|
+
networkIdle?: boolean;
|
|
176
|
+
delayMs?: number;
|
|
177
|
+
}
|
|
178
|
+
export interface RenderOptions {
|
|
179
|
+
format?: (typeof PAGE_FORMATS)[number];
|
|
180
|
+
landscape?: boolean;
|
|
181
|
+
margin?: Margin;
|
|
182
|
+
scale?: number;
|
|
183
|
+
printBackground?: boolean;
|
|
184
|
+
pageRanges?: string;
|
|
185
|
+
headerHtml?: string;
|
|
186
|
+
footerHtml?: string;
|
|
187
|
+
waitFor?: WaitFor;
|
|
188
|
+
emulateMedia?: (typeof EMULATE_MEDIA)[number];
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
}
|
|
191
|
+
export declare const SPEC_MATCHES_TYPES: boolean;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// packages/contract/src/render-options.ts
|
|
2
|
+
//
|
|
3
|
+
// The one description of the render option surface. The API builds its validator
|
|
4
|
+
// from RENDER_OPTIONS_SPEC and the docs site builds its reference table from the
|
|
5
|
+
// same constant, so the two cannot drift. The SDK vendors this file verbatim at
|
|
6
|
+
// build time (see packages/sdk/scripts/vendor-contract.mjs) to stay dependency-free.
|
|
7
|
+
export const PAGE_FORMATS = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid'];
|
|
8
|
+
export const EMULATE_MEDIA = ['print', 'screen'];
|
|
9
|
+
export const MAX_TIMEOUT_MS = 120_000;
|
|
10
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
11
|
+
export const MAX_HTML_BYTES = 5_000_000;
|
|
12
|
+
export const RENDER_OPTIONS_SPEC = [
|
|
13
|
+
{
|
|
14
|
+
name: 'format',
|
|
15
|
+
type: { kind: 'enum', values: PAGE_FORMATS },
|
|
16
|
+
default: 'A4',
|
|
17
|
+
description: 'Paper size. Ignored if the page CSS declares its own @page size.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'landscape',
|
|
21
|
+
type: { kind: 'boolean' },
|
|
22
|
+
default: false,
|
|
23
|
+
description: 'Rotate the paper to landscape orientation.',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'margin',
|
|
27
|
+
type: {
|
|
28
|
+
kind: 'object',
|
|
29
|
+
fields: [
|
|
30
|
+
{ name: 'top', type: { kind: 'css-length' }, description: 'e.g. "20mm", "1in", "72px".' },
|
|
31
|
+
{ name: 'right', type: { kind: 'css-length' }, description: 'e.g. "15mm".' },
|
|
32
|
+
{ name: 'bottom', type: { kind: 'css-length' }, description: 'e.g. "20mm".' },
|
|
33
|
+
{ name: 'left', type: { kind: 'css-length' }, description: 'e.g. "15mm".' },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
description: 'Page margins. Any side may be omitted; omitted sides default to 0.',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'scale',
|
|
40
|
+
type: { kind: 'number', min: 0.1, max: 2 },
|
|
41
|
+
default: 1,
|
|
42
|
+
description: 'Rendering scale factor.',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'printBackground',
|
|
46
|
+
type: { kind: 'boolean' },
|
|
47
|
+
default: true,
|
|
48
|
+
description: 'Print background colours and images. Off by default in browsers; on by default here.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'pageRanges',
|
|
52
|
+
type: { kind: 'string', maxLength: 100, pattern: '^[0-9,\\-\\s]+$' },
|
|
53
|
+
description: 'Subset of pages to keep, e.g. "1-5" or "1,4,7-9". Empty means all pages.',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'headerHtml',
|
|
57
|
+
type: { kind: 'string', maxLength: 50_000 },
|
|
58
|
+
description: 'HTML for the running header. Supports Chromium print classes: date, title, url, pageNumber, totalPages. Needs a top margin to be visible.',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'footerHtml',
|
|
62
|
+
type: { kind: 'string', maxLength: 50_000 },
|
|
63
|
+
description: 'HTML for the running footer. Same classes as headerHtml; needs a bottom margin.',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'waitFor',
|
|
67
|
+
type: {
|
|
68
|
+
kind: 'object',
|
|
69
|
+
fields: [
|
|
70
|
+
{
|
|
71
|
+
name: 'selector',
|
|
72
|
+
type: { kind: 'string', maxLength: 500 },
|
|
73
|
+
description: 'Wait until this CSS selector is attached to the DOM.',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'networkIdle',
|
|
77
|
+
type: { kind: 'boolean' },
|
|
78
|
+
default: false,
|
|
79
|
+
description: 'Wait until there have been no network connections for 500 ms.',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'delayMs',
|
|
83
|
+
type: { kind: 'integer', min: 0, max: 30_000 },
|
|
84
|
+
default: 0,
|
|
85
|
+
description: 'Fixed pause after the other wait conditions are satisfied.',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
description: 'Conditions to satisfy before the PDF is taken. All of them apply, in order.',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'emulateMedia',
|
|
93
|
+
type: { kind: 'enum', values: EMULATE_MEDIA },
|
|
94
|
+
default: 'print',
|
|
95
|
+
description: 'Which CSS media type the page sees.',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'timeoutMs',
|
|
99
|
+
type: { kind: 'integer', min: 1000, max: MAX_TIMEOUT_MS },
|
|
100
|
+
default: DEFAULT_TIMEOUT_MS,
|
|
101
|
+
description: 'Hard ceiling on the whole render. Exceeding it returns 408 render_timeout.',
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
// Compile-time drift guard: this assignment stops type-checking the moment
|
|
105
|
+
// RENDER_OPTIONS_SPEC and RenderOptions describe different sets of options.
|
|
106
|
+
const driftCheck = true;
|
|
107
|
+
export const SPEC_MATCHES_TYPES = driftCheck;
|
|
108
|
+
//# sourceMappingURL=render-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-options.js","sourceRoot":"","sources":["../../../src/contract/render-options.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,gFAAgF;AAChF,qFAAqF;AAkBrF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAU,CAAC;AACtF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAU,CAAC;AAE1D,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC;QACE,IAAI,EAAE,QAAQ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AAO,EAAE,kBAAkB;QAC3B,WAAW,EAAE,4EAA4E;KAC1F;CACwC,CAAC;AA+B5C,2EAA2E;AAC3E,4EAA4E;AAC5E,MAAM,UAAU,GAIJ,IAAI,CAAC;AAEjB,MAAM,CAAC,MAAM,kBAAkB,GAAY,UAAU,CAAC","sourcesContent":["// packages/contract/src/render-options.ts\n//\n// The one description of the render option surface. The API builds its validator\n// from RENDER_OPTIONS_SPEC and the docs site builds its reference table from the\n// same constant, so the two cannot drift. The SDK vendors this file verbatim at\n// build time (see packages/sdk/scripts/vendor-contract.mjs) to stay dependency-free.\n\nexport type OptionKind =\n | { readonly kind: 'enum'; readonly values: readonly string[] }\n | { readonly kind: 'boolean' }\n | { readonly kind: 'number'; readonly min: number; readonly max: number }\n | { readonly kind: 'integer'; readonly min: number; readonly max: number }\n | { readonly kind: 'string'; readonly maxLength: number; readonly pattern?: string }\n | { readonly kind: 'css-length' }\n | { readonly kind: 'object'; readonly fields: readonly OptionField[] };\n\nexport interface OptionField {\n readonly name: string;\n readonly type: OptionKind;\n readonly default?: string | number | boolean;\n readonly description: string;\n}\n\nexport const PAGE_FORMATS = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid'] as const;\nexport const EMULATE_MEDIA = ['print', 'screen'] as const;\n\nexport const MAX_TIMEOUT_MS = 120_000;\nexport const DEFAULT_TIMEOUT_MS = 30_000;\nexport const MAX_HTML_BYTES = 5_000_000;\n\nexport const RENDER_OPTIONS_SPEC = [\n {\n name: 'format',\n type: { kind: 'enum', values: PAGE_FORMATS },\n default: 'A4',\n description: 'Paper size. Ignored if the page CSS declares its own @page size.',\n },\n {\n name: 'landscape',\n type: { kind: 'boolean' },\n default: false,\n description: 'Rotate the paper to landscape orientation.',\n },\n {\n name: 'margin',\n type: {\n kind: 'object',\n fields: [\n { name: 'top', type: { kind: 'css-length' }, description: 'e.g. \"20mm\", \"1in\", \"72px\".' },\n { name: 'right', type: { kind: 'css-length' }, description: 'e.g. \"15mm\".' },\n { name: 'bottom', type: { kind: 'css-length' }, description: 'e.g. \"20mm\".' },\n { name: 'left', type: { kind: 'css-length' }, description: 'e.g. \"15mm\".' },\n ],\n },\n description: 'Page margins. Any side may be omitted; omitted sides default to 0.',\n },\n {\n name: 'scale',\n type: { kind: 'number', min: 0.1, max: 2 },\n default: 1,\n description: 'Rendering scale factor.',\n },\n {\n name: 'printBackground',\n type: { kind: 'boolean' },\n default: true,\n description:\n 'Print background colours and images. Off by default in browsers; on by default here.',\n },\n {\n name: 'pageRanges',\n type: { kind: 'string', maxLength: 100, pattern: '^[0-9,\\\\-\\\\s]+$' },\n description: 'Subset of pages to keep, e.g. \"1-5\" or \"1,4,7-9\". Empty means all pages.',\n },\n {\n name: 'headerHtml',\n type: { kind: 'string', maxLength: 50_000 },\n description:\n 'HTML for the running header. Supports Chromium print classes: date, title, url, pageNumber, totalPages. Needs a top margin to be visible.',\n },\n {\n name: 'footerHtml',\n type: { kind: 'string', maxLength: 50_000 },\n description: 'HTML for the running footer. Same classes as headerHtml; needs a bottom margin.',\n },\n {\n name: 'waitFor',\n type: {\n kind: 'object',\n fields: [\n {\n name: 'selector',\n type: { kind: 'string', maxLength: 500 },\n description: 'Wait until this CSS selector is attached to the DOM.',\n },\n {\n name: 'networkIdle',\n type: { kind: 'boolean' },\n default: false,\n description: 'Wait until there have been no network connections for 500 ms.',\n },\n {\n name: 'delayMs',\n type: { kind: 'integer', min: 0, max: 30_000 },\n default: 0,\n description: 'Fixed pause after the other wait conditions are satisfied.',\n },\n ],\n },\n description: 'Conditions to satisfy before the PDF is taken. All of them apply, in order.',\n },\n {\n name: 'emulateMedia',\n type: { kind: 'enum', values: EMULATE_MEDIA },\n default: 'print',\n description: 'Which CSS media type the page sees.',\n },\n {\n name: 'timeoutMs',\n type: { kind: 'integer', min: 1000, max: MAX_TIMEOUT_MS },\n default: DEFAULT_TIMEOUT_MS,\n description: 'Hard ceiling on the whole render. Exceeding it returns 408 render_timeout.',\n },\n] as const satisfies readonly OptionField[];\n\nexport interface Margin {\n top?: string;\n right?: string;\n bottom?: string;\n left?: string;\n}\n\nexport interface WaitFor {\n selector?: string;\n networkIdle?: boolean;\n delayMs?: number;\n}\n\nexport interface RenderOptions {\n format?: (typeof PAGE_FORMATS)[number];\n landscape?: boolean;\n margin?: Margin;\n scale?: number;\n printBackground?: boolean;\n pageRanges?: string;\n headerHtml?: string;\n footerHtml?: string;\n waitFor?: WaitFor;\n emulateMedia?: (typeof EMULATE_MEDIA)[number];\n timeoutMs?: number;\n}\n\ntype SpecFieldName = (typeof RENDER_OPTIONS_SPEC)[number]['name'];\n\n// Compile-time drift guard: this assignment stops type-checking the moment\n// RENDER_OPTIONS_SPEC and RenderOptions describe different sets of options.\nconst driftCheck: [Exclude<keyof RenderOptions, SpecFieldName>] extends [never]\n ? [Exclude<SpecFieldName, keyof RenderOptions>] extends [never]\n ? true\n : never\n : never = true;\n\nexport const SPEC_MATCHES_TYPES: boolean = driftCheck;\n"]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type RenderOptions } from './render-options.js';
|
|
2
|
+
export declare const OUTPUT_MODES: readonly ["binary", "url"];
|
|
3
|
+
export type OutputMode = (typeof OUTPUT_MODES)[number];
|
|
4
|
+
export declare const RENDER_STATUSES: readonly ["queued", "rendering", "succeeded", "failed"];
|
|
5
|
+
export type RenderStatus = (typeof RENDER_STATUSES)[number];
|
|
6
|
+
export declare const RENDER_SOURCES: readonly ["html", "url"];
|
|
7
|
+
export type RenderSource = (typeof RENDER_SOURCES)[number];
|
|
8
|
+
export declare const ACCOUNT_STATUSES: readonly ["active", "past_due", "cancelled"];
|
|
9
|
+
export type AccountStatus = (typeof ACCOUNT_STATUSES)[number];
|
|
10
|
+
export interface Cookie {
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
domain?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RenderRequest {
|
|
17
|
+
/** Exactly one of html or url. */
|
|
18
|
+
html?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
options?: RenderOptions;
|
|
21
|
+
output?: OutputMode;
|
|
22
|
+
filename?: string;
|
|
23
|
+
/** url input only: extra request headers, so an authenticated page can be rendered. */
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
/** url input only: cookies to seed the context with. */
|
|
26
|
+
cookies?: Cookie[];
|
|
27
|
+
}
|
|
28
|
+
export interface AsyncRenderRequest extends RenderRequest {
|
|
29
|
+
callback_url: string;
|
|
30
|
+
}
|
|
31
|
+
export interface RenderUrlResponse {
|
|
32
|
+
id: string;
|
|
33
|
+
url: string;
|
|
34
|
+
expires_at: string;
|
|
35
|
+
pages: number;
|
|
36
|
+
bytes: number;
|
|
37
|
+
duration_ms: number;
|
|
38
|
+
}
|
|
39
|
+
export interface AsyncRenderAccepted {
|
|
40
|
+
id: string;
|
|
41
|
+
status: 'queued';
|
|
42
|
+
}
|
|
43
|
+
export interface RenderStatusResponse {
|
|
44
|
+
id: string;
|
|
45
|
+
status: RenderStatus;
|
|
46
|
+
url?: string;
|
|
47
|
+
expires_at?: string;
|
|
48
|
+
pages?: number;
|
|
49
|
+
bytes?: number;
|
|
50
|
+
duration_ms?: number;
|
|
51
|
+
error?: {
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface UsageResponse {
|
|
57
|
+
used: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
overage_count: number;
|
|
60
|
+
period_start: string;
|
|
61
|
+
resets_at: string;
|
|
62
|
+
}
|
|
63
|
+
/** Body sent to callback_url when an async render settles. */
|
|
64
|
+
export interface WebhookPayload {
|
|
65
|
+
id: string;
|
|
66
|
+
status: 'succeeded' | 'failed';
|
|
67
|
+
url?: string;
|
|
68
|
+
pages?: number;
|
|
69
|
+
bytes?: number;
|
|
70
|
+
duration_ms: number;
|
|
71
|
+
error?: {
|
|
72
|
+
code: string;
|
|
73
|
+
message: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Top-level request fields, for the generated docs reference. */
|
|
77
|
+
export declare const REQUEST_FIELDS_SPEC: readonly [{
|
|
78
|
+
readonly name: "html";
|
|
79
|
+
readonly type: {
|
|
80
|
+
readonly kind: "string";
|
|
81
|
+
readonly maxLength: 5000000;
|
|
82
|
+
};
|
|
83
|
+
readonly description: "The document to render. Mutually exclusive with url; exactly one is required.";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "url";
|
|
86
|
+
readonly type: {
|
|
87
|
+
readonly kind: "string";
|
|
88
|
+
readonly maxLength: 2000;
|
|
89
|
+
};
|
|
90
|
+
readonly description: "A public http(s) URL to render. Mutually exclusive with html.";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "output";
|
|
93
|
+
readonly type: {
|
|
94
|
+
readonly kind: "enum";
|
|
95
|
+
readonly values: readonly ["binary", "url"];
|
|
96
|
+
};
|
|
97
|
+
readonly default: "binary";
|
|
98
|
+
readonly description: "\"binary\" streams application/pdf back; \"url\" uploads and returns a signed link.";
|
|
99
|
+
}, {
|
|
100
|
+
readonly name: "filename";
|
|
101
|
+
readonly type: {
|
|
102
|
+
readonly kind: "string";
|
|
103
|
+
readonly maxLength: 255;
|
|
104
|
+
};
|
|
105
|
+
readonly default: "document.pdf";
|
|
106
|
+
readonly description: "Used for Content-Disposition on binary output and in the signed URL.";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "headers";
|
|
109
|
+
readonly type: {
|
|
110
|
+
readonly kind: "object";
|
|
111
|
+
readonly fields: readonly [];
|
|
112
|
+
};
|
|
113
|
+
readonly description: "url input only. Extra request headers, e.g. an Authorization header.";
|
|
114
|
+
}, {
|
|
115
|
+
readonly name: "cookies";
|
|
116
|
+
readonly type: {
|
|
117
|
+
readonly kind: "object";
|
|
118
|
+
readonly fields: readonly [];
|
|
119
|
+
};
|
|
120
|
+
readonly description: "url input only. Array of {name, value, domain?, path?} seeded into the context.";
|
|
121
|
+
}];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const OUTPUT_MODES = ['binary', 'url'];
|
|
2
|
+
export const RENDER_STATUSES = ['queued', 'rendering', 'succeeded', 'failed'];
|
|
3
|
+
export const RENDER_SOURCES = ['html', 'url'];
|
|
4
|
+
export const ACCOUNT_STATUSES = ['active', 'past_due', 'cancelled'];
|
|
5
|
+
/** Top-level request fields, for the generated docs reference. */
|
|
6
|
+
export const REQUEST_FIELDS_SPEC = [
|
|
7
|
+
{
|
|
8
|
+
name: 'html',
|
|
9
|
+
type: { kind: 'string', maxLength: 5_000_000 },
|
|
10
|
+
description: 'The document to render. Mutually exclusive with url; exactly one is required.',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'url',
|
|
14
|
+
type: { kind: 'string', maxLength: 2000 },
|
|
15
|
+
description: 'A public http(s) URL to render. Mutually exclusive with html.',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'output',
|
|
19
|
+
type: { kind: 'enum', values: OUTPUT_MODES },
|
|
20
|
+
default: 'binary',
|
|
21
|
+
description: '"binary" streams application/pdf back; "url" uploads and returns a signed link.',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'filename',
|
|
25
|
+
type: { kind: 'string', maxLength: 255 },
|
|
26
|
+
default: 'document.pdf',
|
|
27
|
+
description: 'Used for Content-Disposition on binary output and in the signed URL.',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'headers',
|
|
31
|
+
type: { kind: 'object', fields: [] },
|
|
32
|
+
description: 'url input only. Extra request headers, e.g. an Authorization header.',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'cookies',
|
|
36
|
+
type: { kind: 'object', fields: [] },
|
|
37
|
+
description: 'url input only. Array of {name, value, domain?, path?} seeded into the context.',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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,EAAE,MAAM,EAAE,EAAE,EAAE;QACpC,WAAW,EAAE,iFAAiF;KAC/F;CACwC,CAAC","sourcesContent":["// packages/contract/src/request.ts\nimport { type OptionField, type RenderOptions } from './render-options.js';\n\nexport const OUTPUT_MODES = ['binary', 'url'] as const;\nexport type OutputMode = (typeof OUTPUT_MODES)[number];\n\nexport const RENDER_STATUSES = ['queued', 'rendering', 'succeeded', 'failed'] as const;\nexport type RenderStatus = (typeof RENDER_STATUSES)[number];\n\nexport const RENDER_SOURCES = ['html', 'url'] as const;\nexport type RenderSource = (typeof RENDER_SOURCES)[number];\n\nexport const ACCOUNT_STATUSES = ['active', 'past_due', 'cancelled'] as const;\nexport type AccountStatus = (typeof ACCOUNT_STATUSES)[number];\n\nexport interface Cookie {\n name: string;\n value: string;\n domain?: string;\n path?: string;\n}\n\nexport interface RenderRequest {\n /** Exactly one of html or url. */\n html?: string;\n url?: string;\n options?: RenderOptions;\n output?: OutputMode;\n filename?: string;\n /** url input only: extra request headers, so an authenticated page can be rendered. */\n headers?: Record<string, string>;\n /** url input only: cookies to seed the context with. */\n cookies?: Cookie[];\n}\n\nexport interface AsyncRenderRequest extends RenderRequest {\n callback_url: string;\n}\n\nexport interface RenderUrlResponse {\n id: string;\n url: string;\n expires_at: string;\n pages: number;\n bytes: number;\n duration_ms: number;\n}\n\nexport interface AsyncRenderAccepted {\n id: string;\n status: 'queued';\n}\n\nexport interface RenderStatusResponse {\n id: string;\n status: RenderStatus;\n url?: string;\n expires_at?: string;\n pages?: number;\n bytes?: number;\n duration_ms?: number;\n error?: { code: string; message: string };\n}\n\nexport interface UsageResponse {\n used: number;\n limit: number;\n overage_count: number;\n period_start: string;\n resets_at: string;\n}\n\n/** Body sent to callback_url when an async render settles. */\nexport interface WebhookPayload {\n id: string;\n status: 'succeeded' | 'failed';\n url?: string;\n pages?: number;\n bytes?: number;\n duration_ms: number;\n error?: { code: string; message: string };\n}\n\n/** Top-level request fields, for the generated docs reference. */\nexport const REQUEST_FIELDS_SPEC = [\n {\n name: 'html',\n type: { kind: 'string', maxLength: 5_000_000 },\n description: 'The document to render. Mutually exclusive with url; exactly one is required.',\n },\n {\n name: 'url',\n type: { kind: 'string', maxLength: 2000 },\n description: 'A public http(s) URL to render. Mutually exclusive with html.',\n },\n {\n name: 'output',\n type: { kind: 'enum', values: OUTPUT_MODES },\n default: 'binary',\n description: '\"binary\" streams application/pdf back; \"url\" uploads and returns a signed link.',\n },\n {\n name: 'filename',\n type: { kind: 'string', maxLength: 255 },\n default: 'document.pdf',\n description: 'Used for Content-Disposition on binary output and in the signed URL.',\n },\n {\n name: 'headers',\n type: { kind: 'object', fields: [] },\n description: 'url input only. Extra request headers, e.g. an Authorization header.',\n },\n {\n name: 'cookies',\n type: { kind: 'object', fields: [] },\n description: 'url input only. Array of {name, value, domain?, path?} seeded into the context.',\n },\n] as const satisfies readonly OptionField[];\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ErrorCode } from './contract/index.js';
|
|
2
|
+
/** Every failure from the API arrives as one of these. Branch on `.code`. */
|
|
3
|
+
export declare class PDFCraftError extends Error {
|
|
4
|
+
readonly code: ErrorCode | 'network_error';
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly docsUrl: string | null;
|
|
7
|
+
readonly retryable: boolean;
|
|
8
|
+
constructor(code: ErrorCode | 'network_error', message: string, status: number, docsUrl?: string | null);
|
|
9
|
+
}
|
|
10
|
+
export declare function toError(status: number, body: string): PDFCraftError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Every failure from the API arrives as one of these. Branch on `.code`. */
|
|
2
|
+
export class PDFCraftError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
docsUrl;
|
|
6
|
+
retryable;
|
|
7
|
+
constructor(code, message, status, docsUrl = null) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'PDFCraftError';
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.docsUrl = docsUrl;
|
|
13
|
+
this.retryable = code === 'network_error' || status === 429 || status >= 500;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function toError(status, body) {
|
|
17
|
+
let parsed = {};
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(body);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Non-JSON body (a proxy error page, say) — fall through to the defaults.
|
|
23
|
+
}
|
|
24
|
+
return new PDFCraftError(parsed.error?.code ?? 'internal_error', parsed.error?.message ?? `PDFCraft responded ${status}`, status, parsed.error?.docs_url ?? null);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAGA,6EAA6E;AAC7E,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAA8B;IAClC,MAAM,CAAS;IACf,OAAO,CAAgB;IACvB,SAAS,CAAU;IAE5B,YACE,IAAiC,EACjC,OAAe,EACf,MAAc,EACd,UAAyB,IAAI;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,KAAK,eAAe,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;IAC/E,CAAC;CACF;AAMD,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,IAAY;IAClD,IAAI,MAAM,GAAc,EAAE,CAAC;IAC3B,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAc,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;IAC5E,CAAC;IACD,OAAO,IAAI,aAAa,CACrB,MAAM,CAAC,KAAK,EAAE,IAAkB,IAAI,gBAAgB,EACrD,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,sBAAsB,MAAM,EAAE,EACvD,MAAM,EACN,MAAM,CAAC,KAAK,EAAE,QAAQ,IAAI,IAAI,CAC/B,CAAC;AACJ,CAAC","sourcesContent":["// packages/sdk/src/errors.ts\nimport type { ErrorCode } from './contract/index.js';\n\n/** Every failure from the API arrives as one of these. Branch on `.code`. */\nexport class PDFCraftError extends Error {\n readonly code: ErrorCode | 'network_error';\n readonly status: number;\n readonly docsUrl: string | null;\n readonly retryable: boolean;\n\n constructor(\n code: ErrorCode | 'network_error',\n message: string,\n status: number,\n docsUrl: string | null = null,\n ) {\n super(message);\n this.name = 'PDFCraftError';\n this.code = code;\n this.status = status;\n this.docsUrl = docsUrl;\n this.retryable = code === 'network_error' || status === 429 || status >= 500;\n }\n}\n\ninterface WireError {\n error?: { code?: string; message?: string; docs_url?: string };\n}\n\nexport function toError(status: number, body: string): PDFCraftError {\n let parsed: WireError = {};\n try {\n parsed = JSON.parse(body) as WireError;\n } catch {\n // Non-JSON body (a proxy error page, say) — fall through to the defaults.\n }\n return new PDFCraftError(\n (parsed.error?.code as ErrorCode) ?? 'internal_error',\n parsed.error?.message ?? `PDFCraft responded ${status}`,\n status,\n parsed.error?.docs_url ?? null,\n );\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Renderer, type AsyncRenderInput, type RenderInput, type RendererOptions, } from './client.js';
|
|
2
|
+
export { PDFCraftError } from './errors.js';
|
|
3
|
+
export type { AsyncRenderAccepted, AsyncRenderRequest, Cookie, ErrorCode, Margin, OutputMode, RenderOptions, RenderRequest, RenderStatus, RenderStatusResponse, RenderUrlResponse, UsageResponse, WaitFor, WebhookPayload, } from './contract/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EACL,QAAQ,GAIT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC","sourcesContent":["// packages/sdk/src/index.ts\nexport {\n Renderer,\n type AsyncRenderInput,\n type RenderInput,\n type RendererOptions,\n} from './client.js';\nexport { PDFCraftError } from './errors.js';\nexport type {\n AsyncRenderAccepted,\n AsyncRenderRequest,\n Cookie,\n ErrorCode,\n Margin,\n OutputMode,\n RenderOptions,\n RenderRequest,\n RenderStatus,\n RenderStatusResponse,\n RenderUrlResponse,\n UsageResponse,\n WaitFor,\n WebhookPayload,\n} from './contract/index.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pdfcraft-dev/pdf",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "HTML to PDF in one call. The official PDFCraft SDK.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://pdfcraft.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/igaurav-dev/pdfcraft-dev.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"pdf",
|
|
13
|
+
"pdf-api",
|
|
14
|
+
"html-to-pdf",
|
|
15
|
+
"html-to-pdf-api",
|
|
16
|
+
"url-to-pdf",
|
|
17
|
+
"pdf-generation",
|
|
18
|
+
"headless-chrome",
|
|
19
|
+
"puppeteer",
|
|
20
|
+
"playwright",
|
|
21
|
+
"invoice",
|
|
22
|
+
"chromium"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/cjs/index.js",
|
|
26
|
+
"module": "./dist/esm/index.js",
|
|
27
|
+
"types": "./dist/esm/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/esm/index.d.ts",
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"require": "./dist/cjs/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/fixup.mjs",
|
|
46
|
+
"typecheck": "tsc -p tsconfig.esm.json --noEmit",
|
|
47
|
+
"clean": "rm -rf dist",
|
|
48
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "22.18.9",
|
|
52
|
+
"typescript": "5.9.3"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/igaurav-dev/pdfcraft-dev/issues"
|
|
59
|
+
}
|
|
60
|
+
}
|