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