@streetjs/plugin-sendgrid
v1.0.1
Published
Official Street Framework plugin: SendGrid email. Signed manifest, PluginModule SDK.
Maintainers
Readme
@streetjs/plugin-sendgrid
Official StreetJS Framework plugin for SendGrid email.
It ships a PluginModule subclass that injects a SendGrid mail client into each
request via middleware. Request building (endpoint, bearer auth, JSON body) is pure
and offline-verifiable; the network send uses node:https. No third-party runtime
dependencies.
Install
npm install @streetjs/plugin-sendgridUsage
import { PluginHost, signManifest } from 'streetjs';
import { generateKeyPairSync } from 'node:crypto';
import SendGridPlugin, { sendGridPluginManifest } from '@streetjs/plugin-sendgrid';
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
const host = new PluginHost({
grantedPermissions: ['net', 'secrets', 'middleware'],
publicKey,
});
const plugin = new SendGridPlugin({
apiKey: process.env.SENDGRID_API_KEY,
defaultFrom: '[email protected]',
});
// Signature verification is enforced when the host has a public key.
host.register(plugin, signManifest(sendGridPluginManifest(), privateKey));
await host.enable(plugin.name);
// Inside a handler, the client is available on ctx.state.mail:
// await ctx.state.mail.send({ to: '[email protected]', subject: 'Hi', text: 'Hello' });Manifest
manifest.json— the unsigned plugin manifest (name, version, capabilities, permissions).manifest.signed.json— produced by the build (npm run build) viasignManifest()(SHA-256 checksum + Ed25519 signature). Provide a stable signing key through theSTREET_PLUGIN_SIGNING_KEYenvironment variable (PEM PKCS#8). Without it, the build generates an ephemeral dev keypair and writes the verifying public key tomanifest.pub.
Configuration
| Key | Required | Description |
| ------------- | -------- | ------------------------------------------------- |
| apiKey | yes | SendGrid API key. |
| defaultFrom | no | Default sender address when a message omits from. |
| stateKey | no | ctx.state key for the client (default mail). |
Example
A runnable example lives in example/.
License
MIT
