Comparing version 0.9.5 to 1.0.0-beta1
@@ -1,2 +0,2 @@ | ||
import { AxiosRequestConfig } from "axios"; | ||
import { InternalAxiosRequestConfig } from "axios"; | ||
export interface Response { | ||
@@ -18,3 +18,3 @@ access_token: string; | ||
} | ||
export declare function Authentication(baseUrl: string, provider: CredentialsProvider): (req: AxiosRequestConfig) => Promise<AxiosRequestConfig>; | ||
export declare function Authentication(baseUrl: string, provider: CredentialsProvider): (req: InternalAxiosRequestConfig<any>) => Promise<InternalAxiosRequestConfig<any>>; | ||
/** | ||
@@ -21,0 +21,0 @@ * A Credentials provider is a function which promises client credentials |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,10 +30,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EnvCredentials = exports.ConstantCredentials = exports.Authentication = exports.TokenType = exports.GrantType = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const axios_1 = __importStar(require("axios")); | ||
const user_agent_1 = require("./user_agent"); | ||
const qs_1 = __importDefault(require("qs")); | ||
var GrantType; | ||
@@ -33,12 +48,13 @@ (function (GrantType) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
req.headers || (req.headers = new axios_1.AxiosHeaders()); | ||
// If we have a token that we know isn't expired, use it to make the request. | ||
if (token && tokenExpires && tokenExpires > new Date()) { | ||
req.headers.Authorization = `bearer ${token}`; | ||
req.headers.Authorization = `Bearer ${token}`; | ||
return req; | ||
} | ||
const credentials = yield provider(); | ||
const body = { | ||
client_id: credentials.clientId, | ||
client_secret: credentials.clientSecret, | ||
grant_type: GrantType.CLIENT_CREDENTIALS | ||
}; | ||
const body = new URLSearchParams(); | ||
body.append('client_id', credentials.clientId); | ||
body.append('client_secret', credentials.clientSecret); | ||
body.append('grant_type', GrantType.CLIENT_CREDENTIALS); | ||
const params = {}; | ||
@@ -49,8 +65,7 @@ params.responseType = 'json'; | ||
params.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
params.transformRequest = qs_1.default.stringify; | ||
// Perform the token request in the global Axios instance to avoid interceptor recursion | ||
const rsp = yield axios_1.default.post(baseUrl + '/auth/web/connect/token', body, params); | ||
const rsp = yield axios_1.default.post(baseUrl + '/security/users/authenticate', body, params); | ||
token = rsp.data.access_token; | ||
tokenExpires = new Date(new Date().getTime() + rsp.data.expires_in * 1000); | ||
req.headers.Authorization = `bearer ${token}`; | ||
req.headers.Authorization = `Bearer ${token}`; | ||
return req; | ||
@@ -57,0 +72,0 @@ }); |
import { Cache, Customers, Notes, Payments, Reservations, Tasks, Tours } from './models'; | ||
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; | ||
import * as Auth from './auth'; | ||
@@ -53,3 +53,3 @@ export * as Auth from './auth'; | ||
*/ | ||
onRequest(func: (value: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>): number; | ||
onRequest<T>(func: (value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>): number; | ||
/** | ||
@@ -56,0 +56,0 @@ * Add a new intercepter for responses |
@@ -42,4 +42,4 @@ "use strict"; | ||
this.axios.defaults.responseType = 'json'; | ||
this.axios.defaults.paramsSerializer = JSON.stringify; | ||
this.axios.defaults.headers = { | ||
//this.axios.defaults.paramsSerializer = JSON.stringify | ||
this.axios.defaults.headers.common = { | ||
'User-Agent': user_agent_1.USER_AGENT, | ||
@@ -46,0 +46,0 @@ 'Content-Type': 'application/json', |
{ | ||
"name": "tigerbay", | ||
"version": "0.9.5", | ||
"version": "1.0.0-beta1", | ||
"description": "API Client library for TigerBay", | ||
@@ -31,3 +31,3 @@ "main": "lib/client.js", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"axios": "^1.6.0", | ||
"qs": "^6.9.4" | ||
@@ -34,0 +34,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
82527
2047
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.21.4(transitive)
Updatedaxios@^1.6.0