@bytescale/sdk 1.1.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.
Files changed (49) hide show
  1. package/dist/browser/cjs/main.js +1152 -1094
  2. package/dist/node/cjs/main.js +1156 -952
  3. package/dist/node/esm/main.mjs +1167 -933
  4. package/dist/types/index.d.ts +2 -2
  5. package/dist/types/private/AuthSessionState.d.ts +13 -0
  6. package/dist/types/private/ConsoleUtils.d.ts +5 -0
  7. package/dist/types/private/EnvChecker.d.ts +4 -0
  8. package/dist/types/private/Mutex.d.ts +16 -0
  9. package/dist/types/{uploads/ChunkedStream.d.ts → private/NodeChunkedStream.d.ts} +11 -4
  10. package/dist/types/private/StreamUtils.d.ts +8 -0
  11. package/dist/types/private/TypeUtils.d.ts +2 -0
  12. package/dist/types/private/UploadManagerBase.d.ts +43 -0
  13. package/dist/types/private/dtos/SetAccessTokenRequestDto.d.ts +6 -0
  14. package/dist/types/private/dtos/SetAccessTokenResponseDto.d.ts +7 -0
  15. package/dist/types/private/model/AddCancellationHandler.d.ts +1 -0
  16. package/dist/types/private/model/AuthManagerInterface.d.ts +44 -0
  17. package/dist/types/private/model/AuthSession.d.ts +7 -0
  18. package/dist/types/private/model/OnPartProgress.d.ts +1 -0
  19. package/dist/types/private/model/PreUploadInfo.d.ts +6 -0
  20. package/dist/types/private/model/PutUploadPartResult.d.ts +4 -0
  21. package/dist/types/private/model/UploadManagerInterface.d.ts +5 -0
  22. package/dist/types/private/model/UploadSourceProcessed.d.ts +18 -0
  23. package/dist/types/public/browser/AuthManagerBrowser.d.ts +20 -0
  24. package/dist/types/public/browser/UploadManagerBrowser.d.ts +17 -0
  25. package/dist/types/public/browser/index.d.ts +2 -0
  26. package/dist/types/public/node/AuthManagerNode.d.ts +6 -0
  27. package/dist/types/public/node/UploadManagerNode.d.ts +26 -0
  28. package/dist/types/public/node/index.d.ts +2 -0
  29. package/dist/types/{uploads/UploadModel.d.ts → public/shared/CommonTypes.d.ts} +8 -11
  30. package/dist/types/public/shared/UrlBuilder.d.ts +28 -0
  31. package/dist/types/public/shared/UrlBuilderTypes.d.ts +173 -0
  32. package/dist/types/{generated → public/shared/generated}/runtime.d.ts +44 -29
  33. package/dist/types/public/shared/index.d.ts +4 -0
  34. package/package.json +2 -2
  35. package/tests/ChunkedStream.test.ts +3 -3
  36. package/tests/UploadManager.test.ts +1 -1
  37. package/tests/UrlBuilder.test.ts +168 -0
  38. package/dist/browser/cjs/_70b2.main.js +0 -10
  39. package/dist/browser/cjs/_7392.main.js +0 -10
  40. package/dist/types/uploads/NodeUtils.d.ts +0 -13
  41. package/dist/types/uploads/UploadManager.d.ts +0 -39
  42. package/dist/types/uploads/index.d.ts +0 -3
  43. /package/dist/types/{generated → public/shared/generated}/apis/FileApi.d.ts +0 -0
  44. /package/dist/types/{generated → public/shared/generated}/apis/FolderApi.d.ts +0 -0
  45. /package/dist/types/{generated → public/shared/generated}/apis/JobApi.d.ts +0 -0
  46. /package/dist/types/{generated → public/shared/generated}/apis/UploadApi.d.ts +0 -0
  47. /package/dist/types/{generated → public/shared/generated}/apis/index.d.ts +0 -0
  48. /package/dist/types/{generated → public/shared/generated}/index.d.ts +0 -0
  49. /package/dist/types/{generated → public/shared/generated}/models/index.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- export * from "./generated";
2
- export * from "./uploads";
1
+ export * from "./public/shared";
2
+ export * from "./public/node";
@@ -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,5 @@
1
+ export declare class ConsoleUtils {
2
+ static error(message: string): void;
3
+ static warn(message: string): void;
4
+ private static prefix;
5
+ }
@@ -0,0 +1,4 @@
1
+ export declare class EnvChecker {
2
+ static isNodeJs(): boolean;
3
+ static methodRequiresBrowser(methodName: string): Error;
4
+ }
@@ -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,5 +1,14 @@
1
1
  /// <reference types="node" />
2
- export declare class ChunkedStream {
2
+ /**
3
+ * For Node.js streams only:
4
+ *
5
+ * Converts a stream into a stream of streams, where the next stream is requested via '.take(sizeInBytes: number): Stream'
6
+ *
7
+ * This allows the source stream to be sequentially read (in serial) as a sequence of sub-streams, for the purpose of
8
+ * issuing PutObject requests for a multipart upload, whereby each request requires its own stream, but where that stream
9
+ * needs to be a slice of the source stream.
10
+ */
11
+ export declare class NodeChunkedStream {
3
12
  private readonly source;
4
13
  private buffer;
5
14
  private consumer;
@@ -21,9 +30,7 @@ export declare class ChunkedStream {
21
30
  /**
22
31
  * Only call 'take' after the previously returned stream has been fully consumed.
23
32
  */
24
- take(bytes: number): Promise<NodeJS.ReadableStream>;
33
+ take(bytes: number): NodeJS.ReadableStream;
25
34
  private consumeFromBuffer;
26
35
  private splitBuffer;
27
- private emptyStream;
28
- private finishStream;
29
36
  }
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import type * as stream from "stream";
3
+ export declare class StreamUtils {
4
+ static create(): stream.Readable;
5
+ static empty(): NodeJS.ReadableStream;
6
+ static fromBuffer(buffer: Buffer): NodeJS.ReadableStream;
7
+ static endStream(readable: stream.Readable): void;
8
+ }
@@ -0,0 +1,2 @@
1
+ export declare function assertUnreachable(x: never): never;
2
+ export declare function isDefinedEntry<T, K extends string>(object: [K, T | undefined | null]): object is [K, T];
@@ -0,0 +1,43 @@
1
+ import { BytescaleApiClientConfig, FileDetails, UploadPart } from "../public/shared/generated";
2
+ import { UploadManagerInterface } from "./model/UploadManagerInterface";
3
+ import { PreUploadInfo } from "./model/PreUploadInfo";
4
+ import { UploadSourceBlob } from "./model/UploadSourceProcessed";
5
+ import { PutUploadPartResult } from "./model/PutUploadPartResult";
6
+ import { AddCancellationHandler } from "./model/AddCancellationHandler";
7
+ import { UploadManagerParams, UploadSource } from "../public/shared/CommonTypes";
8
+ /**
9
+ * Methods common to UploadManagerNode and UploadManagerBrowser.
10
+ */
11
+ export declare abstract class UploadManagerBase<TSource, TInit> implements UploadManagerInterface {
12
+ protected readonly config: BytescaleApiClientConfig;
13
+ protected readonly stringMimeType = "text/plain";
14
+ private readonly defaultMaxConcurrentUploadParts;
15
+ private readonly intervalMs;
16
+ private readonly uploadApi;
17
+ constructor(config: BytescaleApiClientConfig);
18
+ upload(request: UploadManagerParams): Promise<FileDetails>;
19
+ protected getBlobInfo({ value: { name, size, type } }: UploadSourceBlob): Partial<PreUploadInfo> & {
20
+ size: number;
21
+ };
22
+ protected abstract processUploadSource(data: UploadSource): TSource;
23
+ protected abstract getPreUploadInfoPartial(request: UploadManagerParams, source: TSource): Partial<PreUploadInfo> & {
24
+ size: number;
25
+ };
26
+ protected abstract preUpload(source: TSource): TInit;
27
+ protected abstract postUpload(init: TInit): Promise<void>;
28
+ protected abstract doPutUploadPart(part: UploadPart, contentLength: number, source: TSource, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<PutUploadPartResult>;
29
+ private onIntervalTick;
30
+ private makeCancellationMethods;
31
+ private makeProgressCallback;
32
+ private assertNotCancelled;
33
+ private isCancelled;
34
+ private beginUpload;
35
+ private uploadPart;
36
+ /**
37
+ * Returns etag for the part.
38
+ */
39
+ private putUploadPart;
40
+ private getUploadPart;
41
+ private getPreUploadInfo;
42
+ private mapAsync;
43
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sync with: bytescale > edge > SetAccessTokenRequestDto.ts
3
+ */
4
+ export interface SetAccessTokenRequestDto {
5
+ accessToken: string;
6
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sync with: upload > edge > SetAccessTokenResponseDto.ts
3
+ */
4
+ export interface SetAccessTokenResponseDto {
5
+ accessToken: string;
6
+ ttlSeconds: number;
7
+ }
@@ -0,0 +1 @@
1
+ export declare type AddCancellationHandler = (cancellationHandler: () => void) => void;
@@ -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,7 @@
1
+ export interface AuthSession {
2
+ accessToken: string | undefined;
3
+ accessTokenRefreshHandle: number | undefined;
4
+ authHeaders: () => Promise<Record<string, string>>;
5
+ authUrl: string;
6
+ isActive: boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export declare type OnPartProgress = (bytesSentDelta: number) => void;
@@ -0,0 +1,6 @@
1
+ export interface PreUploadInfo {
2
+ maxConcurrentUploadParts: number;
3
+ mime: string | undefined;
4
+ originalFileName: string | undefined;
5
+ size: number;
6
+ }
@@ -0,0 +1,4 @@
1
+ export interface PutUploadPartResult {
2
+ etag: string | undefined;
3
+ status: number;
4
+ }
@@ -0,0 +1,5 @@
1
+ import { UploadManagerParams } from "../../public/shared/CommonTypes";
2
+ import { FileDetails } from "../../public/shared/generated";
3
+ export interface UploadManagerInterface {
4
+ upload: (request: UploadManagerParams) => Promise<FileDetails>;
5
+ }
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import { BlobLike } from "../../public/shared/CommonTypes";
3
+ import { NodeChunkedStream } from "../NodeChunkedStream";
4
+ export interface UploadSourceBlob {
5
+ type: "Blob";
6
+ value: BlobLike;
7
+ }
8
+ export interface UploadSourceBuffer {
9
+ type: "Buffer";
10
+ value: Buffer;
11
+ }
12
+ export interface UploadSourceStream {
13
+ type: "Stream";
14
+ value: NodeChunkedStream;
15
+ }
16
+ export declare type UploadSourceProcessedIsomorphic = UploadSourceBlob;
17
+ export declare type UploadSourceProcessedBrowser = UploadSourceProcessedIsomorphic;
18
+ export declare type UploadSourceProcessedNode = UploadSourceStream | UploadSourceBuffer | UploadSourceProcessedIsomorphic;
@@ -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
+ }
@@ -0,0 +1,17 @@
1
+ import { UploadManagerBase } from "../../private/UploadManagerBase";
2
+ import { UploadSourceProcessedBrowser } from "../../private/model/UploadSourceProcessed";
3
+ import { PreUploadInfo } from "../../private/model/PreUploadInfo";
4
+ import { UploadPart } from "../shared/generated";
5
+ import { PutUploadPartResult } from "../../private/model/PutUploadPartResult";
6
+ import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
7
+ import { UploadManagerParams, UploadSource } from "../shared/CommonTypes";
8
+ export declare class UploadManager extends UploadManagerBase<UploadSourceProcessedBrowser, undefined> {
9
+ protected processUploadSource(data: UploadSource): UploadSourceProcessedBrowser;
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;
17
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./UploadManagerBrowser";
2
+ export * from "./AuthManagerBrowser";
@@ -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
+ }
@@ -0,0 +1,26 @@
1
+ import { UploadManagerBase } from "../../private/UploadManagerBase";
2
+ import { UploadSourceProcessedNode } from "../../private/model/UploadSourceProcessed";
3
+ import { NodeChunkedStream } from "../../private/NodeChunkedStream";
4
+ import { PreUploadInfo } from "../../private/model/PreUploadInfo";
5
+ import { UploadPart } from "../shared/generated";
6
+ import { AddCancellationHandler } from "../../private/model/AddCancellationHandler";
7
+ import { UploadManagerParams, UploadSource } from "../shared/CommonTypes";
8
+ declare type UploadManagerNodeInit = undefined | {
9
+ chunkedStream: NodeChunkedStream;
10
+ chunkedStreamPromise: Promise<void>;
11
+ };
12
+ export declare class UploadManager extends UploadManagerBase<UploadSourceProcessedNode, UploadManagerNodeInit> {
13
+ protected processUploadSource(data: UploadSource): UploadSourceProcessedNode;
14
+ protected getPreUploadInfoPartial(request: UploadManagerParams, data: UploadSourceProcessedNode): Partial<PreUploadInfo> & {
15
+ size: number;
16
+ };
17
+ protected preUpload(source: UploadSourceProcessedNode): UploadManagerNodeInit;
18
+ protected postUpload(init: UploadManagerNodeInit): Promise<void>;
19
+ protected doPutUploadPart(part: UploadPart, contentLength: number, source: UploadSourceProcessedNode, onProgress: (bytesSentDelta: number) => void, addCancellationHandler: AddCancellationHandler): Promise<{
20
+ etag: string | undefined;
21
+ status: number;
22
+ }>;
23
+ private coerceRequestBody;
24
+ private sliceDataForRequest;
25
+ }
26
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./UploadManagerNode";
2
+ export * from "./AuthManagerNode";
@@ -1,12 +1,9 @@
1
1
  /// <reference types="node" />
2
+ import { BeginMultipartUploadRequest } from "./generated";
2
3
  /**
3
- * Supported implementations:
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
- import { BeginMultipartUploadRequest } from "../generated";
9
- import { ChunkedStream } from "./ChunkedStream";
6
+ export declare const CommonTypesNoOp = false;
10
7
  export interface BlobLike {
11
8
  readonly name?: string;
12
9
  readonly size: number;
@@ -16,10 +13,10 @@ export interface BlobLike {
16
13
  export interface CancellationToken {
17
14
  isCancelled: boolean;
18
15
  }
19
- export declare class CancelledError extends Error {
20
- msg?: string | undefined;
21
- name: "CancelledError";
22
- constructor(msg?: string | undefined);
16
+ export interface UploadProgress {
17
+ bytesSent: number;
18
+ bytesTotal: number;
19
+ progress: number;
23
20
  }
24
21
  export declare type UploadSource = NodeJS.ReadableStream | BlobLike | Buffer | string;
25
22
  export interface UploadManagerParams extends Omit<BeginMultipartUploadRequest, "size" | "protocol"> {
@@ -27,9 +24,9 @@ export interface UploadManagerParams extends Omit<BeginMultipartUploadRequest, "
27
24
  cancellationToken?: CancellationToken;
28
25
  data: UploadSource;
29
26
  maxConcurrentUploadParts?: number;
27
+ onProgress?: (status: UploadProgress) => void;
30
28
  /**
31
29
  * Only required if 'data' is a 'ReadableStream'.
32
30
  */
33
31
  size?: number;
34
32
  }
35
- export declare type UploadSourceProcessed = ChunkedStream | BlobLike | Buffer;
@@ -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
+ }