Initial commit of Descrybe v2 without local scratch artifacts.

Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
2026-08-09 22:47:43 +02:00
commit 8580c996c3
1285 changed files with 325780 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
// Command sync-stripe-packs ensures each DefaultCreditPack exists in Stripe as a
// Product + one-time Price, then prints Price IDs (and optionally writes them to
// platform settings when -write-settings is set).
//
// go run ./cmd/sync-stripe-packs
// go run ./cmd/sync-stripe-packs -write-settings
package main
import (
"context"
"flag"
"fmt"
"os"
"strings"
"time"
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
"github.com/descrybe/descrybe-v2/apps/api/internal/platformsettings"
"github.com/jackc/pgx/v5/pgxpool"
)
func main() {
pg := flag.String("postgres", os.Getenv("DATABASE_URL"), "Postgres DATABASE_URL")
writeSettings := flag.Bool("write-settings", false, "Upsert stripe.price.pack.* into platform settings")
flag.Parse()
secret := strings.TrimSpace(os.Getenv("STRIPE_SECRET_KEY"))
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
var pool *pgxpool.Pool
var plat *platformsettings.Service
if strings.TrimSpace(*pg) != "" {
var err error
pool, err = pgxpool.New(ctx, *pg)
if err != nil {
fmt.Fprintf(os.Stderr, "connect: %v\n", err)
os.Exit(1)
}
defer pool.Close()
plat = &platformsettings.Service{Pool: pool}
if resolved, err := plat.ResolveStripe(ctx, billing.StripeConfig{SecretKey: secret}); err == nil {
if strings.TrimSpace(resolved.SecretKey) != "" {
secret = resolved.SecretKey
}
}
}
if secret == "" {
fmt.Fprintln(os.Stderr, "STRIPE_SECRET_KEY (or stripe.secret_key in admin settings) required")
os.Exit(1)
}
svc := &billing.StripeService{
Pool: pool,
Cfg: billing.StripeConfig{SecretKey: secret},
}
results, err := svc.SyncCreditPackProducts(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "sync: %v\n", err)
os.Exit(1)
}
fmt.Println("Stripe credit packs (one-time products):")
for _, r := range results {
flag := "ok"
if r.Created {
flag = "created/updated"
}
fmt.Printf(" %-8s $%-5d credits=%-6d price=%s product=%s (%s)\n",
r.PackID, r.PriceUSD, r.Credits, r.PriceID, r.ProductID, flag)
if *writeSettings {
if plat == nil {
fmt.Fprintln(os.Stderr, "-write-settings requires DATABASE_URL")
os.Exit(1)
}
key := billing.CreditPackSettingsKey(r.PackID)
if err := plat.SetKV(ctx, key, r.PriceID); err != nil {
fmt.Fprintf(os.Stderr, "write %s: %v\n", key, err)
os.Exit(1)
}
fmt.Printf(" wrote %s\n", key)
} else {
fmt.Printf(" settings key: %s\n", billing.CreditPackSettingsKey(r.PackID))
fmt.Printf(" env fallback: %s=%s\n", billing.CreditPackEnvVar(r.PackID), r.PriceID)
}
}
if !*writeSettings {
fmt.Println("\nRe-run with -write-settings to store Price IDs in platform settings.")
}
}