@dnv-plant/typescriptpws 1.0.97 → 1.0.98
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/materials.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/materials.sbn.
|
|
12
12
|
***********************************************************************/
|
|
13
13
|
|
|
14
14
|
import { getRequest, postRequest, putRequest, getMaterialsApiTarget, getClientAliasId } from './utilities';
|
|
@@ -29,8 +29,8 @@ export class MaterialInfo {
|
|
|
29
29
|
* @param {string} name - The name of the material.
|
|
30
30
|
*/
|
|
31
31
|
constructor(
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
readonly id: string,
|
|
33
|
+
readonly name: string,
|
|
34
34
|
) {}
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -43,9 +43,9 @@ export class MaterialCasIdInfo {
|
|
|
43
43
|
* @param {number} casId - The CAS ID of the material.
|
|
44
44
|
*/
|
|
45
45
|
constructor(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
readonly id: string,
|
|
47
|
+
readonly name: string,
|
|
48
|
+
readonly casId: number,
|
|
49
49
|
) {}
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -53,10 +53,10 @@ export class MaterialInfoSchema {
|
|
|
53
53
|
schema: Joi.ObjectSchema;
|
|
54
54
|
|
|
55
55
|
constructor() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
this.schema = Joi.object({
|
|
57
|
+
id: Joi.string().guid({ version: 'uuidv4' }).required(),
|
|
58
|
+
displayName: Joi.string().required(),
|
|
59
|
+
}).unknown(true);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
@@ -66,11 +66,11 @@ export class MaterialInfoSchema {
|
|
|
66
66
|
* @throws Error if validation fails.
|
|
67
67
|
*/
|
|
68
68
|
makeMaterialInfo(data: { id: string; displayName: string }): MaterialInfo {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const { error, value } = this.schema.validate(data);
|
|
70
|
+
if (error) {
|
|
71
|
+
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
72
|
+
}
|
|
73
|
+
return new MaterialInfo(value.id, value.displayName);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -78,11 +78,11 @@ export class MaterialCasIdInfoSchema {
|
|
|
78
78
|
schema: Joi.ObjectSchema;
|
|
79
79
|
|
|
80
80
|
constructor() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
this.schema = Joi.object({
|
|
82
|
+
id: Joi.string().guid({ version: 'uuidv4' }).required(),
|
|
83
|
+
name: Joi.string().required(),
|
|
84
|
+
casId: Joi.number().required(),
|
|
85
|
+
}).unknown(true);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
@@ -92,11 +92,11 @@ export class MaterialCasIdInfoSchema {
|
|
|
92
92
|
* @throws Error if validation fails.
|
|
93
93
|
*/
|
|
94
94
|
makeMaterialInfo(data: { id: string; name: string; casId: number }): MaterialCasIdInfo {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
const { error, value } = this.schema.validate(data);
|
|
96
|
+
if (error) {
|
|
97
|
+
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
98
|
+
}
|
|
99
|
+
return new MaterialCasIdInfo(value.id, value.name, value.casId);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -109,9 +109,9 @@ export class MaterialEntityDescriptor {
|
|
|
109
109
|
* @param {number} casId - The CAS ID of the material.
|
|
110
110
|
*/
|
|
111
111
|
constructor(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
readonly id: string,
|
|
113
|
+
readonly name: string,
|
|
114
|
+
readonly casId: number,
|
|
115
115
|
) {}
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -119,13 +119,13 @@ export class MaterialEntityDescriptorSchema {
|
|
|
119
119
|
schema: Joi.ObjectSchema;
|
|
120
120
|
|
|
121
121
|
constructor() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
this.schema = Joi.object({
|
|
123
|
+
id: Joi.string().guid({ version: 'uuidv4' }).required(),
|
|
124
|
+
displayName: Joi.string().required(),
|
|
125
|
+
extendedProperties: Joi.object({
|
|
126
|
+
casId: Joi.number().required(),
|
|
127
|
+
}).required(),
|
|
128
|
+
}).unknown(true);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/** Validates and transforms data into a MaterialEntityDescriptor object.
|
|
@@ -134,19 +134,19 @@ export class MaterialEntityDescriptorSchema {
|
|
|
134
134
|
* @throws Error if validation fails.
|
|
135
135
|
*/
|
|
136
136
|
makeMaterialInfo(data: { id: string; displayName: string; extendedProperties: { casId: number } }): MaterialEntityDescriptor {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
const { error, value } = this.schema.validate(data);
|
|
138
|
+
if (error) {
|
|
139
|
+
throw new Error(`Validation error: ${error.details[0].message}`);
|
|
140
|
+
}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
// Add the cas_id to the data dictionary.
|
|
143
|
+
value.cas_id = value.extendedProperties.casId;
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
// Remove the extended_properties from the data dictionary.
|
|
146
|
+
delete value.extendedProperties;
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
// Return a new instance of the MaterialEntityDescriptor class.
|
|
149
|
+
return new MaterialEntityDescriptor(value.id, value.displayName, value.cas_id);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -158,12 +158,12 @@ async function getDataFromUrl<T>(url: string, schemaClass: SchemaClass, many: bo
|
|
|
158
158
|
|
|
159
159
|
// Validate the data
|
|
160
160
|
const { error, value } = validationSchema.validate(data, {
|
|
161
|
-
|
|
161
|
+
abortEarly: false,
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
if (error) {
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
const errorMessages = error.details.map((e: { message: any }) => e.message).join(', ');
|
|
166
|
+
throw new Error(`Error retrieving data: ${errorMessages}`);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
return value;
|
|
@@ -171,46 +171,46 @@ async function getDataFromUrl<T>(url: string, schemaClass: SchemaClass, many: bo
|
|
|
171
171
|
|
|
172
172
|
export async function getAllCasIds(controller?: AbortController): Promise<MaterialCasIdInfo[]> {
|
|
173
173
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
// Generate the URL
|
|
175
|
+
const apiTarget = getMaterialsApiTarget();
|
|
176
|
+
const clientAliasId = getClientAliasId();
|
|
177
|
+
const url = `${apiTarget}cas?clientId=${clientAliasId}`;
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
// Fetch and validate the data
|
|
180
|
+
return getDataFromUrl(url, new MaterialCasIdInfoSchema(), true, controller) as Promise<MaterialCasIdInfo[]>;
|
|
181
181
|
} catch (error: unknown) {
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
183
|
+
throw new Error(`Error retrieving CAS IDs: ${errorMessage}`);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
export async function getMaterialByCasId(casId: number, controller?: AbortController): Promise<Material[]> {
|
|
188
188
|
try {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
// Generate the URL
|
|
190
|
+
const apiTarget = getMaterialsApiTarget();
|
|
191
|
+
const clientAliasId = getClientAliasId();
|
|
192
|
+
const url = `${apiTarget}cas/${casId}?clientId=${clientAliasId}`;
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
// Fetch and validate the data
|
|
195
|
+
return getDataFromUrl(url, new MaterialSchema(), true, controller) as Promise<Material[]>;
|
|
196
196
|
} catch (error: unknown) {
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
198
|
+
throw new Error(`Error retrieving material with CAS ID ${casId}: ${errorMessage}`);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
export async function getComponents(source: number, controller?: AbortController): Promise<MaterialComponentData[]> {
|
|
203
203
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
// Generate the URL
|
|
205
|
+
const apiTarget = getMaterialsApiTarget();
|
|
206
|
+
const clientAliasId = getClientAliasId();
|
|
207
|
+
const url = `${apiTarget}components?clientId=${clientAliasId}&sources=${source}`;
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
// Fetch and validate the data
|
|
210
|
+
return getDataFromUrl(url, new MaterialEntityDescriptorSchema(), true, controller) as Promise<MaterialComponentData[]>;
|
|
211
211
|
} catch (error: unknown) {
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
213
|
+
throw new Error(`Error retrieving components: ${errorMessage}`);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -228,46 +228,46 @@ export async function getUserComponents(controller?: AbortController): Promise<M
|
|
|
228
228
|
|
|
229
229
|
export async function getComponentById(id: string, controller?: AbortController): Promise<MaterialComponentData> {
|
|
230
230
|
try {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
// Generate the URL
|
|
232
|
+
const apiTarget = getMaterialsApiTarget();
|
|
233
|
+
const clientAliasId = getClientAliasId();
|
|
234
|
+
const url = `${apiTarget}components/id=${id}?clientId=${clientAliasId}`;
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
// Fetch and validate the data
|
|
237
|
+
return getDataFromUrl(url, new MaterialComponentDataSchema(), false, controller) as Promise<MaterialComponentData>;
|
|
238
238
|
} catch (error: unknown) {
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
240
|
+
throw new Error(`Error retrieving component with ID ${id}: ${errorMessage}`);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
export async function getComponentByName(name: string, controller?: AbortController): Promise<MaterialComponentData> {
|
|
245
245
|
try {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
// Generate the URL
|
|
247
|
+
const apiTarget = getMaterialsApiTarget();
|
|
248
|
+
const clientAliasId = getClientAliasId();
|
|
249
|
+
const url = `${apiTarget}components/name=${encodeURIComponent(name)}?clientId=${clientAliasId}`;
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
// Fetch and validate the data
|
|
252
|
+
return getDataFromUrl(url, new MaterialComponentDataSchema(), false, controller) as Promise<MaterialComponentData>;
|
|
253
253
|
} catch (error: unknown) {
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
255
|
+
throw new Error(`Error retrieving component with name ${name}: ${errorMessage}`);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
export async function getComponentByCasId(casId: number, controller?: AbortController): Promise<MaterialComponentData> {
|
|
260
260
|
try {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
// Generate the URL
|
|
262
|
+
const apiTarget = getMaterialsApiTarget();
|
|
263
|
+
const clientAliasId = getClientAliasId();
|
|
264
|
+
const url = `${apiTarget}components/casid=${encodeURIComponent(casId)}?clientId=${clientAliasId}`;
|
|
265
265
|
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
// Fetch and validate the data
|
|
267
|
+
return getDataFromUrl(url, new MaterialComponentDataSchema(), false, controller) as Promise<MaterialComponentData>;
|
|
268
268
|
} catch (error: unknown) {
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
270
|
+
throw new Error(`Error retrieving component with CAS ID ${casId}: ${errorMessage}`);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -275,25 +275,25 @@ export async function storeDataAndGetResponse<T>(url: string, data: any, schemaC
|
|
|
275
275
|
// Serialize the data using the schema
|
|
276
276
|
const { error: reqErr, value: payload } = schemaClass.schema.validate(data);
|
|
277
277
|
if (reqErr) {
|
|
278
|
-
|
|
278
|
+
throw new Error(`Validation error (request): ${reqErr.details[0].message}`);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
const { status: postStatus, headers } = await postRequest(url, JSON.stringify(payload), controller);
|
|
282
282
|
|
|
283
283
|
if (postStatus !== 201) {
|
|
284
|
-
|
|
284
|
+
throw new Error(`Expected 201 from POST, got ${postStatus}`);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
const location = headers.location ?? headers.Location; // header name can vary
|
|
288
288
|
if (!location) {
|
|
289
|
-
|
|
289
|
+
throw new Error('POST succeeded but no Location header returned');
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
const { data: fetched } = await getRequest(location, controller);
|
|
293
293
|
|
|
294
294
|
const { error: respErr, value: parsed } = schemaClass.schema.validate(fetched);
|
|
295
295
|
if (respErr) {
|
|
296
|
-
|
|
296
|
+
throw new Error(`Validation error (response): ${respErr.details[0].message}`);
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
return parsed as T;
|
|
@@ -301,31 +301,31 @@ export async function storeDataAndGetResponse<T>(url: string, data: any, schemaC
|
|
|
301
301
|
|
|
302
302
|
export async function storeMaterialComponentData(materialComponentData: MaterialComponentData, controller?: AbortController): Promise<MaterialComponentData> {
|
|
303
303
|
try {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
// Generate the URL
|
|
305
|
+
const apiTarget = getMaterialsApiTarget();
|
|
306
|
+
const clientAliasId = getClientAliasId();
|
|
307
|
+
const url = `${apiTarget}components?clientId=${clientAliasId}`;
|
|
308
308
|
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
// Store the data and return the response
|
|
310
|
+
return storeDataAndGetResponse(url, materialComponentData, new MaterialComponentDataSchema(), controller);
|
|
311
311
|
} catch (error: unknown) {
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
313
|
+
throw new Error(`Error storing material component data: ${errorMessage}`);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
export async function storeMaterialComponentAndCreateMaterial(materialComponentData: MaterialComponentData, controller?: AbortController): Promise<Material> {
|
|
318
318
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
// Generate the URL
|
|
320
|
+
const apiTarget = getMaterialsApiTarget();
|
|
321
|
+
const clientAliasId = getClientAliasId();
|
|
322
|
+
const url = `${apiTarget}components/material?clientId=${clientAliasId}`;
|
|
323
323
|
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
// Store the data and return the response
|
|
325
|
+
return storeDataAndGetResponse(url, materialComponentData, new MaterialSchema(), controller);
|
|
326
326
|
} catch (error: unknown) {
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
328
|
+
throw new Error(`Error storing material component and creating material: ${errorMessage}`);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
@@ -335,67 +335,67 @@ export async function updateMaterialComponent(data: MaterialComponentData, contr
|
|
|
335
335
|
|
|
336
336
|
// Check if the response status is 204 (no content)
|
|
337
337
|
if (status !== 204) {
|
|
338
|
-
|
|
338
|
+
throw new Error(`Failed to update material component: ${status} ${statusText}`);
|
|
339
339
|
}
|
|
340
340
|
return true;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
export async function getMaterials(controller?: AbortController): Promise<Material[]> {
|
|
344
344
|
try {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
// Generate the URL
|
|
346
|
+
const apiTarget = getMaterialsApiTarget();
|
|
347
|
+
const clientAliasId = getClientAliasId();
|
|
348
|
+
const url = `${apiTarget}materials?clientId=${clientAliasId}`;
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
// Fetch and validate the data
|
|
351
|
+
return getDataFromUrl(url, new MaterialSchema(), true, controller) as Promise<Material[]>;
|
|
352
352
|
} catch (error: unknown) {
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
354
|
+
throw new Error(`Error retrieving materials: ${errorMessage}`);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
export async function getMaterialById(id: string, controller?: AbortController): Promise<Material> {
|
|
359
359
|
try {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
360
|
+
// Generate the URL
|
|
361
|
+
const apiTarget = getMaterialsApiTarget();
|
|
362
|
+
const clientAliasId = getClientAliasId();
|
|
363
|
+
const url = `${apiTarget}materials/id=${id}?clientId=${clientAliasId}`;
|
|
364
364
|
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
// Fetch and validate the data
|
|
366
|
+
return getDataFromUrl(url, new MaterialSchema(), false, controller) as Promise<Material>;
|
|
367
367
|
} catch (error: unknown) {
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
369
|
+
throw new Error(`Error retrieving material with ID ${id}: ${errorMessage}`);
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
export async function getMaterialByName(name: string, controller?: AbortController): Promise<Material> {
|
|
374
374
|
try {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
// Generate the URL
|
|
376
|
+
const apiTarget = getMaterialsApiTarget();
|
|
377
|
+
const clientAliasId = getClientAliasId();
|
|
378
|
+
const url = `${apiTarget}materials/name=${name}?clientId=${clientAliasId}`;
|
|
379
379
|
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
// Fetch and validate the data
|
|
381
|
+
return getDataFromUrl(url, new MaterialSchema(), false, controller) as Promise<Material>;
|
|
382
382
|
} catch (error: unknown) {
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
384
|
+
throw new Error(`Error retrieving material with name ${name}: ${errorMessage}`);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
export async function getMaterialNames(controller?: AbortController) {
|
|
389
389
|
try {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
390
|
+
// Generate the URL
|
|
391
|
+
const apiTarget = getMaterialsApiTarget();
|
|
392
|
+
const clientAliasId = getClientAliasId();
|
|
393
|
+
const url = `${apiTarget}materials/descriptors?clientId=${clientAliasId}`;
|
|
394
394
|
|
|
395
|
-
|
|
396
|
-
|
|
395
|
+
// Fetch and validate the data
|
|
396
|
+
return getDataFromUrl(url, new MaterialInfoSchema(), true, controller) as Promise<MaterialInfo[]>;
|
|
397
397
|
} catch (error: unknown) {
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
399
|
+
throw new Error(`Error retrieving material names: ${errorMessage}`);
|
|
400
400
|
}
|
|
401
|
-
}
|
|
401
|
+
}
|