├── .changeset ├── README.md └── config.json ├── .github ├── actions │ └── setup-project │ │ └── action.yml └── workflows │ ├── changeset.yml │ └── ci.yml ├── .gitignore ├── .npmrc ├── README.md ├── asset └── bunny.png ├── docs-json ├── sdk-0.11.1.json ├── sdk-0.11.2.json └── sdk-latest.json ├── docs ├── .nojekyll ├── assets │ ├── highlight.css │ ├── icons.js │ ├── icons.svg │ ├── main.js │ ├── navigation.js │ ├── search.js │ └── style.css ├── classes │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.InvalidAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.InvalidAddr.html │ └── _bunny_net_edgescript_sdk_latest.net.socketAddr.InvalidAddr.html ├── functions │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.serve.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.servePullZone.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.toString.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.tryParseFromString.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.isV4.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.v4.ip.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.v4.port.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.v4.tryFromString.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.bind.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.isTcpListener.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.toString.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.unstable_local_addr.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.unstable_new.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.serve.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.servePullZone.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.toString.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.tryParseFromString.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.isV4.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.v4.ip.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.v4.port.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.v4.tryFromString.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.bind.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.isTcpListener.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.toString.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.unstable_local_addr.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.unstable_new.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.serve.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.servePullZone.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.toString.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.tryParseFromString.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.isV4.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.v4.ip.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.v4.port.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.v4.tryFromString.html │ ├── _bunny_net_edgescript_sdk_latest.net.tcp.bind.html │ ├── _bunny_net_edgescript_sdk_latest.net.tcp.isTcpListener.html │ ├── _bunny_net_edgescript_sdk_latest.net.tcp.toString.html │ ├── _bunny_net_edgescript_sdk_latest.net.tcp.unstable_local_addr.html │ └── _bunny_net_edgescript_sdk_latest.net.tcp.unstable_new.html ├── index.html ├── media │ └── example │ │ ├── deno-middleware-http │ │ ├── .gitignore │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── main.ts │ │ ├── deno-simple-http-page │ │ ├── .gitignore │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── main.ts │ │ ├── middleware-simple-http │ │ ├── .gitignore │ │ ├── CHANGELOG.md │ │ ├── eslint.config.mjs │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ │ └── main.ts │ │ ├── tests │ │ │ └── empty.test.ts │ │ └── tsconfig.json │ │ └── simple-http-page │ │ ├── .gitignore │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── eslint.config.mjs │ │ ├── jest.config.js │ │ ├── package.json │ │ ├── src │ │ └── main.ts │ │ ├── tests │ │ └── empty.test.ts │ │ └── tsconfig.json ├── modules │ ├── _bunny_net_edgescript_sdk_0_11_1.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.v4.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.html │ ├── _bunny_net_edgescript_sdk_0_11_2.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.v4.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.html │ ├── _bunny_net_edgescript_sdk_latest.html │ ├── _bunny_net_edgescript_sdk_latest.net.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.v4.html │ └── _bunny_net_edgescript_sdk_latest.net.tcp.html └── types │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.OriginRequestContext.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.OriginResponseContext.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.PullZoneHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.PullZoneHandlerOptions.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.ServeHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.http.ServerHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.Enumerate.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.IPv4.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.ip.Range.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.NoAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.SocketAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.SocketAddrError.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.socketAddr.v4.SocketAddrV4.html │ ├── _bunny_net_edgescript_sdk_0_11_1.net.tcp.TcpListener.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.OriginRequestContext.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.OriginResponseContext.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.PullZoneHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.PullZoneHandlerOptions.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.ServeHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.http.ServerHandler.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.Enumerate.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.IPv4.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.ip.Range.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.NoAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.SocketAddr.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.SocketAddrError.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.socketAddr.v4.SocketAddrV4.html │ ├── _bunny_net_edgescript_sdk_0_11_2.net.tcp.TcpListener.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.OriginRequestContext.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.OriginResponseContext.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.PullZoneHandler.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.PullZoneHandlerOptions.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.ServeHandler.html │ ├── _bunny_net_edgescript_sdk_latest.net.http.ServerHandler.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.Enumerate.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.IPv4.html │ ├── _bunny_net_edgescript_sdk_latest.net.ip.Range.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.NoAddr.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddr.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddrError.html │ ├── _bunny_net_edgescript_sdk_latest.net.socketAddr.v4.SocketAddrV4.html │ └── _bunny_net_edgescript_sdk_latest.net.tcp.TcpListener.html ├── example ├── deno-middleware-http │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ └── src │ │ └── main.ts ├── deno-simple-http-page │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package.json │ └── src │ │ └── main.ts ├── middleware-simple-http │ ├── .gitignore │ ├── CHANGELOG.md │ ├── eslint.config.mjs │ ├── jest.config.js │ ├── package.json │ ├── src │ │ └── main.ts │ ├── tests │ │ └── empty.test.ts │ └── tsconfig.json └── simple-http-page │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── eslint.config.mjs │ ├── jest.config.js │ ├── package.json │ ├── src │ └── main.ts │ ├── tests │ └── empty.test.ts │ └── tsconfig.json ├── libs ├── bunny-sdk │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── build.mjs │ ├── eslint.config.mjs │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── lib.ts │ │ ├── net │ │ │ ├── _impl │ │ │ │ └── node │ │ │ │ │ └── serve.ts │ │ │ ├── index.ts │ │ │ ├── ip.test.ts │ │ │ ├── ip.ts │ │ │ ├── serve.ts │ │ │ ├── socket │ │ │ │ ├── v4.test.ts │ │ │ │ └── v4.ts │ │ │ ├── socket_addr.ts │ │ │ └── tcp.ts │ │ └── platform.ts │ ├── tests │ │ └── empty.test.ts │ ├── tsconfig.eslint.json │ ├── tsconfig.json │ ├── typedoc.json │ └── types │ │ ├── bunny.d.ts │ │ └── deno.d.ts └── bunny-storage │ ├── .gitignore │ ├── CHANGELOG.md │ ├── README.md │ ├── build.mjs │ ├── eslint.config.mjs │ ├── jest.config.js │ ├── package.json │ ├── src │ ├── api.ts │ ├── file.test.ts │ ├── file.ts │ ├── lib.ts │ ├── regions.test.ts │ ├── regions.ts │ ├── zone.test.ts │ └── zone.ts │ ├── tests │ ├── __snapshots__ │ │ └── integration.test.ts.snap │ └── integration.test.ts │ ├── tsconfig.eslint.json │ ├── tsconfig.json │ ├── typedoc.json │ └── types │ ├── bunny.d.ts │ └── deno.d.ts ├── package.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── scripts ├── build-doc.sh └── publish.sh ├── typedoc.base.jsonc └── typedoc.json /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.2/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.github/actions/setup-project/action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Node, deno, pnpm & install' 2 | 3 | description: 'Setup node, deno, pnpm and install' 4 | 5 | runs: 6 | using: "composite" 7 | steps: 8 | - uses: pnpm/action-setup@v4.1.0 9 | with: 10 | version: 9 11 | 12 | - uses: actions/setup-node@v3 13 | with: 14 | node-version: '22' 15 | cache: 'pnpm' 16 | cache-dependency-path: './pnpm-lock.yaml' 17 | 18 | - uses: denoland/setup-deno@v1 19 | with: 20 | deno-version: v2.x 21 | 22 | - name: Install 23 | shell: bash 24 | run: pnpm install --frozen-lockfile 25 | 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/changeset.yml: -------------------------------------------------------------------------------- 1 | name: Release Changeset 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | concurrency: ${{ github.workflow }}-${{ github.ref }} 9 | 10 | jobs: 11 | release: 12 | permissions: 13 | contents: write 14 | issues: write 15 | pull-requests: write 16 | 17 | if: github.repository == 'BunnyWay/edge-script-sdk' 18 | 19 | name: Release 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Checkout Repo 23 | uses: actions/checkout@v4 24 | with: 25 | token: ${{ secrets.BUNNY_GITHUB }} 26 | 27 | - name: Creating .npmrc 28 | run: | 29 | cat << EOF > "$HOME/.npmrc" 30 | //registry.npmjs.org/:_authToken=$NPM_TOKEN 31 | EOF 32 | env: 33 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 34 | 35 | - name: Setup Javascript 36 | uses: ./.github/actions/setup-project 37 | 38 | 39 | - name: Create Release Pull Request 40 | uses: changesets/action@v1 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.BUNNY_GITHUB }} 43 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 44 | with: 45 | publish: "pnpm ci:publish" 46 | version: "pnpm ci:version" 47 | title: "🎉 Release" 48 | createGithubReleases: true 49 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continous integration 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | 8 | jobs: 9 | checkout: 10 | runs-on: ubuntu-latest 11 | 12 | name: 'Install, lint and test' 13 | 14 | steps: 15 | - name: 'Checkout' 16 | uses: actions/checkout@v4 17 | 18 | - name: 'Setup Javascript' 19 | uses: ./.github/actions/setup-project 20 | 21 | - name: 'Lint' 22 | run: pnpm run -r lint 23 | 24 | - name: 'Test' 25 | run: pnpm run -r test 26 | env: 27 | STORAGE_ACCESS_KEY: ${{ secrets.STORAGE_ACCESS_KEY }} 28 | STORAGE_ZONE: ${{ secrets.STORAGE_ZONE }} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | .vscode 29 | 30 | # local env files 31 | .env*.local 32 | 33 | # vercel 34 | .vercel 35 | 36 | # typescript 37 | *.tsbuildinfo 38 | next-env.d.ts 39 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | strict-peer-dependencies=false 3 | link-workspace-packages=true 4 | 5 | public-hoist-pattern[]=*eslint* 6 | public-hoist-pattern[]=*prettier* 7 | public-hoist-pattern[]=@types* 8 | public-hoist-pattern[]=@jest* 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | Bunny 4 | 5 |
6 | 7 | # Bunny Edge SDK 8 | 9 | This repository contains multiple libraries to work with Bunny: 10 | 11 | - [@bunny.net/edgescript-sdk](./libs/bunny-sdk/): a library designed to simplify the development and testing of applications on the Bunny Edge Scripting platform. With this SDK, you can build, debug, and run scripts locally, then deploy them seamlessly to Bunny’s global edge network for production. 12 | - [@bunny.net/storage-sdk](./libs/bunny-storage/): a library designed to help you interact with the 13 | Bunny Storage, to store & access file efficiently accross our whole network. 14 | 15 | ## 🥕 Usage 16 | 17 | With `@bunny.net/edgescript-sdk`, you can write scripts that run smoothly on Deno, Node, and within the bunny.net network. Below is a quick example to help you get started with setting up a local server. For additional examples and use cases, refer to the [examples folder](./example/). 18 | 19 | ### Hello World Example 20 | ```typescript 21 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 22 | 23 | function sleep(ms: number): Promise { 24 | return new Promise((resolve) => setTimeout(resolve, ms)); 25 | } 26 | 27 | console.log("Starting server..."); 28 | 29 | BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { 30 | console.log(`[INFO]: ${req.method} - ${req.url}`); 31 | await sleep(1000); // Simulate some processing delay 32 | return new Response("Hello, Bunny Edge!"); 33 | }); 34 | ``` 35 | 36 | If you want more information, feel free to dive into each packages to check 37 | associated examples and documentations. 38 | -------------------------------------------------------------------------------- /asset/bunny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/asset/bunny.png -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /docs/assets/highlight.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --light-hl-0: #AF00DB; 3 | --dark-hl-0: #C586C0; 4 | --light-hl-1: #000000; 5 | --dark-hl-1: #D4D4D4; 6 | --light-hl-2: #0000FF; 7 | --dark-hl-2: #569CD6; 8 | --light-hl-3: #001080; 9 | --dark-hl-3: #9CDCFE; 10 | --light-hl-4: #A31515; 11 | --dark-hl-4: #CE9178; 12 | --light-hl-5: #795E26; 13 | --dark-hl-5: #DCDCAA; 14 | --light-hl-6: #267F99; 15 | --dark-hl-6: #4EC9B0; 16 | --light-hl-7: #098658; 17 | --dark-hl-7: #B5CEA8; 18 | --light-hl-8: #000000FF; 19 | --dark-hl-8: #D4D4D4; 20 | --light-hl-9: #0070C1; 21 | --dark-hl-9: #4FC1FF; 22 | --light-hl-10: #008000; 23 | --dark-hl-10: #6A9955; 24 | --light-code-background: #FFFFFF; 25 | --dark-code-background: #1E1E1E; 26 | } 27 | 28 | @media (prefers-color-scheme: light) { :root { 29 | --hl-0: var(--light-hl-0); 30 | --hl-1: var(--light-hl-1); 31 | --hl-2: var(--light-hl-2); 32 | --hl-3: var(--light-hl-3); 33 | --hl-4: var(--light-hl-4); 34 | --hl-5: var(--light-hl-5); 35 | --hl-6: var(--light-hl-6); 36 | --hl-7: var(--light-hl-7); 37 | --hl-8: var(--light-hl-8); 38 | --hl-9: var(--light-hl-9); 39 | --hl-10: var(--light-hl-10); 40 | --code-background: var(--light-code-background); 41 | } } 42 | 43 | @media (prefers-color-scheme: dark) { :root { 44 | --hl-0: var(--dark-hl-0); 45 | --hl-1: var(--dark-hl-1); 46 | --hl-2: var(--dark-hl-2); 47 | --hl-3: var(--dark-hl-3); 48 | --hl-4: var(--dark-hl-4); 49 | --hl-5: var(--dark-hl-5); 50 | --hl-6: var(--dark-hl-6); 51 | --hl-7: var(--dark-hl-7); 52 | --hl-8: var(--dark-hl-8); 53 | --hl-9: var(--dark-hl-9); 54 | --hl-10: var(--dark-hl-10); 55 | --code-background: var(--dark-code-background); 56 | } } 57 | 58 | :root[data-theme='light'] { 59 | --hl-0: var(--light-hl-0); 60 | --hl-1: var(--light-hl-1); 61 | --hl-2: var(--light-hl-2); 62 | --hl-3: var(--light-hl-3); 63 | --hl-4: var(--light-hl-4); 64 | --hl-5: var(--light-hl-5); 65 | --hl-6: var(--light-hl-6); 66 | --hl-7: var(--light-hl-7); 67 | --hl-8: var(--light-hl-8); 68 | --hl-9: var(--light-hl-9); 69 | --hl-10: var(--light-hl-10); 70 | --code-background: var(--light-code-background); 71 | } 72 | 73 | :root[data-theme='dark'] { 74 | --hl-0: var(--dark-hl-0); 75 | --hl-1: var(--dark-hl-1); 76 | --hl-2: var(--dark-hl-2); 77 | --hl-3: var(--dark-hl-3); 78 | --hl-4: var(--dark-hl-4); 79 | --hl-5: var(--dark-hl-5); 80 | --hl-6: var(--dark-hl-6); 81 | --hl-7: var(--dark-hl-7); 82 | --hl-8: var(--dark-hl-8); 83 | --hl-9: var(--dark-hl-9); 84 | --hl-10: var(--dark-hl-10); 85 | --code-background: var(--dark-code-background); 86 | } 87 | 88 | .hl-0 { color: var(--hl-0); } 89 | .hl-1 { color: var(--hl-1); } 90 | .hl-2 { color: var(--hl-2); } 91 | .hl-3 { color: var(--hl-3); } 92 | .hl-4 { color: var(--hl-4); } 93 | .hl-5 { color: var(--hl-5); } 94 | .hl-6 { color: var(--hl-6); } 95 | .hl-7 { color: var(--hl-7); } 96 | .hl-8 { color: var(--hl-8); } 97 | .hl-9 { color: var(--hl-9); } 98 | .hl-10 { color: var(--hl-10); } 99 | pre, code { background: var(--code-background); } 100 | -------------------------------------------------------------------------------- /docs/assets/navigation.js: -------------------------------------------------------------------------------- 1 | window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE8WXXW+bMBhG/wvXXRpQ9tWrTlOnVZrWqJl2sapCBLwEhRhmm2zRtP8+QxuwjflyeR3lKiF+jsGPgfPw12HoD3OunOt1jvFxhhG7RNEG0ZDEGXtFo51z4YTbOIkIws7VQ/X/+cx1Zy4/mAVsy7/v0yhPEL30yxyf5/h1js9z/Lnvur4727J9woftYhw5V54+nI82SOZH5PSFPn3LWGYcz7JBjDsSb2J8j37liLKPKS5/rpjsmI0i6tKUCzl//9Z97f27aMyAZimmaLIpSHF9c1jmSfIjxehzgKMEEXO6EjSSe5exmM96MvxzXt8sVogcXn7qYsogIpkGSQYyafHnmvUzx2F5dUbwygiZ82ahIk5rMAHqFNVAPgrQ2PQeEQ+7Q9zgfI9IwJDROnFIFdC3QrfLw8IUUozty78P8Mb4LMrBfQSWrhiJ8cZ47TnolNHRM0aOy4BQ9Imk+wmAjbTOvtE03CH2IYqIYe/qgEH9EzthylG70YJaVSO+mxVRRopxfc0Rd/HIJZSh6q6WipOlhE3EKaK6KzpBO2WklNnZ0Vt8CJI4kksaJgGlBisphMlQ13snML+mMs6sNk8pvc9PzR40461aNmMX84aQdEJwGde7P6i4Jc1rVOR0VoeFps9TPnLQXeZbmH2JKUPY8NWn4AgZfVduXfxueuUKVhHQsdNjqj0hA5CU1HVveelTtoANeMzmmLJgnSA/ScMg8QNpuxkgNXlD6Bj9ngbLgzTVf5TqX+qyN3oHeGC67MHqsle/clvSZYF4Ll3WTMGiLgv0c+hyOx5elwW2LV1WkdC6LPCgdVlFQemyZ0OXKwikLlcQKF2uANC6XIFs6XINtKbLniVdbnDgdVmHBNdlHRRCl3UcYF3WIe3ocoMMqcsNGLAuN3i2dLkDDKnLDSyILnuWdLnmwOtyzQLW5RpkQZdrmDVdrpFWdVmDHaLLCX9Po6Ok9mkEhC4/J0PpshRvRZdV4hl0uW0KdnRZpVvW5R48qC6rbAu6rEUC6rLKA9RlLQpAlwUOnC7LECBdliEAuiwDAHVZBlnQZQVoQ5cFJKgu6zmgutyKhNTlVujEutzKgdPlViS4LuvJQLqsh8Hpsp5nQZf7wEC6rMdOrcsCBVSXFQ6oLissOF1WQLC6rMBs6LKCtKXLbdh2Xeaf/2EulyDALQAA" -------------------------------------------------------------------------------- /docs/media/example/deno-middleware-http/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /docs/media/example/deno-middleware-http/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/deno-middleware-http 2 | 3 | ## 0.1.0 4 | 5 | ### Minor Changes 6 | 7 | - c536c15: Add new examples for middleware 8 | 9 | ### Patch Changes 10 | 11 | - Updated dependencies [c536c15] 12 | - @bunny.net/edgescript-sdk@0.11.0 13 | -------------------------------------------------------------------------------- /docs/media/example/deno-middleware-http/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/docs/media/example/deno-middleware-http/README.md -------------------------------------------------------------------------------- /docs/media/example/deno-middleware-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/deno-middleware-http", 3 | "version": "0.1.0", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "private": true, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 10 | }, 11 | "keywords": [ 12 | "github", 13 | "bunny" 14 | ], 15 | "author": "Bunny Devs", 16 | "license": "MIT", 17 | "scripts": { 18 | "lint": "deno lint", 19 | "test": "deno test --allow-none", 20 | "build": "echo \"No build with Deno!\"", 21 | "dev": "deno run src/main.ts", 22 | "release": "echo \"No release\"" 23 | }, 24 | "dependencies": { 25 | "@bunny.net/edgescript-sdk": "^0.11.0" 26 | }, 27 | "devDependencies": {} 28 | } 29 | -------------------------------------------------------------------------------- /docs/media/example/deno-middleware-http/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "../../../libs/bunny-sdk/esm/lib.mjs"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { 10 | const req = ctx.request; 11 | console.log(`[INFO]: ${req.method} - ${req.url}`); 12 | await sleep(1); 13 | return ctx.request; 14 | }).onOriginResponse(async (ctx) => { 15 | const res = ctx.response; 16 | console.log(`[INFO]: ${res.status}`); 17 | await sleep(1); 18 | return ctx.response; 19 | }); 20 | -------------------------------------------------------------------------------- /docs/media/example/deno-simple-http-page/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /docs/media/example/deno-simple-http-page/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/deno-simple-http-page 2 | 3 | ## 0.2.21 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [c536c15] 8 | - @bunny.net/edgescript-sdk@0.11.0 9 | 10 | ## 0.2.20 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [3ba61ac] 15 | - Updated dependencies [49b0fa1] 16 | - @bunny.net/edgescript-sdk@0.10.0 17 | 18 | ## 0.2.19 19 | 20 | ### Patch Changes 21 | 22 | - Updated dependencies [ec2d606] 23 | - Updated dependencies [85e8df4] 24 | - @bunny.net/edgescript-sdk@0.9.0 25 | 26 | ## 0.2.18 27 | 28 | ### Patch Changes 29 | 30 | - Updated dependencies [88318ed] 31 | - @bunny.net/edgescript-sdk@0.8.0 32 | 33 | ## 0.2.17 34 | 35 | ### Patch Changes 36 | 37 | - Updated dependencies [9bd6b41] 38 | - @bunny.net/edgescript-sdk@0.7.0 39 | 40 | ## 0.2.16 41 | 42 | ### Patch Changes 43 | 44 | - Updated dependencies [222cc99] 45 | - @bunny.net/edgescript-sdk@0.6.0 46 | 47 | ## 0.2.15 48 | 49 | ### Patch Changes 50 | 51 | - d36ca8e: Added working examples with Node & Deno 52 | -------------------------------------------------------------------------------- /docs/media/example/deno-simple-http-page/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/docs/media/example/deno-simple-http-page/README.md -------------------------------------------------------------------------------- /docs/media/example/deno-simple-http-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/deno-simple-http-page", 3 | "version": "0.2.21", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "private": true, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 10 | }, 11 | "keywords": [ 12 | "github", 13 | "bunny" 14 | ], 15 | "author": "Bunny Devs", 16 | "license": "MIT", 17 | "scripts": { 18 | "lint": "deno lint", 19 | "test": "deno test --allow-none", 20 | "build": "echo \"No build with Deno!\"", 21 | "dev": "deno run src/main.ts", 22 | "release": "echo \"No release\"" 23 | }, 24 | "dependencies": { 25 | "@bunny.net/edgescript-sdk": "^0.11.0" 26 | }, 27 | "devDependencies": {} 28 | } 29 | -------------------------------------------------------------------------------- /docs/media/example/deno-simple-http-page/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | BunnySDK.net.http.serve(async (req) => { 9 | console.log(`[INFO]: ${req.method} - ${req.url}`); 10 | await sleep(1); 11 | return new Response("blbl"); 12 | }); 13 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/middleware-simple-http 2 | 3 | ## 0.1.2 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [54e064e] 8 | - @bunny.net/edgescript-sdk@0.11.2 9 | 10 | ## 0.1.1 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [ea59365] 15 | - @bunny.net/edgescript-sdk@0.11.1 16 | 17 | ## 0.1.0 18 | 19 | ### Minor Changes 20 | 21 | - c536c15: Add new examples for middleware 22 | 23 | ### Patch Changes 24 | 25 | - Updated dependencies [c536c15] 26 | - @bunny.net/edgescript-sdk@0.11.0 27 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/jest.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | transform: { 7 | '^.+\\.ts$': 'ts-jest' 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/middleware-simple-http", 3 | "version": "0.1.2", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "files": [ 7 | "dist" 8 | ], 9 | "private": true, 10 | "scripts": { 11 | "lint": "eslint src", 12 | "test": "jest --silent --coverage", 13 | "dev": "pnpm run build && node dist/index.js", 14 | "build": "ncc build src/main.ts -o dist/", 15 | "release": "echo \"No release\"" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 20 | }, 21 | "keywords": [ 22 | "github", 23 | "bunny" 24 | ], 25 | "author": "Bunny Devs", 26 | "license": "MIT", 27 | "devDependencies": { 28 | "@eslint/js": "^9.8.0", 29 | "@types/jest": "^29.5.12", 30 | "@types/node": "^22.1.0", 31 | "@typescript-eslint/eslint-plugin": "^8.0.1", 32 | "@typescript-eslint/parser": "^8.0.1", 33 | "@vercel/ncc": "^0.38.1", 34 | "esbuild": "0.23.0", 35 | "eslint": "^9.8.0", 36 | "globals": "^15.9.0", 37 | "jest": "^29.5.12", 38 | "prettier": "^3.3.3", 39 | "ts-jest": "^29.2.4", 40 | "typescript": "^5.5.4", 41 | "typescript-eslint": "^8.0.1" 42 | }, 43 | "dependencies": { 44 | "@bunny.net/edgescript-sdk": "workspace:*" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { 10 | const req = ctx.request; 11 | console.log(`[INFO]: ${req.method} - ${req.url}`); 12 | await sleep(1); 13 | return ctx.request; 14 | }).onOriginResponse(async (ctx) => { 15 | const res = ctx.response; 16 | console.log(`[INFO]: ${res.status}`); 17 | await sleep(1); 18 | return ctx.response; 19 | }); 20 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/tests/empty.test.ts: -------------------------------------------------------------------------------- 1 | // import { jest } from '@jest/globals'; 2 | 3 | describe('empty', () => { 4 | test('empty test', async () => { 5 | expect(true).toBe(true); 6 | }); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /docs/media/example/middleware-simple-http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext" 7 | ], 8 | "outDir": "./dist", 9 | "rootDir": "./src", 10 | "strict": true, 11 | "allowSyntheticDefaultImports": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "downlevelIteration": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "suppressExcessPropertyErrors": false, 17 | "declaration": true, 18 | "sourceMap": false, 19 | "noImplicitAny": false, 20 | "noEmitOnError": false, 21 | "esModuleInterop": true, 22 | "skipLibCheck": true 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "**/*.test.*" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/simple-http-page 2 | 3 | ## 0.2.29 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [54e064e] 8 | - @bunny.net/edgescript-sdk@0.11.2 9 | 10 | ## 0.2.28 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [ea59365] 15 | - @bunny.net/edgescript-sdk@0.11.1 16 | 17 | ## 0.2.27 18 | 19 | ### Patch Changes 20 | 21 | - Updated dependencies [c536c15] 22 | - @bunny.net/edgescript-sdk@0.11.0 23 | 24 | ## 0.2.26 25 | 26 | ### Patch Changes 27 | 28 | - Updated dependencies [3ba61ac] 29 | - Updated dependencies [49b0fa1] 30 | - @bunny.net/edgescript-sdk@0.10.0 31 | 32 | ## 0.2.25 33 | 34 | ### Patch Changes 35 | 36 | - Updated dependencies [555a50f] 37 | - @bunny.net/edgescript-sdk@0.9.3 38 | 39 | ## 0.2.24 40 | 41 | ### Patch Changes 42 | 43 | - Updated dependencies [96c00b7] 44 | - @bunny.net/edgescript-sdk@0.9.2 45 | 46 | ## 0.2.23 47 | 48 | ### Patch Changes 49 | 50 | - Updated dependencies [7d99bc7] 51 | - @bunny.net/edgescript-sdk@0.9.1 52 | 53 | ## 0.2.22 54 | 55 | ### Patch Changes 56 | 57 | - Updated dependencies [ec2d606] 58 | - Updated dependencies [85e8df4] 59 | - @bunny.net/edgescript-sdk@0.9.0 60 | 61 | ## 0.2.21 62 | 63 | ### Patch Changes 64 | 65 | - Updated dependencies [0698b9b] 66 | - @bunny.net/edgescript-sdk@0.8.1 67 | 68 | ## 0.2.20 69 | 70 | ### Patch Changes 71 | 72 | - Updated dependencies [88318ed] 73 | - @bunny.net/edgescript-sdk@0.8.0 74 | 75 | ## 0.2.19 76 | 77 | ### Patch Changes 78 | 79 | - Updated dependencies [2bcc604] 80 | - @bunny.net/edgescript-sdk@0.7.1 81 | 82 | ## 0.2.18 83 | 84 | ### Patch Changes 85 | 86 | - Updated dependencies [9bd6b41] 87 | - @bunny.net/edgescript-sdk@0.7.0 88 | 89 | ## 0.2.17 90 | 91 | ### Patch Changes 92 | 93 | - Updated dependencies [222cc99] 94 | - @bunny.net/edgescript-sdk@0.6.0 95 | 96 | ## 0.2.16 97 | 98 | ### Patch Changes 99 | 100 | - Updated dependencies [e8486ec] 101 | - @bunny.net/edgescript-sdk@0.5.13 102 | 103 | ## 0.2.15 104 | 105 | ### Patch Changes 106 | 107 | - d36ca8e: Added working examples with Node & Deno 108 | 109 | ## 0.2.14 110 | 111 | ### Patch Changes 112 | 113 | - Updated dependencies [b37f85f] 114 | - @bunny.net/edgescript-sdk@0.5.12 115 | 116 | ## 0.2.13 117 | 118 | ### Patch Changes 119 | 120 | - Updated dependencies [8ae9f95] 121 | - @bunny.net/edgescript-sdk@0.5.11 122 | 123 | ## 0.2.12 124 | 125 | ### Patch Changes 126 | 127 | - Updated dependencies [084f151] 128 | - @bunny.net/edgescript-sdk@0.5.10 129 | 130 | ## 0.2.11 131 | 132 | ### Patch Changes 133 | 134 | - Updated dependencies [e66661c] 135 | - @bunny.net/edgescript-sdk@0.5.9 136 | 137 | ## 0.2.10 138 | 139 | ### Patch Changes 140 | 141 | - Updated dependencies [677b80c] 142 | - @bunny.net/edgescript-sdk@0.5.8 143 | 144 | ## 0.2.9 145 | 146 | ### Patch Changes 147 | 148 | - Updated dependencies [25750a3] 149 | - @bunny.net/edgescript-sdk@0.5.7 150 | 151 | ## 0.2.8 152 | 153 | ### Patch Changes 154 | 155 | - Updated dependencies [1d5d4fa] 156 | - @bunny.net/edgescript-sdk@0.5.6 157 | 158 | ## 0.2.7 159 | 160 | ### Patch Changes 161 | 162 | - Updated dependencies [50d5e51] 163 | - @bunny.net/edgescript-sdk@0.5.5 164 | 165 | ## 0.2.6 166 | 167 | ### Patch Changes 168 | 169 | - Updated dependencies [6541554] 170 | - @bunny.net/edgescript-sdk@0.5.4 171 | 172 | ## 0.2.5 173 | 174 | ### Patch Changes 175 | 176 | - Updated dependencies [043c52e] 177 | - @bunny.net/edgescript-sdk@0.5.3 178 | 179 | ## 0.2.4 180 | 181 | ### Patch Changes 182 | 183 | - Updated dependencies [15cdbf3] 184 | - @bunny.net/edgescript-sdk@0.5.2 185 | 186 | ## 0.2.3 187 | 188 | ### Patch Changes 189 | 190 | - Updated dependencies [911191c] 191 | - @bunny.net/edgescript-sdk@0.5.1 192 | 193 | ## 0.2.2 194 | 195 | ### Patch Changes 196 | 197 | - Updated dependencies [a9ff289] 198 | - @bunny.net/edgescript-sdk@0.5.0 199 | 200 | ## 0.2.1 201 | 202 | ### Patch Changes 203 | 204 | - Updated dependencies [644a745] 205 | - @bunny.net/edgescript-sdk@0.4.0 206 | 207 | ## 0.2.0 208 | 209 | ### Minor Changes 210 | 211 | - 5205a40: Add examples 212 | 213 | ### Patch Changes 214 | 215 | - Updated dependencies [5205a40] 216 | - @bunny.net/edgescript-sdk@0.3.0 217 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/docs/media/example/simple-http-page/README.md -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/jest.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | transform: { 7 | '^.+\\.ts$': 'ts-jest' 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/simple-http-page", 3 | "version": "0.2.29", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "files": [ 7 | "dist" 8 | ], 9 | "private": true, 10 | "scripts": { 11 | "lint": "eslint src", 12 | "test": "jest --silent --coverage", 13 | "dev": "pnpm run build && node dist/index.js", 14 | "build": "ncc build src/main.ts -o dist/", 15 | "release": "echo \"No release\"" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 20 | }, 21 | "keywords": [ 22 | "github", 23 | "bunny" 24 | ], 25 | "author": "Bunny Devs", 26 | "license": "MIT", 27 | "devDependencies": { 28 | "@eslint/js": "^9.8.0", 29 | "@types/jest": "^29.5.12", 30 | "@types/node": "^22.1.0", 31 | "@typescript-eslint/eslint-plugin": "^8.0.1", 32 | "@typescript-eslint/parser": "^8.0.1", 33 | "@vercel/ncc": "^0.38.1", 34 | "esbuild": "0.23.0", 35 | "eslint": "^9.8.0", 36 | "globals": "^15.9.0", 37 | "jest": "^29.5.12", 38 | "prettier": "^3.3.3", 39 | "ts-jest": "^29.2.4", 40 | "typescript": "^5.5.4", 41 | "typescript-eslint": "^8.0.1" 42 | }, 43 | "dependencies": { 44 | "@bunny.net/edgescript-sdk": "workspace:*" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.serve(async (req) => { 10 | console.log(`[INFO]: ${req.method} - ${req.url}`); 11 | await sleep(1); 12 | return new Response("blbl"); 13 | }); 14 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/tests/empty.test.ts: -------------------------------------------------------------------------------- 1 | // import { jest } from '@jest/globals'; 2 | 3 | describe('empty', () => { 4 | test('empty test', async () => { 5 | expect(true).toBe(true); 6 | }); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /docs/media/example/simple-http-page/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext" 7 | ], 8 | "outDir": "./dist", 9 | "rootDir": "./src", 10 | "strict": true, 11 | "allowSyntheticDefaultImports": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "downlevelIteration": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "suppressExcessPropertyErrors": false, 17 | "declaration": true, 18 | "sourceMap": false, 19 | "noImplicitAny": false, 20 | "noEmitOnError": false, 21 | "esModuleInterop": true, 22 | "skipLibCheck": true 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "**/*.test.*" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /docs/modules/_bunny_net_edgescript_sdk_0_11_1.html: -------------------------------------------------------------------------------- 1 | @bunny.net/edgescript-sdk/0.11.1 - v0.11.1 | Edge Script SDK Documentation

Module @bunny.net/edgescript-sdk/0.11.1 - v0.11.1

@bunny.net/edge-script-sdk


2 |

The @bunny.net/edge-script-sdk

3 |

Index

Namespaces

net 4 |
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.http.OriginRequestContext.html: -------------------------------------------------------------------------------- 1 | OriginRequestContext | Edge Script SDK Documentation
OriginRequestContext: {
    request: Request;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.http.OriginResponseContext.html: -------------------------------------------------------------------------------- 1 | OriginResponseContext | Edge Script SDK Documentation
OriginResponseContext: {
    request: Request;
    response: Response;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.http.PullZoneHandlerOptions.html: -------------------------------------------------------------------------------- 1 | PullZoneHandlerOptions | Edge Script SDK Documentation
PullZoneHandlerOptions: {
    url: string;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.http.ServeHandler.html: -------------------------------------------------------------------------------- 1 | ServeHandler | Edge Script SDK Documentation
ServeHandler: {} & unknown
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.http.ServerHandler.html: -------------------------------------------------------------------------------- 1 | ServerHandler | Edge Script SDK Documentation
ServerHandler: ((request: Request) => Response | Promise<Response>)

A handler for HTTP Requests. 2 | Consumes a request and return a response.

3 |
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.socketAddr.NoAddr.html: -------------------------------------------------------------------------------- 1 | NoAddr | Edge Script SDK Documentation
NoAddr: {
    _tag: "NoAddr";
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_1.net.socketAddr.SocketAddrError.html: -------------------------------------------------------------------------------- 1 | SocketAddrError | Edge Script SDK Documentation
SocketAddrError: net.socketAddr.InvalidAddr
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.http.OriginRequestContext.html: -------------------------------------------------------------------------------- 1 | OriginRequestContext | Edge Script SDK Documentation
OriginRequestContext: {
    request: Request;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.http.OriginResponseContext.html: -------------------------------------------------------------------------------- 1 | OriginResponseContext | Edge Script SDK Documentation
OriginResponseContext: {
    request: Request;
    response: Response;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.http.PullZoneHandlerOptions.html: -------------------------------------------------------------------------------- 1 | PullZoneHandlerOptions | Edge Script SDK Documentation
PullZoneHandlerOptions: {
    url: string;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.http.ServeHandler.html: -------------------------------------------------------------------------------- 1 | ServeHandler | Edge Script SDK Documentation
ServeHandler: {} & unknown
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.socketAddr.NoAddr.html: -------------------------------------------------------------------------------- 1 | NoAddr | Edge Script SDK Documentation
NoAddr: {
    _tag: "NoAddr";
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_0_11_2.net.socketAddr.SocketAddrError.html: -------------------------------------------------------------------------------- 1 | SocketAddrError | Edge Script SDK Documentation
SocketAddrError: net.socketAddr.InvalidAddr
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.http.OriginRequestContext.html: -------------------------------------------------------------------------------- 1 | OriginRequestContext | Edge Script SDK Documentation
OriginRequestContext: {
    request: Request;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.http.OriginResponseContext.html: -------------------------------------------------------------------------------- 1 | OriginResponseContext | Edge Script SDK Documentation
OriginResponseContext: {
    request: Request;
    response: Response;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.http.PullZoneHandlerOptions.html: -------------------------------------------------------------------------------- 1 | PullZoneHandlerOptions | Edge Script SDK Documentation
PullZoneHandlerOptions: {
    url: string;
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.http.ServeHandler.html: -------------------------------------------------------------------------------- 1 | ServeHandler | Edge Script SDK Documentation
ServeHandler: {} & unknown
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.socketAddr.NoAddr.html: -------------------------------------------------------------------------------- 1 | NoAddr | Edge Script SDK Documentation
NoAddr: {
    _tag: "NoAddr";
}
-------------------------------------------------------------------------------- /docs/types/_bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddrError.html: -------------------------------------------------------------------------------- 1 | SocketAddrError | Edge Script SDK Documentation
SocketAddrError: net.socketAddr.InvalidAddr
-------------------------------------------------------------------------------- /example/deno-middleware-http/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /example/deno-middleware-http/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/deno-middleware-http 2 | 3 | ## 0.1.1 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [6199c9e] 8 | - @bunny.net/edgescript-sdk@0.12.0 9 | 10 | ## 0.1.0 11 | 12 | ### Minor Changes 13 | 14 | - c536c15: Add new examples for middleware 15 | 16 | ### Patch Changes 17 | 18 | - Updated dependencies [c536c15] 19 | - @bunny.net/edgescript-sdk@0.11.0 20 | -------------------------------------------------------------------------------- /example/deno-middleware-http/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/example/deno-middleware-http/README.md -------------------------------------------------------------------------------- /example/deno-middleware-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/deno-middleware-http", 3 | "version": "0.1.1", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "private": true, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 10 | }, 11 | "keywords": [ 12 | "github", 13 | "bunny" 14 | ], 15 | "author": "Bunny Devs", 16 | "license": "MIT", 17 | "scripts": { 18 | "lint": "deno lint", 19 | "test": "deno test --permit-no-files", 20 | "build": "echo \"No build with Deno!\"", 21 | "dev": "deno run src/main.ts", 22 | "release": "echo \"No release\"" 23 | }, 24 | "dependencies": { 25 | "@bunny.net/edgescript-sdk": "^0.12.0" 26 | }, 27 | "devDependencies": {} 28 | } 29 | -------------------------------------------------------------------------------- /example/deno-middleware-http/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "../../../libs/bunny-sdk/esm/lib.mjs"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { 10 | const req = ctx.request; 11 | console.log(`[INFO]: ${req.method} - ${req.url}`); 12 | await sleep(1); 13 | return ctx.request; 14 | }).onOriginResponse(async (ctx) => { 15 | const res = ctx.response; 16 | console.log(`[INFO]: ${res.status}`); 17 | await sleep(1); 18 | return ctx.response; 19 | }); 20 | -------------------------------------------------------------------------------- /example/deno-simple-http-page/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /example/deno-simple-http-page/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/deno-simple-http-page 2 | 3 | ## 0.2.22 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [6199c9e] 8 | - @bunny.net/edgescript-sdk@0.12.0 9 | 10 | ## 0.2.21 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [c536c15] 15 | - @bunny.net/edgescript-sdk@0.11.0 16 | 17 | ## 0.2.20 18 | 19 | ### Patch Changes 20 | 21 | - Updated dependencies [3ba61ac] 22 | - Updated dependencies [49b0fa1] 23 | - @bunny.net/edgescript-sdk@0.10.0 24 | 25 | ## 0.2.19 26 | 27 | ### Patch Changes 28 | 29 | - Updated dependencies [ec2d606] 30 | - Updated dependencies [85e8df4] 31 | - @bunny.net/edgescript-sdk@0.9.0 32 | 33 | ## 0.2.18 34 | 35 | ### Patch Changes 36 | 37 | - Updated dependencies [88318ed] 38 | - @bunny.net/edgescript-sdk@0.8.0 39 | 40 | ## 0.2.17 41 | 42 | ### Patch Changes 43 | 44 | - Updated dependencies [9bd6b41] 45 | - @bunny.net/edgescript-sdk@0.7.0 46 | 47 | ## 0.2.16 48 | 49 | ### Patch Changes 50 | 51 | - Updated dependencies [222cc99] 52 | - @bunny.net/edgescript-sdk@0.6.0 53 | 54 | ## 0.2.15 55 | 56 | ### Patch Changes 57 | 58 | - d36ca8e: Added working examples with Node & Deno 59 | -------------------------------------------------------------------------------- /example/deno-simple-http-page/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/example/deno-simple-http-page/README.md -------------------------------------------------------------------------------- /example/deno-simple-http-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/deno-simple-http-page", 3 | "version": "0.2.22", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "private": true, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 10 | }, 11 | "keywords": [ 12 | "github", 13 | "bunny" 14 | ], 15 | "author": "Bunny Devs", 16 | "license": "MIT", 17 | "scripts": { 18 | "lint": "deno lint", 19 | "test": "deno test --permit-no-files", 20 | "build": "echo \"No build with Deno!\"", 21 | "dev": "deno run src/main.ts", 22 | "release": "echo \"No release\"" 23 | }, 24 | "dependencies": { 25 | "@bunny.net/edgescript-sdk": "^0.12.0" 26 | }, 27 | "devDependencies": {} 28 | } 29 | -------------------------------------------------------------------------------- /example/deno-simple-http-page/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | BunnySDK.net.http.serve(async (req) => { 9 | console.log(`[INFO]: ${req.method} - ${req.url}`); 10 | await sleep(1); 11 | return new Response("blbl"); 12 | }); 13 | -------------------------------------------------------------------------------- /example/middleware-simple-http/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /example/middleware-simple-http/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/middleware-simple-http 2 | 3 | ## 0.1.6 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [6199c9e] 8 | - @bunny.net/edgescript-sdk@0.12.0 9 | 10 | ## 0.1.5 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [05edf67] 15 | - @bunny.net/edgescript-sdk@0.11.5 16 | 17 | ## 0.1.4 18 | 19 | ### Patch Changes 20 | 21 | - Updated dependencies [7a5f7b8] 22 | - @bunny.net/edgescript-sdk@0.11.4 23 | 24 | ## 0.1.3 25 | 26 | ### Patch Changes 27 | 28 | - Updated dependencies [43738c5] 29 | - @bunny.net/edgescript-sdk@0.11.3 30 | 31 | ## 0.1.2 32 | 33 | ### Patch Changes 34 | 35 | - Updated dependencies [54e064e] 36 | - @bunny.net/edgescript-sdk@0.11.2 37 | 38 | ## 0.1.1 39 | 40 | ### Patch Changes 41 | 42 | - Updated dependencies [ea59365] 43 | - @bunny.net/edgescript-sdk@0.11.1 44 | 45 | ## 0.1.0 46 | 47 | ### Minor Changes 48 | 49 | - c536c15: Add new examples for middleware 50 | 51 | ### Patch Changes 52 | 53 | - Updated dependencies [c536c15] 54 | - @bunny.net/edgescript-sdk@0.11.0 55 | -------------------------------------------------------------------------------- /example/middleware-simple-http/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /example/middleware-simple-http/jest.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | transform: { 7 | '^.+\\.ts$': 'ts-jest' 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /example/middleware-simple-http/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/middleware-simple-http", 3 | "version": "0.1.6", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "files": [ 7 | "dist" 8 | ], 9 | "private": true, 10 | "scripts": { 11 | "lint": "eslint src", 12 | "test": "jest --silent --coverage", 13 | "dev": "pnpm run build && node dist/index.js", 14 | "build": "ncc build src/main.ts -o dist/", 15 | "release": "echo \"No release\"" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 20 | }, 21 | "keywords": [ 22 | "github", 23 | "bunny" 24 | ], 25 | "author": "Bunny Devs", 26 | "license": "MIT", 27 | "devDependencies": { 28 | "@eslint/js": "^9.8.0", 29 | "@types/jest": "^29.5.12", 30 | "@types/node": "^22.1.0", 31 | "@typescript-eslint/eslint-plugin": "^8.0.1", 32 | "@typescript-eslint/parser": "^8.0.1", 33 | "@vercel/ncc": "^0.38.1", 34 | "esbuild": "0.23.0", 35 | "eslint": "^9.8.0", 36 | "globals": "^15.9.0", 37 | "jest": "^29.5.12", 38 | "prettier": "^3.3.3", 39 | "ts-jest": "^29.2.4", 40 | "typescript": "^5.5.4", 41 | "typescript-eslint": "^8.0.1" 42 | }, 43 | "dependencies": { 44 | "@bunny.net/edgescript-sdk": "workspace:*" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/middleware-simple-http/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { 10 | const req = ctx.request; 11 | console.log(`[INFO]: ${req.method} - ${req.url}`); 12 | await sleep(1); 13 | return ctx.request; 14 | }).onOriginResponse(async (ctx) => { 15 | const res = ctx.response; 16 | console.log(`[INFO]: ${res.status}`); 17 | await sleep(1); 18 | return ctx.response; 19 | }); 20 | -------------------------------------------------------------------------------- /example/middleware-simple-http/tests/empty.test.ts: -------------------------------------------------------------------------------- 1 | // import { jest } from '@jest/globals'; 2 | 3 | describe('empty', () => { 4 | test('empty test', async () => { 5 | expect(true).toBe(true); 6 | }); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /example/middleware-simple-http/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext" 7 | ], 8 | "outDir": "./dist", 9 | "rootDir": "./src", 10 | "strict": true, 11 | "allowSyntheticDefaultImports": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "downlevelIteration": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "suppressExcessPropertyErrors": false, 17 | "declaration": true, 18 | "sourceMap": false, 19 | "noImplicitAny": false, 20 | "noEmitOnError": false, 21 | "esModuleInterop": true, 22 | "skipLibCheck": true 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "**/*.test.*" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /example/simple-http-page/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-bunny/ 17 | 18 | # production 19 | /build 20 | 21 | # misc 22 | .DS_Store 23 | *.pem 24 | 25 | # debug 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | 30 | .vscode 31 | 32 | # local env files 33 | .env*.local 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | -------------------------------------------------------------------------------- /example/simple-http-page/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # example/simple-http-page 2 | 3 | ## 0.2.33 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [6199c9e] 8 | - @bunny.net/edgescript-sdk@0.12.0 9 | 10 | ## 0.2.32 11 | 12 | ### Patch Changes 13 | 14 | - Updated dependencies [05edf67] 15 | - @bunny.net/edgescript-sdk@0.11.5 16 | 17 | ## 0.2.31 18 | 19 | ### Patch Changes 20 | 21 | - Updated dependencies [7a5f7b8] 22 | - @bunny.net/edgescript-sdk@0.11.4 23 | 24 | ## 0.2.30 25 | 26 | ### Patch Changes 27 | 28 | - Updated dependencies [43738c5] 29 | - @bunny.net/edgescript-sdk@0.11.3 30 | 31 | ## 0.2.29 32 | 33 | ### Patch Changes 34 | 35 | - Updated dependencies [54e064e] 36 | - @bunny.net/edgescript-sdk@0.11.2 37 | 38 | ## 0.2.28 39 | 40 | ### Patch Changes 41 | 42 | - Updated dependencies [ea59365] 43 | - @bunny.net/edgescript-sdk@0.11.1 44 | 45 | ## 0.2.27 46 | 47 | ### Patch Changes 48 | 49 | - Updated dependencies [c536c15] 50 | - @bunny.net/edgescript-sdk@0.11.0 51 | 52 | ## 0.2.26 53 | 54 | ### Patch Changes 55 | 56 | - Updated dependencies [3ba61ac] 57 | - Updated dependencies [49b0fa1] 58 | - @bunny.net/edgescript-sdk@0.10.0 59 | 60 | ## 0.2.25 61 | 62 | ### Patch Changes 63 | 64 | - Updated dependencies [555a50f] 65 | - @bunny.net/edgescript-sdk@0.9.3 66 | 67 | ## 0.2.24 68 | 69 | ### Patch Changes 70 | 71 | - Updated dependencies [96c00b7] 72 | - @bunny.net/edgescript-sdk@0.9.2 73 | 74 | ## 0.2.23 75 | 76 | ### Patch Changes 77 | 78 | - Updated dependencies [7d99bc7] 79 | - @bunny.net/edgescript-sdk@0.9.1 80 | 81 | ## 0.2.22 82 | 83 | ### Patch Changes 84 | 85 | - Updated dependencies [ec2d606] 86 | - Updated dependencies [85e8df4] 87 | - @bunny.net/edgescript-sdk@0.9.0 88 | 89 | ## 0.2.21 90 | 91 | ### Patch Changes 92 | 93 | - Updated dependencies [0698b9b] 94 | - @bunny.net/edgescript-sdk@0.8.1 95 | 96 | ## 0.2.20 97 | 98 | ### Patch Changes 99 | 100 | - Updated dependencies [88318ed] 101 | - @bunny.net/edgescript-sdk@0.8.0 102 | 103 | ## 0.2.19 104 | 105 | ### Patch Changes 106 | 107 | - Updated dependencies [2bcc604] 108 | - @bunny.net/edgescript-sdk@0.7.1 109 | 110 | ## 0.2.18 111 | 112 | ### Patch Changes 113 | 114 | - Updated dependencies [9bd6b41] 115 | - @bunny.net/edgescript-sdk@0.7.0 116 | 117 | ## 0.2.17 118 | 119 | ### Patch Changes 120 | 121 | - Updated dependencies [222cc99] 122 | - @bunny.net/edgescript-sdk@0.6.0 123 | 124 | ## 0.2.16 125 | 126 | ### Patch Changes 127 | 128 | - Updated dependencies [e8486ec] 129 | - @bunny.net/edgescript-sdk@0.5.13 130 | 131 | ## 0.2.15 132 | 133 | ### Patch Changes 134 | 135 | - d36ca8e: Added working examples with Node & Deno 136 | 137 | ## 0.2.14 138 | 139 | ### Patch Changes 140 | 141 | - Updated dependencies [b37f85f] 142 | - @bunny.net/edgescript-sdk@0.5.12 143 | 144 | ## 0.2.13 145 | 146 | ### Patch Changes 147 | 148 | - Updated dependencies [8ae9f95] 149 | - @bunny.net/edgescript-sdk@0.5.11 150 | 151 | ## 0.2.12 152 | 153 | ### Patch Changes 154 | 155 | - Updated dependencies [084f151] 156 | - @bunny.net/edgescript-sdk@0.5.10 157 | 158 | ## 0.2.11 159 | 160 | ### Patch Changes 161 | 162 | - Updated dependencies [e66661c] 163 | - @bunny.net/edgescript-sdk@0.5.9 164 | 165 | ## 0.2.10 166 | 167 | ### Patch Changes 168 | 169 | - Updated dependencies [677b80c] 170 | - @bunny.net/edgescript-sdk@0.5.8 171 | 172 | ## 0.2.9 173 | 174 | ### Patch Changes 175 | 176 | - Updated dependencies [25750a3] 177 | - @bunny.net/edgescript-sdk@0.5.7 178 | 179 | ## 0.2.8 180 | 181 | ### Patch Changes 182 | 183 | - Updated dependencies [1d5d4fa] 184 | - @bunny.net/edgescript-sdk@0.5.6 185 | 186 | ## 0.2.7 187 | 188 | ### Patch Changes 189 | 190 | - Updated dependencies [50d5e51] 191 | - @bunny.net/edgescript-sdk@0.5.5 192 | 193 | ## 0.2.6 194 | 195 | ### Patch Changes 196 | 197 | - Updated dependencies [6541554] 198 | - @bunny.net/edgescript-sdk@0.5.4 199 | 200 | ## 0.2.5 201 | 202 | ### Patch Changes 203 | 204 | - Updated dependencies [043c52e] 205 | - @bunny.net/edgescript-sdk@0.5.3 206 | 207 | ## 0.2.4 208 | 209 | ### Patch Changes 210 | 211 | - Updated dependencies [15cdbf3] 212 | - @bunny.net/edgescript-sdk@0.5.2 213 | 214 | ## 0.2.3 215 | 216 | ### Patch Changes 217 | 218 | - Updated dependencies [911191c] 219 | - @bunny.net/edgescript-sdk@0.5.1 220 | 221 | ## 0.2.2 222 | 223 | ### Patch Changes 224 | 225 | - Updated dependencies [a9ff289] 226 | - @bunny.net/edgescript-sdk@0.5.0 227 | 228 | ## 0.2.1 229 | 230 | ### Patch Changes 231 | 232 | - Updated dependencies [644a745] 233 | - @bunny.net/edgescript-sdk@0.4.0 234 | 235 | ## 0.2.0 236 | 237 | ### Minor Changes 238 | 239 | - 5205a40: Add examples 240 | 241 | ### Patch Changes 242 | 243 | - Updated dependencies [5205a40] 244 | - @bunny.net/edgescript-sdk@0.3.0 245 | -------------------------------------------------------------------------------- /example/simple-http-page/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BunnyWay/edge-script-sdk/863746676d770e2abde540616610202ed77615a5/example/simple-http-page/README.md -------------------------------------------------------------------------------- /example/simple-http-page/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /example/simple-http-page/jest.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | transform: { 7 | '^.+\\.ts$': 'ts-jest' 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /example/simple-http-page/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example/simple-http-page", 3 | "version": "0.2.33", 4 | "main": "src/index.ts", 5 | "type": "module", 6 | "files": [ 7 | "dist" 8 | ], 9 | "private": true, 10 | "scripts": { 11 | "lint": "eslint src", 12 | "test": "jest --silent --coverage", 13 | "dev": "pnpm run build && node dist/index.js", 14 | "build": "ncc build src/main.ts -o dist/", 15 | "release": "echo \"No release\"" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 20 | }, 21 | "keywords": [ 22 | "github", 23 | "bunny" 24 | ], 25 | "author": "Bunny Devs", 26 | "license": "MIT", 27 | "devDependencies": { 28 | "@eslint/js": "^9.8.0", 29 | "@types/jest": "^29.5.12", 30 | "@types/node": "^22.1.0", 31 | "@typescript-eslint/eslint-plugin": "^8.0.1", 32 | "@typescript-eslint/parser": "^8.0.1", 33 | "@vercel/ncc": "^0.38.1", 34 | "esbuild": "0.23.0", 35 | "eslint": "^9.8.0", 36 | "globals": "^15.9.0", 37 | "jest": "^29.5.12", 38 | "prettier": "^3.3.3", 39 | "ts-jest": "^29.2.4", 40 | "typescript": "^5.5.4", 41 | "typescript-eslint": "^8.0.1" 42 | }, 43 | "dependencies": { 44 | "@bunny.net/edgescript-sdk": "workspace:*" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/simple-http-page/src/main.ts: -------------------------------------------------------------------------------- 1 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 2 | 3 | function sleep(ms: number): Promise { 4 | return new Promise((resolve) => setTimeout(resolve, ms)); 5 | } 6 | 7 | console.log("Starting server..."); 8 | 9 | BunnySDK.net.http.serve(async (req) => { 10 | console.log(`[INFO]: ${req.method} - ${req.url}`); 11 | await sleep(1); 12 | return new Response("blbl"); 13 | }); 14 | -------------------------------------------------------------------------------- /example/simple-http-page/tests/empty.test.ts: -------------------------------------------------------------------------------- 1 | // import { jest } from '@jest/globals'; 2 | 3 | describe('empty', () => { 4 | test('empty test', async () => { 5 | expect(true).toBe(true); 6 | }); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /example/simple-http-page/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext" 7 | ], 8 | "outDir": "./dist", 9 | "rootDir": "./src", 10 | "strict": true, 11 | "allowSyntheticDefaultImports": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "downlevelIteration": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "suppressExcessPropertyErrors": false, 17 | "declaration": true, 18 | "sourceMap": false, 19 | "noImplicitAny": false, 20 | "noEmitOnError": false, 21 | "esModuleInterop": true, 22 | "skipLibCheck": true 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "**/*.test.*" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /libs/bunny-sdk/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-node/ 17 | /esm-bunny/ 18 | 19 | # production 20 | /build 21 | 22 | # misc 23 | .DS_Store 24 | *.pem 25 | 26 | # debug 27 | npm-debug.log* 28 | yarn-debug.log* 29 | yarn-error.log* 30 | 31 | .vscode 32 | 33 | # local env files 34 | .env*.local 35 | 36 | # vercel 37 | .vercel 38 | 39 | # typescript 40 | *.tsbuildinfo 41 | next-env.d.ts 42 | -------------------------------------------------------------------------------- /libs/bunny-sdk/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @bunny.net/edgescript-sdk 2 | 3 | ## 0.12.0 4 | 5 | ### Minor Changes 6 | 7 | - 6199c9e: Properly export ESM for Node & Deno 8 | 9 | ## 0.11.5 10 | 11 | ### Patch Changes 12 | 13 | - 05edf67: Update README.md 14 | 15 | ## 0.11.4 16 | 17 | ### Patch Changes 18 | 19 | - 7a5f7b8: Update the export of the package to have a conditional export for Deno 20 | 21 | ## 0.11.3 22 | 23 | ### Patch Changes 24 | 25 | - 43738c5: Ensure we can access subpath when in local 26 | 27 | ## 0.11.2 28 | 29 | ### Patch Changes 30 | 31 | - 54e064e: Ensure proper property passing for middleware url 32 | 33 | ## 0.11.1 34 | 35 | ### Patch Changes 36 | 37 | - ea59365: Fix issue while passing header in local mode" 38 | 39 | ## 0.11.0 40 | 41 | ### Minor Changes 42 | 43 | - c536c15: Add middleware for local development 44 | 45 | ## 0.10.0 46 | 47 | ### Minor Changes 48 | 49 | - 3ba61ac: New overloading for serve to avoid putting listener 50 | - 49b0fa1: serve function should have the handler as first arg 51 | 52 | ## 0.9.3 53 | 54 | ### Patch Changes 55 | 56 | - 555a50f: Remove process replace 57 | 58 | ## 0.9.2 59 | 60 | ### Patch Changes 61 | 62 | - 96c00b7: Try to remove the process dep 63 | 64 | ## 0.9.1 65 | 66 | ### Patch Changes 67 | 68 | - 7d99bc7: Fix build 69 | 70 | ## 0.9.0 71 | 72 | ### Minor Changes 73 | 74 | - ec2d606: Consider the fact we can have a TcpListener with no associated Addr 75 | - 85e8df4: Add a proper addr handling" 76 | 77 | ## 0.8.1 78 | 79 | ### Patch Changes 80 | 81 | - 0698b9b: Change IP separator from ',' to '.' when printing 82 | 83 | ## 0.8.0 84 | 85 | ### Minor Changes 86 | 87 | - 88318ed: Add a toString method to TCP Listener 88 | 89 | ## 0.7.1 90 | 91 | ### Patch Changes 92 | 93 | - 2bcc604: Bump 94 | 95 | ## 0.7.0 96 | 97 | ### Minor Changes 98 | 99 | - 9bd6b41: Bump 100 | 101 | ## 0.6.0 102 | 103 | ### Minor Changes 104 | 105 | - 222cc99: Bump 106 | 107 | ## 0.5.13 108 | 109 | ### Patch Changes 110 | 111 | - e8486ec: Bump publish 112 | 113 | ## 0.5.12 114 | 115 | ### Patch Changes 116 | 117 | - b37f85f: Bump 118 | 119 | ## 0.5.11 120 | 121 | ### Patch Changes 122 | 123 | - 8ae9f95: Bump 124 | 125 | ## 0.5.10 126 | 127 | ### Patch Changes 128 | 129 | - 084f151: bump 130 | 131 | ## 0.5.9 132 | 133 | ### Patch Changes 134 | 135 | - e66661c: bump 136 | 137 | ## 0.5.8 138 | 139 | ### Patch Changes 140 | 141 | - 677b80c: last bump 142 | 143 | ## 0.5.7 144 | 145 | ### Patch Changes 146 | 147 | - 25750a3: bump 148 | 149 | ## 0.5.6 150 | 151 | ### Patch Changes 152 | 153 | - 1d5d4fa: bump 154 | 155 | ## 0.5.5 156 | 157 | ### Patch Changes 158 | 159 | - 50d5e51: bump 160 | 161 | ## 0.5.4 162 | 163 | ### Patch Changes 164 | 165 | - 6541554: bump 166 | 167 | ## 0.5.3 168 | 169 | ### Patch Changes 170 | 171 | - 043c52e: bump 172 | 173 | ## 0.5.2 174 | 175 | ### Patch Changes 176 | 177 | - 15cdbf3: Bump 178 | 179 | ## 0.5.1 180 | 181 | ### Patch Changes 182 | 183 | - 911191c: Bump 184 | 185 | ## 0.5.0 186 | 187 | ### Minor Changes 188 | 189 | - a9ff289: Test bump 190 | 191 | ## 0.4.0 192 | 193 | ### Minor Changes 194 | 195 | - 644a745: First bump 196 | 197 | ## 0.3.0 198 | 199 | ### Minor Changes 200 | 201 | - 5205a40: Add examples 202 | -------------------------------------------------------------------------------- /libs/bunny-sdk/README.md: -------------------------------------------------------------------------------- 1 | # @bunny.net/edge-script-sdk 2 | --- 3 | 4 |
5 | 6 | Bunny 7 | 8 |
9 | 10 | # Bunny Edge Scripting SDK 11 | 12 | This repository contains `@bunny.net/edgescript-sdk`, a library designed to simplify the development and testing of applications on the Bunny Edge Scripting platform. With this SDK, you can build, debug, and run scripts locally, then deploy them seamlessly to Bunny’s global edge network for production. 13 | 14 | Under the hood, Bunny Edge Scripting is built on Deno, and includes a custom runtime that supports running scripts interchangeably in both local and Bunny edge environments. This SDK emulates that environment locally, letting you develop and test your scripts with confidence before deploying them. 15 | 16 | > **Note:** While the Bunny runtime closely matches Deno and Node behaviors, some APIs may differ or be restricted due to the unique requirements of running applications in a serverless CDN-based environment. 17 | 18 | ## 🥕 Usage 19 | 20 | With `@bunny.net/edgescript-sdk`, you can write scripts that run smoothly on Deno, Node, and within the bunny.net network. Below is a quick example to help you get started with setting up a local server. For additional examples and use cases, refer to the [examples folder](./example/). 21 | 22 | ### Hello World Example 23 | ```typescript 24 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 25 | 26 | function sleep(ms: number): Promise { 27 | return new Promise((resolve) => setTimeout(resolve, ms)); 28 | } 29 | 30 | console.log("Starting server..."); 31 | 32 | BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { 33 | console.log(`[INFO]: ${req.method} - ${req.url}`); 34 | await sleep(1000); // Simulate some processing delay 35 | return new Response("Hello, Bunny Edge!"); 36 | }); 37 | ``` 38 | 39 | This example sets up a local HTTP server using the Bunny Edge Scripting SDK. You can access the server at 127.0.0.1:8080 and observe the real-time request logs. This setup mimics the way Bunny's edge network handles requests, providing a consistent development experience. 40 | 41 | ### Parameter Explanation 42 | 43 | - **`port`**: The port on which the server will listen for incoming HTTP requests. In this example, `8080` is specified, so you can access the server at [http://127.0.0.1:8080](http://127.0.0.1:8080). 44 | 45 | - **`hostname`**: The hostname or IP address for the server. Here, `'127.0.0.1'` restricts the server to listen only on the local machine (localhost). To make it accessible over the network, you could set it to `'0.0.0.0'`, allowing other devices to connect to the server. 46 | 47 | ## 🚀 Deploying to Bunny Edge 48 | After local development and testing, deploying to Bunny Edge Scripting is straightforward. Simply push your code to your Bunny Edge Scripting project’s GitHub repository, and it will be automatically deployed across Bunny’s global CDN. 49 | 50 | Once deployed, Bunny’s serve function processes incoming requests through a connected Pull Zone, allowing your application to deliver data from the edge with maximum speed and minimal latency. 51 | 52 | ## 🚨 Error Handling and Logging 53 | Bunny Edge Scripting includes built-in logging to support error tracking and observability. Use console.log, console.warn, and console.error statements within your code to monitor application flow, debug issues, and gather insights both locally and in deployment. 54 | -------------------------------------------------------------------------------- /libs/bunny-sdk/build.mjs: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import { readFile } from 'fs/promises'; 3 | import { defineConfig } from 'tsup' 4 | import { build } from 'tsup' 5 | 6 | const pkg = JSON.parse(await readFile(new URL('./package.json', import.meta.url))); 7 | 8 | const sharedConfig = { 9 | entry: ['src/lib.ts'], 10 | clean: true, 11 | experimentalDts: true, 12 | define: { 13 | "VERSION": `"${pkg.version}"`, 14 | } 15 | }; 16 | 17 | // CJS Build 18 | await build({ 19 | minify: false, 20 | splitting: false, 21 | sourcemap: false, 22 | outDir: "dist/", 23 | platform: "node", 24 | ...sharedConfig, 25 | }) 26 | 27 | let noNodeImpl = { 28 | name: 'example', 29 | setup(build) { 30 | build.onResolve({ filter: /_impl\/node\/.*/ }, args => { 31 | return { path: args.path, namespace: "node-special" } 32 | }) 33 | 34 | build.onLoad({ filter: /.*/, namespace: 'node-special' }, () => ({ 35 | contents: "const handler = { get: () => undefined }; const proxy = new Proxy({}, handler); export default proxy;", 36 | loader: 'js', 37 | })) 38 | }, 39 | } 40 | // ESM Non-Node Build 41 | await build({ 42 | minify: false, 43 | splitting: true, 44 | sourcemap: false, 45 | outDir: "esm/", 46 | platform: 'neutral', 47 | esbuildPlugins: [noNodeImpl], 48 | format: "esm", 49 | ...sharedConfig, 50 | }) 51 | 52 | // ESM Bunny Build 53 | await build({ 54 | minify: true, 55 | splitting: false, 56 | sourcemap: false, 57 | outDir: "esm-bunny/", 58 | platform: 'neutral', 59 | esbuildPlugins: [noNodeImpl], 60 | format: "esm", 61 | ...sharedConfig, 62 | }) 63 | 64 | // ESM Node 65 | await build({ 66 | minify: true, 67 | splitting: false, 68 | sourcemap: false, 69 | outDir: "esm-node/", 70 | platform: 'neutral', 71 | esbuildPlugins: [], 72 | format: "esm", 73 | ...sharedConfig, 74 | }) 75 | -------------------------------------------------------------------------------- /libs/bunny-sdk/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /libs/bunny-sdk/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts'], 6 | transform: { 7 | '^.+\\.ts$': 'ts-jest' 8 | }, 9 | } 10 | -------------------------------------------------------------------------------- /libs/bunny-sdk/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bunny.net/edgescript-sdk", 3 | "version": "0.12.0", 4 | "main": "dist/lib.js", 5 | "module": "esm/lib.mjs", 6 | "types": "dist/_tsup-dts-rollup.d.ts", 7 | "exports": { 8 | ".": { 9 | "deno": "./esm/lib.mjs", 10 | "node": "./esm-node/lib.mjs", 11 | "import": "./esm/lib.mjs", 12 | "require": "./dist/lib.js", 13 | "types": "./dist/_tsup-dts-rollup.d.ts" 14 | } 15 | }, 16 | "files": [ 17 | "dist", 18 | "esm", 19 | "esm-bunny", 20 | "esm-node" 21 | ], 22 | "scripts": { 23 | "lint": "eslint src", 24 | "test": "jest --silent --coverage", 25 | "build": "rm -rf dist esm esm-bunny && node build.mjs", 26 | "release": "rm -rf dist esm esm-bunny && node build.mjs && pnpm changeset publish && pnpm publish" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "keywords": [ 36 | "github", 37 | "bunny" 38 | ], 39 | "author": "Bunny Devs", 40 | "license": "MIT", 41 | "devDependencies": { 42 | "@deno/shim-deno": "^0.19.2", 43 | "@eslint/js": "^9.8.0", 44 | "@microsoft/api-extractor": "^7.47.6", 45 | "@types/jest": "^29.5.12", 46 | "@types/node": "^20.14.15", 47 | "@typescript-eslint/eslint-plugin": "^8.0.1", 48 | "@typescript-eslint/parser": "^8.0.1", 49 | "@vercel/ncc": "^0.38.1", 50 | "esbuild": "0.23.0", 51 | "eslint": "^9.8.0", 52 | "globals": "^15.9.0", 53 | "jest": "^29.5.12", 54 | "npm-dts": "^1.3.13", 55 | "prettier": "^3.3.3", 56 | "ts-jest": "^29.2.4", 57 | "tsup": "^8.2.4", 58 | "typedoc": "^0.26.1", 59 | "typescript": "^5.5.4", 60 | "typescript-eslint": "^8.0.1" 61 | }, 62 | "dependencies": { 63 | "@hono/node-server": "^1.12.0", 64 | "hono": "^4.5.5" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/lib.ts: -------------------------------------------------------------------------------- 1 | import * as net from "./net/index.ts"; 2 | 3 | export { 4 | /** 5 | * The `net` module contains Network related functions and utilities. 6 | */ 7 | net, 8 | }; 9 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/_impl/node/serve.ts: -------------------------------------------------------------------------------- 1 | import * as Tcp from "../../tcp.ts"; 2 | import * as Ip from "../../ip.ts"; 3 | import { ServeHandler, ServerHandler } from "../../serve.ts"; 4 | import * as HonoNode from "@hono/node-server"; 5 | import { Hono } from "hono"; 6 | import * as SocketAddr from "../../socket_addr.ts"; 7 | 8 | export function node_serve(listener: Tcp.TcpListener, handler: ServerHandler): ServeHandler { 9 | const addr = Tcp.unstable_local_addr(listener); 10 | 11 | if (!SocketAddr.isV4(addr)) { 12 | throw new Error("An issue happened with the addr."); 13 | } 14 | 15 | const port = SocketAddr.v4.port(addr); 16 | const hostname = Ip.toString(SocketAddr.v4.ip(addr)); 17 | 18 | const app = new Hono(); 19 | app.all("*", (c) => { 20 | return handler(c.req.raw); 21 | }) 22 | 23 | HonoNode.serve({ 24 | fetch: app.fetch, hostname, port 25 | }); 26 | return ({}); 27 | } 28 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Networking primitives to be used for communication. 3 | * 4 | * The Bunny Network only exposed scripts through a domain name for now, the 5 | * networking stack accessible here reflect what is possible to expose through 6 | * Bunny Edge Scripting. 7 | * 8 | * @packageDocumentation 9 | */ 10 | 11 | import * as tcp from "./tcp.ts"; 12 | import * as socketAddr from "./socket_addr.ts"; 13 | import * as http from "./serve.ts"; 14 | import * as ip from "./ip.ts"; 15 | 16 | export { http, ip, socketAddr, tcp }; 17 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/ip.test.ts: -------------------------------------------------------------------------------- 1 | import * as IP from "./ip.ts"; 2 | 3 | test('toString should convert IPv4 tuple to string', () => { 4 | const ip: IP.IPv4 = [192, 168, 1, 1]; 5 | expect(IP.toString(ip)).toBe('192.168.1.1'); 6 | }); 7 | 8 | test('tryParseFromString should parse valid IP string', () => { 9 | const ipString = '192.168.1.1'; 10 | const expected: IP.IPv4 = [192, 168, 1, 1]; 11 | expect(IP.tryParseFromString(ipString)).toEqual(expected); 12 | }); 13 | 14 | test('tryParseFromString should return SyntaxError for invalid IP string', () => { 15 | const invalidIpString = '999.999.999.999'; 16 | expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); 17 | }); 18 | 19 | test('tryParseFromString should return SyntaxError for non-numeric IP string', () => { 20 | const invalidIpString = 'abc.def.ghi.jkl'; 21 | expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); 22 | }); 23 | 24 | test('tryParseFromString should return SyntaxError for incomplete IP string', () => { 25 | const invalidIpString = '192.168.1'; 26 | expect(IP.tryParseFromString(invalidIpString)).toBeInstanceOf(SyntaxError); 27 | }); 28 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/ip.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Networking Primitives for the IP Address. 3 | * 4 | * @packageDocumentation 5 | */ 6 | 7 | export type Enumerate = 8 | Acc["length"] extends N ? Acc[number] 9 | : Enumerate; 10 | 11 | export type Range = 12 | | Exclude, Enumerate> 13 | | T; 14 | 15 | /** 16 | * An IPv4 Address 17 | */ 18 | export type IPv4 = [Range<0, 255>, Range<0, 255>, Range<0, 255>, Range<0, 255>]; 19 | 20 | export function toString(ip: IPv4): string { 21 | return `${ip[0]}.${ip[1]}.${ip[2]}.${ip[3]}`; 22 | } 23 | 24 | /** 25 | * Try to parse na IP 26 | */ 27 | export function tryParseFromString(ip: string): IPv4 | SyntaxError { 28 | const parts = ip.split(".").map(Number); 29 | if ( 30 | parts.length !== 4 || 31 | parts.some((part) => isNaN(part) || part < 0 || part > 255) 32 | ) { 33 | return new SyntaxError("Invalid IP address"); 34 | } 35 | return [parts[0], parts[1], parts[2], parts[3]] as IPv4; 36 | } 37 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/socket/v4.test.ts: -------------------------------------------------------------------------------- 1 | import { SocketAddrV4, port, tryFromString, ip } from './v4.ts'; 2 | 3 | describe('SocketAddrV4', () => { 4 | describe('port', () => { 5 | it('should return the port number', () => { 6 | const addr: SocketAddrV4 = { _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }; 7 | expect(port(addr)).toBe(8080); 8 | }); 9 | }); 10 | 11 | describe('ip', () => { 12 | it('should return the IP address', () => { 13 | const addr: SocketAddrV4 = { _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }; 14 | expect(ip(addr)).toStrictEqual([127, 0, 0, 1]); 15 | }); 16 | }); 17 | 18 | describe('tryFromString', () => { 19 | it('should parse a valid SocketAddrV4 string', () => { 20 | const result = tryFromString("127.0.0.1:8080"); 21 | expect(result).toEqual({ _tag: "SocketAddrV4", port: 8080, ip: [127, 0, 0, 1] }); 22 | }); 23 | 24 | it('should return a SyntaxError for an invalid IP', () => { 25 | const result = tryFromString("invalid_ip:8080"); 26 | expect(result).toBeInstanceOf(SyntaxError); 27 | expect((result as SyntaxError).message).toBe('Invalid IP address'); 28 | }); 29 | 30 | it('should return a SyntaxError for an invalid port', () => { 31 | const result = tryFromString("127.0.0.1:invalid_port"); 32 | expect(result).toBeInstanceOf(SyntaxError); 33 | expect((result as SyntaxError).message).toBe('Invalid Port'); 34 | }); 35 | 36 | it('should return a SyntaxError for a port out of range', () => { 37 | const result = tryFromString("127.0.0.1:70000"); 38 | expect(result).toBeInstanceOf(SyntaxError); 39 | expect((result as SyntaxError).message).toBe('Invalid Port'); 40 | }); 41 | 42 | it('should return a SyntaxError for an invalid format', () => { 43 | const result = tryFromString("127.0.0.1-8080"); 44 | expect(result).toBeInstanceOf(SyntaxError); 45 | expect((result as SyntaxError).message).toBe('Invalid SocketAddrV4 address'); 46 | }); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/socket/v4.ts: -------------------------------------------------------------------------------- 1 | import * as IP from "../ip.ts"; 2 | 3 | export type SocketAddrV4 = { 4 | readonly _tag: "SocketAddrV4", 5 | port: number, 6 | ip: IP.IPv4, 7 | }; 8 | 9 | /** 10 | * Returns the port number associated with this socket address. 11 | */ 12 | export function port(addr: SocketAddrV4): number { 13 | return addr.port; 14 | } 15 | 16 | /** 17 | * Returns the IP address associated with this socket address. 18 | */ 19 | export function ip(addr: SocketAddrV4): IP.IPv4 { 20 | return addr.ip; 21 | } 22 | 23 | /** 24 | * Try to parse a SocketAddrV4 25 | */ 26 | export function tryFromString(value: string): SocketAddrV4 | SyntaxError { 27 | const parts = value.split(':'); 28 | 29 | if (parts.length !== 2) { 30 | return new SyntaxError('Invalid SocketAddrV4 address'); 31 | } 32 | 33 | const ip = IP.tryParseFromString(parts[0]); 34 | if (ip instanceof SyntaxError) { 35 | return ip; 36 | } 37 | const port = Number(parts[1]); 38 | if (isNaN(port) || port < 0 || port > 65535) { 39 | return new SyntaxError('Invalid Port'); 40 | } 41 | 42 | return ({ 43 | _tag: "SocketAddrV4", 44 | port, 45 | ip, 46 | }) 47 | } 48 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/socket_addr.ts: -------------------------------------------------------------------------------- 1 | import * as v4 from "./socket/v4.ts"; 2 | 3 | export * as v4 from "./socket/v4.ts"; 4 | 5 | export type NoAddr = { 6 | readonly _tag: "NoAddr"; 7 | }; 8 | 9 | /** 10 | * An internet socket address 11 | * 12 | * We have a special case where it's not a socket address but a socket provided 13 | * by Bunny. This type will be refined with the associated method to fix it. 14 | */ 15 | export type SocketAddr = v4.SocketAddrV4 | NoAddr; 16 | 17 | /** 18 | * Tell if it's a v4 [SocketAddr]. 19 | */ 20 | export function isV4(value: SocketAddr): value is v4.SocketAddrV4 { 21 | return value._tag === "SocketAddrV4"; 22 | } 23 | 24 | export type SocketAddrError = InvalidAddr; 25 | 26 | const addr_symbol: symbol = Symbol("invalidAddr"); 27 | export class InvalidAddr extends Error { 28 | _guard: typeof addr_symbol = addr_symbol; 29 | 30 | constructor(message: string) { 31 | super(message); 32 | this.name = "InvalidAddr"; 33 | } 34 | 35 | override toString() { 36 | return `${this.name}: ${this.message}`; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/net/tcp.ts: -------------------------------------------------------------------------------- 1 | import { internal_getPlatform } from "../platform.ts"; 2 | import * as SocketAddr from "./socket_addr.ts"; 3 | 4 | export type TcpListener = { 5 | /** 6 | * Prevent the construction 7 | * @internal 8 | */ 9 | readonly _tag: 'TcpListener'; 10 | addr: SocketAddr.SocketAddr; 11 | } 12 | 13 | export function isTcpListener(value: unknown): value is TcpListener { 14 | return value instanceof Object && value["_tag"] === "TcpListener"; 15 | } 16 | 17 | /** 18 | * Returns the local socket address of this listener. 19 | */ 20 | export function unstable_local_addr(tcp: TcpListener): SocketAddr.SocketAddr { 21 | return tcp.addr; 22 | } 23 | 24 | /** 25 | * Format the associated [TcpListener] to a String 26 | */ 27 | export function toString(tcp: TcpListener): string { 28 | switch (tcp.addr._tag) { 29 | case "SocketAddrV4": 30 | return `${SocketAddr.v4.ip(tcp.addr).join('.')}:${SocketAddr.v4.port(tcp.addr)}`; 31 | case "NoAddr": 32 | return "No addr associated to this listener. You should be running in a controlled environment."; 33 | } 34 | } 35 | 36 | /** 37 | * Create a new [TcpListener]. 38 | */ 39 | export function unstable_new(): TcpListener { 40 | const platform = internal_getPlatform(); 41 | switch (platform.runtime) { 42 | case "bunny": { 43 | return ({ 44 | _tag: "TcpListener", 45 | addr: { 46 | _tag: "NoAddr" 47 | } 48 | }); 49 | } 50 | default: 51 | return ({ 52 | _tag: 'TcpListener', 53 | addr: { 54 | _tag: "SocketAddrV4", 55 | port: 8080, 56 | ip: [127, 0, 0, 1], 57 | }, 58 | }); 59 | 60 | } 61 | } 62 | 63 | 64 | /** 65 | * Bind an Addr 66 | */ 67 | export function bind(addr: SocketAddr.v4.SocketAddrV4): TcpListener { 68 | // TODO: Add a proper bind to ensure the port is available. 69 | 70 | return ({ 71 | _tag: 'TcpListener', 72 | addr, 73 | }); 74 | } 75 | -------------------------------------------------------------------------------- /libs/bunny-sdk/src/platform.ts: -------------------------------------------------------------------------------- 1 | // Adapted from https://github.com/openai/openai-deno-build/blob/ea31e868608f359c6a948f456efea2b28df6e775/core.ts#L1087 2 | 3 | type PlatformName = 4 | | "MacOS" 5 | | "Linux" 6 | | "Windows" 7 | | "FreeBSD" 8 | | "OpenBSD" 9 | | "iOS" 10 | | "Android" 11 | | `Other:${string}` 12 | | "Unknown"; 13 | 14 | // Defined by `build` step. 15 | declare const VERSION: string; 16 | 17 | type Platform = { 18 | /** 19 | * @internal 20 | */ 21 | readonly _tag: "_Platform"; 22 | name: PlatformName; 23 | version: string; 24 | runtime: "bunny" | "node" | "deno" | "unknown"; 25 | runtime_version: string; 26 | }; 27 | 28 | const normalizePlatform = (platform: string): PlatformName => { 29 | // Node platforms: 30 | // - https://nodejs.org/api/process.html#processplatform 31 | // Deno platforms: 32 | // - https://doc.deno.land/deno/stable/~/Deno.build 33 | // - https://github.com/denoland/deno/issues/14799 34 | 35 | platform = platform.toLowerCase(); 36 | 37 | if (platform.includes("ios")) return "iOS"; 38 | if (platform === "android") return "Android"; 39 | if (platform === "darwin") return "MacOS"; 40 | if (platform === "win32") return "Windows"; 41 | if (platform === "freebsd") return "FreeBSD"; 42 | if (platform === "openbsd") return "OpenBSD"; 43 | if (platform === "linux") return "Linux"; 44 | if (platform) return `Other:${platform}`; 45 | return "Unknown"; 46 | }; 47 | 48 | const internal_getPlatform = (): Platform => { 49 | // Check if Bunny 50 | if (typeof Bunny !== "undefined") { 51 | return { 52 | _tag: "_Platform", 53 | version: VERSION, 54 | name: "Unknown", 55 | runtime: "bunny", 56 | runtime_version: "unknown", 57 | }; 58 | } 59 | 60 | // Check if Deno 61 | if (typeof Deno !== "undefined" && Deno.build != null) { 62 | return { 63 | _tag: "_Platform", 64 | version: VERSION, 65 | name: normalizePlatform(Deno.build.os), 66 | runtime: "deno", 67 | runtime_version: typeof Deno.version === "string" 68 | ? Deno.version 69 | : Deno.version?.deno ?? "unknown", 70 | }; 71 | } 72 | const process = globalThis.process; 73 | // Check if Node.js 74 | if ( 75 | Object.prototype.toString.call( 76 | typeof process !== "undefined" ? process : 0, 77 | ) === "[object process]" 78 | ) { 79 | return { 80 | _tag: "_Platform", 81 | version: VERSION, 82 | name: normalizePlatform(process.platform), 83 | runtime: "node", 84 | runtime_version: process.version, 85 | }; 86 | } 87 | 88 | return { 89 | _tag: "_Platform", 90 | version: VERSION, 91 | name: "Unknown", 92 | runtime: "unknown", 93 | runtime_version: "unknown", 94 | }; 95 | }; 96 | 97 | export { 98 | internal_getPlatform, 99 | Platform, 100 | }; 101 | -------------------------------------------------------------------------------- /libs/bunny-sdk/tests/empty.test.ts: -------------------------------------------------------------------------------- 1 | // import { jest } from '@jest/globals'; 2 | 3 | describe('empty', () => { 4 | test('empty test', async () => { 5 | expect(true).toBe(true); 6 | }); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /libs/bunny-sdk/tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": [ 4 | "node_modules" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /libs/bunny-sdk/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext", 7 | "dom" 8 | ], 9 | "outDir": "./dist", 10 | "rootDir": "./src", 11 | "strict": true, 12 | "noImplicitAny": false, 13 | "esModuleInterop": false, 14 | "skipLibCheck": true, 15 | "allowImportingTsExtensions": true, 16 | "allowSyntheticDefaultImports": true, 17 | "noUnusedLocals": true, 18 | "noUnusedParameters": true, 19 | "downlevelIteration": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "suppressExcessPropertyErrors": false, 22 | "declaration": true, 23 | "sourceMap": false, 24 | "noEmitOnError": false 25 | }, 26 | "exclude": [ 27 | "dist", 28 | "esm", 29 | "node_modules", 30 | "**/*.test.*" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /libs/bunny-sdk/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../../typedoc.base.jsonc" 4 | ], 5 | "entryPoints": [ 6 | "src/lib.ts" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /libs/bunny-sdk/types/bunny.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The global BunnySDK available 3 | * @internal 4 | */ 5 | declare namespace Bunny { 6 | type BunnySDKV1 = { 7 | /** 8 | * Serve function 9 | */ 10 | serve: (handler: (request: Request) => Response | Promise) => void, 11 | /** 12 | * Serve PullZone function, to leverage middlewares 13 | */ 14 | registerMiddlewares: (middlewares: { 15 | onOriginRequest: Array<( 16 | ctx: { request: Request }, 17 | ) => Promise | Promise | undefined> 18 | onOriginResponse: Array<( 19 | ctx: { request: Request, response: Response }, 20 | ) => Promise | Promise | undefined> 21 | }) => void, 22 | }; 23 | 24 | export const v1: BunnySDKV1; 25 | 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /libs/bunny-storage/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | /dist/ 15 | /esm/ 16 | /esm-node/ 17 | /esm-bunny/ 18 | 19 | # production 20 | /build 21 | 22 | # misc 23 | .DS_Store 24 | *.pem 25 | 26 | # debug 27 | npm-debug.log* 28 | yarn-debug.log* 29 | yarn-error.log* 30 | 31 | .vscode 32 | 33 | # local env files 34 | .env*.local 35 | 36 | # vercel 37 | .vercel 38 | 39 | # typescript 40 | *.tsbuildinfo 41 | next-env.d.ts 42 | -------------------------------------------------------------------------------- /libs/bunny-storage/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @bunny.net/storage-sdk 2 | 3 | ## 0.3.0 4 | 5 | ### Minor Changes 6 | 7 | - 6199c9e: Properly export ESM for Node & Deno 8 | 9 | ## 0.2.2 10 | 11 | ### Patch Changes 12 | 13 | - ecaa70b: Small issue with url when getting file metadata 14 | 15 | ## 0.2.1 16 | 17 | ### Patch Changes 18 | 19 | - dc07b56: Update README.md 20 | 21 | ## 0.2.0 22 | 23 | ### Minor Changes 24 | 25 | - f479879: Adding the bunny-storage library preview 26 | -------------------------------------------------------------------------------- /libs/bunny-storage/README.md: -------------------------------------------------------------------------------- 1 | # @bunny.net/storage-sdk 2 | --- 3 | 4 |
5 | 6 | Bunny 7 | 8 |
9 | 10 | 11 | The `@bunny.net/storage-sdk` a library designed to help you interact with 12 | BunnyCDN Storage API. 13 | 14 | # Bunny Storage SDK 15 | 16 | This repository contains `@bunny.net/storage-sdk`, a library designed to simplify the usage of the BunnyCDN Storage API. 17 | 18 | ## 🥕 Usage 19 | 20 | With `@bunny.net/storage-sdk`, you can interact with the BunnyCDN Storage API. Below is a quick example to help you get started with setting up a local server. For additional examples and use cases, refer to the [examples folder](/example/). 21 | 22 | ### Listing files on your Storage Zone 23 | ```typescript 24 | import * as BunnySDK from "@bunny.net/edgescript-sdk"; 25 | import * as BunnyStorageSDK from "@bunny.net/storage-sdk"; 26 | 27 | let sz_zone = process.env.STORAGE_ZONE!; 28 | let access_key = process.env.STORAGE_ACCESS_KEY!; 29 | 30 | let sz = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, sz_zone, access_key); 31 | 32 | console.log("Starting server..."); 33 | 34 | BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { 35 | let list = await BunnyStorageSDK.file.list(sz, "/"); 36 | console.log(`[INFO]: ${req.method} - ${req.url}`); 37 | return new Response(JSON.stringify(list)); 38 | }); 39 | ``` 40 | 41 | This example sets up a local HTTP server using the Bunny Edge Scripting SDK to list files on a Storage Zone using the BunnyCDN Storage SDK. You can access the server at 127.0.0.1:8080 and observe the real-time request logs. 42 | 43 | ### Quick Start 44 | 45 | - [list](#listing-files) 46 | - [delete](#remove-files-or-directory) 47 | - [upload](#uploading-a-file) 48 | - [download](#download-a-file) 49 | 50 | #### Getting a file 51 | 52 | When getting a file, you can either get the metadata of a file, or the content 53 | of the file. 54 | 55 | The metadata describe the file. 56 | 57 | ```typescript 58 | import * as BunnyStorageSDK from "@bunny.net/storage-sdk"; 59 | 60 | let storageZone = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, "storage-zone-name", "token") 61 | let obj = await BunnyStorageSDK.file.get(storageZone, "/my-folder/my-file"); 62 | 63 | /* 64 | * Here obj will be equal to something like this: 65 | const obj = { 66 | Guid: '123', 67 | UserId: 'user1', 68 | LastChanged: '2023-01-01T00:00:00Z', 69 | DateCreated: '2022-01-01T00:00:00Z', 70 | StorageZoneName: 'test-zone', 71 | Path: '/test/path', 72 | ObjectName: 'test-file.txt', 73 | Length: 100, 74 | StorageZoneId: 1, 75 | IsDirectory: false, 76 | ServerId: 1, 77 | Checksum: 'abc123', 78 | ReplicatedZones: 'UK,NY', 79 | ContentType: 'text/plain', 80 | data: () => Promise<{ 81 | stream: ReadableStream; 82 | response: Response; 83 | length?: number; 84 | }>, 85 | 86 | }; 87 | */ 88 | ``` 89 | 90 | From this metadata, you can then download the file content by using `await obj.data()`. 91 | 92 | #### Listing files 93 | 94 | You can list and navigate accross your storage zone by using: 95 | 96 | ```typescript 97 | let list = await BunnyStorageSDK.file.list(sz, "/"); 98 | ``` 99 | 100 | This will give you a list of file Metadata you'll be able to navigate. 101 | 102 | #### Uploading a file 103 | 104 | To upload a file, we leverage **Streams** to upload files as it would allow you 105 | to upload files without having the full stream of content available. 106 | 107 | ```typescript 108 | export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream, options?: UploadOptions): Promise; 109 | export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream): Promise; 110 | export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream, options?: UploadOptions): Promise; 111 | 112 | export type UploadOptions = { 113 | /** 114 | * The SHA256 Checksum associated to the data you want to send. If null then 115 | * the server will automatically calculate it. 116 | */ 117 | sha256Checksum?: string; 118 | /** 119 | * You can override the content-type of the file you upload with this option. 120 | */ 121 | contentType?: string; 122 | }; 123 | ``` 124 | 125 | Example: 126 | 127 | ```typescript 128 | await BunnyStorageSDK.file.upload(sz, "/some-file", random_bytes_10kb); 129 | ``` 130 | 131 | #### Download a file 132 | 133 | To downlaod a file, you have two choices, either you use this function to 134 | download it directly. 135 | 136 | ```typescript 137 | export async function download(storageZone: StorageZone.StorageZone, path: string): Promise<{ 138 | stream: ReadableStream; 139 | response: Response; 140 | length?: number; 141 | }>; 142 | ``` 143 | 144 | Example: 145 | 146 | ```typescript 147 | await BunnyStorageSDK.file.download(sz, "/some-file"); 148 | ``` 149 | 150 | You'll have the stream of the content and the associated response and the length 151 | if available. 152 | 153 | You could also use the `data` function available in the File Metadata. 154 | 155 | #### Remove files or directory 156 | 157 | 158 | ```typescript 159 | export async function remove(storageZone: StorageZone.StorageZone, path: string): Promise; 160 | export async function removeDirectory(storageZone: StorageZone.StorageZone, path: string): Promise; 161 | ``` 162 | 163 | Example: 164 | 165 | ```typescript 166 | await BunnyStorageSDK.file.remove(sz, "/some-file"); 167 | ``` 168 | -------------------------------------------------------------------------------- /libs/bunny-storage/build.mjs: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import { readFile } from 'fs/promises'; 3 | import { defineConfig } from 'tsup' 4 | import { build } from 'tsup' 5 | 6 | const pkg = JSON.parse(await readFile(new URL('./package.json', import.meta.url))); 7 | 8 | const sharedConfig = { 9 | entry: ['src/lib.ts'], 10 | clean: true, 11 | experimentalDts: true, 12 | define: { 13 | "VERSION": `"${pkg.version}"`, 14 | } 15 | }; 16 | 17 | // CJS Build 18 | await build({ 19 | minify: false, 20 | splitting: false, 21 | sourcemap: false, 22 | outDir: "dist/", 23 | platform: "node", 24 | ...sharedConfig, 25 | }) 26 | 27 | let noNodeImpl = { 28 | name: 'example', 29 | setup(build) { 30 | build.onResolve({ filter: /_impl\/node\/.*/ }, args => { 31 | return { path: args.path, namespace: "node-special" } 32 | }) 33 | 34 | build.onLoad({ filter: /.*/, namespace: 'node-special' }, () => ({ 35 | contents: "const handler = { get: () => undefined }; const proxy = new Proxy({}, handler); export default proxy;", 36 | loader: 'js', 37 | })) 38 | }, 39 | } 40 | // ESM Non node Build 41 | await build({ 42 | minify: false, 43 | splitting: true, 44 | sourcemap: false, 45 | outDir: "esm/", 46 | platform: 'neutral', 47 | esbuildPlugins: [noNodeImpl], 48 | format: "esm", 49 | ...sharedConfig, 50 | }) 51 | 52 | // ESM Bunny Build 53 | await build({ 54 | minify: true, 55 | splitting: false, 56 | sourcemap: false, 57 | outDir: "esm-bunny/", 58 | platform: 'neutral', 59 | esbuildPlugins: [noNodeImpl], 60 | format: "esm", 61 | ...sharedConfig, 62 | }) 63 | 64 | // ESM Node 65 | await build({ 66 | minify: true, 67 | splitting: false, 68 | sourcemap: false, 69 | outDir: "esm-node/", 70 | platform: 'neutral', 71 | esbuildPlugins: [], 72 | format: "esm", 73 | ...sharedConfig, 74 | }) 75 | -------------------------------------------------------------------------------- /libs/bunny-storage/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | { files: ["**/*.{js,mjs,cjs,ts}"] }, 8 | { languageOptions: { globals: globals.browser } }, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | ]; 12 | 13 | -------------------------------------------------------------------------------- /libs/bunny-storage/jest.config.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | require('dotenv').config({ path: `.env.local`, override: true }); 3 | 4 | module.exports = { 5 | clearMocks: true, 6 | moduleFileExtensions: ['js', 'ts'], 7 | testEnvironment: 'node', 8 | testMatch: ['**/*.test.ts'], 9 | transform: { 10 | '^.+\\.ts$': 'ts-jest' 11 | }, 12 | } 13 | -------------------------------------------------------------------------------- /libs/bunny-storage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bunny.net/storage-sdk", 3 | "version": "0.3.0", 4 | "main": "dist/lib.js", 5 | "module": "esm-node/lib.mjs", 6 | "types": "dist/_tsup-dts-rollup.d.ts", 7 | "exports": { 8 | ".": { 9 | "deno": "./esm/lib.mjs", 10 | "node": "./esm-node/lib.mjs", 11 | "import": "./esm/lib.mjs", 12 | "require": "./dist/lib.js", 13 | "types": "./dist/_tsup-dts-rollup.d.ts" 14 | } 15 | }, 16 | "files": [ 17 | "dist", 18 | "esm", 19 | "esm-bunny", 20 | "esm-node" 21 | ], 22 | "scripts": { 23 | "lint": "eslint src", 24 | "test": "jest --silent --coverage", 25 | "build": "rm -rf dist esm esm-bunny && node build.mjs", 26 | "release": "rm -rf dist esm esm-bunny && node build.mjs && pnpm changeset publish && pnpm publish" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/BunnyWay/edge-script-sdk.git" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "keywords": [ 36 | "github", 37 | "bunny" 38 | ], 39 | "author": "Bunny Devs", 40 | "license": "MIT", 41 | "devDependencies": { 42 | "@deno/shim-deno": "^0.19.2", 43 | "@eslint/js": "^9.8.0", 44 | "@microsoft/api-extractor": "^7.47.6", 45 | "@types/jest": "^29.5.12", 46 | "@types/node": "^20.14.15", 47 | "@typescript-eslint/eslint-plugin": "^8.0.1", 48 | "@typescript-eslint/parser": "^8.0.1", 49 | "@vercel/ncc": "^0.38.1", 50 | "esbuild": "0.23.0", 51 | "eslint": "^9.8.0", 52 | "globals": "^15.9.0", 53 | "jest": "^29.5.12", 54 | "npm-dts": "^1.3.13", 55 | "prettier": "^3.3.3", 56 | "ts-jest": "^29.2.4", 57 | "tsup": "^8.2.4", 58 | "typedoc": "^0.26.1", 59 | "typescript": "^5.5.4", 60 | "typescript-eslint": "^8.0.1", 61 | "ulid": "^2.3.0" 62 | }, 63 | "dependencies": { 64 | "dotenv": "^16.4.7", 65 | "zod": "^3.24.2" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/api.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod'; 2 | import { ZoneSchema } from './file'; 3 | 4 | export const ReplicatedZonesStringSchema = z.string(); 5 | 6 | export const ReplicatedZonesSchema = ReplicatedZonesStringSchema.transform((str) => { 7 | const zones = str.split(',').map(zone => zone.trim()).filter(x => x != ''); 8 | return zones.map(zone => ZoneSchema.parse(zone)); 9 | }); 10 | 11 | 12 | export const StorageFileSchemaDescribe = z.object({ 13 | Guid: z.string(), 14 | UserId: z.string(), 15 | LastChanged: z.coerce.date(), 16 | DateCreated: z.coerce.date(), 17 | StorageZoneName: z.string(), 18 | Path: z.string(), 19 | ObjectName: z.string(), 20 | Length: z.number(), 21 | StorageZoneId: z.number(), 22 | IsDirectory: z.boolean(), 23 | ServerId: z.number(), 24 | Checksum: z.nullable(z.string()), 25 | ReplicatedZones: z.nullable(ReplicatedZonesSchema), 26 | ContentType: z.string(), 27 | }); 28 | 29 | export const StorageFileListing = z.array(StorageFileSchemaDescribe); 30 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/lib.ts: -------------------------------------------------------------------------------- 1 | import * as regions from "./regions.ts"; 2 | import * as file from "./file.ts"; 3 | import * as zone from "./zone.ts"; 4 | 5 | export { 6 | regions, 7 | file, 8 | zone, 9 | }; 10 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/regions.test.ts: -------------------------------------------------------------------------------- 1 | import * as Regions from './regions.ts'; 2 | 3 | describe('StorageRegion enum', () => { 4 | it('should have the correct region codes', () => { 5 | expect(Regions.StorageRegion.Falkenstein).toBe('de'); 6 | expect(Regions.StorageRegion.London).toBe('uk'); 7 | expect(Regions.StorageRegion.NewYork).toBe('ny'); 8 | expect(Regions.StorageRegion.LosAngeles).toBe('la'); 9 | expect(Regions.StorageRegion.Singapore).toBe('sg'); 10 | expect(Regions.StorageRegion.Stockholm).toBe('se'); 11 | expect(Regions.StorageRegion.SaoPaulo).toBe('br'); 12 | expect(Regions.StorageRegion.Johannesburg).toBe('jh'); 13 | expect(Regions.StorageRegion.Sydney).toBe('syd'); 14 | }); 15 | }); 16 | 17 | describe('addr function', () => { 18 | it('should return the correct URL for Falkenstein', () => { 19 | const url = Regions.addr(Regions.StorageRegion.Falkenstein); 20 | expect(url.toString()).toBe('https://storage.bunnycdn.com/'); 21 | }); 22 | 23 | it('should return the correct URL for London', () => { 24 | const url = Regions.addr(Regions.StorageRegion.London); 25 | expect(url.toString()).toBe('https://uk.storage.bunnycdn.com/'); 26 | }); 27 | 28 | it('should return the correct URL for New York', () => { 29 | const url = Regions.addr(Regions.StorageRegion.NewYork); 30 | expect(url.toString()).toBe('https://ny.storage.bunnycdn.com/'); 31 | }); 32 | 33 | it('should return the correct URL for Los Angeles', () => { 34 | const url = Regions.addr(Regions.StorageRegion.LosAngeles); 35 | expect(url.toString()).toBe('https://la.storage.bunnycdn.com/'); 36 | }); 37 | 38 | it('should return the correct URL for Singapore', () => { 39 | const url = Regions.addr(Regions.StorageRegion.Singapore); 40 | expect(url.toString()).toBe('https://sg.storage.bunnycdn.com/'); 41 | }); 42 | 43 | it('should return the correct URL for Stockholm', () => { 44 | const url = Regions.addr(Regions.StorageRegion.Stockholm); 45 | expect(url.toString()).toBe('https://se.storage.bunnycdn.com/'); 46 | }); 47 | 48 | it('should return the correct URL for Sao Paulo', () => { 49 | const url = Regions.addr(Regions.StorageRegion.SaoPaulo); 50 | expect(url.toString()).toBe('https://br.storage.bunnycdn.com/'); 51 | }); 52 | 53 | it('should return the correct URL for Johannesburg', () => { 54 | const url = Regions.addr(Regions.StorageRegion.Johannesburg); 55 | expect(url.toString()).toBe('https://jh.storage.bunnycdn.com/'); 56 | }); 57 | 58 | it('should return the correct URL for Sydney', () => { 59 | const url = Regions.addr(Regions.StorageRegion.Sydney); 60 | expect(url.toString()).toBe('https://syd.storage.bunnycdn.com/'); 61 | }); 62 | 63 | it('should throw an error for invalid region', () => { 64 | // @ts-expect-error Testing with invalid input 65 | expect(() => Regions.addr('invalid-region')).toThrow('Invalid Storage Region'); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/regions.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Regions available for the primary storage region of your storage Zone 3 | */ 4 | export enum StorageRegion { 5 | Falkenstein = "de", 6 | London = "uk", 7 | NewYork = "ny", 8 | LosAngeles = "la", 9 | Singapore = "sg", 10 | Stockholm = "se", 11 | SaoPaulo = "br", 12 | Johannesburg = "jh", 13 | Sydney = "syd", 14 | }; 15 | 16 | /** 17 | * Give the associated URL Address for a Storage Region. 18 | * 19 | * @throws: If the value is not a proper storage region. 20 | */ 21 | export function addr(value: StorageRegion): URL { 22 | switch (value) { 23 | case StorageRegion.Falkenstein: 24 | return new URL("https://storage.bunnycdn.com"); 25 | case StorageRegion.London: 26 | return new URL("https://uk.storage.bunnycdn.com"); 27 | case StorageRegion.NewYork: 28 | return new URL("https://ny.storage.bunnycdn.com"); 29 | case StorageRegion.LosAngeles: 30 | return new URL("https://la.storage.bunnycdn.com"); 31 | case StorageRegion.Singapore: 32 | return new URL("https://sg.storage.bunnycdn.com"); 33 | case StorageRegion.Stockholm: 34 | return new URL("https://se.storage.bunnycdn.com"); 35 | case StorageRegion.SaoPaulo: 36 | return new URL("https://br.storage.bunnycdn.com"); 37 | case StorageRegion.Johannesburg: 38 | return new URL("https://jh.storage.bunnycdn.com"); 39 | case StorageRegion.Sydney: 40 | return new URL("https://syd.storage.bunnycdn.com"); 41 | default: 42 | throw new Error("Invalid Storage Region"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/zone.test.ts: -------------------------------------------------------------------------------- 1 | 2 | import * as Zone from './zone'; 3 | import * as Regions from './regions'; 4 | 5 | describe('StorageZone operations', () => { 6 | describe('connect_with_accesskey function', () => { 7 | it('should create a valid StorageZone object', () => { 8 | const storageZone = Zone.connect_with_accesskey( 9 | Regions.StorageRegion.Falkenstein, 10 | 'test-zone', 11 | 'test-access-key' 12 | ); 13 | 14 | expect(storageZone).toEqual({ 15 | _tag: 'StorageZone', 16 | region: 'de', 17 | name: 'test-zone', 18 | accessKey: 'test-access-key' 19 | }); 20 | }); 21 | }); 22 | 23 | describe('addr function', () => { 24 | it('should return the correct URL for a storage zone', () => { 25 | const storageZone = Zone.connect_with_accesskey( 26 | Regions.StorageRegion.Falkenstein, 27 | 'test-zone', 28 | 'test-access-key' 29 | ); 30 | 31 | const url = Zone.addr(storageZone); 32 | 33 | expect(url.toString()).toBe('https://storage.bunnycdn.com/test-zone/'); 34 | }); 35 | 36 | it('should return the correct URL for a storage zone in a different region', () => { 37 | const storageZone = Zone.connect_with_accesskey( 38 | Regions.StorageRegion.London, 39 | 'uk-zone', 40 | 'test-access-key' 41 | ); 42 | 43 | const url = Zone.addr(storageZone); 44 | 45 | expect(url.toString()).toBe('https://uk.storage.bunnycdn.com/uk-zone/'); 46 | }); 47 | }); 48 | 49 | describe('name function', () => { 50 | it('should return the name of the storage zone', () => { 51 | const storageZone = Zone.connect_with_accesskey( 52 | Regions.StorageRegion.Falkenstein, 53 | 'test-zone', 54 | 'test-access-key' 55 | ); 56 | 57 | const name = Zone.name(storageZone); 58 | 59 | expect(name).toBe('test-zone'); 60 | }); 61 | }); 62 | 63 | describe('key function', () => { 64 | it('should return the correct authentication header and key', () => { 65 | const storageZone = Zone.connect_with_accesskey( 66 | Regions.StorageRegion.Falkenstein, 67 | 'test-zone', 68 | 'test-access-key' 69 | ); 70 | 71 | const [header, key] = Zone.key(storageZone); 72 | 73 | expect(header).toBe('AccessKey'); 74 | expect(key).toBe('test-access-key'); 75 | }); 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /libs/bunny-storage/src/zone.ts: -------------------------------------------------------------------------------- 1 | import * as Regions from "./regions"; 2 | 3 | export type StorageZone = { 4 | readonly _tag: "StorageZone", 5 | region: Regions.StorageRegion, 6 | accessKey: string, 7 | name: string, 8 | 9 | // If this is set up, the reading will not goes into the API but it'll goes to 10 | // the associated PZ, it'll increase greatly the scalibility of the read & the 11 | // performance. 12 | // Especially if caching is activated on a PullZone. 13 | // optimized_reading_pz: null, 14 | }; 15 | 16 | /** 17 | * Give the associated URL Address for a [StorageZone]. 18 | * 19 | * @throws If the value is not a proper [StorageRegion]. 20 | */ 21 | export function addr(value: StorageZone): URL { 22 | return new URL(`${Regions.addr(value.region)}${value.name}/`); 23 | } 24 | 25 | /** 26 | * Give the associated Name for a [StorageZone]. 27 | * 28 | * @throws If the value is not a proper [StorageRegion]. 29 | */ 30 | export function name(value: StorageZone): string { 31 | return value.name; 32 | } 33 | 34 | /** 35 | * Give the associated Authentification header with it's content. 36 | */ 37 | export function key(value: StorageZone): [string, string] { 38 | return ["AccessKey", value.accessKey] 39 | } 40 | 41 | /** 42 | * Connect to an associated [StorageZone] 43 | * 44 | * ## Examples 45 | * 46 | * ### Listing files 47 | * 48 | * ```typescript 49 | * import * as process from "node:process"; 50 | * import * as BunnyStorageSDK from "@bunny.net/storage-sdk"; 51 | * 52 | * let sz_zone = process.env.STORAGE_ZONE; 53 | * let access_key = process.env.STORAGE_ACCESS_KEY; 54 | * 55 | * let region = BunnyStorageSDK.regions.StorageRegion.Falkenstein; 56 | * let sz = BunnyStorageSDK.zone.connect_with_accesskey(region, sz_zone, access_key); 57 | * 58 | * let list: BunnyStorageSDK.file.StorageFile[] = await BunnyStorageSDK.file.list(sz, "/"); 59 | * ``` 60 | * 61 | * 62 | */ 63 | export function connect_with_accesskey(region: Regions.StorageRegion, name: string, accessKey: string): StorageZone { 64 | return ({ 65 | _tag: "StorageZone", 66 | region, 67 | name, 68 | accessKey, 69 | }); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /libs/bunny-storage/tests/__snapshots__/integration.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Integration test with Storage Create Fail to create a proper file with invalid checksum: invalid_fail_file_1 1`] = `[Error: Unable to upload file. Either invalid path specified, either provided checksum invalid]`; 4 | 5 | exports[`Integration test with Storage List The list should be a single tests forlder 1`] = ` 6 | [ 7 | "tests", 8 | ] 9 | `; 10 | -------------------------------------------------------------------------------- /libs/bunny-storage/tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": [ 4 | "node_modules" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /libs/bunny-storage/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "nodenext", 5 | "lib": [ 6 | "esnext", 7 | "dom" 8 | ], 9 | "outDir": "./dist", 10 | "rootDir": "./src", 11 | "strict": true, 12 | "noImplicitAny": false, 13 | "esModuleInterop": false, 14 | "skipLibCheck": true, 15 | "allowImportingTsExtensions": true, 16 | "allowSyntheticDefaultImports": true, 17 | "noUnusedLocals": true, 18 | "noUnusedParameters": true, 19 | "downlevelIteration": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "suppressExcessPropertyErrors": false, 22 | "declaration": true, 23 | "sourceMap": false, 24 | "noEmitOnError": false 25 | }, 26 | "exclude": [ 27 | "dist", 28 | "esm", 29 | "node_modules", 30 | "**/*.test.*" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /libs/bunny-storage/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../../typedoc.base.jsonc" 4 | ], 5 | "entryPoints": [ 6 | "src/lib.ts" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /libs/bunny-storage/types/bunny.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The global BunnySDK available 3 | * @internal 4 | */ 5 | declare namespace Bunny { 6 | type BunnySDKV1 = { 7 | /** 8 | * Serve function 9 | */ 10 | serve: (handler: (request: Request) => Response | Promise) => void, 11 | /** 12 | * Serve PullZone function, to leverage middlewares 13 | */ 14 | registerMiddlewares: (middlewares: { 15 | onOriginRequest: Array<( 16 | ctx: { request: Request }, 17 | ) => Promise | Promise | undefined> 18 | onOriginResponse: Array<( 19 | ctx: { request: Request, response: Response }, 20 | ) => Promise | Promise | undefined> 21 | }) => void, 22 | }; 23 | 24 | export const v1: BunnySDKV1; 25 | 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bunny", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "preinstall": "npx only-allow pnpm", 7 | "build": "pnpm run -r build", 8 | "test": "pnpm run -r test", 9 | "release": "pnpm changeset publish && pnpm publish -r", 10 | "ci:version": "pnpm changeset version && pnpm i --lockfile-only", 11 | "ci:publish": "./scripts/publish.sh" 12 | }, 13 | "dependencies": { 14 | "typedoc": "0.26.1" 15 | }, 16 | "devDependencies": { 17 | "@changesets/cli": "^2.26.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'libs/bunny-sdk' 3 | - 'libs/bunny-storage' 4 | - 'example/simple-http-page' 5 | - 'example/deno-simple-http-page' 6 | - 'example/deno-middleware-http' 7 | - 'example/middleware-simple-http' 8 | -------------------------------------------------------------------------------- /scripts/build-doc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | repo_base=$(git rev-parse --show-toplevel) 4 | cd "$repo_base" 5 | 6 | echo "Creating doc for bunny-sdk" 7 | cd libs/bunny-sdk/ 8 | npx typedoc --json ../../docs-json/sdk-latest.json --options typedoc.json --validation.invalidLink false --name "$(cat package.json | jq -r '.name')/latest" --includeVersion true 9 | npx typedoc --json ../../docs-json/sdk-$(cat package.json | jq -r '.version').json --options typedoc.json --validation.invalidLink false --name $(cat package.json | jq -r '.name')/$(cat package.json | jq -r '.version') --includeVersion false 10 | 11 | cd "$repo_base" 12 | npx typedoc --entryPointStrategy merge "docs-json/*.json" 13 | -------------------------------------------------------------------------------- /scripts/publish.sh: -------------------------------------------------------------------------------- 1 | pnpm run -r build && pnpm changeset publish 2 | -------------------------------------------------------------------------------- /typedoc.base.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://typedoc.org/schema.json" 3 | } 4 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": [ 3 | "libs/*" 4 | ], 5 | "name": "Edge Script SDK Documentation", 6 | "entryPointStrategy": "packages", 7 | "includeVersion": false, 8 | "readme": "./README.md" 9 | } 10 | --------------------------------------------------------------------------------