@nomad-media/public 1.1.8 → 1.1.10

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.
@@ -349,7 +349,7 @@ class NomadMediaSDK {
349
349
  */
350
350
  async logout()
351
351
  {
352
- if (this.token === null)
352
+ if (this.token === null && this.config.username)
353
353
  {
354
354
  await this._init();
355
355
  }
@@ -497,7 +497,7 @@ class NomadMediaSDK {
497
497
  */
498
498
  async clearContinueWatching(USER_ID, ASSET_ID)
499
499
  {
500
- if (this.token === null)
500
+ if (this.token === null && this.config.username)
501
501
  {
502
502
  await this._init();
503
503
  }
@@ -534,7 +534,7 @@ class NomadMediaSDK {
534
534
  */
535
535
  async clearWatchlist(USER_ID)
536
536
  {
537
- if (this.token === null)
537
+ if (this.token === null && this.config.username)
538
538
  {
539
539
  await this._init();
540
540
  }
@@ -575,7 +575,7 @@ class NomadMediaSDK {
575
575
  */
576
576
  async createForm(CONTENT_DEFINITION_ID, FORM_INFO)
577
577
  {
578
- if (this.token === null)
578
+ if (this.token === null && this.config.username)
579
579
  {
580
580
  await this._init();
581
581
  }
@@ -615,7 +615,7 @@ class NomadMediaSDK {
615
615
  */
616
616
  async getContentCookies(CONTENT_ID)
617
617
  {
618
- if (this.token === null)
618
+ if (this.token === null && this.config.username)
619
619
  {
620
620
  await this._init();
621
621
  }
@@ -652,7 +652,7 @@ class NomadMediaSDK {
652
652
  */
653
653
  async getDefaultSiteConfig()
654
654
  {
655
- if (this.token === null)
655
+ if (this.token === null && this.config.username)
656
656
  {
657
657
  await this._init();
658
658
  }
@@ -690,7 +690,7 @@ class NomadMediaSDK {
690
690
  */
691
691
  async getDynamicContent(DYNAMIC_CONTENT_RECORD_ID)
692
692
  {
693
- if (this.token === null)
693
+ if (this.token === null && this.config.username)
694
694
  {
695
695
  await this._init();
696
696
  }
@@ -722,7 +722,7 @@ class NomadMediaSDK {
722
722
  */
723
723
  async getDynamicContents()
724
724
  {
725
- if (this.token === null)
725
+ if (this.token === null && this.config.username)
726
726
  {
727
727
  await this._init();
728
728
  }
@@ -760,7 +760,7 @@ class NomadMediaSDK {
760
760
  */
761
761
  async getMediaGroup(MEDIA_GROUP_ID)
762
762
  {
763
- if (this.token === null)
763
+ if (this.token === null && this.config.username)
764
764
  {
765
765
  await this._init();
766
766
  }
@@ -798,7 +798,7 @@ class NomadMediaSDK {
798
798
  */
799
799
  async getMediaItem(MEDIA_ITEM_ID)
800
800
  {
801
- if (this.token === null)
801
+ if (this.token === null && this.config.username)
802
802
  {
803
803
  await this._init();
804
804
  }
@@ -837,7 +837,7 @@ class NomadMediaSDK {
837
837
  */
838
838
  async getMyContent()
839
839
  {
840
- if (this.token === null)
840
+ if (this.token === null && this.config.username)
841
841
  {
842
842
  await this._init();
843
843
  }
@@ -875,7 +875,7 @@ class NomadMediaSDK {
875
875
  */
876
876
  async getMyGroup(GROUP_ID)
877
877
  {
878
- if (this.token === null)
878
+ if (this.token === null && this.config.username)
879
879
  {
880
880
  await this._init();
881
881
  }
@@ -908,7 +908,7 @@ class NomadMediaSDK {
908
908
  */
909
909
  async getSiteConfig(SITE_CONFIG_RECORD_ID)
910
910
  {
911
- if (this.token === null)
911
+ if (this.token === null && this.config.username)
912
912
  {
913
913
  await this._init();
914
914
  }
@@ -946,7 +946,7 @@ class NomadMediaSDK {
946
946
  */
947
947
  async mediaSearch(QUERY, IDS, SORT_FIELDS, OFFSET, SIZE)
948
948
  {
949
- if (this.token === null)
949
+ if (this.token === null && this.config.username)
950
950
  {
951
951
  await this._init();
952
952
  }
@@ -988,7 +988,7 @@ class NomadMediaSDK {
988
988
 
989
989
  async miscFunctions(URL_PATH, METHOD, BODY, NOT_API_PATH)
990
990
  {
991
- if (this.token === null)
991
+ if (this.token === null && this.config.username)
992
992
  {
993
993
  await this._init();
994
994
  }
@@ -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
  {
@@ -1,4 +1,4 @@
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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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&&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}
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
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
3
  METHOD: `+r+(a?`
4
4
  PARAMS: `+JSON.stringify(a,null,4):"")+(o?`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomad-media/public",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Nomad Media NPM",
5
5
  "main": "dist/nomad-media-sdk.min.js",
6
6
  "type": "module",