Skip to content

Commit

Permalink
feat: exposing config endpoint from admin api (#679)
Browse files Browse the repository at this point in the history
* feat: exposing config endpoint from admin api
  • Loading branch information
cloudinary-pkoniu authored Jul 30, 2024
1 parent 69923e3 commit ad0b83c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,8 @@ exports.update_metadata_rule = function update_metadata_rule(field_external_id,
exports.delete_metadata_rule = function delete_metadata_rule(field_external_id, callback, options = {}) {
return call_api('delete', ['metadata_rules', field_external_id], {}, callback, options);
};

exports.config = function config(callback, options = {}) {
const params = pickOnlyExistingValues(options, 'settings');
return call_api('get', ['config'], params, callback, options);
}
3 changes: 2 additions & 1 deletion lib/v2/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ v1_adapters(exports, api, {
add_related_assets: 2,
add_related_assets_by_asset_id: 2,
delete_related_assets: 2,
delete_related_assets_by_asset_id: 2
delete_related_assets_by_asset_id: 2,
config: 0
});
43 changes: 43 additions & 0 deletions test/integration/api/admin/config_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const sinon = require('sinon');

const cloudinary = require('../../../../lib/cloudinary');
const api_http = require("https");
const ClientRequest = require('_http_client').ClientRequest;

describe('Admin API - Config', () => {
const mocked = {};

beforeEach(function () {
mocked.xhr = sinon.useFakeXMLHttpRequest();
mocked.write = sinon.spy(ClientRequest.prototype, 'write');
mocked.request = sinon.spy(api_http, 'request');
});

afterEach(function () {
mocked.request.restore();
mocked.write.restore();
mocked.xhr.restore();
});

describe('config', () => {
it('should send a request to config endpoint', () => {
cloudinary.v2.api.config();

sinon.assert.calledWith(mocked.request, sinon.match({
pathname: sinon.match('config'),
method: sinon.match('GET'),
query: sinon.match('')
}));
});

it('should send a request to config endpoint with optional parameters', () => {
cloudinary.v2.api.config({ settings: true });

sinon.assert.calledWith(mocked.request, sinon.match({
pathname: sinon.match('config'),
method: sinon.match('GET'),
query: sinon.match('settings=true')
}));
});
});
});
6 changes: 6 additions & 0 deletions types/cloudinary_ts_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,12 @@ cloudinary.v2.api.delete_related_assets_by_asset_id('asset-id', 'public-id-to-un
// $ExpectType Promise<DeleteAssetRelation>
cloudinary.v2.api.delete_related_assets_by_asset_id('asset-id', ['public-id-to-unrelate-1', 'public-id-to-unrelate-2']);

// $ExpectType Promise<ConfigResponse>
cloudinary.v2.api.config();

// $ExpectType Promise<ConfigResponse>
cloudinary.v2.api.config({ settings: true });

// $ExpectType Promise<any>
cloudinary.v2.uploader.create_slideshow({
manifest_json: {
Expand Down
10 changes: 10 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,14 @@ declare module 'cloudinary' {
}
}

export interface ConfigResponse {
cloud_name: string
created_at: string
settings?: {
folder_mode: 'fixed' | 'dynamic'
}
}

export namespace v2 {

/****************************** Global Utils *************************************/
Expand Down Expand Up @@ -944,6 +952,8 @@ declare module 'cloudinary' {
/****************************** Admin API V2 Methods *************************************/

namespace api {
function config(options?: AdminApiOptions | { settings: boolean }, callback?: ResponseCallback): Promise<ConfigResponse>

function create_streaming_profile(name: string, options: AdminApiOptions | {
display_name?: string,
representations: TransformationOptions
Expand Down

0 comments on commit ad0b83c

Please sign in to comment.