nylas-nodejs: Types seem to be wrong

Describe the bug

I’m fetching calendars. These are the keys for the data I’m seeing:

image

The types are nonetheless defined as:

export declare type CalendarProperties = {
    name: string;
    description: string;
    location: string;
    timezone: string;
    readOnly?: boolean;
    isPrimary?: boolean;
    jobStatusId?: string;
    metadata?: object;
    hexColor?: string;
};

export default class Calendar extends RestfulModel implements CalendarProperties {
    name: string;
    description: string;
    location: string;
    timezone: string;
    readOnly?: boolean;
    isPrimary?: boolean;
    jobStatusId?: string;
    metadata?: object;
    hexColor?: string;
    static collectionName: string;
    static attributes: Record<string, Attribute>;
    constructor(connection: NylasConnection, props?: CalendarProperties);
    save(params?: {} | SaveCallback, callback?: SaveCallback): Promise<this>;
    saveRequestBody(): Record<string, unknown>;
    getJobStatus(callback?: GetCallback): Promise<JobStatus>;
}



found in /node_modules/nylas/lib/models/calendar.d.ts.

Notably, properties that should be camelCase per the types are instead snake_case per the api. This makes the types unusable and is overall a usability hit to the SDK.

To Reproduce

  1. Look at code.
  2. Look at data actually coming from the api. \

Expected behavior Types match.

SDK Version:

"nylas": "^6.9.0",

Additional context N/A

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15

Most upvoted comments

No problem - Thanks for taking the time to respond 😄

We’re using:

"nylas": "^7.0.0-beta.3",

In our application at the moment, and it’s been a much smoother dev exp.

Thanks again for all your help and time on this

@birksy89 no problem at all! I did construct it and that’s where I derived my answer from. This was the code I used:

const Nylas = require('./lib/nylas.js');

Nylas.config({
  clientId: 'MY_CLIENT_ID',
  clientSecret: 'MY_SECRET',
});

const nylas = Nylas.with('MY_ACCESS_TOKEN');

const threads = nylas.threads
  .list({ limit: 15, expanded: true })
  .then(threads => {
    threads.forEach(thread => {
      console.log(thread.toJSON());
      console.log(thread);
    });
  });

For each member of the loop, the two console.log statements gave me two different outputs:

for the .toJSON() call I got (similar to yours):

  last_message_timestamp: 1694631162,
  last_message_received_timestamp: 1694631162,
  last_message_sent_timestamp: null,
  first_message_timestamp: 1694631162,

and in the plain console.log(threads) I got:

  lastMessageTimestamp: 2023-09-13T18:52:42.000Z,
  lastMessageReceivedTimestamp: 2023-09-13T18:52:42.000Z,
  firstMessageTimestamp: 2023-09-13T18:52:42.000Z,

Note that in the second example how it’s camelCase and the variable is a Date as opposed to an epoch timestamp.

Now mind you, you don’t need to call toJSON() directly yourself to trigger it. toJSON() is a built-in javascript function. Some libraries will call toJSON as part of a serialization call or something, hence triggering the conversion to snake_case.

Can you provide me more context on how your using your “threads” variable after you fetch the data from our API? If you can share the function code snippet that would give me more clues as to what is going on 😃. Thanks!