Skip to content

Commit bbbad2e

Browse files
author
William Fallon
authored
Convert Security Controller to Typescript (#663)
Converts the security.js to a TypeScript file in order to get autocompletion.
1 parent 49288ba commit bbbad2e

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ src/controllers/Realtime.js
1212
src/controllers/Index.js
1313
src/controllers/Collection.js
1414
src/controllers/Base.js
15+
src/controllers/Security.js
1516
src/core/security/User.js
1617
src/core/security/Profile.js
1718
src/core/security/Role.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ src/controllers/Index.js
4141
src/controllers/Collection.js
4242
src/controllers/Base.js
4343
src/controllers/Realtime.js
44+
src/controllers/Security.js
4445
src/core/security/User.js
4546
src/core/security/Profile.js
4647
src/core/security/Role.js

src/Kuzzle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Kuzzle extends KuzzleEventEmitter {
8383
index: IndexController;
8484
ms: any;
8585
realtime: RealtimeController;
86-
security: any;
86+
security: SecurityController;
8787
server: any;
8888

8989
private _protectedEvents: any;

src/controllers/Security.js renamed to src/controllers/Security.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { BaseController } = require('./Base');
2-
const { Role } = require('../core/security/Role');
3-
const { RoleSearchResult } = require('../core/searchResult/Role');
4-
const { Profile } = require('../core/security/Profile');
5-
const { ProfileSearchResult } = require('../core/searchResult/Profile');
6-
const { User } = require('../core/security/User');
7-
const { UserSearchResult } = require('../core/searchResult/User');
8-
9-
class SecurityController extends BaseController {
1+
import { BaseController } from './Base';
2+
import { Role } from '../core/security/Role';
3+
import { RoleSearchResult } from '../core/searchResult/Role';
4+
import { Profile } from '../core/security/Profile';
5+
import { ProfileSearchResult } from '../core/searchResult/Profile';
6+
import { User } from '../core/security/User';
7+
import { UserSearchResult } from '../core/searchResult/User';
8+
9+
export class SecurityController extends BaseController {
1010
/**
1111
* @param {Kuzzle} kuzzle
1212
*/
@@ -23,7 +23,14 @@ class SecurityController extends BaseController {
2323
*
2424
* @returns {Promise.<Object>} ApiKey { _id, _source }
2525
*/
26-
createApiKey(userId, description, options = {}) {
26+
createApiKey(
27+
userId,
28+
description,
29+
options: {
30+
expiresIn?: string | number,
31+
_id?: string,
32+
refresh?: 'wait_for',
33+
} = {}) {
2734
const request = {
2835
userId,
2936
action: 'createApiKey',
@@ -65,16 +72,20 @@ class SecurityController extends BaseController {
6572
*
6673
* @returns {Promise}
6774
*/
68-
deleteApiKey(userId, id, options = {}) {
75+
deleteApiKey(
76+
userId,
77+
id,
78+
options: {
79+
refresh?: 'wait_for',
80+
} = {}) {
6981
const request = {
7082
userId,
7183
action: 'deleteApiKey',
7284
_id: id,
7385
refresh: options.refresh
7486
};
7587

76-
return this.query(request)
77-
.then(() => {});
88+
return this.query(request);
7889
}
7990

8091
/**
@@ -86,7 +97,15 @@ class SecurityController extends BaseController {
8697
*
8798
* @returns {Promise.<object[]>} - { hits, total }
8899
*/
89-
searchApiKeys(userId, query = {}, options = {}) {
100+
searchApiKeys(
101+
userId,
102+
query = {},
103+
options: {
104+
from?: number,
105+
size?: number,
106+
lang?: string,
107+
} = {}
108+
) {
90109
const request = {
91110
userId,
92111
action: 'searchApiKeys',
@@ -110,7 +129,13 @@ class SecurityController extends BaseController {
110129
.then(response => response.result);
111130
}
112131

113-
createFirstAdmin (_id, body, options = {}) {
132+
createFirstAdmin (
133+
_id,
134+
body,
135+
options: {
136+
reset?: boolean,
137+
} = {}
138+
) {
114139
const request = {
115140
_id,
116141
body,
@@ -136,7 +161,13 @@ class SecurityController extends BaseController {
136161
response.result._source));
137162
}
138163

139-
createOrReplaceRole (_id, body, options = {}) {
164+
createOrReplaceRole (
165+
_id,
166+
body,
167+
options: {
168+
force?: boolean,
169+
} = {}
170+
) {
140171
const request = {
141172
_id,
142173
body,
@@ -176,7 +207,7 @@ class SecurityController extends BaseController {
176207
.then(response => new User(this.kuzzle, response.result._id, response.result._source));
177208
}
178209

179-
createRole (_id, body, options = {}) {
210+
createRole (_id, body, options: { force?: boolean, } = {}) {
180211
const request = {
181212
_id,
182213
body,
@@ -489,7 +520,7 @@ class SecurityController extends BaseController {
489520
.then(response => response.result);
490521
}
491522

492-
updateRole (_id, body, options = {}) {
523+
updateRole (_id, body, options: { force?: boolean, } = {}) {
493524
const request = {
494525
_id,
495526
body,
@@ -537,5 +568,3 @@ class SecurityController extends BaseController {
537568
.then(response => response.result);
538569
}
539570
}
540-
541-
module.exports = { SecurityController };

0 commit comments

Comments
 (0)