Registry / devops / pbts-grpc-transcoder

pbts-grpc-transcoder

JSON →
library0.3.2jsnpmunverified

pbts-grpc-transcoder is a TypeScript library (v0.3.2) that provides gRPC-to-HTTP/1 JSON transcoding for protobuf.js, enabling fully-typed RPC calls over HTTP/1. It allows developers to make gRPC-style service calls using protobuf.js message types, which get automatically transcoded to HTTP/1 JSON requests based on google.api.http annotations in the service definition. Unlike envoy or grpc-gateway, this operates client-side, and is ideal for environments where HTTP/2 or gRPC-Web is unavailable. It requires protobuf.js as a peer dependency and uses a JSON descriptor file. Release cadence is low; no recent updates.

npm install pbts-grpc-transcoder
INSTALL
IMPORT
SIG · PBTS-GRPC-TRANSCOD
P
pbts-grpc-transcoder
devopsjavascriptv0.3.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GrpcTranscoder
import { GrpcTranscoder } from 'pbts-grpc-transcoder'
const GrpcTranscoder = require('pbts-grpc-transcoder').GrpcTranscoder
ESM-only; CJS require will not work.
default
import PbtsGrpcTranscoder from 'pbts-grpc-transcoder'
const PbtsGrpcTranscoder = require('pbts-grpc-transcoder')
Default export is available as ESM, but CJS fallback is not provided.
ServiceStub
import { ServiceStub } from 'pbts-grpc-transcoder'
Less commonly used; for creating stubs manually.

Sets up a GrpcTranscoder instance from a JSON descriptor and makes a typed RPC call.

import * as protobuf from 'protobufjs'; import { GrpcTranscoder } from 'pbts-grpc-transcoder'; import { readFileSync } from 'fs'; const descriptor = JSON.parse(readFileSync('./proto/descriptor.json', 'utf8')); const root = protobuf.Root.fromDescriptor(descriptor); const todoService = root.lookupService('todo.TodoService'); const transcoder = new GrpcTranscoder({ root, service: todoService, host: 'https://api.example.com', apiKey: process.env.API_KEY ?? '' }); const requestMessage = root.lookupType('todo.CreateTodoRequest'); const payload = requestMessage.create({ title: 'Test', completed: true }); transcoder .transcode('CreateTodo', payload) .then((response) => { console.log('Todo created:', response); }) .catch((err) => console.error(err));
Debug
Known issues
gotchaThe JSON descriptor must be generated with protobuf.js's pbjs tool; using another tool may produce incompatible output.
fix
Use `pbjs -t json your.proto > descriptor.json` to generate the descriptor.
affects: >=0.0.0
deprecatedThe constructor accepts `apiKey` as an option, but it is not documented; it's a custom header.
fix
Set custom headers via `headers` option instead for clarity.
affects: <=0.3.2
breakingVersion 0.2.0 changed the transcoder's `transcode` method signature: now returns Promise<protobuf.Message> instead of Promise<object>.
fix
Update code to handle protobuf.Message instances; call .toJSON() if plain object needed.
affects: >=0.2.0
breakingThe imported `ServiceStub` class was removed in v0.3.0; replaced by direct transcoder calls.
fix
Use GrpcTranscoder.transcode() instead of creating a stub.
affects: >=0.3.0
gotchaThe library does not automatically handle authentication; you must pass apiKey or headers.
fix
Always set `apiKey` or `headers` in the constructor.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Root must be a protobuf.Root instance.
Passing a plain JSON object instead of a protobuf.Root instance.
fix
Use protobuf.Root.fromDescriptor(descriptor) to create the Root.
TypeError: transcoder.transcode is not a function
Using an older version (<0.2.0) that had a different API or forgetting to instantiate the transcoder.
fix
Check that you're using v0.2.0+ and that transcoder is an instance of GrpcTranscoder.
Cannot find module 'pbts-grpc-transcoder'
Missing npm install or using CJS require on an ESM-only package.
fix
Use `import` syntax and ensure package is installed: `npm install pbts-grpc-transcoder`.
Error: No HTTP rule found for method 'CreateTodo'
The proto file does not have google.api.http annotations for the RPC.
fix
Add HTTP options to your proto definition and regenerate the descriptor.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
protobufjsrequiredPeer dependency; required for message types and serialization.
Agent activity
7 hits · last 30 days
node
6
Resources
pbts-grpc-transcoder — npm install pbts-grpc-transcoder · libregistry