@paralect/hive 0.0.1 → 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.
Files changed (48) hide show
  1. package/cli/hive.js +74 -0
  2. package/package.json +10 -3
  3. package/starter/.babelrc +3 -0
  4. package/starter/Dockerfile +17 -8
  5. package/starter/bin/deploy.sh +5 -0
  6. package/starter/deploy/api/Chart.yaml +6 -0
  7. package/starter/deploy/api/staging.yaml +3 -0
  8. package/starter/deploy/api/templates/deployment.yaml +43 -0
  9. package/starter/deploy/api/templates/ingress.yaml +26 -0
  10. package/starter/deploy/api/templates/service.yaml +14 -0
  11. package/starter/deploy/script/Dockerfile +39 -0
  12. package/starter/deploy/script/package-lock.json +1499 -0
  13. package/starter/deploy/script/package.json +12 -0
  14. package/starter/deploy/script/src/config.js +48 -0
  15. package/starter/deploy/script/src/index.js +105 -0
  16. package/starter/deploy/script/src/util.js +19 -0
  17. package/starter/package-lock.json +3330 -97
  18. package/starter/package.json +10 -1
  19. package/starter/src/app-config/assertEnv.js +15 -0
  20. package/starter/src/app-config/index.js +56 -0
  21. package/starter/src/app.js +1 -1
  22. package/starter/src/db.js +14 -6
  23. package/starter/src/emails/MyEmailComponent.jsx +16 -0
  24. package/starter/src/emails/dist/MyEmailComponent.js +17 -0
  25. package/starter/src/helpers/getResourceEndpoints.js +16 -13
  26. package/starter/src/helpers/getResources.js +11 -3
  27. package/starter/src/helpers/getSchemas.js +3 -0
  28. package/starter/src/ioEmitter.js +1 -1
  29. package/starter/src/logger.js +1 -1
  30. package/starter/src/middlewares/isAuthorized.js +29 -2
  31. package/starter/src/resources/health/endpoints/get.js +7 -0
  32. package/starter/src/resources/tokens/methods/generateSecureToken.js +9 -0
  33. package/starter/src/resources/tokens/methods/setToken.js +7 -0
  34. package/starter/src/resources/tokens/methods/storeToken.js +33 -0
  35. package/starter/src/resources/tokens/tokens.schema.js +12 -0
  36. package/starter/src/resources/users/endpoints/getCurrentUser.js +4 -1
  37. package/starter/src/resources/users/endpoints/getUserProfile.js +3 -2
  38. package/starter/src/resources/users/methods/ensureUserCreated.js +67 -0
  39. package/starter/src/resources/users/users.schema.js +11 -5
  40. package/starter/src/routes/index.js +1 -1
  41. package/starter/src/services/emailService.js +15 -0
  42. package/starter/src/services/setCookie.js +22 -0
  43. package/starter/src/socketIo.js +1 -1
  44. package/cli/cli.js +0 -10
  45. package/starter/bin/init-project.sh +0 -22
  46. package/starter/mongodb-ca-certificate.cer +0 -32
  47. package/starter/src/config/index.js +0 -24
  48. /package/starter/src/{config → app-config}/app.js +0 -0
package/cli/hive.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander');
4
+ const axios = require('axios');
5
+ const fs = require('fs-extra');
6
+ const path = require('path');
7
+
8
+ const GITHUB_API_URL = 'https://api.github.com/repos';
9
+
10
+ async function fetchDirectoryTree(owner, repo, dirPath) {
11
+ const url = `${GITHUB_API_URL}/${owner}/${repo}/contents/${dirPath}`;
12
+ const response = await axios.get(url);
13
+ return response.data;
14
+ }
15
+
16
+ async function downloadFile(fileUrl, filePath) {
17
+ const response = await axios({
18
+ url: fileUrl,
19
+ method: 'GET',
20
+ responseType: 'stream'
21
+ });
22
+ await fs.ensureDir(path.dirname(filePath));
23
+ response.data.pipe(fs.createWriteStream(filePath));
24
+ return new Promise((resolve, reject) => {
25
+ response.data.on('end', resolve);
26
+ response.data.on('error', reject);
27
+ });
28
+ }
29
+
30
+ async function downloadDirectory(pluginName, baseDir = '') {
31
+ const owner = 'paralect';
32
+ const repo = 'hive-plugins';
33
+
34
+ const destDir = path.join(process.cwd(), baseDir);
35
+
36
+ const tree = await fetchDirectoryTree(owner, repo, pluginName);
37
+ for (const item of tree) {
38
+ const relativePath = path.relative(pluginName, item.path);
39
+ const filePath = path.join(destDir, relativePath);
40
+ if (item.type === 'file') {
41
+ console.log(`Downloading ${item.path}...`);
42
+ await downloadFile(item.download_url, filePath);
43
+ } else if (item.type === 'dir') {
44
+ await downloadDirectory(item.path, path.join(baseDir, relativePath));
45
+ }
46
+ }
47
+ }
48
+
49
+ program
50
+ .command('run [dirPath]')
51
+ .description('Run Hive server')
52
+ .action(async (dirPath = '.') => {
53
+ try {
54
+ process.env.HIVE_SRC = path.resolve(process.cwd(), dirPath);
55
+ require('./../starter/src/app.js');
56
+ } catch (error) {
57
+ console.error('An error occurred:', error.message);
58
+ }
59
+ });
60
+
61
+ program
62
+ .command('install <plugin>')
63
+ .description('Installs Hive plugin')
64
+ .action(async (plugin) => {
65
+ try {
66
+ const destDir = process.cwd();
67
+
68
+ await downloadDirectory(plugin);
69
+ } catch (error) {
70
+ console.error('An error occurred:', error.message);
71
+ }
72
+ });
73
+
74
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@paralect/hive",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "hive": "cli/cli.js"
7
+ "hive": "cli/hive.js"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -14,16 +14,21 @@
14
14
  "@koa/multer": "3.0.0",
15
15
  "@koa/router": "10.1.1",
16
16
  "@paralect/node-mongo": "2.1.1",
17
+ "@react-email/components": "^0.0.20",
18
+ "@react-email/render": "^0.0.16",
17
19
  "@sendgrid/mail": "7.6.1",
18
20
  "@socket.io/redis-adapter": "7.1.0",
19
21
  "@socket.io/redis-emitter": "4.1.1",
20
22
  "app-module-path": "2.2.0",
21
23
  "aws-sdk": "2.1080.0",
24
+ "axios": "^1.7.2",
22
25
  "bcryptjs": "2.4.3",
26
+ "commander": "^12.1.0",
23
27
  "dotenv": "16.0.0",
24
28
  "eslint-config-prettier": "8.5.0",
29
+ "fs-extra": "^11.2.0",
25
30
  "handlebars": "4.7.7",
26
- "joi": "17.6.0",
31
+ "joi": "^17.13.3",
27
32
  "koa": "2.13.4",
28
33
  "koa-bodyparser": "4.3.0",
29
34
  "koa-helmet": "6.1.0",
@@ -37,11 +42,13 @@
37
42
  "moment-duration-format": "2.3.2",
38
43
  "multer": "1.4.4",
39
44
  "node-schedule": "2.1.0",
45
+ "nodemailer": "^6.9.14",
40
46
  "nodemon": "2.0.15",
41
47
  "prettier": "2.6.2",
42
48
  "psl": "1.8.0",
43
49
  "redis": "3.1.2",
44
50
  "require-dir": "1.2.0",
51
+ "slug": "^9.1.0",
45
52
  "socket.io": "4.4.1",
46
53
  "socket.io-emitter": "3.2.0",
47
54
  "tail": "2.2.4",
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": ["@babel/preset-env", "@babel/preset-react"]
3
+ }
@@ -1,13 +1,22 @@
1
- FROM --platform=linux/amd64 node:16.13.1-alpine3.13 as base
1
+ FROM node:16.13.1-alpine3.13 as base
2
2
  RUN apk add --no-cache python3 py3-pip
3
3
 
4
- # On staging containers running in development mode
5
- ARG NODE_ENV=development
4
+ ENV NODE_ENV=production
5
+ ENV APP_ENV=production
6
6
 
7
- ARG APP_ENV
8
- ENV NODE_ENV=$NODE_ENV
9
- ENV APP_ENV=$APP_ENV
7
+ WORKDIR /app
8
+ EXPOSE 3001
9
+ COPY ["./package*.json", "/app/"]
10
10
 
11
- WORKDIR /project
11
+ RUN npm set progress=false && npm config set depth 0
12
12
 
13
- CMD npm run dev 2>&1 | tee /project/logs/log.txt
13
+ RUN npm set-script prepare ""
14
+
15
+ RUN npm ci --only=production --quiet
16
+
17
+ COPY ./ ./
18
+
19
+ RUN mkdir -p /project/logs
20
+ RUN touch /project/logs/log.txt
21
+
22
+ CMD npm start 2>&1 | tee /project/logs/log.txt
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ cd "$( dirname "${BASH_SOURCE[0]}" )"
3
+ cd ..
4
+
5
+ node ./deploy/script/src/index.js
@@ -0,0 +1,6 @@
1
+ apiVersion: v2
2
+ name: hive-api
3
+ description: A Helm chart for Kubernetes
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: 1.16.0
@@ -0,0 +1,3 @@
1
+ nodePool: pool-app
2
+ containerRegistry: paralect/hive-api
3
+ port: 3001
@@ -0,0 +1,43 @@
1
+ kind: Deployment
2
+ apiVersion: apps/v1
3
+ metadata:
4
+ name: {{ .Values.service }}
5
+ labels:
6
+ app: {{ .Values.service }}
7
+ spec:
8
+ replicas: 1
9
+ selector:
10
+ matchLabels:
11
+ app: {{ .Values.service }}
12
+ template:
13
+ metadata:
14
+ labels:
15
+ app: {{ .Values.service }}
16
+ spec:
17
+ restartPolicy: Always
18
+ containers:
19
+ - name: {{ .Values.service }}
20
+ image: {{ .Values.containerRegistry }}:{{ .Values.imagesVersion }}
21
+ env:
22
+ - name: PROJECT_ID
23
+ value: {{ .Values.projectId }}
24
+ env:
25
+ - name: MONGODB_URI
26
+ value: {{ .Values.mongoDbUri }}
27
+ imagePullPolicy: Always
28
+ livenessProbe:
29
+ httpGet:
30
+ path: /health
31
+ port: {{ .Values.port }}
32
+ initialDelaySeconds: 300
33
+ periodSeconds: 10
34
+ ports:
35
+ - containerPort: {{ .Values.port }}
36
+ protocol: TCP
37
+ nodeSelector:
38
+ doks.digitalocean.com/node-pool: {{ .Values.nodePool }}
39
+ strategy:
40
+ type: RollingUpdate
41
+ rollingUpdate:
42
+ maxUnavailable: 0
43
+ maxSurge: 1
@@ -0,0 +1,26 @@
1
+ kind: Ingress
2
+ apiVersion: networking.k8s.io/v1
3
+ metadata:
4
+ name: {{ .Values.service }}
5
+ labels:
6
+ app: {{ .Values.service }}
7
+ annotations:
8
+ nginx.ingress.kubernetes.io/proxy-read-timeout: "180"
9
+ nginx.ingress.kubernetes.io/proxy-body-size: "20m"
10
+ external-dns.alpha.kubernetes.io/hostname: {{ first .Values.domain }}
11
+ external-dns.alpha.kubernetes.io/ttl: "120" #optional
12
+ spec:
13
+ ingressClassName: nginx
14
+ rules:
15
+ {{- range $domain := .Values.domain }}
16
+ - host: {{ $domain }}
17
+ http:
18
+ paths:
19
+ - path: /
20
+ pathType: Prefix
21
+ backend:
22
+ service:
23
+ name: {{ $.Values.service }}
24
+ port:
25
+ number: {{ $.Values.port }}
26
+ {{- end}}
@@ -0,0 +1,14 @@
1
+
2
+ kind: Service
3
+ apiVersion: v1
4
+ metadata:
5
+ name: {{ .Values.service }}
6
+ labels:
7
+ app: {{ .Values.service }}
8
+ spec:
9
+ type: ClusterIP
10
+ selector:
11
+ app: {{ .Values.service }}
12
+ ports:
13
+ - protocol: TCP
14
+ port: {{ .Values.port }}
@@ -0,0 +1,39 @@
1
+ FROM node:16.13.1-alpine3.13
2
+
3
+ RUN apk add docker
4
+
5
+ ARG VCS_REF
6
+ ARG BUILD_DATE
7
+
8
+ # Metadata
9
+ LABEL org.label-schema.vcs-ref=$VCS_REF \
10
+ org.label-schema.name="helm-kubectl" \
11
+ org.label-schema.url="https://hub.docker.com/r/dtzar/helm-kubectl/" \
12
+ org.label-schema.vcs-url="https://github.com/dtzar/helm-kubectl" \
13
+ org.label-schema.build-date=$BUILD_DATE
14
+
15
+ # Note: Latest version of kubectl may be found at:
16
+ # https://github.com/kubernetes/kubernetes/releases
17
+ ENV KUBE_LATEST_VERSION="v1.22.4"
18
+
19
+ # Note: Latest version of helm may be found at:
20
+ # https://github.com/kubernetes/helm/releases
21
+ ENV HELM_VERSION="v3.7.1"
22
+
23
+ RUN apk add --no-cache ca-certificates bash git openssh curl \
24
+ && wget -q https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -O /usr/local/bin/kubectl \
25
+ && chmod +x /usr/local/bin/kubectl \
26
+ && wget -q https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz -O - | tar -xzO linux-amd64/helm > /usr/local/bin/helm \
27
+ && chmod +x /usr/local/bin/helm
28
+
29
+ WORKDIR /home/node/app
30
+
31
+ ADD ./deploy/script/package.json \
32
+ ./deploy/script/package-lock.json \
33
+ ./deploy/script/
34
+
35
+ RUN npm i --prefix ./deploy/script --progress=false --no-audit --production
36
+
37
+ ADD ./ ./
38
+
39
+ CMD node ./deploy/script/src/index.js