forked from queueit/KnownUser.V3.Akamai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queueitHelpers.ts
76 lines (63 loc) · 2.41 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
import crypto from './lib/sha256.js'
const AKAMAI_SDK_VERSION = "3.0.3";
export class QueueITHelper {
public static addKUPlatformVersion = function (redirectQueueUrl) {
return redirectQueueUrl + "&kupver=akamai-" + AKAMAI_SDK_VERSION;
}
public static configureKnownUserHashing = function (Utils) {
Utils.generateSHA256Hash = function (secretKey, stringToHash) {
return crypto.sha256.hmac(secretKey, stringToHash);
};
}
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'],
'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')
};
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;
}
return setting;
}
}
export interface Settings {
SecretKey: string,
ApiKey: string,
CustomerId: string,
IntegrationConfigType: string
}
export class SettingException {
Type: string;
}