@farcaster/hub-web 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -10376
- package/dist/index.mjs +7 -10379
- package/package.json +3 -2
package/README.md
CHANGED
@@ -4,13 +4,11 @@ A lightweight, fast Typescript interface for Farcaster Hubs. Designed to work wi
|
|
4
4
|
|
5
5
|
## Features
|
6
6
|
|
7
|
-
- Call any Hub endpoint from browser environment
|
7
|
+
- Call any Hub endpoint from a browser environment using gRPC-Web.
|
8
8
|
- Serializes and deserializes Farcaster protobufs into Javascript objects.
|
9
9
|
- Has helpers to create and sign Farcaster messages.
|
10
10
|
- Written entirely in TypeScript, with strict types for safety.
|
11
11
|
|
12
|
-
APIs are the same as hub-nodejs (except client initialization). Read the [documentation](https://github.com/farcasterxyz/hubble/tree/main/packages/hub-nodejs/docs), see more [examples](https://github.com/farcasterxyz/hubble/tree/main/packages/hub-nodejs/examples) or get started with the guide below.
|
13
|
-
|
14
12
|
## Installation
|
15
13
|
|
16
14
|
Install @farcaster/hub-web with the package manager of your choice
|
@@ -21,24 +19,94 @@ yarn add @farcaster/hub-web
|
|
21
19
|
pnpm install @farcaster/hub-web
|
22
20
|
```
|
23
21
|
|
24
|
-
|
22
|
+
## Documentation
|
23
|
+
|
24
|
+
The @farcaster/hub-web APIs are largely the same as @farcaster/hub-nodejs. Read the [@farcaster/hub-nodejs documentation](https://github.com/farcasterxyz/hubble/tree/main/packages/hub-nodejs/docs) and browse code [examples](https://github.com/farcasterxyz/hubble/tree/main/packages/hub-nodejs/examples). We're also including sample @farcaster/hub-web code below as well as a list of differences with the other package.
|
25
|
+
|
26
|
+
### Getting start: fetching casts
|
25
27
|
|
26
28
|
```typescript
|
27
29
|
import { getHubRpcClient } from '@farcaster/hub-web';
|
28
30
|
|
29
31
|
(async () => {
|
30
|
-
|
31
|
-
// const client = getHubRpcClient('https://testnet1.farcaster.xyz:2284', false);
|
32
|
-
|
33
|
-
// if you are testing from a browser environment
|
34
|
-
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2284');
|
32
|
+
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2285');
|
35
33
|
|
36
|
-
const castsResult = await client.getCastsByFid({ fid:
|
34
|
+
const castsResult = await client.getCastsByFid({ fid: 15 });
|
37
35
|
|
38
36
|
castsResult.map((casts) => casts.messages.map((cast) => console.log(cast.data?.castAddBody?.text)));
|
39
37
|
})();
|
40
38
|
```
|
41
39
|
|
40
|
+
### Instantiating a client
|
41
|
+
|
42
|
+
The method to construct a Hub gRPC client differs from @farcaster/hub-nodejs. Use `getHubRpcClient`, which returns a Hub gRPC-Web client. Make sure that the gRPC server you're connecting to implements a gRPC-Web proxy. The standard is to expose the gRPC-Web proxy at port 2285.
|
43
|
+
|
44
|
+
#### Usage
|
45
|
+
|
46
|
+
```typescript
|
47
|
+
import { getHubRpcClient } from '@farcaster/hub-web';
|
48
|
+
|
49
|
+
(async () => {
|
50
|
+
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2285');
|
51
|
+
|
52
|
+
// If you're using gRPC-Web from a Nodejs environment, add a second false parameter
|
53
|
+
// const nodeClient = getHubRpcClient('https://testnet1.farcaster.xyz:2285', false);
|
54
|
+
})();
|
55
|
+
```
|
56
|
+
|
57
|
+
#### Returns
|
58
|
+
|
59
|
+
| Type | Description |
|
60
|
+
| :------------- | :------------------------------ |
|
61
|
+
| `HubRpcClient` | A new gRPC-Web Client instance. |
|
62
|
+
|
63
|
+
#### Parameters
|
64
|
+
|
65
|
+
| Name | Type | Description |
|
66
|
+
| :---------- | :-------- | :------------------------------------------------------------------------- |
|
67
|
+
| `url` | `string` | Address and RPC port string (e.g. `https://testnet1.farcaster.xyz:2285`) |
|
68
|
+
| `isBrowser` | `boolean` | Optional parameter indicating whether to use the gRPC-Web Nodejs transport |
|
69
|
+
|
70
|
+
### Streaming hub events
|
71
|
+
|
72
|
+
gRPC-Web hub event streams are instances of the [Observable class](https://rxjs.dev/guide/observable) in @farcaster/hub-web.
|
73
|
+
|
74
|
+
#### Usage
|
75
|
+
|
76
|
+
```typescript
|
77
|
+
import { getHubRpcClient } from '@farcaster/hub-web';
|
78
|
+
|
79
|
+
async () => {
|
80
|
+
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2285');
|
81
|
+
|
82
|
+
const result = client.subscribe({ eventTypes: [HubEventType.PRUNE_MESSAGE], fromId: 0 });
|
83
|
+
|
84
|
+
result.map((observable) => {
|
85
|
+
observable.subscribe({
|
86
|
+
next(event: HubEvent) {
|
87
|
+
console.log('received event', event);
|
88
|
+
},
|
89
|
+
error(err) {
|
90
|
+
console.error(err);
|
91
|
+
},
|
92
|
+
});
|
93
|
+
});
|
94
|
+
};
|
95
|
+
```
|
96
|
+
|
97
|
+
#### Returns
|
98
|
+
|
99
|
+
| Type | Description |
|
100
|
+
| :-------------------------------- | :---------------------------------------------------------------------------- |
|
101
|
+
| `HubResult<Observable<HubEvent>>` | An [Observable](https://rxjs.dev/guide/observable) stream wrapped in a Result |
|
102
|
+
|
103
|
+
#### Parameters
|
104
|
+
|
105
|
+
| Name | Type | Description |
|
106
|
+
| :----------- | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
107
|
+
| `fromId` | `number` | (Optional) ID of the hub event to start streaming from. A `fromId` of `0` will stream all events from the hub, and passing no `fromId` will start the stream from the present moment. |
|
108
|
+
| `eventTypes` | `HubEventType[]` | Array of hub event types to return. If `eventTypes` is `[]`, all event types will be returned. |
|
109
|
+
|
42
110
|
## Contributing
|
43
111
|
|
44
112
|
Please see our [contributing guidelines](https://github.com/farcasterxyz/hubble/blob/main/CONTRIBUTING.md) before making a pull request.
|
package/dist/index.d.ts
CHANGED
@@ -7884,7 +7884,7 @@ declare class GrpcWebError extends tsProtoGlobalThis.Error {
|
|
7884
7884
|
type OriginalUnaryCall<T, U> = (request: T, metadata?: grpc.Metadata) => Promise<U>;
|
7885
7885
|
type WrappedUnaryCall<T, U> = (request: T, metadata?: grpc.Metadata) => Promise<HubResult<U>>;
|
7886
7886
|
type OriginalStream<T, U> = (request: T, metadata?: grpc.Metadata) => Observable<U>;
|
7887
|
-
type WrappedStream<T, U> = (request: T, metadata?: grpc.Metadata) =>
|
7887
|
+
type WrappedStream<T, U> = (request: T, metadata?: grpc.Metadata) => HubResult<Observable<U>>;
|
7888
7888
|
type WrappedClient<C> = {
|
7889
7889
|
$: C;
|
7890
7890
|
} & {
|