@queue-it/fastly 1.1.0 → 2.0.0-beta.1
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/package.json +16 -21
- package/{assembly → src}/contextProvider.ts +12 -8
- package/{assembly → src}/index.ts +1 -1
- package/{assembly → src}/integrationConfigProvider.ts +20 -23
- package/{assembly → src}/requestResponseHandler.ts +9 -15
- package/{assembly → src}/sdk/HttpContextProvider.ts +1 -2
- package/src/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +57 -0
- package/{assembly → src}/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +14 -16
- package/{assembly → src}/sdk/IntegrationConfig/IntegrationConfigModel.ts +5 -5
- package/{assembly → src}/sdk/KnownUser.ts +7 -9
- package/{assembly → src}/sdk/Models.ts +6 -6
- package/{assembly → src}/sdk/QueueITHelpers.ts +33 -29
- package/{assembly → src}/sdk/UserInQueueService.ts +4 -4
- package/{assembly → src}/sdk/UserInQueueStateCookieRepository.ts +26 -27
- package/src/sdk/helpers/Uri.ts +4 -0
- package/{assembly → src}/sdk/helpers/crypto.ts +28 -30
- package/LICENSE +0 -21
- package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -221
- package/assembly/sdk/helpers/Uri.ts +0 -308
- /package/{assembly → src}/helper.ts +0 -0
package/package.json
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@queue-it/fastly",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Queue-it connector for Fastly",
|
|
5
|
-
"main": "
|
|
6
|
-
"ascMain": "assembly/index.ts",
|
|
5
|
+
"main": "src/index.ts",
|
|
7
6
|
"author": "devs@queue-it.com",
|
|
8
7
|
"repository": "https://github.com/queueit/KnownUser.V3.Fastly",
|
|
9
8
|
"license": "MIT",
|
|
10
9
|
"files": [
|
|
11
10
|
"package.json",
|
|
12
11
|
"README.md",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
12
|
+
"src/sdk",
|
|
13
|
+
"src/contextProvider.ts",
|
|
14
|
+
"src/helper.ts",
|
|
15
|
+
"src/integrationConfigProvider.ts",
|
|
16
|
+
"src/requestResponseHandler.ts",
|
|
17
|
+
"src/index.ts"
|
|
19
18
|
],
|
|
20
19
|
"scripts": {
|
|
21
|
-
"test": "
|
|
22
|
-
"
|
|
23
|
-
"asbuild:optimized": "asc assembly/index.ts --target release",
|
|
24
|
-
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"bundle": "esbuild src/index.ts --bundle --outfile=bin/index.js --platform=node --target=es2022 && js-compute-runtime bin/index.js bin/main.wasm",
|
|
25
22
|
"build": "fastly compute build",
|
|
26
23
|
"deploy": "fastly compute deploy"
|
|
27
24
|
},
|
|
28
25
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@fastly/as-compute": "^0.4.1",
|
|
31
|
-
"as-wasi": "^0.4.6",
|
|
32
|
-
"assemblyscript-json": "^1.1.0",
|
|
33
|
-
"assemblyscript-regex": "^1.6.3"
|
|
26
|
+
"@fastly/js-compute": "^3.0.0"
|
|
34
27
|
},
|
|
35
28
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
29
|
+
"@types/jest": "^29.5.0",
|
|
30
|
+
"esbuild": "^0.27.3",
|
|
31
|
+
"jest": "^29.5.0",
|
|
32
|
+
"ts-jest": "^29.1.0",
|
|
33
|
+
"typescript": "^5.4.0"
|
|
39
34
|
}
|
|
40
35
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {IHttpContextProvider, IHttpRequest, IHttpResponse} from "./sdk/HttpContextProvider";
|
|
2
|
-
import {Request, Fastly, Headers} from "@fastly/as-compute";
|
|
3
2
|
import {decodeURIComponent, encodeURIComponent} from "./sdk/helpers/Uri";
|
|
4
3
|
|
|
5
4
|
export function getHttpHandler(req: Request): FastlyHttpContextProvider {
|
|
@@ -7,9 +6,8 @@ export function getHttpHandler(req: Request): FastlyHttpContextProvider {
|
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
export class FastlyHttpContextProvider implements IHttpContextProvider {
|
|
10
|
-
isError:
|
|
9
|
+
isError: boolean = false;
|
|
11
10
|
private readonly req: FastlyHttpRequest;
|
|
12
|
-
// @ts-ignore
|
|
13
11
|
private readonly res: FastlyHttpResponse;
|
|
14
12
|
|
|
15
13
|
constructor(fReq: Request) {
|
|
@@ -28,7 +26,7 @@ export class FastlyHttpContextProvider implements IHttpContextProvider {
|
|
|
28
26
|
|
|
29
27
|
export class FastlyHttpRequest implements IHttpRequest {
|
|
30
28
|
private parsedCookieDic: Map<string, string>
|
|
31
|
-
private bodyFetched:
|
|
29
|
+
private bodyFetched: boolean = false;
|
|
32
30
|
private body: string = '';
|
|
33
31
|
|
|
34
32
|
constructor(private baseReq: Request) {
|
|
@@ -67,10 +65,16 @@ export class FastlyHttpRequest implements IHttpRequest {
|
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
getCookieValue(cookieKey: string): string {
|
|
70
|
-
if (this.parsedCookieDic.
|
|
68
|
+
if (this.parsedCookieDic.size == 0) {
|
|
71
69
|
this.parseCookies(this.getHeader('cookie'))
|
|
72
70
|
}
|
|
73
|
-
|
|
71
|
+
if (!this.parsedCookieDic.has(cookieKey)) return '';
|
|
72
|
+
const cookieVal = this.parsedCookieDic.get(cookieKey)!;
|
|
73
|
+
try {
|
|
74
|
+
return decodeURIComponent(cookieVal);
|
|
75
|
+
} catch {
|
|
76
|
+
return cookieVal;
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
getHeader(name: string): string {
|
|
@@ -95,7 +99,7 @@ export class FastlyHttpRequest implements IHttpRequest {
|
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
getUserHostAddress(): string {
|
|
98
|
-
return
|
|
102
|
+
return this.baseReq.headers.get('Fastly-Client-IP') ?? '';
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
|
|
@@ -106,7 +110,7 @@ export class FastlyHttpResponse implements IHttpResponse {
|
|
|
106
110
|
this.headers = new Headers();
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration:
|
|
113
|
+
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: number): void {
|
|
110
114
|
const expirationDate = new Date(expiration * 1000);
|
|
111
115
|
let setCookieString = cookieName + "=" + encodeURIComponent(cookieValue) + "; expires=" + expirationDate.toUTCString() + ";";
|
|
112
116
|
if (domain != "") {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {IntegrationDetails, IntegrationEndpointProvider, IntegrationEndpointCacheConfig} from "./integrationConfigProvider"
|
|
1
|
+
export {IntegrationDetails, IntegrationEndpointProvider, IntegrationEndpointCacheConfig, resolveIntegrationDetails} from "./integrationConfigProvider"
|
|
2
2
|
export {onQueueITRequest, onQueueITResponse} from "./requestResponseHandler";
|
|
3
3
|
export {RequestLogger} from "./helper";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Fastly, Headers, Request } from "@fastly/as-compute";
|
|
2
1
|
import { RequestLogger } from "./helper";
|
|
3
2
|
|
|
4
|
-
export function getIntegrationConfig(
|
|
3
|
+
export async function getIntegrationConfig(
|
|
5
4
|
details: IntegrationDetails,
|
|
6
5
|
endpointProvider: IntegrationEndpointProvider
|
|
7
|
-
): string {
|
|
6
|
+
): Promise<string> {
|
|
8
7
|
const headers = new Headers();
|
|
9
8
|
headers.set("api-key", details.apiKey);
|
|
10
9
|
headers.set("host", endpointProvider.getHostname(details.customerId));
|
|
@@ -16,19 +15,16 @@ export function getIntegrationConfig(
|
|
|
16
15
|
headers: headers,
|
|
17
16
|
}
|
|
18
17
|
);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (cacheConf.maxAge
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (cacheConf.staleWhileRevalidate != -1) {
|
|
25
|
-
cacheOverride.setSWR(cacheConf.staleWhileRevalidate);
|
|
26
|
-
}
|
|
18
|
+
const cacheConf = endpointProvider.getCacheConfig();
|
|
19
|
+
const cacheInit: { ttl?: number; swr?: number } = {};
|
|
20
|
+
if (cacheConf.maxAge !== -1) cacheInit.ttl = cacheConf.maxAge;
|
|
21
|
+
if (cacheConf.staleWhileRevalidate !== -1) cacheInit.swr = cacheConf.staleWhileRevalidate;
|
|
22
|
+
const cacheOverride = new CacheOverride("override", cacheInit);
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
const beresp = await fetch(request, {
|
|
29
25
|
backend: details.queueItOrigin,
|
|
30
26
|
cacheOverride: cacheOverride,
|
|
31
|
-
})
|
|
27
|
+
});
|
|
32
28
|
|
|
33
29
|
if (!(details.logger instanceof MockLogger)) {
|
|
34
30
|
let cacheState = beresp.headers.get("x-cache");
|
|
@@ -41,7 +37,7 @@ export function getIntegrationConfig(
|
|
|
41
37
|
if (beresp.status != 200) {
|
|
42
38
|
return "";
|
|
43
39
|
}
|
|
44
|
-
return beresp.text();
|
|
40
|
+
return await beresp.text();
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
const integrationCustomerId = "customerId",
|
|
@@ -52,19 +48,20 @@ const integrationCustomerId = "customerId",
|
|
|
52
48
|
workerHost = "workerHost";
|
|
53
49
|
|
|
54
50
|
export function resolveIntegrationDetails(): IntegrationDetails | null {
|
|
55
|
-
const dict = new
|
|
51
|
+
const dict = new ConfigStore(integrationDictionary);
|
|
56
52
|
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
dict.get(integrationCustomerId) === null ||
|
|
54
|
+
dict.get(integrationApiKey) === null ||
|
|
55
|
+
dict.get(integrationSecret) === null ||
|
|
56
|
+
dict.get(integrationQueueItOrigin) === null
|
|
61
57
|
) {
|
|
62
58
|
return null;
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
let workerHostValue = "";
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const workerHostVal = dict.get(workerHost);
|
|
63
|
+
if (workerHostVal !== null) {
|
|
64
|
+
workerHostValue = workerHostVal;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
return new IntegrationDetails(
|
|
@@ -77,8 +74,8 @@ export function resolveIntegrationDetails(): IntegrationDetails | null {
|
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
export class IntegrationEndpointCacheConfig {
|
|
80
|
-
maxAge:
|
|
81
|
-
staleWhileRevalidate:
|
|
77
|
+
maxAge: number = -1;
|
|
78
|
+
staleWhileRevalidate: number = -1;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
export interface IntegrationEndpointProvider {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Request, Response, Headers } from "@fastly/as-compute";
|
|
2
1
|
import { KnownUser } from "./sdk/KnownUser";
|
|
3
2
|
import { QueueITHelper } from "./helper";
|
|
4
3
|
import { FastlyHttpContextProvider, getHttpHandler } from "./contextProvider";
|
|
@@ -13,18 +12,17 @@ import { Utils } from "./sdk/QueueITHelpers";
|
|
|
13
12
|
const QUEUEIT_FAILED_HEADERNAME = "x-queueit-failed";
|
|
14
13
|
let httpProvider: FastlyHttpContextProvider | null = null;
|
|
15
14
|
|
|
16
|
-
export function onQueueITRequest(
|
|
15
|
+
export async function onQueueITRequest(
|
|
17
16
|
req: Request,
|
|
18
17
|
conf: IntegrationDetails | null = null
|
|
19
|
-
): Response | null {
|
|
18
|
+
): Promise<Response | null> {
|
|
20
19
|
if (conf == null) {
|
|
21
20
|
conf = resolveIntegrationDetails();
|
|
22
21
|
}
|
|
23
22
|
if (conf == null) {
|
|
24
|
-
return new Response(
|
|
23
|
+
return new Response("No integration details found.", {
|
|
25
24
|
headers: new Headers(),
|
|
26
25
|
status: 404,
|
|
27
|
-
url: "",
|
|
28
26
|
});
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -35,7 +33,7 @@ export function onQueueITRequest(
|
|
|
35
33
|
QueueITHelper.configureKnownUserHashing();
|
|
36
34
|
httpProvider = getHttpHandler(req);
|
|
37
35
|
|
|
38
|
-
let integrationConfigJson = getIntegrationConfig(conf, integrationProvider);
|
|
36
|
+
let integrationConfigJson = await getIntegrationConfig(conf, integrationProvider);
|
|
39
37
|
const requestUrl: string = conf.resolveWorkerRequestUrl(req.url);
|
|
40
38
|
|
|
41
39
|
const queueItToken = Utils.getParameterByName(
|
|
@@ -66,7 +64,6 @@ export function onQueueITRequest(
|
|
|
66
64
|
let response = new Response(null, {
|
|
67
65
|
status: 200,
|
|
68
66
|
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
69
|
-
url: "",
|
|
70
67
|
});
|
|
71
68
|
// 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
|
|
72
69
|
response.headers.set("Access-Control-Expose-Headers", validationResult.getAjaxQueueRedirectHeaderKey());
|
|
@@ -82,7 +79,6 @@ export function onQueueITRequest(
|
|
|
82
79
|
let response = new Response(null, {
|
|
83
80
|
status: 302,
|
|
84
81
|
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
85
|
-
url: "",
|
|
86
82
|
});
|
|
87
83
|
// Send the user to the queue - either because hash was missing or because is was invalid
|
|
88
84
|
response.headers.set(
|
|
@@ -104,7 +100,6 @@ export function onQueueITRequest(
|
|
|
104
100
|
let response = new Response(null, {
|
|
105
101
|
status: 302,
|
|
106
102
|
headers: httpProvider!.getHttpResponse().getHeaders(),
|
|
107
|
-
url: requestUrlWithoutToken,
|
|
108
103
|
});
|
|
109
104
|
response.headers.set("Location", requestUrlWithoutToken);
|
|
110
105
|
Utils.addNoCacheHeaders(response);
|
|
@@ -123,15 +118,14 @@ export function onQueueITRequest(
|
|
|
123
118
|
//Fill in the Queue-it headers
|
|
124
119
|
export function onQueueITResponse(res: Response): void {
|
|
125
120
|
const contextHeaders = httpProvider!.getHttpResponse().getHeaders();
|
|
126
|
-
const contextHeaderKeys = contextHeaders.keys();
|
|
127
121
|
|
|
128
122
|
if (httpProvider!.isError) {
|
|
129
123
|
res.headers.append(QUEUEIT_FAILED_HEADERNAME, "true");
|
|
130
124
|
}
|
|
131
|
-
for (
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
if (value != null && value
|
|
135
|
-
res.headers.append(
|
|
125
|
+
for (const key of contextHeaders.keys()) {
|
|
126
|
+
if (key.length == 0) continue;
|
|
127
|
+
const value = contextHeaders.get(key);
|
|
128
|
+
if (value != null && value.length > 0)
|
|
129
|
+
res.headers.append(key, value);
|
|
136
130
|
}
|
|
137
131
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Headers } from "@fastly/as-compute";
|
|
2
1
|
|
|
3
2
|
export interface IHttpRequest {
|
|
4
3
|
getUserAgent(): string;
|
|
@@ -10,7 +9,7 @@ export interface IHttpRequest {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export interface IHttpResponse {
|
|
13
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration:
|
|
12
|
+
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: number): void;
|
|
14
13
|
getHeaders(): Headers;
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CustomerIntegration,
|
|
3
|
+
IntegrationConfigModel,
|
|
4
|
+
TriggerModel,
|
|
5
|
+
TriggerPart
|
|
6
|
+
} from "./IntegrationConfigModel";
|
|
7
|
+
|
|
8
|
+
export class CustomerIntegrationDecodingHandler {
|
|
9
|
+
static deserialize(integrationsConfigString: string): CustomerIntegration {
|
|
10
|
+
const result = new CustomerIntegration();
|
|
11
|
+
if (!integrationsConfigString) return result;
|
|
12
|
+
|
|
13
|
+
const parsed = JSON.parse(integrationsConfigString);
|
|
14
|
+
result.Version = parsed.Version ?? 0;
|
|
15
|
+
result.Description = parsed.Description ?? '';
|
|
16
|
+
|
|
17
|
+
if (Array.isArray(parsed.Integrations)) {
|
|
18
|
+
result.Integrations = parsed.Integrations.map((item: any) => {
|
|
19
|
+
const model = new IntegrationConfigModel();
|
|
20
|
+
model.Name = item.Name ?? '';
|
|
21
|
+
model.EventId = item.EventId ?? '';
|
|
22
|
+
model.CookieDomain = item.CookieDomain ?? '';
|
|
23
|
+
model.LayoutName = item.LayoutName ?? '';
|
|
24
|
+
model.Culture = item.Culture ?? '';
|
|
25
|
+
model.ExtendCookieValidity = item.ExtendCookieValidity ?? false;
|
|
26
|
+
model.CookieValidityMinute = item.CookieValidityMinute ?? 0;
|
|
27
|
+
model.QueueDomain = item.QueueDomain ?? '';
|
|
28
|
+
model.RedirectLogic = item.RedirectLogic ?? '';
|
|
29
|
+
model.ForcedTargetUrl = item.ForcedTargetUrl ?? '';
|
|
30
|
+
model.ActionType = item.ActionType ?? '';
|
|
31
|
+
|
|
32
|
+
model.Triggers = (item.Triggers ?? []).map((trigger: any) => {
|
|
33
|
+
const t = new TriggerModel();
|
|
34
|
+
t.LogicalOperator = trigger.LogicalOperator ?? '';
|
|
35
|
+
t.TriggerParts = (trigger.TriggerParts ?? []).map((part: any) => {
|
|
36
|
+
const tp = new TriggerPart();
|
|
37
|
+
tp.ValidatorType = part.ValidatorType ?? '';
|
|
38
|
+
tp.Operator = part.Operator ?? '';
|
|
39
|
+
tp.ValueToCompare = part.ValueToCompare ?? '';
|
|
40
|
+
tp.ValuesToCompare = part.ValuesToCompare ?? [];
|
|
41
|
+
tp.IsNegative = part.IsNegative ?? false;
|
|
42
|
+
tp.IsIgnoreCase = part.IsIgnoreCase ?? false;
|
|
43
|
+
tp.UrlPart = part.UrlPart ?? '';
|
|
44
|
+
tp.CookieName = part.CookieName ?? '';
|
|
45
|
+
tp.HttpHeaderName = part.HttpHeaderName ?? '';
|
|
46
|
+
return tp;
|
|
47
|
+
});
|
|
48
|
+
return t;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return model;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as IntegrationModels from './IntegrationConfigModel'
|
|
2
2
|
import {KnownUserException} from '../Models'
|
|
3
3
|
import {IHttpRequest} from '../HttpContextProvider'
|
|
4
|
-
//@ts-ignore
|
|
5
|
-
import {URL} from '@fastly/as-url';
|
|
6
4
|
|
|
7
5
|
export interface IIntegrationEvaluator {
|
|
8
6
|
getMatchedIntegrationConfig(
|
|
@@ -35,7 +33,7 @@ export class IntegrationEvaluator implements IIntegrationEvaluator {
|
|
|
35
33
|
return null;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
private evaluateTrigger(trigger: IntegrationModels.TriggerModel, currentPageUrl: string, request: IHttpRequest):
|
|
36
|
+
private evaluateTrigger(trigger: IntegrationModels.TriggerModel, currentPageUrl: string, request: IHttpRequest): boolean {
|
|
39
37
|
if (trigger.LogicalOperator == IntegrationModels.LogicalOperatorType.Or) {
|
|
40
38
|
for (let i = 0; i < trigger.TriggerParts.length; i++) {
|
|
41
39
|
let part = trigger.TriggerParts[i];
|
|
@@ -54,7 +52,7 @@ export class IntegrationEvaluator implements IIntegrationEvaluator {
|
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
private evaluateTriggerPart(triggerPart: IntegrationModels.TriggerPart, currentPageUrl: string, request: IHttpRequest):
|
|
55
|
+
private evaluateTriggerPart(triggerPart: IntegrationModels.TriggerPart, currentPageUrl: string, request: IHttpRequest): boolean {
|
|
58
56
|
if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.UrlValidator) {
|
|
59
57
|
return UrlValidatorHelper.evaluate(triggerPart, currentPageUrl);
|
|
60
58
|
} else if (triggerPart.ValidatorType == IntegrationModels.ValidatorType.CookieValidator) {
|
|
@@ -72,7 +70,7 @@ export class IntegrationEvaluator implements IIntegrationEvaluator {
|
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
export class UrlValidatorHelper {
|
|
75
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, url: string):
|
|
73
|
+
public static evaluate(triggerPart: IntegrationModels.TriggerPart, url: string): boolean {
|
|
76
74
|
let urlpart = this.getUrlPart(triggerPart, url);
|
|
77
75
|
return ComparisonOperatorHelper.evaluate(
|
|
78
76
|
triggerPart.Operator,
|
|
@@ -107,7 +105,7 @@ export class UrlValidatorHelper {
|
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
export class CookieValidatorHelper {
|
|
110
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, request: IHttpRequest):
|
|
108
|
+
public static evaluate(triggerPart: IntegrationModels.TriggerPart, request: IHttpRequest): boolean {
|
|
111
109
|
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
112
110
|
triggerPart.IsNegative,
|
|
113
111
|
triggerPart.IsIgnoreCase,
|
|
@@ -122,7 +120,7 @@ export class CookieValidatorHelper {
|
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
export class UserAgentValidatorHelper {
|
|
125
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, userAgent: string):
|
|
123
|
+
public static evaluate(triggerPart: IntegrationModels.TriggerPart, userAgent: string): boolean {
|
|
126
124
|
|
|
127
125
|
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
128
126
|
triggerPart.IsNegative,
|
|
@@ -134,7 +132,7 @@ export class UserAgentValidatorHelper {
|
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
export class RequestBodyValidatorHelper {
|
|
137
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, bodyString: string):
|
|
135
|
+
public static evaluate(triggerPart: IntegrationModels.TriggerPart, bodyString: string): boolean {
|
|
138
136
|
|
|
139
137
|
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
140
138
|
triggerPart.IsNegative,
|
|
@@ -146,7 +144,7 @@ export class RequestBodyValidatorHelper {
|
|
|
146
144
|
}
|
|
147
145
|
|
|
148
146
|
export class HttpHeaderValidatorHelper {
|
|
149
|
-
public static evaluate(triggerPart: IntegrationModels.TriggerPart, headerValue: string):
|
|
147
|
+
public static evaluate(triggerPart: IntegrationModels.TriggerPart, headerValue: string): boolean {
|
|
150
148
|
return ComparisonOperatorHelper.evaluate(triggerPart.Operator,
|
|
151
149
|
triggerPart.IsNegative,
|
|
152
150
|
triggerPart.IsIgnoreCase,
|
|
@@ -158,11 +156,11 @@ export class HttpHeaderValidatorHelper {
|
|
|
158
156
|
|
|
159
157
|
export class ComparisonOperatorHelper {
|
|
160
158
|
public static evaluate(opt: string,
|
|
161
|
-
isNegative:
|
|
162
|
-
isIgnoreCase:
|
|
159
|
+
isNegative: boolean,
|
|
160
|
+
isIgnoreCase: boolean,
|
|
163
161
|
value: string,
|
|
164
162
|
valueToCompare: string,
|
|
165
|
-
valuesToCompare: Array<string> | null):
|
|
163
|
+
valuesToCompare: Array<string> | null): boolean {
|
|
166
164
|
if (valuesToCompare == null) {
|
|
167
165
|
valuesToCompare = new Array<string>();
|
|
168
166
|
}
|
|
@@ -179,7 +177,7 @@ export class ComparisonOperatorHelper {
|
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
|
|
182
|
-
private static contains(value: string, valueToCompare: string, isNegative:
|
|
180
|
+
private static contains(value: string, valueToCompare: string, isNegative: boolean, ignoreCase: boolean): boolean {
|
|
183
181
|
if (valueToCompare == "*" && value != "")
|
|
184
182
|
return true;
|
|
185
183
|
|
|
@@ -196,7 +194,7 @@ export class ComparisonOperatorHelper {
|
|
|
196
194
|
return evaluation;
|
|
197
195
|
}
|
|
198
196
|
|
|
199
|
-
private static equalS(value: string, valueToCompare: string, isNegative:
|
|
197
|
+
private static equalS(value: string, valueToCompare: string, isNegative: boolean, ignoreCase: boolean): boolean {
|
|
200
198
|
let evaluation = false;
|
|
201
199
|
|
|
202
200
|
if (ignoreCase)
|
|
@@ -210,7 +208,7 @@ export class ComparisonOperatorHelper {
|
|
|
210
208
|
return evaluation;
|
|
211
209
|
}
|
|
212
210
|
|
|
213
|
-
private static equalsAny(value: string, valuesToCompare: Array<string>, isNegative:
|
|
211
|
+
private static equalsAny(value: string, valuesToCompare: Array<string>, isNegative: boolean, isIgnoreCase: boolean): boolean {
|
|
214
212
|
for (let i = 0; i < valuesToCompare.length; i++) {
|
|
215
213
|
let valueToCompare = valuesToCompare[i];
|
|
216
214
|
if (ComparisonOperatorHelper.equalS(value, valueToCompare, false, isIgnoreCase))
|
|
@@ -220,7 +218,7 @@ export class ComparisonOperatorHelper {
|
|
|
220
218
|
return isNegative;
|
|
221
219
|
}
|
|
222
220
|
|
|
223
|
-
private static containsAny(value: string, valuesToCompare: Array<string>, isNegative:
|
|
221
|
+
private static containsAny(value: string, valuesToCompare: Array<string>, isNegative: boolean, isIgnoreCase: boolean): boolean {
|
|
224
222
|
for (let i = 0; i < valuesToCompare.length; i++) {
|
|
225
223
|
let valueToCompare = valuesToCompare[i];
|
|
226
224
|
if (ComparisonOperatorHelper.contains(value, valueToCompare, false, isIgnoreCase))
|
|
@@ -9,8 +9,8 @@ export class IntegrationConfigModel {
|
|
|
9
9
|
CookieDomain: string = "";
|
|
10
10
|
LayoutName: string = "";
|
|
11
11
|
Culture: string = "";
|
|
12
|
-
ExtendCookieValidity:
|
|
13
|
-
CookieValidityMinute:
|
|
12
|
+
ExtendCookieValidity: boolean = false;
|
|
13
|
+
CookieValidityMinute: number = 0;
|
|
14
14
|
QueueDomain: string = "";
|
|
15
15
|
RedirectLogic: string = "";
|
|
16
16
|
ForcedTargetUrl: string = "";
|
|
@@ -24,7 +24,7 @@ export class IntegrationConfigModel {
|
|
|
24
24
|
|
|
25
25
|
export class CustomerIntegration {
|
|
26
26
|
Integrations: Array<IntegrationConfigModel>;
|
|
27
|
-
Version:
|
|
27
|
+
Version: number;
|
|
28
28
|
Description: string;
|
|
29
29
|
|
|
30
30
|
constructor() {
|
|
@@ -39,8 +39,8 @@ export class TriggerPart {
|
|
|
39
39
|
Operator: string = "";
|
|
40
40
|
ValueToCompare: string = "";
|
|
41
41
|
ValuesToCompare: Array<string>;
|
|
42
|
-
IsNegative:
|
|
43
|
-
IsIgnoreCase:
|
|
42
|
+
IsNegative: boolean = false;
|
|
43
|
+
IsIgnoreCase: boolean = false;
|
|
44
44
|
UrlPart: string = ""; // UrlValidator
|
|
45
45
|
CookieName: string = ""; // CookieValidator
|
|
46
46
|
HttpHeaderName: string = ""; // HttpHeaderValidator
|
|
@@ -30,7 +30,7 @@ export class KnownUser {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
private static isQueueAjaxCall(
|
|
33
|
-
httpContextProvider: IHttpContextProvider):
|
|
33
|
+
httpContextProvider: IHttpContextProvider): boolean {
|
|
34
34
|
const ajaxHeader = httpContextProvider.getHttpRequest().getHeader(this.QueueITAjaxHeaderKey);
|
|
35
35
|
return ajaxHeader != '';
|
|
36
36
|
}
|
|
@@ -61,9 +61,7 @@ export class KnownUser {
|
|
|
61
61
|
debugEntries: Map<string, string>,
|
|
62
62
|
httpContextProvider: IHttpContextProvider): void {
|
|
63
63
|
let cookieValue = "";
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < entryKeys.length; i++) {
|
|
66
|
-
let key: string = entryKeys[i];
|
|
64
|
+
for (const key of debugEntries.keys()) {
|
|
67
65
|
cookieValue += key + "=" + debugEntries.get(key) + "|";
|
|
68
66
|
}
|
|
69
67
|
|
|
@@ -90,7 +88,7 @@ export class KnownUser {
|
|
|
90
88
|
httpContextProvider: IHttpContextProvider,
|
|
91
89
|
dateTimeProvider: IDateTimeProvider,
|
|
92
90
|
debugEntries: Map<string, string>,
|
|
93
|
-
isDebug:
|
|
91
|
+
isDebug: boolean): ValidationResult {
|
|
94
92
|
|
|
95
93
|
if (isDebug) {
|
|
96
94
|
debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
|
|
@@ -133,7 +131,7 @@ export class KnownUser {
|
|
|
133
131
|
httpContextProvider: IHttpContextProvider,
|
|
134
132
|
dateTimeProvider: IDateTimeProvider,
|
|
135
133
|
debugEntries: Map<string, string>,
|
|
136
|
-
isDebug:
|
|
134
|
+
isDebug: boolean): ValidationResult {
|
|
137
135
|
|
|
138
136
|
targetUrl = this.generateTargetUrl(targetUrl, httpContextProvider);
|
|
139
137
|
|
|
@@ -177,7 +175,7 @@ export class KnownUser {
|
|
|
177
175
|
httpContextProvider: IHttpContextProvider,
|
|
178
176
|
dateTimeProvider: IDateTimeProvider,
|
|
179
177
|
debugEntries: Map<string, string>,
|
|
180
|
-
isDebug:
|
|
178
|
+
isDebug: boolean): ValidationResult {
|
|
181
179
|
let targetUrl: string;
|
|
182
180
|
|
|
183
181
|
if (matchedConfig.RedirectLogic == "ForcedTargetUrl") {
|
|
@@ -211,7 +209,7 @@ export class KnownUser {
|
|
|
211
209
|
httpContextProvider: IHttpContextProvider,
|
|
212
210
|
dateTimeProvider: IDateTimeProvider,
|
|
213
211
|
debugEntries: Map<string, string>,
|
|
214
|
-
isDebug:
|
|
212
|
+
isDebug: boolean): ValidationResult {
|
|
215
213
|
const cancelEventConfig = new CancelEventConfig(
|
|
216
214
|
matchedConfig.EventId,
|
|
217
215
|
matchedConfig.QueueDomain,
|
|
@@ -235,7 +233,7 @@ export class KnownUser {
|
|
|
235
233
|
|
|
236
234
|
public static extendQueueCookie(
|
|
237
235
|
eventId: string,
|
|
238
|
-
cookieValidityMinute:
|
|
236
|
+
cookieValidityMinute: number,
|
|
239
237
|
cookieDomain: string,
|
|
240
238
|
secretKey: string,
|
|
241
239
|
httpContextProvider: IHttpContextProvider): KnownUserException | null {
|
|
@@ -20,10 +20,10 @@ export class QueueEventConfig {
|
|
|
20
20
|
public layoutName: string,
|
|
21
21
|
public culture: string,
|
|
22
22
|
public queueDomain: string,
|
|
23
|
-
public extendCookieValidity:
|
|
24
|
-
public cookieValidityMinute:
|
|
23
|
+
public extendCookieValidity: boolean,
|
|
24
|
+
public cookieValidityMinute: number,
|
|
25
25
|
public cookieDomain: string,
|
|
26
|
-
public version:
|
|
26
|
+
public version: number,
|
|
27
27
|
public actionName: string = 'unspecified') {
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -44,7 +44,7 @@ export class CancelEventConfig {
|
|
|
44
44
|
constructor(public eventId: string,
|
|
45
45
|
public queueDomain: string,
|
|
46
46
|
public cookieDomain: string,
|
|
47
|
-
public version:
|
|
47
|
+
public version: number,
|
|
48
48
|
public actionName: string = 'unspecified') {
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -68,9 +68,9 @@ export class RequestValidationResult {
|
|
|
68
68
|
) {
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
public isAjaxResult:
|
|
71
|
+
public isAjaxResult: boolean = false;
|
|
72
72
|
|
|
73
|
-
public doRedirect():
|
|
73
|
+
public doRedirect(): boolean {
|
|
74
74
|
return this.redirectUrl.length > 0;
|
|
75
75
|
}
|
|
76
76
|
|