@adobe/spacecat-shared-tokowaka-client 1.5.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-tokowaka-client-v1.5.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.5.0...@adobe/spacecat-shared-tokowaka-client-v1.5.1) (2026-01-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * rename tokowaka to edge-optimize in preview api ([#1269](https://github.com/adobe/spacecat-shared/issues/1269)) ([d40caa4](https://github.com/adobe/spacecat-shared/commit/d40caa46d2bb72506e45081a263f4513fce4ce41))
7
+
1
8
  # [@adobe/spacecat-shared-tokowaka-client-v1.5.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.4.7...@adobe/spacecat-shared-tokowaka-client-v1.5.0) (2026-01-15)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-tokowaka-client",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Tokowaka Client for SpaceCat - Edge optimization config management",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.js CHANGED
@@ -306,7 +306,7 @@ class TokowakaClient {
306
306
  siteId,
307
307
  apiKeys: [apiKey],
308
308
  tokowakaEnabled: options.tokowakaEnabled ?? true,
309
- enhancements: false,
309
+ enhancements: options.enhancements ?? false,
310
310
  };
311
311
 
312
312
  const s3Path = await this.uploadMetaconfig(url, metaconfig);
@@ -810,8 +810,8 @@ class TokowakaClient {
810
810
  }
811
811
 
812
812
  // TOKOWAKA_EDGE_URL is mandatory for preview
813
- const tokowakaEdgeUrl = this.env.TOKOWAKA_EDGE_URL;
814
- if (!hasText(tokowakaEdgeUrl)) {
813
+ const edgeUrl = this.env.TOKOWAKA_EDGE_URL;
814
+ if (!hasText(edgeUrl)) {
815
815
  throw this.#createError(
816
816
  'TOKOWAKA_EDGE_URL is required for preview functionality',
817
817
  HTTP_INTERNAL_SERVER_ERROR,
@@ -931,7 +931,7 @@ class TokowakaClient {
931
931
  previewUrl,
932
932
  apiKey,
933
933
  forwardedHost,
934
- tokowakaEdgeUrl,
934
+ edgeUrl,
935
935
  this.log,
936
936
  false,
937
937
  options,
@@ -941,7 +941,7 @@ class TokowakaClient {
941
941
  previewUrl,
942
942
  apiKey,
943
943
  forwardedHost,
944
- tokowakaEdgeUrl,
944
+ edgeUrl,
945
945
  this.log,
946
946
  true,
947
947
  options,
@@ -25,7 +25,7 @@ function sleep(ms) {
25
25
 
26
26
  /**
27
27
  * Makes an HTTP request with retry logic
28
- * Retries until max retries are exhausted or x-tokowaka-cache header is present
28
+ * Retries until max retries are exhausted or x-edge-optimize-cache header is present
29
29
  * @param {string} url - URL to fetch
30
30
  * @param {Object} options - Fetch options
31
31
  * @param {number} maxRetries - Maximum number of retries
@@ -48,10 +48,10 @@ async function fetchWithRetry(url, options, maxRetries, retryDelayMs, log, fetch
48
48
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
49
49
  }
50
50
 
51
- // Check for x-tokowaka-cache header - if present, stop retrying
52
- const cacheHeader = response.headers.get('x-tokowaka-cache');
51
+ // Check for x-edge-optimize-cache header - if present, stop retrying
52
+ const cacheHeader = response.headers.get('x-edge-optimize-cache');
53
53
  if (cacheHeader) {
54
- log.debug(`Cache header found (x-tokowaka-cache: ${cacheHeader}), stopping retry logic`);
54
+ log.debug(`Cache header found (x-edge-optimize-cache: ${cacheHeader}), stopping retry logic`);
55
55
  return response;
56
56
  }
57
57
 
@@ -65,7 +65,7 @@ async function fetchWithRetry(url, options, maxRetries, retryDelayMs, log, fetch
65
65
  } else {
66
66
  // Last attempt without cache header - throw error
67
67
  log.error(`Max retries (${maxRetries}) exhausted without cache header`);
68
- throw new Error(`Cache header (x-tokowaka-cache) not found after ${maxRetries} retries`);
68
+ throw new Error(`Cache header (x-edge-optimize-cache) not found after ${maxRetries} retries`);
69
69
  }
70
70
  } catch (error) {
71
71
  log.warn(`Attempt ${attempt} failed for ${fetchType} HTML, error: ${error.message}`);
@@ -86,12 +86,12 @@ async function fetchWithRetry(url, options, maxRetries, retryDelayMs, log, fetch
86
86
  }
87
87
 
88
88
  /**
89
- * Fetches HTML content from Tokowaka edge with warmup call and retry logic
89
+ * Fetches HTML content from 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} apiKey - Tokowaka API key
92
+ * @param {string} apiKey - Edge Optimize API key
93
93
  * @param {string} forwardedHost - Host to forward in x-forwarded-host header
94
- * @param {string} tokowakaEdgeUrl - Tokowaka edge URL
94
+ * @param {string} edgeUrl - Edge URL
95
95
  * @param {boolean} isOptimized - Whether to fetch optimized HTML (with preview param)
96
96
  * @param {Object} log - Logger instance
97
97
  * @param {Object} options - Additional options
@@ -105,7 +105,7 @@ export async function fetchHtmlWithWarmup(
105
105
  url,
106
106
  apiKey,
107
107
  forwardedHost,
108
- tokowakaEdgeUrl,
108
+ edgeUrl,
109
109
  log,
110
110
  isOptimized = false,
111
111
  options = {},
@@ -116,14 +116,14 @@ export async function fetchHtmlWithWarmup(
116
116
  }
117
117
 
118
118
  if (!hasText(apiKey)) {
119
- throw new Error('Tokowaka API key is required for fetching HTML');
119
+ throw new Error('Edge Optimize API key is required for fetching HTML');
120
120
  }
121
121
 
122
122
  if (!hasText(forwardedHost)) {
123
123
  throw new Error('Forwarded host is required for fetching HTML');
124
124
  }
125
125
 
126
- if (!hasText(tokowakaEdgeUrl)) {
126
+ if (!hasText(edgeUrl)) {
127
127
  throw new Error('TOKOWAKA_EDGE_URL is not configured');
128
128
  }
129
129
 
@@ -139,18 +139,18 @@ export async function fetchHtmlWithWarmup(
139
139
  // Parse the URL to extract path and construct full URL
140
140
  const urlObj = new URL(url);
141
141
  const urlPath = urlObj.pathname;
142
- let fullUrl = `${tokowakaEdgeUrl}${urlPath}`;
142
+ let fullUrl = `${edgeUrl}${urlPath}`;
143
143
 
144
144
  const headers = {
145
145
  'x-forwarded-host': forwardedHost,
146
- 'x-tokowaka-api-key': apiKey,
147
- 'x-tokowaka-url': urlPath,
146
+ 'x-edge-optimize-api-key': apiKey,
147
+ 'x-edge-optimize-url': urlPath,
148
148
  };
149
149
 
150
150
  if (isOptimized) {
151
151
  // Add tokowakaPreview param for optimized HTML
152
152
  fullUrl = `${fullUrl}?tokowakaPreview=true`;
153
- headers['x-tokowaka-url'] = `${urlPath}?tokowakaPreview=true`;
153
+ headers['x-edge-optimize-url'] = `${urlPath}?tokowakaPreview=true`;
154
154
  }
155
155
 
156
156
  const fetchOptions = {
@@ -1924,7 +1924,7 @@ describe('TokowakaClient', () => {
1924
1924
  status: 200,
1925
1925
  statusText: 'OK',
1926
1926
  headers: {
1927
- get: (name) => (name === 'x-tokowaka-cache' ? 'HIT' : null),
1927
+ get: (name) => (name === 'x-edge-optimize-cache' ? 'HIT' : null),
1928
1928
  },
1929
1929
  text: async () => '<html><body>Test HTML</body></html>',
1930
1930
  });
@@ -744,7 +744,6 @@ Overall, Bulk positions itself as a better choice for sports nutrition through i
744
744
  question: 'Old Q?',
745
745
  answer: 'Old A.',
746
746
  },
747
- tokowakaDeployed: 1704884400000,
748
747
  transformRules: {
749
748
  action: 'appendChild',
750
749
  selector: 'main',
@@ -1154,7 +1153,7 @@ Overall, Bulk positions itself as a better choice for sports nutrition through i
1154
1153
  });
1155
1154
  });
1156
1155
 
1157
- describe('tokowakaDeployed filtering', () => {
1156
+ describe('edgeDeployed filtering', () => {
1158
1157
  it('should always create heading patch even when FAQ already deployed for URL', () => {
1159
1158
  const newSuggestion = {
1160
1159
  getId: () => 'sugg-new-1',
@@ -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 API key is required for fetching HTML');
97
+ expect(error.message).to.equal('Edge Optimize API key is required for fetching HTML');
98
98
  }
99
99
  });
100
100
 
@@ -104,7 +104,7 @@ describe('HTML Utils', () => {
104
104
  status: 200,
105
105
  statusText: 'OK',
106
106
  headers: {
107
- get: (name) => (name === 'x-tokowaka-cache' ? 'HIT' : null),
107
+ get: (name) => (name === 'x-edge-optimize-cache' ? 'HIT' : null),
108
108
  },
109
109
  text: async () => '<html>Test HTML</html>',
110
110
  });
@@ -129,7 +129,7 @@ describe('HTML Utils', () => {
129
129
  status: 200,
130
130
  statusText: 'OK',
131
131
  headers: {
132
- get: (name) => (name === 'x-tokowaka-cache' ? 'HIT' : null),
132
+ get: (name) => (name === 'x-edge-optimize-cache' ? 'HIT' : null),
133
133
  },
134
134
  text: async () => '<html>Optimized HTML</html>',
135
135
  });
@@ -285,7 +285,7 @@ describe('HTML Utils', () => {
285
285
  }
286
286
  });
287
287
 
288
- it('should stop retrying when x-tokowaka-cache header is found', async () => {
288
+ it('should stop retrying when x-edge-optimize-cache header is found', async () => {
289
289
  // Warmup succeeds
290
290
  fetchStub.onCall(0).resolves({
291
291
  ok: true,
@@ -312,7 +312,7 @@ describe('HTML Utils', () => {
312
312
  status: 200,
313
313
  statusText: 'OK',
314
314
  headers: {
315
- get: (name) => (name === 'x-tokowaka-cache' ? 'HIT' : null),
315
+ get: (name) => (name === 'x-edge-optimize-cache' ? 'HIT' : null),
316
316
  },
317
317
  text: async () => '<html>Cached HTML</html>',
318
318
  });
@@ -385,7 +385,7 @@ describe('HTML Utils', () => {
385
385
  expect.fail('Should have thrown error');
386
386
  } catch (error) {
387
387
  expect(error.message).to.include('Failed to fetch original HTML');
388
- expect(error.message).to.include('Cache header (x-tokowaka-cache) not found after 2 retries');
388
+ expect(error.message).to.include('Cache header (x-edge-optimize-cache) not found after 2 retries');
389
389
  }
390
390
 
391
391
  // Should have tried 3 times (initial + 2 retries) plus warmup
@@ -409,7 +409,7 @@ describe('HTML Utils', () => {
409
409
  status: 200,
410
410
  statusText: 'OK',
411
411
  headers: {
412
- get: (name) => (name === 'x-tokowaka-cache' ? 'HIT' : null),
412
+ get: (name) => (name === 'x-edge-optimize-cache' ? 'HIT' : null),
413
413
  },
414
414
  text: async () => '<html>Cached HTML</html>',
415
415
  });