diff --git a/apps/bear/next.config.ts b/apps/bear/next.config.ts
index 72850ad..405d1b1 100644
--- a/apps/bear/next.config.ts
+++ b/apps/bear/next.config.ts
@@ -8,7 +8,11 @@ import {
import type { NextConfig } from 'next';
import path from 'node:path';
-import { API_PROXY_PATH, API_PROXY_TIMEOUT_MS } from './src/constants';
+import {
+ API_PROXY_MAX_BODY,
+ API_PROXY_PATH,
+ API_PROXY_TIMEOUT_MS,
+} from './src/constants';
import { apiInternalUrl } from './src/env/env.config';
// Fonts and the icon sprite keep fixed names; a changed font gets a new name, and the sprite a new
@@ -17,12 +21,25 @@ const immutable = [
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
];
+// No page may be framed by another site (checkout, finance and account pages act on a click), and
+// the browser never guesses a type or sends full URLs to other sites.
+const security = [
+ { key: 'Content-Security-Policy', value: "frame-ancestors 'none'" },
+ { key: 'X-Frame-Options', value: 'DENY' },
+ { key: 'X-Content-Type-Options', value: 'nosniff' },
+ { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
+];
+
const nextConfig: NextConfig = {
// Every visitor gets the metadata in
, where Chrome looks for the manifest and Safari for
// its home-screen tags; Next.js would otherwise stream it to the end of (0054).
htmlLimitedBots: /.*/,
- // The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default.
- experimental: { proxyTimeout: API_PROXY_TIMEOUT_MS },
+ // The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default
+ // and two ID images come close to its 10 MB body limit.
+ experimental: {
+ proxyTimeout: API_PROXY_TIMEOUT_MS,
+ proxyClientMaxBodySize: API_PROXY_MAX_BODY,
+ },
// Workspace packages export TypeScript source, so Next.js compiles them.
transpilePackages: [
'@lumina/market',
@@ -55,6 +72,7 @@ const nextConfig: NextConfig = {
// island's plugins write theirs. Next runs from the app's folder, as every Nx target does.
writeServiceWorker({ publicDir: path.join(process.cwd(), 'public') });
return [
+ { source: '/:path*', headers: security },
{ source: '/fonts/:path*', headers: immutable },
{ source: '/icons/:path*', headers: immutable },
// Revalidated on every update check, so a new worker reaches visitors at their next
diff --git a/apps/bear/src/app/(flow)/checkout/[username]/page.tsx b/apps/bear/src/app/(flow)/checkout/[username]/page.tsx
index a099195..f2acc2f 100644
--- a/apps/bear/src/app/(flow)/checkout/[username]/page.tsx
+++ b/apps/bear/src/app/(flow)/checkout/[username]/page.tsx
@@ -1,4 +1,4 @@
-import { ROUTES } from '@lumina/market/app/navigation';
+import { ROUTES, withSearchParams } from '@lumina/market/app/navigation';
import { getChannel, readOnServer } from '@lumina/market/server';
import { toChannelUsername } from '@lumina/market/shared/utils';
import type { Metadata } from 'next';
@@ -7,7 +7,10 @@ import { notFound, permanentRedirect, redirect } from 'next/navigation';
import { i18n } from '../../../../i18n';
import { CheckoutTemplate } from './templates/checkout-template';
-type CheckoutPageProps = { params: Promise<{ username: string }> };
+type CheckoutPageProps = {
+ params: Promise<{ username: string }>;
+ searchParams: Promise>;
+};
export const metadata: Metadata = {
title: i18n.t('payment:checkout.title'),
@@ -20,11 +23,19 @@ export const metadata: Metadata = {
* browser. Another spelling of the username redirects to the stored one; a suspended channel
* sends the visitor to the channel, which says it is unavailable.
*/
-export default async function CheckoutPage({ params }: CheckoutPageProps) {
+export default async function CheckoutPage({
+ params,
+ searchParams,
+}: CheckoutPageProps) {
const segment = (await params).username;
const username = toChannelUsername(segment);
if (!username) notFound();
- if (username !== segment) permanentRedirect(ROUTES.checkout(username));
+ // The invite link's `?code=` goes along (0059).
+ if (username !== segment) {
+ permanentRedirect(
+ withSearchParams(ROUTES.checkout(username), await searchParams),
+ );
+ }
const channel = await readOnServer(() => getChannel(username));
if (channel.status !== 'ok') notFound();
if (channel.data.suspended) redirect(ROUTES.channel(username));
diff --git a/apps/bear/src/app/(main)/channels/[username]/page.tsx b/apps/bear/src/app/(main)/channels/[username]/page.tsx
index 87bf5d5..b418001 100644
--- a/apps/bear/src/app/(main)/channels/[username]/page.tsx
+++ b/apps/bear/src/app/(main)/channels/[username]/page.tsx
@@ -1,4 +1,4 @@
-import { ROUTES } from '@lumina/market/app/navigation';
+import { ROUTES, withSearchParams } from '@lumina/market/app/navigation';
import {
channelMetadata,
getChannel,
@@ -13,7 +13,10 @@ import { displayUrl } from '../../../../configs';
import { i18n } from '../../../../i18n';
import { ChannelTemplate } from './templates/channel-template';
-type ChannelPageProps = { params: Promise<{ username: string }> };
+type ChannelPageProps = {
+ params: Promise<{ username: string }>;
+ searchParams: Promise>;
+};
// The one kind of route whose metadata names its data (0055): it reads through the same per-request
// cache as the page, so the first byte, held for the metadata in (0054), waits for that
@@ -43,11 +46,19 @@ export async function generateMetadata({
* track record and the first posts; subscribe, follow and the locked posts' gates load in the
* browser. Any other spelling of the username redirects to the one the API stores.
*/
-export default async function ChannelPage({ params }: ChannelPageProps) {
+export default async function ChannelPage({
+ params,
+ searchParams,
+}: ChannelPageProps) {
const segment = (await params).username;
const username = toChannelUsername(segment);
if (!username) notFound();
- if (username !== segment) permanentRedirect(ROUTES.channel(username));
+ // An invite link's `?code=` goes along (0059).
+ if (username !== segment) {
+ permanentRedirect(
+ withSearchParams(ROUTES.channel(username), await searchParams),
+ );
+ }
const channel = await readOnServer(() => getChannel(username));
if (channel.status !== 'ok') notFound();
diff --git a/apps/bear/src/constants/api.ts b/apps/bear/src/constants/api.ts
index 8f30a63..8ec7915 100644
--- a/apps/bear/src/constants/api.ts
+++ b/apps/bear/src/constants/api.ts
@@ -14,3 +14,9 @@ export const API_PROXY_PATH = '/api';
* sets no timeout for uploads.
*/
export const API_PROXY_TIMEOUT_MS = 120_000;
+
+/**
+ * The largest request body the `/api` proxy passes on (Next.js cuts at 10 MB by default). Creator
+ * registration and verification send two 5 MB ID images plus the form in one request.
+ */
+export const API_PROXY_MAX_BODY = '12mb';
diff --git a/apps/bear/src/constants/index.ts b/apps/bear/src/constants/index.ts
index bbd4610..1f14e50 100644
--- a/apps/bear/src/constants/index.ts
+++ b/apps/bear/src/constants/index.ts
@@ -1,2 +1,7 @@
-export { API_PROXY_PATH, API_PROXY_TIMEOUT_MS, API_VERSION_PATH } from './api';
+export {
+ API_PROXY_MAX_BODY,
+ API_PROXY_PATH,
+ API_PROXY_TIMEOUT_MS,
+ API_VERSION_PATH,
+} from './api';
export { FORWARDED_COOKIES } from './cookies';
diff --git a/apps/bull/next.config.ts b/apps/bull/next.config.ts
index 72850ad..405d1b1 100644
--- a/apps/bull/next.config.ts
+++ b/apps/bull/next.config.ts
@@ -8,7 +8,11 @@ import {
import type { NextConfig } from 'next';
import path from 'node:path';
-import { API_PROXY_PATH, API_PROXY_TIMEOUT_MS } from './src/constants';
+import {
+ API_PROXY_MAX_BODY,
+ API_PROXY_PATH,
+ API_PROXY_TIMEOUT_MS,
+} from './src/constants';
import { apiInternalUrl } from './src/env/env.config';
// Fonts and the icon sprite keep fixed names; a changed font gets a new name, and the sprite a new
@@ -17,12 +21,25 @@ const immutable = [
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
];
+// No page may be framed by another site (checkout, finance and account pages act on a click), and
+// the browser never guesses a type or sends full URLs to other sites.
+const security = [
+ { key: 'Content-Security-Policy', value: "frame-ancestors 'none'" },
+ { key: 'X-Frame-Options', value: 'DENY' },
+ { key: 'X-Content-Type-Options', value: 'nosniff' },
+ { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
+];
+
const nextConfig: NextConfig = {
// Every visitor gets the metadata in , where Chrome looks for the manifest and Safari for
// its home-screen tags; Next.js would otherwise stream it to the end of (0054).
htmlLimitedBots: /.*/,
- // The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default.
- experimental: { proxyTimeout: API_PROXY_TIMEOUT_MS },
+ // The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default
+ // and two ID images come close to its 10 MB body limit.
+ experimental: {
+ proxyTimeout: API_PROXY_TIMEOUT_MS,
+ proxyClientMaxBodySize: API_PROXY_MAX_BODY,
+ },
// Workspace packages export TypeScript source, so Next.js compiles them.
transpilePackages: [
'@lumina/market',
@@ -55,6 +72,7 @@ const nextConfig: NextConfig = {
// island's plugins write theirs. Next runs from the app's folder, as every Nx target does.
writeServiceWorker({ publicDir: path.join(process.cwd(), 'public') });
return [
+ { source: '/:path*', headers: security },
{ source: '/fonts/:path*', headers: immutable },
{ source: '/icons/:path*', headers: immutable },
// Revalidated on every update check, so a new worker reaches visitors at their next
diff --git a/apps/bull/src/app/(flow)/checkout/[username]/page.tsx b/apps/bull/src/app/(flow)/checkout/[username]/page.tsx
index a099195..f2acc2f 100644
--- a/apps/bull/src/app/(flow)/checkout/[username]/page.tsx
+++ b/apps/bull/src/app/(flow)/checkout/[username]/page.tsx
@@ -1,4 +1,4 @@
-import { ROUTES } from '@lumina/market/app/navigation';
+import { ROUTES, withSearchParams } from '@lumina/market/app/navigation';
import { getChannel, readOnServer } from '@lumina/market/server';
import { toChannelUsername } from '@lumina/market/shared/utils';
import type { Metadata } from 'next';
@@ -7,7 +7,10 @@ import { notFound, permanentRedirect, redirect } from 'next/navigation';
import { i18n } from '../../../../i18n';
import { CheckoutTemplate } from './templates/checkout-template';
-type CheckoutPageProps = { params: Promise<{ username: string }> };
+type CheckoutPageProps = {
+ params: Promise<{ username: string }>;
+ searchParams: Promise>;
+};
export const metadata: Metadata = {
title: i18n.t('payment:checkout.title'),
@@ -20,11 +23,19 @@ export const metadata: Metadata = {
* browser. Another spelling of the username redirects to the stored one; a suspended channel
* sends the visitor to the channel, which says it is unavailable.
*/
-export default async function CheckoutPage({ params }: CheckoutPageProps) {
+export default async function CheckoutPage({
+ params,
+ searchParams,
+}: CheckoutPageProps) {
const segment = (await params).username;
const username = toChannelUsername(segment);
if (!username) notFound();
- if (username !== segment) permanentRedirect(ROUTES.checkout(username));
+ // The invite link's `?code=` goes along (0059).
+ if (username !== segment) {
+ permanentRedirect(
+ withSearchParams(ROUTES.checkout(username), await searchParams),
+ );
+ }
const channel = await readOnServer(() => getChannel(username));
if (channel.status !== 'ok') notFound();
if (channel.data.suspended) redirect(ROUTES.channel(username));
diff --git a/apps/bull/src/app/(main)/channels/[username]/page.tsx b/apps/bull/src/app/(main)/channels/[username]/page.tsx
index 87bf5d5..b418001 100644
--- a/apps/bull/src/app/(main)/channels/[username]/page.tsx
+++ b/apps/bull/src/app/(main)/channels/[username]/page.tsx
@@ -1,4 +1,4 @@
-import { ROUTES } from '@lumina/market/app/navigation';
+import { ROUTES, withSearchParams } from '@lumina/market/app/navigation';
import {
channelMetadata,
getChannel,
@@ -13,7 +13,10 @@ import { displayUrl } from '../../../../configs';
import { i18n } from '../../../../i18n';
import { ChannelTemplate } from './templates/channel-template';
-type ChannelPageProps = { params: Promise<{ username: string }> };
+type ChannelPageProps = {
+ params: Promise<{ username: string }>;
+ searchParams: Promise>;
+};
// The one kind of route whose metadata names its data (0055): it reads through the same per-request
// cache as the page, so the first byte, held for the metadata in (0054), waits for that
@@ -43,11 +46,19 @@ export async function generateMetadata({
* track record and the first posts; subscribe, follow and the locked posts' gates load in the
* browser. Any other spelling of the username redirects to the one the API stores.
*/
-export default async function ChannelPage({ params }: ChannelPageProps) {
+export default async function ChannelPage({
+ params,
+ searchParams,
+}: ChannelPageProps) {
const segment = (await params).username;
const username = toChannelUsername(segment);
if (!username) notFound();
- if (username !== segment) permanentRedirect(ROUTES.channel(username));
+ // An invite link's `?code=` goes along (0059).
+ if (username !== segment) {
+ permanentRedirect(
+ withSearchParams(ROUTES.channel(username), await searchParams),
+ );
+ }
const channel = await readOnServer(() => getChannel(username));
if (channel.status !== 'ok') notFound();
diff --git a/apps/bull/src/constants/api.ts b/apps/bull/src/constants/api.ts
index 8f30a63..8ec7915 100644
--- a/apps/bull/src/constants/api.ts
+++ b/apps/bull/src/constants/api.ts
@@ -14,3 +14,9 @@ export const API_PROXY_PATH = '/api';
* sets no timeout for uploads.
*/
export const API_PROXY_TIMEOUT_MS = 120_000;
+
+/**
+ * The largest request body the `/api` proxy passes on (Next.js cuts at 10 MB by default). Creator
+ * registration and verification send two 5 MB ID images plus the form in one request.
+ */
+export const API_PROXY_MAX_BODY = '12mb';
diff --git a/apps/bull/src/constants/index.ts b/apps/bull/src/constants/index.ts
index bbd4610..1f14e50 100644
--- a/apps/bull/src/constants/index.ts
+++ b/apps/bull/src/constants/index.ts
@@ -1,2 +1,7 @@
-export { API_PROXY_PATH, API_PROXY_TIMEOUT_MS, API_VERSION_PATH } from './api';
+export {
+ API_PROXY_MAX_BODY,
+ API_PROXY_PATH,
+ API_PROXY_TIMEOUT_MS,
+ API_VERSION_PATH,
+} from './api';
export { FORWARDED_COOKIES } from './cookies';
diff --git a/packages/island/src/atoms/count-badge/CountBadge.tsx b/packages/island/src/atoms/count-badge/CountBadge.tsx
index 96750fc..b2ecf7d 100644
--- a/packages/island/src/atoms/count-badge/CountBadge.tsx
+++ b/packages/island/src/atoms/count-badge/CountBadge.tsx
@@ -1,6 +1,6 @@
import { number } from '@lumina/tools/format';
-import { Element } from '../../primitives/element';
+import { GridBox } from '../grid-box';
import { cn } from '../../tools/cn';
import type { CountBadgeProps } from './types';
@@ -18,16 +18,19 @@ export function CountBadge({
if (count <= 0) return null;
return (
-
{count > cap ? `${number(cap)}+` : number(count)}
-
+
);
}
diff --git a/packages/island/src/atoms/dialog/Dialog.tsx b/packages/island/src/atoms/dialog/Dialog.tsx
index 656e472..c113454 100644
--- a/packages/island/src/atoms/dialog/Dialog.tsx
+++ b/packages/island/src/atoms/dialog/Dialog.tsx
@@ -14,6 +14,13 @@ import {
} from './constants';
import type { DialogProps } from './types';
+/** The modal dialogs in the top layer now, other than `dialog`. */
+function otherModals(dialog: HTMLDialogElement): Element[] {
+ return Array.from(document.querySelectorAll('dialog[open]')).filter(
+ (other) => other !== dialog && other.matches(':modal'),
+ );
+}
+
function announce(type: string, dialog: HTMLDialogElement): void {
document.dispatchEvent(new CustomEvent(type, { detail: dialog }));
}
@@ -76,12 +83,34 @@ export function Dialog({
if (open && !isPresent) setIsPresent(true);
// Where the last press started, so a drag out of the panel (selecting text) never closes it.
const pressedLayer = useRef(false);
+ // Whether this dialog announced itself open to the toasts and hasn't announced its close yet, so
+ // each open is matched by exactly one close, however the dialog leaves.
+ const announced = useRef(false);
+ // Whether it was shown and hasn't left yet, so `onExited` runs once however it leaves.
+ const shown = useRef(false);
+ // `open` as last rendered, for the browser's own close to check after the parent answered.
+ const openRef = useRef(open);
+ useEffect(() => {
+ openRef.current = open;
+ });
- const show = useEffectEvent((dialog: HTMLDialogElement) =>
- showDialog(dialog, raiseToasts),
- );
+ const show = (dialog: HTMLDialogElement) => {
+ showDialog(dialog, raiseToasts && !announced.current);
+ if (raiseToasts) announced.current = true;
+ shown.current = true;
+ };
+ const showOnOpen = useEffectEvent(show);
+ // Stops a re-show still waiting after the browser closed the dialog (handleNativeClose).
+ const stopReshow = useRef<(() => void) | null>(null);
+ const cancelReshow = () => {
+ stopReshow.current?.();
+ stopReshow.current = null;
+ };
+ const cancelReshowOnClose = useEffectEvent(cancelReshow);
const left = useEffectEvent((dialog: HTMLDialogElement) => {
- if (raiseToasts) announce(DIALOG_CLOSE_EVENT, dialog);
+ if (announced.current) announce(DIALOG_CLOSE_EVENT, dialog);
+ announced.current = false;
+ shown.current = false;
onExited?.();
});
@@ -91,10 +120,17 @@ export function Dialog({
if (open) {
// Reopened mid-close: the exit transitions run back from where they are.
dialog.removeAttribute('data-closing');
- if (!dialog.open) show(dialog);
+ if (!dialog.open) showOnOpen(dialog);
+ return undefined;
+ }
+ cancelReshowOnClose();
+ // The browser already closed it (see handleNativeClose) and the parent agreed: nothing to
+ // animate, only the close to announce.
+ if (!dialog.open) {
+ if (shown.current) left(dialog);
+ setIsPresent(false);
return undefined;
}
- if (!dialog.open) return undefined;
dialog.setAttribute('data-closing', '');
let cancelled = false;
@@ -114,7 +150,8 @@ export function Dialog({
useEffect(() => {
const dialog = ref.current;
return () => {
- if (dialog?.open) left(dialog);
+ cancelReshowOnClose();
+ if (dialog && shown.current) left(dialog);
};
}, []);
@@ -128,12 +165,41 @@ export function Dialog({
// The browser can close the dialog without asking: Chrome makes a repeated Escape uncancelable
// when the page has had no user activation (right after the ZarinPal return), and a
- // `