Skip to content

Commit 1cbe691

Browse files
Merge remote-tracking branch 'origin/main' into fix/form-label-scale
# Conflicts: # apps/web/package-lock.json # apps/web/package.json
2 parents 88bbd73 + a80acf7 commit 1cbe691

13 files changed

Lines changed: 243 additions & 7 deletions

‎apps/web/.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ NEXT_PUBLIC_GTM_CONTAINER_ID=
1919
# Unset = openframe-client (prod); stage: openframe-client@stage; dev/qa: openframe-client@dev
2020
NEXT_PUBLIC_BREW_CASK=
2121

22+
# The hub's Supabase project host, whose images load directly instead of through the image proxy.
23+
# Read at build time, default in next.config.mjs; set it only for a hub on another project
24+
NEXT_PUBLIC_SUPABASE_HOST=
25+
2226
# Feature Flags
2327
# Script Schedule feature - enables script scheduling functionality
2428
NEXT_PUBLIC_FEATURE_SCRIPT_SCHEDULE=false

‎apps/web/next.config.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const nextConfig = {
5353
distDir: 'dist',
5454
env: {
5555
OPENFRAME_BUNDLE_VERSION: resolveBundleVersion(),
56+
// The hub's Supabase project host: every environment reaches the one hub, so it is one public
57+
// value for the Docker image and both shell bundles. A build env var overrides it.
58+
NEXT_PUBLIC_SUPABASE_HOST: process.env.NEXT_PUBLIC_SUPABASE_HOST || 'shdrojejslhgnojzkzak.supabase.co',
5659
},
5760
images: {
5861
unoptimized: true,

‎apps/web/schema.graphql‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,24 @@ type ProductOption {
30033003
status: SubscriptionProductStatus
30043004
}
30053005

3006+
"""One purchase of prepaid AI tokens and what is left of it."""
3007+
type PurchasedTokenPack {
3008+
"""When the pack was credited."""
3009+
purchasedAt: Instant!
3010+
tokensPurchased: Long!
3011+
tokensRemaining: Long!
3012+
3013+
"""
3014+
The first instant the pack can no longer be spent; null when it never expires.
3015+
"""
3016+
expiresAt: Instant
3017+
3018+
"""
3019+
The last day the pack can be spent, the date printed on the invoice; null when it never expires.
3020+
"""
3021+
validUntil: Date
3022+
}
3023+
30063024
enum PushPlatform {
30073025
IOS
30083026
ANDROID
@@ -5529,6 +5547,12 @@ type SubscriptionUsage {
55295547
is settled by the next purchase and is not reported here.
55305548
"""
55315549
purchasedTokensRemaining: Long!
5550+
5551+
"""
5552+
Every purchased pack that can still be spent, oldest first (the order tokens are used in), with when it
5553+
expires. Packs past their expiry are not listed. Remaining is per pack, before any debt is settled.
5554+
"""
5555+
purchasedTokenPacks: [PurchasedTokenPack!]!
55325556
}
55335557

55345558
""" Tag key definition (shared across all entity types)"""

‎apps/web/src/app/(app)/help-center/endpoints.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export const CONTENT_ORIGIN = isAppShell() ? runtimeEnv.tenantHostUrl() : '';
4949
export const CONTENT_BASE = `${CONTENT_ORIGIN}/content`;
5050
const CONTENT = `${CONTENT_BASE}/api`;
5151

52+
const SUPABASE_HOST = process.env.NEXT_PUBLIC_SUPABASE_HOST;
53+
54+
/**
55+
* Our own Supabase storage loads directly, as on the hub: the WAF answers a proxied `?url=https://…`
56+
* with a 502. The exact project host, never `supabase.co`: other projects stay on the proxy.
57+
*/
58+
export const IMAGE_PROXY_SKIP_DOMAINS = SUPABASE_HOST ? [SUPABASE_HOST] : [];
59+
5260
/**
5361
* A Help Center page's own FAQ block: the lib's shared pages take it as their
5462
* `faq` prop. The topic is what the page is about, written by the page (the

‎apps/web/src/app/(app)/settings/billing-usage/components/billing/billing-usage-content.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { BillingPageFrame } from './billing-page-frame';
2727
import { BillingSections } from './billing-sections';
2828
import { DeviceOverageBlock } from './device-overage-block';
2929
import { PaidAiTokensCard } from './paid-ai-tokens-card';
30+
import { PurchasedTokenPacks } from './purchased-token-packs';
3031
import { useBillingPageActions } from './use-billing-page-actions';
3132

3233
/**
@@ -53,6 +54,7 @@ const billingUsageContentQuery = graphql`
5354
...billingSections_subscription
5455
...paidAiTokensCard_subscription
5556
...aiBalanceAlert_subscription
57+
...purchasedTokenPacks_subscription
5658
...deviceOverageBlock_subscription
5759
...cancelSubscriptionFlow_subscription
5860
}
@@ -222,6 +224,12 @@ export function BillingUsageScreen({ data, onRefetch: refetch }: BillingUsageScr
222224
</div>
223225
)}
224226

227+
{hasAi && subscription && (
228+
<div data-loading-optional className="contents">
229+
<PurchasedTokenPacks subscription={subscription} />
230+
</div>
231+
)}
232+
225233
{subscription && (
226234
<div data-loading-optional className="contents">
227235
<DeviceOverageBlock subscription={subscription} onUpgrade={readOnly ? null : openPlanModal} />

‎apps/web/src/app/(app)/settings/billing-usage/components/billing/device-usage-card.tsx‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import type {
1010
import { BillingPeriod } from '@/generated/schema-enums';
1111
import { formatDate } from '@/lib/format-date';
1212
import { formatCount } from '@/lib/format-number';
13+
import { DEVICE_BILLING_TERMS_URL } from '@/lib/legal-urls';
1314
import { deviceAllocation } from '../shared/device-allocation';
1415
import { planSchedule } from '../shared/plan-schedule';
15-
import { StatEmphasis, StatSuffix, UsageStatCard } from '../shared/usage-stat-card';
16+
import { StatEmphasis, StatLink, StatSuffix, UsageStatCard } from '../shared/usage-stat-card';
1617

1718
/**
1819
* The count against its allocation (`deviceAllocation`, shared with the overage
@@ -28,6 +29,9 @@ const deviceUsageCardFragment = graphql`
2829
}
2930
`;
3031

32+
/** Both forms of the caption run to two lines: a trial's two facts, a plan's billing and how it works. */
33+
const CAPTION_LINES = 2;
34+
3135
/**
3236
* The line under the device count: what the count is measured against, or how it
3337
* is billed.
@@ -52,8 +56,16 @@ function caption(isTrial: boolean, trialEndsOn: string | null, prepaid: boolean,
5256
</>
5357
);
5458
}
55-
if (prepaid) return isAnnual ? 'Annual Prepaid' : 'Monthly Prepaid';
56-
return 'Pay as you go';
59+
return (
60+
<>
61+
<span className="block truncate">
62+
{prepaid ? (isAnnual ? 'Annual Prepaid' : 'Monthly Prepaid') : 'Pay as you go'}
63+
</span>
64+
<span className="block truncate">
65+
<StatLink href={DEVICE_BILLING_TERMS_URL}>How device billing works</StatLink>
66+
</span>
67+
</>
68+
);
5769
}
5870

5971
/** Devices under management, against the package that covers them. */
@@ -70,6 +82,7 @@ export function DeviceUsageCard({ subscription }: { subscription: deviceUsageCar
7082
tone={shown?.tone}
7183
value={shown?.value}
7284
caption={shown?.caption}
85+
captionLines={CAPTION_LINES}
7386
/>
7487
);
7588
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* The billing page's list of token packs: what Payment Terms 5.4 promises the customer can read. The date printed is
3+
* the API's `validUntil`, never one worked out from `expiresAt`, which is a day later (CU-17tkuw61pae).
4+
*/
5+
import { act } from 'react';
6+
import { createRoot, type Root } from 'react-dom/client';
7+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
8+
import type { purchasedTokenPacks_subscription$key } from '@/__generated__/purchasedTokenPacks_subscription.graphql';
9+
import { EMPTY_VALUE } from '@/lib/empty-value';
10+
import { PurchasedTokenPacks } from './purchased-token-packs';
11+
12+
// The `graphql` tag needs the Relay transform, which vitest has no equivalent of;
13+
// a fragment read hands back the record it was given.
14+
vi.mock('react-relay', () => ({
15+
graphql: () => ({}),
16+
useFragment: (_fragment: unknown, ref: unknown) => ref,
17+
}));
18+
19+
const OLDER = {
20+
purchasedAt: '2026-10-28T14:35:00Z',
21+
tokensPurchased: 5_000_000,
22+
tokensRemaining: 1_200_000,
23+
validUntil: '2027-10-28',
24+
// Selected by nothing: a printed date taken from here would be a day late.
25+
expiresAt: '2027-10-29T00:00:00Z',
26+
};
27+
const NEWER = {
28+
purchasedAt: '2026-10-30T09:00:00Z',
29+
tokensPurchased: 1_000_000,
30+
tokensRemaining: 1_000_000,
31+
validUntil: '2027-10-30',
32+
expiresAt: '2027-10-31T00:00:00Z',
33+
};
34+
35+
const subscription = (purchasedTokenPacks: unknown[]) =>
36+
({ usage: { purchasedTokenPacks } }) as unknown as purchasedTokenPacks_subscription$key;
37+
38+
let container: HTMLDivElement;
39+
let root: Root;
40+
41+
function render(ref: purchasedTokenPacks_subscription$key) {
42+
act(() => {
43+
root.render(<PurchasedTokenPacks subscription={ref} />);
44+
});
45+
return [...container.querySelectorAll('li')].map(row => row.textContent ?? '');
46+
}
47+
48+
beforeEach(() => {
49+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
50+
container = document.createElement('div');
51+
root = createRoot(container);
52+
});
53+
54+
afterEach(() => {
55+
act(() => root.unmount());
56+
});
57+
58+
describe('PurchasedTokenPacks', () => {
59+
it("states each pack's tokens, purchase date and the API's last valid day", () => {
60+
const [row] = render(subscription([OLDER]));
61+
62+
expect(row).toContain('1.2M / 5M');
63+
expect(row).toContain('Purchased 2026-10-28');
64+
expect(row).toContain('Valid until 2027-10-28');
65+
});
66+
67+
it('keeps the order the API sent, the order tokens are spent in', () => {
68+
const rows = render(subscription([OLDER, NEWER]));
69+
70+
expect(rows.map(row => /Valid until (\S+?)Purchased/.exec(row)?.[1])).toEqual(['2027-10-28', '2027-10-30']);
71+
});
72+
73+
it('prints no date for a pack that never expires', () => {
74+
const [row] = render(subscription([{ ...OLDER, validUntil: null, expiresAt: null }]));
75+
76+
expect(row).not.toContain('Valid until');
77+
expect(row).toContain(EMPTY_VALUE);
78+
});
79+
80+
it('draws nothing when there are no packs', () => {
81+
render(subscription([]));
82+
83+
expect(container.innerHTML).toBe('');
84+
});
85+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use client';
2+
3+
import { graphql, useFragment } from 'react-relay';
4+
import type { purchasedTokenPacks_subscription$key } from '@/__generated__/purchasedTokenPacks_subscription.graphql';
5+
import { EmptyValue } from '@/app/components/shared/empty-value';
6+
import { formatUtcDay } from '@/lib/format-date';
7+
import { formatCompactCount } from '@/lib/format-number';
8+
import { BillingRow, SectionBlock } from '../shared/billing-section';
9+
10+
const purchasedTokenPacksFragment = graphql`
11+
fragment purchasedTokenPacks_subscription on SubscriptionDetail {
12+
usage {
13+
# Oldest first, the order tokens are spent in; expired packs are not listed.
14+
# validUntil is the date the invoice prints. expiresAt is the instant after
15+
# it, so it is not read here.
16+
purchasedTokenPacks {
17+
purchasedAt
18+
tokensPurchased
19+
tokensRemaining
20+
validUntil
21+
}
22+
}
23+
}
24+
`;
25+
26+
/**
27+
* Every pack that can still be spent, as the API lists them, with the date each one lapses (Payment Terms 5.4).
28+
*
29+
* The figures are per pack, before any debt is settled, so they can add up to more than the balance on the card
30+
* above: nothing here totals them.
31+
*/
32+
export function PurchasedTokenPacks({ subscription }: { subscription: purchasedTokenPacks_subscription$key }) {
33+
const data = useFragment(purchasedTokenPacksFragment, subscription);
34+
const packs = data.usage?.purchasedTokenPacks ?? [];
35+
36+
if (packs.length === 0) return null;
37+
38+
return (
39+
<SectionBlock title="Purchased Tokens">
40+
<ul className="flex flex-col gap-[var(--spacing-system-sf)]">
41+
{packs.map(pack => (
42+
<li key={pack.purchasedAt}>
43+
<BillingRow
44+
label={`${formatCompactCount(pack.tokensRemaining)} / ${formatCompactCount(pack.tokensPurchased)}`}
45+
value={pack.validUntil ? `Valid until ${pack.validUntil}` : <EmptyValue />}
46+
/>
47+
<p className="text-ods-text-secondary text-h6">Purchased {formatUtcDay(pack.purchasedAt)}</p>
48+
</li>
49+
))}
50+
</ul>
51+
</SectionBlock>
52+
);
53+
}

‎apps/web/src/app/(app)/settings/billing-usage/components/shared/usage-stat-card.tsx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface UsageStatCardProps {
2121
value?: ReactNode;
2222
/** The line under the figure — what it is measured against, or how it is billed. Unread while loading. */
2323
caption?: ReactNode;
24+
/** How many lines the caption takes once loaded, so the row keeps its height through the wait. */
25+
captionLines?: number;
2426
/** Its subscription has not answered: the card draws its own skeleton (as it does in a loading scope). */
2527
loading?: boolean;
2628
/**
@@ -71,6 +73,7 @@ export function UsageStatCard({
7173
title,
7274
value,
7375
caption,
76+
captionLines,
7477
tone = 'default',
7578
trailing,
7679
loading: loadingProp,
@@ -95,7 +98,7 @@ export function UsageStatCard({
9598
)}
9699
</div>
97100
{loading ? (
98-
<LoadingLine type="h6" className="w-32" />
101+
<LoadingLine type="h6" lines={captionLines} className="w-32" />
99102
) : (
100103
<p className={cn(CAPTION_CLASS, TONE_TEXT[shownTone])}>{caption}</p>
101104
)}
@@ -140,3 +143,15 @@ export function StatEmphasis({ children }: { children: ReactNode }) {
140143
</span>
141144
);
142145
}
146+
147+
/**
148+
* A caption line that leads out to a document, in a new tab (the desktop shell hands that to the system browser).
149+
* Takes the caption's colour, so a recoloured card recolours it too; the underline is what says it is a link.
150+
*/
151+
export function StatLink({ href, children }: { href: string; children: ReactNode }) {
152+
return (
153+
<a href={href} target="_blank" rel="noopener noreferrer" className="underline underline-offset-2">
154+
{children}
155+
</a>
156+
);
157+
}

‎apps/web/src/app/components/openframe-chat-runtime-provider.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
} from '@flamingo-stack/openframe-frontend-core/utils';
5858
import { useRouter } from 'next/navigation';
5959
import { type ReactNode, useCallback, useMemo } from 'react';
60-
import { CONTENT_ORIGIN } from '@/app/(app)/help-center/endpoints';
60+
import { CONTENT_ORIGIN, IMAGE_PROXY_SKIP_DOMAINS } from '@/app/(app)/help-center/endpoints';
6161
import { composeOpenframeInAppContentUrl } from '@/app/(app)/help-center/help-center-content-href';
6262
import { useMingoLauncherStore } from '@/app/(app)/mingo/stores/mingo-launcher-store';
6363
import { useAuthSession } from '@/app/(auth)/auth/hooks/use-auth-session';
@@ -392,6 +392,7 @@ export function OpenframeChatRuntimeProvider({ children }: { children: ReactNode
392392
// never showed. `/api/auth/identity` is the lib's documented hub default.
393393
identityUrl: content('/api/auth/identity'),
394394
imageProxyUrlPrefix: content('/api/image-proxy'),
395+
imageProxySkipDomains: IMAGE_PROXY_SKIP_DOMAINS,
395396
// Native `<track>` VTT endpoint behind every video surface (help-center
396397
// release / onboarding-guide players, chat video cards, the floating
397398
// walkthrough card). The lib builds caption URLs off the relative hub

0 commit comments

Comments
 (0)