@adobe/spacecat-shared-tokowaka-client 1.1.1 → 1.2.0

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/src/index.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface TokawakaPatch {
21
21
  currValue?: string;
22
22
  target: 'ai-bots' | 'bots' | 'all';
23
23
  opportunityId: string;
24
- suggestionId: string;
24
+ suggestionId?: string;
25
25
  prerenderRequired: boolean;
26
26
  lastUpdated: number;
27
27
  }
@@ -32,17 +32,17 @@ export const TARGET_USER_AGENTS_CATEGORIES: {
32
32
  ALL: 'all';
33
33
  };
34
34
 
35
- export interface TokowakaUrlOptimization {
35
+ export interface TokowakaMetaconfig {
36
+ siteId: string;
36
37
  prerender: boolean;
37
- patches: TokawakaPatch[];
38
38
  }
39
39
 
40
40
  export interface TokowakaConfig {
41
- siteId: string;
42
- baseURL: string;
41
+ url: string;
43
42
  version: string;
44
- tokowakaForceFail: boolean;
45
- tokowakaOptimizations: Record<string, TokowakaUrlOptimization>;
43
+ forceFail: boolean;
44
+ prerender: boolean;
45
+ patches: TokawakaPatch[];
46
46
  }
47
47
 
48
48
  export interface CdnInvalidationResult {
@@ -55,16 +55,37 @@ export interface CdnInvalidationResult {
55
55
  }
56
56
 
57
57
  export interface DeploymentResult {
58
+ s3Paths: string[];
59
+ cdnInvalidations: (CdnInvalidationResult | null)[];
60
+ succeededSuggestions: Array<any>;
61
+ failedSuggestions: Array<{ suggestion: any; reason: string }>;
62
+ }
63
+
64
+ export interface RollbackResult {
65
+ s3Paths: string[];
66
+ cdnInvalidations: (CdnInvalidationResult | null)[];
67
+ succeededSuggestions: Array<any>;
68
+ failedSuggestions: Array<{ suggestion: any; reason: string }>;
69
+ removedPatchesCount: number;
70
+ }
71
+
72
+ export interface PreviewResult {
58
73
  s3Path: string;
74
+ config: TokowakaConfig;
59
75
  cdnInvalidation: CdnInvalidationResult | null;
60
76
  succeededSuggestions: Array<any>;
61
77
  failedSuggestions: Array<{ suggestion: any; reason: string }>;
78
+ html: {
79
+ url: string;
80
+ originalHtml: string;
81
+ optimizedHtml: string;
82
+ };
62
83
  }
63
84
 
64
85
  export interface SiteConfig {
65
86
  getTokowakaConfig(): {
66
- apiKey: string;
67
- cdnProvider?: string;
87
+ apiKey?: string;
88
+ forwardedHost?: string;
68
89
  };
69
90
  getFetchConfig?(): {
70
91
  overrideBaseURL?: string;
@@ -108,12 +129,14 @@ export abstract class BaseOpportunityMapper {
108
129
  abstract requiresPrerender(): boolean;
109
130
 
110
131
  /**
111
- * Converts a suggestion to a Tokowaka patch
132
+ * Converts suggestions to Tokowaka patches
112
133
  */
113
- abstract suggestionToPatch(
114
- suggestion: Suggestion,
115
- opportunityId: string
116
- ): TokawakaPatch | null;
134
+ abstract suggestionsToPatches(
135
+ urlPath: string,
136
+ suggestions: Suggestion[],
137
+ opportunityId: string,
138
+ existingConfig: TokowakaConfig | null
139
+ ): TokawakaPatch[];
117
140
 
118
141
  /**
119
142
  * Checks if a suggestion can be deployed for this opportunity type
@@ -142,7 +165,11 @@ export class HeadingsMapper extends BaseOpportunityMapper {
142
165
 
143
166
  getOpportunityType(): string;
144
167
  requiresPrerender(): boolean;
145
- suggestionToPatch(suggestion: Suggestion, opportunityId: string): TokawakaPatch | null;
168
+ suggestionsToPatches(
169
+ urlPath: string,
170
+ suggestions: Suggestion[],
171
+ opportunityId: string
172
+ ): TokawakaPatch[];
146
173
  canDeploy(suggestion: Suggestion): { eligible: boolean; reason?: string };
147
174
  }
148
175
 
@@ -155,13 +182,36 @@ export class ContentSummarizationMapper extends BaseOpportunityMapper {
155
182
 
156
183
  getOpportunityType(): string;
157
184
  requiresPrerender(): boolean;
158
- suggestionToPatch(suggestion: Suggestion, opportunityId: string): TokawakaPatch | null;
185
+ suggestionsToPatches(
186
+ urlPath: string,
187
+ suggestions: Suggestion[],
188
+ opportunityId: string
189
+ ): TokawakaPatch[];
190
+ canDeploy(suggestion: Suggestion): { eligible: boolean; reason?: string };
191
+ }
192
+
193
+ /**
194
+ * FAQ opportunity mapper
195
+ * Handles conversion of FAQ suggestions to Tokowaka patches
196
+ */
197
+ export class FaqMapper extends BaseOpportunityMapper {
198
+ constructor(log: any);
199
+
200
+ getOpportunityType(): string;
201
+ requiresPrerender(): boolean;
159
202
  canDeploy(suggestion: Suggestion): { eligible: boolean; reason?: string };
160
203
 
161
204
  /**
162
- * Converts markdown text to HAST (Hypertext Abstract Syntax Tree) format
205
+ * Creates patches for FAQ suggestions
206
+ * First patch is heading (h2) if it doesn't exist, then individual FAQ divs
207
+ * @throws {Error} if suggestionToPatch is called directly
163
208
  */
164
- markdownToHast(markdown: string): object;
209
+ suggestionsToPatches(
210
+ urlPath: string,
211
+ suggestions: Suggestion[],
212
+ opportunityId: string,
213
+ existingConfig: TokowakaConfig | null
214
+ ): TokawakaPatch[];
165
215
  }
166
216
 
167
217
  /**
@@ -232,6 +282,7 @@ export class CdnClientRegistry {
232
282
  export default class TokowakaClient {
233
283
  constructor(config: {
234
284
  bucketName: string;
285
+ previewBucketName?: string;
235
286
  s3Client: S3Client;
236
287
  env?: Record<string, any>;
237
288
  }, log: any);
@@ -239,26 +290,44 @@ export default class TokowakaClient {
239
290
  static createFrom(context: {
240
291
  env: {
241
292
  TOKOWAKA_SITE_CONFIG_BUCKET: string;
293
+ TOKOWAKA_PREVIEW_BUCKET?: string;
242
294
  TOKOWAKA_CDN_PROVIDER?: string;
243
295
  TOKOWAKA_CDN_CONFIG?: string;
296
+ TOKOWAKA_EDGE_URL?: string;
244
297
  };
245
298
  log?: any;
246
299
  s3: { s3Client: S3Client };
247
300
  tokowakaClient?: TokowakaClient;
248
301
  }): TokowakaClient;
249
302
 
303
+ /**
304
+ * Generates Tokowaka configuration from suggestions for a specific URL
305
+ */
250
306
  generateConfig(
251
- site: Site,
307
+ url: string,
252
308
  opportunity: Opportunity,
253
309
  suggestions: Suggestion[]
254
- ): TokowakaConfig;
310
+ ): TokowakaConfig | null;
255
311
 
256
- uploadConfig(apiKey: string, config: TokowakaConfig): Promise<string>;
312
+ /**
313
+ * Uploads configuration to S3 for a specific URL
314
+ */
315
+ uploadConfig(url: string, config: TokowakaConfig, isPreview?: boolean): Promise<string>;
257
316
 
258
317
  /**
259
- * Fetches existing Tokowaka configuration from S3
318
+ * Fetches existing Tokowaka configuration from S3 for a specific URL
260
319
  */
261
- fetchConfig(apiKey: string): Promise<TokowakaConfig | null>;
320
+ fetchConfig(url: string, isPreview?: boolean): Promise<TokowakaConfig | null>;
321
+
322
+ /**
323
+ * Fetches domain-level metaconfig from S3
324
+ */
325
+ fetchMetaconfig(url: string, isPreview?: boolean): Promise<TokowakaMetaconfig | null>;
326
+
327
+ /**
328
+ * Uploads domain-level metaconfig to S3
329
+ */
330
+ uploadMetaconfig(url: string, metaconfig: TokowakaMetaconfig, isPreview?: boolean): Promise<string>;
262
331
 
263
332
  /**
264
333
  * Merges existing configuration with new configuration
@@ -266,16 +335,42 @@ export default class TokowakaClient {
266
335
  mergeConfigs(existingConfig: TokowakaConfig, newConfig: TokowakaConfig): TokowakaConfig;
267
336
 
268
337
  /**
269
- * Invalidates CDN cache
338
+ * Invalidates CDN cache for a specific URL
270
339
  */
271
- invalidateCdnCache(apiKey: string, cdnProvider?: string): Promise<CdnInvalidationResult | null>;
340
+ invalidateCdnCache(url: string, provider?: string, isPreview?: boolean): Promise<CdnInvalidationResult | null>;
272
341
 
342
+ /**
343
+ * Deploys suggestions to Tokowaka edge
344
+ */
273
345
  deploySuggestions(
274
346
  site: Site,
275
347
  opportunity: Opportunity,
276
348
  suggestions: Suggestion[]
277
349
  ): Promise<DeploymentResult>;
278
350
 
351
+ /**
352
+ * Rolls back deployed suggestions
353
+ */
354
+ rollbackSuggestions(
355
+ site: Site,
356
+ opportunity: Opportunity,
357
+ suggestions: Suggestion[]
358
+ ): Promise<RollbackResult>;
359
+
360
+ /**
361
+ * Previews suggestions (all must belong to same URL)
362
+ */
363
+ previewSuggestions(
364
+ site: Site,
365
+ opportunity: Opportunity,
366
+ suggestions: Suggestion[],
367
+ options?: {
368
+ warmupDelayMs?: number;
369
+ maxRetries?: number;
370
+ retryDelayMs?: number;
371
+ }
372
+ ): Promise<PreviewResult>;
373
+
279
374
  /**
280
375
  * Registers a custom mapper for an opportunity type
281
376
  */