@adobe/spacecat-shared-tokowaka-client 1.13.2 → 1.13.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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/index.js +13 -2
- package/src/mappers/commerce-page-enrichment-mapper.js +12 -4
- package/src/mappers/generic-mapper.js +6 -2
- package/test/cdn/base-cdn-client.test.js +0 -2
- package/test/cdn/cdn-client-registry.test.js +0 -1
- package/test/cdn/cloudfront-cdn-client.test.js +0 -2
- package/test/cdn/fastly-cdn-client.test.js +0 -2
- package/test/fastly-kv-client.test.js +0 -2
- package/test/index.test.js +78 -10
- package/test/mappers/base-mapper.test.js +0 -1
- package/test/mappers/commerce-page-enrichment-mapper.test.js +15 -7
- package/test/mappers/content-mapper.test.js +0 -2
- package/test/mappers/faq-mapper.test.js +0 -2
- package/test/mappers/generic-mapper.test.js +0 -2
- package/test/mappers/headings-mapper.test.js +0 -2
- package/test/mappers/mapper-registry.test.js +0 -1
- package/test/mappers/prerender-mapper.test.js +0 -2
- package/test/mappers/readability-mapper.test.js +0 -2
- package/test/mappers/semantic-value-visibility-mapper.test.js +0 -2
- package/test/mappers/toc-mapper.test.js +0 -2
- package/test/utils/html-utils.test.js +12 -6
- package/test/utils/htmlToHast.test.js +0 -2
- package/test/utils/patch-utils.test.js +0 -2
- package/test/utils/s3-utils.test.js +0 -2
- package/test/utils/site-utils.test.js +0 -2
- package/test/utils/suggestion-utils.test.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [@adobe/spacecat-shared-tokowaka-client-v1.13.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.13.2...@adobe/spacecat-shared-tokowaka-client-v1.13.3) (2026-04-09)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* skip HTTP check when edge optimize already enabled in site config ([#1519](https://github.com/adobe/spacecat-shared/issues/1519)) ([057608d](https://github.com/adobe/spacecat-shared/commit/057608da86fef2538b68a425d96fa351a4231076))
|
|
6
|
+
|
|
1
7
|
## [@adobe/spacecat-shared-tokowaka-client-v1.13.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.13.1...@adobe/spacecat-shared-tokowaka-client-v1.13.2) (2026-04-06)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1129,6 +1129,13 @@ class TokowakaClient {
|
|
|
1129
1129
|
throw this.#createError('Path is required', HTTP_BAD_REQUEST);
|
|
1130
1130
|
}
|
|
1131
1131
|
|
|
1132
|
+
const currentConfig = site.getConfig();
|
|
1133
|
+
const existingEdgeConfig = currentConfig?.getEdgeOptimizeConfig();
|
|
1134
|
+
const isAlreadyEnabled = existingEdgeConfig?.enabled ?? false;
|
|
1135
|
+
if (isAlreadyEnabled) {
|
|
1136
|
+
return { edgeOptimizeEnabled: true };
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1132
1139
|
const baseURL = getEffectiveBaseURL(site);
|
|
1133
1140
|
const targetUrl = new URL(path, baseURL).toString();
|
|
1134
1141
|
|
|
@@ -1341,8 +1348,12 @@ class TokowakaClient {
|
|
|
1341
1348
|
|
|
1342
1349
|
if (regexPatterns.length > 0) {
|
|
1343
1350
|
const covered = allSuggestions.filter((s) => {
|
|
1344
|
-
if (s.getId() === suggestion.getId())
|
|
1345
|
-
|
|
1351
|
+
if (s.getId() === suggestion.getId()) {
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
if (skippedInBatchIds.has(s.getId())) {
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1346
1357
|
if (!isEdgeDeployableSuggestionStatus(s.getStatus())) {
|
|
1347
1358
|
return false;
|
|
1348
1359
|
}
|
|
@@ -58,26 +58,34 @@ function renderList(items, cls) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function renderValue(key, value, cls) {
|
|
61
|
-
if (value == null)
|
|
61
|
+
if (value == null) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
62
64
|
|
|
63
65
|
if (key === 'facts.facets.category_path' || key === 'category') {
|
|
64
66
|
return `<p class="${cls}">${renderCategoryPath(value)}</p>`;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
if (Array.isArray(value)) {
|
|
68
|
-
if (value.length === 0)
|
|
70
|
+
if (value.length === 0) {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
69
73
|
return renderList(value, cls);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
if (typeof value === 'object') {
|
|
73
77
|
const entries = Object.entries(value).filter(([, v]) => v != null && v !== '');
|
|
74
|
-
if (entries.length === 0)
|
|
78
|
+
if (entries.length === 0) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
75
81
|
const items = entries.map(([k, v]) => `${escapeHtml(k)}: ${escapeHtml(String(v))}`);
|
|
76
82
|
return renderList(items, cls);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
const str = String(value);
|
|
80
|
-
if (!str)
|
|
86
|
+
if (!str) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
81
89
|
return `<p class="${cls}">${escapeHtml(str)}</p>`;
|
|
82
90
|
}
|
|
83
91
|
|
|
@@ -36,8 +36,12 @@ export default class GenericMapper extends BaseOpportunityMapper {
|
|
|
36
36
|
|
|
37
37
|
// eslint-disable-next-line class-methods-use-this
|
|
38
38
|
#resolveValue(data) {
|
|
39
|
-
if (data.format === 'html')
|
|
40
|
-
|
|
39
|
+
if (data.format === 'html') {
|
|
40
|
+
return htmlToHast(data.patchValue);
|
|
41
|
+
}
|
|
42
|
+
if (data.format === 'hast' || data.format === 'json') {
|
|
43
|
+
return JSON.parse(data.patchValue);
|
|
44
|
+
}
|
|
41
45
|
return data.patchValue;
|
|
42
46
|
}
|
|
43
47
|
|
package/test/index.test.js
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/* eslint-env mocha */
|
|
14
|
-
|
|
15
13
|
import { expect, use } from 'chai';
|
|
16
14
|
import sinon from 'sinon';
|
|
17
15
|
import sinonChai from 'sinon-chai';
|
|
@@ -3844,7 +3842,7 @@ describe('TokowakaClient', () => {
|
|
|
3844
3842
|
const site = {
|
|
3845
3843
|
getId: () => 'site-id',
|
|
3846
3844
|
getBaseURL: () => 'https://example.com',
|
|
3847
|
-
getConfig: () => ({}),
|
|
3845
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
3848
3846
|
getDeliveryType: () => 'aem_edge',
|
|
3849
3847
|
};
|
|
3850
3848
|
|
|
@@ -3861,7 +3859,7 @@ describe('TokowakaClient', () => {
|
|
|
3861
3859
|
const site = {
|
|
3862
3860
|
getId: () => 'site-id',
|
|
3863
3861
|
getBaseURL: () => 'https://example.com',
|
|
3864
|
-
getConfig: () => ({}),
|
|
3862
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
3865
3863
|
getDeliveryType: () => 'aem_edge',
|
|
3866
3864
|
};
|
|
3867
3865
|
|
|
@@ -3874,6 +3872,76 @@ describe('TokowakaClient', () => {
|
|
|
3874
3872
|
});
|
|
3875
3873
|
});
|
|
3876
3874
|
|
|
3875
|
+
describe('Early Return (Already Enabled via Site Config)', () => {
|
|
3876
|
+
it('should return edgeOptimizeEnabled: true immediately when enabled is boolean true, without making HTTP request', async () => {
|
|
3877
|
+
const site = {
|
|
3878
|
+
getId: () => 'site-id',
|
|
3879
|
+
getBaseURL: () => 'https://example.com',
|
|
3880
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => ({ enabled: true }) }),
|
|
3881
|
+
getDeliveryType: () => 'aem_edge',
|
|
3882
|
+
};
|
|
3883
|
+
|
|
3884
|
+
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/');
|
|
3885
|
+
|
|
3886
|
+
expect(result).to.deep.equal({ edgeOptimizeEnabled: true });
|
|
3887
|
+
expect(tracingFetchStub).to.not.have.been.called;
|
|
3888
|
+
});
|
|
3889
|
+
|
|
3890
|
+
it('should return edgeOptimizeEnabled: true immediately when enabled is a timestamp (number), without making HTTP request', async () => {
|
|
3891
|
+
const site = {
|
|
3892
|
+
getId: () => 'site-id',
|
|
3893
|
+
getBaseURL: () => 'https://example.com',
|
|
3894
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => ({ enabled: 1772531669121 }) }),
|
|
3895
|
+
getDeliveryType: () => 'aem_edge',
|
|
3896
|
+
};
|
|
3897
|
+
|
|
3898
|
+
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/products');
|
|
3899
|
+
|
|
3900
|
+
expect(result).to.deep.equal({ edgeOptimizeEnabled: true });
|
|
3901
|
+
expect(tracingFetchStub).to.not.have.been.called;
|
|
3902
|
+
});
|
|
3903
|
+
|
|
3904
|
+
it('should NOT return early and should make HTTP request when enabled is false', async () => {
|
|
3905
|
+
const site = {
|
|
3906
|
+
getId: () => 'site-id',
|
|
3907
|
+
getBaseURL: () => 'https://example.com',
|
|
3908
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => ({ enabled: false }) }),
|
|
3909
|
+
getDeliveryType: () => 'aem_edge',
|
|
3910
|
+
};
|
|
3911
|
+
|
|
3912
|
+
const mockResponse = {
|
|
3913
|
+
status: 200,
|
|
3914
|
+
headers: { get: () => null },
|
|
3915
|
+
};
|
|
3916
|
+
tracingFetchStub.resolves(mockResponse);
|
|
3917
|
+
|
|
3918
|
+
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/');
|
|
3919
|
+
|
|
3920
|
+
expect(result.edgeOptimizeEnabled).to.be.false;
|
|
3921
|
+
expect(tracingFetchStub).to.have.been.called;
|
|
3922
|
+
});
|
|
3923
|
+
|
|
3924
|
+
it('should NOT return early and should make HTTP request when edgeOptimizeConfig is undefined', async () => {
|
|
3925
|
+
const site = {
|
|
3926
|
+
getId: () => 'site-id',
|
|
3927
|
+
getBaseURL: () => 'https://example.com',
|
|
3928
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
3929
|
+
getDeliveryType: () => 'aem_edge',
|
|
3930
|
+
};
|
|
3931
|
+
|
|
3932
|
+
const mockResponse = {
|
|
3933
|
+
status: 200,
|
|
3934
|
+
headers: { get: () => null },
|
|
3935
|
+
};
|
|
3936
|
+
tracingFetchStub.resolves(mockResponse);
|
|
3937
|
+
|
|
3938
|
+
const result = await esmockClient.checkEdgeOptimizeStatus(site, '/');
|
|
3939
|
+
|
|
3940
|
+
expect(result.edgeOptimizeEnabled).to.be.false;
|
|
3941
|
+
expect(tracingFetchStub).to.have.been.called;
|
|
3942
|
+
});
|
|
3943
|
+
});
|
|
3944
|
+
|
|
3877
3945
|
describe('Direct Response (No Redirect)', () => {
|
|
3878
3946
|
let site;
|
|
3879
3947
|
|
|
@@ -3881,7 +3949,7 @@ describe('TokowakaClient', () => {
|
|
|
3881
3949
|
site = {
|
|
3882
3950
|
getId: () => 'site-id',
|
|
3883
3951
|
getBaseURL: () => 'https://example.com',
|
|
3884
|
-
getConfig: () => ({}),
|
|
3952
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
3885
3953
|
getDeliveryType: () => 'aem_edge',
|
|
3886
3954
|
};
|
|
3887
3955
|
});
|
|
@@ -4006,7 +4074,7 @@ describe('TokowakaClient', () => {
|
|
|
4006
4074
|
site = {
|
|
4007
4075
|
getId: () => 'site-id',
|
|
4008
4076
|
getBaseURL: () => 'https://example.com',
|
|
4009
|
-
getConfig: () => ({}),
|
|
4077
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
4010
4078
|
getDeliveryType: () => 'aem_edge',
|
|
4011
4079
|
};
|
|
4012
4080
|
clock = sinon.useFakeTimers();
|
|
@@ -4141,7 +4209,7 @@ describe('TokowakaClient', () => {
|
|
|
4141
4209
|
site = {
|
|
4142
4210
|
getId: () => 'site-id',
|
|
4143
4211
|
getBaseURL: () => 'https://example.com',
|
|
4144
|
-
getConfig: () => ({}),
|
|
4212
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
4145
4213
|
getDeliveryType: () => 'aem_edge',
|
|
4146
4214
|
};
|
|
4147
4215
|
});
|
|
@@ -4178,7 +4246,7 @@ describe('TokowakaClient', () => {
|
|
|
4178
4246
|
site = {
|
|
4179
4247
|
getId: () => 'site-id',
|
|
4180
4248
|
getBaseURL: () => 'https://example.com/',
|
|
4181
|
-
getConfig: () => ({}),
|
|
4249
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
4182
4250
|
getDeliveryType: () => 'aem_edge',
|
|
4183
4251
|
};
|
|
4184
4252
|
|
|
@@ -4199,7 +4267,7 @@ describe('TokowakaClient', () => {
|
|
|
4199
4267
|
site = {
|
|
4200
4268
|
getId: () => 'site-id',
|
|
4201
4269
|
getBaseURL: () => 'https://example.com',
|
|
4202
|
-
getConfig: () => ({}),
|
|
4270
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
4203
4271
|
getDeliveryType: () => 'aem_edge',
|
|
4204
4272
|
};
|
|
4205
4273
|
|
|
@@ -4224,7 +4292,7 @@ describe('TokowakaClient', () => {
|
|
|
4224
4292
|
site = {
|
|
4225
4293
|
getId: () => 'site-id',
|
|
4226
4294
|
getBaseURL: () => 'https://example.com',
|
|
4227
|
-
getConfig: () => ({}),
|
|
4295
|
+
getConfig: () => ({ getEdgeOptimizeConfig: () => undefined }),
|
|
4228
4296
|
getDeliveryType: () => 'aem_edge',
|
|
4229
4297
|
};
|
|
4230
4298
|
});
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/* eslint-env mocha */
|
|
14
|
-
|
|
15
13
|
import { expect } from 'chai';
|
|
16
14
|
import sinon from 'sinon';
|
|
17
15
|
import CommercePageEnrichmentMapper from '../../src/mappers/commerce-page-enrichment-mapper.js';
|
|
@@ -20,11 +18,15 @@ import CommercePageEnrichmentMapper from '../../src/mappers/commerce-page-enrich
|
|
|
20
18
|
* Recursively finds the first HAST element node matching a predicate.
|
|
21
19
|
*/
|
|
22
20
|
function findNode(node, predicate) {
|
|
23
|
-
if (predicate(node))
|
|
21
|
+
if (predicate(node)) {
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
24
|
if (node.children) {
|
|
25
25
|
for (const child of node.children) {
|
|
26
26
|
const found = findNode(child, predicate);
|
|
27
|
-
if (found)
|
|
27
|
+
if (found) {
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
return null;
|
|
@@ -35,7 +37,9 @@ function findNode(node, predicate) {
|
|
|
35
37
|
*/
|
|
36
38
|
function findAllNodes(node, predicate) {
|
|
37
39
|
const results = [];
|
|
38
|
-
if (predicate(node))
|
|
40
|
+
if (predicate(node)) {
|
|
41
|
+
results.push(node);
|
|
42
|
+
}
|
|
39
43
|
if (node.children) {
|
|
40
44
|
for (const child of node.children) {
|
|
41
45
|
results.push(...findAllNodes(child, predicate));
|
|
@@ -48,8 +52,12 @@ function findAllNodes(node, predicate) {
|
|
|
48
52
|
* Extracts concatenated text content from a HAST subtree.
|
|
49
53
|
*/
|
|
50
54
|
function textContent(node) {
|
|
51
|
-
if (node.type === 'text')
|
|
52
|
-
|
|
55
|
+
if (node.type === 'text') {
|
|
56
|
+
return node.value;
|
|
57
|
+
}
|
|
58
|
+
if (node.children) {
|
|
59
|
+
return node.children.map(textContent).join('');
|
|
60
|
+
}
|
|
53
61
|
return '';
|
|
54
62
|
}
|
|
55
63
|
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/* eslint-env mocha */
|
|
14
|
-
|
|
15
13
|
import { expect } from 'chai';
|
|
16
14
|
import sinon from 'sinon';
|
|
17
15
|
import { fetchHtmlWithWarmup, calculateForwardedHost } from '../../src/utils/custom-html-utils.js';
|
|
@@ -656,8 +654,12 @@ describe('HTML Utils', () => {
|
|
|
656
654
|
statusText: 'OK',
|
|
657
655
|
headers: {
|
|
658
656
|
get: (name) => {
|
|
659
|
-
if (name === 'x-edgeoptimize-cache')
|
|
660
|
-
|
|
657
|
+
if (name === 'x-edgeoptimize-cache') {
|
|
658
|
+
return 'HIT';
|
|
659
|
+
}
|
|
660
|
+
if (name === 'x-edgeoptimize-proxy') {
|
|
661
|
+
return 'true';
|
|
662
|
+
}
|
|
661
663
|
return null;
|
|
662
664
|
},
|
|
663
665
|
},
|
|
@@ -794,8 +796,12 @@ describe('HTML Utils', () => {
|
|
|
794
796
|
statusText: 'OK',
|
|
795
797
|
headers: {
|
|
796
798
|
get: (name) => {
|
|
797
|
-
if (name === 'x-edgeoptimize-cache')
|
|
798
|
-
|
|
799
|
+
if (name === 'x-edgeoptimize-cache') {
|
|
800
|
+
return 'HIT';
|
|
801
|
+
}
|
|
802
|
+
if (name === 'x-edgeoptimize-proxy') {
|
|
803
|
+
return 'true';
|
|
804
|
+
}
|
|
799
805
|
return null;
|
|
800
806
|
},
|
|
801
807
|
},
|