diff --git a/docs.json b/docs.json index 5ea29e8..5bfd16f 100644 --- a/docs.json +++ b/docs.json @@ -31,7 +31,13 @@ }, { "group": "Client surfaces", - "pages": ["components", "customization"] + "pages": [ + "http-server", + "server-setup", + "components", + "customization", + "alert-rules" + ] } ] }, diff --git a/openapi.yaml b/openapi.yaml index 54ad4e0..58f9d7a 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1,13 +1,14 @@ openapi: 3.1.0 info: title: Pulseforge Events API - version: 1.0.0 + version: 1.1.0 description: Publish public service status and manage incident timelines. servers: - url: https://status.example.com tags: - name: Status - name: Incidents + - name: Alert rules paths: /v1/status: get: @@ -54,7 +55,91 @@ paths: responses: '200': description: Incident resolved + /v1/alert-rules: + get: + operationId: listAlertRules + tags: [Alert rules] + summary: List alert rules + security: [{ bearerAuth: [] }] + responses: + '200': + description: Every alert rule visible to the token + post: + operationId: createAlertRule + tags: [Alert rules] + summary: Create an alert rule + description: Route selected incident events to an email or HTTPS webhook destination. + security: [{ bearerAuth: [] }] + responses: + '201': + description: Alert rule created and enabled + '400': + description: Invalid destination or cooldown + /v1/alert-rules/{ruleId}: + get: + operationId: getAlertRule + tags: [Alert rules] + summary: Get an alert rule + security: [{ bearerAuth: [] }] + parameters: + - $ref: '#/components/parameters/RuleId' + responses: + '200': + description: Alert rule details + '404': + description: Alert rule not found + patch: + operationId: updateAlertRule + tags: [Alert rules] + summary: Update an alert rule + description: Change routing, pause delivery, or adjust the cooldown. + security: [{ bearerAuth: [] }] + parameters: + - $ref: '#/components/parameters/RuleId' + responses: + '200': + description: Alert rule updated + delete: + operationId: deleteAlertRule + tags: [Alert rules] + summary: Delete an alert rule + security: [{ bearerAuth: [] }] + parameters: + - $ref: '#/components/parameters/RuleId' + responses: + '204': + description: Alert rule deleted + /v1/alert-rules/{ruleId}/test: + post: + operationId: testAlertRule + tags: [Alert rules] + summary: Record a test alert + description: Record a synthetic delivery attempt in the reference store. + security: [{ bearerAuth: [] }] + parameters: + - $ref: '#/components/parameters/RuleId' + responses: + '202': + description: Test delivery accepted + /v1/alert-rules/{ruleId}/deliveries: + get: + operationId: listAlertDeliveries + tags: [Alert rules] + summary: List alert delivery history + security: [{ bearerAuth: [] }] + parameters: + - $ref: '#/components/parameters/RuleId' + responses: + '200': + description: Delivery attempts for the alert rule components: + parameters: + RuleId: + in: path + name: ruleId + required: true + schema: + type: string securitySchemes: bearerAuth: type: http diff --git a/src/content/alert-rules.mdx b/src/content/alert-rules.mdx new file mode 100644 index 0000000..f35e9ce --- /dev/null +++ b/src/content/alert-rules.mdx @@ -0,0 +1,153 @@ +--- +title: Alert rules +description: Route incident events to email or webhook destinations with reusable alert rules. +--- + +Alert rules route incident events to email or webhook destinations, decoupling your incident creation logic from notification infrastructure. + +## What are alert rules? + +A rule selects which incident events trigger notifications (for example, +`incident.opened` or `incident.resolved`), specifies where to send them (email +or webhook), and can include a delivery cooldown to reduce alert fatigue. + +Each rule is independent, reusable, and available through the REST API and typed SDK methods. + +## Create a rule + +Use the SDK to set up a rule that sends new incidents to a webhook: + +```ts +import { createPulseforgeClient } from "@pulseforge/events/sdk"; + +const pulseforge = createPulseforgeClient({ + baseUrl: "https://status.example.com", + token: process.env.PULSEFORGE_TOKEN, +}); + +const rule = await pulseforge.createAlertRule({ + name: "Critical incident webhook", + eventTypes: ["incident.opened"], + destination: { + kind: "webhook", + target: "https://alerts.internal.example.com/incidents", + }, + cooldownSeconds: 300, +}); +``` + +## Destination types + +### Email + +Send alerts to a single email address: + +```ts +destination: { + kind: "email", + target: "team@example.com", +} +``` + +### Webhook + +Webhook destinations must use HTTPS: + +```ts +destination: { + kind: "webhook", + target: "https://alerts.internal.example.com/incidents", +} +``` + +## Manage rules + +### List all rules + +```ts +const rules = await pulseforge.listAlertRules(); +``` + +### Get a specific rule + +```ts +const rule = await pulseforge.getAlertRule(ruleId); +``` + +### Update a rule + +Change the destination, cooldown, or pause delivery without recreating it: + +```ts +await pulseforge.updateAlertRule(ruleId, { + destination: { + kind: "email", + target: "new-team@example.com", + }, + isEnabled: true, +}); +``` + +### Delete a rule + +```ts +await pulseforge.deleteAlertRule(ruleId); +``` + +## Test a rule + +The reference store records a synthetic successful delivery so you can verify +rule configuration and delivery-history handling. A production adapter should +replace this simulation with a real destination check: + +```ts +const result = await pulseforge.testAlertRule(ruleId); +console.log(result.delivery.status); // "delivered" in the reference store +``` + +## View delivery history + +Inspect the most recent delivery attempts for a rule: + +```ts +const deliveries = await pulseforge.listAlertDeliveries(ruleId); +deliveries.forEach((d) => { + console.log(`${d.eventType}: ${d.status} at ${d.attemptedAt}`); +}); +``` + +## Embed the alert center + +Display alert rules in your operator dashboard using the `` web component. Register it once in your app: + +```html + +``` + +Then add the component to your page and assign an authenticated client: + +```html + + + +``` + +The component displays the count of configured rules and exposes a `refresh()` method to reload them after mutations. + + + Do not persist an incident-management token in browser storage or expose it + through markup. Supply a short-lived operator credential from your existing + authenticated application session. + diff --git a/src/content/changelog.mdx b/src/content/changelog.mdx index 95f0df6..d5fd201 100644 --- a/src/content/changelog.mdx +++ b/src/content/changelog.mdx @@ -3,6 +3,12 @@ title: Changelog description: Pulseforge Events product and documentation updates. --- +## 1.1.0 — 2026-08-16 + +- Added alert-rule creation, updates, deletion, test delivery, and history. +- Added seven alert-rule operations to the REST API and browser SDK. +- Added the authenticated `pulseforge-alert-center` operator widget. + ## 1.0.0 — 2026-08-16 - Added public status reads and authenticated incident management. diff --git a/src/content/components.mdx b/src/content/components.mdx index 14aa2e3..47d3611 100644 --- a/src/content/components.mdx +++ b/src/content/components.mdx @@ -19,9 +19,22 @@ const pulseforge = createPulseforgeClient({ Omit `token` for calls that only read public status. -## Incident methods +## Status and incidents - `getStatus()` reads public service status. - `createIncident(input)` opens an incident. - `addIncidentUpdate(id, input)` extends its timeline. - `resolveIncident(id)` marks it resolved. + +## Alert rules + +Alert rules route incident events to email or webhook destinations. See +[Alert rules](/alert-rules) for full details and examples. + +- `listAlertRules()` returns all configured rules. +- `getAlertRule(id)` fetches a single rule. +- `createAlertRule(input)` creates a new rule. +- `updateAlertRule(id, input)` modifies a rule. +- `deleteAlertRule(id)` removes a rule. +- `testAlertRule(id)` records a synthetic delivery in the reference store. +- `listAlertDeliveries(id)` shows recent delivery attempts. diff --git a/src/content/http-server.mdx b/src/content/http-server.mdx new file mode 100644 index 0000000..0a938e8 --- /dev/null +++ b/src/content/http-server.mdx @@ -0,0 +1,87 @@ +--- +title: Deploy the HTTP handler +description: Serve the Pulseforge API from a runtime that accepts Fetch API requests. +--- + +`createPulseforgeApp` returns a function that accepts a web-standard `Request` +and returns a `Response`. Use it directly in a Fetch-compatible runtime or add +an explicit adapter for your Node.js framework. + +## Create the handler + +```ts +import { createPulseforgeApp, createPulseforgeStore } from "@pulseforge/events"; + +const store = createPulseforgeStore([ + { id: "api", name: "Events API", status: "operational" }, + { id: "database", name: "Database", status: "operational" }, +]); + +const app = createPulseforgeApp({ + store, + token: process.env.PULSEFORGE_TOKEN, +}); +``` + +Do not pass `app` directly to `node:http.createServer`: Node handlers receive +`IncomingMessage` and `ServerResponse`, not Fetch API request objects. Convert +those values through a tested adapter, or use a runtime with a native Fetch +entry point. + +## Cloudflare Workers + +Create the handler inside `fetch` so the management token comes from a Worker +secret rather than source code or a URL: + +```ts +import { createPulseforgeApp, createPulseforgeStore } from "@pulseforge/events"; + +interface Env { + PULSEFORGE_TOKEN: string; +} + +export default { + fetch(request: Request, env: Env) { + const app = createPulseforgeApp({ + store: createPulseforgeStore(), + token: env.PULSEFORGE_TOKEN, + }); + + return app(request); + }, +}; +``` + +The included store is in-memory and does not provide durable Worker storage. +Use a persistent store adapter before relying on it for production incidents. + +## Endpoints + +### Public status + +- `GET /v1/status` — Read service status and active incidents without authentication. + +### Incident management + +- `POST /v1/incidents` — Create an incident. +- `POST /v1/incidents/:id/updates` — Add a timeline update. +- `PATCH /v1/incidents/:id/resolve` — Resolve an incident. + +### Alert rules + +- `GET /v1/alert-rules` — List rules. +- `POST /v1/alert-rules` — Create a rule. +- `GET /v1/alert-rules/:id` — Fetch a rule. +- `PATCH /v1/alert-rules/:id` — Update a rule. +- `DELETE /v1/alert-rules/:id` — Delete a rule. +- `POST /v1/alert-rules/:id/test` — Record a synthetic delivery test. +- `GET /v1/alert-rules/:id/deliveries` — List delivery history. + +Except for public status, every operation requires: + +```http +Authorization: Bearer YOUR_TOKEN +``` + +Use the [Browser SDK](/components) to call the same operations with typed input +and output, or review the generated [API reference](/api) for every endpoint. diff --git a/src/content/introduction.mdx b/src/content/introduction.mdx index 6e7752e..708abf9 100644 --- a/src/content/introduction.mdx +++ b/src/content/introduction.mdx @@ -1,6 +1,8 @@ --- title: Pulseforge Events -description: Publish service status, manage incident timelines, and embed current availability. +description: >- + Publish service status, manage incident timelines, and embed current + availability. mode: home --- @@ -20,12 +22,18 @@ a dependency-free status widget. Incident state flows through the same public contracts on every surface. + + Set up the HTTP request handler for your runtime environment. + Create an incident and publish the first timeline update. Call the Pulseforge API with typed request and response objects. + + Set up rules to send incident events to email or webhook destinations. + Review every status and incident endpoint from the OpenAPI reference. @@ -40,6 +48,6 @@ The status endpoint is public. Incident mutations require a bearer token and should run only from trusted server-side code. - The bundled store is in-memory. Supply durable storage before using - Pulseforge in a production incident workflow. + The bundled store is in-memory. Supply durable storage before using Pulseforge + in a production incident workflow. diff --git a/src/content/server-setup.mdx b/src/content/server-setup.mdx new file mode 100644 index 0000000..695bb2c --- /dev/null +++ b/src/content/server-setup.mdx @@ -0,0 +1,81 @@ +--- +title: Server-side setup +description: Create and manage incident state using the Pulseforge store. +--- + +## Create a store + +The `createPulseforgeStore` function initializes in-memory incident and alert rule state. Use it on your backend to manage the complete lifecycle of incidents, updates, and alert routing: + +```ts +import { createPulseforgeStore } from "@pulseforge/events"; + +const store = createPulseforgeStore([ + { id: "api", name: "Events API", status: "operational" }, + { id: "db", name: "Database", status: "operational" }, +]); +``` + +By default, `createPulseforgeStore` initializes one service called "Events API". Pass an array of services to define your status page structure. + +## Incident operations + +### Create an incident + +```ts +const incident = store.createIncident({ + title: "High delivery latency detected", + severity: "degraded", + serviceIds: ["api"], +}); +``` + +### Add timeline updates + +```ts +store.addIncidentUpdate(incident.id, { + message: "Scaling database connections in progress", + status: "investigating", +}); +``` + +### Resolve an incident + +```ts +store.resolveIncident(incident.id); +``` + +## Check system status + +```ts +const status = store.getStatus(); +console.log(status.status); // "operational", "degraded", or "outage" +console.log(status.activeIncidents); // incidents not yet resolved +``` + +## Alert rules + +The store extends the alert rule registry, so you can manage rules through the same interface: + +```ts +const rule = store.createAlertRule({ + name: "Page on critical incidents", + eventTypes: ["incident.opened"], + destination: { + kind: "webhook", + target: "https://alerts.example.com/critical", + }, + cooldownSeconds: 300, +}); + +const allRules = store.listAlertRules(); +const testResult = store.testAlertRule(rule.id); +``` + +See [Alert rules](/alert-rules) for the full reference of rule management methods. + + + The store is in-memory only. Incidents and rules are lost when the process + restarts. For production use, persist store data to a durable backend and + restore it on startup. +