@remkoj/optimizely-cms-api 2.0.0-pre5 → 2.0.1-pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.d.ts +1 -0
- package/dist/api-client.js +20 -2
- package/dist/config.js +1 -2
- package/dist/getaccesstoken.js +25 -25
- package/dist/index.d.ts +15 -1
- package/dist/index.js +16 -2
- package/dist/version.json +2 -2
- package/package.json +5 -5
package/dist/api-client.d.ts
CHANGED
package/dist/api-client.js
CHANGED
|
@@ -8,6 +8,7 @@ const client_1 = require("./client");
|
|
|
8
8
|
const getaccesstoken_1 = require("./getaccesstoken");
|
|
9
9
|
const config_1 = require("./config");
|
|
10
10
|
const version_json_1 = __importDefault(require("./version.json"));
|
|
11
|
+
const OpenAPI_1 = require("./client/core/OpenAPI");
|
|
11
12
|
class ApiClient extends client_1.CmsIntegrationApiClient {
|
|
12
13
|
/**
|
|
13
14
|
* Create a new instance of the API Client
|
|
@@ -16,12 +17,26 @@ class ApiClient extends client_1.CmsIntegrationApiClient {
|
|
|
16
17
|
*/
|
|
17
18
|
constructor(config) {
|
|
18
19
|
const options = config ?? (0, config_1.getCmsIntegrationApiConfigFromEnvironment)();
|
|
20
|
+
options.base = new URL(OpenAPI_1.OpenAPI.BASE, options.base);
|
|
21
|
+
let access_token = undefined;
|
|
19
22
|
super({
|
|
20
23
|
BASE: options.base.href,
|
|
21
|
-
TOKEN: () =>
|
|
24
|
+
TOKEN: async () => {
|
|
25
|
+
if (!access_token)
|
|
26
|
+
access_token = await (0, getaccesstoken_1.getAccessToken)(options).catch(e => {
|
|
27
|
+
if (options.debug) {
|
|
28
|
+
console.error(`🔴 [CMS API] Failed to obtain an access token`);
|
|
29
|
+
console.error(e);
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
});
|
|
33
|
+
return access_token ?? '';
|
|
34
|
+
},
|
|
22
35
|
HEADERS: {
|
|
23
36
|
Connection: "Close"
|
|
24
|
-
}
|
|
37
|
+
},
|
|
38
|
+
WITH_CREDENTIALS: true,
|
|
39
|
+
CREDENTIALS: "include"
|
|
25
40
|
});
|
|
26
41
|
this._config = options;
|
|
27
42
|
}
|
|
@@ -37,6 +52,9 @@ class ApiClient extends client_1.CmsIntegrationApiClient {
|
|
|
37
52
|
get debug() {
|
|
38
53
|
return this._config.debug ?? false;
|
|
39
54
|
}
|
|
55
|
+
get version() {
|
|
56
|
+
return OpenAPI_1.OpenAPI.VERSION;
|
|
57
|
+
}
|
|
40
58
|
/**
|
|
41
59
|
* The API version for which this client was build
|
|
42
60
|
*/
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCmsIntegrationApiConfigFromEnvironment =
|
|
3
|
+
exports.getCmsIntegrationApiConfigFromEnvironment = getCmsIntegrationApiConfigFromEnvironment;
|
|
4
4
|
const OpenAPI_1 = require("./client/core/OpenAPI");
|
|
5
5
|
function getCmsIntegrationApiConfigFromEnvironment() {
|
|
6
6
|
const cmsUrl = getMandatory('OPTIMIZELY_CMS_URL');
|
|
@@ -25,7 +25,6 @@ function getCmsIntegrationApiConfigFromEnvironment() {
|
|
|
25
25
|
debug
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
exports.getCmsIntegrationApiConfigFromEnvironment = getCmsIntegrationApiConfigFromEnvironment;
|
|
29
28
|
function getOptional(variable, defaultValue) {
|
|
30
29
|
const envValue = process.env[variable];
|
|
31
30
|
if (!envValue || envValue == "")
|
package/dist/getaccesstoken.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAccessToken =
|
|
3
|
+
exports.getAccessToken = getAccessToken;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
|
+
const OpenAPI_1 = require("./client/core/OpenAPI");
|
|
5
6
|
function isErrorResponse(response) {
|
|
6
7
|
return typeof (response.error) == 'string';
|
|
7
8
|
}
|
|
8
|
-
let _access_token = undefined;
|
|
9
9
|
async function getAccessToken(config) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
body.append("grant_type", "client_credentials");
|
|
20
|
-
if (options.actAs)
|
|
21
|
-
body.append("act_as", options.actAs);
|
|
22
|
-
const response = await (await fetch(authUrl, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers: headers,
|
|
25
|
-
body: body.toString()
|
|
26
|
-
})).json();
|
|
27
|
-
if (isErrorResponse(response))
|
|
28
|
-
throw new Error("Authentication error: " + response.error_description);
|
|
29
|
-
return response.access_token;
|
|
30
|
-
})(config);
|
|
10
|
+
const options = config ?? (0, config_1.getCmsIntegrationApiConfigFromEnvironment)();
|
|
11
|
+
const authUrl = new URL(`${OpenAPI_1.OpenAPI.BASE}/oauth/token`, options.base).href;
|
|
12
|
+
const headers = new Headers();
|
|
13
|
+
headers.append('Authorization', `Basic ${base64Encode(`${options.clientId}:${options.clientSecret}`)}`);
|
|
14
|
+
headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
15
|
+
headers.append('Connection', 'close');
|
|
16
|
+
if (options.debug) {
|
|
17
|
+
console.log(`⚪ [CMS API] Using authentication endpoint: ${authUrl}`);
|
|
18
|
+
console.log(`⚪ [CMS API] Retrieving new credentials for ${options.clientId}, acting as ${options.actAs ?? options.clientId ?? '-'}`);
|
|
31
19
|
}
|
|
32
|
-
|
|
20
|
+
const body = new URLSearchParams();
|
|
21
|
+
body.append("grant_type", "client_credentials");
|
|
22
|
+
if (options.actAs)
|
|
23
|
+
body.append("act_as", options.actAs);
|
|
24
|
+
const httpResponse = await fetch(authUrl, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: headers,
|
|
27
|
+
body: body.toString(),
|
|
28
|
+
cache: "no-store"
|
|
29
|
+
});
|
|
30
|
+
const response = await httpResponse.json();
|
|
31
|
+
if (isErrorResponse(response))
|
|
32
|
+
throw new Error("Authentication error: " + response.error_description);
|
|
33
|
+
return response.access_token;
|
|
33
34
|
}
|
|
34
|
-
exports.getAccessToken = getAccessToken;
|
|
35
35
|
function base64Encode(input) {
|
|
36
36
|
if (btoa && typeof (btoa) == 'function')
|
|
37
37
|
return btoa(input);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,22 @@ import { type CmsIntegrationApiOptions } from './config';
|
|
|
7
7
|
import { ApiClient as CmsIntegrationApiClient } from './api-client';
|
|
8
8
|
export declare function createClient(config?: CmsIntegrationApiOptions): CmsIntegrationApiClient;
|
|
9
9
|
export declare enum ContentRoots {
|
|
10
|
+
/**
|
|
11
|
+
* The Global root node of the Content Tree
|
|
12
|
+
*/
|
|
10
13
|
SystemRoot = "43f936c99b234ea397b261c538ad07c9",
|
|
11
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The root node of the Multi-Channel Content
|
|
16
|
+
*/
|
|
17
|
+
MultiChannelContent = "41118A415C8C4BE08E73520FF3DE8244",
|
|
18
|
+
/**
|
|
19
|
+
* The root node of the Trash
|
|
20
|
+
*/
|
|
21
|
+
Trash = "2f40ba47f4fc47aea2440b909d4cf988",
|
|
22
|
+
/**
|
|
23
|
+
* The root node of the "For all sites" folder
|
|
24
|
+
*/
|
|
25
|
+
ForAllSites = "e56f85d0e8334e02976a2d11fe4d598c"
|
|
12
26
|
}
|
|
13
27
|
export declare enum ContentTypeKeys {
|
|
14
28
|
Folder = "SysContentFolder"
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ContentTypeKeys = exports.ContentRoots = exports.
|
|
29
|
+
exports.ContentTypeKeys = exports.ContentRoots = exports.CmsIntegrationApiClient = exports.ApiClient = exports.CoreClient = exports.IntegrationApi = void 0;
|
|
30
|
+
exports.createClient = createClient;
|
|
30
31
|
__exportStar(require("./config"), exports);
|
|
31
32
|
exports.IntegrationApi = __importStar(require("./client"));
|
|
32
33
|
var client_1 = require("./client");
|
|
@@ -39,11 +40,24 @@ const api_client_3 = require("./api-client");
|
|
|
39
40
|
function createClient(config) {
|
|
40
41
|
return new api_client_3.ApiClient(config);
|
|
41
42
|
}
|
|
42
|
-
exports.createClient = createClient;
|
|
43
43
|
var ContentRoots;
|
|
44
44
|
(function (ContentRoots) {
|
|
45
|
+
/**
|
|
46
|
+
* The Global root node of the Content Tree
|
|
47
|
+
*/
|
|
45
48
|
ContentRoots["SystemRoot"] = "43f936c99b234ea397b261c538ad07c9";
|
|
49
|
+
/**
|
|
50
|
+
* The root node of the Multi-Channel Content
|
|
51
|
+
*/
|
|
46
52
|
ContentRoots["MultiChannelContent"] = "41118A415C8C4BE08E73520FF3DE8244";
|
|
53
|
+
/**
|
|
54
|
+
* The root node of the Trash
|
|
55
|
+
*/
|
|
56
|
+
ContentRoots["Trash"] = "2f40ba47f4fc47aea2440b909d4cf988";
|
|
57
|
+
/**
|
|
58
|
+
* The root node of the "For all sites" folder
|
|
59
|
+
*/
|
|
60
|
+
ContentRoots["ForAllSites"] = "e56f85d0e8334e02976a2d11fe4d598c";
|
|
47
61
|
})(ContentRoots || (exports.ContentRoots = ContentRoots = {}));
|
|
48
62
|
var ContentTypeKeys;
|
|
49
63
|
(function (ContentTypeKeys) {
|
package/dist/version.json
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@remkoj/optimizely-cms-api",
|
|
3
3
|
"displayName": "Optimizely CMS - Integration API Client",
|
|
4
4
|
"description": "A Javascript client for the Integration API provided by the Optimizely CMS.",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.1-pre1",
|
|
6
6
|
"packageManager": "yarn@4.3.0",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"license": "Apache-2.0",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"./dist"
|
|
13
13
|
],
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@types/node": "^20.14.
|
|
15
|
+
"@types/node": "^20.14.9",
|
|
16
16
|
"dotenv": "^16.4.5",
|
|
17
|
-
"glob": "^10.4.
|
|
17
|
+
"glob": "^10.4.2",
|
|
18
18
|
"openapi-typescript-codegen": "^0.29.0",
|
|
19
19
|
"tslib": "^2.6.3",
|
|
20
|
-
"typescript": "^5.
|
|
20
|
+
"typescript": "^5.5.2"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "tsc --build --clean",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"generate-client": "yarn openapi --input ./integrationapi.spec.json --output ./src/client --name CmsIntegrationApiClient",
|
|
29
29
|
"generate-spec": "yarn node scripts/update-spec.js"
|
|
30
30
|
},
|
|
31
|
-
"stableVersion": "2.0.
|
|
31
|
+
"stableVersion": "2.0.1"
|
|
32
32
|
}
|