Skip to content

Commit ad0b83c

Browse files
feat: exposing config endpoint from admin api (#679)
* feat: exposing config endpoint from admin api
1 parent 69923e3 commit ad0b83c

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

lib/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,8 @@ exports.update_metadata_rule = function update_metadata_rule(field_external_id,
692692
exports.delete_metadata_rule = function delete_metadata_rule(field_external_id, callback, options = {}) {
693693
return call_api('delete', ['metadata_rules', field_external_id], {}, callback, options);
694694
};
695+
696+
exports.config = function config(callback, options = {}) {
697+
const params = pickOnlyExistingValues(options, 'settings');
698+
return call_api('get', ['config'], params, callback, options);
699+
}

lib/v2/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ v1_adapters(exports, api, {
7474
add_related_assets: 2,
7575
add_related_assets_by_asset_id: 2,
7676
delete_related_assets: 2,
77-
delete_related_assets_by_asset_id: 2
77+
delete_related_assets_by_asset_id: 2,
78+
config: 0
7879
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const sinon = require('sinon');
2+
3+
const cloudinary = require('../../../../lib/cloudinary');
4+
const api_http = require("https");
5+
const ClientRequest = require('_http_client').ClientRequest;
6+
7+
describe('Admin API - Config', () => {
8+
const mocked = {};
9+
10+
beforeEach(function () {
11+
mocked.xhr = sinon.useFakeXMLHttpRequest();
12+
mocked.write = sinon.spy(ClientRequest.prototype, 'write');
13+
mocked.request = sinon.spy(api_http, 'request');
14+
});
15+
16+
afterEach(function () {
17+
mocked.request.restore();
18+
mocked.write.restore();
19+
mocked.xhr.restore();
20+
});
21+
22+
describe('config', () => {
23+
it('should send a request to config endpoint', () => {
24+
cloudinary.v2.api.config();
25+
26+
sinon.assert.calledWith(mocked.request, sinon.match({
27+
pathname: sinon.match('config'),
28+
method: sinon.match('GET'),
29+
query: sinon.match('')
30+
}));
31+
});
32+
33+
it('should send a request to config endpoint with optional parameters', () => {
34+
cloudinary.v2.api.config({ settings: true });
35+
36+
sinon.assert.calledWith(mocked.request, sinon.match({
37+
pathname: sinon.match('config'),
38+
method: sinon.match('GET'),
39+
query: sinon.match('settings=true')
40+
}));
41+
});
42+
});
43+
});

types/cloudinary_ts_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,12 @@ cloudinary.v2.api.delete_related_assets_by_asset_id('asset-id', 'public-id-to-un
12161216
// $ExpectType Promise<DeleteAssetRelation>
12171217
cloudinary.v2.api.delete_related_assets_by_asset_id('asset-id', ['public-id-to-unrelate-1', 'public-id-to-unrelate-2']);
12181218

1219+
// $ExpectType Promise<ConfigResponse>
1220+
cloudinary.v2.api.config();
1221+
1222+
// $ExpectType Promise<ConfigResponse>
1223+
cloudinary.v2.api.config({ settings: true });
1224+
12191225
// $ExpectType Promise<any>
12201226
cloudinary.v2.uploader.create_slideshow({
12211227
manifest_json: {

types/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,14 @@ declare module 'cloudinary' {
871871
}
872872
}
873873

874+
export interface ConfigResponse {
875+
cloud_name: string
876+
created_at: string
877+
settings?: {
878+
folder_mode: 'fixed' | 'dynamic'
879+
}
880+
}
881+
874882
export namespace v2 {
875883

876884
/****************************** Global Utils *************************************/
@@ -944,6 +952,8 @@ declare module 'cloudinary' {
944952
/****************************** Admin API V2 Methods *************************************/
945953

946954
namespace api {
955+
function config(options?: AdminApiOptions | { settings: boolean }, callback?: ResponseCallback): Promise<ConfigResponse>
956+
947957
function create_streaming_profile(name: string, options: AdminApiOptions | {
948958
display_name?: string,
949959
representations: TransformationOptions

0 commit comments

Comments
 (0)