@queue-it/fastly 1.1.0 → 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.
- package/package.json +16 -21
- package/{assembly → src}/contextProvider.ts +6 -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 +24 -28
- 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/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -221
- package/assembly/sdk/helpers/Uri.ts +0 -308
- /package/{assembly → src}/helper.ts +0 -0
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
//@ts-ignore
|
|
2
|
-
import {RegExp} from "assemblyscript-regex";
|
|
3
1
|
import {KeyValuePair, RequestValidationResult} from "./Models";
|
|
4
2
|
import {IDateTimeProvider} from "./HttpContextProvider";
|
|
5
|
-
import {Date as WasiDate} from "as-wasi";
|
|
6
3
|
import {encodeURIComponent, decodeURIComponent} from "./helpers/Uri";
|
|
7
4
|
import {KnownUser} from "./KnownUser";
|
|
8
|
-
import {Response} from "@fastly/as-compute";
|
|
9
5
|
import {UserInQueueService} from "./UserInQueueService";
|
|
10
6
|
|
|
11
7
|
export class QueueUrlParams {
|
|
12
|
-
public timeStamp:
|
|
8
|
+
public timeStamp: number = 0;
|
|
13
9
|
public eventId: string = "";
|
|
14
10
|
public hashCode: string = "";
|
|
15
|
-
public extendableCookie:
|
|
16
|
-
public cookieValidityMinutes:
|
|
11
|
+
public extendableCookie: boolean = false;
|
|
12
|
+
public cookieValidityMinutes: number = 0;
|
|
17
13
|
public queueITToken: string = "";
|
|
18
14
|
public queueITTokenWithoutHash: string = "";
|
|
19
15
|
public queueId: string = "";
|
|
@@ -42,7 +38,7 @@ export class Utils {
|
|
|
42
38
|
|
|
43
39
|
static generateSHA256Hash: (a: string, b: string) => string = (secretKey: string, stringToHash: string): string => "";
|
|
44
40
|
|
|
45
|
-
static endsWith(str: string, search: string):
|
|
41
|
+
static endsWith(str: string, search: string): boolean {
|
|
46
42
|
if (str == search)
|
|
47
43
|
return true;
|
|
48
44
|
if (str.length == 0 || search.length == 0)
|
|
@@ -50,11 +46,11 @@ export class Utils {
|
|
|
50
46
|
return str.substring(str.length - search.length, str.length) == search;
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
static getCurrentTime():
|
|
54
|
-
return Math.floor(
|
|
49
|
+
static getCurrentTime(): number {
|
|
50
|
+
return Math.floor(Date.now() / 1000);
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
private static _hex2bin:
|
|
53
|
+
private static _hex2bin: number[] = [
|
|
58
54
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
59
55
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
60
56
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
@@ -78,8 +74,8 @@ export class Utils {
|
|
|
78
74
|
let rv = '';
|
|
79
75
|
let i = 0;
|
|
80
76
|
|
|
81
|
-
let c1:
|
|
82
|
-
let c2:
|
|
77
|
+
let c1: number;
|
|
78
|
+
let c2: number;
|
|
83
79
|
|
|
84
80
|
while (len > 1) {
|
|
85
81
|
let h1 = str.charAt(i++);
|
|
@@ -101,29 +97,29 @@ export class Utils {
|
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
static getParameterByName(url: string, name: string): string {
|
|
104
|
-
const namePart =
|
|
100
|
+
const namePart = /[\[\]]/g;
|
|
105
101
|
let match = namePart.exec(name);
|
|
106
|
-
while (match
|
|
107
|
-
let rxmatch = match
|
|
102
|
+
while (match !== null) {
|
|
103
|
+
let rxmatch = match[0];
|
|
108
104
|
name = name.replaceAll(rxmatch, '\\$&')
|
|
109
105
|
match = namePart.exec(name);
|
|
110
106
|
}
|
|
111
107
|
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
|
112
108
|
const results = regex.exec(url);
|
|
113
|
-
if (results
|
|
114
|
-
if (results.
|
|
109
|
+
if (results === null) return '';
|
|
110
|
+
if (results.length < 3) {
|
|
115
111
|
return '';
|
|
116
112
|
}
|
|
117
113
|
|
|
118
|
-
return decodeURIComponent(results
|
|
114
|
+
return decodeURIComponent(results[2].replaceAll('+', ' '));
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
static removeQueueItToken(url: string): string {
|
|
122
|
-
const pattern = new RegExp("([
|
|
118
|
+
const pattern = new RegExp("([?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'gi');
|
|
123
119
|
const match = pattern.exec(url);
|
|
124
|
-
if (match
|
|
120
|
+
if (match === null) return url;
|
|
125
121
|
|
|
126
|
-
url = url.replaceAll(match
|
|
122
|
+
url = url.replaceAll(match[0], '')
|
|
127
123
|
return url;
|
|
128
124
|
}
|
|
129
125
|
}
|
|
@@ -159,9 +155,9 @@ export class QueueParameterHelper {
|
|
|
159
155
|
if (keyValueArr[0] == QueueParameterHelper.HashKey) {
|
|
160
156
|
result.hashCode = keyValueArr[1];
|
|
161
157
|
} else if (keyValueArr[0] == QueueParameterHelper.TimeStampKey) {
|
|
162
|
-
result.timeStamp =
|
|
158
|
+
result.timeStamp = parseInt(keyValueArr[1], 10) || 0;
|
|
163
159
|
} else if (keyValueArr[0] == QueueParameterHelper.CookieValidityMinutesKey) {
|
|
164
|
-
result.cookieValidityMinutes =
|
|
160
|
+
result.cookieValidityMinutes = parseInt(keyValueArr[1], 10) || 0;
|
|
165
161
|
} else if (keyValueArr[0] == QueueParameterHelper.EventIdKey) {
|
|
166
162
|
result.eventId = keyValueArr[1];
|
|
167
163
|
} else if (keyValueArr[0] == QueueParameterHelper.ExtendableCookieKey) {
|
|
@@ -211,9 +207,9 @@ export class CookieHelper {
|
|
|
211
207
|
}
|
|
212
208
|
|
|
213
209
|
export class ConnectorDiagnostics {
|
|
214
|
-
public isEnabled:
|
|
215
|
-
public hasError:
|
|
216
|
-
public validationResult: RequestValidationResult | null
|
|
210
|
+
public isEnabled: boolean = false;
|
|
211
|
+
public hasError: boolean = false;
|
|
212
|
+
public validationResult: RequestValidationResult | null = null
|
|
217
213
|
|
|
218
214
|
private setStateWithTokenError(customerId: string, errorCode: string): void {
|
|
219
215
|
this.hasError = true;
|
|
@@ -258,6 +254,6 @@ export class ConnectorDiagnostics {
|
|
|
258
254
|
|
|
259
255
|
export class DateTimeProvider implements IDateTimeProvider {
|
|
260
256
|
getCurrentTime(): Date {
|
|
261
|
-
return new Date(
|
|
257
|
+
return new Date(Date.now());
|
|
262
258
|
}
|
|
263
259
|
}
|
|
@@ -81,7 +81,7 @@ export class UserInQueueService {
|
|
|
81
81
|
private getQueryString(
|
|
82
82
|
customerId: string,
|
|
83
83
|
eventId: string,
|
|
84
|
-
configVersion:
|
|
84
|
+
configVersion: number,
|
|
85
85
|
culture: string,
|
|
86
86
|
layoutName: string,
|
|
87
87
|
actionName: string)
|
|
@@ -143,7 +143,7 @@ export class UserInQueueService {
|
|
|
143
143
|
const queueParams = QueueParameterHelper.extractQueueParams(queueitToken);
|
|
144
144
|
|
|
145
145
|
let requestValidationResult: RequestValidationResult | null;
|
|
146
|
-
let isTokenValid:
|
|
146
|
+
let isTokenValid: boolean = false;
|
|
147
147
|
|
|
148
148
|
if (queueParams != null) {
|
|
149
149
|
const tokenValidationResult = this.validateToken(config, queueParams, secretKey);
|
|
@@ -201,7 +201,7 @@ export class UserInQueueService {
|
|
|
201
201
|
|
|
202
202
|
public extendQueueCookie(
|
|
203
203
|
eventId: string,
|
|
204
|
-
cookieValidityMinutes:
|
|
204
|
+
cookieValidityMinutes: number,
|
|
205
205
|
cookieDomain: string,
|
|
206
206
|
secretKey: string): void {
|
|
207
207
|
this.userInQueueStateRepository.reissueQueueCookie(eventId, cookieValidityMinutes, cookieDomain, secretKey)
|
|
@@ -237,7 +237,7 @@ export class UserInQueueService {
|
|
|
237
237
|
|
|
238
238
|
class TokenValidationResult {
|
|
239
239
|
constructor(
|
|
240
|
-
public isValid:
|
|
240
|
+
public isValid: boolean,
|
|
241
241
|
public errorCode: string) {
|
|
242
242
|
|
|
243
243
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {IHttpContextProvider} from './HttpContextProvider'
|
|
2
2
|
import {Utils, CookieHelper} from './QueueITHelpers'
|
|
3
|
-
import {Date as WasiDate} from "as-wasi";
|
|
4
3
|
import {KeyValuePair} from "./Models";
|
|
5
4
|
|
|
6
5
|
export class UserInQueueStateCookieRepository {
|
|
@@ -19,7 +18,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
19
18
|
return UserInQueueStateCookieRepository._QueueITDataKey + "_" + eventId;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
public store(eventId: string, queueId: string, fixedCookieValidityMinutes:
|
|
21
|
+
public store(eventId: string, queueId: string, fixedCookieValidityMinutes: number,
|
|
23
22
|
cookieDomain: string, redirectType: string, secretKey: string): void {
|
|
24
23
|
this.createCookie(
|
|
25
24
|
eventId, queueId,
|
|
@@ -52,8 +51,8 @@ export class UserInQueueStateCookieRepository {
|
|
|
52
51
|
UserInQueueStateCookieRepository._HashKey,
|
|
53
52
|
this.generateHash(eventId.toLowerCase(), queueId, fixedCookieValidityMinutes, redirectType.toLowerCase(), issueTime, secretKey)
|
|
54
53
|
));
|
|
55
|
-
const tomorrow: Date = new Date(
|
|
56
|
-
const expire:
|
|
54
|
+
const tomorrow: Date = new Date(Date.now() + 1000 * 60 * 60 * 24);
|
|
55
|
+
const expire: number = Math.floor(tomorrow.getTime() / 1000);
|
|
57
56
|
let cookieValue = CookieHelper.toValueFromKeyValueCollection(cookieValues);
|
|
58
57
|
|
|
59
58
|
this.httpContextProvider.getHttpResponse().setCookie(cookieKey,
|
|
@@ -61,7 +60,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
61
60
|
cookieDomain, expire);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
public getState(eventId: string, cookieValidityMinutes:
|
|
63
|
+
public getState(eventId: string, cookieValidityMinutes: number, secretKey: string, validateTime: boolean): StateInfo {
|
|
65
64
|
const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
|
|
66
65
|
const cookie = this.httpContextProvider.getHttpRequest().getCookieValue(cookieKey);
|
|
67
66
|
|
|
@@ -74,37 +73,37 @@ export class UserInQueueStateCookieRepository {
|
|
|
74
73
|
return new StateInfo(true, false, "", 0, "");
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
const fixedCookieValidity:
|
|
78
|
-
?
|
|
76
|
+
const fixedCookieValidity: number = cookieValues.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)
|
|
77
|
+
? parseInt(cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)!, 10)
|
|
79
78
|
: 0;
|
|
80
79
|
|
|
81
80
|
return new StateInfo(
|
|
82
81
|
true,
|
|
83
82
|
true,
|
|
84
|
-
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)
|
|
83
|
+
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)!,
|
|
85
84
|
fixedCookieValidity,
|
|
86
|
-
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey));
|
|
85
|
+
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)!);
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
private isCookieValid(
|
|
90
89
|
secretKey: string,
|
|
91
90
|
cookieValueMap: Map<string, string>,
|
|
92
91
|
eventId: string,
|
|
93
|
-
cookieValidityMinutes:
|
|
94
|
-
validateTime:
|
|
92
|
+
cookieValidityMinutes: number,
|
|
93
|
+
validateTime: boolean): boolean {
|
|
95
94
|
|
|
96
95
|
const storedHash = cookieValueMap.has(UserInQueueStateCookieRepository._HashKey) ?
|
|
97
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._HashKey) : "";
|
|
96
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._HashKey)! : "";
|
|
98
97
|
const issueTimeString = cookieValueMap.has(UserInQueueStateCookieRepository._IssueTimeKey) ?
|
|
99
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._IssueTimeKey) : "";
|
|
98
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._IssueTimeKey)! : "";
|
|
100
99
|
const queueId = cookieValueMap.has(UserInQueueStateCookieRepository._QueueIdKey) ?
|
|
101
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._QueueIdKey) : "";
|
|
100
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._QueueIdKey)! : "";
|
|
102
101
|
const eventIdFromCookie = cookieValueMap.has(UserInQueueStateCookieRepository._EventIdKey) ?
|
|
103
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._EventIdKey) : "";
|
|
102
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._EventIdKey)! : "";
|
|
104
103
|
const redirectType = cookieValueMap.has(UserInQueueStateCookieRepository._RedirectTypeKey) ?
|
|
105
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._RedirectTypeKey) : "";
|
|
104
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._RedirectTypeKey)! : "";
|
|
106
105
|
let fixedCookieValidityMinutes = cookieValueMap.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey) ?
|
|
107
|
-
cookieValueMap.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey) : "";
|
|
106
|
+
cookieValueMap.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)! : "";
|
|
108
107
|
|
|
109
108
|
const expectedHash = this.generateHash(
|
|
110
109
|
eventIdFromCookie,
|
|
@@ -124,8 +123,8 @@ export class UserInQueueStateCookieRepository {
|
|
|
124
123
|
return false;
|
|
125
124
|
|
|
126
125
|
if (validateTime) {
|
|
127
|
-
let validity:
|
|
128
|
-
let expirationTime:
|
|
126
|
+
let validity: number = fixedCookieValidityMinutes.length > 0 ? parseInt(fixedCookieValidityMinutes, 10) : cookieValidityMinutes;
|
|
127
|
+
let expirationTime: number = parseInt(issueTimeString, 10) + validity * 60;
|
|
129
128
|
|
|
130
129
|
if (expirationTime < Utils.getCurrentTime())
|
|
131
130
|
return false;
|
|
@@ -138,7 +137,7 @@ export class UserInQueueStateCookieRepository {
|
|
|
138
137
|
this.httpContextProvider.getHttpResponse().setCookie(cookieKey, "", cookieDomain, 0);
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
public reissueQueueCookie(eventId: string, cookieValidityMinutes:
|
|
140
|
+
public reissueQueueCookie(eventId: string, cookieValidityMinutes: number, cookieDomain: string, secretKey: string): void {
|
|
142
141
|
const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
|
|
143
142
|
const cookie = this.httpContextProvider.getHttpRequest().getCookieValue(cookieKey);
|
|
144
143
|
|
|
@@ -152,14 +151,14 @@ export class UserInQueueStateCookieRepository {
|
|
|
152
151
|
|
|
153
152
|
let fixedCookieValidityMinutes = "";
|
|
154
153
|
if (cookieValues.has(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)) {
|
|
155
|
-
fixedCookieValidityMinutes = cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)
|
|
154
|
+
fixedCookieValidityMinutes = cookieValues.get(UserInQueueStateCookieRepository._FixedCookieValidityMinutesKey)!.toString();
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
this.createCookie(
|
|
159
158
|
eventId,
|
|
160
|
-
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)
|
|
159
|
+
cookieValues.get(UserInQueueStateCookieRepository._QueueIdKey)!,
|
|
161
160
|
fixedCookieValidityMinutes,
|
|
162
|
-
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)
|
|
161
|
+
cookieValues.get(UserInQueueStateCookieRepository._RedirectTypeKey)!,
|
|
163
162
|
cookieDomain, secretKey);
|
|
164
163
|
}
|
|
165
164
|
|
|
@@ -176,14 +175,14 @@ export class UserInQueueStateCookieRepository {
|
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
export class StateInfo {
|
|
179
|
-
constructor(public isFound:
|
|
180
|
-
public isValid:
|
|
178
|
+
constructor(public isFound: boolean,
|
|
179
|
+
public isValid: boolean,
|
|
181
180
|
public queueId: string,
|
|
182
|
-
public fixedCookieValidityMinutes:
|
|
181
|
+
public fixedCookieValidityMinutes: number,
|
|
183
182
|
public redirectType: string) {
|
|
184
183
|
}
|
|
185
184
|
|
|
186
|
-
isStateExtendable():
|
|
185
|
+
isStateExtendable(): boolean {
|
|
187
186
|
return this.isValid && !this.fixedCookieValidityMinutes;
|
|
188
187
|
}
|
|
189
188
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Hash implements SHA256 hash algorithm.
|
|
2
2
|
export class Hash {
|
|
3
|
-
blockSize:
|
|
4
|
-
digestLength:
|
|
3
|
+
blockSize: number;
|
|
4
|
+
digestLength: number;
|
|
5
5
|
private readonly state: Int32Array;
|
|
6
6
|
private readonly temp: Int32Array;
|
|
7
7
|
private readonly buffer: Uint8Array;
|
|
8
|
-
private bufferLength:
|
|
9
|
-
private bytesHashed:
|
|
10
|
-
finished:
|
|
8
|
+
private bufferLength: number;
|
|
9
|
+
private bytesHashed: number;
|
|
10
|
+
finished: boolean = false
|
|
11
11
|
|
|
12
12
|
// SHA-256 constants
|
|
13
|
-
static K:
|
|
13
|
+
static K: number[] = [
|
|
14
14
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
|
15
15
|
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
|
16
16
|
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
|
@@ -73,7 +73,7 @@ export class Hash {
|
|
|
73
73
|
|
|
74
74
|
// Throws error when trying to update already finalized hash:
|
|
75
75
|
// instance must be reset to use it again.
|
|
76
|
-
update(data: Uint8Array, dataLength:
|
|
76
|
+
update(data: Uint8Array, dataLength: number = 0): Hash {
|
|
77
77
|
if (dataLength == 0) {
|
|
78
78
|
dataLength = data.length;
|
|
79
79
|
}
|
|
@@ -81,7 +81,7 @@ export class Hash {
|
|
|
81
81
|
throw new Error("SHA256: can't update because hash was finished.");
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
let dataPos:
|
|
84
|
+
let dataPos: number = 0;
|
|
85
85
|
this.bytesHashed += dataLength;
|
|
86
86
|
if (this.bufferLength > 0) {
|
|
87
87
|
while (this.bufferLength < 64 && dataLength > 0) {
|
|
@@ -109,11 +109,11 @@ export class Hash {
|
|
|
109
109
|
// If hash was already finalized, puts the same value.
|
|
110
110
|
finish(out: Uint8Array): Hash {
|
|
111
111
|
if (!this.finished) {
|
|
112
|
-
let bytesHashed:
|
|
113
|
-
let left:
|
|
114
|
-
let bitLenHi:
|
|
115
|
-
let bitLenLo:
|
|
116
|
-
let padLength:
|
|
112
|
+
let bytesHashed: number = this.bytesHashed;
|
|
113
|
+
let left: number = this.bufferLength;
|
|
114
|
+
let bitLenHi: number = (bytesHashed / 0x20000000) | 0;
|
|
115
|
+
let bitLenLo: number = bytesHashed << 3;
|
|
116
|
+
let padLength: number = (bytesHashed % 64 < 56) ? 64 : 128;
|
|
117
117
|
this.buffer[left] = 0x80;
|
|
118
118
|
for (let i = left + 1; i < padLength - 8; i++) {
|
|
119
119
|
this.buffer[i] = 0;
|
|
@@ -154,7 +154,7 @@ export class Hash {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// Internal function for use in HMAC for optimization.
|
|
157
|
-
_restoreState(from: Uint32Array, bytesHashed:
|
|
157
|
+
_restoreState(from: Uint32Array, bytesHashed: number): void {
|
|
158
158
|
for (let i = 0; i < this.state.length; i++) {
|
|
159
159
|
this.state[i] = from[i];
|
|
160
160
|
}
|
|
@@ -163,8 +163,8 @@ export class Hash {
|
|
|
163
163
|
this.bufferLength = 0;
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
static hashBlocks(w: Int32Array, v: Int32Array, p: Uint8Array, pos:
|
|
167
|
-
let a:
|
|
166
|
+
static hashBlocks(w: Int32Array, v: Int32Array, p: Uint8Array, pos: number, len: number): number {
|
|
167
|
+
let a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, u: number, i: number, j: number, t1: number, t2: number;
|
|
168
168
|
while (len >= 64) {
|
|
169
169
|
a = v[0];
|
|
170
170
|
b = v[1];
|
|
@@ -176,10 +176,10 @@ export class Hash {
|
|
|
176
176
|
h = v[7];
|
|
177
177
|
for (i = 0; i < 16; i++) {
|
|
178
178
|
j = pos + i * 4;
|
|
179
|
-
let p1 = ((
|
|
180
|
-
let p2 = ((
|
|
181
|
-
let p3 = ((
|
|
182
|
-
let p4 = (
|
|
179
|
+
let p1 = ((p[j] & 0xff) << 24);
|
|
180
|
+
let p2 = ((p[j + 1] & 0xff) << 16);
|
|
181
|
+
let p3 = ((p[j + 2] & 0xff) << 8);
|
|
182
|
+
let p4 = (p[j + 3] & 0xff);
|
|
183
183
|
w[i] = p1 | p2 | p3 | p4;
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -193,7 +193,7 @@ export class Hash {
|
|
|
193
193
|
for (i = 0; i < 64; i++) {
|
|
194
194
|
t1 = (((((e >>> 6 | e << (32 - 6)) ^ (e >>> 11 | e << (32 - 11)) ^
|
|
195
195
|
(e >>> 25 | e << (32 - 25))) + ((e & f) ^ (~e & g))) | 0) +
|
|
196
|
-
((h + ((
|
|
196
|
+
((h + ((Hash.K[i] + w[i]) | 0)) | 0)) | 0;
|
|
197
197
|
t2 = (((a >>> 2 | a << (32 - 2)) ^ (a >>> 13 | a << (32 - 13)) ^
|
|
198
198
|
(a >>> 22 | a << (32 - 22))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
199
199
|
h = g;
|
|
@@ -224,8 +224,8 @@ export class Hash {
|
|
|
224
224
|
export class HMAC {
|
|
225
225
|
private inner: Hash
|
|
226
226
|
private outer: Hash
|
|
227
|
-
blockSize:
|
|
228
|
-
digestLength:
|
|
227
|
+
blockSize: number
|
|
228
|
+
digestLength: number
|
|
229
229
|
private readonly istate: Uint32Array
|
|
230
230
|
private readonly ostate: Uint32Array
|
|
231
231
|
|
|
@@ -311,7 +311,7 @@ export function hash(data: Uint8Array): Uint8Array {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
export function hashString(data: string): string {
|
|
314
|
-
return toHex(hash(
|
|
314
|
+
return toHex(hash(new TextEncoder().encode(data)));
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// Returns HMAC-SHA256 of data under the key.
|
|
@@ -324,17 +324,15 @@ export function hmac(key: Uint8Array, data: Uint8Array): Uint8Array {
|
|
|
324
324
|
|
|
325
325
|
export function toHex(byteArray: Uint8Array): string {
|
|
326
326
|
let acc = '';
|
|
327
|
-
for(let i=0; i<byteArray.length; i++){
|
|
327
|
+
for (let i = 0; i < byteArray.length; i++) {
|
|
328
328
|
let val = byteArray[i];
|
|
329
329
|
acc += ('0' + val.toString(16)).slice(-2);
|
|
330
330
|
}
|
|
331
331
|
return acc;
|
|
332
|
-
//return byteArray.reduce((acc, val) => (acc + ('0' + val.toString(16)).slice(-2)), '');
|
|
333
332
|
}
|
|
334
333
|
|
|
335
334
|
export function hmacString(key: string, data: string): string {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return toHex(hash)
|
|
335
|
+
const encoder = new TextEncoder();
|
|
336
|
+
const result = hmac(encoder.encode(key), encoder.encode(data));
|
|
337
|
+
return toHex(result);
|
|
340
338
|
}
|
|
@@ -1,221 +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
|
-
const ARRAY_NAME_INTEGRATIONS = "Integrations";
|
|
11
|
-
const ARRAY_NAME_TRIGGERS = "Triggers";
|
|
12
|
-
const ARRAY_NAME_TRIGGER_PARTS = "TriggerParts";
|
|
13
|
-
const ARRAY_NAME_VALUES_TO_COMPARE = "ValuesToCompare";
|
|
14
|
-
|
|
15
|
-
export class CustomerIntegrationDecodingHandler extends JSONHandler {
|
|
16
|
-
private readonly _deserializedValue: CustomerIntegration;
|
|
17
|
-
private isInIntegrations: bool = false;
|
|
18
|
-
private isInTriggers: bool = false;
|
|
19
|
-
private isInConfigModel: bool = false;
|
|
20
|
-
private isInTriggerModel: bool = false;
|
|
21
|
-
private isInTriggerPart: bool = false;
|
|
22
|
-
private currentIntegrationConfigModel: IntegrationConfigModel | null;
|
|
23
|
-
private currentTriggerModel: TriggerModel | null;
|
|
24
|
-
private currentTriggerPart: TriggerPart | null;
|
|
25
|
-
private isInTriggerParts: bool = false;
|
|
26
|
-
private isInTriggerPartValuesToCompare: bool = false;
|
|
27
|
-
private arrayStack: string[] = [];
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
super();
|
|
31
|
-
this._deserializedValue = new CustomerIntegration();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pushArray(name: string): bool {
|
|
35
|
-
// Handle array start
|
|
36
|
-
// true means that nested object needs to be traversed, false otherwise
|
|
37
|
-
// Note that returning false means JSONDecoder.startIndex need to be updated by handler
|
|
38
|
-
|
|
39
|
-
// Push array name to stack BEFORE checking if we recognize it
|
|
40
|
-
// This ensures every pushArray has a matching popArray
|
|
41
|
-
this.arrayStack.push(name);
|
|
42
|
-
|
|
43
|
-
if (name == ARRAY_NAME_INTEGRATIONS) {
|
|
44
|
-
this.isInIntegrations = true;
|
|
45
|
-
} else if (name == ARRAY_NAME_TRIGGERS) {
|
|
46
|
-
this.isInTriggers = true;
|
|
47
|
-
} else if (name == ARRAY_NAME_TRIGGER_PARTS) {
|
|
48
|
-
this.isInTriggerParts = true;
|
|
49
|
-
} else if (name == ARRAY_NAME_VALUES_TO_COMPARE) {
|
|
50
|
-
this.isInTriggerPartValuesToCompare = true;
|
|
51
|
-
}
|
|
52
|
-
return this.isInIntegrations
|
|
53
|
-
|| this.isInTriggers
|
|
54
|
-
|| this.isInTriggerParts
|
|
55
|
-
|| this.isInTriggerPartValuesToCompare;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
popArray(): void {
|
|
60
|
-
// Pop array name from stack
|
|
61
|
-
if (this.arrayStack.length == 0) {
|
|
62
|
-
return; // Defensive: should never happen
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const arrayName = this.arrayStack.pop();
|
|
66
|
-
|
|
67
|
-
// Only clear flags for recognized arrays
|
|
68
|
-
if (arrayName == ARRAY_NAME_VALUES_TO_COMPARE) {
|
|
69
|
-
this.isInTriggerPartValuesToCompare = false;
|
|
70
|
-
} else if (arrayName == ARRAY_NAME_TRIGGER_PARTS) {
|
|
71
|
-
this.isInTriggerParts = false;
|
|
72
|
-
} else if (arrayName == ARRAY_NAME_TRIGGERS) {
|
|
73
|
-
this.isInTriggers = false;
|
|
74
|
-
} else if (arrayName == ARRAY_NAME_INTEGRATIONS) {
|
|
75
|
-
this.isInIntegrations = false;
|
|
76
|
-
}
|
|
77
|
-
// Note: Unrecognized arrays (like InvolvedWaitingRoomIds) are popped but don't affect flags
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
pushObject(name: string): bool {
|
|
81
|
-
if (this.isInTriggerParts) {
|
|
82
|
-
this.isInTriggerPart = true;
|
|
83
|
-
this.currentTriggerPart = new TriggerPart();
|
|
84
|
-
} else if (this.isInTriggers) {
|
|
85
|
-
this.isInTriggerModel = true;
|
|
86
|
-
this.currentTriggerModel = new TriggerModel();
|
|
87
|
-
} else if (this.isInIntegrations) {
|
|
88
|
-
this.isInConfigModel = true;
|
|
89
|
-
this.currentIntegrationConfigModel = new IntegrationConfigModel();
|
|
90
|
-
}
|
|
91
|
-
return super.pushObject(name);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
popObject(): void {
|
|
95
|
-
if (this.isInTriggerPart) {
|
|
96
|
-
this.currentTriggerModel!.TriggerParts.push(this.currentTriggerPart!);
|
|
97
|
-
this.isInTriggerPart = false;
|
|
98
|
-
} else if (this.isInTriggerModel) {
|
|
99
|
-
// Defensive: only add trigger if we have a valid integration
|
|
100
|
-
if (this.currentIntegrationConfigModel != null) {
|
|
101
|
-
this.currentIntegrationConfigModel!.Triggers.push(this.currentTriggerModel!);
|
|
102
|
-
}
|
|
103
|
-
this.isInTriggerModel = false;
|
|
104
|
-
} else if (this.isInConfigModel) {
|
|
105
|
-
this._deserializedValue.Integrations.push(this.currentIntegrationConfigModel!);
|
|
106
|
-
this.isInConfigModel = false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setInteger(name: string, value: i64): void {
|
|
111
|
-
if (this.isInConfigModel) {
|
|
112
|
-
this.setConfigModelInteger(name, value);
|
|
113
|
-
} else if (name == "Version") {
|
|
114
|
-
this._deserializedValue.Version = value;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
setBoolean(name: string, value: bool): void {
|
|
119
|
-
if (this.isInTriggerPart) {
|
|
120
|
-
this.setTriggerPartBoolean(name, value);
|
|
121
|
-
} else if (this.isInConfigModel) {
|
|
122
|
-
this.setConfigModelBoolean(name, value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
setString(name: string, value: string): void {
|
|
127
|
-
if (this.isInTriggerPartValuesToCompare) {
|
|
128
|
-
this.addTriggerPartValuesToCompare(value);
|
|
129
|
-
} else if (this.isInTriggerPart) {
|
|
130
|
-
this.setTriggerPartString(name, value);
|
|
131
|
-
} else if (this.isInTriggerModel) {
|
|
132
|
-
this.setTriggerModelString(name, value);
|
|
133
|
-
} else if (this.isInConfigModel) {
|
|
134
|
-
this.setConfigModelString(name, value);
|
|
135
|
-
} else if (name == "Description") {
|
|
136
|
-
this._deserializedValue.Description = value;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
setConfigModelBoolean(name: string, value: bool): void {
|
|
141
|
-
if (name == "ExtendCookieValidity") {
|
|
142
|
-
this.currentIntegrationConfigModel!.ExtendCookieValidity = value;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
setTriggerPartBoolean(name: string, value: bool): void {
|
|
147
|
-
if (name == "IsNegative") {
|
|
148
|
-
this.currentTriggerPart!.IsNegative = value;
|
|
149
|
-
} else if (name == "IsIgnoreCase") {
|
|
150
|
-
this.currentTriggerPart!.IsIgnoreCase = value;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
setConfigModelInteger(name: string, value: i64): void {
|
|
155
|
-
if (name == "CookieValidityMinute") {
|
|
156
|
-
this.currentIntegrationConfigModel!.CookieValidityMinute = value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
addTriggerPartValuesToCompare(value: string): void {
|
|
161
|
-
this.currentTriggerPart!.ValuesToCompare.push(value);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
setTriggerPartString(name: string, value: string): void {
|
|
165
|
-
if (name == "ValidatorType") {
|
|
166
|
-
this.currentTriggerPart!.ValidatorType = value;
|
|
167
|
-
} else if (name == "Operator") {
|
|
168
|
-
this.currentTriggerPart!.Operator = value;
|
|
169
|
-
} else if (name == "ValueToCompare") {
|
|
170
|
-
this.currentTriggerPart!.ValueToCompare = value;
|
|
171
|
-
} else if (name == "UrlPart") {
|
|
172
|
-
this.currentTriggerPart!.UrlPart = value;
|
|
173
|
-
} else if (name == "CookieName") {
|
|
174
|
-
this.currentTriggerPart!.CookieName = value;
|
|
175
|
-
} else if (name == "HttpHeaderName") {
|
|
176
|
-
this.currentTriggerPart!.HttpHeaderName = value;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setTriggerModelString(name: string, value: string): void {
|
|
181
|
-
if (name == "LogicalOperator") {
|
|
182
|
-
this.currentTriggerModel!.LogicalOperator = value;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
setConfigModelString(name: string, value: string): void {
|
|
187
|
-
if (name == "Name") {
|
|
188
|
-
this.currentIntegrationConfigModel!.Name = value;
|
|
189
|
-
} else if (name == "EventId") {
|
|
190
|
-
this.currentIntegrationConfigModel!.EventId = value;
|
|
191
|
-
} else if (name == "CookieDomain") {
|
|
192
|
-
this.currentIntegrationConfigModel!.CookieDomain = value;
|
|
193
|
-
} else if (name == "LayoutName") {
|
|
194
|
-
this.currentIntegrationConfigModel!.LayoutName = value;
|
|
195
|
-
} else if (name == "Culture") {
|
|
196
|
-
this.currentIntegrationConfigModel!.Culture = value;
|
|
197
|
-
} else if (name == "QueueDomain") {
|
|
198
|
-
this.currentIntegrationConfigModel!.QueueDomain = value;
|
|
199
|
-
} else if (name == "RedirectLogic") {
|
|
200
|
-
this.currentIntegrationConfigModel!.RedirectLogic = value;
|
|
201
|
-
} else if (name == "ForcedTargetUrl") {
|
|
202
|
-
this.currentIntegrationConfigModel!.ForcedTargetUrl = value;
|
|
203
|
-
} else if (name == "ActionType") {
|
|
204
|
-
this.currentIntegrationConfigModel!.ActionType = value;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
value(): CustomerIntegration {
|
|
209
|
-
return this._deserializedValue;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
static deserialize(integrationsConfigString: string): CustomerIntegration {
|
|
213
|
-
const handler = new CustomerIntegrationDecodingHandler();
|
|
214
|
-
if (integrationsConfigString == '') {
|
|
215
|
-
return handler.value();
|
|
216
|
-
}
|
|
217
|
-
const decoder = new JSONDecoder<CustomerIntegrationDecodingHandler>(handler);
|
|
218
|
-
decoder.deserialize(Uint8Array.wrap(String.UTF8.encode(integrationsConfigString)));
|
|
219
|
-
return handler.value();
|
|
220
|
-
}
|
|
221
|
-
}
|