lhisp-oauth-client 1.0.34 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lhisp-oauth-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"main": "src/index",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"axios": "^1.10.0",
|
|
26
|
-
"lhisp-logger": "^
|
|
26
|
+
"lhisp-logger": "^2.2.2"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import https from "https";
|
|
2
1
|
import { AxiosHeaders } from "axios";
|
|
2
|
+
import https from "https";
|
|
3
3
|
import { AccessToken, ContentType, ExecutarRequestParams, LhispOauthClientConstructorParams } from "./lhisp-oauth-client.t";
|
|
4
4
|
export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|
5
5
|
protected authUrl: string;
|
|
@@ -34,7 +34,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
34
34
|
getAccessToken(): Promise<iAccessToken>;
|
|
35
35
|
buildAccessToken(data: any): iAccessToken;
|
|
36
36
|
getAuthToken(): string;
|
|
37
|
-
executarRequest<ResponseType>({ method, path, data, params, contentType, headers, ...opt }: ExecutarRequestParams): Promise<ResponseType>;
|
|
37
|
+
executarRequest<ResponseType>({ method, path, data, params, contentType, headers: paramsHeaders, ...opt }: ExecutarRequestParams): Promise<ResponseType>;
|
|
38
38
|
get<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
39
39
|
put<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
40
40
|
patch<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
@@ -24,11 +24,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.LhispOauthClient = void 0;
|
|
27
|
-
const querystring_1 = __importDefault(require("querystring"));
|
|
28
|
-
const https_1 = __importDefault(require("https"));
|
|
29
27
|
const axios_1 = __importDefault(require("axios"));
|
|
30
|
-
const
|
|
28
|
+
const https_1 = __importDefault(require("https"));
|
|
31
29
|
const lhisp_logger_1 = __importDefault(require("lhisp-logger"));
|
|
30
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
31
|
+
const lhisp_oauth_client_t_1 = require("./lhisp-oauth-client.t");
|
|
32
|
+
const logger = (0, lhisp_logger_1.default)({ name: "lhisp-oauth-client" });
|
|
32
33
|
class LhispOauthClient {
|
|
33
34
|
constructor(params) {
|
|
34
35
|
this.authData = {};
|
|
@@ -118,7 +119,7 @@ class LhispOauthClient {
|
|
|
118
119
|
});
|
|
119
120
|
const resp = yield axios_1.default.request(authRequestOpt);
|
|
120
121
|
if (!(resp === null || resp === void 0 ? void 0 : resp.data)) {
|
|
121
|
-
|
|
122
|
+
logger.error({ message: "LhispOauthClient.getAccessToken", resp });
|
|
122
123
|
throw new Error("Resposta inválida ao obter token de acesso.");
|
|
123
124
|
}
|
|
124
125
|
this.accessToken = this.buildAccessToken(resp.data);
|
|
@@ -127,7 +128,7 @@ class LhispOauthClient {
|
|
|
127
128
|
return this.accessToken;
|
|
128
129
|
}
|
|
129
130
|
catch (error) {
|
|
130
|
-
|
|
131
|
+
logger.error({ message: "LhispOauthClient.getAccessToken", error });
|
|
131
132
|
throw error;
|
|
132
133
|
}
|
|
133
134
|
});
|
|
@@ -147,16 +148,17 @@ class LhispOauthClient {
|
|
|
147
148
|
}
|
|
148
149
|
executarRequest(_a) {
|
|
149
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
var { method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, headers } = _a, opt = __rest(_a, ["method", "path", "data", "params", "contentType", "headers"]);
|
|
151
|
+
var { method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, headers: paramsHeaders } = _a, opt = __rest(_a, ["method", "path", "data", "params", "contentType", "headers"]);
|
|
151
152
|
try {
|
|
152
153
|
yield this.getAccessToken();
|
|
153
|
-
const
|
|
154
|
-
const response = yield axios_1.default.request(Object.assign(Object.assign({}, opt), { method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers
|
|
154
|
+
const headers = Object.assign(Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {})), (paramsHeaders || {}));
|
|
155
|
+
const response = yield axios_1.default.request(Object.assign(Object.assign({}, opt), { method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers,
|
|
156
|
+
data,
|
|
155
157
|
params, timeout: this.timeout }));
|
|
156
158
|
return response.data;
|
|
157
159
|
}
|
|
158
160
|
catch (error) {
|
|
159
|
-
|
|
161
|
+
logger.error({
|
|
160
162
|
message: "LhispOauthClient.executarRequest",
|
|
161
163
|
method,
|
|
162
164
|
url: `${this.apiUrl}${path}`,
|