@remkoj/optimizely-cms-api 6.0.0-pre9 → 6.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +66 -0
- package/README.md +6 -2
- package/dist/api-client.d.ts +10 -77
- package/dist/api-client.js +18 -171
- package/dist/client/client/client.gen.js +114 -102
- package/dist/client/client/index.d.ts +3 -1
- package/dist/client/client/types.gen.d.ts +9 -13
- package/dist/client/client/utils.gen.d.ts +8 -4
- package/dist/client/client/utils.gen.js +15 -17
- package/dist/client/client.gen.d.ts +2 -2
- package/dist/client/client.gen.js +2 -4
- package/dist/client/core/auth.gen.d.ts +7 -0
- package/dist/client/core/bodySerializer.gen.d.ts +16 -8
- package/dist/client/core/bodySerializer.gen.js +1 -1
- package/dist/client/core/params.gen.d.ts +12 -2
- package/dist/client/core/params.gen.js +40 -20
- package/dist/client/core/pathSerializer.gen.js +3 -11
- package/dist/client/core/queryKeySerializer.gen.d.ts +1 -1
- package/dist/client/core/queryKeySerializer.gen.js +4 -11
- package/dist/client/core/serverSentEvents.gen.d.ts +1 -1
- package/dist/client/core/serverSentEvents.gen.js +7 -11
- package/dist/client/core/types.gen.d.ts +6 -1
- package/dist/client/core/utils.gen.js +1 -1
- package/dist/client/index.d.ts +4 -4
- package/dist/client/index.js +140 -17
- package/dist/client/sdk.gen.d.ts +336 -23
- package/dist/client/sdk.gen.js +761 -148
- package/dist/client/transformers.gen.d.ts +49 -1
- package/dist/client/transformers.gen.js +491 -49
- package/dist/client/types.gen.d.ts +5323 -466
- package/dist/client-config.d.ts +11 -0
- package/dist/client-config.js +21 -10
- package/dist/config.d.ts +39 -4
- package/dist/config.js +44 -18
- package/dist/getaccesstoken.js +22 -4
- package/dist/index.d.ts +20 -2
- package/dist/index.js +18 -5
- package/dist/types.d.ts +1 -14
- package/dist/types.js +0 -7
- package/dist/version.json +3 -3
- package/package.json +23 -12
- package/dist/instance.client/client/client.gen.d.ts +0 -2
- package/dist/instance.client/client/client.gen.js +0 -208
- package/dist/instance.client/client/index.d.ts +0 -8
- package/dist/instance.client/client/index.js +0 -17
- package/dist/instance.client/client/types.gen.d.ts +0 -124
- package/dist/instance.client/client/types.gen.js +0 -3
- package/dist/instance.client/client/utils.gen.d.ts +0 -33
- package/dist/instance.client/client/utils.gen.js +0 -241
- package/dist/instance.client/client.gen.d.ts +0 -12
- package/dist/instance.client/client.gen.js +0 -9
- package/dist/instance.client/core/auth.gen.d.ts +0 -18
- package/dist/instance.client/core/auth.gen.js +0 -18
- package/dist/instance.client/core/bodySerializer.gen.d.ts +0 -17
- package/dist/instance.client/core/bodySerializer.gen.js +0 -60
- package/dist/instance.client/core/params.gen.d.ts +0 -33
- package/dist/instance.client/core/params.gen.js +0 -92
- package/dist/instance.client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/instance.client/core/pathSerializer.gen.js +0 -123
- package/dist/instance.client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/instance.client/core/queryKeySerializer.gen.js +0 -105
- package/dist/instance.client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/instance.client/core/serverSentEvents.gen.js +0 -139
- package/dist/instance.client/core/types.gen.d.ts +0 -78
- package/dist/instance.client/core/types.gen.js +0 -3
- package/dist/instance.client/core/utils.gen.d.ts +0 -19
- package/dist/instance.client/core/utils.gen.js +0 -93
- package/dist/instance.client/index.d.ts +0 -4
- package/dist/instance.client/index.js +0 -21
- package/dist/instance.client/sdk.gen.d.ts +0 -256
- package/dist/instance.client/sdk.gen.js +0 -638
- package/dist/instance.client/transformers.gen.d.ts +0 -34
- package/dist/instance.client/transformers.gen.js +0 -273
- package/dist/instance.client/types.gen.d.ts +0 -2838
- package/dist/instance.client/types.gen.js +0 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @remkoj/optimizely-cms-api — usage
|
|
2
|
+
|
|
3
|
+
CMS Integration REST API client for Optimizely SaaS CMS. CommonJS module.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @remkoj/optimizely-cms-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Environment variables
|
|
12
|
+
|
|
13
|
+
| Variable | Required | Description |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `OPTIMIZELY_CMS_URL` | yes | CMS instance URL, e.g. `https://<tenant>.cms.optimizely.com` |
|
|
16
|
+
| `OPTIMIZELY_CMS_CLIENT_ID` | yes | OAuth client ID |
|
|
17
|
+
| `OPTIMIZELY_CMS_CLIENT_SECRET` | yes | OAuth client secret |
|
|
18
|
+
| `OPTIMIZELY_CMS_API_BASEURL` | no | Override the API base URL |
|
|
19
|
+
| `OPTIMIZELY_CMS_USER_ID` | no | Impersonate a specific user (`actAs`) |
|
|
20
|
+
| `OPTIMIZELY_DEBUG` | no | Set to `"1"` to enable request/response logging |
|
|
21
|
+
|
|
22
|
+
## Creating a client
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createClient, readEnvConfig } from '@remkoj/optimizely-cms-api'
|
|
26
|
+
|
|
27
|
+
// From environment variables (recommended)
|
|
28
|
+
const client = createClient()
|
|
29
|
+
|
|
30
|
+
// With explicit config
|
|
31
|
+
const client = createClient({
|
|
32
|
+
base: new URL('https://<tenant>.cms.optimizely.com'),
|
|
33
|
+
clientId: '...',
|
|
34
|
+
clientSecret: '...',
|
|
35
|
+
debug: false
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Key exports
|
|
40
|
+
|
|
41
|
+
| Export | Description |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `createClient(config?)` | Creates a new API client instance. Reads env vars when config is omitted. |
|
|
44
|
+
| `readEnvConfig()` | Reads and validates env vars into `CmsIntegrationApiOptions`. |
|
|
45
|
+
| `readPartialEnvConfig()` | Reads env vars without requiring client credentials. |
|
|
46
|
+
| `isClientInstance(value)` | Type guard for `CmsIntegrationApiClient`. |
|
|
47
|
+
| `IntegrationApi.*` | All generated CMS API types (re-exported from `types.gen.ts`). |
|
|
48
|
+
| `ContentRoots` | Enum of well-known content root node GUIDs (SystemRoot, Trash, etc.). |
|
|
49
|
+
| `ApiClient` | Base client class. |
|
|
50
|
+
| `ApiError` | Error thrown when an API operation fails. |
|
|
51
|
+
| `ApiClientInstance` | Type alias for a client instance. |
|
|
52
|
+
|
|
53
|
+
## Types
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import type { CmsIntegrationApiOptions, ApiClientInstance } from '@remkoj/optimizely-cms-api'
|
|
57
|
+
import { IntegrationApi } from '@remkoj/optimizely-cms-api'
|
|
58
|
+
|
|
59
|
+
// Use IntegrationApi.ContentType, IntegrationApi.DisplayTemplate, etc.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Constraints
|
|
63
|
+
|
|
64
|
+
- CommonJS module — works with both `require()` and `import`.
|
|
65
|
+
- `ApiError` exposes `.status`, `.statusText`, `.data`, `.request`, `.response`.
|
|
66
|
+
- `ContentRoots` values are GUIDs as strings.
|
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
# Optimizely CMS - Integration API Client <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
> [!WARNING]
|
|
4
|
+
> There'll be an update of Optimizely SaaS CMS that is incompatible with all SDK versions prior to 5.1.6. If you don't upgrade, you will see empty pages (main website) and "Component not found" messages (preview).
|
|
5
|
+
|
|
1
6
|
[](./LICENSE)
|
|
2
7
|

|
|
3
8
|
|
|
4
|
-
# Optimizely CMS - Integration API Client <!-- omit in toc -->
|
|
5
9
|
A Javascript client for the Integration API provided by the Optimizely CMS. It wraps the [Optimizely CMS SaaS Core REST API](https://docs.developers.optimizely.com/content-management-system/v1.0.0-SaaS-Core/reference/introduction-to-the-cms-content-api).
|
|
6
10
|
|
|
7
11
|
## Installation
|
|
@@ -40,4 +44,4 @@ The following configuration options are available for
|
|
|
40
44
|
| OPTIMIZELY_CMS_URL | base | no | Sets the URL of the Optimizely CMS instance |
|
|
41
45
|
| OPTIMIZELY_CMS_CLIENT_ID | clientId | yes | The API Client ID, as configured within the CMS |
|
|
42
46
|
| OPTIMIZELY_CMS_CLIENT_SECRET | clientSecret | yes | The API Client Secret as generated by the CMS when creating the client |
|
|
43
|
-
| OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
|
|
47
|
+
| OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
|
package/dist/api-client.d.ts
CHANGED
|
@@ -1,58 +1,17 @@
|
|
|
1
|
+
import { ApiClient as AbstractApiClient } from "@remkoj/hey-api-wrapper";
|
|
1
2
|
import * as Operations from './client/sdk.gen';
|
|
2
|
-
import { createClient
|
|
3
|
-
import * as InstanceOperations from './instance.client/sdk.gen';
|
|
4
|
-
import { createClient as createInstanceClient, type RequestResult as InstanceRequestResult, type ResponseStyle as InstanceResponseStyle } from './instance.client/client';
|
|
3
|
+
import { createClient } from './client/client';
|
|
5
4
|
import { type CmsIntegrationApiOptions } from "./config";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type OperationReturnType<RT extends (...args: any) => any> = ReturnType<RT> extends RequestResult<any, any, boolean, ResponseStyle> ? Promise<NonNullable<Awaited<ReturnType<RT>>['data']>> : never;
|
|
12
|
-
type InstanceOperationsType = {
|
|
13
|
-
-readonly [KT in keyof typeof InstanceOperations]: (typeof InstanceOperations)[KT];
|
|
14
|
-
};
|
|
15
|
-
type InstanceOperationsNames = keyof InstanceOperationsType;
|
|
16
|
-
type InstanceOperationReturnType<RT extends (...args: any) => any> = ReturnType<RT> extends InstanceRequestResult<any, any, boolean, InstanceResponseStyle> ? Promise<NonNullable<Awaited<ReturnType<RT>>['data']>> : never;
|
|
17
|
-
type BaseApiClientFunctions = {
|
|
18
|
-
readonly [KT in OperationsNames]: OperationsType[KT] extends Function ? (options?: Parameters<OperationsType[KT]>[0]) => OperationReturnType<OperationsType[KT]> : never;
|
|
19
|
-
};
|
|
20
|
-
type InstanceClientFunctions = {
|
|
21
|
-
readonly [KT in InstanceOperationsNames as InstanceOperationsType[KT] extends Function ? `preview2${Capitalize<KT>}` : never]: InstanceOperationsType[KT] extends Function ? (options?: Parameters<InstanceOperationsType[KT]>[0]) => InstanceOperationReturnType<InstanceOperationsType[KT]> : never;
|
|
22
|
-
};
|
|
23
|
-
type ApiClientFunctions = BaseApiClientFunctions & InstanceClientFunctions;
|
|
24
|
-
type BaseClass = {
|
|
25
|
-
new (...args: any[]): BaseApiClient;
|
|
26
|
-
};
|
|
27
|
-
type NonConstructorKeys<T> = ({
|
|
28
|
-
[P in keyof T]: T[P] extends new () => any ? never : P;
|
|
29
|
-
})[keyof T];
|
|
30
|
-
type OmitConstructor<TBase extends BaseClass> = Pick<TBase, NonConstructorKeys<TBase>>;
|
|
31
|
-
export type ClassWithMixin<TBase extends BaseClass, Mixin> = OmitConstructor<TBase> & {
|
|
32
|
-
new (...args: ConstructorParameters<TBase>): InstanceType<TBase> & Mixin;
|
|
33
|
-
};
|
|
34
|
-
declare class BaseApiClient {
|
|
35
|
-
protected _config: CmsIntegrationApiOptions;
|
|
36
|
-
protected _client: ReturnType<typeof createClient>;
|
|
37
|
-
protected _instanceClient: ReturnType<typeof createInstanceClient>;
|
|
5
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
6
|
+
/**
|
|
7
|
+
* Base implementation of the ApiClient wrapper for the Optimizely CMS Rest API
|
|
8
|
+
*/
|
|
9
|
+
declare class BaseApiClient extends AbstractApiClient<CmsIntegrationApiOptions, ReturnType<typeof createClient>> {
|
|
38
10
|
constructor(config?: CmsIntegrationApiOptions);
|
|
39
|
-
/**
|
|
40
|
-
* Get the runtime configuration of the target CMS version.
|
|
41
|
-
*
|
|
42
|
-
* If this differs from the cmsVersion the client may not work fully or not
|
|
43
|
-
* at all.
|
|
44
|
-
*
|
|
45
|
-
* @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
|
|
46
|
-
*/
|
|
47
|
-
get runtimeCmsVersion(): OptiCmsVersion;
|
|
48
11
|
/**
|
|
49
12
|
* The URL of the CMS instance
|
|
50
13
|
*/
|
|
51
14
|
get cmsUrl(): URL | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Marker to indicate if the client has debugging enabled
|
|
54
|
-
*/
|
|
55
|
-
get debug(): boolean;
|
|
56
15
|
/**
|
|
57
16
|
* Detect the API Version from the URL, returning the runtime version. When
|
|
58
17
|
* this version differs from the `apiVersion` property errors can be expected.
|
|
@@ -66,37 +25,11 @@ declare class BaseApiClient {
|
|
|
66
25
|
* The CMS version for which this client was build
|
|
67
26
|
*/
|
|
68
27
|
get cmsVersion(): string;
|
|
69
|
-
|
|
70
|
-
* Retrieve the version information
|
|
71
|
-
*
|
|
72
|
-
* @returns The version information from the running instance
|
|
73
|
-
*/
|
|
74
|
-
getInstanceInfo(): Promise<InstanceApiVersionInfo>;
|
|
75
|
-
getOpenApiSpec(): Promise<any>;
|
|
28
|
+
getOpenApiSpec(): Promise<OpenAPIV3_1.Document>;
|
|
76
29
|
getSchemaItemBase(): URL | undefined;
|
|
77
30
|
}
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
error: unknown;
|
|
81
|
-
request: Request;
|
|
82
|
-
response: Response;
|
|
83
|
-
};
|
|
84
|
-
constructor(data: {
|
|
85
|
-
error: unknown;
|
|
86
|
-
request: Request;
|
|
87
|
-
response: Response;
|
|
88
|
-
});
|
|
89
|
-
get data(): unknown;
|
|
90
|
-
/**
|
|
91
|
-
* @deprecated use data() instead
|
|
92
|
-
*/
|
|
93
|
-
get body(): unknown;
|
|
94
|
-
get request(): unknown;
|
|
95
|
-
get response(): unknown;
|
|
96
|
-
get status(): number;
|
|
97
|
-
get statusText(): string;
|
|
98
|
-
}
|
|
99
|
-
export declare const ApiClient: ClassWithMixin<typeof BaseApiClient, ApiClientFunctions>;
|
|
31
|
+
export { ApiError } from "@remkoj/hey-api-wrapper";
|
|
32
|
+
export declare const ApiClient: import("@remkoj/hey-api-wrapper/dist/types").ClassWithMixin<typeof BaseApiClient, import("@remkoj/hey-api-wrapper/dist/types").ApiClientFunctions<typeof Operations>>;
|
|
100
33
|
export type ApiClientStatic = typeof ApiClient;
|
|
101
34
|
export type CmsIntegrationApiClient = InstanceType<typeof ApiClient>;
|
|
102
35
|
export default ApiClient;
|
package/dist/api-client.js
CHANGED
|
@@ -37,114 +37,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ApiClient = exports.ApiError = void 0;
|
|
40
|
+
const hey_api_wrapper_1 = require("@remkoj/hey-api-wrapper");
|
|
40
41
|
const Operations = __importStar(require("./client/sdk.gen"));
|
|
41
42
|
const client_1 = require("./client/client");
|
|
42
|
-
const InstanceOperations = __importStar(require("./instance.client/sdk.gen"));
|
|
43
|
-
const client_2 = require("./instance.client/client");
|
|
44
|
-
const config_1 = require("./config");
|
|
45
|
-
const types_1 = require("./types");
|
|
46
43
|
const client_config_1 = require("./client-config");
|
|
44
|
+
const config_1 = require("./config");
|
|
47
45
|
const version_json_1 = __importDefault(require("./version.json"));
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
super(...args);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Bind the operations
|
|
56
|
-
Object.getOwnPropertyNames(Operations).filter(isApiClientFunction).forEach(propName => {
|
|
57
|
-
async function wrapper(args) {
|
|
58
|
-
const operationArgs = {
|
|
59
|
-
throwOnError: false,
|
|
60
|
-
...args,
|
|
61
|
-
//@ts-expect-error
|
|
62
|
-
client: this._client
|
|
63
|
-
};
|
|
64
|
-
//@ts-expect-error
|
|
65
|
-
const result = await Operations[propName](operationArgs);
|
|
66
|
-
if (result.data)
|
|
67
|
-
return result.data;
|
|
68
|
-
throw new ApiError(result);
|
|
69
|
-
}
|
|
70
|
-
//@ts-expect-error
|
|
71
|
-
NewClass.prototype[propName] = wrapper;
|
|
72
|
-
});
|
|
73
|
-
// Bind the older Preview2 operations
|
|
74
|
-
Object.getOwnPropertyNames(InstanceOperations).filter(isInstanceClientFunction).forEach(propName => {
|
|
75
|
-
async function wrapper(args) {
|
|
76
|
-
const operationArgs = {
|
|
77
|
-
throwOnError: false,
|
|
78
|
-
...args,
|
|
79
|
-
//@ts-expect-error
|
|
80
|
-
client: this._instanceClient
|
|
81
|
-
};
|
|
82
|
-
//@ts-expect-error
|
|
83
|
-
const result = await InstanceOperations[propName](operationArgs);
|
|
84
|
-
if (result.data)
|
|
85
|
-
return result.data;
|
|
86
|
-
throw new ApiError(result);
|
|
87
|
-
}
|
|
88
|
-
const fnName = `preview2${toCapitalized(propName)}`;
|
|
89
|
-
//@ts-expect-error
|
|
90
|
-
NewClass.prototype[fnName] = wrapper;
|
|
91
|
-
});
|
|
92
|
-
// Return the new class
|
|
93
|
-
return NewClass;
|
|
94
|
-
}
|
|
95
|
-
function toCapitalized(toCapitalize) {
|
|
96
|
-
return (toCapitalize.substring(0, 1).toUpperCase() + toCapitalize.substring(1));
|
|
97
|
-
}
|
|
98
|
-
function createIsFunctionValidator(baseType) {
|
|
99
|
-
return (propName) => {
|
|
100
|
-
return typeof (baseType[propName]) == 'function';
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const isApiClientFunction = createIsFunctionValidator(Operations);
|
|
104
|
-
const isInstanceClientFunction = createIsFunctionValidator(InstanceOperations);
|
|
105
|
-
class BaseApiClient {
|
|
106
|
-
_config;
|
|
107
|
-
_client;
|
|
108
|
-
_instanceClient;
|
|
46
|
+
/**
|
|
47
|
+
* Base implementation of the ApiClient wrapper for the Optimizely CMS Rest API
|
|
48
|
+
*/
|
|
49
|
+
class BaseApiClient extends hey_api_wrapper_1.ApiClient {
|
|
109
50
|
constructor(config) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this._instanceClient = (0, client_2.createClient)((0, client_config_1.createClientConfig)((0, client_2.createConfig)({
|
|
116
|
-
baseUrl: new URL('/_cms/preview2', this._config.base).href
|
|
117
|
-
})));
|
|
118
|
-
// Configure Client
|
|
119
|
-
if (this._config.debug) {
|
|
120
|
-
this._client.interceptors.request.use(async (request) => {
|
|
121
|
-
console.log(`🔍 [CMS API] Sending ${request.method} request to ${request.url}`);
|
|
122
|
-
return request;
|
|
123
|
-
});
|
|
124
|
-
this._client.interceptors.response.use((response, request) => {
|
|
125
|
-
console.log(`✨ [CMS API] Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
|
|
126
|
-
return response;
|
|
127
|
-
});
|
|
128
|
-
this._instanceClient.interceptors.request.use(async (request) => {
|
|
129
|
-
console.log(`🔍 [CMS API] Sending ${request.method} request to ${request.url}`);
|
|
130
|
-
return request;
|
|
131
|
-
});
|
|
132
|
-
this._instanceClient.interceptors.response.use((response, request) => {
|
|
133
|
-
console.log(`✨ [CMS API] Received response ${response.status} ${response.statusText} of type ${response.headers.get('Content-Type') ?? 'unknown'} for ${request.url}`);
|
|
134
|
-
return response;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Get the runtime configuration of the target CMS version.
|
|
140
|
-
*
|
|
141
|
-
* If this differs from the cmsVersion the client may not work fully or not
|
|
142
|
-
* at all.
|
|
143
|
-
*
|
|
144
|
-
* @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
|
|
145
|
-
*/
|
|
146
|
-
get runtimeCmsVersion() {
|
|
147
|
-
return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMSSAAS;
|
|
51
|
+
const apiConfig = config ?? (0, config_1.readEnvConfig)();
|
|
52
|
+
const apiClient = (0, client_1.createClient)((0, client_config_1.createClientConfig)((0, client_1.createConfig)({
|
|
53
|
+
baseUrl: 'https://api.cms.optimizely.com/v1',
|
|
54
|
+
}), config));
|
|
55
|
+
super(apiConfig, apiClient);
|
|
148
56
|
}
|
|
149
57
|
/**
|
|
150
58
|
* The URL of the CMS instance
|
|
@@ -155,19 +63,13 @@ class BaseApiClient {
|
|
|
155
63
|
const baseUrl = this._client.getConfig().baseUrl;
|
|
156
64
|
return baseUrl ? new URL(baseUrl) : undefined;
|
|
157
65
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Marker to indicate if the client has debugging enabled
|
|
160
|
-
*/
|
|
161
|
-
get debug() {
|
|
162
|
-
return this._config.debug ?? false;
|
|
163
|
-
}
|
|
164
66
|
/**
|
|
165
67
|
* Detect the API Version from the URL, returning the runtime version. When
|
|
166
68
|
* this version differs from the `apiVersion` property errors can be expected.
|
|
167
69
|
*/
|
|
168
70
|
get version() {
|
|
169
71
|
const baseUrl = this._client.getConfig().baseUrl;
|
|
170
|
-
const detectedVersion = baseUrl?.match(/^https{0,1}:\/\/.+?\/(_cms\/){0,1}([a-z0-9
|
|
72
|
+
const detectedVersion = baseUrl?.match(/^https{0,1}:\/\/.+?\/(_cms\/){0,1}([a-z0-9.]+)(\/|$)/)?.at(2);
|
|
171
73
|
return detectedVersion || "";
|
|
172
74
|
}
|
|
173
75
|
/**
|
|
@@ -182,39 +84,14 @@ class BaseApiClient {
|
|
|
182
84
|
get cmsVersion() {
|
|
183
85
|
return version_json_1.default.cms;
|
|
184
86
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Retrieve the version information
|
|
187
|
-
*
|
|
188
|
-
* @returns The version information from the running instance
|
|
189
|
-
*/
|
|
190
|
-
async getInstanceInfo() {
|
|
191
|
-
const result = await this._client.get({
|
|
192
|
-
url: '/info'
|
|
193
|
-
});
|
|
194
|
-
const instanceResult = await this._instanceClient.get({
|
|
195
|
-
url: '/info'
|
|
196
|
-
});
|
|
197
|
-
if (result.data) {
|
|
198
|
-
const data = result.data;
|
|
199
|
-
data.baseUrl = this._client.getConfig().baseUrl;
|
|
200
|
-
data.results = {
|
|
201
|
-
preview2Data: {
|
|
202
|
-
baseUrl: this._instanceClient.getConfig().baseUrl,
|
|
203
|
-
...instanceResult?.data ?? {}
|
|
204
|
-
},
|
|
205
|
-
...data.results,
|
|
206
|
-
};
|
|
207
|
-
return data;
|
|
208
|
-
}
|
|
209
|
-
throw new ApiError(result);
|
|
210
|
-
}
|
|
211
87
|
async getOpenApiSpec() {
|
|
212
88
|
const result = await this._client.get({
|
|
213
89
|
url: '/docs/content-openapi.json',
|
|
90
|
+
throwOnError: false
|
|
214
91
|
});
|
|
215
|
-
if (result
|
|
92
|
+
if (this.isDataResponse(result))
|
|
216
93
|
return result.data;
|
|
217
|
-
throw new ApiError(result);
|
|
94
|
+
throw new hey_api_wrapper_1.ApiError(result);
|
|
218
95
|
}
|
|
219
96
|
getSchemaItemBase() {
|
|
220
97
|
let baseUrl = this._client.getConfig().baseUrl;
|
|
@@ -223,37 +100,7 @@ class BaseApiClient {
|
|
|
223
100
|
return baseUrl ? new URL(baseUrl) : undefined;
|
|
224
101
|
}
|
|
225
102
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (typeof data.error == 'string')
|
|
230
|
-
super(data.error);
|
|
231
|
-
else
|
|
232
|
-
super(`Optimizely CMS API Error: ${data.response.status} ${data.response.statusText}`);
|
|
233
|
-
this._ctx = data;
|
|
234
|
-
}
|
|
235
|
-
get data() {
|
|
236
|
-
return this._ctx.error;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* @deprecated use data() instead
|
|
240
|
-
*/
|
|
241
|
-
get body() {
|
|
242
|
-
return this._ctx.error;
|
|
243
|
-
}
|
|
244
|
-
get request() {
|
|
245
|
-
return this._ctx.request;
|
|
246
|
-
}
|
|
247
|
-
get response() {
|
|
248
|
-
return this._ctx.response;
|
|
249
|
-
}
|
|
250
|
-
get status() {
|
|
251
|
-
return this._ctx.response.status;
|
|
252
|
-
}
|
|
253
|
-
get statusText() {
|
|
254
|
-
return this._ctx.response.statusText;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
exports.ApiError = ApiError;
|
|
258
|
-
exports.ApiClient = applyOperations(BaseApiClient);
|
|
103
|
+
var hey_api_wrapper_2 = require("@remkoj/hey-api-wrapper");
|
|
104
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return hey_api_wrapper_2.ApiError; } });
|
|
105
|
+
exports.ApiClient = (0, hey_api_wrapper_1.withOperations)(BaseApiClient, Operations);
|
|
259
106
|
exports.default = exports.ApiClient;
|