5.2.33 • Published 10 days ago

@netacea/cloudfront v5.2.33

Weekly downloads
67
License
ISC
Repository
-
Last release
10 days ago

Netacea CloudFront

Netacea Header

npm   TypeScript

@netacea/cloudfront is a package designed to add Netacea functionality to CloudFront Lambda@Edge.

Installation

🌻 Starting fresh

Quickest way to get started, is pulling the Netacea CloudFront template repository from github and following the steps in there to get up and running.

git clone https://github.com/Netacea/cloudfront-worker-template-typescript.git

Follow the README.md in the cloudfront-worker-template-typescript repository to get this deployed.

✍ Existing Lambda@Edge worker

Run the following command to install the netacea worker

npm i @netacea/cloudfront --save

Require (javascript) or import (typescript) the worker

// JAVASCRIPT:
const NetaceaCloudFront = require('@netacea/cloudfront').default
// TYPESCRIPT:
import NetaceaCloudFront from '@netacea/cloudfront'

Then declare a variable for the worker.

const worker = new NetaceaCloudFront({
  apiKey: 'your-api-key', // REQUIRED
  secretKey: 'your-secret-key', // REQUIRED IF MITIGATING
  kinesisStreamName: 'your-kinesis-stream-name', // REQUIRED
  kinesisAccessKey: 'your-kinesis-access-key', // REQUIRED
  kinesisSecretKey: 'your-kinesis-secret-key' // REQUIRED if not using secretsManager
})

It's best security practice to not commit your apiKey, secretKey, kinesisAccessKey, kinesisSecretKey to any repository.

The code will run in the Viewer Request, Origin Response and Viewer Response events.

Example Viewer Request:

import NetaceaCloudFront from '@netacea/cloudfront'
const worker = new NetaceaCloudFront({
  apiKey: 'your-api-key', // REQUIRED
  secretKey: 'your-secret-key', // REQUIRED IF MITIGATING
  kinesisStreamName: 'your-kinesis-stream-name', // REQUIRED
  kinesisAccessKey: 'your-kinesis-access-key', // REQUIRED
  kinesisSecretKey: 'your-kinesis-secret-key' // REQUIRED if not using secretsManager
})

export const handler = async (event: any, context: any, callback: any): Promise<any> => {
  context.callbackWaitsForEmptyEventLoop = false
  const netaceaResponse = await worker.run(event)
  const { request, response } = netaceaResponse.Records[0].cf
  if (response !== undefined) {
    return callback(null, response)
  }
  return callback(null, request)
}

Example Origin Response:

import NetaceaCloudFront from '@netacea/cloudfront'
const worker = new NetaceaCloudFront({
  apiKey: 'your-api-key', // REQUIRED
  secretKey: 'your-secret-key', // REQUIRED IF MITIGATING
  kinesisStreamName: 'your-kinesis-stream-name', // REQUIRED
  kinesisAccessKey: 'your-kinesis-access-key', // REQUIRED
  kinesisSecretKey: 'your-kinesis-secret-key' // REQUIRED if not using secretsManager
})

export const handler = async (event: any, context: any, callback: any): Promise<void> => {
  context.callbackWaitsForEmptyEventLoop = false
  if (event.Records[0].cf.response.status >= 400) {
    worker.addNetaceaCookiesToResponse(event)
    worker.ingest(event)
  }
  return callback(null, event.Records[0].cf.response)
}

Example Viewer Response:

import NetaceaCloudFront from '@netacea/cloudfront'
const worker = new NetaceaCloudFront({
  apiKey: 'your-api-key', // REQUIRED
  secretKey: 'your-secret-key', // REQUIRED IF MITIGATING
  kinesisStreamName: 'your-kinesis-stream-name', // REQUIRED
  kinesisAccessKey: 'your-kinesis-access-key', // REQUIRED
  kinesisSecretKey: 'your-kinesis-secret-key' // REQUIRED if not using secretsManager
})

export const handler = async (event: any, context: any, callback: any): Promise<void> => {
  context.callbackWaitsForEmptyEventLoop = false
  if (event.Records[0].cf.response.status < 400) {
    worker.addNetaceaCookiesToResponse(event)
    worker.ingest(event)
  }
  return callback(null, event.Records[0].cf.response)
}

This line is very important for ingest to take place. Without this, latency will be added to some requests.

context.callbackWaitsForEmptyEventLoop = false

⬆ Updating

npm i @netacea/cloudfront@latest --save

This will update the netacea module to the latest version.

5.2.33

10 days ago

5.2.32

16 days ago

5.2.31

23 days ago

5.2.30

24 days ago

5.2.29

1 month ago

5.2.28

1 month ago

5.2.27

1 month ago

5.2.26

1 month ago

5.2.25

1 month ago

5.2.24

1 month ago

5.2.23

1 month ago

5.2.22

1 month ago

5.2.21

2 months ago

5.2.20

2 months ago

5.2.19

2 months ago

5.2.18

2 months ago

5.2.17

2 months ago

5.2.16

2 months ago

5.2.15

2 months ago

5.2.14

2 months ago

5.2.13

2 months ago

5.2.12

2 months ago

5.2.11

2 months ago

5.2.10

2 months ago

5.2.9

2 months ago

5.2.8

2 months ago

5.2.7

2 months ago

5.2.6

2 months ago

5.2.5

2 months ago

5.2.4

2 months ago

5.2.3

2 months ago

5.2.2

2 months ago

5.2.1

3 months ago

5.2.0

3 months ago

5.1.95

3 months ago

5.1.94

3 months ago

5.1.93

3 months ago

5.1.92

3 months ago

5.1.91

3 months ago

5.1.90

3 months ago

5.1.89

3 months ago

5.1.88

3 months ago

5.1.87

3 months ago

5.1.86

3 months ago

5.1.85

4 months ago

5.1.84

4 months ago

5.1.81

4 months ago

5.1.83

4 months ago

5.1.82

4 months ago

5.1.80

4 months ago

5.1.79

5 months ago

5.1.78

5 months ago

5.1.77

5 months ago

5.1.76

5 months ago

5.1.75

5 months ago

5.1.70

6 months ago

5.1.74

6 months ago

5.1.73

6 months ago

5.1.72

6 months ago

5.1.71

6 months ago

5.1.69

7 months ago

5.1.68

7 months ago

5.1.67

7 months ago

5.1.66

7 months ago

5.1.65

7 months ago

5.1.64

7 months ago

5.1.63

8 months ago

5.1.62

8 months ago

5.1.61

8 months ago

5.1.60

8 months ago

5.1.59

8 months ago

5.1.58

8 months ago

5.1.57

8 months ago

5.1.56

8 months ago

5.1.55

9 months ago

5.1.54

9 months ago

5.1.53

9 months ago

5.1.52

9 months ago

5.1.51

9 months ago

5.1.50

9 months ago

5.1.49

9 months ago

5.1.48

10 months ago

5.1.47

10 months ago

5.1.46

10 months ago

5.1.45

10 months ago

5.1.44

10 months ago

5.1.43

10 months ago

5.1.42

10 months ago

5.1.41

10 months ago

5.1.40

10 months ago

5.1.39

11 months ago

5.1.38

11 months ago

5.1.37

11 months ago

5.1.36

11 months ago

5.1.35

11 months ago

5.1.34

11 months ago

5.1.33

11 months ago

5.1.32

11 months ago

5.1.31

11 months ago

5.1.30

11 months ago

5.1.29

11 months ago

5.1.28

11 months ago

5.1.27

11 months ago

5.1.26

11 months ago

5.1.25

11 months ago

5.1.24

12 months ago

5.1.23

12 months ago

5.1.22

12 months ago

5.1.21

12 months ago

5.1.20

12 months ago

5.1.19

12 months ago

5.1.18

12 months ago

5.1.17

1 year ago

5.1.16

1 year ago

5.1.5

1 year ago

5.1.4

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.1.1

1 year ago

5.1.0

1 year ago

5.1.15

1 year ago

5.1.14

1 year ago

5.1.13

1 year ago

5.1.12

1 year ago

5.1.11

1 year ago

5.1.10

1 year ago

5.1.9

1 year ago

5.1.8

1 year ago

5.1.7

1 year ago

5.1.6

1 year ago

4.1.0

1 year ago

4.1.2

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

4.0.3

1 year ago

4.0.2

1 year ago

1.10.9

2 years ago

1.10.8

2 years ago

4.0.1

2 years ago

1.10.7

2 years ago

1.10.5

2 years ago

1.10.4

2 years ago

1.10.3

2 years ago

1.10.6

2 years ago

1.10.2

2 years ago

1.10.1

2 years ago

1.9.0

2 years ago

1.10.0

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago