diff --git a/README.md b/README.md index b83ad00..c2b7068 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ +# Adobe I/O Lib State + [![Version](https://img.shields.io/npm/v/@adobe/aio-lib-state.svg)](https://npmjs.org/package/@adobe/aio-lib-state) [![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-state.svg)](https://npmjs.org/package/@adobe/aio-lib-state) ![Node.js CI](https://github.com/adobe/aio-lib-state/workflows/Node.js%20CI/badge.svg) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-state/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-state/) -# Adobe I/O Lib State - 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. -Alternatively, you can bring your own cloud db keys. As of now we only support Azure Cosmos. - Please note that currently you must be a customer of [Adobe Developer App Builder](https://www.adobe.io/apis/experienceplatform/project-firefly.html) 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. ## Install @@ -39,8 +37,6 @@ npm install @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) const state = await stateLib.init() - // or if you want to use your own cloud DB account (make sure your partition key path is /partitionKey) - const state = await stateLib.init({ cosmos: { endpoint, masterKey, databaseId, containerId, partitionKey } }) // get const res = await state.get('key') // res = { value, expiration } @@ -48,10 +44,16 @@ npm install @adobe/aio-lib-state // put await state.put('key', 'value') - await state.put('key', { anObject: 'value' }, { ttl: -1 }) // -1 for no expiry, defaults to 86400 (24 hours) + await state.put('another key', 'another value', { ttl: -1 }) // -1 for no expiry, 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() ``` ## Explore diff --git a/doc/api.md b/doc/api.md index 2a1b248..5e629ae 100644 --- a/doc/api.md +++ b/doc/api.md @@ -1,7 +1,7 @@ ## Classes
-
StateStore
+
AdobeState

Cloud State Management

@@ -9,12 +9,14 @@ ## Functions
-
init([config])Promise.<StateStore>
+
validate(schema, data)object
+

Validates json according to a schema.

+
+
init([config])Promise.<AdobeState>

Initializes and returns the key-value-store SDK.

To use the SDK you must either provide your OpenWhisk credentials in -config.ow or your own -Azure Cosmos credentials in config.cosmos.

+config.ow or your own

OpenWhisk credentials can also be read from environment variables __OW_NAMESPACE and __OW_API_KEY.

@@ -22,215 +24,179 @@ ## Typedefs
-
OpenWhiskCredentials : object
-

An object holding the OpenWhisk credentials

+
AdobeStateCredentials : object
+

AdobeStateCredentials

-
AzureCosmosPartitionResourceCredentials : object
-

An object holding the Azure Cosmos resource credentials with permissions on a single partition and container

+
AdobeStatePutOptions : object
+

AdobeState put options

-
AzureCosmosMasterCredentials : object
-

An object holding the Azure Cosmos account master key

+
AdobeStateGetReturnValue : object
+

AdobeState get return object

-
StateStorePutOptions : object
-

StateStore put options

-
-
StateStoreGetReturnValue : object
-

StateStore get return object

+
OpenWhiskCredentials : object
+

An object holding the OpenWhisk credentials

-
StateLibError : Object
+
AdobeStateLibError : object
-
StateLibErrors : object
-

State lib custom errors. +

AdobeStateLibErrors : object
+

Adobe State lib custom errors. e.sdkDetails provides additional context for each error (e.g. function parameter)

- + -## *StateStore* +## *AdobeState* Cloud State Management **Kind**: global abstract class -* *[StateStore](#StateStore)* - * *[.get(key)](#StateStore+get) ⇒ [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue)* - * *[.put(key, value, [options])](#StateStore+put) ⇒ Promise.<string>* - * *[.delete(key)](#StateStore+delete) ⇒ Promise.<string>* - * *[._get(key)](#StateStore+_get) ⇒ [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue)* - * *[._put(key, value, options)](#StateStore+_put) ⇒ Promise.<string>* - * *[._delete(key)](#StateStore+_delete) ⇒ Promise.<string>* +* *[AdobeState](#AdobeState)* + * *[.get(key)](#AdobeState+get) ⇒ [Promise.<AdobeStateGetReturnValue>](#AdobeStateGetReturnValue)* + * *[.put(key, value, [options])](#AdobeState+put) ⇒ Promise.<string>* + * *[.delete(key)](#AdobeState+delete) ⇒ Promise.<string>* + * *[.deleteAll()](#AdobeState+deleteAll) ⇒ Promise.<boolean>* + * *[.any()](#AdobeState+any) ⇒ Promise.<boolean>* - + -### *stateStore.get(key) ⇒ [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue)* +### *adobeState.get(key) ⇒ [Promise.<AdobeStateGetReturnValue>](#AdobeStateGetReturnValue)* Retrieves the state value for given key. If the key doesn't exist returns undefined. -**Kind**: instance method of [StateStore](#StateStore) -**Returns**: [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue) - get response holding value and additional info +**Kind**: instance method of [AdobeState](#AdobeState) +**Returns**: [Promise.<AdobeStateGetReturnValue>](#AdobeStateGetReturnValue) - get response holding value and additional info | Param | Type | Description | | --- | --- | --- | | key | string | state key identifier | - + -### *stateStore.put(key, value, [options]) ⇒ Promise.<string>* +### *adobeState.put(key, value, [options]) ⇒ Promise.<string>* Creates or updates a state key-value pair -**Kind**: instance method of [StateStore](#StateStore) +**Kind**: instance method of [AdobeState](#AdobeState) **Returns**: Promise.<string> - key | Param | Type | Default | Description | | --- | --- | --- | --- | | key | string | | state key identifier | -| value | any | | state value | -| [options] | [StateStorePutOptions](#StateStorePutOptions) | {} | put options | +| value | string | | state value | +| [options] | [AdobeStatePutOptions](#AdobeStatePutOptions) | {} | put options | - + -### *stateStore.delete(key) ⇒ Promise.<string>* +### *adobeState.delete(key) ⇒ Promise.<string>* Deletes a state key-value pair -**Kind**: instance method of [StateStore](#StateStore) +**Kind**: instance method of [AdobeState](#AdobeState) **Returns**: Promise.<string> - key of deleted state or `null` if state does not exists | Param | Type | Description | | --- | --- | --- | | key | string | state key identifier | - + -### *stateStore.\_get(key) ⇒ [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue)* -**Kind**: instance method of [StateStore](#StateStore) -**Returns**: [Promise.<StateStoreGetReturnValue>](#StateStoreGetReturnValue) - get response holding value and additional info -**Access**: protected +### *adobeState.deleteAll() ⇒ Promise.<boolean>* +Deletes all key-values -| Param | Type | Description | -| --- | --- | --- | -| key | string | state key identifier | +**Kind**: instance method of [AdobeState](#AdobeState) +**Returns**: Promise.<boolean> - true if deleted, false if not + - +### *adobeState.any() ⇒ Promise.<boolean>* +There exists key-values. -### *stateStore.\_put(key, value, options) ⇒ Promise.<string>* -**Kind**: instance method of [StateStore](#StateStore) -**Returns**: Promise.<string> - key -**Access**: protected +**Kind**: instance method of [AdobeState](#AdobeState) +**Returns**: Promise.<boolean> - true if exists, false if not + -| Param | Type | Description | -| --- | --- | --- | -| key | string | state key identifier | -| value | any | state value | -| options | object | state put options | - - +## validate(schema, data) ⇒ object +Validates json according to a schema. -### *stateStore.\_delete(key) ⇒ Promise.<string>* -**Kind**: instance method of [StateStore](#StateStore) -**Returns**: Promise.<string> - key of deleted state or `null` if state does not exists -**Access**: protected +**Kind**: global function +**Returns**: object - the result | Param | Type | Description | | --- | --- | --- | -| key | string | state key identifier | +| schema | object | the AJV schema | +| data | object | the json data to test | -## init([config]) ⇒ [Promise.<StateStore>](#StateStore) +## init([config]) ⇒ [Promise.<AdobeState>](#AdobeState) Initializes and returns the key-value-store SDK. To use the SDK you must either provide your [OpenWhisk credentials](#OpenWhiskCredentials) in `config.ow` or your own -[Azure Cosmos credentials](#AzureCosmosMasterCredentials) in `config.cosmos`. OpenWhisk credentials can also be read from environment variables `__OW_NAMESPACE` and `__OW_API_KEY`. **Kind**: global function -**Returns**: [Promise.<StateStore>](#StateStore) - A StateStore instance +**Returns**: [Promise.<AdobeState>](#AdobeState) - An AdobeState instance | Param | Type | Default | Description | | --- | --- | --- | --- | | [config] | object | {} | used to init the sdk | | [config.ow] | [OpenWhiskCredentials](#OpenWhiskCredentials) | | [OpenWhiskCredentials](#OpenWhiskCredentials). Set those if you want to use ootb credentials to access the state management service. OpenWhisk namespace and auth can also be passed through environment variables: `__OW_NAMESPACE` and `__OW_API_KEY` | -| [config.cosmos] | [AzureCosmosMasterCredentials](#AzureCosmosMasterCredentials) \| [AzureCosmosPartitionResourceCredentials](#AzureCosmosPartitionResourceCredentials) | | [Azure Cosmos resource credentials](#AzureCosmosPartitionResourceCredentials) or [Azure Cosmos account credentials](#AzureCosmosMasterCredentials) | -| [config.tvm] | object | | tvm configuration, applies only when passing OpenWhisk credentials | -| [config.tvm.apiUrl] | string | | alternative tvm api url. | -| [config.tvm.cacheFile] | string | | alternative tvm cache file, set to `false` to disable caching of temporary credentials. | - + -## OpenWhiskCredentials : object -An object holding the OpenWhisk credentials +## AdobeStateCredentials : object +AdobeStateCredentials **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | -| namespace | string | user namespace | -| auth | string | auth key | - - - -## AzureCosmosPartitionResourceCredentials : object -An object holding the Azure Cosmos resource credentials with permissions on a single partition and container - -**Kind**: global typedef -**Properties** +| namespace | string | the state store namespace | +| apikey | string | the state store api key | -| Name | Type | Description | -| --- | --- | --- | -| endpoint | string | cosmosdb resource endpoint | -| resourceToken | string | cosmosdb resource token restricted to the partitionKey | -| databaseId | string | id for cosmosdb database | -| containerId | string | id for cosmosdb container within database | -| partitionKey | string | key for cosmosdb partition within container authorized by resource token | + - - -## AzureCosmosMasterCredentials : object -An object holding the Azure Cosmos account master key +## AdobeStatePutOptions : object +AdobeState put options **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | -| endpoint | string | cosmosdb resource endpoint | -| masterKey | string | cosmosdb account masterKey | -| databaseId | string | id for cosmosdb database | -| containerId | string | id for cosmosdb container within database | -| partitionKey | string | key for cosmosdb partition where data will be stored | +| ttl | number | time-to-live for key-value pair in seconds, defaults to 24 hours (86400s). Set to < 0 for no expiry. A value of 0 sets default. | - + -## StateStorePutOptions : object -StateStore put options +## AdobeStateGetReturnValue : object +AdobeState get return object **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | -| ttl | number | time-to-live for key-value pair in seconds, defaults to 24 hours (86400s). Set to < 0 for no expiry. A value of 0 sets default. | +| expiration | string \| null | ISO date string of expiration time for the key-value pair, if the ttl is infinite expiration=null | +| value | any | the value set by put | - + -## StateStoreGetReturnValue : object -StateStore get return object +## OpenWhiskCredentials : object +An object holding the OpenWhisk credentials **Kind**: global typedef **Properties** | Name | Type | Description | | --- | --- | --- | -| expiration | string \| null | ISO date string of expiration time for the key-value pair, if the ttl is infinite expiration=null | -| value | any | the value set by put | +| namespace | string | user namespace | +| auth | string | auth key | - + -## StateLibError : Object +## AdobeStateLibError : object **Kind**: global typedef **Properties** @@ -239,12 +205,12 @@ StateStore get return object | message | string | The message for the Error | | code | string | The code for the Error | | sdk | string | The SDK associated with the Error | -| sdkDetails | Object | The SDK details associated with the Error | +| sdkDetails | object | The SDK details associated with the Error | - + -## StateLibErrors : object -State lib custom errors. +## AdobeStateLibErrors : object +Adobe State lib custom errors. `e.sdkDetails` provides additional context for each error (e.g. function parameter) **Kind**: global typedef @@ -252,10 +218,11 @@ State lib custom errors. | Name | Type | Description | | --- | --- | --- | -| ERROR_BAD_ARGUMENT | [StateLibError](#StateLibError) | this error is thrown when an argument is missing or has invalid type | -| ERROR_BAD_REQUEST | [StateLibError](#StateLibError) | this error is thrown when an argument has an illegal value. | -| ERROR_NOT_IMPLEMENTED | [StateLibError](#StateLibError) | this error is thrown when a method is not implemented or when calling methods directly on the abstract class (StateStore). | -| ERROR_PAYLOAD_TOO_LARGE | [StateLibError](#StateLibError) | this error is thrown when the state key, state value or underlying request payload size exceeds the specified limitations. | -| ERROR_BAD_CREDENTIALS | [StateLibError](#StateLibError) | this error is thrown when the supplied init credentials are invalid. | -| ERROR_INTERNAL | [StateLibError](#StateLibError) | this error is thrown when an unknown error is thrown by the underlying DB provider or TVM server for credential exchange. More details can be found in `e.sdkDetails._internal`. | +| ERROR_BAD_ARGUMENT | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when an argument is missing, has invalid type, or includes invalid characters. | +| ERROR_BAD_REQUEST | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when an argument has an illegal value. | +| ERROR_PAYLOAD_TOO_LARGE | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when the state key, state value or underlying request payload size exceeds the specified limitations. | +| ERROR_BAD_CREDENTIALS | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when the supplied init credentials are invalid. | +| ERROR_UNAUTHORIZED | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when the credentials are unauthorized to access the resource | +| ERROR_INTERNAL | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when an unknown error is thrown by the underlying DB provider or TVM server for credential exchange. More details can be found in `e.sdkDetails._internal`. | +| ERROR_REQUEST_RATE_TOO_HIGH | [AdobeStateLibError](#AdobeStateLibError) | this error is thrown when the request rate for accessing state is too high. | diff --git a/lib/AdobeState.js b/lib/AdobeState.js index 2b0081c..562c077 100644 --- a/lib/AdobeState.js +++ b/lib/AdobeState.js @@ -329,7 +329,7 @@ class AdobeState { * Deletes all key-values * * @returns {Promise} true if deleted, false if not - * @memberof StateStore + * @memberof AdobeState */ async deleteAll () { const requestOptions = { @@ -350,7 +350,7 @@ class AdobeState { * There exists key-values. * * @returns {Promise} true if exists, false if not - * @memberof StateStore + * @memberof AdobeState */ async any () { const requestOptions = { diff --git a/lib/StateError.js b/lib/StateError.js index 3d98632..e5a4c4a 100644 --- a/lib/StateError.js +++ b/lib/StateError.js @@ -25,12 +25,10 @@ const logger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-state', { * Adobe State lib custom errors. * `e.sdkDetails` provides additional context for each error (e.g. function parameter) * - * @typedef StateLibErrors + * @typedef AdobeStateLibErrors * @type {object} * @property {AdobeStateLibError} ERROR_BAD_ARGUMENT this error is thrown when an argument is missing, has invalid type, or includes invalid characters. * @property {AdobeStateLibError} ERROR_BAD_REQUEST this error is thrown when an argument has an illegal value. - * @property {AdobeStateLibError} ERROR_NOT_IMPLEMENTED this error is thrown when a method is not implemented or when calling - * methods directly on the abstract class (StateStore). * @property {AdobeStateLibError} ERROR_PAYLOAD_TOO_LARGE this error is thrown when the state key, state value or underlying request payload size * exceeds the specified limitations. * @property {AdobeStateLibError} ERROR_BAD_CREDENTIALS this error is thrown when the supplied init credentials are invalid. @@ -58,7 +56,6 @@ E('ERROR_INTERNAL', '%s') E('ERROR_BAD_REQUEST', '%s') E('ERROR_BAD_ARGUMENT', '%s') E('ERROR_UNKNOWN_PROVIDER', '%s') -E('ERROR_NOT_IMPLEMENTED', 'method `%s` not implemented') E('ERROR_UNAUTHORIZED', 'you are not authorized to access %s') E('ERROR_BAD_CREDENTIALS', 'cannot access %s, make sure your credentials are valid') E('ERROR_PAYLOAD_TOO_LARGE', 'key, value or request payload is too large') diff --git a/lib/init.js b/lib/init.js index 47afef0..d03b5b8 100644 --- a/lib/init.js +++ b/lib/init.js @@ -33,7 +33,6 @@ const { AdobeState } = require('./AdobeState') * To use the SDK you must either provide your * [OpenWhisk credentials]{@link OpenWhiskCredentials} in * `config.ow` or your own - * [Azure Cosmos credentials]{@link AzureCosmosMasterCredentials} in `config.cosmos`. * * OpenWhisk credentials can also be read from environment variables `__OW_NAMESPACE` and `__OW_API_KEY`. * @@ -43,7 +42,7 @@ const { AdobeState } = require('./AdobeState') * to use ootb credentials to access the state management service. OpenWhisk * namespace and auth can also be passed through environment variables: * `__OW_NAMESPACE` and `__OW_API_KEY` - * @returns {Promise} An AdobeStateStore instance + * @returns {Promise} An AdobeState instance */ async function init (config = {}) { const logConfig = utils.withHiddenFields(config, ['ow.auth']) diff --git a/lib/utils.js b/lib/utils.js index aeabd8d..187b50d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -15,6 +15,7 @@ const cloneDeep = require('lodash.clonedeep') /** * Replaces any hidden field values with the string '' * + * @private * @param {object} sourceObj the object to needs fields hidden * @param {Array} fieldsToHide the fields that need the value hidden * @returns {object} the source object but with the specified fields hidden diff --git a/test/jest.setup.js b/test/jest.setup.js index 7bbe70d..e476554 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -66,6 +66,5 @@ global.expectToThrowForbidden = async (received, expectedErrorDetails) => global global.expectToThrowFirewall = async (received, expectedErrorDetails) => global.expectToThrowCustomError(received, 'ERROR_FIREWALL', ['your', 'IP', 'blocked', 'firewall'], expectedErrorDetails) global.expectToThrowInternalWithStatus = async (received, status, expectedErrorDetails) => global.expectToThrowCustomError(received, 'ERROR_INTERNAL', ['' + status], expectedErrorDetails) global.expectToThrowInternal = async (received, expectedErrorDetails) => global.expectToThrowCustomError(received, 'ERROR_INTERNAL', ['unknown'], expectedErrorDetails) -global.expectToThrowNotImplemented = async (received, methodName) => global.expectToThrowCustomError(received, 'ERROR_NOT_IMPLEMENTED', ['not', 'implemented', methodName], {}) global.expectToThrowTooLarge = async (received, expectedErrorDetails) => global.expectToThrowCustomError(received, 'ERROR_PAYLOAD_TOO_LARGE', ['payload', 'is', 'too', 'large'], expectedErrorDetails) global.expectToThrowRequestRateTooHigh = async (received, expectedErrorDetails) => global.expectToThrowCustomError(received, 'ERROR_REQUEST_RATE_TOO_HIGH', ['Request', 'rate', 'too', 'high'], expectedErrorDetails) diff --git a/types.d.ts b/types.d.ts index 7fc3c5d..f3736fb 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,34 +1,52 @@ /** - * StateStore put options + * AdobeStateCredentials + * @property namespace - the state store namespace + * @property apikey - the state store api key + */ +export type AdobeStateCredentials = { + namespace: string; + apikey: string; +}; + +/** + * AdobeState put options * @property ttl - time-to-live for key-value pair in seconds, defaults to 24 hours (86400s). Set to < 0 for no expiry. A * value of 0 sets default. */ -export type StateStorePutOptions = { +export type AdobeStatePutOptions = { ttl: number; }; /** - * StateStore get return object + * AdobeState get return object * @property expiration - ISO date string of expiration time for the key-value pair, if the ttl is infinite * expiration=null * @property value - the value set by put */ -export type StateStoreGetReturnValue = { +export type AdobeStateGetReturnValue = { expiration: string | null; value: any; }; +/** + * Validates json according to a schema. + * @param schema - the AJV schema + * @param data - the json data to test + * @returns the result + */ +export function validate(schema: any, data: any): any; + /** * Cloud State Management */ -export class StateStore { +export class AdobeState { /** * Retrieves the state value for given key. * If the key doesn't exist returns undefined. * @param key - state key identifier * @returns get response holding value and additional info */ - get(key: string): Promise; + get(key: string): Promise; /** * Creates or updates a state key-value pair * @param key - state key identifier @@ -36,7 +54,7 @@ export class StateStore { * @param [options = {}] - put options * @returns key */ - put(key: string, value: any, options?: StateStorePutOptions): Promise; + put(key: string, value: string, options?: AdobeStatePutOptions): Promise; /** * Deletes a state key-value pair * @param key - state key identifier @@ -44,22 +62,15 @@ export class StateStore { */ delete(key: string): Promise; /** - * @param key - state key identifier - * @returns get response holding value and additional info + * Deletes all key-values + * @returns true if deleted, false if not */ - protected _get(key: string): Promise; + deleteAll(): Promise; /** - * @param key - state key identifier - * @param value - state value - * @param options - state put options - * @returns key + * There exists key-values. + * @returns true if exists, false if not */ - protected _put(key: string, value: any, options: any): Promise; - /** - * @param key - state key identifier - * @returns key of deleted state or `null` if state does not exists - */ - protected _delete(key: string): Promise; + any(): Promise; } /** @@ -68,7 +79,7 @@ export class StateStore { * @property sdk - The SDK associated with the Error * @property sdkDetails - The SDK details associated with the Error */ -export type StateLibError = { +export type AdobeStateLibError = { message: string; code: string; sdk: string; @@ -76,25 +87,26 @@ export type StateLibError = { }; /** - * State lib custom errors. + * Adobe State lib custom errors. * `e.sdkDetails` provides additional context for each error (e.g. function parameter) - * @property ERROR_BAD_ARGUMENT - this error is thrown when an argument is missing or has invalid type + * @property ERROR_BAD_ARGUMENT - this error is thrown when an argument is missing, has invalid type, or includes invalid characters. * @property ERROR_BAD_REQUEST - this error is thrown when an argument has an illegal value. - * @property ERROR_NOT_IMPLEMENTED - this error is thrown when a method is not implemented or when calling - * methods directly on the abstract class (StateStore). * @property ERROR_PAYLOAD_TOO_LARGE - this error is thrown when the state key, state value or underlying request payload size * exceeds the specified limitations. * @property ERROR_BAD_CREDENTIALS - this error is thrown when the supplied init credentials are invalid. + * @property ERROR_UNAUTHORIZED - this error is thrown when the credentials are unauthorized to access the resource * @property ERROR_INTERNAL - this error is thrown when an unknown error is thrown by the underlying * DB provider or TVM server for credential exchange. More details can be found in `e.sdkDetails._internal`. + * @property ERROR_REQUEST_RATE_TOO_HIGH - this error is thrown when the request rate for accessing state is too high. */ -export type StateLibErrors = { - ERROR_BAD_ARGUMENT: StateLibError; - ERROR_BAD_REQUEST: StateLibError; - ERROR_NOT_IMPLEMENTED: StateLibError; - ERROR_PAYLOAD_TOO_LARGE: StateLibError; - ERROR_BAD_CREDENTIALS: StateLibError; - ERROR_INTERNAL: StateLibError; +export type AdobeStateLibErrors = { + ERROR_BAD_ARGUMENT: AdobeStateLibError; + ERROR_BAD_REQUEST: AdobeStateLibError; + ERROR_PAYLOAD_TOO_LARGE: AdobeStateLibError; + ERROR_BAD_CREDENTIALS: AdobeStateLibError; + ERROR_UNAUTHORIZED: AdobeStateLibError; + ERROR_INTERNAL: AdobeStateLibError; + ERROR_REQUEST_RATE_TOO_HIGH: AdobeStateLibError; }; /** @@ -107,45 +119,12 @@ export type OpenWhiskCredentials = { auth: string; }; -/** - * An object holding the Azure Cosmos resource credentials with permissions on a single partition and container - * @property endpoint - cosmosdb resource endpoint - * @property resourceToken - cosmosdb resource token restricted to the partitionKey - * @property databaseId - id for cosmosdb database - * @property containerId - id for cosmosdb container within database - * @property partitionKey - key for cosmosdb partition within container authorized by resource token - */ -export type AzureCosmosPartitionResourceCredentials = { - endpoint: string; - resourceToken: string; - databaseId: string; - containerId: string; - partitionKey: string; -}; - -/** - * An object holding the Azure Cosmos account master key - * @property endpoint - cosmosdb resource endpoint - * @property masterKey - cosmosdb account masterKey - * @property databaseId - id for cosmosdb database - * @property containerId - id for cosmosdb container within database - * @property partitionKey - key for cosmosdb partition where data will be stored - */ -export type AzureCosmosMasterCredentials = { - endpoint: string; - masterKey: string; - databaseId: string; - containerId: string; - partitionKey: string; -}; - /** * Initializes and returns the key-value-store SDK. * * To use the SDK you must either provide your * [OpenWhisk credentials]{@link OpenWhiskCredentials} in * `config.ow` or your own - * [Azure Cosmos credentials]{@link AzureCosmosMasterCredentials} in `config.cosmos`. * * OpenWhisk credentials can also be read from environment variables `__OW_NAMESPACE` and `__OW_API_KEY`. * @param [config = {}] - used to init the sdk @@ -153,19 +132,9 @@ export type AzureCosmosMasterCredentials = { * to use ootb credentials to access the state management service. OpenWhisk * namespace and auth can also be passed through environment variables: * `__OW_NAMESPACE` and `__OW_API_KEY` - * @param [config.cosmos] - [Azure Cosmos resource credentials]{@link AzureCosmosPartitionResourceCredentials} or - * [Azure Cosmos account credentials]{@link AzureCosmosMasterCredentials} - * @param [config.tvm] - tvm configuration, applies only when passing OpenWhisk credentials - * @param [config.tvm.apiUrl] - alternative tvm api url. - * @param [config.tvm.cacheFile] - alternative tvm cache file, set to `false` to disable caching of temporary credentials. - * @returns A StateStore instance + * @returns An AdobeState instance */ export function init(config?: { ow?: OpenWhiskCredentials; - cosmos?: AzureCosmosMasterCredentials | AzureCosmosPartitionResourceCredentials; - tvm?: { - apiUrl?: string; - cacheFile?: string; - }; -}): Promise; +}): Promise;