@propelauth/javascript
Advanced tools
Comparing version 1.2.1 to 2.0.0-beta.1
@@ -5,10 +5,2 @@ 'use strict'; | ||
exports.UserRole = void 0; | ||
(function (UserRole) { | ||
UserRole[UserRole["Member"] = 0] = "Member"; | ||
UserRole[UserRole["Admin"] = 1] = "Admin"; | ||
UserRole[UserRole["Owner"] = 2] = "Owner"; | ||
})(exports.UserRole || (exports.UserRole = {})); | ||
function fetchAuthenticationInfo(authUrl) { | ||
@@ -112,3 +104,3 @@ return new Promise((resolve, reject) => { | ||
} else if (key === "user_role") { | ||
this.userRole = toUserRole(value); | ||
this.userRoleName = value; | ||
} else if (key === "access_token") { | ||
@@ -138,6 +130,2 @@ this.accessToken = value; | ||
function toUserRole(userRole) { | ||
return exports.UserRole[userRole]; | ||
} | ||
function logCorsError() { | ||
@@ -144,0 +132,0 @@ console.error("Request to PropelAuth failed due to a CORS error. There are a few likely causes: \n" + " 1. In the Frontend Integration section of your dashboard, make sure your requests are coming either the specified Application URL or localhost with a matching port.\n" + " 2. Make sure your server is hosted on HTTPS in production."); |
@@ -1,9 +0,1 @@ | ||
let UserRole; | ||
(function (UserRole) { | ||
UserRole[UserRole["Member"] = 0] = "Member"; | ||
UserRole[UserRole["Admin"] = 1] = "Admin"; | ||
UserRole[UserRole["Owner"] = 2] = "Owner"; | ||
})(UserRole || (UserRole = {})); | ||
function fetchAuthenticationInfo(authUrl) { | ||
@@ -107,3 +99,3 @@ return new Promise((resolve, reject) => { | ||
} else if (key === "user_role") { | ||
this.userRole = toUserRole(value); | ||
this.userRoleName = value; | ||
} else if (key === "access_token") { | ||
@@ -133,6 +125,2 @@ this.accessToken = value; | ||
function toUserRole(userRole) { | ||
return UserRole[userRole]; | ||
} | ||
function logCorsError() { | ||
@@ -402,3 +390,3 @@ console.error("Request to PropelAuth failed due to a CORS error. There are a few likely causes: \n" + " 1. In the Frontend Integration section of your dashboard, make sure your requests are coming either the specified Application URL or localhost with a matching port.\n" + " 2. Make sure your server is hosted on HTTPS in production."); | ||
export { UserRole, createClient }; | ||
export { createClient }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PropelAuth={})}(this,(function(e){"use strict";var t;function n(t){return new Promise(((n,s)=>{const r=new XMLHttpRequest;r.onreadystatechange=function(){if(r.readyState===XMLHttpRequest.DONE){const a=r.status;if(a>=200&&a<300)try{const o=(t=r.responseText,JSON.parse(t,(function(t,n){if("org_id"===t)this.orgId=n;else if("org_name"===t)this.orgName=n;else if("user_role"===t)this.userRole=(o=n,e.UserRole[o]);else if("access_token"===t)this.accessToken=n;else if("expires_at_seconds"===t)this.expiresAtSeconds=n;else if("org_id_to_org_member_info"===t)this.orgIdToOrgMemberInfo=n;else if("user_id"===t)this.userId=n;else if("email_confirmed"===t)this.emailConfirmed=n;else if("first_name"===t)this.firstName=n;else if("last_name"===t)this.lastName=n;else if("picture_url"===t)this.pictureUrl=n;else{if("mfa_enabled"!==t)return n;this.mfaEnabled=n}var o})));n(o)}catch(e){console.error("Unable to process authentication response",e),s({status:500,message:"Unable to process authentication response"})}else 401===a?n(null):0===a?(o(),s({status:503,message:"Unable to process authentication response"})):s({status:a,message:r.responseText})}var t},r.open("get",`${t}/api/v1/refresh_token`),r.withCredentials=!0,r.ontimeout=function(){s({status:408,message:"Request timed out"})},r.send(null)}))}function o(){console.error("Request to PropelAuth failed due to a CORS error. There are a few likely causes: \n 1. In the Frontend Integration section of your dashboard, make sure your requests are coming either the specified Application URL or localhost with a matching port.\n 2. Make sure your server is hosted on HTTPS in production.")}function s(){return Date.now()/1e3}function r(){return"undefined"!=typeof localStorage}function a(e){if(!r())return null;const t=localStorage.getItem(e);if(!t)return null;const n=parseInt(t,10);return Number.isNaN(n)?null:n}e.UserRole=void 0,(t=e.UserRole||(e.UserRole={}))[t.Member=0]="Member",t[t.Admin=1]="Admin",t[t.Owner=2]="Owner";const i="__PROPEL_AUTH_LOGGED_IN_AT",u="__PROPEL_AUTH_LOGGED_OUT_AT";e.createClient=function(e){!function(e){try{const t=new URL(e.authUrl);e.authUrl=t.origin}catch(e){throw console.error("Invalid authUrl",e),new Error("Unable to initialize auth client")}void 0===e.enableBackgroundTokenRefresh&&(e.enableBackgroundTokenRefresh=!0)}(e);const t={initialLoadFinished:!1,authenticationInfo:null,observers:[],lastLoggedInAtMessage:a(i),lastLoggedOutAtMessage:a(u),authUrl:e.authUrl,refreshInterval:null};function l(e){for(let n=0;n<t.observers.length;n++){const o=t.observers[n];o&&o(e)}}function c(e){var n;const o=null===(n=t.authenticationInfo)||void 0===n?void 0:n.accessToken;t.authenticationInfo=e;const r=null==e?void 0:e.accessToken;!function(e,n){return!e&&(n||!t.initialLoadFinished)}(r,o)?function(e,t){return!t&&e}(r,o)&&(l(!0),function(){const e=s();t.lastLoggedInAtMessage=e,localStorage.setItem(i,String(e))}()):(l(!1),function(){const e=s();t.lastLoggedOutAtMessage=e,localStorage.setItem(u,String(e))}()),t.initialLoadFinished=!0}async function d(e){try{const e=await n(t.authUrl);return c(e),e}catch(n){if(e)return t.authenticationInfo;throw c(null),n}}const f={addLoggedInChangeObserver(e){t.observers.includes(e)?console.error("Observer has been attached already."):e?t.observers.push(e):console.error("Cannot add a null observer")},removeLoggedInChangeObserver(e){const n=t.observers.indexOf(e);-1===n?console.error("Cannot find observer to remove"):t.observers.splice(n,1)},async getAuthenticationInfoOrNull(e){const n=s();if(e)return await d(!1);if(t.authenticationInfo){if(n+240>t.authenticationInfo.expiresAtSeconds){const e=n<t.authenticationInfo.expiresAtSeconds;return await d(e)}return t.authenticationInfo}return await d(!1)},redirectToSignupPage(){window.location.href=`${t.authUrl}/signup`},redirectToLoginPage(){window.location.href=`${t.authUrl}/login`},redirectToAccountPage(){window.location.href=`${t.authUrl}/account`},redirectToOrgPage(e){window.location.href=e?`${t.authUrl}/org?id=${e}`:`${t.authUrl}/org`},redirectToCreateOrgPage(){window.location.href=`${t.authUrl}/create_org`},async logout(e){const n=await(s=t.authUrl,new Promise(((e,t)=>{const n=new XMLHttpRequest;n.onreadystatechange=function(){if(n.readyState===XMLHttpRequest.DONE){const s=n.status;if(s>=200&&s<300){const t=JSON.parse(n.responseText);e(t)}else 0===s?(o(),t({status:503,message:"Unable to process authentication response"})):(console.error("Logout error",n.status,n.responseText),t({status:s,message:n.responseText}))}},n.open("post",`${s}/api/v1/logout`),n.withCredentials=!0,n.ontimeout=function(){t({status:408,message:"Request timed out"})},n.send(null)})));var s;c(null),e&&(window.location.href=n.redirect_to)},destroy(){t.observers=[],window.removeEventListener("storage",g),t.refreshInterval&&clearInterval(t.refreshInterval)}},g=async function(){if(!r())return;const e=a(u),n=a(i);e&&(!t.lastLoggedOutAtMessage||e>t.lastLoggedOutAtMessage)&&(t.lastLoggedOutAtMessage=e,t.authenticationInfo&&await d(!0)),n&&(!t.lastLoggedInAtMessage||n>t.lastLoggedInAtMessage)&&(t.lastLoggedInAtMessage=n,t.authenticationInfo||await d(!0))},h=async function(){await d(!0)};return"undefined"!=typeof window&&(window.addEventListener("storage",g),window.addEventListener("online",h),window.addEventListener("focus",h),e.enableBackgroundTokenRefresh&&(f.getAuthenticationInfoOrNull(),t.refreshInterval=window.setInterval(f.getAuthenticationInfoOrNull,6e4))),f}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PropelAuth={})}(this,(function(e){"use strict";function t(e){return new Promise(((t,o)=>{const s=new XMLHttpRequest;s.onreadystatechange=function(){if(s.readyState===XMLHttpRequest.DONE){const r=s.status;if(r>=200&&r<300)try{const n=(e=s.responseText,JSON.parse(e,(function(e,t){if("org_id"===e)this.orgId=t;else if("org_name"===e)this.orgName=t;else if("user_role"===e)this.userRoleName=t;else if("access_token"===e)this.accessToken=t;else if("expires_at_seconds"===e)this.expiresAtSeconds=t;else if("org_id_to_org_member_info"===e)this.orgIdToOrgMemberInfo=t;else if("user_id"===e)this.userId=t;else if("email_confirmed"===e)this.emailConfirmed=t;else if("first_name"===e)this.firstName=t;else if("last_name"===e)this.lastName=t;else if("picture_url"===e)this.pictureUrl=t;else{if("mfa_enabled"!==e)return t;this.mfaEnabled=t}})));t(n)}catch(e){console.error("Unable to process authentication response",e),o({status:500,message:"Unable to process authentication response"})}else 401===r?t(null):0===r?(n(),o({status:503,message:"Unable to process authentication response"})):o({status:r,message:s.responseText})}var e},s.open("get",`${e}/api/v1/refresh_token`),s.withCredentials=!0,s.ontimeout=function(){o({status:408,message:"Request timed out"})},s.send(null)}))}function n(){console.error("Request to PropelAuth failed due to a CORS error. There are a few likely causes: \n 1. In the Frontend Integration section of your dashboard, make sure your requests are coming either the specified Application URL or localhost with a matching port.\n 2. Make sure your server is hosted on HTTPS in production.")}function o(){return Date.now()/1e3}function s(){return"undefined"!=typeof localStorage}function r(e){if(!s())return null;const t=localStorage.getItem(e);if(!t)return null;const n=parseInt(t,10);return Number.isNaN(n)?null:n}const a="__PROPEL_AUTH_LOGGED_IN_AT",i="__PROPEL_AUTH_LOGGED_OUT_AT";e.createClient=function(e){!function(e){try{const t=new URL(e.authUrl);e.authUrl=t.origin}catch(e){throw console.error("Invalid authUrl",e),new Error("Unable to initialize auth client")}void 0===e.enableBackgroundTokenRefresh&&(e.enableBackgroundTokenRefresh=!0)}(e);const u={initialLoadFinished:!1,authenticationInfo:null,observers:[],lastLoggedInAtMessage:r(a),lastLoggedOutAtMessage:r(i),authUrl:e.authUrl,refreshInterval:null};function l(e){for(let t=0;t<u.observers.length;t++){const n=u.observers[t];n&&n(e)}}function c(e){var t;const n=null===(t=u.authenticationInfo)||void 0===t?void 0:t.accessToken;u.authenticationInfo=e;const s=null==e?void 0:e.accessToken;!function(e,t){return!e&&(t||!u.initialLoadFinished)}(s,n)?function(e,t){return!t&&e}(s,n)&&(l(!0),function(){const e=o();u.lastLoggedInAtMessage=e,localStorage.setItem(a,String(e))}()):(l(!1),function(){const e=o();u.lastLoggedOutAtMessage=e,localStorage.setItem(i,String(e))}()),u.initialLoadFinished=!0}async function d(e){try{const e=await t(u.authUrl);return c(e),e}catch(t){if(e)return u.authenticationInfo;throw c(null),t}}const f={addLoggedInChangeObserver(e){u.observers.includes(e)?console.error("Observer has been attached already."):e?u.observers.push(e):console.error("Cannot add a null observer")},removeLoggedInChangeObserver(e){const t=u.observers.indexOf(e);-1===t?console.error("Cannot find observer to remove"):u.observers.splice(t,1)},async getAuthenticationInfoOrNull(e){const t=o();if(e)return await d(!1);if(u.authenticationInfo){if(t+240>u.authenticationInfo.expiresAtSeconds){const e=t<u.authenticationInfo.expiresAtSeconds;return await d(e)}return u.authenticationInfo}return await d(!1)},redirectToSignupPage(){window.location.href=`${u.authUrl}/signup`},redirectToLoginPage(){window.location.href=`${u.authUrl}/login`},redirectToAccountPage(){window.location.href=`${u.authUrl}/account`},redirectToOrgPage(e){window.location.href=e?`${u.authUrl}/org?id=${e}`:`${u.authUrl}/org`},redirectToCreateOrgPage(){window.location.href=`${u.authUrl}/create_org`},async logout(e){const t=await(o=u.authUrl,new Promise(((e,t)=>{const s=new XMLHttpRequest;s.onreadystatechange=function(){if(s.readyState===XMLHttpRequest.DONE){const o=s.status;if(o>=200&&o<300){const t=JSON.parse(s.responseText);e(t)}else 0===o?(n(),t({status:503,message:"Unable to process authentication response"})):(console.error("Logout error",s.status,s.responseText),t({status:o,message:s.responseText}))}},s.open("post",`${o}/api/v1/logout`),s.withCredentials=!0,s.ontimeout=function(){t({status:408,message:"Request timed out"})},s.send(null)})));var o;c(null),e&&(window.location.href=t.redirect_to)},destroy(){u.observers=[],window.removeEventListener("storage",g),u.refreshInterval&&clearInterval(u.refreshInterval)}},g=async function(){if(!s())return;const e=r(i),t=r(a);e&&(!u.lastLoggedOutAtMessage||e>u.lastLoggedOutAtMessage)&&(u.lastLoggedOutAtMessage=e,u.authenticationInfo&&await d(!0)),t&&(!u.lastLoggedInAtMessage||t>u.lastLoggedInAtMessage)&&(u.lastLoggedInAtMessage=t,u.authenticationInfo||await d(!0))},h=async function(){await d(!0)};return"undefined"!=typeof window&&(window.addEventListener("storage",g),window.addEventListener("online",h),window.addEventListener("focus",h),e.enableBackgroundTokenRefresh&&(f.getAuthenticationInfoOrNull(),u.refreshInterval=window.setInterval(f.getAuthenticationInfoOrNull,6e4))),f}})); | ||
//# sourceMappingURL=javascript.min.js.map |
export type { AuthenticationInfo, User } from "./api"; | ||
export { createClient } from "./client"; | ||
export type { IAuthClient, IAuthOptions } from "./client"; | ||
export { UserRole } from "./org"; | ||
export type { OrgIdToOrgMemberInfo, OrgMemberInfo } from "./org"; |
export declare type OrgMemberInfo = { | ||
orgId: string; | ||
orgName: string; | ||
userRole: UserRole; | ||
userRoleName: string; | ||
}; | ||
@@ -9,6 +9,1 @@ export declare type OrgIdToOrgMemberInfo = { | ||
}; | ||
export declare enum UserRole { | ||
Member = 0, | ||
Admin = 1, | ||
Owner = 2 | ||
} |
@@ -8,3 +8,6 @@ { | ||
}, | ||
"version": "1.2.1", | ||
"version": "2.0.0-beta.1", | ||
"publishConfig": { | ||
"tag": "beta" | ||
}, | ||
"keywords": [ | ||
@@ -11,0 +14,0 @@ "auth", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
120307
737
2