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

@commercelayer/js-auth

Package Overview
Dependencies
Maintainers
2
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.3.0 to 6.3.1

2

dist/index.js

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

function d(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function p(e,t){return Object.keys(e).reduce((r,n)=>{let o=t(n);return r[o]=e[n],r},{})}function m(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function w(e,{domain:t="commercelayer.io",headers:r,...n}){let o=p({grant_type:e,...n},d),s=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 s.errors==null&&(s.expires=new Date(Date.now()+s.expires_in*1e3)),p(s,m)}async function k({domain:e="commercelayer.io",...t}){let r=p(t,d);return await(await fetch(`https://auth.${e}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r)})).json()}var i=class extends Error{constructor(t){super(t),this.name="TokenError"}};function y(e){return typeof globalThis.btoa<"u"?globalThis.btoa(e).replaceAll("=","").replaceAll("+","-").replaceAll("/","_"):Buffer.from(e,"binary").toString("base64url")}function c(e){return typeof globalThis.atob<"u"?globalThis.atob(e.replaceAll("-","+").replaceAll("_","/")):Buffer.from(e,"base64url").toString("binary")}function u(e){let[t,r,n]=`${e}`.split(".");if(t==null||r==null||n==null)throw new i("Invalid token format");return{header:JSON.parse(c(t)),payload:JSON.parse(c(r)),signature:n}}function h(e){return e.application.kind==="user"}function C(e){return e.application.kind==="dashboard"}function x(e){return e.application.kind==="integration"}function S(e){return e.application.kind==="sales_channel"}function b(e){return e.application.kind==="webapp"}var l=class extends Error{constructor(){super("Token expired"),this.name="TokenExpiredError"}};async function J(e,{ignoreExpiration:t=!1,domain:r}={}){let n=u(e),o=await W(n.header.kid,{domain:r,ignoreExpiration:t});if(o==null)throw new i('Invalid token "kid"');if(!t&&Date.now()>=n.payload.exp*1e3)throw new l;let a={name:"RSASSA-PKCS1-v1_5",hash:"SHA-512"},s=await crypto.subtle.importKey("jwk",o,a,!0,["verify"]),f=new Uint8Array(Array.from(c(n.signature),T=>T.charCodeAt(0))),g=new TextEncoder().encode(e.split(".").slice(0,2).join("."));if(!await crypto.subtle.verify(a,s,f,g))throw new i("Invalid signature");return n}async function W(e,{domain:t="commercelayer.io"}){return(await fetch(`https://auth.${t}/.well-known/jwks.json`).then(async n=>await n.json())).keys.find(n=>n.kid===e)}async function A({payload:e}){return await R(e,"cl")}async function R(e,t){let n=y(JSON.stringify({alg:"HS512",typ:"JWT"})),o=y(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)})),a=`${n}.${o}`,s=await j(a,t);return`${a}.${s}`}async function j(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"]),a=await crypto.subtle.sign(n.name,o,r.encode(e));return y(String.fromCharCode(...new Uint8Array(a)))}export{i as TokenError,l as TokenExpiredError,w as authenticate,A as createAssertion,u as jwtDecode,C as jwtIsDashboard,x as jwtIsIntegration,S as jwtIsSalesChannel,h as jwtIsUser,b as jwtIsWebApp,J as jwtVerify,k as revoke};
function d(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function p(e,t){return Object.keys(e).reduce((r,n)=>{let o=t(n);return r[o]=e[n],r},{})}function m(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function w(e,{domain:t="commercelayer.io",headers:r,...n}){let o=p({grant_type:e,...n},d),s=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 s.errors==null&&(s.expires=new Date(Date.now()+s.expires_in*1e3)),p(s,m)}async function k({domain:e="commercelayer.io",...t}){let r=p(t,d);return await(await fetch(`https://auth.${e}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(r)})).json()}var i=class extends Error{constructor(t){super(t),this.name="TokenError"}};function y(e){return typeof btoa<"u"?btoa(e).replaceAll("=","").replaceAll("+","-").replaceAll("/","_"):Buffer.from(e,"binary").toString("base64url")}function c(e){return typeof atob<"u"?atob(e.replaceAll("-","+").replaceAll("_","/")):Buffer.from(e,"base64url").toString("binary")}function u(e){let[t,r,n]=`${e}`.split(".");if(t==null||r==null||n==null)throw new i("Invalid token format");return{header:JSON.parse(c(t)),payload:JSON.parse(c(r)),signature:n}}function C(e){return e.application.kind==="user"}function h(e){return e.application.kind==="dashboard"}function x(e){return e.application.kind==="integration"}function S(e){return e.application.kind==="sales_channel"}function J(e){return e.application.kind==="webapp"}var l=class extends Error{constructor(){super("Token expired"),this.name="TokenExpiredError"}};async function b(e,{ignoreExpiration:t=!1,domain:r}={}){let n=u(e),o=await W(n.header.kid,{domain:r,ignoreExpiration:t});if(o==null)throw new i('Invalid token "kid"');if(!t&&Date.now()>=n.payload.exp*1e3)throw new l;let a={name:"RSASSA-PKCS1-v1_5",hash:"SHA-512"},s=await crypto.subtle.importKey("jwk",o,a,!0,["verify"]),f=new Uint8Array(Array.from(c(n.signature),T=>T.charCodeAt(0))),g=new TextEncoder().encode(e.split(".").slice(0,2).join("."));if(!await crypto.subtle.verify(a,s,f,g))throw new i("Invalid signature");return n}async function W(e,{domain:t="commercelayer.io"}){return(await fetch(`https://auth.${t}/.well-known/jwks.json`).then(async n=>await n.json())).keys.find(n=>n.kid===e)}async function A({payload:e}){return await R(e,"cl")}async function R(e,t){let n=y(JSON.stringify({alg:"HS512",typ:"JWT"})),o=y(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)})),a=`${n}.${o}`,s=await j(a,t);return`${a}.${s}`}async function j(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"]),a=await crypto.subtle.sign(n.name,o,r.encode(e));return y(String.fromCharCode(...new Uint8Array(a)))}export{i as TokenError,l as TokenExpiredError,w as authenticate,A as createAssertion,u as jwtDecode,h as jwtIsDashboard,x as jwtIsIntegration,S as jwtIsSalesChannel,C as jwtIsUser,J as jwtIsWebApp,b as jwtVerify,k as revoke};
//# sourceMappingURL=index.js.map
{
"name": "@commercelayer/js-auth",
"version": "6.3.0",
"version": "6.3.1",
"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

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