@liqhtworks/sophon-sdk 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/.github/workflows/publish.yml +56 -0
- package/.openapi-generator/FILES +73 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/LICENSE +12 -0
- package/README.md +164 -0
- package/dist/apis/DownloadsApi.d.ts +63 -0
- package/dist/apis/DownloadsApi.js +58 -0
- package/dist/apis/HealthApi.d.ts +92 -0
- package/dist/apis/HealthApi.js +85 -0
- package/dist/apis/JobsApi.d.ts +225 -0
- package/dist/apis/JobsApi.js +245 -0
- package/dist/apis/UploadsApi.d.ts +228 -0
- package/dist/apis/UploadsApi.js +255 -0
- package/dist/apis/WebhooksApi.d.ts +138 -0
- package/dist/apis/WebhooksApi.js +152 -0
- package/dist/apis/index.d.ts +5 -0
- package/dist/apis/index.js +23 -0
- package/dist/esm/apis/DownloadsApi.d.ts +63 -0
- package/dist/esm/apis/DownloadsApi.js +54 -0
- package/dist/esm/apis/HealthApi.d.ts +92 -0
- package/dist/esm/apis/HealthApi.js +81 -0
- package/dist/esm/apis/JobsApi.d.ts +225 -0
- package/dist/esm/apis/JobsApi.js +241 -0
- package/dist/esm/apis/UploadsApi.d.ts +228 -0
- package/dist/esm/apis/UploadsApi.js +251 -0
- package/dist/esm/apis/WebhooksApi.d.ts +138 -0
- package/dist/esm/apis/WebhooksApi.js +148 -0
- package/dist/esm/apis/index.d.ts +5 -0
- package/dist/esm/apis/index.js +7 -0
- package/dist/esm/helpers/index.d.ts +3 -0
- package/dist/esm/helpers/index.js +3 -0
- package/dist/esm/helpers/jobs.d.ts +48 -0
- package/dist/esm/helpers/jobs.js +61 -0
- package/dist/esm/helpers/uploads.d.ts +71 -0
- package/dist/esm/helpers/uploads.js +146 -0
- package/dist/esm/helpers/webhooks.d.ts +23 -0
- package/dist/esm/helpers/webhooks.js +84 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/models/CompleteUploadResponse.d.ts +57 -0
- package/dist/esm/models/CompleteUploadResponse.js +63 -0
- package/dist/esm/models/CreateJobOutputOptions.d.ts +55 -0
- package/dist/esm/models/CreateJobOutputOptions.js +46 -0
- package/dist/esm/models/CreateJobRequest.d.ts +61 -0
- package/dist/esm/models/CreateJobRequest.js +56 -0
- package/dist/esm/models/CreateUploadRequest.d.ts +44 -0
- package/dist/esm/models/CreateUploadRequest.js +51 -0
- package/dist/esm/models/CreateUploadResponse.d.ts +52 -0
- package/dist/esm/models/CreateUploadResponse.js +55 -0
- package/dist/esm/models/CreateWebhookRequest.d.ts +40 -0
- package/dist/esm/models/CreateWebhookRequest.js +45 -0
- package/dist/esm/models/ErrorBody.d.ts +72 -0
- package/dist/esm/models/ErrorBody.js +74 -0
- package/dist/esm/models/ErrorEnvelope.d.ts +33 -0
- package/dist/esm/models/ErrorEnvelope.js +44 -0
- package/dist/esm/models/JobOutputInfo.d.ts +95 -0
- package/dist/esm/models/JobOutputInfo.js +72 -0
- package/dist/esm/models/JobProfile.d.ts +49 -0
- package/dist/esm/models/JobProfile.js +69 -0
- package/dist/esm/models/JobProgress.d.ts +75 -0
- package/dist/esm/models/JobProgress.js +60 -0
- package/dist/esm/models/JobResponse.d.ts +134 -0
- package/dist/esm/models/JobResponse.js +94 -0
- package/dist/esm/models/JobSourceInfo.d.ts +62 -0
- package/dist/esm/models/JobSourceInfo.js +53 -0
- package/dist/esm/models/JobSourceType.d.ts +24 -0
- package/dist/esm/models/JobSourceType.js +44 -0
- package/dist/esm/models/JobStatus.d.ts +31 -0
- package/dist/esm/models/JobStatus.js +51 -0
- package/dist/esm/models/ListJobsResponse.d.ts +45 -0
- package/dist/esm/models/ListJobsResponse.js +50 -0
- package/dist/esm/models/OutputContainer.d.ts +27 -0
- package/dist/esm/models/OutputContainer.js +47 -0
- package/dist/esm/models/ReadyResponse.d.ts +38 -0
- package/dist/esm/models/ReadyResponse.js +45 -0
- package/dist/esm/models/UploadJobSource.d.ts +39 -0
- package/dist/esm/models/UploadJobSource.js +48 -0
- package/dist/esm/models/UploadPartResponse.d.ts +38 -0
- package/dist/esm/models/UploadPartResponse.js +47 -0
- package/dist/esm/models/UploadStatusResponse.d.ts +96 -0
- package/dist/esm/models/UploadStatusResponse.js +80 -0
- package/dist/esm/models/WebhookDeliveryPayload.d.ts +85 -0
- package/dist/esm/models/WebhookDeliveryPayload.js +83 -0
- package/dist/esm/models/WebhookListItem.d.ts +50 -0
- package/dist/esm/models/WebhookListItem.js +55 -0
- package/dist/esm/models/WebhookListResponse.d.ts +33 -0
- package/dist/esm/models/WebhookListResponse.js +44 -0
- package/dist/esm/models/WebhookResponse.d.ts +58 -0
- package/dist/esm/models/WebhookResponse.js +59 -0
- package/dist/esm/models/index.d.ts +25 -0
- package/dist/esm/models/index.js +27 -0
- package/dist/esm/runtime.d.ts +184 -0
- package/dist/esm/runtime.js +348 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/helpers/jobs.d.ts +48 -0
- package/dist/helpers/jobs.js +67 -0
- package/dist/helpers/uploads.d.ts +71 -0
- package/dist/helpers/uploads.js +149 -0
- package/dist/helpers/webhooks.d.ts +23 -0
- package/dist/helpers/webhooks.js +89 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +22 -0
- package/dist/models/CompleteUploadResponse.d.ts +57 -0
- package/dist/models/CompleteUploadResponse.js +71 -0
- package/dist/models/CreateJobOutputOptions.d.ts +55 -0
- package/dist/models/CreateJobOutputOptions.js +53 -0
- package/dist/models/CreateJobRequest.d.ts +61 -0
- package/dist/models/CreateJobRequest.js +63 -0
- package/dist/models/CreateUploadRequest.d.ts +44 -0
- package/dist/models/CreateUploadRequest.js +58 -0
- package/dist/models/CreateUploadResponse.d.ts +52 -0
- package/dist/models/CreateUploadResponse.js +62 -0
- package/dist/models/CreateWebhookRequest.d.ts +40 -0
- package/dist/models/CreateWebhookRequest.js +52 -0
- package/dist/models/ErrorBody.d.ts +72 -0
- package/dist/models/ErrorBody.js +82 -0
- package/dist/models/ErrorEnvelope.d.ts +33 -0
- package/dist/models/ErrorEnvelope.js +51 -0
- package/dist/models/JobOutputInfo.d.ts +95 -0
- package/dist/models/JobOutputInfo.js +80 -0
- package/dist/models/JobProfile.d.ts +49 -0
- package/dist/models/JobProfile.js +77 -0
- package/dist/models/JobProgress.d.ts +75 -0
- package/dist/models/JobProgress.js +67 -0
- package/dist/models/JobResponse.d.ts +134 -0
- package/dist/models/JobResponse.js +101 -0
- package/dist/models/JobSourceInfo.d.ts +62 -0
- package/dist/models/JobSourceInfo.js +60 -0
- package/dist/models/JobSourceType.d.ts +24 -0
- package/dist/models/JobSourceType.js +52 -0
- package/dist/models/JobStatus.d.ts +31 -0
- package/dist/models/JobStatus.js +59 -0
- package/dist/models/ListJobsResponse.d.ts +45 -0
- package/dist/models/ListJobsResponse.js +57 -0
- package/dist/models/OutputContainer.d.ts +27 -0
- package/dist/models/OutputContainer.js +55 -0
- package/dist/models/ReadyResponse.d.ts +38 -0
- package/dist/models/ReadyResponse.js +52 -0
- package/dist/models/UploadJobSource.d.ts +39 -0
- package/dist/models/UploadJobSource.js +55 -0
- package/dist/models/UploadPartResponse.d.ts +38 -0
- package/dist/models/UploadPartResponse.js +54 -0
- package/dist/models/UploadStatusResponse.d.ts +96 -0
- package/dist/models/UploadStatusResponse.js +88 -0
- package/dist/models/WebhookDeliveryPayload.d.ts +85 -0
- package/dist/models/WebhookDeliveryPayload.js +91 -0
- package/dist/models/WebhookListItem.d.ts +50 -0
- package/dist/models/WebhookListItem.js +62 -0
- package/dist/models/WebhookListResponse.d.ts +33 -0
- package/dist/models/WebhookListResponse.js +51 -0
- package/dist/models/WebhookResponse.d.ts +58 -0
- package/dist/models/WebhookResponse.js +66 -0
- package/dist/models/index.d.ts +25 -0
- package/dist/models/index.js +43 -0
- package/dist/runtime.d.ts +184 -0
- package/dist/runtime.js +364 -0
- package/docs/CompleteUploadResponse.md +40 -0
- package/docs/CreateJobOutputOptions.md +39 -0
- package/docs/CreateJobRequest.md +42 -0
- package/docs/CreateUploadRequest.md +38 -0
- package/docs/CreateUploadResponse.md +40 -0
- package/docs/CreateWebhookRequest.md +36 -0
- package/docs/DownloadsApi.md +78 -0
- package/docs/ErrorBody.md +40 -0
- package/docs/ErrorEnvelope.md +34 -0
- package/docs/HealthApi.md +129 -0
- package/docs/JobOutputInfo.md +50 -0
- package/docs/JobProfile.md +33 -0
- package/docs/JobProgress.md +48 -0
- package/docs/JobResponse.md +62 -0
- package/docs/JobSourceInfo.md +44 -0
- package/docs/JobSourceType.md +33 -0
- package/docs/JobStatus.md +33 -0
- package/docs/JobsApi.md +407 -0
- package/docs/ListJobsResponse.md +38 -0
- package/docs/OutputContainer.md +33 -0
- package/docs/ReadyResponse.md +36 -0
- package/docs/UploadJobSource.md +37 -0
- package/docs/UploadPartResponse.md +36 -0
- package/docs/UploadStatusResponse.md +50 -0
- package/docs/UploadsApi.md +415 -0
- package/docs/WebhookDeliveryPayload.md +45 -0
- package/docs/WebhookEventsApi.md +91 -0
- package/docs/WebhookListItem.md +40 -0
- package/docs/WebhookListResponse.md +34 -0
- package/docs/WebhookResponse.md +42 -0
- package/docs/WebhooksApi.md +235 -0
- package/package.json +24 -0
- package/src/apis/DownloadsApi.ts +114 -0
- package/src/apis/HealthApi.ts +160 -0
- package/src/apis/JobsApi.ts +491 -0
- package/src/apis/UploadsApi.ts +522 -0
- package/src/apis/WebhooksApi.ts +298 -0
- package/src/apis/index.ts +7 -0
- package/src/helpers/index.ts +3 -0
- package/src/helpers/jobs.ts +112 -0
- package/src/helpers/uploads.ts +243 -0
- package/src/helpers/webhooks.ts +134 -0
- package/src/index.ts +7 -0
- package/src/models/CompleteUploadResponse.ts +102 -0
- package/src/models/CreateJobOutputOptions.ts +101 -0
- package/src/models/CreateJobRequest.ts +123 -0
- package/src/models/CreateUploadRequest.ts +84 -0
- package/src/models/CreateUploadResponse.ts +95 -0
- package/src/models/CreateWebhookRequest.ts +76 -0
- package/src/models/ErrorBody.ts +116 -0
- package/src/models/ErrorEnvelope.ts +74 -0
- package/src/models/JobOutputInfo.ts +149 -0
- package/src/models/JobProfile.ts +76 -0
- package/src/models/JobProgress.ts +133 -0
- package/src/models/JobResponse.ts +236 -0
- package/src/models/JobSourceInfo.ts +106 -0
- package/src/models/JobSourceType.ts +51 -0
- package/src/models/JobStatus.ts +58 -0
- package/src/models/ListJobsResponse.ts +91 -0
- package/src/models/OutputContainer.ts +54 -0
- package/src/models/ReadyResponse.ts +74 -0
- package/src/models/UploadJobSource.ts +85 -0
- package/src/models/UploadPartResponse.ts +75 -0
- package/src/models/UploadStatusResponse.ts +153 -0
- package/src/models/WebhookDeliveryPayload.ts +134 -0
- package/src/models/WebhookListItem.ts +93 -0
- package/src/models/WebhookListResponse.ts +74 -0
- package/src/models/WebhookResponse.ts +104 -0
- package/src/models/index.ts +27 -0
- package/src/runtime.ts +450 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* SOPHON Encoding API
|
|
5
|
+
* REST API for submitting, monitoring, and retrieving SOPHON encoding jobs. Authentication is via Bearer API key or session cookie. All POST endpoints require an Idempotency-Key header. List endpoints use opaque cursor-based pagination.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
export const BASE_PATH = "https://api.liqhtworks.xyz".replace(/\/+$/, "");
|
|
15
|
+
export class Configuration {
|
|
16
|
+
configuration;
|
|
17
|
+
constructor(configuration = {}) {
|
|
18
|
+
this.configuration = configuration;
|
|
19
|
+
}
|
|
20
|
+
set config(configuration) {
|
|
21
|
+
this.configuration = configuration;
|
|
22
|
+
}
|
|
23
|
+
get basePath() {
|
|
24
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
25
|
+
}
|
|
26
|
+
get fetchApi() {
|
|
27
|
+
return this.configuration.fetchApi;
|
|
28
|
+
}
|
|
29
|
+
get middleware() {
|
|
30
|
+
return this.configuration.middleware || [];
|
|
31
|
+
}
|
|
32
|
+
get queryParamsStringify() {
|
|
33
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
34
|
+
}
|
|
35
|
+
get username() {
|
|
36
|
+
return this.configuration.username;
|
|
37
|
+
}
|
|
38
|
+
get password() {
|
|
39
|
+
return this.configuration.password;
|
|
40
|
+
}
|
|
41
|
+
get apiKey() {
|
|
42
|
+
const apiKey = this.configuration.apiKey;
|
|
43
|
+
if (apiKey) {
|
|
44
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
get accessToken() {
|
|
49
|
+
const accessToken = this.configuration.accessToken;
|
|
50
|
+
if (accessToken) {
|
|
51
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
get headers() {
|
|
56
|
+
return this.configuration.headers;
|
|
57
|
+
}
|
|
58
|
+
get credentials() {
|
|
59
|
+
return this.configuration.credentials;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const DefaultConfig = new Configuration();
|
|
63
|
+
/**
|
|
64
|
+
* This is the base class for all generated API classes.
|
|
65
|
+
*/
|
|
66
|
+
export class BaseAPI {
|
|
67
|
+
configuration;
|
|
68
|
+
static jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
|
|
69
|
+
middleware;
|
|
70
|
+
constructor(configuration = DefaultConfig) {
|
|
71
|
+
this.configuration = configuration;
|
|
72
|
+
this.middleware = configuration.middleware;
|
|
73
|
+
}
|
|
74
|
+
withMiddleware(...middlewares) {
|
|
75
|
+
const next = this.clone();
|
|
76
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
77
|
+
return next;
|
|
78
|
+
}
|
|
79
|
+
withPreMiddleware(...preMiddlewares) {
|
|
80
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
81
|
+
return this.withMiddleware(...middlewares);
|
|
82
|
+
}
|
|
83
|
+
withPostMiddleware(...postMiddlewares) {
|
|
84
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
85
|
+
return this.withMiddleware(...middlewares);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if the given MIME is a JSON MIME.
|
|
89
|
+
* JSON MIME examples:
|
|
90
|
+
* application/json
|
|
91
|
+
* application/json; charset=UTF8
|
|
92
|
+
* APPLICATION/JSON
|
|
93
|
+
* application/vnd.company+json
|
|
94
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
95
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
96
|
+
*/
|
|
97
|
+
isJsonMime(mime) {
|
|
98
|
+
if (!mime) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
102
|
+
}
|
|
103
|
+
async request(context, initOverrides) {
|
|
104
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
105
|
+
const response = await this.fetchApi(url, init);
|
|
106
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
107
|
+
return response;
|
|
108
|
+
}
|
|
109
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
110
|
+
}
|
|
111
|
+
async createFetchParams(context, initOverrides) {
|
|
112
|
+
let url = this.configuration.basePath + context.path;
|
|
113
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
114
|
+
// only add the querystring to the URL if there are query parameters.
|
|
115
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
116
|
+
// do not handle correctly sometimes.
|
|
117
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
118
|
+
}
|
|
119
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
120
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
121
|
+
const initOverrideFn = typeof initOverrides === "function"
|
|
122
|
+
? initOverrides
|
|
123
|
+
: async () => initOverrides;
|
|
124
|
+
const initParams = {
|
|
125
|
+
method: context.method,
|
|
126
|
+
headers,
|
|
127
|
+
body: context.body,
|
|
128
|
+
credentials: this.configuration.credentials,
|
|
129
|
+
};
|
|
130
|
+
const overriddenInit = {
|
|
131
|
+
...initParams,
|
|
132
|
+
...(await initOverrideFn({
|
|
133
|
+
init: initParams,
|
|
134
|
+
context,
|
|
135
|
+
}))
|
|
136
|
+
};
|
|
137
|
+
let body;
|
|
138
|
+
if (isFormData(overriddenInit.body)
|
|
139
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
140
|
+
|| isBlob(overriddenInit.body)) {
|
|
141
|
+
body = overriddenInit.body;
|
|
142
|
+
}
|
|
143
|
+
else if (this.isJsonMime(headers['Content-Type'])) {
|
|
144
|
+
body = JSON.stringify(overriddenInit.body);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
body = overriddenInit.body;
|
|
148
|
+
}
|
|
149
|
+
const init = {
|
|
150
|
+
...overriddenInit,
|
|
151
|
+
body
|
|
152
|
+
};
|
|
153
|
+
return { url, init };
|
|
154
|
+
}
|
|
155
|
+
fetchApi = async (url, init) => {
|
|
156
|
+
let fetchParams = { url, init };
|
|
157
|
+
for (const middleware of this.middleware) {
|
|
158
|
+
if (middleware.pre) {
|
|
159
|
+
fetchParams = await middleware.pre({
|
|
160
|
+
fetch: this.fetchApi,
|
|
161
|
+
...fetchParams,
|
|
162
|
+
}) || fetchParams;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let response = undefined;
|
|
166
|
+
try {
|
|
167
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
for (const middleware of this.middleware) {
|
|
171
|
+
if (middleware.onError) {
|
|
172
|
+
response = await middleware.onError({
|
|
173
|
+
fetch: this.fetchApi,
|
|
174
|
+
url: fetchParams.url,
|
|
175
|
+
init: fetchParams.init,
|
|
176
|
+
error: e,
|
|
177
|
+
response: response ? response.clone() : undefined,
|
|
178
|
+
}) || response;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (response === undefined) {
|
|
182
|
+
if (e instanceof Error) {
|
|
183
|
+
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
throw e;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const middleware of this.middleware) {
|
|
191
|
+
if (middleware.post) {
|
|
192
|
+
response = await middleware.post({
|
|
193
|
+
fetch: this.fetchApi,
|
|
194
|
+
url: fetchParams.url,
|
|
195
|
+
init: fetchParams.init,
|
|
196
|
+
response: response.clone(),
|
|
197
|
+
}) || response;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return response;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Create a shallow clone of `this` by constructing a new instance
|
|
204
|
+
* and then shallow cloning data members.
|
|
205
|
+
*/
|
|
206
|
+
clone() {
|
|
207
|
+
const constructor = this.constructor;
|
|
208
|
+
const next = new constructor(this.configuration);
|
|
209
|
+
next.middleware = this.middleware.slice();
|
|
210
|
+
return next;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
;
|
|
214
|
+
function isBlob(value) {
|
|
215
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
216
|
+
}
|
|
217
|
+
function isFormData(value) {
|
|
218
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
219
|
+
}
|
|
220
|
+
export class ResponseError extends Error {
|
|
221
|
+
response;
|
|
222
|
+
name = "ResponseError";
|
|
223
|
+
constructor(response, msg) {
|
|
224
|
+
super(msg);
|
|
225
|
+
this.response = response;
|
|
226
|
+
// restore prototype chain
|
|
227
|
+
const actualProto = new.target.prototype;
|
|
228
|
+
if (Object.setPrototypeOf) {
|
|
229
|
+
Object.setPrototypeOf(this, actualProto);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export class FetchError extends Error {
|
|
234
|
+
cause;
|
|
235
|
+
name = "FetchError";
|
|
236
|
+
constructor(cause, msg) {
|
|
237
|
+
super(msg);
|
|
238
|
+
this.cause = cause;
|
|
239
|
+
// restore prototype chain
|
|
240
|
+
const actualProto = new.target.prototype;
|
|
241
|
+
if (Object.setPrototypeOf) {
|
|
242
|
+
Object.setPrototypeOf(this, actualProto);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export class RequiredError extends Error {
|
|
247
|
+
field;
|
|
248
|
+
name = "RequiredError";
|
|
249
|
+
constructor(field, msg) {
|
|
250
|
+
super(msg);
|
|
251
|
+
this.field = field;
|
|
252
|
+
// restore prototype chain
|
|
253
|
+
const actualProto = new.target.prototype;
|
|
254
|
+
if (Object.setPrototypeOf) {
|
|
255
|
+
Object.setPrototypeOf(this, actualProto);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
export const COLLECTION_FORMATS = {
|
|
260
|
+
csv: ",",
|
|
261
|
+
ssv: " ",
|
|
262
|
+
tsv: "\t",
|
|
263
|
+
pipes: "|",
|
|
264
|
+
};
|
|
265
|
+
export function querystring(params, prefix = '') {
|
|
266
|
+
return Object.keys(params)
|
|
267
|
+
.map(key => querystringSingleKey(key, params[key], prefix))
|
|
268
|
+
.filter(part => part.length > 0)
|
|
269
|
+
.join('&');
|
|
270
|
+
}
|
|
271
|
+
function querystringSingleKey(key, value, keyPrefix = '') {
|
|
272
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
273
|
+
if (value instanceof Array) {
|
|
274
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
275
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
276
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
277
|
+
}
|
|
278
|
+
if (value instanceof Set) {
|
|
279
|
+
const valueAsArray = Array.from(value);
|
|
280
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
281
|
+
}
|
|
282
|
+
if (value instanceof Date) {
|
|
283
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
284
|
+
}
|
|
285
|
+
if (value instanceof Object) {
|
|
286
|
+
return querystring(value, fullKey);
|
|
287
|
+
}
|
|
288
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
289
|
+
}
|
|
290
|
+
export function exists(json, key) {
|
|
291
|
+
const value = json[key];
|
|
292
|
+
return value !== null && value !== undefined;
|
|
293
|
+
}
|
|
294
|
+
export function mapValues(data, fn) {
|
|
295
|
+
const result = {};
|
|
296
|
+
for (const key of Object.keys(data)) {
|
|
297
|
+
result[key] = fn(data[key]);
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
export function canConsumeForm(consumes) {
|
|
302
|
+
for (const consume of consumes) {
|
|
303
|
+
if ('multipart/form-data' === consume.contentType) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
export class JSONApiResponse {
|
|
310
|
+
raw;
|
|
311
|
+
transformer;
|
|
312
|
+
constructor(raw, transformer = (jsonValue) => jsonValue) {
|
|
313
|
+
this.raw = raw;
|
|
314
|
+
this.transformer = transformer;
|
|
315
|
+
}
|
|
316
|
+
async value() {
|
|
317
|
+
return this.transformer(await this.raw.json());
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
export class VoidApiResponse {
|
|
321
|
+
raw;
|
|
322
|
+
constructor(raw) {
|
|
323
|
+
this.raw = raw;
|
|
324
|
+
}
|
|
325
|
+
async value() {
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
export class BlobApiResponse {
|
|
330
|
+
raw;
|
|
331
|
+
constructor(raw) {
|
|
332
|
+
this.raw = raw;
|
|
333
|
+
}
|
|
334
|
+
async value() {
|
|
335
|
+
return await this.raw.blob();
|
|
336
|
+
}
|
|
337
|
+
;
|
|
338
|
+
}
|
|
339
|
+
export class TextApiResponse {
|
|
340
|
+
raw;
|
|
341
|
+
constructor(raw) {
|
|
342
|
+
this.raw = raw;
|
|
343
|
+
}
|
|
344
|
+
async value() {
|
|
345
|
+
return await this.raw.text();
|
|
346
|
+
}
|
|
347
|
+
;
|
|
348
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./uploads"), exports);
|
|
18
|
+
__exportStar(require("./jobs"), exports);
|
|
19
|
+
__exportStar(require("./webhooks"), exports);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type JobTerminalStatus = "completed" | "failed" | "canceled";
|
|
2
|
+
export type JobStatusLike = JobTerminalStatus | "queued" | "probing" | "encoding" | "muxing" | "uploading_output";
|
|
3
|
+
export interface JobLike {
|
|
4
|
+
id: string;
|
|
5
|
+
status: JobStatusLike;
|
|
6
|
+
error?: string | null;
|
|
7
|
+
}
|
|
8
|
+
export interface JobsApiLike {
|
|
9
|
+
getJob(params: {
|
|
10
|
+
id: string;
|
|
11
|
+
}): Promise<JobLike>;
|
|
12
|
+
}
|
|
13
|
+
export interface WaitForJobParams<T extends JobLike = JobLike> {
|
|
14
|
+
api: {
|
|
15
|
+
getJob: (p: {
|
|
16
|
+
id: string;
|
|
17
|
+
}) => Promise<T>;
|
|
18
|
+
};
|
|
19
|
+
jobId: string;
|
|
20
|
+
/** Resolve only on these statuses. Default: the three terminal ones. */
|
|
21
|
+
until?: readonly JobStatusLike[];
|
|
22
|
+
/** Initial poll interval (ms). Default 1000. */
|
|
23
|
+
pollMinMs?: number;
|
|
24
|
+
/** Cap on poll interval (ms). Default 15000. */
|
|
25
|
+
pollMaxMs?: number;
|
|
26
|
+
/** Exponential backoff multiplier per poll. Default 1.5. */
|
|
27
|
+
pollBackoff?: number;
|
|
28
|
+
/** Abort and throw after this many ms. Default 3600000 (1h). */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Called on every poll with the freshly fetched job. */
|
|
31
|
+
onProgress?: (job: T) => void;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
export declare class JobTerminalError<T extends JobLike = JobLike> extends Error {
|
|
35
|
+
readonly job: T;
|
|
36
|
+
constructor(job: T);
|
|
37
|
+
}
|
|
38
|
+
export declare class JobTimeoutError extends Error {
|
|
39
|
+
readonly jobId: string;
|
|
40
|
+
constructor(jobId: string, waitedMs: number);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Polls `getJob` until the job hits a terminal status (or the requested
|
|
44
|
+
* `until` list), then returns the final job. Throws `JobTerminalError` on
|
|
45
|
+
* `failed` / `canceled` unless those are explicitly requested in `until`.
|
|
46
|
+
* Throws `JobTimeoutError` if the timeout elapses.
|
|
47
|
+
*/
|
|
48
|
+
export declare function waitForJob<T extends JobLike = JobLike>(params: WaitForJobParams<T>): Promise<T>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Polling helper that resolves when a job hits a terminal state.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.JobTimeoutError = exports.JobTerminalError = void 0;
|
|
5
|
+
exports.waitForJob = waitForJob;
|
|
6
|
+
class JobTerminalError extends Error {
|
|
7
|
+
job;
|
|
8
|
+
constructor(job) {
|
|
9
|
+
super(job.error ?? `job ${job.id} ended in status ${job.status}`);
|
|
10
|
+
this.name = "JobTerminalError";
|
|
11
|
+
this.job = job;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.JobTerminalError = JobTerminalError;
|
|
15
|
+
class JobTimeoutError extends Error {
|
|
16
|
+
jobId;
|
|
17
|
+
constructor(jobId, waitedMs) {
|
|
18
|
+
super(`job ${jobId} did not finish within ${waitedMs}ms`);
|
|
19
|
+
this.name = "JobTimeoutError";
|
|
20
|
+
this.jobId = jobId;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.JobTimeoutError = JobTimeoutError;
|
|
24
|
+
const DEFAULT_TERMINAL = ["completed", "failed", "canceled"];
|
|
25
|
+
/**
|
|
26
|
+
* Polls `getJob` until the job hits a terminal status (or the requested
|
|
27
|
+
* `until` list), then returns the final job. Throws `JobTerminalError` on
|
|
28
|
+
* `failed` / `canceled` unless those are explicitly requested in `until`.
|
|
29
|
+
* Throws `JobTimeoutError` if the timeout elapses.
|
|
30
|
+
*/
|
|
31
|
+
async function waitForJob(params) {
|
|
32
|
+
const { api, jobId, until = DEFAULT_TERMINAL, pollMinMs = 1000, pollMaxMs = 15000, pollBackoff = 1.5, timeoutMs = 60 * 60 * 1000, onProgress, signal, } = params;
|
|
33
|
+
const start = Date.now();
|
|
34
|
+
let interval = pollMinMs;
|
|
35
|
+
while (true) {
|
|
36
|
+
if (signal?.aborted)
|
|
37
|
+
throw new DOMException("Aborted", "AbortError");
|
|
38
|
+
if (Date.now() - start > timeoutMs)
|
|
39
|
+
throw new JobTimeoutError(jobId, Date.now() - start);
|
|
40
|
+
const job = await api.getJob({ id: jobId });
|
|
41
|
+
onProgress?.(job);
|
|
42
|
+
if (until.some((s) => s === job.status)) {
|
|
43
|
+
// The caller opted into this status; only synthesize a JobTerminalError
|
|
44
|
+
// when they are waiting for the default-terminal set and we landed on a
|
|
45
|
+
// failed/canceled status.
|
|
46
|
+
if (until === DEFAULT_TERMINAL && (job.status === "failed" || job.status === "canceled")) {
|
|
47
|
+
throw new JobTerminalError(job);
|
|
48
|
+
}
|
|
49
|
+
return job;
|
|
50
|
+
}
|
|
51
|
+
await sleep(interval, signal);
|
|
52
|
+
interval = Math.min(Math.ceil(interval * pollBackoff), pollMaxMs);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function sleep(ms, signal) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const t = setTimeout(() => {
|
|
58
|
+
signal?.removeEventListener("abort", onAbort);
|
|
59
|
+
resolve();
|
|
60
|
+
}, ms);
|
|
61
|
+
const onAbort = () => {
|
|
62
|
+
clearTimeout(t);
|
|
63
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
64
|
+
};
|
|
65
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export interface UploadsApiLike {
|
|
2
|
+
createUpload(params: {
|
|
3
|
+
createUploadRequest: {
|
|
4
|
+
file_name: string;
|
|
5
|
+
file_size: number;
|
|
6
|
+
mime_type: string;
|
|
7
|
+
};
|
|
8
|
+
idempotencyKey: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
chunk_size: number;
|
|
12
|
+
total_chunks: number;
|
|
13
|
+
expires_at: string;
|
|
14
|
+
}>;
|
|
15
|
+
uploadPart(params: {
|
|
16
|
+
id: string;
|
|
17
|
+
partNumber: number;
|
|
18
|
+
body: Blob;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
part_number: number;
|
|
21
|
+
received: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
completeUpload(params: {
|
|
24
|
+
id: string;
|
|
25
|
+
idempotencyKey: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
id: string;
|
|
28
|
+
status: string;
|
|
29
|
+
sha256: string;
|
|
30
|
+
bytes: number;
|
|
31
|
+
}>;
|
|
32
|
+
getUpload(params: {
|
|
33
|
+
id: string;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
status: string;
|
|
37
|
+
total_chunks: number;
|
|
38
|
+
received_chunks: number[];
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
export interface UploadProgress {
|
|
42
|
+
bytesUploaded: number;
|
|
43
|
+
bytesTotal: number;
|
|
44
|
+
partsDone: number;
|
|
45
|
+
partsTotal: number;
|
|
46
|
+
}
|
|
47
|
+
export interface UploadFileParams {
|
|
48
|
+
api: UploadsApiLike;
|
|
49
|
+
source: Blob;
|
|
50
|
+
fileName: string;
|
|
51
|
+
mimeType: string;
|
|
52
|
+
/** Resume a prior session instead of creating a new one. */
|
|
53
|
+
uploadId?: string;
|
|
54
|
+
/** Parallel in-flight chunks. Default 4. */
|
|
55
|
+
concurrency?: number;
|
|
56
|
+
/** Retries per chunk before aborting. Default 3. */
|
|
57
|
+
retries?: number;
|
|
58
|
+
/** Base backoff in ms; doubles each attempt. Default 500. */
|
|
59
|
+
retryBaseMs?: number;
|
|
60
|
+
/** Idempotency key reused for createUpload + completeUpload. Auto-generated if omitted. */
|
|
61
|
+
idempotencyKey?: string;
|
|
62
|
+
onProgress?: (p: UploadProgress) => void;
|
|
63
|
+
/** Abort the whole upload. Chunks in flight will still settle. */
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}
|
|
66
|
+
export interface UploadFileResult {
|
|
67
|
+
uploadId: string;
|
|
68
|
+
sha256: string;
|
|
69
|
+
bytes: number;
|
|
70
|
+
}
|
|
71
|
+
export declare function uploadFile(params: UploadFileParams): Promise<UploadFileResult>;
|