UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

66 lines (65 loc) 2.79 kB
/** * Removes the shop locale segment from a given path. * * @param locale The locale to remove (case-insensitive). * @param path The path string. * @param splitter The path separator. Defaults to '/'. * * @returns The path with the locale segment removed. * * @example * ```typescript * stripShopLocaleFromPath('en', '/en/products') // '/products' * stripShopLocaleFromPath('de', '/de/category/shoes') // '/category/shoes' * ``` */ export declare const stripShopLocaleFromPath: (locale: string, path: string, splitter?: string) => string; /** * Purifies a sensitive value by masking characters. Optionally shows the first and last characters. * * @param value The sensitive value to purify. * @param showFirstAndLastChar Whether to show the first and last characters. Defaults to `false`. * * @returns The purified value. * * @example * ```typescript * purifySensitiveValue("secret") // "********" * purifySensitiveValue("secret", true) // "s****t" * purifySensitiveValue("ab", true) // "ab" (doesn't mask if less than 3 characters) * ``` */ export declare const purifySensitiveValue: (value: string, showFirstAndLastChar?: boolean) => string; /** * Purifies sensitive data from an object by masking values associated with blacklisted keys. * Handles nested objects recursively. * * @param data The object containing potentially sensitive data. * @param blacklistedKeys An array of keys to mask. Defaults to `['password']`. * @param showFirstAndLastChar Whether to show the first and last characters of sensitive values. Defaults to `false`. * * @returns A new object with sensitive data purified. * * @example * ```typescript * const data = { name: "John", password: "mysecret", address: { street: "123 Main St", zip: "12345" } } * * const purified = purifySensitiveData(data) // { name: "John", password: "********", address: { street: "123 Main St", zip: "12345" } } * const purifiedWithFirstLast = purifySensitiveData(data, ['password', 'zip'], true) // { name: "John", password: "m****t", address: { street: "123 Main St", zip: "1****5" } } * ``` */ export declare const purifySensitiveData: (data?: Record<string, any>, blacklistedKeys?: string[], showFirstAndLastChar?: boolean) => Record<string, any>; /** * Creates a Headers object from a record, filtering out undefined values. * * @param headers A partial record of header key-value pairs. Undefined values are ignored. * * @returns A new `Headers` object. * * @example * ```typescript * const headers = createAndPurifyHeaders({ 'Content-Type': 'application/json', Authorization: undefined }) * // headers now contains only the 'Content-Type' header * ``` */ export declare const createAndPurifyHeaders: (headers: Partial<Record<string, string | undefined>>) => Headers;