@notifiles/sdk 1.1.1 → 1.1.2

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.1",
4
+ "version": "1.1.2",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -2,4 +2,5 @@ export { default as isValid } from './isValid.js'
2
2
  export { default as upload } from './upload.js'
3
3
  export { default as syncFolder } from './syncFolder.js'
4
4
  export { default as remove } from './remove.js'
5
+ export { default as previewRemoteUrl } from './previewRemoteUrl.js'
5
6
  // export { default as uploadFolder } from './uploadFolder.js'
@@ -0,0 +1,20 @@
1
+ export default async ({
2
+ filename,
3
+ auth,
4
+ // contentType = 'image/png'
5
+ }) => {
6
+
7
+ try {
8
+ const {
9
+ endPoint,
10
+ bucketName
11
+ } = auth
12
+
13
+ const url = `https://${endPoint}/${bucketName}/${filename}`
14
+ return { url }
15
+
16
+ } catch (e) {
17
+ console.error(e)
18
+ }
19
+ return null
20
+ }
@@ -16,27 +16,28 @@ export default async ({ child,
16
16
  src: _url,
17
17
  } } = child
18
18
 
19
-
19
+ //#region CACHE
20
20
  let _activity = await getActivity({ path })
21
- if (!settings.forceUploadAssets) {
22
- const codeActivity = _activity[entry.code]
23
- if (codeActivity) {
24
- const files = codeActivity.files
25
- if (files && files[_url]) {
26
- const cache = files[_url]
27
- return {
28
- ...child,
29
- properties: {
30
- ...child.properties,
31
- src: cache.url
32
- }
33
- }
34
- }
35
- }
36
- }
21
+ // if (!settings.forceUploadAssets) {
22
+ // const codeActivity = _activity[entry.code]
23
+ // if (codeActivity) {
24
+ // const files = codeActivity.files
25
+ // if (files && files[_url]) {
26
+ // const cache = files[_url]
27
+ // return {
28
+ // ...child,
29
+ // properties: {
30
+ // ...child.properties,
31
+ // src: cache.url
32
+ // }
33
+ // }
34
+ // }
35
+ // }
36
+ // }
37
+ //#endregion
37
38
 
38
39
  let result
39
- const destination = `${path}/.assets`
40
+ const destination = buildPaths.email.assetsContainer
40
41
  if (isLocal(_url)) {
41
42
  result = await treatLocalFile({ url: _url, path, destination })
42
43
  }
@@ -53,7 +54,7 @@ export default async ({ child,
53
54
  uploadResult = await upload({
54
55
  id: cloud.id,
55
56
  sourceUrl,
56
- filename: `${buildPaths.email.assetsContainer}/${filename}`,
57
+ filename: `${buildPaths.email.assetsContainerRemote}/${filename}`,
57
58
  auth: cloud.auth,
58
59
  settings
59
60
  })
@@ -14,9 +14,7 @@ export default async (props) => {
14
14
  buildPaths
15
15
  })
16
16
 
17
- // let md = await mdastToMarkdown({ mdast })
18
17
  let body = hastToHtml({ data: _hast })
19
- // await fs.promises.writeFile(`${path}/.build/html/email.cloud.html`, html)
20
18
 
21
19
  await fs.promises.writeFile(
22
20
  buildPaths.email.body,
@@ -7,12 +7,11 @@ export default async (props) => {
7
7
  const { entry } = props
8
8
  const { path, email: { hast }, buildPaths } = entry
9
9
 
10
- const destination = `${path}/.assets`
11
- await ensureDirectoryExists(destination, false)
12
10
 
13
11
  const _hast = await perform({
14
12
  child: hast,
15
13
  path,
14
+ buildPaths
16
15
 
17
16
  })
18
17
 
@@ -36,7 +35,7 @@ export default async (props) => {
36
35
  }
37
36
 
38
37
  const perform = async (props) => {
39
- const { child, path } = props
38
+ const { child, path, buildPaths } = props
40
39
  let _child = { ...child }
41
40
 
42
41
  if (child.properties && child.properties.dataNotifilesDoNotConsolidate) {
@@ -47,7 +46,8 @@ const perform = async (props) => {
47
46
  case 'img': {
48
47
  _child = await treatImage({
49
48
  child: _child,
50
- path
49
+ path,
50
+ buildPaths
51
51
  })
52
52
  } break
53
53
  default:
@@ -1,15 +1,17 @@
1
1
  import isLocal from 'is-local'
2
2
  import treatLocalFile from './treatLocalFile.js'
3
3
  import treatRemoteFile from './treatRemoteFile.js'
4
+ import ensureDirectoryExists from '../../../../lib/fs/ensureDirectoryExists.js'
4
5
 
5
6
  export default async ({ child,
6
- path, entry }) => {
7
+ path, buildPaths }) => {
7
8
  const { properties: {
8
9
  src: url,
9
10
  } } = child
10
11
 
11
12
  let result
12
- const destination = `${path}/.assets`
13
+ const destination = buildPaths.email.assetsContainer
14
+ await ensureDirectoryExists(destination)
13
15
 
14
16
  if (isLocal(url)) {
15
17
  if (url.indexOf(destination) !== 0) {
@@ -23,7 +25,8 @@ export default async ({ child,
23
25
  }
24
26
 
25
27
  let filename = result.filename
26
- const newUrl = `.assets/${filename}`
28
+ // const newUrl = `.assets/${filename}`
29
+ const newUrl = result.path
27
30
  return {
28
31
  ...child,
29
32
  properties: {
@@ -10,5 +10,6 @@ export default async ({
10
10
  await fs.promises.cp(sourceUrl, _destination)
11
11
  return {
12
12
  filename,
13
+ path: _destination
13
14
  }
14
15
  }
@@ -16,7 +16,8 @@ export default async ({ url,
16
16
  const filename = fsPath.basename(item.filename)
17
17
 
18
18
  return {
19
- filename
19
+ filename,
20
+ path: `${destination}/${filename}`
20
21
  }
21
22
  }
22
23
  catch (e) {
@@ -29,7 +29,8 @@ export default async ({
29
29
  textFileName: `${entry.slug}/email/${code}/text.txt`,
30
30
  subject: `${path}/.build/email/${code}/subject.txt`,
31
31
  subjectFileName: `${entry.slug}/email/${code}/subject.txt`,
32
- assetsContainer: `${entry.slug}/email/${code}/assets`,
32
+ assetsContainer: `${path}/.build/email/${code}/assets`,
33
+ assetsContainerRemote: `${entry.slug}/email/${code}/assets`,
33
34
  attachmentsContainer: `${entry.slug}/email/${code}/attachments`,
34
35
  manifestFileNameBuilt: `${path}/.build/email/${code}/manifest.json`,
35
36
  manifestFileName: `${entry.slug}/email/${code}/manifest.json`,
@@ -39,7 +40,8 @@ export default async ({
39
40
  containerRemote: `${entry.slug}/textmessage/${code}`,
40
41
  text: `${path}/.build/textmessage/${code}/textmessage.txt`,
41
42
  textFileName: `${entry.slug}/textmessage/${code}/textmessage.txt`,
42
- assetsContainer: `${entry.slug}/textmessage/${code}/assets`,
43
+ assetsContainer: `${path}/.build/textmessage/${code}/assets`,
44
+ assetsContainerRemote: `${entry.slug}/textmessage/${code}/assets`,
43
45
  manifestFileNameBuilt: `${path}/.build/textmessage/${code}/manifest.json`,
44
46
  manifestFileName: `${entry.slug}/textmessage/${code}/manifest.json`,
45
47
  },
@@ -48,7 +50,8 @@ export default async ({
48
50
  containerRemote: `${entry.slug}/pushnotification/${code}`,
49
51
  text: `${path}/.build/pushnotification/${code}/pushnotification.txt`,
50
52
  textFileName: `${entry.slug}/pushnotification/${code}/pushnotification.txt`,
51
- assetsContainer: `${entry.slug}/pushnotification/${code}/assets`,
53
+ assetsContainer: `${path}/.build/pushnotification/${code}/assets`,
54
+ assetsContainerRemote: `${entry.slug}/pushnotification/${code}/assets`,
52
55
  manifestFileNameBuilt: `${path}/.build/pushnotification/${code}/manifest.json`,
53
56
  manifestFileName: `${entry.slug}/pushnotification/${code}/manifest.json`,
54
57
  },
@@ -8,7 +8,8 @@ export default async (props) => {
8
8
 
9
9
  let _hast = await perform({
10
10
  child: hast,
11
- path
11
+ path,
12
+ buildPaths
12
13
  })
13
14
 
14
15
  let body = hastToHtml({ data: _hast })
@@ -31,7 +32,7 @@ export default async (props) => {
31
32
  }
32
33
 
33
34
  const perform = async (props) => {
34
- const { child, path } = props
35
+ const { child, path, buildPaths } = props
35
36
  let _child = { ...child }
36
37
 
37
38
  if (child.properties && _child.properties.dataNotifilesDoNotOptimize) {
@@ -42,7 +43,8 @@ const perform = async (props) => {
42
43
  case 'img': {
43
44
  _child = await treatImage({
44
45
  child: _child,
45
- path
46
+ path,
47
+ buildPaths
46
48
  })
47
49
  } break
48
50
  default:
@@ -2,9 +2,10 @@ import fsPath from 'path'
2
2
  import isLocal from 'is-local'
3
3
  import isRelative from 'is-relative'
4
4
  import sharp from 'sharp'
5
+ import fs from 'fs'
5
6
 
6
7
  export default async ({ child,
7
- path, }) => {
8
+ path, buildPaths }) => {
8
9
  const { properties: {
9
10
  src: url,
10
11
  } } = child
@@ -22,14 +23,17 @@ export default async ({ child,
22
23
  default: break
23
24
  }
24
25
 
25
- const filename = `_${fsPath.parse(sourceUrl).name}.webp`
26
- const destination = `${path}/.assets/${filename}`
26
+ const filename = `${fsPath.parse(sourceUrl).name}_optimized.webp`
27
+ const destination = `${buildPaths.email.assetsContainer}/${filename}`
27
28
 
28
29
  await sharp(sourceUrl)
29
30
  .webp({ quality: 90 })
30
31
  .toFile(destination)
31
32
 
32
- const newUrl = `.assets/${filename}`
33
+ await fs.promises.rm(sourceUrl)
34
+
35
+ // const newUrl = `assets/${filename}`
36
+ const newUrl = destination
33
37
  return {
34
38
  ...child,
35
39
  properties: {