Skip to content

Commit 364b3a6

Browse files
committed
update existing method signature to unify methods
1 parent e3b688e commit 364b3a6

File tree

12 files changed

+285
-134
lines changed

12 files changed

+285
-134
lines changed

index.ts

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import {
2121
UploadOptions,
2222
UploadResponse,
2323
UrlOptions,
24+
CopyFileOptions,
25+
MoveFileOptions,
26+
CreateFolderOptions,
27+
CopyFolderOptions,
28+
MoveFolderOptions,
2429
} from "./libs/interfaces";
2530
import { IKCallback } from "./libs/interfaces/IKCallback";
2631
import manage from "./libs/manage";
@@ -120,13 +125,13 @@ class ImageKit {
120125
*
121126
* @param listFilesOptions
122127
*/
123-
listFiles(listOptions: ListFileOptions): Promise<ListFileResponse[]>;
124-
listFiles(listOptions: ListFileOptions, callback: IKCallback<ListFileResponse[]>): void;
128+
listFiles(listOptions: ListFileOptions): Promise<FileDetailsResponse[]>;
129+
listFiles(listOptions: ListFileOptions, callback: IKCallback<FileDetailsResponse[]>): void;
125130
listFiles(
126131
listOptions: ListFileOptions,
127-
callback?: IKCallback<ListFileResponse[]>,
128-
): void | Promise<ListFileResponse[]> {
129-
return promisify<ListFileResponse[]>(this, manage.listFiles)(listOptions, this.options, callback);
132+
callback?: IKCallback<FileDetailsResponse[]>,
133+
): void | Promise<FileDetailsResponse[]> {
134+
return promisify<FileDetailsResponse[]>(this, manage.listFiles)(listOptions, this.options, callback);
130135
}
131136

132137
/**
@@ -266,41 +271,39 @@ class ImageKit {
266271
*
267272
* @see {@link https://docs.imagekit.io/api-reference/media-api/copy-file}
268273
*
269-
* @param sourceFilePath
270-
* @param destinationPath
274+
* @param copyFileOptions
271275
*/
272-
copyFile(sourceFilePath: string, destinationPath: string): Promise<void>;
273-
copyFile(sourceFilePath: string, destinationPath: string, callback: IKCallback<void>): void;
274-
copyFile(sourceFilePath: string, destinationPath: string, callback?: IKCallback<void>): void | Promise<void> {
275-
return promisify(this, manage.copyFile)(sourceFilePath, destinationPath, this.options, callback);
276+
copyFile(copyFileOptions: CopyFileOptions): Promise<void>;
277+
copyFile(copyFileOptions: CopyFileOptions, callback: IKCallback<void>): void;
278+
copyFile(copyFileOptions: CopyFileOptions, callback?: IKCallback<void>): void | Promise<void> {
279+
return promisify(this, manage.copyFile)(copyFileOptions, this.options, callback);
276280
}
277281

278282
/**
279283
* This will move a file from one location to another. This method accepts the source file's path and destination folder path.
280284
*
281285
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-file}
282286
*
283-
* @param sourceFilePath
284-
* @param destinationPath
287+
* @param moveFileOptions
285288
*/
286-
moveFile(sourceFilePath: string, destinationPath: string): Promise<void>;
287-
moveFile(sourceFilePath: string, destinationPath: string, callback: IKCallback<void>): void;
288-
moveFile(sourceFilePath: string, destinationPath: string, callback?: IKCallback<void>): void | Promise<void> {
289-
return promisify(this, manage.moveFile)(sourceFilePath, destinationPath, this.options, callback);
289+
moveFile(moveFileOptions: MoveFileOptions): Promise<void>;
290+
moveFile(moveFileOptions: MoveFileOptions, callback: IKCallback<void>): void;
291+
moveFile(moveFileOptions: MoveFileOptions, callback?: IKCallback<void>): void | Promise<void> {
292+
return promisify(this, manage.moveFile)(moveFileOptions, this.options, callback);
290293
}
291294

292295
/**
293296
* This will create a new folder. This method accepts folder name and parent folder path.
294297
*
295298
* @see {@link https://docs.imagekit.io/api-reference/media-api/create-folder}
296299
*
297-
* @param folderName
300+
* @param createFolderOptions
298301
* @param parentFolderPath
299302
*/
300-
createFolder(folderName: string, parentFolderPath: string): Promise<void>;
301-
createFolder(folderName: string, parentFolderPath: string, callback: IKCallback<void>): void;
302-
createFolder(folderName: string, parentFolderPath: string, callback?: IKCallback<void>): void | Promise<void> {
303-
return promisify(this, manage.createFolder)(folderName, parentFolderPath, this.options, callback);
303+
createFolder(createFolderOptions: CreateFolderOptions): Promise<void>;
304+
createFolder(createFolderOptions: CreateFolderOptions, callback: IKCallback<void>): void;
305+
createFolder(createFolderOptions: CreateFolderOptions, callback?: IKCallback<void>): void | Promise<void> {
306+
return promisify(this, manage.createFolder)(createFolderOptions, this.options, callback);
304307
}
305308

306309
/**
@@ -321,23 +324,19 @@ class ImageKit {
321324
*
322325
* @see {@link https://docs.imagekit.io/api-reference/media-api/copy-folder}
323326
*
324-
* @param sourceFolderPath
325-
* @param destinationPath
327+
* @param copyFolderOptions
326328
*/
327-
copyFolder(sourceFolderPath: string, destinationPath: string): Promise<CopyFolderResponse>;
329+
copyFolder(copyFolderOptions: CopyFolderOptions): Promise<CopyFolderResponse>;
328330
copyFolder(
329-
sourceFolderPath: string,
330-
destinationPath: string,
331+
copyFolderOptions: CopyFolderOptions,
331332
callback: IKCallback<CopyFolderResponse, CopyFolderError>,
332333
): void;
333334
copyFolder(
334-
sourceFolderPath: string,
335-
destinationPath: string,
335+
copyFolderOptions: CopyFolderOptions,
336336
callback?: IKCallback<CopyFolderResponse, CopyFolderError>,
337337
): void | Promise<CopyFolderResponse> {
338338
return promisify<CopyFolderResponse>(this, manage.copyFolder)(
339-
sourceFolderPath,
340-
destinationPath,
339+
copyFolderOptions,
341340
this.options,
342341
callback,
343342
);
@@ -351,20 +350,17 @@ class ImageKit {
351350
* @param sourceFolderPath
352351
* @param destinationPath
353352
*/
354-
moveFolder(sourceFolderPath: string, destinationPath: string): Promise<MoveFolderResponse>;
353+
moveFolder(moveFolderOptions: MoveFolderOptions): Promise<MoveFolderResponse>;
355354
moveFolder(
356-
sourceFolderPath: string,
357-
destinationPath: string,
355+
moveFolderOptions: MoveFolderOptions,
358356
callback: IKCallback<MoveFolderResponse, MoveFolderError>,
359357
): void;
360358
moveFolder(
361-
sourceFolderPath: string,
362-
destinationPath: string,
359+
moveFolderOptions: MoveFolderOptions,
363360
callback?: IKCallback<MoveFolderResponse, MoveFolderError>,
364361
): void | Promise<MoveFolderResponse> {
365362
return promisify<MoveFolderResponse>(this, manage.moveFolder)(
366-
sourceFolderPath,
367-
destinationPath,
363+
moveFolderOptions,
368364
this.options,
369365
callback,
370366
);

libs/constants/errorMessages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
"MISSING_UPLOAD_FILENAME_PARAMETER": { message: "Missing fileName parameter for upload", help: "" },
1818
"JOB_ID_MISSING": { message: "Missing jobId parameter", help: "" },
1919
"INVALID_DESTINATION_FOLDER_PATH": { messages: "Invalid destinationPath value", help: "It should be a string like '/path/to/folder'" },
20+
"INVALID_INCLUDE_VERSION": { messages: "Invalid includeVersions value", help: "It should be a boolean" },
2021
"INVALID_SOURCE_FILE_PATH": { messages: "Invalid sourceFilePath value", help: "It should be a string like /path/to/file.jpg'" },
2122
"INVALID_SOURCE_FOLDER_PATH": { messages: "Invalid sourceFolderPath value", help: "It should be a string like '/path/to/folder'" },
2223
"INVALID_FOLDER_NAME": { messages: "Invalid folderName value", help: "" },

libs/interfaces/CopyFile.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface CopyFileOptions {
2+
/**
3+
* The full path of the file you want to copy. For example - /path/to/file.jpg
4+
*/
5+
sourceFilePath: string;
6+
/**
7+
* Full path to the folder you want to copy the above file into. For example - /folder/to/copy/into/
8+
*/
9+
destinationPath: string;
10+
/**
11+
* Option to copy all versions of a file. By default, only the current version of the file is copied. When set to true, all versions of the file will be copied.
12+
* Default value is false
13+
*/
14+
includeVersions?: boolean;
15+
}

libs/interfaces/CopyFolder.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ export interface CopyFolderError extends Error {
2121
message: string;
2222
reason: string;
2323
}
24+
25+
/**
26+
* Copy folder API options
27+
*
28+
* @see {@link https://docs.imagekit.io/api-reference/media-api/copy-folder}
29+
*/
30+
export interface CopyFolderOptions {
31+
/**
32+
* The full path to the source folder you want to copy. For example - /path/of/source/folder.
33+
*/
34+
sourceFolderPath: string;
35+
/**
36+
* Full path to the destination folder where you want to copy the source folder into. For example - /path/of/destination/folder.
37+
*/
38+
destinationPath: string;
39+
/**
40+
* Option to copy all versions of files that are nested inside the selected folder. By default, only the current version of each file will be copied. When set to true, all versions of each file will be copied.
41+
* Default value - false
42+
*/
43+
includeVersions?: boolean;
44+
}

libs/interfaces/CreateFolder.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface CreateFolderOptions {
2+
/**
3+
* The folder will be created with this name. All characters except alphabets and numbers (inclusive of unicode letters, marks, and numerals in other languages) will be replaced by an underscore i.e. _.
4+
*/
5+
folderName: string;
6+
/**
7+
* The folder where the new folder should be created, for root use / else the path e.g. containing/folder/.
8+
* Note: If any folder(s) is not present in the parentFolderPath parameter, it will be automatically created. For example, if you pass /product/images/summer, then product, images, and summer folders will be created if they don't already exist.
9+
*/
10+
parentFolderPath: string;
11+
}

libs/interfaces/FileDetails.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ export interface FileDetailsOptions {
2424
* Final status of pending extensions will be sent to this URL.
2525
*/
2626
webhookUrl?: string
27+
/*
28+
* Array of AI tags to remove from the asset.
29+
*/
30+
removeAITags?: string[];
31+
/*
32+
* A key-value data to be associated with the asset. To unset a key, send null value for that key. Before setting any custom metadata on an asset you have to create the field using custom metadata fields API.
33+
*/
34+
customMetadata?: object;
2735
}
2836

2937
/**
3038
*
31-
* File details such as tags, customCoordinates, and isPrivate properties using get file detail API.
39+
* File object.
3240
*
33-
* @see {@link https://docs.imagekit.io/api-reference/media-api/get-file-details}
34-
* @see {@link https://docs.imagekit.io/api-reference/media-api/update-file-details#understanding-response}
41+
* @see {@link https://docs.imagekit.io/api-reference/media-api#file-object-structure}
3542
*/
3643
export interface FileDetailsResponse {
3744
/**
@@ -82,6 +89,42 @@ export interface FileDetailsResponse {
8289
AITags?: object[];
8390
/*
8491
* Field object which will contain the status of each extension at the time of completion of the update/upload request.
85-
*/
92+
*/
8693
extensionStatus?: { [key: string]: string }
94+
/*
95+
* Consolidated embedded metadata associated with the file. It includes exif, iptc, and xmp data.
96+
*/
97+
embeddedMetadata?: object | null;
98+
/*
99+
* A key-value data associated with the asset. Before setting any custom metadata on an asset, you have to create the field using custom metadata fields API.
100+
*/
101+
customMetadata?: object;
102+
/*
103+
* Size of the file in bytes
104+
*/
105+
size: number;
106+
/*
107+
* The date and time when the file was first uploaded. The format is YYYY-MM-DDTHH:mm:ss.sssZ
108+
*/
109+
createdAt: string;
110+
/*
111+
* The date and time when the file was last updated. The format is YYYY-MM-DDTHH:mm:ss.sssZ
112+
*/
113+
updatedAt: string;
114+
/*
115+
* Height of the image in pixels (Only for images)
116+
*/
117+
height: number;
118+
/*
119+
* Width of the image in pixels (Only for Images)
120+
*/
121+
width: number;
122+
/*
123+
* A boolean indicating if the image has an alpha layer or not.
124+
*/
125+
hasAlpha: boolean;
126+
/*
127+
* MIME Type of the file. For example - image/jpeg
128+
*/
129+
mime: string;
87130
}

libs/interfaces/MoveFile.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Move file API options
3+
*
4+
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-file}
5+
*/
6+
export interface MoveFileOptions {
7+
/**
8+
* The full path of the file you want to move. For example - /path/to/file.jpg
9+
*/
10+
sourceFilePath: string;
11+
/**
12+
* Full path to the folder you want to move the above file into. For example - /folder/to/move/into/
13+
*/
14+
destinationPath: string;
15+
}

libs/interfaces/MoveFolder.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ export interface MoveFolderError extends Error {
2121
message: string;
2222
reason: string;
2323
}
24+
25+
26+
/**
27+
* Move folder API options
28+
*
29+
* @see {@link https://docs.imagekit.io/api-reference/media-api/move-folder}
30+
*/
31+
export interface MoveFolderOptions {
32+
/**
33+
* The full path to the source folder you want to move. For example - /path/of/source/folder.
34+
*/
35+
sourceFolderPath: string;
36+
/**
37+
* Full path to the destination folder where you want to move the source folder into. For example - /path/of/destination/folder.
38+
*/
39+
destinationPath: string;
40+
}

libs/interfaces/UploadResponse.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ export interface UploadResponse {
5757
/**
5858
* The metadata of the upload file. Use responseFields property in request to get the metadata returned in response of upload API.
5959
*/
60-
metadata?: string;
60+
metadata?: object;
6161
/*
62-
* AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse.
63-
*/
62+
* AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse.
63+
*/
6464
AITags?: object[];
6565
/*
6666
* Field object which will contain the status of each extension at the time of completion of the update/upload request.
67-
*/
67+
*/
6868
extensionStatus?: { [key: string]: string }
69+
/*
70+
* Consolidated embedded metadata associated with the file. It includes exif, iptc, and xmp data.
71+
*/
72+
embeddedMetadata?: object | null;
73+
/*
74+
* A key-value data associated with the asset. Before setting any custom metadata on an asset, you have to create the field using custom metadata fields API.
75+
*/
76+
customMetadata?: object;
6977
}

libs/interfaces/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { UploadResponse } from "./UploadResponse";
55
import { FileType } from "./FileType";
66
import { UrlOptions } from "./UrlOptions";
77
import { ListFileOptions, ListFileResponse } from "./ListFile";
8+
import { CopyFileOptions } from "./CopyFile";
9+
import { MoveFileOptions } from "./MoveFile";
10+
import { CreateFolderOptions } from "./CreateFolder";
811
import { FileDetailsOptions, FileDetailsResponse } from "./FileDetails";
912
import { FileMetadataResponse } from "./FileMetadata";
1013
import { PurgeCacheResponse, PurgeCacheStatusResponse } from "./PurgeCache";
1114
import { BulkDeleteFilesResponse, BulkDeleteFilesError } from "./BulkDeleteFiles";
12-
import { CopyFolderResponse, CopyFolderError } from "./CopyFolder";
13-
import { MoveFolderResponse, MoveFolderError } from "./MoveFolder";
15+
import { CopyFolderOptions, CopyFolderResponse, CopyFolderError } from "./CopyFolder";
16+
import { MoveFolderOptions, MoveFolderResponse, MoveFolderError } from "./MoveFolder";
1417

1518
type FinalUrlOptions = ImageKitOptions & UrlOptions; // actual options used to construct url
1619

@@ -36,5 +39,10 @@ export {
3639
CopyFolderError,
3740
MoveFolderResponse,
3841
MoveFolderError,
42+
CopyFileOptions,
43+
MoveFileOptions,
44+
CreateFolderOptions,
45+
CopyFolderOptions,
46+
MoveFolderOptions,
3947
};
4048
export { IKCallback } from "./IKCallback";

0 commit comments

Comments
 (0)