@notifiles/sdk 1.1.16 → 1.1.18

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.16",
4
+ "version": "1.1.18",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -50,6 +50,7 @@
50
50
  },
51
51
  "keywords": [],
52
52
  "dependencies": {
53
+ "@lifeomic/attempt": "^3.1.0",
53
54
  "@microflash/remark-figure-caption": "^2.0.2",
54
55
  "@stdlib/string-replace": "^0.2.1",
55
56
  "axios": "^1.6.1",
@@ -83,6 +84,7 @@
83
84
  "minio": "^7.1.4",
84
85
  "nanoid": "^5.0.7",
85
86
  "node-bunny-storage": "^2.2.0",
87
+ "p-retry": "^6.2.1",
86
88
  "patch-package": "^8.0.0",
87
89
  "rehype-parse": "^9.0.0",
88
90
  "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
  )
@@ -3,114 +3,141 @@ 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 { retry } from '@lifeomic/attempt';
7
7
 
8
8
  export default async (props) => {
9
-
10
9
  const { entry } = props
11
- const { path,
10
+ const {
11
+ path,
12
12
  buildPaths,
13
13
  code,
14
- language } = entry
14
+ language
15
+ } = entry
15
16
 
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
+ // })
16
24
 
17
- // const a = await fs.promises.readFile(`${path}/email.react-email.tsx`, 'utf8')
18
- // // const a = (await import(`${path}/email.react-email.tsx`))
19
- // const component = React.createElement()
20
- // const html_ = await renderAsync(a, {
21
- // pretty: true,
22
- // })
23
25
 
24
-
25
- const { stdout } = await execa`npx react-email@2.1.4 export
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
- const { stdoutB } = await execa`npx react-email@2.1.4 export
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
- await fs.promises.cp(
38
- `${path}/.build/temp/email/${code}/html/email.html`,
39
- buildPaths.email.body
40
- )
41
-
42
- let body = await fs.promises.readFile(buildPaths.email.body, 'utf8')
43
- body = translate({ text: body, strings: language.data })
44
- body = body
45
- .replaceAll('|%', '{{')
46
- .replaceAll('%|', '}}')
47
- .replaceAll(']]', '')
48
- .replaceAll('[[', '')
49
-
50
- await fs.promises.writeFile(
51
- buildPaths.email.body,
52
- body
53
- )
54
-
55
- await fs.promises.cp(
56
- `${path}/.build/temp/email/${code}/text/email.txt`,
57
- buildPaths.email.text
58
- )
59
-
60
- let text = await fs.promises.readFile(buildPaths.email.text, 'utf8')
61
- text = translate({ text: text, strings: language.data })
62
- text = text
63
- .replaceAll('|%', '{{')
64
- .replaceAll('%|', '}}')
65
- .replaceAll(']]', '')
66
- .replaceAll('[[', '')
67
-
68
- await fs.promises.writeFile(
69
- buildPaths.email.text,
70
- text
71
- )
72
-
73
- await fs.promises.cp(
74
- `${path}/email.subject.txt`,
75
- buildPaths.email.subject
76
- )
77
-
78
- let subject = await fs.promises.readFile(buildPaths.email.subject, 'utf8')
79
- subject = translate({ text: subject, strings: language.data })
80
- subject = subject
81
- .trim()
82
- .replaceAll('|%', '{{')
83
- .replaceAll('%|', '}}')
84
- .replaceAll(']]', '')
85
- .replaceAll('[[', '')
86
-
87
- await fs.promises.writeFile(
88
- buildPaths.email.subject,
89
- subject,
90
- 'utf-8'
91
- )
92
-
93
- await fs.promises.cp(
94
- `${path}/manifest.json`,
95
- buildPaths.manifestFileNameBuilt
96
- )
97
-
98
- const child = htmlToHast({ data: body })
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,
112
- }
113
- },
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
+
94
+ try {
95
+ await retry(async (context) => {
96
+ await fs.promises.cp(
97
+ `${path}/manifest.json`,
98
+ buildPaths.manifestFileNameBuilt
99
+ )
100
+ return true
101
+ }, {
102
+ delay: 200,
103
+ maxAttempts: 3,
104
+ initialDelay: 0,
105
+ minDelay: 0,
106
+ maxDelay: 0,
107
+ factor: 0,
108
+ timeout: 0,
109
+ jitter: false,
110
+ initialJitter: false,
111
+ handleError: null,
112
+ handleTimeout: null,
113
+ beforeAttempt: null,
114
+ calculateDelay: null
115
+ });
116
+ } catch (err) {
117
+ console.log(`Attempt ${err} failed`);
118
+ }
119
+
120
+ const child = htmlToHast({ data: body })
121
+ const hast = await perform({
122
+ child,
123
+ path
124
+ })
125
+
126
+ return {
127
+ entry: {
128
+ ...entry,
129
+ email: {
130
+ text,
131
+ body,
132
+ subject,
133
+ hast,
134
+ }
135
+ },
136
+ }
137
+ }
138
+ catch (e) {
139
+ console.error(e)
140
+ return null
114
141
  }
115
142
  }
116
143
 
@@ -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)
@@ -13,15 +13,16 @@ export default async ({
13
13
  settings
14
14
  }) => {
15
15
  adaptSettings({ settings })
16
- const entries = await getEntries({
16
+ let entries = await getEntries({
17
17
  path,
18
18
  settings
19
19
  })
20
20
 
21
- await Promise.all(entries.map(async entry => {
21
+ for (var i in entries) {
22
+ let entry = entries[i]
22
23
  switch (entry.manifest.status) {
23
24
  case 'pause': {
24
- return
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
- return
37
+ continue
37
38
  }
38
39
  entry = (await sync({ entry, settings })).entry
39
- }))
40
+ }
40
41
 
41
42
  return true
42
43
  }