| 1 | import Serializable from './serializable'; |
| 2 | |
| 3 | export default class APICredential implements Serializable { |
| 4 | id?: string; |
| 5 | type: string; |
| 6 | name: string; |
| 7 | url?: string; |
| 8 | key?: string; |
| 9 | cookie?: string; |
| 10 | params?: Record<string, string>; |
| 11 | |
| 12 | static deserialize(data: Partial<APICredential>): APICredential { |
| 13 | if (!data || |
| 14 | typeof data != 'object' || |
| 15 | typeof data.type != 'string' || |
| 16 | typeof data.name != 'string') { |
| 17 | throw new Error(`Invalid APICredential data: ${JSON.stringify(data)}`); |
| 18 | } |
| 19 | if ('params' in data) { |
| 20 | if (typeof data.params != 'object') |
| 21 | throw new Error('The params of APICredential must be Record'); |
| 22 | } |
| 23 | return new APICredential(data); |
| 24 | } |
| 25 | |
| 26 | constructor(init: Partial<APICredential>) { |
| 27 | Object.assign(this, init); |
| 28 | } |
| 29 | |
| 30 | serialize() { |
| 31 | const data: Partial<APICredential> = {type: this.type, name: this.name, url: this.url}; |
| 32 | if (this.url) |
| 33 | data.url = this.url; |
| 34 | if (this.key) |
| 35 | data.key = this.key; |
| 36 | if (this.cookie) |
| 37 | data.cookie = this.cookie; |
| 38 | if (this.params) |
| 39 | data.params = this.params; |
| 40 | return data; |
| 41 | } |
| 42 | } |
nothing calls this directly
no outgoing calls
no test coverage detected