@notifiles/sdk 1.0.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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/index.modern.cjs +856 -0
  4. package/dist/index.modern.cjs.map +1 -0
  5. package/dist/index.modern.modern.js +690 -0
  6. package/dist/index.modern.modern.js.map +1 -0
  7. package/package.json +152 -0
  8. package/src/cloud/add/index.js +38 -0
  9. package/src/cloud/add/index.test.js +38 -0
  10. package/src/cloud/add/lib/validate.js +16 -0
  11. package/src/cloud/index.js +3 -0
  12. package/src/cloud/list/index.js +18 -0
  13. package/src/cloud/list/index.test.js +13 -0
  14. package/src/email/build copy/lib/perform/email.js +52 -0
  15. package/src/index.js +3 -0
  16. package/src/lib/adaptSettings.js +12 -0
  17. package/src/lib/cloudLibrary/bunny/index.js +2 -0
  18. package/src/lib/cloudLibrary/bunny/isValid.js +32 -0
  19. package/src/lib/cloudLibrary/bunny/upload.js +35 -0
  20. package/src/lib/cloudLibrary/index.js +20 -0
  21. package/src/lib/cloudLibrary/minio/index.js +4 -0
  22. package/src/lib/cloudLibrary/minio/isValid.js +33 -0
  23. package/src/lib/cloudLibrary/minio/remove.js +58 -0
  24. package/src/lib/cloudLibrary/minio/upload.js +61 -0
  25. package/src/lib/cloudLibrary/minio/uploadFolder.js +26 -0
  26. package/src/lib/entries/getAtPath.js +105 -0
  27. package/src/lib/entries/isPathEntry.js +29 -0
  28. package/src/lib/entries.js +144 -0
  29. package/src/lib/fs/checkFileExists.js +6 -0
  30. package/src/lib/fs/directoryFilesRecursive.js +83 -0
  31. package/src/lib/fs/ensureDirectoryExists.js +10 -0
  32. package/src/lib/fs/getFileCallerURL.js +12 -0
  33. package/src/lib/fs/importFileAsText.js +15 -0
  34. package/src/lib/fs/importJSONAsync.js +16 -0
  35. package/src/lib/fs/importYAMLAsync.js +14 -0
  36. package/src/lib/remark/hastToHtml.js +6 -0
  37. package/src/lib/remark/htmlToHast.js +6 -0
  38. package/src/lib/remark/htmlToMarkdown copy.js +12 -0
  39. package/src/lib/remark/htmlToMarkdown.js +23 -0
  40. package/src/lib/remark/htmlToMdast.js +13 -0
  41. package/src/lib/remark/htmlToMdast_.js +21 -0
  42. package/src/lib/remark/htmlToMdast_3.js +21 -0
  43. package/src/lib/remark/markdownToHTML.js +22 -0
  44. package/src/lib/remark/markdownToLexer.js +19 -0
  45. package/src/lib/remark/mdastToHTML.js +8 -0
  46. package/src/lib/remark/mdastToMarkdown.js +24 -0
  47. package/src/lib/remark/mdastToString.js +12 -0
  48. package/src/project/index.js +4 -0
  49. package/src/project/isProject/index.js +26 -0
  50. package/src/project/isProject/index.test.js +13 -0
  51. package/src/project/isProject/sync.js +18 -0
  52. package/src/project/lib/activity/createFileIfNeeded.js +33 -0
  53. package/src/project/lib/activity/defaultContent.json +5 -0
  54. package/src/project/lib/activity/updateToFile.js +32 -0
  55. package/src/project/lib/manifest/createFileIfNeeded.js +44 -0
  56. package/src/project/lib/manifest/read.js +21 -0
  57. package/src/project/lib/manifest/update.js +36 -0
  58. package/src/project/lib/manifest/updateToFile.js +22 -0
  59. package/src/project/new/index.js +2 -0
  60. package/src/project/new/plain.js +49 -0
  61. package/src/project/new/plain.test.js +38 -0
  62. package/src/template/build/entry.js +37 -0
  63. package/src/template/build/index.js +2 -0
  64. package/src/template/build/lib/email/index.js +100 -0
  65. package/src/template/build/lib/email/translate.js +16 -0
  66. package/src/template/build/lib/textmessage/index.js +44 -0
  67. package/src/template/build/lib/textmessage/translate.js +25 -0
  68. package/src/template/build/path.js +18 -0
  69. package/src/template/build/path.test.js +29 -0
  70. package/src/template/cloudify/entry.js +20 -0
  71. package/src/template/cloudify/index.js +2 -0
  72. package/src/template/cloudify/lib/email/attachments/addAttachment.js +24 -0
  73. package/src/template/cloudify/lib/email/attachments/index.js +137 -0
  74. package/src/template/cloudify/lib/email/attachments/treatLocalFile.js +13 -0
  75. package/src/template/cloudify/lib/email/attachments/treatRemoteFile.js +26 -0
  76. package/src/template/cloudify/lib/email/image/index.js +90 -0
  77. package/src/template/cloudify/lib/email/image/treatLocalFile.js +13 -0
  78. package/src/template/cloudify/lib/email/image/treatRemoteFile.js +26 -0
  79. package/src/template/cloudify/lib/email/index.js +77 -0
  80. package/src/template/cloudify/lib/remove.js +14 -0
  81. package/src/template/cloudify/lib/textMessage.js +9 -0
  82. package/src/template/cloudify/lib/upload.js +14 -0
  83. package/src/template/cloudify/path.js +20 -0
  84. package/src/template/cloudify/path.test.js +24 -0
  85. package/src/template/consolidate/entry.js +18 -0
  86. package/src/template/consolidate/index.js +2 -0
  87. package/src/template/consolidate/lib/email.js +63 -0
  88. package/src/template/consolidate/lib/image/index.js +35 -0
  89. package/src/template/consolidate/lib/image/treatLocalFile.js +14 -0
  90. package/src/template/consolidate/lib/image/treatRemoteFile.js +25 -0
  91. package/src/template/consolidate/lib/textMessage.js +5 -0
  92. package/src/template/consolidate/path.js +18 -0
  93. package/src/template/consolidate/path.test.js +14 -0
  94. package/src/template/format/entry.js +57 -0
  95. package/src/template/format/index.js +2 -0
  96. package/src/template/format/path.js +18 -0
  97. package/src/template/format/path.test.js +29 -0
  98. package/src/template/index.js +8 -0
  99. package/src/template/lib/activity/createFileIfNeeded.js +33 -0
  100. package/src/template/lib/activity/defaultContent.json +4 -0
  101. package/src/template/lib/activity/get.js +20 -0
  102. package/src/template/lib/activity/updateToFile.js +33 -0
  103. package/src/template/lib/manifest/createFileIfNeeded.js +41 -0
  104. package/src/template/lib/manifest/read.js +22 -0
  105. package/src/template/lib/manifest/update.js +18 -0
  106. package/src/template/lib/manifest/updateToFile.js +22 -0
  107. package/src/template/new/index.js +66 -0
  108. package/src/template/new/index.test.js +19 -0
  109. package/src/template/optimize/entry.js +18 -0
  110. package/src/template/optimize/index.js +2 -0
  111. package/src/template/optimize/lib/email.js +58 -0
  112. package/src/template/optimize/lib/image/index.js +40 -0
  113. package/src/template/optimize/lib/textMessage.js +8 -0
  114. package/src/template/optimize/path.js +18 -0
  115. package/src/template/optimize/path.test.js +16 -0
  116. package/src/template/sync/entry.js +18 -0
  117. package/src/template/sync/index.js +2 -0
  118. package/src/template/sync/lib/email.js +86 -0
  119. package/src/template/sync/lib/textMessage.js +80 -0
  120. package/src/template/sync/lib/upload.js +14 -0
  121. package/src/template/sync/path.js +18 -0
  122. package/src/template/sync/path.test.js +29 -0
  123. package/src/template/update/index.js +1 -0
  124. package/src/template/update/path.js +41 -0
  125. package/src/template/update/path.test.js +46 -0
  126. package/src/template/version/entry.js +10 -0
  127. package/src/template/version/index.js +2 -0
  128. package/src/template/version/lib/perform.js +74 -0
  129. package/src/template/version/lib/reset.js +16 -0
  130. package/src/template/version/lib/updatePost.js +16 -0
  131. package/src/template/version/path.js +20 -0
  132. package/src/template/version/path.test.js +16 -0
@@ -0,0 +1,86 @@
1
+ import upload from './upload.js'
2
+ import fs from 'fs'
3
+ import updateActivity from '../../lib/activity/updateToFile.js'
4
+ import getActivity from '../../lib/activity/get.js'
5
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
6
+
7
+ export default async (props) => {
8
+
9
+ const { entry, settings } = props
10
+ const { path, email, buildPaths, } = entry
11
+ const { body, } = email
12
+
13
+ await fs.promises.writeFile(
14
+ buildPaths.email.body,
15
+ body
16
+ )
17
+
18
+ let manifest = await importJSONAsync(
19
+ buildPaths.manifestFileNameBuilt,
20
+ )
21
+
22
+ let activity = await importJSONAsync(
23
+ buildPaths.activityPath,
24
+ )
25
+
26
+ manifest =
27
+ {
28
+ ...manifest,
29
+ ...activity[entry.code]
30
+ }
31
+
32
+ await fs.promises.writeFile(
33
+ buildPaths.email.manifestFileNameBuilt,
34
+ JSON.stringify(manifest, null, 2)
35
+ )
36
+
37
+ const { clouds } = settings
38
+ let uploadResult = null
39
+ for (var i in clouds) {
40
+ const cloud = clouds[i]
41
+ uploadResult = await upload({
42
+ id: cloud.id,
43
+ sourceUrl: buildPaths.email.body,
44
+ filename: buildPaths.email.bodyFileName,
45
+ auth: cloud.auth,
46
+ settings
47
+ })
48
+ uploadResult = await upload({
49
+ id: cloud.id,
50
+ sourceUrl: buildPaths.email.text,
51
+ filename: buildPaths.email.textFileName,
52
+ auth: cloud.auth,
53
+ settings
54
+ })
55
+ uploadResult = await upload({
56
+ id: cloud.id,
57
+ sourceUrl: buildPaths.email.subject,
58
+ filename: buildPaths.email.subjectFileName,
59
+ auth: cloud.auth,
60
+ settings
61
+ })
62
+ uploadResult = await upload({
63
+ id: cloud.id,
64
+ sourceUrl: buildPaths.email.manifestFileNameBuilt,
65
+ filename: buildPaths.email.manifestFileName,
66
+ auth: cloud.auth,
67
+ settings
68
+ })
69
+ }
70
+
71
+ const _activity = await getActivity({ path })
72
+
73
+ _activity[entry.code] = {
74
+ ...(_activity[entry.code] ? _activity[entry.code] : {}),
75
+ status: "published"
76
+ }
77
+
78
+ await updateActivity({
79
+ path,
80
+ content: _activity,
81
+ })
82
+
83
+ return {
84
+ entry
85
+ }
86
+ }
@@ -0,0 +1,80 @@
1
+ import upload from './upload.js'
2
+ import fs from 'fs'
3
+ import updateActivity from '../../lib/activity/updateToFile.js'
4
+ import getActivity from '../../lib/activity/get.js'
5
+ import importJSONAsync from '../../../lib/fs/importJSONAsync.js'
6
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
7
+
8
+ export default async (props) => {
9
+
10
+ const { entry, settings } = props
11
+ const { path, textMessage, buildPaths, } = entry
12
+ const { text, } = textMessage
13
+
14
+ const textPath = `${path}/textmessage.txt`
15
+ if (!(await checkFileExists(textPath))) {
16
+ return {
17
+ entry
18
+ }
19
+ }
20
+
21
+ await fs.promises.writeFile(
22
+ buildPaths.textMessage.text,
23
+ text
24
+ )
25
+
26
+ let manifest = await importJSONAsync(
27
+ buildPaths.manifestFileNameBuilt,
28
+ )
29
+
30
+ let activity = await importJSONAsync(
31
+ buildPaths.activityPath,
32
+ )
33
+
34
+ manifest =
35
+ {
36
+ ...manifest,
37
+ ...activity[entry.code]
38
+ }
39
+
40
+ await fs.promises.writeFile(
41
+ buildPaths.textMessage.manifestFileNameBuilt,
42
+ JSON.stringify(manifest, null, 2)
43
+ )
44
+
45
+ const { clouds } = settings
46
+ let uploadResult = null
47
+ for (var i in clouds) {
48
+ const cloud = clouds[i]
49
+ uploadResult = await upload({
50
+ id: cloud.id,
51
+ sourceUrl: buildPaths.textMessage.text,
52
+ filename: buildPaths.textMessage.textFileName,
53
+ auth: cloud.auth,
54
+ settings
55
+ })
56
+ uploadResult = await upload({
57
+ id: cloud.id,
58
+ sourceUrl: buildPaths.textMessage.manifestFileNameBuilt,
59
+ filename: buildPaths.textMessage.manifestFileName,
60
+ auth: cloud.auth,
61
+ settings
62
+ })
63
+ }
64
+
65
+ const _activity = await getActivity({ path })
66
+
67
+ _activity[entry.code] = {
68
+ ...(_activity[entry.code] ? _activity[entry.code] : {}),
69
+ status: "published"
70
+ }
71
+
72
+ await updateActivity({
73
+ path,
74
+ content: _activity,
75
+ })
76
+
77
+ return {
78
+ entry
79
+ }
80
+ }
@@ -0,0 +1,14 @@
1
+ export default async (props) => {
2
+
3
+ const { id, settings } = props
4
+
5
+ const cloudLibrary = settings.cloudLibrary({ id })
6
+ if (!cloudLibrary) {
7
+ return {
8
+ isValid: false,
9
+ error: new Error('Cloud not supported.')
10
+ }
11
+ }
12
+
13
+ return cloudLibrary.upload(props)
14
+ }
@@ -0,0 +1,18 @@
1
+ import perform from './lib/email.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+
4
+ export default async ({
5
+ path,
6
+ settings
7
+ }) => {
8
+ let entries = await getEntries({
9
+ path,
10
+ })
11
+
12
+ for (var i in entries) {
13
+ const entry = entries[i]
14
+ await perform({ entry, settings })
15
+ }
16
+
17
+ return true
18
+ }
@@ -0,0 +1,29 @@
1
+
2
+ test.skip('build posts', async () => {
3
+ const fsPath = (await import('path')).default
4
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
5
+ const operation = (await import('./path.js')).default
6
+
7
+ const result = await operation({
8
+ settings: {
9
+ platforms: [{
10
+ id: 'medium',
11
+ auth: {
12
+ token: process.env.TEST_MEDIUM_TOKEN,
13
+ }
14
+ }],
15
+ storage: {
16
+ type: "cdn",
17
+ auth: {
18
+ key: '',
19
+ secret: '',
20
+ bucketName: ''
21
+ }
22
+ }
23
+ },
24
+ path,
25
+ })
26
+ expect(result).toBeTruthy()
27
+ })
28
+
29
+
@@ -0,0 +1 @@
1
+ export { default as processPath } from './path.js'
@@ -0,0 +1,41 @@
1
+ import consolidate from '../consolidate/entry.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+ import build from '../build/entry.js'
4
+ import sync from '../sync/entry.js'
5
+ import format from '../format/entry.js'
6
+ import optimize from '../optimize/entry.js'
7
+ import version from '../version/entry.js'
8
+ import cloudify from '../cloudify/entry.js'
9
+ import adaptSettings from '../../lib/adaptSettings.js'
10
+
11
+ export default async ({
12
+ path,
13
+ settings
14
+ }) => {
15
+ adaptSettings({ settings })
16
+ let entries = await getEntries({
17
+ path,
18
+ settings
19
+ })
20
+
21
+ for (var i in entries) {
22
+ let entry = entries[i]
23
+ switch (entry.manifest.status) {
24
+ case 'pause': {
25
+ continue
26
+ }
27
+ default: break
28
+ }
29
+
30
+ entry = (await format({ entry, settings })).entry
31
+ entry = (await build({ entry, settings })).entry
32
+ entry = (await consolidate({ entry, settings })).entry
33
+ entry = (await optimize({ entry, settings })).entry
34
+ entry = (await cloudify({ entry, settings })).entry
35
+ entry = (await sync({ entry, settings })).entry
36
+
37
+ await version({})
38
+ }
39
+
40
+ return true
41
+ }
@@ -0,0 +1,46 @@
1
+
2
+
3
+ describe('project', () => {
4
+ it('Updates and syncs to minio', async () => {
5
+ const fsPath = (await import('path')).default
6
+ let path = `${fsPath.resolve(process.env.TEST_MOCK_FOLDER)}`
7
+ const operation = (await import('./path.js')).default
8
+ const result = await operation({
9
+ settings: {
10
+ forceUploadAttachments: false,
11
+ clouds: [{
12
+ id: "minio",
13
+ auth: {
14
+ endPoint: process.env.TEST_MINIO_ENDPOINT,
15
+ accessKey: process.env.TEST_MINIO_ACCESS_KEY,
16
+ secretKey: process.env.TEST_MINIO_SECRET,
17
+ bucketName: process.env.TEST_MINIO_BUCKET_NAME
18
+ }
19
+ },],
20
+ },
21
+ path,
22
+ })
23
+ expect(result).toBeTruthy()
24
+ })
25
+ it.skip('Updates and syncs to minio force', async () => {
26
+ const fsPath = (await import('path')).default
27
+ let path = `${fsPath.resolve(process.env.TEST_MOCK_FOLDER)}`
28
+ const operation = (await import('./path.js')).default
29
+ const result = await operation({
30
+ settings: {
31
+ forceUploadAttachments: true,
32
+ clouds: [{
33
+ id: "minio",
34
+ auth: {
35
+ endPoint: process.env.TEST_MINIO_ENDPOINT,
36
+ accessKey: process.env.TEST_MINIO_ACCESS_KEY,
37
+ secretKey: process.env.TEST_MINIO_SECRET,
38
+ bucketName: process.env.TEST_MINIO_BUCKET_NAME
39
+ }
40
+ },],
41
+ },
42
+ path,
43
+ })
44
+ expect(result).toBeTruthy()
45
+ })
46
+ })
@@ -0,0 +1,10 @@
1
+ import perform from './lib/perform.js'
2
+
3
+ export default async ({
4
+ entry,
5
+ source,
6
+ settings
7
+ }) => {
8
+ return
9
+ return perform({ entry, source, settings })
10
+ }
@@ -0,0 +1,2 @@
1
+ export { default as processEntry } from './entry.js'
2
+ export { default as processPath } from './path.js'
@@ -0,0 +1,74 @@
1
+ import markdownToLexer from '../../../lib/remark/markdownToLexer.js'
2
+ import mdastToHTML from '../../../lib/remark/mdastToHTML.js'
3
+ import mdastToMarkdown from '../../../lib/remark/mdastToMarkdown.js'
4
+ import reset from './reset.js'
5
+ import updatePost from './updatePost.js'
6
+
7
+ export default async (props) => {
8
+
9
+ const { entry } = props
10
+ const { path, } = entry
11
+ const data = props.source ? props.source : (entry.post.consolidated
12
+ ? entry.post.consolidated
13
+ : entry.post.source)
14
+
15
+ await reset({ path })
16
+
17
+ const child = markdownToLexer({
18
+ data
19
+ })
20
+
21
+ const mdast = await perform({
22
+ child,
23
+ path
24
+ })
25
+
26
+ let md = await mdastToMarkdown({ mdast })
27
+ let html = mdastToHTML({ mdast })
28
+
29
+ await updatePost({
30
+ path,
31
+ md,
32
+ html
33
+ })
34
+
35
+ return {
36
+ md,
37
+ html,
38
+ entry: mdast
39
+ }
40
+ }
41
+
42
+ const perform = async (props) => {
43
+ const { child, path } = props
44
+ let _child = { ...child }
45
+ // switch (_child.type) {
46
+ // case 'code': {
47
+ // switch (_child.lang) {
48
+ // case 'mermaid': {
49
+ // _child = await buildMermaid({
50
+ // child: _child,
51
+ // path
52
+ // })
53
+ // } break
54
+ // default:
55
+ // break
56
+ // }
57
+ // } break
58
+ // default:
59
+ // break
60
+ // }
61
+
62
+ let _children = []
63
+ if (_child.children) {
64
+ _children = await Promise.all(_child.children.map(async child => perform({
65
+ ...props,
66
+ child
67
+ })))
68
+ }
69
+
70
+ return {
71
+ ..._child,
72
+ children: _children
73
+ }
74
+ }
@@ -0,0 +1,16 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+ import checkFileExists from '../../../lib/fs/checkFileExists.js'
4
+
5
+ export default async ({
6
+ path, }) => {
7
+
8
+ const buildPath = fsPath.join(path, "build")
9
+ if (!(await checkFileExists(buildPath))) {
10
+ return
11
+ }
12
+
13
+ let success = await fs.promises.rmdir(buildPath, { recursive: true })
14
+ success = true
15
+ return success
16
+ }
@@ -0,0 +1,16 @@
1
+ import fsPath from 'path'
2
+ import fs from 'fs'
3
+
4
+ export default async ({
5
+ path,
6
+ md,
7
+ html }) => {
8
+
9
+ const mdPath = fsPath.join(path, ".post.built.md")
10
+ const htmlPath = fsPath.join(path, ".post.built.html")
11
+
12
+ await fs.promises.writeFile(mdPath, md, 'utf8')
13
+ await fs.promises.writeFile(htmlPath, html, 'utf8')
14
+
15
+ return true
16
+ }
@@ -0,0 +1,20 @@
1
+ import perform from './lib/perform.js'
2
+ import getEntries from '../../lib/entries/getAtPath.js'
3
+ import adaptSettings from '../../lib/adaptSettings.js'
4
+
5
+ export default async ({
6
+ path,
7
+ settings
8
+ }) => {
9
+ adaptSettings({ settings })
10
+ let entries = await getEntries({
11
+ path,
12
+ })
13
+
14
+ for (var i in entries) {
15
+ const entry = entries[i]
16
+ await perform({ entry, settings })
17
+ }
18
+
19
+ return true
20
+ }
@@ -0,0 +1,16 @@
1
+
2
+
3
+ test.skip('version posts', async () => {
4
+ const fsPath = (await import('path')).default
5
+ let path = fsPath.resolve(process.env.TEST_MOCK_FOLDER)
6
+ const operation = (await import('./path.js')).default
7
+
8
+ const result = await operation({
9
+ settings: {
10
+ },
11
+ path,
12
+ })
13
+ expect(result).toBeTruthy()
14
+ })
15
+
16
+