UNPKG

salsify-experiences-sdk

Version:

SDK to be used by commerce websites to implement product experiences.

44 lines (41 loc) 1.1 kB
import SdkSettings from '../settings' import { Context } from '../api' import { webcrypto } from 'crypto' import { SDK_VERSION } from '../version' import { Header } from '../utils/request' import HttpStatus, { StatusCodes } from 'http-status-codes' export function makeContext(): Context { return { url: 'https://this.is.a.test/index.html', sessionId: webcrypto.randomUUID(), pageSessionId: webcrypto.randomUUID(), tracking: true, clientId: webcrypto.randomUUID(), languageCode: 'en-US', enhancedContent: { idType: 'MYID', }, version: SDK_VERSION, jsSource: 'npm', } } export function makeSettings(options?: Record<string, unknown>): SdkSettings { return { clientId: webcrypto.randomUUID(), languageCode: 'en-US', enhancedContent: { idType: 'MYID', }, tracking: false, staging: false, ...options, } } export function makeResponse(data: string, status: StatusCodes = HttpStatus.OK): Response { return new Response(data, { status, headers: { [Header.ContentLength]: `${data.length}`, }, }) }