ultrafastmov 0.0.0-stage → 0.1.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-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +133 -2
- package/dist/cjs/client.d.ts +167 -0
- package/dist/cjs/client.js +282 -0
- package/dist/cjs/errors.d.ts +102 -0
- package/dist/cjs/errors.js +163 -0
- package/dist/cjs/files.d.ts +31 -0
- package/dist/cjs/files.js +188 -0
- package/dist/cjs/http.d.ts +49 -0
- package/dist/cjs/http.js +140 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/results.d.ts +114 -0
- package/dist/cjs/results.js +284 -0
- package/dist/cjs/runtime.d.ts +31 -0
- package/dist/cjs/runtime.js +118 -0
- package/dist/cjs/schema.d.ts +2182 -0
- package/dist/cjs/schema.js +83 -0
- package/dist/cjs/types.d.ts +199 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/webhooks.d.ts +22 -0
- package/dist/cjs/webhooks.js +82 -0
- package/dist/esm/client.d.ts +167 -0
- package/dist/esm/client.js +277 -0
- package/dist/esm/errors.d.ts +102 -0
- package/dist/esm/errors.js +138 -0
- package/dist/esm/files.d.ts +31 -0
- package/dist/esm/files.js +181 -0
- package/dist/esm/http.d.ts +49 -0
- package/dist/esm/http.js +136 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/results.d.ts +114 -0
- package/dist/esm/results.js +274 -0
- package/dist/esm/runtime.d.ts +31 -0
- package/dist/esm/runtime.js +75 -0
- package/dist/esm/schema.d.ts +2182 -0
- package/dist/esm/schema.js +79 -0
- package/dist/esm/types.d.ts +199 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/webhooks.d.ts +22 -0
- package/dist/esm/webhooks.js +77 -0
- package/package.json +57 -4
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The ultrafast.mov contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ultrafastmov
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript client for ultrafast, the GPU video engine. A video is a JSON
|
|
4
|
+
document; the render service turns it into an MP4. This package talks to
|
|
5
|
+
ultrafast Cloud or your own `ultrafast serve`.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i ultrafastmov
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { Ultrafast } from "ultrafastmov";
|
|
13
|
+
|
|
14
|
+
const uf = new Ultrafast(); // ULTRAFAST_API_KEY
|
|
15
|
+
|
|
16
|
+
const doc = await uf.load("film.json");
|
|
17
|
+
const sheet = await uf.sheet(doc, { count: 9 });
|
|
18
|
+
const job = await uf.render(doc, {
|
|
19
|
+
webhook: "https://example.com/rendered",
|
|
20
|
+
});
|
|
21
|
+
console.log(job.id, job.status);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Node 18 or later, no dependencies. ESM and CommonJS.
|
|
25
|
+
|
|
26
|
+
## Your own server
|
|
27
|
+
|
|
28
|
+
`ultrafast serve` is the open-source render service for one machine with a
|
|
29
|
+
GPU.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
export ULTRAFAST_BASE_URL=http://localhost:8080
|
|
33
|
+
export ULTRAFAST_API_KEY=... # the server's key (it prints one at first start)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
or `new Ultrafast({ baseUrl: "http://localhost:8080", apiKey })`. Without
|
|
37
|
+
`ULTRAFAST_BASE_URL` the client uses ultrafast Cloud,
|
|
38
|
+
`https://api.ultrafast.mov`.
|
|
39
|
+
|
|
40
|
+
Everything here works against it except what only ultrafast Cloud has:
|
|
41
|
+
jobs and webhooks (`{ job }`, `{ webhook }`, `uf.jobs`), `{ uri }` output
|
|
42
|
+
to your own bucket, and `gs://`, `s3://` or `r2://` inputs. Those throw
|
|
43
|
+
`CloudOnlyError` (`e.feature` says which).
|
|
44
|
+
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const doc = await uf.new("vertical"); // a starter document; names from uf.templates()
|
|
49
|
+
|
|
50
|
+
const frame = await uf.frame(doc, { at: 2.5 }); // Image: bytes, contentType, save(), toBase64()
|
|
51
|
+
await (await uf.sheet(doc, { count: 9 })).save("sheet.png");
|
|
52
|
+
|
|
53
|
+
const { ok, issues } = await uf.check(doc);
|
|
54
|
+
for (const issue of await uf.review(doc, { safe: "social" })) {
|
|
55
|
+
console.log(issue.kind, issue.node, issue.from, issue.to, issue.message);
|
|
56
|
+
}
|
|
57
|
+
console.log(`${await uf.estimate(doc)}`); // $0.004, 8 s of 1080p
|
|
58
|
+
|
|
59
|
+
const render = await uf.render(doc); // stored; render.url is signed
|
|
60
|
+
await render.save("film.mp4"); // streamed, sha256 checked
|
|
61
|
+
const short = await uf.render(doc, { inline: true, range: [0, 3] });
|
|
62
|
+
|
|
63
|
+
const job = await uf.render(doc, { job: true }); // or { webhook } (Cloud)
|
|
64
|
+
const done = await job.wait(); // polls; throws the job's error if it failed
|
|
65
|
+
await uf.jobs.get(job.id);
|
|
66
|
+
|
|
67
|
+
const asset = await uf.upload("interview.mp4"); // or a Blob, File or bytes
|
|
68
|
+
// "src": asset.uri
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Every method that takes a document also takes the path of one.
|
|
72
|
+
|
|
73
|
+
## Local files
|
|
74
|
+
|
|
75
|
+
Documents can name local files: `"src": "footage/a.mp4"`, a font file, a
|
|
76
|
+
logo. Before sending a document the client uploads each one (once per
|
|
77
|
+
client, while its size and mtime stay the same) and sends a copy with
|
|
78
|
+
`asset://` references in their place; your object is not changed. Paths
|
|
79
|
+
resolve against the document's directory when it came from `uf.load`
|
|
80
|
+
(spread copies keep it), else the working directory. Font family names (`"Inter"`), inline face tracks
|
|
81
|
+
and `asset://`, `https://`, `data:` and (on Cloud) `gs://`, `s3://`, `r2://` values are
|
|
82
|
+
sent as they are. `uf.prepare(doc)` returns the copy without rendering.
|
|
83
|
+
|
|
84
|
+
Reading files needs Node. In edge runtimes, pass documents as objects whose
|
|
85
|
+
media are already references.
|
|
86
|
+
|
|
87
|
+
## Webhooks (Cloud)
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { verifyWebhook } from "ultrafastmov";
|
|
91
|
+
|
|
92
|
+
const { webhook_secret } = await uf.me();
|
|
93
|
+
|
|
94
|
+
// in your handler, with the raw body:
|
|
95
|
+
const job = await verifyWebhook(rawBody, req.headers["ultrafast-signature"], webhook_secret);
|
|
96
|
+
if (job.status === "rendered") console.log(job.receipt?.url);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
It checks the HMAC over the raw bytes and refuses deliveries whose
|
|
100
|
+
`sent_at` is more than 5 minutes off (`{ toleranceSec }`). It uses Web
|
|
101
|
+
Crypto, so it runs in Node and edge runtimes alike.
|
|
102
|
+
|
|
103
|
+
## Errors
|
|
104
|
+
|
|
105
|
+
Failures throw `UltrafastError` (or a subclass per API error code, such as
|
|
106
|
+
`InvalidDocumentError` with `issues`, `BusyError`, `OverLimitError`,
|
|
107
|
+
`CloudOnlyError` with `feature`), with
|
|
108
|
+
`status`, `code`, `message`, `retry` and the server's `body`. Requests the
|
|
109
|
+
server refused with `retry: true` (429, 503) are retried with backoff;
|
|
110
|
+
reads and other repeatable requests are also retried after a dropped
|
|
111
|
+
connection. A render is only resent after a dropped connection when it
|
|
112
|
+
writes to an `output.uri`, where the request's `attempt` ids make the
|
|
113
|
+
retry a replay.
|
|
114
|
+
|
|
115
|
+
A synchronous render holds the request open until the video is written,
|
|
116
|
+
and Node's fetch stops waiting for response headers after 5 minutes: on
|
|
117
|
+
Cloud, use a job for long renders.
|
|
118
|
+
|
|
119
|
+
## Types
|
|
120
|
+
|
|
121
|
+
`Document`, `Format`, `Node` (a union over `op` with each op's params),
|
|
122
|
+
`ParamsOf<"text">` and the animated forms (`keys`, `expr`, `wiggle`,
|
|
123
|
+
`oscillate`, `audio`) are generated from the document schema,
|
|
124
|
+
https://ultrafast.mov/schema/v1.json, by `scripts/gen-types.mjs`.
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install
|
|
130
|
+
npm test # builds, typechecks, runs the tests against an in-process fake server
|
|
131
|
+
npm run gen # regenerates src/schema.ts from schema/v1.json
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Licensed under Apache-2.0 OR MIT.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type FetchLike, Transport } from "./http.js";
|
|
2
|
+
import { Estimate, Image, Job, Render, Review } from "./results.js";
|
|
3
|
+
import type { Document } from "./schema.js";
|
|
4
|
+
import type { Asset, Attempt, CheckResult, Health, Me } from "./types.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.ultrafast.mov";
|
|
6
|
+
export interface UltrafastOptions {
|
|
7
|
+
/** Default: `ULTRAFAST_API_KEY`. */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/** Default: `ULTRAFAST_BASE_URL`, else ultrafast Cloud. A self-hosted server: `http://localhost:8080`. */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** A fetch implementation (default: the global one). */
|
|
12
|
+
fetch?: FetchLike;
|
|
13
|
+
/** Retries of requests that are safe to repeat (default 2). */
|
|
14
|
+
maxRetries?: number;
|
|
15
|
+
/** Extra headers on every request. */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/** A document, or the path of a document file (Node). */
|
|
19
|
+
export type DocumentInput = Document | string;
|
|
20
|
+
export interface RenderOptions {
|
|
21
|
+
/** The mp4 in the response (at most 32 MiB) instead of stored with a signed URL. */
|
|
22
|
+
inline?: boolean;
|
|
23
|
+
/** Create the video at this object in your own bucket (`s3://`, `r2://`, `gs://`); create-only. */
|
|
24
|
+
uri?: string;
|
|
25
|
+
/** The stored file's name (default `film.mp4`). */
|
|
26
|
+
name?: string;
|
|
27
|
+
codec?: "h264" | "hevc";
|
|
28
|
+
/** Bits per second; null for the format's default. */
|
|
29
|
+
bitrate?: number | null;
|
|
30
|
+
/** Mix the document's sound (default true). */
|
|
31
|
+
audio?: boolean;
|
|
32
|
+
/** `[from, to]` seconds of the document (default all of it). */
|
|
33
|
+
range?: [number, number] | null;
|
|
34
|
+
/** Ids that make retries safe; one is made up per call when missing. */
|
|
35
|
+
attempt?: Attempt;
|
|
36
|
+
/** The server stops when this passes (at most 10 minutes from receipt). */
|
|
37
|
+
deadline?: Date | string;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
export interface JobOptions extends Omit<RenderOptions, "inline"> {
|
|
41
|
+
/** POSTed the finished job, signed (see `verifyWebhook`). */
|
|
42
|
+
webhook?: string;
|
|
43
|
+
/** A job without a webhook: poll it with `job.wait()`. */
|
|
44
|
+
job?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface FrameOptions {
|
|
47
|
+
/** Seconds (default 0). */
|
|
48
|
+
at?: number;
|
|
49
|
+
format?: "png" | "jpeg";
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}
|
|
52
|
+
export interface SheetOptions {
|
|
53
|
+
/** Frames spread evenly over the document (default 9). */
|
|
54
|
+
count?: number;
|
|
55
|
+
/** Times in seconds, instead of `count`. */
|
|
56
|
+
at?: number[];
|
|
57
|
+
/** Frames per row (default 3, or 5 for a vertical document). */
|
|
58
|
+
columns?: number;
|
|
59
|
+
format?: "png" | "jpeg";
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}
|
|
62
|
+
export interface ReviewOptions {
|
|
63
|
+
/** `margin` (default, 4% of the frame) or `social` (clear of short-video apps' buttons and captions). */
|
|
64
|
+
safe?: "margin" | "social";
|
|
65
|
+
/** Seconds between text probes. */
|
|
66
|
+
step?: number;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
export interface UploadOptions {
|
|
70
|
+
filename?: string;
|
|
71
|
+
contentType?: string;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}
|
|
74
|
+
/** Something to upload: a file path (Node), a Blob or File, or bytes. */
|
|
75
|
+
export type UploadInput = string | Blob | Uint8Array | ArrayBuffer;
|
|
76
|
+
/** The jobs API. */
|
|
77
|
+
export declare class Jobs {
|
|
78
|
+
#private;
|
|
79
|
+
/** @internal */
|
|
80
|
+
constructor(client: Ultrafast, transport: Transport);
|
|
81
|
+
/** Starts a job (`POST /v1/jobs`). */
|
|
82
|
+
create(doc: DocumentInput, opts?: JobOptions): Promise<Job>;
|
|
83
|
+
get(id: string, opts?: {
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}): Promise<Job>;
|
|
86
|
+
/** The caller's jobs, most recent first. */
|
|
87
|
+
list(opts?: {
|
|
88
|
+
limit?: number;
|
|
89
|
+
signal?: AbortSignal;
|
|
90
|
+
}): Promise<Job[]>;
|
|
91
|
+
/** Cancels a queued job. */
|
|
92
|
+
cancel(id: string): Promise<Job>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A client of the ultrafast render service: ultrafast Cloud, or your own
|
|
96
|
+
* `ultrafast serve`.
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const uf = new Ultrafast(); // ULTRAFAST_API_KEY
|
|
100
|
+
* const doc = await uf.load("film.json");
|
|
101
|
+
* await (await uf.render(doc)).save("film.mp4");
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare class Ultrafast {
|
|
105
|
+
#private;
|
|
106
|
+
readonly baseUrl: string;
|
|
107
|
+
readonly jobs: Jobs;
|
|
108
|
+
constructor(opts?: UltrafastOptions);
|
|
109
|
+
/**
|
|
110
|
+
* Reads a document file (Node). Its relative paths resolve against its
|
|
111
|
+
* directory, kept under a symbol key: copies made with spread or
|
|
112
|
+
* `Object.assign` keep it, JSON does not see it.
|
|
113
|
+
*/
|
|
114
|
+
load(path: string | URL): Promise<Document>;
|
|
115
|
+
/** A starter document: `vertical`, `title`, `square`, `promo`, `explainer`, ... (see `templates()`). */
|
|
116
|
+
new(template: string, opts?: {
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}): Promise<Document>;
|
|
119
|
+
/** The names `new()` takes. */
|
|
120
|
+
templates(opts?: {
|
|
121
|
+
signal?: AbortSignal;
|
|
122
|
+
}): Promise<string[]>;
|
|
123
|
+
/**
|
|
124
|
+
* The document as it is sent: local files it names uploaded (once per
|
|
125
|
+
* client) and replaced by their asset:// uris, in a copy.
|
|
126
|
+
*/
|
|
127
|
+
prepare(doc: DocumentInput): Promise<Document>;
|
|
128
|
+
/** A video: a `Render` (stored, or `inline`), or with `webhook` or `job: true`, a `Job`. */
|
|
129
|
+
render(doc: DocumentInput, opts: JobOptions & ({
|
|
130
|
+
webhook: string;
|
|
131
|
+
} | {
|
|
132
|
+
job: true;
|
|
133
|
+
})): Promise<Job>;
|
|
134
|
+
render(doc: DocumentInput, opts?: RenderOptions & {
|
|
135
|
+
webhook?: undefined;
|
|
136
|
+
job?: false;
|
|
137
|
+
}): Promise<Render>;
|
|
138
|
+
render(doc: DocumentInput, opts?: (RenderOptions & {
|
|
139
|
+
webhook?: undefined;
|
|
140
|
+
job?: false;
|
|
141
|
+
}) | (JobOptions & {
|
|
142
|
+
inline?: undefined;
|
|
143
|
+
})): Promise<Render | Job>;
|
|
144
|
+
/** One frame, at `at` seconds. */
|
|
145
|
+
frame(doc: DocumentInput, opts?: FrameOptions): Promise<Image>;
|
|
146
|
+
/** A contact sheet: `count` frames over the film, or the times in `at`, each labeled with its time. */
|
|
147
|
+
sheet(doc: DocumentInput, opts?: SheetOptions): Promise<Image>;
|
|
148
|
+
/** Static and render-time problems, as `ultrafast check` reports them. */
|
|
149
|
+
check(doc: DocumentInput, opts?: {
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}): Promise<CheckResult>;
|
|
152
|
+
/** Renders the film and reports what a viewer would trip on. */
|
|
153
|
+
review(doc: DocumentInput, opts?: ReviewOptions): Promise<Review>;
|
|
154
|
+
/** What rendering will cost (free). */
|
|
155
|
+
estimate(doc: DocumentInput, opts?: {
|
|
156
|
+
range?: [number, number] | null;
|
|
157
|
+
signal?: AbortSignal;
|
|
158
|
+
}): Promise<Estimate>;
|
|
159
|
+
/** Uploads footage, an image, a font or audio; use the asset's `uri` in a document. */
|
|
160
|
+
upload(input: UploadInput, opts?: UploadOptions): Promise<Asset>;
|
|
161
|
+
/** An upload by id. */
|
|
162
|
+
asset(id: string): Promise<Asset>;
|
|
163
|
+
/** Who the key belongs to, and the webhook secret. */
|
|
164
|
+
me(): Promise<Me>;
|
|
165
|
+
/** The server's health (no key needed). */
|
|
166
|
+
health(): Promise<Health>;
|
|
167
|
+
}
|