@iexec/web3mail 1.6.0-nightly-b2a0e93 → 1.7.0
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/utils/subgraphQuery.js +1 -2
- package/dist/utils/subgraphQuery.js.map +1 -1
- package/dist/utils/validators.d.ts +35 -0
- package/dist/utils/validators.js +45 -1
- package/dist/utils/validators.js.map +1 -1
- package/dist/web3mail/IExecWeb3mail.d.ts +4 -2
- package/dist/web3mail/IExecWeb3mail.js +24 -1
- package/dist/web3mail/IExecWeb3mail.js.map +1 -1
- package/dist/web3mail/fetchMyContacts.js +2 -1
- package/dist/web3mail/fetchMyContacts.js.map +1 -1
- package/dist/web3mail/fetchUserContacts.js +1 -1
- package/dist/web3mail/fetchUserContacts.js.map +1 -1
- package/dist/web3mail/internalTypes.d.ts +4 -4
- package/dist/web3mail/prepareEmailCampaign.d.ts +4 -0
- package/dist/web3mail/prepareEmailCampaign.js +106 -0
- package/dist/web3mail/prepareEmailCampaign.js.map +1 -0
- package/dist/web3mail/sendEmail.d.ts +2 -2
- package/dist/web3mail/sendEmail.js +191 -135
- package/dist/web3mail/sendEmail.js.map +1 -1
- package/dist/web3mail/sendEmailCampaign.d.ts +4 -0
- package/dist/web3mail/sendEmailCampaign.js +43 -0
- package/dist/web3mail/sendEmailCampaign.js.map +1 -0
- package/dist/web3mail/types.d.ts +83 -24
- package/package.json +3 -4
- package/src/utils/subgraphQuery.ts +1 -2
- package/src/utils/validators.ts +68 -1
- package/src/web3mail/IExecWeb3mail.ts +38 -5
- package/src/web3mail/fetchMyContacts.ts +2 -1
- package/src/web3mail/fetchUserContacts.ts +7 -5
- package/src/web3mail/internalTypes.ts +5 -3
- package/src/web3mail/prepareEmailCampaign.ts +170 -0
- package/src/web3mail/sendEmail.ts +246 -150
- package/src/web3mail/sendEmailCampaign.ts +69 -0
- package/src/web3mail/types.ts +88 -26
|
@@ -1,53 +1,164 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_DATA_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, } from '../config/config.js';
|
|
2
|
+
import { CALLBACK_WEB3MAIL, DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_DATA_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, } from '../config/config.js';
|
|
3
3
|
import { handleIfProtocolError, WorkflowError } from '../utils/errors.js';
|
|
4
|
+
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
4
5
|
import * as ipfs from '../utils/ipfs-service.js';
|
|
5
6
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
6
|
-
import { addressOrEnsSchema, booleanSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
|
|
7
|
-
|
|
7
|
+
import { addressOrEnsSchema, addressSchema, booleanSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
|
|
8
|
+
import { checkUserVoucher, filterWorkerpoolOrders, } from './sendEmail.models.js';
|
|
9
|
+
export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), workerpoolAddressOrEns, dappAddressOrENS, dappWhitelistAddress, ipfsNode, ipfsGateway, emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, label, dataMaxPrice = MAX_DESIRED_DATA_ORDER_PRICE, appMaxPrice = MAX_DESIRED_APP_ORDER_PRICE, workerpoolMaxPrice = MAX_DESIRED_WORKERPOOL_ORDER_PRICE, senderName, protectedData, useVoucher = false, }) => {
|
|
10
|
+
const vDatasetAddress = addressOrEnsSchema()
|
|
11
|
+
.required()
|
|
12
|
+
.label('protectedData')
|
|
13
|
+
.validateSync(protectedData);
|
|
14
|
+
const vEmailSubject = emailSubjectSchema()
|
|
15
|
+
.required()
|
|
16
|
+
.label('emailSubject')
|
|
17
|
+
.validateSync(emailSubject);
|
|
18
|
+
const vEmailContent = emailContentSchema()
|
|
19
|
+
.required()
|
|
20
|
+
.label('emailContent')
|
|
21
|
+
.validateSync(emailContent);
|
|
22
|
+
const vContentType = contentTypeSchema()
|
|
23
|
+
.required()
|
|
24
|
+
.label('contentType')
|
|
25
|
+
.validateSync(contentType);
|
|
26
|
+
const vSenderName = senderNameSchema()
|
|
27
|
+
.label('senderName')
|
|
28
|
+
.validateSync(senderName);
|
|
29
|
+
const vLabel = labelSchema().label('label').validateSync(label);
|
|
30
|
+
const vWorkerpoolAddressOrEns = addressOrEnsSchema()
|
|
31
|
+
.required()
|
|
32
|
+
.label('WorkerpoolAddressOrEns')
|
|
33
|
+
.validateSync(workerpoolAddressOrEns);
|
|
34
|
+
const vDappAddressOrENS = addressOrEnsSchema()
|
|
35
|
+
.required()
|
|
36
|
+
.label('dappAddressOrENS')
|
|
37
|
+
.validateSync(dappAddressOrENS);
|
|
38
|
+
const vDappWhitelistAddress = addressSchema()
|
|
39
|
+
.required()
|
|
40
|
+
.label('dappWhitelistAddress')
|
|
41
|
+
.validateSync(dappWhitelistAddress);
|
|
42
|
+
const vDataMaxPrice = positiveNumberSchema()
|
|
43
|
+
.label('dataMaxPrice')
|
|
44
|
+
.validateSync(dataMaxPrice);
|
|
45
|
+
const vAppMaxPrice = positiveNumberSchema()
|
|
46
|
+
.label('appMaxPrice')
|
|
47
|
+
.validateSync(appMaxPrice);
|
|
48
|
+
const vWorkerpoolMaxPrice = positiveNumberSchema()
|
|
49
|
+
.label('workerpoolMaxPrice')
|
|
50
|
+
.validateSync(workerpoolMaxPrice);
|
|
51
|
+
const vUseVoucher = booleanSchema()
|
|
52
|
+
.label('useVoucher')
|
|
53
|
+
.validateSync(useVoucher);
|
|
54
|
+
// Check protected data schema through subgraph
|
|
55
|
+
const isValidProtectedData = await checkProtectedDataValidity(graphQLClient, vDatasetAddress);
|
|
56
|
+
if (!isValidProtectedData) {
|
|
57
|
+
throw new Error('This protected data does not contain "email:string" in its schema.');
|
|
58
|
+
}
|
|
59
|
+
const requesterAddress = await iexec.wallet.getAddress();
|
|
60
|
+
let userVoucher;
|
|
61
|
+
if (vUseVoucher) {
|
|
62
|
+
try {
|
|
63
|
+
userVoucher = await iexec.voucher.showUserVoucher(requesterAddress);
|
|
64
|
+
checkUserVoucher({ userVoucher });
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
if (err?.message?.startsWith('No Voucher found for address')) {
|
|
68
|
+
throw new Error('Oops, it seems your wallet is not associated with any voucher. Check on https://builder.iex.ec/');
|
|
69
|
+
}
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
8
73
|
try {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
74
|
+
const [datasetorderForApp, datasetorderForWhitelist, apporder, workerpoolorder,] = await Promise.all([
|
|
75
|
+
// Fetch dataset order for web3mail app
|
|
76
|
+
iexec.orderbook
|
|
77
|
+
.fetchDatasetOrderbook({
|
|
78
|
+
dataset: vDatasetAddress,
|
|
79
|
+
app: dappAddressOrENS,
|
|
80
|
+
requester: requesterAddress,
|
|
81
|
+
})
|
|
82
|
+
.then((datasetOrderbook) => {
|
|
83
|
+
const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
|
|
84
|
+
return desiredPriceDataOrderbook[0]?.order; // may be undefined
|
|
85
|
+
}),
|
|
86
|
+
// Fetch dataset order for web3mail whitelist
|
|
87
|
+
iexec.orderbook
|
|
88
|
+
.fetchDatasetOrderbook({
|
|
89
|
+
dataset: vDatasetAddress,
|
|
90
|
+
app: vDappWhitelistAddress,
|
|
91
|
+
requester: requesterAddress,
|
|
92
|
+
})
|
|
93
|
+
.then((datasetOrderbook) => {
|
|
94
|
+
const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
|
|
95
|
+
return desiredPriceDataOrderbook[0]?.order; // may be undefined
|
|
96
|
+
}),
|
|
97
|
+
// Fetch app order
|
|
98
|
+
iexec.orderbook
|
|
99
|
+
.fetchAppOrderbook({
|
|
100
|
+
app: dappAddressOrENS,
|
|
101
|
+
minTag: ['tee', 'scone'],
|
|
102
|
+
maxTag: ['tee', 'scone'],
|
|
103
|
+
workerpool: workerpoolAddressOrEns,
|
|
104
|
+
})
|
|
105
|
+
.then((appOrderbook) => {
|
|
106
|
+
const desiredPriceAppOrderbook = appOrderbook.orders.filter((order) => order.order.appprice <= vAppMaxPrice);
|
|
107
|
+
const desiredPriceAppOrder = desiredPriceAppOrderbook[0]?.order;
|
|
108
|
+
if (!desiredPriceAppOrder) {
|
|
109
|
+
throw new Error('No App order found for the desired price');
|
|
110
|
+
}
|
|
111
|
+
return desiredPriceAppOrder;
|
|
112
|
+
}),
|
|
113
|
+
// Fetch workerpool order for App or AppWhitelist
|
|
114
|
+
Promise.all([
|
|
115
|
+
// for app
|
|
116
|
+
iexec.orderbook.fetchWorkerpoolOrderbook({
|
|
117
|
+
workerpool: workerpoolAddressOrEns,
|
|
118
|
+
app: vDappAddressOrENS,
|
|
119
|
+
dataset: vDatasetAddress,
|
|
120
|
+
requester: requesterAddress, // public orders + user specific orders
|
|
121
|
+
isRequesterStrict: useVoucher, // If voucher, we only want user specific orders
|
|
122
|
+
minTag: ['tee', 'scone'],
|
|
123
|
+
maxTag: ['tee', 'scone'],
|
|
124
|
+
category: 0,
|
|
125
|
+
}),
|
|
126
|
+
// for app whitelist
|
|
127
|
+
iexec.orderbook.fetchWorkerpoolOrderbook({
|
|
128
|
+
workerpool: workerpoolAddressOrEns,
|
|
129
|
+
app: vDappWhitelistAddress,
|
|
130
|
+
dataset: vDatasetAddress,
|
|
131
|
+
requester: requesterAddress, // public orders + user specific orders
|
|
132
|
+
isRequesterStrict: useVoucher, // If voucher, we only want user specific orders
|
|
133
|
+
minTag: ['tee', 'scone'],
|
|
134
|
+
maxTag: ['tee', 'scone'],
|
|
135
|
+
category: 0,
|
|
136
|
+
}),
|
|
137
|
+
]).then(([workerpoolOrderbookForApp, workerpoolOrderbookForAppWhitelist]) => {
|
|
138
|
+
const desiredPriceWorkerpoolOrder = filterWorkerpoolOrders({
|
|
139
|
+
workerpoolOrders: [
|
|
140
|
+
...workerpoolOrderbookForApp.orders,
|
|
141
|
+
...workerpoolOrderbookForAppWhitelist.orders,
|
|
142
|
+
],
|
|
143
|
+
workerpoolMaxPrice: vWorkerpoolMaxPrice,
|
|
144
|
+
useVoucher: vUseVoucher,
|
|
145
|
+
userVoucher,
|
|
146
|
+
});
|
|
147
|
+
if (!desiredPriceWorkerpoolOrder) {
|
|
148
|
+
throw new Error('No Workerpool order found for the desired price');
|
|
149
|
+
}
|
|
150
|
+
return desiredPriceWorkerpoolOrder;
|
|
151
|
+
}),
|
|
152
|
+
]);
|
|
153
|
+
if (!workerpoolorder) {
|
|
154
|
+
throw new Error('No Workerpool order found for the desired price');
|
|
155
|
+
}
|
|
156
|
+
const datasetorder = datasetorderForApp || datasetorderForWhitelist;
|
|
157
|
+
if (!datasetorder) {
|
|
158
|
+
throw new Error('No Dataset order found for the desired price');
|
|
159
|
+
}
|
|
160
|
+
// Push requester secrets
|
|
161
|
+
const requesterSecretId = generateSecureUniqueId(16);
|
|
51
162
|
const emailContentEncryptionKey = iexec.dataset.generateEncryptionKey();
|
|
52
163
|
const encryptedFile = await iexec.dataset
|
|
53
164
|
.encrypt(Buffer.from(vEmailContent, 'utf8'), emailContentEncryptionKey)
|
|
@@ -57,11 +168,10 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
57
168
|
errorCause: e,
|
|
58
169
|
});
|
|
59
170
|
});
|
|
60
|
-
// Push email message to IPFS
|
|
61
171
|
const cid = await ipfs
|
|
62
172
|
.add(encryptedFile, {
|
|
63
|
-
ipfsNode,
|
|
64
|
-
ipfsGateway,
|
|
173
|
+
ipfsNode: ipfsNode,
|
|
174
|
+
ipfsGateway: ipfsGateway,
|
|
65
175
|
})
|
|
66
176
|
.catch((e) => {
|
|
67
177
|
throw new WorkflowError({
|
|
@@ -70,101 +180,47 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
70
180
|
});
|
|
71
181
|
});
|
|
72
182
|
const multiaddr = `/ipfs/${cid}`;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
contentType: vContentType,
|
|
83
|
-
emailContentEncryptionKey,
|
|
84
|
-
}),
|
|
85
|
-
};
|
|
86
|
-
// Bulk processing
|
|
87
|
-
if (grantedAccess) {
|
|
88
|
-
const vMaxProtectedDataPerTask = positiveNumberSchema()
|
|
89
|
-
.label('maxProtectedDataPerTask')
|
|
90
|
-
.validateSync(maxProtectedDataPerTask);
|
|
91
|
-
const bulkRequest = await dataProtector.prepareBulkRequest({
|
|
92
|
-
app: vDappAddressOrENS,
|
|
93
|
-
appMaxPrice: vAppMaxPrice,
|
|
94
|
-
workerpoolMaxPrice: vWorkerpoolMaxPrice,
|
|
95
|
-
workerpool: vWorkerpoolAddressOrEns,
|
|
96
|
-
args: vLabel,
|
|
97
|
-
inputFiles: [],
|
|
98
|
-
secrets,
|
|
99
|
-
bulkAccesses: grantedAccess,
|
|
100
|
-
maxProtectedDataPerTask: vMaxProtectedDataPerTask,
|
|
101
|
-
});
|
|
102
|
-
const processBulkRequestResponse = await dataProtector.processBulkRequest({
|
|
103
|
-
bulkRequest: bulkRequest.bulkRequest,
|
|
104
|
-
useVoucher: vUseVoucher,
|
|
105
|
-
workerpool: vWorkerpoolAddressOrEns,
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
tasks: processBulkRequestResponse.tasks.map((task) => ({
|
|
109
|
-
taskId: task.taskId,
|
|
110
|
-
dealId: task.dealId,
|
|
111
|
-
bulkIndex: task.bulkIndex,
|
|
112
|
-
})),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
// Single processing mode - protectedData is required
|
|
116
|
-
const vDatasetAddress = addressOrEnsSchema()
|
|
117
|
-
.required()
|
|
118
|
-
.label('protectedData')
|
|
119
|
-
.validateSync(protectedData);
|
|
120
|
-
// Check protected data validity through subgraph
|
|
121
|
-
const isValidProtectedData = await checkProtectedDataValidity(graphQLClient, vDatasetAddress);
|
|
122
|
-
if (!isValidProtectedData) {
|
|
123
|
-
throw new Error('This protected data does not contain "email:string" in its schema.');
|
|
124
|
-
}
|
|
125
|
-
// Use processProtectedData from dataprotector
|
|
126
|
-
const result = await dataProtector.processProtectedData({
|
|
127
|
-
defaultWorkerpool: vWorkerpoolAddressOrEns,
|
|
128
|
-
protectedData: vDatasetAddress,
|
|
183
|
+
await iexec.secrets.pushRequesterSecret(requesterSecretId, JSON.stringify({
|
|
184
|
+
emailSubject: vEmailSubject,
|
|
185
|
+
emailContentMultiAddr: multiaddr,
|
|
186
|
+
contentType: vContentType,
|
|
187
|
+
senderName: vSenderName,
|
|
188
|
+
emailContentEncryptionKey,
|
|
189
|
+
useCallback: true,
|
|
190
|
+
}));
|
|
191
|
+
const requestorderToSign = await iexec.order.createRequestorder({
|
|
129
192
|
app: vDappAddressOrENS,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
193
|
+
category: workerpoolorder.category,
|
|
194
|
+
dataset: vDatasetAddress,
|
|
195
|
+
datasetmaxprice: datasetorder.datasetprice,
|
|
196
|
+
appmaxprice: apporder.appprice,
|
|
197
|
+
workerpoolmaxprice: workerpoolorder.workerpoolprice,
|
|
198
|
+
tag: ['tee', 'scone'],
|
|
134
199
|
workerpool: vWorkerpoolAddressOrEns,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
200
|
+
callback: CALLBACK_WEB3MAIL,
|
|
201
|
+
params: {
|
|
202
|
+
iexec_secrets: {
|
|
203
|
+
1: requesterSecretId,
|
|
204
|
+
},
|
|
205
|
+
iexec_args: vLabel,
|
|
206
|
+
},
|
|
140
207
|
});
|
|
208
|
+
const requestorder = await iexec.order.signRequestorder(requestorderToSign);
|
|
209
|
+
// Match orders and compute task ID
|
|
210
|
+
const { dealid: dealId } = await iexec.order.matchOrders({
|
|
211
|
+
apporder: apporder,
|
|
212
|
+
datasetorder: datasetorder,
|
|
213
|
+
workerpoolorder: workerpoolorder,
|
|
214
|
+
requestorder: requestorder,
|
|
215
|
+
}, { useVoucher: vUseVoucher });
|
|
216
|
+
const taskId = await iexec.deal.computeTaskId(dealId, 0);
|
|
141
217
|
return {
|
|
142
|
-
taskId
|
|
218
|
+
taskId,
|
|
219
|
+
dealId,
|
|
143
220
|
};
|
|
144
221
|
}
|
|
145
222
|
catch (error) {
|
|
146
|
-
// Protocol error detected, re-throwing as-is
|
|
147
|
-
if (error?.isProtocolError === true) {
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
// Handle protocol errors - this will throw if it's an ApiCallError
|
|
151
|
-
// handleIfProtocolError transforms ApiCallError into a WorkflowError with isProtocolError=true
|
|
152
223
|
handleIfProtocolError(error);
|
|
153
|
-
// If we reach here, it's not a protocol error
|
|
154
|
-
// Check if it's a WorkflowError from processProtectedData by checking the message
|
|
155
|
-
const isProcessProtectedDataError = error instanceof Error &&
|
|
156
|
-
error.message === 'Failed to process protected data';
|
|
157
|
-
if (isProcessProtectedDataError) {
|
|
158
|
-
const cause = error?.cause;
|
|
159
|
-
// Return unwrapped cause (the actual Error object)
|
|
160
|
-
// error.cause should be an Error, but ensure it is
|
|
161
|
-
const unwrappedCause = cause instanceof Error ? cause : error;
|
|
162
|
-
throw new WorkflowError({
|
|
163
|
-
message: 'Failed to sendEmail',
|
|
164
|
-
errorCause: unwrappedCause,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
// For all other errors
|
|
168
224
|
throw new WorkflowError({
|
|
169
225
|
message: 'Failed to sendEmail',
|
|
170
226
|
errorCause: error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,GACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,GACf,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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CampaignParams, SendEmailCampaignResponse } from './types.js';
|
|
2
|
+
import { DataProtectorConsumer } from './internalTypes.js';
|
|
3
|
+
export type SendEmailCampaign = typeof sendEmailCampaign;
|
|
4
|
+
export declare const sendEmailCampaign: ({ dataProtector, workerpoolAddressOrEns, campaignRequest, }: DataProtectorConsumer & SendEmailCampaignParams) => Promise<SendEmailCampaignResponse>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NULL_ADDRESS } from 'iexec/utils';
|
|
2
|
+
import { ValidationError } from 'yup';
|
|
3
|
+
import { handleIfProtocolError, WorkflowError } from '../utils/errors.js';
|
|
4
|
+
import { addressOrEnsSchema, campaignRequestSchema, throwIfMissing, } from '../utils/validators.js';
|
|
5
|
+
export const sendEmailCampaign = async ({ dataProtector = throwIfMissing(), workerpoolAddressOrEns = throwIfMissing(), campaignRequest, }) => {
|
|
6
|
+
const vCampaignRequest = campaignRequestSchema()
|
|
7
|
+
.required()
|
|
8
|
+
.label('campaignRequest')
|
|
9
|
+
.validateSync(campaignRequest);
|
|
10
|
+
const vWorkerpoolAddressOrEns = addressOrEnsSchema()
|
|
11
|
+
.required()
|
|
12
|
+
.label('workerpoolAddressOrEns')
|
|
13
|
+
.validateSync(workerpoolAddressOrEns);
|
|
14
|
+
if (vCampaignRequest.workerpool !== NULL_ADDRESS &&
|
|
15
|
+
vCampaignRequest.workerpool.toLowerCase() !==
|
|
16
|
+
vWorkerpoolAddressOrEns.toLowerCase()) {
|
|
17
|
+
throw new ValidationError("workerpoolAddressOrEns doesn't match campaignRequest workerpool");
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
// Process the prepared bulk request
|
|
21
|
+
const processBulkRequestResponse = await dataProtector.processBulkRequest({
|
|
22
|
+
bulkRequest: vCampaignRequest,
|
|
23
|
+
workerpool: vWorkerpoolAddressOrEns,
|
|
24
|
+
waitForResult: false,
|
|
25
|
+
});
|
|
26
|
+
return processBulkRequestResponse;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// Protocol error detected, re-throwing as-is
|
|
30
|
+
if (error?.isProtocolError === true) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
// Handle protocol errors - this will throw if it's an ApiCallError
|
|
34
|
+
// handleIfProtocolError transforms ApiCallError into a WorkflowError with isProtocolError=true
|
|
35
|
+
handleIfProtocolError(error);
|
|
36
|
+
// For all other errors
|
|
37
|
+
throw new WorkflowError({
|
|
38
|
+
message: 'Failed to sendEmailCampaign',
|
|
39
|
+
errorCause: error,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=sendEmailCampaign.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendEmailCampaign.js","sourceRoot":"","sources":["../../src/web3mail/sendEmailCampaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAUhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,EACtC,aAAa,GAAG,cAAc,EAAE,EAChC,sBAAsB,GAAG,cAAc,EAAE,EACzC,eAAe,GAEQ,EAAsC,EAAE;IAC/D,MAAM,gBAAgB,GAAG,qBAAqB,EAAE;SAC7C,QAAQ,EAAE;SACV,KAAK,CAAC,iBAAiB,CAAC;SACxB,YAAY,CAAC,eAAe,CAAoB,CAAC;IAEpD,MAAM,uBAAuB,GAAG,kBAAkB,EAAE;SACjD,QAAQ,EAAE;SACV,KAAK,CAAC,wBAAwB,CAAC;SAC/B,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAExC,IACE,gBAAgB,CAAC,UAAU,KAAK,YAAY;QAC5C,gBAAgB,CAAC,UAAU,CAAC,WAAW,EAAE;YACvC,uBAAuB,CAAC,WAAW,EAAE,EACvC,CAAC;QACD,MAAM,IAAI,eAAe,CACvB,iEAAiE,CAClE,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,oCAAoC;QACpC,MAAM,0BAA0B,GAAG,MAAM,aAAa,CAAC,kBAAkB,CAAC;YACxE,WAAW,EAAE,gBAAgB;YAC7B,UAAU,EAAE,uBAAuB;YACnC,aAAa,EAAE,KAAK;SACrB,CAAC,CAAC;QAEH,OAAO,0BAA0B,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6CAA6C;QAC7C,IAAK,KAAa,EAAE,eAAe,KAAK,IAAI,EAAE,CAAC;YAC7C,MAAM,KAAK,CAAC;QACd,CAAC;QAED,mEAAmE;QACnE,+FAA+F;QAC/F,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE7B,uBAAuB;QACvB,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EAAE,6BAA6B;YACtC,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
package/dist/web3mail/types.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { EnhancedWallet } from 'iexec';
|
|
2
2
|
import { IExecConfigOptions } from 'iexec/IExecConfig';
|
|
3
|
+
import type { BulkRequest } from '@iexec/dataprotector';
|
|
3
4
|
export type Web3SignerProvider = EnhancedWallet;
|
|
4
5
|
export type ENS = string;
|
|
5
6
|
export type AddressOrENS = Address | ENS;
|
|
6
7
|
export type Address = string;
|
|
7
8
|
export type TimeStamp = string;
|
|
9
|
+
/**
|
|
10
|
+
* request to send email in bulk
|
|
11
|
+
*
|
|
12
|
+
* use `prepareEmailCampaign()` to create a `CampaignRequest`
|
|
13
|
+
*
|
|
14
|
+
* then use `sendEmailCampaign()` to send the campaign
|
|
15
|
+
*/
|
|
16
|
+
export type CampaignRequest = BulkRequest;
|
|
17
|
+
/**
|
|
18
|
+
* authorization signed by the data owner granting access to this contact
|
|
19
|
+
*
|
|
20
|
+
* `GrantedAccess` are obtained by fetching contacts (e.g. `fetchMyContacts()` or `fetchUserContacts()`)
|
|
21
|
+
*
|
|
22
|
+
* `GrantedAccess` can be consumed for email campaigns (e.g. `prepareEmailCampaign()` then `sendEmailCampaign()`)
|
|
23
|
+
*/
|
|
8
24
|
export type GrantedAccess = {
|
|
9
25
|
dataset: string;
|
|
10
26
|
datasetprice: string;
|
|
@@ -30,14 +46,7 @@ export type Contact = {
|
|
|
30
46
|
export type SendEmailParams = {
|
|
31
47
|
emailSubject: string;
|
|
32
48
|
emailContent: string;
|
|
33
|
-
protectedData
|
|
34
|
-
/**
|
|
35
|
-
* Granted access to process.
|
|
36
|
-
* use prepareBulkRequest of dataprotector to create a bulk request.
|
|
37
|
-
* if not provided, the single message will be processed.
|
|
38
|
-
*/
|
|
39
|
-
grantedAccess?: GrantedAccess[];
|
|
40
|
-
maxProtectedDataPerTask?: number;
|
|
49
|
+
protectedData: Address;
|
|
41
50
|
contentType?: string;
|
|
42
51
|
senderName?: string;
|
|
43
52
|
label?: string;
|
|
@@ -52,6 +61,9 @@ export type FetchMyContactsParams = {
|
|
|
52
61
|
* Get contacts for this specific user only
|
|
53
62
|
*/
|
|
54
63
|
isUserStrict?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* If true, returns only contacts with bulk processing access grants
|
|
66
|
+
*/
|
|
55
67
|
bulkOnly?: boolean;
|
|
56
68
|
};
|
|
57
69
|
export type FetchUserContactsParams = {
|
|
@@ -60,23 +72,16 @@ export type FetchUserContactsParams = {
|
|
|
60
72
|
*/
|
|
61
73
|
userAddress: Address;
|
|
62
74
|
} & FetchMyContactsParams;
|
|
63
|
-
type
|
|
75
|
+
export type SendEmailResponse = {
|
|
76
|
+
/**
|
|
77
|
+
* ID of the task
|
|
78
|
+
*/
|
|
64
79
|
taskId: string;
|
|
80
|
+
/**
|
|
81
|
+
* ID of the deal containing the task
|
|
82
|
+
*/
|
|
83
|
+
dealId: string;
|
|
65
84
|
};
|
|
66
|
-
type SendEmailBulkResponse = {
|
|
67
|
-
tasks: {
|
|
68
|
-
bulkIndex: number;
|
|
69
|
-
taskId: string;
|
|
70
|
-
dealId: string;
|
|
71
|
-
}[];
|
|
72
|
-
};
|
|
73
|
-
export type SendEmailResponse<Params = {
|
|
74
|
-
protectedData: Address;
|
|
75
|
-
}> = Params extends {
|
|
76
|
-
grantedAccess: GrantedAccess[];
|
|
77
|
-
} ? SendEmailBulkResponse : never & Params extends {
|
|
78
|
-
protectedData: Address;
|
|
79
|
-
} ? SendEmailSingleResponse : never;
|
|
80
85
|
/**
|
|
81
86
|
* Configuration options for Web3Mail.
|
|
82
87
|
*/
|
|
@@ -118,4 +123,58 @@ export type Web3MailConfigOptions = {
|
|
|
118
123
|
*/
|
|
119
124
|
allowExperimentalNetworks?: boolean;
|
|
120
125
|
};
|
|
121
|
-
export {
|
|
126
|
+
export type PrepareEmailCampaignParams = {
|
|
127
|
+
/**
|
|
128
|
+
* List of `GrantedAccess` to contacts to send emails to in bulk.
|
|
129
|
+
*
|
|
130
|
+
* use `fetchMyContacts({ bulkOnly: true })` to get granted accesses.
|
|
131
|
+
*/
|
|
132
|
+
grantedAccesses: GrantedAccess[];
|
|
133
|
+
maxProtectedDataPerTask?: number;
|
|
134
|
+
senderName?: string;
|
|
135
|
+
emailSubject: string;
|
|
136
|
+
emailContent: string;
|
|
137
|
+
contentType?: string;
|
|
138
|
+
label?: string;
|
|
139
|
+
workerpoolAddressOrEns?: AddressOrENS;
|
|
140
|
+
dataMaxPrice?: number;
|
|
141
|
+
appMaxPrice?: number;
|
|
142
|
+
workerpoolMaxPrice?: number;
|
|
143
|
+
};
|
|
144
|
+
export type PrepareEmailCampaignResponse = {
|
|
145
|
+
/**
|
|
146
|
+
* The prepared campaign request
|
|
147
|
+
*
|
|
148
|
+
* Use this in `sendEmailCampaign()` to start or continue sending the campaign
|
|
149
|
+
*/
|
|
150
|
+
campaignRequest: CampaignRequest;
|
|
151
|
+
};
|
|
152
|
+
export type SendEmailCampaignParams = {
|
|
153
|
+
/**
|
|
154
|
+
* The prepared campaign request from `prepareEmailCampaign()`
|
|
155
|
+
*/
|
|
156
|
+
campaignRequest: CampaignRequest;
|
|
157
|
+
/**
|
|
158
|
+
* Workerpool address or ENS to use for processing
|
|
159
|
+
*/
|
|
160
|
+
workerpoolAddressOrEns?: AddressOrENS;
|
|
161
|
+
};
|
|
162
|
+
export type SendEmailCampaignResponse = {
|
|
163
|
+
/**
|
|
164
|
+
* List of tasks created for the campaign
|
|
165
|
+
*/
|
|
166
|
+
tasks: Array<{
|
|
167
|
+
/**
|
|
168
|
+
* ID of the task
|
|
169
|
+
*/
|
|
170
|
+
taskId: string;
|
|
171
|
+
/**
|
|
172
|
+
* ID of the deal containing the task
|
|
173
|
+
*/
|
|
174
|
+
dealId: string;
|
|
175
|
+
/**
|
|
176
|
+
* Index of the task in the bulk request
|
|
177
|
+
*/
|
|
178
|
+
bulkIndex: number;
|
|
179
|
+
}>;
|
|
180
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iexec/web3mail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "rm -rf dist && tsc --project tsconfig.build.json",
|
|
22
22
|
"check-types": "tsc --noEmit",
|
|
23
|
-
"test:prepare": "node tests/scripts/prepare-bellecour-fork-for-tests.js",
|
|
24
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --forceExit -b",
|
|
23
|
+
"test:prepare": "node tests/scripts/prepare-bellecour-fork-for-tests.js && node tests/scripts/prepare-iexec.js",
|
|
25
24
|
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --forceExit --coverage",
|
|
26
25
|
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/unit/**/*.test.ts\" -b",
|
|
27
26
|
"test:unit:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/unit/**/*.unit.ts\" --coverage",
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
"format": "prettier --write \"(src|tests)/**/*.ts\"",
|
|
32
31
|
"check-format": "prettier --check \"(src|tests)/**/*.ts\"",
|
|
33
32
|
"stop-test-stack": "cd tests && docker compose down --volumes --remove-orphans",
|
|
34
|
-
"start-test-stack": "cd tests && npm run stop-test-stack && node scripts/prepare-test-env.js && docker compose build && docker compose up -d &&
|
|
33
|
+
"start-test-stack": "cd tests && npm run stop-test-stack && node scripts/prepare-test-env.js && docker compose build && docker compose up -d && npm run test:prepare"
|
|
35
34
|
},
|
|
36
35
|
"repository": {
|
|
37
36
|
"type": "git",
|
|
@@ -86,9 +86,8 @@ export const getValidContact = async (
|
|
|
86
86
|
grantedAccess: contact.grantedAccess,
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
-
return null;
|
|
90
89
|
})
|
|
91
|
-
.filter((contact) => contact
|
|
90
|
+
.filter((contact) => !!contact);
|
|
92
91
|
} catch (error) {
|
|
93
92
|
throw new WorkflowError({
|
|
94
93
|
message: 'Failed to fetch subgraph',
|