@ditojs/server 1.16.0 → 1.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/server",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/server",
@@ -25,10 +25,10 @@
25
25
  "node >= 18"
26
26
  ],
27
27
  "dependencies": {
28
- "@ditojs/admin": "^1.16.0",
28
+ "@ditojs/admin": "^1.18.0",
29
29
  "@ditojs/build": "^1.14.0",
30
- "@ditojs/router": "^1.16.0",
31
- "@ditojs/utils": "^1.16.0",
30
+ "@ditojs/router": "^1.18.0",
31
+ "@ditojs/utils": "^1.18.0",
32
32
  "@koa/cors": "^4.0.0",
33
33
  "@koa/multer": "^3.0.2",
34
34
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -49,9 +49,9 @@
49
49
  "koa-etag": "^4.0.0",
50
50
  "koa-helmet": "^6.1.0",
51
51
  "koa-mount": "^4.0.0",
52
- "koa-passport": "^4.1.4",
52
+ "koa-passport": "https://github.com/ditojs/koa-passport#dito",
53
53
  "koa-response-time": "^2.1.0",
54
- "koa-session": "^6.2.0",
54
+ "koa-session": "https://github.com/ditojs/koa-session#dito",
55
55
  "koa-static": "^5.0.0",
56
56
  "mime-types": "^2.1.35",
57
57
  "multer": "^1.4.5-lts.1",
@@ -67,7 +67,7 @@
67
67
  "pluralize": "^8.0.0",
68
68
  "repl": "^0.1.3",
69
69
  "uuid": "^9.0.0",
70
- "vite": "^3.2.4",
70
+ "vite": "^3.2.5",
71
71
  "vite-plugin-vue2": "^2.0.2",
72
72
  "vue": "^2.7.14",
73
73
  "vue-template-compiler": "^2.7.14"
@@ -94,5 +94,5 @@
94
94
  "typescript": "^4.9.3"
95
95
  },
96
96
  "types": "types",
97
- "gitHead": "e7e7ddb88965dbffc29c0968054015a647844803"
97
+ "gitHead": "6d5e8c9d08b4e5a15080b01d7f70a53f98b3a819"
98
98
  }
@@ -64,12 +64,16 @@ export class Application extends Koa {
64
64
  const {
65
65
  // Pluck keys out of `config.app` to keep them secret
66
66
  app: { keys, ...app } = {},
67
- log = {},
67
+ log,
68
+ logger,
68
69
  ...rest
69
70
  } = config
70
71
  this.config = {
71
72
  app,
72
- log: log.silent || process.env.DITO_SILENT ? {} : log,
73
+ log: log === false || log?.silent || process.env.DITO_SILENT
74
+ ? {}
75
+ : getOptions(log),
76
+ logger: merge(defaultLoggerOptions, getOptions(logger)),
73
77
  ...rest
74
78
  }
75
79
  this.keys = keys
@@ -582,39 +586,13 @@ export class Application extends Koa {
582
586
  }
583
587
 
584
588
  setupLogger() {
585
- const { err, req, res } = pino.stdSerializers
586
- // Only include `id` from the user, to not inadvertently log PII.
587
- const user = user => ({ id: user.id })
588
- const serializers = { err, req, res, user }
589
-
590
- const { prettyPrint, ...options } = merge({
591
- level: 'info',
592
- serializers,
593
- prettyPrint: {
594
- colorize: true,
595
- // List of keys to ignore in pretty mode.
596
- ignore: 'req,res,durationMs,user,requestId',
597
- // SYS to use system time and not UTC.
598
- translateTime: 'SYS:HH:MM:ss.l'
599
- },
600
- // Redact common sensitive headers.
601
- redact: [
602
- '*.headers["cookie"]',
603
- '*.headers["set-cookie"]',
604
- '*.headers["authorization"]'
605
- ],
606
- base: null // no pid,hostname,name
607
- }, getOptions(this.config.logger))
608
-
589
+ const { prettyPrint, ...options } = this.config.logger
609
590
  const transport = prettyPrint
610
591
  ? pino.transport({
611
592
  target: 'pino-pretty',
612
593
  options: prettyPrint
613
594
  }) : null
614
-
615
- const logger = pino(options, transport)
616
-
617
- this.logger = logger.child({ name: 'app' })
595
+ this.logger = pino(options, transport).child({ name: 'app' })
618
596
  }
619
597
 
620
598
  setupKnex() {
@@ -699,11 +677,14 @@ export class Application extends Koa {
699
677
  }
700
678
  // Use `util.inspect()` instead of Pino's internal error logging for better
701
679
  // stack traces and logging of error data.
702
- return util.inspect(copy, {
703
- compact: false,
704
- depth: null,
705
- maxArrayLength: null
706
- })
680
+ return this.config.logger.prettyPrint
681
+ ? util.inspect(copy, {
682
+ colors: !!this.config.logger.prettyPrint.colorize,
683
+ compact: false,
684
+ depth: null,
685
+ maxArrayLength: null
686
+ })
687
+ : copy
707
688
  }
708
689
 
709
690
  logError(error, ctx) {
@@ -1015,3 +996,29 @@ EventEmitter.mixin(Application.prototype)
1015
996
  function getOptions(options) {
1016
997
  return isObject(options) ? options : {}
1017
998
  }
999
+
1000
+ const { err, req, res } = pino.stdSerializers
1001
+ const defaultLoggerOptions = {
1002
+ level: 'info',
1003
+ serializers: {
1004
+ err,
1005
+ req,
1006
+ res,
1007
+ // Only include `id` from the user, to not inadvertently log PII.
1008
+ user: user => ({ id: user.id })
1009
+ },
1010
+ prettyPrint: {
1011
+ colorize: true,
1012
+ // List of keys to ignore in pretty mode.
1013
+ ignore: 'req,res,durationMs,user,requestId',
1014
+ // SYS to use system time and not UTC.
1015
+ translateTime: 'SYS:HH:MM:ss.l'
1016
+ },
1017
+ // Redact common sensitive headers.
1018
+ redact: [
1019
+ '*.headers["cookie"]',
1020
+ '*.headers["set-cookie"]',
1021
+ '*.headers["authorization"]'
1022
+ ],
1023
+ base: null // no pid,hostname,name
1024
+ }
@@ -208,7 +208,7 @@ export class AdminController extends Controller {
208
208
  return 'common'
209
209
  } else {
210
210
  const module = id.match(/node_modules\/([^/$]*)/)?.[1] || ''
211
- return testModuleIdentifier(module, CORE_DEPENDENCIES)
211
+ return testModuleIdentifier(module, coreDependencies)
212
212
  ? 'core'
213
213
  : 'vendor'
214
214
  }
@@ -219,10 +219,10 @@ export class AdminController extends Controller {
219
219
  )
220
220
  },
221
221
  optimizeDeps: {
222
- exclude: development ? DITO_PACKAGES : [],
222
+ exclude: development ? ditoPackages : [],
223
223
  include: [
224
- ...(development ? [] : DITO_PACKAGES),
225
- ...NON_ESM_DEPENDENCIES
224
+ ...(development ? [] : ditoPackages),
225
+ ...nonEsmDependencies
226
226
  ]
227
227
  },
228
228
  resolve: {
@@ -240,13 +240,13 @@ export class AdminController extends Controller {
240
240
  }
241
241
  }
242
242
 
243
- const DITO_PACKAGES = [
243
+ const ditoPackages = [
244
244
  '@ditojs/admin',
245
245
  '@ditojs/ui',
246
246
  '@ditojs/utils'
247
247
  ]
248
248
 
249
- const NON_ESM_DEPENDENCIES = [
249
+ const nonEsmDependencies = [
250
250
  // All non-es modules need to be explicitly included here, and some of
251
251
  // them only work due to the use of `createCommonJsPlugin()`.
252
252
  'vue-color',
@@ -256,8 +256,8 @@ const NON_ESM_DEPENDENCIES = [
256
256
  'lowlight'
257
257
  ]
258
258
 
259
- const CORE_DEPENDENCIES = [
260
- ...DITO_PACKAGES,
259
+ const coreDependencies = [
260
+ ...ditoPackages,
261
261
 
262
262
  // TODO: Figure out a way to generate this automatically for the current
263
263
  // dito-admin dependencies, e.g. similar to
@@ -7,16 +7,16 @@ export function handleUser() {
7
7
  // on the user model:
8
8
  const { login, logout } = ctx
9
9
 
10
- ctx.login = async function(user, options = {}) {
10
+ ctx.login = ctx.logIn = async function(user, options = {}) {
11
11
  await user.$emit('before:login', options)
12
12
  await login.call(this, user, options)
13
13
  await user.$emit('after:login', options)
14
14
  }
15
15
 
16
- ctx.logout = async function(options = {}) {
16
+ ctx.logout = ctx.logOut = async function(options = {}) {
17
17
  const { user } = ctx.state
18
18
  await user?.$emit('before:logout', options)
19
- await logout.call(this) // No options in passport's logout()
19
+ await logout.call(this, options)
20
20
  // Clear the session after logout, apparently koa-passport doesn't take
21
21
  // care of this itself:
22
22
  // https://stackoverflow.com/questions/55818887/koa-passport-logout-is-not-clearing-session