From 76091fa9f53a5c900fee41ef67724bfc557fbebe Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Tue, 24 Aug 2021 09:06:02 -0700 Subject: [PATCH] removed archivist writes --- .env.template | 14 ++-- package.json | 2 +- serverless.yml | 19 ++---- .../post/XyoArchivistBoundWitnessBody.ts | 8 --- src/archive/block/post/flattenArray.ts | 4 -- src/archive/block/post/index.ts | 68 ------------------- src/archive/block/post/storeBoundWitnesses.ts | 10 --- src/archive/block/post/validateBody.ts | 18 ----- 8 files changed, 12 insertions(+), 131 deletions(-) delete mode 100644 src/archive/block/post/XyoArchivistBoundWitnessBody.ts delete mode 100644 src/archive/block/post/flattenArray.ts delete mode 100644 src/archive/block/post/index.ts delete mode 100644 src/archive/block/post/storeBoundWitnesses.ts delete mode 100644 src/archive/block/post/validateBody.ts diff --git a/.env.template b/.env.template index f170c2f..0f94382 100644 --- a/.env.template +++ b/.env.template @@ -1,7 +1,7 @@ -MONGO_USERNAME= -MONGO_PASSWORD= -MONGO_DOMAIN=xyo-network.0htus -MONGO_DATABASE=archivist -DOMAIN=archivist.xyo.network -CERTIFICATE_NAME="*.archivist.xyo.network" -SERVICE_NAME=api-archivist \ No newline at end of file +ARCHIVIST_MONGO_USERNAME= +ARCHIVIST_MONGO_PASSWORD= +ARCHIVIST_MONGO_DOMAIN=xyo-network.0htus +ARCHIVIST_MONGO_DATABASE=archivist +DOMAIN=api.xyo.network +CERTIFICATE_NAME="*.xyo.network" +SERVICE_NAME=api-xyo \ No newline at end of file diff --git a/package.json b/package.json index f01e482..90fa682 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "api-archivist-nodejs", - "version": "2.0.69", + "version": "2.0.70", "description": "XYO Archivist Serverless API", "sideeffects": false, "engines": { diff --git a/serverless.yml b/serverless.yml index 0798eb0..0e33c8a 100644 --- a/serverless.yml +++ b/serverless.yml @@ -17,10 +17,10 @@ provider: runtime: nodejs14.x versionFunctions: false environment: - MONGO_USERNAME: ${env:MONGO_USERNAME} - MONGO_PASSWORD: ${env:MONGO_PASSWORD} - MONGO_DOMAIN: ${env:MONGO_DOMAIN} - MONGO_DATABASE: ${env:MONGO_DATABASE} + ARCHIVIST_MONGO_USERNAME: ${env:ARCHIVIST_MONGO_USERNAME} + ARCHIVIST_MONGO_PASSWORD: ${env:ARCHIVIST_MONGO_PASSWORD} + ARCHIVIST_MONGO_DOMAIN: ${env:ARCHIVIST_MONGO_DOMAIN} + ARCHIVIST_MONGO_DATABASE: ${env:ARCHIVIST_MONGO_DATABASE} timeout: 29 @@ -52,17 +52,6 @@ custom: stage: ${opt:stage, 'dev'} functions: - block-post: - handler: src/archive/block/post/index.entryPoint - events: - - http: - path: /archive/{archive}/block - method: POST - cors: true - - http: - path: /archive/{archive}/bw - method: POST - cors: true block-sample: handler: src/archive/block/sample/get.entryPoint events: diff --git a/src/archive/block/post/XyoArchivistBoundWitnessBody.ts b/src/archive/block/post/XyoArchivistBoundWitnessBody.ts deleted file mode 100644 index 54fa98f..0000000 --- a/src/archive/block/post/XyoArchivistBoundWitnessBody.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { XyoBoundWitness } from '@xyo-network/sdk-xyo-client-js' - -interface XyoArchivistBoundWitnessBody { - boundWitnesses: XyoBoundWitness[] - payloads?: Record[][] -} - -export default XyoArchivistBoundWitnessBody diff --git a/src/archive/block/post/flattenArray.ts b/src/archive/block/post/flattenArray.ts deleted file mode 100644 index f33cce7..0000000 --- a/src/archive/block/post/flattenArray.ts +++ /dev/null @@ -1,4 +0,0 @@ -const flattenArray = (items: T[][]) => { - return items.reduce((acc, value) => acc.concat(value), []) -} -export default flattenArray diff --git a/src/archive/block/post/index.ts b/src/archive/block/post/index.ts deleted file mode 100644 index 65761b3..0000000 --- a/src/archive/block/post/index.ts +++ /dev/null @@ -1,68 +0,0 @@ -import 'source-map-support/register' - -import { XyoBoundWitness } from '@xyo-network/sdk-xyo-client-js' -import { assertEx } from '@xyo-network/sdk-xyo-js' -import lambda from 'aws-lambda' -import dotenv from 'dotenv' - -import { - getArchivistBoundWitnessesMongoSdk, - getArchivistPayloadForwardingMongoSdk, - Result, - trapServerError, -} from '../../../lib' -import validateBody from './validateBody' - -interface XyoArchivistBoundWitnessBody { - boundWitnesses: XyoBoundWitness[] - payloads?: Record[][] -} - -const storeBoundWitnesses = async (archive: string, boundWitnesses: XyoBoundWitness[]) => { - const bwSdk = getArchivistBoundWitnessesMongoSdk(archive) - return await bwSdk.insertMany(boundWitnesses) -} - -export const entryPoint = async ( - event: lambda.APIGatewayProxyEvent, - context: lambda.Context, - callback: lambda.APIGatewayProxyCallback -) => { - const archive = assertEx(event.pathParameters?.['archive'], 'Missing archive name') - const _source_ip = event.requestContext.identity.sourceIp ?? undefined - const _user_agent = event.requestContext.identity.userAgent ?? undefined - const _timestamp = Date.now() - - await trapServerError(callback, async () => { - dotenv.config() - const body = JSON.parse(assertEx(event?.body, 'Missing post body')) as XyoArchivistBoundWitnessBody - body.boundWitnesses = body.boundWitnesses.map((bw) => { - return { ...bw, _source_ip, _timestamp, _user_agent } - }) - const validationErrors = validateBody(body) - - if (validationErrors.length > 0) { - console.log(`Error: ${validationErrors[0].message}`) - Result.BadRequest(callback, { message: validationErrors[0].message }) - } else { - let bwResult: number | undefined - let payloadsResult: number | undefined - if (body.boundWitnesses) { - bwResult = await storeBoundWitnesses(archive, body.boundWitnesses) - assertEx( - bwResult === body.boundWitnesses.length, - `Boundwitness Storage Failed [${bwResult}/${body.boundWitnesses.length}]` - ) - } - if (body.payloads) { - const payloadSdk = getArchivistPayloadForwardingMongoSdk() - payloadsResult = await payloadSdk.insertMany(assertEx(body.payloads)) - assertEx( - payloadsResult === body.payloads.length, - `Payload Storage Failed [${payloadsResult}/${body.payloads.length}]` - ) - } - return Result.Ok(callback, { boundWitnesses: bwResult, payloads: payloadsResult }) - } - }) -} diff --git a/src/archive/block/post/storeBoundWitnesses.ts b/src/archive/block/post/storeBoundWitnesses.ts deleted file mode 100644 index ad5e885..0000000 --- a/src/archive/block/post/storeBoundWitnesses.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { XyoBoundWitness } from '@xyo-network/sdk-xyo-client-js' - -import { getArchivistBoundWitnessesMongoSdk } from '../../../lib' - -const storeBoundWitnesses = async (archive: string, boundWitnesses: XyoBoundWitness[]) => { - const bwSdk = getArchivistBoundWitnessesMongoSdk(archive) - return await bwSdk.insertMany(boundWitnesses) -} - -export default storeBoundWitnesses diff --git a/src/archive/block/post/validateBody.ts b/src/archive/block/post/validateBody.ts deleted file mode 100644 index 008a827..0000000 --- a/src/archive/block/post/validateBody.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { XyoBoundWitnessWrapper } from '@xyo-network/sdk-xyo-client-js' - -import flattenArray from './flattenArray' -import XyoArchivistBoundWitnessBody from './XyoArchivistBoundWitnessBody' - -const validateBody = (body: XyoArchivistBoundWitnessBody): Error[] => { - if (Array.isArray(body.boundWitnesses)) { - const errors = body.boundWitnesses.map((bw) => { - const wrapper = new XyoBoundWitnessWrapper(bw) - return wrapper.validator.all() - }) - return flattenArray(errors) - } else { - return [Error('boundWitnesses must be array')] - } -} - -export default validateBody