@iexec/web3mail 0.1.1 → 0.2.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.
@@ -3,3 +3,4 @@ export declare const WORKERPOOL_ADDRESS = "prod-v8-bellecour.main.pools.iexec.et
3
3
  export declare const DATAPROTECTOR_SUBGRAPH_ENDPOINT = "https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector";
4
4
  export declare const MAX_DESIRED_APP_ORDER_PRICE = 0;
5
5
  export declare const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
6
+ export declare const DEFAULT_CONTENT_TYPE = "text/plain";
@@ -3,3 +3,4 @@ export const WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
3
3
  export const DATAPROTECTOR_SUBGRAPH_ENDPOINT = 'https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector';
4
4
  export const MAX_DESIRED_APP_ORDER_PRICE = 0;
5
5
  export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
6
+ export const DEFAULT_CONTENT_TYPE = 'text/plain';
@@ -2,3 +2,4 @@ export declare const throwIfMissing: () => never;
2
2
  export declare const addressOrEnsSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
3
3
  export declare const emailSubjectSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
4
4
  export declare const emailContentSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
5
+ export declare const contentTypeSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
@@ -14,3 +14,6 @@ export const addressOrEnsSchema = () => string()
14
14
  export const emailSubjectSchema = () => string().max(78).strict();
15
15
  // 4096 bytes is the current max length for iExec SMS secrets
16
16
  export const emailContentSchema = () => string().max(4096).strict();
17
+ // Valid content types for the variable 'contentType'
18
+ const validContentTypes = ['text/plain', 'text/html'];
19
+ export const contentTypeSchema = () => string().oneOf(validContentTypes, 'Invalid contentType').optional();
@@ -1,2 +1,2 @@
1
1
  import { IExecConsumer, SendEmailParams, SendEmailResponse, SubgraphConsumer } from './types.js';
2
- export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
2
+ export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, contentType, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
@@ -7,12 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, WEB3_MAIL_DAPP_ADDRESS, WORKERPOOL_ADDRESS, } from '../config/config.js';
10
+ import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, WEB3_MAIL_DAPP_ADDRESS, WORKERPOOL_ADDRESS, } from '../config/config.js';
11
11
  import { WorkflowError } from '../utils/errors.js';
12
12
  import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
13
13
  import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
14
- import { addressOrEnsSchema, emailContentSchema, emailSubjectSchema, throwIfMissing, } from '../utils/validators.js';
15
- export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
14
+ import { addressOrEnsSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, throwIfMissing, } from '../utils/validators.js';
15
+ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
16
16
  var _a, _b, _c, _d, _e;
17
17
  try {
18
18
  const vDatasetAddress = addressOrEnsSchema()
@@ -27,6 +27,10 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
27
27
  .required()
28
28
  .label('emailContent')
29
29
  .validateSync(emailContent);
30
+ const vContentType = contentTypeSchema()
31
+ .required()
32
+ .label('contentType')
33
+ .validateSync(contentType);
30
34
  // Check protected data validity through subgraph
31
35
  const isValidProtectedData = yield checkProtectedDataValidity(graphQLClient, vDatasetAddress);
32
36
  if (!isValidProtectedData) {
@@ -85,8 +89,10 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
85
89
  // Push requester secrets
86
90
  const emailSubjectId = generateSecureUniqueId(16);
87
91
  const emailContentId = generateSecureUniqueId(16);
92
+ const optionsId = generateSecureUniqueId(16);
88
93
  yield iexec.secrets.pushRequesterSecret(emailSubjectId, vEmailSubject);
89
94
  yield iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
95
+ yield iexec.secrets.pushRequesterSecret(optionsId, JSON.stringify({ contentType: vContentType }));
90
96
  // Create and sign request order
91
97
  const requestorderToSign = yield iexec.order.createRequestorder({
92
98
  app: WEB3_MAIL_DAPP_ADDRESS,
@@ -101,6 +107,7 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
101
107
  iexec_secrets: {
102
108
  1: emailSubjectId,
103
109
  2: emailContentId,
110
+ 3: optionsId,
104
111
  },
105
112
  },
106
113
  });
@@ -1,5 +1,5 @@
1
- import { EnhancedWallet, IExec } from 'iexec';
2
1
  import { GraphQLClient } from 'graphql-request';
2
+ import { EnhancedWallet, IExec } from 'iexec';
3
3
  export type Web3SignerProvider = EnhancedWallet;
4
4
  export type IExecConsumer = {
5
5
  iexec: IExec;
@@ -15,6 +15,7 @@ export type SendEmailParams = {
15
15
  emailSubject: string;
16
16
  emailContent: string;
17
17
  protectedData: Address;
18
+ contentType?: string;
18
19
  };
19
20
  export type SendEmailResponse = {
20
21
  taskId: Address;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iexec/web3mail",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
5
5
  "main": "./dist/bundle.js",
6
6
  "type": "module",
@@ -4,3 +4,4 @@ export const DATAPROTECTOR_SUBGRAPH_ENDPOINT =
4
4
  'https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector';
5
5
  export const MAX_DESIRED_APP_ORDER_PRICE = 0;
6
6
  export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
7
+ export const DEFAULT_CONTENT_TYPE = 'text/plain';
@@ -25,3 +25,9 @@ export const emailSubjectSchema = () => string().max(78).strict();
25
25
 
26
26
  // 4096 bytes is the current max length for iExec SMS secrets
27
27
  export const emailContentSchema = () => string().max(4096).strict();
28
+
29
+ // Valid content types for the variable 'contentType'
30
+ const validContentTypes = ['text/plain', 'text/html'];
31
+
32
+ export const contentTypeSchema = () =>
33
+ string().oneOf(validContentTypes, 'Invalid contentType').optional();
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DEFAULT_CONTENT_TYPE,
2
3
  MAX_DESIRED_APP_ORDER_PRICE,
3
4
  MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
4
5
  WEB3_MAIL_DAPP_ADDRESS,
@@ -9,6 +10,7 @@ import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
9
10
  import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
10
11
  import {
11
12
  addressOrEnsSchema,
13
+ contentTypeSchema,
12
14
  emailContentSchema,
13
15
  emailSubjectSchema,
14
16
  throwIfMissing,
@@ -25,6 +27,7 @@ export const sendEmail = async ({
25
27
  iexec = throwIfMissing(),
26
28
  emailSubject,
27
29
  emailContent,
30
+ contentType = DEFAULT_CONTENT_TYPE,
28
31
  protectedData,
29
32
  }: IExecConsumer &
30
33
  SubgraphConsumer &
@@ -43,6 +46,11 @@ export const sendEmail = async ({
43
46
  .label('emailContent')
44
47
  .validateSync(emailContent);
45
48
 
49
+ const vContentType = contentTypeSchema()
50
+ .required()
51
+ .label('contentType')
52
+ .validateSync(contentType);
53
+
46
54
  // Check protected data validity through subgraph
47
55
  const isValidProtectedData = await checkProtectedDataValidity(
48
56
  graphQLClient,
@@ -128,9 +136,13 @@ export const sendEmail = async ({
128
136
  // Push requester secrets
129
137
  const emailSubjectId = generateSecureUniqueId(16);
130
138
  const emailContentId = generateSecureUniqueId(16);
139
+ const optionsId = generateSecureUniqueId(16);
131
140
  await iexec.secrets.pushRequesterSecret(emailSubjectId, vEmailSubject);
132
141
  await iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
133
-
142
+ await iexec.secrets.pushRequesterSecret(
143
+ optionsId,
144
+ JSON.stringify({ contentType: vContentType })
145
+ );
134
146
  // Create and sign request order
135
147
  const requestorderToSign = await iexec.order.createRequestorder({
136
148
  app: WEB3_MAIL_DAPP_ADDRESS,
@@ -145,6 +157,7 @@ export const sendEmail = async ({
145
157
  iexec_secrets: {
146
158
  1: emailSubjectId,
147
159
  2: emailContentId,
160
+ 3: optionsId,
148
161
  },
149
162
  },
150
163
  });
@@ -1,5 +1,5 @@
1
- import { EnhancedWallet, IExec } from 'iexec';
2
1
  import { GraphQLClient } from 'graphql-request';
2
+ import { EnhancedWallet, IExec } from 'iexec';
3
3
 
4
4
  export type Web3SignerProvider = EnhancedWallet;
5
5
 
@@ -20,6 +20,7 @@ export type SendEmailParams = {
20
20
  emailSubject: string;
21
21
  emailContent: string;
22
22
  protectedData: Address;
23
+ contentType?: string;
23
24
  };
24
25
 
25
26
  export type SendEmailResponse = {