diff --git a/types/is-deflate/.npmignore b/types/is-deflate/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/is-deflate/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/is-deflate/index.d.ts b/types/is-deflate/index.d.ts new file mode 100644 index 00000000000000..96e08a2045467c --- /dev/null +++ b/types/is-deflate/index.d.ts @@ -0,0 +1,3 @@ +export = is_deflate; + +declare function is_deflate(buf: Buffer | Uint8Array): boolean; diff --git a/types/is-deflate/is-deflate-tests.ts b/types/is-deflate/is-deflate-tests.ts new file mode 100644 index 00000000000000..44709609bfcc90 --- /dev/null +++ b/types/is-deflate/is-deflate-tests.ts @@ -0,0 +1,3 @@ +/// +import isDeflate from "is-deflate"; +isDeflate(Buffer.from("blah blah")); diff --git a/types/is-deflate/package.json b/types/is-deflate/package.json new file mode 100644 index 00000000000000..6e6df2483eb856 --- /dev/null +++ b/types/is-deflate/package.json @@ -0,0 +1,18 @@ +{ + "private": true, + "name": "@types/is-deflate", + "version": "1.0.9999", + "projects": [ + "https://github.com/watson/is-deflate#readme" + ], + "devDependencies": { + "@types/is-deflate": "workspace:.", + "@types/node": "*" + }, + "owners": [ + { + "name": "Matt Cowley", + "githubUsername": "MattIPv4" + } + ] +} diff --git a/types/is-deflate/tsconfig.json b/types/is-deflate/tsconfig.json new file mode 100644 index 00000000000000..f32666113fdf46 --- /dev/null +++ b/types/is-deflate/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "is-deflate-tests.ts" + ] +} diff --git a/types/node/node-tests/tls.ts b/types/node/node-tests/tls.ts index 84bfa124392eb1..5b72a0eabdbe0b 100644 --- a/types/node/node-tests/tls.ts +++ b/types/node/node-tests/tls.ts @@ -314,6 +314,33 @@ import { const r00ts: readonly string[] = rootCertificates; } +// Certificate DN fields are optional and can be string or string[] (multi-valued) +{ + const tlsSocket = connect({}); + const peerCert = tlsSocket.getPeerCertificate(); + const subject = peerCert.subject; + + // Fields are optional and may be string or string[] + const cn: string | string[] | undefined = subject.CN; + const ou: string | string[] | undefined = subject.OU; + const o: string | string[] | undefined = subject.O; + + // Type narrowing with Array.isArray + if (Array.isArray(subject.OU)) { + const ous: string[] = subject.OU; + } else { + const ou: string | undefined = subject.OU; + } + + // Arbitrary DN attributes via index signature + const email: string | string[] | undefined = subject["emailAddress"]; + const dc: string | string[] | undefined = subject["DC"]; + + // Issuer has the same shape + const issuer = peerCert.issuer; + const issuerCN: string | string[] | undefined = issuer.CN; +} + { const _options: TlsOptions = {}; const _server = new Server(_options, (socket) => {}); diff --git a/types/node/tls.d.ts b/types/node/tls.d.ts index 5c45f93774f058..635ee3e7ddebd9 100644 --- a/types/node/tls.d.ts +++ b/types/node/tls.d.ts @@ -15,31 +15,31 @@ declare module "node:tls" { import * as stream from "stream"; const CLIENT_RENEG_LIMIT: number; const CLIENT_RENEG_WINDOW: number; - interface Certificate { + interface Certificate extends NodeJS.Dict { /** * Country code. */ - C: string; + C?: string | string[]; /** * Street. */ - ST: string; + ST?: string | string[]; /** * Locality. */ - L: string; + L?: string | string[]; /** * Organization. */ - O: string; + O?: string | string[]; /** * Organizational unit. */ - OU: string; + OU?: string | string[]; /** * Common name. */ - CN: string; + CN?: string | string[]; } interface PeerCertificate { /** diff --git a/types/node/v20/test/tls.ts b/types/node/v20/test/tls.ts index 7d0298cca28178..c4fc7ebc4fbdf8 100644 --- a/types/node/v20/test/tls.ts +++ b/types/node/v20/test/tls.ts @@ -325,6 +325,33 @@ import { const r00ts: readonly string[] = rootCertificates; } +// Certificate DN fields are optional and can be string or string[] (multi-valued) +{ + const tlsSocket = connect({}); + const peerCert = tlsSocket.getPeerCertificate(); + const subject = peerCert.subject; + + // Fields are optional and may be string or string[] + const cn: string | string[] | undefined = subject.CN; + const ou: string | string[] | undefined = subject.OU; + const o: string | string[] | undefined = subject.O; + + // Type narrowing with Array.isArray + if (Array.isArray(subject.OU)) { + const ous: string[] = subject.OU; + } else { + const ou: string | undefined = subject.OU; + } + + // Arbitrary DN attributes via index signature + const email: string | string[] | undefined = subject["emailAddress"]; + const dc: string | string[] | undefined = subject["DC"]; + + // Issuer has the same shape + const issuer = peerCert.issuer; + const issuerCN: string | string[] | undefined = issuer.CN; +} + { const _options: TlsOptions = {}; const _server = new Server(_options, (socket) => {}); diff --git a/types/node/v20/tls.d.ts b/types/node/v20/tls.d.ts index 0b819a1779e450..7ecc2331f2f8a2 100644 --- a/types/node/v20/tls.d.ts +++ b/types/node/v20/tls.d.ts @@ -15,31 +15,31 @@ declare module "tls" { import * as stream from "stream"; const CLIENT_RENEG_LIMIT: number; const CLIENT_RENEG_WINDOW: number; - interface Certificate { + interface Certificate extends NodeJS.Dict { /** * Country code. */ - C: string; + C?: string | string[]; /** * Street. */ - ST: string; + ST?: string | string[]; /** * Locality. */ - L: string; + L?: string | string[]; /** * Organization. */ - O: string; + O?: string | string[]; /** * Organizational unit. */ - OU: string; + OU?: string | string[]; /** * Common name. */ - CN: string; + CN?: string | string[]; } interface PeerCertificate { /** diff --git a/types/node/v22/test/tls.ts b/types/node/v22/test/tls.ts index 29559361ad00e7..e587ab13f7ee42 100644 --- a/types/node/v22/test/tls.ts +++ b/types/node/v22/test/tls.ts @@ -329,6 +329,33 @@ import { const r00ts: readonly string[] = rootCertificates; } +// Certificate DN fields are optional and can be string or string[] (multi-valued) +{ + const tlsSocket = connect({}); + const peerCert = tlsSocket.getPeerCertificate(); + const subject = peerCert.subject; + + // Fields are optional and may be string or string[] + const cn: string | string[] | undefined = subject.CN; + const ou: string | string[] | undefined = subject.OU; + const o: string | string[] | undefined = subject.O; + + // Type narrowing with Array.isArray + if (Array.isArray(subject.OU)) { + const ous: string[] = subject.OU; + } else { + const ou: string | undefined = subject.OU; + } + + // Arbitrary DN attributes via index signature + const email: string | string[] | undefined = subject["emailAddress"]; + const dc: string | string[] | undefined = subject["DC"]; + + // Issuer has the same shape + const issuer = peerCert.issuer; + const issuerCN: string | string[] | undefined = issuer.CN; +} + { const _options: TlsOptions = {}; const _server = new Server(_options, (socket) => {}); diff --git a/types/node/v22/tls.d.ts b/types/node/v22/tls.d.ts index 84dc89f3b14e15..51770320bb5ee6 100644 --- a/types/node/v22/tls.d.ts +++ b/types/node/v22/tls.d.ts @@ -15,31 +15,31 @@ declare module "tls" { import * as stream from "stream"; const CLIENT_RENEG_LIMIT: number; const CLIENT_RENEG_WINDOW: number; - interface Certificate { + interface Certificate extends NodeJS.Dict { /** * Country code. */ - C: string; + C?: string | string[]; /** * Street. */ - ST: string; + ST?: string | string[]; /** * Locality. */ - L: string; + L?: string | string[]; /** * Organization. */ - O: string; + O?: string | string[]; /** * Organizational unit. */ - OU: string; + OU?: string | string[]; /** * Common name. */ - CN: string; + CN?: string | string[]; } interface PeerCertificate { /** diff --git a/types/node/v24/test/tls.ts b/types/node/v24/test/tls.ts index 29559361ad00e7..e587ab13f7ee42 100644 --- a/types/node/v24/test/tls.ts +++ b/types/node/v24/test/tls.ts @@ -329,6 +329,33 @@ import { const r00ts: readonly string[] = rootCertificates; } +// Certificate DN fields are optional and can be string or string[] (multi-valued) +{ + const tlsSocket = connect({}); + const peerCert = tlsSocket.getPeerCertificate(); + const subject = peerCert.subject; + + // Fields are optional and may be string or string[] + const cn: string | string[] | undefined = subject.CN; + const ou: string | string[] | undefined = subject.OU; + const o: string | string[] | undefined = subject.O; + + // Type narrowing with Array.isArray + if (Array.isArray(subject.OU)) { + const ous: string[] = subject.OU; + } else { + const ou: string | undefined = subject.OU; + } + + // Arbitrary DN attributes via index signature + const email: string | string[] | undefined = subject["emailAddress"]; + const dc: string | string[] | undefined = subject["DC"]; + + // Issuer has the same shape + const issuer = peerCert.issuer; + const issuerCN: string | string[] | undefined = issuer.CN; +} + { const _options: TlsOptions = {}; const _server = new Server(_options, (socket) => {}); diff --git a/types/node/v24/tls.d.ts b/types/node/v24/tls.d.ts index 1e51dabf37afee..db044ac01c4d72 100644 --- a/types/node/v24/tls.d.ts +++ b/types/node/v24/tls.d.ts @@ -15,31 +15,31 @@ declare module "tls" { import * as stream from "stream"; const CLIENT_RENEG_LIMIT: number; const CLIENT_RENEG_WINDOW: number; - interface Certificate { + interface Certificate extends NodeJS.Dict { /** * Country code. */ - C: string; + C?: string | string[]; /** * Street. */ - ST: string; + ST?: string | string[]; /** * Locality. */ - L: string; + L?: string | string[]; /** * Organization. */ - O: string; + O?: string | string[]; /** * Organizational unit. */ - OU: string; + OU?: string | string[]; /** * Common name. */ - CN: string; + CN?: string | string[]; } interface PeerCertificate { /**