kuzzle 2.16.11 → 2.17.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.
Files changed (164) hide show
  1. package/lib/api/controllers/adminController.js +3 -3
  2. package/lib/api/controllers/authController.js +11 -11
  3. package/lib/api/controllers/baseController.js +60 -3
  4. package/lib/api/controllers/clusterController.js +1 -1
  5. package/lib/api/controllers/collectionController.js +7 -5
  6. package/lib/api/controllers/documentController.js +130 -17
  7. package/lib/api/controllers/indexController.js +1 -1
  8. package/lib/api/controllers/memoryStorageController.js +39 -38
  9. package/lib/api/controllers/realtimeController.js +1 -1
  10. package/lib/api/controllers/securityController.js +49 -49
  11. package/lib/api/controllers/serverController.js +73 -27
  12. package/lib/api/documentExtractor.js +3 -3
  13. package/lib/api/funnel.js +40 -21
  14. package/lib/api/httpRoutes.js +9 -4
  15. package/lib/api/openapi/OpenApiManager.d.ts +11 -0
  16. package/lib/api/openapi/OpenApiManager.js +96 -0
  17. package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
  18. package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
  19. package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
  20. package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
  21. package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
  22. package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
  23. package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
  24. package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
  25. package/lib/api/openapi/{document → components/document}/index.js +7 -2
  26. package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
  27. package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
  28. package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
  29. package/lib/api/openapi/components/document/validate.yaml +42 -0
  30. package/lib/api/openapi/components/index.d.ts +2 -0
  31. package/lib/api/openapi/components/index.js +18 -0
  32. package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
  33. package/lib/api/openapi/index.d.ts +1 -2
  34. package/lib/api/openapi/index.js +1 -5
  35. package/lib/api/openapi/openApiGenerator.d.ts +7 -0
  36. package/lib/api/openapi/openApiGenerator.js +133 -0
  37. package/lib/api/request/kuzzleRequest.js +4 -0
  38. package/lib/cluster/node.js +9 -9
  39. package/lib/cluster/publisher.js +1 -1
  40. package/lib/cluster/subscriber.js +1 -1
  41. package/lib/cluster/workers/IDCardRenewer.js +2 -2
  42. package/lib/config/default.config.js +1 -0
  43. package/lib/config/index.js +6 -6
  44. package/lib/core/auth/passportResponse.js +6 -6
  45. package/lib/core/auth/passportWrapper.js +5 -5
  46. package/lib/core/backend/backend.d.ts +5 -1
  47. package/lib/core/backend/backend.js +12 -8
  48. package/lib/core/backend/backendConfig.d.ts +5 -1
  49. package/lib/core/backend/backendConfig.js +4 -0
  50. package/lib/core/backend/backendOpenApi.d.ts +9 -0
  51. package/lib/core/backend/backendOpenApi.js +69 -0
  52. package/lib/core/backend/index.d.ts +1 -0
  53. package/lib/core/backend/index.js +1 -0
  54. package/lib/core/network/accessLogger.js +6 -6
  55. package/lib/core/network/clientConnection.js +1 -1
  56. package/lib/core/network/entryPoint.js +5 -5
  57. package/lib/core/network/httpRouter/index.js +5 -5
  58. package/lib/core/network/httpRouter/routeHandler.js +3 -3
  59. package/lib/core/network/httpRouter/routePart.js +5 -5
  60. package/lib/core/network/protocolManifest.js +1 -1
  61. package/lib/core/network/protocols/httpMessage.js +2 -2
  62. package/lib/core/network/protocols/httpwsProtocol.js +205 -48
  63. package/lib/core/network/protocols/mqttProtocol.js +3 -3
  64. package/lib/core/network/protocols/protocol.js +3 -3
  65. package/lib/core/network/router.js +7 -6
  66. package/lib/core/plugin/plugin.js +38 -64
  67. package/lib/core/plugin/pluginManifest.js +3 -3
  68. package/lib/core/plugin/pluginRepository.js +5 -5
  69. package/lib/core/plugin/pluginsManager.js +29 -28
  70. package/lib/core/realtime/notification/server.js +1 -1
  71. package/lib/core/realtime/notification/user.js +1 -1
  72. package/lib/core/realtime/notifier.js +5 -5
  73. package/lib/core/security/index.js +1 -1
  74. package/lib/core/security/profileRepository.d.ts +176 -0
  75. package/lib/core/security/profileRepository.js +426 -443
  76. package/lib/core/security/roleRepository.js +16 -16
  77. package/lib/core/security/securityLoader.js +2 -2
  78. package/lib/core/security/tokenRepository.js +11 -11
  79. package/lib/core/security/userRepository.js +8 -8
  80. package/lib/core/shared/abstractManifest.js +4 -4
  81. package/lib/core/shared/repository.js +5 -5
  82. package/lib/core/shared/sdk/funnelProtocol.js +1 -1
  83. package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
  84. package/lib/core/shared/store.js +30 -23
  85. package/lib/core/statistics/statistics.js +17 -17
  86. package/lib/core/storage/clientAdapter.js +45 -10
  87. package/lib/core/validation/baseType.js +5 -5
  88. package/lib/core/validation/types/anything.js +1 -1
  89. package/lib/core/validation/types/boolean.js +2 -2
  90. package/lib/core/validation/types/date.js +9 -9
  91. package/lib/core/validation/types/email.js +5 -5
  92. package/lib/core/validation/types/enum.js +6 -6
  93. package/lib/core/validation/types/geoPoint.js +2 -2
  94. package/lib/core/validation/types/geoShape.js +28 -25
  95. package/lib/core/validation/types/integer.js +4 -4
  96. package/lib/core/validation/types/ipAddress.js +7 -6
  97. package/lib/core/validation/types/numeric.js +4 -4
  98. package/lib/core/validation/types/object.js +5 -5
  99. package/lib/core/validation/types/string.js +5 -5
  100. package/lib/core/validation/types/url.js +7 -6
  101. package/lib/core/validation/validation.js +95 -84
  102. package/lib/kerror/codes/1-services.json +12 -0
  103. package/lib/kerror/codes/2-api.json +12 -0
  104. package/lib/kerror/codes/3-network.json +12 -0
  105. package/lib/kerror/codes/4-plugin.json +6 -0
  106. package/lib/kerror/codes/index.js +11 -11
  107. package/lib/kerror/index.js +1 -1
  108. package/lib/kuzzle/dumpGenerator.js +3 -3
  109. package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
  110. package/lib/kuzzle/event/pipeRunner.js +1 -1
  111. package/lib/kuzzle/event/waterfall.js +6 -6
  112. package/lib/kuzzle/kuzzle.js +36 -5
  113. package/lib/kuzzle/log.js +3 -3
  114. package/lib/kuzzle/vault.js +3 -3
  115. package/lib/model/security/profile.d.ts +54 -0
  116. package/lib/model/security/profile.js +174 -233
  117. package/lib/model/security/rights.js +1 -1
  118. package/lib/model/security/role.d.ts +40 -0
  119. package/lib/model/security/role.js +159 -191
  120. package/lib/model/security/user.d.ts +29 -0
  121. package/lib/model/security/user.js +84 -52
  122. package/lib/model/storage/apiKey.js +2 -2
  123. package/lib/model/storage/baseModel.js +3 -3
  124. package/lib/service/cache/redis.js +7 -7
  125. package/lib/service/storage/elasticsearch.js +152 -90
  126. package/lib/service/storage/esWrapper.js +2 -3
  127. package/lib/types/ControllerDefinition.d.ts +3 -3
  128. package/lib/types/ControllerRights.d.ts +22 -0
  129. package/lib/types/ControllerRights.js +23 -0
  130. package/lib/types/HttpStream.d.ts +32 -0
  131. package/lib/types/HttpStream.js +70 -0
  132. package/lib/types/OpenApiDefinition.d.ts +43 -0
  133. package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
  134. package/lib/types/Policy.d.ts +25 -0
  135. package/lib/types/{InternalLogger.js → Policy.js} +2 -2
  136. package/lib/types/PolicyRestrictions.d.ts +21 -0
  137. package/lib/types/PolicyRestrictions.js +23 -0
  138. package/lib/types/Target.d.ts +15 -0
  139. package/lib/types/Target.js +23 -0
  140. package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
  141. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  142. package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
  143. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
  144. package/lib/types/index.d.ts +7 -1
  145. package/lib/types/index.js +7 -1
  146. package/lib/util/array.d.ts +11 -0
  147. package/lib/util/array.js +57 -0
  148. package/lib/util/assertType.js +6 -6
  149. package/lib/util/bufferedPassThrough.d.ts +76 -0
  150. package/lib/util/bufferedPassThrough.js +161 -0
  151. package/lib/util/deprecate.js +7 -5
  152. package/lib/util/didYouMean.js +1 -1
  153. package/lib/util/dump-collection.d.ts +3 -0
  154. package/lib/util/dump-collection.js +265 -0
  155. package/lib/util/extractFields.js +2 -2
  156. package/lib/util/inflector.d.ts +8 -0
  157. package/lib/util/inflector.js +16 -0
  158. package/lib/util/requestAssertions.js +7 -7
  159. package/lib/util/wildcard.js +55 -0
  160. package/package-lock.json +538 -78
  161. package/package.json +5 -3
  162. package/lib/api/openApiGenerator.d.ts +0 -7
  163. package/lib/api/openApiGenerator.js +0 -197
  164. package/lib/types/InternalLogger.d.ts +0 -25
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /*
2
3
  * Kuzzle, a backend software, self-hostable and ready to use
3
4
  * to power modern apps
@@ -18,259 +19,199 @@
18
19
  * See the License for the specific language governing permissions and
19
20
  * limitations under the License.
20
21
  */
21
-
22
- 'use strict';
23
-
24
- const _ = require('lodash');
25
- const Bluebird = require('bluebird');
26
-
27
- const Rights = require('./rights');
28
- const kerror = require('../../kerror');
29
- const { isPlainObject } = require('../../util/safeObject');
30
-
31
- const assertionError = kerror.wrap('api', 'assert');
32
-
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Profile = void 0;
27
+ const lodash_1 = __importDefault(require("lodash"));
28
+ const bluebird_1 = __importDefault(require("bluebird"));
29
+ const rights_1 = __importDefault(require("./rights"));
30
+ const kerror_1 = __importDefault(require("../../kerror"));
31
+ const safeObject_1 = require("../../util/safeObject");
32
+ const assertionError = kerror_1.default.wrap('api', 'assert');
33
33
  /**
34
34
  * @class Profile
35
35
  */
36
36
  class Profile {
37
- constructor() {
38
- this._id = null;
39
- this.policies = [];
40
- this.rateLimit = 0;
41
- }
42
-
43
- /**
44
- * @param {Kuzzle} kuzzle
45
- *
46
- * @returns {Promise}
47
- */
48
- async getPolicies() {
49
- if (!global.kuzzle) {
50
- throw kerror.get('security', 'profile', 'uninitialized', this._id);
37
+ constructor() {
38
+ this._id = null;
39
+ this.policies = [];
40
+ this.optimizedPolicies = [];
41
+ this.rateLimit = 0;
51
42
  }
52
-
53
- return Bluebird.map(this.policies, async ({restrictedTo, roleId}) => {
54
- const role = await global.kuzzle.ask('core:security:role:get', roleId);
55
- return {restrictedTo, role};
56
- });
57
- }
58
-
59
- /**
60
- * @param {Request} request
61
- * @param {Kuzzle} kuzzle
62
- * @returns {Promise<boolean>}
63
- */
64
- async isActionAllowed(request) {
65
- if (this.policies === undefined || this.policies.length === 0) {
66
- return false;
67
- }
68
-
69
- const policies = await this.getPolicies();
70
-
71
- const results = await Bluebird.map(
72
- policies,
73
- policy => policy.role.isActionAllowed(request, policy.restrictedTo));
74
-
75
- return results.includes(true);
76
- }
77
-
78
- /**
79
- * Validates the Profile format
80
- *
81
- * @param {Object} [options]
82
- * @param {boolean} [options.strict] - If true, only allows resctrictions on
83
- * existing indexes/collections
84
- * @returns {Promise}
85
- */
86
- async validateDefinition({ strict = false } = {}) {
87
- this.validateRateLimit();
88
-
89
- if (!this.policies) {
90
- throw assertionError.get('missing_argument', `${this._id}.policies`);
43
+ /**
44
+ * @param {Kuzzle} kuzzle
45
+ *
46
+ * @returns {Promise}
47
+ */
48
+ async getPolicies() {
49
+ if (!global.kuzzle) {
50
+ throw kerror_1.default.get('security', 'profile', 'uninitialized', this._id);
51
+ }
52
+ return bluebird_1.default.map(this.optimizedPolicies, async ({ restrictedTo, roleId }) => {
53
+ const role = await global.kuzzle.ask('core:security:role:get', roleId);
54
+ return { restrictedTo, role };
55
+ });
91
56
  }
92
-
93
- if (!Array.isArray(this.policies)) {
94
- throw assertionError.get('invalid_type', `${this._id}.policies`, 'object[]');
57
+ /**
58
+ * @param {Request} request
59
+ * @returns {Promise}
60
+ */
61
+ async getAllowedPolicies(request) {
62
+ if (this.optimizedPolicies === undefined || this.optimizedPolicies.length === 0) {
63
+ return [];
64
+ }
65
+ const policies = await this.getPolicies();
66
+ return policies.filter(policy => policy.role.isActionAllowed(request));
95
67
  }
96
-
97
- if (this.policies.length === 0) {
98
- throw assertionError.get('empty_argument', `${this._id}.policies`);
68
+ /**
69
+ * @param {Request} request
70
+ * @returns {Promise<boolean>}
71
+ */
72
+ async isActionAllowed(request) {
73
+ if (this.optimizedPolicies === undefined || this.optimizedPolicies.length === 0) {
74
+ return false;
75
+ }
76
+ const allowedPolicies = await this.getAllowedPolicies(request);
77
+ return allowedPolicies
78
+ .some(policy => policy.role.checkRestrictions(request.input.args.index, request.input.args.collection, policy.restrictedTo));
99
79
  }
100
-
101
- let i = 0;
102
- for (const policy of this.policies) {
103
- if (!policy.roleId) {
104
- throw assertionError.get('missing_argument', `${this._id}.policies[${i}].roleId`);
105
- }
106
-
107
- for (const member of Object.keys(policy)) {
108
- if (member !== 'roleId' && member !== 'restrictedTo') {
109
- throw assertionError.get(
110
- 'unexpected_argument',
111
- `${this._id}.policies[${i}].${member}`,
112
- '"roleId", "restrictedTo"');
80
+ /**
81
+ * Validates the Profile format
82
+ *
83
+ * @param {Object} [options]
84
+ * @param {boolean} [options.strict] - If true, only allows resctrictions on
85
+ * existing indexes/collections
86
+ * @returns {Promise}
87
+ */
88
+ async validateDefinition({ strict = false } = {}) {
89
+ this.validateRateLimit();
90
+ if (!this.policies) {
91
+ throw assertionError.get('missing_argument', `${this._id}.policies`);
113
92
  }
114
- }
115
-
116
- if (policy.restrictedTo) {
117
- if (!Array.isArray(policy.restrictedTo)) {
118
- throw assertionError.get(
119
- 'invalid_type',
120
- `${this._id}.policies[${i}].restrictedTo`,
121
- 'object[]');
93
+ if (!Array.isArray(this.policies)) {
94
+ throw assertionError.get('invalid_type', `${this._id}.policies`, 'object[]');
122
95
  }
123
-
124
- let j = 0;
125
- for (const restriction of policy.restrictedTo) {
126
- if (!isPlainObject(restriction)) {
127
- throw assertionError.get(
128
- 'invalid_type',
129
- `${this._id}.policies[${i}].restrictedTo[${restriction}]`,
130
- 'object');
131
- }
132
-
133
- if (restriction.index === null || restriction.index === undefined) {
134
- throw assertionError.get(
135
- 'missing_argument',
136
- `${this._id}.policies[${i}].restrictedTo[${j}].index`);
137
- }
138
-
139
- if (strict) {
140
- const indexExists = await global.kuzzle.ask(
141
- 'core:storage:public:index:exist',
142
- restriction.index);
143
-
144
- if (!indexExists) {
145
- throw kerror.get(
146
- 'services',
147
- 'storage',
148
- 'unknown_index',
149
- restriction.index);
150
- }
151
- }
152
-
153
- if ( restriction.collections !== undefined
154
- && restriction.collections !== null
155
- ) {
156
- if (!Array.isArray(restriction.collections)) {
157
- throw assertionError.get(
158
- 'invalid_type',
159
- `${this._id}.policies[${i}].restrictedTo[${j}].collections`,
160
- 'string[]');
96
+ if (this.policies.length === 0) {
97
+ throw assertionError.get('empty_argument', `${this._id}.policies`);
98
+ }
99
+ let i = 0;
100
+ for (const policy of this.policies) {
101
+ if (!policy.roleId) {
102
+ throw assertionError.get('missing_argument', `${this._id}.policies[${i}].roleId`);
161
103
  }
162
-
163
- if (strict) {
164
- const invalidCollections = [];
165
- for (const collection of restriction.collections) {
166
- const isValid = await global.kuzzle.ask(
167
- 'core:storage:public:collection:exist',
168
- restriction.index,
169
- collection);
170
-
171
- if (!isValid) {
172
- invalidCollections.push(collection);
104
+ for (const member of Object.keys(policy)) {
105
+ if (member !== 'roleId' && member !== 'restrictedTo') {
106
+ throw assertionError.get('unexpected_argument', `${this._id}.policies[${i}].${member}`, '"roleId", "restrictedTo"');
173
107
  }
174
- }
175
-
176
- if (invalidCollections.length > 0) {
177
- throw kerror.get(
178
- 'services',
179
- 'storage',
180
- 'unknown_collection',
181
- restriction.index,
182
- invalidCollections);
183
- }
184
108
  }
185
- }
186
-
187
- for (const member of Object.keys(restriction)) {
188
- if (member !== 'index' && member !== 'collections') {
189
- throw assertionError.get(
190
- 'unexpected_argument',
191
- `${this._id}.policies[${i}].restrictedTo[${j}].${member}`,
192
- '"index", "collections"');
109
+ if (policy.restrictedTo) {
110
+ if (!Array.isArray(policy.restrictedTo)) {
111
+ throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo`, 'object[]');
112
+ }
113
+ let j = 0;
114
+ for (const restriction of policy.restrictedTo) {
115
+ if (!(0, safeObject_1.isPlainObject)(restriction)) {
116
+ throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo[${restriction}]`, 'object');
117
+ }
118
+ if (restriction.index === null || restriction.index === undefined) {
119
+ throw assertionError.get('missing_argument', `${this._id}.policies[${i}].restrictedTo[${j}].index`);
120
+ }
121
+ if (strict) {
122
+ const indexExists = await global.kuzzle.ask('core:storage:public:index:exist', restriction.index);
123
+ if (!indexExists) {
124
+ throw kerror_1.default.get('services', 'storage', 'unknown_index', restriction.index);
125
+ }
126
+ }
127
+ if (restriction.collections !== undefined
128
+ && restriction.collections !== null) {
129
+ if (!Array.isArray(restriction.collections)) {
130
+ throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo[${j}].collections`, 'string[]');
131
+ }
132
+ if (strict) {
133
+ const invalidCollections = [];
134
+ for (const collection of restriction.collections) {
135
+ const isValid = await global.kuzzle.ask('core:storage:public:collection:exist', restriction.index, collection);
136
+ if (!isValid) {
137
+ invalidCollections.push(collection);
138
+ }
139
+ }
140
+ if (invalidCollections.length > 0) {
141
+ throw kerror_1.default.get('services', 'storage', 'unknown_collection', restriction.index, invalidCollections);
142
+ }
143
+ }
144
+ }
145
+ for (const member of Object.keys(restriction)) {
146
+ if (member !== 'index' && member !== 'collections') {
147
+ throw assertionError.get('unexpected_argument', `${this._id}.policies[${i}].restrictedTo[${j}].${member}`, '"index", "collections"');
148
+ }
149
+ }
150
+ j++;
151
+ }
193
152
  }
194
- }
195
-
196
- j++;
153
+ i++;
197
154
  }
198
- }
199
-
200
- i++;
155
+ return true;
201
156
  }
202
-
203
- return true;
204
- }
205
-
206
- /**
207
- * Resolves an array of rights related to the profile's roles.
208
- *
209
- * @returns {Promise}
210
- */
211
- async getRights () {
212
- const profileRights = {};
213
-
214
- const policies = await this.getPolicies();
215
-
216
- for (const policy of policies) {
217
- const role = policy.role;
218
- let restrictedTo = _.cloneDeep(policy.restrictedTo);
219
-
220
- if (restrictedTo === undefined || restrictedTo.length === 0) {
221
- restrictedTo = [{collections: ['*'], index: '*'}];
222
- }
223
-
224
- for (const [controller, rights] of Object.entries(role.controllers)) {
225
- for (const [action, actionRights] of Object.entries(rights.actions)) {
226
- for (const restriction of restrictedTo) {
227
- if (restriction.collections === undefined
228
- || restriction.collections.length === 0
229
- ) {
230
- restriction.collections = ['*'];
157
+ /**
158
+ * Resolves an array of rights related to the profile's roles.
159
+ *
160
+ * @returns {Promise}
161
+ */
162
+ async getRights() {
163
+ const profileRights = {};
164
+ const policies = await this.getPolicies();
165
+ for (const policy of policies) {
166
+ const role = policy.role;
167
+ let restrictedTo = lodash_1.default.cloneDeep(policy.restrictedTo);
168
+ if (restrictedTo === undefined || restrictedTo.size === 0) {
169
+ restrictedTo = new Map([['*', ['*']]]);
231
170
  }
232
-
233
- for (const collection of restriction.collections) {
234
- const rightsItem = {
235
- action,
236
- collection,
237
- controller,
238
- index: restriction.index,
239
- value: actionRights
240
- };
241
- const rightsObject = {
242
- [this.constructor._hash(rightsItem)]: rightsItem
243
- };
244
-
245
- _.assignWith(profileRights, rightsObject, Rights.merge);
171
+ for (const [controller, rights] of Object.entries(role.controllers)) {
172
+ for (const [action, actionRights] of Object.entries(rights.actions)) {
173
+ for (const [restrictedIndex, restrictedCollections] of restrictedTo.entries()) {
174
+ let collections = restrictedCollections;
175
+ if (restrictedCollections === undefined
176
+ || restrictedCollections.length === 0) {
177
+ collections = ['*'];
178
+ }
179
+ for (const collection of collections) {
180
+ const rightsItem = {
181
+ action,
182
+ collection,
183
+ controller,
184
+ index: restrictedIndex,
185
+ value: actionRights
186
+ };
187
+ const rightsObject = {
188
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
189
+ // @ts-ignore
190
+ [this.constructor._hash(rightsItem)]: rightsItem
191
+ };
192
+ lodash_1.default.assignWith(profileRights, rightsObject, rights_1.default.merge);
193
+ }
194
+ }
195
+ }
246
196
  }
247
- }
248
197
  }
249
- }
250
- }
251
-
252
- return profileRights;
253
- }
254
-
255
- static _hash () {
256
- return false;
257
- }
258
-
259
- validateRateLimit () {
260
- if (this.rateLimit === null || this.rateLimit === undefined) {
261
- this.rateLimit = 0;
198
+ return profileRights;
262
199
  }
263
-
264
- if ( typeof this.rateLimit !== 'number'
265
- || !Number.isInteger(this.rateLimit)
266
- ) {
267
- throw assertionError.get('invalid_type', 'rateLimit', 'integer');
200
+ static _hash() {
201
+ return false;
268
202
  }
269
-
270
- if (this.rateLimit < 0) {
271
- throw assertionError.get('invalid_argument', 'rateLimit', 'positive integer, or zero');
203
+ validateRateLimit() {
204
+ if (this.rateLimit === null || this.rateLimit === undefined) {
205
+ this.rateLimit = 0;
206
+ }
207
+ if (typeof this.rateLimit !== 'number'
208
+ || !Number.isInteger(this.rateLimit)) {
209
+ throw assertionError.get('invalid_type', 'rateLimit', 'integer');
210
+ }
211
+ if (this.rateLimit < 0) {
212
+ throw assertionError.get('invalid_argument', 'rateLimit', 'positive integer, or zero');
213
+ }
272
214
  }
273
- }
274
215
  }
275
-
276
- module.exports = Profile;
216
+ exports.Profile = Profile;
217
+ //# sourceMappingURL=profile.js.map
@@ -38,4 +38,4 @@ function merge (prev, cur) {
38
38
  return cur;
39
39
  }
40
40
 
41
- module.exports = {merge};
41
+ module.exports = { merge };
@@ -0,0 +1,40 @@
1
+ import { ControllerRight, ControllerRights } from '../../types/ControllerRights';
2
+ import { KuzzleRequest } from '../../../index';
3
+ import { OptimizedPolicyRestrictions } from '../../types/PolicyRestrictions';
4
+ /**
5
+ * @class Role
6
+ */
7
+ export declare class Role {
8
+ controllers: ControllerRights;
9
+ _id: string;
10
+ constructor();
11
+ /**
12
+ * @param {Request} request
13
+ * @returns {boolean}
14
+ */
15
+ isActionAllowed(request: KuzzleRequest): boolean;
16
+ /**
17
+ * @returns {Promise}
18
+ */
19
+ validateDefinition(): Promise<void>;
20
+ /**
21
+ * @param {String} index
22
+ * @param {String} collection
23
+ * @param {Map<string, string[]>} restrictedTo Restricted indexes
24
+ * @returns {Boolean} resolves to a Boolean value
25
+ */
26
+ checkRestrictions(index: string, collection: string, restrictedTo: OptimizedPolicyRestrictions): boolean;
27
+ /**
28
+ * Verifies that a controller rights definition is correct
29
+ *
30
+ * @param {Array.<string, Object>}
31
+ * @throws If the controller definition is invalid
32
+ */
33
+ validateControllerRights(name: string, controller: ControllerRight): void;
34
+ /**
35
+ * Checks if current role allows to log in
36
+ *
37
+ * @returns {boolean}
38
+ */
39
+ canLogIn(): boolean;
40
+ }