This Edlink JavaScript & TypeScript SDK is a NodeJS wrapper for the Edlink API.
You can find more thorough documentation on the Edlink SDK Docs.
Install the @edlink/typescript package using npm or yarn.
yarn add @edlink/typescript
// Initialize with your Edlink application// Your credentials can be found on the Edlink Dashboardimport{Edlink}from'@edlink/typescript';constedlink=newEdlink({version: 2,client_id: '3a95a779-0ed1-499b-a352-9ea30d0bd5ea',client_secret: '[...]'});Edlink.up().then(console.log);// Ok// TokenSets are required to access protected resources// Integration tokens do not expire and therefore dont have a `refresh_token`// However be sure to store the the `refresh_token` for person token sets// You are required to provide both when making requests on behalf of a person
export typeTokenSet{access_token: string;
refresh_token?: string;
expires_in?: number;
type: TokenSetType;}exportenumTokenSetType={Integration='integration',Person='person'}// Graph requests are even easier, just build a TokenSet from the values// in the Edlink Dashboardconstintegration_token_set={access_token: '[...]'};constdistrict=awaitedlink.use(integration_token_set).districts.fetch('3a95a779-0ed1-499b-a352-9ea30d0bd5ea');forawait(constdistrictofedlink.use(integration_token_set).districts.list()){console.log(district);}// Authenticate a user// First build your login url to provide to the user.// This URL doesnt change and can be hardcoded if desired/** * https://ed.link/sso/login * ?client_id=[...] * &redirect_uri=[...] * &state=[...] * &response_type=code */// Optionally you may provide a state parameter for Endlink to// passback to you upon authentication of the useredlink.loginUrl({redirect_uri: 'https://oauthdebugger.com/debug'});// When the user returns to your site you will be provided with a code// e.g. https://oauthdebugger.com/debug?code=[...]// Provide this code with the matching `redirect_uri` to recieve a token set// Store this entire object securely// You will require more than just the access_tokenconstperson_token_set=awaitedlink.auth.grant({code: '[...]'.redirect_uri: 'https://oauthdebugger.com/debug'});// You can now make requests on behalf of this userconstprofile=awaitedlink.use(person_token_set).my.profile();