import { EventManager } from './EventManager.js'; import { BaseEvents } from '../types/events/BaseEvents.js'; import { Events } from '../types/events/Events.js'; import { Currency } from '../types/Currency.js'; import { AcceptedPayloadTypes } from '../types/Payload.js'; import { AcceptedQueryTypes } from '../types/Query.js'; import { SDKConfig } from '../types/sdk/SDKConfig.js'; import { SDKResponse } from '../types/sdk/SDKResponse.js'; import { PageApi } from '../types/api/page/PageApi.js'; import { ServerOptions } from '../types/cookieHandling/ServerOptions.js'; import './Event.js'; import './ActionError.js'; import './FetchError.js'; import './PageError.js'; import '../types/cookieHandling/CookieManager.js'; import '../types/cookieHandling/CookieValueTypes.js'; import '../types/cookieHandling/TmpCookiesObj.js'; import '../types/redactionHandling/RedactionManager.js'; import '../types/redactionHandling/RedactionManagerConfig.js'; import '../types/redactionHandling/RedactionRule.js'; import '../types/api/page/PageFolderListResponse.js'; import '@frontastic/extension-types'; import '../types/api/page/PagePreviewResponse.js'; import '../types/api/page/PageResponse.js'; import '../types/api/page/Page.js'; import '../types/api/page/PageViewData.js'; import '../types/api/page/RedirectResponse.js'; import 'cookie'; import 'http'; declare class SDK extends EventManager { private _hasBeenConfigured; private _actionQueue; private _endpoint; private _locale; private _currency; private _extensionVersion; private _useCurrencyInLocale; private _sessionLifetime; private _customHeaderValue?; private setEndpoint; /** * A function returning the full url endpoint to be called, to be set within the {@link configure} method. */ endpoint(): string; /** * A function returning the [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) locale, to be set within the {@link configure} method. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). */ locale(): string; private apiHubLocale; /** * A function returning the string representing the ISO 4217 3-Letter Currency Code, to be set within the {@link configure} method. */ currency(): Currency; /** * A function returning the string optionally set within the {@link configure} method, the value to assign to a "coFE-Custom-Configuration" header value in every API call. Overriden on single calls by explicity set customHeaderValue passed in {@link callAction} and {@link PageApi} methods. */ customHeaderValue(): string | undefined; constructor(); private throwIfNotConfigured; private isRedactionManager; /** * The method that must be called prior to any other methods to configure the connection to the backend. An error is throw if not called prior. * * @param {string} config.locale - A string representing the combination of the ISO 639-1 language and ISO 3166-1 country code. For example "en-DE" or "en_DE". * @param {string} config.currency - A string representing the ISO 4217 3-Letter Currency Code, for example EUR. * @param {string} config.endpoint - A string representing the full URL of the endpoint to be called. * @param {string} config.extensionVersion - A string representing the next public extension build ID, to specify the extension version in which to connect. * @param {boolean} [config.useCurrencyInLocale=false] - An optional boolean, default false. To be set to true if currency is required in config.locale, for example en-GB@EUR. * @param {string} [config.sessionLifetime=7776000000] - An optional number of milliseconds in which to persist the session lifeTime, to override the {@link DEFAULT_SESSION_LIFETIME} of 3 months. * @param {boolean} [options.customHeaderValue] - An optional string, the value to assign to a "coFE-Custom-Configuration" header value in every API call. Overriden on single calls by explicity set customHeaderValue passed in {@link callAction} and {@link PageApi} methods. * @param {CookieManager} [config.cookieHandlingOverride] - An optional cookie manager interface that contains all the cookie handling methods. * @param {RedactionManager | RedactionManagerConfig} [config.redactionHandlingOverride] - An optional class/object implementing the {@link RedactionManager} interface or {@link RedactionManagerConfig} to replace the default {@link defaultRedactionRules} passed to the inbuilt {@link RedactionHandler}. * * @returns {void} Void. */ configure(config: SDKConfig): void; /** * Invalidates the current session by deleting session cookies and stopping the action queue. * Use this method during logout to prevent "zombie sessions" where stale session cookies persist. * * This method: * 1. Stops the action queue to prevent new requests from being queued * 2. Optionally waits for pending requests to complete * 3. Deletes the `frontastic-session` cookie * 4. Removes the `__rememberMe` cookie * * @param {Object} [options] - Optional configuration. * @param {ServerOptions} [options.serverOptions] - Server request/response objects for SSR. * @param {boolean} [options.waitForPending=true] - Whether to wait for pending requests to complete. * @param {number} [options.timeoutMs=5000] - Maximum time to wait for pending requests (ms). * * @returns {Promise} Resolves when session is invalidated. * * @example * // Client-side logout * await sdk.invalidateSession(); * * @example * // Server-side logout * await sdk.invalidateSession({ serverOptions: { req, res } }); * * @example * // Immediate invalidation without waiting for pending requests * await sdk.invalidateSession({ waitForPending: false }); */ invalidateSession(options?: { serverOptions?: ServerOptions; waitForPending?: boolean; timeoutMs?: number; }): Promise; /** * The method called to standardise the locale and currency inputs. * * @param {string} config.locale - A string representing the combination of the ISO 639-1 language and ISO 3166-1 country code. For example en-GB or en_GB. * @param {string} config.currency - A string representing the ISO 3-Letter Currency Code, for example EUR. * * @returns {void} Void. */ configureLocale(config: Pick): void; private handleApiCall; private handleSuccesfulCall; private handleError; private getDefaultAPIHeaders; /** * The method used to call extension actions. * * @param {string} options.actionName - The name of the action corresponding to the location of the extension, for example "product/getProduct". * @param {unknown} [options.payload] - An optional key, value pair object payload to be serialised into the body of the request. * @param {Object.} [options.query] - An optional key, value pair object to be serialised into the url query. * @param {boolean} [options.parallel] - An optional boolean, default true indicating whether the action should executed asyncronously or be added to a queue and executed in sequence. Useful to supply false on actions you may think have race conditions. * @param {string} [options.customHeaderValue] - An optional string, the value to assign to a "coFE-Custom-Configuration" header value. Overrides customHeaderValue passed in {@link configure}. * @param {Object} [options.serverOptions] - An optional object containing the res and req objects for ServerResponse and IncomingMessage with cookies respectively. Required for server-side rendering session management. * * @returns {PromiseLike} An object with a boolean isError property, and either an error or data property for true and false respectively. Type of data will match generic argument supplied to method. */ callAction(options: { actionName: string; payload?: AcceptedPayloadTypes; query?: AcceptedQueryTypes; parallel?: boolean; customHeaderValue?: string; serverOptions?: ServerOptions; }): Promise>; /** * The domain to call page methods on the API hub. */ page: PageApi; } export { SDK };