-
Notifications
You must be signed in to change notification settings - Fork 369
chore(backend): Add machines Backend API resource and methods #6335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/backend": minor | ||
--- | ||
|
||
Add machines Backend API resource and methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { joinPaths } from '../../util/path'; | ||
import type { PaginatedResourceResponse } from '../resources/Deserializer'; | ||
import type { Machine } from '../resources/Machine'; | ||
import { AbstractAPI } from './AbstractApi'; | ||
|
||
const basePath = '/machines'; | ||
|
||
type CreateMachineParams = { | ||
name: string; | ||
}; | ||
|
||
type UpdateMachineParams = { | ||
machineId: string; | ||
name: string; | ||
}; | ||
|
||
type GetMachineListParams = { | ||
limit?: number; | ||
offset?: number; | ||
query?: string; | ||
}; | ||
|
||
export class MachineApi extends AbstractAPI { | ||
async get(machineId: string) { | ||
this.requireId(machineId); | ||
return this.request<Machine>({ | ||
method: 'GET', | ||
path: joinPaths(basePath, machineId), | ||
}); | ||
} | ||
|
||
async list(queryParams: GetMachineListParams = {}) { | ||
return this.request<PaginatedResourceResponse<Machine[]>>({ | ||
method: 'GET', | ||
path: basePath, | ||
queryParams, | ||
}); | ||
} | ||
|
||
async create(bodyParams: CreateMachineParams) { | ||
return this.request<Machine>({ | ||
method: 'POST', | ||
path: basePath, | ||
bodyParams, | ||
}); | ||
} | ||
|
||
async update(params: UpdateMachineParams) { | ||
const { machineId, ...bodyParams } = params; | ||
this.requireId(machineId); | ||
return this.request<Machine>({ | ||
method: 'PATCH', | ||
path: joinPaths(basePath, machineId), | ||
bodyParams, | ||
}); | ||
} | ||
|
||
async delete(machineId: string) { | ||
this.requireId(machineId); | ||
return this.request<Machine>({ | ||
method: 'DELETE', | ||
path: joinPaths(basePath, machineId), | ||
}); | ||
} | ||
} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { MachineJSON } from './JSON'; | ||
|
||
export class Machine { | ||
constructor( | ||
readonly id: string, | ||
readonly name: string, | ||
readonly instanceId: string, | ||
readonly createdAt: number, | ||
readonly updatedAt: number, | ||
) {} | ||
|
||
static fromJSON(data: MachineJSON): Machine { | ||
return new Machine(data.id, data.name, data.instance_id, data.created_at, data.updated_at); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add test coverage for the new Machine API.
No tests were added for the new MachineApi class. Please add comprehensive test coverage for all CRUD operations to ensure the API works correctly and to prevent regressions.
Consider adding tests for:
Would you like me to help generate test cases for the MachineApi class?
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is part of an upcoming project (machine-to-machine tokens). The tests will be added later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wobsoriano Thanks for the clarification! That makes sense - I understand this is part of the upcoming machine-to-machine tokens project. I'll note that test coverage can be addressed in a later phase of the project rollout.
🧠 Learnings used