af-consul
Advanced tools
Comparing version 3.0.19 to 3.0.20
@@ -8,6 +8,3 @@ "use strict"; | ||
const getServiceID = (name, instance, projectId = '') => { | ||
if (process.env.CONSUL_SERVICE_ID) { | ||
return process.env.CONSUL_SERVICE_ID; | ||
} | ||
const p = process.env.NODE_ENV === 'production'; | ||
const p = (process.env.NODE_CONSUL_ENV || process.env.NODE_ENV) === 'production'; | ||
return `${p ? 'prd' : 'dev'}-${projectId || ''}${p ? 'r' : 'e'}01-${name}-${instance}`.toLowerCase(); | ||
@@ -17,8 +14,8 @@ }; | ||
const getRegisterConfig = async (options) => { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c; | ||
const { config, projectId = '' } = options; | ||
const { webServer } = config; | ||
// eslint-disable-next-line prefer-const | ||
const { host } = (_b = (_a = config === null || config === void 0 ? void 0 : config.consul) === null || _a === void 0 ? void 0 : _a.service) !== null && _b !== void 0 ? _b : {}; | ||
let { name, instance, version, description, tags, meta, port } = (_d = (_c = config === null || config === void 0 ? void 0 : config.consul) === null || _c === void 0 ? void 0 : _c.service) !== null && _d !== void 0 ? _d : {}; | ||
const consulServiceConfig = (_b = (_a = config === null || config === void 0 ? void 0 : config.consul) === null || _a === void 0 ? void 0 : _a.service) !== null && _b !== void 0 ? _b : {}; | ||
const { id, host } = consulServiceConfig; | ||
let { name, instance, version, description, tags, meta, port } = consulServiceConfig; | ||
name = (0, utils_1.removeAroundQuotas)(name); | ||
@@ -37,3 +34,3 @@ instance = (0, utils_1.removeAroundQuotas)(instance); | ||
} | ||
const serviceId = (0, exports.getServiceID)(name, instance, projectId); | ||
const serviceId = id || process.env.CONSUL_SERVICE_ID || (0, exports.getServiceID)(name, instance, projectId); | ||
const address = host || (await (0, fqdn_1.getFQDNCached)()); | ||
@@ -80,3 +77,3 @@ if (!address) { | ||
}; | ||
const check = { ...(((_e = config.consul) === null || _e === void 0 ? void 0 : _e.check) || {}) }; | ||
const check = { ...(((_c = config.consul) === null || _c === void 0 ? void 0 : _c.check) || {}) }; | ||
[['name', `Service '${name}-${instance}'`], ['timeout', '5s'], ['deregistercriticalserviceafter', '3m']] | ||
@@ -83,0 +80,0 @@ .forEach(([n, v]) => { |
@@ -5,15 +5,12 @@ import { getPackageJson, parseMeta, parseTags, removeAroundQuotas } from './lib/utils'; | ||
export const getServiceID = (name, instance, projectId = '') => { | ||
if (process.env.CONSUL_SERVICE_ID) { | ||
return process.env.CONSUL_SERVICE_ID; | ||
} | ||
const p = process.env.NODE_ENV === 'production'; | ||
const p = (process.env.NODE_CONSUL_ENV || process.env.NODE_ENV) === 'production'; | ||
return `${p ? 'prd' : 'dev'}-${projectId || ''}${p ? 'r' : 'e'}01-${name}-${instance}`.toLowerCase(); | ||
}; | ||
export const getRegisterConfig = async (options) => { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c; | ||
const { config, projectId = '' } = options; | ||
const { webServer } = config; | ||
// eslint-disable-next-line prefer-const | ||
const { host } = (_b = (_a = config === null || config === void 0 ? void 0 : config.consul) === null || _a === void 0 ? void 0 : _a.service) !== null && _b !== void 0 ? _b : {}; | ||
let { name, instance, version, description, tags, meta, port } = (_d = (_c = config === null || config === void 0 ? void 0 : config.consul) === null || _c === void 0 ? void 0 : _c.service) !== null && _d !== void 0 ? _d : {}; | ||
const consulServiceConfig = (_b = (_a = config === null || config === void 0 ? void 0 : config.consul) === null || _a === void 0 ? void 0 : _a.service) !== null && _b !== void 0 ? _b : {}; | ||
const { id, host } = consulServiceConfig; | ||
let { name, instance, version, description, tags, meta, port } = consulServiceConfig; | ||
name = removeAroundQuotas(name); | ||
@@ -32,3 +29,3 @@ instance = removeAroundQuotas(instance); | ||
} | ||
const serviceId = getServiceID(name, instance, projectId); | ||
const serviceId = id || process.env.CONSUL_SERVICE_ID || getServiceID(name, instance, projectId); | ||
const address = host || (await getFQDNCached()); | ||
@@ -75,3 +72,3 @@ if (!address) { | ||
}; | ||
const check = { ...(((_e = config.consul) === null || _e === void 0 ? void 0 : _e.check) || {}) }; | ||
const check = { ...(((_c = config.consul) === null || _c === void 0 ? void 0 : _c.check) || {}) }; | ||
[['name', `Service '${name}-${instance}'`], ['timeout', '5s'], ['deregistercriticalserviceafter', '3m']] | ||
@@ -78,0 +75,0 @@ .forEach(([n, v]) => { |
@@ -98,2 +98,3 @@ /// <reference types="node" /> | ||
service: { | ||
id?: string; | ||
name: string; | ||
@@ -100,0 +101,0 @@ instance: string; |
{ | ||
"name": "af-consul", | ||
"version": "3.0.19", | ||
"version": "3.0.20", | ||
"description": "A highly specialized function library", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/src/index.js", |
@@ -7,6 +7,3 @@ import { getPackageJson, parseMeta, parseTags, removeAroundQuotas } from './lib/utils'; | ||
export const getServiceID = (name: string, instance: string, projectId: string = '') => { | ||
if (process.env.CONSUL_SERVICE_ID) { | ||
return process.env.CONSUL_SERVICE_ID; | ||
} | ||
const p = process.env.NODE_ENV === 'production'; | ||
const p = (process.env.NODE_CONSUL_ENV || process.env.NODE_ENV) === 'production'; | ||
return `${p ? 'prd' : 'dev'}-${projectId || ''}${p ? 'r' : 'e'}01-${name}-${instance}`.toLowerCase(); | ||
@@ -18,6 +15,5 @@ }; | ||
const { webServer } = config; | ||
// eslint-disable-next-line prefer-const | ||
const { host } = config?.consul?.service ?? {}; | ||
let { name, instance, version, description, tags, meta, port } = config?.consul?.service ?? {}; | ||
const consulServiceConfig = config?.consul?.service ?? {}; | ||
const { id, host } = consulServiceConfig; | ||
let { name, instance, version, description, tags, meta, port } = consulServiceConfig; | ||
name = removeAroundQuotas(name); | ||
@@ -37,3 +33,3 @@ instance = removeAroundQuotas(instance); | ||
const serviceId = getServiceID(name, instance, projectId); | ||
const serviceId = id || process.env.CONSUL_SERVICE_ID || getServiceID(name, instance, projectId); | ||
@@ -40,0 +36,0 @@ const address = host || (await getFQDNCached()); |
@@ -116,2 +116,3 @@ import Consul from 'consul'; | ||
service: { | ||
id?: string, | ||
name: string, | ||
@@ -118,0 +119,0 @@ instance: string, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
315255
4574