lhisp-oauth-client 1.0.23 → 1.0.25
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
|
@@ -15,6 +15,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
15
15
|
protected senhaCertificado?: string;
|
|
16
16
|
protected authScope?: string;
|
|
17
17
|
protected headers?: AxiosHeaders;
|
|
18
|
+
protected authHeaders?: AxiosHeaders;
|
|
18
19
|
protected grantType?: string;
|
|
19
20
|
protected agent: https.Agent;
|
|
20
21
|
protected accessToken?: iAccessToken;
|
|
@@ -33,10 +34,10 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
33
34
|
getAccessToken(): Promise<iAccessToken>;
|
|
34
35
|
buildAccessToken(data: any): iAccessToken;
|
|
35
36
|
getAuthToken(): string;
|
|
36
|
-
executarRequest<ResponseType>({ method, path, data, params, contentType, }: ExecutarRequestParams): Promise<ResponseType>;
|
|
37
|
-
get<ResponseType>(
|
|
38
|
-
put<ResponseType>(
|
|
39
|
-
patch<ResponseType>(
|
|
40
|
-
post<ResponseType>(
|
|
41
|
-
delete<ResponseType>(
|
|
37
|
+
executarRequest<ResponseType>({ method, path, data, params, contentType, ...opt }: ExecutarRequestParams): Promise<ResponseType>;
|
|
38
|
+
get<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
39
|
+
put<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
40
|
+
patch<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
41
|
+
post<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
42
|
+
delete<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
42
43
|
}
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -36,6 +47,7 @@ class LhispOauthClient {
|
|
|
36
47
|
}
|
|
37
48
|
this.certificado = params.certificado;
|
|
38
49
|
this.headers = (params.headers ? params.headers : {});
|
|
50
|
+
this.authHeaders = (params.authHeaders ? params.authHeaders : {});
|
|
39
51
|
this.apiUrl = params.apiUrl;
|
|
40
52
|
this.authUrl = params.authUrl;
|
|
41
53
|
this.authScope = params.authScope;
|
|
@@ -83,10 +95,7 @@ class LhispOauthClient {
|
|
|
83
95
|
method: "POST",
|
|
84
96
|
url: this.authUrl,
|
|
85
97
|
httpsAgent: this.agent,
|
|
86
|
-
headers: {
|
|
87
|
-
[this.authHeaderName]: this.getAuthHeaderValue(),
|
|
88
|
-
"Content-Type": this.authContentType,
|
|
89
|
-
},
|
|
98
|
+
headers: Object.assign({ [this.authHeaderName]: this.getAuthHeaderValue(), "Content-Type": this.authContentType }, this.authHeaders),
|
|
90
99
|
data: {},
|
|
91
100
|
};
|
|
92
101
|
if (this.grantType)
|
|
@@ -125,19 +134,15 @@ class LhispOauthClient {
|
|
|
125
134
|
}
|
|
126
135
|
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}`;
|
|
127
136
|
}
|
|
128
|
-
executarRequest(
|
|
137
|
+
executarRequest(_a) {
|
|
138
|
+
var { method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON } = _a, opt = __rest(_a, ["method", "path", "data", "params", "contentType"]);
|
|
129
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
140
|
try {
|
|
131
141
|
yield this.getAccessToken();
|
|
132
142
|
const headers = Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {}));
|
|
133
|
-
const response = yield axios_1.default.request({
|
|
134
|
-
method,
|
|
135
|
-
url: `${this.apiUrl}${path}`,
|
|
136
|
-
httpsAgent: this.agent,
|
|
137
|
-
headers,
|
|
143
|
+
const response = yield axios_1.default.request(Object.assign({ method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers,
|
|
138
144
|
data,
|
|
139
|
-
params,
|
|
140
|
-
});
|
|
145
|
+
params }, opt));
|
|
141
146
|
return response.data;
|
|
142
147
|
}
|
|
143
148
|
catch (error) {
|
|
@@ -154,53 +159,29 @@ class LhispOauthClient {
|
|
|
154
159
|
}
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
|
-
get(
|
|
162
|
+
get(opt) {
|
|
158
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
return this.executarRequest({
|
|
160
|
-
method: "GET",
|
|
161
|
-
path,
|
|
162
|
-
contentType,
|
|
163
|
-
params,
|
|
164
|
-
});
|
|
164
|
+
return this.executarRequest(Object.assign({ method: "GET" }, opt));
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
put(
|
|
167
|
+
put(opt) {
|
|
168
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
return this.executarRequest({
|
|
170
|
-
method: "PUT",
|
|
171
|
-
path,
|
|
172
|
-
data,
|
|
173
|
-
contentType,
|
|
174
|
-
});
|
|
169
|
+
return this.executarRequest(Object.assign({ method: "PUT" }, opt));
|
|
175
170
|
});
|
|
176
171
|
}
|
|
177
|
-
patch(
|
|
172
|
+
patch(opt) {
|
|
178
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
return this.executarRequest({
|
|
180
|
-
method: "PATCH",
|
|
181
|
-
path,
|
|
182
|
-
data,
|
|
183
|
-
contentType,
|
|
184
|
-
});
|
|
174
|
+
return this.executarRequest(Object.assign({ method: "PATCH" }, opt));
|
|
185
175
|
});
|
|
186
176
|
}
|
|
187
|
-
post(
|
|
177
|
+
post(opt) {
|
|
188
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
return this.executarRequest({
|
|
190
|
-
method: "POST",
|
|
191
|
-
path,
|
|
192
|
-
data,
|
|
193
|
-
contentType,
|
|
194
|
-
});
|
|
179
|
+
return this.executarRequest(Object.assign({ method: "POST" }, opt));
|
|
195
180
|
});
|
|
196
181
|
}
|
|
197
|
-
delete(
|
|
182
|
+
delete(opt) {
|
|
198
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
return this.executarRequest({
|
|
200
|
-
method: "DELETE",
|
|
201
|
-
path,
|
|
202
|
-
contentType,
|
|
203
|
-
});
|
|
184
|
+
return this.executarRequest(Object.assign({ method: "DELETE" }, opt));
|
|
204
185
|
});
|
|
205
186
|
}
|
|
206
187
|
}
|