-
Notifications
You must be signed in to change notification settings - Fork 5
/
queueitHelpers.ts
97 lines (82 loc) · 3.56 KB
/
queueitHelpers.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const AKAMAI_SDK_VERSION = "3.0.11";
export class QueueITHelper {
public static addKUPlatformVersion = function (redirectQueueUrl) {
return redirectQueueUrl + "&kupver=akamai-" + AKAMAI_SDK_VERSION;
}
public static getParameterByName(name, url) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return results[2].replace(/\+/g, ' ');
}
public static getNoCacheHeaders() {
return {
'Cache-Control': ['no-cache, no-store, must-revalidate, max-age=0'],
'Pragma': ['no-cache'],
'Expires': ['Fri, 01 Jan 1990 00:00:00 GMT']
};
}
public static getSettingsFromPMVariables(request): Settings {
let setting = {
SecretKey: request.getVariable('PMUSER_QUEUEIT_SECRET_KEY'),
ApiKey: request.getVariable('PMUSER_QUEUEIT_API_KEY'),
CustomerId: request.getVariable('PMUSER_QUEUEIT_CUSTOMERID'),
IntegrationConfigType: request.getVariable('PMUSER_QUEUEIT_CONFIG_TYPE'),
IgnoreOptionsRequests: request.getVariable('PMUSER_QUEUEIT_IGNORE_REQUEST'),
GenerateEnqueueToken: request.getVariable('PMUSER_QUEUEIT_GENERATE_EQTOKEN'),
EnqueueTokenValidityTime: request.getVariable('PMUSER_QUEUEIT_EQTOKEN_VALIDITY'),
AddDebugInfo: request.getVariable('PMUSER_QUEUEIT_ADD_DEBUG'),
NoKey: request.getVariable('PMUSER_QUEUEIT_NO_KEY')
};
if (!setting.CustomerId) {
let settingException = new SettingException();
settingException.Type = "CustomerId";
throw settingException;
}
if (!setting.SecretKey) {
let settingException = new SettingException();
settingException.Type = "SecretKey";
throw settingException;
}
if (!setting.IntegrationConfigType ||
(setting.IntegrationConfigType.toLowerCase() != 'inline' &&
setting.IntegrationConfigType.toLowerCase() != 'cache' &&
setting.IntegrationConfigType.toLowerCase() != 'edgekv')) {
let settingException = new SettingException();
settingException.Type = "ConfigType";
throw settingException;
}
// convert to boolean
setting.IgnoreOptionsRequests = setting.IgnoreOptionsRequests && setting.IgnoreOptionsRequests.toLowerCase() == 'true';
setting.GenerateEnqueueToken = setting.GenerateEnqueueToken && setting.GenerateEnqueueToken.toLowerCase() == 'true';
return setting;
}
// Based on REF 4122 section 4.4 http://www.ietf.org/rfc/rfc4122.txt
public static generateUUID(): string {
const s = [];
const hexDigits = "0123456789abcdef";
for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
}
}
export interface Settings {
SecretKey: string,
ApiKey: string,
CustomerId: string,
IntegrationConfigType: string,
IgnoreOptionsRequests: boolean,
GenerateEnqueueToken: boolean,
EnqueueTokenValidityTime: Number,
NoKey:boolean,
AddDebugInfo: boolean
}
export class SettingException {
Type: string;
}