New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

wrangler-proxy

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrangler-proxy

Wrangler Proxy for your favorite frameworks. Compatible with DrizzleORM

latest
Source
npmnpm
Version
2.2.7
Version published
Weekly downloads
35
52.17%
Maintainers
1
Weekly downloads
 
Created
Source

wrangler-proxy

Download Version

Wrangler Proxy exposes Workers API to outside and integrate to your favorite frameworks. Compatible with DrizzleORM.

Get Started

Install

npm i -D wrangler-proxy

Example wrangler.toml

name = "worker"
compatibility_date = "2023-07-02"

[[d1_databases]]
binding = "D1"
database_name = "D1"
database_id = "<d1-id>"

[[kv_namespaces]]
binding = "KV"
id = "<kv-id>"
preview_id = "<same-kv-id-as-above>"

[[services]]
binding = "WORKER"
service = "<worker-name>"
environment = "production"

Start proxy for dev

Remote mode

wrangler dev node_modules/wrangler-proxy/dist/worker.js --remote

Local mode

wrangler dev node_modules/wrangler-proxy/dist/worker.js

Example SvelteKit project

// file: app.d.ts

declare global {
  namespace App {
    interface Locals {
      D1: D1Database;
    }
    interface Platform {
      env?: {
        D1: D1Database;
      };
    }
  }
}

export {};
// file: src/hooks.server.ts

import { connectD1 } from 'wrangler-proxy';

export const handle = ({ event, resolve }) => {
  event.locals.D1 = event.platform?.env?.D1 ?? connectD1('D1');
  // or connectD1('D1', { hostname: 'custom-host-name' });
  // default hostname is `http://127.0.0.1:8787`
  return resolve(event);
};

Using wrangler-proxy to expose workers API

Init worker

npm create cloudflare@2 - .
// file: src/index.ts
import { createWorker } from 'wrangler-proxy';

export default createWorker();

Features

  • 😔 Need funding
  • 🤷 Not fully tested
  • ✅ Complete

D1

import { connectD1 } from 'wrangler-proxy';
FunctionStatus
prepare()
batch()
dump()😔
exec()

PreparedStatement

FunctionStatus
first()
run()
all()
raw()
bind()

Service Bindings

import { connectServiceBinding } from 'wrangler-proxy';
FunctionStatus
fetch()
connect()😔

app.d.ts

// app.d.ts

declare global {
  namespace App {
    interface Locals {
      SB: Fetcher;
    }
    interface Platform {
      env?: {
        SB: Fetcher;
      };
    }
  }
}

hooks.server.ts

/// hooks.server.ts

import { connectServiceBinding } from 'wrangler-proxy';

export const handle = async ({ resolve, event }) => {
  event.locals.SB = event.platform?.env?.SB ?? connectServiceBinding('SB');
  return resolve(event);
};

Example usage

event.locals.SB.fetch('http://whatever.fake/send');

http://whatever.fake is required as a dummy hostname. Without a dummy hostname the fetch will fail.

KV

import { connectKV } from 'wrangler-proxy';
FunctionStatus
put()🤷
get()
getWithMetadata()🤷
delete()
list()🤷

R2

import { connectR2 } from 'wrangler-proxy';
FunctionStatus
head()😔
get()
put()
createMultipartUpload()😔
resumeMultipartUpload()😔
delete()
list()😔

waitUntil

// file: app.d.ts
namespace App {
  interface Platform {
    context: {
      waitUntil(promise: Promise<any>): void;
    };
  }
}
// file: +page.server.ts
import { waitUntil } from 'wrangler-proxy';

export const actions = {
  default: ({ locals, platform }) => {
    waitUntil((async () => {})(), platform?.context);
    return { message: 'success' };
  },
};

Queues 😔

Hyperdrive 😔

Workers AI 😔

AI Gateway 😔

Stream 😔

Images 😔

Contributing

If you find this project helpful, consider supporting it by

Buy Me A Coffee

or

Donating via PayPal

Your donation will help us implement your requested features faster.

Keywords

workers

FAQs

Package last updated on 29 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts