Skip to content

Commit 53240b7

Browse files
committed
includeDeleted option in get custom metadata fields
1 parent 67354d6 commit 53240b7

File tree

5 files changed

+53
-13
lines changed

5 files changed

+53
-13
lines changed

index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
DeleteFileVersionOptions,
3131
RestoreFileVersionOptions,
3232
CreateCustomMetadataFieldOptions,
33+
GetCustomMetadataFieldsOptions,
3334
CustomMetadataField,
3435
UpdateCustomMetadataFieldOptions,
3536
RenameFileOptions,
@@ -187,12 +188,12 @@ class ImageKit {
187188
*
188189
* @see {@link https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files}
189190
*
190-
* @param fileId The unique fileId of the uploaded file. fileId is returned in list files API and upload API.
191+
* @param fileIdOrURL The unique fileId of the uploaded file or absolute URL.
191192
*/
192-
getFileMetadata(fileId: string): Promise<FileMetadataResponse>;
193-
getFileMetadata(fileId: string, callback: IKCallback<FileMetadataResponse>): void;
194-
getFileMetadata(fileId: string, callback?: IKCallback<FileMetadataResponse>): void | Promise<FileMetadataResponse> {
195-
return promisify<FileMetadataResponse>(this, manage.getFileMetadata)(fileId, this.options, callback);
193+
getFileMetadata(fileIdOrURL: string): Promise<FileMetadataResponse>;
194+
getFileMetadata(fileIdOrURL: string, callback: IKCallback<FileMetadataResponse>): void;
195+
getFileMetadata(fileIdOrURL: string, callback?: IKCallback<FileMetadataResponse>): void | Promise<FileMetadataResponse> {
196+
return promisify<FileMetadataResponse>(this, manage.getFileMetadata)(fileIdOrURL, this.options, callback);
196197
}
197198

198199
/**
@@ -496,10 +497,10 @@ class ImageKit {
496497
* @see {@link https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field}
497498
*
498499
*/
499-
getCustomMetadataFields(): Promise<CustomMetadataField[]>;
500-
getCustomMetadataFields(callback: IKCallback<CustomMetadataField[]>): Promise<CustomMetadataField[]>;
501-
getCustomMetadataFields(callback?: IKCallback<CustomMetadataField[]>): void | Promise<CustomMetadataField[]> {
502-
return promisify<CustomMetadataField[]>(this, customMetadataField.list)(this.options, callback);
500+
getCustomMetadataFields(getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions): Promise<CustomMetadataField[]>;
501+
getCustomMetadataFields(getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions, callback: IKCallback<CustomMetadataField[]>): Promise<CustomMetadataField[]>;
502+
getCustomMetadataFields(getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions, callback?: IKCallback<CustomMetadataField[]>): void | Promise<CustomMetadataField[]> {
503+
return promisify<CustomMetadataField[]>(this, customMetadataField.list)(getCustomMetadataFieldsOptions, this.options, callback);
503504
}
504505

505506
/**

libs/interfaces/CustomMetatadaField.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,11 @@ export interface UpdateCustomMetadataFieldOptions {
6969
* Note: type cannot be updated and will be ignored if sent with the schema. The schema will be validated as per the existing type.
7070
*/
7171
schema?: CustomMetadataFieldSchemaMinusType
72+
}
73+
74+
export interface GetCustomMetadataFieldsOptions {
75+
/**
76+
* Set it to true if you want to receive deleted fields as well in the API response.
77+
*/
78+
includeDeleted?: boolean;
7279
}

libs/interfaces/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { BulkDeleteFilesResponse, BulkDeleteFilesError } from "./BulkDeleteFiles
1515
import { CopyFolderOptions, CopyFolderResponse, CopyFolderError } from "./CopyFolder";
1616
import { MoveFolderOptions, MoveFolderResponse, MoveFolderError } from "./MoveFolder";
1717
import { DeleteFileVersionOptions, RestoreFileVersionOptions } from "./FileVersion"
18-
import { CreateCustomMetadataFieldOptions, CustomMetadataField, UpdateCustomMetadataFieldOptions } from "./CustomMetatadaField"
18+
import { CreateCustomMetadataFieldOptions, CustomMetadataField, UpdateCustomMetadataFieldOptions, GetCustomMetadataFieldsOptions } from "./CustomMetatadaField"
1919
import { RenameFileOptions, RenameFileResponse } from "./Rename"
2020

2121
type FinalUrlOptions = ImageKitOptions & UrlOptions; // actual options used to construct url
@@ -51,6 +51,7 @@ export {
5151
DeleteFileVersionOptions,
5252
RestoreFileVersionOptions,
5353
CreateCustomMetadataFieldOptions,
54+
GetCustomMetadataFieldsOptions,
5455
CustomMetadataField,
5556
UpdateCustomMetadataFieldOptions,
5657
RenameFileOptions,

libs/manage/custom-metadata-field.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
ImageKitOptions,
1818
CreateCustomMetadataFieldOptions,
1919
CustomMetadataField,
20-
UpdateCustomMetadataFieldOptions
20+
UpdateCustomMetadataFieldOptions,
21+
GetCustomMetadataFieldsOptions,
2122
} from "../interfaces/";
2223

2324
const create = function (createCustomMetadataFieldOptions: CreateCustomMetadataFieldOptions, defaultOptions: ImageKitOptions, callback?: IKCallback<CustomMetadataField>) {
@@ -56,12 +57,15 @@ const create = function (createCustomMetadataFieldOptions: CreateCustomMetadataF
5657
};
5758

5859
const list = function (
60+
getCustomMetadataFieldsOptions: GetCustomMetadataFieldsOptions,
5961
defaultOptions: ImageKitOptions,
6062
callback?: IKCallback<CustomMetadataField[]>,
6163
) {
64+
const { includeDeleted = false } = getCustomMetadataFieldsOptions || {};
6265
var requestOptions = {
6366
url: "https://api.imagekit.io/v1/customMetadataFields",
6467
method: "GET",
68+
qs: { includeDeleted }
6569
};
6670

6771
request(requestOptions, defaultOptions, callback);

tests/custom-metadata-field.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ describe("Custom metadata field API", function () {
115115
it('Get field', function (done) {
116116
const scope = nock('https://api.imagekit.io')
117117
.get("/v1/customMetadataFields")
118+
.query({
119+
includeDeleted: false
120+
})
118121
.basicAuth({ user: initializationParams.privateKey, pass: '' })
119122
.reply(function (uri, requestBody) {
120123
expect(requestBody).to.be.empty;
@@ -125,6 +128,24 @@ describe("Custom metadata field API", function () {
125128
imagekit.getCustomMetadataFields();
126129
});
127130

131+
it('Get field - includeDeleted true', function (done) {
132+
const scope = nock('https://api.imagekit.io')
133+
.get("/v1/customMetadataFields")
134+
.query({
135+
includeDeleted: true
136+
})
137+
.basicAuth({ user: initializationParams.privateKey, pass: '' })
138+
.reply(function (uri, requestBody) {
139+
expect(requestBody).to.be.empty;
140+
done();
141+
return [200];
142+
})
143+
144+
imagekit.getCustomMetadataFields({
145+
includeDeleted: true
146+
});
147+
});
148+
128149
it('Update field', function (done) {
129150
const scope = nock('https://api.imagekit.io')
130151
.patch("/v1/customMetadataFields/fieldId")
@@ -235,11 +256,14 @@ describe("Custom metadata field API", function () {
235256
it('Get fields', function (done) {
236257
const scope = nock('https://api.imagekit.io')
237258
.get("/v1/customMetadataFields")
259+
.query({
260+
includeDeleted: false
261+
})
238262
.basicAuth({ user: initializationParams.privateKey, pass: '' })
239263
.reply(200, [dummyAPISuccessResponse, dummyAPISuccessResponse])
240264

241265
var callback = sinon.spy();
242-
imagekit.getCustomMetadataFields(callback);
266+
imagekit.getCustomMetadataFields({}, callback);
243267

244268
setTimeout(function () {
245269
expect(callback.calledOnce).to.be.true;
@@ -312,11 +336,14 @@ describe("Custom metadata field API", function () {
312336
it('Get fields', function (done) {
313337
const scope = nock('https://api.imagekit.io')
314338
.get("/v1/customMetadataFields")
339+
.query({
340+
includeDeleted: false
341+
})
315342
.basicAuth({ user: initializationParams.privateKey, pass: '' })
316343
.reply(500, dummyAPIErrorResponse)
317344

318345
var callback = sinon.spy();
319-
imagekit.getCustomMetadataFields(callback);
346+
imagekit.getCustomMetadataFields({}, callback);
320347

321348
setTimeout(function () {
322349
expect(callback.calledOnce).to.be.true;

0 commit comments

Comments
 (0)