Smart Flows Session
Session
Smart Flow Session Module
Manages session persistence and state management,
handling CRUD operations for sessions, flows, and component states
Session.create() ⇒ Promise\<SessionCreateResult>
Creates or updates a Smart Flow session
Returns: Promise\<SessionCreateResult> - Object containing the session and metadata
Session.get() ⇒ Promise\<FlowSessionTable>
Retrieves the current session or creates a new one
Returns: Promise\<FlowSessionTable> - The current session
Throws:
Error If session retrieval fails
Session.getComponent(flowId, component) ⇒ Promise\<FlowComponentTable>
Retrieves a component's state from the database
Returns: Promise\<FlowComponentTable> - The component's session data
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow |
| component |
SmartFlowComponent |
The component to retrieve |
Session.getFlow(flowId) ⇒ Promise\<FlowTable>
Retrieves or initializes a flow
Returns: Promise\<FlowTable> - The flow data
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow |
Session.getSessionActivity() ⇒ Promise\<{activeTime: number, lastActive: number, isReturningUser: boolean}>
Retrieves the current session activity metrics with recalculation
Returns: Promise\<{activeTime: number, lastActive: number, isReturningUser: boolean}> - Session activity data
Session.init() ⇒ Promise\<SmartFlowSessionModule>
Initializes the Smart Flow session and calculates user activity metrics
Returns: Promise\<SmartFlowSessionModule> - The initialized Session module
Session.remove([excludeId]) ⇒ Promise\<void>
Removes session(s) from the database
| Param |
Type |
Description |
| [excludeId] |
string |
Optional ID of session to exclude from deletion |
Session.removeComponent(flowId, component) ⇒ Promise\<void>
Removes a component from the database
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow |
| component |
SmartFlowComponent |
The component to remove |
Session.removeFlow(flowId) ⇒ Promise\<void>
Removes a flow and its components from the database
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow to remove |
Session.save(session) ⇒ Promise\<FlowSessionTable>
Saves session changes to the database
Returns: Promise\<FlowSessionTable> - The updated session
| Param |
Type |
Description |
| session |
FlowSessionTable |
The session to save |
Session.saveComponent(flowId, component, state) ⇒ Promise\<FlowComponentTable>
Saves component state changes to the database
Returns: Promise\<FlowComponentTable> - The updated component session
Throws:
Error If flowId or component.id is invalid
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow |
| component |
SmartFlowComponent |
The component to update |
| state |
object |
The state changes to save |
Session.saveFlow(flowId, state) ⇒ Promise\<FlowTable>
Saves flow state changes to the database
Returns: Promise\<FlowTable> - The updated flow
| Param |
Type |
Description |
| flowId |
number |
The ID of the flow |
| state |
Partial\<FlowTable> |
The state changes to save |
Session.update([session]) ⇒ Promise\<FlowSessionTable>
Updates an existing session or creates a new one
Returns: Promise\<FlowSessionTable> - The updated or new session
| Param |
Type |
Description |
| [session] |
FlowSessionTable |
Optional session to update |
SessionCreateResult : Array
Tuple containing the session and associated metadata
Properties
| Name |
Type |
Description |
| session |
FlowSessionTable |
The session object |
| meta |
FlowSessionMeta |
The session metadata |
---
title: Smart Flows Session
excerpt: Manage Smart Flows session persistence and component states
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: ''
pages:
- type: endpoint
slug: smart-flows-methods-overview
title: Methods
---
<a name="Session"></a>
## Session
Smart Flow Session Module
Manages session persistence and state management,
handling CRUD operations for sessions, flows, and component states
* [Session](#Session)
* [.create()](#Session.create) ⇒ <code>Promise\<SessionCreateResult></code>
* [.get()](#Session.get) ⇒ <code>Promise\<FlowSessionTable></code>
* [.getComponent(flowId, component)](#Session.getComponent) ⇒ <code>Promise\<FlowComponentTable></code>
* [.getFlow(flowId)](#Session.getFlow) ⇒ <code>Promise\<FlowTable></code>
* [.getSessionActivity()](#Session.getSessionActivity) ⇒ <code>Promise\<{activeTime: number, lastActive: number, isReturningUser: boolean}></code>
* [.init()](#Session.init) ⇒ <code>Promise\<SmartFlowSessionModule></code>
* [.remove([excludeId])](#Session.remove) ⇒ <code>Promise\<void></code>
* [.removeComponent(flowId, component)](#Session.removeComponent) ⇒ <code>Promise\<void></code>
* [.removeFlow(flowId)](#Session.removeFlow) ⇒ <code>Promise\<void></code>
* [.save(session)](#Session.save) ⇒ <code>Promise\<FlowSessionTable></code>
* [.saveComponent(flowId, component, state)](#Session.saveComponent) ⇒ <code>Promise\<FlowComponentTable></code>
* [.saveFlow(flowId, state)](#Session.saveFlow) ⇒ <code>Promise\<FlowTable></code>
* [.update([session])](#Session.update) ⇒ <code>Promise\<FlowSessionTable></code>
<a name="Session.create"></a>
### Session.create() ⇒ <code>Promise\<SessionCreateResult></code>
Creates or updates a Smart Flow session
**Returns**: <code>Promise\<SessionCreateResult></code> - Object containing the session and metadata
<a name="Session.get"></a>
### Session.get() ⇒ <code>Promise\<FlowSessionTable></code>
Retrieves the current session or creates a new one
**Returns**: <code>Promise\<FlowSessionTable></code> - The current session
**Throws**:
- <code>Error</code> If session retrieval fails
<a name="Session.getComponent"></a>
### Session.getComponent(flowId, component) ⇒ <code>Promise\<FlowComponentTable></code>
Retrieves a component's state from the database
**Returns**: <code>Promise\<FlowComponentTable></code> - The component's session data
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow |
| component | <code>SmartFlowComponent</code> | The component to retrieve |
<a name="Session.getFlow"></a>
### Session.getFlow(flowId) ⇒ <code>Promise\<FlowTable></code>
Retrieves or initializes a flow
**Returns**: <code>Promise\<FlowTable></code> - The flow data
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow |
<a name="Session.getSessionActivity"></a>
### Session.getSessionActivity() ⇒ <code>Promise\<{activeTime: number, lastActive: number, isReturningUser: boolean}></code>
Retrieves the current session activity metrics with recalculation
**Returns**: <code>Promise\<{activeTime: number, lastActive: number, isReturningUser: boolean}></code> - Session activity data
<a name="Session.init"></a>
### Session.init() ⇒ <code>Promise\<SmartFlowSessionModule></code>
Initializes the Smart Flow session and calculates user activity metrics
**Returns**: <code>Promise\<SmartFlowSessionModule></code> - The initialized Session module
<a name="Session.remove"></a>
### Session.remove([excludeId]) ⇒ <code>Promise\<void></code>
Removes session(s) from the database
| Param | Type | Description |
| --- | --- | --- |
| [excludeId] | <code>string</code> | Optional ID of session to exclude from deletion |
<a name="Session.removeComponent"></a>
### Session.removeComponent(flowId, component) ⇒ <code>Promise\<void></code>
Removes a component from the database
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow |
| component | <code>SmartFlowComponent</code> | The component to remove |
<a name="Session.removeFlow"></a>
### Session.removeFlow(flowId) ⇒ <code>Promise\<void></code>
Removes a flow and its components from the database
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow to remove |
<a name="Session.save"></a>
### Session.save(session) ⇒ <code>Promise\<FlowSessionTable></code>
Saves session changes to the database
**Returns**: <code>Promise\<FlowSessionTable></code> - The updated session
| Param | Type | Description |
| --- | --- | --- |
| session | <code>FlowSessionTable</code> | The session to save |
<a name="Session.saveComponent"></a>
### Session.saveComponent(flowId, component, state) ⇒ <code>Promise\<FlowComponentTable></code>
Saves component state changes to the database
**Returns**: <code>Promise\<FlowComponentTable></code> - The updated component session
**Throws**:
- <code>Error</code> If flowId or component.id is invalid
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow |
| component | <code>SmartFlowComponent</code> | The component to update |
| state | <code>object</code> | The state changes to save |
<a name="Session.saveFlow"></a>
### Session.saveFlow(flowId, state) ⇒ <code>Promise\<FlowTable></code>
Saves flow state changes to the database
**Returns**: <code>Promise\<FlowTable></code> - The updated flow
| Param | Type | Description |
| --- | --- | --- |
| flowId | <code>number</code> | The ID of the flow |
| state | <code>Partial\<FlowTable></code> | The state changes to save |
<a name="Session.update"></a>
### Session.update([session]) ⇒ <code>Promise\<FlowSessionTable></code>
Updates an existing session or creates a new one
**Returns**: <code>Promise\<FlowSessionTable></code> - The updated or new session
| Param | Type | Description |
| --- | --- | --- |
| [session] | <code>FlowSessionTable</code> | Optional session to update |
<a name="SessionCreateResult"></a>
## SessionCreateResult : <code>Array</code>
Tuple containing the session and associated metadata
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| session | <code>FlowSessionTable</code> | The session object |
| meta | <code>FlowSessionMeta</code> | The session metadata |