lhisp-oauth-client 1.0.32 → 1.0.34
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
|
@@ -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, ...opt }: ExecutarRequestParams): Promise<ResponseType>;
|
|
37
|
+
executarRequest<ResponseType>({ method, path, data, params, contentType, headers, ...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>;
|
|
@@ -140,17 +140,19 @@ class LhispOauthClient {
|
|
|
140
140
|
if (this.formatAccessToken) {
|
|
141
141
|
return this.formatAccessToken(this.accessToken);
|
|
142
142
|
}
|
|
143
|
+
if (!this.accessToken) {
|
|
144
|
+
throw new Error("Access Token não disponível.");
|
|
145
|
+
}
|
|
143
146
|
return `${(_a = this.accessToken) === null || _a === void 0 ? void 0 : _a.token_type} ${(_b = this.accessToken) === null || _b === void 0 ? void 0 : _b.access_token}`;
|
|
144
147
|
}
|
|
145
148
|
executarRequest(_a) {
|
|
146
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
var { method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON } = _a, opt = __rest(_a, ["method", "path", "data", "params", "contentType"]);
|
|
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"]);
|
|
148
151
|
try {
|
|
149
152
|
yield this.getAccessToken();
|
|
150
|
-
const
|
|
151
|
-
const response = yield axios_1.default.request(Object.assign({ method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers,
|
|
152
|
-
|
|
153
|
-
params, timeout: this.timeout }, opt));
|
|
153
|
+
const actualHeaders = Object.assign(Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {})), (headers || {}));
|
|
154
|
+
const response = yield axios_1.default.request(Object.assign(Object.assign({}, opt), { method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers: actualHeaders, data,
|
|
155
|
+
params, timeout: this.timeout }));
|
|
154
156
|
return response.data;
|
|
155
157
|
}
|
|
156
158
|
catch (error) {
|