@powersync/node 0.0.0-dev-20250417091221 → 0.0.0-dev-20250418125956

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,6 +56,22 @@ contains everything you need to know to get started implementing PowerSync in yo
56
56
 
57
57
  A simple example using `@powersync/node` is available in the [`demos/example-node/`](../demos/example-node) directory.
58
58
 
59
+ # Proxy Support
60
+
61
+ This SDK supports HTTP, HTTPS, and WebSocket proxies via environment variables.
62
+
63
+ ## HTTP Connection Method
64
+
65
+ Internally we probe the http environment variables and apply it to fetch requests ([undici](https://www.npmjs.com/package/undici/v/5.6.0))
66
+
67
+ - Set the `HTTPS_PROXY` or `HTTP_PROXY` environment variable to automatically route HTTP requests through a proxy.
68
+
69
+ ## WEB Socket Connection Method
70
+
71
+ Internally the [proxy-agent](https://www.npmjs.com/package/proxy-agent) dependency for WebSocket proxies, which has its own internal code for automatically picking up the appropriate environment variables:
72
+
73
+ - Set the `WS_PROXY` or `WSS_PROXY` environment variable to route the webocket connections through a proxy.
74
+
59
75
  # Found a bug or need help?
60
76
 
61
77
  - Join our [Discord server](https://discord.gg/powersync) where you can browse topics from our community, ask questions, share feedback, or just say hello :)
@@ -1,10 +1,13 @@
1
1
  import { ILogger } from 'js-logger';
2
2
  import { AbstractRemote, AbstractRemoteOptions, BSONImplementation, RemoteConnector } from '@powersync/common';
3
+ import { ProxyAgent } from 'undici';
3
4
  export declare const STREAMING_POST_TIMEOUT_MS = 30000;
4
5
  export declare class NodeRemote extends AbstractRemote {
5
6
  protected connector: RemoteConnector;
6
7
  protected logger: ILogger;
8
+ protected agent: ProxyAgent | undefined;
7
9
  constructor(connector: RemoteConnector, logger?: ILogger, options?: Partial<AbstractRemoteOptions>);
10
+ protected createSocket(url: string): globalThis.WebSocket;
8
11
  getUserAgent(): string;
9
12
  getBSON(): Promise<BSONImplementation>;
10
13
  }
@@ -1,6 +1,9 @@
1
1
  import * as os from 'node:os';
2
2
  import { AbstractRemote, DEFAULT_REMOTE_LOGGER, FetchImplementationProvider } from '@powersync/common';
3
3
  import { BSON } from 'bson';
4
+ import Agent from 'proxy-agent';
5
+ import { ProxyAgent } from 'undici';
6
+ import { WebSocket } from 'ws';
4
7
  export const STREAMING_POST_TIMEOUT_MS = 30_000;
5
8
  class NodeFetchProvider extends FetchImplementationProvider {
6
9
  getFetch() {
@@ -10,13 +13,32 @@ class NodeFetchProvider extends FetchImplementationProvider {
10
13
  export class NodeRemote extends AbstractRemote {
11
14
  connector;
12
15
  logger;
16
+ agent;
13
17
  constructor(connector, logger = DEFAULT_REMOTE_LOGGER, options) {
18
+ // Automatic env vars are not supported by undici
19
+ // proxy-agent does not work directly with dispatcher
20
+ const proxy = process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY;
21
+ const agent = proxy ? new ProxyAgent(proxy) : undefined;
14
22
  super(connector, logger, {
15
23
  ...(options ?? {}),
16
- fetchImplementation: options?.fetchImplementation ?? new NodeFetchProvider()
24
+ fetchImplementation: options?.fetchImplementation ?? new NodeFetchProvider(),
25
+ fetchOptions: {
26
+ dispatcher: agent
27
+ }
17
28
  });
18
29
  this.connector = connector;
19
30
  this.logger = logger;
31
+ this.agent = agent;
32
+ }
33
+ createSocket(url) {
34
+ return new WebSocket(url, {
35
+ // Undici does not seem to be compatible with ws, using `proxy-agent` instead.
36
+ // Automatically uses WS_PROXY or WSS_PROXY env vars
37
+ agent: new Agent.ProxyAgent(),
38
+ headers: {
39
+ 'User-Agent': this.getUserAgent()
40
+ }
41
+ }); // This is compatible in Node environments
20
42
  }
21
43
  getUserAgent() {
22
44
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/node",
3
- "version": "0.0.0-dev-20250417091221",
3
+ "version": "0.0.0-dev-20250418125956",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -36,14 +36,17 @@
36
36
  },
37
37
  "homepage": "https://docs.powersync.com/",
38
38
  "peerDependencies": {
39
- "@powersync/common": "0.0.0-dev-20250417091221"
39
+ "@powersync/common": "0.0.0-dev-20250418125956"
40
40
  },
41
41
  "dependencies": {
42
42
  "@powersync/better-sqlite3": "^0.1.1",
43
43
  "async-lock": "^1.4.0",
44
44
  "bson": "^6.6.0",
45
45
  "comlink": "^4.4.2",
46
- "@powersync/common": "0.0.0-dev-20250417091221"
46
+ "proxy-agent": "^6.5.0",
47
+ "undici": "^7.8.0",
48
+ "ws": "^8.18.1",
49
+ "@powersync/common": "0.0.0-dev-20250418125956"
47
50
  },
48
51
  "devDependencies": {
49
52
  "@types/async-lock": "^1.4.0",