kuzzle 2.30.0-beta.1 → 2.30.1-beta.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.
|
@@ -267,11 +267,15 @@ function initMapping() {
|
|
|
267
267
|
kassert.assertBodyAttributeType(request, "entries", "array");
|
|
268
268
|
|
|
269
269
|
val.forEach((v) => {
|
|
270
|
-
if (
|
|
270
|
+
if (
|
|
271
|
+
typeof v !== "object" ||
|
|
272
|
+
!v.field ||
|
|
273
|
+
(!v.value && v.value !== 0)
|
|
274
|
+
) {
|
|
271
275
|
throw kerror.get(
|
|
272
276
|
"invalid_argument",
|
|
273
277
|
"entries",
|
|
274
|
-
"<array of
|
|
278
|
+
"<array of objects>",
|
|
275
279
|
);
|
|
276
280
|
}
|
|
277
281
|
|
|
@@ -348,7 +352,11 @@ function initMapping() {
|
|
|
348
352
|
kassert.assertBodyHasAttribute(request, "entries");
|
|
349
353
|
kassert.assertBodyAttributeType(request, "entries", "array");
|
|
350
354
|
val.forEach((entry) => {
|
|
351
|
-
if (
|
|
355
|
+
if (
|
|
356
|
+
typeof entry !== "object" ||
|
|
357
|
+
!entry.key ||
|
|
358
|
+
(!entry.value && entry.value !== 0)
|
|
359
|
+
) {
|
|
352
360
|
throw kerror.get(
|
|
353
361
|
"invalid_argument",
|
|
354
362
|
"entries",
|
|
@@ -29,7 +29,6 @@ type UpdateOptions = {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
31
31
|
private module;
|
|
32
|
-
private profiles;
|
|
33
32
|
/**
|
|
34
33
|
* @constructor
|
|
35
34
|
*/
|
|
@@ -42,7 +41,9 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
42
41
|
* @returns {Promise.<Promise>}
|
|
43
42
|
* @throws {NotFoundError} If the corresponding profile doesn't exist
|
|
44
43
|
*/
|
|
45
|
-
load(id: string
|
|
44
|
+
load(id: string, options?: {
|
|
45
|
+
key?: string;
|
|
46
|
+
}): Promise<Profile>;
|
|
46
47
|
/**
|
|
47
48
|
* Loads a Profile object given its id.
|
|
48
49
|
* Stores the promise of the profile being loaded in the memcache
|
|
@@ -140,16 +141,6 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
140
141
|
* @returns {Promise<Profile>}
|
|
141
142
|
*/
|
|
142
143
|
fromDTO(dto: JSONObject): Promise<Profile>;
|
|
143
|
-
/**
|
|
144
|
-
* @override
|
|
145
|
-
*/
|
|
146
|
-
truncate(opts: JSONObject): Promise<void>;
|
|
147
|
-
/**
|
|
148
|
-
* Invalidate the cache entries for the given profile. If none is provided,
|
|
149
|
-
* the entire cache is emptied.
|
|
150
|
-
* @param {string} [profileId]
|
|
151
|
-
*/
|
|
152
|
-
invalidate(profileId?: string): void;
|
|
153
144
|
/**
|
|
154
145
|
* Optimize each policy to get a O(1) index access time
|
|
155
146
|
* and a O(log(n)) collection search time.
|
|
@@ -168,8 +159,8 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
|
|
|
168
159
|
* @param policy
|
|
169
160
|
*/
|
|
170
161
|
private optimizePolicy;
|
|
171
|
-
toDTO(dto: Profile):
|
|
172
|
-
deleteFromDatabase(id: string, options: JSONObject):
|
|
162
|
+
toDTO(dto: Profile): JSONObject;
|
|
163
|
+
deleteFromDatabase(id: string, options: JSONObject): any;
|
|
173
164
|
search(searchBody: JSONObject, options: JSONObject): Promise<{
|
|
174
165
|
aggregations: any;
|
|
175
166
|
hits: any[];
|
|
@@ -51,7 +51,6 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
|
51
51
|
const lodash_1 = require("lodash");
|
|
52
52
|
const kerror = __importStar(require("../../kerror"));
|
|
53
53
|
const profile_1 = require("../../model/security/profile");
|
|
54
|
-
const cacheDbEnum_1 = require("../cache/cacheDbEnum");
|
|
55
54
|
const ObjectRepository_1 = require("../shared/ObjectRepository");
|
|
56
55
|
/**
|
|
57
56
|
* @class ProfileRepository
|
|
@@ -62,12 +61,8 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
62
61
|
* @constructor
|
|
63
62
|
*/
|
|
64
63
|
constructor(securityModule) {
|
|
65
|
-
super({
|
|
66
|
-
cache: cacheDbEnum_1.cacheDbEnum.NONE,
|
|
67
|
-
store: global.kuzzle.internalIndex,
|
|
68
|
-
});
|
|
64
|
+
super({ store: global.kuzzle.internalIndex });
|
|
69
65
|
this.module = securityModule;
|
|
70
|
-
this.profiles = new Map();
|
|
71
66
|
this.collection = "profiles";
|
|
72
67
|
this.ObjectConstructor = profile_1.Profile;
|
|
73
68
|
}
|
|
@@ -111,7 +106,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
111
106
|
*
|
|
112
107
|
* @param {String} [id] - profile identifier
|
|
113
108
|
*/
|
|
114
|
-
global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.
|
|
109
|
+
global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.deleteFromCache(id));
|
|
115
110
|
/**
|
|
116
111
|
* Gets multiple profiles
|
|
117
112
|
* @param {Array} ids
|
|
@@ -156,13 +151,18 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
156
151
|
* @returns {Promise.<Promise>}
|
|
157
152
|
* @throws {NotFoundError} If the corresponding profile doesn't exist
|
|
158
153
|
*/
|
|
159
|
-
async load(id) {
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
async load(id, options = {}) {
|
|
155
|
+
const profile = await this.loadFromCache(id, options);
|
|
156
|
+
if (profile === null) {
|
|
157
|
+
const profileFromDatabase = await this.loadOneFromDatabase(id);
|
|
158
|
+
if (profileFromDatabase !== null) {
|
|
159
|
+
await this.persistToCache(profileFromDatabase);
|
|
160
|
+
profileFromDatabase.optimizedPolicies = this.optimizePolicies(profileFromDatabase.policies);
|
|
161
|
+
}
|
|
162
|
+
return profileFromDatabase;
|
|
162
163
|
}
|
|
163
|
-
const profile = await super.load(id);
|
|
164
164
|
profile.optimizedPolicies = this.optimizePolicies(profile.policies);
|
|
165
|
-
this.
|
|
165
|
+
await this.refreshCacheTTL(profile);
|
|
166
166
|
return profile;
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
@@ -185,14 +185,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
185
185
|
throw kerror.get("api", "assert", "invalid_type", "profileIds", "string[]");
|
|
186
186
|
}
|
|
187
187
|
for (const id of profileIds) {
|
|
188
|
-
|
|
189
|
-
if (!profile) {
|
|
190
|
-
profile = this.loadOneFromDatabase(id).then((p) => {
|
|
191
|
-
p.optimizedPolicies = this.optimizePolicies(p.policies);
|
|
192
|
-
this.profiles.set(id, p);
|
|
193
|
-
return p;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
188
|
+
const profile = this.load(id);
|
|
196
189
|
profiles.push(profile);
|
|
197
190
|
}
|
|
198
191
|
return bluebird_1.default.all(profiles);
|
|
@@ -342,7 +335,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
342
335
|
}
|
|
343
336
|
}
|
|
344
337
|
await this.deleteFromDatabase(profile._id, { refresh });
|
|
345
|
-
this.
|
|
338
|
+
await this.deleteFromCache(profile._id);
|
|
346
339
|
}
|
|
347
340
|
/**
|
|
348
341
|
* From a Profile object, returns a serialized object ready to be persisted
|
|
@@ -384,9 +377,9 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
384
377
|
retryOnConflict,
|
|
385
378
|
});
|
|
386
379
|
const updatedProfile = await this.loadOneFromDatabase(profile._id);
|
|
380
|
+
await this.persistToCache(updatedProfile);
|
|
387
381
|
// Recompute optimized policies based on new policies
|
|
388
382
|
updatedProfile.optimizedPolicies = this.optimizePolicies(updatedProfile.policies);
|
|
389
|
-
this.profiles.set(profile._id, updatedProfile);
|
|
390
383
|
return updatedProfile;
|
|
391
384
|
}
|
|
392
385
|
/**
|
|
@@ -410,32 +403,6 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
410
403
|
}
|
|
411
404
|
return profile;
|
|
412
405
|
}
|
|
413
|
-
/**
|
|
414
|
-
* @override
|
|
415
|
-
*/
|
|
416
|
-
async truncate(opts) {
|
|
417
|
-
try {
|
|
418
|
-
await super.truncate(opts);
|
|
419
|
-
}
|
|
420
|
-
finally {
|
|
421
|
-
// always clear the RAM cache: even if truncate fails in the middle of it,
|
|
422
|
-
// some of the cached profiles might not be valid anymore
|
|
423
|
-
this.invalidate();
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Invalidate the cache entries for the given profile. If none is provided,
|
|
428
|
-
* the entire cache is emptied.
|
|
429
|
-
* @param {string} [profileId]
|
|
430
|
-
*/
|
|
431
|
-
invalidate(profileId) {
|
|
432
|
-
if (!profileId) {
|
|
433
|
-
this.profiles.clear();
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
this.profiles.delete(profileId);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
406
|
/**
|
|
440
407
|
* Optimize each policy to get a O(1) index access time
|
|
441
408
|
* and a O(log(n)) collection search time.
|
|
@@ -496,10 +463,10 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
|
|
|
496
463
|
// Every method described after are for testing purpose only
|
|
497
464
|
// Otherwise we cannot stub them
|
|
498
465
|
// ============================================
|
|
499
|
-
|
|
466
|
+
toDTO(dto) {
|
|
500
467
|
return super.toDTO(dto);
|
|
501
468
|
}
|
|
502
|
-
|
|
469
|
+
deleteFromDatabase(id, options) {
|
|
503
470
|
return super.deleteFromDatabase(id, options);
|
|
504
471
|
}
|
|
505
472
|
async search(searchBody, options) {
|
|
@@ -127,7 +127,7 @@ class ObjectRepository {
|
|
|
127
127
|
let response;
|
|
128
128
|
try {
|
|
129
129
|
response = await global.kuzzle.ask(`core:cache:${this.cacheDb}:get`, key);
|
|
130
|
-
if (response === null) {
|
|
130
|
+
if (response === null || response === undefined) {
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
return await this.fromDTO({ ...JSON.parse(response) });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kuzzle",
|
|
3
3
|
"author": "The Kuzzle Team <support@kuzzle.io>",
|
|
4
|
-
"version": "2.30.
|
|
4
|
+
"version": "2.30.1-beta.1",
|
|
5
5
|
"description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
|
|
6
6
|
"bin": "bin/start-kuzzle-server",
|
|
7
7
|
"scripts": {
|