@jsreport/jsreport-core 3.1.2-test.2 → 3.2.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/LICENSE +166 -166
- package/README.md +298 -298
- package/index.js +29 -29
- package/lib/main/blobStorage/blobStorage.js +52 -52
- package/lib/main/blobStorage/inMemoryProvider.js +27 -27
- package/lib/main/blobStorage/mainActions.js +24 -24
- package/lib/main/createDefaultLoggerFormat.js +17 -17
- package/lib/main/defaults.js +14 -14
- package/lib/main/extensions/discover.js +20 -20
- package/lib/main/extensions/extensionsManager.js +264 -264
- package/lib/main/extensions/fileUtils.js +56 -56
- package/lib/main/extensions/findVersion.js +49 -49
- package/lib/main/extensions/locationCache.js +103 -103
- package/lib/main/extensions/sorter.js +10 -10
- package/lib/main/extensions/validateMinimalVersion.js +50 -50
- package/lib/main/folders/cascadeFolderRemove.js +25 -25
- package/lib/main/folders/getEntitiesInFolder.js +53 -53
- package/lib/main/folders/index.js +42 -42
- package/lib/main/folders/moveBetweenFolders.js +354 -354
- package/lib/main/folders/validateDuplicatedName.js +107 -107
- package/lib/main/folders/validateReservedName.js +53 -53
- package/lib/main/logger.js +244 -244
- package/lib/main/migration/resourcesToAssets.js +230 -230
- package/lib/main/migration/xlsxTemplatesToAssets.js +128 -128
- package/lib/main/monitoring.js +91 -91
- package/lib/main/optionsLoad.js +237 -237
- package/lib/main/optionsSchema.js +237 -237
- package/lib/main/reporter.js +574 -579
- package/lib/main/schemaValidator.js +252 -252
- package/lib/main/settings.js +154 -154
- package/lib/main/store/checkDuplicatedId.js +27 -27
- package/lib/main/store/collection.js +329 -329
- package/lib/main/store/documentStore.js +469 -469
- package/lib/main/store/mainActions.js +28 -28
- package/lib/main/store/memoryStoreProvider.js +99 -99
- package/lib/main/store/queue.js +48 -48
- package/lib/main/store/referenceUtils.js +251 -251
- package/lib/main/store/setupValidateId.js +43 -43
- package/lib/main/store/setupValidateShortid.js +71 -71
- package/lib/main/store/transaction.js +69 -69
- package/lib/main/store/typeUtils.js +180 -180
- package/lib/main/templates.js +34 -34
- package/lib/main/validateEntityName.js +62 -62
- package/lib/shared/createError.js +36 -36
- package/lib/shared/encryption.js +114 -114
- package/lib/shared/folders/index.js +11 -11
- package/lib/shared/folders/normalizeEntityPath.js +15 -15
- package/lib/shared/folders/resolveEntityFromPath.js +88 -88
- package/lib/shared/folders/resolveEntityPath.js +46 -46
- package/lib/shared/folders/resolveFolderFromPath.js +38 -38
- package/lib/shared/generateRequestId.js +4 -4
- package/lib/shared/listenerCollection.js +169 -169
- package/lib/shared/normalizeMetaFromLogs.js +30 -30
- package/lib/shared/reporter.js +128 -123
- package/lib/shared/request.js +64 -64
- package/lib/shared/tempFilesHandler.js +81 -81
- package/lib/shared/templates.js +82 -82
- package/lib/static/helpers.js +33 -33
- package/lib/worker/blobStorage.js +34 -34
- package/lib/worker/defaultProxyExtend.js +46 -46
- package/lib/worker/documentStore.js +49 -49
- package/lib/worker/extensionsManager.js +17 -17
- package/lib/worker/logger.js +48 -48
- package/lib/worker/render/diff.js +138 -138
- package/lib/worker/render/executeEngine.js +239 -207
- package/lib/worker/render/htmlRecipe.js +10 -10
- package/lib/worker/render/moduleHelper.js +45 -43
- package/lib/worker/render/noneEngine.js +12 -12
- package/lib/worker/render/profiler.js +158 -158
- package/lib/worker/render/render.js +202 -205
- package/lib/worker/render/resolveReferences.js +60 -60
- package/lib/worker/reporter.js +192 -191
- package/lib/worker/sandbox/runInSandbox.js +16 -9
- package/lib/worker/sandbox/safeSandbox.js +828 -828
- package/lib/worker/templates.js +80 -78
- package/lib/worker/workerHandler.js +54 -54
- package/package.json +92 -92
- package/test/blobStorage/common.js +21 -21
- package/test/store/common.js +1449 -1449
package/lib/main/settings.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright(c) 2014 Jan Blaha
|
|
3
|
-
*
|
|
4
|
-
* Key-Value persistent store for jsreport using DocumentStore to persist items.
|
|
5
|
-
*/
|
|
6
|
-
const Request = require('../shared/request')
|
|
7
|
-
|
|
8
|
-
const Settings = module.exports = function () {
|
|
9
|
-
this._collection = []
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
Settings.prototype.add = function (key, value, req) {
|
|
13
|
-
const settingItem = {
|
|
14
|
-
key: key,
|
|
15
|
-
value: typeof value !== 'string' ? JSON.stringify(value) : value
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this._collection.push(settingItem)
|
|
19
|
-
|
|
20
|
-
return this.documentStore.collection('settings').insert(settingItem, localReqWithoutAuthorization(req))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
Settings.prototype.get = function (key) {
|
|
24
|
-
return this._collection.find((s) => s.key === key)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Settings.prototype.findValue = async function (key, req) {
|
|
28
|
-
const res = await this.documentStore.collection('settings').find({ key: key }, req)
|
|
29
|
-
if (res.length !== 1) {
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return typeof res[0].value === 'string' ? JSON.parse(res[0].value) : res[0].value
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
Settings.prototype.set = function (key, avalue, req) {
|
|
37
|
-
const value = typeof avalue !== 'string' ? JSON.stringify(avalue) : avalue
|
|
38
|
-
|
|
39
|
-
this.get(key).value = value
|
|
40
|
-
|
|
41
|
-
return this.documentStore.collection('settings').update({
|
|
42
|
-
key: key
|
|
43
|
-
}, {
|
|
44
|
-
$set: { value: value }
|
|
45
|
-
}, localReqWithoutAuthorization(req))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
Settings.prototype.addOrSet = async function (key, avalue, req) {
|
|
49
|
-
const value = typeof avalue !== 'string' ? JSON.stringify(avalue) : avalue
|
|
50
|
-
|
|
51
|
-
const updateCount = await this.documentStore.collection('settings').update({ key }, { $set: { key: key, value: value } }, localReqWithoutAuthorization(req))
|
|
52
|
-
|
|
53
|
-
if (updateCount === 0) {
|
|
54
|
-
await this.documentStore.collection('settings').insert({ key: key, value: value }, localReqWithoutAuthorization(req))
|
|
55
|
-
return 1
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
Settings.prototype.init = async function (documentStore, authorization) {
|
|
60
|
-
this.documentStore = documentStore
|
|
61
|
-
|
|
62
|
-
const incompatibleSettingsToRemove = []
|
|
63
|
-
|
|
64
|
-
if (authorization != null) {
|
|
65
|
-
const col = documentStore.collection('settings')
|
|
66
|
-
|
|
67
|
-
// settings can be read by anyone so we don't add find listeners,
|
|
68
|
-
// we only care about modification listeners
|
|
69
|
-
col.beforeInsertListeners.add('settings', (doc, req) => {
|
|
70
|
-
if (req && req.context && req.context.skipAuthorization) {
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
75
|
-
throw authorization.createAuthorizationError(col.name)
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
col.beforeUpdateListeners.add('settings', (q, u, options, req) => {
|
|
80
|
-
if (req && req.context && req.context.skipAuthorization) {
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
85
|
-
throw authorization.createAuthorizationError(col.name)
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
col.beforeRemoveListeners.add('settings', (q, req) => {
|
|
90
|
-
if (req && req.context && req.context.skipAuthorization) {
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
95
|
-
throw authorization.createAuthorizationError(col.name)
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const res = await documentStore.collection('settings').find({})
|
|
101
|
-
|
|
102
|
-
res.forEach((v) => {
|
|
103
|
-
if (typeof v.value !== 'string') {
|
|
104
|
-
return this._collection.push({
|
|
105
|
-
key: v.key,
|
|
106
|
-
value: v.value
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
return this._collection.push({
|
|
112
|
-
key: v.key,
|
|
113
|
-
value: JSON.parse(v.value)
|
|
114
|
-
})
|
|
115
|
-
} catch (e) {
|
|
116
|
-
incompatibleSettingsToRemove.push(v._id)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
if (incompatibleSettingsToRemove.length) {
|
|
121
|
-
return documentStore.collection('settings').remove({ _id: { $in: incompatibleSettingsToRemove } })
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Settings.prototype.registerEntity = function (documentStore) {
|
|
126
|
-
documentStore.registerEntityType('SettingType', {
|
|
127
|
-
key: { type: 'Edm.String' },
|
|
128
|
-
value: { type: 'Edm.String' }
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
documentStore.registerEntitySet('settings', {
|
|
132
|
-
entityType: 'jsreport.SettingType',
|
|
133
|
-
shared: true,
|
|
134
|
-
exportable: false
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// we want that any code that uses the reporter.settings api directly be able to skip
|
|
139
|
-
// authorization checks. this way we can existing code working normally, but making the entitySet still protected when used from
|
|
140
|
-
// the documentStore api, or http ODATA directly.
|
|
141
|
-
function localReqWithoutAuthorization (req) {
|
|
142
|
-
if (req == null) {
|
|
143
|
-
return req
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// we create copy here to avoid persisting the context.skipAuthorization field in the
|
|
147
|
-
// original req
|
|
148
|
-
const localReq = Request(req)
|
|
149
|
-
localReq.context.skipAuthorization = true
|
|
150
|
-
|
|
151
|
-
return localReq
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
module.exports = Settings
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright(c) 2014 Jan Blaha
|
|
3
|
+
*
|
|
4
|
+
* Key-Value persistent store for jsreport using DocumentStore to persist items.
|
|
5
|
+
*/
|
|
6
|
+
const Request = require('../shared/request')
|
|
7
|
+
|
|
8
|
+
const Settings = module.exports = function () {
|
|
9
|
+
this._collection = []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Settings.prototype.add = function (key, value, req) {
|
|
13
|
+
const settingItem = {
|
|
14
|
+
key: key,
|
|
15
|
+
value: typeof value !== 'string' ? JSON.stringify(value) : value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this._collection.push(settingItem)
|
|
19
|
+
|
|
20
|
+
return this.documentStore.collection('settings').insert(settingItem, localReqWithoutAuthorization(req))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Settings.prototype.get = function (key) {
|
|
24
|
+
return this._collection.find((s) => s.key === key)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Settings.prototype.findValue = async function (key, req) {
|
|
28
|
+
const res = await this.documentStore.collection('settings').find({ key: key }, req)
|
|
29
|
+
if (res.length !== 1) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return typeof res[0].value === 'string' ? JSON.parse(res[0].value) : res[0].value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Settings.prototype.set = function (key, avalue, req) {
|
|
37
|
+
const value = typeof avalue !== 'string' ? JSON.stringify(avalue) : avalue
|
|
38
|
+
|
|
39
|
+
this.get(key).value = value
|
|
40
|
+
|
|
41
|
+
return this.documentStore.collection('settings').update({
|
|
42
|
+
key: key
|
|
43
|
+
}, {
|
|
44
|
+
$set: { value: value }
|
|
45
|
+
}, localReqWithoutAuthorization(req))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Settings.prototype.addOrSet = async function (key, avalue, req) {
|
|
49
|
+
const value = typeof avalue !== 'string' ? JSON.stringify(avalue) : avalue
|
|
50
|
+
|
|
51
|
+
const updateCount = await this.documentStore.collection('settings').update({ key }, { $set: { key: key, value: value } }, localReqWithoutAuthorization(req))
|
|
52
|
+
|
|
53
|
+
if (updateCount === 0) {
|
|
54
|
+
await this.documentStore.collection('settings').insert({ key: key, value: value }, localReqWithoutAuthorization(req))
|
|
55
|
+
return 1
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Settings.prototype.init = async function (documentStore, authorization) {
|
|
60
|
+
this.documentStore = documentStore
|
|
61
|
+
|
|
62
|
+
const incompatibleSettingsToRemove = []
|
|
63
|
+
|
|
64
|
+
if (authorization != null) {
|
|
65
|
+
const col = documentStore.collection('settings')
|
|
66
|
+
|
|
67
|
+
// settings can be read by anyone so we don't add find listeners,
|
|
68
|
+
// we only care about modification listeners
|
|
69
|
+
col.beforeInsertListeners.add('settings', (doc, req) => {
|
|
70
|
+
if (req && req.context && req.context.skipAuthorization) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
75
|
+
throw authorization.createAuthorizationError(col.name)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
col.beforeUpdateListeners.add('settings', (q, u, options, req) => {
|
|
80
|
+
if (req && req.context && req.context.skipAuthorization) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
85
|
+
throw authorization.createAuthorizationError(col.name)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
col.beforeRemoveListeners.add('settings', (q, req) => {
|
|
90
|
+
if (req && req.context && req.context.skipAuthorization) {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (req && req.context && req.context.user && !req.context.user.isAdmin) {
|
|
95
|
+
throw authorization.createAuthorizationError(col.name)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const res = await documentStore.collection('settings').find({})
|
|
101
|
+
|
|
102
|
+
res.forEach((v) => {
|
|
103
|
+
if (typeof v.value !== 'string') {
|
|
104
|
+
return this._collection.push({
|
|
105
|
+
key: v.key,
|
|
106
|
+
value: v.value
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
return this._collection.push({
|
|
112
|
+
key: v.key,
|
|
113
|
+
value: JSON.parse(v.value)
|
|
114
|
+
})
|
|
115
|
+
} catch (e) {
|
|
116
|
+
incompatibleSettingsToRemove.push(v._id)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
if (incompatibleSettingsToRemove.length) {
|
|
121
|
+
return documentStore.collection('settings').remove({ _id: { $in: incompatibleSettingsToRemove } })
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Settings.prototype.registerEntity = function (documentStore) {
|
|
126
|
+
documentStore.registerEntityType('SettingType', {
|
|
127
|
+
key: { type: 'Edm.String' },
|
|
128
|
+
value: { type: 'Edm.String' }
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
documentStore.registerEntitySet('settings', {
|
|
132
|
+
entityType: 'jsreport.SettingType',
|
|
133
|
+
shared: true,
|
|
134
|
+
exportable: false
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// we want that any code that uses the reporter.settings api directly be able to skip
|
|
139
|
+
// authorization checks. this way we can existing code working normally, but making the entitySet still protected when used from
|
|
140
|
+
// the documentStore api, or http ODATA directly.
|
|
141
|
+
function localReqWithoutAuthorization (req) {
|
|
142
|
+
if (req == null) {
|
|
143
|
+
return req
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// we create copy here to avoid persisting the context.skipAuthorization field in the
|
|
147
|
+
// original req
|
|
148
|
+
const localReq = Request(req)
|
|
149
|
+
localReq.context.skipAuthorization = true
|
|
150
|
+
|
|
151
|
+
return localReq
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports = Settings
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const omit = require('lodash.omit')
|
|
2
|
-
const Request = require('../../shared/request')
|
|
3
|
-
|
|
4
|
-
module.exports = async function checkDuplicatedId (store, collectionName, idValue, req) {
|
|
5
|
-
if (idValue == null) {
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const existingEntity = await findEntity(store, collectionName, idValue, req)
|
|
10
|
-
|
|
11
|
-
return existingEntity
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function findEntity (store, collectionName, idValue, req) {
|
|
15
|
-
const localReq = req ? Request(req) : req
|
|
16
|
-
|
|
17
|
-
// we should validate without caring about permissions
|
|
18
|
-
if (localReq) {
|
|
19
|
-
localReq.context = localReq.context ? omit(localReq.context, 'user') : localReq.context
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const existingEntity = await store.collection(collectionName).findOne({
|
|
23
|
-
_id: idValue
|
|
24
|
-
}, localReq)
|
|
25
|
-
|
|
26
|
-
return existingEntity
|
|
27
|
-
}
|
|
1
|
+
const omit = require('lodash.omit')
|
|
2
|
+
const Request = require('../../shared/request')
|
|
3
|
+
|
|
4
|
+
module.exports = async function checkDuplicatedId (store, collectionName, idValue, req) {
|
|
5
|
+
if (idValue == null) {
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const existingEntity = await findEntity(store, collectionName, idValue, req)
|
|
10
|
+
|
|
11
|
+
return existingEntity
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function findEntity (store, collectionName, idValue, req) {
|
|
15
|
+
const localReq = req ? Request(req) : req
|
|
16
|
+
|
|
17
|
+
// we should validate without caring about permissions
|
|
18
|
+
if (localReq) {
|
|
19
|
+
localReq.context = localReq.context ? omit(localReq.context, 'user') : localReq.context
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const existingEntity = await store.collection(collectionName).findOne({
|
|
23
|
+
_id: idValue
|
|
24
|
+
}, localReq)
|
|
25
|
+
|
|
26
|
+
return existingEntity
|
|
27
|
+
}
|