4.1.2
'accedoOneWrapperForBrowsers' is the default export for browsers.
'accedoOne' is the default export for other engines (including Node.js).
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.
(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, ...) |
client
:
an Accedo One client tied to the given params
Factory function to create an instance of an Accedo One client.
You must get an instance before accessing any of the exposed client APIs.
(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) |
client
:
an Accedo One client tied to the given params
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' });
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.
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.
(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) |
promise
:
a promise of an array of entries (objects)
Get one content entry by id, based on the given parameters.
(string)
the entry id
(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) |
promise
:
a promise of an entry (object)
Get one content entry, based on the given parameters.
(object)
the entry alias
(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) |
promise
:
a promise of an entry (object)
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.
promise
:
a promise of a string, the sessionKey
Get the current application status
promise
:
a promise of the application status (string)
Lists all the assets.
promise
:
a promise of a hash of assets (key: asset name, value: asset URL)
Send a usage START event
promise
:
a promise denoting the success of the operation
Send a usage QUIT event
promise
:
a promise denoting the success of the operation
Get all the enabled plugins
promise
:
a promise of the requested data
Get the profile information
promise
:
a promise of the requested data
Get all the metadata
promise
:
a promise of the requested data
Get the metadata by a specific key
(string)
a key to get specific metadata
promise
:
a promise of the requested data
Get the metadata by specific keys
(array)
an array of keys (strings)
promise
:
a promise of the requested data
Get all the application-scope data for a given user
(string)
an Accedo One user
promise
:
a promise of the requested data
Get all the application-group-scope data for a given user
(string)
an Accedo One user
promise
:
a promise of the requested data
Get all the application-scope data for a given user and data key
promise
:
a promise of the requested data
Get all the application-group-scope data for a given user
promise
:
a promise of the requested data
Set the application-scope data for a given user
promise
:
a promise of the requested data
Set the application-group-scope data for a given user
promise
:
a promise of the requested data
Set the application-scope data for a given user
(string)
an Accedo One user
(string)
a key to specify what data to obtain
(object)
the data to store
promise
:
a promise of the requested data
Set the application-group-scope data for a given user
(string)
an Accedo One user
(string)
a key to specify what data to obtain
(object)
the data to store
promise
:
a promise of the requested data
Get all the available locales
promise
:
a promise of the requested data
Get the current log level
promise
:
a promise of the log level (string)
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.
(("debug"
| "info"
| "warn"
| "error"
))
the log level
(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 |
(any?)
extra metadata (will go through JSON.stringify).
Can be passed as any number of trailing arguments.
promise
:
a promise of the success of the operation
(queuing on browser, posting on Node.js)
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.
Name | Description |
---|---|
logs[].logType (
|
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). |
promise
:
a promise of the success of the operation