@commercelayer/js-auth
Advanced tools
Comparing version 6.6.3 to 6.6.4
@@ -1,2 +0,2 @@ | ||
function u(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function d(e,t){return Object.keys(e).reduce((n,r)=>{let o=t(r);return n[o]=e[r],n},{})}function g(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function C(e,{domain:t="commercelayer.io",headers:n,...r}){let o=d({grant_type:e,...r},u),p=await(await fetch(`https://auth.${t}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n},body:JSON.stringify(o)})).json();return p.errors==null&&(p.expires=new Date(Date.now()+p.expires_in*1e3)),d(p,g)}var s=class extends Error{constructor(t){super(t),this.name="TokenError"}};var a=class extends s{constructor(t){super(t),this.name="InvalidTokenError"}};function m(e,t){if(typeof btoa<"u"){let n=t==="utf-8"?unescape(encodeURIComponent(e)):e;return btoa(n).replaceAll("=","").replaceAll("+","-").replaceAll("/","_")}return Buffer.from(e,t).toString("base64url")}function l(e,t){if(typeof atob<"u"){let n=atob(e.replaceAll("-","+").replaceAll("_","/"));return t==="utf-8"?decodeURIComponent(escape(n)):n}return Buffer.from(e,"base64url").toString(t)}function c(e){let[t,n,r]=`${e}`.split(".");if(t==null||n==null||r==null)throw new a("Invalid token format");return{header:JSON.parse(l(t,"binary")),payload:JSON.parse(l(n,"utf-8")),signature:r}}function h(e){return e.application.kind==="user"}function x(e){return e.application.kind==="dashboard"}function J(e){return e.application.kind==="integration"}function S(e){return e.application.kind==="sales_channel"}function b(e){return e.application.kind==="webapp"}async function W(e){let t=d(e,u),n=c(e.token),r=n?.payload?.iss?.startsWith("https://auth.")?n.payload.iss:"https://auth.commercelayer.io";return await(await fetch(`${r}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)})).json()}var y=class extends s{constructor(){super("Token expired"),this.name="TokenExpiredError"}};async function A(e,{ignoreExpiration:t=!1,jwk:n}={}){let r=c(e),o=n??await R(r);if(o==null||o.kid!==r.header.kid)throw new a('Invalid token "kid"');if(!t&&Date.now()>=r.payload.exp*1e3)throw new y;let i={name:"RSASSA-PKCS1-v1_5",hash:"SHA-512"},p=await crypto.subtle.importKey("jwk",o,i,!0,["verify"]),T=new Uint8Array(Array.from(l(r.signature,"binary"),w=>w.charCodeAt(0))),k=new TextEncoder().encode(e.split(".").slice(0,2).join("."));if(!await crypto.subtle.verify(i,p,T,k))throw new a("Invalid signature");return r}var f={};async function R(e){let{kid:t}=e.header;if(f[t]!=null)return f[t];let n=await j(e);return f[t]=n.find(r=>r.kid===t),f[t]}async function j(e){let t=`${e.payload.iss}/.well-known/jwks.json`,n=await fetch(t).then(async r=>await r.json());if(n.keys==null)throw new s(`Invalid jwks response from "${t}": ${JSON.stringify(n)}`);return n.keys}async function P({payload:e}){return await I(e,"cl")}async function I(e,t){let r=m(JSON.stringify({alg:"HS512",typ:"JWT"}),"binary"),o=m(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)}),"utf-8"),i=`${r}.${o}`,p=await O(i,t);return`${i}.${p}`}async function O(e,t){let n=new TextEncoder,r={name:"HMAC",hash:"SHA-512"},o=await crypto.subtle.importKey("raw",n.encode(t),r,!1,["sign","verify"]),i=await crypto.subtle.sign(r.name,o,n.encode(e));return m(String.fromCharCode(...new Uint8Array(i)),"binary")}function K(e){let t=c(e);if(!("organization"in t.payload))throw new a("Invalid token format");return t?.payload?.iss?.startsWith("https://auth.")?t.payload.iss.replace("auth",t.payload.organization.slug):`https://${t.payload.organization.slug}.commercelayer.io`}export{a as InvalidTokenError,s as TokenError,y as TokenExpiredError,C as authenticate,P as createAssertion,K as getCoreApiBaseEndpoint,c as jwtDecode,x as jwtIsDashboard,J as jwtIsIntegration,S as jwtIsSalesChannel,h as jwtIsUser,b as jwtIsWebApp,A as jwtVerify,W as revoke}; | ||
function u(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function d(e,t){return Object.keys(e).reduce((n,r)=>{let o=t(r);return n[o]=e[r],n},{})}function g(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function h(e,{domain:t="commercelayer.io",headers:n,...r}){let o=d({grant_type:e,...r},u),p=await(await fetch(`https://auth.${t}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...n},body:JSON.stringify(o)})).json();return p.errors==null&&(p.expires=new Date(Date.now()+p.expires_in*1e3)),d(p,g)}var s=class extends Error{constructor(t){super(t),this.name="TokenError"}};var a=class extends s{constructor(t){super(t),this.name="InvalidTokenError"}};function m(e,t){if(typeof btoa<"u"){let n=e;if(t==="utf-8"){let r=new TextEncoder().encode(e);n=String.fromCharCode(...r)}return btoa(n).replaceAll("=","").replaceAll("+","-").replaceAll("/","_")}return Buffer.from(e,t).toString("base64url")}function l(e,t){if(typeof atob<"u"){let n=atob(e.replaceAll("-","+").replaceAll("_","/").padEnd(e.length+(4-e.length%4)%4,"="));if(t==="utf-8"){let r=new Uint8Array([...n].map(o=>o.charCodeAt(0)));return new TextDecoder().decode(r)}return n}return Buffer.from(e,"base64url").toString(t)}function c(e){let[t,n,r]=`${e}`.split(".");if(t==null||n==null||r==null)throw new a("Invalid token format");return{header:JSON.parse(l(t,"binary")),payload:JSON.parse(l(n,"utf-8")),signature:r}}function C(e){return e.application.kind==="user"}function x(e){return e.application.kind==="dashboard"}function J(e){return e.application.kind==="integration"}function S(e){return e.application.kind==="sales_channel"}function b(e){return e.application.kind==="webapp"}async function W(e){let t=d(e,u),n=c(e.token),r=n?.payload?.iss?.startsWith("https://auth.")?n.payload.iss:"https://auth.commercelayer.io";return await(await fetch(`${r}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)})).json()}var y=class extends s{constructor(){super("Token expired"),this.name="TokenExpiredError"}};async function A(e,{ignoreExpiration:t=!1,jwk:n}={}){let r=c(e),o=n??await j(r);if(o==null||o.kid!==r.header.kid)throw new a('Invalid token "kid"');if(!t&&Date.now()>=r.payload.exp*1e3)throw new y;let i={name:"RSASSA-PKCS1-v1_5",hash:"SHA-512"},p=await crypto.subtle.importKey("jwk",o,i,!0,["verify"]),T=new Uint8Array(Array.from(l(r.signature,"binary"),w=>w.charCodeAt(0))),k=new TextEncoder().encode(e.split(".").slice(0,2).join("."));if(!await crypto.subtle.verify(i,p,T,k))throw new a("Invalid signature");return r}var f={};async function j(e){let{kid:t}=e.header;if(f[t]!=null)return f[t];let n=await R(e);return f[t]=n.find(r=>r.kid===t),f[t]}async function R(e){let t=`${e.payload.iss}/.well-known/jwks.json`,n=await fetch(t).then(async r=>await r.json());if(n.keys==null)throw new s(`Invalid jwks response from "${t}": ${JSON.stringify(n)}`);return n.keys}async function P({payload:e}){return await I(e,"cl")}async function I(e,t){let r=m(JSON.stringify({alg:"HS512",typ:"JWT"}),"binary"),o=m(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)}),"utf-8"),i=`${r}.${o}`,p=await O(i,t);return`${i}.${p}`}async function O(e,t){let n=new TextEncoder,r={name:"HMAC",hash:"SHA-512"},o=await crypto.subtle.importKey("raw",n.encode(t),r,!1,["sign","verify"]),i=await crypto.subtle.sign(r.name,o,n.encode(e));return m(String.fromCharCode(...new Uint8Array(i)),"binary")}function K(e){let t=c(e);if(!("organization"in t.payload))throw new a("Invalid token format");return t?.payload?.iss?.startsWith("https://auth.")?t.payload.iss.replace("auth",t.payload.organization.slug):`https://${t.payload.organization.slug}.commercelayer.io`}export{a as InvalidTokenError,s as TokenError,y as TokenExpiredError,h as authenticate,P as createAssertion,K as getCoreApiBaseEndpoint,c as jwtDecode,x as jwtIsDashboard,J as jwtIsIntegration,S as jwtIsSalesChannel,C as jwtIsUser,b as jwtIsWebApp,A as jwtVerify,W as revoke}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@commercelayer/js-auth", | ||
"version": "6.6.3", | ||
"version": "6.6.4", | ||
"description": "A JavaScript library designed to simplify authentication when interacting with the Commerce Layer API.", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117185
522