A Node JavaScript abstraction on top of distributed/cloud DBs that exposes a simple state persistence API.
You can initialize the lib with your Adobe I/O Runtime (a.k.a OpenWhisk) credentials.
Please note that currently, you must be a customer of Adobe Developer App Builder to use this library. App Builder is a complete framework that enables enterprise developers to build and deploy custom web applications that extend Adobe Experience Cloud solutions and run on Adobe infrastructure.
npm install @adobe/aio-lib-state
const stateLib = require('@adobe/aio-lib-state')
// init when running in an Adobe I/O Runtime action (OpenWhisk) (uses env vars __OW_API_KEY and __OW_NAMESPACE automatically. default region is 'amer')
const state = await stateLib.init()
// set an explicit region
const state2 = await stateLib.init({ region: 'apac' })
// get
const res = await state.get('key') // res = { value, expiration }
const value = res.value
// put
await state.put('key', 'value')
await state.put('another key', 'another value', { ttl: -1 }) // -1 for max expiry (365 days), defaults to 86400 (24 hours)
// delete
await state.delete('key')
// delete all keys and values
await state.deleteAll()
// returns true if you have at least one key and value
await state.any()
goto
API
set DEBUG=@adobe/aio-lib-state*
to see debug logs.
Apply when init with I/O Runtime credentials:
- Namespace must be in valid AppBuilder format:
amsorg-project(-workspace)?
- Max state value size:
1MB
. - Max state key size:
1024 bytes
. - Supported characters are alphanumeric and
-
,_
,.
- Max-supported TTL is 365 days.
- Default TTL is 1 day.
- when using
@adobe/aio-lib-state
in an action bundled with webpack please make sure to turn off minification and enable resolving of es6 modules. Add the following lines to your webpack config:
optimization: {
minimize: false
},
resolve: {
extensions: ['.js'],
mainFields: ['main']
}
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.