npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tweek-client

v3.2.5

Published

Tweek client for JavaScript

Downloads

29,847

Readme

Tweek Client for JavaScript

Basic usage

Install the package

npm install --save tweek-client

TweekClient

Create a client

createTweekClient(config: CreateTweekClientConfig): TweekClient

use this method to create a tweek client

const tweekClient = createTweekClient({
  baseServiceUrl: 'https://mydomain',
});

the config object accepts these properties:

| Prop | Description | Type | Default | | ------------------------ | ------------------------------------------------------ | ------------------------------------------------- | ----------- | | baseServiceUrl | Required - the url for tweek gateway | string | | context | the context to add to anu request | object | | useLegacyEndpoint | if set to true, will use v1 version of the api | boolean | false | | fetch | a fetch client to use to make the requests | (RequestInfo, RequestInit) => Promise<Response> | cross-fetch | | requestTimeoutInMillis | request timeout in ms | number | 8000 | | onError | callback to be called for request errors | (Error) => void | | getAuthenticationToken | a function that returns a token for jwt authentication | () => Promise<string> \| string | | clientId | client id for basic auth authentication | string | | clientSecret | client secret for basic auth authentication | string |

Query your configuration key and get value

tweekClient.getValues<T>(keyPath: string, config?: GetValuesConfig): Promise<T>

const myConfiguration = await tweekClient.getValues('some_key/path');

the config object accepts these properties:

| Prop | Description | Type | Default | | ---------------- | --------------------------------------------------------------------------------------------- | ---------- | ------- | | include | the keys to include in the request, used to filter scan keys | string[] | | context | override the client context | object | | flatten | if set to true the response will be in the format of a { [keyPath]: value } | boolean | false | | ignoreKeyTypes | if set to true, all the key types will be ignored and returned as strings | boolean | false | | maxChunkSize | if the include section has a lot of entries, it will split the request into multiple chunks | number | 100 |

Query configuration with key value error details

only supported on api versions 1.0-rc3 and above

tweekClient.getValuesWithDetails<T>(path: string, config?: GetValuesConfig) : Promise<DetailedTweekResult<T>>

const myDetaildConfig = await tweekClient.getValuesWithDetails('some_key/path');

the config object has the same properties as getValues

TweekManagementClient

Create a client

createTweekManagementClient(config: CreateTweekManagementClientConfig): TweekManagementClient

use this method to create a tweek management client

const tweekManagementClient = createTweekManagementClient({
  baseServiceUrl: 'https://mydomain',
});

the config object accepts these properties:

| Prop | Description | Type | Default | | ------------------------ | ------------------------------------------------------ | ------------------------------------------------- | ----------- | | baseServiceUrl | Required - the url for tweek gateway | string | | fetch | a fetch client to use to make the requests | (RequestInfo, RequestInit) => Promise<Response> | cross-fetch | | requestTimeoutInMillis | request timeout in ms | number | 8000 | | onError | callback to be called for request errors | (Error) => void | | getAuthenticationToken | a function that returns a token for jwt authentication | () => Promise<string> \| string | | clientId | client id for basic auth authentication | string | | clientSecret | client secret for basic auth authentication | string |

Updating Context

const myContext = {
  age: 23,
};

await tweekManagementClient.appendContext('user', '123456', myContext);

Using Authentication

Example:

function getAuthenticationToken() {
  return 'jwt token';
}

const tweekClient = createTweekClient({
  baseServiceUrl: 'https://mydomain',
  getAuthenticationToken,
});

getAuthenticationToken can also return a promise

function getAuthenticationToken() {
  return Promise.resolve('jwt token');
}

const tweekClient = createTweekClient({
  baseServiceUrl: 'https://mydomain',
  getAuthenticationToken,
});