@verygoodffmpeg/sdk 1.1.0 → 1.1.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/README.md +34 -4
- package/dist/index.cjs +13 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ const job = await client.run(
|
|
|
24
24
|
"input.mp4": "https://example.com/input.mp4",
|
|
25
25
|
},
|
|
26
26
|
output_files: ["output.mp4"],
|
|
27
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
27
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
28
28
|
},
|
|
29
29
|
{ wait: true },
|
|
30
30
|
);
|
|
@@ -37,6 +37,16 @@ console.log(fetched.output_files); // { "output.mp4": "https://..." }
|
|
|
37
37
|
|
|
38
38
|
## Reference
|
|
39
39
|
|
|
40
|
+
### Client — `new VGF(apiKey, options?)`
|
|
41
|
+
|
|
42
|
+
Options: `baseUrl` overrides the API host, and `userAgentSuffix` appends a product token to the SDK's `User-Agent` (sent as `verygoodffmpeg-sdk/<version> <suffix>`).
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const client = new VGF(process.env.VGF_API_KEY, {
|
|
46
|
+
userAgentSuffix: "my-app/2.0",
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
40
50
|
### Create a job — `client.run(params, options?)`
|
|
41
51
|
|
|
42
52
|
Submits an FFmpeg job. Pass `{ wait: true }` to block until the job reaches a terminal state.
|
|
@@ -46,7 +56,7 @@ const job = await client.run(
|
|
|
46
56
|
{
|
|
47
57
|
input_files: { "input.mp4": "https://example.com/input.mp4" },
|
|
48
58
|
output_files: ["output.mp4"],
|
|
49
|
-
ffmpeg_commands: ["-i input.mp4 -c:v libx264 output.mp4"],
|
|
59
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -c:v libx264 outputs/output.mp4"],
|
|
50
60
|
webhook_url: "https://example.com/webhook", // optional
|
|
51
61
|
machine: "nvidia", // optional: "cpu" | "nvidia"
|
|
52
62
|
},
|
|
@@ -54,6 +64,8 @@ const job = await client.run(
|
|
|
54
64
|
);
|
|
55
65
|
```
|
|
56
66
|
|
|
67
|
+
See [Running Commands](https://verygoodffmpeg.com/docs/basics/running-commands) for how commands are executed.
|
|
68
|
+
|
|
57
69
|
### Get a job — `client.jobs.get(id)`
|
|
58
70
|
|
|
59
71
|
Fetches a single job by ID.
|
|
@@ -94,7 +106,7 @@ const url = await client.files.upload(readFileSync("input.mp4"), "video/mp4");
|
|
|
94
106
|
const job = await client.run({
|
|
95
107
|
input_files: { "input.mp4": url },
|
|
96
108
|
output_files: ["output.mp4"],
|
|
97
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
109
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
98
110
|
});
|
|
99
111
|
```
|
|
100
112
|
|
|
@@ -120,10 +132,28 @@ await fetch(upload_url, {
|
|
|
120
132
|
const job = await client.run({
|
|
121
133
|
input_files: { "input.mp4": download_url },
|
|
122
134
|
output_files: ["output.mp4"],
|
|
123
|
-
ffmpeg_commands: ["-i input.mp4 -vf scale=1280:720 output.mp4"],
|
|
135
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vf scale=1280:720 outputs/output.mp4"],
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Referencing files in commands
|
|
140
|
+
|
|
141
|
+
Every job runs in a workspace with two directories. Each entry in `input_files` is downloaded into `inputs` under its key name, and every file your commands write to `outputs` that is listed in `output_files` is uploaded and returned as a download URL.
|
|
142
|
+
|
|
143
|
+
Reference files with plain paths — `inputs/<name>` to read, `outputs/<name>` to write:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
await client.run({
|
|
147
|
+
input_files: { "input.mp4": "https://example.com/video.mp4" },
|
|
148
|
+
output_files: ["output.wav"],
|
|
149
|
+
ffmpeg_commands: ["-i inputs/input.mp4 -vn outputs/output.wav"],
|
|
124
150
|
});
|
|
125
151
|
```
|
|
126
152
|
|
|
153
|
+
Paths work anywhere in the command string, including inside `-filter_complex`, and they are real paths on the worker, so the command is the same one you would run locally.
|
|
154
|
+
|
|
155
|
+
See [File Reference Styles](https://verygoodffmpeg.com/docs/advanced/file-reference-styles) for more.
|
|
156
|
+
|
|
127
157
|
## Complete examples
|
|
128
158
|
|
|
129
159
|
See the [`examples/`](./examples) folder for minimal runnable examples:
|
package/dist/index.cjs
CHANGED
|
@@ -45,11 +45,18 @@ var init_error = __esm({
|
|
|
45
45
|
// src/index.ts
|
|
46
46
|
var index_exports = {};
|
|
47
47
|
__export(index_exports, {
|
|
48
|
+
VERSION: () => VERSION,
|
|
48
49
|
VGF: () => VGF,
|
|
49
50
|
VGFError: () => VGFError,
|
|
50
51
|
default: () => index_default
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(index_exports);
|
|
54
|
+
|
|
55
|
+
// src/version.ts
|
|
56
|
+
var VERSION = "1.1.2";
|
|
57
|
+
var USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
53
60
|
init_error();
|
|
54
61
|
var BASE_URL = "https://verygoodffmpeg.com/api";
|
|
55
62
|
var VGF = class {
|
|
@@ -57,10 +64,13 @@ var VGF = class {
|
|
|
57
64
|
files;
|
|
58
65
|
apiKey;
|
|
59
66
|
baseUrl;
|
|
67
|
+
userAgent;
|
|
60
68
|
constructor(apiKey, options) {
|
|
61
69
|
if (!apiKey) throw new Error("API key is required");
|
|
62
70
|
this.apiKey = apiKey;
|
|
63
71
|
this.baseUrl = options?.baseUrl ?? BASE_URL;
|
|
72
|
+
const suffix = options?.userAgentSuffix?.trim();
|
|
73
|
+
this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;
|
|
64
74
|
this.jobs = new Jobs(this);
|
|
65
75
|
this.files = new Files(this);
|
|
66
76
|
}
|
|
@@ -86,7 +96,8 @@ var VGF = class {
|
|
|
86
96
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
87
97
|
method,
|
|
88
98
|
headers: {
|
|
89
|
-
Authorization: `Bearer ${this.apiKey}
|
|
99
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
100
|
+
"User-Agent": this.userAgent
|
|
90
101
|
// "Content-Type": "application/json",
|
|
91
102
|
},
|
|
92
103
|
body: body != null ? JSON.stringify(body) : void 0
|
|
@@ -159,6 +170,7 @@ var Files = class {
|
|
|
159
170
|
var index_default = VGF;
|
|
160
171
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
172
|
0 && (module.exports = {
|
|
173
|
+
VERSION,
|
|
162
174
|
VGF,
|
|
163
175
|
VGFError
|
|
164
176
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts","../src/index.ts"],"sourcesContent":["export class VGFError extends Error {\n readonly status: number;\n readonly body: string;\n\n constructor(status: number, body: string) {\n super(`VGF API error ${status}: ${body}`);\n this.name = \"VGFError\";\n this.status = status;\n this.body = body;\n }\n}\n","import type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n\n constructor(apiKey: string
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/index.ts","../src/version.ts"],"sourcesContent":["export class VGFError extends Error {\n readonly status: number;\n readonly body: string;\n\n constructor(status: number, body: string) {\n super(`VGF API error ${status}: ${body}`);\n this.name = \"VGFError\";\n this.status = status;\n this.body = body;\n }\n}\n","import { USER_AGENT } from \"./version.js\";\nimport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\nexport { VERSION } from \"./version.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n private userAgent: string;\n\n constructor(\n apiKey: string,\n options?: { baseUrl?: string; userAgentSuffix?: string },\n ) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\n\n // callers building on top of the SDK may append their own product token\n const suffix = options?.userAgentSuffix?.trim();\n this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;\n\n this.jobs = new Jobs(this);\n this.files = new Files(this);\n }\n\n async run(params: RunParams, options: RunOptions = {}): Promise<Job> {\n const qs = options.wait ? \"?wait=true\" : \"\";\n const body = {\n input_files: params.input_files,\n output_files: params.output_files,\n ffmpeg_commands: params.ffmpeg_commands,\n webhook_url: params.webhook_url,\n machine: params.machine,\n timeout_seconds: params.timeout_seconds,\n };\n const res = await this._request<{ data: Job }>(\n \"POST\",\n `/ffmpeg${qs}`,\n body,\n );\n return res.data;\n }\n\n /** @internal */\n async _request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"User-Agent\": this.userAgent,\n // \"Content-Type\": \"application/json\",\n },\n body: body != null ? JSON.stringify(body) : undefined,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, text);\n }\n\n return res.json() as Promise<T>;\n }\n}\n\nclass Jobs {\n constructor(private client: VGF) {}\n\n async list(\n params: ListJobsParams = {},\n ): Promise<{ data: Job[]; pagingParams: PagingParams }> {\n const qs = new URLSearchParams();\n if (params.limit != null) qs.set(\"limit\", String(params.limit));\n if (params.offset != null) qs.set(\"offset\", String(params.offset));\n const query = qs.size ? `?${qs}` : \"\";\n return this.client._request(\"GET\", `/jobs${query}`);\n }\n\n async get(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"GET\",\n `/jobs/${encodeURIComponent(id)}`,\n );\n return res.data;\n }\n\n async cancel(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"POST\",\n `/jobs/${encodeURIComponent(id)}/cancel`,\n );\n return res.data;\n }\n}\n\nclass Files {\n constructor(private client: VGF) {}\n\n async prepareUpload(): Promise<TmpFile> {\n const res = await this.client._request<{ data: TmpFile }>(\n \"POST\",\n \"/tmp-file\",\n );\n return res.data;\n }\n\n /**\n * Uploads a file to temporary storage and returns the download URL,\n * which can be used as an input_files value in a job.\n */\n async upload(\n data: Buffer | Blob | ReadableStream | Uint8Array,\n contentType = \"application/octet-stream\",\n ): Promise<string> {\n const { upload_url, download_url } = await this.prepareUpload();\n const res = await fetch(upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: data as BodyInit,\n });\n if (!res.ok) {\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, `File upload failed: ${res.statusText}`);\n }\n return download_url;\n }\n}\n\nexport default VGF;\n","// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.2\";\n\n/**\n * User-Agent sent with every API request.\n */\nexport const USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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AAa;AAAb;AAAA,EAAc;AAAA,EAAd;AAAA,EAEpB,MAAM,gBAAkC;AACtC,UAAM,MAAM,MAAM,KAAK,OAAO;AAAA,MAC5B;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OACJ,MACA,cAAc,4BACG;AACjB,UAAM,EAAE,YAAY,aAAa,IAAI,MAAM,KAAK,cAAc;AAC9D,UAAM,MAAM,MAAM,MAAM,YAAY;AAAA,MAClC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,YAAY;AAAA,MACvC,MAAM;AAAA,IACR,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,EAAE,UAAAA,UAAS,IAAI,MAAM;AAC3B,YAAM,IAAIA,UAAS,IAAI,QAAQ,uBAAuB,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,gBAAQ;","names":["VGFError"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -49,13 +49,20 @@ declare class VGFError extends Error {
|
|
|
49
49
|
constructor(status: number, body: string);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Version of this SDK, mirrored from package.json at build time.
|
|
54
|
+
*/
|
|
55
|
+
declare const VERSION = "1.1.2";
|
|
56
|
+
|
|
52
57
|
declare class VGF {
|
|
53
58
|
readonly jobs: Jobs;
|
|
54
59
|
readonly files: Files;
|
|
55
60
|
private apiKey;
|
|
56
61
|
private baseUrl;
|
|
62
|
+
private userAgent;
|
|
57
63
|
constructor(apiKey: string, options?: {
|
|
58
64
|
baseUrl?: string;
|
|
65
|
+
userAgentSuffix?: string;
|
|
59
66
|
});
|
|
60
67
|
run(params: RunParams, options?: RunOptions): Promise<Job>;
|
|
61
68
|
/** @internal */
|
|
@@ -82,4 +89,4 @@ declare class Files {
|
|
|
82
89
|
upload(data: Buffer | Blob | ReadableStream | Uint8Array, contentType?: string): Promise<string>;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
export { type Job, type ListJobsParams, type PagingParams, type RunOptions, type RunParams, type TmpFile, VGF, VGFError, VGF as default };
|
|
92
|
+
export { type Job, type ListJobsParams, type PagingParams, type RunOptions, type RunParams, type TmpFile, VERSION, VGF, VGFError, VGF as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,13 +49,20 @@ declare class VGFError extends Error {
|
|
|
49
49
|
constructor(status: number, body: string);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Version of this SDK, mirrored from package.json at build time.
|
|
54
|
+
*/
|
|
55
|
+
declare const VERSION = "1.1.2";
|
|
56
|
+
|
|
52
57
|
declare class VGF {
|
|
53
58
|
readonly jobs: Jobs;
|
|
54
59
|
readonly files: Files;
|
|
55
60
|
private apiKey;
|
|
56
61
|
private baseUrl;
|
|
62
|
+
private userAgent;
|
|
57
63
|
constructor(apiKey: string, options?: {
|
|
58
64
|
baseUrl?: string;
|
|
65
|
+
userAgentSuffix?: string;
|
|
59
66
|
});
|
|
60
67
|
run(params: RunParams, options?: RunOptions): Promise<Job>;
|
|
61
68
|
/** @internal */
|
|
@@ -82,4 +89,4 @@ declare class Files {
|
|
|
82
89
|
upload(data: Buffer | Blob | ReadableStream | Uint8Array, contentType?: string): Promise<string>;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
export { type Job, type ListJobsParams, type PagingParams, type RunOptions, type RunParams, type TmpFile, VGF, VGFError, VGF as default };
|
|
92
|
+
export { type Job, type ListJobsParams, type PagingParams, type RunOptions, type RunParams, type TmpFile, VERSION, VGF, VGFError, VGF as default };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,10 @@ import {
|
|
|
2
2
|
VGFError
|
|
3
3
|
} from "./chunk-DSE47ZPQ.js";
|
|
4
4
|
|
|
5
|
+
// src/version.ts
|
|
6
|
+
var VERSION = "1.1.2";
|
|
7
|
+
var USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;
|
|
8
|
+
|
|
5
9
|
// src/index.ts
|
|
6
10
|
var BASE_URL = "https://verygoodffmpeg.com/api";
|
|
7
11
|
var VGF = class {
|
|
@@ -9,10 +13,13 @@ var VGF = class {
|
|
|
9
13
|
files;
|
|
10
14
|
apiKey;
|
|
11
15
|
baseUrl;
|
|
16
|
+
userAgent;
|
|
12
17
|
constructor(apiKey, options) {
|
|
13
18
|
if (!apiKey) throw new Error("API key is required");
|
|
14
19
|
this.apiKey = apiKey;
|
|
15
20
|
this.baseUrl = options?.baseUrl ?? BASE_URL;
|
|
21
|
+
const suffix = options?.userAgentSuffix?.trim();
|
|
22
|
+
this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;
|
|
16
23
|
this.jobs = new Jobs(this);
|
|
17
24
|
this.files = new Files(this);
|
|
18
25
|
}
|
|
@@ -38,7 +45,8 @@ var VGF = class {
|
|
|
38
45
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
39
46
|
method,
|
|
40
47
|
headers: {
|
|
41
|
-
Authorization: `Bearer ${this.apiKey}
|
|
48
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
49
|
+
"User-Agent": this.userAgent
|
|
42
50
|
// "Content-Type": "application/json",
|
|
43
51
|
},
|
|
44
52
|
body: body != null ? JSON.stringify(body) : void 0
|
|
@@ -110,6 +118,7 @@ var Files = class {
|
|
|
110
118
|
};
|
|
111
119
|
var index_default = VGF;
|
|
112
120
|
export {
|
|
121
|
+
VERSION,
|
|
113
122
|
VGF,
|
|
114
123
|
VGFError,
|
|
115
124
|
index_default as default
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n\n constructor(apiKey: string
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/index.ts"],"sourcesContent":["// Generated by scripts/generate-version.mjs. Do not edit.\n\n/**\n * Version of this SDK, mirrored from package.json at build time.\n */\nexport const VERSION = \"1.1.2\";\n\n/**\n * User-Agent sent with every API request.\n */\nexport const USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;\n","import { USER_AGENT } from \"./version.js\";\nimport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n} from \"./types.js\";\n\nexport type {\n Job,\n RunParams,\n RunOptions,\n ListJobsParams,\n PagingParams,\n TmpFile,\n};\nexport { VGFError } from \"./error.js\";\nexport { VERSION } from \"./version.js\";\n\nconst BASE_URL = \"https://verygoodffmpeg.com/api\";\n\nexport class VGF {\n readonly jobs: Jobs;\n readonly files: Files;\n\n private apiKey: string;\n private baseUrl: string;\n private userAgent: string;\n\n constructor(\n apiKey: string,\n options?: { baseUrl?: string; userAgentSuffix?: string },\n ) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\n\n // callers building on top of the SDK may append their own product token\n const suffix = options?.userAgentSuffix?.trim();\n this.userAgent = suffix ? `${USER_AGENT} ${suffix}` : USER_AGENT;\n\n this.jobs = new Jobs(this);\n this.files = new Files(this);\n }\n\n async run(params: RunParams, options: RunOptions = {}): Promise<Job> {\n const qs = options.wait ? \"?wait=true\" : \"\";\n const body = {\n input_files: params.input_files,\n output_files: params.output_files,\n ffmpeg_commands: params.ffmpeg_commands,\n webhook_url: params.webhook_url,\n machine: params.machine,\n timeout_seconds: params.timeout_seconds,\n };\n const res = await this._request<{ data: Job }>(\n \"POST\",\n `/ffmpeg${qs}`,\n body,\n );\n return res.data;\n }\n\n /** @internal */\n async _request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"User-Agent\": this.userAgent,\n // \"Content-Type\": \"application/json\",\n },\n body: body != null ? JSON.stringify(body) : undefined,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, text);\n }\n\n return res.json() as Promise<T>;\n }\n}\n\nclass Jobs {\n constructor(private client: VGF) {}\n\n async list(\n params: ListJobsParams = {},\n ): Promise<{ data: Job[]; pagingParams: PagingParams }> {\n const qs = new URLSearchParams();\n if (params.limit != null) qs.set(\"limit\", String(params.limit));\n if (params.offset != null) qs.set(\"offset\", String(params.offset));\n const query = qs.size ? `?${qs}` : \"\";\n return this.client._request(\"GET\", `/jobs${query}`);\n }\n\n async get(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"GET\",\n `/jobs/${encodeURIComponent(id)}`,\n );\n return res.data;\n }\n\n async cancel(id: string): Promise<Job> {\n const res = await this.client._request<{ data: Job }>(\n \"POST\",\n `/jobs/${encodeURIComponent(id)}/cancel`,\n );\n return res.data;\n }\n}\n\nclass Files {\n constructor(private client: VGF) {}\n\n async prepareUpload(): Promise<TmpFile> {\n const res = await this.client._request<{ data: TmpFile }>(\n \"POST\",\n \"/tmp-file\",\n );\n return res.data;\n }\n\n /**\n * Uploads a file to temporary storage and returns the download URL,\n * which can be used as an input_files value in a job.\n */\n async upload(\n data: Buffer | Blob | ReadableStream | Uint8Array,\n contentType = \"application/octet-stream\",\n ): Promise<string> {\n const { upload_url, download_url } = await this.prepareUpload();\n const res = await fetch(upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: data as BodyInit,\n });\n if (!res.ok) {\n const { VGFError } = await import(\"./error.js\");\n throw new VGFError(res.status, `File upload failed: ${res.statusText}`);\n }\n return download_url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,MAAM,KAAK,cAAc;AAC9D,UAAM,MAAM,MAAM,MAAM,YAAY;AAAA,MAClC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,YAAY;AAAA,MACvC,MAAM;AAAA,IACR,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,EAAE,UAAAA,UAAS,IAAI,MAAM,OAAO,qBAAY;AAC9C,YAAM,IAAIA,UAAS,IAAI,QAAQ,uBAAuB,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,gBAAQ;","names":["VGFError"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verygoodffmpeg/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "TypeScript SDK for the Very Good FFmpeg API",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/verygoodffmpeg/Very-Good-FFmpeg-Typescript-SDK/issues"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
|
+
"packageManager": "pnpm@11.0.7",
|
|
14
15
|
"main": "./dist/index.cjs",
|
|
15
16
|
"module": "./dist/index.js",
|
|
16
17
|
"types": "./dist/index.d.ts",
|
|
@@ -29,6 +30,13 @@
|
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|
|
31
32
|
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"generate:version": "node scripts/generate-version.mjs",
|
|
35
|
+
"build": "pnpm generate:version && tsup",
|
|
36
|
+
"dev": "pnpm generate:version && tsup --watch",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"prepublishOnly": "pnpm build"
|
|
39
|
+
},
|
|
32
40
|
"publishConfig": {
|
|
33
41
|
"access": "public",
|
|
34
42
|
"registry": "https://registry.npmjs.org"
|
|
@@ -36,16 +44,16 @@
|
|
|
36
44
|
"engines": {
|
|
37
45
|
"node": ">=18"
|
|
38
46
|
},
|
|
47
|
+
"pnpm": {
|
|
48
|
+
"onlyBuiltDependencies": [
|
|
49
|
+
"esbuild"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
39
52
|
"devDependencies": {
|
|
40
53
|
"@types/node": "^25.8.0",
|
|
41
54
|
"dotenv": "^17.4.2",
|
|
42
55
|
"tsup": "^8.5.1",
|
|
43
56
|
"typescript": "^5.4.0",
|
|
44
57
|
"vitest": "^4.1.6"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "tsup",
|
|
48
|
-
"dev": "tsup --watch",
|
|
49
|
-
"test": "vitest run"
|
|
50
58
|
}
|
|
51
|
-
}
|
|
59
|
+
}
|