@jibb-open/jssdk 3.6.2 → 3.6.3
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.
- package/api/auth.js +1 -1
- package/package.json +1 -1
package/api/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Auth=void 0,require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.promise.js");var _config=require("../config.js"),_index=require("../utils/logger/index.js"),_types=require("../types/types.js"),_index2=require("../utils/http/index.js");function _classPrivateMethodInitSpec(a,b){_checkPrivateRedeclaration(a,b),b.add(a)}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classPrivateMethodGet(a,b,c){if(!b.has(a))throw new TypeError("attempted to get private field on non-instance");return c}function _classPrivateFieldGet(a,b){var c=_classExtractFieldDescriptor(a,b,"get");return _classApplyDescriptorGet(a,c)}function _classApplyDescriptorGet(a,b){return b.get?b.get.call(a):b.value}function _classPrivateFieldSet(a,b,c){var d=_classExtractFieldDescriptor(a,b,"set");return _classApplyDescriptorSet(a,d,c),c}function _classExtractFieldDescriptor(a,b,c){if(!b.has(a))throw new TypeError("attempted to "+c+" private field on non-instance");return b.get(a)}function _classApplyDescriptorSet(a,b,c){if(b.set)b.set.call(a,c);else{if(!b.writable)throw new TypeError("attempted to set read only private field");b.value=c}}var _userClaims=/*#__PURE__*/new WeakMap,_getUserTokenFromApiKey=/*#__PURE__*/new WeakSet,_getUserTokenFromIDToken=/*#__PURE__*/new WeakSet,_refreshUserToken=/*#__PURE__*/new WeakSet;class AuthClass{constructor(){_classPrivateMethodInitSpec(this,_refreshUserToken),_classPrivateMethodInitSpec(this,_getUserTokenFromIDToken),_classPrivateMethodInitSpec(this,_getUserTokenFromApiKey),_classPrivateFieldInitSpec(this,_userClaims,{writable:!0,value:void 0}),_index.logger.debug("Creating new Auth instance"),this.apiKey=void 0,_classPrivateFieldSet(this,_userClaims,new Map),this.getIdToken=void 0}setUserToken(a){let b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:_types.AccessLevel.USER,c=new _types.UserClaims(a);_classPrivateFieldGet(this,_userClaims).set(b,c)}setApiKey(a){this.apiKey=a,_classPrivateFieldGet(this,_userClaims).clear()}async getUserClaims(){return await this.getUserToken(),_classPrivateFieldGet(this,_userClaims).get(_types.AccessLevel.USER)}async getUserToken(){let a,{expiry:b,refresh:c,accessLevel:d}=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(c=c||!1,d=d||_types.AccessLevel.USER
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Auth=void 0,require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.promise.js");var _config=require("../config.js"),_index=require("../utils/logger/index.js"),_types=require("../types/types.js"),_index2=require("../utils/http/index.js");function _classPrivateMethodInitSpec(a,b){_checkPrivateRedeclaration(a,b),b.add(a)}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classPrivateMethodGet(a,b,c){if(!b.has(a))throw new TypeError("attempted to get private field on non-instance");return c}function _classPrivateFieldGet(a,b){var c=_classExtractFieldDescriptor(a,b,"get");return _classApplyDescriptorGet(a,c)}function _classApplyDescriptorGet(a,b){return b.get?b.get.call(a):b.value}function _classPrivateFieldSet(a,b,c){var d=_classExtractFieldDescriptor(a,b,"set");return _classApplyDescriptorSet(a,d,c),c}function _classExtractFieldDescriptor(a,b,c){if(!b.has(a))throw new TypeError("attempted to "+c+" private field on non-instance");return b.get(a)}function _classApplyDescriptorSet(a,b,c){if(b.set)b.set.call(a,c);else{if(!b.writable)throw new TypeError("attempted to set read only private field");b.value=c}}var _userClaims=/*#__PURE__*/new WeakMap,_getUserTokenFromApiKey=/*#__PURE__*/new WeakSet,_getUserTokenFromIDToken=/*#__PURE__*/new WeakSet,_refreshUserToken=/*#__PURE__*/new WeakSet;class AuthClass{constructor(){_classPrivateMethodInitSpec(this,_refreshUserToken),_classPrivateMethodInitSpec(this,_getUserTokenFromIDToken),_classPrivateMethodInitSpec(this,_getUserTokenFromApiKey),_classPrivateFieldInitSpec(this,_userClaims,{writable:!0,value:void 0}),_index.logger.debug("Creating new Auth instance"),this.apiKey=void 0,_classPrivateFieldSet(this,_userClaims,new Map),this.getIdToken=void 0}setUserToken(a){let b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:_types.AccessLevel.USER,c=new _types.UserClaims(a);_classPrivateFieldGet(this,_userClaims).set(b,c)}setApiKey(a){this.apiKey=a,_classPrivateFieldGet(this,_userClaims).clear()}async getUserClaims(){return await this.getUserToken(),_classPrivateFieldGet(this,_userClaims).get(_types.AccessLevel.USER)}async getUserToken(){let a,{expiry:b,refresh:c,accessLevel:d}=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(c=c||!1,d=d||_types.AccessLevel.USER,!0===c&&(await _classPrivateMethodGet(this,_refreshUserToken,_refreshUserToken2).call(this,{expiry:b,accessLevel:d})),a=_classPrivateFieldGet(this,_userClaims).get(d),void 0!==a&&!a.isExpired())return a.token;if(await _classPrivateMethodGet(this,_refreshUserToken,_refreshUserToken2).call(this,{expiry:b,accessLevel:d}),a=_classPrivateFieldGet(this,_userClaims).get(d),void 0!==a&&!a.isExpired())return a.token;throw new Error("could not create user token")}logout(){_classPrivateFieldGet(this,_userClaims).clear()}async generateAPIKey(){let a={"Content-Type":"application/json",Accept:"application/json","x-jibb-user-jwt":await this.getUserToken()},b=await _index2.http.get("".concat(_config.Config.apiBaseURL,"/v1/auth/apikey"),a);return b.data.apiKey}async generateCustomAuthPassword(){let a={"Content-Type":"application/json",Accept:"application/json","x-jibb-id-jwt":await this.getIdToken()},b=await _index2.http.get("".concat(_config.Config.apiBaseURL,"/v1/auth/custom"),a);return b.data.password}}async function _getUserTokenFromApiKey2(a){let{expiry:b,accessLevel:c}=a,d={api_key:this.apiKey};b!==void 0&&(d.expiry={seconds:b});let e;switch(c){case _types.AccessLevel.ADMIN:e="".concat(_config.Config.apiBaseURL,"/v1/admin/auth/token");break;case _types.AccessLevel.SUPERADMIN:e="".concat(_config.Config.apiBaseURL,"/v1/superadmin/auth/token");break;default:e="".concat(_config.Config.apiBaseURL,"/v1/auth/token");}let f=await _index2.http.post(e,d,{"Content-Type":"application/json",Accept:"application/json"});return f.data.token}async function _getUserTokenFromIDToken2(a){let{expiry:b,accessLevel:c}=a,d={"Content-Type":"application/json",Accept:"application/json","x-jibb-id-jwt":await this.getIdToken()},e={};b!==void 0&&(e.expiry={seconds:b});let f;switch(c){case _types.AccessLevel.ADMIN:f="".concat(_config.Config.apiBaseURL,"/v1/admin/auth/token");break;case _types.AccessLevel.SUPERADMIN:f="".concat(_config.Config.apiBaseURL,"/v1/superadmin/auth/token");break;default:f="".concat(_config.Config.apiBaseURL,"/v1/auth/token");}let g=await _index2.http.post(f,e,d);return g.data.token}async function _refreshUserToken2(a){let{expiry:b,accessLevel:c}=a;if(this.apiKey){let a=await _classPrivateMethodGet(this,_getUserTokenFromApiKey,_getUserTokenFromApiKey2).call(this,{expiry:b,accessLevel:c});return this.setUserToken(a,c),a}try{let a=await _classPrivateMethodGet(this,_getUserTokenFromIDToken,_getUserTokenFromIDToken2).call(this,{expiry:b,accessLevel:c});return this.setUserToken(a,c),a}catch(a){_index.logger.error(a)}}let Auth=new AuthClass;exports.Auth=Auth;
|