@transloadit/node 4.1.9 → 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/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/tus.ts +3 -0
|
@@ -104,6 +104,11 @@ import {
|
|
|
104
104
|
interpolatableRobotDocumentOcrInstructionsSchema,
|
|
105
105
|
interpolatableRobotDocumentOcrInstructionsWithHiddenFieldsSchema,
|
|
106
106
|
} from './document-ocr.ts'
|
|
107
|
+
import {
|
|
108
|
+
meta as documentOptimizeMeta,
|
|
109
|
+
interpolatableRobotDocumentOptimizeInstructionsSchema,
|
|
110
|
+
interpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsSchema,
|
|
111
|
+
} from './document-optimize.ts'
|
|
107
112
|
import {
|
|
108
113
|
meta as documentSplitMeta,
|
|
109
114
|
interpolatableRobotDocumentSplitInstructionsSchema,
|
|
@@ -435,6 +440,7 @@ const robotStepsInstructions = [
|
|
|
435
440
|
interpolatableRobotDocumentConvertInstructionsSchema,
|
|
436
441
|
interpolatableRobotDocumentMergeInstructionsSchema,
|
|
437
442
|
interpolatableRobotDocumentOcrInstructionsSchema,
|
|
443
|
+
interpolatableRobotDocumentOptimizeInstructionsSchema,
|
|
438
444
|
interpolatableRobotFileReadInstructionsSchema,
|
|
439
445
|
interpolatableRobotDocumentSplitInstructionsSchema,
|
|
440
446
|
interpolatableRobotDocumentThumbsInstructionsSchema,
|
|
@@ -519,6 +525,7 @@ const robotStepsInstructionsWithHiddenFields = [
|
|
|
519
525
|
interpolatableRobotDocumentConvertInstructionsWithHiddenFieldsSchema,
|
|
520
526
|
interpolatableRobotDocumentMergeInstructionsWithHiddenFieldsSchema,
|
|
521
527
|
interpolatableRobotDocumentOcrInstructionsWithHiddenFieldsSchema,
|
|
528
|
+
interpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsSchema,
|
|
522
529
|
interpolatableRobotFileReadInstructionsWithHiddenFieldsSchema,
|
|
523
530
|
interpolatableRobotDocumentSplitInstructionsWithHiddenFieldsSchema,
|
|
524
531
|
interpolatableRobotDocumentThumbsInstructionsWithHiddenFieldsSchema,
|
|
@@ -632,6 +639,7 @@ export const robotsMeta = {
|
|
|
632
639
|
documentConvertMeta,
|
|
633
640
|
documentMergeMeta,
|
|
634
641
|
documentOcrMeta,
|
|
642
|
+
documentOptimizeMeta,
|
|
635
643
|
documentSplitMeta,
|
|
636
644
|
documentThumbsMeta,
|
|
637
645
|
dropboxImportMeta,
|
|
@@ -824,6 +832,12 @@ export type {
|
|
|
824
832
|
InterpolatableRobotDocumentOcrInstructionsWithHiddenFields,
|
|
825
833
|
InterpolatableRobotDocumentOcrInstructionsWithHiddenFieldsInput,
|
|
826
834
|
} from './document-ocr.ts'
|
|
835
|
+
export type {
|
|
836
|
+
InterpolatableRobotDocumentOptimizeInstructions,
|
|
837
|
+
InterpolatableRobotDocumentOptimizeInstructionsInput,
|
|
838
|
+
InterpolatableRobotDocumentOptimizeInstructionsWithHiddenFields,
|
|
839
|
+
InterpolatableRobotDocumentOptimizeInstructionsWithHiddenFieldsInput,
|
|
840
|
+
} from './document-optimize.ts'
|
|
827
841
|
export type {
|
|
828
842
|
InterpolatableRobotDocumentSplitInstructions,
|
|
829
843
|
InterpolatableRobotDocumentSplitInstructionsInput,
|
|
@@ -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
|
+
>
|
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,
|