Skip to content

Commit

Permalink
Modernize the codebase (#72)
Browse files Browse the repository at this point in the history
* chore: add nvmrc

* feat: add typescript

* chore: add commitlint checks

* chore: add funding options to repo

* chore: migrate to typescript

* chore: migrate to jest

* chore: move mocha tests to jest files

* chore: remove old lib code

* chore: bump version to 3.0.0
  • Loading branch information
jasonsims authored Jul 10, 2023
1 parent f9f7e73 commit a6535c6
Show file tree
Hide file tree
Showing 30 changed files with 8,122 additions and 736 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
jest.config.js
.eslintrc.cjs
commitlint.config.js
lib
14 changes: 14 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
extends: [
'semistandard',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint'],
root: true,
};
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: jzimz
16 changes: 2 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
dist
.DS_Store
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run commitlint ${1}
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
npm test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
[caub]: https://github.com/caub
[joelwass]: https://github.com/joelwass

## 3.0.0 (2023-07-10)
* feature: added support for TypeScript
* feature: added support for ES Modules
* development: engines updated to current LTS (v18)
* development: added commit lint
* development: migrated test suite to jest
* development: added funding URL
* development: removed lodash dependency
* development: added .nvmrc

## 2.2.0 (2016-11-09)
* development: [@caub][caub]: Simplified expiry and normalization logic
* development: [@joelwass][joelwass]: Added additional error handling for private key string
Expand Down
63 changes: 34 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AWS CloudFront URL Signature Utility
AWS CloudFront URL Signature Utility
===================
[![Build Status](https://travis-ci.org/jasonsims/aws-cloudfront-sign.svg?branch=master)](https://travis-ci.org/jasonsims/aws-cloudfront-sign)
[![npm version](https://badge.fury.io/js/aws-cloudfront-sign.svg)](http://badge.fury.io/js/aws-cloudfront-sign)
Expand All @@ -15,23 +15,34 @@ Generating signed URLs for CloudFront links is a little more tricky than for S3.

## Usage
### Requirements
* Node.js >=0.10.0
* Node.js >=18
* Active CloudFront distribution with origin configured

### Configuring CloudFront
1. Create a CloudFront distribution
2. Configure your origin with the following settings:

**Origin Domain Name:** {your-s3-bucket}
**Restrict Bucket Access:** Yes
**Grant Read Permissions on Bucket:** Yes, Update Bucket Policy
**Origin Domain Name:** {your-s3-bucket}
**Restrict Bucket Access:** Yes
**Grant Read Permissions on Bucket:** Yes, Update Bucket Policy
3. Create CloudFront Key Pair. [more info][cf_keypair_docs]

### Installing
```sh
npm install aws-cloudfront-sign
```

### TypeScript
```js
import { SignatureOptions } from 'aws-cloudfront-sign/types'
```

### Upgrading from 2.x to 3.x
* There shouldn't be any breaking changes when coming to 3.x. RTMP URLs were deprecated by Amazon
but that will affect all versions.
* Support for ES Modules was added
* Support for TypeScript was added

### Upgrading from 1.x to 2.x
* `expireTime` now takes it's value as milliseconds, Date, or
[moment][moment_docs] instead of seconds.
Expand All @@ -42,18 +53,19 @@ npm install aws-cloudfront-sign
* `@param {Object} options` - URL signature [options](#options)
* `@return {String} signedUrl` - Signed CloudFrontUrl

#### getSignedRTMPUrl(domainName, s3key, options)
* `@param {String} domainName` - Domain name of your Cloudfront distribution
* `@param {String} s3key` - Path to s3 object
* `@param {Object} options` - URL signature [options](#options)
* `@return {Object} url.rtmpServerPath` - RTMP formatted server path
* `@return {Object} url.rtmpStreamName` - Signed RTMP formatted stream name

#### getSignedCookies(url, options)
* `@param {String} url` - Cloudfront URL to sign
* `@param {Object} options` - URL signature [options](#options)
* `@return {Object} cookies` - Signed AWS cookies

#### ~~getSignedRTMPUrl(domainName, s3key, options)~~
⛔️ **Deprecated**: [RTMP Support Discontinuing on December 31, 2020](https://repost.aws/questions/QUoUZgHZh7SEWlnQUPlBmVNQ/announcement-rtmp-support-discontinuing-on-december-31-2020)
* ~~`@param {String} domainName` - Domain name of your Cloudfront distribution~~
* ~~`@param {String} s3key` - Path to s3 object~~
* ~~`@param {Object} options` - URL signature [options](#options)~~
* ~~`@return {Object} url.rtmpServerPath` - RTMP formatted server path~~
* ~~`@return {Object} url.rtmpStreamName` - Signed RTMP formatted stream name~~

### Options
* `expireTime` (**Optional** - Default: 1800 sec == 30 min) - The time when the URL should expire. Accepted values are
* number - Time in milliseconds (`new Date().getTime() + 1800000`)
Expand All @@ -69,7 +81,7 @@ npm install aws-cloudfront-sign
character is also included.

```js
var privateKeyString =
const privateKeyString =
'-----BEGIN RSA PRIVATE KEY-----\n'
'MIIJKAIBAAKCAgEAwGPMqEvxPYQIffDimM9t3A7Z4aBFAUvLiITzmHRc4UPwryJp\n'
'EVi3C0sQQKBHlq2IOwrmqNiAk31/uh4FnrRR1mtQm4x4IID58cFAhKkKI/09+j1h\n'
Expand All @@ -87,33 +99,26 @@ npm install aws-cloudfront-sign
CF_PRIVATE_KEY="$(cat your-private-key.pem)"

# Heroku env
heroku config:set CF_PRIVATE_KEY="$(cat your-private-key.pem)"
heroku config:set CF_PRIVATE_KEY="$(cat your-private-key.pem)"
```

## Examples
### Creating a signed URL
By default the URL will expire after half an hour.
```js
var cf = require('aws-cloudfront-sign')
var options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
var signedUrl = cf.getSignedUrl('http://xxxxxxx.cloudfront.net/path/to/s3/object', options);
// ESM: import { getSignedUrl } from 'aws-cloudfront-sign'
const cf = require('aws-cloudfront-sign')
const options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
const signedUrl = cf.getSignedUrl('http://xxxxxxx.cloudfront.net/path/to/s3/object', options);
console.log('Signed URL: ' + signedUrl);
```

### Creating a signed RTMP URL
```js
var cf = require('aws-cloudfront-sign')
var options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
var signedRTMPUrlObj = cf.getSignedRTMPUrl('xxxxxxx.cloudfront.net', '/path/to/s3/object', options);
console.log('RTMP Server Path: ' + signedRTMPUrlObj.rtmpServerPath);
console.log('Signed Stream Name: ' + signedRTMPUrlObj.rtmpStreamName);
```

### Creating signed cookies
```js
var cf = require('aws-cloudfront-sign')
var options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
var signedCookies = cf.getSignedCookies('http://xxxxxxx.cloudfront.net/*', options);
// ESM: import { getSignedCookies } from 'aws-cloudfront-sign'
const cf = require('aws-cloudfront-sign')
const options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}
const signedCookies = cf.getSignedCookies('http://xxxxxxx.cloudfront.net/*', options);

// You can now set cookies in your response header. For example:
for(var cookieId in signedCookies) {
Expand Down
3 changes: 3 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
73 changes: 0 additions & 73 deletions lib/CannedPolicy.js

This file was deleted.

Loading

0 comments on commit a6535c6

Please sign in to comment.