@magnet.me/consultant 1.6.1 → 1.6.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.
@@ -0,0 +1,32 @@
1
+ import js from '@eslint/js';
2
+ import globals from 'globals';
3
+
4
+ export default [
5
+ js.configs.recommended,
6
+ {
7
+ files: ['src/**/*.js'],
8
+ languageOptions: {
9
+ ecmaVersion: 2017,
10
+ sourceType: 'module',
11
+ globals: globals.node
12
+ },
13
+ rules: {
14
+ indent: [
15
+ 'error',
16
+ 'tab'
17
+ ],
18
+ 'linebreak-style': [
19
+ 'error',
20
+ 'unix'
21
+ ],
22
+ quotes: [
23
+ 'error',
24
+ 'single'
25
+ ],
26
+ semi: [
27
+ 'error',
28
+ 'always'
29
+ ]
30
+ }
31
+ }
32
+ ];
package/out/agent.js CHANGED
@@ -4,18 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = fetchAgent;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _properties = _interopRequireDefault(require("./properties"));
11
-
12
9
  var _consultantError = _interopRequireDefault(require("./consultant-error"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
11
  async function fetchAgent(consulHost) {
17
12
  const uri = `${consulHost}/v1/agent/self`;
18
-
19
13
  try {
20
14
  const res = await (0, _nodeFetch.default)(uri, {
21
15
  timeout: 5000,
package/out/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/agent.js"],"names":["fetchAgent","consulHost","uri","res","timeout","headers","properties","userAgent","json","e","ConsultantError"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAEe,eAAeA,UAAf,CAA0BC,UAA1B,EAAsC;AACpD,QAAMC,GAAG,GAAI,GAAED,UAAW,gBAA1B;;AACA,MAAI;AACH,UAAME,GAAG,GAAG,MAAM,wBAAMD,GAAN,EAAW;AAC5BE,MAAAA,OAAO,EAAG,IADkB;AAE5BC,MAAAA,OAAO,EAAG;AACT,kBAAW,kBADF;AAET,wBAAiB,kBAFR;AAGT,sBAAeC,oBAAWC;AAHjB;AAFkB,KAAX,CAAlB;AAQA,WAAO,MAAMJ,GAAG,CAACK,IAAJ,EAAb;AACA,GAVD,CAWA,OAAOC,CAAP,EAAU;AACT,UAAM,IAAIC,wBAAJ,CAAqB,yCAAwCD,CAAE,EAA/D,CAAN;AACA;AACD","sourcesContent":["import fetch from 'node-fetch';\nimport properties from './properties';\nimport ConsultantError from './consultant-error';\n\nexport default async function fetchAgent(consulHost) {\n\tconst uri = `${consulHost}/v1/agent/self`;\n\ttry {\n\t\tconst res = await fetch(uri, {\n\t\t\ttimeout : 5000,\n\t\t\theaders : {\n\t\t\t\t'accept' : 'application/json',\n\t\t\t\t'content-type' : 'application/json',\n\t\t\t\t'user-agent' : properties.userAgent\n\t\t\t}\n\t\t});\n\t\treturn await res.json();\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not retrieve agent from consul: ${e}`);\n\t}\n}\n"],"file":"agent.js"}
1
+ {"version":3,"file":"agent.js","names":["_nodeFetch","_interopRequireDefault","require","_properties","_consultantError","e","__esModule","default","fetchAgent","consulHost","uri","res","fetch","timeout","headers","properties","userAgent","json","ConsultantError"],"sources":["../src/agent.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport properties from './properties';\nimport ConsultantError from './consultant-error';\n\nexport default async function fetchAgent(consulHost) {\n\tconst uri = `${consulHost}/v1/agent/self`;\n\ttry {\n\t\tconst res = await fetch(uri, {\n\t\t\ttimeout : 5000,\n\t\t\theaders : {\n\t\t\t\t'accept' : 'application/json',\n\t\t\t\t'content-type' : 'application/json',\n\t\t\t\t'user-agent' : properties.userAgent\n\t\t\t}\n\t\t});\n\t\treturn await res.json();\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not retrieve agent from consul: ${e}`);\n\t}\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,gBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAiD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAElC,eAAeG,UAAUA,CAACC,UAAU,EAAE;EACpD,MAAMC,GAAG,GAAG,GAAGD,UAAU,gBAAgB;EACzC,IAAI;IACH,MAAME,GAAG,GAAG,MAAM,IAAAC,kBAAK,EAACF,GAAG,EAAE;MAC5BG,OAAO,EAAG,IAAI;MACdC,OAAO,EAAG;QACT,QAAQ,EAAG,kBAAkB;QAC7B,cAAc,EAAG,kBAAkB;QACnC,YAAY,EAAGC,mBAAU,CAACC;MAC3B;IACD,CAAC,CAAC;IACF,OAAO,MAAML,GAAG,CAACM,IAAI,CAAC,CAAC;EACxB,CAAC,CACD,OAAOZ,CAAC,EAAE;IACT,MAAM,IAAIa,wBAAe,CAAC,yCAAyCb,CAAC,EAAE,CAAC;EACxE;AACD","ignoreList":[]}
package/out/config.js CHANGED
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = initializeConfiguration;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _properties = _interopRequireDefault(require("./properties"));
11
-
12
9
  var _identifier = _interopRequireDefault(require("./identifier"));
13
-
14
10
  var _keyParser = require("./key-parser");
15
-
16
11
  var _atob = _interopRequireDefault(require("atob"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
13
  const configUpdater = (consulHost, prefix, service, callback) => {
21
14
  let consulIndex;
22
15
  let timeoutId;
@@ -24,15 +17,12 @@ const configUpdater = (consulHost, prefix, service, callback) => {
24
17
  const self = {
25
18
  async poll() {
26
19
  let timeout = 500;
27
-
28
20
  try {
29
21
  const prefixUri = prefix ? `${prefix}/` : '';
30
22
  let uri = `${consulHost}/v1/kv/${prefixUri}${service.name}/?recurse=true`;
31
-
32
23
  if (consulIndex) {
33
24
  uri += `&index=${consulIndex}`;
34
25
  }
35
-
36
26
  const response = await (0, _nodeFetch.default)(uri, {
37
27
  headers: {
38
28
  'accept': 'application/json',
@@ -41,31 +31,24 @@ const configUpdater = (consulHost, prefix, service, callback) => {
41
31
  }
42
32
  });
43
33
  consulIndex = response.headers['x-consul-index'];
44
-
45
34
  if (response.status === 404) {
46
35
  timeout = 5000;
47
- const prefixText = prefix ? ` with prefix '${prefix}'` : ''; // eslint-disable-next-line no-console
48
-
36
+ const prefixText = prefix ? ` with prefix '${prefix}'` : '';
49
37
  console.warn(`'${service.name}'${prefixText} cannot be found in Consul`);
50
38
  return;
51
39
  }
52
-
53
40
  if (response.status !== 200) {
54
- timeout = 60000; // eslint-disable-next-line no-console
55
-
41
+ timeout = 60000;
56
42
  console.warn(`Error retrieving data from Consul: ${response.status}: ${await response.text()}`);
57
43
  return;
58
44
  }
59
-
60
45
  const json = await response.json();
61
46
  const properties = parseBody(json, prefix, service);
62
-
63
47
  if (callback) {
64
48
  callback(properties);
65
49
  }
66
50
  } catch (e) {
67
- timeout = 5000; // eslint-disable-next-line no-console
68
-
51
+ timeout = 5000;
69
52
  console.warn(`Error retrieving data from Consul: ${e}`);
70
53
  } finally {
71
54
  if (!shutdown) {
@@ -73,18 +56,16 @@ const configUpdater = (consulHost, prefix, service, callback) => {
73
56
  }
74
57
  }
75
58
  },
76
-
77
59
  stop() {
78
60
  shutdown = true;
79
-
80
61
  if (timeoutId) {
81
62
  clearTimeout(timeoutId);
82
63
  }
83
64
  }
84
-
85
65
  };
86
66
  return self;
87
67
  };
68
+
88
69
  /**
89
70
  * Parses the fetched config from Consul and converts it to a proper object.
90
71
  * @param body {Array} - The response body
@@ -92,8 +73,6 @@ const configUpdater = (consulHost, prefix, service, callback) => {
92
73
  * @param service {Object} - The service identifier to match key specifiers against
93
74
  * @return {Object} A properties object containing all valid properties as specified in the body
94
75
  */
95
-
96
-
97
76
  function parseBody(body, prefix, service) {
98
77
  return body.map(kvPair => {
99
78
  return {
@@ -106,18 +85,15 @@ function parseBody(body, prefix, service) {
106
85
  };
107
86
  }).reduce((properties, kvPair) => Object.assign(properties, kvPair), {});
108
87
  }
109
-
110
88
  const updateConfig = (properties, newConfig, callbacks) => {
111
89
  const updates = Object.keys(newConfig).filter(key => properties[key] !== newConfig[key]);
112
90
  Object.assign(properties, newConfig);
113
91
  const deletes = Object.keys(properties).filter(key => !newConfig[key]);
114
92
  deletes.forEach(key => delete properties[key]);
115
-
116
93
  if (updates.length > 0 || deletes.length > 0) {
117
94
  callbacks.forEach(callback => callback(Object.assign({}, properties)));
118
95
  }
119
96
  };
120
-
121
97
  async function initializeConfiguration({
122
98
  consulHost,
123
99
  service,
@@ -135,19 +111,15 @@ async function initializeConfiguration({
135
111
  getProperties() {
136
112
  return Object.assign({}, liveProperties);
137
113
  },
138
-
139
114
  register(callback) {
140
115
  callbacks.add(callback);
141
116
  },
142
-
143
117
  deregister(callback) {
144
118
  callbacks.delete(callback);
145
119
  },
146
-
147
120
  stop() {
148
121
  updater.stop();
149
122
  }
150
-
151
123
  };
152
124
  }
153
125
  //# sourceMappingURL=config.js.map
package/out/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.js"],"names":["configUpdater","consulHost","prefix","service","callback","consulIndex","timeoutId","shutdown","self","poll","timeout","prefixUri","uri","name","response","headers","props","userAgent","status","prefixText","console","warn","text","json","properties","parseBody","e","setTimeout","stop","clearTimeout","body","map","kvPair","key","Key","value","Value","filter","reduce","Object","assign","updateConfig","newConfig","callbacks","updates","keys","deletes","forEach","length","initializeConfiguration","Set","process","env","CONSUL_HOST","defaultHost","identifier","liveProperties","updater","newProperties","getProperties","register","add","deregister","delete"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA,MAAMA,aAAa,GAAG,CAACC,UAAD,EAAaC,MAAb,EAAqBC,OAArB,EAA8BC,QAA9B,KAA2C;AAChE,MAAIC,WAAJ;AACA,MAAIC,SAAJ;AACA,MAAIC,QAAQ,GAAG,KAAf;AACA,QAAMC,IAAI,GAAG;AACZ,UAAMC,IAAN,GAAa;AACZ,UAAIC,OAAO,GAAG,GAAd;;AACA,UAAI;AACH,cAAMC,SAAS,GAAGT,MAAM,GAAI,GAAEA,MAAO,GAAb,GAAkB,EAA1C;AACA,YAAIU,GAAG,GAAI,GAAEX,UAAW,UAASU,SAAU,GAAER,OAAO,CAACU,IAAK,gBAA1D;;AACA,YAAIR,WAAJ,EAAiB;AAChBO,UAAAA,GAAG,IAAK,UAASP,WAAY,EAA7B;AACA;;AACD,cAAMS,QAAQ,GAAG,MAAM,wBAAMF,GAAN,EAAW;AACjCG,UAAAA,OAAO,EAAG;AACT,sBAAW,kBADF;AAET,4BAAiB,kBAFR;AAGT,0BAAeC,oBAAMC;AAHZ;AADuB,SAAX,CAAvB;AAQAZ,QAAAA,WAAW,GAAGS,QAAQ,CAACC,OAAT,CAAiB,gBAAjB,CAAd;;AACA,YAAID,QAAQ,CAACI,MAAT,KAAoB,GAAxB,EAA6B;AAC5BR,UAAAA,OAAO,GAAG,IAAV;AACA,gBAAMS,UAAU,GAAGjB,MAAM,GAAI,iBAAgBA,MAAO,GAA3B,GAAgC,EAAzD,CAF4B,CAG5B;;AACAkB,UAAAA,OAAO,CAACC,IAAR,CAAc,IAAGlB,OAAO,CAACU,IAAK,IAAGM,UAAW,4BAA5C;AACA;AACA;;AACD,YAAIL,QAAQ,CAACI,MAAT,KAAoB,GAAxB,EAA6B;AAC5BR,UAAAA,OAAO,GAAG,KAAV,CAD4B,CAE5B;;AACAU,UAAAA,OAAO,CAACC,IAAR,CAA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1B,IAAyCrC,oBAAMsC,WAA5D;AAEA,QAAMC,UAAU,GAAG,MAAM,yBAAgBpD,OAAhB,EAAyBF,UAAzB,CAAzB;AAEA,MAAIuD,cAAc,GAAG,EAArB;AAEA,QAAMC,OAAO,GAAGzD,aAAa,CAACC,UAAD,EAAaC,MAAb,EAAqBqD,UAArB,EAAkCG,aAAD,IAAmB;AAChFjB,IAAAA,YAAY,CAACe,cAAD,EAAiBE,aAAjB,EAAgCf,SAAhC,CAAZ;AACA,GAF4B,CAA7B;AAIA,QAAMc,OAAO,CAAChD,IAAR,EAAN;AAEA,SAAO;AACNkD,IAAAA,aAAa,GAAG;AACf,aAAOpB,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBgB,cAAlB,CAAP;AACA,KAHK;;AAINI,IAAAA,QAAQ,CAACxD,QAAD,EAAW;AAClBuC,MAAAA,SAAS,CAACkB,GAAV,CAAczD,QAAd;AACA,KANK;;AAON0D,IAAAA,UAAU,CAAC1D,QAAD,EAAW;AACpBuC,MAAAA,SAAS,CAACoB,MAAV,CAAiB3D,QAAjB;AACA,KATK;;AAUNwB,IAAAA,IAAI,GAAG;AACN6B,MAAAA,OAAO,CAAC7B,IAAR;AACA;;AAZK,GAAP;AAcA","sourcesContent":["import fetch from 'node-fetch';\nimport props from './properties';\nimport fetchIdentifier from './identifier';\nimport {parseKey, keyApplies} from './key-parser';\nimport atob from 'atob';\n\nconst configUpdater = (consulHost, prefix, service, callback) => {\n\tlet consulIndex;\n\tlet timeoutId;\n\tlet shutdown = false;\n\tconst self = {\n\t\tasync poll() {\n\t\t\tlet timeout = 500;\n\t\t\ttry {\n\t\t\t\tconst prefixUri = prefix ? `${prefix}/` : '';\n\t\t\t\tlet uri = `${consulHost}/v1/kv/${prefixUri}${service.name}/?recurse=true`;\n\t\t\t\tif (consulIndex) {\n\t\t\t\t\turi += `&index=${consulIndex}`;\n\t\t\t\t}\n\t\t\t\tconst response = await fetch(uri, {\n\t\t\t\t\theaders : {\n\t\t\t\t\t\t'accept' : 'application/json',\n\t\t\t\t\t\t'content-type' : 'application/json',\n\t\t\t\t\t\t'user-agent' : props.userAgent\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tconsulIndex = response.headers['x-consul-index'];\n\t\t\t\tif (response.status === 404) {\n\t\t\t\t\ttimeout = 5000;\n\t\t\t\t\tconst prefixText = prefix ? ` with prefix '${prefix}'` : '';\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(`'${service.name}'${prefixText} cannot be found in Consul`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (response.status !== 200) {\n\t\t\t\t\ttimeout = 60000;\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(`Error retrieving data from Consul: ${response.status}: ${await response.text()}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst json = await response.json();\n\t\t\t\tconst properties = parseBody(json, prefix, service);\n\t\t\t\tif (callback) {\n\t\t\t\t\tcallback(properties);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\ttimeout = 5000;\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(`Error retrieving data from Consul: ${e}`);\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tif (!shutdown) {\n\t\t\t\t\ttimeoutId = setTimeout(self.poll, timeout);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tstop() {\n\t\t\tshutdown = true;\n\t\t\tif (timeoutId) {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t}\n\t\t}\n\t};\n\n\treturn self;\n};\n\n/**\n * Parses the fetched config from Consul and converts it to a proper object.\n * @param body {Array} - The response body\n * @param prefix {string} - The prefix to extract from the key path\n * @param service {Object} - The service identifier to match key specifiers against\n * @return {Object} A properties object containing all valid properties as specified in the body\n */\nfunction parseBody(body, prefix, service) {\n\treturn body.map(kvPair => {\n\t\treturn {key : parseKey(kvPair.Key, prefix), value : kvPair.Value};\n\t})\n\t\t.filter(kvPair => kvPair.key.key && keyApplies(kvPair.key, service))\n\t\t.map(kvPair => {\n\t\t\treturn {[kvPair.key.key] : atob(kvPair.value)};\n\t\t})\n\t\t.reduce((properties, kvPair) => Object.assign(properties, kvPair), {});\n}\n\nconst updateConfig = (properties, newConfig, callbacks) => {\n\tconst updates = Object.keys(newConfig).filter(key => properties[key] !== newConfig[key]);\n\n\tObject.assign(properties, newConfig);\n\n\tconst deletes = Object.keys(properties).filter(key => !newConfig[key]);\n\tdeletes.forEach(key => delete properties[key]);\n\n\tif (updates.length > 0 || deletes.length > 0) {\n\t\tcallbacks.forEach(callback => callback(Object.assign({}, properties)));\n\t}\n};\n\nexport default async function initializeConfiguration({consulHost, service, prefix}) {\n\tconst callbacks = new Set();\n\n\tconsulHost = consulHost || process.env.CONSUL_HOST || props.defaultHost;\n\n\tconst identifier = await fetchIdentifier(service, consulHost);\n\n\tlet liveProperties = {};\n\n\tconst updater = configUpdater(consulHost, prefix, identifier, (newProperties) => {\n\t\tupdateConfig(liveProperties, newProperties, callbacks);\n\t});\n\n\tawait updater.poll();\n\n\treturn {\n\t\tgetProperties() {\n\t\t\treturn Object.assign({}, liveProperties);\n\t\t},\n\t\tregister(callback) {\n\t\t\tcallbacks.add(callback);\n\t\t},\n\t\tderegister(callback) {\n\t\t\tcallbacks.delete(callback);\n\t\t},\n\t\tstop() {\n\t\t\tupdater.stop();\n\t\t}\n\t};\n}\n"],"file":"config.js"}
1
+ {"version":3,"file":"config.js","names":["_nodeFetch","_interopRequireDefault","require","_properties","_identifier","_keyParser","_atob","e","__esModule","default","configUpdater","consulHost","prefix","service","callback","consulIndex","timeoutId","shutdown","self","poll","timeout","prefixUri","uri","name","response","fetch","headers","props","userAgent","status","prefixText","console","warn","text","json","properties","parseBody","setTimeout","stop","clearTimeout","body","map","kvPair","key","parseKey","Key","value","Value","filter","keyApplies","atob","reduce","Object","assign","updateConfig","newConfig","callbacks","updates","keys","deletes","forEach","length","initializeConfiguration","Set","process","env","CONSUL_HOST","defaultHost","identifier","fetchIdentifier","liveProperties","updater","newProperties","getProperties","register","add","deregister","delete"],"sources":["../src/config.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport props from './properties';\nimport fetchIdentifier from './identifier';\nimport {parseKey, keyApplies} from './key-parser';\nimport atob from 'atob';\n\nconst configUpdater = (consulHost, prefix, service, callback) => {\n\tlet consulIndex;\n\tlet timeoutId;\n\tlet shutdown = false;\n\tconst self = {\n\t\tasync poll() {\n\t\t\tlet timeout = 500;\n\t\t\ttry {\n\t\t\t\tconst prefixUri = prefix ? `${prefix}/` : '';\n\t\t\t\tlet uri = `${consulHost}/v1/kv/${prefixUri}${service.name}/?recurse=true`;\n\t\t\t\tif (consulIndex) {\n\t\t\t\t\turi += `&index=${consulIndex}`;\n\t\t\t\t}\n\t\t\t\tconst response = await fetch(uri, {\n\t\t\t\t\theaders : {\n\t\t\t\t\t\t'accept' : 'application/json',\n\t\t\t\t\t\t'content-type' : 'application/json',\n\t\t\t\t\t\t'user-agent' : props.userAgent\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tconsulIndex = response.headers['x-consul-index'];\n\t\t\t\tif (response.status === 404) {\n\t\t\t\t\ttimeout = 5000;\n\t\t\t\t\tconst prefixText = prefix ? ` with prefix '${prefix}'` : '';\n\t\t\t\t\tconsole.warn(`'${service.name}'${prefixText} cannot be found in Consul`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (response.status !== 200) {\n\t\t\t\t\ttimeout = 60000;\n\t\t\t\t\tconsole.warn(`Error retrieving data from Consul: ${response.status}: ${await response.text()}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst json = await response.json();\n\t\t\t\tconst properties = parseBody(json, prefix, service);\n\t\t\t\tif (callback) {\n\t\t\t\t\tcallback(properties);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\ttimeout = 5000;\n\t\t\t\tconsole.warn(`Error retrieving data from Consul: ${e}`);\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tif (!shutdown) {\n\t\t\t\t\ttimeoutId = setTimeout(self.poll, timeout);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tstop() {\n\t\t\tshutdown = true;\n\t\t\tif (timeoutId) {\n\t\t\t\tclearTimeout(timeoutId);\n\t\t\t}\n\t\t}\n\t};\n\n\treturn self;\n};\n\n/**\n * Parses the fetched config from Consul and converts it to a proper object.\n * @param body {Array} - The response body\n * @param prefix {string} - The prefix to extract from the key path\n * @param service {Object} - The service identifier to match key specifiers against\n * @return {Object} A properties object containing all valid properties as specified in the body\n */\nfunction parseBody(body, prefix, service) {\n\treturn body.map(kvPair => {\n\t\treturn {key : parseKey(kvPair.Key, prefix), value : kvPair.Value};\n\t})\n\t\t.filter(kvPair => kvPair.key.key && keyApplies(kvPair.key, service))\n\t\t.map(kvPair => {\n\t\t\treturn {[kvPair.key.key] : atob(kvPair.value)};\n\t\t})\n\t\t.reduce((properties, kvPair) => Object.assign(properties, kvPair), {});\n}\n\nconst updateConfig = (properties, newConfig, callbacks) => {\n\tconst updates = Object.keys(newConfig).filter(key => properties[key] !== newConfig[key]);\n\n\tObject.assign(properties, newConfig);\n\n\tconst deletes = Object.keys(properties).filter(key => !newConfig[key]);\n\tdeletes.forEach(key => delete properties[key]);\n\n\tif (updates.length > 0 || deletes.length > 0) {\n\t\tcallbacks.forEach(callback => callback(Object.assign({}, properties)));\n\t}\n};\n\nexport default async function initializeConfiguration({consulHost, service, prefix}) {\n\tconst callbacks = new Set();\n\n\tconsulHost = consulHost || process.env.CONSUL_HOST || props.defaultHost;\n\n\tconst identifier = await fetchIdentifier(service, consulHost);\n\n\tlet liveProperties = {};\n\n\tconst updater = configUpdater(consulHost, prefix, identifier, (newProperties) => {\n\t\tupdateConfig(liveProperties, newProperties, callbacks);\n\t});\n\n\tawait updater.poll();\n\n\treturn {\n\t\tgetProperties() {\n\t\t\treturn Object.assign({}, liveProperties);\n\t\t},\n\t\tregister(callback) {\n\t\t\tcallbacks.add(callback);\n\t\t},\n\t\tderegister(callback) {\n\t\t\tcallbacks.delete(callback);\n\t\t},\n\t\tstop() {\n\t\t\tupdater.stop();\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAExB,MAAMG,aAAa,GAAGA,CAACC,UAAU,EAAEC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,KAAK;EAChE,IAAIC,WAAW;EACf,IAAIC,SAAS;EACb,IAAIC,QAAQ,GAAG,KAAK;EACpB,MAAMC,IAAI,GAAG;IACZ,MAAMC,IAAIA,CAAA,EAAG;MACZ,IAAIC,OAAO,GAAG,GAAG;MACjB,IAAI;QACH,MAAMC,SAAS,GAAGT,MAAM,GAAG,GAAGA,MAAM,GAAG,GAAG,EAAE;QAC5C,IAAIU,GAAG,GAAG,GAAGX,UAAU,UAAUU,SAAS,GAAGR,OAAO,CAACU,IAAI,gBAAgB;QACzE,IAAIR,WAAW,EAAE;UAChBO,GAAG,IAAI,UAAUP,WAAW,EAAE;QAC/B;QACA,MAAMS,QAAQ,GAAG,MAAM,IAAAC,kBAAK,EAACH,GAAG,EAAE;UACjCI,OAAO,EAAG;YACT,QAAQ,EAAG,kBAAkB;YAC7B,cAAc,EAAG,kBAAkB;YACnC,YAAY,EAAGC,mBAAK,CAACC;UACtB;QACD,CAAC,CAAC;QAEFb,WAAW,GAAGS,QAAQ,CAACE,OAAO,CAAC,gBAAg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AACsC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAElB,UAAU,CAAC,CAAC,CAAC;EACvE;AACD,CAAC;AAEc,eAAe2B,uBAAuBA,CAAC;EAACnD,UAAU;EAAEE,OAAO;EAAED;AAAM,CAAC,EAAE;EACpF,MAAM4C,SAAS,GAAG,IAAIO,GAAG,CAAC,CAAC;EAE3BpD,UAAU,GAAGA,UAAU,IAAIqD,OAAO,CAACC,GAAG,CAACC,WAAW,IAAIvC,mBAAK,CAACwC,WAAW;EAEvE,MAAMC,UAAU,GAAG,MAAM,IAAAC,mBAAe,EAACxD,OAAO,EAAEF,UAAU,CAAC;EAE7D,IAAI2D,cAAc,GAAG,CAAC,CAAC;EAEvB,MAAMC,OAAO,GAAG7D,aAAa,CAACC,UAAU,EAAEC,MAAM,EAAEwD,UAAU,EAAGI,aAAa,IAAK;IAChFlB,YAAY,CAACgB,cAAc,EAAEE,aAAa,EAAEhB,SAAS,CAAC;EACvD,CAAC,CAAC;EAEF,MAAMe,OAAO,CAACpD,IAAI,CAAC,CAAC;EAEpB,OAAO;IACNsD,aAAaA,CAAA,EAAG;MACf,OAAOrB,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEiB,cAAc,CAAC;IACzC,CAAC;IACDI,QAAQA,CAAC5D,QAAQ,EAAE;MAClB0C,SAAS,CAACmB,GAAG,CAAC7D,QAAQ,CAAC;IACxB,CAAC;IACD8D,UAAUA,CAAC9D,QAAQ,EAAE;MACpB0C,SAAS,CAACqB,MAAM,CAAC/D,QAAQ,CAAC;IAC3B,CAAC;IACDwB,IAAIA,CAAA,EAAG;MACNiC,OAAO,CAACjC,IAAI,CAAC,CAAC;IACf;EACD,CAAC;AACF","ignoreList":[]}
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class ConsultantError extends Error {
9
8
  constructor(message) {
10
9
  super(message);
11
10
  this.message = message;
12
11
  this.name = 'ConsultantError';
13
12
  }
14
-
15
13
  }
16
-
17
- var _default = ConsultantError;
18
- exports.default = _default;
14
+ var _default = exports.default = ConsultantError;
19
15
  //# sourceMappingURL=consultant-error.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/consultant-error.js"],"names":["ConsultantError","Error","constructor","message","name"],"mappings":";;;;;;;AAAA,MAAMA,eAAN,SAA8BC,KAA9B,CAAoC;AACnCC,EAAAA,WAAW,CAACC,OAAD,EAAU;AACpB,UAAMA,OAAN;AACA,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKC,IAAL,GAAY,iBAAZ;AACA;;AALkC;;eAQrBJ,e","sourcesContent":["class ConsultantError extends Error {\n\tconstructor(message) {\n\t\tsuper(message);\n\t\tthis.message = message;\n\t\tthis.name = 'ConsultantError';\n\t}\n}\n\nexport default ConsultantError;\n"],"file":"consultant-error.js"}
1
+ {"version":3,"file":"consultant-error.js","names":["ConsultantError","Error","constructor","message","name","_default","exports","default"],"sources":["../src/consultant-error.js"],"sourcesContent":["class ConsultantError extends Error {\n\tconstructor(message) {\n\t\tsuper(message);\n\t\tthis.message = message;\n\t\tthis.name = 'ConsultantError';\n\t}\n}\n\nexport default ConsultantError;\n"],"mappings":";;;;;;AAAA,MAAMA,eAAe,SAASC,KAAK,CAAC;EACnCC,WAAWA,CAACC,OAAO,EAAE;IACpB,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,IAAI,GAAG,iBAAiB;EAC9B;AACD;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcP,eAAe","ignoreList":[]}
package/out/health.js CHANGED
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = health;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _properties = _interopRequireDefault(require("./properties"));
11
-
12
9
  var _consultantError = _interopRequireDefault(require("./consultant-error"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
11
  async function health({
17
12
  service,
18
13
  consulHost
@@ -20,7 +15,6 @@ async function health({
20
15
  consulHost = consulHost || process.env.CONSUL_HOST || _properties.default.defaultHost;
21
16
  const uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`;
22
17
  let result;
23
-
24
18
  try {
25
19
  result = await (0, _nodeFetch.default)(uri, {
26
20
  method: 'GET',
@@ -31,11 +25,9 @@ async function health({
31
25
  } catch (e) {
32
26
  throw new _consultantError.default(`Could not get health for ${service}: ${e}`);
33
27
  }
34
-
35
28
  if (result.ok) {
36
29
  return result.json();
37
30
  }
38
-
39
31
  const body = result.text();
40
32
  throw new _consultantError.default(`Could not get health for ${service}: ${body} (status ${result.status})`);
41
33
  }
package/out/health.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/health.js"],"names":["health","service","consulHost","process","env","CONSUL_HOST","props","defaultHost","uri","result","method","headers","properties","userAgent","e","ConsultantError","ok","json","body","text","status"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;AAEe,eAAeA,MAAf,CAAsB;AAAEC,EAAAA,OAAF;AAAWC,EAAAA;AAAX,CAAtB,EAA+C;AAC7DA,EAAAA,UAAU,GAAGA,UAAU,IAAIC,OAAO,CAACC,GAAR,CAAYC,WAA1B,IAAyCC,oBAAMC,WAA5D;AACA,QAAMC,GAAG,GAAI,GAAEN,UAAW,sBAAqBD,OAAQ,2BAAvD;AAEA,MAAIQ,MAAJ;;AACA,MAAI;AACHA,IAAAA,MAAM,GAAG,MAAM,wBAAMD,GAAN,EAAW;AACzBE,MAAAA,MAAM,EAAG,KADgB;AAEzBC,MAAAA,OAAO,EAAG;AACT,sBAAeC,oBAAWC;AADjB;AAFe,KAAX,CAAf;AAMA,GAPD,CAQA,OAAOC,CAAP,EAAU;AACT,UAAM,IAAIC,wBAAJ,CAAqB,4BAA2Bd,OAAQ,KAAIa,CAAE,EAA9D,CAAN;AACA;;AAED,MAAIL,MAAM,CAACO,EAAX,EAAe;AACd,WAAOP,MAAM,CAACQ,IAAP,EAAP;AACA;;AACD,QAAMC,IAAI,GAAGT,MAAM,CAACU,IAAP,EAAb;AACA,QAAM,IAAIJ,wBAAJ,CAAqB,4BAA2Bd,OAAQ,KAAIiB,IAAK,YAAWT,MAAM,CAACW,MAAO,GAA1F,CAAN;AACA","sourcesContent":["import fetch from 'node-fetch';\nimport props from './properties';\nimport properties from './properties';\nimport ConsultantError from './consultant-error';\n\nexport default async function health({ service, consulHost }) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || props.defaultHost;\n\tconst uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`;\n\n\tlet result;\n\ttry {\n\t\tresult = await fetch(uri, {\n\t\t\tmethod : 'GET',\n\t\t\theaders : {\n\t\t\t\t'user-agent' : properties.userAgent\n\t\t\t}\n\t\t});\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not get health for ${service}: ${e}`);\n\t}\n\n\tif (result.ok) {\n\t\treturn result.json();\n\t}\n\tconst body = result.text();\n\tthrow new ConsultantError(`Could not get health for ${service}: ${body} (status ${result.status})`);\n}"],"file":"health.js"}
1
+ {"version":3,"file":"health.js","names":["_nodeFetch","_interopRequireDefault","require","_properties","_consultantError","e","__esModule","default","health","service","consulHost","process","env","CONSUL_HOST","props","defaultHost","uri","result","fetch","method","headers","properties","userAgent","ConsultantError","ok","json","body","text","status"],"sources":["../src/health.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport props from './properties';\nimport properties from './properties';\nimport ConsultantError from './consultant-error';\n\nexport default async function health({ service, consulHost }) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || props.defaultHost;\n\tconst uri = `${consulHost}/v1/health/service/${service}?near=_agent&passing=true`;\n\n\tlet result;\n\ttry {\n\t\tresult = await fetch(uri, {\n\t\t\tmethod : 'GET',\n\t\t\theaders : {\n\t\t\t\t'user-agent' : properties.userAgent\n\t\t\t}\n\t\t});\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not get health for ${service}: ${e}`);\n\t}\n\n\tif (result.ok) {\n\t\treturn result.json();\n\t}\n\tconst body = result.text();\n\tthrow new ConsultantError(`Could not get health for ${service}: ${body} (status ${result.status})`);\n}"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,gBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAiD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAElC,eAAeG,MAAMA,CAAC;EAAEC,OAAO;EAAEC;AAAW,CAAC,EAAE;EAC7DA,UAAU,GAAGA,UAAU,IAAIC,OAAO,CAACC,GAAG,CAACC,WAAW,IAAIC,mBAAK,CAACC,WAAW;EACvE,MAAMC,GAAG,GAAG,GAAGN,UAAU,sBAAsBD,OAAO,2BAA2B;EAEjF,IAAIQ,MAAM;EACV,IAAI;IACHA,MAAM,GAAG,MAAM,IAAAC,kBAAK,EAACF,GAAG,EAAE;MACzBG,MAAM,EAAG,KAAK;MACdC,OAAO,EAAG;QACT,YAAY,EAAGC,mBAAU,CAACC;MAC3B;IACD,CAAC,CAAC;EACH,CAAC,CACD,OAAOjB,CAAC,EAAE;IACT,MAAM,IAAIkB,wBAAe,CAAC,4BAA4Bd,OAAO,KAAKJ,CAAC,EAAE,CAAC;EACvE;EAEA,IAAIY,MAAM,CAACO,EAAE,EAAE;IACd,OAAOP,MAAM,CAACQ,IAAI,CAAC,CAAC;EACrB;EACA,MAAMC,IAAI,GAAGT,MAAM,CAACU,IAAI,CAAC,CAAC;EAC1B,MAAM,IAAIJ,wBAAe,CAAC,4BAA4Bd,OAAO,KAAKiB,IAAI,YAAYT,MAAM,CAACW,MAAM,GAAG,CAAC;AACpG","ignoreList":[]}
package/out/identifier.js CHANGED
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = loadIdentifier;
7
-
8
7
  var _agent = _interopRequireDefault(require("./agent"));
9
-
10
8
  var _crypto = require("crypto");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
10
  async function loadIdentifier(identifier, consulHost) {
15
11
  const agent = await (0, _agent.default)(consulHost);
16
12
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/identifier.js"],"names":["loadIdentifier","identifier","consulHost","agent","name","process","env","SERVICE_NAME","dataCenter","SERVICE_DC","Config","Datacenter","host","SERVICE_HOST","NodeName","instance","SERVICE_INSTANCE"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEe,eAAeA,cAAf,CAA8BC,UAA9B,EAA0CC,UAA1C,EAAsD;AACpE,QAAMC,KAAK,GAAG,MAAM,oBAAWD,UAAX,CAApB;AAEA,SAAO;AACNE,IAAAA,IAAI,EAAGH,UAAU,CAACG,IAAX,IAAmBC,OAAO,CAACC,GAAR,CAAYC,YADhC;AAENC,IAAAA,UAAU,EAAGP,UAAU,CAACO,UAAX,IAAyBH,OAAO,CAACC,GAAR,CAAYG,UAArC,IAAmDN,KAAK,CAACO,MAAN,CAAaC,UAFvE;AAGNC,IAAAA,IAAI,EAAGX,UAAU,CAACW,IAAX,IAAmBP,OAAO,CAACC,GAAR,CAAYO,YAA/B,IAA+CV,KAAK,CAACO,MAAN,CAAaI,QAH7D;AAINC,IAAAA,QAAQ,EAAGd,UAAU,CAACc,QAAX,IAAuBV,OAAO,CAACC,GAAR,CAAYU,gBAAnC,IAAuD;AAJ5D,GAAP;AAMA","sourcesContent":["import fetchAgent from './agent';\nimport { randomUUID } from 'crypto';\n\nexport default async function loadIdentifier(identifier, consulHost) {\n\tconst agent = await fetchAgent(consulHost);\n\n\treturn {\n\t\tname : identifier.name || process.env.SERVICE_NAME,\n\t\tdataCenter : identifier.dataCenter || process.env.SERVICE_DC || agent.Config.Datacenter,\n\t\thost : identifier.host || process.env.SERVICE_HOST || agent.Config.NodeName,\n\t\tinstance : identifier.instance || process.env.SERVICE_INSTANCE || randomUUID(),\n\t};\n}\n"],"file":"identifier.js"}
1
+ {"version":3,"file":"identifier.js","names":["_agent","_interopRequireDefault","require","_crypto","e","__esModule","default","loadIdentifier","identifier","consulHost","agent","fetchAgent","name","process","env","SERVICE_NAME","dataCenter","SERVICE_DC","Config","Datacenter","host","SERVICE_HOST","NodeName","instance","SERVICE_INSTANCE","randomUUID"],"sources":["../src/identifier.js"],"sourcesContent":["import fetchAgent from './agent';\nimport { randomUUID } from 'crypto';\n\nexport default async function loadIdentifier(identifier, consulHost) {\n\tconst agent = await fetchAgent(consulHost);\n\n\treturn {\n\t\tname : identifier.name || process.env.SERVICE_NAME,\n\t\tdataCenter : identifier.dataCenter || process.env.SERVICE_DC || agent.Config.Datacenter,\n\t\thost : identifier.host || process.env.SERVICE_HOST || agent.Config.NodeName,\n\t\tinstance : identifier.instance || process.env.SERVICE_INSTANCE || randomUUID(),\n\t};\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAAoC,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAErB,eAAeG,cAAcA,CAACC,UAAU,EAAEC,UAAU,EAAE;EACpE,MAAMC,KAAK,GAAG,MAAM,IAAAC,cAAU,EAACF,UAAU,CAAC;EAE1C,OAAO;IACNG,IAAI,EAAGJ,UAAU,CAACI,IAAI,IAAIC,OAAO,CAACC,GAAG,CAACC,YAAY;IAClDC,UAAU,EAAGR,UAAU,CAACQ,UAAU,IAAIH,OAAO,CAACC,GAAG,CAACG,UAAU,IAAIP,KAAK,CAACQ,MAAM,CAACC,UAAU;IACvFC,IAAI,EAAGZ,UAAU,CAACY,IAAI,IAAIP,OAAO,CAACC,GAAG,CAACO,YAAY,IAAIX,KAAK,CAACQ,MAAM,CAACI,QAAQ;IAC3EC,QAAQ,EAAGf,UAAU,CAACe,QAAQ,IAAIV,OAAO,CAACC,GAAG,CAACU,gBAAgB,IAAI,IAAAC,kBAAU,EAAC;EAC9E,CAAC;AACF","ignoreList":[]}
package/out/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "service", {
7
- enumerable: true,
8
- get: function () {
9
- return _service.default;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "config", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -21,12 +15,14 @@ Object.defineProperty(exports, "health", {
21
15
  return _health.default;
22
16
  }
23
17
  });
24
-
18
+ Object.defineProperty(exports, "service", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _service.default;
22
+ }
23
+ });
25
24
  var _service = _interopRequireDefault(require("./service"));
26
-
27
25
  var _config = _interopRequireDefault(require("./config"));
28
-
29
26
  var _health = _interopRequireDefault(require("./health"));
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
32
28
  //# sourceMappingURL=index.js.map
package/out/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["import service from './service';\nimport config from './config';\nimport health from './health';\n\nexport {\n\t/**\n\t * Registers a service with Consul\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service - The service specific configuration\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {Number} configuration.service.port - The port on which this service runs\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.healthCheckPath] - An optional http path where the health check can be found\n\t * @param {Number} [configuration.healthCheckInterval] - The interval (in seconds) at which the health check is polled. If 0 no health check is done\n\t * @param {string} [configuration.consulHost] - Where Consultant can find a Consul agent\n\t * @return {Promise} An Promise containing the identifier as well as a deregister function\n\t * @return {Object} identifier - The specified service identifier\n\t * @return {function} deregister - Function to deregister the service with its health check from Consul\n\t */\n\tservice,\n\t/**\n\t * Set up the key/value retrieval and polling\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service The service identifier used to validate properties against\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.prefix] - The prefix path that should be before the service name in the key/value store\n\t * @param {Number} [configuration.interval] - The interval (in milliseconds) at which to poll the store. If set to 0, no polling will be done\n\t * @return {Promise} A promise containing the configuration Object\n\t * @return {function} getProperties - Getter to retrieve a copy of the current properties\n\t * @return {function} register - Register a callback that receives the latest properties object any time a change is detected\n\t * @return {function} deregister - Remove a registered callback\n\t * @return {function} stop - Stop the store polling\n\t */\n\tconfig,\n\t/**\n\t * Get the health information for a service\n\t * @function\n\t * @param {Object} configuration\n\t * @param {string} configuration.service The service name to search\n\t * @param {string} configuration.consulHost Where Consultant can find a Consul agent\n\t */\n\thealth\n};\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["_service","_interopRequireDefault","require","_config","_health","e","__esModule","default"],"sources":["../src/index.js"],"sourcesContent":["import service from './service';\nimport config from './config';\nimport health from './health';\n\nexport {\n\t/**\n\t * Registers a service with Consul\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service - The service specific configuration\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {Number} configuration.service.port - The port on which this service runs\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.healthCheckPath] - An optional http path where the health check can be found\n\t * @param {Number} [configuration.healthCheckInterval] - The interval (in seconds) at which the health check is polled. If 0 no health check is done\n\t * @param {string} [configuration.consulHost] - Where Consultant can find a Consul agent\n\t * @return {Promise} An Promise containing the identifier as well as a deregister function\n\t * @return {Object} identifier - The specified service identifier\n\t * @return {function} deregister - Function to deregister the service with its health check from Consul\n\t */\n\tservice,\n\t/**\n\t * Set up the key/value retrieval and polling\n\t * @function\n\t * @param {Object} configuration\n\t * @param {Object} configuration.service The service identifier used to validate properties against\n\t * @param {string} configuration.service.name - The name of the service (Used in both the registration and config retrieving)\n\t * @param {string} [configuration.service.dataCenter] - The data center the service resides in\n\t * @param {string} [configuration.service.host] - The host where Consul can find the service\n\t * @param {string} [configuration.service.instance] - The instance identifier of the service\n\t * @param {string} [configuration.prefix] - The prefix path that should be before the service name in the key/value store\n\t * @param {Number} [configuration.interval] - The interval (in milliseconds) at which to poll the store. If set to 0, no polling will be done\n\t * @return {Promise} A promise containing the configuration Object\n\t * @return {function} getProperties - Getter to retrieve a copy of the current properties\n\t * @return {function} register - Register a callback that receives the latest properties object any time a change is detected\n\t * @return {function} deregister - Remove a registered callback\n\t * @return {function} stop - Stop the store polling\n\t */\n\tconfig,\n\t/**\n\t * Get the health information for a service\n\t * @function\n\t * @param {Object} configuration\n\t * @param {string} configuration.service The service name to search\n\t * @param {string} configuration.consulHost Where Consultant can find a Consul agent\n\t */\n\thealth\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AAA8B,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
package/out/key-parser.js CHANGED
@@ -3,25 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.parseKey = parseKey;
7
6
  exports.keyApplies = keyApplies;
7
+ exports.parseKey = parseKey;
8
8
  const validSpecifiers = {
9
9
  dc: 'dataCenter',
10
10
  host: 'host',
11
11
  instance: 'instance'
12
12
  };
13
-
14
13
  function parseKey(key, prefix) {
15
14
  let tail = key;
16
-
17
15
  if (prefix) {
18
16
  if (!key.startsWith(prefix + '/')) {
19
17
  return undefined;
20
18
  }
21
-
22
19
  tail = key.substring(prefix.length + 1);
23
20
  }
24
-
25
21
  if (tail.includes('/[')) {
26
22
  const specifierStart = tail.indexOf('/[');
27
23
  const serviceName = tail.substring(0, specifierStart);
@@ -47,15 +43,15 @@ function parseKey(key, prefix) {
47
43
  };
48
44
  }
49
45
  }
46
+
50
47
  /**
51
48
  * Splits up the specifier string into an array of specifier objects
52
49
  * @param {string} specifiersPart - A string of the following expected format: [spec1=val1,spec2=val2,...]
53
50
  * @return {Array} An array of specifiers in the following format [{dataCenter:'development'},{host:'localhost'},...]
54
51
  */
55
-
56
-
57
52
  function extractSpecifiers(specifiersPart) {
58
- return specifiersPart.split(',').map(specifier => specifier.split('=')) // validSpecifiers is a hard-coded object so this check is safe
53
+ return specifiersPart.split(',').map(specifier => specifier.split('='))
54
+ // validSpecifiers is a hard-coded object so this check is safe
59
55
  // eslint-disable-next-line no-prototype-builtins
60
56
  .filter(kvArray => validSpecifiers.hasOwnProperty(kvArray[0])).map(kvArray => {
61
57
  const key = validSpecifiers[kvArray[0]];
@@ -64,11 +60,9 @@ function extractSpecifiers(specifiersPart) {
64
60
  };
65
61
  });
66
62
  }
67
-
68
63
  function keyApplies(key, service) {
69
64
  return isUnsetOrEqual(key.name, service.name) && isUnsetOrEqual(key.dataCenter, service.dataCenter) && isUnsetOrEqual(key.host, service.host) && isUnsetOrEqual(key.instance, service.instance);
70
65
  }
71
-
72
66
  function isUnsetOrEqual(keyField, serviceField) {
73
67
  return !keyField || keyField === serviceField;
74
68
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/key-parser.js"],"names":["validSpecifiers","dc","host","instance","parseKey","key","prefix","tail","startsWith","undefined","substring","length","includes","specifierStart","indexOf","serviceName","specifierEnd","specifiersPart","specifiers","extractSpecifiers","Object","assign","name","split","map","specifier","filter","kvArray","hasOwnProperty","keyApplies","service","isUnsetOrEqual","dataCenter","keyField","serviceField"],"mappings":";;;;;;;AAAA,MAAMA,eAAe,GAAG;AAACC,EAAAA,EAAE,EAAG,YAAN;AAAoBC,EAAAA,IAAI,EAAG,MAA3B;AAAmCC,EAAAA,QAAQ,EAAG;AAA9C,CAAxB;;AAEA,SAASC,QAAT,CAAkBC,GAAlB,EAAuBC,MAAvB,EAA+B;AAC9B,MAAIC,IAAI,GAAGF,GAAX;;AACA,MAAIC,MAAJ,EAAY;AACX,QAAI,CAACD,GAAG,CAACG,UAAJ,CAAeF,MAAM,GAAG,GAAxB,CAAL,EAAmC;AAClC,aAAOG,SAAP;AACA;;AACDF,IAAAA,IAAI,GAAGF,GAAG,CAACK,SAAJ,CAAcJ,MAAM,CAACK,MAAP,GAAgB,CAA9B,CAAP;AACA;;AAED,MAAIJ,IAAI,CAACK,QAAL,CAAc,IAAd,CAAJ,EAAyB;AACxB,UAAMC,cAAc,GAAGN,IAAI,CAACO,OAAL,CAAa,IAAb,CAAvB;AACA,UAAMC,WAAW,GAAGR,IAAI,CAACG,SAAL,CAAe,CAAf,EAAkBG,cAAlB,CAApB;AACA,UAAMG,YAAY,GAAGT,IAAI,CAACO,OAAL,CAAa,GA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A,WAAO;AAAC,OAACtB,GAAD,GAAQsB,OAAO,CAAC,CAAD;AAAhB,KAAP;AACA,GARK,CAAP;AASA;;AAED,SAASE,UAAT,CAAoBxB,GAApB,EAAyByB,OAAzB,EAAkC;AACjC,SAAOC,cAAc,CAAC1B,GAAG,CAACiB,IAAL,EAAWQ,OAAO,CAACR,IAAnB,CAAd,IACHS,cAAc,CAAC1B,GAAG,CAAC2B,UAAL,EAAiBF,OAAO,CAACE,UAAzB,CADX,IAEHD,cAAc,CAAC1B,GAAG,CAACH,IAAL,EAAW4B,OAAO,CAAC5B,IAAnB,CAFX,IAGH6B,cAAc,CAAC1B,GAAG,CAACF,QAAL,EAAe2B,OAAO,CAAC3B,QAAvB,CAHlB;AAIA;;AAED,SAAS4B,cAAT,CAAwBE,QAAxB,EAAkCC,YAAlC,EAAgD;AAC/C,SAAO,CAACD,QAAD,IAAaA,QAAQ,KAAKC,YAAjC;AACA","sourcesContent":["const validSpecifiers = {dc : 'dataCenter', host : 'host', instance : 'instance'};\n\nfunction parseKey(key, prefix) {\n\tlet tail = key;\n\tif (prefix) {\n\t\tif (!key.startsWith(prefix + '/')) {\n\t\t\treturn undefined;\n\t\t}\n\t\ttail = key.substring(prefix.length + 1);\n\t}\n\n\tif (tail.includes('/[')) {\n\t\tconst specifierStart = tail.indexOf('/[');\n\t\tconst serviceName = tail.substring(0, specifierStart);\n\t\tconst specifierEnd = tail.indexOf(']');\n\t\tconst specifiersPart = tail.substring(specifierStart + 2, specifierEnd);\n\n\t\tconst specifiers = extractSpecifiers(specifiersPart);\n\n\t\ttail = tail.substring(specifierEnd + 1);\n\n\t\treturn Object.assign({name : serviceName, key : tail}, ...specifiers);\n\t}\n\telse if (tail.includes('/')) {\n\t\tconst serviceName = tail.substring(0, tail.indexOf('/'));\n\t\ttail = tail.substring(tail.indexOf('/') + 1);\n\t\treturn {key : tail, name : serviceName};\n\t}\n\telse {\n\t\treturn {key : '', name : tail};\n\t}\n}\n\n/**\n * Splits up the specifier string into an array of specifier objects\n * @param {string} specifiersPart - A string of the following expected format: [spec1=val1,spec2=val2,...]\n * @return {Array} An array of specifiers in the following format [{dataCenter:'development'},{host:'localhost'},...]\n */\nfunction extractSpecifiers(specifiersPart) {\n\treturn specifiersPart.split(',')\n\t\t.map(specifier => specifier.split('='))\n\t\t// validSpecifiers is a hard-coded object so this check is safe\n\t\t// eslint-disable-next-line no-prototype-builtins\n\t\t.filter(kvArray => validSpecifiers.hasOwnProperty(kvArray[0]))\n\t\t.map(kvArray => {\n\t\t\tconst key = validSpecifiers[kvArray[0]];\n\t\t\treturn {[key] : kvArray[1]};\n\t\t});\n}\n\nfunction keyApplies(key, service) {\n\treturn isUnsetOrEqual(key.name, service.name)\n\t\t&& isUnsetOrEqual(key.dataCenter, service.dataCenter)\n\t\t&& isUnsetOrEqual(key.host, service.host)\n\t\t&& isUnsetOrEqual(key.instance, service.instance);\n}\n\nfunction isUnsetOrEqual(keyField, serviceField) {\n\treturn !keyField || keyField === serviceField;\n}\n\nexport {parseKey, keyApplies};"],"file":"key-parser.js"}
1
+ {"version":3,"file":"key-parser.js","names":["validSpecifiers","dc","host","instance","parseKey","key","prefix","tail","startsWith","undefined","substring","length","includes","specifierStart","indexOf","serviceName","specifierEnd","specifiersPart","specifiers","extractSpecifiers","Object","assign","name","split","map","specifier","filter","kvArray","hasOwnProperty","keyApplies","service","isUnsetOrEqual","dataCenter","keyField","serviceField"],"sources":["../src/key-parser.js"],"sourcesContent":["const validSpecifiers = {dc : 'dataCenter', host : 'host', instance : 'instance'};\n\nfunction parseKey(key, prefix) {\n\tlet tail = key;\n\tif (prefix) {\n\t\tif (!key.startsWith(prefix + '/')) {\n\t\t\treturn undefined;\n\t\t}\n\t\ttail = key.substring(prefix.length + 1);\n\t}\n\n\tif (tail.includes('/[')) {\n\t\tconst specifierStart = tail.indexOf('/[');\n\t\tconst serviceName = tail.substring(0, specifierStart);\n\t\tconst specifierEnd = tail.indexOf(']');\n\t\tconst specifiersPart = tail.substring(specifierStart + 2, specifierEnd);\n\n\t\tconst specifiers = extractSpecifiers(specifiersPart);\n\n\t\ttail = tail.substring(specifierEnd + 1);\n\n\t\treturn Object.assign({name : serviceName, key : tail}, ...specifiers);\n\t}\n\telse if (tail.includes('/')) {\n\t\tconst serviceName = tail.substring(0, tail.indexOf('/'));\n\t\ttail = tail.substring(tail.indexOf('/') + 1);\n\t\treturn {key : tail, name : serviceName};\n\t}\n\telse {\n\t\treturn {key : '', name : tail};\n\t}\n}\n\n/**\n * Splits up the specifier string into an array of specifier objects\n * @param {string} specifiersPart - A string of the following expected format: [spec1=val1,spec2=val2,...]\n * @return {Array} An array of specifiers in the following format [{dataCenter:'development'},{host:'localhost'},...]\n */\nfunction extractSpecifiers(specifiersPart) {\n\treturn specifiersPart.split(',')\n\t\t.map(specifier => specifier.split('='))\n\t\t// validSpecifiers is a hard-coded object so this check is safe\n\t\t// eslint-disable-next-line no-prototype-builtins\n\t\t.filter(kvArray => validSpecifiers.hasOwnProperty(kvArray[0]))\n\t\t.map(kvArray => {\n\t\t\tconst key = validSpecifiers[kvArray[0]];\n\t\t\treturn {[key] : kvArray[1]};\n\t\t});\n}\n\nfunction keyApplies(key, service) {\n\treturn isUnsetOrEqual(key.name, service.name)\n\t\t&& isUnsetOrEqual(key.dataCenter, service.dataCenter)\n\t\t&& isUnsetOrEqual(key.host, service.host)\n\t\t&& isUnsetOrEqual(key.instance, service.instance);\n}\n\nfunction isUnsetOrEqual(keyField, serviceField) {\n\treturn !keyField || keyField === serviceField;\n}\n\nexport {parseKey, keyApplies};"],"mappings":";;;;;;;AAAA,MAAMA,eAAe,GAAG;EAACC,EAAE,EAAG,YAAY;EAAEC,IAAI,EAAG,MAAM;EAAEC,QAAQ,EAAG;AAAU,CAAC;AAEjF,SAASC,QAAQA,CAACC,GAAG,EAAEC,MAAM,EAAE;EAC9B,IAAIC,IAAI,GAAGF,GAAG;EACd,IAAIC,MAAM,EAAE;IACX,IAAI,CAACD,GAAG,CAACG,UAAU,C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,cAAc,EAAE;EAC1C,OAAOA,cAAc,CAACM,KAAK,CAAC,GAAG,CAAC,CAC9BC,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACF,KAAK,CAAC,GAAG,CAAC;EACtC;EACA;EAAA,CACCG,MAAM,CAACC,OAAO,IAAI3B,eAAe,CAAC4B,cAAc,CAACD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7DH,GAAG,CAACG,OAAO,IAAI;IACf,MAAMtB,GAAG,GAAGL,eAAe,CAAC2B,OAAO,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO;MAAC,CAACtB,GAAG,GAAIsB,OAAO,CAAC,CAAC;IAAC,CAAC;EAC5B,CAAC,CAAC;AACJ;AAEA,SAASE,UAAUA,CAACxB,GAAG,EAAEyB,OAAO,EAAE;EACjC,OAAOC,cAAc,CAAC1B,GAAG,CAACiB,IAAI,EAAEQ,OAAO,CAACR,IAAI,CAAC,IACzCS,cAAc,CAAC1B,GAAG,CAAC2B,UAAU,EAAEF,OAAO,CAACE,UAAU,CAAC,IAClDD,cAAc,CAAC1B,GAAG,CAACH,IAAI,EAAE4B,OAAO,CAAC5B,IAAI,CAAC,IACtC6B,cAAc,CAAC1B,GAAG,CAACF,QAAQ,EAAE2B,OAAO,CAAC3B,QAAQ,CAAC;AACnD;AAEA,SAAS4B,cAAcA,CAACE,QAAQ,EAAEC,YAAY,EAAE;EAC/C,OAAO,CAACD,QAAQ,IAAIA,QAAQ,KAAKC,YAAY;AAC9C","ignoreList":[]}
package/out/properties.js CHANGED
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = {
7
+ var _default = exports.default = {
8
8
  userAgent: 'consultant-js',
9
9
  defaultHost: 'http://localhost:8500'
10
10
  };
11
- exports.default = _default;
12
11
  //# sourceMappingURL=properties.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/properties.js"],"names":["userAgent","defaultHost"],"mappings":";;;;;;eAAe;AACdA,EAAAA,SAAS,EAAE,eADG;AAEdC,EAAAA,WAAW,EAAE;AAFC,C","sourcesContent":["export default {\n\tuserAgent: 'consultant-js',\n\tdefaultHost: 'http://localhost:8500'\n};\n"],"file":"properties.js"}
1
+ {"version":3,"file":"properties.js","names":["userAgent","defaultHost"],"sources":["../src/properties.js"],"sourcesContent":["export default {\n\tuserAgent: 'consultant-js',\n\tdefaultHost: 'http://localhost:8500'\n};\n"],"mappings":";;;;;;iCAAe;EACdA,SAAS,EAAE,eAAe;EAC1BC,WAAW,EAAE;AACd,CAAC","ignoreList":[]}
package/out/service.js CHANGED
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = register;
7
-
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _consultantError = _interopRequireDefault(require("./consultant-error"));
11
-
12
9
  var _properties = _interopRequireDefault(require("./properties"));
13
-
14
10
  var _identifier = _interopRequireDefault(require("./identifier"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
12
  const deregister = async (host, instance) => {
19
13
  const uri = `${host}/v1/agent/service/deregister/${instance.instance}`;
20
14
  const opts = {
@@ -23,14 +17,12 @@ const deregister = async (host, instance) => {
23
17
  'user-agent': _properties.default.userAgent
24
18
  }
25
19
  };
26
-
27
20
  try {
28
21
  await (0, _nodeFetch.default)(uri, opts);
29
22
  } catch (e) {
30
23
  throw new _consultantError.default(`Could not deregister from Consul: ${e}`);
31
24
  }
32
25
  };
33
-
34
26
  async function register({
35
27
  service,
36
28
  healthCheckPath,
@@ -39,15 +31,12 @@ async function register({
39
31
  }) {
40
32
  consulHost = consulHost || process.env.CONSUL_HOST || _properties.default.defaultHost;
41
33
  const portNumber = Number(service.port);
42
-
43
34
  if (!(portNumber > 0 && portNumber < 65536)) {
44
35
  throw new _consultantError.default(`service.port=${service.port} is not a proper port`);
45
36
  }
46
-
47
37
  if (!service.name) {
48
38
  throw new _consultantError.default('service.name was not defined');
49
39
  }
50
-
51
40
  const identifier = await (0, _identifier.default)(service, consulHost);
52
41
  const body = {
53
42
  Id: identifier.instance,
@@ -55,16 +44,14 @@ async function register({
55
44
  Address: identifier.host,
56
45
  Port: service.port
57
46
  };
58
-
59
47
  if (healthCheckPath && healthCheckInterval > 0) {
60
48
  Object.assign(body, {
61
49
  Check: {
62
50
  HTTP: `http://${identifier.host}:${service.port}${healthCheckPath}`,
63
- Interval: healthCheckInterval
51
+ Interval: `${healthCheckInterval}s`
64
52
  }
65
53
  });
66
54
  }
67
-
68
55
  const url = `${consulHost}/v1/agent/service/register`;
69
56
  const opts = {
70
57
  method: 'PUT',
@@ -75,13 +62,11 @@ async function register({
75
62
  },
76
63
  body: JSON.stringify(body)
77
64
  };
78
-
79
65
  try {
80
66
  await (0, _nodeFetch.default)(url, opts);
81
67
  } catch (e) {
82
68
  throw new _consultantError.default('Could not register service with Consul', e);
83
69
  }
84
-
85
70
  return {
86
71
  identifier,
87
72
  deregister: () => deregister(consulHost, identifier)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/service.js"],"names":["deregister","host","instance","uri","opts","method","headers","properties","userAgent","e","ConsultantError","register","service","healthCheckPath","healthCheckInterval","consulHost","process","env","CONSUL_HOST","defaultHost","portNumber","Number","port","name","identifier","body","Id","Name","Address","Port","Object","assign","Check","HTTP","Interval","url","JSON","stringify"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAEA,MAAMA,UAAU,GAAG,OAAOC,IAAP,EAAaC,QAAb,KAA0B;AAC5C,QAAMC,GAAG,GAAI,GAAEF,IAAK,gCAA+BC,QAAQ,CAACA,QAAS,EAArE;AACA,QAAME,IAAI,GAAG;AACZC,IAAAA,MAAM,EAAG,KADG;AAEZC,IAAAA,OAAO,EAAG;AACT,oBAAeC,oBAAWC;AADjB;AAFE,GAAb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U,IAAK,GAAET,eAAgB,EAD5D;AAEPqB,QAAAA,QAAQ,EAAGpB;AAFJ;AADW,KAApB;AAMA;;AAED,QAAMqB,GAAG,GAAI,GAAEpB,UAAW,4BAA1B;AACA,QAAMX,IAAI,GAAG;AACZC,IAAAA,MAAM,EAAG,KADG;AAEZC,IAAAA,OAAO,EAAG;AACT,gBAAW,kBADF;AAET,sBAAiB,kBAFR;AAGT,oBAAeC,oBAAWC;AAHjB,KAFE;AAOZiB,IAAAA,IAAI,EAAGW,IAAI,CAACC,SAAL,CAAeZ,IAAf;AAPK,GAAb;;AAUA,MAAI;AACH,UAAM,wBAAMU,GAAN,EAAW/B,IAAX,CAAN;AACA,GAFD,CAGA,OAAOK,CAAP,EAAU;AACT,UAAM,IAAIC,wBAAJ,CAAoB,wCAApB,EAA8DD,CAA9D,CAAN;AACA;;AAED,SAAO;AACNe,IAAAA,UADM;AAENxB,IAAAA,UAAU,EAAG,MAAMA,UAAU,CAACe,UAAD,EAAaS,UAAb;AAFvB,GAAP;AAIA","sourcesContent":["import fetch from 'node-fetch';\nimport ConsultantError from './consultant-error';\nimport properties from './properties';\nimport fetchIdentifier from './identifier';\n\nconst deregister = async (host, instance) => {\n\tconst uri = `${host}/v1/agent/service/deregister/${instance.instance}`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'user-agent' : properties.userAgent\n\t\t}\n\t};\n\n\ttry {\n\t\tawait fetch(uri, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not deregister from Consul: ${e}`);\n\t}\n};\n\nexport default async function register({service, healthCheckPath, healthCheckInterval = 10, consulHost}) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || properties.defaultHost;\n\n\tconst portNumber = Number(service.port);\n\tif (!(portNumber > 0 && portNumber < 65536)) {\n\t\tthrow new ConsultantError(`service.port=${service.port} is not a proper port`);\n\t}\n\n\tif (!service.name) {\n\t\tthrow new ConsultantError('service.name was not defined');\n\t}\n\n\tconst identifier = await fetchIdentifier(service, consulHost);\n\n\tconst body = {\n\t\tId : identifier.instance,\n\t\tName : identifier.name,\n\t\tAddress : identifier.host,\n\t\tPort : service.port,\n\t};\n\n\tif (healthCheckPath && healthCheckInterval > 0) {\n\t\tObject.assign(body, {\n\t\t\tCheck : {\n\t\t\t\tHTTP : `http://${identifier.host}:${service.port}${healthCheckPath}`,\n\t\t\t\tInterval : healthCheckInterval\n\t\t\t}\n\t\t});\n\t}\n\n\tconst url = `${consulHost}/v1/agent/service/register`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'accept' : 'application/json',\n\t\t\t'content-type' : 'application/json',\n\t\t\t'user-agent' : properties.userAgent\n\t\t},\n\t\tbody : JSON.stringify(body)\n\t};\n\n\ttry {\n\t\tawait fetch(url, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError('Could not register service with Consul', e);\n\t}\n\n\treturn {\n\t\tidentifier,\n\t\tderegister : () => deregister(consulHost, identifier)\n\t};\n}\n"],"file":"service.js"}
1
+ {"version":3,"file":"service.js","names":["_nodeFetch","_interopRequireDefault","require","_consultantError","_properties","_identifier","e","__esModule","default","deregister","host","instance","uri","opts","method","headers","properties","userAgent","fetch","ConsultantError","register","service","healthCheckPath","healthCheckInterval","consulHost","process","env","CONSUL_HOST","defaultHost","portNumber","Number","port","name","identifier","fetchIdentifier","body","Id","Name","Address","Port","Object","assign","Check","HTTP","Interval","url","JSON","stringify"],"sources":["../src/service.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport ConsultantError from './consultant-error';\nimport properties from './properties';\nimport fetchIdentifier from './identifier';\n\nconst deregister = async (host, instance) => {\n\tconst uri = `${host}/v1/agent/service/deregister/${instance.instance}`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'user-agent' : properties.userAgent\n\t\t}\n\t};\n\n\ttry {\n\t\tawait fetch(uri, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError(`Could not deregister from Consul: ${e}`);\n\t}\n};\n\nexport default async function register({service, healthCheckPath, healthCheckInterval = 10, consulHost}) {\n\tconsulHost = consulHost || process.env.CONSUL_HOST || properties.defaultHost;\n\n\tconst portNumber = Number(service.port);\n\tif (!(portNumber > 0 && portNumber < 65536)) {\n\t\tthrow new ConsultantError(`service.port=${service.port} is not a proper port`);\n\t}\n\n\tif (!service.name) {\n\t\tthrow new ConsultantError('service.name was not defined');\n\t}\n\n\tconst identifier = await fetchIdentifier(service, consulHost);\n\n\tconst body = {\n\t\tId : identifier.instance,\n\t\tName : identifier.name,\n\t\tAddress : identifier.host,\n\t\tPort : service.port,\n\t};\n\n\tif (healthCheckPath && healthCheckInterval > 0) {\n\t\tObject.assign(body, {\n\t\t\tCheck : {\n\t\t\t\tHTTP : `http://${identifier.host}:${service.port}${healthCheckPath}`,\n\t\t\t\tInterval : `${healthCheckInterval}s`\n\t\t\t}\n\t\t});\n\t}\n\n\tconst url = `${consulHost}/v1/agent/service/register`;\n\tconst opts = {\n\t\tmethod : 'PUT',\n\t\theaders : {\n\t\t\t'accept' : 'application/json',\n\t\t\t'content-type' : 'application/json',\n\t\t\t'user-agent' : properties.userAgent\n\t\t},\n\t\tbody : JSON.stringify(body)\n\t};\n\n\ttry {\n\t\tawait fetch(url, opts);\n\t}\n\tcatch (e) {\n\t\tthrow new ConsultantError('Could not register service with Consul', e);\n\t}\n\n\treturn {\n\t\tidentifier,\n\t\tderegister : () => deregister(consulHost, identifier)\n\t};\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAA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ED,IAAIT,eAAe,IAAIC,mBAAmB,GAAG,CAAC,EAAE;IAC/CiB,MAAM,CAACC,MAAM,CAACN,IAAI,EAAE;MACnBO,KAAK,EAAG;QACPC,IAAI,EAAG,UAAUV,UAAU,CAACvB,IAAI,IAAIW,OAAO,CAACU,IAAI,GAAGT,eAAe,EAAE;QACpEsB,QAAQ,EAAG,GAAGrB,mBAAmB;MAClC;IACD,CAAC,CAAC;EACH;EAEA,MAAMsB,GAAG,GAAG,GAAGrB,UAAU,4BAA4B;EACrD,MAAMX,IAAI,GAAG;IACZC,MAAM,EAAG,KAAK;IACdC,OAAO,EAAG;MACT,QAAQ,EAAG,kBAAkB;MAC7B,cAAc,EAAG,kBAAkB;MACnC,YAAY,EAAGC,mBAAU,CAACC;IAC3B,CAAC;IACDkB,IAAI,EAAGW,IAAI,CAACC,SAAS,CAACZ,IAAI;EAC3B,CAAC;EAED,IAAI;IACH,MAAM,IAAAjB,kBAAK,EAAC2B,GAAG,EAAEhC,IAAI,CAAC;EACvB,CAAC,CACD,OAAOP,CAAC,EAAE;IACT,MAAM,IAAIa,wBAAe,CAAC,wCAAwC,EAAEb,CAAC,CAAC;EACvE;EAEA,OAAO;IACN2B,UAAU;IACVxB,UAAU,EAAGA,CAAA,KAAMA,UAAU,CAACe,UAAU,EAAES,UAAU;EACrD,CAAC;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magnet.me/consultant",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "A library to register services to Consul and listen for property changes.",
5
5
  "main": "out/index.js",
6
6
  "scripts": {
@@ -16,11 +16,13 @@
16
16
  "node-fetch": "^2.6.7"
17
17
  },
18
18
  "devDependencies": {
19
- "@babel/cli": "^7.0.0",
20
- "@babel/core": "^7.0.0",
21
- "@babel/preset-env": "^7.0.0",
22
- "eslint": "^6.8.0",
23
- "express": "^4.15.3"
19
+ "@babel/cli": "^7.28.6",
20
+ "@babel/core": "^7.29.0",
21
+ "@babel/preset-env": "^7.29.5",
22
+ "@babel/traverse": "^7.29.0",
23
+ "@eslint/js": "^10.0.1",
24
+ "eslint": "^10.3.0",
25
+ "globals": "^17.6.0"
24
26
  },
25
27
  "directories": {
26
28
  "example": "example"
@@ -33,8 +35,5 @@
33
35
  "url": "https://github.com/Magnetme/consultant-js/issues"
34
36
  },
35
37
  "homepage": "https://github.com/Magnetme/consultant-js#readme",
36
- "types": "./out/index.d.ts",
37
- "resolutions": {
38
- "@babel/traverse": "7.23.2"
39
- }
38
+ "types": "./out/index.d.ts"
40
39
  }
package/out/promisify.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = promisify;
7
-
8
- function promisify(func) {
9
- return new Promise((resolve, reject) => {
10
- func((err, res) => {
11
- if (err) {
12
- reject(err);
13
- } else {
14
- resolve(res);
15
- }
16
- });
17
- });
18
- }
19
- //# sourceMappingURL=promisify.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/promisify.js"],"names":["promisify","func","Promise","resolve","reject","err","res"],"mappings":";;;;;;;AAAe,SAASA,SAAT,CAAmBC,IAAnB,EAAyB;AACvC,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACvCH,IAAAA,IAAI,CAAC,CAACI,GAAD,EAAMC,GAAN,KAAc;AAClB,UAAID,GAAJ,EAAS;AACRD,QAAAA,MAAM,CAACC,GAAD,CAAN;AACA,OAFD,MAEO;AACNF,QAAAA,OAAO,CAACG,GAAD,CAAP;AACA;AACD,KANG,CAAJ;AAOA,GARM,CAAP;AASA","sourcesContent":["export default function promisify(func) {\n\treturn new Promise((resolve, reject) => {\n\t\tfunc((err, res) => {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t});\n\t});\n}\n"],"file":"promisify.js"}