@beauraines/rtm-api 1.4.1 → 1.5.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 +12 -0
- package/README.md +1 -1
- package/package.json +18 -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 +2 -2
- package/src/user/tasks.js +24 -24
- 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/.eslintrc.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"commonjs": true,
|
|
5
|
+
"es2021": true
|
|
6
|
+
},
|
|
7
|
+
"extends": "eslint:recommended",
|
|
8
|
+
"overrides": [
|
|
9
|
+
],
|
|
10
|
+
"parserOptions": {
|
|
11
|
+
"ecmaVersion": "latest"
|
|
12
|
+
},
|
|
13
|
+
"rules": {
|
|
14
|
+
"indent": [
|
|
15
|
+
"error",
|
|
16
|
+
2
|
|
17
|
+
],
|
|
18
|
+
"linebreak-style": [
|
|
19
|
+
"error",
|
|
20
|
+
"unix"
|
|
21
|
+
],
|
|
22
|
+
"quotes": [
|
|
23
|
+
"error",
|
|
24
|
+
"single"
|
|
25
|
+
],
|
|
26
|
+
"semi": [
|
|
27
|
+
"error",
|
|
28
|
+
"always"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: 'Publish to NPM'
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_run:
|
|
5
|
+
workflows: ['Node.js CI']
|
|
6
|
+
types: [completed]
|
|
7
|
+
branches: [master,main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish-new-version:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
|
+
with:
|
|
16
|
+
fetch-depth: '0'
|
|
17
|
+
- name: git setup
|
|
18
|
+
run: |
|
|
19
|
+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
20
|
+
git config --local user.name "github-actions[bot]"
|
|
21
|
+
- name: setup node
|
|
22
|
+
uses: actions/setup-node@v3
|
|
23
|
+
with:
|
|
24
|
+
node-version: 16.x
|
|
25
|
+
registry-url: 'https://registry.npmjs.org'
|
|
26
|
+
- name: npm install
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Should release
|
|
30
|
+
id: should_release
|
|
31
|
+
continue-on-error: true
|
|
32
|
+
run: npm run should-release -- -v
|
|
33
|
+
|
|
34
|
+
- name: No release
|
|
35
|
+
if: steps.should_release.outcome != 'success'
|
|
36
|
+
run: echo "No release required. Skipping publishing."
|
|
37
|
+
|
|
38
|
+
- name: Version bump
|
|
39
|
+
if: steps.should_release.outcome == 'success'
|
|
40
|
+
run: npm run release
|
|
41
|
+
|
|
42
|
+
- name: Publish to NPM
|
|
43
|
+
if: steps.should_release.outcome == 'success'
|
|
44
|
+
run: npm publish
|
|
45
|
+
env:
|
|
46
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
47
|
+
|
|
48
|
+
- name: Push commits to GitHub
|
|
49
|
+
if: steps.should_release.outcome == 'success'
|
|
50
|
+
uses: ad-m/github-push-action@master
|
|
51
|
+
with:
|
|
52
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
53
|
+
branch: ${{ github.ref }}
|
|
54
|
+
tags: true
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main,master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main,master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
node-version: [16.x,18.x]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v3
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
- run: npm ci
|
|
25
|
+
- run: npm test
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## [1.5.0](https://github.com/beauraines/rtm-api/compare/v1.3.1...v1.5.0) (2023-03-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add debug ([#14](https://github.com/beauraines/rtm-api/issues/14)) ([3314648](https://github.com/beauraines/rtm-api/commit/3314648ca1680f4b25c602a5700afef7d99fb247))
|
|
11
|
+
|
|
12
|
+
### [1.4.2](https://github.com/beauraines/rtm-api/compare/v1.3.1...v1.4.2) (2023-03-05)
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ user.tasks.get('priority:1', function(err, tasks) {
|
|
|
56
56
|
This module can be installed via `npm`:
|
|
57
57
|
|
|
58
58
|
```
|
|
59
|
-
npm
|
|
59
|
+
npm i @beauraines/rtm-api
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
or downloaded directly from the [GitHub repository](https://github.com/beauraines/rtm-api).
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beauraines/rtm-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Remember the Milk API Interface",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "David Waring <dev@davidwaring.net> (https://davidwaring.net)",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Beau Raines <beau.raines@gmail.com>"
|
|
8
|
+
],
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"keywords": [
|
|
8
11
|
"rtm",
|
|
@@ -14,10 +17,18 @@
|
|
|
14
17
|
],
|
|
15
18
|
"main": "src/client/index.js",
|
|
16
19
|
"scripts": {
|
|
17
|
-
"docs": "jsdoc -c jsdoc.json --readme README.md --template $NODE_PATH/@dwaring87/docdash"
|
|
20
|
+
"docs": "jsdoc -c jsdoc.json --readme README.md --template $NODE_PATH/@dwaring87/docdash",
|
|
21
|
+
"test": "jest --passWithNoTests",
|
|
22
|
+
"lint": "eslint src",
|
|
23
|
+
"lint:fix": "eslint src --fix",
|
|
24
|
+
"release": "standard-version",
|
|
25
|
+
"should-release": "should-release"
|
|
18
26
|
},
|
|
19
27
|
"devDependencies": {
|
|
20
28
|
"@dwaring87/docdash": "^0.4.1",
|
|
29
|
+
"eslint": "^8.35.0",
|
|
30
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
31
|
+
"jest": "^29.4.3",
|
|
21
32
|
"jsdoc": "^3.6.3"
|
|
22
33
|
},
|
|
23
34
|
"repository": {
|
|
@@ -28,6 +39,9 @@
|
|
|
28
39
|
"url": "https://github.com/beauraines/rtm-api/issues"
|
|
29
40
|
},
|
|
30
41
|
"dependencies": {
|
|
31
|
-
"
|
|
42
|
+
"debug": "^4.3.4",
|
|
43
|
+
"node-fetch": "^2.6.7",
|
|
44
|
+
"should-release": "^1.2.0",
|
|
45
|
+
"standard-version": "^9.5.0"
|
|
32
46
|
}
|
|
33
47
|
}
|
package/src/client/user.js
CHANGED
|
@@ -53,14 +53,14 @@ module.exports = function(client) {
|
|
|
53
53
|
apiKey: user.client.key,
|
|
54
54
|
apiSecret: user.client.secret,
|
|
55
55
|
perms: user.client.perms
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
59
|
rtn.client = {
|
|
60
60
|
apiKey: client.key,
|
|
61
61
|
apiSecret: client.key,
|
|
62
62
|
perms: client.perms
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
return rtn;
|
|
@@ -94,7 +94,7 @@ module.exports = function(client) {
|
|
|
94
94
|
return user;
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
throw
|
|
97
|
+
throw 'Missing User Properties';
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
|
package/src/list/helper.js
CHANGED
package/src/response/error.js
CHANGED
|
@@ -50,7 +50,7 @@ class RTMError extends RTMResponse{
|
|
|
50
50
|
* @returns {string}
|
|
51
51
|
*/
|
|
52
52
|
toString() {
|
|
53
|
-
return super.toString() +
|
|
53
|
+
return super.toString() + ' ERROR ' + this._code + ': ' + this._msg;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
}
|
|
@@ -65,7 +65,7 @@ class RTMError extends RTMResponse{
|
|
|
65
65
|
* @returns {RTMError}
|
|
66
66
|
*/
|
|
67
67
|
RTMError.networkError = function() {
|
|
68
|
-
return new RTMError(-1,
|
|
68
|
+
return new RTMError(-1, 'Network Error: Could not make request to RTM API Server');
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -75,7 +75,7 @@ RTMError.networkError = function() {
|
|
|
75
75
|
* @returns {RTMError}
|
|
76
76
|
*/
|
|
77
77
|
RTMError.responseError = function() {
|
|
78
|
-
return new RTMError(-2,
|
|
78
|
+
return new RTMError(-2, 'Response Error: Could not parse the response from the RTM API Server');
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
/**
|
|
@@ -86,7 +86,7 @@ RTMError.responseError = function() {
|
|
|
86
86
|
* @returns {RTMError}
|
|
87
87
|
*/
|
|
88
88
|
RTMError.referenceError = function() {
|
|
89
|
-
return new RTMError(-3,
|
|
89
|
+
return new RTMError(-3, 'Reference Error: Could not find item by reference index number or name');
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -97,7 +97,7 @@ RTMError.referenceError = function() {
|
|
|
97
97
|
* @returns {RTMError}
|
|
98
98
|
*/
|
|
99
99
|
RTMError.rateLimitError = function() {
|
|
100
|
-
return new RTMError(-4,
|
|
100
|
+
return new RTMError(-4, 'Rate Limit Error: Your Account has temporarily reached the RTM API Rate Limit. Please wait a minute and try the request again later.');
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
/**
|
|
@@ -108,7 +108,7 @@ RTMError.rateLimitError = function() {
|
|
|
108
108
|
* @returns {RTMError}
|
|
109
109
|
*/
|
|
110
110
|
RTMError.serverError = function() {
|
|
111
|
-
return new RTMError(-5,
|
|
111
|
+
return new RTMError(-5, 'RTM API Server Error: The RTM API Server is not responding. Please try the request again later.');
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
module.exports = RTMError;
|
package/src/response/response.js
CHANGED
|
@@ -77,7 +77,7 @@ class RTMResponse {
|
|
|
77
77
|
* @returns {string}
|
|
78
78
|
*/
|
|
79
79
|
toString() {
|
|
80
|
-
return
|
|
80
|
+
return '[' + this._status + ']';
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
}
|
|
@@ -88,14 +88,14 @@ class RTMResponse {
|
|
|
88
88
|
* @type {string}
|
|
89
89
|
* @default
|
|
90
90
|
*/
|
|
91
|
-
RTMResponse.STATUS_OK =
|
|
91
|
+
RTMResponse.STATUS_OK = 'ok';
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* RTM Status of 'fail' = error
|
|
95
95
|
* @type {string}
|
|
96
96
|
* @default
|
|
97
97
|
*/
|
|
98
|
-
RTMResponse.STATUS_FAIL =
|
|
98
|
+
RTMResponse.STATUS_FAIL = 'fail';
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
|
package/src/response/success.js
CHANGED
package/src/task/helper.js
CHANGED
|
@@ -76,42 +76,42 @@ function add(name, props, user, callback) {
|
|
|
76
76
|
|
|
77
77
|
// Parse the props keys
|
|
78
78
|
if ( props.due ) {
|
|
79
|
-
name = name +
|
|
79
|
+
name = name + ' ^' + props.due;
|
|
80
80
|
}
|
|
81
81
|
if ( props.priority ) {
|
|
82
|
-
name = name +
|
|
82
|
+
name = name + ' !' + props.priority;
|
|
83
83
|
}
|
|
84
84
|
if ( props.list ) {
|
|
85
|
-
name = name +
|
|
85
|
+
name = name + ' #' + props.list;
|
|
86
86
|
}
|
|
87
87
|
if ( props.tags ) {
|
|
88
88
|
if ( !Array.isArray(props.tags) ) {
|
|
89
89
|
props.tags = [props.tags];
|
|
90
90
|
}
|
|
91
91
|
for ( let i = 0; i < props.tags.length; i++ ) {
|
|
92
|
-
name = name +
|
|
92
|
+
name = name + ' #' + props.tags[i];
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
if ( props.location ) {
|
|
96
|
-
name = name +
|
|
96
|
+
name = name + ' @' + props.location;
|
|
97
97
|
}
|
|
98
98
|
if ( props.start ) {
|
|
99
|
-
name = name +
|
|
99
|
+
name = name + ' ~' + props.start;
|
|
100
100
|
}
|
|
101
101
|
if ( props.repeat ) {
|
|
102
|
-
name = name +
|
|
102
|
+
name = name + ' *' + props.repeat;
|
|
103
103
|
}
|
|
104
104
|
if ( props.estimate ) {
|
|
105
|
-
name = name +
|
|
105
|
+
name = name + ' =' + props.estimate;
|
|
106
106
|
}
|
|
107
107
|
if ( props.to ) {
|
|
108
|
-
name = name +
|
|
108
|
+
name = name + ' +' + props.to;
|
|
109
109
|
}
|
|
110
110
|
if ( props.url ) {
|
|
111
|
-
name = name +
|
|
111
|
+
name = name + ' ' + props.url;
|
|
112
112
|
}
|
|
113
113
|
if ( props.note ) {
|
|
114
|
-
name = name +
|
|
114
|
+
name = name + ' //' + props.note;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// Set the request params
|
|
@@ -233,7 +233,7 @@ function addNotes(listId, taskSeriesId, taskId, title, notes, user, callback) {
|
|
|
233
233
|
list_id: listId,
|
|
234
234
|
taskseries_id: taskSeriesId,
|
|
235
235
|
task_id: taskId,
|
|
236
|
-
|
|
236
|
+
note_title: title,
|
|
237
237
|
note_text: notes
|
|
238
238
|
};
|
|
239
239
|
user.get('rtm.tasks.notes.add', params, function(err) {
|
|
@@ -274,7 +274,7 @@ function remove(listId, taskSeriesId, taskId, user, callback) {
|
|
|
274
274
|
*/
|
|
275
275
|
function movePriority(listId, taskSeriesId, taskId, direction, user, callback) {
|
|
276
276
|
if ( direction.toLowerCase() !== 'up' && direction.toLowerCase() !== 'down' ) {
|
|
277
|
-
throw
|
|
277
|
+
throw 'Incorrect priority direction. Must be either \'up\' or \'down\'';
|
|
278
278
|
}
|
|
279
279
|
let params = {
|
|
280
280
|
timeline: user.timeline,
|
package/src/task/index.js
CHANGED
|
@@ -215,12 +215,12 @@ class RTMTask {
|
|
|
215
215
|
* Task subtask flag
|
|
216
216
|
* @type {boolean}
|
|
217
217
|
*/
|
|
218
|
-
this.isSubtask = series.parent_task_id !=
|
|
218
|
+
this.isSubtask = series.parent_task_id != '' ? true : false;
|
|
219
219
|
|
|
220
220
|
/** Task parent task id
|
|
221
221
|
* @type {integer|undefined}
|
|
222
222
|
*/
|
|
223
|
-
this.parentTaskId = series.parent_task_id !=
|
|
223
|
+
this.parentTaskId = series.parent_task_id != '' ? parseFloat(series.parent_task_id) : undefined;
|
|
224
224
|
|
|
225
225
|
|
|
226
226
|
}
|
|
@@ -240,7 +240,7 @@ class RTMTask {
|
|
|
240
240
|
*/
|
|
241
241
|
get list() {
|
|
242
242
|
if ( this._list === undefined ) {
|
|
243
|
-
throw
|
|
243
|
+
throw 'Tasks not loaded with associated Lists';
|
|
244
244
|
}
|
|
245
245
|
return this._list;
|
|
246
246
|
}
|
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
|
}
|
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) {
|
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];
|