storyblok-js-client
Version:
Universal JavaScript SDK for Storyblok's API
119 lines (118 loc) • 5.01 kB
TypeScript
import { StoryblokContentVersionKeys } from './constants';
import { ICacheProvider, ISbConfig, ISbContentMangmntAPI, ISbCustomFetch, ISbLinksParams, ISbLinksResult, ISbResponseData, ISbResult, ISbStories, ISbStoriesParams, ISbStory, ISbStoryParams } from './interfaces';
interface CachedVersions {
[key: string]: number;
}
interface LinksType {
[key: string]: any;
}
interface RelationsType {
[key: string]: any;
}
declare class Storyblok {
private client;
private maxRetries;
private retriesDelay;
private throttle;
private accessToken;
private cache;
private resolveCounter;
relations: RelationsType;
links: LinksType;
version: StoryblokContentVersionKeys | undefined;
/**
* @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
* @see https://github.com/storyblok/richtext
*/
richTextResolver: unknown;
resolveNestedRelations: boolean;
private stringifiedStoriesCache;
private inlineAssets;
/**
*
* @param config ISbConfig interface
* @param pEndpoint string, optional
*/
constructor(config: ISbConfig, pEndpoint?: string);
private parseParams;
private factoryParamOptions;
private makeRequest;
get(slug: 'cdn/links', params?: ISbLinksParams, fetchOptions?: ISbCustomFetch): Promise<ISbLinksResult>;
get(slug: string, params?: ISbStoriesParams, fetchOptions?: ISbCustomFetch): Promise<ISbResult>;
getAll(slug: string, params?: ISbStoriesParams, entity?: string, fetchOptions?: ISbCustomFetch): Promise<any[]>;
post(slug: string, params?: ISbStoriesParams | ISbContentMangmntAPI, fetchOptions?: ISbCustomFetch): Promise<ISbResponseData>;
put(slug: string, params?: ISbStoriesParams | ISbContentMangmntAPI, fetchOptions?: ISbCustomFetch): Promise<ISbResponseData>;
delete(slug: string, params?: ISbStoriesParams | ISbContentMangmntAPI, fetchOptions?: ISbCustomFetch): Promise<ISbResponseData>;
getStories(params?: ISbStoriesParams, fetchOptions?: ISbCustomFetch): Promise<ISbStories>;
getStory(slug: string, params?: ISbStoryParams, fetchOptions?: ISbCustomFetch): Promise<ISbStory>;
private getToken;
ejectInterceptor(): void;
private _addResolveLevel;
private _cleanCopy;
private _insertLinks;
/**
*
* @param resolveId A counter number as a string
* @param uuid The uuid of the story
* @returns string | object
*/
private getStoryReference;
/**
* Resolves a field's value by replacing UUIDs with their corresponding story references
* @param jtree - The JSON tree object containing the field to resolve
* @param treeItem - The key of the field to resolve
* @param resolveId - The unique identifier for the current resolution context
*
* This method handles both single string UUIDs and arrays of UUIDs:
* - For single strings: directly replaces the UUID with the story reference
* - For arrays: maps through each UUID and replaces with corresponding story references
*/
private _resolveField;
/**
* Inserts relations into the JSON tree by resolving references
* @param jtree - The JSON tree object to process
* @param treeItem - The current field being processed
* @param fields - The relation patterns to resolve (string or array of strings)
* @param resolveId - The unique identifier for the current resolution context
*
* This method handles two types of relation patterns:
* 1. Nested relations: matches fields that end with the current field name
* Example: If treeItem is "event_type", it matches patterns like "*.event_type"
*
* 2. Direct component relations: matches exact component.field patterns
* Example: "event.event_type" for component "event" and field "event_type"
*
* The method supports both string and array formats for the fields parameter,
* allowing flexible specification of relation patterns.
*/
private _insertRelations;
/**
* Recursively traverses and resolves relations in the story content tree
* @param story - The story object containing the content to process
* @param fields - The relation patterns to resolve
* @param resolveId - The unique identifier for the current resolution context
*/
private iterateTree;
private resolveLinks;
private resolveRelations;
/**
*
* @param responseData
* @param params
* @param resolveId
* @description Resolves the relations and links of the stories
* @returns Promise<void>
*
*/
private resolveStories;
private cacheResponse;
private throttledRequest;
cacheVersions(): CachedVersions;
cacheVersion(): number;
setCacheVersion(cv: number): void;
clearCacheVersion(): void;
cacheProvider(): ICacheProvider;
flushCache(): Promise<this>;
private processInlineAssets;
}
export default Storyblok;