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 5.1.0 to 5.2.0

dist/index.cjs.map

91

dist/index.js

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

// src/utils/camelCaseToSnake.ts
function camelCaseToSnake(str) {
return str.replace(/[A-Z]/g, function(letter) {
return "_" + letter.toLowerCase();
});
}
// src/utils/snakeToCamelCase.ts
function snakeToCamelCase(str) {
return str.replace(
/([-_][a-z])/g,
(group) => group.toUpperCase().replace("-", "").replace("_", "")
);
}
// src/core.ts
async function authentication(grantType, { domain = "commercelayer.io", slug, headers, ...options }) {
const attributes = {
grant_type: grantType,
...options
};
const body = Object.keys(attributes).reduce((acc, key) => {
const camelKey = camelCaseToSnake(key);
acc[camelKey] = attributes[key];
return acc;
}, {});
return await fetch(`https://${slug}.${domain}/oauth/token`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
...headers
},
body: JSON.stringify(body)
}).then(async (response) => {
const json = await response.json();
json.expires = new Date(Date.now() + json.expires_in * 1e3);
return Object.keys(json).reduce((acc, key) => {
const camelKey = snakeToCamelCase(key);
acc[camelKey] = json[key];
return acc;
}, {});
});
}
var core = {
authentication
};
// src/provisioning.ts
async function authentication2({
domain = "commercelayer.io",
headers,
...options
}) {
const attributes = {
grant_type: "client_credentials",
scope: "provisioning-api",
...options
};
const body = Object.keys(attributes).reduce((acc, key) => {
const camelKey = camelCaseToSnake(key);
acc[camelKey] = attributes[key];
return acc;
}, {});
return await fetch(`https://auth.${domain}/oauth/token`, {
method: "POST",
headers: {
"Content-Type": "application/vnd.api+json",
Accept: "application/vnd.api+json",
...headers
},
body: JSON.stringify(body)
}).then(async (response) => {
const json = await response.json();
json.expires = new Date(Date.now() + json.expires_in * 1e3);
return Object.keys(json).reduce((acc, key) => {
const camelKey = snakeToCamelCase(key);
acc[camelKey] = json[key];
return acc;
}, {});
});
}
var provisioning = {
authentication: authentication2
};
export {
core,
provisioning
};
function c(e){return e.replace(/[A-Z]/g,function(t){return"_"+t.toLowerCase()})}function m(e){return e.replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_",""))}async function i({attributes:e,headers:t,endpoint:r}){let a=Object.keys(e).reduce((o,n)=>{let s=c(n);return o[s]=e[n],o},{});return await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...t},body:JSON.stringify(a)}).then(async o=>{let n=await o.json();return n.expires=new Date(Date.now()+n.expires_in*1e3),Object.keys(n).reduce((s,p)=>{let u=m(p);return s[u]=n[p],s},{})})}async function y(e,{domain:t="commercelayer.io",slug:r,headers:a,...o}){return await i({attributes:{grant_type:e,...o},endpoint:`https://${r}.${t}/oauth/token`,headers:a})}var C={authentication:y};async function T({domain:e="commercelayer.io",headers:t,...r}){return await i({attributes:{grant_type:"client_credentials",scope:"provisioning-api",...r},endpoint:`https://auth.${e}/oauth/token`,headers:t})}var d={authentication:T};export{C as core,d as provisioning};
//# sourceMappingURL=index.js.map
{
"name": "@commercelayer/js-auth",
"version": "5.1.0",
"version": "5.2.0",
"description": "Commerce Layer Javascript Auth",

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

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