-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathindex.ts
681 lines (645 loc) · 26.1 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/*
Helper Modules
*/
import _ from "lodash";
import errorMessages from "./libs/constants/errorMessages";
import {
BulkDeleteFilesError,
BulkDeleteFilesResponse,
CopyFolderError,
CopyFolderResponse,
FileDetailsOptions,
FileObject,
FolderObject,
FileMetadataResponse,
ImageKitOptions,
ListFileOptions,
ListFileResponse,
MoveFolderError,
MoveFolderResponse,
PurgeCacheResponse,
PurgeCacheStatusResponse,
UploadOptions,
UploadResponse,
UrlOptions,
CopyFileOptions,
MoveFileOptions,
CreateFolderOptions,
CopyFolderOptions,
MoveFolderOptions,
FileVersionDetailsOptions,
DeleteFileVersionOptions,
RestoreFileVersionOptions,
CreateCustomMetadataFieldOptions,
GetCustomMetadataFieldsOptions,
CustomMetadataField,
UpdateCustomMetadataFieldOptions,
RenameFileOptions,
RenameFileResponse,
} from "./libs/interfaces";
import { IKCallback } from "./libs/interfaces/IKCallback";
import manage from "./libs/manage";
import signature from "./libs/signature";
import upload from "./libs/upload";
import { verify as verifyWebhookEvent } from "./utils/webhook-signature";
import customMetadataField from "./libs/manage/custom-metadata-field";
/*
Implementations
*/
import url from "./libs/url";
/*
Utils
*/
import pHashUtils from "./utils/phash";
import transformationUtils from "./utils/transformation";
import IKResponse from "./libs/interfaces/IKResponse";
const promisify = function <T = void>(thisContext: ImageKit, fn: Function) {
return function (...args: any[]): Promise<T> | void {
if (args.length === fn.length && typeof args[args.length - 1] !== "undefined") {
if (typeof args[args.length - 1] !== "function") {
throw new Error("Callback must be a function.");
}
fn.call(thisContext, ...args);
} else {
return new Promise<T>((resolve, reject) => {
const callback = function (err: Error, ...results: any[]) {
if (err) {
return reject(err);
} else {
resolve(results.length > 1 ? results : results[0]);
}
};
args.pop()
args.push(callback);
fn.call(thisContext, ...args);
});
}
};
};
class ImageKit {
options: ImageKitOptions = {
uploadEndpoint: "https://upload.imagekit.io/api/v1/files/upload",
publicKey: "",
privateKey: "",
urlEndpoint: "",
transformationPosition: transformationUtils.getDefault(),
};
constructor(opts: ImageKitOptions = {} as ImageKitOptions) {
this.options = _.extend(this.options, opts);
if (!this.options.publicKey) {
throw new Error(errorMessages.MANDATORY_PUBLIC_KEY_MISSING.message);
}
if (!this.options.privateKey) {
throw new Error(errorMessages.MANDATORY_PRIVATE_KEY_MISSING.message);
}
if (!this.options.urlEndpoint) {
throw new Error(errorMessages.MANDATORY_URL_ENDPOINT_KEY_MISSING.message);
}
}
/**
* This method allows you to create an URL to access a file using the relative or absolute path and the ImageKit URL endpoint (urlEndpoint). The file can be an image, video or any other static file supported by ImageKit.
*
* @see {@link https://github.com/imagekit-developer/imagekit-nodejs#url-generation}
* @see {@link https://docs.imagekit.io/integration/url-endpoints}
*
* @param urlOptions
*/
url(urlOptions: UrlOptions): string {
return url(urlOptions, this.options);
}
/**
* You can upload file to ImageKit.io media library from your server-side using private API key authentication.
*
* @see {@link https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload}
*
* @param uploadOptions
*/
upload(uploadOptions: UploadOptions): Promise<IKResponse<UploadResponse>>;
upload(uploadOptions: UploadOptions, callback: IKCallback<IKResponse<UploadResponse>>): void;
upload(
uploadOptions: UploadOptions,
callback?: IKCallback<IKResponse<UploadResponse>>,
): void | Promise<IKResponse<UploadResponse>> {
return promisify<IKResponse<UploadResponse>>(this, upload)(uploadOptions, this.options, callback);
}
/**
* This API can list all the uploaded files in your ImageKit.io media library.
* For searching and filtering, you can use query parameters as described in docs.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/list-and-search-files}
*
* @param listFilesOptions
*/
listFiles(listOptions: ListFileOptions): Promise<IKResponse<ListFileResponse>>;
listFiles(listOptions: ListFileOptions, callback: IKCallback<IKResponse<ListFileResponse>>): void;
listFiles(
listOptions: ListFileOptions,
callback?: IKCallback<IKResponse<ListFileResponse>>,
): void | Promise<IKResponse<ListFileResponse>> {
return promisify<IKResponse<ListFileResponse>>(this, manage.listFiles)(listOptions, this.options, callback);
}
/**
* Get the file details such as tags, customCoordinates, and isPrivate properties using get file detail API.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/get-file-details}
*
* @param fileId
*/
getFileDetails(fileId: string): Promise<IKResponse<FileObject>>;
getFileDetails(fileId: string, callback: IKCallback<IKResponse<FileObject>>): void;
getFileDetails(
fileId: string,
callback?: IKCallback<IKResponse<FileObject>>,
): void | Promise<IKResponse<FileObject>> {
return promisify<IKResponse<FileObject>>(this, manage.getFileDetails)(fileId, this.options, callback);
}
/**
* Get all versions of an assset.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/get-file-versions}
*
* @param fileId
*/
getFileVersions(fileId: string): Promise<IKResponse<FileObject>>;
getFileVersions(fileId: string, callback: IKCallback<IKResponse<FileObject>>): void;
getFileVersions(
fileId: string,
callback?: IKCallback<IKResponse<FileObject>>,
): void | Promise<IKResponse<FileObject>> {
return promisify<IKResponse<FileObject>>(this, manage.getFileVersions)(fileId, this.options, callback);
}
/**
* Get file details of a specific version.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/get-file-version-details}
*
* @param fileVersionDetailsOptions
*/
getFileVersionDetails(fileVersionDetailsOptions: FileVersionDetailsOptions): Promise<IKResponse<FileObject>>;
getFileVersionDetails(
fileVersionDetailsOptions: FileVersionDetailsOptions,
callback: IKCallback<IKResponse<FileObject>>,
): void;
getFileVersionDetails(
fileVersionDetailsOptions: FileVersionDetailsOptions,
callback?: IKCallback<IKResponse<FileObject>>,
): void | Promise<IKResponse<FileObject>> {
return promisify<IKResponse<FileObject>>(this, manage.getFileVersionDetails)(
fileVersionDetailsOptions,
this.options,
callback,
);
}
/**
* Get image exif, pHash and other metadata for uploaded files in ImageKit.io media library using this API.
*
* @see {@link https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files}
*
* @param fileIdOrURL The unique fileId of the uploaded file or absolute URL.
*/
getFileMetadata(fileIdOrURL: string): Promise<IKResponse<FileMetadataResponse>>;
getFileMetadata(fileIdOrURL: string, callback: IKCallback<IKResponse<FileMetadataResponse>>): void;
getFileMetadata(
fileIdOrURL: string,
callback?: IKCallback<IKResponse<FileMetadataResponse>>,
): void | Promise<IKResponse<FileMetadataResponse>> {
return promisify<IKResponse<FileMetadataResponse>>(this, manage.getFileMetadata)(
fileIdOrURL,
this.options,
callback,
);
}
/**
* Update file details such as tags and customCoordinates attribute using update file detail API.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/update-file-details}
*
* @param fileId The unique fileId of the uploaded file. fileId is returned in list files API and upload API.
* @param updateData
*/
updateFileDetails(fileId: string, updateData: FileDetailsOptions): Promise<IKResponse<FileObject>>;
updateFileDetails(fileId: string, updateData: FileDetailsOptions, callback: IKCallback<IKResponse<FileObject>>): void;
updateFileDetails(
fileId: string,
updateData: FileDetailsOptions,
callback?: IKCallback<IKResponse<FileObject>>,
): void | Promise<IKResponse<FileObject>> {
return promisify<IKResponse<FileObject>>(this, manage.updateFileDetails)(
fileId,
updateData,
this.options,
callback,
);
}
/**
* Add tags to multiple files in a single request. The method accepts an array of fileIDs of the files and an array of tags that have to be added to those files.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/add-tags-bulk}
*
* @param fileIds
* @param tags
*/
bulkAddTags(fileIds: string[], tags: string[]): Promise<IKResponse<void>>;
bulkAddTags(fileIds: string[], tags: string[], callback: IKCallback<IKResponse<void>>): void;
bulkAddTags(
fileIds: string[],
tags: string[],
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.bulkAddTags)(fileIds, tags, this.options, callback);
}
/**
* Remove tags to multiple files in a single request. The method accepts an array of fileIDs of the files and an array of tags that have to be removed to those files.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/remove-tags-bulk}
*
* @param fileIds
* @param tags
*/
bulkRemoveTags(fileIds: string[], tags: string[]): Promise<IKResponse<void>>;
bulkRemoveTags(fileIds: string[], tags: string[], callback: IKCallback<IKResponse<void>>): void;
bulkRemoveTags(
fileIds: string[],
tags: string[],
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.bulkRemoveTags)(fileIds, tags, this.options, callback);
}
/**
* Remove AITags from multiple files in a single request.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk}
*
* @param fileIds
* @param tags
*/
bulkRemoveAITags(fileIds: string[], tags: string[]): Promise<IKResponse<void>>;
bulkRemoveAITags(fileIds: string[], tags: string[], callback: IKCallback<IKResponse<void>>): void;
bulkRemoveAITags(
fileIds: string[],
tags: string[],
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.bulkRemoveAITags)(fileIds, tags, this.options, callback);
}
/**
* You can programmatically delete uploaded files in media library using delete file API.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/delete-file}
*
* @param fileId The unique fileId of the uploaded file. fileId is returned in list files API and upload API
*/
deleteFile(fileId: string): Promise<IKResponse<void>>;
deleteFile(fileId: string, callback: IKCallback<IKResponse<void>>): void;
deleteFile(fileId: string, callback?: IKCallback<IKResponse<void>>): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.deleteFile)(fileId, this.options, callback);
}
/**
* Delete any non-current version of a file.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/delete-file-version}
*
* @param deleteFileVersionOptions
*/
deleteFileVersion(deleteFileVersionOptions: DeleteFileVersionOptions): Promise<IKResponse<void>>;
deleteFileVersion(deleteFileVersionOptions: DeleteFileVersionOptions, callback: IKCallback<IKResponse<void>>): void;
deleteFileVersion(
deleteFileVersionOptions: DeleteFileVersionOptions,
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.deleteFileVersion)(
deleteFileVersionOptions,
this.options,
callback,
);
}
/**
* Restore file version to a different version of a file.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/restore-file-version}
*
* @param restoreFileVersionOptions
*/
restoreFileVersion(restoreFileVersionOptions: RestoreFileVersionOptions): Promise<IKResponse<FileObject>>;
restoreFileVersion(
restoreFileVersionOptions: RestoreFileVersionOptions,
callback: IKCallback<IKResponse<FileObject>>,
): void;
restoreFileVersion(
restoreFileVersionOptions: RestoreFileVersionOptions,
callback?: IKCallback<IKResponse<FileObject>>,
): void | Promise<IKResponse<FileObject>> {
return promisify<IKResponse<FileObject>>(this, manage.restoreFileVersion)(
restoreFileVersionOptions,
this.options,
callback,
);
}
/**
* This will purge CDN and ImageKit.io internal cache.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/purge-cache}
*
* @param url The exact URL of the file to be purged. For example - https://ik.imageki.io/your_imagekit_id/rest-of-the-file-path.jpg
*/
purgeCache(url: string): Promise<IKResponse<PurgeCacheResponse>>;
purgeCache(url: string, callback: IKCallback<IKResponse<PurgeCacheResponse>>): void;
purgeCache(
url: string,
callback?: IKCallback<IKResponse<PurgeCacheResponse>>,
): void | Promise<IKResponse<PurgeCacheResponse>> {
return promisify<IKResponse<PurgeCacheResponse>>(this, manage.purgeCache)(url, this.options, callback);
}
/**
* Get the status of submitted purge request.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/purge-cache-status}
*
* @param requestId The requestId returned in response of purge cache API.
*/
getPurgeCacheStatus(requestId: string, callback: IKCallback<IKResponse<PurgeCacheStatusResponse>>): void;
getPurgeCacheStatus(requestId: string): Promise<IKResponse<PurgeCacheStatusResponse>>;
getPurgeCacheStatus(
requestId: string,
callback?: IKCallback<IKResponse<PurgeCacheStatusResponse>>,
): void | Promise<IKResponse<PurgeCacheStatusResponse>> {
return promisify<IKResponse<PurgeCacheStatusResponse>>(this, manage.getPurgeCacheStatus)(
requestId,
this.options,
callback,
);
}
/**
* Delete multiple files. The method accepts an array of file IDs of the files that have to be deleted.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/delete-files-bulk}
*
* @param fileIdArray The requestId returned in response of purge cache API.
*/
bulkDeleteFiles(
fileIdArray: string[],
callback?: IKCallback<IKResponse<BulkDeleteFilesResponse>, IKResponse<BulkDeleteFilesError>>,
): void | Promise<IKResponse<BulkDeleteFilesResponse>>;
bulkDeleteFiles(
fileIdArray: string[],
callback?: IKCallback<IKResponse<BulkDeleteFilesResponse>, IKResponse<BulkDeleteFilesError>>,
): void | Promise<IKResponse<BulkDeleteFilesResponse>> {
return promisify<IKResponse<BulkDeleteFilesResponse>>(this, manage.bulkDeleteFiles)(
fileIdArray,
this.options,
callback,
);
}
/**
* This will copy a file from one location to another. This method accepts the source file's path and destination folder path.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/copy-file}
*
* @param copyFileOptions
*/
copyFile(copyFileOptions: CopyFileOptions): Promise<IKResponse<void>>;
copyFile(copyFileOptions: CopyFileOptions, callback: IKCallback<IKResponse<void>>): void;
copyFile(
copyFileOptions: CopyFileOptions,
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.copyFile)(copyFileOptions, this.options, callback);
}
/**
* This will move a file from one location to another. This method accepts the source file's path and destination folder path.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-file}
*
* @param moveFileOptions
*/
moveFile(moveFileOptions: MoveFileOptions): Promise<IKResponse<void>>;
moveFile(moveFileOptions: MoveFileOptions, callback: IKCallback<IKResponse<void>>): void;
moveFile(
moveFileOptions: MoveFileOptions,
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.moveFile)(moveFileOptions, this.options, callback);
}
/**
* You can programmatically rename an already existing file in the media library using rename file API. This operation would rename all file versions of the file. Note: The old URLs will stop working. The file/file version URLs cached on CDN will continue to work unless a purge is requested.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/rename-file}
*
* @param renameFileOptions
*/
renameFile(renameFileOptions: RenameFileOptions): Promise<IKResponse<RenameFileResponse>>;
renameFile(renameFileOptions: RenameFileOptions, callback: IKCallback<IKResponse<RenameFileResponse>>): void;
renameFile(
renameFileOptions: RenameFileOptions,
callback?: IKCallback<IKResponse<RenameFileResponse>>,
): void | Promise<IKResponse<RenameFileResponse>> {
return promisify<IKResponse<RenameFileResponse>>(this, manage.renameFile)(
renameFileOptions,
this.options,
callback,
);
}
/**
* This will create a new folder. This method accepts folder name and parent folder path.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/create-folder}
*
* @param createFolderOptions
*/
createFolder(createFolderOptions: CreateFolderOptions): Promise<IKResponse<void>>;
createFolder(createFolderOptions: CreateFolderOptions, callback: IKCallback<IKResponse<void>>): void;
createFolder(
createFolderOptions: CreateFolderOptions,
callback?: IKCallback<IKResponse<void>>,
): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.createFolder)(createFolderOptions, this.options, callback);
}
/**
* This will delete the specified folder and all nested files & folders. This method accepts the full path of the folder that is to be deleted.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/delete-folder}
*
* @param foldePath
*/
deleteFolder(folderPath: string): Promise<IKResponse<void>>;
deleteFolder(folderPath: string, callback: IKCallback<IKResponse<void>>): void;
deleteFolder(folderPath: string, callback?: IKCallback<IKResponse<void>>): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.deleteFolder)(folderPath, this.options, callback);
}
/**
* This will copy a folder from one location to another. This method accepts the source folder's path and destination folder path.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/copy-folder}
*
* @param copyFolderOptions
*/
copyFolder(copyFolderOptions: CopyFolderOptions): Promise<IKResponse<CopyFolderResponse>>;
copyFolder(
copyFolderOptions: CopyFolderOptions,
callback: IKCallback<IKResponse<CopyFolderResponse>, IKResponse<CopyFolderError>>,
): void;
copyFolder(
copyFolderOptions: CopyFolderOptions,
callback?: IKCallback<IKResponse<CopyFolderResponse>, IKResponse<CopyFolderError>>,
): void | Promise<IKResponse<CopyFolderResponse>> {
return promisify<IKResponse<CopyFolderResponse>>(this, manage.copyFolder)(
copyFolderOptions,
this.options,
callback,
);
}
/**
* This will move a folder from one location to another. This method accepts the source folder's path and destination folder path.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-folder}
*
* @param moveFolderOptions
*/
moveFolder(moveFolderOptions: MoveFolderOptions): Promise<IKResponse<MoveFolderResponse>>;
moveFolder(
moveFolderOptions: MoveFolderOptions,
callback: IKCallback<IKResponse<MoveFolderResponse>, IKResponse<MoveFolderError>>,
): void;
moveFolder(
moveFolderOptions: MoveFolderOptions,
callback?: IKCallback<IKResponse<MoveFolderResponse>, MoveFolderError>,
): void | Promise<IKResponse<MoveFolderResponse>> {
return promisify<IKResponse<MoveFolderResponse>>(this, manage.moveFolder)(
moveFolderOptions,
this.options,
callback,
);
}
/**
* In case you are looking to implement client-side file upload, you are going to need a token, expiry timestamp, and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these authentication parameters for you.
*
* @see {@link https://github.com/imagekit-developer/imagekit-nodejs#authentication-parameter-generation}
*
* @param token
* @param expire
*/
getAuthenticationParameters(token?: string, expire?: number): { token: string; expire: number; signature: string } {
return signature.getAuthenticationParameters(token, expire, this.options);
}
/**
* This allows us to get a bulk operation status e.g. copy or move folder. This method accepts jobId that is returned by copy and move folder operations.
*
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-folder}
*
* @param jobId
*/
getBulkJobStatus(jobId: string): Promise<IKResponse<void>>;
getBulkJobStatus(jobId: string, callback: IKCallback<IKResponse<void>>): Promise<IKResponse<void>>;
getBulkJobStatus(jobId: string, callback?: IKCallback<IKResponse<void>>): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, manage.getBulkJobStatus)(jobId, this.options, callback);
}
/**
* Create custom metadata field
*
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field}
*
* @param createCustomMetadataFieldOptions
*/
createCustomMetadataField(
createCustomMetadataFieldOptions: CreateCustomMetadataFieldOptions,
): Promise<IKResponse<CustomMetadataField>>;
createCustomMetadataField(
createCustomMetadataFieldOptions: CreateCustomMetadataFieldOptions,
callback: IKCallback<IKResponse<CustomMetadataField>>,
): Promise<IKResponse<CustomMetadataField>>;
createCustomMetadataField(
createCustomMetadataFieldOptions: CreateCustomMetadataFieldOptions,
callback?: IKCallback<IKResponse<CustomMetadataField>>,
): void | Promise<IKResponse<CustomMetadataField>> {
return promisify<IKResponse<CustomMetadataField>>(this, customMetadataField.create)(
createCustomMetadataFieldOptions,
this.options,
callback,
);
}
/**
*Get a list of all the custom metadata fields.
*
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field}
*
*/
getCustomMetadataFields(
getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions,
): Promise<IKResponse<CustomMetadataField[]>>;
getCustomMetadataFields(
getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions,
callback: IKCallback<IKResponse<CustomMetadataField[]>>,
): Promise<IKResponse<CustomMetadataField[]>>;
getCustomMetadataFields(
getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions,
callback?: IKCallback<IKResponse<CustomMetadataField[]>>,
): void | Promise<IKResponse<CustomMetadataField[]>> {
return promisify<IKResponse<CustomMetadataField[]>>(this, customMetadataField.list)(
getCustomMetadataFieldsOptions,
this.options,
callback,
);
}
/**
* Update custom metadata field
*
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field}
*
* @param fieldId
* @param updateCustomMetadataFieldOptions
*/
updateCustomMetadataField(
fieldId: string,
updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions,
): Promise<IKResponse<CustomMetadataField>>;
updateCustomMetadataField(
fieldId: string,
updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions,
callback: IKCallback<IKResponse<CustomMetadataField>>,
): Promise<IKResponse<CustomMetadataField>>;
updateCustomMetadataField(
fieldId: string,
updateCustomMetadataFieldOptions: UpdateCustomMetadataFieldOptions,
callback?: IKCallback<IKResponse<CustomMetadataField>>,
): void | Promise<IKResponse<CustomMetadataField>> {
return promisify<IKResponse<CustomMetadataField>>(this, customMetadataField.update)(
fieldId,
updateCustomMetadataFieldOptions,
this.options,
callback,
);
}
/**
* Delete a custom metadata field
*
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field}
*
* @param fieldId
*/
deleteCustomMetadataField(fieldId: string): Promise<IKResponse<void>>;
deleteCustomMetadataField(fieldId: string, callback: IKCallback<IKResponse<void>>): void;
deleteCustomMetadataField(fieldId: string, callback?: IKCallback<IKResponse<void>>): void | Promise<IKResponse<void>> {
return promisify<IKResponse<void>>(this, customMetadataField.deleteField)(fieldId, this.options, callback);
}
/**
* Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on an image's contents. ImageKit.io metadata API returns the pHash value of an image in the response. You can use this value to find a duplicate (or similar) image by calculating the distance between the two images' pHash value.
*
* This SDK exposes pHashDistance function to calculate the distance between two pHash values. It accepts two pHash hexadecimal strings and returns a numeric value indicative of the level of difference between the two images.
*
* @see {@link https://docs.imagekit.io/api-reference/metadata-api#perceptual-hash-phash}
*
* @param firstPHash
* @param secondPHash
*/
pHashDistance(firstPHash: string, secondPHash: string): number | Error {
return pHashUtils.pHashDistance(firstPHash, secondPHash);
}
/**
* @param payload - Raw webhook request body (Encoded as UTF8 string or Buffer)
* @param signature - Webhook signature as UTF8 encoded strings (Stored in `x-ik-signature` header of the request)
* @param secret - Webhook secret as UTF8 encoded string [Copy from ImageKit dashboard](https://imagekit.io/dashboard/developer/webhooks)
* @returns \{ `timestamp`: Verified UNIX epoch timestamp if signature, `event`: Parsed webhook event payload \}
*/
verifyWebhookEvent = verifyWebhookEvent;
}
export = ImageKit;