new EvolvClient(opts)
The EvolvClient provides a low level integration with the Evolv participant APIs.
The client provides asynchronous access to key states, values, contexts, and configurations.
Parameters:
| Name | Type | Description |
|---|---|---|
opts |
Partial.<EvolvClientOptions> |
An object of options for the client. |
Members
(inner, constant) beaconOptions :Partial.<EmitterOptions>
Methods
allowEvents()
If the client was configured with bufferEvents: true then calling this will allow data to be sent back to Evolv
clearActiveKeys(prefix)
Clears the active keys to reset the key states.
Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
String |
The prefix of the keys clear. |
confirm()
Confirm that the consumer has successfully received and applied values, making them eligible for inclusion in optimization statistics.
contaminate(details, allExperiments)
Marks a consumer as unsuccessfully retrieving and / or applying requested values, making them ineligible for inclusion in optimization statistics.
Parameters:
| Name | Type | Description |
|---|---|---|
details |
Object |
Optional. Information on the reason for contamination. If provided, the object should contain a reason. Optionally, a 'details' value should be included for extra debugging info |
allExperiments |
boolean |
If true, the user will be excluded from all optimizations, including optimization not applicable to this page |
destroy()
Destroy the client and its dependencies.
emit(type, metadata, flush)
Send an event to the events endpoint.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
String |
The type associated with the event. |
metadata |
Object |
Any metadata to attach to the event. |
flush |
Boolean |
If true, the event will be sent immediately. |
flush()
Force all beacons to transmit.
get(key) → {SubscribablePromise.<(*|Error)>}
Get the value of a specified key.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String |
The key of the value to retrieve. |
getActiveKeys(prefix) → {SubscribablePromise.<(Object|Error)>}
Check all active keys that start with the specified prefix.
Parameters:
| Name | Type | Description |
|---|---|---|
prefix |
String |
The prefix of the keys to check. |
getConfig(key) → {SubscribablePromise.<(*|Error)>}
Get the configuration for a specified key.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String |
The key to retrieve the configuration for. |
initialize(uid, sid, remoteContext, localContext)
Initializes the client with required context information.
Parameters:
| Name | Type | Description |
|---|---|---|
uid |
String |
A globally unique identifier for the current participant. |
sid |
String |
A globally unique session identifier for the current participant. |
remoteContext |
Object |
A map of data used for evaluating context predicates and analytics. |
localContext |
Object |
A map of data used only for evaluating context predicates. |
isActive(key) → {SubscribablePromise.<(Boolean|Error)>}
Check if a specified key is currently active.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String |
The key to check. |
on(topic, listener)
Add listeners to lifecycle events that take place in to client.
Currently supported events:
- "initialized" - Called when the client is fully initialized and ready for use with (topic, options)
- "context.initialized" - Called when the context is fully initialized and ready for use with (topic, updated_context)
- "context.changed" - Called whenever a change is made to the context values with (topic, updated_context)
- "context.value.removed" - Called when a value is removed from context with (topic, key, updated_context)
- "context.value.added" - Called when a new value is added to the context with (topic, key, value, local, updated_context)
- "context.value.changed" - Called when a value is changed in the context (topic, key, value, before, local, updated_context)
- "context.destroyed" - Called when the context is destroyed with (topic, context)
- "genome.request.sent" - Called when a request for a genome is sent with (topic, requested_keys)
- "config.request.sent" - Called when a request for a config is sent with (topic, requested_keys)
- "genome.request.received" - Called when the result of a request for a genome is received (topic, requested_keys)
- "config.request.received" - Called when the result of a request for a config is received (topic, requested_keys)
- "request.failed" - Called when a request fails (topic, source, requested_keys, error)
- "genome.updated" - Called when the stored genome is updated (topic, allocation_response)
- "config.updated" - Called when the stored config is updated (topic, config_response)
- "effective.genome.updated" - Called when the effective genome is updated (topic, effectiveGenome)
- "store.destroyed" - Called when the store is destroyed (topic, store)
- "confirmed" - Called when the consumer is confirmed (topic)
- "contaminated" - Called when the consumer is contaminated (topic)
- "event.emitted" - Called when an event is emitted through the beacon (topic, type, score)
Parameters:
| Name | Type | Description |
|---|---|---|
topic |
String |
The event topic on which the listener should be invoked. |
listener |
function |
The listener to be invoked for the specified topic. |
- Source:
- See:
-
- EvolvClient#once for listeners that should only be invoked once.
once(topic, listener)
Add a listener to a lifecycle event to be invoked once on the next instance of the event to take place in to client.
See the "on" function for supported events.
Parameters:
| Name | Type | Description |
|---|---|---|
topic |
String |
The event topic on which the listener should be invoked. |
listener |
function |
The listener to be invoked for the specified topic. |
- Source:
- See:
-
- EvolvClient#on for listeners that should be invoked on each event.
preload(prefixes, configOnly, immediate)
Preload all keys under under the specified prefixes.
Parameters:
| Name | Type | Description |
|---|---|---|
prefixes |
Array.<String> |
A list of prefixes to keys to load. |
configOnly |
Boolean |
If true, only the config would be loaded. (default: false) |
immediate |
Boolean |
Forces the requests to the server. (default: false) |
reevaluateContext()
Reevaluates the current context.