@queue-it/fastly 3.6.0 → 4.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -58
- package/package.json +23 -16
- package/src/contextProvider.ts +175 -0
- package/src/fastlyCryptoProvider.ts +8 -0
- package/src/helper.ts +11 -0
- package/{assembly/sdk → src}/helpers/crypto.ts +338 -340
- package/src/index.ts +3 -0
- package/src/integrationConfigProvider.ts +199 -0
- package/src/requestResponseHandler.ts +200 -0
- package/README-INTERNAL.md +0 -21
- package/asconfig.json +0 -17
- package/assembly/__tests__/CustomerIntegrationDecodingHandler.spec.ts +0 -1086
- package/assembly/__tests__/IntegrationConfigHelpersTest.spec.ts +0 -574
- package/assembly/__tests__/KnownUserTest.spec.ts +0 -1894
- package/assembly/__tests__/Mocks.ts +0 -321
- package/assembly/__tests__/QueueParameterHelper.spec.ts +0 -59
- package/assembly/__tests__/UserInQueueService.spec.ts +0 -418
- package/assembly/__tests__/UserInQueueStateCookieRepository.spec.ts +0 -337
- package/assembly/__tests__/as-pect.config.js +0 -57
- package/assembly/__tests__/as-pect.d.ts +0 -1
- package/assembly/contextProvider.ts +0 -123
- package/assembly/helper.ts +0 -23
- package/assembly/index.ts +0 -10
- package/assembly/integrationConfigProvider.ts +0 -32
- package/assembly/requestResponseHandler.ts +0 -92
- package/assembly/sdk/HttpContextProvider.ts +0 -24
- package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -198
- package/assembly/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +0 -232
- package/assembly/sdk/IntegrationConfig/IntegrationConfigModel.ts +0 -93
- package/assembly/sdk/KnownUser.ts +0 -396
- package/assembly/sdk/Models.ts +0 -105
- package/assembly/sdk/QueueITHelpers.ts +0 -263
- package/assembly/sdk/UserInQueueService.ts +0 -245
- package/assembly/sdk/UserInQueueStateCookieRepository.ts +0 -189
- package/assembly/sdk/helpers/Date.ts +0 -194
- package/assembly/sdk/helpers/Uri.ts +0 -308
- package/assembly/tsconfig.json +0 -6
- package/index.js +0 -5
- package/pipelines/ci.yaml +0 -28
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {Fastly, Request, Response} from "@fastly/as-compute";
|
|
2
|
-
import {KnownUser} from "./sdk/KnownUser";
|
|
3
|
-
import {QueueITHelper} from "./helper";
|
|
4
|
-
import {FastlyHttpContextProvider, getHttpHandler} from "./contextProvider";
|
|
5
|
-
import {getIntegrationConfig} from "./integrationConfigProvider"
|
|
6
|
-
import {Utils} from "./sdk/QueueITHelpers";
|
|
7
|
-
|
|
8
|
-
const QUEUEIT_FAILED_HEADERNAME = 'x-queueit-failed';
|
|
9
|
-
|
|
10
|
-
const ORIGIN_BACKEND = '',
|
|
11
|
-
QUEUEIT_BACKEND = '',
|
|
12
|
-
QUEUEIT_CUSTOMERID = '',
|
|
13
|
-
QUEUEIT_SECRETKEY = '',
|
|
14
|
-
QUEUEIT_APIKEY = '';
|
|
15
|
-
|
|
16
|
-
let httpProvider: FastlyHttpContextProvider | null = null;
|
|
17
|
-
|
|
18
|
-
export function onQueueITRequest(req: Request): Response {
|
|
19
|
-
let integrationConfigJson = getIntegrationConfig(QUEUEIT_CUSTOMERID, QUEUEIT_APIKEY, QUEUEIT_BACKEND);
|
|
20
|
-
|
|
21
|
-
QueueITHelper.configureKnownUserHashing();
|
|
22
|
-
httpProvider = getHttpHandler(req);
|
|
23
|
-
const queueItToken = Utils.getParameterByName(req.url, KnownUser.QueueITTokenKey);
|
|
24
|
-
|
|
25
|
-
const requestUrl: string = req.url;
|
|
26
|
-
const requestUrlWithoutToken: string = Utils.removeQueueItToken(requestUrl);
|
|
27
|
-
// The requestUrlWithoutToken is used to match Triggers and as the Target url (where to return the users to).
|
|
28
|
-
// It is therefor important that this is exactly the url of the users browsers. So, if your webserver is
|
|
29
|
-
// behind e.g. a load balancer that modifies the host name or port, reformat requestUrlWithoutToken before proceeding.
|
|
30
|
-
const validationResultPair = KnownUser.validateRequestByIntegrationConfig(requestUrlWithoutToken, queueItToken, integrationConfigJson,
|
|
31
|
-
QUEUEIT_CUSTOMERID, QUEUEIT_SECRETKEY, httpProvider!);
|
|
32
|
-
|
|
33
|
-
if (validationResultPair.first != null &&
|
|
34
|
-
validationResultPair.first!.doRedirect()) {
|
|
35
|
-
const validationResult = validationResultPair.first!;
|
|
36
|
-
|
|
37
|
-
if (validationResult.isAjaxResult) {
|
|
38
|
-
let response = new Response(null, {
|
|
39
|
-
status: 200,
|
|
40
|
-
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
41
|
-
url: ''
|
|
42
|
-
});
|
|
43
|
-
// In case of ajax call send the user to the queue by sending a custom queue-it header and redirecting user to queue from javascript
|
|
44
|
-
response.headers.set(validationResult.getAjaxQueueRedirectHeaderKey(), QueueITHelper.addKUPlatformVersion(validationResult.getAjaxRedirectUrl()));
|
|
45
|
-
Utils.addNoCacheHeaders(response);
|
|
46
|
-
return response;
|
|
47
|
-
} else {
|
|
48
|
-
let response = new Response(null, {
|
|
49
|
-
status: 302,
|
|
50
|
-
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
51
|
-
url: ''
|
|
52
|
-
});
|
|
53
|
-
// Send the user to the queue - either because hash was missing or because is was invalid
|
|
54
|
-
response.headers.set('Location', QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl));
|
|
55
|
-
Utils.addNoCacheHeaders(response);
|
|
56
|
-
return response;
|
|
57
|
-
}
|
|
58
|
-
} else if (validationResultPair.first != null) {
|
|
59
|
-
const validationResult = validationResultPair.first!;
|
|
60
|
-
// Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
|
|
61
|
-
if (requestUrl != requestUrlWithoutToken && validationResult.actionType == 'Queue') {
|
|
62
|
-
let response = new Response(null, {
|
|
63
|
-
status: 302,
|
|
64
|
-
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
65
|
-
url: requestUrlWithoutToken
|
|
66
|
-
});
|
|
67
|
-
response.headers.set('Location', requestUrlWithoutToken);
|
|
68
|
-
Utils.addNoCacheHeaders(response);
|
|
69
|
-
return response;
|
|
70
|
-
} else {
|
|
71
|
-
// lets caller decide the next step, or just serve the request normally
|
|
72
|
-
return getOriginResponse(req);
|
|
73
|
-
}
|
|
74
|
-
} else if (validationResultPair.second != null) {
|
|
75
|
-
httpProvider!.isError = true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return getOriginResponse(req);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getOriginResponse(req: Request): Response {
|
|
82
|
-
let cacheOverride = new Fastly.CacheOverride();
|
|
83
|
-
cacheOverride.setTTL(0);
|
|
84
|
-
const res = Fastly.fetch(req, {
|
|
85
|
-
backend: ORIGIN_BACKEND,
|
|
86
|
-
cacheOverride,
|
|
87
|
-
}).wait();
|
|
88
|
-
if (httpProvider!.isError) {
|
|
89
|
-
res.headers.append(QUEUEIT_FAILED_HEADERNAME, "true");
|
|
90
|
-
}
|
|
91
|
-
return res;
|
|
92
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Headers } from "@fastly/as-compute";
|
|
2
|
-
|
|
3
|
-
export interface IHttpRequest {
|
|
4
|
-
getUserAgent(): string;
|
|
5
|
-
getHeader(name: string): string;
|
|
6
|
-
getAbsoluteUri(): string;
|
|
7
|
-
getUserHostAddress(): string;
|
|
8
|
-
getCookieValue(cookieKey: string): string;
|
|
9
|
-
getRequestBodyAsString(): string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IHttpResponse {
|
|
13
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void;
|
|
14
|
-
getHeaders(): Headers;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IHttpContextProvider {
|
|
18
|
-
getHttpRequest(): IHttpRequest;
|
|
19
|
-
getHttpResponse(): IHttpResponse;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IDateTimeProvider {
|
|
23
|
-
getCurrentTime(): Date
|
|
24
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import {JSONHandler} from "assemblyscript-json";
|
|
2
|
-
import {
|
|
3
|
-
CustomerIntegration,
|
|
4
|
-
IntegrationConfigModel,
|
|
5
|
-
TriggerModel,
|
|
6
|
-
TriggerPart
|
|
7
|
-
} from "./IntegrationConfigModel";
|
|
8
|
-
import {JSONDecoder} from "assemblyscript-json";
|
|
9
|
-
|
|
10
|
-
export class CustomerIntegrationDecodingHandler extends JSONHandler {
|
|
11
|
-
private readonly _deserializedValue: CustomerIntegration;
|
|
12
|
-
private isInIntegrations: bool = false;
|
|
13
|
-
private isInTriggers: bool = false;
|
|
14
|
-
private isInConfigModel: bool = false;
|
|
15
|
-
private isInTriggerModel: bool = false;
|
|
16
|
-
private isInTriggerPart: bool = false;
|
|
17
|
-
private currentIntegrationConfigModel: IntegrationConfigModel | null;
|
|
18
|
-
private currentTriggerModel: TriggerModel | null;
|
|
19
|
-
private currentTriggerPart: TriggerPart | null;
|
|
20
|
-
private isInTriggerParts: bool = false;
|
|
21
|
-
private isInTriggerPartValuesToCompare: bool = false;
|
|
22
|
-
|
|
23
|
-
constructor() {
|
|
24
|
-
super();
|
|
25
|
-
this._deserializedValue = new CustomerIntegration();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
pushArray(name: string): bool {
|
|
29
|
-
// Handle array start
|
|
30
|
-
// true means that nested object needs to be traversed, false otherwise
|
|
31
|
-
// Note that returning false means JSONDecoder.startIndex need to be updated by handler
|
|
32
|
-
if (name == "Integrations") {
|
|
33
|
-
this.isInIntegrations = true;
|
|
34
|
-
} else if (name == "Triggers") {
|
|
35
|
-
this.isInTriggers = true;
|
|
36
|
-
} else if (name == "TriggerParts") {
|
|
37
|
-
this.isInTriggerParts = true;
|
|
38
|
-
} else if (name == "ValuesToCompare") {
|
|
39
|
-
this.isInTriggerPartValuesToCompare = true;
|
|
40
|
-
}
|
|
41
|
-
return this.isInIntegrations
|
|
42
|
-
|| this.isInTriggers
|
|
43
|
-
|| this.isInTriggerParts
|
|
44
|
-
|| this.isInTriggerPartValuesToCompare;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
popArray(): void {
|
|
49
|
-
if (this.isInTriggerPartValuesToCompare) {
|
|
50
|
-
this.isInTriggerPartValuesToCompare = false;
|
|
51
|
-
} else if (this.isInTriggerParts) {
|
|
52
|
-
this.isInTriggerParts = false;
|
|
53
|
-
} else if (this.isInTriggers) {
|
|
54
|
-
this.isInTriggers = false;
|
|
55
|
-
} else if (this.isInIntegrations) {
|
|
56
|
-
this.isInIntegrations = false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
pushObject(name: string): bool {
|
|
61
|
-
if (this.isInTriggerParts) {
|
|
62
|
-
this.isInTriggerPart = true;
|
|
63
|
-
this.currentTriggerPart = new TriggerPart();
|
|
64
|
-
} else if (this.isInTriggers) {
|
|
65
|
-
this.isInTriggerModel = true;
|
|
66
|
-
this.currentTriggerModel = new TriggerModel();
|
|
67
|
-
} else if (this.isInIntegrations) {
|
|
68
|
-
this.isInConfigModel = true;
|
|
69
|
-
this.currentIntegrationConfigModel = new IntegrationConfigModel();
|
|
70
|
-
}
|
|
71
|
-
return super.pushObject(name);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
popObject(): void {
|
|
75
|
-
if (this.isInTriggerPart) {
|
|
76
|
-
this.currentTriggerModel!.TriggerParts.push(this.currentTriggerPart!);
|
|
77
|
-
this.isInTriggerPart = false;
|
|
78
|
-
} else if (this.isInTriggerModel) {
|
|
79
|
-
this.currentIntegrationConfigModel!.Triggers.push(this.currentTriggerModel!);
|
|
80
|
-
this.isInTriggerModel = false;
|
|
81
|
-
} else if (this.isInConfigModel) {
|
|
82
|
-
this._deserializedValue.Integrations.push(this.currentIntegrationConfigModel!);
|
|
83
|
-
this.isInConfigModel = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
setInteger(name: string, value: i64): void {
|
|
88
|
-
if (this.isInConfigModel) {
|
|
89
|
-
this.setConfigModelInteger(name, value);
|
|
90
|
-
} else if (name == "Version") {
|
|
91
|
-
this._deserializedValue.Version = value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setBoolean(name: string, value: bool): void {
|
|
96
|
-
if (this.isInTriggerPart) {
|
|
97
|
-
this.setTriggerPartBoolean(name, value);
|
|
98
|
-
} else if (this.isInConfigModel) {
|
|
99
|
-
this.setConfigModelBoolean(name, value);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setString(name: string, value: string): void {
|
|
104
|
-
if (this.isInTriggerPartValuesToCompare) {
|
|
105
|
-
this.addTriggerPartValuesToCompare(value);
|
|
106
|
-
} else if (this.isInTriggerPart) {
|
|
107
|
-
this.setTriggerPartString(name, value);
|
|
108
|
-
} else if (this.isInTriggerModel) {
|
|
109
|
-
this.setTriggerModelString(name, value);
|
|
110
|
-
} else if (this.isInConfigModel) {
|
|
111
|
-
this.setConfigModelString(name, value);
|
|
112
|
-
} else if (name == "Description") {
|
|
113
|
-
this._deserializedValue.Description = value;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
setConfigModelBoolean(name: string, value: bool): void {
|
|
118
|
-
if (name == "ExtendCookieValidity") {
|
|
119
|
-
this.currentIntegrationConfigModel!.ExtendCookieValidity = value;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setTriggerPartBoolean(name: string, value: bool): void {
|
|
124
|
-
if (name == "IsNegative") {
|
|
125
|
-
this.currentTriggerPart!.IsNegative = value;
|
|
126
|
-
} else if (name == "IsIgnoreCase") {
|
|
127
|
-
this.currentTriggerPart!.IsIgnoreCase = value;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setConfigModelInteger(name: string, value: i64): void {
|
|
132
|
-
if (name == "CookieValidityMinute") {
|
|
133
|
-
this.currentIntegrationConfigModel!.CookieValidityMinute = value;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
addTriggerPartValuesToCompare(value: string): void {
|
|
138
|
-
this.currentTriggerPart!.ValuesToCompare.push(value);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
setTriggerPartString(name: string, value: string): void {
|
|
142
|
-
if (name == "ValidatorType") {
|
|
143
|
-
this.currentTriggerPart!.ValidatorType = value;
|
|
144
|
-
} else if (name == "Operator") {
|
|
145
|
-
this.currentTriggerPart!.Operator = value;
|
|
146
|
-
} else if (name == "ValueToCompare") {
|
|
147
|
-
this.currentTriggerPart!.ValueToCompare = value;
|
|
148
|
-
} else if (name == "UrlPart") {
|
|
149
|
-
this.currentTriggerPart!.UrlPart = value;
|
|
150
|
-
} else if (name == "CookieName") {
|
|
151
|
-
this.currentTriggerPart!.CookieName = value;
|
|
152
|
-
} else if (name == "HttpHeaderName") {
|
|
153
|
-
this.currentTriggerPart!.HttpHeaderName = value;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
setTriggerModelString(name: string, value: string): void {
|
|
158
|
-
if (name == "LogicalOperator") {
|
|
159
|
-
this.currentTriggerModel!.LogicalOperator = value;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
setConfigModelString(name: string, value: string): void {
|
|
164
|
-
if (name == "Name") {
|
|
165
|
-
this.currentIntegrationConfigModel!.Name = value;
|
|
166
|
-
} else if (name == "EventId") {
|
|
167
|
-
this.currentIntegrationConfigModel!.EventId = value;
|
|
168
|
-
} else if (name == "CookieDomain") {
|
|
169
|
-
this.currentIntegrationConfigModel!.CookieDomain = value;
|
|
170
|
-
} else if (name == "LayoutName") {
|
|
171
|
-
this.currentIntegrationConfigModel!.LayoutName = value;
|
|
172
|
-
} else if (name == "Culture") {
|
|
173
|
-
this.currentIntegrationConfigModel!.Culture = value;
|
|
174
|
-
} else if (name == "QueueDomain") {
|
|
175
|
-
this.currentIntegrationConfigModel!.QueueDomain = value;
|
|
176
|
-
} else if (name == "RedirectLogic") {
|
|
177
|
-
this.currentIntegrationConfigModel!.RedirectLogic = value;
|
|
178
|
-
} else if (name == "ForcedTargetUrl") {
|
|
179
|
-
this.currentIntegrationConfigModel!.ForcedTargetUrl = value;
|
|
180
|
-
} else if (name == "ActionType") {
|
|
181
|
-
this.currentIntegrationConfigModel!.ActionType = value;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
value(): CustomerIntegration {
|
|
186
|
-
return this._deserializedValue;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static deserialize(integrationsConfigString: string): CustomerIntegration {
|
|
190
|
-
const handler = new CustomerIntegrationDecodingHandler();
|
|
191
|
-
if (integrationsConfigString == '') {
|
|
192
|
-
return handler.value();
|
|
193
|
-
}
|
|
194
|
-
const decoder = new JSONDecoder<CustomerIntegrationDecodingHandler>(handler);
|
|
195
|
-
decoder.deserialize(Uint8Array.wrap(String.UTF8.encode(integrationsConfigString)));
|
|
196
|
-
return handler.value();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import * as IntegrationModels from './IntegrationConfigModel'
|
|
2
|
-
import {KnownUserException} from '../Models'
|
|
3
|
-
import {IHttpRequest} from '../HttpContextProvider'
|
|
4
|
-
//@ts-ignore
|
|
5
|
-
import {URL} from '@fastly/as-url';
|
|
6
|
-
|
|
7
|
-
export interface IIntegrationEvaluator {
|
|
8
|
-
getMatchedIntegrationConfig(
|
|
9
|
-
customerIntegration: IntegrationModels.CustomerIntegration,
|
|
10
|
-
currentPageUrl: string,
|
|
11
|
-
request: IHttpRequest): IntegrationModels.IntegrationConfigModelResult | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class IntegrationEvaluator implements IIntegrationEvaluator {
|
|
15
|
-
public getMatchedIntegrationConfig(
|
|
16
|
-
customerIntegration: IntegrationModels.CustomerIntegration,
|
|
17
|
-
currentPageUrl: string,
|
|
18
|
-
request: IHttpRequest | null): IntegrationModels.IntegrationConfigModelResult | null {
|
|
19
|
-
|
|
20
|
-
if (request == null)
|
|
21
|
-
return new IntegrationModels.IntegrationConfigModelResult(null, new KnownUserException("request is null"));
|
|
22
|
-
|
|
23
|
-
if (customerIntegration == null)
|
|
24
|
-
return new IntegrationModels.IntegrationConfigModelResult(null, new KnownUserException("customerIntegration is null"));
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < customerIntegration.Integrations.length; i++) {
|
|
27
|
-
let integration = customerIntegration.Integrations[i];
|
|
28
|
-
for (let t = 0; t < integration.Triggers.length; t++) {
|
|
29
|
-
let trigger = integration.Triggers[t];
|
|
30
|
-
if (this.evaluateTrigger(trigger, currentPageUrl, request)) {
|
|
31
|
-
return new IntegrationModels.IntegrationConfigModelResult(integration, null);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private evaluateTrigger(trigger: IntegrationModels.TriggerModel, currentPageUrl: string, request: IHttpRequest): bool {
|
|
39
|
-
if (trigger.LogicalOperator == IntegrationModels.LogicalOperatorType.Or) {
|
|
40
|
-
for (let i = 0; i < trigger.TriggerParts.length; i++) {
|
|
41
|
-
let part = trigger.TriggerParts[i];
|
|
42
|
-
if (this.evaluateTriggerPart(part, currentPageUrl, request))
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
} else {
|
|
47
|
-
for (let i = 0; i < trigger.TriggerParts.length; i++) {
|
|
48
|
-
let part = trigger.TriggerParts[i];
|
|
49
|
-
let matched = this.evaluateTriggerPart(part, currentPageUrl, request);
|
|
50
|
-
if (!matched)
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private evaluateTriggerPart(triggerPart: IntegrationModels.TriggerPart, currentPageUrl: string, request: IHttpRequest): bool {
|
|
58
|
-
if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.UrlValidator) {
|
|
59
|
-
return UrlValidatorHelper.evaluate(triggerPart, currentPageUrl);
|
|
60
|
-
} else if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.CookieValidator) {
|
|
61
|
-
return CookieValidatorHelper.evaluate(triggerPart, request);
|
|
62
|
-
} else if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.UserAgentValidator) {
|
|
63
|
-
return UserAgentValidatorHelper.evaluate(triggerPart, request.getUserAgent());
|
|
64
|
-
} else if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.HttpHeaderValidator) {
|
|
65
|
-
return HttpHeaderValidatorHelper.evaluate(triggerPart, request.getHeader(triggerPart.HttpHeaderName));
|
|
66
|
-
} else if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.RequestBodyValidator) {
|
|
67
|
-
return RequestBodyValidatorHelper.evaluate(triggerPart, request.getRequestBodyAsString());
|
|
68
|
-
} else {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class UrlValidatorHelper {
|
|
75
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, url: string): bool {
|
|
76
|
-
let urlpart = this.getUrlPart(triggerPart, url);
|
|
77
|
-
return ComparisonOperatorHelper.evaluate(
|
|
78
|
-
triggerPart.Operator,
|
|
79
|
-
triggerPart.IsNegative,
|
|
80
|
-
triggerPart.IsIgnoreCase,
|
|
81
|
-
urlpart,
|
|
82
|
-
triggerPart.ValueToCompare,
|
|
83
|
-
triggerPart.ValuesToCompare);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private static getUrlPart(triggerPart: IntegrationModels.TriggerPart, url: string): string {
|
|
87
|
-
if (triggerPart.UrlPart == IntegrationModels.UrlPartType.PagePath) {
|
|
88
|
-
return this.getPathFromUrl(url);
|
|
89
|
-
} else if (triggerPart.UrlPart == IntegrationModels.UrlPartType.PageUrl) {
|
|
90
|
-
return url;
|
|
91
|
-
} else if (triggerPart.UrlPart == IntegrationModels.UrlPartType.HostName) {
|
|
92
|
-
return this.getHostNameFromUrl(url);
|
|
93
|
-
} else {
|
|
94
|
-
return "";
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public static getHostNameFromUrl(url: string): string {
|
|
99
|
-
let urlx = new URL(url);
|
|
100
|
-
return urlx.host;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public static getPathFromUrl(url: string): string {
|
|
104
|
-
let urlx = new URL(url);
|
|
105
|
-
return urlx.pathname;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export class CookieValidatorHelper {
|
|
110
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, request: IHttpRequest): bool {
|
|
111
|
-
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
112
|
-
triggerPart.IsNegative,
|
|
113
|
-
triggerPart.IsIgnoreCase,
|
|
114
|
-
this.getCookie(triggerPart.CookieName, request),
|
|
115
|
-
triggerPart.ValueToCompare,
|
|
116
|
-
triggerPart.ValuesToCompare);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private static getCookie(cookieName: string, request: IHttpRequest): string {
|
|
120
|
-
return request.getCookieValue(cookieName);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export class UserAgentValidatorHelper {
|
|
125
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, userAgent: string): bool {
|
|
126
|
-
|
|
127
|
-
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
128
|
-
triggerPart.IsNegative,
|
|
129
|
-
triggerPart.IsIgnoreCase,
|
|
130
|
-
userAgent,
|
|
131
|
-
triggerPart.ValueToCompare,
|
|
132
|
-
triggerPart.ValuesToCompare);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export class RequestBodyValidatorHelper {
|
|
137
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, bodyString: string): bool {
|
|
138
|
-
|
|
139
|
-
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
140
|
-
triggerPart.IsNegative,
|
|
141
|
-
triggerPart.IsIgnoreCase,
|
|
142
|
-
bodyString,
|
|
143
|
-
triggerPart.ValueToCompare,
|
|
144
|
-
triggerPart.ValuesToCompare);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export class HttpHeaderValidatorHelper {
|
|
149
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, headerValue: string): bool {
|
|
150
|
-
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
151
|
-
triggerPart.IsNegative,
|
|
152
|
-
triggerPart.IsIgnoreCase,
|
|
153
|
-
headerValue,
|
|
154
|
-
triggerPart.ValueToCompare,
|
|
155
|
-
triggerPart.ValuesToCompare);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export class ComparisonOperatorHelper {
|
|
160
|
-
public static evaluate(opt: string,
|
|
161
|
-
isNegative: bool,
|
|
162
|
-
isIgnoreCase: bool,
|
|
163
|
-
value: string,
|
|
164
|
-
valueToCompare: string,
|
|
165
|
-
valuesToCompare: Array<string> | null): bool {
|
|
166
|
-
if (valuesToCompare == null) {
|
|
167
|
-
valuesToCompare = new Array<string>();
|
|
168
|
-
}
|
|
169
|
-
if (opt == IntegrationModels.ComparisonOperatorType.EqualS) {
|
|
170
|
-
return ComparisonOperatorHelper.equalS(value, valueToCompare, isNegative, isIgnoreCase);
|
|
171
|
-
} else if (opt == IntegrationModels.ComparisonOperatorType.Contains) {
|
|
172
|
-
return ComparisonOperatorHelper.contains(value, valueToCompare, isNegative, isIgnoreCase);
|
|
173
|
-
} else if (opt == IntegrationModels.ComparisonOperatorType.EqualsAny) {
|
|
174
|
-
return ComparisonOperatorHelper.equalsAny(value, valuesToCompare, isNegative, isIgnoreCase);
|
|
175
|
-
} else if (opt == IntegrationModels.ComparisonOperatorType.ContainsAny) {
|
|
176
|
-
return ComparisonOperatorHelper.containsAny(value, valuesToCompare, isNegative, isIgnoreCase);
|
|
177
|
-
} else {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private static contains(value: string, valueToCompare: string, isNegative: bool, ignoreCase: bool): bool {
|
|
183
|
-
if (valueToCompare == "*" && value != "")
|
|
184
|
-
return true;
|
|
185
|
-
|
|
186
|
-
let evaluation = false;
|
|
187
|
-
|
|
188
|
-
if (ignoreCase)
|
|
189
|
-
evaluation = value.toUpperCase().indexOf(valueToCompare.toUpperCase()) != -1;
|
|
190
|
-
else
|
|
191
|
-
evaluation = value.indexOf(valueToCompare) != -1;
|
|
192
|
-
|
|
193
|
-
if (isNegative)
|
|
194
|
-
return !evaluation;
|
|
195
|
-
else
|
|
196
|
-
return evaluation;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
private static equalS(value: string, valueToCompare: string, isNegative: bool, ignoreCase: bool): bool {
|
|
200
|
-
let evaluation = false;
|
|
201
|
-
|
|
202
|
-
if (ignoreCase)
|
|
203
|
-
evaluation = value.toUpperCase() == valueToCompare.toUpperCase();
|
|
204
|
-
else
|
|
205
|
-
evaluation = value == valueToCompare;
|
|
206
|
-
|
|
207
|
-
if (isNegative)
|
|
208
|
-
return !evaluation;
|
|
209
|
-
else
|
|
210
|
-
return evaluation;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private static equalsAny(value: string, valuesToCompare: Array<string>, isNegative: bool, isIgnoreCase: bool): bool {
|
|
214
|
-
for (let i = 0; i < valuesToCompare.length; i++) {
|
|
215
|
-
let valueToCompare = valuesToCompare[i];
|
|
216
|
-
if (ComparisonOperatorHelper.equalS(value, valueToCompare, false, isIgnoreCase))
|
|
217
|
-
return !isNegative;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return isNegative;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private static containsAny(value: string, valuesToCompare: Array<string>, isNegative: bool, isIgnoreCase: bool): bool {
|
|
224
|
-
for (let i = 0; i < valuesToCompare.length; i++) {
|
|
225
|
-
let valueToCompare = valuesToCompare[i];
|
|
226
|
-
if (ComparisonOperatorHelper.contains(value, valueToCompare, false, isIgnoreCase))
|
|
227
|
-
return !isNegative;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return isNegative;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {KnownUserException, Tuple} from "../Models";
|
|
2
|
-
|
|
3
|
-
export class IntegrationConfigModelResult extends Tuple<IntegrationConfigModel | null, KnownUserException | null> {
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class IntegrationConfigModel {
|
|
7
|
-
Name: string = "";
|
|
8
|
-
EventId: string = "";
|
|
9
|
-
CookieDomain: string = "";
|
|
10
|
-
LayoutName: string = "";
|
|
11
|
-
Culture: string = "";
|
|
12
|
-
ExtendCookieValidity: bool = false;
|
|
13
|
-
CookieValidityMinute: i64 = 0;
|
|
14
|
-
QueueDomain: string = "";
|
|
15
|
-
RedirectLogic: string = "";
|
|
16
|
-
ForcedTargetUrl: string = "";
|
|
17
|
-
ActionType: string = "";
|
|
18
|
-
Triggers: Array<TriggerModel>;
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.Triggers = new Array<TriggerModel>();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class CustomerIntegration {
|
|
26
|
-
Integrations: Array<IntegrationConfigModel>;
|
|
27
|
-
Version: i64;
|
|
28
|
-
Description: string;
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
this.Integrations = new Array<IntegrationConfigModel>();
|
|
32
|
-
this.Version = 0;
|
|
33
|
-
this.Description = "";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class TriggerPart {
|
|
38
|
-
ValidatorType: string = "";
|
|
39
|
-
Operator: string = "";
|
|
40
|
-
ValueToCompare: string = "";
|
|
41
|
-
ValuesToCompare: Array<string>;
|
|
42
|
-
IsNegative: bool = false;
|
|
43
|
-
IsIgnoreCase: bool = false;
|
|
44
|
-
UrlPart: string = ""; // UrlValidator
|
|
45
|
-
CookieName: string = ""; // CookieValidator
|
|
46
|
-
HttpHeaderName: string = ""; // HttpHeaderValidator
|
|
47
|
-
|
|
48
|
-
constructor() {
|
|
49
|
-
this.ValuesToCompare = new Array<string>();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class TriggerModel {
|
|
54
|
-
constructor() {
|
|
55
|
-
this.TriggerParts = new Array<TriggerPart>();
|
|
56
|
-
this.LogicalOperator = "";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
TriggerParts: Array<TriggerPart>;
|
|
60
|
-
LogicalOperator: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export class ValidatorType {
|
|
64
|
-
public static readonly UrlValidator: string = "UrlValidator";
|
|
65
|
-
public static readonly CookieValidator: string = "CookieValidator";
|
|
66
|
-
public static readonly UserAgentValidator: string = "UserAgentValidator";
|
|
67
|
-
public static readonly HttpHeaderValidator: string = "HttpHeaderValidator";
|
|
68
|
-
public static readonly RequestBodyValidator: string = "RequestBodyValidator";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export class UrlPartType {
|
|
72
|
-
static readonly HostName: string = "HostName";
|
|
73
|
-
static readonly PagePath: string = "PagePath";
|
|
74
|
-
static readonly PageUrl: string = "PageUrl";
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export class ComparisonOperatorType {
|
|
78
|
-
static readonly EqualS: string = "Equals";
|
|
79
|
-
static readonly Contains: string = "Contains";
|
|
80
|
-
static readonly EqualsAny: string = "EqualsAny";
|
|
81
|
-
static readonly ContainsAny: string = "ContainsAny";
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class LogicalOperatorType {
|
|
85
|
-
public static readonly Or: string = "Or";
|
|
86
|
-
public static readonly And: string = "And";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export class ActionType {
|
|
90
|
-
public static readonly IgnoreAction: string = "Ignore";
|
|
91
|
-
public static readonly CancelAction: string = "Cancel";
|
|
92
|
-
public static readonly QueueAction: string = "Queue";
|
|
93
|
-
}
|