Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ git submodule update --recursive --init
Software that needs installing to work with this library:

- Rust
```
```sh
curl -so rust.sh https://sh.rustup.rs && sh rust.sh -y
restart shell or run source $HOME/.cargo/env
```
Expand Down
3 changes: 3 additions & 0 deletions create-wit-bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

~/.cargo/bin/wit-bindgen c --out-dir runtime/fastedge/host-api/bindings --world bindings runtime/fastedge/host-api/wit
13 changes: 13 additions & 0 deletions docs/examples/variables-and-secrets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getEnv } from 'fastedge::env';
import { getSecret } from 'fastedge::secret';

async function eventHandler(event) {
const username = getEnv('USERNAME');
const password = getSecret('PASSWORD');

return new Response(`Username: ${username}, Password: ${password}`);
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
13 changes: 8 additions & 5 deletions docs/src/content/docs/examples/main-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { LinkCard, CardGrid } from '@astrojs/starlight/components';

This is a brief list of examples, demonstrating the basic usage of FastEdge compute.

More examples will be added to the
More examples will be added to the examples-repo as we build out more functionality.

<a href='https://github.com/G-Core/FastEdge-sdk-js/tree/main/docs/examples' target='_blank'>
repo
<a href='https://github.com/G-Core/FastEdge-examples/tree/main/javascript' target='_blank'>
examples-repo
</a>
as we build out more functionality.

## Some Examples
## Some Basic Examples

<CardGrid>
<LinkCard title='Basic example' href='/FastEdge-sdk-js/examples/basic/' />
Expand All @@ -27,4 +26,8 @@ as we build out more functionality.
title='Header manipulation with environment variables'
href='/FastEdge-sdk-js/examples/headers/'
/>
<LinkCard
title='Environment variables and secrets'
href='/FastEdge-sdk-js/examples/variables-and-secrets/'
/>
</CardGrid>
12 changes: 12 additions & 0 deletions docs/src/content/docs/examples/variables-and-secrets.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Environment Variables and Secrets
description: An example using environment variables and secrets.
prev:
link: /FastEdge-sdk-js/examples/main-examples/
label: Back to examples
---

import { Code } from '@astrojs/starlight/components';
import importedCode from '/examples/variables-and-secrets.js?raw';

<Code code={importedCode} lang='js' title='docs/examples/variables-and-secrets.js' />
38 changes: 38 additions & 0 deletions docs/src/content/docs/reference/fastedge::secret/getSecret.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: getSecret
description: How to use FastEdge secret variables.
---

### Secret Variables

To access secret variables, set during deployment on the FastEdge network.

```js
import { getSecret } from 'fastedge::secret';

async function eventHandler(event) {
const secretToken = getSecret('MY_SECRET_TOKEN');
return new Response({ secretToken });
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
getSecret(secretName);
```

##### Parameters

- `secretName` (required)

A string containing the name of the key you want to retrieve the value of.

##### Return Value

A string containing the value of the key. If the key does not exist, null is returned.

**Note**: If the secret contains multiple `secret_slots` you will always receive the MAX `slot`
value.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
title: getSecretEffectiveAt
description: How to use FastEdge secret variables.
---

### Secret Variables

To access slot specific secret variables, set during deployment on the FastEdge network.

```js
import { getSecretEffectiveAt } from 'fastedge::secret';

async function eventHandler(event) {
const secretToken = getSecretEffectiveAt('MY_SECRET_TOKEN', 1);
return new Response({ secretToken });
}

addEventListener('fetch', (event) => {
event.respondWith(eventHandler(event));
});
```

```js title="SYNTAX"
getSecretEffectiveAt(secretName, 0);
```

##### Parameters

- `secretName` (required)

A string containing the name of the key you want to retrieve the value of.

- `effectiveAt` (required)

A number representing the slot you wish to access.

##### Return Value

A string containing the value of the key. If the key does not exist, null is returned.

### Slots and secret rollover

Using `getSecretEffectiveAt()` to access different slots within a given secret and how to use slots.

The concept of slots allows you to manage secret rollover within your own applications in many
different ways.

##### Example 1 (Slots as indices)

Validating a token against a specific version of a secret.

Having created a secret:

```json
{
"secret": {
"comment": "The password to validate the token has been signed with",
"id": 168,
"name": "token-secret",
"secret_slots": [
{
"slot": 0,
"value": "original_password"
},
{
"slot": 5,
"value": "updated_password"
}
]
}
}
```

It would now be easy enough to also provide the `slot` value within the tokens claims as to which
password it should validate against. This would allow you to slowly rollover from one password to
another and keep all users able to refresh their tokens without issues, as each users token also
carries the data to know which password was still in use when it was issued.

It always returns `effectiveAt >= secret_slots.slot`

So a request to:

- `getSecretEffectiveAt("token-secret", 0)` would return `original_password`
- `getSecretEffectiveAt("token-secret", 3)` would return `original_password`
- `getSecretEffectiveAt("token-secret", 5)` would return `updated_password`
- `getSecretEffectiveAt("token-secret", 7)` would return `updated_password`

This `>=` logic makes it very easy to implement the following example.

##### Example 2 (Slots as timestamps)

Validating a token against a specific version of a secret using timestamps:

```json
{
"secret": {
"comment": "The password to validate the token has been signed with",
"id": 168,
"name": "token-secret",
"secret_slots": [
{
"slot": 0,
"value": "original_password"
},
{
"slot": 1741790697, // Wed Mar 12 2025 14:44:57
"value": "new_password"
}
]
}
}
```

As you can see any token being validated with an `iat` claim time before 1741790697 would use the
`original_password` and any token after this time would start to use the `new_password`

This is as simple as using `getSecretEffectiveAt("token-secret", claims.iat)`
28 changes: 28 additions & 0 deletions docs/src/content/docs/reference/headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Headers
description: Response / Request Headers.
---

TThe Headers() constructor creates a new Headers object.

```js
new Headers();
new Headers(init);
```

##### Parameters

- `init` (optional)

An object containing any HTTP headers you want to prepopulate your `Headers` object with. This can
be a simple object literal with String values, an array of name-value pairs, where each pair is a
2-element string array; or an existing Headers object. In the last case, the new Headers object
copies its data from the existing Headers object.

:::note[INFO]

Request and Response Headers are immutable. This means, if you need to modify Request headers for
downstream fetch requests, or modify Response headers prior to returning a Response. You will need
to create a `new Headers()` object.

:::
4 changes: 2 additions & 2 deletions docs/src/content/docs/reference/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This Javascript SDK is not yet fully fledged, but it is growing quickly.
As we test and write more functionality we will endeavour to keep adding to this reference guide.

At present there is all the basic javascript functionality provided by
<a href="https://spidermonkey.dev/" target="_blank">SpiderMonkey</a>. This is the engine our
Javascript product is embedded with.
<a href="https://github.com/bytecodealliance/StarlingMonkey" target="_blank">StarlingMonkey</a>.
This is the engine our Javascript product is embedded with.

We will continue to add more, so please check back often!
37 changes: 37 additions & 0 deletions docs/src/content/docs/reference/request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Request
description: Request object definition.
---

The Request() constructor creates a new Request object.

```js
new Request(input);
new Request(input, options);
```

##### Parameters

- `input`

Defines the resource you wish to fetch. Can be one of the following:

- A string containing the resource you wish to fetch.
- `Request` object, effectively creating a copy.

- `options` (optional)

An options object containing any other data to associate with the Request

- method: (optional)

e.g. `GET`, `POST`, `PUT`, `DELETE`. (Default is `GET`)

- headers: (optional)

An object: containing either a `Headers` object or object literal with `String` key/value pairs.

- body: (optional)

Any body that you want to add to your request: this can be an `ArrayBuffer`, a `TypedArray`, a
`DataView`, a `URLSearchParams`, string object or literal, or a `ReadableStream` object.
15 changes: 14 additions & 1 deletion docs/src/content/docs/reference/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ new Response(body, options);

- `body` (optional)

A string defining the body of a response. This can be `null` that is the default.
A object defining the body of a response. This can be `null` (which is the default) or one of the
following:

- ArrayBuffer
- TypedArray
- DataView
- ReadableStream
- URLSearchParams
- String
- string literal

- `options` (optional)

Expand All @@ -25,6 +34,10 @@ new Response(body, options);

A number representing the http status code. e.g. `200`

- statusText: (optional)

The status message associated with the status code, e.g. `OK`.

- headers: (optional)

An object: containing either a `Headers` object or object literal with `String` key/value pairs.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"build:monkey:prod": "./runtime/fastedge/build.sh",
"build:libs": "node esbuild/fastedge-libs.js",
"build:types": "tsc -p ./src/static-server/tsconfig.json",
"FIX:build:wasm": "node build-examples-config.js",
"FIX:generate:wit-world": "make -j8 -C fastedge-runtime/cbindings generate-wit-bindgen",
"generate:wit-world": "./create-wit-bindings.sh",
"lint": "npx eslint -c ./config/eslint/repo/.eslintrc.cjs .",
"semantic-release": "semantic-release",
"test:solo": "NODE_ENV=test jest -c ./config/jest/jest.config.js --",
Expand Down
2 changes: 1 addition & 1 deletion runtime/StarlingMonkey
Submodule StarlingMonkey updated 96 files
+16 −33 .github/workflows/main.yml
+9 −0 ADOPTERS.md
+15 −15 CMakeLists.txt
+59 −8 README.md
+2 −2 builtins/web/crypto/crypto-algorithm.h
+2 −2 builtins/web/crypto/crypto-key-ec-components.h
+2 −2 builtins/web/crypto/crypto-key-rsa-components.h
+2 −2 builtins/web/crypto/crypto-key.h
+2 −2 builtins/web/crypto/crypto.h
+2 −2 builtins/web/crypto/json-web-key.h
+2 −2 builtins/web/crypto/subtle-crypto.h
+2 −2 builtins/web/dom-exception.h
+7 −5 builtins/web/fetch/fetch-api.cpp
+1 −0 builtins/web/fetch/fetch-errors.h
+15 −84 builtins/web/fetch/fetch_event.cpp
+2 −2 builtins/web/fetch/fetch_event.h
+781 −443 builtins/web/fetch/headers.cpp
+85 −45 builtins/web/fetch/headers.h
+179 −140 builtins/web/fetch/request-response.cpp
+11 −13 builtins/web/fetch/request-response.h
+2 −2 builtins/web/performance.h
+2 −2 builtins/web/queue-microtask.h
+2 −2 builtins/web/streams/compression-stream.h
+2 −2 builtins/web/streams/decompression-stream.h
+2 −2 builtins/web/streams/native-stream-sink.h
+2 −2 builtins/web/streams/native-stream-source.h
+2 −2 builtins/web/streams/transform-stream-default-controller.h
+39 −19 builtins/web/streams/transform-stream.cpp
+2 −2 builtins/web/streams/transform-stream.h
+2 −2 builtins/web/structured-clone.h
+28 −92 builtins/web/url.cpp
+2 −2 builtins/web/url.h
+2 −2 builtins/web/worker-location.h
+1 −1 cmake/add_as_subproject.cmake
+10 −2 cmake/openssl.cmake
+1 −1 cmake/spidermonkey.cmake
+2 −2 cmake/weval.cmake
+43 −24 componentize.sh
+2 −0 crates/rust-url/rust-url.h
+2,240 −2,362 host-apis/wasi-0.2.0/bindings/bindings.c
+2,354 −2,400 host-apis/wasi-0.2.0/bindings/bindings.h
+ host-apis/wasi-0.2.0/bindings/bindings_component_type.o
+291 −322 host-apis/wasi-0.2.0/host_api.cpp
+3 −5 host-apis/wasi-0.2.0/include/exports.h
+ host-apis/wasi-0.2.0/preview1-adapter-debug/wasi_snapshot_preview1.wasm
+ host-apis/wasi-0.2.0/preview1-adapter-release/wasi_snapshot_preview1.wasm
+77 −5 include/builtin.h
+109 −0 include/config-parser.h
+31 −10 include/extension-api.h
+31 −30 include/host_api.h
+0 −10 runtime/builtin.cpp
+7 −1 runtime/decode.cpp
+1 −0 runtime/decode.h
+37 −0 runtime/encode.cpp
+4 −0 runtime/encode.h
+168 −85 runtime/engine.cpp
+0 −2 runtime/event_loop.cpp
+55 −31 runtime/js.cpp
+2 −1 runtime/script_loader.cpp
+21 −8 runtime/sequence.hpp
+0 −0 tests/assert.js
+13 −0 tests/e2e/eventloop-stall/eventloop-stall.js
+1 −0 tests/e2e/eventloop-stall/expect_serve_stderr.txt
+1 −0 tests/e2e/headers/expect_serve_body.txt
+8 −0 tests/e2e/headers/expect_serve_headers.txt
+0 −0 tests/e2e/headers/expect_serve_stderr.txt
+42 −0 tests/e2e/headers/headers.js
+1 −0 tests/e2e/multi-stream-forwarding/expect_serve_body.txt
+58 −0 tests/e2e/multi-stream-forwarding/multi-stream-forwarding.js
+1 −0 tests/e2e/runtime-err/expect_serve_status.txt
+10 −0 tests/e2e/runtime-err/expect_serve_stderr.txt
+9 −0 tests/e2e/runtime-err/runtime-err.js
+2 −1 tests/e2e/syntax-err/expect_wizer_stderr.txt
+2 −1 tests/e2e/tla-err/expect_wizer_stderr.txt
+1 −1 tests/integration/btoa/btoa.js
+1 −1 tests/integration/crypto/crypto.js
+1 −1 tests/integration/fetch/fetch.js
+1 −1 tests/integration/performance/performance.js
+1 −1 tests/integration/test-server.js
+0 −285 tests/integration/tests/performance.js
+1 −1 tests/integration/timers/timers.js
+27 −9 tests/test.sh
+17 −12 tests/tests.cmake
+1 −1 tests/wpt-harness/build-wpt-runtime.sh
+1 −1 tests/wpt-harness/expectations/fetch/api/basic/request-headers-nonascii.any.js.json
+17 −17 tests/wpt-harness/expectations/fetch/api/headers/header-setcookie.any.js.json
+9 −9 tests/wpt-harness/expectations/fetch/api/headers/headers-basic.any.js.json
+1 −1 tests/wpt-harness/expectations/fetch/api/headers/headers-combine.any.js.json
+3 −3 tests/wpt-harness/expectations/fetch/api/headers/headers-errors.any.js.json
+7 −7 tests/wpt-harness/expectations/fetch/api/headers/headers-record.any.js.json
+1 −1 tests/wpt-harness/expectations/fetch/api/request/request-headers.any.js.json
+1 −1 tests/wpt-harness/expectations/fetch/api/response/response-headers-guard.any.js.json
+5 −4 tests/wpt-harness/run-wpt.mjs
+5 −5 tests/wpt-harness/tests.json
+2 −2 tests/wpt-harness/wpt.cmake
+0 −1 tests/wpt-harness/wpt_builtins.cpp
4 changes: 2 additions & 2 deletions runtime/fastedge/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ HOST_API=$(realpath host-api) cmake -B $BUILD_PATH -DCMAKE_BUILD_TYPE=$BUILD_TYP
# cmake --build $BUILD_PATH --parallel 16
cmake --build $BUILD_PATH --parallel 8
# Copy the built WebAssembly module to the parent directory
mv $BUILD_PATH/starling.wasm/starling.wasm ../../lib/fastedge-runtime.wasm
mv $BUILD_PATH/starling.wasm/preview1-adapter.wasm ../../lib/preview1-adapter.wasm
mv $BUILD_PATH/starling-raw.wasm/starling-raw.wasm ../../lib/fastedge-runtime.wasm
mv $BUILD_PATH/starling-raw.wasm/preview1-adapter.wasm ../../lib/preview1-adapter.wasm
Loading
Loading