@dotcom-tool-kit/upload-assets-to-s3 3.2.0 → 4.0.0-beta.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/.toolkitrc.yml CHANGED
@@ -1,2 +1,7 @@
1
- hooks:
1
+ tasks:
2
+ UploadAssetsToS3: './lib/tasks/upload-assets-to-s3'
3
+
4
+ commands:
2
5
  'release:remote': UploadAssetsToS3
6
+
7
+ version: 2
package/README.md CHANGED
@@ -17,32 +17,28 @@ plugins:
17
17
  - '@dotcom-tool-kit/upload-assets-to-s3'
18
18
  ```
19
19
 
20
+ <!-- begin autogenerated docs -->
21
+ ## Tasks
20
22
 
21
- ## Options
22
- | Key | Description | Default value |
23
- |-|-|-|
24
- | `accessKeyIdEnvVar` | variable name of the project's aws access key id. If uploading to multiple buckets the same credentials will need to work for all. | no default value - for backwards compatability the plugin falls back to the default value for `accessKeyId` |
25
- | `secretAccessKeyEnvVar` | variable name of the project's aws secret access key | no default value - for backwards compatability the plugin falls back to the default value for `secretAccessKey` |
26
- | `accessKeyId` | **DEPRECATED** variable name of the project's aws access key id | 'aws_access_hashed_assets' |
27
- | `secretAccessKey` | **DEPRECATED** variable name of the project's aws secret access key | 'aws_secret_hashed_assets' |
28
- | `directory` | the folder in the project whose contents will be uploaded to S3 | 'public' |
29
- | `reviewBucket` | the development or test S3 bucket | `['ft-next-hashed-assets-preview']` |
30
- | `prodBucket` | production S3 bucket/s; an array of strings. The same files will be uploaded to each. _Note: most Customer Products buckets that have a `prod` and `prod-us` version are already configured in AWS to replicate file changes from one to the other so you don't need to specify both here. Also, if multiple buckets are specified the same credentials will need to be valid for both for the upload to be successful_ | `['ft-next-hashed-assets-prod']` |
31
- | `region` | the AWS region your buckets are stored in (let the Platforms team know if you need to upload to multiple buckets in multiple regions) | eu-west-1 |
32
- | `destination` | the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket | 'hashed-assets/page-kit' |
33
- | `extensions` | file extensions to be uploaded to S3 | 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json' |
34
- | `cacheControl` | header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin | 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600' |
35
-
36
- Example:
37
- ```yml
38
- '@dotcom-tool-kit/upload-assets-to-s3':
39
- '@dotcom-tool-kit/upload-assets-to-s3':
40
- accessKeyId: AWS_ACCESS
41
- secretAccessKey: AWS_KEY
42
- prodBucket: ['ft-next-service-registry-prod']
43
- reviewBucket: ['ft-next-service-registry-dev']
44
- destination: ''
45
- ```
23
+ ### `UploadAssetsToS3`
24
+
25
+ Upload files to an AWS S3 bucket.
26
+ #### Task options
27
+
28
+ | Property | Description | Type | Default |
29
+ | :---------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------- | :--------------------------------------------------------------------------- |
30
+ | `accessKeyIdEnvVar` | variable name of the project's aws access key id. If uploading to multiple buckets the same credentials will need to work for all | `string` | `'AWS_ACCESS_HASHED_ASSETS'` |
31
+ | `secretAccessKeyEnvVar` | variable name of the project's aws secret access key | `string` | `'AWS_SECRET_HASHED_ASSETS'` |
32
+ | `directory` | the folder in the project whose contents will be uploaded to S3 | `string` | `'public'` |
33
+ | `reviewBucket` | the development or test S3 bucket | `Array<string>` | `["ft-next-hashed-assets-preview"]` |
34
+ | `prodBucket` | production S3 bucket(s). The same files will be uploaded to each. **Note**: most Customer Products buckets that have a `prod` and `prod-us` version are already configured in AWS to replicate file changes from one to the other so you don't need to specify both here. Also, if multiple buckets are specified the same credentials will need to be valid for both for the upload to be successful. | `Array<string>` | `["ft-next-hashed-assets-prod"]` |
35
+ | `region` | the AWS region your buckets are stored in (let the Platforms team know if you need to upload to multiple buckets in multiple regions). | `string` | `'eu-west-1'` |
36
+ | `destination` | the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket | `string` | `'hashed-assets/page-kit'` |
37
+ | `extensions` | file extensions to be uploaded to S3 | `string` | `'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json'` |
38
+ | `cacheControl` | header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin | `string` | `'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600'` |
39
+
40
+ _All properties are optional._
41
+ <!-- end autogenerated docs -->
46
42
 
47
43
  ## Testing uploads using the review bucket
48
44
 
@@ -1,8 +1,9 @@
1
- import { Task } from '@dotcom-tool-kit/types';
1
+ import { Task } from '@dotcom-tool-kit/base';
2
2
  import { S3Client } from '@aws-sdk/client-s3';
3
- import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/types/lib/schema/upload-assets-to-s3';
4
- export default class UploadAssetsToS3 extends Task<typeof UploadAssetsToS3Schema> {
5
- static description: string;
3
+ import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/schemas/lib/tasks/upload-assets-to-s3';
4
+ export default class UploadAssetsToS3 extends Task<{
5
+ task: typeof UploadAssetsToS3Schema;
6
+ }> {
6
7
  run(): Promise<void>;
7
8
  uploadFile(file: string, options: UploadAssetsToS3Options, s3: S3Client): Promise<void>;
8
9
  uploadAssetsToS3(options: UploadAssetsToS3Options): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uDAAuD,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC,OAAO,sBAAsB,CAAC;IAC/E,MAAM,CAAC,WAAW,SAAK;IAEjB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDvF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiCxE"}
1
+ {"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,wDAAwD,CAAA;AAE/D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC;IAAE,IAAI,EAAE,OAAO,sBAAsB,CAAA;CAAE,CAAC;IACnF,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDvF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CAsCxE"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const types_1 = require("@dotcom-tool-kit/types");
4
+ const base_1 = require("@dotcom-tool-kit/base");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const client_s3_1 = require("@aws-sdk/client-s3");
7
7
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -9,7 +9,7 @@ const mime_1 = tslib_1.__importDefault(require("mime"));
9
9
  const glob_1 = require("glob");
10
10
  const error_1 = require("@dotcom-tool-kit/error");
11
11
  const logger_1 = require("@dotcom-tool-kit/logger");
12
- class UploadAssetsToS3 extends types_1.Task {
12
+ class UploadAssetsToS3 extends base_1.Task {
13
13
  async run() {
14
14
  await this.uploadAssetsToS3(this.options);
15
15
  }
@@ -69,31 +69,28 @@ class UploadAssetsToS3 extends types_1.Task {
69
69
  if (files.length === 0) {
70
70
  throw new error_1.ToolKitError(`no files found at the provided directory: ${options.directory}`);
71
71
  }
72
- // HACK:20231006:IM Doppler doesn't support secrets with lowercase
73
- // characters so let's check if the provided AWS environment variable name
74
- // is available in all caps as will be the case when running our migration
75
- // script.
76
- const checkUppercaseName = (envName) => {
77
- return process.env[envName] ?? process.env[envName.toUpperCase()];
78
- };
72
+ const accessKeyId = process.env[options.accessKeyIdEnvVar];
73
+ const secretAccessKey = process.env[options.secretAccessKeyEnvVar];
74
+ if (!accessKeyId || !secretAccessKey) {
75
+ const missingVars = [
76
+ !accessKeyId ? options.accessKeyIdEnvVar : false,
77
+ !secretAccessKey ? options.secretAccessKeyEnvVar : false
78
+ ];
79
+ const error = new error_1.ToolKitError(`environment variable${missingVars.length > 1 ? 's' : ''} ${missingVars.join(' and ')} not set`);
80
+ error.details = `if your AWS credentials are stored in different environment variables, set the ${logger_1.styles.code('accessKeyIdEnvVar')} and ${logger_1.styles.code('secretAccessKeyEnvVar')} options for this task.`;
81
+ throw error;
82
+ }
79
83
  const s3 = new client_s3_1.S3Client({
80
84
  region: options.region,
81
- // will fallback to default value for accessKeyId if neither
82
- // accessKeyIdEnvVar nor accessKeyId have been provided as options
83
85
  credentials: {
84
- accessKeyId:
85
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
- checkUppercaseName(options.accessKeyIdEnvVar ?? options.accessKeyId),
87
- secretAccessKey:
88
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89
- checkUppercaseName(options.secretAccessKeyEnvVar ?? options.secretAccessKey)
86
+ accessKeyId,
87
+ secretAccessKey
90
88
  }
91
89
  });
92
90
  await Promise.all(files.map((file) => this.uploadFile(file, options, s3)));
93
91
  }
94
92
  }
95
93
  exports.default = UploadAssetsToS3;
96
- UploadAssetsToS3.description = '';
97
94
  const getFileType = (filename) => {
98
95
  // We need to know the original file type so ignore any compression
99
96
  const originalFile = filename.replace(/\.(br|gz)$/, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcom-tool-kit/upload-assets-to-s3",
3
- "version": "3.2.0",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -11,9 +11,9 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "@aws-sdk/client-s3": "^3.256.0",
14
- "@dotcom-tool-kit/error": "^3.2.0",
15
- "@dotcom-tool-kit/logger": "^3.4.0",
16
- "@dotcom-tool-kit/types": "^3.6.0",
14
+ "@dotcom-tool-kit/base": "4.0.0-beta.0",
15
+ "@dotcom-tool-kit/error": "4.0.0-beta.0",
16
+ "@dotcom-tool-kit/logger": "4.0.0-beta.0",
17
17
  "glob": "^7.1.6",
18
18
  "mime": "^2.5.2",
19
19
  "tslib": "^2.3.1"
@@ -27,6 +27,7 @@
27
27
  "homepage": "https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/upload-assets-to-s3",
28
28
  "devDependencies": {
29
29
  "@aws-sdk/types": "^3.13.1",
30
+ "@dotcom-tool-kit/schemas": "2.0.0-beta.0",
30
31
  "@jest/globals": "^27.4.6",
31
32
  "@types/glob": "^7.1.3",
32
33
  "@types/jest": "^27.4.0",
@@ -41,10 +42,10 @@
41
42
  "extends": "../../package.json"
42
43
  },
43
44
  "peerDependencies": {
44
- "dotcom-tool-kit": "3.x"
45
+ "dotcom-tool-kit": "4.0.0-beta.0"
45
46
  },
46
47
  "engines": {
47
- "node": "16.x || 18.x || 20.x",
48
+ "node": "18.x || 20.x",
48
49
  "npm": "7.x || 8.x || 9.x || 10.x"
49
50
  }
50
51
  }
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import UploadAssetsToS3 from './tasks/upload-assets-to-s3';
2
- export declare const tasks: (typeof UploadAssetsToS3)[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,6BAA6B,CAAA;AAE1D,eAAO,MAAM,KAAK,6BAAqB,CAAA"}
package/lib/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tasks = void 0;
4
- const tslib_1 = require("tslib");
5
- const upload_assets_to_s3_1 = tslib_1.__importDefault(require("./tasks/upload-assets-to-s3"));
6
- exports.tasks = [upload_assets_to_s3_1.default];