### Start Local Server with Hello World Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/README.md This example demonstrates how to set up a local server using the Bunny Edge SDK. It includes a basic 'Hello, Bunny Edge!' response and simulates processing delay. Ensure the SDK is installed. ```typescript import * as BunnySDK from "@bunny.net/edgescript-sdk"; function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } console.log("Starting server..."); BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { console.log(`[INFO]: ${req.method} - ${req.url}`); await sleep(1000); // Simulate some processing delay return new Response("Hello, Bunny Edge!"); }); ``` -------------------------------- ### Run the Example Application Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/form-upload/README.md Execute this command to start the Node.js server for the form upload example. After starting, access the application via the provided URL. ```bash npm start ``` -------------------------------- ### Install Dependencies Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/delete-file/README.md Run this command to install the necessary Node.js dependencies for the example. ```bash npm install ``` -------------------------------- ### Run the List Files Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/list-files/README.md Execute the script using npm start, providing an optional path to list files from. If no path is given, the root directory is listed. ```bash npm start -- /path/to/directory ``` -------------------------------- ### Run the Form Upload Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/form-upload/README.md Execute this Deno task to start the local server for the form upload example. Access the application at http://localhost:8080. ```bash deno task start ``` -------------------------------- ### Install Deno on Windows Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/file-info/README.md Use this PowerShell command to install Deno on Windows. ```powershell irm https://deno.land/install.ps1 | iex ``` -------------------------------- ### Initialize Theme and Show Page Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.ip.toString.html Sets the theme based on local storage and controls page display. Use this for initial page setup. ```javascript document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"; document.body.style.display="none"; setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500) ``` -------------------------------- ### Run Delete File Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/delete-file/README.md Execute the example script to delete a file. Provide the path to the file as a command-line argument. ```bash npm start -- /path/to/file.txt ``` -------------------------------- ### Run Download Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/download-file/README.md Execute the script to download a file from Bunny Storage. Provide the remote file path and the desired local path as arguments. ```bash npm start -- /remote/path/file.txt ./local-file.txt ``` -------------------------------- ### Run List Files Example with Deno Task Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/list-files/README.md Executes the list files example using Deno's task runner. Provide an optional path to list files from a specific directory; otherwise, it lists the root directory. ```bash deno task start /path/to/directory ``` -------------------------------- ### Install Deno on macOS/Linux Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-file/README.md Use this command to install Deno on macOS or Linux systems. ```bash # macOS/Linux curl -fsSL https://deno.land/install.sh | sh ``` -------------------------------- ### Install Deno on Windows Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-file/README.md Use this command to install Deno on Windows systems using PowerShell. ```powershell # Windows (PowerShell) irm https://deno.land/install.ps1 | iex ``` -------------------------------- ### Run Download File Example with Deno Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/download-file/README.md Executes the Deno task to download a file from Bunny Storage to a local path. Requires the remote file path and the desired local path as arguments. ```bash deno task start /remote/path/file.txt ./local-file.txt ``` -------------------------------- ### Run File Upload Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/file-upload/README.md Execute the Deno task to upload a local file to a specified remote path in Bunny Storage. Ensure environment variables are set before running. ```bash deno task start ./local-file.txt /remote/path/file.txt ``` -------------------------------- ### Run File Upload Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/file-upload/README.md Execute the script to upload a local file to a specified destination in Bunny Storage. Provide the local file path and the remote destination path as arguments. ```bash npm start -- ./local-file.txt /remote/path/file.txt ``` -------------------------------- ### HTTP Serve API Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.serve.html The serve function is used to start an HTTP server and handle incoming requests with a provided handler. ```APIDOC ## POST /api/users ### Description Creates a new user in the system. ### Method POST ### Endpoint /api/users ### Parameters #### Query Parameters - **limit** (number) - Optional - The maximum number of users to return. #### Request Body - **username** (string) - Required - The desired username. - **email** (string) - Required - The user's email address. ### Request Example ```json { "username": "john_doe", "email": "john.doe@example.com" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the newly created user. - **username** (string) - The username of the created user. #### Response Example ```json { "id": "user-12345", "username": "john_doe" } ``` ``` ```APIDOC ## serve(handler) ### Description Serves HTTP requests with the provided handler. ### Method Serve ### Endpoint N/A (Function call) ### Parameters #### Path Parameters - **handler** (net.http.ServerHandler) - Required - The handler function to process requests. ### Request Example ```typescript import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11"; console.log("Starting server..."); BunnySDK.net.http.serve(async (req) => { console.log(`[INFO]: ${req.method} - ${req.url}`); return new Response("Hello bunny!"); }); ``` ### Response #### Success Response (200) Returns a ServeHandler. #### Response Example ```typescript // ServeHandler object is returned ``` ``` ```APIDOC ## serve(listener, handler) ### Description Serves HTTP requests with the provided handler, listening on a specific host and port. ### Method Serve ### Endpoint N/A (Function call) ### Parameters #### Path Parameters - **listener** (object) - Required - An object containing hostname and port. - **hostname** (string) - Required - The hostname to listen on. - **port** (number) - Required - The port to listen on. - **handler** (net.http.ServerHandler) - Required - The handler function to process requests. ### Request Example ```typescript import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11"; const listener = { hostname: "localhost", port: 8080 }; BunnySDK.net.http.serve(listener, async (req) => { return new Response("Hello from specific port!"); }); ``` ### Response #### Success Response (200) Returns a ServeHandler. #### Response Example ```typescript // ServeHandler object is returned ``` ``` ```APIDOC ## serve(listener, handler) ### Description Serves HTTP requests with the provided handler, using a TcpListener. ### Method Serve ### Endpoint N/A (Function call) ### Parameters #### Path Parameters - **listener** (net.tcp.TcpListener) - Required - The TcpListener to use for accepting connections. - **handler** (net.http.ServerHandler) - Required - The handler function to process requests. ### Request Example ```typescript import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11"; // Assuming TcpListener is created elsewhere // const listener = new BunnySDK.net.tcp.TcpListener(...); // BunnySDK.net.http.serve(listener, async (req) => { // return new Response("Hello from TcpListener!"); // }); ``` ### Response #### Success Response (200) Returns a ServeHandler. #### Response Example ```typescript // ServeHandler object is returned ``` ``` -------------------------------- ### Run Delete Multiple Files Example Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-multiple-files/README.md Execute the Deno task to delete specified files from Bunny Storage. Provide the file paths as arguments. ```bash deno task start /file1.txt /file2.txt /folder/file3.txt ``` -------------------------------- ### Serve HTTP Requests Locally Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/index.html Starts an HTTP server to handle incoming requests. This function is intended for local development and debugging of edge scripts. It logs requests and returns a simple response. Ensure the SDK is imported correctly. ```typescript import * as BunnySDK from "@bunny.net/edgescript-sdk"; function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } console.log("Starting server..."); BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { console.log(`[INFO]: ${req.method} - ${req.url}`); await sleep(1); return new Response("blbl"); }); ``` -------------------------------- ### Get File Metadata Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Retrieves metadata for a specific file from a BunnyCDN Storage Zone. The returned object contains file details and a `data()` method to download the content. ```typescript import * as BunnyStorageSDK from "@bunny.net/storage-sdk"; let storageZone = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, "storage-zone-name", "token") let obj = await BunnyStorageSDK.file.get(storageZone, "/my-folder/my-file"); /* * Here obj will be equal to something like this: const obj = { Guid: '123', UserId: 'user1', LastChanged: '2023-01-01T00:00:00Z', DateCreated: '2022-01-01T00:00:00Z', StorageZoneName: 'test-zone', Path: '/test/path', ObjectName: 'test-file.txt', Length: 100, StorageZoneId: 1, IsDirectory: false, ServerId: 1, Checksum: 'abc123', ReplicatedZones: 'UK,NY', ContentType: 'text/plain', data: () => Promise<{ stream: ReadableStream; response: Response; length?: number; }>, }; */ ``` -------------------------------- ### List Files on Storage Zone with Local Server Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Sets up a local HTTP server to list files on a BunnyCDN Storage Zone using the Bunny Edge Scripting SDK and BunnyCDN Storage SDK. Requires STORAGE_ZONE and STORAGE_ACCESS_KEY environment variables. ```typescript import * as BunnySDK from "@bunny.net/edgescript-sdk"; import * as BunnyStorageSDK from "@bunny.net/storage-sdk"; let sz_zone = process.env.STORAGE_ZONE!; let access_key = process.env.STORAGE_ACCESS_KEY!; let sz = BunnyStorageSDK.zone.connect_with_accesskey(BunnyStorageSDK.regions.StorageRegion.Falkenstein, sz_zone, access_key); console.log("Starting server..."); BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => { let list = await BunnyStorageSDK.file.list(sz, "/"); console.log(`[INFO]: ${req.method} - ${req.url}`); return new Response(JSON.stringify(list)); }); ``` -------------------------------- ### Run Batch Upload Script Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/batch-upload/README.md Execute the script with the local directory to upload and the desired remote directory in Bunny Storage as arguments. ```bash npm start -- ./local-folder /remote-folder ``` -------------------------------- ### Run Batch Directory Upload Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/batch-upload/README.md Execute the Deno task to upload a local directory to a specified remote directory in Bunny Storage. The first argument is the local directory, and the second is the destination in Bunny Storage. ```bash deno task start ./local-folder /remote-folder ``` -------------------------------- ### servePullZone(options) Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.servePullZone.html Serves HTTP requests for a PullZone. Configures production and local development environments using the `url` option. ```APIDOC ## servePullZone(options) ### Description Serves HTTP requests for a PullZone. If you have an associated PullZone within Bunny, we'll use it on production and for local development you can configure it with the `url` option. ### Method servePullZone ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **options** (net.http.PullZoneHandlerOptions) - Required - Options for configuring the PullZone handler. ### Returns * **net.http.PullZoneHandler** - A PullZoneHandler instance. ### Example ```typescript import BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11.2"; console.log("Starting server..."); BunnySDK.net.http.servePullZone({ url: "https://echo.free.beeceptor.com/" }) .onOriginRequest( (ctx) => { const optFT = ctx.request.headers.get("feature-flags"); const featureFlags = optFT ? optFT.split(",").map((v) => v.trimStart()) : []; // Route-based matching and feature flag check const path = new URL(ctx.request.url).pathname; if (path === "/d") { if (!featureFlags.includes("route-d-preview")) { return Promise.resolve( new Response("You cannot use this route.", { status: 400 }), ); } } return Promise.resolve(ctx.request); }, ) .onOriginResponse((ctx) => { const response = ctx.response; response.headers.append("Via", "Custom"); return Promise.resolve(response); }); ``` ``` -------------------------------- ### Set Bunny Storage Environment Variables Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-file/README.md Configure the necessary environment variables for Bunny Storage authentication and zone identification. The region is optional and defaults to 'de'. ```bash export BUNNY_STORAGE_API_KEY="your-storage-api-key" export BUNNY_STORAGE_ZONE="your-storage-zone-name" export BUNNY_STORAGE_REGION="de" # Optional, defaults to "de" (Falkenstein) ``` -------------------------------- ### servePullZone(listener, options) Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.servePullZone.html Serves HTTP requests for a PullZone using a TCP listener and options. ```APIDOC ## servePullZone(listener, options) ### Description Serves HTTP requests for a PullZone using a TCP listener and options. ### Method servePullZone ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **listener** (net.tcp.TcpListener) - Required - A TCP listener instance. * **options** (net.http.PullZoneHandlerOptions) - Required - Options for configuring the PullZone handler. ### Returns * **net.http.PullZoneHandler** - A PullZoneHandler instance. ### Example ```typescript // Example usage for servePullZone with TcpListener import BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11.2"; // Assuming TcpListener is available and instantiated // const tcpListener = new BunnySDK.net.tcp.TcpListener(...); // BunnySDK.net.http.servePullZone(tcpListener, { // url: "https://example.com/" // }); ``` ``` -------------------------------- ### servePullZone(listener, options) Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.servePullZone.html Serves HTTP requests for a PullZone using a specified listener and options. ```APIDOC ## servePullZone(listener, options) ### Description Serves HTTP requests for a PullZone using a specified listener and options. ### Method servePullZone ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **listener** ({ hostname: string; port: number; }) - Required - An object containing the hostname and port for the listener. * **hostname** (string) - Required - The hostname for the listener. * **port** (number) - Required - The port for the listener. * **options** (net.http.PullZoneHandlerOptions) - Required - Options for configuring the PullZone handler. ### Returns * **net.http.PullZoneHandler** - A PullZoneHandler instance. ### Example ```typescript // Example usage for servePullZone with listener object import BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11.2"; const listener = { hostname: "localhost", port: 8080 }; BunnySDK.net.http.servePullZone(listener, { url: "https://example.com/" }); ``` ``` -------------------------------- ### Serve PullZone with URL Configuration Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.servePullZone.html Use this function to serve HTTP requests for a PullZone. Configure the PullZone URL for local development or production. It allows for custom request and response handling. ```typescript import BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11.2"; console.log("Starting server..."); BunnySDK.net.http.servePullZone({ url: "https://echo.free.beeceptor.com/" }) .onOriginRequest( (ctx) => { const optFT = ctx.request.headers.get("feature-flags"); const featureFlags = optFT ? optFT.split(",").map((v) => v.trimStart()) : []; // Route-based matching and feature flag check const path = new URL(ctx.request.url).pathname; if (path === "/d") { if (!featureFlags.includes("route-d-preview")) { return Promise.resolve( new Response("You cannot use this route.", { status: 400 }), ); } } return Promise.resolve(ctx.request); }, ) .onOriginResponse((ctx) => { const response = ctx.response; response.headers.append("Via", "Custom"); return Promise.resolve(response); }); ``` -------------------------------- ### Serve HTTP requests with a handler Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.http.serve.html Use this function to serve incoming HTTP requests. It requires a handler function that processes each request and returns a Response. Ensure the SDK is imported correctly. ```typescript import * as BunnySDK from "https://esm.sh/@bunny.net/edgescript-sdk@0.11"; console.log("Starting server..."); BunnySDK.net.http.serve(async (req) => { console.log(`[INFO]: ${req.method} - ${req.url}`); return new Response("Hello bunny!"); }); ``` -------------------------------- ### List Files in Storage Zone Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Lists files within a specified path in a BunnyCDN Storage Zone. Requires a pre-configured storage zone object. ```typescript let list = await BunnyStorageSDK.file.list(sz, "/"); ``` -------------------------------- ### serve Function Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.http.html The `serve` function is used to handle incoming HTTP requests within the Edge Script SDK. ```APIDOC ## serve ### Description Handles incoming HTTP requests. ### Method (Not specified, typically POST or GET depending on usage) ### Endpoint (Not specified, context-dependent within the SDK) ### Parameters (Specific parameters for `serve` are not detailed in the provided text, but it likely accepts a handler function.) ### Request Example (Not provided) ### Response (Not provided) ``` -------------------------------- ### Run File Deletion Task Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-file/README.md Execute the Deno task to delete a specified file from Bunny Storage. Replace '/path/to/file.txt' with the actual file path. ```bash deno task start /path/to/file.txt ``` -------------------------------- ### HTTP Module Overview Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.http.html The http namespace provides networking primitives for the HTTP(S) protocol. ```APIDOC ## Namespace http Networking Primitives for the HTTP(S) protocol. ### Type Aliases - **OriginRequestContext** - **OriginResponseContext** - **PullZoneHandler** - **PullZoneHandlerOptions** - **ServeHandler** - **ServerHandler** ### Functions - **serve**: Handles incoming HTTP requests. - **servePullZone**: Handles requests specifically for a pull zone. ``` -------------------------------- ### Download File Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Downloads a file from a BunnyCDN Storage Zone, returning a stream of the content and the HTTP response. Alternatively, the `data()` method on file metadata can be used. ```typescript export async function download(storageZone: StorageZone.StorageZone, path: string): Promise<{ stream: ReadableStream; response: Response; length?: number; }>; ``` ```typescript await BunnyStorageSDK.file.download(sz, "/some-file"); ``` -------------------------------- ### Run Delete Multiple Files Script Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/delete-multiple-files/README.md Execute the script to delete specified files from Bunny Storage. Pass the file paths as command-line arguments. ```bash npm start -- /file1.txt /file2.txt /folder/file3.txt ``` -------------------------------- ### Run the Delete Old Files Script Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/node/delete-old-files/README.md Execute the script with the target directory and the age in days for files to be deleted. The days argument defaults to 30 if not provided. ```bash npm start -- /backups 30 ``` -------------------------------- ### socketAddr Namespace Overview Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.socketAddr.html Provides an overview of the socketAddr namespace, including its sub-namespaces, classes, type aliases, and functions. ```APIDOC ## Namespace socketAddr * Defined in libs/bunny-sdk/src/net/socket_addr.ts:1 ### Index ### Namespaces * [v4](_bunny_net_edgescript_sdk_latest.net.socketAddr.v4.html) ### Classes * [InvalidAddr](../classes/_bunny_net_edgescript_sdk_latest.net.socketAddr.InvalidAddr.html) ### Type Aliases * [NoAddr](../types/_bunny_net_edgescript_sdk_latest.net.socketAddr.NoAddr.html) * [SocketAddr](../types/_bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddr.html) * [SocketAddrError](../types/_bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddrError.html) ### Functions * [isV4](../functions/_bunny_net_edgescript_sdk_latest.net.socketAddr.isV4.html) ``` -------------------------------- ### Upload File with Stream Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Uploads a file to a BunnyCDN Storage Zone using a ReadableStream. Supports optional SHA256 checksum and content type overrides. ```typescript export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream, options?: UploadOptions): Promise; export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream): Promise; export async function upload(storageZone: StorageZone.StorageZone, path: string, stream: ReadableStream, options?: UploadOptions): Promise; export type UploadOptions = { /** * The SHA256 Checksum associated to the data you want to send. If null then * the server will automatically calculate it. */ sha256Checksum?: string; /** * You can override the content-type of the file you upload with this option. */ contentType?: string; }; ``` ```typescript await BunnyStorageSDK.file.upload(sz, "/some-file", random_bytes_10kb); ``` -------------------------------- ### onOriginRequest Middleware Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.http.PullZoneHandler.html Allows you to add a middleware function to process incoming origin requests. The middleware receives an `OriginRequestContext` and can return a `Request` or `Response`. ```APIDOC ## POST /edge-script/middleware/onOriginRequest ### Description Adds a middleware for processing incoming origin requests. ### Method POST ### Endpoint /edge-script/middleware/onOriginRequest ### Parameters #### Request Body - **middleware** (function) - Required - A function that takes an `OriginRequestContext` and returns a `Promise` or `Promise`. - **ctx** (OriginRequestContext) - Required - The context object for the origin request. ### Response #### Success Response (200) - **PullZoneHandler** (object) - Returns a `PullZoneHandler` instance. ### Request Example ```json { "middleware": "(ctx) => Promise.resolve(ctx.request)" } ``` ### Response Example ```json { "handler": "..." } ``` ``` -------------------------------- ### IP Namespace Functions Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.ip.html Provides functions for working with IP addresses, including conversion to string and parsing from string. ```APIDOC ## Functions ### toString Converts an IP address to its string representation. ### Method (Implicitly a function call, not a direct HTTP method) ### Endpoint N/A (Client-side SDK function) ### Parameters (Specific parameters depend on the function's implementation, not detailed here) ### Request Example ```javascript // Example usage (hypothetical) ip.toString(someIpAddress); ``` ### Response #### Success Response - **string**: The string representation of the IP address. #### Response Example ```json { "example": "192.168.1.1" } ``` ### tryParseFromString Attempts to parse an IP address from a string. ### Method (Implicitly a function call, not a direct HTTP method) ### Endpoint N/A (Client-side SDK function) ### Parameters (Specific parameters depend on the function's implementation, not detailed here) ### Request Example ```javascript // Example usage (hypothetical) ip.tryParseFromString("192.168.1.1"); ``` ### Response #### Success Response - **IPv4 | null**: The parsed IPv4 address object if successful, otherwise null. #### Response Example ```json { "example": { "_value": "192.168.1.1" } } ``` ``` -------------------------------- ### net.tcp.unstable_new Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.tcp.unstable_new.html Creates a new TcpListener instance. This is an unstable new function. ```APIDOC ## unstable_new() ### Description Create a new [TcpListener]. ### Method N/A (Function Call) ### Endpoint N/A (Client-side SDK function) ### Returns - **TcpListener** (net.tcp.TcpListener) - A new TcpListener instance. ### Example ```typescript import { net } from '@bunny.net/edgescript-sdk/latest'; const listener = net.tcp.unstable_new(); ``` ``` -------------------------------- ### servePullZone Function Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.http.html The `servePullZone` function is designed to handle requests specifically for a pull zone. ```APIDOC ## servePullZone ### Description Handles requests specifically for a pull zone. ### Method (Not specified, typically POST or GET depending on usage) ### Endpoint (Not specified, context-dependent within the SDK) ### Parameters (Specific parameters for `servePullZone` are not detailed in the provided text, but it likely accepts handler options and a handler function.) ### Request Example (Not provided) ### Response (Not provided) ``` -------------------------------- ### net.tcp.bind Function Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.tcp.bind.html The bind function creates and returns a TcpListener bound to the specified network address. ```APIDOC ## net.tcp.bind Function ### Description Bind an Addr. This function creates a TCP listener and binds it to the provided network address. ### Method (Not explicitly defined, assumed to be a function call) ### Endpoint (Not applicable for SDK functions) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example (Not applicable for SDK functions) ### Response #### Success Response (200) - **TcpListener** (net.tcp.TcpListener) - A TcpListener object that is bound to the specified address. #### Response Example (Not explicitly defined, but would be an instance of TcpListener) ### Error Handling (Not explicitly defined in the provided text) ``` -------------------------------- ### Function tryParseFromString Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.ip.tryParseFromString.html Attempts to parse an IP address string into an IPv4 object. Returns an array of SyntaxError if parsing fails. ```APIDOC ## Function tryParseFromString ### Description Try to parse an IP address string. ### Method N/A (This is a function, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **ip** (net.ip.IPv4) - The parsed IPv4 address object. #### Response Example ```json { "ip": "192.168.1.1" } ``` #### Error Response - **SyntaxError[]** - An array of syntax errors encountered during parsing. ``` -------------------------------- ### onOriginResponse Middleware Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.http.PullZoneHandler.html Allows you to add a middleware function to process outgoing origin responses. The middleware receives an `OriginResponseContext` and must return a `Response`. ```APIDOC ## POST /edge-script/middleware/onOriginResponse ### Description Adds a middleware for processing outgoing origin responses. ### Method POST ### Endpoint /edge-script/middleware/onOriginResponse ### Parameters #### Request Body - **middleware** (function) - Required - A function that takes an `OriginResponseContext` and returns a `Promise`. - **ctx** (OriginResponseContext) - Required - The context object for the origin response. ### Response #### Success Response (200) - **PullZoneHandler** (object) - Returns a `PullZoneHandler` instance. ### Request Example ```json { "middleware": "(ctx) => Promise.resolve(ctx.response)" } ``` ### Response Example ```json { "handler": "..." } ``` ``` -------------------------------- ### Function isTcpListener Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.tcp.isTcpListener.html Checks if the provided value is an array of TcpListener objects. ```APIDOC ## Function isTcpListener ### Description Checks if the provided value is an array of TcpListener objects. ### Method N/A (This is a function, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **value** (net.tcp.TcpListener[]) - The input value to check. #### Response Example N/A ### Source Defined in libs/bunny-sdk/src/net/tcp.ts:13 ``` -------------------------------- ### v4 Namespace Functions Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.socketAddr.v4.html This section covers the functions available within the v4 namespace for managing IPv4 socket addresses. ```APIDOC ## v4 Namespace ### Description The `v4` namespace provides utilities for working with IPv4 socket addresses. ### Functions #### `ip(address: SocketAddrV4)` * **Description**: Retrieves the IP address from a `SocketAddrV4` structure. * **Type**: Function #### `port(address: SocketAddrV4)` * **Description**: Retrieves the port number from a `SocketAddrV4` structure. * **Type**: Function #### `tryFromString(address: string)` * **Description**: Attempts to parse a string into a `SocketAddrV4` structure. * **Type**: Function * **Parameters**: * `address` (string) - Required - The string representation of the IPv4 address and port (e.g., "192.168.1.1:8080"). * **Returns**: `SocketAddrV4 | null` - The parsed `SocketAddrV4` structure or null if parsing fails. ### Type Aliases #### `SocketAddrV4` * **Description**: Represents an IPv4 socket address, typically containing an IP address and a port number. * **Type**: Type Alias ``` -------------------------------- ### Run Delete Old Files Script Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/examples/deno/delete-old-files/README.md Execute the Deno task to delete files older than 30 days from the specified directory. You can provide a different number of days as the second argument. ```bash deno task start /backups 30 ``` -------------------------------- ### net.tcp.toString Function Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.tcp.toString.html Formats a TcpListener object to a string representation. ```APIDOC ## net.tcp.toString ### Description Formats the associated [TcpListener] to a String. ### Method N/A (This is a function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **string** - The string representation of the TcpListener. #### Response Example ```json ["192.168.1.1:8080", "10.0.0.1:80"] ``` ### Defined in libs/bunny-sdk/src/net/tcp.ts:27 ``` -------------------------------- ### TCP Namespace Functions Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.tcp.html This section provides documentation for the functions available within the TCP namespace of the Edge Script SDK. ```APIDOC ## TCP Namespace Functions ### Description Provides functions for network operations using TCP. ### Functions #### `bind(port: number, hostname?: string): Promise` * **Description**: Binds a TCP listener to a specified port and hostname. * **Method**: Not applicable (function call) * **Parameters**: * `port` (number) - Required - The port number to bind to. * `hostname` (string) - Optional - The hostname or IP address to bind to. #### `isTcpListener(listener: any): boolean` * **Description**: Checks if a given value is a valid TcpListener. * **Method**: Not applicable (function call) * **Parameters**: * `listener` (any) - Required - The value to check. #### `toString(listener: TcpListener): string` * **Description**: Returns a string representation of the TcpListener. * **Method**: Not applicable (function call) * **Parameters**: * `listener` (TcpListener) - Required - The TcpListener to convert to a string. #### `unstable_local_addr(listener: TcpListener): string` * **Description**: Gets the local address of the TcpListener. This function is unstable. * **Method**: Not applicable (function call) * **Parameters**: * `listener` (TcpListener) - Required - The TcpListener to get the local address from. #### `unstable_new(port: number, hostname?: string): Promise` * **Description**: Creates a new TCP listener. This function is unstable. * **Method**: Not applicable (function call) * **Parameters**: * `port` (number) - Required - The port number for the new listener. * `hostname` (string) - Optional - The hostname or IP address for the new listener. ### Type Aliases #### `TcpListener` * **Description**: Represents a TCP listener. * **Defined in**: `libs/bunny-sdk/src/net/tcp.ts:1` ``` -------------------------------- ### Remove Files or Directory Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md These functions allow you to remove files or entire directories from storage. ```APIDOC ## Remove Files or Directory ### Description Removes a file or directory from the specified storage zone. ### Methods - `remove(storageZone: StorageZone.StorageZone, path: string): Promise` - `removeDirectory(storageZone: StorageZone.StorageZone, path: string): Promise` ### Parameters #### Path Parameters - **storageZone** (StorageZone.StorageZone) - Required - The storage zone object. - **path** (string) - Required - The path to the file or directory to remove. ### Request Example ```typescript await BunnyStorageSDK.file.remove(sz, "/some-file"); await BunnyStorageSDK.file.removeDirectory(sz, "/some-directory"); ``` ### Response #### Success Response (200) - **boolean** - Returns `true` if the operation was successful, `false` otherwise. #### Response Example ```json true ``` ``` -------------------------------- ### Remove a Directory Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Use the `removeDirectory` function to delete a directory and all its contents from a storage zone. This operation is irreversible. ```typescript export async function removeDirectory(storageZone: StorageZone.StorageZone, path: string): Promise; ``` -------------------------------- ### Remove a File Source: https://github.com/bunnyway/edge-script-sdk/blob/main/libs/bunny-storage/README.md Use the `remove` function to delete a specific file from a storage zone. Ensure the path is correct to avoid errors. ```typescript export async function remove(storageZone: StorageZone.StorageZone, path: string): Promise; ``` ```typescript await BunnyStorageSDK.file.remove(sz, "/some-file"); ``` -------------------------------- ### SocketAddrError Type Alias Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.socketAddr.SocketAddrError.html Details of the SocketAddrError type alias, its definition, and where it is defined within the SDK. ```APIDOC ## SocketAddrError Type Alias ### Description Represents an error related to socket addresses, specifically an alias for `net.socketAddr.InvalidAddr`. ### Type Alias `SocketAddrError` ### Defined In `libs/bunny-sdk/src/net/socket_addr.ts:24` ### Type Definition `net.socketAddr.InvalidAddr` ``` -------------------------------- ### toString Function Signature Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.tcp.toString.html The toString function takes a TcpListener object as input and returns an array of strings. This is the signature for formatting TCP listener data. ```typescript toString(tcp: net.tcp.TcpListener): string[] ``` -------------------------------- ### IP Namespace Type Aliases Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.ip.html Defines types for representing IP addresses and ranges. ```APIDOC ### Type Aliases #### Enumerate Represents an enumeration of IP addresses. #### IPv4 Represents an IPv4 address. #### Range Represents a range of IP addresses. ``` -------------------------------- ### net.socketAddr.v4.tryFromString Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.socketAddr.v4.tryFromString.html Attempts to parse a string into a SocketAddrV4 object. This function is useful for validating and converting string representations of IPv4 addresses and ports into a structured format. ```APIDOC ## net.socketAddr.v4.tryFromString ### Description Try to parse a SocketAddrV4 from a string value. ### Method N/A (This is a function, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **SocketAddrV4** (object) - The parsed IPv4 address and port. - **SyntaxError** (object) - An array of errors if parsing fails. #### Response Example ```json { "success": true, "data": { "ip": "192.168.1.1", "port": 8080 } } ``` ```json { "success": false, "errors": [ { "message": "Invalid IP address format" } ] } ``` ``` -------------------------------- ### InvalidAddr Class Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/classes/_bunny_net_edgescript_sdk_latest.net.socketAddr.InvalidAddr.html Details about the InvalidAddr class, including its hierarchy, constructors, properties, and methods. ```APIDOC ## Class InvalidAddr #### Hierarchy * Error * InvalidAddr * Defined in libs/bunny-sdk/src/net/socket_addr.ts:27 ### Constructors * **new InvalidAddr(message: string)** * Constructs an instance of InvalidAddr. * **Parameters**: * `message` (string) - The error message. * **Returns**: `InvalidAddr` - An instance of InvalidAddr. * Overrides `Error.constructor`. * Defined in libs/bunny-sdk/src/net/socket_addr.ts:30 ### Properties * **_guard**: `symbol` * Internal guard symbol. * Defined in libs/bunny-sdk/src/net/socket_addr.ts:28 * **cause?**: `unknown` * Inherited from `Error.cause`. * Defined in node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es2022.error.d.ts:24 * **message**: `string` * Inherited from `Error.message`. * Defined in node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es5.d.ts:1077 * **name**: `string` * Inherited from `Error.name`. * Defined in node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es5.d.ts:1076 * **stack?**: `string` * Inherited from `Error.stack`. * Defined in node_modules/.pnpm/typescript@5.5.4/node_modules/typescript/lib/lib.es5.d.ts:1078 * **static prepareStackTrace?**: `((err: Error, stackTraces: CallSite[]) => any)` * Optional override for formatting stack traces. * See: [https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces) * Inherited from `Error.prepareStackTrace`. * Defined in node_modules/.pnpm/@types+node@20.14.15/node_modules/@types/node/globals.d.ts:28 * **static stackTraceLimit**: `number` * Inherited from `Error.stackTraceLimit`. * Defined in node_modules/.pnpm/@types+node@20.14.15/node_modules/@types/node/globals.d.ts:30 ### Methods * **toString()**: `string` * Returns a string representation of the object. * Defined in libs/bunny-sdk/src/net/socket_addr.ts:35 * **static captureStackTrace(targetObject: object, constructorOpt?: Function)**: `void` * Creates a `.stack` property on a target object. * **Parameters**: * `targetObject` (object) - The object to add the stack trace to. * `constructorOpt` (Function, optional) - The constructor to exclude from the stack trace. * Inherited from `Error.captureStackTrace`. * Defined in node_modules/.pnpm/@types+node@20.14.15/node_modules/@types/node/globals.d.ts:21 ### Settings * Member Visibility: * Protected * Inherited * External * Theme: * OS * Light * Dark ``` -------------------------------- ### PullZoneHandler API Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.http.PullZoneHandler.html Defines the structure and methods available for the PullZoneHandler, including event handlers for origin requests and responses. ```APIDOC ## PullZoneHandler ### Description Represents a handler for customizing the behavior of pull zones within the Edge Script SDK. It allows you to intercept and modify origin requests and responses. ### Methods #### `onOriginRequest(middleware)` Registers a middleware function to be executed before an origin request is made. The middleware receives an `OriginRequestContext` and can return a `Request` or `Response`. - **`middleware`** (function) - Required - A function that takes an `OriginRequestContext` and returns a `Promise` or `Promise`. #### `onOriginResponse(middleware)` Registers a middleware function to be executed before an origin response is returned. The middleware receives an `OriginResponseContext` and can return a `Response`. - **`middleware`** (function) - Required - A function that takes an `OriginResponseContext` and returns a `Promise`. ### Type Definition ```typescript PullZoneHandler: { onOriginRequest: (middleware: (ctx: OriginRequestContext) => Promise | Promise) => PullZoneHandler; onOriginResponse: (middleware: (ctx: OriginResponseContext) => Promise) => PullZoneHandler; } ``` ### Example Usage (Conceptual) ```javascript // Assuming 'net' and 'http' are imported from the SDK const handler = new net.http.PullZoneHandler(); handler.onOriginRequest(async (ctx) => { // Modify request headers, body, etc. const request = ctx.request; request.headers.set('X-Custom-Header', 'MyValue'); return request; }); handler.onOriginResponse(async (ctx) => { // Modify response headers, body, etc. const response = ctx.response; response.headers.set('X-Edge-Processed', 'true'); return response; }); // The handler would then be applied to a specific pull zone configuration. ``` ``` -------------------------------- ### PullZoneHandlerOptions Type Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.http.PullZoneHandlerOptions.html Defines the structure for options when handling pull zones in the Edge Script SDK. ```APIDOC ## PullZoneHandlerOptions Type Definition ### Description This type alias defines the structure for options related to pull zone handling within the Edge Script SDK. It specifies the necessary properties for configuring a pull zone handler. ### Type Alias `PullZoneHandlerOptions` ### Properties #### url (string) - **url** (string) - Required - The URL to be used for the pull zone handler. ``` -------------------------------- ### OriginRequestContext Type Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.http.OriginRequestContext.html Defines the structure of the OriginRequestContext object available in edge scripts. ```APIDOC ## Type Alias OriginRequestContext ### Description Represents the context of an incoming request at the edge. ### Type Definition ```typescript { request: Request; } ``` ### Fields * **request** (Request) - Required - The incoming `Request` object. ``` -------------------------------- ### socketAddr.InvalidAddr Class Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/modules/_bunny_net_edgescript_sdk_latest.net.socketAddr.html Represents an invalid socket address. ```APIDOC ## Class InvalidAddr Represents an invalid socket address. ### Signature * **new InvalidAddr**(_message_: string) ### Parameters * **_message** (string) - The error message describing why the address is invalid. ### Properties * **message** (string) - The error message. ``` -------------------------------- ### TcpListener Type Definition Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.tcp.TcpListener.html Provides the type definition for TcpListener, including its internal structure and properties. ```APIDOC ## TcpListener Type ### Description Represents a TCP listener, holding information about the network address it is bound to. ### Type Declaration * **`_tag`** (string) - Readonly, Internal - Indicates the type is 'TcpListener'. This is to prevent external construction. * **`addr`** (net.socketAddr.SocketAddr) - The network address the listener is bound to. ### Defined In `libs/bunny-sdk/src/net/tcp.ts:4` ``` -------------------------------- ### Convert IPv4 to String Array Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.ip.toString.html Converts an IPv4 address into an array of strings. This function is defined in `net/ip.ts`. ```typescript toString(ip): string[] ``` -------------------------------- ### net.ip.toString Function Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/functions/_bunny_net_edgescript_sdk_latest.net.ip.toString.html Converts an IP address to a string representation. This function is part of the network utilities in the Edge Script SDK. ```APIDOC ## net.ip.toString Function ### Description Converts an IP address to a string representation. ### Method N/A (This is a function call, not an HTTP method) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **string** - The string representation of the IP address. #### Response Example N/A ### Defined in libs/bunny-sdk/src/net/ip.ts:20 ``` -------------------------------- ### net.ip.Enumerate Type Alias Source: https://github.com/bunnyway/edge-script-sdk/blob/main/docs/types/_bunny_net_edgescript_sdk_latest.net.ip.Enumerate.html Details about the `Enumerate` type alias within the `net.ip` module, used for IP address enumeration. ```APIDOC ## Type Alias Enumerate ### Description Represents a type that enumerates IP addresses based on a number `N` and an accumulator `Acc`. ### Type Parameters * **N** (number) - Extends number. The number of items to enumerate. * **Acc** (number[]) - Defaults to `[]`. An array of numbers used as an accumulator. ### Source * Defined in libs/bunny-sdk/src/net/ip.ts:7 ```