@sp-api-sdk/auth
Advanced tools
Comparing version 1.8.3 to 1.8.4
@@ -5,3 +5,3 @@ { | ||
"description": "Amazon Selling Partner API authentication helper class", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"main": "dist/cjs/index.js", | ||
@@ -31,3 +31,3 @@ "module": "dist/es/index.js", | ||
"got": "^11.8.2", | ||
"type-fest": "^1.3.0" | ||
"type-fest": "^2.0.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "repository": { |
@@ -8,2 +8,3 @@ "use strict"; | ||
this.name = 'AccessTokenError'; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
this.meta = meta; | ||
@@ -10,0 +11,0 @@ } |
@@ -5,3 +5,3 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const got_1 = tslib_1.__importDefault(require("got")); | ||
const got_1 = tslib_1.__importStar(require("got")); | ||
const error_1 = require("./error"); | ||
@@ -25,3 +25,3 @@ tslib_1.__exportStar(require("./error"), exports); | ||
client_id: this.clientId, | ||
client_secret: this.clientSecret | ||
client_secret: this.clientSecret, | ||
}; | ||
@@ -38,3 +38,3 @@ if (this.refreshToken) { | ||
this.value = await got_1.default.post('https://api.amazon.com/auth/o2/token', { | ||
json: body | ||
json: body, | ||
}).json(); | ||
@@ -48,6 +48,6 @@ if (!this.value) { | ||
catch (error) { | ||
const accessTokenError = error.response ? | ||
new error_1.AccessTokenError(`HTTP Response code ${error.response.statusCode}`, JSON.parse(error.response.body)) : | ||
new error_1.AccessTokenError('Unknown Error'); | ||
throw accessTokenError; | ||
if (error instanceof got_1.RequestError && error.response) { | ||
throw new error_1.AccessTokenError(`HTTP Response code ${error.response.statusCode}`, JSON.parse(error.response.body)); | ||
} | ||
throw new error_1.AccessTokenError('Unknown Error'); | ||
} | ||
@@ -54,0 +54,0 @@ } |
@@ -20,4 +20,4 @@ "use strict"; | ||
async getCredentials() { | ||
if (!this._credentials || | ||
(this._credentials?.Expiration && Date.now() >= this._credentials.Expiration.getTime())) { | ||
if (!this._credentials | ||
|| (this._credentials?.Expiration && Date.now() >= this._credentials.Expiration.getTime())) { | ||
this._credentials = await this.fetchCredentials(); | ||
@@ -35,4 +35,4 @@ } | ||
secretAccessKey: this.secretAccessKey, | ||
sessionToken: this.sessionToken | ||
} | ||
sessionToken: this.sessionToken, | ||
}, | ||
}; | ||
@@ -45,3 +45,3 @@ if (this.region) { | ||
RoleArn: this.role.arn, | ||
RoleSessionName: this.role.sessionName | ||
RoleSessionName: this.role.sessionName, | ||
})); | ||
@@ -48,0 +48,0 @@ if (!credentials) { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const process_1 = tslib_1.__importDefault(require("process")); | ||
const package_json_1 = tslib_1.__importDefault(require("../package.json")); | ||
@@ -16,10 +17,10 @@ const access_token_1 = require("./access-token"); | ||
constructor(parameters) { | ||
const clientId = parameters.clientId || process.env.LWA_CLIENT_ID; | ||
const clientSecret = parameters.clientSecret || process.env.LWA_CLIENT_SECRET; | ||
const accessKeyId = parameters.accessKeyId || process.env.AWS_ACCESS_KEY_ID; | ||
const secretAccessKey = parameters.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY; | ||
const sessionToken = parameters.sessionToken || process.env.AWS_SESSION_TOKEN; | ||
const region = parameters.region || process.env.AWS_DEFAULT_REGION; | ||
const roleArn = parameters.role?.arn || process.env.AWS_ROLE_ARN; | ||
const roleSessionName = parameters.role?.sessionName || process.env.AWS_ROLE_SESSION_NAME || `${package_json_1.default.name.replace('/', '-')}@${package_json_1.default.version}`; | ||
const clientId = parameters.clientId || process_1.default.env.LWA_CLIENT_ID; | ||
const clientSecret = parameters.clientSecret || process_1.default.env.LWA_CLIENT_SECRET; | ||
const accessKeyId = parameters.accessKeyId || process_1.default.env.AWS_ACCESS_KEY_ID; | ||
const secretAccessKey = parameters.secretAccessKey || process_1.default.env.AWS_SECRET_ACCESS_KEY; | ||
const sessionToken = parameters.sessionToken || process_1.default.env.AWS_SESSION_TOKEN; | ||
const region = parameters.region || process_1.default.env.AWS_DEFAULT_REGION; | ||
const roleArn = parameters.role?.arn || process_1.default.env.AWS_ROLE_ARN; | ||
const roleSessionName = parameters.role?.sessionName || process_1.default.env.AWS_ROLE_SESSION_NAME || `${package_json_1.default.name.replace('/', '-')}@${package_json_1.default.version}`; | ||
let role = null; | ||
@@ -29,3 +30,3 @@ if (roleArn) { | ||
arn: roleArn, | ||
sessionName: roleSessionName | ||
sessionName: roleSessionName, | ||
}; | ||
@@ -52,3 +53,3 @@ } | ||
clientSecret, | ||
refreshToken: parameters.refreshToken | ||
refreshToken: parameters.refreshToken, | ||
}); | ||
@@ -60,3 +61,3 @@ } | ||
clientSecret, | ||
scopes: parameters.scopes | ||
scopes: parameters.scopes, | ||
}); | ||
@@ -73,3 +74,3 @@ } | ||
region, | ||
role | ||
role, | ||
}); | ||
@@ -88,3 +89,3 @@ } | ||
SecretAccessKey: this._secretAccessKey, | ||
SessionToken: this._sessionToken | ||
SessionToken: this._sessionToken, | ||
}; | ||
@@ -91,0 +92,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Amazon Selling Partner API authentication helper class", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"main": "dist/cjs/index.js", | ||
@@ -31,3 +31,3 @@ "module": "dist/es/index.js", | ||
"got": "^11.8.2", | ||
"type-fest": "^1.3.0" | ||
"type-fest": "^2.0.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "repository": { |
@@ -5,4 +5,5 @@ export class AccessTokenError extends Error { | ||
this.name = 'AccessTokenError'; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
this.meta = meta; | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import got from 'got'; | ||
import got, { RequestError } from 'got'; | ||
import { AccessTokenError } from './error'; | ||
@@ -20,3 +20,3 @@ export * from './error'; | ||
client_id: this.clientId, | ||
client_secret: this.clientSecret | ||
client_secret: this.clientSecret, | ||
}; | ||
@@ -33,3 +33,3 @@ if (this.refreshToken) { | ||
this.value = await got.post('https://api.amazon.com/auth/o2/token', { | ||
json: body | ||
json: body, | ||
}).json(); | ||
@@ -43,6 +43,6 @@ if (!this.value) { | ||
catch (error) { | ||
const accessTokenError = error.response ? | ||
new AccessTokenError(`HTTP Response code ${error.response.statusCode}`, JSON.parse(error.response.body)) : | ||
new AccessTokenError('Unknown Error'); | ||
throw accessTokenError; | ||
if (error instanceof RequestError && error.response) { | ||
throw new AccessTokenError(`HTTP Response code ${error.response.statusCode}`, JSON.parse(error.response.body)); | ||
} | ||
throw new AccessTokenError('Unknown Error'); | ||
} | ||
@@ -49,0 +49,0 @@ } |
@@ -16,4 +16,4 @@ import { STSClient, AssumeRoleCommand } from '@aws-sdk/client-sts'; | ||
async getCredentials() { | ||
if (!this._credentials || | ||
(this._credentials?.Expiration && Date.now() >= this._credentials.Expiration.getTime())) { | ||
if (!this._credentials | ||
|| (this._credentials?.Expiration && Date.now() >= this._credentials.Expiration.getTime())) { | ||
this._credentials = await this.fetchCredentials(); | ||
@@ -31,4 +31,4 @@ } | ||
secretAccessKey: this.secretAccessKey, | ||
sessionToken: this.sessionToken | ||
} | ||
sessionToken: this.sessionToken, | ||
}, | ||
}; | ||
@@ -41,3 +41,3 @@ if (this.region) { | ||
RoleArn: this.role.arn, | ||
RoleSessionName: this.role.sessionName | ||
RoleSessionName: this.role.sessionName, | ||
})); | ||
@@ -44,0 +44,0 @@ if (!credentials) { |
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | ||
import process from 'process'; | ||
import pkg from '../package.json'; | ||
@@ -23,3 +24,3 @@ import { AccessToken } from './access-token'; | ||
arn: roleArn, | ||
sessionName: roleSessionName | ||
sessionName: roleSessionName, | ||
}; | ||
@@ -46,3 +47,3 @@ } | ||
clientSecret, | ||
refreshToken: parameters.refreshToken | ||
refreshToken: parameters.refreshToken, | ||
}); | ||
@@ -54,3 +55,3 @@ } | ||
clientSecret, | ||
scopes: parameters.scopes | ||
scopes: parameters.scopes, | ||
}); | ||
@@ -67,3 +68,3 @@ } | ||
region, | ||
role | ||
role, | ||
}); | ||
@@ -82,5 +83,5 @@ } | ||
SecretAccessKey: this._secretAccessKey, | ||
SessionToken: this._sessionToken | ||
SessionToken: this._sessionToken, | ||
}; | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { RequireExactlyOne } from 'type-fest'; | ||
import type { RequireExactlyOne } from 'type-fest'; | ||
export * from './error'; | ||
@@ -3,0 +3,0 @@ export declare enum AuthorizationScope { |
@@ -1,2 +0,2 @@ | ||
import { Credentials } from '@aws-sdk/client-sts'; | ||
import type { Credentials } from '@aws-sdk/client-sts'; | ||
export * from './error'; | ||
@@ -3,0 +3,0 @@ interface Role { |
@@ -1,4 +0,5 @@ | ||
import { Credentials } from '@aws-sdk/client-sts'; | ||
import { RequireExactlyOne, SetOptional } from 'type-fest'; | ||
import { AccessToken, AuthorizationScope } from './access-token'; | ||
import type { Credentials } from '@aws-sdk/client-sts'; | ||
import type { RequireExactlyOne, SetOptional } from 'type-fest'; | ||
import { AccessToken } from './access-token'; | ||
import type { AuthorizationScope } from './access-token'; | ||
export interface SellingPartnerAuthParameters { | ||
@@ -5,0 +6,0 @@ clientId?: string; |
@@ -5,3 +5,3 @@ { | ||
"description": "Amazon Selling Partner API authentication helper class", | ||
"version": "1.8.3", | ||
"version": "1.8.4", | ||
"main": "dist/cjs/index.js", | ||
@@ -31,3 +31,3 @@ "module": "dist/es/index.js", | ||
"got": "^11.8.2", | ||
"type-fest": "^1.3.0" | ||
"type-fest": "^2.0.0" | ||
}, | ||
@@ -53,3 +53,3 @@ "repository": { | ||
], | ||
"gitHead": "11aebd49b53f06d4f96cf15c62d0b90365660e13" | ||
"gitHead": "3b2a61e225ed988547320fae35f085582caf67e4" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126573
534
8
+ Addedtype-fest@2.19.0(transitive)
- Removedtype-fest@1.4.0(transitive)
Updatedtype-fest@^2.0.0