JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 31
  • Score
    100M100P100Q69457F
  • License MIT

A set of utlities for ZEIT Integrtions

Package Exports

  • @zeit/integration-utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@zeit/integration-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@zeit/integration-utils

npm install size cicleci codecov

A set of utilies for ZEIT Integrations.
Vist https://zeit.co/docs/integrations for more details.

Install

yarn add @zeit/integrations

Middleware for Micro / Now v2

This middleware helps to write UiHook for ZEIT integrations easily.

const {withUiHook} = require('@zeit/integration-utils');

module.exports = withUiHook(async (options) => {
    const {payload, zeitClient} = options;
    const {action, clientState} = payload;
    let metadata = await zeitClient.getMetadata();

    if (action === 'submit') {
        metadata = clientState;
        await zeitClient.setMetadata(metadata);
    }

    if (action === 'reset') {
        metadata = {};
        await zeitClient.setMetadata(metadata);
    }

    return `
        <Page>
            <Container>
                <Input label="Secret Id" name="secretId" value="${metadata.secretId || ''}"/>
                <Input label="Secret Key" name="secretKey" type="password" value="${metadata.secretKey || ''}" />
            </Container>
            <Container>
                <Button action="submit">Submit</Button>
                <Button action="reset">Reset</Button>
            </Container>
        </Page>
    `;
});

This middleware calls the handler with an object containing following entities:

  • payload - the information related uiHook
  • zeitClient - initialized API client for ZEIT with some helpers