@rpcbase/server 0.223.0 → 0.225.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/cli/run_native.js CHANGED
@@ -137,7 +137,7 @@ const get_processes = (args) => {
137
137
  "-E", `http.port=${env.SEARCH_INDEX_PORT}`,
138
138
  ...(is_production ? [] : [
139
139
  "-E", `http.cors.enabled=true`,
140
- // "-E", `http.cors.allow-origin=http://localhost:8080`,
140
+ "-E", `http.cors.allow-origin=http://localhost:8080`,
141
141
  ]),
142
142
  "-E", `path.data=${data_dir}`,
143
143
  "-E", "discovery.type=single-node",
package/express/index.js CHANGED
@@ -3,6 +3,7 @@ const debug = require("debug")
3
3
  const express = require("express")
4
4
  const body_parser = require("body-parser")
5
5
  const request_ip = require("request-ip")
6
+ const Sentry = require("@sentry/node")
6
7
 
7
8
  // functionality middlewares
8
9
  const auth = require("../src/auth")
@@ -14,7 +15,10 @@ const custom_cors = require("./custom_cors")
14
15
  const log = debug("rb:server")
15
16
 
16
17
  const is_production = process.env.IS_PRODUCTION === "yes"
17
- const {APP_DOMAIN, CLIENT_PORT} = process.env
18
+ const is_development = process.env.NODE_ENV === "development"
19
+ const {APP_DOMAIN, SENTRY_DSN, CLIENT_PORT} = process.env
20
+
21
+ const has_sentry = !!SENTRY_DSN
18
22
 
19
23
  // TODO: document this
20
24
  // we could have a larger size, but it's good practice to keep it small to prevent body upload ddos attacks
@@ -24,8 +28,34 @@ const BODY_MAX_SIZE_MB = 80
24
28
  log("server is production:", JSON.stringify(is_production))
25
29
 
26
30
  module.exports = () => {
31
+
27
32
  const app = express()
28
33
 
34
+ if (has_sentry && !is_development) {
35
+ Sentry.init({
36
+ dsn: SENTRY_DSN,
37
+ integrations: [
38
+ // enable HTTP calls tracing
39
+ new Sentry.Integrations.Http({
40
+ tracing: true
41
+ }),
42
+ // enable Express.js middleware tracing
43
+ new Sentry.Integrations.Express({
44
+ app
45
+ }),
46
+ ],
47
+ // Performance Monitoring
48
+ tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!,
49
+ });
50
+
51
+ // Trace incoming requests
52
+ app.use(Sentry.Handlers.requestHandler());
53
+ app.use(Sentry.Handlers.tracingHandler());
54
+
55
+ }
56
+
57
+
58
+
29
59
  app.use(request_ip.mw())
30
60
 
31
61
  app.use(body_parser.json({limit: `${BODY_MAX_SIZE_MB}mb`}))
package/mailer/index.js CHANGED
@@ -4,20 +4,23 @@ const postmark = require("postmark")
4
4
 
5
5
  const log = debug("rb:mailer")
6
6
 
7
- const {POSTMARK_API_KEY, IS_PRODUCTION} = process.env
7
+ const {POSTMARK_API_KEY, IS_PRODUCTION, RB_FORCE_SEND_EMAILS} = process.env
8
8
 
9
9
  const is_production = IS_PRODUCTION === "yes"
10
+ const force_send = RB_FORCE_SEND_EMAILS === "yes"
11
+
10
12
  log("mailer, is_production:", is_production, "env:", JSON.stringify(IS_PRODUCTION))
11
13
 
12
14
  let client
13
15
 
14
- if (is_production && typeof POSTMARK_API_KEY === "string" && POSTMARK_API_KEY.trim() !== "") {
16
+ if (force_send || is_production && typeof POSTMARK_API_KEY === "string" && POSTMARK_API_KEY.trim() !== "") {
15
17
  client = new postmark.ServerClient(POSTMARK_API_KEY)
16
18
  } else {
17
19
  client = {
18
20
  sendEmail: async(payload) => {
19
21
  log("sendEmail disabled when not in production")
20
22
  log("From:", payload.From, "To:", payload.To, "Subject:", payload.Subject)
23
+ return {Message: "OK"}
21
24
  }
22
25
  }
23
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.223.0",
3
+ "version": "0.225.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -13,6 +13,7 @@
13
13
  "@rpcbase/access-control": "0.27.0",
14
14
  "@rpcbase/agent": "0.30.0",
15
15
  "@rpcbase/std": "0.9.0",
16
+ "@sentry/node": "7.64.0",
16
17
  "bluebird": "3.7.2",
17
18
  "body-parser": "1.20.2",
18
19
  "bull": "4.11.2",
@@ -6,7 +6,7 @@ const op_names = {
6
6
  update: "update",
7
7
  }
8
8
 
9
- const dispatch_queue = (queue, model_name, op, doc) => {
9
+ const dispatch_queue = (queue, model_name, op, doc, update_description) => {
10
10
  const instance = queue.instance()
11
11
 
12
12
  const tasks = queue.get_tasks()
@@ -16,9 +16,7 @@ const dispatch_queue = (queue, model_name, op, doc) => {
16
16
  // skip if there's no matching handler
17
17
  if (!Object.keys(tasks).includes(handler_name)) return
18
18
 
19
- // console.log("handler_name", handler_name)
20
-
21
- queue.add(handler_name, {doc}, {
19
+ queue.add(handler_name, {doc, update_description}, {
22
20
  jobId: `${op}-${doc._id}`,
23
21
  removeOnComplete: true,
24
22
  removeOnFail: true,
@@ -40,7 +40,7 @@ const mongoose_delete_plugin = (schema) => {
40
40
  const get_dispatch_change_handler = (model_name) => (change) => {
41
41
  const op = change.operationType
42
42
  if (["insert", "update"].includes(op)) {
43
- dispatch_queue(queue, model_name, op, change.fullDocument)
43
+ dispatch_queue(queue, model_name, op, change.fullDocument, change.updateDescription)
44
44
  }
45
45
  }
46
46
 
@@ -2,6 +2,7 @@
2
2
  const fs = require("fs")
3
3
  const path = require("path")
4
4
  const glob = require("glob")
5
+ const Sentry = require("@sentry/node")
5
6
 
6
7
  const async_wrapper = require("../helpers/async_wrapper")
7
8
 
@@ -13,6 +14,9 @@ const COMPRESSED_EXTENSIONS_MAP = {
13
14
  ".svg": "image/svg+xml",
14
15
  }
15
16
 
17
+ const {SENTRY_DSN, NODE_ENV} = process.env
18
+ const has_sentry = !!SENTRY_DSN
19
+
16
20
  const is_development = process.env.NODE_ENV === "development"
17
21
  // do not serve compression in dev, the assets are only compressed in the github action
18
22
  const COMPRESSED_EXTENSIONS = is_development ? [] : Object.keys(COMPRESSED_EXTENSIONS_MAP)
@@ -77,33 +81,45 @@ const client_router = (app) => {
77
81
  const client_routes = get_client_routes()
78
82
 
79
83
  const index_file_path = path.join(client_build_dir, "./index.html")
80
- if (!fs.existsSync(index_file_path)) {
81
- console.log("index file not found, skipping server:client_router")
82
- return
84
+ if (fs.existsSync(index_file_path)) {
85
+ const index_file_buffer = fs.readFileSync(index_file_path)
86
+
87
+ app.get("*", async_wrapper(async(req, res, next) => {
88
+ const full_path = req.baseUrl + req.path
89
+
90
+ // TODO: this shouldn't be here,
91
+ // it should be handled by the api and rpc routers being declared before this router
92
+ if (full_path.startsWith("/api/") || full_path.startsWith("/rpc/")) {
93
+ return next()
94
+ }
95
+
96
+ if (client_routes.indexOf(full_path) > -1) {
97
+ serve_file(req, res, full_path)
98
+ return
99
+ } else {
100
+ // TODO: should handle 404 here
101
+ res.writeHead(200, {
102
+ "Content-Type": "text/html"
103
+ })
104
+ res.end(index_file_buffer)
105
+ }
106
+ }))
83
107
  }
108
+ // register final error handlers
84
109
 
85
- const index_file_buffer = fs.readFileSync(index_file_path)
86
-
87
- app.get("*", async_wrapper(async(req, res, next) => {
88
- const full_path = req.baseUrl + req.path
110
+ if (has_sentry && !is_development) {
111
+ // The error handler must be registered before any other error middleware and after all controllers
112
+ app.use(Sentry.Handlers.errorHandler())
113
+ }
89
114
 
90
- // TODO: this shouldn't be here,
91
- // it should be handled by the api and rpc routers being declared before this router
92
- if (full_path.startsWith("/api/") || full_path.startsWith("/rpc/")) {
93
- return next()
94
- }
95
115
 
96
- if (client_routes.indexOf(full_path) > -1) {
97
- serve_file(req, res, full_path)
98
- return
99
- } else {
100
- // TODO: should handle 404 here
101
- res.writeHead(200, {
102
- "Content-Type": "text/html"
103
- })
104
- res.end(index_file_buffer)
105
- }
106
- }))
116
+ app.use((err, req, res, next) => {
117
+ console.error("server got err", err)
118
+ res.status(500).json({
119
+ status: "error",
120
+ message: "something went wrong",
121
+ })
122
+ })
107
123
  }
108
124
 
109
125
  module.exports = client_router