@notifiles/sdk 1.1.16 → 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.
|
|
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",
|
|
@@ -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.
|
|
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.
|
|
27
|
+
await fs.promises.rm(
|
|
28
28
|
`${entry.path}/.build/temp`,
|
|
29
29
|
{ recursive: true }
|
|
30
30
|
)
|
|
@@ -3,114 +3,136 @@ import fs from 'fs';
|
|
|
3
3
|
import translate from './translate.js';
|
|
4
4
|
import htmlToHast from '../../../../lib/remark/htmlToHast.js';
|
|
5
5
|
//#TODO: https://github.com/anfragment/react-email-dynamic
|
|
6
|
-
|
|
6
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
7
7
|
|
|
8
8
|
export default async (props) => {
|
|
9
|
-
|
|
10
9
|
const { entry } = props
|
|
11
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
path,
|
|
12
12
|
buildPaths,
|
|
13
13
|
code,
|
|
14
|
-
language
|
|
15
|
-
|
|
14
|
+
language
|
|
15
|
+
} = entry
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
// })
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
const { stdout } = await execa`npx react-email@2.1.4 export
|
|
26
27
|
--pretty
|
|
27
28
|
--plainText
|
|
28
29
|
--dir ${path}
|
|
29
30
|
--outDir ${path}/.build/temp/email/${code}/text`
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
const { stdoutB } = await execa`npx react-email@2.1.4 export
|
|
32
33
|
--pretty
|
|
33
34
|
--dir ${path}
|
|
34
35
|
--outDir ${path}/.build/temp/email/${code}/html`
|
|
35
36
|
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const hast = await perform({
|
|
100
|
-
child,
|
|
101
|
-
path
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
entry: {
|
|
106
|
-
...entry,
|
|
107
|
-
email: {
|
|
108
|
-
text,
|
|
109
|
-
body,
|
|
110
|
-
subject,
|
|
111
|
-
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
|
|
112
100
|
}
|
|
113
|
-
|
|
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
|
|
114
136
|
}
|
|
115
137
|
}
|
|
116
138
|
|
|
@@ -13,15 +13,16 @@ export default async ({
|
|
|
13
13
|
settings
|
|
14
14
|
}) => {
|
|
15
15
|
adaptSettings({ settings })
|
|
16
|
-
|
|
16
|
+
let entries = await getEntries({
|
|
17
17
|
path,
|
|
18
18
|
settings
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
for (var i in entries) {
|
|
22
|
+
let entry = entries[i]
|
|
22
23
|
switch (entry.manifest.status) {
|
|
23
24
|
case 'pause': {
|
|
24
|
-
|
|
25
|
+
continue
|
|
25
26
|
}
|
|
26
27
|
default: break
|
|
27
28
|
}
|
|
@@ -33,10 +34,10 @@ export default async ({
|
|
|
33
34
|
entry = (await cloudify({ entry, settings })).entry
|
|
34
35
|
entry = (await attach({ entry, settings })).entry
|
|
35
36
|
if (settings.dryRun) {
|
|
36
|
-
|
|
37
|
+
continue
|
|
37
38
|
}
|
|
38
39
|
entry = (await sync({ entry, settings })).entry
|
|
39
|
-
}
|
|
40
|
+
}
|
|
40
41
|
|
|
41
42
|
return true
|
|
42
43
|
}
|