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, CustomRequestBody, QueryParameters, RequireParametersUnlessAllAreOptional } from "../../types"; import type { CorsPreferences } from '../models/index'; /** * [Cors](https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=cors:Summary) * ================================== * * *[Download API specification](https://developer.salesforce.com/static/commercecloud/commerce-api/cors/cors-oas-v1-public.yaml) # API Overview The CORS Preferences API allows you to manage your Cross-Origin Resource Sharing (CORS) preferences. By specifying which domains are permitted to access a site, you can define exceptions to the same-site policy that browsers would otherwise enforce. ## Authentication & Authorization For resource access, you must use a client ID and client secret from Account Manager to request an access token. The access token is used as a bearer token and added to the Authorization header of your API request. You must include `sfcc.cors-preferences.rw` (read-write access) or `sfcc.cors-preferences` (read-only access) in the client ID used to generate the token. For a full list of permissions, see the [Authorization Scopes Catalog.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/auth-z-scope-catalog.html) For detailed setup instructions, see the [Authorization for Admin APIs.](https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-admin-apis.html) ## Use Cases ### Manage CORS configuration You can use the preferences/cors endpoint to retrieve, set, or delete your configuration for CORS origins. ## Usage Notes 1. This configuration is made per client ID and site. 2. All known domain names and aliases are added to the list automatically and do not need to be configured for CORS explicitly. 3. If a configuration is absent, CORS will not be active. To enable cors for a client without specifying custom origins, configure the client and site with an empty origin list. The known domain names and aliases will still apply.*
* * 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 { CORSPreferences, ClientConfig } from "commerce-sdk"; * // or * const { CORSPreferences, 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 corsClient = new CORSPreferences(clientConfig); * ``` * * * API Version: 1.4.4
* Last Updated:
*
* */ export declare class CORSPreferences extends BaseClient { constructor(config: ClientConfig); /** * Delete all CORS preferences for the given site. * * If you would like to get a raw Response object use the other deleteCorsPreferences 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 organization the request is being made by * @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.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 void. */ deleteCorsPreferences(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>): Promise; /** * Delete all CORS preferences for the given 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 organization the request is being made by * @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.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 void otherwise. */ deleteCorsPreferences(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>, rawResponse?: T): Promise; /** * Return all CORS preferences for the given site. * * If you would like to get a raw Response object use the other getCorsPreferences 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 organization the request is being made by * @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.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 CorsPreferences. */ getCorsPreferences(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>): Promise; /** * Return all CORS preferences for the given 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 organization the request is being made by * @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.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 CorsPreferences otherwise. */ getCorsPreferences(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>, rawResponse?: T): Promise; /** * Create or replace all CORS preferences for the given site. * * If you would like to get a raw Response object use the other updateCorsPreferences 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 organization the request is being made by * @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.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 options.body - The data to send as the request body. * * @returns A promise of type CorsPreferences. */ updateCorsPreferences(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: CorsPreferences & CustomRequestBody; }>): Promise; /** * Create or replace all CORS preferences for the given 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 organization the request is being made by * @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.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 options.body - The data to send as the request body. * @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 CorsPreferences otherwise. */ updateCorsPreferences(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: CorsPreferences & CustomRequestBody; }>, rawResponse?: T): Promise; }