@paralect/hive 0.0.2 → 0.0.3
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 +5 -2
- package/starter/.babelrc +3 -0
- package/starter/Dockerfile +17 -8
- package/starter/bin/deploy.sh +5 -0
- package/starter/deploy/api/Chart.yaml +6 -0
- package/starter/deploy/api/staging.yaml +3 -0
- package/starter/deploy/api/templates/deployment.yaml +43 -0
- package/starter/deploy/api/templates/ingress.yaml +26 -0
- package/starter/deploy/api/templates/service.yaml +14 -0
- package/starter/deploy/script/Dockerfile +39 -0
- package/starter/deploy/script/package-lock.json +1499 -0
- package/starter/deploy/script/package.json +12 -0
- package/starter/deploy/script/src/config.js +48 -0
- package/starter/deploy/script/src/index.js +105 -0
- package/starter/deploy/script/src/util.js +19 -0
- package/starter/package-lock.json +3363 -139
- package/starter/package.json +9 -1
- package/starter/src/app-config/index.js +10 -0
- package/starter/src/db.js +13 -3
- package/starter/src/emails/MyEmailComponent.jsx +16 -0
- package/starter/src/emails/dist/MyEmailComponent.js +17 -0
- package/starter/src/helpers/getResourceEndpoints.js +16 -13
- package/starter/src/helpers/getResources.js +2 -1
- package/starter/src/helpers/getSchemas.js +3 -0
- package/starter/src/resources/health/endpoints/get.js +7 -0
- package/starter/src/resources/users/endpoints/getCurrentUser.js +4 -1
- package/starter/src/resources/users/endpoints/getUserProfile.js +3 -2
- package/starter/src/routes/index.js +1 -1
- package/starter/src/services/emailService.js +15 -0
- package/starter/bin/init-project.sh +0 -22
package/starter/package.json
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build-assets": "mjml ./src/assets/emails/*.mjml -o ./src/assets/emails/dist/",
|
|
20
|
+
"build-emails": "babel src/emails --out-dir src/emails/dist",
|
|
20
21
|
"dev": "nodemon --watch src src/app.js",
|
|
21
22
|
"init-project": "./bin/init-project.sh",
|
|
22
23
|
"start": "node src/app.js",
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
"@koa/multer": "3.0.0",
|
|
32
33
|
"@koa/router": "10.1.1",
|
|
33
34
|
"@paralect/node-mongo": "2.1.1",
|
|
35
|
+
"@react-email/components": "^0.0.20",
|
|
36
|
+
"@react-email/render": "^0.0.16",
|
|
34
37
|
"@sendgrid/mail": "7.6.1",
|
|
35
38
|
"@socket.io/redis-adapter": "7.1.0",
|
|
36
39
|
"@socket.io/redis-emitter": "4.1.1",
|
|
@@ -40,7 +43,7 @@
|
|
|
40
43
|
"dotenv": "16.0.0",
|
|
41
44
|
"eslint-config-prettier": "8.5.0",
|
|
42
45
|
"handlebars": "4.7.7",
|
|
43
|
-
"joi": "17.
|
|
46
|
+
"joi": "^17.13.3",
|
|
44
47
|
"koa": "2.13.4",
|
|
45
48
|
"koa-bodyparser": "4.3.0",
|
|
46
49
|
"koa-helmet": "6.1.0",
|
|
@@ -54,6 +57,7 @@
|
|
|
54
57
|
"moment-duration-format": "2.3.2",
|
|
55
58
|
"multer": "1.4.4",
|
|
56
59
|
"node-schedule": "2.1.0",
|
|
60
|
+
"nodemailer": "^6.9.14",
|
|
57
61
|
"nodemon": "2.0.15",
|
|
58
62
|
"prettier": "2.6.2",
|
|
59
63
|
"psl": "1.8.0",
|
|
@@ -66,6 +70,10 @@
|
|
|
66
70
|
"winston": "3.6.0"
|
|
67
71
|
},
|
|
68
72
|
"devDependencies": {
|
|
73
|
+
"@babel/cli": "^7.24.7",
|
|
74
|
+
"@babel/core": "^7.24.7",
|
|
75
|
+
"@babel/preset-env": "^7.24.7",
|
|
76
|
+
"@babel/preset-react": "^7.24.7",
|
|
69
77
|
"eslint": "8.9.0",
|
|
70
78
|
"eslint-config-airbnb-base": "15.0.0",
|
|
71
79
|
"eslint-plugin-import": "2.25.4",
|
|
@@ -33,6 +33,16 @@ const config = {
|
|
|
33
33
|
url: process.env.REDIS_URI,
|
|
34
34
|
},
|
|
35
35
|
|
|
36
|
+
smtp: {
|
|
37
|
+
host: process.env.SMTP_SERVER,
|
|
38
|
+
port: process.env.SMTP_PORT,
|
|
39
|
+
secure: true,
|
|
40
|
+
auth: {
|
|
41
|
+
user: process.env.SMTP_USER,
|
|
42
|
+
pass: process.env.SMTP_KEY,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
|
|
36
46
|
...appConfig,
|
|
37
47
|
|
|
38
48
|
assert(configKey) {
|
package/starter/src/db.js
CHANGED
|
@@ -17,10 +17,20 @@ db.init = async () => {
|
|
|
17
17
|
_.each(
|
|
18
18
|
schemaPaths,
|
|
19
19
|
({ file: schemaFile, resourceName, name: schemaName }) => {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let schema = require(schemaFile);
|
|
21
|
+
|
|
22
|
+
if (process.env.HIVE_SRC) {
|
|
23
|
+
let extendSchemaPath = `${process.env.HIVE_SRC}/resources/${resourceName}/${schemaName}.extends.schema.js`;
|
|
24
|
+
|
|
25
|
+
if (fs.existsSync(extendSchemaPath)) {
|
|
26
|
+
let extendsSchema = require(extendSchemaPath);
|
|
27
|
+
|
|
28
|
+
schema = schema.append(extendsSchema);
|
|
29
|
+
console.log('schema', schema);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
db.schemas[schemaName] = schema;
|
|
24
34
|
|
|
25
35
|
db.services[schemaName] = db.createService(`${resourceName}`, {
|
|
26
36
|
validate: (obj) => schema.validate(obj, { allowUnknown: true }),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const { Html, Head, Body, Container, Heading, Text } = require('@react-email/components');
|
|
3
|
+
|
|
4
|
+
const MyEmailComponent = ({ name }) => (
|
|
5
|
+
<Html>
|
|
6
|
+
<Head />
|
|
7
|
+
<Body>
|
|
8
|
+
<Container>
|
|
9
|
+
<Heading>Hello, {name}!</Heading>
|
|
10
|
+
<Text>This is a test email using @react-email and Express.</Text>
|
|
11
|
+
</Container>
|
|
12
|
+
</Body>
|
|
13
|
+
</Html>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
module.exports = { MyEmailComponent };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var _require = require('@react-email/components'),
|
|
5
|
+
Html = _require.Html,
|
|
6
|
+
Head = _require.Head,
|
|
7
|
+
Body = _require.Body,
|
|
8
|
+
Container = _require.Container,
|
|
9
|
+
Heading = _require.Heading,
|
|
10
|
+
Text = _require.Text;
|
|
11
|
+
var MyEmailComponent = function MyEmailComponent(_ref) {
|
|
12
|
+
var name = _ref.name;
|
|
13
|
+
return /*#__PURE__*/React.createElement(Html, null, /*#__PURE__*/React.createElement(Head, null), /*#__PURE__*/React.createElement(Body, null, /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Heading, null, "Hello, ", name, "!"), /*#__PURE__*/React.createElement(Text, null, "This is a test email using @react-email and Express."))));
|
|
14
|
+
};
|
|
15
|
+
module.exports = {
|
|
16
|
+
MyEmailComponent: MyEmailComponent
|
|
17
|
+
};
|
|
@@ -6,21 +6,24 @@ const {
|
|
|
6
6
|
} = fs;
|
|
7
7
|
|
|
8
8
|
module.exports = async (resourceName) => {
|
|
9
|
-
|
|
10
|
-
let isHiveEndpoint;
|
|
9
|
+
let endpointFiles = [];
|
|
11
10
|
|
|
12
|
-
if (fs.existsSync(`${
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (fs.existsSync(`${process.env.HIVE_SRC}/resources/${resourceName}/endpoints`)) {
|
|
12
|
+
endpointFiles = [...endpointFiles, ...(await readdir(
|
|
13
|
+
`${process.env.HIVE_SRC}/resources/${resourceName}/endpoints`
|
|
14
|
+
)).map( f => ({ name: f, isHiveEndpoint: true}))];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (fs.existsSync(`${__dirname}/../resources/${resourceName}/endpoints`)) {
|
|
18
|
+
endpointFiles = [...endpointFiles, ...(await readdir(
|
|
16
19
|
`${__dirname}/../resources/${resourceName}/endpoints`
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
return endpointFiles.map((f) => ({
|
|
20
|
-
file: isHiveEndpoint ? `${process.env.HIVE_SRC}/resources/${resourceName}/endpoints/${f}`: `${__dirname}/../resources/${resourceName}/endpoints/${f}`,
|
|
21
|
-
name: _.last(f.split("/")).replace(".js", ""),
|
|
22
|
-
}));
|
|
20
|
+
)).map( f => ({ name: f }))];
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
console.log('endpointFiles', resourceName, endpointFiles);
|
|
24
|
+
return endpointFiles.map(({ name, isHiveEndpoint }) => ({
|
|
25
|
+
file: isHiveEndpoint ? `${process.env.HIVE_SRC}/resources/${resourceName}/endpoints/${name}`: `${__dirname}/../resources/${resourceName}/endpoints/${name}`,
|
|
26
|
+
name: _.last(name.split("/")).replace(".js", ""),
|
|
27
|
+
}));
|
|
28
|
+
|
|
26
29
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const _ = require("lodash");
|
|
1
2
|
const path = require("path");
|
|
2
3
|
const fs = require("fs");
|
|
3
4
|
|
|
@@ -19,7 +20,7 @@ module.exports = async () => {
|
|
|
19
20
|
let hiveResourcesDirPath = `${process.env.HIVE_SRC}/resources`;
|
|
20
21
|
|
|
21
22
|
if (fs.existsSync(hiveResourcesDirPath)) {
|
|
22
|
-
resourceDirs = [...resourceDirs, ...((await getDirectories(hiveResourcesDirPath)).map(r => ({ dirName: r.dirName, isHive: true })))]
|
|
23
|
+
resourceDirs = _.uniqBy([...resourceDirs, ...((await getDirectories(hiveResourcesDirPath)).map(r => ({ dirName: r.dirName, isHive: true })))], r => r.dirName);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -3,6 +3,7 @@ const {
|
|
|
3
3
|
} = require("fs");
|
|
4
4
|
const getResources = require("./getResources");
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
module.exports = async () => {
|
|
7
8
|
const resources = await getResources();
|
|
8
9
|
|
|
@@ -12,11 +13,13 @@ module.exports = async () => {
|
|
|
12
13
|
resources.map(async ({ dir: resourceDir, name: resourceName }) => {
|
|
13
14
|
const resourceSchemas = (await readdir(resourceDir))
|
|
14
15
|
.filter((f) => f.includes("schema.js"))
|
|
16
|
+
.filter((f) => !f.includes("extends.schema"))
|
|
15
17
|
.map((f) => ({
|
|
16
18
|
file: `${resourceDir}/${f}`,
|
|
17
19
|
resourceName,
|
|
18
20
|
name: f.replace(".schema.js", ""),
|
|
19
21
|
}));
|
|
22
|
+
|
|
20
23
|
schemas.push(...resourceSchemas);
|
|
21
24
|
})
|
|
22
25
|
);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
const { render } = require('@react-email/render');
|
|
2
|
+
const { MyEmailComponent } = require('emails/dist/MyEmailComponent');
|
|
3
|
+
const React = require('react');
|
|
4
|
+
|
|
1
5
|
const handler = (ctx) => {
|
|
6
|
+
const emailHtml = render(React.createElement(MyEmailComponent, { name: 'test' }));
|
|
7
|
+
|
|
8
|
+
ctx.body = emailHtml;
|
|
2
9
|
ctx.status = 200;
|
|
3
10
|
};
|
|
4
11
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
const Joi = require("joi");
|
|
2
|
+
const userService = require('db').services.users;
|
|
3
|
+
|
|
1
4
|
module.exports.handler = async (ctx) => {
|
|
2
5
|
const user = await userService.findOne({ _id: ctx.state.user._id });
|
|
3
6
|
ctx.body = user;
|
|
4
7
|
};
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
module.exports.middlewares = [require('middlewares/isAuthorized')];
|
|
7
10
|
|
|
8
11
|
module.exports.requestSchema = Joi.object({});
|
|
9
12
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
const Joi = require("joi");
|
|
2
|
+
const userService = require('db').services.users;
|
|
3
|
+
|
|
1
4
|
module.exports.handler = async (ctx) => {
|
|
2
5
|
const { userId } = ctx.params;
|
|
3
6
|
const user = await userService.findOne({ _id: userId });
|
|
4
7
|
ctx.body = user;
|
|
5
8
|
};
|
|
6
9
|
|
|
7
|
-
const Joi = require("joi");
|
|
8
|
-
|
|
9
10
|
module.exports.requestSchema = Joi.object({
|
|
10
11
|
userId: Joi.string().required(),
|
|
11
12
|
});
|
|
@@ -74,7 +74,7 @@ const defineRoutes = async (app) => {
|
|
|
74
74
|
app.use(tryToAttachUser);
|
|
75
75
|
|
|
76
76
|
const resources = await getResources();
|
|
77
|
-
|
|
77
|
+
console.log('resources', resources)
|
|
78
78
|
_.each(resources, async ({ name: resourceName }) => {
|
|
79
79
|
const resourceRouter = new Router();
|
|
80
80
|
const globalRouter = new Router();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const config = require('app-config');
|
|
2
|
+
const nodemailer = require('nodemailer');
|
|
3
|
+
|
|
4
|
+
config.assert('smtp');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
sendEmail: async ({ to, subject, html }) => {
|
|
8
|
+
const transporter = nodemailer.createTransport(config.smtp)
|
|
9
|
+
|
|
10
|
+
return await transporter.sendMail({
|
|
11
|
+
from: process.env.SMTP_USER,
|
|
12
|
+
to, subject, html
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
DIR=$PROJECT_SRC
|
|
3
|
-
echo CHECKING $DIR
|
|
4
|
-
|
|
5
|
-
if [ -f "$DIR/package.json" ]; then
|
|
6
|
-
echo "Project already initialized"
|
|
7
|
-
else
|
|
8
|
-
### Control will jump here if $DIR does NOT exists ###
|
|
9
|
-
echo "Configuring project..."
|
|
10
|
-
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
|
11
|
-
cd ..
|
|
12
|
-
pwd
|
|
13
|
-
mkdir -p $PROJECT_SRC
|
|
14
|
-
|
|
15
|
-
echo Unzipping project starter to $DIR
|
|
16
|
-
unzip ./project-api-starter.zip -d $DIR
|
|
17
|
-
|
|
18
|
-
echo dir before script
|
|
19
|
-
ls $PROJECT_SRC
|
|
20
|
-
fi
|
|
21
|
-
|
|
22
|
-
exit 1
|