Skip to content

fix(billing,dashboard): Stripe item period end + dashboard NEXT_PUBLIC_* build args - #745

Merged
unjica merged 1 commit into
developfrom
fix/stripe-period-end-and-dashboard-public-env
Oct 6, 2026
Merged

unjica merged 1 commit into
developfrom
fix/stripe-period-end-and-dashboard-public-env

Conversation

@unjica

@unjica unjica commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Base branch: develop.

Summary

Fix 1 — billing period end (Stripe dahlia)

stripeSubscriptionPeriodEndUnix only read top-level current_period_end. The API uses stripe@22 with no apiVersion pin → SDK default 2026-03-25.dahlia, where (since 2025-03-31.basil) a Subscription carries the period end only on items.data[].current_period_end. So checkout.session.completed (subscriptions.retrieve) stored stripe_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, else null.

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 email periodEnd (webhook payload) — works for both (DB column is still cleared to null as before).
  • No other callers of current_period_end in apps/api/src.

Tests:

  • Unit: 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).
  • Integration: subscription mocks in billing-checkout, affiliates, affiliates-protections now use the dahlia shape (period end only on items). billing-checkout flag-OFF test asserts stripe_subscription_status = active and stripe_current_period_end equals the item period end — verified it fails on the old implementation and passes with the fix.

Fix 2 — dashboard NEXT_PUBLIC_* at build

The root Dockerfile only passed NEXT_PUBLIC_AFFILIATES_ENABLED into next build, so other configured values (prod bundles show un-inlined NEXT_PUBLIC_SENTRY_DSN, NEXT_PUBLIC_TELEMETRY_INGEST_URL / _API_KEY / _APP) never reached the browser. Added ARG + ENV for every NEXT_PUBLIC_* the dashboard code actually reads:

Variable Read in Notes
NEXT_PUBLIC_AFFILIATES_ENABLED client + server action already present
NEXT_PUBLIC_DASHBOARD_DEBUG client (OverviewApiResponseLogger) === "1"
NEXT_PUBLIC_GA_MEASUREMENT_ID server (root layout) ?.trim()
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION server (root layout metadata) ?.trim()
NEXT_PUBLIC_SENTRY_DSN client (browser Sentry init) public DSN by design
NEXT_PUBLIC_SITE_URL server (metadata, robots, sitemap) ?.trim()
NEXT_PUBLIC_TELEMETRY_API_KEY client (product telemetry) public ingest key by design
NEXT_PUBLIC_TELEMETRY_APP client ?.trim() || default
NEXT_PUBLIC_TELEMETRY_INGEST_URL client ?.trim()
NEXT_PUBLIC_TELEMETRY_PUBLIC_DASHBOARD middleware === "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 the tt_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 (the withSentryConfig upload 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-time NEXT_PUBLIC_*, keep the Dockerfile list in sync, no secrets), docs/AFFILIATES.md cross-link, CHANGELOG.md [Unreleased].

How to test

  • pnpm lint ✅
  • pnpm test with RUN_DB_INTEGRATION_TESTS=true against 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 on develop); with timezone=UTC (as in CI) all pass.
  • tsc -p tsconfig.build.json --noEmit (api) ✅
  • hadolint Dockerfile → only the pre-existing DL3008 warning.

Code review (Bugbot)

Paused: GitHub bugbot-review is currently a no-op.

Checklist

  • Tests pass
  • Lint passes
  • CHANGELOG [Unreleased] updated
  • Documentation updated
  • No breaking changes

Security / privacy

Only public, browser-exposed NEXT_PUBLIC_* values are passed as build args. No secrets.

…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.
@unjica
unjica merged commit c5de836 into develop Oct 6, 2026
7 checks passed
@unjica unjica mentioned this pull request Oct 6, 2026
4 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant