Skip to content
Closed
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
38 changes: 37 additions & 1 deletion lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare class PubNub extends PubNubCore<
* @throws An error if {@link PubNub} client already configured to use `keepAlive`.
* `keepAlive` and `proxy` can't be used simultaneously.
*/
setProxy(configuration?: NodeTransportProxyConfiguration): void;
setProxy(configuration?: PubNub.NodeTransportProxyConfiguration): void;
}

/**
Expand Down Expand Up @@ -2683,6 +2683,32 @@ declare namespace PubNub {
): Promise<PubNubFile | undefined>;
}

/**
* Proxy configuration accepted by {@link PubNub.setProxy}.
*
* This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers
* (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` proxy URI
* by the Node.js transport. A fully-formed proxy URI string is also accepted.
*
* **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent`
* does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable
* auto-detection. Only explicit HTTP/HTTPS proxies are handled here.
*/
export type NodeTransportProxyConfiguration =
| string
| {
/** Proxy host name (alias of {@link host}). */
hostname?: string;
/** Proxy host name. */
host?: string;
/** Proxy port. */
port?: number;
/** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */
protocol?: string;
/** Basic-auth credentials in `user:password` form. */
auth?: string;
};

/**
* NodeJS platform PubNub client configuration.
*/
Expand Down Expand Up @@ -7077,6 +7103,16 @@ declare namespace PubNub {
message: DataSyncData;
};

/**
* Extended DataSync change real-time event.
*
* Type extended for listener manager support.
*/
type DataSyncEvent = {
type: PubNubEventType.DataSync;
data: DataSyncObject;
};

/**
* Subscribe request parameters.
*/
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@types/lil-uuid": "^0.1.3",
"@types/mocha": "^9.1.1",
"@types/nock": "^9.3.1",
"@types/node": "^22.13.14",
"@types/node-fetch": "^2.6.11",
"@types/sinon": "^17.0.3",
"@types/text-encoding": "^0.0.39",
Expand Down
2 changes: 0 additions & 2 deletions src/core/types/api/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ export type DataSyncObject = Event & {
* Extended DataSync change real-time event.
*
* Type extended for listener manager support.
*
* @internal
*/
type DataSyncEvent = {
type: PubNubEventType.DataSync;
Expand Down
26 changes: 26 additions & 0 deletions src/node/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ import { ICryptoModule } from '../../core/interfaces/crypto-module';
const KEEP_ALIVE = false;
// endregion

/**
* Proxy configuration accepted by {@link PubNub.setProxy}.
*
* This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers
* (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` proxy URI
* by the Node.js transport. A fully-formed proxy URI string is also accepted.
*
* **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent`
* does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable
* auto-detection. Only explicit HTTP/HTTPS proxies are handled here.
*/
export type NodeTransportProxyConfiguration =
| string
| {
/** Proxy host name (alias of {@link host}). */
hostname?: string;
/** Proxy host name. */
host?: string;
/** Proxy port. */
port?: number;
/** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */
protocol?: string;
/** Basic-auth credentials in `user:password` form. */
auth?: string;
};

/**
* NodeJS platform PubNub client configuration.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { NodeCryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/module
import type { NodeCryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule';

import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration';
import { PubNubConfiguration, setDefaults } from './components/configuration';
import { PubNubConfiguration, NodeTransportProxyConfiguration, setDefaults } from './components/configuration';
import PubNubFile, { PubNubFileParameters } from '../file/modules/node';
import { CryptorConfiguration } from '../core/interfaces/crypto-module';
import { makeConfiguration } from '../core/components/configuration';
import { TokenManager } from '../core/components/token_manager';
import { Cryptography } from '../core/interfaces/cryptography';
import { NodeTransport, NodeTransportProxyConfiguration } from '../transport/node-transport';
import { NodeTransport } from '../transport/node-transport';
import { PubNubMiddleware } from '../transport/middleware';
import { PubNubFileConstructor } from '../core/types/file';
import { decode } from '../core/components/base64_codec';
Expand Down
27 changes: 1 addition & 26 deletions src/transport/node-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Agent, ProxyAgent, Dispatcher, buildConnector } from 'undici';
import { Buffer } from 'buffer';
import * as zlib from 'zlib';

import type { NodeTransportProxyConfiguration } from '../node/components/configuration';
import { CancellationController, TransportRequest } from '../core/types/transport-request';
import { Transport, TransportKeepAlive } from '../core/interfaces/transport';
import { TransportResponse } from '../core/types/transport-response';
Expand All @@ -18,32 +19,6 @@ import { PubNubAPIError } from '../errors/pubnub-api-error';
import { PubNubFileInterface } from '../core/types/file';
import { queryStringFromObject } from '../core/utils';

/**
* Proxy configuration accepted by {@link NodeTransport.setProxy}.
*
* This replaces the `proxy-agent` package's `ProxyAgentOptions`. The common fields used by callers
* (`hostname`/`host`, `port`, `protocol`, `auth`) are mapped onto an `undici` {@link ProxyAgent} URI
* by {@link NodeTransport.proxyAgentOptions}. A fully-formed proxy URI string is also accepted.
*
* **Known limitation (deferred to a later iteration):** unlike `proxy-agent`, `undici`'s `ProxyAgent`
* does not support SOCKS proxies, PAC files, or `HTTP(S)_PROXY`/`NO_PROXY` environment-variable
* auto-detection. Only explicit HTTP/HTTPS proxies are handled here.
*/
export type NodeTransportProxyConfiguration =
| string
| {
/** Proxy host name (alias of {@link host}). */
hostname?: string;
/** Proxy host name. */
host?: string;
/** Proxy port. */
port?: number;
/** Proxy protocol (`'http'` / `'https'`). Defaults to `http`. */
protocol?: string;
/** Basic-auth credentials in `user:password` form. */
auth?: string;
};

/**
* Class representing a `fetch`-based Node.js transport provider.
*
Expand Down
30 changes: 30 additions & 0 deletions test/release/declarations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import assert from 'assert';
import path from 'path';
import * as ts from 'typescript';

describe('published TypeScript declarations', () => {
it('type-checks the complete public bundle without skipLibCheck', function () {
this.timeout(30000);

const program = ts.createProgram([path.resolve(__dirname, '../../lib/types/index.d.ts')], {
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.NodeNext,
moduleResolution: ts.ModuleResolutionKind.NodeNext,
strict: true,
skipLibCheck: false,
noEmit: true,
types: ['node'],
});
const diagnostics = ts.getPreEmitDiagnostics(program);

assert.strictEqual(
diagnostics.length,
0,
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
getCanonicalFileName: (fileName) => fileName,
getCurrentDirectory: () => process.cwd(),
getNewLine: () => '\n',
}),
);
});
});