node-consul-service 1.0.74 → 1.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var Consul = require('consul');
4
3
  var require$$1 = require('util');
5
4
  var stream = require('stream');
6
5
  var path = require('path');
@@ -10,8 +9,6 @@ var require$$0$1 = require('url');
10
9
  var require$$6 = require('fs');
11
10
  var crypto = require('crypto');
12
11
  var require$$4$1 = require('assert');
13
- var require$$1$1 = require('tty');
14
- var require$$0$2 = require('os');
15
12
  var zlib = require('zlib');
16
13
  var events = require('events');
17
14
 
@@ -15538,1196 +15535,6 @@ var proxyFromEnv = /*@__PURE__*/getDefaultExportFromCjs(proxyFromEnvExports);
15538
15535
 
15539
15536
  var followRedirects$1 = {exports: {}};
15540
15537
 
15541
- var src = {exports: {}};
15542
-
15543
- var browser = {exports: {}};
15544
-
15545
- /**
15546
- * Helpers.
15547
- */
15548
-
15549
- var ms;
15550
- var hasRequiredMs;
15551
-
15552
- function requireMs () {
15553
- if (hasRequiredMs) return ms;
15554
- hasRequiredMs = 1;
15555
- var s = 1000;
15556
- var m = s * 60;
15557
- var h = m * 60;
15558
- var d = h * 24;
15559
- var w = d * 7;
15560
- var y = d * 365.25;
15561
-
15562
- /**
15563
- * Parse or format the given `val`.
15564
- *
15565
- * Options:
15566
- *
15567
- * - `long` verbose formatting [false]
15568
- *
15569
- * @param {String|Number} val
15570
- * @param {Object} [options]
15571
- * @throws {Error} throw an error if val is not a non-empty string or a number
15572
- * @return {String|Number}
15573
- * @api public
15574
- */
15575
-
15576
- ms = function (val, options) {
15577
- options = options || {};
15578
- var type = typeof val;
15579
- if (type === 'string' && val.length > 0) {
15580
- return parse(val);
15581
- } else if (type === 'number' && isFinite(val)) {
15582
- return options.long ? fmtLong(val) : fmtShort(val);
15583
- }
15584
- throw new Error(
15585
- 'val is not a non-empty string or a valid number. val=' +
15586
- JSON.stringify(val)
15587
- );
15588
- };
15589
-
15590
- /**
15591
- * Parse the given `str` and return milliseconds.
15592
- *
15593
- * @param {String} str
15594
- * @return {Number}
15595
- * @api private
15596
- */
15597
-
15598
- function parse(str) {
15599
- str = String(str);
15600
- if (str.length > 100) {
15601
- return;
15602
- }
15603
- var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
15604
- str
15605
- );
15606
- if (!match) {
15607
- return;
15608
- }
15609
- var n = parseFloat(match[1]);
15610
- var type = (match[2] || 'ms').toLowerCase();
15611
- switch (type) {
15612
- case 'years':
15613
- case 'year':
15614
- case 'yrs':
15615
- case 'yr':
15616
- case 'y':
15617
- return n * y;
15618
- case 'weeks':
15619
- case 'week':
15620
- case 'w':
15621
- return n * w;
15622
- case 'days':
15623
- case 'day':
15624
- case 'd':
15625
- return n * d;
15626
- case 'hours':
15627
- case 'hour':
15628
- case 'hrs':
15629
- case 'hr':
15630
- case 'h':
15631
- return n * h;
15632
- case 'minutes':
15633
- case 'minute':
15634
- case 'mins':
15635
- case 'min':
15636
- case 'm':
15637
- return n * m;
15638
- case 'seconds':
15639
- case 'second':
15640
- case 'secs':
15641
- case 'sec':
15642
- case 's':
15643
- return n * s;
15644
- case 'milliseconds':
15645
- case 'millisecond':
15646
- case 'msecs':
15647
- case 'msec':
15648
- case 'ms':
15649
- return n;
15650
- default:
15651
- return undefined;
15652
- }
15653
- }
15654
-
15655
- /**
15656
- * Short format for `ms`.
15657
- *
15658
- * @param {Number} ms
15659
- * @return {String}
15660
- * @api private
15661
- */
15662
-
15663
- function fmtShort(ms) {
15664
- var msAbs = Math.abs(ms);
15665
- if (msAbs >= d) {
15666
- return Math.round(ms / d) + 'd';
15667
- }
15668
- if (msAbs >= h) {
15669
- return Math.round(ms / h) + 'h';
15670
- }
15671
- if (msAbs >= m) {
15672
- return Math.round(ms / m) + 'm';
15673
- }
15674
- if (msAbs >= s) {
15675
- return Math.round(ms / s) + 's';
15676
- }
15677
- return ms + 'ms';
15678
- }
15679
-
15680
- /**
15681
- * Long format for `ms`.
15682
- *
15683
- * @param {Number} ms
15684
- * @return {String}
15685
- * @api private
15686
- */
15687
-
15688
- function fmtLong(ms) {
15689
- var msAbs = Math.abs(ms);
15690
- if (msAbs >= d) {
15691
- return plural(ms, msAbs, d, 'day');
15692
- }
15693
- if (msAbs >= h) {
15694
- return plural(ms, msAbs, h, 'hour');
15695
- }
15696
- if (msAbs >= m) {
15697
- return plural(ms, msAbs, m, 'minute');
15698
- }
15699
- if (msAbs >= s) {
15700
- return plural(ms, msAbs, s, 'second');
15701
- }
15702
- return ms + ' ms';
15703
- }
15704
-
15705
- /**
15706
- * Pluralization helper.
15707
- */
15708
-
15709
- function plural(ms, msAbs, n, name) {
15710
- var isPlural = msAbs >= n * 1.5;
15711
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
15712
- }
15713
- return ms;
15714
- }
15715
-
15716
- var common;
15717
- var hasRequiredCommon;
15718
-
15719
- function requireCommon () {
15720
- if (hasRequiredCommon) return common;
15721
- hasRequiredCommon = 1;
15722
- /**
15723
- * This is the common logic for both the Node.js and web browser
15724
- * implementations of `debug()`.
15725
- */
15726
-
15727
- function setup(env) {
15728
- createDebug.debug = createDebug;
15729
- createDebug.default = createDebug;
15730
- createDebug.coerce = coerce;
15731
- createDebug.disable = disable;
15732
- createDebug.enable = enable;
15733
- createDebug.enabled = enabled;
15734
- createDebug.humanize = requireMs();
15735
- createDebug.destroy = destroy;
15736
-
15737
- Object.keys(env).forEach(key => {
15738
- createDebug[key] = env[key];
15739
- });
15740
-
15741
- /**
15742
- * The currently active debug mode names, and names to skip.
15743
- */
15744
-
15745
- createDebug.names = [];
15746
- createDebug.skips = [];
15747
-
15748
- /**
15749
- * Map of special "%n" handling functions, for the debug "format" argument.
15750
- *
15751
- * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
15752
- */
15753
- createDebug.formatters = {};
15754
-
15755
- /**
15756
- * Selects a color for a debug namespace
15757
- * @param {String} namespace The namespace string for the debug instance to be colored
15758
- * @return {Number|String} An ANSI color code for the given namespace
15759
- * @api private
15760
- */
15761
- function selectColor(namespace) {
15762
- let hash = 0;
15763
-
15764
- for (let i = 0; i < namespace.length; i++) {
15765
- hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
15766
- hash |= 0; // Convert to 32bit integer
15767
- }
15768
-
15769
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
15770
- }
15771
- createDebug.selectColor = selectColor;
15772
-
15773
- /**
15774
- * Create a debugger with the given `namespace`.
15775
- *
15776
- * @param {String} namespace
15777
- * @return {Function}
15778
- * @api public
15779
- */
15780
- function createDebug(namespace) {
15781
- let prevTime;
15782
- let enableOverride = null;
15783
- let namespacesCache;
15784
- let enabledCache;
15785
-
15786
- function debug(...args) {
15787
- // Disabled?
15788
- if (!debug.enabled) {
15789
- return;
15790
- }
15791
-
15792
- const self = debug;
15793
-
15794
- // Set `diff` timestamp
15795
- const curr = Number(new Date());
15796
- const ms = curr - (prevTime || curr);
15797
- self.diff = ms;
15798
- self.prev = prevTime;
15799
- self.curr = curr;
15800
- prevTime = curr;
15801
-
15802
- args[0] = createDebug.coerce(args[0]);
15803
-
15804
- if (typeof args[0] !== 'string') {
15805
- // Anything else let's inspect with %O
15806
- args.unshift('%O');
15807
- }
15808
-
15809
- // Apply any `formatters` transformations
15810
- let index = 0;
15811
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
15812
- // If we encounter an escaped % then don't increase the array index
15813
- if (match === '%%') {
15814
- return '%';
15815
- }
15816
- index++;
15817
- const formatter = createDebug.formatters[format];
15818
- if (typeof formatter === 'function') {
15819
- const val = args[index];
15820
- match = formatter.call(self, val);
15821
-
15822
- // Now we need to remove `args[index]` since it's inlined in the `format`
15823
- args.splice(index, 1);
15824
- index--;
15825
- }
15826
- return match;
15827
- });
15828
-
15829
- // Apply env-specific formatting (colors, etc.)
15830
- createDebug.formatArgs.call(self, args);
15831
-
15832
- const logFn = self.log || createDebug.log;
15833
- logFn.apply(self, args);
15834
- }
15835
-
15836
- debug.namespace = namespace;
15837
- debug.useColors = createDebug.useColors();
15838
- debug.color = createDebug.selectColor(namespace);
15839
- debug.extend = extend;
15840
- debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
15841
-
15842
- Object.defineProperty(debug, 'enabled', {
15843
- enumerable: true,
15844
- configurable: false,
15845
- get: () => {
15846
- if (enableOverride !== null) {
15847
- return enableOverride;
15848
- }
15849
- if (namespacesCache !== createDebug.namespaces) {
15850
- namespacesCache = createDebug.namespaces;
15851
- enabledCache = createDebug.enabled(namespace);
15852
- }
15853
-
15854
- return enabledCache;
15855
- },
15856
- set: v => {
15857
- enableOverride = v;
15858
- }
15859
- });
15860
-
15861
- // Env-specific initialization logic for debug instances
15862
- if (typeof createDebug.init === 'function') {
15863
- createDebug.init(debug);
15864
- }
15865
-
15866
- return debug;
15867
- }
15868
-
15869
- function extend(namespace, delimiter) {
15870
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
15871
- newDebug.log = this.log;
15872
- return newDebug;
15873
- }
15874
-
15875
- /**
15876
- * Enables a debug mode by namespaces. This can include modes
15877
- * separated by a colon and wildcards.
15878
- *
15879
- * @param {String} namespaces
15880
- * @api public
15881
- */
15882
- function enable(namespaces) {
15883
- createDebug.save(namespaces);
15884
- createDebug.namespaces = namespaces;
15885
-
15886
- createDebug.names = [];
15887
- createDebug.skips = [];
15888
-
15889
- let i;
15890
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
15891
- const len = split.length;
15892
-
15893
- for (i = 0; i < len; i++) {
15894
- if (!split[i]) {
15895
- // ignore empty strings
15896
- continue;
15897
- }
15898
-
15899
- namespaces = split[i].replace(/\*/g, '.*?');
15900
-
15901
- if (namespaces[0] === '-') {
15902
- createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
15903
- } else {
15904
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
15905
- }
15906
- }
15907
- }
15908
-
15909
- /**
15910
- * Disable debug output.
15911
- *
15912
- * @return {String} namespaces
15913
- * @api public
15914
- */
15915
- function disable() {
15916
- const namespaces = [
15917
- ...createDebug.names.map(toNamespace),
15918
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
15919
- ].join(',');
15920
- createDebug.enable('');
15921
- return namespaces;
15922
- }
15923
-
15924
- /**
15925
- * Returns true if the given mode name is enabled, false otherwise.
15926
- *
15927
- * @param {String} name
15928
- * @return {Boolean}
15929
- * @api public
15930
- */
15931
- function enabled(name) {
15932
- if (name[name.length - 1] === '*') {
15933
- return true;
15934
- }
15935
-
15936
- let i;
15937
- let len;
15938
-
15939
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
15940
- if (createDebug.skips[i].test(name)) {
15941
- return false;
15942
- }
15943
- }
15944
-
15945
- for (i = 0, len = createDebug.names.length; i < len; i++) {
15946
- if (createDebug.names[i].test(name)) {
15947
- return true;
15948
- }
15949
- }
15950
-
15951
- return false;
15952
- }
15953
-
15954
- /**
15955
- * Convert regexp to namespace
15956
- *
15957
- * @param {RegExp} regxep
15958
- * @return {String} namespace
15959
- * @api private
15960
- */
15961
- function toNamespace(regexp) {
15962
- return regexp.toString()
15963
- .substring(2, regexp.toString().length - 2)
15964
- .replace(/\.\*\?$/, '*');
15965
- }
15966
-
15967
- /**
15968
- * Coerce `val`.
15969
- *
15970
- * @param {Mixed} val
15971
- * @return {Mixed}
15972
- * @api private
15973
- */
15974
- function coerce(val) {
15975
- if (val instanceof Error) {
15976
- return val.stack || val.message;
15977
- }
15978
- return val;
15979
- }
15980
-
15981
- /**
15982
- * XXX DO NOT USE. This is a temporary stub function.
15983
- * XXX It WILL be removed in the next major release.
15984
- */
15985
- function destroy() {
15986
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
15987
- }
15988
-
15989
- createDebug.enable(createDebug.load());
15990
-
15991
- return createDebug;
15992
- }
15993
-
15994
- common = setup;
15995
- return common;
15996
- }
15997
-
15998
- /* eslint-env browser */
15999
-
16000
- var hasRequiredBrowser;
16001
-
16002
- function requireBrowser () {
16003
- if (hasRequiredBrowser) return browser.exports;
16004
- hasRequiredBrowser = 1;
16005
- (function (module, exports) {
16006
- /**
16007
- * This is the web browser implementation of `debug()`.
16008
- */
16009
-
16010
- exports.formatArgs = formatArgs;
16011
- exports.save = save;
16012
- exports.load = load;
16013
- exports.useColors = useColors;
16014
- exports.storage = localstorage();
16015
- exports.destroy = (() => {
16016
- let warned = false;
16017
-
16018
- return () => {
16019
- if (!warned) {
16020
- warned = true;
16021
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
16022
- }
16023
- };
16024
- })();
16025
-
16026
- /**
16027
- * Colors.
16028
- */
16029
-
16030
- exports.colors = [
16031
- '#0000CC',
16032
- '#0000FF',
16033
- '#0033CC',
16034
- '#0033FF',
16035
- '#0066CC',
16036
- '#0066FF',
16037
- '#0099CC',
16038
- '#0099FF',
16039
- '#00CC00',
16040
- '#00CC33',
16041
- '#00CC66',
16042
- '#00CC99',
16043
- '#00CCCC',
16044
- '#00CCFF',
16045
- '#3300CC',
16046
- '#3300FF',
16047
- '#3333CC',
16048
- '#3333FF',
16049
- '#3366CC',
16050
- '#3366FF',
16051
- '#3399CC',
16052
- '#3399FF',
16053
- '#33CC00',
16054
- '#33CC33',
16055
- '#33CC66',
16056
- '#33CC99',
16057
- '#33CCCC',
16058
- '#33CCFF',
16059
- '#6600CC',
16060
- '#6600FF',
16061
- '#6633CC',
16062
- '#6633FF',
16063
- '#66CC00',
16064
- '#66CC33',
16065
- '#9900CC',
16066
- '#9900FF',
16067
- '#9933CC',
16068
- '#9933FF',
16069
- '#99CC00',
16070
- '#99CC33',
16071
- '#CC0000',
16072
- '#CC0033',
16073
- '#CC0066',
16074
- '#CC0099',
16075
- '#CC00CC',
16076
- '#CC00FF',
16077
- '#CC3300',
16078
- '#CC3333',
16079
- '#CC3366',
16080
- '#CC3399',
16081
- '#CC33CC',
16082
- '#CC33FF',
16083
- '#CC6600',
16084
- '#CC6633',
16085
- '#CC9900',
16086
- '#CC9933',
16087
- '#CCCC00',
16088
- '#CCCC33',
16089
- '#FF0000',
16090
- '#FF0033',
16091
- '#FF0066',
16092
- '#FF0099',
16093
- '#FF00CC',
16094
- '#FF00FF',
16095
- '#FF3300',
16096
- '#FF3333',
16097
- '#FF3366',
16098
- '#FF3399',
16099
- '#FF33CC',
16100
- '#FF33FF',
16101
- '#FF6600',
16102
- '#FF6633',
16103
- '#FF9900',
16104
- '#FF9933',
16105
- '#FFCC00',
16106
- '#FFCC33'
16107
- ];
16108
-
16109
- /**
16110
- * Currently only WebKit-based Web Inspectors, Firefox >= v31,
16111
- * and the Firebug extension (any Firefox version) are known
16112
- * to support "%c" CSS customizations.
16113
- *
16114
- * TODO: add a `localStorage` variable to explicitly enable/disable colors
16115
- */
16116
-
16117
- // eslint-disable-next-line complexity
16118
- function useColors() {
16119
- // NB: In an Electron preload script, document will be defined but not fully
16120
- // initialized. Since we know we're in Chrome, we'll just detect this case
16121
- // explicitly
16122
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
16123
- return true;
16124
- }
16125
-
16126
- // Internet Explorer and Edge do not support colors.
16127
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
16128
- return false;
16129
- }
16130
-
16131
- let m;
16132
-
16133
- // Is webkit? http://stackoverflow.com/a/16459606/376773
16134
- // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
16135
- return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
16136
- // Is firebug? http://stackoverflow.com/a/398120/376773
16137
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
16138
- // Is firefox >= v31?
16139
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
16140
- (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
16141
- // Double check webkit in userAgent just in case we are in a worker
16142
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
16143
- }
16144
-
16145
- /**
16146
- * Colorize log arguments if enabled.
16147
- *
16148
- * @api public
16149
- */
16150
-
16151
- function formatArgs(args) {
16152
- args[0] = (this.useColors ? '%c' : '') +
16153
- this.namespace +
16154
- (this.useColors ? ' %c' : ' ') +
16155
- args[0] +
16156
- (this.useColors ? '%c ' : ' ') +
16157
- '+' + module.exports.humanize(this.diff);
16158
-
16159
- if (!this.useColors) {
16160
- return;
16161
- }
16162
-
16163
- const c = 'color: ' + this.color;
16164
- args.splice(1, 0, c, 'color: inherit');
16165
-
16166
- // The final "%c" is somewhat tricky, because there could be other
16167
- // arguments passed either before or after the %c, so we need to
16168
- // figure out the correct index to insert the CSS into
16169
- let index = 0;
16170
- let lastC = 0;
16171
- args[0].replace(/%[a-zA-Z%]/g, match => {
16172
- if (match === '%%') {
16173
- return;
16174
- }
16175
- index++;
16176
- if (match === '%c') {
16177
- // We only are interested in the *last* %c
16178
- // (the user may have provided their own)
16179
- lastC = index;
16180
- }
16181
- });
16182
-
16183
- args.splice(lastC, 0, c);
16184
- }
16185
-
16186
- /**
16187
- * Invokes `console.debug()` when available.
16188
- * No-op when `console.debug` is not a "function".
16189
- * If `console.debug` is not available, falls back
16190
- * to `console.log`.
16191
- *
16192
- * @api public
16193
- */
16194
- exports.log = console.debug || console.log || (() => {});
16195
-
16196
- /**
16197
- * Save `namespaces`.
16198
- *
16199
- * @param {String} namespaces
16200
- * @api private
16201
- */
16202
- function save(namespaces) {
16203
- try {
16204
- if (namespaces) {
16205
- exports.storage.setItem('debug', namespaces);
16206
- } else {
16207
- exports.storage.removeItem('debug');
16208
- }
16209
- } catch (error) {
16210
- // Swallow
16211
- // XXX (@Qix-) should we be logging these?
16212
- }
16213
- }
16214
-
16215
- /**
16216
- * Load `namespaces`.
16217
- *
16218
- * @return {String} returns the previously persisted debug modes
16219
- * @api private
16220
- */
16221
- function load() {
16222
- let r;
16223
- try {
16224
- r = exports.storage.getItem('debug');
16225
- } catch (error) {
16226
- // Swallow
16227
- // XXX (@Qix-) should we be logging these?
16228
- }
16229
-
16230
- // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
16231
- if (!r && typeof process !== 'undefined' && 'env' in process) {
16232
- r = process.env.DEBUG;
16233
- }
16234
-
16235
- return r;
16236
- }
16237
-
16238
- /**
16239
- * Localstorage attempts to return the localstorage.
16240
- *
16241
- * This is necessary because safari throws
16242
- * when a user disables cookies/localstorage
16243
- * and you attempt to access it.
16244
- *
16245
- * @return {LocalStorage}
16246
- * @api private
16247
- */
16248
-
16249
- function localstorage() {
16250
- try {
16251
- // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
16252
- // The Browser also has localStorage in the global context.
16253
- return localStorage;
16254
- } catch (error) {
16255
- // Swallow
16256
- // XXX (@Qix-) should we be logging these?
16257
- }
16258
- }
16259
-
16260
- module.exports = requireCommon()(exports);
16261
-
16262
- const {formatters} = module.exports;
16263
-
16264
- /**
16265
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
16266
- */
16267
-
16268
- formatters.j = function (v) {
16269
- try {
16270
- return JSON.stringify(v);
16271
- } catch (error) {
16272
- return '[UnexpectedJSONParseError]: ' + error.message;
16273
- }
16274
- };
16275
- } (browser, browser.exports));
16276
- return browser.exports;
16277
- }
16278
-
16279
- var node = {exports: {}};
16280
-
16281
- var hasFlag;
16282
- var hasRequiredHasFlag;
16283
-
16284
- function requireHasFlag () {
16285
- if (hasRequiredHasFlag) return hasFlag;
16286
- hasRequiredHasFlag = 1;
16287
-
16288
- hasFlag = (flag, argv = process.argv) => {
16289
- const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
16290
- const position = argv.indexOf(prefix + flag);
16291
- const terminatorPosition = argv.indexOf('--');
16292
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
16293
- };
16294
- return hasFlag;
16295
- }
16296
-
16297
- var supportsColor_1;
16298
- var hasRequiredSupportsColor;
16299
-
16300
- function requireSupportsColor () {
16301
- if (hasRequiredSupportsColor) return supportsColor_1;
16302
- hasRequiredSupportsColor = 1;
16303
- const os = require$$0$2;
16304
- const tty = require$$1$1;
16305
- const hasFlag = requireHasFlag();
16306
-
16307
- const {env} = process;
16308
-
16309
- let forceColor;
16310
- if (hasFlag('no-color') ||
16311
- hasFlag('no-colors') ||
16312
- hasFlag('color=false') ||
16313
- hasFlag('color=never')) {
16314
- forceColor = 0;
16315
- } else if (hasFlag('color') ||
16316
- hasFlag('colors') ||
16317
- hasFlag('color=true') ||
16318
- hasFlag('color=always')) {
16319
- forceColor = 1;
16320
- }
16321
-
16322
- if ('FORCE_COLOR' in env) {
16323
- if (env.FORCE_COLOR === 'true') {
16324
- forceColor = 1;
16325
- } else if (env.FORCE_COLOR === 'false') {
16326
- forceColor = 0;
16327
- } else {
16328
- forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
16329
- }
16330
- }
16331
-
16332
- function translateLevel(level) {
16333
- if (level === 0) {
16334
- return false;
16335
- }
16336
-
16337
- return {
16338
- level,
16339
- hasBasic: true,
16340
- has256: level >= 2,
16341
- has16m: level >= 3
16342
- };
16343
- }
16344
-
16345
- function supportsColor(haveStream, streamIsTTY) {
16346
- if (forceColor === 0) {
16347
- return 0;
16348
- }
16349
-
16350
- if (hasFlag('color=16m') ||
16351
- hasFlag('color=full') ||
16352
- hasFlag('color=truecolor')) {
16353
- return 3;
16354
- }
16355
-
16356
- if (hasFlag('color=256')) {
16357
- return 2;
16358
- }
16359
-
16360
- if (haveStream && !streamIsTTY && forceColor === undefined) {
16361
- return 0;
16362
- }
16363
-
16364
- const min = forceColor || 0;
16365
-
16366
- if (env.TERM === 'dumb') {
16367
- return min;
16368
- }
16369
-
16370
- if (process.platform === 'win32') {
16371
- // Windows 10 build 10586 is the first Windows release that supports 256 colors.
16372
- // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
16373
- const osRelease = os.release().split('.');
16374
- if (
16375
- Number(osRelease[0]) >= 10 &&
16376
- Number(osRelease[2]) >= 10586
16377
- ) {
16378
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
16379
- }
16380
-
16381
- return 1;
16382
- }
16383
-
16384
- if ('CI' in env) {
16385
- if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
16386
- return 1;
16387
- }
16388
-
16389
- return min;
16390
- }
16391
-
16392
- if ('TEAMCITY_VERSION' in env) {
16393
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
16394
- }
16395
-
16396
- if (env.COLORTERM === 'truecolor') {
16397
- return 3;
16398
- }
16399
-
16400
- if ('TERM_PROGRAM' in env) {
16401
- const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
16402
-
16403
- switch (env.TERM_PROGRAM) {
16404
- case 'iTerm.app':
16405
- return version >= 3 ? 3 : 2;
16406
- case 'Apple_Terminal':
16407
- return 2;
16408
- // No default
16409
- }
16410
- }
16411
-
16412
- if (/-256(color)?$/i.test(env.TERM)) {
16413
- return 2;
16414
- }
16415
-
16416
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
16417
- return 1;
16418
- }
16419
-
16420
- if ('COLORTERM' in env) {
16421
- return 1;
16422
- }
16423
-
16424
- return min;
16425
- }
16426
-
16427
- function getSupportLevel(stream) {
16428
- const level = supportsColor(stream, stream && stream.isTTY);
16429
- return translateLevel(level);
16430
- }
16431
-
16432
- supportsColor_1 = {
16433
- supportsColor: getSupportLevel,
16434
- stdout: translateLevel(supportsColor(true, tty.isatty(1))),
16435
- stderr: translateLevel(supportsColor(true, tty.isatty(2)))
16436
- };
16437
- return supportsColor_1;
16438
- }
16439
-
16440
- /**
16441
- * Module dependencies.
16442
- */
16443
-
16444
- var hasRequiredNode;
16445
-
16446
- function requireNode () {
16447
- if (hasRequiredNode) return node.exports;
16448
- hasRequiredNode = 1;
16449
- (function (module, exports) {
16450
- const tty = require$$1$1;
16451
- const util = require$$1;
16452
-
16453
- /**
16454
- * This is the Node.js implementation of `debug()`.
16455
- */
16456
-
16457
- exports.init = init;
16458
- exports.log = log;
16459
- exports.formatArgs = formatArgs;
16460
- exports.save = save;
16461
- exports.load = load;
16462
- exports.useColors = useColors;
16463
- exports.destroy = util.deprecate(
16464
- () => {},
16465
- 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
16466
- );
16467
-
16468
- /**
16469
- * Colors.
16470
- */
16471
-
16472
- exports.colors = [6, 2, 3, 4, 5, 1];
16473
-
16474
- try {
16475
- // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
16476
- // eslint-disable-next-line import/no-extraneous-dependencies
16477
- const supportsColor = requireSupportsColor();
16478
-
16479
- if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
16480
- exports.colors = [
16481
- 20,
16482
- 21,
16483
- 26,
16484
- 27,
16485
- 32,
16486
- 33,
16487
- 38,
16488
- 39,
16489
- 40,
16490
- 41,
16491
- 42,
16492
- 43,
16493
- 44,
16494
- 45,
16495
- 56,
16496
- 57,
16497
- 62,
16498
- 63,
16499
- 68,
16500
- 69,
16501
- 74,
16502
- 75,
16503
- 76,
16504
- 77,
16505
- 78,
16506
- 79,
16507
- 80,
16508
- 81,
16509
- 92,
16510
- 93,
16511
- 98,
16512
- 99,
16513
- 112,
16514
- 113,
16515
- 128,
16516
- 129,
16517
- 134,
16518
- 135,
16519
- 148,
16520
- 149,
16521
- 160,
16522
- 161,
16523
- 162,
16524
- 163,
16525
- 164,
16526
- 165,
16527
- 166,
16528
- 167,
16529
- 168,
16530
- 169,
16531
- 170,
16532
- 171,
16533
- 172,
16534
- 173,
16535
- 178,
16536
- 179,
16537
- 184,
16538
- 185,
16539
- 196,
16540
- 197,
16541
- 198,
16542
- 199,
16543
- 200,
16544
- 201,
16545
- 202,
16546
- 203,
16547
- 204,
16548
- 205,
16549
- 206,
16550
- 207,
16551
- 208,
16552
- 209,
16553
- 214,
16554
- 215,
16555
- 220,
16556
- 221
16557
- ];
16558
- }
16559
- } catch (error) {
16560
- // Swallow - we only care if `supports-color` is available; it doesn't have to be.
16561
- }
16562
-
16563
- /**
16564
- * Build up the default `inspectOpts` object from the environment variables.
16565
- *
16566
- * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
16567
- */
16568
-
16569
- exports.inspectOpts = Object.keys(process.env).filter(key => {
16570
- return /^debug_/i.test(key);
16571
- }).reduce((obj, key) => {
16572
- // Camel-case
16573
- const prop = key
16574
- .substring(6)
16575
- .toLowerCase()
16576
- .replace(/_([a-z])/g, (_, k) => {
16577
- return k.toUpperCase();
16578
- });
16579
-
16580
- // Coerce string value into JS value
16581
- let val = process.env[key];
16582
- if (/^(yes|on|true|enabled)$/i.test(val)) {
16583
- val = true;
16584
- } else if (/^(no|off|false|disabled)$/i.test(val)) {
16585
- val = false;
16586
- } else if (val === 'null') {
16587
- val = null;
16588
- } else {
16589
- val = Number(val);
16590
- }
16591
-
16592
- obj[prop] = val;
16593
- return obj;
16594
- }, {});
16595
-
16596
- /**
16597
- * Is stdout a TTY? Colored output is enabled when `true`.
16598
- */
16599
-
16600
- function useColors() {
16601
- return 'colors' in exports.inspectOpts ?
16602
- Boolean(exports.inspectOpts.colors) :
16603
- tty.isatty(process.stderr.fd);
16604
- }
16605
-
16606
- /**
16607
- * Adds ANSI color escape codes if enabled.
16608
- *
16609
- * @api public
16610
- */
16611
-
16612
- function formatArgs(args) {
16613
- const {namespace: name, useColors} = this;
16614
-
16615
- if (useColors) {
16616
- const c = this.color;
16617
- const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
16618
- const prefix = ` ${colorCode};1m${name} \u001B[0m`;
16619
-
16620
- args[0] = prefix + args[0].split('\n').join('\n' + prefix);
16621
- args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
16622
- } else {
16623
- args[0] = getDate() + name + ' ' + args[0];
16624
- }
16625
- }
16626
-
16627
- function getDate() {
16628
- if (exports.inspectOpts.hideDate) {
16629
- return '';
16630
- }
16631
- return new Date().toISOString() + ' ';
16632
- }
16633
-
16634
- /**
16635
- * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
16636
- */
16637
-
16638
- function log(...args) {
16639
- return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
16640
- }
16641
-
16642
- /**
16643
- * Save `namespaces`.
16644
- *
16645
- * @param {String} namespaces
16646
- * @api private
16647
- */
16648
- function save(namespaces) {
16649
- if (namespaces) {
16650
- process.env.DEBUG = namespaces;
16651
- } else {
16652
- // If you set a process.env field to null or undefined, it gets cast to the
16653
- // string 'null' or 'undefined'. Just delete instead.
16654
- delete process.env.DEBUG;
16655
- }
16656
- }
16657
-
16658
- /**
16659
- * Load `namespaces`.
16660
- *
16661
- * @return {String} returns the previously persisted debug modes
16662
- * @api private
16663
- */
16664
-
16665
- function load() {
16666
- return process.env.DEBUG;
16667
- }
16668
-
16669
- /**
16670
- * Init logic for `debug` instances.
16671
- *
16672
- * Create a new `inspectOpts` object in case `useColors` is set
16673
- * differently for a particular `debug` instance.
16674
- */
16675
-
16676
- function init(debug) {
16677
- debug.inspectOpts = {};
16678
-
16679
- const keys = Object.keys(exports.inspectOpts);
16680
- for (let i = 0; i < keys.length; i++) {
16681
- debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
16682
- }
16683
- }
16684
-
16685
- module.exports = requireCommon()(exports);
16686
-
16687
- const {formatters} = module.exports;
16688
-
16689
- /**
16690
- * Map %o to `util.inspect()`, all on a single line.
16691
- */
16692
-
16693
- formatters.o = function (v) {
16694
- this.inspectOpts.colors = this.useColors;
16695
- return util.inspect(v, this.inspectOpts)
16696
- .split('\n')
16697
- .map(str => str.trim())
16698
- .join(' ');
16699
- };
16700
-
16701
- /**
16702
- * Map %O to `util.inspect()`, allowing multiple lines if needed.
16703
- */
16704
-
16705
- formatters.O = function (v) {
16706
- this.inspectOpts.colors = this.useColors;
16707
- return util.inspect(v, this.inspectOpts);
16708
- };
16709
- } (node, node.exports));
16710
- return node.exports;
16711
- }
16712
-
16713
- /**
16714
- * Detect Electron renderer / nwjs process, which is node, but we should
16715
- * treat as a browser.
16716
- */
16717
-
16718
- var hasRequiredSrc;
16719
-
16720
- function requireSrc () {
16721
- if (hasRequiredSrc) return src.exports;
16722
- hasRequiredSrc = 1;
16723
- if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
16724
- src.exports = requireBrowser();
16725
- } else {
16726
- src.exports = requireNode();
16727
- }
16728
- return src.exports;
16729
- }
16730
-
16731
15538
  var debug_1;
16732
15539
  var hasRequiredDebug;
16733
15540
 
@@ -16740,7 +15547,7 @@ function requireDebug () {
16740
15547
  if (!debug) {
16741
15548
  try {
16742
15549
  /* eslint global-require: off */
16743
- debug = requireSrc()("follow-redirects");
15550
+ debug = require("debug")("follow-redirects");
16744
15551
  }
16745
15552
  catch (error) { /* */ }
16746
15553
  if (typeof debug !== "function") {
@@ -20164,8 +18971,6 @@ class AtlasClient {
20164
18971
  }
20165
18972
  }
20166
18973
 
20167
- // src/lib/client.ts
20168
- let consulClient = null;
20169
18974
  let atlasClient = null;
20170
18975
  function toBoolean(value) {
20171
18976
  if (typeof value === 'boolean')
@@ -20174,25 +18979,12 @@ function toBoolean(value) {
20174
18979
  return value.toLowerCase() === 'true';
20175
18980
  return false;
20176
18981
  }
20177
- function initClient({ host = '127.0.0.1', port = 8500, secure = false }) {
18982
+ function initClient({ host = '127.0.0.1', port = 3371, secure = false }) {
20178
18983
  atlasClient = new AtlasClient({
20179
18984
  host: host !== null && host !== void 0 ? host : '127.0.0.1',
20180
- port: 371,
18985
+ port,
20181
18986
  version: '1',
20182
18987
  });
20183
- consulClient = new Consul({
20184
- host: host !== null && host !== void 0 ? host : '127.0.0.1',
20185
- port: port !== null && port !== void 0 ? port : 8500,
20186
- secure: toBoolean(secure),
20187
- });
20188
- consulClient.agent.self(err => {
20189
- if (err) {
20190
- console.error('❌ Failed to connect to Consul:', err.message);
20191
- }
20192
- else {
20193
- console.log('✅ Connected to Consul successfully');
20194
- }
20195
- });
20196
18988
  }
20197
18989
  function getAtlasClient() {
20198
18990
  if (!atlasClient) {
@@ -20200,61 +18992,19 @@ function getAtlasClient() {
20200
18992
  }
20201
18993
  return atlasClient;
20202
18994
  }
20203
- function getClient() {
20204
- if (!consulClient) {
20205
- throw new Error('Consul client not initialized. Call initClient() first.');
20206
- }
20207
- return consulClient;
20208
- }
20209
18995
 
20210
- const registeredServices = new Set();
20211
18996
  async function registerService(options) {
20212
- var _a, _b, _c, _d;
20213
- const { name, id, port, address = 'localhost', check, tags, meta } = options;
18997
+ const { name, port, address = 'localhost', tags, meta } = options;
20214
18998
  const atlasClient = getAtlasClient();
20215
- await atlasClient.registerService({
18999
+ await atlasClient
19000
+ .registerService({
20216
19001
  address,
20217
19002
  port,
20218
19003
  name,
20219
- }).then((res) => {
20220
- console.log("🚀 ~ registerService ~ res:", res);
19004
+ })
19005
+ .then(res => {
19006
+ console.log("Service Registered");
20221
19007
  });
20222
- if (registeredServices.has(id)) {
20223
- console.log(`⚠️ Service "${id}" is already registered.`);
20224
- return;
20225
- }
20226
- const serviceDefinition = {
20227
- name,
20228
- id,
20229
- address,
20230
- port,
20231
- tags,
20232
- meta,
20233
- };
20234
- if (check !== false) {
20235
- const checkDefinition = {
20236
- name: (_a = check === null || check === void 0 ? void 0 : check.name) !== null && _a !== void 0 ? _a : `${name}-check`,
20237
- http: (_b = check === null || check === void 0 ? void 0 : check.http) !== null && _b !== void 0 ? _b : `http://${address}:${port}/health`,
20238
- interval: (_c = check === null || check === void 0 ? void 0 : check.interval) !== null && _c !== void 0 ? _c : '10s',
20239
- timeout: (_d = check === null || check === void 0 ? void 0 : check.timeout) !== null && _d !== void 0 ? _d : '5s',
20240
- };
20241
- if (check === null || check === void 0 ? void 0 : check.deregistercriticalserviceafter) {
20242
- checkDefinition.deregistercriticalserviceafter = check.deregistercriticalserviceafter;
20243
- }
20244
- serviceDefinition.check = checkDefinition;
20245
- }
20246
- await getClient().agent.service.register(serviceDefinition);
20247
- registeredServices.add(id);
20248
- console.log(`✅ Service "${id}" registered successfully.`);
20249
- }
20250
- async function deregisterService(id) {
20251
- if (!registeredServices.has(id)) {
20252
- console.log(`⚠️ Service "${id}" is not registered.`);
20253
- return;
20254
- }
20255
- await getClient().agent.service.deregister(id);
20256
- registeredServices.delete(id);
20257
- console.log(`🛑 Service "${id}" deregistered successfully.`);
20258
19008
  }
20259
19009
 
20260
19010
  const BASE_LOG_DIR$2 = '/home/log';
@@ -20264,12 +19014,12 @@ async function ensureLogDir$2(dir) {
20264
19014
  await require$$6.promises.mkdir(dir, { recursive: true });
20265
19015
  }
20266
19016
  function formatLogLine(targetService, instance, elapsedMs) {
20267
- var _a, _b, _c, _d, _e;
19017
+ var _a, _b, _c, _d;
20268
19018
  const ts = new Date().toISOString();
20269
- const addr = (_b = (_a = instance.ServiceAddress) !== null && _a !== void 0 ? _a : instance.Address) !== null && _b !== void 0 ? _b : 'unknown';
20270
- const port = (_c = instance.ServicePort) !== null && _c !== void 0 ? _c : 'unknown';
20271
- const node = (_d = instance.Node) !== null && _d !== void 0 ? _d : 'N/A';
20272
- const id = (_e = instance.ServiceID) !== null && _e !== void 0 ? _e : 'N/A';
19019
+ const addr = (_a = instance.address) !== null && _a !== void 0 ? _a : 'unknown';
19020
+ const port = (_b = instance.port) !== null && _b !== void 0 ? _b : 'unknown';
19021
+ const node = (_c = instance.Node) !== null && _c !== void 0 ? _c : 'N/A';
19022
+ const id = (_d = instance.ServiceID) !== null && _d !== void 0 ? _d : 'N/A';
20273
19023
  const elapsed = elapsedMs !== undefined ? ` | Elapsed=${elapsedMs}ms` : '';
20274
19024
  return `${ts} | Target=${targetService} | ${addr}:${port} | Node=${node} | ID=${id}${elapsed}\n`;
20275
19025
  }
@@ -20314,29 +19064,33 @@ function get(key) {
20314
19064
  return record.value;
20315
19065
  }
20316
19066
 
20317
- const CACHE_TTL = 60000;
19067
+ const CACHE_TTL = 60000; // 1 دقيقة
19068
+ // جلب كل الخدمات
20318
19069
  async function listServices() {
20319
19070
  const cacheKey = 'services:list';
20320
19071
  const cached = get(cacheKey);
20321
19072
  if (cached)
20322
19073
  return cached;
20323
- const services = await getClient().agent.service.list();
20324
- const values = Object.values(services);
20325
- set(cacheKey, values, CACHE_TTL);
20326
- return values;
19074
+ const services = await getAtlasClient().listServices();
19075
+ set(cacheKey, services, CACHE_TTL);
19076
+ return services;
20327
19077
  }
19078
+ // جلب كل الـ instances لسيرفس معين
20328
19079
  async function getServiceInstances(serviceName) {
20329
19080
  const cacheKey = `services:${serviceName}`;
20330
19081
  const cached = get(cacheKey);
20331
19082
  if (cached)
20332
19083
  return cached;
20333
19084
  const start = Date.now();
20334
- const services = await getClient().catalog.service.nodes(serviceName);
19085
+ const services = await getAtlasClient().listServices(); // هنجيب كل السيرفسات
20335
19086
  const elapsed = Date.now() - start;
20336
19087
  console.log(`⏱️ Discovery for ${serviceName} took ${elapsed}ms`);
20337
- set(cacheKey, services, CACHE_TTL);
20338
- return services;
19088
+ // فلترة السيرفس المطلوب
19089
+ const instances = services.filter(s => s.name === serviceName);
19090
+ set(cacheKey, instances, CACHE_TTL);
19091
+ return instances;
20339
19092
  }
19093
+ // جلب instance عشوائي لسيرفس معين
20340
19094
  async function getRandomServiceInstance(serviceName) {
20341
19095
  const cacheKey = `random:${serviceName}`;
20342
19096
  const cached = get(cacheKey);
@@ -20350,18 +19104,17 @@ async function getRandomServiceInstance(serviceName) {
20350
19104
  const instance = instances[randomIndex];
20351
19105
  const elapsed = Date.now() - start;
20352
19106
  await appendDiscoveryLog(serviceName, instance, elapsed);
20353
- // cache random instance
20354
19107
  set(cacheKey, instance, CACHE_TTL);
20355
19108
  return instance;
20356
19109
  }
19110
+ // جلب URL جاهز للاتصال
20357
19111
  async function getServiceUrl(serviceName) {
20358
19112
  const cacheKey = `url:${serviceName}`;
20359
19113
  const cached = get(cacheKey);
20360
19114
  if (cached)
20361
19115
  return cached;
20362
19116
  const instance = await getRandomServiceInstance(serviceName);
20363
- const url = `http://${instance.ServiceAddress}:${instance.ServicePort}`;
20364
- // cache url
19117
+ const url = `http://${instance.address}:${instance.port}`;
20365
19118
  set(cacheKey, url, CACHE_TTL);
20366
19119
  return url;
20367
19120
  }
@@ -20435,7 +19188,7 @@ async function callService(serviceName, options = {}) {
20435
19188
  const start = Date.now();
20436
19189
  try {
20437
19190
  const instance = await getRandomServiceInstance(serviceName);
20438
- const url = `http://${instance.ServiceAddress}:${instance.ServicePort}${path}`;
19191
+ const url = `http://${instance.address}:${instance.port}${path}`;
20439
19192
  const response = await axios.request({ url, method, data, headers, params });
20440
19193
  const elapsed = Date.now() - start;
20441
19194
  // 📌 سجل الكول
@@ -20624,9 +19377,7 @@ async function dataLink(data, schema) {
20624
19377
 
20625
19378
  exports.callService = callService;
20626
19379
  exports.dataLink = dataLink;
20627
- exports.deregisterService = deregisterService;
20628
19380
  exports.getAtlasClient = getAtlasClient;
20629
- exports.getClient = getClient;
20630
19381
  exports.getRandomServiceInstance = getRandomServiceInstance;
20631
19382
  exports.getServiceInstances = getServiceInstances;
20632
19383
  exports.getServiceUrl = getServiceUrl;