@nomad-media/public 1.1.9 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1006,7 +1006,11 @@ class NomadMediaSDK {
1006
1006
 
1007
1007
  const HEADERS = new Headers();
1008
1008
  HEADERS.append("Content-Type", "application/json");
1009
- HEADERS.append("Authorization", `Bearer ${this.token}`);
1009
+
1010
+ if (this.token !== null)
1011
+ {
1012
+ HEADERS.append("Authorization", `Bearer ${this.token}`);
1013
+ }
1010
1014
 
1011
1015
  if (this.debugMode)
1012
1016
  {
@@ -1080,14 +1084,27 @@ async function _login(instance, USERNAME, PASSWORD, URL, DEBUG_MODE)
1080
1084
  "password": PASSWORD
1081
1085
  };
1082
1086
 
1083
- return await _sendRequest(instance, null, "Login", API_URL, "POST", null, BODY, DEBUG_MODE);
1087
+ try
1088
+ {
1089
+ return await _sendRequest(instance, null, "Login", API_URL, "POST", null, BODY, DEBUG_MODE);
1090
+ }
1091
+ catch (error)
1092
+ {
1093
+ if (error.message.includes("409"))
1094
+ {
1095
+ throw new Error("Invalid username or password");
1096
+ }
1097
+ else
1098
+ {
1099
+ throw error;
1100
+ }
1101
+ }
1084
1102
  }
1085
1103
 
1086
1104
 
1087
1105
 
1088
1106
 
1089
1107
 
1090
-
1091
1108
  async function _logout(instance, AUTH_TOKEN, URL, DEBUG_MODE)
1092
1109
  {
1093
1110
  const API_URL = `${URL}/api/account/logout`;
@@ -1109,7 +1126,7 @@ async function _refreshToken(instance, AUTH_TOKEN, URL, REFRESH_TOKEN, DEBUG_MOD
1109
1126
  };
1110
1127
 
1111
1128
  const TOKEN_INFO = await _sendRequest(instance, AUTH_TOKEN, "Refreshing Token", API_URL, "POST", null, BODY, DEBUG_MODE);
1112
- instance.token = TOKEN_INFO.token;
1129
+ return TOKEN_INFO;
1113
1130
  }
1114
1131
 
1115
1132
 
@@ -1209,7 +1226,7 @@ async function _sendRequest(instance, AUTH_TOKEN, FUNCTION_NAME, URL, METHOD_TYP
1209
1226
 
1210
1227
  if (AUTH_TOKEN) HEADERS["Authorization"] = `Bearer ${AUTH_TOKEN}`;
1211
1228
 
1212
- if (DEBUG) console.log(`URL: ${URL}\nMETHOD: ${METHOD_TYPE}` + (PARAMS ? `\nPARAMS: ${JSON.stringify(PARAMS, null, 4)}` : "") + (BODY ? `\nBODY: ${JSON.stringify(BODY, null, 4)}` : ""));
1229
+ if (DEBUG) console.log(`URL: ${URL}\nMETHOD: ${METHOD_TYPE}` + (PARAMS && PARAMS.size === 0 ? `\nPARAMS: ${JSON.stringify(PARAMS, null, 4)}` : "") + (BODY ? `\nBODY: ${JSON.stringify(BODY, null, 4)}` : ""));
1213
1230
 
1214
1231
  let retries = 0;
1215
1232
  let RESPONSE = null;
@@ -1246,12 +1263,11 @@ async function _sendRequest(instance, AUTH_TOKEN, FUNCTION_NAME, URL, METHOD_TYP
1246
1263
  if (error.code === 'ECONNABORTED' && retries < MAX_RETRIES)
1247
1264
  {
1248
1265
  retries++;
1249
- await _sleep(SLEEP_TIME * 2 ** retries);
1266
+ await _sleep(SLEEP_TIME);
1250
1267
  }
1251
1268
  else
1252
1269
  {
1253
- console.error(`${FUNCTION_NAME} failed`, error);
1254
- _apiExceptionHandler(error, FUNCTION_NAME);
1270
+ _apiExceptionHandler(error.response?.data.message ? error.response.data.message : error.message, `${FUNCTION_NAME} failed`);
1255
1271
  }
1256
1272
  }
1257
1273
  } while (!RESPONSE || RESPONSE.status < 200 || RESPONSE.status >= 300);
@@ -1,5 +1,5 @@
1
- import{promises as fs}from"fs";import path from"path";class NomadMediaSDK{constructor(t={}){return NomadMediaSDK.instance||(this.config=t,this.token=null,this.refreshTokenVal=null,this.expirationSeconds=null,this.userSessionId=null,this.id=null,this.debugMode=t.debugMode||!1,NomadMediaSDK.instance=this)}async _init(){await this.login(),this.__scheduleTokenRefresh()}async login(){_printDatetime("Logging in as "+this.config.username);try{var t=await _login(this,this.config.username,this.config.password,this.config.serviceApiUrl,this.debugMode);this.token=t.token,this.refreshTokenVal=t.refreshToken,this.expirationSeconds=Date.now()+1e3*t.expirationSeconds,this.userSessionId=t.userSessionId,this.id=t.id,_printDatetime("Login successful")}catch(t){throw _printDatetime("Login failed"),t}}async logout(){null===this.token&&this.config.username&&await this._init(),_printDatetime("Logging out");try{await _logout(this,this.token,this.config.serviceApiUrl,this.debugMode),this.token=null,this.refreshTokenVal=null,this.expirationSeconds=null,this.userSessionId=null,this.id=null,_printDatetime("Logout successful")}catch(t){throw _printDatetime("Loggout failed"),t}}async refreshToken(){_printDatetime("Refreshing token");try{var t=await _refreshToken(this,this.token,this.config.serviceApiUrl,this.refreshTokenVal,this.debugMode);this.token=t.token,_printDatetime("Token refresh successful")}catch(t){throw _printDatetime("Token refresh failed"),t}}__scheduleTokenRefresh(){var t;this.token&&this.expirationSeconds&&0<(t=this.expirationSeconds-Date.now())&&(this.refreshTimer&&clearTimeout(this.refreshTimer),this.refreshTimer=setTimeout(async()=>{await this.refreshToken(),this.__scheduleTokenRefresh()},t-5e3))}async forgotPassword(){var e=this.config.username;_printDatetime("Sending code to "+e);try{await _forgotPassword(this,this.config.serviceApiUrl,e,this.debugMode),_printDatetime("Code sent to "+e)}catch(t){throw _printDatetime("Code failed to send to "+e),t}}async resetPassword(t,e){var i=this.config.username;_printDatetime("Resetting password for "+i);try{await _resetPassword(this,this.config.serviceApiUrl,i,t,e,this.debugMode),_printDatetime("Password reset for "+i)}catch(t){throw _printDatetime("Password failed to reset for "+i),t}}async clearContinueWatching(t,e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Clearing continue watching");try{await _clearContinueWatching(this,this.token,this.config.serviceApiUrl,t,e,this.debugMode),_printDatetime("Continue watching cleared")}catch(t){throw _printDatetime("Continue watching failed to clear"),t}}async clearWatchlist(t){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Clearing watchlist");try{t=t||this.id,await _clearWatchlist(this,this.token,this.config.serviceApiUrl,t,this.debugMode),_printDatetime("Watchlist cleared")}catch(t){throw _printDatetime("Watchlist failed to clear"),t}}async createForm(t,e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Creating form");try{var i=await _createForm(this,this.token,this.config.serviceApiUrl,t,e,this.debugMode);return _printDatetime("Form created"),i}catch(t){throw _printDatetime("Form failed to create"),t}}async getContentCookies(t){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting content cookies");try{var e=await _getContentCookies(this,this.token,this.config.serviceApiUrl,t,this.debugMode);return _printDatetime("Content cookies gotten"),e}catch(t){throw _printDatetime("Content cookies failed to get"),t}}async getDefaultSiteConfig(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting default site config");try{var t=await _getDefaultSiteConfig(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("Default site config gotten"),t}catch(t){throw _printDatetime("Default site config failed to get"),t}}async getDynamicContent(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting dynamic content: "+e);try{var t=await _getDynamicContent(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Dynamic content gotten: "+e),t}catch(t){throw _printDatetime("Dynamic content failed to get: "+e),t}}async getDynamicContents(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting dynamic contents");try{var t=await _getDynamicContents(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("Dynamic contents gotten"),t}catch(t){throw _printDatetime("Dynamic contents failed to get"),t}}async getMediaGroup(e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting media group: "+e);try{var t=await _getMediaGroup(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Media group gotten: "+e),t}catch(t){throw _printDatetime("Media group failed to get: "+e),t}}async getMediaItem(e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting media item: "+e);try{var t=await _getMediaItem(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Media item gotten: "+e),t}catch(t){throw _printDatetime("Media item failed to get: "+e),t}}async getMyContent(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is not available for portal API type.");_printDatetime("Getting my content");try{var t=await _getMyContent(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("My content gotten"),t}catch(t){throw _printDatetime("My content failed to get"),t}}async getMyGroup(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting my group: "+e);try{var t=await _getMyGroup(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("My group gotten: "+e),t}catch(t){throw _printDatetime("My group failed to get: "+e),t}}async getSiteConfig(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting site config: "+e);try{var t=await _getSiteConfig(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Site config gotten: "+e),t}catch(t){throw _printDatetime("Site config failed to get: "+e),t}}async mediaSearch(t,e,i,n,r){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Searching media...");try{var a=await _mediaSearch(this,this.token,this.config.serviceApiUrl,t,e,i,n,r,this.debugMode);return _printDatetime("Media search complete"),a}catch(t){throw _printDatetime("Media search failed"),t}}async miscFunctions(e,i,n,r){null===this.token&&this.config.username&&await this._init(),_printDatetime("Calling function: "+e);try{let t=this.config.serviceApiUrl+"/"+e;r&&(t=(t=(t=t.replace("/api","")).replace("app-api.","")).replace("admin-app.",""));var a=new Headers,o=(a.append("Content-Type","application/json"),a.append("Authorization","Bearer "+this.token),this.debugMode&&(console.log(`URL: ${t}
2
- METHOD: `+i),n)&&console.log("BODY: "+JSON.stringify(n,null,4)),{method:i,headers:a}),s=(n&&(o.body=JSON.stringify(n)),await fetch(t,o)),c=await s.text();if(!s.ok)try{throw JSON.parse(c)}catch(t){throw c}try{return JSON.parse(c)}catch(t){return c}}catch(t){_apiExceptionHandler(t,"API call failed")}}}export default NomadMediaSDK;async function _forgotPassword(t,e,i,n){return _sendRequest(t,null,"Forgot Password",e+"/api/account/forgot-password","POST",null,{username:i},n)}async function _login(t,e,i,n,r){return _sendRequest(t,null,"Login",n+"/api/account/login","POST",null,{userName:e,password:i},r)}async function _logout(t,e,i,n){return _sendRequest(t,e,"Logout",i+"/api/account/logout","POST",null,null,n)}async function _refreshToken(t,e,i,n,r){e=await _sendRequest(t,e,"Refreshing Token",i+"/api/account/refresh-token","POST",null,{refreshToken:n},r);t.token=e.token}async function _resetPassword(t,e,i,n,r,a){return _sendRequest(t,null,"Reset Password",e+"/api/account/reset-password","POST",null,{userName:i,TOKEN:n,newPassword:r},a)}function _apiExceptionHandler(i,n){if(!i)throw new Error(n);if("string"==typeof i)throw new Error(n+": "+i);if(!i.errors)throw new Error(n+": "+i.message);if(Array.isArray(i.errors)){let e="";for(let t=0;t<i.errors.length;t++)e+=`${i.errors[t].code}: ${i.errors[t].field}: ${i.errors[t].message}\n`;throw new Error(n+": "+e)}if("object"==typeof i.errors){let t="";for(var e in i.errors)Object.prototype.hasOwnProperty.call(i.errors,e)&&(t+=`${e}: ${i.errors[e]}\n`);throw new Error(n+": "+t)}}import{getRandomValues}from"crypto";function _newGuid(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t=>(t^getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}function _printDatetime(t){var e=(new Date).toLocaleTimeString();console.log(e+": "+t)}import axios from"axios";let MAX_RETRIES=5,TIMEOUT=3e4,SLEEP_TIME=6e4;async function _sendRequest(t,e,i,n,r,a,o,s){var c={"Content-Type":"application/json"};e&&(c.Authorization="Bearer "+e),s&&console.log(`URL: ${n}
3
- METHOD: `+r+(a?`
1
+ import{promises as fs}from"fs";import path from"path";class NomadMediaSDK{constructor(t={}){return NomadMediaSDK.instance||(this.config=t,this.token=null,this.refreshTokenVal=null,this.expirationSeconds=null,this.userSessionId=null,this.id=null,this.debugMode=t.debugMode||!1,NomadMediaSDK.instance=this)}async _init(){await this.login(),this.__scheduleTokenRefresh()}async login(){_printDatetime("Logging in as "+this.config.username);try{var t=await _login(this,this.config.username,this.config.password,this.config.serviceApiUrl,this.debugMode);this.token=t.token,this.refreshTokenVal=t.refreshToken,this.expirationSeconds=Date.now()+1e3*t.expirationSeconds,this.userSessionId=t.userSessionId,this.id=t.id,_printDatetime("Login successful")}catch(t){throw _printDatetime("Login failed"),t}}async logout(){null===this.token&&this.config.username&&await this._init(),_printDatetime("Logging out");try{await _logout(this,this.token,this.config.serviceApiUrl,this.debugMode),this.token=null,this.refreshTokenVal=null,this.expirationSeconds=null,this.userSessionId=null,this.id=null,_printDatetime("Logout successful")}catch(t){throw _printDatetime("Loggout failed"),t}}async refreshToken(){_printDatetime("Refreshing token");try{var t=await _refreshToken(this,this.token,this.config.serviceApiUrl,this.refreshTokenVal,this.debugMode);this.token=t.token,_printDatetime("Token refresh successful")}catch(t){throw _printDatetime("Token refresh failed"),t}}__scheduleTokenRefresh(){var t;this.token&&this.expirationSeconds&&0<(t=this.expirationSeconds-Date.now())&&(this.refreshTimer&&clearTimeout(this.refreshTimer),this.refreshTimer=setTimeout(async()=>{await this.refreshToken(),this.__scheduleTokenRefresh()},t-5e3))}async forgotPassword(){var e=this.config.username;_printDatetime("Sending code to "+e);try{await _forgotPassword(this,this.config.serviceApiUrl,e,this.debugMode),_printDatetime("Code sent to "+e)}catch(t){throw _printDatetime("Code failed to send to "+e),t}}async resetPassword(t,e){var i=this.config.username;_printDatetime("Resetting password for "+i);try{await _resetPassword(this,this.config.serviceApiUrl,i,t,e,this.debugMode),_printDatetime("Password reset for "+i)}catch(t){throw _printDatetime("Password failed to reset for "+i),t}}async clearContinueWatching(t,e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Clearing continue watching");try{await _clearContinueWatching(this,this.token,this.config.serviceApiUrl,t,e,this.debugMode),_printDatetime("Continue watching cleared")}catch(t){throw _printDatetime("Continue watching failed to clear"),t}}async clearWatchlist(t){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Clearing watchlist");try{t=t||this.id,await _clearWatchlist(this,this.token,this.config.serviceApiUrl,t,this.debugMode),_printDatetime("Watchlist cleared")}catch(t){throw _printDatetime("Watchlist failed to clear"),t}}async createForm(t,e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Creating form");try{var i=await _createForm(this,this.token,this.config.serviceApiUrl,t,e,this.debugMode);return _printDatetime("Form created"),i}catch(t){throw _printDatetime("Form failed to create"),t}}async getContentCookies(t){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting content cookies");try{var e=await _getContentCookies(this,this.token,this.config.serviceApiUrl,t,this.debugMode);return _printDatetime("Content cookies gotten"),e}catch(t){throw _printDatetime("Content cookies failed to get"),t}}async getDefaultSiteConfig(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting default site config");try{var t=await _getDefaultSiteConfig(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("Default site config gotten"),t}catch(t){throw _printDatetime("Default site config failed to get"),t}}async getDynamicContent(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting dynamic content: "+e);try{var t=await _getDynamicContent(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Dynamic content gotten: "+e),t}catch(t){throw _printDatetime("Dynamic content failed to get: "+e),t}}async getDynamicContents(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting dynamic contents");try{var t=await _getDynamicContents(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("Dynamic contents gotten"),t}catch(t){throw _printDatetime("Dynamic contents failed to get"),t}}async getMediaGroup(e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting media group: "+e);try{var t=await _getMediaGroup(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Media group gotten: "+e),t}catch(t){throw _printDatetime("Media group failed to get: "+e),t}}async getMediaItem(e){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Getting media item: "+e);try{var t=await _getMediaItem(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Media item gotten: "+e),t}catch(t){throw _printDatetime("Media item failed to get: "+e),t}}async getMyContent(){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is not available for portal API type.");_printDatetime("Getting my content");try{var t=await _getMyContent(this,this.token,this.config.serviceApiUrl,this.debugMode);return _printDatetime("My content gotten"),t}catch(t){throw _printDatetime("My content failed to get"),t}}async getMyGroup(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting my group: "+e);try{var t=await _getMyGroup(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("My group gotten: "+e),t}catch(t){throw _printDatetime("My group failed to get: "+e),t}}async getSiteConfig(e){null===this.token&&this.config.username&&await this._init(),_printDatetime("Getting site config: "+e);try{var t=await _getSiteConfig(this,this.token,this.config.serviceApiUrl,e,this.debugMode);return _printDatetime("Site config gotten: "+e),t}catch(t){throw _printDatetime("Site config failed to get: "+e),t}}async mediaSearch(t,e,i,n,r){if(null===this.token&&this.config.username&&await this._init(),"portal"!==this.config.apiType)throw new Error("This function is only available for portal API type.");_printDatetime("Searching media...");try{var a=await _mediaSearch(this,this.token,this.config.serviceApiUrl,t,e,i,n,r,this.debugMode);return _printDatetime("Media search complete"),a}catch(t){throw _printDatetime("Media search failed"),t}}async miscFunctions(e,i,n,r){null===this.token&&this.config.username&&await this._init(),_printDatetime("Calling function: "+e);try{let t=this.config.serviceApiUrl+"/"+e;r&&(t=(t=(t=t.replace("/api","")).replace("app-api.","")).replace("admin-app.",""));var a=new Headers,o=(a.append("Content-Type","application/json"),null!==this.token&&a.append("Authorization","Bearer "+this.token),this.debugMode&&(console.log(`URL: ${t}
2
+ METHOD: `+i),n)&&console.log("BODY: "+JSON.stringify(n,null,4)),{method:i,headers:a}),s=(n&&(o.body=JSON.stringify(n)),await fetch(t,o)),c=await s.text();if(!s.ok)try{throw JSON.parse(c)}catch(t){throw c}try{return JSON.parse(c)}catch(t){return c}}catch(t){_apiExceptionHandler(t,"API call failed")}}}export default NomadMediaSDK;async function _forgotPassword(t,e,i,n){return _sendRequest(t,null,"Forgot Password",e+"/api/account/forgot-password","POST",null,{username:i},n)}async function _login(t,e,i,n,r){n+="/api/account/login",e={userName:e,password:i};try{return await _sendRequest(t,null,"Login",n,"POST",null,e,r)}catch(t){throw t.message.includes("409")?new Error("Invalid username or password"):t}}async function _logout(t,e,i,n){return _sendRequest(t,e,"Logout",i+"/api/account/logout","POST",null,null,n)}async function _refreshToken(t,e,i,n,r){return await _sendRequest(t,e,"Refreshing Token",i+"/api/account/refresh-token","POST",null,{refreshToken:n},r)}async function _resetPassword(t,e,i,n,r,a){return _sendRequest(t,null,"Reset Password",e+"/api/account/reset-password","POST",null,{userName:i,TOKEN:n,newPassword:r},a)}function _apiExceptionHandler(i,n){if(!i)throw new Error(n);if("string"==typeof i)throw new Error(n+": "+i);if(!i.errors)throw new Error(n+": "+i.message);if(Array.isArray(i.errors)){let e="";for(let t=0;t<i.errors.length;t++)e+=`${i.errors[t].code}: ${i.errors[t].field}: ${i.errors[t].message}\n`;throw new Error(n+": "+e)}if("object"==typeof i.errors){let t="";for(var e in i.errors)Object.prototype.hasOwnProperty.call(i.errors,e)&&(t+=`${e}: ${i.errors[e]}\n`);throw new Error(n+": "+t)}}import{getRandomValues}from"crypto";function _newGuid(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t=>(t^getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}function _printDatetime(t){var e=(new Date).toLocaleTimeString();console.log(e+": "+t)}import axios from"axios";let MAX_RETRIES=5,TIMEOUT=3e4,SLEEP_TIME=6e4;async function _sendRequest(t,e,i,n,r,a,o,s){var c={"Content-Type":"application/json"};e&&(c.Authorization="Bearer "+e),s&&console.log(`URL: ${n}
3
+ METHOD: `+r+(a&&0===a.size?`
4
4
  PARAMS: `+JSON.stringify(a,null,4):"")+(o?`
5
- BODY: `+JSON.stringify(o,null,4):""));let l=0,h=null;do{try{if(200<=(h=await axios({method:r,url:n,headers:c,params:a||{},data:o||{},timeout:TIMEOUT})).status&&h.status<300)break;if(403!==h.status||"Refreshing Token"===i)throw new Error;await t.refreshToken()}catch(t){"ECONNABORTED"===t.code&&l<MAX_RETRIES?(l++,await _sleep(SLEEP_TIME*2**l)):(console.error(i+" failed",t),_apiExceptionHandler(t,i))}}while(!h||h.status<200||300<=h.status);try{return h.data}catch(t){}}async function _sleep(e){if(e&&0!==e)return new Promise(t=>{setTimeout(()=>{t()},1e3*e)})}function _slugify(t){return t&&0!==t.trim().length?t.toString().normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-"):""}async function _clearContinueWatching(t,e,i,n,r,a){return _sendRequest(t,e,"Clear Continue Watching",i+"/api/media/clear-watching","POST",{userId:n,assetId:r},null,a)}async function _clearWatchlist(t,e,i,n,r){return _sendRequest(t,e,"Clear Watchlist",i+"/api/media/clear-watchlist?userId="+n,"POST",null,null,r)}async function _createForm(t,e,i,n,r,a){return _sendRequest(t,e,"Creating Form",i+"/api/media/form/"+n,"POST",null,r,a)}async function _getContentCookies(t,e,i,n,r){return _sendRequest(t,e,"Get Content Cookies",i+"/api/media/set-cookies/"+n,"GET",null,null,r)}async function _getDefaultSiteConfig(t,e,i,n){return _sendRequest(t,e,"Get Default Site Config",i+"/api/media/config","GET",null,null,n)}async function _getDynamicContent(t,e,i,n,r){return _sendRequest(t,e,"Get Dynamic Content",i+"/api/media/content/"+n,"GET",null,null,r)}async function _getDynamicContents(t,e,i,n){return _sendRequest(t,e,"Get Dynamic Contents",i+"/api/media/content","GET",null,null,n)}async function _getMediaGroup(t,e,i,n,r){return _sendRequest(t,e,"Get Media Group",i+"/api/media/group/"+n,"GET",null,null,r)}async function _getMediaItem(t,e,i,n,r){return _sendRequest(t,e,"Get Media Item",i+"/api/media/item/"+n,"GET",null,null,r)}async function _getMyContent(t,e,i,n){return _sendRequest(t,e,"Get My Content",i+"/api/media/my-content","GET",null,null,n)}async function _getMyGroup(t,e,i,n,r){return _sendRequest(t,e,"Get My Group",i+"/api/media/my-group/"+n,"GET",null,null,r)}async function _getSiteConfig(t,e,i,n,r){return _sendRequest(t,e,"Get Site Config",i+"/api/media/config/"+n,"GET",null,null,r)}async function _mediaSearch(t,e,i,n,r,a,o,s,c){i+="/api/media/search",n={searchQuery:n,ids:r,sortFields:a};return n.pageOffset=o||0,n.pageSize=s||100,_sendRequest(t,e,"Media Search",i,"POST",null,n,c)}
5
+ BODY: `+JSON.stringify(o,null,4):""));let l=0,h=null;do{try{if(200<=(h=await axios({method:r,url:n,headers:c,params:a||{},data:o||{},timeout:TIMEOUT})).status&&h.status<300)break;if(403!==h.status||"Refreshing Token"===i)throw new Error;await t.refreshToken()}catch(t){"ECONNABORTED"===t.code&&l<MAX_RETRIES?(l++,await _sleep(SLEEP_TIME)):_apiExceptionHandler((t.response?.data.message?t.response.data:t).message,i+" failed")}}while(!h||h.status<200||300<=h.status);try{return h.data}catch(t){}}async function _sleep(e){if(e&&0!==e)return new Promise(t=>{setTimeout(()=>{t()},1e3*e)})}function _slugify(t){return t&&0!==t.trim().length?t.toString().normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-"):""}async function _clearContinueWatching(t,e,i,n,r,a){return _sendRequest(t,e,"Clear Continue Watching",i+"/api/media/clear-watching","POST",{userId:n,assetId:r},null,a)}async function _clearWatchlist(t,e,i,n,r){return _sendRequest(t,e,"Clear Watchlist",i+"/api/media/clear-watchlist?userId="+n,"POST",null,null,r)}async function _createForm(t,e,i,n,r,a){return _sendRequest(t,e,"Creating Form",i+"/api/media/form/"+n,"POST",null,r,a)}async function _getContentCookies(t,e,i,n,r){return _sendRequest(t,e,"Get Content Cookies",i+"/api/media/set-cookies/"+n,"GET",null,null,r)}async function _getDefaultSiteConfig(t,e,i,n){return _sendRequest(t,e,"Get Default Site Config",i+"/api/media/config","GET",null,null,n)}async function _getDynamicContent(t,e,i,n,r){return _sendRequest(t,e,"Get Dynamic Content",i+"/api/media/content/"+n,"GET",null,null,r)}async function _getDynamicContents(t,e,i,n){return _sendRequest(t,e,"Get Dynamic Contents",i+"/api/media/content","GET",null,null,n)}async function _getMediaGroup(t,e,i,n,r){return _sendRequest(t,e,"Get Media Group",i+"/api/media/group/"+n,"GET",null,null,r)}async function _getMediaItem(t,e,i,n,r){return _sendRequest(t,e,"Get Media Item",i+"/api/media/item/"+n,"GET",null,null,r)}async function _getMyContent(t,e,i,n){return _sendRequest(t,e,"Get My Content",i+"/api/media/my-content","GET",null,null,n)}async function _getMyGroup(t,e,i,n,r){return _sendRequest(t,e,"Get My Group",i+"/api/media/my-group/"+n,"GET",null,null,r)}async function _getSiteConfig(t,e,i,n,r){return _sendRequest(t,e,"Get Site Config",i+"/api/media/config/"+n,"GET",null,null,r)}async function _mediaSearch(t,e,i,n,r,a,o,s,c){i+="/api/media/search",n={searchQuery:n,ids:r,sortFields:a};return n.pageOffset=o||0,n.pageSize=s||100,_sendRequest(t,e,"Media Search",i,"POST",null,n,c)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomad-media/public",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Nomad Media NPM",
5
5
  "main": "dist/nomad-media-sdk.min.js",
6
6
  "type": "module",