samanbayaka 0.0.2

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 ADDED
@@ -0,0 +1,97 @@
1
+ # samanbayaka
2
+
3
+ ##check environment variable before start the server
4
+ $echo $SBK_CONFIG_PATH
5
+ $echo export SBK_PORT=87xx for gateway services
6
+
7
+
8
+
9
+ ## Getting started
10
+
11
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
12
+
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
+
15
+ ## Add your files
16
+
17
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
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:
19
+
20
+ ```
21
+ cd existing_repo
22
+ git remote add origin https://gitlab.com/dalal.suvendu/samanbayaka.git
23
+ git branch -M main
24
+ git push -uf origin main
25
+ ```
26
+
27
+ ## Integrate with your tools
28
+
29
+ - [ ] [Set up project integrations](https://gitlab.com/dalal.suvendu/samanbayaka/-/settings/integrations)
30
+
31
+ ## Collaborate with your team
32
+
33
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
34
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
35
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
36
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
37
+ - [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
38
+
39
+ ## Test and Deploy
40
+
41
+ Use the built-in continuous integration in GitLab.
42
+
43
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
44
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
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.
67
+
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
+
71
+ ## Installation
72
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
73
+
74
+ ## Usage
75
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
76
+
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
+
80
+ ## Roadmap
81
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
82
+
83
+ ## Contributing
84
+ State if you are open to contributions and what your requirements are for accepting them.
85
+
86
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
87
+
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
+
90
+ ## Authors and acknowledgment
91
+ Show your appreciation to those who have contributed to the project.
92
+
93
+ ## License
94
+ For open source projects, say how it is licensed.
95
+
96
+ ## Project status
97
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
package/bash/sbk.sh ADDED
@@ -0,0 +1,11 @@
1
+ ###############################################################################
2
+ # Environment Variables
3
+ # To set permanent environment variables for all users, create an sbk.sh file in the path /etc/profile.d/
4
+ # Environment Variables will be set after a reboot or execute $source /etc/profile.d/sbk.sh
5
+ ###############################################################################
6
+
7
+ ##Configurations files path
8
+ $export SBK_CONFIG_PATH="/usr/local/etc/your_folder"
9
+
10
+ ##web service port 8760-8769
11
+ $export SBK_PORT=8765
@@ -0,0 +1,159 @@
1
+ /*broker.mjs*/
2
+
3
+ export default Object.freeze({
4
+ /**
5
+ * Namespace of nodes to segment your nodes on the same network
6
+ */
7
+ namespace: "prod",
8
+
9
+ /**
10
+ * Timeouts
11
+ */
12
+ requestTimeout: 10 * 1000,
13
+
14
+ /**
15
+ * Retry policy
16
+ */
17
+ retryPolicy: {
18
+ enabled: true,
19
+ retries: 5,
20
+ delay: 100,
21
+ maxDelay: 2000,
22
+ factor: 2,
23
+ check: err => err && !!err.retryable
24
+ },
25
+
26
+ /**
27
+ * Controls whether ctx.params is cloned or passed by reference
28
+ */
29
+ contextParamsCloning: false,
30
+
31
+ /**
32
+ * Limits nested service call depth
33
+ */
34
+ maxCallLevel: 100,
35
+
36
+ /**
37
+ * How often (seconds) a node sends heartbeat signals
38
+ */
39
+ heartbeatInterval: 5,
40
+ heartbeatTimeout: 15,
41
+
42
+ /**
43
+ * When your service shuts down
44
+ */
45
+ tracking: {
46
+ enabled: true,
47
+ shutdownTimeout: 10 * 1000,
48
+ },
49
+
50
+ /**
51
+ * Controls whether Moleculer’s built-in load balancer is used
52
+ */
53
+ disableBalancer: false,
54
+
55
+ /**
56
+ * Load balancing
57
+ */
58
+ registry: {
59
+ strategy: "RoundRobin",
60
+ preferLocal: true
61
+ },
62
+
63
+ /**
64
+ * Circuit breaker in Moleculer—a critical pattern to prevent
65
+ * cascading failures in distributed systems
66
+ */
67
+ circuitBreaker: {
68
+ enabled: true,
69
+ threshold: 0.5,
70
+ minRequestCount: 20,
71
+ windowTime: 60,
72
+ halfOpenTime: 10 * 1000
73
+ },
74
+
75
+ /**
76
+ * Bulkhead (prevent overload)
77
+ */
78
+ bulkhead: {
79
+ enabled: true,
80
+ concurrency: 50,
81
+ maxQueueSize: 200
82
+ },
83
+
84
+ /**
85
+ * Metrics (optional but recommended)
86
+ */
87
+ // metrics: {
88
+ // enabled: true,
89
+ // reporter: [
90
+ // {
91
+ // type: "Prometheus",
92
+ // options: {
93
+ // port: 3030
94
+ // }
95
+ // }
96
+ // ]
97
+ // },
98
+
99
+ /**
100
+ * Transit options control the internal messaging layer of Moleculer
101
+ */
102
+ transit: {
103
+ maxQueueSize: 50 * 1000,
104
+ disableReconnect: false,
105
+ disableVersionCheck: false,
106
+ packetLogFilter: ["HEARTBEAT"]
107
+ },
108
+
109
+ uidGenerator: null,
110
+
111
+ errorHandler: null,
112
+
113
+ // cacher: "MemoryLRU",
114
+
115
+ /**
116
+ * Serializer
117
+ */
118
+ serializer: "MsgPack",
119
+
120
+ validator: true,
121
+ errorRegenerator: null,
122
+
123
+ // metrics: {
124
+ // enabled: true,
125
+ // reporter: [
126
+ // "Console"
127
+ // ]
128
+ // },
129
+
130
+ // tracing: {
131
+ // enabled: true,
132
+ // exporter: [
133
+ // "Console"
134
+ // ]
135
+ // },
136
+
137
+ internalServices: true,
138
+ internalMiddlewares: true,
139
+
140
+ hotReload: true,
141
+
142
+ // middlewares: ["MyMiddleware"],
143
+
144
+ replOptions: {
145
+ delimiter: "mol # ",
146
+ customCommands: [
147
+ {
148
+ command: "hello <name>",
149
+ action(broker, args) {
150
+ // ...
151
+ }
152
+ }
153
+ ]
154
+ },
155
+
156
+ metadata: {
157
+ // region: "eu-west1"
158
+ },
159
+ })
@@ -0,0 +1,54 @@
1
+ /*kafkajs.mjs*/
2
+ // export default Object.freeze({
3
+ // prefix: "SBK",
4
+ // client: {
5
+ // clientId: "moleculer-kafkajs",
6
+ // brokers: ["redpanda:9092"],
7
+ // connectionTimeout: 3000,
8
+ // requestTimeout: 25000,
9
+ // enforceRequestTimeout: false,
10
+ // retry: {
11
+ // maxRetryTime: 30000,
12
+ // initialRetryTime: 300,
13
+ // factor: 0.2,
14
+ // multiplier: 2,
15
+ // retries: 5
16
+ // },
17
+ // producer: {
18
+ // idempotent: true,
19
+ // maxInFlightRequests: 1,
20
+ // },
21
+ // logLevel: "INFO",
22
+ // }
23
+ // })
24
+
25
+
26
+ export default Object.freeze({
27
+ type: "Kafka",
28
+ options: {
29
+ // host: "localhost:9092", // Your Kafka broker address
30
+ client: {
31
+ clientId: "moleculer-cluster",
32
+ brokers: ["redpanda:9092"],
33
+ connectionTimeout: 3000,
34
+ requestTimeout: 25000,
35
+ enforceRequestTimeout: false,
36
+ retry: {
37
+ maxRetryTime: 30000,
38
+ initialRetryTime: 300,
39
+ factor: 0.2,
40
+ multiplier: 2,
41
+ retries: 5
42
+ }
43
+ },
44
+ producer: {
45
+ idempotent: true,
46
+ maxInFlightRequests: 1,
47
+ },
48
+ consumer: {
49
+ groupId: "moleculer-group"
50
+ },
51
+ logLevel: "INFO",
52
+ }
53
+ // Ensure protocol v5 is active (default in 0.15.0-beta1)
54
+ })
@@ -0,0 +1,35 @@
1
+ /*logger.mjs*/
2
+ export default Object.freeze({
3
+ type: "Console",
4
+ options: {
5
+ /**
6
+ * Logging level
7
+ */
8
+ level: "info",
9
+
10
+ /**
11
+ * Using colors on the output
12
+ */
13
+ colors: true,
14
+
15
+ /**
16
+ * Print module names with different colors (like docker-compose for containers)
17
+ */
18
+ moduleColors: true,
19
+
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
+
25
+ /**
26
+ * Custom object printer. If not defined, it uses the `util.inspect` method.
27
+ */
28
+ objectPrinter: null,
29
+
30
+ /**
31
+ * Auto-padding the module name in order to messages begin at the same column.
32
+ */
33
+ autoPadding: false
34
+ }
35
+ })
@@ -0,0 +1,26 @@
1
+ /*nats.mjs*/
2
+ export default Object.freeze({
3
+ type: "NATS",
4
+ options: {
5
+ /**
6
+ * High availability
7
+ */
8
+ servers: [
9
+ "nats://nats:4222",
10
+ ],
11
+
12
+ /**
13
+ * Reconnect settings
14
+ */
15
+ reconnect: true,
16
+ maxReconnectAttempts: -1,
17
+ reconnectTimeWait: 2000,
18
+
19
+ /**
20
+ * Performance
21
+ */
22
+ maxInFlight: 1000,
23
+ timeout: 5000,
24
+
25
+ }
26
+ })
@@ -0,0 +1,26 @@
1
+ /*server.mjs*/
2
+ const PORT = process.env.SBK_PORT || 8765
3
+
4
+ export default Object.freeze({
5
+ PORT,
6
+ assetPath: 'public',
7
+ servicesDir: 'services',
8
+ serviceMain: "index.mjs",
9
+
10
+ /**
11
+ * base url of OpenAPI spec
12
+ */
13
+ URL_SERVERS: [
14
+ {url: `http://localhost:${PORT}`, description: "Development"}
15
+ ],
16
+
17
+ /**
18
+ * url of Redpanda web client
19
+ */
20
+ URL_REDPANDA_WEB_UI: "http://redpanda.web.ui:8080",
21
+
22
+ /**
23
+ * swagger stats route
24
+ */
25
+ SW_STATS_RT: "/swagger-stats",
26
+ })
package/gateway.mjs ADDED
@@ -0,0 +1,140 @@
1
+ /*index.mjs*/
2
+ import path from "path"
3
+ import url from "url"
4
+
5
+ import ApiGateway from "moleculer-web"
6
+ import OpenApi from "moleculer-auto-openapi"
7
+ import cookieParser from "cookie-parser"
8
+ import helmet from "helmet"
9
+ import compression from "compression"
10
+
11
+ import {sbk} from "./index.mjs"
12
+ import {
13
+ getConfig,
14
+ assetPath
15
+ } from '#hFil/esm-loading.mjs'
16
+ import {formatApiGwErrors} from '#hUti/format-errors.mjs'
17
+
18
+ const CONFIG = await getConfig('server')
19
+
20
+
21
+ await sbk ('nats', {
22
+ name: "gateway",
23
+ mixins: [
24
+ ApiGateway,
25
+ ],
26
+
27
+ settings: {
28
+ port: CONFIG.PORT,
29
+
30
+ /**
31
+ * Middleware mode (for ExpressJS)
32
+ */
33
+ middleware: false,
34
+
35
+ /**
36
+ * Exposed global path prefix
37
+ */
38
+ path: "/sbk",
39
+
40
+ /**
41
+ * Global middlewares. Applied to all routes.
42
+ */
43
+ use: [
44
+ compression(),
45
+ cookieParser(),
46
+ helmet(),
47
+ ],
48
+
49
+ cors: {
50
+ methods: ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
51
+ origin: "*",
52
+ },
53
+
54
+
55
+ routes: [
56
+ /**
57
+ * API routes
58
+ */
59
+ {
60
+ path: "/api",
61
+ whitelist: [
62
+ /**
63
+ * Access any actions except 'system' service
64
+ */
65
+ /^(?!(gateway|system)\.)\w+(?:\.\w+)*$/
66
+ ],
67
+ autoAliases: true,
68
+ mergeParams: false,
69
+ mappingPolicy: "restrict",
70
+ logging: true,
71
+
72
+ /**
73
+ * Use bodyparser module
74
+ */
75
+ bodyParsers: {
76
+ json: true,
77
+ urlencoded: { extended: true }
78
+ },
79
+ },
80
+ ],
81
+
82
+
83
+ // /**
84
+ // * Logging request parameters with 'info' level
85
+ // */
86
+ logRequestParams: null,
87
+
88
+
89
+ // /**
90
+ // * Logging response data with 'debug' level
91
+ // */
92
+ logResponseData: false,
93
+
94
+
95
+ /**
96
+ * global assets location
97
+ */
98
+ assets: {
99
+ /**
100
+ * Root folder of assets
101
+ */
102
+ folder: assetPath.rootFolder,
103
+
104
+ /**
105
+ * Further options to `serve-static` module
106
+ */
107
+ options: {}
108
+ },
109
+
110
+
111
+ /**
112
+ * Global error handler
113
+ */
114
+ onError(req, res, err) {
115
+
116
+ formatApiGwErrors(req, res, err)
117
+
118
+ /**
119
+ * Custom logging
120
+ */
121
+ this.logResponse(req, res)
122
+ }
123
+
124
+ },
125
+
126
+
127
+
128
+ methods: {
129
+ /**
130
+ * This overrides the errorHandler method found in the official file
131
+ */
132
+ errorHandler(req, res, err) {
133
+ // // don't log client side errors unless it's configured
134
+ // if (this.settings.log4XXResponses || (err && !_.inRange(err.code, 400, 500))) {
135
+ // this.logger.error(" Request error!", err.name, ":", err.message, "\n", err.stack, "\nData:", err.data);
136
+ // }
137
+ this.sendError(req, res, err)
138
+ }
139
+ },
140
+ })