lhisp-oauth-client 1.0.17 → 1.0.23
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.23",
|
|
4
4
|
"main": "src/index",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"test:watch": "jest --watchAll"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@types/jest": "^29.5.
|
|
16
|
-
"@types/node": "^20.
|
|
17
|
-
"jest": "^29.
|
|
18
|
-
"ts-jest": "^29.1.
|
|
19
|
-
"typescript": "^5.
|
|
15
|
+
"@types/jest": "^29.5.8",
|
|
16
|
+
"@types/node": "^20.9.0",
|
|
17
|
+
"jest": "^29.7.0",
|
|
18
|
+
"ts-jest": "^29.1.1",
|
|
19
|
+
"typescript": "^5.2.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"axios": "^1.
|
|
23
|
-
"lhisp-logger": "^1.0.
|
|
22
|
+
"axios": "^1.6.1",
|
|
23
|
+
"lhisp-logger": "^1.0.14"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import https from "https";
|
|
4
|
+
import { AxiosHeaders } from "axios";
|
|
4
5
|
import { AccessToken, ContentType, ExecutarRequestParams, LhispOauthClientConstructorParams } from "./lhisp-oauth-client.t";
|
|
5
6
|
export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
|
|
6
7
|
protected authUrl: string;
|
|
@@ -13,7 +14,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
13
14
|
protected certificado?: string | Buffer;
|
|
14
15
|
protected senhaCertificado?: string;
|
|
15
16
|
protected authScope?: string;
|
|
16
|
-
protected headers?:
|
|
17
|
+
protected headers?: AxiosHeaders;
|
|
17
18
|
protected grantType?: string;
|
|
18
19
|
protected agent: https.Agent;
|
|
19
20
|
protected accessToken?: iAccessToken;
|
|
@@ -21,6 +22,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
21
22
|
protected tokenCreatedAt: number;
|
|
22
23
|
protected tokenExpiresIn: number;
|
|
23
24
|
protected sendAuthCredentialsOnRequestBody?: boolean;
|
|
25
|
+
protected formatAccessToken?: (accessToken?: iAccessToken) => string;
|
|
24
26
|
constructor(params: LhispOauthClientConstructorParams);
|
|
25
27
|
getAuthHeaderValue(): string;
|
|
26
28
|
parseData({ data, contentType }: {
|
|
@@ -46,6 +46,7 @@ class LhispOauthClient {
|
|
|
46
46
|
this.authHeaderName = params.authHeaderName || lhisp_oauth_client_t_1.defaultAuthHeaderName;
|
|
47
47
|
this.tokenHeaderName = params.tokenHeaderName || lhisp_oauth_client_t_1.defaultTokenHeaderName;
|
|
48
48
|
this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody;
|
|
49
|
+
this.formatAccessToken = params.formatAccessToken;
|
|
49
50
|
}
|
|
50
51
|
getAuthHeaderValue() {
|
|
51
52
|
return `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`).toString("base64")}`;
|
|
@@ -119,16 +120,16 @@ class LhispOauthClient {
|
|
|
119
120
|
}
|
|
120
121
|
getAuthToken() {
|
|
121
122
|
var _a, _b;
|
|
123
|
+
if (this.formatAccessToken) {
|
|
124
|
+
return this.formatAccessToken(this.accessToken);
|
|
125
|
+
}
|
|
122
126
|
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}`;
|
|
123
127
|
}
|
|
124
128
|
executarRequest({ method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, }) {
|
|
125
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
130
|
try {
|
|
127
131
|
yield this.getAccessToken();
|
|
128
|
-
|
|
129
|
-
"Content-Type": contentType,
|
|
130
|
-
[this.tokenHeaderName]: this.getAuthToken(),
|
|
131
|
-
};
|
|
132
|
+
const headers = Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {}));
|
|
132
133
|
const response = yield axios_1.default.request({
|
|
133
134
|
method,
|
|
134
135
|
url: `${this.apiUrl}${path}`,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { AxiosRequestConfig } from "axios";
|
|
2
3
|
export interface Headers {
|
|
3
4
|
[name: string]: any;
|
|
@@ -7,7 +8,7 @@ export interface LhispOauthClientConstructorParams {
|
|
|
7
8
|
apiUrl: string;
|
|
8
9
|
clientId: string;
|
|
9
10
|
clientSecret: string;
|
|
10
|
-
certificado?: string;
|
|
11
|
+
certificado?: string | Buffer;
|
|
11
12
|
senhaCertificado?: string;
|
|
12
13
|
authScope?: string;
|
|
13
14
|
authHeaderName?: string;
|
|
@@ -16,6 +17,7 @@ export interface LhispOauthClientConstructorParams {
|
|
|
16
17
|
grantType?: string;
|
|
17
18
|
authContentType?: ContentType;
|
|
18
19
|
sendAuthCredentialsOnRequestBody?: boolean;
|
|
20
|
+
formatAccessToken?: (accessToken?: AccessToken) => string;
|
|
19
21
|
debug?: boolean;
|
|
20
22
|
}
|
|
21
23
|
export interface ExecutarRequestParams extends AxiosRequestConfig {
|