mirror of
https://github.com/hanzoai/notify.git
synced 2026-10-30 15:04:32 +00:00
Replaces the chi-based notifyd scaffold with the canonical
hanzoai/auto-style layout: hanzoai/base as the HTTP + SQLite + auth
substrate (via the platform plugin for IAM JWT validation and
X-Org-Id injection), hanzoai/tasks for durable async sends, and a
per-tenant Notifier resolver that pulls provider credentials from
KMS through platform.KMSClient.
Library at the module root stays untouched — all 33 provider impls
(plivo, twilio, ses, sendgrid, mail, whatsapp, discord, slack, …)
keep their existing public API. The service wraps them.
cmd/notifyd
- base.New + platform.MustRegister
- schema.MustRegister (6 collections: tenants, providers,
templates, events, messages, meter)
- tasks worker registered when TASKS_ADDR is set; sync path
runs the same Deliver activity directly when not
internal/
- boot/ thin platform.KMSClient wiring (env-driven)
- schema/ 6 base collections
- routes/ /v1/notify/{send,messages,providers,templates,events,metering,health}
+ convenience /send/{sms,email,voice,whatsapp}
- tenant/ KMS-backed resolver builds library Notifier per send
- template/ draft → pending → approved → published → archived
- event/ catalog routing (fills missing channel / template)
- metering/ per-send ledger writer + aggregate query
- tasks/ NotifySendWorkflow + Deliver activity (idempotent on
replay; reloads message row before resending)
- zaprpc/ procedure name constants (server impl follow-up)
pkg/
- client/ public HTTP SDK (Send / Message / Providers / Templates)
- types/ wire shapes shared by routes and client
cucloud: fmt.Errorf(msg) → errors.New(msg) for the go 1.26 vet pass
that landed with this dependency bump. Behaviour unchanged.
Boot smoke-tested locally:
- SQLite migrations apply cleanly
- /v1/notify/health returns {"service":"notify","status":"ok"}
- missing X-Org-Id returns 401 on every authenticated route
- send with stub tenant returns the expected base validation error
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package routes
|
|
|
|
import (
|
|
"github.com/hanzoai/base"
|
|
"github.com/hanzoai/base/apis"
|
|
"github.com/hanzoai/base/core"
|
|
"github.com/hanzoai/base/tools/router"
|
|
|
|
"github.com/hanzoai/notify/internal/metering"
|
|
)
|
|
|
|
// mountMetering installs GET /v1/notify/metering.
|
|
//
|
|
// Query params:
|
|
// from — RFC3339 lower bound (inclusive). Optional.
|
|
// to — RFC3339 upper bound (inclusive). Optional.
|
|
//
|
|
// The tenant scope comes from X-Org-Id; superadmin override via
|
|
// ?tenant= is intentionally not exposed on this surface — the billing
|
|
// roll-up runs out-of-cluster against the underlying SQLite directly.
|
|
func mountMetering(r *router.Router[*core.RequestEvent], app *base.Base) {
|
|
r.GET("/v1/notify/metering", func(e *core.RequestEvent) error {
|
|
org, err := orgFromRequest(e)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
q := e.Request.URL.Query()
|
|
summary, err := metering.Aggregate(app, org, q.Get("from"), q.Get("to"), 10000)
|
|
if err != nil {
|
|
return apis.NewInternalServerError("aggregate", err)
|
|
}
|
|
return jsonOK(e, summary)
|
|
})
|
|
}
|