particle-api-js 11.1.7 → 12.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.
Files changed (85) hide show
  1. package/README.md +90 -10
  2. package/dist/particle.min.js +1 -1
  3. package/dist/particle.min.js.map +1 -1
  4. package/fs.d.ts +2 -0
  5. package/lib/fs.d.ts +2 -0
  6. package/lib/fs.js +3 -0
  7. package/lib/package.json +109 -0
  8. package/lib/src/Agent.d.ts +38 -0
  9. package/lib/src/Agent.d.ts.map +1 -0
  10. package/lib/src/Agent.js +228 -0
  11. package/lib/src/Agent.js.map +1 -0
  12. package/lib/src/Client.d.ts +80 -0
  13. package/lib/src/Client.d.ts.map +1 -0
  14. package/lib/src/Client.js +104 -0
  15. package/lib/src/Client.js.map +1 -0
  16. package/lib/src/Defaults.d.ts +6 -0
  17. package/lib/src/Defaults.d.ts.map +1 -0
  18. package/lib/src/Defaults.js +12 -0
  19. package/lib/src/Defaults.js.map +1 -0
  20. package/lib/src/EventStream.d.ts +29 -0
  21. package/lib/src/EventStream.d.ts.map +1 -0
  22. package/lib/src/EventStream.js +270 -0
  23. package/lib/src/EventStream.js.map +1 -0
  24. package/lib/src/Library.d.ts +33 -0
  25. package/lib/src/Library.d.ts.map +1 -0
  26. package/lib/src/Library.js +19 -0
  27. package/lib/src/Library.js.map +1 -0
  28. package/{src/Particle.js → lib/src/Particle.d.ts} +790 -1666
  29. package/lib/src/Particle.d.ts.map +1 -0
  30. package/lib/src/Particle.js +2794 -0
  31. package/lib/src/Particle.js.map +1 -0
  32. package/lib/src/types/common.d.ts +71 -0
  33. package/lib/src/types/common.d.ts.map +1 -0
  34. package/lib/src/types/common.js +3 -0
  35. package/lib/src/types/common.js.map +1 -0
  36. package/lib/src/types/index.d.ts +4 -0
  37. package/lib/src/types/index.d.ts.map +1 -0
  38. package/lib/src/types/index.js +20 -0
  39. package/lib/src/types/index.js.map +1 -0
  40. package/lib/src/types/requests.d.ts +667 -0
  41. package/lib/src/types/requests.d.ts.map +1 -0
  42. package/lib/src/types/requests.js +3 -0
  43. package/lib/src/types/requests.js.map +1 -0
  44. package/lib/src/types/responses.d.ts +472 -0
  45. package/lib/src/types/responses.d.ts.map +1 -0
  46. package/lib/src/types/responses.js +3 -0
  47. package/lib/src/types/responses.js.map +1 -0
  48. package/package.json +34 -14
  49. package/scripts/postprocess-docs.js +306 -0
  50. package/typedoc.json +20 -0
  51. package/.circleci/config.yml +0 -104
  52. package/.nvmrc +0 -1
  53. package/CHANGELOG.md +0 -404
  54. package/EventStream-e2e-browser.html +0 -39
  55. package/EventStream-e2e-node.js +0 -34
  56. package/RELEASE.md +0 -12
  57. package/bower.json +0 -30
  58. package/docs/api.md +0 -2594
  59. package/eslint.config.mjs +0 -7
  60. package/examples/login/login.html +0 -17
  61. package/karma.conf.js +0 -80
  62. package/src/Agent.js +0 -397
  63. package/src/Client.js +0 -171
  64. package/src/Defaults.js +0 -8
  65. package/src/EventStream.js +0 -269
  66. package/src/Library.js +0 -33
  67. package/test/Agent.integration.js +0 -23
  68. package/test/Agent.spec.js +0 -488
  69. package/test/Client.spec.js +0 -216
  70. package/test/Defaults.spec.js +0 -30
  71. package/test/EventStream.feature +0 -65
  72. package/test/EventStream.spec.js +0 -263
  73. package/test/FakeAgent.js +0 -27
  74. package/test/Library.spec.js +0 -40
  75. package/test/Particle.integration.js +0 -38
  76. package/test/Particle.spec.js +0 -3198
  77. package/test/fixtures/index.js +0 -15
  78. package/test/fixtures/libraries.json +0 -33
  79. package/test/fixtures/library.json +0 -31
  80. package/test/fixtures/libraryVersions.json +0 -211
  81. package/test/out.tmp +0 -0
  82. package/test/support/FixtureHttpServer.js +0 -28
  83. package/test/test-setup.js +0 -17
  84. package/tsconfig.json +0 -17
  85. package/webpack.config.js +0 -46
package/eslint.config.mjs DELETED
@@ -1,7 +0,0 @@
1
- import { particle } from 'eslint-config-particle';
2
-
3
- export default particle({
4
- rootDir: import.meta.dirname,
5
- testGlobals: 'mocha',
6
- globalIgnores: ['dist', 'coverage']
7
- });
@@ -1,17 +0,0 @@
1
- <html>
2
- <head>
3
- <title>Particle Login Example</title>
4
- </head>
5
- <body>
6
- <script src="https://cdn.jsdelivr.net/particle-api-js/5/particle.min.js"></script>
7
- <script>
8
- var particle = new Particle();
9
- particle.login({ username: 'name@example.com', password: 'password' })
10
- .then(function(result) {
11
- console.log('Your access token', result.body.access_token);
12
- }, function(err) {
13
- console.error(err);
14
- });
15
- </script>
16
- </body>
17
- </html>
package/karma.conf.js DELETED
@@ -1,80 +0,0 @@
1
- // Karma configuration
2
- // Generated on Wed Jul 20 2016 12:00:09 GMT-0400 (EDT)
3
- 'use strict';
4
- const webpackConf = require('./webpack.config.js');
5
- const webpack = require('webpack');
6
-
7
- module.exports = function karmaCfg(config){
8
- config.set({
9
- // base path that will be used to resolve all patterns (eg. files, exclude)
10
- basePath: '',
11
-
12
- // frameworks to use
13
- // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14
- frameworks: ['webpack', 'mocha', 'chai'],
15
-
16
- // list of files / patterns to load in the browser
17
- files: [
18
- 'dist/particle.min.js',
19
- 'test/*.spec.js',
20
- 'test/*.integration.js'
21
- ],
22
-
23
- // list of files to exclude
24
- exclude: [
25
- ],
26
-
27
- // preprocess matching files before serving them to the browser
28
- // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
29
- preprocessors: {
30
- 'src/**/*.js': ['webpack'],
31
- 'test/**/*.js': ['webpack']
32
- },
33
-
34
- // Transform test files to a single browser consumable file
35
- webpack: {
36
- mode: 'development',
37
- target: 'web',
38
- devtool: 'inline-source-map',
39
- output: webpackConf.output,
40
- externals: webpackConf.externals,
41
- resolve: webpackConf.resolve,
42
- plugins: [
43
- new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
44
- new webpack.EnvironmentPlugin({
45
- SKIP_AGENT_TEST: process.env.SKIP_AGENT_TEST || false
46
- })
47
- ]
48
- },
49
-
50
- // test results reporter to use
51
- // possible values: 'dots', 'progress'
52
- // available reporters: https://npmjs.org/browse/keyword/karma-reporter
53
- reporters: ['progress', 'coverage'],
54
-
55
- // web server port
56
- port: 9876,
57
-
58
- // enable / disable colors in the output (reporters and logs)
59
- colors: true,
60
-
61
- // level of logging
62
- // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
63
- logLevel: config.LOG_INFO,
64
-
65
- // enable / disable watching file and executing tests whenever any file changes
66
- autoWatch: true,
67
-
68
- // start these browsers
69
- // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
70
- browsers: ['Firefox'],
71
-
72
- // Continuous Integration mode
73
- // if true, Karma captures browsers, runs the tests and exits
74
- singleRun: false,
75
-
76
- // Concurrency level
77
- // how many browser should be started simultaneous
78
- concurrency: Infinity
79
- });
80
- };
package/src/Agent.js DELETED
@@ -1,397 +0,0 @@
1
- 'use strict';
2
- const fetch = require('node-fetch');
3
- const FormData = require('form-data');
4
- const qs = require('qs');
5
- const fs = require('../fs');
6
- const packageJson = require('../package.json');
7
-
8
- /**
9
- * The object returned for a basic request
10
- * @typedef {object} JSONResponse
11
- * @property {number} statusCode The HTTP response status
12
- * @property {object} body The endpoint's response parsed as a JSON
13
- */
14
-
15
- /**
16
- * The possible response from an API request
17
- * @typedef {JSONResponse | Buffer | ArrayBuffer} RequestResponse The type is based on
18
- * the request config and whether is on browser or node
19
- */
20
-
21
- /**
22
- * The error object generated in case of a failed request
23
- * @typedef {object} RequestError
24
- * @property {number} statusCode The HTTP response status
25
- * @property {string} errorDescription Details on what caused the failed request
26
- * @property {string} shortErrorDescription Summarized version of the fail reason
27
- * @property {object} body The response object from the request
28
- * @property {object} error The error object from the request
29
- */
30
-
31
- class Agent {
32
- constructor(baseUrl){
33
- this.setBaseUrl(baseUrl);
34
- }
35
-
36
- setBaseUrl(baseUrl) {
37
- this.baseUrl = baseUrl;
38
- }
39
-
40
- /**
41
- * Make a GET request
42
- * @param {object} params Configurations to customize the request
43
- * @param {string} params.uri The URI to request
44
- * @param {string} [params.auth] Authorization token to use
45
- * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
46
- * @param {object} [params.query] Key/Value pairs of query params
47
- * @param {object} [params.context] The invocation context, describing the tool and project
48
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
49
- */
50
- get({ uri, auth, headers, query, context }) {
51
- return this.request({ uri, method: 'get', auth, headers, query, context });
52
- }
53
-
54
- /**
55
- * Make a HEAD request
56
- * @param {object} params Configurations to customize the request
57
- * @param {string} params.uri The URI to request
58
- * @param {string} [params.auth] Authorization token to use
59
- * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
60
- * @param {object} [params.query] Key/Value pairs of query params
61
- * @param {object} [params.context] The invocation context, describing the tool and project
62
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
63
- */
64
- head({ uri, auth, headers, query, context }) {
65
- return this.request({ uri, method: 'head', auth, headers, query, context });
66
- }
67
-
68
- /**
69
- * Make a POST request
70
- * @param {object} params Configurations to customize the request
71
- * @param {string} params.uri The URI to request
72
- * @param {string} [params.auth] Authorization token to use
73
- * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
74
- * @param {object} [params.data] Object to send as JSON data in the body.
75
- * @param {object} [params.context] The invocation context, describing the tool and project
76
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
77
- */
78
- post({ uri, headers, data, auth, context }) {
79
- return this.request({ uri, method: 'post', auth, headers, data, context });
80
- }
81
-
82
- /**
83
- * Make a PUT request
84
- * @param {object} params Configurations to customize the request
85
- * @param {string} params.uri The URI to request
86
- * @param {string} [params.auth] Authorization token to use
87
- * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
88
- * @param {object} [params.data] Object to send as JSON data in the body.
89
- * @param {object} [params.query] Key/Value pairs of query params or a correctly formatted string
90
- * @param {object} [params.context] The invocation context, describing the tool and project
91
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
92
- */
93
- put({ uri, auth, headers, data, query, context }) {
94
- return this.request({ uri, method: 'put', auth, headers, data, query, context });
95
- }
96
-
97
- /**
98
- * Make a DELETE request
99
- * @param {object} params Configurations to customize the request
100
- * @param {string} params.uri The URI to request
101
- * @param {string} [params.auth] Authorization token to use
102
- * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
103
- * @param {object} [params.data] Object to send as JSON data in the body.
104
- * @param {object} [params.context] The invocation context, describing the tool and project
105
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
106
- */
107
- delete({ uri, auth, headers, data, context }) {
108
- return this.request({ uri, method: 'delete', auth, headers, data, context });
109
- }
110
-
111
- /**
112
- *
113
- * @param {object} config An obj with all the possible request configurations
114
- * @param {string} config.uri The URI to request
115
- * @param {string} config.method The method used to request the URI, should be in uppercase.
116
- * @param {object} [config.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
117
- * @param {object} [config.data] Object to send as JSON data in the body.
118
- * @param {string} [config.auth] Authorization
119
- * @param {object} [config.query] Query parameters
120
- * @param {object} [config.form] Form fields
121
- * @param {object} [config.files] Array of file names and file content
122
- * @param {object} [config.context] The invocation context, describing the tool and project.
123
- * @param {boolean} [config.isBuffer=false] Indicate if the response should be treated as Buffer instead of JSON
124
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
125
- */
126
- request({
127
- uri,
128
- method,
129
- headers = undefined,
130
- data = undefined,
131
- auth,
132
- query = undefined,
133
- form = undefined,
134
- files = undefined,
135
- context = undefined,
136
- isBuffer = false
137
- }){
138
- const requestFiles = this._sanitizeFiles(files);
139
- const requestParams = this._buildRequest({ uri, method, headers, data, auth, query, form, context, files: requestFiles });
140
- return this._promiseResponse(requestParams, isBuffer);
141
- }
142
-
143
- /**
144
- * Promises to send the request and retrieve the response.
145
- * @param {[string, object]} requestParams First argument is the URI to request, the second one are the options.
146
- * @param {boolean} isBuffer Indicate if the response body should be returned as a Buffer (Node) / ArrayBuffer (browser) instead of JSON
147
- * @param {function} [makerequest=fetch] The fetch function to use. Override for testing.
148
- * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
149
- * @private
150
- */
151
- _promiseResponse(requestParams, isBuffer, makerequest = fetch) {
152
- let status;
153
- return makerequest(...requestParams)
154
- .then((resp) => {
155
- status = resp.status;
156
- if (!resp.ok) {
157
- return resp.text().then((err) => {
158
- const objError = JSON.parse(err);
159
- // particle-commnds/src/cmd/api expects response.text. to be a string
160
- const response = Object.assign(resp, { text: err });
161
- throw Object.assign(objError, { response });
162
- });
163
- }
164
- if (status === 204) { // Can't do resp.json() since there is no body to parse
165
- return '';
166
- }
167
- if (isBuffer) {
168
- return resp.blob();
169
- }
170
- return resp.json();
171
- }).then((body) => {
172
- if (isBuffer) {
173
- return body.arrayBuffer().then((arrayBuffer) => {
174
- if (!this.isForBrowser()) {
175
- return Buffer.from(arrayBuffer);
176
- }
177
- return arrayBuffer;
178
- });
179
- }
180
- return {
181
- body,
182
- statusCode: status
183
- };
184
- }).catch((error) => {
185
- const errorType = status ? `HTTP error ${status}` : 'Network error';
186
- let errorDescription = `${errorType} from ${requestParams[0]}`;
187
- let shortErrorDescription;
188
- if (error.error_description) { // Fetch responded with ok false
189
- errorDescription = `${errorDescription} - ${error.error_description}`;
190
- shortErrorDescription = error.error_description;
191
- }
192
- const reason = new Error(errorDescription);
193
- Object.assign(reason, {
194
- statusCode: status,
195
- errorDescription,
196
- shortErrorDescription,
197
- error,
198
- body: error
199
- });
200
- throw reason;
201
- });
202
- }
203
-
204
- /**
205
- * Generate the params in a format valid for 'fetch'
206
- * @param {object} config Configurations to customize the request
207
- * @param {string} config.uri The URI to request
208
- * @param {string} config.method The method used to request the URI, should be in uppercase.
209
- * @param {object} [config.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
210
- * @param {object} [config.data] Object to send as JSON data in the body.
211
- * @param {string} [config.auth] Authorization
212
- * @param {object} [config.query] Query parameters
213
- * @param {object} [config.form] Form fields
214
- * @param {object} [config.files] Object of key-value file names and file content
215
- * @param {object} [config.context] The invocation context, describing the tool and project.
216
- * @returns {[string, object]} The uri to make the request too, and extra configs
217
- * @private
218
- */
219
- _buildRequest({ uri, method, headers, data, auth, query, form, files, context }){
220
- let actualUri = uri;
221
- if (this.baseUrl && uri[0] === '/') {
222
- actualUri = `${this.baseUrl}${uri}`;
223
- }
224
- if (query) {
225
- const queryParams = qs.stringify(query);
226
- if (queryParams) {
227
- const hasParams = actualUri.includes('?');
228
- actualUri = `${actualUri}${hasParams ? '&' : '?'}${queryParams}`;
229
- }
230
- }
231
-
232
- const userAgentHeader = { 'User-Agent': `${packageJson.name}/${packageJson.version} (${packageJson.repository.url})` };
233
- let body;
234
- let contentTypeHeader;
235
- if (files){
236
- // @ts-ignore
237
- contentTypeHeader = {}; // Needed to allow fetch create its own
238
- body = this._getFromData(files, form);
239
- } else if (form){
240
- contentTypeHeader = { 'Content-Type': 'application/x-www-form-urlencoded' };
241
- body = qs.stringify(form);
242
- } else if (data) {
243
- if (data instanceof FormData) {
244
- body = data;
245
- } else {
246
- contentTypeHeader = { 'Content-Type': 'application/json' };
247
- body = JSON.stringify(data);
248
- }
249
- }
250
- const finalHeaders = Object.assign({},
251
- userAgentHeader,
252
- contentTypeHeader,
253
- this._getAuthorizationHeader(auth),
254
- this._getContextHeaders(context),
255
- headers
256
- );
257
-
258
- return [actualUri, { method, body, headers: finalHeaders }];
259
- }
260
-
261
- isForBrowser() {
262
- return typeof window !== 'undefined';
263
- }
264
-
265
- _getFromData(files, form) {
266
- const formData = new FormData();
267
- for (const [name, file] of Object.entries(files)){
268
- let path = file.path;
269
- let fileData = file.data;
270
- if (!this.isForBrowser()) {
271
- const nodeFormData = this._getNodeFormData(file);
272
- path = nodeFormData.path;
273
- fileData = nodeFormData.file;
274
- }
275
- formData.append(name, fileData, path);
276
- }
277
- if (form){
278
- for (const [name, value] of Object.entries(form)){
279
- formData.append(name, value);
280
- }
281
- }
282
- return formData;
283
- }
284
-
285
- _getNodeFormData(file) {
286
- let fileData = file.data;
287
- if (typeof file.data === 'string') {
288
- fileData = fs.createReadStream(file.data);
289
- }
290
- return {
291
- file: fileData,
292
- path: { filepath: file.path } // Different API for nodejs
293
- };
294
- }
295
-
296
- _getContextHeaders(context = {}) {
297
- return Object.assign({},
298
- this._getToolContext(context.tool),
299
- this._getProjectContext(context.project)
300
- );
301
- }
302
-
303
- _getToolContext(tool = {}){
304
- let value = '';
305
- if (tool.name){
306
- value += this._toolIdent(tool);
307
- if (tool.components){
308
- for (const component of tool.components){
309
- value += ', ' + this._toolIdent(component);
310
- }
311
- }
312
- }
313
- if (value){
314
- return { 'X-Particle-Tool': value };
315
- }
316
- return {};
317
- }
318
-
319
- _toolIdent(tool){
320
- return this._nameAtVersion(tool.name, tool.version);
321
- }
322
-
323
- _nameAtVersion(name, version){
324
- let value = '';
325
- if (name){
326
- value += name;
327
- if (version){
328
- value += '@' + version;
329
- }
330
- }
331
- return value;
332
- }
333
-
334
- _getProjectContext(project = {}){
335
- const value = this._buildSemicolonSeparatedProperties(project, 'name');
336
- if (value){
337
- return { 'X-Particle-Project': value };
338
- }
339
- return {};
340
- }
341
-
342
- /**
343
- * Creates a string like primaryPropertyValue; name=value; name1=value
344
- * from the properties of an object.
345
- * @param {object} obj The object to create the string from
346
- * @param {string} primaryProperty The name of the primary property which is the default value and must be defined.
347
- * @private
348
- * @return {string} The formatted string representing the object properties and the default property.
349
- */
350
- _buildSemicolonSeparatedProperties(obj, primaryProperty){
351
- let value = '';
352
- if (obj[primaryProperty]){
353
- value += obj[primaryProperty];
354
- for (const prop in obj){
355
- if (prop !== primaryProperty && Object.hasOwnProperty.call(obj, prop)){
356
- value += '; ' + prop + '=' + obj[prop];
357
- }
358
- }
359
- }
360
- return value;
361
- }
362
-
363
- /**
364
- * Adds an authorization header.
365
- * @param {string} [auth] The authorization bearer token.
366
- * @returns {object} The original request.
367
- */
368
- _getAuthorizationHeader(auth){
369
- if (typeof auth === 'string') {
370
- return { Authorization: `Bearer ${auth}` };
371
- }
372
-
373
- return {};
374
- }
375
-
376
- /**
377
- *
378
- * @param {Object} files converts the file names to file, file1, file2.
379
- * @returns {object} the renamed files.
380
- */
381
- _sanitizeFiles(files){
382
- let requestFiles;
383
- if (files){
384
- requestFiles = {};
385
- Object.keys(files).forEach((k, i) => {
386
- const name = i ? `file${i + 1}` : 'file';
387
- requestFiles[name] = {
388
- data: files[k],
389
- path: k
390
- };
391
- });
392
- }
393
- return requestFiles;
394
- }
395
- }
396
-
397
- module.exports = Agent;
package/src/Client.js DELETED
@@ -1,171 +0,0 @@
1
- 'use strict';
2
- const Library = require('./Library');
3
- let Particle = undefined;
4
-
5
- class Client {
6
- constructor({ auth, api = new Particle() }){
7
- this.auth = auth;
8
- this.api = api;
9
- }
10
-
11
- ready(){
12
- return Boolean(this.auth);
13
- }
14
-
15
- /**
16
- * Get firmware library objects
17
- * @param {Object} query The query parameters for libraries. See Particle.listLibraries
18
- * @returns {Promise} A promise
19
- */
20
- libraries(query = {}){
21
- return this.api.listLibraries(Object.assign({}, query, { auth: this.auth }))
22
- .then(payload => {
23
- const libraries = payload.body.data || [];
24
- return libraries.map(l => new Library(this, l));
25
- });
26
- }
27
-
28
- /**
29
- * Get one firmware library object
30
- * @param {String} name Name of the library to fetch
31
- * @param {Object} query The query parameters for libraries. See Particle.getLibrary
32
- * @returns {Promise} A promise
33
- */
34
- library(name, query = {}){
35
- return this.api.getLibrary(Object.assign({}, query, { name, auth: this.auth }))
36
- .then(payload => {
37
- const library = payload.body.data || {};
38
- return new Library(this, library);
39
- });
40
- }
41
-
42
- /**
43
- * Get list of library versions
44
- * @param {String} name Name of the library to fetch
45
- * @param {Object} query The query parameters for versions. See Particle.getLibraryVersions
46
- * @returns {Promise} A promise
47
- */
48
- libraryVersions(name, query = {}){
49
- return this.api.getLibraryVersions(Object.assign({}, query, { name, auth: this.auth }))
50
- .then(payload => {
51
- const libraries = payload.body.data || [];
52
- return libraries.map(l => new Library(this, l));
53
- });
54
- }
55
-
56
- /**
57
- * Contribute a new library version
58
- * @param {Buffer} archive The compressed archive with the library source
59
- * @returns {Promise} A promise
60
- */
61
- contributeLibrary(archive){
62
- return this.api.contributeLibrary({ archive, auth: this.auth })
63
- .then(payload => {
64
- const library = payload.body.data || {};
65
- return new Library(this, library);
66
- }, error => {
67
- this._throwError(error);
68
- });
69
- }
70
-
71
- /**
72
- * Make the the most recent private library version public
73
- * @param {string} name The name of the library to publish
74
- * @return {Promise} To publish the library
75
- */
76
- publishLibrary(name){
77
- return this.api.publishLibrary({ name, auth: this.auth })
78
- .then(payload => {
79
- const library = payload.body.data || {};
80
- return new Library(this, library);
81
- }, error => {
82
- this._throwError(error);
83
- });
84
- }
85
-
86
- /**
87
- * Delete an entire published library
88
- * @param {object} params Specific params of the library to delete
89
- * @param {string} params.name Name of the library to delete
90
- * @param {string} params.force Key to force deleting a public library
91
- * @returns {Promise} A promise
92
- */
93
- deleteLibrary({ name, force }){
94
- return this.api.deleteLibrary({ name, force, auth: this.auth })
95
- .then(() => true, error => this._throwError(error));
96
- }
97
-
98
- _throwError(error){
99
- if (error.body && error.body.errors){
100
- const errorMessages = error.body.errors.map((e) => e.message).join('\n');
101
- throw new Error(errorMessages);
102
- }
103
- throw error;
104
- }
105
-
106
- downloadFile(uri){
107
- return this.api.downloadFile({ uri });
108
- }
109
-
110
- /**
111
- * @param {Object} files Object containing files to be compiled
112
- * @param {Number} platformId Platform id number of the device you are compiling for
113
- * @param {String} targetVersion System firmware version to compile against
114
- * @returns {Promise} A promise
115
- * @deprecated Will be removed in 6.5
116
- */
117
- compileCode(files, platformId, targetVersion){
118
- return this.api.compileCode({ files, platformId, targetVersion, auth: this.auth });
119
- }
120
-
121
- /**
122
- * @param {object} params
123
- * @param {string} params.deviceId Device ID or Name
124
- * @param {boolean} params.signal Signal on or off
125
- * @returns {Promise} A promise
126
- * @deprecated Will be removed in 6.5
127
- */
128
- signalDevice({ signal, deviceId }){
129
- return this.api.signalDevice({ signal, deviceId, auth: this.auth });
130
- }
131
-
132
- /**
133
- * @returns {Promise} A promise
134
- * @deprecated Will be removed in 6.5
135
- */
136
- listDevices(){
137
- return this.api.listDevices({ auth: this.auth });
138
- }
139
-
140
- /**
141
- * @returns {Promise} A promise
142
- * @deprecated Will be removed in 6.5
143
- */
144
- listBuildTargets(){
145
- return this.api.listBuildTargets({ onlyFeatured: true, auth: this.auth })
146
- .then(payload => {
147
- const targets = [];
148
- for (const target of payload.body.targets){
149
- for (const platform of target.platforms){
150
- targets.push({
151
- version: target.version,
152
- platform: platform,
153
- prerelease: target.prereleases.indexOf(platform) > -1,
154
- firmware_vendor: target.firmware_vendor
155
- });
156
- }
157
- }
158
- return targets;
159
- }, () => {});
160
- }
161
-
162
- trackingIdentity({ full = false, context = undefined } = {}){
163
- return this.api.trackingIdentity({ full, context, auth: this.auth })
164
- .then(payload => {
165
- return payload.body;
166
- });
167
- }
168
- }
169
-
170
- module.exports = Client;
171
- Particle = require('./Particle'); // Move it to after the export to avoid issue with circular reference
package/src/Defaults.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
- module.exports = {
3
- baseUrl: 'https://api.particle.io',
4
- clientSecret: 'particle-api',
5
- clientId: 'particle-api',
6
- tokenDuration: 7776000, // 90 days
7
- auth: undefined
8
- };