particle-api-js 10.1.0 → 10.3.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.
@@ -96,25 +96,25 @@ 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
- blockId: 1,
100
- runId: 1,
101
- block: {
99
+ logicFunctionId: 1,
100
+ logicRunId: 1,
101
+ logicFunction: {
102
102
  enabled: true,
103
- name: 'block-1',
103
+ name: 'function-1',
104
104
  description: 'hello world',
105
- logic: {
105
+ source: {
106
106
  type: 'JavaScript',
107
- code: 'console.log("hello from block-1");'
107
+ code: 'console.log("hello from function-1");'
108
108
  },
109
- matchers: [
109
+ logic_triggers: [
110
110
  {
111
- type: 'PubSub',
111
+ type: 'Event',
112
112
  enabled: true,
113
113
  product_id: 9001,
114
114
  event_name: 'main',
115
115
  },
116
116
  {
117
- type: 'Chron',
117
+ type: 'Scheduled',
118
118
  enabled: true,
119
119
  cron: '0 0 1 * *',
120
120
  start_at: '2021-05-15T18:29:45.000Z',
@@ -122,6 +122,19 @@ const props = {
122
122
  }
123
123
  ]
124
124
  },
125
+ logic: {
126
+ source: {
127
+ type: 'JavaScript',
128
+ code: 'export default function main() { console.log("hi"); }'
129
+ },
130
+ event: {
131
+ event_name: 'main',
132
+ device_id: '1234',
133
+ event_data: JSON.stringify({ data: true }),
134
+ product_id: 9001,
135
+ user_id: '5678'
136
+ }
137
+ },
125
138
  ledgerName: 'myledger',
126
139
  ledger: {
127
140
  scope: 'Owner',
@@ -2574,31 +2587,55 @@ describe('ParticleAPI', () => {
2574
2587
  });
2575
2588
  });
2576
2589
 
2577
- describe('.createLogicBlock', () => {
2590
+ describe('.executeLogic', () => {
2591
+ it('generates org request', () => {
2592
+ return api.executeLogic(propsWithOrg).then((results) => {
2593
+ results.should.match({
2594
+ method: 'post',
2595
+ uri: `/v1/orgs/${org}/logic/execute`,
2596
+ auth: props.auth,
2597
+ data: props.logic
2598
+ });
2599
+ });
2600
+ });
2601
+
2602
+ it('generates user request', () => {
2603
+ return api.executeLogic(props).then((results) => {
2604
+ results.should.match({
2605
+ method: 'post',
2606
+ uri: '/v1/logic/execute',
2607
+ auth: props.auth,
2608
+ data: props.logic
2609
+ });
2610
+ });
2611
+ });
2612
+ });
2613
+
2614
+ describe('.createLogicFunction', () => {
2578
2615
  it('generates request', () => {
2579
- return api.createLogicBlock(propsWithOrg).then((results) => {
2616
+ return api.createLogicFunction(propsWithOrg).then((results) => {
2580
2617
  results.should.match({
2581
2618
  method: 'post',
2582
- uri: `/v1/orgs/${org}/blocks`,
2619
+ uri: `/v1/orgs/${org}/logic/functions`,
2583
2620
  auth: props.auth,
2584
2621
  data: {
2585
- block: {
2622
+ logic_function: {
2586
2623
  enabled: true,
2587
- name: 'block-1',
2624
+ name: 'function-1',
2588
2625
  description: 'hello world',
2589
- logic: {
2626
+ source: {
2590
2627
  type: 'JavaScript',
2591
- code: 'console.log("hello from block-1");'
2628
+ code: 'console.log("hello from function-1");'
2592
2629
  },
2593
- matchers: [
2630
+ logic_triggers: [
2594
2631
  {
2595
- type: 'PubSub',
2632
+ type: 'Event',
2596
2633
  enabled: true,
2597
2634
  product_id: parseInt(props.productId),
2598
2635
  event_name: props.event,
2599
2636
  },
2600
2637
  {
2601
- type: 'Chron',
2638
+ type: 'Scheduled',
2602
2639
  enabled: true,
2603
2640
  cron: '0 0 1 * *',
2604
2641
  start_at: '2021-05-15T18:29:45.000Z',
@@ -2612,43 +2649,43 @@ describe('ParticleAPI', () => {
2612
2649
  });
2613
2650
  });
2614
2651
 
2615
- describe('.getLogicBlock', () => {
2652
+ describe('.getLogicFunction', () => {
2616
2653
  it('generates request', () => {
2617
- return api.getLogicBlock(propsWithOrg).then((results) => {
2654
+ return api.getLogicFunction(propsWithOrg).then((results) => {
2618
2655
  results.should.match({
2619
2656
  method: 'get',
2620
- uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2657
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}`,
2621
2658
  auth: props.auth
2622
2659
  });
2623
2660
  });
2624
2661
  });
2625
2662
  });
2626
2663
 
2627
- describe('.updateLogicBlock', () => {
2664
+ describe('.updateLogicFunction', () => {
2628
2665
  it('generates request', () => {
2629
- return api.updateLogicBlock(propsWithOrg).then((results) => {
2666
+ return api.updateLogicFunction(propsWithOrg).then((results) => {
2630
2667
  results.should.match({
2631
2668
  method: 'put',
2632
- uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2669
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}`,
2633
2670
  auth: props.auth,
2634
2671
  data: {
2635
- block: {
2672
+ logic_function: {
2636
2673
  enabled: true,
2637
- name: 'block-1',
2674
+ name: 'function-1',
2638
2675
  description: 'hello world',
2639
- logic: {
2676
+ source: {
2640
2677
  type: 'JavaScript',
2641
- code: 'console.log("hello from block-1");'
2678
+ code: 'console.log("hello from function-1");'
2642
2679
  },
2643
- matchers: [
2680
+ logic_triggers: [
2644
2681
  {
2645
- type: 'PubSub',
2682
+ type: 'Event',
2646
2683
  enabled: true,
2647
2684
  product_id: parseInt(props.productId),
2648
2685
  event_name: props.event,
2649
2686
  },
2650
2687
  {
2651
- type: 'Chron',
2688
+ type: 'Scheduled',
2652
2689
  enabled: true,
2653
2690
  cron: '0 0 1 * *',
2654
2691
  start_at: '2021-05-15T18:29:45.000Z',
@@ -2662,60 +2699,60 @@ describe('ParticleAPI', () => {
2662
2699
  });
2663
2700
  });
2664
2701
 
2665
- describe('.deleteLogicBlock', () => {
2702
+ describe('.deleteLogicFunction', () => {
2666
2703
  it('generates request', () => {
2667
- return api.deleteLogicBlock(propsWithOrg).then((results) => {
2704
+ return api.deleteLogicFunction(propsWithOrg).then((results) => {
2668
2705
  results.should.match({
2669
2706
  method: 'delete',
2670
- uri: `/v1/orgs/${org}/blocks/${props.blockId}`,
2707
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}`,
2671
2708
  auth: props.auth
2672
2709
  });
2673
2710
  });
2674
2711
  });
2675
2712
  });
2676
2713
 
2677
- describe('.listLogicBlocks', () => {
2714
+ describe('.listLogicFunctions', () => {
2678
2715
  it('generates request', () => {
2679
- return api.listLogicBlocks(propsWithOrg).then((results) => {
2716
+ return api.listLogicFunctions(propsWithOrg).then((results) => {
2680
2717
  results.should.match({
2681
2718
  method: 'get',
2682
- uri: `/v1/orgs/${org}/blocks`,
2719
+ uri: `/v1/orgs/${org}/logic/functions`,
2683
2720
  auth: props.auth
2684
2721
  });
2685
2722
  });
2686
2723
  });
2687
2724
  });
2688
2725
 
2689
- describe('.listBlockRuns', () => {
2726
+ describe('.listLogicRuns', () => {
2690
2727
  it('generates request', () => {
2691
- return api.listBlockRuns(propsWithOrg).then((results) => {
2728
+ return api.listLogicRuns(propsWithOrg).then((results) => {
2692
2729
  results.should.match({
2693
2730
  method: 'get',
2694
- uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs`,
2731
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}/runs`,
2695
2732
  auth: props.auth,
2696
2733
  });
2697
2734
  });
2698
2735
  });
2699
2736
  });
2700
2737
 
2701
- describe('.getBlockRun', () => {
2738
+ describe('.getLogicRun', () => {
2702
2739
  it('generates request', () => {
2703
- return api.getBlockRun(propsWithOrg).then((results) => {
2740
+ return api.getLogicRun(propsWithOrg).then((results) => {
2704
2741
  results.should.match({
2705
2742
  method: 'get',
2706
- uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}`,
2743
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}/runs/${props.logicRunId}`,
2707
2744
  auth: props.auth,
2708
2745
  });
2709
2746
  });
2710
2747
  });
2711
2748
  });
2712
2749
 
2713
- describe('.getBlockRunLog', () => {
2750
+ describe('.getLogicRunLogs', () => {
2714
2751
  it('generates request', () => {
2715
- return api.getBlockRunLog(propsWithOrg).then((results) => {
2752
+ return api.getLogicRunLogs(propsWithOrg).then((results) => {
2716
2753
  results.should.match({
2717
2754
  method: 'get',
2718
- uri: `/v1/orgs/${org}/blocks/${props.blockId}/runs/${props.runId}/logs`,
2755
+ uri: `/v1/orgs/${org}/logic/functions/${props.logicFunctionId}/runs/${props.logicRunId}/logs`,
2719
2756
  auth: props.auth,
2720
2757
  });
2721
2758
  });