Session
Smart Flow Session Module
Manages session persistence and state management, handling CRUD operations for sessions, flows, and component states
- Session
- .create() ⇒
Promise<SessionCreateResult>
- .get() ⇒
Promise<FlowSessionTable>
- .getComponent(flowId, component) ⇒
Promise<FlowComponentTable>
- .getFlow(flowId) ⇒
Promise<FlowTable>
- .getSessionActivity() ⇒
Promise<{activeTime: number, lastActive: number, isReturningUser: boolean}>
- .init() ⇒
Promise<SmartFlowSessionModule>
- .remove([excludeId]) ⇒
Promise<void>
- .removeComponent(flowId, component) ⇒
Promise<void>
- .removeFlow(flowId) ⇒
Promise<void>
- .save(session) ⇒
Promise<FlowSessionTable>
- .saveComponent(flowId, component, state) ⇒
Promise<FlowComponentTable>
- .saveFlow(flowId, state) ⇒
Promise<FlowTable>
- .update([session]) ⇒
Promise<FlowSessionTable>
- .create() ⇒
Session.create() ⇒ Promise<SessionCreateResult>
Promise<SessionCreateResult>
Creates or updates a Smart Flow session
Returns: Promise<SessionCreateResult>
- Object containing the session and metadata
Session.get() ⇒ Promise<FlowSessionTable>
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>
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>
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}>
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>
Promise<SmartFlowSessionModule>
Initializes the Smart Flow session and calculates user activity metrics
Returns: Promise<SmartFlowSessionModule>
- The initialized Session module
Session.remove([excludeId]) ⇒ Promise<void>
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>
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>
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>
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>
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>
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>
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
Array
Tuple containing the session and associated metadata
Properties
Name | Type | Description |
---|---|---|
session | FlowSessionTable | The session object |
meta | FlowSessionMeta | The session metadata |