-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathapiKey.ts
More file actions
57 lines (49 loc) · 1.5 KB
/
apiKey.ts
File metadata and controls
57 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Model, Document, Types } from 'mongoose';
import { VirtualId, MongooseTimestamps } from './mongoose';
import { Error, RouteParam } from './express';
// -------- MONGOOSE --------
/** Full Api Key interface */
export interface IApiKey extends VirtualId, MongooseTimestamps {
_id: Types.ObjectId;
__v: number;
label: string;
lastUsedAt?: Date;
hashedKey: string;
token?: string;
}
/** Mongoose document object for API Key */
export interface ApiKeyDocument
extends IApiKey,
Omit<Document<Types.ObjectId>, 'id'> {
toJSON(options?: any): IApiKey;
toObject(options?: any): IApiKey;
}
/**
* Sanitised API key object which hides the `hashedKey` field
* and can be exposed to the client
*/
export interface SanitisedApiKey
extends Pick<
ApiKeyDocument,
'id' | 'label' | 'lastUsedAt' | 'createdAt' | 'token'
> {}
/** Mongoose model for API Key */
export interface ApiKeyModel extends Model<ApiKeyDocument> {}
// -------- API --------
/**
* Response body for userController.createApiKey & userController.removeApiKey
* - Either an ApiKeyResponse or Error
*/
export type ApiKeyResponseOrError = ApiKeyResponse | Error;
/** Response for api-key related endpoints, containing list of keys */
export interface ApiKeyResponse {
apiKeys: ApiKeyDocument[];
}
/** userController.createApiKey - Request */
export interface CreateApiKeyRequestBody {
label: string;
}
/** userController.removeApiKey - Request */
export interface RemoveApiKeyRequestParams extends RouteParam {
keyId: string;
}