aws-classify-server 0.1.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/LICENSE +21 -0
- package/README.md +306 -0
- package/lib/cjs/ClassDef.d.ts +6 -0
- package/lib/cjs/ClassDef.js +2 -0
- package/lib/cjs/ClassifyResponse.d.ts +6 -0
- package/lib/cjs/ClassifyResponse.js +11 -0
- package/lib/cjs/ClassifyServerless.d.ts +27 -0
- package/lib/cjs/ClassifyServerless.js +288 -0
- package/lib/cjs/SessionData.d.ts +6 -0
- package/lib/cjs/SessionData.js +2 -0
- package/lib/cjs/aws-classify-common/EndPointsLogging.d.ts +8 -0
- package/lib/cjs/aws-classify-common/EndPointsLogging.js +11 -0
- package/lib/cjs/aws-classify-common/LambdaRequest.d.ts +6 -0
- package/lib/cjs/aws-classify-common/LambdaRequest.js +2 -0
- package/lib/cjs/aws-classify-common/LambdaResponse.d.ts +6 -0
- package/lib/cjs/aws-classify-common/LambdaResponse.js +2 -0
- package/lib/cjs/aws-classify-common/index.d.ts +4 -0
- package/lib/cjs/aws-classify-common/index.js +7 -0
- package/lib/cjs/dispatch.d.ts +7 -0
- package/lib/cjs/dispatch.js +79 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +12 -0
- package/lib/esm/ClassDef.d.ts +6 -0
- package/lib/esm/ClassDef.js +1 -0
- package/lib/esm/ClassifyResponse.d.ts +6 -0
- package/lib/esm/ClassifyResponse.js +7 -0
- package/lib/esm/ClassifyServerless.d.ts +27 -0
- package/lib/esm/ClassifyServerless.js +282 -0
- package/lib/esm/SessionData.d.ts +6 -0
- package/lib/esm/SessionData.js +1 -0
- package/lib/esm/aws-classify-common/EndPointsLogging.d.ts +8 -0
- package/lib/esm/aws-classify-common/EndPointsLogging.js +8 -0
- package/lib/esm/aws-classify-common/LambdaRequest.d.ts +6 -0
- package/lib/esm/aws-classify-common/LambdaRequest.js +1 -0
- package/lib/esm/aws-classify-common/LambdaResponse.d.ts +6 -0
- package/lib/esm/aws-classify-common/LambdaResponse.js +1 -0
- package/lib/esm/aws-classify-common/index.d.ts +4 -0
- package/lib/esm/aws-classify-common/index.js +2 -0
- package/lib/esm/dispatch.d.ts +7 -0
- package/lib/esm/dispatch.js +73 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.js +3 -0
- package/package.json +36 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ClassifyServerless } from "./index";
|
|
11
|
+
import { serialize } from "js-freeze-dry";
|
|
12
|
+
import { getSessionData, saveSessionData } from "./ClassifyServerless";
|
|
13
|
+
export const classifyServerless = new ClassifyServerless();
|
|
14
|
+
export const responseHandler = (event, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
//console.log(`dispatching`);
|
|
17
|
+
return {
|
|
18
|
+
statusCode: 200,
|
|
19
|
+
body: (yield classifyServerless.dispatch(event, context)) || "",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
//console.log(`request.body = ${event.body}`);
|
|
24
|
+
console.log(`error = ${err.message} ${err.stack}`);
|
|
25
|
+
return {
|
|
26
|
+
statusCode: 200,
|
|
27
|
+
body: serialize({
|
|
28
|
+
data: undefined,
|
|
29
|
+
exception: `Internal Server Error (${err}) - see log at ${new Date()}`,
|
|
30
|
+
cargo: undefined,
|
|
31
|
+
sessionId: undefined
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export const webSocketConnect = (event, _context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
//console.log('connecting');
|
|
38
|
+
const sessionId = event.headers['Sec-WebSocket-Protocol'] || "";
|
|
39
|
+
const connectId = event.requestContext.connectionId;
|
|
40
|
+
//console.log(JSON.stringify(event));
|
|
41
|
+
const result = yield getSessionData(sessionId); // Make sure session id passed in is valid
|
|
42
|
+
if (result) {
|
|
43
|
+
// Save connection id
|
|
44
|
+
yield saveSessionData(sessionId, undefined, undefined, connectId);
|
|
45
|
+
//console.log(`webSocketConnect session ${sessionId} connected to websocket connectId ${connectId}`);
|
|
46
|
+
return {
|
|
47
|
+
statusCode: 200,
|
|
48
|
+
headers: {
|
|
49
|
+
'Sec-WebSocket-Protocol': sessionId
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
msg: connectId,
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log(`invalid sessionId - webSocketConnect sessionId=${sessionId} connectId=${connectId}`);
|
|
58
|
+
return {
|
|
59
|
+
statusCode: 500,
|
|
60
|
+
body: 'Opps'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
export const webSocketDisconnect = (_event, _context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
//console.log('Disconnect ' + JSON.stringify(event));
|
|
66
|
+
//console.log(`webSocketDisconnect sessionId=${sessionId} connectId=${connectId}`);
|
|
67
|
+
return {
|
|
68
|
+
statusCode: 200,
|
|
69
|
+
headers: {
|
|
70
|
+
'Sec-WebSocket-Protocol': 'websocket'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
});
|
package/lib/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aws-classify-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./lib/cjs/index.js",
|
|
5
|
+
"module": "./lib/esm/index.js",
|
|
6
|
+
"types": "./lib/esm/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/lib"
|
|
9
|
+
],
|
|
10
|
+
"description": "Typescript Interface to Lambda and Websockets",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prepare": "cd tests && cd client && npm run test && cd .. && cd .. && npm run build",
|
|
13
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
14
|
+
"build:esm": "tsc",
|
|
15
|
+
"build:cjs": "tsc --module commonjs --outDir lib/cjs"
|
|
16
|
+
},
|
|
17
|
+
"repository": "https://github.com/selsamman/aws-classify",
|
|
18
|
+
"author": "Sam Elsamman",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/aws-lambda": "^8.10.103",
|
|
22
|
+
"@types/node": "^18.8.3",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
24
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
25
|
+
"aws-lambda": "^1.0.7",
|
|
26
|
+
"eslint": "8.22.0",
|
|
27
|
+
"typescript": "^4.8.2"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@aws-sdk/client-apigatewaymanagementapi": "^3.180.0",
|
|
31
|
+
"@aws-sdk/client-dynamodb": "^3.168.0",
|
|
32
|
+
"@aws-sdk/lib-dynamodb": "^3.168.0",
|
|
33
|
+
"aws-classify-common": "0.1.0",
|
|
34
|
+
"js-freeze-dry": "^1.1.4"
|
|
35
|
+
}
|
|
36
|
+
}
|