@storyblok/api-client 0.2.3 → 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 (65) 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/inline-relations.cjs +13 -1
  52. package/dist/utils/inline-relations.cjs.map +1 -1
  53. package/dist/utils/inline-relations.mjs +13 -1
  54. package/dist/utils/inline-relations.mjs.map +1 -1
  55. package/dist/utils/rate-limit.cjs +9 -5
  56. package/dist/utils/rate-limit.cjs.map +1 -1
  57. package/dist/utils/rate-limit.d.cts +4 -18
  58. package/dist/utils/rate-limit.d.mts +4 -18
  59. package/dist/utils/rate-limit.mjs +10 -4
  60. package/dist/utils/rate-limit.mjs.map +1 -1
  61. package/package.json +18 -8
  62. package/dist/index.cjs.map +0 -1
  63. package/dist/index.mjs.map +0 -1
  64. package/dist/types.d.cts +0 -37
  65. package/dist/types.d.mts +0 -37
package/dist/index.mjs CHANGED
@@ -1,152 +1,4 @@
1
- import { createConfig } from "./generated/shared/client/utils.gen.mjs";
2
- import { createClient } from "./generated/shared/client/client.gen.mjs";
3
- import "./generated/shared/client/index.mjs";
4
- import { createMemoryCacheProvider, createStrategy } from "./utils/cache.mjs";
5
1
  import { ClientError } from "./error.mjs";
6
- import { createThrottle, createThrottleManager, parseRateLimitPolicyHeader } from "./utils/rate-limit.mjs";
7
- import { createCacheKey, shouldUseCache } from "./utils/request.mjs";
8
- import { applyCvToQuery, extractCv } from "./utils/cv.mjs";
9
- import { createStoriesResource } from "./resources/stories.mjs";
10
- import { createLinksResource } from "./resources/links.mjs";
11
- import { createTagsResource } from "./resources/tags.mjs";
12
- import { createDatasourcesResource } from "./resources/datasources.mjs";
13
- import { createDatasourceEntriesResource } from "./resources/datasource-entries.mjs";
14
- import { createSpacesResource } from "./resources/spaces.mjs";
15
- import { getRegionBaseUrl } from "@storyblok/region-helper";
2
+ import { createApiClient } from "./client.mjs";
16
3
 
17
- //#region src/index.ts
18
- const createApiClient = (config) => {
19
- const { accessToken, region = "eu", baseUrl, headers = {}, throwOnError = false, cache = {}, inlineRelations = false, retry, timeout = 3e4, rateLimit, fetch: customFetch } = config;
20
- const retryOptions = {
21
- limit: 3,
22
- backoffLimit: 2e4,
23
- jitter: true,
24
- ...retry
25
- };
26
- const throttleManager = createThrottleManager(rateLimit ?? {});
27
- const cacheProvider = cache.provider ?? createMemoryCacheProvider();
28
- const swrOptions = cache.onRevalidationError ? { onRevalidationError: cache.onRevalidationError } : void 0;
29
- const strategy = cache.strategy ? typeof cache.strategy === "string" ? createStrategy(cache.strategy, swrOptions) : cache.strategy : createStrategy("cache-first");
30
- const cacheTtlMs = cache.ttlMs ?? 6e4;
31
- const cacheFlush = cache.flush ?? "auto";
32
- let currentCv;
33
- const client = createClient(createConfig({
34
- auth: accessToken,
35
- baseUrl: baseUrl || getRegionBaseUrl(region),
36
- headers,
37
- throwOnError,
38
- kyOptions: {
39
- throwHttpErrors: true,
40
- timeout,
41
- retry: retryOptions,
42
- ...customFetch && { fetch: customFetch }
43
- }
44
- }));
45
- client.interceptors.error.use((error, response) => new ClientError(response?.statusText || "API request failed", {
46
- status: response?.status ?? 0,
47
- statusText: response?.statusText ?? "",
48
- data: error
49
- }));
50
- const security = [{
51
- in: "query",
52
- name: "token",
53
- type: "apiKey"
54
- }];
55
- const updateCv = async (result) => {
56
- const nextCv = extractCv(result.data);
57
- if (nextCv === void 0) return true;
58
- if (currentCv !== void 0 && nextCv < currentCv) return false;
59
- if (cacheFlush === "auto" && currentCv !== void 0 && currentCv !== nextCv) await cacheProvider.flush();
60
- currentCv = nextCv;
61
- return true;
62
- };
63
- const cacheSuccessResult = async (key, result) => {
64
- const shouldCacheResult = await updateCv(result);
65
- if (result.error === void 0 && shouldCacheResult) await cacheProvider.set(key, {
66
- value: result,
67
- ttlMs: cacheTtlMs
68
- });
69
- return result;
70
- };
71
- const requestNetwork = async (method, path, query, options) => {
72
- return client.request({
73
- ...options,
74
- method,
75
- query,
76
- security,
77
- url: path
78
- });
79
- };
80
- /**
81
- * Wraps a raw SDK call to cast the `error: unknown` type returned by
82
- * generated code to `ClientError` — the error interceptor ensures the
83
- * runtime value IS a ClientError.
84
- */
85
- const asApiResponse = (p) => p;
86
- const requestWithCache = async (method, path, rawQuery, fetchFn, cacheOptions) => {
87
- const query = currentCv !== void 0 ? applyCvToQuery(rawQuery, currentCv) : rawQuery;
88
- if (!shouldUseCache(method, path, rawQuery)) {
89
- const networkResult = await fetchFn(query);
90
- throttleManager.adaptToResponse(networkResult.response);
91
- await updateCv(networkResult);
92
- return networkResult;
93
- }
94
- const baseKey = createCacheKey(method, path, rawQuery);
95
- const key = cacheOptions?.cacheKeyPrefix ? `${cacheOptions.cacheKeyPrefix}:${baseKey}` : baseKey;
96
- const cachedResult = (await cacheProvider.get(key))?.value;
97
- const loadNetwork = async () => {
98
- const result = await fetchFn(query);
99
- throttleManager.adaptToResponse(result.response);
100
- return cacheSuccessResult(key, result);
101
- };
102
- return strategy({
103
- key,
104
- cachedResult,
105
- loadNetwork
106
- });
107
- };
108
- const request = async (method, path, options = {}) => {
109
- const rawQuery = options.query || {};
110
- return requestWithCache(method, path, rawQuery, (query) => {
111
- return throttleManager.execute(path, rawQuery, () => requestNetwork(method, path, query, options));
112
- });
113
- };
114
- const getRequest = (path, options = {}) => {
115
- return request("GET", path, options);
116
- };
117
- const resourceDeps = {
118
- client,
119
- requestWithCache,
120
- asApiResponse,
121
- throttleManager
122
- };
123
- const stories = createStoriesResource({
124
- ...resourceDeps,
125
- inlineRelations
126
- });
127
- /**
128
- * Flush the in-memory cache and reset the tracked cv.
129
- *
130
- * Call this explicitly when `cache.flush` is set to `'manual'`, e.g. after
131
- * receiving a Storyblok webhook event that signals content has changed.
132
- */
133
- const flushCache = async () => {
134
- await cacheProvider.flush();
135
- currentCv = void 0;
136
- };
137
- return {
138
- datasourceEntries: createDatasourceEntriesResource(resourceDeps),
139
- datasources: createDatasourcesResource(resourceDeps),
140
- flushCache,
141
- get: getRequest,
142
- interceptors: client.interceptors,
143
- links: createLinksResource(resourceDeps),
144
- spaces: createSpacesResource(resourceDeps),
145
- stories,
146
- tags: createTagsResource(resourceDeps)
147
- };
148
- };
149
-
150
- //#endregion
151
- export { ClientError, createApiClient, createThrottle, parseRateLimitPolicyHeader };
152
- //# sourceMappingURL=index.mjs.map
4
+ export { ClientError, createApiClient };
@@ -1 +1 @@
1
- {"version":3,"file":"datasource-entries.cjs","names":["listDatasourceEntriesApi"],"sources":["../../src/resources/datasource-entries.ts"],"sourcesContent":["import { list as listDatasourceEntriesApi } from '../generated/datasource_entries/sdk.gen';\nimport type {\n ListData as DatasourceEntriesListData,\n ListResponses as DatasourceEntriesListResponses,\n} from '../generated/datasource_entries/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createDatasourceEntriesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: DatasourceEntriesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasource_entries';\n return requestWithCache<DatasourceEntriesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>(listDatasourceEntriesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAOA,SAAgB,gCAAgC,MAAoB;CAClE,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA0I,EAAE,KAChE;EAC5E,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAoE,OAAO,aAAa,QAAQ,iBAA0C;AAC/I,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAiEA,qBAAyB;IACxF;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"datasource-entries.cjs","names":["listDatasourceEntriesApi"],"sources":["../../src/resources/datasource-entries.ts"],"sourcesContent":["import { list as listDatasourceEntriesApi } from '../generated/datasource_entries/sdk.gen';\nimport type {\n ListData as DatasourceEntriesListData,\n ListResponses as DatasourceEntriesListResponses,\n} from '../generated/datasource_entries/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createDatasourceEntriesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: DatasourceEntriesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasource_entries';\n return requestWithCache<DatasourceEntriesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>(listDatasourceEntriesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAOA,SAAgB,gCAA6E,MAAyC;CACpI,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA0I,EAAE,KAChE;EAC5E,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAoE,OAAO,aAAa,QAAQ,iBAA0C;AAC/I,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAiEA,qBAAyB;IACxF;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"datasource-entries.mjs","names":["listDatasourceEntriesApi"],"sources":["../../src/resources/datasource-entries.ts"],"sourcesContent":["import { list as listDatasourceEntriesApi } from '../generated/datasource_entries/sdk.gen';\nimport type {\n ListData as DatasourceEntriesListData,\n ListResponses as DatasourceEntriesListResponses,\n} from '../generated/datasource_entries/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createDatasourceEntriesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: DatasourceEntriesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasource_entries';\n return requestWithCache<DatasourceEntriesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>(listDatasourceEntriesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAOA,SAAgB,gCAAgC,MAAoB;CAClE,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA0I,EAAE,KAChE;EAC5E,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAoE,OAAO,aAAa,QAAQ,iBAA0C;AAC/I,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAiEA,KAAyB;IACxF;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"datasource-entries.mjs","names":["listDatasourceEntriesApi"],"sources":["../../src/resources/datasource-entries.ts"],"sourcesContent":["import { list as listDatasourceEntriesApi } from '../generated/datasource_entries/sdk.gen';\nimport type {\n ListData as DatasourceEntriesListData,\n ListResponses as DatasourceEntriesListResponses,\n} from '../generated/datasource_entries/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createDatasourceEntriesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: DatasourceEntriesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasource_entries';\n return requestWithCache<DatasourceEntriesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourceEntriesListResponses[200], ThrowOnError>(listDatasourceEntriesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAOA,SAAgB,gCAA6E,MAAyC;CACpI,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA0I,EAAE,KAChE;EAC5E,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAoE,OAAO,aAAa,QAAQ,iBAA0C;AAC/I,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAiEA,KAAyB;IACxF;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"datasources.cjs","names":["getDatasourceApi","listDatasourcesApi"],"sources":["../../src/resources/datasources.ts"],"sourcesContent":["import { get as getDatasourceApi, list as listDatasourcesApi } from '../generated/datasources/sdk.gen';\nimport type {\n GetData as DatasourcesGetData,\n GetResponses as DatasourcesGetResponses,\n ListData as DatasourcesListData,\n ListResponses as DatasourcesListResponses,\n} from '../generated/datasources/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createDatasourcesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = false>(\n id: DatasourcesGetData['path']['id'],\n options: { query?: DatasourcesGetData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesGetResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = `/v2/cdn/datasources/${id}`;\n return requestWithCache<DatasourcesGetResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesGetResponses[200], ThrowOnError>(getDatasourceApi({\n client,\n path: { id },\n query: requestQuery as DatasourcesGetData['query'], // bridge generic cache callback (Record<string, unknown>) to typed SDK query\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: DatasourcesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasources';\n return requestWithCache<DatasourcesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesListResponses[200], ThrowOnError>(listDatasourcesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AASA,SAAgB,0BAA0B,MAAoB;CAC5D,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO;EACL,KAAK,OACH,IACA,UAAmI,EAAE,KAChE;GACrE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc,uBAAuB;AAC3C,UAAO,iBAA6D,OAAO,aAAa,QAAQ,iBAA0C;AACxI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA0DA,oBAAiB;KACzE;KACA,MAAM,EAAE,IAAI;KACZ,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAGJ,MAAM,OACJ,UAAoI,EAAE,KAChE;GACtE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc;AACpB,UAAO,iBAA8D,OAAO,aAAa,QAAQ,iBAA0C;AACzI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA2DC,qBAAmB;KAC5E;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAEL"}
1
+ {"version":3,"file":"datasources.cjs","names":["getDatasourceApi","listDatasourcesApi"],"sources":["../../src/resources/datasources.ts"],"sourcesContent":["import { get as getDatasourceApi, list as listDatasourcesApi } from '../generated/datasources/sdk.gen';\nimport type {\n GetData as DatasourcesGetData,\n GetResponses as DatasourcesGetResponses,\n ListData as DatasourcesListData,\n ListResponses as DatasourcesListResponses,\n} from '../generated/datasources/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createDatasourcesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n id: DatasourcesGetData['path']['id'],\n options: { query?: DatasourcesGetData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesGetResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = `/v2/cdn/datasources/${id}`;\n return requestWithCache<DatasourcesGetResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesGetResponses[200], ThrowOnError>(getDatasourceApi({\n client,\n path: { id },\n query: requestQuery as DatasourcesGetData['query'], // bridge generic cache callback (Record<string, unknown>) to typed SDK query\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: DatasourcesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasources';\n return requestWithCache<DatasourcesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesListResponses[200], ThrowOnError>(listDatasourcesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AASA,SAAgB,0BAAuE,MAAyC;CAC9H,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO;EACL,KAAK,OACH,IACA,UAAmI,EAAE,KAChE;GACrE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc,uBAAuB;AAC3C,UAAO,iBAA6D,OAAO,aAAa,QAAQ,iBAA0C;AACxI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA0DA,oBAAiB;KACzE;KACA,MAAM,EAAE,IAAI;KACZ,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAGJ,MAAM,OACJ,UAAoI,EAAE,KAChE;GACtE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc;AACpB,UAAO,iBAA8D,OAAO,aAAa,QAAQ,iBAA0C;AACzI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA2DC,qBAAmB;KAC5E;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"datasources.mjs","names":["getDatasourceApi","listDatasourcesApi"],"sources":["../../src/resources/datasources.ts"],"sourcesContent":["import { get as getDatasourceApi, list as listDatasourcesApi } from '../generated/datasources/sdk.gen';\nimport type {\n GetData as DatasourcesGetData,\n GetResponses as DatasourcesGetResponses,\n ListData as DatasourcesListData,\n ListResponses as DatasourcesListResponses,\n} from '../generated/datasources/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createDatasourcesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = false>(\n id: DatasourcesGetData['path']['id'],\n options: { query?: DatasourcesGetData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesGetResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = `/v2/cdn/datasources/${id}`;\n return requestWithCache<DatasourcesGetResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesGetResponses[200], ThrowOnError>(getDatasourceApi({\n client,\n path: { id },\n query: requestQuery as DatasourcesGetData['query'], // bridge generic cache callback (Record<string, unknown>) to typed SDK query\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: DatasourcesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasources';\n return requestWithCache<DatasourcesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesListResponses[200], ThrowOnError>(listDatasourcesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AASA,SAAgB,0BAA0B,MAAoB;CAC5D,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO;EACL,KAAK,OACH,IACA,UAAmI,EAAE,KAChE;GACrE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc,uBAAuB;AAC3C,UAAO,iBAA6D,OAAO,aAAa,QAAQ,iBAA0C;AACxI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA0DA,IAAiB;KACzE;KACA,MAAM,EAAE,IAAI;KACZ,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAGJ,MAAM,OACJ,UAAoI,EAAE,KAChE;GACtE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc;AACpB,UAAO,iBAA8D,OAAO,aAAa,QAAQ,iBAA0C;AACzI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA2DC,KAAmB;KAC5E;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAEL"}
1
+ {"version":3,"file":"datasources.mjs","names":["getDatasourceApi","listDatasourcesApi"],"sources":["../../src/resources/datasources.ts"],"sourcesContent":["import { get as getDatasourceApi, list as listDatasourcesApi } from '../generated/datasources/sdk.gen';\nimport type {\n GetData as DatasourcesGetData,\n GetResponses as DatasourcesGetResponses,\n ListData as DatasourcesListData,\n ListResponses as DatasourcesListResponses,\n} from '../generated/datasources/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createDatasourcesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n id: DatasourcesGetData['path']['id'],\n options: { query?: DatasourcesGetData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesGetResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = `/v2/cdn/datasources/${id}`;\n return requestWithCache<DatasourcesGetResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesGetResponses[200], ThrowOnError>(getDatasourceApi({\n client,\n path: { id },\n query: requestQuery as DatasourcesGetData['query'], // bridge generic cache callback (Record<string, unknown>) to typed SDK query\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: DatasourcesListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<DatasourcesListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/datasources';\n return requestWithCache<DatasourcesListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<DatasourcesListResponses[200], ThrowOnError>(listDatasourcesApi({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AASA,SAAgB,0BAAuE,MAAyC;CAC9H,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO;EACL,KAAK,OACH,IACA,UAAmI,EAAE,KAChE;GACrE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc,uBAAuB;AAC3C,UAAO,iBAA6D,OAAO,aAAa,QAAQ,iBAA0C;AACxI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA0DA,IAAiB;KACzE;KACA,MAAM,EAAE,IAAI;KACZ,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAGJ,MAAM,OACJ,UAAoI,EAAE,KAChE;GACtE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc;AACpB,UAAO,iBAA8D,OAAO,aAAa,QAAQ,iBAA0C;AACzI,WAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAA2DC,KAAmB;KAC5E;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;KACN;;EAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"links.cjs","names":["listLinks"],"sources":["../../src/resources/links.ts"],"sourcesContent":["import { list as listLinks } from '../generated/links/sdk.gen';\nimport type { ListData as LinksListData, ListResponses as LinksListResponses } from '../generated/links/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createLinksResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: LinksListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<LinksListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/links';\n return requestWithCache<LinksListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<LinksListResponses[200], ThrowOnError>(listLinks({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,oBAAoB,MAAoB;CACtD,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA8H,EAAE,KAChE;EAChE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,QAAQ,iBAA0C;AACnI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,qBAAU;IAC7D;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"links.cjs","names":["listLinks"],"sources":["../../src/resources/links.ts"],"sourcesContent":["import { list as listLinks } from '../generated/links/sdk.gen';\nimport type { ListData as LinksListData, ListResponses as LinksListResponses } from '../generated/links/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createLinksResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: LinksListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<LinksListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/links';\n return requestWithCache<LinksListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<LinksListResponses[200], ThrowOnError>(listLinks({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,oBAAiE,MAAyC;CACxH,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA8H,EAAE,KAChE;EAChE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,QAAQ,iBAA0C;AACnI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,qBAAU;IAC7D;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"links.mjs","names":["listLinks"],"sources":["../../src/resources/links.ts"],"sourcesContent":["import { list as listLinks } from '../generated/links/sdk.gen';\nimport type { ListData as LinksListData, ListResponses as LinksListResponses } from '../generated/links/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createLinksResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: LinksListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<LinksListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/links';\n return requestWithCache<LinksListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<LinksListResponses[200], ThrowOnError>(listLinks({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,oBAAoB,MAAoB;CACtD,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA8H,EAAE,KAChE;EAChE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,QAAQ,iBAA0C;AACnI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,KAAU;IAC7D;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"links.mjs","names":["listLinks"],"sources":["../../src/resources/links.ts"],"sourcesContent":["import { list as listLinks } from '../generated/links/sdk.gen';\nimport type { ListData as LinksListData, ListResponses as LinksListResponses } from '../generated/links/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createLinksResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n list: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { query?: LinksListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<LinksListResponses[200], ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/links';\n return requestWithCache<LinksListResponses[200], ThrowOnError>('GET', requestPath, query, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<LinksListResponses[200], ThrowOnError>(listLinks({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,oBAAiE,MAAyC;CACxH,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,MAAM,OACJ,UAA8H,EAAE,KAChE;EAChE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;EAC3D,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,QAAQ,iBAA0C;AACnI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,KAAU;IAC7D;IACA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"spaces.cjs","names":["getSpaceApi"],"sources":["../../src/resources/spaces.ts"],"sourcesContent":["import { get as getSpaceApi } from '../generated/spaces/sdk.gen';\nimport type { GetResponses as SpacesGetResponses } from '../generated/spaces/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createSpacesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = false>(\n options: { signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<SpacesGetResponses[200], ThrowOnError>> => {\n const { signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/spaces/me';\n return requestWithCache<SpacesGetResponses[200], ThrowOnError>('GET', requestPath, {}, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<SpacesGetResponses[200], ThrowOnError>(getSpaceApi({\n client,\n // The OpenAPI spec declares no query params so the generated type\n // is `query?: never`. At runtime we still need to pass a query object\n // because `setAuthParams` mutates it in-place to inject the `token`.\n query: requestQuery as never,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,qBAAqB,MAAoB;CACvD,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,KAAK,OACH,UAA8F,EAAE,KAChC;EAChE,MAAM,EAAE,QAAQ,cAAc,iBAAiB;EAC/C,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,EAAE,GAAG,iBAA0C;AAChI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,oBAAY;IAC/D;IAIA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"spaces.cjs","names":["getSpaceApi"],"sources":["../../src/resources/spaces.ts"],"sourcesContent":["import { get as getSpaceApi } from '../generated/spaces/sdk.gen';\nimport type { GetResponses as SpacesGetResponses } from '../generated/spaces/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createSpacesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<SpacesGetResponses[200], ThrowOnError>> => {\n const { signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/spaces/me';\n return requestWithCache<SpacesGetResponses[200], ThrowOnError>('GET', requestPath, {}, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<SpacesGetResponses[200], ThrowOnError>(getSpaceApi({\n client,\n // The OpenAPI spec declares no query params so the generated type\n // is `query?: never`. At runtime we still need to pass a query object\n // because `setAuthParams` mutates it in-place to inject the `token`.\n query: requestQuery as never,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,qBAAkE,MAAyC;CACzH,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,KAAK,OACH,UAA8F,EAAE,KAChC;EAChE,MAAM,EAAE,QAAQ,cAAc,iBAAiB;EAC/C,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,EAAE,GAAG,iBAA0C;AAChI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,oBAAY;IAC/D;IAIA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -1 +1 @@
1
- {"version":3,"file":"spaces.mjs","names":["getSpaceApi"],"sources":["../../src/resources/spaces.ts"],"sourcesContent":["import { get as getSpaceApi } from '../generated/spaces/sdk.gen';\nimport type { GetResponses as SpacesGetResponses } from '../generated/spaces/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\nexport function createSpacesResource(deps: ResourceDeps) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = false>(\n options: { signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<SpacesGetResponses[200], ThrowOnError>> => {\n const { signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/spaces/me';\n return requestWithCache<SpacesGetResponses[200], ThrowOnError>('GET', requestPath, {}, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<SpacesGetResponses[200], ThrowOnError>(getSpaceApi({\n client,\n // The OpenAPI spec declares no query params so the generated type\n // is `query?: never`. At runtime we still need to pass a query object\n // because `setAuthParams` mutates it in-place to inject the `token`.\n query: requestQuery as never,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,qBAAqB,MAAoB;CACvD,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,KAAK,OACH,UAA8F,EAAE,KAChC;EAChE,MAAM,EAAE,QAAQ,cAAc,iBAAiB;EAC/C,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,EAAE,GAAG,iBAA0C;AAChI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,IAAY;IAC/D;IAIA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
1
+ {"version":3,"file":"spaces.mjs","names":["getSpaceApi"],"sources":["../../src/resources/spaces.ts"],"sourcesContent":["import { get as getSpaceApi } from '../generated/spaces/sdk.gen';\nimport type { GetResponses as SpacesGetResponses } from '../generated/spaces/types.gen';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\n\nexport function createSpacesResource<DefaultThrowOnError extends boolean = false>(deps: ResourceDeps<DefaultThrowOnError>) {\n const { client, requestWithCache, asApiResponse, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = DefaultThrowOnError>(\n options: { signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<SpacesGetResponses[200], ThrowOnError>> => {\n const { signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/spaces/me';\n return requestWithCache<SpacesGetResponses[200], ThrowOnError>('GET', requestPath, {}, (requestQuery: Record<string, unknown>) => {\n return throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<SpacesGetResponses[200], ThrowOnError>(getSpaceApi({\n client,\n // The OpenAPI spec declares no query params so the generated type\n // is `query?: never`. At runtime we still need to pass a query object\n // because `setAuthParams` mutates it in-place to inject the `token`.\n query: requestQuery as never,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n });\n },\n };\n}\n"],"mappings":";;;AAIA,SAAgB,qBAAkE,MAAyC;CACzH,MAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB;AAErE,QAAO,EACL,KAAK,OACH,UAA8F,EAAE,KAChC;EAChE,MAAM,EAAE,QAAQ,cAAc,iBAAiB;EAC/C,MAAM,cAAc;AACpB,SAAO,iBAAwD,OAAO,aAAa,EAAE,GAAG,iBAA0C;AAChI,UAAO,gBAAgB,QAAQ,aAAa,oBAC1C,cAAqDA,IAAY;IAC/D;IAIA,OAAO;IACP;IACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;IACtD,GAAI,eAAe,EAAE,WAAW;KAAE,GAAG,OAAO,WAAW,CAAC;KAAW,GAAG;KAAc,EAAE,GAAG,EAAE;IAC5F,CAAC,CAAC,CAAC;IACN;IAEL"}
@@ -8,10 +8,11 @@ function createStoriesResource(deps) {
8
8
  return {
9
9
  get: async (identifier, options = {}) => {
10
10
  const { query = {}, signal, throwOnError, fetchOptions } = options;
11
- const resolvedQuery = typeof identifier === "string" && UUID_RE.test(identifier) && !query.find_by ? {
12
- ...query,
11
+ const typedQuery = query ?? {};
12
+ const resolvedQuery = typeof identifier === "string" && UUID_RE.test(identifier) && !typedQuery.find_by ? {
13
+ ...typedQuery,
13
14
  find_by: "uuid"
14
- } : query;
15
+ } : typedQuery;
15
16
  const requestPath = `/v2/cdn/stories/${identifier}`;
16
17
  return requestWithCache("GET", requestPath, resolvedQuery, async (requestQuery) => {
17
18
  const response = await throttleManager.execute(requestPath, requestQuery, () => asApiResponse(require_sdk_gen.get({
@@ -42,8 +43,9 @@ function createStoriesResource(deps) {
42
43
  },
43
44
  list: async (options = {}) => {
44
45
  const { query = {}, signal, throwOnError, fetchOptions } = options;
46
+ const typedQuery = query ?? {};
45
47
  const requestPath = "/v2/cdn/stories";
46
- return requestWithCache("GET", requestPath, query, async (requestQuery) => {
48
+ return requestWithCache("GET", requestPath, typedQuery, async (requestQuery) => {
47
49
  const response = await throttleManager.execute(requestPath, requestQuery, () => asApiResponse(require_sdk_gen.list({
48
50
  client,
49
51
  query: requestQuery,
@@ -1 +1 @@
1
- {"version":3,"file":"stories.cjs","names":["get","resolveRelationMap","inlineStoryContent","list","inlineStoriesContent"],"sources":["../../src/resources/stories.ts"],"sourcesContent":["import { get, list } from '../generated/stories/sdk.gen';\nimport type { GetData, GetResponses, ListData, ListResponses } from '../generated/stories/types.gen';\nimport type {\n AssetField,\n MultilinkField,\n PluginField,\n RichtextField,\n StoryCapi,\n StoryContent,\n TableField,\n} from '../generated/stories';\nimport { inlineStoriesContent, inlineStoryContent, resolveRelationMap } from '../utils/inline-relations';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../types';\n\ntype InlinedStoryContentField =\n | string\n | number\n | boolean\n | Array<string | AssetField | StoryContent | StoryWithInlinedRelations>\n | AssetField\n | MultilinkField\n | TableField\n | RichtextField\n | PluginField\n | StoryWithInlinedRelations\n | undefined;\n\ninterface InlinedStoryContent {\n _uid: string;\n component: string;\n _editable?: string;\n [key: string]: InlinedStoryContentField;\n}\n\nexport type StoryWithInlinedRelations = Omit<StoryCapi, 'content'> & {\n content: InlinedStoryContent;\n};\n\ntype StoryResult<InlineRelations extends boolean> = InlineRelations extends true\n ? StoryWithInlinedRelations\n : StoryCapi;\n\ntype GetResponse<InlineRelations extends boolean> = Omit<GetResponses[200], 'story'> & {\n story: StoryResult<InlineRelations>;\n};\ntype ListResponse<InlineRelations extends boolean> = Omit<ListResponses[200], 'stories'> & {\n stories: Array<StoryResult<InlineRelations>>;\n};\n\n/** Pre-resolved to avoid TypeScript emitting deep indexed-access chains that trip up DTS bundlers. */\ntype StoryIdentifier = GetData['path']['identifier'];\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport interface StoriesResourceDeps extends ResourceDeps {\n inlineRelations: boolean;\n}\n\nexport function createStoriesResource<InlineRelations extends boolean>(\n deps: StoriesResourceDeps,\n) {\n const { client, requestWithCache, asApiResponse, inlineRelations, throttleManager } = deps;\n\n return {\n get: async <ThrowOnError extends boolean = false>(\n identifier: StoryIdentifier,\n options: { query?: GetData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<GetResponse<InlineRelations>, ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const resolvedQuery = typeof identifier === 'string' && UUID_RE.test(identifier) && !query.find_by\n ? { ...query, find_by: 'uuid' as const }\n : query;\n const requestPath = `/v2/cdn/stories/${identifier}`;\n type Res = ApiResponse<GetResponse<InlineRelations>, ThrowOnError>;\n return requestWithCache<GetResponse<InlineRelations>, ThrowOnError>('GET', requestPath, resolvedQuery, async (requestQuery: Record<string, unknown>): Promise<Res> => {\n const response = await throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<GetResponse<InlineRelations>, ThrowOnError>(get({\n client,\n path: { identifier },\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n\n if (!inlineRelations || response.data === undefined) {\n return response;\n }\n\n const resolved = await resolveRelationMap(response.data, requestQuery, { client, throttleManager });\n if (!resolved) {\n return response;\n }\n\n return {\n ...response,\n data: {\n ...response.data,\n story: inlineStoryContent(response.data.story, resolved.relationPaths, resolved.relationMap),\n },\n };\n }, inlineRelations ? { cacheKeyPrefix: 'inline' } : undefined);\n },\n\n list: async <ThrowOnError extends boolean = false>(\n options: { query?: ListData['query']; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<ListResponse<InlineRelations>, ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const requestPath = '/v2/cdn/stories';\n type ResAll = ApiResponse<ListResponse<InlineRelations>, ThrowOnError>;\n return requestWithCache<ListResponse<InlineRelations>, ThrowOnError>('GET', requestPath, query, async (requestQuery: Record<string, unknown>): Promise<ResAll> => {\n const response = await throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse<ListResponse<InlineRelations>, ThrowOnError>(list({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n })));\n\n if (!inlineRelations || response.data === undefined) {\n return response;\n }\n\n const resolved = await resolveRelationMap(response.data, requestQuery, { client, throttleManager });\n if (!resolved) {\n return response;\n }\n\n return {\n ...response,\n data: {\n ...response.data,\n stories: inlineStoriesContent(response.data.stories, resolved.relationPaths, resolved.relationMap),\n },\n };\n }, inlineRelations ? { cacheKeyPrefix: 'inline' } : undefined);\n },\n };\n}\n"],"mappings":";;;;AAoDA,MAAM,UAAU;AAMhB,SAAgB,sBACd,MACA;CACA,MAAM,EAAE,QAAQ,kBAAkB,eAAe,iBAAiB,oBAAoB;AAEtF,QAAO;EACL,KAAK,OACH,YACA,UAAwH,EAAE,KACrD;GACrE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,gBAAgB,OAAO,eAAe,YAAY,QAAQ,KAAK,WAAW,IAAI,CAAC,MAAM,UACvF;IAAE,GAAG;IAAO,SAAS;IAAiB,GACtC;GACJ,MAAM,cAAc,mBAAmB;AAEvC,UAAO,iBAA6D,OAAO,aAAa,eAAe,OAAO,iBAAwD;IACpK,MAAM,WAAW,MAAM,gBAAgB,QAAQ,aAAa,oBAC1D,cAA0DA,oBAAI;KAC5D;KACA,MAAM,EAAE,YAAY;KACpB,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;AAEN,QAAI,CAAC,mBAAmB,SAAS,SAAS,OACxC,QAAO;IAGT,MAAM,WAAW,MAAMC,4CAAmB,SAAS,MAAM,cAAc;KAAE;KAAQ;KAAiB,CAAC;AACnG,QAAI,CAAC,SACH,QAAO;AAGT,WAAO;KACL,GAAG;KACH,MAAM;MACJ,GAAG,SAAS;MACZ,OAAOC,4CAAmB,SAAS,KAAK,OAAO,SAAS,eAAe,SAAS,YAAY;MAC7F;KACF;MACA,kBAAkB,EAAE,gBAAgB,UAAU,GAAG,OAAU;;EAGhE,MAAM,OACJ,UAAyH,EAAE,KACrD;GACtE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,cAAc;AAEpB,UAAO,iBAA8D,OAAO,aAAa,OAAO,OAAO,iBAA2D;IAChK,MAAM,WAAW,MAAM,gBAAgB,QAAQ,aAAa,oBAC1D,cAA2DC,qBAAK;KAC9D;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;AAEN,QAAI,CAAC,mBAAmB,SAAS,SAAS,OACxC,QAAO;IAGT,MAAM,WAAW,MAAMF,4CAAmB,SAAS,MAAM,cAAc;KAAE;KAAQ;KAAiB,CAAC;AACnG,QAAI,CAAC,SACH,QAAO;AAGT,WAAO;KACL,GAAG;KACH,MAAM;MACJ,GAAG,SAAS;MACZ,SAASG,8CAAqB,SAAS,KAAK,SAAS,SAAS,eAAe,SAAS,YAAY;MACnG;KACF;MACA,kBAAkB,EAAE,gBAAgB,UAAU,GAAG,OAAU;;EAEjE"}
1
+ {"version":3,"file":"stories.cjs","names":["get","resolveRelationMap","inlineStoryContent","list","inlineStoriesContent"],"sources":["../../src/resources/stories.ts"],"sourcesContent":["import { get, list } from '../generated/stories/sdk.gen';\nimport type { GetData, GetResponses, ListData, ListResponses } from '../generated/stories/types.gen';\nimport type {\n AssetFieldValue,\n BlokContent,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n StoryCapi,\n TableFieldValue,\n} from '../generated/stories';\nimport { inlineStoriesContent, inlineStoryContent, resolveRelationMap } from '../utils/inline-relations';\nimport type { ApiResponse, FetchOptions, ResourceDeps } from '../client';\nimport type { Story as CapiStory, Block as Component, RootBlocks as RootComponents } from '@storyblok/schema';\n\ntype InlinedStoryContentField =\n | string\n | number\n | boolean\n | Array<string | AssetFieldValue | BlokContent | StoryWithInlinedRelations>\n | AssetFieldValue\n | MultilinkFieldValue\n | TableFieldValue\n | RichtextFieldValue\n | PluginFieldValue\n | StoryWithInlinedRelations\n | undefined;\n\ninterface InlinedStoryContent {\n _uid: string;\n component: string;\n _editable?: string;\n [key: string]: InlinedStoryContentField;\n}\n\nexport type StoryWithInlinedRelations = Omit<StoryCapi, 'content'> & {\n content: InlinedStoryContent;\n};\n\n/** Splits `\"comp.field,comp2.field2\"` into a union of `{ component, field }`. */\ntype ParseRelations<T extends string> =\n T extends `${infer Comp}.${infer Field},${infer Rest}`\n ? { component: Comp; field: Field } | ParseRelations<Rest>\n : T extends `${infer Comp}.${infer Field}`\n ? { component: Comp; field: Field }\n : never;\n\n/** Extracts resolved field names for a given component name. */\ntype ResolvedFieldsFor<R extends string, ComponentName extends string> =\n Extract<ParseRelations<R>, { component: ComponentName }>['field'];\n\n/** A resolved relation: a full story typed to the component union. */\ntype ResolvedRelation<TComponents extends Component> =\n { [K in TComponents as K['name']]: CapiStory<K, TComponents> }[TComponents['name']];\n\n/**\n * Given a story type and a set of resolved field names, replaces\n * those fields with `ResolvedRelation<TComponents>` (a full story object).\n */\ntype WithResolvedRelations<\n TStory,\n TComponents extends Component,\n Fields extends string,\n> = TStory extends { content: infer C } ? Omit<TStory, 'content'> & {\n content: {\n [K in keyof C]: K extends Fields ? ResolvedRelation<TComponents> : C[K]\n };\n}\n : TStory;\n\n/**\n * Resolves to a narrowed component-derived story type when `TComponents` is a specific\n * Component union, or falls back to the generated StoryCapi / StoryWithInlinedRelations\n * when `TComponents` is the default Component base type (no type argument provided).\n *\n * When `ResolveRelations` is a string literal (e.g. `\"article.author\"`),\n * matched fields are widened from their schema type to `ResolvedRelation<TComponents>`\n * — a full story object typed to the component union.\n *\n * Uses a mapped-type approach instead of a distributive conditional with a\n * separate full-components parameter. This ensures the full `TComponents` union is\n * preserved even when DTS bundlers (like tsdown) inline the type alias —\n * a distributive conditional + default-parameter pattern would collapse\n * both parameters to the distributed single member after inlining.\n *\n * The mapped type `{ [K in TComponents as K[\"name\"]]: CapiStory<K, TComponents> }`\n * iterates each union member as `K` while keeping `TComponents` as the full union\n * for nested blok field resolution. The final indexed access\n * `[TComponents[\"name\"]]` produces the discriminated union of all story types.\n */\ntype StoryResult<\n TComponents extends Component,\n InlineRelations extends boolean,\n ResolveRelationsRaw extends string | undefined = undefined,\n> =\n Component extends TComponents\n ? InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi // fallback\n : ResolveRelationsRaw extends string\n ? {\n [K in RootComponents<TComponents> as K['name']]: WithResolvedRelations<\n CapiStory<K, TComponents>,\n TComponents,\n ResolvedFieldsFor<ResolveRelationsRaw, K['name']>\n >\n }[RootComponents<TComponents>['name']]\n : CapiStory<TComponents>;\n\ntype GetResponse<\n TComponents extends Component,\n InlineRelations extends boolean,\n ResolveRelationsRaw extends string | undefined = undefined,\n> = Omit<GetResponses[200], 'story'> & {\n story: StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>;\n};\ntype ListResponse<\n TComponents extends Component,\n InlineRelations extends boolean,\n ResolveRelationsRaw extends string | undefined = undefined,\n> = Omit<ListResponses[200], 'stories'> & {\n stories: Array<StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>>;\n};\n\n/** Pre-resolved to avoid TypeScript emitting deep indexed-access chains that trip up DTS bundlers. */\ntype StoryIdentifier = GetData['path']['identifier'];\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport interface StoriesResourceDeps<DefaultThrowOnError extends boolean = false> extends ResourceDeps<DefaultThrowOnError> {\n inlineRelations: boolean;\n}\n\nexport function createStoriesResource<\n TComponents extends Component = Component,\n InlineRelations extends boolean = false,\n DefaultThrowOnError extends boolean = false,\n>(\n deps: StoriesResourceDeps<DefaultThrowOnError>,\n) {\n const { client, requestWithCache, asApiResponse, inlineRelations, throttleManager } = deps;\n\n return {\n get: async <\n ThrowOnError extends boolean = DefaultThrowOnError,\n const ResolveRelationsStr extends string | undefined = undefined,\n >(\n identifier: StoryIdentifier,\n options: { query?: Omit<NonNullable<GetData['query']>, 'resolve_relations'> & { resolve_relations?: ResolveRelationsStr }; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<GetResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const typedQuery = (query ?? {}) as NonNullable<GetData['query']>;\n const resolvedQuery = typeof identifier === 'string' && UUID_RE.test(identifier) && !typedQuery.find_by\n ? { ...typedQuery, find_by: 'uuid' }\n : typedQuery;\n const requestPath = `/v2/cdn/stories/${identifier}`;\n return requestWithCache('GET', requestPath, resolvedQuery, async (requestQuery: Record<string, unknown>) => {\n const response = await throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse(get({\n client,\n path: { identifier },\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n }))) satisfies ApiResponse<GetResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>;\n\n if (!inlineRelations || response.data === undefined) {\n return response;\n }\n\n const resolved = await resolveRelationMap(response.data, requestQuery, { client, throttleManager });\n if (!resolved) {\n return response;\n }\n\n return {\n ...response,\n data: {\n ...response.data,\n // `inlineStoryContent` operates on raw `StoryCapi` shapes and mutates relation fields\n // from UUID strings to full story objects. We cast to satisfy its parameter type.\n story: inlineStoryContent(response.data.story as StoryCapi, resolved.relationPaths, resolved.relationMap),\n },\n };\n }, inlineRelations ? { cacheKeyPrefix: 'inline' } : undefined);\n },\n\n list: async <\n ThrowOnError extends boolean = DefaultThrowOnError,\n const ResolveRelationsStr extends string | undefined = undefined,\n >(\n options: { query?: Omit<NonNullable<ListData['query']>, 'resolve_relations'> & { resolve_relations?: ResolveRelationsStr }; signal?: AbortSignal; throwOnError?: ThrowOnError; fetchOptions?: FetchOptions } = {},\n ): Promise<ApiResponse<ListResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>> => {\n const { query = {}, signal, throwOnError, fetchOptions } = options;\n const typedQuery = (query ?? {}) as NonNullable<ListData['query']>;\n const requestPath = '/v2/cdn/stories';\n return requestWithCache('GET', requestPath, typedQuery, async (requestQuery: Record<string, unknown>) => {\n const response = await throttleManager.execute(requestPath, requestQuery, () =>\n asApiResponse(list({\n client,\n query: requestQuery,\n signal,\n ...(throwOnError === undefined ? {} : { throwOnError }),\n ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}),\n }))) satisfies ApiResponse<ListResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>;\n\n if (!inlineRelations || response.data === undefined) {\n return response;\n }\n\n const resolved = await resolveRelationMap(response.data, requestQuery, { client, throttleManager });\n if (!resolved) {\n return response;\n }\n\n return {\n ...response,\n data: {\n ...response.data,\n // `inlineStoriesContent` operates on raw `StoryCapi` shapes and mutates relation fields\n // from UUID strings to full story objects. We cast to satisfy its parameter type.\n stories: inlineStoriesContent(response.data.stories as StoryCapi[], resolved.relationPaths, resolved.relationMap),\n },\n };\n }, inlineRelations ? { cacheKeyPrefix: 'inline' } : undefined);\n },\n };\n}\n"],"mappings":";;;;AA6HA,MAAM,UAAU;AAMhB,SAAgB,sBAKd,MACA;CACA,MAAM,EAAE,QAAQ,kBAAkB,eAAe,iBAAiB,oBAAoB;AAEtF,QAAO;EACL,KAAK,OAIH,YACA,UAA8M,EAAE,KACzG;GACvG,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,aAAc,SAAS,EAAE;GAC/B,MAAM,gBAAgB,OAAO,eAAe,YAAY,QAAQ,KAAK,WAAW,IAAI,CAAC,WAAW,UAC5F;IAAE,GAAG;IAAY,SAAS;IAAQ,GAClC;GACJ,MAAM,cAAc,mBAAmB;AACvC,UAAO,iBAAiB,OAAO,aAAa,eAAe,OAAO,iBAA0C;IAC1G,MAAM,WAAW,MAAM,gBAAgB,QAAQ,aAAa,oBAC1D,cAAcA,oBAAI;KAChB;KACA,MAAM,EAAE,YAAY;KACpB,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;AAEN,QAAI,CAAC,mBAAmB,SAAS,SAAS,OACxC,QAAO;IAGT,MAAM,WAAW,MAAMC,4CAAmB,SAAS,MAAM,cAAc;KAAE;KAAQ;KAAiB,CAAC;AACnG,QAAI,CAAC,SACH,QAAO;AAGT,WAAO;KACL,GAAG;KACH,MAAM;MACJ,GAAG,SAAS;MAGZ,OAAOC,4CAAmB,SAAS,KAAK,OAAoB,SAAS,eAAe,SAAS,YAAY;MAC1G;KACF;MACA,kBAAkB,EAAE,gBAAgB,UAAU,GAAG,OAAU;;EAGhE,MAAM,OAIJ,UAA+M,EAAE,KACzG;GACxG,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,cAAc,iBAAiB;GAC3D,MAAM,aAAc,SAAS,EAAE;GAC/B,MAAM,cAAc;AACpB,UAAO,iBAAiB,OAAO,aAAa,YAAY,OAAO,iBAA0C;IACvG,MAAM,WAAW,MAAM,gBAAgB,QAAQ,aAAa,oBAC1D,cAAcC,qBAAK;KACjB;KACA,OAAO;KACP;KACA,GAAI,iBAAiB,SAAY,EAAE,GAAG,EAAE,cAAc;KACtD,GAAI,eAAe,EAAE,WAAW;MAAE,GAAG,OAAO,WAAW,CAAC;MAAW,GAAG;MAAc,EAAE,GAAG,EAAE;KAC5F,CAAC,CAAC,CAAC;AAEN,QAAI,CAAC,mBAAmB,SAAS,SAAS,OACxC,QAAO;IAGT,MAAM,WAAW,MAAMF,4CAAmB,SAAS,MAAM,cAAc;KAAE;KAAQ;KAAiB,CAAC;AACnG,QAAI,CAAC,SACH,QAAO;AAGT,WAAO;KACL,GAAG;KACH,MAAM;MACJ,GAAG,SAAS;MAGZ,SAASG,8CAAqB,SAAS,KAAK,SAAwB,SAAS,eAAe,SAAS,YAAY;MAClH;KACF;MACA,kBAAkB,EAAE,gBAAgB,UAAU,GAAG,OAAU;;EAEjE"}
@@ -1,7 +1,9 @@
1
- import { AssetField, MultilinkField, PluginField, RichtextField, StoryCapi, StoryContent, TableField } from "../generated/stories/types.gen.cjs";
1
+ import { AssetFieldValue, BlokContent, GetData, GetResponses, ListData, ListResponses, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, StoryCapi, TableFieldValue } from "../generated/stories/types.gen.cjs";
2
+ import { ApiResponse, FetchOptions, ResourceDeps } from "../client.cjs";
3
+ import { Block, RootBlocks, Story } from "@storyblok/schema";
2
4
 
3
5
  //#region src/resources/stories.d.ts
4
- type InlinedStoryContentField = string | number | boolean | Array<string | AssetField | StoryContent | StoryWithInlinedRelations> | AssetField | MultilinkField | TableField | RichtextField | PluginField | StoryWithInlinedRelations | undefined;
6
+ type InlinedStoryContentField = string | number | boolean | Array<string | AssetFieldValue | BlokContent | StoryWithInlinedRelations> | AssetFieldValue | MultilinkFieldValue | TableFieldValue | RichtextFieldValue | PluginFieldValue | StoryWithInlinedRelations | undefined;
5
7
  interface InlinedStoryContent {
6
8
  _uid: string;
7
9
  component: string;
@@ -11,6 +13,79 @@ interface InlinedStoryContent {
11
13
  type StoryWithInlinedRelations = Omit<StoryCapi, 'content'> & {
12
14
  content: InlinedStoryContent;
13
15
  };
16
+ /** Splits `"comp.field,comp2.field2"` into a union of `{ component, field }`. */
17
+ type ParseRelations<T extends string> = T extends `${infer Comp}.${infer Field},${infer Rest}` ? {
18
+ component: Comp;
19
+ field: Field;
20
+ } | ParseRelations<Rest> : T extends `${infer Comp}.${infer Field}` ? {
21
+ component: Comp;
22
+ field: Field;
23
+ } : never;
24
+ /** Extracts resolved field names for a given component name. */
25
+ type ResolvedFieldsFor<R extends string, ComponentName extends string> = Extract<ParseRelations<R>, {
26
+ component: ComponentName;
27
+ }>['field'];
28
+ /** A resolved relation: a full story typed to the component union. */
29
+ type ResolvedRelation<TComponents extends Block> = { [K in TComponents as K['name']]: Story<K, TComponents> }[TComponents['name']];
30
+ /**
31
+ * Given a story type and a set of resolved field names, replaces
32
+ * those fields with `ResolvedRelation<TComponents>` (a full story object).
33
+ */
34
+ type WithResolvedRelations<TStory, TComponents extends Block, Fields extends string> = TStory extends {
35
+ content: infer C;
36
+ } ? Omit<TStory, 'content'> & {
37
+ content: { [K in keyof C]: K extends Fields ? ResolvedRelation<TComponents> : C[K] };
38
+ } : TStory;
39
+ /**
40
+ * Resolves to a narrowed component-derived story type when `TComponents` is a specific
41
+ * Component union, or falls back to the generated StoryCapi / StoryWithInlinedRelations
42
+ * when `TComponents` is the default Component base type (no type argument provided).
43
+ *
44
+ * When `ResolveRelations` is a string literal (e.g. `"article.author"`),
45
+ * matched fields are widened from their schema type to `ResolvedRelation<TComponents>`
46
+ * — a full story object typed to the component union.
47
+ *
48
+ * Uses a mapped-type approach instead of a distributive conditional with a
49
+ * separate full-components parameter. This ensures the full `TComponents` union is
50
+ * preserved even when DTS bundlers (like tsdown) inline the type alias —
51
+ * a distributive conditional + default-parameter pattern would collapse
52
+ * both parameters to the distributed single member after inlining.
53
+ *
54
+ * The mapped type `{ [K in TComponents as K["name"]]: CapiStory<K, TComponents> }`
55
+ * iterates each union member as `K` while keeping `TComponents` as the full union
56
+ * for nested blok field resolution. The final indexed access
57
+ * `[TComponents["name"]]` produces the discriminated union of all story types.
58
+ */
59
+ type StoryResult<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Block extends TComponents ? InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi : ResolveRelationsRaw extends string ? { [K in RootBlocks<TComponents> as K['name']]: WithResolvedRelations<Story<K, TComponents>, TComponents, ResolvedFieldsFor<ResolveRelationsRaw, K['name']>> }[RootBlocks<TComponents>['name']] : Story<TComponents>;
60
+ type GetResponse<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Omit<GetResponses[200], 'story'> & {
61
+ story: StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>;
62
+ };
63
+ type ListResponse<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Omit<ListResponses[200], 'stories'> & {
64
+ stories: Array<StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>>;
65
+ };
66
+ /** Pre-resolved to avoid TypeScript emitting deep indexed-access chains that trip up DTS bundlers. */
67
+ type StoryIdentifier = GetData['path']['identifier'];
68
+ interface StoriesResourceDeps<DefaultThrowOnError extends boolean = false> extends ResourceDeps<DefaultThrowOnError> {
69
+ inlineRelations: boolean;
70
+ }
71
+ declare function createStoriesResource<TComponents extends Block = Block, InlineRelations extends boolean = false, DefaultThrowOnError extends boolean = false>(deps: StoriesResourceDeps<DefaultThrowOnError>): {
72
+ get: <ThrowOnError extends boolean = DefaultThrowOnError, const ResolveRelationsStr extends string | undefined = undefined>(identifier: StoryIdentifier, options?: {
73
+ query?: Omit<NonNullable<GetData["query"]>, "resolve_relations"> & {
74
+ resolve_relations?: ResolveRelationsStr;
75
+ };
76
+ signal?: AbortSignal;
77
+ throwOnError?: ThrowOnError;
78
+ fetchOptions?: FetchOptions;
79
+ }) => Promise<ApiResponse<GetResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>>;
80
+ list: <ThrowOnError extends boolean = DefaultThrowOnError, const ResolveRelationsStr extends string | undefined = undefined>(options?: {
81
+ query?: Omit<NonNullable<ListData["query"]>, "resolve_relations"> & {
82
+ resolve_relations?: ResolveRelationsStr;
83
+ };
84
+ signal?: AbortSignal;
85
+ throwOnError?: ThrowOnError;
86
+ fetchOptions?: FetchOptions;
87
+ }) => Promise<ApiResponse<ListResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>>;
88
+ };
14
89
  //#endregion
15
- export { StoryWithInlinedRelations };
90
+ export { StoryWithInlinedRelations, createStoriesResource };
16
91
  //# sourceMappingURL=stories.d.cts.map
@@ -1,6 +1,9 @@
1
- import { AssetField, MultilinkField, PluginField, RichtextField, StoryCapi, StoryContent, TableField } from "../generated/stories/types.gen.mjs";
1
+ import { AssetFieldValue, BlokContent, GetData, GetResponses, ListData, ListResponses, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, StoryCapi, TableFieldValue } from "../generated/stories/types.gen.mjs";
2
+ import { ApiResponse, FetchOptions, ResourceDeps } from "../client.mjs";
3
+ import { Block, RootBlocks, Story } from "@storyblok/schema";
4
+
2
5
  //#region src/resources/stories.d.ts
3
- type InlinedStoryContentField = string | number | boolean | Array<string | AssetField | StoryContent | StoryWithInlinedRelations> | AssetField | MultilinkField | TableField | RichtextField | PluginField | StoryWithInlinedRelations | undefined;
6
+ type InlinedStoryContentField = string | number | boolean | Array<string | AssetFieldValue | BlokContent | StoryWithInlinedRelations> | AssetFieldValue | MultilinkFieldValue | TableFieldValue | RichtextFieldValue | PluginFieldValue | StoryWithInlinedRelations | undefined;
4
7
  interface InlinedStoryContent {
5
8
  _uid: string;
6
9
  component: string;
@@ -10,6 +13,79 @@ interface InlinedStoryContent {
10
13
  type StoryWithInlinedRelations = Omit<StoryCapi, 'content'> & {
11
14
  content: InlinedStoryContent;
12
15
  };
16
+ /** Splits `"comp.field,comp2.field2"` into a union of `{ component, field }`. */
17
+ type ParseRelations<T extends string> = T extends `${infer Comp}.${infer Field},${infer Rest}` ? {
18
+ component: Comp;
19
+ field: Field;
20
+ } | ParseRelations<Rest> : T extends `${infer Comp}.${infer Field}` ? {
21
+ component: Comp;
22
+ field: Field;
23
+ } : never;
24
+ /** Extracts resolved field names for a given component name. */
25
+ type ResolvedFieldsFor<R extends string, ComponentName extends string> = Extract<ParseRelations<R>, {
26
+ component: ComponentName;
27
+ }>['field'];
28
+ /** A resolved relation: a full story typed to the component union. */
29
+ type ResolvedRelation<TComponents extends Block> = { [K in TComponents as K['name']]: Story<K, TComponents> }[TComponents['name']];
30
+ /**
31
+ * Given a story type and a set of resolved field names, replaces
32
+ * those fields with `ResolvedRelation<TComponents>` (a full story object).
33
+ */
34
+ type WithResolvedRelations<TStory, TComponents extends Block, Fields extends string> = TStory extends {
35
+ content: infer C;
36
+ } ? Omit<TStory, 'content'> & {
37
+ content: { [K in keyof C]: K extends Fields ? ResolvedRelation<TComponents> : C[K] };
38
+ } : TStory;
39
+ /**
40
+ * Resolves to a narrowed component-derived story type when `TComponents` is a specific
41
+ * Component union, or falls back to the generated StoryCapi / StoryWithInlinedRelations
42
+ * when `TComponents` is the default Component base type (no type argument provided).
43
+ *
44
+ * When `ResolveRelations` is a string literal (e.g. `"article.author"`),
45
+ * matched fields are widened from their schema type to `ResolvedRelation<TComponents>`
46
+ * — a full story object typed to the component union.
47
+ *
48
+ * Uses a mapped-type approach instead of a distributive conditional with a
49
+ * separate full-components parameter. This ensures the full `TComponents` union is
50
+ * preserved even when DTS bundlers (like tsdown) inline the type alias —
51
+ * a distributive conditional + default-parameter pattern would collapse
52
+ * both parameters to the distributed single member after inlining.
53
+ *
54
+ * The mapped type `{ [K in TComponents as K["name"]]: CapiStory<K, TComponents> }`
55
+ * iterates each union member as `K` while keeping `TComponents` as the full union
56
+ * for nested blok field resolution. The final indexed access
57
+ * `[TComponents["name"]]` produces the discriminated union of all story types.
58
+ */
59
+ type StoryResult<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Block extends TComponents ? InlineRelations extends true ? StoryWithInlinedRelations : StoryCapi : ResolveRelationsRaw extends string ? { [K in RootBlocks<TComponents> as K['name']]: WithResolvedRelations<Story<K, TComponents>, TComponents, ResolvedFieldsFor<ResolveRelationsRaw, K['name']>> }[RootBlocks<TComponents>['name']] : Story<TComponents>;
60
+ type GetResponse<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Omit<GetResponses[200], 'story'> & {
61
+ story: StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>;
62
+ };
63
+ type ListResponse<TComponents extends Block, InlineRelations extends boolean, ResolveRelationsRaw extends string | undefined = undefined> = Omit<ListResponses[200], 'stories'> & {
64
+ stories: Array<StoryResult<TComponents, InlineRelations, ResolveRelationsRaw>>;
65
+ };
66
+ /** Pre-resolved to avoid TypeScript emitting deep indexed-access chains that trip up DTS bundlers. */
67
+ type StoryIdentifier = GetData['path']['identifier'];
68
+ interface StoriesResourceDeps<DefaultThrowOnError extends boolean = false> extends ResourceDeps<DefaultThrowOnError> {
69
+ inlineRelations: boolean;
70
+ }
71
+ declare function createStoriesResource<TComponents extends Block = Block, InlineRelations extends boolean = false, DefaultThrowOnError extends boolean = false>(deps: StoriesResourceDeps<DefaultThrowOnError>): {
72
+ get: <ThrowOnError extends boolean = DefaultThrowOnError, const ResolveRelationsStr extends string | undefined = undefined>(identifier: StoryIdentifier, options?: {
73
+ query?: Omit<NonNullable<GetData["query"]>, "resolve_relations"> & {
74
+ resolve_relations?: ResolveRelationsStr;
75
+ };
76
+ signal?: AbortSignal;
77
+ throwOnError?: ThrowOnError;
78
+ fetchOptions?: FetchOptions;
79
+ }) => Promise<ApiResponse<GetResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>>;
80
+ list: <ThrowOnError extends boolean = DefaultThrowOnError, const ResolveRelationsStr extends string | undefined = undefined>(options?: {
81
+ query?: Omit<NonNullable<ListData["query"]>, "resolve_relations"> & {
82
+ resolve_relations?: ResolveRelationsStr;
83
+ };
84
+ signal?: AbortSignal;
85
+ throwOnError?: ThrowOnError;
86
+ fetchOptions?: FetchOptions;
87
+ }) => Promise<ApiResponse<ListResponse<TComponents, InlineRelations, ResolveRelationsStr>, ThrowOnError>>;
88
+ };
13
89
  //#endregion
14
- export { StoryWithInlinedRelations };
90
+ export { StoryWithInlinedRelations, createStoriesResource };
15
91
  //# sourceMappingURL=stories.d.mts.map
@@ -8,10 +8,11 @@ function createStoriesResource(deps) {
8
8
  return {
9
9
  get: async (identifier, options = {}) => {
10
10
  const { query = {}, signal, throwOnError, fetchOptions } = options;
11
- const resolvedQuery = typeof identifier === "string" && UUID_RE.test(identifier) && !query.find_by ? {
12
- ...query,
11
+ const typedQuery = query ?? {};
12
+ const resolvedQuery = typeof identifier === "string" && UUID_RE.test(identifier) && !typedQuery.find_by ? {
13
+ ...typedQuery,
13
14
  find_by: "uuid"
14
- } : query;
15
+ } : typedQuery;
15
16
  const requestPath = `/v2/cdn/stories/${identifier}`;
16
17
  return requestWithCache("GET", requestPath, resolvedQuery, async (requestQuery) => {
17
18
  const response = await throttleManager.execute(requestPath, requestQuery, () => asApiResponse(get({
@@ -42,8 +43,9 @@ function createStoriesResource(deps) {
42
43
  },
43
44
  list: async (options = {}) => {
44
45
  const { query = {}, signal, throwOnError, fetchOptions } = options;
46
+ const typedQuery = query ?? {};
45
47
  const requestPath = "/v2/cdn/stories";
46
- return requestWithCache("GET", requestPath, query, async (requestQuery) => {
48
+ return requestWithCache("GET", requestPath, typedQuery, async (requestQuery) => {
47
49
  const response = await throttleManager.execute(requestPath, requestQuery, () => asApiResponse(list({
48
50
  client,
49
51
  query: requestQuery,