import { IKitConfigs } from "./configAPIClient"; import { UserAttributeFilters } from "./forwarders.interfaces"; import { IMParticleUser } from "./identity-user-interfaces"; import { Dictionary, AttributeValue } from "./utils"; import { SDKIdentityApi } from "./identity.interfaces"; import { SDKLoggerApi } from "./sdkRuntimeModels"; import { IStore, LocalSessionAttributes } from "./store"; import { IErrorReportingService, ILoggingService } from "./reporting/types"; import { IRoktLauncherOptions } from "./roktLauncherOptions"; import IntegrationCapture from "./integrationCapture"; export type RoktAttributeValueArray = Array; export type RoktAttributeValueType = string | number | boolean | undefined | null; export type RoktAttributeValue = RoktAttributeValueType | RoktAttributeValueArray; export type RoktAttributes = Record; export interface IRoktPartnerExtensionData { [extensionName: string]: T; } export interface IRoktSelectPlacementsOptions { attributes: RoktAttributes; identifier?: string; } interface IRoktPlacement { } export interface IRoktSelection { close: () => void; getPlacements: () => Promise; } export interface IRoktLauncher { selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise; hashAttributes: (attributes: RoktAttributes) => Promise>; use: (name: string) => Promise; } export interface IRoktMessage { messageId: string; methodName: string; payload: any; resolve?: Function; reject?: Function; } export interface RoktKitFilterSettings { userAttributeFilters?: UserAttributeFilters; filterUserAttributes?: (userAttributes: Dictionary, filterList: number[]) => Dictionary; filteredUser?: IMParticleUser | null; } export interface IRoktKitSettings { accountId?: string; placementAttributesMapping?: string; hashedEmailUserIdentityType?: string; } export interface IRoktKit { filters: RoktKitFilterSettings; filteredUser: IMParticleUser | null; launcher: IRoktLauncher | null; userAttributes: Dictionary; hashAttributes: (attributes: RoktAttributes) => Promise; selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise; setExtensionData(extensionData: IRoktPartnerExtensionData): void; use: (name: string) => Promise; onShoppableAdsReady(callback: () => void): void; terminate?: () => Promise; launcherOptions?: Dictionary; settings?: IRoktKitSettings; integrationName?: string; } export interface IRoktOptions { sandbox?: boolean; launcherOptions?: IRoktLauncherOptions; domain?: string; } export type { IRoktLauncherOptions } from "./roktLauncherOptions"; export default class RoktManager { kit: IRoktKit; filters: RoktKitFilterSettings; private currentUser; private messageQueue; private sandbox; private placementAttributesMapping; private identityService; private store; private launcherOptions?; private logger; private errorReporter; private loggingService; private domain?; private mappedEmailShaIdentityType?; private captureTiming?; private integrationCapture?; private onReadyCallback; private initialized; private isShoppableAdsLoaded; /** * Sets a callback to be invoked when RoktManager becomes ready */ setOnReadyCallback(callback: () => void): void; /** * Initializes the RoktManager with configuration settings and user data. * * @param {IKitConfigs} roktConfig - Configuration object containing user attribute filters and settings * @param {IMParticleUser} filteredUser - User object with filtered attributes * @param {SDKIdentityApi} identityService - The mParticle Identity instance * @param {SDKLoggerApi} logger - The mParticle Logger instance * @param {IRoktOptions} options - Options for the RoktManager * @param {Function} captureTiming - Function to capture performance timing marks * @param {IErrorReportingService} errorReporter - Dispatcher for error/warning reporting * @param {ILoggingService} loggingService - Dispatcher for informational logging * * @throws Logs error to console if placementAttributesMapping parsing fails */ init(roktConfig: IKitConfigs, filteredUser: IMParticleUser, identityService: SDKIdentityApi, store: IStore, logger?: SDKLoggerApi, options?: IRoktOptions, captureTiming?: (metricsName: string) => void, errorReporter?: IErrorReportingService, loggingService?: ILoggingService, integrationCapture?: IntegrationCapture): void; get isInitialized(): boolean; attachKit(kit: IRoktKit): void; /** * Renders ads based on the options provided * * @param {IRoktSelectPlacementsOptions} options - The options for selecting placements, including attributes and optional identifier * @returns {Promise} A promise that resolves to the selection * * @example * // Correct usage with await * await window.mParticle.Rokt.selectPlacements({ * attributes: { * email: 'user@example.com', * customAttr: 'value' * } * }); */ selectPlacements(options: IRoktSelectPlacementsOptions): Promise; /** * Hashes attributes and returns both original and hashed versions * with Rokt-compatible key names (like emailsha256, mobilesha256) * * * @param {RoktAttributes} attributes - Attributes to hash * @returns {Promise} Object with both original and hashed attributes * */ hashAttributes(attributes: RoktAttributes): Promise; setExtensionData(extensionData: IRoktPartnerExtensionData): void; use(name: string): Promise; /** * Tears down the current Rokt launcher and removes the placements it rendered. * * Intended for hosts that cannot simply destroy the container element — * SPA route changes and confirmation pages, for example. * * Unlike the other proxied methods, a call made before the kit is ready is * *not* queued. Replaying a teardown against a launcher created later would * silently tear down placements the caller never asked to remove; with no * launcher there is nothing to terminate, so this resolves as a no-op. * * @example * await window.mParticle.Rokt.terminate(); * * @returns {Promise} Resolves once the launcher has torn down. Never rejects. */ terminate(): Promise; onShoppableAdsReady(callback: () => void): void; flushOnShoppableAdsReadyMessageQueue(kit: IRoktKit): void; /** * Hashes an attribute using SHA-256 * * @param {string | number | boolean | undefined | null} attribute - The value to hash * @returns {Promise} SHA-256 hashed value or undefined/null * */ hashSha256(attribute: RoktAttributeValueType): Promise; getLocalSessionAttributes(): LocalSessionAttributes; setLocalSessionAttribute(key: string, value: AttributeValue): void; isReady(): boolean; private setUserAttributes; private mapPlacementAttributes; onIdentityComplete(): void; processMessageQueue(): void; private queueMessage; private deferredCall; /** * Hashes a string input using SHA-256 and returns the hex digest * Uses the Web Crypto API for secure hashing * * @param {string} input - The string to hash * @returns {Promise} The SHA-256 hash as a hexadecimal string */ private sha256Hex; /** * Converts an ArrayBuffer to a hexadecimal string representation * Each byte is converted to a 2-character hex string with leading zeros * * @param {ArrayBuffer} buffer - The buffer to convert * @returns {string} The hexadecimal string representation */ private arrayBufferToHex; /** * Checks if an identity value has changed by comparing current and new values * * @param {string | undefined} currentValue - The current identity value * @param {string | undefined} newValue - The new identity value to compare against * @returns {boolean} True if the identity has changed (new value exists and differs from current), false otherwise */ private hasIdentityChanged; }