Skip to content

Commit 8103e27

Browse files
authored
chore(main): release 3.0.0 (#577)
Co-authored-by: JakeChampion <[email protected]>
1 parent 7691fdf commit 8103e27

File tree

627 files changed

+23591
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

627 files changed

+23591
-1
lines changed

CHANGELOG.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,70 @@
11
# Changelog
22

33

4+
## 3.0.0 (2023-07-08)
5+
6+
7+
### Changed
8+
9+
*⚠ BREAKING CHANGE*
10+
11+
* Rename SimpleCache.delete to SimpleCache.purge and require purge options to be supplied as the second parameter
12+
13+
We are renaming because "purge" is already a well-known and documented concept for removing content from Fastly's cache.
14+
15+
The new addition of a second argument allows the caller to decide what scope to purge the content from, currently they can choose to purge from all of Fastly ("global") or from the POP that contains the currently executing instance ("pop"). We do not provide a default option right now, in the future we may provide a default option, if we discover a common pattern is being used.
16+
17+
18+
Here is an example of migrating an application using SimpleCache.delete to SimpleCache.purge with the same behaviour:
19+
```diff
20+
/// <reference types="@fastly/js-compute" />
21+
22+
import { SimpleCache } from 'fastly:cache';
23+
24+
addEventListener('fetch', event => event.respondWith(app(event)));
25+
26+
async function app(event) {
27+
const url = new URL(event.request);
28+
const path = url.pathname;
29+
if (url.searchParams.has('delete')) {
30+
- SimpleCache.delete(path);
31+
+ SimpleCache.purge(path, { scope: "global" });
32+
return new Response(page, { status: 204 });
33+
}
34+
35+
let page = SimpleCache.getOrSet(path, async () => {
36+
return {
37+
value: await render(path),
38+
// Store the page in the cache for 1 minute.
39+
ttl: 60
40+
}
41+
});
42+
return new Response(page, {
43+
headers: {
44+
'content-type': 'text/plain;charset=UTF-8'
45+
}
46+
});
47+
}
48+
49+
async function render(path) {
50+
// expensive/slow function which constructs and returns the contents for a given path
51+
await new Promise(resolve => setTimeout(resolve, 10_000));
52+
return path;
53+
}
54+
55+
56+
```
57+
58+
59+
### Added
60+
61+
* add event.client.tlsCipherOpensslName ([49b0c99](https://github.com/fastly/js-compute-runtime/commit/49b0c99523147998304dc559b836bcc79008e8b0))
62+
* add event.client.tlsClientCertificate ([cf93b62](https://github.com/fastly/js-compute-runtime/commit/cf93b6226b01ca653688571ed0db27e0f6d39bc2))
63+
* add event.client.tlsClientHello ([3d87cb2](https://github.com/fastly/js-compute-runtime/commit/3d87cb28a670735441a0d8c6d16291867c8f2244))
64+
* add event.client.tlsJA3MD5 ([2ecf4af](https://github.com/fastly/js-compute-runtime/commit/2ecf4afcc503e60a1aa972c88d47149b22dbf70c))
65+
* add event.client.tlsProtocol ([4c91142](https://github.com/fastly/js-compute-runtime/commit/4c9114213343d4dea2a1ac2955980e19540a4463))
66+
* Rename SimpleCache.delete to SimpleCache.purge and require purge options to be supplied as the second parameter ([20113c1](https://github.com/fastly/js-compute-runtime/commit/20113c1df6ad57a98c5b8c27b06d67117d2029ef))
67+
468
## 2.5.0 (2023-07-05)
569

670

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
import {Fiddle} from '@site/src/components/fiddle';
8+
9+
# `Backend()`
10+
11+
The **`Backend` constructor** lets you dynamically create new [Fastly Backends](https://developer.fastly.com/reference/api/services/backend/) for your Compute@Edge service.
12+
13+
Dynamically creating new [Fastly Backends](https://developer.fastly.com/reference/api/services/backend/) is disabled by default for Fastly Services. Please contact [Fastly Support](https://support.fastly.com/hc/requests/new?ticket_form_id=360000269711) to request the feature be enabled on the Fastly Services which require Dynamic Backends.
14+
15+
By default, Dynamic Backends are disabled within a JavaScript application as it can be a potential avenue for third-party JavaScript code to send requests, potentially including sensitive/secret data, off to destinations that the JavaScript project was not intending, which could be a security issue.
16+
17+
To enable Dynamic Backends the application will need to explicitly allow Dynamic Backends via:
18+
19+
```js
20+
import { allowDynamicBackends } from "fastly:experimental";
21+
allowDynamicBackends(true);
22+
```
23+
24+
**Note**: Can only be used when processing requests, not during build-time initialization.
25+
26+
## Syntax
27+
28+
```js
29+
new Backend(backendConfiguration)
30+
```
31+
32+
> **Note:** `Backend()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).
33+
34+
### Parameters
35+
36+
- `backendConfiguration`
37+
38+
- : An Object which contains all the configuration options to apply to the newly created Backend.
39+
40+
- `name` _: string_
41+
- The name of the backend.
42+
- The name has to be between 1 and 254 characters inclusive.
43+
- The name can be whatever you would like, as long as it does not match the name of any of the static service backends nor match any other dynamic backends built during a single execution of the application.
44+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is not valid. I.E. The value is null, undefined, an empty string or a string with more than 254 characters.
45+
- `target` _: string_
46+
- A hostname, IPv4, or IPv6 address for the backend as well as an optional port.
47+
- The target has to be at-least 1 character.
48+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is not valid. I.E. Is null, undefined, an empty string, not a valid IP address or host, or is the string `::`
49+
- `hostOverride` _: string_ _**optional**_
50+
- If set, will force the HTTP Host header on connections to this backend to be the supplied value.
51+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string.
52+
- `connectTimeout` _: number_ _**optional**_
53+
- Maximum duration in milliseconds to wait for a connection to this backend to be established.
54+
- If exceeded, the connection is aborted and a 503 response will be presented instead.
55+
- Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32
56+
- `firstByteTimeout` _: number_ _**optional**_
57+
- Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent.
58+
- If exceeded, the connection is aborted and a 503 response will be presented instead.
59+
- Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32
60+
- `betweenBytesTimeout` _: number_ _**optional**_
61+
- Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend.
62+
- If exceeded, the response received so far will be considered complete and the fetch will end.
63+
- Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32
64+
- `useSSL` _: boolean_ _**optional**_
65+
- Whether or not to require TLS for connections to this backend.
66+
- `tlsMinVersion` _: 1 | 1.1 | 1.2 | 1.3_ _**optional**_
67+
- Minimum allowed TLS version on SSL connections to this backend.
68+
- If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
69+
- Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is not 1, 1.1, 1.2, or 1.3
70+
- `tlsMaxVersion` _: 1 | 1.1 | 1.2 | 1.3_ _**optional**_
71+
- Maximum allowed TLS version on SSL connections to this backend.
72+
- If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
73+
- Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is not 1, 1.1, 1.2, or 1.3
74+
- `certificateHostname` _: string_ _**optional**_
75+
- Define the hostname that the server certificate should declare.
76+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string.
77+
- `caCertificate` _: string_ _**optional**_
78+
- The CA certificate to use when checking the validity of the backend.
79+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string.
80+
- `ciphers` _: string_ _**optional**_
81+
- List of OpenSSL ciphers to support for connections to this origin.
82+
- If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
83+
- [List of ciphers supported by Fastly](https://developer.fastly.com/learning/concepts/routing-traffic-to-fastly/#use-a-tls-configuration).
84+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string.
85+
- `sniHostname` _: string_ _**optional**_
86+
- The SNI hostname to use on connections to this backend.
87+
- Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string.
88+
89+
### Return value
90+
91+
A new `Backend` object.
92+
93+
## Examples
94+
95+
In this example an implicit Dynamic Backend is created when making the fetch request to <https://www.fastly.com/> and the response is then returned to the client.
96+
<Fiddle config={{
97+
"type": "javascript",
98+
"title": "Implicit Dynamic Backend Example",
99+
"origins": [
100+
"https://http-me.glitch.me"
101+
],
102+
"src": {
103+
"deps": "{\n \"@fastly/js-compute\": \"^1.0.1\"\n}",
104+
"main": `
105+
/// <reference types="@fastly/js-compute" />
106+
import { allowDynamicBackends } from "fastly:experimental";
107+
allowDynamicBackends(true);
108+
async function app() {
109+
// For any request, return the fastly homepage -- without defining a backend!
110+
return fetch('https://www.fastly.com/');
111+
}
112+
addEventListener("fetch", event => event.respondWith(app(event)));
113+
`
114+
},
115+
"requests": [
116+
{
117+
"enableCluster": true,
118+
"enableShield": false,
119+
"enableWAF": false,
120+
"method": "GET",
121+
"path": "/status=200",
122+
"useFreshCache": false,
123+
"followRedirects": false,
124+
"tests": "",
125+
"delay": 0
126+
}
127+
],
128+
"srcVersion": 1
129+
}}>
130+
131+
```js
132+
/// <reference types="@fastly/js-compute" />
133+
import { allowDynamicBackends } from "fastly:experimental";
134+
allowDynamicBackends(true);
135+
async function app() {
136+
// For any request, return the fastly homepage -- without defining a backend!
137+
return fetch('https://www.fastly.com/');
138+
}
139+
addEventListener("fetch", event => event.respondWith(app(event)));
140+
```
141+
142+
</Fiddle>
143+
144+
In this example an explicit Dynamic Backend is created and supplied to the fetch request, the response is then returned to the client.
145+
146+
147+
<Fiddle config={{
148+
"type": "javascript",
149+
"title": "Explicit Dynamic Backend Example",
150+
"origins": [
151+
"https://http-me.glitch.me"
152+
],
153+
"src": {
154+
"deps": "{\n \"@fastly/js-compute\": \"^1.0.1\"\n}",
155+
"main": `
156+
/// <reference types="@fastly/js-compute" />
157+
import { allowDynamicBackends } from "fastly:experimental";
158+
import { Backend } from "fastly:backend";
159+
allowDynamicBackends(true);
160+
async function app() {
161+
// For any request, return the fastly homepage -- without defining a backend!
162+
const backend = new Backend({
163+
name: 'fastly',
164+
target: 'fastly.com',
165+
hostOverride: "www.fastly.com",
166+
connectTimeout: 1000,
167+
firstByteTimeout: 15000,
168+
betweenBytesTimeout: 10000,
169+
useSSL: true,
170+
sslMinVersion: 1.3,
171+
sslMaxVersion: 1.3,
172+
});
173+
return fetch('https://www.fastly.com/', {
174+
backend // Here we are configuring this request to use the backend from above.
175+
});
176+
}
177+
addEventListener("fetch", event => event.respondWith(app(event)));
178+
`
179+
},
180+
"requests": [
181+
{
182+
"enableCluster": true,
183+
"enableShield": false,
184+
"enableWAF": false,
185+
"method": "GET",
186+
"path": "/status=200",
187+
"useFreshCache": false,
188+
"followRedirects": false,
189+
"tests": "",
190+
"delay": 0
191+
}
192+
],
193+
"srcVersion": 1
194+
}}>
195+
196+
```js
197+
/// <reference types="@fastly/js-compute" />
198+
import { allowDynamicBackends } from "fastly:experimental";
199+
import { Backend } from "fastly:backend";
200+
allowDynamicBackends(true);
201+
async function app() {
202+
// For any request, return the fastly homepage -- without defining a backend!
203+
const backend = new Backend({
204+
name: 'fastly',
205+
target: 'fastly.com',
206+
hostOverride: "www.fastly.com",
207+
connectTimeout: 1000,
208+
firstByteTimeout: 15000,
209+
betweenBytesTimeout: 10000,
210+
useSSL: true,
211+
sslMinVersion: 1.3,
212+
sslMaxVersion: 1.3,
213+
});
214+
return fetch('https://www.fastly.com/', {
215+
backend // Here we are configuring this request to use the backend from above.
216+
});
217+
}
218+
addEventListener("fetch", event => event.respondWith(app(event)));
219+
```
220+
221+
</Fiddle>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
import {Fiddle} from '@site/src/components/fiddle';
8+
9+
# toString
10+
11+
The **`toString()`** method returns a string representing the specified Backend value.
12+
13+
## Syntax
14+
15+
```js
16+
toString()
17+
```
18+
19+
### Return value
20+
21+
A string representing the specified Backend value.
22+
23+
## Description
24+
25+
The [Backend](../Backend.mdx) object overrides the `toString()` method of [Object](../../../globals//Object/Object.mdx); it does not inherit
26+
[`Object.prototype.toString()`](../../../globals/Object/prototype/toString.mdx). For [Backend](../Backend.mdx) values, the `toString` method returns the name given to the [Backend](../Backend.mdx) object during construction.
27+
28+
The `toString()` method requires its `this` value to be a [Backend](../Backend.mdx) object.
29+
30+
If the `this` value does not inherit from `Backend.prototype`, a [TypeError](../../../globals/TypeError/TypeError.mdx) is thrown.
31+
32+
## Examples
33+
34+
### Using toString()
35+
36+
The following example logs the string value of a [Backend](../Backend.mdx) object:
37+
38+
<Fiddle config={{
39+
"type": "javascript",
40+
"title": "Backend.prototype.toString Example",
41+
"origins": [
42+
"https://http-me.glitch.me"
43+
],
44+
"src": {
45+
"deps": "{\n \"@fastly/js-compute\": \"^1.0.1\"\n}",
46+
"main": `
47+
/// <reference types=\"@fastly/js-compute\" />
48+
import { Backend } from "fastly:backend";
49+
async function app() {
50+
const backend = new Backend({
51+
name: "fastly",
52+
target: "fastly.com",
53+
});
54+
console.log(backend.toString()); // "fastly"
55+
}
56+
addEventListener("fetch", event => event.respondWith(app(event)));
57+
`
58+
},
59+
"requests": [
60+
{
61+
"enableCluster": true,
62+
"enableShield": false,
63+
"enableWAF": false,
64+
"method": "GET",
65+
"path": "/status=200",
66+
"useFreshCache": false,
67+
"followRedirects": false,
68+
"tests": "",
69+
"delay": 0
70+
}
71+
],
72+
"srcVersion": 1
73+
}}>
74+
75+
```js
76+
import { Backend } from "fastly:backend";
77+
async function app() {
78+
const backend = new Backend({
79+
name: "fastly",
80+
target: "fastly.com",
81+
});
82+
console.log(backend.toString()); // "fastly"
83+
}
84+
addEventListener("fetch", event => event.respondWith(app(event)));
85+
```
86+
87+
</Fiddle>

0 commit comments

Comments
 (0)