particle-api-js 9.4.1 → 10.1.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 (51) hide show
  1. package/.circleci/config.yml +7 -5
  2. package/CHANGELOG.md +11 -0
  3. package/{test/EventStream-e2e-browser.html → EventStream-e2e-browser.html} +0 -1
  4. package/{test/EventStream-e2e-node.js → EventStream-e2e-node.js} +2 -3
  5. package/README.md +2 -2
  6. package/RELEASE.md +1 -1
  7. package/dist/particle.min.js +1 -399
  8. package/dist/particle.min.js.map +1 -1
  9. package/docs/api.md +5223 -115
  10. package/fs.js +2 -0
  11. package/karma.conf.js +18 -6
  12. package/package.json +23 -26
  13. package/src/Agent.js +407 -0
  14. package/src/Client.js +170 -0
  15. package/src/Defaults.js +7 -0
  16. package/src/EventStream.js +263 -0
  17. package/src/Library.js +33 -0
  18. package/src/Particle.js +2644 -0
  19. package/test/Agent.integration.js +5 -4
  20. package/test/Agent.spec.js +174 -291
  21. package/test/Client.spec.js +7 -7
  22. package/test/Defaults.spec.js +2 -2
  23. package/test/EventStream.spec.js +6 -4
  24. package/test/FakeAgent.js +2 -2
  25. package/test/Library.spec.js +2 -2
  26. package/test/Particle.integration.js +7 -7
  27. package/test/Particle.spec.js +332 -18
  28. package/test/fixtures/index.js +4 -18
  29. package/test/support/FixtureHttpServer.js +5 -3
  30. package/test/test-setup.js +5 -5
  31. package/tsconfig.json +14 -0
  32. package/webpack.config.js +45 -0
  33. package/.babelrc +0 -4
  34. package/lib/Agent.js +0 -516
  35. package/lib/Agent.js.map +0 -1
  36. package/lib/Client.js +0 -312
  37. package/lib/Client.js.map +0 -1
  38. package/lib/Defaults.js +0 -14
  39. package/lib/Defaults.js.map +0 -1
  40. package/lib/EventStream.js +0 -335
  41. package/lib/EventStream.js.map +0 -1
  42. package/lib/Library.js +0 -67
  43. package/lib/Library.js.map +0 -1
  44. package/lib/Particle.js +0 -3248
  45. package/lib/Particle.js.map +0 -1
  46. package/lib/superagent-binary-parser.js +0 -20
  47. package/lib/superagent-binary-parser.js.map +0 -1
  48. package/test/Client.integration.js +0 -69
  49. package/test/fixtures/tarball.tar.gz +0 -0
  50. package/test/fixtures/test-library-publish-0.0.1.tar.gz +0 -0
  51. package/test/fixtures/test-library-publish-0.0.2.tar.gz +0 -0
@@ -0,0 +1,2644 @@
1
+ const Defaults = require('./Defaults');
2
+ const EventStream = require('./EventStream');
3
+ const Agent = require('./Agent');
4
+ const Client = require('./Client');
5
+
6
+ // Hack to avoid importing the type on every @return statement
7
+ /**
8
+ * @typedef {import('./Agent').RequestResponse} RequestResponse
9
+ */
10
+ /**
11
+ * @typedef {import('./Agent').RequestError} RequestError
12
+ */
13
+
14
+ /**
15
+ * Particle Cloud API wrapper.
16
+ *
17
+ * See <https://docs.particle.io/reference/javascript/> for examples
18
+ * of using the `Particle` class.
19
+ *
20
+ * Most Particle methods take a single unnamed argument object documented as
21
+ * `options` with key/value pairs for each option.
22
+ */
23
+ class Particle {
24
+ /**
25
+ * Contructor for the Cloud API wrapper.
26
+ *
27
+ * Create a new Particle object and call methods below on it.
28
+ *
29
+ * @param {Object} options Options for this API call Options to be used for all requests (see [Defaults](../src/Defaults.js))
30
+ */
31
+ constructor(options = {}){
32
+ if (options.auth) {
33
+ this.setDefaultAuth(options.auth);
34
+ }
35
+
36
+ // todo - this seems a bit dangerous - would be better to put all options/context in a contained object
37
+ Object.assign(this, Defaults, options);
38
+ this.context = {};
39
+ this.agent = new Agent(this.baseUrl);
40
+ }
41
+
42
+ _isValidContext(name, context){
43
+ return (name==='tool' || name==='project') && context!==undefined;
44
+ }
45
+
46
+ setContext(name, context){
47
+ if (context!==undefined){
48
+ if (this._isValidContext(name, context)){
49
+ this.context[name] = context;
50
+ } else {
51
+ throw Error('unknown context name or undefined context: '+name);
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Builds the final context from the context parameter and the context items in the api.
58
+ * @param {Object} context The invocation context, this takes precedence over the local context.
59
+ * @returns {Object} The context to use.
60
+ * @private
61
+ */
62
+ _buildContext(context){
63
+ return Object.assign(this.context, context);
64
+ }
65
+
66
+ /**
67
+ * Login to Particle Cloud using an existing Particle acccount.
68
+ * @param {Object} options Options for this API call
69
+ * @param {String} options.username Username for the Particle account
70
+ * @param {String} options.password Password for the Particle account
71
+ * @param {Number} options.tokenDuration How long the access token should last in seconds
72
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
73
+ * @param {Number} [options.context] Request context
74
+ * @returns {Promise} A promise
75
+ */
76
+ // @ts-ignore
77
+ login({ username, password, tokenDuration = this.tokenDuration, headers, context }){
78
+ return this.request({
79
+ uri: '/oauth/token',
80
+ method: 'post',
81
+ headers,
82
+ form: {
83
+ username,
84
+ password,
85
+ grant_type: 'password',
86
+ // @ts-ignore
87
+ client_id: this.clientId,
88
+ // @ts-ignore
89
+ client_secret: this.clientSecret,
90
+ expires_in: tokenDuration
91
+ },
92
+ context
93
+ });
94
+ }
95
+
96
+ /**
97
+ * If login failed with an 'mfa_required' error, this must be called with a valid OTP code to login
98
+ * @param {Object} options Options for this API call
99
+ * @param {String} options.mfaToken Given as 'mfa_token' in the error body of `.login()`.
100
+ * @param {String} options.otp Current one-time-password generated from the authentication application
101
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
102
+ * @param {Number} [options.context] Request context
103
+ * @returns {Promise} A promise
104
+ */
105
+ sendOtp({ mfaToken, otp, headers, context }){
106
+ return this.request({
107
+ uri: '/oauth/token',
108
+ method: 'post',
109
+ headers,
110
+ form: {
111
+ grant_type: 'urn:custom:mfa-otp',
112
+ mfa_token: mfaToken,
113
+ otp,
114
+ // @ts-ignore
115
+ client_id: this.clientId,
116
+ // @ts-ignore
117
+ client_secret: this.clientSecret
118
+ },
119
+ context
120
+ });
121
+ }
122
+
123
+ /**
124
+ * Enable MFA on the currently logged in user
125
+ * @param {Object} options Options for this API call
126
+ * @param {Object} options.auth Access token
127
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
128
+ * @param {Object} [options.context] Request context
129
+ * @returns {Promise} A promise
130
+ */
131
+ enableMfa({ auth, headers, context }){
132
+ return this.get({ uri: '/v1/user/mfa-enable', auth, headers, context });
133
+ }
134
+
135
+ /**
136
+ * Confirm MFA for the user. This must be called with current TOTP code, determined from the results of enableMfa(). You will be prompted to enter an OTP code every time you login after enrollment is confirmed.
137
+ * @param {Object} options Options for this API call
138
+ * @param {Object} options.auth Access token
139
+ * @param {Object} options.mfaToken Token given from previous step to
140
+ * @param {Object} options.otp Current one-time-password generated from the authentication app
141
+ * @param {Boolean} options.invalidateTokens Should all tokens be invalidated
142
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
143
+ * @param {Object} [options.context] Request context
144
+ * @returns {Promise} A promise
145
+ */
146
+ confirmMfa({ mfaToken, otp, invalidateTokens = false, auth, headers, context }){
147
+ let data = { mfa_token: mfaToken, otp };
148
+
149
+ if (invalidateTokens) {
150
+ data.invalidate_tokens = true;
151
+ }
152
+
153
+ return this.post({
154
+ uri: '/v1/user/mfa-enable',
155
+ auth,
156
+ headers,
157
+ data,
158
+ context
159
+ });
160
+ }
161
+
162
+ /**
163
+ * Disable MFA for the user.
164
+ * @param {Object} options Options for this API call
165
+ * @param {Object} options.auth Access token
166
+ * @param {Object} options.currentPassword User's current password
167
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
168
+ * @param {Object} [options.context] Request context
169
+ * @returns {Promise} A promise
170
+ */
171
+ disableMfa({ currentPassword, auth, headers, context }){
172
+ return this.put({
173
+ uri: '/v1/user/mfa-disable',
174
+ auth,
175
+ headers,
176
+ data: { current_password: currentPassword },
177
+ context
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Create Customer for Product.
183
+ * @param {Object} options Options for this API call
184
+ * @param {String} options.email Username for the Particle account
185
+ * @param {String} options.password Password for the Particle account
186
+ * @param {String} options.product Create the customer in this product ID or slug
187
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
188
+ * @param {Object} [options.context] Request context
189
+ * @returns {Promise} A promise
190
+ */
191
+ createCustomer({ email, password, product, headers, context }){
192
+ return this.request({
193
+ uri: `/v1/products/${product}/customers`,
194
+ method: 'post',
195
+ headers,
196
+ form: {
197
+ email,
198
+ password,
199
+ grant_type: 'client_credentials',
200
+ // @ts-ignore
201
+ client_id: this.clientId,
202
+ // @ts-ignore
203
+ client_secret: this.clientSecret
204
+ },
205
+ context
206
+ });
207
+ }
208
+
209
+ /**
210
+ * Login to Particle Cloud using an OAuth client.
211
+ * @param {Object} options Options for this API call
212
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
213
+ * @param {Object} [options.context] Request context
214
+ * @returns {Promise} A promise
215
+ */
216
+ loginAsClientOwner({ headers, context }){
217
+ return this.request({
218
+ uri: '/oauth/token',
219
+ method: 'post',
220
+ headers,
221
+ form: {
222
+ grant_type: 'client_credentials',
223
+ // @ts-ignore
224
+ client_id: this.clientId,
225
+ // @ts-ignore
226
+ client_secret: this.clientSecret
227
+ },
228
+ context
229
+ });
230
+ }
231
+
232
+ /**
233
+ * Create a user account for the Particle Cloud
234
+ * @param {Object} options Options for this API call
235
+ * @param {String} options.username Email of the new user
236
+ * @param {String} options.password Password
237
+ * @param {String} options.accountInfo Object that contains account information fields such as user real name, company name, business account flag etc
238
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
239
+ * @param {Object} [options.context] Request context
240
+ * @returns {Promise} A promise
241
+ */
242
+ createUser({ username, password, accountInfo, headers, context }){
243
+ return this.post({
244
+ uri: '/v1/users',
245
+ headers,
246
+ data: {
247
+ username,
248
+ password,
249
+ account_info : accountInfo
250
+ },
251
+ context
252
+ });
253
+ }
254
+
255
+ /**
256
+ * Verify new user account via verification email
257
+ * @param {Object} options Options for this API call
258
+ * @param {String} options.token The string token sent in the verification email
259
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
260
+ * @param {Object} [options.context] Request context
261
+ * @returns {Promise} A promise
262
+ */
263
+ verifyUser({ token, headers, context }){
264
+ return this.post({
265
+ uri: '/v1/user/verify',
266
+ headers,
267
+ data: { token },
268
+ context
269
+ });
270
+ }
271
+
272
+ /**
273
+ * Send reset password email for a Particle Cloud user account
274
+ * @param {Object} options Options for this API call
275
+ * @param {String} options.username Email of the user
276
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
277
+ * @param {Object} [options.context] Request context
278
+ * @returns {Promise} A promise
279
+ */
280
+ resetPassword({ username, headers, context }){
281
+ return this.post({
282
+ uri: '/v1/user/password-reset',
283
+ headers,
284
+ data: { username },
285
+ context
286
+ });
287
+ }
288
+
289
+ /**
290
+ * Revoke an access token
291
+ * @param {Object} options Options for this API call
292
+ * @param {String} options.username Username of the Particle cloud account that the token belongs to.
293
+ * @param {String} options.password Password for the account
294
+ * @param {String} options.token Access token you wish to revoke
295
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
296
+ * @param {Object} [options.context] Request context
297
+ * @returns {Promise} A promise
298
+ */
299
+ deleteAccessToken({ username, password, token, headers, context }){
300
+ return this.delete({
301
+ uri: `/v1/access_tokens/${token}`,
302
+ auth: { username, password },
303
+ headers,
304
+ data: { access_token: token },
305
+ context
306
+ });
307
+ }
308
+
309
+ /**
310
+ * Revoke the current session access token
311
+ * @param {Object} options Options for this API call
312
+ * @param {String} options.auth Access Token
313
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
314
+ * @param {Object} [options.context] Request context
315
+ * @returns {Promise} A promise
316
+ */
317
+ deleteCurrentAccessToken({ auth, headers, context }){
318
+ return this.delete({
319
+ uri: '/v1/access_tokens/current',
320
+ auth,
321
+ headers,
322
+ context
323
+ });
324
+ }
325
+
326
+ /**
327
+ * Revoke all active access tokens
328
+ * @param {Object} options Options for this API call
329
+ * @param {String} options.auth Access Token
330
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
331
+ * @param {Object} [options.context] Request context
332
+ * @returns {Promise} A promise
333
+ */
334
+ deleteActiveAccessTokens({ auth, headers, context }){
335
+ return this.delete({
336
+ uri: '/v1/access_tokens',
337
+ auth,
338
+ headers,
339
+ context
340
+ });
341
+ }
342
+
343
+ /**
344
+ * Delete the current user
345
+ * @param {Object} options Options for this API call
346
+ * @param {String} options.auth Access Token
347
+ * @param {String} options.password Password
348
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
349
+ * @param {Object} [options.context] Request context
350
+ * @returns {Promise} A promise
351
+ */
352
+ deleteUser({ auth, password, headers, context }){
353
+ return this.delete({
354
+ uri: '/v1/user',
355
+ data: { password },
356
+ auth,
357
+ headers,
358
+ context
359
+ });
360
+ }
361
+
362
+ /**
363
+ * List all valid access tokens for a Particle Cloud account
364
+ * @param {Object} options Options for this API call
365
+ * @param {String} options.username Username
366
+ * @param {String} options.password Password
367
+ * @param {String} options.otp Current one-time-password generated from the authentication application
368
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
369
+ * @param {Object} [options.context] Request context
370
+ * @returns {Promise} A promise
371
+ */
372
+ listAccessTokens({ username, password, otp, headers, context }){
373
+ return this.get({
374
+ uri: '/v1/access_tokens',
375
+ auth: { username, password },
376
+ query: otp ? { otp } : undefined,
377
+ headers,
378
+ context
379
+ });
380
+ }
381
+
382
+ /**
383
+ * Retrieves the information that is used to identify the current login for tracking.
384
+ * @param {Object} [options] Options for this API call
385
+ * @param {String} [options.auth] The access token
386
+ * @param {Boolean} [options.full] When true, retrieve all information for registering a user with the tracking API. When false,
387
+ * retrieve only the unique tracking ID for the current login.
388
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
389
+ * @param {Object} [options.context] Request context
390
+ * @returns {Promise<Object>} Resolve the tracking identify of the current login
391
+ */
392
+ trackingIdentity({ full = false, auth, headers, context } = {}){
393
+ return this.get({
394
+ uri: '/v1/user/identify',
395
+ auth,
396
+ headers,
397
+ query: (full ? undefined : { tracking: 1 }),
398
+ context
399
+ });
400
+ }
401
+
402
+ /**
403
+ * List devices claimed to the account or product
404
+ * @param {Object} options Options for this API call
405
+ * @param {String} [options.deviceId] (Product only) Filter results to devices with this ID (partial matching)
406
+ * @param {String} [options.deviceName] (Product only) Filter results to devices with this name (partial matching)
407
+ * @param {Array.<string>} [options.groups] (Product only) A list of full group names to filter results to devices belonging to these groups only.
408
+ * @param {String} [options.sortAttr] (Product only) The attribute by which to sort results. See API docs for options.
409
+ * @param {String} [options.sortDir] (Product only) The direction of sorting. See API docs for options.
410
+ * @param {Number} [options.page] (Product only) Current page of results
411
+ * @param {Number} [options.perPage] (Product only) Records per page
412
+ * @param {String} [options.product] List devices in this product ID or slug
413
+ * @param {String} options.auth Access Token
414
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
415
+ * @param {Object} [options.context] Request context
416
+ * @returns {Promise} A promise
417
+ */
418
+ listDevices({ deviceId, deviceName, groups, sortAttr, sortDir, page, perPage, product, auth, headers, context }){
419
+ let uri, query;
420
+
421
+ if (product){
422
+ uri = `/v1/products/${product}/devices`;
423
+ query = {
424
+ deviceId,
425
+ deviceName,
426
+ groups: Array.isArray(groups) ? groups.join(',') : undefined,
427
+ sortAttr,
428
+ sortDir,
429
+ page,
430
+ per_page: perPage
431
+ };
432
+ } else {
433
+ uri = '/v1/devices';
434
+ }
435
+
436
+ return this.get({ uri, auth, headers, query, context });
437
+ }
438
+
439
+ /**
440
+ * Get detailed informationa about a device
441
+ * @param {Object} options Options for this API call
442
+ * @param {String} options.deviceId Device ID or Name
443
+ * @param {String} [options.product] Device in this product ID or slug
444
+ * @param {String} options.auth Access token
445
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
446
+ * @param {Object} [options.context] Request context
447
+ * @returns {Promise} A promise
448
+ */
449
+ getDevice({ deviceId, product, auth, headers, context }){
450
+ const uri = this.deviceUri({ deviceId, product });
451
+ return this.get({ uri, auth, headers, context });
452
+ }
453
+
454
+ /**
455
+ * Claim a device to the account. The device must be online and unclaimed.
456
+ * @param {Object} options Options for this API call
457
+ * @param {String} options.deviceId Device ID
458
+ * @param {String} options.auth Access Token
459
+ * @param {boolean} options.requestTransfer True to request the device be transfered from another user
460
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
461
+ * @param {Object} [options.context] Request context
462
+ * @returns {Promise} A promise
463
+ */
464
+ claimDevice({ deviceId, requestTransfer, auth, headers, context }){
465
+ return this.post({
466
+ uri: '/v1/devices',
467
+ auth,
468
+ headers,
469
+ data: {
470
+ id: deviceId,
471
+ request_transfer: !!requestTransfer
472
+ },
473
+ context
474
+ });
475
+ }
476
+
477
+ /**
478
+ * Add a device to a product or move device out of quarantine.
479
+ * @param {Object} options Options for this API call
480
+ * @param {String} options.deviceId Device ID
481
+ * @param {Object} options.file A file that contains a single-column list of device IDs, device serial numbers, device IMEIs, or devie ICCIDs.
482
+ * Node: Either a path or Buffer. Browser: a File or Blob.
483
+ * @param {String} options.product Add to this product ID or slug
484
+ * @param {String} options.auth Access Token
485
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
486
+ * @param {Object} [options.context] Request context
487
+ * @returns {Promise} A promise
488
+ */
489
+ addDeviceToProduct({ deviceId, product, file, auth, headers, context }){
490
+ let files, data;
491
+
492
+ if (file){
493
+ files = { file };
494
+ } else if (deviceId){
495
+ data = { id: deviceId };
496
+ }
497
+
498
+ return this.request({
499
+ uri: `/v1/products/${product}/devices`,
500
+ method: 'post',
501
+ headers,
502
+ data,
503
+ files,
504
+ auth,
505
+ context
506
+ });
507
+ }
508
+
509
+ /**
510
+ * Unclaim / Remove a device from your account or product, or deny quarantine
511
+ * @param {Object} options Options for this API call
512
+ * @param {String} options.deviceId Device ID or Name
513
+ * @param {Boolean} [options.deny] (Product only) Deny this quarantined device, instead of removing an already approved device
514
+ * @param {String} options.product Remove from this product ID or slug
515
+ * @param {String} options.auth Access Token
516
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
517
+ * @param {Object} [options.context] Request context
518
+ * @returns {Promise} A promise
519
+ */
520
+ removeDevice({ deviceId, deny, product, auth, headers, context }){
521
+ const uri = this.deviceUri({ deviceId, product });
522
+ const data = product ? { deny } : undefined;
523
+ return this.delete({ uri, data, auth, headers, context });
524
+ }
525
+
526
+ /**
527
+ * Unclaim a product device its the owner, but keep it in the product
528
+ * @param {Object} options Options for this API call
529
+ * @param {String} options.deviceId Device ID or Name
530
+ * @param {String} options.product Remove from this product ID or slug
531
+ * @param {String} options.auth Access Token
532
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
533
+ * @param {Object} [options.context] Request context
534
+ * @returns {Promise} A promise
535
+ */
536
+ removeDeviceOwner({ deviceId, product, auth, headers, context }){
537
+ const uri = `/v1/products/${product}/devices/${deviceId}/owner`;
538
+ return this.delete({ uri, auth, headers, context });
539
+ }
540
+
541
+ /**
542
+ * Rename a device
543
+ * @param {Object} options Options for this API call
544
+ * @param {String} options.deviceId Device ID or Name
545
+ * @param {String} options.name Desired Name
546
+ * @param {String} [options.product] Rename device in this product ID or slug
547
+ * @param {String} options.auth Access Token
548
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
549
+ * @param {Object} [options.context] Request context
550
+ * @returns {Promise} A promise
551
+ */
552
+ renameDevice({ deviceId, name, product, auth, headers, context }){
553
+ return this.updateDevice({ deviceId, name, product, auth, headers, context });
554
+ }
555
+
556
+ /**
557
+ * Instruct the device to turn on/off the LED in a rainbow pattern
558
+ * @param {Object} options Options for this API call
559
+ * @param {String} options.deviceId Device ID or Name
560
+ * @param {Boolean} options.signal Signal on or off
561
+ * @param {String} [options.product] Device in this product ID or slug
562
+ * @param {String} options.auth Access Token
563
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
564
+ * @param {Object} [options.context] Request context
565
+ * @returns {Promise} A promise
566
+ */
567
+ signalDevice({ deviceId, signal, product, auth, headers, context }){
568
+ return this.updateDevice({ deviceId, signal, product, auth, headers, context });
569
+ }
570
+
571
+ /**
572
+ * Store some notes about device
573
+ * @param {Object} options Options for this API call
574
+ * @param {String} options.deviceId Device ID or Name
575
+ * @param {String} options.notes Your notes about this device
576
+ * @param {String} [options.product] Device in this product ID or slug
577
+ * @param {String} options.auth Access Token
578
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
579
+ * @param {Object} [options.context] Request context
580
+ * @returns {Promise} A promise
581
+ */
582
+ setDeviceNotes({ deviceId, notes, product, auth, headers, context }){
583
+ return this.updateDevice({ deviceId, notes, product, auth, headers, context });
584
+ }
585
+
586
+ /**
587
+ * Mark device as being used in development of a product so it opts out of automatic firmware updates
588
+ * @param {Object} options Options for this API call
589
+ * @param {String} options.deviceId Device ID or Name
590
+ * @param {Boolean} options.development Set to true to mark as development, false to return to product fleet
591
+ * @param {String} options.product Device in this product ID or slug
592
+ * @param {String} options.auth Access Token
593
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
594
+ * @param {Object} [options.context] Request context
595
+ * @returns {Promise} A promise
596
+ */
597
+ markAsDevelopmentDevice({ deviceId, development = true, product, auth, headers, context }){
598
+ return this.updateDevice({ deviceId, development, product, auth, headers, context });
599
+ }
600
+
601
+ /**
602
+ * Mark device as being used in development of a product so it opts out of automatic firmware updates
603
+ * @param {Object} options Options for this API call
604
+ * @param {String} options.deviceId Device ID or Name
605
+ * @param {Number} options.desiredFirmwareVersion Lock the product device to run this firmware version.
606
+ * @param {Boolean} [options.flash] Immediately flash firmware indicated by desiredFirmwareVersion
607
+ * @param {String} options.product Device in this product ID or slug
608
+ * @param {String} options.auth Access Token
609
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
610
+ * @param {Object} [options.context] Request context
611
+ * @returns {Promise} A promise
612
+ */
613
+ lockDeviceProductFirmware({ deviceId, desiredFirmwareVersion, flash, product, auth, context }){
614
+ return this.updateDevice({ deviceId, desiredFirmwareVersion, flash, product, auth, context });
615
+ }
616
+
617
+ /**
618
+ * Mark device as receiving automatic firmware updates
619
+ * @param {Object} options Options for this API call
620
+ * @param {String} options.deviceId Device ID or Name
621
+ * @param {String} options.product Device in this product ID or slug
622
+ * @param {String} options.auth Access Token
623
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
624
+ * @param {Object} [options.context] Request context
625
+ * @returns {Promise} A promise
626
+ */
627
+ unlockDeviceProductFirmware({ deviceId, product, auth, headers, context }){
628
+ return this.updateDevice({ deviceId, desiredFirmwareVersion: null, product, auth, headers, context });
629
+ }
630
+
631
+ /**
632
+ * Update multiple device attributes at the same time
633
+ * @param {Object} options Options for this API call
634
+ * @param {String} options.deviceId Device ID or Name
635
+ * @param {String} [options.name] Desired Name
636
+ * @param {Boolean} [options.signal] Signal device on or off
637
+ * @param {String} [options.notes] Your notes about this device
638
+ * @param {Boolean} [options.development] (Product only) Set to true to mark as development, false to return to product fleet
639
+ * @param {Number} [options.desiredFirmwareVersion] (Product only) Lock the product device to run this firmware version.
640
+ * Pass `null` to unlock firmware and go back to released firmware.
641
+ * @param {Boolean} [options.flash] (Product only) Immediately flash firmware indicated by desiredFirmwareVersion
642
+ * @param {String} [options.product] Device in this product ID or slug
643
+ * @param {String} options.auth Access Token
644
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
645
+ * @param {Object} [options.context] Request context
646
+ * @returns {Promise} A promise
647
+ */
648
+ updateDevice({ deviceId, name, signal, notes, development, desiredFirmwareVersion, flash, product, auth, headers, context }){
649
+ let signalValue;
650
+ if (signal !== undefined){
651
+ signalValue = signal ? '1' : '0';
652
+ }
653
+
654
+ const uri = this.deviceUri({ deviceId, product });
655
+ const data = product ?
656
+ { name, signal: signalValue, notes, development, desired_firmware_version: desiredFirmwareVersion, flash } :
657
+ { name, signal: signalValue, notes };
658
+
659
+ return this.put({ uri, auth, headers, data, context });
660
+ }
661
+
662
+ /**
663
+ * Provision a new device for products that allow self-provisioning
664
+ * @param {Object} options Options for this API call
665
+ * @param {String} options.productId Product ID where to create this device
666
+ * @param {String} options.auth Access Token
667
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
668
+ * @param {Object} [options.context] Request context
669
+ * @returns {Promise} A promise
670
+ */
671
+ provisionDevice({ productId, auth, headers, context }){
672
+ return this.post({
673
+ uri: '/v1/devices',
674
+ auth,
675
+ headers,
676
+ data: { product_id: productId },
677
+ context
678
+ });
679
+ }
680
+
681
+ /**
682
+ * Generate a claim code to use in the device claiming process.
683
+ * To generate a claim code for a product, the access token MUST belong to a
684
+ * customer of the product.
685
+ * @param {Object} options Options for this API call
686
+ * @param {String} [options.iccid] ICCID of the SIM card used in the Electron
687
+ * @param {String} [options.product] Device in this product ID or slug
688
+ * @param {String} options.auth Access Token
689
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
690
+ * @param {Object} [options.context] Request context
691
+ * @returns {Promise} A promise
692
+ */
693
+ getClaimCode({ iccid, product, auth, headers, context }){
694
+ const uri = product ? `/v1/products/${product}/device_claims` : '/v1/device_claims';
695
+ return this.post({ uri, auth, headers, data: { iccid }, context });
696
+ }
697
+
698
+ validatePromoCode({ promoCode, auth, headers, context }){
699
+ return this.get({
700
+ uri: `/v1/promo_code/${promoCode}`,
701
+ auth,
702
+ headers,
703
+ context
704
+ });
705
+ }
706
+
707
+ changeProduct({ deviceId, productId, auth, headers, context }){
708
+ return this.put({
709
+ uri: `/v1/devices/${deviceId}`,
710
+ auth,
711
+ headers,
712
+ data: { product_id: productId },
713
+ context
714
+ });
715
+ }
716
+
717
+ /**
718
+ * Get the value of a device variable
719
+ * @param {Object} options Options for this API call
720
+ * @param {String} options.deviceId Device ID or Name
721
+ * @param {String} options.name Variable name
722
+ * @param {String} [options.product] Device in this product ID or slug
723
+ * @param {String} options.auth Access Token
724
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
725
+ * @param {Object} [options.context] Request context
726
+ * @returns {Promise} A promise
727
+ */
728
+ getVariable({ deviceId, name, product, auth, headers, context }){
729
+ const uri = product ?
730
+ `/v1/products/${product}/devices/${deviceId}/${name}` :
731
+ `/v1/devices/${deviceId}/${name}`;
732
+
733
+ return this.get({ uri, auth, headers, context });
734
+ }
735
+
736
+ /**
737
+ * Compile and flash application firmware to a device. Pass a pre-compiled binary to flash it directly to the device.
738
+ * @param {Object} options Options for this API call
739
+ * @param {String} options.deviceId Device ID or Name
740
+ * @param {String} options.product Flash device in this product ID or slug
741
+ * @param {Object} options.files Object containing files to be compiled and flashed. Keys should be the filenames, including relative path, and the values should be a path or Buffer of the file contents in Node, or a File or Blob in the browser.
742
+ * @param {String} [options.targetVersion=latest] System firmware version to compile against
743
+ * @param {String} options.auth Access Token
744
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
745
+ * @param {Object} [options.context] Request context
746
+ * @returns {Promise} A promise
747
+ */
748
+ flashDevice({ deviceId, product, files, targetVersion, auth, headers, context }){
749
+ const uri = this.deviceUri({ deviceId, product });
750
+ const form = {};
751
+
752
+ if (targetVersion){
753
+ form.build_target_version = targetVersion;
754
+ } else {
755
+ form.latest = 'true';
756
+ }
757
+
758
+ return this.request({ uri, method: 'put', auth, headers, files, form, context });
759
+ }
760
+
761
+ /**
762
+ * DEPRECATED: Flash the Tinker application to a device. Instead compile and flash the Tinker source code.
763
+ * @param {Object} options Options for this API call
764
+ * @param {String} options.deviceId Device ID or Name
765
+ * @param {String} options.auth Access Token
766
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
767
+ * @param {Object} [options.context] Request context
768
+ * @returns {Promise} A promise
769
+ */
770
+ flashTinker({ deviceId, auth, headers, context }){
771
+ /* eslint-disable no-console */
772
+ /* @ts-ignore */
773
+ if (console && console.warning){
774
+ // @ts-ignore
775
+ console.warning('Particle.flashTinker is deprecated');
776
+ }
777
+ /* eslint-enable no-console */
778
+ return this.put({
779
+ uri: `/v1/devices/${deviceId}`,
780
+ headers,
781
+ data: { app: 'tinker' },
782
+ auth,
783
+ context
784
+ });
785
+ }
786
+
787
+ /**
788
+ * Compile firmware using the Particle Cloud
789
+ * @param {Object} options Options for this API call
790
+ * @param {Object} options.files Object containing files to be compiled. Keys should be the filenames, including relative path, and the values should be a path or Buffer of the file contents in Node, or a File or Blob in the browser.
791
+ * @param {Number} [options.platformId] Platform id number of the device you are compiling for. Common values are 0=Core, 6=Photon, 10=Electron.
792
+ * @param {String} [options.targetVersion=latest] System firmware version to compile against
793
+ * @param {String} options.auth Access Token
794
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
795
+ * @param {Object} [options.context] Request context
796
+ * @returns {Promise} A promise
797
+ */
798
+ compileCode({ files, platformId, targetVersion, auth, headers, context }){
799
+ const form = { platform_id: platformId };
800
+
801
+ if (targetVersion){
802
+ form.build_target_version = targetVersion;
803
+ } else {
804
+ form.latest = 'true';
805
+ }
806
+
807
+ return this.request({
808
+ uri: '/v1/binaries',
809
+ method: 'post',
810
+ auth,
811
+ headers,
812
+ files,
813
+ form,
814
+ context
815
+ });
816
+ }
817
+
818
+ /**
819
+ * Download a firmware binary
820
+ * @param {Object} options Options for this API call
821
+ * @param {String} options.binaryId Binary ID received from a successful compile call
822
+ * @param {String} options.auth Access Token
823
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
824
+ * @param {Object} [options.context] Request context
825
+ * @returns {Promise<RequestResponse, RequestError>} A promise
826
+ */
827
+ downloadFirmwareBinary({ binaryId, auth, headers, context }){
828
+ return this.request({
829
+ uri: `/v1/binaries/${binaryId}`,
830
+ method: 'get',
831
+ auth,
832
+ headers,
833
+ context,
834
+ isBuffer: true
835
+ });
836
+ }
837
+
838
+ /**
839
+ * Send a new device public key to the Particle Cloud
840
+ * @param {Object} options Options for this API call
841
+ * @param {String} options.deviceId Device ID or Name
842
+ * @param {(String|Buffer)} options.key Public key contents
843
+ * @param {String} [options.algorithm=rsa] Algorithm used to generate the public key. Valid values are `rsa` or `ecc`.
844
+ * @param {String} options.auth Access Token
845
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
846
+ * @param {Object} [options.context] Request context
847
+ * @returns {Promise} A promise
848
+ */
849
+ sendPublicKey({ deviceId, key, algorithm, auth, headers, context }){
850
+ return this.post({
851
+ uri: `/v1/provisioning/${deviceId}`,
852
+ auth,
853
+ headers,
854
+ data: {
855
+ deviceID: deviceId,
856
+ publicKey: ( typeof key === 'string' ? key : key.toString() ),
857
+ filename: 'particle-api',
858
+ order: `manual_${ Date.now() }`,
859
+ algorithm: algorithm || 'rsa'
860
+ },
861
+ context
862
+ });
863
+ }
864
+
865
+ /**
866
+ * Call a device function
867
+ * @param {Object} options Options for this API call
868
+ * @param {String} options.deviceId Device ID or Name
869
+ * @param {String} options.name Function name
870
+ * @param {String} options.argument Function argument
871
+ * @param {String} [options.product] Device in this product ID or slug
872
+ * @param {String} options.auth Access Token
873
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
874
+ * @param {Object} [options.context] Request context
875
+ * @returns {Promise} A promise
876
+ */
877
+ callFunction({ deviceId, name, argument, product, auth, headers, context }){
878
+ const uri = product ?
879
+ `/v1/products/${product}/devices/${deviceId}/${name}` :
880
+ `/v1/devices/${deviceId}/${name}`;
881
+ return this.post({ uri, auth, headers, data: { args: argument }, context });
882
+ }
883
+
884
+ /**
885
+ * Get a stream of events
886
+ * @param {Object} options Options for this API call
887
+ * @param {String} [options.deviceId] Device ID or Name, or `mine` to indicate only your devices.
888
+ * @param {String} [options.name] Event Name
889
+ * @param {String} [options.org] Organization Slug
890
+ * @param {String} [options.product] Events for this product ID or slug
891
+ * @param {String} options.auth Access Token
892
+ * @returns {Promise} If the promise resolves, the resolution value will be an EventStream object that will
893
+ * emit 'event' events.
894
+ */
895
+ getEventStream({ deviceId, name, org, product, auth }){
896
+ let uri = '/v1/';
897
+ if (org){
898
+ uri += `orgs/${org}/`;
899
+ }
900
+
901
+ if (product){
902
+ uri += `products/${product}/`;
903
+ }
904
+
905
+ if (deviceId){
906
+ uri += 'devices/';
907
+ if (!(deviceId.toLowerCase() === 'mine')){
908
+ uri += `${deviceId}/`;
909
+ }
910
+ }
911
+
912
+ uri += 'events';
913
+
914
+ if (name){
915
+ uri += `/${encodeURIComponent(name)}`;
916
+ }
917
+
918
+ auth = this._getActiveAuthToken(auth);
919
+ return new EventStream(`${this.baseUrl}${uri}`, auth).connect();
920
+ }
921
+
922
+ /**
923
+ * Publish a event to the Particle Cloud
924
+ * @param {Object} options Options for this API call
925
+ * @param {String} options.name Event name
926
+ * @param {String} options.data Event data
927
+ * @param {Boolean} options.isPrivate Should the event be publicly available?
928
+ * @param {String} [options.product] Event for this product ID or slug
929
+ * @param {String} options.auth Access Token
930
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
931
+ * @param {Object} [options.context] Request context
932
+ * @returns {Promise} A promise
933
+ */
934
+ publishEvent({ name, data, isPrivate, product, auth, headers, context }){
935
+ const uri = product ? `/v1/products/${product}/events` : '/v1/devices/events';
936
+ const postData = { name, data, private: isPrivate };
937
+ return this.post({ uri, auth, headers, data: postData, context });
938
+ }
939
+
940
+ /**
941
+ * Create a webhook
942
+ * @param {Object} options Options for this API call
943
+ * @param {String} options.event The name of the Particle event that should trigger the Webhook
944
+ * @param {String} options.url The web address that will be targeted when the Webhook is triggered
945
+ * @param {String} [options.device] Trigger Webhook only for this device ID or Name
946
+ * @param {Boolean} [options.rejectUnauthorized] Set to `false` to skip SSL certificate validation of the target URL
947
+ * @param {Boolean} [options.noDefaults] Don't include default event data in the webhook request
948
+ * @param {Object} [options.hook] Webhook configuration settings
949
+ * @param {String} [options.hook.method=POST] Type of web request triggered by the Webhook (GET, POST, PUT, or DELETE)
950
+ * @param {Object} [options.hook.auth] Auth data like `{ username: 'me', password: '1234' }` to send via basic auth header with the Webhook request
951
+ * @param {Object} [options.hook.headers] Additional headers to add to the Webhook like `{ 'X-ONE': '1', X-TWO: '2' }`
952
+ * @param {Object} [options.hook.query] Query params to add to the Webhook request like `{ foo: 'foo', bar: 'bar' }`
953
+ * @param {Object} [options.hook.json] JSON data to send with the Webhook request - sets `Content-Type` to `application/json`
954
+ * @param {Object} [options.hook.form] Form data to send with the Webhook request - sets `Content-Type` to `application/x-www-form-urlencoded`
955
+ * @param {String} [options.hook.body] Custom body to send with the Webhook request
956
+ * @param {Object} [options.hook.responseTemplate] Template to use to customize the Webhook response body
957
+ * @param {Object} [options.hook.responseEvent] The Webhook response event name that your devices can subscribe to
958
+ * @param {Object} [options.hook.errorResponseEvent] The Webhook error response event name that your devices can subscribe to
959
+ * @param {String} [options.product] Webhook for this product ID or slug
960
+ * @param {String} options.auth Access Token
961
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
962
+ * @param {Object} [options.context] Request context
963
+ * @returns {Promise} A promise
964
+ */
965
+ createWebhook({ event, url, device, rejectUnauthorized, noDefaults, hook, product, auth, headers, context }){
966
+ const uri = product ? `/v1/products/${product}/webhooks` : '/v1/webhooks';
967
+ const data = { event, url, deviceId: device, rejectUnauthorized, noDefaults };
968
+
969
+ if (hook){
970
+ data.requestType = hook.method;
971
+ data.auth = hook.auth;
972
+ data.headers = hook.headers;
973
+ data.query = hook.query;
974
+ data.json = hook.json;
975
+ data.form = hook.form;
976
+ data.body = hook.body;
977
+ data.responseTemplate = hook.responseTemplate;
978
+ data.responseTopic = hook.responseEvent;
979
+ data.errorResponseTopic = hook.errorResponseEvent;
980
+ }
981
+
982
+ if (!data.requestType){
983
+ data.requestType = 'POST';
984
+ }
985
+
986
+ return this.post({ uri, auth, headers, data, context });
987
+ }
988
+
989
+ /**
990
+ * Delete a webhook
991
+ * @param {Object} options Options for this API call
992
+ * @param {String} options.hookId Webhook ID
993
+ * @param {String} [options.product] Webhook for this product ID or slug
994
+ * @param {String} options.auth Access Token
995
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
996
+ * @param {Object} [options.context] Request context
997
+ * @returns {Promise} A promise
998
+ */
999
+ deleteWebhook({ hookId, product, auth, headers, context }){
1000
+ const uri = product ? `/v1/products/${product}/webhooks/${hookId}` : `/v1/webhooks/${hookId}`;
1001
+ return this.delete({ uri, auth, headers, context });
1002
+ }
1003
+
1004
+ /**
1005
+ * List all webhooks owned by the account or product
1006
+ * @param {Object} options Options for this API call
1007
+ * @param {String} [options.product] Webhooks for this product ID or slug
1008
+ * @param {String} options.auth Access Token
1009
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1010
+ * @param {Object} [options.context] Request context
1011
+ * @returns {Promise} A promise
1012
+ */
1013
+ listWebhooks({ product, auth, headers, context }){
1014
+ const uri = product ? `/v1/products/${product}/webhooks` : '/v1/webhooks';
1015
+ return this.get({ uri, auth, headers, context });
1016
+ }
1017
+
1018
+ /**
1019
+ * Create an integration to send events to an external service
1020
+ *
1021
+ * See the API docs for details https://docs.particle.io/reference/api/#integrations-webhooks-
1022
+ *
1023
+ * @param {Object} options Options for this API call
1024
+ * @param {String} options.event Event that triggers the integration
1025
+ * @param {Object} options.settings Settings specific to that integration type
1026
+ * @param {String} [options.deviceId] Trigger integration only for this device ID or Name
1027
+ * @param {String} [options.product] Integration for this product ID or slug
1028
+ * @param {String} options.auth Access Token
1029
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1030
+ * @param {Object} [options.context] Request context
1031
+ * @returns {Promise} A promise
1032
+ */
1033
+ createIntegration({ event, settings, deviceId, product, auth, headers, context }){
1034
+ const uri = product ? `/v1/products/${product}/integrations` : '/v1/integrations';
1035
+ const data = Object.assign({ event, deviceid: deviceId }, settings);
1036
+ return this.post({ uri, data, auth, headers, context });
1037
+ }
1038
+
1039
+ /**
1040
+ * Edit an integration to send events to an external service
1041
+ *
1042
+ * See the API docs for details https://docs.particle.io/reference/api/#integrations-webhooks-
1043
+ *
1044
+ * @param {Object} options Options for this API call
1045
+ * @param {String} options.integrationId The integration to edit
1046
+ * @param {String} [options.event] Change the event that triggers the integration
1047
+ * @param {Object} [options.settings] Change the settings specific to that integration type
1048
+ * @param {String} [options.deviceId] Trigger integration only for this device ID or Name
1049
+ * @param {String} [options.product] Integration for this product ID or slug
1050
+ * @param {String} options.auth Access Token
1051
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1052
+ * @param {Object} [options.context] Request context
1053
+ * @returns {Promise} A promise
1054
+ */
1055
+ editIntegration({ integrationId, event, settings, deviceId, product, auth, headers, context }){
1056
+ const uri = product ? `/v1/products/${product}/integrations/${integrationId}` : `/v1/integrations/${integrationId}`;
1057
+ const data = Object.assign({ event, deviceid: deviceId }, settings);
1058
+ return this.put({ uri, auth, headers, data, context });
1059
+ }
1060
+
1061
+ /**
1062
+ * Delete an integration to send events to an external service
1063
+ *
1064
+ * @param {Object} options Options for this API call
1065
+ * @param {String} options.integrationId The integration to remove
1066
+ * @param {String} [options.product] Integration for this product ID or slug
1067
+ * @param {String} options.auth Access Token
1068
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1069
+ * @param {Object} [options.context] Request context
1070
+ * @returns {Promise} A promise
1071
+ */
1072
+ deleteIntegration({ integrationId, product, auth, headers, context }){
1073
+ const uri = product ? `/v1/products/${product}/integrations/${integrationId}` : `/v1/integrations/${integrationId}`;
1074
+ return this.delete({ uri, auth, headers, context });
1075
+ }
1076
+
1077
+ /**
1078
+ * List all integrations owned by the account or product
1079
+ * @param {Object} options Options for this API call
1080
+ * @param {String} [options.product] Integrations for this product ID or slug
1081
+ * @param {String} options.auth Access Token
1082
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1083
+ * @param {Object} [options.context] Request context
1084
+ * @returns {Promise} A promise
1085
+ */
1086
+ listIntegrations({ product, auth, headers, context }){
1087
+ const uri = product ? `/v1/products/${product}/integrations` : '/v1/integrations';
1088
+ return this.get({ uri, auth, headers, context });
1089
+ }
1090
+
1091
+ /**
1092
+ * Get details about the current user
1093
+ * @param {Object} options Options for this API call
1094
+ * @param {String} options.auth Access Token
1095
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1096
+ * @param {Object} [options.context] Request context
1097
+ * @returns {Promise} A promise
1098
+ */
1099
+ getUserInfo({ auth, headers, context }){
1100
+ return this.get({ uri: '/v1/user', auth, headers, context });
1101
+ }
1102
+
1103
+ /**
1104
+ * Set details on the current user
1105
+ * @param {Object} options Options for this API call
1106
+ * @param {String} options.auth Access Token
1107
+ * @param {String} options.accountInfo Set user's extended info fields (name, business account, company name, etc)
1108
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1109
+ * @param {Object} [options.context] Request context
1110
+ * @returns {Promise} A promise
1111
+ */
1112
+ setUserInfo({ accountInfo, auth, headers, context }){
1113
+ const data = { account_info: accountInfo };
1114
+ return this.put({ uri: '/v1/user', auth, headers, data, context });
1115
+ }
1116
+
1117
+ /**
1118
+ * Change username (i.e, email)
1119
+ * @param {Object} options Options for this API call
1120
+ * @param {String} options.auth Access Token
1121
+ * @param {String} options.currentPassword Current password
1122
+ * @param {String} options.username New email
1123
+ * @param {Boolean} options.invalidateTokens Should all tokens be invalidated
1124
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1125
+ * @param {Object} [options.context] Request context
1126
+ * @returns {Promise} A promise
1127
+ */
1128
+ changeUsername({ currentPassword, username, invalidateTokens = false, auth, headers, context }){
1129
+ const data = { username, current_password: currentPassword };
1130
+
1131
+ if (invalidateTokens) {
1132
+ data.invalidate_tokens = true;
1133
+ }
1134
+
1135
+ return this.put({ uri: '/v1/user', auth, headers, data, context });
1136
+ }
1137
+
1138
+ /**
1139
+ * Change user's password
1140
+ * @param {Object} options Options for this API call
1141
+ * @param {String} options.auth Access Token
1142
+ * @param {String} options.currentPassword Current password
1143
+ * @param {String} options.password New password
1144
+ * @param {Boolean} options.invalidateTokens Should all tokens be invalidated
1145
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1146
+ * @param {Object} [options.context] Request context
1147
+ * @returns {Promise} A promise
1148
+ */
1149
+ changeUserPassword({ currentPassword, password, invalidateTokens = false, auth, headers, context }){
1150
+ const data = { password, current_password: currentPassword };
1151
+
1152
+ if (invalidateTokens) {
1153
+ data.invalidate_tokens = true;
1154
+ }
1155
+
1156
+ return this.put({ uri: '/v1/user', auth, headers, data, context });
1157
+ }
1158
+
1159
+ /**
1160
+ * List SIM cards owned by a user or product
1161
+ * @param {Object} options Options for this API call
1162
+ * @param {String} [options.iccid] (Product only) Filter to SIM cards matching this ICCID
1163
+ * @param {String} [options.deviceId] (Product only) Filter to SIM cards matching this device ID
1164
+ * @param {String} [options.deviceName] (Product only) Filter to SIM cards matching this device name
1165
+ * @param {Number} [options.page] (Product only) Current page of results
1166
+ * @param {Number} [options.perPage] (Product only) Records per page
1167
+ * @param {String} [options.product] SIM cards for this product ID or slug
1168
+ * @param {String} options.auth Access Token
1169
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1170
+ * @param {Object} [options.context] Request context
1171
+ * @returns {Promise} A promise
1172
+ */
1173
+ listSIMs({ iccid, deviceId, deviceName, page, perPage, product, auth, headers, context }){
1174
+ const uri = product ? `/v1/products/${product}/sims` : '/v1/sims';
1175
+ const query = product ? { iccid, deviceId, deviceName, page, per_page: perPage } : undefined;
1176
+ return this.get({ uri, auth, headers, query, context });
1177
+ }
1178
+
1179
+ /**
1180
+ * Get data usage for one SIM card for the current billing period
1181
+ * @param {Object} options Options for this API call
1182
+ * @param {String} options.iccid ICCID of the SIM card
1183
+ * @param {String} [options.product] SIM card for this product ID or slug
1184
+ * @param {String} options.auth Access Token
1185
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1186
+ * @param {Object} [options.context] Request context
1187
+ * @returns {Promise} A promise
1188
+ */
1189
+ getSIMDataUsage({ iccid, product, auth, headers, context }){
1190
+ const uri = product ?
1191
+ `/v1/products/${product}/sims/${iccid}/data_usage` :
1192
+ `/v1/sims/${iccid}/data_usage`;
1193
+
1194
+ return this.get({ uri, auth, headers, context });
1195
+ }
1196
+
1197
+ /**
1198
+ * Get data usage for all SIM cards in a product the current billing period
1199
+ * @param {Object} options Options for this API call
1200
+ * @param {String} options.product SIM cards for this product ID or slug
1201
+ * @param {String} options.auth Access Token
1202
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1203
+ * @param {Object} [options.context] Request context
1204
+ * @returns {Promise} A promise
1205
+ */
1206
+ getFleetDataUsage({ product, auth, headers, context }){
1207
+ return this.get({
1208
+ uri: `/v1/products/${product}/sims/data_usage`,
1209
+ auth,
1210
+ headers,
1211
+ context
1212
+ });
1213
+ }
1214
+
1215
+ /**
1216
+ * Check SIM status
1217
+ * @param {Object} options Options for this API call
1218
+ * @param {String} options.iccid ICCID of the SIM card
1219
+ * @param {String} options.auth Access Token
1220
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1221
+ * @param {Object} [options.context] Request context
1222
+ * @returns {Promise} A promise
1223
+ */
1224
+ checkSIM({ iccid, auth, headers, context }){
1225
+ return this.head({ uri: `/v1/sims/${iccid}`, auth, headers, context });
1226
+ }
1227
+
1228
+ /**
1229
+ * Activate and add SIM cards to an account or product
1230
+ * @param {Object} options Options for this API call
1231
+ * @param {String} options.iccid ICCID of the SIM card
1232
+ * @param {Array<String>} options.iccids (Product only) ICCID of multiple SIM cards to import
1233
+ * @param {String} options.country The ISO country code for the SIM cards
1234
+ * @param {String} [options.product] SIM cards for this product ID or slug
1235
+ * @param {String} options.auth Access Token
1236
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1237
+ * @param {Object} [options.context] Request context
1238
+ * @param {any} [options.promoCode]
1239
+ * @returns {Promise} A promise
1240
+ */
1241
+ activateSIM({ iccid, iccids, country, promoCode, product, auth, headers, context }){
1242
+ // promoCode is deprecated
1243
+ iccids = iccids || [iccid];
1244
+ const uri = product ? `/v1/products/${product}/sims` : `/v1/sims/${iccid}`;
1245
+ const data = product ?
1246
+ { sims: iccids, country } :
1247
+ { country, promoCode, action: 'activate' };
1248
+ const method = product ? 'post' : 'put';
1249
+
1250
+ return this.request({ uri, method, headers, data, auth, context });
1251
+ }
1252
+
1253
+ /**
1254
+ * Deactivate a SIM card so it doesn't incur data usage in future months.
1255
+ * @param {Object} options Options for this API call
1256
+ * @param {String} options.iccid ICCID of the SIM card
1257
+ * @param {String} [options.product] SIM cards for this product ID or slug
1258
+ * @param {String} options.auth Access Token
1259
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1260
+ * @param {Object} [options.context] Request context
1261
+ * @returns {Promise} A promise
1262
+ */
1263
+ deactivateSIM({ iccid, product, auth, headers, context }){
1264
+ const uri = product ? `/v1/products/${product}/sims/${iccid}` : `/v1/sims/${iccid}`;
1265
+ const data = { action: 'deactivate' };
1266
+ return this.put({ uri, auth, headers, data, context });
1267
+ }
1268
+
1269
+ /**
1270
+ * Reactivate a SIM card the was deactivated or unpause a SIM card that was automatically paused
1271
+ * @param {Object} options Options for this API call
1272
+ * @param {String} options.iccid ICCID of the SIM card
1273
+ * @param {Number} [options.mbLimit] New monthly data limit. Necessary if unpausing a SIM card
1274
+ * @param {String} [options.product] SIM cards for this product ID or slug
1275
+ * @param {String} options.auth Access Token
1276
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1277
+ * @param {Object} [options.context] Request context
1278
+ * @returns {Promise} A promise
1279
+ */
1280
+ reactivateSIM({ iccid, mbLimit, product, auth, headers, context }){
1281
+ const uri = product ? `/v1/products/${product}/sims/${iccid}` : `/v1/sims/${iccid}`;
1282
+ const data = { mb_limit: mbLimit, action: 'reactivate' };
1283
+ return this.put({ uri, auth, headers, data, context });
1284
+ }
1285
+
1286
+ /**
1287
+ * Update SIM card data limit
1288
+ * @param {Object} options Options for this API call
1289
+ * @param {String} options.iccid ICCID of the SIM card
1290
+ * @param {Array} options.mbLimit Data limit in megabyte for the SIM card
1291
+ * @param {String} [options.product] SIM cards for this product ID or slug
1292
+ * @param {String} options.auth Access Token
1293
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1294
+ * @param {Object} [options.context] Request context
1295
+ * @returns {Promise} A promise
1296
+ */
1297
+ updateSIM({ iccid, mbLimit, product, auth, headers, context }){
1298
+ const uri = product ? `/v1/products/${product}/sims/${iccid}` : `/v1/sims/${iccid}`;
1299
+ const data = { mb_limit: mbLimit };
1300
+ return this.put({ uri, auth, headers, data, context });
1301
+ }
1302
+
1303
+ /**
1304
+ * Remove a SIM card from an account so it can be activated by a different account
1305
+ * @param {Object} options Options for this API call
1306
+ * @param {String} options.iccid ICCID of the SIM card
1307
+ * @param {String} [options.product] SIM cards for this product ID or slug
1308
+ * @param {String} options.auth Access Token
1309
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1310
+ * @param {Object} [options.context] Request context
1311
+ * @returns {Promise} A promise
1312
+ */
1313
+ removeSIM({ iccid, product, auth, headers, context }){
1314
+ const uri = product ? `/v1/products/${product}/sims/${iccid}` : `/v1/sims/${iccid}`;
1315
+ return this.delete({ uri, auth, headers, context });
1316
+ }
1317
+
1318
+ /**
1319
+ * List valid build targets to be used for compiling
1320
+ * @param {Object} options Options for this API call
1321
+ * @param {Boolean} [options.onlyFeatured=false] Only list featured build targets
1322
+ * @param {String} options.auth Access Token
1323
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1324
+ * @param {Object} [options.context] Request context
1325
+ * @returns {Promise} A promise
1326
+ */
1327
+ listBuildTargets({ onlyFeatured, auth, headers, context }){
1328
+ const query = onlyFeatured ? { featured: !!onlyFeatured } : undefined;
1329
+ return this.get({ uri: '/v1/build_targets', auth, headers, query, context });
1330
+ }
1331
+
1332
+ /**
1333
+ * List firmware libraries
1334
+ * @param {Object} options Options for this API call
1335
+ * @param {Number} options.page Page index (default, first page)
1336
+ * @param {Number} options.limit Number of items per page
1337
+ * @param {String} options.filter Search term for the libraries
1338
+ * @param {String} options.sort Ordering key for the library list
1339
+ * @param {Array<String>} options.architectures List of architectures to filter
1340
+ * @param {String} options.category Category to filter
1341
+ * @param {String} options.scope The library scope to list. Default is 'all'. Other values are
1342
+ * - 'all' - list public libraries and my private libraries
1343
+ * - 'public' - list only public libraries
1344
+ * - 'private' - list only my private libraries
1345
+ * - 'mine' - list my libraries (public and private)
1346
+ * - 'official' - list only official libraries
1347
+ * - 'verified' - list only verified libraries
1348
+ * - 'featured' - list only featured libraries
1349
+ * @param {String} options.excludeScopes list of scopes to exclude
1350
+ * @param {String} options.category Category to filter
1351
+ * @param {String} options.auth Access Token
1352
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1353
+ * @param {Object} [options.context] Request context
1354
+ * @returns {Promise} A promise
1355
+ */
1356
+ listLibraries({ page, limit, filter, sort, architectures, category, scope, excludeScopes, auth, headers, context }){
1357
+ return this.get({
1358
+ uri: '/v1/libraries',
1359
+ auth,
1360
+ headers,
1361
+ query: {
1362
+ page,
1363
+ filter,
1364
+ limit,
1365
+ sort,
1366
+ architectures: this._asList(architectures),
1367
+ category,
1368
+ scope,
1369
+ excludeScopes: this._asList(excludeScopes)
1370
+ },
1371
+ context
1372
+ });
1373
+ }
1374
+
1375
+ _asList(value){
1376
+ return (Array.isArray(value) ? value.join(',') : value);
1377
+ }
1378
+
1379
+ /**
1380
+ * Get firmware library details
1381
+ * @param {Object} options Options for this API call
1382
+ * @param {String} options.name Name of the library to fetch
1383
+ * @param {String} options.version Version of the library to fetch (default: latest)
1384
+ * @param {String} options.auth Access Token
1385
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1386
+ * @param {Object} [options.context] Request context
1387
+ * @returns {Promise} A promise
1388
+ */
1389
+ getLibrary({ name, version, auth, headers, context }){
1390
+ return this.get({
1391
+ uri: `/v1/libraries/${name}`,
1392
+ auth,
1393
+ headers,
1394
+ query: { version },
1395
+ context
1396
+ });
1397
+ }
1398
+
1399
+ /**
1400
+ * Firmware library details for each version
1401
+ * @param {Object} options Options for this API call
1402
+ * @param {String} options.name Name of the library to fetch
1403
+ * @param {Number} options.page Page index (default, first page)
1404
+ * @param {Number} options.limit Number of items per page
1405
+ * @param {String} options.auth Access Token
1406
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1407
+ * @param {Object} [options.context] Request context
1408
+ * @returns {Promise} A promise
1409
+ */
1410
+ getLibraryVersions({ name, page, limit, auth, headers, context }){
1411
+ return this.get({
1412
+ uri: `/v1/libraries/${name}/versions`,
1413
+ auth,
1414
+ headers,
1415
+ query: { page, limit },
1416
+ context
1417
+ });
1418
+ }
1419
+
1420
+ /**
1421
+ * Contribute a new library version from a compressed archive
1422
+ * @param {Object} options Options for this API call
1423
+ * @param {String|Buffer} options.archive Compressed archive file containing the library sources
1424
+ * Either a path or Buffer of the file contents in Node, or a File or Blob in the browser.
1425
+ * @param {String} options.auth Access Token
1426
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1427
+ * @param {Object} [options.context] Request context
1428
+ * @returns {Promise} A promise
1429
+ */
1430
+ contributeLibrary({ archive, auth, headers, context }){
1431
+ const files = {
1432
+ 'archive.tar.gz': archive
1433
+ };
1434
+
1435
+ return this.request({
1436
+ uri: '/v1/libraries',
1437
+ method: 'post',
1438
+ auth,
1439
+ headers,
1440
+ files,
1441
+ context
1442
+ });
1443
+ }
1444
+
1445
+ /**
1446
+ * Publish the latest version of a library to the public
1447
+ * @param {Object} options Options for this API call
1448
+ * @param {String} options.name Name of the library to publish
1449
+ * @param {String} options.auth Access Token
1450
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1451
+ * @param {Object} [options.context] Request context
1452
+ * @returns {Promise} A promise
1453
+ */
1454
+ publishLibrary({ name, auth, headers, context }){
1455
+ return this.request({
1456
+ uri: `/v1/libraries/${name}`,
1457
+ method: 'patch',
1458
+ auth,
1459
+ headers,
1460
+ data: { visibility: 'public' },
1461
+ context
1462
+ });
1463
+ }
1464
+
1465
+ /**
1466
+ * Delete one version of a library or an entire private library
1467
+ * @param {Object} options Options for this API call
1468
+ * @param {String} options.name Name of the library to remove
1469
+ * @param {String} options.force Key to force deleting a public library
1470
+ * @param {String} options.auth Access Token
1471
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1472
+ * @param {Object} [options.context] Request context
1473
+ * @returns {Promise} A promise
1474
+ */
1475
+ deleteLibrary({ name, force, auth, headers, context }){
1476
+ return this.delete({
1477
+ uri: `/v1/libraries/${name}`,
1478
+ auth,
1479
+ headers,
1480
+ data: { force },
1481
+ context
1482
+ });
1483
+ }
1484
+
1485
+ /**
1486
+ * Download an external file that may not be on the API
1487
+ * @param {Object} options Options for this API call
1488
+ * @param {String} options.uri URL of the file.
1489
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1490
+ * @param {Object} [options.context] Request context
1491
+ * @returns {Promise} Resolves to a buffer with the file data
1492
+ */
1493
+ downloadFile({ uri, headers, context }){
1494
+ return this.request({ uri, method: 'get', headers, context, isBuffer: true });
1495
+ }
1496
+
1497
+ /**
1498
+ * List OAuth client created by the account
1499
+ * @param {Object} options Options for this API call
1500
+ * @param {String} [options.product] List clients for this product ID or slug
1501
+ * @param {String} options.auth Access Token
1502
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1503
+ * @param {Object} [options.context] Request context
1504
+ * @returns {Promise} A promise
1505
+ */
1506
+ listOAuthClients({ product, auth, headers, context }){
1507
+ const uri = product ? `/v1/products/${product}/clients` : '/v1/clients';
1508
+ return this.get({ uri, auth, headers, context });
1509
+ }
1510
+
1511
+ /**
1512
+ * Create an OAuth client
1513
+ * @param {Object} options Options for this API call
1514
+ * @param {String} options.name Name of the OAuth client
1515
+ * @param {String} options.type web, installed or web
1516
+ * @param {String} [options.redirect_uri] URL to redirect after OAuth flow. Only for type web.
1517
+ * @param {Object} [options.scope] Limits what the access tokens created by this client can do.
1518
+ * @param {String} [options.product] Create client for this product ID or slug
1519
+ * @param {String} options.auth Access Token
1520
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1521
+ * @param {Object} [options.context] Request context
1522
+ * @returns {Promise} A promise
1523
+ */
1524
+ createOAuthClient({ name, type, redirect_uri, scope, product, auth, headers, context }){
1525
+ const uri = product ? `/v1/products/${product}/clients` : '/v1/clients';
1526
+ const data = { name, type, redirect_uri, scope };
1527
+ return this.post({ uri, auth, headers, data, context });
1528
+ }
1529
+
1530
+ /**
1531
+ * Update an OAuth client
1532
+ * @param {Object} options Options for this API call
1533
+ * @param {String} options.clientId The OAuth client to update
1534
+ * @param {String} [options.name] New Name of the OAuth client
1535
+ * @param {Object} [options.scope] New scope of the OAuth client
1536
+ * @param {String} [options.product] Update client linked to this product ID or slug
1537
+ * @param {String} options.auth Access Token
1538
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1539
+ * @param {Object} [options.context] Request context
1540
+ * @returns {Promise} A promise
1541
+ */
1542
+ updateOAuthClient({ clientId, name, scope, product, auth, headers, context }){
1543
+ const uri = product ? `/v1/products/${product}/clients/${clientId}` : `/v1/clients/${clientId}`;
1544
+ const data = { name, scope };
1545
+ return this.put({ uri, data, auth, headers, context });
1546
+ }
1547
+
1548
+ /**
1549
+ * Delete an OAuth client
1550
+ * @param {Object} options Options for this API call
1551
+ * @param {String} options.clientId The OAuth client to update
1552
+ * @param {String} [options.product] OAuth client linked to this product ID or slug
1553
+ * @param {String} options.auth Access Token
1554
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1555
+ * @param {Object} [options.context] Request context
1556
+ * @returns {Promise} A promise
1557
+ */
1558
+ deleteOAuthClient({ clientId, product, auth, headers, context }){
1559
+ const uri = product ? `/v1/products/${product}/clients/${clientId}` : `/v1/clients/${clientId}`;
1560
+ return this.delete({ uri, auth, headers, context });
1561
+ }
1562
+
1563
+ /**
1564
+ * List products the account has access to
1565
+ * @param {Object} options Options for this API call
1566
+ * @param {String} options.auth Access Token
1567
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1568
+ * @param {Object} [options.context] Request context
1569
+ * @returns {Promise} A promise
1570
+ */
1571
+ listProducts({ auth, headers, context }){
1572
+ return this.get({ uri: '/v1/products', auth, headers, context });
1573
+ }
1574
+
1575
+ /**
1576
+ * Get detailed information about a product
1577
+ * @param {Object} options Options for this API call
1578
+ * @param {String} options.product Product ID or slug
1579
+ * @param {String} options.auth Access token
1580
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1581
+ * @param {Object} [options.context] Request context
1582
+ * @returns {Promise} A promise
1583
+ */
1584
+ getProduct({ product, auth, headers, context }){
1585
+ return this.get({ uri: `/v1/products/${product}`, auth, headers, context });
1586
+ }
1587
+
1588
+ /**
1589
+ * List product firmware versions
1590
+ * @param {Object} options Options for this API call
1591
+ * @param {String} options.product Firmware for this product ID or slug
1592
+ * @param {String} options.auth Access Token
1593
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1594
+ * @param {Object} [options.context] Request context
1595
+ * @returns {Promise} A promise
1596
+ */
1597
+ listProductFirmware({ product, auth, headers, context }){
1598
+ return this.get({ uri: `/v1/products/${product}/firmware`, auth, headers, context });
1599
+ }
1600
+
1601
+ /**
1602
+ * List product firmware versions
1603
+ * @param {Object} options Options for this API call
1604
+ * @param {Object} options.file Path or Buffer of the new firmware file
1605
+ * Either a path or Buffer of the file contents in Node, or a File or Blob in the browser.
1606
+ * @param {Number} options.version Version number of new firmware
1607
+ * @param {String} options.title Short identifier for the new firmware
1608
+ * @param {String} [options.description] Longer description for the new firmware
1609
+ * @param {String} options.product Firmware for this product ID or slug
1610
+ * @param {String} options.auth Access Token
1611
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1612
+ * @param {Object} [options.context] Request context
1613
+ * @returns {Promise} A promise
1614
+ */
1615
+ uploadProductFirmware({ file, version, title, description, product, auth, headers, context }){
1616
+ return this.request({
1617
+ uri: `/v1/products/${product}/firmware`,
1618
+ method: 'post',
1619
+ auth,
1620
+ headers,
1621
+ form: {
1622
+ version,
1623
+ title,
1624
+ description
1625
+ },
1626
+ files: {
1627
+ 'firmware.bin': file
1628
+ },
1629
+ context
1630
+ });
1631
+ }
1632
+
1633
+ /**
1634
+ * Get information about a product firmware version
1635
+ * @param {Object} options Options for this API call
1636
+ * @param {Number} options.version Version number of firmware
1637
+ * @param {String} options.product Firmware for this product ID or slug
1638
+ * @param {String} options.auth Access token
1639
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1640
+ * @param {Object} [options.context] Request context
1641
+ * @returns {Promise} A promise
1642
+ */
1643
+ getProductFirmware({ version, product, auth, headers, context }){
1644
+ return this.get({
1645
+ uri: `/v1/products/${product}/firmware/${version}`,
1646
+ auth,
1647
+ headers,
1648
+ context
1649
+ });
1650
+ }
1651
+
1652
+ /**
1653
+ * Update information for a product firmware version
1654
+ * @param {Object} options Options for this API call
1655
+ * @param {Number} options.version Version number of new firmware
1656
+ * @param {String} [options.title] New title
1657
+ * @param {String} [options.description] New description
1658
+ * @param {String} options.product Firmware for this product ID or slug
1659
+ * @param {String} options.auth Access Token
1660
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1661
+ * @param {Object} [options.context] Request context
1662
+ * @returns {Promise} A promise
1663
+ */
1664
+ updateProductFirmware({ version, title, description, product, auth, headers, context }){
1665
+ const uri = `/v1/products/${product}/firmware/${version}`;
1666
+ return this.put({ uri, auth, headers, data: { title, description }, context });
1667
+ }
1668
+
1669
+ /**
1670
+ * Download a product firmware binary
1671
+ * @param {Object} options Options for this API call
1672
+ * @param {Number} options.version Version number of new firmware
1673
+ * @param {String} options.product Firmware for this product ID or slug
1674
+ * @param {String} options.auth Access Token
1675
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1676
+ * @param {Object} [options.context] Request context
1677
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
1678
+ */
1679
+ downloadProductFirmware({ version, product, auth, headers, context }){
1680
+ return this.request({
1681
+ uri: `/v1/products/${product}/firmware/${version}/binary`,
1682
+ method: 'get',
1683
+ auth,
1684
+ headers,
1685
+ context,
1686
+ isBuffer: true
1687
+ });
1688
+ }
1689
+
1690
+ /**
1691
+ * Release a product firmware version as the default version
1692
+ * @param {Object} options Options for this API call
1693
+ * @param {Number} options.version Version number of new firmware
1694
+ * @param {String} options.product Firmware for this product ID or slug
1695
+ * @param {String} options.auth Access Token
1696
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1697
+ * @param {Object} [options.context] Request context
1698
+ * @returns {Promise} A promise
1699
+ */
1700
+ releaseProductFirmware({ version, product, auth, headers, context }){
1701
+ const uri = `/v1/products/${product}/firmware/release`;
1702
+ return this.put({ uri, auth, headers, data: { version }, context });
1703
+ }
1704
+
1705
+ /**
1706
+ * List product team members
1707
+ * @param {Object} options Options for this API call
1708
+ * @param {String} options.product Team for this product ID or slug
1709
+ * @param {String} options.auth Access Token
1710
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1711
+ * @param {Object} [options.context] Request context
1712
+ * @returns {Promise} A promise
1713
+ */
1714
+ listTeamMembers({ product, auth, headers, context }){
1715
+ return this.get({
1716
+ uri: `/v1/products/${product}/team`,
1717
+ auth,
1718
+ headers,
1719
+ context
1720
+ });
1721
+ }
1722
+
1723
+ /**
1724
+ * Invite Particle user to a product team
1725
+ * @param {Object} options Options for this API call
1726
+ * @param {String} options.username Username for the Particle account
1727
+ * @param {String} options.product Team for this product ID or slug
1728
+ * @param {String} options.auth Access Token
1729
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1730
+ * @param {Object} [options.context] Request context
1731
+ * @returns {Promise} A promise
1732
+ */
1733
+ inviteTeamMember({ username, product, auth, headers, context }){
1734
+ return this.post({
1735
+ uri: `/v1/products/${product}/team`,
1736
+ auth,
1737
+ headers,
1738
+ data: { username },
1739
+ context
1740
+ });
1741
+ }
1742
+
1743
+ /**
1744
+ * Remove Particle user to a product team
1745
+ * @param {Object} options Options for this API call
1746
+ * @param {String} options.username Username for the Particle account
1747
+ * @param {String} options.product Team for this product ID or slug
1748
+ * @param {String} options.auth Access Token
1749
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1750
+ * @param {Object} [options.context] Request context
1751
+ * @returns {Promise} A promise
1752
+ */
1753
+ removeTeamMember({ username, product, auth, headers, context }){
1754
+ return this.delete({
1755
+ uri: `/v1/products/${product}/team/${username}`,
1756
+ auth,
1757
+ headers,
1758
+ context
1759
+ });
1760
+ }
1761
+
1762
+ /**
1763
+ * Fetch details about a serial number
1764
+ * @param {Object} options Options for this API call
1765
+ * @param {String} options.serialNumber The serial number printed on the barcode of the device packaging
1766
+ * @param {String} options.auth Access Token
1767
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1768
+ * @param {Object} [options.context] Request context
1769
+ * @returns {Promise} A promise
1770
+ */
1771
+ lookupSerialNumber({ serialNumber, auth, headers, context }){
1772
+ return this.get({
1773
+ uri: `/v1/serial_numbers/${serialNumber}`,
1774
+ auth,
1775
+ headers,
1776
+ context
1777
+ });
1778
+ }
1779
+
1780
+ /**
1781
+ * Create a mesh network
1782
+ * @param {Object} options Options for this API call
1783
+ * @param {String} options.name Network name
1784
+ * @param {String} options.deviceId Gateway device ID
1785
+ * @param {String} [options.iccid] ICCID of the active SIM card (only for cellular gateway devices)
1786
+ * @param {String} options.auth Access token
1787
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1788
+ * @param {Object} [options.context] Request context
1789
+ * @returns {Promise<Object>} A promise
1790
+ */
1791
+ createMeshNetwork({ name, deviceId, iccid, auth, headers, context }){
1792
+ return this.post({
1793
+ uri: '/v1/networks',
1794
+ auth,
1795
+ headers,
1796
+ data: { name, device_id: deviceId, iccid },
1797
+ context
1798
+ });
1799
+ }
1800
+
1801
+ /**
1802
+ * Remove a mesh network.
1803
+ * @param {Object} options Options for this API call
1804
+ * @param {String} options.networkId Network ID or name
1805
+ * @param {String} options.auth Access token
1806
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1807
+ * @param {Object} [options.context] Request context
1808
+ * @returns {Promise<Object>} A promise
1809
+ */
1810
+ removeMeshNetwork({ networkId, auth, headers, context }){
1811
+ return this.delete({ uri: `/v1/networks/${networkId}`, auth, headers, context });
1812
+ }
1813
+
1814
+ /**
1815
+ * List all mesh networks
1816
+ * @param {Object} options Options for this API call
1817
+ * @param {String} options.auth Access token
1818
+ * @param {Number} [options.page] Current page of results
1819
+ * @param {Number} [options.perPage] Records per page
1820
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1821
+ * @param {Object} [options.context] Request context
1822
+ * @returns {Promise<Object>} A promise
1823
+ */
1824
+ listMeshNetworks({ page, perPage, auth, headers, context }){
1825
+ const query = page ? { page, per_page: perPage } : undefined;
1826
+ return this.get({ uri: '/v1/networks', auth, headers, query, context });
1827
+ }
1828
+
1829
+ /**
1830
+ * Get information about a mesh network.
1831
+ * @param {Object} options Options for this API call
1832
+ * @param {String} options.networkId Network ID or name
1833
+ * @param {String} options.auth Access token
1834
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1835
+ * @param {Object} [options.context] Request context
1836
+ * @returns {Promise<Object>} A promise
1837
+ */
1838
+ getMeshNetwork({ networkId, auth, headers, context }){
1839
+ return this.get({ uri: `/v1/networks/${networkId}`, auth, headers, context });
1840
+ }
1841
+
1842
+ /**
1843
+ * Modify a mesh network.
1844
+ * @param {Object} options Options for this API call
1845
+ * @param {String} options.networkId Network ID or name
1846
+ * @param {String} options.action 'add-device', 'remove-device', 'gateway-enable' or 'gateway-disable'
1847
+ * @param {String} options.deviceId Device ID
1848
+ * @param {String} options.auth Access token
1849
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1850
+ * @param {Object} [options.context] Request context
1851
+ * @returns {Promise<Object>} A promise
1852
+ */
1853
+ updateMeshNetwork({ networkId, action, deviceId, auth, headers, context }){
1854
+ return this.put({
1855
+ uri: `/v1/networks/${networkId}`,
1856
+ auth,
1857
+ headers,
1858
+ data: { action, device_id: deviceId },
1859
+ context
1860
+ });
1861
+ }
1862
+
1863
+ /**
1864
+ * Add a device to a mesh network.
1865
+ * @param {Object} options Options for this API call
1866
+ * @param {String} options.networkId Network ID or name
1867
+ * @param {String} options.deviceId Device ID
1868
+ * @param {String} options.auth Access token
1869
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1870
+ * @param {Object} [options.context] Request context
1871
+ * @returns {Promise<Object>} A promise
1872
+ */
1873
+ addMeshNetworkDevice({ networkId, deviceId, auth, headers, context }){
1874
+ return this.updateMeshNetwork({
1875
+ action: 'add-device',
1876
+ networkId,
1877
+ deviceId,
1878
+ auth,
1879
+ headers,
1880
+ context
1881
+ });
1882
+ }
1883
+
1884
+ /**
1885
+ * Remove a device from a mesh network.
1886
+ * @param {Object} options Options for this API call
1887
+ * @param {String} [options.networkId] Network ID or name
1888
+ * @param {String} options.deviceId Device ID
1889
+ * @param {String} options.auth Access token
1890
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1891
+ * @param {Object} [options.context] Request context
1892
+ * @returns {Promise<Object>} A promise
1893
+ */
1894
+ removeMeshNetworkDevice({ networkId, deviceId, auth, headers, context }){
1895
+ if (!networkId){
1896
+ return this.delete({
1897
+ uri: `/v1/devices/${deviceId}/network`,
1898
+ auth,
1899
+ headers, context
1900
+ });
1901
+ }
1902
+ return this.updateMeshNetwork({
1903
+ action: 'remove-device',
1904
+ networkId,
1905
+ deviceId,
1906
+ auth,
1907
+ headers,
1908
+ context
1909
+ });
1910
+ }
1911
+
1912
+ /**
1913
+ * List all devices of a mesh network.
1914
+ * @param {Object} options Options for this API call
1915
+ * @param {String} options.networkId Network ID or name
1916
+ * @param {String} options.auth Access token
1917
+ * @param {Number} [options.role] Device role: 'gateway' or 'node'
1918
+ * @param {Number} [options.page] Current page of results
1919
+ * @param {Number} [options.perPage] Records per page
1920
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1921
+ * @param {Object} [options.context] Request context
1922
+ * @returns {Promise<Object>} A promise
1923
+ */
1924
+ listMeshNetworkDevices({ networkId, role, page, perPage, auth, headers, context }){
1925
+ const query = (role || page) ? { role, page, per_page: perPage } : undefined;
1926
+ return this.get({
1927
+ uri: `/v1/networks/${networkId}/devices`,
1928
+ auth,
1929
+ headers,
1930
+ query,
1931
+ context
1932
+ });
1933
+ }
1934
+
1935
+ /**
1936
+ * Get product configuration
1937
+ * @param {Object} options Options for this API call
1938
+ * @param {String} options.product Config for this product ID or slug
1939
+ * @param {String} options.auth Access Token
1940
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1941
+ * @param {Object} [options.context] Request context
1942
+ * @returns {Promise} A promise
1943
+ */
1944
+ getProductConfiguration({ auth, product, headers, context }){
1945
+ return this.get({
1946
+ uri: `/v1/products/${product}/config`,
1947
+ auth,
1948
+ headers,
1949
+ context
1950
+ });
1951
+ }
1952
+
1953
+ /**
1954
+ * Get product configuration schema
1955
+ * @param {Object} options Options for this API call
1956
+ * @param {String} options.product Config for this product ID or slug
1957
+ * @param {String} options.auth Access Token
1958
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1959
+ * @param {Object} [options.context] Request context
1960
+ * @returns {Promise} A promise
1961
+ */
1962
+ getProductConfigurationSchema({ auth, product, headers = {}, context }){
1963
+ headers.accept = 'application/schema+json';
1964
+ return this.get({
1965
+ uri: `/v1/products/${product}/config`,
1966
+ auth,
1967
+ headers,
1968
+ context
1969
+ });
1970
+ }
1971
+
1972
+ /**
1973
+ * Get product device's configuration
1974
+ * @param {Object} options Options for this API call
1975
+ * @param {String} options.product Config for this product ID or slug
1976
+ * @param {String} options.auth Access Token
1977
+ * @param {String} options.deviceId Device ID to access
1978
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1979
+ * @param {Object} [options.context] Request context
1980
+ * @returns {Promise} A promise
1981
+ */
1982
+ getProductDeviceConfiguration({ auth, product, deviceId, headers, context }){
1983
+ return this.get({
1984
+ uri: `/v1/products/${product}/config/${deviceId}`,
1985
+ auth,
1986
+ headers,
1987
+ context
1988
+ });
1989
+ }
1990
+
1991
+ /**
1992
+ * Get product device's configuration schema
1993
+ * @param {Object} options Options for this API call
1994
+ * @param {String} options.product Config for this product ID or slug
1995
+ * @param {String} options.auth Access Token
1996
+ * @param {String} options.deviceId Device ID to access
1997
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
1998
+ * @param {Object} [options.context] Request context
1999
+ * @returns {Promise} A promise
2000
+ */
2001
+ getProductDeviceConfigurationSchema({ auth, product, deviceId, headers, context }){
2002
+ headers.accept = 'application/schema+json';
2003
+ return this.get({
2004
+ uri: `/v1/products/${product}/config/${deviceId}`,
2005
+ auth,
2006
+ headers,
2007
+ context
2008
+ });
2009
+ }
2010
+
2011
+ /**
2012
+ * Set product configuration
2013
+ * @param {Object} options Options for this API call
2014
+ * @param {String} options.product Config for this product ID or slug
2015
+ * @param {String} options.auth Access Token
2016
+ * @param {Object} options.config Product configuration to update
2017
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2018
+ * @param {Object} [options.context] Request context
2019
+ * @returns {Promise} A promise
2020
+ */
2021
+ setProductConfiguration({ auth, product, config, headers, context }){
2022
+ return this.put({
2023
+ uri: `/v1/products/${product}/config`,
2024
+ auth,
2025
+ data: config,
2026
+ headers,
2027
+ context
2028
+ });
2029
+ }
2030
+
2031
+ /**
2032
+ * Set product configuration for a specific device within the product
2033
+ * @param {Object} options Options for this API call
2034
+ * @param {String} options.product Config for this product ID or slug
2035
+ * @param {String} options.auth Access Token
2036
+ * @param {Object} options.config Product configuration to update
2037
+ * @param {String} options.deviceId Device ID to access
2038
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2039
+ * @param {Object} [options.context] Request context
2040
+ * @returns {Promise} A promise
2041
+ */
2042
+ setProductDeviceConfiguration({ auth, product, deviceId, config, headers, context }){
2043
+ return this.put({
2044
+ uri: `/v1/products/${product}/config/${deviceId}`,
2045
+ data: config,
2046
+ auth,
2047
+ headers,
2048
+ context
2049
+ });
2050
+ }
2051
+
2052
+ /**
2053
+ * Query location for devices within a product
2054
+ * @param {Object} options Options for this API call
2055
+ * @param {String} options.product Locations for this product ID or slug
2056
+ * @param {String} options.auth Access Token
2057
+ * @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query
2058
+ * @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma
2059
+ * @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma
2060
+ * @param {String} options.deviceId Device ID prefix to include in the query
2061
+ * @param {String} options.deviceName Device name prefix to include in the query
2062
+ * @param {String} options.groups Array of group names to include in the query
2063
+ * @param {String} options.page Page of results to display. Defaults to 1
2064
+ * @param {String} options.perPage Number of results per page. Defaults to 20. Maximum of 100
2065
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2066
+ * @param {Object} [options.context] Request context
2067
+ * @returns {Promise} A promise
2068
+ */
2069
+ getProductLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, deviceName, groups, page, perPage, headers, context }){
2070
+ return this.get({
2071
+ uri: `/v1/products/${product}/locations`,
2072
+ query: {
2073
+ date_range: dateRange,
2074
+ rect_bl: rectBl,
2075
+ rect_tr: rectTr,
2076
+ device_id: deviceId,
2077
+ device_name: deviceName,
2078
+ groups,
2079
+ page,
2080
+ per_page: perPage
2081
+ },
2082
+ auth,
2083
+ headers,
2084
+ context
2085
+ });
2086
+ }
2087
+
2088
+ /**
2089
+ * Query location for one device within a product
2090
+ * @param {Object} options Options for this API call
2091
+ * @param {String} options.product Locations for this product ID or slug
2092
+ * @param {String} options.auth Access Token
2093
+ * @param {String} options.dateRange Start and end date in ISO8601 format, separated by comma, to query
2094
+ * @param {String} options.rectBl Bottom left of the rectangular bounding box to query. Latitude and longitude separated by comma
2095
+ * @param {String} options.rectTr Top right of the rectangular bounding box to query. Latitude and longitude separated by comma
2096
+ * @param {String} options.deviceId Device ID to query
2097
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2098
+ * @param {Object} [options.context] Request context
2099
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2100
+ * @param {Object} [options.context] Request context
2101
+ * @returns {Promise} A promise
2102
+ */
2103
+ getProductDeviceLocations({ auth, product, dateRange, rectBl, rectTr, deviceId, headers, context }){
2104
+ return this.get({
2105
+ uri: `/v1/products/${product}/locations/${deviceId}`,
2106
+ query: {
2107
+ date_range: dateRange,
2108
+ rect_bl: rectBl,
2109
+ rect_tr: rectTr
2110
+ },
2111
+ auth,
2112
+ headers,
2113
+ context
2114
+ });
2115
+ }
2116
+
2117
+ /**
2118
+ * Creates a new logic block in the specified organization using the provided block data.
2119
+ *
2120
+ * When you create a logic block with PubSub matchers, events will immediately
2121
+ * start being handled by the block code.
2122
+ *
2123
+ * When you create a Chron matcher, it will immediately be scheduled at the next time
2124
+ * according to the cron and start_at properties.
2125
+ *
2126
+ * @param {Object} options The options for creating the logic block.
2127
+ * @param {Object} options.auth Access token
2128
+ * @param {string} options.org The name of the organization.
2129
+ * @param {string} options.block The block object containing the block details.
2130
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2131
+ * @param {Object} [options.context] Request context
2132
+ *
2133
+ * @returns {Promise<RequestResponse>} A promise that resolves to the created logic block data.
2134
+ */
2135
+ createLogicBlock({ auth, org, block, headers, context }) {
2136
+ return this.post({
2137
+ uri: `/v1/orgs/${org}/blocks`,
2138
+ auth,
2139
+ data: { block },
2140
+ headers,
2141
+ context
2142
+ });
2143
+ }
2144
+
2145
+ /**
2146
+ * Get a logic block in the specified organization by block ID.
2147
+ *
2148
+ * @param {Object} options The options for the logic block.
2149
+ * @param {Object} options.auth Access token
2150
+ * @param {string} options.org The name of the organization.
2151
+ * @param {string} options.blockId The ID of the block to retrieve.
2152
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2153
+ * @param {Object} [options.context] Request context
2154
+ *
2155
+ * @returns {Promise<RequestResponse>} A promise that resolves to the specified logic block data.
2156
+ */
2157
+ getLogicBlock({ auth, org, blockId, headers, context }) {
2158
+ return this.get({
2159
+ uri: `/v1/orgs/${org}/blocks/${blockId}`,
2160
+ auth,
2161
+ headers,
2162
+ context
2163
+ });
2164
+ }
2165
+
2166
+ /**
2167
+ * Updates an existing logic block in the specified organization using the provided block data.
2168
+ *
2169
+ * If you include an id on a matcher, it will update the matcher in place.
2170
+ *
2171
+ * @param {Object} options The options for updating the logic block.
2172
+ * @param {Object} options.auth The authentication object with the API key.
2173
+ * @param {string} options.org The unique identifier of the organization.
2174
+ * @param {string} options.blockId The ID of the block to update.
2175
+ * @param {string} options.block The block object containing the block details.
2176
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2177
+ * @param {Object} [options.context] Request context.
2178
+ *
2179
+ * @returns {Promise<RequestResponse>} A promise that resolves to the updated logic block data.
2180
+ */
2181
+ updateLogicBlock({ auth, org, blockId, block, headers, context }) {
2182
+ return this.put({
2183
+ uri: `/v1/orgs/${org}/blocks/${blockId}`,
2184
+ auth,
2185
+ data: { block },
2186
+ headers,
2187
+ context
2188
+ });
2189
+ }
2190
+
2191
+ /**
2192
+ * Deletes a logic block in the specified organization by block ID.
2193
+ *
2194
+ * @param {Object} options The options for deleting the logic block.
2195
+ * @param {Object} options.auth The authentication object with the API key.
2196
+ * @param {string} options.org The unique identifier of the organization.
2197
+ * @param {string} options.blockId The ID of the block to delete.
2198
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2199
+ * @param {Object} [options.context] Request context.
2200
+ *
2201
+ * @returns {Promise<RequestResponse>} A promise that resolves to an object containing the deleted block ID.
2202
+ */
2203
+ deleteLogicBlock({ auth, org, blockId, headers, context }) {
2204
+ return this.delete({
2205
+ uri: `/v1/orgs/${org}/blocks/${blockId}`,
2206
+ auth,
2207
+ headers,
2208
+ context
2209
+ });
2210
+ }
2211
+
2212
+ /**
2213
+ * Lists all logic blocks in the specified organization.
2214
+ *
2215
+ * @param {Object} options The options for listing logic blocks.
2216
+ * @param {Object} options.auth The authentication object with the API key.
2217
+ * @param {string} options.org The unique identifier of the organization.
2218
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2219
+ * @param {Object} [options.context] Request context.
2220
+ *
2221
+ * @returns {Promise<RequestResponse>} A promise that resolves to an array of logic block data.
2222
+ */
2223
+ listLogicBlocks({ auth, org, headers, context }) {
2224
+ return this.get({
2225
+ uri: `/v1/orgs/${org}/blocks`,
2226
+ auth,
2227
+ headers,
2228
+ context
2229
+ });
2230
+ }
2231
+
2232
+ /**
2233
+ * Lists all block runs for the specified block.
2234
+ *
2235
+ * @param {Object} options The options for the request.
2236
+ * @param {Object} options.auth Access token
2237
+ * @param {string} options.org The unique identifier of the organization.
2238
+ * @param {number} options.blockId The ID of the block for which to retrieve the block runs.
2239
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2240
+ * @param {Object} [options.context] Request context
2241
+ *
2242
+ * @returns {Promise<RequestResponse>} A promise that resolves to an array of block run data.
2243
+ */
2244
+ listBlockRuns({ auth, org, blockId, headers, context }) {
2245
+ return this.get({
2246
+ uri: `/v1/orgs/${org}/blocks/${blockId}/runs`,
2247
+ auth,
2248
+ headers,
2249
+ context
2250
+ });
2251
+ }
2252
+
2253
+ /**
2254
+ * Retrieves a block run by its ID for the specified block.
2255
+ *
2256
+ * @param {Object} options The options for the request.
2257
+ * @param {Object} options.auth Access token
2258
+ * @param {string} options.org The unique identifier of the organization.
2259
+ * @param {number} options.blockId The ID of the block for which to retrieve the block run.
2260
+ * @param {number} options.runId The ID of the block run to retrieve.
2261
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2262
+ * @param {Object} [options.context] Request context
2263
+ *
2264
+ * @returns {Promise<RequestResponse>} A promise that resolves to an array of block run data for the specified block run ID.
2265
+ */
2266
+ getBlockRun({ auth, org, blockId, runId, headers, context }) {
2267
+ return this.get({
2268
+ uri: `/v1/orgs/${org}/blocks/${blockId}/runs/${runId}`,
2269
+ auth,
2270
+ headers,
2271
+ context
2272
+ });
2273
+ }
2274
+
2275
+ /**
2276
+ * Retrieves the logs for a block run by its ID for the specified block.
2277
+ *
2278
+ * @param {Object} options The options for the request.
2279
+ * @param {Object} options.auth Access token
2280
+ * @param {string} options.org The unique identifier of the organization.
2281
+ * @param {number} options.blockId The ID of the block for which to retrieve the block run logs.
2282
+ * @param {number} options.runId The ID of the block run for which to retrieve the logs.
2283
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2284
+ * @param {Object} [options.context] Request context
2285
+ *
2286
+ * @returns {Promise<RequestResponse>} A promise that resolves to the logs for the specified block run ID.
2287
+ */
2288
+ getBlockRunLog({ auth, org, blockId, runId, headers, context }) {
2289
+ return this.get({
2290
+ uri: `/v1/orgs/${org}/blocks/${blockId}/runs/${runId}/logs`,
2291
+ auth,
2292
+ headers,
2293
+ context
2294
+ });
2295
+ }
2296
+
2297
+ /**
2298
+ * Creates a new ledger definition in the specified organization.
2299
+ *
2300
+ * @param {Object} options The options for creating the ledger definition.
2301
+ * @param {Object} options.auth Access token
2302
+ * @param {string} options.org The name of the organization.
2303
+ * @param {object} options.definition The ledger definition object.
2304
+ * @param {object} options.ledger The ledger definition object.
2305
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2306
+ * @param {Object} [options.context] Request context
2307
+ *
2308
+ * @returns {Promise<RequestResponse>} A promise that resolves to the created ledger definition data.
2309
+ */
2310
+ createLedger({ auth, org, ledger, headers, context }) {
2311
+ return this.post({
2312
+ uri: `/v1/orgs/${org}/ledgers`,
2313
+ auth,
2314
+ data: { ledger },
2315
+ headers,
2316
+ context
2317
+ });
2318
+ }
2319
+
2320
+ /**
2321
+ * Get a ledger definition in the specified organization by ledger name.
2322
+ *
2323
+ * @param {Object} options The options for the ledger definition.
2324
+ * @param {Object} options.auth Access token
2325
+ * @param {string} options.org The name of the organization.
2326
+ * @param {string} options.ledgerName The ID of the ledger definition to retrieve.
2327
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2328
+ * @param {Object} [options.context] Request context
2329
+ *
2330
+ * @returns {Promise<RequestResponse>} A promise that resolves to the specified ledger definition data.
2331
+ */
2332
+ getLedger({ auth, org, ledgerName, headers, context }) {
2333
+ return this.get({
2334
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}`,
2335
+ auth,
2336
+ headers,
2337
+ context
2338
+ });
2339
+ }
2340
+
2341
+ /**
2342
+ * Updates an existing ledger definition in the specified organization.
2343
+ *
2344
+ * @param {Object} options The options for updating the ledger definition.
2345
+ * @param {Object} options.auth The authentication object with the API key.
2346
+ * @param {string} options.org The unique identifier of the organization.
2347
+ * @param {string} options.ledgerName Name of the ledger definition to update.
2348
+ * @param {object} options.ledger The ledger definition object.
2349
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2350
+ * @param {Object} [options.context] Request context.
2351
+ *
2352
+ * @returns {Promise<RequestResponse>} A promise that resolves to the updated ledger definition data.
2353
+ */
2354
+ updateLedger({ auth, org, ledgerName, ledger, headers, context }) {
2355
+ return this.put({
2356
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}`,
2357
+ auth,
2358
+ data: { ledger },
2359
+ headers,
2360
+ context
2361
+ });
2362
+ }
2363
+
2364
+ /**
2365
+ * Archives a ledger definition in the specified organization by ledger name.
2366
+ *
2367
+ * @param {Object} options The options for archiving the ledger definition.
2368
+ * @param {Object} options.auth The authentication object with the API key.
2369
+ * @param {string} options.org The unique identifier of the organization.
2370
+ * @param {string} options.ledgerName Name of the ledger definition to archive.
2371
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2372
+ * @param {Object} [options.context] Request context.
2373
+ *
2374
+ * @returns {Promise<RequestResponse>} A promise that resolves to an object confirming the ledger definition was archived.
2375
+ */
2376
+ archiveLedger({ auth, org, ledgerName, headers, context }) {
2377
+ return this.delete({
2378
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}`,
2379
+ auth,
2380
+ headers,
2381
+ context
2382
+ });
2383
+ }
2384
+
2385
+ /**
2386
+ * Lists all ledger definitions in the specified organization.
2387
+ *
2388
+ * @param {Object} options The options for listing ledger definitions.
2389
+ * @param {Object} options.auth The authentication object with the API key.
2390
+ * @param {string} options.org The unique identifier of the organization.
2391
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2392
+ * @param {Object} [options.context] Request context.
2393
+ *
2394
+ * @returns {Promise<RequestResponse>} A promise that resolves to an array of ledger definition data.
2395
+ */
2396
+ listLedgers({ auth, org, headers, context }) {
2397
+ return this.get({
2398
+ uri: `/v1/orgs/${org}/ledgers`,
2399
+ auth,
2400
+ headers,
2401
+ context
2402
+ });
2403
+ }
2404
+
2405
+ /**
2406
+ * Get ledger instance data.
2407
+ *
2408
+ * @param {Object} options The options for the ledger instance.
2409
+ * @param {Object} options.auth Access token
2410
+ * @param {string} options.org The name of the organization.
2411
+ * @param {string} options.ledgerName Ledger name.
2412
+ * @param {string} options.scopeValue Scope value.
2413
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2414
+ * @param {Object} [options.context] Request context
2415
+ *
2416
+ * @returns {Promise<RequestResponse>} A promise that resolves to the specified ledger instance data.
2417
+ */
2418
+ getLedgerInstance({ auth, org, ledgerName, scopeValue, headers, context }) {
2419
+ return this.get({
2420
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}/instances/${scopeValue}`,
2421
+ auth,
2422
+ headers,
2423
+ context
2424
+ });
2425
+ }
2426
+
2427
+ /**
2428
+ * Set ledger instance data.
2429
+ *
2430
+ * @param {Object} options The options for updating the ledger instance.
2431
+ * @param {Object} options.auth The authentication object with the API key.
2432
+ * @param {string} options.org The unique identifier of the organization.
2433
+ * @param {string} options.ledgerName Ledger name.
2434
+ * @param {string} options.scopeValue Scope value.
2435
+ * @param {object} options.instance The ledger instance object.
2436
+ * @param {object} options.data The data to set to the instance
2437
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2438
+ * @param {Object} [options.context] Request context.
2439
+ *
2440
+ * @returns {Promise<RequestResponse>} A promise that resolves to the updated ledger instance data.
2441
+ */
2442
+ setLedgerInstance({ auth, org, ledgerName, scopeValue, data, headers, context }) {
2443
+ return this.put({
2444
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}/instances/${scopeValue}`,
2445
+ auth,
2446
+ data: { data },
2447
+ headers,
2448
+ context
2449
+ });
2450
+ }
2451
+
2452
+ /**
2453
+ * Delete a ledger instance in the specified organization by ledger name.
2454
+ *
2455
+ * @param {Object} options The options for archiving the ledger instance.
2456
+ * @param {Object} options.auth The authentication object with the API key.
2457
+ * @param {string} options.org The unique identifier of the organization.
2458
+ * @param {string} options.ledgerName Name of the ledger instance to archive.
2459
+ * @param {string} options.scopeValue Scope value.
2460
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2461
+ * @param {Object} [options.context] Request context.
2462
+ *
2463
+ * @returns {Promise<RequestResponse>} A promise that resolves to an object confirming the ledger instance was deleted.
2464
+ */
2465
+ deleteLedgerInstance({ auth, org, ledgerName, scopeValue, headers, context }) {
2466
+ return this.delete({
2467
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}/instances/${scopeValue}`,
2468
+ auth,
2469
+ headers,
2470
+ context
2471
+ });
2472
+ }
2473
+
2474
+ /**
2475
+ * Lists ledger instances.
2476
+ *
2477
+ * @param {Object} options The options for listing ledger instances.
2478
+ * @param {Object} options.auth The authentication object with the API key.
2479
+ * @param {string} options.org The unique identifier of the organization.
2480
+ * @param {string} options.ledgerName Name of the ledger instance to archive.
2481
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2482
+ * @param {Object} [options.context] Request context.
2483
+ *
2484
+ * @returns {Promise<RequestResponse>} A promise that resolves to an array of ledger instance data.
2485
+ */
2486
+ listLedgerInstances({ auth, org, ledgerName, headers, context }) {
2487
+ return this.get({
2488
+ uri: `/v1/orgs/${org}/ledgers/${ledgerName}/instances`,
2489
+ auth,
2490
+ headers,
2491
+ context
2492
+ });
2493
+ }
2494
+
2495
+ /**
2496
+ * Set default auth token that will be used in each method if `auth` is not provided
2497
+ * @param {String} auth A Particle access token
2498
+ * @throws {Error} When not auth string is provided
2499
+ */
2500
+ setDefaultAuth(auth){
2501
+ if (typeof auth === 'string' && auth.length !== 0) {
2502
+ this._defaultAuth = auth;
2503
+ } else {
2504
+ throw new Error('Must pass a non-empty string');
2505
+ }
2506
+ }
2507
+ /**
2508
+ * Return provided token if truthy else use default auth if truthy else undefined
2509
+ * @param {*} auth Optional auth token or undefined
2510
+ * @private
2511
+ * @returns {String|undefined} a Particle auth token or undefined
2512
+ */
2513
+ _getActiveAuthToken(auth) {
2514
+ return auth || this._defaultAuth;
2515
+ }
2516
+ /**
2517
+ * API URI to access a device
2518
+ * @param {Object} options Options for this API call
2519
+ * @param {String} options.deviceId Device ID to access
2520
+ * @param {String} [options.product] Device only in this product ID or slug
2521
+ * @private
2522
+ * @returns {string} URI
2523
+ */
2524
+ deviceUri({ deviceId, product }){
2525
+ return product ? `/v1/products/${product}/devices/${deviceId}` : `/v1/devices/${deviceId}`;
2526
+ }
2527
+
2528
+ /**
2529
+ * Make a GET request
2530
+ * @param {object} params
2531
+ * @param {string} params.uri The URI to request
2532
+ * @param {string|object} [params.auth] Authorization token to use
2533
+ * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2534
+ * @param {string|object} [params.query] Key/VAlue pairs of query params or a correctly formatted string
2535
+ * @param {object} [params.context] The invocation context, describing the tool and project
2536
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2537
+ */
2538
+ get({ uri, auth, headers, query, context }){
2539
+ context = this._buildContext(context);
2540
+ auth = this._getActiveAuthToken(auth);
2541
+ return this.agent.get({ uri, auth, headers, query, context });
2542
+ }
2543
+
2544
+ /**
2545
+ * Make a HEAD request
2546
+ * @param {object} params
2547
+ * @param {string} params.uri The URI to request
2548
+ * @param {string|object} [params.auth] Authorization token to use
2549
+ * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2550
+ * @param {string|object} [params.query] Key/VAlue pairs of query params or a correctly formatted string
2551
+ * @param {object} [params.context] The invocation context, describing the tool and project
2552
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2553
+ */
2554
+ head({ uri, auth, headers, query, context }){
2555
+ context = this._buildContext(context);
2556
+ auth = this._getActiveAuthToken(auth);
2557
+ return this.agent.head({ uri, auth, headers, query, context });
2558
+ }
2559
+
2560
+ /**
2561
+ * Make a POST request
2562
+ * @param {object} params
2563
+ * @param {string} params.uri The URI to request
2564
+ * @param {string|object} [params.auth] Authorization token to use
2565
+ * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2566
+ * @param {string|object} [params.data] Key/VAlue pairs of query params or a correctly formatted string
2567
+ * @param {object} [params.context] The invocation context, describing the tool and project
2568
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2569
+ */
2570
+ post({ uri, auth, headers, data, context }){
2571
+ context = this._buildContext(context);
2572
+ auth = this._getActiveAuthToken(auth);
2573
+ return this.agent.post({ uri, auth, headers, data, context });
2574
+ }
2575
+
2576
+ /**
2577
+ * Make a PUT request
2578
+ * @param {object} params
2579
+ * @param {string} params.uri The URI to request
2580
+ * @param {string|object} [params.auth] Authorization token to use
2581
+ * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2582
+ * @param {string|object} [params.data] Key/VAlue pairs of query params or a correctly formatted string
2583
+ * @param {object} [params.context] The invocation context, describing the tool and project
2584
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2585
+ */
2586
+ put({ uri, auth, headers, data, context }){
2587
+ context = this._buildContext(context);
2588
+ auth = this._getActiveAuthToken(auth);
2589
+ return this.agent.put({ uri, auth, headers, data, context });
2590
+ }
2591
+
2592
+ /**
2593
+ * Make a DELETE request
2594
+ * @param {object} params
2595
+ * @param {string} params.uri The URI to request
2596
+ * @param {string|object} [params.auth] Authorization token to use
2597
+ * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2598
+ * @param {string|object} [params.data] Key/VAlue pairs of query params or a correctly formatted string
2599
+ * @param {object} [params.context] The invocation context, describing the tool and project
2600
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2601
+ */
2602
+ delete({ uri, auth, headers, data, context }){
2603
+ context = this._buildContext(context);
2604
+ auth = this._getActiveAuthToken(auth);
2605
+ return this.agent.delete({ uri, auth, headers, data, context });
2606
+ }
2607
+
2608
+ /**
2609
+ *
2610
+ * @param {Object} args An obj with all the possible request configurations
2611
+ * @param {String} args.uri The URI to request
2612
+ * @param {String} args.method The method used to request the URI, should be in uppercase.
2613
+ * @param {Object} [args.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2614
+ * @param {object} [args.data] Arbitrary data to send as the body.
2615
+ * @param {string|object} [args.auth] Authorization
2616
+ * @param {String|Object} [args.query] Query parameters
2617
+ * @param {Object} [args.form] Form fields
2618
+ * @param {Object} [args.files] Array of file names and file content
2619
+ * @param {Object} [args.context] The invocation context, describing the tool and project.
2620
+ * @param {boolean} [args.isBuffer] Indicate if the response should be treated as Buffer instead of JSON
2621
+ * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2622
+ */
2623
+ request(args){
2624
+ args.context = this._buildContext(args.context);
2625
+ args.auth = this._getActiveAuthToken(args.auth);
2626
+ return this.agent.request(args);
2627
+ }
2628
+
2629
+ client(options = {}){
2630
+ // @ts-ignore
2631
+ return new Client(Object.assign({ api: this }, options));
2632
+ }
2633
+
2634
+ // Internal method used to target Particle's APIs other than the default
2635
+ setBaseUrl(baseUrl){
2636
+ this.baseUrl = baseUrl;
2637
+ this.agent.setBaseUrl(baseUrl);
2638
+ }
2639
+ }
2640
+
2641
+ // Aliases for backwards compatibility
2642
+ Particle.prototype.removeAccessToken = Particle.prototype.deleteAccessToken;
2643
+
2644
+ module.exports = Particle;