@iexec/web3mail 0.6.1 → 1.0.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/errors.d.ts +8 -4
- package/dist/utils/errors.js +15 -5
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/ipfs-service.js +8 -17
- package/dist/utils/ipfs-service.js.map +1 -1
- package/dist/utils/paginate.js +3 -12
- package/dist/utils/paginate.js.map +1 -1
- package/dist/utils/subgraphQuery.js +14 -17
- package/dist/utils/subgraphQuery.js.map +1 -1
- package/dist/utils/validators.d.ts +3 -0
- package/dist/utils/validators.js +10 -3
- package/dist/utils/validators.js.map +1 -1
- package/dist/web3mail/IExecWeb3mail.d.ts +4 -4
- package/dist/web3mail/IExecWeb3mail.js +42 -14
- package/dist/web3mail/IExecWeb3mail.js.map +1 -1
- package/dist/web3mail/fetchMyContacts.d.ts +2 -2
- package/dist/web3mail/fetchMyContacts.js +14 -25
- package/dist/web3mail/fetchMyContacts.js.map +1 -1
- package/dist/web3mail/fetchUserContacts.d.ts +1 -1
- package/dist/web3mail/fetchUserContacts.js +29 -30
- package/dist/web3mail/fetchUserContacts.js.map +1 -1
- package/dist/web3mail/sendEmail.js +33 -36
- package/dist/web3mail/sendEmail.js.map +1 -1
- package/dist/web3mail/types.d.ts +7 -1
- package/package.json +8 -5
- package/src/index.ts +1 -0
- package/src/utils/errors.ts +24 -6
- package/src/utils/index.ts +1 -0
- package/src/utils/subgraphQuery.ts +8 -8
- package/src/utils/validators.ts +13 -1
- package/src/web3mail/IExecWeb3mail.ts +15 -7
- package/src/web3mail/fetchMyContacts.ts +18 -18
- package/src/web3mail/fetchUserContacts.ts +21 -6
- package/src/web3mail/sendEmail.ts +15 -4
- package/src/web3mail/types.ts +8 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
declare class WorkflowError extends Error {
|
|
2
|
-
|
|
3
|
-
constructor(message
|
|
1
|
+
export declare class WorkflowError extends Error {
|
|
2
|
+
isProtocolError: boolean;
|
|
3
|
+
constructor({ message, errorCause, isProtocolError, }: {
|
|
4
|
+
message: string;
|
|
5
|
+
errorCause: Error;
|
|
6
|
+
isProtocolError?: boolean;
|
|
7
|
+
});
|
|
4
8
|
}
|
|
5
|
-
export
|
|
9
|
+
export declare function handleIfProtocolError(error: Error): void;
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ApiCallError } from 'iexec/errors';
|
|
2
|
+
export class WorkflowError extends Error {
|
|
3
|
+
isProtocolError;
|
|
4
|
+
constructor({ message, errorCause, isProtocolError = false, }) {
|
|
5
|
+
super(message, { cause: errorCause });
|
|
4
6
|
this.name = this.constructor.name;
|
|
5
|
-
this.
|
|
7
|
+
this.isProtocolError = isProtocolError;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function handleIfProtocolError(error) {
|
|
11
|
+
if (error instanceof ApiCallError) {
|
|
12
|
+
throw new WorkflowError({
|
|
13
|
+
message: "A service in the iExec protocol appears to be unavailable. You can retry later or contact iExec's technical support for help.",
|
|
14
|
+
errorCause: error,
|
|
15
|
+
isProtocolError: true,
|
|
16
|
+
});
|
|
6
17
|
}
|
|
7
18
|
}
|
|
8
|
-
export { WorkflowError };
|
|
9
19
|
//# sourceMappingURL=errors.js.map
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,aAAc,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,eAAe,CAAU;IAEzB,YAAY,EACV,OAAO,EACP,UAAU,EACV,eAAe,GAAG,KAAK,GAKxB;QACC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAY;IAChD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EACL,+HAA+H;YACjI,UAAU,EAAE,KAAK;YACjB,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WorkflowError } from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { create } from 'kubo-rpc-client';
|
|
11
2
|
import { IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY } from '../config/config.js';
|
|
12
|
-
const get = (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) =>
|
|
3
|
+
const get = async (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
|
|
13
4
|
const multiaddr = `/ipfs/${cid.toString()}`;
|
|
14
5
|
const publicUrl = `${ipfsGateway}${multiaddr}`;
|
|
15
|
-
const res =
|
|
6
|
+
const res = await fetch(publicUrl);
|
|
16
7
|
if (!res.ok) {
|
|
17
8
|
throw Error(`Failed to load content from ${publicUrl}`);
|
|
18
9
|
}
|
|
19
|
-
const arrayBuffer =
|
|
10
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
20
11
|
return new Uint8Array(arrayBuffer);
|
|
21
|
-
}
|
|
22
|
-
const add = (content, { ipfsNode = IPFS_UPLOAD_URL, ipfsGateway = DEFAULT_IPFS_GATEWAY, } = {}) =>
|
|
12
|
+
};
|
|
13
|
+
const add = async (content, { ipfsNode = IPFS_UPLOAD_URL, ipfsGateway = DEFAULT_IPFS_GATEWAY, } = {}) => {
|
|
23
14
|
const ipfsClient = create(ipfsNode);
|
|
24
|
-
const { cid } =
|
|
25
|
-
|
|
15
|
+
const { cid } = await ipfsClient.add(content);
|
|
16
|
+
await get(cid.toString(), { ipfsGateway });
|
|
26
17
|
return cid.toString();
|
|
27
|
-
}
|
|
18
|
+
};
|
|
28
19
|
export { add, get };
|
|
29
20
|
//# sourceMappingURL=ipfs-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfs-service.js","sourceRoot":"","sources":["../../src/utils/ipfs-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipfs-service.js","sourceRoot":"","sources":["../../src/utils/ipfs-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAS5E,MAAM,GAAG,GAAG,KAAK,EACf,GAAG,EACH,EAAE,WAAW,GAAG,oBAAoB,KAAiB,EAAE,EACvD,EAAE;IACF,MAAM,SAAS,GAAG,SAAS,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,GAAG,WAAW,GAAG,SAAS,EAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,+BAA+B,SAAS,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;IAC5C,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,GAAG,GAAG,KAAK,EACf,OAAO,EACP,EACE,QAAQ,GAAG,eAAe,EAC1B,WAAW,GAAG,oBAAoB,MACpB,EAAE,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/utils/paginate.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const autoPaginateRequest = ({ request }, { orders = [] } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
const res = yield request;
|
|
1
|
+
export const autoPaginateRequest = async ({ request }, { orders = [] } = {}) => {
|
|
2
|
+
const res = await request;
|
|
12
3
|
const totalCount = res.count;
|
|
13
4
|
if (res.orders.length > 0) {
|
|
14
5
|
orders.push(...res.orders);
|
|
@@ -19,5 +10,5 @@ export const autoPaginateRequest = ({ request }, { orders = [] } = {}) => __awai
|
|
|
19
10
|
}
|
|
20
11
|
}
|
|
21
12
|
return { orders, count: totalCount };
|
|
22
|
-
}
|
|
13
|
+
};
|
|
23
14
|
//# sourceMappingURL=paginate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../src/utils/paginate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../src/utils/paginate.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,EAAE,OAAO,EAAE,EACX,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,EAAE,EACpB,EAAE;IACF,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC;IAC1B,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC;IAC7B,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/C,OAAO,mBAAmB,CACxB;gBACE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE;aACpB,EACD,EAAE,MAAM,EAAE,CACX,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AACvC,CAAC,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { gql } from 'graphql-request';
|
|
11
2
|
import { WorkflowError } from './errors.js';
|
|
12
3
|
const checkProtectedDataQuery = gql `
|
|
@@ -31,7 +22,7 @@ const checkProtectedDataQuery = gql `
|
|
|
31
22
|
}
|
|
32
23
|
}
|
|
33
24
|
`;
|
|
34
|
-
export const getValidContact = (graphQLClient, contacts) =>
|
|
25
|
+
export const getValidContact = async (graphQLClient, contacts) => {
|
|
35
26
|
try {
|
|
36
27
|
// Contacts addresses
|
|
37
28
|
const contactsAddresses = contacts.map((contact) => contact.address);
|
|
@@ -47,7 +38,7 @@ export const getValidContact = (graphQLClient, contacts) => __awaiter(void 0, vo
|
|
|
47
38
|
start,
|
|
48
39
|
range,
|
|
49
40
|
};
|
|
50
|
-
const protectedDataResultQuery =
|
|
41
|
+
const protectedDataResultQuery = await graphQLClient.request(checkProtectedDataQuery, variables);
|
|
51
42
|
const { protectedDatas } = protectedDataResultQuery;
|
|
52
43
|
protectedDataList.push(...protectedDatas);
|
|
53
44
|
continuePagination = protectedDatas.length === range;
|
|
@@ -68,10 +59,13 @@ export const getValidContact = (graphQLClient, contacts) => __awaiter(void 0, vo
|
|
|
68
59
|
});
|
|
69
60
|
}
|
|
70
61
|
catch (error) {
|
|
71
|
-
throw new WorkflowError(
|
|
62
|
+
throw new WorkflowError({
|
|
63
|
+
message: 'Failed to fetch subgraph',
|
|
64
|
+
errorCause: error,
|
|
65
|
+
});
|
|
72
66
|
}
|
|
73
|
-
}
|
|
74
|
-
export const checkProtectedDataValidity = (graphQLClient, protectedData) =>
|
|
67
|
+
};
|
|
68
|
+
export const checkProtectedDataValidity = async (graphQLClient, protectedData) => {
|
|
75
69
|
try {
|
|
76
70
|
const variables = {
|
|
77
71
|
requiredSchema: ['email:string'],
|
|
@@ -79,12 +73,15 @@ export const checkProtectedDataValidity = (graphQLClient, protectedData) => __aw
|
|
|
79
73
|
start: 0,
|
|
80
74
|
range: 1,
|
|
81
75
|
};
|
|
82
|
-
const protectedDataResultQuery =
|
|
76
|
+
const protectedDataResultQuery = await graphQLClient.request(checkProtectedDataQuery, variables);
|
|
83
77
|
const { protectedDatas } = protectedDataResultQuery;
|
|
84
78
|
return protectedDatas.length === 1;
|
|
85
79
|
}
|
|
86
80
|
catch (error) {
|
|
87
|
-
throw new WorkflowError(
|
|
81
|
+
throw new WorkflowError({
|
|
82
|
+
message: 'Failed to fetch subgraph',
|
|
83
|
+
errorCause: error,
|
|
84
|
+
});
|
|
88
85
|
}
|
|
89
|
-
}
|
|
86
|
+
};
|
|
90
87
|
//# sourceMappingURL=subgraphQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subgraphQuery.js","sourceRoot":"","sources":["../../src/utils/subgraphQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subgraphQuery.js","sourceRoot":"","sources":["../../src/utils/subgraphQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,uBAAuB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;CAqBlC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,aAA4B,EAC5B,QAAmB,EACC,EAAE;IACtB,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAErE,aAAa;QACb,MAAM,iBAAiB,GAAyB,EAAE,CAAC;QACnD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,IAAI,CAAC;QACnB,IAAI,kBAAkB,GAAG,IAAI,CAAC;QAE9B,GAAG,CAAC;YACF,MAAM,SAAS,GAAG;gBAChB,cAAc,EAAE,CAAC,cAAc,CAAC;gBAChC,EAAE,EAAE,iBAAiB;gBACrB,KAAK;gBACL,KAAK;aACN,CAAC;YAEF,MAAM,w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,CAAC;SACT,CAAC;QAEF,MAAM,wBAAwB,GAC5B,MAAM,aAAa,CAAC,OAAO,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAAC;QAElE,MAAM,EAAE,cAAc,EAAE,GAAG,wBAAwB,CAAC;QAEpD,OAAO,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EAAE,0BAA0B;YACnC,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IExec } from 'iexec';
|
|
2
|
+
export declare const isValidProvider: (iexec: IExec) => Promise<void>;
|
|
1
3
|
export declare const throwIfMissing: () => never;
|
|
2
4
|
export declare const isEnsTest: (value: string) => boolean;
|
|
3
5
|
export declare const addressOrEnsSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
@@ -8,3 +10,4 @@ export declare const contentTypeSchema: () => import("yup").StringSchema<string,
|
|
|
8
10
|
export declare const senderNameSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
9
11
|
export declare const labelSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
10
12
|
export declare const positiveNumberSchema: () => import("yup").NumberSchema<number, import("yup").AnyObject, undefined, "">;
|
|
13
|
+
export declare const booleanSchema: () => import("yup").BooleanSchema<boolean, import("yup").AnyObject, undefined, "">;
|
package/dist/utils/validators.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { isAddress } from 'ethers';
|
|
2
|
-
import { ValidationError, number, string } from 'yup';
|
|
2
|
+
import { ValidationError, boolean, number, string } from 'yup';
|
|
3
|
+
export const isValidProvider = async (iexec) => {
|
|
4
|
+
const client = await iexec.config.resolveContractsClient();
|
|
5
|
+
if (!client.signer) {
|
|
6
|
+
throw new Error('Unauthorized method. Please log in with your wallet, you must set a valid provider with a signer.');
|
|
7
|
+
}
|
|
8
|
+
};
|
|
3
9
|
export const throwIfMissing = () => {
|
|
4
10
|
throw new ValidationError('Missing parameter');
|
|
5
11
|
};
|
|
@@ -7,10 +13,10 @@ const isUndefined = (value) => value === undefined;
|
|
|
7
13
|
const isAddressTest = (value) => isAddress(value);
|
|
8
14
|
export const isEnsTest = (value) => value.endsWith('.eth') && value.length > 6;
|
|
9
15
|
export const addressOrEnsSchema = () => string()
|
|
10
|
-
.transform((value) =>
|
|
16
|
+
.transform((value) => value?.toLowerCase() || value)
|
|
11
17
|
.test('is-address-or-ens', '${path} should be an ethereum address or a ENS name', (value) => isUndefined(value) || isAddressTest(value) || isEnsTest(value));
|
|
12
18
|
export const addressSchema = () => string()
|
|
13
|
-
.transform((value) =>
|
|
19
|
+
.transform((value) => value?.toLowerCase() || value)
|
|
14
20
|
.test('is-address', '${path} should be an ethereum address', (value) => isUndefined(value) || isAddressTest(value));
|
|
15
21
|
// 78 char length for email subject (rfc2822)
|
|
16
22
|
export const emailSubjectSchema = () => string().max(78).strict();
|
|
@@ -24,4 +30,5 @@ export const senderNameSchema = () => string().trim().min(3).max(20).optional();
|
|
|
24
30
|
// Used to identify the email campaign, minimum of 3 characters and max of 10
|
|
25
31
|
export const labelSchema = () => string().trim().min(3).max(10).optional();
|
|
26
32
|
export const positiveNumberSchema = () => number().integer().min(0).typeError('${path} must be a non-negative number');
|
|
33
|
+
export const booleanSchema = () => boolean();
|
|
27
34
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;A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EAAE,CAAC,OAAO,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Eip1193Provider } from 'ethers';
|
|
2
|
-
import { Contact, FetchUserContactsParams, SendEmailParams,
|
|
2
|
+
import { Contact, FetchUserContactsParams, SendEmailParams, Web3MailConfigOptions, SendEmailResponse, Web3SignerProvider } from './types.js';
|
|
3
3
|
export declare class IExecWeb3mail {
|
|
4
4
|
private iexec;
|
|
5
5
|
private ipfsNode;
|
|
@@ -8,8 +8,8 @@ export declare class IExecWeb3mail {
|
|
|
8
8
|
private dappAddressOrENS;
|
|
9
9
|
private dappWhitelistAddress;
|
|
10
10
|
private graphQLClient;
|
|
11
|
-
constructor(ethProvider
|
|
12
|
-
fetchMyContacts
|
|
11
|
+
constructor(ethProvider?: Eip1193Provider | Web3SignerProvider | string, options?: Web3MailConfigOptions);
|
|
12
|
+
fetchMyContacts(): Promise<Contact[]>;
|
|
13
13
|
fetchUserContacts(args?: FetchUserContactsParams): Promise<Contact[]>;
|
|
14
|
-
sendEmail
|
|
14
|
+
sendEmail(args: SendEmailParams): Promise<SendEmailResponse>;
|
|
15
15
|
}
|
|
@@ -4,37 +4,65 @@ import { fetchMyContacts } from './fetchMyContacts.js';
|
|
|
4
4
|
import { sendEmail } from './sendEmail.js';
|
|
5
5
|
import { GraphQLClient } from 'graphql-request';
|
|
6
6
|
import { WEB3_MAIL_DAPP_ADDRESS, IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY, DATAPROTECTOR_SUBGRAPH_ENDPOINT, WHITELIST_SMART_CONTRACT_ADDRESS, } from '../config/config.js';
|
|
7
|
+
import { isValidProvider } from '../utils/validators.js';
|
|
7
8
|
export class IExecWeb3mail {
|
|
9
|
+
iexec;
|
|
10
|
+
ipfsNode;
|
|
11
|
+
ipfsGateway;
|
|
12
|
+
dataProtectorSubgraph;
|
|
13
|
+
dappAddressOrENS;
|
|
14
|
+
dappWhitelistAddress;
|
|
15
|
+
graphQLClient;
|
|
8
16
|
constructor(ethProvider, options) {
|
|
9
|
-
this.fetchMyContacts = () => fetchMyContacts({
|
|
10
|
-
iexec: this.iexec,
|
|
11
|
-
graphQLClient: this.graphQLClient,
|
|
12
|
-
dappAddressOrENS: this.dappAddressOrENS,
|
|
13
|
-
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
14
|
-
});
|
|
15
|
-
this.sendEmail = (args) => sendEmail(Object.assign(Object.assign({}, args), { iexec: this.iexec, ipfsNode: this.ipfsNode, ipfsGateway: this.ipfsGateway, dappAddressOrENS: this.dappAddressOrENS, dappWhitelistAddress: this.dappWhitelistAddress, graphQLClient: this.graphQLClient }));
|
|
16
17
|
try {
|
|
17
|
-
this.iexec = new IExec({ ethProvider
|
|
18
|
+
this.iexec = new IExec({ ethProvider: ethProvider || 'bellecour' }, options?.iexecOptions);
|
|
18
19
|
}
|
|
19
20
|
catch (e) {
|
|
20
21
|
throw Error('Unsupported ethProvider');
|
|
21
22
|
}
|
|
22
23
|
try {
|
|
23
24
|
this.dataProtectorSubgraph =
|
|
24
|
-
|
|
25
|
+
options?.dataProtectorSubgraph || DATAPROTECTOR_SUBGRAPH_ENDPOINT;
|
|
25
26
|
this.graphQLClient = new GraphQLClient(this.dataProtectorSubgraph);
|
|
26
27
|
}
|
|
27
28
|
catch (e) {
|
|
28
29
|
throw Error('Impossible to create GraphQLClient');
|
|
29
30
|
}
|
|
30
|
-
this.dappAddressOrENS =
|
|
31
|
-
this.ipfsNode =
|
|
32
|
-
this.ipfsGateway =
|
|
31
|
+
this.dappAddressOrENS = options?.dappAddressOrENS || WEB3_MAIL_DAPP_ADDRESS;
|
|
32
|
+
this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL;
|
|
33
|
+
this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY;
|
|
33
34
|
this.dappWhitelistAddress =
|
|
34
|
-
|
|
35
|
+
options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS;
|
|
36
|
+
}
|
|
37
|
+
async fetchMyContacts() {
|
|
38
|
+
await isValidProvider(this.iexec);
|
|
39
|
+
return fetchMyContacts({
|
|
40
|
+
iexec: this.iexec,
|
|
41
|
+
graphQLClient: this.graphQLClient,
|
|
42
|
+
dappAddressOrENS: this.dappAddressOrENS,
|
|
43
|
+
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
44
|
+
});
|
|
35
45
|
}
|
|
36
46
|
fetchUserContacts(args) {
|
|
37
|
-
return fetchUserContacts(
|
|
47
|
+
return fetchUserContacts({
|
|
48
|
+
...args,
|
|
49
|
+
iexec: this.iexec,
|
|
50
|
+
graphQLClient: this.graphQLClient,
|
|
51
|
+
dappAddressOrENS: this.dappAddressOrENS,
|
|
52
|
+
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async sendEmail(args) {
|
|
56
|
+
await isValidProvider(this.iexec);
|
|
57
|
+
return sendEmail({
|
|
58
|
+
...args,
|
|
59
|
+
iexec: this.iexec,
|
|
60
|
+
ipfsNode: this.ipfsNode,
|
|
61
|
+
ipfsGateway: this.ipfsGateway,
|
|
62
|
+
dappAddressOrENS: this.dappAddressOrENS,
|
|
63
|
+
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
64
|
+
graphQLClient: this.graphQLClient,
|
|
65
|
+
});
|
|
38
66
|
}
|
|
39
67
|
}
|
|
40
68
|
//# sourceMappingURL=IExecWeb3mail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IExecWeb3mail.js","sourceRoot":"","sources":["../../src/web3mail/IExecWeb3mail.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAU3C,OA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AE,IAAI,CAAC,gBAAgB;YACvC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Contact, DappAddressConsumer, DappWhitelistAddressConsumer, IExecConsumer, SubgraphConsumer } from './types.js';
|
|
2
|
-
export declare const fetchMyContacts: ({ graphQLClient, iexec, dappAddressOrENS, dappWhitelistAddress, }: IExecConsumer & SubgraphConsumer & DappAddressConsumer & DappWhitelistAddressConsumer) => Promise<Contact[]>;
|
|
1
|
+
import { Contact, DappAddressConsumer, DappWhitelistAddressConsumer, FetchMyContactsParams, IExecConsumer, SubgraphConsumer } from './types.js';
|
|
2
|
+
export declare const fetchMyContacts: ({ graphQLClient, iexec, dappAddressOrENS, dappWhitelistAddress, isUserStrict, }: IExecConsumer & SubgraphConsumer & DappAddressConsumer & DappWhitelistAddressConsumer & FetchMyContactsParams) => Promise<Contact[]>;
|
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { booleanSchema, throwIfMissing } from '../utils/validators.js';
|
|
2
|
+
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
3
|
+
export const fetchMyContacts = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), dappAddressOrENS = throwIfMissing(), dappWhitelistAddress = throwIfMissing(), isUserStrict = false, }) => {
|
|
4
|
+
const vIsUserStrict = booleanSchema()
|
|
5
|
+
.label('isUserStrict')
|
|
6
|
+
.validateSync(isUserStrict);
|
|
7
|
+
const userAddress = await iexec.wallet.getAddress();
|
|
8
|
+
return fetchUserContacts({
|
|
9
|
+
iexec,
|
|
10
|
+
graphQLClient,
|
|
11
|
+
dappAddressOrENS,
|
|
12
|
+
dappWhitelistAddress,
|
|
13
|
+
userAddress,
|
|
14
|
+
isUserStrict: vIsUserStrict,
|
|
8
15
|
});
|
|
9
16
|
};
|
|
10
|
-
import { WorkflowError } from '../utils/errors.js';
|
|
11
|
-
import { throwIfMissing } from '../utils/validators.js';
|
|
12
|
-
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
13
|
-
export const fetchMyContacts = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), dappAddressOrENS = throwIfMissing(), dappWhitelistAddress = throwIfMissing(), }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
try {
|
|
15
|
-
const userAddress = yield iexec.wallet.getAddress();
|
|
16
|
-
return yield fetchUserContacts({
|
|
17
|
-
iexec,
|
|
18
|
-
graphQLClient,
|
|
19
|
-
dappAddressOrENS,
|
|
20
|
-
dappWhitelistAddress,
|
|
21
|
-
userAddress,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new WorkflowError(`Failed to fetch my contacts: ${error.message}`, error);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
17
|
//# sourceMappingURL=fetchMyContacts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchMyContacts.js","sourceRoot":"","sources":["../../src/web3mail/fetchMyContacts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchMyContacts.js","sourceRoot":"","sources":["../../src/web3mail/fetchMyContacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAU3D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,aAAa,GAAG,cAAc,EAAE,EAChC,KAAK,GAAG,cAAc,EAAE,EACxB,gBAAgB,GAAG,cAAc,EAAE,EACnC,oBAAoB,GAAG,cAAc,EAAE,EACvC,YAAY,GAAG,KAAK,GAKC,EAAsB,EAAE;IAC7C,MAAM,aAAa,GAAG,aAAa,EAAE;SAClC,KAAK,CAAC,cAAc,CAAC;SACrB,YAAY,CAAC,YAAY,CAAC,CAAC;IAE9B,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACpD,OAAO,iBAAiB,CAAC;QACvB,KAAK;QACL,aAAa;QACb,gBAAgB;QAChB,oBAAoB;QACpB,WAAW;QACX,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Contact, DappAddressConsumer, DappWhitelistAddressConsumer, FetchUserContactsParams, IExecConsumer, SubgraphConsumer } from './types.js';
|
|
2
|
-
export declare const fetchUserContacts: ({ graphQLClient, iexec, dappAddressOrENS, dappWhitelistAddress, userAddress, }: IExecConsumer & SubgraphConsumer & DappAddressConsumer & DappWhitelistAddressConsumer & FetchUserContactsParams) => Promise<Contact[]>;
|
|
2
|
+
export declare const fetchUserContacts: ({ graphQLClient, iexec, dappAddressOrENS, dappWhitelistAddress, userAddress, isUserStrict, }: IExecConsumer & SubgraphConsumer & DappAddressConsumer & DappWhitelistAddressConsumer & FetchUserContactsParams) => Promise<Contact[]>;
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { ANY_DATASET_ADDRESS } from '../config/config.js';
|
|
11
|
-
import { WorkflowError } from '../utils/errors.js';
|
|
2
|
+
import { handleIfProtocolError, WorkflowError } from '../utils/errors.js';
|
|
12
3
|
import { autoPaginateRequest } from '../utils/paginate.js';
|
|
13
4
|
import { getValidContact } from '../utils/subgraphQuery.js';
|
|
14
|
-
import { addressOrEnsSchema, addressSchema, isEnsTest, throwIfMissing, } from '../utils/validators.js';
|
|
15
|
-
export const fetchUserContacts = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), dappAddressOrENS = throwIfMissing(), dappWhitelistAddress = throwIfMissing(), userAddress,
|
|
5
|
+
import { addressOrEnsSchema, addressSchema, booleanSchema, isEnsTest, throwIfMissing, } from '../utils/validators.js';
|
|
6
|
+
export const fetchUserContacts = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), dappAddressOrENS = throwIfMissing(), dappWhitelistAddress = throwIfMissing(), userAddress, isUserStrict = false, }) => {
|
|
16
7
|
try {
|
|
17
8
|
const vDappAddressOrENS = addressOrEnsSchema()
|
|
18
9
|
.required()
|
|
@@ -26,23 +17,28 @@ export const fetchUserContacts = ({ graphQLClient = throwIfMissing(), iexec = th
|
|
|
26
17
|
.required()
|
|
27
18
|
.label('userAddress')
|
|
28
19
|
.validateSync(userAddress);
|
|
29
|
-
const
|
|
20
|
+
const vIsUserStrict = booleanSchema()
|
|
21
|
+
.label('isUserStrict')
|
|
22
|
+
.validateSync(isUserStrict);
|
|
23
|
+
const [dappOrders, whitelistOrders] = await Promise.all([
|
|
30
24
|
fetchAllOrdersByApp({
|
|
31
25
|
iexec,
|
|
32
26
|
userAddress: vUserAddress,
|
|
33
27
|
appAddress: vDappAddressOrENS,
|
|
28
|
+
isUserStrict: vIsUserStrict,
|
|
34
29
|
}),
|
|
35
30
|
fetchAllOrdersByApp({
|
|
36
31
|
iexec,
|
|
37
32
|
userAddress: vUserAddress,
|
|
38
33
|
appAddress: vDappWhitelistAddress,
|
|
34
|
+
isUserStrict: vIsUserStrict,
|
|
39
35
|
}),
|
|
40
36
|
]);
|
|
41
37
|
const orders = dappOrders.concat(whitelistOrders);
|
|
42
38
|
const myContacts = [];
|
|
43
39
|
let web3DappResolvedAddress = vDappAddressOrENS;
|
|
44
40
|
if (isEnsTest(vDappAddressOrENS)) {
|
|
45
|
-
web3DappResolvedAddress =
|
|
41
|
+
web3DappResolvedAddress = await iexec.ens.resolveName(vDappAddressOrENS);
|
|
46
42
|
}
|
|
47
43
|
orders.forEach((order) => {
|
|
48
44
|
if (order.order.apprestrict.toLowerCase() ===
|
|
@@ -59,25 +55,28 @@ export const fetchUserContacts = ({ graphQLClient = throwIfMissing(), iexec = th
|
|
|
59
55
|
});
|
|
60
56
|
//getValidContact function remove duplicated contacts for the same protectedData address,
|
|
61
57
|
//keeping the most recent one
|
|
62
|
-
return
|
|
58
|
+
return await getValidContact(graphQLClient, myContacts);
|
|
63
59
|
}
|
|
64
60
|
catch (error) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const ordersFirstPage = iexec.orderbook.fetchDatasetOrderbook(ANY_DATASET_ADDRESS, {
|
|
71
|
-
app: appAddress,
|
|
72
|
-
requester: userAddress,
|
|
73
|
-
isAppStrict: true,
|
|
74
|
-
// Use maxPageSize here to avoid too many round-trips (we want everything anyway)
|
|
75
|
-
pageSize: 1000,
|
|
76
|
-
});
|
|
77
|
-
const { orders: allOrders } = yield autoPaginateRequest({
|
|
78
|
-
request: ordersFirstPage,
|
|
61
|
+
handleIfProtocolError(error);
|
|
62
|
+
throw new WorkflowError({
|
|
63
|
+
message: 'Failed to fetch user contacts',
|
|
64
|
+
errorCause: error,
|
|
79
65
|
});
|
|
80
|
-
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
async function fetchAllOrdersByApp({ iexec, userAddress, appAddress, isUserStrict, }) {
|
|
69
|
+
const ordersFirstPage = iexec.orderbook.fetchDatasetOrderbook(ANY_DATASET_ADDRESS, {
|
|
70
|
+
app: appAddress,
|
|
71
|
+
requester: userAddress,
|
|
72
|
+
isAppStrict: true,
|
|
73
|
+
isRequesterStrict: isUserStrict,
|
|
74
|
+
// Use maxPageSize here to avoid too many round-trips (we want everything anyway)
|
|
75
|
+
pageSize: 1000,
|
|
76
|
+
});
|
|
77
|
+
const { orders: allOrders } = await autoPaginateRequest({
|
|
78
|
+
request: ordersFirstPage,
|
|
81
79
|
});
|
|
80
|
+
return allOrders;
|
|
82
81
|
}
|
|
83
82
|
//# sourceMappingURL=fetchUserContacts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchUserContacts.js","sourceRoot":"","sources":["../../src/web3mail/fetchUserContacts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchUserContacts.js","sourceRoot":"","sources":["../../src/web3mail/fetchUserContacts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,EACT,cAAc,GACf,MAAM,wBAAwB,CAAC;AAUhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,aAAa,GAAG,cAAc,EAAE,EAChC,KAAK,GAAG,cAAc,EAAE,EACxB,gBAAgB,GAAG,cAAc,EAAE,EACnC,oBAAoB,GAAG,cAAc,EAAE,EACvC,WAAW,EACX,YAAY,GAAG,KAAK,GAKG,EAAsB,EAAE;IAC/C,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,kBAAkB,EAAE;aAC3C,QAAQ,EAAE;aACV,KAAK,CAAC,kBAAkB,CAAC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