diff --git a/.changeset/config.json b/.changeset/config.json index 6fa7ea240..dbf3a08d2 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,10 +1,20 @@ { "$schema": "https://unpkg.com/@changesets/config@2.0.1/schema.json", - "changelog": ["@changesets/changelog-github", { "repo": "lagonapp/lagon" }], + "changelog": [ + "@changesets/changelog-github", + { + "repo": "lagonapp/lagon" + } + ], "commit": false, - "fixed": [], + "fixed": [ + [ + "@lagon/runtime", + "@lagon/js-runtime" + ] + ], "linked": [], "access": "public", "baseBranch": "main", "updateInternalDependencies": "patch" -} +} \ No newline at end of file diff --git a/.changeset/tricky-dogs-impress.md b/.changeset/tricky-dogs-impress.md new file mode 100644 index 000000000..8737311ed --- /dev/null +++ b/.changeset/tricky-dogs-impress.md @@ -0,0 +1,6 @@ +--- +'@lagon/docs': minor +'@lagon/js-runtime': minor +--- + +Add `navigator.userAgent` API diff --git a/packages/docs/pages/runtime-apis.mdx b/packages/docs/pages/runtime-apis.mdx index 10966d95b..2c3563f48 100644 --- a/packages/docs/pages/runtime-apis.mdx +++ b/packages/docs/pages/runtime-apis.mdx @@ -32,7 +32,7 @@ You can log multiple objects, and use string substitution. [See the documentatio ### `process` -The only usage of `process` is to get [environment variables](/cloud/environment-variables) via `process.env`. +The only usage of `process` is to access [environment variables](/cloud/environment-variables) via `process.env`. Example: @@ -44,6 +44,12 @@ export function handler(request: Request): Response { --- +### `navigator.userAgent` + +`navigator.userAgent` is a fixed string that can be used to detect the current runtime. Its value is always `Lagon/VERSION`, where `VERSION` is the current version of the Lagon Runtime. + +--- + ### `crypto` The standard `crypto` object. diff --git a/packages/js-runtime/package.json b/packages/js-runtime/package.json index b5b3ad95b..decd9c5c8 100644 --- a/packages/js-runtime/package.json +++ b/packages/js-runtime/package.json @@ -1,6 +1,6 @@ { "name": "@lagon/js-runtime", - "version": "0.1.8", + "version": "0.1.10", "description": "JavaScript Runtime", "private": true, "type": "module", @@ -17,4 +17,4 @@ "blob-polyfill": "^7.0.20220408", "web-streams-polyfill": "^3.2.1" } -} +} \ No newline at end of file diff --git a/packages/js-runtime/src/index.ts b/packages/js-runtime/src/index.ts index 5c374d4f4..4242a4cd2 100644 --- a/packages/js-runtime/src/index.ts +++ b/packages/js-runtime/src/index.ts @@ -9,6 +9,7 @@ import './runtime/blob'; import './runtime/global/console'; import './runtime/global/process'; import './runtime/global/crypto'; +import './runtime/global/navigator'; import './runtime/http/URLSearchParams'; import './runtime/http/URL'; import './runtime/http/Headers'; diff --git a/packages/js-runtime/src/runtime/global/navigator.ts b/packages/js-runtime/src/runtime/global/navigator.ts new file mode 100644 index 000000000..2554ed4f6 --- /dev/null +++ b/packages/js-runtime/src/runtime/global/navigator.ts @@ -0,0 +1,12 @@ +// esbuild will inline the version as a const, and since both +// runtime and js-runtime are versioned together, we can safely +// import the version from the package.json instead of injecting +// it from the Rust code. +import { version } from '../../../package.json'; + +(globalThis => { + globalThis.navigator = { + ...globalThis.navigator, + userAgent: `Lagon/${version}`, + }; +})(globalThis);