samanbayaka 0.0.9 → 0.0.10
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/README.md +136 -74
- package/bash/sbk.sh +5 -2
- package/commit-hash.mjs +1 -1
- package/config/broker.mjs +2 -0
- package/config/logger.mjs +21 -21
- package/helper/file/esm-loading.mjs +198 -145
- package/helper/logger/pino.mjs +39 -0
- package/helper/utility/error-handler.mjs +280 -0
- package/helper/validator/AjvValidator.mjs +1 -1
- package/index.mjs +72 -88
- package/package.json +11 -5
- package/services/about/index.mjs +38 -0
- package/services/demo/create-user.mjs +43 -0
- package/services/demo/index.mjs +4 -0
- package/services/demo/mail.service.mjs +10 -0
- package/services/demo/role.service.mjs +18 -0
- package/services/demo/sms.service.mjs +10 -0
- package/services/demo/user.service.mjs +43 -0
- package/services/gateway/index.mjs +16 -20
- package/config/server.mjs +0 -36
- package/helper/utility/env-errors-handler.mjs +0 -32
- package/helper/utility/format-errors.mjs +0 -72
- package/helper/utility/node-argv.mjs +0 -55
- package/services/system/index.mjs +0 -220
- package/services/system/metrics.mjs +0 -49
- /package/services/{system → demo}/scalar.mjs +0 -0
- /package/services/{system → demo}/sw-stats-mw.mjs +0 -0
package/README.md
CHANGED
|
@@ -1,97 +1,159 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center" style="margin: 0;">
|
|
2
|
+
<img style="background-color: #000; border-radius: 30%;" src="https://unpkg.com/samanbayaka/public/favicon.svg" width="256" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
$echo $SBK_CONFIG_PATH
|
|
5
|
-
$echo export SBK_PORT=87xx for gateway services
|
|
5
|
+
# samanbayaka
|
|
6
6
|
|
|
7
|
+
This project is a modular, production-ready microservices framework built with Moleculer and Moleculer-Web latest, using NATS as a high-performance messaging transporter and AJV for robust schema validation. It provides a scalable foundation for developing distributed Node.js applications, emphasizing fault tolerance, clean architecture, and efficient service communication. The system is designed to support flexible orchestration of services while maintaining strong validation and reliability across components.
|
|
7
8
|
|
|
9
|
+
[](https://www.npmjs.com/package/samanbayaka)
|
|
10
|
+
[](LICENSE)
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
# Features
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
- Moleculer-based microservices architecture
|
|
15
|
+
- NATS transporter for high-performance messaging
|
|
16
|
+
- Redpanda transporter for persistent,robust and scalability.
|
|
17
|
+
- In memory L1 cache and Redis cache for L2
|
|
18
|
+
- Schema validation using AJV
|
|
19
|
+
- Dynamic service loading (Gateway / Feature / Demo)
|
|
20
|
+
- Graceful shutdown handling (SIGINT, SIGTERM)
|
|
21
|
+
- Centralized error handling middleware
|
|
22
|
+
- REPL support for debugging
|
|
23
|
+
- Config-driven initialization
|
|
24
|
+
- Metrics and Log shipping for Grafana
|
|
12
25
|
|
|
13
|
-
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
14
26
|
|
|
15
|
-
## Add your files
|
|
16
27
|
|
|
17
|
-
|
|
18
|
-
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
28
|
+
# Installation
|
|
19
29
|
|
|
30
|
+
```bash
|
|
31
|
+
pnpm install samanbayaka
|
|
20
32
|
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
# Prerequisites
|
|
34
|
+
It is assumed that NATS, Redpanda, and Redis are installed and properly configured. All services should be discoverable through the /etc/hosts file.
|
|
35
|
+
#### Minimum required Node.js version: >= 22.x.x
|
|
36
|
+
```bash
|
|
37
|
+
node -v
|
|
38
|
+
nvm use 22
|
|
25
39
|
```
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
46
|
-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
47
|
-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
48
|
-
|
|
49
|
-
***
|
|
50
|
-
|
|
51
|
-
# Editing this README
|
|
52
|
-
|
|
53
|
-
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
54
|
-
|
|
55
|
-
## Suggestions for a good README
|
|
56
|
-
|
|
57
|
-
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
58
|
-
|
|
59
|
-
## Name
|
|
60
|
-
Choose a self-explaining name for your project.
|
|
61
|
-
|
|
62
|
-
## Description
|
|
63
|
-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
64
|
-
|
|
65
|
-
## Badges
|
|
66
|
-
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
41
|
+
#### Environment variables
|
|
42
|
+
To configure all required environment variables, copy the <your_project_name>/bash/sbk.sh file into the /etc/profile.d/ directory and update the environment variable values as needed. Before copying, ensure that your current working directory is the project directory.
|
|
43
|
+
```bash
|
|
44
|
+
pwd
|
|
45
|
+
sudo cp bash/sbk.sh /etc/profile.d/
|
|
46
|
+
source /etc/profile.d/sbk.sh
|
|
47
|
+
```
|
|
48
|
+
Optionally, you may verify the set environment variables.
|
|
49
|
+
```bash
|
|
50
|
+
echo $SBK_PORT
|
|
51
|
+
```
|
|
52
|
+
#### Configuration files
|
|
53
|
+
Create a directory to store the configuration files, then copy all configuration files from the current project path into this directory and update them as needed. Before copying, ensure that your current working directory is the project directory.
|
|
54
|
+
```bash
|
|
55
|
+
pwd
|
|
56
|
+
sudo mkdir -p /usr/local/etc/<your_project_name>
|
|
57
|
+
sudo cp config/*.* /usr/local/etc/<your_project_name>
|
|
58
|
+
```
|
|
67
59
|
|
|
68
|
-
## Visuals
|
|
69
|
-
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
# Usage
|
|
62
|
+
#### Create a service, gateway
|
|
63
|
+
The gateway is an important service that exposes all endpoints as REST APIs. At least one Gateway service is mandatory in the project.
|
|
64
|
+
```bash
|
|
65
|
+
mkdir gateway
|
|
66
|
+
cd gateway
|
|
67
|
+
npm init -y
|
|
68
|
+
pnpm install samanbayaka
|
|
69
|
+
touch index.mjs
|
|
70
|
+
```
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
Open and edit the index.mjs file as follows
|
|
73
|
+
```bash
|
|
74
|
+
import sbk from "samanbayaka"
|
|
75
|
+
await sbk.loadGatewayService()
|
|
76
|
+
```
|
|
77
|
+
Run the service, gateway
|
|
78
|
+
```bash
|
|
79
|
+
node index.mjs
|
|
80
|
+
```
|
|
76
81
|
|
|
77
|
-
## Support
|
|
78
|
-
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
#### Create your endpoints as a feature service, such as a test service
|
|
84
|
+
```bash
|
|
85
|
+
mkdir test
|
|
86
|
+
cd test
|
|
87
|
+
npm init -y
|
|
88
|
+
pnpm install samanbayaka
|
|
89
|
+
touch index.mjs
|
|
90
|
+
```
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
Open and edit the index.mjs file as follows
|
|
93
|
+
```bash
|
|
94
|
+
import sbk from "samanbayaka"
|
|
95
|
+
await sbk.loadFeatureService.mainBus({
|
|
96
|
+
name: "test",
|
|
97
|
+
version: "v1",
|
|
98
|
+
|
|
99
|
+
actions: {
|
|
100
|
+
hello: {
|
|
101
|
+
rest: {
|
|
102
|
+
method: "GET",
|
|
103
|
+
path: "/hello"
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Enable caching to this action
|
|
108
|
+
*/
|
|
109
|
+
cache: {
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* These cache entries will be expired after 5 seconds instead of 30.
|
|
113
|
+
*/
|
|
114
|
+
ttl: 2*60
|
|
115
|
+
},
|
|
116
|
+
handler(ctx){
|
|
117
|
+
return "Hello Samanbayaka"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
welcome: {
|
|
121
|
+
rest: "GET /welcome",
|
|
122
|
+
handler(ctx) {
|
|
123
|
+
return `Welcome, ${ctx.params.query?.name || "Guest"} - ${ctx.broker.nodeID}`
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
createUser
|
|
127
|
+
},
|
|
128
|
+
})
|
|
85
129
|
|
|
86
|
-
|
|
130
|
+
```
|
|
131
|
+
Run the service, test
|
|
132
|
+
```bash
|
|
133
|
+
node index.mjs
|
|
134
|
+
```
|
|
135
|
+
# Demo
|
|
136
|
+
You can also run the demo service to better understand how the system works.
|
|
137
|
+
```bash
|
|
138
|
+
mkdir demo
|
|
139
|
+
cd demo
|
|
140
|
+
npm init -y
|
|
141
|
+
pnpm install samanbayaka
|
|
142
|
+
touch demo.mjs
|
|
143
|
+
```
|
|
144
|
+
Open and edit the demo.mjs file as follows
|
|
145
|
+
```bash
|
|
146
|
+
import sbk from "samanbayaka"
|
|
147
|
+
await sbk.loadDemo()
|
|
148
|
+
```
|
|
149
|
+
Run the service, demo
|
|
150
|
+
```bash
|
|
151
|
+
node demo.mjs
|
|
152
|
+
```
|
|
87
153
|
|
|
88
|
-
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
89
154
|
|
|
90
|
-
## Authors and acknowledgment
|
|
91
|
-
Show your appreciation to those who have contributed to the project.
|
|
92
155
|
|
|
93
|
-
## License
|
|
94
|
-
For open source projects, say how it is licensed.
|
|
95
156
|
|
|
96
|
-
|
|
97
|
-
|
|
157
|
+
<p align="center" style="margin-top: 100px;">
|
|
158
|
+
<img src="https://moleculer.services/images/banner.png" alt="Moleculer Logo" width="600">
|
|
159
|
+
</p>
|
package/bash/sbk.sh
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
###############################################################################
|
|
6
6
|
|
|
7
7
|
##Configurations files path
|
|
8
|
-
|
|
8
|
+
export SBK_CONFIG_PATH="/usr/local/etc/your_folder"
|
|
9
9
|
|
|
10
10
|
##web server port 8760-8769
|
|
11
|
-
|
|
11
|
+
export SBK_PORT=8765
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
export SBK_LOG_LEVEL=info
|
package/commit-hash.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const COMMIT_HASH = '
|
|
1
|
+
export const COMMIT_HASH = '95e0f1a';
|
package/config/broker.mjs
CHANGED
package/config/logger.mjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
/*logger.mjs*/
|
|
2
2
|
export default Object.freeze({
|
|
3
|
-
type: "
|
|
3
|
+
type: "Pino",
|
|
4
4
|
options: {
|
|
5
5
|
/**
|
|
6
6
|
* Logging level
|
|
7
7
|
*/
|
|
8
8
|
level: "info",
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
colors: true,
|
|
10
|
+
// /**
|
|
11
|
+
// * Using colors on the output
|
|
12
|
+
// */
|
|
13
|
+
// colors: true,
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
moduleColors: true,
|
|
15
|
+
// /**
|
|
16
|
+
// * Print module names with different colors (like docker-compose for containers)
|
|
17
|
+
// */
|
|
18
|
+
// moduleColors: true,
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
formatter: "full",
|
|
20
|
+
// /**
|
|
21
|
+
// * Line formatter. It can be "json", "short", "simple", "full", a `Function` or a template string like "{timestamp} {level} {nodeID}/{mod}: {msg}"
|
|
22
|
+
// */
|
|
23
|
+
// formatter: "full",
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
objectPrinter: null,
|
|
25
|
+
// /**
|
|
26
|
+
// * Custom object printer. If not defined, it uses the `util.inspect` method.
|
|
27
|
+
// */
|
|
28
|
+
// objectPrinter: null,
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
autoPadding: false
|
|
30
|
+
// /**
|
|
31
|
+
// * Auto-padding the module name in order to messages begin at the same column.
|
|
32
|
+
// */
|
|
33
|
+
// autoPadding: false
|
|
34
34
|
}
|
|
35
35
|
})
|