@fastly/js-compute
Advanced tools
Comparing version 0.5.3 to 0.5.4
@@ -0,1 +1,77 @@ | ||
## 0.5.4 (2022-09-28) | ||
#### Dynamic Backend support | ||
This feature makes it possible to use the standard `fetch` within JavaScript applications. | ||
Dynamic Backends is a new feature which enables JavaScript applications to dynamically create new backend server definitions without having to deploy a new version of their Fastly Service. These backends function exactly the same as existing backends, and can be configured in all the same ways as existing backends can via the Fastly Service configuration. | ||
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. To enable Dynamic Backends the application will need to set `fastly.allowDynamicBackends` is to `true`. | ||
There are two ways to make use of Dynamic Backends within JavaScript projects: | ||
The first way is by omitting the `backend` property definition on the Request instance. The JavaScript Runtime will then create a Dynamic Backend definition using default configuration options. This approach is useful for JavaScript applications as it means that a standard `fetch` call will now be possible, which means libraries that use the standard `fetch` will begin to work for applications deployed to Fastly. | ||
Below is as an example JavaScript application using the default Dynamic Backend option: | ||
```js | ||
// Enable dynamic backends -- warning, this is potentially dangerous as third-party dependencies could make requests to their own backends, potentially including your sensitive/secret data | ||
fastly.allowDynamicBackends = true; | ||
// For any request, return the fastly homepage -- without defining a backend! | ||
addEventListener("fetch", event => { | ||
event.respondWith(fetch('https://www.fastly.com/')); | ||
}); | ||
``` | ||
The second way is by creating a new Dynamic Backend using the new `Backend` class. This approach is useful for JavaScript applications that want to have full control over the configuration of the new backend defintion, such as only allowing TLS 1.3 and disallowing older versions of TLS for requests made to the new backend. | ||
E.G. | ||
```js | ||
// Enable dynamic backends -- warning, this is potentially dangerous as third-party dependencies could make requests to their own backends, potentially including your sensitive/secret data | ||
fastly.allowDynamicBackends = true; | ||
// For any request, return the fastly homepage -- without defining a backend! | ||
addEventListener("fetch", event => { | ||
// We are not defining all the possible fields here, the ones which are not defined will use their default value instead. | ||
const backend = new Backend({ | ||
name: 'fastly', | ||
target: 'fastly.com', | ||
hostOverride: "www.fastly.com", | ||
sslMinVersion: 1.3, | ||
sslMaxVersion: 1.3, | ||
sniHostname: "www.fastly.com", | ||
}); | ||
event.respondWith(fetch('https://www.fastly.com/', { | ||
backend // Here we are configuring this request to use the newly defined backend from above. | ||
})); | ||
}); | ||
``` | ||
#### Config-store support and Dictionary deprecated | ||
We have renamed the `Dictionary` class to `ConfigStore`, the old name `Dictionary` still exists but is now deprecated. We recommend replacing `Dictionary` with `ConfigStore` in your code to avoid having to migrate in the future when `Dictionary` is fully removed. | ||
Below is an example application using the `ConfigStore` class: | ||
```js | ||
async function app(event) { | ||
const store = new ConfigStore('example') | ||
// Retrieve the contents of the 'hello' key | ||
const hello = await store.get('hello') | ||
return new Response(hello) | ||
} | ||
addEventListener("fetch", event => { | ||
event.respondWith(app(event)) | ||
}) | ||
``` | ||
### Added | ||
* Add ConfigStore class ([#270](https://github.com/fastly/js-compute-runtime/pull/270)) | ||
* Add Dynamic Backends support ([#250](https://github.com/fastly/js-compute-runtime/issues/250)) | ||
* Improved performance when constructing a ObjectStore instance ([#272](https://github.com/fastly/js-compute-runtime/pull/272) | ||
## 0.5.3 (2022-09-16) | ||
@@ -2,0 +78,0 @@ |
148
index.d.ts
@@ -23,3 +23,89 @@ declare var self: typeof globalThis; | ||
declare interface BackendConfiguration { | ||
/** | ||
* The name of the backend. | ||
*/ | ||
name: string, | ||
/** | ||
* A hostname, IPv4, or IPv6 address for the backend as well as an optional port. | ||
* E.G. "hostname", "ip address", "hostname:port", or "ip address:port" | ||
*/ | ||
target: string, | ||
/** | ||
* If set, will force the HTTP Host header on connections to this backend to be the supplied value. | ||
*/ | ||
hostOverride?: string, | ||
/** | ||
* Maximum duration in milliseconds to wait for a connection to this backend to be established. | ||
* If exceeded, the connection is aborted and a 503 response will be presented instead. | ||
* Defaults to 1,000 milliseconds. | ||
*/ | ||
connectTimeout?: number, | ||
/** | ||
* Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. | ||
* If exceeded, the connection is aborted and a 503 response will be presented instead. | ||
* Defaults to 15,000 milliseconds. | ||
*/ | ||
firstByteTimeout?: number, | ||
/** | ||
* Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. | ||
* If exceeded, the response received so far will be considered complete and the fetch will end. | ||
* Defaults to 10,000 milliseconds. | ||
*/ | ||
betweenBytesTimeout?: number, | ||
/** | ||
* Whether or not to require TLS for connections to this backend. | ||
*/ | ||
useSSL?: boolean, | ||
/** | ||
* Minimum allowed TLS version on SSL connections to this backend. | ||
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. | ||
*/ | ||
tlsMinVersion?: number, | ||
/** | ||
* Maximum allowed TLS version on SSL connections to this backend. | ||
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. | ||
*/ | ||
tlsMaxVersion?: number, | ||
/** | ||
* Define the hostname that the server certificate should declare. | ||
*/ | ||
certificateHostname?: string, | ||
/** | ||
* Whether or not to validate the server certificate. | ||
* Highly recommended to enable this if `useSSL` is set to `true`. | ||
*/ | ||
checkCertificate?: boolean, | ||
/** | ||
* The CA certificate to use when checking the validity of the backend. | ||
*/ | ||
caCertificate?: string, | ||
/** | ||
* List of OpenSSL ciphers to support for connections to this origin. | ||
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. | ||
*/ | ||
ciphers?: string, | ||
/** | ||
* The SNI hostname to use on connections to this backend. | ||
*/ | ||
sniHostname?: string, | ||
} | ||
/** | ||
* Class for creating new [Fastly Backends](https://developer.fastly.com/reference/api/services/backend/). | ||
* | ||
* **Note**: Can only be used when processing requests, not during build-time initialization. | ||
*/ | ||
declare class Backend { | ||
/** | ||
* Creates a new Backend object | ||
*/ | ||
constructor(configuration: BackendConfiguration); | ||
/** | ||
* Returns the name of the Backend, which can be used on {@link RequestInit.backend} | ||
*/ | ||
toString(): string; | ||
} | ||
/** | ||
* A Fastly C@E specific implementation of [FetchEvent](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/FetchEvent). | ||
@@ -149,5 +235,23 @@ */ | ||
/** | ||
* Class for accessing [Fastly Edge Dictionaries](https://docs.fastly.com/en/guides/about-edge-dictionaries). | ||
* | ||
* **Note**: Can only be used when processing requests, not during build-time initialization. | ||
*/ | ||
declare class ConfigStore { | ||
/** | ||
* Creates a new ConfigStore object | ||
*/ | ||
constructor(name: string); | ||
/** | ||
* Get a value for a key in the config-store. | ||
*/ | ||
get(key: string): string; | ||
} | ||
/** | ||
* Class for accessing [Fastly Edge Dictionaries](https://docs.fastly.com/en/guides/about-edge-dictionaries). | ||
* | ||
* **Note**: Can only be used when processing requests, not during build-time initialization. | ||
* @deprecated This class has been renamed `ConfigStore`. Replace `Dictionary` with `ConfigStore` in your code to avoid having to migrate in the future when `Dictionary` is removed. | ||
*/ | ||
@@ -357,24 +461,24 @@ declare class Dictionary { | ||
declare interface ObjectStoreEntry { | ||
/** | ||
* A ReadableStream with the contents of the entry. | ||
*/ | ||
get body(): ReadableStream; | ||
/** | ||
* A boolean value that indicates whether the body has been read from already. | ||
*/ | ||
get bodyUsed(): boolean; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with a string. | ||
* The response is always decoded using UTF-8. | ||
*/ | ||
text(): Promise<string>; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with the result of parsing the body text as JSON. | ||
*/ | ||
json(): Promise<object>; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with an ArrayBuffer. | ||
*/ | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
// And eventually formData and blob once we support them on Request and Response, too. | ||
/** | ||
* A ReadableStream with the contents of the entry. | ||
*/ | ||
get body(): ReadableStream; | ||
/** | ||
* A boolean value that indicates whether the body has been read from already. | ||
*/ | ||
get bodyUsed(): boolean; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with a string. | ||
* The response is always decoded using UTF-8. | ||
*/ | ||
text(): Promise<string>; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with the result of parsing the body text as JSON. | ||
*/ | ||
json(): Promise<object>; | ||
/** | ||
* Reads the body and returns it as a promise that resolves with an ArrayBuffer. | ||
*/ | ||
arrayBuffer(): Promise<ArrayBuffer>; | ||
// And eventually formData and blob once we support them on Request and Response, too. | ||
} | ||
@@ -381,0 +485,0 @@ |
{ | ||
"name": "@fastly/js-compute", | ||
"version": "0.5.3", | ||
"js-compute-runtime-version": "0.5.2", | ||
"version": "0.5.4", | ||
"js-compute-runtime-version": "0.5.3", | ||
"engines": { | ||
@@ -35,3 +35,3 @@ "node": "^16 || ^18" | ||
"devDependencies": { | ||
"tsd": "^0.22.0", | ||
"tsd": "^0.24.1", | ||
"typedoc": "^0.21", | ||
@@ -38,0 +38,0 @@ "typescript": "^4.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
60599538
84
2009
5