particle-api-js 10.4.0 → 10.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "particle-api-js",
3
- "version": "10.4.0",
3
+ "version": "10.4.2",
4
4
  "description": "Particle API Client",
5
5
  "main": "src/Particle.js",
6
6
  "scripts": {
package/src/Agent.js CHANGED
@@ -103,7 +103,7 @@ class Agent {
103
103
  * @param {string} params.uri The URI to request
104
104
  * @param {Auth} [params.auth] Authorization token to use
105
105
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
106
- * @param {object} [params.data] Key/Value pairs of query params
106
+ * @param {object} [params.data] Request body
107
107
  * @param {object} [params.context] The invocation context, describing the tool and project
108
108
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
109
109
  */
@@ -117,12 +117,13 @@ class Agent {
117
117
  * @param {string} params.uri The URI to request
118
118
  * @param {Auth} [params.auth] Authorization token to use
119
119
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
120
- * @param {object} [params.data] Key/VAlue pairs of query params
120
+ * @param {object} [params.data] Request body
121
+ * @param {object} [params.query] Key/Value pairs of query params or a correctly formatted string
121
122
  * @param {object} [params.context] The invocation context, describing the tool and project
122
123
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
123
124
  */
124
- put({ uri, auth, headers, data, context }) {
125
- return this.request({ uri, method: 'put', auth, headers, data, context });
125
+ put({ uri, auth, headers, data, query, context }) {
126
+ return this.request({ uri, method: 'put', auth, headers, data, query, context });
126
127
  }
127
128
 
128
129
  /**
@@ -131,7 +132,7 @@ class Agent {
131
132
  * @param {string} params.uri The URI to request
132
133
  * @param {Auth} [params.auth] Authorization token to use
133
134
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
134
- * @param {object} [params.data] Key/Value pairs of query params
135
+ * @param {object} [params.data] Request body
135
136
  * @param {object} [params.context] The invocation context, describing the tool and project
136
137
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
137
138
  */
package/src/Particle.js CHANGED
@@ -2162,7 +2162,7 @@ class Particle {
2162
2162
  * @param {Object} options The options for creating the logic function.
2163
2163
  * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2164
2164
  * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2165
- * @param {string} options.logicFunction The logic function object containing the function details.
2165
+ * @param {Object} options.logicFunction The logic function object containing the function details.
2166
2166
  * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2167
2167
  * @param {Object} [options.context] Request context
2168
2168
  *
@@ -2208,7 +2208,7 @@ class Particle {
2208
2208
  * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2209
2209
  * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2210
2210
  * @param {string} options.logicFunctionId The ID of the logic function to update.
2211
- * @param {string} options.logicFunction The logic function object containing the logic function details.
2211
+ * @param {Object} options.logicFunction The logic function object containing the logic function details.
2212
2212
  * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2213
2213
  * @param {Object} [options.context] Request context.
2214
2214
  *
@@ -2275,7 +2275,7 @@ class Particle {
2275
2275
  * @param {Object} options The options for the request.
2276
2276
  * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2277
2277
  * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2278
- * @param {number} options.logicFunctionId The ID of the logic function for which to retrieve the logic runs.
2278
+ * @param {string} options.logicFunctionId The ID of the logic function for which to retrieve the logic runs.
2279
2279
  * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2280
2280
  * @param {Object} [options.context] Request context
2281
2281
  *
@@ -2296,8 +2296,8 @@ class Particle {
2296
2296
  * @param {Object} options The options for the request.
2297
2297
  * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2298
2298
  * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2299
- * @param {number} options.logicFunctionId The ID of the logic function for which to retrieve the logic run.
2300
- * @param {number} options.logicRunId The ID of the logic run to retrieve.
2299
+ * @param {string} options.logicFunctionId The ID of the logic function for which to retrieve the logic run.
2300
+ * @param {string} options.logicRunId The ID of the logic run to retrieve.
2301
2301
  * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2302
2302
  * @param {Object} [options.context] Request context
2303
2303
  *
@@ -2318,8 +2318,8 @@ class Particle {
2318
2318
  * @param {Object} options The options for the request.
2319
2319
  * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2320
2320
  * @param {string} [options.org] The unique identifier of the organization.
2321
- * @param {number} options.logicFunctionId The ID of the logic function for which to retrieve the logic run logs.
2322
- * @param {number} options.logicRunId The ID of the logic run for which to retrieve the logs.
2321
+ * @param {string} options.logicFunctionId The ID of the logic function for which to retrieve the logic run logs.
2322
+ * @param {string} options.logicRunId The ID of the logic run for which to retrieve the logs.
2323
2323
  * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2324
2324
  * @param {Object} [options.context] Request context
2325
2325
  *
@@ -2477,25 +2477,33 @@ class Particle {
2477
2477
  });
2478
2478
  }
2479
2479
 
2480
+ /**
2481
+ * @typedef {"Replace" | "Merge"} SetMode
2482
+ */
2483
+
2480
2484
  /**
2481
2485
  * Set ledger instance data.
2482
2486
  *
2483
- * @param {Object} options The options for updating the ledger instance.
2484
- * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2485
- * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2486
- * @param {string} options.ledgerName Ledger name.
2487
- * @param {string} options.scopeValue Scope value.
2488
- * @param {object} options.data The data to set to the instance
2489
- * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2490
- * @param {Object} [options.context] Request context.
2487
+ * @param {Object} options The options for updating the ledger instance.
2488
+ * @param {Auth} [options.auth] The access token or basic auth object. Can be ignored if provided in constructor
2489
+ * @param {string} [options.org] The Organization ID or slug. If not provided, the request will go to your sandbox account.
2490
+ * @param {string} options.ledgerName Ledger name.
2491
+ * @param {string} options.scopeValue Scope value.
2492
+ * @param {object} options.instance The instance with the data
2493
+ * @param {SetMode} [options.setMode] How the data should be set with existing data. Default is "Replace"
2494
+ * @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2495
+ * @param {Object} [options.context] Request context.
2491
2496
  *
2492
2497
  * @returns {Promise<RequestResponse>} A promise that resolves to the updated ledger instance data.
2493
2498
  */
2494
- setLedgerInstance({ auth, org, ledgerName, scopeValue, data, headers, context }) {
2499
+ setLedgerInstance({ auth, org, ledgerName, scopeValue, instance, setMode, headers, context }) {
2495
2500
  return this.put({
2496
2501
  uri: this._namespacedPath(org, `ledgers/${ledgerName}/instances/${scopeValue}`),
2502
+ query: {
2503
+ set_mode: setMode
2504
+ },
2497
2505
  auth,
2498
- data: { data },
2506
+ data: { instance },
2499
2507
  headers,
2500
2508
  context
2501
2509
  });
@@ -2685,7 +2693,7 @@ class Particle {
2685
2693
  * @param {string} params.uri The URI to request
2686
2694
  * @param {Auth} [params.auth] Authorization token to use
2687
2695
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2688
- * @param {string | object} [params.data] Key/Value pairs of query params or a correctly formatted string
2696
+ * @param {string | object} [params.data] Request body
2689
2697
  * @param {object} [params.context] The invocation context, describing the tool and project
2690
2698
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2691
2699
  */
@@ -2701,14 +2709,15 @@ class Particle {
2701
2709
  * @param {string} params.uri The URI to request
2702
2710
  * @param {Auth} [params.auth] Authorization token to use
2703
2711
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2704
- * @param {string | object} [params.data] Key/Value pairs of query params or a correctly formatted string
2712
+ * @param {string | object} [params.data] Request body
2713
+ * @param {object} [params.query] Key/Value pairs of query params or a correctly formatted string
2705
2714
  * @param {object} [params.context] The invocation context, describing the tool and project
2706
2715
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2707
2716
  */
2708
- put({ uri, auth, headers, data, context }){
2717
+ put({ uri, auth, headers, data, query, context }){
2709
2718
  context = this._buildContext(context);
2710
2719
  auth = this._getActiveAuthToken(auth);
2711
- return this.agent.put({ uri, auth, headers, data, context });
2720
+ return this.agent.put({ uri, auth, headers, data, query, context });
2712
2721
  }
2713
2722
 
2714
2723
  /**
@@ -2717,7 +2726,7 @@ class Particle {
2717
2726
  * @param {string} params.uri The URI to request
2718
2727
  * @param {Auth} [params.auth] Authorization token to use
2719
2728
  * @param {object} [params.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
2720
- * @param {string | object} [params.data] Key/Value pairs of query params or a correctly formatted string
2729
+ * @param {string | object} [params.data] Request body
2721
2730
  * @param {object} [params.context] The invocation context, describing the tool and project
2722
2731
  * @returns {Promise<RequestResponse, RequestError>} A promise that resolves with either the requested data or an error object
2723
2732
  */
@@ -78,8 +78,8 @@ describe('Agent', () => {
78
78
 
79
79
  it('can PUT a resource', () => {
80
80
  method = 'put';
81
- return agent.put({ uri, auth, headers, data, context }).then(() => {
82
- expect(agent.request).to.be.calledWith({ uri, method, auth, headers, data, context });
81
+ return agent.put({ uri, auth, headers, data, context, query }).then(() => {
82
+ expect(agent.request).to.be.calledWith({ uri, method, auth, headers, data, context, query });
83
83
  });
84
84
  });
85
85
 
package/test/FakeAgent.js CHANGED
@@ -11,8 +11,8 @@ class FakeAgent {
11
11
  return this.request({ uri, method: 'post', auth, headers, data, context });
12
12
  }
13
13
 
14
- put({ uri, auth, headers, data, context }){
15
- return this.request({ uri, method: 'put', auth, headers, data, context });
14
+ put({ uri, auth, headers, data, query, context }){
15
+ return this.request({ uri, method: 'put', auth, headers, data, query, context });
16
16
  }
17
17
 
18
18
  delete({ uri, auth, headers, data, context }){
@@ -20,7 +20,7 @@ class FakeAgent {
20
20
  }
21
21
 
22
22
  request(opts){
23
- return new Promise((resolve) => resolve(opts));
23
+ return Promise.resolve(opts);
24
24
  }
25
25
  }
26
26
  module.exports = FakeAgent;
@@ -66,7 +66,7 @@ const props = {
66
66
  clientId: 'client-123',
67
67
  type: 'web',
68
68
  redirect_uri: 'https://example.com',
69
- scope: '',
69
+ scope: 'Owner',
70
70
  deviceName: 'test-device',
71
71
  page: 5,
72
72
  perPage: 50,
@@ -78,7 +78,7 @@ const props = {
78
78
  notes: 'A fancy Photon',
79
79
  desiredFirmwareVersion: 42,
80
80
  flash: false,
81
- version: 42,
81
+ version: '42',
82
82
  title: 'prod',
83
83
  description: 'ready for production',
84
84
  file: new Buffer('ELF...'),
@@ -96,8 +96,8 @@ const props = {
96
96
  dateRange: '2020-05-15T18:29:45.000Z,2020-05-19T18:29:45.000Z',
97
97
  rectBl: '56.185412,-4.049868',
98
98
  rectTr: '56.571537,-5.385920',
99
- logicFunctionId: 1,
100
- logicRunId: 1,
99
+ logicFunctionId: 'ea838324-a4a7-4fa6-b278-95bdaed7114b',
100
+ logicRunId: 'd0580956-71dc-4f11-89e2-987dcf82a86f',
101
101
  logicFunction: {
102
102
  enabled: true,
103
103
  name: 'function-1',
@@ -140,9 +140,13 @@ const props = {
140
140
  scope: 'Owner',
141
141
  name: 'myledger',
142
142
  description: 'my ledger',
143
- direction: 'Downstream'
143
+ direction: 'CloudOnly'
144
144
  },
145
- scopeValue: '1234'
145
+ scopeValue: 'abc1234',
146
+ instance: {
147
+ property: 'yes'
148
+ },
149
+ setMode: 'Replace'
146
150
  };
147
151
 
148
152
  const product = 'ze-product-v1';
@@ -312,6 +316,7 @@ describe('ParticleAPI', () => {
312
316
  method: 'put',
313
317
  auth: props.auth,
314
318
  headers: props.headers,
319
+ query: undefined,
315
320
  data: {
316
321
  current_password: props.password,
317
322
  },
@@ -1459,6 +1464,7 @@ describe('ParticleAPI', () => {
1459
1464
  method: 'put',
1460
1465
  auth: 'X',
1461
1466
  headers: undefined,
1467
+ query: undefined,
1462
1468
  data: {
1463
1469
  account_info: { first_name: 'John', last_name: 'Scully' }
1464
1470
  },
@@ -1477,6 +1483,7 @@ describe('ParticleAPI', () => {
1477
1483
  method: 'put',
1478
1484
  auth: 'X',
1479
1485
  headers: undefined,
1486
+ query: undefined,
1480
1487
  data: {
1481
1488
  current_password: 'blabla',
1482
1489
  username: 'john@skul.ly'
@@ -1493,6 +1500,7 @@ describe('ParticleAPI', () => {
1493
1500
  method: 'put',
1494
1501
  auth: 'X',
1495
1502
  headers: undefined,
1503
+ query: undefined,
1496
1504
  data: {
1497
1505
  current_password: 'blabla',
1498
1506
  username: 'john@skul.ly',
@@ -1513,6 +1521,7 @@ describe('ParticleAPI', () => {
1513
1521
  method: 'put',
1514
1522
  auth: 'X',
1515
1523
  headers: undefined,
1524
+ query: undefined,
1516
1525
  data: {
1517
1526
  current_password: 'blabla',
1518
1527
  password: 'blabla2'
@@ -1530,6 +1539,7 @@ describe('ParticleAPI', () => {
1530
1539
  uri: '/v1/user',
1531
1540
  auth: 'X',
1532
1541
  headers: undefined,
1542
+ query: undefined,
1533
1543
  data: {
1534
1544
  current_password: 'blabla',
1535
1545
  password: 'blabla2',
@@ -2619,30 +2629,7 @@ describe('ParticleAPI', () => {
2619
2629
  uri: `/v1/orgs/${org}/logic/functions`,
2620
2630
  auth: props.auth,
2621
2631
  data: {
2622
- logic_function: {
2623
- enabled: true,
2624
- name: 'function-1',
2625
- description: 'hello world',
2626
- source: {
2627
- type: 'JavaScript',
2628
- code: 'console.log("hello from function-1");'
2629
- },
2630
- logic_triggers: [
2631
- {
2632
- type: 'Event',
2633
- enabled: true,
2634
- product_id: parseInt(props.productId),
2635
- event_name: props.event,
2636
- },
2637
- {
2638
- type: 'Scheduled',
2639
- enabled: true,
2640
- cron: '0 0 1 * *',
2641
- start_at: '2021-05-15T18:29:45.000Z',
2642
- end_at: '2021-05-19T18:29:45.000Z',
2643
- }
2644
- ]
2645
- }
2632
+ logic_function: props.logicFunction
2646
2633
  }
2647
2634
  });
2648
2635
  });
@@ -2669,30 +2656,7 @@ describe('ParticleAPI', () => {
2669
2656
  uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}`,
2670
2657
  auth: props.auth,
2671
2658
  data: {
2672
- logic_function: {
2673
- enabled: true,
2674
- name: 'function-1',
2675
- description: 'hello world',
2676
- source: {
2677
- type: 'JavaScript',
2678
- code: 'console.log("hello from function-1");'
2679
- },
2680
- logic_triggers: [
2681
- {
2682
- type: 'Event',
2683
- enabled: true,
2684
- product_id: parseInt(props.productId),
2685
- event_name: props.event,
2686
- },
2687
- {
2688
- type: 'Scheduled',
2689
- enabled: true,
2690
- cron: '0 0 1 * *',
2691
- start_at: '2021-05-15T18:29:45.000Z',
2692
- end_at: '2021-05-19T18:29:45.000Z',
2693
- }
2694
- ]
2695
- }
2659
+ logic_function: props.logicFunction
2696
2660
  }
2697
2661
  });
2698
2662
  });
@@ -2781,12 +2745,7 @@ describe('ParticleAPI', () => {
2781
2745
  uri: `/v1/orgs/${org}/ledgers`,
2782
2746
  auth: props.auth,
2783
2747
  data: {
2784
- ledger: {
2785
- scope: 'Owner',
2786
- name: 'myledger',
2787
- description: 'my ledger',
2788
- direction: 'Downstream'
2789
- }
2748
+ ledger: props.ledger
2790
2749
  }
2791
2750
  });
2792
2751
  });
@@ -2813,12 +2772,7 @@ describe('ParticleAPI', () => {
2813
2772
  uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2814
2773
  auth: props.auth,
2815
2774
  data: {
2816
- ledger: {
2817
- scope: 'Owner',
2818
- name: 'myledger',
2819
- description: 'my ledger',
2820
- direction: 'Downstream'
2821
- }
2775
+ ledger: props.ledger
2822
2776
  }
2823
2777
  });
2824
2778
  });
@@ -2867,11 +2821,12 @@ describe('ParticleAPI', () => {
2867
2821
  results.should.match({
2868
2822
  method: 'put',
2869
2823
  uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2824
+ query: {
2825
+ set_mode: props.setMode
2826
+ },
2870
2827
  auth: props.auth,
2871
2828
  data: {
2872
- data: {
2873
- sentient: true
2874
- }
2829
+ instance: props.instance
2875
2830
  }
2876
2831
  });
2877
2832
  });
@@ -3070,7 +3025,7 @@ describe('ParticleAPI', () => {
3070
3025
 
3071
3026
  it('calls _buildContext and _getActiveAuthToken from put', () => {
3072
3027
  api.agent.put = sinon.stub().returns(result);
3073
- const options = { uri, auth, headers, data, context };
3028
+ const options = { uri, auth, headers, data, context, query };
3074
3029
  const res = api.put(options);
3075
3030
  expect(res).to.equal(result);
3076
3031
  expect(api.agent.put).to.have.been.calledWith({
@@ -3078,6 +3033,7 @@ describe('ParticleAPI', () => {
3078
3033
  auth,
3079
3034
  headers,
3080
3035
  data,
3036
+ query,
3081
3037
  context: contextResult
3082
3038
  });
3083
3039
  });