Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bufbuild/connect-web

Package Overview
Dependencies
Maintainers
5
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bufbuild/connect-web - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

42

dist/cjs/grpc-web-transport.js

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

}, async (unaryRequest) => {
var _a, _b, _c, _d;
var _a, _b, _c;
const response = await fetch(unaryRequest.url, Object.assign(Object.assign({}, unaryRequest.init), { headers: unaryRequest.header, signal: unaryRequest.signal, body: createGrpcWebRequestBody(unaryRequest.message, options.binaryOptions) }));

@@ -55,10 +55,16 @@ const headError = (_c = (_b = (_a = extractHttpStatusError(response)) !== null && _a !== void 0 ? _a : extractContentTypeError(response.headers)) !== null && _b !== void 0 ? _b : extractDetailsError(response.headers, transportOptions.errorDetailRegistry)) !== null && _c !== void 0 ? _c : extractHeadersError(response.headers);

const reader = (0, envelope_js_1.createEnvelopeReadableStream)(response.body).getReader();
const messageResult = await reader.read();
if (messageResult.done) {
throw "missing message";
const messageOrTrailerResult = await reader.read();
if (messageOrTrailerResult.done) {
throw "premature eof";
}
if (messageResult.value.flags !== 0b00000000) {
if (messageOrTrailerResult.value.flags === trailerFlag) {
// Unary responses require exactly one response message, but in
// case of an error, it is perfectly valid to have a response body
// that only contains error trailers.
parseGrpcWebTrailerAndExtractError(messageOrTrailerResult.value.data, transportOptions.errorDetailRegistry);
// At this point, we received trailers only, but the trailers did
// not have an error status code.
throw "unexpected trailer";
}
const message = method.O.fromBinary(messageResult.value.data, transportOptions.binaryOptions);
const message = method.O.fromBinary(messageOrTrailerResult.value.data, transportOptions.binaryOptions);
const trailerResult = await reader.read();

@@ -68,10 +74,6 @@ if (trailerResult.done) {

}
if ((trailerResult.value.flags & trailerFlag) !== trailerFlag) {
if (trailerResult.value.flags !== trailerFlag) {
throw "missing trailer";
}
const trailer = parseGrpcWebTrailer(trailerResult.value.data);
const trailerError = (_d = extractDetailsError(trailer, transportOptions.errorDetailRegistry)) !== null && _d !== void 0 ? _d : extractHeadersError(trailer);
if (trailerError) {
throw trailerError;
}
const trailer = parseGrpcWebTrailerAndExtractError(trailerResult.value.data, transportOptions.errorDetailRegistry);
const eofResult = await reader.read();

@@ -130,3 +132,2 @@ if (!eofResult.done) {

async read() {
var _a;
const result = await reader.read();

@@ -144,7 +145,3 @@ if (result.done) {

endStreamReceived = true;
const trailer = parseGrpcWebTrailer(result.value.data);
const err = (_a = extractDetailsError(trailer, transportOptions.errorDetailRegistry)) !== null && _a !== void 0 ? _a : extractHeadersError(trailer);
if (err) {
throw err;
}
const trailer = parseGrpcWebTrailerAndExtractError(result.value.data, transportOptions.errorDetailRegistry);
trailer.forEach((value, key) => this.trailer.append(key, value));

@@ -272,2 +269,11 @@ return {

}
function parseGrpcWebTrailerAndExtractError(data, errorDetailRegistry) {
var _a;
const trailer = parseGrpcWebTrailer(data);
const err = (_a = extractDetailsError(trailer, errorDetailRegistry)) !== null && _a !== void 0 ? _a : extractHeadersError(trailer);
if (err) {
throw err;
}
return trailer;
}
function parseGrpcWebTrailer(data) {

@@ -274,0 +280,0 @@ const headers = new Headers();

@@ -46,5 +46,3 @@ "use strict";

function createServerStreamingFn(transport, service, method) {
// TODO there is no reason to return a promise here, we could simply return the async iterable right away
// eslint-disable-next-line @typescript-eslint/require-await
return async function (requestMessage, options) {
return function (requestMessage, options) {
let streamResponse;

@@ -51,0 +49,0 @@ return {

@@ -41,3 +41,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

}, async (unaryRequest) => {
var _a, _b, _c, _d;
var _a, _b, _c;
const response = await fetch(unaryRequest.url, Object.assign(Object.assign({}, unaryRequest.init), { headers: unaryRequest.header, signal: unaryRequest.signal, body: createGrpcWebRequestBody(unaryRequest.message, options.binaryOptions) }));

@@ -52,10 +52,16 @@ const headError = (_c = (_b = (_a = extractHttpStatusError(response)) !== null && _a !== void 0 ? _a : extractContentTypeError(response.headers)) !== null && _b !== void 0 ? _b : extractDetailsError(response.headers, transportOptions.errorDetailRegistry)) !== null && _c !== void 0 ? _c : extractHeadersError(response.headers);

const reader = createEnvelopeReadableStream(response.body).getReader();
const messageResult = await reader.read();
if (messageResult.done) {
throw "missing message";
const messageOrTrailerResult = await reader.read();
if (messageOrTrailerResult.done) {
throw "premature eof";
}
if (messageResult.value.flags !== 0b00000000) {
if (messageOrTrailerResult.value.flags === trailerFlag) {
// Unary responses require exactly one response message, but in
// case of an error, it is perfectly valid to have a response body
// that only contains error trailers.
parseGrpcWebTrailerAndExtractError(messageOrTrailerResult.value.data, transportOptions.errorDetailRegistry);
// At this point, we received trailers only, but the trailers did
// not have an error status code.
throw "unexpected trailer";
}
const message = method.O.fromBinary(messageResult.value.data, transportOptions.binaryOptions);
const message = method.O.fromBinary(messageOrTrailerResult.value.data, transportOptions.binaryOptions);
const trailerResult = await reader.read();

@@ -65,10 +71,6 @@ if (trailerResult.done) {

}
if ((trailerResult.value.flags & trailerFlag) !== trailerFlag) {
if (trailerResult.value.flags !== trailerFlag) {
throw "missing trailer";
}
const trailer = parseGrpcWebTrailer(trailerResult.value.data);
const trailerError = (_d = extractDetailsError(trailer, transportOptions.errorDetailRegistry)) !== null && _d !== void 0 ? _d : extractHeadersError(trailer);
if (trailerError) {
throw trailerError;
}
const trailer = parseGrpcWebTrailerAndExtractError(trailerResult.value.data, transportOptions.errorDetailRegistry);
const eofResult = await reader.read();

@@ -127,3 +129,2 @@ if (!eofResult.done) {

async read() {
var _a;
const result = await reader.read();

@@ -141,7 +142,3 @@ if (result.done) {

endStreamReceived = true;
const trailer = parseGrpcWebTrailer(result.value.data);
const err = (_a = extractDetailsError(trailer, transportOptions.errorDetailRegistry)) !== null && _a !== void 0 ? _a : extractHeadersError(trailer);
if (err) {
throw err;
}
const trailer = parseGrpcWebTrailerAndExtractError(result.value.data, transportOptions.errorDetailRegistry);
trailer.forEach((value, key) => this.trailer.append(key, value));

@@ -268,2 +265,11 @@ return {

}
function parseGrpcWebTrailerAndExtractError(data, errorDetailRegistry) {
var _a;
const trailer = parseGrpcWebTrailer(data);
const err = (_a = extractDetailsError(trailer, errorDetailRegistry)) !== null && _a !== void 0 ? _a : extractHeadersError(trailer);
if (err) {
throw err;
}
return trailer;
}
function parseGrpcWebTrailer(data) {

@@ -270,0 +276,0 @@ const headers = new Headers();

@@ -42,5 +42,3 @@ // Copyright 2021-2022 Buf Technologies, Inc.

function createServerStreamingFn(transport, service, method) {
// TODO there is no reason to return a promise here, we could simply return the async iterable right away
// eslint-disable-next-line @typescript-eslint/require-await
return async function (requestMessage, options) {
return function (requestMessage, options) {
let streamResponse;

@@ -47,0 +45,0 @@ return {

@@ -9,3 +9,3 @@ import type { MethodInfoServerStreaming, MethodInfoUnary, PartialMessage, ServiceType } from "@bufbuild/protobuf";

export declare type PromiseClient<T extends ServiceType> = {
[P in keyof T["methods"]]: T["methods"][P] extends MethodInfoUnary<infer I, infer O> ? (request: PartialMessage<I>, options?: CallOptions) => Promise<O> : T["methods"][P] extends MethodInfoServerStreaming<infer I, infer O> ? (request: PartialMessage<I>, options?: CallOptions) => Promise<AsyncIterable<O>> : never;
[P in keyof T["methods"]]: T["methods"][P] extends MethodInfoUnary<infer I, infer O> ? (request: PartialMessage<I>, options?: CallOptions) => Promise<O> : T["methods"][P] extends MethodInfoServerStreaming<infer I, infer O> ? (request: PartialMessage<I>, options?: CallOptions) => AsyncIterable<O> : never;
};

@@ -12,0 +12,0 @@ /**

{
"name": "@bufbuild/connect-web",
"version": "0.0.8",
"version": "0.0.9",
"license": "Apache-2.0",

@@ -25,3 +25,3 @@ "repository": {

"peerDependencies": {
"@bufbuild/protobuf": "^0.0.6"
"@bufbuild/protobuf": "^0.0.7"
},

@@ -28,0 +28,0 @@ "devDependencies": {

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