@drstrain/sfetch
v0.1.1
Published
Internal TypeScript library for secured fetch over Bun with optional Unix socket transport
Readme
sFetch (Secured Fetch)
An internal TypeScript library for secure HTTP requests with Unix domain socket transport. The default Unix socket path is /tmp/request-hx.sock.
Publish
- Build the package:
bun run build - Optional dry run:
npm pack --dry-run - Publish to your registry:
- npm (scoped, restricted):
npm login npm publish --access restricted - Bun CLI:
bun login bun publish
- npm (scoped, restricted):
- To publish to a private registry (e.g. Verdaccio/GitHub Packages), set:
Then run the publish command for that registry.{ "publishConfig": { "registry": "https://your.registry.url/" } }
Quick Start
import { sFetch, DEFAULT_SOCKET_PATH } from "./index.ts";
async function main() {
const res = await sFetch("/health", {
// socketPath: '' // override default socket path, default is /tmp/request-hx.sock
// token: 'abc' // override env S_TOKEN
method: "POST",
});
console.log(res.status);
}
main();API
type SFetchInit = Omit<RequestInit, "headers"> & {
headers?: Headers | Array<[string, string]> | Record<string, string>;
useUnixSocket?: boolean;
socketPath?: string;
token?: string; // overrides env
urlBase?: string;
};
function sFetch(input: string | URL | Request, init?: SFetchInit): Promise<Response>;Token Header
- Reads an environment variable named
S_TOKENby default. - If the variable is missing, it sends
S_TOKEN: ''. - Override the env key via
process.S_TOKENor passtokendirectly.
Unix Socket Transport
- Default socket path is
/tmp/request-hx.sock. - Implementation options:
- Use
http+unixstyle URLs (e.g.http://unix:/tmp/request-hx.sock:/path) if supported by the runtime. - Open a Unix socket and write an HTTP request manually, then parse the response.
- Use
