novuhq / novu

Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations.
https://novu.co
Other
34.47k stars 3.51k forks source link

🐛 Bug Report: Novu SDK layouts response DTO is not correct #3446

Open underfisk opened 1 year ago

underfisk commented 1 year ago

📜 Description

Noticed while using the Novu Nodejs SDK that when attempting to fetch a list of layouts, the response DTO does not match the API response

👟 Reproduction steps

  1. Install Novu nodejs SDK
  2. Retrieve a list of layouts novu.layouts.list({ your params})
  3. Inspect the API response

👍 Expected behavior

The interface should reflect the actual API response

👎 Actual Behavior with Screenshots

const axiosResponse = await novu.layouts.list({ page: 0, pageSize: 100 })
const list = axiosResponse.data

You'll observe that list will have the following content:

{
    page: 0,
    totalCount: 2,
    pageSize: 100,
    data: [ [Object], [Object] ]
}

When inspecting with my IDE, this is what I see: Screenshot 2023-05-17 at 6 01 27 PM

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

Yes I am willing to submit a PR!

underfisk commented 1 year ago

Bumping

p-fernandez commented 1 year ago

@underfisk sorry but could you clarify what you are receiving that doesn't match the interface ILayoutPaginationResponse when using the Node SDK functionality novu.layouts.list? https://github.com/novuhq/novu/blob/f596c26ba247889edd1d1b687c7a944792f7b024/packages/node/src/lib/layouts/layout.interface.ts#L44

marvinjude commented 1 year ago

@p-fernandez @scopsy, Seem to me like @underfisk is explicitly typing fff(possibly inferred by the editor for whatever reason) as ILayoutPaginationResponse in the example above and referencing fff.data where fff is actually an AxiosResponse with data type -> ILayoutPaginationResponse

Whereas, Correct use on the user's end should look like so:

import { AxiosResponse } from "axios";

//@ts-ignore
const fff: AxiosResponse<ILayoutPaginationResponse> = await novu.layouts.list({
  page: 0,
  pageSize: 100,
});

fff.data.data // now you can see the right hint as you type

@p-fernandez Is there any documentation on how to use types like ILayoutPaginationResponse?https://github.com/novuhq/novu/blob/f596c26ba247889edd1d1b687c7a944792f7b024/packages/node/src/lib/layouts/layout.interface.ts#L44 I can see it's just a public type as it isn't used internally. Or was this written for future internal use?

This seems to be all tied to the fact that most methods don't have explicit return types.

Happy to make a PR

Also see https://github.com/novuhq/novu/issues/3928#issuecomment-1671909148

scopsy commented 1 year ago

@jainpawan21 I think that you have made some adjustments based on that recently, any thoughts on this one?

jainpawan21 commented 1 year ago

@jainpawan21 I think that you have made some adjustments based on that recently, any thoughts on this one?

This should not happen i will check this

Assigning this to myself

peoray commented 8 months ago

What's the status on this @jainpawan21 :)