-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): publish grpc-bridge package
Signed-off-by: Norman Meier <norman@berty.tech>
- Loading branch information
Showing
7 changed files
with
147 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,76 @@ | ||
# `@berty/berty-store` | ||
# `@berty/grpc-bridge` | ||
|
||
> TODO: description | ||
Berty GRPC plumbing | ||
|
||
## Usage | ||
# Usage | ||
|
||
## React | ||
|
||
Tested with a raw `create-react-app` | ||
|
||
```sh | ||
yarn add '@berty/grpc-bridge@2.361.5' '@berty/api@2.361.1' '@improbable-eng/grpc-web@^0.15.0' 'google-protobuf@^3.14.0' | ||
``` | ||
|
||
```js | ||
import './App.css'; | ||
import beapi from "@berty/api" | ||
import { Service, rpcWeb, logger } from "@berty/grpc-bridge" | ||
import { grpc } from "@improbable-eng/grpc-web" | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<button onClick={async () => { | ||
const opts = { | ||
transport: grpc.CrossBrowserHttpTransport({ withCredentials: false }), | ||
host: "http://127.0.0.1:9091", | ||
} | ||
const rpc = rpcWeb(opts) | ||
const client = Service(beapi.messenger.MessengerService, rpc, logger.create('MESSENGER')) | ||
|
||
const accountReply = await client.accountGet({}) | ||
console.log("account", accountReply) | ||
|
||
const stream = await client.eventStream({}) | ||
stream.onMessage(msg => console.log("got msg:", msg)) | ||
stream.start() | ||
|
||
await client.accountUpdate({ displayName: "niceeee" }) | ||
}}> | ||
Test | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; | ||
``` | ||
const bertyStore = require('@berty/berty-store'); | ||
|
||
// TODO: DEMONSTRATE API | ||
## Node | ||
|
||
```sh | ||
yarn add '@berty/grpc-bridge@2.361.5' '@berty/api@2.361.1' '@improbable-eng/grpc-web@^0.15.0' '@improbable-eng/grpc-web-node-http-transport@^0.15.0' 'google-protobuf@^3.14.0' | ||
``` | ||
|
||
```js | ||
const beapi = require("@berty/api") | ||
const { Service, rpcWeb, logger } = require("@berty/grpc-bridge") | ||
const { NodeHttpTransport } = require('@improbable-eng/grpc-web-node-http-transport') | ||
|
||
const opts = { | ||
transport: NodeHttpTransport(), | ||
host: "http://127.0.0.1:9091", | ||
} | ||
const rpc = rpcWeb(opts) | ||
|
||
const client = Service(beapi.messenger.MessengerService, rpc, logger.create('MESSENGER')) | ||
|
||
client.eventStream({}).then(stream => { | ||
stream.onMessage(msg => console.log("msg:", msg)) | ||
stream.start().then((r) => { | ||
console.log("eventStream started:", r) | ||
client.accountUpdate({ displayName: "toto" }) | ||
}) | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import grpcBridge from './bridge' | ||
|
||
import rpcWeb from './rpc/rpc.grpcweb' | ||
import { logger } from './middleware' | ||
|
||
export type { GRPCBridge } from './bridge' | ||
export { ReactNativeTransport } from './grpc-web-react-native-transport' | ||
export { WebsocketTransport } from './grpc-web-websocket-transport' | ||
export { createService as Service } from './service' | ||
export { GRPCError, EOF } from './error' | ||
|
||
export { rpcWeb, logger } | ||
|
||
export default grpcBridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@berty/grpc-bridge", | ||
"version": "{{ .Version }}", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"repository": "https://github.com/berty/berty", | ||
"homepage": "https://github.com/berty/berty/tree/master/js/packages/grpc-bridge#readme", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepublish": "tsc" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@berty/api": "{{ .Version }}", | ||
"@improbable-eng/grpc-web": "^0.15.0", | ||
"base64-js": "^1.3.0", | ||
"lodash": "^4.14.178", | ||
"protobufjs": "^6.11.2" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.178", | ||
"typescript": "^4.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"allowJs": true, | ||
"isolatedModules": true, | ||
"moduleResolution": "node", | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters