gotenberg-client 0.0.0 → 0.0.2
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 +454 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/package.json +67 -0
- package/dist/src/client.d.ts +26 -0
- package/dist/src/client.js +231 -0
- package/dist/src/gotenberg.d.ts +39 -0
- package/dist/src/gotenberg.js +107 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/request.d.ts +22 -0
- package/dist/src/request.js +243 -0
- package/dist/src/types.d.ts +249 -0
- package/dist/src/types.js +9 -0
- package/package.json +65 -11
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
export type Result<T, E> = {
|
|
2
|
+
ok: true;
|
|
3
|
+
value: T;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: E;
|
|
7
|
+
};
|
|
8
|
+
export declare const Result: {
|
|
9
|
+
ok<T, E = never>(value: T): Result<T, E>;
|
|
10
|
+
err<T = never, E = unknown>(error: E): Result<T, E>;
|
|
11
|
+
};
|
|
12
|
+
export type GotenbergErrorType = "config" | "network" | "http" | "invalid-response";
|
|
13
|
+
export type GotenbergError = {
|
|
14
|
+
type: GotenbergErrorType;
|
|
15
|
+
message: string;
|
|
16
|
+
status?: number;
|
|
17
|
+
trace?: string | null;
|
|
18
|
+
details?: string;
|
|
19
|
+
cause?: unknown;
|
|
20
|
+
};
|
|
21
|
+
/** wraps async work to limit concurrency — matches the signature of p-limit's returned function */
|
|
22
|
+
export type GotenbergLimiter = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
23
|
+
export type GotenbergClientOptions = {
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
defaultHeaders?: Record<string, string>;
|
|
26
|
+
basicAuth?: {
|
|
27
|
+
username: string;
|
|
28
|
+
password: string;
|
|
29
|
+
};
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
/** optional concurrency limiter — all outgoing requests pass through this when set */
|
|
32
|
+
limiter?: GotenbergLimiter;
|
|
33
|
+
};
|
|
34
|
+
export type GotenbergBinaryResponse = {
|
|
35
|
+
blob: Blob;
|
|
36
|
+
trace: string | null;
|
|
37
|
+
contentType: string | null;
|
|
38
|
+
filename: string | null;
|
|
39
|
+
};
|
|
40
|
+
export type GotenbergHealth = {
|
|
41
|
+
status: "up" | "down";
|
|
42
|
+
details?: Record<string, {
|
|
43
|
+
status: "up" | "down";
|
|
44
|
+
timestamp?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
export type GotenbergFile = {
|
|
49
|
+
name: string;
|
|
50
|
+
data: Blob | ArrayBuffer | Uint8Array | string;
|
|
51
|
+
contentType?: string;
|
|
52
|
+
};
|
|
53
|
+
export type PdfOutputOptions = {
|
|
54
|
+
pdfa?: "PDF/A-1b" | "PDF/A-2b" | "PDF/A-3b";
|
|
55
|
+
pdfua?: boolean;
|
|
56
|
+
metadata?: Record<string, string>;
|
|
57
|
+
flatten?: boolean;
|
|
58
|
+
userPassword?: string;
|
|
59
|
+
ownerPassword?: string;
|
|
60
|
+
};
|
|
61
|
+
export type ChromiumPageOptions = {
|
|
62
|
+
singlePage?: boolean;
|
|
63
|
+
paperWidth?: number | string;
|
|
64
|
+
paperHeight?: number | string;
|
|
65
|
+
marginTop?: number | string;
|
|
66
|
+
marginBottom?: number | string;
|
|
67
|
+
marginLeft?: number | string;
|
|
68
|
+
marginRight?: number | string;
|
|
69
|
+
preferCssPageSize?: boolean;
|
|
70
|
+
generateDocumentOutline?: boolean;
|
|
71
|
+
generateTaggedPdf?: boolean;
|
|
72
|
+
printBackground?: boolean;
|
|
73
|
+
omitBackground?: boolean;
|
|
74
|
+
landscape?: boolean;
|
|
75
|
+
scale?: number | string;
|
|
76
|
+
nativePageRanges?: string;
|
|
77
|
+
};
|
|
78
|
+
export type ChromiumWaitOptions = {
|
|
79
|
+
waitDelay?: string;
|
|
80
|
+
waitForExpression?: string;
|
|
81
|
+
waitForSelector?: string;
|
|
82
|
+
};
|
|
83
|
+
export type ChromiumNetworkOptions = {
|
|
84
|
+
emulatedMediaType?: "screen" | "print";
|
|
85
|
+
userAgent?: string;
|
|
86
|
+
extraHttpHeaders?: Record<string, string>;
|
|
87
|
+
cookies?: Array<{
|
|
88
|
+
name: string;
|
|
89
|
+
value: string;
|
|
90
|
+
domain: string;
|
|
91
|
+
path?: string;
|
|
92
|
+
secure?: boolean;
|
|
93
|
+
httpOnly?: boolean;
|
|
94
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
95
|
+
}>;
|
|
96
|
+
failOnHttpStatusCodes?: number[];
|
|
97
|
+
failOnResourceHttpStatusCodes?: number[];
|
|
98
|
+
ignoreResourceHttpStatusDomains?: string[];
|
|
99
|
+
failOnResourceLoadingFailed?: boolean;
|
|
100
|
+
failOnConsoleExceptions?: boolean;
|
|
101
|
+
skipNetworkIdleEvent?: boolean;
|
|
102
|
+
};
|
|
103
|
+
export type ChromiumConvertOptions = ChromiumPageOptions & ChromiumWaitOptions & ChromiumNetworkOptions & PdfOutputOptions;
|
|
104
|
+
export type ScreenshotOptions = ChromiumWaitOptions & ChromiumNetworkOptions & {
|
|
105
|
+
width?: number;
|
|
106
|
+
height?: number;
|
|
107
|
+
clip?: boolean;
|
|
108
|
+
format?: "png" | "jpeg" | "webp";
|
|
109
|
+
quality?: number;
|
|
110
|
+
omitBackground?: boolean;
|
|
111
|
+
optimizeForSpeed?: boolean;
|
|
112
|
+
};
|
|
113
|
+
export type LibreOfficeOptions = {
|
|
114
|
+
landscape?: boolean;
|
|
115
|
+
nativePageRanges?: string;
|
|
116
|
+
password?: string;
|
|
117
|
+
merge?: boolean;
|
|
118
|
+
updateIndexes?: boolean;
|
|
119
|
+
skipEmptyPages?: boolean;
|
|
120
|
+
singlePageSheets?: boolean;
|
|
121
|
+
exportFormFields?: boolean;
|
|
122
|
+
allowDuplicateFieldNames?: boolean;
|
|
123
|
+
exportBookmarks?: boolean;
|
|
124
|
+
exportBookmarksToPdfDestination?: boolean;
|
|
125
|
+
exportPlaceholders?: boolean;
|
|
126
|
+
exportNotes?: boolean;
|
|
127
|
+
exportNotesPages?: boolean;
|
|
128
|
+
exportOnlyNotesPages?: boolean;
|
|
129
|
+
exportNotesInMargin?: boolean;
|
|
130
|
+
exportHiddenSlides?: boolean;
|
|
131
|
+
convertOooTargetToPdfTarget?: boolean;
|
|
132
|
+
exportLinksRelativeFsys?: boolean;
|
|
133
|
+
addOriginalDocumentAsStream?: boolean;
|
|
134
|
+
losslessImageCompression?: boolean;
|
|
135
|
+
quality?: number;
|
|
136
|
+
reduceImageResolution?: boolean;
|
|
137
|
+
maxImageResolution?: number;
|
|
138
|
+
} & PdfOutputOptions;
|
|
139
|
+
type CommonInput = {
|
|
140
|
+
trace?: string;
|
|
141
|
+
outputFilename?: string;
|
|
142
|
+
headers?: Record<string, string>;
|
|
143
|
+
signal?: AbortSignal;
|
|
144
|
+
};
|
|
145
|
+
export type ConvertUrlInput = CommonInput & {
|
|
146
|
+
url: string;
|
|
147
|
+
options?: ChromiumConvertOptions;
|
|
148
|
+
};
|
|
149
|
+
export type ConvertHtmlInput = CommonInput & {
|
|
150
|
+
indexHtml: string | GotenbergFile;
|
|
151
|
+
files?: GotenbergFile[];
|
|
152
|
+
options?: ChromiumConvertOptions;
|
|
153
|
+
};
|
|
154
|
+
export type ConvertMarkdownInput = CommonInput & {
|
|
155
|
+
indexHtml: string | GotenbergFile;
|
|
156
|
+
markdownFiles: GotenbergFile[];
|
|
157
|
+
files?: GotenbergFile[];
|
|
158
|
+
options?: ChromiumConvertOptions;
|
|
159
|
+
};
|
|
160
|
+
export type ScreenshotUrlInput = CommonInput & {
|
|
161
|
+
url: string;
|
|
162
|
+
options?: ScreenshotOptions;
|
|
163
|
+
};
|
|
164
|
+
export type ScreenshotHtmlInput = CommonInput & {
|
|
165
|
+
indexHtml: string | GotenbergFile;
|
|
166
|
+
files?: GotenbergFile[];
|
|
167
|
+
options?: ScreenshotOptions;
|
|
168
|
+
};
|
|
169
|
+
export type ScreenshotMarkdownInput = CommonInput & {
|
|
170
|
+
indexHtml: string | GotenbergFile;
|
|
171
|
+
markdownFiles: GotenbergFile[];
|
|
172
|
+
files?: GotenbergFile[];
|
|
173
|
+
options?: ScreenshotOptions;
|
|
174
|
+
};
|
|
175
|
+
export type ConvertOfficeInput = CommonInput & {
|
|
176
|
+
files: GotenbergFile[];
|
|
177
|
+
options?: LibreOfficeOptions;
|
|
178
|
+
embeds?: GotenbergFile[];
|
|
179
|
+
};
|
|
180
|
+
export type MergePdfInput = CommonInput & {
|
|
181
|
+
files: GotenbergFile[];
|
|
182
|
+
options?: PdfOutputOptions;
|
|
183
|
+
embeds?: GotenbergFile[];
|
|
184
|
+
};
|
|
185
|
+
export type SplitPdfInput = CommonInput & {
|
|
186
|
+
files: GotenbergFile[];
|
|
187
|
+
splitMode: "intervals" | "pages";
|
|
188
|
+
splitSpan: string;
|
|
189
|
+
splitUnify?: boolean;
|
|
190
|
+
options?: PdfOutputOptions;
|
|
191
|
+
embeds?: GotenbergFile[];
|
|
192
|
+
};
|
|
193
|
+
export type FlattenPdfInput = CommonInput & {
|
|
194
|
+
files: GotenbergFile[];
|
|
195
|
+
};
|
|
196
|
+
export type EncryptPdfInput = CommonInput & {
|
|
197
|
+
files: GotenbergFile[];
|
|
198
|
+
userPassword: string;
|
|
199
|
+
ownerPassword?: string;
|
|
200
|
+
};
|
|
201
|
+
export type EmbedFilesInput = CommonInput & {
|
|
202
|
+
files: GotenbergFile[];
|
|
203
|
+
embeds: GotenbergFile[];
|
|
204
|
+
};
|
|
205
|
+
export type ReadMetadataInput = {
|
|
206
|
+
files: GotenbergFile[];
|
|
207
|
+
trace?: string;
|
|
208
|
+
headers?: Record<string, string>;
|
|
209
|
+
signal?: AbortSignal;
|
|
210
|
+
};
|
|
211
|
+
export type WriteMetadataInput = CommonInput & {
|
|
212
|
+
files: GotenbergFile[];
|
|
213
|
+
metadata: Record<string, string>;
|
|
214
|
+
};
|
|
215
|
+
export type ConvertToPdfaInput = CommonInput & {
|
|
216
|
+
files: GotenbergFile[];
|
|
217
|
+
pdfa?: "PDF/A-1b" | "PDF/A-2b" | "PDF/A-3b";
|
|
218
|
+
pdfua?: boolean;
|
|
219
|
+
};
|
|
220
|
+
export type GotenbergClient = {
|
|
221
|
+
health: (signal?: AbortSignal) => Promise<Result<GotenbergHealth, GotenbergError>>;
|
|
222
|
+
version: (signal?: AbortSignal) => Promise<Result<string, GotenbergError>>;
|
|
223
|
+
convertUrl: (input: ConvertUrlInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
224
|
+
convertHtml: (input: ConvertHtmlInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
225
|
+
convertMarkdown: (input: ConvertMarkdownInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
226
|
+
screenshotUrl: (input: ScreenshotUrlInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
227
|
+
screenshotHtml: (input: ScreenshotHtmlInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
228
|
+
screenshotMarkdown: (input: ScreenshotMarkdownInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
229
|
+
convertOffice: (input: ConvertOfficeInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
230
|
+
mergePdf: (input: MergePdfInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
231
|
+
splitPdf: (input: SplitPdfInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
232
|
+
flattenPdf: (input: FlattenPdfInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
233
|
+
encryptPdf: (input: EncryptPdfInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
234
|
+
embedFiles: (input: EmbedFilesInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
235
|
+
readMetadata: (input: ReadMetadataInput) => Promise<Result<Record<string, Record<string, string>>, GotenbergError>>;
|
|
236
|
+
writeMetadata: (input: WriteMetadataInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
237
|
+
convertToPdfa: (input: ConvertToPdfaInput) => Promise<Result<GotenbergBinaryResponse, GotenbergError>>;
|
|
238
|
+
};
|
|
239
|
+
export type GotenbergLogger = {
|
|
240
|
+
info?: (message: string, meta?: Record<string, unknown>) => void;
|
|
241
|
+
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
242
|
+
error?: (message: string, meta?: Record<string, unknown>) => void;
|
|
243
|
+
};
|
|
244
|
+
export type GotenbergOptions = {
|
|
245
|
+
logger?: GotenbergLogger;
|
|
246
|
+
/** optional concurrency limiter shared across all requests from this instance */
|
|
247
|
+
limiter?: GotenbergLimiter;
|
|
248
|
+
};
|
|
249
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,13 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "gotenberg-client",
|
|
3
|
+
"description": "TypeScript client for the Gotenberg document conversion API.",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gotenberg",
|
|
7
|
+
"typescript",
|
|
8
|
+
"api-client",
|
|
9
|
+
"pdf",
|
|
10
|
+
"conversion"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"module": "dist/index.js",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"private": false,
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "zmzlois",
|
|
18
|
+
"email": "lois@normal-people.com",
|
|
19
|
+
"url": "https://github.com/zmzlois",
|
|
20
|
+
"x": "https://x.com/zmzlois"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/zmzlois/gotenberg-client#readme",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/zmzlois/gotenberg-client.git",
|
|
26
|
+
"directory": "."
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/zmzlois/gotenberg-client/issues"
|
|
30
|
+
},
|
|
31
|
+
"funding": {
|
|
32
|
+
"type": "github",
|
|
33
|
+
"url": "https://github.com/sponsors/zmzlois/dashboard"
|
|
34
|
+
},
|
|
35
|
+
"main": "dist/index.js",
|
|
36
|
+
"types": "dist/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"README.md",
|
|
46
|
+
"LICENSE"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"format": "biome check --write .",
|
|
50
|
+
"format:code": "biome format --write .",
|
|
51
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
52
|
+
"typecheck": "bunx tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"test": "bun test"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "^2.0.0",
|
|
61
|
+
"@types/bun": "latest",
|
|
62
|
+
"typescript": "^5"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"typescript": "^5"
|
|
66
|
+
}
|
|
13
67
|
}
|