feat: replace IPFS upload with cover metadata API and add cover data management#518
feat: replace IPFS upload with cover metadata API and add cover data management#518valentinludu wants to merge 11 commits into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR refactors cover input handling from client-side schema validation to server-side metadata generation. It removes all legacy cover input IPFS schemas, redefines the IPFS content type system, introduces cover metadata type contracts with proof-of-loss entries and authentication types, refactors the Quote service to POST metadata to a dedicated backend endpoint instead of accepting pre-validated IPFS content, adds authentication and CoverData APIs, and updates all dependent tests. ChangesCover Metadata Generation Refactoring
Sequence DiagramsequenceDiagram
participant Caller
participant Quote
participant ProductAPI as Product API
participant MetadataAPI as POST /cover-metadata
Caller->>Quote: getQuoteAndBuyCoverInputs({coverMetadata, ...})
Quote->>ProductAPI: fetch product config
ProductAPI-->>Quote: ProductType with isProofOfLossRequired
alt isProofOfLossRequired && !coverMetadata
Quote-->>Caller: error: Missing cover metadata
else coverMetadata with proofOfLoss or publicData
Quote->>MetadataAPI: POST CoverMetadataInput
alt success
MetadataAPI-->>Quote: {cid}
Quote-->>Caller: buyCoverInput with ipfsData=cid
else failure
Quote-->>Caller: error: Failed to create cover metadata
end
else metadata absent or empty
Quote-->>Caller: buyCoverInput with ipfsData=''
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/quote/Quote.ts (1)
46-48:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate README to match the new
coverMetadata+POST /cover-metadataflow
README.mdstill documents the removedipfsCidOrContent/IPFSContentTypesparam and describes local IPFS upload behavior, butQuote.getQuoteAndBuyCoverInputsnow usescoverMetadataand creates the CID viaPOST /cover-metadata(then passes it asipfsData). Update the README examples and theipfsCidOrContentsection (≈ lines 180-196, 210-224, 229-232).Want me to draft the README update for the new
coverMetadataflow?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/quote/Quote.ts` around lines 46 - 48, README still documents the removed ipfsCidOrContent / IPFSContentTypes and local IPFS upload behavior; update all examples and sections (~lines noted) to reflect that Quote.getQuoteAndBuyCoverInputs now accepts coverMetadata, posts it to POST /cover-metadata to obtain a CID which is passed as ipfsData to the API, remove references to ipfsCidOrContent/IPFSContentTypes and replace with a short example showing construction of coverMetadata, the POST /cover-metadata call returning the CID, and how that CID is used as ipfsData in the getQuoteAndBuyCoverInputs call.
🧹 Nitpick comments (1)
src/quote/Quote.ts (1)
236-243: 💤 Low valueGuard against a missing response before reading
cid.The sibling helpers
getQuoteandgetProductCapacityboth checkif (!response) throw ...before dereferencing.createCoverMetadatareadsresponse.ciddirectly; ifsendRequestresolves toundefined, this throws an opaqueTypeErrorinstead of a clear error. Adding a guard keeps behavior consistent and produces a clearer message.♻️ Proposed guard
const response = await this.sendRequest<CoverMetadataResponse>('/cover-metadata', options); + if (!response?.cid) { + throw new Error('Failed to create cover metadata'); + } return response.cid;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/quote/Quote.ts` around lines 236 - 243, createCoverMetadata currently dereferences response.cid without ensuring sendRequest returned a value; add the same guard used in getQuote/getProductCapacity: after calling this.sendRequest<CoverMetadataResponse>('/cover-metadata', options) check if response is falsy and throw a descriptive error (e.g., "Failed to create cover metadata: empty response") before returning response.cid so we avoid opaque TypeErrors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/quote/Quote.ts`:
- Around line 141-162: Tighten the proof-of-loss gating: when
productType.isProofOfLossRequired is true, verify coverMetadata.proofOfLoss
exists and has content (e.g., check coverMetadata?.proofOfLoss?.length) and
return the same error if it’s missing or empty instead of only checking for
coverMetadata truthiness; update the hasCoverMetadata logic to reflect this.
Also harden createCoverMetadata usage by validating its response includes a
non-empty cid before assigning ipfsData (or return a clear error if cid is
missing), so you don’t silently proceed with ipfsData = '' when the backend
reply is unexpected.
---
Outside diff comments:
In `@src/quote/Quote.ts`:
- Around line 46-48: README still documents the removed ipfsCidOrContent /
IPFSContentTypes and local IPFS upload behavior; update all examples and
sections (~lines noted) to reflect that Quote.getQuoteAndBuyCoverInputs now
accepts coverMetadata, posts it to POST /cover-metadata to obtain a CID which is
passed as ipfsData to the API, remove references to
ipfsCidOrContent/IPFSContentTypes and replace with a short example showing
construction of coverMetadata, the POST /cover-metadata call returning the CID,
and how that CID is used as ipfsData in the getQuoteAndBuyCoverInputs call.
---
Nitpick comments:
In `@src/quote/Quote.ts`:
- Around line 236-243: createCoverMetadata currently dereferences response.cid
without ensuring sendRequest returned a value; add the same guard used in
getQuote/getProductCapacity: after calling
this.sendRequest<CoverMetadataResponse>('/cover-metadata', options) check if
response is falsy and throw a descriptive error (e.g., "Failed to create cover
metadata: empty response") before returning response.cid so we avoid opaque
TypeErrors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fe3d4bd1-d04e-46ba-ac68-3b6b2134fab0
📒 Files selected for processing (12)
src/ipfs/Ipfs.tssrc/ipfs/schemas.tssrc/ipfs/uploadIPFSContent.test.tssrc/ipfs/validateIPFSContent.test.tssrc/nexus-sdk.tssrc/quote/Quote.tssrc/quote/getQuoteAndBuyCoverInputs.test.tssrc/types/cover-metadata.tssrc/types/index.tssrc/types/ipfs.tssrc/types/product.tssrc/types/sdk.ts
💤 Files with no reviewable changes (4)
- src/ipfs/Ipfs.ts
- src/ipfs/validateIPFSContent.test.ts
- src/ipfs/schemas.ts
- src/types/ipfs.ts
Deploying sdk with
|
| Latest commit: |
72a5f56
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f31be761.sdk-9yp.pages.dev |
| Branch Preview URL: | https://feat-cover-metadata-api.sdk-9yp.pages.dev |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/auth.test.ts`:
- Around line 10-12: The test file uses a spy on Date.now that needs to be
properly cleaned up to prevent test pollution. Move the spy restoration call
from within the test body (around line 21) to an afterEach hook that wraps the
entire test suite. This ensures that Date.now is always restored to its original
state after each test completes, even if an assertion fails before the
restoration line, preventing the mock from leaking into subsequent tests.
In `@src/cover/Cover.ts`:
- Around line 44-46: In the Cover.ts file where signature is checked before
calling buildAuthHeaders, add validation logic to ensure the signature object
has the expected shape and required properties before building auth headers.
Instead of only checking if signature exists with the current if (signature)
condition, validate that the signature contains all necessary fields required by
buildAuthHeaders to construct valid authorization headers. This way, if an
incomplete or invalid signature is passed, you will get an early error with
clear context rather than letting buildAuthHeaders create malformed headers that
fail later during the viewCoverMetadata operation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f3dfbdfc-3209-4bd4-8a61-d9010a6f725d
📒 Files selected for processing (11)
src/auth.test.tssrc/auth.tssrc/cover/Cover.test.tssrc/cover/Cover.tssrc/cover/index.tssrc/index.tssrc/nexus-sdk.tssrc/quote/Quote.tssrc/quote/getQuoteAndBuyCoverInputs.test.tssrc/types/cover-metadata.tssrc/types/product.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/types/product.ts
- src/quote/getQuoteAndBuyCoverInputs.test.ts
- src/quote/Quote.ts
Summary
Quote.getQuoteAndBuyCoverInputswith a call toPOST /cover-metadataon the backendipfsCidOrContentparam, replace withcoverMetadataaccepting{ proofOfLoss?, publicData? }isProofOfLossRequired(from product type API) to enforce metadata requirementCoverDataclass withgetCover,viewCoverMetadata, andeditCoverMetadatamethodsbuildAuthTypedData,buildCoverMetadataAuthMessage) for signed cover metadata requestsWhat was removed
Ipfsdependency fromQuoteclass (still available onNexusSDK.ipfsfor claims/governance)coverValidators,coverQuotaShare,coverAumCoverAmountPercentage,coverWalletAddress,coverWalletAddresses,coverFreeText,coverDesignatedWallets,defiPassContentipfsContentTypefield fromProductTypeWhat was added
CoverDataclass (src/cover/Cover.ts) exposed asNexusSDK.coverwith:getCover(coverId)— fetch cover details by IDviewCoverMetadata({ coverMetadataId, signature? })— view cover metadata (public fields always returned; privateproofOfLossonly with a valid EIP-712 signature)editCoverMetadata({ coverMetadataId, proofOfLoss, signature })— update proof-of-loss entries on existing cover metadata (requires authentication)src/auth.ts):buildAuthTypedData(message)— builds an EIP-712 typed-data object for Nexus Mutual API authenticationbuildCoverMetadataAuthMessage()— convenience wrapper with the cover metadata auth messagesrc/types/cover-metadata.ts):CoverMetadataInput,CoverMetadataResponse— create metadata during buy-cover flowProofOfLossEntry(discriminated union:address,api_key,validator,csv,free_text)AddressValue,ApiKeyValue,ValidatorValue,CsvValue,FreeTextValue— entry content typesCoverPublicData— optionalquotaShare/aumCoverAmountPercentageGetCoverResponse,ViewCoverMetadataResponse,EditCoverMetadataParams,AuthSignature,AuthPayload— API contractsisProofOfLossRequiredonProductType,proofOfLossInputTypesonProductcreateCoverMetadata()method inQuotethat POSTs to/cover-metadataand returns the CIDWhy
Previously the SDK uploaded proof-of-loss data directly to IPFS, making sensitive information (wallet addresses, validator keys, API keys) publicly accessible on-chain. The new flow stores private data server-side in Postgres and only puts a UUID reference on IPFS, improving privacy for cover holders.
Additionally, integrators had no way to view or edit cover metadata after purchase. The new
CoverDataclass provides authenticated endpoints for both viewing private metadata and updating proof-of-loss entries.Breaking changes
GetQuoteAndBuyCoverInputsParams.ipfsCidOrContentremoved → usecoverMetadataQuoteconstructor no longer accepts anIpfsinstanceContentTypeenum values removed from exportsSummary by CodeRabbit
New Features
Tests