@remkoj/optimizely-cms-api 6.0.0-pre1 → 6.0.0-pre11
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/LICENSE +12 -12
- package/README.md +3 -5
- package/dist/api-client.d.ts +23 -7
- package/dist/api-client.js +97 -37
- package/dist/client/client/{client.d.ts → client.gen.d.ts} +1 -1
- package/dist/client/client/client.gen.js +208 -0
- package/dist/client/client/index.d.ts +8 -7
- package/dist/client/client/index.js +15 -12
- package/dist/client/client/{types.d.ts → types.gen.d.ts} +18 -13
- package/dist/client/{core/types.js → client/types.gen.js} +1 -0
- package/dist/client/client/{utils.d.ts → utils.gen.d.ts} +9 -21
- package/dist/client/client/{utils.js → utils.gen.js} +68 -122
- package/dist/client/client.gen.d.ts +3 -3
- package/dist/client/client.gen.js +1 -1
- package/dist/client/core/{auth.js → auth.gen.js} +1 -0
- package/dist/client/core/{bodySerializer.d.ts → bodySerializer.gen.d.ts} +13 -5
- package/dist/client/core/{bodySerializer.js → bodySerializer.gen.js} +4 -0
- package/dist/client/core/{params.d.ts → params.gen.d.ts} +10 -0
- package/dist/client/core/{params.js → params.gen.js} +1 -0
- package/dist/client/core/{pathSerializer.js → pathSerializer.gen.js} +1 -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.d.ts → types.gen.d.ts} +19 -14
- package/dist/client/{client/types.js → core/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 +1 -1
- package/dist/client/index.js +1 -2
- package/dist/client/sdk.gen.d.ts +28 -167
- package/dist/client/sdk.gen.js +34 -421
- package/dist/client/transformers.gen.d.ts +8 -24
- package/dist/client/transformers.gen.js +76 -192
- package/dist/client/types.gen.d.ts +511 -2167
- package/dist/client/types.gen.js +0 -84
- package/dist/client-config.d.ts +5 -2
- package/dist/client-config.js +42 -14
- package/dist/config.d.ts +5 -2
- package/dist/config.js +26 -17
- package/dist/getaccesstoken.d.ts +1 -1
- package/dist/getaccesstoken.js +10 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.js +10 -1
- 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/instance.client/client/types.gen.js +3 -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 +8 -12
- package/dist/client/client/client.js +0 -147
- /package/dist/client/core/{auth.d.ts → auth.gen.d.ts} +0 -0
- /package/dist/client/core/{pathSerializer.d.ts → pathSerializer.gen.d.ts} +0 -0
package/dist/client/types.gen.js
CHANGED
|
@@ -1,87 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.VersionStatus = exports.PropertyDataType = exports.LocaleStatus = exports.IndexingType = exports.ContentTypeUsage = exports.ContentTypeFeature = exports.ContentBaseType = exports.CompositionBehavior = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Represent a Composition behavior for a ContentType.
|
|
7
|
-
*/
|
|
8
|
-
exports.CompositionBehavior = {
|
|
9
|
-
SECTION_ENABLED: 'sectionEnabled',
|
|
10
|
-
ELEMENT_ENABLED: 'elementEnabled'
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Represent the base type of a ContentType.
|
|
14
|
-
*/
|
|
15
|
-
exports.ContentBaseType = {
|
|
16
|
-
PAGE: 'page',
|
|
17
|
-
COMPONENT: 'component',
|
|
18
|
-
MEDIA: 'media',
|
|
19
|
-
IMAGE: 'image',
|
|
20
|
-
VIDEO: 'video',
|
|
21
|
-
FOLDER: 'folder',
|
|
22
|
-
EXPERIENCE: 'experience',
|
|
23
|
-
SECTION: 'section',
|
|
24
|
-
ELEMENT: 'element'
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Represent different features that a content type can have.
|
|
28
|
-
*/
|
|
29
|
-
exports.ContentTypeFeature = {
|
|
30
|
-
LOCALIZATION: 'localization',
|
|
31
|
-
VERSIONING: 'versioning',
|
|
32
|
-
PUBLISH_PERIOD: 'publishPeriod',
|
|
33
|
-
ROUTING: 'routing',
|
|
34
|
-
BINARY: 'binary'
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Represent the usage types for a ContentType.
|
|
38
|
-
*/
|
|
39
|
-
exports.ContentTypeUsage = {
|
|
40
|
-
PROPERTY: 'property',
|
|
41
|
-
INSTANCE: 'instance'
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Represents the indexing type of a content type property.
|
|
45
|
-
*/
|
|
46
|
-
exports.IndexingType = {
|
|
47
|
-
DISABLED: 'disabled',
|
|
48
|
-
QUERYABLE: 'queryable',
|
|
49
|
-
SEARCHABLE: 'searchable'
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Represent the different status values of a content locale.
|
|
53
|
-
*/
|
|
54
|
-
exports.LocaleStatus = {
|
|
55
|
-
DRAFT: 'draft',
|
|
56
|
-
PUBLISHED: 'published'
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Represent the basic type that a PropertyFormat
|
|
60
|
-
* is using for data storage and data transport.
|
|
61
|
-
*/
|
|
62
|
-
exports.PropertyDataType = {
|
|
63
|
-
STRING: 'string',
|
|
64
|
-
URL: 'url',
|
|
65
|
-
BOOLEAN: 'boolean',
|
|
66
|
-
INTEGER: 'integer',
|
|
67
|
-
FLOAT: 'float',
|
|
68
|
-
DATE_TIME: 'dateTime',
|
|
69
|
-
CONTENT_REFERENCE: 'contentReference',
|
|
70
|
-
CONTENT: 'content',
|
|
71
|
-
BINARY: 'binary',
|
|
72
|
-
JSON: 'json',
|
|
73
|
-
ARRAY: 'array',
|
|
74
|
-
COMPONENT: 'component'
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Represent the different status values of a content version.
|
|
78
|
-
*/
|
|
79
|
-
exports.VersionStatus = {
|
|
80
|
-
DRAFT: 'draft',
|
|
81
|
-
READY: 'ready',
|
|
82
|
-
PUBLISHED: 'published',
|
|
83
|
-
PREVIOUS: 'previous',
|
|
84
|
-
SCHEDULED: 'scheduled',
|
|
85
|
-
REJECTED: 'rejected',
|
|
86
|
-
IN_REVIEW: 'inReview'
|
|
87
|
-
};
|
package/dist/client-config.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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 {};
|
package/dist/client-config.js
CHANGED
|
@@ -3,25 +3,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createClientConfig = void 0;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
5
|
const getaccesstoken_1 = require("./getaccesstoken");
|
|
6
|
-
const createClientConfig = (config) => {
|
|
7
|
-
const envConfig = (0, config_1.
|
|
8
|
-
const baseUrl = envConfig.base
|
|
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;
|
|
9
20
|
const newClientConfig = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
17
31
|
return undefined;
|
|
18
|
-
}
|
|
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;
|
|
19
49
|
},
|
|
20
50
|
...config,
|
|
51
|
+
baseUrl: baseUrl.href,
|
|
21
52
|
};
|
|
22
|
-
// Ensure the baseUrl is set
|
|
23
|
-
if (!newClientConfig.baseUrl)
|
|
24
|
-
newClientConfig.baseUrl = baseUrl;
|
|
25
53
|
return newClientConfig;
|
|
26
54
|
};
|
|
27
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,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.readPartialEnvConfig = readPartialEnvConfig;
|
|
4
|
+
exports.readEnvConfig = readEnvConfig;
|
|
4
5
|
const types_1 = require("./types");
|
|
5
|
-
function
|
|
6
|
-
const cmsUrl = getOptional('OPTIMIZELY_CMS_URL'
|
|
7
|
-
const clientId =
|
|
8
|
-
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');
|
|
9
10
|
const actAs = getOptional('OPTIMIZELY_CMS_USER_ID');
|
|
10
11
|
const debug = getOptional('OPTIMIZELY_DEBUG', "0") == "1";
|
|
11
|
-
const cmsVersion = getSelection('OPTIMIZELY_CMS_SCHEMA', [types_1.OptiCmsVersion.CMS12, types_1.OptiCmsVersion.CMS13], types_1.OptiCmsVersion.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
}
|
|
21
22
|
}
|
|
22
23
|
if (debug)
|
|
23
|
-
console.log(`[Optimizely CMS API] Connecting to ${
|
|
24
|
+
console.log(`[Optimizely CMS API] Connecting to ${base || 'CMS API HOST'} as ${clientId ?? 'Anonymous'}`);
|
|
24
25
|
return {
|
|
25
|
-
base
|
|
26
|
+
base,
|
|
26
27
|
clientId,
|
|
27
28
|
clientSecret,
|
|
28
29
|
actAs,
|
|
@@ -30,6 +31,14 @@ function getCmsIntegrationApiConfigFromEnvironment() {
|
|
|
30
31
|
cmsVersion
|
|
31
32
|
};
|
|
32
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
|
+
}
|
|
33
42
|
function getOptional(variable, defaultValue) {
|
|
34
43
|
const envValue = process.env[variable];
|
|
35
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,22 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAccessToken = getAccessToken;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
5
|
function isErrorResponse(response) {
|
|
7
6
|
return typeof (response.error) == 'string';
|
|
8
7
|
}
|
|
9
|
-
async function getAccessToken(config) {
|
|
10
|
-
const options = config ?? (0, config_1.
|
|
11
|
-
|
|
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;
|
|
12
11
|
const headers = new Headers();
|
|
13
|
-
if (options.
|
|
14
|
-
|
|
15
|
-
|
|
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 ?? ''}`)}`);
|
|
16
18
|
headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
17
19
|
headers.append('Connection', 'close');
|
|
18
20
|
if (options.debug) {
|
|
19
21
|
console.log(`⚪ [CMS API] Using authentication endpoint: ${authUrl}`);
|
|
20
|
-
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 : ""}`);
|
|
21
23
|
}
|
|
22
24
|
const body = new URLSearchParams();
|
|
23
25
|
body.append("grant_type", "client_credentials");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export * from './config';
|
|
2
2
|
export * as IntegrationApi from './client/types.gen';
|
|
3
|
+
export * as Preview2IntegrationApi from './instance.client/types.gen';
|
|
3
4
|
export { ApiClient, ApiError, ApiClient as CoreClient, type ApiClientStatic, type CmsIntegrationApiClient } from './api-client';
|
|
4
5
|
export { OptiCmsVersion } from "./types";
|
|
5
6
|
import { type CmsIntegrationApiOptions } from './config';
|
|
6
7
|
import { type CmsIntegrationApiClient } from './api-client';
|
|
8
|
+
export { readEnvConfig } from './config';
|
|
9
|
+
export type ApiClientInstance = CmsIntegrationApiClient;
|
|
7
10
|
export declare function createClient(config?: CmsIntegrationApiOptions): CmsIntegrationApiClient;
|
|
11
|
+
export declare function isClientInstance(value?: object): value is CmsIntegrationApiClient;
|
|
8
12
|
export declare enum ContentRoots {
|
|
9
13
|
/**
|
|
10
14
|
* The Global root node of the Content Tree
|
package/dist/index.js
CHANGED
|
@@ -36,10 +36,12 @@ 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.CoreClient = exports.ApiError = exports.ApiClient = exports.IntegrationApi = void 0;
|
|
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
43
|
exports.IntegrationApi = __importStar(require("./client/types.gen"));
|
|
44
|
+
exports.Preview2IntegrationApi = __importStar(require("./instance.client/types.gen"));
|
|
43
45
|
var api_client_1 = require("./api-client");
|
|
44
46
|
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
|
|
45
47
|
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_client_1.ApiError; } });
|
|
@@ -47,9 +49,16 @@ Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function (
|
|
|
47
49
|
var types_1 = require("./types");
|
|
48
50
|
Object.defineProperty(exports, "OptiCmsVersion", { enumerable: true, get: function () { return types_1.OptiCmsVersion; } });
|
|
49
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; } });
|
|
50
54
|
function createClient(config) {
|
|
51
55
|
return new api_client_2.ApiClient(config);
|
|
52
56
|
}
|
|
57
|
+
function isClientInstance(value) {
|
|
58
|
+
if (typeof value !== 'object' || value === null)
|
|
59
|
+
return false;
|
|
60
|
+
return typeof value['getInstanceInfo'] === 'function';
|
|
61
|
+
}
|
|
53
62
|
var ContentRoots;
|
|
54
63
|
(function (ContentRoots) {
|
|
55
64
|
/**
|
|
@@ -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; } });
|