@adobe/spacecat-shared-tokowaka-client 1.4.2 → 1.4.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 +7 -0
- package/package.json +1 -1
- package/src/index.js +5 -14
- package/src/utils/custom-html-utils.js +5 -5
- package/test/index.test.js +5 -18
- package/test/utils/html-utils.test.js +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.4.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.4.2...@adobe/spacecat-shared-tokowaka-client-v1.4.3) (2025-12-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* revert using preview key in Edge Preview API ([#1244](https://github.com/adobe/spacecat-shared/issues/1244)) ([8ac3ff6](https://github.com/adobe/spacecat-shared/commit/8ac3ff6b397a2235f1df4fffa6918f6fe6dc107d)), closes [adobe/spacecat-shared#1228](https://github.com/adobe/spacecat-shared/issues/1228)
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-tokowaka-client-v1.4.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.4.1...@adobe/spacecat-shared-tokowaka-client-v1.4.2) (2025-12-12)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -700,11 +700,11 @@ class TokowakaClient {
|
|
|
700
700
|
*/
|
|
701
701
|
async previewSuggestions(site, opportunity, suggestions, options = {}) {
|
|
702
702
|
// Get site's forwarded host for preview
|
|
703
|
-
const { forwardedHost } = site.getConfig()?.getTokowakaConfig() || {};
|
|
703
|
+
const { forwardedHost, apiKey } = site.getConfig()?.getTokowakaConfig() || {};
|
|
704
704
|
|
|
705
|
-
if (!hasText(forwardedHost)) {
|
|
705
|
+
if (!hasText(forwardedHost) || !hasText(apiKey)) {
|
|
706
706
|
throw this.#createError(
|
|
707
|
-
'Site does not have a Tokowaka forwarded host configured. '
|
|
707
|
+
'Site does not have a Tokowaka API key or forwarded host configured. '
|
|
708
708
|
+ 'Please onboard the site to Tokowaka first.',
|
|
709
709
|
HTTP_BAD_REQUEST,
|
|
710
710
|
);
|
|
@@ -720,15 +720,6 @@ class TokowakaClient {
|
|
|
720
720
|
);
|
|
721
721
|
}
|
|
722
722
|
|
|
723
|
-
// TOKOWAKA_PREVIEW_API_KEY is mandatory for preview
|
|
724
|
-
const tokowakaPreviewApiKey = this.env.TOKOWAKA_PREVIEW_API_KEY;
|
|
725
|
-
if (!hasText(tokowakaPreviewApiKey)) {
|
|
726
|
-
throw this.#createError(
|
|
727
|
-
'TOKOWAKA_PREVIEW_API_KEY is required for preview functionality',
|
|
728
|
-
HTTP_INTERNAL_SERVER_ERROR,
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
723
|
// TOKOWAKA_EDGE_URL is mandatory for preview
|
|
733
724
|
const tokowakaEdgeUrl = this.env.TOKOWAKA_EDGE_URL;
|
|
734
725
|
if (!hasText(tokowakaEdgeUrl)) {
|
|
@@ -826,7 +817,7 @@ class TokowakaClient {
|
|
|
826
817
|
// Fetch original HTML (without preview)
|
|
827
818
|
originalHtml = await fetchHtmlWithWarmup(
|
|
828
819
|
previewUrl,
|
|
829
|
-
|
|
820
|
+
apiKey,
|
|
830
821
|
forwardedHost,
|
|
831
822
|
tokowakaEdgeUrl,
|
|
832
823
|
this.log,
|
|
@@ -836,7 +827,7 @@ class TokowakaClient {
|
|
|
836
827
|
// Then fetch optimized HTML (with preview)
|
|
837
828
|
optimizedHtml = await fetchHtmlWithWarmup(
|
|
838
829
|
previewUrl,
|
|
839
|
-
|
|
830
|
+
apiKey,
|
|
840
831
|
forwardedHost,
|
|
841
832
|
tokowakaEdgeUrl,
|
|
842
833
|
this.log,
|
|
@@ -89,7 +89,7 @@ async function fetchWithRetry(url, options, maxRetries, retryDelayMs, log, fetch
|
|
|
89
89
|
* Fetches HTML content from Tokowaka edge with warmup call and retry logic
|
|
90
90
|
* Makes an initial warmup call, waits, then makes the actual call with retries
|
|
91
91
|
* @param {string} url - Full URL to fetch
|
|
92
|
-
* @param {string}
|
|
92
|
+
* @param {string} apiKey - Tokowaka API key
|
|
93
93
|
* @param {string} forwardedHost - Host to forward in x-forwarded-host header
|
|
94
94
|
* @param {string} tokowakaEdgeUrl - Tokowaka edge URL
|
|
95
95
|
* @param {boolean} isOptimized - Whether to fetch optimized HTML (with preview param)
|
|
@@ -103,7 +103,7 @@ async function fetchWithRetry(url, options, maxRetries, retryDelayMs, log, fetch
|
|
|
103
103
|
*/
|
|
104
104
|
export async function fetchHtmlWithWarmup(
|
|
105
105
|
url,
|
|
106
|
-
|
|
106
|
+
apiKey,
|
|
107
107
|
forwardedHost,
|
|
108
108
|
tokowakaEdgeUrl,
|
|
109
109
|
log,
|
|
@@ -115,8 +115,8 @@ export async function fetchHtmlWithWarmup(
|
|
|
115
115
|
throw new Error('URL is required for fetching HTML');
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
if (!hasText(
|
|
119
|
-
throw new Error('Tokowaka
|
|
118
|
+
if (!hasText(apiKey)) {
|
|
119
|
+
throw new Error('Tokowaka API key is required for fetching HTML');
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
if (!hasText(forwardedHost)) {
|
|
@@ -143,7 +143,7 @@ export async function fetchHtmlWithWarmup(
|
|
|
143
143
|
|
|
144
144
|
const headers = {
|
|
145
145
|
'x-forwarded-host': forwardedHost,
|
|
146
|
-
'x-tokowaka-
|
|
146
|
+
'x-tokowaka-api-key': apiKey,
|
|
147
147
|
'x-tokowaka-url': urlPath,
|
|
148
148
|
};
|
|
149
149
|
|
package/test/index.test.js
CHANGED
|
@@ -64,7 +64,8 @@ describe('TokowakaClient', () => {
|
|
|
64
64
|
getBaseURL: () => 'https://example.com',
|
|
65
65
|
getConfig: () => ({
|
|
66
66
|
getTokowakaConfig: () => ({
|
|
67
|
-
forwardedHost: '
|
|
67
|
+
forwardedHost: 'example.com',
|
|
68
|
+
apiKey: 'test-api-key',
|
|
68
69
|
}),
|
|
69
70
|
}),
|
|
70
71
|
};
|
|
@@ -1697,16 +1698,14 @@ describe('TokowakaClient', () => {
|
|
|
1697
1698
|
// Stub fetchConfig to return null by default (no existing config)
|
|
1698
1699
|
sinon.stub(client, 'fetchConfig').resolves(null);
|
|
1699
1700
|
|
|
1700
|
-
// Add TOKOWAKA_EDGE_URL
|
|
1701
|
+
// Add TOKOWAKA_EDGE_URL to env
|
|
1701
1702
|
client.env.TOKOWAKA_EDGE_URL = 'https://edge-dev.tokowaka.now';
|
|
1702
|
-
client.env.TOKOWAKA_PREVIEW_API_KEY = 'internal-preview-key-123';
|
|
1703
1703
|
});
|
|
1704
1704
|
|
|
1705
1705
|
afterEach(() => {
|
|
1706
1706
|
// fetchStub will be restored by global afterEach sinon.restore()
|
|
1707
1707
|
// Just clean up env changes
|
|
1708
1708
|
delete client.env.TOKOWAKA_EDGE_URL;
|
|
1709
|
-
delete client.env.TOKOWAKA_PREVIEW_API_KEY;
|
|
1710
1709
|
});
|
|
1711
1710
|
|
|
1712
1711
|
it('should preview suggestions successfully with HTML', async () => {
|
|
@@ -1735,18 +1734,6 @@ describe('TokowakaClient', () => {
|
|
|
1735
1734
|
expect(s3Client.send).to.have.been.calledOnce;
|
|
1736
1735
|
});
|
|
1737
1736
|
|
|
1738
|
-
it('should throw error if TOKOWAKA_PREVIEW_API_KEY is not configured', async () => {
|
|
1739
|
-
delete client.env.TOKOWAKA_PREVIEW_API_KEY;
|
|
1740
|
-
|
|
1741
|
-
try {
|
|
1742
|
-
await client.previewSuggestions(mockSite, mockOpportunity, mockSuggestions);
|
|
1743
|
-
expect.fail('Should have thrown error');
|
|
1744
|
-
} catch (error) {
|
|
1745
|
-
expect(error.message).to.include('TOKOWAKA_PREVIEW_API_KEY is required for preview');
|
|
1746
|
-
expect(error.status).to.equal(500);
|
|
1747
|
-
}
|
|
1748
|
-
});
|
|
1749
|
-
|
|
1750
1737
|
it('should preview prerender-only suggestions with no patches', async () => {
|
|
1751
1738
|
// Update fetchConfig to return existing config with deployed patches
|
|
1752
1739
|
client.fetchConfig.resolves({
|
|
@@ -1826,7 +1813,7 @@ describe('TokowakaClient', () => {
|
|
|
1826
1813
|
await client.previewSuggestions(mockSite, mockOpportunity, mockSuggestions);
|
|
1827
1814
|
expect.fail('Should have thrown error');
|
|
1828
1815
|
} catch (error) {
|
|
1829
|
-
expect(error.message).to.include('Site does not have a Tokowaka forwarded host configured');
|
|
1816
|
+
expect(error.message).to.include('Site does not have a Tokowaka API key or forwarded host configured');
|
|
1830
1817
|
expect(error.status).to.equal(400);
|
|
1831
1818
|
}
|
|
1832
1819
|
});
|
|
@@ -1840,7 +1827,7 @@ describe('TokowakaClient', () => {
|
|
|
1840
1827
|
await client.previewSuggestions(mockSite, mockOpportunity, mockSuggestions);
|
|
1841
1828
|
expect.fail('Should have thrown error');
|
|
1842
1829
|
} catch (error) {
|
|
1843
|
-
expect(error.message).to.include('Site does not have a Tokowaka forwarded host configured');
|
|
1830
|
+
expect(error.message).to.include('Site does not have a Tokowaka API key or forwarded host configured');
|
|
1844
1831
|
expect(error.status).to.equal(400);
|
|
1845
1832
|
}
|
|
1846
1833
|
});
|
|
@@ -54,7 +54,7 @@ describe('HTML Utils', () => {
|
|
|
54
54
|
try {
|
|
55
55
|
await fetchHtmlWithWarmup(
|
|
56
56
|
'https://example.com/page',
|
|
57
|
-
'
|
|
57
|
+
'api-key',
|
|
58
58
|
'',
|
|
59
59
|
'edge-url',
|
|
60
60
|
log,
|
|
@@ -70,7 +70,7 @@ describe('HTML Utils', () => {
|
|
|
70
70
|
try {
|
|
71
71
|
await fetchHtmlWithWarmup(
|
|
72
72
|
'https://example.com/page',
|
|
73
|
-
'
|
|
73
|
+
'api-key',
|
|
74
74
|
'host',
|
|
75
75
|
'',
|
|
76
76
|
log,
|
|
@@ -82,7 +82,7 @@ describe('HTML Utils', () => {
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('should throw error when
|
|
85
|
+
it('should throw error when apiKey is missing', async () => {
|
|
86
86
|
try {
|
|
87
87
|
await fetchHtmlWithWarmup(
|
|
88
88
|
'https://example.com/page',
|
|
@@ -94,7 +94,7 @@ describe('HTML Utils', () => {
|
|
|
94
94
|
);
|
|
95
95
|
expect.fail('Should have thrown error');
|
|
96
96
|
} catch (error) {
|
|
97
|
-
expect(error.message).to.equal('Tokowaka
|
|
97
|
+
expect(error.message).to.equal('Tokowaka API key is required for fetching HTML');
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
|
|
@@ -111,7 +111,7 @@ describe('HTML Utils', () => {
|
|
|
111
111
|
|
|
112
112
|
const html = await fetchHtmlWithWarmup(
|
|
113
113
|
'https://example.com/page',
|
|
114
|
-
'
|
|
114
|
+
'api-key',
|
|
115
115
|
'host',
|
|
116
116
|
'https://edge.example.com',
|
|
117
117
|
log,
|
|
@@ -136,7 +136,7 @@ describe('HTML Utils', () => {
|
|
|
136
136
|
|
|
137
137
|
const html = await fetchHtmlWithWarmup(
|
|
138
138
|
'https://example.com/page?param=value',
|
|
139
|
-
'
|
|
139
|
+
'api-key',
|
|
140
140
|
'host',
|
|
141
141
|
'https://edge.example.com',
|
|
142
142
|
log,
|
|
@@ -178,7 +178,7 @@ describe('HTML Utils', () => {
|
|
|
178
178
|
try {
|
|
179
179
|
await fetchHtmlWithWarmup(
|
|
180
180
|
'https://example.com/page',
|
|
181
|
-
'
|
|
181
|
+
'api-key',
|
|
182
182
|
'host',
|
|
183
183
|
'https://edge.example.com',
|
|
184
184
|
log,
|
|
@@ -208,7 +208,7 @@ describe('HTML Utils', () => {
|
|
|
208
208
|
try {
|
|
209
209
|
await fetchHtmlWithWarmup(
|
|
210
210
|
'https://example.com/page',
|
|
211
|
-
'
|
|
211
|
+
'api-key',
|
|
212
212
|
'host',
|
|
213
213
|
'https://edge.example.com',
|
|
214
214
|
log,
|
|
@@ -239,7 +239,7 @@ describe('HTML Utils', () => {
|
|
|
239
239
|
try {
|
|
240
240
|
await fetchHtmlWithWarmup(
|
|
241
241
|
'https://example.com/page',
|
|
242
|
-
'
|
|
242
|
+
'api-key',
|
|
243
243
|
'host',
|
|
244
244
|
'https://edge.example.com',
|
|
245
245
|
log,
|
|
@@ -319,7 +319,7 @@ describe('HTML Utils', () => {
|
|
|
319
319
|
|
|
320
320
|
const html = await fetchHtmlWithWarmup(
|
|
321
321
|
'https://example.com/page',
|
|
322
|
-
'
|
|
322
|
+
'api-key',
|
|
323
323
|
'host',
|
|
324
324
|
'https://edge.example.com',
|
|
325
325
|
log,
|
|
@@ -375,7 +375,7 @@ describe('HTML Utils', () => {
|
|
|
375
375
|
try {
|
|
376
376
|
await fetchHtmlWithWarmup(
|
|
377
377
|
'https://example.com/page',
|
|
378
|
-
'
|
|
378
|
+
'api-key',
|
|
379
379
|
'host',
|
|
380
380
|
'https://edge.example.com',
|
|
381
381
|
log,
|
|
@@ -416,7 +416,7 @@ describe('HTML Utils', () => {
|
|
|
416
416
|
|
|
417
417
|
const html = await fetchHtmlWithWarmup(
|
|
418
418
|
'https://example.com/page',
|
|
419
|
-
'
|
|
419
|
+
'api-key',
|
|
420
420
|
'host',
|
|
421
421
|
'https://edge.example.com',
|
|
422
422
|
log,
|