@startinblox/core 2.0.5-beta.5 → 2.0.6-beta.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.
@@ -171,6 +171,9 @@ let __tla = (async () => {
171
171
  __publicField(this, "authToken", null);
172
172
  __publicField(this, "contractNegotiations", /* @__PURE__ */ new Map());
173
173
  __publicField(this, "transferProcesses", /* @__PURE__ */ new Map());
174
+ __publicField(this, "contractAgreements", /* @__PURE__ */ new Map());
175
+ __publicField(this, "assetAgreements", /* @__PURE__ */ new Map());
176
+ __publicField(this, "edrTokens", /* @__PURE__ */ new Map());
174
177
  var _a2, _b;
175
178
  this.validateConfig(config);
176
179
  this.config = config;
@@ -192,6 +195,15 @@ let __tla = (async () => {
192
195
  if (missing.length > 0) {
193
196
  throw new Error(`Missing required configuration: ${missing.join(", ")}`);
194
197
  }
198
+ if (!config.edrsEndpoint) {
199
+ config.edrsEndpoint = config.catalogEndpoint.replace("/catalog/request", "/edrs");
200
+ }
201
+ if (!config.publicEndpoint) {
202
+ if (config.endpoint) {
203
+ const baseUrl = config.endpoint.replace("/management", "");
204
+ config.publicEndpoint = `${baseUrl}/public`;
205
+ }
206
+ }
195
207
  }
196
208
  async getData(args) {
197
209
  if ("targetType" in args) {
@@ -216,7 +228,6 @@ let __tla = (async () => {
216
228
  async getCatalog(counterPartyAddress) {
217
229
  await this.ensureAuthenticated();
218
230
  const catalogRequest = this.buildV3CatalogRequest(counterPartyAddress);
219
- console.log("Sending v3 catalog request:", JSON.stringify(catalogRequest, null, 2));
220
231
  const response = await this.fetchAuthn(this.config.catalogEndpoint, {
221
232
  method: "POST",
222
233
  headers: this.headers,
@@ -280,6 +291,110 @@ let __tla = (async () => {
280
291
  getNegotiationStatus(negotiationId) {
281
292
  return this._getNegotiationStatus(negotiationId);
282
293
  }
294
+ async getContractAgreement(negotiationId) {
295
+ await this.ensureAuthenticated();
296
+ try {
297
+ const response = await this.fetchAuthn(`${this.config.contractNegotiationEndpoint}/${negotiationId}/agreement`, {
298
+ method: "GET",
299
+ headers: this.headers
300
+ });
301
+ if (!response.ok) {
302
+ console.error(`Failed to get contract agreement: ${response.status} ${response.statusText}`);
303
+ return null;
304
+ }
305
+ const agreement = await response.json();
306
+ this.contractAgreements.set(agreement["@id"], agreement);
307
+ const assetId = agreement.assetId;
308
+ if (assetId) {
309
+ const existing = this.assetAgreements.get(assetId);
310
+ const mapping = {
311
+ assetId,
312
+ catalogId: existing == null ? void 0 : existing.catalogId,
313
+ agreementId: agreement["@id"],
314
+ agreement,
315
+ negotiationId,
316
+ transferId: existing == null ? void 0 : existing.transferId,
317
+ edrToken: existing == null ? void 0 : existing.edrToken,
318
+ createdAt: (existing == null ? void 0 : existing.createdAt) || Date.now(),
319
+ lastUpdated: Date.now()
320
+ };
321
+ this.assetAgreements.set(assetId, mapping);
322
+ }
323
+ return agreement;
324
+ } catch (error2) {
325
+ console.error("Error retrieving contract agreement:", error2);
326
+ return null;
327
+ }
328
+ }
329
+ getStoredContractAgreement(assetId) {
330
+ const mapping = this.assetAgreements.get(assetId);
331
+ return (mapping == null ? void 0 : mapping.agreement) || null;
332
+ }
333
+ async getAllContractNegotiations() {
334
+ await this.ensureAuthenticated();
335
+ try {
336
+ const requestEndpoint = `${this.config.contractNegotiationEndpoint}/request`;
337
+ const response = await this.fetchAuthn(requestEndpoint, {
338
+ method: "POST",
339
+ headers: this.headers,
340
+ body: JSON.stringify({
341
+ "@context": {
342
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/"
343
+ },
344
+ "@type": "QuerySpec",
345
+ offset: 0,
346
+ limit: 1e3
347
+ })
348
+ });
349
+ if (!response.ok) {
350
+ const getResponse = await this.fetchAuthn(`${this.config.contractNegotiationEndpoint}?offset=0&limit=1000`, {
351
+ method: "GET",
352
+ headers: this.headers
353
+ });
354
+ if (!getResponse.ok) {
355
+ console.warn(`Failed to fetch contract negotiations: ${getResponse.status} ${getResponse.statusText}`);
356
+ return [];
357
+ }
358
+ const getData = await getResponse.json();
359
+ return Array.isArray(getData) ? getData : getData.items || [];
360
+ }
361
+ const data = await response.json();
362
+ return Array.isArray(data) ? data : data.items || [];
363
+ } catch (error2) {
364
+ console.error("Error fetching contract negotiations:", error2);
365
+ return [];
366
+ }
367
+ }
368
+ async loadExistingAgreements() {
369
+ try {
370
+ const negotiations = await this.getAllContractNegotiations();
371
+ let _loadedCount = 0;
372
+ for (const negotiation of negotiations) {
373
+ if (negotiation.state === "FINALIZED" || negotiation.state === "AGREED") {
374
+ try {
375
+ const agreement = await this.getContractAgreement(negotiation["@id"]);
376
+ if (agreement) {
377
+ _loadedCount++;
378
+ }
379
+ } catch (error2) {
380
+ console.warn(`\u26A0\uFE0F Failed to load agreement for negotiation ${negotiation["@id"]}:`, error2);
381
+ }
382
+ }
383
+ }
384
+ } catch (error2) {
385
+ console.error("Error loading existing agreements:", error2);
386
+ }
387
+ }
388
+ getAllAssetAgreements() {
389
+ return Array.from(this.assetAgreements.values());
390
+ }
391
+ getAssetAgreement(assetId) {
392
+ return this.assetAgreements.get(assetId) || null;
393
+ }
394
+ hasValidAgreement(assetId) {
395
+ const agreement = this.getAssetAgreement(assetId);
396
+ return agreement !== null;
397
+ }
283
398
  async initiateTransfer(counterPartyAddress, contractId, dataDestination) {
284
399
  await this.ensureAuthenticated();
285
400
  const transferRequest = {
@@ -305,21 +420,173 @@ let __tla = (async () => {
305
420
  this.transferProcesses.set(transferId, transfer);
306
421
  return transferId;
307
422
  }
423
+ async initiateEDRTransfer(assetId, counterPartyAddress, contractId) {
424
+ await this.ensureAuthenticated();
425
+ const edrRequest = {
426
+ "@context": {
427
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/"
428
+ },
429
+ "@type": "https://w3id.org/edc/v0.0.1/ns/TransferRequest",
430
+ assetId,
431
+ protocol: "dataspace-protocol-http",
432
+ counterPartyAddress,
433
+ contractId,
434
+ transferType: "HttpData-PULL",
435
+ dataDestination: {
436
+ type: "HttpProxy"
437
+ }
438
+ };
439
+ const response = await this.fetchAuthn(this.config.transferProcessEndpoint, {
440
+ method: "POST",
441
+ headers: this.headers,
442
+ body: JSON.stringify(edrRequest)
443
+ });
444
+ if (!response.ok) {
445
+ const errorText = await response.text();
446
+ throw new Error(`EDR transfer initiation failed: ${response.status} ${response.statusText} - ${errorText}`);
447
+ }
448
+ const edrResponse = await response.json();
449
+ const transferId = edrResponse["@id"];
450
+ const mapping = this.assetAgreements.get(assetId);
451
+ if (mapping) {
452
+ mapping.transferId = transferId;
453
+ mapping.lastUpdated = Date.now();
454
+ this.assetAgreements.set(assetId, mapping);
455
+ }
456
+ return transferId;
457
+ }
458
+ async getEDRToken(transferId, maxRetries = 10, retryDelay = 2e3) {
459
+ await this.ensureAuthenticated();
460
+ const edrsEndpoint = this.config.edrsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", "/edrs");
461
+ const requestUrl = `${edrsEndpoint}/${transferId}/dataaddress`;
462
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
463
+ try {
464
+ const response = await this.fetchAuthn(requestUrl, {
465
+ method: "GET",
466
+ headers: this.headers
467
+ });
468
+ if (response.ok) {
469
+ const edrDataAddress = await response.json();
470
+ this.edrTokens.set(transferId, edrDataAddress);
471
+ const assetMapping = Array.from(this.assetAgreements.values()).find((mapping) => mapping.transferId === transferId);
472
+ if (assetMapping) {
473
+ assetMapping.edrToken = edrDataAddress.authorization;
474
+ assetMapping.lastUpdated = Date.now();
475
+ }
476
+ return edrDataAddress;
477
+ }
478
+ const errorText = await response.text();
479
+ let errorObj;
480
+ try {
481
+ errorObj = JSON.parse(errorText);
482
+ } catch (_e) {
483
+ errorObj = {
484
+ message: errorText
485
+ };
486
+ }
487
+ console.warn(`\u26A0\uFE0F EDR token attempt ${attempt}/${maxRetries} failed: ${response.status} ${response.statusText}`, errorObj);
488
+ if (response.status === 404 && attempt < maxRetries) {
489
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
490
+ continue;
491
+ }
492
+ console.error(`\u274C Final EDR token retrieval failed: ${response.status} ${response.statusText}`, errorObj);
493
+ console.error(`\u{1F517} Request URL: ${requestUrl}`);
494
+ console.error(`\u{1F194} Transfer ID used: ${transferId}`);
495
+ throw new Error(`EDR token retrieval failed: ${response.status} ${response.statusText} - ${errorObj.message || errorText}`);
496
+ } catch (error2) {
497
+ if (attempt === maxRetries) {
498
+ throw error2;
499
+ }
500
+ console.warn(`\u26A0\uFE0F EDR token attempt ${attempt}/${maxRetries} error:`, error2);
501
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
502
+ }
503
+ }
504
+ throw new Error(`Failed to retrieve EDR token after ${maxRetries} attempts`);
505
+ }
506
+ getStoredEDRToken(transferId) {
507
+ return this.edrTokens.get(transferId) || null;
508
+ }
509
+ async fetchWithEDRToken(edrDataAddress, additionalPath) {
510
+ const { endpoint, authorization } = edrDataAddress;
511
+ const url2 = additionalPath ? `${endpoint}${additionalPath}` : endpoint;
512
+ try {
513
+ const response = await fetch(url2, {
514
+ method: "GET",
515
+ headers: {
516
+ Authorization: authorization,
517
+ Accept: "application/json"
518
+ },
519
+ mode: "cors"
520
+ });
521
+ if (!response.ok) {
522
+ throw new Error(`EDR data fetch failed: ${response.status} ${response.statusText}`);
523
+ }
524
+ return await response.json();
525
+ } catch (error2) {
526
+ console.error("Error fetching data with EDR token:", error2);
527
+ throw error2;
528
+ }
529
+ }
530
+ async accessAssetData(assetId, counterPartyAddress, policy, counterPartyId, additionalPath) {
531
+ try {
532
+ const existingMapping = this.assetAgreements.get(assetId);
533
+ if ((existingMapping == null ? void 0 : existingMapping.edrToken) && existingMapping.transferId) {
534
+ const edrDataAddress = this.edrTokens.get(existingMapping.transferId);
535
+ if (edrDataAddress) {
536
+ return await this.fetchWithEDRToken(edrDataAddress, additionalPath);
537
+ }
538
+ }
539
+ const negotiationId = await this.negotiateContract(counterPartyAddress, assetId, policy, counterPartyId);
540
+ return {
541
+ negotiationId,
542
+ status: "negotiation_initiated"
543
+ };
544
+ } catch (error2) {
545
+ console.error("Error in complete asset access flow:", error2);
546
+ throw error2;
547
+ }
548
+ }
549
+ async continueAssetAccess(negotiationId, assetId, counterPartyAddress, additionalPath) {
550
+ try {
551
+ const agreement = await this.getContractAgreement(negotiationId);
552
+ if (!agreement) {
553
+ throw new Error("Failed to retrieve contract agreement");
554
+ }
555
+ const transferId = await this.initiateEDRTransfer(assetId, counterPartyAddress, agreement["@id"]);
556
+ const edrDataAddress = await this.getEDRToken(transferId);
557
+ if (!edrDataAddress) {
558
+ throw new Error("Failed to retrieve EDR token");
559
+ }
560
+ const data = await this.fetchWithEDRToken(edrDataAddress, additionalPath);
561
+ return data;
562
+ } catch (error2) {
563
+ console.error("Error continuing asset access flow:", error2);
564
+ throw error2;
565
+ }
566
+ }
567
+ async accessStoredAssetData(assetId, additionalPath) {
568
+ const mapping = this.assetAgreements.get(assetId);
569
+ if (!(mapping == null ? void 0 : mapping.transferId)) {
570
+ throw new Error(`No stored transfer information for asset: ${assetId}`);
571
+ }
572
+ const edrDataAddress = this.edrTokens.get(mapping.transferId);
573
+ if (!edrDataAddress) {
574
+ throw new Error(`No stored EDR token for asset: ${assetId}`);
575
+ }
576
+ return await this.fetchWithEDRToken(edrDataAddress, additionalPath);
577
+ }
308
578
  async fetchThroughDataspace(resourceId) {
309
579
  try {
310
- console.log(`Fetching resource through dataspace: ${resourceId}`);
311
580
  const catalog = await this.getCatalog();
312
581
  if (!catalog) {
313
582
  console.error("No catalog available");
314
583
  return null;
315
584
  }
316
- console.log("Catalog received:", catalog);
317
585
  const dataset2 = this.findDatasetInCatalog(catalog, resourceId);
318
586
  if (!dataset2) {
319
587
  console.error(`Dataset ${resourceId} not found in catalog`);
320
588
  return null;
321
589
  }
322
- console.log("Dataset found:", dataset2);
323
590
  return catalog;
324
591
  } catch (error2) {
325
592
  console.error("Dataspace fetch failed:", error2);
@@ -568,6 +835,331 @@ let __tla = (async () => {
568
835
  sortOrder: "ASC"
569
836
  };
570
837
  }
838
+ async getAllAssets(querySpec) {
839
+ return this.getAssets(querySpec);
840
+ }
841
+ async getAsset(assetId) {
842
+ await this.ensureAuthenticated();
843
+ const apiVersion = this.config.apiVersion || "v3";
844
+ const assetsEndpoint = this.config.assetsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/assets" : "/assets");
845
+ const response = await this.fetchAuthn(`${assetsEndpoint}/${assetId}`, {
846
+ method: "GET",
847
+ headers: this.headers
848
+ });
849
+ if (!response.ok) {
850
+ if (response.status === 404) {
851
+ return null;
852
+ }
853
+ throw new Error(`Failed to get asset: ${response.status} ${response.statusText}`);
854
+ }
855
+ const asset = await response.json();
856
+ if (asset["@id"]) {
857
+ await this.cache.set(asset["@id"], asset);
858
+ }
859
+ return asset;
860
+ }
861
+ async createAsset(assetInput) {
862
+ await this.ensureAuthenticated();
863
+ const apiVersion = this.config.apiVersion || "v3";
864
+ const assetsEndpoint = this.config.assetsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/assets" : "/assets");
865
+ const assetData = {
866
+ "@context": {
867
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
868
+ edc: "https://w3id.org/edc/v0.0.1/ns/"
869
+ },
870
+ "@type": "Asset",
871
+ "@id": assetInput["@id"],
872
+ properties: assetInput.properties || {},
873
+ dataAddress: assetInput.dataAddress
874
+ };
875
+ const response = await this.fetchAuthn(assetsEndpoint, {
876
+ method: "POST",
877
+ headers: this.headers,
878
+ body: JSON.stringify(assetData)
879
+ });
880
+ if (!response.ok) {
881
+ const errorText = await response.text();
882
+ throw new Error(`Failed to create asset: ${response.status} ${response.statusText} - ${errorText}`);
883
+ }
884
+ let createdAsset;
885
+ try {
886
+ createdAsset = await response.json();
887
+ } catch {
888
+ createdAsset = {
889
+ "@type": "Asset",
890
+ "@id": assetInput["@id"],
891
+ properties: assetInput.properties,
892
+ dataAddress: assetInput.dataAddress,
893
+ createdAt: Date.now()
894
+ };
895
+ }
896
+ if (createdAsset["@id"]) {
897
+ await this.cache.set(createdAsset["@id"], createdAsset);
898
+ }
899
+ return createdAsset;
900
+ }
901
+ async updateAsset(assetId, assetInput) {
902
+ await this.ensureAuthenticated();
903
+ const apiVersion = this.config.apiVersion || "v3";
904
+ const assetsEndpoint = this.config.assetsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/assets" : "/assets");
905
+ const assetData = {
906
+ "@context": {
907
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
908
+ edc: "https://w3id.org/edc/v0.0.1/ns/"
909
+ },
910
+ "@type": "Asset",
911
+ "@id": assetInput["@id"],
912
+ properties: assetInput.properties || {},
913
+ dataAddress: assetInput.dataAddress
914
+ };
915
+ const response = await this.fetchAuthn(`${assetsEndpoint}/${assetId}`, {
916
+ method: "PUT",
917
+ headers: this.headers,
918
+ body: JSON.stringify(assetData)
919
+ });
920
+ if (!response.ok) {
921
+ const errorText = await response.text();
922
+ throw new Error(`Failed to update asset: ${response.status} ${response.statusText} - ${errorText}`);
923
+ }
924
+ const updatedAsset = {
925
+ "@type": "Asset",
926
+ "@id": assetInput["@id"],
927
+ properties: assetInput.properties,
928
+ dataAddress: assetInput.dataAddress,
929
+ createdAt: Date.now()
930
+ };
931
+ await this.cache.set(assetId, updatedAsset);
932
+ return updatedAsset;
933
+ }
934
+ async deleteAsset(assetId) {
935
+ await this.ensureAuthenticated();
936
+ const apiVersion = this.config.apiVersion || "v3";
937
+ const assetsEndpoint = this.config.assetsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/assets" : "/assets");
938
+ const response = await this.fetchAuthn(`${assetsEndpoint}/${assetId}`, {
939
+ method: "DELETE",
940
+ headers: this.headers
941
+ });
942
+ if (!response.ok) {
943
+ const errorText = await response.text();
944
+ throw new Error(`Failed to delete asset: ${response.status} ${response.statusText} - ${errorText}`);
945
+ }
946
+ await this.cache.delete(assetId);
947
+ return true;
948
+ }
949
+ async getAllPolicies(querySpec) {
950
+ return this.getPolicyDefinitions(querySpec);
951
+ }
952
+ async getPolicy(policyId) {
953
+ await this.ensureAuthenticated();
954
+ const apiVersion = this.config.apiVersion || "v3";
955
+ const policiesEndpoint = this.config.policiesEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/policydefinitions" : "/policydefinitions");
956
+ const response = await this.fetchAuthn(`${policiesEndpoint}/${policyId}`, {
957
+ method: "GET",
958
+ headers: this.headers
959
+ });
960
+ if (!response.ok) {
961
+ if (response.status === 404) {
962
+ return null;
963
+ }
964
+ throw new Error(`Failed to get policy: ${response.status} ${response.statusText}`);
965
+ }
966
+ const policy = await response.json();
967
+ if (policy["@id"]) {
968
+ await this.cache.set(policy["@id"], policy);
969
+ }
970
+ return policy;
971
+ }
972
+ async createPolicy(policyInput) {
973
+ await this.ensureAuthenticated();
974
+ const apiVersion = this.config.apiVersion || "v3";
975
+ const policiesEndpoint = this.config.policiesEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/policydefinitions" : "/policydefinitions");
976
+ const policyData = {
977
+ "@context": {
978
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
979
+ edc: "https://w3id.org/edc/v0.0.1/ns/",
980
+ odrl: "http://www.w3.org/ns/odrl/2/"
981
+ },
982
+ "@type": "PolicyDefinition",
983
+ "@id": policyInput["@id"],
984
+ policy: policyInput.policy
985
+ };
986
+ const response = await this.fetchAuthn(policiesEndpoint, {
987
+ method: "POST",
988
+ headers: this.headers,
989
+ body: JSON.stringify(policyData)
990
+ });
991
+ if (!response.ok) {
992
+ const errorText = await response.text();
993
+ throw new Error(`Failed to create policy: ${response.status} ${response.statusText} - ${errorText}`);
994
+ }
995
+ const createdPolicy = {
996
+ "@type": "PolicyDefinition",
997
+ "@id": policyInput["@id"],
998
+ policy: policyInput.policy,
999
+ createdAt: Date.now()
1000
+ };
1001
+ if (createdPolicy["@id"]) {
1002
+ await this.cache.set(createdPolicy["@id"], createdPolicy);
1003
+ }
1004
+ return createdPolicy;
1005
+ }
1006
+ async updatePolicy(policyId, policyInput) {
1007
+ await this.ensureAuthenticated();
1008
+ const apiVersion = this.config.apiVersion || "v3";
1009
+ const policiesEndpoint = this.config.policiesEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/policydefinitions" : "/policydefinitions");
1010
+ const policyData = {
1011
+ "@context": {
1012
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
1013
+ edc: "https://w3id.org/edc/v0.0.1/ns/",
1014
+ odrl: "http://www.w3.org/ns/odrl/2/"
1015
+ },
1016
+ "@type": "PolicyDefinition",
1017
+ "@id": policyInput["@id"],
1018
+ policy: policyInput.policy
1019
+ };
1020
+ const response = await this.fetchAuthn(`${policiesEndpoint}/${policyId}`, {
1021
+ method: "PUT",
1022
+ headers: this.headers,
1023
+ body: JSON.stringify(policyData)
1024
+ });
1025
+ if (!response.ok) {
1026
+ const errorText = await response.text();
1027
+ throw new Error(`Failed to update policy: ${response.status} ${response.statusText} - ${errorText}`);
1028
+ }
1029
+ const updatedPolicy = {
1030
+ "@type": "PolicyDefinition",
1031
+ "@id": policyInput["@id"],
1032
+ policy: policyInput.policy,
1033
+ createdAt: Date.now()
1034
+ };
1035
+ await this.cache.set(policyId, updatedPolicy);
1036
+ return updatedPolicy;
1037
+ }
1038
+ async deletePolicy(policyId) {
1039
+ await this.ensureAuthenticated();
1040
+ const apiVersion = this.config.apiVersion || "v3";
1041
+ const policiesEndpoint = this.config.policiesEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/policydefinitions" : "/policydefinitions");
1042
+ const response = await this.fetchAuthn(`${policiesEndpoint}/${policyId}`, {
1043
+ method: "DELETE",
1044
+ headers: this.headers
1045
+ });
1046
+ if (!response.ok) {
1047
+ const errorText = await response.text();
1048
+ throw new Error(`Failed to delete policy: ${response.status} ${response.statusText} - ${errorText}`);
1049
+ }
1050
+ await this.cache.delete(policyId);
1051
+ return true;
1052
+ }
1053
+ async getAllContractDefinitions(querySpec) {
1054
+ return this.getContractDefinitions(querySpec);
1055
+ }
1056
+ async getContractDefinition(contractId) {
1057
+ await this.ensureAuthenticated();
1058
+ const apiVersion = this.config.apiVersion || "v3";
1059
+ const contractDefsEndpoint = this.config.contractDefinitionsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/contractdefinitions" : "/contractdefinitions");
1060
+ const response = await this.fetchAuthn(`${contractDefsEndpoint}/${contractId}`, {
1061
+ method: "GET",
1062
+ headers: this.headers
1063
+ });
1064
+ if (!response.ok) {
1065
+ if (response.status === 404) {
1066
+ return null;
1067
+ }
1068
+ throw new Error(`Failed to get contract definition: ${response.status} ${response.statusText}`);
1069
+ }
1070
+ const contract = await response.json();
1071
+ if (contract["@id"]) {
1072
+ await this.cache.set(contract["@id"], contract);
1073
+ }
1074
+ return contract;
1075
+ }
1076
+ async createContractDefinition(contractInput) {
1077
+ await this.ensureAuthenticated();
1078
+ const apiVersion = this.config.apiVersion || "v3";
1079
+ const contractDefsEndpoint = this.config.contractDefinitionsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/contractdefinitions" : "/contractdefinitions");
1080
+ const contractData = {
1081
+ "@context": {
1082
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
1083
+ edc: "https://w3id.org/edc/v0.0.1/ns/"
1084
+ },
1085
+ "@type": "ContractDefinition",
1086
+ "@id": contractInput["@id"],
1087
+ accessPolicyId: contractInput.accessPolicyId,
1088
+ contractPolicyId: contractInput.contractPolicyId,
1089
+ assetsSelector: contractInput.assetsSelector || []
1090
+ };
1091
+ const response = await this.fetchAuthn(contractDefsEndpoint, {
1092
+ method: "POST",
1093
+ headers: this.headers,
1094
+ body: JSON.stringify(contractData)
1095
+ });
1096
+ if (!response.ok) {
1097
+ const errorText = await response.text();
1098
+ throw new Error(`Failed to create contract definition: ${response.status} ${response.statusText} - ${errorText}`);
1099
+ }
1100
+ const createdContract = {
1101
+ "@type": "ContractDefinition",
1102
+ "@id": contractInput["@id"],
1103
+ accessPolicyId: contractInput.accessPolicyId,
1104
+ contractPolicyId: contractInput.contractPolicyId,
1105
+ assetsSelector: contractInput.assetsSelector,
1106
+ createdAt: Date.now()
1107
+ };
1108
+ if (createdContract["@id"]) {
1109
+ await this.cache.set(createdContract["@id"], createdContract);
1110
+ }
1111
+ return createdContract;
1112
+ }
1113
+ async updateContractDefinition(contractId, contractInput) {
1114
+ await this.ensureAuthenticated();
1115
+ const apiVersion = this.config.apiVersion || "v3";
1116
+ const contractDefsEndpoint = this.config.contractDefinitionsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/contractdefinitions" : "/contractdefinitions");
1117
+ const contractData = {
1118
+ "@context": {
1119
+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
1120
+ edc: "https://w3id.org/edc/v0.0.1/ns/"
1121
+ },
1122
+ "@type": "ContractDefinition",
1123
+ "@id": contractInput["@id"],
1124
+ accessPolicyId: contractInput.accessPolicyId,
1125
+ contractPolicyId: contractInput.contractPolicyId,
1126
+ assetsSelector: contractInput.assetsSelector || []
1127
+ };
1128
+ const response = await this.fetchAuthn(`${contractDefsEndpoint}/${contractId}`, {
1129
+ method: "PUT",
1130
+ headers: this.headers,
1131
+ body: JSON.stringify(contractData)
1132
+ });
1133
+ if (!response.ok) {
1134
+ const errorText = await response.text();
1135
+ throw new Error(`Failed to update contract definition: ${response.status} ${response.statusText} - ${errorText}`);
1136
+ }
1137
+ const updatedContract = {
1138
+ "@type": "ContractDefinition",
1139
+ "@id": contractInput["@id"],
1140
+ accessPolicyId: contractInput.accessPolicyId,
1141
+ contractPolicyId: contractInput.contractPolicyId,
1142
+ assetsSelector: contractInput.assetsSelector,
1143
+ createdAt: Date.now()
1144
+ };
1145
+ await this.cache.set(contractId, updatedContract);
1146
+ return updatedContract;
1147
+ }
1148
+ async deleteContractDefinition(contractId) {
1149
+ await this.ensureAuthenticated();
1150
+ const apiVersion = this.config.apiVersion || "v3";
1151
+ const contractDefsEndpoint = this.config.contractDefinitionsEndpoint || this.config.catalogEndpoint.replace("/catalog/request", apiVersion === "v3" ? "/contractdefinitions" : "/contractdefinitions");
1152
+ const response = await this.fetchAuthn(`${contractDefsEndpoint}/${contractId}`, {
1153
+ method: "DELETE",
1154
+ headers: this.headers
1155
+ });
1156
+ if (!response.ok) {
1157
+ const errorText = await response.text();
1158
+ throw new Error(`Failed to delete contract definition: ${response.status} ${response.statusText} - ${errorText}`);
1159
+ }
1160
+ await this.cache.delete(contractId);
1161
+ return true;
1162
+ }
571
1163
  async fetchAuthn(iri, options) {
572
1164
  await this.ensureAuthenticated();
573
1165
  return fetch(iri, {
@@ -662,9 +1254,7 @@ let __tla = (async () => {
662
1254
  return token;
663
1255
  }
664
1256
  async getAllSelfDescriptions() {
665
- console.log("Fetching all self-descriptions from Federated Catalogue...", this.fcBaseUrl);
666
1257
  const token = await this.connect();
667
- console.log("Token received:", token);
668
1258
  const url2 = `${this.fcBaseUrl}/self-descriptions`;
669
1259
  const headers = new Headers({
670
1260
  Authorization: `Bearer ${token}`
@@ -672,7 +1262,6 @@ let __tla = (async () => {
672
1262
  const response = await fetch(url2, {
673
1263
  headers
674
1264
  });
675
- console.log("Response status:", response.status);
676
1265
  return await response.json();
677
1266
  }
678
1267
  async getSelfDescriptionByHash(sdHash) {
@@ -839,7 +1428,6 @@ let __tla = (async () => {
839
1428
  try {
840
1429
  if (await this.cache.has(id)) {
841
1430
  await this.cache.delete(id);
842
- console.log(`[FederatedCatalogueStore] Cleared cache for ${id}`);
843
1431
  }
844
1432
  } catch (error2) {
845
1433
  console.error(`[FederatedCatalogueStore] Error clearing cache for ${id}:`, error2);
@@ -848,7 +1436,6 @@ let __tla = (async () => {
848
1436
  async cacheResource(key, resourceProxy) {
849
1437
  try {
850
1438
  await this.cache.set(key, resourceProxy);
851
- console.log(`[FederatedCatalogueStore] Cached resource ${key}`);
852
1439
  } catch (error2) {
853
1440
  console.error(`[FederatedCatalogueStore] Error caching resource ${key}:`, error2);
854
1441
  }
@@ -873,7 +1460,6 @@ let __tla = (async () => {
873
1460
  "@id": id
874
1461
  };
875
1462
  await this.cache.set(id, resourceWithId);
876
- console.log(`[FederatedCatalogueStore] Stored local data for ${id}`);
877
1463
  this.notifyComponents(id, resourceWithId);
878
1464
  return id;
879
1465
  } catch (error2) {
@@ -27544,10 +28130,8 @@ let __tla = (async () => {
27544
28130
  let indexUri;
27545
28131
  if (options.dataSrcIndex) {
27546
28132
  indexUri = options.dataSrcIndex;
27547
- console.log("\u{1F4C2} [SolidIndexingSearchProvider.queryIndex] Using direct index URI:", indexUri);
27548
28133
  } else if (options.dataSrcProfile) {
27549
28134
  indexUri = await this.discoverIndexFromProfile(options.dataSrcProfile);
27550
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndex] Discovered index URI from profile:", indexUri);
27551
28135
  } else {
27552
28136
  console.warn("Either dataSrcIndex or dataSrcProfile must be specified");
27553
28137
  return [];
@@ -27556,10 +28140,7 @@ let __tla = (async () => {
27556
28140
  console.warn("\u26A0\uFE0F [SolidIndexingSearchProvider.queryIndex] Invalid index URI, returning empty results");
27557
28141
  return [];
27558
28142
  }
27559
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndex] Starting query with options:", JSON.stringify(options, null, 2));
27560
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndex] Filter values:", JSON.stringify(options.filterValues, null, 2));
27561
28143
  const filterFields = Object.entries(options.filterValues);
27562
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndex] Filter fields:", filterFields);
27563
28144
  const firstField = filterFields[0];
27564
28145
  const firstFieldValue = firstField[1];
27565
28146
  let path = firstField[0];
@@ -27574,21 +28155,7 @@ let __tla = (async () => {
27574
28155
  fieldName = path.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
27575
28156
  }
27576
28157
  const searchPattern = firstFieldValue.value;
27577
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndex] Parsed parameters:");
27578
- console.log(" - Path:", path);
27579
- console.log(" - Field name:", fieldName);
27580
- console.log(" - Search pattern:", searchPattern);
27581
- console.log(" - RDF type:", options.dataRdfType);
27582
- console.log(" - Exact match mapping:", options.exactMatchMapping);
27583
- console.log("\u{1F527} [SolidIndexingSearchProvider.queryIndex] Generating SHACL shapes...");
27584
28158
  const { targetShape, subIndexShape, finalShape } = this.generateShapes(options.dataRdfType, fieldName, searchPattern, options.exactMatchMapping);
27585
- console.log("\u{1F4DD} [SolidIndexingSearchProvider.queryIndex] Generated shapes:");
27586
- console.log("=== TARGET SHAPE ===");
27587
- console.log(targetShape);
27588
- console.log("=== SUBINDEX SHAPE ===");
27589
- console.log(subIndexShape);
27590
- console.log("=== FINAL SHAPE ===");
27591
- console.log(finalShape);
27592
28159
  const parser = new N3.Parser({
27593
28160
  format: "text/turtle"
27594
28161
  });
@@ -27602,10 +28169,7 @@ let __tla = (async () => {
27602
28169
  const entryTransformer = new EntryStreamTransformerDefaultImpl(SEMANTIZER);
27603
28170
  const finalIndexStrategy = new IndexStrategyFinalShapeDefaultImpl(finalIndexShapeGraph, subIndexShapeGraph, shaclValidator, entryTransformer);
27604
28171
  const shaclStrategy = new IndexQueryingStrategyShaclUsingFinalIndex(targetShapeGraph, finalIndexStrategy, shaclValidator, entryTransformer);
27605
- console.log("\u{1F527} [SolidIndexingSearchProvider.queryIndex] Creating index with factory...");
27606
28172
  const index = await SEMANTIZER.load(indexUri, indexFactory);
27607
- console.log("\u2705 [SolidIndexingSearchProvider.queryIndex] Index created successfully");
27608
- console.log("\u{1F680} [SolidIndexingSearchProvider.queryIndex] Starting query stream...");
27609
28173
  const resultStream = index.mixins.index.query(shaclStrategy);
27610
28174
  return new Promise((resolve, reject) => {
27611
28175
  const resultIds = [];
@@ -27614,22 +28178,17 @@ let __tla = (async () => {
27614
28178
  let streamEnded = false;
27615
28179
  const checkComplete = () => {
27616
28180
  if (streamEnded && pendingFetches === 0) {
27617
- console.log(`\u{1F3C1} [SolidIndexingSearchProvider.queryIndex] All resources fetched. Found ${resultIds.length} result IDs:`, resultIds);
27618
- console.log(`\u{1F3AF} [SolidIndexingSearchProvider.queryIndex] Returning ${resources.length} resources for ldp:contains`);
27619
28181
  resolve(resources);
27620
28182
  }
27621
28183
  };
27622
28184
  resultStream.on("data", async (result) => {
27623
- console.log("\u{1F4E6} [SolidIndexingSearchProvider.queryIndex] Received result:", result.value);
27624
28185
  if (result.value) {
27625
28186
  resultIds.push(result.value);
27626
- console.log("\u2705 [SolidIndexingSearchProvider.queryIndex] Added result ID:", result.value);
27627
28187
  pendingFetches++;
27628
28188
  try {
27629
28189
  const resource = await this.dataFetcher(result.value);
27630
28190
  if (resource) {
27631
28191
  resources.push(resource);
27632
- console.log(`\u2705 [SolidIndexingSearchProvider.queryIndex] Successfully fetched resource: ${result.value}`);
27633
28192
  } else {
27634
28193
  console.warn(`\u26A0\uFE0F [SolidIndexingSearchProvider.queryIndex] Could not fetch resource: ${result.value}`);
27635
28194
  }
@@ -27646,7 +28205,6 @@ let __tla = (async () => {
27646
28205
  reject(error2);
27647
28206
  });
27648
28207
  resultStream.on("end", () => {
27649
- console.log(`\u{1F3C1} [SolidIndexingSearchProvider.queryIndex] Stream ended. Found ${resultIds.length} result IDs:`, resultIds);
27650
28208
  streamEnded = true;
27651
28209
  checkComplete();
27652
28210
  });
@@ -27657,9 +28215,7 @@ let __tla = (async () => {
27657
28215
  console.warn("\u26A0\uFE0F [SolidIndexingSearchProvider.queryIndexConjunction] Invalid index URL:", options.dataSrcIndex, options.dataSrcProfile);
27658
28216
  return [];
27659
28217
  }
27660
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Starting conjunction query with options:", JSON.stringify(options, null, 2));
27661
28218
  const filterFields = Object.entries(options.filterValues);
27662
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Filter fields:", filterFields);
27663
28219
  if (filterFields.length === 0) {
27664
28220
  return [];
27665
28221
  }
@@ -27672,29 +28228,22 @@ let __tla = (async () => {
27672
28228
  },
27673
28229
  exactMatchMapping: options.exactMatchMapping
27674
28230
  };
27675
- console.log(`\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Executing query for ${propertyName}:`, queryOptions);
27676
28231
  return this.query(queryOptions);
27677
28232
  });
27678
28233
  try {
27679
28234
  const allResults = await Promise.all(queryPromises);
27680
- console.log("\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] All individual queries completed");
27681
28235
  if (allResults.length === 1) {
27682
28236
  return allResults[0];
27683
28237
  }
27684
28238
  const baseResults = allResults[0];
27685
- console.log(`\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Base results count: ${baseResults.length}`);
27686
28239
  const intersectionResults = baseResults.filter((resource) => {
27687
28240
  const resourceId = resource["@id"];
27688
- console.log(`\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Checking resource: ${resourceId}`);
27689
- const existsInAllSets = allResults.every((resultSet, index) => {
28241
+ const existsInAllSets = allResults.every((resultSet, _index) => {
27690
28242
  const found = resultSet.some((r) => r["@id"] === resourceId);
27691
- console.log(` - Set ${index}: ${found ? "\u2705" : "\u274C"} (${resultSet.length} items)`);
27692
28243
  return found;
27693
28244
  });
27694
- console.log(` - Final result: ${existsInAllSets ? "\u2705 IN INTERSECTION" : "\u274C NOT IN INTERSECTION"}`);
27695
28245
  return existsInAllSets;
27696
28246
  });
27697
- console.log(`\u{1F50D} [SolidIndexingSearchProvider.queryIndexConjunction] Conjunction results count: ${intersectionResults.length}`);
27698
28247
  return intersectionResults;
27699
28248
  } catch (error2) {
27700
28249
  console.error("\u274C [SolidIndexingSearchProvider.queryIndexConjunction] Error in conjunction query:", error2);
@@ -27702,11 +28251,6 @@ let __tla = (async () => {
27702
28251
  }
27703
28252
  }
27704
28253
  generateShapes(rdfType, propertyName, pattern, exactMatchMapping) {
27705
- console.log("\u{1F527} [SolidIndexingSearchProvider.generateShapes] Generating shapes with parameters:");
27706
- console.log(" - RDF Type:", rdfType);
27707
- console.log(" - Property Name:", propertyName);
27708
- console.log(" - Pattern:", pattern);
27709
- console.log(" - Exact Match Mapping:", exactMatchMapping);
27710
28254
  const isExactMatch = exactMatchMapping == null ? void 0 : exactMatchMapping[propertyName];
27711
28255
  let matchValue;
27712
28256
  if (isExactMatch) {
@@ -27716,15 +28260,8 @@ let __tla = (async () => {
27716
28260
  const words = cleanPattern.split(" ").filter((word) => word.length >= 3);
27717
28261
  const prefix = words.length > 0 ? words[0].substring(0, 3) : pattern.substring(0, 3);
27718
28262
  matchValue = `${prefix}.*`;
27719
- console.log(" - Cleaned pattern:", cleanPattern);
27720
- console.log(" - Extracted words:", words);
27721
- console.log(" - Generated prefix:", prefix);
27722
28263
  }
27723
28264
  const matchConstraint = "sh:pattern";
27724
- console.log(" - Is Exact Match:", isExactMatch);
27725
- console.log(" - Match Value:", matchValue);
27726
- console.log(" - Match Constraint:", matchConstraint);
27727
- console.log(" - Generated SHACL constraint: [ sh:path", `${matchConstraint}; sh:hasValue "${matchValue}" ]`);
27728
28265
  const targetShape = `
27729
28266
  @prefix sh: <http://www.w3.org/ns/shacl#> .
27730
28267
  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@@ -27882,7 +28419,6 @@ sh:property [
27882
28419
  extractPublicTypeIndexUrl(profileData) {
27883
28420
  var _a2, _b;
27884
28421
  const profileDoc = (_a2 = profileData["@graph"]) == null ? void 0 : _a2.find((item) => item["@type"] === "foaf:PersonalProfileDocument");
27885
- console.log("\u{1F50D} [SolidIndexingSearchProvider.extractPublicTypeIndexUrl] Profile document:", profileDoc);
27886
28422
  if (profileDoc == null ? void 0 : profileDoc["foaf:primaryTopic"]) {
27887
28423
  const primaryTopicId = profileDoc == null ? void 0 : profileDoc["foaf:primaryTopic"];
27888
28424
  const primaryTopic = (_b = profileData["@graph"]) == null ? void 0 : _b.find((item) => item["@id"] === primaryTopicId);
@@ -27963,7 +28499,7 @@ sh:property [
27963
28499
  this.searchProvider = new SolidIndexingSearchProvider(this.getData.bind(this));
27964
28500
  }
27965
28501
  async initGetter() {
27966
- const { CustomGetter } = await import("./custom-getter-FYE7WERU.js");
28502
+ const { CustomGetter } = await import("./custom-getter-cITbP3Tj.js");
27967
28503
  return CustomGetter;
27968
28504
  }
27969
28505
  async getData(id, context2, parentId, localData, forceFetch, serverPagination, serverSearch, headers, bypassLoadingList) {
@@ -32327,7 +32863,6 @@ sh:property [
32327
32863
  }
32328
32864
  async load(uri, _otherFetch) {
32329
32865
  const headers = store$1.headers;
32330
- console.log(`Loading\xB7specific\xB7URI\xB7${uri}`);
32331
32866
  const response = await store$1.fetchAuthn(uri, {
32332
32867
  method: "GET",
32333
32868
  headers,
@@ -32373,7 +32908,6 @@ sh:property [
32373
32908
  input.push(null);
32374
32909
  }
32375
32910
  });
32376
- console.log("[IndexLoader] Input loaded", input);
32377
32911
  const parserJsonld = new Parser();
32378
32912
  const quads = parserJsonld.import(input);
32379
32913
  const resDataset = factory.dataset();