particle-api-js 11.1.7 → 12.0.0

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