@bytescale/sdk 1.2.0 → 1.3.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/dist/browser/cjs/main.js +891 -179
- package/dist/node/cjs/main.js +405 -186
- package/dist/node/esm/main.mjs +411 -188
- package/dist/types/index.d.ts +2 -0
- package/dist/types/private/AuthSessionState.d.ts +13 -0
- package/dist/types/private/ConsoleUtils.d.ts +5 -0
- package/dist/types/private/EnvChecker.d.ts +4 -0
- package/dist/types/private/Mutex.d.ts +16 -0
- package/dist/types/private/TypeUtils.d.ts +2 -0
- package/dist/types/{uploads/private → private}/UploadManagerBase.d.ts +2 -2
- package/dist/types/private/dtos/SetAccessTokenRequestDto.d.ts +6 -0
- package/dist/types/private/dtos/SetAccessTokenResponseDto.d.ts +7 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +44 -0
- package/dist/types/private/model/AuthSession.d.ts +7 -0
- package/dist/types/private/model/UploadManagerInterface.d.ts +5 -0
- package/dist/types/{uploads/private → private}/model/UploadSourceProcessed.d.ts +1 -1
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +20 -0
- package/dist/types/{uploads/public → public}/browser/UploadManagerBrowser.d.ts +2 -2
- package/dist/types/{uploads/public → public}/browser/index.d.ts +1 -0
- package/dist/types/public/node/AuthManagerNode.d.ts +6 -0
- package/dist/types/{uploads/public → public}/node/UploadManagerNode.d.ts +2 -2
- package/dist/types/{uploads/public → public}/node/index.d.ts +1 -0
- package/dist/types/{uploads/public/shared/Model.d.ts → public/shared/CommonTypes.d.ts} +3 -9
- package/dist/types/public/shared/UrlBuilder.d.ts +28 -0
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +173 -0
- package/dist/types/{generated → public/shared/generated}/runtime.d.ts +44 -14
- package/dist/types/public/shared/index.d.ts +4 -0
- package/package.json +2 -2
- package/tests/ChunkedStream.test.ts +1 -1
- package/tests/UrlBuilder.test.ts +168 -0
- package/dist/types/index.browser.d.ts +0 -3
- package/dist/types/index.node.d.ts +0 -3
- package/dist/types/uploads/private/TypeUtils.d.ts +0 -1
- package/dist/types/uploads/private/model/UploadManagerInterface.d.ts +0 -5
- package/dist/types/uploads/public/shared/index.d.ts +0 -1
- /package/dist/types/{uploads/private → private}/NodeChunkedStream.d.ts +0 -0
- /package/dist/types/{uploads/private → private}/StreamUtils.d.ts +0 -0
- /package/dist/types/{uploads/private → private}/model/AddCancellationHandler.d.ts +0 -0
- /package/dist/types/{uploads/private → private}/model/OnPartProgress.d.ts +0 -0
- /package/dist/types/{uploads/private → private}/model/PreUploadInfo.d.ts +0 -0
- /package/dist/types/{uploads/private → private}/model/PutUploadPartResult.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/apis/FileApi.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/apis/FolderApi.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/apis/JobApi.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/apis/UploadApi.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/apis/index.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/index.d.ts +0 -0
- /package/dist/types/{generated → public/shared/generated}/models/index.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthSession } from "./model/AuthSession";
|
|
2
|
+
export declare class AuthSessionState {
|
|
3
|
+
/**
|
|
4
|
+
* Intentionally global:
|
|
5
|
+
*
|
|
6
|
+
* Users frequently have problems caused by them not keeping track of *Api and *Manager instances correctly, so we
|
|
7
|
+
* make this global as in 99.9% of cases, this is what users want, and it prevents lots of common mistakes.
|
|
8
|
+
*
|
|
9
|
+
* We only set this in the browser.
|
|
10
|
+
* Never in Node.js.
|
|
11
|
+
*/
|
|
12
|
+
static session: AuthSession | undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
|
|
3
|
+
*
|
|
4
|
+
* Characteristics:
|
|
5
|
+
* - Non-reentrant.
|
|
6
|
+
* - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
|
|
7
|
+
* - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
|
|
8
|
+
* the mutex every time.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Mutex {
|
|
11
|
+
private mutex;
|
|
12
|
+
private resolver;
|
|
13
|
+
safe<T>(callback: () => Promise<T>): Promise<T>;
|
|
14
|
+
private acquire;
|
|
15
|
+
private release;
|
|
16
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BytescaleApiClientConfig, FileDetails, UploadPart } from "
|
|
2
|
-
import { UploadManagerParams, UploadSource } from "../public/shared";
|
|
1
|
+
import { BytescaleApiClientConfig, FileDetails, UploadPart } from "../public/shared/generated";
|
|
3
2
|
import { UploadManagerInterface } from "./model/UploadManagerInterface";
|
|
4
3
|
import { PreUploadInfo } from "./model/PreUploadInfo";
|
|
5
4
|
import { UploadSourceBlob } from "./model/UploadSourceProcessed";
|
|
6
5
|
import { PutUploadPartResult } from "./model/PutUploadPartResult";
|
|
7
6
|
import { AddCancellationHandler } from "./model/AddCancellationHandler";
|
|
7
|
+
import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes";
|
|
8
8
|
/**
|
|
9
9
|
* Methods common to UploadManagerNode and UploadManagerBrowser.
|
|
10
10
|
*/
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface AuthManagerInterface {
|
|
2
|
+
/**
|
|
3
|
+
* Begins an authenticated Bytescale API and Bytescale CDN session.
|
|
4
|
+
*
|
|
5
|
+
* You can only call this method if 'isAuthSessionActive() === false', else an error will be returned.
|
|
6
|
+
*
|
|
7
|
+
* You can only call this method in the browser (not Node.js).
|
|
8
|
+
*
|
|
9
|
+
* You should call this method after the user has signed-in to your web app.
|
|
10
|
+
*
|
|
11
|
+
* After calling this method:
|
|
12
|
+
*
|
|
13
|
+
* 1) You must add '?auth=true' to the URL of any private file you're trying to access. This includes the URLs you use in 'src' elements in img/video elements, etc.
|
|
14
|
+
*
|
|
15
|
+
* 2) You must await the promise before attempting to perform any downloads or API operations that require authentication.
|
|
16
|
+
*
|
|
17
|
+
* The auth process works as follows:
|
|
18
|
+
*
|
|
19
|
+
* 1) After you call this method, the AuthManager will periodically fetch a JWT in plain text from the given 'authUrl'.
|
|
20
|
+
*
|
|
21
|
+
* 2) The JWT will be saved to a cookie scoped to the Bytescale CDN. This allows the user to view private files via the URL in the browser, including <img> elements on the page that reference private images, etc.
|
|
22
|
+
*
|
|
23
|
+
* 3) The JWT will also be added as a request header via 'authorization-token' to all Bytescale API requests made via this SDK. This allows the user to upload private files and perform administrative operations permitted by the JWT, such as deleting files, etc.
|
|
24
|
+
*
|
|
25
|
+
* @param authUrl The fully-qualified URL for your backend API's auth endpoint.
|
|
26
|
+
* @param authHeaders Headers to send to your backend API.
|
|
27
|
+
* IMPORTANT: do not call '*AuthSession' inside this callback, as this will cause a deadlock.
|
|
28
|
+
*/
|
|
29
|
+
beginAuthSession: (authUrl: string, authHeaders: () => Promise<Record<string, string>>) => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Ends an authenticated Bytescale API and Bytescale CDN session.
|
|
32
|
+
*
|
|
33
|
+
* This method idempotent, meaning you can call it regardless of the value of 'isAuthSessionActive()', and no error will be thrown.
|
|
34
|
+
*
|
|
35
|
+
* You can only call this method in the browser (not Node.js).
|
|
36
|
+
*
|
|
37
|
+
* You should call this method after the user has signed-out of your web app.
|
|
38
|
+
*/
|
|
39
|
+
endAuthSession: () => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an authenticated Bytescale API and Bytescale CDN session is active.
|
|
42
|
+
*/
|
|
43
|
+
isAuthSessionActive: () => boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
import { BaseAPI, BytescaleApiClientConfig } from "../shared/generated";
|
|
3
|
+
export declare class AuthManager extends BaseAPI implements AuthManagerInterface {
|
|
4
|
+
private readonly accessTokenUrl;
|
|
5
|
+
private readonly authSessionMutex;
|
|
6
|
+
private readonly contentType;
|
|
7
|
+
private readonly contentTypeJson;
|
|
8
|
+
private readonly contentTypeText;
|
|
9
|
+
private readonly minJwtTtlSeconds;
|
|
10
|
+
private readonly retryAuthAfterErrorSeconds;
|
|
11
|
+
private readonly refreshBeforeExpirySeconds;
|
|
12
|
+
constructor(config: BytescaleApiClientConfig);
|
|
13
|
+
isAuthSessionActive(): boolean;
|
|
14
|
+
beginAuthSession(authUrl: string, authHeaders: () => Promise<Record<string, string>>): Promise<void>;
|
|
15
|
+
endAuthSession(): Promise<void>;
|
|
16
|
+
private refreshAccessToken;
|
|
17
|
+
private deleteAccessToken;
|
|
18
|
+
private setAccessToken;
|
|
19
|
+
private getAccessToken;
|
|
20
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { UploadManagerBase } from "../../private/UploadManagerBase";
|
|
2
2
|
import { UploadSourceProcessedBrowser } from "../../private/model/UploadSourceProcessed";
|
|
3
|
-
import { UploadManagerParams, UploadSource } from "../shared";
|
|
4
3
|
import { PreUploadInfo } from "../../private/model/PreUploadInfo";
|
|
5
|
-
import { UploadPart } from "
|
|
4
|
+
import { UploadPart } from "../shared/generated";
|
|
6
5
|
import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
|
|
7
6
|
import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
|
|
7
|
+
import { UploadManagerParams, UploadSource } from "../shared/CommonTypes";
|
|
8
8
|
export declare class UploadManager extends UploadManagerBase<UploadSourceProcessedBrowser, undefined> {
|
|
9
9
|
protected processUploadSource(data: UploadSource): UploadSourceProcessedBrowser;
|
|
10
10
|
protected getPreUploadInfoPartial(_request: UploadManagerParams, data: UploadSourceProcessedBrowser): Partial<PreUploadInfo> & {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
export declare class AuthManager implements AuthManagerInterface {
|
|
3
|
+
beginAuthSession(_authUrl: string, _authHeaders: () => Promise<Record<string, string>>): Promise<void>;
|
|
4
|
+
endAuthSession(): Promise<void>;
|
|
5
|
+
isAuthSessionActive(): boolean;
|
|
6
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { UploadManagerBase } from "../../private/UploadManagerBase";
|
|
2
2
|
import { UploadSourceProcessedNode } from "../../private/model/UploadSourceProcessed";
|
|
3
3
|
import { NodeChunkedStream } from "../../private/NodeChunkedStream";
|
|
4
|
-
import { UploadManagerParams, UploadSource } from "../shared";
|
|
5
4
|
import { PreUploadInfo } from "../../private/model/PreUploadInfo";
|
|
6
|
-
import { UploadPart } from "
|
|
5
|
+
import { UploadPart } from "../shared/generated";
|
|
7
6
|
import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
|
|
7
|
+
import { UploadManagerParams, UploadSource } from "../shared/CommonTypes";
|
|
8
8
|
declare type UploadManagerNodeInit = undefined | {
|
|
9
9
|
chunkedStream: NodeChunkedStream;
|
|
10
10
|
chunkedStreamPromise: Promise<void>;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { BeginMultipartUploadRequest } from "./generated";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* - Node.js 'buffer.Blob', e.g. 'new buffer.Blob([JSON.stringify({someValue: 42})], {type: "application/json"})'
|
|
5
|
-
* - Browser 'Blob', e.g. 'new Blob([JSON.stringify({someValue: 42})], {type: "application/json"})'
|
|
6
|
-
* - Browser 'File', e.g. from a <input type="file" onchange="...">
|
|
4
|
+
* Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
|
|
7
5
|
*/
|
|
8
|
-
|
|
6
|
+
export declare const CommonTypesNoOp = false;
|
|
9
7
|
export interface BlobLike {
|
|
10
8
|
readonly name?: string;
|
|
11
9
|
readonly size: number;
|
|
@@ -20,10 +18,6 @@ export interface UploadProgress {
|
|
|
20
18
|
bytesTotal: number;
|
|
21
19
|
progress: number;
|
|
22
20
|
}
|
|
23
|
-
export declare class CancelledError extends Error {
|
|
24
|
-
name: "CancelledError";
|
|
25
|
-
constructor();
|
|
26
|
-
}
|
|
27
21
|
export declare type UploadSource = NodeJS.ReadableStream | BlobLike | Buffer | string;
|
|
28
22
|
export interface UploadManagerParams extends Omit<BeginMultipartUploadRequest, "size" | "protocol"> {
|
|
29
23
|
accountId: string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UrlBuilderConfig, UrlBuilderParams } from "./UrlBuilderTypes";
|
|
2
|
+
export declare class UrlBuilder {
|
|
3
|
+
private readonly cdnUrl;
|
|
4
|
+
constructor(config?: UrlBuilderConfig);
|
|
5
|
+
/**
|
|
6
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
7
|
+
*
|
|
8
|
+
* Example 1) Raw file:
|
|
9
|
+
*
|
|
10
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
11
|
+
*
|
|
12
|
+
* Example 2) Image resized to 500x500:
|
|
13
|
+
*
|
|
14
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } })
|
|
15
|
+
*
|
|
16
|
+
* Example 3) Image resized to 500x500, which is privately accessible (i.e. requires 'AuthManager.beginAuthSession' before it can be accessed):
|
|
17
|
+
*
|
|
18
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true })
|
|
19
|
+
*/
|
|
20
|
+
url(params: UrlBuilderParams): string;
|
|
21
|
+
private raw;
|
|
22
|
+
private transformation;
|
|
23
|
+
private getBaseUrl;
|
|
24
|
+
private getCommonQueryParams;
|
|
25
|
+
private makeQueryParams;
|
|
26
|
+
private getTransformationParams;
|
|
27
|
+
private addQueryParams;
|
|
28
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workaround for tsc aliases, where we cannot export implementation-less modules in our dists.
|
|
3
|
+
*/
|
|
4
|
+
export declare const UrlBuilderTypesNoOp = false;
|
|
5
|
+
export declare type ParameterGroup = Record<string, string | number | boolean | undefined | null>;
|
|
6
|
+
export declare type KeyValuePair = [string, string];
|
|
7
|
+
export interface UrlBuilderConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The base URL of the Bytescale CDN.
|
|
10
|
+
*/
|
|
11
|
+
cdnUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface UrlBuilderParams {
|
|
14
|
+
/**
|
|
15
|
+
* The account that manages the file.
|
|
16
|
+
*/
|
|
17
|
+
accountId: string;
|
|
18
|
+
/**
|
|
19
|
+
* The file to download.
|
|
20
|
+
*
|
|
21
|
+
* Must begin with: "/"
|
|
22
|
+
*/
|
|
23
|
+
filePath: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional parameters to control how the URL is constructed.
|
|
26
|
+
*/
|
|
27
|
+
options?: UrlBuilderOptions;
|
|
28
|
+
}
|
|
29
|
+
export interface UrlBuilderOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Set to 'true' to download a private file. Requires an active auth session. See AuthManager.beginAuthSession.
|
|
32
|
+
*
|
|
33
|
+
* Set to 'false' or omit when downloading publicly-accessible files.
|
|
34
|
+
*
|
|
35
|
+
* Default: false
|
|
36
|
+
*/
|
|
37
|
+
auth?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies whether to use caching for this request, or to always re-request the file.
|
|
40
|
+
*
|
|
41
|
+
* For file transformations, setting 'true' will cause the file to be re-processed on every request.
|
|
42
|
+
*
|
|
43
|
+
* Default: false
|
|
44
|
+
*/
|
|
45
|
+
cache?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Specifies the maximum amount of time, in seconds, the file will be cached on the user's device and in the Bytescale CDN's edge cache.
|
|
48
|
+
*
|
|
49
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
50
|
+
*/
|
|
51
|
+
cacheTtl?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Forces the browser to display a download prompt for the file, instead of displaying the file in the browser.
|
|
54
|
+
*
|
|
55
|
+
* When set to true, the Bytescale CDN will add a 'content-disposition: attachment' header to the HTTP response.
|
|
56
|
+
*
|
|
57
|
+
* Default: false
|
|
58
|
+
*/
|
|
59
|
+
forceDownloadPrompt?: boolean;
|
|
60
|
+
transformation?: UrlBuilderParamsTransformation;
|
|
61
|
+
/**
|
|
62
|
+
* Downloads the latest version of your file (if you have overwritten it) when added to the URL with a unique value.
|
|
63
|
+
*
|
|
64
|
+
* The value of the version parameter can be anything, e.g. an incremental number, a timestamp, etc.
|
|
65
|
+
*
|
|
66
|
+
* You only need to provide and update this value if/when you overwrite your file.
|
|
67
|
+
*/
|
|
68
|
+
version?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare type UrlBuilderParamsTransformation = UrlBuilderParamsTransformationPreset | UrlBuilderParamsImageTransformation | UrlBuilderParamsVideoTransformation | UrlBuilderParamsAudioTransformation | UrlBuilderParamsArchiveTransformation;
|
|
71
|
+
export interface UrlBuilderParamsTransformationOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The transformation artifact to download.
|
|
74
|
+
*
|
|
75
|
+
* Some transformations produce multiple files. The 'artifact' parameter is used to select which file to download.
|
|
76
|
+
*
|
|
77
|
+
* Must begin with: "/"
|
|
78
|
+
*
|
|
79
|
+
* Default: "/"
|
|
80
|
+
*/
|
|
81
|
+
artifact?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Specifies whether to permanently cache the transformed result in the Bytescale CDN.
|
|
84
|
+
*
|
|
85
|
+
* Permanently cached files can be deleted via a manual action in the Bytescale Dashboard.
|
|
86
|
+
*
|
|
87
|
+
* When cache=false this parameter is automatically set to false.
|
|
88
|
+
*
|
|
89
|
+
* When cachePermanently="auto" the permanent cache will only be used for files that take more than 1000ms to process.
|
|
90
|
+
*
|
|
91
|
+
* When the permanent cache is used, approximately 200ms of latency is added to the initial request. Thereafter, files will be served from the Bytescale CDN's edge cache or permanent cache, so will have minimal latency.
|
|
92
|
+
*
|
|
93
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
94
|
+
*/
|
|
95
|
+
cachePermanently?: "auto" | boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Set to true to return transformed files over 6MB in the initial HTTP response.
|
|
98
|
+
*
|
|
99
|
+
* By default, transformations that produce files larger than 6MB require a subsequent HTTP request to return the result: the initial HTTP request will process the file and return a JSON result instructing the requester the transformation has been performed. All subsequent requests will return the transformed file. Enable this flag to ensure the transformed file is always returned in the initial response.
|
|
100
|
+
*
|
|
101
|
+
* Recommendation: set large=true only if you require transformation results over 6MB. A small amount of latency is incurred on edge cache misses when this flag is enabled. In general, we recommend adjusting your transformation parameters to keep files below this size, instead of enabling this flag.
|
|
102
|
+
*
|
|
103
|
+
* Default: false
|
|
104
|
+
*/
|
|
105
|
+
large?: boolean;
|
|
106
|
+
}
|
|
107
|
+
export interface UrlBuilderParamsTransformationApiBase<T> {
|
|
108
|
+
/**
|
|
109
|
+
* Use the "params" field to pass parameters to the File Processing API.
|
|
110
|
+
*
|
|
111
|
+
* Use the "type" field to specify which File Processing API to use:
|
|
112
|
+
*
|
|
113
|
+
* - https://www.bytescale.com/docs/image-processing-api
|
|
114
|
+
* - https://www.bytescale.com/docs/video-processing-api
|
|
115
|
+
* - https://www.bytescale.com/docs/audio-processing-api
|
|
116
|
+
* - https://www.bytescale.com/docs/archive-processing-api
|
|
117
|
+
*
|
|
118
|
+
* To repeat a parameter (e.g. when adding multiple text layers to an image), use an array instead of an object, e.g.
|
|
119
|
+
*
|
|
120
|
+
* [ { text: "hello" }, { text: "world" } ]
|
|
121
|
+
*
|
|
122
|
+
* Order is sensitive both within and across parameter groups for certain transformation operations, please consult
|
|
123
|
+
* the documentation for the File Processing API you are using (see links above).
|
|
124
|
+
*/
|
|
125
|
+
params?: (T & UrlBuilderParamsTransformationOptions) | Array<T & UrlBuilderParamsTransformationOptions>;
|
|
126
|
+
}
|
|
127
|
+
export interface UrlBuilderParamsTransformationPreset {
|
|
128
|
+
params?: UrlBuilderParamsTransformationOptions;
|
|
129
|
+
/**
|
|
130
|
+
* The name of the transformation preset, as displayed in the Bytescale Dashboard.
|
|
131
|
+
*
|
|
132
|
+
* To specify transformation parameters on-the-fly, set "type" to a File Processing API (e.g. "image", "video", "audio"), and then use the "params" field to pass parameters to the File Processing API.
|
|
133
|
+
*/
|
|
134
|
+
preset: string;
|
|
135
|
+
/**
|
|
136
|
+
* Use a transformation preset that was created in the Bytescale Dashboard.
|
|
137
|
+
*
|
|
138
|
+
* To specify transformation parameters on-the-fly, set "type" to a File Processing API (e.g. "image", "video", "audio"), and then use the "params" field to pass parameters to the File Processing API.
|
|
139
|
+
*/
|
|
140
|
+
type: "preset";
|
|
141
|
+
}
|
|
142
|
+
export interface UrlBuilderParamsImageTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
143
|
+
/**
|
|
144
|
+
* Set to "image" to use Bytescale's Image Processing API:
|
|
145
|
+
*
|
|
146
|
+
* https://www.bytescale.com/docs/image-processing-api
|
|
147
|
+
*/
|
|
148
|
+
type: "image";
|
|
149
|
+
}
|
|
150
|
+
export interface UrlBuilderParamsVideoTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
151
|
+
/**
|
|
152
|
+
* Set to "video" to use Bytescale's Video Processing API:
|
|
153
|
+
*
|
|
154
|
+
* https://www.bytescale.com/docs/video-processing-api
|
|
155
|
+
*/
|
|
156
|
+
type: "video";
|
|
157
|
+
}
|
|
158
|
+
export interface UrlBuilderParamsAudioTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
159
|
+
/**
|
|
160
|
+
* Set to "audio" to use Bytescale's Audio Processing API:
|
|
161
|
+
*
|
|
162
|
+
* https://www.bytescale.com/docs/audio-processing-api
|
|
163
|
+
*/
|
|
164
|
+
type: "audio";
|
|
165
|
+
}
|
|
166
|
+
export interface UrlBuilderParamsArchiveTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
167
|
+
/**
|
|
168
|
+
* Set to "archive" to use Bytescale's Archive Processing API:
|
|
169
|
+
*
|
|
170
|
+
* https://www.bytescale.com/docs/archive-processing-api
|
|
171
|
+
*/
|
|
172
|
+
type: "archive";
|
|
173
|
+
}
|
|
@@ -10,22 +10,61 @@ import { ErrorResponse } from "./models";
|
|
|
10
10
|
* https://openapi-generator.tech
|
|
11
11
|
* Do not edit the class manually.
|
|
12
12
|
*/
|
|
13
|
-
export declare const BASE_PATH: string;
|
|
14
13
|
export interface BytescaleApiClientConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Required for Node.js: you must provide an instance of requires("node-fetch")
|
|
16
|
+
*
|
|
17
|
+
* Not required for the browser.
|
|
18
|
+
*/
|
|
15
19
|
fetchApi?: FetchAPI;
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Required for all environments. Must begin with "public_" or "secret_".
|
|
22
|
+
*
|
|
23
|
+
* Please note: if you require JWT-based auth, you must provide an API key to this field, and then call 'AuthManager.beginAuthSession' to start a JWT-based auth session. The JWT's permissions will be merged with the API key's permissions, with precedence given to the JWT.
|
|
24
|
+
*/
|
|
25
|
+
apiKey: string;
|
|
26
|
+
/**
|
|
27
|
+
* The base URL of the Bytescale API.
|
|
28
|
+
*/
|
|
29
|
+
apiUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The base URL of the Bytescale CDN.
|
|
32
|
+
*/
|
|
33
|
+
cdnUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Headers to include in all API requests.
|
|
36
|
+
*
|
|
37
|
+
* These headers take precedence over any headers automatically added by the SDK (e.g. "Authorization", "Content-Type", etc.).
|
|
38
|
+
*/
|
|
17
39
|
headers?: () => Promise<HTTPHeaders>;
|
|
18
40
|
}
|
|
41
|
+
export declare class BytescaleApiClientConfigResolver {
|
|
42
|
+
static defaultApiUrl: string;
|
|
43
|
+
static defaultCdnUrl: string;
|
|
44
|
+
static getApiUrl(config: BytescaleApiClientConfig): string;
|
|
45
|
+
static getCdnUrl(config: BytescaleApiClientConfig): string;
|
|
46
|
+
static getFetchApi(config: BytescaleApiClientConfig): FetchAPI;
|
|
47
|
+
}
|
|
19
48
|
/**
|
|
20
49
|
* This is the base class for all generated API classes.
|
|
21
50
|
*/
|
|
22
51
|
export declare class BaseAPI {
|
|
23
52
|
protected readonly config: BytescaleApiClientConfig;
|
|
53
|
+
protected static readonly specialApiKeys: string[];
|
|
54
|
+
protected static readonly specialApiKeyAccountId = "W142hJk";
|
|
55
|
+
protected static readonly accountIdLength = 7;
|
|
24
56
|
constructor(config: BytescaleApiClientConfig);
|
|
25
|
-
protected request(context: RequestOpts, initOverrides: RequestInit | InitOverrideFunction | undefined,
|
|
57
|
+
protected request(context: RequestOpts, initOverrides: RequestInit | InitOverrideFunction | undefined, baseUrlOverride: string | undefined): Promise<Response>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a successful response (2**) else throws an error.
|
|
60
|
+
*/
|
|
61
|
+
protected doFetch(url: string, init: RequestInit, isBytescaleApi: boolean): Promise<Response>;
|
|
26
62
|
protected encodeParam(paramName: string, paramValue: string): string;
|
|
27
63
|
private createFetchParams;
|
|
28
|
-
|
|
64
|
+
}
|
|
65
|
+
export declare class CancelledError extends Error {
|
|
66
|
+
name: "CancelledError";
|
|
67
|
+
constructor();
|
|
29
68
|
}
|
|
30
69
|
export declare class BytescaleApiError extends Error {
|
|
31
70
|
name: "BytescaleApiError";
|
|
@@ -48,15 +87,10 @@ export declare type HTTPRequestInit = {
|
|
|
48
87
|
method: HTTPMethod;
|
|
49
88
|
body?: HTTPBody;
|
|
50
89
|
};
|
|
51
|
-
export declare type ModelPropertyNaming = "camelCase" | "snake_case" | "PascalCase" | "original";
|
|
52
90
|
export declare type InitOverrideFunction = (requestContext: {
|
|
53
91
|
init: HTTPRequestInit;
|
|
54
92
|
context: RequestOpts;
|
|
55
93
|
}) => Promise<RequestInit>;
|
|
56
|
-
export interface FetchParams {
|
|
57
|
-
url: string;
|
|
58
|
-
init: RequestInit;
|
|
59
|
-
}
|
|
60
94
|
export interface RequestOpts {
|
|
61
95
|
path: string;
|
|
62
96
|
method: HTTPMethod;
|
|
@@ -69,13 +103,9 @@ export interface ApiResponse<T> {
|
|
|
69
103
|
raw: Response;
|
|
70
104
|
value(): Promise<T>;
|
|
71
105
|
}
|
|
72
|
-
export interface ResponseTransformer<T> {
|
|
73
|
-
(json: any): T;
|
|
74
|
-
}
|
|
75
106
|
export declare class JSONApiResponse<T> {
|
|
76
107
|
raw: Response;
|
|
77
|
-
|
|
78
|
-
constructor(raw: Response, transformer?: ResponseTransformer<T>);
|
|
108
|
+
constructor(raw: Response);
|
|
79
109
|
value(): Promise<T>;
|
|
80
110
|
}
|
|
81
111
|
export declare class VoidApiResponse {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytescale/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Bytescale JavaScript SDK",
|
|
5
5
|
"author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
38
38
|
"typecheck": "tsc --noEmit",
|
|
39
39
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --silent=false --verbose=false",
|
|
40
|
-
"prepack": "npm run clean && webpack && tsc-alias",
|
|
40
|
+
"prepack": "npm run clean && webpack && tsc-alias && rm dist/types/index.browser.d.ts && mv dist/types/index.node.d.ts dist/types/index.d.ts",
|
|
41
41
|
"postpack": "[ ! -f bytescale-sdk-*.tgz ] || mv bytescale-sdk-*.tgz bytescale-sdk.tgz",
|
|
42
42
|
"prepare": "husky install",
|
|
43
43
|
"prepack:cdn": "npm run clean && webpack --config webpack.config.cdn.js && find dist -name \"*.ts\" -type f -delete && for f in dist/*.js; do cp -- \"$f\" \"${f%.js}\"; done",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeChunkedStream } from "../src/
|
|
1
|
+
import { NodeChunkedStream } from "../src/private/NodeChunkedStream";
|
|
2
2
|
import { createRandomStreamFactory } from "./utils/RandomStream";
|
|
3
3
|
import { streamToBuffer } from "./utils/StreamToBuffer";
|
|
4
4
|
|