chore(backend): Add M2M token list method#7939
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: b55941c The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/backend/src/api/endpoints/M2MTokenApi.ts (1)
83-89: Add JSDoc and an explicit return type to the new publiclistAPI.This keeps the public surface consistent and clearer for SDK consumers.
Proposed update
+ /** + * Retrieves machine-to-machine tokens for a specific machine. + */ - async list(queryParams: GetM2MTokenListParams) { + async list(queryParams: GetM2MTokenListParams): Promise<PaginatedResourceResponse<M2MToken[]>> { return this.request<PaginatedResourceResponse<M2MToken[]>>({ method: 'GET', path: basePath, queryParams, }); }Based on learnings: "enforce explicit return type annotations for exported functions and public APIs," and as per coding guidelines: "All public APIs must be documented with JSDoc."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/backend/src/api/endpoints/M2MTokenApi.ts` around lines 83 - 89, The exported async method list lacks an explicit return type and JSDoc; update the public API by adding a JSDoc block describing the method, its parameter (queryParams: GetM2MTokenListParams) and its return value, and annotate the function signature with an explicit return type Promise<PaginatedResourceResponse<M2MToken[]>> (the function named list that calls this.request should be updated accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/backend/src/api/endpoints/M2MTokenApi.ts`:
- Around line 83-89: The list method in M2MTokenApi does not validate the
required machine identifier (subject) from GetM2MTokenListParams before making
the request; add input validation in the list(queryParams:
GetM2MTokenListParams) function to check that queryParams.subject exists, is a
non-empty string (trimmed) and meets any expected format, throw a clear Error
(or return a rejected Promise) for invalid values, and sanitize/trim the subject
before passing queryParams to this.request so only validated data is sent.
In `@packages/backend/src/api/resources/Deserializer.ts`:
- Around line 80-85: The M2M branch can return totalCount as undefined and uses
any[]; tighten the isM2MTokenResponse type guard so it asserts payload has a
numeric total_count and an array m2m_tokens of unknown (not any), update the
guard implementation (the one defined around lines 117-123) to check typeof
payload.total_count === 'number' and Array.isArray(payload.m2m_tokens'), then
change the mapping in the branch that uses jsonToObject to treat items as
unknown (e.g. map(item => jsonToObject(item) as U)) and set totalCount =
payload.total_count as number so the returned PaginatedResourceResponse<U>
always has a number totalCount.
---
Nitpick comments:
In `@packages/backend/src/api/endpoints/M2MTokenApi.ts`:
- Around line 83-89: The exported async method list lacks an explicit return
type and JSDoc; update the public API by adding a JSDoc block describing the
method, its parameter (queryParams: GetM2MTokenListParams) and its return value,
and annotate the function signature with an explicit return type
Promise<PaginatedResourceResponse<M2MToken[]>> (the function named list that
calls this.request should be updated accordingly).
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
.changeset/shiny-apples-travel.mdpackages/backend/src/api/__tests__/M2MTokenApi.test.tspackages/backend/src/api/endpoints/M2MTokenApi.tspackages/backend/src/api/resources/Deserializer.ts
Description
This PR adds a new method in the M2M token API to list all M2M tokens by a machine (BAPI proxy doc).
Also fixes incorrect mock IDs in unit tests
Resolves USER-4822
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Release Notes
New Features