S3Plugin is the first official reference plugin for the StreetJS
plugin system. It provides AWS S3 object storage, built on the
framework’s existing AWS SigV4 signer and S3StorageAdapter — no AWS SDK, no
third-party dependencies.
It demonstrates the full plugin contract: a signed manifest, capability
metadata, an explicit permission declaration, a validated configuration schema,
lifecycle hooks, and sandbox middleware integration.
import{generateKeyPairSync}from'node:crypto';import{PluginHost,signManifest,S3Plugin,s3PluginManifest}from'streetjs';const{publicKey,privateKey}=generateKeyPairSync('ed25519');consthost=newPluginHost({grantedPermissions:['net','secrets','middleware'],publicKey,// host now requires a valid signature to register});constmanifest=signManifest(s3PluginManifest(),privateKey);host.register(newS3Plugin({bucket:'my-bucket',region:'us-east-1',accessKeyId:process.env.AWS_ACCESS_KEY_ID!,secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY!,prefix:'tenants/acme',}),manifest);awaithost.enable('street-plugin-s3');
Using it in request handling
On load the plugin registers a middleware that injects an S3StorageAdapter
into ctx.state[stateKey] (default s3). Mount the plugin’s middleware in your
pipeline and use it from any handler:
1
2
3
4
5
6
for (constmwofhost.middlewaresOf('street-plugin-s3'))app.use(mw);// in a handler:consts3=ctx.state['s3'];// S3StorageAdapterawaits3.write('reports/2025.csv',stream);constdata=awaits3.read('reports/2025.csv');
Lifecycle
Hook
Behaviour
onInstall
Validates configuration once (fails enable on bad config).
onLoad
Builds the S3StorageAdapter and registers the injector middleware.
onUnload
Releases the adapter (plugin.storage then throws until reloaded).
Offline-verifiable signing
signedObjectHeaders(method, key, payloadHash, now?) returns deterministic AWS
SigV4 headers for an object request, enabling signing verification without any
network call: