particle-api-js 9.4.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,12 +95,49 @@ const props = {
95
95
  groups: ['foo', 'bar'],
96
96
  dateRange: '2020-05-15T18:29:45.000Z,2020-05-19T18:29:45.000Z',
97
97
  rectBl: '56.185412,-4.049868',
98
- rectTr: '56.571537,-5.385920'
98
+ rectTr: '56.571537,-5.385920',
99
+ blockId: 1,
100
+ runId: 1,
101
+ block: {
102
+ enabled: true,
103
+ name: 'block-1',
104
+ description: 'hello world',
105
+ logic: {
106
+ type: 'JavaScript',
107
+ code: 'console.log("hello from block-1");'
108
+ },
109
+ matchers: [
110
+ {
111
+ type: 'PubSub',
112
+ enabled: true,
113
+ product_id: 9001,
114
+ event_name: 'main',
115
+ },
116
+ {
117
+ type: 'Chron',
118
+ enabled: true,
119
+ cron: '0 0 1 * *',
120
+ start_at: '2021-05-15T18:29:45.000Z',
121
+ end_at: '2021-05-19T18:29:45.000Z',
122
+ }
123
+ ]
124
+ },
125
+ ledgerName: 'myledger',
126
+ ledger: {
127
+ scope: 'Owner',
128
+ name: 'myledger',
129
+ description: 'my ledger',
130
+ direction: 'Downstream'
131
+ },
132
+ scopeValue: '1234'
99
133
  };
100
134
 
101
135
  const product = 'ze-product-v1';
102
136
  const propsWithProduct = Object.assign({ product }, props);
103
137
 
138
+ const org = 'test-org';
139
+ const propsWithOrg = Object.assign({ org }, props);
140
+
104
141
  class Common {
105
142
  static expectCredentials({ form }){
106
143
  form.username.should.equal(props.username);
@@ -854,15 +891,15 @@ describe('ParticleAPI', () => {
854
891
 
855
892
  describe('.downloadFirmwareBinary', () => {
856
893
  it('generates request', () => {
857
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
894
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
858
895
  const req = api.downloadFirmwareBinary(propsWithProduct);
859
- api._provideFileData.callCount.should.equal(1);
896
+ api.request.callCount.should.equal(1);
860
897
  return req.then((results) => {
861
898
  results.should.match({
862
899
  uri: `/v1/binaries/${props.binaryId}`,
863
900
  method: 'get',
864
901
  auth: props.auth,
865
- raw: true
902
+ isBuffer: true
866
903
  });
867
904
  });
868
905
  });
@@ -1916,12 +1953,12 @@ describe('ParticleAPI', () => {
1916
1953
 
1917
1954
  describe('.downloadFile', () => {
1918
1955
  it('generates request', () => {
1919
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
1956
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
1920
1957
  const uri = 'http://example.com/path/to/file.png';
1921
1958
  const req = api.downloadFile({ uri });
1922
- api._provideFileData.callCount.should.equal(1);
1959
+ api.request.callCount.should.equal(1);
1923
1960
  return req.then((results) => {
1924
- results.should.match({ uri, method: 'get', raw: true });
1961
+ results.should.match({ uri, method: 'get', isBuffer: true });
1925
1962
  });
1926
1963
  });
1927
1964
  });
@@ -2137,17 +2174,17 @@ describe('ParticleAPI', () => {
2137
2174
 
2138
2175
  describe('.downloadProductFirmware', () => {
2139
2176
  it('generates request', () => {
2140
- sinon.stub(api, '_provideFileData').callsFake(x => Promise.resolve(x));
2177
+ sinon.stub(api, 'request').callsFake(x => Promise.resolve(x));
2141
2178
  const req = api.downloadProductFirmware(propsWithProduct);
2142
- api._provideFileData.callCount.should.equal(1);
2179
+ api.request.callCount.should.equal(1);
2143
2180
  return req.then((results) => {
2144
2181
  results.should.match({
2145
2182
  uri: `/v1/products/${product}/firmware/${props.version}/binary`,
2146
2183
  method: 'get',
2147
2184
  auth: props.auth,
2148
2185
  headers: props.headers,
2149
- context: {},
2150
- raw: true
2186
+ context: undefined,
2187
+ isBuffer: true
2151
2188
  });
2152
2189
  });
2153
2190
  });
@@ -2537,6 +2574,154 @@ describe('ParticleAPI', () => {
2537
2574
  });
2538
2575
  });
2539
2576
 
2577
+ describe('.createLogicBlock', () => {
2578
+ it('generates request', () => {
2579
+ return api.createLogicBlock(propsWithOrg).then((results) => {
2580
+ results.should.match({
2581
+ method: 'post',
2582
+ uri: `/v1/orgs/${org}/blocks`,
2583
+ auth: props.auth,
2584
+ data: {
2585
+ block: {
2586
+ enabled: true,
2587
+ name: 'block-1',
2588
+ description: 'hello world',
2589
+ logic: {
2590
+ type: 'JavaScript',
2591
+ code: 'console.log("hello from block-1");'
2592
+ },
2593
+ matchers: [
2594
+ {
2595
+ type: 'PubSub',
2596
+ enabled: true,
2597
+ product_id: parseInt(props.productId),
2598
+ event_name: props.event,
2599
+ },
2600
+ {
2601
+ type: 'Chron',
2602
+ enabled: true,
2603
+ cron: '0 0 1 * *',
2604
+ start_at: '2021-05-15T18:29:45.000Z',
2605
+ end_at: '2021-05-19T18:29:45.000Z',
2606
+ }
2607
+ ]
2608
+ }
2609
+ }
2610
+ });
2611
+ });
2612
+ });
2613
+ });
2614
+
2615
+ describe('.getLogicBlock', () => {
2616
+ it('generates request', () => {
2617
+ return api.getLogicBlock(propsWithOrg).then((results) => {
2618
+ results.should.match({
2619
+ method: 'get',
2620
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2621
+ auth: props.auth
2622
+ });
2623
+ });
2624
+ });
2625
+ });
2626
+
2627
+ describe('.updateLogicBlock', () => {
2628
+ it('generates request', () => {
2629
+ return api.updateLogicBlock(propsWithOrg).then((results) => {
2630
+ results.should.match({
2631
+ method: 'put',
2632
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2633
+ auth: props.auth,
2634
+ data: {
2635
+ block: {
2636
+ enabled: true,
2637
+ name: 'block-1',
2638
+ description: 'hello world',
2639
+ logic: {
2640
+ type: 'JavaScript',
2641
+ code: 'console.log("hello from block-1");'
2642
+ },
2643
+ matchers: [
2644
+ {
2645
+ type: 'PubSub',
2646
+ enabled: true,
2647
+ product_id: parseInt(props.productId),
2648
+ event_name: props.event,
2649
+ },
2650
+ {
2651
+ type: 'Chron',
2652
+ enabled: true,
2653
+ cron: '0 0 1 * *',
2654
+ start_at: '2021-05-15T18:29:45.000Z',
2655
+ end_at: '2021-05-19T18:29:45.000Z',
2656
+ }
2657
+ ]
2658
+ }
2659
+ }
2660
+ });
2661
+ });
2662
+ });
2663
+ });
2664
+
2665
+ describe('.deleteLogicBlock', () => {
2666
+ it('generates request', () => {
2667
+ return api.deleteLogicBlock(propsWithOrg).then((results) => {
2668
+ results.should.match({
2669
+ method: 'delete',
2670
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2671
+ auth: props.auth
2672
+ });
2673
+ });
2674
+ });
2675
+ });
2676
+
2677
+ describe('.listLogicBlocks', () => {
2678
+ it('generates request', () => {
2679
+ return api.listLogicBlocks(propsWithOrg).then((results) => {
2680
+ results.should.match({
2681
+ method: 'get',
2682
+ uri: `/v1/orgs/${org}/blocks`,
2683
+ auth: props.auth
2684
+ });
2685
+ });
2686
+ });
2687
+ });
2688
+
2689
+ describe('.listBlockRuns', () => {
2690
+ it('generates request', () => {
2691
+ return api.listBlockRuns(propsWithOrg).then((results) => {
2692
+ results.should.match({
2693
+ method: 'get',
2694
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs`,
2695
+ auth: props.auth,
2696
+ });
2697
+ });
2698
+ });
2699
+ });
2700
+
2701
+ describe('.getBlockRun', () => {
2702
+ it('generates request', () => {
2703
+ return api.getBlockRun(propsWithOrg).then((results) => {
2704
+ results.should.match({
2705
+ method: 'get',
2706
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}`,
2707
+ auth: props.auth,
2708
+ });
2709
+ });
2710
+ });
2711
+ });
2712
+
2713
+ describe('.getBlockRunLog', () => {
2714
+ it('generates request', () => {
2715
+ return api.getBlockRunLog(propsWithOrg).then((results) => {
2716
+ results.should.match({
2717
+ method: 'get',
2718
+ uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}/logs`,
2719
+ auth: props.auth,
2720
+ });
2721
+ });
2722
+ });
2723
+ });
2724
+
2540
2725
  describe('.deleteUser', () => {
2541
2726
  it('sends request to delete the current user', () => {
2542
2727
  return api.deleteUser(props).then(result => {
@@ -2550,6 +2735,135 @@ describe('ParticleAPI', () => {
2550
2735
  });
2551
2736
  });
2552
2737
  });
2738
+
2739
+ describe('.createLedger', () => {
2740
+ it('generates request', () => {
2741
+ return api.createLedger(propsWithOrg).then((results) => {
2742
+ results.should.match({
2743
+ method: 'post',
2744
+ uri: `/v1/orgs/${org}/ledgers`,
2745
+ auth: props.auth,
2746
+ data: {
2747
+ ledger: {
2748
+ scope: 'Owner',
2749
+ name: 'myledger',
2750
+ description: 'my ledger',
2751
+ direction: 'Downstream'
2752
+ }
2753
+ }
2754
+ });
2755
+ });
2756
+ });
2757
+ });
2758
+
2759
+ describe('.getLedger', () => {
2760
+ it('generates request', () => {
2761
+ return api.getLedger(propsWithOrg).then((results) => {
2762
+ results.should.match({
2763
+ method: 'get',
2764
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2765
+ auth: props.auth
2766
+ });
2767
+ });
2768
+ });
2769
+ });
2770
+
2771
+ describe('.updateLedger', () => {
2772
+ it('generates request', () => {
2773
+ return api.updateLedger(propsWithOrg).then((results) => {
2774
+ results.should.match({
2775
+ method: 'put',
2776
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2777
+ auth: props.auth,
2778
+ data: {
2779
+ ledger: {
2780
+ scope: 'Owner',
2781
+ name: 'myledger',
2782
+ description: 'my ledger',
2783
+ direction: 'Downstream'
2784
+ }
2785
+ }
2786
+ });
2787
+ });
2788
+ });
2789
+ });
2790
+
2791
+ describe('.archiveLedger', () => {
2792
+ it('generates request', () => {
2793
+ return api.archiveLedger(propsWithOrg).then((results) => {
2794
+ results.should.match({
2795
+ method: 'delete',
2796
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}`,
2797
+ auth: props.auth
2798
+ });
2799
+ });
2800
+ });
2801
+ });
2802
+
2803
+ describe('.listLedgers', () => {
2804
+ it('generates request', () => {
2805
+ return api.listLedgers(propsWithOrg).then((results) => {
2806
+ results.should.match({
2807
+ method: 'get',
2808
+ uri: `/v1/orgs/${org}/ledgers`,
2809
+ auth: props.auth
2810
+ });
2811
+ });
2812
+ });
2813
+ });
2814
+
2815
+ describe('.getLedgerInstance', () => {
2816
+ it('generates request', () => {
2817
+ return api.getLedgerInstance(propsWithOrg).then((results) => {
2818
+ results.should.match({
2819
+ method: 'get',
2820
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2821
+ auth: props.auth
2822
+ });
2823
+ });
2824
+ });
2825
+ });
2826
+
2827
+ describe('.setLedgerInstance', () => {
2828
+ it('generates request', () => {
2829
+ return api.setLedgerInstance(propsWithOrg).then((results) => {
2830
+ results.should.match({
2831
+ method: 'put',
2832
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2833
+ auth: props.auth,
2834
+ data: {
2835
+ data: {
2836
+ sentient: true
2837
+ }
2838
+ }
2839
+ });
2840
+ });
2841
+ });
2842
+ });
2843
+
2844
+ describe('.deleteLedgerInstance', () => {
2845
+ it('generates request', () => {
2846
+ return api.deleteLedgerInstance(propsWithOrg).then((results) => {
2847
+ results.should.match({
2848
+ method: 'delete',
2849
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances/${props.scopeValue}`,
2850
+ auth: props.auth
2851
+ });
2852
+ });
2853
+ });
2854
+ });
2855
+
2856
+ describe('.listLedgerInstances', () => {
2857
+ it('generates request', () => {
2858
+ return api.listLedgerInstances(propsWithOrg).then((results) => {
2859
+ results.should.match({
2860
+ method: 'get',
2861
+ uri: `/v1/orgs/${org}/ledgers/${props.ledgerName}/instances`,
2862
+ auth: props.auth
2863
+ });
2864
+ });
2865
+ });
2866
+ });
2553
2867
  });
2554
2868
 
2555
2869
  describe('backwards-compatibility function aliases', () => {
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = binaryParser;
7
- // Binary parser for superagent
8
-
9
- function binaryParser(res, fn) {
10
- /* global Buffer */
11
- var data = [];
12
- res.on('data', function (chunk) {
13
- return data.push(chunk);
14
- });
15
- res.on('end', function () {
16
- return fn(null, Buffer.concat(data));
17
- });
18
- }
19
- module.exports = exports['default'];
20
- //# sourceMappingURL=superagent-binary-parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/superagent-binary-parser.js"],"names":["binaryParser","res","fn","data","on","push","chunk","Buffer","concat"],"mappings":";;;;;kBAEwBA,Y;AAFxB;;AAEe,SAASA,YAAT,CAAsBC,GAAtB,EAA2BC,EAA3B,EAA+B;AAC7C;AACA,KAAIC,OAAO,EAAX;AACAF,KAAIG,EAAJ,CAAO,MAAP,EAAe;AAAA,SAASD,KAAKE,IAAL,CAAUC,KAAV,CAAT;AAAA,EAAf;AACAL,KAAIG,EAAJ,CAAO,KAAP,EAAc;AAAA,SAAMF,GAAG,IAAH,EAASK,OAAOC,MAAP,CAAcL,IAAd,CAAT,CAAN;AAAA,EAAd;AACA","file":"superagent-binary-parser.js","sourcesContent":["// Binary parser for superagent\n\nexport default function binaryParser(res, fn) {\n\t/* global Buffer */\n\tlet data = [];\n\tres.on('data', chunk => data.push(chunk));\n\tres.on('end', () => fn(null, Buffer.concat(data)));\n}\n"]}