UNPKG

@moicky/dynamodb

Version:

Contains a collection of convenience functions for working with AWS DynamoDB

32 lines (31 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClient = exports.initClient = void 0; const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); const oidc_1 = require("@vercel/functions/oidc"); const schemas_1 = require("./schemas"); const authType = process.env.MOICKY_DYNAMODB_AWS_ROLE; const roleArn = process.env.AWS_ROLE_ARN; let client = new client_dynamodb_1.DynamoDBClient({ region: process.env.AWS_REGION || "eu-central-1", ...(authType === "vercel" && roleArn && { credentials: (0, oidc_1.awsCredentialsProvider)({ roleArn }) }), }); const defaultTable = process.env.DYNAMODB_TABLE; if (defaultTable) { (0, schemas_1.initSchema)({ [defaultTable]: (0, schemas_1.getDefaultTableSchema)() }); } /** * Initializes the {@link DynamoDBClient} to use for all operations. * @param newClient - The new {@link DynamoDBClient} to use */ const initClient = (newClient) => { client = newClient; }; exports.initClient = initClient; /** * Returns the current {@link DynamoDBClient} used for all operations. * @returns The current {@link DynamoDBClient} */ const getClient = () => client; exports.getClient = getClient;