First commit

This commit is contained in:
Aravind142857
2023-06-05 20:06:13 -05:00
commit 4e3c08d1c4
672 changed files with 179969 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import { URL } from 'whatwg-url';
import { redactConnectionString, ConnectionStringRedactionOptions } from './redact';
export { redactConnectionString, ConnectionStringRedactionOptions };
declare class CaseInsensitiveMap<K extends string = string> extends Map<K, string> {
delete(name: K): boolean;
get(name: K): string | undefined;
has(name: K): boolean;
set(name: K, value: any): this;
_normalizeKey(name: any): K;
}
declare abstract class URLWithoutHost extends URL {
abstract get host(): never;
abstract set host(value: never);
abstract get hostname(): never;
abstract set hostname(value: never);
abstract get port(): never;
abstract set port(value: never);
abstract get href(): string;
abstract set href(value: string);
}
export interface ConnectionStringParsingOptions {
looseValidation?: boolean;
}
export declare class ConnectionString extends URLWithoutHost {
_hosts: string[];
constructor(uri: string, options?: ConnectionStringParsingOptions);
get host(): never;
set host(_ignored: never);
get hostname(): never;
set hostname(_ignored: never);
get port(): never;
set port(_ignored: never);
get href(): string;
set href(_ignored: string);
get isSRV(): boolean;
get hosts(): string[];
set hosts(list: string[]);
toString(): string;
clone(): ConnectionString;
redact(options?: ConnectionStringRedactionOptions): ConnectionString;
typedSearchParams<T extends {}>(): {
append(name: keyof T & string, value: any): void;
delete(name: keyof T & string): void;
get(name: keyof T & string): string | null;
getAll(name: keyof T & string): string[];
has(name: keyof T & string): boolean;
set(name: keyof T & string, value: any): void;
keys(): IterableIterator<keyof T & string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[keyof T & string, string]>;
_normalizeKey(name: keyof T & string): string;
[Symbol.iterator](): IterableIterator<[keyof T & string, string]>;
sort(): void;
forEach<THIS_ARG = void>(callback: (this: THIS_ARG, value: string, name: string, searchParams: any) => void, thisArg?: THIS_ARG | undefined): void;
readonly [Symbol.toStringTag]: "URLSearchParams";
};
}
export declare class CommaAndColonSeparatedRecord<K extends {} = Record<string, unknown>> extends CaseInsensitiveMap<keyof K & string> {
constructor(from?: string | null);
toString(): string;
}
export default ConnectionString;

213
node_modules/mongodb-connection-string-url/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,213 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommaAndColonSeparatedRecord = exports.ConnectionString = exports.redactConnectionString = void 0;
const whatwg_url_1 = require("whatwg-url");
const redact_1 = require("./redact");
Object.defineProperty(exports, "redactConnectionString", { enumerable: true, get: function () { return redact_1.redactConnectionString; } });
const DUMMY_HOSTNAME = '__this_is_a_placeholder__';
function connectionStringHasValidScheme(connectionString) {
return (connectionString.startsWith('mongodb://') ||
connectionString.startsWith('mongodb+srv://'));
}
const HOSTS_REGEX = /^(?<protocol>[^/]+):\/\/(?:(?<username>[^:@]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^/?@]*)(?<rest>.*)/;
class CaseInsensitiveMap extends Map {
delete(name) {
return super.delete(this._normalizeKey(name));
}
get(name) {
return super.get(this._normalizeKey(name));
}
has(name) {
return super.has(this._normalizeKey(name));
}
set(name, value) {
return super.set(this._normalizeKey(name), value);
}
_normalizeKey(name) {
name = `${name}`;
for (const key of this.keys()) {
if (key.toLowerCase() === name.toLowerCase()) {
name = key;
break;
}
}
return name;
}
}
function caseInsenstiveURLSearchParams(Ctor) {
return class CaseInsenstiveURLSearchParams extends Ctor {
append(name, value) {
return super.append(this._normalizeKey(name), value);
}
delete(name) {
return super.delete(this._normalizeKey(name));
}
get(name) {
return super.get(this._normalizeKey(name));
}
getAll(name) {
return super.getAll(this._normalizeKey(name));
}
has(name) {
return super.has(this._normalizeKey(name));
}
set(name, value) {
return super.set(this._normalizeKey(name), value);
}
keys() {
return super.keys();
}
values() {
return super.values();
}
entries() {
return super.entries();
}
[Symbol.iterator]() {
return super[Symbol.iterator]();
}
_normalizeKey(name) {
return CaseInsensitiveMap.prototype._normalizeKey.call(this, name);
}
};
}
class URLWithoutHost extends whatwg_url_1.URL {
}
class MongoParseError extends Error {
get name() {
return 'MongoParseError';
}
}
class ConnectionString extends URLWithoutHost {
constructor(uri, options = {}) {
var _a;
const { looseValidation } = options;
if (!looseValidation && !connectionStringHasValidScheme(uri)) {
throw new MongoParseError('Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"');
}
const match = uri.match(HOSTS_REGEX);
if (!match) {
throw new MongoParseError(`Invalid connection string "${uri}"`);
}
const { protocol, username, password, hosts, rest } = (_a = match.groups) !== null && _a !== void 0 ? _a : {};
if (!looseValidation) {
if (!protocol || !hosts) {
throw new MongoParseError(`Protocol and host list are required in "${uri}"`);
}
try {
decodeURIComponent(username !== null && username !== void 0 ? username : '');
decodeURIComponent(password !== null && password !== void 0 ? password : '');
}
catch (err) {
throw new MongoParseError(err.message);
}
const illegalCharacters = /[:/?#[\]@]/gi;
if (username === null || username === void 0 ? void 0 : username.match(illegalCharacters)) {
throw new MongoParseError(`Username contains unescaped characters ${username}`);
}
if (!username || !password) {
const uriWithoutProtocol = uri.replace(`${protocol}://`, '');
if (uriWithoutProtocol.startsWith('@') || uriWithoutProtocol.startsWith(':')) {
throw new MongoParseError('URI contained empty userinfo section');
}
}
if (password === null || password === void 0 ? void 0 : password.match(illegalCharacters)) {
throw new MongoParseError('Password contains unescaped characters');
}
}
let authString = '';
if (typeof username === 'string')
authString += username;
if (typeof password === 'string')
authString += `:${password}`;
if (authString)
authString += '@';
try {
super(`${protocol.toLowerCase()}://${authString}${DUMMY_HOSTNAME}${rest}`);
}
catch (err) {
if (looseValidation) {
new ConnectionString(uri, {
...options,
looseValidation: false
});
}
if (typeof err.message === 'string') {
err.message = err.message.replace(DUMMY_HOSTNAME, hosts);
}
throw err;
}
this._hosts = hosts.split(',');
if (!looseValidation) {
if (this.isSRV && this.hosts.length !== 1) {
throw new MongoParseError('mongodb+srv URI cannot have multiple service names');
}
if (this.isSRV && this.hosts.some(host => host.includes(':'))) {
throw new MongoParseError('mongodb+srv URI cannot have port number');
}
}
if (!this.pathname) {
this.pathname = '/';
}
Object.setPrototypeOf(this.searchParams, caseInsenstiveURLSearchParams(this.searchParams.constructor).prototype);
}
get host() { return DUMMY_HOSTNAME; }
set host(_ignored) { throw new Error('No single host for connection string'); }
get hostname() { return DUMMY_HOSTNAME; }
set hostname(_ignored) { throw new Error('No single host for connection string'); }
get port() { return ''; }
set port(_ignored) { throw new Error('No single host for connection string'); }
get href() { return this.toString(); }
set href(_ignored) { throw new Error('Cannot set href for connection strings'); }
get isSRV() {
return this.protocol.includes('srv');
}
get hosts() {
return this._hosts;
}
set hosts(list) {
this._hosts = list;
}
toString() {
return super.toString().replace(DUMMY_HOSTNAME, this.hosts.join(','));
}
clone() {
return new ConnectionString(this.toString(), {
looseValidation: true
});
}
redact(options) {
return (0, redact_1.redactValidConnectionString)(this, options);
}
typedSearchParams() {
const sametype = false && new (caseInsenstiveURLSearchParams(whatwg_url_1.URLSearchParams))();
return this.searchParams;
}
[Symbol.for('nodejs.util.inspect.custom')]() {
const { href, origin, protocol, username, password, hosts, pathname, search, searchParams, hash } = this;
return { href, origin, protocol, username, password, hosts, pathname, search, searchParams, hash };
}
}
exports.ConnectionString = ConnectionString;
class CommaAndColonSeparatedRecord extends CaseInsensitiveMap {
constructor(from) {
super();
for (const entry of (from !== null && from !== void 0 ? from : '').split(',')) {
if (!entry)
continue;
const colonIndex = entry.indexOf(':');
if (colonIndex === -1) {
this.set(entry, '');
}
else {
this.set(entry.slice(0, colonIndex), entry.slice(colonIndex + 1));
}
}
}
toString() {
return [...this].map(entry => entry.join(':')).join(',');
}
}
exports.CommaAndColonSeparatedRecord = CommaAndColonSeparatedRecord;
exports.default = ConnectionString;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import ConnectionString from './index';
export interface ConnectionStringRedactionOptions {
redactUsernames?: boolean;
replacementString?: string;
}
export declare function redactValidConnectionString(inputUrl: Readonly<ConnectionString>, options?: ConnectionStringRedactionOptions): ConnectionString;
export declare function redactConnectionString(uri: string, options?: ConnectionStringRedactionOptions): string;

View File

@@ -0,0 +1,86 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.redactConnectionString = exports.redactValidConnectionString = void 0;
const index_1 = __importStar(require("./index"));
function redactValidConnectionString(inputUrl, options) {
var _a, _b;
const url = inputUrl.clone();
const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : '_credentials_';
const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;
if ((url.username || url.password) && redactUsernames) {
url.username = replacementString;
url.password = '';
}
else if (url.password) {
url.password = replacementString;
}
if (url.searchParams.has('authMechanismProperties')) {
const props = new index_1.CommaAndColonSeparatedRecord(url.searchParams.get('authMechanismProperties'));
if (props.get('AWS_SESSION_TOKEN')) {
props.set('AWS_SESSION_TOKEN', replacementString);
url.searchParams.set('authMechanismProperties', props.toString());
}
}
if (url.searchParams.has('tlsCertificateKeyFilePassword')) {
url.searchParams.set('tlsCertificateKeyFilePassword', replacementString);
}
if (url.searchParams.has('proxyUsername') && redactUsernames) {
url.searchParams.set('proxyUsername', replacementString);
}
if (url.searchParams.has('proxyPassword')) {
url.searchParams.set('proxyPassword', replacementString);
}
return url;
}
exports.redactValidConnectionString = redactValidConnectionString;
function redactConnectionString(uri, options) {
var _a, _b;
const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : '<credentials>';
const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;
let parsed;
try {
parsed = new index_1.default(uri);
}
catch (_c) { }
if (parsed) {
options = { ...options, replacementString: '___credentials___' };
return parsed.redact(options).toString().replace(/___credentials___/g, replacementString);
}
const R = replacementString;
const replacements = [
uri => uri.replace(redactUsernames ? /(\/\/)(.*)(@)/g : /(\/\/[^@]*:)(.*)(@)/g, `$1${R}$3`),
uri => uri.replace(/(AWS_SESSION_TOKEN(:|%3A))([^,&]+)/gi, `$1${R}`),
uri => uri.replace(/(tlsCertificateKeyFilePassword=)([^&]+)/gi, `$1${R}`),
uri => redactUsernames ? uri.replace(/(proxyUsername=)([^&]+)/gi, `$1${R}`) : uri,
uri => uri.replace(/(proxyPassword=)([^&]+)/gi, `$1${R}`)
];
for (const replacer of replacements) {
uri = replacer(uri);
}
return uri;
}
exports.redactConnectionString = redactConnectionString;
//# sourceMappingURL=redact.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAyE;AAOzE,SAAgB,2BAA2B,CACzC,QAAoC,EACpC,OAA0C;;IAC1C,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC7B,MAAM,iBAAiB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,eAAe,CAAC;IACxE,MAAM,eAAe,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,IAAI,CAAC;IAEzD,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,GA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