@storyblok/api-client 0.2.4 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/client.cjs +176 -0
  2. package/dist/client.cjs.map +1 -0
  3. package/dist/client.d.cts +333 -0
  4. package/dist/client.d.mts +333 -0
  5. package/dist/client.mjs +175 -0
  6. package/dist/client.mjs.map +1 -0
  7. package/dist/error.cjs.map +1 -1
  8. package/dist/error.d.cts +13 -2
  9. package/dist/error.d.mts +13 -2
  10. package/dist/error.mjs.map +1 -1
  11. package/dist/generated/datasource_entries/types.gen.d.cts +1 -16
  12. package/dist/generated/datasource_entries/types.gen.d.mts +1 -16
  13. package/dist/generated/datasources/types.gen.d.cts +1 -28
  14. package/dist/generated/datasources/types.gen.d.mts +1 -28
  15. package/dist/generated/links/types.gen.d.cts +1 -18
  16. package/dist/generated/links/types.gen.d.mts +1 -18
  17. package/dist/generated/shared/client/index.d.mts +1 -1
  18. package/dist/generated/shared/client/types.gen.d.cts +39 -3
  19. package/dist/generated/shared/client/types.gen.d.mts +39 -3
  20. package/dist/generated/shared/core/serverSentEvents.gen.d.cts +4 -1
  21. package/dist/generated/shared/core/serverSentEvents.gen.d.mts +4 -1
  22. package/dist/generated/shared/core/types.gen.d.cts +14 -1
  23. package/dist/generated/shared/core/types.gen.d.mts +14 -1
  24. package/dist/generated/spaces/types.gen.d.cts +1 -9
  25. package/dist/generated/spaces/types.gen.d.mts +1 -9
  26. package/dist/generated/stories/index.d.mts +1 -1
  27. package/dist/generated/stories/types.gen.d.cts +72 -9
  28. package/dist/generated/stories/types.gen.d.mts +72 -9
  29. package/dist/generated/tags/types.gen.d.cts +1 -16
  30. package/dist/generated/tags/types.gen.d.mts +1 -16
  31. package/dist/index.cjs +2 -153
  32. package/dist/index.d.cts +4 -172
  33. package/dist/index.d.mts +4 -172
  34. package/dist/index.mjs +2 -150
  35. package/dist/resources/datasource-entries.cjs.map +1 -1
  36. package/dist/resources/datasource-entries.mjs.map +1 -1
  37. package/dist/resources/datasources.cjs.map +1 -1
  38. package/dist/resources/datasources.mjs.map +1 -1
  39. package/dist/resources/links.cjs.map +1 -1
  40. package/dist/resources/links.mjs.map +1 -1
  41. package/dist/resources/spaces.cjs.map +1 -1
  42. package/dist/resources/spaces.mjs.map +1 -1
  43. package/dist/resources/stories.cjs +6 -4
  44. package/dist/resources/stories.cjs.map +1 -1
  45. package/dist/resources/stories.d.cts +78 -3
  46. package/dist/resources/stories.d.mts +79 -3
  47. package/dist/resources/stories.mjs +6 -4
  48. package/dist/resources/stories.mjs.map +1 -1
  49. package/dist/resources/tags.cjs.map +1 -1
  50. package/dist/resources/tags.mjs.map +1 -1
  51. package/dist/utils/rate-limit.cjs +9 -5
  52. package/dist/utils/rate-limit.cjs.map +1 -1
  53. package/dist/utils/rate-limit.d.cts +4 -18
  54. package/dist/utils/rate-limit.d.mts +4 -18
  55. package/dist/utils/rate-limit.mjs +10 -4
  56. package/dist/utils/rate-limit.mjs.map +1 -1
  57. package/package.json +18 -8
  58. package/dist/index.cjs.map +0 -1
  59. package/dist/index.mjs.map +0 -1
  60. package/dist/types.d.cts +0 -37
  61. package/dist/types.d.mts +0 -37
@@ -24,21 +24,6 @@ type ListData = {
24
24
  };
25
25
  url: '/v2/cdn/tags';
26
26
  };
27
- type ListResponses = {
28
- /**
29
- * Array of tags
30
- */
31
- 200: {
32
- /**
33
- * Array of tag objects
34
- */
35
- tags: Array<TagCapi>;
36
- /**
37
- * Cache version Unix timestamp
38
- */
39
- cv?: number;
40
- };
41
- };
42
27
  //#endregion
43
- export { ListData, ListResponses, TagCapi };
28
+ export { ListData, TagCapi };
44
29
  //# sourceMappingURL=types.gen.d.cts.map
@@ -24,21 +24,6 @@ type ListData = {
24
24
  };
25
25
  url: '/v2/cdn/tags';
26
26
  };
27
- type ListResponses = {
28
- /**
29
- * Array of tags
30
- */
31
- 200: {
32
- /**
33
- * Array of tag objects
34
- */
35
- tags: Array<TagCapi>;
36
- /**
37
- * Cache version Unix timestamp
38
- */
39
- cv?: number;
40
- };
41
- };
42
27
  //#endregion
43
- export { ListData, ListResponses, TagCapi };
28
+ export { ListData, TagCapi };
44
29
  //# sourceMappingURL=types.gen.d.mts.map
package/dist/index.cjs CHANGED
@@ -1,157 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_utils_gen = require('./generated/shared/client/utils.gen.cjs');
4
- const require_client_gen = require('./generated/shared/client/client.gen.cjs');
5
- require('./generated/shared/client/index.cjs');
6
- const require_cache = require('./utils/cache.cjs');
7
2
  const require_error = require('./error.cjs');
8
- const require_rate_limit = require('./utils/rate-limit.cjs');
9
- const require_request = require('./utils/request.cjs');
10
- const require_cv = require('./utils/cv.cjs');
11
- const require_stories = require('./resources/stories.cjs');
12
- const require_links = require('./resources/links.cjs');
13
- const require_tags = require('./resources/tags.cjs');
14
- const require_datasources = require('./resources/datasources.cjs');
15
- const require_datasource_entries = require('./resources/datasource-entries.cjs');
16
- const require_spaces = require('./resources/spaces.cjs');
17
- let _storyblok_region_helper = require("@storyblok/region-helper");
3
+ const require_client = require('./client.cjs');
18
4
 
19
- //#region src/index.ts
20
- const createApiClient = (config) => {
21
- const { accessToken, region = "eu", baseUrl, headers = {}, throwOnError = false, cache = {}, inlineRelations = false, retry, timeout = 3e4, rateLimit, fetch: customFetch } = config;
22
- const retryOptions = {
23
- limit: 3,
24
- backoffLimit: 2e4,
25
- jitter: true,
26
- ...retry
27
- };
28
- const throttleManager = require_rate_limit.createThrottleManager(rateLimit ?? {});
29
- const cacheProvider = cache.provider ?? require_cache.createMemoryCacheProvider();
30
- const swrOptions = cache.onRevalidationError ? { onRevalidationError: cache.onRevalidationError } : void 0;
31
- const strategy = cache.strategy ? typeof cache.strategy === "string" ? require_cache.createStrategy(cache.strategy, swrOptions) : cache.strategy : require_cache.createStrategy("cache-first");
32
- const cacheTtlMs = cache.ttlMs ?? 6e4;
33
- const cacheFlush = cache.flush ?? "auto";
34
- let currentCv;
35
- const client = require_client_gen.createClient(require_utils_gen.createConfig({
36
- auth: accessToken,
37
- baseUrl: baseUrl || (0, _storyblok_region_helper.getRegionBaseUrl)(region),
38
- headers,
39
- throwOnError,
40
- kyOptions: {
41
- throwHttpErrors: true,
42
- timeout,
43
- retry: retryOptions,
44
- ...customFetch && { fetch: customFetch }
45
- }
46
- }));
47
- client.interceptors.error.use((error, response) => new require_error.ClientError(response?.statusText || "API request failed", {
48
- status: response?.status ?? 0,
49
- statusText: response?.statusText ?? "",
50
- data: error
51
- }));
52
- const security = [{
53
- in: "query",
54
- name: "token",
55
- type: "apiKey"
56
- }];
57
- const updateCv = async (result) => {
58
- const nextCv = require_cv.extractCv(result.data);
59
- if (nextCv === void 0) return true;
60
- if (currentCv !== void 0 && nextCv < currentCv) return false;
61
- if (cacheFlush === "auto" && currentCv !== void 0 && currentCv !== nextCv) await cacheProvider.flush();
62
- currentCv = nextCv;
63
- return true;
64
- };
65
- const cacheSuccessResult = async (key, result) => {
66
- const shouldCacheResult = await updateCv(result);
67
- if (result.error === void 0 && shouldCacheResult) await cacheProvider.set(key, {
68
- value: result,
69
- ttlMs: cacheTtlMs
70
- });
71
- return result;
72
- };
73
- const requestNetwork = async (method, path, query, options) => {
74
- return client.request({
75
- ...options,
76
- method,
77
- query,
78
- security,
79
- url: path
80
- });
81
- };
82
- /**
83
- * Wraps a raw SDK call to cast the `error: unknown` type returned by
84
- * generated code to `ClientError` — the error interceptor ensures the
85
- * runtime value IS a ClientError.
86
- */
87
- const asApiResponse = (p) => p;
88
- const requestWithCache = async (method, path, rawQuery, fetchFn, cacheOptions) => {
89
- const query = currentCv !== void 0 ? require_cv.applyCvToQuery(rawQuery, currentCv) : rawQuery;
90
- if (!require_request.shouldUseCache(method, path, rawQuery)) {
91
- const networkResult = await fetchFn(query);
92
- throttleManager.adaptToResponse(networkResult.response);
93
- await updateCv(networkResult);
94
- return networkResult;
95
- }
96
- const baseKey = require_request.createCacheKey(method, path, rawQuery);
97
- const key = cacheOptions?.cacheKeyPrefix ? `${cacheOptions.cacheKeyPrefix}:${baseKey}` : baseKey;
98
- const cachedResult = (await cacheProvider.get(key))?.value;
99
- const loadNetwork = async () => {
100
- const result = await fetchFn(query);
101
- throttleManager.adaptToResponse(result.response);
102
- return cacheSuccessResult(key, result);
103
- };
104
- return strategy({
105
- key,
106
- cachedResult,
107
- loadNetwork
108
- });
109
- };
110
- const request = async (method, path, options = {}) => {
111
- const rawQuery = options.query || {};
112
- return requestWithCache(method, path, rawQuery, (query) => {
113
- return throttleManager.execute(path, rawQuery, () => requestNetwork(method, path, query, options));
114
- });
115
- };
116
- const getRequest = (path, options = {}) => {
117
- return request("GET", path, options);
118
- };
119
- const resourceDeps = {
120
- client,
121
- requestWithCache,
122
- asApiResponse,
123
- throttleManager
124
- };
125
- const stories = require_stories.createStoriesResource({
126
- ...resourceDeps,
127
- inlineRelations
128
- });
129
- /**
130
- * Flush the in-memory cache and reset the tracked cv.
131
- *
132
- * Call this explicitly when `cache.flush` is set to `'manual'`, e.g. after
133
- * receiving a Storyblok webhook event that signals content has changed.
134
- */
135
- const flushCache = async () => {
136
- await cacheProvider.flush();
137
- currentCv = void 0;
138
- };
139
- return {
140
- datasourceEntries: require_datasource_entries.createDatasourceEntriesResource(resourceDeps),
141
- datasources: require_datasources.createDatasourcesResource(resourceDeps),
142
- flushCache,
143
- get: getRequest,
144
- interceptors: client.interceptors,
145
- links: require_links.createLinksResource(resourceDeps),
146
- spaces: require_spaces.createSpacesResource(resourceDeps),
147
- stories,
148
- tags: require_tags.createTagsResource(resourceDeps)
149
- };
150
- };
151
-
152
- //#endregion
153
5
  exports.ClientError = require_error.ClientError;
154
- exports.createApiClient = createApiClient;
155
- exports.createThrottle = require_rate_limit.createThrottle;
156
- exports.parseRateLimitPolicyHeader = require_rate_limit.parseRateLimitPolicyHeader;
157
- //# sourceMappingURL=index.cjs.map
6
+ exports.createApiClient = require_client.createApiClient;
package/dist/index.d.cts CHANGED
@@ -1,175 +1,7 @@
1
- import { DatasourceEntryCapi, ListData, ListResponses } from "./generated/datasource_entries/types.gen.cjs";
2
- import { DatasourceCapi, GetData, GetResponses, ListData as ListData$1, ListResponses as ListResponses$1 } from "./generated/datasources/types.gen.cjs";
3
1
  import { Middleware } from "./generated/shared/client/utils.gen.cjs";
4
- import { ResolvedRequestOptions } from "./generated/shared/client/types.gen.cjs";
5
- import { LinkCapi, ListData as ListData$2, ListResponses as ListResponses$2 } from "./generated/links/types.gen.cjs";
6
- import { GetResponses as GetResponses$1, SpaceCapi } from "./generated/spaces/types.gen.cjs";
7
- import { GetData as GetData$1, ListData as ListData$3, StoryCapi } from "./generated/stories/types.gen.cjs";
8
- import { ListData as ListData$4, ListResponses as ListResponses$3, TagCapi } from "./generated/tags/types.gen.cjs";
9
2
  import { CacheProvider, CacheStrategy, CacheStrategyHandler } from "./utils/cache.cjs";
10
- import { ClientError } from "./error.cjs";
11
- import { RateLimitConfig, createThrottle, parseRateLimitPolicyHeader } from "./utils/rate-limit.cjs";
12
- import { ApiResponse, FetchOptions, HttpRequestMethod, HttpRequestOptions } from "./types.cjs";
3
+ import { ApiErrorBody, ClientError } from "./error.cjs";
13
4
  import { StoryWithInlinedRelations } from "./resources/stories.cjs";
14
- import { RetryOptions } from "ky";
15
- import { Region } from "@storyblok/region-helper";
16
-
17
- //#region src/index.d.ts
18
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
19
- type Story = Prettify<StoryCapi>;
20
- /**
21
- * Cache configuration.
22
- *
23
- * **Note:** Requests with `version: 'draft'` always bypass the cache regardless
24
- * of the configured strategy. Only published content is cached.
25
- */
26
- interface CacheConfig {
27
- /** Custom cache provider. Defaults to an in-memory LRU cache (1 000 entries). */
28
- provider?: CacheProvider;
29
- /** Cache strategy for published requests. @default 'cache-first' */
30
- strategy?: CacheStrategy | CacheStrategyHandler;
31
- /** Time-to-live in milliseconds for cached entries. @default 60_000 */
32
- ttlMs?: number;
33
- /**
34
- * Controls when the cache is flushed on cv change.
35
- *
36
- * - `'auto'` (default): automatically flush the cache whenever the API returns a new cv value.
37
- * - `'manual'`: never auto-flush; call `client.flushCache()` explicitly (e.g. on webhook trigger).
38
- */
39
- flush?: 'auto' | 'manual';
40
- /**
41
- * Called when SWR background revalidation fails.
42
- * Only relevant when `strategy` is `'swr'`.
43
- * @default console.warn
44
- */
45
- onRevalidationError?: (error: unknown) => void;
46
- }
47
- interface ContentApiClientConfig<ThrowOnError extends boolean = false, InlineRelations extends boolean = false> {
48
- accessToken: string;
49
- region?: Region;
50
- baseUrl?: string;
51
- headers?: Record<string, string>;
52
- throwOnError?: ThrowOnError;
53
- cache?: CacheConfig;
54
- inlineRelations?: InlineRelations;
55
- retry?: RetryOptions;
56
- /**
57
- * Request timeout in milliseconds.
58
- * @default 30_000
59
- */
60
- timeout?: number;
61
- /**
62
- * Preventive rate limiting to avoid hitting the Storyblok CDN rate limits.
63
- *
64
- * - `undefined` (default): auto-detect tier from path + `per_page` query param.
65
- * - `number`: fixed max concurrent requests per second (single queue).
66
- * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.
67
- * - `false`: disable rate limiting entirely.
68
- */
69
- rateLimit?: RateLimitConfig | number | false;
70
- /**
71
- * Custom `fetch` function to use for all requests.
72
- * Must be fully compatible with the Fetch API standard.
73
- *
74
- * Use cases:
75
- * - SSR framework fetch wrappers (e.g., Next.js `fetch` with caching)
76
- * - Custom instrumentation or logging around requests
77
- *
78
- * @default globalThis.fetch
79
- */
80
- fetch?: typeof globalThis.fetch;
81
- }
82
- declare const createApiClient: <ThrowOnError extends boolean = false, InlineRelations extends boolean = false>(config: ContentApiClientConfig<ThrowOnError, InlineRelations>) => {
83
- datasourceEntries: {
84
- list: <ThrowOnError_1 extends boolean = false>(options?: {
85
- query?: ListData["query"];
86
- signal?: AbortSignal;
87
- throwOnError?: ThrowOnError_1;
88
- fetchOptions?: FetchOptions;
89
- }) => Promise<ApiResponse<ListResponses[200], ThrowOnError_1>>;
90
- };
91
- datasources: {
92
- get: <ThrowOnError_1 extends boolean = false>(id: GetData["path"]["id"], options?: {
93
- query?: GetData["query"];
94
- signal?: AbortSignal;
95
- throwOnError?: ThrowOnError_1;
96
- fetchOptions?: FetchOptions;
97
- }) => Promise<ApiResponse<GetResponses[200], ThrowOnError_1>>;
98
- list: <ThrowOnError_1 extends boolean = false>(options?: {
99
- query?: ListData$1["query"];
100
- signal?: AbortSignal;
101
- throwOnError?: ThrowOnError_1;
102
- fetchOptions?: FetchOptions;
103
- }) => Promise<ApiResponse<ListResponses$1[200], ThrowOnError_1>>;
104
- };
105
- flushCache: () => Promise<void>;
106
- get: (path: string, options?: HttpRequestOptions) => Promise<{
107
- data?: unknown;
108
- error?: ClientError;
109
- response: Response;
110
- request: Request;
111
- }>;
112
- interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions<"fields", boolean, string>>;
113
- links: {
114
- list: <ThrowOnError_1 extends boolean = false>(options?: {
115
- query?: ListData$2["query"];
116
- signal?: AbortSignal;
117
- throwOnError?: ThrowOnError_1;
118
- fetchOptions?: FetchOptions;
119
- }) => Promise<ApiResponse<ListResponses$2[200], ThrowOnError_1>>;
120
- };
121
- spaces: {
122
- get: <ThrowOnError_1 extends boolean = false>(options?: {
123
- signal?: AbortSignal;
124
- throwOnError?: ThrowOnError_1;
125
- fetchOptions?: FetchOptions;
126
- }) => Promise<ApiResponse<GetResponses$1[200], ThrowOnError_1>>;
127
- };
128
- stories: {
129
- get: <ThrowOnError_1 extends boolean = false>(identifier: string | number, options?: {
130
- query?: GetData$1["query"];
131
- signal?: AbortSignal;
132
- throwOnError?: ThrowOnError_1 | undefined;
133
- fetchOptions?: FetchOptions;
134
- }) => Promise<ApiResponse<Omit<{
135
- story: StoryCapi;
136
- cv?: number;
137
- rels?: Array<StoryCapi>;
138
- links?: Array<{
139
- [key: string]: unknown;
140
- }>;
141
- rel_uuids?: Array<string>;
142
- link_uuids?: Array<string>;
143
- }, "story"> & {
144
- story: InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi;
145
- }, ThrowOnError_1>>;
146
- list: <ThrowOnError_1 extends boolean = false>(options?: {
147
- query?: ListData$3["query"];
148
- signal?: AbortSignal;
149
- throwOnError?: ThrowOnError_1 | undefined;
150
- fetchOptions?: FetchOptions;
151
- }) => Promise<ApiResponse<Omit<{
152
- stories: Array<StoryCapi>;
153
- cv?: number;
154
- rels?: Array<StoryCapi>;
155
- links?: Array<{
156
- [key: string]: unknown;
157
- }>;
158
- rel_uuids?: Array<string>;
159
- link_uuids?: Array<string>;
160
- }, "stories"> & {
161
- stories: (InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi)[];
162
- }, ThrowOnError_1>>;
163
- };
164
- tags: {
165
- list: <ThrowOnError_1 extends boolean = false>(options?: {
166
- query?: ListData$4["query"];
167
- signal?: AbortSignal;
168
- throwOnError?: ThrowOnError_1;
169
- fetchOptions?: FetchOptions;
170
- }) => Promise<ApiResponse<ListResponses$3[200], ThrowOnError_1>>;
171
- };
172
- };
173
- //#endregion
174
- export { type ApiResponse, type CacheProvider, type CacheStrategy, type CacheStrategyHandler, ClientError, ContentApiClientConfig, type DatasourceCapi as Datasource, type DatasourceEntryCapi as DatasourceEntry, type FetchOptions, type HttpRequestMethod, type HttpRequestOptions, type LinkCapi as Link, type Middleware, type RateLimitConfig, type SpaceCapi as Space, Story, type StoryWithInlinedRelations, type TagCapi as Tag, createApiClient, createThrottle, parseRateLimitPolicyHeader };
175
- //# sourceMappingURL=index.d.cts.map
5
+ import { ApiResponse, CacheConfig, ContentApiClient, ContentApiClientConfig, FetchOptions, HttpRequestMethod, HttpRequestOptions, RequestWithCacheOptions, ResourceDeps, createApiClient } from "./client.cjs";
6
+ import { Block as Component, Datasource, DatasourceEntry, Link, Space, Story, StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug, Tag } from "@storyblok/schema";
7
+ export { type ApiErrorBody, type ApiResponse, type CacheConfig, type CacheProvider, type CacheStrategy, type CacheStrategyHandler, ClientError, type Component, type ContentApiClient, type ContentApiClientConfig, type Datasource, type DatasourceEntry, type FetchOptions, type HttpRequestMethod, type HttpRequestOptions, type Link, type Middleware, type RequestWithCacheOptions, type ResourceDeps, type Space, type Story, type StoryAlternate, type StoryLocalizedPath, type StoryTranslatedSlug, type StoryWithInlinedRelations, type Tag, createApiClient };
package/dist/index.d.mts CHANGED
@@ -1,175 +1,7 @@
1
- import { DatasourceEntryCapi, ListData, ListResponses } from "./generated/datasource_entries/types.gen.mjs";
2
- import { DatasourceCapi, GetData, GetResponses, ListData as ListData$1, ListResponses as ListResponses$1 } from "./generated/datasources/types.gen.mjs";
3
1
  import { Middleware } from "./generated/shared/client/utils.gen.mjs";
4
- import { ResolvedRequestOptions } from "./generated/shared/client/types.gen.mjs";
5
- import { LinkCapi, ListData as ListData$2, ListResponses as ListResponses$2 } from "./generated/links/types.gen.mjs";
6
- import { GetResponses as GetResponses$1, SpaceCapi } from "./generated/spaces/types.gen.mjs";
7
- import { GetData as GetData$1, ListData as ListData$3, StoryCapi } from "./generated/stories/types.gen.mjs";
8
- import { ListData as ListData$4, ListResponses as ListResponses$3, TagCapi } from "./generated/tags/types.gen.mjs";
9
2
  import { CacheProvider, CacheStrategy, CacheStrategyHandler } from "./utils/cache.mjs";
10
- import { ClientError } from "./error.mjs";
11
- import { RateLimitConfig, createThrottle, parseRateLimitPolicyHeader } from "./utils/rate-limit.mjs";
12
- import { ApiResponse, FetchOptions, HttpRequestMethod, HttpRequestOptions } from "./types.mjs";
3
+ import { ApiErrorBody, ClientError } from "./error.mjs";
13
4
  import { StoryWithInlinedRelations } from "./resources/stories.mjs";
14
- import { RetryOptions } from "ky";
15
- import { Region } from "@storyblok/region-helper";
16
-
17
- //#region src/index.d.ts
18
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
19
- type Story = Prettify<StoryCapi>;
20
- /**
21
- * Cache configuration.
22
- *
23
- * **Note:** Requests with `version: 'draft'` always bypass the cache regardless
24
- * of the configured strategy. Only published content is cached.
25
- */
26
- interface CacheConfig {
27
- /** Custom cache provider. Defaults to an in-memory LRU cache (1 000 entries). */
28
- provider?: CacheProvider;
29
- /** Cache strategy for published requests. @default 'cache-first' */
30
- strategy?: CacheStrategy | CacheStrategyHandler;
31
- /** Time-to-live in milliseconds for cached entries. @default 60_000 */
32
- ttlMs?: number;
33
- /**
34
- * Controls when the cache is flushed on cv change.
35
- *
36
- * - `'auto'` (default): automatically flush the cache whenever the API returns a new cv value.
37
- * - `'manual'`: never auto-flush; call `client.flushCache()` explicitly (e.g. on webhook trigger).
38
- */
39
- flush?: 'auto' | 'manual';
40
- /**
41
- * Called when SWR background revalidation fails.
42
- * Only relevant when `strategy` is `'swr'`.
43
- * @default console.warn
44
- */
45
- onRevalidationError?: (error: unknown) => void;
46
- }
47
- interface ContentApiClientConfig<ThrowOnError extends boolean = false, InlineRelations extends boolean = false> {
48
- accessToken: string;
49
- region?: Region;
50
- baseUrl?: string;
51
- headers?: Record<string, string>;
52
- throwOnError?: ThrowOnError;
53
- cache?: CacheConfig;
54
- inlineRelations?: InlineRelations;
55
- retry?: RetryOptions;
56
- /**
57
- * Request timeout in milliseconds.
58
- * @default 30_000
59
- */
60
- timeout?: number;
61
- /**
62
- * Preventive rate limiting to avoid hitting the Storyblok CDN rate limits.
63
- *
64
- * - `undefined` (default): auto-detect tier from path + `per_page` query param.
65
- * - `number`: fixed max concurrent requests per second (single queue).
66
- * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.
67
- * - `false`: disable rate limiting entirely.
68
- */
69
- rateLimit?: RateLimitConfig | number | false;
70
- /**
71
- * Custom `fetch` function to use for all requests.
72
- * Must be fully compatible with the Fetch API standard.
73
- *
74
- * Use cases:
75
- * - SSR framework fetch wrappers (e.g., Next.js `fetch` with caching)
76
- * - Custom instrumentation or logging around requests
77
- *
78
- * @default globalThis.fetch
79
- */
80
- fetch?: typeof globalThis.fetch;
81
- }
82
- declare const createApiClient: <ThrowOnError extends boolean = false, InlineRelations extends boolean = false>(config: ContentApiClientConfig<ThrowOnError, InlineRelations>) => {
83
- datasourceEntries: {
84
- list: <ThrowOnError_1 extends boolean = false>(options?: {
85
- query?: ListData["query"];
86
- signal?: AbortSignal;
87
- throwOnError?: ThrowOnError_1;
88
- fetchOptions?: FetchOptions;
89
- }) => Promise<ApiResponse<ListResponses[200], ThrowOnError_1>>;
90
- };
91
- datasources: {
92
- get: <ThrowOnError_1 extends boolean = false>(id: GetData["path"]["id"], options?: {
93
- query?: GetData["query"];
94
- signal?: AbortSignal;
95
- throwOnError?: ThrowOnError_1;
96
- fetchOptions?: FetchOptions;
97
- }) => Promise<ApiResponse<GetResponses[200], ThrowOnError_1>>;
98
- list: <ThrowOnError_1 extends boolean = false>(options?: {
99
- query?: ListData$1["query"];
100
- signal?: AbortSignal;
101
- throwOnError?: ThrowOnError_1;
102
- fetchOptions?: FetchOptions;
103
- }) => Promise<ApiResponse<ListResponses$1[200], ThrowOnError_1>>;
104
- };
105
- flushCache: () => Promise<void>;
106
- get: (path: string, options?: HttpRequestOptions) => Promise<{
107
- data?: unknown;
108
- error?: ClientError;
109
- response: Response;
110
- request: Request;
111
- }>;
112
- interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions<"fields", boolean, string>>;
113
- links: {
114
- list: <ThrowOnError_1 extends boolean = false>(options?: {
115
- query?: ListData$2["query"];
116
- signal?: AbortSignal;
117
- throwOnError?: ThrowOnError_1;
118
- fetchOptions?: FetchOptions;
119
- }) => Promise<ApiResponse<ListResponses$2[200], ThrowOnError_1>>;
120
- };
121
- spaces: {
122
- get: <ThrowOnError_1 extends boolean = false>(options?: {
123
- signal?: AbortSignal;
124
- throwOnError?: ThrowOnError_1;
125
- fetchOptions?: FetchOptions;
126
- }) => Promise<ApiResponse<GetResponses$1[200], ThrowOnError_1>>;
127
- };
128
- stories: {
129
- get: <ThrowOnError_1 extends boolean = false>(identifier: string | number, options?: {
130
- query?: GetData$1["query"];
131
- signal?: AbortSignal;
132
- throwOnError?: ThrowOnError_1 | undefined;
133
- fetchOptions?: FetchOptions;
134
- }) => Promise<ApiResponse<Omit<{
135
- story: StoryCapi;
136
- cv?: number;
137
- rels?: Array<StoryCapi>;
138
- links?: Array<{
139
- [key: string]: unknown;
140
- }>;
141
- rel_uuids?: Array<string>;
142
- link_uuids?: Array<string>;
143
- }, "story"> & {
144
- story: InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi;
145
- }, ThrowOnError_1>>;
146
- list: <ThrowOnError_1 extends boolean = false>(options?: {
147
- query?: ListData$3["query"];
148
- signal?: AbortSignal;
149
- throwOnError?: ThrowOnError_1 | undefined;
150
- fetchOptions?: FetchOptions;
151
- }) => Promise<ApiResponse<Omit<{
152
- stories: Array<StoryCapi>;
153
- cv?: number;
154
- rels?: Array<StoryCapi>;
155
- links?: Array<{
156
- [key: string]: unknown;
157
- }>;
158
- rel_uuids?: Array<string>;
159
- link_uuids?: Array<string>;
160
- }, "stories"> & {
161
- stories: (InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi)[];
162
- }, ThrowOnError_1>>;
163
- };
164
- tags: {
165
- list: <ThrowOnError_1 extends boolean = false>(options?: {
166
- query?: ListData$4["query"];
167
- signal?: AbortSignal;
168
- throwOnError?: ThrowOnError_1;
169
- fetchOptions?: FetchOptions;
170
- }) => Promise<ApiResponse<ListResponses$3[200], ThrowOnError_1>>;
171
- };
172
- };
173
- //#endregion
174
- export { type ApiResponse, type CacheProvider, type CacheStrategy, type CacheStrategyHandler, ClientError, ContentApiClientConfig, type DatasourceCapi as Datasource, type DatasourceEntryCapi as DatasourceEntry, type FetchOptions, type HttpRequestMethod, type HttpRequestOptions, type LinkCapi as Link, type Middleware, type RateLimitConfig, type SpaceCapi as Space, Story, type StoryWithInlinedRelations, type TagCapi as Tag, createApiClient, createThrottle, parseRateLimitPolicyHeader };
175
- //# sourceMappingURL=index.d.mts.map
5
+ import { ApiResponse, CacheConfig, ContentApiClient, ContentApiClientConfig, FetchOptions, HttpRequestMethod, HttpRequestOptions, RequestWithCacheOptions, ResourceDeps, createApiClient } from "./client.mjs";
6
+ import { Block as Component, Datasource, DatasourceEntry, Link, Space, Story, StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug, Tag } from "@storyblok/schema";
7
+ export { type ApiErrorBody, type ApiResponse, type CacheConfig, type CacheProvider, type CacheStrategy, type CacheStrategyHandler, ClientError, type Component, type ContentApiClient, type ContentApiClientConfig, type Datasource, type DatasourceEntry, type FetchOptions, type HttpRequestMethod, type HttpRequestOptions, type Link, type Middleware, type RequestWithCacheOptions, type ResourceDeps, type Space, type Story, type StoryAlternate, type StoryLocalizedPath, type StoryTranslatedSlug, type StoryWithInlinedRelations, type Tag, createApiClient };