Skip to content

Commit bfcfbb9

Browse files
authored
fix: added folder object in ListFileResponse (#106)
* fix: added folder object in ListFileResponse * chore: moved changelog to separate file
1 parent 5e264de commit bfcfbb9

File tree

8 files changed

+89
-81
lines changed

8 files changed

+89
-81
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Changelog
2+
3+
### SDK Version 5.3.0
4+
5+
### Breaking changes
6+
7+
**1. `listFiles` API response type**
8+
* The `listFiles` method now returns a unified response type, ListFileResponse, which is an array of both `FileObject` and `FolderObject`. Previously, the response contained only `FileObject`. The `type` property in the response object indicates whether the object is a file or a folder. Even though this change has been made to just the type of the return object, it can be considered a breaking change so it may require require any code relying on the `listFiles` response to be updated.
9+
10+
```
11+
const result = await imagekit.listFiles({ skip: 0, limit: 10 });
12+
13+
# Before (Pre-version 5.3.0)
14+
result.forEach((item) => {
15+
console.log(item);
16+
});
17+
18+
# After (Version 5.3.0 and above)
19+
result.forEach((item) => {
20+
if (item.type === "folder") {
21+
console.log(item) // item is of type FolderObject
22+
} else {
23+
console.log(item) // item is of type FileObject
24+
}
25+
});
26+
```
27+
28+
29+
### SDK Version 5.0.0
30+
31+
#### Breaking changes
32+
33+
**1. Overlay syntax update**
34+
* In version 5.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
35+
* You can migrate to the new layers syntax using the `raw` transformation parameter.
36+
37+
**2. Remove Node.js 10.x support**
38+
* In version 5.0.0, we've removed support for Node.js version 10.x.

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ ImageKit is complete media storage, optimization, and transformation solution th
2525
* [Support](#support)
2626
* [Links](#links)
2727

28-
## Changelog
29-
30-
### SDK Version 5.0.0
31-
32-
#### Breaking changes
33-
34-
**1. Overlay syntax update**
35-
* In version 5.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
36-
* You can migrate to the new layers syntax using the `raw` transformation parameter.
37-
38-
**2. Remove Node.js 10.x support**
39-
* In version 5.0.0, we've removed support for Node.js version 10.x.
40-
4128
## Installation
4229

4330
Use the following command to download this module. Use the optional `--save` parameter if you wish to save the dependency in your `package.json` file.

index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CopyFolderResponse,
1111
FileDetailsOptions,
1212
FileObject,
13+
FolderObject,
1314
FileMetadataResponse,
1415
ImageKitOptions,
1516
ListFileOptions,
@@ -135,13 +136,13 @@ class ImageKit {
135136
*
136137
* @param listFilesOptions
137138
*/
138-
listFiles(listOptions: ListFileOptions): Promise<IKResponse<FileObject[]>>;
139-
listFiles(listOptions: ListFileOptions, callback: IKCallback<IKResponse<FileObject[]>>): void;
139+
listFiles(listOptions: ListFileOptions): Promise<IKResponse<ListFileResponse>>;
140+
listFiles(listOptions: ListFileOptions, callback: IKCallback<IKResponse<ListFileResponse>>): void;
140141
listFiles(
141142
listOptions: ListFileOptions,
142-
callback?: IKCallback<IKResponse<FileObject[]>>,
143-
): void | Promise<IKResponse<FileObject[]>> {
144-
return promisify<IKResponse<FileObject[]>>(this, manage.listFiles)(listOptions, this.options, callback);
143+
callback?: IKCallback<IKResponse<ListFileResponse>>,
144+
): void | Promise<IKResponse<ListFileResponse>> {
145+
return promisify<IKResponse<ListFileResponse>>(this, manage.listFiles)(listOptions, this.options, callback);
145146
}
146147

147148
/**

libs/interfaces/FileDetails.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { FileType } from "./FileType";
2-
import { Item } from "./Item";
32

43
export interface EmbeddedMetadataValues {
54
[key: string]:
@@ -56,13 +55,13 @@ export interface FileDetailsOptions {
5655
* Example - 50,50,500,500
5756
*/
5857
customCoordinates?: string;
59-
/*
60-
* Object with array of extensions to be processed on the image.
61-
*/
58+
/*
59+
* Object with array of extensions to be processed on the image.
60+
*/
6261
extensions?: Extension;
6362
/*
64-
* Final status of pending extensions will be sent to this URL.
65-
*/
63+
* Final status of pending extensions will be sent to this URL.
64+
*/
6665
webhookUrl?: string
6766
/*
6867
* Array of AI tags to remove from the asset.
@@ -93,9 +92,9 @@ export interface FileObject {
9392
*/
9493
fileId: string;
9594
/**
96-
* Type of item. It can be either file or folder.
95+
* Type of item. It can be either file, file-version or folder.
9796
*/
98-
type: Item;
97+
type: "file" | "file-version";
9998
/**
10099
* Name of the file or folder.
101100
*/
@@ -180,6 +179,38 @@ export interface FileObject {
180179
versionInfo?: { name: string; id: string };
181180
}
182181

182+
/**
183+
*
184+
* Folder object.
185+
*
186+
* @see {@link https://docs.imagekit.io/api-reference/media-api#file-object-structure}
187+
*/
188+
export interface FolderObject {
189+
/**
190+
* The unique fileId of the folder.
191+
*/
192+
folderId: string;
193+
/**
194+
* Type of item. It can be either file, file-version or folder.
195+
*/
196+
type: "folder";
197+
/**
198+
* Name of the file or folder.
199+
*/
200+
name: string;
201+
/**
202+
* The relative path of the folder.
203+
*/
204+
folderPath: string;
205+
/*
206+
* The date and time when the folder was first created. The format is YYYY-MM-DDTHH:mm:ss.sssZ
207+
*/
208+
createdAt: string;
209+
/*
210+
* The date and time when the folder was last updated. The format is YYYY-MM-DDTHH:mm:ss.sssZ
211+
*/
212+
updatedAt: string;
213+
}
183214

184215
export interface FileVersionDetailsOptions {
185216
/**
@@ -190,4 +221,4 @@ export interface FileVersionDetailsOptions {
190221
* The unique versionId of the uploaded file's version. This is returned in list files API and upload API as id within the versionInfo parameter.
191222
*/
192223
versionId: string;
193-
}
224+
}

libs/interfaces/Item.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

libs/interfaces/ListFile.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { FileObject, FolderObject } from "./FileDetails";
12
import { FileType } from "./FileType";
2-
import { Item } from "./Item";
33

44
/**
55
* List and search files options
@@ -76,50 +76,4 @@ export interface ListFileOptions {
7676
*
7777
* @see {@link https://docs.imagekit.io/api-reference/media-api/list-and-search-files#response-structure-and-status-code-application-json}
7878
*/
79-
export interface ListFileResponse {
80-
/**
81-
* The unique fileId of the uploaded file.
82-
*/
83-
fileId: string;
84-
/**
85-
* Type of item. It can be either file or folder.
86-
*/
87-
type: Item;
88-
/**
89-
* Name of the file or folder.
90-
*/
91-
name: string;
92-
/**
93-
* The date and time when the file was first uploaded. The format is `YYYY-MM-DDTHH:mm:ss.sssZ`.
94-
*/
95-
createdAt: string;
96-
/**
97-
* The relative path of the file. In the case of an image, you can use this
98-
* path to construct different transformations.
99-
*/
100-
filePath: string;
101-
/**
102-
* Array of tags associated with the image. If no tags are set, it will be null.
103-
*/
104-
tags: string[] | null;
105-
/**
106-
* Is the file marked as private. It can be either true or false.
107-
*/
108-
isPrivateFile: boolean;
109-
/**
110-
* Value of custom coordinates associated with the image in format x,y,width,height. If customCoordinates are not defined then it is null.
111-
*/
112-
customCoordinates: string | null;
113-
/**
114-
* A publicly accessible URL of the file.
115-
*/
116-
url: string;
117-
/**
118-
* In case of an image, a small thumbnail URL.
119-
*/
120-
thumbnail: string;
121-
/**
122-
* The type of file, it could be either image or non-image.
123-
*/
124-
fileType: FileType;
125-
}
79+
export type ListFileResponse = Array<FileObject | FolderObject>;

libs/interfaces/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ListFileOptions, ListFileResponse } from "./ListFile";
88
import { CopyFileOptions } from "./CopyFile";
99
import { MoveFileOptions } from "./MoveFile";
1010
import { CreateFolderOptions } from "./CreateFolder";
11-
import { FileDetailsOptions, FileVersionDetailsOptions, FileObject } from "./FileDetails";
11+
import { FileDetailsOptions, FileVersionDetailsOptions, FileObject, FolderObject } from "./FileDetails";
1212
import { FileMetadataResponse } from "./FileMetadata";
1313
import { PurgeCacheResponse, PurgeCacheStatusResponse } from "./PurgeCache";
1414
import { BulkDeleteFilesResponse, BulkDeleteFilesError } from "./BulkDeleteFiles";
@@ -44,6 +44,7 @@ export type {
4444
FileDetailsOptions,
4545
FileVersionDetailsOptions,
4646
FileObject,
47+
FolderObject,
4748
FileMetadataResponse,
4849
PurgeCacheResponse,
4950
PurgeCacheStatusResponse,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit",
3-
"version": "5.2.1",
3+
"version": "5.3.0",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)