houndjs
Version:
The MediaHound JavaScript SDK
1 lines • 10.6 kB
JavaScript
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("base-64"),require("form-data")):"function"==typeof define&&define.amd?define(["base-64","form-data"],n):"object"==typeof exports?exports.houndjs=n(require("base-64"),require("form-data")):e.houndjs=n(e["base-64"],e["form-data"])}(this,function(e,n){return function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=14)}([function(e,n,t){"use strict";function r(e,n){var t={};for(var r in e)n.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}var o=t(1),i=t(2),a=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},u=function e(n){var t=n.json,o=n.responseType,i=n.generateRequest,u=t.content,s=t.pagingInfo,c=r(t,["content","pagingInfo"]),p=!(!s||!s.next),d=void 0;d="pagedResponse"===o?u:u?u.map(function(n){return e({json:n,responseType:"pagedResponse",generateRequest:i})}):[];var f=a({content:d,hasMorePages:p},c);return p&&(f.next=function(){return i({method:"GET",url:s.next,responseType:o})}),f},s=function(e,n,t){if("none"===n)return null;if("json"===n)return e;if("pagedResponse"===n||"silo"===n)return u({json:e,responseType:n,generateRequest:t});throw new Error("houndjs Invalid response type set")},c=function e(n){var u=n.method,c=n.endpoint,p=n.url,d=n.params,f=n.paramsProper,l=void 0!==f&&f,v=n.responseType,m=n.debug,g=void 0!==m&&m,h=n.useHimitsu,y=void 0===h||h,b=n.accessToken,T=void 0===b?o.details.getAccessToken():b,j=o.getLocale();return t.i(i.a)({url:p?p:o.details.getRootEndpoint()+"/"+c,method:u,params:d,paramsProper:l,authorization:T?"Bearer "+T:void 0,locale:j,debug:g,useHimitsu:y}).then(function(n){if(g){var t=n.json,o=r(n,["json"]);return a({},o,{response:s(t,v,e)})}return s(n,v,e)})};n.a=c},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(2);t.d(n,"details",function(){return P}),t.d(n,"configure",function(){return _}),t.d(n,"setLocale",function(){return O}),t.d(n,"getLocale",function(){return k}),t.d(n,"getLoginDialogURL",function(){return S}),t.d(n,"loginWithAccessToken",function(){return x}),t.d(n,"loginWithCredentials",function(){return R});var o=void 0;"undefined"!=typeof window?o=window.btoa:"function"==typeof btoa?o=btoa:"undefined"==typeof window&&(o=t(12).encode);var i=null,a=null,u=null,s=null,c=null,p="https://api.mediahound.com/",d=null,f=function(){return a?a:i},l=function(e){i=e},v=function(){return u},m=function(){return s},g=function(){return c},h=function(){return p},y=function(e){p=e},b=function(){return"1.3"},T=function(){return o(s+":"+c)},j=function(){return""+h()+b()},P={getAccessToken:f,getUsername:v,getClientId:m,getClientSecret:g,getOrigin:h,getApiVersion:b,getAuthHeaders:T,getRootEndpoint:j,setOrigin:y,setAccessToken:l},w=function(){return t.i(r.a)({method:"POST",url:j()+"/security/oauth/token",params:{client_id:m(),client_secret:g(),grant_type:"client_credentials",scope:"public_profile"},authorization:"Basic "+T(),useForms:!0}).then(function(e){var n=e.access_token;return i=n,{accessToken:n}})},_=function(e){var n=e.clientId,t=e.clientSecret,r=e.origin;return s=n,c=t,r&&(p=r),w()},O=function(e){d=e},k=function(){return d},S=function(e){var n=e.redirectUrl,t=e.scope;return j()+"/security/oauth/authorize?client_id="+m()+"&client_secret="+g()+"&scope="+t+"&response_type=token&redirect_uri="+n},x=function(e){var n=e.accessToken;return t.i(r.a)({method:"POST",url:j()+"/security/oauth/check_token",params:{token:n},authorization:"Basic "+T(),useForms:!0}).then(function(e){var t=e.user_name;return a=n,u=t,t})},R=function(e){var n=e.username,o=e.password,i=e.scope;return t.i(r.a)({method:"POST",url:j()+"/security/oauth/token",params:{username:n,password:o,scope:i,grant_type:"password",client_id:m(),client_secret:g()},authorization:"Basic "+T(),useForms:!0}).then(function(e){var n=e.access_token;if(n)return x({accessToken:n});var t=new Error("houndjs Invalid Credentials");throw t.json=e,t})}},function(e,n,t){"use strict";var r=void 0;"undefined"!=typeof window?r=window.FormData:"function"==typeof FormData?r=FormData:"undefined"==typeof window&&(r=t(13));var o=function(e){return Object.keys(e).reduce(function(n,t){var r=e[t];return void 0!==r&&(n[t]=r),n},{})},i=function(e){return Object.keys(e).reduce(function(n,t){return n.append(t,e[t]),n},new r)},a=function(e){var n=o(e);return Object.keys(n).reduce(function(e,t){var r=n[t];if(void 0!==r)if("types"===t){var o=!0,i=!1,a=void 0;try{for(var u,s=r[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var c=u.value,p=encodeURIComponent(c);e.push(t+"="+p)}}catch(e){i=!0,a=e}finally{try{!o&&s.return&&s.return()}finally{if(i)throw a}}}else{var d=encodeURIComponent(r instanceof Object?JSON.stringify(r):r);e.push(t+"="+d)}return e},[]).join("&")},u=function(e){return JSON.stringify(o(e))},s=function(e){var n=e.method,t=e.url,r=e.params,o=e.authorization,s=e.paramsProper,c=void 0!==s&&s,p=e.useForms,d=void 0!==p&&p,f=e.locale,l=void 0===f?null:f,v=e.debug,m=void 0!==v&&v,g=e.useHimitsu,h=void 0===g||g,y={Accept:"application/json"};o&&(y.Authorization=o),l&&(y["Accept-Language"]=l);var b=void 0;r&&("GET"===n?t=c?t+"?useHimitsu="+h+"¶ms="+encodeURIComponent(JSON.stringify(r)):t+"?useHimitsu="+h+"&"+a(r):d?b=i(r):(b=u(r),y["Content-Type"]="application/json"));var T=0;return m&&performance&&(T=performance.now()),fetch(t,{method:n,headers:y,body:b}).then(function(e){if(!e.ok){var n=new Error("houndjs Request Failed: "+e.status+" "+e.statusText);throw n.response=e,n}if(m&&performance){var t=performance.now(),r=t-T;return e.json().then(function(e){return{json:e,responseTime:r}}).catch(function(e){return{json:null,responseTime:r}})}return e.json().catch(function(e){return{json:null}})})};n.a=s},function(e,n,t){"use strict";var r=t(0);n.a=function(e){var n=e.ids,o=e.action,i=e.debug,a=void 0!==i&&i;return t.i(r.a)({method:"PUT",endpoint:"graph/action/"+o,params:{ids:n},responseType:"json",debug:a})}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(0);t.d(n,"create",function(){return o}),t.d(n,"update",function(){return i});var o=function(e){var n=e.name,o=e.description,i=e.content,a=e.debug,u=void 0!==a&&a;return t.i(r.a)({method:"POST",endpoint:"graph/collection/new",params:{name:n,description:o,content:i},responseType:"json",debug:u})},i=function(e){var n=e.id,o=e.operations,i=e.allowDuplicates,a=void 0!==i&&i,u=e.debug,s=void 0!==u&&u;return t.i(r.a)({method:"POST",endpoint:"graph/collection/"+n+"/update",params:{operations:o,allowDuplicates:a},responseType:"none",debug:s})}},function(e,n,t){"use strict";var r=t(0);n.a=function(e){var n=e.filters,o=e.sort,i=e.components,a=e.pageSize,u=e.debug,s=void 0!==u&&u,c=e.method,p=void 0===c?"GET":c,d=e.useHimitsu,f=void 0===d||d;return t.i(r.a)({method:p,endpoint:"graph/explore",params:{filters:n,sort:o,components:i,pageSize:a},paramsProper:!0,responseType:"pagedResponse",debug:s,useHimitsu:f})}},function(e,n,t){"use strict";var r=t(0);n.a=function(e){var n=e.ids,o=e.components,i=e.pageSize,a=e.debug,u=void 0!==a&&a;return t.i(r.a)({method:"GET",endpoint:"graph/lookup",params:{ids:n,components:o,pageSize:i},paramsProper:!0,responseType:"pagedResponse",debug:u})}},function(e,n,t){"use strict";var r=t(0);n.a=function(e){var n=e.factors,o=e.filters,i=e.components,a=e.distribution,u=e.promote,s=e.config,c=e.pageSize,p=e.method,d=void 0===p?"GET":p,f=e.debug,l=void 0!==f&&f,v=e.useHimitsu,m=void 0===v||v;return t.i(r.a)({method:d,endpoint:"graph/relate",params:{factors:n,filters:o,components:i,distribution:a,promote:u,config:s,pageSize:c},paramsProper:!0,responseType:"pagedResponse",debug:l,useHimitsu:m})}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(0),o=t(11);t.d(n,"all",function(){return i}),t.d(n,"segmented",function(){return a});var i=function(e){var n=e.searchTerm,i=e.scopes,a=e.pageSize,u=e.debug,s=void 0!==u&&u;return t.i(r.a)({method:"GET",endpoint:"search/all/"+t.i(o.a)(n),params:{version:"1.3",pageSize:a,types:Array.isArray(i)?i:void 0},responseType:"pagedResponse",debug:s})},a=function(e){var n=e.searchTerm,i=e.scopes,a=e.siloPageSize,u=e.includeAll,s=void 0===u||u,c=e.debug,p=void 0!==c&&c;return t.i(r.a)({method:"GET",endpoint:"search/segmented/"+t.i(o.a)(n),params:{version:"1.3",siloPageSize:a,includeAll:s,types:Array.isArray(i)?i:void 0},responseType:"silo",debug:p})}},function(e,n,t){"use strict";var r=t(0);n.a=function(e){var n=e.patterns,o=e.sharedPatterns,i=e.global,a=e.silosPerPage,u=e.itemsPerSilo,s=e.debug,c=void 0!==s&&s,p=e.method,d=void 0===p?"GET":p,f=e.useHimitsu,l=void 0===f||f;return t.i(r.a)({method:d,endpoint:"graph/silo",params:{patterns:n,sharedPatterns:o,global:i,silosPerPage:a,itemsPerSilo:u},responseType:"silo",debug:c,paramsProper:!0,useHimitsu:l})}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(0);t.d(n,"compose",function(){return o});var o=function(e){var n=e.ids,o=e.types,i=e.components,a=e.debug,u=void 0!==a&&a;return t.i(r.a)({method:"GET",endpoint:"graph/trait/compose",params:{ids:n,types:o,components:i},responseType:"silo",debug:u})}},function(e,n,t){"use strict";n.a=function(e){return encodeURIComponent(e).replace(/\-/g,"%2D").replace(/\_/g,"%5F").replace(/\./g,"%2E").replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}},function(n,t){n.exports=e},function(e,t){e.exports=n},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(1);t.d(n,"sdk",function(){return r});var o=t(7);t.d(n,"relate",function(){return o.a});var i=t(5);t.d(n,"explore",function(){return i.a});var a=t(6);t.d(n,"lookup",function(){return a.a});var u=t(9);t.d(n,"silo",function(){return u.a});var s=t(8);t.d(n,"search",function(){return s});var c=t(3);t.d(n,"takeAction",function(){return c.a});var p=t(4);t.d(n,"collection",function(){return p});var d=t(10);t.d(n,"trait",function(){return d});var f=t(0);t.d(n,"houndRequest",function(){return f.a})}])});