@brimble/consul 1.0.1 → 1.0.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/README.md CHANGED
@@ -24,6 +24,7 @@ See the official [HTTP API][consul-docs-api] docs for more information.
24
24
  - [Connect](#catalog-connect)
25
25
  - [Node](#catalog-node)
26
26
  - [Service](#catalog-service)
27
+ * [Config](#config)
27
28
  * [Event](#event)
28
29
  * [Health](#health)
29
30
  * [Intention](#intention)
@@ -1067,6 +1068,101 @@ Result
1067
1068
  ]
1068
1069
  ```
1069
1070
 
1071
+ <a id="config"></a>
1072
+
1073
+ ### consul.config
1074
+
1075
+ - [list](#config-list)
1076
+ - [get](#config-get)
1077
+ - [set](#config-set)
1078
+ - [destroy](#config-destroy)
1079
+
1080
+ <a id="config-list"></a>
1081
+
1082
+ ### consul.config.list(options)
1083
+
1084
+ Lists config entries for a given kind.
1085
+
1086
+ Options
1087
+
1088
+ - kind (String): config entry kind
1089
+ - dc (String, optional): datacenter
1090
+
1091
+ Usage
1092
+
1093
+ ```javascript
1094
+ await consul.config.list("service-resolver");
1095
+ ```
1096
+
1097
+ <a id="config-get"></a>
1098
+
1099
+ ### consul.config.get(options)
1100
+
1101
+ Gets a config entry.
1102
+
1103
+ Options
1104
+
1105
+ - kind (String): config entry kind
1106
+ - name (String): config entry name
1107
+ - dc (String, optional): datacenter
1108
+
1109
+ Usage
1110
+
1111
+ ```javascript
1112
+ await consul.config.get({
1113
+ kind: "service-resolver",
1114
+ name: "salary-index-ng",
1115
+ });
1116
+ ```
1117
+
1118
+ <a id="config-set"></a>
1119
+
1120
+ ### consul.config.set(entry[, options])
1121
+
1122
+ Creates or updates a config entry.
1123
+
1124
+ Options
1125
+
1126
+ - entry (Object): Consul config entry payload
1127
+ - token (String, optional): ACL token
1128
+ - dc (String, optional): datacenter
1129
+
1130
+ Usage
1131
+
1132
+ ```javascript
1133
+ await consul.config.set(
1134
+ {
1135
+ Kind: "service-resolver",
1136
+ Name: "salary-index-ng",
1137
+ Redirect: {
1138
+ Service: "6a3ea78d3d66fd3ab1dbbb12",
1139
+ },
1140
+ },
1141
+ { token: process.env.CONSUL_HTTP_TOKEN },
1142
+ );
1143
+ ```
1144
+
1145
+ <a id="config-destroy"></a>
1146
+
1147
+ ### consul.config.destroy(options)
1148
+
1149
+ Deletes a config entry. Alias: `consul.config.delete(options)`.
1150
+
1151
+ Options
1152
+
1153
+ - kind (String): config entry kind
1154
+ - name (String): config entry name
1155
+ - dc (String, optional): datacenter
1156
+
1157
+ Usage
1158
+
1159
+ ```javascript
1160
+ await consul.config.destroy({
1161
+ kind: "service-resolver",
1162
+ name: "salary-index-ng",
1163
+ });
1164
+ ```
1165
+
1070
1166
  <a id="event"></a>
1071
1167
 
1072
1168
  ### consul.event
@@ -0,0 +1,55 @@
1
+ import { CommonOptions, Consul } from "./consul";
2
+
3
+ interface ConfigEntry {
4
+ Kind: string;
5
+ Name: string;
6
+ Namespace?: string;
7
+ Partition?: string;
8
+ Meta?: Record<string, string>;
9
+ CreateIndex?: number;
10
+ ModifyIndex?: number;
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ interface ListOptions extends CommonOptions {
15
+ kind: string;
16
+ }
17
+
18
+ type ListResult = ConfigEntry[];
19
+
20
+ interface GetOptions extends CommonOptions {
21
+ kind: string;
22
+ name: string;
23
+ }
24
+
25
+ type GetResult = ConfigEntry;
26
+
27
+ type SetOptions = CommonOptions;
28
+
29
+ type SetResult = boolean;
30
+
31
+ interface DestroyOptions extends CommonOptions {
32
+ kind: string;
33
+ name: string;
34
+ }
35
+
36
+ type DestroyResult = boolean;
37
+
38
+ declare class Config {
39
+ constructor(consul: Consul);
40
+
41
+ consul: Consul;
42
+
43
+ list(options: ListOptions): Promise<ListResult>;
44
+ list(kind: string): Promise<ListResult>;
45
+
46
+ get(options: GetOptions): Promise<GetResult>;
47
+
48
+ set(entry: ConfigEntry, options?: SetOptions): Promise<SetResult>;
49
+
50
+ destroy(options: DestroyOptions): Promise<DestroyResult>;
51
+
52
+ delete(options: DestroyOptions): Promise<DestroyResult>;
53
+ }
54
+
55
+ export { Config, ConfigEntry };
package/lib/config.js ADDED
@@ -0,0 +1,117 @@
1
+ const errors = require("./errors");
2
+ const utils = require("./utils");
3
+
4
+ class Config {
5
+ constructor(consul) {
6
+ this.consul = consul;
7
+ }
8
+
9
+ /**
10
+ * Lists config entries for a kind
11
+ */
12
+ async list(opts) {
13
+ if (typeof opts === "string") {
14
+ opts = { kind: opts };
15
+ }
16
+
17
+ opts = utils.normalizeKeys(opts);
18
+ opts = utils.defaults(opts, this.consul._defaults);
19
+
20
+ const req = {
21
+ name: "config.list",
22
+ path: "/config/{kind}",
23
+ params: { kind: opts.kind },
24
+ query: {},
25
+ };
26
+
27
+ if (!opts.kind) {
28
+ throw this.consul._err(errors.Validation("kind required"), req);
29
+ }
30
+
31
+ utils.options(req, opts);
32
+
33
+ return await this.consul._get(req, utils.body);
34
+ }
35
+
36
+ /**
37
+ * Gets a config entry
38
+ */
39
+ async get(opts) {
40
+ opts = utils.normalizeKeys(opts);
41
+ opts = utils.defaults(opts, this.consul._defaults);
42
+
43
+ const req = {
44
+ name: "config.get",
45
+ path: "/config/{kind}/{name}",
46
+ params: { kind: opts.kind, name: opts.name },
47
+ query: {},
48
+ };
49
+
50
+ if (!opts.kind) {
51
+ throw this.consul._err(errors.Validation("kind required"), req);
52
+ }
53
+ if (!opts.name) {
54
+ throw this.consul._err(errors.Validation("name required"), req);
55
+ }
56
+
57
+ utils.options(req, opts);
58
+
59
+ return await this.consul._get(req, utils.body);
60
+ }
61
+
62
+ /**
63
+ * Creates or updates a config entry
64
+ */
65
+ async set(entry, opts) {
66
+ opts = utils.normalizeKeys(opts);
67
+ opts = utils.defaults(opts, this.consul._defaults);
68
+
69
+ const req = {
70
+ name: "config.set",
71
+ path: "/config",
72
+ query: {},
73
+ type: "json",
74
+ body: entry,
75
+ };
76
+
77
+ if (!entry) {
78
+ throw this.consul._err(errors.Validation("entry required"), req);
79
+ }
80
+
81
+ utils.options(req, opts);
82
+
83
+ return await this.consul._put(req, utils.body);
84
+ }
85
+
86
+ /**
87
+ * Deletes a config entry
88
+ */
89
+ async destroy(opts) {
90
+ opts = utils.normalizeKeys(opts);
91
+ opts = utils.defaults(opts, this.consul._defaults);
92
+
93
+ const req = {
94
+ name: "config.destroy",
95
+ path: "/config/{kind}/{name}",
96
+ params: { kind: opts.kind, name: opts.name },
97
+ query: {},
98
+ };
99
+
100
+ if (!opts.kind) {
101
+ throw this.consul._err(errors.Validation("kind required"), req);
102
+ }
103
+ if (!opts.name) {
104
+ throw this.consul._err(errors.Validation("name required"), req);
105
+ }
106
+
107
+ utils.options(req, opts);
108
+
109
+ return await this.consul._delete(req, utils.body);
110
+ }
111
+
112
+ delete() {
113
+ return this.destroy.apply(this, arguments);
114
+ }
115
+ }
116
+
117
+ exports.Config = Config;
package/lib/consul.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Agent as httpsAgent } from "https";
3
3
  import { Acl } from "./acl";
4
4
  import { Agent } from "./agent";
5
5
  import { Catalog } from "./catalog";
6
+ import { Config } from "./config";
6
7
  import { Event } from "./event";
7
8
  import { Health } from "./health";
8
9
  import { Intention } from "./intention";
@@ -51,6 +52,7 @@ declare class Consul {
51
52
  acl: Acl;
52
53
  agent: Agent;
53
54
  catalog: Catalog;
55
+ config: Config;
54
56
  event: Event;
55
57
  health: Health;
56
58
  intention: Intention;
@@ -63,6 +65,7 @@ declare class Consul {
63
65
  static Acl: typeof Acl;
64
66
  static Agent: typeof Agent;
65
67
  static Catalog: typeof Catalog;
68
+ static Config: typeof Config;
66
69
  static Event: typeof Event;
67
70
  static Health: typeof Health;
68
71
  static Intention: typeof Intention;
package/lib/consul.js CHANGED
@@ -3,6 +3,7 @@ const papi = require("papi");
3
3
  const Acl = require("./acl").Acl;
4
4
  const Agent = require("./agent").Agent;
5
5
  const Catalog = require("./catalog").Catalog;
6
+ const Config = require("./config").Config;
6
7
  const Event = require("./event").Event;
7
8
  const Health = require("./health").Health;
8
9
  const Intention = require("./intention").Intention;
@@ -52,6 +53,7 @@ class Consul extends papi.Client {
52
53
  this.acl = new Consul.Acl(this);
53
54
  this.agent = new Consul.Agent(this);
54
55
  this.catalog = new Consul.Catalog(this);
56
+ this.config = new Consul.Config(this);
55
57
  this.event = new Consul.Event(this);
56
58
  this.health = new Consul.Health(this);
57
59
  this.intention = new Consul.Intention(this);
@@ -84,6 +86,7 @@ class Consul extends papi.Client {
84
86
  Consul.Acl = Acl;
85
87
  Consul.Agent = Agent;
86
88
  Consul.Catalog = Catalog;
89
+ Consul.Config = Config;
87
90
  Consul.Event = Event;
88
91
  Consul.Health = Health;
89
92
  Consul.Intention = Intention;
package/lib/index.d.ts CHANGED
@@ -1,18 +1,3 @@
1
- import { Consul, SelectionAlgorithm } from "./consul";
2
- import {
3
- ConsulResolverConfig,
4
- ServiceInfo,
5
- OptimalServiceResult,
6
- ServiceMetrics,
7
- Resolver,
8
- } from "./resolver";
1
+ import { Consul } from "./consul";
9
2
 
10
3
  export = Consul;
11
-
12
- export type {
13
- ConsulResolverConfig,
14
- ServiceInfo,
15
- OptimalServiceResult,
16
- ServiceMetrics,
17
- };
18
- export { SelectionAlgorithm, Resolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brimble/consul",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Consul client",
5
5
  "main": "./lib",
6
6
  "types": "./lib/index.d.ts",