particle-api-js 10.6.0 → 11.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "particle-api-js",
3
- "version": "10.6.0",
3
+ "version": "11.0.0",
4
4
  "description": "Particle API Client",
5
5
  "main": "src/Particle.js",
6
6
  "scripts": {
package/src/Agent.js CHANGED
@@ -23,20 +23,6 @@ const qs = require('qs');
23
23
  const fs = require('../fs');
24
24
  const packageJson = require('../package.json');
25
25
 
26
- /**
27
- * @typedef {string} AccessToken
28
- */
29
-
30
- /**
31
- * @typedef {object} BasicAuth
32
- * @property {string} username
33
- * @property {string} password
34
- */
35
-
36
- /**
37
- * @typedef {AccessToken | BasicAuth} Auth Prefer using an access token over basic auth for better security
38
- */
39
-
40
26
  /**
41
27
  * The object returned for a basic request
42
28
  * @typedef {object} JSONResponse
@@ -73,7 +59,7 @@ class Agent {
73
59
  * Make a GET request
74
60
  * @param {object} params Configurations to customize the request
75
61
  * @param {string} params.uri The URI to request
76
- * @param {Auth} [params.auth] Authorization token to use
62
+ * @param {string} [params.auth] Authorization token to use
77
63
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
78
64
  * @param {object} [params.query] Key/Value pairs of query params
79
65
  * @param {object} [params.context] The invocation context, describing the tool and project
@@ -87,7 +73,7 @@ class Agent {
87
73
  * Make a HEAD request
88
74
  * @param {object} params Configurations to customize the request
89
75
  * @param {string} params.uri The URI to request
90
- * @param {Auth} [params.auth] Authorization token to use
76
+ * @param {string} [params.auth] Authorization token to use
91
77
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
92
78
  * @param {object} [params.query] Key/Value pairs of query params
93
79
  * @param {object} [params.context] The invocation context, describing the tool and project
@@ -101,7 +87,7 @@ class Agent {
101
87
  * Make a POST request
102
88
  * @param {object} params Configurations to customize the request
103
89
  * @param {string} params.uri The URI to request
104
- * @param {Auth} [params.auth] Authorization token to use
90
+ * @param {string} [params.auth] Authorization token to use
105
91
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
106
92
  * @param {object} [params.data] Request body
107
93
  * @param {object} [params.context] The invocation context, describing the tool and project
@@ -115,7 +101,7 @@ class Agent {
115
101
  * Make a PUT request
116
102
  * @param {object} params Configurations to customize the request
117
103
  * @param {string} params.uri The URI to request
118
- * @param {Auth} [params.auth] Authorization token to use
104
+ * @param {string} [params.auth] Authorization token to use
119
105
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
120
106
  * @param {object} [params.data] Request body
121
107
  * @param {object} [params.query] Key/Value pairs of query params or a correctly formatted string
@@ -130,7 +116,7 @@ class Agent {
130
116
  * Make a DELETE request
131
117
  * @param {object} params Configurations to customize the request
132
118
  * @param {string} params.uri The URI to request
133
- * @param {Auth} [params.auth] Authorization token to use
119
+ * @param {string} [params.auth] Authorization token to use
134
120
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
135
121
  * @param {object} [params.data] Request body
136
122
  * @param {object} [params.context] The invocation context, describing the tool and project
@@ -147,7 +133,7 @@ class Agent {
147
133
  * @param {string} config.method The method used to request the URI, should be in uppercase.
148
134
  * @param {object} [config.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
149
135
  * @param {object} [config.data] Arbitrary data to send as the body.
150
- * @param {Auth} [config.auth] Authorization
136
+ * @param {string} [config.auth] Authorization
151
137
  * @param {object} [config.query] Query parameters
152
138
  * @param {object} [config.form] Form fields
153
139
  * @param {object} [config.files] Array of file names and file content
@@ -240,7 +226,7 @@ class Agent {
240
226
  * @param {string} config.method The method used to request the URI, should be in uppercase.
241
227
  * @param {object} [config.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
242
228
  * @param {object} [config.data] Arbitrary data to send as the body.
243
- * @param {Auth} [config.auth] Authorization
229
+ * @param {string} [config.auth] Authorization
244
230
  * @param {object} [config.query] Query parameters
245
231
  * @param {object} [config.form] Form fields
246
232
  * @param {object} [config.files] Array of file names and file content
@@ -390,24 +376,15 @@ class Agent {
390
376
 
391
377
  /**
392
378
  * Adds an authorization header.
393
- * @param {Auth} [auth] The authorization bearer token.
379
+ * @param {string} [auth] The authorization bearer token.
394
380
  * @returns {object} The original request.
395
381
  */
396
382
  _getAuthorizationHeader(auth){
397
- if (!auth) {
398
- return {};
399
- }
400
383
  if (typeof auth === 'string') {
401
384
  return { Authorization: `Bearer ${auth}` };
402
385
  }
403
- let encoded;
404
- if (this.isForBrowser()) {
405
- encoded = btoa(`${auth.username}:${auth.password}`);
406
- } else {
407
- encoded = Buffer.from(`${auth.username}:${auth.password}`)
408
- .toString('base64');
409
- }
410
- return { Authorization: `Basic ${encoded}` };
386
+
387
+ return {};
411
388
  }
412
389
 
413
390
  /**
@@ -29,7 +29,10 @@ class EventStream extends EventEmitter {
29
29
  const req = requestor.request({
30
30
  hostname,
31
31
  protocol,
32
- path: `${path}?access_token=${this.token}`,
32
+ path,
33
+ headers: {
34
+ 'Authorization': `Bearer ${this.token}`
35
+ },
33
36
  method: 'get',
34
37
  // @ts-ignore
35
38
  port: parseInt(port, 10) || (isSecure ? 443 : 80),