@queue-it/fastly 3.6.0 → 4.4.3-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.
Files changed (39) hide show
  1. package/README.md +156 -58
  2. package/package.json +23 -16
  3. package/src/contextProvider.ts +175 -0
  4. package/src/fastlyCryptoProvider.ts +8 -0
  5. package/src/helper.ts +11 -0
  6. package/{assembly/sdk → src}/helpers/crypto.ts +338 -340
  7. package/src/index.ts +3 -0
  8. package/src/integrationConfigProvider.ts +199 -0
  9. package/src/requestResponseHandler.ts +200 -0
  10. package/README-INTERNAL.md +0 -21
  11. package/asconfig.json +0 -17
  12. package/assembly/__tests__/CustomerIntegrationDecodingHandler.spec.ts +0 -1086
  13. package/assembly/__tests__/IntegrationConfigHelpersTest.spec.ts +0 -574
  14. package/assembly/__tests__/KnownUserTest.spec.ts +0 -1894
  15. package/assembly/__tests__/Mocks.ts +0 -321
  16. package/assembly/__tests__/QueueParameterHelper.spec.ts +0 -59
  17. package/assembly/__tests__/UserInQueueService.spec.ts +0 -418
  18. package/assembly/__tests__/UserInQueueStateCookieRepository.spec.ts +0 -337
  19. package/assembly/__tests__/as-pect.config.js +0 -57
  20. package/assembly/__tests__/as-pect.d.ts +0 -1
  21. package/assembly/contextProvider.ts +0 -123
  22. package/assembly/helper.ts +0 -23
  23. package/assembly/index.ts +0 -10
  24. package/assembly/integrationConfigProvider.ts +0 -32
  25. package/assembly/requestResponseHandler.ts +0 -92
  26. package/assembly/sdk/HttpContextProvider.ts +0 -24
  27. package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -198
  28. package/assembly/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +0 -232
  29. package/assembly/sdk/IntegrationConfig/IntegrationConfigModel.ts +0 -93
  30. package/assembly/sdk/KnownUser.ts +0 -396
  31. package/assembly/sdk/Models.ts +0 -105
  32. package/assembly/sdk/QueueITHelpers.ts +0 -263
  33. package/assembly/sdk/UserInQueueService.ts +0 -245
  34. package/assembly/sdk/UserInQueueStateCookieRepository.ts +0 -189
  35. package/assembly/sdk/helpers/Date.ts +0 -194
  36. package/assembly/sdk/helpers/Uri.ts +0 -308
  37. package/assembly/tsconfig.json +0 -6
  38. package/index.js +0 -5
  39. package/pipelines/ci.yaml +0 -28
@@ -1,337 +0,0 @@
1
- import {Utils} from "../sdk/QueueITHelpers";
2
- import {hmacString} from "../sdk/helpers/crypto";
3
- import {
4
- MockHttpContextProvider,
5
- MockHttpRequest,
6
- MockHttpResponse
7
- } from "./Mocks";
8
- import {UserInQueueStateCookieRepository} from "../sdk/UserInQueueStateCookieRepository";
9
-
10
- Utils.generateSHA256Hash = hmacString;
11
-
12
-
13
- function generateHash(eventId: string, queueId: string, fixedCookieValidityMinutes: string, redirectType: string, issueTime: string, secretKey: string): string {
14
- return Utils.generateSHA256Hash(secretKey, eventId + queueId + fixedCookieValidityMinutes + redirectType + issueTime);
15
- }
16
-
17
- const httpContextProvider = new MockHttpContextProvider(new MockHttpRequest(), new MockHttpResponse());
18
- const userInQueueStateCookieRepository = new UserInQueueStateCookieRepository(httpContextProvider);
19
-
20
- function resetMocks(): void {
21
- httpContextProvider.reset();
22
- }
23
-
24
- describe('userInQueueStateCookieRepository', () => {
25
- it('should store_hasValidState_ExtendableCookie_CookieIsSaved', () => {
26
- resetMocks();
27
- const eventId = "event1";
28
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
29
- const cookieDomain = ".test.com";
30
- const queueId = "queueId";
31
- const cookieValidity = 10;
32
-
33
- userInQueueStateCookieRepository.store(eventId, queueId, 0, cookieDomain, "queue", secretKey);
34
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
35
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
36
-
37
- expect(state.isValid).toBeTruthy('should be valid');
38
- expect(state.queueId).toBe(queueId, 'should have expected queue id');
39
- expect(state.isStateExtendable()).toBeTruthy('should be extendable');
40
- expect(state.redirectType).toBe('queue', 'should redirect to queue');
41
-
42
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
43
-
44
- let cookie = httpContextProvider.res.cookies.get(cookieKey);
45
- let timeDiff = cookie.expiration - Utils.getCurrentTime() - (24 * 60 * 60);
46
- expect(cookie).not.toBeNull('eventId cookie should be present');
47
- expect(timeDiff < 1000).toBeTruthy();
48
- expect(cookie.domain).toBe(cookieDomain);
49
- });
50
-
51
- it('should store_hasValidState_nonExtendableCookie_CookieIsSaved', () => {
52
- resetMocks();
53
- const eventId = "event1";
54
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
55
- const cookieDomain = ".test.com";
56
- const queueId = "queueId";
57
- const cookieValidity = 3;
58
-
59
- userInQueueStateCookieRepository.store(eventId, queueId, cookieValidity, cookieDomain, "idle", secretKey);
60
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
61
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
62
-
63
- expect(state.isValid).toBeTruthy();
64
- expect(state.queueId).toBe(queueId);
65
- expect(state.isStateExtendable()).toBeFalsy();
66
- expect(state.redirectType).toBe('idle');
67
- expect(state.fixedCookieValidityMinutes).toBe(3);
68
-
69
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
70
- expect(httpContextProvider.res.cookies.get(cookieKey)).not.toBeNull();
71
- const timeDiff = httpContextProvider.res.cookies.get(cookieKey).expiration - Utils.getCurrentTime() - (24 * 60 * 60);
72
- expect(timeDiff < 100).toBeTruthy();
73
- expect(httpContextProvider.res.cookies.get(cookieKey).domain).toBe(cookieDomain);
74
- });
75
-
76
- it('should store_hasValidState_tamperedCookie_stateIsNotValid_isCookieExtendable', () => {
77
- resetMocks();
78
- const eventId = "event1";
79
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
80
- const cookieDomain = ".test.com";
81
- const queueId = "queueId";
82
- const cookieValidity = 10;
83
-
84
- userInQueueStateCookieRepository.store(eventId, queueId, 3, cookieDomain, "Idle", secretKey);
85
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
86
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
87
- expect(state.isValid).toBeTruthy();
88
-
89
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
90
- const oldCookieValue = httpContextProvider.res.cookies.get(cookieKey).value;
91
-
92
- httpContextProvider.res.cookies.get(cookieKey).value = oldCookieValue.replace("FixedValidityMins=3", "FixedValidityMins=10");
93
- const state2 = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
94
- expect(state2.isValid).toBeFalsy();
95
- expect(state.isStateExtendable()).toBeFalsy();
96
- });
97
-
98
- it('should store_hasValidState_tamperedCookie_stateIsNotValid_eventId', () => {
99
- resetMocks();
100
- const eventId = "event1";
101
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
102
- const cookieDomain = ".test.com";
103
- const queueId = "queueId";
104
- const cookieValidity = 10;
105
-
106
- userInQueueStateCookieRepository.store(eventId, queueId, 3, cookieDomain, "Idle", secretKey);
107
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
108
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
109
- expect(state.isValid).toBeTruthy();
110
-
111
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
112
- const oldCookieValue = httpContextProvider.res.cookies.get(cookieKey).value;
113
- httpContextProvider.res.cookies.get(cookieKey).value = oldCookieValue.replace("EventId=event1", "EventId=event2");
114
-
115
- const state2 = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
116
- expect(state2.isValid).toBeFalsy();
117
- expect(state.isStateExtendable()).toBeFalsy();
118
- });
119
-
120
- it('should store_hasValidState_expiredCookie_stateIsNotValid', () => {
121
- resetMocks();
122
- const eventId = "event1";
123
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
124
- const cookieDomain = ".test.com";
125
- const queueId = "queueId";
126
- const cookieValidity = -1;
127
-
128
- userInQueueStateCookieRepository.store(eventId, queueId, 0, cookieDomain, "idle", secretKey);
129
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
130
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
131
-
132
- expect(state.isValid).toBeFalsy();
133
- });
134
-
135
- it('should store_hasValidState_differentEventId_stateIsNotValid', () => {
136
- resetMocks();
137
- const eventId = "event1";
138
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
139
- const cookieDomain = ".test.com";
140
- const queueId = "queueId";
141
- const cookieValidity = 10;
142
-
143
- userInQueueStateCookieRepository.store(eventId, queueId, 0, cookieDomain, "Queue", secretKey);
144
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
145
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
146
- expect(state.isValid).toBeTruthy();
147
-
148
- const state2 = userInQueueStateCookieRepository.getState("event2", cookieValidity, secretKey, true);
149
- expect(state2.isValid).toBeFalsy();
150
- });
151
-
152
- it('should hasValidState_noCookie_stateIsNotValid', () => {
153
- resetMocks();
154
- const eventId = "event1";
155
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
156
- const cookieValidity = 10;
157
-
158
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
159
- expect(state.isValid).toBeFalsy();
160
- });
161
-
162
- it('should hasValidState_invalidCookie_stateIsNotValid', () => {
163
- resetMocks();
164
- const eventId = "event1";
165
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
166
- const cookieDomain = ".test.com";
167
- const queueId = "queueId";
168
- const cookieValidity = 10;
169
-
170
- userInQueueStateCookieRepository.store(eventId, queueId, 20, cookieDomain, "Queue", secretKey);
171
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
172
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
173
- expect(state.isValid).toBeTruthy();
174
-
175
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
176
- httpContextProvider.res.cookies.get(cookieKey).value = "IsCookieExtendable=ooOOO&Expires=|||&QueueId=000&Hash=23232";
177
- const state2 = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
178
- expect(state2.isValid).toBeFalsy();
179
- });
180
-
181
- it('should cancelQueueCookie', () => {
182
- resetMocks();
183
- const eventId = "event1";
184
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
185
- const cookieDomain = ".test.com";
186
- const queueId = "queueId";
187
- const cookieValidity = 20;
188
-
189
- userInQueueStateCookieRepository.store(eventId, queueId, 20, cookieDomain, "Queue", secretKey);
190
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
191
- const state = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
192
- expect(state.isValid).toBeTruthy('should be valid');
193
-
194
- userInQueueStateCookieRepository.cancelQueueCookie(eventId, cookieDomain);
195
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
196
- const state2 = userInQueueStateCookieRepository.getState(eventId, cookieValidity, secretKey, true);
197
- expect(state2.isValid).toBeFalsy('shouldn`t be valid');
198
-
199
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
200
- expect(httpContextProvider.res.cookies.get(cookieKey)).not.toBeNull('event cookie should not be null');
201
- expect(httpContextProvider.res.cookies.get(cookieKey).expiration).toBe(0);
202
- expect(httpContextProvider.res.cookies.get(cookieKey).domain).toBe(cookieDomain);
203
- expect(httpContextProvider.res.cookies.get(cookieKey).value).toBe('');
204
- });
205
-
206
- it('should extendQueueCookie_cookieExist', () => {
207
- resetMocks();
208
- const eventId = "event1";
209
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
210
- const cookieDomain = ".test.com";
211
- const queueId = "queueId";
212
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
213
-
214
- userInQueueStateCookieRepository.store(eventId, queueId, 0, cookieDomain, "Queue", secretKey);
215
- httpContextProvider.req.setCookie('QueueITAccepted-SDFrts345E-V3_event1', httpContextProvider.res.cookies.get('QueueITAccepted-SDFrts345E-V3_event1'));
216
- userInQueueStateCookieRepository.reissueQueueCookie(eventId, 12, cookieDomain, secretKey);
217
-
218
- const state = userInQueueStateCookieRepository.getState(eventId, 5, secretKey, true);
219
- expect(state.isValid).toBeTruthy();
220
- expect(state.queueId).toBe(queueId);
221
- expect(state.isStateExtendable()).toBeTruthy();
222
- expect(httpContextProvider.res.cookies.get(cookieKey).expiration - Utils.getCurrentTime() - 24 * 60 * 60 < 100).toBeTruthy();
223
- expect(httpContextProvider.res.cookies.get(cookieKey).domain).toBe(cookieDomain);
224
- });
225
-
226
- it('should extendQueueCookie_cookieDoesNotExist', () => {
227
- resetMocks();
228
- const eventId = "event1";
229
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
230
- const cookieDomain = ".test.com";
231
- const queueId = "queueId";
232
-
233
- userInQueueStateCookieRepository.store("event2", queueId, 20, cookieDomain, "Queue", secretKey);
234
- userInQueueStateCookieRepository.reissueQueueCookie(eventId, 12, cookieDomain, secretKey);
235
-
236
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey("event2");
237
- expect(httpContextProvider.res.cookies.has(cookieKey)).toBeTruthy()
238
- expect(httpContextProvider.res.cookies.get(cookieKey)).not.toBeNull();
239
- });
240
-
241
- it('should getState_validCookieFormat_extendable', () => {
242
- resetMocks();
243
- const eventId = "event1";
244
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
245
- const cookieDomain = ".test.com";
246
- const queueId = "queueId";
247
- const issueTime = Utils.getCurrentTime();
248
- const hash = generateHash(eventId, queueId, '', "queue", issueTime.toString(), secretKey);
249
-
250
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
251
- httpContextProvider.getHttpResponse().setCookie(cookieKey,
252
- "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + issueTime.toString() + "&Hash=" + hash,
253
- cookieDomain, Utils.getCurrentTime() + (24 * 60 * 60));
254
- httpContextProvider.req.setCookie(cookieKey, httpContextProvider.res.cookies.get(cookieKey));
255
- const state = userInQueueStateCookieRepository.getState(eventId, 10, secretKey, true);
256
-
257
- expect(state.isStateExtendable()).toBeTruthy('should be extendable');
258
- expect(state.isValid).toBeTruthy('should be valid');
259
- expect(state.isFound).toBeTruthy('should be found');
260
- expect(state.queueId).toBe(queueId);
261
- expect(state.redirectType).toBe('queue');
262
- });
263
-
264
- it('should getState_oldCookie_invalid_expiredCookie_extendable', () => {
265
- resetMocks();
266
- const eventId = "event1";
267
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
268
- const cookieDomain = ".test.com";
269
- const queueId = "queueId";
270
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
271
- const issueTime = Utils.getCurrentTime() - 11 * 60;
272
- const hash = generateHash(eventId, queueId, '', "queue", issueTime.toString(), secretKey);
273
-
274
- httpContextProvider.getHttpResponse().setCookie(cookieKey,
275
- "EventId=" + eventId + "&QueueId=" + queueId + "&RedirectType=queue&IssueTime=" + issueTime.toString() + "&Hash=" + hash,
276
- cookieDomain, Utils.getCurrentTime() + 24 * 60 * 60);
277
- httpContextProvider.req.setCookie(cookieKey, httpContextProvider.res.cookies.get(cookieKey));
278
- const state = userInQueueStateCookieRepository.getState(eventId, 10, secretKey, true);
279
-
280
- expect(state.isValid).toBeFalsy();
281
- expect(state.isFound).toBeTruthy();
282
- });
283
-
284
- it('should getState_oldCookie_invalid_expiredCookie_nonExtendable', () => {
285
- resetMocks();
286
- const eventId = "event1";
287
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
288
- const cookieDomain = ".test.com";
289
- const queueId = "queueId";
290
- const issueTime = Utils.getCurrentTime() - 4 * 60;
291
- const hash = generateHash(eventId, queueId, '3', "idle", issueTime.toString(), secretKey);
292
-
293
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
294
- httpContextProvider.getHttpResponse().setCookie(cookieKey,
295
- "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + issueTime.toString() + "&Hash=" + hash,
296
- cookieDomain, Utils.getCurrentTime() + (24 * 60 * 60));
297
- httpContextProvider.req.setCookie(cookieKey, httpContextProvider.res.cookies.get(cookieKey));
298
- const state = userInQueueStateCookieRepository.getState(eventId, 10, secretKey, true);
299
-
300
- expect(state.isValid).toBeFalsy();
301
- expect(state.isFound).toBeTruthy();
302
- });
303
-
304
- it('should getState_validCookieFormat_nonExtendable', () => {
305
- resetMocks();
306
- const eventId = "event1";
307
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
308
- const cookieDomain = ".test.com";
309
- const queueId = "queueId";
310
- const issueTime = Utils.getCurrentTime();
311
- const hash = generateHash(eventId, queueId, '3', "idle", issueTime.toString(), secretKey);
312
-
313
- const cookieKey = UserInQueueStateCookieRepository.getCookieKey(eventId);
314
- httpContextProvider.getHttpResponse()
315
- .setCookie(cookieKey, "EventId=" + eventId + "&QueueId=" + queueId + "&FixedValidityMins=3&RedirectType=idle&IssueTime=" + issueTime.toString() + "&Hash=" + hash,
316
- cookieDomain, Utils.getCurrentTime() + (24 * 60 * 60));
317
- httpContextProvider.req.setCookie(cookieKey, httpContextProvider.res.cookies.get(cookieKey));
318
- const state = userInQueueStateCookieRepository.getState(eventId, 10, secretKey, true);
319
-
320
- expect(state.isStateExtendable()).toBeFalsy();
321
- expect(state.isValid).toBeTruthy();
322
- expect(state.isFound).toBeTruthy();
323
- expect(state.queueId).toBe(queueId);
324
- expect(state.redirectType).toBe('idle');
325
- });
326
-
327
- it('should getState_NoCookie', () => {
328
- resetMocks();
329
- const eventId = "event1";
330
- const secretKey = "4e1deweb821-a82ew5-49da-acdqq0-5d3476f2068db";
331
-
332
- const state = userInQueueStateCookieRepository.getState(eventId, 10, secretKey, true);
333
-
334
- expect(state.isFound).toBeFalsy();
335
- expect(state.isValid).toBeFalsy();
336
- });
337
- });
@@ -1,57 +0,0 @@
1
- module.exports = {
2
- wasi: {},
3
- /**
4
- * A set of globs passed to the glob package that qualify typescript files for testing.
5
- */
6
- include: ["assembly/__tests__/**/*.spec.ts"],
7
- /**
8
- * A set of globs passed to the glob package that quality files to be added to each test.
9
- */
10
- add: ["assembly/__tests__/**/*.include.ts"],
11
- /**
12
- * All the compiler flags needed for this test suite. Make sure that a binary file is output.
13
- */
14
- flags: {
15
- /** To output a wat file, uncomment the following line. */
16
- // "--textFile": ["output.wat"],
17
- /** A runtime must be provided here. */
18
- "--runtime": ["stub"],
19
- },
20
- /**
21
- * A set of regexp that will disclude source files from testing.
22
- */
23
- disclude: [/node_modules/],
24
- /**
25
- * Add your required AssemblyScript imports here.
26
- */
27
- imports(memory, createImports, instantiateSync, binary) {
28
- let instance; // Imports can reference this
29
- const myImports = {
30
- // put your web assembly imports here, and return the module
31
- //log: console.log
32
- };
33
- instance = instantiateSync(binary, createImports(myImports));
34
- return instance;
35
- },
36
- /**
37
- * Add a custom reporter here if you want one. The following example is in typescript.
38
- *
39
- * @example
40
- * import { TestReporter, TestGroup, TestResult, TestContext } from "as-pect";
41
- *
42
- * export class CustomReporter extends TestReporter {
43
- * // implement each abstract method here
44
- * public abstract onStart(suite: TestContext): void;
45
- * public abstract onGroupStart(group: TestGroup): void;
46
- * public abstract onGroupFinish(group: TestGroup): void;
47
- * public abstract onTestStart(group: TestGroup, result: TestResult): void;
48
- * public abstract onTestFinish(group: TestGroup, result: TestResult): void;
49
- * public abstract onFinish(suite: TestContext): void;
50
- * }
51
- */
52
- // reporter: new CustomReporter(),
53
- /**
54
- * Specify if the binary wasm file should be written to the file system.
55
- */
56
- outputBinary: false,
57
- };
@@ -1 +0,0 @@
1
- /// <reference types="@as-pect/assembly/types/as-pect" />
@@ -1,123 +0,0 @@
1
- import {IHttpContextProvider, IHttpRequest, IHttpResponse} from "./sdk/HttpContextProvider";
2
- import {Request, Fastly, Headers} from "@fastly/as-compute";
3
- import {decodeURIComponent, encodeURIComponent} from "./sdk/helpers/Uri";
4
- import {toUTCString} from "./sdk/helpers/Date";
5
-
6
- export function getHttpHandler(req: Request): FastlyHttpContextProvider {
7
- return new FastlyHttpContextProvider(req);
8
- }
9
-
10
- export class FastlyHttpContextProvider implements IHttpContextProvider {
11
- isError: bool = false;
12
- private readonly req: FastlyHttpRequest;
13
- // @ts-ignore
14
- private readonly res: FastlyHttpResponse;
15
-
16
- constructor(fReq: Request) {
17
- this.req = new FastlyHttpRequest(fReq);
18
- this.res = new FastlyHttpResponse();
19
- }
20
-
21
- getHttpRequest(): IHttpRequest {
22
- return this.req;
23
- }
24
-
25
- getHttpResponse(): IHttpResponse {
26
- return this.res;
27
- }
28
- }
29
-
30
- export class FastlyHttpRequest implements IHttpRequest {
31
- private parsedCookieDic: Map<string, string>
32
- private bodyFetched: bool = false;
33
- private body: string = '';
34
-
35
- constructor(private baseReq: Request) {
36
- this.parsedCookieDic = new Map();
37
- this.bodyFetched = false;
38
- }
39
-
40
- private parseCookies(cookieValue: string): void {
41
- const cookies = cookieValue.split(';');
42
- for (let i = 0; i < cookies.length; i++) {
43
- let cookieKV = cookies[i].split('=', 2);
44
- if (cookieKV.length >= 2) {
45
- this.parsedCookieDic.set(cookieKV[0].trim(), cookieKV[1].trim())
46
- }
47
- }
48
- }
49
-
50
- private handleBody(): void {
51
- if (this.baseReq.bodyUsed || this.bodyFetched) {
52
- return;
53
- }
54
- this.bodyFetched = true;
55
- const rawBody: ArrayBuffer | null = null; // this.context.req.arrayBuffer();
56
- if (rawBody == null) {
57
- return;
58
- }
59
- if (rawBody!.byteLength == 0) {
60
- return;
61
- }
62
-
63
- this.body = ''; // this.context.req.text()
64
- }
65
-
66
- getAbsoluteUri(): string {
67
- return this.baseReq.url;
68
- }
69
-
70
- getCookieValue(cookieKey: string): string {
71
- if (this.parsedCookieDic.keys().length == 0) {
72
- this.parseCookies(this.getHeader('cookie'))
73
- }
74
- return this.parsedCookieDic.has(cookieKey) ? decodeURIComponent(this.parsedCookieDic.get(cookieKey)) : '';
75
- }
76
-
77
- getHeader(name: string): string {
78
- if (name.length == 0) return "";
79
- if (!this.baseReq.headers.has(name)) {
80
- return '';
81
- }
82
- const value = this.baseReq.headers.get(name);
83
- if (value == null) return '';
84
- return value!;
85
- }
86
-
87
- getRequestBodyAsString(): string {
88
- if (!this.bodyFetched) {
89
- this.handleBody();
90
- }
91
- return this.body;
92
- }
93
-
94
- getUserAgent(): string {
95
- return this.baseReq.headers.has('user-agent') ? this.baseReq.headers.get('user-agent')! : '';
96
- }
97
-
98
- getUserHostAddress(): string {
99
- return Fastly.getClientIpAddressString();
100
- }
101
- }
102
-
103
- export class FastlyHttpResponse implements IHttpResponse {
104
- private readonly headers: Headers;
105
-
106
- constructor() {
107
- this.headers = new Headers();
108
- }
109
-
110
- setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void {
111
- const expirationDate = new Date(expiration * 1000);
112
- let setCookieString = cookieName + "=" + encodeURIComponent(cookieValue) + "; expires=" + toUTCString(expirationDate) + ";";
113
- if (domain != "") {
114
- setCookieString += " domain=" + domain + ";";
115
- }
116
- setCookieString += " path=/;";
117
- this.headers.set('set-cookie', setCookieString);
118
- }
119
-
120
- getHeaders(): Headers {
121
- return this.headers;
122
- }
123
- }
@@ -1,23 +0,0 @@
1
- import {Utils} from "./sdk/QueueITHelpers";
2
- import {hmacString} from "./sdk/helpers/crypto";
3
-
4
- export class QueueITHelper {
5
- static readonly KUP_VERSION: string = "fastly-1.0.0";
6
-
7
- static configureKnownUserHashing(): void {
8
- Utils.generateSHA256Hash = hmacString;
9
- }
10
-
11
- static addKUPlatformVersion(redirectQueueUrl: string): string {
12
- return redirectQueueUrl + "&kupver=" + QueueITHelper.KUP_VERSION;
13
- }
14
-
15
- static getHostname(customerId: string): string {
16
- return customerId + ".queue-it.net";
17
- }
18
-
19
- static getEndpoint(customerId: string): string {
20
- const host = QueueITHelper.getHostname(customerId);
21
- return "https://" + host + "/status/integrationconfig/secure/" + customerId;
22
- }
23
- }
package/assembly/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import {Fastly} from "@fastly/as-compute";
2
- import {onQueueITRequest} from "./requestResponseHandler";
3
-
4
- const req = Fastly.getClientRequest();
5
- // This is optional and could be done through the Fastly website
6
- req.headers.set('host', 'fastly.v3.ticketania.com');
7
-
8
- let res = onQueueITRequest(req);
9
-
10
- Fastly.respondWith(res);
@@ -1,32 +0,0 @@
1
- import {Fastly, Headers, Request} from "@fastly/as-compute";
2
- import {QueueITHelper} from "./helper";
3
-
4
- let integrationConfig: string = ``;
5
-
6
- function pullIntegrationConfigFromQueueIt(customerId: string, apiKey: string, backend: string): string {
7
- let headers = new Headers();
8
- headers.set('api-key', apiKey);
9
- headers.set('host', QueueITHelper.getHostname(customerId));
10
- const request = new Request(QueueITHelper.getEndpoint(customerId), {
11
- method: 'GET', body: null, headers: headers
12
- })
13
- let cacheOverride = new Fastly.CacheOverride();
14
- cacheOverride.setTTL(60 * 5);
15
-
16
- let beresp = Fastly.fetch(request, {
17
- backend: backend,
18
- cacheOverride: cacheOverride
19
- }).wait();
20
- if (beresp.status != 200) {
21
- return '';
22
- }
23
- return beresp.text();
24
- }
25
-
26
- export function getIntegrationConfig(customerId: string, apiKey: string, backend: string): string {
27
- if (integrationConfig.length > 0) {
28
- return integrationConfig;
29
- }
30
- integrationConfig = pullIntegrationConfigFromQueueIt(customerId, apiKey, backend);
31
- return integrationConfig;
32
- }