@commercelayer/js-auth
Advanced tools
Comparing version 4.2.2 to 4.3.0
import { type TReturn, type GrantType, type TOptions } from './types/index'; | ||
export declare function authentication<G extends GrantType>(grantType: G, { domain, slug, ...options }: TOptions<G>): Promise<TReturn<G>>; | ||
export declare function authentication<G extends GrantType>(grantType: G, { domain, slug, headers, ...options }: TOptions<G>): Promise<TReturn<G>>; | ||
export default authentication; | ||
@@ -4,0 +4,0 @@ export { provisioning } from './provisioning'; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.core=exports.provisioning=exports.authentication=void 0;const tslib_1=require("tslib"),camelCaseToSnake_1=require("./utils/camelCaseToSnake"),snakeToCamelCase_1=require("./utils/snakeToCamelCase");function authentication(grantType,_a){var{domain="commercelayer.io",slug}=_a,options=tslib_1.__rest(_a,["domain","slug"]);return tslib_1.__awaiter(this,void 0,void 0,function*(){const attributes=Object.assign({grant_type:grantType},options),body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=(0,camelCaseToSnake_1.camelCaseToSnake)(key);return acc[camelKey]=attributes[key],acc},{});return yield fetch(`https://${slug}.${domain}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(body)}).then(response=>tslib_1.__awaiter(this,void 0,void 0,function*(){const json=yield response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=(0,snakeToCamelCase_1.snakeToCamelCase)(key);return acc[camelKey]=json[key],acc},{})}))})}exports.authentication=authentication,exports.default=authentication;var provisioning_1=require("./provisioning");Object.defineProperty(exports,"provisioning",{enumerable:!0,get:function(){return provisioning_1.provisioning}}),exports.core={authentication}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.core=exports.provisioning=exports.authentication=void 0;const tslib_1=require("tslib"),camelCaseToSnake_1=require("./utils/camelCaseToSnake"),snakeToCamelCase_1=require("./utils/snakeToCamelCase");function authentication(grantType,_a){var{domain="commercelayer.io",slug,headers}=_a,options=tslib_1.__rest(_a,["domain","slug","headers"]);return tslib_1.__awaiter(this,void 0,void 0,function*(){const attributes=Object.assign({grant_type:grantType},options),body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=(0,camelCaseToSnake_1.camelCaseToSnake)(key);return acc[camelKey]=attributes[key],acc},{});return yield fetch(`https://${slug}.${domain}/oauth/token`,{method:"POST",headers:Object.assign({"Content-Type":"application/json",Accept:"application/json"},headers),body:JSON.stringify(body)}).then(response=>tslib_1.__awaiter(this,void 0,void 0,function*(){const json=yield response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=(0,snakeToCamelCase_1.snakeToCamelCase)(key);return acc[camelKey]=json[key],acc},{})}))})}exports.authentication=authentication,exports.default=authentication;var provisioning_1=require("./provisioning");Object.defineProperty(exports,"provisioning",{enumerable:!0,get:function(){return provisioning_1.provisioning}}),exports.core={authentication}; |
@@ -10,3 +10,3 @@ import type { TClientCredentials } from './types/clientCredentials'; | ||
} | ||
declare function authentication({ domain, ...options }: TProvisioningOptions): Promise<TProvisioningReturn>; | ||
declare function authentication({ domain, headers, ...options }: TProvisioningOptions): Promise<TProvisioningReturn>; | ||
export declare const provisioning: { | ||
@@ -13,0 +13,0 @@ authentication: typeof authentication; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.provisioning=void 0;const tslib_1=require("tslib"),camelCaseToSnake_1=require("./utils/camelCaseToSnake"),snakeToCamelCase_1=require("./utils/snakeToCamelCase");function authentication(_a){var{domain="commercelayer.io"}=_a,options=tslib_1.__rest(_a,["domain"]);return tslib_1.__awaiter(this,void 0,void 0,function*(){const attributes=Object.assign({grant_type:"client_credentials",scope:"provisioning-api"},options),body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=(0,camelCaseToSnake_1.camelCaseToSnake)(key);return acc[camelKey]=attributes[key],acc},{});return yield fetch(`https://auth.${domain}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"},body:JSON.stringify(body)}).then(response=>tslib_1.__awaiter(this,void 0,void 0,function*(){const json=yield response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=(0,snakeToCamelCase_1.snakeToCamelCase)(key);return acc[camelKey]=json[key],acc},{})}))})}exports.provisioning={authentication}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.provisioning=void 0;const tslib_1=require("tslib"),camelCaseToSnake_1=require("./utils/camelCaseToSnake"),snakeToCamelCase_1=require("./utils/snakeToCamelCase");function authentication(_a){var{domain="commercelayer.io",headers}=_a,options=tslib_1.__rest(_a,["domain","headers"]);return tslib_1.__awaiter(this,void 0,void 0,function*(){const attributes=Object.assign({grant_type:"client_credentials",scope:"provisioning-api"},options),body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=(0,camelCaseToSnake_1.camelCaseToSnake)(key);return acc[camelKey]=attributes[key],acc},{});return yield fetch(`https://auth.${domain}/oauth/token`,{method:"POST",headers:Object.assign({"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"},headers),body:JSON.stringify(body)}).then(response=>tslib_1.__awaiter(this,void 0,void 0,function*(){const json=yield response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=(0,snakeToCamelCase_1.snakeToCamelCase)(key);return acc[camelKey]=json[key],acc},{})}))})}exports.provisioning={authentication}; |
@@ -26,2 +26,6 @@ import { type TPasswordReturn, type TPassword } from './password'; | ||
domain?: string; | ||
/** | ||
* The request headers. | ||
*/ | ||
headers?: HeadersInit; | ||
} | ||
@@ -28,0 +32,0 @@ export type TOptions<TGrantType> = TGrantType extends 'password' ? TPassword : TGrantType extends 'refresh_token' ? TRefreshToken : TGrantType extends 'client_credentials' ? TClientCredentials : TGrantType extends 'authorization_code' ? TAuthorizationCode : never; |
import { type TReturn, type GrantType, type TOptions } from './types/index'; | ||
export declare function authentication<G extends GrantType>(grantType: G, { domain, slug, ...options }: TOptions<G>): Promise<TReturn<G>>; | ||
export declare function authentication<G extends GrantType>(grantType: G, { domain, slug, headers, ...options }: TOptions<G>): Promise<TReturn<G>>; | ||
export default authentication; | ||
@@ -4,0 +4,0 @@ export { provisioning } from './provisioning'; |
@@ -1,1 +0,1 @@ | ||
import{camelCaseToSnake}from"./utils/camelCaseToSnake";import{snakeToCamelCase}from"./utils/snakeToCamelCase";export async function authentication(grantType,{domain="commercelayer.io",slug,...options}){const attributes={grant_type:grantType,...options},body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=camelCaseToSnake(key);return acc[camelKey]=attributes[key],acc},{});return await fetch(`https://${slug}.${domain}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(body)}).then(async response=>{const json=await response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=snakeToCamelCase(key);return acc[camelKey]=json[key],acc},{})})}export default authentication;export{provisioning}from"./provisioning";export const core={authentication}; | ||
import{camelCaseToSnake}from"./utils/camelCaseToSnake";import{snakeToCamelCase}from"./utils/snakeToCamelCase";export async function authentication(grantType,{domain="commercelayer.io",slug,headers,...options}){const attributes={grant_type:grantType,...options},body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=camelCaseToSnake(key);return acc[camelKey]=attributes[key],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();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=snakeToCamelCase(key);return acc[camelKey]=json[key],acc},{})})}export default authentication;export{provisioning}from"./provisioning";export const core={authentication}; |
@@ -10,3 +10,3 @@ import type { TClientCredentials } from './types/clientCredentials'; | ||
} | ||
declare function authentication({ domain, ...options }: TProvisioningOptions): Promise<TProvisioningReturn>; | ||
declare function authentication({ domain, headers, ...options }: TProvisioningOptions): Promise<TProvisioningReturn>; | ||
export declare const provisioning: { | ||
@@ -13,0 +13,0 @@ authentication: typeof authentication; |
@@ -1,1 +0,1 @@ | ||
import{camelCaseToSnake}from"./utils/camelCaseToSnake";import{snakeToCamelCase}from"./utils/snakeToCamelCase";async function authentication({domain="commercelayer.io",...options}){const attributes={grant_type:"client_credentials",scope:"provisioning-api",...options},body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=camelCaseToSnake(key);return acc[camelKey]=attributes[key],acc},{});return await fetch(`https://auth.${domain}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/vnd.api+json",Accept:"application/vnd.api+json"},body:JSON.stringify(body)}).then(async response=>{const json=await response.json();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=snakeToCamelCase(key);return acc[camelKey]=json[key],acc},{})})}export const provisioning={authentication}; | ||
import{camelCaseToSnake}from"./utils/camelCaseToSnake";import{snakeToCamelCase}from"./utils/snakeToCamelCase";async function authentication({domain="commercelayer.io",headers,...options}){const attributes={grant_type:"client_credentials",scope:"provisioning-api",...options},body=Object.keys(attributes).reduce((acc,key)=>{const camelKey=camelCaseToSnake(key);return acc[camelKey]=attributes[key],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();return json.expires=new Date(Date.now()+json.expires_in*1e3),Object.keys(json).reduce((acc,key)=>{const camelKey=snakeToCamelCase(key);return acc[camelKey]=json[key],acc},{})})}export const provisioning={authentication}; |
@@ -26,2 +26,6 @@ import { type TPasswordReturn, type TPassword } from './password'; | ||
domain?: string; | ||
/** | ||
* The request headers. | ||
*/ | ||
headers?: HeadersInit; | ||
} | ||
@@ -28,0 +32,0 @@ export type TOptions<TGrantType> = TGrantType extends 'password' ? TPassword : TGrantType extends 'refresh_token' ? TRefreshToken : TGrantType extends 'client_credentials' ? TClientCredentials : TGrantType extends 'authorization_code' ? TAuthorizationCode : never; |
{ | ||
"name": "@commercelayer/js-auth", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "Commerce Layer Javascript Auth", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
19613
280