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.
package/bundle/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { createClient, createConfig, formDataBodySerializer } from '@hey-api/client-fetch';
2
2
  import { jsonization } from '@aas-core-works/aas-core3.0-typescript';
3
3
 
4
+ // This file is auto-generated by @hey-api/openapi-ts
5
+
6
+ var types_gen = /*#__PURE__*/Object.freeze({
7
+ __proto__: null
8
+ });
9
+
4
10
  // This file is auto-generated by @hey-api/openapi-ts
5
11
  const client = createClient(createConfig());
6
12
  /**
@@ -133,6 +139,38 @@ const deleteSubmodelReferenceByIdAasRepository = (options) => {
133
139
  });
134
140
  };
135
141
 
142
+ /**
143
+ * Encodes a given string into Base64 format.
144
+ * Optionally transforms the output into a URL-safe Base64 string.
145
+ *
146
+ * The process includes:
147
+ * 1. Trimming the input string.
148
+ * 2. Percent-encoding the string.
149
+ * 3. Converting percent-encoded characters back to their raw representation.
150
+ * 4. Encoding the result into Base64.
151
+ * 5. Optionally making the Base64 string URL safe by replacing '+' with '-', '/' with '_' and removing trailing '='.
152
+ *
153
+ * @function base64Encode
154
+ * @param {string} string - The string to encode.
155
+ * @param {boolean} [urlSafe=true] - Whether to return a URL-safe encoded string. Defaults to true.
156
+ * @returns {string} The Base64 encoded string, converted to URL-safe format if requested.
157
+ */
158
+ function base64Encode(string, urlSafe = true) {
159
+ string = string.trim();
160
+ if (string === '')
161
+ return '';
162
+ const encodedUriComponent = encodeURIComponent(string);
163
+ const unescapedEncodedUriComponent = unescape(encodedUriComponent); // reverse percent-encoding
164
+ const base64String = btoa(unescapedEncodedUriComponent);
165
+ if (!urlSafe)
166
+ return base64String;
167
+ const urlSafeBase64String = base64String
168
+ .replace(/\+/g, '-') // Replace + with -
169
+ .replace(/\//g, '_') // Replace / with _
170
+ .replace(/=+$/, ''); // Remove padding (=)
171
+ return urlSafeBase64String;
172
+ }
173
+
136
174
  /**
137
175
  * Provide an implementation of the Asset Administration Shell (AAS) V3.0.
138
176
  *
@@ -610,401 +648,415 @@ function createCustomClient(baseURL, headers = new Headers()) {
610
648
 
611
649
  class AasRepositoryClient {
612
650
  /**
613
- * Returns all Asset Administration Shells
651
+ * Returns all Asset Administration Shells.
614
652
  *
615
- * @async
616
- * @function getAllAssetAdministrationShells
617
- * @param baseURL The API base URL
618
- * @param headers Request headers
619
- * @param assetIds A list of specific Asset identifiers. Every single value asset identifier is a base64-url-encoded
620
- * @param idShort The Asset Administration Shell’s IdShort
621
- * @param limit The maximum number of elements in the response array
622
- * @param cursor A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
623
- * @returns {Promise<GetAllAssetAdministrationShellsResponse>} Requested Asset Administration Shells
653
+ * @param options Object containing:
654
+ * - baseUrl: The API base URL
655
+ * - headers?: Optional Request headers
656
+ * - assetIds?: A list of asset identifiers
657
+ * - idShort?: The AAS's idShort
658
+ * - limit?: Max number of elements to return
659
+ * - cursor?: A paging cursor from previous responses
660
+ *
661
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
624
662
  */
625
- async getAllAssetAdministrationShells(baseURL, headers, assetIds, idShort, limit, cursor) {
663
+ async getAllAssetAdministrationShells(options) {
664
+ const { baseUrl, headers, assetIds, idShort, limit, cursor } = options;
626
665
  try {
627
- const client = createCustomClient(baseURL, headers);
666
+ const client = createCustomClient(baseUrl, headers);
667
+ const encodedAssetIds = assetIds?.map((id) => base64Encode(JSON.stringify(id)));
628
668
  const { data, error } = await getAllAssetAdministrationShells({
629
669
  client,
630
- query: {
631
- assetIds,
632
- idShort,
633
- limit,
634
- cursor,
635
- },
670
+ query: { assetIds: encodedAssetIds, idShort, limit, cursor },
636
671
  });
637
672
  if (error) {
638
- console.error('Error from server:', error);
639
- throw new Error(JSON.stringify(error.messages));
673
+ return { success: false, error };
640
674
  }
641
675
  const shells = (data.result ?? []).map(convertApiAasToCoreAas);
642
676
  return {
643
- pagedResult: data.paging_metadata,
644
- result: shells,
677
+ success: true,
678
+ data: {
679
+ pagedResult: data.paging_metadata,
680
+ result: shells,
681
+ },
645
682
  };
646
683
  }
647
- catch (error) {
648
- console.error('Error fetching Asset Administration Shells:', error);
649
- throw error;
684
+ catch (err) {
685
+ return {
686
+ success: false,
687
+ error: err instanceof Error ? err : new Error(String(err)),
688
+ };
650
689
  }
651
690
  }
652
691
  /**
653
- * Creates a new Asset Administration Shell
692
+ * Creates a new Asset Administration Shell.
693
+ *
694
+ * @param options Object containing:
695
+ * - baseUrl: The API base URL
696
+ * - assetAdministrationShell: The AAS to create
697
+ * - headers?: Optional request headers
654
698
  *
655
- * @async
656
- * @function postAssetAdministrationShell
657
- * @param baseURL The API base URL
658
- * @param assetAdministrationShell Asset Administration Shell object
659
- * @param headers Request headers
660
- * @returns {Promise<AssetAdministrationShell>} Asset Administration Shell created successfully
699
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
661
700
  */
662
- async postAssetAdministrationShell(baseURL, assetAdministrationShell, headers) {
701
+ async postAssetAdministrationShell(options) {
702
+ const { baseUrl, assetAdministrationShell, headers } = options;
663
703
  try {
664
- const client = createCustomClient(baseURL, headers);
704
+ const client = createCustomClient(baseUrl, headers);
665
705
  const { data, error } = await postAssetAdministrationShell({
666
706
  client,
667
707
  body: convertCoreAasToApiAas(assetAdministrationShell),
668
708
  });
669
709
  if (error) {
670
- console.error('Error from server:', error);
671
- throw new Error(JSON.stringify(error.messages));
710
+ return { success: false, error };
672
711
  }
673
- return convertApiAasToCoreAas(data);
712
+ return { success: true, data: convertApiAasToCoreAas(data) };
674
713
  }
675
- catch (error) {
676
- console.error('Error creating Asset Administration Shell:', error);
677
- throw error;
714
+ catch (err) {
715
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
678
716
  }
679
717
  }
680
718
  /**
681
- * Deletes an Asset Administration Shell
719
+ * Deletes an Asset Administration Shell by its unique identifier.
682
720
  *
683
- * @async
684
- * @function deleteAssetAdministrationShellById
685
- * @param baseURL The API base URL
686
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
687
- * @param headers Request headers
688
- * @returns {Promise<void>} Asset Administration Shell deleted successfully
721
+ * @param options Object containing:
722
+ * - baseUrl: The API base URL
723
+ * - aasIdentifier: The unique ID for the AAS
724
+ * - headers?: Optional request headers
725
+ *
726
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
689
727
  */
690
- async deleteAssetAdministrationShellById(baseURL, aasIdentifier, headers) {
728
+ async deleteAssetAdministrationShellById(options) {
729
+ const { baseUrl, aasIdentifier, headers } = options;
691
730
  try {
692
- const client = createCustomClient(baseURL, headers);
693
- const { error } = await deleteAssetAdministrationShellById({
731
+ const client = createCustomClient(baseUrl, headers);
732
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
733
+ const { data, error } = await deleteAssetAdministrationShellById({
694
734
  client,
695
- path: { aasIdentifier },
735
+ path: { aasIdentifier: encodedAasIdentifier },
696
736
  });
697
737
  if (error) {
698
- console.error('Error from server:', error);
699
- throw new Error(JSON.stringify(error.messages));
738
+ return { success: false, error };
700
739
  }
701
- return;
740
+ return { success: true, data };
702
741
  }
703
- catch (error) {
704
- console.error('Error deleting Asset Administration Shell:', error);
705
- throw error;
742
+ catch (err) {
743
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
706
744
  }
707
745
  }
708
746
  /**
709
- * Returns a specific Asset Administration Shell
747
+ * Returns a specific Asset Administration Shell by its unique identifier.
748
+ *
749
+ * @param options Object containing:
750
+ * - baseUrl: The API base URL
751
+ * - aasIdentifier: The unique ID
752
+ * - headers?: Optional request headers
710
753
  *
711
- * @async
712
- * @function getAssetAdministrationShellById
713
- * @param baseURL The API base URL
714
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
715
- * @param headers Request headers
716
- * @returns {Promise<AssetAdministrationShell>} Requested Asset Administration Shell
754
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
717
755
  */
718
- async getAssetAdministrationShellById(baseURL, aasIdentifier, headers) {
756
+ async getAssetAdministrationShellById(options) {
757
+ const { baseUrl, aasIdentifier, headers } = options;
719
758
  try {
720
- const client = createCustomClient(baseURL, headers);
759
+ const client = createCustomClient(baseUrl, headers);
760
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
721
761
  const { data, error } = await getAssetAdministrationShellById({
722
762
  client,
723
- path: { aasIdentifier },
763
+ path: { aasIdentifier: encodedAasIdentifier },
724
764
  });
725
765
  if (error) {
726
- console.error('Error from server:', error);
727
- throw new Error(JSON.stringify(error.messages));
766
+ return { success: false, error };
728
767
  }
729
- return convertApiAasToCoreAas(data);
768
+ return { success: true, data: convertApiAasToCoreAas(data) };
730
769
  }
731
- catch (error) {
732
- console.error('Error fetching Asset Administration Shell:', error);
733
- throw error;
770
+ catch (err) {
771
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
734
772
  }
735
773
  }
736
774
  /**
737
- * Updates an existing Asset Administration Shell
775
+ * Updates an existing Asset Administration Shell by ID (PUT).
738
776
  *
739
- * @async
740
- * @function putAssetAdministrationShellById
741
- * @param baseURL The API base URL
742
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
743
- * @param assetAdministrationShell Asset Administration Shell object
744
- * @param headers Request headers
745
- * @returns {Promise<void>} Asset Administration Shell updated successfully
777
+ * @param options Object containing:
778
+ * - baseUrl: The API base URL
779
+ * - aasIdentifier: The unique ID
780
+ * - assetAdministrationShell: The updated AAS object
781
+ * - headers?: Optional request headers
782
+ *
783
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
746
784
  */
747
- async putAssetAdministrationShellById(baseURL, aasIdentifier, assetAdministrationShell, headers) {
785
+ async putAssetAdministrationShellById(options) {
786
+ const { baseUrl, aasIdentifier, assetAdministrationShell, headers } = options;
748
787
  try {
749
- const client = createCustomClient(baseURL, headers);
750
- const { error } = await putAssetAdministrationShellById({
788
+ const client = createCustomClient(baseUrl, headers);
789
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
790
+ const { data, error } = await putAssetAdministrationShellById({
751
791
  client,
752
- path: { aasIdentifier },
792
+ path: { aasIdentifier: encodedAasIdentifier },
753
793
  body: convertCoreAasToApiAas(assetAdministrationShell),
754
794
  });
755
795
  if (error) {
756
- console.error('Error from server:', error);
757
- throw new Error(JSON.stringify(error.messages));
796
+ return { success: false, error };
758
797
  }
759
- return;
798
+ return { success: true, data };
760
799
  }
761
- catch (error) {
762
- console.error('Error updating Asset Administration Shell:', error);
763
- throw error;
800
+ catch (err) {
801
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
764
802
  }
765
803
  }
766
804
  /**
767
- * Returns the Asset Information
805
+ * Returns the AssetInformation for the given AAS.
806
+ *
807
+ * @param options Object containing:
808
+ * - baseUrl: The API base URL
809
+ * - aasIdentifier: The unique ID
810
+ * - headers?: Optional request headers
768
811
  *
769
- * @async
770
- * @function getAssetInformation
771
- * @param baseURL The API base URL
772
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
773
- * @param headers Request headers
774
- * @returns {Promise<AssetInformation>} Requested Asset Information
812
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
775
813
  */
776
- async getAssetInformation(baseURL, aasIdentifier, headers) {
814
+ async getAssetInformation(options) {
815
+ const { baseUrl, aasIdentifier, headers } = options;
777
816
  try {
778
- const client = createCustomClient(baseURL, headers);
817
+ const client = createCustomClient(baseUrl, headers);
818
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
779
819
  const { data, error } = await getAssetInformationAasRepository({
780
820
  client,
781
- path: { aasIdentifier },
821
+ path: { aasIdentifier: encodedAasIdentifier },
782
822
  });
783
823
  if (error) {
784
- console.error('Error from server:', error);
785
- throw new Error(JSON.stringify(error.messages));
824
+ return { success: false, error };
786
825
  }
787
- return convertApiAssetInformationToCoreAssetInformation(data);
826
+ return {
827
+ success: true,
828
+ data: convertApiAssetInformationToCoreAssetInformation(data),
829
+ };
788
830
  }
789
- catch (error) {
790
- console.error('Error fetching Asset Information:', error);
791
- throw error;
831
+ catch (err) {
832
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
792
833
  }
793
834
  }
794
835
  /**
795
- * Updates the Asset Information
836
+ * Updates the AssetInformation for the given AAS.
837
+ *
838
+ * @param options Object containing:
839
+ * - baseUrl: The API base URL
840
+ * - aasIdentifier: The unique ID
841
+ * - assetInformation: The updated AssetInformation object
842
+ * - headers?: Optional request headers
796
843
  *
797
- * @async
798
- * @function putAssetInformation
799
- * @param baseURL The API base URL
800
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
801
- * @param assetInformation Asset Information object
802
- * @param headers Request headers
803
- * @returns {Promise<void>} Asset Information updated successfully
844
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
804
845
  */
805
- async putAssetInformation(baseURL, aasIdentifier, assetInformation, headers) {
846
+ async putAssetInformation(options) {
847
+ const { baseUrl, aasIdentifier, assetInformation, headers } = options;
806
848
  try {
807
- const client = createCustomClient(baseURL, headers);
808
- const { error } = await putAssetInformationAasRepository({
849
+ const client = createCustomClient(baseUrl, headers);
850
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
851
+ const { data, error } = await putAssetInformationAasRepository({
809
852
  client,
810
- path: { aasIdentifier },
853
+ path: { aasIdentifier: encodedAasIdentifier },
811
854
  body: convertCoreAssetInformationToApiAssetInformation(assetInformation),
812
855
  });
813
856
  if (error) {
814
- console.error('Error from server:', error);
815
- throw new Error(JSON.stringify(error.messages));
857
+ return { success: false, error };
816
858
  }
817
- return;
859
+ return { success: true, data };
818
860
  }
819
- catch (error) {
820
- console.error('Error updating Asset Information:', error);
821
- throw error;
861
+ catch (err) {
862
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
822
863
  }
823
864
  }
824
865
  /**
825
- * Deletes the Thumbnail
866
+ * Deletes the Thumbnail associated with the given AAS.
826
867
  *
827
- * @async
828
- * @function deleteThumbnail
829
- * @param baseURL The API base URL
830
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
831
- * @param headers Request headers
832
- * @returns {Promise<void>} Thumbnail deletion successful
868
+ * @param options Object containing:
869
+ * - baseUrl: The API base URL
870
+ * - aasIdentifier: The unique ID
871
+ * - headers?: Optional request headers
872
+ *
873
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
833
874
  */
834
- async deleteThumbnail(baseURL, aasIdentifier, headers) {
875
+ async deleteThumbnail(options) {
876
+ const { baseUrl, aasIdentifier, headers } = options;
835
877
  try {
836
- const client = createCustomClient(baseURL, headers);
837
- const { error } = await deleteThumbnailAasRepository({
878
+ const client = createCustomClient(baseUrl, headers);
879
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
880
+ const { data, error } = await deleteThumbnailAasRepository({
838
881
  client,
839
- path: { aasIdentifier },
882
+ path: { aasIdentifier: encodedAasIdentifier },
840
883
  });
841
884
  if (error) {
842
- console.error('Error from server:', error);
843
- throw new Error(JSON.stringify(error.messages));
885
+ return { success: false, error };
844
886
  }
845
- return;
887
+ return {
888
+ success: true,
889
+ data: data,
890
+ };
846
891
  }
847
- catch (error) {
848
- console.error('Error deleting Thumbnail:', error);
849
- throw error;
892
+ catch (err) {
893
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
850
894
  }
851
895
  }
852
896
  /**
853
- * Returns the Thumbnail
897
+ * Returns the Thumbnail associated with an AAS, if any.
898
+ *
899
+ * @param options Object containing:
900
+ * - baseUrl: The API base URL
901
+ * - aasIdentifier: The unique ID
902
+ * - headers?: Optional request headers
854
903
  *
855
- * @async
856
- * @function getThumbnail
857
- * @param baseURL The API base URL
858
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
859
- * @param headers Request headers
860
- * @returns {Promise<Blob | File>} The thumbnail of the Asset Information.
904
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
861
905
  */
862
- async getThumbnail(baseURL, aasIdentifier, headers) {
906
+ async getThumbnail(options) {
907
+ const { baseUrl, aasIdentifier, headers } = options;
863
908
  try {
864
- const client = createCustomClient(baseURL, headers);
909
+ const client = createCustomClient(baseUrl, headers);
910
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
865
911
  const { data, error } = await getThumbnailAasRepository({
866
912
  client,
867
- path: { aasIdentifier },
913
+ path: { aasIdentifier: encodedAasIdentifier },
868
914
  });
869
915
  if (error) {
870
- console.error('Error from server:', error);
871
- throw new Error(JSON.stringify(error.messages));
916
+ return { success: false, error };
872
917
  }
873
- return data;
918
+ return { success: true, data };
874
919
  }
875
- catch (error) {
876
- console.error('Error fetching Thumbnail:', error);
877
- throw error;
920
+ catch (err) {
921
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
878
922
  }
879
923
  }
880
924
  /**
881
- * Updates the Thumbnail
925
+ * Updates (or creates) the Thumbnail for the given AAS.
882
926
  *
883
- * @async
884
- * @function putThumbnail
885
- * @param baseURL The API base URL
886
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
887
- * @param thumbnail Thumbnail to upload
888
- * @param headers Request headers
889
- * @returns {Promise<void>} Thumbnail updated successfully
927
+ * @param options Object containing:
928
+ * - baseUrl: The API base URL
929
+ * - aasIdentifier: The unique ID
930
+ * - thumbnail: The thumbnail data to upload
931
+ * - headers?: Optional request headers
932
+ *
933
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
890
934
  */
891
- async putThumbnail(baseURL, aasIdentifier, thumbnail, headers) {
935
+ async putThumbnail(options) {
936
+ const { baseUrl, aasIdentifier, thumbnail, headers } = options;
892
937
  try {
893
- const client = createCustomClient(baseURL, headers);
894
- const { error } = await putThumbnailAasRepository({
938
+ const client = createCustomClient(baseUrl, headers);
939
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
940
+ const { data, error } = await putThumbnailAasRepository({
895
941
  client,
896
- path: { aasIdentifier },
942
+ path: { aasIdentifier: encodedAasIdentifier },
897
943
  body: thumbnail,
898
944
  });
899
945
  if (error) {
900
- console.error('Error from server:', error);
901
- throw new Error(JSON.stringify(error.messages));
946
+ return { success: false, error };
902
947
  }
903
- return;
948
+ return { success: true, data };
904
949
  }
905
- catch (error) {
906
- console.error('Error updating Thumbnail:', error);
907
- throw error;
950
+ catch (err) {
951
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
908
952
  }
909
953
  }
910
954
  /**
911
- * Returns all submodel references
955
+ * Returns all submodel references for the given AAS.
956
+ *
957
+ * @param options Object containing:
958
+ * - baseUrl: The API base URL
959
+ * - aasIdentifier: The unique ID
960
+ * - headers?: Optional request headers
961
+ * - limit?: Max number of elements
962
+ * - cursor?: Paging cursor
912
963
  *
913
- * @async
914
- * @function getAllSubmodelReferences
915
- * @param baseURL The API base URL
916
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
917
- * @param headers Request headers
918
- * @param limit The maximum number of elements in the response array
919
- * @param cursor A server-generated identifier retrieved from pagingMetadata that specifies from which position the result listing should continue
920
- * @returns {Promise<getAllSubmodelReferencesResponse>} Requested submodel references
964
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
921
965
  */
922
- async getAllSubmodelReferences(baseURL, aasIdentifier, headers, limit, cursor) {
966
+ async getAllSubmodelReferences(options) {
967
+ const { baseUrl, aasIdentifier, headers, limit, cursor } = options;
923
968
  try {
924
- const client = createCustomClient(baseURL, headers);
969
+ const client = createCustomClient(baseUrl, headers);
970
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
925
971
  const { data, error } = await getAllSubmodelReferencesAasRepository({
926
972
  client,
927
- path: { aasIdentifier },
928
- query: {
929
- limit,
930
- cursor,
931
- },
973
+ path: { aasIdentifier: encodedAasIdentifier },
974
+ query: { limit, cursor },
932
975
  });
933
976
  if (error) {
934
- console.error('Error from server:', error);
935
- throw new Error(JSON.stringify(error.messages));
977
+ return { success: false, error };
936
978
  }
937
979
  const submodelReferences = (data.result ?? []).map(convertApiReferenceToCoreReference);
938
980
  return {
939
- pagedResult: data.paging_metadata,
940
- result: submodelReferences,
981
+ success: true,
982
+ data: {
983
+ pagedResult: data.paging_metadata,
984
+ result: submodelReferences,
985
+ },
941
986
  };
942
987
  }
943
- catch (error) {
944
- console.error('Error fetching Submodel References:', error);
945
- throw error;
988
+ catch (err) {
989
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
946
990
  }
947
991
  }
948
992
  /**
949
- * Creates a submodel reference at the Asset Administration Shell
993
+ * Creates a submodel reference at the given AAS.
950
994
  *
951
- * @async
952
- * @function postSubmodelReference
953
- * @param baseURL The API base URL
954
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
955
- * @param submodelReference Reference to the Submodel
956
- * @param headers Request headers
957
- * @returns {promise<Reference>} Submodel reference created successfully
995
+ * @param options Object containing:
996
+ * - baseUrl: The API base URL
997
+ * - aasIdentifier: The unique ID of the AAS
998
+ * - submodelReference: The Reference to the submodel
999
+ * - headers?: Optional request headers
1000
+ *
1001
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
958
1002
  */
959
- async postSubmodelReference(baseURL, aasIdentifier, submodelReference, headers) {
1003
+ async postSubmodelReference(options) {
1004
+ const { baseUrl, aasIdentifier, submodelReference, headers } = options;
960
1005
  try {
961
- const client = createCustomClient(baseURL, headers);
1006
+ const client = createCustomClient(baseUrl, headers);
1007
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
962
1008
  const { data, error } = await postSubmodelReferenceAasRepository({
963
1009
  client,
964
- path: { aasIdentifier },
1010
+ path: { aasIdentifier: encodedAasIdentifier },
965
1011
  body: convertCoreReferenceToApiReference(submodelReference),
966
1012
  });
967
1013
  if (error) {
968
- console.error('Error from server:', error);
969
- throw new Error(JSON.stringify(error.messages));
1014
+ return { success: false, error };
970
1015
  }
971
- return convertApiReferenceToCoreReference(data);
1016
+ return { success: true, data: convertApiReferenceToCoreReference(data) };
972
1017
  }
973
- catch (error) {
974
- console.error('Error creating Submodel Reference:', error);
975
- throw error;
1018
+ catch (err) {
1019
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
976
1020
  }
977
1021
  }
978
1022
  /**
979
- * Deletes the submodel reference from the Asset Administration Shell. Does not delete the submodel itself!
1023
+ * Deletes a submodel reference from the given AAS (does not delete the submodel itself).
1024
+ *
1025
+ * @param options Object containing:
1026
+ * - baseUrl: The API base URL
1027
+ * - aasIdentifier: Unique ID of the AAS
1028
+ * - submodelIdentifier: The submodel's unique ID
1029
+ * - headers?: Optional request headers
980
1030
  *
981
- * @async
982
- * @function deleteSubmodelReferenceById
983
- * @param baseURL The API base URL
984
- * @param aasIdentifier The Asset Administration Shell’s unique id (UTF8-BASE64-URL-encoded)
985
- * @param submodelIdentifier The Submodel’s unique id (UTF8-BASE64-URL-encoded)
986
- * @param headers Request headers
987
- * @returns {Promise<void>} Submodel reference deleted successfully
1031
+ * @returns Either `{ success: true; data: ... }` or `{ success: false; error: ... }`.
988
1032
  */
989
- async deleteSubmodelReferenceById(baseURL, aasIdentifier, submodelIdentifier, headers) {
1033
+ async deleteSubmodelReferenceById(options) {
1034
+ const { baseUrl, aasIdentifier, submodelIdentifier, headers } = options;
990
1035
  try {
991
- const client = createCustomClient(baseURL, headers);
992
- const { error } = await deleteSubmodelReferenceByIdAasRepository({
1036
+ const client = createCustomClient(baseUrl, headers);
1037
+ const encodedAasIdentifier = base64Encode(aasIdentifier);
1038
+ const encodedSubmodelIdentifier = base64Encode(submodelIdentifier);
1039
+ const { data, error } = await deleteSubmodelReferenceByIdAasRepository({
993
1040
  client,
994
- path: { aasIdentifier, submodelIdentifier },
1041
+ path: {
1042
+ aasIdentifier: encodedAasIdentifier,
1043
+ submodelIdentifier: encodedSubmodelIdentifier,
1044
+ },
995
1045
  });
996
1046
  if (error) {
997
- console.error('Error from server:', error);
998
- throw new Error(JSON.stringify(error.messages));
1047
+ return { success: false, error };
999
1048
  }
1000
- return;
1049
+ return { success: true, data };
1001
1050
  }
1002
- catch (error) {
1003
- console.error('Error deleting Submodel Reference:', error);
1004
- throw error;
1051
+ catch (err) {
1052
+ return { success: false, error: err instanceof Error ? err : new Error(String(err)) };
1005
1053
  }
1006
1054
  }
1007
1055
  }
1008
1056
 
1009
- export { AasRepositoryClient };
1057
+ var index = /*#__PURE__*/Object.freeze({
1058
+ __proto__: null
1059
+ });
1060
+
1061
+ export { AasRepositoryClient, types_gen as AasTypes, index as Models };
1010
1062
  //# sourceMappingURL=index.js.map