-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathintegrationConfigProvider.ts
More file actions
42 lines (35 loc) · 1.63 KB
/
integrationConfigProvider.ts
File metadata and controls
42 lines (35 loc) · 1.63 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
/*INLINE config*/
const inlineIntegrationConfig = 'IF YOU ARE USING INLINE CONFIGURATION: GET YOUR INTEGRATION CONFIG IN JSON FORMAT FROM GO QUEUE-IT PLATFORM AND PASTE IT HERE';
/*INLINE config*/
import { httpRequest } from 'http-request';
import { EdgeKV } from './lib/edgekv.js';
export { IntegrationConfigProvider };
class IntegrationConfigProvider {
public static getIntegrationConfig = async function (customerId: string, configType: string, apiKey: string) {
switch (configType.toLowerCase()) {
case 'inline':
return inlineIntegrationConfig;
case 'cache':
return IntegrationConfigProvider.getIntegrationConfigFromCache(apiKey);
case 'edgekv':
return IntegrationConfigProvider.getIntegrationConfigFromEdgeKV(customerId);
}
return '';
}
private static getIntegrationConfigFromCache = async function (apiKey: string) {
const options: any = {}
options.method = "GET";
options.headers = { "api-key": apiKey };
options.timeout = 1400;
return (await httpRequest("/queueit/integrationconfig/", options)).text();
}
private static getIntegrationConfigFromEdgeKV = async function (customerId: string) {
let edgeKV = new EdgeKV("QueueIT", customerId);
return await edgeKV.requestHandlerTemplate(
() => edgeKV.getRequest({ namespace: 'QueueIT', group: customerId, item: 'integrationConfig' }),
(response) => response.text(),
async (response) => await edgeKV.streamText(response.body),
"GET JSON string",
null);
}
}