@transloadit/node 4.1.8 → 4.2.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/README.md +23 -1
- package/dist/Transloadit.d.ts +17 -5
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +206 -39
- package/dist/Transloadit.js.map +1 -1
- package/dist/alphalib/mcache.d.ts.map +1 -1
- package/dist/alphalib/mcache.js +22 -7
- package/dist/alphalib/mcache.js.map +1 -1
- package/dist/alphalib/types/assemblyReplay.d.ts +56 -0
- package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplayNotification.d.ts +56 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.d.ts +63 -57
- package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.js +9 -1
- package/dist/alphalib/types/assemblyStatus.js.map +1 -1
- package/dist/alphalib/types/assemblyUrls.d.ts +1 -1
- package/dist/alphalib/types/assemblyUrls.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyUrls.js.map +1 -1
- package/dist/alphalib/types/robots/_index.d.ts +608 -81
- package/dist/alphalib/types/robots/_index.d.ts.map +1 -1
- package/dist/alphalib/types/robots/_index.js +4 -0
- package/dist/alphalib/types/robots/_index.js.map +1 -1
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts +4 -4
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts.map +1 -1
- package/dist/alphalib/types/robots/_instructions-primitives.js +1 -0
- package/dist/alphalib/types/robots/_instructions-primitives.js.map +1 -1
- package/dist/alphalib/types/robots/document-optimize.d.ts +489 -0
- package/dist/alphalib/types/robots/document-optimize.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-optimize.js +151 -0
- package/dist/alphalib/types/robots/document-optimize.js.map +1 -0
- package/dist/alphalib/types/template.d.ts +1050 -174
- package/dist/alphalib/types/template.d.ts.map +1 -1
- package/dist/cli/commands/assemblies.d.ts.map +1 -1
- package/dist/cli/commands/assemblies.js +2 -2
- package/dist/cli/commands/assemblies.js.map +1 -1
- package/dist/tus.d.ts +2 -1
- package/dist/tus.d.ts.map +1 -1
- package/dist/tus.js +2 -1
- package/dist/tus.js.map +1 -1
- package/package.json +2 -2
- package/src/Transloadit.ts +279 -49
- package/src/alphalib/mcache.ts +26 -7
- package/src/alphalib/types/assemblyStatus.ts +9 -1
- package/src/alphalib/types/assemblyUrls.ts +2 -5
- package/src/alphalib/types/robots/_index.ts +14 -0
- package/src/alphalib/types/robots/_instructions-primitives.ts +1 -0
- package/src/alphalib/types/robots/document-optimize.ts +180 -0
- package/src/cli/commands/assemblies.ts +4 -2
- package/src/tus.ts +3 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { RobotMetaInput } from './_instructions-primitives.ts'
|
|
4
|
+
import { interpolateRobot, robotBase, robotUse } from './_instructions-primitives.ts'
|
|
5
|
+
|
|
6
|
+
export const meta: RobotMetaInput = {
|
|
7
|
+
allowed_for_url_transform: true,
|
|
8
|
+
bytescount: 1,
|
|
9
|
+
discount_factor: 1,
|
|
10
|
+
discount_pct: 0,
|
|
11
|
+
example_code: {
|
|
12
|
+
steps: {
|
|
13
|
+
optimized: {
|
|
14
|
+
robot: '/document/optimize',
|
|
15
|
+
use: ':original',
|
|
16
|
+
preset: 'ebook',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
example_code_description: 'Optimize PDF file size using the ebook preset:',
|
|
21
|
+
extended_description: `
|
|
22
|
+
This <dfn>Robot</dfn> reduces PDF file sizes. It recompresses images, subsets fonts, and applies various optimizations to reduce file size while maintaining acceptable quality.
|
|
23
|
+
|
|
24
|
+
## Quality Presets
|
|
25
|
+
|
|
26
|
+
The Robot supports four quality presets that control the trade-off between file size and quality:
|
|
27
|
+
|
|
28
|
+
| Preset | DPI | Use Case | Typical Savings |
|
|
29
|
+
|--------|-----|----------|-----------------|
|
|
30
|
+
| \`screen\` | 72 | Screen viewing, smallest files | ~86% |
|
|
31
|
+
| \`ebook\` | 150 | Good balance of quality/size | ~71% |
|
|
32
|
+
| \`printer\` | 300 | Print quality | Moderate |
|
|
33
|
+
| \`prepress\` | Highest | Press-ready, largest files | Minimal |
|
|
34
|
+
|
|
35
|
+
## Use Cases
|
|
36
|
+
|
|
37
|
+
- Reducing storage costs for archived documents
|
|
38
|
+
- Faster document delivery and download
|
|
39
|
+
- Meeting email attachment size limits
|
|
40
|
+
- Mobile-optimized document viewing
|
|
41
|
+
`,
|
|
42
|
+
minimum_charge: 2097152,
|
|
43
|
+
output_factor: 0.5,
|
|
44
|
+
override_lvl1: 'Document Processing',
|
|
45
|
+
purpose_sentence: 'reduces the file size of PDF documents',
|
|
46
|
+
purpose_verb: 'optimize',
|
|
47
|
+
purpose_word: 'optimize PDF',
|
|
48
|
+
purpose_words: 'Optimize PDF file size',
|
|
49
|
+
service_slug: 'document-processing',
|
|
50
|
+
slot_count: 10,
|
|
51
|
+
title: 'Reduce PDF file size',
|
|
52
|
+
typical_file_size_mb: 2.0,
|
|
53
|
+
typical_file_type: 'document',
|
|
54
|
+
name: 'DocumentOptimizeRobot',
|
|
55
|
+
priceFactor: 1,
|
|
56
|
+
queueSlotCount: 10,
|
|
57
|
+
minimumCharge: 2097152,
|
|
58
|
+
isAllowedForUrlTransform: true,
|
|
59
|
+
trackOutputFileSize: true,
|
|
60
|
+
isInternal: false,
|
|
61
|
+
removeJobResultFilesFromDiskRightAfterStoringOnS3: false,
|
|
62
|
+
stage: 'beta',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const robotDocumentOptimizeInstructionsSchema = robotBase
|
|
66
|
+
.merge(robotUse)
|
|
67
|
+
.extend({
|
|
68
|
+
robot: z.literal('/document/optimize').describe(`
|
|
69
|
+
This Robot reduces PDF file sizes. It recompresses images, subsets fonts, and applies various optimizations to reduce file size while maintaining acceptable quality.
|
|
70
|
+
|
|
71
|
+
## Quality Presets
|
|
72
|
+
|
|
73
|
+
The Robot supports four quality presets that control the trade-off between file size and quality:
|
|
74
|
+
|
|
75
|
+
| Preset | DPI | Use Case | Typical Savings |
|
|
76
|
+
|--------|-----|----------|-----------------|
|
|
77
|
+
| \`screen\` | 72 | Screen viewing, smallest files | ~86% |
|
|
78
|
+
| \`ebook\` | 150 | Good balance of quality/size | ~71% |
|
|
79
|
+
| \`printer\` | 300 | Print quality | Moderate |
|
|
80
|
+
| \`prepress\` | Highest | Press-ready, largest files | Minimal |
|
|
81
|
+
`),
|
|
82
|
+
preset: z
|
|
83
|
+
.enum(['screen', 'ebook', 'printer', 'prepress'])
|
|
84
|
+
.default('ebook')
|
|
85
|
+
.describe(`
|
|
86
|
+
The quality preset to use for optimization. Each preset provides a different balance between file size and quality:
|
|
87
|
+
|
|
88
|
+
- \`screen\` - Lowest quality, smallest file size. Best for screen viewing only. Images are downsampled to 72 DPI.
|
|
89
|
+
- \`ebook\` - Good balance of quality and size. Suitable for most purposes. Images are downsampled to 150 DPI.
|
|
90
|
+
- \`printer\` - High quality suitable for printing. Images are kept at 300 DPI.
|
|
91
|
+
- \`prepress\` - Highest quality for professional printing. Minimal compression applied.
|
|
92
|
+
`),
|
|
93
|
+
image_dpi: z
|
|
94
|
+
.number()
|
|
95
|
+
.int()
|
|
96
|
+
.min(36)
|
|
97
|
+
.max(600)
|
|
98
|
+
.optional()
|
|
99
|
+
.describe(`
|
|
100
|
+
Target DPI (dots per inch) for embedded images. When specified, this overrides the DPI setting from the preset.
|
|
101
|
+
|
|
102
|
+
Higher DPI values result in better image quality but larger file sizes. Lower values produce smaller files but may result in pixelated images when printed.
|
|
103
|
+
|
|
104
|
+
Common values:
|
|
105
|
+
- 72 - Screen viewing
|
|
106
|
+
- 150 - eBooks and general documents
|
|
107
|
+
- 300 - Print quality
|
|
108
|
+
- 600 - High-quality print
|
|
109
|
+
`),
|
|
110
|
+
compress_fonts: z
|
|
111
|
+
.boolean()
|
|
112
|
+
.default(true)
|
|
113
|
+
.describe(`
|
|
114
|
+
Whether to compress embedded fonts. When enabled, fonts are compressed to reduce file size.
|
|
115
|
+
`),
|
|
116
|
+
subset_fonts: z
|
|
117
|
+
.boolean()
|
|
118
|
+
.default(true)
|
|
119
|
+
.describe(`
|
|
120
|
+
Whether to subset embedded fonts, keeping only the glyphs that are actually used in the document. This can significantly reduce file size for documents that only use a small portion of a font's character set.
|
|
121
|
+
`),
|
|
122
|
+
remove_metadata: z
|
|
123
|
+
.boolean()
|
|
124
|
+
.default(false)
|
|
125
|
+
.describe(`
|
|
126
|
+
Whether to strip document metadata (title, author, keywords, etc.) from the PDF. This can provide a small reduction in file size and may be useful for privacy.
|
|
127
|
+
`),
|
|
128
|
+
linearize: z
|
|
129
|
+
.boolean()
|
|
130
|
+
.default(true)
|
|
131
|
+
.describe(`
|
|
132
|
+
Whether to linearize (optimize for Fast Web View) the output PDF. Linearized PDFs can begin displaying in a browser before they are fully downloaded, improving the user experience for web delivery.
|
|
133
|
+
`),
|
|
134
|
+
compatibility: z
|
|
135
|
+
.enum(['1.4', '1.5', '1.6', '1.7', '2.0'])
|
|
136
|
+
.default('1.7')
|
|
137
|
+
.describe(`
|
|
138
|
+
The PDF version compatibility level. Lower versions have broader compatibility but fewer features. Higher versions support more advanced features but may not open in older PDF readers.
|
|
139
|
+
|
|
140
|
+
- \`1.4\` - Acrobat 5 compatibility, most widely supported
|
|
141
|
+
- \`1.5\` - Acrobat 6 compatibility
|
|
142
|
+
- \`1.6\` - Acrobat 7 compatibility
|
|
143
|
+
- \`1.7\` - Acrobat 8+ compatibility (default)
|
|
144
|
+
- \`2.0\` - PDF 2.0 standard
|
|
145
|
+
`),
|
|
146
|
+
})
|
|
147
|
+
.strict()
|
|
148
|
+
|
|
149
|
+
export const robotDocumentOptimizeInstructionsWithHiddenFieldsSchema =
|
|
150
|
+
robotDocumentOptimizeInstructionsSchema.extend({
|
|
151
|
+
result: z
|
|
152
|
+
.union([z.literal('debug'), robotDocumentOptimizeInstructionsSchema.shape.result])
|
|
153
|
+
.optional(),
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
export type RobotDocumentOptimizeInstructions = z.infer<
|
|
157
|
+
typeof robotDocumentOptimizeInstructionsSchema
|
|
158
|
+
>
|
|
159
|
+
export type RobotDocumentOptimizeInstructionsWithHiddenFields = z.infer<
|
|
160
|
+
typeof robotDocumentOptimizeInstructionsWithHiddenFieldsSchema
|
|
161
|
+
>
|
|
162
|
+
|
|
163
|
+
export const interpolatableRobotDocumentOptimizeInstructionsSchema = interpolateRobot(
|
|
164
|
+
robotDocumentOptimizeInstructionsSchema,
|
|
165
|
+
)
|
|
166
|
+
export type InterpolatableRobotDocumentOptimizeInstructions =
|
|
167
|
+
InterpolatableRobotDocumentOptimizeInstructionsInput
|
|
168
|
+
|
|
169
|
+
export type InterpolatableRobotDocumentOptimizeInstructionsInput = z.input<
|
|
170
|
+
typeof interpolatableRobotDocumentOptimizeInstructionsSchema
|
|
171
|
+
>
|
|
172
|
+
|
|
173
|
+
export const interpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsSchema =
|
|
174
|
+
interpolateRobot(robotDocumentOptimizeInstructionsWithHiddenFieldsSchema)
|
|
175
|
+
export type InterpolatableRobotDocumentOptimizeInstructionsWithHiddenFields = z.infer<
|
|
176
|
+
typeof interpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsSchema
|
|
177
|
+
>
|
|
178
|
+
export type InterpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsInput = z.input<
|
|
179
|
+
typeof interpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsSchema
|
|
180
|
+
>
|
|
@@ -883,7 +883,8 @@ export async function create(
|
|
|
883
883
|
if (!firstKey) throw new Error('No results in assembly')
|
|
884
884
|
const firstResult = assembly.results[firstKey]
|
|
885
885
|
if (!firstResult || !firstResult[0]) throw new Error('No results in assembly')
|
|
886
|
-
const resulturl =
|
|
886
|
+
const resulturl =
|
|
887
|
+
(firstResult[0] as { ssl_url?: string; url?: string }).ssl_url ?? firstResult[0].url
|
|
887
888
|
|
|
888
889
|
if (outStream != null && resulturl && !superceded) {
|
|
889
890
|
outputctl.debug('DOWNLOADING')
|
|
@@ -983,7 +984,8 @@ export async function create(
|
|
|
983
984
|
if (asm.results && resolvedOutput != null) {
|
|
984
985
|
for (const [stepName, stepResults] of Object.entries(asm.results)) {
|
|
985
986
|
for (const stepResult of stepResults) {
|
|
986
|
-
const resultUrl =
|
|
987
|
+
const resultUrl =
|
|
988
|
+
(stepResult as { ssl_url?: string; url?: string }).ssl_url ?? stepResult.url
|
|
987
989
|
if (!resultUrl) continue
|
|
988
990
|
|
|
989
991
|
let outPath: string
|
package/src/tus.ts
CHANGED
|
@@ -22,6 +22,7 @@ interface SendTusRequestOptions {
|
|
|
22
22
|
uploadConcurrency: number
|
|
23
23
|
onProgress: (options: UploadProgress) => void
|
|
24
24
|
signal?: AbortSignal
|
|
25
|
+
uploadUrls?: Record<string, string>
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export async function sendTusRequest({
|
|
@@ -31,6 +32,7 @@ export async function sendTusRequest({
|
|
|
31
32
|
uploadConcurrency,
|
|
32
33
|
onProgress,
|
|
33
34
|
signal,
|
|
35
|
+
uploadUrls,
|
|
34
36
|
}: SendTusRequestOptions) {
|
|
35
37
|
const streamLabels = Object.keys(streamsMap)
|
|
36
38
|
|
|
@@ -133,6 +135,7 @@ export async function sendTusRequest({
|
|
|
133
135
|
|
|
134
136
|
const tusOptions: UploadOptions = {
|
|
135
137
|
endpoint: assembly.tus_url,
|
|
138
|
+
uploadUrl: uploadUrls?.[label],
|
|
136
139
|
metadata: {
|
|
137
140
|
assembly_url: assembly.assembly_ssl_url,
|
|
138
141
|
fieldname: label,
|