basyx-typescript-sdk 1.0.2 → 1.1.0

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.
@@ -61,6 +61,15 @@ export function base64Decode(urlSafeBase64String) {
61
61
  base64String += '=='.substring(0, 4 - incompleteFourChars);
62
62
  const encodedUriComponent = atob(base64String);
63
63
  const escapedEncodedUriComponent = escape(encodedUriComponent);
64
- const decodedString = decodeURIComponent(escapedEncodedUriComponent);
65
- return decodedString;
64
+ try {
65
+ const decodedString = decodeURIComponent(escapedEncodedUriComponent);
66
+ return decodedString;
67
+ }
68
+ catch {
69
+ // If decodeURIComponent fails, it usually means the decoded string does not contain valid percent-encoded sequences.
70
+ // This can happen if the original input to base64Encode did not require URI encoding (e.g., only contained ASCII characters).
71
+ // In such cases, we return the unescaped string directly as a fallback.
72
+ // Example: base64Decode(base64Encode("simpleASCII")) will not require URI decoding.
73
+ return unescape(escapedEncodedUriComponent);
74
+ }
66
75
  }
@@ -1,7 +1,24 @@
1
1
  import { common } from '@aas-core-works/aas-core3.0-typescript';
2
2
  import { administrativeInformationFromJsonable, assetKindFromJsonable, DeserializationError, extensionFromJsonable, langStringNameTypeFromJsonable, langStringTextTypeFromJsonable, referenceFromJsonable, specificAssetIdFromJsonable, toJsonable, } from '@aas-core-works/aas-core3.0-typescript/jsonization';
3
+ import { AssetKind } from '@aas-core-works/aas-core3.0-typescript/types';
3
4
  //import { AasRegistryService } from '../generated';
4
5
  import { AssetAdministrationShellDescriptor, SubmodelDescriptor, } from '../models/Descriptors';
6
+ /**
7
+ * Convert AssetKind enum to its JSON string representation.
8
+ * The Core library uses numeric enums (e.g., Instance = 1), but the API expects strings.
9
+ */
10
+ function assetKindToJsonable(assetKind) {
11
+ switch (assetKind) {
12
+ case AssetKind.Instance:
13
+ return 'Instance';
14
+ case AssetKind.Type:
15
+ return 'Type';
16
+ case AssetKind.NotApplicable:
17
+ return 'NotApplicable';
18
+ default:
19
+ throw new Error(`Unknown AssetKind value: ${assetKind}`);
20
+ }
21
+ }
5
22
  export function assetAdministrationShellDescriptorFromJsonable(json) {
6
23
  if (json === null) {
7
24
  return new common.Either(null, new DeserializationError('Expected a JSON object, but got null'));
@@ -108,7 +125,9 @@ export function toJsonableAssetAdministrationShellDescriptor(descriptor) {
108
125
  extensions: descriptor.extensions.map(toJsonable),
109
126
  }),
110
127
  ...(descriptor.administration !== null && { administration: toJsonable(descriptor.administration) }),
111
- ...(descriptor.assetKind !== null && { assetKind: descriptor.assetKind }),
128
+ ...(descriptor.assetKind !== null && {
129
+ assetKind: assetKindToJsonable(descriptor.assetKind),
130
+ }),
112
131
  ...(descriptor.assetType !== null && { assetType: descriptor.assetType }),
113
132
  ...(descriptor.globalAssetId !== null && { globalAssetId: descriptor.globalAssetId }),
114
133
  ...(descriptor.specificAssetIds !== null && {
@@ -0,0 +1,9 @@
1
+ export { assetAdministrationShellDescriptorFromJsonable, endpointFromJsonable, protocolInformationFromJsonable, submodelDescriptorFromJsonable, toJsonableAssetAdministrationShellDescriptor, toJsonableEndpoint, toJsonableProtocolInformation, toJsonableSecurityAttribute, toJsonableSubmodelDescriptor, } from './descriptorJsonization';
2
+ export { convertApiAasDescriptorToCoreAasDescriptor, convertApiSubmodelDescriptorToCoreSubmodelDescriptor, convertCoreAasDescriptorToApiAasDescriptor, convertCoreSubmodelDescriptorToApiSubmodelDescriptor, } from './convertAasDescriptorTypes';
3
+ export { convertApiAssetIdToCoreAssetId, convertCoreAssetIdToApiAssetId } from './convertAasDiscoveryTypes';
4
+ export { convertApiAasToCoreAas, convertApiAssetInformationToCoreAssetInformation, convertApiReferenceToCoreReference, convertCoreAasToApiAas, convertCoreAssetInformationToApiAssetInformation, convertCoreReferenceToApiReference, } from './convertAasTypes';
5
+ export { convertApiCDToCoreCD, convertCoreCDToApiCD } from './convertConceptDescriptionTypes';
6
+ export { convertApiSubmodelElementToCoreSubmodelElement, convertApiSubmodelToCoreSubmodel, convertCoreSubmodelElementToApiSubmodelElement, convertCoreSubmodelToApiSubmodel, } from './convertSubmodelTypes';
7
+ export { applyDefaults } from './apiConfig';
8
+ export { base64Decode, base64Encode } from './base64Url';
9
+ export { handleApiError } from './errorHandler';
@@ -0,0 +1,12 @@
1
+ // Descriptor Serialization/Deserialization
2
+ export { assetAdministrationShellDescriptorFromJsonable, endpointFromJsonable, protocolInformationFromJsonable, submodelDescriptorFromJsonable, toJsonableAssetAdministrationShellDescriptor, toJsonableEndpoint, toJsonableProtocolInformation, toJsonableSecurityAttribute, toJsonableSubmodelDescriptor, } from './descriptorJsonization';
3
+ // Type Converters
4
+ export { convertApiAasDescriptorToCoreAasDescriptor, convertApiSubmodelDescriptorToCoreSubmodelDescriptor, convertCoreAasDescriptorToApiAasDescriptor, convertCoreSubmodelDescriptorToApiSubmodelDescriptor, } from './convertAasDescriptorTypes';
5
+ export { convertApiAssetIdToCoreAssetId, convertCoreAssetIdToApiAssetId } from './convertAasDiscoveryTypes';
6
+ export { convertApiAasToCoreAas, convertApiAssetInformationToCoreAssetInformation, convertApiReferenceToCoreReference, convertCoreAasToApiAas, convertCoreAssetInformationToApiAssetInformation, convertCoreReferenceToApiReference, } from './convertAasTypes';
7
+ export { convertApiCDToCoreCD, convertCoreCDToApiCD } from './convertConceptDescriptionTypes';
8
+ export { convertApiSubmodelElementToCoreSubmodelElement, convertApiSubmodelToCoreSubmodel, convertCoreSubmodelElementToApiSubmodelElement, convertCoreSubmodelToApiSubmodel, } from './convertSubmodelTypes';
9
+ // Utilities
10
+ export { applyDefaults } from './apiConfig';
11
+ export { base64Decode, base64Encode } from './base64Url';
12
+ export { handleApiError } from './errorHandler';
@@ -0,0 +1,3 @@
1
+ import { Environment } from '@aas-core-works/aas-core3.0-typescript/types';
2
+ export declare class BaSyxEnvironment extends Environment {
3
+ }
@@ -0,0 +1,3 @@
1
+ import { Environment } from '@aas-core-works/aas-core3.0-typescript/types';
2
+ export class BaSyxEnvironment extends Environment {
3
+ }
@@ -0,0 +1,240 @@
1
+ import type { ApiResult } from '../models/api';
2
+ import { AssetAdministrationShell, Reference, Submodel } from '@aas-core-works/aas-core3.0-typescript/types';
3
+ import { Configuration } from '../generated';
4
+ import { AssetId } from '../models/AssetId';
5
+ import { AssetAdministrationShellDescriptor } from '../models/Descriptors';
6
+ export interface AasServiceConfig {
7
+ registryConfig?: Configuration;
8
+ repositoryConfig?: Configuration;
9
+ submodelRegistryConfig?: Configuration;
10
+ submodelRepositoryConfig?: Configuration;
11
+ conceptDescriptionRepositoryConfig?: Configuration;
12
+ discoveryConfig?: Configuration;
13
+ }
14
+ /**
15
+ * AasService combines and orchestrates multiple clients and services, including:
16
+ * - AasRegistryClient
17
+ * - AasRepositoryClient
18
+ * - AasDiscoveryClient
19
+ * - SubmodelService
20
+ *
21
+ * It provides higher-level functionality for working with Asset Administration Shells
22
+ * by coordinating operations across these BaSyx components, demonstrating the multi-client pattern.
23
+ */
24
+ export declare class AasService {
25
+ private registryClient;
26
+ private repositoryClient;
27
+ private discoveryClient;
28
+ private registryConfig?;
29
+ private repositoryConfig?;
30
+ private discoveryConfig?;
31
+ private submodelService;
32
+ constructor(config: AasServiceConfig);
33
+ /**
34
+ * Retrieves a list of all Asset Administration Shells.
35
+ *
36
+ * This method first attempts to fetch AAS Descriptors from the Registry,
37
+ * then uses the descriptor endpoints to fetch the actual shells.
38
+ * If a registry is not configured or fails, it falls back to fetching
39
+ * AAS directly from the Repository.
40
+ *
41
+ * @param options Object containing:
42
+ * - preferRegistry?: Whether to prefer registry over repository (default: true)
43
+ * - limit?: Maximum number of elements to retrieve
44
+ * - cursor?: Pagination cursor
45
+ * - includeSubmodels?: Whether to fetch submodels for each shell (default: false)
46
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
47
+ *
48
+ * @returns Either `{ success: true; data: { shells, source, submodels? } }` or `{ success: false; error: ... }`.
49
+ */
50
+ getAasList(options?: {
51
+ preferRegistry?: boolean;
52
+ limit?: number;
53
+ cursor?: string;
54
+ includeSubmodels?: boolean;
55
+ includeConceptDescriptions?: boolean;
56
+ }): Promise<ApiResult<{
57
+ shells: AssetAdministrationShell[];
58
+ source: 'registry' | 'repository';
59
+ submodels?: Record<string, Submodel[]>;
60
+ }, any>>;
61
+ /**
62
+ * Retrieves an Asset Administration Shell by ID.
63
+ *
64
+ * This method first attempts to fetch the descriptor from the registry
65
+ * and use its endpoint to fetch the shell. If that fails, it falls back
66
+ * to fetching directly from the repository.
67
+ *
68
+ * @param options Object containing:
69
+ * - aasIdentifier: The AAS identifier
70
+ * - useRegistryEndpoint?: Whether to try registry endpoint first (default: true)
71
+ * - includeSubmodels?: Whether to fetch submodels for the shell (default: false)
72
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
73
+ *
74
+ * @returns Either `{ success: true; data: { shell, descriptor?, submodels? } }` or `{ success: false; error: ... }`.
75
+ */
76
+ getAasById(options: {
77
+ aasIdentifier: string;
78
+ useRegistryEndpoint?: boolean;
79
+ includeSubmodels?: boolean;
80
+ includeConceptDescriptions?: boolean;
81
+ }): Promise<ApiResult<{
82
+ shell: AssetAdministrationShell;
83
+ descriptor?: AssetAdministrationShellDescriptor;
84
+ submodels?: Submodel[];
85
+ }, any>>;
86
+ /**
87
+ * Gets the endpoint URL for an Asset Administration Shell by its identifier.
88
+ *
89
+ * If registry is configured and useRegistry is true, retrieves the endpoint
90
+ * from the descriptor's endpoint object. Otherwise, constructs the endpoint
91
+ * from the repository base path and the encoded AAS identifier.
92
+ *
93
+ * @param options Object containing:
94
+ * - aasIdentifier: The AAS identifier
95
+ * - useRegistry?: Whether to try getting endpoint from registry (default: true)
96
+ *
97
+ * @returns Either `{ success: true; data: endpointUrl }` or `{ success: false; error: ... }`.
98
+ */
99
+ getAasEndpointById(options: {
100
+ aasIdentifier: string;
101
+ useRegistry?: boolean;
102
+ }): Promise<ApiResult<string, any>>;
103
+ /**
104
+ * Retrieves an Asset Administration Shell by its endpoint URL.
105
+ *
106
+ * Extracts the base URL and base64url-encoded AAS identifier from the endpoint,
107
+ * decodes the identifier, and fetches the shell from the repository.
108
+ *
109
+ * @param options Object containing:
110
+ * - endpoint: The endpoint URL (format: http://host/shells/{base64EncodedId})
111
+ * - includeSubmodels?: Whether to fetch submodels for the shell (default: false)
112
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
113
+ *
114
+ * @returns Either `{ success: true; data: { shell, submodels? } }` or `{ success: false; error: ... }`.
115
+ */
116
+ getAasByEndpoint(options: {
117
+ endpoint: string;
118
+ includeSubmodels?: boolean;
119
+ includeConceptDescriptions?: boolean;
120
+ }): Promise<ApiResult<{
121
+ shell: AssetAdministrationShell;
122
+ submodels?: Submodel[];
123
+ }, any>>;
124
+ /**
125
+ * Creates an Asset Administration Shell and optionally registers it in the registry.
126
+ *
127
+ * This method creates the AAS in the repository first. If registry is configured
128
+ * and registerInRegistry is true, it automatically creates a descriptor from the shell
129
+ * and registers it in the registry with the repository endpoint.
130
+ *
131
+ * @param options Object containing:
132
+ * - shell: The AAS to create
133
+ * - registerInRegistry?: Whether to register the descriptor in the registry (default: true)
134
+ *
135
+ * @returns Either `{ success: true; data: { shell, descriptor? } }` or `{ success: false; error: ... }`.
136
+ */
137
+ createAas(options: {
138
+ shell: AssetAdministrationShell;
139
+ registerInRegistry?: boolean;
140
+ }): Promise<ApiResult<{
141
+ shell: AssetAdministrationShell;
142
+ descriptor?: AssetAdministrationShellDescriptor;
143
+ }, any>>;
144
+ /**
145
+ * Updates an Asset Administration Shell and optionally updates its descriptor in the registry.
146
+ *
147
+ * This method updates the AAS in the repository. If registry is configured
148
+ * and updateInRegistry is true, it automatically creates/updates the descriptor
149
+ * in the registry with the updated shell data.
150
+ *
151
+ * @param options Object containing:
152
+ * - shell: The updated AAS
153
+ * - updateInRegistry?: Whether to update the descriptor in the registry (default: true)
154
+ *
155
+ * @returns Either `{ success: true; data: { shell, descriptor? } }` or `{ success: false; error: ... }`.
156
+ */
157
+ updateAas(options: {
158
+ shell: AssetAdministrationShell;
159
+ updateInRegistry?: boolean;
160
+ }): Promise<ApiResult<{
161
+ shell: AssetAdministrationShell;
162
+ descriptor?: AssetAdministrationShellDescriptor;
163
+ }, any>>;
164
+ /**
165
+ * Deletes an Asset Administration Shell and optionally removes it from the registry.
166
+ *
167
+ * This method removes the descriptor from the registry first (if requested),
168
+ * then deletes the AAS from the repository.
169
+ *
170
+ * @param options Object containing:
171
+ * - aasIdentifier: The AAS identifier to remove
172
+ * - deleteFromRegistry?: Whether to delete from registry (default: true)
173
+ *
174
+ * @returns Either `{ success: true; data: void }` or `{ success: false; error: ... }`.
175
+ */
176
+ deleteAas(options: {
177
+ aasIdentifier: string;
178
+ deleteFromRegistry?: boolean;
179
+ }): Promise<ApiResult<void, any>>;
180
+ /**
181
+ * Retrieves Asset Administration Shells by their asset identifiers.
182
+ *
183
+ * This method uses the discovery service to resolve asset IDs to AAS identifiers,
184
+ * then fetches the corresponding shells. If multiple AAS IDs are found for the given
185
+ * asset IDs, all matching shells are returned.
186
+ *
187
+ * @param options Object containing:
188
+ * - assetIds: Array of asset identifiers to search for
189
+ * - includeSubmodels?: Whether to fetch submodels for each shell (default: false)
190
+ * - includeConceptDescriptions?: Whether to fetch concept descriptions (default: false)
191
+ *
192
+ * @returns Either `{ success: true; data: { shells, aasIds } }` or `{ success: false; error: ... }`.
193
+ */
194
+ getAasByAssetId(options: {
195
+ assetIds: AssetId[];
196
+ includeSubmodels?: boolean;
197
+ includeConceptDescriptions?: boolean;
198
+ }): Promise<ApiResult<{
199
+ shells: AssetAdministrationShell[];
200
+ aasIds: string[];
201
+ }, any>>;
202
+ /**
203
+ * Resolves a reference to retrieve the endpoints for the referenced AAS, Submodel, and SubmodelElement path.
204
+ *
205
+ * This method parses a Reference object and extracts the AAS ID, Submodel ID, and builds the path
206
+ * to the SubmodelElement if applicable. It supports ModelReferences with keys pointing to:
207
+ * - AssetAdministrationShell
208
+ * - Submodel
209
+ * - SubmodelElements (including nested elements in collections and lists)
210
+ *
211
+ * @param options Object containing:
212
+ * - reference: The Reference object to resolve
213
+ *
214
+ * @returns Either `{ success: true; data: { aasEndpoint?, submodelEndpoint?, submodelElementPath? } }` or `{ success: false; error: ... }`.
215
+ */
216
+ resolveReference(options: {
217
+ reference: Reference;
218
+ }): Promise<ApiResult<{
219
+ aasEndpoint?: string;
220
+ submodelEndpoint?: string;
221
+ submodelElementPath?: string;
222
+ }, any>>;
223
+ /**
224
+ * Helper method to create an AAS descriptor from an AssetAdministrationShell.
225
+ * Populates descriptor fields from the shell including metadata and endpoint configuration.
226
+ *
227
+ * @param shell The AssetAdministrationShell to create descriptor from
228
+ * @returns AssetAdministrationShellDescriptor with all populated fields
229
+ */
230
+ private createDescriptorFromAas;
231
+ /**
232
+ * Helper method to fetch submodels for a list of shells.
233
+ * Returns a map of shell IDs to their corresponding submodels.
234
+ *
235
+ * @param shells Array of Asset Administration Shells
236
+ * @param includeConceptDescriptions Whether to fetch concept descriptions for submodels
237
+ * @returns Record mapping shell IDs to arrays of Submodels
238
+ */
239
+ private fetchSubmodelsForShells;
240
+ }