@bitblit/ratchet-aws 4.0.115-alpha → 4.0.119-alpha

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 (122) hide show
  1. package/lib/build/ratchet-aws-info.d.ts +1 -1
  2. package/lib/cloudwatch/cloud-watch-log-group-ratchet.d.ts +1 -0
  3. package/lib/cloudwatch/cloud-watch-logs-ratchet.d.ts +1 -0
  4. package/lib/cloudwatch/cloud-watch-metrics-ratchet.d.ts +2 -1
  5. package/lib/daemon/daemon-like.d.ts +1 -1
  6. package/lib/daemon/daemon-process-state-public-token.d.ts +1 -1
  7. package/lib/daemon/daemon-util.d.ts +2 -2
  8. package/lib/daemon/daemon.d.ts +2 -2
  9. package/lib/dynamodb/dynamo-ratchet.d.ts +1 -0
  10. package/lib/ec2/ec2-ratchet.d.ts +4 -2
  11. package/lib/index.d.ts +78 -1
  12. package/lib/index.mjs +11 -0
  13. package/lib/index.mjs.map +1 -0
  14. package/lib/model/cloud-watch-metrics-minute-level-dynamo-count-request.d.ts +1 -1
  15. package/lib/route53/route-53-ratchet.d.ts +1 -0
  16. package/lib/s3/s3-cache-ratchet.d.ts +3 -2
  17. package/lib/s3/s3-cache-to-local-disk-ratchet.d.ts +1 -1
  18. package/lib/ses/mailer.d.ts +1 -0
  19. package/lib/sns/sns-ratchet.d.ts +1 -0
  20. package/package.json +33 -103
  21. package/lib/batch/aws-batch-background-processor.js +0 -45
  22. package/lib/batch/aws-batch-background-processor.spec.js +0 -15
  23. package/lib/batch/aws-batch-ratchet.js +0 -55
  24. package/lib/batch/aws-batch-ratchet.spec.js +0 -33
  25. package/lib/build/ratchet-aws-info.js +0 -14
  26. package/lib/cache/dynamo-db-storage-provider.js +0 -109
  27. package/lib/cache/s3-storage-provider.js +0 -43
  28. package/lib/cache/simple-cache-object-wrapper.js +0 -1
  29. package/lib/cache/simple-cache-read-options.js +0 -1
  30. package/lib/cache/simple-cache-storage-provider.js +0 -1
  31. package/lib/cache/simple-cache.js +0 -64
  32. package/lib/cache/simple-cache.spec.js +0 -67
  33. package/lib/cloudwatch/cloud-watch-log-group-ratchet.js +0 -71
  34. package/lib/cloudwatch/cloud-watch-log-group-ratchet.spec.js +0 -19
  35. package/lib/cloudwatch/cloud-watch-logs-ratchet.js +0 -170
  36. package/lib/cloudwatch/cloud-watch-logs-ratchet.spec.js +0 -84
  37. package/lib/cloudwatch/cloud-watch-metrics-ratchet.js +0 -54
  38. package/lib/cloudwatch/cloud-watch-metrics-ratchet.spec.js +0 -23
  39. package/lib/daemon/daemon-like.js +0 -1
  40. package/lib/daemon/daemon-process-create-options.js +0 -1
  41. package/lib/daemon/daemon-process-state-public-token.js +0 -1
  42. package/lib/daemon/daemon-process-state.js +0 -1
  43. package/lib/daemon/daemon-util.js +0 -148
  44. package/lib/daemon/daemon-util.spec.js +0 -79
  45. package/lib/daemon/daemon.js +0 -128
  46. package/lib/dao/prototype-dao-config.js +0 -1
  47. package/lib/dao/prototype-dao-db.js +0 -1
  48. package/lib/dao/prototype-dao-provider.js +0 -1
  49. package/lib/dao/prototype-dao.js +0 -88
  50. package/lib/dao/prototype-dao.spec.js +0 -26
  51. package/lib/dao/s3-prototype-dao-provider.js +0 -26
  52. package/lib/dao/s3-simple-dao.js +0 -76
  53. package/lib/dao/simple-dao-item.js +0 -1
  54. package/lib/dynamodb/dynamo-ratchet-like.js +0 -1
  55. package/lib/dynamodb/dynamo-ratchet.js +0 -666
  56. package/lib/dynamodb/dynamo-ratchet.spec.js +0 -156
  57. package/lib/dynamodb/dynamo-table-ratchet.js +0 -88
  58. package/lib/dynamodb/hash-spreader.js +0 -65
  59. package/lib/dynamodb/hash-spreader.spec.js +0 -17
  60. package/lib/ec2/ec2-ratchet.js +0 -107
  61. package/lib/ec2/ec2-ratchet.spec.js +0 -31
  62. package/lib/environment/cascade-environment-service-provider.js +0 -24
  63. package/lib/environment/env-var-environment-service-provider.js +0 -30
  64. package/lib/environment/environment-service-config.js +0 -1
  65. package/lib/environment/environment-service-provider.js +0 -1
  66. package/lib/environment/environment-service.js +0 -50
  67. package/lib/environment/environment-service.spec.js +0 -22
  68. package/lib/environment/fixed-environment-service-provider.js +0 -21
  69. package/lib/environment/s3-environment-service-provider.js +0 -27
  70. package/lib/environment/ssm-environment-service-provider.js +0 -59
  71. package/lib/expiring-code/dynamo-expiring-code-provider.js +0 -24
  72. package/lib/expiring-code/expiring-code-params.js +0 -1
  73. package/lib/expiring-code/expiring-code-provider.js +0 -1
  74. package/lib/expiring-code/expiring-code-ratchet.js +0 -34
  75. package/lib/expiring-code/expiring-code-ratchet.spec.js +0 -7
  76. package/lib/expiring-code/expiring-code.js +0 -1
  77. package/lib/expiring-code/s3-expiring-code-provider.js +0 -48
  78. package/lib/expiring-code/s3-expiring-code-provider.spec.js +0 -46
  79. package/lib/iam/aws-credentials-ratchet.js +0 -18
  80. package/lib/index.js +0 -1
  81. package/lib/lambda/lambda-event-detector.js +0 -38
  82. package/lib/lambda/lambda-event-type-guards.js +0 -24
  83. package/lib/model/cloud-watch-metrics-minute-level-dynamo-count-request.js +0 -1
  84. package/lib/model/cloud-watch-metrics-unit.js +0 -30
  85. package/lib/model/dynamo/doc-put-item-command-input.js +0 -1
  86. package/lib/model/dynamo/doc-query-command-input.js +0 -1
  87. package/lib/model/dynamo/doc-scan-command-input.js +0 -1
  88. package/lib/model/dynamo/doc-update-item-command-input.js +0 -1
  89. package/lib/model/dynamo-count-result.js +0 -1
  90. package/lib/route53/route-53-ratchet.js +0 -55
  91. package/lib/runtime-parameter/cached-stored-runtime-parameter.js +0 -1
  92. package/lib/runtime-parameter/dynamo-runtime-parameter-provider.js +0 -36
  93. package/lib/runtime-parameter/dynamo-runtime-parameter-provider.spec.js +0 -49
  94. package/lib/runtime-parameter/global-variable-override-runtime-parameter-provider.js +0 -51
  95. package/lib/runtime-parameter/global-variable-override-runtime-parameter-provider.spec.js +0 -37
  96. package/lib/runtime-parameter/memory-runtime-parameter-provider.js +0 -27
  97. package/lib/runtime-parameter/runtime-parameter-provider.js +0 -1
  98. package/lib/runtime-parameter/runtime-parameter-ratchet.js +0 -71
  99. package/lib/runtime-parameter/runtime-parameter-ratchet.spec.js +0 -39
  100. package/lib/runtime-parameter/stored-runtime-parameter.js +0 -1
  101. package/lib/s3/s3-cache-ratchet.js +0 -330
  102. package/lib/s3/s3-cache-ratchet.spec.js +0 -97
  103. package/lib/s3/s3-cache-to-local-disk-ratchet.js +0 -105
  104. package/lib/s3/s3-cache-to-local-dist-ratchet.spec.js +0 -22
  105. package/lib/s3/s3-location-sync-ratchet.js +0 -140
  106. package/lib/s3/s3-ratchet.js +0 -22
  107. package/lib/s3/s3-ratchet.spec.js +0 -20
  108. package/lib/ses/email-attachment.js +0 -1
  109. package/lib/ses/mailer-config.js +0 -1
  110. package/lib/ses/mailer-like.js +0 -1
  111. package/lib/ses/mailer.js +0 -206
  112. package/lib/ses/mailer.spec.js +0 -104
  113. package/lib/ses/ratchet-template-renderer.js +0 -1
  114. package/lib/ses/ready-to-send-email.js +0 -1
  115. package/lib/ses/remote-handlebars-template-renderer.js +0 -78
  116. package/lib/ses/resolved-ready-to-send-email.js +0 -1
  117. package/lib/sns/sns-ratchet.js +0 -45
  118. package/lib/sns/sns-ratchet.spec.js +0 -17
  119. package/lib/sync-lock/dynamo-db-sync-lock.js +0 -69
  120. package/lib/sync-lock/dynamo-db-sync-lock.spec.js +0 -30
  121. package/lib/sync-lock/memory-sync-lock.js +0 -35
  122. package/lib/sync-lock/sync-lock-provider.js +0 -1
@@ -1,59 +0,0 @@
1
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
4
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
5
- import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
6
- import { GetParameterCommand, SSMClient } from '@aws-sdk/client-ssm';
7
- export class SsmEnvironmentServiceProvider {
8
- region;
9
- ssmEncrypted;
10
- ssm;
11
- constructor(region = 'us-east-1', ssmEncrypted = true) {
12
- this.region = region;
13
- this.ssmEncrypted = ssmEncrypted;
14
- RequireRatchet.notNullOrUndefined(region);
15
- RequireRatchet.notNullOrUndefined(ssmEncrypted);
16
- this.ssm = new SSMClient({ region: this.region });
17
- }
18
- async fetchConfig(name) {
19
- Logger.silly('SsmEnvironmentServiceProvider fetch for %s', name);
20
- const params = {
21
- Name: name,
22
- WithDecryption: this.ssmEncrypted,
23
- };
24
- let rval = null;
25
- let toParse = null;
26
- try {
27
- const value = await this.ssm.send(new GetParameterCommand(params));
28
- toParse = StringRatchet.trimToNull(value?.Parameter?.Value);
29
- }
30
- catch (err) {
31
- const errCode = err['code'] || '';
32
- if (errCode.toLowerCase().indexOf('throttlingexception') !== -1) {
33
- Logger.warn('Throttled while trying to read parameters - waiting 1 second before allowing retry');
34
- await PromiseRatchet.wait(1_000);
35
- }
36
- else if (errCode.toLowerCase().indexOf('parameternotfound') !== -1) {
37
- const errMsg = Logger.warn('AWS could not find parameter %s - are you using the right AWS key?', name);
38
- throw new Error(errMsg);
39
- }
40
- else {
41
- Logger.error('Final environment fetch error (cannot retry) : %s', err, err);
42
- throw err;
43
- }
44
- }
45
- if (toParse) {
46
- try {
47
- rval = JSON.parse(toParse);
48
- }
49
- catch (err) {
50
- Logger.error('Failed to read env - null or invalid JSON : %s : %s', err, toParse, err);
51
- throw err;
52
- }
53
- }
54
- else {
55
- ErrorRatchet.throwFormattedErr('Could not find system parameter with name : %s in this account', name);
56
- }
57
- return rval;
58
- }
59
- }
@@ -1,24 +0,0 @@
1
- export class DynamoExpiringCodeProvider {
2
- tableName;
3
- dynamoRatchet;
4
- constructor(tableName, dynamoRatchet) {
5
- this.tableName = tableName;
6
- this.dynamoRatchet = dynamoRatchet;
7
- }
8
- async checkCode(code, context, deleteOnMatch) {
9
- const keys = { code: code, context: context };
10
- const expCode = await this.dynamoRatchet.simpleGet(this.tableName, keys);
11
- const rval = expCode && expCode.expiresEpochMS > Date.now();
12
- if (rval && deleteOnMatch) {
13
- await this.dynamoRatchet.simpleDelete(this.tableName, keys);
14
- }
15
- return rval;
16
- }
17
- async storeCode(code) {
18
- const output = await this.dynamoRatchet.simplePut(this.tableName, code);
19
- return output && output.ConsumedCapacity.CapacityUnits > 0;
20
- }
21
- async createTableIfMissing(dtr) {
22
- return null;
23
- }
24
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
2
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
3
- export class ExpiringCodeRatchet {
4
- provider;
5
- constructor(provider) {
6
- this.provider = provider;
7
- }
8
- static generateCode(params) {
9
- RequireRatchet.notNullOrUndefined(params, 'params');
10
- RequireRatchet.notNullOrUndefined(params.context, 'params.context');
11
- RequireRatchet.notNullOrUndefined(params.length, 'params.length');
12
- RequireRatchet.notNullOrUndefined(params.alphabet, 'params.alphabet');
13
- let code = '';
14
- for (let i = 0; i < params.length; i++) {
15
- code += params.alphabet.charAt(Math.floor(params.alphabet.length * Math.random()));
16
- }
17
- const rval = {
18
- code: code,
19
- context: params.context,
20
- tags: params.tags,
21
- expiresEpochMS: Date.now() + params.timeToLiveSeconds * 1000,
22
- };
23
- return rval;
24
- }
25
- async createNewCode(params) {
26
- const value = ExpiringCodeRatchet.generateCode(params);
27
- const rval = await this.provider.storeCode(value);
28
- return rval ? value : null;
29
- }
30
- async checkCode(code, context, deleteOnMatch) {
31
- const rval = await this.provider.checkCode(StringRatchet.trimToEmpty(code), StringRatchet.trimToEmpty(context), deleteOnMatch);
32
- return rval;
33
- }
34
- }
@@ -1,7 +0,0 @@
1
- import { ExpiringCodeRatchet } from './expiring-code-ratchet.js';
2
- describe('#ExpiringCodeRatchet', () => {
3
- it('Should generate valid codes', async () => {
4
- const output = ExpiringCodeRatchet.generateCode({ context: 'test', length: 5, timeToLiveSeconds: 10, alphabet: 'A' });
5
- expect(output.code).toEqual('AAAAA');
6
- });
7
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
3
- export class S3ExpiringCodeProvider {
4
- s3CacheRatchet;
5
- keyName;
6
- constructor(s3CacheRatchet, keyName) {
7
- this.s3CacheRatchet = s3CacheRatchet;
8
- this.keyName = keyName;
9
- RequireRatchet.notNullOrUndefined(s3CacheRatchet, 's3CacheRatchet');
10
- RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(s3CacheRatchet.getDefaultBucket(), 's3CacheRatchet.defaultBucket');
11
- RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(keyName, 'keyName');
12
- }
13
- async fetchFile() {
14
- const rval = (await this.s3CacheRatchet.fetchCacheFileAsObject(this.keyName)) || {
15
- data: [],
16
- lastModifiedEpochMS: Date.now(),
17
- };
18
- return rval;
19
- }
20
- async updateFile(vals) {
21
- const next = {
22
- data: vals || [],
23
- lastModifiedEpochMS: Date.now(),
24
- };
25
- next.data = next.data.filter((d) => d.expiresEpochMS > Date.now());
26
- Logger.info('Updating code file to %s codes', next.data.length);
27
- const rval = await this.s3CacheRatchet.writeObjectToCacheFile(this.keyName, next);
28
- return rval;
29
- }
30
- async checkCode(code, context, deleteOnMatch) {
31
- const val = await this.fetchFile();
32
- const rval = val.data.find((d) => d?.code?.toUpperCase() === code?.toUpperCase() && d?.context?.toUpperCase() === context?.toUpperCase());
33
- if (rval) {
34
- if (deleteOnMatch || rval.expiresEpochMS < Date.now()) {
35
- Logger.info('Stripping used/expired code from the database');
36
- const newData = val.data.filter((d) => d != rval);
37
- await this.updateFile(newData);
38
- }
39
- }
40
- return !!rval && rval.expiresEpochMS > Date.now();
41
- }
42
- async storeCode(code) {
43
- const old = await this.fetchFile();
44
- old.data.push(code);
45
- const wrote = await this.updateFile(old.data);
46
- return !!wrote;
47
- }
48
- }
@@ -1,46 +0,0 @@
1
- import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
2
- import { S3ExpiringCodeProvider } from './s3-expiring-code-provider.js';
3
- import { jest } from '@jest/globals';
4
- let mockS3Ratchet;
5
- const testCode = { code: '12345', context: 'ctx', expiresEpochMS: Date.now() + 100_000, tags: ['tag1'] };
6
- const testCode2 = { code: '45678', context: 'ctx', expiresEpochMS: Date.now() + 100_000, tags: ['tag1'] };
7
- describe('#S3ExpiringCodeProvider', () => {
8
- beforeEach(() => {
9
- mockS3Ratchet = JestRatchet.mock(jest.fn);
10
- mockS3Ratchet.getDefaultBucket.mockReturnValue('TEST-BUCKET');
11
- });
12
- it('Should fetch file', async () => {
13
- const val = new S3ExpiringCodeProvider(mockS3Ratchet, 'test.json');
14
- const output = await val.fetchFile();
15
- expect(output).not.toBeFalsy();
16
- expect(output.data).not.toBeFalsy();
17
- expect(output.lastModifiedEpochMS).not.toBeFalsy();
18
- });
19
- it('Should update file', async () => {
20
- const val = new S3ExpiringCodeProvider(mockS3Ratchet, 'test.json');
21
- mockS3Ratchet.writeObjectToCacheFile.mockResolvedValue({});
22
- const wrote = await val.updateFile([testCode]);
23
- expect(wrote).not.toBeFalsy();
24
- });
25
- it('Should check code', async () => {
26
- mockS3Ratchet.fetchCacheFileAsObject.mockResolvedValue({
27
- data: [testCode],
28
- lastModifiedEpochMS: 1234,
29
- });
30
- const val = new S3ExpiringCodeProvider(mockS3Ratchet, 'test.json');
31
- const testValidCode = await val.checkCode('12345', 'ctx', false);
32
- const testInvalidCode = await val.checkCode('09876', 'ctx', false);
33
- expect(testValidCode).toBeTruthy();
34
- expect(testInvalidCode).toBeFalsy();
35
- });
36
- it('Should store code', async () => {
37
- mockS3Ratchet.fetchCacheFileAsObject.mockResolvedValue({
38
- data: [testCode],
39
- lastModifiedEpochMS: 1234,
40
- });
41
- mockS3Ratchet.writeObjectToCacheFile.mockResolvedValue({});
42
- const val = new S3ExpiringCodeProvider(mockS3Ratchet, 'test.json');
43
- const output = await val.storeCode(testCode2);
44
- expect(output).toBeTruthy();
45
- });
46
- });
@@ -1,18 +0,0 @@
1
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
2
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
3
- export class AwsCredentialsRatchet {
4
- constructor() { }
5
- static applySetProfileEnvironmentalVariable(newProfile) {
6
- if (!!process.env) {
7
- if (StringRatchet.trimToNull(newProfile)) {
8
- process.env['AWS_PROFILE'] = newProfile;
9
- }
10
- else {
11
- ErrorRatchet.throwFormattedErr('Cannot set profile to null/empty string');
12
- }
13
- }
14
- else {
15
- ErrorRatchet.throwFormattedErr('Cannot set profile - not in a node environment - process missing');
16
- }
17
- }
18
- }
package/lib/index.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- export class LambdaEventDetector {
2
- static isValidCronEvent(event) {
3
- return event && event.source == 'aws.events' && event.resources && event.resources.length > 0;
4
- }
5
- static isValidSnsEvent(event) {
6
- return event && event.Records && event.Records.length > 0 && event.Records[0].EventSource == 'aws:sns';
7
- }
8
- static isValidDynamoDBEvent(event) {
9
- return event && event.Records && event.Records.length > 0 && event.Records[0].eventSource == 'aws:dynamodb';
10
- }
11
- static isValidS3Event(event) {
12
- return event && event.Records && event.Records.length > 0 && event.Records[0].eventSource == 'aws:s3';
13
- }
14
- static isValidApiGatewayV2WithRequestContextEvent(event) {
15
- return event && event.rawPath && event.requestContext && event.routeKey;
16
- }
17
- static isValidApiGatewayEvent(event) {
18
- return event && event.httpMethod && event.path && event.requestContext;
19
- }
20
- static isValidApiGatewayAuthorizerEvent(event) {
21
- return event && event.authorizationToken && event.methodArn;
22
- }
23
- static isSingleCronEvent(event) {
24
- return this.isValidCronEvent(event) && LambdaEventDetector.isSingleEntryEvent(event, 'resources');
25
- }
26
- static isSingleSnsEvent(event) {
27
- return this.isValidSnsEvent(event) && LambdaEventDetector.isSingleEntryEvent(event);
28
- }
29
- static isSingleDynamoDBEvent(event) {
30
- return this.isValidDynamoDBEvent(event) && LambdaEventDetector.isSingleEntryEvent(event);
31
- }
32
- static isSingleS3Event(event) {
33
- return this.isValidS3Event(event) && LambdaEventDetector.isSingleEntryEvent(event);
34
- }
35
- static isSingleEntryEvent(event, entryName = 'Records') {
36
- return event && event[entryName] && event[entryName] instanceof Array && event[entryName].length === 1;
37
- }
38
- }
@@ -1,24 +0,0 @@
1
- import { LambdaEventDetector } from './lambda-event-detector.js';
2
- export class LambdaEventTypeGuards {
3
- static isValidCronEvent(event) {
4
- return LambdaEventDetector.isValidCronEvent(event);
5
- }
6
- static isValidSnsEvent(event) {
7
- return LambdaEventDetector.isValidSnsEvent(event);
8
- }
9
- static isValidDynamoDBEvent(event) {
10
- return LambdaEventDetector.isValidDynamoDBEvent(event);
11
- }
12
- static isValidS3Event(event) {
13
- return LambdaEventDetector.isValidS3Event(event);
14
- }
15
- static isValidApiGatewayV2WithRequestContextEvent(event) {
16
- return LambdaEventDetector.isValidApiGatewayV2WithRequestContextEvent(event);
17
- }
18
- static isValidApiGatewayEvent(event) {
19
- return LambdaEventDetector.isValidApiGatewayEvent(event);
20
- }
21
- static isValidApiGatewayAuthorizerEvent(event) {
22
- return LambdaEventDetector.isValidApiGatewayAuthorizerEvent(event);
23
- }
24
- }
@@ -1,30 +0,0 @@
1
- export var CloudWatchMetricsUnit;
2
- (function (CloudWatchMetricsUnit) {
3
- CloudWatchMetricsUnit["Seconds"] = "Seconds";
4
- CloudWatchMetricsUnit["Microseconds"] = "Microseconds";
5
- CloudWatchMetricsUnit["Milliseconds"] = "Milliseconds";
6
- CloudWatchMetricsUnit["Bytes"] = "Bytes";
7
- CloudWatchMetricsUnit["Kilobytes"] = "Kilobytes";
8
- CloudWatchMetricsUnit["Megabytes"] = "Megabytes";
9
- CloudWatchMetricsUnit["Gigabytes"] = "Gigabytes";
10
- CloudWatchMetricsUnit["Terabytes"] = "Terabytes";
11
- CloudWatchMetricsUnit["Bits"] = "Bits";
12
- CloudWatchMetricsUnit["Kilobits"] = "Kilobits";
13
- CloudWatchMetricsUnit["Megabits"] = "Megabits";
14
- CloudWatchMetricsUnit["Gigabits"] = "Gigabits";
15
- CloudWatchMetricsUnit["Terabits"] = "Terabits";
16
- CloudWatchMetricsUnit["Percent"] = "Percent";
17
- CloudWatchMetricsUnit["Count"] = "Count";
18
- CloudWatchMetricsUnit["BytesPerSecond"] = "Bytes/Second";
19
- CloudWatchMetricsUnit["KilobytesPerSecond"] = "Kilobytes/Second";
20
- CloudWatchMetricsUnit["MegabytesPerSecond"] = "Megabytes/Second";
21
- CloudWatchMetricsUnit["GigabytesPerSecond"] = "Gigabytes/Second";
22
- CloudWatchMetricsUnit["TerabytesPerSecond"] = "Terabytes/Second";
23
- CloudWatchMetricsUnit["BitsPerSecond"] = "Terabytes/Second";
24
- CloudWatchMetricsUnit["KilobitsPerSecond"] = "Kilobits/Second";
25
- CloudWatchMetricsUnit["MegabitsPerSecond"] = "Megabits/Second";
26
- CloudWatchMetricsUnit["GigabitsPerSecond"] = "Gigabits/Second";
27
- CloudWatchMetricsUnit["TerabitsPerSecond"] = "Terabits/Second";
28
- CloudWatchMetricsUnit["CountPerSecond"] = "Count/Second";
29
- CloudWatchMetricsUnit["None"] = "None";
30
- })(CloudWatchMetricsUnit || (CloudWatchMetricsUnit = {}));
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,55 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- import { ChangeResourceRecordSetsCommand, waitUntilResourceRecordSetsChanged, } from '@aws-sdk/client-route-53';
3
- import { WaiterState } from '@aws-sdk/util-waiter';
4
- export class Route53Ratchet {
5
- route53;
6
- hostedZoneId;
7
- constructor(route53, hostedZoneId) {
8
- this.route53 = route53;
9
- this.hostedZoneId = hostedZoneId;
10
- if (!this.route53) {
11
- throw 'route53 may not be null';
12
- }
13
- }
14
- async changeCnameRecordTarget(domainName, target, hostedZoneId = this.hostedZoneId, ttlSeconds = 600) {
15
- Logger.info('Updating %s to point to %s', domainName, target);
16
- try {
17
- const params = {
18
- ChangeBatch: {
19
- Changes: [
20
- {
21
- Action: 'UPSERT',
22
- ResourceRecordSet: {
23
- Name: domainName,
24
- ResourceRecords: [
25
- {
26
- Value: target,
27
- },
28
- ],
29
- TTL: ttlSeconds,
30
- Type: 'CNAME',
31
- },
32
- },
33
- ],
34
- },
35
- HostedZoneId: hostedZoneId,
36
- };
37
- const result = await this.route53.send(new ChangeResourceRecordSetsCommand(params));
38
- Logger.debug('Updated domain result: %j', result);
39
- const waitParams = {
40
- Id: result.ChangeInfo.Id,
41
- };
42
- const waitResult = await waitUntilResourceRecordSetsChanged({ client: this.route53, maxWaitTime: 300 }, waitParams);
43
- Logger.debug('Wait responsed: %j', waitResult);
44
- if (waitResult.state === WaiterState.SUCCESS) {
45
- Logger.info('Updated %s to point to %s', domainName, hostedZoneId);
46
- return true;
47
- }
48
- }
49
- catch (err) {
50
- Logger.warn('Error update CName for %s with value %s: %j', domainName, target, err);
51
- }
52
- Logger.info('Cannot update %s to point to %s', domainName, target);
53
- return false;
54
- }
55
- }
@@ -1,36 +0,0 @@
1
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- export class DynamoRuntimeParameterProvider {
4
- dynamo;
5
- tableName;
6
- constructor(dynamo, tableName) {
7
- this.dynamo = dynamo;
8
- this.tableName = tableName;
9
- RequireRatchet.notNullOrUndefined(this.dynamo);
10
- RequireRatchet.notNullOrUndefined(this.tableName);
11
- }
12
- async readParameter(groupId, paramKey) {
13
- Logger.silly('Reading %s / %s from underlying db', groupId, paramKey);
14
- const req = {
15
- groupId: groupId,
16
- paramKey: paramKey,
17
- };
18
- const rval = await this.dynamo.simpleGet(this.tableName, req);
19
- return rval;
20
- }
21
- async readAllParametersForGroup(groupId) {
22
- const qry = {
23
- TableName: this.tableName,
24
- KeyConditionExpression: 'groupId = :groupId',
25
- ExpressionAttributeValues: {
26
- ':groupId': groupId,
27
- },
28
- };
29
- const all = await this.dynamo.fullyExecuteQuery(qry);
30
- return all;
31
- }
32
- async writeParameter(toStore) {
33
- const rval = await this.dynamo.simplePut(this.tableName, toStore);
34
- return !!rval;
35
- }
36
- }
@@ -1,49 +0,0 @@
1
- import { DynamoRuntimeParameterProvider } from './dynamo-runtime-parameter-provider.js';
2
- import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
3
- import { RuntimeParameterRatchet } from './runtime-parameter-ratchet.js';
4
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
5
- import { LoggerLevelName } from '@bitblit/ratchet-common/lib/logger/logger-level-name.js';
6
- import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
7
- import { jest } from '@jest/globals';
8
- let mockDynamoRatchet;
9
- const testEntry = { groupId: 'test', paramKey: 'test', paramValue: '15', ttlSeconds: 0.5 };
10
- const testEntry2 = { groupId: 'test', paramKey: 'test1', paramValue: '20', ttlSeconds: 0.5 };
11
- describe('#runtimeParameterRatchet', function () {
12
- beforeEach(() => {
13
- mockDynamoRatchet = JestRatchet.mock(jest.fn);
14
- });
15
- it('fetch and cache a runtime parameter', async () => {
16
- Logger.setLevel(LoggerLevelName.silly);
17
- const tableName = 'default-table';
18
- mockDynamoRatchet.simpleGet.mockResolvedValue(testEntry);
19
- mockDynamoRatchet.simplePut.mockResolvedValue({});
20
- const drpp = new DynamoRuntimeParameterProvider(mockDynamoRatchet, tableName);
21
- const rpr = new RuntimeParameterRatchet(drpp);
22
- const stored = await rpr.storeParameter('test', 'test1', 15, 0.5);
23
- Logger.info('Stored : %j', stored);
24
- const cache1 = await rpr.fetchParameter('test', 'test1');
25
- const cache1a = await rpr.fetchParameter('test', 'test1');
26
- const cache1b = await rpr.fetchParameter('test', 'test1');
27
- expect(cache1).toEqual(15);
28
- expect(cache1a).toEqual(15);
29
- expect(cache1b).toEqual(15);
30
- await PromiseRatchet.wait(1000);
31
- const cache2 = await rpr.fetchParameter('test', 'test1');
32
- expect(cache2).toEqual(15);
33
- mockDynamoRatchet.simpleGet.mockResolvedValue(null);
34
- const cacheMiss = await rpr.fetchParameter('test', 'test-miss');
35
- expect(cacheMiss).toBeNull();
36
- const cacheDefault = await rpr.fetchParameter('test', 'test-miss', 27);
37
- expect(cacheDefault).toEqual(27);
38
- }, 30_000);
39
- it('reads underlying entries', async () => {
40
- Logger.setLevel(LoggerLevelName.silly);
41
- const tableName = 'default-table';
42
- mockDynamoRatchet.fullyExecuteQuery.mockResolvedValue([testEntry, testEntry2]);
43
- const drpp = new DynamoRuntimeParameterProvider(mockDynamoRatchet, tableName);
44
- const rpr = new RuntimeParameterRatchet(drpp);
45
- const vals = await rpr.readUnderlyingEntries('test');
46
- expect(vals).not.toBeFalsy();
47
- expect(vals.length).toEqual(2);
48
- }, 30_000);
49
- });
@@ -1,51 +0,0 @@
1
- import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
2
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
3
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
4
- export class GlobalVariableOverrideRuntimeParameterProvider {
5
- wrapped;
6
- options = {
7
- globalTTL: 1,
8
- separator: '.',
9
- prefix: 'RuntimeEnv-',
10
- suffix: '',
11
- };
12
- constructor(wrapped, opts) {
13
- this.wrapped = wrapped;
14
- RequireRatchet.notNullOrUndefined(this.wrapped, 'wrapped');
15
- RequireRatchet.notNullOrUndefined(global?.process?.env, '"process" not found - this only runs in Node, not the browser');
16
- if (opts) {
17
- this.options = opts;
18
- }
19
- RequireRatchet.notNullOrUndefined(this.options.globalTTL, 'this.options.globalTTL');
20
- RequireRatchet.notNullOrUndefined(this.options.separator, 'this.options.separator');
21
- RequireRatchet.true(this.options.globalTTL > 0, 'this.options.globalTTL must be larger than 0');
22
- }
23
- generateName(groupId, paramKey) {
24
- return (StringRatchet.trimToEmpty(this.options.prefix) +
25
- groupId +
26
- StringRatchet.trimToEmpty(this.options.separator) +
27
- paramKey +
28
- StringRatchet.trimToEmpty(this.options.suffix));
29
- }
30
- async readParameter(groupId, paramKey) {
31
- const asString = StringRatchet.trimToNull(process.env[this.generateName(groupId, paramKey)]);
32
- if (asString && !StringRatchet.canParseAsJson(asString)) {
33
- ErrorRatchet.throwFormattedErr('Cannot parse ENV override (%s / %s) as JSON - did you forget the quotes on a string?', groupId, paramKey);
34
- }
35
- const rval = asString
36
- ? {
37
- groupId: groupId,
38
- paramKey: paramKey,
39
- paramValue: asString,
40
- ttlSeconds: this.options.globalTTL,
41
- }
42
- : await this.wrapped.readParameter(groupId, paramKey);
43
- return rval;
44
- }
45
- async readAllParametersForGroup(groupId) {
46
- return this.wrapped.readAllParametersForGroup(groupId);
47
- }
48
- async writeParameter(toStore) {
49
- return this.wrapped.writeParameter(toStore);
50
- }
51
- }
@@ -1,37 +0,0 @@
1
- import { DynamoRuntimeParameterProvider } from './dynamo-runtime-parameter-provider.js';
2
- import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
3
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
4
- import { LoggerLevelName } from '@bitblit/ratchet-common/lib/logger/logger-level-name.js';
5
- import { RuntimeParameterRatchet } from './runtime-parameter-ratchet.js';
6
- import { GlobalVariableOverrideRuntimeParameterProvider } from './global-variable-override-runtime-parameter-provider.js';
7
- import { jest } from '@jest/globals';
8
- let mockDynamoRatchet;
9
- const testEntry = { groupId: 'test', paramKey: 'test', paramValue: '15', ttlSeconds: 0.5 };
10
- const testEntry2 = { groupId: 'test', paramKey: 'test1', paramValue: '"not-overridden"', ttlSeconds: 0.5 };
11
- describe('#globalVariableOverrideRuntimeParameterProvider', function () {
12
- beforeEach(() => {
13
- mockDynamoRatchet = JestRatchet.mock(jest.fn);
14
- });
15
- it('reads underlying entries', async () => {
16
- Logger.setLevel(LoggerLevelName.silly);
17
- mockDynamoRatchet.simpleGet.mockResolvedValue(testEntry2);
18
- const drpp = new DynamoRuntimeParameterProvider(mockDynamoRatchet, 'test-table');
19
- const er = new GlobalVariableOverrideRuntimeParameterProvider(drpp, {
20
- globalTTL: 1,
21
- separator: '.',
22
- prefix: 'p-',
23
- suffix: null,
24
- });
25
- process.env[er.generateName('test', 'test1')] = '"override"';
26
- const rpr = new RuntimeParameterRatchet(er);
27
- const root = await drpp.readParameter('test', 'test1');
28
- const override = await er.readParameter('test', 'test1');
29
- const fetched = await rpr.fetchParameter('test', 'test1');
30
- expect(root).not.toBeNull();
31
- expect(override).not.toBeNull();
32
- expect(fetched).not.toBeNull();
33
- expect(root.paramValue).toEqual('"not-overridden"');
34
- expect(override.paramValue).toEqual('"override"');
35
- expect(fetched).toEqual('override');
36
- }, 30_000);
37
- });
@@ -1,27 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- export class MemoryRuntimeParameterProvider {
3
- data;
4
- constructor(data = Promise.resolve({})) {
5
- this.data = data;
6
- }
7
- async readParameter(groupId, paramKey) {
8
- Logger.silly('Reading %s / %s from underlying db', groupId, paramKey);
9
- const d = await this.data;
10
- return d[groupId + '::' + paramKey];
11
- }
12
- async readAllParametersForGroup(groupId) {
13
- const d = await this.data;
14
- const out = [];
15
- Object.keys(d).forEach((k) => {
16
- if (k.startsWith(groupId)) {
17
- out.push(d[k]);
18
- }
19
- });
20
- return out;
21
- }
22
- async writeParameter(toStore) {
23
- const d = await this.data;
24
- d[toStore.groupId + '::' + toStore.paramKey] = toStore;
25
- return true;
26
- }
27
- }
@@ -1 +0,0 @@
1
- export {};