@notifiles/sdk 1.1.15 → 1.1.17

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notifiles/sdk",
3
3
  "type": "module",
4
- "version": "1.1.15",
4
+ "version": "1.1.17",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -83,6 +83,7 @@
83
83
  "minio": "^7.1.4",
84
84
  "nanoid": "^5.0.7",
85
85
  "node-bunny-storage": "^2.2.0",
86
+ "p-retry": "^6.2.1",
86
87
  "patch-package": "^8.0.0",
87
88
  "rehype-parse": "^9.0.0",
88
89
  "rehype-remark": "^10.0.0",
@@ -100,7 +100,7 @@ const perform = async (props) => {
100
100
  return results
101
101
  }
102
102
  catch (e) {
103
- console.error(e)
103
+ console.error(path, e)
104
104
  return null
105
105
  }
106
106
  }
@@ -10,7 +10,7 @@ export default async ({
10
10
  }) => {
11
11
  const buildPath = `${entry.path}/.build`
12
12
  if ((await checkFileExists(buildPath))) {
13
- await fs.promises.rmdir(
13
+ await fs.promises.rm(
14
14
  buildPath,
15
15
  { recursive: true }
16
16
  )
@@ -24,7 +24,7 @@ export default async ({
24
24
  }))
25
25
 
26
26
  if ((await checkFileExists(`${entry.path}/.build/temp`))) {
27
- await fs.promises.rmdir(
27
+ await fs.promises.rm(
28
28
  `${entry.path}/.build/temp`,
29
29
  { recursive: true }
30
30
  )
@@ -2,113 +2,137 @@ import { execa } from 'execa';
2
2
  import fs from 'fs';
3
3
  import translate from './translate.js';
4
4
  import htmlToHast from '../../../../lib/remark/htmlToHast.js';
5
+ //#TODO: https://github.com/anfragment/react-email-dynamic
6
+ import pRetry, { AbortError } from 'p-retry';
5
7
 
6
8
  export default async (props) => {
7
-
8
9
  const { entry } = props
9
- const { path,
10
+ const {
11
+ path,
10
12
  buildPaths,
11
13
  code,
12
- language } = entry
13
-
14
+ language
15
+ } = entry
14
16
 
15
- // const a = await fs.promises.readFile(`${path}/email.react-email.tsx`, 'utf8')
16
- // // const a = (await import(`${path}/email.react-email.tsx`))
17
- // const component = React.createElement()
18
- // const html_ = await renderAsync(a, {
19
- // pretty: true,
20
- // })
17
+ try {
18
+ // const a = await fs.promises.readFile(`${path}/email.react-email.tsx`, 'utf8')
19
+ // // const a = (await import(`${path}/email.react-email.tsx`))
20
+ // const component = React.createElement()
21
+ // const html_ = await renderAsync(a, {
22
+ // pretty: true,
23
+ // })
21
24
 
22
25
 
23
- const { stdout } = await execa`npx react-email@2.1.4 export
26
+ const { stdout } = await execa`npx react-email@2.1.4 export
24
27
  --pretty
25
28
  --plainText
26
29
  --dir ${path}
27
30
  --outDir ${path}/.build/temp/email/${code}/text`
28
31
 
29
- const { stdoutB } = await execa`npx react-email@2.1.4 export
32
+ const { stdoutB } = await execa`npx react-email@2.1.4 export
30
33
  --pretty
31
34
  --dir ${path}
32
35
  --outDir ${path}/.build/temp/email/${code}/html`
33
36
 
34
37
 
35
- await fs.promises.cp(
36
- `${path}/.build/temp/email/${code}/html/email.html`,
37
- buildPaths.email.body
38
- )
39
-
40
- let body = await fs.promises.readFile(buildPaths.email.body, 'utf8')
41
- body = translate({ text: body, strings: language.data })
42
- body = body
43
- .replaceAll('|%', '{{')
44
- .replaceAll('%|', '}}')
45
- .replaceAll(']]', '')
46
- .replaceAll('[[', '')
47
-
48
- await fs.promises.writeFile(
49
- buildPaths.email.body,
50
- body
51
- )
52
-
53
- await fs.promises.cp(
54
- `${path}/.build/temp/email/${code}/text/email.txt`,
55
- buildPaths.email.text
56
- )
57
-
58
- let text = await fs.promises.readFile(buildPaths.email.text, 'utf8')
59
- text = translate({ text: text, strings: language.data })
60
- text = text
61
- .replaceAll('|%', '{{')
62
- .replaceAll('%|', '}}')
63
- .replaceAll(']]', '')
64
- .replaceAll('[[', '')
65
-
66
- await fs.promises.writeFile(
67
- buildPaths.email.text,
68
- text
69
- )
70
-
71
- await fs.promises.cp(
72
- `${path}/email.subject.txt`,
73
- buildPaths.email.subject
74
- )
75
-
76
- let subject = await fs.promises.readFile(buildPaths.email.subject, 'utf8')
77
- subject = translate({ text: subject, strings: language.data })
78
- subject = subject
79
- .trim()
80
- .replaceAll('|%', '{{')
81
- .replaceAll('%|', '}}')
82
- .replaceAll(']]', '')
83
- .replaceAll('[[', '')
84
-
85
- await fs.promises.writeFile(
86
- buildPaths.email.subject,
87
- subject,
88
- 'utf-8'
89
- )
90
-
91
- await fs.promises.cp(
92
- `${path}/manifest.json`,
93
- buildPaths.manifestFileNameBuilt
94
- )
95
-
96
- const child = htmlToHast({ data: body })
97
- const hast = await perform({
98
- child,
99
- path
100
- })
101
-
102
- return {
103
- entry: {
104
- ...entry,
105
- email: {
106
- text,
107
- body,
108
- subject,
109
- hast,
38
+ await fs.promises.cp(
39
+ `${path}/.build/temp/email/${code}/html/email.html`,
40
+ buildPaths.email.body
41
+ )
42
+
43
+ let body = await fs.promises.readFile(buildPaths.email.body, 'utf8')
44
+ body = translate({ text: body, strings: language.data })
45
+ body = body
46
+ .replaceAll('|%', '{{')
47
+ .replaceAll('%|', '}}')
48
+ .replaceAll(']]', '')
49
+ .replaceAll('[[', '')
50
+
51
+ await fs.promises.writeFile(
52
+ buildPaths.email.body,
53
+ body
54
+ )
55
+
56
+ await fs.promises.cp(
57
+ `${path}/.build/temp/email/${code}/text/email.txt`,
58
+ buildPaths.email.text
59
+ )
60
+
61
+ let text = await fs.promises.readFile(buildPaths.email.text, 'utf8')
62
+ text = translate({ text: text, strings: language.data })
63
+ text = text
64
+ .replaceAll('|%', '{{')
65
+ .replaceAll('%|', '}}')
66
+ .replaceAll(']]', '')
67
+ .replaceAll('[[', '')
68
+
69
+ await fs.promises.writeFile(
70
+ buildPaths.email.text,
71
+ text
72
+ )
73
+
74
+ await fs.promises.cp(
75
+ `${path}/email.subject.txt`,
76
+ buildPaths.email.subject
77
+ )
78
+
79
+ let subject = await fs.promises.readFile(buildPaths.email.subject, 'utf8')
80
+ subject = translate({ text: subject, strings: language.data })
81
+ subject = subject
82
+ .trim()
83
+ .replaceAll('|%', '{{')
84
+ .replaceAll('%|', '}}')
85
+ .replaceAll(']]', '')
86
+ .replaceAll('[[', '')
87
+
88
+ await fs.promises.writeFile(
89
+ buildPaths.email.subject,
90
+ subject,
91
+ 'utf-8'
92
+ )
93
+ const run = async () => {
94
+ try {
95
+ await fs.promises.cp(
96
+ `${path}/manifest.json`,
97
+ buildPaths.manifestFileNameBuilt
98
+ )
99
+ return true
110
100
  }
111
- },
101
+ catch (e) {
102
+ throw new AbortError(e.message);
103
+ }
104
+ }
105
+ pRetry(run, {
106
+ retries: 15,
107
+ onFailedAttempt: error => {
108
+ console.log(`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`);
109
+ // 1st request => Attempt 1 failed. There are 4 retries left.
110
+ // 2nd request => Attempt 2 failed. There are 3 retries left.
111
+ // …
112
+ },
113
+ })
114
+
115
+ const child = htmlToHast({ data: body })
116
+ const hast = await perform({
117
+ child,
118
+ path
119
+ })
120
+
121
+ return {
122
+ entry: {
123
+ ...entry,
124
+ email: {
125
+ text,
126
+ body,
127
+ subject,
128
+ hast,
129
+ }
130
+ },
131
+ }
132
+ }
133
+ catch (e) {
134
+ console.error(e)
135
+ return null
112
136
  }
113
137
  }
114
138
 
@@ -26,7 +26,7 @@ export default async ({
26
26
  if (!force) {
27
27
  return false
28
28
  }
29
- await fs.promises.rmdir(folderPath, { recursive: true })
29
+ await fs.promises.rm(folderPath, { recursive: true })
30
30
  }
31
31
 
32
32
  await fs.promises.mkdir(folderPath)