Skip to content

Commit

Permalink
Preparing release 3.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
queue-it committed Jun 22, 2022
1 parent ea7b004 commit 63e3cd9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
11 changes: 6 additions & 5 deletions akamaiContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class AkamaiHttpRequest {
return this.getHeader("user-agent");
}

public getHeader(headerNameArg: string) {
public getHeader(headerNameArg:string) {
if (headerNameArg=="x-queueit-ajaxpageurl") {
return (this._akamiNativeRequest.getVariable('PMUSER_QUEUEIT_AJAXURL') || this._akamiNativeRequest.getHeader(headerNameArg) || []).toString();
}
return (this._akamiNativeRequest.getHeader(headerNameArg) || []).toString();
}

public getAbsoluteUri() {
return `${this._akamiNativeRequest.scheme}://${this._akamiNativeRequest.host}${this._akamiNativeRequest.url}`;
}
Expand All @@ -80,11 +82,10 @@ class AkamaiHttpRequest {
return undefined;
}
}

public getRequestBodyAsString() {
return "";
return this._akamiNativeRequest.getVariable('PMUSER_REQ_BODY') || "";
}
}
}

class AkamaiHttpResponse {
constructor(private _akamiNativeRequest: any) {
Expand Down
58 changes: 39 additions & 19 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ 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 QUEUEIT_GENERATEDRESPONSE = 'PMUSER_QUEUEIT_REDIRECTED';

export async function onClientRequest(request) {
let settings: Settings = null;
try {

// Set PMUSER variable to allow validation that EdgeWorker was executed
request.setVariable(EXECUTED_VARIABLE_NAME, 'true');

const settings = QueueITHelper.getSettingsFromPMVariables(request);
settings = QueueITHelper.getSettingsFromPMVariables(request);
if (!settings || isIgnored(request, settings)) {
return;
}
Expand All @@ -37,12 +40,12 @@ export async function onClientRequest(request) {
});

if (settings.GenerateEnqueueToken) {
const validityTime = !settings.EnqueueTokenValidityTime || settings.EnqueueTokenValidityTime < 30000 ?
const validityTime = !settings.EnqueueTokenValidityTime || settings.EnqueueTokenValidityTime < 30000 ?
240000 : settings.EnqueueTokenValidityTime;
contextProvider.setEnqueueTokenProvider(
settings.CustomerId,
settings.SecretKey,
validityTime,
validityTime,
contextProvider.getHttpRequest().getUserHostAddress()
);
}
Expand All @@ -59,21 +62,23 @@ export async function onClientRequest(request) {
headers[headerName] = [QueueITHelper.addKUPlatformVersion(validationResult.getAjaxRedirectUrl())];
headers['Access-Control-Expose-Headers'] = [headerName];
request.respondWith(200, headers, "");
return;

} else {
// Send the user to the queue - either because hash was missing or because is was invalid
let headers = QueueITHelper.getNoCacheHeaders();
headers['Location'] = [QueueITHelper.addKUPlatformVersion(validationResult.redirectUrl)];
request.respondWith(302, headers, "");
return;
}
request.setVariable(QUEUEIT_GENERATEDRESPONSE, 'true');
return;
} else {
// Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
// Support mobile scenario adding the condition !validationResult.isAjaxResult
if (!validationResult.isAjaxResult && queueitToken && validationResult.actionType === "Queue") {
let headers = QueueITHelper.getNoCacheHeaders();
headers['Location'] = [requestUrlWithoutToken];
request.respondWith(302, headers, "");
request.setVariable(QUEUEIT_GENERATEDRESPONSE, 'true');
return;
}
}
Expand All @@ -83,19 +88,15 @@ export async function onClientRequest(request) {
} else {
request.setVariable(ERROR_VARIABLE_NAME, 'request');
}
/*
if (typeof ex == 'string') {
request.setVariable(ERROR_VARIABLE_NAME, ex);
}
else {
request.setVariable(ERROR_VARIABLE_NAME, JSON.stringify(ex));
if (settings != null && settings.AddDebugInfo) {
logExceptionInResponseHeader(true, request, null, ex);
}
*/
logger.log('OnClientRequest Exception: %s', ex);
}
}

export async function onClientResponse(request, response) {
let settings: Settings = null;
try {
response.addHeader(QUEUEIT_CONNECTOR_EXECUTED_HEADER_NAME, QUEUEIT_CONNECTOR_NAME);

Expand Down Expand Up @@ -127,14 +128,9 @@ export async function onClientResponse(request, response) {
} else {
response.addHeader(QUEUEIT_FAILED_HEADERNAME, 'response');
}
/*
if (typeof ex == 'string') {
response.addHeader(QUEUEIT_FAILED_HEADERNAME, ex);
}
else {
response.addHeader(QUEUEIT_FAILED_HEADERNAME, JSON.stringify(ex));
if (settings != null && settings.AddDebugInfo) {
logExceptionInResponseHeader(false, request, response, ex);
}
*/
logger.log('OnClientRequest Exception: %s', ex);
}
}
Expand Down Expand Up @@ -169,4 +165,28 @@ async function validateRequest(contextProvider: AkamaiContextProvider, settings:
settings.CustomerId, settings.SecretKey, contextProvider);

return { queueitToken, requestUrlWithoutToken, validationResult };
}
function logExceptionInResponseHeader(isRequest, request, response, ex,) {
try {
if (isRequest) {
if (typeof ex == 'string') {
request.setVariable(ERROR_VARIABLE_NAME, ex);
}
else {
request.setVariable(ERROR_VARIABLE_NAME, JSON.stringify(ex));
}
return;
}
else {
if (typeof ex == 'string') {
response.addHeader(QUEUEIT_FAILED_HEADERNAME, ex);
}
else {
response.addHeader(QUEUEIT_FAILED_HEADERNAME, JSON.stringify(ex));
}
}
}
catch
{ }

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"repository": "https://github.com/queueit/KnownUser.V3.Akamai",
"license": "MIT",
"main": "./dist/index.js",
"version": "3.0.9",
"version": "3.0.10",
"type": "module",
"scripts": {},
"dependencies": {
Expand Down
10 changes: 6 additions & 4 deletions queueitHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const AKAMAI_SDK_VERSION = "3.0.9";
const AKAMAI_SDK_VERSION = "3.0.10";

export class QueueITHelper {

Expand All @@ -18,7 +18,7 @@ export class QueueITHelper {

public static getNoCacheHeaders() {
return {
'Cache-Control': ['no-cache, no-store, must-revalidate'],
'Cache-Control': ['no-cache, no-store, must-revalidate, max-age=0'],
'Pragma': ['no-cache'],
'Expires': ['Fri, 01 Jan 1990 00:00:00 GMT']
};
Expand All @@ -32,7 +32,8 @@ export class QueueITHelper {
IntegrationConfigType: request.getVariable('PMUSER_QUEUEIT_CONFIG_TYPE'),
IgnoreOptionsRequests: request.getVariable('PMUSER_QUEUEIT_IGNORE_OPTIONS_REQUESTS'),
GenerateEnqueueToken: request.getVariable('PMUSER_QUEUEIT_GENERATE_EQTOKEN'),
EnqueueTokenValidityTime: request.getVariable('PMUSER_QUEUEIT_EQTOKEN_VALIDITY_TIME')
EnqueueTokenValidityTime: request.getVariable('PMUSER_QUEUEIT_EQTOKEN_VALIDITY_TIME'),
AddDebugInfo: request.getVariable('PMUSER_QUEUEIT_ADD_DEBUG')
};

if (!setting.CustomerId) {
Expand Down Expand Up @@ -85,7 +86,8 @@ export interface Settings {
IntegrationConfigType: string,
IgnoreOptionsRequests: boolean,
GenerateEnqueueToken: boolean,
EnqueueTokenValidityTime: Number
EnqueueTokenValidityTime: Number,
AddDebugInfo: boolean
}

export class SettingException {
Expand Down

0 comments on commit 63e3cd9

Please sign in to comment.