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.0.0 to 6.0.1

2

dist/index.js

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

function p(e){return e.replace(/[A-Z]/g,function(n){return"_"+n.toLowerCase()})}function i(e,n){return Object.keys(e).reduce((t,a)=>{let r=n(a);return t[r]=e[a],t},{})}function d(e){return e.replace(/([-_][a-z])/g,n=>n.toUpperCase().replace("-","").replace("_",""))}async function u(e,{domain:n="commercelayer.io",headers:t,...a}){let r=i({grant_type:e,...a},p),s=await(await fetch(`https://auth.${n}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...t},body:JSON.stringify(r)})).json();return s.expires=new Date(Date.now()+s.expires_in*1e3),i(s,d)}async function g({domain:e="commercelayer.io",...n}){let t=i(n,p);return await(await fetch(`https://auth.${e}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)})).json()}function c(e){return typeof window<"u"?window.btoa(e.replaceAll("=","").replaceAll("+","-").replaceAll("/","_")):Buffer.from(e,"binary").toString("base64url")}function l(e){return typeof window<"u"?window.atob(e.replaceAll("-","+").replaceAll("_","/")):Buffer.from(e,"base64url").toString("binary")}function m(e){let[n,t]=e.split(".");return{header:JSON.parse(n!=null?l(n):"null"),payload:JSON.parse(t!=null?l(t):"null")}}function y(e){return e.application.kind==="user"}function f(e){return e.application.kind==="dashboard"}function C(e){return e.application.kind==="integration"}function T(e){return e.application.kind==="sales_channel"}function w(e){return e.application.kind==="webapp"}async function k({payload:e}){return await h(e,"cl")}async function h(e,n){let a=c(JSON.stringify({alg:"HS512",typ:"JWT"})),r=c(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)})),o=`${a}.${r}`,s=await S(o,n);return`${o}.${s}`}async function S(e,n){let t=new TextEncoder,a={name:"HMAC",hash:"SHA-512"},r=await crypto.subtle.importKey("raw",t.encode(n),a,!1,["sign","verify"]),o=await crypto.subtle.sign(a.name,r,t.encode(e));return c(String.fromCharCode(...new Uint8Array(o)))}export{u as authenticate,k as createAssertion,m as jwtDecode,f as jwtIsDashboard,C as jwtIsIntegration,T as jwtIsSalesChannel,y as jwtIsUser,w as jwtIsWebApp,g as revoke};
function p(e){return e.replace(/[A-Z]/g,function(n){return"_"+n.toLowerCase()})}function i(e,n){return Object.keys(e).reduce((t,a)=>{let r=n(a);return t[r]=e[a],t},{})}function d(e){return e.replace(/([-_][a-z])/g,n=>n.toUpperCase().replace("-","").replace("_",""))}async function u(e,{domain:n="commercelayer.io",headers:t,...a}){let r=i({grant_type:e,...a},p),s=await(await fetch(`https://auth.${n}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...t},body:JSON.stringify(r)})).json();return s.expires=new Date(Date.now()+s.expires_in*1e3),i(s,d)}async function g({domain:e="commercelayer.io",...n}){let t=i(n,p);return await(await fetch(`https://auth.${e}/oauth/revoke`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)})).json()}function c(e){return typeof window<"u"?window.btoa(e).replaceAll("=","").replaceAll("+","-").replaceAll("/","_"):Buffer.from(e,"binary").toString("base64url")}function l(e){return typeof window<"u"?window.atob(e.replaceAll("-","+").replaceAll("_","/")):Buffer.from(e,"base64url").toString("binary")}function m(e){let[n,t]=e.split(".");return{header:JSON.parse(n!=null?l(n):"null"),payload:JSON.parse(t!=null?l(t):"null")}}function y(e){return e.application.kind==="user"}function f(e){return e.application.kind==="dashboard"}function C(e){return e.application.kind==="integration"}function T(e){return e.application.kind==="sales_channel"}function w(e){return e.application.kind==="webapp"}async function k({payload:e}){return await h(e,"cl")}async function h(e,n){let a=c(JSON.stringify({alg:"HS512",typ:"JWT"})),r=c(JSON.stringify({...e,iat:Math.floor(new Date().getTime()/1e3)})),o=`${a}.${r}`,s=await S(o,n);return`${o}.${s}`}async function S(e,n){let t=new TextEncoder,a={name:"HMAC",hash:"SHA-512"},r=await crypto.subtle.importKey("raw",t.encode(n),a,!1,["sign","verify"]),o=await crypto.subtle.sign(a.name,r,t.encode(e));return c(String.fromCharCode(...new Uint8Array(o)))}export{u as authenticate,k as createAssertion,m as jwtDecode,f as jwtIsDashboard,C as jwtIsIntegration,T as jwtIsSalesChannel,y as jwtIsUser,w as jwtIsWebApp,g as revoke};
//# sourceMappingURL=index.js.map
{
"name": "@commercelayer/js-auth",
"version": "6.0.0",
"version": "6.0.1",
"description": "Commerce Layer Javascript Auth",

@@ -5,0 +5,0 @@ "repository": {

@@ -59,2 +59,3 @@ # Commerce Layer JS Auth

| **Authorization code** | | | ✅ |
| **JWT bearer** | ✅ | | ✅ |

@@ -96,3 +97,3 @@ Check our [documentation](https://docs.commercelayer.io/developers/authentication) for further information on each single authorization flow.

Sales channel applications can use the [password](https://docs.commercelayer.io/developers/authentication/password) grant type to exchange a customer credentials for an access token (i.e., to get a "logged" access token).
Sales channel applications can use the [password](https://docs.commercelayer.io/developers/authentication/password) grant type to exchange customer credentials for an access token (i.e., to get a "logged" access token).

@@ -138,3 +139,3 @@ #### Steps

2. Use this codes to get the access token:
2. Use this code to get the access token:

@@ -165,3 +166,3 @@ ```ts

2. Use this url to authorize your webapp on Commerce Layer:
2. Use this URL to authorize your webapp on Commerce Layer:

@@ -200,3 +201,3 @@ ```bash

2. Use this codes to get the access token:
2. Use this code to get the access token:

@@ -220,6 +221,8 @@ ```ts

**Sales channels** and **webapps** can accomplish it by leveraging the [JWT Bearer flow](https://docs.commercelayer.io/core/authentication/jwt-bearer),
which allows a client application to obtain an access token using a JSON Web Token (JWT) [_assertion_](https://docs.commercelayer.io/core/authentication/jwt-bearer#creating-the-jwt-assertion).
which allows a client application to obtain an access token using a JSON Web Token (JWT) [assertion](https://docs.commercelayer.io/core/authentication/jwt-bearer#creating-the-jwt-assertion).
You can use this code to create an _assertion_:
#### Steps
1. Use this code to create an assertion:
```ts

@@ -244,3 +247,3 @@ const assertion = await createAssertion({

You can now get an access token using the `urn:ietf:params:oauth:grant-type:jwt-bearer` grant type:
2. Use this code to get the access token:

@@ -263,3 +266,3 @@ ```ts

Any previously generated access tokens (refresh tokens included) can be [revoked](https://docs.commercelayer.io/core/authentication/revoking-a-token) before their natural expiration date.
Any previously generated access tokens (refresh tokens included) can be [revoked](https://docs.commercelayer.io/core/authentication/revoking-a-token) before their natural expiration date:

@@ -280,3 +283,3 @@ ```ts

We offer an helper method that is able to decode an access token. The return is fully typed.
We offer a helper method to decode an access token. The return is fully typed:

@@ -283,0 +286,0 @@ ```ts

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