basyx-typescript-sdk 0.2.0 → 0.2.2

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.
@@ -4,405 +4,412 @@ import { convertApiAasToCoreAas, convertApiAssetInformationToCoreAssetInformatio
4
4
  import { createCustomClient } from '../lib/createAasRepoClient';
5
5
  export class AasRepositoryClient {
6
6
  /**
7
- * Returns all Asset Administration Shells
7
+ * Returns all Asset Administration Shells.
8
8
  *
9
- * @function getAllAssetAdministrationShells
10
- * @param {GetAllAssetAdministrationShellsOptions} options - Options object.
11
- * @param {string} options.baseUrl - The API base URL
12
- * @param {Headers} [options.headers] - Request headers
13
- * @param {string[]} [options.assetIds] - A list of specific Asset identifiers. Every single value asset identifier is a base64-url-encoded
14
- * @param {string} [options.idShort] - The Asset Administration Shell's IdShort
15
- * @param {number} [options.limit] - The maximum number of elements in the response array
16
- * @param {string} [options.cursor] - A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
17
- * @returns {Promise<GetAllAssetAdministrationShellsResponse>} Requested Asset Administration Shells
9
+ * @param options Object containing:
10
+ * - baseUrl: The API base URL
11
+ * - headers?: Optional Request headers
12
+ * - assetIds?: A list of asset identifiers
13
+ * - idShort?: The AAS's idShort
14
+ * - limit?: Max number of elements to return
15
+ * - cursor?: A paging cursor from previous responses
16
+ *
17
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
18
18
  */
19
- async getAllAssetAdministrationShells({ baseUrl, headers, assetIds, idShort, limit, cursor, }) {
19
+ async getAllAssetAdministrationShells(options) {
20
+ const { baseUrl, headers, assetIds, idShort, limit, cursor } = options;
20
21
  try {
21
22
  const client = createCustomClient(baseUrl, headers);
22
- const { data, error } = await AasRepository.getAllAssetAdministrationShells({
23
+ const encodedAssetIds = assetIds?.map((id) => base64Encode(JSON.stringify(id)));
24
+ const result = await AasRepository.getAllAssetAdministrationShells({
23
25
  client,
24
- query: { assetIds, idShort, limit, cursor },
26
+ query: { assetIds: encodedAssetIds, idShort, limit, cursor },
25
27
  });
26
- if (error) {
27
- console.error('Error from server:', error);
28
- throw new Error(JSON.stringify(error.messages));
28
+ if (result.error) {
29
+ return { success: false, error: result.error };
29
30
  }
30
- const shells = (data.result ?? []).map(convertApiAasToCoreAas);
31
+ const shells = (result.data.result ?? []).map(convertApiAasToCoreAas);
31
32
  return {
32
- pagedResult: data.paging_metadata,
33
- result: shells,
33
+ success: true,
34
+ data: {
35
+ pagedResult: result.data.paging_metadata,
36
+ result: shells,
37
+ },
34
38
  };
35
39
  }
36
- catch (error) {
37
- console.error('Error fetching Asset Administration Shells:', error);
38
- throw error;
40
+ catch (err) {
41
+ return {
42
+ success: false,
43
+ error: err instanceof Error ? err : new Error(String(err)),
44
+ };
39
45
  }
40
46
  }
41
47
  /**
42
- * Creates a new Asset Administration Shell
48
+ * Creates a new Asset Administration Shell.
49
+ *
50
+ * @param options Object containing:
51
+ * - baseUrl: The API base URL
52
+ * - assetAdministrationShell: The AAS to create
53
+ * - headers?: Optional request headers
43
54
  *
44
- * @function postAssetAdministrationShell
45
- * @param {PostAssetAdministrationShellOptions} options - Options object.
46
- * @param {string} options.baseUrl - The API base URL
47
- * @param {AssetAdministrationShell} options.assetAdministrationShell - Asset Administration Shell object
48
- * @param {Headers} [options.headers] - Request headers
49
- * @returns {Promise<AssetAdministrationShell>} Asset Administration Shell created successfully
55
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
50
56
  */
51
- async postAssetAdministrationShell({ baseUrl, assetAdministrationShell, headers, }) {
57
+ async postAssetAdministrationShell(options) {
58
+ const { baseUrl, assetAdministrationShell, headers } = options;
52
59
  try {
53
60
  const client = createCustomClient(baseUrl, headers);
54
- const { data, error } = await AasRepository.postAssetAdministrationShell({
61
+ const result = await AasRepository.postAssetAdministrationShell({
55
62
  client,
56
63
  body: convertCoreAasToApiAas(assetAdministrationShell),
57
64
  });
58
- if (error) {
59
- console.error('Error from server:', error);
60
- throw new Error(JSON.stringify(error.messages));
65
+ if (result.error) {
66
+ return { success: false, error: result.error };
61
67
  }
62
- return convertApiAasToCoreAas(data);
68
+ return { success: true, data: convertApiAasToCoreAas(result.data) };
63
69
  }
64
- catch (error) {
65
- console.error('Error creating Asset Administration Shell:', error);
66
- throw error;
70
+ catch (err) {
71
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
67
72
  }
68
73
  }
69
74
  /**
70
- * Deletes an Asset Administration Shell
75
+ * Deletes an Asset Administration Shell by its unique identifier.
76
+ *
77
+ * @param options Object containing:
78
+ * - baseUrl: The API base URL
79
+ * - aasIdentifier: The unique ID for the AAS
80
+ * - headers?: Optional request headers
71
81
  *
72
- * @function deleteAssetAdministrationShellById
73
- * @param {AasIdentifierOptions} options - Options object.
74
- * @param {string} options.baseUrl - The API base URL
75
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
76
- * @param {Headers} [options.headers] - Request headers
77
- * @returns {Promise<void>} Asset Administration Shell deleted successfully
82
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
78
83
  */
79
- async deleteAssetAdministrationShellById({ baseUrl, aasIdentifier, headers }) {
84
+ async deleteAssetAdministrationShellById(options) {
85
+ const { baseUrl, aasIdentifier, headers } = options;
80
86
  try {
81
87
  const client = createCustomClient(baseUrl, headers);
82
88
  const encodedAasIdentifier = base64Encode(aasIdentifier);
83
- const { error } = await AasRepository.deleteAssetAdministrationShellById({
89
+ const result = await AasRepository.deleteAssetAdministrationShellById({
84
90
  client,
85
91
  path: { aasIdentifier: encodedAasIdentifier },
86
92
  });
87
- if (error) {
88
- console.error('Error from server:', error);
89
- throw new Error(JSON.stringify(error.messages));
93
+ if (result.error) {
94
+ return { success: false, error: result.error };
90
95
  }
91
- return;
96
+ return { success: true, data: result.data };
92
97
  }
93
- catch (error) {
94
- console.error('Error deleting Asset Administration Shell:', error);
95
- throw error;
98
+ catch (err) {
99
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
96
100
  }
97
101
  }
98
102
  /**
99
- * Returns a specific Asset Administration Shell
103
+ * Returns a specific Asset Administration Shell by its unique identifier.
100
104
  *
101
- * @function getAssetAdministrationShellById
102
- * @param {AasIdentifierOptions} options - Options object.
103
- * @param {string} options.baseUrl - The API base URL
104
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
105
- * @param {Headers} [options.headers] - Request headers
106
- * @returns {Promise<AssetAdministrationShell>} Requested Asset Administration Shell
105
+ * @param options Object containing:
106
+ * - baseUrl: The API base URL
107
+ * - aasIdentifier: The unique ID
108
+ * - headers?: Optional request headers
109
+ *
110
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
107
111
  */
108
- async getAssetAdministrationShellById({ baseUrl, aasIdentifier, headers, }) {
112
+ async getAssetAdministrationShellById(options) {
113
+ const { baseUrl, aasIdentifier, headers } = options;
109
114
  try {
110
115
  const client = createCustomClient(baseUrl, headers);
111
116
  const encodedAasIdentifier = base64Encode(aasIdentifier);
112
- const { data, error } = await AasRepository.getAssetAdministrationShellById({
117
+ const result = await AasRepository.getAssetAdministrationShellById({
113
118
  client,
114
119
  path: { aasIdentifier: encodedAasIdentifier },
115
120
  });
116
- if (error) {
117
- console.error('Error from server:', error);
118
- throw new Error(JSON.stringify(error.messages));
121
+ if (result.error) {
122
+ // Return the complete error object with status code
123
+ return {
124
+ success: false,
125
+ error: result.error,
126
+ };
119
127
  }
120
- return convertApiAasToCoreAas(data);
128
+ return { success: true, data: convertApiAasToCoreAas(result.data) };
121
129
  }
122
- catch (error) {
123
- console.error('Error fetching Asset Administration Shell:', error);
124
- throw error;
130
+ catch (err) {
131
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
125
132
  }
126
133
  }
127
134
  /**
128
- * Updates an existing Asset Administration Shell
135
+ * Updates an existing Asset Administration Shell by ID (PUT).
136
+ *
137
+ * @param options Object containing:
138
+ * - baseUrl: The API base URL
139
+ * - aasIdentifier: The unique ID
140
+ * - assetAdministrationShell: The updated AAS object
141
+ * - headers?: Optional request headers
129
142
  *
130
- * @function putAssetAdministrationShellById
131
- * @param {PutAssetAdministrationShellOptions} options - Options object.
132
- * @param {string} options.baseUrl - The API base URL
133
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
134
- * @param {AssetAdministrationShell} options.assetAdministrationShell - Asset Administration Shell object
135
- * @param {Headers} [options.headers] - Request headers
136
- * @returns {Promise<void>} Asset Administration Shell updated successfully
143
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
137
144
  */
138
- async putAssetAdministrationShellById({ baseUrl, aasIdentifier, assetAdministrationShell, headers, }) {
145
+ async putAssetAdministrationShellById(options) {
146
+ const { baseUrl, aasIdentifier, assetAdministrationShell, headers } = options;
139
147
  try {
140
148
  const client = createCustomClient(baseUrl, headers);
141
149
  const encodedAasIdentifier = base64Encode(aasIdentifier);
142
- const { error } = await AasRepository.putAssetAdministrationShellById({
150
+ const result = await AasRepository.putAssetAdministrationShellById({
143
151
  client,
144
152
  path: { aasIdentifier: encodedAasIdentifier },
145
153
  body: convertCoreAasToApiAas(assetAdministrationShell),
146
154
  });
147
- if (error) {
148
- console.error('Error from server:', error);
149
- throw new Error(JSON.stringify(error.messages));
155
+ if (result.error) {
156
+ return { success: false, error: result.error };
150
157
  }
151
- return;
158
+ return { success: true, data: result.data };
152
159
  }
153
- catch (error) {
154
- console.error('Error updating Asset Administration Shell:', error);
155
- throw error;
160
+ catch (err) {
161
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
156
162
  }
157
163
  }
158
164
  /**
159
- * Returns the Asset Information
165
+ * Returns the AssetInformation for the given AAS.
166
+ *
167
+ * @param options Object containing:
168
+ * - baseUrl: The API base URL
169
+ * - aasIdentifier: The unique ID
170
+ * - headers?: Optional request headers
160
171
  *
161
- * @function getAssetInformation
162
- * @param {AasIdentifierOptions} options - Options object.
163
- * @param {string} options.baseUrl - The API base URL
164
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
165
- * @param {Headers} [options.headers] - Request headers
166
- * @returns {Promise<AssetInformation>} Requested Asset Information
172
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
167
173
  */
168
- async getAssetInformation({ baseUrl, aasIdentifier, headers }) {
174
+ async getAssetInformation(options) {
175
+ const { baseUrl, aasIdentifier, headers } = options;
169
176
  try {
170
177
  const client = createCustomClient(baseUrl, headers);
171
178
  const encodedAasIdentifier = base64Encode(aasIdentifier);
172
- const { data, error } = await AasRepository.getAssetInformationAasRepository({
179
+ const result = await AasRepository.getAssetInformationAasRepository({
173
180
  client,
174
181
  path: { aasIdentifier: encodedAasIdentifier },
175
182
  });
176
- if (error) {
177
- console.error('Error from server:', error);
178
- throw new Error(JSON.stringify(error.messages));
183
+ if (result.error) {
184
+ return { success: false, error: result.error };
179
185
  }
180
- return convertApiAssetInformationToCoreAssetInformation(data);
186
+ return {
187
+ success: true,
188
+ data: convertApiAssetInformationToCoreAssetInformation(result.data),
189
+ };
181
190
  }
182
- catch (error) {
183
- console.error('Error fetching Asset Information:', error);
184
- throw error;
191
+ catch (err) {
192
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
185
193
  }
186
194
  }
187
195
  /**
188
- * Updates the Asset Information
196
+ * Updates the AssetInformation for the given AAS.
197
+ *
198
+ * @param options Object containing:
199
+ * - baseUrl: The API base URL
200
+ * - aasIdentifier: The unique ID
201
+ * - assetInformation: The updated AssetInformation object
202
+ * - headers?: Optional request headers
189
203
  *
190
- * @function putAssetInformation
191
- * @param {PutAssetInformationOptions} options - Options object.
192
- * @param {string} options.baseUrl - The API base URL
193
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
194
- * @param {AssetInformation} options.assetInformation - Asset Information object
195
- * @param {Headers} [options.headers] - Request headers
196
- * @returns {Promise<void>} Asset Information updated successfully
204
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
197
205
  */
198
- async putAssetInformation({ baseUrl, aasIdentifier, assetInformation, headers, }) {
206
+ async putAssetInformation(options) {
207
+ const { baseUrl, aasIdentifier, assetInformation, headers } = options;
199
208
  try {
200
209
  const client = createCustomClient(baseUrl, headers);
201
210
  const encodedAasIdentifier = base64Encode(aasIdentifier);
202
- const { error } = await AasRepository.putAssetInformationAasRepository({
211
+ const result = await AasRepository.putAssetInformationAasRepository({
203
212
  client,
204
213
  path: { aasIdentifier: encodedAasIdentifier },
205
214
  body: convertCoreAssetInformationToApiAssetInformation(assetInformation),
206
215
  });
207
- if (error) {
208
- console.error('Error from server:', error);
209
- throw new Error(JSON.stringify(error.messages));
216
+ if (result.error) {
217
+ return { success: false, error: result.error };
210
218
  }
211
- return;
219
+ return { success: true, data: result.data };
212
220
  }
213
- catch (error) {
214
- console.error('Error updating Asset Information:', error);
215
- throw error;
221
+ catch (err) {
222
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
216
223
  }
217
224
  }
218
225
  /**
219
- * Deletes the Thumbnail
226
+ * Deletes the Thumbnail associated with the given AAS.
220
227
  *
221
- * @function deleteThumbnail
222
- * @param {AasIdentifierOptions} options - Options object.
223
- * @param {string} options.baseUrl - The API base URL
224
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
225
- * @param {Headers} [options.headers] - Request headers
226
- * @returns {Promise<void>} Thumbnail deletion successful
228
+ * @param options Object containing:
229
+ * - baseUrl: The API base URL
230
+ * - aasIdentifier: The unique ID
231
+ * - headers?: Optional request headers
232
+ *
233
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
227
234
  */
228
- async deleteThumbnail({ baseUrl, aasIdentifier, headers }) {
235
+ async deleteThumbnail(options) {
236
+ const { baseUrl, aasIdentifier, headers } = options;
229
237
  try {
230
238
  const client = createCustomClient(baseUrl, headers);
231
239
  const encodedAasIdentifier = base64Encode(aasIdentifier);
232
- const { error } = await AasRepository.deleteThumbnailAasRepository({
240
+ const result = await AasRepository.deleteThumbnailAasRepository({
233
241
  client,
234
242
  path: { aasIdentifier: encodedAasIdentifier },
235
243
  });
236
- if (error) {
237
- console.error('Error from server:', error);
238
- throw new Error(JSON.stringify(error.messages));
244
+ if (result.error) {
245
+ return { success: false, error: result.error };
239
246
  }
240
- return;
247
+ return {
248
+ success: true,
249
+ data: result.data,
250
+ };
241
251
  }
242
- catch (error) {
243
- console.error('Error deleting Thumbnail:', error);
244
- throw error;
252
+ catch (err) {
253
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
245
254
  }
246
255
  }
247
256
  /**
248
- * Returns the Thumbnail
257
+ * Returns the Thumbnail associated with an AAS, if any.
249
258
  *
250
- * @function getThumbnail
251
- * @param {AasIdentifierOptions} options - Options object.
252
- * @param {string} options.baseUrl - The API base URL
253
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
254
- * @param {Headers} [options.headers] - Request headers
255
- * @returns {Promise<Blob | File>} The thumbnail of the Asset Information.
259
+ * @param options Object containing:
260
+ * - baseUrl: The API base URL
261
+ * - aasIdentifier: The unique ID
262
+ * - headers?: Optional request headers
263
+ *
264
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
256
265
  */
257
- async getThumbnail({ baseUrl, aasIdentifier, headers }) {
266
+ async getThumbnail(options) {
267
+ const { baseUrl, aasIdentifier, headers } = options;
258
268
  try {
259
269
  const client = createCustomClient(baseUrl, headers);
260
270
  const encodedAasIdentifier = base64Encode(aasIdentifier);
261
- const { data, error } = await AasRepository.getThumbnailAasRepository({
271
+ const result = await AasRepository.getThumbnailAasRepository({
262
272
  client,
263
273
  path: { aasIdentifier: encodedAasIdentifier },
264
274
  });
265
- if (error) {
266
- console.error('Error from server:', error);
267
- throw new Error(JSON.stringify(error.messages));
275
+ if (result.error) {
276
+ return { success: false, error: result.error };
268
277
  }
269
- return data;
278
+ return { success: true, data: result.data };
270
279
  }
271
- catch (error) {
272
- console.error('Error fetching Thumbnail:', error);
273
- throw error;
280
+ catch (err) {
281
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
274
282
  }
275
283
  }
276
284
  /**
277
- * Updates the Thumbnail
285
+ * Updates (or creates) the Thumbnail for the given AAS.
286
+ *
287
+ * @param options Object containing:
288
+ * - baseUrl: The API base URL
289
+ * - aasIdentifier: The unique ID
290
+ * - thumbnail: The thumbnail data to upload
291
+ * - headers?: Optional request headers
278
292
  *
279
- * @function putThumbnail
280
- * @param {PutThumbnailOptions} options - Options object.
281
- * @param {string} options.baseUrl - The API base URL
282
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
283
- * @param {AssetinformationThumbnailBody} options.thumbnail - Thumbnail to upload
284
- * @param {Headers} [options.headers] - Request headers
285
- * @returns {Promise<void>} Thumbnail updated successfully
293
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
286
294
  */
287
- async putThumbnail({ baseUrl, aasIdentifier, thumbnail, headers }) {
295
+ async putThumbnail(options) {
296
+ const { baseUrl, aasIdentifier, thumbnail, headers } = options;
288
297
  try {
289
298
  const client = createCustomClient(baseUrl, headers);
290
299
  const encodedAasIdentifier = base64Encode(aasIdentifier);
291
- const { error } = await AasRepository.putThumbnailAasRepository({
300
+ const result = await AasRepository.putThumbnailAasRepository({
292
301
  client,
293
302
  path: { aasIdentifier: encodedAasIdentifier },
294
303
  body: thumbnail,
295
304
  });
296
- if (error) {
297
- console.error('Error from server:', error);
298
- throw new Error(JSON.stringify(error.messages));
305
+ if (result.error) {
306
+ return { success: false, error: result.error };
299
307
  }
300
- return;
308
+ return { success: true, data: result.data };
301
309
  }
302
- catch (error) {
303
- console.error('Error updating Thumbnail:', error);
304
- throw error;
310
+ catch (err) {
311
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
305
312
  }
306
313
  }
307
314
  /**
308
- * Returns all submodel references
315
+ * Returns all submodel references for the given AAS.
316
+ *
317
+ * @param options Object containing:
318
+ * - baseUrl: The API base URL
319
+ * - aasIdentifier: The unique ID
320
+ * - headers?: Optional request headers
321
+ * - limit?: Max number of elements
322
+ * - cursor?: Paging cursor
309
323
  *
310
- * @function getAllSubmodelReferences
311
- * @param {GetAllSubmodelReferencesOptions} options - Options object.
312
- * @param {string} options.baseUrl - The API base URL
313
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
314
- * @param {Headers} [options.headers] - Request headers
315
- * @param {number} [options.limit] - The maximum number of elements in the response array
316
- * @param {string} [options.cursor] - A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
317
- * @returns {Promise<GetAllSubmodelReferencesResponse>} Requested submodel references
324
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
318
325
  */
319
- async getAllSubmodelReferences({ baseUrl, aasIdentifier, headers, limit, cursor, }) {
326
+ async getAllSubmodelReferences(options) {
327
+ const { baseUrl, aasIdentifier, headers, limit, cursor } = options;
320
328
  try {
321
329
  const client = createCustomClient(baseUrl, headers);
322
330
  const encodedAasIdentifier = base64Encode(aasIdentifier);
323
- const { data, error } = await AasRepository.getAllSubmodelReferencesAasRepository({
331
+ const result = await AasRepository.getAllSubmodelReferencesAasRepository({
324
332
  client,
325
333
  path: { aasIdentifier: encodedAasIdentifier },
326
- query: {
327
- limit,
328
- cursor,
329
- },
334
+ query: { limit, cursor },
330
335
  });
331
- if (error) {
332
- console.error('Error from server:', error);
333
- throw new Error(JSON.stringify(error.messages));
336
+ if (result.error) {
337
+ return { success: false, error: result.error };
334
338
  }
335
- const submodelReferences = (data.result ?? []).map(convertApiReferenceToCoreReference);
339
+ const submodelReferences = (result.data.result ?? []).map(convertApiReferenceToCoreReference);
336
340
  return {
337
- pagedResult: data.paging_metadata,
338
- result: submodelReferences,
341
+ success: true,
342
+ data: {
343
+ pagedResult: result.data.paging_metadata,
344
+ result: submodelReferences,
345
+ },
339
346
  };
340
347
  }
341
- catch (error) {
342
- console.error('Error fetching Submodel References:', error);
343
- throw error;
348
+ catch (err) {
349
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
344
350
  }
345
351
  }
346
352
  /**
347
- * Creates a submodel reference at the Asset Administration Shell
353
+ * Creates a submodel reference at the given AAS.
354
+ *
355
+ * @param options Object containing:
356
+ * - baseUrl: The API base URL
357
+ * - aasIdentifier: The unique ID of the AAS
358
+ * - submodelReference: The Reference to the submodel
359
+ * - headers?: Optional request headers
348
360
  *
349
- * @function postSubmodelReference
350
- * @param {PostSubmodelReferenceOptions} options - Options object.
351
- * @param {string} options.baseUrl - The API base URL
352
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
353
- * @param {Reference} options.submodelReference - Reference to the Submodel
354
- * @param {Headers} [options.headers] - Request headers
355
- * @returns {Promise<Reference>} Submodel reference created successfully
361
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
356
362
  */
357
- async postSubmodelReference({ baseUrl, aasIdentifier, submodelReference, headers, }) {
363
+ async postSubmodelReference(options) {
364
+ const { baseUrl, aasIdentifier, submodelReference, headers } = options;
358
365
  try {
359
366
  const client = createCustomClient(baseUrl, headers);
360
367
  const encodedAasIdentifier = base64Encode(aasIdentifier);
361
- const { data, error } = await AasRepository.postSubmodelReferenceAasRepository({
368
+ const result = await AasRepository.postSubmodelReferenceAasRepository({
362
369
  client,
363
370
  path: { aasIdentifier: encodedAasIdentifier },
364
371
  body: convertCoreReferenceToApiReference(submodelReference),
365
372
  });
366
- if (error) {
367
- console.error('Error from server:', error);
368
- throw new Error(JSON.stringify(error.messages));
373
+ if (result.error) {
374
+ return { success: false, error: result.error };
369
375
  }
370
- return convertApiReferenceToCoreReference(data);
376
+ return { success: true, data: convertApiReferenceToCoreReference(result.data) };
371
377
  }
372
- catch (error) {
373
- console.error('Error creating Submodel Reference:', error);
374
- throw error;
378
+ catch (err) {
379
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
375
380
  }
376
381
  }
377
382
  /**
378
- * Deletes the submodel reference from the Asset Administration Shell. Does not delete the submodel itself!
383
+ * Deletes a submodel reference from the given AAS (does not delete the submodel itself).
379
384
  *
380
- * @function deleteSubmodelReferenceById
381
- * @param {DeleteSubmodelReferenceByIdOptions} options - Options object.
382
- * @param {string} options.baseUrl - The API base URL
383
- * @param {string} options.aasIdentifier - The Asset Administration Shell's unique id
384
- * @param {string} options.submodelIdentifier - The Submodel's unique id
385
- * @param {Headers} [options.headers] - Request headers
386
- * @returns {Promise<void>} Submodel reference deleted successfully
385
+ * @param options Object containing:
386
+ * - baseUrl: The API base URL
387
+ * - aasIdentifier: Unique ID of the AAS
388
+ * - submodelIdentifier: The submodel's unique ID
389
+ * - headers?: Optional request headers
390
+ *
391
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
387
392
  */
388
- async deleteSubmodelReferenceById({ baseUrl, aasIdentifier, submodelIdentifier, headers, }) {
393
+ async deleteSubmodelReferenceById(options) {
394
+ const { baseUrl, aasIdentifier, submodelIdentifier, headers } = options;
389
395
  try {
390
396
  const client = createCustomClient(baseUrl, headers);
391
397
  const encodedAasIdentifier = base64Encode(aasIdentifier);
392
398
  const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
393
- const { error } = await AasRepository.deleteSubmodelReferenceByIdAasRepository({
399
+ const result = await AasRepository.deleteSubmodelReferenceByIdAasRepository({
394
400
  client,
395
- path: { aasIdentifier: encodedAasIdentifier, submodelIdentifier: encodedSubmodelIdentifier },
401
+ path: {
402
+ aasIdentifier: encodedAasIdentifier,
403
+ submodelIdentifier: encodedSubmodelIdentifier,
404
+ },
396
405
  });
397
- if (error) {
398
- console.error('Error from server:', error);
399
- throw new Error(JSON.stringify(error.messages));
406
+ if (result.error) {
407
+ return { success: false, error: result.error };
400
408
  }
401
- return;
409
+ return { success: true, data: result.data };
402
410
  }
403
- catch (error) {
404
- console.error('Error deleting Submodel Reference:', error);
405
- throw error;
411
+ catch (err) {
412
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
406
413
  }
407
414
  }
408
415
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './clients';
2
2
  export * as AasTypes from './generated/types.gen';
3
- export * as AasRepositoryModels from './models/aas-repository';
3
+ export * as Models from './models';