Skip to content

Commit 1226b6d

Browse files
Merge branch 'master' into IK-1068
2 parents ee59717 + ff88b20 commit 1226b6d

File tree

13 files changed

+173
-57
lines changed

13 files changed

+173
-57
lines changed

README.md

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ImageKit.io Node.js SDK
44

55
[![Node CI](https://github.com/imagekit-developer/imagekit-nodejs/workflows/Node%20CI/badge.svg)](https://github.com/imagekit-developer/imagekit-nodejs/)
6-
[![npm version](https://img.shields.io/npm/v/imagekit)](https://www.npmjs.com/package/imagekit)
6+
[![npm version](https://img.shields.io/npm/v/imagekit)](https://www.npmjs.com/package/imagekit)
77
[![codecov](https://codecov.io/gh/imagekit-developer/imagekit-nodejs/branch/master/graph/badge.svg)](https://codecov.io/gh/imagekit-developer/imagekit-nodejs)
88
[![Try imagekit on RunKit](https://badge.runkitcdn.com/imagekit.svg)](https://npm.runkit.com/imagekit)
99
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -45,6 +45,10 @@ Use the following command to download this module. Use the optional `--save` par
4545
```
4646
npm install imagekit --save
4747
# or
48+
pnpm install imagekit --save
49+
# or
50+
bun install imagekit // if you are using [Bun](https://bun.sh/) compiler
51+
# or
4852
yarn add imagekit
4953
```
5054

@@ -351,13 +355,14 @@ imagekit.upload({
351355
}
352356
]
353357
},
354-
checks={`"file.size" < "1mb"`} // To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
358+
checks: {`"file.size" < "1mb"`}, // To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
359+
isPublished: true
355360
}, function(error, result) {
356361
if(error) console.log(error);
357362
else console.log(result);
358363
});
359364

360-
// Using Promises
365+
// Using Promises
361366

362367
imagekit.upload({
363368
file : <url|base_64|binary>, //required
@@ -411,7 +416,7 @@ imagekit.listFiles({
411416
});
412417

413418

414-
// Using Promises
419+
// Using Promises
415420

416421
imagekit.listFiles({
417422
skip : 10,
@@ -436,7 +441,7 @@ imagekit.getFileDetails("file_id", function(error, result) {
436441
});
437442

438443

439-
// Using Promises
444+
// Using Promises
440445

441446
imagekit.getFileDetails("file_id")
442447
}).then(response => {
@@ -459,7 +464,7 @@ imagekit.getFileVersions("file_id", function(error, result) {
459464
});
460465

461466

462-
// Using Promises
467+
// Using Promises
463468

464469
imagekit.getFileVersions("file_id")
465470
}).then(response => {
@@ -485,7 +490,7 @@ imagekit.getFileVersionDetails({
485490
});
486491

487492

488-
// Using Promises
493+
// Using Promises
489494

490495
imagekit.getFileVersionDetails({
491496
fileId: "file_id",
@@ -502,10 +507,12 @@ imagekit.getFileVersionDetails({
502507

503508
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details). The first argument to the `updateFileDetails` method is the file ID, and the second argument is an object with the parameters to be updated.
504509

510+
Note: If `publish` is included in the update options, no other parameters are allowed. If any are present, an error will be returned: `Your request cannot contain any other parameters when publish is present`.
511+
505512
```js
506513
// Using Callback Function
507514

508-
imagekit.updateFileDetails("file_id", {
515+
imagekit.updateFileDetails("file_id", {
509516
tags : ['image_tag'],
510517
customCoordinates : "10,10,100,100",
511518
extensions: [
@@ -521,18 +528,13 @@ imagekit.updateFileDetails("file_id", {
521528
});
522529

523530

524-
// Using Promises
531+
// Using Promises
525532

526533
imagekit.updateFileDetails("file_id", {
527-
tags : ['image_tag'],
528-
customCoordinates : "10,10,100,100",
529-
extensions: [
530-
{
531-
name: "google-auto-tagging",
532-
maxTags: 5,
533-
minConfidence: 95
534-
}
535-
]
534+
publish: {
535+
isPublished: true,
536+
includeFileVersions: true
537+
}
536538
}).then(response => {
537539
console.log(response);
538540
}).catch(error => {
@@ -616,7 +618,7 @@ imagekit.deleteFile("file_id", function(error, result) {
616618
});
617619

618620

619-
// Using Promises
621+
// Using Promises
620622

621623
imagekit.deleteFile("file_id").then(response => {
622624
console.log(response);
@@ -641,7 +643,7 @@ imagekit.deleteFileVersion({
641643
});
642644

643645

644-
// Using Promises
646+
// Using Promises
645647

646648
imagekit.deleteFile({
647649
fileId: "file_id",
@@ -666,7 +668,7 @@ imagekit.bulkDeleteFiles(["file_id_1", "file_id_2"], function(error, result) {
666668
});
667669

668670

669-
// Using Promises
671+
// Using Promises
670672

671673
imagekit.bulkDeleteFiles(["file_id_1", "file_id_2"]).then(response => {
672674
console.log(response);
@@ -925,7 +927,7 @@ imagekit.purgeCache("full_url", function(error, result) {
925927
});
926928

927929

928-
// Using Promises
930+
// Using Promises
929931

930932
imagekit.purgeCache("full_url").then(response => {
931933
console.log(response);
@@ -947,7 +949,7 @@ imagekit.getPurgeCacheStatus("cache_request_id", function(error, result) {
947949
});
948950

949951

950-
// Using Promises
952+
// Using Promises
951953

952954
imagekit.getPurgeCacheStatus("cache_request_id").then(response => {
953955
console.log(response);
@@ -968,7 +970,7 @@ imagekit.getFileMetadata("file_id", function(error, result) {
968970
});
969971

970972

971-
// Using Promises
973+
// Using Promises
972974
imagekit.getFileMetadata("file_id")
973975
}).then(response => {
974976
console.log(response);
@@ -987,7 +989,7 @@ imagekit.getFileMetadata("https://ik.imagekit.io/your_imagekit_id/sample.jpg", f
987989
});
988990

989991

990-
// Using Promises
992+
// Using Promises
991993
imagekit.getFileMetadata("https://ik.imagekit.io/your_imagekit_id/sample.jpg")
992994
}).then(response => {
993995
console.log(response);
@@ -1012,15 +1014,15 @@ imagekit.createCustomMetadataField(
10121014
minValue: 1000,
10131015
maxValue: 3000
10141016
}
1015-
},
1017+
},
10161018
function(error, result) {
10171019
if(error) console.log(error);
10181020
else console.log(result);
10191021
}
10201022
);
10211023

10221024

1023-
// Using Promises
1025+
// Using Promises
10241026

10251027
imagekit.createCustomMetadataField(
10261028
{
@@ -1049,15 +1051,15 @@ Get the list of all custom metadata fields as per the [API documentation here](h
10491051
imagekit.getCustomMetadataFields(
10501052
{
10511053
includeDeleted: false // optional
1052-
},
1054+
},
10531055
function(error, result) {
10541056
if(error) console.log(error);
10551057
else console.log(result);
10561058
}
10571059
);
10581060

10591061

1060-
// Using Promises
1062+
// Using Promises
10611063

10621064
imagekit.getCustomMetadataFields(
10631065
{
@@ -1084,15 +1086,15 @@ imagekit.updateCustomMetadataField(
10841086
minValue: 500,
10851087
maxValue: 2500
10861088
}
1087-
},
1089+
},
10881090
function(error, result) {
10891091
if(error) console.log(error);
10901092
else console.log(result);
10911093
}
10921094
);
10931095

10941096

1095-
// Using Promises
1097+
// Using Promises
10961098

10971099
imagekit.updateCustomMetadataField(
10981100
"field_id",
@@ -1101,7 +1103,7 @@ imagekit.updateCustomMetadataField(
11011103
minValue: 500,
11021104
maxValue: 2500
11031105
}
1104-
},
1106+
},
11051107
).then(response => {
11061108
console.log(response);
11071109
}).catch(error => {
@@ -1125,7 +1127,7 @@ imagekit.deleteCustomMetadataField(
11251127
);
11261128

11271129

1128-
// Using Promises
1130+
// Using Promises
11291131

11301132
imagekit.deleteCustomMetadataField(
11311133
"field_id"

libs/interfaces/FileDetails.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export interface FileDetailsOptions {
7272
* 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.
7373
*/
7474
customMetadata?: CMValues;
75+
/**
76+
* Configure the publication status of a file and its versions.
77+
*/
78+
publish?: {
79+
isPublished: boolean;
80+
includeFileVersions?: boolean;
81+
};
7582
}
7683

7784
/**

libs/interfaces/UploadOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ export interface UploadOptions {
112112
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
113113
*/
114114
checks?: string
115+
/**
116+
* Optional. Determines whether the file should be uploaded as published.
117+
* If set to false, the file will be marked as unpublished, restricting access to the file through the media library only.
118+
* Files in draft or unpublished states can only be publicly accessed after they are published.
119+
*/
120+
isPublished?: boolean
115121
}

libs/interfaces/UploadResponse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ export interface UploadResponse {
7676
* 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.
7777
*/
7878
customMetadata?: CMValues;
79+
/**
80+
* Is the file published or in draft state. It can be either true or false.
81+
*/
82+
isPublished?: boolean
7983
}

libs/manage/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import request from "../../utils/request";
1313
Interfaces
1414
*/
1515
import { IKCallback } from "../interfaces/IKCallback";
16-
import { ImageKitOptions, PurgeCacheResponse, PurgeCacheStatusResponse } from "../interfaces/";
16+
import { ImageKitOptions, PurgeCacheResponse, PurgeCacheStatusResponse } from "../interfaces";
1717

1818
const purgeCache = function (url: string, defaultOptions: ImageKitOptions, callback?: IKCallback<PurgeCacheResponse>) {
1919
if (!url && !url.length) {

libs/manage/custom-metadata-field.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
CustomMetadataField,
2020
UpdateCustomMetadataFieldOptions,
2121
GetCustomMetadataFieldsOptions,
22-
} from "../interfaces/";
22+
} from "../interfaces";
2323

2424
const create = function (createCustomMetadataFieldOptions: CreateCustomMetadataFieldOptions, defaultOptions: ImageKitOptions, callback?: IKCallback<CustomMetadataField>) {
2525
const { name, label, schema } = createCustomMetadataFieldOptions;

libs/manage/file.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from "lodash";
1+
import { isObject } from 'lodash';
22

33
/*
44
Constants
@@ -35,7 +35,7 @@ import {
3535
RestoreFileVersionOptions,
3636
RenameFileOptions,
3737
RenameFileResponse,
38-
} from "../interfaces/";
38+
} from "../interfaces";
3939
import ImageKit from "../..";
4040

4141
/*
@@ -198,18 +198,26 @@ const updateDetails = function (
198198
return;
199199
}
200200

201-
if (!_.isObject(updateData)) {
201+
if (!isObject(updateData)) {
202202
respond(true, errorMessages.UPDATE_DATA_MISSING, callback);
203203
return;
204204
}
205-
var data = {
205+
206+
var data = {};
207+
data = {
206208
tags: updateData.tags,
207209
customCoordinates: updateData.customCoordinates,
208210
extensions: updateData.extensions,
209211
webhookUrl: updateData.webhookUrl,
210-
customMetadata: updateData.customMetadata
212+
customMetadata: updateData.customMetadata,
211213
};
212214

215+
if (updateData.publish)
216+
data = {
217+
...data,
218+
publish: updateData.publish,
219+
};
220+
213221
var requestOptions = {
214222
url: "https://api.imagekit.io/v1/files/" + fileId + "/details",
215223
method: "PATCH",
@@ -227,12 +235,12 @@ const listFiles = function (
227235
defaultOptions: ImageKitOptions,
228236
callback?: IKCallback<FileObject[]>,
229237
) {
230-
if (listOptions && !_.isObject(listOptions)) {
238+
if (listOptions && !isObject(listOptions)) {
231239
respond(true, errorMessages.INVALID_LIST_OPTIONS, callback);
232240
return;
233241
}
234242

235-
if (listOptions && listOptions.tags && _.isArray(listOptions.tags) && listOptions.tags.length) {
243+
if (listOptions && listOptions.tags && Array.isArray(listOptions.tags) && listOptions.tags.length) {
236244
listOptions.tags = listOptions.tags.join(",");
237245
}
238246

@@ -627,7 +635,7 @@ const createFolder = function (
627635
request(requestOptions, defaultOptions, callback);
628636
};
629637

630-
/*
638+
/*
631639
Delete folder
632640
*/
633641
const deleteFolder = function (folderPath: string, defaultOptions: ImageKitOptions, callback?: IKCallback<void>) {

libs/upload/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from "lodash";
2-
import errorMessages from "../../libs/constants/errorMessages";
2+
import errorMessages from "../constants/errorMessages";
33
import respond from "../../utils/respond";
44
import request from "../../utils/request";
55
import { IKCallback } from "../interfaces/IKCallback";

0 commit comments

Comments
 (0)