@dnv-plant/typescriptpws 1.0.97 → 1.0.98-alpha.2397542
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/LICENSE +1 -1
- package/azure-test-job.yml +25 -0
- package/index.ts +18 -13
- package/package.json +2 -1
- package/src/calculations/applicationTools.ts +16 -12
- package/src/calculations/calculationBase.ts +40 -13
- package/src/calculations/discharge.ts +752 -109
- package/src/calculations/dispersion.ts +17 -15
- package/src/calculations/dispersionView.ts +31 -27
- package/src/calculations/fireball.ts +17 -13
- package/src/calculations/flammableWorkflow.ts +291 -0
- package/src/calculations/jetFire.ts +19 -22
- package/src/calculations/lateExplosion.ts +16 -12
- package/src/calculations/linkedRunners.ts +2715 -780
- package/src/calculations/poolFire.ts +16 -12
- package/src/calculations/properties.ts +17 -14
- package/src/calculations/radiation.ts +65 -61
- package/src/calculations/standalones.ts +16 -12
- package/src/calculations/toxics.ts +17 -13
- package/src/calculations/utilities.ts +673 -23
- package/src/constants.ts +25 -15
- package/src/entities.ts +455 -320
- package/src/entity-schemas.ts +284 -148
- package/src/enums.ts +123 -64
- package/src/materials.ts +152 -152
- package/src/utilities.ts +40 -27
package/src/utilities.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* Editing it may lead to inconsistent results and limit DNV's ability to provide support.
|
|
7
7
|
* Please contact DNV if you believe changes are required.
|
|
8
8
|
*
|
|
9
|
-
* Version: 1.0.
|
|
10
|
-
* Date/time:
|
|
11
|
-
* Template:
|
|
9
|
+
* Version: 1.0.0
|
|
10
|
+
* Date/time: 23 Jun 2026 12:11:11
|
|
11
|
+
* Template: TYPE_SCRIPT_PWS/utilities.sbn.
|
|
12
12
|
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
import jwt from 'jsonwebtoken';
|
|
@@ -18,10 +18,12 @@ import { REST_API_URI, PWS_CLIENT_ID, REST_API_VERSION } from './constants';
|
|
|
18
18
|
|
|
19
19
|
const accessTokenKey = '__pwsAccessToken';
|
|
20
20
|
const usedInDnvKey = '__pwsUsedInDnvKey';
|
|
21
|
+
const isAnalytics2Key = '__pwsIsAnalytics2';
|
|
21
22
|
const clientAliasKey = '__pwsClientAliasId';
|
|
22
23
|
|
|
23
24
|
(globalThis as any)[accessTokenKey] = (globalThis as any)[accessTokenKey] ?? '';
|
|
24
25
|
(globalThis as any)[usedInDnvKey] = (globalThis as any)[usedInDnvKey] ?? false;
|
|
26
|
+
(globalThis as any)[isAnalytics2Key] = (globalThis as any)[isAnalytics2Key] ?? false;
|
|
25
27
|
(globalThis as any)[clientAliasKey] = (globalThis as any)[clientAliasKey] ?? PWS_CLIENT_ID;
|
|
26
28
|
|
|
27
29
|
export function getAccessToken(): string {
|
|
@@ -42,6 +44,16 @@ export function setUsedInDnvProduct(value: boolean) {
|
|
|
42
44
|
(globalThis as any)[usedInDnvKey] = value;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
// For DNV use only
|
|
48
|
+
function isAnalytics2(): boolean {
|
|
49
|
+
return (globalThis as any)[isAnalytics2Key];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// For DNV use only
|
|
53
|
+
export function setAnalytics2(value: boolean) {
|
|
54
|
+
(globalThis as any)[isAnalytics2Key] = value;
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
// Get client alias ID
|
|
46
58
|
export function getClientAliasId() {
|
|
47
59
|
return (globalThis as any)[clientAliasKey];
|
|
@@ -55,8 +67,8 @@ export function setClientAliasId(clientAliasId: string) {
|
|
|
55
67
|
// Get headers for requests
|
|
56
68
|
function getHeaders(accessToken: string) {
|
|
57
69
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
Authorization: `Bearer ${accessToken}`,
|
|
60
72
|
};
|
|
61
73
|
}
|
|
62
74
|
|
|
@@ -66,17 +78,17 @@ const axiosInstance = axios.create({});
|
|
|
66
78
|
export async function postRequest<T>(url: string, data: string, controller?: AbortController): Promise<AxiosResponse<T>> {
|
|
67
79
|
const accessToken = getAccessToken();
|
|
68
80
|
if (!accessToken) {
|
|
69
|
-
|
|
81
|
+
throw new Error('Access token not found');
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
73
85
|
if (hasExpired) {
|
|
74
|
-
|
|
86
|
+
throw new Error(`Expired access token (${expiryDate})`);
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
const response = await axiosInstance.post<T>(url, data, {
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
headers: getHeaders(accessToken),
|
|
91
|
+
signal: controller?.signal,
|
|
80
92
|
});
|
|
81
93
|
return response;
|
|
82
94
|
}
|
|
@@ -85,17 +97,17 @@ export async function postRequest<T>(url: string, data: string, controller?: Abo
|
|
|
85
97
|
export async function putRequest<T>(url: string, data: string, controller?: AbortController): Promise<AxiosResponse<T>> {
|
|
86
98
|
const accessToken = getAccessToken();
|
|
87
99
|
if (!accessToken) {
|
|
88
|
-
|
|
100
|
+
throw new Error('Access token not found');
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
92
104
|
if (hasExpired) {
|
|
93
|
-
|
|
105
|
+
throw new Error(`Expired access token (${expiryDate})`);
|
|
94
106
|
}
|
|
95
107
|
|
|
96
108
|
const response = await axiosInstance.put<T>(url, data, {
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
headers: getHeaders(accessToken),
|
|
110
|
+
signal: controller?.signal,
|
|
99
111
|
});
|
|
100
112
|
return response;
|
|
101
113
|
}
|
|
@@ -104,18 +116,18 @@ export async function putRequest<T>(url: string, data: string, controller?: Abor
|
|
|
104
116
|
export async function getRequest<T>(url: string, controller?: AbortController): Promise<AxiosResponse<T>> {
|
|
105
117
|
const accessToken = getAccessToken();
|
|
106
118
|
if (!accessToken) {
|
|
107
|
-
|
|
119
|
+
throw new Error('Access token not found');
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
const [, expiryDate, hasExpired] = getAccessTokenInfo(accessToken);
|
|
111
123
|
if (hasExpired) {
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
console.log(`Your access token has expired: ${expiryDate}`);
|
|
125
|
+
throw new Error('Expired access token');
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
const response = await axiosInstance.get<T>(url, {
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
headers: getHeaders(accessToken),
|
|
130
|
+
signal: controller?.signal,
|
|
119
131
|
});
|
|
120
132
|
return response;
|
|
121
133
|
}
|
|
@@ -126,14 +138,14 @@ function getAccessTokenInfo(accessToken: string): [string, string, boolean] {
|
|
|
126
138
|
|
|
127
139
|
// Ensure the token is valid and contains the expected properties
|
|
128
140
|
if (!decoded || typeof decoded !== 'object' || !('exp' in decoded)) {
|
|
129
|
-
|
|
141
|
+
throw new Error('Invalid or malformed token');
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
const exp = decoded.exp as number;
|
|
133
145
|
const aud = decoded.aud as string | undefined;
|
|
134
146
|
|
|
135
147
|
if (typeof exp !== 'number') {
|
|
136
|
-
|
|
148
|
+
throw new Error('Token does not have a valid expiration time');
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
const platform = aud || 'unknown';
|
|
@@ -150,16 +162,16 @@ function getApiRoot() {
|
|
|
150
162
|
const isDnvProduct = isUsedInDnvProduct();
|
|
151
163
|
|
|
152
164
|
if (isDnvProduct) {
|
|
153
|
-
|
|
165
|
+
return '/api/';
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
if (accessToken) {
|
|
157
|
-
|
|
169
|
+
const [platform] = getAccessTokenInfo(accessToken);
|
|
158
170
|
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
// Determine API root based on devMode
|
|
172
|
+
const apiTarget = devMode ? '/api/' : `${platform}/api/`;
|
|
161
173
|
|
|
162
|
-
|
|
174
|
+
return apiTarget;
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
return REST_API_URI;
|
|
@@ -172,7 +184,8 @@ function getApiVersion() {
|
|
|
172
184
|
|
|
173
185
|
// Get analytics API target URL
|
|
174
186
|
export function getAnalyticsApiTarget() {
|
|
175
|
-
|
|
187
|
+
const analyticsName = isAnalytics2() ? 'analytics2' : 'analytics';
|
|
188
|
+
return `${getApiRoot()}${analyticsName}/v${getApiVersion()}/`;
|
|
176
189
|
}
|
|
177
190
|
|
|
178
191
|
// Get materials API target URL
|
|
@@ -188,4 +201,4 @@ export function convertSnakeCaseToCamelCase(snakeStr: string) {
|
|
|
188
201
|
// Convert camelCase to snake_case
|
|
189
202
|
export function convertCamelCaseToSnakeCase(camelStr: string) {
|
|
190
203
|
return camelStr.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
191
|
-
}
|
|
204
|
+
}
|