Skip to content

Commit d766dac

Browse files
feat: add inspectBulkRequest method
1 parent 81a7b4b commit d766dac

File tree

14 files changed

+950
-43
lines changed

14 files changed

+950
-43
lines changed

packages/sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build": "rimraf dist && tsc --project tsconfig.build.json",
1818
"build:watch": "npm run build -- --watch",
1919
"check-types": "tsc --noEmit",
20+
"test:prepare": "node tests/prepare-iexec.js",
2021
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\"",
2122
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --coverage",
2223
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/unit/**/*.test.ts\"",
@@ -32,7 +33,7 @@
3233
"generate:abi": "rimraf generated/abis && node tools/generateAbiModules.mjs",
3334
"refresh-abis": "mkdir -p .tmp && cp -r abis/core/registry .tmp/ 2>/dev/null || true && rm -rf abis && mkdir -p abis/core && cp -r ../smart-contract/abis/. ./abis/core/ && if [ -d .tmp/registry ]; then mkdir -p abis/core/registry && cp -r .tmp/registry/. ./abis/core/registry/ && rm -rf .tmp; fi",
3435
"stop-test-stack": "cd tests && docker compose --project-name dataprotector-sdk down --volumes --remove-orphans",
35-
"start-test-stack": "cd tests && npm run stop-test-stack && node prepare-test-env.js && docker compose --project-name dataprotector-sdk build && docker compose --project-name dataprotector-sdk up -d"
36+
"start-test-stack": "cd tests && npm run stop-test-stack && node prepare-test-env.js && docker compose --project-name dataprotector-sdk build && docker compose --project-name dataprotector-sdk up -d && npm run test:prepare"
3637
},
3738
"repository": {
3839
"type": "git",

packages/sdk/src/lib/IExecDataProtectorModule.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type EthersCompatibleProvider =
2222
interface IExecDataProtectorResolvedConfig {
2323
dataprotectorContractAddress: AddressOrENS;
2424
graphQLClient: GraphQLClient;
25+
pocoSubgraphClient: GraphQLClient;
2526
ipfsNode: string;
2627
ipfsGateway: string;
2728
defaultWorkerpool: string;
@@ -33,6 +34,8 @@ abstract class IExecDataProtectorModule {
3334

3435
protected graphQLClient!: GraphQLClient;
3536

37+
protected pocoSubgraphClient!: GraphQLClient;
38+
3639
protected ipfsNode!: string;
3740

3841
protected ipfsGateway!: string;
@@ -62,6 +65,7 @@ abstract class IExecDataProtectorModule {
6265
this.initPromise = this.resolveConfig().then((config) => {
6366
this.dataprotectorContractAddress = config.dataprotectorContractAddress;
6467
this.graphQLClient = config.graphQLClient;
68+
this.pocoSubgraphClient = config.graphQLClient;
6569
this.ipfsNode = config.ipfsNode;
6670
this.ipfsGateway = config.ipfsGateway;
6771
this.defaultWorkerpool = config.defaultWorkerpool;
@@ -103,7 +107,9 @@ abstract class IExecDataProtectorModule {
103107
);
104108
}
105109

106-
let iexec: IExec, graphQLClient: GraphQLClient;
110+
let iexec: IExec,
111+
graphQLClient: GraphQLClient,
112+
pocoSubgraphClient: GraphQLClient;
107113

108114
try {
109115
iexec = new IExec(
@@ -125,13 +131,21 @@ abstract class IExecDataProtectorModule {
125131
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
126132
}
127133

134+
try {
135+
const pocoSubgraphURL = await iexec.config.resolvePocoSubgraphURL();
136+
pocoSubgraphClient = new GraphQLClient(pocoSubgraphURL);
137+
} catch (error: any) {
138+
throw new Error(`Failed to create PoCo GraphQLClient: ${error.message}`);
139+
}
140+
128141
return {
129142
dataprotectorContractAddress: dataprotectorContractAddress.toLowerCase(),
130143
defaultWorkerpool,
131144
graphQLClient,
132145
ipfsNode,
133146
ipfsGateway,
134147
iexec,
148+
pocoSubgraphClient,
135149
};
136150
}
137151
}

packages/sdk/src/lib/dataProtectorCore/IExecDataProtectorCore.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isValidProvider } from '../../utils/validators.js';
1+
import { isValidSigner } from '../../utils/validators.js';
22
import { IExecDataProtectorModule } from '../IExecDataProtectorModule.js';
33
import {
44
GetGrantedAccessParams,
@@ -23,11 +23,14 @@ import {
2323
WaitForTaskCompletionParams,
2424
PrepareBulkRequestParams,
2525
PrepareBulkRequestResponse,
26+
InspectBulkRequestResponse,
27+
InspectBulkRequestParams,
2628
} from '../types/index.js';
2729
import { getGrantedAccess } from './getGrantedAccess.js';
2830
import { getProtectedData } from './getProtectedData.js';
2931
import { getResultFromCompletedTask } from './getResultFromCompletedTask.js';
3032
import { grantAccess } from './grantAccess.js';
33+
import { inspectBulkRequest } from './inspectBulkRequest.js';
3134
import { prepareBulkRequest } from './prepareBulkRequest.js';
3235
import { processBulkRequest } from './processBulkRequest.js';
3336
import { processProtectedData } from './processProtectedData.js';
@@ -42,7 +45,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
4245
args: ProtectDataParams
4346
): Promise<ProtectedDataWithSecretProps> {
4447
await this.init();
45-
await isValidProvider(this.iexec);
48+
await isValidSigner(this.iexec);
4649
return protectData({
4750
...args,
4851
dataprotectorContractAddress: this.dataprotectorContractAddress,
@@ -55,33 +58,33 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
5558

5659
async grantAccess(args: GrantAccessParams): Promise<GrantedAccess> {
5760
await this.init();
58-
await isValidProvider(this.iexec);
61+
await isValidSigner(this.iexec);
5962
return grantAccess({ ...args, iexec: this.iexec });
6063
}
6164

6265
async revokeOneAccess(args: GrantedAccess): Promise<RevokedAccess> {
6366
await this.init();
64-
await isValidProvider(this.iexec);
67+
await isValidSigner(this.iexec);
6568
return revokeOneAccess({ ...args, iexec: this.iexec });
6669
}
6770

6871
async revokeAllAccess(args: RevokeAllAccessParams): Promise<RevokedAccess[]> {
6972
await this.init();
70-
await isValidProvider(this.iexec);
73+
await isValidSigner(this.iexec);
7174
return revokeAllAccess({ ...args, iexec: this.iexec });
7275
}
7376

7477
async transferOwnership(args: TransferParams): Promise<TransferResponse> {
7578
await this.init();
76-
await isValidProvider(this.iexec);
79+
await isValidSigner(this.iexec);
7780
return transferOwnership({ ...args, iexec: this.iexec });
7881
}
7982

8083
async processProtectedData<Params extends ProcessProtectedDataParams>(
8184
args: Params
8285
): Promise<ProcessProtectedDataResponse<Params>> {
8386
await this.init();
84-
await isValidProvider(this.iexec);
87+
await isValidSigner(this.iexec);
8588
return processProtectedData({
8689
...args,
8790
iexec: this.iexec,
@@ -93,7 +96,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
9396
args: PrepareBulkRequestParams
9497
): Promise<PrepareBulkRequestResponse> {
9598
await this.init();
96-
await isValidProvider(this.iexec);
99+
await isValidSigner(this.iexec);
97100
return prepareBulkRequest({
98101
...args,
99102
iexec: this.iexec,
@@ -104,7 +107,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
104107
args: Params
105108
): Promise<ProcessBulkRequestResponse<Params>> {
106109
await this.init();
107-
await isValidProvider(this.iexec);
110+
await isValidSigner(this.iexec);
108111
return processBulkRequest({
109112
...args,
110113
iexec: this.iexec,
@@ -131,11 +134,22 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
131134
return getGrantedAccess({ ...args, iexec: this.iexec });
132135
}
133136

137+
async inspectBulkRequest<Params extends InspectBulkRequestParams>(
138+
args: Params
139+
): Promise<InspectBulkRequestResponse<Params>> {
140+
await this.init();
141+
return inspectBulkRequest({
142+
...args,
143+
iexec: this.iexec,
144+
pocoSubgraphClient: this.pocoSubgraphClient,
145+
defaultWorkerpool: this.defaultWorkerpool,
146+
});
147+
}
148+
134149
async waitForTaskCompletion(
135150
args: WaitForTaskCompletionParams
136151
): Promise<WaitForTaskCompletionResponse> {
137152
await this.init();
138-
await isValidProvider(this.iexec);
139153
return waitForTaskCompletion({
140154
...args,
141155
iexec: this.iexec,
@@ -146,7 +160,6 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
146160
args: GetResultFromCompletedTaskParams
147161
): Promise<GetResultFromCompletedTaskResponse> {
148162
await this.init();
149-
await isValidProvider(this.iexec);
150163
return getResultFromCompletedTask({
151164
...args,
152165
iexec: this.iexec,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { WorkflowError } from '../../utils/errors.js';
2+
import { throwIfMissing } from '../../utils/validators.js';
3+
import { PocoSubgraphConsumer } from '../types/internalTypes.js';
4+
import { getProtectedDataInBulkByBulkRequestHash } from './subgraph/getProtectedDataInBulkByBulkRequestHash.js';
5+
6+
export async function getProtectedDataInBulk({
7+
pocoSubgraphClient = throwIfMissing(),
8+
bulkRequestHash = throwIfMissing(),
9+
}: PocoSubgraphConsumer & {
10+
bulkRequestHash: string;
11+
}): Promise<
12+
Record<string, { dealId: string; protectedDataAddresses: string[] }>
13+
> {
14+
try {
15+
const result = await getProtectedDataInBulkByBulkRequestHash({
16+
pocoSubgraphClient,
17+
bulkRequestHash,
18+
});
19+
20+
const tasks: Record<
21+
string,
22+
{ dealId: string; protectedDataAddresses: string[] }
23+
> = {};
24+
result.deals.forEach((deal) => {
25+
deal.tasks.forEach((task) => {
26+
tasks[task.taskId] = {
27+
dealId: deal.dealId,
28+
protectedDataAddresses:
29+
task.bulkSlice?.datasets.map((dataset) => dataset.id) ?? undefined,
30+
};
31+
});
32+
});
33+
return tasks;
34+
} catch (e) {
35+
console.log('[getProtectedDataInBulk] ERROR', e);
36+
throw new WorkflowError({
37+
message: 'Failed to get protected data in bulk',
38+
errorCause: e,
39+
});
40+
}
41+
}

0 commit comments

Comments
 (0)