@remkoj/optimizely-cms-api 5.1.5 → 6.0.0-pre10
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/README.md +3 -5
- package/dist/api-client.d.ts +70 -11
- package/dist/api-client.js +208 -48
- package/dist/client/client/client.gen.d.ts +2 -0
- package/dist/client/client/client.gen.js +208 -0
- package/dist/client/client/index.d.ts +8 -0
- package/dist/client/client/index.js +17 -0
- package/dist/client/client/types.gen.d.ts +124 -0
- package/dist/client/{core/ApiRequestOptions.js → client/types.gen.js} +1 -0
- package/dist/client/client/utils.gen.d.ts +33 -0
- package/dist/client/client/utils.gen.js +242 -0
- package/dist/client/client.gen.d.ts +12 -0
- package/dist/client/client.gen.js +9 -0
- package/dist/client/core/auth.gen.d.ts +18 -0
- package/dist/client/core/auth.gen.js +18 -0
- package/dist/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/client/core/bodySerializer.gen.js +60 -0
- package/dist/client/core/params.gen.d.ts +33 -0
- package/dist/client/core/params.gen.js +92 -0
- package/dist/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/client/core/pathSerializer.gen.js +123 -0
- package/dist/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/client/core/queryKeySerializer.gen.js +105 -0
- package/dist/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/client/core/serverSentEvents.gen.js +139 -0
- package/dist/client/core/types.gen.d.ts +78 -0
- package/dist/client/core/{ApiResult.js → types.gen.js} +1 -0
- package/dist/client/core/utils.gen.d.ts +19 -0
- package/dist/client/core/utils.gen.js +93 -0
- package/dist/client/index.d.ts +4 -78
- package/dist/client/index.js +18 -46
- package/dist/client/sdk.gen.d.ts +117 -0
- package/dist/client/sdk.gen.js +251 -0
- package/dist/client/transformers.gen.d.ts +18 -0
- package/dist/client/transformers.gen.js +157 -0
- package/dist/client/types.gen.d.ts +1285 -0
- package/dist/client/{models/BooleanProperty.js → types.gen.js} +1 -0
- package/dist/client-config.d.ts +5 -0
- package/dist/client-config.js +55 -0
- package/dist/config.d.ts +5 -2
- package/dist/config.js +26 -18
- package/dist/getaccesstoken.d.ts +1 -1
- package/dist/getaccesstoken.js +10 -9
- package/dist/index.d.ts +7 -6
- package/dist/index.js +15 -8
- package/dist/instance.client/client/client.gen.d.ts +2 -0
- package/dist/instance.client/client/client.gen.js +208 -0
- package/dist/instance.client/client/index.d.ts +8 -0
- package/dist/instance.client/client/index.js +17 -0
- package/dist/instance.client/client/types.gen.d.ts +124 -0
- package/dist/{client/models/BinaryProperty.js → instance.client/client/types.gen.js} +1 -0
- package/dist/instance.client/client/utils.gen.d.ts +33 -0
- package/dist/instance.client/client/utils.gen.js +242 -0
- package/dist/instance.client/client.gen.d.ts +12 -0
- package/dist/instance.client/client.gen.js +9 -0
- package/dist/instance.client/core/auth.gen.d.ts +18 -0
- package/dist/instance.client/core/auth.gen.js +18 -0
- package/dist/instance.client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/instance.client/core/bodySerializer.gen.js +60 -0
- package/dist/instance.client/core/params.gen.d.ts +33 -0
- package/dist/instance.client/core/params.gen.js +92 -0
- package/dist/instance.client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/instance.client/core/pathSerializer.gen.js +123 -0
- package/dist/instance.client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/instance.client/core/queryKeySerializer.gen.js +105 -0
- package/dist/instance.client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/instance.client/core/serverSentEvents.gen.js +139 -0
- package/dist/instance.client/core/types.gen.d.ts +78 -0
- package/dist/instance.client/core/types.gen.js +3 -0
- package/dist/instance.client/core/utils.gen.d.ts +19 -0
- package/dist/instance.client/core/utils.gen.js +93 -0
- package/dist/instance.client/index.d.ts +4 -0
- package/dist/instance.client/index.js +21 -0
- package/dist/instance.client/sdk.gen.d.ts +303 -0
- package/dist/instance.client/sdk.gen.js +699 -0
- package/dist/instance.client/transformers.gen.d.ts +48 -0
- package/dist/instance.client/transformers.gen.js +431 -0
- package/dist/instance.client/types.gen.d.ts +2838 -0
- package/dist/instance.client/types.gen.js +3 -0
- package/dist/types.d.ts +3 -1
- package/dist/types.js +1 -0
- package/dist/version.json +3 -3
- package/package.json +16 -11
- package/dist/client/CmsIntegrationApiClient.d.ts +0 -22
- package/dist/client/CmsIntegrationApiClient.js +0 -34
- package/dist/client/core/ApiError.d.ts +0 -10
- package/dist/client/core/ApiError.js +0 -15
- package/dist/client/core/ApiRequestOptions.d.ts +0 -13
- package/dist/client/core/ApiResult.d.ts +0 -7
- package/dist/client/core/BaseHttpRequest.d.ts +0 -8
- package/dist/client/core/BaseHttpRequest.js +0 -9
- package/dist/client/core/CancelablePromise.d.ts +0 -20
- package/dist/client/core/CancelablePromise.js +0 -116
- package/dist/client/core/FetchHttpRequest.d.ts +0 -14
- package/dist/client/core/FetchHttpRequest.js +0 -20
- package/dist/client/core/OpenAPI.d.ts +0 -16
- package/dist/client/core/OpenAPI.js +0 -14
- package/dist/client/core/request.d.ts +0 -30
- package/dist/client/core/request.js +0 -294
- package/dist/client/models/BinaryProperty.d.ts +0 -8
- package/dist/client/models/BooleanProperty.d.ts +0 -5
- package/dist/client/models/Changeset.d.ts +0 -26
- package/dist/client/models/Changeset.js +0 -2
- package/dist/client/models/ChangesetItem.d.ts +0 -11
- package/dist/client/models/ChangesetItem.js +0 -2
- package/dist/client/models/ChangesetItemPage.d.ts +0 -19
- package/dist/client/models/ChangesetItemPage.js +0 -2
- package/dist/client/models/ChangesetPage.d.ts +0 -19
- package/dist/client/models/ChangesetPage.js +0 -2
- package/dist/client/models/ComponentListItem.d.ts +0 -10
- package/dist/client/models/ComponentListItem.js +0 -2
- package/dist/client/models/ComponentProperty.d.ts +0 -10
- package/dist/client/models/ComponentProperty.js +0 -2
- package/dist/client/models/CompositionBehavior.d.ts +0 -7
- package/dist/client/models/CompositionBehavior.js +0 -15
- package/dist/client/models/ContentBaseType.d.ts +0 -14
- package/dist/client/models/ContentBaseType.js +0 -22
- package/dist/client/models/ContentComponent.d.ts +0 -30
- package/dist/client/models/ContentComponent.js +0 -2
- package/dist/client/models/ContentItem.d.ts +0 -60
- package/dist/client/models/ContentItem.js +0 -2
- package/dist/client/models/ContentItemListWithContentTypes.d.ts +0 -27
- package/dist/client/models/ContentItemListWithContentTypes.js +0 -2
- package/dist/client/models/ContentItemPage.d.ts +0 -19
- package/dist/client/models/ContentItemPage.js +0 -2
- package/dist/client/models/ContentItemWithContentTypes.d.ts +0 -12
- package/dist/client/models/ContentItemWithContentTypes.js +0 -2
- package/dist/client/models/ContentListItem.d.ts +0 -14
- package/dist/client/models/ContentListItem.js +0 -2
- package/dist/client/models/ContentLocaleInfo.d.ts +0 -19
- package/dist/client/models/ContentLocaleInfo.js +0 -2
- package/dist/client/models/ContentMetadata.d.ts +0 -38
- package/dist/client/models/ContentMetadata.js +0 -2
- package/dist/client/models/ContentMetadataPage.d.ts +0 -19
- package/dist/client/models/ContentMetadataPage.js +0 -2
- package/dist/client/models/ContentProperty.d.ts +0 -14
- package/dist/client/models/ContentProperty.js +0 -2
- package/dist/client/models/ContentReference.d.ts +0 -17
- package/dist/client/models/ContentReference.js +0 -2
- package/dist/client/models/ContentReferenceListItem.d.ts +0 -14
- package/dist/client/models/ContentReferenceListItem.js +0 -2
- package/dist/client/models/ContentReferenceProperty.d.ts +0 -14
- package/dist/client/models/ContentReferenceProperty.js +0 -2
- package/dist/client/models/ContentType.d.ts +0 -84
- package/dist/client/models/ContentType.js +0 -2
- package/dist/client/models/ContentTypeFeature.d.ts +0 -10
- package/dist/client/models/ContentTypeFeature.js +0 -18
- package/dist/client/models/ContentTypePage.d.ts +0 -19
- package/dist/client/models/ContentTypePage.js +0 -2
- package/dist/client/models/ContentTypeProperty.d.ts +0 -47
- package/dist/client/models/ContentTypeProperty.js +0 -2
- package/dist/client/models/ContentTypeUsage.d.ts +0 -7
- package/dist/client/models/ContentTypeUsage.js +0 -15
- package/dist/client/models/CopyContentOptions.d.ts +0 -21
- package/dist/client/models/CopyContentOptions.js +0 -2
- package/dist/client/models/DateTimeListItem.d.ts +0 -14
- package/dist/client/models/DateTimeListItem.js +0 -2
- package/dist/client/models/DateTimeProperty.d.ts +0 -14
- package/dist/client/models/DateTimeProperty.js +0 -2
- package/dist/client/models/DisplaySetting.d.ts +0 -22
- package/dist/client/models/DisplaySetting.js +0 -2
- package/dist/client/models/DisplaySettingChoice.d.ts +0 -13
- package/dist/client/models/DisplaySettingChoice.js +0 -2
- package/dist/client/models/DisplayTemplate.d.ts +0 -49
- package/dist/client/models/DisplayTemplate.js +0 -2
- package/dist/client/models/DisplayTemplatePage.d.ts +0 -19
- package/dist/client/models/DisplayTemplatePage.js +0 -2
- package/dist/client/models/DoubleEnumerationSettings.d.ts +0 -10
- package/dist/client/models/DoubleEnumerationSettings.js +0 -2
- package/dist/client/models/DoubleEnumerationValue.d.ts +0 -13
- package/dist/client/models/DoubleEnumerationValue.js +0 -2
- package/dist/client/models/FloatListItem.d.ts +0 -16
- package/dist/client/models/FloatListItem.js +0 -2
- package/dist/client/models/FloatProperty.d.ts +0 -16
- package/dist/client/models/FloatProperty.js +0 -2
- package/dist/client/models/ImageDescriptor.d.ts +0 -17
- package/dist/client/models/ImageDescriptor.js +0 -2
- package/dist/client/models/IndexingType.d.ts +0 -8
- package/dist/client/models/IndexingType.js +0 -16
- package/dist/client/models/Int32EnumerationSettings.d.ts +0 -10
- package/dist/client/models/Int32EnumerationSettings.js +0 -2
- package/dist/client/models/Int32EnumerationValue.d.ts +0 -13
- package/dist/client/models/Int32EnumerationValue.js +0 -2
- package/dist/client/models/IntegerListItem.d.ts +0 -16
- package/dist/client/models/IntegerListItem.js +0 -2
- package/dist/client/models/IntegerProperty.d.ts +0 -16
- package/dist/client/models/IntegerProperty.js +0 -2
- package/dist/client/models/JsonStringProperty.d.ts +0 -5
- package/dist/client/models/JsonStringProperty.js +0 -2
- package/dist/client/models/ListProperty.d.ts +0 -26
- package/dist/client/models/ListProperty.js +0 -2
- package/dist/client/models/ListPropertyItem.d.ts +0 -11
- package/dist/client/models/ListPropertyItem.js +0 -2
- package/dist/client/models/LocaleStatus.d.ts +0 -7
- package/dist/client/models/LocaleStatus.js +0 -15
- package/dist/client/models/OauthToken.d.ts +0 -18
- package/dist/client/models/OauthToken.js +0 -2
- package/dist/client/models/OauthTokenError.d.ts +0 -13
- package/dist/client/models/OauthTokenError.js +0 -2
- package/dist/client/models/OauthTokenRequest.d.ts +0 -21
- package/dist/client/models/OauthTokenRequest.js +0 -2
- package/dist/client/models/ProblemDetails.d.ts +0 -1
- package/dist/client/models/ProblemDetails.js +0 -2
- package/dist/client/models/PropertyDataType.d.ts +0 -18
- package/dist/client/models/PropertyDataType.js +0 -26
- package/dist/client/models/PropertyFormat.d.ts +0 -37
- package/dist/client/models/PropertyFormat.js +0 -2
- package/dist/client/models/PropertyFormatPage.d.ts +0 -19
- package/dist/client/models/PropertyFormatPage.js +0 -2
- package/dist/client/models/PropertyGroup.d.ts +0 -21
- package/dist/client/models/PropertyGroup.js +0 -2
- package/dist/client/models/PropertyGroupPage.d.ts +0 -19
- package/dist/client/models/PropertyGroupPage.js +0 -2
- package/dist/client/models/StringEnumerationSettings.d.ts +0 -10
- package/dist/client/models/StringEnumerationSettings.js +0 -2
- package/dist/client/models/StringEnumerationValue.d.ts +0 -13
- package/dist/client/models/StringEnumerationValue.js +0 -2
- package/dist/client/models/StringListItem.d.ts +0 -20
- package/dist/client/models/StringListItem.js +0 -2
- package/dist/client/models/StringProperty.d.ts +0 -20
- package/dist/client/models/StringProperty.js +0 -2
- package/dist/client/models/UrlListItem.d.ts +0 -5
- package/dist/client/models/UrlListItem.js +0 -2
- package/dist/client/models/UrlProperty.d.ts +0 -5
- package/dist/client/models/UrlProperty.js +0 -2
- package/dist/client/models/VersionStatus.d.ts +0 -12
- package/dist/client/models/VersionStatus.js +0 -20
- package/dist/client/services/ChangesetsService.d.ts +0 -105
- package/dist/client/services/ChangesetsService.js +0 -239
- package/dist/client/services/ContentService.d.ts +0 -172
- package/dist/client/services/ContentService.js +0 -409
- package/dist/client/services/ContentTypesService.d.ts +0 -66
- package/dist/client/services/ContentTypesService.js +0 -149
- package/dist/client/services/DisplayTemplatesService.d.ts +0 -60
- package/dist/client/services/DisplayTemplatesService.js +0 -135
- package/dist/client/services/OauthService.d.ts +0 -17
- package/dist/client/services/OauthService.js +0 -28
- package/dist/client/services/PropertyFormatsService.d.ts +0 -26
- package/dist/client/services/PropertyFormatsService.js +0 -53
- package/dist/client/services/PropertyGroupsService.d.ts +0 -61
- package/dist/client/services/PropertyGroupsService.js +0 -135
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ClientOptions, Config } from './client/client';
|
|
2
|
+
import { type CmsIntegrationApiOptions } from "./config";
|
|
3
|
+
type CreateConfig<T extends ClientOptions = ClientOptions> = (config?: Config<ClientOptions & T>, apiConfig?: CmsIntegrationApiOptions) => Config<Required<ClientOptions> & T>;
|
|
4
|
+
export declare const createClientConfig: CreateConfig;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClientConfig = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const getaccesstoken_1 = require("./getaccesstoken");
|
|
6
|
+
const createClientConfig = (config, apiConfig) => {
|
|
7
|
+
const envConfig = apiConfig || (0, config_1.readPartialEnvConfig)();
|
|
8
|
+
const baseUrl = config?.baseUrl && !config.baseUrl.startsWith('/') ? new URL(config.baseUrl) : envConfig?.base ? new URL(config?.baseUrl ?? '/', envConfig.base) : undefined;
|
|
9
|
+
// If we don't have a valid base URL just return the config as given
|
|
10
|
+
if (!baseUrl)
|
|
11
|
+
return { ...config };
|
|
12
|
+
if (!baseUrl.pathname.endsWith('/'))
|
|
13
|
+
baseUrl.pathname = baseUrl.pathname + '/';
|
|
14
|
+
if (envConfig.debug)
|
|
15
|
+
process.stdout.write(`⚪ [CMS API] Creating API-Client for ${baseUrl.href} as ${envConfig.actAs ?? envConfig.clientId}\n`);
|
|
16
|
+
const authBaseUrl = baseUrl.hostname === 'api.cms.optimizely.com' ?
|
|
17
|
+
new URL("/", baseUrl) :
|
|
18
|
+
baseUrl;
|
|
19
|
+
let clientToken = undefined;
|
|
20
|
+
const newClientConfig = {
|
|
21
|
+
security: [{
|
|
22
|
+
in: 'header',
|
|
23
|
+
name: 'Authorization',
|
|
24
|
+
scheme: 'bearer',
|
|
25
|
+
type: 'apiKey'
|
|
26
|
+
}],
|
|
27
|
+
auth: async (auth) => {
|
|
28
|
+
if (auth.type !== 'apiKey' || auth.scheme !== 'bearer') {
|
|
29
|
+
if (envConfig.debug)
|
|
30
|
+
console.error(`❌ [CMS API] Unsupported auth model`, auth);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (typeof (clientToken) !== 'string' || clientToken.length == 0) {
|
|
34
|
+
try {
|
|
35
|
+
const token = await (0, getaccesstoken_1.getAccessToken)(envConfig, authBaseUrl.href);
|
|
36
|
+
clientToken = token;
|
|
37
|
+
if (envConfig.debug)
|
|
38
|
+
console.log(`🔑 [CMS API] Using new token`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (envConfig.debug)
|
|
42
|
+
console.error(`❌ [CMS API] Error while resolving the Access Token`, error);
|
|
43
|
+
clientToken = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (envConfig.debug)
|
|
47
|
+
console.log(`🔑 [CMS API] Using previously generated token`);
|
|
48
|
+
return clientToken;
|
|
49
|
+
},
|
|
50
|
+
...config,
|
|
51
|
+
baseUrl: baseUrl.href,
|
|
52
|
+
};
|
|
53
|
+
return newClientConfig;
|
|
54
|
+
};
|
|
55
|
+
exports.createClientConfig = createClientConfig;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OptiCmsVersion } from './types';
|
|
2
2
|
export type CmsIntegrationApiOptions = {
|
|
3
|
-
base
|
|
3
|
+
base?: URL;
|
|
4
4
|
clientId?: string;
|
|
5
5
|
clientSecret?: string;
|
|
6
6
|
actAs?: string;
|
|
@@ -10,4 +10,7 @@ export type CmsIntegrationApiOptions = {
|
|
|
10
10
|
*/
|
|
11
11
|
cmsVersion?: OptiCmsVersion;
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
type ClientCredentials = 'clientId' | 'clientSecret' | 'cmsVersion';
|
|
14
|
+
export declare function readPartialEnvConfig(): CmsIntegrationApiOptions;
|
|
15
|
+
export declare function readEnvConfig(): Omit<CmsIntegrationApiOptions, ClientCredentials> & Pick<Required<CmsIntegrationApiOptions>, ClientCredentials>;
|
|
16
|
+
export {};
|
package/dist/config.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.readPartialEnvConfig = readPartialEnvConfig;
|
|
4
|
+
exports.readEnvConfig = readEnvConfig;
|
|
5
5
|
const types_1 = require("./types");
|
|
6
|
-
function
|
|
7
|
-
const cmsUrl = getOptional('OPTIMIZELY_CMS_URL'
|
|
8
|
-
const clientId =
|
|
9
|
-
const clientSecret =
|
|
6
|
+
function readPartialEnvConfig() {
|
|
7
|
+
const cmsUrl = getOptional('OPTIMIZELY_CMS_URL');
|
|
8
|
+
const clientId = getOptional('OPTIMIZELY_CMS_CLIENT_ID');
|
|
9
|
+
const clientSecret = getOptional('OPTIMIZELY_CMS_CLIENT_SECRET');
|
|
10
10
|
const actAs = getOptional('OPTIMIZELY_CMS_USER_ID');
|
|
11
11
|
const debug = getOptional('OPTIMIZELY_DEBUG', "0") == "1";
|
|
12
|
-
const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13], types_1.OptiCmsVersion.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13, types_1.OptiCmsVersion.CMSSAAS], types_1.OptiCmsVersion.CMSSAAS);
|
|
13
|
+
// Determine the base, if set by the config
|
|
14
|
+
let base;
|
|
15
|
+
if (cmsUrl) {
|
|
16
|
+
try {
|
|
17
|
+
base = new URL(cmsUrl.includes("://") ? cmsUrl : 'https://' + cmsUrl);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
throw new Error("Invalid Optimizely CMS URL provided");
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
if (debug)
|
|
24
|
-
console.log(`[Optimizely CMS API] Connecting to ${
|
|
24
|
+
console.log(`[Optimizely CMS API] Connecting to ${base || 'CMS API HOST'} as ${clientId ?? 'Anonymous'}`);
|
|
25
25
|
return {
|
|
26
|
-
base
|
|
26
|
+
base,
|
|
27
27
|
clientId,
|
|
28
28
|
clientSecret,
|
|
29
29
|
actAs,
|
|
@@ -31,6 +31,14 @@ function getCmsIntegrationApiConfigFromEnvironment() {
|
|
|
31
31
|
cmsVersion
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
function readEnvConfig() {
|
|
35
|
+
const partialConfig = readPartialEnvConfig();
|
|
36
|
+
if (!partialConfig.clientId)
|
|
37
|
+
throw new Error("The Client ID (OPTIMIZELY_CMS_CLIENT_ID) is a required environment variable");
|
|
38
|
+
if (!partialConfig.clientSecret)
|
|
39
|
+
throw new Error("The Client Secret (OPTIMIZELY_CMS_CLIENT_SECRET) is a required environment variable");
|
|
40
|
+
return partialConfig;
|
|
41
|
+
}
|
|
34
42
|
function getOptional(variable, defaultValue) {
|
|
35
43
|
const envValue = process.env[variable];
|
|
36
44
|
if (!envValue || envValue == "")
|
package/dist/getaccesstoken.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type CmsIntegrationApiOptions } from "./config";
|
|
2
|
-
export declare function getAccessToken(config?: CmsIntegrationApiOptions): Promise<string>;
|
|
2
|
+
export declare function getAccessToken(config?: CmsIntegrationApiOptions, baseUrl?: string): Promise<string>;
|
|
3
3
|
export default getAccessToken;
|
package/dist/getaccesstoken.js
CHANGED
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAccessToken = getAccessToken;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
|
-
const OpenAPI_1 = require("./client/core/OpenAPI");
|
|
6
|
-
const types_1 = require("./types");
|
|
7
5
|
function isErrorResponse(response) {
|
|
8
6
|
return typeof (response.error) == 'string';
|
|
9
7
|
}
|
|
10
|
-
async function getAccessToken(config) {
|
|
11
|
-
const options = config ?? (0, config_1.
|
|
12
|
-
|
|
8
|
+
async function getAccessToken(config, baseUrl) {
|
|
9
|
+
const options = config ?? (0, config_1.readEnvConfig)();
|
|
10
|
+
const authUrl = new URL(`oauth/token`, baseUrl ?? options.base ?? 'https://api.cms.optimizely.com/').href;
|
|
13
11
|
const headers = new Headers();
|
|
14
|
-
if (options.
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
if (!options.clientId || !options.clientSecret) {
|
|
13
|
+
if (options.debug)
|
|
14
|
+
console.log(`❌ [CMS API] Skipping authentication due to missing clientId or clientSecret`);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
headers.append('Authorization', `Basic ${base64Encode(`${options.clientId ?? ''}:${options.clientSecret ?? ''}`)}`);
|
|
17
18
|
headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
18
19
|
headers.append('Connection', 'close');
|
|
19
20
|
if (options.debug) {
|
|
20
21
|
console.log(`⚪ [CMS API] Using authentication endpoint: ${authUrl}`);
|
|
21
|
-
console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId
|
|
22
|
+
console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId ?? '-'}${options.actAs ? ", acting as " + options.actAs : ""}`);
|
|
22
23
|
}
|
|
23
24
|
const body = new URLSearchParams();
|
|
24
25
|
body.append("grant_type", "client_credentials");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export * from './config';
|
|
2
|
-
export * as IntegrationApi from './client';
|
|
3
|
-
export
|
|
4
|
-
export { ApiClient } from './api-client';
|
|
5
|
-
export { ApiClient as CmsIntegrationApiClient } from './api-client';
|
|
2
|
+
export * as IntegrationApi from './client/types.gen';
|
|
3
|
+
export * as Preview2IntegrationApi from './instance.client/types.gen';
|
|
4
|
+
export { ApiClient, ApiError, ApiClient as CoreClient, type ApiClientStatic, type CmsIntegrationApiClient } from './api-client';
|
|
6
5
|
export { OptiCmsVersion } from "./types";
|
|
7
6
|
import { type CmsIntegrationApiOptions } from './config';
|
|
8
|
-
import {
|
|
9
|
-
export
|
|
7
|
+
import { type CmsIntegrationApiClient } from './api-client';
|
|
8
|
+
export { readEnvConfig } from './config';
|
|
9
|
+
export type ApiClientInstance = CmsIntegrationApiClient;
|
|
10
10
|
export declare function createClient(config?: CmsIntegrationApiOptions): CmsIntegrationApiClient;
|
|
11
|
+
export declare function isClientInstance(value?: object): value is CmsIntegrationApiClient;
|
|
11
12
|
export declare enum ContentRoots {
|
|
12
13
|
/**
|
|
13
14
|
* The Global root node of the Content Tree
|
package/dist/index.js
CHANGED
|
@@ -36,21 +36,28 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ContentTypeKeys = exports.ContentRoots = exports.OptiCmsVersion = exports.
|
|
39
|
+
exports.ContentTypeKeys = exports.ContentRoots = exports.readEnvConfig = exports.OptiCmsVersion = exports.CoreClient = exports.ApiError = exports.ApiClient = exports.Preview2IntegrationApi = exports.IntegrationApi = void 0;
|
|
40
40
|
exports.createClient = createClient;
|
|
41
|
+
exports.isClientInstance = isClientInstance;
|
|
41
42
|
__exportStar(require("./config"), exports);
|
|
42
|
-
exports.IntegrationApi = __importStar(require("./client"));
|
|
43
|
-
|
|
44
|
-
Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return client_1.CmsIntegrationApiClient; } });
|
|
43
|
+
exports.IntegrationApi = __importStar(require("./client/types.gen"));
|
|
44
|
+
exports.Preview2IntegrationApi = __importStar(require("./instance.client/types.gen"));
|
|
45
45
|
var api_client_1 = require("./api-client");
|
|
46
46
|
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(exports, "
|
|
47
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_client_1.ApiError; } });
|
|
48
|
+
Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
|
|
49
49
|
var types_1 = require("./types");
|
|
50
50
|
Object.defineProperty(exports, "OptiCmsVersion", { enumerable: true, get: function () { return types_1.OptiCmsVersion; } });
|
|
51
|
-
const
|
|
51
|
+
const api_client_2 = require("./api-client");
|
|
52
|
+
var config_1 = require("./config");
|
|
53
|
+
Object.defineProperty(exports, "readEnvConfig", { enumerable: true, get: function () { return config_1.readEnvConfig; } });
|
|
52
54
|
function createClient(config) {
|
|
53
|
-
return new
|
|
55
|
+
return new api_client_2.ApiClient(config);
|
|
56
|
+
}
|
|
57
|
+
function isClientInstance(value) {
|
|
58
|
+
if (typeof value !== 'object' || value === null)
|
|
59
|
+
return false;
|
|
60
|
+
return typeof value['getInstanceInfo'] === 'function';
|
|
54
61
|
}
|
|
55
62
|
var ContentRoots;
|
|
56
63
|
(function (ContentRoots) {
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createClient = void 0;
|
|
5
|
+
const serverSentEvents_gen_1 = require("../core/serverSentEvents.gen");
|
|
6
|
+
const utils_gen_1 = require("../core/utils.gen");
|
|
7
|
+
const utils_gen_2 = require("./utils.gen");
|
|
8
|
+
const createClient = (config = {}) => {
|
|
9
|
+
let _config = (0, utils_gen_2.mergeConfigs)((0, utils_gen_2.createConfig)(), config);
|
|
10
|
+
const getConfig = () => ({ ..._config });
|
|
11
|
+
const setConfig = (config) => {
|
|
12
|
+
_config = (0, utils_gen_2.mergeConfigs)(_config, config);
|
|
13
|
+
return getConfig();
|
|
14
|
+
};
|
|
15
|
+
const interceptors = (0, utils_gen_2.createInterceptors)();
|
|
16
|
+
const beforeRequest = async (options) => {
|
|
17
|
+
const opts = {
|
|
18
|
+
..._config,
|
|
19
|
+
...options,
|
|
20
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
21
|
+
headers: (0, utils_gen_2.mergeHeaders)(_config.headers, options.headers),
|
|
22
|
+
serializedBody: undefined,
|
|
23
|
+
};
|
|
24
|
+
if (opts.security) {
|
|
25
|
+
await (0, utils_gen_2.setAuthParams)({
|
|
26
|
+
...opts,
|
|
27
|
+
security: opts.security,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (opts.requestValidator) {
|
|
31
|
+
await opts.requestValidator(opts);
|
|
32
|
+
}
|
|
33
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
34
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
35
|
+
}
|
|
36
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
37
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
38
|
+
opts.headers.delete('Content-Type');
|
|
39
|
+
}
|
|
40
|
+
const url = (0, utils_gen_2.buildUrl)(opts);
|
|
41
|
+
return { opts, url };
|
|
42
|
+
};
|
|
43
|
+
const request = async (options) => {
|
|
44
|
+
// @ts-expect-error
|
|
45
|
+
const { opts, url } = await beforeRequest(options);
|
|
46
|
+
const requestInit = {
|
|
47
|
+
redirect: 'follow',
|
|
48
|
+
...opts,
|
|
49
|
+
body: (0, utils_gen_1.getValidRequestBody)(opts),
|
|
50
|
+
};
|
|
51
|
+
let request = new Request(url, requestInit);
|
|
52
|
+
for (const fn of interceptors.request.fns) {
|
|
53
|
+
if (fn) {
|
|
54
|
+
request = await fn(request, opts);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
58
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
59
|
+
const _fetch = opts.fetch;
|
|
60
|
+
let response = await _fetch(request);
|
|
61
|
+
for (const fn of interceptors.response.fns) {
|
|
62
|
+
if (fn) {
|
|
63
|
+
response = await fn(response, request, opts);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const result = {
|
|
67
|
+
request,
|
|
68
|
+
response,
|
|
69
|
+
};
|
|
70
|
+
if (response.ok) {
|
|
71
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
72
|
+
? (0, utils_gen_2.getParseAs)(response.headers.get('Content-Type'))
|
|
73
|
+
: opts.parseAs) ?? 'json';
|
|
74
|
+
if (response.status === 204 ||
|
|
75
|
+
response.headers.get('Content-Length') === '0') {
|
|
76
|
+
let emptyData;
|
|
77
|
+
switch (parseAs) {
|
|
78
|
+
case 'arrayBuffer':
|
|
79
|
+
case 'blob':
|
|
80
|
+
case 'text':
|
|
81
|
+
emptyData = await response[parseAs]();
|
|
82
|
+
break;
|
|
83
|
+
case 'formData':
|
|
84
|
+
emptyData = new FormData();
|
|
85
|
+
break;
|
|
86
|
+
case 'stream':
|
|
87
|
+
emptyData = response.body;
|
|
88
|
+
break;
|
|
89
|
+
case 'json':
|
|
90
|
+
default:
|
|
91
|
+
emptyData = {};
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return opts.responseStyle === 'data'
|
|
95
|
+
? emptyData
|
|
96
|
+
: {
|
|
97
|
+
data: emptyData,
|
|
98
|
+
...result,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
let data;
|
|
102
|
+
switch (parseAs) {
|
|
103
|
+
case 'arrayBuffer':
|
|
104
|
+
case 'blob':
|
|
105
|
+
case 'formData':
|
|
106
|
+
case 'json':
|
|
107
|
+
case 'text':
|
|
108
|
+
data = await response[parseAs]();
|
|
109
|
+
break;
|
|
110
|
+
case 'stream':
|
|
111
|
+
return opts.responseStyle === 'data'
|
|
112
|
+
? response.body
|
|
113
|
+
: {
|
|
114
|
+
data: response.body,
|
|
115
|
+
...result,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (parseAs === 'json') {
|
|
119
|
+
if (opts.responseValidator) {
|
|
120
|
+
await opts.responseValidator(data);
|
|
121
|
+
}
|
|
122
|
+
if (opts.responseTransformer) {
|
|
123
|
+
data = await opts.responseTransformer(data);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return opts.responseStyle === 'data'
|
|
127
|
+
? data
|
|
128
|
+
: {
|
|
129
|
+
data,
|
|
130
|
+
...result,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const textError = await response.text();
|
|
134
|
+
let jsonError;
|
|
135
|
+
try {
|
|
136
|
+
jsonError = JSON.parse(textError);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// noop
|
|
140
|
+
}
|
|
141
|
+
const error = jsonError ?? textError;
|
|
142
|
+
let finalError = error;
|
|
143
|
+
for (const fn of interceptors.error.fns) {
|
|
144
|
+
if (fn) {
|
|
145
|
+
finalError = (await fn(error, response, request, opts));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
finalError = finalError || {};
|
|
149
|
+
if (opts.throwOnError) {
|
|
150
|
+
throw finalError;
|
|
151
|
+
}
|
|
152
|
+
// TODO: we probably want to return error and improve types
|
|
153
|
+
return opts.responseStyle === 'data'
|
|
154
|
+
? undefined
|
|
155
|
+
: {
|
|
156
|
+
error: finalError,
|
|
157
|
+
...result,
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
161
|
+
const makeSseFn = (method) => async (options) => {
|
|
162
|
+
const { opts, url } = await beforeRequest(options);
|
|
163
|
+
return (0, serverSentEvents_gen_1.createSseClient)({
|
|
164
|
+
...opts,
|
|
165
|
+
body: opts.body,
|
|
166
|
+
headers: opts.headers,
|
|
167
|
+
method,
|
|
168
|
+
onRequest: async (url, init) => {
|
|
169
|
+
let request = new Request(url, init);
|
|
170
|
+
for (const fn of interceptors.request.fns) {
|
|
171
|
+
if (fn) {
|
|
172
|
+
request = await fn(request, opts);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return request;
|
|
176
|
+
},
|
|
177
|
+
url,
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
buildUrl: utils_gen_2.buildUrl,
|
|
182
|
+
connect: makeMethodFn('CONNECT'),
|
|
183
|
+
delete: makeMethodFn('DELETE'),
|
|
184
|
+
get: makeMethodFn('GET'),
|
|
185
|
+
getConfig,
|
|
186
|
+
head: makeMethodFn('HEAD'),
|
|
187
|
+
interceptors,
|
|
188
|
+
options: makeMethodFn('OPTIONS'),
|
|
189
|
+
patch: makeMethodFn('PATCH'),
|
|
190
|
+
post: makeMethodFn('POST'),
|
|
191
|
+
put: makeMethodFn('PUT'),
|
|
192
|
+
request,
|
|
193
|
+
setConfig,
|
|
194
|
+
sse: {
|
|
195
|
+
connect: makeSseFn('CONNECT'),
|
|
196
|
+
delete: makeSseFn('DELETE'),
|
|
197
|
+
get: makeSseFn('GET'),
|
|
198
|
+
head: makeSseFn('HEAD'),
|
|
199
|
+
options: makeSseFn('OPTIONS'),
|
|
200
|
+
patch: makeSseFn('PATCH'),
|
|
201
|
+
post: makeSseFn('POST'),
|
|
202
|
+
put: makeSseFn('PUT'),
|
|
203
|
+
trace: makeSseFn('TRACE'),
|
|
204
|
+
},
|
|
205
|
+
trace: makeMethodFn('TRACE'),
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
exports.createClient = createClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export { createClient } from './client.gen';
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.mergeHeaders = exports.createConfig = exports.createClient = exports.serializeQueryKeyValue = exports.buildClientParams = exports.urlSearchParamsBodySerializer = exports.jsonBodySerializer = exports.formDataBodySerializer = void 0;
|
|
5
|
+
var bodySerializer_gen_1 = require("../core/bodySerializer.gen");
|
|
6
|
+
Object.defineProperty(exports, "formDataBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.formDataBodySerializer; } });
|
|
7
|
+
Object.defineProperty(exports, "jsonBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.jsonBodySerializer; } });
|
|
8
|
+
Object.defineProperty(exports, "urlSearchParamsBodySerializer", { enumerable: true, get: function () { return bodySerializer_gen_1.urlSearchParamsBodySerializer; } });
|
|
9
|
+
var params_gen_1 = require("../core/params.gen");
|
|
10
|
+
Object.defineProperty(exports, "buildClientParams", { enumerable: true, get: function () { return params_gen_1.buildClientParams; } });
|
|
11
|
+
var queryKeySerializer_gen_1 = require("../core/queryKeySerializer.gen");
|
|
12
|
+
Object.defineProperty(exports, "serializeQueryKeyValue", { enumerable: true, get: function () { return queryKeySerializer_gen_1.serializeQueryKeyValue; } });
|
|
13
|
+
var client_gen_1 = require("./client.gen");
|
|
14
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_gen_1.createClient; } });
|
|
15
|
+
var utils_gen_1 = require("./utils.gen");
|
|
16
|
+
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return utils_gen_1.createConfig; } });
|
|
17
|
+
Object.defineProperty(exports, "mergeHeaders", { enumerable: true, get: function () { return utils_gen_1.mergeHeaders; } });
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
6
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Base URL for all requests made by this client.
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: T['baseUrl'];
|
|
11
|
+
/**
|
|
12
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
13
|
+
* fetch instance.
|
|
14
|
+
*
|
|
15
|
+
* @default globalThis.fetch
|
|
16
|
+
*/
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/**
|
|
19
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
|
+
* options won't have any effect.
|
|
21
|
+
*
|
|
22
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
23
|
+
*/
|
|
24
|
+
next?: never;
|
|
25
|
+
/**
|
|
26
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
27
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
28
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
29
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
30
|
+
*
|
|
31
|
+
* @default 'auto'
|
|
32
|
+
*/
|
|
33
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
34
|
+
/**
|
|
35
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
36
|
+
*
|
|
37
|
+
* @default 'fields'
|
|
38
|
+
*/
|
|
39
|
+
responseStyle?: ResponseStyle;
|
|
40
|
+
/**
|
|
41
|
+
* Throw an error instead of returning it in the response?
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
throwOnError?: T['throwOnError'];
|
|
46
|
+
}
|
|
47
|
+
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
|
+
responseStyle: TResponseStyle;
|
|
49
|
+
throwOnError: ThrowOnError;
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
51
|
+
/**
|
|
52
|
+
* Any body that you want to add to your request.
|
|
53
|
+
*
|
|
54
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
55
|
+
*/
|
|
56
|
+
body?: unknown;
|
|
57
|
+
path?: Record<string, unknown>;
|
|
58
|
+
query?: Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Security mechanism(s) to use for the request.
|
|
61
|
+
*/
|
|
62
|
+
security?: ReadonlyArray<Auth>;
|
|
63
|
+
url: Url;
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
serializedBody?: string;
|
|
67
|
+
}
|
|
68
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
69
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
|
+
request: Request;
|
|
71
|
+
response: Response;
|
|
72
|
+
}> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
73
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
74
|
+
error: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
|
+
}) & {
|
|
79
|
+
request: Request;
|
|
80
|
+
response: Response;
|
|
81
|
+
}>;
|
|
82
|
+
export interface ClientOptions {
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
responseStyle?: ResponseStyle;
|
|
85
|
+
throwOnError?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
89
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
90
|
+
type BuildUrlFn = <TData extends {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
path?: Record<string, unknown>;
|
|
93
|
+
query?: Record<string, unknown>;
|
|
94
|
+
url: string;
|
|
95
|
+
}>(options: Pick<TData, 'url'> & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
97
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
101
|
+
* and the returned object will become the client's initial configuration.
|
|
102
|
+
*
|
|
103
|
+
* You may want to initialize your client this way instead of calling
|
|
104
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
105
|
+
* to ensure your client always has the correct values.
|
|
106
|
+
*/
|
|
107
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
108
|
+
export interface TDataShape {
|
|
109
|
+
body?: unknown;
|
|
110
|
+
headers?: unknown;
|
|
111
|
+
path?: unknown;
|
|
112
|
+
query?: unknown;
|
|
113
|
+
url: string;
|
|
114
|
+
}
|
|
115
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & Omit<TData, 'url'>;
|
|
117
|
+
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = TData extends {
|
|
118
|
+
body?: any;
|
|
119
|
+
} ? TData extends {
|
|
120
|
+
headers?: any;
|
|
121
|
+
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body' | 'headers' | 'url'> & TData : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body' | 'url'> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers'> : TData extends {
|
|
122
|
+
headers?: any;
|
|
123
|
+
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers' | 'url'> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'> : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> & TData;
|
|
124
|
+
export {};
|