@@ -466,6 +466,7 @@ function build_eager(transformations) {
466466 return format == null ? transformationString : `${ transformationString } /${ format } ` ;
467467 } ) . join ( '|' ) ;
468468}
469+
469470/**
470471 * Build the custom headers for the request
471472 * @private
@@ -791,6 +792,24 @@ function patchFetchFormat() {
791792 }
792793}
793794
795+ function build_distribution_domain ( options ) {
796+ var source = consumeOption ( options , 'source' , '' ) ;
797+ var cloud_name = consumeOption ( options , 'cloud_name' , config ( ) . cloud_name ) ;
798+
799+ if ( ! cloud_name ) {
800+ throw new Error ( 'Must supply cloud_name in tag or in configuration' ) ;
801+ }
802+
803+ var secure = consumeOption ( options , 'secure' , config ( ) . secure ) ;
804+ var private_cdn = consumeOption ( options , 'private_cdn' , config ( ) . private_cdn ) ;
805+ var cname = consumeOption ( options , 'cname' , config ( ) . cname ) ;
806+ var secure_distribution = consumeOption ( options , 'secure_distribution' , config ( ) . secure_distribution ) ;
807+ var cdn_subdomain = consumeOption ( options , 'cdn_subdomain' , config ( ) . cdn_subdomain ) ;
808+ var secure_cdn_subdomain = consumeOption ( options , 'secure_cdn_subdomain' , config ( ) . secure_cdn_subdomain ) ;
809+
810+ return unsigned_url_prefix ( source , cloud_name , private_cdn , cdn_subdomain , secure_cdn_subdomain , cname , secure , secure_distribution ) ;
811+ }
812+
794813function url ( public_id ) {
795814 var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
796815
@@ -886,7 +905,7 @@ function url(public_id) {
886905 }
887906 // eslint-disable-next-line no-empty
888907 } catch ( error ) { }
889- var hash = computeHash ( to_sign + api_secret , signature_algorithm , 'base64' ) ;
908+ var hash = compute_hash ( to_sign + api_secret , signature_algorithm , 'base64' ) ;
890909 signature = hash . replace ( / \/ / g, '_' ) . replace ( / \+ / g, '-' ) . substring ( 0 , long_url_signature ? 32 : 8 ) ;
891910 signature = `s--${ signature } --` ;
892911 }
@@ -1002,6 +1021,7 @@ function finalize_resource_type(resource_type, type, url_suffix, use_root_path,
10021021 }
10031022 return [ resource_type , type ] ;
10041023}
1024+
10051025// cdn_subdomain and secure_cdn_subdomain
10061026// 1) Customers in shared distribution (e.g. res.cloudinary.com)
10071027// if cdn_domain is true uses res-[1-5].cloudinary.com for both http and https.
@@ -1092,7 +1112,7 @@ function api_sign_request(params_to_sign, api_secret) {
10921112
10931113 return `${ k } =${ toArray ( v ) . join ( "," ) } ` ;
10941114 } ) . sort ( ) . join ( "&" ) ;
1095- return computeHash ( to_sign + api_secret , config ( ) . signature_algorithm || DEFAULT_SIGNATURE_ALGORITHM , 'hex' ) ;
1115+ return compute_hash ( to_sign + api_secret , config ( ) . signature_algorithm || DEFAULT_SIGNATURE_ALGORITHM , 'hex' ) ;
10961116}
10971117
10981118/**
@@ -1103,7 +1123,7 @@ function api_sign_request(params_to_sign, api_secret) {
11031123 * @param {string } encoding type of encoding
11041124 * @return {string } computed hash value
11051125 */
1106- function computeHash ( input , signature_algorithm , encoding ) {
1126+ function compute_hash ( input , signature_algorithm , encoding ) {
11071127 if ( ! SUPPORTED_SIGNATURE_ALGORITHMS . includes ( signature_algorithm ) ) {
11081128 throw new Error ( `Signature algorithm ${ signature_algorithm } is not supported. Supported algorithms: ${ SUPPORTED_SIGNATURE_ALGORITHMS . join ( ', ' ) } ` ) ;
11091129 }
@@ -1132,6 +1152,13 @@ function clear_blank(hash) {
11321152 return filtered_hash ;
11331153}
11341154
1155+ function sort_object_by_key ( object ) {
1156+ return Object . keys ( object ) . sort ( ) . reduce ( function ( obj , key ) {
1157+ obj [ key ] = object [ key ] ;
1158+ return obj ;
1159+ } , { } ) ;
1160+ }
1161+
11351162function merge ( hash1 , hash2 ) {
11361163 return _extends ( { } , hash1 , hash2 ) ;
11371164}
@@ -1150,11 +1177,14 @@ function sign_request(params) {
11501177function webhook_signature ( data , timestamp ) {
11511178 var options = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
11521179
1153- ensurePresenceOf ( { data, timestamp } ) ;
1180+ ensurePresenceOf ( {
1181+ data,
1182+ timestamp
1183+ } ) ;
11541184
11551185 var api_secret = ensureOption ( options , 'api_secret' ) ;
11561186 var signature_algorithm = ensureOption ( options , 'signature_algorithm' , DEFAULT_SIGNATURE_ALGORITHM ) ;
1157- return computeHash ( data + timestamp + api_secret , signature_algorithm , 'hex' ) ;
1187+ return compute_hash ( data + timestamp + api_secret , signature_algorithm , 'hex' ) ;
11581188}
11591189
11601190/**
@@ -1253,7 +1283,9 @@ function download_backedup_asset(asset_id, version_id) {
12531283 * @param options
12541284 */
12551285function api_download_url ( action , params , options ) {
1256- var download_params = _extends ( { } , params , { mode : "download" } ) ;
1286+ var download_params = _extends ( { } , params , {
1287+ mode : "download"
1288+ } ) ;
12571289 var cloudinary_params = exports . sign_request ( download_params , options ) ;
12581290 return exports . api_url ( action , options ) + "?" + hashToQuery ( cloudinary_params ) ;
12591291}
@@ -1487,6 +1519,7 @@ function process_video_params(param) {
14871519 return null ;
14881520 }
14891521}
1522+
14901523/**
14911524 * Returns a Hash of parameters used to create an archive
14921525 * @private
@@ -1530,7 +1563,10 @@ exports.create_source_tag = function create_source_tag(src, source_type) {
15301563 var codecs_str = isArray ( codecs ) ? codecs . join ( ', ' ) : codecs ;
15311564 mime_type += `; codecs=${ codecs_str } ` ;
15321565 }
1533- return `<source ${ utils . html_attrs ( { src, type : mime_type } ) } >` ;
1566+ return `<source ${ utils . html_attrs ( {
1567+ src,
1568+ type : mime_type
1569+ } ) } >`;
15341570} ;
15351571
15361572function build_explicit_api_params ( public_id ) {
@@ -1726,6 +1762,9 @@ exports.jsonArrayParam = jsonArrayParam;
17261762exports . download_folder = download_folder ;
17271763exports . base_api_url = base_api_url ;
17281764exports . download_backedup_asset = download_backedup_asset ;
1765+ exports . compute_hash = compute_hash ;
1766+ exports . build_distribution_domain = build_distribution_domain ;
1767+ exports . sort_object_by_key = sort_object_by_key ;
17291768
17301769// was exported before, so kept for backwards compatibility
17311770exports . DEFAULT_POSTER_OPTIONS = DEFAULT_POSTER_OPTIONS ;
0 commit comments