1.1.0 • Published 16 days ago

@vercel/edge-config v1.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
16 days ago

@vercel/edge-config

CI Edge Runtime Compatible

A client that lets you read Edge Config.

Examples

You can use the methods below to read your Edge Config given you have its Connection String stored in an Environment Variable called process.env.EDGE_CONFIG.

Reading a value

import { get } from '@vercel/edge-config';
await get('someKey');

Returns the value if the key exists. Returns undefined if the key does not exist. Throws on invalid tokens, deleted edge configs or network errors.

Checking if a key exists

import { has } from '@vercel/edge-config';
await has('someKey');

Returns true if the key exists. Returns false if the key does not exist. Throws on invalid tokens, deleted edge configs or network errors.

Reading all items

import { getAll } from '@vercel/edge-config';
await getAll();

Returns all Edge Config items. Throws on invalid tokens, deleted edge configs or network errors.

Reading items in batch

import { getAll } from '@vercel/edge-config';
await getAll(['keyA', 'keyB']);

Returns selected Edge Config items. Throws on invalid tokens, deleted edge configs or network errors.

Default behaviour

By default @vercel/edge-config will read from the Edge Config stored in process.env.EDGE_CONFIG.

The exported get, getAll, has and digest functions are bound to this default Edge Config Client.

Reading a value from a specific Edge Config

You can use createClient(connectionString) to read values from Edge Configs other than the default one.

import { createClient } from '@vercel/edge-config';
const edgeConfig = createClient(process.env.ANOTHER_EDGE_CONFIG);
await edgeConfig.get('someKey');

The createClient function connects to a any Edge Config based on the provided Connection String.

It returns the same get, getAll, has and digest functions as the default Edge Config Client exports.

Features

Error Handling

  • An error is thrown in case of a network error
  • An error is thrown in case of an unexpected response

Edge Runtime Support

@vercel/edge-config is compatible with the Edge Runtime. It can be used inside environments like Vercel Edge Functions as follows:

// Next.js (pages/api/edge.js) (npm i next@canary)
// Other frameworks (api/edge.js) (npm i -g vercel@canary)

import { get } from '@vercel/edge-config';

export default (req) => {
  const value = await get("someKey")
  return new Response(`someKey contains value "${value})"`);
};

export const config = { runtime: 'edge' };

Caught a Bug?

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Link the package to the global module directory: npm link
  3. Within the module you want to test your local development instance of @vercel/edge-config, just link it to the dependencies: npm link @vercel/edge-config. Instead of the default one from npm, Node.js will now use your clone of @vercel/edge-config!

As always, you can run the tests using: npm test

1.1.0

2 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

0.3.0

8 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.1.11

12 months ago

0.2.1

11 months ago

0.2.0

12 months ago

0.1.11-canary.1

12 months ago

0.1.11-canary.0

12 months ago

0.1.10

1 year ago

0.1.6-canary.0

1 year ago

0.1.8-canary.0

1 year ago

0.1.2

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.5-canary.0

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.0-canary.10

2 years ago

0.1.0-canary.11

2 years ago

0.1.0-canary.12

2 years ago

0.1.0

1 year ago

0.1.0-canary.5

2 years ago

0.1.0-canary.4

2 years ago

0.1.0-canary.3

2 years ago

0.1.1

1 year ago

0.1.0-canary.2

2 years ago

0.1.0-canary.13

2 years ago

0.1.0-canary.9

2 years ago

0.1.0-canary.14

2 years ago

0.1.0-canary.8

2 years ago

0.1.0-canary.15

1 year ago

0.1.0-canary.7

2 years ago

0.1.0-canary.6

2 years ago

0.1.0-canary.0

2 years ago