Namespaces
Organize and isolate different parts of your application at the App, Space, and Workbook level.
Event Filters
Target specific Sheets or event properties to create precise Event handling rules for your Listeners.
Namespaces
Understanding Namespaces
Namespaces are simple string identifiers that you can assign to Apps, Spaces, and Workbooks to organize and isolate different parts of your Flatfile application. When you assign a namespace to a resource, Events from that resource can be filtered using Listener namespace patterns.How Namespace Filtering Works
Listeners use prefix patterns to filter Events based on the namespace of the resource that generated the Event:space:namespace
- Listen to Events from Spaces with the given namespace or belonging to Apps with that namespaceworkbook:namespace
- Listen to Events from Workbooks with the given namespace
App Namespaces
The most common namespace pattern is creating separate Apps with distinct namespaces, then using namespaced Listeners to handle different configurations for each app.Setting App Namespaces
Namespaces are set when creating an App via the Flatfile Dashboard:
App settings modal with namespace field ("example-app")
Customer Portal
App Name: Customer Portal
Namespace:
Purpose: External customer data import
Namespace:
customer-portal
Purpose: External customer data import
Internal Tools
App Name: Internal Tools
Namespace:
Purpose: Admin and operations
Namespace:
internal-tools
Purpose: Admin and operations
Partner Integration
App Name: Partner Integration
Namespace:
Purpose: B2B data exchange
Namespace:
partner-integration
Purpose: B2B data exchange
Listening to App Namespace Events
Now you can uselistener.namespace()
to create separate Listeners for Spaces within each App. This will provide a new, filtered Listener object scoped to your callback function.
This pattern allows each App to have completely different:
- Space configurations and blueprints
- Data validation rules
- Processing workflows
- User experiences
- Integration behaviors
listener.use()
, as in this example), see Events and Listeners.
Space Namespaces
Beyond App-level namespacing, you can also apply namespaces directly to individual Spaces, enabling unique configurations and behaviors on a space-by-space basis.Important: Spaces inherit their App’s namespace by default. When you create listeners that filter on
space:app-namespace
, they receive Events from spaces within that App.If you override a Space’s namespace to be different from its App, Listeners filtering on the App’s namespace will no longer receive Events from that Space. For example:- App has namespace
"my-app"
- You create a Space with explicit namespace
"my-space"
- Listeners filtering on
space:my-space
will receive Events from that Space - Listeners filtering on
space:my-app
will not receive Events from that Space
Setting Space Namespaces
Assign a namespace when creating a Space via the API:space:configure
Job by updating the Space. This may be useful if you’re creating Spaces from the Flatfile Dashboard, which doesn’t support setting a namespace during creation.
This example shows how to set the namespace based on the Space name, allowing you to have multiple configurations in the same App:
In this example, we’ll show the full Job Listener lifecycle implementation, complete with
ack
to acknowledge the job, update
to report progress, and complete
or fail
to finish the job.However, for most implementations, we recommend using the Space Configure plugin. This plugin takes care of even more of the heavy lifting for you; not only does it handle the Job lifecycle, but it also takes care of all of the API calls necessary to configure the Space and create its Workbooks and documents.Listening to Space Namespace Events
Uselistener.namespace()
to filter Events from Spaces with specific namespaces. This will provide a new, filtered Listener object scoped to your callback function:
Workbook Namespaces
Workbooks can also have namespaces for more granular Event filtering within the same Space. This can be set directly in the Workbook’s Blueprint. This example configures a structure with two Workbooks in the same Space, with a flow for moving data from the staging Workbook to the production Workbook.Setting Workbook Namespaces
Listening to Workbook Namespace Events
Events from Workbooks with namespaces are filtered using theworkbook:namespace
pattern.
Listening to Multiple Namespaces
Thelistener.namespace()
function can accept an array of namespace patterns as its first argument, allowing you to listen to Events from multiple namespaces with a single Listener configuration. This is useful when you want to apply the same processing logic across different namespaces.
You can also mix different namespace types in the same array. The Listener in this example will receive Events from both the space:admin-tools
and workbook:critical-data
namespaces:
Nested Namespace Example
You can also nest namespacing: let’s say you have two Apps (customer-portal
and vendor-portal
), and each App processes data through different Workbook types (invoices
and orders
). You want to ensure that each App’s Workbooks are completely isolated from the other App, but within each App you want specific handling for each Workbook type.
This example demonstrates how App, Space, and Workbook namespaces work together with nested Listeners:
Setting Up Multiple Apps
First, create two Apps via the Flatfile Dashboard, each with distinct namespaces:Customer Portal
App Name: Customer Portal
Namespace:
Purpose: External customer data import and processing
Namespace:
customer-portal
Purpose: External customer data import and processing
Vendor Portal
App Name: Vendor Portal
Namespace:
Purpose: B2B vendor data exchange and management
Namespace:
vendor-portal
Purpose: B2B vendor data exchange and management
Nested Listener Configuration
To help reduce scrolling for this example, we’ve split it into two tabs: Blueprints and Listener Configuration.
Each App requires different field structures for their invoice and order processing, so we define App-specific Blueprint configurations. See the next tab for the Listener Configuration.
Event Filters
Understanding Event Filtering
Thelistener.filter()
method creates filtered Listener instances that only respond to Events matching specific criteria, returning a new FlatfileListener
instance with the applied filter conditions.
Basic Filtering
The most fundamental use oflistener.filter()
is to respond to specific Events based on simple criteria. This approach is useful when you want different processing logic for different types of Jobs or Events within the same namespace, without creating separate Event handlers for each case.
Wildcard Filtering
Filters support wildcard patterns using*
to match partial values. This may be useful when you want to filter by ID patterns or prefixes.
This example filters for commit:created
events that were initiated by Jobs rather than users. When a Job causes changes to your data (commits), the actorId
in the event context will be the job ID (starting with "us_jb"
):
Chaining Filters and Namespaces
You can also chain multiple filters along with namespaces to isolate highly specific events. This example shows how to combine a namespace with two filters to handle failed submit jobs for third-party integrations:Filter Properties
Thelistener.filter()
method accepts an object defining filter criteria based on Event properties.
Important: This is not intended to be a comprehensive list of all possible filter properties, but a reference for commonly-used ones.Event properties vary significantly by event type, and using a filter property that doesn’t exist for an event type will result in no matches.Refer to the Event Reference for the specific properties available for each event you want to filter on. You can always
console.log()
your events prior to filtering to see what properties are available.Universal Properties
These properties are available for filtering across most or all event types:Property | Description | Example |
---|---|---|
topic | Event topic pattern | { topic: 'records:created' } |
domain | Event domain (supports wildcards) | { domain: 'space' } |
environmentId | Environment identifier | { environmentId: 'us_env_123' } |
Common Context Properties
These properties are available in many events but not all:Property | Description | Example | Available In |
---|---|---|---|
spaceId | Specific space | { spaceId: 'us_sp_789' } | Most events (not environment events) |
actorId | Specific actor | { actorId: 'us_usr_123' } | Most user-initiated events |
accountId | Account identifier | { accountId: 'us_acc_123' } | Most events |
Specific Context Properties
These properties are only available for certain event types:Property | Description | Example | Available In |
---|---|---|---|
workbookId | Specific workbook | { workbookId: 'us_wb_456' } | Workbook, sheet, record, some job events |
sheetId | Specific sheet ID | { sheetId: 'us_sh_123' } | Sheet, record, program events |
sheet | Sheet slug | { sheet: 'contacts' } | Sheet, record, program events |
jobId | Specific job ID | { jobId: 'us_jb_123' } | Job events only |
fileId | File identifier | { fileId: 'us_fl_123' } | File events only |
Job Event Filters
Special filter properties for job events:Property | Description | Example |
---|---|---|
job | Job type identifier | { job: 'workbook:submit' } |
payload.status | Job status | { 'payload.status': 'failed' } |
payload.domain | Event domain | { 'payload.domain': 'space' } |
payload.operation | Operation name | { 'payload.operation': 'configure' } |
Record Event Filters
Specific to record creation, update, and deletion events:Property | Description | Example |
---|---|---|
payload.recordIds | Array of affected record IDs | { 'payload.recordIds': ['rec_123'] } |
payload.recordCount | Number of records affected | { 'payload.recordCount': 5 } |
payload.sheetId | Sheet containing the records | { 'payload.sheetId': 'us_sh_123' } |
File Event Filters
Specific to file upload and processing events:Property | Description | Example |
---|---|---|
payload.status | File processing status | { 'payload.status': 'completed' } |
payload.workbookId | Associated workbook | { 'payload.workbookId': 'us_wb_123' } |
*
.