kuzzle 2.19.12 → 2.20.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.
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/api/controllers/authController.d.ts +164 -0
- package/lib/api/controllers/authController.js +469 -654
- package/lib/api/controllers/baseController.d.ts +74 -0
- package/lib/api/controllers/baseController.js +169 -221
- package/lib/api/controllers/documentController.js +6 -8
- package/lib/api/funnel.js +4 -1
- package/lib/api/httpRoutes.js +6 -0
- package/lib/api/openapi/openApiGenerator.js +2 -2
- package/lib/api/request/kuzzleRequest.d.ts +3 -1
- package/lib/api/request/kuzzleRequest.js +32 -0
- package/lib/core/backend/backendController.js +2 -2
- package/lib/core/backend/backendPlugin.js +2 -2
- package/lib/core/network/protocols/httpwsProtocol.js +0 -12
- package/lib/core/plugin/pluginRepository.js +1 -1
- package/lib/core/plugin/pluginsManager.js +1 -1
- package/lib/core/security/index.js +1 -1
- package/lib/core/security/profileRepository.d.ts +14 -4
- package/lib/core/security/profileRepository.js +2 -2
- package/lib/core/security/roleRepository.js +1 -1
- package/lib/core/security/tokenRepository.d.ts +73 -0
- package/lib/core/security/tokenRepository.js +359 -460
- package/lib/core/security/userRepository.js +1 -1
- package/lib/core/shared/repository.d.ts +178 -0
- package/lib/core/shared/repository.js +365 -450
- package/lib/kerror/codes/7-security.json +6 -0
- package/lib/model/security/token.d.ts +2 -0
- package/lib/model/security/token.js +1 -0
- package/lib/service/storage/elasticsearch.js +4 -0
- package/lib/util/{inflector.d.ts → Inflector.d.ts} +5 -0
- package/lib/util/{inflector.js → Inflector.js} +12 -1
- package/package.json +11 -4
|
@@ -83,14 +83,11 @@ const HTTP_ALLOWED_CONTENT_TYPES = [
|
|
|
83
83
|
];
|
|
84
84
|
const HTTP_SKIPPED_HEADERS = ["content-length", "set-cookie"];
|
|
85
85
|
const HTTP_HEADER_CONNECTION = Buffer.from("Connection");
|
|
86
|
-
const HTTP_HEADER_CONTENT_LENGTH = Buffer.from("Content-Length");
|
|
87
86
|
const HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = Buffer.from(
|
|
88
87
|
"Access-Control-Allow-Origin"
|
|
89
88
|
);
|
|
90
89
|
const HTTP_HEADER_SET_COOKIE = Buffer.from("Set-Cookie");
|
|
91
90
|
const HTTP_HEADER_VARY = Buffer.from("Vary");
|
|
92
|
-
const HTTP_HEADER_TRANSFER_ENCODING = Buffer.from("Transfer-Encoding");
|
|
93
|
-
const CHUNKED = Buffer.from("chunked");
|
|
94
91
|
const WILDCARD = Buffer.from("*");
|
|
95
92
|
const ORIGIN = Buffer.from("Origin");
|
|
96
93
|
const X_KUZZLE_REQUEST_ID = Buffer.from("X-Kuzzle-Request-Id");
|
|
@@ -782,15 +779,6 @@ class HttpWsProtocol extends Protocol {
|
|
|
782
779
|
// Send Headers in one go
|
|
783
780
|
response.cork(() => {
|
|
784
781
|
this.httpWriteRequestHeaders(request, response, message);
|
|
785
|
-
|
|
786
|
-
if (streamSizeFixed) {
|
|
787
|
-
response.writeHeader(
|
|
788
|
-
HTTP_HEADER_CONTENT_LENGTH,
|
|
789
|
-
Buffer.from(httpStream.totalBytes.toString())
|
|
790
|
-
);
|
|
791
|
-
} else {
|
|
792
|
-
response.writeHeader(HTTP_HEADER_TRANSFER_ENCODING, CHUNKED);
|
|
793
|
-
}
|
|
794
782
|
});
|
|
795
783
|
|
|
796
784
|
httpStream.stream.on("data", (chunk) => {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
const { merge } = require("lodash");
|
|
25
25
|
|
|
26
26
|
const { NotFoundError } = require("../../kerror/errors");
|
|
27
|
-
const Repository = require("../shared/repository");
|
|
27
|
+
const { Repository } = require("../shared/repository");
|
|
28
28
|
const cacheDbEnum = require("../cache/cacheDbEnum");
|
|
29
29
|
|
|
30
30
|
class PluginRepository extends Repository {
|
|
@@ -30,7 +30,7 @@ const _ = require("lodash");
|
|
|
30
30
|
|
|
31
31
|
const kerror = require("../../kerror");
|
|
32
32
|
const didYouMean = require("../../util/didYouMean");
|
|
33
|
-
const { Inflector } = require("../../util/
|
|
33
|
+
const { Inflector } = require("../../util/Inflector");
|
|
34
34
|
const debug = require("../../util/debug")("kuzzle:plugins");
|
|
35
35
|
const { KuzzleError } = require("../../kerror/errors");
|
|
36
36
|
const { has, get, isPlainObject } = require("../../util/safeObject");
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
const RoleRepository = require("./roleRepository");
|
|
25
25
|
const { ProfileRepository } = require("./profileRepository");
|
|
26
|
-
const TokenRepository = require("./tokenRepository");
|
|
26
|
+
const { TokenRepository } = require("./tokenRepository");
|
|
27
27
|
const UserRepository = require("./userRepository");
|
|
28
28
|
const SecurityLoader = require("./securityLoader");
|
|
29
29
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="lodash" />
|
|
2
2
|
import { Profile } from "../../model/security/profile";
|
|
3
|
-
import Repository from "../shared/repository";
|
|
3
|
+
import { Repository } from "../shared/repository";
|
|
4
4
|
import { JSONObject } from "kuzzle-sdk";
|
|
5
5
|
/** @internal */
|
|
6
6
|
type CreateOrReplaceOptions = {
|
|
@@ -27,7 +27,7 @@ type UpdateOptions = {
|
|
|
27
27
|
* @class ProfileRepository
|
|
28
28
|
* @extends Repository
|
|
29
29
|
*/
|
|
30
|
-
export declare class ProfileRepository extends Repository {
|
|
30
|
+
export declare class ProfileRepository extends Repository<Profile> {
|
|
31
31
|
private module;
|
|
32
32
|
private profiles;
|
|
33
33
|
/**
|
|
@@ -170,7 +170,17 @@ export declare class ProfileRepository extends Repository {
|
|
|
170
170
|
private optimizePolicy;
|
|
171
171
|
toDTO(dto: Profile): Promise<JSONObject>;
|
|
172
172
|
deleteFromDatabase(id: string, options: JSONObject): Promise<any>;
|
|
173
|
-
search(searchBody: JSONObject, options: JSONObject): Promise<
|
|
174
|
-
|
|
173
|
+
search(searchBody: JSONObject, options: JSONObject): Promise<{
|
|
174
|
+
aggregations: any;
|
|
175
|
+
hits: any[];
|
|
176
|
+
scrollId: any;
|
|
177
|
+
total: any;
|
|
178
|
+
}>;
|
|
179
|
+
scroll(id: string, ttl: number): Promise<{
|
|
180
|
+
aggregations: any;
|
|
181
|
+
hits: any[];
|
|
182
|
+
scrollId: any;
|
|
183
|
+
total: any;
|
|
184
|
+
}>;
|
|
175
185
|
}
|
|
176
186
|
export {};
|
|
@@ -50,14 +50,14 @@ exports.ProfileRepository = void 0;
|
|
|
50
50
|
const lodash_1 = require("lodash");
|
|
51
51
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
52
52
|
const profile_1 = require("../../model/security/profile");
|
|
53
|
-
const repository_1 =
|
|
53
|
+
const repository_1 = require("../shared/repository");
|
|
54
54
|
const kerror = __importStar(require("../../kerror"));
|
|
55
55
|
const cacheDbEnum_1 = __importDefault(require("../cache/cacheDbEnum"));
|
|
56
56
|
/**
|
|
57
57
|
* @class ProfileRepository
|
|
58
58
|
* @extends Repository
|
|
59
59
|
*/
|
|
60
|
-
class ProfileRepository extends repository_1.
|
|
60
|
+
class ProfileRepository extends repository_1.Repository {
|
|
61
61
|
/**
|
|
62
62
|
* @constructor
|
|
63
63
|
*/
|
|
@@ -25,7 +25,7 @@ const Bluebird = require("bluebird");
|
|
|
25
25
|
|
|
26
26
|
const kuzzleStateEnum = require("../../kuzzle/kuzzleStateEnum");
|
|
27
27
|
const { Role } = require("../../model/security/role");
|
|
28
|
-
const Repository = require("../shared/repository");
|
|
28
|
+
const { Repository } = require("../shared/repository");
|
|
29
29
|
const kerror = require("../../kerror");
|
|
30
30
|
const didYouMean = require("../../util/didYouMean");
|
|
31
31
|
const cacheDbEnum = require("../cache/cacheDbEnum");
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { JSONObject } from "kuzzle-sdk";
|
|
2
|
+
import { Token } from "../../model/security/token";
|
|
3
|
+
import { Repository } from "../shared/repository";
|
|
4
|
+
import { User } from "../../model/security/user";
|
|
5
|
+
export declare class TokenRepository extends Repository<Token> {
|
|
6
|
+
private tokenGracePeriod;
|
|
7
|
+
private anonymousToken;
|
|
8
|
+
constructor(opts?: JSONObject);
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Expires the given token immediately
|
|
12
|
+
*/
|
|
13
|
+
expire(token: Token): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* We allow a grace period before expiring the token to allow
|
|
16
|
+
* queued requests to execute, but we mark the token as "refreshed" to forbid
|
|
17
|
+
* any refreshes on that token, to prevent token bombing
|
|
18
|
+
*
|
|
19
|
+
* @param user
|
|
20
|
+
* @param requestToken
|
|
21
|
+
* @param expiresIn - new token expiration delay
|
|
22
|
+
*/
|
|
23
|
+
refresh(user: User, token: Token, expiresIn: string): Promise<Token>;
|
|
24
|
+
/**
|
|
25
|
+
* @param user
|
|
26
|
+
* @param options - { algorithm, expiresIn, bypassMaxTTL (false), type (authToken) }
|
|
27
|
+
*
|
|
28
|
+
* @returns {Promise.<Object>} { _id, jwt, userId, ttl, expiresAt }
|
|
29
|
+
*/
|
|
30
|
+
generateToken(user: User, { algorithm, expiresIn, bypassMaxTTL, type, singleUse, }?: {
|
|
31
|
+
algorithm?: string;
|
|
32
|
+
expiresIn?: string;
|
|
33
|
+
bypassMaxTTL?: boolean;
|
|
34
|
+
type?: string;
|
|
35
|
+
singleUse?: boolean;
|
|
36
|
+
}): Promise<Token>;
|
|
37
|
+
/**
|
|
38
|
+
* Persists a token in the cache
|
|
39
|
+
*
|
|
40
|
+
* @param encodedToken - Encoded token
|
|
41
|
+
* @param userId - User ID
|
|
42
|
+
* @param ttl - TTL in ms (-1 for infinite duration)
|
|
43
|
+
*/
|
|
44
|
+
persistForUser(encodedToken: string, userId: string, { ttl, singleUse, }: {
|
|
45
|
+
ttl: number;
|
|
46
|
+
singleUse: boolean;
|
|
47
|
+
}): Promise<Token>;
|
|
48
|
+
verifyToken(token: string): Promise<Token>;
|
|
49
|
+
removeTokenPrefix(token: string): string;
|
|
50
|
+
loadForUser(userId: string, encodedToken: string): Promise<Token>;
|
|
51
|
+
hydrate(userToken: any, data: any): Promise<any>;
|
|
52
|
+
serializeToDatabase(token: any): any;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes tokens affiliated to the provided user identifier
|
|
55
|
+
*/
|
|
56
|
+
deleteByKuid(kuid: string, { keepApiKeys }?: {
|
|
57
|
+
keepApiKeys?: boolean;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Loads authentication token from API key into Redis
|
|
61
|
+
*/
|
|
62
|
+
private loadApiKeys;
|
|
63
|
+
/**
|
|
64
|
+
* The repository main class refreshes automatically the TTL
|
|
65
|
+
* of accessed entries, letting only unaccessed entries expire
|
|
66
|
+
*
|
|
67
|
+
* But tokens' TTL must remain the same than their expiration time,
|
|
68
|
+
* refreshing a token entry has no meaning.
|
|
69
|
+
*
|
|
70
|
+
* So we need to override the TTL auto-refresh function to disable it
|
|
71
|
+
*/
|
|
72
|
+
refreshCacheTTL(): void;
|
|
73
|
+
}
|