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 { ShopperContext } from '../models/index'; /** * [Shopper Context](https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-context:Summary) * ================================== * * *[Download API specification](https://developer.salesforce.com/static/commercecloud/commerce-api/shopper-context/shopper-context-oas-v1-public.yaml) # API Overview With the Shopper Context API, you can set any context information as a key/value pair and use it to retrieve personalized promotions, payment methods, and shipping methods. The context information that is set is evaluated against the customer group definitions to determine a customer group (shopper segment), and is then used to activate the experiences that are associated with a particular segment, such as promotions. You can also get personalized API responses triggered by shopper context from the [Open Commerce API](https://developer.salesforce.com/docs/commerce/b2c-commerce/references/b2c-commerce-ocapi/get-started-with-ocapi.html) (OCAPI). Support for both the B2C Commerce API and OCAPI allows shopper context to be used in hybrid deployments. **Warning** Access tokens with a scope that includes the Shopper Context API are powerful. They can activate specific promotions and can be used to see how a storefront would be displayed in the future. Don't share them with untrusted clients like web browsers or client apps. Make Shopper Context calls with a private client and only set shopper context through a secure backend channel. To avoid misuse, do not make direct calls through a browser or similar client in which data can be viewed. As part of this, when creating a SLAS public client for a tenant, if you attempt to add the Shopper Context API scope, a warning message is displayed to ensure you are aware of the pitfalls of doing so. **Note**: Shopper context is valid for 1 day for guest shoppers and 7 days for registered shoppers. To extend the context set, create a new context. As a best practice, refresh your contexts periodically to ensure that the right personalized experience is rendered for your shoppers. ## Authentication & Authorization The Shopper Context API requires a shopper access token from the Shopper Login and API Access Service (SLAS). You must include `sfcc.shopper-context.rw` in the client ID used to generate the SLAS 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 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. For more information, see [Authorization for Shopper APIs](https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-shopper-apis.html) in the Get Started guides. **Warning**: As with all APIs, never store access tokens in the browser because this creates a security vulnerability. ## Use Cases For detailed usage information, see the [Shopper Context guides](https://developer.salesforce.com/docs/commerce/commerce-api/guide/shopper-context-api.html).*
* * 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 { ShopperContexts, ClientConfig } from "commerce-sdk"; * // or * const { ShopperContexts, 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 shopperContextClient = new ShopperContexts(clientConfig); * ``` * * * API Version: 1.4.4
* Last Updated:
*
* */ export declare class ShopperContexts extends BaseClient { constructor(config: ClientConfig); /** * * * If you would like to get a raw Response object use the other createShopperContext 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.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @param options.parameters.evaluateContextWithClientIp - Determines whether to evaluate the context using the provided `clientIp`. This property is available with B2C Commerce version 24.7. - If `evaluateContextWithClientIp` is set to `true`: - The `clientIP` is saved and used in subsequent requests. - If `evaluateContextWithClientIp` is set to `false`: - The `clientIP` is not saved and will not be used in subsequent requests. * @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 void. */ createShopperContext(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; evaluateContextWithClientIp?: boolean; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: ShopperContext & CustomRequestBody; }>): Promise; /** * * * @param options - An object containing the options for this method. * @param options.parameters - An object containing the parameters for this method. * @param options.parameters.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @param options.parameters.evaluateContextWithClientIp - Determines whether to evaluate the context using the provided `clientIp`. This property is available with B2C Commerce version 24.7. - If `evaluateContextWithClientIp` is set to `true`: - The `clientIP` is saved and used in subsequent requests. - If `evaluateContextWithClientIp` is set to `false`: - The `clientIP` is not saved and will not be used in subsequent requests. * @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 void otherwise. */ createShopperContext(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; evaluateContextWithClientIp?: boolean; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: ShopperContext & CustomRequestBody; }>, rawResponse?: T): Promise; /** * Get a shopper's context based on the shopperJWT. * * If you would like to get a raw Response object use the other deleteShopperContext 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.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @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. */ deleteShopperContext(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>): Promise; /** * Get a shopper's context based on the shopperJWT. * * @param options - An object containing the options for this method. * @param options.parameters - An object containing the parameters for this method. * @param options.parameters.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @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. */ deleteShopperContext(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>, rawResponse?: T): Promise; /** * * * If you would like to get a raw Response object use the other getShopperContext 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.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @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 ShopperContext. */ getShopperContext(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>): Promise; /** * * * @param options - An object containing the options for this method. * @param options.parameters - An object containing the parameters for this method. * @param options.parameters.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @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 ShopperContext otherwise. */ getShopperContext(options?: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; }>, rawResponse?: T): Promise; /** * If the shopper context exists, it's updated with the patch body. - If a new attribute that does not exist in the existing shopper context is present, it is added to the context. -If an attribute is already present in the existing shopper context, its value is replaced by the corresponding value from the new shopper context in the request body as follows: - `custom qualifiers` or `assignment qualifiers`: If the individual qualifier key exists, it is overwritten with the new value. If the value of the key is set to null, it is deleted from the existing shopper context. If an empty `custom qualifiers` or `assignment qualifiers` object `{}` is passed, the entire qualifier object is deleted. - `effectiveDateTime` or `sourceCode` or `clientIp`: If the new value is set to an empty string (""), it is deleted from the existing shopper context. If the new value is set to null, it is ignored. If the new value is not empty or null, it overwrites the existing value. - `customerGroupIds`: If a list of `customerGroupIds` exists, it is replaced by the new list of customer group IDs from the request. If `customerGroupIds` is set to an empty array [], the existing list in the shopper context is deleted. - `geoLocation`: If it exists, the entire `geoLocation` object is replaced with the new value. If the new value is set to null, it is ignored. If an empty `geoLocation` object `{}` is passed, it is deleted. * * If you would like to get a raw Response object use the other updateShopperContext 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.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @param options.parameters.evaluateContextWithClientIp - Determines whether to evaluate the context using the provided `clientIp`. This property is available with B2C Commerce version 24.7. - If `evaluateContextWithClientIp` is set to `true`: - The `clientIP` is saved and used in subsequent requests. - If `evaluateContextWithClientIp` is set to `false`: - The `clientIP` is not saved and will not be used in subsequent requests. * @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 ShopperContext. */ updateShopperContext(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; evaluateContextWithClientIp?: boolean; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: ShopperContext & CustomRequestBody; }>): Promise; /** * If the shopper context exists, it's updated with the patch body. - If a new attribute that does not exist in the existing shopper context is present, it is added to the context. -If an attribute is already present in the existing shopper context, its value is replaced by the corresponding value from the new shopper context in the request body as follows: - `custom qualifiers` or `assignment qualifiers`: If the individual qualifier key exists, it is overwritten with the new value. If the value of the key is set to null, it is deleted from the existing shopper context. If an empty `custom qualifiers` or `assignment qualifiers` object `{}` is passed, the entire qualifier object is deleted. - `effectiveDateTime` or `sourceCode` or `clientIp`: If the new value is set to an empty string (""), it is deleted from the existing shopper context. If the new value is set to null, it is ignored. If the new value is not empty or null, it overwrites the existing value. - `customerGroupIds`: If a list of `customerGroupIds` exists, it is replaced by the new list of customer group IDs from the request. If `customerGroupIds` is set to an empty array [], the existing list in the shopper context is deleted. - `geoLocation`: If it exists, the entire `geoLocation` object is replaced with the new value. If the new value is set to null, it is ignored. If an empty `geoLocation` object `{}` is passed, it is deleted. * * @param options - An object containing the options for this method. * @param options.parameters - An object containing the parameters for this method. * @param options.parameters.usid - The Shopper's unique identifier. It is a required parameter and is part of the response from the Guest or Registered User Shopper Login (SLAS) API call. * @param options.parameters.organizationId - An identifier for the organization the request is being made by * @param options.parameters.siteId - The site context. * @param options.parameters.evaluateContextWithClientIp - Determines whether to evaluate the context using the provided `clientIp`. This property is available with B2C Commerce version 24.7. - If `evaluateContextWithClientIp` is set to `true`: - The `clientIP` is saved and used in subsequent requests. - If `evaluateContextWithClientIp` is set to `false`: - The `clientIP` is not saved and will not be used in subsequent requests. * @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 ShopperContext otherwise. */ updateShopperContext(options: RequireParametersUnlessAllAreOptional<{ parameters?: CompositeParameters<{ usid: string; organizationId: string; siteId: string; evaluateContextWithClientIp?: boolean; } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions; fetchOptions?: RequestInit; headers?: { [key: string]: string; }; body: ShopperContext & CustomRequestBody; }>, rawResponse?: T): Promise; }