1 | import StorageInterface from "./Interfaces/StorageInterface";
|
2 | import LoggerInterface from "./Interfaces/LoggerInterface";
|
3 | declare type UrlEnviromentType = {
|
4 | [key: string]: string;
|
5 | };
|
6 | export declare const ALLOWED_ENVIROMENTS: string[];
|
7 | export declare const URL_ENVIROMENTS: UrlEnviromentType;
|
8 | export default class Session {
|
9 | storageInterface: StorageInterface;
|
10 | logger: LoggerInterface;
|
11 | apiKey: string | boolean;
|
12 | apiKeyIdentifier: string | boolean;
|
13 | encryptionKey: string | boolean;
|
14 | allowedIps: string[];
|
15 | isOAuthKey: boolean;
|
16 | environment: string;
|
17 | environmentUrl: string;
|
18 | publicKey: any;
|
19 | publicKeyPem: string;
|
20 | privateKey: any;
|
21 | privateKeyPem: string;
|
22 | serverPublicKey: string;
|
23 | serverPublicKeyPem: string;
|
24 | installCreated?: Date;
|
25 | installUpdated?: Date;
|
26 | installToken: string;
|
27 | deviceId: number;
|
28 | sessionToken: string;
|
29 | sessionTokenId: string | number;
|
30 | sessionId: number;
|
31 | sessionExpiryTime?: Date;
|
32 | sessionTimeout: number;
|
33 | sessionExpiryTimeChecker?: any;
|
34 | userInfo: any;
|
35 | storageKeyLocation: string;
|
36 | storageIvLocation: string;
|
37 | constructor(storageInterface: StorageInterface, loggerInterface: LoggerInterface);
|
38 | /**
|
39 | * Checks default values and looks in storage interface
|
40 | * @param {{forceNewKeypair: boolean}} options
|
41 | * Promise<void>}
{ |
42 | */
|
43 | setup(apiKey: string | false, allowedIps?: string[], environment?: string, encryptionKey?: string | boolean): Promise<boolean>;
|
44 | /**
|
45 | * Updates the encryption key and stores data using that new key
|
46 | * @param {string} encryptionKey
|
47 | * @returns {Promise<boolean>}
|
48 | */
|
49 | setEncryptionKey(encryptionKey: string): Promise<boolean>;
|
50 | /**
|
51 | * Setup the keypair and generate a new one when required
|
52 | * @param {boolean} forceNewKeypair
|
53 | * @param {boolean} ignoreCI - if true the hardcoded certs won't be used even if process.env.CI is set
|
54 | * @returns {Promise<boolean>}
|
55 | */
|
56 | setupKeypair(forceNewKeypair?: boolean, bitSize?: number, ignoreCI?: boolean): Promise<boolean>;
|
57 | /**
|
58 | * Checks if a session is stored and verifies/loads it into this instance
|
59 | * @returns {Promise.<boolean>}
|
60 | */
|
61 | loadSession(): Promise<boolean>;
|
62 | /**
|
63 | * Stores this session using the storageInterface
|
64 | * @returns {Promise.<void>}
|
65 | */
|
66 | storeSession(): Promise<boolean>;
|
67 | /**
|
68 | * Resets all values to default and remove data from storage
|
69 | * @returns {Promise<void>}
|
70 | */
|
71 | destroySession(): Promise<any>;
|
72 | /**
|
73 | * Removes info from the object, keeps stored data in
|
74 | * @param {boolean} save
|
75 | * @returns {Promise<boolean>}
|
76 | */
|
77 | destroyInstallationMemory(): Promise<void>;
|
78 | /**
|
79 | * Destroys only the data associated with the api session
|
80 | * @param {boolean} save
|
81 | * @returns {Promise<undefined>}
|
82 | */
|
83 | destroyApiSession(save?: boolean): Promise<boolean>;
|
84 | /**
|
85 | * Destroys only the data associated with the installation
|
86 | * @param {boolean} save
|
87 | * @returns {Promise<undefined>}
|
88 | */
|
89 | destroyApiInstallation(save?: boolean): Promise<boolean>;
|
90 | /**
|
91 | * Destroys only the data associated with the device installation
|
92 | * @param {boolean} save
|
93 | * @returns {Promise<undefined>}
|
94 | */
|
95 | destroyApiDeviceInstallation(save?: boolean): Promise<boolean>;
|
96 | /**
|
97 | * Attempt to decrypt the session data with our stored IV and encryption key
|
98 | * @param encryptedSession
|
99 | * @returns {Promise<any>}
|
100 | */
|
101 | private decryptSession;
|
102 | /**
|
103 | * Attempt to encrypt the session data with encryption key
|
104 | * @param sessionData
|
105 | * @returns {Promise<boolean>}
|
106 | */
|
107 | private encryptSession;
|
108 | /**
|
109 | * @param data
|
110 | * @param {string} data_location
|
111 | * @param {string} iv_location
|
112 | * @returns {Promise<boolean>}
|
113 | */
|
114 | storeEncryptedData(data: any, location: string): Promise<boolean>;
|
115 | /**
|
116 | * @param {string} data_location
|
117 | * @param {string} iv_location
|
118 | * @returns {Promise<any>}
|
119 | */
|
120 | loadEncryptedData(data_location: string, iv_location?: string): Promise<any>;
|
121 | /**
|
122 | * Wrapper around the storage interface for remove calls
|
123 | * @param key
|
124 | * @param {boolean} silent
|
125 | * @returns {Promise<any>}
|
126 | */
|
127 | asyncStorageRemove(key: string, silent?: boolean): Promise<any>;
|
128 | /**
|
129 | * Wrapper around the storage interface for get calls
|
130 | * @param key
|
131 | * @param {boolean} silent
|
132 | * @returns {Promise<any>}
|
133 | */
|
134 | asyncStorageGet(key: string, silent?: boolean): Promise<any>;
|
135 | /**
|
136 | * Wrapper around the storage interface for set calls
|
137 | * @param key
|
138 | * @param value
|
139 | * @param {boolean} silent
|
140 | * @returns {Promise<any>}
|
141 | */
|
142 | asyncStorageSet(key: string, value: any, silent?: boolean): Promise<any>;
|
143 | /**
|
144 | * Checks if this session has a succesful installation stored
|
145 | * @returns {boolean}
|
146 | */
|
147 | verifyInstallation(): boolean;
|
148 | /**
|
149 | * Checks if this session has a succesful device installation stored
|
150 | * @returns {boolean}
|
151 | */
|
152 | verifyDeviceInstallation(): boolean;
|
153 | /**
|
154 | * Checks if this session has a succesful session setup
|
155 | * @returns {boolean}
|
156 | */
|
157 | verifySessionInstallation(): boolean;
|
158 | /**
|
159 | * Checks if session has expired yet
|
160 | * @returns {boolean}
|
161 | */
|
162 | verifySessionExpiry(): boolean;
|
163 | /**
|
164 | * Set enviroment and check if type is allowed/valid
|
165 | * @param environmentType
|
166 | */
|
167 | environmentType: string;
|
168 | }
|
169 | export {};
|