diff --git a/akamaiContextProvider.ts b/akamaiContextProvider.ts index a9db12a..bdff56f 100644 --- a/akamaiContextProvider.ts +++ b/akamaiContextProvider.ts @@ -3,7 +3,6 @@ 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.js'; export class AkamaiContextProvider implements IConnectorContextProvider { private _httpRequest: IHttpRequest; @@ -26,18 +25,15 @@ export class AkamaiContextProvider implements IConnectorContextProvider { } public setEnqueueTokenProvider( - setting: Settings, + customerId: string, + secretKey: string, validityTime: Number, clientIp: string, customData?: any) { - - if (!setting || validityTime < -1) { - this._enqueueTokenProvider = null; - return; - } - + this._enqueueTokenProvider = new AkamaiEnqueueTokenProvider( - setting, + customerId, + secretKey, validityTime, clientIp, customData diff --git a/akamaiEnqueueTokenProvider.ts b/akamaiEnqueueTokenProvider.ts index 982107e..bbae0d7 100644 --- a/akamaiEnqueueTokenProvider.ts +++ b/akamaiEnqueueTokenProvider.ts @@ -1,32 +1,32 @@ import { IEnqueueTokenProvider } from "queueit-knownuser"; -import { QueueITHelper, Settings } from "./queueitHelpers.js"; +import { QueueITHelper } from "./queueitHelpers.js"; import { Token, Payload } from "./sdk/queueToken.js"; export class AkamaiEnqueueTokenProvider implements IEnqueueTokenProvider { - _settings: Settings; + _customerId: string; + _secretKey: string; _validityTime: Number; _clientIp: string; _customData: any; public constructor( - setting: Settings, + customerId: string, + secretKey: string, validityTime: Number, clientIp?: string, customData?: any ) { - this._settings = setting; + this._customerId = customerId; + this._secretKey = secretKey; this._validityTime = validityTime; this._clientIp = clientIp; this._customData = `{ ${(customData !== null) ? `,"cd":"${customData}"` : ''} }`; } public getEnqueueToken(wrId: string): string { - if (!this._settings || this._validityTime < -1 || !this._clientIp) { - return null; - } - const token = Token.Enqueue(this._settings.CustomerId) + const token = Token.Enqueue(this._customerId) .WithPayload( Payload.Enqueue() .WithKey(QueueITHelper.generateUUID()) @@ -36,7 +36,7 @@ export class AkamaiEnqueueTokenProvider implements IEnqueueTokenProvider { .WithEventId(wrId) .WithIpAddress(this._clientIp) .WithValidity(this._validityTime) - .Generate(this._settings.SecretKey); + .Generate(this._secretKey); return token.Token; } diff --git a/main.ts b/main.ts index c88525c..27abf0b 100644 --- a/main.ts +++ b/main.ts @@ -22,7 +22,7 @@ export async function onClientRequest(request) { request.setVariable(EXECUTED_VARIABLE_NAME, 'true'); const settings = QueueITHelper.getSettingsFromPMVariables(request); - if (isIgnored(request, settings)) { + if (!settings || isIgnored(request, settings)) { return; } @@ -37,9 +37,12 @@ export async function onClientRequest(request) { }); if (settings.GenerateEnqueueToken) { + const validityTime = !settings.EnqueueTokenValidityTime || settings.EnqueueTokenValidityTime < 30000 ? + 240000 : settings.EnqueueTokenValidityTime; contextProvider.setEnqueueTokenProvider( - settings, - 60000, + settings.CustomerId, + settings.SecretKey, + validityTime, contextProvider.getHttpRequest().getUserHostAddress() ); } diff --git a/package.json b/package.json index 3bd8c7b..6a0044d 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.8", + "version": "3.0.9", "type": "module", "scripts": {}, "dependencies": { diff --git a/queueitHelpers.ts b/queueitHelpers.ts index 514bf60..4040433 100644 --- a/queueitHelpers.ts +++ b/queueitHelpers.ts @@ -1,5 +1,5 @@ -const AKAMAI_SDK_VERSION = "3.0.8"; +const AKAMAI_SDK_VERSION = "3.0.9"; export class QueueITHelper { @@ -31,7 +31,8 @@ export class QueueITHelper { CustomerId: request.getVariable('PMUSER_QUEUEIT_CUSTOMERID'), IntegrationConfigType: request.getVariable('PMUSER_QUEUEIT_CONFIG_TYPE'), IgnoreOptionsRequests: request.getVariable('PMUSER_QUEUEIT_IGNORE_OPTIONS_REQUESTS'), - GenerateEnqueueToken: request.getVariable('PMUSER_QUEUEIT_GENERATE_EQTOKEN') + GenerateEnqueueToken: request.getVariable('PMUSER_QUEUEIT_GENERATE_EQTOKEN'), + EnqueueTokenValidityTime: request.getVariable('PMUSER_QUEUEIT_EQTOKEN_VALIDITY_TIME') }; if (!setting.CustomerId) { @@ -83,7 +84,8 @@ export interface Settings { CustomerId: string, IntegrationConfigType: string, IgnoreOptionsRequests: boolean, - GenerateEnqueueToken: boolean + GenerateEnqueueToken: boolean, + EnqueueTokenValidityTime: Number } export class SettingException {