Repository navigation
fix(billing,dashboard): Stripe item period end + dashboard NEXT_PUBLIC_* build args - #745
Merged
Merged
Conversation
…LIC_* at build stripeSubscriptionPeriodEndUnix now falls back to the latest items.data[].current_period_end when the top-level field is absent (stripe@22 default API dahlia / basil+ webhook payloads), so checkout.session.completed no longer stores a null period end. Integration mocks use the dahlia subscription shape. The root Dockerfile declares every NEXT_PUBLIC_* the dashboard reads as a build ARG so Railway passes them into next build. Unset values behave as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Base branch:
develop.Summary
Fix 1 — billing period end (Stripe dahlia)
stripeSubscriptionPeriodEndUnixonly read top-levelcurrent_period_end. The API usesstripe@22with noapiVersionpin → SDK default2026-03-25.dahlia, where (since2025-03-31.basil) a Subscription carries the period end only onitems.data[].current_period_end. Socheckout.session.completed(subscriptions.retrieve) storedstripe_current_period_end = null.Now: top-level when it is a number (acacia-and-older webhook payloads), else the max of
items.data[].current_period_end, elsenull.Callers checked:
checkout.session.completed→stripe.subscriptions.retrieve(dahlia SDK object) — fixed.customer.subscription.updated→subscriptionToOrgSyncPatch(webhook payload; shape follows the endpoint's API version) — works for both.customer.subscription.deleted→ canceled emailperiodEnd(webhook payload) — works for both (DB column is still cleared to null as before).current_period_endinapps/api/src.Tests:
stripe-runtime-fields.test.ts(top-level, top-level preferred, items-only, max of items, garbage/null cases);stripe-subscription-sync.test.ts(items-only dahlia shape).billing-checkout,affiliates,affiliates-protectionsnow use the dahlia shape (period end only on items).billing-checkoutflag-OFF test assertsstripe_subscription_status = activeandstripe_current_period_endequals the item period end — verified it fails on the old implementation and passes with the fix.Fix 2 — dashboard
NEXT_PUBLIC_*at buildThe root
Dockerfileonly passedNEXT_PUBLIC_AFFILIATES_ENABLEDintonext build, so other configured values (prod bundles show un-inlinedNEXT_PUBLIC_SENTRY_DSN,NEXT_PUBLIC_TELEMETRY_INGEST_URL/_API_KEY/_APP) never reached the browser. AddedARG+ENVfor everyNEXT_PUBLIC_*the dashboard code actually reads:NEXT_PUBLIC_AFFILIATES_ENABLEDNEXT_PUBLIC_DASHBOARD_DEBUGOverviewApiResponseLogger)=== "1"NEXT_PUBLIC_GA_MEASUREMENT_ID?.trim()NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION?.trim()NEXT_PUBLIC_SENTRY_DSNNEXT_PUBLIC_SITE_URL?.trim()NEXT_PUBLIC_TELEMETRY_API_KEYNEXT_PUBLIC_TELEMETRY_APP?.trim() || defaultNEXT_PUBLIC_TELEMETRY_INGEST_URL?.trim()NEXT_PUBLIC_TELEMETRY_PUBLIC_DASHBOARD=== "true"Excluded:
NEXT_PUBLIC_TT_RELEASE(appears only inside docs code-snippet strings, not read).Unset behavior: an unset ARG becomes
""; every read site uses?.trim()falsy checks,|| default, or=== "…", so""behaves exactly like unset (feature off / default).Secrets: none of these is a private key —
NEXT_PUBLIC_*ships to browsers by design (Sentry DSN and thett_live_ingest key are documented as client-safe). No secret build args were added; Sentry source-map upload (SENTRY_AUTH_TOKEN) is intentionally not passed into the image build (thewithSentryConfigupload stays inactive as today).Behavior change on the next dashboard rebuild (intended): browser Sentry and dashboard product telemetry, which were configured on Railway but never inlined, start working. Server-side reads of these vars become build-time values (same values as set on Railway, which rebuilds on variable change).
Docs:
DEPLOYMENT.md(Dashboard: build-timeNEXT_PUBLIC_*, keep the Dockerfile list in sync, no secrets),docs/AFFILIATES.mdcross-link,CHANGELOG.md[Unreleased].How to test
pnpm lint✅pnpm testwithRUN_DB_INTEGRATION_TESTS=trueagainst local Postgres 17 ✅ (api 1164 passed / 8 skipped; all workspaces green). Note: locally 4 unrelated brief/dashboard-query integration tests fail only when the Postgres server timezone is not UTC (same ondevelop); withtimezone=UTC(as in CI) all pass.tsc -p tsconfig.build.json --noEmit(api) ✅hadolint Dockerfile→ only the pre-existing DL3008 warning.Code review (Bugbot)
Checklist
[Unreleased]updatedSecurity / privacy
Only public, browser-exposed
NEXT_PUBLIC_*values are passed as build args. No secrets.