@bytescale/sdk 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +391 -48
- package/dist/browser/cjs/main.js +723 -589
- package/dist/node/cjs/main.js +640 -263
- package/dist/node/esm/main.mjs +640 -263
- package/dist/types/index.d.ts +1 -1
- package/dist/types/private/AuthSessionState.d.ts +25 -8
- package/dist/types/private/EnvChecker.d.ts +1 -1
- package/dist/types/private/Mutex.d.ts +1 -1
- package/dist/types/private/StreamUtils.d.ts +1 -0
- package/dist/types/private/UploadManagerBase.d.ts +6 -1
- package/dist/types/private/UploadManagerBrowserWorkerBase.d.ts +19 -0
- package/dist/types/private/UploadManagerFetchUtils.d.ts +8 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +22 -5
- package/dist/types/private/model/AuthSession.d.ts +2 -2
- package/dist/types/private/model/OnPartProgress.d.ts +1 -1
- package/dist/types/private/model/UploadSourceProcessed.d.ts +6 -1
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +11 -6
- package/dist/types/public/browser/UploadManagerBrowser.d.ts +3 -12
- package/dist/types/public/node/AuthManagerNode.d.ts +8 -3
- package/dist/types/public/shared/CommonTypes.d.ts +0 -1
- package/dist/types/public/shared/UrlBuilder.d.ts +10 -11
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +65 -71
- package/dist/types/public/shared/generated/apis/FileApi.d.ts +104 -3
- package/dist/types/public/shared/generated/apis/FolderApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/JobApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/UploadApi.d.ts +6 -3
- package/dist/types/public/shared/generated/models/index.d.ts +5 -7
- package/dist/types/public/shared/generated/runtime.d.ts +7 -5
- package/dist/types/public/worker/UploadManagerWorker.d.ts +8 -0
- package/dist/types/public/worker/index.d.ts +2 -0
- package/dist/worker/cjs/main.js +2578 -0
- package/dist/worker/esm/main.mjs +2578 -0
- package/package.json +7 -8
- package/tests/UploadManager.test.ts +0 -7
- package/tests/UrlBuilder.test.ts +60 -59
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./public/shared";
|
|
2
|
-
export * from "./public/
|
|
2
|
+
export * from "./public/browser";
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { AuthSession } from "./model/AuthSession";
|
|
2
|
+
import { Mutex } from "./Mutex";
|
|
3
|
+
/**
|
|
4
|
+
* Maintains a global session state, even across package versions.
|
|
5
|
+
*
|
|
6
|
+
* This is to allow users to start auth sessions via the Bytescale JavaScript SDK, where due to versioning or other
|
|
7
|
+
* bundling issues, the Bytescale Upload Widget has been bundled with a different Bytescale JavaScript SDK. In this
|
|
8
|
+
* scenario, the user wouldn't be able to start an auth session with the Bytescale Upload Widget. Therefore, we use
|
|
9
|
+
* global state (i.e. on the window) to ensure the session state can be shared between the user's instance of the
|
|
10
|
+
* Bytescale JavaScript SDK and the Upload Widget's version of the Bytescale JavaScript SDK.
|
|
11
|
+
*
|
|
12
|
+
* Users also frequently have problems caused by them not keeping track of *Api and *Manager instances correctly, so
|
|
13
|
+
* making this global prevents a lot of common mistakes.
|
|
14
|
+
*/
|
|
2
15
|
export declare class AuthSessionState {
|
|
16
|
+
private static readonly stateKey;
|
|
17
|
+
private static readonly mutexKey;
|
|
3
18
|
/**
|
|
4
|
-
*
|
|
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.
|
|
19
|
+
* Called in the browser only.
|
|
11
20
|
*/
|
|
12
|
-
static
|
|
21
|
+
static getMutex(): Mutex;
|
|
22
|
+
/**
|
|
23
|
+
* Called in the browser only.
|
|
24
|
+
*/
|
|
25
|
+
static setSession(session: AuthSession | undefined): void;
|
|
26
|
+
/**
|
|
27
|
+
* Called in the browser and in Node.js (so we check the env before calling env-specific code).
|
|
28
|
+
*/
|
|
29
|
+
static getSession(): AuthSession | undefined;
|
|
13
30
|
}
|
|
@@ -3,6 +3,7 @@ import type * as stream from "stream";
|
|
|
3
3
|
export declare class StreamUtils {
|
|
4
4
|
static create(): stream.Readable;
|
|
5
5
|
static empty(): NodeJS.ReadableStream;
|
|
6
|
+
static fromArrayBuffer(buffer: ArrayBuffer): NodeJS.ReadableStream;
|
|
6
7
|
static fromBuffer(buffer: Buffer): NodeJS.ReadableStream;
|
|
7
8
|
static endStream(readable: stream.Readable): void;
|
|
8
9
|
}
|
|
@@ -11,6 +11,7 @@ import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes"
|
|
|
11
11
|
export declare abstract class UploadManagerBase<TSource, TInit> implements UploadManagerInterface {
|
|
12
12
|
protected readonly config: BytescaleApiClientConfig;
|
|
13
13
|
protected readonly stringMimeType = "text/plain";
|
|
14
|
+
private readonly accountId;
|
|
14
15
|
private readonly defaultMaxConcurrentUploadParts;
|
|
15
16
|
private readonly intervalMs;
|
|
16
17
|
private readonly uploadApi;
|
|
@@ -28,7 +29,11 @@ export declare abstract class UploadManagerBase<TSource, TInit> implements Uploa
|
|
|
28
29
|
protected abstract doPutUploadPart(part: UploadPart, contentLength: number, source: TSource, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
|
|
29
30
|
private onIntervalTick;
|
|
30
31
|
private makeCancellationMethods;
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
34
|
+
*/
|
|
35
|
+
private makeOnProgressForPartFactory;
|
|
36
|
+
private makeProgressEvent;
|
|
32
37
|
private assertNotCancelled;
|
|
33
38
|
private isCancelled;
|
|
34
39
|
private beginUpload;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UploadManagerBase } from "./UploadManagerBase";
|
|
2
|
+
import { UploadSourceProcessedBrowser, UploadSourceProcessedWorker } from "./model/UploadSourceProcessed";
|
|
3
|
+
import { PreUploadInfo } from "./model/PreUploadInfo";
|
|
4
|
+
import { UploadPart } from "../public/shared/generated";
|
|
5
|
+
import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes";
|
|
6
|
+
declare type BrowserOrWorkerUploadSource = UploadSourceProcessedBrowser | UploadSourceProcessedWorker;
|
|
7
|
+
/**
|
|
8
|
+
* The "browser" and "worker" runtimes support the same input types, but the former uses XHR and the latter uses Fetch.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class UploadManagerBrowserWorkerBase extends UploadManagerBase<BrowserOrWorkerUploadSource, undefined> {
|
|
11
|
+
protected processUploadSource(data: UploadSource): BrowserOrWorkerUploadSource;
|
|
12
|
+
protected getPreUploadInfoPartial(_request: UploadManagerParams, data: BrowserOrWorkerUploadSource): Partial<PreUploadInfo> & {
|
|
13
|
+
size: number;
|
|
14
|
+
};
|
|
15
|
+
protected preUpload(_source: BrowserOrWorkerUploadSource): undefined;
|
|
16
|
+
protected postUpload(_init: undefined): Promise<void>;
|
|
17
|
+
protected getRequestBody(part: UploadPart, blob: BrowserOrWorkerUploadSource): Blob | ArrayBuffer;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BytescaleApiClientConfig, UploadPart } from "../public/shared";
|
|
2
|
+
import { AddCancellationHandler } from "./model/AddCancellationHandler";
|
|
3
|
+
export declare class UploadManagerFetchUtils {
|
|
4
|
+
static doPutUploadPart(config: BytescaleApiClientConfig, part: UploadPart, content: BodyInit, contentLength: number, addCancellationHandler: AddCancellationHandler): Promise<{
|
|
5
|
+
etag: string | undefined;
|
|
6
|
+
status: number;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import { BytescaleApiClientConfig } from "../../public/shared";
|
|
2
|
+
export interface BeginAuthSessionParams {
|
|
3
|
+
/**
|
|
4
|
+
* The account ID to authorize requests for.
|
|
5
|
+
*/
|
|
6
|
+
accountId: string;
|
|
7
|
+
/**
|
|
8
|
+
* Headers to send to your backend API.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: do not call 'AuthManager.beginAuthSession' or 'AuthManager.endAuthSession' inside this callback, as this will cause a deadlock.
|
|
11
|
+
*/
|
|
12
|
+
authHeaders: () => Promise<Record<string, string>>;
|
|
13
|
+
/**
|
|
14
|
+
* The fully-qualified URL for your backend API's auth endpoint.
|
|
15
|
+
*/
|
|
16
|
+
authUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional configuration.
|
|
19
|
+
*/
|
|
20
|
+
options?: Pick<BytescaleApiClientConfig, "fetchApi" | "cdnUrl">;
|
|
21
|
+
}
|
|
1
22
|
export interface AuthManagerInterface {
|
|
2
23
|
/**
|
|
3
24
|
* Begins an authenticated Bytescale API and Bytescale CDN session.
|
|
@@ -21,12 +42,8 @@ export interface AuthManagerInterface {
|
|
|
21
42
|
* 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
43
|
*
|
|
23
44
|
* 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
45
|
*/
|
|
29
|
-
beginAuthSession: (
|
|
46
|
+
beginAuthSession: (params: BeginAuthSessionParams) => Promise<void>;
|
|
30
47
|
/**
|
|
31
48
|
* Ends an authenticated Bytescale API and Bytescale CDN session.
|
|
32
49
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { BeginAuthSessionParams } from "./AuthManagerInterface";
|
|
1
2
|
export interface AuthSession {
|
|
2
3
|
accessToken: string | undefined;
|
|
3
4
|
accessTokenRefreshHandle: number | undefined;
|
|
4
|
-
authHeaders: () => Promise<Record<string, string>>;
|
|
5
|
-
authUrl: string;
|
|
6
5
|
isActive: boolean;
|
|
6
|
+
params: BeginAuthSessionParams;
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare type OnPartProgress = (
|
|
1
|
+
export declare type OnPartProgress = (bytesSentTotalForPart: number) => void;
|
|
@@ -9,10 +9,15 @@ export interface UploadSourceBuffer {
|
|
|
9
9
|
type: "Buffer";
|
|
10
10
|
value: Buffer;
|
|
11
11
|
}
|
|
12
|
+
export interface UploadSourceArrayBuffer {
|
|
13
|
+
type: "ArrayBuffer";
|
|
14
|
+
value: ArrayBuffer;
|
|
15
|
+
}
|
|
12
16
|
export interface UploadSourceStream {
|
|
13
17
|
type: "Stream";
|
|
14
18
|
value: NodeChunkedStream;
|
|
15
19
|
}
|
|
16
|
-
export declare type UploadSourceProcessedIsomorphic = UploadSourceBlob;
|
|
20
|
+
export declare type UploadSourceProcessedIsomorphic = UploadSourceBlob | UploadSourceArrayBuffer;
|
|
17
21
|
export declare type UploadSourceProcessedBrowser = UploadSourceProcessedIsomorphic;
|
|
22
|
+
export declare type UploadSourceProcessedWorker = UploadSourceProcessedIsomorphic;
|
|
18
23
|
export declare type UploadSourceProcessedNode = UploadSourceStream | UploadSourceBuffer | UploadSourceProcessedIsomorphic;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
-
|
|
3
|
-
export declare class AuthManager extends BaseAPI implements AuthManagerInterface {
|
|
4
|
-
private readonly accessTokenUrl;
|
|
1
|
+
import { AuthManagerInterface, BeginAuthSessionParams } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
declare class AuthManagerImpl implements AuthManagerInterface {
|
|
5
3
|
private readonly authSessionMutex;
|
|
6
4
|
private readonly contentType;
|
|
7
5
|
private readonly contentTypeJson;
|
|
8
6
|
private readonly contentTypeText;
|
|
9
7
|
private readonly minJwtTtlSeconds;
|
|
8
|
+
private readonly maxJwtTtlSeconds;
|
|
10
9
|
private readonly retryAuthAfterErrorSeconds;
|
|
11
10
|
private readonly refreshBeforeExpirySeconds;
|
|
12
|
-
constructor(
|
|
11
|
+
constructor();
|
|
13
12
|
isAuthSessionActive(): boolean;
|
|
14
|
-
beginAuthSession(
|
|
13
|
+
beginAuthSession(params: BeginAuthSessionParams): Promise<void>;
|
|
15
14
|
endAuthSession(): Promise<void>;
|
|
16
15
|
private refreshAccessToken;
|
|
16
|
+
private getAccessTokenUrl;
|
|
17
17
|
private deleteAccessToken;
|
|
18
18
|
private setAccessToken;
|
|
19
19
|
private getAccessToken;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
23
|
+
*/
|
|
24
|
+
export declare const AuthManager: AuthManagerImpl;
|
|
25
|
+
export {};
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { UploadManagerBase } from "../../private/UploadManagerBase";
|
|
2
1
|
import { UploadSourceProcessedBrowser } from "../../private/model/UploadSourceProcessed";
|
|
3
|
-
import { PreUploadInfo } from "../../private/model/PreUploadInfo";
|
|
4
2
|
import { UploadPart } from "../shared/generated";
|
|
5
3
|
import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
|
|
6
4
|
import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
|
|
7
|
-
import {
|
|
8
|
-
export declare class UploadManager extends
|
|
9
|
-
protected
|
|
10
|
-
protected getPreUploadInfoPartial(_request: UploadManagerParams, data: UploadSourceProcessedBrowser): Partial<PreUploadInfo> & {
|
|
11
|
-
size: number;
|
|
12
|
-
};
|
|
13
|
-
protected preUpload(_source: UploadSourceProcessedBrowser): undefined;
|
|
14
|
-
protected postUpload(_init: undefined): Promise<void>;
|
|
15
|
-
protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedBrowser, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
|
|
16
|
-
private getRequestBody;
|
|
5
|
+
import { UploadManagerBrowserWorkerBase } from "../../private/UploadManagerBrowserWorkerBase";
|
|
6
|
+
export declare class UploadManager extends UploadManagerBrowserWorkerBase {
|
|
7
|
+
protected doPutUploadPart(part: UploadPart, _contentLength: number, source: UploadSourceProcessedBrowser, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
|
|
17
8
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
-
|
|
3
|
-
beginAuthSession(
|
|
1
|
+
import { AuthManagerInterface, BeginAuthSessionParams } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
declare class AuthManagerImpl implements AuthManagerInterface {
|
|
3
|
+
beginAuthSession(_params: BeginAuthSessionParams): Promise<void>;
|
|
4
4
|
endAuthSession(): Promise<void>;
|
|
5
5
|
isAuthSessionActive(): boolean;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
9
|
+
*/
|
|
10
|
+
export declare const AuthManager: AuthManagerImpl;
|
|
11
|
+
export {};
|
|
@@ -20,7 +20,6 @@ export interface UploadProgress {
|
|
|
20
20
|
}
|
|
21
21
|
export declare type UploadSource = NodeJS.ReadableStream | BlobLike | Buffer | string;
|
|
22
22
|
export interface UploadManagerParams extends Omit<BeginMultipartUploadRequest, "size" | "protocol"> {
|
|
23
|
-
accountId: string;
|
|
24
23
|
cancellationToken?: CancellationToken;
|
|
25
24
|
data: UploadSource;
|
|
26
25
|
maxConcurrentUploadParts?: number;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlBuilderParams } from "./UrlBuilderTypes";
|
|
2
2
|
export declare class UrlBuilder {
|
|
3
|
-
private readonly cdnUrl;
|
|
4
|
-
constructor(config?: UrlBuilderConfig);
|
|
5
3
|
/**
|
|
6
4
|
* Builds a URL to either a raw file or a transformed file.
|
|
7
5
|
*
|
|
@@ -21,12 +19,13 @@ export declare class UrlBuilder {
|
|
|
21
19
|
*
|
|
22
20
|
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
23
21
|
*/
|
|
24
|
-
url(params: UrlBuilderParams): string;
|
|
25
|
-
private raw;
|
|
26
|
-
private transformation;
|
|
27
|
-
private getBaseUrl;
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
private
|
|
22
|
+
static url(params: UrlBuilderParams): string;
|
|
23
|
+
private static raw;
|
|
24
|
+
private static transformation;
|
|
25
|
+
private static getBaseUrl;
|
|
26
|
+
private static getCommonTransformationQueryParams;
|
|
27
|
+
private static getCommonQueryParams;
|
|
28
|
+
private static makeQueryParams;
|
|
29
|
+
private static getTransformationParams;
|
|
30
|
+
private static addQueryParams;
|
|
32
31
|
}
|
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
export declare const UrlBuilderTypesNoOp = false;
|
|
5
5
|
export declare type ParameterGroup = Record<string, string | number | boolean | undefined | null>;
|
|
6
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
7
|
export interface UrlBuilderParams {
|
|
14
8
|
/**
|
|
15
9
|
* The account that manages the file.
|
|
@@ -26,7 +20,10 @@ export interface UrlBuilderParams {
|
|
|
26
20
|
*/
|
|
27
21
|
options?: UrlBuilderOptions;
|
|
28
22
|
}
|
|
29
|
-
export
|
|
23
|
+
export declare type UrlBuilderOptions = UrlBuilderOptionsRaw | UrlBuilderTransformationOptions;
|
|
24
|
+
export declare type UrlBuilderTransformationOptions = UrlBuilderTransformationApiOptions | UrlBuilderOptionsPreset;
|
|
25
|
+
export declare type UrlBuilderTransformationApiOptions = UrlBuilderOptionsImage | UrlBuilderOptionsVideo | UrlBuilderOptionsAudio | UrlBuilderOptionsArchive;
|
|
26
|
+
export interface UrlBuilderOptionsBase {
|
|
30
27
|
/**
|
|
31
28
|
* Set to 'true' to download a private file. Requires an active auth session. See AuthManager.beginAuthSession.
|
|
32
29
|
*
|
|
@@ -57,7 +54,6 @@ export interface UrlBuilderOptions {
|
|
|
57
54
|
* Default: false
|
|
58
55
|
*/
|
|
59
56
|
forceDownloadPrompt?: boolean;
|
|
60
|
-
transformation?: UrlBuilderParamsTransformation;
|
|
61
57
|
/**
|
|
62
58
|
* Downloads the latest version of your file (if you have overwritten it) when added to the URL with a unique value.
|
|
63
59
|
*
|
|
@@ -67,48 +63,55 @@ export interface UrlBuilderOptions {
|
|
|
67
63
|
*/
|
|
68
64
|
version?: string;
|
|
69
65
|
}
|
|
70
|
-
export
|
|
71
|
-
|
|
66
|
+
export interface UrlBuilderOptionsRaw extends UrlBuilderOptionsBase {
|
|
67
|
+
transformation?: undefined;
|
|
68
|
+
}
|
|
69
|
+
export interface UrlBuilderOptionsImage extends UrlBuilderOptionsTransformationApi<ParameterGroup> {
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* Some transformations produce multiple files. The 'artifact' parameter is used to select which file to download.
|
|
76
|
-
*
|
|
77
|
-
* Must begin with: "/"
|
|
71
|
+
* Set to "image" to use Bytescale's Image Processing API:
|
|
78
72
|
*
|
|
79
|
-
*
|
|
73
|
+
* https://www.bytescale.com/docs/image-processing-api
|
|
80
74
|
*/
|
|
81
|
-
|
|
75
|
+
transformation: "image";
|
|
76
|
+
}
|
|
77
|
+
export interface UrlBuilderOptionsVideo extends UrlBuilderOptionsTransformationApi<ParameterGroup> {
|
|
82
78
|
/**
|
|
83
|
-
*
|
|
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.
|
|
79
|
+
* Set to "video" to use Bytescale's Video Processing API:
|
|
92
80
|
*
|
|
93
|
-
*
|
|
81
|
+
* https://www.bytescale.com/docs/video-processing-api
|
|
94
82
|
*/
|
|
95
|
-
|
|
83
|
+
transformation: "video";
|
|
84
|
+
}
|
|
85
|
+
export interface UrlBuilderOptionsAudio extends UrlBuilderOptionsTransformationApi<ParameterGroup> {
|
|
96
86
|
/**
|
|
97
|
-
* Set to
|
|
87
|
+
* Set to "audio" to use Bytescale's Audio Processing API:
|
|
98
88
|
*
|
|
99
|
-
*
|
|
89
|
+
* https://www.bytescale.com/docs/audio-processing-api
|
|
90
|
+
*/
|
|
91
|
+
transformation: "audio";
|
|
92
|
+
}
|
|
93
|
+
export interface UrlBuilderOptionsArchive extends UrlBuilderOptionsTransformationApi<ParameterGroup> {
|
|
94
|
+
/**
|
|
95
|
+
* Set to "archive" to use Bytescale's Archive Processing API:
|
|
100
96
|
*
|
|
101
|
-
*
|
|
97
|
+
* https://www.bytescale.com/docs/archive-processing-api
|
|
98
|
+
*/
|
|
99
|
+
transformation: "archive";
|
|
100
|
+
}
|
|
101
|
+
export interface UrlBuilderOptionsPreset extends UrlBuilderOptionsTransformation {
|
|
102
|
+
transformation: "preset";
|
|
103
|
+
/**
|
|
104
|
+
* The name of the transformation preset, as displayed in the Bytescale Dashboard.
|
|
102
105
|
*
|
|
103
|
-
*
|
|
106
|
+
* To specify transformation parameters on-the-fly, set "transformation" to a File Processing API (e.g. "image", "video", "audio"), and then use the "transformationParams" field to pass parameters to the File Processing API.
|
|
104
107
|
*/
|
|
105
|
-
|
|
108
|
+
transformationPreset: string;
|
|
106
109
|
}
|
|
107
|
-
export interface
|
|
110
|
+
export interface UrlBuilderOptionsTransformationApi<T> extends UrlBuilderOptionsTransformation {
|
|
108
111
|
/**
|
|
109
|
-
* Use the "
|
|
112
|
+
* Use the "transformationParams" field to pass parameters to the File Processing API.
|
|
110
113
|
*
|
|
111
|
-
* Use the "
|
|
114
|
+
* Use the "transformation" field to specify which File Processing API to use:
|
|
112
115
|
*
|
|
113
116
|
* - https://www.bytescale.com/docs/image-processing-api
|
|
114
117
|
* - https://www.bytescale.com/docs/video-processing-api
|
|
@@ -122,52 +125,43 @@ export interface UrlBuilderParamsTransformationApiBase<T> {
|
|
|
122
125
|
* Order is sensitive both within and across parameter groups for certain transformation operations, please consult
|
|
123
126
|
* the documentation for the File Processing API you are using (see links above).
|
|
124
127
|
*/
|
|
125
|
-
|
|
128
|
+
transformationParams?: T | T[];
|
|
126
129
|
}
|
|
127
|
-
export interface
|
|
128
|
-
params?: UrlBuilderParamsTransformationOptions;
|
|
130
|
+
export interface UrlBuilderOptionsTransformation extends UrlBuilderOptionsBase {
|
|
129
131
|
/**
|
|
130
|
-
* The
|
|
132
|
+
* The transformation artifact to download.
|
|
131
133
|
*
|
|
132
|
-
*
|
|
133
|
-
*/
|
|
134
|
-
preset: string;
|
|
135
|
-
/**
|
|
136
|
-
* Use a transformation preset that was created in the Bytescale Dashboard.
|
|
134
|
+
* Some transformations produce multiple files. The 'artifact' parameter is used to select which file to download.
|
|
137
135
|
*
|
|
138
|
-
*
|
|
139
|
-
*/
|
|
140
|
-
type: "preset";
|
|
141
|
-
}
|
|
142
|
-
export interface UrlBuilderParamsImageTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
143
|
-
/**
|
|
144
|
-
* Set to "image" to use Bytescale's Image Processing API:
|
|
136
|
+
* Must begin with: "/"
|
|
145
137
|
*
|
|
146
|
-
*
|
|
138
|
+
* Default: "/"
|
|
147
139
|
*/
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
export interface UrlBuilderParamsVideoTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
140
|
+
artifact?: string;
|
|
151
141
|
/**
|
|
152
|
-
*
|
|
142
|
+
* Specifies whether to permanently cache the transformed result in the Bytescale CDN.
|
|
153
143
|
*
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
type: "video";
|
|
157
|
-
}
|
|
158
|
-
export interface UrlBuilderParamsAudioTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
159
|
-
/**
|
|
160
|
-
* Set to "audio" to use Bytescale's Audio Processing API:
|
|
144
|
+
* Permanently cached files can be deleted via a manual action in the Bytescale Dashboard.
|
|
161
145
|
*
|
|
162
|
-
*
|
|
146
|
+
* When cache=false this parameter is automatically set to false.
|
|
147
|
+
*
|
|
148
|
+
* When cachePermanently="auto" the permanent cache will only be used for files that take more than 1000ms to process.
|
|
149
|
+
*
|
|
150
|
+
* 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.
|
|
151
|
+
*
|
|
152
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
163
153
|
*/
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
export interface UrlBuilderParamsArchiveTransformation extends UrlBuilderParamsTransformationApiBase<ParameterGroup> {
|
|
154
|
+
cachePermanently?: "auto" | boolean;
|
|
167
155
|
/**
|
|
168
|
-
*
|
|
156
|
+
* Only set this parameter to `true` if you expect the HTTP response body for the transformation request to be over 6MB.
|
|
169
157
|
*
|
|
170
|
-
*
|
|
158
|
+
* We recommend leaving this parameter unset (so it defaults to `false`) and controlling the HTTP response body size via transformation parameters. E.g. for Image Processing API requests, you can shrink the HTTP response body by reducing the output image's dimensions and/or quality.
|
|
159
|
+
*
|
|
160
|
+
* Setting this parameter to `true` will route the request via an alternative CDN path, which allows responses over 6MB, but incurs a ~200ms latency on all CDN edge cache misses for the URL.
|
|
161
|
+
*
|
|
162
|
+
* Setting this parameter to `false` (default) results in faster routing. If a response over 6MB is returned, the initial response will be a JSON error indicating the response was too large to return. All subsequent requests to the same URL will successfully return the transformed file (forever).
|
|
163
|
+
*
|
|
164
|
+
* Default: false
|
|
171
165
|
*/
|
|
172
|
-
|
|
166
|
+
large?: boolean;
|
|
173
167
|
}
|
|
@@ -30,8 +30,25 @@ export interface DeleteFileBatchOperationParams {
|
|
|
30
30
|
export interface DownloadFileParams {
|
|
31
31
|
accountId: string;
|
|
32
32
|
filePath: string;
|
|
33
|
+
/**
|
|
34
|
+
* Specifies whether to cache the raw file in the Bytescale CDN.
|
|
35
|
+
*
|
|
36
|
+
* Default: true
|
|
37
|
+
*/
|
|
33
38
|
cache?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 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.
|
|
41
|
+
*
|
|
42
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
43
|
+
*/
|
|
34
44
|
cacheTtl?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Downloads the latest version of your file (if you have overwritten it) when added to the URL with a unique value.
|
|
47
|
+
*
|
|
48
|
+
* The value of the `version` parameter can be anything, e.g. an incremental number, a timestamp, etc.
|
|
49
|
+
*
|
|
50
|
+
* You only need to provide and update this value if/when you overwrite your file.
|
|
51
|
+
*/
|
|
35
52
|
version?: string;
|
|
36
53
|
}
|
|
37
54
|
export interface GetFileDetailsParams {
|
|
@@ -41,29 +58,113 @@ export interface GetFileDetailsParams {
|
|
|
41
58
|
export interface ProcessFileParams {
|
|
42
59
|
accountId: string;
|
|
43
60
|
filePath: string;
|
|
61
|
+
/**
|
|
62
|
+
* The name of the File Processing API (e.g. "image", "video", "audio") or transformation preset (created in the Bytescale Dashboard) to use when processing the file.
|
|
63
|
+
*/
|
|
44
64
|
transformation: string;
|
|
65
|
+
/**
|
|
66
|
+
* Some transformations output multiple files, called artifacts.
|
|
67
|
+
*
|
|
68
|
+
* You can download each individual transformation artifact by specifying its path with this parameter
|
|
69
|
+
*/
|
|
45
70
|
artifact?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Specifies whether to cache the transformed result.
|
|
73
|
+
*
|
|
74
|
+
* If set to `false` the transformation will be executed on every request.
|
|
75
|
+
*
|
|
76
|
+
* *Recommendation:* instead of disabling the cache, a more performant solution is to use the `version` parameter and to increment it each time you require an updated result.
|
|
77
|
+
*
|
|
78
|
+
* Default: true
|
|
79
|
+
*/
|
|
46
80
|
cache?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Specifies whether to cache the transformed result in the Bytescale CDN perma-cache.
|
|
83
|
+
*
|
|
84
|
+
* Perma-caching works by storing your file permanently, or until a manual cache purge is performed.
|
|
85
|
+
*
|
|
86
|
+
* When `cache=false` this parameter is automatically set to `false`.
|
|
87
|
+
*
|
|
88
|
+
* When `cache_perm=auto` the perma-cache will only be used for files that take more than 1000ms to process.
|
|
89
|
+
*
|
|
90
|
+
* When the perma-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 perma-cache, so will have minimal latency.
|
|
91
|
+
*
|
|
92
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
93
|
+
*/
|
|
47
94
|
cachePerm?: ProcessFileCachePermEnum;
|
|
95
|
+
/**
|
|
96
|
+
* Specifies the maximum amount of time, in seconds, the transformed result will be cached on the user's device and in the Bytescale CDN's edge cache.
|
|
97
|
+
*
|
|
98
|
+
* If the file is perma-cached, then the file will not be reprocessed on edge cache misses.
|
|
99
|
+
*
|
|
100
|
+
* If the file is not perma-cached, then the file will be reprocessed on edge cache misses.
|
|
101
|
+
*
|
|
102
|
+
* For more information on perma-caching, see: `cache_perm`
|
|
103
|
+
*
|
|
104
|
+
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
|
|
105
|
+
*/
|
|
48
106
|
cacheTtl?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Only set this parameter to `true` if you expect the HTTP response body for the transformation request to be over 6MB.
|
|
109
|
+
*
|
|
110
|
+
* We recommend leaving this parameter unset (so it defaults to `false`) and controlling the HTTP response body size via transformation parameters. E.g. for Image Processing API requests, you can shrink the HTTP response body by reducing the output image's dimensions and/or quality.
|
|
111
|
+
*
|
|
112
|
+
* Setting this parameter to `true` will route the request via an alternative CDN path, which allows responses over 6MB, but incurs a ~200ms latency on all CDN edge cache misses for the URL.
|
|
113
|
+
*
|
|
114
|
+
* Setting this parameter to `false` (default) results in faster routing. If a response over 6MB is returned, the initial response will be a JSON error indicating the response was too large to return. All subsequent requests to the same URL will successfully return the transformed file (forever).
|
|
115
|
+
*
|
|
116
|
+
* Default: `false`
|
|
117
|
+
*/
|
|
49
118
|
large?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Parameters to submit to the File Processing API (e.g. the Image Processing API).
|
|
121
|
+
*
|
|
122
|
+
* Please see the documentation for each File Processing API to determine which values can appear here:
|
|
123
|
+
*
|
|
124
|
+
* - https://www.bytescale.com/docs/image-processing-api
|
|
125
|
+
* - https://www.bytescale.com/docs/video-processing-api
|
|
126
|
+
* - https://www.bytescale.com/docs/audio-processing-api
|
|
127
|
+
* - https://www.bytescale.com/docs/archive-processing-api
|
|
128
|
+
*/
|
|
50
129
|
transformationParams?: {
|
|
51
130
|
[key: string]: ProcessFileTransformationParamsParameterValue;
|
|
52
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Add this parameter and increment its value to force the file to be reprocessed.
|
|
134
|
+
*
|
|
135
|
+
* The Bytescale CDN caches files based on the full URL (including the querystring), meaning this parameter is useful when dealing with changes made to transformation presets. By contrast, File Processing APIs (like the Image Processing API) shouldn't ever require this parameter, since the URL/querystring naturally changes each time you adjust a parameter, causing a cache miss and the file to be reprocessed with the new querystring parameters.
|
|
136
|
+
*
|
|
137
|
+
* The value of the `version` parameter can be anything, e.g. an incremental number, a timestamp, etc.
|
|
138
|
+
*
|
|
139
|
+
* You only need to provide and update this value if/when you make changes to a transformation preset's settings.
|
|
140
|
+
*/
|
|
53
141
|
version?: string;
|
|
54
142
|
}
|
|
55
143
|
export interface ProcessFileAndSaveOperationParams {
|
|
56
144
|
accountId: string;
|
|
57
145
|
filePath: string;
|
|
146
|
+
/**
|
|
147
|
+
* The name of the File Processing API (e.g. "image", "video", "audio") or transformation preset (created in the Bytescale Dashboard) to use when processing the file.
|
|
148
|
+
*/
|
|
58
149
|
transformation: string;
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
*/
|
|
59
153
|
processFileAndSaveRequest: ProcessFileAndSaveRequest;
|
|
154
|
+
/**
|
|
155
|
+
* Parameters to submit to the File Processing API (e.g. the Image Processing API).
|
|
156
|
+
*
|
|
157
|
+
* Please see the documentation for each File Processing API to determine which values can appear here:
|
|
158
|
+
*
|
|
159
|
+
* - https://www.bytescale.com/docs/image-processing-api
|
|
160
|
+
* - https://www.bytescale.com/docs/video-processing-api
|
|
161
|
+
* - https://www.bytescale.com/docs/audio-processing-api
|
|
162
|
+
* - https://www.bytescale.com/docs/archive-processing-api
|
|
163
|
+
*/
|
|
60
164
|
transformationParams?: {
|
|
61
165
|
[key: string]: ProcessFileTransformationParamsParameterValue;
|
|
62
166
|
};
|
|
63
167
|
}
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
168
|
export declare class FileApi extends runtime.BaseAPI {
|
|
68
169
|
/**
|
|
69
170
|
* Copies a file synchronously.
|