Socket
Socket
Sign inDemoInstall

@grpc/grpc-js

Package Overview
Dependencies
Maintainers
3
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grpc/grpc-js - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

15

build/src/channel.js

@@ -79,2 +79,8 @@ "use strict";

}
/* This ensures that the target has a scheme that is registered with the
* resolver */
const defaultSchemeMapResult = resolver_1.mapUriDefaultScheme(originalTargetUri);
if (defaultSchemeMapResult === null) {
throw new Error(`Could not find a default scheme for target name "${target}"`);
}
if (this.options['grpc.default_authority']) {

@@ -84,12 +90,7 @@ this.defaultAuthority = this.options['grpc.default_authority'];

else {
this.defaultAuthority = resolver_1.getDefaultAuthority(originalTargetUri);
this.defaultAuthority = resolver_1.getDefaultAuthority(defaultSchemeMapResult);
}
const proxyMapResult = http_proxy_1.mapProxyName(originalTargetUri, options);
const proxyMapResult = http_proxy_1.mapProxyName(defaultSchemeMapResult, options);
this.target = proxyMapResult.target;
this.options = Object.assign({}, this.options, proxyMapResult.extraOptions);
const targetUri = uri_parser_1.parseUri(target);
if (targetUri === null) {
throw new Error(`Could not parse target name "${target}"`);
}
this.target = targetUri;
/* The global boolean parameter to getSubchannelPool has the inverse meaning to what

@@ -96,0 +97,0 @@ * the grpc.use_local_subchannel_pool channel option means. */

@@ -27,2 +27,3 @@ "use strict";

const uri_parser_1 = require("./uri-parser");
const url_1 = require("url");
const TRACER_NAME = 'proxy';

@@ -54,24 +55,26 @@ function trace(text) {

}
const proxyUrl = uri_parser_1.parseUri(proxyEnv);
if (proxyUrl === null) {
let proxyUrl;
try {
proxyUrl = new url_1.URL(proxyEnv);
}
catch (e) {
logging_1.log(constants_1.LogVerbosity.ERROR, `cannot parse value of "${envVar}" env var`);
return {};
}
if (proxyUrl.scheme !== 'http') {
logging_1.log(constants_1.LogVerbosity.ERROR, `"${proxyUrl.scheme}" scheme not supported in proxy URI`);
if (proxyUrl.protocol !== 'http:') {
logging_1.log(constants_1.LogVerbosity.ERROR, `"${proxyUrl.protocol}" scheme not supported in proxy URI`);
return {};
}
const splitPath = proxyUrl.path.split('@');
let host;
let userCred = null;
if (splitPath.length === 2) {
logging_1.log(constants_1.LogVerbosity.INFO, 'userinfo found in proxy URI');
userCred = splitPath[0];
host = splitPath[1];
if (proxyUrl.username) {
if (proxyUrl.password) {
logging_1.log(constants_1.LogVerbosity.INFO, 'userinfo found in proxy URI');
userCred = `${proxyUrl.username}:${proxyUrl.password}`;
}
else {
userCred = proxyUrl.username;
}
}
else {
host = proxyUrl.path;
}
const result = {
address: host,
address: proxyUrl.host,
};

@@ -127,3 +130,6 @@ if (userCred) {

return {
target: { path: proxyInfo.address },
target: {
scheme: 'dns',
path: proxyInfo.address
},
extraOptions: extraOptions,

@@ -130,0 +136,0 @@ };

@@ -230,5 +230,5 @@ "use strict";

resolver_1.registerResolver('dns', DnsResolver);
resolver_1.registerDefaultResolver(DnsResolver);
resolver_1.registerDefaultScheme('dns');
}
exports.setup = setup;
//# sourceMappingURL=resolver-dns.js.map

@@ -62,3 +62,3 @@ import { ServiceConfig } from './service-config';

*/
export declare function registerDefaultResolver(resolverClass: ResolverConstructor): void;
export declare function registerDefaultScheme(scheme: string): void;
/**

@@ -77,2 +77,3 @@ * Create a name resolver for the specified target, if possible. Throws an

export declare function getDefaultAuthority(target: GrpcUri): string;
export declare function mapUriDefaultScheme(target: GrpcUri): GrpcUri | null;
export declare function registerAll(): void;

@@ -23,3 +23,3 @@ "use strict";

const registeredResolvers = {};
let defaultResolver = null;
let defaultScheme = null;
/**

@@ -41,6 +41,6 @@ * Register a resolver class to handle target names prefixed with the `prefix`

*/
function registerDefaultResolver(resolverClass) {
defaultResolver = resolverClass;
function registerDefaultScheme(scheme) {
defaultScheme = scheme;
}
exports.registerDefaultResolver = registerDefaultResolver;
exports.registerDefaultScheme = registerDefaultScheme;
/**

@@ -57,12 +57,4 @@ * Create a name resolver for the specified target, if possible. Throws an

else {
if (defaultResolver !== null) {
/* If the scheme does not correspond to a registered scheme, we assume
* that the whole thing is the path, and the scheme was pulled out
* incorrectly. For example, it is valid to parse "localhost:80" as
* having a scheme of "localhost" and a path of 80, but that is not
* how the resolver should see it */
return new defaultResolver({ path: uri_parser_1.uriToString(target) }, listener);
}
throw new Error(`No resolver could be created for target ${uri_parser_1.uriToString(target)}`);
}
throw new Error(`No resolver could be created for target ${uri_parser_1.uriToString(target)}`);
}

@@ -80,10 +72,22 @@ exports.createResolver = createResolver;

else {
if (defaultResolver !== null) {
// See comment in createResolver for why we handle the target like this
return defaultResolver.getDefaultAuthority({ path: uri_parser_1.uriToString(target) });
throw new Error(`Invalid target ${uri_parser_1.uriToString(target)}`);
}
}
exports.getDefaultAuthority = getDefaultAuthority;
function mapUriDefaultScheme(target) {
if (target.scheme === undefined || !(target.scheme in registeredResolvers)) {
if (defaultScheme !== null) {
return {
scheme: defaultScheme,
authority: undefined,
path: uri_parser_1.uriToString(target)
};
}
else {
return null;
}
}
throw new Error(`Invalid target ${uri_parser_1.uriToString(target)}`);
return target;
}
exports.getDefaultAuthority = getDefaultAuthority;
exports.mapUriDefaultScheme = mapUriDefaultScheme;
function registerAll() {

@@ -90,0 +94,0 @@ resolver_dns.setup();

@@ -135,6 +135,10 @@ "use strict";

}
const portUri = uri_parser_1.parseUri(port);
if (portUri === null) {
const initialPortUri = uri_parser_1.parseUri(port);
if (initialPortUri === null) {
throw new Error(`Could not parse port "${port}"`);
}
const portUri = resolver_1.mapUriDefaultScheme(initialPortUri);
if (portUri === null) {
throw new Error(`Could not get a default scheme for port "${port}"`);
}
const serverOptions = {};

@@ -141,0 +145,0 @@ if ('grpc.max_concurrent_streams' in this.options) {

{
"name": "@grpc/grpc-js",
"version": "1.0.0",
"version": "1.0.1",
"description": "gRPC Library for Node - pure JS implementation",

@@ -5,0 +5,0 @@ "homepage": "https://grpc.io/",

@@ -24,5 +24,12 @@ # Pure JavaScript gRPC Client

This library does not directly handle `.proto` files. To use `.proto` files with this library we recommend using the `@grpc/proto-loader` package.
## Migrating from [`grpc`](https://www.npmjs.com/package/grpc)
`@grpc/grpc-js` is almost a drop-in replacement for `grpc`, but you may need to make a few code changes to use it:
- If you are currently loading `.proto` files using `grpc.load`, that function is not available in this library. You should instead load your `.proto` files using `@grpc/proto-loader` and load the resulting package definition objects into `@grpc/grpc-js` using `grpc.loadPackageDefinition`.
- If you are currently loading packages generated by `grpc-tools`, you should instead generate your files using the `--generate_package_definitions` option in `grpc-tools`, then load the object exported by the generated file into `@grpc/grpc-js` using `grpc.loadPackageDefinition`.
- If you have a server and you are using `Server#bind` to bind ports, you will need to use `Server#bindAsync` instead.
## Some Notes on API Guarantees

@@ -29,0 +36,0 @@

@@ -36,3 +36,3 @@ /*

import { CompressionFilterFactory } from './compression-filter';
import { getDefaultAuthority } from './resolver';
import { getDefaultAuthority, mapUriDefaultScheme } from './resolver';
import { ServiceConfig, validateServiceConfig } from './service-config';

@@ -174,16 +174,17 @@ import { trace, log } from './logging';

}
/* This ensures that the target has a scheme that is registered with the
* resolver */
const defaultSchemeMapResult = mapUriDefaultScheme(originalTargetUri);
if (defaultSchemeMapResult === null) {
throw new Error(`Could not find a default scheme for target name "${target}"`);
}
if (this.options['grpc.default_authority']) {
this.defaultAuthority = this.options['grpc.default_authority'] as string;
} else {
this.defaultAuthority = getDefaultAuthority(originalTargetUri);
this.defaultAuthority = getDefaultAuthority(defaultSchemeMapResult);
}
const proxyMapResult = mapProxyName(originalTargetUri, options);
const proxyMapResult = mapProxyName(defaultSchemeMapResult, options);
this.target = proxyMapResult.target;
this.options = Object.assign({}, this.options, proxyMapResult.extraOptions);
const targetUri = parseUri(target);
if (targetUri === null) {
throw new Error(`Could not parse target name "${target}"`);
}
this.target = targetUri;
/* The global boolean parameter to getSubchannelPool has the inverse meaning to what

@@ -190,0 +191,0 @@ * the grpc.use_local_subchannel_pool channel option means. */

@@ -32,2 +32,3 @@ /*

import { GrpcUri, parseUri, splitHostPort, uriToString } from './uri-parser';
import { URL } from 'url';

@@ -64,26 +65,27 @@ const TRACER_NAME = 'proxy';

}
const proxyUrl = parseUri(proxyEnv);
if (proxyUrl === null) {
let proxyUrl: URL;
try {
proxyUrl = new URL(proxyEnv);
} catch (e) {
log(LogVerbosity.ERROR, `cannot parse value of "${envVar}" env var`);
return {};
}
if (proxyUrl.scheme !== 'http') {
if (proxyUrl.protocol !== 'http:') {
log(
LogVerbosity.ERROR,
`"${proxyUrl.scheme}" scheme not supported in proxy URI`
`"${proxyUrl.protocol}" scheme not supported in proxy URI`
);
return {};
}
const splitPath = proxyUrl.path.split('@');
let host: string;
let userCred: string | null = null;
if (splitPath.length === 2) {
log(LogVerbosity.INFO, 'userinfo found in proxy URI');
userCred = splitPath[0];
host = splitPath[1];
} else {
host = proxyUrl.path;
if (proxyUrl.username) {
if (proxyUrl.password) {
log(LogVerbosity.INFO, 'userinfo found in proxy URI');
userCred = `${proxyUrl.username}:${proxyUrl.password}`;
} else {
userCred = proxyUrl.username;
}
}
const result: ProxyInfo = {
address: host,
address: proxyUrl.host,
};

@@ -150,3 +152,6 @@ if (userCred) {

return {
target: { path: proxyInfo.address },
target: {
scheme: 'dns',
path: proxyInfo.address
},
extraOptions: extraOptions,

@@ -153,0 +158,0 @@ };

@@ -21,3 +21,3 @@ /*

registerResolver,
registerDefaultResolver,
registerDefaultScheme,
} from './resolver';

@@ -285,3 +285,3 @@ import * as dns from 'dns';

registerResolver('dns', DnsResolver);
registerDefaultResolver(DnsResolver);
registerDefaultScheme('dns');
}

@@ -288,0 +288,0 @@

@@ -21,3 +21,2 @@ /*

registerResolver,
registerDefaultResolver,
} from './resolver';

@@ -24,0 +23,0 @@ import { SubchannelAddress } from './subchannel';

@@ -77,3 +77,3 @@ /*

const registeredResolvers: { [scheme: string]: ResolverConstructor } = {};
let defaultResolver: ResolverConstructor | null = null;
let defaultScheme: string | null = null;

@@ -99,4 +99,4 @@ /**

*/
export function registerDefaultResolver(resolverClass: ResolverConstructor) {
defaultResolver = resolverClass;
export function registerDefaultScheme(scheme: string) {
defaultScheme = scheme;
}

@@ -117,14 +117,6 @@

} else {
if (defaultResolver !== null) {
/* If the scheme does not correspond to a registered scheme, we assume
* that the whole thing is the path, and the scheme was pulled out
* incorrectly. For example, it is valid to parse "localhost:80" as
* having a scheme of "localhost" and a path of 80, but that is not
* how the resolver should see it */
return new defaultResolver({ path: uriToString(target) }, listener);
}
throw new Error(
`No resolver could be created for target ${uriToString(target)}`
);
}
throw new Error(
`No resolver could be created for target ${uriToString(target)}`
);
}

@@ -141,8 +133,19 @@

} else {
if (defaultResolver !== null) {
// See comment in createResolver for why we handle the target like this
return defaultResolver.getDefaultAuthority({ path: uriToString(target) });
throw new Error(`Invalid target ${uriToString(target)}`);
}
}
export function mapUriDefaultScheme(target: GrpcUri): GrpcUri | null {
if (target.scheme === undefined || !(target.scheme in registeredResolvers)) {
if (defaultScheme !== null) {
return {
scheme: defaultScheme,
authority: undefined,
path: uriToString(target)
};
} else {
return null;
}
}
throw new Error(`Invalid target ${uriToString(target)}`);
return target;
}

@@ -149,0 +152,0 @@

@@ -48,3 +48,3 @@ /*

import { ChannelOptions } from './channel-options';
import { createResolver, ResolverListener } from './resolver';
import { createResolver, ResolverListener, mapUriDefaultScheme } from './resolver';
import { log } from './logging';

@@ -230,6 +230,10 @@ import {

const portUri = parseUri(port);
if (portUri === null) {
const initialPortUri = parseUri(port);
if (initialPortUri === null) {
throw new Error(`Could not parse port "${port}"`);
}
const portUri = mapUriDefaultScheme(initialPortUri);
if (portUri === null) {
throw new Error(`Could not get a default scheme for port "${port}"`);
}

@@ -236,0 +240,0 @@ const serverOptions: http2.ServerOptions = {};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc