@verygoodffmpeg/sdk 1.0.1 → 1.1.1
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 +10 -0
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -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.
|
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.1";
|
|
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
|
}
|
|
@@ -71,7 +81,8 @@ var VGF = class {
|
|
|
71
81
|
output_files: params.output_files,
|
|
72
82
|
ffmpeg_commands: params.ffmpeg_commands,
|
|
73
83
|
webhook_url: params.webhook_url,
|
|
74
|
-
machine: params.machine
|
|
84
|
+
machine: params.machine,
|
|
85
|
+
timeout_seconds: params.timeout_seconds
|
|
75
86
|
};
|
|
76
87
|
const res = await this._request(
|
|
77
88
|
"POST",
|
|
@@ -85,7 +96,8 @@ var VGF = class {
|
|
|
85
96
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
86
97
|
method,
|
|
87
98
|
headers: {
|
|
88
|
-
Authorization: `Bearer ${this.apiKey}
|
|
99
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
100
|
+
"User-Agent": this.userAgent
|
|
89
101
|
// "Content-Type": "application/json",
|
|
90
102
|
},
|
|
91
103
|
body: body != null ? JSON.stringify(body) : void 0
|
|
@@ -158,6 +170,7 @@ var Files = class {
|
|
|
158
170
|
var index_default = VGF;
|
|
159
171
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
172
|
0 && (module.exports = {
|
|
173
|
+
VERSION,
|
|
161
174
|
VGF,
|
|
162
175
|
VGFError
|
|
163
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.1\";\n\n/**\n * User-Agent sent with every API request.\n */\nexport const USER_AGENT = `verygoodffmpeg-sdk/${VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,MACzB;AAAA,MACA;AAAA,MAET,YAAY,QAAgB,MAAc;AACxC,cAAM,iBAAiB,MAAM,KAAK,IAAI,EAAE;AACxC,aAAK,OAAO;AACZ,aAAK,SAAS;AACd,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;ACVA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,UAAU;AAKhB,IAAM,aAAa,sBAAsB,OAAO;;;ADQvD;AAGA,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACE,QACA,SACA;AACA,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;AAClD,SAAK,SAAS;AACd,SAAK,UAAU,SAAS,WAAW;AAGnC,UAAM,SAAS,SAAS,iBAAiB,KAAK;AAC9C,SAAK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ANGED
|
@@ -12,6 +12,7 @@ interface Job {
|
|
|
12
12
|
input_files: Record<string, string>;
|
|
13
13
|
output_files: Record<string, string>;
|
|
14
14
|
webhook_url: string | null;
|
|
15
|
+
timeout_seconds: number | null;
|
|
15
16
|
total_input_bytes: number | null;
|
|
16
17
|
total_output_bytes: number | null;
|
|
17
18
|
}
|
|
@@ -21,6 +22,7 @@ interface RunParams {
|
|
|
21
22
|
ffmpeg_commands: string[];
|
|
22
23
|
webhook_url?: string;
|
|
23
24
|
machine?: "cpu" | "nvidia";
|
|
25
|
+
timeout_seconds?: number;
|
|
24
26
|
}
|
|
25
27
|
interface RunOptions {
|
|
26
28
|
/** Wait for the job to complete before returning. */
|
|
@@ -47,13 +49,20 @@ declare class VGFError extends Error {
|
|
|
47
49
|
constructor(status: number, body: string);
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Version of this SDK, mirrored from package.json at build time.
|
|
54
|
+
*/
|
|
55
|
+
declare const VERSION = "1.1.1";
|
|
56
|
+
|
|
50
57
|
declare class VGF {
|
|
51
58
|
readonly jobs: Jobs;
|
|
52
59
|
readonly files: Files;
|
|
53
60
|
private apiKey;
|
|
54
61
|
private baseUrl;
|
|
62
|
+
private userAgent;
|
|
55
63
|
constructor(apiKey: string, options?: {
|
|
56
64
|
baseUrl?: string;
|
|
65
|
+
userAgentSuffix?: string;
|
|
57
66
|
});
|
|
58
67
|
run(params: RunParams, options?: RunOptions): Promise<Job>;
|
|
59
68
|
/** @internal */
|
|
@@ -80,4 +89,4 @@ declare class Files {
|
|
|
80
89
|
upload(data: Buffer | Blob | ReadableStream | Uint8Array, contentType?: string): Promise<string>;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
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
|
@@ -12,6 +12,7 @@ interface Job {
|
|
|
12
12
|
input_files: Record<string, string>;
|
|
13
13
|
output_files: Record<string, string>;
|
|
14
14
|
webhook_url: string | null;
|
|
15
|
+
timeout_seconds: number | null;
|
|
15
16
|
total_input_bytes: number | null;
|
|
16
17
|
total_output_bytes: number | null;
|
|
17
18
|
}
|
|
@@ -21,6 +22,7 @@ interface RunParams {
|
|
|
21
22
|
ffmpeg_commands: string[];
|
|
22
23
|
webhook_url?: string;
|
|
23
24
|
machine?: "cpu" | "nvidia";
|
|
25
|
+
timeout_seconds?: number;
|
|
24
26
|
}
|
|
25
27
|
interface RunOptions {
|
|
26
28
|
/** Wait for the job to complete before returning. */
|
|
@@ -47,13 +49,20 @@ declare class VGFError extends Error {
|
|
|
47
49
|
constructor(status: number, body: string);
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Version of this SDK, mirrored from package.json at build time.
|
|
54
|
+
*/
|
|
55
|
+
declare const VERSION = "1.1.1";
|
|
56
|
+
|
|
50
57
|
declare class VGF {
|
|
51
58
|
readonly jobs: Jobs;
|
|
52
59
|
readonly files: Files;
|
|
53
60
|
private apiKey;
|
|
54
61
|
private baseUrl;
|
|
62
|
+
private userAgent;
|
|
55
63
|
constructor(apiKey: string, options?: {
|
|
56
64
|
baseUrl?: string;
|
|
65
|
+
userAgentSuffix?: string;
|
|
57
66
|
});
|
|
58
67
|
run(params: RunParams, options?: RunOptions): Promise<Job>;
|
|
59
68
|
/** @internal */
|
|
@@ -80,4 +89,4 @@ declare class Files {
|
|
|
80
89
|
upload(data: Buffer | Blob | ReadableStream | Uint8Array, contentType?: string): Promise<string>;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
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.1";
|
|
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
|
}
|
|
@@ -23,7 +30,8 @@ var VGF = class {
|
|
|
23
30
|
output_files: params.output_files,
|
|
24
31
|
ffmpeg_commands: params.ffmpeg_commands,
|
|
25
32
|
webhook_url: params.webhook_url,
|
|
26
|
-
machine: params.machine
|
|
33
|
+
machine: params.machine,
|
|
34
|
+
timeout_seconds: params.timeout_seconds
|
|
27
35
|
};
|
|
28
36
|
const res = await this._request(
|
|
29
37
|
"POST",
|
|
@@ -37,7 +45,8 @@ var VGF = class {
|
|
|
37
45
|
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
38
46
|
method,
|
|
39
47
|
headers: {
|
|
40
|
-
Authorization: `Bearer ${this.apiKey}
|
|
48
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
49
|
+
"User-Agent": this.userAgent
|
|
41
50
|
// "Content-Type": "application/json",
|
|
42
51
|
},
|
|
43
52
|
body: body != null ? JSON.stringify(body) : void 0
|
|
@@ -109,6 +118,7 @@ var Files = class {
|
|
|
109
118
|
};
|
|
110
119
|
var index_default = VGF;
|
|
111
120
|
export {
|
|
121
|
+
VERSION,
|
|
112
122
|
VGF,
|
|
113
123
|
VGFError,
|
|
114
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.1\";\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;\n }\n}\n\nexport default VGF;\n"],"mappings":";;;;;AAKO,IAAM,UAAU;AAKhB,IAAM,aAAa,sBAAsB,OAAO;;;ACWvD,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACE,QACA,SACA;AACA,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;AAClD,SAAK,SAAS;AACd,SAAK,UAAU,SAAS,WAAW;AAGnC,UAAM,SAAS,SAAS,iBAAiB,KAAK;AAC9C,SAAK,YAAY,SAAS,GAAG,UAAU,IAAI,MAAM,KAAK;AAEtD,SAAK,OAAO,IAAI,KAAK,IAAI;AACzB,SAAK,QAAQ,IAAI,MAAM,IAAI;AAAA,EAC7B;AAAA,EAEA,MAAM,IAAI,QAAmB,UAAsB,CAAC,GAAiB;AACnE,UAAM,KAAK,QAAQ,OAAO,eAAe;AACzC,UAAM,OAAO;AAAA,MACX,aAAa,OAAO;AAAA,MACpB,cAAc,OAAO;AAAA,MACrB,iBAAiB,OAAO;AAAA,MACxB,aAAa,OAAO;AAAA,MACpB,SAAS,OAAO;AAAA,MAChB,iBAAiB,OA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,IAAI;AAAA,EACb;AAAA,EAEA,MAAM,OAAO,IAA0B;AACrC,UAAM,MAAM,MAAM,KAAK,OAAO;AAAA,MAC5B;AAAA,MACA,SAAS,mBAAmB,EAAE,CAAC;AAAA,IACjC;AACA,WAAO,IAAI;AAAA,EACb;AACF;AAEA,IAAM,QAAN,MAAY;AAAA,EACV,YAAoB,QAAa;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,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.
|
|
3
|
+
"version": "1.1.1",
|
|
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
|
+
}
|