@commercelayer/js-auth
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
33701
9
0
254
2
128