@jsreport/jsreport-core 3.12.0 → 4.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.
package/README.md CHANGED
@@ -282,6 +282,17 @@ jsreport.documentStore.collection('templates')
282
282
 
283
283
  ## Changelog
284
284
 
285
+ ### 4.0.1
286
+
287
+ - fix parameter mutations passed to store methods producing unexpected changes in store
288
+
289
+ ### 4.0.0
290
+
291
+ - minimum node.js version is now `18.15.0`
292
+ - remove old migration options `migrateXlsxTemplatesToAssets`, `migrateResourcesToAssets`
293
+ - sandbox now uses SES instead of vm2 for evaluating user code
294
+ - internal changes to support multi admin users
295
+
285
296
  ### 3.12.0
286
297
 
287
298
  - update vm2 to fix security issues
@@ -1,271 +1,263 @@
1
- const { getDefaultTempDirectory, getDefaultLoadConfig } = require('./defaults')
2
- // we use deepmerge instead of node.extend here because it supports
3
- // concatenating arrays instead of replacing them, something necessary
4
- // to support extending some values in schemas like the "enum"
5
- const deepMerge = require('deepmerge')
6
-
7
- module.exports.getRootSchemaOptions = () => ({
8
- type: 'object',
9
- properties: {
10
- rootDirectory: {
11
- type: 'string',
12
- description: 'specifies where is the application root and where jsreport searches for extensions'
13
- },
14
- appDirectory: {
15
- type: 'string',
16
- description: 'specifies directory of the script that was used to start node.js, this value is mostly metadata that is useful for your own code inside jsreport scripts'
17
- },
18
- tempDirectory: {
19
- type: 'string',
20
- default: getDefaultTempDirectory(),
21
- description: 'specifies where jsreport stores temporary files used by the conversion pipeline'
22
- },
23
- loadConfig: {
24
- type: 'boolean',
25
- default: getDefaultLoadConfig(),
26
- description: 'specifies if jsreport should load configuration values from external sources (cli args, env vars, configuration files) or not'
27
- },
28
- autoTempCleanup: {
29
- type: 'boolean',
30
- default: true,
31
- description: 'specifies if after some interval jsreport should automatically clean up temporary files generated while rendering reports'
32
- },
33
- discover: {
34
- type: 'boolean',
35
- defaultNotInitialized: true,
36
- description: 'specifies if jsreport should discover/search installed extensions in project and use them automatically'
37
- },
38
- useExtensionsLocationCache: {
39
- type: 'boolean',
40
- default: true,
41
- description: 'whether if jsreport should read list of extensions from a previous generated cache or if it should crawl and try to search extensions again, set it to false when you want to always force crawling node_modules when searching for extensions while starting jsreport'
42
- },
43
- logger: {
44
- type: 'object',
45
- properties: {
46
- silent: { type: 'boolean' }
47
- }
48
- },
49
- reportTimeout: {
50
- type: ['string', 'number'],
51
- '$jsreport-acceptsDuration': true,
52
- description: 'global single timeout that controls how much a report generation should wait before it times out',
53
- default: 60000
54
- },
55
- reportTimeoutMargin: {
56
- type: ['string', 'number'],
57
- description: 'the time to wait before the worker thread is forcibly killed after timeout',
58
- '$jsreport-acceptsDuration': true,
59
- default: '2s'
60
- },
61
- enableRequestReportTimeout: { type: 'boolean', default: false, description: 'option that enables passing a custom report timeout per request using req.options.timeout. this enables that the caller of the report generation control the report timeout so enable it only when you trust the caller' },
62
- trustUserCode: { type: 'boolean', default: false, description: 'option that control whether code sandboxing is enabled or not, code sandboxing has an impact on performance when rendering large reports. when true code sandboxing will be disabled meaning that users can potentially penetrate the local system if you allow code from external users to be part of your reports' },
63
- allowLocalFilesAccess: { type: 'boolean', default: false },
64
- encryption: {
65
- type: 'object',
66
- default: {},
67
- properties: {
68
- secretKey: {
69
- type: 'string',
70
- minLength: 16,
71
- maxLength: 16
72
- },
73
- enabled: {
74
- type: 'boolean',
75
- default: true
76
- }
77
- }
78
- },
79
- sandbox: {
80
- type: 'object',
81
- default: {},
82
- properties: {
83
- isolateModules: { type: 'boolean', default: true, description: 'option that control whether require/import of modules during rendering are isolated from other renders or not. when this is false the require/import of modules will behave like normal require, which means that module is evaluated only once and next require/import are resolved from a cache' },
84
- allowedModules: {
85
- anyOf: [{
86
- type: 'string',
87
- '$jsreport-constantOrArray': ['*']
88
- }, {
89
- type: 'array',
90
- items: { type: 'string' }
91
- }]
92
- },
93
- cache: {
94
- type: 'object',
95
- default: {},
96
- properties: {
97
- max: { type: 'number', default: 100 },
98
- enabled: { type: 'boolean', default: true }
99
- }
100
- }
101
- }
102
- },
103
- workers: {
104
- type: 'object',
105
- default: {},
106
- properties: {
107
- numberOfWorkers: {
108
- type: 'number',
109
- default: 2,
110
- description: 'Number of workers allocated. Every worker can process a single request in parallel. This means increasing numberOfWorkers will increase the parallelization.'
111
- },
112
- initTimeout: {
113
- type: ['string', 'number'],
114
- '$jsreport-acceptsDuration': true,
115
- description: 'Timeout for initializing a worker thread. This should be increased only when running at very slow HW environment.',
116
- default: '30s'
117
- },
118
- resourceLimits: {
119
- type: 'object',
120
- description: 'Limits for the individual workers. See https://nodejs.org/api/worker_threads.html#worker_threads_worker_resourcelimits',
121
- properties: {
122
- maxOldGenerationSizeMb: { type: 'number' },
123
- maxYoungGenerationSizeMb: { type: 'number' },
124
- codeRangeSizeMb: { type: 'number' },
125
- stackSizeMb: { type: 'number' }
126
- }
127
- }
128
- }
129
- },
130
- store: {
131
- type: 'object',
132
- properties: {
133
- provider: { type: 'string', enum: ['memory'] },
134
- transactions: {
135
- type: 'object',
136
- properties: {
137
- enabled: { type: 'boolean', default: true }
138
- }
139
- }
140
- }
141
- },
142
- blobStorage: {
143
- type: 'object',
144
- properties: {
145
- provider: { type: 'string', enum: ['memory'] }
146
- }
147
- },
148
- extensions: {
149
- type: 'object',
150
- properties: {}
151
- },
152
- extensionsList: {
153
- anyOf: [
154
- {
155
- type: 'string',
156
- '$jsreport-constantOrArray': []
157
- },
158
- {
159
- type: 'array',
160
- items: { type: 'string' }
161
- }
162
- ]
163
- },
164
- migrateXlsxTemplatesToAssets: {
165
- type: 'boolean',
166
- default: true
167
- },
168
- migrateResourcesToAssets: {
169
- type: 'boolean',
170
- default: true
171
- },
172
- profiler: {
173
- type: 'object',
174
- default: {},
175
- properties: {
176
- defaultMode: {
177
- type: 'string',
178
- default: 'standard'
179
- },
180
- fullModeDurationCheckInterval: {
181
- type: ['string', 'number'],
182
- '$jsreport-acceptsDuration': true,
183
- default: '10m'
184
- },
185
- fullModeDuration: {
186
- type: ['string', 'number'],
187
- '$jsreport-acceptsDuration': true,
188
- default: '4h'
189
- },
190
- maxProfilesHistory: {
191
- type: 'number',
192
- default: 1000
193
- },
194
- cleanupInterval: {
195
- type: ['string', 'number'],
196
- '$jsreport-acceptsDuration': true,
197
- default: '1m'
198
- },
199
- maxUnallocatedProfileAge: {
200
- type: ['string', 'number'],
201
- '$jsreport-acceptsDuration': true,
202
- default: '24h'
203
- },
204
- maxDiffSize: {
205
- type: ['string', 'number'],
206
- '$jsreport-acceptsSize': true,
207
- default: '50mb'
208
- }
209
- }
210
- }
211
- }
212
- })
213
-
214
- module.exports.extendRootSchemaOptions = (rootSchema, schema) => {
215
- const schemasToApply = Array.isArray(schema) ? schema : [schema]
216
-
217
- rootSchema.properties = rootSchema.properties || {}
218
-
219
- rootSchema.properties.extensions = rootSchema.properties.extensions || {
220
- type: 'object',
221
- properties: {}
222
- }
223
-
224
- schemasToApply.forEach((sch) => {
225
- if (sch == null) {
226
- return
227
- }
228
-
229
- if (sch.schema == null && sch.name != null) {
230
- rootSchema.properties.extensions.properties[sch.name] = {
231
- type: 'object',
232
- properties: {
233
- enabled: { type: 'boolean' }
234
- }
235
- }
236
- return
237
- } else if (sch.schema == null) {
238
- return
239
- }
240
-
241
- Object.keys(sch.schema).forEach((key) => {
242
- const current = sch.schema[key]
243
-
244
- if (key === 'extensions') {
245
- if (current == null) {
246
- return
247
- }
248
-
249
- Object.keys(current).forEach(s => {
250
- rootSchema.properties.extensions.properties[s] = deepMerge(rootSchema.properties.extensions.properties[s] || {}, current[s])
251
-
252
- if (
253
- rootSchema.properties.extensions.properties[s].properties &&
254
- rootSchema.properties.extensions.properties[s].properties.enabled == null
255
- ) {
256
- rootSchema.properties.extensions.properties[s].properties.enabled = { type: 'boolean' }
257
- }
258
- })
259
- } else if (current != null) {
260
- rootSchema.properties[key] = deepMerge(rootSchema.properties[key] || {}, current)
261
- }
262
- })
263
- })
264
-
265
- return rootSchema
266
- }
267
-
268
- module.exports.ignoreInitialSchemaProperties = [
269
- 'properties.store.properties.provider',
270
- 'properties.blobStorage.properties.provider'
271
- ]
1
+ const { getDefaultTempDirectory, getDefaultLoadConfig } = require('./defaults')
2
+ // we use deepmerge instead of node.extend here because it supports
3
+ // concatenating arrays instead of replacing them, something necessary
4
+ // to support extending some values in schemas like the "enum"
5
+ const deepMerge = require('deepmerge')
6
+
7
+ module.exports.getRootSchemaOptions = () => ({
8
+ type: 'object',
9
+ properties: {
10
+ rootDirectory: {
11
+ type: 'string',
12
+ description: 'specifies where is the application root and where jsreport searches for extensions'
13
+ },
14
+ appDirectory: {
15
+ type: 'string',
16
+ description: 'specifies directory of the script that was used to start node.js, this value is mostly metadata that is useful for your own code inside jsreport scripts'
17
+ },
18
+ tempDirectory: {
19
+ type: 'string',
20
+ default: getDefaultTempDirectory(),
21
+ description: 'specifies where jsreport stores temporary files used by the conversion pipeline'
22
+ },
23
+ loadConfig: {
24
+ type: 'boolean',
25
+ default: getDefaultLoadConfig(),
26
+ description: 'specifies if jsreport should load configuration values from external sources (cli args, env vars, configuration files) or not'
27
+ },
28
+ autoTempCleanup: {
29
+ type: 'boolean',
30
+ default: true,
31
+ description: 'specifies if after some interval jsreport should automatically clean up temporary files generated while rendering reports'
32
+ },
33
+ discover: {
34
+ type: 'boolean',
35
+ defaultNotInitialized: true,
36
+ description: 'specifies if jsreport should discover/search installed extensions in project and use them automatically'
37
+ },
38
+ useExtensionsLocationCache: {
39
+ type: 'boolean',
40
+ default: true,
41
+ description: 'whether if jsreport should read list of extensions from a previous generated cache or if it should crawl and try to search extensions again, set it to false when you want to always force crawling node_modules when searching for extensions while starting jsreport'
42
+ },
43
+ logger: {
44
+ type: 'object',
45
+ properties: {
46
+ silent: { type: 'boolean' }
47
+ }
48
+ },
49
+ reportTimeout: {
50
+ type: ['string', 'number'],
51
+ '$jsreport-acceptsDuration': true,
52
+ description: 'global single timeout that controls how much a report generation should wait before it times out',
53
+ default: 60000
54
+ },
55
+ reportTimeoutMargin: {
56
+ type: ['string', 'number'],
57
+ description: 'the time to wait before the worker thread is forcibly killed after timeout',
58
+ '$jsreport-acceptsDuration': true,
59
+ default: '2s'
60
+ },
61
+ enableRequestReportTimeout: { type: 'boolean', default: false, description: 'option that enables passing a custom report timeout per request using req.options.timeout. this enables that the caller of the report generation control the report timeout so enable it only when you trust the caller' },
62
+ trustUserCode: { type: 'boolean', default: false, description: 'option that control whether code sandboxing is enabled or not, code sandboxing has an impact on performance when rendering large reports. when true code sandboxing will be disabled meaning that users can potentially penetrate the local system if you allow code from external users to be part of your reports' },
63
+ allowLocalFilesAccess: { type: 'boolean', default: false },
64
+ encryption: {
65
+ type: 'object',
66
+ default: {},
67
+ properties: {
68
+ secretKey: {
69
+ type: 'string',
70
+ minLength: 16,
71
+ maxLength: 16
72
+ },
73
+ enabled: {
74
+ type: 'boolean',
75
+ default: true
76
+ }
77
+ }
78
+ },
79
+ sandbox: {
80
+ type: 'object',
81
+ default: {},
82
+ properties: {
83
+ isolateModules: { type: 'boolean', default: true, description: 'option that control whether require/import of modules during rendering are isolated from other renders or not. when this is false the require/import of modules will behave like normal require, which means that module is evaluated only once and next require/import are resolved from a cache' },
84
+ allowedModules: {
85
+ anyOf: [{
86
+ type: 'string',
87
+ '$jsreport-constantOrArray': ['*']
88
+ }, {
89
+ type: 'array',
90
+ items: { type: 'string' }
91
+ }]
92
+ },
93
+ cache: {
94
+ type: 'object',
95
+ default: {},
96
+ properties: {
97
+ max: { type: 'number', default: 100 },
98
+ enabled: { type: 'boolean', default: true }
99
+ }
100
+ }
101
+ }
102
+ },
103
+ workers: {
104
+ type: 'object',
105
+ default: {},
106
+ properties: {
107
+ numberOfWorkers: {
108
+ type: 'number',
109
+ default: 2,
110
+ description: 'Number of workers allocated. Every worker can process a single request in parallel. This means increasing numberOfWorkers will increase the parallelization.'
111
+ },
112
+ initTimeout: {
113
+ type: ['string', 'number'],
114
+ '$jsreport-acceptsDuration': true,
115
+ description: 'Timeout for initializing a worker thread. This should be increased only when running at very slow HW environment.',
116
+ default: '30s'
117
+ },
118
+ resourceLimits: {
119
+ type: 'object',
120
+ description: 'Limits for the individual workers. See https://nodejs.org/api/worker_threads.html#worker_threads_worker_resourcelimits',
121
+ properties: {
122
+ maxOldGenerationSizeMb: { type: 'number' },
123
+ maxYoungGenerationSizeMb: { type: 'number' },
124
+ codeRangeSizeMb: { type: 'number' },
125
+ stackSizeMb: { type: 'number' }
126
+ }
127
+ }
128
+ }
129
+ },
130
+ store: {
131
+ type: 'object',
132
+ properties: {
133
+ provider: { type: 'string', enum: ['memory'] },
134
+ transactions: {
135
+ type: 'object',
136
+ properties: {
137
+ enabled: { type: 'boolean', default: true }
138
+ }
139
+ }
140
+ }
141
+ },
142
+ blobStorage: {
143
+ type: 'object',
144
+ properties: {
145
+ provider: { type: 'string', enum: ['memory'] }
146
+ }
147
+ },
148
+ extensions: {
149
+ type: 'object',
150
+ properties: {}
151
+ },
152
+ extensionsList: {
153
+ anyOf: [
154
+ {
155
+ type: 'string',
156
+ '$jsreport-constantOrArray': []
157
+ },
158
+ {
159
+ type: 'array',
160
+ items: { type: 'string' }
161
+ }
162
+ ]
163
+ },
164
+ profiler: {
165
+ type: 'object',
166
+ default: {},
167
+ properties: {
168
+ defaultMode: {
169
+ type: 'string',
170
+ default: 'standard'
171
+ },
172
+ fullModeDurationCheckInterval: {
173
+ type: ['string', 'number'],
174
+ '$jsreport-acceptsDuration': true,
175
+ default: '10m'
176
+ },
177
+ fullModeDuration: {
178
+ type: ['string', 'number'],
179
+ '$jsreport-acceptsDuration': true,
180
+ default: '4h'
181
+ },
182
+ maxProfilesHistory: {
183
+ type: 'number',
184
+ default: 1000
185
+ },
186
+ cleanupInterval: {
187
+ type: ['string', 'number'],
188
+ '$jsreport-acceptsDuration': true,
189
+ default: '1m'
190
+ },
191
+ maxUnallocatedProfileAge: {
192
+ type: ['string', 'number'],
193
+ '$jsreport-acceptsDuration': true,
194
+ default: '24h'
195
+ },
196
+ maxDiffSize: {
197
+ type: ['string', 'number'],
198
+ '$jsreport-acceptsSize': true,
199
+ default: '50mb'
200
+ }
201
+ }
202
+ }
203
+ }
204
+ })
205
+
206
+ module.exports.extendRootSchemaOptions = (rootSchema, schema) => {
207
+ const schemasToApply = Array.isArray(schema) ? schema : [schema]
208
+
209
+ rootSchema.properties = rootSchema.properties || {}
210
+
211
+ rootSchema.properties.extensions = rootSchema.properties.extensions || {
212
+ type: 'object',
213
+ properties: {}
214
+ }
215
+
216
+ schemasToApply.forEach((sch) => {
217
+ if (sch == null) {
218
+ return
219
+ }
220
+
221
+ if (sch.schema == null && sch.name != null) {
222
+ rootSchema.properties.extensions.properties[sch.name] = {
223
+ type: 'object',
224
+ properties: {
225
+ enabled: { type: 'boolean' }
226
+ }
227
+ }
228
+ return
229
+ } else if (sch.schema == null) {
230
+ return
231
+ }
232
+
233
+ Object.keys(sch.schema).forEach((key) => {
234
+ const current = sch.schema[key]
235
+
236
+ if (key === 'extensions') {
237
+ if (current == null) {
238
+ return
239
+ }
240
+
241
+ Object.keys(current).forEach(s => {
242
+ rootSchema.properties.extensions.properties[s] = deepMerge(rootSchema.properties.extensions.properties[s] || {}, current[s])
243
+
244
+ if (
245
+ rootSchema.properties.extensions.properties[s].properties &&
246
+ rootSchema.properties.extensions.properties[s].properties.enabled == null
247
+ ) {
248
+ rootSchema.properties.extensions.properties[s].properties.enabled = { type: 'boolean' }
249
+ }
250
+ })
251
+ } else if (current != null) {
252
+ rootSchema.properties[key] = deepMerge(rootSchema.properties[key] || {}, current)
253
+ }
254
+ })
255
+ })
256
+
257
+ return rootSchema
258
+ }
259
+
260
+ module.exports.ignoreInitialSchemaProperties = [
261
+ 'properties.store.properties.provider',
262
+ 'properties.blobStorage.properties.provider'
263
+ ]
@@ -6,6 +6,7 @@
6
6
  const path = require('path')
7
7
  const { Readable } = require('stream')
8
8
  const Reaper = require('@jsreport/reap')
9
+ const pkg = require('../../package.json')
9
10
  const optionsLoad = require('./optionsLoad')
10
11
  const { createLogger, configureLogger, silentLogs } = require('./logger')
11
12
  const checkEntityName = require('./validateEntityName')
@@ -28,8 +29,6 @@ const Reporter = require('../shared/reporter')
28
29
  const Request = require('./request')
29
30
  const generateRequestId = require('../shared/generateRequestId')
30
31
  const Profiler = require('./profiler')
31
- const migrateXlsxTemplatesToAssets = require('./migration/xlsxTemplatesToAssets')
32
- const migrateResourcesToAssets = require('./migration/resourcesToAssets')
33
32
  const semver = require('semver')
34
33
  let reportCounter = 0
35
34
 
@@ -37,8 +36,8 @@ class MainReporter extends Reporter {
37
36
  constructor (options, defaults) {
38
37
  super(options)
39
38
 
40
- if (!semver.satisfies(process.versions.node, '>=16.11.0')) {
41
- throw this.createError('jsreport needs at least node 16.11.0 to run.')
39
+ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
40
+ throw this.createError(`jsreport needs at least node ${pkg.engines.node} to run.`)
42
41
  }
43
42
 
44
43
  this.defaults = defaults || {}
@@ -172,14 +171,6 @@ class MainReporter extends Reporter {
172
171
 
173
172
  this._initializing = true
174
173
 
175
- if (this.compilation) {
176
- this.compilation.resource('vm2-events.js', require.resolve('vm2/lib/events.js'))
177
- this.compilation.resource('vm2-resolver-compat.js', require.resolve('vm2/lib/resolver-compat.js'))
178
- this.compilation.resource('vm2-resolver.js', require.resolve('vm2/lib/resolver.js'))
179
- this.compilation.resource('vm2-setup-node-sandbox.js', require.resolve('vm2/lib/setup-node-sandbox.js'))
180
- this.compilation.resource('vm2-setup-sandbox.js', require.resolve('vm2/lib/setup-sandbox.js'))
181
- }
182
-
183
174
  try {
184
175
  this._registerLogMainAction()
185
176
 
@@ -237,7 +228,11 @@ class MainReporter extends Reporter {
237
228
 
238
229
  await this.documentStore.init()
239
230
  await this.blobStorage.init()
240
- await this.settings.init(this.documentStore, this.authorization)
231
+
232
+ await this.settings.init(this.documentStore, {
233
+ authentication: this.authentication,
234
+ authorization: this.authorization
235
+ })
241
236
 
242
237
  const extensionsForWorkers = this.extensionsManager.extensions.filter(e => e.worker)
243
238
 
@@ -267,9 +262,6 @@ class MainReporter extends Reporter {
267
262
  setupValidateId(this)
268
263
  setupValidateShortid(this)
269
264
 
270
- this.initializeListeners.insert(0, 'core-resources-migration', () => migrateResourcesToAssets(this))
271
- this.initializeListeners.insert(0, 'core-xlsxTemplates-migration', () => migrateXlsxTemplatesToAssets(this))
272
-
273
265
  await this.initializeListeners.fire()
274
266
 
275
267
  this._workersManager = this._workersManagerFactory
@@ -1,5 +1,5 @@
1
1
  const extend = require('node.extend.without.arrays')
2
- const set = require('lodash.set')
2
+ const set = require('set-value')
3
3
  const hasOwn = require('has-own-deep')
4
4
  const unsetValue = require('unset-value')
5
5
  const ms = require('ms')