Spike/rydership markd#1
Conversation
toddjudd
left a comment
There was a problem hiding this comment.
Most of these are personal opinions. I'd also recommend setting up a prettier config. we have it all of our integrations and it keeps the repo from having random files with tabs vs spaces, or with unsupported line endings etc. I like having it as a check for every PR.
Everything looks good though, this is a pretty cool project.
| @@ -0,0 +1,45 @@ | |||
| export default { | |||
There was a problem hiding this comment.
I'd highly recommend vitest over jest especially for a typescript project. You'll fight with jest and ts-jest where vitest will work out of the box.
| }); | ||
| } | ||
|
|
||
| async initialize?(config: AdapterConfig): Promise<void> { |
There was a problem hiding this comment.
This may be a personal opinion, but I never type function return types unless absolutely needed and I know what I'm doing. Here's a Video with some more info, but the jist is return types can lie. I've not had an issue relying on inference yet.
| async createSalesOrder(input: CreateSalesOrderInput): Promise<OrderResult> { | ||
| try { | ||
| const payload = this.transformCreateSalesOrderInput(input); | ||
| const response = await this.client.post<RydershipOrder>('/orders', payload); |
There was a problem hiding this comment.
This typing is hopeful, line 171 confirms the type which is good. In out integrations we're using zod which let's use define a schema like this
// define a schema
export const RyderOrderSchema = z.object({
id: z.number(),
})
// convert it to a type when needed
export type RyderOrder = z.infer<typeof RyderOrderSchema>
// use it to parse unknown data into the correct shape
const data = client.get('/orders')
const order = RyderOrderSchema.parse(data) // will throw error
const safeOrder = RyderOrderSchema.safeparse(data) // => { success: true; data: {id:1}}
const safeOrder = RyderOrderSchema.safeparse(data) // => { success: false; errors: ZodError}
// Then we use them as params on the get call like this:
async getResource<T extends z.ZodTypeAny>(
resource: string,
resourceParser: T,
id?: number,
fields?: string[]
) {
const url = id ? `${resource}/${id}` : resource;
const method = 'get';
const axiosConfig = {
url,
params: {fields},
method,
} as AxiosRequestConfig;
try {
const {data} = await this._axiosInstance.request<
z.infer<typeof resourceParser>
>(axiosConfig);
return resourceParser.parse(data) as z.infer<typeof resourceParser>;
} catch (error) {
throw new ClientError(error, {
resource: url,
method,
client,
});
}
}
What is being changed/added/removed in this PR?
This is the initial PR for our fork of onX MCP. It lays down a lot of foundation:
-- getOrders
-- healthCheck
-- updateOrder
-- tests for the above, and then some
Checklist
Gotchas
References
AB#
Dependencies
Requires PR #
Testing Plan
Notes for Reviewer
Other information