feat: replace direct IPFS upload with POST /cover-metadata endpoint#518
feat: replace direct IPFS upload with POST /cover-metadata endpoint#518valentinludu wants to merge 8 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, and refactors the Quote service to POST metadata to a dedicated endpoint instead of accepting pre-validated IPFS content. ChangesCover Metadata Generation Refactoring
Sequence DiagramsequenceDiagram
participant Caller
participant Quote
participant ProductAPI
participant CoverMetadataAPI as POST /cover-metadata
Caller->>Quote: getQuoteAndBuyCoverInputs(params with coverMetadata)
Quote->>ProductAPI: fetch product config
ProductAPI-->>Quote: product with isProofOfLossRequired flag
alt proofOfLossRequired && !coverMetadata
Quote-->>Caller: error: missing cover metadata
else coverMetadata provided
Quote->>CoverMetadataAPI: POST CoverMetadataInput
CoverMetadataAPI-->>Quote: CoverMetadataResponse {cid}
Quote->>Quote: compute quote with ipfsData=cid
Quote-->>Caller: buyCoverInput with ipfsData=cid
else no metadata provided
Quote->>Quote: compute quote with ipfsData=''
Quote-->>Caller: buyCoverInput with ipfsData=''
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 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
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: |
270bc6d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d0b0876f.sdk-9yp.pages.dev |
| Branch Preview URL: | https://feat-cover-metadata-api.sdk-9yp.pages.dev |
Summary
Quote.getQuoteAndBuyCoverInputswith a call toPOST /cover-metadataon the backendipfsCidOrContentparam, replace withcoverMetadataaccepting{ proofOfLoss?, publicData? }isProofOfLossRequired(from product type API) to enforce metadata requirementWhat was removed
Ipfsdependency fromQuoteclass (still available onNexusSDK.ipfsfor claims/governance)coverValidators,coverQuotaShare,coverAumCoverAmountPercentage,coverWalletAddress,coverWalletAddresses,coverFreeText,coverDesignatedWallets,defiPassContentipfsContentTypefield fromProductTypeWhat was added
CoverMetadataInput,ProofOfLossEntry,ProofOfLossValue,CoverPublicDatatypesisProofOfLossRequiredonProductType,proofOfLossInputTypesonProductcreateCoverMetadata()method that 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.
Breaking changes
GetQuoteAndBuyCoverInputsParams.ipfsCidOrContentremoved → usecoverMetadataQuoteconstructor no longer accepts anIpfsinstanceContentTypeenum values removed from exports