@beauraines/rtm-api 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +31 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/publish.yml +54 -0
- package/.github/workflows/test.yaml +25 -0
- package/CHANGELOG.md +19 -0
- package/README.md +17 -4
- package/docs/RTMClient.html +2 -2
- package/docs/RTMError.html +2 -2
- package/docs/RTMList.html +2 -2
- package/docs/RTMResponse.html +2 -2
- package/docs/RTMSuccess.html +2 -2
- package/docs/RTMTask.html +227 -5
- package/docs/RTMUser.html +271 -21
- package/docs/client_auth.js.html +2 -2
- package/docs/client_index.js.html +2 -2
- package/docs/client_user.js.html +5 -5
- package/docs/global.html +298 -3
- package/docs/index.html +12 -7
- package/docs/list_index.js.html +2 -2
- package/docs/response_error.js.html +8 -8
- package/docs/response_response.js.html +5 -5
- package/docs/response_success.js.html +3 -3
- package/docs/task_helper.js.html +15 -18
- package/docs/task_index.js.html +34 -16
- package/docs/user_index.js.html +5 -5
- package/docs/user_lists.js.html +2 -2
- package/docs/user_tasks.js.html +73 -9
- package/docs/utils_fetch.js.html +128 -0
- package/package.json +17 -4
- package/src/client/user.js +3 -3
- package/src/list/helper.js +1 -1
- package/src/response/error.js +6 -6
- package/src/response/response.js +3 -3
- package/src/response/success.js +1 -1
- package/src/task/helper.js +13 -13
- package/src/task/index.js +3 -3
- package/src/user/index.js +4 -3
- package/src/user/tasks.js +56 -26
- package/src/utils/auth.js +9 -9
- package/src/utils/fetch.js +23 -21
- package/src/utils/get.js +8 -5
- package/src/utils/sign.js +2 -2
package/src/user/index.js
CHANGED
|
@@ -133,7 +133,7 @@ class RTMUser {
|
|
|
133
133
|
*/
|
|
134
134
|
get client() {
|
|
135
135
|
if ( !this._client ) {
|
|
136
|
-
throw
|
|
136
|
+
throw 'User does not have Client specified';
|
|
137
137
|
}
|
|
138
138
|
return this._client;
|
|
139
139
|
}
|
|
@@ -153,7 +153,7 @@ class RTMUser {
|
|
|
153
153
|
*/
|
|
154
154
|
get timeline() {
|
|
155
155
|
if ( !this._timeline ) {
|
|
156
|
-
throw
|
|
156
|
+
throw 'User does not have a valid timeline set';
|
|
157
157
|
}
|
|
158
158
|
return this._timeline;
|
|
159
159
|
}
|
|
@@ -274,9 +274,10 @@ class RTMUser {
|
|
|
274
274
|
* - {@link RTMUser~tasks/increasePriority|increasePriority}
|
|
275
275
|
* - {@link RTMUser~tasks/move|move}
|
|
276
276
|
* - {@link RTMUser~tasks/setDueDate|setDueDate}
|
|
277
|
+
* - {@link RTMUser~tasks/setStartDate|setStartDate}
|
|
277
278
|
* - {@link RTMUser~tasks/postpone|postpone}
|
|
278
279
|
* - {@link RTMUser~tasks/setName|setName}
|
|
279
|
-
* @returns {{get: function, add:function, remove: function, complete: function, uncomplete: function, addNotes: function, addTags: function, removeTags: function, priority: function, decreasePriority: function, increasePriority: function, move: function, setDueDate: function, postpone: function, setName: function}}
|
|
280
|
+
* @returns {{get: function, add:function, remove: function, complete: function, uncomplete: function, addNotes: function, addTags: function, removeTags: function, priority: function, decreasePriority: function, increasePriority: function, move: function, setDueDate: function, setStartDate: function, postpone: function, setName: function}}
|
|
280
281
|
*/
|
|
281
282
|
get tasks() {
|
|
282
283
|
return require('./tasks.js')(this);
|
package/src/user/tasks.js
CHANGED
|
@@ -5,7 +5,7 @@ const _lists = require('../list/helper.js');
|
|
|
5
5
|
const taskIds = require('../utils/taskIds.js');
|
|
6
6
|
const errors = require('../response/error.js');
|
|
7
7
|
const { getListId, getTaskId, getTaskSeriesId } = require('../utils/taskIds');
|
|
8
|
-
const { callAPI, buildUrl } = require('../utils/fetch')
|
|
8
|
+
const { callAPI, buildUrl } = require('../utils/fetch');
|
|
9
9
|
const RTMTask = require('../task/index.js');
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -28,7 +28,7 @@ module.exports = function(user) {
|
|
|
28
28
|
rtn.get = function(filter, callback) {
|
|
29
29
|
if ( callback === undefined && typeof filter === 'function' ) {
|
|
30
30
|
callback = filter;
|
|
31
|
-
filter =
|
|
31
|
+
filter = '';
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Callback counters
|
|
@@ -77,8 +77,8 @@ module.exports = function(user) {
|
|
|
77
77
|
if ( list === undefined ) {
|
|
78
78
|
list = {
|
|
79
79
|
id: TASKS[i].list_id,
|
|
80
|
-
name:
|
|
81
|
-
}
|
|
80
|
+
name: 'List #' + TASKS[i].list_id
|
|
81
|
+
};
|
|
82
82
|
}
|
|
83
83
|
TASKS[i]._list = list;
|
|
84
84
|
}
|
|
@@ -92,10 +92,10 @@ module.exports = function(user) {
|
|
|
92
92
|
* @return {JSON}
|
|
93
93
|
*/
|
|
94
94
|
rtn.rtmFetch = async function(filter) {
|
|
95
|
-
let url = buildUrl(user,filter)
|
|
95
|
+
let url = buildUrl(user,filter);
|
|
96
96
|
let response = await callAPI(url);
|
|
97
|
-
return await response.rsp.tasks?.list
|
|
98
|
-
}
|
|
97
|
+
return await response.rsp.tasks?.list;
|
|
98
|
+
};
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Get the RTMTask specified by its index. Unlike getTask(), this will only create an RTMTask
|
|
@@ -107,36 +107,36 @@ module.exports = function(user) {
|
|
|
107
107
|
*/
|
|
108
108
|
rtn.rtmIndexFetchTask = async function(index,filter) {
|
|
109
109
|
|
|
110
|
-
let url = buildUrl(user,filter)
|
|
110
|
+
let url = buildUrl(user,filter);
|
|
111
111
|
let response = await callAPI(url,user);
|
|
112
|
-
const lists = response.rsp.tasks?.list
|
|
112
|
+
const lists = response.rsp.tasks?.list;
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
// index to ids
|
|
116
|
-
let listId = getListId(user.id,index)
|
|
117
|
-
let taskSeriesId = getTaskSeriesId(user.id,index)
|
|
118
|
-
let taskId = getTaskId(user.id,index)
|
|
116
|
+
let listId = getListId(user.id,index);
|
|
117
|
+
let taskSeriesId = getTaskSeriesId(user.id,index);
|
|
118
|
+
let taskId = getTaskId(user.id,index);
|
|
119
119
|
|
|
120
120
|
if (listId == undefined || taskSeriesId == undefined || taskId == undefined) {
|
|
121
|
-
return {err: {code: -3}} // Not sure why this is the code
|
|
121
|
+
return {err: {code: -3}}; // Not sure why this is the code
|
|
122
122
|
}
|
|
123
123
|
// filter the response for the matching index
|
|
124
|
-
let taskList = lists.filter(x => x.id == listId)[0].taskseries
|
|
125
|
-
let taskSeries = taskList ? taskList.filter(x => x.id == taskSeriesId)[0] : null
|
|
124
|
+
let taskList = lists.filter(x => x.id == listId)[0].taskseries;
|
|
125
|
+
let taskSeries = taskList ? taskList.filter(x => x.id == taskSeriesId)[0] : null;
|
|
126
126
|
taskSeries
|
|
127
127
|
? taskSeries.task = taskSeries.task.filter(x => x.id == taskId)[0]
|
|
128
|
-
: null
|
|
128
|
+
: null;
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
let err
|
|
132
|
-
let task
|
|
131
|
+
let err;
|
|
132
|
+
let task;
|
|
133
133
|
if (!taskSeries ) {
|
|
134
|
-
err = {code: -3} // Not sure why this is the code
|
|
134
|
+
err = {code: -3}; // Not sure why this is the code
|
|
135
135
|
} else {
|
|
136
|
-
task = new RTMTask(user.id,listId,taskSeries,taskSeries.task)
|
|
136
|
+
task = new RTMTask(user.id,listId,taskSeries,taskSeries.task);
|
|
137
137
|
}
|
|
138
|
-
return {err,task}
|
|
139
|
-
}
|
|
138
|
+
return {err,task};
|
|
139
|
+
};
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
142
|
* Get the RTMTask specified by its index. While this will return only the matching RTMTask,
|
|
@@ -153,7 +153,7 @@ module.exports = function(user) {
|
|
|
153
153
|
rtn.getTask = function(index, filter, callback) {
|
|
154
154
|
if ( callback === undefined && typeof filter === 'function' ) {
|
|
155
155
|
callback = filter;
|
|
156
|
-
filter =
|
|
156
|
+
filter = '';
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Get Task Info
|
|
@@ -347,7 +347,7 @@ module.exports = function(user) {
|
|
|
347
347
|
* @function RTMUser~tasks/addNotes
|
|
348
348
|
*/
|
|
349
349
|
rtn.addNotes = function(index, title, notes, callback) {
|
|
350
|
-
var title = (typeof title !== 'undefined') ? title :
|
|
350
|
+
var title = (typeof title !== 'undefined') ? title : '';
|
|
351
351
|
|
|
352
352
|
// Get the Task
|
|
353
353
|
_getTaskInfo(index, function(err, listId, taskSeriesId, taskId) {
|
|
@@ -360,7 +360,7 @@ module.exports = function(user) {
|
|
|
360
360
|
listId,
|
|
361
361
|
taskSeriesId,
|
|
362
362
|
taskId,
|
|
363
|
-
|
|
363
|
+
title,
|
|
364
364
|
notes,
|
|
365
365
|
user,
|
|
366
366
|
callback
|
|
@@ -588,7 +588,7 @@ module.exports = function(user) {
|
|
|
588
588
|
return callback(err);
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
-
//
|
|
591
|
+
// Sets the Due Date of the Task
|
|
592
592
|
return _tasks.setDueDate(
|
|
593
593
|
listId,
|
|
594
594
|
taskSeriesId,
|
|
@@ -602,6 +602,36 @@ module.exports = function(user) {
|
|
|
602
602
|
|
|
603
603
|
};
|
|
604
604
|
|
|
605
|
+
/**
|
|
606
|
+
* Set the Start Date of the specified Task
|
|
607
|
+
* @param {int} index Task Index
|
|
608
|
+
* @param {string} start The Start Date of the Task (RTM parsed date)
|
|
609
|
+
* @param {function} callback Callback function(err)
|
|
610
|
+
* @param {RTMError} callback.err RTM API Error Response, if encountered
|
|
611
|
+
* @function RTMUser~tasks/setStartDate
|
|
612
|
+
*/
|
|
613
|
+
rtn.setStartDate = function(index, start, callback) {
|
|
614
|
+
|
|
615
|
+
// Get the Task
|
|
616
|
+
_getTaskInfo(index, function(err, listId, taskSeriesId, taskId) {
|
|
617
|
+
if ( err ) {
|
|
618
|
+
return callback(err);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Sets the Start Date of the Task
|
|
622
|
+
return _tasks.setStartDate(
|
|
623
|
+
listId,
|
|
624
|
+
taskSeriesId,
|
|
625
|
+
taskId,
|
|
626
|
+
start,
|
|
627
|
+
user,
|
|
628
|
+
callback
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
};
|
|
634
|
+
|
|
605
635
|
/**
|
|
606
636
|
* Set the Name of the specified Task
|
|
607
637
|
* @param {int} index Task Index
|
package/src/utils/auth.js
CHANGED
|
@@ -86,14 +86,14 @@ function getAuthToken(frob, client, callback) {
|
|
|
86
86
|
* @param {function} callback Callback function(err, verified)
|
|
87
87
|
* @private
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
function verifyAuthToken(token, client, callback) {
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
// Get token from RTMUser
|
|
92
|
+
if ( typeof token === 'object' ) {
|
|
93
|
+
if ( token.constructor.name === 'RTMUser' ) {
|
|
94
|
+
token = token.authToken;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
97
|
|
|
98
98
|
// Set request parameters
|
|
99
99
|
let params = {
|
|
@@ -173,10 +173,10 @@ function _formQuery(params) {
|
|
|
173
173
|
let parts = [];
|
|
174
174
|
for ( let key in params ) {
|
|
175
175
|
if ( params.hasOwnProperty(key) ) {
|
|
176
|
-
parts.push(encodeURIComponent(key) +
|
|
176
|
+
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
return parts.join(
|
|
179
|
+
return parts.join('&');
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
|
package/src/utils/fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fetch = require('node-fetch');
|
|
2
|
-
const sign = require('../utils/sign')
|
|
3
|
-
|
|
2
|
+
const sign = require('../utils/sign');
|
|
3
|
+
const debug = require('debug')('rtm-api-fetch');
|
|
4
4
|
|
|
5
5
|
// API Configuration Properties
|
|
6
6
|
const config = require('../../config');
|
|
@@ -18,12 +18,12 @@ function buildUrl(user,filter) {
|
|
|
18
18
|
api_key: user._client._apiKey,
|
|
19
19
|
v: version,
|
|
20
20
|
format
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
|
|
23
|
-
let apiSig=sign(query,{secret:user._client._apiSecret})
|
|
23
|
+
let apiSig=sign(query,{secret:user._client._apiSecret});
|
|
24
24
|
|
|
25
|
-
let url = `${scheme}://${base}?${formQuery(query)}&api_sig=${apiSig}
|
|
26
|
-
return url
|
|
25
|
+
let url = `${scheme}://${base}?${formQuery(query)}&api_sig=${apiSig}`;
|
|
26
|
+
return url;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
|
|
@@ -36,13 +36,13 @@ function buildUrl(user,filter) {
|
|
|
36
36
|
* @returns {string} URL Encoded query string
|
|
37
37
|
*/
|
|
38
38
|
function formQuery(params) {
|
|
39
|
-
let parts = [];
|
|
40
|
-
for ( let key in params ) {
|
|
39
|
+
let parts = [];
|
|
40
|
+
for ( let key in params ) {
|
|
41
41
|
if ( params.hasOwnProperty(key) ) {
|
|
42
|
-
|
|
42
|
+
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
|
|
43
43
|
}
|
|
44
|
-
}
|
|
45
|
-
return parts.join(
|
|
44
|
+
}
|
|
45
|
+
return parts.join('&');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -52,16 +52,18 @@ return parts.join("&");
|
|
|
52
52
|
*/
|
|
53
53
|
async function callAPI(url) {
|
|
54
54
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
console.error(error)
|
|
55
|
+
const response = await fetch(url);
|
|
56
|
+
if (await response.ok) {
|
|
57
|
+
const responseJson = await response.json();
|
|
58
|
+
debug(JSON.stringify(responseJson));
|
|
59
|
+
return responseJson;
|
|
60
|
+
} else {
|
|
61
|
+
// TODO improve this error message
|
|
62
|
+
console.error('There was an error');
|
|
64
63
|
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error);
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
module.exports = {callAPI,formQuery, buildUrl}
|
|
69
|
+
module.exports = {callAPI,formQuery, buildUrl};
|
package/src/utils/get.js
CHANGED
|
@@ -8,6 +8,8 @@ const RTMClient = require('../client/index.js');
|
|
|
8
8
|
const RTMUser = require('../user/index.js');
|
|
9
9
|
const sign = require('./sign.js');
|
|
10
10
|
|
|
11
|
+
const debug = require('debug')('rtm-api-get');
|
|
12
|
+
|
|
11
13
|
// API Configuration Properties
|
|
12
14
|
const config = require('../../config');
|
|
13
15
|
const scheme = config.api.scheme;
|
|
@@ -64,7 +66,7 @@ function _makeRequest(scheme, options, callback) {
|
|
|
64
66
|
|
|
65
67
|
// Require the http(s) module
|
|
66
68
|
let http = undefined;
|
|
67
|
-
if ( scheme ===
|
|
69
|
+
if ( scheme === 'https' ) {
|
|
68
70
|
http = require('https');
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
@@ -88,10 +90,11 @@ function _makeRequest(scheme, options, callback) {
|
|
|
88
90
|
|
|
89
91
|
// Parse the API Response
|
|
90
92
|
let parsed = parse(resp);
|
|
93
|
+
debug(JSON.stringify(parsed));
|
|
91
94
|
|
|
92
95
|
// Return parsed result as error or success
|
|
93
96
|
if ( !parsed.isOk ) {
|
|
94
|
-
return callback(parsed)
|
|
97
|
+
return callback(parsed);
|
|
95
98
|
}
|
|
96
99
|
else {
|
|
97
100
|
return callback(null, parsed);
|
|
@@ -182,7 +185,7 @@ function _buildRequestUrl(method, params, user, client) {
|
|
|
182
185
|
let query = _formQuery(args.params);
|
|
183
186
|
|
|
184
187
|
// Build the API request URL
|
|
185
|
-
return scheme + '://' + base +
|
|
188
|
+
return scheme + '://' + base + '?' + query;
|
|
186
189
|
|
|
187
190
|
}
|
|
188
191
|
|
|
@@ -236,10 +239,10 @@ function _formQuery(params) {
|
|
|
236
239
|
let parts = [];
|
|
237
240
|
for ( let key in params ) {
|
|
238
241
|
if ( params.hasOwnProperty(key) ) {
|
|
239
|
-
parts.push(encodeURIComponent(key) +
|
|
242
|
+
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
|
-
return parts.join(
|
|
245
|
+
return parts.join('&');
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
|
package/src/utils/sign.js
CHANGED
|
@@ -44,7 +44,7 @@ function sign(params, client) {
|
|
|
44
44
|
let toHash = client.secret + cat;
|
|
45
45
|
|
|
46
46
|
// Return the Hash
|
|
47
|
-
return crypto.createHash('md5').update(toHash).digest(
|
|
47
|
+
return crypto.createHash('md5').update(toHash).digest('hex');
|
|
48
48
|
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -80,7 +80,7 @@ function _sort(object) {
|
|
|
80
80
|
* @private
|
|
81
81
|
*/
|
|
82
82
|
function _concat(object) {
|
|
83
|
-
let rtn =
|
|
83
|
+
let rtn = '';
|
|
84
84
|
for ( let key in object ) {
|
|
85
85
|
if ( object.hasOwnProperty(key) ) {
|
|
86
86
|
rtn += key + object[key];
|