@jsreport/jsreport-core 3.1.2-test.2 → 3.4.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.
Files changed (81) hide show
  1. package/LICENSE +166 -166
  2. package/README.md +310 -298
  3. package/index.js +29 -29
  4. package/lib/main/blobStorage/blobStorage.js +53 -52
  5. package/lib/main/blobStorage/inMemoryProvider.js +27 -27
  6. package/lib/main/blobStorage/mainActions.js +24 -24
  7. package/lib/main/createDefaultLoggerFormat.js +17 -17
  8. package/lib/main/defaults.js +14 -14
  9. package/lib/main/extensions/discover.js +20 -20
  10. package/lib/main/extensions/extensionsManager.js +264 -264
  11. package/lib/main/extensions/fileUtils.js +56 -56
  12. package/lib/main/extensions/findVersion.js +49 -49
  13. package/lib/main/extensions/locationCache.js +103 -103
  14. package/lib/main/extensions/sorter.js +10 -10
  15. package/lib/main/extensions/validateMinimalVersion.js +50 -50
  16. package/lib/main/folders/cascadeFolderRemove.js +25 -25
  17. package/lib/main/folders/getEntitiesInFolder.js +53 -53
  18. package/lib/main/folders/index.js +42 -42
  19. package/lib/main/folders/moveBetweenFolders.js +354 -354
  20. package/lib/main/folders/validateDuplicatedName.js +107 -107
  21. package/lib/main/folders/validateReservedName.js +53 -53
  22. package/lib/main/logger.js +254 -244
  23. package/lib/main/migration/resourcesToAssets.js +230 -230
  24. package/lib/main/migration/xlsxTemplatesToAssets.js +128 -128
  25. package/lib/main/monitoring.js +92 -91
  26. package/lib/main/optionsLoad.js +231 -237
  27. package/lib/main/optionsSchema.js +237 -237
  28. package/lib/main/profiler.js +13 -1
  29. package/lib/main/reporter.js +589 -579
  30. package/lib/main/request.js +21 -0
  31. package/lib/main/schemaValidator.js +252 -252
  32. package/lib/main/settings.js +154 -154
  33. package/lib/main/store/checkDuplicatedId.js +27 -27
  34. package/lib/main/store/collection.js +329 -329
  35. package/lib/main/store/documentStore.js +469 -469
  36. package/lib/main/store/mainActions.js +28 -28
  37. package/lib/main/store/memoryStoreProvider.js +99 -99
  38. package/lib/main/store/queue.js +48 -48
  39. package/lib/main/store/referenceUtils.js +251 -251
  40. package/lib/main/store/setupValidateId.js +43 -43
  41. package/lib/main/store/setupValidateShortid.js +71 -71
  42. package/lib/main/store/transaction.js +69 -69
  43. package/lib/main/store/typeUtils.js +180 -180
  44. package/lib/main/templates.js +34 -34
  45. package/lib/main/validateEntityName.js +62 -62
  46. package/lib/shared/createError.js +36 -36
  47. package/lib/shared/encryption.js +114 -114
  48. package/lib/shared/folders/index.js +11 -11
  49. package/lib/shared/folders/normalizeEntityPath.js +15 -15
  50. package/lib/shared/folders/resolveEntityFromPath.js +88 -88
  51. package/lib/shared/folders/resolveEntityPath.js +46 -46
  52. package/lib/shared/folders/resolveFolderFromPath.js +38 -38
  53. package/lib/shared/generateRequestId.js +4 -4
  54. package/lib/shared/listenerCollection.js +169 -169
  55. package/lib/shared/normalizeMetaFromLogs.js +30 -30
  56. package/lib/shared/reporter.js +128 -123
  57. package/lib/shared/request.js +64 -64
  58. package/lib/shared/tempFilesHandler.js +81 -81
  59. package/lib/shared/templates.js +82 -82
  60. package/lib/static/helpers.js +33 -33
  61. package/lib/worker/blobStorage.js +34 -34
  62. package/lib/worker/defaultProxyExtend.js +46 -46
  63. package/lib/worker/documentStore.js +49 -49
  64. package/lib/worker/extensionsManager.js +17 -17
  65. package/lib/worker/logger.js +48 -48
  66. package/lib/worker/render/diff.js +138 -138
  67. package/lib/worker/render/executeEngine.js +232 -207
  68. package/lib/worker/render/htmlRecipe.js +10 -10
  69. package/lib/worker/render/moduleHelper.js +45 -43
  70. package/lib/worker/render/noneEngine.js +12 -12
  71. package/lib/worker/render/profiler.js +162 -158
  72. package/lib/worker/render/render.js +202 -205
  73. package/lib/worker/render/resolveReferences.js +60 -60
  74. package/lib/worker/reporter.js +197 -191
  75. package/lib/worker/sandbox/runInSandbox.js +64 -12
  76. package/lib/worker/sandbox/safeSandbox.js +829 -828
  77. package/lib/worker/templates.js +80 -78
  78. package/lib/worker/workerHandler.js +55 -54
  79. package/package.json +91 -92
  80. package/test/blobStorage/common.js +25 -21
  81. package/test/store/common.js +1449 -1449
@@ -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
+ }