@queue-it/fastly 1.0.3 → 1.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Queue-it
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -2,7 +2,7 @@ import { Utils } from "./sdk/QueueITHelpers";
2
2
  import { hmacString } from "./sdk/helpers/crypto";
3
3
 
4
4
  export class QueueITHelper {
5
- static readonly KUP_VERSION: string = "fastly-1.0.3";
5
+ static readonly KUP_VERSION: string = "fastly-1.1.0";
6
6
 
7
7
  static configureKnownUserHashing(): void {
8
8
  Utils.generateSHA256Hash = hmacString;
@@ -69,6 +69,7 @@ export function onQueueITRequest(
69
69
  url: "",
70
70
  });
71
71
  // In case of ajax call send the user to the queue by sending a custom queue-it header and redirecting user to queue from javascript
72
+ response.headers.set("Access-Control-Expose-Headers", validationResult.getAjaxQueueRedirectHeaderKey());
72
73
  response.headers.set(
73
74
  validationResult.getAjaxQueueRedirectHeaderKey(),
74
75
  QueueITHelper.addKUPlatformVersion(
@@ -1,198 +1,221 @@
1
- import {JSONHandler} from "assemblyscript-json";
2
- import {
3
- CustomerIntegration,
4
- IntegrationConfigModel,
5
- TriggerModel,
6
- TriggerPart
7
- } from "./IntegrationConfigModel";
8
- import {JSONDecoder} from "assemblyscript-json";
9
-
10
- export class CustomerIntegrationDecodingHandler extends JSONHandler {
11
- private readonly _deserializedValue: CustomerIntegration;
12
- private isInIntegrations: bool = false;
13
- private isInTriggers: bool = false;
14
- private isInConfigModel: bool = false;
15
- private isInTriggerModel: bool = false;
16
- private isInTriggerPart: bool = false;
17
- private currentIntegrationConfigModel: IntegrationConfigModel | null;
18
- private currentTriggerModel: TriggerModel | null;
19
- private currentTriggerPart: TriggerPart | null;
20
- private isInTriggerParts: bool = false;
21
- private isInTriggerPartValuesToCompare: bool = false;
22
-
23
- constructor() {
24
- super();
25
- this._deserializedValue = new CustomerIntegration();
26
- }
27
-
28
- pushArray(name: string): bool {
29
- // Handle array start
30
- // true means that nested object needs to be traversed, false otherwise
31
- // Note that returning false means JSONDecoder.startIndex need to be updated by handler
32
- if (name == "Integrations") {
33
- this.isInIntegrations = true;
34
- } else if (name == "Triggers") {
35
- this.isInTriggers = true;
36
- } else if (name == "TriggerParts") {
37
- this.isInTriggerParts = true;
38
- } else if (name == "ValuesToCompare") {
39
- this.isInTriggerPartValuesToCompare = true;
40
- }
41
- return this.isInIntegrations
42
- || this.isInTriggers
43
- || this.isInTriggerParts
44
- || this.isInTriggerPartValuesToCompare;
45
- }
46
-
47
-
48
- popArray(): void {
49
- if (this.isInTriggerPartValuesToCompare) {
50
- this.isInTriggerPartValuesToCompare = false;
51
- } else if (this.isInTriggerParts) {
52
- this.isInTriggerParts = false;
53
- } else if (this.isInTriggers) {
54
- this.isInTriggers = false;
55
- } else if (this.isInIntegrations) {
56
- this.isInIntegrations = false;
57
- }
58
- }
59
-
60
- pushObject(name: string): bool {
61
- if (this.isInTriggerParts) {
62
- this.isInTriggerPart = true;
63
- this.currentTriggerPart = new TriggerPart();
64
- } else if (this.isInTriggers) {
65
- this.isInTriggerModel = true;
66
- this.currentTriggerModel = new TriggerModel();
67
- } else if (this.isInIntegrations) {
68
- this.isInConfigModel = true;
69
- this.currentIntegrationConfigModel = new IntegrationConfigModel();
70
- }
71
- return super.pushObject(name);
72
- }
73
-
74
- popObject(): void {
75
- if (this.isInTriggerPart) {
76
- this.currentTriggerModel!.TriggerParts.push(this.currentTriggerPart!);
77
- this.isInTriggerPart = false;
78
- } else if (this.isInTriggerModel) {
79
- this.currentIntegrationConfigModel!.Triggers.push(this.currentTriggerModel!);
80
- this.isInTriggerModel = false;
81
- } else if (this.isInConfigModel) {
82
- this._deserializedValue.Integrations.push(this.currentIntegrationConfigModel!);
83
- this.isInConfigModel = false;
84
- }
85
- }
86
-
87
- setInteger(name: string, value: i64): void {
88
- if (this.isInConfigModel) {
89
- this.setConfigModelInteger(name, value);
90
- } else if (name == "Version") {
91
- this._deserializedValue.Version = value;
92
- }
93
- }
94
-
95
- setBoolean(name: string, value: bool): void {
96
- if (this.isInTriggerPart) {
97
- this.setTriggerPartBoolean(name, value);
98
- } else if (this.isInConfigModel) {
99
- this.setConfigModelBoolean(name, value);
100
- }
101
- }
102
-
103
- setString(name: string, value: string): void {
104
- if (this.isInTriggerPartValuesToCompare) {
105
- this.addTriggerPartValuesToCompare(value);
106
- } else if (this.isInTriggerPart) {
107
- this.setTriggerPartString(name, value);
108
- } else if (this.isInTriggerModel) {
109
- this.setTriggerModelString(name, value);
110
- } else if (this.isInConfigModel) {
111
- this.setConfigModelString(name, value);
112
- } else if (name == "Description") {
113
- this._deserializedValue.Description = value;
114
- }
115
- }
116
-
117
- setConfigModelBoolean(name: string, value: bool): void {
118
- if (name == "ExtendCookieValidity") {
119
- this.currentIntegrationConfigModel!.ExtendCookieValidity = value;
120
- }
121
- }
122
-
123
- setTriggerPartBoolean(name: string, value: bool): void {
124
- if (name == "IsNegative") {
125
- this.currentTriggerPart!.IsNegative = value;
126
- } else if (name == "IsIgnoreCase") {
127
- this.currentTriggerPart!.IsIgnoreCase = value;
128
- }
129
- }
130
-
131
- setConfigModelInteger(name: string, value: i64): void {
132
- if (name == "CookieValidityMinute") {
133
- this.currentIntegrationConfigModel!.CookieValidityMinute = value;
134
- }
135
- }
136
-
137
- addTriggerPartValuesToCompare(value: string): void {
138
- this.currentTriggerPart!.ValuesToCompare.push(value);
139
- }
140
-
141
- setTriggerPartString(name: string, value: string): void {
142
- if (name == "ValidatorType") {
143
- this.currentTriggerPart!.ValidatorType = value;
144
- } else if (name == "Operator") {
145
- this.currentTriggerPart!.Operator = value;
146
- } else if (name == "ValueToCompare") {
147
- this.currentTriggerPart!.ValueToCompare = value;
148
- } else if (name == "UrlPart") {
149
- this.currentTriggerPart!.UrlPart = value;
150
- } else if (name == "CookieName") {
151
- this.currentTriggerPart!.CookieName = value;
152
- } else if (name == "HttpHeaderName") {
153
- this.currentTriggerPart!.HttpHeaderName = value;
154
- }
155
- }
156
-
157
- setTriggerModelString(name: string, value: string): void {
158
- if (name == "LogicalOperator") {
159
- this.currentTriggerModel!.LogicalOperator = value;
160
- }
161
- }
162
-
163
- setConfigModelString(name: string, value: string): void {
164
- if (name == "Name") {
165
- this.currentIntegrationConfigModel!.Name = value;
166
- } else if (name == "EventId") {
167
- this.currentIntegrationConfigModel!.EventId = value;
168
- } else if (name == "CookieDomain") {
169
- this.currentIntegrationConfigModel!.CookieDomain = value;
170
- } else if (name == "LayoutName") {
171
- this.currentIntegrationConfigModel!.LayoutName = value;
172
- } else if (name == "Culture") {
173
- this.currentIntegrationConfigModel!.Culture = value;
174
- } else if (name == "QueueDomain") {
175
- this.currentIntegrationConfigModel!.QueueDomain = value;
176
- } else if (name == "RedirectLogic") {
177
- this.currentIntegrationConfigModel!.RedirectLogic = value;
178
- } else if (name == "ForcedTargetUrl") {
179
- this.currentIntegrationConfigModel!.ForcedTargetUrl = value;
180
- } else if (name == "ActionType") {
181
- this.currentIntegrationConfigModel!.ActionType = value;
182
- }
183
- }
184
-
185
- value(): CustomerIntegration {
186
- return this._deserializedValue;
187
- }
188
-
189
- static deserialize(integrationsConfigString: string): CustomerIntegration {
190
- const handler = new CustomerIntegrationDecodingHandler();
191
- if (integrationsConfigString == '') {
192
- return handler.value();
193
- }
194
- const decoder = new JSONDecoder<CustomerIntegrationDecodingHandler>(handler);
195
- decoder.deserialize(Uint8Array.wrap(String.UTF8.encode(integrationsConfigString)));
196
- return handler.value();
197
- }
198
- }
1
+ 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
+ }