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.5.0 to 6.6.0

10

dist/index.d.ts

@@ -186,3 +186,3 @@ interface TBaseOptions {

/** The options type for the `revoke` helper. */
type RevokeOptions = Pick<TBaseOptions, 'clientId' | 'domain'> & {
type RevokeOptions = Pick<TBaseOptions, 'clientId'> & {
/** Your application's client secret (required for confidential API credentials and non-confidential API credentials without a customer or a user in the JWT only). */

@@ -232,3 +232,3 @@ clientSecret?: string;

*/
declare function revoke({ domain, ...options }: RevokeOptions): Promise<RevokeReturn>;
declare function revoke(options: RevokeOptions): Promise<RevokeReturn>;

@@ -397,3 +397,3 @@ /**

*/
declare function jwtVerify(accessToken: string, { ignoreExpiration, domain, jwk }?: JwtVerifyOptions): Promise<CommerceLayerJWT>;
declare function jwtVerify(accessToken: string, { ignoreExpiration, jwk }?: JwtVerifyOptions): Promise<CommerceLayerJWT>;
type CommerceLayerJsonWebKey = JsonWebKey & {

@@ -404,6 +404,2 @@ kid: string;

/**
* The Commerce Layer's domain.
*/
domain?: string;
/**
* Do not validate the token expiration when set to `true`.

@@ -410,0 +406,0 @@ * @default false

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

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

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