File size: 1,029 Bytes
b39afbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
 * All rights reserved.
 */

import { DBObject, type IDBObjectLink } from './DBObject';

interface IAPIKeyMetaData {
  name: string;
  description: string;
  revoked: boolean;
  // @deprecated
  owner: IDBObjectLink;
}

class APIKey extends DBObject {
  static readonly modelName = 'APIKey';

  meta: IAPIKeyMetaData;
  apiNamespace: string;
  variableName: string;
  vaultType: string; // Type of vault used to store the key: local, vaultwarden, etc
  key: string; // ID mapping to the actual key in the keystore
  owner: string; // _id of the owner

  constructor(id: string) {
    super(id);
    this._id = `${APIKey.modelName}:${this.id}`;
    this.meta = {
      name: '',
      description: '',
      owner: {
        id: '',
        type: '',
        name: ''
      },
      revoked: false
    };
    this.key = '';
    this.vaultType = 'local';
    this.owner = '';
    this.apiNamespace = '';
    this.variableName = '';
  }
}

export { APIKey, type IAPIKeyMetaData };