feat(API): Add patch method for credentials public API#23431
feat(API): Add patch method for credentials public API#23431guillaumejacquart merged 4 commits intomasterfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
E2E Tests: n8n tests passed after 12m 56.6s Run Details
Groups
This message was posted automatically by
currents.dev | Integration Settings
|
There was a problem hiding this comment.
5 issues found across 11 files
Prompt for AI agents (all 5 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/cli/src/public-api/v1/handlers/credentials/credentials.service.ts">
<violation number="1" location="packages/cli/src/public-api/v1/handlers/credentials/credentials.service.ts:150">
P2: Rule violated: **Prefer Typeguards over Type casting**
Type narrowing with `as CredentialsEntity` violates the rule to prefer type guards over type casting. The `getCredentials` function returns `ICredentialsDb | null`, but the repository actually returns `CredentialsEntity`. Consider updating `getCredentials` return type to `CredentialsEntity | null` to avoid the cast, or create a type guard if runtime validation is needed.</violation>
<violation number="2" location="packages/cli/src/public-api/v1/handlers/credentials/credentials.service.ts:168">
P1: OAuth token data is not preserved when `isPartialData` is false/undefined. Unlike the partial update branch which preserves `oauthTokenData`, the full replace branch will cause loss of OAuth tokens. This should preserve existing `oauthTokenData` like the partial mode does, consistent with the main `CredentialsService.prepareUpdateData` pattern.</violation>
</file>
<file name="packages/cli/src/public-api/v1/handlers/credentials/credentials.handler.ts">
<violation number="1" location="packages/cli/src/public-api/v1/handlers/credentials/credentials.handler.ts:75">
P2: Rule violated: **Prefer Typeguards over Type casting**
Avoid using `as CredentialsEntity` for type narrowing. The `updateCredential` function returns `ICredentialsDb | null`, while `sanitizeCredentials` expects `CredentialsEntity`. Instead of casting, consider updating `updateCredential`'s return type to `CredentialsEntity | null` to match its actual behavior, or use a type guard if runtime validation is needed.</violation>
<violation number="2" location="packages/cli/src/public-api/v1/handlers/credentials/credentials.handler.ts:80">
P2: Error handling doesn't preserve `httpStatusCode` from errors that extend `ResponseError`. If underlying service methods throw errors with specific HTTP status codes, they'll incorrectly return 500. Consider checking for `httpStatusCode` property on errors to match the pattern used in `createCredential`.</violation>
</file>
<file name="packages/cli/src/credentials/credentials.service.ts">
<violation number="1" location="packages/cli/src/credentials/credentials.service.ts:466">
P2: Rule violated: **Prefer Typeguards over Type casting**
Use type annotation instead of `as` for type specification. According to the coding guidelines, prefer `const x: Type = value` over `const x = value as Type`.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
1c57fbd to
5ad93d7
Compare
5ad93d7 to
d50c039
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ireneea
left a comment
There was a problem hiding this comment.
Looks good to me 👍 (just a nitpicking comment)
| writeOnly: true | ||
| example: { accessToken: 'new_token_value' } | ||
| description: The credential data. Required when changing credential type. | ||
| isGlobal: |
There was a problem hiding this comment.
[NIT] Is it worth mentioning that this is only relevant if they have the sharing license & the user has global scope.
Even if this is a patch endpoint I wonder if some users would just treat it as a post endpoint and pass the entire payload?
|
Got released with |
Summary
Adds PATCH /credentials/:id to the public API for updating existing credentials.
Implementation:
isPartialData field behavior
Overview
Added optional isPartialData boolean field to the PATCH endpoint request body to control how credential data is updated.
Behavior
isPartialData: false (default)
isPartialData: true
Example
Replace mode (default):
Merge mode:
Related Linear tickets, Github issues, and Community forum posts
Review / Merge checklist
release/backport(if the PR is an urgent fix that needs to be backported)