UNPKG

@commercelayer/organization-config

Version:

Organization config utils for extracting config by market

187 lines (184 loc) 5.38 kB
/** * This file was automatically generated by json-schema-to-typescript. * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, * and run json-schema-to-typescript to regenerate this file. */ type Url = string; /** * The international 2-letter country code as defined by the ISO 3166-1 standard. */ type CountryCode = string; /** * List of billing countries by identifier and label. */ type StateCountry = { value: CountryCode; /** * Name of the country. */ label: string; }[]; /** * List of shipping countries by identifier and label. */ type StateCountry1 = { value: CountryCode; /** * Name of the country. */ label: string; }[]; /** * List of shipping countries by identifier and label. * * This interface was referenced by `undefined`'s JSON-Schema definition * via the `patternProperty` "^.*$". */ type StateCountry2 = { value: CountryCode; /** * Name of the country. */ label: string; }[]; /** * List of shipping countries by identifier and label. * * This interface was referenced by `undefined`'s JSON-Schema definition * via the `patternProperty` "^.*$". */ type StateCountry3 = { value: CountryCode; /** * Name of the country. */ label: string; }[]; /** * Payload to use when using the config field of the Organization on CommerceLayer. */ interface ValidConfigForOrganizationsInCommerceLayer { mfe?: { default?: MfeConfig; [k: string]: MfeConfig | undefined; }; [k: string]: unknown; } /** * Default settings for links and checkout. * * This interface was referenced by `undefined`'s JSON-Schema definition * via the `patternProperty` "^market:id:[a-zA-Z0-9]*$$". */ interface MfeConfig { /** * Links for specific micro frontends. */ links?: { cart?: Url; checkout?: Url; identity?: Url; microstore?: Url; my_account?: Url; }; /** * Settings for the Checkout micro front end. */ checkout?: { thankyou_page?: Url; optional_billing_info?: boolean; billing_countries?: StateCountry; shipping_countries?: StateCountry1; default_country?: CountryCode; /** * List of states by country with identifier and label. */ billing_states?: { [k: string]: StateCountry2; }; /** * List of states by country with identifier and label. */ shipping_states?: { [k: string]: StateCountry3; }; }; /** * Checkout internal links settings. */ urls?: { privacy?: Url; terms?: Url; }; /** * Default language setting. */ language?: string; } /** * Represents a type that can be null or undefined, making it optional in use. * @template T The type that is being made nullable. */ type NullableType<T> = T | null | undefined; /** * Params used by the getConfig function */ interface ConfigParams { /** * Language code (e.g., 'en', 'fr') used to dynamically replace the `:lang` placeholder in URLs. */ lang?: NullableType<string>; /** * Organization slug used to replace the `:slug` placeholder in URLs. */ slug?: NullableType<string>; /** * Access token string used to replace the `:access_token` placeholder in URLs. */ accessToken?: NullableType<string>; /** * Unique identifier for an order used to replace the `:order_id` placeholder in URLs. */ orderId?: NullableType<string>; /** * Order token string used to replace the `:token` placeholder in URLs. */ token?: NullableType<string>; /** * Unique identifier for an SKU list used to replace the `:sku_list_id` placeholder in URLs. */ skuListId?: NullableType<string>; /** * Unique identifier for an SKU used to replace the `:sku_id` placeholder in URLs. */ skuId?: NullableType<string>; } interface GetMfeConfigProps { /** * `config` attribute of the organization */ jsonConfig?: { mfe?: MfeConfigs; }; /** * Market identifier for fetching specific configuration overrides. (`market:id:hashid`) */ market?: string; /** * Parameters for replacing URL placeholders. */ params?: ConfigParams; } type MfeConfigs = NonNullable<ValidConfigForOrganizationsInCommerceLayer["mfe"]>; type DefaultMfeConfig = NonNullable<NonNullable<ValidConfigForOrganizationsInCommerceLayer["mfe"]>["default"]>; /** * Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier. * Placeholder values in the configuration URLs can be replaced with actual values from the `params`. * * @param jsonConfig The complete configuration object of the organization. * @param market The market identifier used to get market-specific configuration overrides. * @param params The object containing replacement values for URL placeholders, such as language and access token. * @returns The merged configuration object for the specified market, or null if no configuration is found. */ declare function getMfeConfig({ jsonConfig, market, params, }: GetMfeConfigProps): DefaultMfeConfig | null; export { type DefaultMfeConfig, type MfeConfigs, getMfeConfig };