lhisp-oauth-client 1.0.16 → 1.0.21

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.16",
3
+ "version": "1.0.21",
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.2",
16
- "@types/node": "^20.3.1",
17
- "jest": "^29.5.0",
18
- "ts-jest": "^29.1.0",
19
- "typescript": "^5.1.3"
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.4.0",
23
- "lhisp-logger": "^1.0.11"
22
+ "axios": "^1.6.1",
23
+ "lhisp-logger": "^1.0.14"
24
24
  }
25
25
  }
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import https from "https";
4
+ import { AxiosHeaders } from "axios";
3
5
  import { AccessToken, ContentType, ExecutarRequestParams, LhispOauthClientConstructorParams } from "./lhisp-oauth-client.t";
4
6
  export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
5
7
  protected authUrl: string;
@@ -9,10 +11,10 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
9
11
  protected authHeaderName: string;
10
12
  protected tokenHeaderName: string;
11
13
  protected authContentType: ContentType;
12
- protected certificado?: string;
14
+ protected certificado?: string | Buffer;
13
15
  protected senhaCertificado?: string;
14
16
  protected authScope?: string;
15
- protected headers?: Headers;
17
+ protected headers?: AxiosHeaders;
16
18
  protected grantType?: string;
17
19
  protected agent: https.Agent;
18
20
  protected accessToken?: iAccessToken;
@@ -20,6 +22,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
20
22
  protected tokenCreatedAt: number;
21
23
  protected tokenExpiresIn: number;
22
24
  protected sendAuthCredentialsOnRequestBody?: boolean;
25
+ protected forceTokenTypeToCamelCase?: boolean;
23
26
  constructor(params: LhispOauthClientConstructorParams);
24
27
  getAuthHeaderValue(): string;
25
28
  parseData({ data, contentType }: {
@@ -24,7 +24,7 @@ class LhispOauthClient {
24
24
  this.tokenExpiresIn = 0;
25
25
  if (params.certificado) {
26
26
  this.agent = new https_1.default.Agent({
27
- pfx: params.certificado,
27
+ pfx: Buffer.isBuffer(params.certificado) ? params.certificado : Buffer.from(params.certificado, "base64"),
28
28
  passphrase: params.senhaCertificado,
29
29
  rejectUnauthorized: false,
30
30
  });
@@ -118,17 +118,17 @@ class LhispOauthClient {
118
118
  return data;
119
119
  }
120
120
  getAuthToken() {
121
- var _a, _b;
122
- 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}`;
121
+ var _a, _b, _c, _d, _e, _f, _g;
122
+ const tokenType = this.forceTokenTypeToCamelCase
123
+ ? `${(_c = (_b = (_a = this.accessToken) === null || _a === void 0 ? void 0 : _a.token_type) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.toUpperCase()}${(_e = (_d = this.accessToken) === null || _d === void 0 ? void 0 : _d.token_type) === null || _e === void 0 ? void 0 : _e.substring(1)}`
124
+ : (_f = this.accessToken) === null || _f === void 0 ? void 0 : _f.token_type;
125
+ return `${tokenType} ${(_g = this.accessToken) === null || _g === void 0 ? void 0 : _g.access_token}`;
123
126
  }
124
127
  executarRequest({ method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, }) {
125
128
  return __awaiter(this, void 0, void 0, function* () {
126
129
  try {
127
130
  yield this.getAccessToken();
128
- let headers = {
129
- "Content-Type": contentType,
130
- [this.tokenHeaderName]: this.getAuthToken(),
131
- };
131
+ const headers = Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {}));
132
132
  const response = yield axios_1.default.request({
133
133
  method,
134
134
  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
+ forceTokenTypeToCamelCase?: boolean;
19
21
  debug?: boolean;
20
22
  }
21
23
  export interface ExecutarRequestParams extends AxiosRequestConfig {