Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sites-29590): support user bearer token #22

Merged
merged 3 commits into from
Mar 11, 2025
Merged

fix(sites-29590): support user bearer token #22

merged 3 commits into from
Mar 11, 2025

Conversation

bhellema
Copy link
Collaborator

@bhellema bhellema commented Mar 8, 2025

No description provided.

@bhellema bhellema requested a review from ManasMaji March 8, 2025 04:23
Comment on lines +93 to +94
export async function uploadAssets(target, token, assetFolder, fileUploader = null) {
const fileUpload = fileUploader || createFileUploader();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One doubt: why are we allowing a fileUploader instance to be passed, since this is an implementation details which consumer should not have access to.
Also, in case the consumer passes a random value (since the type definition is not explicit) here it will break the logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the fileUploader allows me to test the fact that it was uploaded. This is a super weird/hard function to test. Do you see any other way of testing this?

let assetPath = path.join(downloadFolder, jcrPath.replace(CONTENT_DAM_PREFIX, ''));
fs.mkdirSync(path.dirname(assetPath), { recursive: true });

const buffer = Buffer.from(await blob.arrayBuffer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, your implementation is so much simpler! 🥇

for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
const file = new File([fs.readFileSync(packagePath)], 'file');
const formData = new FormData();
formData.set('install', 'true');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so we can directly install a package, without having to upload it first! 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that. One thing that continues to mess things up is the index page on reinstalls. There's a install issue due to nodes being present iirc. Once I delete the index page then it installed fine.

* @return {Promise<Array<PromiseSettledResult<string>>>} A promise that resolves when all assets are downloaded.
* Each promise in the array will resolve with the JCR path of the downloaded asset.
*/
export async function downloadAssets(assetMapping, downloadFolder, maxRetries = 3,retryDelay = 5000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function downloadAssets(assetMapping, downloadFolder, maxRetries = 3,retryDelay = 5000) {
export async function downloadAssets(assetMapping, downloadFolder, maxRetries = 3, retryDelay = 5000) {
  1. Should the maxRetries also be read from the process.env.MAX_RETRIES (similar to how it is done in package-helper.js)?
  2. Same for the retryDelay should be just declare a const and not have it as an input (to keep the method signatures consistent)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I think no one is going to mess with those environment variables. If it doesn't work after a specific number of tries, there's something wrong.


Run the following command to upload content package (JCR pages) and associated assets to your AEM author:

```
npm run aem-upload -- --zip /path/to/zip.zip --asset-mapping /path/to/asset-mapping.json
npm run aem-upload -- \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +33 to +35
const scope = nock('http://www.aem.com')
.get('/asset1.jpg')
.replyWithFile(200, path.resolve(__dirname, 'fixtures/image1.jpeg'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Makes mocking api calls so much cleaner. clap-clap

@bhellema bhellema merged commit 4d190b1 into main Mar 11, 2025
2 checks passed
@bhellema bhellema deleted the bhellema/1 branch March 11, 2025 12:44
github-actions bot pushed a commit that referenced this pull request Mar 11, 2025
# 1.0.0 (2025-03-11)

### Bug Fixes

* Add unit test coverage ([#6](#6)) ([16b6146](16b6146))
* Figure out asset folder name from jcr image path ([#15](#15)) ([461292c](461292c))
* **sites-29589:** [Xwalk] aem-import-helper should take zip file and image mapping as args ([#20](#20)) ([2c1c615](2c1c615))
* **sites-29590:** support user bearer token ([#22](#22)) ([4d190b1](4d190b1))

### Features

* [Import Assistant] Page transformations ([#4](#4)) ([bfacdb0](bfacdb0))
* Implement standalone upload command ([72fd15d](72fd15d))
* Import Assistant ([#7](#7)) ([05e2082](05e2082))
* Initial implementation of SharePoint upload ([00eb93a](00eb93a))
* Initial implementation of SharePoint upload ([6cfc248](6cfc248))
* Initial implementation of SharePoint upload ([927d7eb](927d7eb))
* Initial implementation of SharePoint upload ([cc5a4b1](cc5a4b1))
* Show UI URL when job was created ([#13](#13)) ([04db418](04db418))
* SITES-27041 [Import Assistant] Remove system prompts from import builder ([#9](#9)) ([978a68d](978a68d))
* **sites-29400:** integrate xwalk support into aem-import-helper ([#17](#17)) ([e4e3afd](e4e3afd))
* **sites-29416:** [Xwalk] Add support for importing non-image assets ([#19](#19)) ([3c6c87d](3c6c87d))
* SITES-29655 Remove import assistant related code from the helper ([823c56a](823c56a))
* SITES-29655 Remove import assistant related code from the helper ([c3caac0](c3caac0))
* SITES-29655 Remove import assistant related code from the helper ([7f262e1](7f262e1))
* Upload content to AEM ([#11](#11)) ([6140cf1](6140cf1))
* Use multipart formdata to start a job ([#3](#3)) ([852d96d](852d96d))
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants