@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.
Files changed (241) hide show
  1. package/README.md +3 -5
  2. package/dist/api-client.d.ts +70 -11
  3. package/dist/api-client.js +208 -48
  4. package/dist/client/client/client.gen.d.ts +2 -0
  5. package/dist/client/client/client.gen.js +208 -0
  6. package/dist/client/client/index.d.ts +8 -0
  7. package/dist/client/client/index.js +17 -0
  8. package/dist/client/client/types.gen.d.ts +124 -0
  9. package/dist/client/{core/ApiRequestOptions.js → client/types.gen.js} +1 -0
  10. package/dist/client/client/utils.gen.d.ts +33 -0
  11. package/dist/client/client/utils.gen.js +242 -0
  12. package/dist/client/client.gen.d.ts +12 -0
  13. package/dist/client/client.gen.js +9 -0
  14. package/dist/client/core/auth.gen.d.ts +18 -0
  15. package/dist/client/core/auth.gen.js +18 -0
  16. package/dist/client/core/bodySerializer.gen.d.ts +25 -0
  17. package/dist/client/core/bodySerializer.gen.js +60 -0
  18. package/dist/client/core/params.gen.d.ts +33 -0
  19. package/dist/client/core/params.gen.js +92 -0
  20. package/dist/client/core/pathSerializer.gen.d.ts +33 -0
  21. package/dist/client/core/pathSerializer.gen.js +123 -0
  22. package/dist/client/core/queryKeySerializer.gen.d.ts +18 -0
  23. package/dist/client/core/queryKeySerializer.gen.js +105 -0
  24. package/dist/client/core/serverSentEvents.gen.d.ts +71 -0
  25. package/dist/client/core/serverSentEvents.gen.js +139 -0
  26. package/dist/client/core/types.gen.d.ts +78 -0
  27. package/dist/client/core/{ApiResult.js → types.gen.js} +1 -0
  28. package/dist/client/core/utils.gen.d.ts +19 -0
  29. package/dist/client/core/utils.gen.js +93 -0
  30. package/dist/client/index.d.ts +4 -78
  31. package/dist/client/index.js +18 -46
  32. package/dist/client/sdk.gen.d.ts +117 -0
  33. package/dist/client/sdk.gen.js +251 -0
  34. package/dist/client/transformers.gen.d.ts +18 -0
  35. package/dist/client/transformers.gen.js +157 -0
  36. package/dist/client/types.gen.d.ts +1285 -0
  37. package/dist/client/{models/BooleanProperty.js → types.gen.js} +1 -0
  38. package/dist/client-config.d.ts +5 -0
  39. package/dist/client-config.js +55 -0
  40. package/dist/config.d.ts +5 -2
  41. package/dist/config.js +26 -18
  42. package/dist/getaccesstoken.d.ts +1 -1
  43. package/dist/getaccesstoken.js +10 -9
  44. package/dist/index.d.ts +7 -6
  45. package/dist/index.js +15 -8
  46. package/dist/instance.client/client/client.gen.d.ts +2 -0
  47. package/dist/instance.client/client/client.gen.js +208 -0
  48. package/dist/instance.client/client/index.d.ts +8 -0
  49. package/dist/instance.client/client/index.js +17 -0
  50. package/dist/instance.client/client/types.gen.d.ts +124 -0
  51. package/dist/{client/models/BinaryProperty.js → instance.client/client/types.gen.js} +1 -0
  52. package/dist/instance.client/client/utils.gen.d.ts +33 -0
  53. package/dist/instance.client/client/utils.gen.js +242 -0
  54. package/dist/instance.client/client.gen.d.ts +12 -0
  55. package/dist/instance.client/client.gen.js +9 -0
  56. package/dist/instance.client/core/auth.gen.d.ts +18 -0
  57. package/dist/instance.client/core/auth.gen.js +18 -0
  58. package/dist/instance.client/core/bodySerializer.gen.d.ts +25 -0
  59. package/dist/instance.client/core/bodySerializer.gen.js +60 -0
  60. package/dist/instance.client/core/params.gen.d.ts +33 -0
  61. package/dist/instance.client/core/params.gen.js +92 -0
  62. package/dist/instance.client/core/pathSerializer.gen.d.ts +33 -0
  63. package/dist/instance.client/core/pathSerializer.gen.js +123 -0
  64. package/dist/instance.client/core/queryKeySerializer.gen.d.ts +18 -0
  65. package/dist/instance.client/core/queryKeySerializer.gen.js +105 -0
  66. package/dist/instance.client/core/serverSentEvents.gen.d.ts +71 -0
  67. package/dist/instance.client/core/serverSentEvents.gen.js +139 -0
  68. package/dist/instance.client/core/types.gen.d.ts +78 -0
  69. package/dist/instance.client/core/types.gen.js +3 -0
  70. package/dist/instance.client/core/utils.gen.d.ts +19 -0
  71. package/dist/instance.client/core/utils.gen.js +93 -0
  72. package/dist/instance.client/index.d.ts +4 -0
  73. package/dist/instance.client/index.js +21 -0
  74. package/dist/instance.client/sdk.gen.d.ts +303 -0
  75. package/dist/instance.client/sdk.gen.js +699 -0
  76. package/dist/instance.client/transformers.gen.d.ts +48 -0
  77. package/dist/instance.client/transformers.gen.js +431 -0
  78. package/dist/instance.client/types.gen.d.ts +2838 -0
  79. package/dist/instance.client/types.gen.js +3 -0
  80. package/dist/types.d.ts +3 -1
  81. package/dist/types.js +1 -0
  82. package/dist/version.json +3 -3
  83. package/package.json +16 -11
  84. package/dist/client/CmsIntegrationApiClient.d.ts +0 -22
  85. package/dist/client/CmsIntegrationApiClient.js +0 -34
  86. package/dist/client/core/ApiError.d.ts +0 -10
  87. package/dist/client/core/ApiError.js +0 -15
  88. package/dist/client/core/ApiRequestOptions.d.ts +0 -13
  89. package/dist/client/core/ApiResult.d.ts +0 -7
  90. package/dist/client/core/BaseHttpRequest.d.ts +0 -8
  91. package/dist/client/core/BaseHttpRequest.js +0 -9
  92. package/dist/client/core/CancelablePromise.d.ts +0 -20
  93. package/dist/client/core/CancelablePromise.js +0 -116
  94. package/dist/client/core/FetchHttpRequest.d.ts +0 -14
  95. package/dist/client/core/FetchHttpRequest.js +0 -20
  96. package/dist/client/core/OpenAPI.d.ts +0 -16
  97. package/dist/client/core/OpenAPI.js +0 -14
  98. package/dist/client/core/request.d.ts +0 -30
  99. package/dist/client/core/request.js +0 -294
  100. package/dist/client/models/BinaryProperty.d.ts +0 -8
  101. package/dist/client/models/BooleanProperty.d.ts +0 -5
  102. package/dist/client/models/Changeset.d.ts +0 -26
  103. package/dist/client/models/Changeset.js +0 -2
  104. package/dist/client/models/ChangesetItem.d.ts +0 -11
  105. package/dist/client/models/ChangesetItem.js +0 -2
  106. package/dist/client/models/ChangesetItemPage.d.ts +0 -19
  107. package/dist/client/models/ChangesetItemPage.js +0 -2
  108. package/dist/client/models/ChangesetPage.d.ts +0 -19
  109. package/dist/client/models/ChangesetPage.js +0 -2
  110. package/dist/client/models/ComponentListItem.d.ts +0 -10
  111. package/dist/client/models/ComponentListItem.js +0 -2
  112. package/dist/client/models/ComponentProperty.d.ts +0 -10
  113. package/dist/client/models/ComponentProperty.js +0 -2
  114. package/dist/client/models/CompositionBehavior.d.ts +0 -7
  115. package/dist/client/models/CompositionBehavior.js +0 -15
  116. package/dist/client/models/ContentBaseType.d.ts +0 -14
  117. package/dist/client/models/ContentBaseType.js +0 -22
  118. package/dist/client/models/ContentComponent.d.ts +0 -30
  119. package/dist/client/models/ContentComponent.js +0 -2
  120. package/dist/client/models/ContentItem.d.ts +0 -60
  121. package/dist/client/models/ContentItem.js +0 -2
  122. package/dist/client/models/ContentItemListWithContentTypes.d.ts +0 -27
  123. package/dist/client/models/ContentItemListWithContentTypes.js +0 -2
  124. package/dist/client/models/ContentItemPage.d.ts +0 -19
  125. package/dist/client/models/ContentItemPage.js +0 -2
  126. package/dist/client/models/ContentItemWithContentTypes.d.ts +0 -12
  127. package/dist/client/models/ContentItemWithContentTypes.js +0 -2
  128. package/dist/client/models/ContentListItem.d.ts +0 -14
  129. package/dist/client/models/ContentListItem.js +0 -2
  130. package/dist/client/models/ContentLocaleInfo.d.ts +0 -19
  131. package/dist/client/models/ContentLocaleInfo.js +0 -2
  132. package/dist/client/models/ContentMetadata.d.ts +0 -38
  133. package/dist/client/models/ContentMetadata.js +0 -2
  134. package/dist/client/models/ContentMetadataPage.d.ts +0 -19
  135. package/dist/client/models/ContentMetadataPage.js +0 -2
  136. package/dist/client/models/ContentProperty.d.ts +0 -14
  137. package/dist/client/models/ContentProperty.js +0 -2
  138. package/dist/client/models/ContentReference.d.ts +0 -17
  139. package/dist/client/models/ContentReference.js +0 -2
  140. package/dist/client/models/ContentReferenceListItem.d.ts +0 -14
  141. package/dist/client/models/ContentReferenceListItem.js +0 -2
  142. package/dist/client/models/ContentReferenceProperty.d.ts +0 -14
  143. package/dist/client/models/ContentReferenceProperty.js +0 -2
  144. package/dist/client/models/ContentType.d.ts +0 -84
  145. package/dist/client/models/ContentType.js +0 -2
  146. package/dist/client/models/ContentTypeFeature.d.ts +0 -10
  147. package/dist/client/models/ContentTypeFeature.js +0 -18
  148. package/dist/client/models/ContentTypePage.d.ts +0 -19
  149. package/dist/client/models/ContentTypePage.js +0 -2
  150. package/dist/client/models/ContentTypeProperty.d.ts +0 -47
  151. package/dist/client/models/ContentTypeProperty.js +0 -2
  152. package/dist/client/models/ContentTypeUsage.d.ts +0 -7
  153. package/dist/client/models/ContentTypeUsage.js +0 -15
  154. package/dist/client/models/CopyContentOptions.d.ts +0 -21
  155. package/dist/client/models/CopyContentOptions.js +0 -2
  156. package/dist/client/models/DateTimeListItem.d.ts +0 -14
  157. package/dist/client/models/DateTimeListItem.js +0 -2
  158. package/dist/client/models/DateTimeProperty.d.ts +0 -14
  159. package/dist/client/models/DateTimeProperty.js +0 -2
  160. package/dist/client/models/DisplaySetting.d.ts +0 -22
  161. package/dist/client/models/DisplaySetting.js +0 -2
  162. package/dist/client/models/DisplaySettingChoice.d.ts +0 -13
  163. package/dist/client/models/DisplaySettingChoice.js +0 -2
  164. package/dist/client/models/DisplayTemplate.d.ts +0 -49
  165. package/dist/client/models/DisplayTemplate.js +0 -2
  166. package/dist/client/models/DisplayTemplatePage.d.ts +0 -19
  167. package/dist/client/models/DisplayTemplatePage.js +0 -2
  168. package/dist/client/models/DoubleEnumerationSettings.d.ts +0 -10
  169. package/dist/client/models/DoubleEnumerationSettings.js +0 -2
  170. package/dist/client/models/DoubleEnumerationValue.d.ts +0 -13
  171. package/dist/client/models/DoubleEnumerationValue.js +0 -2
  172. package/dist/client/models/FloatListItem.d.ts +0 -16
  173. package/dist/client/models/FloatListItem.js +0 -2
  174. package/dist/client/models/FloatProperty.d.ts +0 -16
  175. package/dist/client/models/FloatProperty.js +0 -2
  176. package/dist/client/models/ImageDescriptor.d.ts +0 -17
  177. package/dist/client/models/ImageDescriptor.js +0 -2
  178. package/dist/client/models/IndexingType.d.ts +0 -8
  179. package/dist/client/models/IndexingType.js +0 -16
  180. package/dist/client/models/Int32EnumerationSettings.d.ts +0 -10
  181. package/dist/client/models/Int32EnumerationSettings.js +0 -2
  182. package/dist/client/models/Int32EnumerationValue.d.ts +0 -13
  183. package/dist/client/models/Int32EnumerationValue.js +0 -2
  184. package/dist/client/models/IntegerListItem.d.ts +0 -16
  185. package/dist/client/models/IntegerListItem.js +0 -2
  186. package/dist/client/models/IntegerProperty.d.ts +0 -16
  187. package/dist/client/models/IntegerProperty.js +0 -2
  188. package/dist/client/models/JsonStringProperty.d.ts +0 -5
  189. package/dist/client/models/JsonStringProperty.js +0 -2
  190. package/dist/client/models/ListProperty.d.ts +0 -26
  191. package/dist/client/models/ListProperty.js +0 -2
  192. package/dist/client/models/ListPropertyItem.d.ts +0 -11
  193. package/dist/client/models/ListPropertyItem.js +0 -2
  194. package/dist/client/models/LocaleStatus.d.ts +0 -7
  195. package/dist/client/models/LocaleStatus.js +0 -15
  196. package/dist/client/models/OauthToken.d.ts +0 -18
  197. package/dist/client/models/OauthToken.js +0 -2
  198. package/dist/client/models/OauthTokenError.d.ts +0 -13
  199. package/dist/client/models/OauthTokenError.js +0 -2
  200. package/dist/client/models/OauthTokenRequest.d.ts +0 -21
  201. package/dist/client/models/OauthTokenRequest.js +0 -2
  202. package/dist/client/models/ProblemDetails.d.ts +0 -1
  203. package/dist/client/models/ProblemDetails.js +0 -2
  204. package/dist/client/models/PropertyDataType.d.ts +0 -18
  205. package/dist/client/models/PropertyDataType.js +0 -26
  206. package/dist/client/models/PropertyFormat.d.ts +0 -37
  207. package/dist/client/models/PropertyFormat.js +0 -2
  208. package/dist/client/models/PropertyFormatPage.d.ts +0 -19
  209. package/dist/client/models/PropertyFormatPage.js +0 -2
  210. package/dist/client/models/PropertyGroup.d.ts +0 -21
  211. package/dist/client/models/PropertyGroup.js +0 -2
  212. package/dist/client/models/PropertyGroupPage.d.ts +0 -19
  213. package/dist/client/models/PropertyGroupPage.js +0 -2
  214. package/dist/client/models/StringEnumerationSettings.d.ts +0 -10
  215. package/dist/client/models/StringEnumerationSettings.js +0 -2
  216. package/dist/client/models/StringEnumerationValue.d.ts +0 -13
  217. package/dist/client/models/StringEnumerationValue.js +0 -2
  218. package/dist/client/models/StringListItem.d.ts +0 -20
  219. package/dist/client/models/StringListItem.js +0 -2
  220. package/dist/client/models/StringProperty.d.ts +0 -20
  221. package/dist/client/models/StringProperty.js +0 -2
  222. package/dist/client/models/UrlListItem.d.ts +0 -5
  223. package/dist/client/models/UrlListItem.js +0 -2
  224. package/dist/client/models/UrlProperty.d.ts +0 -5
  225. package/dist/client/models/UrlProperty.js +0 -2
  226. package/dist/client/models/VersionStatus.d.ts +0 -12
  227. package/dist/client/models/VersionStatus.js +0 -20
  228. package/dist/client/services/ChangesetsService.d.ts +0 -105
  229. package/dist/client/services/ChangesetsService.js +0 -239
  230. package/dist/client/services/ContentService.d.ts +0 -172
  231. package/dist/client/services/ContentService.js +0 -409
  232. package/dist/client/services/ContentTypesService.d.ts +0 -66
  233. package/dist/client/services/ContentTypesService.js +0 -149
  234. package/dist/client/services/DisplayTemplatesService.d.ts +0 -60
  235. package/dist/client/services/DisplayTemplatesService.js +0 -135
  236. package/dist/client/services/OauthService.d.ts +0 -17
  237. package/dist/client/services/OauthService.js +0 -28
  238. package/dist/client/services/PropertyFormatsService.d.ts +0 -26
  239. package/dist/client/services/PropertyFormatsService.js +0 -53
  240. package/dist/client/services/PropertyGroupsService.d.ts +0 -61
  241. package/dist/client/services/PropertyGroupsService.js +0 -135
package/README.md CHANGED
@@ -17,13 +17,12 @@ import createClient, { ContentRoots } from '@remkoj/optimizely-cms-integration-a
17
17
 
18
18
  // Create an instance of the client
19
19
  const client = createClient({
20
- base: "https://example.com",
21
20
  clientId: "apiClientID",
22
21
  clientSecret: "apiClientSecret"
23
22
  });
24
23
 
25
24
  // Start using client
26
- client.content.contentListItems(ContentRoots.SystemRoot).then(response => {
25
+ client.preview2ContentList(ContentRoots.SystemRoot).then(response => {
27
26
  const items = response.items
28
27
  items?.map(item => {
29
28
  // Do something with the item
@@ -38,8 +37,7 @@ The configuration object for the `createClient()` method is optional, if it is o
38
37
  The following configuration options are available for
39
38
  | Environment variable | Configuration key | Required | Usage |
40
39
  | --- | --- | --- | --- |
41
- | OPTIMIZELY_CMS_URL | base | yes | The URL where the CMS is available |
40
+ | OPTIMIZELY_CMS_URL | base | no | Sets the URL of the Optimizely CMS instance |
42
41
  | OPTIMIZELY_CMS_CLIENT_ID | clientId | yes | The API Client ID, as configured within the CMS |
43
42
  | OPTIMIZELY_CMS_CLIENT_SECRET | clientSecret | yes | The API Client Secret as generated by the CMS when creating the client |
44
- | OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
45
- | OPTIMIZELY_CMS_SCHEMA | cmsVersion | no | Override the target Optimizely CMS Version:<br/><br/>`OPTI-CMS-12`: Optimizely CMS 12, With [CMS Service Preview 1](https://nuget.optimizely.com/package/?id=Optimizely.Cms.Preview1.Service) installed and working.<br/><br/>`OPTI-CMS-13`: Optimizely SaaS CMS / CMS 13<br/><br/>**Default:** SaaS CMS / CMS 13 |
43
+ | OPTIMIZELY_CMS_USER_ID | actAs | no | The username of the CMS user to impersonate |
@@ -1,30 +1,62 @@
1
- import { CmsIntegrationApiClient } from "./client";
1
+ import * as Operations from './client/sdk.gen';
2
+ import { createClient, type RequestResult, type ResponseStyle } from './client/client';
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';
2
5
  import { type CmsIntegrationApiOptions } from "./config";
3
6
  import { type InstanceApiVersionInfo, OptiCmsVersion } from "./types";
4
- import type { CancelablePromise } from "./client";
5
- export declare class ApiClient extends CmsIntegrationApiClient {
6
- private _config;
7
- /**
8
- * Create a new instance of the API Client
9
- *
10
- * @param config The instance configuration
11
- */
7
+ type OperationsType = {
8
+ -readonly [KT in keyof typeof Operations]: (typeof Operations)[KT];
9
+ };
10
+ type OperationsNames = keyof OperationsType;
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>;
12
38
  constructor(config?: CmsIntegrationApiOptions);
13
39
  /**
14
40
  * Get the runtime configuration of the target CMS version.
15
41
  *
16
42
  * If this differs from the cmsVersion the client may not work fully or not
17
43
  * at all.
44
+ *
45
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
18
46
  */
19
47
  get runtimeCmsVersion(): OptiCmsVersion;
20
48
  /**
21
49
  * The URL of the CMS instance
22
50
  */
23
- get cmsUrl(): URL;
51
+ get cmsUrl(): URL | undefined;
24
52
  /**
25
53
  * Marker to indicate if the client has debugging enabled
26
54
  */
27
55
  get debug(): boolean;
56
+ /**
57
+ * Detect the API Version from the URL, returning the runtime version. When
58
+ * this version differs from the `apiVersion` property errors can be expected.
59
+ */
28
60
  get version(): string;
29
61
  /**
30
62
  * The API version for which this client was build
@@ -39,5 +71,32 @@ export declare class ApiClient extends CmsIntegrationApiClient {
39
71
  *
40
72
  * @returns The version information from the running instance
41
73
  */
42
- getInstanceInfo(): CancelablePromise<InstanceApiVersionInfo>;
74
+ getInstanceInfo(): Promise<InstanceApiVersionInfo>;
75
+ getOpenApiSpec(): Promise<any>;
76
+ getSchemaItemBase(): URL | undefined;
77
+ }
78
+ export declare class ApiError extends Error {
79
+ protected _ctx: {
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;
43
98
  }
99
+ export declare const ApiClient: ClassWithMixin<typeof BaseApiClient, ApiClientFunctions>;
100
+ export type ApiClientStatic = typeof ApiClient;
101
+ export type CmsIntegrationApiClient = InstanceType<typeof ApiClient>;
102
+ export default ApiClient;
@@ -1,64 +1,159 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ApiClient = void 0;
7
- const client_1 = require("./client");
8
- const getaccesstoken_1 = require("./getaccesstoken");
39
+ exports.ApiClient = exports.ApiError = void 0;
40
+ const Operations = __importStar(require("./client/sdk.gen"));
41
+ const client_1 = require("./client/client");
42
+ const InstanceOperations = __importStar(require("./instance.client/sdk.gen"));
43
+ const client_2 = require("./instance.client/client");
9
44
  const config_1 = require("./config");
10
45
  const types_1 = require("./types");
46
+ const client_config_1 = require("./client-config");
11
47
  const version_json_1 = __importDefault(require("./version.json"));
12
- const OpenAPI_1 = require("./client/core/OpenAPI");
13
- class ApiClient extends client_1.CmsIntegrationApiClient {
14
- /**
15
- * Create a new instance of the API Client
16
- *
17
- * @param config The instance configuration
18
- */
48
+ function applyOperations(Base) {
49
+ // Create the new class
50
+ class NewClass extends Base {
51
+ constructor(...args) {
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;
19
109
  constructor(config) {
20
- const options = config ?? (0, config_1.getCmsIntegrationApiConfigFromEnvironment)();
21
- options.base = new URL(OpenAPI_1.OpenAPI.BASE, options.base);
22
- if (options.cmsVersion == types_1.OptiCmsVersion.CMS12)
23
- options.base.pathname = options.base.pathname.replace('preview2', 'preview1');
24
- const apiVersion = options.cmsVersion == types_1.OptiCmsVersion.CMS12 ? 'preview1' : OpenAPI_1.OpenAPI.VERSION;
25
- let access_token = undefined;
26
- super({
27
- BASE: options.base.href,
28
- TOKEN: async () => {
29
- if (!access_token)
30
- access_token = await (0, getaccesstoken_1.getAccessToken)(options).catch(e => {
31
- if (options.debug) {
32
- console.error(`🔴 [CMS API] Failed to obtain an access token`);
33
- console.error(e);
34
- }
35
- return undefined;
36
- });
37
- return access_token ?? '';
38
- },
39
- HEADERS: {
40
- Connection: "Close"
41
- },
42
- WITH_CREDENTIALS: true,
43
- CREDENTIALS: "include",
44
- VERSION: apiVersion
45
- });
46
- this._config = options;
110
+ // Store instance variables
111
+ this._config = config ?? (0, config_1.readEnvConfig)();
112
+ this._client = (0, client_1.createClient)((0, client_config_1.createClientConfig)((0, client_1.createConfig)({
113
+ baseUrl: 'https://api.cms.optimizely.com/preview3'
114
+ }), this._config));
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
+ }
47
137
  }
48
138
  /**
49
139
  * Get the runtime configuration of the target CMS version.
50
140
  *
51
141
  * If this differs from the cmsVersion the client may not work fully or not
52
142
  * at all.
143
+ *
144
+ * @deprecated This is based on the OPTIMIZELY_CMS_SCHEMA environment that is ignored by API client
53
145
  */
54
146
  get runtimeCmsVersion() {
55
- return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMS13;
147
+ return this._config.cmsVersion ?? types_1.OptiCmsVersion.CMSSAAS;
56
148
  }
57
149
  /**
58
150
  * The URL of the CMS instance
59
151
  */
60
152
  get cmsUrl() {
61
- return this._config.base;
153
+ if (this._config.base)
154
+ return this._config.base;
155
+ const baseUrl = this._client.getConfig().baseUrl;
156
+ return baseUrl ? new URL(baseUrl) : undefined;
62
157
  }
63
158
  /**
64
159
  * Marker to indicate if the client has debugging enabled
@@ -66,8 +161,14 @@ class ApiClient extends client_1.CmsIntegrationApiClient {
66
161
  get debug() {
67
162
  return this._config.debug ?? false;
68
163
  }
164
+ /**
165
+ * Detect the API Version from the URL, returning the runtime version. When
166
+ * this version differs from the `apiVersion` property errors can be expected.
167
+ */
69
168
  get version() {
70
- return this._config.cmsVersion == types_1.OptiCmsVersion.CMS12 ? 'preview1' : OpenAPI_1.OpenAPI.VERSION;
169
+ const baseUrl = this._client.getConfig().baseUrl;
170
+ const detectedVersion = baseUrl?.match(/^https{0,1}:\/\/.+?\/(_cms\/){0,1}([a-z0-9\.]+)(\/|$)/)?.at(2);
171
+ return detectedVersion || "";
71
172
  }
72
173
  /**
73
174
  * The API version for which this client was build
@@ -86,14 +187,73 @@ class ApiClient extends client_1.CmsIntegrationApiClient {
86
187
  *
87
188
  * @returns The version information from the running instance
88
189
  */
89
- getInstanceInfo() {
90
- return this.request.request({
91
- method: 'GET',
92
- url: '/info',
93
- errors: {
94
- 403: `Forbidden`,
95
- },
190
+ async getInstanceInfo() {
191
+ const result = await this._client.get({
192
+ url: '/info'
193
+ });
194
+ const instanceResult = await this._instanceClient.get({
195
+ url: '/info'
96
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
+ async getOpenApiSpec() {
212
+ const result = await this._client.get({
213
+ url: '/docs/content-openapi.json',
214
+ });
215
+ if (result.data)
216
+ return result.data;
217
+ throw new ApiError(result);
218
+ }
219
+ getSchemaItemBase() {
220
+ let baseUrl = this._client.getConfig().baseUrl;
221
+ if (typeof (baseUrl) === 'string' && !baseUrl.endsWith('/'))
222
+ baseUrl = baseUrl + '/';
223
+ return baseUrl ? new URL(baseUrl) : undefined;
224
+ }
225
+ }
226
+ class ApiError extends Error {
227
+ _ctx;
228
+ constructor(data) {
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;
97
255
  }
98
256
  }
99
- exports.ApiClient = ApiClient;
257
+ exports.ApiError = ApiError;
258
+ exports.ApiClient = applyOperations(BaseApiClient);
259
+ exports.default = exports.ApiClient;
@@ -0,0 +1,2 @@
1
+ import type { Client, Config } from './types.gen';
2
+ export declare const createClient: (config?: Config) => Client;
@@ -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; } });