@storyblok/management-api-client 0.2.1 → 0.2.2

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/index.cjs CHANGED
@@ -3,6 +3,7 @@ const require_error = require('./client/error.cjs');
3
3
  const require_client = require('./client/client.cjs');
4
4
  require('./client/index.cjs');
5
5
  const require_sdk_registry_generated = require('./sdk-registry.generated.cjs');
6
+ const require_normalize_asset_url = require('./utils/normalize-asset-url.cjs');
6
7
  const require_generated_users_types_gen = require('./generated/users/types.gen.cjs');
7
8
  const require_generated_stories_types_gen = require('./generated/stories/types.gen.cjs');
8
9
  const require_generated_spaces_types_gen = require('./generated/spaces/types.gen.cjs');
@@ -163,4 +164,5 @@ Object.defineProperty(exports, 'Users', {
163
164
  }
164
165
  });
165
166
  exports.createClient = require_client.createClient;
167
+ exports.normalizeAssetUrl = require_normalize_asset_url.normalizeAssetUrl;
166
168
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["sdkRegistry","createClient"],"sources":["../src/index.ts"],"sourcesContent":["// Import generated SDKs with shared client support\nimport { createClient } from './client';\nimport type { Client } from './client/types';\nimport { getManagementBaseUrl, type Region } from '@storyblok/region-helper';\nimport { sdkRegistry, SdkRegistryInstance } from './sdk-registry.generated';\n\ntype PersonalAccessToken = {\n accessToken: string;\n}\n\ntype OAuthToken = {\n oauthToken: string;\n}\n\nexport interface ManagementApiClientConfig<ThrowOnError extends boolean = false> {\n token: PersonalAccessToken | OAuthToken;\n region?: Region;\n baseUrl?: string; // Override for custom endpoints\n headers?: Record<string, string>;\n throwOnError?: ThrowOnError;\n}\n\nexport interface ManagementApiClient<ThrowOnError extends boolean = false> extends SdkRegistryInstance {}\nexport class ManagementApiClient<ThrowOnError extends boolean = false> {\n protected client: Client;\n protected config: ManagementApiClientConfig<ThrowOnError>;\n protected sdkCache: Record<string, Promise<any>> = {};\n\n constructor(config: ManagementApiClientConfig<ThrowOnError>) {\n this.config = config;\n this.client = createClientInstance(config);\n\n Object.entries(sdkRegistry).forEach(([name, Sdk]) => {\n Object.defineProperty(this, name, {\n get: () => new Sdk({ client: this.client as any }),\n enumerable: true,\n configurable: true\n });\n });\n }\n\n\n /**\n * @returns The client's interceptors\n * @example\n * client.interceptors.request.use((request, options) => {\n * console.log('Request:', request);\n * return request;\n * });\n */\n public get interceptors(): Client['interceptors'] {\n return this.client.interceptors;\n }\n\n /**\n * @param config - The configuration to set\n * @example\n * client.setConfig({ region: 'eu' });\n */\n setConfig(config: Partial<Omit<ManagementApiClientConfig, 'token'>>): void {\n const { region, baseUrl, headers } = config;\n \n if (headers) {\n this.client.setConfig({\n baseUrl: baseUrl || this.config.baseUrl,\n region: region || this.config.region!,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(this.config.token),\n ...headers\n }\n });\n }\n }\n\n /**\n * @param token - The token to set\n * @example\n * client.setToken({ accessToken: '123' });\n */\n setToken(token: PersonalAccessToken | OAuthToken): void {\n this.config.token = token;\n this.client.setConfig({\n region: this.config.region ?? \"eu\",\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...this.config.headers\n }\n });\n }\n}\n\n// Pure functions for client creation and setup\nfunction createClientInstance<ThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<ThrowOnError>\n): Client {\n const { token, region = \"eu\", baseUrl, headers = {}, throwOnError = false } = config;\n \n return createClient({\n baseUrl,\n region,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...headers\n },\n throwOnError: throwOnError ?? false\n });\n}\n\nfunction getAuthHeader(token: PersonalAccessToken | OAuthToken): Record<string, string> {\n return 'accessToken' in token ? {\n 'Authorization': token.accessToken\n } : {\n 'Authorization': token.oauthToken\n }\n}\n\n// Export client utilities\nexport { ClientError } from './client/error';\nexport { createClient } from './client';\nexport type { Client } from './client/types';\n\n// Export all generated types\nexport * from './types.generated';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,IAAa,sBAAb,MAAuE;CACrE,AAAU;CACV,AAAU;CACV,AAAU,WAAyC,EAAE;CAErD,YAAY,QAAiD;AAC3D,OAAK,SAAS;AACd,OAAK,SAAS,qBAAqB,OAAO;AAE1C,SAAO,QAAQA,2CAAY,CAAC,SAAS,CAAC,MAAM,SAAS;AACnD,UAAO,eAAe,MAAM,MAAM;IAChC,WAAW,IAAI,IAAI,EAAE,QAAQ,KAAK,QAAe,CAAC;IAClD,YAAY;IACZ,cAAc;IACf,CAAC;IACF;;;;;;;;;;CAYJ,IAAW,eAAuC;AAChD,SAAO,KAAK,OAAO;;;;;;;CAQrB,UAAU,QAAiE;EACzE,MAAM,EAAE,QAAQ,SAAS,YAAY;AAErC,MAAI,QACF,MAAK,OAAO,UAAU;GACpB,SAAS,WAAW,KAAK,OAAO;GAChC,QAAQ,UAAU,KAAK,OAAO;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,KAAK,OAAO,MAAM;IACnC,GAAG;IACJ;GACF,CAAC;;;;;;;CASN,SAAS,OAA+C;AACtD,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,UAAU;GACpB,QAAQ,KAAK,OAAO,UAAU;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,MAAM;IACvB,GAAG,KAAK,OAAO;IAChB;GACF,CAAC;;;AAKN,SAAS,qBACP,QACQ;CACR,MAAM,EAAE,OAAO,SAAS,MAAM,SAAS,UAAU,EAAE,EAAE,eAAe,UAAU;AAE9E,QAAOC,4BAAa;EAClB;EACA;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,cAAc,MAAM;GACvB,GAAG;GACJ;EACD,cAAc,gBAAgB;EAC/B,CAAC;;AAGJ,SAAS,cAAc,OAAiE;AACtF,QAAO,iBAAiB,QAAQ,EAC9B,iBAAiB,MAAM,aACxB,GAAG,EACF,iBAAiB,MAAM,YACxB"}
1
+ {"version":3,"file":"index.cjs","names":["sdkRegistry","createClient"],"sources":["../src/index.ts"],"sourcesContent":["// Import generated SDKs with shared client support\nimport { createClient } from './client';\nimport type { Client } from './client/types';\nimport { getManagementBaseUrl, type Region } from '@storyblok/region-helper';\nimport { sdkRegistry, SdkRegistryInstance } from './sdk-registry.generated';\n\ntype PersonalAccessToken = {\n accessToken: string;\n}\n\ntype OAuthToken = {\n oauthToken: string;\n}\n\nexport interface ManagementApiClientConfig<ThrowOnError extends boolean = false> {\n token: PersonalAccessToken | OAuthToken;\n region?: Region;\n baseUrl?: string; // Override for custom endpoints\n headers?: Record<string, string>;\n throwOnError?: ThrowOnError;\n}\n\nexport interface ManagementApiClient<ThrowOnError extends boolean = false> extends SdkRegistryInstance {}\nexport class ManagementApiClient<ThrowOnError extends boolean = false> {\n protected client: Client;\n protected config: ManagementApiClientConfig<ThrowOnError>;\n protected sdkCache: Record<string, Promise<any>> = {};\n\n constructor(config: ManagementApiClientConfig<ThrowOnError>) {\n this.config = config;\n this.client = createClientInstance(config);\n\n Object.entries(sdkRegistry).forEach(([name, Sdk]) => {\n Object.defineProperty(this, name, {\n get: () => new Sdk({ client: this.client as any }),\n enumerable: true,\n configurable: true\n });\n });\n }\n\n\n /**\n * @returns The client's interceptors\n * @example\n * client.interceptors.request.use((request, options) => {\n * console.log('Request:', request);\n * return request;\n * });\n */\n public get interceptors(): Client['interceptors'] {\n return this.client.interceptors;\n }\n\n /**\n * @param config - The configuration to set\n * @example\n * client.setConfig({ region: 'eu' });\n */\n setConfig(config: Partial<Omit<ManagementApiClientConfig, 'token'>>): void {\n const { region, baseUrl, headers } = config;\n \n if (headers) {\n this.client.setConfig({\n baseUrl: baseUrl || this.config.baseUrl,\n region: region || this.config.region!,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(this.config.token),\n ...headers\n }\n });\n }\n }\n\n /**\n * @param token - The token to set\n * @example\n * client.setToken({ accessToken: '123' });\n */\n setToken(token: PersonalAccessToken | OAuthToken): void {\n this.config.token = token;\n this.client.setConfig({\n region: this.config.region ?? \"eu\",\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...this.config.headers\n }\n });\n }\n}\n\n// Pure functions for client creation and setup\nfunction createClientInstance<ThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<ThrowOnError>\n): Client {\n const { token, region = \"eu\", baseUrl, headers = {}, throwOnError = false } = config;\n \n return createClient({\n baseUrl,\n region,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...headers\n },\n throwOnError: throwOnError ?? false\n });\n}\n\nfunction getAuthHeader(token: PersonalAccessToken | OAuthToken): Record<string, string> {\n return 'accessToken' in token ? {\n 'Authorization': token.accessToken\n } : {\n 'Authorization': token.oauthToken\n }\n}\n\n// Export client utilities\nexport { ClientError } from './client/error';\nexport { createClient } from './client';\nexport type { Client } from './client/types';\n\n// Export asset utilities\nexport { normalizeAssetUrl } from './utils/normalize-asset-url';\n\n// Export all generated types\nexport * from './types.generated';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,IAAa,sBAAb,MAAuE;CACrE,AAAU;CACV,AAAU;CACV,AAAU,WAAyC,EAAE;CAErD,YAAY,QAAiD;AAC3D,OAAK,SAAS;AACd,OAAK,SAAS,qBAAqB,OAAO;AAE1C,SAAO,QAAQA,2CAAY,CAAC,SAAS,CAAC,MAAM,SAAS;AACnD,UAAO,eAAe,MAAM,MAAM;IAChC,WAAW,IAAI,IAAI,EAAE,QAAQ,KAAK,QAAe,CAAC;IAClD,YAAY;IACZ,cAAc;IACf,CAAC;IACF;;;;;;;;;;CAYJ,IAAW,eAAuC;AAChD,SAAO,KAAK,OAAO;;;;;;;CAQrB,UAAU,QAAiE;EACzE,MAAM,EAAE,QAAQ,SAAS,YAAY;AAErC,MAAI,QACF,MAAK,OAAO,UAAU;GACpB,SAAS,WAAW,KAAK,OAAO;GAChC,QAAQ,UAAU,KAAK,OAAO;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,KAAK,OAAO,MAAM;IACnC,GAAG;IACJ;GACF,CAAC;;;;;;;CASN,SAAS,OAA+C;AACtD,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,UAAU;GACpB,QAAQ,KAAK,OAAO,UAAU;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,MAAM;IACvB,GAAG,KAAK,OAAO;IAChB;GACF,CAAC;;;AAKN,SAAS,qBACP,QACQ;CACR,MAAM,EAAE,OAAO,SAAS,MAAM,SAAS,UAAU,EAAE,EAAE,eAAe,UAAU;AAE9E,QAAOC,4BAAa;EAClB;EACA;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,cAAc,MAAM;GACvB,GAAG;GACJ;EACD,cAAc,gBAAgB;EAC/B,CAAC;;AAGJ,SAAS,cAAc,OAAiE;AACtF,QAAO,iBAAiB,QAAQ,EAC9B,iBAAiB,MAAM,aACxB,GAAG,EACF,iBAAiB,MAAM,YACxB"}
package/dist/index.d.cts CHANGED
@@ -13,6 +13,7 @@ import { Client } from "./client/types.cjs";
13
13
  import { SdkRegistryInstance } from "./sdk-registry.generated.cjs";
14
14
  import { ClientError } from "./client/error.cjs";
15
15
  import { createClient } from "./client/client.cjs";
16
+ import { normalizeAssetUrl } from "./utils/normalize-asset-url.cjs";
16
17
  import { Region } from "@storyblok/region-helper";
17
18
 
18
19
  //#region src/index.d.ts
@@ -58,5 +59,5 @@ declare class ManagementApiClient<ThrowOnError extends boolean = false> {
58
59
  setToken(token: PersonalAccessToken | OAuthToken): void;
59
60
  }
60
61
  //#endregion
61
- export { types_gen_d_exports as AssetFolders, types_gen_d_exports$1 as Assets, type Client, ClientError, types_gen_d_exports$2 as ComponentFolders, types_gen_d_exports$3 as Components, types_gen_d_exports$4 as DatasourceEntries, types_gen_d_exports$5 as Datasources, types_gen_d_exports$6 as InternalTags, ManagementApiClient, ManagementApiClientConfig, types_gen_d_exports$7 as Presets, types_gen_d_exports$8 as Spaces, types_gen_d_exports$9 as Stories, types_gen_d_exports$10 as Users, createClient };
62
+ export { types_gen_d_exports as AssetFolders, types_gen_d_exports$1 as Assets, type Client, ClientError, types_gen_d_exports$2 as ComponentFolders, types_gen_d_exports$3 as Components, types_gen_d_exports$4 as DatasourceEntries, types_gen_d_exports$5 as Datasources, types_gen_d_exports$6 as InternalTags, ManagementApiClient, ManagementApiClientConfig, types_gen_d_exports$7 as Presets, types_gen_d_exports$8 as Spaces, types_gen_d_exports$9 as Stories, types_gen_d_exports$10 as Users, createClient, normalizeAssetUrl };
62
63
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import { Client } from "./client/types.js";
13
13
  import { SdkRegistryInstance } from "./sdk-registry.generated.js";
14
14
  import { ClientError } from "./client/error.js";
15
15
  import { createClient } from "./client/client.js";
16
+ import { normalizeAssetUrl } from "./utils/normalize-asset-url.js";
16
17
  import { Region } from "@storyblok/region-helper";
17
18
 
18
19
  //#region src/index.d.ts
@@ -58,5 +59,5 @@ declare class ManagementApiClient<ThrowOnError extends boolean = false> {
58
59
  setToken(token: PersonalAccessToken | OAuthToken): void;
59
60
  }
60
61
  //#endregion
61
- export { types_gen_d_exports as AssetFolders, types_gen_d_exports$1 as Assets, type Client, ClientError, types_gen_d_exports$2 as ComponentFolders, types_gen_d_exports$3 as Components, types_gen_d_exports$4 as DatasourceEntries, types_gen_d_exports$5 as Datasources, types_gen_d_exports$6 as InternalTags, ManagementApiClient, ManagementApiClientConfig, types_gen_d_exports$7 as Presets, types_gen_d_exports$8 as Spaces, types_gen_d_exports$9 as Stories, types_gen_d_exports$10 as Users, createClient };
62
+ export { types_gen_d_exports as AssetFolders, types_gen_d_exports$1 as Assets, type Client, ClientError, types_gen_d_exports$2 as ComponentFolders, types_gen_d_exports$3 as Components, types_gen_d_exports$4 as DatasourceEntries, types_gen_d_exports$5 as Datasources, types_gen_d_exports$6 as InternalTags, ManagementApiClient, ManagementApiClientConfig, types_gen_d_exports$7 as Presets, types_gen_d_exports$8 as Spaces, types_gen_d_exports$9 as Stories, types_gen_d_exports$10 as Users, createClient, normalizeAssetUrl };
62
63
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { ClientError } from "./client/error.js";
2
2
  import { createClient } from "./client/client.js";
3
3
  import "./client/index.js";
4
4
  import { sdkRegistry } from "./sdk-registry.generated.js";
5
+ import { normalizeAssetUrl } from "./utils/normalize-asset-url.js";
5
6
  import { types_gen_exports as types_gen_exports$10 } from "./generated/users/types.gen.js";
6
7
  import { types_gen_exports as types_gen_exports$9 } from "./generated/stories/types.gen.js";
7
8
  import { types_gen_exports as types_gen_exports$8 } from "./generated/spaces/types.gen.js";
@@ -93,5 +94,5 @@ function getAuthHeader(token) {
93
94
  }
94
95
 
95
96
  //#endregion
96
- export { types_gen_exports as AssetFolders, types_gen_exports$1 as Assets, ClientError, types_gen_exports$2 as ComponentFolders, types_gen_exports$3 as Components, types_gen_exports$4 as DatasourceEntries, types_gen_exports$5 as Datasources, types_gen_exports$6 as InternalTags, ManagementApiClient, types_gen_exports$7 as Presets, types_gen_exports$8 as Spaces, types_gen_exports$9 as Stories, types_gen_exports$10 as Users, createClient };
97
+ export { types_gen_exports as AssetFolders, types_gen_exports$1 as Assets, ClientError, types_gen_exports$2 as ComponentFolders, types_gen_exports$3 as Components, types_gen_exports$4 as DatasourceEntries, types_gen_exports$5 as Datasources, types_gen_exports$6 as InternalTags, ManagementApiClient, types_gen_exports$7 as Presets, types_gen_exports$8 as Spaces, types_gen_exports$9 as Stories, types_gen_exports$10 as Users, createClient, normalizeAssetUrl };
97
98
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Import generated SDKs with shared client support\nimport { createClient } from './client';\nimport type { Client } from './client/types';\nimport { getManagementBaseUrl, type Region } from '@storyblok/region-helper';\nimport { sdkRegistry, SdkRegistryInstance } from './sdk-registry.generated';\n\ntype PersonalAccessToken = {\n accessToken: string;\n}\n\ntype OAuthToken = {\n oauthToken: string;\n}\n\nexport interface ManagementApiClientConfig<ThrowOnError extends boolean = false> {\n token: PersonalAccessToken | OAuthToken;\n region?: Region;\n baseUrl?: string; // Override for custom endpoints\n headers?: Record<string, string>;\n throwOnError?: ThrowOnError;\n}\n\nexport interface ManagementApiClient<ThrowOnError extends boolean = false> extends SdkRegistryInstance {}\nexport class ManagementApiClient<ThrowOnError extends boolean = false> {\n protected client: Client;\n protected config: ManagementApiClientConfig<ThrowOnError>;\n protected sdkCache: Record<string, Promise<any>> = {};\n\n constructor(config: ManagementApiClientConfig<ThrowOnError>) {\n this.config = config;\n this.client = createClientInstance(config);\n\n Object.entries(sdkRegistry).forEach(([name, Sdk]) => {\n Object.defineProperty(this, name, {\n get: () => new Sdk({ client: this.client as any }),\n enumerable: true,\n configurable: true\n });\n });\n }\n\n\n /**\n * @returns The client's interceptors\n * @example\n * client.interceptors.request.use((request, options) => {\n * console.log('Request:', request);\n * return request;\n * });\n */\n public get interceptors(): Client['interceptors'] {\n return this.client.interceptors;\n }\n\n /**\n * @param config - The configuration to set\n * @example\n * client.setConfig({ region: 'eu' });\n */\n setConfig(config: Partial<Omit<ManagementApiClientConfig, 'token'>>): void {\n const { region, baseUrl, headers } = config;\n \n if (headers) {\n this.client.setConfig({\n baseUrl: baseUrl || this.config.baseUrl,\n region: region || this.config.region!,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(this.config.token),\n ...headers\n }\n });\n }\n }\n\n /**\n * @param token - The token to set\n * @example\n * client.setToken({ accessToken: '123' });\n */\n setToken(token: PersonalAccessToken | OAuthToken): void {\n this.config.token = token;\n this.client.setConfig({\n region: this.config.region ?? \"eu\",\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...this.config.headers\n }\n });\n }\n}\n\n// Pure functions for client creation and setup\nfunction createClientInstance<ThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<ThrowOnError>\n): Client {\n const { token, region = \"eu\", baseUrl, headers = {}, throwOnError = false } = config;\n \n return createClient({\n baseUrl,\n region,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...headers\n },\n throwOnError: throwOnError ?? false\n });\n}\n\nfunction getAuthHeader(token: PersonalAccessToken | OAuthToken): Record<string, string> {\n return 'accessToken' in token ? {\n 'Authorization': token.accessToken\n } : {\n 'Authorization': token.oauthToken\n }\n}\n\n// Export client utilities\nexport { ClientError } from './client/error';\nexport { createClient } from './client';\nexport type { Client } from './client/types';\n\n// Export all generated types\nexport * from './types.generated';\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,IAAa,sBAAb,MAAuE;CACrE,AAAU;CACV,AAAU;CACV,AAAU,WAAyC,EAAE;CAErD,YAAY,QAAiD;AAC3D,OAAK,SAAS;AACd,OAAK,SAAS,qBAAqB,OAAO;AAE1C,SAAO,QAAQ,YAAY,CAAC,SAAS,CAAC,MAAM,SAAS;AACnD,UAAO,eAAe,MAAM,MAAM;IAChC,WAAW,IAAI,IAAI,EAAE,QAAQ,KAAK,QAAe,CAAC;IAClD,YAAY;IACZ,cAAc;IACf,CAAC;IACF;;;;;;;;;;CAYJ,IAAW,eAAuC;AAChD,SAAO,KAAK,OAAO;;;;;;;CAQrB,UAAU,QAAiE;EACzE,MAAM,EAAE,QAAQ,SAAS,YAAY;AAErC,MAAI,QACF,MAAK,OAAO,UAAU;GACpB,SAAS,WAAW,KAAK,OAAO;GAChC,QAAQ,UAAU,KAAK,OAAO;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,KAAK,OAAO,MAAM;IACnC,GAAG;IACJ;GACF,CAAC;;;;;;;CASN,SAAS,OAA+C;AACtD,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,UAAU;GACpB,QAAQ,KAAK,OAAO,UAAU;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,MAAM;IACvB,GAAG,KAAK,OAAO;IAChB;GACF,CAAC;;;AAKN,SAAS,qBACP,QACQ;CACR,MAAM,EAAE,OAAO,SAAS,MAAM,SAAS,UAAU,EAAE,EAAE,eAAe,UAAU;AAE9E,QAAO,aAAa;EAClB;EACA;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,cAAc,MAAM;GACvB,GAAG;GACJ;EACD,cAAc,gBAAgB;EAC/B,CAAC;;AAGJ,SAAS,cAAc,OAAiE;AACtF,QAAO,iBAAiB,QAAQ,EAC9B,iBAAiB,MAAM,aACxB,GAAG,EACF,iBAAiB,MAAM,YACxB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Import generated SDKs with shared client support\nimport { createClient } from './client';\nimport type { Client } from './client/types';\nimport { getManagementBaseUrl, type Region } from '@storyblok/region-helper';\nimport { sdkRegistry, SdkRegistryInstance } from './sdk-registry.generated';\n\ntype PersonalAccessToken = {\n accessToken: string;\n}\n\ntype OAuthToken = {\n oauthToken: string;\n}\n\nexport interface ManagementApiClientConfig<ThrowOnError extends boolean = false> {\n token: PersonalAccessToken | OAuthToken;\n region?: Region;\n baseUrl?: string; // Override for custom endpoints\n headers?: Record<string, string>;\n throwOnError?: ThrowOnError;\n}\n\nexport interface ManagementApiClient<ThrowOnError extends boolean = false> extends SdkRegistryInstance {}\nexport class ManagementApiClient<ThrowOnError extends boolean = false> {\n protected client: Client;\n protected config: ManagementApiClientConfig<ThrowOnError>;\n protected sdkCache: Record<string, Promise<any>> = {};\n\n constructor(config: ManagementApiClientConfig<ThrowOnError>) {\n this.config = config;\n this.client = createClientInstance(config);\n\n Object.entries(sdkRegistry).forEach(([name, Sdk]) => {\n Object.defineProperty(this, name, {\n get: () => new Sdk({ client: this.client as any }),\n enumerable: true,\n configurable: true\n });\n });\n }\n\n\n /**\n * @returns The client's interceptors\n * @example\n * client.interceptors.request.use((request, options) => {\n * console.log('Request:', request);\n * return request;\n * });\n */\n public get interceptors(): Client['interceptors'] {\n return this.client.interceptors;\n }\n\n /**\n * @param config - The configuration to set\n * @example\n * client.setConfig({ region: 'eu' });\n */\n setConfig(config: Partial<Omit<ManagementApiClientConfig, 'token'>>): void {\n const { region, baseUrl, headers } = config;\n \n if (headers) {\n this.client.setConfig({\n baseUrl: baseUrl || this.config.baseUrl,\n region: region || this.config.region!,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(this.config.token),\n ...headers\n }\n });\n }\n }\n\n /**\n * @param token - The token to set\n * @example\n * client.setToken({ accessToken: '123' });\n */\n setToken(token: PersonalAccessToken | OAuthToken): void {\n this.config.token = token;\n this.client.setConfig({\n region: this.config.region ?? \"eu\",\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...this.config.headers\n }\n });\n }\n}\n\n// Pure functions for client creation and setup\nfunction createClientInstance<ThrowOnError extends boolean = false>(\n config: ManagementApiClientConfig<ThrowOnError>\n): Client {\n const { token, region = \"eu\", baseUrl, headers = {}, throwOnError = false } = config;\n \n return createClient({\n baseUrl,\n region,\n headers: {\n 'Content-Type': 'application/json',\n ...getAuthHeader(token),\n ...headers\n },\n throwOnError: throwOnError ?? false\n });\n}\n\nfunction getAuthHeader(token: PersonalAccessToken | OAuthToken): Record<string, string> {\n return 'accessToken' in token ? {\n 'Authorization': token.accessToken\n } : {\n 'Authorization': token.oauthToken\n }\n}\n\n// Export client utilities\nexport { ClientError } from './client/error';\nexport { createClient } from './client';\nexport type { Client } from './client/types';\n\n// Export asset utilities\nexport { normalizeAssetUrl } from './utils/normalize-asset-url';\n\n// Export all generated types\nexport * from './types.generated';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,IAAa,sBAAb,MAAuE;CACrE,AAAU;CACV,AAAU;CACV,AAAU,WAAyC,EAAE;CAErD,YAAY,QAAiD;AAC3D,OAAK,SAAS;AACd,OAAK,SAAS,qBAAqB,OAAO;AAE1C,SAAO,QAAQ,YAAY,CAAC,SAAS,CAAC,MAAM,SAAS;AACnD,UAAO,eAAe,MAAM,MAAM;IAChC,WAAW,IAAI,IAAI,EAAE,QAAQ,KAAK,QAAe,CAAC;IAClD,YAAY;IACZ,cAAc;IACf,CAAC;IACF;;;;;;;;;;CAYJ,IAAW,eAAuC;AAChD,SAAO,KAAK,OAAO;;;;;;;CAQrB,UAAU,QAAiE;EACzE,MAAM,EAAE,QAAQ,SAAS,YAAY;AAErC,MAAI,QACF,MAAK,OAAO,UAAU;GACpB,SAAS,WAAW,KAAK,OAAO;GAChC,QAAQ,UAAU,KAAK,OAAO;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,KAAK,OAAO,MAAM;IACnC,GAAG;IACJ;GACF,CAAC;;;;;;;CASN,SAAS,OAA+C;AACtD,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,UAAU;GACpB,QAAQ,KAAK,OAAO,UAAU;GAC9B,SAAS;IACP,gBAAgB;IAChB,GAAG,cAAc,MAAM;IACvB,GAAG,KAAK,OAAO;IAChB;GACF,CAAC;;;AAKN,SAAS,qBACP,QACQ;CACR,MAAM,EAAE,OAAO,SAAS,MAAM,SAAS,UAAU,EAAE,EAAE,eAAe,UAAU;AAE9E,QAAO,aAAa;EAClB;EACA;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,cAAc,MAAM;GACvB,GAAG;GACJ;EACD,cAAc,gBAAgB;EAC/B,CAAC;;AAGJ,SAAS,cAAc,OAAiE;AACtF,QAAO,iBAAiB,QAAQ,EAC9B,iBAAiB,MAAM,aACxB,GAAG,EACF,iBAAiB,MAAM,YACxB"}
@@ -0,0 +1,21 @@
1
+
2
+ //#region src/utils/normalize-asset-url.ts
3
+ /**
4
+ * Normalizes an S3 asset URL to a Storyblok CDN URL.
5
+ *
6
+ * The MAPI returns asset filenames pointing to the raw S3 origin
7
+ * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the
8
+ * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not
9
+ * support the Storyblok Image Service (`/m/...`), which breaks image
10
+ * optimization in frontends.
11
+ *
12
+ * Works for all regions because the regional CDN domain
13
+ * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,
14
+ * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket
15
+ * name in the path.
16
+ */
17
+ const normalizeAssetUrl = (url) => url.replace(/^https?:\/\/s3\.amazonaws\.com\//, "https://");
18
+
19
+ //#endregion
20
+ exports.normalizeAssetUrl = normalizeAssetUrl;
21
+ //# sourceMappingURL=normalize-asset-url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-asset-url.cjs","names":[],"sources":["../../src/utils/normalize-asset-url.ts"],"sourcesContent":["/**\n * Normalizes an S3 asset URL to a Storyblok CDN URL.\n *\n * The MAPI returns asset filenames pointing to the raw S3 origin\n * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the\n * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not\n * support the Storyblok Image Service (`/m/...`), which breaks image\n * optimization in frontends.\n *\n * Works for all regions because the regional CDN domain\n * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,\n * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket\n * name in the path.\n */\nexport const normalizeAssetUrl = (url: string): string =>\n url.replace(/^https?:\\/\\/s3\\.amazonaws\\.com\\//, 'https://');\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAa,qBAAqB,QAChC,IAAI,QAAQ,oCAAoC,WAAW"}
@@ -0,0 +1,19 @@
1
+ //#region src/utils/normalize-asset-url.d.ts
2
+ /**
3
+ * Normalizes an S3 asset URL to a Storyblok CDN URL.
4
+ *
5
+ * The MAPI returns asset filenames pointing to the raw S3 origin
6
+ * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the
7
+ * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not
8
+ * support the Storyblok Image Service (`/m/...`), which breaks image
9
+ * optimization in frontends.
10
+ *
11
+ * Works for all regions because the regional CDN domain
12
+ * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,
13
+ * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket
14
+ * name in the path.
15
+ */
16
+ declare const normalizeAssetUrl: (url: string) => string;
17
+ //#endregion
18
+ export { normalizeAssetUrl };
19
+ //# sourceMappingURL=normalize-asset-url.d.cts.map
@@ -0,0 +1,19 @@
1
+ //#region src/utils/normalize-asset-url.d.ts
2
+ /**
3
+ * Normalizes an S3 asset URL to a Storyblok CDN URL.
4
+ *
5
+ * The MAPI returns asset filenames pointing to the raw S3 origin
6
+ * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the
7
+ * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not
8
+ * support the Storyblok Image Service (`/m/...`), which breaks image
9
+ * optimization in frontends.
10
+ *
11
+ * Works for all regions because the regional CDN domain
12
+ * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,
13
+ * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket
14
+ * name in the path.
15
+ */
16
+ declare const normalizeAssetUrl: (url: string) => string;
17
+ //#endregion
18
+ export { normalizeAssetUrl };
19
+ //# sourceMappingURL=normalize-asset-url.d.ts.map
@@ -0,0 +1,20 @@
1
+ //#region src/utils/normalize-asset-url.ts
2
+ /**
3
+ * Normalizes an S3 asset URL to a Storyblok CDN URL.
4
+ *
5
+ * The MAPI returns asset filenames pointing to the raw S3 origin
6
+ * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the
7
+ * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not
8
+ * support the Storyblok Image Service (`/m/...`), which breaks image
9
+ * optimization in frontends.
10
+ *
11
+ * Works for all regions because the regional CDN domain
12
+ * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,
13
+ * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket
14
+ * name in the path.
15
+ */
16
+ const normalizeAssetUrl = (url) => url.replace(/^https?:\/\/s3\.amazonaws\.com\//, "https://");
17
+
18
+ //#endregion
19
+ export { normalizeAssetUrl };
20
+ //# sourceMappingURL=normalize-asset-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-asset-url.js","names":[],"sources":["../../src/utils/normalize-asset-url.ts"],"sourcesContent":["/**\n * Normalizes an S3 asset URL to a Storyblok CDN URL.\n *\n * The MAPI returns asset filenames pointing to the raw S3 origin\n * (e.g. `https://s3.amazonaws.com/a.storyblok.com/f/...`) instead of the\n * CloudFront CDN (e.g. `https://a.storyblok.com/f/...`). The S3 URL does not\n * support the Storyblok Image Service (`/m/...`), which breaks image\n * optimization in frontends.\n *\n * Works for all regions because the regional CDN domain\n * (`a.storyblok.com`, `a-us.storyblok.com`, `a-ap.storyblok.com`,\n * `a-ca.storyblok.com`, `a.storyblokchina.cn`) is embedded as the S3 bucket\n * name in the path.\n */\nexport const normalizeAssetUrl = (url: string): string =>\n url.replace(/^https?:\\/\\/s3\\.amazonaws\\.com\\//, 'https://');\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,qBAAqB,QAChC,IAAI,QAAQ,oCAAoC,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/management-api-client",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "Storyblok Management API Client",
6
6
  "main": "./dist/index.cjs",