@defra/grants-config-utils 1.3.2 → 1.4.1
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/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v24.
|
|
1
|
+
v24.22.1
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @defra/grants-config-utils
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1100a38: Fix npm audit issues
|
|
8
|
+
|
|
9
|
+
## 1.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 6229239: Allow listing bucket files to accept a prefix. Fix bug when no files found, to not throw exception
|
|
14
|
+
|
|
3
15
|
## 1.3.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/grants-config-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "NPM module for providing utils for publishing grants config",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=24",
|
|
6
|
+
"node": ">=24.22.1",
|
|
7
7
|
"npm": ">=11.10.0"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@aws-sdk/client-sns": "3.1113.0",
|
|
51
51
|
"@aws-sdk/client-sqs": "3.1113.0",
|
|
52
52
|
"@aws-sdk/client-sts": "3.1113.0",
|
|
53
|
-
"brace-expansion": "5.0.
|
|
53
|
+
"brace-expansion": "5.0.12",
|
|
54
54
|
"convict": "6.2.5",
|
|
55
55
|
"convict-format-with-validator": "6.2.0"
|
|
56
56
|
},
|
|
@@ -59,18 +59,18 @@
|
|
|
59
59
|
"@babel/preset-env": "8.0.2",
|
|
60
60
|
"@changesets/changelog-github": "1.0.0",
|
|
61
61
|
"@changesets/cli": "3.0.1",
|
|
62
|
-
"@vitest/coverage-v8": "4.1.
|
|
62
|
+
"@vitest/coverage-v8": "4.1.12",
|
|
63
63
|
"eslint": "10.7.0",
|
|
64
64
|
"eslint-config-prettier": "10.1.1",
|
|
65
65
|
"husky": "9.1.7",
|
|
66
66
|
"lint-staged": "17.3.0",
|
|
67
|
-
"neostandard": "0.
|
|
67
|
+
"neostandard": "0.14.1",
|
|
68
68
|
"prettier": "3.9.6",
|
|
69
|
-
"vitest": "4.1.
|
|
69
|
+
"vitest": "4.1.12",
|
|
70
70
|
"vitest-fetch-mock": "0.4.5"
|
|
71
71
|
},
|
|
72
72
|
"overrides": {
|
|
73
|
-
"brace-expansion": "5.0.
|
|
73
|
+
"brace-expansion": "5.0.12",
|
|
74
74
|
"eslint": "10.7.0"
|
|
75
75
|
},
|
|
76
76
|
"release-it": {
|
|
@@ -43,18 +43,19 @@ export const listFiles = async (logger, prefix) => {
|
|
|
43
43
|
return result.Contents ?? [];
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export const listAllFiles = async (logger) => {
|
|
46
|
+
export const listAllFiles = async (logger, prefix) => {
|
|
47
47
|
const client = initialiseClient();
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
48
|
+
const input = {
|
|
49
|
+
Bucket: bucketName,
|
|
50
|
+
...(prefix && { Prefix: prefix }),
|
|
51
|
+
};
|
|
52
|
+
const paginator = paginateListObjectsV2({ client }, input);
|
|
54
53
|
|
|
55
54
|
const objectKeys = [];
|
|
56
55
|
for await (const { Contents } of paginator) {
|
|
57
|
-
|
|
56
|
+
if (Contents) {
|
|
57
|
+
objectKeys.push(...Contents.map((obj) => ({ Key: obj.Key })));
|
|
58
|
+
}
|
|
58
59
|
}
|
|
59
60
|
logger.info(`Found ${objectKeys.length ?? 0} files in bucket ${bucketName}`);
|
|
60
61
|
return objectKeys;
|
|
@@ -296,6 +296,74 @@ describe("s3-interactions", () => {
|
|
|
296
296
|
);
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
+
it("should return an empty array if Contents is undefined", async () => {
|
|
300
|
+
const mockListResponse = {
|
|
301
|
+
Contents: undefined,
|
|
302
|
+
IsTruncated: false,
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
mockS3Client.send.mockResolvedValueOnce(mockListResponse);
|
|
306
|
+
|
|
307
|
+
const result = await listAllFiles(mockLogger);
|
|
308
|
+
|
|
309
|
+
expect(result).toEqual([]);
|
|
310
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
311
|
+
`Found 0 files in bucket ${defaultBucketName}`,
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should include Prefix in paginateListObjectsV2 call when prefix is provided", async () => {
|
|
316
|
+
const prefix = "configs/subfolder";
|
|
317
|
+
const mockListResponse = {
|
|
318
|
+
Contents: [{ Key: "configs/subfolder/file.json" }],
|
|
319
|
+
IsTruncated: false,
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
mockS3Client.send.mockResolvedValueOnce(mockListResponse);
|
|
323
|
+
|
|
324
|
+
const result = await listAllFiles(mockLogger, prefix);
|
|
325
|
+
|
|
326
|
+
expect(mockS3Client.send).toHaveBeenCalledWith(
|
|
327
|
+
expect.objectContaining({
|
|
328
|
+
input: {
|
|
329
|
+
Bucket: defaultBucketName,
|
|
330
|
+
Prefix: prefix,
|
|
331
|
+
},
|
|
332
|
+
}),
|
|
333
|
+
);
|
|
334
|
+
expect(result).toEqual([{ Key: "configs/subfolder/file.json" }]);
|
|
335
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
336
|
+
`Found 1 files in bucket ${defaultBucketName}`,
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("should not include Prefix in paginateListObjectsV2 call when prefix is not provided", async () => {
|
|
341
|
+
const mockListResponse = {
|
|
342
|
+
Contents: [{ Key: "file.json" }],
|
|
343
|
+
IsTruncated: false,
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
mockS3Client.send.mockResolvedValueOnce(mockListResponse);
|
|
347
|
+
|
|
348
|
+
const result = await listAllFiles(mockLogger);
|
|
349
|
+
|
|
350
|
+
expect(mockS3Client.send).toHaveBeenCalledWith(
|
|
351
|
+
expect.objectContaining({
|
|
352
|
+
input: {
|
|
353
|
+
Bucket: defaultBucketName,
|
|
354
|
+
},
|
|
355
|
+
}),
|
|
356
|
+
);
|
|
357
|
+
expect(mockS3Client.send).not.toHaveBeenCalledWith(
|
|
358
|
+
expect.objectContaining({
|
|
359
|
+
input: expect.objectContaining({
|
|
360
|
+
Prefix: expect.anything(),
|
|
361
|
+
}),
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
expect(result).toEqual([{ Key: "file.json" }]);
|
|
365
|
+
});
|
|
366
|
+
|
|
299
367
|
it("should throw an error if listing fails", async () => {
|
|
300
368
|
const mockError = new Error("List all failed");
|
|
301
369
|
|