For Developers

Design Patterns

There are a few design patterns that are used throughout the SDK that help with reusability and scalability. The following sections will explain these patterns and how to use them.

The use() function

This function will either initialize an instance of the User or Graph API based on the token set you pass it. All the requests you make with that instance with now be scoped to that TokenSet.

// Graph API
edlink.use({
    access_token: '[...]',
    type: TokenSetType.Integration
});

// User API
edlink.use({
    access_token: '[...]',
    refresh_token: '[...]',
    expiration_date: Date.now();
    type: TokenSetType.Person
});

Using async generators

This SDK makes use of generators to simplify pagination. Here is an example of how to use one:

const schools: Map<string, School> = new Map();

for await (const school of edlink.use(token_set).schools.list({ limit: 20 })) {
    schools.set(school.id, school);
}

console.log(schools.size); // 20

Error handling for generators is a little different. Click the link below to read more about it.

Paging Arguments

Some functions paginate requests and accept a configuration object allowing you to customize this behavior. For example:

edlink.use(token_set).schools.list({
    limit: 50
});
ParameterTypeDescription
limitnumberThe max number of items to recieve.

Filtering

Some functions accept a filter object allowing you to filter the results the API returns. For example:

for await (const person of edlink.use(token_set).people.list({
    filter: {
        first_name: [{ operator: 'starts with', value: 'Lil' }]
    }
})) {
    console.log(person.first_name); // Lilly, Lillian, etc.
}