@verygoodffmpeg/sdk 1.0.0 → 1.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/README.md +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ TypeScript SDK for the Very Good FFmpeg API — run FFmpeg jobs in the cloud.
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@verygoodffmpeg/sdk)
|
|
6
6
|
|
|
7
|
-
[Homepage](https://verygoodffmpeg.com) · [API Docs](https://verygoodffmpeg.com/docs)
|
|
7
|
+
[Homepage](https://verygoodffmpeg.com) · [API Docs](https://verygoodffmpeg.com/docs) · [GitHub](https://github.com/verygoodffmpeg/Very-Good-FFmpeg-Typescript-SDK)
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
package/dist/index.cjs
CHANGED
|
@@ -71,7 +71,8 @@ var VGF = class {
|
|
|
71
71
|
output_files: params.output_files,
|
|
72
72
|
ffmpeg_commands: params.ffmpeg_commands,
|
|
73
73
|
webhook_url: params.webhook_url,
|
|
74
|
-
machine: params.machine
|
|
74
|
+
machine: params.machine,
|
|
75
|
+
timeout_seconds: params.timeout_seconds
|
|
75
76
|
};
|
|
76
77
|
const res = await this._request(
|
|
77
78
|
"POST",
|
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, options?: { baseUrl?: string }) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\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 };\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 // \"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":";;;;;;;;;;;;;;;;;;;;;;;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;AAiBA;AAEA,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,SAAgC;AAC1D,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;AAClD,SAAK,SAAS;AACd,SAAK,UAAU,SAAS,WAAW;AACnC,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,
|
|
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, options?: { baseUrl?: string }) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\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 // \"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":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,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AM,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
|
@@ -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. */
|
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. */
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,8 @@ var VGF = class {
|
|
|
23
23
|
output_files: params.output_files,
|
|
24
24
|
ffmpeg_commands: params.ffmpeg_commands,
|
|
25
25
|
webhook_url: params.webhook_url,
|
|
26
|
-
machine: params.machine
|
|
26
|
+
machine: params.machine,
|
|
27
|
+
timeout_seconds: params.timeout_seconds
|
|
27
28
|
};
|
|
28
29
|
const res = await this._request(
|
|
29
30
|
"POST",
|
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, options?: { baseUrl?: string }) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\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 };\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 // \"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":";;;;;AAmBA,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,SAAgC;AAC1D,QAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;AAClD,SAAK,SAAS;AACd,SAAK,UAAU,SAAS,WAAW;AACnC,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,
|
|
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, options?: { baseUrl?: string }) {\n if (!apiKey) throw new Error(\"API key is required\");\n this.apiKey = apiKey;\n this.baseUrl = options?.baseUrl ?? BASE_URL;\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 // \"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":";;;;;AAmBA,IAAM,WAAW;AAEV,IAAM,MAAN,MAAU;AAAA,EACN;AAAA,EACA;AAAA,EAED;AAAA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AE;AAAA,IACxE;AACA,WAAO;AAAA,EACT;AACF;AAEA,IAAO,gBAAQ;","names":["VGFError"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verygoodffmpeg/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "TypeScript SDK for the Very Good FFmpeg API",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/verygoodffmpeg/Very-Good-FFmpeg-Typescript-SDK.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/verygoodffmpeg/Very-Good-FFmpeg-Typescript-SDK#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/verygoodffmpeg/Very-Good-FFmpeg-Typescript-SDK/issues"
|
|
12
|
+
},
|
|
5
13
|
"type": "module",
|
|
6
14
|
"main": "./dist/index.cjs",
|
|
7
15
|
"module": "./dist/index.js",
|