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.
Files changed (33) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/api/controllers/authController.d.ts +164 -0
  4. package/lib/api/controllers/authController.js +469 -654
  5. package/lib/api/controllers/baseController.d.ts +74 -0
  6. package/lib/api/controllers/baseController.js +169 -221
  7. package/lib/api/controllers/documentController.js +6 -8
  8. package/lib/api/funnel.js +4 -1
  9. package/lib/api/httpRoutes.js +6 -0
  10. package/lib/api/openapi/openApiGenerator.js +2 -2
  11. package/lib/api/request/kuzzleRequest.d.ts +3 -1
  12. package/lib/api/request/kuzzleRequest.js +32 -0
  13. package/lib/core/backend/backendController.js +2 -2
  14. package/lib/core/backend/backendPlugin.js +2 -2
  15. package/lib/core/network/protocols/httpwsProtocol.js +0 -12
  16. package/lib/core/plugin/pluginRepository.js +1 -1
  17. package/lib/core/plugin/pluginsManager.js +1 -1
  18. package/lib/core/security/index.js +1 -1
  19. package/lib/core/security/profileRepository.d.ts +14 -4
  20. package/lib/core/security/profileRepository.js +2 -2
  21. package/lib/core/security/roleRepository.js +1 -1
  22. package/lib/core/security/tokenRepository.d.ts +73 -0
  23. package/lib/core/security/tokenRepository.js +359 -460
  24. package/lib/core/security/userRepository.js +1 -1
  25. package/lib/core/shared/repository.d.ts +178 -0
  26. package/lib/core/shared/repository.js +365 -450
  27. package/lib/kerror/codes/7-security.json +6 -0
  28. package/lib/model/security/token.d.ts +2 -0
  29. package/lib/model/security/token.js +1 -0
  30. package/lib/service/storage/elasticsearch.js +4 -0
  31. package/lib/util/{inflector.d.ts → Inflector.d.ts} +5 -0
  32. package/lib/util/{inflector.js → Inflector.js} +12 -1
  33. package/package.json +11 -4
@@ -23,7 +23,7 @@
23
23
 
24
24
  const { Request } = require("../../api/request");
25
25
  const debug = require("../../util/debug")("kuzzle:core:security:users");
26
- const Repository = require("../shared/repository");
26
+ const { Repository } = require("../shared/repository");
27
27
  const kerror = require("../../kerror");
28
28
  const { User } = require("../../model/security/user");
29
29
  const ApiKey = require("../../model/storage/apiKey");
@@ -0,0 +1,178 @@
1
+ import { JSONObject } from "kuzzle-sdk";
2
+ export declare class Repository<TObject extends {
3
+ _id: string;
4
+ }> {
5
+ protected ttl: number;
6
+ protected index: string;
7
+ protected collection: string;
8
+ protected ObjectConstructor: any;
9
+ protected store: any;
10
+ protected cacheDb: any;
11
+ constructor({ cache, store }?: {
12
+ cache?: any;
13
+ store?: any;
14
+ });
15
+ loadOneFromDatabase(id: string): Promise<TObject>;
16
+ loadMultiFromDatabase(ids: string[]): Promise<TObject[]>;
17
+ /**
18
+ * Search in database corresponding repository according to a query
19
+ *
20
+ * @param {object} searchBody
21
+ * @param {object} [options] - optional search arguments (from, size, scroll)
22
+ * @returns {Promise}
23
+ */
24
+ search(searchBody: any, options?: {}): Promise<{
25
+ aggregations: any;
26
+ hits: any[];
27
+ scrollId: any;
28
+ total: any;
29
+ }>;
30
+ /**
31
+ * Scroll over a paginated search request
32
+ */
33
+ scroll(scrollId: string, ttl?: string | number): Promise<{
34
+ aggregations: any;
35
+ hits: any[];
36
+ scrollId: any;
37
+ total: any;
38
+ }>;
39
+ /**
40
+ * Loads an object from Cache. Returns a promise that resolves either to the
41
+ * retrieved object of null in case it is not found.
42
+ *
43
+ * The opts object currently accepts one optional parameter: key, which forces
44
+ * the cache key to fetch.
45
+ * In case the key is not provided, it defaults to repos/<index>/<collection>/<id>, i.e.: repos/%kuzzle/users/12
46
+ *
47
+ * @param id - The id of the object to get
48
+ * @param options.key - Cache key.
49
+ */
50
+ loadFromCache(id: string, options?: {
51
+ key?: string;
52
+ }): Promise<TObject>;
53
+ /**
54
+ * Loads an object from Cache or from the Database if not available in Cache.
55
+ * Returns a promise that resolves either to the
56
+ * retrieved object of null in case it is not found.
57
+ *
58
+ * If the object is not found in Cache and found in the Database,
59
+ * it will be written to cache also.
60
+ *
61
+ * The opts object currently accepts one optional parameter: key, which forces
62
+ * the cache key to fetch.
63
+ * In case the key is not provided, it defaults to <collection>/id
64
+ * (e.g. users/12)
65
+ *
66
+ * @param id - The id of the object to get
67
+ * @param options.key - Optional cache key
68
+ */
69
+ load(id: string, options?: {
70
+ key?: string;
71
+ }): Promise<TObject>;
72
+ /**
73
+ * Persists the given object in the collection that is attached to the repository.
74
+ *
75
+ * @param object - The object to persist
76
+ * @param options.method -
77
+ * @returns {Promise}
78
+ */
79
+ persistToDatabase(object: TObject, options?: any): any;
80
+ /**
81
+ * Given an object with an id, delete it from the configured storage engines
82
+ *
83
+ * @param object - The object to delete
84
+ * @param options.key - if provided, removes the given key instead of the default one (<collection>/<id>)
85
+ */
86
+ delete(object: TObject, options?: any): Promise<void>;
87
+ /**
88
+ * Delete repository from database according to its id
89
+ */
90
+ deleteFromDatabase(id: string, options?: JSONObject): any;
91
+ /**
92
+ * Persists the given ObjectConstructor object in cache.
93
+ *
94
+ * @param object - The object to persist
95
+ * @param options.key - if provided, stores the object to the given key instead of the default one (<collection>/<id>)
96
+ * @param options.ttl - if provided, overrides the default ttl set on the repository for the current operation
97
+ */
98
+ persistToCache(object: TObject, options?: {
99
+ key?: string;
100
+ ttl?: number;
101
+ }): Promise<TObject>;
102
+ /**
103
+ * Removes the object from the Cache Engine
104
+ *
105
+ * @param id
106
+ * @param options.key - if provided, stores the object to the given key instead of the default one (<collection>/<id>)
107
+ */
108
+ deleteFromCache(id: string, options?: {
109
+ key?: string;
110
+ }): Promise<void>;
111
+ /**
112
+ * @param object
113
+ * @param options.key - if provided, stores the object to the given key instead of the default one (<collection>/<id>)
114
+ * @param options.ttl - if provided, overrides the default ttl set on the repository for the current operation
115
+ */
116
+ refreshCacheTTL(object: JSONObject, options?: {
117
+ key?: string;
118
+ ttl?: number;
119
+ }): any;
120
+ /**
121
+ * @param object
122
+ * @param options.key - if provided, stores the object to the given key instead of the default one (<collection>/<id>)
123
+ */
124
+ expireFromCache(object: TObject, options?: {
125
+ key?: string;
126
+ }): Promise<void>;
127
+ /**
128
+ * Serializes the object before being persisted to cache.
129
+ *
130
+ * @param object - The object to serialize
131
+ */
132
+ serializeToCache(object: TObject): any;
133
+ /**
134
+ * Serializes the object before being persisted to the database.
135
+ *
136
+ * @param object - The object to serialize
137
+ */
138
+ serializeToDatabase(object: TObject): Omit<TObject, "_id">;
139
+ /**
140
+ * @param {string} id
141
+ */
142
+ getCacheKey(id: string): string;
143
+ /**
144
+ * @param {object} dto
145
+ * @returns {Promise<ObjectConstructor>}
146
+ */
147
+ fromDTO(dto: JSONObject): Promise<TObject>;
148
+ /**
149
+ * @param {ObjectConstructor} o
150
+ * @returns {object}
151
+ */
152
+ toDTO(o: TObject): any;
153
+ /**
154
+ * Recursively delete all objects in repository with a scroll
155
+ *
156
+ * @param {object} options - ES options (refresh)
157
+ * @param {object} part
158
+ * @returns {Promise<integer>} total deleted objects
159
+ */
160
+ truncate(options: any): Promise<any>;
161
+ /**
162
+ * Do not override this: this function calls itself.
163
+ */
164
+ private _truncate;
165
+ /**
166
+ * @param {Array} objects
167
+ * @param {object} options
168
+ * @returns {Promise<integer>} count of deleted objects
169
+ */
170
+ private truncatePart;
171
+ /**
172
+ * Given a raw search response from ES, returns a {total: int, hits: []} object
173
+ * @param {object} raw
174
+ * @returns {Promise<object>}
175
+ * @private
176
+ */
177
+ private formatSearchResults;
178
+ }