@brimble/consul 2.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.
package/README.md ADDED
@@ -0,0 +1,2242 @@
1
+ > [!CAUTION]
2
+ > This project is no longer maintained.
3
+
4
+ # Consul
5
+
6
+ This is a [Consul][consul] client.
7
+
8
+ - [Documentation](#documentation)
9
+ - [License](#license)
10
+
11
+ ## Documentation
12
+
13
+ See the official [HTTP API][consul-docs-api] docs for more information.
14
+
15
+ - [Consul](#init)
16
+ - [Common Method Call Options](#common-options)
17
+
18
+ * [ACL](#acl)
19
+ - [Legacy](#acl-legacy)
20
+ * [Agent](#agent)
21
+ - [Check](#agent-check)
22
+ - [Service](#agent-service)
23
+ * [Catalog](#catalog)
24
+ - [Connect](#catalog-connect)
25
+ - [Node](#catalog-node)
26
+ - [Service](#catalog-service)
27
+ * [Event](#event)
28
+ * [Health](#health)
29
+ * [Intention](#intention)
30
+ * [KV](#kv)
31
+ * [Query](#query)
32
+ * [Session](#session)
33
+ * [Status](#status)
34
+ * [Transaction](#transaction)
35
+ * [Watch](#watch)
36
+
37
+ <a id="init"></a>
38
+
39
+ ### Consul([options])
40
+
41
+ Initialize a new Consul client.
42
+
43
+ Options
44
+
45
+ - host (String, default: 127.0.0.1): agent address
46
+ - port (Integer, default: 8500): agent HTTP(S) port
47
+ - secure (Boolean, default: false): enable HTTPS
48
+ - defaults (Object, optional): common method call options that will be included with every call (ex: set default `token`), these options can be override on a per call basis
49
+
50
+ Advanced options
51
+
52
+ - agent (http.Agent|https.Agent, optionals): if not set uses the global agent
53
+ - baseUrl, headers, tags, socketPath, and timeout (see [Papi](https://github.com/silas/node-papi/blob/main/README.md#client) for details)
54
+ - tls options: ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, and sessionIdContext (see [Node.js docs](https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_connect_options_callback) for details)
55
+
56
+ Usage
57
+
58
+ ```javascript
59
+ import Consul from "consul";
60
+
61
+ const consul = new Consul();
62
+ ```
63
+
64
+ <a id="common-options"></a>
65
+
66
+ ### Common Method Call Options
67
+
68
+ These options can be included with any method call, although only certain endpoints support them. See the [HTTP API][consul-docs-api] for more information.
69
+
70
+ - dc (String, optional): datacenter (defaults to local for agent)
71
+ - partition (String, optional): partition (defaults to 'default' partition)
72
+ - wan (Boolean, default: false): return WAN members instead of LAN members
73
+ - consistent (Boolean, default: false): require strong consistency
74
+ - stale (Boolean, default: false): use whatever is available, can be arbitrarily stale
75
+ - index (String, optional): used with `ModifyIndex` to block and wait for changes
76
+ - wait (String, optional): limit how long to wait for changes (ex: `5m`), used with index
77
+ - token (String, optional): ACL token
78
+ - near (String, optional): used to sort the node list in ascending order based on the estimated round trip time from that node
79
+ - node-meta (String[], optional): used to specify a desired node metadata key/value pair of the form key:value
80
+ - filter (String, optional): used to [refine a data query](https://www.consul.io/api/features/filtering.html) for some API listing endpoints
81
+
82
+ These options work for all methods.
83
+
84
+ - ctx (EventEmitter, optional): emit `cancel` to abort request
85
+ - timeout (Number|String, optional): number of milliseconds before request is aborted (ex: `1000` or `1s`)
86
+
87
+ <a id="acl"></a>
88
+
89
+ ### consul.acl
90
+
91
+ - [bootstrap](#acl-bootstrap)
92
+ - [legacy](#acl-legacy)
93
+ - [replication](#acl-replication)
94
+
95
+ <a id="acl-bootstrap"></a>
96
+
97
+ ### consul.acl.bootstrap()
98
+
99
+ Creates one-time management token if not configured.
100
+
101
+ Usage
102
+
103
+ ```javascript
104
+ await consul.acl.bootstrap();
105
+ ```
106
+
107
+ Result
108
+
109
+ ```json
110
+ {
111
+ "ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
112
+ }
113
+ ```
114
+
115
+ <a id="acl-replication"></a>
116
+
117
+ ### consul.acl.replication([options])
118
+
119
+ Get the status of the ACL replication process in the datacenter.
120
+
121
+ Usage
122
+
123
+ ```javascript
124
+ await consul.acl.replication();
125
+ ```
126
+
127
+ Result
128
+
129
+ ```json
130
+ {
131
+ "Enabled": true,
132
+ "Running": true,
133
+ "SourceDatacenter": "dc1",
134
+ "ReplicatedIndex": 1976,
135
+ "LastSuccess": "2016-08-05T06:28:58Z",
136
+ "LastError": "2016-08-05T06:28:28Z"
137
+ }
138
+ ```
139
+
140
+ <a id="acl-legacy"></a>
141
+
142
+ ### consul.acl.legacy
143
+
144
+ - [create](#acl-legacy-create)
145
+ - [update](#acl-legacy-update)
146
+ - [destroy](#acl-legacy-destroy)
147
+ - [get](#acl-legacy-get)
148
+ - [clone](#acl-legacy-clone)
149
+ - [list](#acl-legacy-list)
150
+
151
+ <a id="acl-legacy-create"></a>
152
+
153
+ ### consul.acl.legacy.create([options])
154
+
155
+ Creates a new token with policy.
156
+
157
+ Options
158
+
159
+ - name (String, optional): human readable name for the token
160
+ - type (String, enum: client, management; default: client): type of token
161
+ - rules (String, optional): string encoded HCL or JSON
162
+
163
+ Usage
164
+
165
+ ```javascript
166
+ await consul.acl.legacy.create();
167
+ ```
168
+
169
+ Result
170
+
171
+ ```json
172
+ {
173
+ "ID": "b1f4c10e-b61b-e1de-de95-218c9fefdd3e"
174
+ }
175
+ ```
176
+
177
+ <a id="acl-legacy-update"></a>
178
+
179
+ ### consul.acl.legacy.update(options)
180
+
181
+ Update the policy of a token.
182
+
183
+ Options
184
+
185
+ - id (String): token ID
186
+ - name (String, optional): human readable name for the token
187
+ - type (String, enum: client, management; default: client): type of token
188
+ - rules (String, optional): string encoded HCL or JSON
189
+
190
+ Usage
191
+
192
+ ```javascript
193
+ await consul.acl.legacy.update({
194
+ id: "63e1d82e-f718-eb92-3b7d-61f0c71d45b4",
195
+ name: "test",
196
+ });
197
+ ```
198
+
199
+ <a id="acl-legacy-destroy"></a>
200
+
201
+ ### consul.acl.legacy.destroy(options)
202
+
203
+ Destroys a given token.
204
+
205
+ Options
206
+
207
+ - id (String): token ID
208
+
209
+ Usage
210
+
211
+ ```javascript
212
+ await consul.acl.legacy.destroy("b1f4c10e-b61b-e1de-de95-218c9fefdd3e");
213
+ ```
214
+
215
+ <a id="acl-legacy-get"></a>
216
+
217
+ ### consul.acl.legacy.get(options)
218
+
219
+ Queries the policy of a given token.
220
+
221
+ Options
222
+
223
+ - id (String): token ID
224
+
225
+ Usage
226
+
227
+ ```javascript
228
+ await consul.acl.legacy.get("63e1d82e-f718-eb92-3b7d-61f0c71d45b4");
229
+ ```
230
+
231
+ Result
232
+
233
+ ```json
234
+ {
235
+ "CreateIndex": 7,
236
+ "ModifyIndex": 7,
237
+ "ID": "63e1d82e-f718-eb92-3b7d-61f0c71d45b4",
238
+ "Name": "Read only",
239
+ "Type": "client",
240
+ "Rules": "{\"key\":{\"\":{\"policy\":\"read\"}}}"
241
+ }
242
+ ```
243
+
244
+ <a id="acl-legacy-clone"></a>
245
+
246
+ ### consul.acl.legacy.clone(options)
247
+
248
+ Creates a new token by cloning an existing token.
249
+
250
+ Options
251
+
252
+ - id (String): token ID
253
+
254
+ Usage
255
+
256
+ ```javascript
257
+ await consul.acl.legacy.clone("63e1d82e-f718-eb92-3b7d-61f0c71d45b4");
258
+ ```
259
+
260
+ Result
261
+
262
+ ```json
263
+ {
264
+ "ID": "9fb8b20b-2636-adbb-9b99-d879df3305ec"
265
+ }
266
+ ```
267
+
268
+ <a id="acl-legacy-list"></a>
269
+
270
+ ### consul.acl.legacy.list([options])
271
+
272
+ Lists all the active tokens.
273
+
274
+ Usage
275
+
276
+ ```javascript
277
+ await consul.acl.legacy.list();
278
+ ```
279
+
280
+ Result
281
+
282
+ ```json
283
+ [
284
+ {
285
+ "CreateIndex": 2,
286
+ "ModifyIndex": 2,
287
+ "ID": "anonymous",
288
+ "Name": "Anonymous Token",
289
+ "Type": "client",
290
+ "Rules": ""
291
+ }
292
+ {
293
+ "CreateIndex": 3,
294
+ "ModifyIndex": 3,
295
+ "ID": "root",
296
+ "Name": "Master Token",
297
+ "Type": "management",
298
+ "Rules": ""
299
+ }
300
+ ]
301
+ ```
302
+
303
+ <a id="agent"></a>
304
+
305
+ ### consul.agent
306
+
307
+ - [check](#agent-check)
308
+ - [service](#agent-service)
309
+ - [members](#agent-members)
310
+ - [reload](#agent-reload)
311
+ - [self](#agent-self)
312
+ - [maintenance](#agent-maintenance)
313
+ - [join](#agent-join)
314
+ - [forceLeave](#agent-force-leave)
315
+
316
+ <a id="agent-members"></a>
317
+
318
+ ### consul.agent.members([options])
319
+
320
+ Returns the members as seen by the consul agent.
321
+
322
+ Options
323
+
324
+ - wan (Boolean, default: false): return WAN members instead of LAN members
325
+
326
+ Usage
327
+
328
+ ```javascript
329
+ await consul.agent.members();
330
+ ```
331
+
332
+ Result
333
+
334
+ ```json
335
+ [
336
+ {
337
+ "Name": "node1",
338
+ "Addr": "127.0.0.1",
339
+ "Port": 8301,
340
+ "Tags": {
341
+ "bootstrap": "1",
342
+ "build": "0.3.0:441d613e",
343
+ "dc": "dc1",
344
+ "port": "8300",
345
+ "role": "consul",
346
+ "vsn": "2",
347
+ "vsn_max": "2",
348
+ "vsn_min": "1"
349
+ },
350
+ "Status": 1,
351
+ "ProtocolMin": 1,
352
+ "ProtocolMax": 2,
353
+ "ProtocolCur": 2,
354
+ "DelegateMin": 2,
355
+ "DelegateMax": 4,
356
+ "DelegateCur": 4
357
+ }
358
+ ]
359
+ ```
360
+
361
+ <a id="agent-reload"></a>
362
+
363
+ ### consul.agent.reload([options])
364
+
365
+ Reload agent configuration.
366
+
367
+ Usage
368
+
369
+ ```javascript
370
+ await consul.agent.reload();
371
+ ```
372
+
373
+ <a id="agent-self"></a>
374
+
375
+ ### consul.agent.self()
376
+
377
+ Returns the agent node configuration.
378
+
379
+ Usage
380
+
381
+ ```javascript
382
+ await consul.agent.self();
383
+ ```
384
+
385
+ Result
386
+
387
+ ```json
388
+ {
389
+ "Config": {
390
+ "Bootstrap": true,
391
+ "Server": true,
392
+ "Datacenter": "dc1",
393
+ "DataDir": "/tmp/node1/data",
394
+ "DNSRecursor": "",
395
+ "DNSConfig": {
396
+ "NodeTTL": 0,
397
+ "ServiceTTL": null,
398
+ "AllowStale": false,
399
+ "MaxStale": 5000000000
400
+ },
401
+ "Domain": "consul.",
402
+ "LogLevel": "INFO",
403
+ "NodeName": "node1",
404
+ "ClientAddr": "127.0.0.1",
405
+ "BindAddr": "127.0.0.1",
406
+ "AdvertiseAddr": "127.0.0.1",
407
+ "Ports": {
408
+ "DNS": 8600,
409
+ "HTTP": 8500,
410
+ "RPC": 8400,
411
+ "SerfLan": 8301,
412
+ "SerfWan": 8302,
413
+ "Server": 8300
414
+ },
415
+ "LeaveOnTerm": false,
416
+ "SkipLeaveOnInt": false,
417
+ "StatsiteAddr": "",
418
+ "Protocol": 2,
419
+ "EnableDebug": false,
420
+ "VerifyIncoming": false,
421
+ "VerifyOutgoing": false,
422
+ "CAFile": "",
423
+ "CertFile": "",
424
+ "KeyFile": "",
425
+ "ServerName": "",
426
+ "StartJoin": [],
427
+ "UiDir": "",
428
+ "PidFile": "/tmp/node1/pid",
429
+ "EnableSyslog": false,
430
+ "SyslogFacility": "LOCAL0",
431
+ "RejoinAfterLeave": false,
432
+ "CheckUpdateInterval": 300000000000,
433
+ "Revision": "441d613e1bd96254c78c46ee7c1b35c161fc7295+CHANGES",
434
+ "Version": "0.3.0",
435
+ "VersionPrerelease": ""
436
+ },
437
+ "Member": {
438
+ "Name": "node1",
439
+ "Addr": "127.0.0.1",
440
+ "Port": 8301,
441
+ "Tags": {
442
+ "bootstrap": "1",
443
+ "build": "0.3.0:441d613e",
444
+ "dc": "dc1",
445
+ "port": "8300",
446
+ "role": "consul",
447
+ "vsn": "2",
448
+ "vsn_max": "2",
449
+ "vsn_min": "1"
450
+ },
451
+ "Status": 1,
452
+ "ProtocolMin": 1,
453
+ "ProtocolMax": 2,
454
+ "ProtocolCur": 2,
455
+ "DelegateMin": 2,
456
+ "DelegateMax": 4,
457
+ "DelegateCur": 4
458
+ }
459
+ }
460
+ ```
461
+
462
+ <a id="agent-maintenance"></a>
463
+
464
+ ### consul.agent.maintenance(options)
465
+
466
+ Set node maintenance mode.
467
+
468
+ Options
469
+
470
+ - enable (Boolean): maintenance mode enabled
471
+ - reason (String, optional): human readable reason for maintenance
472
+
473
+ Usage
474
+
475
+ ```javascript
476
+ await consul.agent.maintenance(true);
477
+ ```
478
+
479
+ <a id="agent-join"></a>
480
+
481
+ ### consul.agent.join(options)
482
+
483
+ Trigger agent to join a node.
484
+
485
+ Options
486
+
487
+ - address (String): node IP address to join
488
+ - wan (Boolean, default false): attempt to join using the WAN pool
489
+
490
+ Usage
491
+
492
+ ```javascript
493
+ await consul.agent.join("127.0.0.2");
494
+ ```
495
+
496
+ <a id="agent-force-leave"></a>
497
+
498
+ ### consul.agent.forceLeave(options)
499
+
500
+ Force remove node.
501
+
502
+ Options
503
+
504
+ - node (String): node name to remove
505
+
506
+ Usage
507
+
508
+ ```javascript
509
+ await consul.agent.forceLeave("node2");
510
+ ```
511
+
512
+ <a id="agent-check"></a>
513
+
514
+ ### consul.agent.check
515
+
516
+ - [list](#agent-check-list)
517
+ - [register](#agent-check-register)
518
+ - [deregister](#agent-check-deregister)
519
+ - [pass](#agent-check-pass)
520
+ - [warn](#agent-check-warn)
521
+ - [fail](#agent-check-fail)
522
+
523
+ <a id="agent-check-list"></a>
524
+
525
+ ### consul.agent.check.list()
526
+
527
+ Returns the checks the agent is managing.
528
+
529
+ Usage
530
+
531
+ ```javascript
532
+ await consul.agent.check.list();
533
+ ```
534
+
535
+ Result
536
+
537
+ ```json
538
+ {
539
+ "example": {
540
+ "Node": "node1",
541
+ "CheckID": "example",
542
+ "Name": "example",
543
+ "Status": "passing",
544
+ "Notes": "This is an example check.",
545
+ "Output": "",
546
+ "ServiceID": "",
547
+ "ServiceName": ""
548
+ }
549
+ }
550
+ ```
551
+
552
+ <a id="agent-check-register"></a>
553
+
554
+ ### consul.agent.check.register(options)
555
+
556
+ Registers a new check.
557
+
558
+ Options
559
+
560
+ - name (String): check name
561
+ - id (String, optional): check ID
562
+ - serviceid (String, optional): service ID, associate check with existing service
563
+ - http (String): url to test, 2xx passes, 429 warns, and all others fail
564
+ - tlsskipverify (Boolean, default: false): skip HTTPS verification
565
+ - tcp (String): host:port to test, passes if connection is established, fails otherwise
566
+ - args (String[]): path to check script, requires interval
567
+ - script (String): path to check script, requires interval (DEPRECATED)
568
+ - dockercontainerid (String, optional): Docker container ID to run script
569
+ - grpc (String, optional): gRPC endpoint (ex: `127.0.0.1:12345`)
570
+ - grpcusetls (Boolean, optional): enable TLS for gRPC check
571
+ - shell (String, optional): shell in which to run script (currently only supported with Docker)
572
+ - interval (String): interval to run check, requires script (ex: `15s`)
573
+ - timeout (String, optional): timeout for the check (ex: `10s`)
574
+ - ttl (String): time to live before check must be updated (ex: `60s`)
575
+ - aliasnode (String): ID of a node for an alias check (ex: `web1`)
576
+ - aliasservice (String): ID of a service for an alias check (ex: `web`)
577
+ - notes (String, optional): human readable description of check
578
+ - status (String, optional): initial service status
579
+ - deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after
580
+ which to automatically deregister service if check remains in critical state
581
+ - successbeforepassing (Number, optional): number of consecutive successful
582
+ results required before check status transitions to passing
583
+ - failuresbeforecritical (Number, optional): number of consecutive unsuccessful
584
+ results required before check status transitions to critical
585
+
586
+ Usage
587
+
588
+ ```javascript
589
+ await consul.agent.check.register({
590
+ name: "example",
591
+ ttl: "15s",
592
+ notes: "This is an example check.",
593
+ });
594
+ ```
595
+
596
+ <a id="agent-check-deregister"></a>
597
+
598
+ ### consul.agent.check.deregister(options)
599
+
600
+ Deregister a check.
601
+
602
+ Options
603
+
604
+ - id (String): check ID
605
+
606
+ Usage
607
+
608
+ ```javascript
609
+ await consul.agent.check.deregister("example");
610
+ ```
611
+
612
+ <a id="agent-check-pass"></a>
613
+
614
+ ### consul.agent.check.pass(options)
615
+
616
+ Mark a test as passing.
617
+
618
+ Options
619
+
620
+ - id (String): check ID
621
+ - note (String, optional): human readable message
622
+
623
+ Usage
624
+
625
+ ```javascript
626
+ await consul.agent.check.pass("example");
627
+ ```
628
+
629
+ <a id="agent-check-warn"></a>
630
+
631
+ ### consul.agent.check.warn(options)
632
+
633
+ Mark a test as warning.
634
+
635
+ Options
636
+
637
+ - id (String): check ID
638
+ - note (String, optional): human readable message
639
+
640
+ Usage
641
+
642
+ ```javascript
643
+ await consul.agent.check.warn("example");
644
+ ```
645
+
646
+ <a id="agent-check-fail"></a>
647
+
648
+ ### consul.agent.check.fail(options)
649
+
650
+ Mark a test as critical.
651
+
652
+ Options
653
+
654
+ - id (String): check ID
655
+ - note (String, optional): human readable message
656
+
657
+ Usage
658
+
659
+ ```javascript
660
+ await consul.agent.check.fail("example");
661
+ ```
662
+
663
+ <a id="agent-service"></a>
664
+
665
+ ### consul.agent.service
666
+
667
+ - [list](#agent-service-list)
668
+ - [register](#agent-service-register)
669
+ - [deregister](#agent-service-deregister)
670
+ - [maintenance](#agent-service-maintenance)
671
+
672
+ <a id="agent-service-list"></a>
673
+
674
+ ### consul.agent.service.list()
675
+
676
+ Returns the services the agent is managing.
677
+
678
+ Usage
679
+
680
+ ```javascript
681
+ await consul.agent.service.list();
682
+ ```
683
+
684
+ Result
685
+
686
+ ```json
687
+ {
688
+ "example": {
689
+ "ID": "example",
690
+ "Service": "example",
691
+ "Tags": ["dev", "web"],
692
+ "Port": 80
693
+ }
694
+ }
695
+ ```
696
+
697
+ <a id="agent-service-register"></a>
698
+
699
+ ### consul.agent.service.register(options)
700
+
701
+ Registers a new service.
702
+
703
+ Options
704
+
705
+ - name (String): service name
706
+ - id (String, optional): service ID
707
+ - tags (String[], optional): service tags
708
+ - address (String, optional): service IP address
709
+ - port (Integer, optional): service port
710
+ - meta (Object, optional): metadata linked to the service instance
711
+ - check (Object, optional): service check
712
+ - http (String): URL endpoint, requires interval
713
+ - tcp (String): host:port to test, passes if connection is established, fails otherwise
714
+ - script (String): path to check script, requires interval
715
+ - dockercontainerid (String, optional): Docker container ID to run script
716
+ - shell (String, optional): shell in which to run script (currently only supported with Docker)
717
+ - interval (String): interval to run check, requires script (ex: `15s`)
718
+ - timeout (String, optional): timeout for the check (ex: `10s`)
719
+ - ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: `60s`)
720
+ - notes (String, optional): human readable description of check
721
+ - status (String, optional): initial service status
722
+ - deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after
723
+ which to automatically deregister service if check remains in critical state
724
+ - checks (Object[], optional): service checks (see `check` above)
725
+ - connect (Object, optional): specifies the [configuration](https://www.consul.io/api/agent/service.html#connect-structure) for Connect
726
+ - proxy (Object, optional): specifies the [configuration](https://www.consul.io/docs/connect/registration/service-registration.html) for a Connect proxy instance
727
+ - taggedAddresses (Object, optional): specifies a map of explicit LAN and WAN addresses for the service instance
728
+
729
+ Usage
730
+
731
+ ```javascript
732
+ await consul.agent.service.register("example");
733
+ ```
734
+
735
+ <a id="agent-service-deregister"></a>
736
+
737
+ ### consul.agent.service.deregister(options)
738
+
739
+ Deregister a service.
740
+
741
+ Options
742
+
743
+ - id (String): service ID
744
+
745
+ Usage
746
+
747
+ ```javascript
748
+ await consul.agent.service.deregister("example");
749
+ ```
750
+
751
+ <a id="agent-service-maintenance"></a>
752
+
753
+ ### consul.agent.service.maintenance(options)
754
+
755
+ Set service maintenance mode.
756
+
757
+ Options
758
+
759
+ - id (String): service ID
760
+ - enable (Boolean): maintenance mode enabled
761
+ - reason (String, optional): human readable reason for maintenance
762
+
763
+ Usage
764
+
765
+ ```javascript
766
+ await consul.agent.service.maintenance({ id: "example", enable: true });
767
+ ```
768
+
769
+ <a id="catalog"></a>
770
+
771
+ ### consul.catalog
772
+
773
+ - [register](#catalog-register)
774
+ - [deregister](#catalog-deregister)
775
+ - [datacenters](#catalog-datacenters)
776
+ - [connect](#catalog-connect)
777
+ - [node](#catalog-node)
778
+ - [service](#catalog-service)
779
+
780
+ <a id="catalog-register"></a>
781
+
782
+ ### consul.catalog.register(options)
783
+
784
+ Registers or updates entries in the catalog.
785
+
786
+ NOTE: this endpoint is a low-level mechanism for registering or updating entries in the catalog. It is usually preferable to instead use the agent endpoints for registration as they are simpler and perform anti-entropy. It is suggested to read the [catalog API](https://developer.hashicorp.com/consul/api-docs/catalog) documentation before using that.
787
+
788
+ Options
789
+
790
+ - id (String, optional): an optional UUID to assign to the node. This must be a 36-character UUID-formatted string
791
+ - node (String, required): specifies the node ID to register
792
+ - address (String, required): specifies the address to register.
793
+ - taggedaddresses (Object, optional): specifies the tagged addresses
794
+ - nodemeta (Object, optional): specifies arbitrary KV metadata pairs for filtering purposes
795
+ - service (Objet, optional): specifies to register a service
796
+ - id (String): service ID. If ID is not provided, it will be defaulted to the value of the Service.Service property.
797
+ Only one service with a given ID may be present per node.
798
+ - service (String): service name
799
+ - tags (String[], optional): service tags
800
+ - meta (Object, optional): metadata linked to the service instance
801
+ - address (String): service IP address
802
+ - port (Integer): service port
803
+ - check (Object, optional): specifies to register a check.The register API manipulates the health check entry in the Catalog, but it does not setup the
804
+ TCP/HTTP check to monitor the node's health.
805
+ - node (String): the node id this check will bind to
806
+ - name (String): check name
807
+ - checkid (String): the CheckID can be omitted and will default to the value of Name. The CheckID must be unique on this node.
808
+ - serviceid (String): if a ServiceID is provided that matches the ID of a service on that node, the check is treated as a service level health check, instead of a node level health check.
809
+ - notes (String): notes is an opaque field that is meant to hold human-readable text
810
+ - status (String): initial status. The Status must be one of `passing`, `warning`, or `critical`.
811
+ - definition (Object): health check definition
812
+ - http (String): URL endpoint, requires interval
813
+ - tlsskipverify (Boolean, default: false): skip HTTPS verification
814
+ - tlsservername (String): SNI
815
+ - tcp (String): host:port to test, passes if connection is established, fails otherwise
816
+ - intervalduration (String): interval to run check, requires script (ex: `15s`)
817
+ - timeoutduration (String): timeout for the check (ex: `10s`)
818
+ - deregistercriticalserviceafterduration (String): timeout after
819
+ which to automatically deregister service if check remains in critical state (ex: `120s`)
820
+ - checks (Object[], optional): multiple checks can be provided by replacing `check` with `checks` and sending an array of `check` objects.
821
+ - skipnodeupdate (Bool, optional): pecifies whether to skip updating the node's information in the registration. Note, if the parameter is enabled for a node that doesn't exist, it will still be created
822
+
823
+ Usage
824
+
825
+ ```javascript
826
+ await consul.catalog.register("example");
827
+ ```
828
+
829
+ <a id="catalog-deregister"></a>
830
+
831
+ ### consul.catalog.deregister(options)
832
+
833
+ Deregister entries in the catalog.
834
+
835
+ NOTE:This endpoint is a low-level mechanism for directly removing entries from the Catalog. It is usually preferable to instead use the agent endpoints for deregistration as they are simpler and perform anti-entropy. It is suggested to read the [catalog API](https://developer.hashicorp.com/consul/api-docs/catalog) documentation before using that.
836
+
837
+ Options
838
+
839
+ - node (String, required): specifies the ID of the node. If no other values are provided, this node, all its services, and all its checks are removed.
840
+ - checkid (String, optional): specifies the ID of the check to remove.
841
+ - serviceid (String, optional): specifies the ID of the service to remove. The service and all associated checks will be removed.
842
+
843
+ Usage
844
+
845
+ ```javascript
846
+ await consul.catalog.deregister("example");
847
+ ```
848
+
849
+ or
850
+
851
+ ```javascript
852
+ await consul.catalog.deregister({ id: "example" });
853
+ ```
854
+
855
+ <a id="catalog-datacenters"></a>
856
+
857
+ ### consul.catalog.datacenters()
858
+
859
+ Lists known datacenters.
860
+
861
+ Usage
862
+
863
+ ```javascript
864
+ await consul.catalog.datacenters();
865
+ ```
866
+
867
+ Result
868
+
869
+ ```json
870
+ ["dc1"]
871
+ ```
872
+
873
+ <a id="catalog-connect"></a>
874
+
875
+ ### consul.catalog.connect
876
+
877
+ - [nodes](#catalog-connect-nodes)
878
+
879
+ <a id="catalog-connect-nodes"></a>
880
+
881
+ ### consul.catalog.connect.nodes(options)
882
+
883
+ Lists the nodes for a given Connect-capable service.
884
+
885
+ Options
886
+
887
+ - service (String): service name
888
+ - dc (String, optional): datacenter (defaults to local for agent)
889
+
890
+ Usage
891
+
892
+ ```javascript
893
+ await consul.catalog.connect.nodes("example");
894
+ ```
895
+
896
+ Result
897
+
898
+ ```json
899
+ [
900
+ {
901
+ "ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
902
+ "Node": "foobar",
903
+ "Address": "192.168.10.10",
904
+ "Datacenter": "dc1",
905
+ "TaggedAddresses": {
906
+ "lan": "192.168.10.10",
907
+ "wan": "10.0.10.10"
908
+ },
909
+ "NodeMeta": {
910
+ "somekey": "somevalue"
911
+ },
912
+ "CreateIndex": 51,
913
+ "ModifyIndex": 51,
914
+ "ServiceAddress": "172.17.0.3",
915
+ "ServiceEnableTagOverride": false,
916
+ "ServiceID": "32a2a47f7992:nodea:5000",
917
+ "ServiceName": "foobar",
918
+ "ServiceKind": "connect-proxy",
919
+ "ServiceProxyDestination": "my-service",
920
+ "ServicePort": 5000,
921
+ "ServiceMeta": {
922
+ "foobar_meta_value": "baz"
923
+ },
924
+ "ServiceTags": ["tacos"]
925
+ }
926
+ ]
927
+ ```
928
+
929
+ <a id="catalog-node"></a>
930
+
931
+ ### consul.catalog.node
932
+
933
+ - [list](#catalog-node-list)
934
+ - [services](#catalog-node-services)
935
+
936
+ <a id="catalog-node-list"></a>
937
+
938
+ ### consul.catalog.node.list([options])
939
+
940
+ Lists nodes in a given datacenter.
941
+
942
+ Options
943
+
944
+ - dc (String, optional): datacenter (defaults to local for agent)
945
+
946
+ Usage
947
+
948
+ ```javascript
949
+ await consul.catalog.node.list();
950
+ ```
951
+
952
+ Result
953
+
954
+ ```json
955
+ [
956
+ {
957
+ "Node": "node1",
958
+ "Address": "127.0.0.1"
959
+ }
960
+ ]
961
+ ```
962
+
963
+ <a id="catalog-node-services"></a>
964
+
965
+ ### consul.catalog.node.services(options)
966
+
967
+ Lists the services provided by a node.
968
+
969
+ Options
970
+
971
+ - node (String): node ID
972
+
973
+ Usage
974
+
975
+ ```javascript
976
+ await consul.catalog.node.services("node1");
977
+ ```
978
+
979
+ Result
980
+
981
+ ```json
982
+ {
983
+ "Node": {
984
+ "Node": "node1",
985
+ "Address": "127.0.0.1"
986
+ },
987
+ "Services": {
988
+ "consul": {
989
+ "ID": "consul",
990
+ "Service": "consul",
991
+ "Tags": [],
992
+ "Port": 8300
993
+ },
994
+ "example": {
995
+ "ID": "example",
996
+ "Service": "example",
997
+ "Tags": ["dev", "web"],
998
+ "Port": 80
999
+ }
1000
+ }
1001
+ }
1002
+ ```
1003
+
1004
+ <a id="catalog-service"></a>
1005
+
1006
+ ### consul.catalog.service
1007
+
1008
+ - [list](#catalog-service-list)
1009
+ - [nodes](#catalog-service-nodes)
1010
+
1011
+ <a id="catalog-service-list"></a>
1012
+
1013
+ ### consul.catalog.service.list([options])
1014
+
1015
+ Lists services in a given datacenter.
1016
+
1017
+ Options
1018
+
1019
+ - dc (String): datacenter (defaults to local for agent)
1020
+
1021
+ Usage
1022
+
1023
+ ```javascript
1024
+ await consul.catalog.service.list();
1025
+ ```
1026
+
1027
+ Result
1028
+
1029
+ ```json
1030
+ {
1031
+ "consul": [],
1032
+ "example": ["dev", "web"]
1033
+ }
1034
+ ```
1035
+
1036
+ <a id="catalog-service-nodes"></a>
1037
+
1038
+ ### consul.catalog.service.nodes(options)
1039
+
1040
+ Lists the nodes for a given service.
1041
+
1042
+ Options
1043
+
1044
+ - service (String): service name
1045
+ - dc (String, optional): datacenter (defaults to local for agent)
1046
+ - tag (String, optional): filter by tag
1047
+
1048
+ Usage
1049
+
1050
+ ```javascript
1051
+ await consul.catalog.service.nodes("example");
1052
+ ```
1053
+
1054
+ Result
1055
+
1056
+ ```json
1057
+ [
1058
+ {
1059
+ "Node": "node1",
1060
+ "Address": "127.0.0.1",
1061
+ "ServiceID": "example",
1062
+ "ServiceName": "example",
1063
+ "ServiceTags": ["dev", "web"],
1064
+ "ServicePort": 80
1065
+ }
1066
+ ]
1067
+ ```
1068
+
1069
+ <a id="event"></a>
1070
+
1071
+ ### consul.event
1072
+
1073
+ - [fire](#event-fire)
1074
+ - [list](#event-list)
1075
+
1076
+ <a id="event-fire"></a>
1077
+
1078
+ ### consul.event.fire(options)
1079
+
1080
+ Fires a new user event.
1081
+
1082
+ Options
1083
+
1084
+ - name (String): event name
1085
+ - payload (String|Buffer): payload
1086
+ - node (String, optional): regular expression to filter by node
1087
+ - service (String, optional): regular expression to filter by service
1088
+ - tag (String, optional): regular expression to filter by tag
1089
+
1090
+ Usage
1091
+
1092
+ ```javascript
1093
+ await consul.event.fire("deploy", "53");
1094
+ ```
1095
+
1096
+ Result
1097
+
1098
+ ```json
1099
+ {
1100
+ "ID": "4730953b-3135-7ff2-47a7-9d9fc9c4e5a2",
1101
+ "Name": "deploy",
1102
+ "Payload": "53",
1103
+ "NodeFilter": "",
1104
+ "ServiceFilter": "",
1105
+ "TagFilter": "",
1106
+ "Version": 1,
1107
+ "LTime": 0
1108
+ }
1109
+ ```
1110
+
1111
+ <a id="event-list"></a>
1112
+
1113
+ ### consul.event.list([options])
1114
+
1115
+ Lists the most recent events an agent has seen.
1116
+
1117
+ Options
1118
+
1119
+ - name (String, optional): filter by event name
1120
+
1121
+ Usage
1122
+
1123
+ ```javascript
1124
+ await consul.event.list("deploy");
1125
+ ```
1126
+
1127
+ Result
1128
+
1129
+ ```json
1130
+ [
1131
+ {
1132
+ "ID": "4730953b-3135-7ff2-47a7-9d9fc9c4e5a2",
1133
+ "Name": "deploy",
1134
+ "Payload": "53",
1135
+ "NodeFilter": "",
1136
+ "ServiceFilter": "",
1137
+ "TagFilter": "",
1138
+ "Version": 1,
1139
+ "LTime": 2
1140
+ }
1141
+ ]
1142
+ ```
1143
+
1144
+ <a id="health"></a>
1145
+
1146
+ ### consul.health
1147
+
1148
+ - [node](#health-node)
1149
+ - [checks](#health-checks)
1150
+ - [service](#health-service)
1151
+ - [state](#health-state)
1152
+
1153
+ <a id="health-node"></a>
1154
+
1155
+ ### consul.health.node(options)
1156
+
1157
+ Returns the health info of a node.
1158
+
1159
+ Options
1160
+
1161
+ - node (String): node
1162
+ - dc (String, optional): datacenter (defaults to local for agent)
1163
+
1164
+ Usage
1165
+
1166
+ ```javascript
1167
+ await consul.health.node("node1");
1168
+ ```
1169
+
1170
+ Result
1171
+
1172
+ ```json
1173
+ [
1174
+ {
1175
+ "Node": "node1",
1176
+ "CheckID": "serfHealth",
1177
+ "Name": "Serf Health Status",
1178
+ "Status": "passing",
1179
+ "Notes": "",
1180
+ "Output": "Agent alive and reachable",
1181
+ "ServiceID": "",
1182
+ "ServiceName": ""
1183
+ },
1184
+ {
1185
+ "Node": "node1",
1186
+ "CheckID": "service:example",
1187
+ "Name": "Service 'example' check",
1188
+ "Status": "critical",
1189
+ "Notes": "",
1190
+ "Output": "",
1191
+ "ServiceID": "example",
1192
+ "ServiceName": "example"
1193
+ }
1194
+ ]
1195
+ ```
1196
+
1197
+ <a id="health-checks"></a>
1198
+
1199
+ ### consul.health.checks(options)
1200
+
1201
+ Returns the checks of a service.
1202
+
1203
+ Options
1204
+
1205
+ - service (String): service name
1206
+ - dc (String, optional): datacenter (defaults to local for agent)
1207
+
1208
+ Usage
1209
+
1210
+ ```javascript
1211
+ await consul.health.checks("example");
1212
+ ```
1213
+
1214
+ Result
1215
+
1216
+ ```json
1217
+ [
1218
+ {
1219
+ "Node": "node1",
1220
+ "CheckID": "service:example",
1221
+ "Name": "Service 'example' check",
1222
+ "Status": "critical",
1223
+ "Notes": "",
1224
+ "Output": "",
1225
+ "ServiceID": "example",
1226
+ "ServiceName": "example"
1227
+ }
1228
+ ]
1229
+ ```
1230
+
1231
+ <a id="health-service"></a>
1232
+
1233
+ ### consul.health.service(options)
1234
+
1235
+ Returns the nodes and health info of a service.
1236
+
1237
+ Options
1238
+
1239
+ - service (String): service name
1240
+ - dc (String, optional): datacenter (defaults to local for agent)
1241
+ - tag (String, optional): filter by tag
1242
+ - passing (Boolean, optional): restrict to passing checks
1243
+
1244
+ Usage
1245
+
1246
+ ```javascript
1247
+ await consul.health.service("example");
1248
+ ```
1249
+
1250
+ Result
1251
+
1252
+ ```json
1253
+ [
1254
+ {
1255
+ "Node": {
1256
+ "Node": "node1",
1257
+ "Address": "127.0.0.1"
1258
+ },
1259
+ "Service": {
1260
+ "ID": "example",
1261
+ "Service": "example",
1262
+ "Tags": [],
1263
+ "Port": 0
1264
+ },
1265
+ "Checks": [
1266
+ {
1267
+ "Node": "node1",
1268
+ "CheckID": "service:example",
1269
+ "Name": "Service 'example' check",
1270
+ "Status": "critical",
1271
+ "Notes": "",
1272
+ "Output": "",
1273
+ "ServiceID": "example",
1274
+ "ServiceName": "example"
1275
+ },
1276
+ {
1277
+ "Node": "node1",
1278
+ "CheckID": "serfHealth",
1279
+ "Name": "Serf Health Status",
1280
+ "Status": "passing",
1281
+ "Notes": "",
1282
+ "Output": "Agent alive and reachable",
1283
+ "ServiceID": "",
1284
+ "ServiceName": ""
1285
+ }
1286
+ ]
1287
+ }
1288
+ ]
1289
+ ```
1290
+
1291
+ <a id="health-state"></a>
1292
+
1293
+ ### consul.health.state(options)
1294
+
1295
+ Returns the checks in a given state.
1296
+
1297
+ Options
1298
+
1299
+ - state (String, enum: any, passing, warning, critical): state
1300
+ - dc (String, optional): datacenter (defaults to local for agent)
1301
+
1302
+ Usage
1303
+
1304
+ ```javascript
1305
+ await consul.health.state("critical");
1306
+ ```
1307
+
1308
+ Result
1309
+
1310
+ ```json
1311
+ [
1312
+ {
1313
+ "Node": "node1",
1314
+ "CheckID": "service:example",
1315
+ "Name": "Service 'example' check",
1316
+ "Status": "critical",
1317
+ "Notes": "",
1318
+ "Output": "",
1319
+ "ServiceID": "example",
1320
+ "ServiceName": "example"
1321
+ }
1322
+ ]
1323
+ ```
1324
+
1325
+ <a id="intention"></a>
1326
+
1327
+ ### consul.intention
1328
+
1329
+ - [list](#intention-list)
1330
+ - [create](#intention-create)
1331
+ - [get](#intention-get)
1332
+ - [update](#intention-update)
1333
+ - [destroy](#intention-destroy)
1334
+
1335
+ <a id="intention-list"></a>
1336
+
1337
+ ### consul.intention.list([options])
1338
+
1339
+ List all Connect intentions.
1340
+
1341
+ Options
1342
+
1343
+ - dc (String, optional): datacenter (defaults to local for agent)
1344
+
1345
+ Usage
1346
+
1347
+ ```javascript
1348
+ await consul.intention.list();
1349
+ ```
1350
+
1351
+ Result
1352
+
1353
+ ```json
1354
+ [
1355
+ {
1356
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
1357
+ "SourceName": "web",
1358
+ "DestinationName": "db",
1359
+ "SourceType": "",
1360
+ "Action": "allow",
1361
+ "Description": "",
1362
+ "Meta": null,
1363
+ "Precedence": 9,
1364
+ "CreateIndex": 11,
1365
+ "ModifyIndex": 12
1366
+ }
1367
+ ]
1368
+ ```
1369
+
1370
+ <a id="intention-create"></a>
1371
+
1372
+ ### consul.intention.create(options)
1373
+
1374
+ Create a new Connect intention.
1375
+
1376
+ Options
1377
+
1378
+ - sourcename (String, required): source service name
1379
+ - destinationname (String, required): destination service name
1380
+ - action (String, enum: allow, deny; required): action to take
1381
+ - description (String, optional): human readable description
1382
+ - sourcetype (String, optional): source type (e.g., "consul")
1383
+ - meta (Object, optional): metadata key/value pairs
1384
+ - precedence (Number, optional): precedence for the intention
1385
+ - permissions (Array, optional): L7 permissions for application-aware intentions
1386
+ - dc (String, optional): datacenter (defaults to local for agent)
1387
+
1388
+ Usage
1389
+
1390
+ ```javascript
1391
+ await consul.intention.create({
1392
+ sourcename: "web",
1393
+ destinationname: "db",
1394
+ action: "allow",
1395
+ description: "Allow web service to access database",
1396
+ });
1397
+ ```
1398
+
1399
+ Result
1400
+
1401
+ ```json
1402
+ {
1403
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1"
1404
+ }
1405
+ ```
1406
+
1407
+ <a id="intention-get"></a>
1408
+
1409
+ ### consul.intention.get(options)
1410
+
1411
+ Get a specific Connect intention.
1412
+
1413
+ Options
1414
+
1415
+ - id (String, required): intention ID
1416
+ - dc (String, optional): datacenter (defaults to local for agent)
1417
+
1418
+ Usage
1419
+
1420
+ ```javascript
1421
+ await consul.intention.get("a0f5dc05-84c3-5f5a-1d88-05b875e524e1");
1422
+ ```
1423
+
1424
+ Result
1425
+
1426
+ ```json
1427
+ {
1428
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
1429
+ "SourceName": "web",
1430
+ "DestinationName": "db",
1431
+ "SourceType": "",
1432
+ "Action": "allow",
1433
+ "Description": "Allow web service to access database",
1434
+ "Meta": null,
1435
+ "Precedence": 9,
1436
+ "CreateIndex": 11,
1437
+ "ModifyIndex": 12
1438
+ }
1439
+ ```
1440
+
1441
+ <a id="intention-update"></a>
1442
+
1443
+ ### consul.intention.update(options)
1444
+
1445
+ Update an existing Connect intention.
1446
+
1447
+ Options
1448
+
1449
+ - id (String, required): intention ID
1450
+ - sourcename (String, required): source service name
1451
+ - destinationname (String, required): destination service name
1452
+ - action (String, enum: allow, deny; required): action to take
1453
+ - description (String, optional): human readable description
1454
+ - sourcetype (String, optional): source type (e.g., "consul")
1455
+ - meta (Object, optional): metadata key/value pairs
1456
+ - precedence (Number, optional): precedence for the intention
1457
+ - permissions (Array, optional): L7 permissions for application-aware intentions
1458
+ - dc (String, optional): datacenter (defaults to local for agent)
1459
+
1460
+ Usage
1461
+
1462
+ ```javascript
1463
+ await consul.intention.update({
1464
+ id: "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
1465
+ sourcename: "web",
1466
+ destinationname: "db",
1467
+ action: "deny",
1468
+ description: "Block web service from accessing database",
1469
+ });
1470
+ ```
1471
+
1472
+ <a id="intention-destroy"></a>
1473
+
1474
+ ### consul.intention.destroy(options)
1475
+
1476
+ Delete a Connect intention.
1477
+
1478
+ Options
1479
+
1480
+ - id (String, required): intention ID
1481
+ - dc (String, optional): datacenter (defaults to local for agent)
1482
+
1483
+ Usage
1484
+
1485
+ ```javascript
1486
+ await consul.intention.destroy("a0f5dc05-84c3-5f5a-1d88-05b875e524e1");
1487
+ ```
1488
+
1489
+ <a id="kv"></a>
1490
+
1491
+ ### consul.kv
1492
+
1493
+ - [get](#kv-get)
1494
+ - [keys](#kv-keys)
1495
+ - [set](#kv-set)
1496
+ - [del](#kv-del)
1497
+
1498
+ <a id="kv-get"></a>
1499
+
1500
+ ### consul.kv.get(options)
1501
+
1502
+ Return key/value (kv) pair(s) or `undefined` if key not found.
1503
+
1504
+ Options
1505
+
1506
+ - key (String): path to value
1507
+ - dc (String, optional): datacenter (defaults to local for agent)
1508
+ - recurse (Boolean, default: false): return all keys with given key prefix
1509
+ - index (String, optional): used with `ModifyIndex` to block and wait for changes
1510
+ - wait (String, optional): limit how long to wait for changes (ex: `5m`), used with index
1511
+ - raw (Boolean, optional): return raw value (can't be used with recursive, implies buffer)
1512
+ - buffer (Boolean, default: false): decode value into Buffer instead of String
1513
+
1514
+ Usage
1515
+
1516
+ ```javascript
1517
+ await consul.kv.get("hello");
1518
+ ```
1519
+
1520
+ Result
1521
+
1522
+ ```json
1523
+ {
1524
+ "CreateIndex": 6,
1525
+ "ModifyIndex": 6,
1526
+ "LockIndex": 0,
1527
+ "Key": "hello",
1528
+ "Flags": 0,
1529
+ "Value": "world"
1530
+ }
1531
+ ```
1532
+
1533
+ <a id="kv-keys"></a>
1534
+
1535
+ ### consul.kv.keys(options)
1536
+
1537
+ Return keys for a given prefix.
1538
+
1539
+ Options
1540
+
1541
+ - key (String): path prefix
1542
+ - dc (String, optional): datacenter (defaults to local for agent)
1543
+ - separator (String, optional): list keys up to a given separator
1544
+
1545
+ Usage
1546
+
1547
+ ```javascript
1548
+ await consul.kv.keys("a/");
1549
+ ```
1550
+
1551
+ Result
1552
+
1553
+ ```json
1554
+ ["a/b", "a/c"]
1555
+ ```
1556
+
1557
+ <a id="kv-set"></a>
1558
+
1559
+ ### consul.kv.set(options)
1560
+
1561
+ Set key/value (kv) pair.
1562
+
1563
+ Options
1564
+
1565
+ - key (String): key
1566
+ - value (String|Buffer): value
1567
+ - dc (String, optional): datacenter (defaults to local for agent)
1568
+ - flags (Number, optional): unsigned integer opaque to user, can be used by application
1569
+ - cas (String, optional): use with `ModifyIndex` to do a check-and-set operation
1570
+ - acquire (String, optional): session ID, lock acquisition operation
1571
+ - release (String, optional): session ID, lock release operation
1572
+
1573
+ Usage
1574
+
1575
+ ```javascript
1576
+ await consul.kv.set("hello", "world");
1577
+ ```
1578
+
1579
+ Result
1580
+
1581
+ ```json
1582
+ true
1583
+ ```
1584
+
1585
+ <a id="kv-del"></a>
1586
+
1587
+ ### consul.kv.del(options)
1588
+
1589
+ Delete key/value (kv) pair(s).
1590
+
1591
+ Options
1592
+
1593
+ - key (String): key
1594
+ - dc (String, optional): datacenter (defaults to local for agent)
1595
+ - recurse (Boolean, default: false): delete all keys with given key prefix
1596
+ - cas (String, optional): use with `ModifyIndex` to do a check-and-set operation (must be greater than `0`)
1597
+
1598
+ Usage
1599
+
1600
+ ```javascript
1601
+ await consul.kv.del("hello");
1602
+ ```
1603
+
1604
+ <a id="query"></a>
1605
+
1606
+ ### consul.query
1607
+
1608
+ - [list](#query-list)
1609
+ - [create](#query-create)
1610
+ - [update](#query-update)
1611
+ - [get](#query-get)
1612
+ - [destroy](#query-destroy)
1613
+ - [execute](#query-execute)
1614
+ - [explain](#query-explain)
1615
+
1616
+ <a id="query-list"></a>
1617
+
1618
+ ### consul.query.list()
1619
+
1620
+ List prepared query.
1621
+
1622
+ Usage
1623
+
1624
+ ```javascript
1625
+ await consul.query.list();
1626
+ ```
1627
+
1628
+ Result
1629
+
1630
+ ```json
1631
+ [
1632
+ {
1633
+ "ID": "422b14b9-874b-4520-bd2e-e149a42b0066",
1634
+ "Name": "redis",
1635
+ "Session": "",
1636
+ "Token": "",
1637
+ "Template": {
1638
+ "Type": "",
1639
+ "Regexp": ""
1640
+ },
1641
+ "Service": {
1642
+ "Service": "redis",
1643
+ "Failover": {
1644
+ "NearestN": 3,
1645
+ "Datacenters": ["dc1", "dc2"]
1646
+ },
1647
+ "OnlyPassing": false,
1648
+ "Tags": ["master", "!experimental"]
1649
+ },
1650
+ "DNS": {
1651
+ "TTL": "10s"
1652
+ },
1653
+ "RaftIndex": {
1654
+ "CreateIndex": 23,
1655
+ "ModifyIndex": 42
1656
+ }
1657
+ }
1658
+ ]
1659
+ ```
1660
+
1661
+ <a id="query-create"></a>
1662
+
1663
+ ### consul.query.create(options)
1664
+
1665
+ Create a new prepared query.
1666
+
1667
+ Options
1668
+
1669
+ - name (String, optional): name that can be used to execute a query instead of using its ID
1670
+ - session (String, optional): provides a way to automatically remove a prepared query when the given session is invalidated
1671
+ - token (String, optional): captured ACL Token that is reused as the ACL Token every time the query is executed
1672
+ - near (String, optional): allows specifying a particular node to sort near based on distance sorting using Network Coordinates
1673
+ - service.service (String, required): name of the service to query
1674
+ - service.failover.nearestn (Number, optional): when set the query will be forwarded to up to nearest N other datacenters based on their estimated network round trip time using Network Coordinates from the WAN gossip pool
1675
+ - service.failover.datacenters (String[], optional): fixed list of remote datacenters to forward the query to if there are no healthy nodes in the local datacenter
1676
+ - service.onlypassing (Boolean, default: false): filter results to only nodes with a passing state
1677
+ - service.tags (String[], optional): list of service tags to filter the query results
1678
+ - ttl.dns (String, optional, ex: `10s`): controls how the TTL is set when query results are served over DNS
1679
+
1680
+ Usage
1681
+
1682
+ ```javascript
1683
+ await consul.query.create({
1684
+ name: 'redis',
1685
+ service: {
1686
+ service: 'redis'
1687
+ onlypassing: true
1688
+ },
1689
+ });
1690
+ ```
1691
+
1692
+ Result
1693
+
1694
+ ```json
1695
+ {
1696
+ "ID": "422b14b9-874b-4520-bd2e-e149a42b0066"
1697
+ }
1698
+ ```
1699
+
1700
+ <a id="query-update"></a>
1701
+
1702
+ ### consul.query.update(options)
1703
+
1704
+ Update existing prepared query.
1705
+
1706
+ Options
1707
+
1708
+ - query (String, required): ID of the query
1709
+
1710
+ And all [create options][query-create].
1711
+
1712
+ Usage
1713
+
1714
+ ```javascript
1715
+ await consul.query.update({
1716
+ query: '422b14b9-874b-4520-bd2e-e149a42b0066',
1717
+ name: 'redis',
1718
+ service: {
1719
+ service: 'redis'
1720
+ onlypassing: false
1721
+ },
1722
+ });
1723
+ ```
1724
+
1725
+ <a id="query-get"></a>
1726
+
1727
+ ### consul.query.get(options)
1728
+
1729
+ Get prepared query.
1730
+
1731
+ Options
1732
+
1733
+ - query (String, required): ID of the query
1734
+
1735
+ Usage
1736
+
1737
+ ```javascript
1738
+ await consul.query.get("6119cabf-c052-48fe-9f07-711762e52931");
1739
+ ```
1740
+
1741
+ Result
1742
+
1743
+ ```json
1744
+ {
1745
+ "ID": "6119cabf-c052-48fe-9f07-711762e52931",
1746
+ "Name": "redis",
1747
+ "Session": "",
1748
+ "Token": "",
1749
+ "Template": {
1750
+ "Type": "",
1751
+ "Regexp": ""
1752
+ },
1753
+ "Service": {
1754
+ "Service": "redis",
1755
+ "Failover": {
1756
+ "NearestN": 3,
1757
+ "Datacenters": ["dc1", "dc2"]
1758
+ },
1759
+ "OnlyPassing": false,
1760
+ "Tags": ["master", "!experimental"]
1761
+ },
1762
+ "DNS": {
1763
+ "TTL": "10s"
1764
+ },
1765
+ "RaftIndex": {
1766
+ "CreateIndex": 23,
1767
+ "ModifyIndex": 42
1768
+ }
1769
+ }
1770
+ ```
1771
+
1772
+ <a id="query-destroy"></a>
1773
+
1774
+ ### consul.query.destroy(options)
1775
+
1776
+ Delete prepared query.
1777
+
1778
+ Options
1779
+
1780
+ - query (String, required): ID of the query
1781
+
1782
+ Usage
1783
+
1784
+ ```javascript
1785
+ await consul.query.destroy("422b14b9-874b-4520-bd2e-e149a42b0066");
1786
+ ```
1787
+
1788
+ <a id="query-execute"></a>
1789
+
1790
+ ### consul.query.execute(options)
1791
+
1792
+ Execute prepared query.
1793
+
1794
+ Options
1795
+
1796
+ - query (String, required): ID of the query
1797
+
1798
+ Usage
1799
+
1800
+ ```javascript
1801
+ await consul.query.execute("6119cabf-c052-48fe-9f07-711762e52931");
1802
+ ```
1803
+
1804
+ Result
1805
+
1806
+ ```json
1807
+ {
1808
+ "Service": "redis",
1809
+ "Nodes": [
1810
+ {
1811
+ "Node": {
1812
+ "Node": "foobar",
1813
+ "Address": "10.1.10.12",
1814
+ "TaggedAddresses": {
1815
+ "lan": "10.1.10.12",
1816
+ "wan": "10.1.10.12"
1817
+ }
1818
+ },
1819
+ "Service": {
1820
+ "ID": "redis",
1821
+ "Service": "redis",
1822
+ "Tags": null,
1823
+ "Port": 8000
1824
+ },
1825
+ "Checks": [
1826
+ {
1827
+ "Node": "foobar",
1828
+ "CheckID": "service:redis",
1829
+ "Name": "Service 'redis' check",
1830
+ "Status": "passing",
1831
+ "Notes": "",
1832
+ "Output": "",
1833
+ "ServiceID": "redis",
1834
+ "ServiceName": "redis"
1835
+ },
1836
+ {
1837
+ "Node": "foobar",
1838
+ "CheckID": "serfHealth",
1839
+ "Name": "Serf Health Status",
1840
+ "Status": "passing",
1841
+ "Notes": "",
1842
+ "Output": "",
1843
+ "ServiceID": "",
1844
+ "ServiceName": ""
1845
+ }
1846
+ ],
1847
+ "DNS": {
1848
+ "TTL": "10s"
1849
+ },
1850
+ "Datacenter": "dc3",
1851
+ "Failovers": 2
1852
+ }
1853
+ ]
1854
+ }
1855
+ ```
1856
+
1857
+ <a id="query-explain"></a>
1858
+
1859
+ ### consul.query.explain(options)
1860
+
1861
+ Explain prepared query.
1862
+
1863
+ Options
1864
+
1865
+ - query (String, required): ID of the query
1866
+
1867
+ Usage
1868
+
1869
+ ```javascript
1870
+ await consul.query.explain("422b14b9-874b-4520-bd2e-e149a42b0066");
1871
+ ```
1872
+
1873
+ Result
1874
+
1875
+ ```json
1876
+ {
1877
+ "Query": {
1878
+ "ID": "422b14b9-874b-4520-bd2e-e149a42b0066",
1879
+ "Name": "redis",
1880
+ "Session": "",
1881
+ "Token": "",
1882
+ "Template": {
1883
+ "Type": "",
1884
+ "Regexp": ""
1885
+ },
1886
+ "Service": {
1887
+ "Service": "redis",
1888
+ "Failover": {
1889
+ "NearestN": 3,
1890
+ "Datacenters": ["dc1", "dc2"]
1891
+ },
1892
+ "OnlyPassing": false,
1893
+ "Tags": ["master", "!experimental"]
1894
+ },
1895
+ "DNS": {
1896
+ "TTL": "10s"
1897
+ },
1898
+ "RaftIndex": {
1899
+ "CreateIndex": 23,
1900
+ "ModifyIndex": 42
1901
+ }
1902
+ }
1903
+ }
1904
+ ```
1905
+
1906
+ <a id="session"></a>
1907
+
1908
+ ### consul.session
1909
+
1910
+ - [create](#session-create)
1911
+ - [destroy](#session-destroy)
1912
+ - [get](#session-get)
1913
+ - [node](#session-node)
1914
+ - [list](#session-list)
1915
+ - [renew](#session-renew)
1916
+
1917
+ <a id="session-create"></a>
1918
+
1919
+ ### consul.session.create([options])
1920
+
1921
+ Create a new session.
1922
+
1923
+ Options
1924
+
1925
+ - dc (String, optional): datacenter (defaults to local for agent)
1926
+ - lockdelay (String, range: 1s-60s, default: `15s`): the time consul prevents locks held by the session from being acquired after a session has been invalidated
1927
+ - name (String, optional): human readable name for the session
1928
+ - node (String, optional): node with which to associate session (defaults to connected agent)
1929
+ - checks (String[], optional): checks to associate with session
1930
+ - behavior (String, enum: release, delete; default: release): controls the behavior when a session is invalidated
1931
+ - ttl (String, optional, valid: `10s`-`86400s`): interval session must be renewed
1932
+
1933
+ Usage
1934
+
1935
+ ```javascript
1936
+ await consul.session.create();
1937
+ ```
1938
+
1939
+ Result
1940
+
1941
+ ```json
1942
+ {
1943
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1"
1944
+ }
1945
+ ```
1946
+
1947
+ <a id="session-destroy"></a>
1948
+
1949
+ ### consul.session.destroy(options)
1950
+
1951
+ Destroy a given session.
1952
+
1953
+ Options
1954
+
1955
+ - id (String): session ID
1956
+ - dc (String, optional): datacenter (defaults to local for agent)
1957
+
1958
+ Usage
1959
+
1960
+ ```javascript
1961
+ await consul.session.destroy("a0f5dc05-84c3-5f5a-1d88-05b875e524e1");
1962
+ ```
1963
+
1964
+ <a id="session-get"></a>
1965
+
1966
+ ### consul.session.get(options)
1967
+
1968
+ Queries a given session.
1969
+
1970
+ Options
1971
+
1972
+ - id (String): session ID
1973
+ - dc (String, optional): datacenter (defaults to local for agent)
1974
+
1975
+ Usage
1976
+
1977
+ ```javascript
1978
+ await consul.session.get("a0f5dc05-84c3-5f5a-1d88-05b875e524e1");
1979
+ ```
1980
+
1981
+ Result
1982
+
1983
+ ```json
1984
+ {
1985
+ "CreateIndex": 11,
1986
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
1987
+ "Name": "",
1988
+ "Node": "node1",
1989
+ "Checks": ["serfHealth"],
1990
+ "LockDelay": 15000000000
1991
+ }
1992
+ ```
1993
+
1994
+ <a id="session-node"></a>
1995
+
1996
+ ### consul.session.node(options)
1997
+
1998
+ Lists sessions belonging to a node.
1999
+
2000
+ Options
2001
+
2002
+ - node (String): node
2003
+ - dc (String, optional): datacenter (defaults to local for agent)
2004
+
2005
+ Usage
2006
+
2007
+ ```javascript
2008
+ await consul.session.node("node1");
2009
+ ```
2010
+
2011
+ Result
2012
+
2013
+ ```json
2014
+ [
2015
+ {
2016
+ "CreateIndex": 13,
2017
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
2018
+ "Name": "",
2019
+ "Node": "node1",
2020
+ "Checks": ["serfHealth"],
2021
+ "LockDelay": 15000000000
2022
+ }
2023
+ ]
2024
+ ```
2025
+
2026
+ <a id="session-list"></a>
2027
+
2028
+ ### consul.session.list([options])
2029
+
2030
+ Lists all the active sessions.
2031
+
2032
+ Options
2033
+
2034
+ - dc (String, optional): datacenter (defaults to local for agent)
2035
+
2036
+ Usage
2037
+
2038
+ ```javascript
2039
+ await consul.session.list();
2040
+ ```
2041
+
2042
+ Result
2043
+
2044
+ ```json
2045
+ [
2046
+ {
2047
+ "CreateIndex": 15,
2048
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
2049
+ "Name": "",
2050
+ "Node": "node1",
2051
+ "Checks": ["serfHealth"],
2052
+ "LockDelay": 15000000000
2053
+ }
2054
+ ]
2055
+ ```
2056
+
2057
+ <a id="session-renew"></a>
2058
+
2059
+ ### consul.session.renew(options)
2060
+
2061
+ Renew a given session.
2062
+
2063
+ Options
2064
+
2065
+ - id (String): session ID
2066
+ - dc (String, optional): datacenter (defaults to local for agent)
2067
+
2068
+ Usage
2069
+
2070
+ ```javascript
2071
+ await consul.session.renew("a0f5dc05-84c3-5f5a-1d88-05b875e524e1");
2072
+ ```
2073
+
2074
+ Result
2075
+
2076
+ ```json
2077
+ [
2078
+ {
2079
+ "CreateIndex": 15,
2080
+ "ID": "a0f5dc05-84c3-5f5a-1d88-05b875e524e1",
2081
+ "Name": "",
2082
+ "Node": "node1",
2083
+ "Checks": ["serfHealth"],
2084
+ "LockDelay": 15000000000,
2085
+ "Behavior": "release",
2086
+ "TTL": ""
2087
+ }
2088
+ ]
2089
+ ```
2090
+
2091
+ <a id="status"></a>
2092
+
2093
+ ### consul.status
2094
+
2095
+ - [leader](#status-leader)
2096
+ - [peers](#status-peers)
2097
+
2098
+ <a id="status-leader"></a>
2099
+
2100
+ ### consul.status.leader()
2101
+
2102
+ Returns the current Raft leader.
2103
+
2104
+ Usage
2105
+
2106
+ ```javascript
2107
+ await consul.status.leader();
2108
+ ```
2109
+
2110
+ Result
2111
+
2112
+ ```json
2113
+ "127.0.0.1:8300"
2114
+ ```
2115
+
2116
+ <a id="status-peers"></a>
2117
+
2118
+ ### consul.status.peers()
2119
+
2120
+ Returns the current Raft peer set.
2121
+
2122
+ Usage
2123
+
2124
+ ```javascript
2125
+ await consul.status.peers();
2126
+ ```
2127
+
2128
+ Result
2129
+
2130
+ ```json
2131
+ ["127.0.0.1:8300"]
2132
+ ```
2133
+
2134
+ <a id="transaction"></a>
2135
+
2136
+ ### consul.transaction.create(operations)
2137
+
2138
+ operations: The body of the request should be a list of operations to perform inside the atomic transaction. Up to 64 operations may be present in a single transaction.
2139
+
2140
+ Usage
2141
+
2142
+ ```javascript
2143
+ await consul.transaction.create([
2144
+ {
2145
+ {
2146
+ KV: {
2147
+ Verb: 'set',
2148
+ Key: 'key1',
2149
+ Value: Buffer.from('value1').toString('base64')
2150
+ }
2151
+ },{
2152
+ KV: {
2153
+ Verb: 'delete',
2154
+ Key: 'key2'
2155
+ }
2156
+ }
2157
+ }
2158
+ ]);
2159
+ ```
2160
+
2161
+ <a id="watch"></a>
2162
+
2163
+ ### consul.watch(options)
2164
+
2165
+ Watch an endpoint for changes.
2166
+
2167
+ The watch relies on blocking queries, adding the `index` and `wait` parameters as per [Consul's documentation](https://www.consul.io/docs/agent/http.html)
2168
+
2169
+ If a blocking query is dropped due to a Consul crash or disconnect, watch will attempt to reinitiate the blocking query with logarithmic backoff.
2170
+
2171
+ Upon reconnect, unlike the first call to watch() in which the latest `x-consul-index` is unknown, the last known `x-consul-index` will be reused, thus not emitting the `change` event unless it has been incremented since.
2172
+
2173
+ NOTE: If you specify an alternative options.timeout keep in mind that a small random amount of additional wait is added to all requests (wait / 16). The default timeout is currently set to (wait + wait \* 0.1), you should use something similar to avoid issues.
2174
+
2175
+ Options
2176
+
2177
+ - method (Function): method to watch
2178
+ - options (Object): method options
2179
+ - backoffFactor (Integer, default: 100): backoff factor in milliseconds to apply between attempts (`backoffFactor * (2 ^ retry attempt)`)
2180
+ - backoffMax (Integer, default: 30000): maximum backoff time in milliseconds to wait between attempts
2181
+ - maxAttempts (Integer): maximum number of retry attempts to make before giving up
2182
+
2183
+ Usage
2184
+
2185
+ ```javascript
2186
+ const watch = consul.watch({
2187
+ method: consul.kv.get,
2188
+ options: { key: "test" },
2189
+ backoffFactor: 1000,
2190
+ });
2191
+
2192
+ watch.on("change", (data, res) => {
2193
+ console.log("data:", data);
2194
+ });
2195
+
2196
+ watch.on("error", (err) => {
2197
+ console.log("error:", err);
2198
+ });
2199
+
2200
+ setTimeout(() => {
2201
+ watch.end();
2202
+ }, 30 * 1000);
2203
+ ```
2204
+
2205
+ ## Acceptance Tests
2206
+
2207
+ 1. Install [Consul][download] into your `PATH`
2208
+
2209
+ ```console
2210
+ $ brew install consul
2211
+ ```
2212
+
2213
+ 1. Attach required IPs
2214
+
2215
+ ```console
2216
+ $ sudo ifconfig lo0 alias 127.0.0.2 up
2217
+ $ sudo ifconfig lo0 alias 127.0.0.3 up
2218
+ ```
2219
+
2220
+ 1. Install client dependencies
2221
+
2222
+ ```console
2223
+ $ npm install
2224
+ ```
2225
+
2226
+ 1. Run tests
2227
+
2228
+ ```console
2229
+ $ npm run acceptance
2230
+ ```
2231
+
2232
+ ## License
2233
+
2234
+ This work is licensed under the MIT License (see the LICENSE file).
2235
+
2236
+ Parts of the Documentation were copied from the official
2237
+ [Consul website][consul-docs-api], see the NOTICE file for license
2238
+ information.
2239
+
2240
+ [consul]: https://www.consul.io/
2241
+ [consul-docs-api]: https://www.consul.io/api-docs
2242
+ [download]: https://www.consul.io/downloads