@queue-it/fastly 5.0.0 → 5.0.1-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queue-it/fastly",
3
- "version": "5.0.0",
3
+ "version": "5.0.1-beta.0",
4
4
  "description": "Queue-it connector for Fastly",
5
5
  "main": "src/index.ts",
6
6
  "author": "devs@queue-it.com",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "scripts": {
22
22
  "typecheck": "tsc --noEmit",
23
- "bundle": "esbuild src/index.ts --bundle --outfile=bin/index.js --platform=node --target=es2022 && js-compute-runtime bin/index.js bin/main.wasm",
23
+ "bundle": "esbuild src/index.ts --bundle --outfile=bin/index.js --platform=node --target=es2022 --external:fastly:* && js-compute-runtime bin/index.js bin/main.wasm",
24
24
  "build": "fastly compute build",
25
25
  "deploy": "fastly compute deploy"
26
26
  },
@@ -17,9 +17,10 @@ export function getHttpHandler(
17
17
  req: Request,
18
18
  clientIp: string = '',
19
19
  bodyString: string = '',
20
+ decodeRequestBody: boolean = false,
20
21
  directActionsSettings?: FastlyDirectActionsSettings
21
22
  ): FastlyHttpContextProvider {
22
- return new FastlyHttpContextProvider(req, clientIp, bodyString, directActionsSettings);
23
+ return new FastlyHttpContextProvider(req, clientIp, bodyString, decodeRequestBody, directActionsSettings);
23
24
  }
24
25
 
25
26
  export class FastlyHttpContextProvider implements IConnectorContextProvider {
@@ -35,9 +36,10 @@ export class FastlyHttpContextProvider implements IConnectorContextProvider {
35
36
  fReq: Request,
36
37
  clientIp: string = '',
37
38
  bodyString: string = '',
39
+ decodeRequestBody: boolean = false,
38
40
  directActionsSettings?: FastlyDirectActionsSettings
39
41
  ) {
40
- this._httpRequest = new FastlyHttpRequest(fReq, clientIp, bodyString);
42
+ this._httpRequest = new FastlyHttpRequest(fReq, clientIp, bodyString, decodeRequestBody);
41
43
  this._httpResponse = new FastlyHttpResponse();
42
44
  this._normalizationProvider = new DefaultNormalizationProvider();
43
45
  this._cryptoProvider = new FastlyCryptoProvider();
@@ -102,7 +104,12 @@ export class FastlyHttpContextProvider implements IConnectorContextProvider {
102
104
  class FastlyHttpRequest implements IHttpRequest {
103
105
  private _parsedCookieDic: Record<string, string> | null = null;
104
106
 
105
- constructor(private baseReq: Request, private _clientIp: string = '', private _bodyString: string = '') {}
107
+ constructor(
108
+ private baseReq: Request,
109
+ private _clientIp: string = '',
110
+ private _bodyString: string = '',
111
+ private _decodeRequestBody: boolean = false
112
+ ) {}
106
113
 
107
114
  getUserAgent(): string {
108
115
  return this.getHeader('user-agent');
@@ -141,6 +148,13 @@ class FastlyHttpRequest implements IHttpRequest {
141
148
  }
142
149
 
143
150
  getRequestBodyAsString(): string {
151
+ if (this._decodeRequestBody) {
152
+ try {
153
+ return decodeURIComponent(this._bodyString);
154
+ } catch {
155
+ // fall through to return the raw body
156
+ }
157
+ }
144
158
  return this._bodyString;
145
159
  }
146
160
 
package/src/helper.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export class QueueITHelper {
2
- static readonly KUP_VERSION: string = "fastly-5.0.0";
2
+ static readonly KUP_VERSION: string = "fastly-5.0.1";
3
3
 
4
4
  static addKUPlatformVersion(redirectQueueUrl: string): string {
5
5
  return `${redirectQueueUrl}&kupver=${QueueITHelper.KUP_VERSION}`;
@@ -61,6 +61,7 @@ const integrationCustomerId = "customerId",
61
61
  enqueueTokenValidityTimeKey = "enqueueTokenValidityTime",
62
62
  enqueueTokenKeyEnabledKey = "enqueueTokenKeyEnabled",
63
63
  requestBodyEnabledKey = "requestBodyEnabled",
64
+ decodeRequestBodyKey = "decodeRequestBody",
64
65
  directActionsDisabledKey = "directActionsDisabled",
65
66
  directActionsProxyKeyKey = "directActionsProxyKey",
66
67
  directPassTimeoutKey = "directPassTimeout",
@@ -107,6 +108,12 @@ export function resolveIntegrationDetails(): IntegrationDetails | null {
107
108
  requestBodyEnabled = requestBodyEnabledVal.toLowerCase() === "true";
108
109
  }
109
110
 
111
+ let decodeRequestBody = false;
112
+ const decodeRequestBodyVal = dict.get(decodeRequestBodyKey);
113
+ if (decodeRequestBodyVal !== null) {
114
+ decodeRequestBody = decodeRequestBodyVal.toLowerCase() === "true";
115
+ }
116
+
110
117
  let directActionsDisabled = false;
111
118
  const directActionsDisabledVal = dict.get(directActionsDisabledKey);
112
119
  if (directActionsDisabledVal !== null) {
@@ -150,6 +157,7 @@ export function resolveIntegrationDetails(): IntegrationDetails | null {
150
157
  enqueueTokenValidityTime,
151
158
  enqueueTokenKeyEnabled,
152
159
  requestBodyEnabled,
160
+ decodeRequestBody,
153
161
  new QueueItIntegrationEndpointProvider(),
154
162
  new MockLogger(),
155
163
  {
@@ -227,6 +235,7 @@ export class IntegrationDetails {
227
235
  public enqueueTokenValidityTime: number = 240000,
228
236
  public enqueueTokenKeyEnabled: boolean = false,
229
237
  public requestBodyEnabled: boolean = false,
238
+ public decodeRequestBody: boolean = false,
230
239
  public provider: IntegrationEndpointProvider = new QueueItIntegrationEndpointProvider(),
231
240
  public logger: RequestLogger = new MockLogger(),
232
241
  directActionsSettings?: FastlyDirectActionsSettings
@@ -38,7 +38,7 @@ export async function onQueueITRequest(
38
38
  bodyString = ((await req.clone().text()) || '').substring(0, 2048);
39
39
  }
40
40
 
41
- httpProvider = getHttpHandler(req, conf.clientIp, bodyString, conf.directActionsSettings);
41
+ httpProvider = getHttpHandler(req, conf.clientIp, bodyString, conf.decodeRequestBody, conf.directActionsSettings);
42
42
  sendNoCacheHeaders = false;
43
43
 
44
44
  if (conf.enqueueTokenEnabled) {