Skip to content

Commit fa93182

Browse files
authored
Merge branch 'master' into patch-3
2 parents ad34788 + cb68d9e commit fa93182

29 files changed

+561
-105
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
1.35.0 / 2023-03-03
2+
==================
3+
4+
* fix: removing nested nulls from options passed to api, closes #581
5+
* feat: add option to configure tracked analytics
6+
7+
1.34.0 / 2023-02-13
8+
==================
9+
10+
* fix: resource_type is not optional
11+
* feat: search for folders
12+
* feat: support for extra_headers in upload request
13+
14+
1.33.0 / 2022-12-15
15+
==================
16+
17+
* feat: start and end offset normalized in a transformation string
18+
* feat: new config option for hiding sensitive data when logging errors
19+
* feat: multiple ACLs for generate_auth_token
20+
* fix: improved TS typing
21+
122
1.32.0 / 2022-09-14
223
==================
324

lib-es5/api.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function deleteResourcesParams(options) {
1616
}
1717

1818
function getResourceParams(options) {
19-
return pickOnlyExistingValues(options, "exif", "cinemagraph_analysis", "colors", "derived_next_cursor", "faces", "image_metadata", "pages", "phash", "coordinates", "max_results", "versions", "accessibility_analysis");
19+
return pickOnlyExistingValues(options, "exif", "cinemagraph_analysis", "colors", "derived_next_cursor", "faces", "image_metadata", "media_metadata", "pages", "phash", "coordinates", "max_results", "versions", "accessibility_analysis");
2020
}
2121

2222
exports.ping = function ping(callback) {
@@ -183,6 +183,9 @@ exports.update = function update(public_id, callback) {
183183
if (options.moderation_status != null) {
184184
params.moderation_status = options.moderation_status;
185185
}
186+
if (options.clear_invalid !== null) {
187+
params.clear_invalid = options.clear_invalid;
188+
}
186189
return call_api("post", uri, params, callback, options);
187190
};
188191

@@ -541,6 +544,13 @@ exports.search = function search(params, callback) {
541544
return call_api("post", "resources/search", params, callback, options);
542545
};
543546

547+
exports.search_folders = function search_folders(params, callback) {
548+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
549+
550+
options.content_type = 'json';
551+
return call_api("post", "folders/search", params, callback, options);
552+
};
553+
544554
exports.update_resources_access_mode_by_prefix = function update_resources_access_mode_by_prefix(access_mode, prefix, callback) {
545555
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
546556

lib-es5/api_client/execute_request.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4+
35
// eslint-disable-next-line import/order
46
var config = require("../config");
57
var https = /^http:/.test(config().upload_prefix) ? require('http') : require('https');
@@ -74,6 +76,21 @@ function execute_request(method, params, auth, api_url, callback) {
7476
request_options.headers['Content-Length'] = Buffer.byteLength(query_params);
7577
}
7678
handle_response = function handle_response(res) {
79+
var _config = config(),
80+
_config$hide_sensitiv = _config.hide_sensitive,
81+
hide_sensitive = _config$hide_sensitiv === undefined ? false : _config$hide_sensitiv;
82+
83+
var sanitizedOptions = _extends({}, request_options);
84+
85+
if (hide_sensitive === true) {
86+
if ("auth" in sanitizedOptions) {
87+
delete sanitizedOptions.auth;
88+
}
89+
if ("Authorization" in sanitizedOptions.headers) {
90+
delete sanitizedOptions.headers.Authorization;
91+
}
92+
}
93+
7794
if (includes([200, 400, 401, 403, 404, 409, 420, 500], res.statusCode)) {
7895
var buffer = "";
7996
var error = false;
@@ -106,7 +123,7 @@ function execute_request(method, params, auth, api_url, callback) {
106123

107124
if (result.error) {
108125
deferred.reject(Object.assign({
109-
request_options,
126+
request_options: sanitizedOptions,
110127
query_params
111128
}, result));
112129
} else {
@@ -122,7 +139,7 @@ function execute_request(method, params, auth, api_url, callback) {
122139
error: {
123140
message: e,
124141
http_code: res.statusCode,
125-
request_options,
142+
request_options: sanitizedOptions,
126143
query_params
127144
}
128145
};
@@ -136,7 +153,7 @@ function execute_request(method, params, auth, api_url, callback) {
136153
error: {
137154
message: "Server returned unexpected status code - " + res.statusCode,
138155
http_code: res.statusCode,
139-
request_options,
156+
request_options: sanitizedOptions,
140157
query_params
141158
}
142159
};

lib-es5/auth_token.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function escapeToLower(url) {
3535
* @property {number} start_time=now The start time of the token in seconds from epoch.
3636
* @property {string} expiration The expiration time of the token in seconds from epoch.
3737
* @property {string} duration The duration of the token (from start_time).
38-
* @property {string} acl The ACL for the token.
38+
* @property {string|Array<string>} acl The ACL(s) for the token.
3939
* @property {string} url The URL to authentication in case of a URL token.
4040
*
4141
*/
@@ -65,6 +65,9 @@ module.exports = function (options) {
6565
}
6666
tokenParts.push(`exp=${options.expiration}`);
6767
if (options.acl != null) {
68+
if (Array.isArray(options.acl) === true) {
69+
options.acl = options.acl.join("!");
70+
}
6871
tokenParts.push(`acl=${escapeToLower(options.acl)}`);
6972
}
7073
var toSign = [].concat(tokenParts);

lib-es5/uploader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ exports.rename = function rename(from_public_id, to_public_id, callback) {
269269
to_public_id: to_public_id,
270270
overwrite: options.overwrite,
271271
invalidate: options.invalidate,
272-
to_type: options.to_type
272+
to_type: options.to_type,
273+
context: options.context,
274+
metadata: options.metadata
273275
}];
274276
});
275277
};
@@ -662,6 +664,9 @@ function post(url, post_data, boundary, file, callback, options) {
662664
if (options.x_unique_upload_id != null) {
663665
headers['X-Unique-Upload-Id'] = options.x_unique_upload_id;
664666
}
667+
if (options.extra_headers !== null) {
668+
headers = merge(headers, options.extra_headers);
669+
}
665670
if (oauth_token != null) {
666671
headers.Authorization = `Bearer ${oauth_token}`;
667672
}
@@ -811,7 +816,8 @@ exports.update_metadata = function update_metadata(metadata, public_ids, callbac
811816
metadata: utils.encode_context(metadata),
812817
public_ids: utils.build_array(public_ids),
813818
timestamp: utils.timestamp(),
814-
type: options.type
819+
type: options.type,
820+
clear_invalid: options.clear_invalid
815821
};
816822
return [params];
817823
});

lib-es5/utils/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ function build_upload_params(options) {
367367
format: options.format,
368368
filename_override: options.filename_override,
369369
image_metadata: utils.as_safe_bool(options.image_metadata),
370+
media_metadata: utils.as_safe_bool(options.media_metadata),
370371
invalidate: utils.as_safe_bool(options.invalidate),
371372
moderation: options.moderation,
372373
notification_url: options.notification_url,
@@ -567,6 +568,12 @@ function generate_transformation_string(options) {
567568
options.start_offset = _split_range2[0];
568569
options.end_offset = _split_range2[1];
569570
}
571+
if (options.start_offset) {
572+
options.start_offset = normalize_expression(options.start_offset);
573+
}
574+
if (options.end_offset) {
575+
options.end_offset = normalize_expression(options.end_offset);
576+
}
570577
var overlay = process_layer(consumeOption(options, "overlay"));
571578
var radius = process_radius(consumeOption(options, "radius"));
572579
var underlay = process_layer(consumeOption(options, "underlay"));
@@ -893,7 +900,17 @@ function url(public_id) {
893900
var urlAnalytics = ensureOption(options, 'urlAnalytics', false);
894901

895902
if (urlAnalytics === true) {
896-
var sdkVersions = getSDKVersions();
903+
var _getSDKVersions = getSDKVersions(),
904+
sdkCode = _getSDKVersions.sdkCode,
905+
sdkSemver = _getSDKVersions.sdkSemver,
906+
techVersion = _getSDKVersions.techVersion;
907+
908+
var sdkVersions = {
909+
sdkCode: ensureOption(options, 'sdkCode', sdkCode),
910+
sdkSemver: ensureOption(options, 'sdkSemver', sdkSemver),
911+
techVersion: ensureOption(options, 'techVersion', techVersion)
912+
};
913+
897914
var analyticsOptions = getAnalyticsOptions(Object.assign({}, options, sdkVersions));
898915

899916
var sdkAnalyticsSignature = getSDKAnalyticsSignature(analyticsOptions);
@@ -903,7 +920,7 @@ function url(public_id) {
903920
if (resultUrl.indexOf('?') >= 0) {
904921
appender = '&';
905922
}
906-
resultUrl = `${resultUrl}${appender}_s=${sdkAnalyticsSignature}`;
923+
resultUrl = `${resultUrl}${appender}_a=${sdkAnalyticsSignature}`;
907924
}
908925

909926
return resultUrl;
@@ -1105,7 +1122,9 @@ function clear_blank(hash) {
11051122
k = _ref29[0],
11061123
v = _ref29[1];
11071124

1108-
filtered_hash[k] = v;
1125+
filtered_hash[k] = v.filter ? v.filter(function (x) {
1126+
return x;
1127+
}) : v;
11091128
});
11101129
return filtered_hash;
11111130
}

lib-es5/v2/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ v1_adapters(exports, api, {
5555
update_resources_access_mode_by_tag: 2,
5656
update_resources_access_mode_by_ids: 2,
5757
search: 1,
58+
search_folders: 1,
5859
delete_derived_by_transformation: 2,
5960
add_metadata_field: 1,
6061
list_metadata_fields: 1,

lib-es5/v2/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ var v1 = require('../cloudinary');
66
var api = require('./api');
77
var uploader = require('./uploader');
88
var search = require('./search');
9+
var search_folders = require('./search_folders');
910

1011
var v2 = _extends({}, v1, {
1112
api,
1213
uploader,
13-
search
14+
search,
15+
search_folders
1416
});
1517
module.exports = v2;

lib-es5/v2/search_folders.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4+
5+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6+
7+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8+
9+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
10+
11+
var Search = require('./search');
12+
var api = require('./api');
13+
14+
var SearchFolders = function (_Search) {
15+
_inherits(SearchFolders, _Search);
16+
17+
function SearchFolders() {
18+
_classCallCheck(this, SearchFolders);
19+
20+
return _possibleConstructorReturn(this, (SearchFolders.__proto__ || Object.getPrototypeOf(SearchFolders)).call(this));
21+
}
22+
23+
_createClass(SearchFolders, [{
24+
key: 'execute',
25+
value: function execute(options, callback) {
26+
if (callback === null) {
27+
callback = options;
28+
}
29+
options = options || {};
30+
return api.search_folders(this.to_query(), options, callback);
31+
}
32+
}], [{
33+
key: 'instance',
34+
value: function instance() {
35+
return new SearchFolders();
36+
}
37+
}]);
38+
39+
return SearchFolders;
40+
}(Search);
41+
42+
module.exports = SearchFolders;

lib/api.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function deleteResourcesParams(options, params = {}) {
1010
}
1111

1212
function getResourceParams(options) {
13-
return pickOnlyExistingValues(options, "exif", "cinemagraph_analysis", "colors", "derived_next_cursor", "faces", "image_metadata", "pages", "phash", "coordinates", "max_results", "versions", "accessibility_analysis");
13+
return pickOnlyExistingValues(options, "exif", "cinemagraph_analysis", "colors", "derived_next_cursor", "faces", "image_metadata", "media_metadata", "pages", "phash", "coordinates", "max_results", "versions", "accessibility_analysis");
1414
}
1515

1616
exports.ping = function ping(callback, options = {}) {
@@ -131,6 +131,9 @@ exports.update = function update(public_id, callback, options = {}) {
131131
if (options.moderation_status != null) {
132132
params.moderation_status = options.moderation_status;
133133
}
134+
if (options.clear_invalid !== null) {
135+
params.clear_invalid = options.clear_invalid;
136+
}
134137
return call_api("post", uri, params, callback, options);
135138
};
136139

@@ -401,6 +404,11 @@ exports.search = function search(params, callback, options = {}) {
401404
return call_api("post", "resources/search", params, callback, options);
402405
};
403406

407+
exports.search_folders = function search_folders(params, callback, options = {}) {
408+
options.content_type = 'json';
409+
return call_api("post", "folders/search", params, callback, options);
410+
};
411+
404412
exports.update_resources_access_mode_by_prefix = function update_resources_access_mode_by_prefix(
405413
access_mode,
406414
prefix,

0 commit comments

Comments
 (0)