Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercelayer/js-auth

Package Overview
Dependencies
Maintainers
0
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercelayer/js-auth - npm Package Compare versions

Comparing version 6.6.2 to 6.6.3

2

dist/index.js

@@ -1,2 +0,2 @@

function m(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function d(e,t){return Object.keys(e).reduce((r,n)=>{let o=t(n);return r[o]=e[n],r},{})}function g(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function h(e,{domain:t="commercelayer.io",headers:r,...n}){let o=d({grant_type:e,...n},m),p=await(await fetch(`https://auth.${t}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...r},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 u(e){return typeof btoa<"u"?btoa(e).replaceAll("=","").replaceAll("+","-").replaceAll("/","_"):Buffer.from(e,"binary").toString("base64url")}function l(e){return typeof atob<"u"?atob(e.replaceAll("-","+").replaceAll("_","/")):Buffer.from(e,"base64url").toString("binary")}function c(e){let[t,r,n]=`${e}`.split(".");if(t==null||r==null||n==null)throw new a("Invalid token format");return{header:JSON.parse(l(t)),payload:JSON.parse(l(r)),signature:n}}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 W(e){return e.application.kind==="webapp"}async function b(e){let t=d(e,m),r=c(e.token),n=r?.payload?.iss?.startsWith("https://auth.")?r.payload.iss:"https://auth.commercelayer.io";return await(await fetch(`${n}/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:r}={}){let n=c(e),o=r??await j(n);if(o==null||o.kid!==n.header.kid)throw new a('Invalid token "kid"');if(!t&&Date.now()>=n.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(n.signature),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 n}var f={};async function j(e){let{kid:t}=e.header;if(f[t]!=null)return f[t];let r=await R(e);return f[t]=r.find(n=>n.kid===t),f[t]}async function R(e){let t=`${e.payload.iss}/.well-known/jwks.json`,r=await fetch(t).then(async n=>await n.json());if(r.keys==null)throw new s(`Invalid jwks response from "${t}": ${JSON.stringify(r)}`);return r.keys}async function P({payload:e}){return await I(e,"cl")}async function I(e,t){let n=u(JSON.stringify({alg:"HS512",typ:"JWT"})),o=u(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)})),i=`${n}.${o}`,p=await O(i,t);return`${i}.${p}`}async function O(e,t){let r=new TextEncoder,n={name:"HMAC",hash:"SHA-512"},o=await crypto.subtle.importKey("raw",r.encode(t),n,!1,["sign","verify"]),i=await crypto.subtle.sign(n.name,o,r.encode(e));return u(String.fromCharCode(...new Uint8Array(i)))}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,W as jwtIsWebApp,A as jwtVerify,b 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 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};
//# sourceMappingURL=index.js.map
{
"name": "@commercelayer/js-auth",
"version": "6.6.2",
"version": "6.6.3",
"description": "A JavaScript library designed to simplify authentication when interacting with the Commerce Layer API.",

@@ -45,3 +45,3 @@ "repository": {

"typescript": "^5.6.3",
"vitest": "^2.1.2",
"vitest": "^2.1.3",
"vitest-fetch-mock": "^0.3.0"

@@ -48,0 +48,0 @@ },

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc