feat(erp): erpsetup for live ERPNext, reserved tenant slugs (#32)
ci / shared (push) Successful in 12s
ci / test (push) Successful in 22m58s
ci / image (push) Successful in 37s

This commit was merged in pull request #32.
This commit is contained in:
sharang committed 2026-09-23 17:16:24 +00:00
1 parent 13da983d1e
commit ceeff16f26
8 files changed
+587 -2

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
// erpsetup — applies the live-ERPNext configuration the tenant-registry needs
// (custom fields, the Usage Record doctype, the Frappe Webhooks). Idempotent;
// run with -dry-run first. It never submits, cancels or deletes ERP documents.
//
// ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… \
// ERP_WEBHOOK_SECRET=… erpsetup -webhook-url https://registry.breakpilot.com/v1/internal/erp/webhook -dry-run
//
// The API user needs System Manager for this run (it creates a DocType and
// Webhooks); the registry's day-to-day key can then have a narrower role.
package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"git.breakpilot.com/platform/tenant-registry/internal/erpsetup"
)
func main() {
dry := flag.Bool("dry-run", false, "report what would be created, change nothing")
hook := flag.String("webhook-url", "", "registry webhook receiver, e.g. https://registry.breakpilot.com/v1/internal/erp/webhook")
lead := flag.String("lead-doctype", envOr("ERP_LEAD_DOCTYPE", "Lead"), `"Lead" (ERPNext) or "CRM Lead" (Frappe CRM)`)
flag.Parse()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
steps, err := erpsetup.Run(ctx, erpsetup.Config{
BaseURL: os.Getenv("ERP_BASE_URL"),
APIKey: os.Getenv("ERP_API_KEY"),
APISecret: os.Getenv("ERP_API_SECRET"),
WebhookURL: *hook,
WebhookSecret: os.Getenv("ERP_WEBHOOK_SECRET"),
LeadDoctype: *lead,
DryRun: *dry,
Log: func(f string, a ...any) { fmt.Printf(f+"\n", a...) },
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("%d steps, done%s\n", len(steps), map[bool]string{true: " (dry run, nothing changed)", false: ""}[*dry])
}
func envOr(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}