feat: způsob přihlášení a správa obchodů podle konfigurace serveru
CI / Generate TypeScript types (push) Successful in 12s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 32s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m47s
CI / Build and push Docker image (push) Successful in 49s
CI / Notify (push) Successful in 2s
CI / Generate TypeScript types (push) Successful in 12s
CI / Server unit tests (push) Successful in 26s
CI / Build server (push) Successful in 32s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m47s
CI / Build and push Docker image (push) Successful in 49s
CI / Notify (push) Successful in 2s
This commit is contained in:
10 files changed
+185
-82
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import type { GroupLimits } from "../../../types";
|
||||
|
||||
/**
|
||||
* Runtime konfigurace ze serveru (GET /api/config). Do načtení (nebo když endpoint
|
||||
* neodpoví) platí výchozí hodnoty — stejné jako výchozí hodnoty na serveru (server/src/limits.ts).
|
||||
* Výchozí limity skupinových objednávek — stejné jako výchozí hodnoty na serveru
|
||||
* (server/src/limits.ts). Platí do načtení konfigurace nebo když endpoint neodpoví.
|
||||
*/
|
||||
export const DEFAULT_GROUP_LIMITS: GroupLimits = {
|
||||
maxNoteLength: 300,
|
||||
@@ -14,21 +14,40 @@ export const DEFAULT_GROUP_LIMITS: GroupLimits = {
|
||||
maxItems: 20,
|
||||
};
|
||||
|
||||
let groupLimits: GroupLimits = DEFAULT_GROUP_LIMITS;
|
||||
/** Runtime konfigurace ze serveru (GET /api/config). */
|
||||
export type AppRuntimeConfig = {
|
||||
/** Pokus o načtení konfigurace skončil (úspěšně i neúspěšně) */
|
||||
loaded: boolean,
|
||||
/** Přihlášení přes důvěryhodné hlavičky z proxy; undefined = nevíme (konfigurace se nenačetla) */
|
||||
trustedHeaders?: boolean,
|
||||
/** Správa obchodů je zapnutá (server má admin heslo); undefined = nevíme */
|
||||
storeAdmin?: boolean,
|
||||
groupLimits: GroupLimits,
|
||||
};
|
||||
|
||||
let config: AppRuntimeConfig = { loaded: false, groupLimits: DEFAULT_GROUP_LIMITS };
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
export function getGroupLimits(): GroupLimits {
|
||||
return groupLimits;
|
||||
export function getAppConfig(): AppRuntimeConfig {
|
||||
return config;
|
||||
}
|
||||
|
||||
/** Nastaví limity ze serveru (chybějící hodnoty doplní výchozími) a upozorní odběratele. */
|
||||
export function setGroupLimits(limits: Partial<GroupLimits> | undefined): void {
|
||||
if (!limits) return;
|
||||
groupLimits = { ...DEFAULT_GROUP_LIMITS, ...limits };
|
||||
export function getGroupLimits(): GroupLimits {
|
||||
return config.groupLimits;
|
||||
}
|
||||
|
||||
/** Uloží konfiguraci ze serveru (chybějící limity doplní výchozími) a upozorní odběratele. */
|
||||
export function setAppConfig(patch: Partial<Omit<AppRuntimeConfig, 'groupLimits'>> & { groupLimits?: Partial<GroupLimits> }): void {
|
||||
const { groupLimits, ...rest } = patch;
|
||||
config = {
|
||||
...config,
|
||||
...rest,
|
||||
groupLimits: groupLimits ? { ...DEFAULT_GROUP_LIMITS, ...groupLimits } : config.groupLimits,
|
||||
};
|
||||
listeners.forEach(l => l());
|
||||
}
|
||||
|
||||
export function subscribeGroupLimits(listener: () => void): () => void {
|
||||
export function subscribeAppConfig(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
Reference in new issue
Block a user