FaasJS Plugins And Runtime
Default Workflow
- Use plugins for cross-cutting business context such as auth, tenant, request metadata, and permission scope.
- Implement plugin lifecycle hooks with clear ownership, retry-safe mount initialization, and exactly one
next()call when required. - Provide injected field types through
DefineApiInjectmodule augmentation. - Prefer injected loggers when the framework provides one; create labeled loggers for standalone code.
- Keep
@faasjs/node-utilsusage in Node-only bootstrapping and tooling paths.
Load These References
- Plugin interface, lifecycle hooks, injected fields, config-driven loading, and tests:
references/guidelines/plugins.md. - Logger selection, levels, formatting, timing, and secret handling:
references/guidelines/logger.md. loadConfig,.envloading, module hooks, schema helpers, and path containment:references/guidelines/node-utils.md.
Gotchas
- Mutate
InvokeDatafor injected fields and document the type surface with module augmentation. - Keep
onMountretry-safe: concurrent callers share one attempt, and a later call may retry after failure. - Do not log secrets or full sensitive payloads.
- Keep module hook registration at process bootstrap.
Validation
- Test plugins with real
Funcinstances when behavior depends on lifecycle execution. - Cover shared mount success, shared mount failure, and later retry when
onMountowns resources. - Run focused tests with
vp test <pattern>. - Run
vp check --fixbefore handoff when plugin or runtime files changed.