Node.js SDK upgrade (v0.x to v1.0)
Learn how to upgrade to v1.0 of the Knock Node.js SDK.
Basic changes
#Import style
#Import the SDK using the standard ES6 import syntax:
Client initialization
#Initialize your client with an options object:
What's new in v1.0
#The v1.0 SDK brings complete TypeScript support, improved error handling, and new resources to the Node.js ecosystem.
Fully typed API
#Complete TypeScript definitions for all requests and responses:
Enhanced error handling
#Typed errors with better context:
Auto-pagination
#Iterate through paginated resources automatically:
Request/response access
#Get more control over raw responses:
Configurable logging
#Better debugging capabilities:
Configurable timeouts and retries
#Fine-tune request behavior:
New resources
#Additional resources like Audiences, Channels, and Integrations:
Breaking changes
#Client initialization
#Client initialization accepts an options object instead of just the API key.
Parameter changes
#Some parameter names have changed to match the API (e.g., cancellationKey is now cancellation_key).
Error handling
#Error handling has been completely revamped with typed errors.
Token signing
#The signUserToken method should now be imported from @knocklabs/node/lib/tokenSigner if referenced directly:
Method changes
#Several method names have changed:
notify()is nowworkflows.trigger()users.getSchedules()is nowusers.listSchedules()workflows.createSchedules()is nowschedules.create()workflows.listSchedules()is nowschedules.list()workflows.updateSchedules()is nowschedules.update()workflows.deleteSchedules()is nowschedules.delete()
Bulk operations
#Bulk operations are now organized in their own namespaces: users.bulk.*, objects.bulk.*, schedules.bulk.*, etc.
Parameter changes
#A PreferenceSet ID parameter is now required for users.getPreferences().
All parameters are now in camelCase in the method signature but use snake_case in the request body. Query parameters are now passed as a separate object in most list methods:
Response handling
#The new SDK returns the data directly in most cases rather than wrapped in a data property. Pagination is handled differently with cursor-based pagination.
Common operations
#Need help?
#If you run into any issues during your migration, reach out to our support team or open an issue on GitHub.