@zeit/addons
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@zeit/addons

npm install size cicleci codecov

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

Install

yarn add @zeit/addons

Middleware for Micro / Now v2

This middleware helps to write UiHook for ZEIT addons easily.

const {withUiHook} = require('@zeit/addons');

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

Readme

Keywords

none

Package Sidebar

Install

npm i @zeit/addons

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

9.01 kB

Total Files

8

Last publish

Collaborators

  • gdborton
  • matheuss
  • matt.straka
  • nick.tracey
  • zeit-bot
  • vercel-release-bot