@intlayer/config
Version:
Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.
93 lines (92 loc) • 4.21 kB
TypeScript
import { CustomIntlayerConfig, CustomRoutingConfig, EditorConfig, InternationalizationConfig, IntlayerConfig, LogConfig, LogFunctions, RoutingConfig } from "@intlayer/types/config";
//#region src/configFile/buildBrowserConfiguration.d.ts
/**
* Browser-safe subset of {@link IntlayerConfig}.
*
* Excludes server-only fields (`system`, `content`, `build`, `compiler`,
* `dictionary`, `ai`) and sensitive editor credentials (`clientId`,
* `clientSecret`) that must never be shipped to the browser.
*/
type BrowserIntlayerConfig = {
internationalization: Pick<InternationalizationConfig, 'locales' | 'defaultLocale'>;
routing: RoutingConfig;
editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;
log: Pick<LogConfig, 'mode' | 'prefix'>;
};
declare global {
interface Window {
/** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */
INTLAYER_CONFIG?: BrowserIntlayerConfig;
}
}
/**
* Build the internationalization section of the Intlayer configuration.
*
* @param customConfiguration - Partial user-supplied internationalization config.
* @returns A fully-defaulted {@link InternationalizationConfig}.
*/
declare const buildInternationalizationFields: (customConfiguration?: Partial<InternationalizationConfig>) => InternationalizationConfig;
/**
* Build the routing section of the Intlayer configuration.
*
* @param customConfiguration - Partial user-supplied routing config.
* @returns A fully-defaulted {@link RoutingConfig}.
*/
declare const buildRoutingFields: (customConfiguration?: Partial<CustomRoutingConfig>) => RoutingConfig;
/**
* Build the editor section of the Intlayer configuration.
*
* Returns the **full** {@link EditorConfig} including sensitive fields
* (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}
* omits those fields when exposing config to the client.
*
* @param customConfiguration - Partial user-supplied editor config.
* @returns A fully-defaulted {@link EditorConfig}.
*/
declare const buildEditorFields: (customConfiguration?: Partial<EditorConfig>) => EditorConfig;
/**
* Build the log section of the Intlayer configuration.
*
* @param customConfiguration - Partial user-supplied log config.
* @param logFunctions - Optional custom log function overrides (server-only).
* @returns A fully-defaulted {@link LogConfig}.
*/
declare const buildLogFields: (customConfiguration?: Partial<LogConfig>, logFunctions?: LogFunctions) => LogConfig;
/**
* Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.
*
* Applies defaults for every field and strips all server-only or sensitive
* information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,
* `editor.clientId`, `editor.clientSecret`).
*
* This is the browser counterpart of `buildConfigurationFields`. It is safe
* to call in browser environments because it has no Node.js dependencies.
*
* @param customConfig - Optional partial user-supplied Intlayer config.
* @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.
*
* @example
* ```ts
* import { buildBrowserConfiguration } from '@intlayer/config/client';
*
* window.INTLAYER_CONFIG = buildBrowserConfiguration({
* internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },
* });
* ```
*/
declare const buildBrowserConfiguration: (customConfig?: CustomIntlayerConfig) => BrowserIntlayerConfig;
/**
* Extract a {@link BrowserIntlayerConfig} from an already-built full
* {@link IntlayerConfig}.
*
* Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold
* the full server-side config and need to inject the browser-safe subset at
* compile time via a bundler `define`.
*
* @param config - A fully-built server-side Intlayer configuration.
* @returns The browser-safe subset of that configuration.
*/
declare const extractBrowserConfiguration: (config: IntlayerConfig) => BrowserIntlayerConfig;
//#endregion
export { BrowserIntlayerConfig, buildBrowserConfiguration, buildEditorFields, buildInternationalizationFields, buildLogFields, buildRoutingFields, extractBrowserConfiguration };
//# sourceMappingURL=buildBrowserConfiguration.d.ts.map