File Manager
Official sources are open to Staxis GitLab group members: how to join and view the code.
Repository:
File Manager development
Versions:
tags
and releases
Description
File Manager is a runtime layer for filesystem CRUD within the configured temporary directory, which defaults to system-temp. Its label and typology are both filemanager. Calling packs need a Vault token and an explicit access profile for the requested operations.
Read before flight
This is an initial release.
Under heavy load, it may exhaust process and disk resources. The current File Manager does not have a
queue limit, a cap on concurrent operations, or storage quotas.
The system uses Node.js's `node:fs/promises`, so Node.js already manages execution through its own thread pool. That pool, however, does not limit the number of requests the application can accumulate, nor does it coordinate changes to the same file. Node.js Documentation
We suggest accounting for these limits when choosing workloads:
-
β RAM: Reads and writes operate on whole Buffers. Many requests can consume a significant amount of memory, even while they are waiting.
-
β Disk: Writes and copies can fill up the volume; if it is shared, logs and other services are also affected.
-
β Latency: Many operations can slow down other activities that share the disk and thread pool.
-
β Data: Simultaneous writes with `overwrite: true` are not coordinated. Operations such as `move` and `rename` involve copying and deleting, so they can also interfere with concurrent operations.
There is a specific milestone tracking request scheduling and resource limits for this layer. Work is currently on hold for technical reasons.
What It Does
The layer writes Buffers, reads file contents, copies and relocates files, deletes individual files, and lists directories. Each operation checks the calling pack's profile and resolves paths through engine.fileaccess. Targets supplied to its API are relative to the temporary directory.
HTTP routes, upload parsing, application-user authorization, download streaming, and file expiration belong to the calling application or their dedicated packs. File Manager handles the selected file operation and returns its result.
Files Map
| File | Purpose |
|---|---|
| manifest.json | Declares the filemanager label, typology, and Vault permits |
| main.js | Implements token checks, access profiles, filesystem operations, and lifecycle |
| configs.js | Provides the Guardian file-access rule and an initially empty access-profile list |
| readme.md | Repository reference for the pack |
Requirements
- No required pack dependencies and no external npm dependencies.
- Place filemanager before its callers in the project's stack.
- Configure KEY:FILEMANAGER and the project's Vault keys before startup.
- Review and prepare integrity records for the installed files.
- Keep the Guardian file-access rule and the caller's operation profile configured.
Install the pack through the Manager, or select its optional entry in the monolithic .roll profile. After installation, check the merged project configuration against the following settings.
Configuration
The pack's defaults enable its Guardian access to system-temp and initialize engineopt.filemanager.access as an empty array. An empty array grants no caller access. The following example grants whorequest a directory for its own files. In the project's config.js, these settings belong to config.engineopt. Merge the following engineopt branch into the exported config object. The two branches are config.engineopt.guard and config.engineopt.filemanager; preserve their other existing entries.
// config.js -> config (merge into the exported object)
engineopt: {
guard: {
allowedFileAccess: [
{
pack: 'filemanager',
roots: ['./system-temp', './system-temp/*']
}
]
},
filemanager: {
access: [
{
layer: 'whorequest',
write: ['./system-temp/whorequest/*'],
read: ['./system-temp/whorequest/*'],
list: ['./system-temp/whorequest'],
delete: false
}
]
}
}
The access profile's layer field is the caller's pack label, whorequest. It is separate from the provider's label and typology, filemanager. Exactly one profile must match the caller. Missing profiles, duplicate matching profiles, and missing operation permissions are denied.
- true grants that operation throughout the managed temporary-directory scope.
- false or an omitted permission denies that operation.
- An array grants matching project-relative paths, including the temporary-directory prefix.
- The profile matcher is case-insensitive, and * can span directory separators.
API targets use paths such as whorequest/note.txt. Access-profile patterns use paths such as ./system-temp/whorequest/*. If engineopt.folders.temp changes, update both Guardian roots and access-profile patterns. These examples assume the standard system-lrpcks/filemanager/main.js layout.
Parent directories must already exist. The layer provides file operations and directory listings. Create the example directory during project setup.
node -e "require('node:fs').mkdirSync('system-temp/whorequest', { recursive: true })"
Request Access
Run the following inside an asynchronous factory or method of whorequest. Its manifest can declare "require": ["filemanager"]. The supplied File Manager manifest has permits=true, allowing packs to request Vault tokens. The operation profiles above still decide which calls succeed. You can also restrict the provider's permits to selected caller labels.
const token = engine.vault.requireAccess(
'whorequest', // Requester's manifest.label
'filemanager' // Provider's manifest.label
)
if (typeof token !== 'string' || token.startsWith('error:')) {
throw new Error('File Manager access denied')
}
const instance = layers.require(
'filemanager', // Provider's manifest.typology: runtime slot
token,
false
)
const files = instance?.assets
if (!files || typeof files.write !== 'function') {
throw new Error('File Manager is unavailable')
}
const result = await files.write(
token,
Buffer.from('Hello from whorequest'),
'whorequest/note.txt'
)
if (result.errors) {
throw new Error(result.message)
}
Pass false to layers.require to get the instance, then use its assets. true selects the lifecycle API, whose attach and detach methods serve a different purpose. Every CRUD call takes the token again. File Manager verifies it when establishing the operation profile.
Operations
| Call | Required permissions | Result |
|---|---|---|
| write(token, buffer, target, options) | write(target) | Creates a file from a Buffer. Existing targets are protected unless overwrite is explicitly true. |
| read(token, target) | read(target) | Returns the whole file as a Buffer. |
| copyFile(token, source, target) | read(source) and write(target) | Copies into a new target and refuses to overwrite an existing file. |
| rename(token, source, name) | write(target) and delete(source) | Copies to the new name in the source directory, then deletes the source. Supply a plain filename. |
| move(token, source, target) | write(target) and delete(source) | Copies to another authorized relative path, then deletes the source. |
| delete(token, target) | delete(target) | Unlinks one file. Directory removal is outside this API. |
| list(token, target = '.') | list(directory) | Lists immediate children with name, type, size, createdAt, and modifiedAt. |
const readResult = await files.read(token, 'whorequest/note.txt')
if (!readResult.errors) {
const text = readResult.payload.toString('utf8')
}
const listing = await files.list(token, 'whorequest')
To replace an existing file, pass { overwrite: true } to write. The example profile denies delete, so rename, move, and delete fail until their required permissions are granted. A directory listing exposes child names and metadata independently of file-read permission.
Store an Upload from httpRestParser
As shown in the pack's README, httpRestParser decodes multipart/form-data uploads and exposes each file as a Buffer. File Manager stores the Buffer selected by the calling layer. httpRestParser is a library: place it after PPM in the library group, before runtime callers. The calling pack can declare "require": ["httpRestParser", "filemanager"].
This example continues inside whorequest with the token and files obtained above. Register receiveUpload with your HTTP routing layer after application-user authorization. The existing access profile and setup directory allow the destination whorequest/upload.bin.
const parser = libraries.require('httpRestParser')
if (!parser || typeof parser.receiver !== 'function') {
throw new Error('httpRestParser is unavailable')
}
async function receiveUpload(req, res) {
return parser.receiver(req, res, async received => {
// Parsing failures may already have closed the HTTP response.
if (received.errors) {
if (!res.writableEnded) {
parser.emitter.buffer(req, res, received)
}
return
}
const uploaded = received.payload?.files?.[0]
if (!uploaded || !Buffer.isBuffer(uploaded.buffer)) {
return parser.emitter.buffer(req, res, {
errors: true,
message: 'file not received',
payload: false
})
}
// Application code chooses the destination, independently of uploaded.filename.
const stored = await files.write(
token,
uploaded.buffer,
'whorequest/upload.bin'
)
return parser.emitter.buffer(req, res, stored)
})
}
The handler uses native Node.js request and response objects. With a framework adapter, supply its underlying objects. The example selects only the first uploaded file and refuses to overwrite an existing upload.bin. For multiple files, iterate received.payload.files and choose a distinct authorized destination for each Buffer. Inspect stored.errors when adding further application logic.
Configure serveropt.httpMultipartLimit to limit the whole buffered multipart request in bytes; the parser's supplied default is 10 MiB. File Manager remains independent from HTTP parsing, user authorization, storage quotas, and file expiration.
Current parser limitation: httpRestParser lowercases the whole Content-Type header, including the multipart boundary value. Boundaries containing uppercase letters can therefore be rejected even when the request is valid. This requires a correction in httpRestParser.
Results and Partial Failure
Operations return the same result envelope. Inspect errors before consuming payload.
{
errors: false,
message: 'Operation result',
payload: false
}
read returns a Buffer payload. list returns metadata entries. write returns the relative name and byte size. copyFile, rename, and move return source and target names. A failure returns errors=true, an explanatory message, and payload=false.
rename and move copy first and delete afterwards. If deletion fails, the target can remain alongside the source, and the result reports an error describing that situation. Reconcile the two paths before retrying. Explicit overwrite uses a normal file write and can truncate the previous contents. These operations provide no transaction or automatic rollback.
Security Scope
File Manager grants filesystem capabilities to a calling pack. With the supplied scope, targets stay under system-temp. The layer rejects absolute paths, parent traversal outside that root, null bytes, and colon-containing targets. It checks the root and path components with lstat and rejects symbolic links before reading or writing. Unless you have deliberately disabled Guardian checks, its gate also evaluates the resolved path against the provider's configured scope.
This makes the configured directory ownership important. The path checks and filesystem operation occur separately. Prevent other untrusted writers from replacing those paths between validation and I/O. The layer runs with the operating-system permissions of the Node.js process.
- Grant paths and operations deliberately. read=true can return any file content in the managed scope. write or delete can change data there. Keep unrelated callers in separate directories.
- Vault identifies the calling pack. Application-user authentication and authorization belong in the route or application layer that invokes File Manager. Choose destinations in application code before passing a client-supplied filename or path.
- read and write handle whole Buffers. The layer provides no file-size, storage, rate, or per-user quota. Apply the limits needed by uploads and public endpoints in their calling code.
- When Guardian checks are enabled, the temporary-directory check rejects executable and source files in that directory. Use this layer for managed data files and configure application build outputs separately.
Permission Cache and Lifecycle
A successfully verified token caches its decoded requester profile and the selected operation permissions until its expiry, normally ten minutes. Calls using that cached token reuse the saved permissions. Changes to manifests or configuration therefore do not immediately revoke a cached grant.
Expired cache entries are removed when the same token is presented again. detach clears the entire cache and publishes an inactive bundle state. Previously obtained function references can still call the implementation, so lifecycle changes alone do not revoke every retained JavaScript reference. Coordinate policy changes with the callers and restart the application when immediate revocation is required.
Documentation
This page is the HTML adaptation of the pack's readme.md, with practical clarifications checked against the implementation. Complete Staxis onboarding to request GitLab access to the official sources.