Skip to content

Commit

Permalink
feat(api-prerendering-service): DynamoDB storage operations with upgr…
Browse files Browse the repository at this point in the history
…ade (#1996)
  • Loading branch information
brunozoric committed Nov 1, 2021
1 parent ad30d3c commit 1d3602e
Show file tree
Hide file tree
Showing 83 changed files with 4,511 additions and 1,270 deletions.
2 changes: 1 addition & 1 deletion api/code/graphql/jest.config.js
Expand Up @@ -16,7 +16,7 @@ if (TEST_TYPE !== "unit") {
log.info(`${log.info.hl("api/code/graphql")}: Assigning environment variables...`);
const stackOutput = getStackOutput({ folder: "api", env: DEPLOY_ENVIRONMENT });

if (stackOutput) {
if (stackOutput && Object.keys(stackOutput).length > 0) {
// Assign received values as environment variables.
Object.assign(process.env, {
// We assign `region`, `dynamoDbTable`, and `apiUrl` as AWS_REGION, DB_TABLE, and API_URL
Expand Down
2 changes: 1 addition & 1 deletion api/code/headlessCMS/jest.config.js
Expand Up @@ -16,7 +16,7 @@ if (TEST_TYPE !== "unit") {
log.info(`${log.info.hl("api/code/headlessCMS")}: Assigning environment variables...`);
const stackOutput = getStackOutput({ folder: "api", env: DEPLOY_ENVIRONMENT });

if (stackOutput) {
if (stackOutput && Object.keys(stackOutput).length > 0) {
// Assign received values as environment variables.
Object.assign(process.env, {
// We assign `region`, `dynamoDbTable`, and `apiUrl` as AWS_REGION, DB_TABLE, and API_URL
Expand Down
3 changes: 1 addition & 2 deletions api/code/prerenderingService/flush/package.json
Expand Up @@ -8,10 +8,9 @@
"dependencies": {
"@webiny/api-prerendering-service": "^5.16.0",
"@webiny/api-prerendering-service-aws": "^5.16.0",
"@webiny/api-prerendering-service-so-ddb": "5.16.0",
"@webiny/cli": "^5.16.0",
"@webiny/db-dynamodb": "^5.16.0",
"@webiny/handler-aws": "^5.16.0",
"@webiny/handler-db": "^5.16.0",
"@webiny/handler-logs": "^5.16.0",
"@webiny/project-utils": "^5.16.0"
}
Expand Down
32 changes: 17 additions & 15 deletions api/code/prerenderingService/flush/src/index.ts
@@ -1,22 +1,24 @@
import { DocumentClient } from "aws-sdk/clients/dynamodb";
import { createHandler } from "@webiny/handler-aws";
import dbPlugins from "@webiny/handler-db";
import { DynamoDbDriver } from "@webiny/db-dynamodb";
import flushPlugins from "@webiny/api-prerendering-service/flush";
import flushAwsPlugins from "@webiny/api-prerendering-service-aws/flush";
import logsPlugins from "@webiny/handler-logs";
import { createPrerenderingServiceStorageOperations } from "@webiny/api-prerendering-service-so-ddb";

export const handler = createHandler(
logsPlugins(),
flushPlugins(),
flushAwsPlugins(),
dbPlugins({
table: process.env.DB_TABLE,
driver: new DynamoDbDriver({
documentClient: new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
const documentClient = new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
});
export const handler = createHandler({
plugins: [
logsPlugins(),
flushPlugins({
storageOperations: createPrerenderingServiceStorageOperations({
documentClient,
table: table => ({ ...table, name: process.env.DB_TABLE })
})
})
})
);
}),
flushAwsPlugins()
],
http: { debug: process.env.DEBUG === "true" }
});
6 changes: 3 additions & 3 deletions api/code/prerenderingService/flush/tsconfig.json
Expand Up @@ -8,13 +8,13 @@
"path": "../../../../packages/api-prerendering-service-aws"
},
{
"path": "../../../../packages/handler-aws"
"path": "../../../../packages/api-prerendering-service-so-ddb"
},
{
"path": "../../../../packages/handler-logs"
"path": "../../../../packages/handler-aws"
},
{
"path": "../../../../packages/db-dynamodb"
"path": "../../../../packages/handler-logs"
}
]
}
3 changes: 1 addition & 2 deletions api/code/prerenderingService/queue/add/package.json
Expand Up @@ -7,10 +7,9 @@
},
"dependencies": {
"@webiny/api-prerendering-service": "^5.16.0",
"@webiny/api-prerendering-service-so-ddb": "5.16.0",
"@webiny/cli": "^5.16.0",
"@webiny/db-dynamodb": "^5.16.0",
"@webiny/handler-aws": "^5.16.0",
"@webiny/handler-db": "^5.16.0",
"@webiny/handler-logs": "^5.16.0",
"@webiny/project-utils": "^5.16.0"
}
Expand Down
28 changes: 15 additions & 13 deletions api/code/prerenderingService/queue/add/src/index.ts
@@ -1,20 +1,22 @@
import { DocumentClient } from "aws-sdk/clients/dynamodb";
import { createHandler } from "@webiny/handler-aws";
import dbPlugins from "@webiny/handler-db";
import { DynamoDbDriver } from "@webiny/db-dynamodb";
import queueAddPlugins from "@webiny/api-prerendering-service/queue/add";
import logsPlugins from "@webiny/handler-logs";
import { createPrerenderingServiceStorageOperations } from "@webiny/api-prerendering-service-so-ddb";

export const handler = createHandler(
logsPlugins(),
queueAddPlugins(),
dbPlugins({
table: process.env.DB_TABLE,
driver: new DynamoDbDriver({
documentClient: new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
const documentClient = new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
});
export const handler = createHandler({
plugins: [
logsPlugins(),
queueAddPlugins({
storageOperations: createPrerenderingServiceStorageOperations({
documentClient,
table: table => ({ ...table, name: process.env.DB_TABLE })
})
})
})
);
],
http: { debug: process.env.DEBUG === "true" }
});
6 changes: 3 additions & 3 deletions api/code/prerenderingService/queue/add/tsconfig.json
Expand Up @@ -5,13 +5,13 @@
"path": "../../../../../packages/api-prerendering-service"
},
{
"path": "../../../../../packages/handler-aws"
"path": "../../../../../packages/api-prerendering-service-so-ddb"
},
{
"path": "../../../../../packages/handler-logs"
"path": "../../../../../packages/handler-aws"
},
{
"path": "../../../../../packages/db-dynamodb"
"path": "../../../../../packages/handler-logs"
}
]
}
3 changes: 1 addition & 2 deletions api/code/prerenderingService/queue/process/package.json
Expand Up @@ -7,10 +7,9 @@
},
"dependencies": {
"@webiny/api-prerendering-service": "^5.16.0",
"@webiny/api-prerendering-service-so-ddb": "5.16.0",
"@webiny/cli": "^5.16.0",
"@webiny/db-dynamodb": "^5.16.0",
"@webiny/handler-aws": "^5.16.0",
"@webiny/handler-db": "^5.16.0",
"@webiny/handler-logs": "^5.16.0",
"@webiny/project-utils": "^5.16.0"
}
Expand Down
37 changes: 19 additions & 18 deletions api/code/prerenderingService/queue/process/src/index.ts
@@ -1,25 +1,26 @@
import { DocumentClient } from "aws-sdk/clients/dynamodb";
import { createHandler } from "@webiny/handler-aws";
import dbPlugins from "@webiny/handler-db";
import { DynamoDbDriver } from "@webiny/db-dynamodb";
import queueProcessPlugins from "@webiny/api-prerendering-service/queue/process";
import logsPlugins from "@webiny/handler-logs";
import { createPrerenderingServiceStorageOperations } from "@webiny/api-prerendering-service-so-ddb";

export const handler = createHandler(
logsPlugins(),
queueProcessPlugins({
handlers: {
render: process.env.PRERENDERING_RENDER_HANDLER,
flush: process.env.PRERENDERING_FLUSH_HANDLER
}
}),
dbPlugins({
table: process.env.DB_TABLE,
driver: new DynamoDbDriver({
documentClient: new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
const documentClient = new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
});
export const handler = createHandler({
plugins: [
logsPlugins(),
queueProcessPlugins({
handlers: {
render: process.env.PRERENDERING_RENDER_HANDLER,
flush: process.env.PRERENDERING_FLUSH_HANDLER
},
storageOperations: createPrerenderingServiceStorageOperations({
documentClient,
table: table => ({ ...table, name: process.env.DB_TABLE })
})
})
})
);
],
http: { debug: process.env.DEBUG === "true" }
});
3 changes: 3 additions & 0 deletions api/code/prerenderingService/queue/process/tsconfig.json
Expand Up @@ -4,6 +4,9 @@
{
"path": "../../../../../packages/api-prerendering-service"
},
{
"path": "../../../../../packages/api-prerendering-service-so-ddb"
},
{
"path": "../../../../../packages/handler-aws"
},
Expand Down
3 changes: 1 addition & 2 deletions api/code/prerenderingService/render/package.json
Expand Up @@ -8,10 +8,9 @@
"dependencies": {
"@webiny/api-prerendering-service": "^5.16.0",
"@webiny/api-prerendering-service-aws": "^5.16.0",
"@webiny/api-prerendering-service-so-ddb": "5.16.0",
"@webiny/cli": "^5.16.0",
"@webiny/db-dynamodb": "^5.16.0",
"@webiny/handler-aws": "^5.16.0",
"@webiny/handler-db": "^5.16.0",
"@webiny/handler-logs": "^5.16.0",
"@webiny/project-utils": "^5.16.0"
}
Expand Down
32 changes: 17 additions & 15 deletions api/code/prerenderingService/render/src/index.ts
@@ -1,22 +1,24 @@
import { DocumentClient } from "aws-sdk/clients/dynamodb";
import { createHandler } from "@webiny/handler-aws";
import dbPlugins from "@webiny/handler-db";
import { DynamoDbDriver } from "@webiny/db-dynamodb";
import renderPlugins from "@webiny/api-prerendering-service/render";
import renderAwsPlugins from "@webiny/api-prerendering-service-aws/render";
import logsPlugins from "@webiny/handler-logs";
import { createPrerenderingServiceStorageOperations } from "@webiny/api-prerendering-service-so-ddb";

export const handler = createHandler(
logsPlugins(),
renderPlugins(),
renderAwsPlugins(),
dbPlugins({
table: process.env.DB_TABLE,
driver: new DynamoDbDriver({
documentClient: new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
const documentClient = new DocumentClient({
convertEmptyValues: true,
region: process.env.AWS_REGION
});
export const handler = createHandler({
plugins: [
logsPlugins(),
renderPlugins({
storageOperations: createPrerenderingServiceStorageOperations({
documentClient,
table: table => ({ ...table, name: process.env.DB_TABLE })
})
})
})
);
}),
renderAwsPlugins()
],
http: { debug: process.env.DEBUG === "true" }
});
3 changes: 3 additions & 0 deletions api/code/prerenderingService/render/tsconfig.json
Expand Up @@ -7,6 +7,9 @@
{
"path": "../../../../packages/api-prerendering-service-aws"
},
{
"path": "../../../../packages/api-prerendering-service-so-ddb"
},
{
"path": "../../../../packages/handler-aws"
},
Expand Down
Expand Up @@ -33,7 +33,8 @@ class FormBuilderTestEnvironment extends NodeEnvironment {
await super.setup();

const elasticsearchClient = createElasticsearchClient({
node: `http://localhost:${ELASTICSEARCH_PORT}`
node: `http://localhost:${ELASTICSEARCH_PORT}`,
auth: {}
});
const documentClient = new DocumentClient({
convertEmptyValues: true,
Expand All @@ -43,10 +44,8 @@ class FormBuilderTestEnvironment extends NodeEnvironment {
accessKeyId: "test",
secretAccessKey: "test"
});
const elasticsearchClientContext = createElasticsearchClientContextPlugin({
endpoint: `http://localhost:${ELASTICSEARCH_PORT}`,
auth: {}
});
const elasticsearchClientContext =
createElasticsearchClientContextPlugin(elasticsearchClient);

/**
* Intercept DocumentClient operations and trigger dynamoToElastic function (almost like a DynamoDB Stream trigger)
Expand Down
6 changes: 5 additions & 1 deletion packages/api-headless-cms/__tests__/utils/tenancySecurity.ts
Expand Up @@ -44,7 +44,11 @@ export const createTenancyAndSecurity = ({ setupGraphQL, permissions, identity }
}),
setupGraphQL ? createSecurityGraphQL() : null,
new ContextPlugin<Context>(context => {
context.tenancy.setCurrentTenant({ id: "root", name: "Root" });
context.tenancy.setCurrentTenant({
id: "root",
name: "Root",
webinyVersion: context.WEBINY_VERSION
});

context.security.addAuthenticator(async () => {
return (
Expand Down
3 changes: 2 additions & 1 deletion packages/api-headless-cms/__tests__/utils/useGqlHandler.ts
Expand Up @@ -83,7 +83,8 @@ export const useGqlHandler = (args?: GQLHandlerCallableArgs) => {
type: "admin"
},
description: "test",
createdOn: new Date().toISOString()
createdOn: new Date().toISOString(),
webinyVersion: context.WEBINY_VERSION
};
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/api-prerendering-service-so-ddb/.babelrc.js
@@ -0,0 +1 @@
module.exports = require("../../.babel.node")({ path: __dirname });

0 comments on commit 1d3602e

Please sign in to comment.