Socket
Socket
Sign inDemoInstall

mockci

Package Overview
Dependencies
8
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mockci

This is the npm package to use the MockCI API.


Version published
Weekly downloads
8
increased by700%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

MockCI npm package

This is the npm package to use the MockCI API.

MockCI creates a DynamoDB compatible endpoint that you can use and throwaway. This allows you to test all you DynamoDB related code locally with minimal changes.

install:

npm install mockci
# or
yarn add mockci

example usage:

import { MockCIPrefab, MockCISession } from 'mockci'
import { DynamoDBClient, ScanCommand, ScanCommandInput } from "@aws-sdk/client-dynamodb";

type DynamoDBItem = {
    id: string
    value: string
}

async function generateDdbEndpoint() {
    const prefab: MockCIPrefab = {
        "dynamodb": {
            "tables": [
                {
                    "seedData": [
                        {
                            "id": generateName(),
                            "value": "seeded value"
                        }
                    ],
                    "name": "generic-table",
                    "attributes": [
                        { "name": "id", "type": "S" },
                    ],
                    "hashKey": "id"
                }
            ]
        }
    }
    const endpointBlob = await MockCISession.start({ prefab })
    return endpointBlob.dynamodbEndpoint
}

async function listDDBItems(ddbClient: DynamoDBClient): Promise<DynamoDBItem[]> {
    const params: ScanCommandInput = {
        TableName: 'generic-table',
    }
    const data = await ddbClient.send(new ScanCommand(params));
    return data.Items.map((element) => ({
        id: element.id.S,
        value: element.value.S,
    }))
}

//this is optional, you can try out the DynamoDB mock without using an API key,
//if you reach the api limits of anonymous sessions,
//head to [the [MockCI]()](https://mockci.cloud/signup) website to get a free API key.
MockCISession.setAPIKey('YOUR_API_KEY_HERE')

generateDdbEndpoint()
.then((endpoint) => {
    let ddbClient = new DynamoDBClient({
        region: 'us-east-1',
        endpoint,
        credentials: {
            //if you're in the browser this is required (but can be any value)
            //if you're in Node and have a local AWS profile configure, this is optional
            accessKeyId: 'anyvalueworks',
            secretAccessKey: 'anyvalueworks',
        }
    })
    return listDDBItems(ddbClient)
})
.then(console.log)

Keywords

FAQs

Last updated on 09 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc