Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions packages/v1-ready/asana/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {OAuth2Requester, get} = require('@friggframework/core');
const { OAuth2Requester, get } = require('@friggframework/core');
const FormData = require('form-data');

// core objects
Expand Down Expand Up @@ -63,24 +63,29 @@ class Api extends OAuth2Requester {
return super.getTokenFromCode(code);
}


async setTokens(params) {
this.access_token = get(params, 'access_token');
// this.refresh_token = get(params, 'refresh_token', null); // Removing because it sets to `null` but the request
// just doesn't return a refresh_token... long lived.
const newRefreshToken = get(params, 'refresh_token', null);

// Asana provides only one long lived refresh token, so we don't need to replace it.
if (newRefreshToken) {
this.refresh_token = newRefreshToken;
}

const accessExpiresIn = get(params, 'expires_in', null);
const refreshExpiresIn = get(
params,
'x_refresh_token_expires_in',
null
);
const refreshExpiresIn = get(params, 'x_refresh_token_expires_in', null);

this.accessTokenExpire = new Date(Date.now() + accessExpiresIn * 1000);
this.refreshTokenExpire = new Date(Date.now() + refreshExpiresIn * 1000);
if (accessExpiresIn) {
this.accessTokenExpire = new Date(Date.now() + accessExpiresIn * 1000);
}
if (refreshExpiresIn) {
this.refreshTokenExpire = new Date(Date.now() + refreshExpiresIn * 1000);
}

await this.notify(this.DLGT_TOKEN_UPDATE);
}


addJsonHeaders(options) {
const jsonHeaders = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -119,14 +124,14 @@ class Api extends OAuth2Requester {
// ************************** Projects **********************************

async createProject(body) {
const options = {
url: this.baseUrl + this.URLs.projects,
body: {
data: body,
},
};
const options = {
url: this.baseUrl + this.URLs.projects,
body: {
data: body,
},
};

return this._post(options);
return this._post(options);
}

async listProjects(params) {
Expand Down Expand Up @@ -224,13 +229,13 @@ class Api extends OAuth2Requester {

async listTasks(params) {
const workspaceId = get(params, 'workspaceId');
const assigneeId = get(params, 'assigneeId');
const assigneeId = get(params, 'assigneeId');

const options = {
url: this.baseUrl + this.URLs.tasks,
query: {
workspace: workspaceId,
assignee: assigneeId,
workspace: workspaceId,
assignee: assigneeId,
}
};

Expand Down Expand Up @@ -294,7 +299,7 @@ class Api extends OAuth2Requester {
};

let response = await super._post(requestOptions, false);

if (!response?.data) {
throw new Error('Failed to attach file to task: No response data received');
}
Expand All @@ -304,7 +309,7 @@ class Api extends OAuth2Requester {
resource_name: response.data.name,
resource_url: typeof resource === 'string' ? resource : null,
};

return response;
} catch (err) {
console.log(err);
Expand Down Expand Up @@ -403,4 +408,4 @@ class Api extends OAuth2Requester {

}

module.exports = {Api};
module.exports = { Api };
Loading