construct-hub 0.4.430 → 0.4.431

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 (37) hide show
  1. package/.jsii +9 -9
  2. package/docs/operator-runbook.md +45 -0
  3. package/lib/backend/package-stats/index.d.ts +15 -2
  4. package/lib/backend/package-stats/index.js +79 -21
  5. package/lib/backend/package-stats/package-stats-aggregator.d.ts +7 -0
  6. package/lib/backend/package-stats/package-stats-aggregator.js +20 -0
  7. package/lib/backend/package-stats/package-stats-aggregator.lambda.bundle/index.js +62489 -0
  8. package/lib/backend/package-stats/{package-stats.lambda.bundle → package-stats-aggregator.lambda.bundle}/index.js.map +4 -4
  9. package/lib/backend/package-stats/package-stats-aggregator.lambda.d.ts +13 -0
  10. package/lib/backend/package-stats/package-stats-aggregator.lambda.js +78 -0
  11. package/lib/backend/package-stats/package-stats-chunker.d.ts +7 -0
  12. package/lib/backend/package-stats/package-stats-chunker.js +20 -0
  13. package/lib/backend/package-stats/package-stats-chunker.lambda.bundle/index.js +60075 -0
  14. package/lib/backend/package-stats/package-stats-chunker.lambda.bundle/index.js.map +7 -0
  15. package/lib/backend/package-stats/package-stats-chunker.lambda.d.ts +6 -0
  16. package/lib/backend/package-stats/package-stats-chunker.lambda.js +25 -0
  17. package/lib/backend/package-stats/package-stats-processor.d.ts +7 -0
  18. package/lib/backend/package-stats/package-stats-processor.js +20 -0
  19. package/lib/backend/package-stats/{package-stats.lambda.bundle → package-stats-processor.lambda.bundle}/index.js +36 -2556
  20. package/lib/backend/package-stats/package-stats-processor.lambda.bundle/index.js.map +7 -0
  21. package/lib/backend/package-stats/package-stats-processor.lambda.d.ts +10 -0
  22. package/lib/backend/package-stats/package-stats-processor.lambda.js +41 -0
  23. package/lib/backend-dashboard.js +8 -6
  24. package/lib/construct-hub.d.ts +1 -1
  25. package/lib/construct-hub.js +12 -4
  26. package/lib/package-sources/code-artifact.js +1 -1
  27. package/lib/package-sources/npmjs.js +1 -1
  28. package/lib/package-tag/index.js +3 -3
  29. package/lib/package-tag-group/index.js +2 -2
  30. package/lib/preload-file/index.js +1 -1
  31. package/lib/s3/storage.js +1 -1
  32. package/lib/spdx-license.js +1 -1
  33. package/package.json +7 -3
  34. package/lib/backend/package-stats/package-stats.d.ts +0 -7
  35. package/lib/backend/package-stats/package-stats.js +0 -20
  36. package/lib/backend/package-stats/package-stats.lambda.d.ts +0 -25
  37. package/lib/backend/package-stats/package-stats.lambda.js +0 -79
@@ -34704,7 +34704,7 @@ var require_dist_cjs70 = __commonJS({
34704
34704
  ];
34705
34705
  }).s("AmazonS3", "GetObjectAttributes", {}).n("S3Client", "GetObjectAttributesCommand").sc(GetObjectAttributes).build() {
34706
34706
  };
34707
- var GetObjectCommand2 = class extends smithyClient.Command.classBuilder().ep({
34707
+ var GetObjectCommand = class extends smithyClient.Command.classBuilder().ep({
34708
34708
  ...commonParams3,
34709
34709
  Bucket: { type: "contextParams", name: "Bucket" },
34710
34710
  Key: { type: "contextParams", name: "Key" }
@@ -35345,7 +35345,7 @@ var require_dist_cjs70 = __commonJS({
35345
35345
  GetBucketTaggingCommand,
35346
35346
  GetBucketVersioningCommand,
35347
35347
  GetBucketWebsiteCommand,
35348
- GetObjectCommand: GetObjectCommand2,
35348
+ GetObjectCommand,
35349
35349
  GetObjectAclCommand,
35350
35350
  GetObjectAttributesCommand,
35351
35351
  GetObjectLegalHoldCommand,
@@ -35586,7 +35586,7 @@ var require_dist_cjs70 = __commonJS({
35586
35586
  exports2.GetBucketWebsiteCommand = GetBucketWebsiteCommand;
35587
35587
  exports2.GetObjectAclCommand = GetObjectAclCommand;
35588
35588
  exports2.GetObjectAttributesCommand = GetObjectAttributesCommand;
35589
- exports2.GetObjectCommand = GetObjectCommand2;
35589
+ exports2.GetObjectCommand = GetObjectCommand;
35590
35590
  exports2.GetObjectLegalHoldCommand = GetObjectLegalHoldCommand;
35591
35591
  exports2.GetObjectLockConfigurationCommand = GetObjectLockConfigurationCommand;
35592
35592
  exports2.GetObjectRetentionCommand = GetObjectRetentionCommand;
@@ -35716,2388 +35716,6 @@ var require_dist_cjs70 = __commonJS({
35716
35716
  }
35717
35717
  });
35718
35718
 
35719
- // node_modules/aws-embedded-metrics/lib/Constants.js
35720
- var require_Constants = __commonJS({
35721
- "node_modules/aws-embedded-metrics/lib/Constants.js"(exports2) {
35722
- "use strict";
35723
- Object.defineProperty(exports2, "__esModule", { value: true });
35724
- exports2.Constants = void 0;
35725
- var Constants;
35726
- (function(Constants2) {
35727
- Constants2[Constants2["MAX_DIMENSION_SET_SIZE"] = 30] = "MAX_DIMENSION_SET_SIZE";
35728
- Constants2[Constants2["MAX_DIMENSION_NAME_LENGTH"] = 250] = "MAX_DIMENSION_NAME_LENGTH";
35729
- Constants2[Constants2["MAX_DIMENSION_VALUE_LENGTH"] = 1024] = "MAX_DIMENSION_VALUE_LENGTH";
35730
- Constants2[Constants2["MAX_METRIC_NAME_LENGTH"] = 1024] = "MAX_METRIC_NAME_LENGTH";
35731
- Constants2[Constants2["MAX_NAMESPACE_LENGTH"] = 256] = "MAX_NAMESPACE_LENGTH";
35732
- Constants2["VALID_NAMESPACE_REGEX"] = "^(?=.*\\S)[a-zA-Z0-9 ._#:/-]+$";
35733
- Constants2["VALID_DIMENSION_REGEX"] = "^[\0-\x7F]+$";
35734
- Constants2[Constants2["MAX_TIMESTAMP_PAST_AGE"] = 12096e5] = "MAX_TIMESTAMP_PAST_AGE";
35735
- Constants2[Constants2["MAX_TIMESTAMP_FUTURE_AGE"] = 72e5] = "MAX_TIMESTAMP_FUTURE_AGE";
35736
- Constants2["DEFAULT_NAMESPACE"] = "aws-embedded-metrics";
35737
- Constants2[Constants2["MAX_METRICS_PER_EVENT"] = 100] = "MAX_METRICS_PER_EVENT";
35738
- Constants2[Constants2["MAX_VALUES_PER_METRIC"] = 100] = "MAX_VALUES_PER_METRIC";
35739
- Constants2["DEFAULT_AGENT_HOST"] = "0.0.0.0";
35740
- Constants2[Constants2["DEFAULT_AGENT_PORT"] = 25888] = "DEFAULT_AGENT_PORT";
35741
- })(Constants = exports2.Constants || (exports2.Constants = {}));
35742
- }
35743
- });
35744
-
35745
- // node_modules/aws-embedded-metrics/lib/environment/Environments.js
35746
- var require_Environments = __commonJS({
35747
- "node_modules/aws-embedded-metrics/lib/environment/Environments.js"(exports2) {
35748
- "use strict";
35749
- Object.defineProperty(exports2, "__esModule", { value: true });
35750
- var Environments;
35751
- (function(Environments2) {
35752
- Environments2["Local"] = "Local";
35753
- Environments2["Lambda"] = "Lambda";
35754
- Environments2["Agent"] = "Agent";
35755
- Environments2["EC2"] = "EC2";
35756
- Environments2["ECS"] = "ECS";
35757
- Environments2["Unknown"] = "";
35758
- })(Environments || (Environments = {}));
35759
- exports2.default = Environments;
35760
- }
35761
- });
35762
-
35763
- // node_modules/aws-embedded-metrics/lib/config/EnvironmentConfigurationProvider.js
35764
- var require_EnvironmentConfigurationProvider = __commonJS({
35765
- "node_modules/aws-embedded-metrics/lib/config/EnvironmentConfigurationProvider.js"(exports2) {
35766
- "use strict";
35767
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
35768
- return mod && mod.__esModule ? mod : { "default": mod };
35769
- };
35770
- Object.defineProperty(exports2, "__esModule", { value: true });
35771
- exports2.EnvironmentConfigurationProvider = void 0;
35772
- var Constants_1 = require_Constants();
35773
- var Environments_1 = __importDefault2(require_Environments());
35774
- var ENV_VAR_PREFIX = "AWS_EMF";
35775
- var ConfigKeys;
35776
- (function(ConfigKeys2) {
35777
- ConfigKeys2["LOG_GROUP_NAME"] = "LOG_GROUP_NAME";
35778
- ConfigKeys2["LOG_STREAM_NAME"] = "LOG_STREAM_NAME";
35779
- ConfigKeys2["ENABLE_DEBUG_LOGGING"] = "ENABLE_DEBUG_LOGGING";
35780
- ConfigKeys2["SERVICE_NAME"] = "SERVICE_NAME";
35781
- ConfigKeys2["SERVICE_TYPE"] = "SERVICE_TYPE";
35782
- ConfigKeys2["AGENT_ENDPOINT"] = "AGENT_ENDPOINT";
35783
- ConfigKeys2["ENVIRONMENT_OVERRIDE"] = "ENVIRONMENT";
35784
- ConfigKeys2["NAMESPACE"] = "NAMESPACE";
35785
- })(ConfigKeys || (ConfigKeys = {}));
35786
- var EnvironmentConfigurationProvider = class {
35787
- getConfiguration() {
35788
- return {
35789
- agentEndpoint: this.getEnvVariable(ConfigKeys.AGENT_ENDPOINT),
35790
- debuggingLoggingEnabled: this.tryGetEnvVariableAsBoolean(ConfigKeys.ENABLE_DEBUG_LOGGING, false),
35791
- logGroupName: this.getEnvVariable(ConfigKeys.LOG_GROUP_NAME),
35792
- logStreamName: this.getEnvVariable(ConfigKeys.LOG_STREAM_NAME),
35793
- serviceName: this.getEnvVariable(ConfigKeys.SERVICE_NAME) || this.getEnvVariableWithoutPrefix(ConfigKeys.SERVICE_NAME),
35794
- serviceType: this.getEnvVariable(ConfigKeys.SERVICE_TYPE) || this.getEnvVariableWithoutPrefix(ConfigKeys.SERVICE_TYPE),
35795
- environmentOverride: this.getEnvironmentOverride(),
35796
- namespace: this.getEnvVariable(ConfigKeys.NAMESPACE) || Constants_1.Constants.DEFAULT_NAMESPACE
35797
- };
35798
- }
35799
- getEnvVariableWithoutPrefix(configKey) {
35800
- return process.env[configKey];
35801
- }
35802
- getEnvVariable(configKey) {
35803
- return process.env[`${ENV_VAR_PREFIX}_${configKey}`];
35804
- }
35805
- tryGetEnvVariableAsBoolean(configKey, fallback) {
35806
- const configValue = this.getEnvVariable(configKey);
35807
- return !configValue ? fallback : configValue.toLowerCase() === "true";
35808
- }
35809
- getEnvironmentOverride() {
35810
- const overrideValue = this.getEnvVariable(ConfigKeys.ENVIRONMENT_OVERRIDE);
35811
- const environment = Environments_1.default[overrideValue];
35812
- if (environment === void 0) {
35813
- return Environments_1.default.Unknown;
35814
- }
35815
- return environment;
35816
- }
35817
- };
35818
- exports2.EnvironmentConfigurationProvider = EnvironmentConfigurationProvider;
35819
- }
35820
- });
35821
-
35822
- // node_modules/aws-embedded-metrics/lib/config/Configuration.js
35823
- var require_Configuration = __commonJS({
35824
- "node_modules/aws-embedded-metrics/lib/config/Configuration.js"(exports2) {
35825
- "use strict";
35826
- Object.defineProperty(exports2, "__esModule", { value: true });
35827
- var EnvironmentConfigurationProvider_1 = require_EnvironmentConfigurationProvider();
35828
- var Configuration = new EnvironmentConfigurationProvider_1.EnvironmentConfigurationProvider().getConfiguration();
35829
- exports2.default = Configuration;
35830
- }
35831
- });
35832
-
35833
- // node_modules/aws-embedded-metrics/lib/utils/Logger.js
35834
- var require_Logger = __commonJS({
35835
- "node_modules/aws-embedded-metrics/lib/utils/Logger.js"(exports2) {
35836
- "use strict";
35837
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
35838
- return mod && mod.__esModule ? mod : { "default": mod };
35839
- };
35840
- Object.defineProperty(exports2, "__esModule", { value: true });
35841
- exports2.LOG = void 0;
35842
- var Configuration_1 = __importDefault2(require_Configuration());
35843
- var LOG = (...args) => {
35844
- if (Configuration_1.default.debuggingLoggingEnabled) {
35845
- console.log(...args);
35846
- }
35847
- };
35848
- exports2.LOG = LOG;
35849
- }
35850
- });
35851
-
35852
- // node_modules/aws-embedded-metrics/lib/logger/Unit.js
35853
- var require_Unit = __commonJS({
35854
- "node_modules/aws-embedded-metrics/lib/logger/Unit.js"(exports2) {
35855
- "use strict";
35856
- Object.defineProperty(exports2, "__esModule", { value: true });
35857
- exports2.Unit = void 0;
35858
- var Unit2;
35859
- (function(Unit3) {
35860
- Unit3["Seconds"] = "Seconds";
35861
- Unit3["Microseconds"] = "Microseconds";
35862
- Unit3["Milliseconds"] = "Milliseconds";
35863
- Unit3["Bytes"] = "Bytes";
35864
- Unit3["Kilobytes"] = "Kilobytes";
35865
- Unit3["Megabytes"] = "Megabytes";
35866
- Unit3["Gigabytes"] = "Gigabytes";
35867
- Unit3["Terabytes"] = "Terabytes";
35868
- Unit3["Bits"] = "Bits";
35869
- Unit3["Kilobits"] = "Kilobits";
35870
- Unit3["Megabits"] = "Megabits";
35871
- Unit3["Gigabits"] = "Gigabits";
35872
- Unit3["Terabits"] = "Terabits";
35873
- Unit3["Percent"] = "Percent";
35874
- Unit3["Count"] = "Count";
35875
- Unit3["BytesPerSecond"] = "Bytes/Second";
35876
- Unit3["KilobytesPerSecond"] = "Kilobytes/Second";
35877
- Unit3["MegabytesPerSecond"] = "Megabytes/Second";
35878
- Unit3["GigabytesPerSecond"] = "Gigabytes/Second";
35879
- Unit3["TerabytesPerSecond"] = "Terabytes/Second";
35880
- Unit3["BitsPerSecond"] = "Bits/Second";
35881
- Unit3["KilobitsPerSecond"] = "Kilobits/Second";
35882
- Unit3["MegabitsPerSecond"] = "Megabits/Second";
35883
- Unit3["GigabitsPerSecond"] = "Gigabits/Second";
35884
- Unit3["TerabitsPerSecond"] = "Terabits/Second";
35885
- Unit3["CountPerSecond"] = "Count/Second";
35886
- Unit3["None"] = "None";
35887
- })(Unit2 = exports2.Unit || (exports2.Unit = {}));
35888
- }
35889
- });
35890
-
35891
- // node_modules/aws-embedded-metrics/lib/logger/StorageResolution.js
35892
- var require_StorageResolution = __commonJS({
35893
- "node_modules/aws-embedded-metrics/lib/logger/StorageResolution.js"(exports2) {
35894
- "use strict";
35895
- Object.defineProperty(exports2, "__esModule", { value: true });
35896
- exports2.StorageResolution = void 0;
35897
- var StorageResolution;
35898
- (function(StorageResolution2) {
35899
- StorageResolution2[StorageResolution2["High"] = 1] = "High";
35900
- StorageResolution2[StorageResolution2["Standard"] = 60] = "Standard";
35901
- })(StorageResolution = exports2.StorageResolution || (exports2.StorageResolution = {}));
35902
- }
35903
- });
35904
-
35905
- // node_modules/aws-embedded-metrics/lib/exceptions/DimensionSetExceededError.js
35906
- var require_DimensionSetExceededError = __commonJS({
35907
- "node_modules/aws-embedded-metrics/lib/exceptions/DimensionSetExceededError.js"(exports2) {
35908
- "use strict";
35909
- Object.defineProperty(exports2, "__esModule", { value: true });
35910
- exports2.DimensionSetExceededError = void 0;
35911
- var DimensionSetExceededError = class _DimensionSetExceededError extends Error {
35912
- constructor(msg) {
35913
- super(msg);
35914
- Object.setPrototypeOf(this, _DimensionSetExceededError.prototype);
35915
- }
35916
- };
35917
- exports2.DimensionSetExceededError = DimensionSetExceededError;
35918
- }
35919
- });
35920
-
35921
- // node_modules/aws-embedded-metrics/lib/exceptions/InvalidDimensionError.js
35922
- var require_InvalidDimensionError = __commonJS({
35923
- "node_modules/aws-embedded-metrics/lib/exceptions/InvalidDimensionError.js"(exports2) {
35924
- "use strict";
35925
- Object.defineProperty(exports2, "__esModule", { value: true });
35926
- exports2.InvalidDimensionError = void 0;
35927
- var InvalidDimensionError = class _InvalidDimensionError extends Error {
35928
- constructor(msg) {
35929
- super(msg);
35930
- Object.setPrototypeOf(this, _InvalidDimensionError.prototype);
35931
- }
35932
- };
35933
- exports2.InvalidDimensionError = InvalidDimensionError;
35934
- }
35935
- });
35936
-
35937
- // node_modules/aws-embedded-metrics/lib/exceptions/InvalidMetricError.js
35938
- var require_InvalidMetricError = __commonJS({
35939
- "node_modules/aws-embedded-metrics/lib/exceptions/InvalidMetricError.js"(exports2) {
35940
- "use strict";
35941
- Object.defineProperty(exports2, "__esModule", { value: true });
35942
- exports2.InvalidMetricError = void 0;
35943
- var InvalidMetricError = class _InvalidMetricError extends Error {
35944
- constructor(msg) {
35945
- super(msg);
35946
- Object.setPrototypeOf(this, _InvalidMetricError.prototype);
35947
- }
35948
- };
35949
- exports2.InvalidMetricError = InvalidMetricError;
35950
- }
35951
- });
35952
-
35953
- // node_modules/aws-embedded-metrics/lib/exceptions/InvalidNamespaceError.js
35954
- var require_InvalidNamespaceError = __commonJS({
35955
- "node_modules/aws-embedded-metrics/lib/exceptions/InvalidNamespaceError.js"(exports2) {
35956
- "use strict";
35957
- Object.defineProperty(exports2, "__esModule", { value: true });
35958
- exports2.InvalidNamespaceError = void 0;
35959
- var InvalidNamespaceError = class _InvalidNamespaceError extends Error {
35960
- constructor(msg) {
35961
- super(msg);
35962
- Object.setPrototypeOf(this, _InvalidNamespaceError.prototype);
35963
- }
35964
- };
35965
- exports2.InvalidNamespaceError = InvalidNamespaceError;
35966
- }
35967
- });
35968
-
35969
- // node_modules/aws-embedded-metrics/lib/exceptions/InvalidTimestampError.js
35970
- var require_InvalidTimestampError = __commonJS({
35971
- "node_modules/aws-embedded-metrics/lib/exceptions/InvalidTimestampError.js"(exports2) {
35972
- "use strict";
35973
- Object.defineProperty(exports2, "__esModule", { value: true });
35974
- exports2.InvalidTimestampError = void 0;
35975
- var InvalidTimestampError = class _InvalidTimestampError extends Error {
35976
- constructor(msg) {
35977
- super(msg);
35978
- Object.setPrototypeOf(this, _InvalidTimestampError.prototype);
35979
- }
35980
- };
35981
- exports2.InvalidTimestampError = InvalidTimestampError;
35982
- }
35983
- });
35984
-
35985
- // node_modules/aws-embedded-metrics/lib/utils/Validator.js
35986
- var require_Validator = __commonJS({
35987
- "node_modules/aws-embedded-metrics/lib/utils/Validator.js"(exports2) {
35988
- "use strict";
35989
- Object.defineProperty(exports2, "__esModule", { value: true });
35990
- exports2.validateTimestamp = exports2.validateNamespace = exports2.validateMetric = exports2.validateDimensionSet = void 0;
35991
- var Constants_1 = require_Constants();
35992
- var Unit_1 = require_Unit();
35993
- var StorageResolution_1 = require_StorageResolution();
35994
- var DimensionSetExceededError_1 = require_DimensionSetExceededError();
35995
- var InvalidDimensionError_1 = require_InvalidDimensionError();
35996
- var InvalidMetricError_1 = require_InvalidMetricError();
35997
- var InvalidNamespaceError_1 = require_InvalidNamespaceError();
35998
- var InvalidTimestampError_1 = require_InvalidTimestampError();
35999
- var validateDimensionSet = (dimensionSet) => {
36000
- if (Object.keys(dimensionSet).length > Constants_1.Constants.MAX_DIMENSION_SET_SIZE)
36001
- throw new DimensionSetExceededError_1.DimensionSetExceededError(`Maximum number of dimensions per dimension set allowed are ${Constants_1.Constants.MAX_DIMENSION_SET_SIZE}`);
36002
- Object.entries(dimensionSet).forEach(([key, value]) => {
36003
- dimensionSet[key] = value = String(value);
36004
- if (!new RegExp(Constants_1.Constants.VALID_DIMENSION_REGEX).test(key)) {
36005
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension key ${key} has invalid characters`);
36006
- }
36007
- if (!new RegExp(Constants_1.Constants.VALID_DIMENSION_REGEX).test(value)) {
36008
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension value ${value} has invalid characters`);
36009
- }
36010
- if (key.trim().length == 0) {
36011
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension key ${key} must include at least one non-whitespace character`);
36012
- }
36013
- if (value.trim().length == 0) {
36014
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension value ${value} must include at least one non-whitespace character`);
36015
- }
36016
- if (key.length > Constants_1.Constants.MAX_DIMENSION_NAME_LENGTH) {
36017
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension key ${key} must not exceed maximum length ${Constants_1.Constants.MAX_DIMENSION_NAME_LENGTH}`);
36018
- }
36019
- if (value.length > Constants_1.Constants.MAX_DIMENSION_VALUE_LENGTH) {
36020
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension value ${value} must not exceed maximum length ${Constants_1.Constants.MAX_DIMENSION_VALUE_LENGTH}`);
36021
- }
36022
- if (key.startsWith(":")) {
36023
- throw new InvalidDimensionError_1.InvalidDimensionError(`Dimension key ${key} cannot start with ':'`);
36024
- }
36025
- });
36026
- };
36027
- exports2.validateDimensionSet = validateDimensionSet;
36028
- var validateMetric = (key, value, unit, storageResolution, metricNameAndResolutionMap) => {
36029
- if (key.trim().length == 0) {
36030
- throw new InvalidMetricError_1.InvalidMetricError(`Metric key ${key} must include at least one non-whitespace character`);
36031
- }
36032
- if (key.length > Constants_1.Constants.MAX_METRIC_NAME_LENGTH) {
36033
- throw new InvalidMetricError_1.InvalidMetricError(`Metric key ${key} must not exceed maximum length ${Constants_1.Constants.MAX_METRIC_NAME_LENGTH}`);
36034
- }
36035
- if (!Number.isFinite(value)) {
36036
- throw new InvalidMetricError_1.InvalidMetricError(`Metric value ${value} is not a number`);
36037
- }
36038
- if (value > Number.MAX_SAFE_INTEGER) {
36039
- throw new InvalidMetricError_1.InvalidMetricError(`Metric value ${value} must not exceed maximum value ${Number.MAX_SAFE_INTEGER}}`);
36040
- }
36041
- if (value < -Number.MAX_SAFE_INTEGER) {
36042
- throw new InvalidMetricError_1.InvalidMetricError(`Metric value ${value} must not be less than minimum value ${-Number.MAX_SAFE_INTEGER}`);
36043
- }
36044
- if (unit !== void 0 && !Object.values(Unit_1.Unit).map((u3) => String(u3)).includes(unit)) {
36045
- throw new InvalidMetricError_1.InvalidMetricError(`Metric unit ${unit} is not valid`);
36046
- }
36047
- if (storageResolution !== void 0 && !Object.values(StorageResolution_1.StorageResolution).map((s3) => s3).includes(storageResolution)) {
36048
- throw new InvalidMetricError_1.InvalidMetricError(`Metric resolution ${storageResolution} is not valid`);
36049
- }
36050
- if ((metricNameAndResolutionMap === null || metricNameAndResolutionMap === void 0 ? void 0 : metricNameAndResolutionMap.has(key)) && metricNameAndResolutionMap.get(key) !== (storageResolution ? storageResolution : StorageResolution_1.StorageResolution.Standard)) {
36051
- throw new InvalidMetricError_1.InvalidMetricError(`Resolution for metrics ${key} is already set. A single log event cannot have a metric with two different resolutions.`);
36052
- }
36053
- };
36054
- exports2.validateMetric = validateMetric;
36055
- var validateNamespace = (namespace) => {
36056
- if (namespace.trim().length == 0) {
36057
- throw new InvalidNamespaceError_1.InvalidNamespaceError(`Namespace must include at least one non-whitespace character`);
36058
- }
36059
- if (namespace.length > Constants_1.Constants.MAX_NAMESPACE_LENGTH) {
36060
- throw new InvalidNamespaceError_1.InvalidNamespaceError(`Namespace must not exceed maximum length ${Constants_1.Constants.MAX_NAMESPACE_LENGTH}`);
36061
- }
36062
- if (!new RegExp(Constants_1.Constants.VALID_NAMESPACE_REGEX).test(namespace)) {
36063
- throw new InvalidNamespaceError_1.InvalidNamespaceError(`Namespace ${namespace} has invalid characters`);
36064
- }
36065
- };
36066
- exports2.validateNamespace = validateNamespace;
36067
- var validateTimestamp = (timestamp) => {
36068
- if (!isDate(timestamp)) {
36069
- throw new InvalidTimestampError_1.InvalidTimestampError(`Timestamp ${String(timestamp)} is invalid`);
36070
- }
36071
- timestamp = new Date(timestamp);
36072
- if (timestamp < new Date(Date.now() - Constants_1.Constants.MAX_TIMESTAMP_PAST_AGE)) {
36073
- throw new InvalidTimestampError_1.InvalidTimestampError(`Timestamp ${String(timestamp)} must not be older than ${Constants_1.Constants.MAX_TIMESTAMP_PAST_AGE} milliseconds`);
36074
- }
36075
- if (timestamp > new Date(Date.now() + Constants_1.Constants.MAX_TIMESTAMP_FUTURE_AGE)) {
36076
- throw new InvalidTimestampError_1.InvalidTimestampError(`Timestamp ${String(timestamp)} must not be newer than ${Constants_1.Constants.MAX_TIMESTAMP_FUTURE_AGE} milliseconds`);
36077
- }
36078
- };
36079
- exports2.validateTimestamp = validateTimestamp;
36080
- var isDate = (timestamp) => {
36081
- return timestamp instanceof Date && !isNaN(new Date(timestamp).getTime()) || new Date(timestamp).getTime() > 0;
36082
- };
36083
- }
36084
- });
36085
-
36086
- // node_modules/aws-embedded-metrics/lib/logger/MetricValues.js
36087
- var require_MetricValues = __commonJS({
36088
- "node_modules/aws-embedded-metrics/lib/logger/MetricValues.js"(exports2) {
36089
- "use strict";
36090
- Object.defineProperty(exports2, "__esModule", { value: true });
36091
- exports2.MetricValues = void 0;
36092
- var StorageResolution_1 = require_StorageResolution();
36093
- var MetricValues = class {
36094
- constructor(value, unit, storageResolution) {
36095
- this.values = [value];
36096
- this.unit = unit || "None";
36097
- this.storageResolution = storageResolution || StorageResolution_1.StorageResolution.Standard;
36098
- }
36099
- /**
36100
- * Appends the provided value to the current metric
36101
- * @param value
36102
- */
36103
- addValue(value) {
36104
- this.values.push(value);
36105
- }
36106
- };
36107
- exports2.MetricValues = MetricValues;
36108
- }
36109
- });
36110
-
36111
- // node_modules/aws-embedded-metrics/lib/logger/MetricsContext.js
36112
- var require_MetricsContext = __commonJS({
36113
- "node_modules/aws-embedded-metrics/lib/logger/MetricsContext.js"(exports2) {
36114
- "use strict";
36115
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
36116
- return mod && mod.__esModule ? mod : { "default": mod };
36117
- };
36118
- Object.defineProperty(exports2, "__esModule", { value: true });
36119
- exports2.MetricsContext = void 0;
36120
- var Configuration_1 = __importDefault2(require_Configuration());
36121
- var Logger_1 = require_Logger();
36122
- var Validator_1 = require_Validator();
36123
- var MetricValues_1 = require_MetricValues();
36124
- var StorageResolution_1 = require_StorageResolution();
36125
- var MetricsContext = class _MetricsContext {
36126
- /**
36127
- * Use this to create a new, empty context.
36128
- */
36129
- static empty() {
36130
- return new _MetricsContext();
36131
- }
36132
- /**
36133
- * Constructor used to create child instances.
36134
- * You should not use this constructor directly.
36135
- * Instead, use createCopyWithContext() or empty().
36136
- *
36137
- * The reason for this is to avoid unexpected behavior when creating
36138
- * MetricsContexts with defaultDimensions and existing dimensions.
36139
- *
36140
- * @param properties
36141
- * @param dimensions
36142
- */
36143
- constructor(namespace, properties, dimensions, defaultDimensions, shouldUseDefaultDimensions, timestamp) {
36144
- this.metrics = /* @__PURE__ */ new Map();
36145
- this.meta = {};
36146
- this.shouldUseDefaultDimensions = true;
36147
- this.metricNameAndResolutionMap = /* @__PURE__ */ new Map();
36148
- this.namespace = namespace || Configuration_1.default.namespace;
36149
- this.properties = properties || {};
36150
- this.dimensions = dimensions || [];
36151
- this.timestamp = timestamp;
36152
- this.meta.Timestamp = _MetricsContext.resolveMetaTimestamp(timestamp);
36153
- this.defaultDimensions = defaultDimensions || {};
36154
- if (shouldUseDefaultDimensions != void 0) {
36155
- this.shouldUseDefaultDimensions = shouldUseDefaultDimensions;
36156
- }
36157
- }
36158
- static resolveMetaTimestamp(timestamp) {
36159
- if (timestamp instanceof Date) {
36160
- return timestamp.getTime();
36161
- } else if (timestamp) {
36162
- return timestamp;
36163
- } else {
36164
- return Date.now();
36165
- }
36166
- }
36167
- setNamespace(value) {
36168
- (0, Validator_1.validateNamespace)(value);
36169
- this.namespace = value;
36170
- }
36171
- setProperty(key, value) {
36172
- this.properties[key] = value;
36173
- }
36174
- setTimestamp(timestamp) {
36175
- (0, Validator_1.validateTimestamp)(timestamp);
36176
- this.timestamp = timestamp;
36177
- this.meta.Timestamp = _MetricsContext.resolveMetaTimestamp(timestamp);
36178
- }
36179
- /**
36180
- * Sets default dimensions for the Context.
36181
- * A dimension set will be created with just the default dimensions
36182
- * and all calls to putDimensions will be prepended with the defaults.
36183
- */
36184
- setDefaultDimensions(dimensions) {
36185
- (0, Logger_1.LOG)(`Received default dimensions`, dimensions);
36186
- this.defaultDimensions = dimensions;
36187
- }
36188
- /**
36189
- * Adds a new set of dimensions. Any time a new dimensions set
36190
- * is added, the set is first prepended by the default dimensions.
36191
- *
36192
- * @param dimensions
36193
- */
36194
- putDimensions(incomingDimensionSet) {
36195
- (0, Validator_1.validateDimensionSet)(incomingDimensionSet);
36196
- const incomingDimensionSetKeys = Object.keys(incomingDimensionSet);
36197
- this.dimensions = this.dimensions.filter((existingDimensionSet) => {
36198
- const existingDimensionSetKeys = Object.keys(existingDimensionSet);
36199
- if (existingDimensionSetKeys.length !== incomingDimensionSetKeys.length) {
36200
- return true;
36201
- }
36202
- return !existingDimensionSetKeys.every((existingDimensionSetKey) => incomingDimensionSetKeys.includes(existingDimensionSetKey));
36203
- });
36204
- this.dimensions.push(incomingDimensionSet);
36205
- }
36206
- /**
36207
- * Overwrite all dimensions.
36208
- *
36209
- * @param dimensionSets
36210
- */
36211
- setDimensions(dimensionSets, useDefault = false) {
36212
- dimensionSets.forEach((dimensionSet) => (0, Validator_1.validateDimensionSet)(dimensionSet));
36213
- this.shouldUseDefaultDimensions = useDefault;
36214
- this.dimensions = dimensionSets;
36215
- }
36216
- /**
36217
- * Reset all custom dimensions
36218
- * @param useDefault Indicates whether default dimensions should be used
36219
- */
36220
- resetDimensions(useDefault) {
36221
- this.shouldUseDefaultDimensions = useDefault;
36222
- this.dimensions = [];
36223
- }
36224
- /**
36225
- * Get the current dimensions.
36226
- */
36227
- getDimensions() {
36228
- if (this.shouldUseDefaultDimensions === false) {
36229
- return this.dimensions;
36230
- }
36231
- if (Object.keys(this.defaultDimensions).length === 0) {
36232
- return this.dimensions;
36233
- }
36234
- if (this.dimensions.length === 0) {
36235
- return [this.defaultDimensions];
36236
- }
36237
- return this.dimensions.map((custom) => {
36238
- return Object.assign(Object.assign({}, this.defaultDimensions), custom);
36239
- });
36240
- }
36241
- putMetric(key, value, unit, storageResolution) {
36242
- var _a2;
36243
- (0, Validator_1.validateMetric)(key, value, unit, storageResolution, this.metricNameAndResolutionMap);
36244
- const currentMetric = this.metrics.get(key);
36245
- if (currentMetric) {
36246
- currentMetric.addValue(value);
36247
- } else {
36248
- this.metrics.set(key, new MetricValues_1.MetricValues(value, unit, storageResolution));
36249
- }
36250
- (_a2 = this.metricNameAndResolutionMap) === null || _a2 === void 0 ? void 0 : _a2.set(key, storageResolution || StorageResolution_1.StorageResolution.Standard);
36251
- }
36252
- /**
36253
- * Creates an independently flushable context.
36254
- * Custom dimensions are preserved by default unless preserveDimensions parameter is set.
36255
- * @param preserveDimensions Indicates whether custom dimensions should be preserved
36256
- */
36257
- createCopyWithContext(preserveDimensions = true) {
36258
- return new _MetricsContext(this.namespace, Object.assign({}, this.properties), preserveDimensions ? Object.assign([], this.dimensions) : [], this.defaultDimensions, this.shouldUseDefaultDimensions, this.timestamp);
36259
- }
36260
- };
36261
- exports2.MetricsContext = MetricsContext;
36262
- }
36263
- });
36264
-
36265
- // node_modules/aws-embedded-metrics/lib/logger/MetricsLogger.js
36266
- var require_MetricsLogger = __commonJS({
36267
- "node_modules/aws-embedded-metrics/lib/logger/MetricsLogger.js"(exports2) {
36268
- "use strict";
36269
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
36270
- function adopt(value) {
36271
- return value instanceof P ? value : new P(function(resolve) {
36272
- resolve(value);
36273
- });
36274
- }
36275
- return new (P || (P = Promise))(function(resolve, reject) {
36276
- function fulfilled(value) {
36277
- try {
36278
- step(generator.next(value));
36279
- } catch (e3) {
36280
- reject(e3);
36281
- }
36282
- }
36283
- function rejected(value) {
36284
- try {
36285
- step(generator["throw"](value));
36286
- } catch (e3) {
36287
- reject(e3);
36288
- }
36289
- }
36290
- function step(result) {
36291
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
36292
- }
36293
- step((generator = generator.apply(thisArg, _arguments || [])).next());
36294
- });
36295
- };
36296
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
36297
- return mod && mod.__esModule ? mod : { "default": mod };
36298
- };
36299
- Object.defineProperty(exports2, "__esModule", { value: true });
36300
- exports2.MetricsLogger = void 0;
36301
- var Configuration_1 = __importDefault2(require_Configuration());
36302
- var MetricsContext_1 = require_MetricsContext();
36303
- var MetricsLogger = class _MetricsLogger {
36304
- constructor(resolveEnvironment, context) {
36305
- this.configureContextForEnvironment = (context2, environment) => {
36306
- const defaultDimensions = {
36307
- // LogGroup name will entirely depend on the environment since there
36308
- // are some cases where the LogGroup cannot be configured (e.g. Lambda)
36309
- LogGroup: environment.getLogGroupName(),
36310
- ServiceName: Configuration_1.default.serviceName || environment.getName(),
36311
- ServiceType: Configuration_1.default.serviceType || environment.getType()
36312
- };
36313
- context2.setDefaultDimensions(defaultDimensions);
36314
- environment.configureContext(context2);
36315
- };
36316
- this.resolveEnvironment = resolveEnvironment;
36317
- this.context = context || MetricsContext_1.MetricsContext.empty();
36318
- this.flushPreserveDimensions = true;
36319
- }
36320
- /**
36321
- * Flushes the current context state to the configured sink.
36322
- */
36323
- flush() {
36324
- return __awaiter2(this, void 0, void 0, function* () {
36325
- const environment = yield this.resolveEnvironment();
36326
- this.configureContextForEnvironment(this.context, environment);
36327
- const sink = environment.getSink();
36328
- yield sink.accept(this.context);
36329
- this.context = this.context.createCopyWithContext(this.flushPreserveDimensions);
36330
- });
36331
- }
36332
- /**
36333
- * Set a property on the published metrics.
36334
- * This is stored in the emitted log data and you are not
36335
- * charged for this data by CloudWatch Metrics.
36336
- * These values can be values that are useful for searching on,
36337
- * but have too high cardinality to emit as dimensions to
36338
- * CloudWatch Metrics.
36339
- *
36340
- * @param key Property name
36341
- * @param value Property value
36342
- */
36343
- setProperty(key, value) {
36344
- this.context.setProperty(key, value);
36345
- return this;
36346
- }
36347
- /**
36348
- * Adds a dimension.
36349
- * This is generally a low cardinality key-value pair that is part of the metric identity.
36350
- * CloudWatch treats each unique combination of dimensions as a separate metric, even if the metrics have the same metric name.
36351
- *
36352
- * @param dimension
36353
- * @param value
36354
- * @see [CloudWatch Dimensions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Dimension)
36355
- */
36356
- putDimensions(dimensions) {
36357
- this.context.putDimensions(dimensions);
36358
- return this;
36359
- }
36360
- setDimensions(dimensionSetOrSets, useDefault = false) {
36361
- if (Array.isArray(dimensionSetOrSets)) {
36362
- this.context.setDimensions(dimensionSetOrSets, useDefault);
36363
- } else {
36364
- this.context.setDimensions([dimensionSetOrSets], useDefault);
36365
- }
36366
- return this;
36367
- }
36368
- /**
36369
- * Clear all custom dimensions on this MetricsLogger instance
36370
- *
36371
- * @param useDefault indicates whether default dimensions should be used
36372
- */
36373
- resetDimensions(useDefault) {
36374
- this.context.resetDimensions(useDefault);
36375
- return this;
36376
- }
36377
- /**
36378
- * Put a metric value.
36379
- * This value will be emitted to CloudWatch Metrics asyncronously and does not contribute to your
36380
- * account TPS limits. The value will also be available in your CloudWatch Logs
36381
- * @param key
36382
- * @param value
36383
- * @param unit
36384
- * @param storageResolution
36385
- */
36386
- putMetric(key, value, unit, storageResolution) {
36387
- this.context.putMetric(key, value, unit, storageResolution);
36388
- return this;
36389
- }
36390
- /**
36391
- * Set the CloudWatch namespace that metrics should be published to.
36392
- * @param value
36393
- */
36394
- setNamespace(value) {
36395
- this.context.setNamespace(value);
36396
- return this;
36397
- }
36398
- /**
36399
- * Set the timestamp of metrics emitted in this context.
36400
- *
36401
- * If not set, the timestamp will default to new Date() at the point
36402
- * the context is constructed.
36403
- *
36404
- * If set, timestamp will preserved across calls to flush().
36405
- *
36406
- * @param timestamp
36407
- */
36408
- setTimestamp(timestamp) {
36409
- this.context.setTimestamp(timestamp);
36410
- return this;
36411
- }
36412
- /**
36413
- * Creates a new logger using the same contextual data as
36414
- * the previous logger. This allows you to flush the instances
36415
- * independently.
36416
- */
36417
- new() {
36418
- return new _MetricsLogger(this.resolveEnvironment, this.context.createCopyWithContext());
36419
- }
36420
- };
36421
- exports2.MetricsLogger = MetricsLogger;
36422
- }
36423
- });
36424
-
36425
- // node_modules/@datastructures-js/heap/src/heap.js
36426
- var require_heap = __commonJS({
36427
- "node_modules/@datastructures-js/heap/src/heap.js"(exports2) {
36428
- "use strict";
36429
- var Heap = class _Heap {
36430
- /**
36431
- * @param {function} compare
36432
- * @param {array} [values]
36433
- * @param {number|string|object} [_leaf]
36434
- */
36435
- constructor(compare, values, _leaf) {
36436
- if (typeof compare !== "function") {
36437
- throw new Error("Heap constructor expects a compare function");
36438
- }
36439
- this._compare = compare;
36440
- this._nodes = Array.isArray(values) ? values : [];
36441
- this._leaf = _leaf || null;
36442
- if (this._nodes.length > 0) {
36443
- this.fix();
36444
- }
36445
- }
36446
- /**
36447
- * Converts the heap to a cloned array without sorting.
36448
- * @public
36449
- * @returns {Array}
36450
- */
36451
- toArray() {
36452
- return Array.from(this._nodes);
36453
- }
36454
- /**
36455
- * Checks if a parent has a left child
36456
- * @private
36457
- */
36458
- _hasLeftChild(parentIndex) {
36459
- const leftChildIndex = parentIndex * 2 + 1;
36460
- return leftChildIndex < this.size();
36461
- }
36462
- /**
36463
- * Checks if a parent has a right child
36464
- * @private
36465
- */
36466
- _hasRightChild(parentIndex) {
36467
- const rightChildIndex = parentIndex * 2 + 2;
36468
- return rightChildIndex < this.size();
36469
- }
36470
- /**
36471
- * Compares two nodes
36472
- * @private
36473
- */
36474
- _compareAt(i3, j3) {
36475
- return this._compare(this._nodes[i3], this._nodes[j3]);
36476
- }
36477
- /**
36478
- * Swaps two nodes in the heap
36479
- * @private
36480
- */
36481
- _swap(i3, j3) {
36482
- const temp = this._nodes[i3];
36483
- this._nodes[i3] = this._nodes[j3];
36484
- this._nodes[j3] = temp;
36485
- }
36486
- /**
36487
- * Checks if parent and child should be swapped
36488
- * @private
36489
- */
36490
- _shouldSwap(parentIndex, childIndex) {
36491
- if (parentIndex < 0 || parentIndex >= this.size()) {
36492
- return false;
36493
- }
36494
- if (childIndex < 0 || childIndex >= this.size()) {
36495
- return false;
36496
- }
36497
- return this._compareAt(parentIndex, childIndex) > 0;
36498
- }
36499
- /**
36500
- * Compares children of a parent
36501
- * @private
36502
- */
36503
- _compareChildrenOf(parentIndex) {
36504
- if (!this._hasLeftChild(parentIndex) && !this._hasRightChild(parentIndex)) {
36505
- return -1;
36506
- }
36507
- const leftChildIndex = parentIndex * 2 + 1;
36508
- const rightChildIndex = parentIndex * 2 + 2;
36509
- if (!this._hasLeftChild(parentIndex)) {
36510
- return rightChildIndex;
36511
- }
36512
- if (!this._hasRightChild(parentIndex)) {
36513
- return leftChildIndex;
36514
- }
36515
- const compare = this._compareAt(leftChildIndex, rightChildIndex);
36516
- return compare > 0 ? rightChildIndex : leftChildIndex;
36517
- }
36518
- /**
36519
- * Compares two children before a position
36520
- * @private
36521
- */
36522
- _compareChildrenBefore(index, leftChildIndex, rightChildIndex) {
36523
- const compare = this._compareAt(rightChildIndex, leftChildIndex);
36524
- if (compare <= 0 && rightChildIndex < index) {
36525
- return rightChildIndex;
36526
- }
36527
- return leftChildIndex;
36528
- }
36529
- /**
36530
- * Recursively bubbles up a node if it's in a wrong position
36531
- * @private
36532
- */
36533
- _heapifyUp(startIndex) {
36534
- let childIndex = startIndex;
36535
- let parentIndex = Math.floor((childIndex - 1) / 2);
36536
- while (this._shouldSwap(parentIndex, childIndex)) {
36537
- this._swap(parentIndex, childIndex);
36538
- childIndex = parentIndex;
36539
- parentIndex = Math.floor((childIndex - 1) / 2);
36540
- }
36541
- }
36542
- /**
36543
- * Recursively bubbles down a node if it's in a wrong position
36544
- * @private
36545
- */
36546
- _heapifyDown(startIndex) {
36547
- let parentIndex = startIndex;
36548
- let childIndex = this._compareChildrenOf(parentIndex);
36549
- while (this._shouldSwap(parentIndex, childIndex)) {
36550
- this._swap(parentIndex, childIndex);
36551
- parentIndex = childIndex;
36552
- childIndex = this._compareChildrenOf(parentIndex);
36553
- }
36554
- }
36555
- /**
36556
- * Recursively bubbles down a node before a given index
36557
- * @private
36558
- */
36559
- _heapifyDownUntil(index) {
36560
- let parentIndex = 0;
36561
- let leftChildIndex = 1;
36562
- let rightChildIndex = 2;
36563
- let childIndex;
36564
- while (leftChildIndex < index) {
36565
- childIndex = this._compareChildrenBefore(
36566
- index,
36567
- leftChildIndex,
36568
- rightChildIndex
36569
- );
36570
- if (this._shouldSwap(parentIndex, childIndex)) {
36571
- this._swap(parentIndex, childIndex);
36572
- }
36573
- parentIndex = childIndex;
36574
- leftChildIndex = parentIndex * 2 + 1;
36575
- rightChildIndex = parentIndex * 2 + 2;
36576
- }
36577
- }
36578
- /**
36579
- * Inserts a new value into the heap
36580
- * @public
36581
- * @param {number|string|object} value
36582
- * @returns {Heap}
36583
- */
36584
- insert(value) {
36585
- this._nodes.push(value);
36586
- this._heapifyUp(this.size() - 1);
36587
- if (this._leaf === null || this._compare(value, this._leaf) > 0) {
36588
- this._leaf = value;
36589
- }
36590
- return this;
36591
- }
36592
- /**
36593
- * Inserts a new value into the heap
36594
- * @public
36595
- * @param {number|string|object} value
36596
- * @returns {Heap}
36597
- */
36598
- push(value) {
36599
- return this.insert(value);
36600
- }
36601
- /**
36602
- * Removes and returns the root node in the heap
36603
- * @public
36604
- * @returns {number|string|object}
36605
- */
36606
- extractRoot() {
36607
- if (this.isEmpty()) {
36608
- return null;
36609
- }
36610
- const root = this.root();
36611
- this._nodes[0] = this._nodes[this.size() - 1];
36612
- this._nodes.pop();
36613
- this._heapifyDown(0);
36614
- if (root === this._leaf) {
36615
- this._leaf = null;
36616
- }
36617
- return root;
36618
- }
36619
- /**
36620
- * Removes and returns the root node in the heap
36621
- * @public
36622
- * @returns {number|string|object}
36623
- */
36624
- pop() {
36625
- return this.extractRoot();
36626
- }
36627
- /**
36628
- * Applies heap sort and return the values sorted by priority
36629
- * @public
36630
- * @returns {array}
36631
- */
36632
- sort() {
36633
- for (let i3 = this.size() - 1; i3 > 0; i3 -= 1) {
36634
- this._swap(0, i3);
36635
- this._heapifyDownUntil(i3);
36636
- }
36637
- return this._nodes;
36638
- }
36639
- /**
36640
- * Fixes node positions in the heap
36641
- * @public
36642
- * @returns {Heap}
36643
- */
36644
- fix() {
36645
- for (let i3 = Math.floor(this.size() / 2) - 1; i3 >= 0; i3 -= 1) {
36646
- this._heapifyDown(i3);
36647
- }
36648
- for (let i3 = Math.floor(this.size() / 2); i3 < this.size(); i3 += 1) {
36649
- const value = this._nodes[i3];
36650
- if (this._leaf === null || this._compare(value, this._leaf) > 0) {
36651
- this._leaf = value;
36652
- }
36653
- }
36654
- return this;
36655
- }
36656
- /**
36657
- * Verifies that all heap nodes are in the right position
36658
- * @public
36659
- * @returns {boolean}
36660
- */
36661
- isValid() {
36662
- const isValidRecursive = (parentIndex) => {
36663
- let isValidLeft = true;
36664
- let isValidRight = true;
36665
- if (this._hasLeftChild(parentIndex)) {
36666
- const leftChildIndex = parentIndex * 2 + 1;
36667
- if (this._compareAt(parentIndex, leftChildIndex) > 0) {
36668
- return false;
36669
- }
36670
- isValidLeft = isValidRecursive(leftChildIndex);
36671
- }
36672
- if (this._hasRightChild(parentIndex)) {
36673
- const rightChildIndex = parentIndex * 2 + 2;
36674
- if (this._compareAt(parentIndex, rightChildIndex) > 0) {
36675
- return false;
36676
- }
36677
- isValidRight = isValidRecursive(rightChildIndex);
36678
- }
36679
- return isValidLeft && isValidRight;
36680
- };
36681
- return isValidRecursive(0);
36682
- }
36683
- /**
36684
- * Returns a shallow copy of the heap
36685
- * @public
36686
- * @returns {Heap}
36687
- */
36688
- clone() {
36689
- return new _Heap(this._compare, this._nodes.slice(), this._leaf);
36690
- }
36691
- /**
36692
- * Returns the root node in the heap
36693
- * @public
36694
- * @returns {number|string|object}
36695
- */
36696
- root() {
36697
- if (this.isEmpty()) {
36698
- return null;
36699
- }
36700
- return this._nodes[0];
36701
- }
36702
- /**
36703
- * Returns the root node in the heap
36704
- * @public
36705
- * @returns {number|string|object}
36706
- */
36707
- top() {
36708
- return this.root();
36709
- }
36710
- /**
36711
- * Returns a leaf node in the heap
36712
- * @public
36713
- * @returns {number|string|object}
36714
- */
36715
- leaf() {
36716
- return this._leaf;
36717
- }
36718
- /**
36719
- * Returns the number of nodes in the heap
36720
- * @public
36721
- * @returns {number}
36722
- */
36723
- size() {
36724
- return this._nodes.length;
36725
- }
36726
- /**
36727
- * Checks if the heap is empty
36728
- * @public
36729
- * @returns {boolean}
36730
- */
36731
- isEmpty() {
36732
- return this.size() === 0;
36733
- }
36734
- /**
36735
- * Clears the heap
36736
- * @public
36737
- */
36738
- clear() {
36739
- this._nodes = [];
36740
- this._leaf = null;
36741
- }
36742
- /**
36743
- * Implements an iterable on the heap
36744
- * @public
36745
- */
36746
- [Symbol.iterator]() {
36747
- let size = this.size();
36748
- return {
36749
- next: () => {
36750
- size -= 1;
36751
- return {
36752
- value: this.pop(),
36753
- done: size === -1
36754
- };
36755
- }
36756
- };
36757
- }
36758
- /**
36759
- * Builds a heap from a array of values
36760
- * @public
36761
- * @static
36762
- * @param {array} values
36763
- * @param {function} compare
36764
- * @returns {Heap}
36765
- */
36766
- static heapify(values, compare) {
36767
- if (!Array.isArray(values)) {
36768
- throw new Error("Heap.heapify expects an array of values");
36769
- }
36770
- if (typeof compare !== "function") {
36771
- throw new Error("Heap.heapify expects a compare function");
36772
- }
36773
- return new _Heap(compare, values).fix();
36774
- }
36775
- /**
36776
- * Checks if a list of values is a valid heap
36777
- * @public
36778
- * @static
36779
- * @param {array} values
36780
- * @param {function} compare
36781
- * @returns {boolean}
36782
- */
36783
- static isHeapified(values, compare) {
36784
- return new _Heap(compare, values).isValid();
36785
- }
36786
- };
36787
- exports2.Heap = Heap;
36788
- }
36789
- });
36790
-
36791
- // node_modules/@datastructures-js/heap/src/minHeap.js
36792
- var require_minHeap = __commonJS({
36793
- "node_modules/@datastructures-js/heap/src/minHeap.js"(exports2) {
36794
- "use strict";
36795
- var { Heap } = require_heap();
36796
- var getMinCompare = (getCompareValue) => (a3, b3) => {
36797
- const aVal = typeof getCompareValue === "function" ? getCompareValue(a3) : a3;
36798
- const bVal = typeof getCompareValue === "function" ? getCompareValue(b3) : b3;
36799
- return aVal <= bVal ? -1 : 1;
36800
- };
36801
- var MinHeap = class _MinHeap extends Heap {
36802
- /**
36803
- * @param {function} [getCompareValue]
36804
- * @param {array} [values]
36805
- */
36806
- constructor(getCompareValue, values) {
36807
- super(getMinCompare(getCompareValue), values);
36808
- this._getCompareValue = getCompareValue;
36809
- }
36810
- /**
36811
- * Inserts a new value into the heap
36812
- * @public
36813
- * @param {number|string|object} value
36814
- * @returns {MinHeap}
36815
- */
36816
- insert(value) {
36817
- super.insert(value);
36818
- return this;
36819
- }
36820
- /**
36821
- * Inserts a new value into the heap
36822
- * @public
36823
- * @param {number|string|object} value
36824
- * @returns {MinHeap}
36825
- */
36826
- push(value) {
36827
- return this.insert(value);
36828
- }
36829
- /**
36830
- * Fixes node positions in the heap
36831
- * @public
36832
- * @returns {MinHeap}
36833
- */
36834
- fix() {
36835
- super.fix();
36836
- return this;
36837
- }
36838
- /**
36839
- * Returns a shallow copy of the MinHeap
36840
- * @public
36841
- * @returns {MinHeap}
36842
- */
36843
- clone() {
36844
- return new _MinHeap(this._getCompareValue, this._nodes.slice());
36845
- }
36846
- /**
36847
- * Builds a MinHeap from an array
36848
- * @public
36849
- * @static
36850
- * @param {array} values
36851
- * @param {function} [getCompareValue]
36852
- * @returns {MinHeap}
36853
- */
36854
- static heapify(values, getCompareValue) {
36855
- if (!Array.isArray(values)) {
36856
- throw new Error("MinHeap.heapify expects an array");
36857
- }
36858
- return new _MinHeap(getCompareValue, values);
36859
- }
36860
- /**
36861
- * Checks if a list of values is a valid min heap
36862
- * @public
36863
- * @static
36864
- * @param {array} values
36865
- * @param {function} [getCompareValue]
36866
- * @returns {boolean}
36867
- */
36868
- static isHeapified(values, getCompareValue) {
36869
- return new _MinHeap(getCompareValue, values).isValid();
36870
- }
36871
- };
36872
- exports2.MinHeap = MinHeap;
36873
- }
36874
- });
36875
-
36876
- // node_modules/@datastructures-js/heap/src/maxHeap.js
36877
- var require_maxHeap = __commonJS({
36878
- "node_modules/@datastructures-js/heap/src/maxHeap.js"(exports2) {
36879
- "use strict";
36880
- var { Heap } = require_heap();
36881
- var getMaxCompare = (getCompareValue) => (a3, b3) => {
36882
- const aVal = typeof getCompareValue === "function" ? getCompareValue(a3) : a3;
36883
- const bVal = typeof getCompareValue === "function" ? getCompareValue(b3) : b3;
36884
- return aVal < bVal ? 1 : -1;
36885
- };
36886
- var MaxHeap = class _MaxHeap extends Heap {
36887
- /**
36888
- * @param {function} [getCompareValue]
36889
- * @param {array} [values]
36890
- */
36891
- constructor(getCompareValue, values) {
36892
- super(getMaxCompare(getCompareValue), values);
36893
- this._getCompareValue = getCompareValue;
36894
- }
36895
- /**
36896
- * Inserts a new value into the heap
36897
- * @public
36898
- * @param {number|string|object} value
36899
- * @returns {MaxHeap}
36900
- */
36901
- insert(value) {
36902
- super.insert(value);
36903
- return this;
36904
- }
36905
- /**
36906
- * Inserts a new value into the heap
36907
- * @public
36908
- * @param {number|string|object} value
36909
- * @returns {MaxHeap}
36910
- */
36911
- push(value) {
36912
- return this.insert(value);
36913
- }
36914
- /**
36915
- * Fixes node positions in the heap
36916
- * @public
36917
- * @returns {MaxHeap}
36918
- */
36919
- fix() {
36920
- super.fix();
36921
- return this;
36922
- }
36923
- /**
36924
- * Returns a shallow copy of the MaxHeap
36925
- * @public
36926
- * @returns {MaxHeap}
36927
- */
36928
- clone() {
36929
- return new _MaxHeap(this._getCompareValue, this._nodes.slice());
36930
- }
36931
- /**
36932
- * Builds a MaxHeap from an array
36933
- * @public
36934
- * @static
36935
- * @param {array} values
36936
- * @param {function} [getCompareValue]
36937
- * @returns {MaxHeap}
36938
- */
36939
- static heapify(values, getCompareValue) {
36940
- if (!Array.isArray(values)) {
36941
- throw new Error("MaxHeap.heapify expects an array");
36942
- }
36943
- return new _MaxHeap(getCompareValue, values);
36944
- }
36945
- /**
36946
- * Checks if a list of values is a valid max heap
36947
- * @public
36948
- * @static
36949
- * @param {array} values
36950
- * @param {function} [getCompareValue]
36951
- * @returns {boolean}
36952
- */
36953
- static isHeapified(values, getCompareValue) {
36954
- return new _MaxHeap(getCompareValue, values).isValid();
36955
- }
36956
- };
36957
- exports2.MaxHeap = MaxHeap;
36958
- }
36959
- });
36960
-
36961
- // node_modules/@datastructures-js/heap/index.js
36962
- var require_heap2 = __commonJS({
36963
- "node_modules/@datastructures-js/heap/index.js"(exports2) {
36964
- "use strict";
36965
- var { Heap } = require_heap();
36966
- var { MinHeap } = require_minHeap();
36967
- var { MaxHeap } = require_maxHeap();
36968
- exports2.Heap = Heap;
36969
- exports2.MinHeap = MinHeap;
36970
- exports2.MaxHeap = MaxHeap;
36971
- }
36972
- });
36973
-
36974
- // node_modules/aws-embedded-metrics/lib/serializers/LogSerializer.js
36975
- var require_LogSerializer = __commonJS({
36976
- "node_modules/aws-embedded-metrics/lib/serializers/LogSerializer.js"(exports2) {
36977
- "use strict";
36978
- Object.defineProperty(exports2, "__esModule", { value: true });
36979
- exports2.LogSerializer = void 0;
36980
- var heap_1 = require_heap2();
36981
- var Constants_1 = require_Constants();
36982
- var DimensionSetExceededError_1 = require_DimensionSetExceededError();
36983
- var StorageResolution_1 = require_StorageResolution();
36984
- var LogSerializer = class {
36985
- /**
36986
- * Retrieve the current context as a JSON string
36987
- */
36988
- serialize(context) {
36989
- const dimensionKeys = [];
36990
- let dimensionProperties = {};
36991
- context.getDimensions().forEach((dimensionSet) => {
36992
- const keys = Object.keys(dimensionSet);
36993
- if (keys.length > Constants_1.Constants.MAX_DIMENSION_SET_SIZE) {
36994
- const errMsg = `Maximum number of dimensions allowed are ${Constants_1.Constants.MAX_DIMENSION_SET_SIZE}.Account for default dimensions if not using set_dimensions.`;
36995
- throw new DimensionSetExceededError_1.DimensionSetExceededError(errMsg);
36996
- }
36997
- dimensionKeys.push(keys);
36998
- dimensionProperties = Object.assign(Object.assign({}, dimensionProperties), dimensionSet);
36999
- });
37000
- const createBody = () => {
37001
- return Object.assign(Object.assign(Object.assign({}, dimensionProperties), context.properties), { _aws: Object.assign(Object.assign({}, context.meta), { CloudWatchMetrics: [
37002
- {
37003
- Dimensions: dimensionKeys,
37004
- Metrics: [],
37005
- Namespace: context.namespace
37006
- }
37007
- ] }) });
37008
- };
37009
- const eventBatches = [];
37010
- let currentBody = createBody();
37011
- const currentMetricsInBody = () => currentBody._aws.CloudWatchMetrics[0].Metrics.length;
37012
- const hasMaxMetrics = () => currentMetricsInBody() === Constants_1.Constants.MAX_METRICS_PER_EVENT;
37013
- const serializeCurrentBody = () => {
37014
- eventBatches.push(JSON.stringify(currentBody));
37015
- currentBody = createBody();
37016
- };
37017
- const remainingMetrics = heap_1.MaxHeap.heapify(Array.from(context.metrics, ([key, value]) => {
37018
- return { name: key, numLeft: value.values.length };
37019
- }), (metric) => metric.numLeft);
37020
- let processedMetrics = [];
37021
- while (!remainingMetrics.isEmpty()) {
37022
- const metricProgress = remainingMetrics.extractRoot();
37023
- const metric = context.metrics.get(metricProgress.name);
37024
- if (metric) {
37025
- const startIndex = metric.values.length - metricProgress.numLeft;
37026
- const metricValue = metricProgress.numLeft === 1 ? metric.values[startIndex] : (
37027
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
37028
- metric.values.slice(startIndex, startIndex + Constants_1.Constants.MAX_VALUES_PER_METRIC)
37029
- );
37030
- currentBody[metricProgress.name] = metricValue;
37031
- const metricBody = Object.assign({ Name: metricProgress.name, Unit: metric.unit }, metric.storageResolution == StorageResolution_1.StorageResolution.High ? { StorageResolution: StorageResolution_1.StorageResolution.High } : {});
37032
- currentBody._aws.CloudWatchMetrics[0].Metrics.push(metricBody);
37033
- metricProgress.numLeft -= Constants_1.Constants.MAX_VALUES_PER_METRIC;
37034
- if (metricProgress.numLeft > 0) {
37035
- processedMetrics.push(metricProgress);
37036
- }
37037
- if (hasMaxMetrics() || remainingMetrics.isEmpty()) {
37038
- serializeCurrentBody();
37039
- processedMetrics.forEach((processingMetric) => remainingMetrics.insert(processingMetric));
37040
- processedMetrics = [];
37041
- }
37042
- }
37043
- }
37044
- if (eventBatches.length === 0 || currentMetricsInBody() > 0) {
37045
- serializeCurrentBody();
37046
- }
37047
- return eventBatches;
37048
- }
37049
- };
37050
- exports2.LogSerializer = LogSerializer;
37051
- }
37052
- });
37053
-
37054
- // node_modules/aws-embedded-metrics/lib/sinks/ConsoleSink.js
37055
- var require_ConsoleSink = __commonJS({
37056
- "node_modules/aws-embedded-metrics/lib/sinks/ConsoleSink.js"(exports2) {
37057
- "use strict";
37058
- Object.defineProperty(exports2, "__esModule", { value: true });
37059
- exports2.ConsoleSink = void 0;
37060
- var console_1 = require("console");
37061
- var LogSerializer_1 = require_LogSerializer();
37062
- var ConsoleSink = class _ConsoleSink {
37063
- constructor(serializer) {
37064
- this.name = "ConsoleSink";
37065
- this.serializer = serializer || new LogSerializer_1.LogSerializer();
37066
- this.console = process.env[_ConsoleSink.AWS_LAMBDA_LOG_FORMAT] === "JSON" ? new console_1.Console(process.stdout, process.stderr) : console;
37067
- }
37068
- accept(context) {
37069
- const events = this.serializer.serialize(context);
37070
- events.forEach((event) => this.console.log(event));
37071
- return Promise.resolve();
37072
- }
37073
- };
37074
- exports2.ConsoleSink = ConsoleSink;
37075
- ConsoleSink.AWS_LAMBDA_LOG_FORMAT = "AWS_LAMBDA_LOG_FORMAT";
37076
- }
37077
- });
37078
-
37079
- // node_modules/aws-embedded-metrics/lib/sinks/connections/TcpClient.js
37080
- var require_TcpClient = __commonJS({
37081
- "node_modules/aws-embedded-metrics/lib/sinks/connections/TcpClient.js"(exports2) {
37082
- "use strict";
37083
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37084
- function adopt(value) {
37085
- return value instanceof P ? value : new P(function(resolve) {
37086
- resolve(value);
37087
- });
37088
- }
37089
- return new (P || (P = Promise))(function(resolve, reject) {
37090
- function fulfilled(value) {
37091
- try {
37092
- step(generator.next(value));
37093
- } catch (e3) {
37094
- reject(e3);
37095
- }
37096
- }
37097
- function rejected(value) {
37098
- try {
37099
- step(generator["throw"](value));
37100
- } catch (e3) {
37101
- reject(e3);
37102
- }
37103
- }
37104
- function step(result) {
37105
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37106
- }
37107
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37108
- });
37109
- };
37110
- Object.defineProperty(exports2, "__esModule", { value: true });
37111
- exports2.TcpClient = void 0;
37112
- var net = require("net");
37113
- var Logger_1 = require_Logger();
37114
- var TcpClient = class {
37115
- constructor(endpoint) {
37116
- this.endpoint = endpoint;
37117
- this.socket = new net.Socket({ allowHalfOpen: true }).setEncoding("utf8").setKeepAlive(true).setTimeout(5e3).on("timeout", () => this.disconnect("idle timeout")).on("end", () => this.disconnect("end")).on("data", (data2) => (0, Logger_1.LOG)("TcpClient received data.", data2));
37118
- this.initialConnect.apply(this);
37119
- }
37120
- initialConnect() {
37121
- return __awaiter2(this, void 0, void 0, function* () {
37122
- return new Promise((resolve, reject) => {
37123
- this.socket.connect(this.endpoint.port, this.endpoint.host, (err) => {
37124
- if (err)
37125
- reject(err);
37126
- else
37127
- resolve();
37128
- });
37129
- });
37130
- });
37131
- }
37132
- warmup() {
37133
- return __awaiter2(this, void 0, void 0, function* () {
37134
- try {
37135
- yield this.establishConnection();
37136
- } catch (err) {
37137
- (0, Logger_1.LOG)("Failed to connect", err);
37138
- }
37139
- });
37140
- }
37141
- sendMessage(message) {
37142
- return __awaiter2(this, void 0, void 0, function* () {
37143
- yield this.waitForOpenConnection();
37144
- yield new Promise((resolve, reject) => {
37145
- const onSendError = (err) => {
37146
- (0, Logger_1.LOG)("Failed to write", err);
37147
- reject(err);
37148
- };
37149
- const wasFlushedToKernel = this.socket.write(message, (err) => {
37150
- if (!err) {
37151
- (0, Logger_1.LOG)("Write succeeded");
37152
- resolve();
37153
- } else {
37154
- onSendError(err);
37155
- }
37156
- });
37157
- if (!wasFlushedToKernel) {
37158
- (0, Logger_1.LOG)("TcpClient data was not flushed to kernel buffer and was queued in memory.");
37159
- }
37160
- });
37161
- });
37162
- }
37163
- disconnect(eventName) {
37164
- (0, Logger_1.LOG)("TcpClient disconnected due to:", eventName);
37165
- this.socket.removeAllListeners();
37166
- this.socket.destroy();
37167
- this.socket.unref();
37168
- }
37169
- waitForOpenConnection() {
37170
- return __awaiter2(this, void 0, void 0, function* () {
37171
- if (!this.socket.writable || this.socket.readyState !== "open") {
37172
- yield this.establishConnection();
37173
- }
37174
- });
37175
- }
37176
- establishConnection() {
37177
- return __awaiter2(this, void 0, void 0, function* () {
37178
- yield new Promise((resolve, reject) => {
37179
- const onError = (e3) => {
37180
- if (e3.message.includes("EISCONN")) {
37181
- resolve();
37182
- return;
37183
- }
37184
- (0, Logger_1.LOG)("TCP Client received error", e3);
37185
- this.disconnect(e3.message);
37186
- reject(e3);
37187
- };
37188
- const onConnect = () => {
37189
- this.socket.removeListener("error", onError);
37190
- (0, Logger_1.LOG)("TcpClient connected.", this.endpoint);
37191
- resolve();
37192
- };
37193
- switch (this.socket.readyState) {
37194
- case "open":
37195
- resolve();
37196
- break;
37197
- case "opening":
37198
- this.socket.once("connect", onConnect);
37199
- this.socket.once("error", onError);
37200
- break;
37201
- default:
37202
- (0, Logger_1.LOG)("opening connection with socket in state: ", this.socket.readyState);
37203
- this.socket.connect(this.endpoint.port, this.endpoint.host, onConnect).once("error", onError);
37204
- break;
37205
- }
37206
- });
37207
- });
37208
- }
37209
- };
37210
- exports2.TcpClient = TcpClient;
37211
- }
37212
- });
37213
-
37214
- // node_modules/aws-embedded-metrics/lib/sinks/connections/UdpClient.js
37215
- var require_UdpClient = __commonJS({
37216
- "node_modules/aws-embedded-metrics/lib/sinks/connections/UdpClient.js"(exports2) {
37217
- "use strict";
37218
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37219
- function adopt(value) {
37220
- return value instanceof P ? value : new P(function(resolve) {
37221
- resolve(value);
37222
- });
37223
- }
37224
- return new (P || (P = Promise))(function(resolve, reject) {
37225
- function fulfilled(value) {
37226
- try {
37227
- step(generator.next(value));
37228
- } catch (e3) {
37229
- reject(e3);
37230
- }
37231
- }
37232
- function rejected(value) {
37233
- try {
37234
- step(generator["throw"](value));
37235
- } catch (e3) {
37236
- reject(e3);
37237
- }
37238
- }
37239
- function step(result) {
37240
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37241
- }
37242
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37243
- });
37244
- };
37245
- Object.defineProperty(exports2, "__esModule", { value: true });
37246
- exports2.UdpClient = void 0;
37247
- var dgram = require("dgram");
37248
- var Logger_1 = require_Logger();
37249
- var UdpClient = class {
37250
- constructor(endpoint) {
37251
- this.endpoint = endpoint;
37252
- }
37253
- // No warm up for UDP
37254
- warmup() {
37255
- return Promise.resolve();
37256
- }
37257
- sendMessage(message) {
37258
- return __awaiter2(this, void 0, void 0, function* () {
37259
- const client = dgram.createSocket("udp4");
37260
- client.send(message, this.endpoint.port, this.endpoint.host, (error2) => {
37261
- if (error2) {
37262
- (0, Logger_1.LOG)(error2);
37263
- }
37264
- client.close();
37265
- });
37266
- return Promise.resolve();
37267
- });
37268
- }
37269
- };
37270
- exports2.UdpClient = UdpClient;
37271
- }
37272
- });
37273
-
37274
- // node_modules/aws-embedded-metrics/lib/sinks/AgentSink.js
37275
- var require_AgentSink = __commonJS({
37276
- "node_modules/aws-embedded-metrics/lib/sinks/AgentSink.js"(exports2) {
37277
- "use strict";
37278
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37279
- function adopt(value) {
37280
- return value instanceof P ? value : new P(function(resolve) {
37281
- resolve(value);
37282
- });
37283
- }
37284
- return new (P || (P = Promise))(function(resolve, reject) {
37285
- function fulfilled(value) {
37286
- try {
37287
- step(generator.next(value));
37288
- } catch (e3) {
37289
- reject(e3);
37290
- }
37291
- }
37292
- function rejected(value) {
37293
- try {
37294
- step(generator["throw"](value));
37295
- } catch (e3) {
37296
- reject(e3);
37297
- }
37298
- }
37299
- function step(result) {
37300
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37301
- }
37302
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37303
- });
37304
- };
37305
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37306
- return mod && mod.__esModule ? mod : { "default": mod };
37307
- };
37308
- Object.defineProperty(exports2, "__esModule", { value: true });
37309
- exports2.AgentSink = void 0;
37310
- var url = require("url");
37311
- var Configuration_1 = __importDefault2(require_Configuration());
37312
- var LogSerializer_1 = require_LogSerializer();
37313
- var Logger_1 = require_Logger();
37314
- var TcpClient_1 = require_TcpClient();
37315
- var UdpClient_1 = require_UdpClient();
37316
- var TCP = "tcp:";
37317
- var UDP = "udp:";
37318
- var defaultTcpEndpoint = {
37319
- host: "0.0.0.0",
37320
- port: 25888,
37321
- protocol: TCP
37322
- };
37323
- var parseEndpoint = (endpoint) => {
37324
- try {
37325
- if (!endpoint) {
37326
- return defaultTcpEndpoint;
37327
- }
37328
- const parsedUrl = url.parse(endpoint);
37329
- if (!parsedUrl.hostname || !parsedUrl.port || !parsedUrl.protocol) {
37330
- (0, Logger_1.LOG)(`Failed to parse the provided agent endpoint. Falling back to the default TCP endpoint.`, parsedUrl);
37331
- return defaultTcpEndpoint;
37332
- }
37333
- if (parsedUrl.protocol !== TCP && parsedUrl.protocol !== UDP) {
37334
- (0, Logger_1.LOG)(`The provided agent endpoint protocol '${parsedUrl.protocol}' is not supported. Please use TCP or UDP. Falling back to the default TCP endpoint.`, parsedUrl);
37335
- return defaultTcpEndpoint;
37336
- }
37337
- return {
37338
- host: parsedUrl.hostname,
37339
- port: Number(parsedUrl.port),
37340
- protocol: parsedUrl.protocol
37341
- };
37342
- } catch (e3) {
37343
- (0, Logger_1.LOG)("Failed to parse the provided agent endpoint", e3);
37344
- return defaultTcpEndpoint;
37345
- }
37346
- };
37347
- var AgentSink = class {
37348
- constructor(logGroupName, logStreamName, serializer) {
37349
- this.name = "AgentSink";
37350
- this.logGroupName = logGroupName;
37351
- this.logStreamName = logStreamName;
37352
- this.serializer = serializer || new LogSerializer_1.LogSerializer();
37353
- this.endpoint = parseEndpoint(Configuration_1.default.agentEndpoint);
37354
- this.socketClient = this.getSocketClient(this.endpoint);
37355
- (0, Logger_1.LOG)("Using socket client", this.socketClient.constructor.name);
37356
- }
37357
- accept(context) {
37358
- return __awaiter2(this, void 0, void 0, function* () {
37359
- if (this.logGroupName) {
37360
- context.meta.LogGroupName = this.logGroupName;
37361
- }
37362
- if (this.logStreamName) {
37363
- context.meta.LogStreamName = this.logStreamName;
37364
- }
37365
- const events = this.serializer.serialize(context);
37366
- (0, Logger_1.LOG)(`Sending {} events to socket.`, events.length);
37367
- for (let index = 0; index < events.length; index++) {
37368
- const event = events[index];
37369
- const message = event + "\n";
37370
- const bytes = Buffer.from(message);
37371
- yield this.socketClient.sendMessage(bytes);
37372
- }
37373
- });
37374
- }
37375
- getSocketClient(endpoint) {
37376
- (0, Logger_1.LOG)("Getting socket client for connection.", endpoint);
37377
- const client = endpoint.protocol === TCP ? new TcpClient_1.TcpClient(endpoint) : new UdpClient_1.UdpClient(endpoint);
37378
- client.warmup();
37379
- return client;
37380
- }
37381
- };
37382
- exports2.AgentSink = AgentSink;
37383
- }
37384
- });
37385
-
37386
- // node_modules/aws-embedded-metrics/lib/environment/DefaultEnvironment.js
37387
- var require_DefaultEnvironment = __commonJS({
37388
- "node_modules/aws-embedded-metrics/lib/environment/DefaultEnvironment.js"(exports2) {
37389
- "use strict";
37390
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37391
- return mod && mod.__esModule ? mod : { "default": mod };
37392
- };
37393
- Object.defineProperty(exports2, "__esModule", { value: true });
37394
- exports2.DefaultEnvironment = void 0;
37395
- var Configuration_1 = __importDefault2(require_Configuration());
37396
- var AgentSink_1 = require_AgentSink();
37397
- var Logger_1 = require_Logger();
37398
- var DefaultEnvironment = class {
37399
- probe() {
37400
- return Promise.resolve(true);
37401
- }
37402
- getName() {
37403
- if (!Configuration_1.default.serviceName) {
37404
- (0, Logger_1.LOG)("Unknown ServiceName.");
37405
- return "Unknown";
37406
- }
37407
- return Configuration_1.default.serviceName;
37408
- }
37409
- getType() {
37410
- if (!Configuration_1.default.serviceType) {
37411
- (0, Logger_1.LOG)("Unknown ServiceType.");
37412
- return "Unknown";
37413
- }
37414
- return Configuration_1.default.serviceType;
37415
- }
37416
- getLogGroupName() {
37417
- if (Configuration_1.default.logGroupName === "") {
37418
- return "";
37419
- }
37420
- return Configuration_1.default.logGroupName ? Configuration_1.default.logGroupName : `${this.getName()}-metrics`;
37421
- }
37422
- configureContext() {
37423
- }
37424
- getSink() {
37425
- if (!this.sink) {
37426
- this.sink = new AgentSink_1.AgentSink(this.getLogGroupName(), Configuration_1.default.logStreamName);
37427
- }
37428
- return this.sink;
37429
- }
37430
- };
37431
- exports2.DefaultEnvironment = DefaultEnvironment;
37432
- }
37433
- });
37434
-
37435
- // node_modules/aws-embedded-metrics/lib/utils/Fetch.js
37436
- var require_Fetch = __commonJS({
37437
- "node_modules/aws-embedded-metrics/lib/utils/Fetch.js"(exports2) {
37438
- "use strict";
37439
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37440
- function adopt(value) {
37441
- return value instanceof P ? value : new P(function(resolve) {
37442
- resolve(value);
37443
- });
37444
- }
37445
- return new (P || (P = Promise))(function(resolve, reject) {
37446
- function fulfilled(value) {
37447
- try {
37448
- step(generator.next(value));
37449
- } catch (e3) {
37450
- reject(e3);
37451
- }
37452
- }
37453
- function rejected(value) {
37454
- try {
37455
- step(generator["throw"](value));
37456
- } catch (e3) {
37457
- reject(e3);
37458
- }
37459
- }
37460
- function step(result) {
37461
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37462
- }
37463
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37464
- });
37465
- };
37466
- Object.defineProperty(exports2, "__esModule", { value: true });
37467
- exports2.fetchString = exports2.fetchJSON = exports2.fetch = void 0;
37468
- var http_1 = require("http");
37469
- var SOCKET_TIMEOUT = 1e3;
37470
- var fetch2 = (options) => {
37471
- return new Promise((resolve, reject) => {
37472
- const request = (0, http_1.request)(options, (response) => {
37473
- if (!response.statusCode) {
37474
- reject(`Received undefined response status code from '${options.host || "unknown"}/${options.path || "unknown"}'`);
37475
- return;
37476
- }
37477
- if (response.statusCode < 200 || response.statusCode > 299) {
37478
- reject(new Error(`Failed to load page, status code: ${response.statusCode}`));
37479
- return;
37480
- }
37481
- const body = [];
37482
- let bodyBytes = 0;
37483
- response.on("data", (chunk) => {
37484
- bodyBytes += chunk.length;
37485
- body.push(chunk);
37486
- });
37487
- response.on("end", () => {
37488
- const buffer = Buffer.concat(body, bodyBytes);
37489
- resolve(buffer);
37490
- });
37491
- }).on("error", (err) => {
37492
- reject(err);
37493
- });
37494
- request.on("socket", (socket) => {
37495
- socket.on("timeout", () => {
37496
- request.abort();
37497
- reject(`Socket timeout while connecting to '${options.host || "unknown"}/${options.path || "unknown"}'`);
37498
- });
37499
- socket.setTimeout(SOCKET_TIMEOUT);
37500
- });
37501
- request.end();
37502
- });
37503
- };
37504
- exports2.fetch = fetch2;
37505
- var fetchString = (options) => __awaiter2(void 0, void 0, void 0, function* () {
37506
- const buffer = yield fetch2(options);
37507
- return buffer.toString();
37508
- });
37509
- exports2.fetchString = fetchString;
37510
- var fetchJSON = (options) => __awaiter2(void 0, void 0, void 0, function* () {
37511
- const responseString = yield fetchString(options);
37512
- return JSON.parse(responseString);
37513
- });
37514
- exports2.fetchJSON = fetchJSON;
37515
- }
37516
- });
37517
-
37518
- // node_modules/aws-embedded-metrics/lib/environment/ECSEnvironment.js
37519
- var require_ECSEnvironment = __commonJS({
37520
- "node_modules/aws-embedded-metrics/lib/environment/ECSEnvironment.js"(exports2) {
37521
- "use strict";
37522
- var __createBinding2 = exports2 && exports2.__createBinding || (Object.create ? (function(o3, m3, k3, k22) {
37523
- if (k22 === void 0) k22 = k3;
37524
- var desc = Object.getOwnPropertyDescriptor(m3, k3);
37525
- if (!desc || ("get" in desc ? !m3.__esModule : desc.writable || desc.configurable)) {
37526
- desc = { enumerable: true, get: function() {
37527
- return m3[k3];
37528
- } };
37529
- }
37530
- Object.defineProperty(o3, k22, desc);
37531
- }) : (function(o3, m3, k3, k22) {
37532
- if (k22 === void 0) k22 = k3;
37533
- o3[k22] = m3[k3];
37534
- }));
37535
- var __setModuleDefault2 = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o3, v3) {
37536
- Object.defineProperty(o3, "default", { enumerable: true, value: v3 });
37537
- }) : function(o3, v3) {
37538
- o3["default"] = v3;
37539
- });
37540
- var __importStar2 = exports2 && exports2.__importStar || function(mod) {
37541
- if (mod && mod.__esModule) return mod;
37542
- var result = {};
37543
- if (mod != null) {
37544
- for (var k3 in mod) if (k3 !== "default" && Object.prototype.hasOwnProperty.call(mod, k3)) __createBinding2(result, mod, k3);
37545
- }
37546
- __setModuleDefault2(result, mod);
37547
- return result;
37548
- };
37549
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37550
- function adopt(value) {
37551
- return value instanceof P ? value : new P(function(resolve) {
37552
- resolve(value);
37553
- });
37554
- }
37555
- return new (P || (P = Promise))(function(resolve, reject) {
37556
- function fulfilled(value) {
37557
- try {
37558
- step(generator.next(value));
37559
- } catch (e3) {
37560
- reject(e3);
37561
- }
37562
- }
37563
- function rejected(value) {
37564
- try {
37565
- step(generator["throw"](value));
37566
- } catch (e3) {
37567
- reject(e3);
37568
- }
37569
- }
37570
- function step(result) {
37571
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37572
- }
37573
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37574
- });
37575
- };
37576
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37577
- return mod && mod.__esModule ? mod : { "default": mod };
37578
- };
37579
- Object.defineProperty(exports2, "__esModule", { value: true });
37580
- exports2.ECSEnvironment = void 0;
37581
- var Configuration_1 = __importDefault2(require_Configuration());
37582
- var AgentSink_1 = require_AgentSink();
37583
- var Fetch_1 = require_Fetch();
37584
- var Logger_1 = require_Logger();
37585
- var os = __importStar2(require("os"));
37586
- var Constants_1 = require_Constants();
37587
- var formatImageName = (imageName) => {
37588
- if (imageName) {
37589
- const splitImageName = imageName.split("/");
37590
- return splitImageName[splitImageName.length - 1];
37591
- }
37592
- return imageName;
37593
- };
37594
- var ECSEnvironment = class {
37595
- probe() {
37596
- return __awaiter2(this, void 0, void 0, function* () {
37597
- if (!process.env.ECS_CONTAINER_METADATA_URI) {
37598
- return Promise.resolve(false);
37599
- }
37600
- if (process.env.FLUENT_HOST && !Configuration_1.default.agentEndpoint) {
37601
- this.fluentBitEndpoint = `tcp://${process.env.FLUENT_HOST}:${Constants_1.Constants.DEFAULT_AGENT_PORT}`;
37602
- Configuration_1.default.agentEndpoint = this.fluentBitEndpoint;
37603
- (0, Logger_1.LOG)(`Using FluentBit configuration. Endpoint: ${this.fluentBitEndpoint}`);
37604
- }
37605
- try {
37606
- const options = new URL(process.env.ECS_CONTAINER_METADATA_URI);
37607
- this.metadata = yield (0, Fetch_1.fetchJSON)(options);
37608
- if (this.metadata) {
37609
- this.metadata.FormattedImageName = formatImageName(this.metadata.Image);
37610
- (0, Logger_1.LOG)(`Successfully collected ECS Container metadata.`);
37611
- }
37612
- } catch (e3) {
37613
- (0, Logger_1.LOG)("Failed to collect ECS Container Metadata.");
37614
- (0, Logger_1.LOG)(e3);
37615
- }
37616
- return true;
37617
- });
37618
- }
37619
- getName() {
37620
- var _a2;
37621
- if (Configuration_1.default.serviceName) {
37622
- return Configuration_1.default.serviceName;
37623
- }
37624
- return ((_a2 = this.metadata) === null || _a2 === void 0 ? void 0 : _a2.FormattedImageName) ? this.metadata.FormattedImageName : "Unknown";
37625
- }
37626
- getType() {
37627
- return "AWS::ECS::Container";
37628
- }
37629
- getLogGroupName() {
37630
- if (this.fluentBitEndpoint) {
37631
- return "";
37632
- }
37633
- return Configuration_1.default.logGroupName || this.getName();
37634
- }
37635
- configureContext(context) {
37636
- var _a2, _b, _c3, _d, _e3;
37637
- this.addProperty(context, "containerId", os.hostname());
37638
- this.addProperty(context, "createdAt", (_a2 = this.metadata) === null || _a2 === void 0 ? void 0 : _a2.CreatedAt);
37639
- this.addProperty(context, "startedAt", (_b = this.metadata) === null || _b === void 0 ? void 0 : _b.StartedAt);
37640
- this.addProperty(context, "image", (_c3 = this.metadata) === null || _c3 === void 0 ? void 0 : _c3.Image);
37641
- this.addProperty(context, "cluster", (_d = this.metadata) === null || _d === void 0 ? void 0 : _d.Labels["com.amazonaws.ecs.cluster"]);
37642
- this.addProperty(context, "taskArn", (_e3 = this.metadata) === null || _e3 === void 0 ? void 0 : _e3.Labels["com.amazonaws.ecs.task-arn"]);
37643
- if (this.fluentBitEndpoint) {
37644
- context.setDefaultDimensions({
37645
- ServiceName: Configuration_1.default.serviceName || this.getName(),
37646
- ServiceType: Configuration_1.default.serviceType || this.getType()
37647
- });
37648
- }
37649
- }
37650
- getSink() {
37651
- if (!this.sink) {
37652
- const logGroupName = this.fluentBitEndpoint ? "" : this.getLogGroupName();
37653
- this.sink = new AgentSink_1.AgentSink(logGroupName);
37654
- }
37655
- return this.sink;
37656
- }
37657
- addProperty(context, key, value) {
37658
- if (value) {
37659
- context.setProperty(key, value);
37660
- }
37661
- }
37662
- };
37663
- exports2.ECSEnvironment = ECSEnvironment;
37664
- }
37665
- });
37666
-
37667
- // node_modules/aws-embedded-metrics/lib/environment/EC2Environment.js
37668
- var require_EC2Environment = __commonJS({
37669
- "node_modules/aws-embedded-metrics/lib/environment/EC2Environment.js"(exports2) {
37670
- "use strict";
37671
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37672
- function adopt(value) {
37673
- return value instanceof P ? value : new P(function(resolve) {
37674
- resolve(value);
37675
- });
37676
- }
37677
- return new (P || (P = Promise))(function(resolve, reject) {
37678
- function fulfilled(value) {
37679
- try {
37680
- step(generator.next(value));
37681
- } catch (e3) {
37682
- reject(e3);
37683
- }
37684
- }
37685
- function rejected(value) {
37686
- try {
37687
- step(generator["throw"](value));
37688
- } catch (e3) {
37689
- reject(e3);
37690
- }
37691
- }
37692
- function step(result) {
37693
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37694
- }
37695
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37696
- });
37697
- };
37698
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37699
- return mod && mod.__esModule ? mod : { "default": mod };
37700
- };
37701
- Object.defineProperty(exports2, "__esModule", { value: true });
37702
- exports2.EC2Environment = void 0;
37703
- var Configuration_1 = __importDefault2(require_Configuration());
37704
- var AgentSink_1 = require_AgentSink();
37705
- var Fetch_1 = require_Fetch();
37706
- var Logger_1 = require_Logger();
37707
- var host = "169.254.169.254";
37708
- var tokenPath = "/latest/api/token";
37709
- var tokenRequestHeaderKey = "X-aws-ec2-metadata-token-ttl-seconds";
37710
- var tokenRequestHeaderValue = "21600";
37711
- var metadataPath = "/latest/dynamic/instance-identity/document";
37712
- var metadataRequestTokenHeaderKey = "X-aws-ec2-metadata-token";
37713
- var EC2Environment = class {
37714
- probe() {
37715
- return __awaiter2(this, void 0, void 0, function* () {
37716
- try {
37717
- const options = {
37718
- host,
37719
- path: tokenPath,
37720
- method: "PUT",
37721
- headers: { [tokenRequestHeaderKey]: tokenRequestHeaderValue }
37722
- };
37723
- this.token = yield (0, Fetch_1.fetchString)(options);
37724
- } catch (e3) {
37725
- (0, Logger_1.LOG)(e3);
37726
- return false;
37727
- }
37728
- try {
37729
- const metadataOptions = {
37730
- host,
37731
- path: metadataPath,
37732
- method: "GET",
37733
- headers: { [metadataRequestTokenHeaderKey]: this.token }
37734
- };
37735
- this.metadata = yield (0, Fetch_1.fetchJSON)(metadataOptions);
37736
- return !!this.metadata;
37737
- } catch (e3) {
37738
- (0, Logger_1.LOG)(e3);
37739
- return false;
37740
- }
37741
- });
37742
- }
37743
- getName() {
37744
- if (!Configuration_1.default.serviceName) {
37745
- (0, Logger_1.LOG)("Unknown ServiceName.");
37746
- return "Unknown";
37747
- }
37748
- return Configuration_1.default.serviceName;
37749
- }
37750
- getType() {
37751
- if (this.metadata) {
37752
- return "AWS::EC2::Instance";
37753
- }
37754
- return "Unknown";
37755
- }
37756
- getLogGroupName() {
37757
- return Configuration_1.default.logGroupName ? Configuration_1.default.logGroupName : `${this.getName()}-metrics`;
37758
- }
37759
- configureContext(context) {
37760
- if (this.metadata) {
37761
- context.setProperty("imageId", this.metadata.imageId);
37762
- context.setProperty("instanceId", this.metadata.instanceId);
37763
- context.setProperty("instanceType", this.metadata.instanceType);
37764
- context.setProperty("privateIP", this.metadata.privateIp);
37765
- context.setProperty("availabilityZone", this.metadata.availabilityZone);
37766
- }
37767
- }
37768
- getSink() {
37769
- if (!this.sink) {
37770
- this.sink = new AgentSink_1.AgentSink(this.getLogGroupName(), Configuration_1.default.logStreamName);
37771
- }
37772
- return this.sink;
37773
- }
37774
- };
37775
- exports2.EC2Environment = EC2Environment;
37776
- }
37777
- });
37778
-
37779
- // node_modules/aws-embedded-metrics/lib/environment/LambdaEnvironment.js
37780
- var require_LambdaEnvironment = __commonJS({
37781
- "node_modules/aws-embedded-metrics/lib/environment/LambdaEnvironment.js"(exports2) {
37782
- "use strict";
37783
- Object.defineProperty(exports2, "__esModule", { value: true });
37784
- exports2.LambdaEnvironment = void 0;
37785
- var ConsoleSink_1 = require_ConsoleSink();
37786
- var LambdaEnvironment = class {
37787
- probe() {
37788
- return Promise.resolve(process.env.AWS_LAMBDA_FUNCTION_NAME ? true : false);
37789
- }
37790
- getName() {
37791
- return process.env.AWS_LAMBDA_FUNCTION_NAME || "Unknown";
37792
- }
37793
- getType() {
37794
- return "AWS::Lambda::Function";
37795
- }
37796
- getLogGroupName() {
37797
- return this.getName();
37798
- }
37799
- configureContext(context) {
37800
- this.addProperty(context, "executionEnvironment", process.env.AWS_EXECUTION_ENV);
37801
- this.addProperty(context, "memorySize", process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE);
37802
- this.addProperty(context, "functionVersion", process.env.AWS_LAMBDA_FUNCTION_VERSION);
37803
- this.addProperty(context, "logStreamId", process.env.AWS_LAMBDA_LOG_STREAM_NAME);
37804
- const trace = this.getSampledTrace();
37805
- if (trace) {
37806
- this.addProperty(context, "traceId", trace);
37807
- }
37808
- }
37809
- getSink() {
37810
- if (!this.sink) {
37811
- this.sink = new ConsoleSink_1.ConsoleSink();
37812
- }
37813
- return this.sink;
37814
- }
37815
- addProperty(context, key, value) {
37816
- if (value) {
37817
- context.setProperty(key, value);
37818
- }
37819
- }
37820
- getSampledTrace() {
37821
- if (process.env._X_AMZN_TRACE_ID && process.env._X_AMZN_TRACE_ID.includes("Sampled=1")) {
37822
- return process.env._X_AMZN_TRACE_ID;
37823
- }
37824
- }
37825
- };
37826
- exports2.LambdaEnvironment = LambdaEnvironment;
37827
- }
37828
- });
37829
-
37830
- // node_modules/aws-embedded-metrics/lib/environment/LocalEnvironment.js
37831
- var require_LocalEnvironment = __commonJS({
37832
- "node_modules/aws-embedded-metrics/lib/environment/LocalEnvironment.js"(exports2) {
37833
- "use strict";
37834
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37835
- return mod && mod.__esModule ? mod : { "default": mod };
37836
- };
37837
- Object.defineProperty(exports2, "__esModule", { value: true });
37838
- exports2.LocalEnvironment = void 0;
37839
- var Configuration_1 = __importDefault2(require_Configuration());
37840
- var Logger_1 = require_Logger();
37841
- var ConsoleSink_1 = require_ConsoleSink();
37842
- var LocalEnvironment = class {
37843
- probe() {
37844
- return Promise.resolve(false);
37845
- }
37846
- getName() {
37847
- if (!Configuration_1.default.serviceName) {
37848
- (0, Logger_1.LOG)("Unknown ServiceName.");
37849
- return "Unknown";
37850
- }
37851
- return Configuration_1.default.serviceName;
37852
- }
37853
- getType() {
37854
- if (!Configuration_1.default.serviceType) {
37855
- (0, Logger_1.LOG)("Unknown ServiceType.");
37856
- return "Unknown";
37857
- }
37858
- return Configuration_1.default.serviceType;
37859
- }
37860
- getLogGroupName() {
37861
- return Configuration_1.default.logGroupName ? Configuration_1.default.logGroupName : `${this.getName()}-metrics`;
37862
- }
37863
- configureContext() {
37864
- }
37865
- getSink() {
37866
- if (!this.sink) {
37867
- this.sink = new ConsoleSink_1.ConsoleSink();
37868
- }
37869
- return this.sink;
37870
- }
37871
- };
37872
- exports2.LocalEnvironment = LocalEnvironment;
37873
- }
37874
- });
37875
-
37876
- // node_modules/aws-embedded-metrics/lib/environment/EnvironmentDetector.js
37877
- var require_EnvironmentDetector = __commonJS({
37878
- "node_modules/aws-embedded-metrics/lib/environment/EnvironmentDetector.js"(exports2) {
37879
- "use strict";
37880
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
37881
- function adopt(value) {
37882
- return value instanceof P ? value : new P(function(resolve) {
37883
- resolve(value);
37884
- });
37885
- }
37886
- return new (P || (P = Promise))(function(resolve, reject) {
37887
- function fulfilled(value) {
37888
- try {
37889
- step(generator.next(value));
37890
- } catch (e3) {
37891
- reject(e3);
37892
- }
37893
- }
37894
- function rejected(value) {
37895
- try {
37896
- step(generator["throw"](value));
37897
- } catch (e3) {
37898
- reject(e3);
37899
- }
37900
- }
37901
- function step(result) {
37902
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
37903
- }
37904
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37905
- });
37906
- };
37907
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
37908
- return mod && mod.__esModule ? mod : { "default": mod };
37909
- };
37910
- Object.defineProperty(exports2, "__esModule", { value: true });
37911
- exports2.cleanResolveEnvironment = exports2.resolveEnvironment = void 0;
37912
- var Logger_1 = require_Logger();
37913
- var DefaultEnvironment_1 = require_DefaultEnvironment();
37914
- var ECSEnvironment_1 = require_ECSEnvironment();
37915
- var EC2Environment_1 = require_EC2Environment();
37916
- var LambdaEnvironment_1 = require_LambdaEnvironment();
37917
- var Configuration_1 = __importDefault2(require_Configuration());
37918
- var Environments_1 = __importDefault2(require_Environments());
37919
- var LocalEnvironment_1 = require_LocalEnvironment();
37920
- var lambdaEnvironment = new LambdaEnvironment_1.LambdaEnvironment();
37921
- var ecsEnvironment = new ECSEnvironment_1.ECSEnvironment();
37922
- var ec2Environment = new EC2Environment_1.EC2Environment();
37923
- var defaultEnvironment = new DefaultEnvironment_1.DefaultEnvironment();
37924
- var environments = [lambdaEnvironment, ecsEnvironment, ec2Environment];
37925
- var environment = void 0;
37926
- var getEnvironmentFromOverride = () => {
37927
- switch (Configuration_1.default.environmentOverride) {
37928
- case Environments_1.default.Agent:
37929
- return defaultEnvironment;
37930
- case Environments_1.default.EC2:
37931
- return ec2Environment;
37932
- case Environments_1.default.Lambda:
37933
- return lambdaEnvironment;
37934
- case Environments_1.default.ECS:
37935
- return ecsEnvironment;
37936
- case Environments_1.default.Local:
37937
- return new LocalEnvironment_1.LocalEnvironment();
37938
- case Environments_1.default.Unknown:
37939
- default:
37940
- return void 0;
37941
- }
37942
- };
37943
- var discoverEnvironment = () => __awaiter2(void 0, void 0, void 0, function* () {
37944
- (0, Logger_1.LOG)(`Discovering environment`);
37945
- for (const envUnderTest of environments) {
37946
- (0, Logger_1.LOG)(`Testing: ${envUnderTest.constructor.name}`);
37947
- try {
37948
- if (yield envUnderTest.probe()) {
37949
- return envUnderTest;
37950
- }
37951
- } catch (e3) {
37952
- (0, Logger_1.LOG)(`Failed probe: ${envUnderTest.constructor.name}`);
37953
- }
37954
- }
37955
- return defaultEnvironment;
37956
- });
37957
- var _resolveEnvironment = () => __awaiter2(void 0, void 0, void 0, function* () {
37958
- (0, Logger_1.LOG)("Resolving environment");
37959
- if (environment) {
37960
- return environment;
37961
- }
37962
- if (Configuration_1.default.environmentOverride) {
37963
- (0, Logger_1.LOG)("Environment override supplied", Configuration_1.default.environmentOverride);
37964
- environment = getEnvironmentFromOverride();
37965
- if (environment) {
37966
- return environment;
37967
- } else {
37968
- (0, Logger_1.LOG)("Invalid environment provided. Falling back to auto-discovery.", Configuration_1.default.environmentOverride);
37969
- }
37970
- }
37971
- environment = yield discoverEnvironment();
37972
- return environment;
37973
- });
37974
- var environmentPromise = _resolveEnvironment();
37975
- var resolveEnvironment = () => __awaiter2(void 0, void 0, void 0, function* () {
37976
- return environmentPromise;
37977
- });
37978
- exports2.resolveEnvironment = resolveEnvironment;
37979
- var cleanResolveEnvironment = () => __awaiter2(void 0, void 0, void 0, function* () {
37980
- yield environmentPromise;
37981
- environment = void 0;
37982
- return yield _resolveEnvironment();
37983
- });
37984
- exports2.cleanResolveEnvironment = cleanResolveEnvironment;
37985
- }
37986
- });
37987
-
37988
- // node_modules/aws-embedded-metrics/lib/logger/MetricsLoggerFactory.js
37989
- var require_MetricsLoggerFactory = __commonJS({
37990
- "node_modules/aws-embedded-metrics/lib/logger/MetricsLoggerFactory.js"(exports2) {
37991
- "use strict";
37992
- Object.defineProperty(exports2, "__esModule", { value: true });
37993
- exports2.createMetricsLogger = void 0;
37994
- var __1 = require_lib();
37995
- var EnvironmentDetector_1 = require_EnvironmentDetector();
37996
- var MetricsContext_1 = require_MetricsContext();
37997
- var createMetricsLogger = () => {
37998
- const context = MetricsContext_1.MetricsContext.empty();
37999
- return new __1.MetricsLogger(EnvironmentDetector_1.resolveEnvironment, context);
38000
- };
38001
- exports2.createMetricsLogger = createMetricsLogger;
38002
- }
38003
- });
38004
-
38005
- // node_modules/aws-embedded-metrics/lib/logger/MetricScope.js
38006
- var require_MetricScope = __commonJS({
38007
- "node_modules/aws-embedded-metrics/lib/logger/MetricScope.js"(exports2) {
38008
- "use strict";
38009
- var __awaiter2 = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
38010
- function adopt(value) {
38011
- return value instanceof P ? value : new P(function(resolve) {
38012
- resolve(value);
38013
- });
38014
- }
38015
- return new (P || (P = Promise))(function(resolve, reject) {
38016
- function fulfilled(value) {
38017
- try {
38018
- step(generator.next(value));
38019
- } catch (e3) {
38020
- reject(e3);
38021
- }
38022
- }
38023
- function rejected(value) {
38024
- try {
38025
- step(generator["throw"](value));
38026
- } catch (e3) {
38027
- reject(e3);
38028
- }
38029
- }
38030
- function step(result) {
38031
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
38032
- }
38033
- step((generator = generator.apply(thisArg, _arguments || [])).next());
38034
- });
38035
- };
38036
- Object.defineProperty(exports2, "__esModule", { value: true });
38037
- exports2.metricScope = void 0;
38038
- var Logger_1 = require_Logger();
38039
- var MetricsLoggerFactory_1 = require_MetricsLoggerFactory();
38040
- var metricScope2 = (handler2) => {
38041
- const wrappedHandler = (...args) => __awaiter2(void 0, void 0, void 0, function* () {
38042
- const metrics = (0, MetricsLoggerFactory_1.createMetricsLogger)();
38043
- try {
38044
- return yield handler2(metrics)(...args);
38045
- } finally {
38046
- try {
38047
- yield metrics.flush();
38048
- } catch (e3) {
38049
- (0, Logger_1.LOG)("Failed to flush metrics", e3);
38050
- }
38051
- }
38052
- });
38053
- return wrappedHandler;
38054
- };
38055
- exports2.metricScope = metricScope2;
38056
- }
38057
- });
38058
-
38059
- // node_modules/aws-embedded-metrics/lib/index.js
38060
- var require_lib = __commonJS({
38061
- "node_modules/aws-embedded-metrics/lib/index.js"(exports2) {
38062
- "use strict";
38063
- var __importDefault2 = exports2 && exports2.__importDefault || function(mod) {
38064
- return mod && mod.__esModule ? mod : { "default": mod };
38065
- };
38066
- Object.defineProperty(exports2, "__esModule", { value: true });
38067
- exports2.Configuration = exports2.StorageResolution = exports2.Unit = exports2.createMetricsLogger = exports2.metricScope = exports2.AgentSink = exports2.LocalSink = exports2.MetricsLogger = void 0;
38068
- var MetricsLogger_1 = require_MetricsLogger();
38069
- Object.defineProperty(exports2, "MetricsLogger", { enumerable: true, get: function() {
38070
- return MetricsLogger_1.MetricsLogger;
38071
- } });
38072
- var ConsoleSink_1 = require_ConsoleSink();
38073
- Object.defineProperty(exports2, "LocalSink", { enumerable: true, get: function() {
38074
- return ConsoleSink_1.ConsoleSink;
38075
- } });
38076
- var AgentSink_1 = require_AgentSink();
38077
- Object.defineProperty(exports2, "AgentSink", { enumerable: true, get: function() {
38078
- return AgentSink_1.AgentSink;
38079
- } });
38080
- var MetricScope_1 = require_MetricScope();
38081
- Object.defineProperty(exports2, "metricScope", { enumerable: true, get: function() {
38082
- return MetricScope_1.metricScope;
38083
- } });
38084
- var MetricsLoggerFactory_1 = require_MetricsLoggerFactory();
38085
- Object.defineProperty(exports2, "createMetricsLogger", { enumerable: true, get: function() {
38086
- return MetricsLoggerFactory_1.createMetricsLogger;
38087
- } });
38088
- var Unit_1 = require_Unit();
38089
- Object.defineProperty(exports2, "Unit", { enumerable: true, get: function() {
38090
- return Unit_1.Unit;
38091
- } });
38092
- var StorageResolution_1 = require_StorageResolution();
38093
- Object.defineProperty(exports2, "StorageResolution", { enumerable: true, get: function() {
38094
- return StorageResolution_1.StorageResolution;
38095
- } });
38096
- var Configuration_1 = __importDefault2(require_Configuration());
38097
- exports2.Configuration = Configuration_1.default;
38098
- }
38099
- });
38100
-
38101
35719
  // node_modules/@sindresorhus/is/dist/index.js
38102
35720
  var require_dist = __commonJS({
38103
35721
  "node_modules/@sindresorhus/is/dist/index.js"(exports2, module2) {
@@ -68922,26 +66540,22 @@ var require_aws_xray = __commonJS({
68922
66540
  });
68923
66541
 
68924
66542
  // node_modules/aws-xray-sdk-core/dist/lib/index.js
68925
- var require_lib2 = __commonJS({
66543
+ var require_lib = __commonJS({
68926
66544
  "node_modules/aws-xray-sdk-core/dist/lib/index.js"(exports2, module2) {
68927
66545
  "use strict";
68928
66546
  module2.exports = require_aws_xray();
68929
66547
  }
68930
66548
  });
68931
66549
 
68932
- // src/backend/package-stats/package-stats.lambda.ts
68933
- var package_stats_lambda_exports = {};
68934
- __export(package_stats_lambda_exports, {
66550
+ // src/backend/package-stats/package-stats-processor.lambda.ts
66551
+ var package_stats_processor_lambda_exports = {};
66552
+ __export(package_stats_processor_lambda_exports, {
68935
66553
  handler: () => handler
68936
66554
  });
68937
- module.exports = __toCommonJS(package_stats_lambda_exports);
68938
- var import_client_s33 = __toESM(require_dist_cjs70());
68939
- var import_aws_embedded_metrics = __toESM(require_lib());
66555
+ module.exports = __toCommonJS(package_stats_processor_lambda_exports);
66556
+ var import_client_s32 = __toESM(require_dist_cjs70());
68940
66557
  var import_got = __toESM(require_source5());
68941
66558
 
68942
- // src/backend/package-stats/constants.ts
68943
- var METRICS_NAMESPACE = "ConstructHub/PackageStats";
68944
-
68945
66559
  // src/backend/package-stats/npm-downloads.lambda-shared.ts
68946
66560
  var NpmDownloadsClient = class _NpmDownloadsClient {
68947
66561
  static {
@@ -69065,41 +66679,13 @@ function isSingleDownloadsEntry(data2) {
69065
66679
  return "downloads" in data2 && typeof data2.downloads === "number";
69066
66680
  }
69067
66681
 
69068
- // src/caching.ts
69069
- var CacheStrategy = class _CacheStrategy {
69070
- constructor(cacheControl) {
69071
- this.cacheControl = cacheControl;
69072
- }
69073
- /**
69074
- * Default caching policy for all S3 objects.
69075
- */
69076
- static default() {
69077
- return new _CacheStrategy([
69078
- "public",
69079
- "max-age=300",
69080
- "must-revalidate",
69081
- "s-maxage=60",
69082
- "proxy-revalidate"
69083
- ]);
69084
- }
69085
- toString() {
69086
- return this.cacheControl.join(", ");
69087
- }
69088
- toArray() {
69089
- return this.cacheControl;
69090
- }
69091
- };
69092
-
69093
- // src/backend/catalog-builder/client.lambda-shared.ts
69094
- var import_client_s32 = __toESM(require_dist_cjs70());
69095
-
69096
66682
  // src/backend/shared/aws.lambda-shared.ts
69097
66683
  var import_client_ecs = __toESM(require_dist_cjs71());
69098
66684
  var import_client_lambda = __toESM(require_dist_cjs72());
69099
66685
  var import_client_s3 = __toESM(require_dist_cjs70());
69100
66686
  var import_client_sfn = __toESM(require_dist_cjs73());
69101
66687
  var import_client_sqs = __toESM(require_dist_cjs75());
69102
- var AWSXRay = __toESM(require_lib2());
66688
+ var AWSXRay = __toESM(require_lib());
69103
66689
  AWSXRay.setContextMissingStrategy(() => {
69104
66690
  });
69105
66691
  var S3_CLIENT = AWSXRay.captureAWSv3Client(new import_client_s3.S3Client({}));
@@ -69120,152 +66706,46 @@ function requireEnv(name) {
69120
66706
  return result;
69121
66707
  }
69122
66708
 
69123
- // src/backend/catalog-builder/client.lambda-shared.ts
69124
- var CatalogNotFoundError = class extends Error {
69125
- constructor(key) {
69126
- super(`No catalog was found at ${key}`);
69127
- }
69128
- };
69129
- var CatalogClient = class _CatalogClient {
69130
- /**
69131
- * Creates a new client for accessing the catalog.
69132
- */
69133
- static async newClient() {
69134
- const client = new _CatalogClient();
69135
- await client.init();
69136
- return client;
69137
- }
69138
- constructor() {
69139
- this.bucketName = requireEnv("CATALOG_BUCKET_NAME");
69140
- this.objectKey = requireEnv("CATALOG_OBJECT_KEY");
69141
- this.s3Client = S3_CLIENT;
69142
- }
69143
- /**
69144
- * Downloads the catalog object and stores it in memory.
69145
- */
69146
- async init() {
69147
- if (this._packages) {
69148
- throw new Error("init() cannot be called twice");
69149
- }
69150
- this._packages = [];
69151
- const params = {
69152
- Bucket: this.bucketName,
69153
- Key: this.objectKey
69154
- };
69155
- let contents;
69156
- try {
69157
- const res = await this.s3Client.send(new import_client_s32.GetObjectCommand(params));
69158
- contents = await res.Body?.transformToString("utf-8");
69159
- } catch (e3) {
69160
- throw new CatalogNotFoundError(`${this.bucketName}/${this.objectKey}`);
69161
- }
69162
- if (!contents) {
69163
- throw new Error(
69164
- `Catalog body is empty at ${this.bucketName}/${this.objectKey}`
69165
- );
69166
- }
69167
- try {
69168
- const data2 = JSON.parse(contents);
69169
- if (typeof data2 != "object") {
69170
- throw new Error("Invalid format in catalog file. Expecting a map");
69171
- }
69172
- this._packages = data2.packages;
69173
- } catch (e3) {
69174
- throw new Error(
69175
- `Unable to parse catalog file ${this.bucketName}/${this.objectKey}: ${e3}`
69176
- );
69177
- }
69178
- }
69179
- /**
69180
- * Returns a copy of the catalog list.
69181
- */
69182
- get packages() {
69183
- if (!this._packages) {
69184
- throw new Error("CatalogClient must be initialized");
69185
- }
69186
- return [...this._packages];
69187
- }
69188
- };
69189
-
69190
- // src/backend/package-stats/package-stats.lambda.ts
69191
- async function handler(event, context) {
69192
- console.log(JSON.stringify(event, null, 2));
66709
+ // src/backend/package-stats/package-stats-processor.lambda.ts
66710
+ async function handler(event) {
66711
+ const { packages, chunkIndex } = event;
69193
66712
  const STATS_BUCKET_NAME = requireEnv("STATS_BUCKET_NAME");
69194
- const STATS_OBJECT_KEY = requireEnv("STATS_OBJECT_KEY");
69195
- const catalogClient = await CatalogClient.newClient();
69196
- const catalog = catalogClient.packages;
69197
- if (catalog.length === 0) {
69198
- throw new Error("No packages found.");
69199
- }
69200
- const currentDate = (/* @__PURE__ */ new Date()).toISOString();
69201
- const stats = { packages: {}, updated: currentDate };
69202
- const npmClient = new NpmDownloadsClient(import_got.default);
69203
- const packageNames = [...new Set(catalog.map((pkg) => pkg.name)).values()];
69204
66713
  console.log(
69205
- `Retrieving download stats for all ${packageNames.length} registered packages: [${packageNames.join(",")}].`
66714
+ `Processing chunk ${chunkIndex} with ${packages.length} packages`
69206
66715
  );
69207
- const npmDownloads = await npmClient.getDownloads(packageNames, {
66716
+ const npmClient = new NpmDownloadsClient(import_got.default);
66717
+ const npmDownloads = await npmClient.getDownloads(packages, {
69208
66718
  period: "last-week" /* LAST_WEEK */,
69209
66719
  throwErrors: false
69210
66720
  });
66721
+ const chunkStats = {};
69211
66722
  for (const [pkgName, entry] of npmDownloads.entries()) {
69212
- updateStats(stats, pkgName, entry);
69213
- }
69214
- const statsCount = Object.keys(stats.packages).length;
69215
- console.log(`There are now ${statsCount} packages with NPM stats stored.`);
69216
- await (0, import_aws_embedded_metrics.metricScope)((metrics) => async () => {
69217
- metrics.setDimensions({});
69218
- metrics.setNamespace(METRICS_NAMESPACE);
69219
- metrics.putMetric(
69220
- "RegisteredPackagesWithStats" /* REGISTERED_PACKAGES_WITH_STATS */,
69221
- statsCount,
69222
- import_aws_embedded_metrics.Unit.Count
69223
- );
69224
- })();
69225
- return S3_CLIENT.send(
69226
- new import_client_s33.PutObjectCommand({
69227
- Bucket: STATS_BUCKET_NAME,
69228
- Key: STATS_OBJECT_KEY,
69229
- Body: JSON.stringify(stats, null, 2),
69230
- ContentType: "application/json",
69231
- CacheControl: CacheStrategy.default().toString(),
69232
- Metadata: {
69233
- "Lambda-Log-Group": context.logGroupName,
69234
- "Lambda-Log-Stream": context.logStreamName,
69235
- "Lambda-Run-Id": context.awsRequestId,
69236
- "Package-Stats-Count": `${statsCount}`
66723
+ chunkStats[pkgName] = {
66724
+ downloads: {
66725
+ npm: entry.downloads
69237
66726
  }
66727
+ };
66728
+ }
66729
+ const chunkKey = `stats-chunks/chunk-${chunkIndex}.json`;
66730
+ await S3_CLIENT.send(
66731
+ new import_client_s32.PutObjectCommand({
66732
+ Bucket: STATS_BUCKET_NAME,
66733
+ Key: chunkKey,
66734
+ Body: JSON.stringify(chunkStats),
66735
+ ContentType: "application/json"
69238
66736
  })
69239
66737
  );
69240
- }
69241
- function updateStats(stats, pkgName, entry) {
69242
- stats.packages[pkgName] = {
69243
- ...stats.packages[pkgName] ?? {},
69244
- downloads: {
69245
- ...stats.packages[pkgName]?.downloads ?? {},
69246
- npm: entry.downloads
69247
- }
66738
+ console.log(
66739
+ `Processed chunk ${chunkIndex}: ${Object.keys(chunkStats).length} packages with stats`
66740
+ );
66741
+ return {
66742
+ chunkIndex,
66743
+ chunkKey,
66744
+ packageCount: Object.keys(chunkStats).length
69248
66745
  };
69249
66746
  }
69250
66747
  // Annotate the CommonJS export names for ESM import in node:
69251
66748
  0 && (module.exports = {
69252
66749
  handler
69253
66750
  });
69254
- /*! Bundled license information:
69255
-
69256
- @datastructures-js/heap/src/heap.js:
69257
- (**
69258
- * @license MIT
69259
- * @copyright 2020 Eyas Ranjous <eyas.ranjous@gmail.com>
69260
- *
69261
- * @class
69262
- *)
69263
-
69264
- @datastructures-js/heap/src/minHeap.js:
69265
- @datastructures-js/heap/src/maxHeap.js:
69266
- (**
69267
- * @license MIT
69268
- * @copyright 2020 Eyas Ranjous <eyas.ranjous@gmail.com>
69269
- *)
69270
- */
69271
66751
  //# sourceMappingURL=index.js.map