Add initial serverless setup.

This commit is contained in:
Patrick Fic
2026-01-08 12:09:38 -08:00
parent b29600158a
commit 2a53f7b7d0
11 changed files with 139 additions and 11 deletions

2
.gitignore vendored
View File

@@ -17,3 +17,5 @@ macbuild.sh
deploy.ps1
# Sentry Config File
.env.sentry-build-plugin
.serverless/

View File

@@ -1,3 +1,3 @@
provider: s3
bucket: esdp
bucket: esdatapump
region: ca-central-1

View File

@@ -56,5 +56,5 @@ appImage:
npmRebuild: false
publish:
provider: s3
bucket: esdp
bucket: esdatapump
region: ca-central-1

13
serverless/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "serverless",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs"
}

73
serverless/serverless.yml Normal file
View File

@@ -0,0 +1,73 @@
service: esdp-api
app: esdp-api-app
frameworkVersion: "4"
stages:
prod:
# Enables observability in the prod stage
observability: true
# Sepcify parameter values to be used in the prod stage
params:
es_endpoint: https://insurtechtoolkit.com
domain: es.imex.online
beta:
# Enables observability in the prod stage
observability: false
# Sepcify parameter values to be used in the prod stage
params:
es_endpoint: https://4284-79073.el-alt.com
domain: beta.es.imex.online
alpha:
# Enables observability in the prod stage
observability: false
# Sepcify parameter values to be used in the prod stage
params:
es_endpoint: https://4284-79287.el-alt.com
domain: alpha.es.imex.online
dev:
# Enables observability in the prod stage
observability: false
# Sepcify parameter values to be used in the prod stage
params:
es_endpoint: https://4284-79287.el-alt.com
domain: alpha.es.imex.online
# params:
# dev:
# domain: dev.es.imex.online
# alpha:
# domain: alpha.es.imex.online
# beta:
# domain: beta.es.imex.online
# prod:
# domain: es.imex.online
provider:
name: aws
runtime: nodejs22.x
region: ca-central-1
domain: ${param:domain}
httpApi: # This creates a cheaper, faster "HTTP API" Gateway
cors: true # Automatically configures CORS
functions:
# Route 1: POST /scrub
scrub:
handler: src/handlers/scrub.handler
environment:
ES_ENDPOINT: ${param:es_endpoint}
events:
- httpApi:
path: /scrub
method: post
# Route 1: POST /scrub
emsupload:
handler: src/handlers/emsupload.handler
environment:
ES_ENDPOINT: ${param:es_endpoint}
events:
- httpApi:
path: /emsupload
method: post

View File

@@ -0,0 +1,15 @@
// You can require shared code from the lib folder
// const { dbConnect } = require('../lib/db');
exports.handler = async (event) => {
// Path parameters are automatically parsed for you
const userId = event.pathParameters.id;
return {
statusCode: 200,
body: JSON.stringify({
message: `EMS Upload Path`,
})
};
};

View File

@@ -0,0 +1,15 @@
// You can require shared code from the lib folder
// const { dbConnect } = require('../lib/db');
exports.handler = async (event) => {
// Path parameters are automatically parsed for you
return {
statusCode: 200,
body: JSON.stringify({
message: `Scrub Path`,
data: { id: 1, name: "Alice" }
})
};
};

0
serverless/src/lib/db.js Normal file
View File

View File

@@ -188,8 +188,8 @@ export interface ESJobObject extends Omit<
close_date: string | null;
created_at: string;
id: string;
group: string;
group_verified: boolean;
group?: string;
group_verified?: boolean;
updated_at: string;
v_age: number;
v_type: string;

View File

@@ -1,10 +1,14 @@
import { RawJobDataObject } from "../decoder/decoder";
import { ESJobObject } from "./es-job-object.interface";
import _ from "lodash";
import dayjas from "dayjs";
import dayjs from "dayjs";
import axios from "axios";
const sendingEntityId = "87330f61-412b-4251-baaa-d026565b23c5";
function TransformJobForEstimateScrubber(job: RawJobDataObject): ESJobObject {
async function TransformJobForEstimateScrubber(
job: RawJobDataObject,
): Promise<ESJobObject> {
//Take the job object and strip off everything we don't need.
const omittedJob = _.omit(job, [
"cat_no",
@@ -190,17 +194,23 @@ function TransformJobForEstimateScrubber(job: RawJobDataObject): ESJobObject {
//Add the ES Objects.
const vehType: string = (
await axios.post(`https://api.test.imex.online/es/vehicletype`, {
model: job.v_model_desc,
})
).data?.type;
return {
//TODO: Remove hard coded values
...omittedJob,
impact_1: job.area_of_damage?.impact1,
impact_2: job.area_of_damage?.impact2,
close_date: null,
created_at: "2025-12-11T18:09:14.085604+00:00",
created_at: dayjs().toISOString(),
id: "c478593b-58a2-4bab-b7c7-2df19a257b2b",
group: "Group 10",
group_verified: false,
updated_at: "2025-12-11T18:09:14.085604+00:00",
// group: "Group 10",
// group_verified: false,
updated_at: dayjs().toISOString(),
v_age: 20, //Needed? RPS calc.
v_type: "PC", // need to get from API.
v_makedesc: job.v_make_desc,

View File

@@ -47,7 +47,7 @@ async function ScrubEstimate({
//Scrub Estimate Transformer. Original schema kept to keep data in line with ImEX standards.
const transformedJob = TransformJobForEstimateScrubber(job);
const transformedJob = await TransformJobForEstimateScrubber(job);
const basicAuthUser = "Imex2";
const basicAuthpassword = "Patrick";
const currentChannel = autoUpdater.channel;