@dotcms/client 1.7.1-next.2379 → 26.7.27-1
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/index.cjs.js
CHANGED
|
@@ -4,6 +4,90 @@ var consola = require('consola');
|
|
|
4
4
|
var types = require('@dotcms/types');
|
|
5
5
|
var internal = require('./internal.cjs.js');
|
|
6
6
|
|
|
7
|
+
const SDK_VERSION = "26.07.27-01";
|
|
8
|
+
|
|
9
|
+
const DOTCMS_VERSION_HEADER = 'x-dotcms-version';
|
|
10
|
+
const DOTCMS_MIN_SDK_HEADER = 'x-dotcms-min-sdk';
|
|
11
|
+
let hasWarnedOutdatedSdk = false;
|
|
12
|
+
let hasWarnedNewerSdk = false;
|
|
13
|
+
/**
|
|
14
|
+
* Parses a date-lockstep version string (e.g. "26.7.14-1") into a flat array of numeric
|
|
15
|
+
* segments for ordered comparison. Returns null if any segment isn't a plain integer
|
|
16
|
+
* (e.g. an LTS-shaped version like "26.7.14_lts_v1"), so callers can skip the comparison
|
|
17
|
+
* instead of comparing unrelated formats.
|
|
18
|
+
*/
|
|
19
|
+
const parseVersionSegments = (version) => {
|
|
20
|
+
const segments = version
|
|
21
|
+
.trim()
|
|
22
|
+
.replace(/^v/i, '')
|
|
23
|
+
.split(/[.-]/)
|
|
24
|
+
.map((segment) => Number(segment));
|
|
25
|
+
return segments.some((segment) => !Number.isFinite(segment)) ? null : segments;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Compares two date-lockstep version strings segment by segment as numbers (not as
|
|
29
|
+
* strings), so e.g. "26.10.1" correctly compares greater than "26.7.13". Returns null
|
|
30
|
+
* (instead of throwing) if either version can't be parsed, so callers can fail open.
|
|
31
|
+
*/
|
|
32
|
+
const compareVersions = (a, b) => {
|
|
33
|
+
const segmentsA = parseVersionSegments(a);
|
|
34
|
+
const segmentsB = parseVersionSegments(b);
|
|
35
|
+
if (!segmentsA || !segmentsB) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const length = Math.max(segmentsA.length, segmentsB.length);
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
const partA = segmentsA[i] ?? 0;
|
|
41
|
+
const partB = segmentsB[i] ?? 0;
|
|
42
|
+
if (partA !== partB) {
|
|
43
|
+
return partA > partB ? 1 : -1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Reads the dotCMS server's advertised version and minimum supported SDK version off a
|
|
50
|
+
* response (see `SdkVersionWebInterceptor` on the server) and logs a console error/warning
|
|
51
|
+
* if this SDK is outside the compatible range:
|
|
52
|
+
*
|
|
53
|
+
* - `ownVersion < X-DotCMS-Min-SDK` → console.error, the SDK must be upgraded.
|
|
54
|
+
* - `ownVersion > X-DotCMS-Version` → console.warn, the SDK is ahead of this server and
|
|
55
|
+
* may call APIs it doesn't have yet (e.g. a dev environment newer than the one it's
|
|
56
|
+
* pointed at).
|
|
57
|
+
*
|
|
58
|
+
* Fails open by design: if the headers are absent (an older server that doesn't send
|
|
59
|
+
* them yet) or unparsable, this silently does nothing — it never throws and never
|
|
60
|
+
* changes request/response behavior. Each kind of warning logs at most once per session
|
|
61
|
+
* so it doesn't spam the console on every request.
|
|
62
|
+
*/
|
|
63
|
+
const checkSdkCompatibility = (headers, ownVersion) => {
|
|
64
|
+
try {
|
|
65
|
+
if (!ownVersion) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const serverVersion = headers.get(DOTCMS_VERSION_HEADER);
|
|
69
|
+
const minSdkVersion = headers.get(DOTCMS_MIN_SDK_HEADER);
|
|
70
|
+
if (!serverVersion || !minSdkVersion) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!hasWarnedOutdatedSdk && (compareVersions(ownVersion, minSdkVersion) ?? 0) < 0) {
|
|
74
|
+
hasWarnedOutdatedSdk = true;
|
|
75
|
+
console.error(`[dotCMS SDK] SDK ${ownVersion} is not supported by dotCMS ${serverVersion} ` +
|
|
76
|
+
`(minimum required: ${minSdkVersion}). Upgrade required: ` +
|
|
77
|
+
'https://www.dotcms.com/docs/latest/sdk-version-compatibility');
|
|
78
|
+
}
|
|
79
|
+
if (!hasWarnedNewerSdk && (compareVersions(ownVersion, serverVersion) ?? 0) > 0) {
|
|
80
|
+
hasWarnedNewerSdk = true;
|
|
81
|
+
console.warn(`[dotCMS SDK] SDK ${ownVersion} is newer than dotCMS ${serverVersion} ` +
|
|
82
|
+
'and may call APIs the server does not have yet.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Never let a compatibility-check failure break the actual request.
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Build-time constant — see sdkVersionPlugin in rollup.config.cjs.
|
|
7
91
|
/**
|
|
8
92
|
* HTTP client implementation using the Fetch API.
|
|
9
93
|
*
|
|
@@ -71,6 +155,11 @@ class FetchHttpClient extends types.BaseHttpClient {
|
|
|
71
155
|
try {
|
|
72
156
|
// Use native fetch API - no additional configuration needed
|
|
73
157
|
const response = await fetch(url, options);
|
|
158
|
+
// Fire-and-forget: reads X-DotCMS-Version / X-DotCMS-Min-SDK off the
|
|
159
|
+
// response and logs a console warning on mismatch. Fails open (no headers,
|
|
160
|
+
// e.g. an older server) and never throws, so this can't affect the actual
|
|
161
|
+
// request/response handling below.
|
|
162
|
+
checkSdkCompatibility(response.headers, SDK_VERSION);
|
|
74
163
|
if (!response.ok) {
|
|
75
164
|
// Parse response body for error context
|
|
76
165
|
let errorBody;
|
package/index.esm.js
CHANGED
|
@@ -2,6 +2,90 @@ import { consola } from 'consola';
|
|
|
2
2
|
import { BaseHttpClient, DISTANCE_FUNCTIONS, DotHttpError, DotErrorAISearch, DotErrorContent, DotErrorNavigation, UVE_MODE, DotErrorPage } from '@dotcms/types';
|
|
3
3
|
import { graphqlToPageEntity } from './internal.esm.js';
|
|
4
4
|
|
|
5
|
+
const SDK_VERSION = "26.07.27-01";
|
|
6
|
+
|
|
7
|
+
const DOTCMS_VERSION_HEADER = 'x-dotcms-version';
|
|
8
|
+
const DOTCMS_MIN_SDK_HEADER = 'x-dotcms-min-sdk';
|
|
9
|
+
let hasWarnedOutdatedSdk = false;
|
|
10
|
+
let hasWarnedNewerSdk = false;
|
|
11
|
+
/**
|
|
12
|
+
* Parses a date-lockstep version string (e.g. "26.7.14-1") into a flat array of numeric
|
|
13
|
+
* segments for ordered comparison. Returns null if any segment isn't a plain integer
|
|
14
|
+
* (e.g. an LTS-shaped version like "26.7.14_lts_v1"), so callers can skip the comparison
|
|
15
|
+
* instead of comparing unrelated formats.
|
|
16
|
+
*/
|
|
17
|
+
const parseVersionSegments = (version) => {
|
|
18
|
+
const segments = version
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/^v/i, '')
|
|
21
|
+
.split(/[.-]/)
|
|
22
|
+
.map((segment) => Number(segment));
|
|
23
|
+
return segments.some((segment) => !Number.isFinite(segment)) ? null : segments;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Compares two date-lockstep version strings segment by segment as numbers (not as
|
|
27
|
+
* strings), so e.g. "26.10.1" correctly compares greater than "26.7.13". Returns null
|
|
28
|
+
* (instead of throwing) if either version can't be parsed, so callers can fail open.
|
|
29
|
+
*/
|
|
30
|
+
const compareVersions = (a, b) => {
|
|
31
|
+
const segmentsA = parseVersionSegments(a);
|
|
32
|
+
const segmentsB = parseVersionSegments(b);
|
|
33
|
+
if (!segmentsA || !segmentsB) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const length = Math.max(segmentsA.length, segmentsB.length);
|
|
37
|
+
for (let i = 0; i < length; i++) {
|
|
38
|
+
const partA = segmentsA[i] ?? 0;
|
|
39
|
+
const partB = segmentsB[i] ?? 0;
|
|
40
|
+
if (partA !== partB) {
|
|
41
|
+
return partA > partB ? 1 : -1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Reads the dotCMS server's advertised version and minimum supported SDK version off a
|
|
48
|
+
* response (see `SdkVersionWebInterceptor` on the server) and logs a console error/warning
|
|
49
|
+
* if this SDK is outside the compatible range:
|
|
50
|
+
*
|
|
51
|
+
* - `ownVersion < X-DotCMS-Min-SDK` → console.error, the SDK must be upgraded.
|
|
52
|
+
* - `ownVersion > X-DotCMS-Version` → console.warn, the SDK is ahead of this server and
|
|
53
|
+
* may call APIs it doesn't have yet (e.g. a dev environment newer than the one it's
|
|
54
|
+
* pointed at).
|
|
55
|
+
*
|
|
56
|
+
* Fails open by design: if the headers are absent (an older server that doesn't send
|
|
57
|
+
* them yet) or unparsable, this silently does nothing — it never throws and never
|
|
58
|
+
* changes request/response behavior. Each kind of warning logs at most once per session
|
|
59
|
+
* so it doesn't spam the console on every request.
|
|
60
|
+
*/
|
|
61
|
+
const checkSdkCompatibility = (headers, ownVersion) => {
|
|
62
|
+
try {
|
|
63
|
+
if (!ownVersion) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const serverVersion = headers.get(DOTCMS_VERSION_HEADER);
|
|
67
|
+
const minSdkVersion = headers.get(DOTCMS_MIN_SDK_HEADER);
|
|
68
|
+
if (!serverVersion || !minSdkVersion) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!hasWarnedOutdatedSdk && (compareVersions(ownVersion, minSdkVersion) ?? 0) < 0) {
|
|
72
|
+
hasWarnedOutdatedSdk = true;
|
|
73
|
+
console.error(`[dotCMS SDK] SDK ${ownVersion} is not supported by dotCMS ${serverVersion} ` +
|
|
74
|
+
`(minimum required: ${minSdkVersion}). Upgrade required: ` +
|
|
75
|
+
'https://www.dotcms.com/docs/latest/sdk-version-compatibility');
|
|
76
|
+
}
|
|
77
|
+
if (!hasWarnedNewerSdk && (compareVersions(ownVersion, serverVersion) ?? 0) > 0) {
|
|
78
|
+
hasWarnedNewerSdk = true;
|
|
79
|
+
console.warn(`[dotCMS SDK] SDK ${ownVersion} is newer than dotCMS ${serverVersion} ` +
|
|
80
|
+
'and may call APIs the server does not have yet.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Never let a compatibility-check failure break the actual request.
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Build-time constant — see sdkVersionPlugin in rollup.config.cjs.
|
|
5
89
|
/**
|
|
6
90
|
* HTTP client implementation using the Fetch API.
|
|
7
91
|
*
|
|
@@ -69,6 +153,11 @@ class FetchHttpClient extends BaseHttpClient {
|
|
|
69
153
|
try {
|
|
70
154
|
// Use native fetch API - no additional configuration needed
|
|
71
155
|
const response = await fetch(url, options);
|
|
156
|
+
// Fire-and-forget: reads X-DotCMS-Version / X-DotCMS-Min-SDK off the
|
|
157
|
+
// response and logs a console warning on mismatch. Fails open (no headers,
|
|
158
|
+
// e.g. an older server) and never throws, so this can't affect the actual
|
|
159
|
+
// request/response handling below.
|
|
160
|
+
checkSdkCompatibility(response.headers, SDK_VERSION);
|
|
72
161
|
if (!response.ok) {
|
|
73
162
|
// Parse response body for error context
|
|
74
163
|
let errorBody;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.07.27-01",
|
|
4
4
|
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
"module": "./index.esm.js",
|
|
54
54
|
"main": "./index.cjs.js",
|
|
55
55
|
"types": "./index.d.ts"
|
|
56
|
-
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.0.0-test";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two date-lockstep version strings segment by segment as numbers (not as
|
|
3
|
+
* strings), so e.g. "26.10.1" correctly compares greater than "26.7.13". Returns null
|
|
4
|
+
* (instead of throwing) if either version can't be parsed, so callers can fail open.
|
|
5
|
+
*/
|
|
6
|
+
export declare const compareVersions: (a: string, b: string) => number | null;
|
|
7
|
+
/**
|
|
8
|
+
* Resets the once-per-session warning flags. Test-only — production code never needs
|
|
9
|
+
* to warn more than once per page load.
|
|
10
|
+
*/
|
|
11
|
+
export declare const resetSdkCompatibilityWarnings: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Reads the dotCMS server's advertised version and minimum supported SDK version off a
|
|
14
|
+
* response (see `SdkVersionWebInterceptor` on the server) and logs a console error/warning
|
|
15
|
+
* if this SDK is outside the compatible range:
|
|
16
|
+
*
|
|
17
|
+
* - `ownVersion < X-DotCMS-Min-SDK` → console.error, the SDK must be upgraded.
|
|
18
|
+
* - `ownVersion > X-DotCMS-Version` → console.warn, the SDK is ahead of this server and
|
|
19
|
+
* may call APIs it doesn't have yet (e.g. a dev environment newer than the one it's
|
|
20
|
+
* pointed at).
|
|
21
|
+
*
|
|
22
|
+
* Fails open by design: if the headers are absent (an older server that doesn't send
|
|
23
|
+
* them yet) or unparsable, this silently does nothing — it never throws and never
|
|
24
|
+
* changes request/response behavior. Each kind of warning logs at most once per session
|
|
25
|
+
* so it doesn't spam the console on every request.
|
|
26
|
+
*/
|
|
27
|
+
export declare const checkSdkCompatibility: (headers: Headers, ownVersion: string) => void;
|