GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Exceptionless.JavaScript/dist/exceptionless.node.js at master · wanglong/Exceptionless.JavaScript Expand file tree/ Copy pathexceptionless.node.jsMore file actions 2298 lines (2298 loc) · 87.2 KB / Copy pathexceptionless.node.jsFile metadata and controls2298 lines (2298 loc) · 87.2 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var os = require("os"); var nodestacktrace = require("stack-trace"); var child = require("child_process"); var path = require("path"); var Fs = require("fs"); var Path = require("path"); var http = require("http"); var https = require("https"); var url = require("url"); var DefaultLastReferenceIdManager = (function () { function DefaultLastReferenceIdManager() { this._lastReferenceId = null; } DefaultLastReferenceIdManager.prototype.getLast = function () { return this._lastReferenceId; }; DefaultLastReferenceIdManager.prototype.clearLast = function () { this._lastReferenceId = null; }; DefaultLastReferenceIdManager.prototype.setLast = function (eventId) { this._lastReferenceId = eventId; }; return DefaultLastReferenceIdManager; }()); exports.DefaultLastReferenceIdManager = DefaultLastReferenceIdManager; var ConsoleLog = (function () { function ConsoleLog() { } ConsoleLog.prototype.trace = function (message) { this.log('debug', message); }; ConsoleLog.prototype.info = function (message) { this.log('info', message); }; ConsoleLog.prototype.warn = function (message) { this.log('warn', message); }; ConsoleLog.prototype.error = function (message) { this.log('error', message); }; ConsoleLog.prototype.log = function (level, message) { if (console) { var msg = "[" + level + "] Exceptionless: " + message; if (console[level]) { console[level](msg); } else if (console.log) { console["log"](msg); } } }; return ConsoleLog; }()); exports.ConsoleLog = ConsoleLog; var NullLog = (function () { function NullLog() { } NullLog.prototype.trace = function (message) { }; NullLog.prototype.info = function (message) { }; NullLog.prototype.warn = function (message) { }; NullLog.prototype.error = function (message) { }; return NullLog; }()); exports.NullLog = NullLog; var HeartbeatPlugin = (function () { function HeartbeatPlugin(heartbeatInterval) { if (heartbeatInterval === void 0) { heartbeatInterval = 30000; } this.priority = 100; this.name = 'HeartbeatPlugin'; this._interval = heartbeatInterval >= 30000 ? heartbeatInterval : 60000; } HeartbeatPlugin.prototype.run = function (context, next) { clearInterval(this._intervalId); var user = context.event.data['@user']; if (user && user.identity) { this._intervalId = setInterval(function () { return context.client.submitSessionHeartbeat(user.identity); }, this._interval); } next && next(); }; return HeartbeatPlugin; }()); exports.HeartbeatPlugin = HeartbeatPlugin; var ReferenceIdPlugin = (function () { function ReferenceIdPlugin() { this.priority = 20; this.name = 'ReferenceIdPlugin'; } ReferenceIdPlugin.prototype.run = function (context, next) { if ((!context.event.reference_id || context.event.reference_id.length === 0) && context.event.type === 'error') { context.event.reference_id = Utils.guid().replace('-', '').substring(0, 10); } next && next(); }; return ReferenceIdPlugin; }()); exports.ReferenceIdPlugin = ReferenceIdPlugin; var EventPluginContext = (function () { function EventPluginContext(client, event, contextData) { this.client = client; this.event = event; this.contextData = contextData ? contextData : new ContextData(); } Object.defineProperty(EventPluginContext.prototype, "log", { get: function () { return this.client.config.log; }, enumerable: true, configurable: true }); return EventPluginContext; }()); exports.EventPluginContext = EventPluginContext; var EventPluginManager = (function () { function EventPluginManager() { } EventPluginManager.run = function (context, callback) { var wrap = function (plugin, next) { return function () { try { if (!context.cancelled) { plugin.run(context, next); } } catch (ex) { context.cancelled = true; context.log.error("Error running plugin '" + plugin.name + "': " + ex.message + ". Discarding Event."); } if (context.cancelled && !!callback) { callback(context); } }; }; var plugins = context.client.config.plugins; var wrappedPlugins = []; if (!!callback) { wrappedPlugins[plugins.length] = wrap({ name: 'cb', priority: 9007199254740992, run: callback }, null); } for (var index = plugins.length - 1; index > -1; index--) { wrappedPlugins[index] = wrap(plugins[index], !!callback || (index < plugins.length - 1) ? wrappedPlugins[index + 1] : null); } wrappedPlugins[0](); }; EventPluginManager.addDefaultPlugins = function (config) { config.addPlugin(new ConfigurationDefaultsPlugin()); config.addPlugin(new ErrorPlugin()); config.addPlugin(new DuplicateCheckerPlugin()); config.addPlugin(new EventExclusionPlugin()); config.addPlugin(new ModuleInfoPlugin()); config.addPlugin(new RequestInfoPlugin()); config.addPlugin(new EnvironmentInfoPlugin()); config.addPlugin(new SubmissionMethodPlugin()); }; return EventPluginManager; }()); exports.EventPluginManager = EventPluginManager; var DefaultEventQueue = (function () { function DefaultEventQueue(config) { this._handlers = []; this._processingQueue = false; this._config = config; } DefaultEventQueue.prototype.enqueue = function (event) { var eventWillNotBeQueued = 'The event will not be queued.'; var config = this._config; var log = config.log; if (!config.enabled) { log.info("Configuration is disabled. " + eventWillNotBeQueued); return; } if (!config.isValid) { log.info("Invalid Api Key. " + eventWillNotBeQueued); return; } if (this.areQueuedItemsDiscarded()) { log.info("Queue items are currently being discarded. " + eventWillNotBeQueued); return; } this.ensureQueueTimer(); var timestamp = config.storage.queue.save(event); var logText = "type=" + event.type + " " + (!!event.reference_id ? 'refid=' + event.reference_id : ''); if (timestamp) { log.info("Enqueuing event: " + timestamp + " " + logText); } else { log.error("Could not enqueue event " + logText); } }; DefaultEventQueue.prototype.process = function (isAppExiting) { var _this = this; var queueNotProcessed = 'The queue will not be processed.'; var config = this._config; var log = config.log; if (this._processingQueue) { return; } log.info('Processing queue...'); if (!config.enabled) { log.info("Configuration is disabled. " + queueNotProcessed); return; } if (!config.isValid) { log.info("Invalid Api Key. " + queueNotProcessed); return; } this._processingQueue = true; this.ensureQueueTimer(); try { var events_1 = config.storage.queue.get(config.submissionBatchSize); if (!events_1 || events_1.length === 0) { this._processingQueue = false; return; } log.info("Sending " + events_1.length + " events to " + config.serverUrl + "."); config.submissionClient.postEvents(events_1.map(function (e) { return e.value; }), config, function (response) { _this.processSubmissionResponse(response, events_1); _this.eventsPosted(events_1.map(function (e) { return e.value; }), response); log.info('Finished processing queue.'); _this._processingQueue = false; }, isAppExiting); } catch (ex) { log.error("Error processing queue: " + ex); this.suspendProcessing(); this._processingQueue = false; } }; DefaultEventQueue.prototype.suspendProcessing = function (durationInMinutes, discardFutureQueuedItems, clearQueue) { var config = this._config; if (!durationInMinutes || durationInMinutes <= 0) { durationInMinutes = 5; } config.log.info("Suspending processing for " + durationInMinutes + " minutes."); this._suspendProcessingUntil = new Date(new Date().getTime() + (durationInMinutes * 60000)); if (discardFutureQueuedItems) { this._discardQueuedItemsUntil = this._suspendProcessingUntil; } if (clearQueue) { config.storage.queue.clear(); } }; DefaultEventQueue.prototype.onEventsPosted = function (handler) { !!handler && this._handlers.push(handler); }; DefaultEventQueue.prototype.eventsPosted = function (events, response) { var handlers = this._handlers; for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { var handler = handlers_1[_i]; try { handler(events, response); } catch (ex) { this._config.log.error("Error calling onEventsPosted handler: " + ex); } } }; DefaultEventQueue.prototype.areQueuedItemsDiscarded = function () { return this._discardQueuedItemsUntil && this._discardQueuedItemsUntil > new Date(); }; DefaultEventQueue.prototype.ensureQueueTimer = function () { var _this = this; if (!this._queueTimer) { this._queueTimer = setInterval(function () { return _this.onProcessQueue(); }, 10000); } }; DefaultEventQueue.prototype.isQueueProcessingSuspended = function () { return this._suspendProcessingUntil && this._suspendProcessingUntil > new Date(); }; DefaultEventQueue.prototype.onProcessQueue = function () { if (!this.isQueueProcessingSuspended() && !this._processingQueue) { this.process(); } }; DefaultEventQueue.prototype.processSubmissionResponse = function (response, events) { var noSubmission = 'The event will not be submitted.'; var config = this._config; var log = config.log; if (response.success) { log.info("Sent " + events.length + " events."); this.removeEvents(events); return; } if (response.serviceUnavailable) { log.error('Server returned service unavailable.'); this.suspendProcessing(); return; } if (response.paymentRequired) { log.info('Too many events have been submitted, please upgrade your plan.'); this.suspendProcessing(null, true, true); return; } if (response.unableToAuthenticate) { log.info("Unable to authenticate, please check your configuration. " + noSubmission); this.suspendProcessing(15); this.removeEvents(events); return; } if (response.notFound || response.badRequest) { log.error("Error while trying to submit data: " + response.message); this.suspendProcessing(60 * 4); this.removeEvents(events); return; } if (response.requestEntityTooLarge) { var message = 'Event submission discarded for being too large.'; if (config.submissionBatchSize > 1) { log.error(message + " Retrying with smaller batch size."); config.submissionBatchSize = Math.max(1, Math.round(config.submissionBatchSize / 1.5)); } else { log.error(message + " " + noSubmission); this.removeEvents(events); } return; } if (!response.success) { log.error("Error submitting events: " + (response.message || 'Please check the network tab for more info.')); this.suspendProcessing(); } }; DefaultEventQueue.prototype.removeEvents = function (events) { for (var index = 0; index < (events || []).length; index++) { this._config.storage.queue.remove(events[index].timestamp); } }; return DefaultEventQueue; }()); exports.DefaultEventQueue = DefaultEventQueue; var InMemoryStorageProvider = (function () { function InMemoryStorageProvider(maxQueueItems) { if (maxQueueItems === void 0) { maxQueueItems = 250; } this.queue = new InMemoryStorage(maxQueueItems); this.settings = new InMemoryStorage(1); } return InMemoryStorageProvider; }()); exports.InMemoryStorageProvider = InMemoryStorageProvider; var DefaultSubmissionClient = (function () { function DefaultSubmissionClient() { this.configurationVersionHeader = 'x-exceptionless-configversion'; } DefaultSubmissionClient.prototype.postEvents = function (events, config, callback, isAppExiting) { var data = JSON.stringify(events); var request = this.createRequest(config, 'POST', config.serverUrl + "/api/v2/events", data); var cb = this.createSubmissionCallback(config, callback); return config.submissionAdapter.sendRequest(request, cb, isAppExiting); }; DefaultSubmissionClient.prototype.postUserDescription = function (referenceId, description, config, callback) { var path = config.serverUrl + "/api/v2/events/by-ref/" + encodeURIComponent(referenceId) + "/user-description"; var data = JSON.stringify(description); var request = this.createRequest(config, 'POST', path, data); var cb = this.createSubmissionCallback(config, callback); return config.submissionAdapter.sendRequest(request, cb); }; DefaultSubmissionClient.prototype.getSettings = function (config, version, callback) { var request = this.createRequest(config, 'GET', config.configServerUrl + "/api/v2/projects/config?v=" + version); var cb = function (status, message, data, headers) { if (status !== 200) { return callback(new SettingsResponse(false, null, -1, null, message)); } var settings; try { settings = JSON.parse(data); } catch (e) { config.log.error("Unable to parse settings: '" + data + "'"); } if (!settings || isNaN(settings.version)) { return callback(new SettingsResponse(false, null, -1, null, 'Invalid configuration settings.')); } callback(new SettingsResponse(true, settings.settings || {}, settings.version)); }; return config.submissionAdapter.sendRequest(request, cb); }; DefaultSubmissionClient.prototype.sendHeartbeat = function (sessionIdOrUserId, closeSession, config) { var request = this.createRequest(config, 'GET', config.heartbeatServerUrl + "/api/v2/events/session/heartbeat?id=" + sessionIdOrUserId + "&close=" + closeSession); config.submissionAdapter.sendRequest(request); }; DefaultSubmissionClient.prototype.createRequest = function (config, method, url, data) { if (data === void 0) { data = null; } return { method: method, url: url, data: data, apiKey: config.apiKey, userAgent: config.userAgent }; }; DefaultSubmissionClient.prototype.createSubmissionCallback = function (config, callback) { var _this = this; return function (status, message, data, headers) { var settingsVersion = headers && parseInt(headers[_this.configurationVersionHeader], 10); if (!isNaN(settingsVersion)) { SettingsManager.checkVersion(settingsVersion, config); } else { config.log.error('No config version header was returned.'); } callback(new SubmissionResponse(status, message)); }; }; return DefaultSubmissionClient; }()); exports.DefaultSubmissionClient = DefaultSubmissionClient; var Utils = (function () { function Utils() { } Utils.addRange = function (target) { var values = []; for (var _i = 1; _i < arguments.length; _i++) { values[_i - 1] = arguments[_i]; } if (!target) { target = []; } if (!values || values.length === 0) { return target; } for (var _a = 0, values_1 = values; _a < values_1.length; _a++) { var value = values_1[_a]; if (value && target.indexOf(value) < 0) { target.push(value); } } return target; }; Utils.getHashCode = function (source) { if (!source || source.length === 0) { return 0; } var hash = 0; for (var index = 0; index < source.length; index++) { var character = source.charCodeAt(index); hash = ((hash << 5) - hash) + character; hash |= 0; } return hash; }; Utils.getCookies = function (cookies, exclusions) { var result = {}; var parts = (cookies || '').split('; '); for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) { var part = parts_1[_i]; var cookie = part.split('='); if (!Utils.isMatch(cookie[0], exclusions)) { result[cookie[0]] = cookie[1]; } } return !Utils.isEmpty(result) ? result : null; }; Utils.guid = function () { function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); }; Utils.merge = function (defaultValues, values) { var result = {}; for (var key in defaultValues || {}) { if (defaultValues[key] !== undefined && defaultValues[key] !== null) { result[key] = defaultValues[key]; } } for (var key in values || {}) { if (values[key] !== undefined && values[key] !== null) { result[key] = values[key]; } } return result; }; Utils.parseVersion = function (source) { if (!source) { return null; } var versionRegex = /(v?((\d+)\.(\d+)(\.(\d+))?)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?)/; var matches = versionRegex.exec(source); if (matches && matches.length > 0) { return matches[0]; } return null; }; Utils.parseQueryString = function (query, exclusions) { if (!query || query.length === 0) { return null; } var pairs = query.split('&'); if (pairs.length === 0) { return null; } var result = {}; for (var _i = 0, pairs_1 = pairs; _i < pairs_1.length; _i++) { var pair = pairs_1[_i]; var parts = pair.split('='); if (!Utils.isMatch(parts[0], exclusions)) { result[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); } } return !Utils.isEmpty(result) ? result : null; }; Utils.randomNumber = function () { return Math.floor(Math.random() * 9007199254740992); }; Utils.isMatch = function (input, patterns, ignoreCase) { if (ignoreCase === void 0) { ignoreCase = true; } if (!input || typeof input !== 'string') { return false; } var trim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; input = (ignoreCase ? input.toLowerCase() : input).replace(trim, ''); return (patterns || []).some(function (pattern) { if (typeof pattern !== 'string') { return false; } pattern = (ignoreCase ? pattern.toLowerCase() : pattern).replace(trim, ''); if (pattern.length <= 0) { return false; } var startsWithWildcard = pattern[0] === '*'; if (startsWithWildcard) { pattern = pattern.slice(1); } var endsWithWildcard = pattern[pattern.length - 1] === '*'; if (endsWithWildcard) { pattern = pattern.substring(0, pattern.length - 1); } if (startsWithWildcard && endsWithWildcard) { return pattern.length <= input.length && input.indexOf(pattern, 0) !== -1; } if (startsWithWildcard) { return Utils.endsWith(input, pattern); } if (endsWithWildcard) { return Utils.startsWith(input, pattern); } return input === pattern; }); }; Utils.isEmpty = function (input) { return input === null || (typeof (input) === 'object' && Object.keys(input).length === 0); }; Utils.startsWith = function (input, prefix) { return input.substring(0, prefix.length) === prefix; }; Utils.endsWith = function (input, suffix) { return input.indexOf(suffix, input.length - suffix.length) !== -1; }; Utils.stringify = function (data, exclusions, maxDepth) { function stringifyImpl(obj, excludedKeys) { var cache = []; return JSON.stringify(obj, function (key, value) { if (Utils.isMatch(key, excludedKeys)) { return; } if (typeof value === 'object' && !!value) { if (cache.indexOf(value) !== -1) { return; } cache.push(value); } return value; }); } if (({}).toString.call(data) === '[object Object]') { var flattened = {}; for (var prop in data) { var value = data[prop]; if (value === data) { continue; } flattened[prop] = data[prop]; } return stringifyImpl(flattened, exclusions); } if (({}).toString.call(data) === '[object Array]') { var result = []; for (var index = 0; index < data.length; index++) { result[index] = JSON.parse(stringifyImpl(data[index], exclusions)); } return JSON.stringify(result); } return stringifyImpl(data, exclusions); }; Utils.toBoolean = function (input, defaultValue) { if (defaultValue === void 0) { defaultValue = false; } if (typeof input === 'boolean') { return input; } if (input === null || typeof input !== 'number' && typeof input !== 'string') { return defaultValue; } switch ((input + '').toLowerCase().trim()) { case 'true': case 'yes': case '1': return true; case 'false': case 'no': case '0': case null: return false; } return defaultValue; }; return Utils; }()); exports.Utils = Utils; var SettingsManager = (function () { function SettingsManager() { } SettingsManager.onChanged = function (handler) { !!handler && this._handlers.push(handler); }; SettingsManager.applySavedServerSettings = function (config) { if (!config || !config.isValid) { return; } var savedSettings = this.getSavedServerSettings(config); config.log.info("Applying saved settings: v" + savedSettings.version); config.settings = Utils.merge(config.settings, savedSettings.settings); this.changed(config); }; SettingsManager.getVersion = function (config) { if (!config || !config.isValid) { return 0; } var savedSettings = this.getSavedServerSettings(config); return savedSettings.version || 0; }; SettingsManager.checkVersion = function (version, config) { var currentVersion = this.getVersion(config); if (version <= currentVersion) { return; } config.log.info("Updating settings from v" + currentVersion + " to v" + version); this.updateSettings(config, currentVersion); }; SettingsManager.updateSettings = function (config, version) { var _this = this; if (!config || !config.enabled || this._isUpdatingSettings) { return; } var unableToUpdateMessage = 'Unable to update settings'; if (!config.isValid) { config.log.error(unableToUpdateMessage + ": ApiKey is not set."); return; } if (!version || version < 0) { version = this.getVersion(config); } config.log.info("Checking for updated settings from: v" + version + "."); this._isUpdatingSettings = true; config.submissionClient.getSettings(config, version, function (response) { try { if (!config || !response || !response.success || !response.settings) { config.log.warn(unableToUpdateMessage + ": " + response.message); return; } config.settings = Utils.merge(config.settings, response.settings); var savedServerSettings = SettingsManager.getSavedServerSettings(config); for (var key in savedServerSettings) { if (response.settings[key]) { continue; } delete config.settings[key]; } var newSettings = { version: response.settingsVersion, settings: response.settings }; config.storage.settings.save(newSettings); config.log.info("Updated settings: v" + newSettings.version); _this.changed(config); } finally { _this._isUpdatingSettings = false; } }); }; SettingsManager.changed = function (config) { var handlers = this._handlers; for (var _i = 0, handlers_2 = handlers; _i < handlers_2.length; _i++) { var handler = handlers_2[_i]; try { handler(config); } catch (ex) { config.log.error("Error calling onChanged handler: " + ex); } } }; SettingsManager.getSavedServerSettings = function (config) { var item = config.storage.settings.get()[0]; if (item && item.value && item.value.version && item.value.settings) { return item.value; } return { version: 0, settings: {} }; }; return SettingsManager; }()); SettingsManager._isUpdatingSettings = false; SettingsManager._handlers = []; exports.SettingsManager = SettingsManager; var SubmissionResponse = (function () { function SubmissionResponse(statusCode, message) { this.success = false; this.badRequest = false; this.serviceUnavailable = false; this.paymentRequired = false; this.unableToAuthenticate = false; this.notFound = false; this.requestEntityTooLarge = false; this.statusCode = statusCode; this.message = message; this.success = statusCode >= 200 && statusCode <= 299; this.badRequest = statusCode === 400; this.serviceUnavailable = statusCode === 503; this.paymentRequired = statusCode === 402; this.unableToAuthenticate = statusCode === 401 || statusCode === 403; this.notFound = statusCode === 404; this.requestEntityTooLarge = statusCode === 413; } return SubmissionResponse; }()); exports.SubmissionResponse = SubmissionResponse; var ExceptionlessClient = (function () { function ExceptionlessClient(settingsOrApiKey, serverUrl) { var _this = this; this.config = typeof settingsOrApiKey === 'object' ? new Configuration(settingsOrApiKey) : new Configuration({ apiKey: settingsOrApiKey, serverUrl: serverUrl }); this.updateSettingsTimer(5000); this.config.onChanged(function (config) { return _this.updateSettingsTimer(_this._timeoutId > 0 ? 5000 : 0); }); this.config.queue.onEventsPosted(function (events, response) { return _this.updateSettingsTimer(); }); } ExceptionlessClient.prototype.createException = function (exception) { var pluginContextData = new ContextData(); pluginContextData.setException(exception); return this.createEvent(pluginContextData).setType('error'); }; ExceptionlessClient.prototype.submitException = function (exception, callback) { this.createException(exception).submit(callback); }; ExceptionlessClient.prototype.createUnhandledException = function (exception, submissionMethod) { var builder = this.createException(exception); builder.pluginContextData.markAsUnhandledError(); builder.pluginContextData.setSubmissionMethod(submissionMethod); return builder; }; ExceptionlessClient.prototype.submitUnhandledException = function (exception, submissionMethod, callback) { this.createUnhandledException(exception, submissionMethod).submit(callback); }; ExceptionlessClient.prototype.createFeatureUsage = function (feature) { return this.createEvent().setType('usage').setSource(feature); }; ExceptionlessClient.prototype.submitFeatureUsage = function (feature, callback) { this.createFeatureUsage(feature).submit(callback); }; ExceptionlessClient.prototype.createLog = function (sourceOrMessage, message, level) { var builder = this.createEvent().setType('log'); if (level) { builder = builder.setSource(sourceOrMessage).setMessage(message).setProperty('@level', level); } else if (message) { builder = builder.setSource(sourceOrMessage).setMessage(message); } else { builder = builder.setMessage(sourceOrMessage); try { var caller = this.createLog.caller; builder = builder.setSource(caller && caller.caller && caller.caller.name); } catch (e) { this.config.log.trace('Unable to resolve log source: ' + e.message); } } return builder; }; ExceptionlessClient.prototype.submitLog = function (sourceOrMessage, message, level, callback) { this.createLog(sourceOrMessage, message, level).submit(callback); }; ExceptionlessClient.prototype.createNotFound = function (resource) { return this.createEvent().setType('404').setSource(resource); }; ExceptionlessClient.prototype.submitNotFound = function (resource, callback) { this.createNotFound(resource).submit(callback); }; ExceptionlessClient.prototype.createSessionStart = function () { return this.createEvent().setType('session'); }; ExceptionlessClient.prototype.submitSessionStart = function (callback) { this.createSessionStart().submit(callback); }; ExceptionlessClient.prototype.submitSessionEnd = function (sessionIdOrUserId) { if (sessionIdOrUserId) { this.config.log.info("Submitting session end: " + sessionIdOrUserId); this.config.submissionClient.sendHeartbeat(sessionIdOrUserId, true, this.config); } }; ExceptionlessClient.prototype.submitSessionHeartbeat = function (sessionIdOrUserId) { if (sessionIdOrUserId) { this.config.log.info("Submitting session heartbeat: " + sessionIdOrUserId); this.config.submissionClient.sendHeartbeat(sessionIdOrUserId, false, this.config); } }; ExceptionlessClient.prototype.createEvent = function (pluginContextData) { return new EventBuilder({ date: new Date() }, this, pluginContextData); }; ExceptionlessClient.prototype.submitEvent = function (event, pluginContextData, callback) { function cancelled(eventPluginContext) { if (!!eventPluginContext) { eventPluginContext.cancelled = true; } return !!callback && callback(eventPluginContext); } var context = new EventPluginContext(this, event, pluginContextData); if (!event) { return cancelled(context); } if (!this.config.enabled) { this.config.log.info('Event submission is currently disabled.'); return cancelled(context); } if (!event.data) { event.data = {}; } if (!event.tags || !event.tags.length) { event.tags = []; } EventPluginManager.run(context, function (ctx) { var config = ctx.client.config; var ev = ctx.event; if (!ctx.cancelled) { if (!ev.type || ev.type.length === 0) { ev.type = 'log'; } if (!ev.date) { ev.date = new Date(); } config.queue.enqueue(ev); if (ev.reference_id && ev.reference_id.length > 0) { ctx.log.info("Setting last reference id '" + ev.reference_id + "'"); config.lastReferenceIdManager.setLast(ev.reference_id); } } !!callback && callback(ctx); }); }; ExceptionlessClient.prototype.updateUserEmailAndDescription = function (referenceId, email, description, callback) { var _this = this; if (!referenceId || !email || !description || !this.config.enabled) { return !!callback && callback(new SubmissionResponse(500, 'cancelled')); } var userDescription = { email_address: email, description: description }; this.config.submissionClient.postUserDescription(referenceId, userDescription, this.config, function (response) { if (!response.success) { _this.config.log.error("Failed to submit user email and description for event '" + referenceId + "': " + response.statusCode + " " + response.message); } !!callback && callback(response); }); }; ExceptionlessClient.prototype.getLastReferenceId = function () { return this.config.lastReferenceIdManager.getLast(); }; ExceptionlessClient.prototype.updateSettingsTimer = function (initialDelay) { var _this = this; this.config.log.info("Updating settings timer with delay: " + initialDelay); this._timeoutId = clearTimeout(this._timeoutId); this._timeoutId = clearInterval(this._intervalId); var interval = this.config.updateSettingsWhenIdleInterval; if (interval > 0) { var updateSettings = function () { return SettingsManager.updateSettings(_this.config); }; if (initialDelay > 0) { this._timeoutId = setTimeout(updateSettings, initialDelay); } this._intervalId = setInterval(updateSettings, interval); } }; Object.defineProperty(ExceptionlessClient, "default", { get: function () { if (ExceptionlessClient._instance === null) { ExceptionlessClient._instance = new ExceptionlessClient(null); } return ExceptionlessClient._instance; }, enumerable: true, configurable: true }); return ExceptionlessClient; }()); ExceptionlessClient._instance = null; exports.ExceptionlessClient = ExceptionlessClient; var ContextData = (function () { function ContextData() { } ContextData.prototype.setException = function (exception) { if (exception) { this['@@_Exception'] = exception; } }; Object.defineProperty(ContextData.prototype, "hasException", { get: function () { return !!this['@@_Exception']; }, enumerable: true, configurable: true }); ContextData.prototype.getException = function () { return this['@@_Exception'] || null; }; ContextData.prototype.markAsUnhandledError = function () { this['@@_IsUnhandledError'] = true; }; Object.defineProperty(ContextData.prototype, "isUnhandledError", { get: function () { return !!this['@@_IsUnhandledError']; }, enumerable: true, configurable: true }); ContextData.prototype.setSubmissionMethod = function (method) { if (method) { this['@@_SubmissionMethod'] = method; } }; ContextData.prototype.getSubmissionMethod = function () { return this['@@_SubmissionMethod'] || null; }; return ContextData; }()); exports.ContextData = ContextData; var Configuration = (function () { function Configuration(configSettings) { this.defaultTags = []; this.defaultData = {}; this.enabled = true; this.lastReferenceIdManager = new DefaultLastReferenceIdManager(); this.settings = {}; this._serverUrl = 'https://collector.exceptionless.io'; this._configServerUrl = 'https://config.exceptionless.io'; this._heartbeatServerUrl = 'https://heartbeat.exceptionless.io'; this._updateSettingsWhenIdleInterval = 120000; this._dataExclusions = []; this._userAgentBotPatterns = []; this._plugins = []; this._handlers = []; function inject(fn) { return typeof fn === 'function' ? fn(this) : fn; } configSettings = Utils.merge(Configuration.defaults, configSettings); this.log = inject(configSettings.log) || new NullLog(); this.apiKey = configSettings.apiKey; this.serverUrl = configSettings.serverUrl; this.configServerUrl = configSettings.configServerUrl; this.heartbeatServerUrl = configSettings.heartbeatServerUrl; this.updateSettingsWhenIdleInterval = configSettings.updateSettingsWhenIdleInterval; this.includePrivateInformation = configSettings.includePrivateInformation; this.environmentInfoCollector = inject(configSettings.environmentInfoCollector); this.errorParser = inject(configSettings.errorParser); this.lastReferenceIdManager = inject(configSettings.lastReferenceIdManager) || new DefaultLastReferenceIdManager(); this.moduleCollector = inject(configSettings.moduleCollector); this.requestInfoCollector = inject(configSettings.requestInfoCollector); this.submissionBatchSize = inject(configSettings.submissionBatchSize) || 50; this.submissionAdapter = inject(configSettings.submissionAdapter); this.submissionClient = inject(configSettings.submissionClient) || new DefaultSubmissionClient(); this.storage = inject(configSettings.storage) || new InMemoryStorageProvider(); this.queue = inject(configSettings.queue) || new DefaultEventQueue(this); SettingsManager.applySavedServerSettings(this); EventPluginManager.addDefaultPlugins(this); } Object.defineProperty(Configuration.prototype, "apiKey", { get: function () { return this._apiKey; }, set: function (value) { this._apiKey = value || null; this.log.info("apiKey: " + this._apiKey); this.changed(); }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "isValid", { get: function () { return !!this.apiKey && this.apiKey.length >= 10; }, enumerable: true, configurable: true }); Object.defineProperty(Configuration.prototype, "serverUrl", { get: function () { |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |