feat: serverless new mint handler placeholder (#221)

* feat: add handler.

* fix: make the handler compilable.

* feat: parse json
This commit is contained in:
Shredder 2023-04-25 22:09:54 +03:30 committed by GitHub
parent 737715e1e3
commit 957219b8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 0 deletions

View File

@ -5,6 +5,8 @@ jspm_packages
# Serverless directories
.serverless
yarn-error.log
# esbuild directories
.esbuild

View File

@ -36,4 +36,12 @@ functions:
- http:
path: build
method: post
cors: true
submitMintInfo:
handler: dist/functions/mints/handler.submitMintInfo
events:
- http:
path: mint
method: post
cors: true

View File

@ -0,0 +1,45 @@
import {
APIGatewayProxyResult,
APIGatewayEvent,
///APIGatewayEventRequestContext,
} from 'aws-lambda';
import { formatJSONResponse } from '@libs/api-gateway';
import { v4 } from 'uuid';
export const submitMintInfo = async (
event: APIGatewayEvent,
///context: APIGatewayEventRequestContext
): Promise<APIGatewayProxyResult> => {
try {
const id = v4();
/**if (!verifyAlchemySig(event.headers.xalchemywork)) {
throw new Error('Invalid sig');
}**/
if (event.body == undefined) {
throw new Error('Undefined data');
}
const mintInfo = {
buildId: id,
createdAt: new Date().toISOString(),
body: JSON.parse(event.body),
};
// check if we have it in mongo
// if so, trigger verification call
// if not, add to mongo
return formatJSONResponse({
mintInfo,
});
} catch (e) {
return formatJSONResponse({
status: 500,
message: e,
});
}
};

View File

@ -0,0 +1,13 @@
import { handlerPath } from '@libs/handler-resolver';
export const newMint = {
handler: `${handlerPath(__dirname)}/handler.newMint`,
events: [
{
http: {
method: 'post',
path: 'mint',
},
},
],
};