@imagekit/javascript 5.1.0 → 5.2.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.
@@ -1,37 +1,4 @@
1
- interface TransformationObject {
2
- type: "transformation";
3
- value: string;
4
- }
5
- interface GifToVideoOrThumbnailObject {
6
- type: "gif-to-video" | "thumbnail";
7
- value?: string;
8
- }
9
- interface AbsObject {
10
- type: "abs";
11
- value: string;
12
- protocol: "hls" | "dash";
13
- }
14
- type PostTransformation = TransformationObject | GifToVideoOrThumbnailObject | AbsObject;
15
- interface Transformation {
16
- /**
17
- * Specifies pre-transformations to be applied. Must be a valid string of transformations like "w-300,h-300".
18
- * Refer to the docs for more details on transformations.
19
- *
20
- * {@link https://imagekit.io/docs/dam/pre-and-post-transformation-on-upload#pre-transformation}
21
- */
22
- pre?: string;
23
- /**
24
- * Specifies post-transformations to be applied. This is an array of transformation objects, each with:
25
- * - type: One of "transformation", "gif-to-video", "thumbnail", or "abs".
26
- * - value: A valid transformation string required if "type" is "transformation" or "abs". Optional if "type" is "gif-to-video" or "thumbnail".
27
- * - protocol: Used only when type is "abs". Can be "hls" or "dash".
28
- *
29
- * Refer to the docs for more details on transformations and usage in post.
30
- *
31
- * {@link https://imagekit.io/docs/dam/pre-and-post-transformation-on-upload#post-transformation}
32
- */
33
- post?: PostTransformation[];
34
- }
1
+ import * as Shared from './shared';
35
2
  /**
36
3
  * Options used when uploading a file using the V1 API.
37
4
  * Check out the official documentation:
@@ -39,122 +6,182 @@ interface Transformation {
39
6
  */
40
7
  export interface UploadOptions {
41
8
  /**
42
- * This field accepts three main input formats for the file content:
43
- * - "binary": Directly pass the binary data. Typically used when uploading via the browser using a File or Blob.
44
- * - "base64": A base64-encoded string of the file content.
45
- * - "url": A direct URL from which ImageKit server will download the file and upload.
9
+ * The API accepts any of the following:
10
+ *
11
+ * - **Binary data** send the raw bytes as `multipart/form-data`.
12
+ * - **HTTP / HTTPS URL** a publicly reachable URL that ImageKit’s servers can
13
+ * fetch.
14
+ * - **Base64 string** – the file encoded as a Base64 data URI or plain Base64.
15
+ *
16
+ * When supplying a URL, the server must receive the response headers within 8
17
+ * seconds; otherwise the request fails with 400 Bad Request.
46
18
  */
47
19
  file: string | Blob | File;
48
20
  /**
49
- * The name with which the file should be uploaded.
50
- * - Valid characters: alphanumeric (a-z, A-Z, 0-9, including Unicode letters and numerals) and the special chars ". _ -"
51
- * - Any other character (including space) is replaced with "_"
21
+ * The name with which the file has to be uploaded. The file name can contain:
22
+ *
23
+ * - Alphanumeric Characters: `a-z`, `A-Z`, `0-9`.
24
+ * - Special Characters: `.`, `-`
52
25
  *
53
- * Example: "company_logo.png"
26
+ * Any other character including space will be replaced by `_`
54
27
  */
55
28
  fileName: string;
56
29
  /**
57
- * The HMAC-SHA1 digest of the concatenation of "token + expire". The signing key is your ImageKit private API key.
58
- * Required for client-side authentication. Must be computed on the server side.
59
- * Calculate this signature in your secure server and pass it to the client.
30
+ * A unique value that the ImageKit.io server will use to recognize and prevent
31
+ * subsequent retries for the same request. We suggest using V4 UUIDs, or another
32
+ * random string with enough entropy to avoid collisions.
33
+ *
34
+ * **Note**: Sending a value that has been used in the past will result in a
35
+ * validation error. Even if your previous request resulted in an error, you should
36
+ * always send a new value for this field.
60
37
  */
61
- signature: string;
38
+ token: string;
62
39
  /**
63
- * A unique value to identify and prevent replays. Typically a UUID (e.g., version 4).
64
- * Each request must carry a fresh token. The server rejects reused tokens, even if the original request failed.
40
+ * Server-side checks to run on the asset. Read more about
41
+ * [Upload API checks](/docs/api-reference/upload-file/upload-file#upload-api-checks).
65
42
  */
66
- token: string;
43
+ checks?: string;
67
44
  /**
68
- * A Unix timestamp in seconds, less than 1 hour in the future.
45
+ * Define an important area in the image. This is only relevant for image type
46
+ * files.
47
+ *
48
+ * - To be passed as a string with the x and y coordinates of the top-left corner,
49
+ * and width and height of the area of interest in the format `x,y,width,height`.
50
+ * For example - `10,10,100,100`
51
+ * - Can be used with fo-customtransformation.
52
+ * - If this field is not specified and the file is overwritten, then
53
+ * customCoordinates will be removed.
69
54
  */
70
- expire: number;
55
+ customCoordinates?: string;
71
56
  /**
72
- * The public API key of your ImageKit account. You can find it in the [ImageKit dashboard](https://imagekit.io/dashboard/developer/api-keys).
57
+ * JSON key-value pairs to associate with the asset. Create the custom metadata
58
+ * fields before setting these values.
73
59
  */
74
- publicKey: string;
60
+ customMetadata?: {
61
+ [key: string]: unknown;
62
+ };
75
63
  /**
76
- * Whether to use a unique filename for this file or not.
77
- * - Accepts true or false.
78
- * - If set true, ImageKit.io will add a unique suffix to the filename parameter to get a unique filename.
79
- * - If set false, then the image is uploaded with the provided filename parameter and any existing file with the same name is replaced.
80
- * Default value - true
64
+ * Optional text to describe the contents of the file.
81
65
  */
82
- useUniqueFileName?: boolean;
66
+ description?: string;
83
67
  /**
84
- * Optionally set tags on the uploaded file.
85
- * If passing an array, the SDK automatically joins them into a comma-separated string when sending to the server.
86
- * Example: ["t-shirt", "round-neck", "men"] => "t-shirt,round-neck,men"
68
+ * The time until your signature is valid. It must be a
69
+ * [Unix time](https://en.wikipedia.org/wiki/Unix_time) in less than 1 hour into
70
+ * the future. It should be in seconds.
87
71
  */
88
- tags?: string | string[];
72
+ expire: number;
89
73
  /**
90
- * The folder path where the file will be stored, e.g., "/images/folder/".
91
- * - If the path doesn't exist, it is created on-the-fly.
92
- * - Nested folders are supported by using multiple "/".
93
- * - Default: "/"
74
+ * Array of extensions to be applied to the asset. Each extension can be configured
75
+ * with specific parameters based on the extension type.
76
+ */
77
+ extensions?: Shared.Extensions;
78
+ /**
79
+ * The folder path in which the image has to be uploaded. If the folder(s) didn't
80
+ * exist before, a new folder(s) is created.
81
+ *
82
+ * The folder name can contain:
83
+ *
84
+ * - Alphanumeric Characters: `a-z` , `A-Z` , `0-9`
85
+ * - Special Characters: `/` , `_` , `-`
86
+ *
87
+ * Using multiple `/` creates a nested folder.
94
88
  */
95
89
  folder?: string;
96
90
  /**
97
- * Whether to mark the file as private (only relevant for image uploads).
98
- * A private file requires signed URLs or named transformations for access.
99
- * Default: false
91
+ * Whether to mark the file as private or not.
92
+ *
93
+ * If `true`, the file is marked as private and is accessible only using named
94
+ * transformation or signed URL.
100
95
  */
101
96
  isPrivateFile?: boolean;
102
97
  /**
103
- * A string in "x,y,width,height" format that defines the region of interest in an image (top-left coords and area size).
104
- * Example: "10,10,100,100".
98
+ * Whether to upload file as published or not.
99
+ *
100
+ * If `false`, the file is marked as unpublished, which restricts access to the
101
+ * file only via the media library. Files in draft or unpublished state can only be
102
+ * publicly accessed after being published.
103
+ *
104
+ * The option to upload in draft state is only available in custom enterprise
105
+ * pricing plans.
105
106
  */
106
- customCoordinates?: string;
107
+ isPublished?: boolean;
107
108
  /**
108
- * A comma-separated or array-based set of fields to return in the upload response.
109
- * Example: "tags,customCoordinates,isPrivateFile,metadata"
109
+ * If set to `true` and a file already exists at the exact location, its AITags
110
+ * will be removed. Set `overwriteAITags` to `false` to preserve AITags.
110
111
  */
111
- responseFields?: string | string[];
112
+ overwriteAITags?: boolean;
112
113
  /**
113
- * An array of extension objects to apply to the image, e.g. background removal, auto-tagging, etc.
114
- * The SDK will JSON-stringify this array automatically before sending.
114
+ * If the request does not have `customMetadata`, and a file already exists at the
115
+ * exact location, existing customMetadata will be removed.
115
116
  */
116
- extensions?: object[];
117
+ overwriteCustomMetadata?: boolean;
117
118
  /**
118
- * A webhook URL to receive the final status of any pending extensions once they've completed processing.
119
+ * If `false` and `useUniqueFileName` is also `false`, and a file already exists at
120
+ * the exact location, upload API will return an error immediately.
119
121
  */
120
- webhookUrl?: string;
122
+ overwriteFile?: boolean;
121
123
  /**
122
- * Defaults to true. If false, and "useUniqueFileName" is also false, the API immediately fails if a file with the same name/folder already exists.
124
+ * If the request does not have `tags`, and a file already exists at the exact
125
+ * location, existing tags will be removed.
123
126
  */
124
- overwriteFile?: boolean;
127
+ overwriteTags?: boolean;
125
128
  /**
126
- * Defaults to true. If true, and an existing file is found at the same location, its AITags are removed. Set to false to keep existing AITags.
129
+ * The public API key of your ImageKit account.
130
+ * You can find it in the [ImageKit dashboard](https://imagekit.io/dashboard/developer/api-keys).
127
131
  */
128
- overwriteAITags?: boolean;
132
+ publicKey: string;
129
133
  /**
130
- * Defaults to true. If no tags are specified in the request, existing tags are removed from overwritten files. Setting to false has no effect if the request includes tags.
134
+ * Array of response field keys to include in the API response body.
131
135
  */
132
- overwriteTags?: boolean;
136
+ responseFields?: Array<'tags' | 'customCoordinates' | 'isPrivateFile' | 'embeddedMetadata' | 'isPublished' | 'customMetadata' | 'metadata' | 'selectedFieldsSchema'>;
133
137
  /**
134
- * Defaults to true. If no customMetadata is specified in the request, existing customMetadata is removed from overwritten files. Setting to false has no effect if the request specifies customMetadata.
138
+ * The HMAC-SHA1 digest of the concatenation of "token + expire". The signing key is your ImageKit private API key.
139
+ * Calculate this signature in your secure server and pass it to the client.
135
140
  */
136
- overwriteCustomMetadata?: boolean;
141
+ signature: string;
137
142
  /**
138
- * A stringified JSON or an object containing custom metadata fields to store with the file.
139
- * Custom metadata fields must be pre-defined in your ImageKit configuration.
143
+ * Set the tags while uploading the file. Provide an array of tag strings (e.g.
144
+ * `["tag1", "tag2", "tag3"]`). The combined length of all tag characters must not
145
+ * exceed 500, and the `%` character is not allowed. If this field is not specified
146
+ * and the file is overwritten, the existing tags will be removed.
140
147
  */
141
- customMetadata?: string | Record<string, string | number | boolean | Array<string | number | boolean>>;
148
+ tags?: Array<string>;
142
149
  /**
143
- * Defines pre and post transformations to be applied to the file during upload. The SDK enforces certain validation rules for pre/post transformations.
144
- * For details, see:
145
- * {@link https://imagekit.io/docs/dam/pre-and-post-transformation-on-upload}
150
+ * Configure pre-processing (`pre`) and post-processing (`post`) transformations.
151
+ *
152
+ * - `pre` — applied before the file is uploaded to the Media Library.
153
+ * Useful for reducing file size or applying basic optimizations upfront (e.g.,
154
+ * resize, compress).
155
+ *
156
+ * - `post` — applied immediately after upload.
157
+ * Ideal for generating transformed versions (like video encodes or thumbnails)
158
+ * in advance, so they're ready for delivery without delay.
159
+ *
160
+ * You can mix and match any combination of post-processing types.
146
161
  */
147
- transformation?: Transformation;
162
+ transformation?: FileUploadParams.Transformation;
163
+ /**
164
+ * Whether to use a unique filename for this file or not.
165
+ *
166
+ * If `true`, ImageKit.io will add a unique suffix to the filename parameter to get
167
+ * a unique filename.
168
+ *
169
+ * If `false`, then the image is uploaded with the provided filename parameter, and
170
+ * any existing file with the same name is replaced.
171
+ */
172
+ useUniqueFileName?: boolean;
173
+ /**
174
+ * The final status of extensions after they have completed execution will be
175
+ * delivered to this endpoint as a POST request.
176
+ * [Learn more](/docs/api-reference/digital-asset-management-dam/managing-assets/update-file-details#webhook-payload-structure)
177
+ * about the webhook payload structure.
178
+ */
179
+ webhookUrl?: string;
148
180
  /**
149
181
  * An optional XMLHttpRequest instance for the upload. The SDK merges it with its own logic to handle progress events, etc.
150
182
  * You can listen to `progress` or other events on this object for custom logic.
151
183
  */
152
184
  xhr?: XMLHttpRequest;
153
- /**
154
- * A string specifying the checks to be performed server-side before uploading to the media library, e.g. size or mime type checks.
155
- * For format details, see: {@link https://imagekit.io/docs/api-reference/upload-file/upload-file#upload-api-checks}
156
- */
157
- checks?: string;
158
185
  /**
159
186
  * Optional callback function that will be called with the progress event when the file is being uploaded.
160
187
  */
@@ -165,4 +192,80 @@ export interface UploadOptions {
165
192
  */
166
193
  abortSignal?: AbortSignal;
167
194
  }
168
- export {};
195
+ export declare namespace FileUploadParams {
196
+ /**
197
+ * Configure pre-processing (`pre`) and post-processing (`post`) transformations.
198
+ *
199
+ * - `pre` — applied before the file is uploaded to the Media Library.
200
+ * Useful for reducing file size or applying basic optimizations upfront (e.g.,
201
+ * resize, compress).
202
+ *
203
+ * - `post` — applied immediately after upload.
204
+ * Ideal for generating transformed versions (like video encodes or thumbnails)
205
+ * in advance, so they're ready for delivery without delay.
206
+ *
207
+ * You can mix and match any combination of post-processing types.
208
+ */
209
+ interface Transformation {
210
+ /**
211
+ * List of transformations to apply _after_ the file is uploaded.
212
+ * Each item must match one of the following types: `transformation`,
213
+ * `gif-to-video`, `thumbnail`, `abs`.
214
+ */
215
+ post?: Array<Transformation.Transformation | Transformation.GifToVideo | Transformation.Thumbnail | Transformation.Abs>;
216
+ /**
217
+ * Transformation string to apply before uploading the file to the Media Library.
218
+ * Useful for optimizing files at ingestion.
219
+ */
220
+ pre?: string;
221
+ }
222
+ namespace Transformation {
223
+ interface Transformation {
224
+ /**
225
+ * Transformation type.
226
+ */
227
+ type: 'transformation';
228
+ /**
229
+ * Transformation string (e.g. `w-200,h-200`).
230
+ * Same syntax as ImageKit URL-based transformations.
231
+ */
232
+ value: string;
233
+ }
234
+ interface GifToVideo {
235
+ /**
236
+ * Converts an animated GIF into an MP4.
237
+ */
238
+ type: 'gif-to-video';
239
+ /**
240
+ * Optional transformation string to apply to the output video.
241
+ * **Example**: `q-80`
242
+ */
243
+ value?: string;
244
+ }
245
+ interface Thumbnail {
246
+ /**
247
+ * Generates a thumbnail image.
248
+ */
249
+ type: 'thumbnail';
250
+ /**
251
+ * Optional transformation string.
252
+ * **Example**: `w-150,h-150`
253
+ */
254
+ value?: string;
255
+ }
256
+ interface Abs {
257
+ /**
258
+ * Streaming protocol to use (`hls` or `dash`).
259
+ */
260
+ protocol: 'hls' | 'dash';
261
+ /**
262
+ * Adaptive Bitrate Streaming (ABS) setup.
263
+ */
264
+ type: 'abs';
265
+ /**
266
+ * List of different representations you want to create separated by an underscore.
267
+ */
268
+ value: string;
269
+ }
270
+ }
271
+ }