Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.9.0] - 2026-11-10

### Changed

- **After checkout, people land back in the app.** A completed checkout or a Free plan pick now returns to the subscription page with a "You're on Pro now" banner, with no separate confirmation step. Set `billing.successRoute` to land on any page of your app, and put `<bridge-checkout-notice />` there for the same banner, or read the `checkoutResult` signal for a message of your own. The old confirmation page at `/subscription/success` still works for apps that point to it.
- **A subscription page that fits your app.** Plan cards and the current-plan panel have their own surface built from your `--bridge-*` tokens, so they look right on any app background. Prices are shown large and formatted for their currency, buttons say "Upgrade to" or "Switch to", the current plan is marked in your primary colour, and its renewal date and card are shown. Two optional tokens, `--bridge-card-bg` and `--bridge-card-shadow`, tune the cards. Plan buttons no longer read "Select free plan" or "29 USD / month", so tests that match that text need updating.
- **Bridge pages follow your app's text.** Every text size on the sign-in and subscription pages now scales from your page's body text size, alongside the font family and text colour they already inherited. At the usual 16px nothing changes; set `--bridge-font-size` to size Bridge text differently.
- **Your CSS always wins.** Bridge's styles now live in a CSS cascade layer named `bridge`, so any normal CSS you write against a Bridge class or data attribute overrides it, whatever the load order or specificity, with no `!important`. CSS inside one of your own layers declared before `bridge`, including Tailwind utility classes on Bridge's elements, still ranks below it.

### Added

- **Weight and shadow settings.** `--bridge-font-weight-heading`, `--bridge-font-weight-button`, `--bridge-font-weight-label` and `--bridge-button-shadow` let an app with heavy type or hard drop shadows carry that look onto the Bridge pages. `--bridge-card-shadow` also styles the plan-change dialog. Every default is the previous look.
- **The same subscription page as the other Bridge packages.** The Angular pages now match bridge-svelte 0.9.3: the same layout, wording and settings.

## [0.8.1] - 2026-11-04

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion bridge-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nebulr-group/bridge-angular",
"version": "0.8.1",
"version": "0.9.0",
"description": "The Bridge for Angular: sign-in, workspaces and roles, feature flags, Stripe subscriptions and plan limits with providers and route helpers.",
"author": "Iman Pouya",
"license": "MIT",
Expand Down
71 changes: 71 additions & 0 deletions bridge-angular/src/lib/billing/checkout-result.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* TBP-944 (svelte TBP-813) — the one-shot "a checkout just finished" signal the
* landing page reads. In memory only; whoever shows it clears it, so it shows once.
*/
import { effect, Injector, runInInjectionContext } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { afterEach, describe, expect, it } from 'vitest';
import {
checkoutResult,
clearCheckoutResult,
markCheckoutComplete,
takeCheckoutResult,
} from './checkout-result';

afterEach(() => clearCheckoutResult());

describe('checkoutResult (TBP-944)', () => {
it('starts empty', () => {
expect(checkoutResult()).toBeNull();
expect(takeCheckoutResult()).toBeNull();
});

it('markCheckoutComplete sets what the signal reads', () => {
markCheckoutComplete({ kind: 'checkout' });
expect(checkoutResult()).toEqual({ kind: 'checkout' });
});

it('carries the plan name of a Free pick', () => {
markCheckoutComplete({ kind: 'plan', planName: 'Free' });
expect(checkoutResult()).toEqual({ kind: 'plan', planName: 'Free' });
});

it('a later result replaces an earlier one', () => {
markCheckoutComplete({ kind: 'plan', planName: 'Free' });
markCheckoutComplete({ kind: 'checkout' });
expect(checkoutResult()).toEqual({ kind: 'checkout' });
});

it('takeCheckoutResult returns the result once, then nothing', () => {
markCheckoutComplete({ kind: 'plan', planName: 'Pro' });
expect(takeCheckoutResult()).toEqual({ kind: 'plan', planName: 'Pro' });
expect(takeCheckoutResult()).toBeNull();
expect(checkoutResult()).toBeNull();
});

it('clearCheckoutResult forgets it without showing it', () => {
markCheckoutComplete({ kind: 'checkout' });
clearCheckoutResult();
expect(checkoutResult()).toBeNull();
expect(takeCheckoutResult()).toBeNull();
});

it('an effect reading it sees it set and then cleared', () => {
const seen: unknown[] = [];
const injector = TestBed.inject(Injector);
const ref = runInInjectionContext(injector, () => effect(() => seen.push(checkoutResult())));
TestBed.flushEffects();
markCheckoutComplete({ kind: 'checkout' });
TestBed.flushEffects();
takeCheckoutResult();
TestBed.flushEffects();
ref.destroy();
expect(seen).toEqual([null, { kind: 'checkout' }, null]);
});

it('the exported signal is read-only: apps cannot set it', () => {
expect(typeof checkoutResult).toBe('function');
expect((checkoutResult as unknown as { set?: unknown }).set).toBeUndefined();
expect((checkoutResult as unknown as { update?: unknown }).update).toBeUndefined();
});
});
50 changes: 50 additions & 0 deletions bridge-angular/src/lib/billing/checkout-result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* TBP-944 (svelte TBP-813) — "a checkout just finished", for whichever page it
* lands on.
*
* A completed checkout used to stop on a confirmation page
* (`/subscription/success`) before going anywhere. It now lands on
* `billing.successRoute` (the subscription page by default), and this one-shot
* signal is how that page knows to say so: `<bridge-checkout-notice>` shows it
* as a banner, and an app that wants its own message reads `checkoutResult`.
*
* In memory only, never in the URL or storage: the checkout return navigates
* inside the running app, so the signal is still here when the landing page
* renders, and a reload (or a later visit) does not show it again. Whoever
* shows it clears it.
*
* Plain module-level signals rather than a service, so the OAuth-callback
* resolver and the plan picker can set it without an injection context, and an
* app can read it from a template, a `computed` or an `effect`.
*/
import { signal, type Signal } from '@angular/core';

/** What just completed. */
export interface BridgeCheckoutResult {
/** `checkout`: a paid Stripe checkout returned. `plan`: a plan was set without one (a Free pick). */
kind: 'checkout' | 'plan';
/** The plan's name, when the page that set it knew it. Otherwise read the current plan. */
planName?: string;
}

const result = signal<BridgeCheckoutResult | null>(null);

/** The checkout that just completed, or `null`. Cleared once something shows it. Read-only. */
export const checkoutResult: Signal<BridgeCheckoutResult | null> = result.asReadonly();

/** Record a completed checkout or plan pick. Called by the plugin, not by apps. */
export function markCheckoutComplete(value: BridgeCheckoutResult): void {
result.set(value);
}

/** Read the result and clear it, so it is shown once. */
export function takeCheckoutResult(): BridgeCheckoutResult | null {
const value = result();
if (value) result.set(null);
return value;
}

/** Forget the result without showing it. */
export function clearCheckoutResult(): void {
result.set(null);
}
29 changes: 16 additions & 13 deletions bridge-angular/src/lib/components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import { AuthService } from '../../shared/services/auth.service';
</button>
`,
styles: [`
.login-button {
display: inline-block;
padding: 0.5rem 1rem;
background-color: #3b82f6;
color: white;
border-radius: 0.25rem;
border: none;
cursor: pointer;
font-size: 0.875rem;
transition: background-color 0.2s;
}
/* TBP-944 — in the \`bridge\` layer with the stylesheet, so any CSS of the app wins. */
@layer bridge {
.login-button {
display: inline-block;
padding: 0.5rem 1rem;
background-color: #3b82f6;
color: white;
border-radius: 0.25rem;
border: none;
cursor: pointer;
font-size: calc(0.875 * var(--bridge-text-base, 1rem));
transition: background-color 0.2s;
}

.login-button:hover {
background-color: #2563eb;
.login-button:hover {
background-color: #2563eb;
}
}
`],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type BridgePageOptions,
} from '../../routing/bridge-routes';
import { resolveCallbackTarget } from '../../routing/callback';
import { markCheckoutComplete } from '../../billing/checkout-result';
import { routeSegments } from '../../routing/route-path';
import { logger } from '../../shared/logger';
import { AuthService } from '../../shared/services/auth.service';
Expand Down Expand Up @@ -216,6 +217,9 @@ export class BridgeAuthPageComponent implements OnInit {
handleCallback: (code) => this.auth.handleCallback(code),
confirmStripeCheckout: (id) => this.auth.confirmStripeCheckout(id),
refreshBilling: () => this.auth.loadSubscription(),
// TBP-944 — the landing page (the subscription page by default) says
// the checkout went through; no separate confirmation page.
completeCheckout: () => markCheckoutComplete({ kind: 'checkout' }),
takeReturnTo,
logError: (message, err) => logger.error(message, err),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/**
* TBP-744 — the component every `bridgeBillingRoutes()` page renders. Angular
* port of bridge-svelte's `<BridgeBillingRoutes>` body:
* manage the current plan, "Manage billing" and the plan picker
* manage the current plan, "Manage billing" and the plan picker; a
* completed checkout lands here, with a banner
* plan the paywall: where a plan-less workspace is sent
* success where a completed checkout (or a Free pick) lands
* success the old confirmation page, for `billing.successRoute`
* error where a failed checkout confirmation lands
*
* Not normally used directly — spread `bridgeBillingRoutes()` into the router.
* TBP-944 (svelte TBP-813) — a paid checkout and a Free pick land on
* `billing.successRoute`, by default these routes' own subscription page, which
* shows `<bridge-checkout-notice>`. The current plan sits in a panel with its
* renewal date and card, above the plan picker.
*
* Not normally used directly: spread `bridgeBillingRoutes()` into the router.
*/
import { Component, OnInit, inject } from '@angular/core';
import { Component, OnDestroy, OnInit, computed, inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import type { BridgeBillingPage } from '../../routing/billing-paths';
import type { BillingSubscriptionSnapshot } from '@nebulr-group/bridge-auth-core';
import { clearCheckoutResult } from '../../billing/checkout-result';
import { BridgeConfigService } from '../../config/bridge-config.service';
import { createSubscriptionSignal, type BillingSignal } from '../../core/billing-signals';
import { resolveBillingPaths, type BridgeBillingPage } from '../../routing/billing-paths';
import {
BRIDGE_BILLING_PAGE_DATA,
BRIDGE_PAGE_OPTIONS_DATA,
Expand All @@ -19,6 +29,8 @@ import {
import { routeSegments } from '../../routing/route-path';
import { AuthService } from '../../shared/services/auth.service';
import { BillingPortalButtonComponent } from '../subscription/billing-portal-button.component';
import { CheckoutNoticeComponent } from '../subscription/checkout-notice.component';
import { subscriptionMeta } from '../subscription/plan-format';
import { PlanSelectorComponent } from '../subscription/plan-selector.component';
import { SubscriptionStatusComponent } from '../subscription/subscription-status.component';

Expand All @@ -32,22 +44,31 @@ const DEFAULT_HEADINGS: Record<BridgeBillingPage, string> = {
@Component({
selector: 'bridge-billing-page',
standalone: true,
imports: [BillingPortalButtonComponent, PlanSelectorComponent, SubscriptionStatusComponent],
imports: [BillingPortalButtonComponent, CheckoutNoticeComponent, PlanSelectorComponent, SubscriptionStatusComponent],
template: `
<div class="bridge-billing-page" [attr.data-bridge-billing-route]="page">
@if (page === 'manage' && options.checkoutNotice !== false) {
<bridge-checkout-notice />
}
<h1 class="bridge-billing-heading">{{ heading }}</h1>
@switch (page) {
@case ('manage') {
<div class="bridge-billing-current">
<span class="bridge-billing-label">Current plan</span>
<bridge-subscription-status />
<p class="bridge-billing-text">Your plan, what it includes, and billing.</p>
<div class="bridge-billing-summary" data-bridge-billing-summary>
<div class="bridge-billing-summary-plan">
<span class="bridge-billing-label">Current plan</span>
<bridge-subscription-status className="bridge-billing-summary-status" />
@if (meta()) {
<span class="bridge-billing-summary-meta" data-bridge-billing-meta>{{ meta() }}</span>
}
</div>
<bridge-billing-portal-button />
</div>
<bridge-plan-selector [successRedirect]="at('success')" [cancelRedirect]="base" />
<bridge-plan-selector heading="Change plan" [successRedirect]="successTarget" [cancelRedirect]="base" />
}
@case ('plan') {
<p class="bridge-billing-text">Pick a plan to start using the app.</p>
<bridge-plan-selector [successRedirect]="at('success')" [cancelRedirect]="at('plan')" />
<bridge-plan-selector [successRedirect]="successTarget" [cancelRedirect]="at('plan')" />
}
@case ('success') {
<p class="bridge-billing-text">Your plan is active.</p>
Expand All @@ -68,9 +89,10 @@ const DEFAULT_HEADINGS: Record<BridgeBillingPage, string> = {
</div>
`,
})
export class BridgeBillingPageComponent implements OnInit {
export class BridgeBillingPageComponent implements OnInit, OnDestroy {
private readonly route = inject(ActivatedRoute);
private readonly auth = inject(AuthService);
private readonly config = inject(BridgeConfigService, { optional: true });

protected readonly page: BridgeBillingPage = this.route.snapshot.data[BRIDGE_BILLING_PAGE_DATA] ?? 'manage';
protected readonly options: BridgePageOptions = this.route.snapshot.data[BRIDGE_PAGE_OPTIONS_DATA] ?? {
Expand All @@ -90,12 +112,42 @@ export class BridgeBillingPageComponent implements OnInit {
return this.base === '/' ? `/${sub}` : `${this.base}/${sub}`;
}

/**
* TBP-944 — where a checkout or a Free pick lands: `billing.successRoute`, by
* default this set's own subscription page, wherever the routes live.
*/
protected readonly successTarget = (() => {
let paths;
try {
paths = resolveBillingPaths(this.config?.getConfig().billing);
} catch {
paths = resolveBillingPaths(undefined);
}
return paths.successIsDefault ? this.base : paths.successRoute;
})();

/** The current plan's renewal date and card, for the line under its name. */
private readonly billing: BillingSignal<BillingSubscriptionSnapshot> | null = (() => {
try {
return createSubscriptionSignal();
} catch {
return null; // Bridge not initialised: no meta line
}
})();
protected readonly meta = computed(() => subscriptionMeta(this.billing?.value().state));

ngOnInit(): void {
// The success page always re-reads: the checkout just changed the plan.
// The others read unless something already loaded it.
const { status, loading } = this.auth.subscription();
if (this.page === 'success' || (!status && !loading)) {
void this.auth.loadSubscription();
}
// The old confirmation page says it all; no banner on the next page too.
if (this.page === 'success') clearCheckoutResult();
}

ngOnDestroy(): void {
this.billing?.destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ describe('the subscription page bridgeBillingRoutes() serves (TBP-937)', () => {
it('shows "Manage billing" next to the current plan, with no app code', async () => {
const harness = await RouterTestingHarness.create('/subscription');
const el = harness.routeNativeElement as HTMLElement;
const button = el.querySelector('.bridge-billing-current [data-bridge-billing-portal]');
// TBP-944 — the current plan sits in its summary panel, with the button beside it.
const button = el.querySelector('[data-bridge-billing-summary] [data-bridge-billing-portal]');
expect(button?.textContent?.trim()).toBe('Manage billing');
});

Expand Down
Loading
Loading