0.6.4 • Published 5 years ago

@zeit/integration-utils v0.6.4

Weekly downloads
85
License
MIT
Repository
github
Last release
5 years ago

@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
0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago