@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/.releaserc.cjs +17 -0
- package/CHANGELOG.md +69 -1
- package/CODE_OF_CONDUCT.md +75 -0
- package/CONTRIBUTING.md +74 -0
- package/README.md +155 -15
- package/package.json +4 -4
- package/src/index.d.ts +120 -25
- package/src/index.js +481 -177
- package/src/mappers/base-mapper.js +41 -9
- package/src/mappers/content-summarization-mapper.js +38 -35
- package/src/mappers/faq-mapper.js +247 -0
- package/src/mappers/headings-mapper.js +37 -23
- package/src/mappers/mapper-registry.js +2 -0
- package/src/utils/custom-html-utils.js +195 -0
- package/src/utils/markdown-utils.js +24 -0
- package/src/utils/patch-utils.js +103 -0
- package/src/utils/s3-utils.js +117 -0
- package/src/utils/site-utils.js +25 -0
- package/src/utils/suggestion-utils.js +69 -0
- package/test/index.test.js +1268 -462
- package/test/mappers/base-mapper.test.js +250 -7
- package/test/mappers/content-mapper.test.js +26 -24
- package/test/mappers/faq-mapper.test.js +1428 -0
- package/test/mappers/headings-mapper.test.js +23 -17
- package/test/utils/html-utils.test.js +432 -0
- package/test/utils/patch-utils.test.js +409 -0
- package/test/utils/s3-utils.test.js +140 -0
- package/test/utils/site-utils.test.js +80 -0
- package/test/utils/suggestion-utils.test.js +187 -0
package/.releaserc.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: "semantic-release-monorepo",
|
|
3
|
+
plugins: [
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
"@semantic-release/release-notes-generator",
|
|
6
|
+
["@semantic-release/changelog", {
|
|
7
|
+
"changelogFile": "CHANGELOG.md",
|
|
8
|
+
}],
|
|
9
|
+
"@semantic-release/npm",
|
|
10
|
+
["@semantic-release/git", {
|
|
11
|
+
"assets": ["package.json", "CHANGELOG.md"],
|
|
12
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
13
|
+
}],
|
|
14
|
+
["@semantic-release/github", {}],
|
|
15
|
+
],
|
|
16
|
+
branches: ['main'],
|
|
17
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.2.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.1.0...@adobe/spacecat-shared-tokowaka-client-v1.2.0) (2025-11-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* url path-wise edge deployment ([#1178](https://github.com/adobe/spacecat-shared/issues/1178)) ([37b0d1a](https://github.com/adobe/spacecat-shared/commit/37b0d1a388f842a62cb95eb5272feb49d1dfb3e8))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.1.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.6...@adobe/spacecat-shared-tokowaka-client-v1.1.0) (2025-11-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* edge rollback feature for tokowaka ([#1167](https://github.com/adobe/spacecat-shared/issues/1167)) ([b47fd05](https://github.com/adobe/spacecat-shared/commit/b47fd0518ae1fe220914bfd88810383a306775fd))
|
|
14
|
+
|
|
15
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.5...@adobe/spacecat-shared-tokowaka-client-v1.0.6) (2025-11-22)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** update external fixes ([#1162](https://github.com/adobe/spacecat-shared/issues/1162)) ([f0152c5](https://github.com/adobe/spacecat-shared/commit/f0152c5ecddb75b6b3c6e2f0d756d5fb04171dd3))
|
|
21
|
+
|
|
22
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.4...@adobe/spacecat-shared-tokowaka-client-v1.0.5) (2025-11-21)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* edge preview feature for Tokowaka ([#1124](https://github.com/adobe/spacecat-shared/issues/1124)) ([cd2a06f](https://github.com/adobe/spacecat-shared/commit/cd2a06f62e3ca9e8c2b87e1810d420a06a002526))
|
|
28
|
+
|
|
29
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.3...@adobe/spacecat-shared-tokowaka-client-v1.0.4) (2025-11-15)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* **deps:** update external fixes ([#1131](https://github.com/adobe/spacecat-shared/issues/1131)) ([d4a3f4a](https://github.com/adobe/spacecat-shared/commit/d4a3f4a653e59e9bdde7926ea8f1a2f9b68739ff))
|
|
35
|
+
|
|
36
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.2...@adobe/spacecat-shared-tokowaka-client-v1.0.3) (2025-11-13)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* add faq mapper for edge deploy API ([#1083](https://github.com/adobe/spacecat-shared/issues/1083)) ([4c7ff9d](https://github.com/adobe/spacecat-shared/commit/4c7ff9db3312e76fa8965a2d53a699528975f414))
|
|
42
|
+
|
|
43
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.1...@adobe/spacecat-shared-tokowaka-client-v1.0.2) (2025-11-08)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Bug Fixes
|
|
47
|
+
|
|
48
|
+
* **deps:** update external fixes ([#1107](https://github.com/adobe/spacecat-shared/issues/1107)) ([f4cdb50](https://github.com/adobe/spacecat-shared/commit/f4cdb50f96d18dd92de81055f2b58310a68c0cac))
|
|
49
|
+
|
|
50
|
+
# [@adobe/spacecat-shared-tokowaka-client-v1.0.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-tokowaka-client-v1.0.0...@adobe/spacecat-shared-tokowaka-client-v1.0.1) (2025-11-01)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Bug Fixes
|
|
54
|
+
|
|
55
|
+
* **deps:** update external fixes ([#1081](https://github.com/adobe/spacecat-shared/issues/1081)) ([4476494](https://github.com/adobe/spacecat-shared/commit/44764944350f9344d0ca5e2af5a2161cc7470899))
|
|
56
|
+
|
|
57
|
+
# @adobe/spacecat-shared-tokowaka-client-v1.0.0 (2025-10-30)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Bug Fixes
|
|
61
|
+
|
|
62
|
+
* add releaserc to tokowaka client ([#1071](https://github.com/adobe/spacecat-shared/issues/1071)) ([e49f02c](https://github.com/adobe/spacecat-shared/commit/e49f02ce455868f1035bce4f87553a2b82ad7d68))
|
|
63
|
+
* update publish config for tokowaka client ([#1070](https://github.com/adobe/spacecat-shared/issues/1070)) ([066d5a1](https://github.com/adobe/spacecat-shared/commit/066d5a1c00848323c2828041004c0959ca015890))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
* add tokowaka client ([#1025](https://github.com/adobe/spacecat-shared/issues/1025)) ([7af58b0](https://github.com/adobe/spacecat-shared/commit/7af58b03ef341c32b35a6614365024af6a636a56))
|
|
69
|
+
|
|
1
70
|
# @adobe/spacecat-shared-tokowaka-client
|
|
2
71
|
|
|
3
72
|
## 1.0.0 (2025-10-15)
|
|
@@ -9,4 +78,3 @@
|
|
|
9
78
|
* S3 configuration management
|
|
10
79
|
* Extensible mapper pattern for opportunity-specific transformations
|
|
11
80
|
* Built-in support for headings opportunity
|
|
12
|
-
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Adobe Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at Grp-opensourceoffice@adobe.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
|
75
|
+
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributing to Project Franklin
|
|
2
|
+
|
|
3
|
+
This project (like almost all of Project Franklin) is an Open Development project and welcomes contributions from everyone who finds it useful or lacking.
|
|
4
|
+
|
|
5
|
+
## Code Of Conduct
|
|
6
|
+
|
|
7
|
+
This project adheres to the Adobe [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to cstaub at adobe dot com.
|
|
8
|
+
|
|
9
|
+
## Contributor License Agreement
|
|
10
|
+
|
|
11
|
+
All third-party contributions to this project must be accompanied by a signed contributor license. This gives Adobe permission to redistribute your contributions as part of the project. [Sign our CLA](http://opensource.adobe.com/cla.html)! You only need to submit an Adobe CLA one time, so if you have submitted one previously, you are good to go!
|
|
12
|
+
|
|
13
|
+
## Things to Keep in Mind
|
|
14
|
+
|
|
15
|
+
This project uses a **commit then review** process, which means that for approved maintainers, changes can be merged immediately, but will be reviewed by others.
|
|
16
|
+
|
|
17
|
+
For other contributors, a maintainer of the project has to approve the pull request.
|
|
18
|
+
|
|
19
|
+
# Before You Contribute
|
|
20
|
+
|
|
21
|
+
* Check that there is an existing issue in GitHub issues
|
|
22
|
+
* Check if there are other pull requests that might overlap or conflict with your intended contribution
|
|
23
|
+
|
|
24
|
+
# How to Contribute
|
|
25
|
+
|
|
26
|
+
1. Fork the repository
|
|
27
|
+
2. Make some changes on a branch on your fork
|
|
28
|
+
3. Create a pull request from your branch
|
|
29
|
+
|
|
30
|
+
In your pull request, outline:
|
|
31
|
+
|
|
32
|
+
* What the changes intend
|
|
33
|
+
* How they change the existing code
|
|
34
|
+
* If (and what) they breaks
|
|
35
|
+
* Start the pull request with the GitHub issue ID, e.g. #123
|
|
36
|
+
|
|
37
|
+
Lastly, please follow the [pull request template](.github/pull_request_template.md) when submitting a pull request!
|
|
38
|
+
|
|
39
|
+
Each commit message that is not part of a pull request:
|
|
40
|
+
|
|
41
|
+
* Should contain the issue ID like `#123`
|
|
42
|
+
* Can contain the tag `[trivial]` for trivial changes that don't relate to an issue
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Coding Styleguides
|
|
47
|
+
|
|
48
|
+
We enforce a coding styleguide using `eslint`. As part of your build, run `npm run lint` to check if your code is conforming to the style guide. We do the same for every PR in our CI, so PRs will get rejected if they don't follow the style guide.
|
|
49
|
+
|
|
50
|
+
You can fix some of the issues automatically by running `npx eslint . --fix`.
|
|
51
|
+
|
|
52
|
+
## Commit Message Format
|
|
53
|
+
|
|
54
|
+
This project uses a structured commit changelog format that should be used for every commit. Use `npm run commit` instead of your usual `git commit` to generate commit messages using a wizard.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# either add all changed files
|
|
58
|
+
$ git add -A
|
|
59
|
+
# or selectively add files
|
|
60
|
+
$ git add package.json
|
|
61
|
+
# then commit using the wizard
|
|
62
|
+
$ npm run commit
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
# How Contributions get Reviewed
|
|
66
|
+
|
|
67
|
+
One of the maintainers will look at the pull request within one week. Feedback on the pull request will be given in writing, in GitHub.
|
|
68
|
+
|
|
69
|
+
# Release Management
|
|
70
|
+
|
|
71
|
+
The project's committers will release to the [Adobe organization on npmjs.org](https://www.npmjs.com/org/adobe).
|
|
72
|
+
Please contact the [Adobe Open Source Advisory Board](https://git.corp.adobe.com/OpenSourceAdvisoryBoard/discuss/issues) to get access to the npmjs organization.
|
|
73
|
+
|
|
74
|
+
The release process is fully automated using `semantic-release`, increasing the version numbers, etc. based on the contents of the commit messages found.
|
package/README.md
CHANGED
|
@@ -26,34 +26,76 @@ Creates a client instance from a context object.
|
|
|
26
26
|
**Required context properties:**
|
|
27
27
|
- `context.s3.s3Client` (S3Client): AWS S3 client instance
|
|
28
28
|
- `context.log` (Object, optional): Logger instance
|
|
29
|
-
- `context.env.TOKOWAKA_SITE_CONFIG_BUCKET` (string): S3 bucket name for configurations
|
|
29
|
+
- `context.env.TOKOWAKA_SITE_CONFIG_BUCKET` (string): S3 bucket name for deployed configurations
|
|
30
|
+
- `context.env.TOKOWAKA_PREVIEW_BUCKET` (string): S3 bucket name for preview configurations
|
|
30
31
|
- `context.env.TOKOWAKA_CDN_PROVIDER` (string): CDN provider for cache invalidation
|
|
31
32
|
- `context.env.TOKOWAKA_CDN_CONFIG` (string): JSON configuration for CDN client
|
|
33
|
+
- `context.env.TOKOWAKA_EDGE_URL` (string): Tokowaka edge URL for preview HTML fetching
|
|
32
34
|
|
|
33
35
|
## Environment Variables
|
|
34
36
|
|
|
35
37
|
**Required:**
|
|
36
|
-
- `TOKOWAKA_SITE_CONFIG_BUCKET` - S3 bucket name for storing configurations
|
|
38
|
+
- `TOKOWAKA_SITE_CONFIG_BUCKET` - S3 bucket name for storing deployed configurations
|
|
39
|
+
- `TOKOWAKA_PREVIEW_BUCKET` - S3 bucket name for storing preview configurations
|
|
37
40
|
|
|
38
41
|
**Optional (for CDN invalidation):**
|
|
39
42
|
- `TOKOWAKA_CDN_PROVIDER` - CDN provider name (e.g., "cloudfront")
|
|
40
43
|
- `TOKOWAKA_CDN_CONFIG` - JSON string with CDN-specific configuration. (e.g., { "cloudfront": { "distributionId": <distribution-id>, "region": "us-east-1" }})
|
|
41
44
|
|
|
45
|
+
**Optional (for preview functionality):**
|
|
46
|
+
- `TOKOWAKA_EDGE_URL` - Tokowaka edge URL for fetching HTML content during preview
|
|
47
|
+
|
|
42
48
|
### Main Methods
|
|
43
49
|
|
|
44
50
|
#### `deploySuggestions(site, opportunity, suggestions)`
|
|
45
51
|
|
|
46
|
-
Generates configuration and uploads to S3
|
|
52
|
+
Generates configuration and uploads to S3 **per URL**. **Automatically fetches existing configuration for each URL and merges** new suggestions with it. Invalidates CDN cache after upload.
|
|
53
|
+
|
|
54
|
+
**Architecture Change:** Creates one S3 file per URL instead of a single file with all URLs. This prevents files from growing too large over time.
|
|
47
55
|
|
|
48
56
|
**Returns:** `Promise<DeploymentResult>` with:
|
|
49
|
-
- `
|
|
50
|
-
- `
|
|
57
|
+
- `s3Paths` - Array of S3 keys where configs were uploaded (one per URL)
|
|
58
|
+
- `cdnInvalidations` - Array of CDN invalidation results (one per URL)
|
|
51
59
|
- `succeededSuggestions` - Array of deployed suggestions
|
|
52
60
|
- `failedSuggestions` - Array of `{suggestion, reason}` objects for ineligible suggestions
|
|
53
61
|
|
|
54
|
-
#### `
|
|
62
|
+
#### `rollbackSuggestions(site, opportunity, suggestions)`
|
|
63
|
+
|
|
64
|
+
Rolls back previously deployed suggestions by removing their patches from the configuration. **Automatically fetches existing configuration for each URL** and removes patches matching the provided suggestions. Invalidates CDN cache after upload.
|
|
65
|
+
|
|
66
|
+
**Architecture Change:** Updates one S3 file per URL instead of a single file with all URLs.
|
|
67
|
+
|
|
68
|
+
**Mapper-Specific Rollback Behavior:**
|
|
69
|
+
- Each opportunity mapper handles its own rollback logic via `rollbackPatches()` method
|
|
70
|
+
- **FAQ:** Automatically removes the "FAQs" heading patch if no FAQ suggestions remain for that URL
|
|
71
|
+
- **Headings/Summarization:** Simple removal by suggestion ID (default behavior)
|
|
72
|
+
|
|
73
|
+
**Returns:** `Promise<RollbackResult>` with:
|
|
74
|
+
- `s3Paths` - Array of S3 keys where configs were uploaded (one per URL)
|
|
75
|
+
- `cdnInvalidations` - Array of CDN invalidation results (one per URL)
|
|
76
|
+
- `succeededSuggestions` - Array of rolled back suggestions
|
|
77
|
+
- `failedSuggestions` - Array of `{suggestion, reason}` objects for ineligible suggestions
|
|
78
|
+
- `removedPatchesCount` - Total number of patches removed across all URLs
|
|
79
|
+
|
|
80
|
+
#### `previewSuggestions(site, opportunity, suggestions, options)`
|
|
55
81
|
|
|
56
|
-
|
|
82
|
+
Previews suggestions by uploading to preview S3 path and fetching HTML comparison. **All suggestions must belong to the same URL.**
|
|
83
|
+
|
|
84
|
+
**Returns:** `Promise<PreviewResult>` with:
|
|
85
|
+
- `s3Path` - S3 key where preview config was uploaded
|
|
86
|
+
- `config` - Preview configuration object
|
|
87
|
+
- `cdnInvalidation` - CDN invalidation result
|
|
88
|
+
- `succeededSuggestions` - Array of previewed suggestions
|
|
89
|
+
- `failedSuggestions` - Array of `{suggestion, reason}` objects for ineligible suggestions
|
|
90
|
+
- `html` - Object with `url`, `originalHtml`, and `optimizedHtml`
|
|
91
|
+
|
|
92
|
+
#### `fetchConfig(url, isPreview)`
|
|
93
|
+
|
|
94
|
+
Fetches existing Tokowaka configuration from S3 for a specific URL.
|
|
95
|
+
|
|
96
|
+
**Parameters:**
|
|
97
|
+
- `url` - Full URL (e.g., 'https://www.example.com/products/item')
|
|
98
|
+
- `isPreview` - Whether to fetch from preview path (default: false)
|
|
57
99
|
|
|
58
100
|
**Returns:** `Promise<TokowakaConfig | null>` - Configuration object or null if not found
|
|
59
101
|
|
|
@@ -63,37 +105,135 @@ Merges existing configuration with new configuration. For each URL path, checks
|
|
|
63
105
|
|
|
64
106
|
**Returns:** `TokowakaConfig` - Merged configuration
|
|
65
107
|
|
|
66
|
-
#### `generateConfig(
|
|
108
|
+
#### `generateConfig(url, opportunity, suggestions)`
|
|
109
|
+
|
|
110
|
+
Generates Tokowaka configuration from opportunity suggestions for a specific URL without uploading.
|
|
111
|
+
|
|
112
|
+
**Parameters:**
|
|
113
|
+
- `url` - Full URL for which to generate config
|
|
114
|
+
- `opportunity` - Opportunity entity
|
|
115
|
+
- `suggestions` - Array of suggestion entities
|
|
116
|
+
|
|
117
|
+
#### `uploadConfig(url, config, isPreview)`
|
|
67
118
|
|
|
68
|
-
|
|
119
|
+
Uploads configuration to S3 for a specific URL.
|
|
69
120
|
|
|
70
|
-
|
|
121
|
+
**Parameters:**
|
|
122
|
+
- `url` - Full URL (e.g., 'https://www.example.com/products/item')
|
|
123
|
+
- `config` - Tokowaka configuration object
|
|
124
|
+
- `isPreview` - Whether to upload to preview path (default: false)
|
|
71
125
|
|
|
72
|
-
|
|
126
|
+
**Returns:** `Promise<string>` - S3 key of uploaded configuration
|
|
73
127
|
|
|
74
128
|
## CDN Cache Invalidation
|
|
75
129
|
|
|
76
130
|
The client invalidates CDN cache after uploading configurations. Failures are logged but don't block deployment.
|
|
77
131
|
|
|
132
|
+
## Site Configuration
|
|
133
|
+
|
|
134
|
+
Sites must have the following configuration in their `tokowakaConfig`:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
{
|
|
138
|
+
"tokowakaConfig": {
|
|
139
|
+
"apiKey": "legacy-key-kept-for-backward-compatibility", // Optional, kept for backward compatibility
|
|
140
|
+
"forwardedHost": "www.example.com" // Required for preview functionality
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Note:**
|
|
146
|
+
- `apiKey` is optional and **not used** for S3 paths or HTTP headers (kept in schema for potential future use)
|
|
147
|
+
- `forwardedHost` is **required** for preview functionality to fetch HTML from Tokowaka edge
|
|
148
|
+
|
|
78
149
|
## Supported Opportunity Types
|
|
79
150
|
|
|
80
151
|
### Headings
|
|
81
152
|
|
|
82
153
|
**Deployment Eligibility:** Only suggestions with `checkType: 'heading-empty'`, `checkType: 'heading-missing-h1'` and `checkType: 'heading-h1-length'` can be deployed currently.
|
|
83
154
|
|
|
155
|
+
### FAQ
|
|
156
|
+
|
|
157
|
+
**Deployment Eligibility:** Suggestions must have `shouldOptimize: true` flag and valid FAQ item structure.
|
|
158
|
+
|
|
159
|
+
**Special Behavior:** Automatically manages heading patch - adds heading when first FAQ is deployed, removes heading when last FAQ is rolled back.
|
|
160
|
+
|
|
84
161
|
### Content Summarization
|
|
85
162
|
|
|
86
|
-
**Deployment Eligibility:**
|
|
163
|
+
**Deployment Eligibility:** Currently all suggestions for `summarization` opportunity can be deployed.
|
|
87
164
|
|
|
88
165
|
## S3 Storage
|
|
89
166
|
|
|
90
|
-
Configurations are stored
|
|
167
|
+
Configurations are now stored **per URL** with domain-level metadata:
|
|
168
|
+
|
|
169
|
+
### Structure
|
|
170
|
+
```
|
|
171
|
+
s3://{TOKOWAKA_SITE_CONFIG_BUCKET}/opportunities/{normalized-domain}/
|
|
172
|
+
├── config (domain-level metaconfig: siteId, prerender)
|
|
173
|
+
├── {base64-encoded-path-1} (URL-specific patches)
|
|
174
|
+
├── {base64-encoded-path-2} (URL-specific patches)
|
|
175
|
+
└── ...
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
For preview configurations:
|
|
179
|
+
```
|
|
180
|
+
s3://{TOKOWAKA_PREVIEW_BUCKET}/preview/opportunities/{normalized-domain}/
|
|
181
|
+
├── config
|
|
182
|
+
├── {base64-encoded-path-1}
|
|
183
|
+
└── ...
|
|
91
184
|
```
|
|
92
|
-
|
|
185
|
+
|
|
186
|
+
**Architecture Change:** Each URL has its own configuration file instead of one file per site. Domain-level metaconfig is stored separately to avoid duplication.
|
|
187
|
+
|
|
188
|
+
**URL Normalization:**
|
|
189
|
+
- Domain: Strips `www.` prefix (e.g., `www.example.com` → `example.com`)
|
|
190
|
+
- Path: Removes trailing slash (except for root `/`), ensures starts with `/`, then base64 URL encodes
|
|
191
|
+
|
|
192
|
+
**Example:**
|
|
193
|
+
- URL: `https://www.example.com/products/item`
|
|
194
|
+
- Metaconfig Path: `opportunities/example.com/config`
|
|
195
|
+
- Patch Config Path: `opportunities/example.com/L3Byb2R1Y3RzL2l0ZW0`
|
|
196
|
+
- Where `L3Byb2R1Y3RzL2l0ZW0` is base64 URL encoding of `/products/item`
|
|
197
|
+
|
|
198
|
+
### Metaconfig File Structure
|
|
199
|
+
Domain-level metaconfig (created once per domain, shared by all URLs):
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"siteId": "abc-123",
|
|
203
|
+
"prerender": true
|
|
204
|
+
}
|
|
93
205
|
```
|
|
94
206
|
|
|
95
|
-
|
|
207
|
+
### Configuration File Structure
|
|
208
|
+
Per-URL configuration (flat structure):
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"url": "https://example.com/products/item",
|
|
212
|
+
"version": "1.0",
|
|
213
|
+
"forceFail": false,
|
|
214
|
+
"prerender": true,
|
|
215
|
+
"patches": [
|
|
216
|
+
{
|
|
217
|
+
"opportunityId": "abc-123",
|
|
218
|
+
"suggestionId": "xyz-789",
|
|
219
|
+
"prerenderRequired": true,
|
|
220
|
+
"lastUpdated": 1234567890,
|
|
221
|
+
"op": "insertAfter",
|
|
222
|
+
"selector": "main",
|
|
223
|
+
"value": { ... },
|
|
224
|
+
"valueFormat": "hast",
|
|
225
|
+
"target": "ai-bots"
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
```
|
|
96
230
|
|
|
231
|
+
**Note:**
|
|
232
|
+
- `siteId` is stored only in domain-level `config` (metaconfig)
|
|
233
|
+
- `prerender` is stored in both metaconfig (domain-level) and patch files (URL-level)
|
|
234
|
+
- The `baseURL` field has been renamed to `url`
|
|
235
|
+
- The `tokowakaOptimizations` nested structure has been removed
|
|
236
|
+
- The `tokowakaForceFail` field has been renamed to `forceFail`
|
|
97
237
|
|
|
98
238
|
## Reference Material
|
|
99
239
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-tokowaka-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Tokowaka Client for SpaceCat - Edge optimization config management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/spacecat-shared-utils": "1.66.1",
|
|
38
|
-
"@aws-sdk/client-cloudfront": "3.
|
|
39
|
-
"@aws-sdk/client-s3": "3.
|
|
38
|
+
"@aws-sdk/client-cloudfront": "3.937.0",
|
|
39
|
+
"@aws-sdk/client-s3": "3.937.0",
|
|
40
40
|
"mdast-util-from-markdown": "2.0.2",
|
|
41
|
-
"mdast-util-to-hast": "12.
|
|
41
|
+
"mdast-util-to-hast": "12.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"aws-sdk-client-mock": "4.1.0",
|