particle-api-js 11.1.7 → 12.0.1

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