lhisp-oauth-client 1.0.21 → 1.0.24
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
|
@@ -22,7 +22,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
22
22
|
protected tokenCreatedAt: number;
|
|
23
23
|
protected tokenExpiresIn: number;
|
|
24
24
|
protected sendAuthCredentialsOnRequestBody?: boolean;
|
|
25
|
-
protected
|
|
25
|
+
protected formatAccessToken?: (accessToken?: iAccessToken) => string;
|
|
26
26
|
constructor(params: LhispOauthClientConstructorParams);
|
|
27
27
|
getAuthHeaderValue(): string;
|
|
28
28
|
parseData({ data, contentType }: {
|
|
@@ -33,10 +33,10 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
33
33
|
getAccessToken(): Promise<iAccessToken>;
|
|
34
34
|
buildAccessToken(data: any): iAccessToken;
|
|
35
35
|
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>(
|
|
36
|
+
executarRequest<ResponseType>({ method, path, data, params, contentType, ...opt }: ExecutarRequestParams): Promise<ResponseType>;
|
|
37
|
+
get<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
38
|
+
put<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
39
|
+
patch<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
40
|
+
post<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
41
|
+
delete<ResponseType>(opt: ExecutarRequestParams): Promise<ResponseType>;
|
|
42
42
|
}
|
|
@@ -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
|
};
|
|
@@ -46,6 +57,7 @@ class LhispOauthClient {
|
|
|
46
57
|
this.authHeaderName = params.authHeaderName || lhisp_oauth_client_t_1.defaultAuthHeaderName;
|
|
47
58
|
this.tokenHeaderName = params.tokenHeaderName || lhisp_oauth_client_t_1.defaultTokenHeaderName;
|
|
48
59
|
this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody;
|
|
60
|
+
this.formatAccessToken = params.formatAccessToken;
|
|
49
61
|
}
|
|
50
62
|
getAuthHeaderValue() {
|
|
51
63
|
return `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`).toString("base64")}`;
|
|
@@ -118,25 +130,21 @@ class LhispOauthClient {
|
|
|
118
130
|
return data;
|
|
119
131
|
}
|
|
120
132
|
getAuthToken() {
|
|
121
|
-
var _a, _b
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return `${
|
|
133
|
+
var _a, _b;
|
|
134
|
+
if (this.formatAccessToken) {
|
|
135
|
+
return this.formatAccessToken(this.accessToken);
|
|
136
|
+
}
|
|
137
|
+
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}`;
|
|
126
138
|
}
|
|
127
|
-
executarRequest(
|
|
139
|
+
executarRequest(_a) {
|
|
140
|
+
var { method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON } = _a, opt = __rest(_a, ["method", "path", "data", "params", "contentType"]);
|
|
128
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
142
|
try {
|
|
130
143
|
yield this.getAccessToken();
|
|
131
144
|
const headers = Object.assign({ "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken() }, (this.headers || {}));
|
|
132
|
-
const response = yield axios_1.default.request({
|
|
133
|
-
method,
|
|
134
|
-
url: `${this.apiUrl}${path}`,
|
|
135
|
-
httpsAgent: this.agent,
|
|
136
|
-
headers,
|
|
145
|
+
const response = yield axios_1.default.request(Object.assign({ method, url: `${this.apiUrl}${path}`, httpsAgent: this.agent, headers,
|
|
137
146
|
data,
|
|
138
|
-
params,
|
|
139
|
-
});
|
|
147
|
+
params }, opt));
|
|
140
148
|
return response.data;
|
|
141
149
|
}
|
|
142
150
|
catch (error) {
|
|
@@ -153,53 +161,29 @@ class LhispOauthClient {
|
|
|
153
161
|
}
|
|
154
162
|
});
|
|
155
163
|
}
|
|
156
|
-
get(
|
|
164
|
+
get(opt) {
|
|
157
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
return this.executarRequest({
|
|
159
|
-
method: "GET",
|
|
160
|
-
path,
|
|
161
|
-
contentType,
|
|
162
|
-
params,
|
|
163
|
-
});
|
|
166
|
+
return this.executarRequest(Object.assign({ method: "GET" }, opt));
|
|
164
167
|
});
|
|
165
168
|
}
|
|
166
|
-
put(
|
|
169
|
+
put(opt) {
|
|
167
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
return this.executarRequest({
|
|
169
|
-
method: "PUT",
|
|
170
|
-
path,
|
|
171
|
-
data,
|
|
172
|
-
contentType,
|
|
173
|
-
});
|
|
171
|
+
return this.executarRequest(Object.assign({ method: "PUT" }, opt));
|
|
174
172
|
});
|
|
175
173
|
}
|
|
176
|
-
patch(
|
|
174
|
+
patch(opt) {
|
|
177
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
return this.executarRequest({
|
|
179
|
-
method: "PATCH",
|
|
180
|
-
path,
|
|
181
|
-
data,
|
|
182
|
-
contentType,
|
|
183
|
-
});
|
|
176
|
+
return this.executarRequest(Object.assign({ method: "PATCH" }, opt));
|
|
184
177
|
});
|
|
185
178
|
}
|
|
186
|
-
post(
|
|
179
|
+
post(opt) {
|
|
187
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
return this.executarRequest({
|
|
189
|
-
method: "POST",
|
|
190
|
-
path,
|
|
191
|
-
data,
|
|
192
|
-
contentType,
|
|
193
|
-
});
|
|
181
|
+
return this.executarRequest(Object.assign({ method: "POST" }, opt));
|
|
194
182
|
});
|
|
195
183
|
}
|
|
196
|
-
delete(
|
|
184
|
+
delete(opt) {
|
|
197
185
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
return this.executarRequest({
|
|
199
|
-
method: "DELETE",
|
|
200
|
-
path,
|
|
201
|
-
contentType,
|
|
202
|
-
});
|
|
186
|
+
return this.executarRequest(Object.assign({ method: "DELETE" }, opt));
|
|
203
187
|
});
|
|
204
188
|
}
|
|
205
189
|
}
|
|
@@ -17,7 +17,7 @@ export interface LhispOauthClientConstructorParams {
|
|
|
17
17
|
grantType?: string;
|
|
18
18
|
authContentType?: ContentType;
|
|
19
19
|
sendAuthCredentialsOnRequestBody?: boolean;
|
|
20
|
-
|
|
20
|
+
formatAccessToken?: (accessToken?: AccessToken) => string;
|
|
21
21
|
debug?: boolean;
|
|
22
22
|
}
|
|
23
23
|
export interface ExecutarRequestParams extends AxiosRequestConfig {
|