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
@@ -0,0 +1,31 @@
1
+ import { AgentAPI } from './endpoints/agent';
2
+ import { CatalogAPI } from './endpoints/catalog';
3
+ import { HealthAPI } from './endpoints/health';
4
+ import { ConsulHttpClient } from './http-client';
5
+ import { ConsulClientOptions, OnRequestHook, OnResponseHook } from './types';
6
+
7
+ export class ConsulClient {
8
+ private readonly httpClient: ConsulHttpClient;
9
+
10
+ public readonly agent: AgentAPI;
11
+ public readonly health: HealthAPI;
12
+ public readonly catalog: CatalogAPI;
13
+
14
+ constructor (options: ConsulClientOptions) {
15
+ this.httpClient = new ConsulHttpClient(options);
16
+ this.agent = new AgentAPI(this.httpClient);
17
+ this.health = new HealthAPI(this.httpClient);
18
+ this.catalog = new CatalogAPI(this.httpClient);
19
+ }
20
+
21
+ onRequest (hook: OnRequestHook): void {
22
+ this.httpClient.onRequest(hook);
23
+ }
24
+
25
+ onResponse (hook: OnResponseHook): void {
26
+ this.httpClient.onResponse(hook);
27
+ }
28
+ }
29
+
30
+ export * from './types';
31
+ export { ConsulHttpClient } from './http-client';
@@ -0,0 +1,134 @@
1
+ // ================== Connection Options ==================
2
+ export interface ConsulClientOptions {
3
+ host: string;
4
+ port: string | number;
5
+ secure?: boolean | undefined;
6
+ token?: string | undefined;
7
+ dc?: string | undefined;
8
+ timeout?: number | undefined;
9
+ defaults?: { token?: string | undefined } | undefined;
10
+ }
11
+
12
+ // ================== Register Service ==================
13
+ export interface RegisterCheck {
14
+ name?: string;
15
+ http?: string;
16
+ tcp?: string;
17
+ script?: string;
18
+ shell?: string;
19
+ dockercontainerid?: string;
20
+ interval?: string;
21
+ timeout?: string;
22
+ ttl?: string;
23
+ notes?: string;
24
+ status?: string;
25
+ deregistercriticalserviceafter?: string;
26
+ }
27
+
28
+ export interface RegisterServiceOptions {
29
+ id?: string;
30
+ name: string;
31
+ tags?: string[];
32
+ address?: string;
33
+ port?: number;
34
+ meta?: Record<string, string>;
35
+ check?: RegisterCheck;
36
+ checks?: RegisterCheck[];
37
+ connect?: Record<string, unknown>;
38
+ proxy?: Record<string, unknown>;
39
+ taggedAddresses?: Record<string, unknown>;
40
+ weights?: { passing?: number; warning?: number };
41
+ enableTagOverride?: boolean;
42
+ }
43
+
44
+ // ================== Service Info ==================
45
+ export interface ServiceInfo {
46
+ ID: string;
47
+ Service: string;
48
+ Tags?: string[];
49
+ Meta?: Record<string, string | null>;
50
+ Port: number;
51
+ Address: string;
52
+ Weights?: { Passing: number; Warning: number };
53
+ EnableTagOverride?: boolean;
54
+ Datacenter?: string;
55
+ Proxy?: Record<string, unknown>;
56
+ Connect?: Record<string, unknown>;
57
+ CreateIndex?: number;
58
+ ModifyIndex?: number;
59
+ }
60
+
61
+ // ================== Health Service ==================
62
+ export interface NodeInfo {
63
+ ID: string;
64
+ Node?: string;
65
+ Address: string;
66
+ Datacenter?: string;
67
+ TaggedAddresses?: Record<string, string>;
68
+ Meta?: Record<string, string>;
69
+ CreateIndex?: number;
70
+ ModifyIndex?: number;
71
+ }
72
+
73
+ export interface HealthCheck {
74
+ Node: string;
75
+ CheckID: string;
76
+ Name: string;
77
+ Status: 'passing' | 'warning' | 'critical';
78
+ Notes?: string;
79
+ Output?: string;
80
+ ServiceID?: string;
81
+ ServiceName?: string;
82
+ ServiceTags?: string[];
83
+ Type?: string;
84
+ Definition?: Record<string, unknown>;
85
+ CreateIndex?: number;
86
+ ModifyIndex?: number;
87
+ }
88
+
89
+ export interface HealthServiceInfo {
90
+ Node?: NodeInfo;
91
+ Service?: ServiceInfo;
92
+ Checks?: HealthCheck[];
93
+ }
94
+
95
+ // ================== Agent Members ==================
96
+ export interface AgentMember {
97
+ Name: string;
98
+ Addr: string;
99
+ Port: number;
100
+ Tags?: Record<string, string>;
101
+ Status: number;
102
+ ProtocolMin: number;
103
+ ProtocolMax: number;
104
+ ProtocolCur: number;
105
+ DelegateMin: number;
106
+ DelegateMax: number;
107
+ DelegateCur: number;
108
+ }
109
+
110
+ // ================== Request/Response Hooks ==================
111
+ export interface RequestInfo {
112
+ id: number;
113
+ method: string;
114
+ url: string;
115
+ headers: Record<string, string>;
116
+ body?: string | undefined;
117
+ timestamp: number;
118
+ // Properties for compatibility with existing debug utilities
119
+ path: string;
120
+ hostname: string;
121
+ port: string | number;
122
+ protocol: string;
123
+ query?: Record<string, string | boolean | undefined> | undefined;
124
+ }
125
+
126
+ export interface ResponseInfo {
127
+ requestId: number;
128
+ statusCode: number;
129
+ body?: unknown;
130
+ timestamp: number;
131
+ }
132
+
133
+ export type OnRequestHook = (request: RequestInfo) => void;
134
+ export type OnResponseHook = (request: RequestInfo, response: ResponseInfo) => void;
@@ -0,0 +1,94 @@
1
+ /* eslint-disable no-console */
2
+ // noinspection JSUnusedGlobalSymbols
3
+
4
+ import { DEBUG, FORCE_EVERY_REGISTER_ATTEMPT, PREFIX } from './constants';
5
+ import { ICLOptions, IConsulAPI, ICyclicStartArgs, IRegisterConfig, IRegisterCyclic } from './interfaces';
6
+ import { cyan, green, magenta, reset } from './lib/color';
7
+ import loggerStub from './lib/logger-stub';
8
+ import { toMills } from './lib/utils';
9
+
10
+ const prefix = 'CONSUL-REG:';
11
+ const prefixG = `${green}${prefix}${reset}`;
12
+
13
+ const DEFAULT_INTERVAL = 60_000;
14
+
15
+ const isDebugReg = /\baf-consul:(reg|\*)/i.test(DEBUG) || /\baf-consul:\*/i.test(DEBUG);
16
+ const debug = (msg: string) => {
17
+ if (isDebugReg) {
18
+ console.log(`${magenta}${PREFIX}${reset}: ${msg}`);
19
+ }
20
+ };
21
+
22
+ export const getRegisterCyclic = (
23
+ opts: ICLOptions,
24
+ consulApi: IConsulAPI,
25
+ registerConfig: IRegisterConfig,
26
+ ): IRegisterCyclic => ({
27
+ isStarted: false,
28
+ skipNextRegisterAttemptUntil: 0,
29
+ healthCheckIntervalMillis: 0,
30
+ registerIntervalMillis: 0,
31
+ options: opts,
32
+ _timerId: setTimeout(() => null, 0),
33
+ _logger: loggerStub,
34
+
35
+ async start (cyclicStartArgs?: ICyclicStartArgs): Promise<-1 | 0 | 1> {
36
+ const {
37
+ cLOptions,
38
+ registerInterval,
39
+ registerType = 'if-not-registered',
40
+ deleteOtherInstance = false,
41
+ noAlreadyRegisteredMessage = false,
42
+ } = cyclicStartArgs || {};
43
+
44
+ if (!cLOptions && !this.options) {
45
+ return -1;
46
+ }
47
+ if (this.isStarted) {
48
+ return 0;
49
+ }
50
+ const options = (cLOptions || this.options) as ICLOptions;
51
+ this.healthCheckIntervalMillis = toMills(options.config.consul.check?.interval);
52
+ this.registerIntervalMillis = registerInterval || (this.healthCheckIntervalMillis * 1.5) || DEFAULT_INTERVAL;
53
+
54
+ this._logger = options.logger || loggerStub;
55
+
56
+ options.em?.on('health-check', () => {
57
+ this.skipNextRegisterAttemptUntil = Date.now() + (this.healthCheckIntervalMillis * 1.5);
58
+ });
59
+
60
+ const doLoop = async () => {
61
+ if (FORCE_EVERY_REGISTER_ATTEMPT || this.skipNextRegisterAttemptUntil < Date.now()) {
62
+ try {
63
+ if (this.isStarted) {
64
+ debug(`${prefixG} Service ${cyan}${registerConfig.id}${reset} registration check...`);
65
+ }
66
+ await consulApi.registerService(registerConfig, {
67
+ registerType: (FORCE_EVERY_REGISTER_ATTEMPT || !this.isStarted) ? 'force' : (registerType || 'if-not-registered'),
68
+ deleteOtherInstance,
69
+ noAlreadyRegisteredMessage,
70
+ });
71
+ } catch (err: Error | any) {
72
+ err.message = `${prefix} ERROR: ${err.message}`;
73
+ this._logger.error(err);
74
+ }
75
+ this.skipNextRegisterAttemptUntil = 0;
76
+ } else {
77
+ debug(`${prefixG} Skip registration check after health check`);
78
+ }
79
+ clearTimeout(this._timerId);
80
+ this._timerId = setTimeout(doLoop, this.registerIntervalMillis);
81
+ };
82
+ doLoop().then((r) => r);
83
+ this.isStarted = true;
84
+ const { host, port, defaults } = consulApi.agentOptions.reg;
85
+ this._logger.info(`Cyclic Register of service ${cyan}${registerConfig.id}${reset} started. Agent: ${
86
+ cyan}${host}:${port}${reset}, token: ${cyan}${defaults?.token?.substring(0, 4)}***${reset}`);
87
+ return 1;
88
+ },
89
+ stop () {
90
+ clearTimeout(this._timerId);
91
+ this.isStarted = false;
92
+ this._logger.info(`Cyclic Register of service ${cyan}${registerConfig.id}${reset} stopped`);
93
+ },
94
+ });
package/src/get-api.ts ADDED
@@ -0,0 +1,62 @@
1
+ /* eslint-disable no-console */
2
+ // noinspection JSUnusedGlobalSymbols
3
+
4
+ import { CONSUL_DEBUG_ON, MAX_API_CACHED, PREFIX } from './constants';
5
+ import { getRegisterCyclic } from './cyclic-register';
6
+ import { getRegisterConfig } from './get-register-config';
7
+ import { IAFConsulAPI, ICache, ICLOptions, IConsulAgentOptions, IConsulAPI, TRegisterType } from './interfaces';
8
+ import { magenta, reset, yellow } from './lib/color';
9
+ import { getConfigHash } from './lib/hash';
10
+ import { minimizeCache } from './lib/utils';
11
+ import { getConsulApiCached } from './prepare-consul-api';
12
+
13
+ export { accessPointsUpdater } from './access-points/access-points-updater';
14
+
15
+ const defaultGetConsulUIAddress = (serviceId: string): string => {
16
+ const { NODE_ENV, CONSUL_UI_HOST, CONSUL_DC_PROD, CONSUL_DC_DEV } = process.env;
17
+ const p = NODE_ENV === 'production';
18
+ return `https://${CONSUL_UI_HOST || ''}/ui/dc-${p ? (CONSUL_DC_PROD || 'prd') : (CONSUL_DC_DEV || 'dev')}/services/${serviceId}/instances`;
19
+ };
20
+
21
+ const debug = (msg: string) => {
22
+ if (CONSUL_DEBUG_ON) {
23
+ console.log(`${magenta}${PREFIX}${reset}: ${msg}`);
24
+ }
25
+ };
26
+
27
+ // cached
28
+
29
+ export const apiCache: ICache<IAFConsulAPI> = {};
30
+
31
+ export const getAPI = async (options: ICLOptions): Promise<IAFConsulAPI> => {
32
+ const hash = getConfigHash(options);
33
+ if (!apiCache[hash]) {
34
+ const api: IConsulAPI = await getConsulApiCached(options) as IAFConsulAPI;
35
+ const registerConfig = await getRegisterConfig(options);
36
+ const serviceId = registerConfig.id;
37
+ minimizeCache(apiCache, MAX_API_CACHED);
38
+
39
+ const consulUI = (options.getConsulUIAddress || defaultGetConsulUIAddress)(serviceId);
40
+ debug(`${yellow} REGISTER CONFIG:\n${JSON.stringify(registerConfig, undefined, 2)}\n${reset}`);
41
+ debug(`Consul UI: ${consulUI}`);
42
+
43
+ const value = {
44
+ registerConfig,
45
+ serviceId,
46
+ register: {
47
+ once: async (registerType: TRegisterType = 'if-not-registered') => api.registerService(registerConfig, { registerType }),
48
+ cyclic: getRegisterCyclic(options, api, registerConfig),
49
+ },
50
+ deregister: (svcId?: string, agentOptions?: IConsulAgentOptions) => api.deregisterIfNeed(svcId || serviceId, agentOptions),
51
+ consulUI,
52
+ } as IAFConsulAPI;
53
+
54
+ Object.entries(api).forEach(([k, v]) => {
55
+ // @ts-ignore
56
+ value[k] = typeof v === 'function' ? v.bind(api) : v;
57
+ });
58
+
59
+ apiCache[hash] = { created: Date.now(), value };
60
+ }
61
+ return apiCache[hash].value;
62
+ };
@@ -0,0 +1,102 @@
1
+ import { PREFIX } from './constants';
2
+ import { ICLOptions, IRegisterConfig } from './interfaces';
3
+ import { getFQDNCached } from './lib/fqdn';
4
+ import { getPackageJson, parseMeta, parseTags, removeAroundQuotas } from './lib/utils';
5
+
6
+ export const getServiceID = (name: string, instance: string, envCode: string = '') => {
7
+ const p = (process.env.NODE_CONSUL_ENV || process.env.NODE_ENV) === 'production';
8
+ return `${p ? 'prd' : 'dev'}-${envCode}-${name}-${instance}`.toLowerCase();
9
+ };
10
+
11
+ export const getRegisterConfig = async (options: ICLOptions): Promise<IRegisterConfig> => {
12
+ const { config, envCode = '' } = options;
13
+ const { webServer } = config;
14
+ const consulServiceConfig = config?.consul?.service ?? {};
15
+ const { id, host } = consulServiceConfig;
16
+ let { name, instance, version, description, tags, meta, port } = consulServiceConfig;
17
+ name = removeAroundQuotas(name);
18
+ instance = removeAroundQuotas(instance);
19
+ version = removeAroundQuotas(version);
20
+ description = removeAroundQuotas(description);
21
+ tags = parseTags(tags);
22
+ tags = [name, version, ...(tags)];
23
+ if (envCode) {
24
+ tags.push(envCode);
25
+ }
26
+ port = Number(port) || Number(webServer.port);
27
+ if (!port) {
28
+ throw new Error(`${PREFIX}: Port is empty!`);
29
+ }
30
+
31
+ const serviceId = id || process.env.CONSUL_SERVICE_ID || getServiceID(name, instance, envCode);
32
+
33
+ const address = host || (await getFQDNCached());
34
+ if (!address) {
35
+ throw new Error(`${PREFIX}: Address is empty!`);
36
+ }
37
+
38
+ meta = parseMeta(meta, { serviceId, name, instance, address, port });
39
+ const metaObj: Record<string, string> = {
40
+ host: address,
41
+ port: String(port),
42
+ NODE_ENV: process.env.NODE_ENV || '',
43
+ };
44
+ if (name) {
45
+ metaObj.name = name;
46
+ }
47
+ if (version) {
48
+ metaObj.version = version;
49
+ }
50
+ if (description) {
51
+ metaObj.description = description;
52
+ }
53
+ if (instance) {
54
+ metaObj.instance = instance;
55
+ }
56
+
57
+ let packageJson = getPackageJson();
58
+ if (packageJson) {
59
+ metaObj.pj_name = packageJson.name;
60
+ metaObj.pj_version = packageJson.version;
61
+ }
62
+ if (metaObj.pj_name !== 'fa-consul') {
63
+ packageJson = getPackageJson('/node_modules/fa-consul');
64
+ if (packageJson) {
65
+ metaObj.af_consul_version = packageJson.version;
66
+ }
67
+ }
68
+ const registerConfig: IRegisterConfig = {
69
+ id: serviceId,
70
+ name: serviceId,
71
+ port,
72
+ address,
73
+ tags,
74
+ // @ts-ignore
75
+ meta: <Record<string, string>>{ ...metaObj, ...meta },
76
+ };
77
+ const check = { ...(config.consul?.check || {}) };
78
+ [['name', `Service '${name}-${instance}'`], ['timeout', '5s'], ['deregistercriticalserviceafter', '3m']]
79
+ .forEach(([n, v]) => {
80
+ // @ts-ignore
81
+ if (!check[n]) {
82
+ // @ts-ignore
83
+ check[n] = v;
84
+ }
85
+ });
86
+ if (!(check.http || check.tcp || check.script || check.shell)) {
87
+ check.http = `http://${address}:${port}/health`;
88
+ }
89
+ if ((check.http || check.script) && !check.interval) {
90
+ check.interval = '10s';
91
+ }
92
+ registerConfig.check = check;
93
+
94
+ if (!config.service) {
95
+ config.service = {};
96
+ }
97
+ config.service.id = serviceId;
98
+ config.service.address = address;
99
+ config.service.fromService = `${serviceId} / ${address}`;
100
+
101
+ return registerConfig;
102
+ };
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ export { AccessPoints } from './access-points/access-points';
2
+ export { accessPointsUpdater } from './access-points/access-points-updater';
3
+ export { getAPI } from './get-api';
4
+ export { getRegisterConfig, getServiceID } from './get-register-config';
5
+ export { getConsulApiCached, prepareConsulAPI } from './prepare-consul-api';
6
+ export { getFQDN, getFQDNCached } from './lib/fqdn';
7
+ export { substitutePercentBracket } from './lib/utils';
8
+ export { checkAccessPointAvailability, isHttpAvailable } from './access-points/access-points-utils';
9
+ export type {
10
+ IAFConfig,
11
+ ICache,
12
+ ICLOptions,
13
+ IConsulAgentConfig,
14
+ IConsulAgentOptions,
15
+ IConsulAPI,
16
+ ICyclicStartArgs,
17
+ IRegisterConfig,
18
+ IRegisterCyclic,
19
+ IAccessPoint,
20
+ IAccessPoints,
21
+ IAPIArgs,
22
+ IAFConsulAPI,
23
+ IAFConsulConfig,
24
+ IConsulServiceInfo,
25
+ IFullConsulAgentConfig,
26
+ IFullConsulAgentOptions,
27
+ IConsulNodeInfo,
28
+ IMeta,
29
+ IRegisterCheck,
30
+ IConsulHealthServiceInfo,
31
+ ISocketInfo,
32
+ ILogger,
33
+ IRegisterOptions,
34
+ TRegisterResult,
35
+ TCommonFnResult,
36
+ TRegisterType,
37
+ TLoggerMethod,
38
+ Maybe,
39
+ Nullable,
40
+ TBooleanLike,
41
+ } from './interfaces';
42
+
43
+ // Export new consul-client types for advanced usage
44
+ export { ConsulClient, ConsulHttpClient } from './consul-client';
45
+ export type {
46
+ ConsulClientOptions,
47
+ RegisterCheck,
48
+ RegisterServiceOptions,
49
+ ServiceInfo,
50
+ NodeInfo,
51
+ HealthCheck,
52
+ HealthServiceInfo,
53
+ AgentMember,
54
+ RequestInfo,
55
+ ResponseInfo,
56
+ OnRequestHook,
57
+ OnResponseHook,
58
+ } from './consul-client';