Accedo One client factory

'accedoOneWrapperForBrowsers' is the default export for browsers.

'accedoOne' is the default export for other engines (including Node.js).

accedoOneWrapperForBrowsers

A wrapper over the Accedo One factory for browsers. If Web Storage is supported, Provides default onDeviceIdGenerated and onSessionKeyChanged callbacks for persistency through Web Storage. Also sets the deviceId and sessionKey values from Web Storage to the factory when not given as an option.

This behaviour can be customised by providing a browserInfoProvider function returning an object with the keys deviceId and sessionKey. You could implement a different strategy relying on cookies or a device-specific API for instance.

If you do, you will want to customise the onSessionKeyChanged and onDeviceIdGenerated callbacks as well.

Refer to the factory's documentation to see other available options.

Note this is this library's module export for Web Storage-enabled devices.

accedoOneWrapperForBrowsers(config: object): client
Parameters
config (object) the configuration for the new instance
Name Description
config.browserInfoProvider string A function that should return an object with deviceId and sessionKey properties, saved from previous sessions (see onDeviceIdGenerated , onSessionKeyChanged )
config.appKey/log/gid/etc any? You should also pass any extra option accepted by the accedoOne factory function (appKey, log, gid, ...)
Returns
client: an Accedo One client tied to the given params

accedoOne

Factory function to create an instance of an Accedo One client.

You must get an instance before accessing any of the exposed client APIs.

accedoOne(config: object): client
Parameters
config (object) the configuration for the new instance
Name Description
config.appKey string the application Key
config.deviceId string? the device identifier (if not provided, a uuid will be generated instead)
config.sessionKey string? the sessionKey (note a new one may be created when not given or expired)
config.useSharedSession string? makes all client instances reuse the same session when truthy (useful in node environment, when using the consumer sessionKey isn't possible)
config.ip string? the user's IP, given to Accedo One for every request this client will trigger (for geolocation).
config.log function? a function to use to see this SDK's logs
config.onDeviceIdGenerated function? callback to obtain the new deviceId, if one gets generated
config.sessionKeyInQueryString boolean? when truthy, will pass sessionKey in query string instead of X-SESSION header
config.onSessionKeyChanged function? callback to obtain the sessionKey, anytime a new one gets generated
config.target string? all APIs calls will use this as the base API URL (defaults to the Accedo One API URL)
Returns
client: an Accedo One client tied to the given params
Example
const accedoOne = require('@accedo/accedo-one');

// when all info is available - use all of it !
const client = accedoOne({ appKey: 'MY_APP_KEY', deviceId: 'DEVICE_ID', sessionKey: 'SOME_SESSION_KEY' });

// when there is no known sessionKey yet
const client2 = accedoOne({ appKey: 'MY_APP_KEY', deviceId: 'DEVICE_ID' });

// when there is no known sessionKey or deviceId yet
const client3 = accedoOne({ appKey: 'MY_APP_KEY' });

Instance methods

To use those methods, call them on an instance of a client. All API calls will make use of the existing parameters on the instance (appKey, etc). Code examples can be found in the github repository.

getEntries

Get all the content entries, based on the given parameters. DO NOT use several of the id, alias, typeId and typeAlias options at the same time - behaviour would be ungaranteed.

getEntries(params: object?): promise
Parameters
params (object?) a parameters object
Name Description
params.preview boolean? when true, get the preview version
params.at (string | date)? when given, get the version at the given time
params.id array? an array of entry ids (strings)
params.gid string? used for whitelisting
params.alias array? an array of entry aliases (strings)
params.typeId array? only return entries of the given type ids (strings)
params.typeAlias string? only return entries whose entry type has this alias
params.size (number | string)? limit to that many results per page (limits as per Accedo One API, currently 1 to 50, default 20)
params.offset (number | string)? offset the result by that many pages
params.locale string? if available, get the version for the given locale (defaults to the default locale)
Returns
promise: a promise of an array of entries (objects)

getEntryById

Get one content entry by id, based on the given parameters.

getEntryById(id: string, params: object?): promise
Parameters
id (string) the entry id
params (object?) a parameters object
Name Description
params.preview boolean? when true, get the preview version
params.at (string | date)? when given, get the version at the given time
params.gid string? used for whitelisting
params.locale string? if available, get the version for the given locale (defaults to the default locale)
Returns
promise: a promise of an entry (object)

getEntryByAlias

Get one content entry, based on the given parameters.

getEntryByAlias(alias: object, params: object?): promise
Parameters
alias (object) the entry alias
params (object?) a parameters object
Name Description
params.preview boolean? when true, get the preview version
params.gid string? used for whitelisting
params.at (string | date)? when given, get the version at the given time
params.locale string? if available, get the version for the given locale (defaults to the default locale)
Returns
promise: a promise of an entry (object)

createSession

creates a session. Note you do not usually need to worry about this. Other methods will call it automatically for you when it is needed.

createSession(): promise
Returns
promise: a promise of a string, the sessionKey

getApplicationStatus

Get the current application status

getApplicationStatus(): promise
Returns
promise: a promise of the application status (string)

getAllAssets

Lists all the assets.

getAllAssets(): promise
Returns
promise: a promise of a hash of assets (key: asset name, value: asset URL)

sendUsageStartEvent

Send a usage START event

sendUsageStartEvent(): promise
Returns
promise: a promise denoting the success of the operation

sendUsageStopEvent

Send a usage QUIT event

sendUsageStopEvent(retentionTimeInSeconds: (number | string)?): promise
Parameters
retentionTimeInSeconds ((number | string)?) the retention time, in seconds
Returns
promise: a promise denoting the success of the operation

getAllEnabledPlugins

Get all the enabled plugins

getAllEnabledPlugins(): promise
Returns
promise: a promise of the requested data

getProfileInfo

Get the profile information

getProfileInfo(): promise
Returns
promise: a promise of the requested data

getAllMetadata

Get all the metadata

getAllMetadata(params: object?): promise
Parameters
params (object?) a parameters object
Name Description
params.gid string? used for whitelisting
Returns
promise: a promise of the requested data

getMetadataByKey

Get the metadata by a specific key

getMetadataByKey(key: string, params: object?): promise
Parameters
key (string) a key to get specific metadata
params (object?) a parameters object
Name Description
params.gid string? used for whitelisting
Returns
promise: a promise of the requested data

getMetadataByKeys

Get the metadata by specific keys

getMetadataByKeys(keys: array, params: object?): promise
Parameters
keys (array) an array of keys (strings)
params (object?) a parameters object
Name Description
params.gid string? used for whitelisting
Returns
promise: a promise of the requested data

getAllApplicationScopeDataByUser

Get all the application-scope data for a given user

getAllApplicationScopeDataByUser(userName: string): promise
Parameters
userName (string) an Accedo One user
Returns
promise: a promise of the requested data

getAllApplicationGroupScopeDataByUser

Get all the application-group-scope data for a given user

getAllApplicationGroupScopeDataByUser(userName: string): promise
Parameters
userName (string) an Accedo One user
Returns
promise: a promise of the requested data

getApplicationScopeDataByUserAndKey

Get all the application-scope data for a given user and data key

getApplicationScopeDataByUserAndKey(userName: string, key: string): promise
Parameters
userName (string) an Accedo One user
key (string) a key to specify what data to obtain
Returns
promise: a promise of the requested data

getApplicationGroupScopeDataByUserAndKey

Get all the application-group-scope data for a given user

getApplicationGroupScopeDataByUserAndKey(userName: string, key: string): promise
Parameters
userName (string) an Accedo One user
key (string) a key to specify what data to obtain
Returns
promise: a promise of the requested data

setApplicationScopeUserData

Set the application-scope data for a given user

setApplicationScopeUserData(userName: string, data: object): promise
Parameters
userName (string) an Accedo One user
data (object) the data to store
Returns
promise: a promise of the requested data

setApplicationGroupScopeUserData

Set the application-group-scope data for a given user

setApplicationGroupScopeUserData(userName: string, data: object): promise
Parameters
userName (string) an Accedo One user
data (object) the data to store
Returns
promise: a promise of the requested data

setApplicationScopeUserDataByKey

Set the application-scope data for a given user

setApplicationScopeUserDataByKey(userName: string, key: string, data: object): promise
Parameters
userName (string) an Accedo One user
key (string) a key to specify what data to obtain
data (object) the data to store
Returns
promise: a promise of the requested data

setApplicationGroupScopeUserDataByKey

Set the application-group-scope data for a given user

setApplicationGroupScopeUserDataByKey(userName: string, key: string, data: object): promise
Parameters
userName (string) an Accedo One user
key (string) a key to specify what data to obtain
data (object) the data to store
Returns
promise: a promise of the requested data

getAvailableLocales

Get all the available locales

getAvailableLocales(): promise
Returns
promise: a promise of the requested data

getLogLevel

Get the current log level

getLogLevel(): promise
Returns
promise: a promise of the log level (string)

sendLog

NOTE: the behaviour varies when run on Node.js or on browsers.

On Node.js, the log will be sent immediately.

On browsers: add the log to a queue so several logs may be sent as a batch, when a predefined total size is reached or after a debouncing delay. Whenever the user navigates away, the SDK will also attempt to send any queued-up log.

If the current log level is high enough, lower level logs will be ignored.

sendLog(level: ("debug" | "info" | "warn" | "error"), details: object, metadata: any?): promise
Parameters
level (("debug" | "info" | "warn" | "error")) the log level
details (object) the log information
Name Description
details.message string the log message
details.errorCode number the error code (max 5 digits)
details.dim1 string the dimension 1 information
details.dim2 string the dimension 2 information
details.dim3 string the dimension 3 information
details.dim4 string the dimension 4 information
metadata (any?) extra metadata (will go through JSON.stringify). Can be passed as any number of trailing arguments.
Returns
promise: a promise of the success of the operation (queuing on browser, posting on Node.js)

sendLogs

Send batched logs, each with its own level, timestamp, details and extra metadata. Note that on browsers, the other method, sendLog, is more convenient as it will auto-batch logs for you.

sendLogs(logs: Array<object>): promise
Parameters
logs (Array<object>) Log description objects
Name Description
logs[].logType ("debug" | "info" | "warn" | "error") the log type
logs[].timestamp (string | number) the timestamp for the log, as a UTC ISO 8601 string (ie. '2016-07-04T06:17:21Z'), or a POSIX millisecond number
logs[].message string the log message
logs[].errorCode string the error code
logs[].dim1 string the dimension 1 information
logs[].dim2 string the dimension 2 information
logs[].dim3 string the dimension 3 information
logs[].dim4 string the dimension 4 information
logs[].metadata any? extra metadata (will go through JSON.stringify).
Returns
promise: a promise of the success of the operation