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

chore(application-system): using aws-sdkv3 initial implementation #16281

Merged
merged 38 commits into from
Oct 16, 2024

Conversation

HjorturJ
Copy link
Member

@HjorturJ HjorturJ commented Oct 4, 2024

...

https://app.asana.com/0/1207402031871459/1208590659495997/f

What

Implement s3 aws sdk v3 without breaking anything

Why

because aws sdk v2 will be depricated in 2025

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced file upload and export functionalities with improved parameter structures for AWS S3 operations.
    • Introduced new methods for file handling in the AWS service, including presigned URL generation.
  • Bug Fixes

    • Improved error handling for PDF generation to enhance reliability.
  • Documentation

    • Updated test suite for AWS service to reflect new method names and functionalities.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request focus on enhancing AWS service integration within the application. Key updates include refactoring methods in the EndorsementListService and SharedTemplateApiService to adopt an object-based parameter structure for file operations. Error handling improvements have also been made in the PDF generation process, ensuring clearer logging when failures occur.

Changes

File Change Summary
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts Updated exportList and uploadFileToS3 methods to use an object parameter for presigned URL generation and file uploads. Enhanced error handling in createPdfBuffer.
libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts Modified saveAttachmentToApplication method to encapsulate parameters for uploadFile method in an object.

Possibly related PRs

Suggested reviewers

  • rafnarnason
  • HjorturJ
  • kksteini

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 05e86d2 and 7aa62af.

📒 Files selected for processing (2)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2 hunks)
  • libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts
  • libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 4, 2024

Datadog Report

All test runs 487ac6e 🔗

101 Total Test Services: 0 Failed, 99 Passed
🔻 Test Sessions change in coverage: 9 decreased, 2 increased, 183 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 81 0 34.34s N/A Link
air-discount-scheme-web 0 0 0 2 0 9.3s N/A Link
api 0 0 0 4 0 3.08s N/A Link
api-catalogue-services 0 0 0 23 0 11.62s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 18.85s N/A Link
api-domains-assets 0 0 0 3 0 11.94s N/A Link
api-domains-auth-admin 0 0 0 18 0 12.4s N/A Link
api-domains-communications 0 0 0 5 0 34.3s N/A Link
api-domains-criminal-record 0 0 0 5 0 9.98s N/A Link
api-domains-driving-license 0 0 0 23 0 31.85s N/A Link

🔻 Code Coverage Decreases vs Default Branch (9)

This report shows up to 5 code coverage decreases.

  • services-endorsements-api - jest 51.67% (-0.41%) - Details
  • clients-middlewares - jest 75.42% (-0.31%) - Details
  • api-domains-mortgage-certificate - jest 34.5% (-0.06%) - Details
  • services-auth-personal-representative-public - jest 40.7% (-0.03%) - Details
  • services-auth-public-api - jest 45.9% (-0.02%) - Details

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 79.22078% with 16 lines in your changes missing coverage. Please review.

Project coverage is 36.73%. Comparing base (695edee) to head (7aa62af).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
libs/nest/aws/src/lib/aws.service.ts 82.25% 11 Missing ⚠️
libs/application/api/files/src/lib/file.service.ts 75.00% 2 Missing ⚠️
...templates/parental-leave/parental-leave.service.ts 50.00% 2 Missing ⚠️
...modules/endorsementList/endorsementList.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #16281    +/-   ##
========================================
  Coverage   36.72%   36.73%            
========================================
  Files        6809     6810     +1     
  Lines      141179   141284   +105     
  Branches    40248    40273    +25     
========================================
+ Hits        51846    51896    +50     
- Misses      89333    89388    +55     
Flag Coverage Δ
air-discount-scheme-backend 54.06% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 36.93% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.89% <ø> (ø)
api-domains-criminal-record 48.00% <ø> (ø)
api-domains-driving-license 44.40% <ø> (ø)
api-domains-education 31.51% <ø> (ø)
api-domains-health-insurance 34.77% <ø> (ø)
api-domains-mortgage-certificate 34.95% <ø> (ø)
api-domains-payment-schedule 41.16% <ø> (ø)
application-api-files 56.70% <19.71%> (-1.32%) ⬇️
application-core 71.85% <ø> (ø)
application-system-api 41.37% <17.10%> (-0.03%) ⬇️
application-template-api-modules 27.86% <13.23%> (-0.01%) ⬇️
application-templates-accident-notification 29.29% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.35% <ø> (ø)
application-templates-driving-license 18.29% <ø> (ø)
application-templates-estate 12.31% <ø> (ø)
application-templates-example-payment 25.14% <ø> (ø)
application-templates-financial-aid 14.27% <ø> (ø)
application-templates-general-petition 23.43% <ø> (ø)
application-templates-inheritance-report 6.43% <ø> (ø)
application-templates-marriage-conditions 15.09% <ø> (ø)
application-templates-mortgage-certificate 43.78% <ø> (ø)
application-templates-parental-leave 29.97% <ø> (+0.12%) ⬆️
application-types 6.69% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.35% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 29.84% <ø> (ø)
auth-react 22.77% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.67% <ø> (ø)
clients-driving-license-book 43.80% <ø> (ø)
clients-financial-statements-inao 49.32% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 73.05% <ø> (+0.33%) ⬆️
clients-regulations 42.80% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.44% <ø> (ø)
clients-zendesk 54.61% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.02% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 5.44% <ø> (-0.14%) ⬇️
dokobit-signing 63.38% <ø> (ø)
download-service 44.19% <ø> (ø)
email-service 61.13% <ø> (ø)
feature-flags 91.11% <ø> (ø)
file-storage 53.71% <ø> (ø)
financial-aid-backend 56.40% <ø> (ø)
financial-aid-shared 19.03% <ø> (ø)
icelandic-names-registry-backend 53.97% <ø> (ø)
infra-nest-server 48.17% <ø> (ø)
infra-tracing 43.24% <ø> (ø)
island-ui-core 28.39% <ø> (ø)
judicial-system-api 18.36% <ø> (ø)
judicial-system-audit-trail 69.35% <ø> (ø)
judicial-system-backend 55.15% <ø> (ø)
judicial-system-formatters 79.25% <ø> (ø)
judicial-system-message 67.24% <ø> (ø)
judicial-system-message-handler 48.35% <ø> (ø)
judicial-system-scheduler 69.54% <ø> (ø)
judicial-system-types 47.12% <ø> (ø)
judicial-system-web 27.91% <ø> (ø)
license-api 42.67% <ø> (-0.08%) ⬇️
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 67.80% <ø> (ø)
nest-audit 68.20% <ø> (ø)
nest-aws 60.29% <80.95%> (?)
nest-config 78.44% <ø> (ø)
nest-feature-flags 51.52% <ø> (ø)
nest-problem 45.85% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 62.74% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 16.15% <ø> (ø)
reference-backend 49.79% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 51.89% <ø> (ø)
services-auth-delegation-api 57.38% <ø> (+0.06%) ⬆️
services-auth-ids-api 51.43% <ø> (+<0.01%) ⬆️
services-auth-personal-representative 45.16% <ø> (ø)
services-auth-personal-representative-public 41.24% <ø> (ø)
services-auth-public-api 48.91% <ø> (ø)
services-documents 60.58% <ø> (ø)
services-endorsements-api 53.63% <14.06%> (-0.54%) ⬇️
services-sessions 65.33% <ø> (-0.05%) ⬇️
services-university-gateway 48.42% <ø> (+0.11%) ⬆️
services-user-notification 46.97% <ø> (-0.04%) ⬇️
services-user-profile 62.18% <ø> (+0.07%) ⬆️
shared-components 27.65% <ø> (ø)
shared-form-fields 31.59% <ø> (ø)
shared-mocking 64.62% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.90% <ø> (ø)
skilavottord-ws 24.24% <ø> (ø)
testing-e2e 66.66% <ø> (ø)
web 1.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rc/app/modules/application/template-api.service.ts 0.00% <ø> (ø)
...i-modules/src/lib/modules/shared/shared.service.ts 48.54% <ø> (ø)
.../templates/parental-leave/parental-leave.module.ts 100.00% <100.00%> (ø)
libs/nest/aws/src/lib/aws.module.ts 100.00% <100.00%> (ø)
...modules/endorsementList/endorsementList.service.ts 30.34% <0.00%> (ø)
libs/application/api/files/src/lib/file.service.ts 78.89% <75.00%> (-0.20%) ⬇️
...templates/parental-leave/parental-leave.service.ts 45.73% <50.00%> (+0.13%) ⬆️
libs/nest/aws/src/lib/aws.service.ts 80.30% <82.25%> (+57.57%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9451f1d...7aa62af. Read the comment docs.

@HjorturJ HjorturJ added the deploy-feature Deploys features to dev label Oct 4, 2024
Copy link
Contributor

github-actions bot commented Oct 4, 2024

Affected services are: air-discount-scheme-api,air-discount-scheme-backend,api,application-system-api,download-service,financial-aid-api,financial-aid-backend,financial-aid-open-api,github-actions-cache,icelandic-names-registry-backend,judicial-system-api,judicial-system-digital-mailbox-api,judicial-system-backend,judicial-system-message-handler,judicial-system-robot-api,judicial-system-scheduler,judicial-system-xrd-api,license-api,reference-backend,regulations-admin-backend,services-auth-admin-api,services-auth-ids-api,services-auth-delegation-api,services-auth-personal-representative,services-auth-personal-representative-public,services-auth-public-api,services-contentful-entry-tagger,services-documents,services-endorsements-api,services-form-system,services-search-indexer,services-sessions,services-university-gateway,services-user-notification,services-user-profile,services-xroad-collector,skilavottord-ws,air-discount-scheme-web,auth-admin-web,consultation-portal,contentful-apps,financial-aid-web-osk,financial-aid-web-veita,judicial-system-web,skilavottord-web,web,application-system-form,island-ui-storybook,portals-admin,service-portal,system-e2e,external-contracts-tests,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://choreaws-v3-s3-implementation-api-catalogue.dev01.devland.is/api
https://choreaws-v3-s3-implementation-api.dev01.devland.is/download
https://choreaws-v3-s3-implementation-application-callback-xrd.internal.dev01.devland.is/application-payment
https://choreaws-v3-s3-implementation-application-callback-xrd.internal.dev01.devland.is/applications
https://choreaws-v3-s3-implementation-application-payment-callback-xrd.internal.dev01.devland.is/application-payment
https://choreaws-v3-s3-implementation-application-payment-callback-xrd.internal.dev01.devland.is/applications
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/api
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/app/skilavottord/
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/app/skilavottord/api/graphql
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/minarsidur
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/samradsgatt
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/stjornbord
https://choreaws-v3-s3-implementation-beta.dev01.devland.is/umsoknir
https://choreaws-v3-s3-implementation-license-api-xrd.internal.dev01.devland.is/
https://choreaws-v3-s3-implementation-loftbru-cf.dev01.devland.is/
https://choreaws-v3-s3-implementation-loftbru-cf.dev01.devland.is/api/graphql
https://choreaws-v3-s3-implementation-loftbru-cf.dev01.devland.is/api/public
https://choreaws-v3-s3-implementation-loftbru-cf.dev01.devland.is/api/swagger
https://choreaws-v3-s3-implementation-loftbru.dev01.devland.is/
https://choreaws-v3-s3-implementation-loftbru.dev01.devland.is/api/graphql
https://choreaws-v3-s3-implementation-loftbru.dev01.devland.is/api/public
https://choreaws-v3-s3-implementation-loftbru.dev01.devland.is/api/swagger
https://choreaws-v3-s3-implementation-service-portal-api.internal.dev01.devland.is/
https://choreaws-v3-s3-implementation-services-university-gateway.internal.dev01.devland.is/api
https://choreaws-v3-s3-implementation-sessions-api.internal.dev01.devland.is/
https://choreaws-v3-s3-implementation-ui.dev01.devland.is/

Deployed services: application-system-api,application-system-form,service-portal,service-portal-api,portals-admin,consultation-portal,api,web,xroad-collector,skilavottord-web,skilavottord-ws,services-documents,island-ui-storybook,download-service,icelandic-names-registry-backend,endorsement-system-api,air-discount-scheme-web,air-discount-scheme-backend,air-discount-scheme-api,regulations-admin-backend,external-contracts-tests,application-system-api-worker,license-api,services-sessions,services-sessions-worker,services-sessions-cleanup,services-university-gateway,services-university-gateway-worker.
Excluded services: search-indexer-service,github-actions-cache,user-notification,user-notification-worker,user-notification-cleanup-worker,contentful-entry-tagger-service,contentful-apps

@HjorturJ HjorturJ marked this pull request as ready for review October 9, 2024 09:30
@HjorturJ HjorturJ requested review from a team as code owners October 9, 2024 09:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🧹 Outside diff range and nitpick comments (16)
libs/nest/aws/src/lib/aws.module.ts (1)

7-13: LGTM: Updated providers with S3Client

The addition of S3Client as a provider is correct and necessary for dependency injection. Using useValue with new S3Client() creates a singleton instance, which is generally a good practice.

Consider using useFactory instead of useValue for more flexibility in configuration, especially if you need to pass options to the S3Client constructor in the future. For example:

{
  provide: S3Client,
  useFactory: () => new S3Client(/* potential config options */),
}

This approach would allow for easier configuration changes and environment-specific setups in the future.

libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts (2)

26-26: LGTM: AwsModule correctly added to imports. Consider sorting imports alphabetically.

The addition of AwsModule to the imports array is consistent with the new import statement and aligns with the PR objective of implementing AWS SDK v3.

For better readability and consistency, consider sorting the imports alphabetically. Here's a suggested change:

 imports: [
+  ApplicationApiCoreModule,
+  AwsModule,
   NationalRegistryClientModule,
   SharedTemplateAPIModule.register(config),
   SmsModule,
   VMSTModule,
-  ApplicationApiCoreModule,
-  AwsModule,
 ],

Line range hint 1-38: Confirm adherence to coding guidelines for libs//* files**

The module adheres well to the coding guidelines:

  1. It's located in the libs/ directory, promoting reusability across different NextJS apps.
  2. It uses TypeScript effectively with proper import/export statements and type definitions.
  3. The specific import of AwsModule supports effective tree-shaking.

To further improve type safety and exportability:

Consider explicitly exporting the BaseTemplateAPIModuleConfig type used in the register method:

export { BaseTemplateAPIModuleConfig } from '../../../types'

This would enhance the module's type safety and make it easier for consumers to use the correct configuration type.

apps/application-system/api/src/app/modules/application/template-api.service.ts (1)

45-47: LGTM! Consider adding type annotation for improved clarity.

The changes to the uploadFile method call align well with AWS SDK v3's object-based parameter approach. This update improves code readability and maintainability while maintaining the same functionality.

Consider adding a type annotation to the object parameter for improved clarity:

await this.awsService.uploadFile(
  buffer,
  { bucket: uploadBucket, key: s3key } as const,
  uploadParameters,
)

This change would make the parameter structure more explicit and help prevent potential errors in the future.

libs/application/api/files/src/lib/file.service.ts (3)

57-59: Approve changes with a suggestion for type safety

The updates to fileExists and uploadFile method calls align well with the transition to AWS SDK v3's object-based parameters. This change enhances code consistency and readability.

To further improve type safety and maintainability, consider defining an interface for the bucket and key object:

interface S3Location {
  bucket: string;
  key: string;
}

Then use this interface in method calls:

if ((await this.awsService.fileExists(location as S3Location)) === false) {
  // ...
  await this.awsService.uploadFile(
    content,
    location as S3Location,
    // ...
  )
}

This approach will make the code more robust and easier to maintain across the codebase.

Also applies to: 61-69


88-91: Approve change with suggestion for consistency

The update to the uploadFile method call in the uploadSignedFile method is consistent with the transition to object-based parameters. This change enhances code consistency and aligns with the AWS SDK v3 style.

For improved consistency, consider using a single object for all parameters:

await this.awsService.uploadFile({
  content: Buffer.from(file, 'binary'),
  location: { bucket, key: s3FileName },
  options: {
    ContentEncoding: 'binary',
    ContentType: 'application/pdf',
  },
});

This approach would make all AWS service method calls consistent throughout the file.


156-159: Approve change with suggestion for type safety

The introduction of the getFileContent method with object-based parameters is consistent with the AWS SDK v3 style and enhances code flexibility.

To improve type safety and code clarity, consider defining an enum for the encoding type:

enum S3FileEncoding {
  BINARY = 'binary',
  UTF8 = 'utf8',
  // Add other encoding types as needed
}

// Usage
const fileContent = await this.awsService.getFileContent(
  { bucket, key: s3FileName },
  S3FileEncoding.BINARY
);

This approach will make the code more robust and self-documenting.

libs/application/api/files/src/lib/file.service.spec.ts (1)

Line range hint 1-377: Overall assessment: Code changes improve quality and consistency.

The updates in this file consistently implement the transition to AWS SDK v3, improving code clarity and maintaining a uniform approach across the test suite. The changes adhere to the coding guidelines for the libs directory, enhancing reusability and modularity. The object-based parameter structure for AWS service methods improves readability and reduces the likelihood of errors.

To further improve the code:

  1. Consider adding type annotations for the object parameters to enhance type safety.
  2. Update the documentation comments if any exist for these methods to reflect the new parameter structure.
libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.spec.ts (1)

Line range hint 1-524: Adherence to coding guidelines for libs/**/*

The file generally adheres to the coding guidelines:

  1. Reusability: As part of a library, this test suite contributes to the reusability of the ParentalLeaveService across different NextJS apps.
  2. TypeScript usage: The file effectively uses TypeScript for defining types and interfaces, enhancing code quality and maintainability.

However, to further improve adherence to guidelines:

  1. Consider extracting common test setup logic into shared helper functions to enhance reusability within the test suite.
  2. Ensure that any new AWS SDK v3 related code (when implemented) follows effective tree-shaking and bundling practices.
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (3)

686-689: Improved AWS S3 integration and error handling

The changes to the getPresignedUrl method call are good. Using an object parameter enhances code readability and reduces the likelihood of errors. The error handling has also been improved.

Consider adding more specific error types for different failure scenarios. For example:

} catch (error) {
  this.logger.error(`Failed to export list ${listId}`, { error })
  if (error instanceof NotFoundException) {
    throw error;
  }
  throw new InternalServerErrorException('Failed to export list');
}

This approach provides more granular error responses to the client.


754-754: Consistent use of object parameters for AWS S3 operations

The update to use an object parameter for bucket and key in the uploadFileToS3 method is consistent with the changes made in the exportList method. This improves code readability and maintainability.

Consider enhancing the error handling to provide more context:

} catch (error) {
  this.logger.error(`Failed to upload file to S3`, { error, filename, bucket: environment.exportsBucketName })
  throw new InternalServerErrorException('Error uploading file to S3');
}

This will provide more detailed logging and a more specific error response.


Line range hint 1-754: Overall assessment of AWS SDK v3 integration

The changes in this file successfully implement the transition to AWS SDK v3 for S3 operations. The modifications are focused on the exportList and uploadFileToS3 methods, updating them to use the new object-based parameter structure for S3 operations.

Key points:

  1. The changes are consistent and well-implemented.
  2. Error handling has been maintained and slightly improved.
  3. The updates don't introduce any breaking changes to the service's public API.
  4. The modifications align with the PR objective of implementing AWS SDK v3.

As you continue to update other parts of the application to use AWS SDK v3, ensure consistent error handling and logging practices across all AWS service integrations. Consider creating a centralized AWS error handling utility to standardize error responses and logging for all AWS operations.

libs/nest/aws/src/lib/aws.service.ts (1)

85-85: Address TODO: Select default expiration for presigned URLs

There's a TODO comment indicating the need to select a default expiration time for presigned URLs. Defining a standard expiration ensures consistency and security across the application.

Would you like assistance in determining an appropriate default expiration time and implementing it?

libs/nest/aws/src/lib/aws.service.spec.ts (3)

110-110: Fix typo in test description

There's a typo in the test description on line 110: "doesnt" should be "doesn't".

Apply this diff to correct the typo:

-    'should return false if the object doesnt exist in s3',
+    "should return false if the object doesn't exist in s3",

150-162: Add test cases for edge URLs in getBucketKey method

The test for getBucketKey could include additional edge case URLs, such as URLs with query parameters or different S3 endpoint formats, to ensure robust parsing.

Consider adding more test cases:

const edgeCaseUri = 'https://abc.s3.example.com/def?versionId=123'
const resultFromEdgeCase = awsService.getBucketKey(edgeCaseUri)

expect(resultFromEdgeCase.bucket).toEqual(bucketKeyPair.bucket)
expect(resultFromEdgeCase.key).toEqual(bucketKeyPair.key)

145-145: Log the error message directly instead of creating a new Error

When logging the error, it's not necessary to create a new Error object with the message. Instead, log the message directly or pass the actual error object if available.

Apply this diff to simplify the logging:

-        Error('Unexpected http response when deleting object from S3'),
+        'Unexpected HTTP response when deleting object from S3',

Or if there's an error object:

-        Error('Unexpected http response when deleting object from S3'),
+        actualError,

This approach provides clearer logging without unnecessary object creation.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eb721e9 and dbc153a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • apps/application-system/api/src/app/modules/application/template-api.service.ts (1 hunks)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2 hunks)
  • libs/application/api/files/src/lib/file.service.spec.ts (8 hunks)
  • libs/application/api/files/src/lib/file.service.ts (6 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts (2 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.spec.ts (2 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts (3 hunks)
  • libs/nest/aws/src/lib/aws.module.ts (1 hunks)
  • libs/nest/aws/src/lib/aws.service.spec.ts (1 hunks)
  • libs/nest/aws/src/lib/aws.service.ts (1 hunks)
  • package.json (2 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
apps/application-system/api/src/app/modules/application/template-api.service.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/application/api/files/src/lib/file.service.spec.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/api/files/src/lib/file.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.spec.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/nest/aws/src/lib/aws.module.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/nest/aws/src/lib/aws.service.spec.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/nest/aws/src/lib/aws.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (23)
libs/nest/aws/src/lib/aws.module.ts (2)

3-3: LGTM: Import of S3Client from AWS SDK v3

The import of S3Client from @aws-sdk/client-s3 is correct and aligns with the PR objective of implementing AWS SDK v3.


14-14: LGTM: Exported AwsService and S3Client

The updated exports array now includes both AwsService and S3Client, which increases the module's flexibility and reusability. This change aligns well with the coding guideline for reusability of components across different NextJS apps.

libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.module.ts (2)

14-14: LGTM: Import statement is correctly formatted and follows best practices.

The import of AwsModule from '@island.is/nest/aws' is well-structured and follows TypeScript conventions. It imports a specific module, which is beneficial for effective tree-shaking.


Line range hint 1-38: Summary: AWS integration successfully implemented

The changes in this file successfully integrate the AWS module into the ParentalLeaveModule. This aligns with the PR objective of implementing AWS SDK v3. The modifications are minimal and maintain the existing structure of the module.

Key points:

  1. AwsModule is correctly imported and added to the module's imports.
  2. The changes adhere to the coding guidelines for libs/**/* files.
  3. The module remains reusable and continues to use TypeScript effectively.

These changes lay the groundwork for using AWS services within the parental leave application system. Ensure that the actual usage of AWS services is implemented in the relevant service files.

libs/application/api/files/src/lib/file.service.ts (4)

72-72: Approve change to getPresignedUrl

The update to the getPresignedUrl method call is consistent with the transition to object-based parameters. This change enhances code consistency and aligns with the AWS SDK v3 style.


138-138: Approve change to getPresignedUrl

The update to the getPresignedUrl method call is consistent with the transition to object-based parameters. This change enhances code consistency and aligns with the AWS SDK v3 style.


260-260: Approve change to deleteObject

The update to the deleteObject method call is consistent with the transition to object-based parameters. This change enhances code consistency and aligns with the AWS SDK v3 style.


Line range hint 1-300: Summary of FileService changes

The changes made to the FileService class consistently update AWS S3 operations to use object-based parameters, aligning with AWS SDK v3 standards. This transition enhances code readability, flexibility, and maintainability.

Key improvements:

  1. Consistent use of object parameters for bucket and key across all AWS service method calls.
  2. Enhanced reusability of the code, making it more adaptable to different AWS configurations.

Suggestions for further improvement:

  1. Introduce interfaces or types for commonly used parameter objects (e.g., S3Location).
  2. Consider using enums for string literals to improve type safety.
  3. Standardize the parameter structure across all AWS service method calls for even greater consistency.

Overall, these changes represent a significant step towards modernizing the codebase and improving its maintainability.

libs/application/api/files/src/lib/file.service.spec.ts (7)

8-8: LGTM: Import statement updated correctly.

The import statement has been updated to include both AwsModule and AwsService. This change aligns with the transition to AWS SDK v3 and adheres to the coding guideline for reusability of components across different NextJS apps.


Line range hint 118-128: LGTM: Test module setup updated correctly.

The test module setup has been updated to use AwsModule in the imports array instead of providing AwsService directly. This change enhances modularity and reusability, aligning with the coding guidelines for the libs directory.


178-189: LGTM: Mock calls updated to use object-based parameters.

The uploadFile and getPresignedUrl mock calls have been updated to use an object-based parameter structure. This change improves code clarity and consistency, aligning with the transition to AWS SDK v3.


201-203: LGTM: getFileContent mock call updated consistently.

The getFileContent mock call has been updated to use an object-based parameter structure, consistent with the other AWS service method updates in this file. This change enhances code clarity and maintains consistency across the test suite.


274-277: LGTM: getPresignedUrl mock call updated consistently.

The getPresignedUrl mock call has been updated to use an object-based parameter structure, maintaining consistency with the other AWS service method updates in this file. This change enhances code clarity and ensures a uniform approach across the test suite.


227-228: LGTM: getFileContent mock implementation updated correctly.

The mock implementation for getFileContent has been updated, consistent with the method name change observed earlier in the file.

To ensure the implementation is consistent across the codebase, please run the following script:

#!/bin/bash
# Description: Verify the implementation of 'getFileContent' across the codebase

# Test: Search for the implementation of 'getFileContent'. Expect: Consistent implementation.
rg --type typescript -A 5 'getFileContent\s*\('

134-135: LGTM: Mock updated to reflect new method name.

The mock has been correctly updated from getFile to getFileContent, reflecting the changes in the AWS SDK v3 implementation.

To ensure consistency across the codebase, please run the following script to verify the method name change:

libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.spec.ts (1)

45-45: LGTM: AwsService added to test providers

The addition of AwsService to the test module providers aligns with the PR objective of implementing AWS SDK v3. This change prepares the testing environment for potential AWS-related tests in the future.

However, to ensure comprehensive test coverage:

  1. Consider adding specific tests for AWS SDK v3 functionality if applicable to this service.
  2. Verify that existing tests still pass with this new provider.

To ensure no regressions were introduced, please run the following command:

Also applies to: 243-246

package.json (1)

72-72: LGTM: AWS SDK v3 dependencies added successfully.

The addition of AWS SDK v3 dependencies for S3 operations aligns well with the PR objective. The consistent versioning (3.662.0) across these packages is good for compatibility.

Could you please verify if the AWS SDK v2 dependency ("aws-sdk": "2.814.0") is still needed? If it's part of a gradual migration strategy, consider updating the project documentation to reflect the use of both SDK versions to avoid confusion for other developers.

Also applies to: 75-76, 148-148

libs/nest/aws/src/lib/aws.service.ts (1)

1-12: Positive impact on bundling by using AWS SDK v3's modular imports

By updating to AWS SDK v3 and utilizing modular imports, the codebase benefits from improved tree-shaking and reduced bundle sizes. This aligns with effective bundling practices outlined in the coding guidelines.

libs/nest/aws/src/lib/aws.service.spec.ts (2)

21-163: Comprehensive test coverage and adherence to coding guidelines

The test suite provides comprehensive coverage of the AwsService functionalities, adhering to the coding guidelines for TypeScript usage and code reusability.

Great job on implementing thorough tests that ensure the reliability of the AWS SDK v3 integration.


41-42: Ensure mocks are properly reset

In the beforeEach block, consider using s3Mock.resetHistory() and s3Mock.resetBehavior() for a more thorough reset of the mock state.

Run the following script to confirm the available reset methods and their usage:

Ensure that you're using the most appropriate methods to reset the mock between tests.

libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts (3)

2-2: LGTM!

The import statement for AwsService is correctly added.


115-115: Constructor injection of AwsService is correctly implemented

The AwsService is properly injected into the ParentalLeaveService constructor.


386-392: Ensure correct usage of awsService.getFileContent

Verify that the getFileContent method is being called with the correct parameters and that 'base64' is the appropriate argument according to the AwsService method signature.

libs/nest/aws/src/lib/aws.service.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.spec.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.spec.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.spec.ts Outdated Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.spec.ts Show resolved Hide resolved
libs/nest/aws/src/lib/aws.service.spec.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts (1)

290-292: LGTM! Consider adding a type for the upload options.

The change to use an object for specifying the bucket and key in the uploadFile method call is a good improvement. It aligns with the goal of implementing AWS SDK v3 and makes the code more structured and readable.

To further enhance type safety and code clarity, consider defining an interface for the upload options:

interface UploadOptions {
  bucket: string;
  key: string;
}

Then use it in the method call:

const uploadOptions: UploadOptions = { bucket: uploadBucket, key: s3key };
const url = await this.awsService.uploadFile(buffer, uploadOptions, uploadParameters);

This will make the code more self-documenting and help prevent potential errors in the future.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 151fa96 and 467d41a.

📒 Files selected for processing (2)
  • apps/system-e2e/src/tests/islandis/application-system/acceptance/parental-leave.spec.ts (2 hunks)
  • libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/system-e2e/src/tests/islandis/application-system/acceptance/parental-leave.spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/template-api-modules/src/lib/modules/shared/shared.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
libs/nest/aws/src/lib/aws.service.ts (5)

28-41: LGTM: Improved getFile and new getFileContent method

The getFile method has been updated to use a more flexible BucketKeyPairOrFilename parameter, and a new getFileContent method has been added with encoding support. These changes improve the API's usability and flexibility.

Consider adding a comment explaining the purpose of the getFileContent method and when to use it versus getFile.


44-76: LGTM: Improved uploadFile method with better error handling

The uploadFile method has been updated to use the new Upload class from AWS SDK v3, which allows for better handling of large files and provides progress tracking capabilities. The error handling and logging have also been improved.

Consider adding a comment explaining the benefits of using the Upload class, such as its ability to handle large files and track progress.


79-94: LGTM: Updated getPresignedUrl method with flexible expiration

The getPresignedUrl method has been updated to use the new getSignedUrl function from AWS SDK v3 and now includes an expirationOverride parameter for flexibility.

Consider reducing the default expiration time from 120 minutes to a shorter duration (e.g., 15 minutes) to enhance security. Long-lived presigned URLs can pose a security risk if intercepted.


97-117: LGTM: Updated fileExists method with improved error handling

The fileExists method has been updated to use the HeadObjectCommand from AWS SDK v3 and includes improved error handling.

Consider differentiating between "file not found" errors and other types of errors. Currently, the method returns false for all error cases, which might mask unexpected issues. You could throw an error for unexpected cases while returning false only when the file is confirmed not to exist.


143-173: LGTM: Useful utility methods getBucketKey and getFileResponse

The new getBucketKey and getFileResponse methods improve code reusability and error handling across the service. The getBucketKey method correctly handles both object and string inputs, enhancing flexibility.

Consider making getBucketKey a private method since it's an internal utility and doesn't need to be exposed in the public API.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e1293f3 and 6659310.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • libs/nest/aws/src/lib/aws.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/nest/aws/src/lib/aws.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (3)
libs/nest/aws/src/lib/aws.service.ts (3)

1-19: LGTM: Updated imports and new interfaces

The import statements have been correctly updated to use AWS SDK v3, and the new BucketKeyPair interface and EncodingString type are well-defined. These changes align with the transition to the new SDK version and improve type safety in the service.


23-26: LGTM: Updated constructor for AWS SDK v3

The constructor has been correctly updated to inject S3Client instead of S3, which is necessary for the transition to AWS SDK v3. The injection is properly done using the @Inject decorator.


119-141: LGTM: Well-implemented deleteObject method

The new deleteObject method is well-implemented using the DeleteObjectCommand from AWS SDK v3. It includes proper error handling, logging, and correctly checks for both 200 and 204 status codes as successful responses.

Copy link
Member

@norda-gunni norda-gunni left a comment

Choose a reason for hiding this comment

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

LGTM

@HjorturJ HjorturJ added automerge Merge this PR as soon as all checks pass and removed deploy-feature Deploys features to dev labels Oct 15, 2024
Copy link
Member

@birkirkristmunds birkirkristmunds left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@eirikurn eirikurn left a comment

Choose a reason for hiding this comment

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

Approving core files with one question. Great job!

libs/nest/aws/src/lib/aws.module.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants