@schibsted/sourcepoint
Version:
Package containing scripts used by Schibsteds' sites to integrate with Sourcepoint CMP
193 lines (181 loc) • 6.96 kB
TypeScript
type RequiredProperties = {
/**
* - Maps the message to a specific property (website, app, OTT) as set up in the Sourcepoint account dashboard.
*/
baseEndpoint: string;
/**
* - Consent message language. Available: `en`, `no`, `sv`, `fi`, `dk`.
*/
consentLanguage: string;
/**
* - Maps the message to a specific property (website, app, OTT) as set up in the Sourcepoint account dashboard.
*/
propertyId: number;
};
type ExtendedRequiredProperties = {
/**
* - Allows to use the Privacy Manager ID for the property group use of a property group's Privacy Manager ID.
*/
groupPmId: number;
};
type OptionalProperties = Partial<{
/**
* - (**Optional**) Used to override organization's Sourcepoint account. Default value: 1047.
*/
accountId: number;
/**
* - (**Optional**) Used to display a message from one property, e.g. production url, on another domain, e.g. staging/test site.
*/
propertyHref: string;
/**
* - (**Optional**) Array with key value pairs passed to Sourcepoint – could be used as conditions in scenarios.
*/
targetingParams: string[];
/**
* - (**Optional**) Schibsted account user identifier for logged-in users, e.g. 123456. It's not a full SDRN. Send it only if a user is logged-in.
*/
userId: number;
/**
* - (**Optional**) Schibsted account realm of the logged in user. E.g. schibsted.com, spid.no, schibsted.fi.
*/
realm: string;
/**
* - (**Optional**) Provide in order to redirect users to Privacy Settings UI page with a `client_id` parameter passed. It's a unique identifier generated for an individual service client.
*/
clientId: string;
/**
* - (**Optional**) Pulse Event Tracker object.
*/
pulseTracker: object;
/**
* - (**Optional**) Used to allow users to return to a specific page from Privacy Settings UI. Its default value is the current URL.
*/
referrer: string;
/**
* - (**Optional**) It should be a base64-encoded string. Enables passing any query parameters as a part of a specific redirect URL.
*/
state: string;
/**
* - (**Optional**) Provide when you assign Pulse to different variable than `window.pulse`. Used in the server-side integration type.
*/
pulseObjectName: string;
/**
* - (**Optional**) Provide if you want to enable displaying modal in a mobile app webview. `all` – all modals will be enabled; `scc` – only SCC modal will be enabled; `tcf` – only TCF modal will be enabled; `psi` – only PSI modal will be enabled.
*/
showInWebview: 'all' | 'scc' | 'tcf' | 'psi';
/**
* - (**Optional**) Schibsted account browser SDK Identity object.
*/
identityObject: object;
/**
* - (**Optional**) Provide in case you assigned the `Identity` object to a different global variable than `window.Identity`.
*/
identityObjectName: string;
/**
* - (**Optional**) When using the consent identifier, Sourcepoint will persist the consent preferences for the end-user in other properties in the configuration.
*/
authId: string;
/**
* - (**Optional**) Enables the brand level consent feature.
*/
enableUserCentric: boolean;
/**
* - (**Optional**) Enables the ecosystem level consent feature.
*/
enableEcosystemConsent: boolean;
/**
* - (**Optional**) Extension of the `enableUserCentric` parameter: to handle more specific cases. Provide if consent shouldn't be tied to the merchant level.
*/
groupId: string;
/**
* - (**Optional**) Disables blocking of CMP snippet on webviews that don't provide `_sp_pass_consent` parameter in URL.
*/
disableNativeConsentCheck: boolean;
/**
* - (**Optional**) Disables the Sentry error tracking.
*/
disableSentry: boolean;
}>;
type BaseConfig = RequiredProperties & OptionalProperties;
type ExtendedConfig = BaseConfig & ExtendedRequiredProperties;
export type PSIConfig = BaseConfig;
export type SCCConfig = ExtendedConfig;
export type TCFConfig = ExtendedConfig;
// client-side solution types
/**
* @description Configures the PSI pop-up on the client-side (in the browser).
* @param {Window} window - `window` object.
* @param {Document} document - `document` object.
* @param {Navigator} navigator - `navigator` object.
* @param {PSIConfig} config - The configuration object required to establish a connection with the Sourcepoint service.
*/
export function psi(
window: Window,
document: Document,
navigator: Navigator,
config: PSIConfig
): void;
/**
* @description Configures the SCC pop-up on the client-side (in the browser).
* @param {Window} window - `window` object.
* @param {Document} document - `document` object.
* @param {Navigator} navigator - `navigator` object.
* @param {SCCConfig} config - The configuration object required to establish a connection with the Sourcepoint service.
*/
export function scc(
window: Window,
document: Document,
navigator: Navigator,
config: SCCConfig
): void;
/**
* @description Configures the TCF pop-up on the client-side (in the browser).
* @param {Window} window - `window` object.
* @param {Document} document - `document` object.
* @param {Navigator} navigator - `navigator` object.
* @param {TCFConfig} config - The configuration object required to establish a connection with the Sourcepoint service.
*/
export function tcf(
window: Window,
document: Document,
navigator: Navigator,
config: TCFConfig
): void | Promise<void>;
/**
* Represents the categories for which consent can be given.
*/
export type ConsentCategory =
| 'CMP:advertising'
| 'CMP:analytics'
| 'CMP:marketing'
| 'CMP:personalisation'
| 'CMP:performance_marketing';
/**
* Represents the value of a consent.
* `1` means granted, `0` means denied, and `null` means user has not made a choice yet.
*/
export type ConsentState = '1' | '0' | null;
declare global {
interface Window {
psi?: {
openPrivacySettings: (url: string) => void;
setUserId: (id?: number) => void;
};
_tcf_?: {
getConsentedToAllSync: () => boolean | null;
isConsentedToAll: (callback: (value: boolean) => void) => void;
getCachedOrDefaultConsentsForPulse: () => object;
subscribe: (
consentCategory: ConsentCategory,
callback: (value: ConsentState) => void
) => void;
subscribeAny: (callback: () => void) => void;
getPermissionSync: (consentCategory: ConsentCategory) => ConsentState;
getPermission: (
consentCategory: ConsentCategory,
callback: (value: ConsentState) => void
) => void;
showPrivacyManager: () => void;
};
}
}