@contentstack/utils
Version:
Contentstack utilities for Javascript
44 lines (43 loc) • 2.37 kB
TypeScript
/**
* Shape returned by {@link getVariantAliases} for interoperability with other Utils SDKs (snake_case JSON keys).
*/
export interface VariantAliasesResult {
entry_uid: string;
contenttype_uid: string;
variants: string[];
}
/** CDA entry JSON: at minimum includes `uid`; may include `_content_type_uid` and `publish_details.variants`. */
export type CDAEntryLike = Record<string, unknown>;
/**
* Extracts variant **alias** strings from `publish_details.variants` on a CDA entry.
* Only present when the entry was fetched with the `x-cs-variant-uid` header set to variant **aliases** (not UIDs).
*
* @param entry - Single CDA entry object (must include `uid`).
* @param contentTypeUid - Used when `entry._content_type_uid` is missing. Otherwise omitted or empty string yields `contenttype_uid: ""`.
* @returns `{ entry_uid, contenttype_uid, variants }` with snake_case keys for cross-SDK JSON parity.
* @throws TypeError if `entry` is null/undefined or not a plain object.
* @throws Error if `entry` has no non-empty `uid`.
*/
export declare function getVariantAliases(entry: CDAEntryLike, contentTypeUid?: string): VariantAliasesResult;
/**
* Extracts variant aliases for each entry in order.
*
* @param entries - Array of CDA entry objects.
* @param contentTypeUid - Applied when an entry lacks `_content_type_uid`.
* @returns One result object per input entry.
* @throws TypeError if `entries` is null/undefined or not an array, or any element is not a plain object.
* @throws Error if any entry has no non-empty `uid`.
*/
export declare function getVariantAliases(entries: CDAEntryLike[], contentTypeUid?: string): VariantAliasesResult[];
/**
* Serialises variant alias results for use as an HTML `data-csvariants` attribute value.
*
* @param entries - CDA entries to process (same rules as {@link getVariantAliases} for each item).
* @param contentTypeUid - Applied when an entry lacks `_content_type_uid`.
* @returns `{ "data-csvariants": "<JSON string of VariantAliasesResult[]>" }`.
* @throws TypeError if `entries` is null/undefined or not an array, or any element is not a plain object.
* @throws Error if any entry has no non-empty `uid`.
*/
export declare function getVariantMetadataTags(entries: CDAEntryLike[], contentTypeUid?: string): {
'data-csvariants': string;
};