Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin-anyone #3107

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/plugin-anyone/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "error"
},
"suspicious": {
"noExplicitAny": "error"
},
"style": {
"useConst": "error",
"useImportType": "off"
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "es5"
}
},
"files": {
"ignore": [
"dist/**/*",
"extra/**/*",
"node_modules/**/*"
]
}
}
7 changes: 6 additions & 1 deletion packages/plugin-anyone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"tsup": "8.3.5"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"vitest": "^1.2.1",
"@vitest/coverage-v8": "^1.2.1"
},
Expand All @@ -19,7 +20,11 @@
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
"test:coverage": "vitest run --coverage",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-anyone/src/actions/startAnyone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const startAnyone: Action = {
await proxyService.initialize();

_callback({
text: `Started Anyone`,
text: 'Started Anyone',
});

return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-anyone/src/actions/stopAnyone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const stopAnyone: Action = {
await AnyoneClientService.stop();

_callback({
text: `Stopped Anyone and cleaned up proxy`,
text: 'Stopped Anyone and cleaned up proxy',
});

return true;
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-anyone/src/services/AnyoneProxyService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { AnonSocksClient } from "@anyone-protocol/anyone-client";
import axios from "axios";
import type { AxiosDefaults, AxiosStatic } from "axios";
import { AnyoneClientService } from "./AnyoneClientService";

export class AnyoneProxyService {
private static instance: AnyoneProxyService | null = null;
private sockClient: AnonSocksClient | null = null;
private originalAxios: any = null;
private originalDefaults: any = null;
private originalAxios: Partial<AxiosStatic> | null = null;
private originalDefaults: Partial<AxiosDefaults> | null = null;

static getInstance(): AnyoneProxyService {
if (!AnyoneProxyService.instance) {
Expand All @@ -25,7 +26,7 @@ export class AnyoneProxyService {
this.sockClient = new AnonSocksClient(anon);

// Store original axios configuration
this.originalDefaults = { ...axios.defaults };
this.originalDefaults = { ...axios.defaults } as typeof axios.defaults;
this.originalAxios = {
request: axios.request,
get: axios.get,
Expand All @@ -39,7 +40,7 @@ export class AnyoneProxyService {
axios.defaults = {
...axios.defaults,
...this.sockClient.axios.defaults,
};
} as typeof axios.defaults;

// Apply proxy methods
axios.request = this.sockClient.axios.request.bind(
Expand All @@ -55,7 +56,7 @@ export class AnyoneProxyService {
cleanup(): void {
if (this.originalAxios && this.originalDefaults) {
// Create fresh axios defaults
axios.defaults = { ...this.originalDefaults };
axios.defaults = { ...this.originalDefaults } as typeof axios.defaults;

// Create fresh bindings
axios.request = this.originalAxios.request.bind(axios);
Expand Down
Loading