From 11365d398fb5b208157a046a9e003a554364b271 Mon Sep 17 00:00:00 2001 From: queue-it Date: Fri, 18 Feb 2022 14:14:40 +0000 Subject: [PATCH] Preparing release 3.0.6 --- akamaiContextProvider.ts | 2 +- akamaiEnqueueTokenProvider.ts | 2 +- integrationConfigProvider.ts | 2 +- main.ts | 53 +++++++++++++++-------------------- package.json | 2 +- queueitHelpers.ts | 14 +++++++-- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/akamaiContextProvider.ts b/akamaiContextProvider.ts index 7dca05a..a9db12a 100644 --- a/akamaiContextProvider.ts +++ b/akamaiContextProvider.ts @@ -3,7 +3,7 @@ import { Cookies } from 'cookies'; import { IConnectorContextProvider, ICryptoProvider, IEnqueueTokenProvider, IHttpRequest, IHttpResponse } from 'queueit-knownuser'; import { AkamaiCryptoProvider } from './akamaiCryptoProvider.js'; import { AkamaiEnqueueTokenProvider } from './akamaiEnqueueTokenProvider.js'; -import { Settings } from './QueueITHelpers'; +import { Settings } from './queueitHelpers.js'; export class AkamaiContextProvider implements IConnectorContextProvider { private _httpRequest: IHttpRequest; diff --git a/akamaiEnqueueTokenProvider.ts b/akamaiEnqueueTokenProvider.ts index 5415062..982107e 100644 --- a/akamaiEnqueueTokenProvider.ts +++ b/akamaiEnqueueTokenProvider.ts @@ -1,5 +1,5 @@ import { IEnqueueTokenProvider } from "queueit-knownuser"; -import { QueueITHelper, Settings } from "./QueueITHelpers.js"; +import { QueueITHelper, Settings } from "./queueitHelpers.js"; import { Token, Payload } from "./sdk/queueToken.js"; export class AkamaiEnqueueTokenProvider implements IEnqueueTokenProvider { diff --git a/integrationConfigProvider.ts b/integrationConfigProvider.ts index 5d4e828..a05cf38 100644 --- a/integrationConfigProvider.ts +++ b/integrationConfigProvider.ts @@ -24,7 +24,7 @@ class IntegrationConfigProvider { const options: any = {} options.method = "GET"; options.headers = { "api-key": apiKey }; - options.timeout = 950; + options.timeout = 1400; return (await httpRequest("/queueit/integrationconfig/", options)).text(); } private static getIntegrationConfigFromEdgeKV = async function () { diff --git a/main.ts b/main.ts index a9fab0c..8341765 100644 --- a/main.ts +++ b/main.ts @@ -2,7 +2,7 @@ import { AkamaiContextProvider } from './akamaiContextProvider.js'; import { KnownUser } from './sdk/queueit-knownuserv3-sdk.js'; -import { QueueITHelper, SettingException, Settings } from './QueueITHelpers.js'; +import { QueueITHelper, SettingException, Settings } from './queueitHelpers.js'; import { IntegrationConfigProvider } from './integrationConfigProvider.js'; // @ts-ignore @@ -10,24 +10,23 @@ import { logger } from 'log'; const COOKIE_VARIABLE_NAME = 'PMUSER_QUEUEIT_C'; const ERROR_VARIABLE_NAME = 'PMUSER_QUEUEIT_ER'; +const EXECUTED_VARIABLE_NAME = 'PMUSER_QUEUEIT_EXECUTED'; const BIG_SET_COOKIE_VALUE = 'TOO_BIG_COOKIE'; const QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME = 'x-queueit-connector'; const QUEUEIT_FAILED_HEADERNAME = 'x-queueit-failed'; const QUEUEIT_CONNECTOR_NAME = "akamai"; -const SHOULD_IGNORE_OPTIONS_REQUESTS = false; -const SHOULD_INCLUDE_ENQUEUETOKEN = false; -const EXECUTED_VARIABLE_NAME = 'PMUSER_QUEUEIT_EXECUTED'; export async function onClientRequest(request) { try { // Set PMUSER variable to allow validation that EdgeWorker was executed request.setVariable(EXECUTED_VARIABLE_NAME, 'true'); - if (isIgnored(request)) { + const settings = QueueITHelper.getSettingsFromPMVariables(request); + if (isIgnored(request, settings)) { return; } - let httpContext = new AkamaiContextProvider(request, { + let contextProvider = new AkamaiContextProvider(request, { storeCookie: function (cookieString) { if (cookieString.length < 800) { request.setVariable(COOKIE_VARIABLE_NAME, cookieString); @@ -36,17 +35,16 @@ export async function onClientRequest(request) { } } }); - const settings = QueueITHelper.getSettingsFromPMVariables(request); - if (includeEnqueueToken()) { - httpContext.setEnqueueTokenProvider( + if (settings.GenerateEnqueueToken) { + contextProvider.setEnqueueTokenProvider( settings, 60000, - httpContext.getHttpRequest().getUserHostAddress() + contextProvider.getHttpRequest().getUserHostAddress() ); } - let { queueitToken, requestUrlWithoutToken, validationResult } = await validateRequest(httpContext, settings); + let { queueitToken, requestUrlWithoutToken, validationResult } = await validateRequest(contextProvider, settings); if (validationResult.doRedirect()) { // Adding no cache headers to prevent browsers to cache requests @@ -98,7 +96,8 @@ export async function onClientResponse(request, response) { try { response.addHeader(QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME, QUEUEIT_CONNECTOR_NAME); - if (isIgnored(request)) { + let settings = QueueITHelper.getSettingsFromPMVariables(request); + if (isIgnored(request, settings)) { return; } @@ -106,14 +105,13 @@ export async function onClientResponse(request, response) { if (cookieString && cookieString !== BIG_SET_COOKIE_VALUE) { response.addHeader('Set-Cookie', cookieString); } else if (cookieString == BIG_SET_COOKIE_VALUE) { - let httpContext = new AkamaiContextProvider(request, { + let contextProvider = new AkamaiContextProvider(request, { storeCookie: function (cookieString) { response.addHeader('Set-Cookie', cookieString); } }); //cookie value was big so re-evaluating to be able to set the cookie on the response - let settings = QueueITHelper.getSettingsFromPMVariables(request); - await validateRequest(httpContext, settings); + await validateRequest(contextProvider, settings); } let error = request.getVariable(ERROR_VARIABLE_NAME); @@ -138,27 +136,23 @@ export async function onClientResponse(request, response) { } } -function isIgnored(request) { - return SHOULD_IGNORE_OPTIONS_REQUESTS && request.method === 'OPTIONS'; -} - -function includeEnqueueToken() { - return SHOULD_INCLUDE_ENQUEUETOKEN; +function isIgnored(request, settings: Settings) { + return request.method === 'OPTIONS' && settings.IgnoreOptionsRequests; } -async function getQueueItToken(httpContext, requestUrl: string) { +async function getQueueItToken(contextProvider: AkamaiContextProvider, requestUrl: string) { let queueitToken = QueueITHelper.getParameterByName(KnownUser.QueueITTokenKey, requestUrl); if (queueitToken) { return queueitToken; } const tokenHeaderName = `x-${KnownUser.QueueITTokenKey}`; - return httpContext.getHttpRequest().getHeader(tokenHeaderName); + return contextProvider.getHttpRequest().getHeader(tokenHeaderName); } -async function validateRequest(httpContext, settings: Settings) { - const requestUrl = httpContext.getHttpRequest().getAbsoluteUri(); - const queueitToken = await getQueueItToken(httpContext, requestUrl); +async function validateRequest(contextProvider: AkamaiContextProvider, settings: Settings) { + const requestUrl = contextProvider.getHttpRequest().getAbsoluteUri(); + const queueitToken = await getQueueItToken(contextProvider, requestUrl); let requestUrlWithoutToken = requestUrl.replace(new RegExp("([\?&])(" + KnownUser.QueueITTokenKey + "=[^&]*)", 'i'), ""); requestUrlWithoutToken = requestUrlWithoutToken.replace(new RegExp("[?]$"), ""); @@ -168,10 +162,7 @@ async function validateRequest(httpContext, settings: Settings) { const validationResult = KnownUser.validateRequestByIntegrationConfig( requestUrl, queueitToken, integrationConfig, - settings.CustomerId, settings.SecretKey, httpContext); + settings.CustomerId, settings.SecretKey, contextProvider); return { queueitToken, requestUrlWithoutToken, validationResult }; -} - - - +} \ No newline at end of file diff --git a/package.json b/package.json index 5735f28..ef89648 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "repository": "https://github.com/queueit/KnownUser.V3.Akamai", "license": "MIT", "main": "./dist/index.js", - "version": "3.0.5", + "version": "3.0.6", "type": "module", "scripts": {}, "dependencies": { diff --git a/queueitHelpers.ts b/queueitHelpers.ts index 6be7d5d..dddae84 100644 --- a/queueitHelpers.ts +++ b/queueitHelpers.ts @@ -1,5 +1,5 @@ -const AKAMAI_SDK_VERSION = "3.0.5"; +const AKAMAI_SDK_VERSION = "3.0.6"; export class QueueITHelper { @@ -29,7 +29,9 @@ export class QueueITHelper { SecretKey: request.getVariable('PMUSER_QUEUEIT_SECRET_KEY'), ApiKey: request.getVariable('PMUSER_QUEUEIT_API_KEY'), CustomerId: request.getVariable('PMUSER_QUEUEIT_CUSTOMERID'), - IntegrationConfigType: request.getVariable('PMUSER_QUEUEIT_CONFIG_TYPE') + IntegrationConfigType: request.getVariable('PMUSER_QUEUEIT_CONFIG_TYPE'), + IgnoreOptionsRequests: request.getVariable('PMUSER_QUEUEIT_IGNORE_OPTIONS_REQUESTS'), + GenerateEnqueueToken: request.getVariable('PMUSER_QUEUEIT_GENERATE_EQTOKEN') }; if (!setting.CustomerId) { @@ -53,6 +55,10 @@ export class QueueITHelper { throw settingException; } + // convert to boolean + setting.IgnoreOptionsRequests = setting.IgnoreOptionsRequests && setting.IgnoreOptionsRequests.toLowerCase() == 'true'; + setting.GenerateEnqueueToken = setting.GenerateEnqueueToken && setting.GenerateEnqueueToken.toLowerCase() == 'true'; + return setting; } @@ -75,7 +81,9 @@ export interface Settings { SecretKey: string, ApiKey: string, CustomerId: string, - IntegrationConfigType: string + IntegrationConfigType: string, + IgnoreOptionsRequests: boolean, + GenerateEnqueueToken: boolean } export class SettingException {