@storyblok/management-api-client 1.0.0-alpha.2 → 1.0.0-alpha.3
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.
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +11 -5
- package/dist/client.d.mts +11 -5
- package/dist/client.mjs.map +1 -1
- package/dist/generated/mapi/_internal.gen.d.cts +1 -171
- package/dist/generated/mapi/_internal.gen.d.mts +1 -171
- package/dist/generated/mapi/types-aliased.gen.d.cts +171 -1
- package/dist/generated/mapi/types-aliased.gen.d.mts +171 -1
- package/dist/generated/types/block.d.cts +27 -8
- package/dist/generated/types/block.d.mts +27 -8
- package/dist/generated/types/field.d.cts +24 -12
- package/dist/generated/types/field.d.mts +24 -12
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/resources/components.cjs.map +1 -1
- package/dist/resources/components.d.cts +17 -17
- package/dist/resources/components.d.mts +17 -17
- package/dist/resources/components.mjs.map +1 -1
- package/package.json +1 -1
- package/playground/integration-tests/test/specs/mapi-round-trip.spec.e2e.ts +30 -40
- package/playground/integration-tests/test/types/components.test-d.ts +7 -46
- package/playground/integration-tests/test/types/resources.test-d.ts +0 -152
- package/playground/integration-tests/test/types/stories.test-d.ts +9 -42
- package/test/GUIDE.md +2 -2
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.cjs","names":["createThrottleManager","createClient","createConfig","ClientError","createAssetFoldersResource","createAssetsResource","createComponentFoldersResource","createDatasourceEntriesResource","createDatasourcesResource","createExperimentsResource","createInternalTagsResource","createPresetsResource","createSpacesResource","createUsersResource","createComponentsResource","createStoriesResource"],"sources":["../src/client.ts"],"sourcesContent":["import type { Client, ResolvedRequestOptions, RetryOptions } from './generated/mapi/client';\nimport type { Middleware } from './generated/mapi/client/utils.gen';\nimport { createClient, createConfig } from './generated/mapi/client';\nimport { getManagementBaseUrl } from '@storyblok/region-helper';\nimport type { Region } from '@storyblok/region-helper';\nimport type { Block as Component } from './generated/types/block';\nimport { ClientError } from './error';\nimport type { RateLimitConfig } from './utils/rate-limit';\nimport { createThrottleManager } from './utils/rate-limit';\nimport { querySerializer } from './utils/query-serializer';\nimport { createAssetFoldersResource } from './resources/asset-folders';\nimport { createAssetsResource } from './resources/assets';\nimport { createComponentFoldersResource } from './resources/component-folders';\nimport { createComponentsResource } from './resources/components';\nimport { createDatasourceEntriesResource } from './resources/datasource-entries';\nimport { createDatasourcesResource } from './resources/datasources';\nimport { createExperimentsResource } from './resources/experiments';\nimport { createInternalTagsResource } from './resources/internal-tags';\nimport { createPresetsResource } from './resources/presets';\nimport { createSpacesResource } from './resources/spaces';\nimport { createStoriesResource } from './resources/stories';\nimport { createUsersResource } from './resources/users';\n\n// ---------------------------------------------------------------------------\n// Client types (co-located with runtime)\n// ---------------------------------------------------------------------------\n\nexport type ApiResponse<T, ThrowOnError extends boolean = false> =\n ThrowOnError extends true\n ? { data: T; error?: never; response: Response; request: Request }\n : | { data: T; error: undefined; response: Response; request: Request }\n | { data: undefined; error: ClientError; response: Response; request: Request };\n\nexport interface RequestConfigOverrides {\n throwOnError?: boolean;\n}\n\n/**\n * Arbitrary options forwarded to the underlying `fetch()` call.\n *\n * Standard `RequestInit` properties (`cache`, `credentials`, `mode`, …) and\n * non-standard, vendor-specific properties (Next.js `next`, Cloudflare `cf`, …)\n * are both supported.\n *\n * @example\n * ```ts\n * client.stories.get(123, {\n * fetchOptions: {\n * cache: 'no-store',\n * next: { revalidate: 60 },\n * },\n * })\n * ```\n */\nexport type FetchOptions = Record<string, unknown>;\n\nexport interface HttpRequestOptions {\n query?: Record<string, unknown>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n throwOnError?: RequestConfigOverrides['throwOnError'];\n fetchOptions?: FetchOptions;\n}\n\n/**\n * Dependencies injected into every resource factory.\n */\nexport interface MapiResourceDeps<DefaultThrowOnError extends boolean = false> {\n client: Client;\n spaceId?: number;\n wrapRequest: <TData, ThrowOnError extends boolean = DefaultThrowOnError>(fn: () => Promise<unknown>, throwOnError?: ThrowOnError) => Promise<ApiResponse<TData, ThrowOnError>>;\n}\n\ntype TokenConfig =\n | {\n /** Personal access token for authentication. */\n personalAccessToken: string;\n oauthToken?: never;\n }\n | {\n personalAccessToken?: never;\n /** OAuth bearer token for authentication. */\n oauthToken: string;\n }\n | {\n personalAccessToken?: undefined;\n oauthToken?: undefined;\n };\n\nexport type ManagementApiClientConfig<\n ThrowOnError extends boolean = false,\n> = TokenConfig & {\n /**\n * The Storyblok space ID. Used as the default for space-scoped endpoints.\n * You can also override it per request via `path.space_id`.\n */\n spaceId?: number;\n /**\n * Storyblok region. Determines the base URL.\n * @default 'eu'\n */\n region?: Region;\n /**\n * Override the base URL entirely (e.g. for testing).\n */\n baseUrl?: string;\n /**\n * Additional request headers.\n */\n headers?: Record<string, string>;\n /**\n * Throw on HTTP errors instead of returning them.\n * @default false\n */\n throwOnError?: ThrowOnError;\n /**\n * Retry configuration for failed requests.\n */\n retry?: RetryOptions;\n /**\n * Request timeout in milliseconds.\n * @default 30_000\n */\n timeout?: number;\n /**\n * Preventive rate limiting to avoid hitting the Storyblok Management API rate limits.\n *\n * - `undefined` (default): single bucket at maxConcurrency: 6.\n * - `number`: fixed max concurrent requests per second.\n * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.\n * - `false`: disable rate limiting entirely.\n */\n rateLimit?: RateLimitConfig | number | false;\n};\n\n// ---------------------------------------------------------------------------\n// Client factory\n// ---------------------------------------------------------------------------\n\nfunction getAuthorizationHeader(config: ManagementApiClientConfig<boolean>): string | undefined {\n if (config.personalAccessToken) {\n return config.personalAccessToken;\n }\n if (config.oauthToken) {\n return config.oauthToken.startsWith('Bearer ')\n ? config.oauthToken\n : `Bearer ${config.oauthToken}`;\n }\n return undefined;\n}\n\nconst createManagementApiClientBase = <DefaultThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): {\n deps: MapiResourceDeps<DefaultThrowOnError>;\n resources: Omit<ReturnType<typeof buildResources<DefaultThrowOnError>>, never>;\n} => {\n const {\n spaceId,\n region = 'eu',\n baseUrl,\n headers = {},\n throwOnError = false,\n retry = {\n limit: 12,\n backoffLimit: 20_000,\n methods: ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'],\n statusCodes: [429],\n },\n timeout = 30_000,\n rateLimit,\n } = config;\n\n const throttleManager = createThrottleManager(rateLimit ?? {});\n const authHeader = getAuthorizationHeader(config);\n\n const client: Client = createClient(\n createConfig({\n baseUrl: baseUrl || getManagementBaseUrl(region),\n headers: {\n ...(authHeader ? { Authorization: authHeader } : {}),\n ...headers,\n },\n // Default serializer throws on nested objects; MAPI needs `filter_query`\n // serialized as a nested hash (`filter_query[field][op]=value`).\n querySerializer,\n throwOnError,\n kyOptions: {\n throwHttpErrors: true,\n timeout,\n retry,\n },\n }),\n );\n\n client.interceptors.error.use(\n (error: unknown, response: Response) =>\n new ClientError(response?.statusText || 'API request failed', {\n status: response?.status ?? 0,\n statusText: response?.statusText ?? '',\n data: error,\n }),\n );\n\n function wrapRequest<TData, CurrentThrowOnError extends boolean = DefaultThrowOnError>(\n fn: () => Promise<unknown>,\n _throwOnError?: CurrentThrowOnError,\n ): Promise<ApiResponse<TData, CurrentThrowOnError>> {\n return throttleManager.execute(\n () => fn() as Promise<ApiResponse<TData, CurrentThrowOnError>>,\n );\n }\n\n const deps: MapiResourceDeps<DefaultThrowOnError> = { client, spaceId, wrapRequest };\n return { deps, resources: buildResources(deps, client) };\n};\n\nfunction buildResources<DefaultThrowOnError extends boolean = false>(\n deps: MapiResourceDeps<DefaultThrowOnError>,\n client: Client,\n) {\n /**\n * Escape hatch: send a GET request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpGet = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.get({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a POST request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPost = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.post({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPut = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.put({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PATCH request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPatch = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.patch({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a DELETE request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpDelete = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.delete({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n return {\n assetFolders: createAssetFoldersResource(deps),\n assets: createAssetsResource(deps),\n componentFolders: createComponentFoldersResource(deps),\n datasourceEntries: createDatasourceEntriesResource(deps),\n datasources: createDatasourcesResource(deps),\n experiments: createExperimentsResource(deps),\n delete: httpDelete,\n get: httpGet,\n patch: httpPatch,\n interceptors: client.interceptors as Middleware<Request, Response, unknown, ResolvedRequestOptions>,\n internalTags: createInternalTagsResource(deps),\n post: httpPost,\n presets: createPresetsResource(deps),\n put: httpPut,\n spaces: createSpacesResource(deps),\n users: createUsersResource<DefaultThrowOnError>({ client, wrapRequest: deps.wrapRequest }),\n };\n}\n\ntype StoryblokTypesConfig = { components: Component } | { blocks: Component };\n\ntype ResolveComponents<T extends StoryblokTypesConfig> =\n T extends { components: infer C extends Component } ? C\n : T extends { blocks: infer B extends Component } ? B\n : never;\n\n/**\n * The return type of `createManagementApiClient`, parameterised by `TComponents` so that\n * `.stories` methods can narrow story content types without touching the runtime object.\n */\nexport type ManagementApiClient<\n TComponents extends Component = Component,\n DefaultThrowOnError extends boolean = false,\n> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {\n components: ReturnType<typeof createComponentsResource<TComponents, DefaultThrowOnError>>;\n stories: ReturnType<typeof createStoriesResource<TComponents, DefaultThrowOnError>>;\n /**\n * Returns the same client instance cast to a version that narrows story content\n * to the provided component types. No runtime cost — type parameter is erased.\n *\n * Accepts either `{ components: ... }` or `{ blocks: ... }` — the latter matches the\n * `Schema` type produced by `@storyblok/schema`'s `InferSchema`.\n *\n * @example\n * ```ts\n * import type { Schema } from './schema';\n *\n * const client = createManagementApiClient({ personalAccessToken: '...' })\n * .withTypes<Schema>();\n * ```\n */\n withTypes: <T extends StoryblokTypesConfig>() => ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n};\n\nexport const createManagementApiClient = <\n DefaultThrowOnError extends boolean = false,\n>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): ManagementApiClient<Component, DefaultThrowOnError> => {\n const { deps, resources } = createManagementApiClientBase(config);\n const self: ManagementApiClient<Component, DefaultThrowOnError> = {\n ...resources,\n components: createComponentsResource<Component, DefaultThrowOnError>(deps),\n stories: createStoriesResource<Component, DefaultThrowOnError>(deps),\n withTypes<T extends StoryblokTypesConfig>() {\n return self as unknown as ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n },\n };\n return self;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4IA,SAAS,uBAAuB,QAAgE;AAC9F,KAAI,OAAO,oBACT,QAAO,OAAO;AAEhB,KAAI,OAAO,WACT,QAAO,OAAO,WAAW,WAAW,UAAU,GAC1C,OAAO,aACP,UAAU,OAAO;;AAKzB,MAAM,iCACJ,WAIG;CACH,MAAM,EACJ,SACA,SAAS,MACT,SACA,UAAU,EAAE,EACZ,eAAe,OACf,QAAQ;EACN,OAAO;EACP,cAAc;EACd,SAAS;GAAC;GAAO;GAAQ;GAAO;GAAU;GAAS;GAAQ;GAAW;GAAQ;EAC9E,aAAa,CAAC,IAAI;EACnB,EACD,UAAU,KACV,cACE;CAEJ,MAAM,kBAAkBA,yCAAsB,aAAa,EAAE,CAAC;CAC9D,MAAM,aAAa,uBAAuB,OAAO;CAEjD,MAAM,SAAiBC,gCACrBC,+BAAa;EACX,SAAS,8DAAgC,OAAO;EAChD,SAAS;GACP,GAAI,aAAa,EAAE,eAAe,YAAY,GAAG,EAAE;GACnD,GAAG;GACJ;EAGD;EACA;EACA,WAAW;GACT,iBAAiB;GACjB;GACA;GACD;EACF,CAAC,CACH;AAED,QAAO,aAAa,MAAM,KACvB,OAAgB,aACf,IAAIC,0BAAY,UAAU,cAAc,sBAAsB;EAC5D,QAAQ,UAAU,UAAU;EAC5B,YAAY,UAAU,cAAc;EACpC,MAAM;EACP,CAAC,CACL;CAED,SAAS,YACP,IACA,eACkD;AAClD,SAAO,gBAAgB,cACf,IAAI,CACX;;CAGH,MAAM,OAA8C;EAAE;EAAQ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,kBACV,OAAO,OAAO;GAAE,KAAK;GAAM,GAAG;GAAM,GAAI,eAAe,EAAE,WAAW;IAAE,GAAG,OAAO,WAAW,CAAC;IAAW,GAAG;IAAc,EAAE,GAAG,EAAE;GAAG,CAAC,CACpI;;AAGH,QAAO;EACL,cAAcC,iDAA2B,KAAK;EAC9C,QAAQC,oCAAqB,KAAK;EAClC,kBAAkBC,yDAA+B,KAAK;EACtD,mBAAmBC,2DAAgC,KAAK;EACxD,aAAaC,8CAA0B,KAAK;EAC5C,aAAaC,8CAA0B,KAAK;EAC5C,QAAQ;EACR,KAAK;EACL,OAAO;EACP,cAAc,OAAO;EACrB,cAAcC,iDAA2B,KAAK;EAC9C,MAAM;EACN,SAASC,sCAAsB,KAAK;EACpC,KAAK;EACL,QAAQC,oCAAqB,KAAK;EAClC,OAAOC,kCAAyC;GAAE;GAAQ,aAAa,KAAK;GAAa,CAAC;EAC3F;;AAsCH,MAAa,6BAGX,WACwD;CACxD,MAAM,EAAE,MAAM,cAAc,8BAA8B,OAAO;CACjE,MAAM,OAA4D;EAChE,GAAG;EACH,YAAYC,4CAAyD,KAAK;EAC1E,SAASC,sCAAsD,KAAK;EACpE,YAA4C;AAC1C,UAAO;;EAEV;AACD,QAAO"}
|
|
1
|
+
{"version":3,"file":"client.cjs","names":["createThrottleManager","createClient","createConfig","ClientError","createAssetFoldersResource","createAssetsResource","createComponentFoldersResource","createDatasourceEntriesResource","createDatasourcesResource","createExperimentsResource","createInternalTagsResource","createPresetsResource","createSpacesResource","createUsersResource","createComponentsResource","createStoriesResource"],"sources":["../src/client.ts"],"sourcesContent":["import type { Client, ResolvedRequestOptions, RetryOptions } from './generated/mapi/client';\nimport type { Middleware } from './generated/mapi/client/utils.gen';\nimport { createClient, createConfig } from './generated/mapi/client';\nimport { getManagementBaseUrl } from '@storyblok/region-helper';\nimport type { Region } from '@storyblok/region-helper';\nimport type { Block } from './generated/types/block';\nimport { ClientError } from './error';\nimport type { RateLimitConfig } from './utils/rate-limit';\nimport { createThrottleManager } from './utils/rate-limit';\nimport { querySerializer } from './utils/query-serializer';\nimport { createAssetFoldersResource } from './resources/asset-folders';\nimport { createAssetsResource } from './resources/assets';\nimport { createComponentFoldersResource } from './resources/component-folders';\nimport { createComponentsResource } from './resources/components';\nimport { createDatasourceEntriesResource } from './resources/datasource-entries';\nimport { createDatasourcesResource } from './resources/datasources';\nimport { createExperimentsResource } from './resources/experiments';\nimport { createInternalTagsResource } from './resources/internal-tags';\nimport { createPresetsResource } from './resources/presets';\nimport { createSpacesResource } from './resources/spaces';\nimport { createStoriesResource } from './resources/stories';\nimport { createUsersResource } from './resources/users';\n\n// ---------------------------------------------------------------------------\n// Client types (co-located with runtime)\n// ---------------------------------------------------------------------------\n\nexport type ApiResponse<T, ThrowOnError extends boolean = false> =\n ThrowOnError extends true\n ? { data: T; error?: never; response: Response; request: Request }\n : | { data: T; error: undefined; response: Response; request: Request }\n | { data: undefined; error: ClientError; response: Response; request: Request };\n\nexport interface RequestConfigOverrides {\n throwOnError?: boolean;\n}\n\n/**\n * Arbitrary options forwarded to the underlying `fetch()` call.\n *\n * Standard `RequestInit` properties (`cache`, `credentials`, `mode`, …) and\n * non-standard, vendor-specific properties (Next.js `next`, Cloudflare `cf`, …)\n * are both supported.\n *\n * @example\n * ```ts\n * client.stories.get(123, {\n * fetchOptions: {\n * cache: 'no-store',\n * next: { revalidate: 60 },\n * },\n * })\n * ```\n */\nexport type FetchOptions = Record<string, unknown>;\n\nexport interface HttpRequestOptions {\n query?: Record<string, unknown>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n throwOnError?: RequestConfigOverrides['throwOnError'];\n fetchOptions?: FetchOptions;\n}\n\n/**\n * Dependencies injected into every resource factory.\n */\nexport interface MapiResourceDeps<DefaultThrowOnError extends boolean = false> {\n client: Client;\n spaceId?: number;\n wrapRequest: <TData, ThrowOnError extends boolean = DefaultThrowOnError>(fn: () => Promise<unknown>, throwOnError?: ThrowOnError) => Promise<ApiResponse<TData, ThrowOnError>>;\n}\n\ntype TokenConfig =\n | {\n /** Personal access token for authentication. */\n personalAccessToken: string;\n oauthToken?: never;\n }\n | {\n personalAccessToken?: never;\n /** OAuth bearer token for authentication. */\n oauthToken: string;\n }\n | {\n personalAccessToken?: undefined;\n oauthToken?: undefined;\n };\n\nexport type ManagementApiClientConfig<\n ThrowOnError extends boolean = false,\n> = TokenConfig & {\n /**\n * The Storyblok space ID. Used as the default for space-scoped endpoints.\n * You can also override it per request via `path.space_id`.\n */\n spaceId?: number;\n /**\n * Storyblok region. Determines the base URL.\n * @default 'eu'\n */\n region?: Region;\n /**\n * Override the base URL entirely (e.g. for testing).\n */\n baseUrl?: string;\n /**\n * Additional request headers.\n */\n headers?: Record<string, string>;\n /**\n * Throw on HTTP errors instead of returning them.\n * @default false\n */\n throwOnError?: ThrowOnError;\n /**\n * Retry configuration for failed requests.\n */\n retry?: RetryOptions;\n /**\n * Request timeout in milliseconds.\n * @default 30_000\n */\n timeout?: number;\n /**\n * Preventive rate limiting to avoid hitting the Storyblok Management API rate limits.\n *\n * - `undefined` (default): single bucket at maxConcurrency: 6.\n * - `number`: fixed max concurrent requests per second.\n * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.\n * - `false`: disable rate limiting entirely.\n */\n rateLimit?: RateLimitConfig | number | false;\n};\n\n// ---------------------------------------------------------------------------\n// Client factory\n// ---------------------------------------------------------------------------\n\nfunction getAuthorizationHeader(config: ManagementApiClientConfig<boolean>): string | undefined {\n if (config.personalAccessToken) {\n return config.personalAccessToken;\n }\n if (config.oauthToken) {\n return config.oauthToken.startsWith('Bearer ')\n ? config.oauthToken\n : `Bearer ${config.oauthToken}`;\n }\n return undefined;\n}\n\nconst createManagementApiClientBase = <DefaultThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): {\n deps: MapiResourceDeps<DefaultThrowOnError>;\n resources: Omit<ReturnType<typeof buildResources<DefaultThrowOnError>>, never>;\n} => {\n const {\n spaceId,\n region = 'eu',\n baseUrl,\n headers = {},\n throwOnError = false,\n retry = {\n limit: 12,\n backoffLimit: 20_000,\n methods: ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'],\n statusCodes: [429],\n },\n timeout = 30_000,\n rateLimit,\n } = config;\n\n const throttleManager = createThrottleManager(rateLimit ?? {});\n const authHeader = getAuthorizationHeader(config);\n\n const client: Client = createClient(\n createConfig({\n baseUrl: baseUrl || getManagementBaseUrl(region),\n headers: {\n ...(authHeader ? { Authorization: authHeader } : {}),\n ...headers,\n },\n // Default serializer throws on nested objects; MAPI needs `filter_query`\n // serialized as a nested hash (`filter_query[field][op]=value`).\n querySerializer,\n throwOnError,\n kyOptions: {\n throwHttpErrors: true,\n timeout,\n retry,\n },\n }),\n );\n\n client.interceptors.error.use(\n (error: unknown, response: Response) =>\n new ClientError(response?.statusText || 'API request failed', {\n status: response?.status ?? 0,\n statusText: response?.statusText ?? '',\n data: error,\n }),\n );\n\n function wrapRequest<TData, CurrentThrowOnError extends boolean = DefaultThrowOnError>(\n fn: () => Promise<unknown>,\n _throwOnError?: CurrentThrowOnError,\n ): Promise<ApiResponse<TData, CurrentThrowOnError>> {\n return throttleManager.execute(\n () => fn() as Promise<ApiResponse<TData, CurrentThrowOnError>>,\n );\n }\n\n const deps: MapiResourceDeps<DefaultThrowOnError> = { client, spaceId, wrapRequest };\n return { deps, resources: buildResources(deps, client) };\n};\n\nfunction buildResources<DefaultThrowOnError extends boolean = false>(\n deps: MapiResourceDeps<DefaultThrowOnError>,\n client: Client,\n) {\n /**\n * Escape hatch: send a GET request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpGet = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.get({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a POST request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPost = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.post({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPut = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.put({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PATCH request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPatch = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.patch({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a DELETE request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpDelete = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.delete({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n return {\n assetFolders: createAssetFoldersResource(deps),\n assets: createAssetsResource(deps),\n componentFolders: createComponentFoldersResource(deps),\n datasourceEntries: createDatasourceEntriesResource(deps),\n datasources: createDatasourcesResource(deps),\n experiments: createExperimentsResource(deps),\n delete: httpDelete,\n get: httpGet,\n patch: httpPatch,\n interceptors: client.interceptors as Middleware<Request, Response, unknown, ResolvedRequestOptions>,\n internalTags: createInternalTagsResource(deps),\n post: httpPost,\n presets: createPresetsResource(deps),\n put: httpPut,\n spaces: createSpacesResource(deps),\n users: createUsersResource<DefaultThrowOnError>({ client, wrapRequest: deps.wrapRequest }),\n };\n}\n\ntype StoryblokTypesConfig = { components: Block } | { blocks: Block };\n\ntype ResolveComponents<T extends StoryblokTypesConfig> =\n T extends { components: infer C extends Block } ? C\n : T extends { blocks: infer B extends Block } ? B\n : never;\n\n/**\n * The return type of `createManagementApiClient`, parameterised by `TBlocks` so that\n * `.stories` methods can narrow story content types without touching the runtime object.\n * Component *definitions* (`.components`) are wire-shaped and not narrowed by `TBlocks`.\n */\nexport type ManagementApiClient<\n TBlocks extends Block = Block,\n DefaultThrowOnError extends boolean = false,\n> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {\n components: ReturnType<typeof createComponentsResource<DefaultThrowOnError>>;\n stories: ReturnType<typeof createStoriesResource<TBlocks, DefaultThrowOnError>>;\n /**\n * Returns the same client instance cast to a version that narrows story content\n * to the provided component types. No runtime cost — type parameter is erased.\n *\n * Accepts either `{ components: ... }` or `{ blocks: ... }` — the latter matches the\n * `Schema` type produced by `@storyblok/schema`'s `InferSchema`.\n *\n * @example\n * ```ts\n * import type { Schema } from './schema';\n *\n * const client = createManagementApiClient({ personalAccessToken: '...' })\n * .withTypes<Schema>();\n * ```\n */\n withTypes: <T extends StoryblokTypesConfig>() => ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n};\n\nexport const createManagementApiClient = <\n DefaultThrowOnError extends boolean = false,\n>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): ManagementApiClient<Block, DefaultThrowOnError> => {\n const { deps, resources } = createManagementApiClientBase(config);\n const self: ManagementApiClient<Block, DefaultThrowOnError> = {\n ...resources,\n components: createComponentsResource<DefaultThrowOnError>(deps),\n stories: createStoriesResource<Block, DefaultThrowOnError>(deps),\n withTypes<T extends StoryblokTypesConfig>() {\n return self as unknown as ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n },\n };\n return self;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4IA,SAAS,uBAAuB,QAAgE;AAC9F,KAAI,OAAO,oBACT,QAAO,OAAO;AAEhB,KAAI,OAAO,WACT,QAAO,OAAO,WAAW,WAAW,UAAU,GAC1C,OAAO,aACP,UAAU,OAAO;;AAKzB,MAAM,iCACJ,WAIG;CACH,MAAM,EACJ,SACA,SAAS,MACT,SACA,UAAU,EAAE,EACZ,eAAe,OACf,QAAQ;EACN,OAAO;EACP,cAAc;EACd,SAAS;GAAC;GAAO;GAAQ;GAAO;GAAU;GAAS;GAAQ;GAAW;GAAQ;EAC9E,aAAa,CAAC,IAAI;EACnB,EACD,UAAU,KACV,cACE;CAEJ,MAAM,kBAAkBA,yCAAsB,aAAa,EAAE,CAAC;CAC9D,MAAM,aAAa,uBAAuB,OAAO;CAEjD,MAAM,SAAiBC,gCACrBC,+BAAa;EACX,SAAS,8DAAgC,OAAO;EAChD,SAAS;GACP,GAAI,aAAa,EAAE,eAAe,YAAY,GAAG,EAAE;GACnD,GAAG;GACJ;EAGD;EACA;EACA,WAAW;GACT,iBAAiB;GACjB;GACA;GACD;EACF,CAAC,CACH;AAED,QAAO,aAAa,MAAM,KACvB,OAAgB,aACf,IAAIC,0BAAY,UAAU,cAAc,sBAAsB;EAC5D,QAAQ,UAAU,UAAU;EAC5B,YAAY,UAAU,cAAc;EACpC,MAAM;EACP,CAAC,CACL;CAED,SAAS,YACP,IACA,eACkD;AAClD,SAAO,gBAAgB,cACf,IAAI,CACX;;CAGH,MAAM,OAA8C;EAAE;EAAQ;EAAS;EAAa;AACpF,QAAO;EAAE;EAAM,WAAW,eAAe,MAAM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eAAe,EAAE,WAAW;IAAE,GAAG,OAAO,WAAW,CAAC;IAAW,GAAG;IAAc,EAAE,GAAG,EAAE;GAAG,CAAC,CACpI;;AAGH,QAAO;EACL,cAAcC,iDAA2B,KAAK;EAC9C,QAAQC,oCAAqB,KAAK;EAClC,kBAAkBC,yDAA+B,KAAK;EACtD,mBAAmBC,2DAAgC,KAAK;EACxD,aAAaC,8CAA0B,KAAK;EAC5C,aAAaC,8CAA0B,KAAK;EAC5C,QAAQ;EACR,KAAK;EACL,OAAO;EACP,cAAc,OAAO;EACrB,cAAcC,iDAA2B,KAAK;EAC9C,MAAM;EACN,SAASC,sCAAsB,KAAK;EACpC,KAAK;EACL,QAAQC,oCAAqB,KAAK;EAClC,OAAOC,kCAAyC;GAAE;GAAQ,aAAa,KAAK;GAAa,CAAC;EAC3F;;AAuCH,MAAa,6BAGX,WACoD;CACpD,MAAM,EAAE,MAAM,cAAc,8BAA8B,OAAO;CACjE,MAAM,OAAwD;EAC5D,GAAG;EACH,YAAYC,4CAA8C,KAAK;EAC/D,SAASC,sCAAkD,KAAK;EAChE,YAA4C;AAC1C,UAAO;;EAEV;AACD,QAAO"}
|
package/dist/client.d.cts
CHANGED
|
@@ -412,7 +412,12 @@ declare function buildResources<DefaultThrowOnError extends boolean = false>(dep
|
|
|
412
412
|
fetchOptions?: FetchOptions;
|
|
413
413
|
} & SpaceIdPathOverride): Promise<ApiResponse<CompleteExperimentWithWinnerResponses[200], ThrowOnError>>;
|
|
414
414
|
selectWinner<ThrowOnError extends boolean = false>(experimentId: number | string, variantId: number, options?: {
|
|
415
|
-
signal
|
|
415
|
+
signal?
|
|
416
|
+
/**
|
|
417
|
+
* Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped
|
|
418
|
+
* in a dedicated resource method.
|
|
419
|
+
*/
|
|
420
|
+
: AbortSignal;
|
|
416
421
|
throwOnError?: ThrowOnError;
|
|
417
422
|
fetchOptions?: FetchOptions;
|
|
418
423
|
} & SpaceIdPathOverride): Promise<ApiResponse<SelectExperimentWinnerResponses[200], ThrowOnError>>;
|
|
@@ -603,12 +608,13 @@ type ResolveComponents<T extends StoryblokTypesConfig> = T extends {
|
|
|
603
608
|
blocks: infer B extends Block;
|
|
604
609
|
} ? B : never;
|
|
605
610
|
/**
|
|
606
|
-
* The return type of `createManagementApiClient`, parameterised by `
|
|
611
|
+
* The return type of `createManagementApiClient`, parameterised by `TBlocks` so that
|
|
607
612
|
* `.stories` methods can narrow story content types without touching the runtime object.
|
|
613
|
+
* Component *definitions* (`.components`) are wire-shaped and not narrowed by `TBlocks`.
|
|
608
614
|
*/
|
|
609
|
-
type ManagementApiClient<
|
|
610
|
-
components: ReturnType<typeof createComponentsResource<
|
|
611
|
-
stories: ReturnType<typeof createStoriesResource<
|
|
615
|
+
type ManagementApiClient<TBlocks extends Block = Block, DefaultThrowOnError extends boolean = false> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {
|
|
616
|
+
components: ReturnType<typeof createComponentsResource<DefaultThrowOnError>>;
|
|
617
|
+
stories: ReturnType<typeof createStoriesResource<TBlocks, DefaultThrowOnError>>;
|
|
612
618
|
/**
|
|
613
619
|
* Returns the same client instance cast to a version that narrows story content
|
|
614
620
|
* to the provided component types. No runtime cost — type parameter is erased.
|
package/dist/client.d.mts
CHANGED
|
@@ -412,7 +412,12 @@ declare function buildResources<DefaultThrowOnError extends boolean = false>(dep
|
|
|
412
412
|
fetchOptions?: FetchOptions;
|
|
413
413
|
} & SpaceIdPathOverride): Promise<ApiResponse<CompleteExperimentWithWinnerResponses[200], ThrowOnError>>;
|
|
414
414
|
selectWinner<ThrowOnError extends boolean = false>(experimentId: number | string, variantId: number, options?: {
|
|
415
|
-
signal
|
|
415
|
+
signal?
|
|
416
|
+
/**
|
|
417
|
+
* Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped
|
|
418
|
+
* in a dedicated resource method.
|
|
419
|
+
*/
|
|
420
|
+
: AbortSignal;
|
|
416
421
|
throwOnError?: ThrowOnError;
|
|
417
422
|
fetchOptions?: FetchOptions;
|
|
418
423
|
} & SpaceIdPathOverride): Promise<ApiResponse<SelectExperimentWinnerResponses[200], ThrowOnError>>;
|
|
@@ -603,12 +608,13 @@ type ResolveComponents<T extends StoryblokTypesConfig> = T extends {
|
|
|
603
608
|
blocks: infer B extends Block;
|
|
604
609
|
} ? B : never;
|
|
605
610
|
/**
|
|
606
|
-
* The return type of `createManagementApiClient`, parameterised by `
|
|
611
|
+
* The return type of `createManagementApiClient`, parameterised by `TBlocks` so that
|
|
607
612
|
* `.stories` methods can narrow story content types without touching the runtime object.
|
|
613
|
+
* Component *definitions* (`.components`) are wire-shaped and not narrowed by `TBlocks`.
|
|
608
614
|
*/
|
|
609
|
-
type ManagementApiClient<
|
|
610
|
-
components: ReturnType<typeof createComponentsResource<
|
|
611
|
-
stories: ReturnType<typeof createStoriesResource<
|
|
615
|
+
type ManagementApiClient<TBlocks extends Block = Block, DefaultThrowOnError extends boolean = false> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {
|
|
616
|
+
components: ReturnType<typeof createComponentsResource<DefaultThrowOnError>>;
|
|
617
|
+
stories: ReturnType<typeof createStoriesResource<TBlocks, DefaultThrowOnError>>;
|
|
612
618
|
/**
|
|
613
619
|
* Returns the same client instance cast to a version that narrows story content
|
|
614
620
|
* to the provided component types. No runtime cost — type parameter is erased.
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { Client, ResolvedRequestOptions, RetryOptions } from './generated/mapi/client';\nimport type { Middleware } from './generated/mapi/client/utils.gen';\nimport { createClient, createConfig } from './generated/mapi/client';\nimport { getManagementBaseUrl } from '@storyblok/region-helper';\nimport type { Region } from '@storyblok/region-helper';\nimport type { Block as Component } from './generated/types/block';\nimport { ClientError } from './error';\nimport type { RateLimitConfig } from './utils/rate-limit';\nimport { createThrottleManager } from './utils/rate-limit';\nimport { querySerializer } from './utils/query-serializer';\nimport { createAssetFoldersResource } from './resources/asset-folders';\nimport { createAssetsResource } from './resources/assets';\nimport { createComponentFoldersResource } from './resources/component-folders';\nimport { createComponentsResource } from './resources/components';\nimport { createDatasourceEntriesResource } from './resources/datasource-entries';\nimport { createDatasourcesResource } from './resources/datasources';\nimport { createExperimentsResource } from './resources/experiments';\nimport { createInternalTagsResource } from './resources/internal-tags';\nimport { createPresetsResource } from './resources/presets';\nimport { createSpacesResource } from './resources/spaces';\nimport { createStoriesResource } from './resources/stories';\nimport { createUsersResource } from './resources/users';\n\n// ---------------------------------------------------------------------------\n// Client types (co-located with runtime)\n// ---------------------------------------------------------------------------\n\nexport type ApiResponse<T, ThrowOnError extends boolean = false> =\n ThrowOnError extends true\n ? { data: T; error?: never; response: Response; request: Request }\n : | { data: T; error: undefined; response: Response; request: Request }\n | { data: undefined; error: ClientError; response: Response; request: Request };\n\nexport interface RequestConfigOverrides {\n throwOnError?: boolean;\n}\n\n/**\n * Arbitrary options forwarded to the underlying `fetch()` call.\n *\n * Standard `RequestInit` properties (`cache`, `credentials`, `mode`, …) and\n * non-standard, vendor-specific properties (Next.js `next`, Cloudflare `cf`, …)\n * are both supported.\n *\n * @example\n * ```ts\n * client.stories.get(123, {\n * fetchOptions: {\n * cache: 'no-store',\n * next: { revalidate: 60 },\n * },\n * })\n * ```\n */\nexport type FetchOptions = Record<string, unknown>;\n\nexport interface HttpRequestOptions {\n query?: Record<string, unknown>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n throwOnError?: RequestConfigOverrides['throwOnError'];\n fetchOptions?: FetchOptions;\n}\n\n/**\n * Dependencies injected into every resource factory.\n */\nexport interface MapiResourceDeps<DefaultThrowOnError extends boolean = false> {\n client: Client;\n spaceId?: number;\n wrapRequest: <TData, ThrowOnError extends boolean = DefaultThrowOnError>(fn: () => Promise<unknown>, throwOnError?: ThrowOnError) => Promise<ApiResponse<TData, ThrowOnError>>;\n}\n\ntype TokenConfig =\n | {\n /** Personal access token for authentication. */\n personalAccessToken: string;\n oauthToken?: never;\n }\n | {\n personalAccessToken?: never;\n /** OAuth bearer token for authentication. */\n oauthToken: string;\n }\n | {\n personalAccessToken?: undefined;\n oauthToken?: undefined;\n };\n\nexport type ManagementApiClientConfig<\n ThrowOnError extends boolean = false,\n> = TokenConfig & {\n /**\n * The Storyblok space ID. Used as the default for space-scoped endpoints.\n * You can also override it per request via `path.space_id`.\n */\n spaceId?: number;\n /**\n * Storyblok region. Determines the base URL.\n * @default 'eu'\n */\n region?: Region;\n /**\n * Override the base URL entirely (e.g. for testing).\n */\n baseUrl?: string;\n /**\n * Additional request headers.\n */\n headers?: Record<string, string>;\n /**\n * Throw on HTTP errors instead of returning them.\n * @default false\n */\n throwOnError?: ThrowOnError;\n /**\n * Retry configuration for failed requests.\n */\n retry?: RetryOptions;\n /**\n * Request timeout in milliseconds.\n * @default 30_000\n */\n timeout?: number;\n /**\n * Preventive rate limiting to avoid hitting the Storyblok Management API rate limits.\n *\n * - `undefined` (default): single bucket at maxConcurrency: 6.\n * - `number`: fixed max concurrent requests per second.\n * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.\n * - `false`: disable rate limiting entirely.\n */\n rateLimit?: RateLimitConfig | number | false;\n};\n\n// ---------------------------------------------------------------------------\n// Client factory\n// ---------------------------------------------------------------------------\n\nfunction getAuthorizationHeader(config: ManagementApiClientConfig<boolean>): string | undefined {\n if (config.personalAccessToken) {\n return config.personalAccessToken;\n }\n if (config.oauthToken) {\n return config.oauthToken.startsWith('Bearer ')\n ? config.oauthToken\n : `Bearer ${config.oauthToken}`;\n }\n return undefined;\n}\n\nconst createManagementApiClientBase = <DefaultThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): {\n deps: MapiResourceDeps<DefaultThrowOnError>;\n resources: Omit<ReturnType<typeof buildResources<DefaultThrowOnError>>, never>;\n} => {\n const {\n spaceId,\n region = 'eu',\n baseUrl,\n headers = {},\n throwOnError = false,\n retry = {\n limit: 12,\n backoffLimit: 20_000,\n methods: ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'],\n statusCodes: [429],\n },\n timeout = 30_000,\n rateLimit,\n } = config;\n\n const throttleManager = createThrottleManager(rateLimit ?? {});\n const authHeader = getAuthorizationHeader(config);\n\n const client: Client = createClient(\n createConfig({\n baseUrl: baseUrl || getManagementBaseUrl(region),\n headers: {\n ...(authHeader ? { Authorization: authHeader } : {}),\n ...headers,\n },\n // Default serializer throws on nested objects; MAPI needs `filter_query`\n // serialized as a nested hash (`filter_query[field][op]=value`).\n querySerializer,\n throwOnError,\n kyOptions: {\n throwHttpErrors: true,\n timeout,\n retry,\n },\n }),\n );\n\n client.interceptors.error.use(\n (error: unknown, response: Response) =>\n new ClientError(response?.statusText || 'API request failed', {\n status: response?.status ?? 0,\n statusText: response?.statusText ?? '',\n data: error,\n }),\n );\n\n function wrapRequest<TData, CurrentThrowOnError extends boolean = DefaultThrowOnError>(\n fn: () => Promise<unknown>,\n _throwOnError?: CurrentThrowOnError,\n ): Promise<ApiResponse<TData, CurrentThrowOnError>> {\n return throttleManager.execute(\n () => fn() as Promise<ApiResponse<TData, CurrentThrowOnError>>,\n );\n }\n\n const deps: MapiResourceDeps<DefaultThrowOnError> = { client, spaceId, wrapRequest };\n return { deps, resources: buildResources(deps, client) };\n};\n\nfunction buildResources<DefaultThrowOnError extends boolean = false>(\n deps: MapiResourceDeps<DefaultThrowOnError>,\n client: Client,\n) {\n /**\n * Escape hatch: send a GET request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpGet = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.get({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a POST request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPost = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.post({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPut = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.put({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PATCH request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPatch = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.patch({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a DELETE request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpDelete = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.delete({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n return {\n assetFolders: createAssetFoldersResource(deps),\n assets: createAssetsResource(deps),\n componentFolders: createComponentFoldersResource(deps),\n datasourceEntries: createDatasourceEntriesResource(deps),\n datasources: createDatasourcesResource(deps),\n experiments: createExperimentsResource(deps),\n delete: httpDelete,\n get: httpGet,\n patch: httpPatch,\n interceptors: client.interceptors as Middleware<Request, Response, unknown, ResolvedRequestOptions>,\n internalTags: createInternalTagsResource(deps),\n post: httpPost,\n presets: createPresetsResource(deps),\n put: httpPut,\n spaces: createSpacesResource(deps),\n users: createUsersResource<DefaultThrowOnError>({ client, wrapRequest: deps.wrapRequest }),\n };\n}\n\ntype StoryblokTypesConfig = { components: Component } | { blocks: Component };\n\ntype ResolveComponents<T extends StoryblokTypesConfig> =\n T extends { components: infer C extends Component } ? C\n : T extends { blocks: infer B extends Component } ? B\n : never;\n\n/**\n * The return type of `createManagementApiClient`, parameterised by `TComponents` so that\n * `.stories` methods can narrow story content types without touching the runtime object.\n */\nexport type ManagementApiClient<\n TComponents extends Component = Component,\n DefaultThrowOnError extends boolean = false,\n> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {\n components: ReturnType<typeof createComponentsResource<TComponents, DefaultThrowOnError>>;\n stories: ReturnType<typeof createStoriesResource<TComponents, DefaultThrowOnError>>;\n /**\n * Returns the same client instance cast to a version that narrows story content\n * to the provided component types. No runtime cost — type parameter is erased.\n *\n * Accepts either `{ components: ... }` or `{ blocks: ... }` — the latter matches the\n * `Schema` type produced by `@storyblok/schema`'s `InferSchema`.\n *\n * @example\n * ```ts\n * import type { Schema } from './schema';\n *\n * const client = createManagementApiClient({ personalAccessToken: '...' })\n * .withTypes<Schema>();\n * ```\n */\n withTypes: <T extends StoryblokTypesConfig>() => ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n};\n\nexport const createManagementApiClient = <\n DefaultThrowOnError extends boolean = false,\n>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): ManagementApiClient<Component, DefaultThrowOnError> => {\n const { deps, resources } = createManagementApiClientBase(config);\n const self: ManagementApiClient<Component, DefaultThrowOnError> = {\n ...resources,\n components: createComponentsResource<Component, DefaultThrowOnError>(deps),\n stories: createStoriesResource<Component, DefaultThrowOnError>(deps),\n withTypes<T extends StoryblokTypesConfig>() {\n return self as unknown as ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n },\n };\n return self;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4IA,SAAS,uBAAuB,QAAgE;AAC9F,KAAI,OAAO,oBACT,QAAO,OAAO;AAEhB,KAAI,OAAO,WACT,QAAO,OAAO,WAAW,WAAW,UAAU,GAC1C,OAAO,aACP,UAAU,OAAO;;AAKzB,MAAM,iCACJ,WAIG;CACH,MAAM,EACJ,SACA,SAAS,MACT,SACA,UAAU,EAAE,EACZ,eAAe,OACf,QAAQ;EACN,OAAO;EACP,cAAc;EACd,SAAS;GAAC;GAAO;GAAQ;GAAO;GAAU;GAAS;GAAQ;GAAW;GAAQ;EAC9E,aAAa,CAAC,IAAI;EACnB,EACD,UAAU,KACV,cACE;CAEJ,MAAM,kBAAkB,sBAAsB,aAAa,EAAE,CAAC;CAC9D,MAAM,aAAa,uBAAuB,OAAO;CAEjD,MAAM,SAAiB,aACrB,aAAa;EACX,SAAS,WAAW,qBAAqB,OAAO;EAChD,SAAS;GACP,GAAI,aAAa,EAAE,eAAe,YAAY,GAAG,EAAE;GACnD,GAAG;GACJ;EAGD;EACA;EACA,WAAW;GACT,iBAAiB;GACjB;GACA;GACD;EACF,CAAC,CACH;AAED,QAAO,aAAa,MAAM,KACvB,OAAgB,aACf,IAAI,YAAY,UAAU,cAAc,sBAAsB;EAC5D,QAAQ,UAAU,UAAU;EAC5B,YAAY,UAAU,cAAc;EACpC,MAAM;EACP,CAAC,CACL;CAED,SAAS,YACP,IACA,eACkD;AAClD,SAAO,gBAAgB,cACf,IAAI,CACX;;CAGH,MAAM,OAA8C;EAAE;EAAQ;EAAS;EAAa;AACpF,QAAO;EAAE;EAAM,WAAW,eAAe,MAAM,OAAO;EAAE;;AAG1D,SAAS,eACP,MACA,QACA;;;;;CAKA,MAAM,WACJ,MACA,UAA8B,EAAE,KACqB;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,CAAC,CACpI;;AAGH,QAAO;EACL,cAAc,2BAA2B,KAAK;EAC9C,QAAQ,qBAAqB,KAAK;EAClC,kBAAkB,+BAA+B,KAAK;EACtD,mBAAmB,gCAAgC,KAAK;EACxD,aAAa,0BAA0B,KAAK;EAC5C,aAAa,0BAA0B,KAAK;EAC5C,QAAQ;EACR,KAAK;EACL,OAAO;EACP,cAAc,OAAO;EACrB,cAAc,2BAA2B,KAAK;EAC9C,MAAM;EACN,SAAS,sBAAsB,KAAK;EACpC,KAAK;EACL,QAAQ,qBAAqB,KAAK;EAClC,OAAO,oBAAyC;GAAE;GAAQ,aAAa,KAAK;GAAa,CAAC;EAC3F;;AAsCH,MAAa,6BAGX,WACwD;CACxD,MAAM,EAAE,MAAM,cAAc,8BAA8B,OAAO;CACjE,MAAM,OAA4D;EAChE,GAAG;EACH,YAAY,yBAAyD,KAAK;EAC1E,SAAS,sBAAsD,KAAK;EACpE,YAA4C;AAC1C,UAAO;;EAEV;AACD,QAAO"}
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { Client, ResolvedRequestOptions, RetryOptions } from './generated/mapi/client';\nimport type { Middleware } from './generated/mapi/client/utils.gen';\nimport { createClient, createConfig } from './generated/mapi/client';\nimport { getManagementBaseUrl } from '@storyblok/region-helper';\nimport type { Region } from '@storyblok/region-helper';\nimport type { Block } from './generated/types/block';\nimport { ClientError } from './error';\nimport type { RateLimitConfig } from './utils/rate-limit';\nimport { createThrottleManager } from './utils/rate-limit';\nimport { querySerializer } from './utils/query-serializer';\nimport { createAssetFoldersResource } from './resources/asset-folders';\nimport { createAssetsResource } from './resources/assets';\nimport { createComponentFoldersResource } from './resources/component-folders';\nimport { createComponentsResource } from './resources/components';\nimport { createDatasourceEntriesResource } from './resources/datasource-entries';\nimport { createDatasourcesResource } from './resources/datasources';\nimport { createExperimentsResource } from './resources/experiments';\nimport { createInternalTagsResource } from './resources/internal-tags';\nimport { createPresetsResource } from './resources/presets';\nimport { createSpacesResource } from './resources/spaces';\nimport { createStoriesResource } from './resources/stories';\nimport { createUsersResource } from './resources/users';\n\n// ---------------------------------------------------------------------------\n// Client types (co-located with runtime)\n// ---------------------------------------------------------------------------\n\nexport type ApiResponse<T, ThrowOnError extends boolean = false> =\n ThrowOnError extends true\n ? { data: T; error?: never; response: Response; request: Request }\n : | { data: T; error: undefined; response: Response; request: Request }\n | { data: undefined; error: ClientError; response: Response; request: Request };\n\nexport interface RequestConfigOverrides {\n throwOnError?: boolean;\n}\n\n/**\n * Arbitrary options forwarded to the underlying `fetch()` call.\n *\n * Standard `RequestInit` properties (`cache`, `credentials`, `mode`, …) and\n * non-standard, vendor-specific properties (Next.js `next`, Cloudflare `cf`, …)\n * are both supported.\n *\n * @example\n * ```ts\n * client.stories.get(123, {\n * fetchOptions: {\n * cache: 'no-store',\n * next: { revalidate: 60 },\n * },\n * })\n * ```\n */\nexport type FetchOptions = Record<string, unknown>;\n\nexport interface HttpRequestOptions {\n query?: Record<string, unknown>;\n body?: unknown;\n headers?: Record<string, string>;\n signal?: AbortSignal;\n throwOnError?: RequestConfigOverrides['throwOnError'];\n fetchOptions?: FetchOptions;\n}\n\n/**\n * Dependencies injected into every resource factory.\n */\nexport interface MapiResourceDeps<DefaultThrowOnError extends boolean = false> {\n client: Client;\n spaceId?: number;\n wrapRequest: <TData, ThrowOnError extends boolean = DefaultThrowOnError>(fn: () => Promise<unknown>, throwOnError?: ThrowOnError) => Promise<ApiResponse<TData, ThrowOnError>>;\n}\n\ntype TokenConfig =\n | {\n /** Personal access token for authentication. */\n personalAccessToken: string;\n oauthToken?: never;\n }\n | {\n personalAccessToken?: never;\n /** OAuth bearer token for authentication. */\n oauthToken: string;\n }\n | {\n personalAccessToken?: undefined;\n oauthToken?: undefined;\n };\n\nexport type ManagementApiClientConfig<\n ThrowOnError extends boolean = false,\n> = TokenConfig & {\n /**\n * The Storyblok space ID. Used as the default for space-scoped endpoints.\n * You can also override it per request via `path.space_id`.\n */\n spaceId?: number;\n /**\n * Storyblok region. Determines the base URL.\n * @default 'eu'\n */\n region?: Region;\n /**\n * Override the base URL entirely (e.g. for testing).\n */\n baseUrl?: string;\n /**\n * Additional request headers.\n */\n headers?: Record<string, string>;\n /**\n * Throw on HTTP errors instead of returning them.\n * @default false\n */\n throwOnError?: ThrowOnError;\n /**\n * Retry configuration for failed requests.\n */\n retry?: RetryOptions;\n /**\n * Request timeout in milliseconds.\n * @default 30_000\n */\n timeout?: number;\n /**\n * Preventive rate limiting to avoid hitting the Storyblok Management API rate limits.\n *\n * - `undefined` (default): single bucket at maxConcurrency: 6.\n * - `number`: fixed max concurrent requests per second.\n * - `{ maxConcurrency?: number; adaptToServerHeaders?: boolean }`: full config.\n * - `false`: disable rate limiting entirely.\n */\n rateLimit?: RateLimitConfig | number | false;\n};\n\n// ---------------------------------------------------------------------------\n// Client factory\n// ---------------------------------------------------------------------------\n\nfunction getAuthorizationHeader(config: ManagementApiClientConfig<boolean>): string | undefined {\n if (config.personalAccessToken) {\n return config.personalAccessToken;\n }\n if (config.oauthToken) {\n return config.oauthToken.startsWith('Bearer ')\n ? config.oauthToken\n : `Bearer ${config.oauthToken}`;\n }\n return undefined;\n}\n\nconst createManagementApiClientBase = <DefaultThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): {\n deps: MapiResourceDeps<DefaultThrowOnError>;\n resources: Omit<ReturnType<typeof buildResources<DefaultThrowOnError>>, never>;\n} => {\n const {\n spaceId,\n region = 'eu',\n baseUrl,\n headers = {},\n throwOnError = false,\n retry = {\n limit: 12,\n backoffLimit: 20_000,\n methods: ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'],\n statusCodes: [429],\n },\n timeout = 30_000,\n rateLimit,\n } = config;\n\n const throttleManager = createThrottleManager(rateLimit ?? {});\n const authHeader = getAuthorizationHeader(config);\n\n const client: Client = createClient(\n createConfig({\n baseUrl: baseUrl || getManagementBaseUrl(region),\n headers: {\n ...(authHeader ? { Authorization: authHeader } : {}),\n ...headers,\n },\n // Default serializer throws on nested objects; MAPI needs `filter_query`\n // serialized as a nested hash (`filter_query[field][op]=value`).\n querySerializer,\n throwOnError,\n kyOptions: {\n throwHttpErrors: true,\n timeout,\n retry,\n },\n }),\n );\n\n client.interceptors.error.use(\n (error: unknown, response: Response) =>\n new ClientError(response?.statusText || 'API request failed', {\n status: response?.status ?? 0,\n statusText: response?.statusText ?? '',\n data: error,\n }),\n );\n\n function wrapRequest<TData, CurrentThrowOnError extends boolean = DefaultThrowOnError>(\n fn: () => Promise<unknown>,\n _throwOnError?: CurrentThrowOnError,\n ): Promise<ApiResponse<TData, CurrentThrowOnError>> {\n return throttleManager.execute(\n () => fn() as Promise<ApiResponse<TData, CurrentThrowOnError>>,\n );\n }\n\n const deps: MapiResourceDeps<DefaultThrowOnError> = { client, spaceId, wrapRequest };\n return { deps, resources: buildResources(deps, client) };\n};\n\nfunction buildResources<DefaultThrowOnError extends boolean = false>(\n deps: MapiResourceDeps<DefaultThrowOnError>,\n client: Client,\n) {\n /**\n * Escape hatch: send a GET request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpGet = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.get({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a POST request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPost = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.post({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PUT request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPut = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.put({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a PATCH request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpPatch = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.patch({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n /**\n * Escape hatch: send a DELETE request to any MAPI endpoint not yet wrapped\n * in a dedicated resource method.\n */\n const httpDelete = <TData = unknown>(\n path: string,\n options: HttpRequestOptions = {},\n ): Promise<ApiResponse<TData, DefaultThrowOnError>> => {\n const { fetchOptions, ...rest } = options;\n return deps.wrapRequest<TData>(() =>\n client.delete({ url: path, ...rest, ...(fetchOptions ? { kyOptions: { ...client.getConfig().kyOptions, ...fetchOptions } } : {}) }),\n );\n };\n\n return {\n assetFolders: createAssetFoldersResource(deps),\n assets: createAssetsResource(deps),\n componentFolders: createComponentFoldersResource(deps),\n datasourceEntries: createDatasourceEntriesResource(deps),\n datasources: createDatasourcesResource(deps),\n experiments: createExperimentsResource(deps),\n delete: httpDelete,\n get: httpGet,\n patch: httpPatch,\n interceptors: client.interceptors as Middleware<Request, Response, unknown, ResolvedRequestOptions>,\n internalTags: createInternalTagsResource(deps),\n post: httpPost,\n presets: createPresetsResource(deps),\n put: httpPut,\n spaces: createSpacesResource(deps),\n users: createUsersResource<DefaultThrowOnError>({ client, wrapRequest: deps.wrapRequest }),\n };\n}\n\ntype StoryblokTypesConfig = { components: Block } | { blocks: Block };\n\ntype ResolveComponents<T extends StoryblokTypesConfig> =\n T extends { components: infer C extends Block } ? C\n : T extends { blocks: infer B extends Block } ? B\n : never;\n\n/**\n * The return type of `createManagementApiClient`, parameterised by `TBlocks` so that\n * `.stories` methods can narrow story content types without touching the runtime object.\n * Component *definitions* (`.components`) are wire-shaped and not narrowed by `TBlocks`.\n */\nexport type ManagementApiClient<\n TBlocks extends Block = Block,\n DefaultThrowOnError extends boolean = false,\n> = ReturnType<typeof buildResources<DefaultThrowOnError>> & {\n components: ReturnType<typeof createComponentsResource<DefaultThrowOnError>>;\n stories: ReturnType<typeof createStoriesResource<TBlocks, DefaultThrowOnError>>;\n /**\n * Returns the same client instance cast to a version that narrows story content\n * to the provided component types. No runtime cost — type parameter is erased.\n *\n * Accepts either `{ components: ... }` or `{ blocks: ... }` — the latter matches the\n * `Schema` type produced by `@storyblok/schema`'s `InferSchema`.\n *\n * @example\n * ```ts\n * import type { Schema } from './schema';\n *\n * const client = createManagementApiClient({ personalAccessToken: '...' })\n * .withTypes<Schema>();\n * ```\n */\n withTypes: <T extends StoryblokTypesConfig>() => ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n};\n\nexport const createManagementApiClient = <\n DefaultThrowOnError extends boolean = false,\n>(\n config: ManagementApiClientConfig<DefaultThrowOnError>,\n): ManagementApiClient<Block, DefaultThrowOnError> => {\n const { deps, resources } = createManagementApiClientBase(config);\n const self: ManagementApiClient<Block, DefaultThrowOnError> = {\n ...resources,\n components: createComponentsResource<DefaultThrowOnError>(deps),\n stories: createStoriesResource<Block, DefaultThrowOnError>(deps),\n withTypes<T extends StoryblokTypesConfig>() {\n return self as unknown as ManagementApiClient<ResolveComponents<T>, DefaultThrowOnError>;\n },\n };\n return self;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4IA,SAAS,uBAAuB,QAAgE;AAC9F,KAAI,OAAO,oBACT,QAAO,OAAO;AAE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EACP,cAAc,OAAO;EACrB,cAAc,2BAA2B,KAAK;EAC9C,MAAM;EACN,SAAS,sBAAsB,KAAK;EACpC,KAAK;EACL,QAAQ,qBAAqB,KAAK;EAClC,OAAO,oBAAyC;GAAE;GAAQ,aAAa,KAAK;GAAa,CAAC;EAC3F;;AAuCH,MAAa,6BAGX,WACoD;CACpD,MAAM,EAAE,MAAM,cAAc,8BAA8B,OAAO;CACjE,MAAM,OAAwD;EAC5D,GAAG;EACH,YAAY,yBAA8C,KAAK;EAC/D,SAAS,sBAAkD,KAAK;EAChE,YAA4C;AAC1C,UAAO;;EAEV;AACD,QAAO"}
|
|
@@ -1,174 +1,4 @@
|
|
|
1
1
|
//#region src/generated/mapi/_internal.gen.d.ts
|
|
2
|
-
type ComponentCreate = {
|
|
3
|
-
/**
|
|
4
|
-
* Name of the component
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* Human-readable display name
|
|
9
|
-
*/
|
|
10
|
-
display_name?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Component description
|
|
13
|
-
*/
|
|
14
|
-
description?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Preview template HTML
|
|
17
|
-
*/
|
|
18
|
-
preview_tmpl?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Component image URL
|
|
21
|
-
*/
|
|
22
|
-
image?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Field used for preview
|
|
25
|
-
*/
|
|
26
|
-
preview_field?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Whether this component can be used as a root component
|
|
29
|
-
*/
|
|
30
|
-
is_root?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Whether this component can be nested inside other components
|
|
33
|
-
*/
|
|
34
|
-
is_nestable?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Default preset ID
|
|
37
|
-
*/
|
|
38
|
-
preset_id?: number;
|
|
39
|
-
/**
|
|
40
|
-
* UUID
|
|
41
|
-
*/
|
|
42
|
-
component_group_uuid?: string;
|
|
43
|
-
/**
|
|
44
|
-
* Component color for UI display
|
|
45
|
-
*/
|
|
46
|
-
color?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Component icon name
|
|
49
|
-
*/
|
|
50
|
-
icon?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Asset preview URL for content type
|
|
53
|
-
*/
|
|
54
|
-
content_type_asset_preview?: string;
|
|
55
|
-
/**
|
|
56
|
-
* List of internal tag IDs
|
|
57
|
-
*/
|
|
58
|
-
internal_tag_ids?: Array<number>;
|
|
59
|
-
/**
|
|
60
|
-
* Component field schema definition
|
|
61
|
-
*/
|
|
62
|
-
schema?: {
|
|
63
|
-
[key: string]: {
|
|
64
|
-
type?: 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group';
|
|
65
|
-
/**
|
|
66
|
-
* Human-readable field name
|
|
67
|
-
*/
|
|
68
|
-
display_name?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Whether this field is required
|
|
71
|
-
*/
|
|
72
|
-
required?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Whether this field is translatable
|
|
75
|
-
*/
|
|
76
|
-
translatable?: boolean;
|
|
77
|
-
[key: string]: unknown | 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group' | string | boolean | undefined;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Component metadata
|
|
82
|
-
*/
|
|
83
|
-
metadata?: {
|
|
84
|
-
[key: string]: unknown;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
type ComponentUpdate = {
|
|
88
|
-
/**
|
|
89
|
-
* Name of the component
|
|
90
|
-
*/
|
|
91
|
-
name?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Human-readable display name
|
|
94
|
-
*/
|
|
95
|
-
display_name?: string;
|
|
96
|
-
/**
|
|
97
|
-
* Component description
|
|
98
|
-
*/
|
|
99
|
-
description?: string;
|
|
100
|
-
/**
|
|
101
|
-
* Preview template HTML
|
|
102
|
-
*/
|
|
103
|
-
preview_tmpl?: string;
|
|
104
|
-
/**
|
|
105
|
-
* Component image URL
|
|
106
|
-
*/
|
|
107
|
-
image?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Field used for preview
|
|
110
|
-
*/
|
|
111
|
-
preview_field?: string;
|
|
112
|
-
/**
|
|
113
|
-
* Whether this component can be used as a root component
|
|
114
|
-
*/
|
|
115
|
-
is_root?: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Whether this component can be nested inside other components
|
|
118
|
-
*/
|
|
119
|
-
is_nestable?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Default preset ID
|
|
122
|
-
*/
|
|
123
|
-
preset_id?: number;
|
|
124
|
-
/**
|
|
125
|
-
* UUID
|
|
126
|
-
*/
|
|
127
|
-
component_group_uuid?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Component color for UI display
|
|
130
|
-
*/
|
|
131
|
-
color?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Component icon name
|
|
134
|
-
*/
|
|
135
|
-
icon?: string;
|
|
136
|
-
/**
|
|
137
|
-
* Asset preview URL for content type
|
|
138
|
-
*/
|
|
139
|
-
content_type_asset_preview?: string;
|
|
140
|
-
/**
|
|
141
|
-
* List of internal tag IDs
|
|
142
|
-
*/
|
|
143
|
-
internal_tag_ids?: Array<number>;
|
|
144
|
-
/**
|
|
145
|
-
* Component field schema definition
|
|
146
|
-
*/
|
|
147
|
-
schema?: {
|
|
148
|
-
[key: string]: {
|
|
149
|
-
type?: 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group';
|
|
150
|
-
/**
|
|
151
|
-
* Human-readable field name
|
|
152
|
-
*/
|
|
153
|
-
display_name?: string;
|
|
154
|
-
/**
|
|
155
|
-
* Whether this field is required
|
|
156
|
-
*/
|
|
157
|
-
required?: boolean;
|
|
158
|
-
/**
|
|
159
|
-
* Whether this field is translatable
|
|
160
|
-
*/
|
|
161
|
-
translatable?: boolean;
|
|
162
|
-
[key: string]: unknown | 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group' | string | boolean | undefined;
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Component metadata
|
|
167
|
-
*/
|
|
168
|
-
metadata?: {
|
|
169
|
-
[key: string]: unknown;
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
2
|
type MapiStory = {
|
|
173
3
|
name: string;
|
|
174
4
|
/**
|
|
@@ -537,5 +367,5 @@ type Stage = {
|
|
|
537
367
|
created_at: string;
|
|
538
368
|
};
|
|
539
369
|
//#endregion
|
|
540
|
-
export {
|
|
370
|
+
export { MapiStory, StoryCreate, StoryUpdate };
|
|
541
371
|
//# sourceMappingURL=_internal.gen.d.cts.map
|
|
@@ -1,174 +1,4 @@
|
|
|
1
1
|
//#region src/generated/mapi/_internal.gen.d.ts
|
|
2
|
-
type ComponentCreate = {
|
|
3
|
-
/**
|
|
4
|
-
* Name of the component
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* Human-readable display name
|
|
9
|
-
*/
|
|
10
|
-
display_name?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Component description
|
|
13
|
-
*/
|
|
14
|
-
description?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Preview template HTML
|
|
17
|
-
*/
|
|
18
|
-
preview_tmpl?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Component image URL
|
|
21
|
-
*/
|
|
22
|
-
image?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Field used for preview
|
|
25
|
-
*/
|
|
26
|
-
preview_field?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Whether this component can be used as a root component
|
|
29
|
-
*/
|
|
30
|
-
is_root?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Whether this component can be nested inside other components
|
|
33
|
-
*/
|
|
34
|
-
is_nestable?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Default preset ID
|
|
37
|
-
*/
|
|
38
|
-
preset_id?: number;
|
|
39
|
-
/**
|
|
40
|
-
* UUID
|
|
41
|
-
*/
|
|
42
|
-
component_group_uuid?: string;
|
|
43
|
-
/**
|
|
44
|
-
* Component color for UI display
|
|
45
|
-
*/
|
|
46
|
-
color?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Component icon name
|
|
49
|
-
*/
|
|
50
|
-
icon?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Asset preview URL for content type
|
|
53
|
-
*/
|
|
54
|
-
content_type_asset_preview?: string;
|
|
55
|
-
/**
|
|
56
|
-
* List of internal tag IDs
|
|
57
|
-
*/
|
|
58
|
-
internal_tag_ids?: Array<number>;
|
|
59
|
-
/**
|
|
60
|
-
* Component field schema definition
|
|
61
|
-
*/
|
|
62
|
-
schema?: {
|
|
63
|
-
[key: string]: {
|
|
64
|
-
type?: 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group';
|
|
65
|
-
/**
|
|
66
|
-
* Human-readable field name
|
|
67
|
-
*/
|
|
68
|
-
display_name?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Whether this field is required
|
|
71
|
-
*/
|
|
72
|
-
required?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Whether this field is translatable
|
|
75
|
-
*/
|
|
76
|
-
translatable?: boolean;
|
|
77
|
-
[key: string]: unknown | 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group' | string | boolean | undefined;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Component metadata
|
|
82
|
-
*/
|
|
83
|
-
metadata?: {
|
|
84
|
-
[key: string]: unknown;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
type ComponentUpdate = {
|
|
88
|
-
/**
|
|
89
|
-
* Name of the component
|
|
90
|
-
*/
|
|
91
|
-
name?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Human-readable display name
|
|
94
|
-
*/
|
|
95
|
-
display_name?: string;
|
|
96
|
-
/**
|
|
97
|
-
* Component description
|
|
98
|
-
*/
|
|
99
|
-
description?: string;
|
|
100
|
-
/**
|
|
101
|
-
* Preview template HTML
|
|
102
|
-
*/
|
|
103
|
-
preview_tmpl?: string;
|
|
104
|
-
/**
|
|
105
|
-
* Component image URL
|
|
106
|
-
*/
|
|
107
|
-
image?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Field used for preview
|
|
110
|
-
*/
|
|
111
|
-
preview_field?: string;
|
|
112
|
-
/**
|
|
113
|
-
* Whether this component can be used as a root component
|
|
114
|
-
*/
|
|
115
|
-
is_root?: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Whether this component can be nested inside other components
|
|
118
|
-
*/
|
|
119
|
-
is_nestable?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Default preset ID
|
|
122
|
-
*/
|
|
123
|
-
preset_id?: number;
|
|
124
|
-
/**
|
|
125
|
-
* UUID
|
|
126
|
-
*/
|
|
127
|
-
component_group_uuid?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Component color for UI display
|
|
130
|
-
*/
|
|
131
|
-
color?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Component icon name
|
|
134
|
-
*/
|
|
135
|
-
icon?: string;
|
|
136
|
-
/**
|
|
137
|
-
* Asset preview URL for content type
|
|
138
|
-
*/
|
|
139
|
-
content_type_asset_preview?: string;
|
|
140
|
-
/**
|
|
141
|
-
* List of internal tag IDs
|
|
142
|
-
*/
|
|
143
|
-
internal_tag_ids?: Array<number>;
|
|
144
|
-
/**
|
|
145
|
-
* Component field schema definition
|
|
146
|
-
*/
|
|
147
|
-
schema?: {
|
|
148
|
-
[key: string]: {
|
|
149
|
-
type?: 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group';
|
|
150
|
-
/**
|
|
151
|
-
* Human-readable field name
|
|
152
|
-
*/
|
|
153
|
-
display_name?: string;
|
|
154
|
-
/**
|
|
155
|
-
* Whether this field is required
|
|
156
|
-
*/
|
|
157
|
-
required?: boolean;
|
|
158
|
-
/**
|
|
159
|
-
* Whether this field is translatable
|
|
160
|
-
*/
|
|
161
|
-
translatable?: boolean;
|
|
162
|
-
[key: string]: unknown | 'bloks' | 'text' | 'textarea' | 'richtext' | 'markdown' | 'number' | 'datetime' | 'boolean' | 'options' | 'option' | 'asset' | 'multiasset' | 'multilink' | 'table' | 'section' | 'commerce' | 'custom' | 'image' | 'file' | 'tab' | 'link' | 'group' | string | boolean | undefined;
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Component metadata
|
|
167
|
-
*/
|
|
168
|
-
metadata?: {
|
|
169
|
-
[key: string]: unknown;
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
2
|
type MapiStory = {
|
|
173
3
|
name: string;
|
|
174
4
|
/**
|
|
@@ -537,5 +367,5 @@ type Stage = {
|
|
|
537
367
|
created_at: string;
|
|
538
368
|
};
|
|
539
369
|
//#endregion
|
|
540
|
-
export {
|
|
370
|
+
export { MapiStory, StoryCreate, StoryUpdate };
|
|
541
371
|
//# sourceMappingURL=_internal.gen.d.mts.map
|