@nevermined-io/core-kit 0.0.2-rc19
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/README.md +15 -0
- package/dist/Instantiable.abstract.d.ts +35 -0
- package/dist/Instantiable.abstract.d.ts.map +1 -0
- package/dist/Instantiable.abstract.js +102 -0
- package/dist/artifacts/generated.d.ts +29912 -0
- package/dist/artifacts/generated.d.ts.map +1 -0
- package/dist/artifacts/generated.js +16797 -0
- package/dist/contracts/AccessManager.d.ts +17 -0
- package/dist/contracts/AccessManager.d.ts.map +1 -0
- package/dist/contracts/AccessManager.js +15 -0
- package/dist/contracts/AssetRegistry.d.ts +65 -0
- package/dist/contracts/AssetRegistry.d.ts.map +1 -0
- package/dist/contracts/AssetRegistry.js +103 -0
- package/dist/contracts/ContractBase.d.ts +21 -0
- package/dist/contracts/ContractBase.d.ts.map +1 -0
- package/dist/contracts/ContractBase.js +270 -0
- package/dist/contracts/ContractsApi.d.ts +62 -0
- package/dist/contracts/ContractsApi.d.ts.map +1 -0
- package/dist/contracts/ContractsApi.js +66 -0
- package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
- package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
- package/dist/contracts/FiatPaymentTemplate.js +14 -0
- package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
- package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
- package/dist/contracts/FiatSettlementCondition.js +18 -0
- package/dist/contracts/FixedPaymentTemplate.d.ts +10 -0
- package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
- package/dist/contracts/FixedPaymentTemplate.js +14 -0
- package/dist/contracts/NFT1155Base.d.ts +41 -0
- package/dist/contracts/NFT1155Base.d.ts.map +1 -0
- package/dist/contracts/NFT1155Base.js +21 -0
- package/dist/contracts/NFT1155Credits.d.ts +6 -0
- package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
- package/dist/contracts/NFT1155Credits.js +9 -0
- package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
- package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
- package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
- package/dist/contracts/NVMConfig.d.ts +10 -0
- package/dist/contracts/NVMConfig.d.ts.map +1 -0
- package/dist/contracts/NVMConfig.js +18 -0
- package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
- package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
- package/dist/contracts/ProtocolStandardFees.js +15 -0
- package/dist/contracts/Roles.d.ts +13 -0
- package/dist/contracts/Roles.d.ts.map +1 -0
- package/dist/contracts/Roles.js +12 -0
- package/dist/contracts/index.d.ts +3 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/errors/NeverminedErrors.d.ts +71 -0
- package/dist/errors/NeverminedErrors.d.ts.map +1 -0
- package/dist/errors/NeverminedErrors.js +123 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/models/Logger.d.ts +9 -0
- package/dist/models/Logger.d.ts.map +1 -0
- package/dist/models/Logger.js +27 -0
- package/dist/models/NeverminedOptions.d.ts +55 -0
- package/dist/models/NeverminedOptions.d.ts.map +1 -0
- package/dist/models/NeverminedOptions.js +58 -0
- package/dist/models/NvmApiKey.d.ts +137 -0
- package/dist/models/NvmApiKey.d.ts.map +1 -0
- package/dist/models/NvmApiKey.js +234 -0
- package/dist/models/Transactions.d.ts +11 -0
- package/dist/models/Transactions.d.ts.map +1 -0
- package/dist/models/Transactions.js +1 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +4 -0
- package/dist/nevermined/DID.d.ts +45 -0
- package/dist/nevermined/DID.d.ts.map +1 -0
- package/dist/nevermined/DID.js +90 -0
- package/dist/nevermined/Nevermined.d.ts +48 -0
- package/dist/nevermined/Nevermined.d.ts.map +1 -0
- package/dist/nevermined/Nevermined.js +72 -0
- package/dist/nevermined/api/PaymentsApi.d.ts +17 -0
- package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
- package/dist/nevermined/api/PaymentsApi.js +125 -0
- package/dist/nevermined/api/ServicesApi.d.ts +28 -0
- package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
- package/dist/nevermined/api/ServicesApi.js +33 -0
- package/dist/nevermined/api/UtilsApi.d.ts +28 -0
- package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
- package/dist/nevermined/api/UtilsApi.js +33 -0
- package/dist/nevermined/index.d.ts +4 -0
- package/dist/nevermined/index.d.ts.map +1 -0
- package/dist/nevermined/index.js +3 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +276 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/BlockchainViemUtils.js +376 -0
- package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
- package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/JwtUtils.js +154 -0
- package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
- package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/SignatureUtils.js +99 -0
- package/dist/nevermined/utils/WebServiceConnector.d.ts +32 -0
- package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
- package/dist/nevermined/utils/WebServiceConnector.js +191 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +19 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
- package/dist/nevermined/utils/ZeroDevPolicies.js +78 -0
- package/dist/nevermined/utils/index.d.ts +6 -0
- package/dist/nevermined/utils/index.d.ts.map +1 -0
- package/dist/nevermined/utils/index.js +5 -0
- package/dist/services/Api.d.ts +7 -0
- package/dist/services/Api.d.ts.map +1 -0
- package/dist/services/Api.js +25 -0
- package/dist/services/MarketplaceAPI.d.ts +7 -0
- package/dist/services/MarketplaceAPI.d.ts.map +1 -0
- package/dist/services/MarketplaceAPI.js +25 -0
- package/dist/services/MetadataService.d.ts +90 -0
- package/dist/services/MetadataService.d.ts.map +1 -0
- package/dist/services/MetadataService.js +277 -0
- package/dist/services/Profiles.d.ts +16 -0
- package/dist/services/Profiles.d.ts.map +1 -0
- package/dist/services/Profiles.js +84 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +3 -0
- package/dist/utils/ConversionTypeHelpers.d.ts +8 -0
- package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
- package/dist/utils/ConversionTypeHelpers.js +31 -0
- package/dist/utils/Network.d.ts +5 -0
- package/dist/utils/Network.d.ts.map +1 -0
- package/dist/utils/Network.js +224 -0
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +109 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +27 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
|
|
2
|
+
export declare class MarketplaceApi extends Instantiable {
|
|
3
|
+
constructor(config: InstantiableConfig);
|
|
4
|
+
protected get url(): string | undefined;
|
|
5
|
+
login(clientAssertion: string): Promise<string>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=MarketplaceAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarketplaceAPI.d.ts","sourceRoot":"","sources":["../../src/services/MarketplaceAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAK9E,qBAAa,cAAe,SAAQ,YAAY;gBAClC,MAAM,EAAE,kBAAkB;IAKtC,SAAS,KAAK,GAAG,uBAEhB;IAEY,KAAK,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkB7D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Instantiable } from '../Instantiable.abstract.js';
|
|
2
|
+
import { ApiError, HttpError } from '../errors/NeverminedErrors.js';
|
|
3
|
+
const authPath = '/api/v1/api-keys';
|
|
4
|
+
export class MarketplaceApi extends Instantiable {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super();
|
|
7
|
+
this.setInstanceConfig(config);
|
|
8
|
+
}
|
|
9
|
+
get url() {
|
|
10
|
+
return this.config.backendUrl;
|
|
11
|
+
}
|
|
12
|
+
async login(clientAssertion) {
|
|
13
|
+
try {
|
|
14
|
+
const response = await this.nevermined.utils.fetch.fetchToken(`${this.url}${authPath}/login`, clientAssertion);
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new HttpError(`Error Login - ${response.statusText} ${response.url}`, response.status);
|
|
17
|
+
}
|
|
18
|
+
const backendAuthToken = (await response.json()).access_token;
|
|
19
|
+
return backendAuthToken;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DDO, SearchQuery } from '@nvm-monorepo/commons';
|
|
2
|
+
import { DID } from '../nevermined/DID.js';
|
|
3
|
+
import { Api } from './Api.js';
|
|
4
|
+
export declare const apiPath = "/api/v1/protocol/agents";
|
|
5
|
+
export declare const servicePath = "/api/v1/metadata/assets/service";
|
|
6
|
+
export interface QueryResult {
|
|
7
|
+
results: DDO[];
|
|
8
|
+
page: number;
|
|
9
|
+
totalPages: number;
|
|
10
|
+
totalResults: {
|
|
11
|
+
[jsonPath: string]: any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface DDOStatus {
|
|
15
|
+
internal: {
|
|
16
|
+
id: string;
|
|
17
|
+
type: string;
|
|
18
|
+
status: string;
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
|
+
external: {
|
|
22
|
+
id: string;
|
|
23
|
+
type: string;
|
|
24
|
+
status: string;
|
|
25
|
+
url: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface AuthToken {
|
|
29
|
+
access_token: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Provides a interface with Metadata.
|
|
33
|
+
* Metadata provides an off-chain database store for metadata about data assets.
|
|
34
|
+
*/
|
|
35
|
+
export declare class MetadataService extends Api {
|
|
36
|
+
getVersionInfo(): Promise<any>;
|
|
37
|
+
getAccessUrl(accessToken: any, payload: any): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Search over the DDOs using a query.
|
|
40
|
+
* @param query - Query to filter the DDOs.
|
|
41
|
+
* @returns A list of {@link QueryResult}s.
|
|
42
|
+
*/
|
|
43
|
+
queryMetadata(query: SearchQuery): Promise<QueryResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Search over the Services using a query.
|
|
46
|
+
* @param query - Query to filter the Services.
|
|
47
|
+
* @returns A list of {@link ServiceSecondary}.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Update a DDO in Metadata.
|
|
51
|
+
* @param ddo - DDO to be stored.assignable
|
|
52
|
+
* @returns Final DDO.
|
|
53
|
+
*/
|
|
54
|
+
updateDDO(did: DID | string, ddo: DDO, backendAuthToken: string): Promise<DDO>;
|
|
55
|
+
/**
|
|
56
|
+
* Stores a DDO in Metadata.
|
|
57
|
+
* @param ddo - DDO to be stored.
|
|
58
|
+
* @returns Final DDO.
|
|
59
|
+
*/
|
|
60
|
+
storeDDO(ddo: DDO, backendAuthToken: string): Promise<DDO>;
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves a DDO by DID.
|
|
63
|
+
* @param did - DID of the asset.
|
|
64
|
+
* @param metadataServiceEndpoint - Metadata service endpoint.
|
|
65
|
+
* @returns DDO of the asset.
|
|
66
|
+
*/
|
|
67
|
+
retrieveDDO(did?: DID | string, metadataServiceEndpoint?: string): Promise<DDO>;
|
|
68
|
+
retrieveDDOFromImmutableBackend(immutableUrl: string): Promise<DDO>;
|
|
69
|
+
delete(did: DID | string, backendAuthToken: string): Promise<import("node-fetch").Response>;
|
|
70
|
+
retrieveDDOByUrl(metadataServiceEndpoint?: string): Promise<DDO>;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves a DDO by DID.
|
|
73
|
+
* @param did - DID of the asset.
|
|
74
|
+
* @returns DDO of the asset.
|
|
75
|
+
*/
|
|
76
|
+
status(did: DID | string, metadataServiceEndpoint?: string): Promise<DDOStatus>;
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves a service by its agreementId.
|
|
79
|
+
* @param agreementId - agreementId of the service.
|
|
80
|
+
* @returns Service object.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param agreementId - The agreement ID of the service.
|
|
85
|
+
* @param agreement - Stores the Service object with its agreementId
|
|
86
|
+
* @returns the newly stored service object
|
|
87
|
+
*/
|
|
88
|
+
getServiceEndpoint(did: DID): string;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=MetadataService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataService.d.ts","sourceRoot":"","sources":["../../src/services/MetadataService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,eAAO,MAAM,OAAO,4BAA4B,CAAA;AAChD,eAAO,MAAM,WAAW,oCAAoC,CAAA;AAE5D,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,GAAG,EAAE,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;CAC1C;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE;QACR,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;IACD,QAAQ,EAAE;QACR,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;KACZ,CAAA;CACF;AAED,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,GAAG;IACzB,cAAc;IAId,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAuB1E;;;;OAIG;IACU,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IA2BpE;;;;OAIG;IAsBH;;;;OAIG;IACU,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA0B3F;;;;OAIG;IACU,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA0BvE;;;;;OAKG;IACU,WAAW,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAgC/E,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAWnE,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,gBAAgB,EAAE,MAAM;IAWlD,gBAAgB,CAAC,uBAAuB,CAAC,EAAE,MAAM;IAI9D;;;;OAIG;IACU,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAyB5F;;;;OAIG;IA4BH;;;;;OAKG;IAiCI,kBAAkB,CAAC,GAAG,EAAE,GAAG;CAGnC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { DDO } from '@nvm-monorepo/commons';
|
|
2
|
+
import { ApiError, HttpError } from '../errors/NeverminedErrors.js';
|
|
3
|
+
import { DID } from '../nevermined/DID.js';
|
|
4
|
+
import { Api } from './Api.js';
|
|
5
|
+
export const apiPath = '/api/v1/protocol/agents';
|
|
6
|
+
export const servicePath = '/api/v1/metadata/assets/service';
|
|
7
|
+
/**
|
|
8
|
+
* Provides a interface with Metadata.
|
|
9
|
+
* Metadata provides an off-chain database store for metadata about data assets.
|
|
10
|
+
*/
|
|
11
|
+
export class MetadataService extends Api {
|
|
12
|
+
async getVersionInfo() {
|
|
13
|
+
return (await this.nevermined.utils.fetch.get(this.url)).json();
|
|
14
|
+
}
|
|
15
|
+
async getAccessUrl(accessToken, payload) {
|
|
16
|
+
const accessUrl = await this.nevermined.utils.fetch
|
|
17
|
+
.post(`${accessToken.service_endpoint}/${accessToken.resource_id}`, payload)
|
|
18
|
+
.then((response) => {
|
|
19
|
+
if (response.ok) {
|
|
20
|
+
return response.text();
|
|
21
|
+
}
|
|
22
|
+
throw new HttpError(`getAccessUrl Failed - ${response.statusText} ${response.url}`, response.status);
|
|
23
|
+
})
|
|
24
|
+
.then((consumptionUrl) => {
|
|
25
|
+
this.logger.info('Success accessing consume endpoint: ', consumptionUrl);
|
|
26
|
+
return consumptionUrl;
|
|
27
|
+
})
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
throw new ApiError(error);
|
|
30
|
+
});
|
|
31
|
+
return accessUrl;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Search over the DDOs using a query.
|
|
35
|
+
* @param query - Query to filter the DDOs.
|
|
36
|
+
* @returns A list of {@link QueryResult}s.
|
|
37
|
+
*/
|
|
38
|
+
async queryMetadata(query) {
|
|
39
|
+
const result = await this.nevermined.utils.fetch
|
|
40
|
+
.post(`${this.url}${apiPath}/query`, JSON.stringify(query))
|
|
41
|
+
.then((response) => {
|
|
42
|
+
if (response.ok) {
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
throw new HttpError(`queryMetadata failed - ${response.statusText} ${response.url}`, response.status);
|
|
46
|
+
})
|
|
47
|
+
.then((results) => {
|
|
48
|
+
return {
|
|
49
|
+
results: (results.results || []).map((ddo) => new DDO(ddo)),
|
|
50
|
+
page: results.page,
|
|
51
|
+
totalPages: results.total_pages,
|
|
52
|
+
totalResults: results.total_results,
|
|
53
|
+
};
|
|
54
|
+
})
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
throw new ApiError(error);
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Search over the Services using a query.
|
|
62
|
+
* @param query - Query to filter the Services.
|
|
63
|
+
* @returns A list of {@link ServiceSecondary}.
|
|
64
|
+
*/
|
|
65
|
+
// public async queryServiceMetadata(query: {
|
|
66
|
+
// [property: string]: string | number | string[] | number[] | object
|
|
67
|
+
// }): Promise<ServiceSecondary[]> {
|
|
68
|
+
// const result: ServiceSecondary[] = await this.nevermined.utils.fetch
|
|
69
|
+
// .post(`${this.url}${servicePath}/query`, JSON.stringify(query))
|
|
70
|
+
// .then((response: any) => {
|
|
71
|
+
// if (response.ok) {
|
|
72
|
+
// return response.json() as ServiceSecondary[]
|
|
73
|
+
// }
|
|
74
|
+
// throw new HttpError(
|
|
75
|
+
// `queryServicesMetadata failed - ${response.statusText} ${response.url}`,
|
|
76
|
+
// response.status,
|
|
77
|
+
// )
|
|
78
|
+
// })
|
|
79
|
+
// .catch((error) => {
|
|
80
|
+
// throw new ApiError(error)
|
|
81
|
+
// })
|
|
82
|
+
// return result
|
|
83
|
+
// }
|
|
84
|
+
/**
|
|
85
|
+
* Update a DDO in Metadata.
|
|
86
|
+
* @param ddo - DDO to be stored.assignable
|
|
87
|
+
* @returns Final DDO.
|
|
88
|
+
*/
|
|
89
|
+
async updateDDO(did, ddo, backendAuthToken) {
|
|
90
|
+
const fullUrl = `${this.url}${apiPath}/${DID.parse(did).getDid()}`;
|
|
91
|
+
const result = await this.nevermined.utils.fetch
|
|
92
|
+
.put(fullUrl, DDO.serialize(ddo), {
|
|
93
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
94
|
+
})
|
|
95
|
+
.then((response) => {
|
|
96
|
+
if (response.ok) {
|
|
97
|
+
return response.json();
|
|
98
|
+
}
|
|
99
|
+
throw new HttpError(`updateDDO failed - ${response.statusText} ${response.url}`, response.status);
|
|
100
|
+
})
|
|
101
|
+
.then((response) => {
|
|
102
|
+
return new DDO(response);
|
|
103
|
+
})
|
|
104
|
+
.catch((error) => {
|
|
105
|
+
throw new ApiError(error);
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Stores a DDO in Metadata.
|
|
111
|
+
* @param ddo - DDO to be stored.
|
|
112
|
+
* @returns Final DDO.
|
|
113
|
+
*/
|
|
114
|
+
async storeDDO(ddo, backendAuthToken) {
|
|
115
|
+
const fullUrl = `${this.url}${apiPath}`;
|
|
116
|
+
const result = await this.nevermined.utils.fetch
|
|
117
|
+
.post(fullUrl, DDO.serialize(ddo), {
|
|
118
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
119
|
+
})
|
|
120
|
+
.then((response) => {
|
|
121
|
+
if (response.ok) {
|
|
122
|
+
return response.json();
|
|
123
|
+
}
|
|
124
|
+
throw new HttpError(`storeDDO failed - ${response.statusText} ${response.url}`, response.status);
|
|
125
|
+
})
|
|
126
|
+
.then((response) => {
|
|
127
|
+
return new DDO(response);
|
|
128
|
+
})
|
|
129
|
+
.catch((error) => {
|
|
130
|
+
throw new ApiError(error);
|
|
131
|
+
});
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Retrieves a DDO by DID.
|
|
136
|
+
* @param did - DID of the asset.
|
|
137
|
+
* @param metadataServiceEndpoint - Metadata service endpoint.
|
|
138
|
+
* @returns DDO of the asset.
|
|
139
|
+
*/
|
|
140
|
+
async retrieveDDO(did, metadataServiceEndpoint) {
|
|
141
|
+
let fullUrl;
|
|
142
|
+
if (did) {
|
|
143
|
+
fullUrl = metadataServiceEndpoint || `${this.url}${apiPath}/${DID.parse(did).getDid()}`;
|
|
144
|
+
}
|
|
145
|
+
else if (metadataServiceEndpoint) {
|
|
146
|
+
fullUrl = metadataServiceEndpoint;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new ApiError(`A DID or metadataServiceEndpoint needs to be specified`);
|
|
150
|
+
}
|
|
151
|
+
const result = await this.nevermined.utils.fetch
|
|
152
|
+
.get(fullUrl)
|
|
153
|
+
.then((response) => {
|
|
154
|
+
if (response.ok) {
|
|
155
|
+
return response.json();
|
|
156
|
+
}
|
|
157
|
+
throw new HttpError(`retrieveDDO failed - ${response.statusText} ${response.url}`, response.status);
|
|
158
|
+
})
|
|
159
|
+
.then((response) => {
|
|
160
|
+
return new DDO(response);
|
|
161
|
+
})
|
|
162
|
+
.catch((error) => {
|
|
163
|
+
throw new ApiError(error);
|
|
164
|
+
});
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
async retrieveDDOFromImmutableBackend(immutableUrl) {
|
|
168
|
+
if (!(immutableUrl && immutableUrl.length > 10))
|
|
169
|
+
throw new Error(`Invalid immutable url`);
|
|
170
|
+
if (immutableUrl.startsWith('cid://')) {
|
|
171
|
+
return await this.nevermined.utils.fetch.fetchCID(immutableUrl).then((response) => {
|
|
172
|
+
return DDO.deserialize(response);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
throw new Error(`Invalid url`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async delete(did, backendAuthToken) {
|
|
180
|
+
const result = await this.nevermined.utils.fetch.delete(`${this.url}${apiPath}/${DID.parse(did).getDid()}`, undefined, {
|
|
181
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
182
|
+
});
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
async retrieveDDOByUrl(metadataServiceEndpoint) {
|
|
186
|
+
return this.retrieveDDO(undefined, metadataServiceEndpoint);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Retrieves a DDO by DID.
|
|
190
|
+
* @param did - DID of the asset.
|
|
191
|
+
* @returns DDO of the asset.
|
|
192
|
+
*/
|
|
193
|
+
async status(did, metadataServiceEndpoint) {
|
|
194
|
+
const fullUrl = metadataServiceEndpoint || `${this.url}${apiPath}/${DID.parse(did).getDid()}/status`;
|
|
195
|
+
const result = await this.nevermined.utils.fetch
|
|
196
|
+
.get(fullUrl)
|
|
197
|
+
.then((response) => {
|
|
198
|
+
if (response.ok) {
|
|
199
|
+
return response.json();
|
|
200
|
+
}
|
|
201
|
+
throw new HttpError(`status failed - ${response.statusText} ${response.url}`, response.status);
|
|
202
|
+
})
|
|
203
|
+
.then((response) => {
|
|
204
|
+
return response;
|
|
205
|
+
})
|
|
206
|
+
.catch((error) => {
|
|
207
|
+
throw new ApiError(error);
|
|
208
|
+
});
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Retrieves a service by its agreementId.
|
|
213
|
+
* @param agreementId - agreementId of the service.
|
|
214
|
+
* @returns Service object.
|
|
215
|
+
*/
|
|
216
|
+
// public async retrieveService(
|
|
217
|
+
// agreementId: string,
|
|
218
|
+
// metadataServiceEndpoint?: string,
|
|
219
|
+
// ): Promise<ServiceSecondary> {
|
|
220
|
+
// const fullUrl = metadataServiceEndpoint || `${this.url}${servicePath}/${agreementId}`
|
|
221
|
+
// const result = await this.nevermined.utils.fetch
|
|
222
|
+
// .get(fullUrl)
|
|
223
|
+
// .then((response: any) => {
|
|
224
|
+
// if (response.ok) {
|
|
225
|
+
// return response.json()
|
|
226
|
+
// }
|
|
227
|
+
// throw new HttpError(
|
|
228
|
+
// `retrieveService failed - ${response.statusText} ${response.url}`,
|
|
229
|
+
// response.status,
|
|
230
|
+
// )
|
|
231
|
+
// })
|
|
232
|
+
// .then((response: ServiceSecondary) => {
|
|
233
|
+
// return response as ServiceSecondary
|
|
234
|
+
// })
|
|
235
|
+
// .catch((error) => {
|
|
236
|
+
// throw new ApiError(error)
|
|
237
|
+
// })
|
|
238
|
+
// return result
|
|
239
|
+
// }
|
|
240
|
+
/**
|
|
241
|
+
*
|
|
242
|
+
* @param agreementId - The agreement ID of the service.
|
|
243
|
+
* @param agreement - Stores the Service object with its agreementId
|
|
244
|
+
* @returns the newly stored service object
|
|
245
|
+
*/
|
|
246
|
+
// public async storeService(
|
|
247
|
+
// agreementId: string,
|
|
248
|
+
// agreement: ServiceSecondary,
|
|
249
|
+
// ): Promise<ServiceSecondary> {
|
|
250
|
+
// const fullUrl = `${this.url}${servicePath}`
|
|
251
|
+
// agreement['agreementId'] = agreementId
|
|
252
|
+
// const agreementStore = JSON.stringify(agreement)
|
|
253
|
+
// const result: ServiceSecondary = await this.nevermined.utils.fetch
|
|
254
|
+
// .post(fullUrl, agreementStore, {
|
|
255
|
+
// Authorization: `Bearer ${this.config.marketplaceAuthToken}`,
|
|
256
|
+
// })
|
|
257
|
+
// .then((response: any) => {
|
|
258
|
+
// if (response.ok) {
|
|
259
|
+
// return response.json()
|
|
260
|
+
// }
|
|
261
|
+
// throw new HttpError(
|
|
262
|
+
// `storeService failed - ${response.statusText} ${response.url}`,
|
|
263
|
+
// response.status,
|
|
264
|
+
// )
|
|
265
|
+
// })
|
|
266
|
+
// .then((response: ServiceSecondary) => {
|
|
267
|
+
// return response as ServiceSecondary
|
|
268
|
+
// })
|
|
269
|
+
// .catch((error) => {
|
|
270
|
+
// throw new ApiError(error)
|
|
271
|
+
// })
|
|
272
|
+
// return result
|
|
273
|
+
// }
|
|
274
|
+
getServiceEndpoint(did) {
|
|
275
|
+
return `${this.url}${apiPath}/did:nv:${did.getId()}`;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NewProfile, Profile, ReducedProfile } from '@nvm-monorepo/commons';
|
|
2
|
+
import { Api } from './Api.js';
|
|
3
|
+
export declare class Profiles extends Api {
|
|
4
|
+
/**
|
|
5
|
+
* Create user profile
|
|
6
|
+
*/
|
|
7
|
+
create(newProfile: NewProfile, backendAuthToken: string): Promise<Profile>;
|
|
8
|
+
/**
|
|
9
|
+
* Update user profile
|
|
10
|
+
*/
|
|
11
|
+
update(userId: string, profile: Partial<NewProfile>, backendAuthToken: string): Promise<Profile>;
|
|
12
|
+
findOneByUserId(userId: string, backendAuthToken: string): Promise<Profile>;
|
|
13
|
+
findOneByAddress(address: string): Promise<ReducedProfile>;
|
|
14
|
+
disableOneByUserId(userId: string, backendAuthToken: string): Promise<Profile>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=Profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Profiles.d.ts","sourceRoot":"","sources":["../../src/services/Profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAI9B,qBAAa,QAAS,SAAQ,GAAG;IAC/B;;OAEG;IACU,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBvF;;OAEG;IACU,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,EAC5B,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC;IAqBN,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB3E,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAmB1D,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAoB5F"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ApiError, HttpError } from '../errors/NeverminedErrors.js';
|
|
2
|
+
import { Api } from './Api.js';
|
|
3
|
+
const profilePath = '/api/v1/metadata/profiles';
|
|
4
|
+
export class Profiles extends Api {
|
|
5
|
+
/**
|
|
6
|
+
* Create user profile
|
|
7
|
+
*/
|
|
8
|
+
async create(newProfile, backendAuthToken) {
|
|
9
|
+
const fullUrl = `${this.url}${profilePath}`;
|
|
10
|
+
try {
|
|
11
|
+
const response = await this.nevermined.utils.fetch.post(fullUrl, JSON.stringify(newProfile), {
|
|
12
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
13
|
+
});
|
|
14
|
+
if (response.ok) {
|
|
15
|
+
return response.json();
|
|
16
|
+
}
|
|
17
|
+
throw new HttpError(`Create profile fail - ${response.statusText} ${response.url}`, response.status);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Update user profile
|
|
25
|
+
*/
|
|
26
|
+
async update(userId, profile, backendAuthToken) {
|
|
27
|
+
const fullUrl = `${this.url}${profilePath}/${userId}`;
|
|
28
|
+
try {
|
|
29
|
+
const response = await this.nevermined.utils.fetch.put(fullUrl, JSON.stringify(profile), {
|
|
30
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
31
|
+
});
|
|
32
|
+
if (response.ok) {
|
|
33
|
+
return response.json();
|
|
34
|
+
}
|
|
35
|
+
throw new HttpError(`Update profile fail - ${response.statusText} ${response.url}`, response.status);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async findOneByUserId(userId, backendAuthToken) {
|
|
42
|
+
const fullUrl = `${this.url}${profilePath}/${userId}`;
|
|
43
|
+
try {
|
|
44
|
+
const response = await this.nevermined.utils.fetch.get(fullUrl, {
|
|
45
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
46
|
+
});
|
|
47
|
+
if (response.ok) {
|
|
48
|
+
return response.json();
|
|
49
|
+
}
|
|
50
|
+
throw new HttpError(`Find profile with userId ${userId} fail - ${response.statusText} ${response.url}`, response.status);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async findOneByAddress(address) {
|
|
57
|
+
const fullUrl = `${this.url}${profilePath}/address/${address}`;
|
|
58
|
+
try {
|
|
59
|
+
const response = await this.nevermined.utils.fetch.get(fullUrl);
|
|
60
|
+
if (response.ok) {
|
|
61
|
+
return response.json();
|
|
62
|
+
}
|
|
63
|
+
throw new HttpError(`Find profile with address ${address} fail - ${response.statusText} ${response.url}`, response.status);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async disableOneByUserId(userId, backendAuthToken) {
|
|
70
|
+
const fullUrl = `${this.url}${profilePath}/${userId}`;
|
|
71
|
+
try {
|
|
72
|
+
const response = await this.nevermined.utils.fetch.delete(fullUrl, undefined, {
|
|
73
|
+
Authorization: `Bearer ${backendAuthToken}`,
|
|
74
|
+
});
|
|
75
|
+
if (response.ok) {
|
|
76
|
+
return response.json();
|
|
77
|
+
}
|
|
78
|
+
throw new HttpError(`Disable profile with userId ${userId} fail - ${response.statusText} ${response.url}`, response.status);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const zeroX: (input: string) => `0x${string}`;
|
|
2
|
+
export declare const noZeroX: (input: string) => string;
|
|
3
|
+
export declare function zeroXTransformer(input: string | undefined, zeroOutput: boolean): string;
|
|
4
|
+
export declare const didPrefixed: (input: string) => string;
|
|
5
|
+
export declare const noDidPrefixed: (input: string) => string;
|
|
6
|
+
export declare function didTransformer(input: string | undefined, prefixOutput: boolean): string;
|
|
7
|
+
export declare const didZeroX: (input: string) => `0x${string}`;
|
|
8
|
+
//# sourceMappingURL=ConversionTypeHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversionTypeHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/ConversionTypeHelpers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAsC,KAAK,MAAM,EAAE,CAAA;AACtF,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,WAAmC,CAAA;AAExE,wBAAgB,gBAAgB,CAAC,KAAK,oBAAK,EAAE,UAAU,EAAE,OAAO,UAG/D;AAGD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,WAAgC,CAAA;AACzE,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAAiC,CAAA;AAE5E,wBAAgB,cAAc,CAAC,KAAK,oBAAK,EAAE,YAAY,EAAE,OAAO,UAG/D;AAGD,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,kBAAgC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LoggerInstance } from '../models/Logger.js';
|
|
2
|
+
// Ox transformer
|
|
3
|
+
export const zeroX = (input) => zeroXTransformer(input, true);
|
|
4
|
+
export const noZeroX = (input) => zeroXTransformer(input, false);
|
|
5
|
+
export function zeroXTransformer(input = '', zeroOutput) {
|
|
6
|
+
const { valid, output } = inputMatch(input, /^(?:0x)*([a-f0-9]+)$/i, 'zeroXTransformer');
|
|
7
|
+
return (zeroOutput && valid ? '0x' : '') + output;
|
|
8
|
+
}
|
|
9
|
+
// did:nv: transformer
|
|
10
|
+
export const didPrefixed = (input) => didTransformer(input, true);
|
|
11
|
+
export const noDidPrefixed = (input) => didTransformer(input, false);
|
|
12
|
+
export function didTransformer(input = '', prefixOutput) {
|
|
13
|
+
const { valid, output } = inputMatch(input, /^(?:0x|did:nv:)*([a-f0-9]{64})$/i, 'didTransformer');
|
|
14
|
+
return (prefixOutput && valid ? 'did:nv:' : '') + output;
|
|
15
|
+
}
|
|
16
|
+
// 0x + did:nv: transformer
|
|
17
|
+
export const didZeroX = (input) => zeroX(noDidPrefixed(input));
|
|
18
|
+
// Shared functions
|
|
19
|
+
function inputMatch(input, regexp, conversorName) {
|
|
20
|
+
if (typeof input !== 'string') {
|
|
21
|
+
LoggerInstance().debug('Not input string:');
|
|
22
|
+
LoggerInstance().debug(input);
|
|
23
|
+
throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`);
|
|
24
|
+
}
|
|
25
|
+
const match = input.match(regexp);
|
|
26
|
+
if (!match) {
|
|
27
|
+
LoggerInstance().debug(`[${conversorName}] Input transformation failed for input ${input}.`);
|
|
28
|
+
return { valid: false, output: input };
|
|
29
|
+
}
|
|
30
|
+
return { valid: true, output: match[1] };
|
|
31
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Chain } from 'viem/chains';
|
|
2
|
+
export declare function getNetworkName(networkId: number): Promise<string>;
|
|
3
|
+
export declare function isTestnet(networkId: number): boolean;
|
|
4
|
+
export declare function getChain(networkId: number | undefined): Chain;
|
|
5
|
+
//# sourceMappingURL=Network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Network.d.ts","sourceRoot":"","sources":["../../src/utils/Network.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EAeX,MAAM,aAAa,CAAA;AAGpB,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmEvE;AACD,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAmEpD;AACD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAoF7D"}
|