oip-common 0.2.1 → 0.3.1
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/assets/i18n/app-modules.en.json +23 -23
- package/assets/i18n/app-modules.ru.json +23 -23
- package/assets/i18n/en.json +11 -0
- package/assets/i18n/ru.json +11 -0
- package/assets/layout/_menu.scss +148 -159
- package/assets/oip-common.scss +6 -5
- package/fesm2022/oip-common.mjs +2026 -1275
- package/fesm2022/oip-common.mjs.map +1 -1
- package/index.d.ts +330 -300
- package/package.json +4 -1
- package/scripts/generate-api.mjs +3 -1
- package/templates/http-client.ejs +25 -13
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oip-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A template for cross-platform web applications based on sakai-ng and primeNG",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"oip",
|
|
8
8
|
"template"
|
|
9
9
|
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@fortawesome/fontawesome-free": "^7.2.0"
|
|
12
|
+
},
|
|
10
13
|
"author": "Igor Tyulyakov aka g101k",
|
|
11
14
|
"license": "MIT",
|
|
12
15
|
"repository": {
|
package/scripts/generate-api.mjs
CHANGED
|
@@ -8,6 +8,7 @@ const { apiConfig, generateResponses, config } = it;
|
|
|
8
8
|
import { LayoutService } from "../services/app.layout.service";
|
|
9
9
|
import { SecurityService } from "../services/security.service";
|
|
10
10
|
import { inject, Injectable } from "@angular/core";
|
|
11
|
+
import { firstValueFrom } from "rxjs";
|
|
11
12
|
|
|
12
13
|
export type QueryParamsType = Record<string | number, any>;
|
|
13
14
|
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
@@ -61,15 +62,13 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
61
62
|
protected securityService = inject(SecurityService);
|
|
62
63
|
protected layoutService = inject(LayoutService);
|
|
63
64
|
public baseUrl: string = "<%~ apiConfig.baseUrl %>";
|
|
64
|
-
private securityData: SecurityDataType | null = null;
|
|
65
65
|
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"] =
|
|
66
|
-
(
|
|
66
|
+
() => ({
|
|
67
67
|
headers: {
|
|
68
68
|
"Accept-language": this.layoutService.language()
|
|
69
69
|
? this.layoutService.language()
|
|
70
70
|
: 'en',
|
|
71
71
|
"X-Timezone": this.layoutService.timeZone(),
|
|
72
|
-
Authorization: `Bearer ${securityData}`,
|
|
73
72
|
},
|
|
74
73
|
});
|
|
75
74
|
|
|
@@ -83,13 +82,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
83
82
|
referrerPolicy: 'no-referrer',
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
constructor() {
|
|
87
|
-
this.securityService.getAccessToken().subscribe((token) => {
|
|
88
|
-
this.securityData = token;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
85
|
public setSecurityData = (data: SecurityDataType | null) => {
|
|
92
|
-
this.securityData = data;
|
|
93
86
|
}
|
|
94
87
|
|
|
95
88
|
protected encodeQueryParam(key: string, value: any) {
|
|
@@ -199,8 +192,9 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
199
192
|
<% } else { %>
|
|
200
193
|
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
|
|
201
194
|
<% } %>
|
|
202
|
-
const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) && this.securityWorker && await this.securityWorker(
|
|
203
|
-
const
|
|
195
|
+
const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) && this.securityWorker && await this.securityWorker(null)) || {};
|
|
196
|
+
const csrfParams = await this.getCsrfRequestParams(params.method, path);
|
|
197
|
+
const requestParams = this.mergeRequestParams(this.mergeRequestParams(params, secureParams), csrfParams);
|
|
204
198
|
const queryString = query && this.toQueryString(query);
|
|
205
199
|
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
|
206
200
|
let responseFormat = format || requestParams.format;
|
|
@@ -251,6 +245,24 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
251
245
|
<% } else { %>
|
|
252
246
|
return data;
|
|
253
247
|
<% } %>
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
private async getCsrfRequestParams(method: string | undefined, path: string): Promise<RequestParams> {
|
|
252
|
+
if (!method || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase())) {
|
|
253
|
+
return {};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (
|
|
257
|
+
path.includes("/api/security/create-auth-session") ||
|
|
258
|
+
path.includes("/api/security/get-auth-csrf-token")
|
|
259
|
+
) {
|
|
260
|
+
return {};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const csrfToken = await firstValueFrom(this.securityService.getCsrfToken());
|
|
264
|
+
return csrfToken?.token
|
|
265
|
+
? { headers: { [csrfToken.headerName]: csrfToken.token } }
|
|
266
|
+
: {};
|
|
267
|
+
}
|
|
256
268
|
}
|