import { BaseClient, ClientConfig, Response } from "@commerce-apps/core";
import type { CommonParameters } from "@commerce-apps/core";
import type { OperationOptions } from "retry";
import type { RequestInit } from "node-fetch";
import type { CompositeParameters, QueryParameters, RequireParametersUnlessAllAreOptional } from "../../types";
import type { SiteConfiguration } from '../models/index';
export type GetConfigurationsSfdcDwDntEnum = '0' | '1';
export type GetConfigurationsPersonalizedEnum = 'none';
/**
* [Shopper Configurations](https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-configurations:Summary)
* ==================================
*
* *[Download API specification](https://developer.salesforce.com/static/commercecloud/commerce-api/shopper-configurations/shopper-configurations-oas-v1-public.yaml)
# API Overview
The Shopper Configurations API provides cacheable configuration data to shopper-facing applications, enabling them to make decisions based on merchant settings without requiring server-side logic.
This highly cacheable data encompasses toggles, preferences, and configuration information that allows the application to be reactive to changes performed by the merchant, admin, or support engineer.
Configuration types include:
- siteConfiguration: Site-specific settings such as name, status, currencies, and locales
- globalConfiguration: Instance-wide settings such as feature flags
## Authentication & Authorization
The Shopper Configuration API requires a shopper access token from the Shopper Login and API Access Service (SLAS).
You must include `sfcc.shopper-configurations` in the client ID used to generate the SLAS token. For a full list of required permissions, see the [Authorization Scopes Catalog.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/auth-z-scope-catalog.html)
For details on how to request a shopper access token from SLAS, see the guest user flows for [public clients](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-public-client.html) and [private clients](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas-private-client.html) in the SLAS guides.
## Customization
### Hooks
You can extend the Shopper Configurations response with custom data using the `dw.shop.shopper_configuration.modifyGETResponse` hook. This is useful for adding custom site preferences to the response.
```javascript
exports.modifyGETResponse = function (configResp) {
var customPreference = dw.system.Site.getCurrent().getCustomPreferenceValue(
"customerServiceEmail"
);
configResp.c_customPrefs = {
customerServiceEmail: customPreference || "noreply@example.com"
};
};
```
For details on hook registration, see [Hook Method Details](https://developer.salesforce.com/docs/commerce/commerce-api/guide/hook-method-details.html). For general information on hooks, see [Extensibility with Hooks.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/extensibility_via_hooks.html)
## Response Details
### Personalization
Responses from this API are not personalized via the Shopper Context API.
### Caching
Caching is provided for this API. For details, see [Server-Side Web-Tier Caching.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/server-side-web-tier-caching.html)
### Timeouts
Shopper API requests must respond within 10 seconds, including any hook execution. If a response exceeds this threshold, an HTTP 504 status code is returned. For details, see [Timeouts and Limits.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/timeouts-limits.html)
### Error Handling
Error responses follow the [RFC 7807](https://datatracker.ietf.org/doc/html/rfc7807) problem detail format. To trace errors, include a `correlation-id` header in your request — the response returns it as `x-correlation-id`. For details, see [HTTP Status Codes and Errors.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/error-response-codes.html)
## Use Cases
### Get Site Configuration
Retrieve site and global configuration settings (name, status, currencies, locales, feature flags).
```sh
curl "https://{shortCode}.api.commercecloud.salesforce.com/configuration/shopper-configurations/v1/organizations/{organizationId}/configurations?siteId=RefArch" \
-H "Authorization: Bearer {access_token}"
```
### Site Identification and Availability
Retrieve the site's display name and current operational status to determine if the storefront is online, offline, or in a maintenance state for shoppers.
### Currency Configuration
Identify the default currency for the site and the list of all supported currencies to ensure correct price rendering and multi-currency support.
### Locale and Language Settings
Access the default locale and the full set of supported locales to localize content, formatting, and language for the shopper's specific region.
### Feature Enablement
View the status of various storefront features and toggles to dynamically enable or disable application logic based on the merchant's active configuration.*
*
* For instructions on how to retrieve access token for admin APIs: https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-admin-apis.html
* Example with admin auth
*
* ```typescript
* import { ShopperConfigurations, ClientConfig } from "commerce-sdk";
* // or
* const { ShopperConfigurations, ClientConfig } = require("commerce-sdk");
*
* const clientConfig: ClientConfig = {
* parameters: {
* clientId: "XXXXXX",
* organizationId: "XXXX",
* shortCode: "XXX",
* siteId: "XX"
* }
* };
*
* token = { access_token: 'INSERT_ACCESS_TOKEN_HERE' };
*
* clientConfig.headers['authorization'] = `Bearer ${token.access_token}`;
* const shopperConfigurationsClient = new ShopperConfigurations(clientConfig);
* ```
*
*
* API Version: 1.4.4
* Last Updated:
*
*
*/
export declare class ShopperConfigurations extends BaseClient {
constructor(config: ClientConfig);
/**
* Retrieves configurations for the specified organization and site.
*
* If you would like to get a raw Response object use the other getConfigurations function.
*
* @param options - An object containing the options for this method.
* @param options.parameters - An object containing the parameters for this method.
* @param options.parameters.organizationId - An identifier for the Salesforce Commerce Cloud organization the request is being made by. It consists of a prefix 'f_ecom_' followed by a 4-character [realm identifier](https://developer.salesforce.com/docs/commerce/commerce-api/guide/base-url.html#realm-id) and a 3-character [instance type identifier](https://developer.salesforce.com/docs/commerce/commerce-api/guide/base-url.html#instance-id).
* @param options.parameters.siteId - The identifier of the site that a request is being made in the context of. Attributes might have site specific values, and some objects may only be assigned to specific sites.
* @param options.parameters.personalized - Controls whether personalization is applied to the response. Set to `none` to opt out of personalized response handling so the response is safe to cache at the CDN layer.
When set to `none`, the server skips applying personalization to the response.
Setting `personalized=none` is necessary but not sufficient for CDN caching: a response is only cached when the endpoint is also cacheable in the [server-side web-tier cache](https://developer.salesforce.com/docs/commerce/commerce-api/guide/server-side-web-tier-caching.html), subject to its TTLs and invalidation. A call that is uncacheable in the web tier is not cached at the CDN either. See [CDN caching](https://developer.salesforce.com/docs/commerce/commerce-api/guide/cdn-caching.html).
* @param options.retrySettings - Retry options for the `node-retry` package
* @param options.fetchOptions - Fetch options for the `make-fetch-happen` package
* @param options.headers - An object literal of key value pairs of the headers to be sent with this request.
*
* @returns A promise of type SiteConfiguration.
*/
getConfigurations(options?: RequireParametersUnlessAllAreOptional<{
parameters?: CompositeParameters<{
organizationId: string;
siteId: string;
personalized?: GetConfigurationsPersonalizedEnum;
} & QueryParameters, CommonParameters>;
retrySettings?: OperationOptions;
fetchOptions?: RequestInit;
headers?: {
[key: string]: string;
};
}>): Promise;
/**
* Retrieves configurations for the specified organization and site.
*
* @param options - An object containing the options for this method.
* @param options.parameters - An object containing the parameters for this method.
* @param options.parameters.organizationId - An identifier for the Salesforce Commerce Cloud organization the request is being made by. It consists of a prefix 'f_ecom_' followed by a 4-character [realm identifier](https://developer.salesforce.com/docs/commerce/commerce-api/guide/base-url.html#realm-id) and a 3-character [instance type identifier](https://developer.salesforce.com/docs/commerce/commerce-api/guide/base-url.html#instance-id).
* @param options.parameters.siteId - The identifier of the site that a request is being made in the context of. Attributes might have site specific values, and some objects may only be assigned to specific sites.
* @param options.parameters.personalized - Controls whether personalization is applied to the response. Set to `none` to opt out of personalized response handling so the response is safe to cache at the CDN layer.
When set to `none`, the server skips applying personalization to the response.
Setting `personalized=none` is necessary but not sufficient for CDN caching: a response is only cached when the endpoint is also cacheable in the [server-side web-tier cache](https://developer.salesforce.com/docs/commerce/commerce-api/guide/server-side-web-tier-caching.html), subject to its TTLs and invalidation. A call that is uncacheable in the web tier is not cached at the CDN either. See [CDN caching](https://developer.salesforce.com/docs/commerce/commerce-api/guide/cdn-caching.html).
* @param options.retrySettings - Retry options for the `node-retry` package
* @param options.fetchOptions - Fetch options for the `make-fetch-happen` package
* @param options.headers - An object literal of key value pairs of the headers to be sent with this request.
* @param rawResponse - Set to true to return entire Response object instead of DTO.
*
* @returns A promise of type Response if rawResponse is true, a promise of type SiteConfiguration otherwise.
*/
getConfigurations(options?: RequireParametersUnlessAllAreOptional<{
parameters?: CompositeParameters<{
organizationId: string;
siteId: string;
personalized?: GetConfigurationsPersonalizedEnum;
} & QueryParameters, CommonParameters>;
retrySettings?: OperationOptions;
fetchOptions?: RequestInit;
headers?: {
[key: string]: string;
};
}>, rawResponse?: T): Promise;
}