@cumulus/async-operations 18.2.2 → 18.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@cumulus/async-operations",
3
- "version": "18.2.2",
3
+ "version": "18.3.0",
4
4
  "description": "Cumulus Core internal async operations module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
8
- "node": ">=16.19.0"
8
+ "node": ">=20.12.2"
9
9
  },
10
10
  "scripts": {
11
11
  "clean": "git clean -d -x -e node_modules -f",
12
12
  "test": "../../node_modules/.bin/ava",
13
+ "test:ci": "../../scripts/run_package_ci_unit.sh",
13
14
  "test:coverage": "../../node_modules/.bin/nyc npm test",
14
15
  "prepare": "npm run tsc",
15
16
  "tsc": "../../node_modules/.bin/tsc",
@@ -22,27 +23,28 @@
22
23
  "files": [
23
24
  "tests/**/*.js"
24
25
  ],
25
- "fail-fast": true,
26
+ "failFast": true,
26
27
  "verbose": true,
27
28
  "timeout": "2m"
28
29
  },
29
30
  "author": "Cumulus Authors",
30
31
  "license": "Apache-2.0",
31
32
  "dependencies": {
32
- "@aws-sdk/client-lambda": "^3.447.0",
33
- "@cumulus/aws-client": "18.2.2",
34
- "@cumulus/db": "18.2.2",
35
- "@cumulus/errors": "18.2.2",
36
- "@cumulus/es-client": "18.2.2",
37
- "@cumulus/logger": "18.2.2",
38
- "@cumulus/types": "18.2.2",
33
+ "@aws-sdk/client-ecs": "^3.477.0",
34
+ "@aws-sdk/client-lambda": "^3.529.1",
35
+ "@cumulus/aws-client": "18.3.0",
36
+ "@cumulus/db": "18.3.0",
37
+ "@cumulus/errors": "18.3.0",
38
+ "@cumulus/es-client": "18.3.0",
39
+ "@cumulus/logger": "18.3.0",
40
+ "@cumulus/types": "18.3.0",
39
41
  "knex": "2.4.1",
40
42
  "uuid": "8.3.2"
41
43
  },
42
44
  "devDependencies": {
43
- "@cumulus/common": "18.2.2",
45
+ "@cumulus/common": "18.3.0",
44
46
  "@types/aws-sdk": "2.7.0",
45
47
  "@types/uuid": "^8.0.0"
46
48
  },
47
- "gitHead": "d2f030f1d77b6d3072cb20f84261b10a7b160620"
49
+ "gitHead": "e8731c150ac49c1bab058183a7a5d91464e1701c"
48
50
  }
@@ -1,6 +1,6 @@
1
- import { ECS } from 'aws-sdk';
1
+ import { RunTaskCommandOutput } from '@aws-sdk/client-ecs';
2
2
  import { Knex } from 'knex';
3
- import { FunctionConfiguration } from '@aws-sdk/client-lambda';
3
+ import { FunctionConfiguration, GetFunctionConfigurationCommand } from '@aws-sdk/client-lambda';
4
4
  import { ecs, s3, lambda } from '@cumulus/aws-client/services';
5
5
 
6
6
  import {
@@ -13,8 +13,6 @@ import {
13
13
  import Logger from '@cumulus/logger';
14
14
  import { ApiAsyncOperation, AsyncOperationType } from '@cumulus/types/api/async_operations';
15
15
  import { v4 as uuidv4 } from 'uuid';
16
- import type { AWSError } from 'aws-sdk/lib/error';
17
- import type { PromiseResult } from 'aws-sdk/lib/request';
18
16
 
19
17
  import type {
20
18
  AsyncOperationPgModelObject,
@@ -25,18 +23,18 @@ const {
25
23
  indexAsyncOperation,
26
24
  } = require('@cumulus/es-client/indexer');
27
25
  const {
28
- Search,
26
+ getEsClient, EsClient,
29
27
  } = require('@cumulus/es-client/search');
30
28
 
31
29
  const logger = new Logger({ sender: '@cumulus/async-operation' });
32
30
 
33
- type StartEcsTaskReturnType = Promise<PromiseResult<ECS.RunTaskResponse, AWSError>>;
31
+ type StartEcsTaskReturnType = Promise<RunTaskCommandOutput>;
34
32
 
35
33
  export const getLambdaConfiguration = async (
36
34
  functionName: string
37
- ): Promise<FunctionConfiguration> => lambda().getFunctionConfiguration({
35
+ ): Promise<FunctionConfiguration> => lambda().send(new GetFunctionConfigurationCommand({
38
36
  FunctionName: functionName,
39
- });
37
+ }));
40
38
 
41
39
  export const getLambdaEnvironmentVariables = (
42
40
  configuration: FunctionConfiguration
@@ -120,7 +118,7 @@ export const startECSTask = async ({
120
118
  },
121
119
  ],
122
120
  },
123
- }).promise();
121
+ });
124
122
  };
125
123
 
126
124
  export const createAsyncOperation = async (
@@ -129,7 +127,7 @@ export const createAsyncOperation = async (
129
127
  stackName: string,
130
128
  systemBucket: string,
131
129
  knexConfig?: NodeJS.ProcessEnv,
132
- esClient?: object,
130
+ esClient?: typeof EsClient,
133
131
  asyncOperationPgModel?: AsyncOperationPgModelObject
134
132
  }
135
133
  ): Promise<Partial<ApiAsyncOperation>> => {
@@ -138,7 +136,7 @@ export const createAsyncOperation = async (
138
136
  stackName,
139
137
  systemBucket,
140
138
  knexConfig = process.env,
141
- esClient = await Search.es(),
139
+ esClient = await getEsClient(),
142
140
  asyncOperationPgModel = new AsyncOperationPgModel(),
143
141
  } = params;
144
142
 
@@ -7,6 +7,9 @@ const sinon = require('sinon');
7
7
  const omit = require('lodash/omit');
8
8
 
9
9
  const { v4: uuidv4 } = require('uuid');
10
+ const { mockClient } = require('aws-sdk-client-mock');
11
+ const { GetFunctionConfigurationCommand } = require('@aws-sdk/client-lambda');
12
+
10
13
  const { ecs, lambda, s3 } = require('@cumulus/aws-client/services');
11
14
  const { getJsonS3Object, recursivelyDeleteS3Bucket } = require('@cumulus/aws-client/S3');
12
15
  // eslint-disable-next-line node/no-unpublished-require
@@ -65,12 +68,8 @@ test.before(async (t) => {
65
68
  ecsClient = ecs();
66
69
  ecsClient.runTask = (params) => {
67
70
  stubbedEcsRunTaskParams = params;
68
- return {
69
- promise: () => {
70
- if (!stubbedEcsRunTaskResult) return Promise.reject(new Error('stubbedEcsRunTaskResult has not yet been set'));
71
- return Promise.resolve(stubbedEcsRunTaskResult);
72
- },
73
- };
71
+ if (!stubbedEcsRunTaskResult) return Promise.reject(new Error('stubbedEcsRunTaskResult has not yet been set'));
72
+ return Promise.resolve(stubbedEcsRunTaskResult);
74
73
  };
75
74
 
76
75
  t.context.functionConfig = {
@@ -81,10 +80,10 @@ test.before(async (t) => {
81
80
  },
82
81
  };
83
82
 
84
- sinon.stub(lambda(), 'getFunctionConfiguration').returns(
83
+ const mockLambdaClient = mockClient(lambda()).onAnyCommand().rejects();
84
+ mockLambdaClient.on(GetFunctionConfigurationCommand).resolves(
85
85
  Promise.resolve(t.context.functionConfig)
86
86
  );
87
-
88
87
  t.context.asyncOperationPgModel = new AsyncOperationPgModel();
89
88
  });
90
89
 
@@ -526,8 +525,11 @@ test.serial('createAsyncOperation() does not write to Elasticsearch if writing t
526
525
  test.serial('createAsyncOperation() does not write to PostgreSQL if writing to Elasticsearch fails', async (t) => {
527
526
  const { id, createObject } = t.context;
528
527
  const fakeEsClient = {
529
- index: () => {
530
- throw new Error('ES something bad');
528
+ initializeEsClient: () => Promise.resolve(),
529
+ client: {
530
+ index: () => {
531
+ throw new Error('ES something bad');
532
+ },
531
533
  },
532
534
  };
533
535