diff --git a/apps/bear/.env.example b/apps/bear/.env.example
new file mode 100644
index 0000000..604e5a5
--- /dev/null
+++ b/apps/bear/.env.example
@@ -0,0 +1,13 @@
+# Copy to .env.local. Public variables are inlined into the browser bundle: never put a secret in one.
+# The API's public origin; routes live under /v1, uploads under /files.
+NEXT_PUBLIC_API_ORIGIN=http://localhost:3000
+NEXT_PUBLIC_SITE_URL=http://localhost:3002
+NEXT_PUBLIC_BALE_HANDLE=lumina_support
+NEXT_PUBLIC_TELEGRAM_HANDLE=lumina_support
+NEXT_PUBLIC_SUPPORT_HOURS=شنبه تا پنجشنبه، ۹ تا ۱۸
+
+# Server only: the API origin from inside the deployment network.
+API_INTERNAL_ORIGIN=http://localhost:3000
+
+# Only for steps that run without the real env (lint, type-check, image build).
+SKIP_ENV_VALIDATION=false
diff --git a/apps/bear/src/app/(auth)/error.tsx b/apps/bear/src/app/(auth)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bear/src/app/(auth)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bear/src/app/(flow)/error.tsx b/apps/bear/src/app/(flow)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bear/src/app/(flow)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bear/src/app/(main)/error.tsx b/apps/bear/src/app/(main)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bear/src/app/(main)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bear/src/app/(onboarding)/error.tsx b/apps/bear/src/app/(onboarding)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bear/src/app/(onboarding)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bear/src/app/global-error.tsx b/apps/bear/src/app/global-error.tsx
new file mode 100644
index 0000000..b33a685
--- /dev/null
+++ b/apps/bear/src/app/global-error.tsx
@@ -0,0 +1,36 @@
+'use client';
+
+// global-error replaces the root layout: no providers, so it brings the bootstrap, styles and i18n.
+import '../bootstrap/bootstrap.client';
+import '../styles/app.css';
+
+import { Element } from '@lumina/island/primitives/element';
+import { ErrorFallback } from '@lumina/market/app/error-boundaries';
+
+import { i18n } from '../i18n/i18n.client';
+import { yekanBakh } from '../styles';
+
+type GlobalErrorProps = {
+ error: Error & { digest?: string };
+};
+
+/** The app boundary (EB-W): the last resort when nothing below caught the error. */
+export default function GlobalError({ error }: GlobalErrorProps) {
+ return (
+
+
+
+ window.location.reload()}
+ />
+
+
+ );
+}
diff --git a/apps/bear/src/app/layout.tsx b/apps/bear/src/app/layout.tsx
index cd2875d..e135a22 100644
--- a/apps/bear/src/app/layout.tsx
+++ b/apps/bear/src/app/layout.tsx
@@ -1,16 +1,31 @@
+// First: fills the server module graph before anything renders.
+import '../bootstrap/bootstrap.server';
+import '../styles/app.css';
+
+import { Element } from '@lumina/island/primitives/element';
+import type { Metadata } from 'next';
import type { ReactNode } from 'react';
+import { rootMetadata } from '../configs';
+import { i18n } from '../i18n';
import { yekanBakh, yekanBakhLatin } from '../styles';
-import '../styles/app.css';
+import { AppProviders } from './organisms/app-providers';
+
+export function generateMetadata(): Metadata {
+ return rootMetadata();
+}
export default function RootLayout({ children }: { children: ReactNode }) {
return (
-
-
{children}
-
+
+ {children}
+
+
);
}
diff --git a/apps/bear/src/app/not-found.tsx b/apps/bear/src/app/not-found.tsx
new file mode 100644
index 0000000..ace5888
--- /dev/null
+++ b/apps/bear/src/app/not-found.tsx
@@ -0,0 +1,9 @@
+import { StatusEmptyState } from '@lumina/market/app/error-boundaries';
+import type { Metadata } from 'next';
+
+export const metadata: Metadata = { robots: { index: false } };
+
+/** A missing channel, post or page: calm, with the way home. */
+export default function NotFound() {
+ return ;
+}
diff --git a/apps/bear/src/app/organisms/.gitkeep b/apps/bear/src/app/organisms/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/app/organisms/app-providers/AppProviders.tsx b/apps/bear/src/app/organisms/app-providers/AppProviders.tsx
new file mode 100644
index 0000000..e6b3522
--- /dev/null
+++ b/apps/bear/src/app/organisms/app-providers/AppProviders.tsx
@@ -0,0 +1,19 @@
+'use client';
+
+// First: fills the client module graph before any client component renders.
+import '../../../bootstrap/bootstrap.client';
+
+import { AppShell } from '@lumina/market/app/app-shell';
+
+import { getQueryClient } from '../../../configs/react-query';
+import { i18n } from '../../../i18n/i18n.client';
+import type { AppProvidersProps } from './types';
+
+/** The app's root client component: runs the client bootstrap, then the platform's shell. */
+export function AppProviders({ children }: AppProvidersProps) {
+ return (
+
+ {children}
+
+ );
+}
diff --git a/apps/bear/src/app/organisms/app-providers/index.ts b/apps/bear/src/app/organisms/app-providers/index.ts
new file mode 100644
index 0000000..99d3f7d
--- /dev/null
+++ b/apps/bear/src/app/organisms/app-providers/index.ts
@@ -0,0 +1,2 @@
+export { AppProviders } from './AppProviders';
+export type { AppProvidersProps } from './types';
diff --git a/apps/bear/src/app/organisms/app-providers/types.ts b/apps/bear/src/app/organisms/app-providers/types.ts
new file mode 100644
index 0000000..4c2011a
--- /dev/null
+++ b/apps/bear/src/app/organisms/app-providers/types.ts
@@ -0,0 +1,5 @@
+import type { ReactNode } from 'react';
+
+export type AppProvidersProps = {
+ children: ReactNode;
+};
diff --git a/apps/bear/src/app/organisms/page-error/PageError.tsx b/apps/bear/src/app/organisms/page-error/PageError.tsx
new file mode 100644
index 0000000..a6ccd21
--- /dev/null
+++ b/apps/bear/src/app/organisms/page-error/PageError.tsx
@@ -0,0 +1,30 @@
+'use client';
+
+import { Element } from '@lumina/island/primitives/element';
+import { ErrorFallback } from '@lumina/market/app/error-boundaries';
+import { useQueryErrorResetBoundary } from '@tanstack/react-query';
+
+import type { PageErrorProps } from './types';
+
+/**
+ * The page-size boundary (EB-S) every route group's error.tsx renders, inside the shell, so a
+ * failed page keeps the bars usable. Try again resets the failed queries first, or they would
+ * throw again at once. Never indexed.
+ */
+export function PageError({ error, retry }: PageErrorProps) {
+ const queryErrors = useQueryErrorResetBoundary();
+
+ return (
+ <>
+
+ {
+ queryErrors.reset();
+ retry();
+ }}
+ />
+ >
+ );
+}
diff --git a/apps/bear/src/app/organisms/page-error/index.ts b/apps/bear/src/app/organisms/page-error/index.ts
new file mode 100644
index 0000000..d8273cd
--- /dev/null
+++ b/apps/bear/src/app/organisms/page-error/index.ts
@@ -0,0 +1,2 @@
+export { PageError } from './PageError';
+export type { PageErrorProps } from './types';
diff --git a/apps/bear/src/app/organisms/page-error/types.ts b/apps/bear/src/app/organisms/page-error/types.ts
new file mode 100644
index 0000000..8da62ca
--- /dev/null
+++ b/apps/bear/src/app/organisms/page-error/types.ts
@@ -0,0 +1,5 @@
+export type PageErrorProps = {
+ error: Error & { digest?: string };
+ /** Next.js re-fetches and re-renders the segment. */
+ retry: () => void;
+};
diff --git a/apps/bear/src/bootstrap/.gitkeep b/apps/bear/src/bootstrap/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/bootstrap/bootstrap.client.ts b/apps/bear/src/bootstrap/bootstrap.client.ts
new file mode 100644
index 0000000..8f745b7
--- /dev/null
+++ b/apps/bear/src/bootstrap/bootstrap.client.ts
@@ -0,0 +1,32 @@
+import { configureErrorHandler } from '@lumina/libs/error-handler';
+import { eventEmitter } from '@lumina/libs/event-emitter';
+import { http } from '@lumina/libs/http';
+import { mapApiErrorBody } from '@lumina/market/app/http';
+import { SESSION_REFRESH_ENDPOINT } from '@lumina/market/app/session';
+import { setEnv as setMarketEnv } from '@lumina/market/env';
+import { AUTH_EVENTS } from '@lumina/market/features/auth';
+
+import { API_VERSION_PATH } from '../constants';
+import { clientEnv } from '../env';
+import { ERROR_HANDLER_CONFIG } from './error-reporting';
+
+// Fills the client module graph with public values only, before client components render (during
+// SSR and in the browser). Idempotent: safe to run again.
+setMarketEnv({
+ apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
+ baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
+ telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
+});
+// The session lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the
+// whole app; when that fails the session is over and the shell signs the user out.
+http.configure({
+ baseUrl: `${clientEnv.NEXT_PUBLIC_API_ORIGIN}${API_VERSION_PATH}`,
+ refresh: {
+ endpoint: SESSION_REFRESH_ENDPOINT,
+ onFailure: () =>
+ eventEmitter.emit(AUTH_EVENTS.logout, { reason: 'session-ended' }),
+ },
+ mapErrorBody: mapApiErrorBody,
+});
+configureErrorHandler(ERROR_HANDLER_CONFIG);
diff --git a/apps/bear/src/bootstrap/bootstrap.server.ts b/apps/bear/src/bootstrap/bootstrap.server.ts
new file mode 100644
index 0000000..26a5dbf
--- /dev/null
+++ b/apps/bear/src/bootstrap/bootstrap.server.ts
@@ -0,0 +1,29 @@
+import 'server-only';
+
+import { configureErrorHandler } from '@lumina/libs/error-handler';
+import { http } from '@lumina/libs/http';
+import { configureServerHttp } from '@lumina/libs/server';
+import { mapApiErrorBody } from '@lumina/market/app/http';
+import { setEnv as setMarketEnv } from '@lumina/market/env';
+import { cookies } from 'next/headers';
+
+import { API_VERSION_PATH } from '../constants';
+import { clientEnv } from '../env';
+import { serverEnv } from '../env/server';
+import { ERROR_HANDLER_CONFIG } from './error-reporting';
+
+// Fills the server module graph once, before rendering. Idempotent: safe to run again.
+setMarketEnv({
+ apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
+ baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
+ telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
+});
+// Each server request forwards its own user's session cookies; nothing per user is kept in module
+// state. The server never refreshes: proxy.ts already did, before rendering.
+configureServerHttp({
+ baseUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
+ getCookieHeader: async () => (await cookies()).toString(),
+});
+http.configure({ mapErrorBody: mapApiErrorBody });
+configureErrorHandler(ERROR_HANDLER_CONFIG);
diff --git a/apps/bear/src/bootstrap/error-reporting.ts b/apps/bear/src/bootstrap/error-reporting.ts
new file mode 100644
index 0000000..727e8f0
--- /dev/null
+++ b/apps/bear/src/bootstrap/error-reporting.ts
@@ -0,0 +1,7 @@
+import type { ErrorHandlerConfig } from '@lumina/libs/error-handler';
+
+/**
+ * The error handler's settings for both sides. `report` takes the error-tracking integration's
+ * adapter once it exists; until then 5xx and logic errors are classified but not sent anywhere.
+ */
+export const ERROR_HANDLER_CONFIG: ErrorHandlerConfig = {};
diff --git a/apps/bear/src/configs/.gitkeep b/apps/bear/src/configs/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/configs/index.ts b/apps/bear/src/configs/index.ts
new file mode 100644
index 0000000..bc4704f
--- /dev/null
+++ b/apps/bear/src/configs/index.ts
@@ -0,0 +1,2 @@
+export { getQueryClient } from './react-query';
+export { rootMetadata } from './seo';
diff --git a/apps/bear/src/configs/react-query.ts b/apps/bear/src/configs/react-query.ts
new file mode 100644
index 0000000..6c346bd
--- /dev/null
+++ b/apps/bear/src/configs/react-query.ts
@@ -0,0 +1,50 @@
+import { handleError } from '@lumina/libs/error-handler';
+import {
+ defaultShouldDehydrateQuery,
+ environmentManager,
+ QueryCache,
+ QueryClient,
+} from '@tanstack/react-query';
+
+function makeQueryClient(): QueryClient {
+ return new QueryClient({
+ queryCache: new QueryCache({
+ // The one place a failed refetch stops; a failed first load goes to its boundary instead.
+ onError: (error, query) => {
+ if (query.state.data !== undefined) {
+ handleError(error, { where: 'refetch' });
+ }
+ },
+ }),
+ defaultOptions: {
+ queries: {
+ // Hydrated data isn't refetched on mount.
+ staleTime: 60_000,
+ // The HTTP lib already retried idempotent requests; the user retries from the fallback.
+ retry: false,
+ // Offline fails at once and shows the network fallback, instead of an endless skeleton.
+ networkMode: 'offlineFirst',
+ // A first load that fails throws to its boundary; a failed refetch keeps the data.
+ throwOnError: (_error, query) => query.state.data === undefined,
+ },
+ mutations: { networkMode: 'offlineFirst' },
+ dehydrate: {
+ // Pending queries stream to the browser.
+ shouldDehydrateQuery: (query) =>
+ defaultShouldDehydrateQuery(query) ||
+ query.state.status === 'pending',
+ // Next.js reports the real error on the server; the browser gets its digest.
+ shouldRedactErrors: () => false,
+ },
+ },
+ });
+}
+
+let browserQueryClient: QueryClient | undefined;
+
+/** A new client for every server request; one shared client in the browser. */
+export function getQueryClient(): QueryClient {
+ if (environmentManager.isServer()) return makeQueryClient();
+ browserQueryClient ??= makeQueryClient();
+ return browserQueryClient;
+}
diff --git a/apps/bear/src/configs/seo.ts b/apps/bear/src/configs/seo.ts
new file mode 100644
index 0000000..7ba7a36
--- /dev/null
+++ b/apps/bear/src/configs/seo.ts
@@ -0,0 +1,15 @@
+import type { Metadata } from 'next';
+
+import { clientEnv } from '../env';
+import { i18n } from '../i18n';
+
+/** The root metadata: the brand as the title template, and absolute URLs from the site address. */
+export function rootMetadata(): Metadata {
+ const name = i18n.t('app.name');
+ return {
+ metadataBase: new URL(clientEnv.NEXT_PUBLIC_SITE_URL),
+ title: { default: name, template: `%s · ${name}` },
+ description: i18n.t('app.description'),
+ applicationName: name,
+ };
+}
diff --git a/apps/bear/src/constants/.gitkeep b/apps/bear/src/constants/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/constants/api.ts b/apps/bear/src/constants/api.ts
new file mode 100644
index 0000000..6535d63
--- /dev/null
+++ b/apps/bear/src/constants/api.ts
@@ -0,0 +1,2 @@
+/** Every gateway route except `/files/*` sits under this prefix. */
+export const API_VERSION_PATH = '/v1';
diff --git a/apps/bear/src/constants/index.ts b/apps/bear/src/constants/index.ts
new file mode 100644
index 0000000..80dfdd5
--- /dev/null
+++ b/apps/bear/src/constants/index.ts
@@ -0,0 +1 @@
+export { API_VERSION_PATH } from './api';
diff --git a/apps/bear/src/env/.gitkeep b/apps/bear/src/env/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/env/env.client.ts b/apps/bear/src/env/env.client.ts
new file mode 100644
index 0000000..67ec37c
--- /dev/null
+++ b/apps/bear/src/env/env.client.ts
@@ -0,0 +1,24 @@
+import { createClientEnv } from '@lumina/libs/env';
+import * as v from 'valibot';
+
+const required = v.pipe(v.string(), v.nonEmpty());
+const url = v.pipe(v.string(), v.url());
+
+/** Public variables, inlined into the browser bundle. Next.js inlines only literal reads. */
+export const clientEnv = createClientEnv({
+ prefix: 'NEXT_PUBLIC_',
+ schema: {
+ NEXT_PUBLIC_API_ORIGIN: url,
+ NEXT_PUBLIC_SITE_URL: url,
+ NEXT_PUBLIC_BALE_HANDLE: required,
+ NEXT_PUBLIC_TELEGRAM_HANDLE: required,
+ NEXT_PUBLIC_SUPPORT_HOURS: required,
+ },
+ runtimeEnv: {
+ NEXT_PUBLIC_API_ORIGIN: process.env.NEXT_PUBLIC_API_ORIGIN,
+ NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
+ NEXT_PUBLIC_BALE_HANDLE: process.env.NEXT_PUBLIC_BALE_HANDLE,
+ NEXT_PUBLIC_TELEGRAM_HANDLE: process.env.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ NEXT_PUBLIC_SUPPORT_HOURS: process.env.NEXT_PUBLIC_SUPPORT_HOURS,
+ },
+});
diff --git a/apps/bear/src/env/env.server.ts b/apps/bear/src/env/env.server.ts
new file mode 100644
index 0000000..1a488a1
--- /dev/null
+++ b/apps/bear/src/env/env.server.ts
@@ -0,0 +1,13 @@
+import 'server-only';
+
+import { createServerEnv } from '@lumina/libs/env/server';
+import * as v from 'valibot';
+
+/** Server variables; only server code imports them, through `env/server`. */
+export const serverEnv = createServerEnv({
+ schema: {
+ API_INTERNAL_ORIGIN: v.pipe(v.string(), v.url()),
+ },
+ runtimeEnv: process.env,
+ skipValidation: process.env.SKIP_ENV_VALIDATION === 'true',
+});
diff --git a/apps/bear/src/env/index.ts b/apps/bear/src/env/index.ts
new file mode 100644
index 0000000..75d54bf
--- /dev/null
+++ b/apps/bear/src/env/index.ts
@@ -0,0 +1 @@
+export { clientEnv } from './env.client';
diff --git a/apps/bear/src/env/server.ts b/apps/bear/src/env/server.ts
new file mode 100644
index 0000000..1a91a3c
--- /dev/null
+++ b/apps/bear/src/env/server.ts
@@ -0,0 +1,3 @@
+import 'server-only';
+
+export { serverEnv } from './env.server';
diff --git a/apps/bear/src/i18n/.gitkeep b/apps/bear/src/i18n/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bear/src/i18n/i18n.client.ts b/apps/bear/src/i18n/i18n.client.ts
new file mode 100644
index 0000000..5237748
--- /dev/null
+++ b/apps/bear/src/i18n/i18n.client.ts
@@ -0,0 +1,8 @@
+import { setI18n } from 'react-i18next';
+
+import { i18n } from './i18n';
+
+// useTranslation works even without a provider (global-error renders outside the shell).
+setI18n(i18n);
+
+export { i18n };
diff --git a/apps/bear/src/i18n/i18n.ts b/apps/bear/src/i18n/i18n.ts
new file mode 100644
index 0000000..c81f6b6
--- /dev/null
+++ b/apps/bear/src/i18n/i18n.ts
@@ -0,0 +1,27 @@
+import {
+ DEFAULT_LOCALE,
+ DEFAULT_NAMESPACE,
+ NAMESPACES,
+ resources,
+} from '@lumina/market/shared/locales';
+import { createInstance } from 'i18next';
+import type { i18n as I18n } from 'i18next';
+
+/**
+ * The app's i18n instance. One Persian locale with resources bundled in, so it initialises
+ * synchronously and holds nothing per request. Server components read it directly; client code
+ * imports it through `i18n.client`, which binds it to react-i18next (React context can't load in
+ * a server component).
+ */
+export const i18n: I18n = createInstance();
+
+void i18n.init({
+ lng: DEFAULT_LOCALE,
+ fallbackLng: DEFAULT_LOCALE,
+ resources,
+ ns: NAMESPACES,
+ defaultNS: DEFAULT_NAMESPACE,
+ initAsync: false,
+ // React escapes already.
+ interpolation: { escapeValue: false },
+});
diff --git a/apps/bear/src/i18n/index.ts b/apps/bear/src/i18n/index.ts
new file mode 100644
index 0000000..09e93ea
--- /dev/null
+++ b/apps/bear/src/i18n/index.ts
@@ -0,0 +1 @@
+export { i18n } from './i18n';
diff --git a/apps/bear/src/instrumentation.ts b/apps/bear/src/instrumentation.ts
new file mode 100644
index 0000000..94cef4b
--- /dev/null
+++ b/apps/bear/src/instrumentation.ts
@@ -0,0 +1,17 @@
+import { configureErrorHandler, handleError } from '@lumina/libs/error-handler';
+import type { Instrumentation } from 'next';
+
+import { ERROR_HANDLER_CONFIG } from './bootstrap/error-reporting';
+
+export function register(): void {
+ configureErrorHandler(ERROR_HANDLER_CONFIG);
+}
+
+/** Reports what no server code caught, once, with the route it happened on. */
+export const onRequestError: Instrumentation.onRequestError = (
+ error,
+ _request,
+ context,
+) => {
+ handleError(error, { where: 'server', name: context.routePath });
+};
diff --git a/apps/bear/src/proxy.ts b/apps/bear/src/proxy.ts
new file mode 100644
index 0000000..301ac7a
--- /dev/null
+++ b/apps/bear/src/proxy.ts
@@ -0,0 +1,17 @@
+import { refreshSessionInProxy } from '@lumina/market/server';
+import type { NextRequest } from 'next/server';
+
+import { API_VERSION_PATH } from './constants';
+import { serverEnv } from './env/server';
+
+/** Refreshes an expired session before the page renders (see refreshSessionInProxy). */
+export function proxy(request: NextRequest) {
+ return refreshSessionInProxy(request, {
+ apiUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
+ });
+}
+
+export const config = {
+ // Pages and their data requests only: not build assets, images or files with an extension.
+ matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.[a-zA-Z0-9]+$).*)'],
+};
diff --git a/apps/bear/src/styles/fonts.ts b/apps/bear/src/styles/fonts.ts
index 1b9ac2f..c6f1b75 100644
--- a/apps/bear/src/styles/fonts.ts
+++ b/apps/bear/src/styles/fonts.ts
@@ -7,7 +7,7 @@ import localFont from 'next/font/local';
export const yekanBakh = localFont({
src: '../../../../packages/island/src/fonts/yekan-bakh-fa-num-vf.woff2',
variable: '--font-yekan-bakh',
- weight: '100 950',
+ weight: '100 1000',
display: 'swap',
adjustFontFallback: 'Arial',
});
@@ -16,7 +16,7 @@ export const yekanBakh = localFont({
export const yekanBakhLatin = localFont({
src: '../../../../packages/island/src/fonts/yekan-bakh-vf.woff2',
variable: '--font-yekan-bakh-latin',
- weight: '100 950',
+ weight: '100 1000',
display: 'swap',
preload: false,
adjustFontFallback: 'Arial',
diff --git a/apps/bull/.env.example b/apps/bull/.env.example
new file mode 100644
index 0000000..2c80a51
--- /dev/null
+++ b/apps/bull/.env.example
@@ -0,0 +1,13 @@
+# Copy to .env.local. Public variables are inlined into the browser bundle: never put a secret in one.
+# The API's public origin; routes live under /v1, uploads under /files.
+NEXT_PUBLIC_API_ORIGIN=http://localhost:3000
+NEXT_PUBLIC_SITE_URL=http://localhost:3001
+NEXT_PUBLIC_BALE_HANDLE=lumina_support
+NEXT_PUBLIC_TELEGRAM_HANDLE=lumina_support
+NEXT_PUBLIC_SUPPORT_HOURS=شنبه تا پنجشنبه، ۹ تا ۱۸
+
+# Server only: the API origin from inside the deployment network.
+API_INTERNAL_ORIGIN=http://localhost:3000
+
+# Only for steps that run without the real env (lint, type-check, image build).
+SKIP_ENV_VALIDATION=false
diff --git a/apps/bull/AGENTS.md b/apps/bull/AGENTS.md
new file mode 100644
index 0000000..643577d
--- /dev/null
+++ b/apps/bull/AGENTS.md
@@ -0,0 +1,9 @@
+
+
+# This is NOT the Next.js you know
+
+This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
+
+This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
+
+
diff --git a/apps/bull/CLAUDE.md b/apps/bull/CLAUDE.md
new file mode 100644
index 0000000..43c994c
--- /dev/null
+++ b/apps/bull/CLAUDE.md
@@ -0,0 +1 @@
+@AGENTS.md
diff --git a/apps/bull/src/app/(auth)/error.tsx b/apps/bull/src/app/(auth)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bull/src/app/(auth)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bull/src/app/(flow)/error.tsx b/apps/bull/src/app/(flow)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bull/src/app/(flow)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bull/src/app/(main)/error.tsx b/apps/bull/src/app/(main)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bull/src/app/(main)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bull/src/app/(onboarding)/error.tsx b/apps/bull/src/app/(onboarding)/error.tsx
new file mode 100644
index 0000000..7d8dfc7
--- /dev/null
+++ b/apps/bull/src/app/(onboarding)/error.tsx
@@ -0,0 +1,3 @@
+'use client';
+
+export { PageError as default } from '../organisms/page-error';
diff --git a/apps/bull/src/app/global-error.tsx b/apps/bull/src/app/global-error.tsx
new file mode 100644
index 0000000..b33a685
--- /dev/null
+++ b/apps/bull/src/app/global-error.tsx
@@ -0,0 +1,36 @@
+'use client';
+
+// global-error replaces the root layout: no providers, so it brings the bootstrap, styles and i18n.
+import '../bootstrap/bootstrap.client';
+import '../styles/app.css';
+
+import { Element } from '@lumina/island/primitives/element';
+import { ErrorFallback } from '@lumina/market/app/error-boundaries';
+
+import { i18n } from '../i18n/i18n.client';
+import { yekanBakh } from '../styles';
+
+type GlobalErrorProps = {
+ error: Error & { digest?: string };
+};
+
+/** The app boundary (EB-W): the last resort when nothing below caught the error. */
+export default function GlobalError({ error }: GlobalErrorProps) {
+ return (
+
+
+
+ window.location.reload()}
+ />
+
+
+ );
+}
diff --git a/apps/bull/src/app/layout.tsx b/apps/bull/src/app/layout.tsx
index cd2875d..e135a22 100644
--- a/apps/bull/src/app/layout.tsx
+++ b/apps/bull/src/app/layout.tsx
@@ -1,16 +1,31 @@
+// First: fills the server module graph before anything renders.
+import '../bootstrap/bootstrap.server';
+import '../styles/app.css';
+
+import { Element } from '@lumina/island/primitives/element';
+import type { Metadata } from 'next';
import type { ReactNode } from 'react';
+import { rootMetadata } from '../configs';
+import { i18n } from '../i18n';
import { yekanBakh, yekanBakhLatin } from '../styles';
-import '../styles/app.css';
+import { AppProviders } from './organisms/app-providers';
+
+export function generateMetadata(): Metadata {
+ return rootMetadata();
+}
export default function RootLayout({ children }: { children: ReactNode }) {
return (
-
- {children}
-
+
+ {children}
+
+
);
}
diff --git a/apps/bull/src/app/not-found.tsx b/apps/bull/src/app/not-found.tsx
new file mode 100644
index 0000000..ace5888
--- /dev/null
+++ b/apps/bull/src/app/not-found.tsx
@@ -0,0 +1,9 @@
+import { StatusEmptyState } from '@lumina/market/app/error-boundaries';
+import type { Metadata } from 'next';
+
+export const metadata: Metadata = { robots: { index: false } };
+
+/** A missing channel, post or page: calm, with the way home. */
+export default function NotFound() {
+ return ;
+}
diff --git a/apps/bull/src/app/organisms/.gitkeep b/apps/bull/src/app/organisms/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/app/organisms/app-providers/AppProviders.tsx b/apps/bull/src/app/organisms/app-providers/AppProviders.tsx
new file mode 100644
index 0000000..e6b3522
--- /dev/null
+++ b/apps/bull/src/app/organisms/app-providers/AppProviders.tsx
@@ -0,0 +1,19 @@
+'use client';
+
+// First: fills the client module graph before any client component renders.
+import '../../../bootstrap/bootstrap.client';
+
+import { AppShell } from '@lumina/market/app/app-shell';
+
+import { getQueryClient } from '../../../configs/react-query';
+import { i18n } from '../../../i18n/i18n.client';
+import type { AppProvidersProps } from './types';
+
+/** The app's root client component: runs the client bootstrap, then the platform's shell. */
+export function AppProviders({ children }: AppProvidersProps) {
+ return (
+
+ {children}
+
+ );
+}
diff --git a/apps/bull/src/app/organisms/app-providers/index.ts b/apps/bull/src/app/organisms/app-providers/index.ts
new file mode 100644
index 0000000..99d3f7d
--- /dev/null
+++ b/apps/bull/src/app/organisms/app-providers/index.ts
@@ -0,0 +1,2 @@
+export { AppProviders } from './AppProviders';
+export type { AppProvidersProps } from './types';
diff --git a/apps/bull/src/app/organisms/app-providers/types.ts b/apps/bull/src/app/organisms/app-providers/types.ts
new file mode 100644
index 0000000..4c2011a
--- /dev/null
+++ b/apps/bull/src/app/organisms/app-providers/types.ts
@@ -0,0 +1,5 @@
+import type { ReactNode } from 'react';
+
+export type AppProvidersProps = {
+ children: ReactNode;
+};
diff --git a/apps/bull/src/app/organisms/page-error/PageError.tsx b/apps/bull/src/app/organisms/page-error/PageError.tsx
new file mode 100644
index 0000000..a6ccd21
--- /dev/null
+++ b/apps/bull/src/app/organisms/page-error/PageError.tsx
@@ -0,0 +1,30 @@
+'use client';
+
+import { Element } from '@lumina/island/primitives/element';
+import { ErrorFallback } from '@lumina/market/app/error-boundaries';
+import { useQueryErrorResetBoundary } from '@tanstack/react-query';
+
+import type { PageErrorProps } from './types';
+
+/**
+ * The page-size boundary (EB-S) every route group's error.tsx renders, inside the shell, so a
+ * failed page keeps the bars usable. Try again resets the failed queries first, or they would
+ * throw again at once. Never indexed.
+ */
+export function PageError({ error, retry }: PageErrorProps) {
+ const queryErrors = useQueryErrorResetBoundary();
+
+ return (
+ <>
+
+ {
+ queryErrors.reset();
+ retry();
+ }}
+ />
+ >
+ );
+}
diff --git a/apps/bull/src/app/organisms/page-error/index.ts b/apps/bull/src/app/organisms/page-error/index.ts
new file mode 100644
index 0000000..d8273cd
--- /dev/null
+++ b/apps/bull/src/app/organisms/page-error/index.ts
@@ -0,0 +1,2 @@
+export { PageError } from './PageError';
+export type { PageErrorProps } from './types';
diff --git a/apps/bull/src/app/organisms/page-error/types.ts b/apps/bull/src/app/organisms/page-error/types.ts
new file mode 100644
index 0000000..8da62ca
--- /dev/null
+++ b/apps/bull/src/app/organisms/page-error/types.ts
@@ -0,0 +1,5 @@
+export type PageErrorProps = {
+ error: Error & { digest?: string };
+ /** Next.js re-fetches and re-renders the segment. */
+ retry: () => void;
+};
diff --git a/apps/bull/src/bootstrap/.gitkeep b/apps/bull/src/bootstrap/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/bootstrap/bootstrap.client.ts b/apps/bull/src/bootstrap/bootstrap.client.ts
new file mode 100644
index 0000000..8f745b7
--- /dev/null
+++ b/apps/bull/src/bootstrap/bootstrap.client.ts
@@ -0,0 +1,32 @@
+import { configureErrorHandler } from '@lumina/libs/error-handler';
+import { eventEmitter } from '@lumina/libs/event-emitter';
+import { http } from '@lumina/libs/http';
+import { mapApiErrorBody } from '@lumina/market/app/http';
+import { SESSION_REFRESH_ENDPOINT } from '@lumina/market/app/session';
+import { setEnv as setMarketEnv } from '@lumina/market/env';
+import { AUTH_EVENTS } from '@lumina/market/features/auth';
+
+import { API_VERSION_PATH } from '../constants';
+import { clientEnv } from '../env';
+import { ERROR_HANDLER_CONFIG } from './error-reporting';
+
+// Fills the client module graph with public values only, before client components render (during
+// SSR and in the browser). Idempotent: safe to run again.
+setMarketEnv({
+ apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
+ baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
+ telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
+});
+// The session lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the
+// whole app; when that fails the session is over and the shell signs the user out.
+http.configure({
+ baseUrl: `${clientEnv.NEXT_PUBLIC_API_ORIGIN}${API_VERSION_PATH}`,
+ refresh: {
+ endpoint: SESSION_REFRESH_ENDPOINT,
+ onFailure: () =>
+ eventEmitter.emit(AUTH_EVENTS.logout, { reason: 'session-ended' }),
+ },
+ mapErrorBody: mapApiErrorBody,
+});
+configureErrorHandler(ERROR_HANDLER_CONFIG);
diff --git a/apps/bull/src/bootstrap/bootstrap.server.ts b/apps/bull/src/bootstrap/bootstrap.server.ts
new file mode 100644
index 0000000..26a5dbf
--- /dev/null
+++ b/apps/bull/src/bootstrap/bootstrap.server.ts
@@ -0,0 +1,29 @@
+import 'server-only';
+
+import { configureErrorHandler } from '@lumina/libs/error-handler';
+import { http } from '@lumina/libs/http';
+import { configureServerHttp } from '@lumina/libs/server';
+import { mapApiErrorBody } from '@lumina/market/app/http';
+import { setEnv as setMarketEnv } from '@lumina/market/env';
+import { cookies } from 'next/headers';
+
+import { API_VERSION_PATH } from '../constants';
+import { clientEnv } from '../env';
+import { serverEnv } from '../env/server';
+import { ERROR_HANDLER_CONFIG } from './error-reporting';
+
+// Fills the server module graph once, before rendering. Idempotent: safe to run again.
+setMarketEnv({
+ apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
+ baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
+ telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
+});
+// Each server request forwards its own user's session cookies; nothing per user is kept in module
+// state. The server never refreshes: proxy.ts already did, before rendering.
+configureServerHttp({
+ baseUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
+ getCookieHeader: async () => (await cookies()).toString(),
+});
+http.configure({ mapErrorBody: mapApiErrorBody });
+configureErrorHandler(ERROR_HANDLER_CONFIG);
diff --git a/apps/bull/src/bootstrap/error-reporting.ts b/apps/bull/src/bootstrap/error-reporting.ts
new file mode 100644
index 0000000..727e8f0
--- /dev/null
+++ b/apps/bull/src/bootstrap/error-reporting.ts
@@ -0,0 +1,7 @@
+import type { ErrorHandlerConfig } from '@lumina/libs/error-handler';
+
+/**
+ * The error handler's settings for both sides. `report` takes the error-tracking integration's
+ * adapter once it exists; until then 5xx and logic errors are classified but not sent anywhere.
+ */
+export const ERROR_HANDLER_CONFIG: ErrorHandlerConfig = {};
diff --git a/apps/bull/src/configs/.gitkeep b/apps/bull/src/configs/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/configs/index.ts b/apps/bull/src/configs/index.ts
new file mode 100644
index 0000000..bc4704f
--- /dev/null
+++ b/apps/bull/src/configs/index.ts
@@ -0,0 +1,2 @@
+export { getQueryClient } from './react-query';
+export { rootMetadata } from './seo';
diff --git a/apps/bull/src/configs/react-query.ts b/apps/bull/src/configs/react-query.ts
new file mode 100644
index 0000000..6c346bd
--- /dev/null
+++ b/apps/bull/src/configs/react-query.ts
@@ -0,0 +1,50 @@
+import { handleError } from '@lumina/libs/error-handler';
+import {
+ defaultShouldDehydrateQuery,
+ environmentManager,
+ QueryCache,
+ QueryClient,
+} from '@tanstack/react-query';
+
+function makeQueryClient(): QueryClient {
+ return new QueryClient({
+ queryCache: new QueryCache({
+ // The one place a failed refetch stops; a failed first load goes to its boundary instead.
+ onError: (error, query) => {
+ if (query.state.data !== undefined) {
+ handleError(error, { where: 'refetch' });
+ }
+ },
+ }),
+ defaultOptions: {
+ queries: {
+ // Hydrated data isn't refetched on mount.
+ staleTime: 60_000,
+ // The HTTP lib already retried idempotent requests; the user retries from the fallback.
+ retry: false,
+ // Offline fails at once and shows the network fallback, instead of an endless skeleton.
+ networkMode: 'offlineFirst',
+ // A first load that fails throws to its boundary; a failed refetch keeps the data.
+ throwOnError: (_error, query) => query.state.data === undefined,
+ },
+ mutations: { networkMode: 'offlineFirst' },
+ dehydrate: {
+ // Pending queries stream to the browser.
+ shouldDehydrateQuery: (query) =>
+ defaultShouldDehydrateQuery(query) ||
+ query.state.status === 'pending',
+ // Next.js reports the real error on the server; the browser gets its digest.
+ shouldRedactErrors: () => false,
+ },
+ },
+ });
+}
+
+let browserQueryClient: QueryClient | undefined;
+
+/** A new client for every server request; one shared client in the browser. */
+export function getQueryClient(): QueryClient {
+ if (environmentManager.isServer()) return makeQueryClient();
+ browserQueryClient ??= makeQueryClient();
+ return browserQueryClient;
+}
diff --git a/apps/bull/src/configs/seo.ts b/apps/bull/src/configs/seo.ts
new file mode 100644
index 0000000..7ba7a36
--- /dev/null
+++ b/apps/bull/src/configs/seo.ts
@@ -0,0 +1,15 @@
+import type { Metadata } from 'next';
+
+import { clientEnv } from '../env';
+import { i18n } from '../i18n';
+
+/** The root metadata: the brand as the title template, and absolute URLs from the site address. */
+export function rootMetadata(): Metadata {
+ const name = i18n.t('app.name');
+ return {
+ metadataBase: new URL(clientEnv.NEXT_PUBLIC_SITE_URL),
+ title: { default: name, template: `%s · ${name}` },
+ description: i18n.t('app.description'),
+ applicationName: name,
+ };
+}
diff --git a/apps/bull/src/constants/.gitkeep b/apps/bull/src/constants/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/constants/api.ts b/apps/bull/src/constants/api.ts
new file mode 100644
index 0000000..6535d63
--- /dev/null
+++ b/apps/bull/src/constants/api.ts
@@ -0,0 +1,2 @@
+/** Every gateway route except `/files/*` sits under this prefix. */
+export const API_VERSION_PATH = '/v1';
diff --git a/apps/bull/src/constants/index.ts b/apps/bull/src/constants/index.ts
new file mode 100644
index 0000000..80dfdd5
--- /dev/null
+++ b/apps/bull/src/constants/index.ts
@@ -0,0 +1 @@
+export { API_VERSION_PATH } from './api';
diff --git a/apps/bull/src/env/.gitkeep b/apps/bull/src/env/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/env/env.client.ts b/apps/bull/src/env/env.client.ts
new file mode 100644
index 0000000..67ec37c
--- /dev/null
+++ b/apps/bull/src/env/env.client.ts
@@ -0,0 +1,24 @@
+import { createClientEnv } from '@lumina/libs/env';
+import * as v from 'valibot';
+
+const required = v.pipe(v.string(), v.nonEmpty());
+const url = v.pipe(v.string(), v.url());
+
+/** Public variables, inlined into the browser bundle. Next.js inlines only literal reads. */
+export const clientEnv = createClientEnv({
+ prefix: 'NEXT_PUBLIC_',
+ schema: {
+ NEXT_PUBLIC_API_ORIGIN: url,
+ NEXT_PUBLIC_SITE_URL: url,
+ NEXT_PUBLIC_BALE_HANDLE: required,
+ NEXT_PUBLIC_TELEGRAM_HANDLE: required,
+ NEXT_PUBLIC_SUPPORT_HOURS: required,
+ },
+ runtimeEnv: {
+ NEXT_PUBLIC_API_ORIGIN: process.env.NEXT_PUBLIC_API_ORIGIN,
+ NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
+ NEXT_PUBLIC_BALE_HANDLE: process.env.NEXT_PUBLIC_BALE_HANDLE,
+ NEXT_PUBLIC_TELEGRAM_HANDLE: process.env.NEXT_PUBLIC_TELEGRAM_HANDLE,
+ NEXT_PUBLIC_SUPPORT_HOURS: process.env.NEXT_PUBLIC_SUPPORT_HOURS,
+ },
+});
diff --git a/apps/bull/src/env/env.server.ts b/apps/bull/src/env/env.server.ts
new file mode 100644
index 0000000..1a488a1
--- /dev/null
+++ b/apps/bull/src/env/env.server.ts
@@ -0,0 +1,13 @@
+import 'server-only';
+
+import { createServerEnv } from '@lumina/libs/env/server';
+import * as v from 'valibot';
+
+/** Server variables; only server code imports them, through `env/server`. */
+export const serverEnv = createServerEnv({
+ schema: {
+ API_INTERNAL_ORIGIN: v.pipe(v.string(), v.url()),
+ },
+ runtimeEnv: process.env,
+ skipValidation: process.env.SKIP_ENV_VALIDATION === 'true',
+});
diff --git a/apps/bull/src/env/index.ts b/apps/bull/src/env/index.ts
new file mode 100644
index 0000000..75d54bf
--- /dev/null
+++ b/apps/bull/src/env/index.ts
@@ -0,0 +1 @@
+export { clientEnv } from './env.client';
diff --git a/apps/bull/src/env/server.ts b/apps/bull/src/env/server.ts
new file mode 100644
index 0000000..1a91a3c
--- /dev/null
+++ b/apps/bull/src/env/server.ts
@@ -0,0 +1,3 @@
+import 'server-only';
+
+export { serverEnv } from './env.server';
diff --git a/apps/bull/src/i18n/.gitkeep b/apps/bull/src/i18n/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/apps/bull/src/i18n/i18n.client.ts b/apps/bull/src/i18n/i18n.client.ts
new file mode 100644
index 0000000..5237748
--- /dev/null
+++ b/apps/bull/src/i18n/i18n.client.ts
@@ -0,0 +1,8 @@
+import { setI18n } from 'react-i18next';
+
+import { i18n } from './i18n';
+
+// useTranslation works even without a provider (global-error renders outside the shell).
+setI18n(i18n);
+
+export { i18n };
diff --git a/apps/bull/src/i18n/i18n.ts b/apps/bull/src/i18n/i18n.ts
new file mode 100644
index 0000000..c81f6b6
--- /dev/null
+++ b/apps/bull/src/i18n/i18n.ts
@@ -0,0 +1,27 @@
+import {
+ DEFAULT_LOCALE,
+ DEFAULT_NAMESPACE,
+ NAMESPACES,
+ resources,
+} from '@lumina/market/shared/locales';
+import { createInstance } from 'i18next';
+import type { i18n as I18n } from 'i18next';
+
+/**
+ * The app's i18n instance. One Persian locale with resources bundled in, so it initialises
+ * synchronously and holds nothing per request. Server components read it directly; client code
+ * imports it through `i18n.client`, which binds it to react-i18next (React context can't load in
+ * a server component).
+ */
+export const i18n: I18n = createInstance();
+
+void i18n.init({
+ lng: DEFAULT_LOCALE,
+ fallbackLng: DEFAULT_LOCALE,
+ resources,
+ ns: NAMESPACES,
+ defaultNS: DEFAULT_NAMESPACE,
+ initAsync: false,
+ // React escapes already.
+ interpolation: { escapeValue: false },
+});
diff --git a/apps/bull/src/i18n/index.ts b/apps/bull/src/i18n/index.ts
new file mode 100644
index 0000000..09e93ea
--- /dev/null
+++ b/apps/bull/src/i18n/index.ts
@@ -0,0 +1 @@
+export { i18n } from './i18n';
diff --git a/apps/bull/src/instrumentation.ts b/apps/bull/src/instrumentation.ts
new file mode 100644
index 0000000..94cef4b
--- /dev/null
+++ b/apps/bull/src/instrumentation.ts
@@ -0,0 +1,17 @@
+import { configureErrorHandler, handleError } from '@lumina/libs/error-handler';
+import type { Instrumentation } from 'next';
+
+import { ERROR_HANDLER_CONFIG } from './bootstrap/error-reporting';
+
+export function register(): void {
+ configureErrorHandler(ERROR_HANDLER_CONFIG);
+}
+
+/** Reports what no server code caught, once, with the route it happened on. */
+export const onRequestError: Instrumentation.onRequestError = (
+ error,
+ _request,
+ context,
+) => {
+ handleError(error, { where: 'server', name: context.routePath });
+};
diff --git a/apps/bull/src/proxy.ts b/apps/bull/src/proxy.ts
new file mode 100644
index 0000000..301ac7a
--- /dev/null
+++ b/apps/bull/src/proxy.ts
@@ -0,0 +1,17 @@
+import { refreshSessionInProxy } from '@lumina/market/server';
+import type { NextRequest } from 'next/server';
+
+import { API_VERSION_PATH } from './constants';
+import { serverEnv } from './env/server';
+
+/** Refreshes an expired session before the page renders (see refreshSessionInProxy). */
+export function proxy(request: NextRequest) {
+ return refreshSessionInProxy(request, {
+ apiUrl: `${serverEnv.API_INTERNAL_ORIGIN}${API_VERSION_PATH}`,
+ });
+}
+
+export const config = {
+ // Pages and their data requests only: not build assets, images or files with an extension.
+ matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.[a-zA-Z0-9]+$).*)'],
+};
diff --git a/apps/bull/src/styles/fonts.ts b/apps/bull/src/styles/fonts.ts
index 1b9ac2f..c6f1b75 100644
--- a/apps/bull/src/styles/fonts.ts
+++ b/apps/bull/src/styles/fonts.ts
@@ -7,7 +7,7 @@ import localFont from 'next/font/local';
export const yekanBakh = localFont({
src: '../../../../packages/island/src/fonts/yekan-bakh-fa-num-vf.woff2',
variable: '--font-yekan-bakh',
- weight: '100 950',
+ weight: '100 1000',
display: 'swap',
adjustFontFallback: 'Arial',
});
@@ -16,7 +16,7 @@ export const yekanBakh = localFont({
export const yekanBakhLatin = localFont({
src: '../../../../packages/island/src/fonts/yekan-bakh-vf.woff2',
variable: '--font-yekan-bakh-latin',
- weight: '100 950',
+ weight: '100 1000',
display: 'swap',
preload: false,
adjustFontFallback: 'Arial',