Abo-Spiegel: fehlt ein neues Feld in Appwrite, wird ohne dieses Feld gespiegelt

Schützt Webhooks und den öffentlichen Kündigungs-/Widerrufsknopf, falls das
Setup-Skript erst nach dem Deploy läuft; der Fehler steht laut im Log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-09-27 15:45:54 +00:00
1 parent dc61649228
commit 2694ef18d6
2 files changed
+71 -1

No files matched your search

+20 -1
View File
@@ -138,7 +138,7 @@ function periodEndOf(sub) {
return sub.current_period_end || sub.items?.data?.[0]?.current_period_end || null
}
async function upsertSubscriptionDoc(id, data) {
async function writeSubscriptionDoc(id, data) {
const existing = await getDocument(config.collections.subscriptions, id).catch(() => null)
if (existing) return updateDocument(config.collections.subscriptions, id, data)
try {
@@ -150,6 +150,25 @@ async function upsertSubscriptionDoc(id, data) {
}
}
async function upsertSubscriptionDoc(id, data) {
let fields = data
for (;;) {
try {
return await writeSubscriptionDoc(id, fields)
} catch (err) {
// Neues Feld noch nicht in Appwrite (Setup-Skript nicht gelaufen): ohne das Feld spiegeln,
// damit Webhooks und der öffentliche Kündigungs-/Widerrufsknopf weiter funktionieren
const missing = err.status === 400 && /Unknown attribute: "(\w+)"/.exec(err.message || '')?.[1]
if (!missing || !(missing in fields)) throw err
console.error(
`[stripe] Appwrite kennt das Feld "${missing}" nicht (scripts/setup-abo-collections.mjs ausführen) – Abo ${id} ohne dieses Feld gespiegelt`
)
const { [missing]: _dropped, ...rest } = fields
fields = rest
}
}
}
/** Stripe-Subscription frisch laden und nach Appwrite spiegeln. */
export async function syncSubscription(subscriptionId) {
const stripe = getStripe()