@iexec/web3mail 0.2.0 → 0.3.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.
@@ -1 +1 @@
1
- export declare function generateSecureUniqueId(length: number): string;
1
+ export declare function generateSecureUniqueId(length: any): string;
@@ -1,5 +1,5 @@
1
- import crypto from 'crypto';
1
+ import { randomBytes } from '@ethersproject/random';
2
+ import { hexlify } from '@ethersproject/bytes';
2
3
  export function generateSecureUniqueId(length) {
3
- const buffer = crypto.randomBytes(length);
4
- return buffer.toString('hex');
4
+ return hexlify(randomBytes(length));
5
5
  }
@@ -3,3 +3,4 @@ export declare const addressOrEnsSchema: () => import("yup").StringSchema<string
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
5
  export declare const contentTypeSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
6
+ export declare const senderNameSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
@@ -17,3 +17,5 @@ export const emailContentSchema = () => string().max(4096).strict();
17
17
  // Valid content types for the variable 'contentType'
18
18
  const validContentTypes = ['text/plain', 'text/html'];
19
19
  export const contentTypeSchema = () => string().oneOf(validContentTypes, 'Invalid contentType').optional();
20
+ // Minimum of 3 characters and max of 20 to avoid sender being flagged as spam
21
+ export const senderNameSchema = () => string().trim().min(3).max(20).optional();
@@ -1,2 +1,2 @@
1
1
  import { IExecConsumer, SendEmailParams, SendEmailResponse, SubgraphConsumer } from './types.js';
2
- export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, contentType, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
2
+ export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, contentType, senderName, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
@@ -11,8 +11,8 @@ import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_WORKERPO
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, 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* () {
14
+ import { addressOrEnsSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
15
+ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, senderName, 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()
@@ -31,6 +31,9 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
31
31
  .required()
32
32
  .label('contentType')
33
33
  .validateSync(contentType);
34
+ const vSenderName = senderNameSchema()
35
+ .label('senderName')
36
+ .validateSync(senderName);
34
37
  // Check protected data validity through subgraph
35
38
  const isValidProtectedData = yield checkProtectedDataValidity(graphQLClient, vDatasetAddress);
36
39
  if (!isValidProtectedData) {
@@ -92,7 +95,7 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
92
95
  const optionsId = generateSecureUniqueId(16);
93
96
  yield iexec.secrets.pushRequesterSecret(emailSubjectId, vEmailSubject);
94
97
  yield iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
95
- yield iexec.secrets.pushRequesterSecret(optionsId, JSON.stringify({ contentType: vContentType }));
98
+ yield iexec.secrets.pushRequesterSecret(optionsId, JSON.stringify({ contentType: vContentType, senderName: vSenderName }));
96
99
  // Create and sign request order
97
100
  const requestorderToSign = yield iexec.order.createRequestorder({
98
101
  app: WEB3_MAIL_DAPP_ADDRESS,
@@ -16,6 +16,7 @@ export type SendEmailParams = {
16
16
  emailContent: string;
17
17
  protectedData: Address;
18
18
  contentType?: string;
19
+ senderName?: string;
19
20
  };
20
21
  export type SendEmailResponse = {
21
22
  taskId: Address;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@iexec/web3mail",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
5
- "main": "./dist/bundle.js",
5
+ "main": "./dist/index.js",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "node": "./dist/index.js",
12
- "default": "./dist/bundle.js"
12
+ "default": "./dist/index.js"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -18,8 +18,7 @@
18
18
  "dist"
19
19
  ],
20
20
  "scripts": {
21
- "build": "rm -rf dist && tsc && webpack",
22
- "start": "node dist/bundle.js",
21
+ "build": "rm -rf dist && tsc",
23
22
  "test": "rm -rf dist && tsc && NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
24
23
  "lint": "eslint . --ext .ts",
25
24
  "format": "prettier --write \"src/**/*.ts\"",
@@ -42,9 +41,6 @@
42
41
  "@iexec/dataprotector": "^0.1.0",
43
42
  "@types/jest": "^29.5.1",
44
43
  "@typescript-eslint/eslint-plugin": "^5.54.0",
45
- "assert": "^2.0.0",
46
- "constants-browserify": "^1.0.0",
47
- "crypto-browserify": "^3.12.0",
48
44
  "eslint": "^8.35.0",
49
45
  "eslint-config-prettier": "^8.6.0",
50
46
  "eslint-config-standard-with-typescript": "^34.0.0",
@@ -53,15 +49,15 @@
53
49
  "eslint-plugin-promise": "^6.1.1",
54
50
  "jest": "^29.5.0",
55
51
  "prettier": "^2.8.4",
56
- "stream-browserify": "^3.0.0",
57
52
  "ts-jest": "^29.1.0",
58
53
  "ts-loader": "^9.4.2",
59
- "typescript": "^4.9.5",
60
- "webpack-cli": "^5.0.1"
54
+ "typescript": "^4.9.5"
61
55
  },
62
56
  "dependencies": {
57
+ "@ethersproject/bytes": "^5.7.0",
58
+ "@ethersproject/random": "^5.7.0",
63
59
  "graphql-request": "^6.1.0",
64
- "iexec": "^8.1.5",
60
+ "iexec": "^8.2.1",
65
61
  "yup": "^1.1.1"
66
62
  }
67
63
  }
@@ -1,6 +1,6 @@
1
- import crypto from 'crypto';
1
+ import { randomBytes } from '@ethersproject/random';
2
+ import { hexlify } from '@ethersproject/bytes';
2
3
 
3
- export function generateSecureUniqueId(length: number): string {
4
- const buffer = crypto.randomBytes(length);
5
- return buffer.toString('hex');
4
+ export function generateSecureUniqueId(length) {
5
+ return hexlify(randomBytes(length));
6
6
  }
@@ -31,3 +31,6 @@ const validContentTypes = ['text/plain', 'text/html'];
31
31
 
32
32
  export const contentTypeSchema = () =>
33
33
  string().oneOf(validContentTypes, 'Invalid contentType').optional();
34
+
35
+ // Minimum of 3 characters and max of 20 to avoid sender being flagged as spam
36
+ export const senderNameSchema = () => string().trim().min(3).max(20).optional();
@@ -13,6 +13,7 @@ import {
13
13
  contentTypeSchema,
14
14
  emailContentSchema,
15
15
  emailSubjectSchema,
16
+ senderNameSchema,
16
17
  throwIfMissing,
17
18
  } from '../utils/validators.js';
18
19
  import {
@@ -28,6 +29,7 @@ export const sendEmail = async ({
28
29
  emailSubject,
29
30
  emailContent,
30
31
  contentType = DEFAULT_CONTENT_TYPE,
32
+ senderName,
31
33
  protectedData,
32
34
  }: IExecConsumer &
33
35
  SubgraphConsumer &
@@ -45,11 +47,13 @@ export const sendEmail = async ({
45
47
  .required()
46
48
  .label('emailContent')
47
49
  .validateSync(emailContent);
48
-
49
50
  const vContentType = contentTypeSchema()
50
51
  .required()
51
52
  .label('contentType')
52
53
  .validateSync(contentType);
54
+ const vSenderName = senderNameSchema()
55
+ .label('senderName')
56
+ .validateSync(senderName);
53
57
 
54
58
  // Check protected data validity through subgraph
55
59
  const isValidProtectedData = await checkProtectedDataValidity(
@@ -141,7 +145,7 @@ export const sendEmail = async ({
141
145
  await iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
142
146
  await iexec.secrets.pushRequesterSecret(
143
147
  optionsId,
144
- JSON.stringify({ contentType: vContentType })
148
+ JSON.stringify({ contentType: vContentType, senderName: vSenderName })
145
149
  );
146
150
  // Create and sign request order
147
151
  const requestorderToSign = await iexec.order.createRequestorder({
@@ -21,6 +21,7 @@ export type SendEmailParams = {
21
21
  emailContent: string;
22
22
  protectedData: Address;
23
23
  contentType?: string;
24
+ senderName?: string;
24
25
  };
25
26
 
26
27
  export type SendEmailResponse = {