3.2.5 • Published 2 years ago

tweek-client v3.2.5

Weekly downloads
9,249
License
MIT
Repository
github
Last release
2 years ago

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:

PropDescriptionTypeDefault
baseServiceUrlRequired - the url for tweek gatewaystring
contextthe context to add to anu requestobject
useLegacyEndpointif set to true, will use v1 version of the apibooleanfalse
fetcha fetch client to use to make the requests(RequestInfo, RequestInit) => Promise<Response>cross-fetch
requestTimeoutInMillisrequest timeout in msnumber8000
onErrorcallback to be called for request errors(Error) => void
getAuthenticationTokena function that returns a token for jwt authentication() => Promise<string> \| string
clientIdclient id for basic auth authenticationstring
clientSecretclient secret for basic auth authenticationstring

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:

PropDescriptionTypeDefault
includethe keys to include in the request, used to filter scan keysstring[]
contextoverride the client contextobject
flattenif set to true the response will be in the format of a { keyPath: value }booleanfalse
ignoreKeyTypesif set to true, all the key types will be ignored and returned as stringsbooleanfalse
maxChunkSizeif the include section has a lot of entries, it will split the request into multiple chunksnumber100

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:

PropDescriptionTypeDefault
baseServiceUrlRequired - the url for tweek gatewaystring
fetcha fetch client to use to make the requests(RequestInfo, RequestInit) => Promise<Response>cross-fetch
requestTimeoutInMillisrequest timeout in msnumber8000
onErrorcallback to be called for request errors(Error) => void
getAuthenticationTokena function that returns a token for jwt authentication() => Promise<string> \| string
clientIdclient id for basic auth authenticationstring
clientSecretclient secret for basic auth authenticationstring

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,
});
3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.2.1-rc1

3 years ago

2.2.1-rc0

4 years ago

2.2.0

4 years ago

2.1.4

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-rc7

5 years ago

1.0.0-rc6

5 years ago

1.0.0-rc5

5 years ago

1.0.0-rc4

5 years ago

1.0.0-rc3

5 years ago

1.0.0-rc2

5 years ago

1.0.0-rc1

5 years ago

1.0.0-rc0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago