@queue-it/fastly 1.0.4 → 2.0.0-beta.0

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.
@@ -1,395 +1,393 @@
1
- import {UserInQueueService} from './UserInQueueService'
2
- import {UserInQueueStateCookieRepository} from './UserInQueueStateCookieRepository'
3
- import {IDateTimeProvider, IHttpContextProvider} from './HttpContextProvider'
4
- import {
5
- CancelEventConfig,
6
- QueueEventConfig,
7
- KnownUserException,
8
- RequestValidationResult,
9
- ActionTypes,
10
- ValidationResult
11
- } from './Models'
12
- import {Utils, ConnectorDiagnostics, DateTimeProvider} from './QueueITHelpers'
13
- import * as IntegrationConfig from './IntegrationConfig/IntegrationConfigModel'
14
- import * as IntegrationConfigHelpers from './IntegrationConfig/IntegrationConfigHelpers'
15
- import {CustomerIntegrationDecodingHandler} from "./IntegrationConfig/CustomerIntegrationDecodingHandler";
16
-
17
- export class KnownUser {
18
- public static readonly QueueITTokenKey: string = "queueittoken";
19
- public static readonly QueueITDebugKey: string = "queueitdebug";
20
- public static readonly QueueITAjaxHeaderKey: string = "x-queueit-ajaxpageurl";
21
-
22
- static UserInQueueService: UserInQueueService | null = null;
23
-
24
- private static getUserInQueueService(
25
- httpContextProvider: IHttpContextProvider): UserInQueueService {
26
- if (this.UserInQueueService == null) {
27
- return new UserInQueueService(new UserInQueueStateCookieRepository(httpContextProvider));
28
- }
29
- return this.UserInQueueService!;
30
- }
31
-
32
- private static isQueueAjaxCall(
33
- httpContextProvider: IHttpContextProvider): bool {
34
- const ajaxHeader = httpContextProvider.getHttpRequest().getHeader(this.QueueITAjaxHeaderKey);
35
- return ajaxHeader != '';
36
- }
37
-
38
- private static generateTargetUrl(
39
- originalTargetUrl: string,
40
- httpContextProvider: IHttpContextProvider): string {
41
- return !this.isQueueAjaxCall(httpContextProvider) ?
42
- originalTargetUrl :
43
- Utils.decodeUrl(httpContextProvider.getHttpRequest().getHeader(this.QueueITAjaxHeaderKey));
44
- }
45
-
46
- private static logExtraRequestDetails(
47
- debugEntries: Map<string, string>,
48
- httpContextProvider: IHttpContextProvider,
49
- dateTimeProvider: IDateTimeProvider): void {
50
- const date = dateTimeProvider.getCurrentTime();
51
- debugEntries.set("ServerUtcTime", date.toISOString().split('.')[0] + "Z");
52
- debugEntries.set("RequestIP", httpContextProvider.getHttpRequest().getUserHostAddress());
53
- debugEntries.set("RequestHttpHeader_Via", httpContextProvider.getHttpRequest().getHeader("Via"));
54
- debugEntries.set("RequestHttpHeader_Forwarded", httpContextProvider.getHttpRequest().getHeader("Forwarded"));
55
- debugEntries.set("RequestHttpHeader_XForwardedFor", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-For"));
56
- debugEntries.set("RequestHttpHeader_XForwardedHost", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-Host"));
57
- debugEntries.set("RequestHttpHeader_XForwardedProto", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-Proto"));
58
- }
59
-
60
- private static setDebugCookie(
61
- debugEntries: Map<string, string>,
62
- httpContextProvider: IHttpContextProvider): void {
63
- let cookieValue = "";
64
- let entryKeys = debugEntries.keys();
65
- for (let i = 0; i < entryKeys.length; i++) {
66
- let key: string = entryKeys[i];
67
- cookieValue += key + "=" + debugEntries.get(key) + "|";
68
- }
69
-
70
- if (cookieValue.lastIndexOf("|") == cookieValue.length - 1) {
71
- cookieValue = cookieValue.substring(0, cookieValue.length - 1);
72
- }
73
-
74
- if (cookieValue == "")
75
- return;
76
-
77
- httpContextProvider.getHttpResponse().setCookie(
78
- this.QueueITDebugKey,
79
- cookieValue,
80
- "",
81
- Utils.getCurrentTime() + 20 * 60); // now + 20 mins
82
- }
83
-
84
- private static _resolveQueueRequestByLocalConfig(
85
- targetUrl: string,
86
- queueitToken: string,
87
- queueConfig: QueueEventConfig | null,
88
- customerId: string,
89
- secretKey: string,
90
- httpContextProvider: IHttpContextProvider,
91
- dateTimeProvider: IDateTimeProvider,
92
- debugEntries: Map<string, string>,
93
- isDebug: bool): ValidationResult {
94
-
95
- if (isDebug) {
96
- debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
97
- debugEntries.set("TargetUrl", targetUrl);
98
- debugEntries.set("QueueitToken", queueitToken);
99
- debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
100
- debugEntries.set("QueueConfig", queueConfig != null ? queueConfig.getString() : "NULL");
101
-
102
- this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
103
- }
104
-
105
- if (customerId == "")
106
- return new ValidationResult(null, new KnownUserException("customerId can not be null or empty."));
107
- if (secretKey == "")
108
- return new ValidationResult(null, new KnownUserException("secretKey can not be null or empty."));
109
- if (queueConfig == null)
110
- return new ValidationResult(null, new KnownUserException("queueConfig can not be null."));
111
- if (queueConfig.eventId == "")
112
- return new ValidationResult(null, new KnownUserException("queueConfig.eventId can not be null or empty."));
113
- if (queueConfig.queueDomain == "")
114
- return new ValidationResult(null, new KnownUserException("queueConfig.queueDomain can not be null or empty."));
115
- if (queueConfig.cookieValidityMinute <= 0)
116
- return new ValidationResult(null, new KnownUserException("queueConfig.cookieValidityMinute should be integer greater than 0."));
117
-
118
- const userInQueueService = this.getUserInQueueService(httpContextProvider);
119
- const result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey);
120
- if (result != null && result.first != null) {
121
- result.first!.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
122
- }
123
-
124
- return result;
125
- }
126
-
127
- private static _cancelRequestByLocalConfig(
128
- targetUrl: string,
129
- queueitToken: string,
130
- cancelConfig: CancelEventConfig | null,
131
- customerId: string,
132
- secretKey: string,
133
- httpContextProvider: IHttpContextProvider,
134
- dateTimeProvider: IDateTimeProvider,
135
- debugEntries: Map<string, string>,
136
- isDebug: bool): ValidationResult {
137
-
138
- targetUrl = this.generateTargetUrl(targetUrl, httpContextProvider);
139
-
140
- if (isDebug) {
141
- debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
142
- debugEntries.set("TargetUrl", targetUrl);
143
- debugEntries.set("QueueitToken", queueitToken);
144
- debugEntries.set("CancelConfig", cancelConfig != null ? cancelConfig.getString() : "NULL");
145
- debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
146
-
147
- this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
148
- }
149
-
150
- if (targetUrl == '')
151
- return new ValidationResult(null, new KnownUserException("targetUrl can not be null or empty."));
152
- if (customerId == '')
153
- return new ValidationResult(null, new KnownUserException("customerId can not be null or empty."));
154
- if (secretKey == '')
155
- return new ValidationResult(null, new KnownUserException("secretKey can not be null or empty."));
156
- if (cancelConfig == null)
157
- return new ValidationResult(null, new KnownUserException("cancelConfig can not be null."));
158
- if (cancelConfig.eventId == '')
159
- return new ValidationResult(null, new KnownUserException("cancelConfig.eventId can not be null or empty."));
160
- if (cancelConfig.queueDomain == '')
161
- return new ValidationResult(null, new KnownUserException("cancelConfig.queueDomain can not be null or empty."));
162
-
163
- const userInQueueService = this.getUserInQueueService(httpContextProvider);
164
- const result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey);
165
- if (result.first != null) {
166
- result.first!.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
167
- }
168
-
169
- return result;
170
- }
171
-
172
- private static handleQueueAction(
173
- currentUrlWithoutQueueITToken: string, queueitToken: string,
174
- customerIntegrationInfo: IntegrationConfig.CustomerIntegration, customerId: string,
175
- secretKey: string,
176
- matchedConfig: IntegrationConfig.IntegrationConfigModel,
177
- httpContextProvider: IHttpContextProvider,
178
- dateTimeProvider: IDateTimeProvider,
179
- debugEntries: Map<string, string>,
180
- isDebug: bool): ValidationResult {
181
- let targetUrl: string;
182
-
183
- if (matchedConfig.RedirectLogic == "ForcedTargetUrl") {
184
- targetUrl = matchedConfig.ForcedTargetUrl;
185
- } else if (matchedConfig.RedirectLogic == "EventTargetUrl") {
186
- targetUrl = "";
187
- } else {
188
- targetUrl = this.generateTargetUrl(currentUrlWithoutQueueITToken, httpContextProvider);
189
- }
190
-
191
- const queueEventConfig = new QueueEventConfig(
192
- matchedConfig.EventId,
193
- matchedConfig.LayoutName,
194
- matchedConfig.Culture,
195
- matchedConfig.QueueDomain,
196
- matchedConfig.ExtendCookieValidity,
197
- matchedConfig.CookieValidityMinute,
198
- matchedConfig.CookieDomain,
199
- customerIntegrationInfo.Version,
200
- matchedConfig.Name
201
- );
202
-
203
- return this._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueEventConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, isDebug);
204
- }
205
-
206
- private static handleCancelAction(
207
- currentUrlWithoutQueueITToken: string, queueitToken: string,
208
- customerIntegrationInfo: IntegrationConfig.CustomerIntegration, customerId: string,
209
- secretKey: string,
210
- matchedConfig: IntegrationConfig.IntegrationConfigModel,
211
- httpContextProvider: IHttpContextProvider,
212
- dateTimeProvider: IDateTimeProvider,
213
- debugEntries: Map<string, string>,
214
- isDebug: bool): ValidationResult {
215
- const cancelEventConfig = new CancelEventConfig(
216
- matchedConfig.EventId,
217
- matchedConfig.QueueDomain,
218
- matchedConfig.CookieDomain,
219
- customerIntegrationInfo.Version,
220
- matchedConfig.Name
221
- );
222
-
223
- const targetUrl = this.generateTargetUrl(currentUrlWithoutQueueITToken, httpContextProvider);
224
- return this._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelEventConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, isDebug);
225
- }
226
-
227
- private static handleIgnoreAction(
228
- httpContextProvider: IHttpContextProvider,
229
- actionName: string): ValidationResult {
230
- const userInQueueService = this.getUserInQueueService(httpContextProvider);
231
- const result = userInQueueService.getIgnoreResult(actionName);
232
- result.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
233
- return new ValidationResult(result, null);
234
- }
235
-
236
- public static extendQueueCookie(
237
- eventId: string,
238
- cookieValidityMinute: i64,
239
- cookieDomain: string,
240
- secretKey: string,
241
- httpContextProvider: IHttpContextProvider): KnownUserException | null {
242
- if (eventId == "") {
243
- return new KnownUserException("eventId can not be null or empty.");
244
- }
245
- if (secretKey == "") {
246
- return new KnownUserException("secretKey can not be null or empty.");
247
- }
248
- if (cookieValidityMinute <= 0) {
249
- return new KnownUserException("cookieValidityMinute should be integer greater than 0.");
250
- }
251
-
252
- const userInQueueService = this.getUserInQueueService(httpContextProvider);
253
- userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey);
254
- return null;
255
- }
256
-
257
- public static resolveQueueRequestByLocalConfig(
258
- targetUrl: string,
259
- queueitToken: string,
260
- queueConfig: QueueEventConfig | null,
261
- customerId: string,
262
- secretKey: string,
263
- httpContextProvider: IHttpContextProvider,
264
- dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
265
- if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
266
- const debugEntries = new Map<string, string>();
267
- const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
268
-
269
- if (connectorDiagnostics.hasError) {
270
- return new ValidationResult(connectorDiagnostics.validationResult, null);
271
- }
272
-
273
- targetUrl = this.generateTargetUrl(targetUrl, httpContextProvider);
274
- const result = this._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
275
- if (result != null && result.second != null) {
276
- if (connectorDiagnostics.isEnabled) {
277
- debugEntries.set("Exception", result.second!.message);
278
- }
279
- }
280
- this.setDebugCookie(debugEntries, httpContextProvider);
281
- return result;
282
- }
283
-
284
- private static handleException(diagnostics: ConnectorDiagnostics,
285
- debugEntries: Map<string, string>,
286
- ex: KnownUserException,
287
- httpContext: IHttpContextProvider): void {
288
- if (diagnostics.isEnabled) debugEntries.set('Exception', ex.message);
289
- this.setDebugCookie(debugEntries, httpContext);
290
- }
291
-
292
- public static validateRequestByIntegrationConfig(
293
- currentUrlWithoutQueueITToken: string,
294
- queueitToken: string,
295
- integrationsConfigString: string,
296
- customerId: string,
297
- secretKey: string,
298
- httpContextProvider: IHttpContextProvider,
299
- dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
300
- if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
301
-
302
- const debugEntries = new Map<string, string>();
303
-
304
- const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
305
- if (connectorDiagnostics.hasError) {
306
- return new ValidationResult(connectorDiagnostics.validationResult, null);
307
- }
308
- if (connectorDiagnostics.isEnabled) {
309
- debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
310
- debugEntries.set("PureUrl", currentUrlWithoutQueueITToken);
311
- debugEntries.set("QueueitToken", queueitToken);
312
- debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
313
-
314
- this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
315
- }
316
-
317
- const customerIntegrationInfo = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
318
-
319
- if (connectorDiagnostics.isEnabled) {
320
- debugEntries.set('ConfigVersion', customerIntegrationInfo && customerIntegrationInfo.Version != 0 ? customerIntegrationInfo.Version.toString() : "NULL");
321
- }
322
-
323
- if (currentUrlWithoutQueueITToken == '') {
324
- const ex = new KnownUserException("currentUrlWithoutQueueITToken can not be null or empty.");
325
- this.handleException(connectorDiagnostics, debugEntries, ex, httpContextProvider);
326
- return new ValidationResult(null, ex);
327
- }
328
- if (customerIntegrationInfo == null || customerIntegrationInfo.Version == 0) {
329
- const ex = new KnownUserException("integrationsConfigString can not be null or empty.");
330
- this.handleException(connectorDiagnostics, debugEntries, ex, httpContextProvider);
331
- return new ValidationResult(null, ex);
332
- }
333
-
334
- const configEvaluator = new IntegrationConfigHelpers.IntegrationEvaluator();
335
-
336
- const configMatchResult = configEvaluator.getMatchedIntegrationConfig(
337
- customerIntegrationInfo,
338
- currentUrlWithoutQueueITToken,
339
- httpContextProvider.getHttpRequest());
340
-
341
- if (connectorDiagnostics.isEnabled) {
342
- debugEntries.set('MatchedConfig', configMatchResult != null && configMatchResult.first != null ?
343
- configMatchResult.first!.Name
344
- : "NULL");
345
- }
346
- if (configMatchResult == null || configMatchResult.second != null) {
347
- this.setDebugCookie(debugEntries, httpContextProvider);
348
- return new ValidationResult(new RequestValidationResult("", "", "", "", "", ""), null);
349
- }
350
- const matchedConfig = configMatchResult.first!;
351
- let result: ValidationResult
352
-
353
- if (matchedConfig.ActionType == ActionTypes.QueueAction) {
354
- result = this.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
355
- customerId, secretKey, matchedConfig, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
356
- } else if (matchedConfig.ActionType == ActionTypes.CancelAction) {
357
- result = this.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
358
- customerId, secretKey, matchedConfig, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
359
- } else {
360
- result = this.handleIgnoreAction(httpContextProvider, matchedConfig.Name);
361
- }
362
- if (result.second != null && connectorDiagnostics.isEnabled) {
363
- debugEntries.set('Exception', result.second!.message);
364
- }
365
-
366
- this.setDebugCookie(debugEntries, httpContextProvider);
367
- return result;
368
- }
369
-
370
- public static cancelRequestByLocalConfig(
371
- targetUrl: string,
372
- queueitToken: string,
373
- cancelConfig: CancelEventConfig | null,
374
- customerId: string,
375
- secretKey: string,
376
- httpContextProvider: IHttpContextProvider,
377
- dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
378
- if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
379
- const debugEntries = new Map<string, string>();
380
- const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
381
-
382
- if (connectorDiagnostics.hasError)
383
- return new ValidationResult(connectorDiagnostics.validationResult, null);
384
-
385
- const result = this._cancelRequestByLocalConfig(
386
- targetUrl, queueitToken, cancelConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
387
- if (result.second != null && connectorDiagnostics.isEnabled) {
388
- debugEntries.set('Exception', result.second!.message);
389
- }
390
- this.setDebugCookie(debugEntries, httpContextProvider);
391
-
392
- return result;
393
- }
394
- }
395
-
1
+ import {UserInQueueService} from './UserInQueueService'
2
+ import {UserInQueueStateCookieRepository} from './UserInQueueStateCookieRepository'
3
+ import {IDateTimeProvider, IHttpContextProvider} from './HttpContextProvider'
4
+ import {
5
+ CancelEventConfig,
6
+ QueueEventConfig,
7
+ KnownUserException,
8
+ RequestValidationResult,
9
+ ActionTypes,
10
+ ValidationResult
11
+ } from './Models'
12
+ import {Utils, ConnectorDiagnostics, DateTimeProvider} from './QueueITHelpers'
13
+ import * as IntegrationConfig from './IntegrationConfig/IntegrationConfigModel'
14
+ import * as IntegrationConfigHelpers from './IntegrationConfig/IntegrationConfigHelpers'
15
+ import {CustomerIntegrationDecodingHandler} from "./IntegrationConfig/CustomerIntegrationDecodingHandler";
16
+
17
+ export class KnownUser {
18
+ public static readonly QueueITTokenKey: string = "queueittoken";
19
+ public static readonly QueueITDebugKey: string = "queueitdebug";
20
+ public static readonly QueueITAjaxHeaderKey: string = "x-queueit-ajaxpageurl";
21
+
22
+ static UserInQueueService: UserInQueueService | null = null;
23
+
24
+ private static getUserInQueueService(
25
+ httpContextProvider: IHttpContextProvider): UserInQueueService {
26
+ if (this.UserInQueueService == null) {
27
+ return new UserInQueueService(new UserInQueueStateCookieRepository(httpContextProvider));
28
+ }
29
+ return this.UserInQueueService!;
30
+ }
31
+
32
+ private static isQueueAjaxCall(
33
+ httpContextProvider: IHttpContextProvider): boolean {
34
+ const ajaxHeader = httpContextProvider.getHttpRequest().getHeader(this.QueueITAjaxHeaderKey);
35
+ return ajaxHeader != '';
36
+ }
37
+
38
+ private static generateTargetUrl(
39
+ originalTargetUrl: string,
40
+ httpContextProvider: IHttpContextProvider): string {
41
+ return !this.isQueueAjaxCall(httpContextProvider) ?
42
+ originalTargetUrl :
43
+ Utils.decodeUrl(httpContextProvider.getHttpRequest().getHeader(this.QueueITAjaxHeaderKey));
44
+ }
45
+
46
+ private static logExtraRequestDetails(
47
+ debugEntries: Map<string, string>,
48
+ httpContextProvider: IHttpContextProvider,
49
+ dateTimeProvider: IDateTimeProvider): void {
50
+ const date = dateTimeProvider.getCurrentTime();
51
+ debugEntries.set("ServerUtcTime", date.toISOString().split('.')[0] + "Z");
52
+ debugEntries.set("RequestIP", httpContextProvider.getHttpRequest().getUserHostAddress());
53
+ debugEntries.set("RequestHttpHeader_Via", httpContextProvider.getHttpRequest().getHeader("Via"));
54
+ debugEntries.set("RequestHttpHeader_Forwarded", httpContextProvider.getHttpRequest().getHeader("Forwarded"));
55
+ debugEntries.set("RequestHttpHeader_XForwardedFor", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-For"));
56
+ debugEntries.set("RequestHttpHeader_XForwardedHost", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-Host"));
57
+ debugEntries.set("RequestHttpHeader_XForwardedProto", httpContextProvider.getHttpRequest().getHeader("X-Forwarded-Proto"));
58
+ }
59
+
60
+ private static setDebugCookie(
61
+ debugEntries: Map<string, string>,
62
+ httpContextProvider: IHttpContextProvider): void {
63
+ let cookieValue = "";
64
+ for (const key of debugEntries.keys()) {
65
+ cookieValue += key + "=" + debugEntries.get(key) + "|";
66
+ }
67
+
68
+ if (cookieValue.lastIndexOf("|") == cookieValue.length - 1) {
69
+ cookieValue = cookieValue.substring(0, cookieValue.length - 1);
70
+ }
71
+
72
+ if (cookieValue == "")
73
+ return;
74
+
75
+ httpContextProvider.getHttpResponse().setCookie(
76
+ this.QueueITDebugKey,
77
+ cookieValue,
78
+ "",
79
+ Utils.getCurrentTime() + 20 * 60); // now + 20 mins
80
+ }
81
+
82
+ private static _resolveQueueRequestByLocalConfig(
83
+ targetUrl: string,
84
+ queueitToken: string,
85
+ queueConfig: QueueEventConfig | null,
86
+ customerId: string,
87
+ secretKey: string,
88
+ httpContextProvider: IHttpContextProvider,
89
+ dateTimeProvider: IDateTimeProvider,
90
+ debugEntries: Map<string, string>,
91
+ isDebug: boolean): ValidationResult {
92
+
93
+ if (isDebug) {
94
+ debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
95
+ debugEntries.set("TargetUrl", targetUrl);
96
+ debugEntries.set("QueueitToken", queueitToken);
97
+ debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
98
+ debugEntries.set("QueueConfig", queueConfig != null ? queueConfig.getString() : "NULL");
99
+
100
+ this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
101
+ }
102
+
103
+ if (customerId == "")
104
+ return new ValidationResult(null, new KnownUserException("customerId can not be null or empty."));
105
+ if (secretKey == "")
106
+ return new ValidationResult(null, new KnownUserException("secretKey can not be null or empty."));
107
+ if (queueConfig == null)
108
+ return new ValidationResult(null, new KnownUserException("queueConfig can not be null."));
109
+ if (queueConfig.eventId == "")
110
+ return new ValidationResult(null, new KnownUserException("queueConfig.eventId can not be null or empty."));
111
+ if (queueConfig.queueDomain == "")
112
+ return new ValidationResult(null, new KnownUserException("queueConfig.queueDomain can not be null or empty."));
113
+ if (queueConfig.cookieValidityMinute <= 0)
114
+ return new ValidationResult(null, new KnownUserException("queueConfig.cookieValidityMinute should be integer greater than 0."));
115
+
116
+ const userInQueueService = this.getUserInQueueService(httpContextProvider);
117
+ const result = userInQueueService.validateQueueRequest(targetUrl, queueitToken, queueConfig, customerId, secretKey);
118
+ if (result != null && result.first != null) {
119
+ result.first!.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
120
+ }
121
+
122
+ return result;
123
+ }
124
+
125
+ private static _cancelRequestByLocalConfig(
126
+ targetUrl: string,
127
+ queueitToken: string,
128
+ cancelConfig: CancelEventConfig | null,
129
+ customerId: string,
130
+ secretKey: string,
131
+ httpContextProvider: IHttpContextProvider,
132
+ dateTimeProvider: IDateTimeProvider,
133
+ debugEntries: Map<string, string>,
134
+ isDebug: boolean): ValidationResult {
135
+
136
+ targetUrl = this.generateTargetUrl(targetUrl, httpContextProvider);
137
+
138
+ if (isDebug) {
139
+ debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
140
+ debugEntries.set("TargetUrl", targetUrl);
141
+ debugEntries.set("QueueitToken", queueitToken);
142
+ debugEntries.set("CancelConfig", cancelConfig != null ? cancelConfig.getString() : "NULL");
143
+ debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
144
+
145
+ this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
146
+ }
147
+
148
+ if (targetUrl == '')
149
+ return new ValidationResult(null, new KnownUserException("targetUrl can not be null or empty."));
150
+ if (customerId == '')
151
+ return new ValidationResult(null, new KnownUserException("customerId can not be null or empty."));
152
+ if (secretKey == '')
153
+ return new ValidationResult(null, new KnownUserException("secretKey can not be null or empty."));
154
+ if (cancelConfig == null)
155
+ return new ValidationResult(null, new KnownUserException("cancelConfig can not be null."));
156
+ if (cancelConfig.eventId == '')
157
+ return new ValidationResult(null, new KnownUserException("cancelConfig.eventId can not be null or empty."));
158
+ if (cancelConfig.queueDomain == '')
159
+ return new ValidationResult(null, new KnownUserException("cancelConfig.queueDomain can not be null or empty."));
160
+
161
+ const userInQueueService = this.getUserInQueueService(httpContextProvider);
162
+ const result = userInQueueService.validateCancelRequest(targetUrl, cancelConfig, customerId, secretKey);
163
+ if (result.first != null) {
164
+ result.first!.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
165
+ }
166
+
167
+ return result;
168
+ }
169
+
170
+ private static handleQueueAction(
171
+ currentUrlWithoutQueueITToken: string, queueitToken: string,
172
+ customerIntegrationInfo: IntegrationConfig.CustomerIntegration, customerId: string,
173
+ secretKey: string,
174
+ matchedConfig: IntegrationConfig.IntegrationConfigModel,
175
+ httpContextProvider: IHttpContextProvider,
176
+ dateTimeProvider: IDateTimeProvider,
177
+ debugEntries: Map<string, string>,
178
+ isDebug: boolean): ValidationResult {
179
+ let targetUrl: string;
180
+
181
+ if (matchedConfig.RedirectLogic == "ForcedTargetUrl") {
182
+ targetUrl = matchedConfig.ForcedTargetUrl;
183
+ } else if (matchedConfig.RedirectLogic == "EventTargetUrl") {
184
+ targetUrl = "";
185
+ } else {
186
+ targetUrl = this.generateTargetUrl(currentUrlWithoutQueueITToken, httpContextProvider);
187
+ }
188
+
189
+ const queueEventConfig = new QueueEventConfig(
190
+ matchedConfig.EventId,
191
+ matchedConfig.LayoutName,
192
+ matchedConfig.Culture,
193
+ matchedConfig.QueueDomain,
194
+ matchedConfig.ExtendCookieValidity,
195
+ matchedConfig.CookieValidityMinute,
196
+ matchedConfig.CookieDomain,
197
+ customerIntegrationInfo.Version,
198
+ matchedConfig.Name
199
+ );
200
+
201
+ return this._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueEventConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, isDebug);
202
+ }
203
+
204
+ private static handleCancelAction(
205
+ currentUrlWithoutQueueITToken: string, queueitToken: string,
206
+ customerIntegrationInfo: IntegrationConfig.CustomerIntegration, customerId: string,
207
+ secretKey: string,
208
+ matchedConfig: IntegrationConfig.IntegrationConfigModel,
209
+ httpContextProvider: IHttpContextProvider,
210
+ dateTimeProvider: IDateTimeProvider,
211
+ debugEntries: Map<string, string>,
212
+ isDebug: boolean): ValidationResult {
213
+ const cancelEventConfig = new CancelEventConfig(
214
+ matchedConfig.EventId,
215
+ matchedConfig.QueueDomain,
216
+ matchedConfig.CookieDomain,
217
+ customerIntegrationInfo.Version,
218
+ matchedConfig.Name
219
+ );
220
+
221
+ const targetUrl = this.generateTargetUrl(currentUrlWithoutQueueITToken, httpContextProvider);
222
+ return this._cancelRequestByLocalConfig(targetUrl, queueitToken, cancelEventConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, isDebug);
223
+ }
224
+
225
+ private static handleIgnoreAction(
226
+ httpContextProvider: IHttpContextProvider,
227
+ actionName: string): ValidationResult {
228
+ const userInQueueService = this.getUserInQueueService(httpContextProvider);
229
+ const result = userInQueueService.getIgnoreResult(actionName);
230
+ result.isAjaxResult = this.isQueueAjaxCall(httpContextProvider);
231
+ return new ValidationResult(result, null);
232
+ }
233
+
234
+ public static extendQueueCookie(
235
+ eventId: string,
236
+ cookieValidityMinute: number,
237
+ cookieDomain: string,
238
+ secretKey: string,
239
+ httpContextProvider: IHttpContextProvider): KnownUserException | null {
240
+ if (eventId == "") {
241
+ return new KnownUserException("eventId can not be null or empty.");
242
+ }
243
+ if (secretKey == "") {
244
+ return new KnownUserException("secretKey can not be null or empty.");
245
+ }
246
+ if (cookieValidityMinute <= 0) {
247
+ return new KnownUserException("cookieValidityMinute should be integer greater than 0.");
248
+ }
249
+
250
+ const userInQueueService = this.getUserInQueueService(httpContextProvider);
251
+ userInQueueService.extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey);
252
+ return null;
253
+ }
254
+
255
+ public static resolveQueueRequestByLocalConfig(
256
+ targetUrl: string,
257
+ queueitToken: string,
258
+ queueConfig: QueueEventConfig | null,
259
+ customerId: string,
260
+ secretKey: string,
261
+ httpContextProvider: IHttpContextProvider,
262
+ dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
263
+ if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
264
+ const debugEntries = new Map<string, string>();
265
+ const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
266
+
267
+ if (connectorDiagnostics.hasError) {
268
+ return new ValidationResult(connectorDiagnostics.validationResult, null);
269
+ }
270
+
271
+ targetUrl = this.generateTargetUrl(targetUrl, httpContextProvider);
272
+ const result = this._resolveQueueRequestByLocalConfig(targetUrl, queueitToken, queueConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
273
+ if (result != null && result.second != null) {
274
+ if (connectorDiagnostics.isEnabled) {
275
+ debugEntries.set("Exception", result.second!.message);
276
+ }
277
+ }
278
+ this.setDebugCookie(debugEntries, httpContextProvider);
279
+ return result;
280
+ }
281
+
282
+ private static handleException(diagnostics: ConnectorDiagnostics,
283
+ debugEntries: Map<string, string>,
284
+ ex: KnownUserException,
285
+ httpContext: IHttpContextProvider): void {
286
+ if (diagnostics.isEnabled) debugEntries.set('Exception', ex.message);
287
+ this.setDebugCookie(debugEntries, httpContext);
288
+ }
289
+
290
+ public static validateRequestByIntegrationConfig(
291
+ currentUrlWithoutQueueITToken: string,
292
+ queueitToken: string,
293
+ integrationsConfigString: string,
294
+ customerId: string,
295
+ secretKey: string,
296
+ httpContextProvider: IHttpContextProvider,
297
+ dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
298
+ if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
299
+
300
+ const debugEntries = new Map<string, string>();
301
+
302
+ const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
303
+ if (connectorDiagnostics.hasError) {
304
+ return new ValidationResult(connectorDiagnostics.validationResult, null);
305
+ }
306
+ if (connectorDiagnostics.isEnabled) {
307
+ debugEntries.set("SdkVersion", UserInQueueService.SDK_VERSION);
308
+ debugEntries.set("PureUrl", currentUrlWithoutQueueITToken);
309
+ debugEntries.set("QueueitToken", queueitToken);
310
+ debugEntries.set("OriginalUrl", httpContextProvider.getHttpRequest().getAbsoluteUri());
311
+
312
+ this.logExtraRequestDetails(debugEntries, httpContextProvider, dateTimeProvider);
313
+ }
314
+
315
+ const customerIntegrationInfo = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
316
+
317
+ if (connectorDiagnostics.isEnabled) {
318
+ debugEntries.set('ConfigVersion', customerIntegrationInfo && customerIntegrationInfo.Version != 0 ? customerIntegrationInfo.Version.toString() : "NULL");
319
+ }
320
+
321
+ if (currentUrlWithoutQueueITToken == '') {
322
+ const ex = new KnownUserException("currentUrlWithoutQueueITToken can not be null or empty.");
323
+ this.handleException(connectorDiagnostics, debugEntries, ex, httpContextProvider);
324
+ return new ValidationResult(null, ex);
325
+ }
326
+ if (customerIntegrationInfo == null || customerIntegrationInfo.Version == 0) {
327
+ const ex = new KnownUserException("integrationsConfigString can not be null or empty.");
328
+ this.handleException(connectorDiagnostics, debugEntries, ex, httpContextProvider);
329
+ return new ValidationResult(null, ex);
330
+ }
331
+
332
+ const configEvaluator = new IntegrationConfigHelpers.IntegrationEvaluator();
333
+
334
+ const configMatchResult = configEvaluator.getMatchedIntegrationConfig(
335
+ customerIntegrationInfo,
336
+ currentUrlWithoutQueueITToken,
337
+ httpContextProvider.getHttpRequest());
338
+
339
+ if (connectorDiagnostics.isEnabled) {
340
+ debugEntries.set('MatchedConfig', configMatchResult != null && configMatchResult.first != null ?
341
+ configMatchResult.first!.Name
342
+ : "NULL");
343
+ }
344
+ if (configMatchResult == null || configMatchResult.second != null) {
345
+ this.setDebugCookie(debugEntries, httpContextProvider);
346
+ return new ValidationResult(new RequestValidationResult("", "", "", "", "", ""), null);
347
+ }
348
+ const matchedConfig = configMatchResult.first!;
349
+ let result: ValidationResult
350
+
351
+ if (matchedConfig.ActionType == ActionTypes.QueueAction) {
352
+ result = this.handleQueueAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
353
+ customerId, secretKey, matchedConfig, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
354
+ } else if (matchedConfig.ActionType == ActionTypes.CancelAction) {
355
+ result = this.handleCancelAction(currentUrlWithoutQueueITToken, queueitToken, customerIntegrationInfo,
356
+ customerId, secretKey, matchedConfig, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
357
+ } else {
358
+ result = this.handleIgnoreAction(httpContextProvider, matchedConfig.Name);
359
+ }
360
+ if (result.second != null && connectorDiagnostics.isEnabled) {
361
+ debugEntries.set('Exception', result.second!.message);
362
+ }
363
+
364
+ this.setDebugCookie(debugEntries, httpContextProvider);
365
+ return result;
366
+ }
367
+
368
+ public static cancelRequestByLocalConfig(
369
+ targetUrl: string,
370
+ queueitToken: string,
371
+ cancelConfig: CancelEventConfig | null,
372
+ customerId: string,
373
+ secretKey: string,
374
+ httpContextProvider: IHttpContextProvider,
375
+ dateTimeProvider: IDateTimeProvider | null = null): ValidationResult {
376
+ if (dateTimeProvider == null) dateTimeProvider = new DateTimeProvider();
377
+ const debugEntries = new Map<string, string>();
378
+ const connectorDiagnostics = ConnectorDiagnostics.verify(customerId, secretKey, queueitToken);
379
+
380
+ if (connectorDiagnostics.hasError)
381
+ return new ValidationResult(connectorDiagnostics.validationResult, null);
382
+
383
+ const result = this._cancelRequestByLocalConfig(
384
+ targetUrl, queueitToken, cancelConfig, customerId, secretKey, httpContextProvider, dateTimeProvider, debugEntries, connectorDiagnostics.isEnabled);
385
+ if (result.second != null && connectorDiagnostics.isEnabled) {
386
+ debugEntries.set('Exception', result.second!.message);
387
+ }
388
+ this.setDebugCookie(debugEntries, httpContextProvider);
389
+
390
+ return result;
391
+ }
392
+ }
393
+