@imagekit/javascript 5.0.0-beta.3
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 +38 -0
- package/dist/constants/errorMessages.d.ts +63 -0
- package/dist/constants/supportedTransforms.d.ts +7 -0
- package/dist/imagekit.cjs.js +619 -0
- package/dist/imagekit.esm.js +609 -0
- package/dist/imagekit.min.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/interfaces/SrcOptions.d.ts +32 -0
- package/dist/interfaces/Transformation.d.ts +624 -0
- package/dist/interfaces/UploadOptions.d.ts +164 -0
- package/dist/interfaces/UploadResponse.d.ts +175 -0
- package/dist/interfaces/index.d.ts +4 -0
- package/dist/upload.d.ts +49 -0
- package/dist/url.d.ts +16 -0
- package/dist/utils/transformation.d.ts +10 -0
- package/package.json +76 -0
- package/src/constants/errorMessages.ts +24 -0
- package/src/constants/supportedTransforms.ts +80 -0
- package/src/index.ts +13 -0
- package/src/interfaces/SrcOptions.ts +35 -0
- package/src/interfaces/Transformation.ts +723 -0
- package/src/interfaces/UploadOptions.ts +192 -0
- package/src/interfaces/UploadResponse.ts +182 -0
- package/src/interfaces/index.ts +7 -0
- package/src/upload.ts +274 -0
- package/src/url.ts +301 -0
- package/src/utils/transformation.ts +40 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
var errorMessages = {
|
|
2
|
+
MANDATORY_INITIALIZATION_MISSING: {
|
|
3
|
+
message: "Missing urlEndpoint during SDK initialization"
|
|
4
|
+
},
|
|
5
|
+
INVALID_TRANSFORMATION_POSITION: {
|
|
6
|
+
message: "Invalid transformationPosition parameter"
|
|
7
|
+
},
|
|
8
|
+
PRIVATE_KEY_CLIENT_SIDE: {
|
|
9
|
+
message: "privateKey should not be passed on the client side"
|
|
10
|
+
},
|
|
11
|
+
MISSING_UPLOAD_DATA: {
|
|
12
|
+
message: "Missing data for upload"
|
|
13
|
+
},
|
|
14
|
+
MISSING_UPLOAD_FILE_PARAMETER: {
|
|
15
|
+
message: "Missing file parameter for upload"
|
|
16
|
+
},
|
|
17
|
+
MISSING_UPLOAD_FILENAME_PARAMETER: {
|
|
18
|
+
message: "Missing fileName parameter for upload"
|
|
19
|
+
},
|
|
20
|
+
MISSING_AUTHENTICATION_ENDPOINT: {
|
|
21
|
+
message: "Missing authentication endpoint for upload"
|
|
22
|
+
},
|
|
23
|
+
MISSING_PUBLIC_KEY: {
|
|
24
|
+
message: "Missing public key for upload"
|
|
25
|
+
},
|
|
26
|
+
AUTH_ENDPOINT_TIMEOUT: {
|
|
27
|
+
message: "The authenticationEndpoint you provided timed out in 60 seconds"
|
|
28
|
+
},
|
|
29
|
+
AUTH_ENDPOINT_NETWORK_ERROR: {
|
|
30
|
+
message: "Request to authenticationEndpoint failed due to network error"
|
|
31
|
+
},
|
|
32
|
+
AUTH_INVALID_RESPONSE: {
|
|
33
|
+
message: "Invalid response from authenticationEndpoint. The SDK expects a JSON response with three fields i.e. signature, token and expire."
|
|
34
|
+
},
|
|
35
|
+
UPLOAD_ENDPOINT_NETWORK_ERROR: {
|
|
36
|
+
message: "Request to ImageKit upload endpoint failed due to network error"
|
|
37
|
+
},
|
|
38
|
+
INVALID_UPLOAD_OPTIONS: {
|
|
39
|
+
message: "Invalid uploadOptions parameter"
|
|
40
|
+
},
|
|
41
|
+
MISSING_SIGNATURE: {
|
|
42
|
+
message: "Missing signature for upload. The SDK expects token, signature and expire for authentication."
|
|
43
|
+
},
|
|
44
|
+
MISSING_TOKEN: {
|
|
45
|
+
message: "Missing token for upload. The SDK expects token, signature and expire for authentication."
|
|
46
|
+
},
|
|
47
|
+
MISSING_EXPIRE: {
|
|
48
|
+
message: "Missing expire for upload. The SDK expects token, signature and expire for authentication."
|
|
49
|
+
},
|
|
50
|
+
INVALID_TRANSFORMATION: {
|
|
51
|
+
message: "Invalid transformation parameter. Please include at least pre, post, or both."
|
|
52
|
+
},
|
|
53
|
+
INVALID_PRE_TRANSFORMATION: {
|
|
54
|
+
message: "Invalid pre transformation parameter."
|
|
55
|
+
},
|
|
56
|
+
INVALID_POST_TRANSFORMATION: {
|
|
57
|
+
message: "Invalid post transformation parameter."
|
|
58
|
+
},
|
|
59
|
+
UPLOAD_ABORTED: {
|
|
60
|
+
message: "Request aborted by the user"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
class ImageKitInvalidRequestError extends Error {
|
|
65
|
+
constructor(message, responseMetadata) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.$ResponseMetadata = void 0;
|
|
68
|
+
this.name = "ImageKitInvalidRequestError";
|
|
69
|
+
this.$ResponseMetadata = responseMetadata;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class ImageKitAbortError extends Error {
|
|
73
|
+
constructor(message, reason) {
|
|
74
|
+
super(message);
|
|
75
|
+
this.reason = void 0;
|
|
76
|
+
this.name = "ImageKitAbortError";
|
|
77
|
+
this.reason = reason;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class ImageKitUploadNetworkError extends Error {
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "ImageKitUploadNetworkError";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class ImageKitServerError extends Error {
|
|
87
|
+
constructor(message, responseMetadata) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.$ResponseMetadata = void 0;
|
|
90
|
+
this.name = "ImageKitServerError";
|
|
91
|
+
this.$ResponseMetadata = responseMetadata;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const upload = uploadOptions => {
|
|
95
|
+
if (!uploadOptions) {
|
|
96
|
+
return Promise.reject(new ImageKitInvalidRequestError("Invalid options provided for upload"));
|
|
97
|
+
}
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const {
|
|
100
|
+
xhr: userProvidedXHR
|
|
101
|
+
} = uploadOptions || {};
|
|
102
|
+
delete uploadOptions.xhr;
|
|
103
|
+
const xhr = userProvidedXHR || new XMLHttpRequest();
|
|
104
|
+
if (!uploadOptions.file) {
|
|
105
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_UPLOAD_FILE_PARAMETER.message));
|
|
106
|
+
}
|
|
107
|
+
if (!uploadOptions.fileName) {
|
|
108
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_UPLOAD_FILENAME_PARAMETER.message));
|
|
109
|
+
}
|
|
110
|
+
if (!uploadOptions.publicKey || uploadOptions.publicKey.length === 0) {
|
|
111
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_PUBLIC_KEY.message));
|
|
112
|
+
}
|
|
113
|
+
if (!uploadOptions.token) {
|
|
114
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_TOKEN.message));
|
|
115
|
+
}
|
|
116
|
+
if (!uploadOptions.signature) {
|
|
117
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_SIGNATURE.message));
|
|
118
|
+
}
|
|
119
|
+
if (!uploadOptions.expire) {
|
|
120
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.MISSING_EXPIRE.message));
|
|
121
|
+
}
|
|
122
|
+
if (uploadOptions.transformation) {
|
|
123
|
+
if (!(Object.keys(uploadOptions.transformation).includes("pre") || Object.keys(uploadOptions.transformation).includes("post"))) {
|
|
124
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_TRANSFORMATION.message));
|
|
125
|
+
}
|
|
126
|
+
if (Object.keys(uploadOptions.transformation).includes("pre") && !uploadOptions.transformation.pre) {
|
|
127
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_PRE_TRANSFORMATION.message));
|
|
128
|
+
}
|
|
129
|
+
if (Object.keys(uploadOptions.transformation).includes("post")) {
|
|
130
|
+
if (Array.isArray(uploadOptions.transformation.post)) {
|
|
131
|
+
for (let transformation of uploadOptions.transformation.post) {
|
|
132
|
+
if (transformation.type === "abs" && !(transformation.protocol || transformation.value)) {
|
|
133
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
|
|
134
|
+
} else if (transformation.type === "transformation" && !transformation.value) {
|
|
135
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
return reject(new ImageKitInvalidRequestError(errorMessages.INVALID_POST_TRANSFORMATION.message));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var formData = new FormData();
|
|
144
|
+
let key;
|
|
145
|
+
for (key in uploadOptions) {
|
|
146
|
+
if (key) {
|
|
147
|
+
if (key === "file" && typeof uploadOptions.file != "string") {
|
|
148
|
+
formData.append('file', uploadOptions.file, String(uploadOptions.fileName));
|
|
149
|
+
} else if (key === "tags" && Array.isArray(uploadOptions.tags)) {
|
|
150
|
+
formData.append('tags', uploadOptions.tags.join(","));
|
|
151
|
+
} else if (key === 'signature') {
|
|
152
|
+
formData.append("signature", uploadOptions.signature);
|
|
153
|
+
} else if (key === 'expire') {
|
|
154
|
+
formData.append("expire", String(uploadOptions.expire));
|
|
155
|
+
} else if (key === 'token') {
|
|
156
|
+
formData.append("token", uploadOptions.token);
|
|
157
|
+
} else if (key === "responseFields" && Array.isArray(uploadOptions.responseFields)) {
|
|
158
|
+
formData.append('responseFields', uploadOptions.responseFields.join(","));
|
|
159
|
+
} else if (key === "extensions" && Array.isArray(uploadOptions.extensions)) {
|
|
160
|
+
formData.append('extensions', JSON.stringify(uploadOptions.extensions));
|
|
161
|
+
} else if (key === "customMetadata" && typeof uploadOptions.customMetadata === "object" && !Array.isArray(uploadOptions.customMetadata) && uploadOptions.customMetadata !== null) {
|
|
162
|
+
formData.append('customMetadata', JSON.stringify(uploadOptions.customMetadata));
|
|
163
|
+
} else if (key === "transformation" && typeof uploadOptions.transformation === "object" && uploadOptions.transformation !== null) {
|
|
164
|
+
formData.append(key, JSON.stringify(uploadOptions.transformation));
|
|
165
|
+
} else if (key === 'checks' && uploadOptions.checks) {
|
|
166
|
+
formData.append("checks", uploadOptions.checks);
|
|
167
|
+
} else if (uploadOptions[key] !== undefined) {
|
|
168
|
+
if (["onProgress", "abortSignal"].includes(key)) continue;
|
|
169
|
+
formData.append(key, String(uploadOptions[key]));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
formData.append("publicKey", uploadOptions.publicKey);
|
|
174
|
+
if (uploadOptions.onProgress) {
|
|
175
|
+
xhr.upload.onprogress = function (event) {
|
|
176
|
+
if (uploadOptions.onProgress) uploadOptions.onProgress(event);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function onAbortHandler() {
|
|
180
|
+
var _uploadOptions$abortS;
|
|
181
|
+
xhr.abort();
|
|
182
|
+
return reject(new ImageKitAbortError("Upload aborted", (_uploadOptions$abortS = uploadOptions.abortSignal) === null || _uploadOptions$abortS === void 0 ? void 0 : _uploadOptions$abortS.reason));
|
|
183
|
+
}
|
|
184
|
+
if (uploadOptions.abortSignal) {
|
|
185
|
+
if (uploadOptions.abortSignal.aborted) {
|
|
186
|
+
var _uploadOptions$abortS2;
|
|
187
|
+
return reject(new ImageKitAbortError("Upload aborted", (_uploadOptions$abortS2 = uploadOptions.abortSignal) === null || _uploadOptions$abortS2 === void 0 ? void 0 : _uploadOptions$abortS2.reason));
|
|
188
|
+
}
|
|
189
|
+
uploadOptions.abortSignal.addEventListener("abort", onAbortHandler);
|
|
190
|
+
xhr.addEventListener("loadend", () => {
|
|
191
|
+
if (uploadOptions.abortSignal) {
|
|
192
|
+
uploadOptions.abortSignal.removeEventListener("abort", onAbortHandler);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
xhr.open('POST', 'https://upload.imagekit.io/api/v1/files/upload');
|
|
197
|
+
xhr.onerror = function (e) {
|
|
198
|
+
return reject(new ImageKitUploadNetworkError(errorMessages.UPLOAD_ENDPOINT_NETWORK_ERROR.message));
|
|
199
|
+
};
|
|
200
|
+
xhr.onload = function () {
|
|
201
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
202
|
+
try {
|
|
203
|
+
var body = JSON.parse(xhr.responseText);
|
|
204
|
+
var uploadResponse = addResponseHeadersAndBody(body, xhr);
|
|
205
|
+
return resolve(uploadResponse);
|
|
206
|
+
} catch (ex) {
|
|
207
|
+
return reject(ex);
|
|
208
|
+
}
|
|
209
|
+
} else if (xhr.status >= 400 && xhr.status < 500) {
|
|
210
|
+
try {
|
|
211
|
+
var body = JSON.parse(xhr.responseText);
|
|
212
|
+
return reject(new ImageKitInvalidRequestError(body.message ?? "Invalid request. Please check the parameters.", getResponseMetadata(xhr)));
|
|
213
|
+
} catch (ex) {
|
|
214
|
+
return reject(ex);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
try {
|
|
218
|
+
var body = JSON.parse(xhr.responseText);
|
|
219
|
+
return reject(new ImageKitServerError(body.message ?? "Server error occurred while uploading the file. This is rare and usually temporary.", getResponseMetadata(xhr)));
|
|
220
|
+
} catch (ex) {
|
|
221
|
+
return reject(new ImageKitServerError("Server error occurred while uploading the file. This is rare and usually temporary.", getResponseMetadata(xhr)));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
xhr.send(formData);
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
const addResponseHeadersAndBody = (body, xhr) => {
|
|
229
|
+
let response = {
|
|
230
|
+
...body
|
|
231
|
+
};
|
|
232
|
+
const responseMetadata = getResponseMetadata(xhr);
|
|
233
|
+
Object.defineProperty(response, "$ResponseMetadata", {
|
|
234
|
+
value: responseMetadata,
|
|
235
|
+
enumerable: false,
|
|
236
|
+
writable: false
|
|
237
|
+
});
|
|
238
|
+
return response;
|
|
239
|
+
};
|
|
240
|
+
const getResponseMetadata = xhr => {
|
|
241
|
+
const headers = getResponseHeaderMap(xhr);
|
|
242
|
+
const responseMetadata = {
|
|
243
|
+
statusCode: xhr.status,
|
|
244
|
+
headers: headers,
|
|
245
|
+
requestId: headers["x-request-id"]
|
|
246
|
+
};
|
|
247
|
+
return responseMetadata;
|
|
248
|
+
};
|
|
249
|
+
function getResponseHeaderMap(xhr) {
|
|
250
|
+
const headers = {};
|
|
251
|
+
const responseHeaders = xhr.getAllResponseHeaders();
|
|
252
|
+
if (Object.keys(responseHeaders).length) {
|
|
253
|
+
responseHeaders.trim().split(/[\r\n]+/).map(value => value.split(/: /)).forEach(keyValue => {
|
|
254
|
+
headers[keyValue[0].trim().toLowerCase()] = keyValue[1].trim();
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return headers;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const supportedTransforms = {
|
|
261
|
+
width: "w",
|
|
262
|
+
height: "h",
|
|
263
|
+
aspectRatio: "ar",
|
|
264
|
+
background: "bg",
|
|
265
|
+
border: "b",
|
|
266
|
+
crop: "c",
|
|
267
|
+
cropMode: "cm",
|
|
268
|
+
dpr: "dpr",
|
|
269
|
+
focus: "fo",
|
|
270
|
+
quality: "q",
|
|
271
|
+
x: "x",
|
|
272
|
+
xCenter: "xc",
|
|
273
|
+
y: "y",
|
|
274
|
+
yCenter: "yc",
|
|
275
|
+
format: "f",
|
|
276
|
+
videoCodec: "vc",
|
|
277
|
+
audioCodec: "ac",
|
|
278
|
+
radius: "r",
|
|
279
|
+
rotation: "rt",
|
|
280
|
+
blur: "bl",
|
|
281
|
+
named: "n",
|
|
282
|
+
defaultImage: "di",
|
|
283
|
+
flip: "fl",
|
|
284
|
+
original: "orig",
|
|
285
|
+
startOffset: "so",
|
|
286
|
+
endOffset: "eo",
|
|
287
|
+
duration: "du",
|
|
288
|
+
streamingResolutions: "sr",
|
|
289
|
+
grayscale: "e-grayscale",
|
|
290
|
+
aiUpscale: "e-upscale",
|
|
291
|
+
aiRetouch: "e-retouch",
|
|
292
|
+
aiVariation: "e-genvar",
|
|
293
|
+
aiDropShadow: "e-dropshadow",
|
|
294
|
+
aiChangeBackground: "e-changebg",
|
|
295
|
+
aiRemoveBackground: "e-bgremove",
|
|
296
|
+
aiRemoveBackgroundExternal: "e-removedotbg",
|
|
297
|
+
contrastStretch: "e-contrast",
|
|
298
|
+
shadow: "e-shadow",
|
|
299
|
+
sharpen: "e-sharpen",
|
|
300
|
+
unsharpMask: "e-usm",
|
|
301
|
+
gradient: "e-gradient",
|
|
302
|
+
progressive: "pr",
|
|
303
|
+
lossless: "lo",
|
|
304
|
+
colorProfile: "cp",
|
|
305
|
+
metadata: "md",
|
|
306
|
+
opacity: "o",
|
|
307
|
+
trim: "t",
|
|
308
|
+
zoom: "z",
|
|
309
|
+
page: "pg",
|
|
310
|
+
fontSize: "fs",
|
|
311
|
+
fontFamily: "ff",
|
|
312
|
+
fontColor: "co",
|
|
313
|
+
innerAlignment: "ia",
|
|
314
|
+
padding: "pa",
|
|
315
|
+
alpha: "al",
|
|
316
|
+
typography: "tg",
|
|
317
|
+
lineHeight: "lh",
|
|
318
|
+
fontOutline: "fol",
|
|
319
|
+
fontShadow: "fsh",
|
|
320
|
+
raw: "raw"
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const QUERY_TRANSFORMATION_POSITION = "query";
|
|
324
|
+
const CHAIN_TRANSFORM_DELIMITER = ":";
|
|
325
|
+
const TRANSFORM_DELIMITER = ",";
|
|
326
|
+
const TRANSFORM_KEY_VALUE_DELIMITER = "-";
|
|
327
|
+
var transformationUtils = {
|
|
328
|
+
addAsQueryParameter: options => {
|
|
329
|
+
return options.transformationPosition === QUERY_TRANSFORMATION_POSITION;
|
|
330
|
+
},
|
|
331
|
+
getTransformKey: function (transform) {
|
|
332
|
+
if (!transform) {
|
|
333
|
+
return "";
|
|
334
|
+
}
|
|
335
|
+
return supportedTransforms[transform] || supportedTransforms[transform.toLowerCase()] || "";
|
|
336
|
+
},
|
|
337
|
+
getChainTransformDelimiter: function () {
|
|
338
|
+
return CHAIN_TRANSFORM_DELIMITER;
|
|
339
|
+
},
|
|
340
|
+
getTransformDelimiter: function () {
|
|
341
|
+
return TRANSFORM_DELIMITER;
|
|
342
|
+
},
|
|
343
|
+
getTransformKeyValueDelimiter: function () {
|
|
344
|
+
return TRANSFORM_KEY_VALUE_DELIMITER;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
const safeBtoa = function (str) {
|
|
348
|
+
if (typeof window !== "undefined") {
|
|
349
|
+
return btoa(str);
|
|
350
|
+
} else {
|
|
351
|
+
return Buffer.from(str, "utf8").toString("base64");
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const TRANSFORMATION_PARAMETER = "tr";
|
|
356
|
+
const SIMPLE_OVERLAY_PATH_REGEX = new RegExp('^[a-zA-Z0-9-._/ ]*$');
|
|
357
|
+
const SIMPLE_OVERLAY_TEXT_REGEX = new RegExp('^[a-zA-Z0-9-._ ]*$');
|
|
358
|
+
function removeTrailingSlash(str) {
|
|
359
|
+
if (typeof str == "string" && str[str.length - 1] == "/") {
|
|
360
|
+
str = str.substring(0, str.length - 1);
|
|
361
|
+
}
|
|
362
|
+
return str;
|
|
363
|
+
}
|
|
364
|
+
function removeLeadingSlash(str) {
|
|
365
|
+
if (typeof str == "string" && str[0] == "/") {
|
|
366
|
+
str = str.slice(1);
|
|
367
|
+
}
|
|
368
|
+
return str;
|
|
369
|
+
}
|
|
370
|
+
function pathJoin(parts, sep) {
|
|
371
|
+
var separator = sep || "/";
|
|
372
|
+
var replace = new RegExp(separator + "{1,}", "g");
|
|
373
|
+
return parts.join(separator).replace(replace, separator);
|
|
374
|
+
}
|
|
375
|
+
const buildSrc = opts => {
|
|
376
|
+
opts.urlEndpoint = opts.urlEndpoint || "";
|
|
377
|
+
opts.src = opts.src || "";
|
|
378
|
+
opts.transformationPosition = opts.transformationPosition || "query";
|
|
379
|
+
if (!opts.src) {
|
|
380
|
+
return "";
|
|
381
|
+
}
|
|
382
|
+
const isAbsoluteURL = opts.src.startsWith("http://") || opts.src.startsWith("https://");
|
|
383
|
+
var urlObj, isSrcParameterUsedForURL, urlEndpointPattern;
|
|
384
|
+
try {
|
|
385
|
+
if (!isAbsoluteURL) {
|
|
386
|
+
urlEndpointPattern = new URL(opts.urlEndpoint).pathname;
|
|
387
|
+
urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern, ""), opts.src]));
|
|
388
|
+
} else {
|
|
389
|
+
urlObj = new URL(opts.src);
|
|
390
|
+
isSrcParameterUsedForURL = true;
|
|
391
|
+
}
|
|
392
|
+
} catch (e) {
|
|
393
|
+
console.error(e);
|
|
394
|
+
return "";
|
|
395
|
+
}
|
|
396
|
+
for (var i in opts.queryParameters) {
|
|
397
|
+
urlObj.searchParams.append(i, String(opts.queryParameters[i]));
|
|
398
|
+
}
|
|
399
|
+
var transformationString = buildTransformationString(opts.transformation);
|
|
400
|
+
if (transformationString && transformationString.length) {
|
|
401
|
+
if (!transformationUtils.addAsQueryParameter(opts) && !isSrcParameterUsedForURL) {
|
|
402
|
+
urlObj.pathname = pathJoin([TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString, urlObj.pathname]);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (urlEndpointPattern) {
|
|
406
|
+
urlObj.pathname = pathJoin([urlEndpointPattern, urlObj.pathname]);
|
|
407
|
+
} else {
|
|
408
|
+
urlObj.pathname = pathJoin([urlObj.pathname]);
|
|
409
|
+
}
|
|
410
|
+
if (transformationString && transformationString.length) {
|
|
411
|
+
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
|
|
412
|
+
if (urlObj.searchParams.toString() !== "") {
|
|
413
|
+
return `${urlObj.href}&${TRANSFORMATION_PARAMETER}=${transformationString}`;
|
|
414
|
+
} else {
|
|
415
|
+
return `${urlObj.href}?${TRANSFORMATION_PARAMETER}=${transformationString}`;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return urlObj.href;
|
|
420
|
+
};
|
|
421
|
+
function processInputPath(str, enccoding) {
|
|
422
|
+
str = removeTrailingSlash(removeLeadingSlash(str));
|
|
423
|
+
if (enccoding === "plain") {
|
|
424
|
+
return `i-${str.replace(/\//g, "@@")}`;
|
|
425
|
+
}
|
|
426
|
+
if (enccoding === "base64") {
|
|
427
|
+
return `ie-${encodeURIComponent(safeBtoa(str))}`;
|
|
428
|
+
}
|
|
429
|
+
if (SIMPLE_OVERLAY_PATH_REGEX.test(str)) {
|
|
430
|
+
return `i-${str.replace(/\//g, "@@")}`;
|
|
431
|
+
} else {
|
|
432
|
+
return `ie-${encodeURIComponent(safeBtoa(str))}`;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function processText(str, enccoding) {
|
|
436
|
+
if (enccoding === "plain") {
|
|
437
|
+
return `i-${encodeURIComponent(str)}`;
|
|
438
|
+
}
|
|
439
|
+
if (enccoding === "base64") {
|
|
440
|
+
return `ie-${encodeURIComponent(safeBtoa(str))}`;
|
|
441
|
+
}
|
|
442
|
+
if (SIMPLE_OVERLAY_TEXT_REGEX.test(str)) {
|
|
443
|
+
return `i-${encodeURIComponent(str)}`;
|
|
444
|
+
}
|
|
445
|
+
return `ie-${encodeURIComponent(safeBtoa(str))}`;
|
|
446
|
+
}
|
|
447
|
+
function processOverlay(overlay) {
|
|
448
|
+
const entries = [];
|
|
449
|
+
const {
|
|
450
|
+
type,
|
|
451
|
+
position = {},
|
|
452
|
+
timing = {},
|
|
453
|
+
transformation = []
|
|
454
|
+
} = overlay || {};
|
|
455
|
+
if (!type) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
switch (type) {
|
|
459
|
+
case "text":
|
|
460
|
+
{
|
|
461
|
+
const textOverlay = overlay;
|
|
462
|
+
if (!textOverlay.text) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const enccoding = textOverlay.encoding || "auto";
|
|
466
|
+
entries.push("l-text");
|
|
467
|
+
entries.push(processText(textOverlay.text, enccoding));
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
case "image":
|
|
471
|
+
entries.push("l-image");
|
|
472
|
+
{
|
|
473
|
+
const imageOverlay = overlay;
|
|
474
|
+
const enccoding = imageOverlay.encoding || "auto";
|
|
475
|
+
if (imageOverlay.input) {
|
|
476
|
+
entries.push(processInputPath(imageOverlay.input, enccoding));
|
|
477
|
+
} else {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
case "video":
|
|
483
|
+
entries.push("l-video");
|
|
484
|
+
{
|
|
485
|
+
const videoOverlay = overlay;
|
|
486
|
+
const enccoding = videoOverlay.encoding || "auto";
|
|
487
|
+
if (videoOverlay.input) {
|
|
488
|
+
entries.push(processInputPath(videoOverlay.input, enccoding));
|
|
489
|
+
} else {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
494
|
+
case "subtitle":
|
|
495
|
+
entries.push("l-subtitle");
|
|
496
|
+
{
|
|
497
|
+
const subtitleOverlay = overlay;
|
|
498
|
+
const enccoding = subtitleOverlay.encoding || "auto";
|
|
499
|
+
if (subtitleOverlay.input) {
|
|
500
|
+
entries.push(processInputPath(subtitleOverlay.input, enccoding));
|
|
501
|
+
} else {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
break;
|
|
506
|
+
case "solidColor":
|
|
507
|
+
entries.push("l-image");
|
|
508
|
+
entries.push(`i-ik_canvas`);
|
|
509
|
+
{
|
|
510
|
+
const solidColorOverlay = overlay;
|
|
511
|
+
if (solidColorOverlay.color) {
|
|
512
|
+
entries.push(`bg-${solidColorOverlay.color}`);
|
|
513
|
+
} else {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
const {
|
|
520
|
+
x,
|
|
521
|
+
y,
|
|
522
|
+
focus
|
|
523
|
+
} = position;
|
|
524
|
+
if (x) {
|
|
525
|
+
entries.push(`lx-${x}`);
|
|
526
|
+
}
|
|
527
|
+
if (y) {
|
|
528
|
+
entries.push(`ly-${y}`);
|
|
529
|
+
}
|
|
530
|
+
if (focus) {
|
|
531
|
+
entries.push(`lfo-${focus}`);
|
|
532
|
+
}
|
|
533
|
+
const {
|
|
534
|
+
start,
|
|
535
|
+
end,
|
|
536
|
+
duration
|
|
537
|
+
} = timing;
|
|
538
|
+
if (start) {
|
|
539
|
+
entries.push(`lso-${start}`);
|
|
540
|
+
}
|
|
541
|
+
if (end) {
|
|
542
|
+
entries.push(`leo-${end}`);
|
|
543
|
+
}
|
|
544
|
+
if (duration) {
|
|
545
|
+
entries.push(`ldu-${duration}`);
|
|
546
|
+
}
|
|
547
|
+
const transformationString = buildTransformationString(transformation);
|
|
548
|
+
if (transformationString && transformationString.trim() !== "") entries.push(transformationString);
|
|
549
|
+
entries.push("l-end");
|
|
550
|
+
return entries.join(transformationUtils.getTransformDelimiter());
|
|
551
|
+
}
|
|
552
|
+
const buildTransformationString = function (transformation) {
|
|
553
|
+
if (!Array.isArray(transformation)) {
|
|
554
|
+
return "";
|
|
555
|
+
}
|
|
556
|
+
var parsedTransforms = [];
|
|
557
|
+
for (var i = 0, l = transformation.length; i < l; i++) {
|
|
558
|
+
var parsedTransformStep = [];
|
|
559
|
+
for (var key in transformation[i]) {
|
|
560
|
+
let value = transformation[i][key];
|
|
561
|
+
if (value === undefined || value === null) {
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (key === "overlay" && typeof value === "object") {
|
|
565
|
+
var rawString = processOverlay(value);
|
|
566
|
+
if (rawString && rawString.trim() !== "") {
|
|
567
|
+
parsedTransformStep.push(rawString);
|
|
568
|
+
}
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
var transformKey = transformationUtils.getTransformKey(key);
|
|
572
|
+
if (!transformKey) {
|
|
573
|
+
transformKey = key;
|
|
574
|
+
}
|
|
575
|
+
if (transformKey === "") {
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (["e-grayscale", "e-contrast", "e-removedotbg", "e-bgremove", "e-upscale", "e-retouch", "e-genvar"].includes(transformKey)) {
|
|
579
|
+
if (value === true || value === "-" || value === "true") {
|
|
580
|
+
parsedTransformStep.push(transformKey);
|
|
581
|
+
} else {
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
} else if (["e-sharpen", "e-shadow", "e-gradient", "e-usm", "e-dropshadow"].includes(transformKey) && (value.toString().trim() === "" || value === true || value === "true")) {
|
|
585
|
+
parsedTransformStep.push(transformKey);
|
|
586
|
+
} else if (key === "raw") {
|
|
587
|
+
parsedTransformStep.push(transformation[i][key]);
|
|
588
|
+
} else {
|
|
589
|
+
if (transformKey === "di") {
|
|
590
|
+
value = removeTrailingSlash(removeLeadingSlash(value || ""));
|
|
591
|
+
value = value.replace(/\//g, "@@");
|
|
592
|
+
}
|
|
593
|
+
if (transformKey === "sr" && Array.isArray(value)) {
|
|
594
|
+
value = value.join("_");
|
|
595
|
+
}
|
|
596
|
+
if (transformKey === "t" && value.toString().trim() === "") {
|
|
597
|
+
value = "true";
|
|
598
|
+
}
|
|
599
|
+
parsedTransformStep.push([transformKey, value].join(transformationUtils.getTransformKeyValueDelimiter()));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (parsedTransformStep.length) {
|
|
603
|
+
parsedTransforms.push(parsedTransformStep.join(transformationUtils.getTransformDelimiter()));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return parsedTransforms.join(transformationUtils.getChainTransformDelimiter());
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
export { ImageKitAbortError, ImageKitInvalidRequestError, ImageKitServerError, ImageKitUploadNetworkError, buildSrc, buildTransformationString, upload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).ImageKit={})}(this,(function(e){"use strict";var r={message:"Missing file parameter for upload"},t={message:"Missing fileName parameter for upload"},n={message:"Missing public key for upload"},a={message:"Request to ImageKit upload endpoint failed due to network error"},s={message:"Missing signature for upload. The SDK expects token, signature and expire for authentication."},o={message:"Missing token for upload. The SDK expects token, signature and expire for authentication."},i={message:"Missing expire for upload. The SDK expects token, signature and expire for authentication."},u={message:"Invalid transformation parameter. Please include at least pre, post, or both."},p={message:"Invalid pre transformation parameter."},l={message:"Invalid post transformation parameter."};class c extends Error{constructor(e,r){super(e),this.$ResponseMetadata=void 0,this.name="ImageKitInvalidRequestError",this.$ResponseMetadata=r}}class d extends Error{constructor(e,r){super(e),this.reason=void 0,this.name="ImageKitAbortError",this.reason=r}}class f extends Error{constructor(e){super(e),this.name="ImageKitUploadNetworkError"}}class g extends Error{constructor(e,r){super(e),this.$ResponseMetadata=void 0,this.name="ImageKitServerError",this.$ResponseMetadata=r}}const m=(e,r)=>{let t={...e};const n=h(r);return Object.defineProperty(t,"$ResponseMetadata",{value:n,enumerable:!1,writable:!1}),t},h=e=>{const r=function(e){const r={},t=e.getAllResponseHeaders();Object.keys(t).length&&t.trim().split(/[\r\n]+/).map(e=>e.split(/: /)).forEach(e=>{r[e[0].trim().toLowerCase()]=e[1].trim()});return r}(e);return{statusCode:e.status,headers:r,requestId:r["x-request-id"]}};const y={width:"w",height:"h",aspectRatio:"ar",background:"bg",border:"b",crop:"c",cropMode:"cm",dpr:"dpr",focus:"fo",quality:"q",x:"x",xCenter:"xc",y:"y",yCenter:"yc",format:"f",videoCodec:"vc",audioCodec:"ac",radius:"r",rotation:"rt",blur:"bl",named:"n",defaultImage:"di",flip:"fl",original:"orig",startOffset:"so",endOffset:"eo",duration:"du",streamingResolutions:"sr",grayscale:"e-grayscale",aiUpscale:"e-upscale",aiRetouch:"e-retouch",aiVariation:"e-genvar",aiDropShadow:"e-dropshadow",aiChangeBackground:"e-changebg",aiRemoveBackground:"e-bgremove",aiRemoveBackgroundExternal:"e-removedotbg",contrastStretch:"e-contrast",shadow:"e-shadow",sharpen:"e-sharpen",unsharpMask:"e-usm",gradient:"e-gradient",progressive:"pr",lossless:"lo",colorProfile:"cp",metadata:"md",opacity:"o",trim:"t",zoom:"z",page:"pg",fontSize:"fs",fontFamily:"ff",fontColor:"co",innerAlignment:"ia",padding:"pa",alpha:"al",typography:"tg",lineHeight:"lh",fontOutline:"fol",fontShadow:"fsh",raw:"raw"};var b=e=>"query"===e.transformationPosition,v=function(e){return e&&(y[e]||y[e.toLowerCase()])||""},w=function(){return":"},x=function(){return","},S=function(){return"-"};const k=function(e){return"undefined"!=typeof window?btoa(e):Buffer.from(e,"utf8").toString("base64")},R=new RegExp("^[a-zA-Z0-9-._/ ]*$"),I=new RegExp("^[a-zA-Z0-9-._ ]*$");function E(e){return"string"==typeof e&&"/"==e[e.length-1]&&(e=e.substring(0,e.length-1)),e}function M(e){return"string"==typeof e&&"/"==e[0]&&(e=e.slice(1)),e}function j(e,r){var t=r||"/",n=new RegExp(t+"{1,}","g");return e.join(t).replace(n,t)}function A(e,r){return e=E(M(e)),"plain"===r?"i-"+e.replace(/\//g,"@@"):"base64"===r?"ie-"+encodeURIComponent(k(e)):R.test(e)?"i-"+e.replace(/\//g,"@@"):"ie-"+encodeURIComponent(k(e))}function P(e){const r=[],{type:t,position:n={},timing:a={},transformation:s=[]}=e||{};if(!t)return;switch(t){case"text":{const t=e;if(!t.text)return;const n=t.encoding||"auto";r.push("l-text"),r.push(function(e,r){return"plain"===r?"i-"+encodeURIComponent(e):"base64"===r?"ie-"+encodeURIComponent(k(e)):I.test(e)?"i-"+encodeURIComponent(e):"ie-"+encodeURIComponent(k(e))}(t.text,n))}break;case"image":r.push("l-image");{const t=e,n=t.encoding||"auto";if(!t.input)return;r.push(A(t.input,n))}break;case"video":r.push("l-video");{const t=e,n=t.encoding||"auto";if(!t.input)return;r.push(A(t.input,n))}break;case"subtitle":r.push("l-subtitle");{const t=e,n=t.encoding||"auto";if(!t.input)return;r.push(A(t.input,n))}break;case"solidColor":r.push("l-image"),r.push("i-ik_canvas");{const t=e;if(!t.color)return;r.push("bg-"+t.color)}}const{x:o,y:i,focus:u}=n;o&&r.push("lx-"+o),i&&r.push("ly-"+i),u&&r.push("lfo-"+u);const{start:p,end:l,duration:c}=a;p&&r.push("lso-"+p),l&&r.push("leo-"+l),c&&r.push("ldu-"+c);const d=K(s);return d&&""!==d.trim()&&r.push(d),r.push("l-end"),r.join(x())}const K=function(e){if(!Array.isArray(e))return"";for(var r=[],t=0,n=e.length;t<n;t++){var a=[];for(var s in e[t]){let r=e[t][s];if(null!=r)if("overlay"!==s||"object"!=typeof r){var o=v(s);if(o||(o=s),""!==o)if(["e-grayscale","e-contrast","e-removedotbg","e-bgremove","e-upscale","e-retouch","e-genvar"].includes(o)){if(!0!==r&&"-"!==r&&"true"!==r)continue;a.push(o)}else!["e-sharpen","e-shadow","e-gradient","e-usm","e-dropshadow"].includes(o)||""!==r.toString().trim()&&!0!==r&&"true"!==r?"raw"===s?a.push(e[t][s]):("di"===o&&(r=E(M(r||"")),r=r.replace(/\//g,"@@")),"sr"===o&&Array.isArray(r)&&(r=r.join("_")),"t"===o&&""===r.toString().trim()&&(r="true"),a.push([o,r].join(S()))):a.push(o)}else{var i=P(r);i&&""!==i.trim()&&a.push(i)}}a.length&&r.push(a.join(x()))}return r.join(w())};e.ImageKitAbortError=d,e.ImageKitInvalidRequestError=c,e.ImageKitServerError=g,e.ImageKitUploadNetworkError=f,e.buildSrc=e=>{if(e.urlEndpoint=e.urlEndpoint||"",e.src=e.src||"",e.transformationPosition=e.transformationPosition||"query",!e.src)return"";const r=e.src.startsWith("http://")||e.src.startsWith("https://");var t,n,a;try{r?(t=new URL(e.src),n=!0):(a=new URL(e.urlEndpoint).pathname,t=new URL(j([e.urlEndpoint.replace(a,""),e.src])))}catch(e){return console.error(e),""}for(var s in e.queryParameters)t.searchParams.append(s,String(e.queryParameters[s]));var o=K(e.transformation);return o&&o.length&&(b(e)||n||(t.pathname=j(["tr"+w()+o,t.pathname]))),t.pathname=j(a?[a,t.pathname]:[t.pathname]),o&&o.length&&(b(e)||n)?""!==t.searchParams.toString()?`${t.href}&tr=${o}`:`${t.href}?tr=${o}`:t.href},e.buildTransformationString=K,e.upload=e=>e?new Promise((y,b)=>{const{xhr:v}=e||{};delete e.xhr;const w=v||new XMLHttpRequest;if(!e.file)return b(new c(r.message));if(!e.fileName)return b(new c(t.message));if(!e.publicKey||0===e.publicKey.length)return b(new c(n.message));if(!e.token)return b(new c(o.message));if(!e.signature)return b(new c(s.message));if(!e.expire)return b(new c(i.message));if(e.transformation){if(!Object.keys(e.transformation).includes("pre")&&!Object.keys(e.transformation).includes("post"))return b(new c(u.message));if(Object.keys(e.transformation).includes("pre")&&!e.transformation.pre)return b(new c(p.message));if(Object.keys(e.transformation).includes("post")){if(!Array.isArray(e.transformation.post))return b(new c(l.message));for(let r of e.transformation.post){if("abs"===r.type&&!r.protocol&&!r.value)return b(new c(l.message));if("transformation"===r.type&&!r.value)return b(new c(l.message))}}}var x=new FormData;let S;for(S in e)if(S)if("file"===S&&"string"!=typeof e.file)x.append("file",e.file,String(e.fileName));else if("tags"===S&&Array.isArray(e.tags))x.append("tags",e.tags.join(","));else if("signature"===S)x.append("signature",e.signature);else if("expire"===S)x.append("expire",String(e.expire));else if("token"===S)x.append("token",e.token);else if("responseFields"===S&&Array.isArray(e.responseFields))x.append("responseFields",e.responseFields.join(","));else if("extensions"===S&&Array.isArray(e.extensions))x.append("extensions",JSON.stringify(e.extensions));else if("customMetadata"!==S||"object"!=typeof e.customMetadata||Array.isArray(e.customMetadata)||null===e.customMetadata){if("transformation"===S&&"object"==typeof e.transformation&&null!==e.transformation)x.append(S,JSON.stringify(e.transformation));else if("checks"===S&&e.checks)x.append("checks",e.checks);else if(void 0!==e[S]){if(["onProgress","abortSignal"].includes(S))continue;x.append(S,String(e[S]))}}else x.append("customMetadata",JSON.stringify(e.customMetadata));function k(){var r;return w.abort(),b(new d("Upload aborted",null===(r=e.abortSignal)||void 0===r?void 0:r.reason))}if(x.append("publicKey",e.publicKey),e.onProgress&&(w.upload.onprogress=function(r){e.onProgress&&e.onProgress(r)}),e.abortSignal){var R;if(e.abortSignal.aborted)return b(new d("Upload aborted",null===(R=e.abortSignal)||void 0===R?void 0:R.reason));e.abortSignal.addEventListener("abort",k),w.addEventListener("loadend",()=>{e.abortSignal&&e.abortSignal.removeEventListener("abort",k)})}w.open("POST","https://upload.imagekit.io/api/v1/files/upload"),w.onerror=function(e){return b(new f(a.message))},w.onload=function(){if(w.status>=200&&w.status<300)try{var e=JSON.parse(w.responseText),r=m(e,w);return y(r)}catch(e){return b(e)}else if(w.status>=400&&w.status<500)try{e=JSON.parse(w.responseText);return b(new c(e.message??"Invalid request. Please check the parameters.",h(w)))}catch(e){return b(e)}else try{e=JSON.parse(w.responseText);return b(new g(e.message??"Server error occurred while uploading the file. This is rare and usually temporary.",h(w)))}catch(e){return b(new g("Server error occurred while uploading the file. This is rare and usually temporary.",h(w)))}},w.send(x)}):Promise.reject(new c("Invalid options provided for upload")),Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SrcOptions, Transformation, UploadOptions, UploadResponse } from "./interfaces";
|
|
2
|
+
import { ImageKitAbortError, ImageKitInvalidRequestError, ImageKitServerError, ImageKitUploadNetworkError, upload } from "./upload";
|
|
3
|
+
import { buildSrc, buildTransformationString } from "./url";
|
|
4
|
+
export { buildSrc, buildTransformationString, upload, ImageKitInvalidRequestError, ImageKitAbortError, ImageKitServerError, ImageKitUploadNetworkError };
|
|
5
|
+
export type { Transformation, SrcOptions, UploadOptions, UploadResponse };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Transformation } from "./Transformation";
|
|
2
|
+
import { TransformationPosition } from ".";
|
|
3
|
+
export interface SrcOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Accepts a relative or absolute path of the resource. If a relative path is provided, it is appended to the `urlEndpoint`.
|
|
6
|
+
* If an absolute path is provided, `urlEndpoint` is ignored.
|
|
7
|
+
*/
|
|
8
|
+
src: string;
|
|
9
|
+
/**
|
|
10
|
+
* Get your urlEndpoint from the [ImageKit dashboard](https://imagekit.io/dashboard/url-endpoints).
|
|
11
|
+
*/
|
|
12
|
+
urlEndpoint: string;
|
|
13
|
+
/**
|
|
14
|
+
* An array of objects specifying the transformations to be applied in the URL. If more than one transformation is specified, they are applied in the order they are specified as chained transformations.
|
|
15
|
+
*
|
|
16
|
+
* {@link https://imagekit.io/docs/transformations#chained-transformations}
|
|
17
|
+
*/
|
|
18
|
+
transformation?: Array<Transformation>;
|
|
19
|
+
/**
|
|
20
|
+
* These are additional query parameters that you want to add to the final URL.
|
|
21
|
+
* They can be any query parameters and not necessarily related to ImageKit.
|
|
22
|
+
* This is especially useful if you want to add a versioning parameter to your URLs.
|
|
23
|
+
*/
|
|
24
|
+
queryParameters?: {
|
|
25
|
+
[key: string]: string | number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* By default, the transformation string is added as a query parameter in the URL, e.g., `?tr=w-100,h-100`.
|
|
29
|
+
* If you want to add the transformation string in the path of the URL, set this to `path`.
|
|
30
|
+
*/
|
|
31
|
+
transformationPosition?: TransformationPosition;
|
|
32
|
+
}
|