[66699] Node SDK v6.0.0 - major refactor release#302
Merged
mrashed-dev merged 43 commits intoJan 12, 2022
Conversation
As the SDK coverage grows, we need to decouple the standard functionality of a model from the specific functionality/structure of a "classic" Nylas API model. A "classic" Nylas API model is a model used for endpoints like Event, Calendar, Message, etc. where we expect the object to have an id, account_id, and object field. There are a lot of "dumb" models like Contact.Emails that would benefit from being cast as a basic model versus the current RestfulModel, as well as having the ability in the future for creating different types of models.
This PR is a big one, it's aimed at two things -- improving how we deserialize objects while improving how users can create objects using the SDK.
This PR is to address the Node SDK typing issues our customers have been experiencing.
This PR represents a few bug fixes I found during some testing I did myself, as well as porting in all the features from the latest v5.9.0 release, ensuring that all the latest features are in and ready for testing.
This PR addresses some issues found in the v6.0.0 canary release by the QA team. The main fix has been related to the Contact class making it a default export and enabling save functionality for it.
All it does is call /files/{id}
This was
linked to
issues
Jan 11, 2022
Contributor
Author
|
@philrenaud @AaronDDM -- The PR contains a lot of merge conflict resolutions and already-reviewed code from previously-merged PRs that were squashed into this one. The commits that are un-reviewed are all the commits starting from |
philrenaud
approved these changes
Jan 11, 2022
AaronDDM
approved these changes
Jan 11, 2022
A customer noticed that we were returning only the access token in the exchange token response. This doesn't match the API's response so I updated the response body to include the full response body from the call we make to exchange the token. This will return identifying information about the account as well.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR represents the major update v6.0.0 of the Node SDK. The main theme of this major release is refactoring and improving the SDK to make it more Typescript-like as well as improving the usability of the SDK by providing better and stricter type hinting as well as expected parameters. This major release can be broken down into three main sections: refactoring
RestfulModel, improving deserialization and object creation, and improving the typing of the SDK in general.Refactoring
RestfulModeland IntroducingModelsuperclassAs the SDK coverage grows, we need to define what a "basic" model is instead of solely using
RestfulModelfor every model represented in the SDK. To do this we needed to decouple the standard functionality of a model from the specific functionality/structure of a "classic" Nylas API model. A "classic" Nylas API model is a model used for endpoints likeEvent,Calendar,Message, etc. where we expect the object to have anid,account_id, andobjectfield and we are expected to perform RESTful operations directly with this model. Now with the Nylas API, there are a lot of models that are representations of API objects, but don't have endpoint(s) nor are we expected to make RESTful calls directly using them. A perfect example of this are all theContactsubclasses. This allows the user to instantiate these objects without the need to pass in aNylasConnectiontype, which cleans up the code and produces less overhead.The same logic was also applied to refactoring
RestfulModelCollectionand creating aModelCollectionsuperclass.Improving Deserialization and Object Creation
Following up on the creation of the
Modelsuperclass, each model has an accompanying interface that represents an object of parameters that the model will use, as well as the proper strictness dictated by what values will always be present in any scenario (GET, POST, PUT). In the constructor of each model, we now specify that we can take in an optionalpropsproperty of the Model interface's type. This helps to hint the user as to what properties they must pass in during the initialization of the object. This also helps us with the strictness of the typing in each model as now we properly outline what properties are needed at a bare minimum.This
propsmethod property is left as optional because it allows some flexibility to the SDK user to just instantiate a type of object then either:If taking this route, we initialize all the required types to a default value in order not to upset Typescript's strictness requirements.
With this, we also deprecate the
RestfulModelCollection.build()method as it provides a way for the user to bypass the constructor typing requirements and pass in whatever object they want. It also does not provide any type hinting to the user when trying to initialize the object. Here's an example of the before and after:Improving SDK Typing
The biggest change we've made here is that all of the SDK methods that are meant to be used by the end users all have a non-any return type. In addition to this, the PR improves on the previous work of the refactor to ensure that we are utilizing the use of models, interfaces, and proper deserialization. With this, our support for Calendar availability has improved with the introduction of classes and types for API objects like free-busy and availability. Our support for Native Authentication and Virtual Calendars have also seen improvements as we have models to represent these objects and introduced enums to provide the user an easier time with providing things like providers and scopes without needing to refer to the API docs to see what scopes/providers are supported and to reduce user typing errors.
Breaking Changes
RestfulModelandRestfulModelCollection, introducedModelandModelCollectionsuperclass for models that do not directly interact with the Nylas APIEvent.whenis now ofWhentypeNeuralMessageOptionsis now aModelclass instead of an interface typeCalendarRestfulModelCollection.freeBusy()now returns a (new)FreeBusytype instead of a JSONCalendarRestfulModelCollection.availability()now returns a (new)CalendarAvailabilitytype instead of a JSONCalendarRestfulModelCollection.consecutiveAvailability()now returns a (new)CalendarConsecutiveAvailabilitytype instead of a JSONConnect.authorize()now takes in a parameter ofVirtualCalendarProperties | NativeAuthenticationPropertiestype (new) instead of an object and returnsAuthorizationCodetype (new) instead of a JSONConnect.token()now returns anAccounttype instead of a JSONContact,EventConferencing, andFolderare now default exportsNylas.application()deprecatesapplication_nameandredirect_urisin favour of camelCaseRestfulModelCollection.build()as it does not allow for proper property and type hinting in favor of instantiating vianew Model()Connect.newAccount()as it had no functionalityFile.metadata()as it doesn't appear any different than making aNylasConnection.files().find()callMigration Guide
//todo
License
I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.