fa-consul 1.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.
Files changed (125) hide show
  1. package/README.md +112 -0
  2. package/dist/__tests__/lib/logger.d.ts +3 -0
  3. package/dist/__tests__/lib/logger.d.ts.map +1 -0
  4. package/dist/__tests__/lib/logger.js +25 -0
  5. package/dist/__tests__/lib/logger.js.map +1 -0
  6. package/dist/access-points/access-points-updater.d.ts +19 -0
  7. package/dist/access-points/access-points-updater.d.ts.map +1 -0
  8. package/dist/access-points/access-points-updater.js +141 -0
  9. package/dist/access-points/access-points-updater.js.map +1 -0
  10. package/dist/access-points/access-points-utils.d.ts +4 -0
  11. package/dist/access-points/access-points-utils.d.ts.map +1 -0
  12. package/dist/access-points/access-points-utils.js +27 -0
  13. package/dist/access-points/access-points-utils.js.map +1 -0
  14. package/dist/access-points/access-points.d.ts +20 -0
  15. package/dist/access-points/access-points.d.ts.map +1 -0
  16. package/dist/access-points/access-points.js +166 -0
  17. package/dist/access-points/access-points.js.map +1 -0
  18. package/dist/constants.d.ts +7 -0
  19. package/dist/constants.d.ts.map +1 -0
  20. package/dist/constants.js +7 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/consul-client/endpoints/agent.d.ts +31 -0
  23. package/dist/consul-client/endpoints/agent.d.ts.map +1 -0
  24. package/dist/consul-client/endpoints/agent.js +87 -0
  25. package/dist/consul-client/endpoints/agent.js.map +1 -0
  26. package/dist/consul-client/endpoints/catalog.d.ts +11 -0
  27. package/dist/consul-client/endpoints/catalog.d.ts.map +1 -0
  28. package/dist/consul-client/endpoints/catalog.js +14 -0
  29. package/dist/consul-client/endpoints/catalog.js.map +1 -0
  30. package/dist/consul-client/endpoints/health.d.ts +18 -0
  31. package/dist/consul-client/endpoints/health.d.ts.map +1 -0
  32. package/dist/consul-client/endpoints/health.js +28 -0
  33. package/dist/consul-client/endpoints/health.js.map +1 -0
  34. package/dist/consul-client/http-client.d.ts +26 -0
  35. package/dist/consul-client/http-client.d.ts.map +1 -0
  36. package/dist/consul-client/http-client.js +139 -0
  37. package/dist/consul-client/http-client.js.map +1 -0
  38. package/dist/consul-client/index.d.ts +16 -0
  39. package/dist/consul-client/index.d.ts.map +1 -0
  40. package/dist/consul-client/index.js +25 -0
  41. package/dist/consul-client/index.js.map +1 -0
  42. package/dist/consul-client/types.d.ts +126 -0
  43. package/dist/consul-client/types.d.ts.map +1 -0
  44. package/dist/consul-client/types.js +2 -0
  45. package/dist/consul-client/types.js.map +1 -0
  46. package/dist/cyclic-register.d.ts +3 -0
  47. package/dist/cyclic-register.d.ts.map +1 -0
  48. package/dist/cyclic-register.js +75 -0
  49. package/dist/cyclic-register.js.map +1 -0
  50. package/dist/get-api.d.ts +5 -0
  51. package/dist/get-api.d.ts.map +1 -0
  52. package/dist/get-api.js +51 -0
  53. package/dist/get-api.js.map +1 -0
  54. package/dist/get-register-config.d.ts +4 -0
  55. package/dist/get-register-config.d.ts.map +1 -0
  56. package/dist/get-register-config.js +94 -0
  57. package/dist/get-register-config.js.map +1 -0
  58. package/dist/index.d.ts +12 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +11 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/interfaces.d.ts +251 -0
  63. package/dist/interfaces.d.ts.map +1 -0
  64. package/dist/interfaces.js +2 -0
  65. package/dist/interfaces.js.map +1 -0
  66. package/dist/lib/color.d.ts +40 -0
  67. package/dist/lib/color.d.ts.map +1 -0
  68. package/dist/lib/color.js +41 -0
  69. package/dist/lib/color.js.map +1 -0
  70. package/dist/lib/curl-text.d.ts +3 -0
  71. package/dist/lib/curl-text.d.ts.map +1 -0
  72. package/dist/lib/curl-text.js +73 -0
  73. package/dist/lib/curl-text.js.map +1 -0
  74. package/dist/lib/fqdn.d.ts +3 -0
  75. package/dist/lib/fqdn.d.ts.map +1 -0
  76. package/dist/lib/fqdn.js +40 -0
  77. package/dist/lib/fqdn.js.map +1 -0
  78. package/dist/lib/hash.d.ts +3 -0
  79. package/dist/lib/hash.d.ts.map +1 -0
  80. package/dist/lib/hash.js +64 -0
  81. package/dist/lib/hash.js.map +1 -0
  82. package/dist/lib/http-request-text.d.ts +4 -0
  83. package/dist/lib/http-request-text.d.ts.map +1 -0
  84. package/dist/lib/http-request-text.js +21 -0
  85. package/dist/lib/http-request-text.js.map +1 -0
  86. package/dist/lib/logger-stub.d.ts +9 -0
  87. package/dist/lib/logger-stub.d.ts.map +1 -0
  88. package/dist/lib/logger-stub.js +10 -0
  89. package/dist/lib/logger-stub.js.map +1 -0
  90. package/dist/lib/utils.d.ts +17 -0
  91. package/dist/lib/utils.d.ts.map +1 -0
  92. package/dist/lib/utils.js +164 -0
  93. package/dist/lib/utils.js.map +1 -0
  94. package/dist/prepare-consul-api.d.ts +4 -0
  95. package/dist/prepare-consul-api.d.ts.map +1 -0
  96. package/dist/prepare-consul-api.js +380 -0
  97. package/dist/prepare-consul-api.js.map +1 -0
  98. package/dist/src/get-register-config.d.ts +4 -0
  99. package/dist/src/get-register-config.d.ts.map +1 -0
  100. package/dist/src/get-register-config.js +94 -0
  101. package/dist/src/get-register-config.js.map +1 -0
  102. package/package.json +65 -0
  103. package/src/access-points/access-points-updater.ts +154 -0
  104. package/src/access-points/access-points-utils.ts +31 -0
  105. package/src/access-points/access-points.ts +185 -0
  106. package/src/constants.ts +7 -0
  107. package/src/consul-client/endpoints/agent.ts +91 -0
  108. package/src/consul-client/endpoints/catalog.ts +13 -0
  109. package/src/consul-client/endpoints/health.ts +31 -0
  110. package/src/consul-client/http-client.ts +166 -0
  111. package/src/consul-client/index.ts +31 -0
  112. package/src/consul-client/types.ts +134 -0
  113. package/src/cyclic-register.ts +94 -0
  114. package/src/get-api.ts +62 -0
  115. package/src/get-register-config.ts +102 -0
  116. package/src/index.ts +58 -0
  117. package/src/interfaces.ts +276 -0
  118. package/src/lib/color.ts +43 -0
  119. package/src/lib/curl-text.ts +91 -0
  120. package/src/lib/fqdn.ts +45 -0
  121. package/src/lib/hash.ts +56 -0
  122. package/src/lib/http-request-text.ts +24 -0
  123. package/src/lib/logger-stub.ts +11 -0
  124. package/src/lib/utils.ts +174 -0
  125. package/src/prepare-consul-api.ts +426 -0
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ ## Not of interest to third party users
2
+
3
+ #### Example of settings for registering a service
4
+
5
+ ```js
6
+ const registerOptions = {
7
+ name: 'service name', // (String): service name
8
+ id: 'service ID', // (String, optional): service ID
9
+ tags: ['tag1'], // (String[], optional): service tags
10
+ address: '0.0.0.0', // (String, optional): service IP address
11
+ port: 9602, // (Integer, optional): service port
12
+ meta: {}, // (Object, optional): metadata linked to the service instance
13
+ check: { // (Object, optional): service check
14
+ http: '', // (String): URL endpoint, requires interval
15
+ tcp: '', // (String): host:port to test, passes if connection is established, fails otherwise
16
+ script: '', // (String): path to check script, requires interval
17
+ dockercontainerid: '', // (String, optional): Docker container ID to run script
18
+ shell: '', // (String, optional): shell in which to run script (currently only supported with Docker)
19
+ interval: '', // (String): interval to run check, requires script (ex: 15s)
20
+ timeout: '', // (String, optional): timeout for the check (ex: 10s)
21
+ ttl: '', // (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: 60s)
22
+ notes: '', // (String, optional): human readable description of check
23
+ status: '', // (String, optional): initial service status
24
+ deregistercriticalserviceafter: '' // (String, optional, Consul 0.7+): timeout after which to automatically deregister service if check remains in critical state
25
+ },
26
+ checks: [{}], // (Object[], optional): service checks (see check above)
27
+ connect: {}, // (Object, optional): specifies the configuration for Connect
28
+ proxy: {}, // (Object, optional): specifies the configuration for a Connect proxy instance
29
+ taggedAddresses: {} // (Object, optional): specifies a map of explicit LAN and WAN addresses for the service instance
30
+ };
31
+
32
+
33
+ ```
34
+
35
+ #### Usage example
36
+
37
+ ```ts
38
+ import 'dotenv/config';
39
+ import os from 'os';
40
+ import { logger } from './logger';
41
+ import { getAPI } from '../src';
42
+
43
+ const e = process.env;
44
+ const config = {
45
+ consul: {
46
+ check: {
47
+ interval: e.CONSUL_HEALTH_CHECK_INTERVAL || '1s',
48
+ timeout: e.CONSUL_HEALTH_CHECK_TMEOUT || '1s',
49
+ deregistercriticalserviceafter: e.CONSUL_DEREGISTER_CRITICAL_SERVICE_AFTER || '1m',
50
+ },
51
+ agent: {
52
+ reg: {
53
+ host: e.CONSUL_AGENT_HOST || thisHostName,
54
+ port: e.CONSUL_AGENT_PORT || '8500',
55
+ secure: e.CONSUL_AGENT_SECURE,
56
+ token: e.CONSUL_AGENT_TOKEN,
57
+ },
58
+ dev: {
59
+ dc: e.CONSUL_AGENT_DEV_DC || 'dc-dev',
60
+ host: e.CONSUL_AGENT_DEV_HOST || thisHostName,
61
+ port: e.CONSUL_AGENT_DEV_PORT || '8500',
62
+ secure: e.CONSUL_AGENT_DEV_SECURE,
63
+ token: e.CONSUL_AGENT_DEV_TOKEN,
64
+ },
65
+ prd: {
66
+ dc: e.CONSUL_AGENT_PRD_DC || 'dc-prd',
67
+ host: e.CONSUL_AGENT_PRD_HOST || thisHostName,
68
+ port: e.CONSUL_AGENT_PRD_PORT || '8500',
69
+ secure: e.CONSUL_AGENT_PRD_SECURE,
70
+ token: e.CONSUL_AGENT_PRD_TOKEN,
71
+ },
72
+ },
73
+ // Details of the service being registered with consul
74
+ service: {
75
+ name: e.CONSUL_SERVICE_NAME || 'fa-consul',
76
+ instance: e.CONSUL_SERVICE_INSTANCE || 'test',
77
+ version: e.CONSUL_SERVICE_VERSION || '0.0.1',
78
+ description: e.CONSUL_SERVICE_DESCRIPTION || 'AF-CONSUL TEST',
79
+ tags: e.CONSUL_SERVICE_TAGS || ['af', 'consul', 'test'],
80
+ meta: e.CONSUL_SERVICE_META || { CONSUL_TEST: 12345, line_yellow: 'straight' },
81
+ host: e.CONSUL_SERVICE_HOST || null,
82
+ port: e.CONSUL_SERVICE_PORT || null,
83
+ },
84
+ },
85
+ webServer: {
86
+ host: e.WS_HOST || '0.0.0.0',
87
+ port: e.WS_PORT || '10000',
88
+ },
89
+ }
90
+ ```
91
+
92
+ ## Идентификаторы отладки
93
+
94
+ AP-UPDATER - access-points-updater:
95
+ - Polling ${CONSUL_ID}
96
+ - The data is up-to-date ${CONSUL_ID}
97
+
98
+ af-consul
99
+ `${yellow} REGISTER CONFIG:\n${JSON.stringify(registerConfig, undefined, 2)}\n${reset}`
100
+ `CONSUL AGENT OPTIONS:\n${JSON.stringify(fullConsulAgentOptions, undefined, 2)}`
101
+ `${rqId}HTTP Status: ${statusCode}`
102
+ `${rqId}res.body not found! res: ${res}`
103
+ `No info about service ID ${cyan}${serviceName}`
104
+ `${prefixG} Skip registration check after health check`
105
+
106
+ af-consul:curl
107
+ const msg = dbg.curl ? getCurl(request, true) : getHttpRequestText(request);
108
+ `[${request._id_}] ${yellow}${msg}${reset}`
109
+
110
+ af-consul:reg
111
+ `${PREFIX}: updated ${updatedCount.length} access point(s)`
112
+ `${prefixG} Service ${cyan}${registerConfig.id}${reset} registration check...`
@@ -0,0 +1,3 @@
1
+ declare const logger: import("af-logger").LoggerEx;
2
+ export { logger };
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../__tests__/lib/logger.ts"],"names":[],"mappings":"AA0BA,QAAA,MAAQ,MAAM,8BAAgC,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { getAFLogger } from 'af-logger';
2
+ const minLevel = 'silly';
3
+ const prefix = 'fa-consul';
4
+ const logDir = './_log';
5
+ const loggerSettings = {
6
+ minLevel,
7
+ name: prefix,
8
+ filePrefix: prefix,
9
+ logDir,
10
+ minLogSize: 0,
11
+ minErrorLogSize: 0,
12
+ // displayLoggerName: true,
13
+ // displayFunctionName: true,
14
+ // displayFilePath: 'displayAll',
15
+ // emitter: em,
16
+ fileLoggerMap: {
17
+ silly: 'info',
18
+ info: 'info',
19
+ error: 'error',
20
+ fatal: 'error',
21
+ },
22
+ };
23
+ const { logger } = getAFLogger(loggerSettings);
24
+ export { logger };
25
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../__tests__/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,MAAM,QAAQ,GAAG,OAAO,CAAC;AACzB,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,MAAM,MAAM,GAAG,QAAQ,CAAC;AAExB,MAAM,cAAc,GAAoB;IACtC,QAAQ;IACR,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,MAAM;IAClB,MAAM;IACN,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,CAAC;IAClB,2BAA2B;IAC3B,6BAA6B;IAC7B,iCAAiC;IACjC,eAAe;IACf,aAAa,EAAE;QACb,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { IAccessPoint, ICLOptions } from '../interfaces';
2
+ export declare function updateAccessPoint(clOptions: ICLOptions, accessPoint: IAccessPoint): Promise<-2 | -1 | 0 | 1>;
3
+ export declare function updateAccessPoints(clOptions: ICLOptions): Promise<boolean>;
4
+ export declare const accessPointsUpdater: {
5
+ isStarted: boolean;
6
+ isAnyUpdated: boolean;
7
+ _timerId: NodeJS.Timeout;
8
+ _logger: {
9
+ silly: (message?: any, ...optionalParams: any[]) => void;
10
+ debug: (message?: any, ...optionalParams: any[]) => void;
11
+ info: (message?: any, ...optionalParams: any[]) => void;
12
+ warn: (message?: any, ...optionalParams: any[]) => void;
13
+ error: (message?: any, ...optionalParams: any[]) => void;
14
+ };
15
+ start(clOptions: ICLOptions, updateInterval?: number): number;
16
+ waitForAnyUpdated(timeout?: number): Promise<boolean>;
17
+ stop(): void;
18
+ };
19
+ //# sourceMappingURL=access-points-updater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points-updater.d.ts","sourceRoot":"","sources":["../../src/access-points/access-points-updater.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,YAAY,EAEZ,UAAU,EAGX,MAAM,eAAe,CAAC;AAyBvB,wBAAsB,iBAAiB,CAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CA0DnH;AAED,wBAAsB,kBAAkB,CAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAejF;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;qBAKZ,UAAU,mBAAkB,MAAM,GAAY,MAAM;gCAuBpC,MAAM,GAAqC,OAAO,CAAC,OAAO,CAAC;;CAY9F,CAAC"}
@@ -0,0 +1,141 @@
1
+ /* eslint-disable no-console */
2
+ // noinspection JSUnusedGlobalSymbols
3
+ import { DEBUG, CONSUL_AP_UPDATE_TIMEOUT_MILLIS } from '../constants';
4
+ import { getConsulApiCached } from '../index';
5
+ import { cyan, green, magenta, red, reset } from '../lib/color';
6
+ import loggerStub from '../lib/logger-stub';
7
+ import { sleep } from '../lib/utils';
8
+ const PREFIX = 'AP-UPDATER';
9
+ const dbg = { on: /\bAP-UPDATER\*?/i.test(DEBUG) || DEBUG === '*' };
10
+ const debug = (msg) => {
11
+ if (dbg.on) {
12
+ console.log(`${magenta}${PREFIX}${reset}: ${msg}`);
13
+ }
14
+ };
15
+ const UPDATE_INTERVAL_IF_CONSUL_REGISTER_SUCCESS_MILLIS = Number(process.env.UPDATE_INTERVAL_IF_CONSUL_REGISTER_SUCCESS_MILLIS) || (2 * 60_000);
16
+ // A stub in case such a function is not set for the access point in the configuration
17
+ function retrieveProps(accessPoint, host, meta) {
18
+ const port = Number(meta?.port) || accessPoint.port;
19
+ return { host, port };
20
+ }
21
+ // Служит для исключения повторного опроса consulID в пределах одного цикла updateAccessPoints
22
+ let oneUpdateCache = {};
23
+ export async function updateAccessPoint(clOptions, accessPoint) {
24
+ if (!accessPoint.updateIntervalIfSuccessMillis) {
25
+ accessPoint.updateIntervalIfSuccessMillis = UPDATE_INTERVAL_IF_CONSUL_REGISTER_SUCCESS_MILLIS;
26
+ }
27
+ if (Date.now() - (accessPoint.lastSuccessUpdate || 0) < accessPoint.updateIntervalIfSuccessMillis) {
28
+ return 0;
29
+ }
30
+ const { consulServiceName } = accessPoint;
31
+ const CONSUL_ID = `${cyan}${consulServiceName}${reset}`;
32
+ let result = oneUpdateCache[consulServiceName];
33
+ if (result) {
34
+ if (result.length) {
35
+ // Точка доступа уже опрошена в этом цикле и она была недоступна
36
+ return 0;
37
+ }
38
+ // Точка доступа еще опрошена в этом цикле и есть сведения по ней. В этом просе будут взяты другие метаданные, нежели в предыдущем updateAccessPoint
39
+ }
40
+ else {
41
+ // Точка доступа еще не опрошена в этом цикле
42
+ const consulApi = await getConsulApiCached(clOptions);
43
+ if (!consulApi) {
44
+ clOptions.logger?.warn(`${PREFIX}: Failed to get consul API`);
45
+ return -2;
46
+ }
47
+ debug(`${reset}Polling ${CONSUL_ID}`);
48
+ result = await consulApi.consulHealthService({ options: { service: consulServiceName, passing: true } });
49
+ oneUpdateCache[consulServiceName] = result;
50
+ }
51
+ const { Address: host, Meta: meta } = result?.[0]?.Service || {};
52
+ if (!host) {
53
+ clOptions.logger?.warn(`${red}There is no information for ${CONSUL_ID}`);
54
+ accessPoint.lastSuccessUpdate = 0;
55
+ const wasReachable = accessPoint.isReachable;
56
+ accessPoint.isReachable = false;
57
+ if (wasReachable) {
58
+ clOptions.em?.emit('access-point-updated', { accessPoint, changes: [['isReachable', true, false]] });
59
+ }
60
+ return -1;
61
+ }
62
+ accessPoint.isReachable = true;
63
+ accessPoint.lastSuccessUpdate = Date.now();
64
+ // If the retrieveProps function is not set for the access point in the configuration, use the stub
65
+ if (typeof accessPoint.retrieveProps !== 'function') {
66
+ accessPoint.retrieveProps = retrieveProps.bind(null, accessPoint);
67
+ }
68
+ const properties = accessPoint.retrieveProps(host, meta);
69
+ const changes = accessPoint.setProps?.(properties)?.getChanges?.();
70
+ if (changes?.length) {
71
+ if (meta) {
72
+ accessPoint.meta = meta;
73
+ }
74
+ clOptions.em?.emit('access-point-updated', { accessPoint, changes });
75
+ }
76
+ else {
77
+ debug(`${green}The data is up-to-date ${CONSUL_ID}`);
78
+ }
79
+ return 1;
80
+ }
81
+ export async function updateAccessPoints(clOptions) {
82
+ const accessPoints = Object.values(clOptions.config.accessPoints).filter((ap) => ap?.isAP && !ap.noConsul);
83
+ const result = [];
84
+ for (let i = 0; i < accessPoints.length; i++) {
85
+ const accessPoint = accessPoints[i];
86
+ if (!accessPoint) {
87
+ continue;
88
+ }
89
+ const res = await updateAccessPoint(clOptions, accessPoint);
90
+ result.push(res);
91
+ }
92
+ const updatedCount = result.filter((v) => v > 0);
93
+ if (updatedCount.length) {
94
+ clOptions.logger?.silly(`${PREFIX}: updated ${updatedCount.length} access point(s)`);
95
+ clOptions.em?.emit('access-points-updated');
96
+ }
97
+ return !!updatedCount;
98
+ }
99
+ export const accessPointsUpdater = {
100
+ isStarted: false,
101
+ isAnyUpdated: false,
102
+ _timerId: setTimeout(() => null, 0),
103
+ _logger: loggerStub,
104
+ start(clOptions, updateInterval = 10_000) {
105
+ if (this.isStarted) {
106
+ return 0;
107
+ }
108
+ this._logger = clOptions.logger || loggerStub;
109
+ const doLoop = async () => {
110
+ try {
111
+ oneUpdateCache = {};
112
+ const isAnyUpdated = await updateAccessPoints(clOptions);
113
+ if (isAnyUpdated) {
114
+ this.isAnyUpdated = true;
115
+ }
116
+ }
117
+ catch (err) {
118
+ this._logger?.error(err);
119
+ }
120
+ clearTimeout(this._timerId);
121
+ this._timerId = setTimeout(doLoop, updateInterval);
122
+ };
123
+ doLoop().then((r) => r);
124
+ this.isStarted = true;
125
+ this._logger.info('Access point updater started');
126
+ return 1;
127
+ },
128
+ async waitForAnyUpdated(timeout = CONSUL_AP_UPDATE_TIMEOUT_MILLIS) {
129
+ const start = Date.now();
130
+ while (!this.isAnyUpdated && (Date.now() - start < timeout)) {
131
+ await sleep(100);
132
+ }
133
+ return this.isAnyUpdated;
134
+ },
135
+ stop() {
136
+ clearTimeout(this._timerId);
137
+ this.isStarted = false;
138
+ this._logger.info('Access point updater stopped');
139
+ },
140
+ };
141
+ //# sourceMappingURL=access-points-updater.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points-updater.js","sourceRoot":"","sources":["../../src/access-points/access-points-updater.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,qCAAqC;AAErC,OAAO,EAAE,KAAK,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAQ9C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,MAAM,MAAM,GAAG,YAAY,CAAC;AAE5B,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;AACpE,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5B,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,KAAK,GAAG,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,iDAAiD,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,i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,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAClD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,KAAK,CAAC,iBAAiB,CAAE,UAAkB,+BAA+B;QACxE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC;YAC5D,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,IAAI;QACF,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IACpD,CAAC;CACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { AccessPoints } from './access-points';
2
+ export declare const isHttpAvailable: (url: string) => Promise<unknown>;
3
+ export declare const checkAccessPointAvailability: (accessPoints: AccessPoints, accessPointId: string, onError: (errorMessage: string) => false) => Promise<boolean>;
4
+ //# sourceMappingURL=access-points-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points-utils.d.ts","sourceRoot":"","sources":["../../src/access-points/access-points-utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,qBAGzC,CAAC;AAEH,eAAO,MAAM,4BAA4B,GAAU,cAAc,YAAY,EAAE,eAAe,MAAM,EAAE,SAAS,CAAC,YAAY,EAAE,MAAM,KAAK,KAAK,qBAkB7I,CAAC"}
@@ -0,0 +1,27 @@
1
+ import * as http from 'http';
2
+ import * as https from 'https';
3
+ import { CONSUL_AP_UPDATE_TIMEOUT_MILLIS } from '../constants';
4
+ export const isHttpAvailable = (url) => new Promise((resolve) => {
5
+ const client = /^https:/i.test(url) ? https : http;
6
+ client.request(url, (r) => resolve(r.statusCode > 0)).on('error', () => resolve(false)).end();
7
+ });
8
+ export const checkAccessPointAvailability = async (accessPoints, accessPointId, onError) => {
9
+ const it = `Access point "${accessPointId}"`;
10
+ const ap = accessPoints.getAP(accessPointId);
11
+ if (!ap) {
12
+ return onError(`${it} is not found`);
13
+ }
14
+ if (!ap.waitForHostPortUpdated) {
15
+ return onError(`${it} has no method "waitForHostPortUpdated"`);
16
+ }
17
+ if (!(await ap.waitForHostPortUpdated(CONSUL_AP_UPDATE_TIMEOUT_MILLIS))) {
18
+ return onError(`${it} update timed out`);
19
+ }
20
+ const { host, port, protocol = 'http', path = '' } = ap;
21
+ const url = `${protocol}://${host}:${port}${path}`;
22
+ if (!(await isHttpAvailable(url))) {
23
+ return onError(`${it} is not available`);
24
+ }
25
+ return true;
26
+ };
27
+ //# sourceMappingURL=access-points-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points-utils.js","sourceRoot":"","sources":["../../src/access-points/access-points-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAI/D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtE,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AACrG,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,EAAE,YAA0B,EAAE,aAAqB,EAAE,OAAwC,EAAE,EAAE;IAChJ,MAAM,EAAE,GAAG,iBAAiB,aAAa,GAAG,CAAC;IAC7C,MAAM,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC7C,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACvC,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC,GAAG,EAAE,yCAAyC,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,sBAAsB,CAAC,+BAA+B,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,GAAG,QAAQ,MAAM,IAAI,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;IACnD,IAAI,CAAC,CAAC,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { IAccessPoint, IAccessPoints, ILogger } from '../interfaces';
2
+ declare const _logger_: unique symbol;
3
+ export declare class AccessPoints {
4
+ private readonly [_logger_];
5
+ constructor(accessPoints: IAccessPoints, logger?: ILogger);
6
+ static normalizePort(port: unknown): number | null;
7
+ static normalizeProtocol(protocol: string | null): string;
8
+ static normalizeValue(propName: string, propValue: any): any;
9
+ static getPureProps(accessPointSource: Record<string, any>): IAccessPoint;
10
+ addAP(apKey: string, apData: any): IAccessPoint | undefined;
11
+ setAP(apKey: string, apData: Record<string, any> | null): IAccessPoint | undefined;
12
+ getAP(accessPointKey: string, andNotIsAP?: boolean): IAccessPoint | undefined;
13
+ /**
14
+ * Если передан accessPointKey, то возвращается этот AP, если есть.
15
+ * Если accessPointKey НЕ передан, то возвращаются ВСЕ AP
16
+ */
17
+ get(accessPointKey?: string, andNotIsAP?: boolean): IAccessPoints | IAccessPoint | undefined;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=access-points.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points.d.ts","sourceRoot":"","sources":["../../src/access-points/access-points.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAOrE,QAAA,MAAM,QAAQ,eAAyB,CAAC;AAkBxC,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAU;gBAExB,YAAY,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,OAAO;IAY1D,MAAM,CAAC,aAAa,CAAE,IAAI,EAAE,OAAO;IAInC,MAAM,CAAC,iBAAiB,CAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAOjD,MAAM,CAAC,cAAc,CAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG;IAWvD,MAAM,CAAC,YAAY,CAAE,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY;IAe1E,KAAK,CAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,YAAY,GAAG,SAAS;IA4B5D,KAAK,CAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,YAAY,GAAG,SAAS;IA+CnF,KAAK,CAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS;IAY9E;;;OAGG;IACH,GAAG,CAAE,cAAc,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS;CAe9F"}
@@ -0,0 +1,166 @@
1
+ import { CONSUL_AP_UPDATE_TIMEOUT_MILLIS } from '../constants';
2
+ import { blue, cyan, green, magenta, reset } from '../lib/color';
3
+ import loggerStub from '../lib/logger-stub';
4
+ import { isObject, sleep } from '../lib/utils';
5
+ const PREFIX = 'ACCESS-POINT';
6
+ const _logger_ = Symbol.for('_logger_');
7
+ const addAdditionalAPProps = (accessPoint) => {
8
+ if (accessPoint.noConsul) {
9
+ return;
10
+ }
11
+ Object.defineProperty(accessPoint, 'isAP', { value: true });
12
+ Object.defineProperty(accessPoint, 'lastSuccessUpdate', { value: 0, writable: true });
13
+ Object.defineProperty(accessPoint, 'idHostPortUpdated', { value: false, writable: true });
14
+ accessPoint.waitForHostPortUpdated = async (timeout = CONSUL_AP_UPDATE_TIMEOUT_MILLIS) => {
15
+ const start = Date.now();
16
+ while (!accessPoint.idHostPortUpdated && (Date.now() - start < timeout)) {
17
+ await sleep(100);
18
+ }
19
+ return !!accessPoint.idHostPortUpdated;
20
+ };
21
+ };
22
+ export class AccessPoints {
23
+ [_logger_];
24
+ constructor(accessPoints, logger) {
25
+ this[_logger_] = logger || loggerStub;
26
+ if (!accessPoints) {
27
+ const msg = 'Empty argument "accessPoints" passed to constructor';
28
+ this[_logger_].error(msg);
29
+ throw new Error(msg);
30
+ }
31
+ Object.entries(accessPoints).forEach(([apKey, apData]) => {
32
+ this.addAP(apKey, apData);
33
+ });
34
+ }
35
+ static normalizePort(port) {
36
+ return Number(port) || null;
37
+ }
38
+ static normalizeProtocol(protocol) {
39
+ if (!protocol || !/^https?$/i.test(protocol)) {
40
+ protocol = 'http';
41
+ }
42
+ return protocol?.toLowerCase();
43
+ }
44
+ static normalizeValue(propName, propValue) {
45
+ switch (propName) {
46
+ case 'port':
47
+ return AccessPoints.normalizePort(propValue);
48
+ case 'protocol':
49
+ return AccessPoints.normalizeProtocol(propValue);
50
+ default:
51
+ return propValue;
52
+ }
53
+ }
54
+ static getPureProps(accessPointSource) {
55
+ const accessPoint = Object.create(null);
56
+ Object.entries(accessPointSource).forEach(([propName, propValue]) => {
57
+ if (propValue === undefined || typeof propValue === 'function') {
58
+ return;
59
+ }
60
+ if (typeof propValue === 'object' && propValue !== null) {
61
+ accessPoint[propName] = { ...propValue };
62
+ return;
63
+ }
64
+ accessPoint[propName] = propValue;
65
+ });
66
+ return accessPoint;
67
+ }
68
+ addAP(apKey, apData) {
69
+ if (!apData || !isObject(apData)) {
70
+ return undefined;
71
+ }
72
+ if (apData.noConsul) {
73
+ // @ts-ignore
74
+ this[apKey] = apData;
75
+ return AccessPoints.getPureProps(apData);
76
+ }
77
+ if (!apData.consulServiceName) {
78
+ this[_logger_].error(`"${apKey}" access point not added because it lacks "consulServiceName" property`);
79
+ return undefined;
80
+ }
81
+ const accessPoint = {};
82
+ addAdditionalAPProps(accessPoint);
83
+ // @ts-ignore
84
+ this[apKey] = accessPoint;
85
+ Object.entries(apData).forEach(([propName, v]) => {
86
+ accessPoint[propName] = AccessPoints.normalizeValue(propName, v);
87
+ });
88
+ accessPoint.id = apKey;
89
+ accessPoint.title = accessPoint.title || apKey;
90
+ accessPoint.setProps = this.setAP.bind(this, apKey);
91
+ return AccessPoints.getPureProps(accessPoint);
92
+ }
93
+ setAP(apKey, apData) {
94
+ if (!apData) {
95
+ return undefined;
96
+ }
97
+ // @ts-ignore
98
+ const accessPoint = this[apKey];
99
+ if (!accessPoint) {
100
+ return this.addAP(apKey, apData);
101
+ }
102
+ /* istanbul ignore if */
103
+ if (!accessPoint.isAP) {
104
+ addAdditionalAPProps(accessPoint);
105
+ }
106
+ const was = [];
107
+ const became = [];
108
+ const changes = [];
109
+ const msgVal = (propName, propValue, valueColor) => {
110
+ const ret = (v, color = blue) => `${cyan}${propName}${reset}: ${color}${v}${reset}`;
111
+ return (propValue == null || propValue === '') ? ret(`[${String(propValue)}]`) : ret(propValue, valueColor);
112
+ };
113
+ Object.entries(apData).forEach(([propName, newV]) => {
114
+ if (newV === undefined) {
115
+ return;
116
+ }
117
+ const oldV = accessPoint[propName];
118
+ newV = AccessPoints.normalizeValue(propName, newV);
119
+ if (oldV !== newV) {
120
+ was.push(msgVal(propName, oldV, magenta));
121
+ became.push(msgVal(propName, newV, green));
122
+ changes.push([propName, oldV, newV]);
123
+ }
124
+ accessPoint[propName] = newV;
125
+ });
126
+ if (was.length) {
127
+ this[_logger_].info(`${PREFIX}: Change AP ${green}${accessPoint.id}${reset}/${cyan}${accessPoint.consulServiceName}${reset} from ${was.join('; ')} to ${became.join('; ')}`);
128
+ }
129
+ accessPoint.idHostPortUpdated = accessPoint.idHostPortUpdated
130
+ || !!(accessPoint.host && accessPoint.port && (apData.host || apData.port));
131
+ const result = AccessPoints.getPureProps(accessPoint);
132
+ result.getChanges = () => (changes.length ? changes : undefined);
133
+ return result;
134
+ }
135
+ getAP(accessPointKey, andNotIsAP) {
136
+ if (accessPointKey) {
137
+ // @ts-ignore
138
+ const accessPoint = this[accessPointKey];
139
+ if (!andNotIsAP && !accessPoint?.isAP) {
140
+ return undefined;
141
+ }
142
+ return accessPoint;
143
+ }
144
+ return undefined;
145
+ }
146
+ /**
147
+ * Если передан accessPointKey, то возвращается этот AP, если есть.
148
+ * Если accessPointKey НЕ передан, то возвращаются ВСЕ AP
149
+ */
150
+ get(accessPointKey, andNotIsAP) {
151
+ if (accessPointKey) {
152
+ // @ts-ignore
153
+ const accessPoint = this[accessPointKey];
154
+ if (!accessPoint || (!andNotIsAP && !accessPoint?.isAP)) {
155
+ return undefined;
156
+ }
157
+ return AccessPoints.getPureProps(accessPoint);
158
+ }
159
+ const accessPoints = Object.create(null);
160
+ Object.values(this).filter((ap) => ap?.isAP).forEach((accessPoint) => {
161
+ accessPoints[accessPoint.id] = AccessPoints.getPureProps(accessPoint);
162
+ });
163
+ return accessPoints;
164
+ }
165
+ }
166
+ //# sourceMappingURL=access-points.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-points.js","sourceRoot":"","sources":["../../src/access-points/access-points.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,GAAG,cAAc,CAAC;AAE9B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAExC,MAAM,oBAAoB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAChE,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACtF,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1F,WAAW,CAAC,sBAAsB,GAAG,KAAK,EAAE,UAAkB,+BAA+B,EAAoB,EAAE;QACjH,MAAM,KA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,OAAO,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAkB,CAAC;QAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;YACnE,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QACH,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export declare const PREFIX = "AF-CONSUL";
2
+ export declare const MAX_API_CACHED = 3;
3
+ export declare const CONSUL_AP_UPDATE_TIMEOUT_MILLIS: number;
4
+ export declare const DEBUG: string;
5
+ export declare const CONSUL_DEBUG_ON: boolean;
6
+ export declare const FORCE_EVERY_REGISTER_ATTEMPT: boolean;
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,eAAO,MAAM,+BAA+B,QAAgE,CAAC;AAC7G,eAAO,MAAM,KAAK,QAA2C,CAAC;AAC9D,eAAO,MAAM,eAAe,SAAqE,CAAC;AAClG,eAAO,MAAM,4BAA4B,SAA6C,CAAC"}
@@ -0,0 +1,7 @@
1
+ export const PREFIX = 'AF-CONSUL';
2
+ export const MAX_API_CACHED = 3;
3
+ export const CONSUL_AP_UPDATE_TIMEOUT_MILLIS = Number(process.env.CONSUL_AP_UPDATE_TIMEOUT_MILLIS) || 10_000;
4
+ export const DEBUG = (String(process.env.DEBUG || '')).trim();
5
+ export const CONSUL_DEBUG_ON = DEBUG.split(/[ ,]/).some((v) => /af-consul/i.test(v) || v === '*');
6
+ export const FORCE_EVERY_REGISTER_ATTEMPT = !!process.env.FORCE_EVERY_REGISTER_ATTEMPT;
7
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,WAAW,CAAC;AAClC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,IAAI,MAAM,CAAC;AAC7G,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { ConsulHttpClient } from '../http-client';
2
+ import { ServiceInfo, RegisterServiceOptions, AgentMember } from '../types';
3
+ export declare class AgentAPI {
4
+ private client;
5
+ constructor(client: ConsulHttpClient);
6
+ /**
7
+ * GET /v1/agent/services
8
+ * Returns all services registered with the local agent
9
+ */
10
+ serviceList(): Promise<Record<string, ServiceInfo>>;
11
+ /**
12
+ * PUT /v1/agent/service/register
13
+ * Registers a new service with the local agent
14
+ */
15
+ serviceRegister(options: RegisterServiceOptions): Promise<void>;
16
+ /**
17
+ * PUT /v1/agent/service/deregister/:service_id
18
+ * Deregisters a service from the local agent
19
+ */
20
+ serviceDeregister(serviceId: string): Promise<void>;
21
+ /**
22
+ * GET /v1/agent/members
23
+ * Returns the members the agent sees in the cluster
24
+ */
25
+ members(options?: {
26
+ wan?: boolean;
27
+ segment?: string;
28
+ }): Promise<AgentMember[]>;
29
+ private formatCheck;
30
+ }
31
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/consul-client/endpoints/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC;AAE3F,qBAAa,QAAQ;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,gBAAgB;IAE7C;;;OAGG;IACG,WAAW,IAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAI1D;;;OAGG;IACG,eAAe,CAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BtE;;;OAGG;IACG,iBAAiB,CAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1D;;;OAGG;IACG,OAAO,CAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAOrF,OAAO,CAAC,WAAW;CAyBpB"}