@farcaster/hub-web 0.2.2 → 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 -8
- package/dist/index.d.ts +3 -5
- package/dist/index.js +30 -10384
- package/dist/index.mjs +29 -10383
- package/package.json +4 -3
package/README.md
CHANGED
@@ -4,7 +4,7 @@ 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.
|
@@ -19,24 +19,94 @@ yarn add @farcaster/hub-web
|
|
19
19
|
pnpm install @farcaster/hub-web
|
20
20
|
```
|
21
21
|
|
22
|
-
|
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
|
23
27
|
|
24
28
|
```typescript
|
25
29
|
import { getHubRpcClient } from '@farcaster/hub-web';
|
26
30
|
|
27
31
|
(async () => {
|
28
|
-
|
29
|
-
// const client = getHubRpcClient('https://testnet1.farcaster.xyz:2284', false);
|
32
|
+
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2285');
|
30
33
|
|
31
|
-
|
32
|
-
const client = getHubRpcClient('https://testnet1.farcaster.xyz:2284');
|
33
|
-
|
34
|
-
const castsResult = await client.getCastsByFid({ fid: 7884 });
|
34
|
+
const castsResult = await client.getCastsByFid({ fid: 15 });
|
35
35
|
|
36
36
|
castsResult.map((casts) => casts.messages.map((cast) => console.log(cast.data?.castAddBody?.text)));
|
37
37
|
})();
|
38
38
|
```
|
39
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
|
+
|
40
110
|
## Contributing
|
41
111
|
|
42
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
@@ -1,6 +1,7 @@
|
|
1
1
|
import { HubResult } from '@farcaster/core';
|
2
2
|
export * from '@farcaster/core';
|
3
3
|
import { grpc } from '@improbable-eng/grpc-web';
|
4
|
+
export { grpc } from '@improbable-eng/grpc-web';
|
4
5
|
import { Observable } from 'rxjs';
|
5
6
|
export { Observable } from 'rxjs';
|
6
7
|
import _m0 from 'protobufjs/minimal';
|
@@ -7880,13 +7881,10 @@ declare class GrpcWebError extends tsProtoGlobalThis.Error {
|
|
7880
7881
|
constructor(message: string, code: grpc.Code, metadata: grpc.Metadata);
|
7881
7882
|
}
|
7882
7883
|
|
7883
|
-
declare const Code: typeof grpc.Code;
|
7884
|
-
declare const Metadata: typeof grpc.Metadata;
|
7885
|
-
|
7886
7884
|
type OriginalUnaryCall<T, U> = (request: T, metadata?: grpc.Metadata) => Promise<U>;
|
7887
7885
|
type WrappedUnaryCall<T, U> = (request: T, metadata?: grpc.Metadata) => Promise<HubResult<U>>;
|
7888
7886
|
type OriginalStream<T, U> = (request: T, metadata?: grpc.Metadata) => Observable<U>;
|
7889
|
-
type WrappedStream<T, U> = (request: T, metadata?: grpc.Metadata) =>
|
7887
|
+
type WrappedStream<T, U> = (request: T, metadata?: grpc.Metadata) => HubResult<Observable<U>>;
|
7890
7888
|
type WrappedClient<C> = {
|
7891
7889
|
$: C;
|
7892
7890
|
} & {
|
@@ -7898,4 +7896,4 @@ type AdminRpcClient = WrappedClient<AdminService>;
|
|
7898
7896
|
declare const getAdminRpcClient: (url: string, isBrowser?: boolean) => AdminRpcClient;
|
7899
7897
|
declare const getAuthMetadata: (username: string, password: string) => grpc.Metadata;
|
7900
7898
|
|
7901
|
-
export { AdminRpcClient, AdminService, AdminServiceClientImpl, AdminServiceDeleteAllMessagesFromDbDesc, AdminServiceDesc, AdminServiceRebuildSyncTrieDesc, AdminServiceSubmitIdRegistryEventDesc, AdminServiceSubmitNameRegistryEventDesc,
|
7899
|
+
export { AdminRpcClient, AdminService, AdminServiceClientImpl, AdminServiceDeleteAllMessagesFromDbDesc, AdminServiceDesc, AdminServiceRebuildSyncTrieDesc, AdminServiceSubmitIdRegistryEventDesc, AdminServiceSubmitNameRegistryEventDesc, GrpcWebError, GrpcWebImpl, HubRpcClient, HubService, HubServiceClientImpl, HubServiceDesc, HubServiceGetAllCastMessagesByFidDesc, HubServiceGetAllMessagesBySyncIdsDesc, HubServiceGetAllReactionMessagesByFidDesc, HubServiceGetAllSignerMessagesByFidDesc, HubServiceGetAllSyncIdsByPrefixDesc, HubServiceGetAllUserDataMessagesByFidDesc, HubServiceGetAllVerificationMessagesByFidDesc, HubServiceGetCastDesc, HubServiceGetCastsByFidDesc, HubServiceGetCastsByMentionDesc, HubServiceGetCastsByParentDesc, HubServiceGetEventDesc, HubServiceGetFidsDesc, HubServiceGetIdRegistryEventByAddressDesc, HubServiceGetIdRegistryEventDesc, HubServiceGetInfoDesc, HubServiceGetNameRegistryEventDesc, HubServiceGetReactionDesc, HubServiceGetReactionsByCastDesc, HubServiceGetReactionsByFidDesc, HubServiceGetSignerDesc, HubServiceGetSignersByFidDesc, HubServiceGetSyncMetadataByPrefixDesc, HubServiceGetSyncSnapshotByPrefixDesc, HubServiceGetUserDataByFidDesc, HubServiceGetUserDataDesc, HubServiceGetVerificationDesc, HubServiceGetVerificationsByFidDesc, HubServiceSubmitMessageDesc, HubServiceSubscribeDesc, getAdminRpcClient, getAuthMetadata, getHubRpcClient };
|