aws-classify-server 0.1.5 → 0.1.6
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.
|
@@ -16,6 +16,7 @@ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
|
16
16
|
const client_apigatewaymanagementapi_1 = require("@aws-sdk/client-apigatewaymanagementapi");
|
|
17
17
|
const ddbClient = new client_dynamodb_1.DynamoDBClient({ region: process.env.DD_REGION, endpoint: process.env.DD_ENDPOINT });
|
|
18
18
|
const ddbDocClient = lib_dynamodb_1.DynamoDBDocument.from(ddbClient);
|
|
19
|
+
const updateDebounceInterval = 1000 * 60 * 10; // Don't update session unless 10 minutes have passed or data changed
|
|
19
20
|
class ClassifyServerless {
|
|
20
21
|
constructor() {
|
|
21
22
|
this.logLevel = {};
|
|
@@ -109,7 +110,7 @@ class ClassifyServerless {
|
|
|
109
110
|
return (0, js_freeze_dry_1.serialize)(lambdaResponse, classes);
|
|
110
111
|
}
|
|
111
112
|
const updatedSessionData = (0, js_freeze_dry_1.serialize)(obj, classes);
|
|
112
|
-
if (!result || updatedSessionData !== result.sessionData)
|
|
113
|
+
if (!result || updatedSessionData !== result.sessionData || (Date.now() > (result.updated + updateDebounceInterval)))
|
|
113
114
|
sessionId = yield saveSessionData(sessionId, request.interfaceName, updatedSessionData, undefined, obj.__userId__, this.expirationMinutes);
|
|
114
115
|
// Formulate response
|
|
115
116
|
const lambdaResponse = {
|
|
@@ -242,7 +243,7 @@ class ClassifyServerless {
|
|
|
242
243
|
this.log(`creating response for ${interfaceName} with sessionId=${sessionId} connectionId= ${obj.__connectionId__} sessionData=${sessionData}`);
|
|
243
244
|
const ret = yield callback(obj);
|
|
244
245
|
const updatedSessionData = (0, js_freeze_dry_1.serialize)(obj, classes);
|
|
245
|
-
if (updatedSessionData !== result.sessionData ||
|
|
246
|
+
if (updatedSessionData !== result.sessionData || (Date.now() > (result.updated + updateDebounceInterval))) {
|
|
246
247
|
if (this.logLevel.calls)
|
|
247
248
|
this.log(`saving session data for ${interfaceName} with sessionId=${sessionId} connectionId= ${obj.__connectionId__} sessionData=${updatedSessionData}`);
|
|
248
249
|
yield saveSessionData(sessionId, interfaceName, updatedSessionData, undefined, undefined, this.expirationMinutes);
|
|
@@ -338,7 +339,7 @@ function saveSessionData(sessionId, interfaceName, sessionData, connectionId, us
|
|
|
338
339
|
const expires = new Date();
|
|
339
340
|
expires.setMinutes(expires.getMinutes() + expirationMinutes);
|
|
340
341
|
updateExpressionComponents.push('expires = :expires');
|
|
341
|
-
expressionAttributeValues[':expires'] = expires.getTime() / 1000;
|
|
342
|
+
expressionAttributeValues[':expires'] = Math.floor(expires.getTime() / 1000);
|
|
342
343
|
}
|
|
343
344
|
if (sessionData && interfaceName) {
|
|
344
345
|
updateExpressionComponents.push(`interface_${interfaceName} = :data`);
|
|
@@ -13,6 +13,7 @@ import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
|
13
13
|
import { ApiGatewayManagementApiClient, PostToConnectionCommand } from "@aws-sdk/client-apigatewaymanagementapi";
|
|
14
14
|
const ddbClient = new DynamoDBClient({ region: process.env.DD_REGION, endpoint: process.env.DD_ENDPOINT });
|
|
15
15
|
const ddbDocClient = DynamoDBDocument.from(ddbClient);
|
|
16
|
+
const updateDebounceInterval = 1000 * 60 * 10; // Don't update session unless 10 minutes have passed or data changed
|
|
16
17
|
export class ClassifyServerless {
|
|
17
18
|
constructor() {
|
|
18
19
|
this.logLevel = {};
|
|
@@ -106,7 +107,7 @@ export class ClassifyServerless {
|
|
|
106
107
|
return serialize(lambdaResponse, classes);
|
|
107
108
|
}
|
|
108
109
|
const updatedSessionData = serialize(obj, classes);
|
|
109
|
-
if (!result || updatedSessionData !== result.sessionData)
|
|
110
|
+
if (!result || updatedSessionData !== result.sessionData || (Date.now() > (result.updated + updateDebounceInterval)))
|
|
110
111
|
sessionId = yield saveSessionData(sessionId, request.interfaceName, updatedSessionData, undefined, obj.__userId__, this.expirationMinutes);
|
|
111
112
|
// Formulate response
|
|
112
113
|
const lambdaResponse = {
|
|
@@ -239,7 +240,7 @@ export class ClassifyServerless {
|
|
|
239
240
|
this.log(`creating response for ${interfaceName} with sessionId=${sessionId} connectionId= ${obj.__connectionId__} sessionData=${sessionData}`);
|
|
240
241
|
const ret = yield callback(obj);
|
|
241
242
|
const updatedSessionData = serialize(obj, classes);
|
|
242
|
-
if (updatedSessionData !== result.sessionData ||
|
|
243
|
+
if (updatedSessionData !== result.sessionData || (Date.now() > (result.updated + updateDebounceInterval))) {
|
|
243
244
|
if (this.logLevel.calls)
|
|
244
245
|
this.log(`saving session data for ${interfaceName} with sessionId=${sessionId} connectionId= ${obj.__connectionId__} sessionData=${updatedSessionData}`);
|
|
245
246
|
yield saveSessionData(sessionId, interfaceName, updatedSessionData, undefined, undefined, this.expirationMinutes);
|
|
@@ -333,7 +334,7 @@ export function saveSessionData(sessionId, interfaceName, sessionData, connectio
|
|
|
333
334
|
const expires = new Date();
|
|
334
335
|
expires.setMinutes(expires.getMinutes() + expirationMinutes);
|
|
335
336
|
updateExpressionComponents.push('expires = :expires');
|
|
336
|
-
expressionAttributeValues[':expires'] = expires.getTime() / 1000;
|
|
337
|
+
expressionAttributeValues[':expires'] = Math.floor(expires.getTime() / 1000);
|
|
337
338
|
}
|
|
338
339
|
if (sessionData && interfaceName) {
|
|
339
340
|
updateExpressionComponents.push(`interface_${interfaceName} = :data`);
|