@notifiles/sdk 1.0.0 → 1.1.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notifiles/sdk",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -46,7 +46,7 @@ const perform = async (props) => {
46
46
 
47
47
 
48
48
  let testMessagePath = fsPath.join(folderPath, 'textmessage.txt')
49
- let pushPath = fsPath.join(folderPath, 'push.txt')
49
+ let pushPath = fsPath.join(folderPath, 'pushnotification.txt')
50
50
  const i18nPath = fsPath.join(folderPath, 'i18n.json')
51
51
  let manifest = await importJSONAsync(fsPath.join(folderPath, 'manifest.json'))
52
52
 
@@ -63,7 +63,7 @@ const perform = async (props) => {
63
63
 
64
64
  // const module = await import(emailPath)
65
65
  let textMessage = null
66
- let push = null
66
+ let pushNotification = null
67
67
  let i18n = null
68
68
 
69
69
  if (await checkFileExists(testMessagePath)) {
@@ -71,7 +71,7 @@ const perform = async (props) => {
71
71
  }
72
72
 
73
73
  if (await checkFileExists(pushPath)) {
74
- push = await fs.promises.readFile(pushPath, 'utf8')
74
+ pushNotification = await fs.promises.readFile(pushPath, 'utf8')
75
75
  }
76
76
 
77
77
  if (await checkFileExists(i18nPath)) {
@@ -85,7 +85,7 @@ const perform = async (props) => {
85
85
  path: folderPath,
86
86
  // email: module,
87
87
  textMessage,
88
- push,
88
+ pushNotification,
89
89
  i18n: i18n ? i18n : {},
90
90
  manifest,
91
91
  activity
@@ -1,6 +1,7 @@
1
1
  import checkFileExists from '../../lib/fs/checkFileExists.js'
2
2
  import performEmail from './lib/email/index.js'
3
3
  import performTextMessage from './lib/textmessage/index.js'
4
+ import performPushNotification from './lib/pushnotification/index.js'
4
5
  import fs from 'fs'
5
6
 
6
7
  export default async ({
@@ -18,6 +19,7 @@ export default async ({
18
19
  const versions = await Promise.all(entry.versions.map(async _entry => {
19
20
  let res = await performEmail({ entry: _entry, settings, })
20
21
  res = await performTextMessage({ entry: res.entry, settings, })
22
+ res = await performPushNotification({ entry: res.entry, settings, })
21
23
  return res.entry
22
24
  }))
23
25
 
@@ -0,0 +1,44 @@
1
+ import fs from 'fs'
2
+ import translate from './translate.js'
3
+ import checkFileExists from '../../../../lib/fs/checkFileExists.js'
4
+
5
+ export default async (props) => {
6
+
7
+ const { entry } = props
8
+ const { path,
9
+ buildPaths,
10
+ code,
11
+ language } = entry
12
+
13
+ const textPath = `${path}/pushnotification.txt`
14
+ if (!(await checkFileExists(textPath))) {
15
+ return {
16
+ entry
17
+ }
18
+ }
19
+
20
+ await fs.promises.cp(
21
+ textPath,
22
+ buildPaths.pushNotification.text
23
+ )
24
+
25
+ let text = await fs.promises.readFile(buildPaths.pushNotification.text, 'utf8')
26
+ text = translate({ text: text, strings: language.data })
27
+ text = text
28
+ .replaceAll('|%', '{{')
29
+ .replaceAll('%|', '}}')
30
+
31
+ await fs.promises.writeFile(
32
+ buildPaths.pushNotification.text,
33
+ text
34
+ )
35
+
36
+ return {
37
+ entry: {
38
+ ...entry,
39
+ pushNotification: {
40
+ text,
41
+ }
42
+ },
43
+ }
44
+ }
@@ -0,0 +1,25 @@
1
+ export default ({ text, strings }) => {
2
+ let _text = text
3
+
4
+ const firsts = _text.split('[[')
5
+ let matched = firsts.map(element => {
6
+ if (element.indexOf(']]') === -1) {
7
+ return element
8
+ }
9
+
10
+ let seconds = element.split(']]')
11
+ const key = seconds[0]
12
+ const value = strings[key]
13
+ if (!value) {
14
+ return seconds.join('')
15
+ }
16
+ seconds = seconds.length > 1
17
+ ? seconds.slice(1, seconds.length)
18
+ : seconds
19
+ return [value, seconds].join('')
20
+ })
21
+
22
+ matched = matched.join('')
23
+ return matched
24
+
25
+ }
@@ -1,6 +1,7 @@
1
1
  import adaptSettings from '../../lib/adaptSettings.js'
2
2
  import performEmail from './lib/email/index.js'
3
3
  import performTextMessage from './lib/textMessage.js'
4
+ import performPushNotification from './lib/pushNotification.js'
4
5
 
5
6
  export default async ({
6
7
  entry,
@@ -13,6 +14,7 @@ export default async ({
13
14
  versions: await Promise.all(entry.versions.map(async _entry => {
14
15
  let res = await performEmail({ entry: _entry, settings, })
15
16
  res = await performTextMessage({ entry: res.entry, settings, })
17
+ res = await performPushNotification({ entry: res.entry, settings, })
16
18
  return res.entry
17
19
  }))
18
20
  }
@@ -0,0 +1,9 @@
1
+
2
+ export default async (props) => {
3
+
4
+ const { entry } = props
5
+
6
+ return {
7
+ entry
8
+ }
9
+ }
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -0,0 +1,5 @@
1
+
2
+ export default async (props) => {
3
+ const { entry } = props
4
+ return { entry }
5
+ }
@@ -41,6 +41,14 @@ export default async ({
41
41
  manifestFileNameBuilt: `${path}/.build/textmessage/${code}/manifest.json`,
42
42
  manifestFileName: `${entry.slug}/textmessage/${code}/manifest.json`,
43
43
  },
44
+ pushNotification: {
45
+ container: `${path}/.build/pushnotification/${code}`,
46
+ text: `${path}/.build/pushnotification/${code}/pushnotification.txt`,
47
+ textFileName: `${entry.slug}/pushnotification/${code}/pushnotification.txt`,
48
+ assetsContainer: `${entry.slug}/pushnotification/${code}/assets`,
49
+ manifestFileNameBuilt: `${path}/.build/pushnotification/${code}/manifest.json`,
50
+ manifestFileName: `${entry.slug}/pushnotification/${code}/manifest.json`,
51
+ },
44
52
  manifestFileNameBuilt: `${path}/.build/manifest.json`,
45
53
  manifestFileName: `${entry.slug}/manifest.json`,
46
54
  activityPath: `${path}/.activity.json`,
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -0,0 +1,8 @@
1
+
2
+ export default async (props) => {
3
+ const { entry } = props
4
+
5
+ return {
6
+ entry
7
+ }
8
+ }
@@ -1,5 +1,6 @@
1
1
  import performEmail from './lib/email.js'
2
2
  import performTextMessage from './lib/textMessage.js'
3
+ import performPushNotification from './lib/pushNotification.js'
3
4
 
4
5
  export default async ({
5
6
  entry,
@@ -11,6 +12,7 @@ export default async ({
11
12
  versions: await Promise.all(entry.versions.map(async _entry => {
12
13
  let res = await performEmail({ entry: _entry, settings, })
13
14
  res = await performTextMessage({ entry: res.entry, settings, })
15
+ res = await performPushNotification({ entry: res.entry, settings, })
14
16
  return res.entry
15
17
  }))
16
18
  }
@@ -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, pushNotification, buildPaths, } = entry
12
+ const { text, } = pushNotification
13
+
14
+ const textPath = `${path}/pushnotification.txt`
15
+ if (!(await checkFileExists(textPath))) {
16
+ return {
17
+ entry
18
+ }
19
+ }
20
+
21
+ await fs.promises.writeFile(
22
+ buildPaths.pushNotification.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.pushNotification.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.pushNotification.text,
52
+ filename: buildPaths.pushNotification.textFileName,
53
+ auth: cloud.auth,
54
+ settings
55
+ })
56
+ uploadResult = await upload({
57
+ id: cloud.id,
58
+ sourceUrl: buildPaths.pushNotification.manifestFileNameBuilt,
59
+ filename: buildPaths.pushNotification.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
+ }
@@ -1,52 +0,0 @@
1
- import htmlToMdast from '../../../../lib/remark/htmlToMdast_.js'
2
- import mdastToMarkdown from '../../../../lib/remark/mdastToMarkdown.js'
3
- import reset from '../reset.js'
4
- import { render } from '@react-email/render'
5
-
6
- export default async (props) => {
7
-
8
- const { entry } = props
9
- const { path, email } = entry
10
- const { default: Template, } = email
11
- await reset({ path })
12
-
13
- let html = render(<Template />, {
14
- pretty: true,
15
- })
16
-
17
- const text = render(<Template />, {
18
- plainText: true,
19
- })
20
-
21
- const child = await htmlToMdast({ data: html })
22
- const mdast = await perform({
23
- child,
24
- path
25
- })
26
-
27
- let md = await mdastToMarkdown({ mdast })
28
-
29
- // await updatePost({
30
- // path,
31
- // md,
32
- // html
33
- // })
34
-
35
- return {
36
- entry: {
37
- ...entry,
38
- email: {
39
- text,
40
- html,
41
- mdast,
42
- md
43
- }
44
- },
45
-
46
- }
47
- }
48
-
49
- const perform = async (props) => {
50
- const { child, path } = props
51
- return child
52
- }