@jsreport/jsreport-core 3.0.0 → 3.1.2-test.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 (80) hide show
  1. package/LICENSE +166 -166
  2. package/README.md +298 -284
  3. package/index.js +29 -27
  4. package/lib/main/blobStorage/blobStorage.js +52 -47
  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 -265
  11. package/lib/main/extensions/fileUtils.js +56 -55
  12. package/lib/main/extensions/findVersion.js +49 -53
  13. package/lib/main/extensions/locationCache.js +103 -97
  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 +244 -244
  23. package/lib/main/migration/resourcesToAssets.js +230 -210
  24. package/lib/main/migration/xlsxTemplatesToAssets.js +128 -118
  25. package/lib/main/monitoring.js +91 -91
  26. package/lib/main/optionsLoad.js +237 -237
  27. package/lib/main/optionsSchema.js +237 -237
  28. package/lib/main/profiler.js +2 -1
  29. package/lib/main/reporter.js +575 -578
  30. package/lib/main/schemaValidator.js +252 -252
  31. package/lib/main/settings.js +154 -154
  32. package/lib/main/store/checkDuplicatedId.js +27 -27
  33. package/lib/main/store/collection.js +329 -329
  34. package/lib/main/store/documentStore.js +469 -469
  35. package/lib/main/store/mainActions.js +28 -28
  36. package/lib/main/store/memoryStoreProvider.js +99 -99
  37. package/lib/main/store/queue.js +48 -48
  38. package/lib/main/store/referenceUtils.js +251 -251
  39. package/lib/main/store/setupValidateId.js +43 -43
  40. package/lib/main/store/setupValidateShortid.js +71 -71
  41. package/lib/main/store/transaction.js +69 -69
  42. package/lib/main/store/typeUtils.js +180 -180
  43. package/lib/main/templates.js +34 -34
  44. package/lib/main/validateEntityName.js +62 -62
  45. package/lib/shared/createError.js +36 -36
  46. package/lib/shared/encryption.js +114 -114
  47. package/lib/shared/folders/index.js +11 -11
  48. package/lib/shared/folders/normalizeEntityPath.js +15 -15
  49. package/lib/shared/folders/resolveEntityFromPath.js +88 -88
  50. package/lib/shared/folders/resolveEntityPath.js +46 -46
  51. package/lib/shared/folders/resolveFolderFromPath.js +38 -38
  52. package/lib/shared/generateRequestId.js +4 -4
  53. package/lib/shared/listenerCollection.js +169 -0
  54. package/lib/shared/normalizeMetaFromLogs.js +30 -30
  55. package/lib/shared/reporter.js +128 -123
  56. package/lib/shared/request.js +64 -64
  57. package/lib/shared/tempFilesHandler.js +81 -81
  58. package/lib/shared/templates.js +82 -82
  59. package/lib/static/helpers.js +33 -33
  60. package/lib/worker/blobStorage.js +34 -34
  61. package/lib/worker/defaultProxyExtend.js +46 -46
  62. package/lib/worker/documentStore.js +49 -49
  63. package/lib/worker/extensionsManager.js +17 -17
  64. package/lib/worker/logger.js +48 -48
  65. package/lib/worker/render/diff.js +138 -138
  66. package/lib/worker/render/executeEngine.js +227 -190
  67. package/lib/worker/render/htmlRecipe.js +10 -10
  68. package/lib/worker/render/moduleHelper.js +45 -43
  69. package/lib/worker/render/noneEngine.js +12 -12
  70. package/lib/worker/render/profiler.js +158 -158
  71. package/lib/worker/render/render.js +213 -209
  72. package/lib/worker/render/resolveReferences.js +60 -60
  73. package/lib/worker/reporter.js +192 -187
  74. package/lib/worker/sandbox/runInSandbox.js +13 -4
  75. package/lib/worker/sandbox/safeSandbox.js +828 -822
  76. package/lib/worker/templates.js +78 -78
  77. package/lib/worker/workerHandler.js +54 -54
  78. package/package.json +92 -92
  79. package/test/blobStorage/common.js +21 -21
  80. 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
+ }