@towns-labs/react-sdk 2.0.1
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 +69 -0
- package/dist/esm/TownsSyncProvider.jsx +39 -0
- package/dist/esm/TownsSyncProvider.jsx.map +1 -0
- package/dist/esm/connectTowns.js +45 -0
- package/dist/esm/connectTowns.js.map +1 -0
- package/dist/esm/index.js +35 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internals/TownsSyncContext.js +4 -0
- package/dist/esm/internals/TownsSyncContext.js.map +1 -0
- package/dist/esm/internals/useAction.js +58 -0
- package/dist/esm/internals/useAction.js.map +1 -0
- package/dist/esm/internals/useTownsSync.js +5 -0
- package/dist/esm/internals/useTownsSync.js.map +1 -0
- package/dist/esm/internals/utils.js +10 -0
- package/dist/esm/internals/utils.js.map +1 -0
- package/dist/esm/useAdminRedact.js +43 -0
- package/dist/esm/useAdminRedact.js.map +1 -0
- package/dist/esm/useAgentConnection.js +128 -0
- package/dist/esm/useAgentConnection.js.map +1 -0
- package/dist/esm/useChannel.js +18 -0
- package/dist/esm/useChannel.js.map +1 -0
- package/dist/esm/useCreateChannel.js +24 -0
- package/dist/esm/useCreateChannel.js.map +1 -0
- package/dist/esm/useCreateDm.js +22 -0
- package/dist/esm/useCreateDm.js.map +1 -0
- package/dist/esm/useCreateGdm.js +22 -0
- package/dist/esm/useCreateGdm.js.map +1 -0
- package/dist/esm/useCreateSpace.js +22 -0
- package/dist/esm/useCreateSpace.js.map +1 -0
- package/dist/esm/useDm.js +16 -0
- package/dist/esm/useDm.js.map +1 -0
- package/dist/esm/useGdm.js +16 -0
- package/dist/esm/useGdm.js.map +1 -0
- package/dist/esm/useJoinSpace.js +23 -0
- package/dist/esm/useJoinSpace.js.map +1 -0
- package/dist/esm/useMember.js +36 -0
- package/dist/esm/useMember.js.map +1 -0
- package/dist/esm/useMemberList.js +17 -0
- package/dist/esm/useMemberList.js.map +1 -0
- package/dist/esm/useMyMember.js +71 -0
- package/dist/esm/useMyMember.js.map +1 -0
- package/dist/esm/useObservable.js +56 -0
- package/dist/esm/useObservable.js.map +1 -0
- package/dist/esm/useReactions.js +17 -0
- package/dist/esm/useReactions.js.map +1 -0
- package/dist/esm/useRedact.js +43 -0
- package/dist/esm/useRedact.js.map +1 -0
- package/dist/esm/useScrollback.js +27 -0
- package/dist/esm/useScrollback.js.map +1 -0
- package/dist/esm/useSendMessage.js +31 -0
- package/dist/esm/useSendMessage.js.map +1 -0
- package/dist/esm/useSendReaction.js +33 -0
- package/dist/esm/useSendReaction.js.map +1 -0
- package/dist/esm/useSpace.js +28 -0
- package/dist/esm/useSpace.js.map +1 -0
- package/dist/esm/useSyncAgent.jsx +20 -0
- package/dist/esm/useSyncAgent.jsx.map +1 -0
- package/dist/esm/useThreads.js +19 -0
- package/dist/esm/useThreads.js.map +1 -0
- package/dist/esm/useTimeline.js +32 -0
- package/dist/esm/useTimeline.js.map +1 -0
- package/dist/esm/useTowns.js +16 -0
- package/dist/esm/useTowns.js.map +1 -0
- package/dist/esm/useTownsAuthStatus.js +30 -0
- package/dist/esm/useTownsAuthStatus.js.map +1 -0
- package/dist/esm/useUserDms.js +36 -0
- package/dist/esm/useUserDms.js.map +1 -0
- package/dist/esm/useUserGdms.js +27 -0
- package/dist/esm/useUserGdms.js.map +1 -0
- package/dist/esm/useUserSpaces.js +27 -0
- package/dist/esm/useUserSpaces.js.map +1 -0
- package/dist/esm/utils.js +17 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/TownsSyncProvider.d.ts +23 -0
- package/dist/types/TownsSyncProvider.d.ts.map +1 -0
- package/dist/types/connectTowns.d.ts +29 -0
- package/dist/types/connectTowns.d.ts.map +1 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/internals/TownsSyncContext.d.ts +11 -0
- package/dist/types/internals/TownsSyncContext.d.ts.map +1 -0
- package/dist/types/internals/useAction.d.ts +38 -0
- package/dist/types/internals/useAction.d.ts.map +1 -0
- package/dist/types/internals/useTownsSync.d.ts +8 -0
- package/dist/types/internals/useTownsSync.d.ts.map +1 -0
- package/dist/types/internals/utils.d.ts +3 -0
- package/dist/types/internals/utils.d.ts.map +1 -0
- package/dist/types/useAdminRedact.d.ts +42 -0
- package/dist/types/useAdminRedact.d.ts.map +1 -0
- package/dist/types/useAgentConnection.d.ts +83 -0
- package/dist/types/useAgentConnection.d.ts.map +1 -0
- package/dist/types/useChannel.d.ts +12 -0
- package/dist/types/useChannel.d.ts.map +1 -0
- package/dist/types/useCreateChannel.d.ts +23 -0
- package/dist/types/useCreateChannel.d.ts.map +1 -0
- package/dist/types/useCreateDm.d.ts +28 -0
- package/dist/types/useCreateDm.d.ts.map +1 -0
- package/dist/types/useCreateGdm.d.ts +31 -0
- package/dist/types/useCreateGdm.d.ts.map +1 -0
- package/dist/types/useCreateSpace.d.ts +29 -0
- package/dist/types/useCreateSpace.d.ts.map +1 -0
- package/dist/types/useDm.d.ts +11 -0
- package/dist/types/useDm.d.ts.map +1 -0
- package/dist/types/useGdm.d.ts +11 -0
- package/dist/types/useGdm.d.ts.map +1 -0
- package/dist/types/useJoinSpace.d.ts +24 -0
- package/dist/types/useJoinSpace.d.ts.map +1 -0
- package/dist/types/useMember.d.ts +30 -0
- package/dist/types/useMember.d.ts.map +1 -0
- package/dist/types/useMemberList.d.ts +11 -0
- package/dist/types/useMemberList.d.ts.map +1 -0
- package/dist/types/useMyMember.d.ts +83 -0
- package/dist/types/useMyMember.d.ts.map +1 -0
- package/dist/types/useObservable.d.ts +59 -0
- package/dist/types/useObservable.d.ts.map +1 -0
- package/dist/types/useReactions.d.ts +10 -0
- package/dist/types/useReactions.d.ts.map +1 -0
- package/dist/types/useRedact.d.ts +42 -0
- package/dist/types/useRedact.d.ts.map +1 -0
- package/dist/types/useScrollback.d.ts +27 -0
- package/dist/types/useScrollback.d.ts.map +1 -0
- package/dist/types/useSendMessage.d.ts +32 -0
- package/dist/types/useSendMessage.d.ts.map +1 -0
- package/dist/types/useSendReaction.d.ts +32 -0
- package/dist/types/useSendReaction.d.ts.map +1 -0
- package/dist/types/useSpace.d.ts +22 -0
- package/dist/types/useSpace.d.ts.map +1 -0
- package/dist/types/useSyncAgent.d.ts +12 -0
- package/dist/types/useSyncAgent.d.ts.map +1 -0
- package/dist/types/useThreads.d.ts +11 -0
- package/dist/types/useThreads.d.ts.map +1 -0
- package/dist/types/useTimeline.d.ts +24 -0
- package/dist/types/useTimeline.d.ts.map +1 -0
- package/dist/types/useTowns.d.ts +14 -0
- package/dist/types/useTowns.d.ts.map +1 -0
- package/dist/types/useTownsAuthStatus.d.ts +26 -0
- package/dist/types/useTownsAuthStatus.d.ts.map +1 -0
- package/dist/types/useUserDms.d.ts +41 -0
- package/dist/types/useUserDms.d.ts.map +1 -0
- package/dist/types/useUserGdms.d.ts +32 -0
- package/dist/types/useUserGdms.d.ts.map +1 -0
- package/dist/types/useUserSpaces.d.ts +32 -0
- package/dist/types/useUserSpaces.d.ts.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +75 -0
- package/src/connectTowns.ts +63 -0
- package/src/index.ts +34 -0
- package/src/internals/TownsSyncContext.ts +12 -0
- package/src/internals/useAction.ts +84 -0
- package/src/internals/useTownsSync.ts +4 -0
- package/src/internals/utils.ts +11 -0
- package/src/useAdminRedact.ts +45 -0
- package/src/useAgentConnection.ts +143 -0
- package/src/useChannel.ts +27 -0
- package/src/useCreateChannel.ts +30 -0
- package/src/useCreateDm.ts +25 -0
- package/src/useCreateGdm.ts +25 -0
- package/src/useCreateSpace.ts +25 -0
- package/src/useDm.ts +17 -0
- package/src/useGdm.ts +17 -0
- package/src/useJoinSpace.ts +26 -0
- package/src/useMember.ts +45 -0
- package/src/useMemberList.ts +21 -0
- package/src/useMyMember.ts +83 -0
- package/src/useObservable.ts +129 -0
- package/src/useReactions.ts +21 -0
- package/src/useRedact.ts +45 -0
- package/src/useScrollback.ts +31 -0
- package/src/useSendMessage.ts +35 -0
- package/src/useSendReaction.ts +39 -0
- package/src/useSpace.ts +30 -0
- package/src/useThreads.ts +22 -0
- package/src/useTimeline.ts +35 -0
- package/src/useTowns.ts +22 -0
- package/src/useTownsAuthStatus.ts +32 -0
- package/src/useUserDms.ts +38 -0
- package/src/useUserGdms.ts +29 -0
- package/src/useUserSpaces.ts +29 -0
- package/src/utils.ts +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @towns-labs/react-sdk
|
|
2
|
+
|
|
3
|
+
React Hooks for River SDK.
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
|
|
7
|
+
in the future:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @towns-labs/react-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
# Usage
|
|
14
|
+
|
|
15
|
+
## Connect to River
|
|
16
|
+
|
|
17
|
+
`@towns-labs/react-sdk` suggests you to use Wagmi to connect to Towns Protocol.
|
|
18
|
+
Wrap your app with `TownsSyncProvider` and use the `useAgentConnection` hook to connect to Towns Protocol.
|
|
19
|
+
|
|
20
|
+
> [!NOTE]
|
|
21
|
+
> You'll need to use `useEthersSigner` to get the signer from viem wallet client.
|
|
22
|
+
> You can get the hook from [wagmi docs](https://wagmi.sh/react/guides/ethers#usage-1).
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { TownsSyncProvider, useAgentConnection } from "@towns-labs/react-sdk";
|
|
26
|
+
import { townsEnv } from "@towns-labs/sdk";
|
|
27
|
+
import { WagmiProvider } from "wagmi";
|
|
28
|
+
import { useEthersSigner } from "./utils/viem-to-ethers";
|
|
29
|
+
import { wagmiConfig } from "./config/wagmi";
|
|
30
|
+
|
|
31
|
+
const townsConfig = townsEnv().makeTownsConfig("beta");
|
|
32
|
+
|
|
33
|
+
const App = ({ children }: { children: React.ReactNode }) => {
|
|
34
|
+
return (
|
|
35
|
+
<WagmiProvider config={wagmiConfig}>
|
|
36
|
+
<TownsSyncProvider>{children}</TownsSyncProvider>
|
|
37
|
+
</WagmiProvider>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const ConnectTowns = () => {
|
|
42
|
+
const { connect, isConnecting, isConnected } = useAgentConnection();
|
|
43
|
+
const signer = useEthersSigner();
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
<button
|
|
48
|
+
onClick={async () => {
|
|
49
|
+
if (!signer) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
connect(signer, { townsConfig });
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{isConnecting ? "Disconnect" : "Connect"}
|
|
56
|
+
</button>
|
|
57
|
+
{isConnected && <span>Connected!</span>}
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Get information about an account
|
|
64
|
+
|
|
65
|
+
## Post messages to a stream
|
|
66
|
+
|
|
67
|
+
## Subscribe to a stream
|
|
68
|
+
|
|
69
|
+
## Addding persistance
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { TownsSyncContext } from './internals/TownsSyncContext';
|
|
4
|
+
/**
|
|
5
|
+
* Provides the sync agent to all hooks usage that interacts with the Towns Protocol.
|
|
6
|
+
*
|
|
7
|
+
* - If you want to interact with the sync agent directly, you can use the `useSyncAgent` hook.
|
|
8
|
+
* - If you want to interact with the Towns Protocol using hooks provided by this SDK, you should wrap your App with this provider.
|
|
9
|
+
*
|
|
10
|
+
* You can pass an initial sync agent instance to the provider.
|
|
11
|
+
* This can be useful for persisting authentication.
|
|
12
|
+
*
|
|
13
|
+
* @param props - The props for the provider
|
|
14
|
+
* @returns The provider
|
|
15
|
+
*/
|
|
16
|
+
export const TownsSyncProvider = (props) => {
|
|
17
|
+
const [syncAgent, setSyncAgent] = useState(() => props.syncAgent);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setSyncAgent(props.syncAgent);
|
|
20
|
+
}, [props.syncAgent]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (syncAgent) {
|
|
23
|
+
syncAgent.start();
|
|
24
|
+
}
|
|
25
|
+
return () => {
|
|
26
|
+
if (syncAgent) {
|
|
27
|
+
syncAgent.stop();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, [syncAgent]);
|
|
31
|
+
return (<TownsSyncContext.Provider value={{
|
|
32
|
+
config: props.config,
|
|
33
|
+
syncAgent,
|
|
34
|
+
setSyncAgent,
|
|
35
|
+
}}>
|
|
36
|
+
{props.children}
|
|
37
|
+
</TownsSyncContext.Provider>);
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=TownsSyncProvider.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TownsSyncProvider.jsx","sourceRoot":"","sources":["../../src/TownsSyncProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAE/D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAQjC,EAAE,EAAE;IACD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAEjE,SAAS,CAAC,GAAG,EAAE;QACX,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAA;IAErB,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,SAAS,EAAE,CAAC;YACZ,SAAS,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;QACD,OAAO,GAAG,EAAE;YACR,IAAI,SAAS,EAAE,CAAC;gBACZ,SAAS,CAAC,IAAI,EAAE,CAAA;YACpB,CAAC;QACL,CAAC,CAAA;IACL,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,CACH,CAAC,gBAAgB,CAAC,QAAQ,CACtB,KAAK,CAAC,CAAC;YACH,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS;YACT,YAAY;SACf,CAAC,CAEF;YAAA,CAAC,KAAK,CAAC,QAAQ,CACnB;QAAA,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAC/B,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// This file can be used on server side to create a Towns Protocol Client
|
|
2
|
+
/// We don't want a 'use client' directive here
|
|
3
|
+
import { SyncAgent, makeSignerContext, makeSignerContextFromBearerToken, } from '@towns-labs/sdk';
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
unpackEnvelopeOpts: {
|
|
7
|
+
disableSignatureValidation: true,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Sign and connect to Towns using a Signer and a random delegate wallet every time
|
|
12
|
+
* @param signer - The signer to use
|
|
13
|
+
* @param config - The configuration for the sync agent
|
|
14
|
+
* @returns The sync agent
|
|
15
|
+
*/
|
|
16
|
+
export const signAndConnect = async (signer, config) => {
|
|
17
|
+
const delegateWallet = ethers.Wallet.createRandom();
|
|
18
|
+
const signerContext = await makeSignerContext(signer, delegateWallet);
|
|
19
|
+
return new SyncAgent({ context: signerContext, ...defaultConfig, ...config });
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Connect to Towns using a SignerContext
|
|
23
|
+
*
|
|
24
|
+
* Useful for server side code, allowing you to persist the signer context and use it to auth with Towns later
|
|
25
|
+
* @param signerContext - The signer context to use
|
|
26
|
+
* @param config - The configuration for the sync agent
|
|
27
|
+
* @returns The sync agent
|
|
28
|
+
*/
|
|
29
|
+
export const connectTowns = async (signerContext, config) => {
|
|
30
|
+
return new SyncAgent({ context: signerContext, ...defaultConfig, ...config });
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Connect to Towns using a Bearer Token
|
|
34
|
+
* Towns clients can use this to connect to Towns Protocol on behalf of a user
|
|
35
|
+
*
|
|
36
|
+
* Useful for server side code, allowing you to persist the signer context and use it to auth with Towns later
|
|
37
|
+
* @param token - The bearer token to use
|
|
38
|
+
* @param config - The configuration for the sync agent
|
|
39
|
+
* @returns The sync agent
|
|
40
|
+
*/
|
|
41
|
+
export const connectTownsWithBearerToken = async (token, config) => {
|
|
42
|
+
const signerContext = await makeSignerContextFromBearerToken(token);
|
|
43
|
+
return new SyncAgent({ context: signerContext, ...defaultConfig, ...config });
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=connectTowns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectTowns.js","sourceRoot":"","sources":["../../src/connectTowns.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+CAA+C;AAC/C,OAAO,EAEH,SAAS,EAET,iBAAiB,EACjB,gCAAgC,GACnC,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,aAAa,GAA6B;IAC5C,kBAAkB,EAAE;QAChB,0BAA0B,EAAE,IAAI;KACnC;CACJ,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAC/B,MAAqB,EACrB,MAAwC,EACtB,EAAE;IACpB,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;IACnD,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IACrE,OAAO,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;AACjF,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC7B,aAA4B,EAC5B,MAAwC,EACtB,EAAE;IACpB,OAAO,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;AACjF,CAAC,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC5C,KAAa,EACb,MAAwC,EACtB,EAAE;IACpB,MAAM,aAAa,GAAG,MAAM,gCAAgC,CAAC,KAAK,CAAC,CAAA;IACnE,OAAO,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;AACjF,CAAC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* This file is generated by running 🏕️ scripts/generate_sdk_index.sh 🏕️ *
|
|
3
|
+
**************************************************************************/
|
|
4
|
+
export * from './TownsSyncProvider';
|
|
5
|
+
export * from './connectTowns';
|
|
6
|
+
export * from './useAdminRedact';
|
|
7
|
+
export * from './useAgentConnection';
|
|
8
|
+
export * from './useChannel';
|
|
9
|
+
export * from './useCreateChannel';
|
|
10
|
+
export * from './useCreateDm';
|
|
11
|
+
export * from './useCreateGdm';
|
|
12
|
+
export * from './useCreateSpace';
|
|
13
|
+
export * from './useDm';
|
|
14
|
+
export * from './useGdm';
|
|
15
|
+
export * from './useJoinSpace';
|
|
16
|
+
export * from './useMember';
|
|
17
|
+
export * from './useMemberList';
|
|
18
|
+
export * from './useMyMember';
|
|
19
|
+
export * from './useObservable';
|
|
20
|
+
export * from './useReactions';
|
|
21
|
+
export * from './useRedact';
|
|
22
|
+
export * from './useScrollback';
|
|
23
|
+
export * from './useSendMessage';
|
|
24
|
+
export * from './useSendReaction';
|
|
25
|
+
export * from './useSpace';
|
|
26
|
+
export * from './useSyncAgent';
|
|
27
|
+
export * from './useThreads';
|
|
28
|
+
export * from './useTimeline';
|
|
29
|
+
export * from './useTowns';
|
|
30
|
+
export * from './useTownsAuthStatus';
|
|
31
|
+
export * from './useUserDms';
|
|
32
|
+
export * from './useUserGdms';
|
|
33
|
+
export * from './useUserSpaces';
|
|
34
|
+
export * from './utils';
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;4EAE4E;AAC5E,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TownsSyncContext.js","sourceRoot":"","sources":["../../../src/internals/TownsSyncContext.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AASrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAoC,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to create an action from a namespace.
|
|
4
|
+
* @internal
|
|
5
|
+
* @param namespace - The namespace to create the action from.
|
|
6
|
+
* @param fnName - The name of the action to create. Example: `Namespace.fnName`
|
|
7
|
+
* @param config - Configuration options for the action.
|
|
8
|
+
* @returns The action and its loading state.
|
|
9
|
+
*/
|
|
10
|
+
export const useAction = (namespace, fnName, config) => {
|
|
11
|
+
const [status, setStatus] = useState('idle');
|
|
12
|
+
const [error, setError] = useState();
|
|
13
|
+
const [data, setData] = useState();
|
|
14
|
+
const action = useCallback(async (...args) => {
|
|
15
|
+
if (!namespace) {
|
|
16
|
+
throw new Error(`useAction: namespace is undefined`);
|
|
17
|
+
}
|
|
18
|
+
const fn = namespace[fnName];
|
|
19
|
+
if (typeof fn !== 'function') {
|
|
20
|
+
throw new Error(`useAction: fn ${fnName} is not a function`);
|
|
21
|
+
}
|
|
22
|
+
setStatus('loading');
|
|
23
|
+
try {
|
|
24
|
+
const data = (await fn.apply(namespace, args));
|
|
25
|
+
setData(data);
|
|
26
|
+
setStatus('success');
|
|
27
|
+
config?.onSuccess?.(data);
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
setStatus('error');
|
|
32
|
+
if (error instanceof Error) {
|
|
33
|
+
setError(error);
|
|
34
|
+
config?.onError?.(error);
|
|
35
|
+
}
|
|
36
|
+
// Let the caller handle the error
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
setStatus('idle');
|
|
41
|
+
}
|
|
42
|
+
}, [config, fnName, namespace]);
|
|
43
|
+
return {
|
|
44
|
+
/** The action to execute. */
|
|
45
|
+
action,
|
|
46
|
+
/** The data returned by the action. */
|
|
47
|
+
data,
|
|
48
|
+
/** The error that occurred while executing the action. */
|
|
49
|
+
error,
|
|
50
|
+
/** Whether the action is pending. */
|
|
51
|
+
isPending: status === 'loading',
|
|
52
|
+
/** Whether the action is successful. */
|
|
53
|
+
isSuccess: status === 'success',
|
|
54
|
+
/** Whether the action is in error. */
|
|
55
|
+
isError: status === 'error',
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=useAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAction.js","sourceRoot":"","sources":["../../../src/internals/useAction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAsB7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACrB,SAAgC,EAChC,MAAoB,EACpB,MAAyB,EAC3B,EAAE;IACA,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA2C,MAAM,CAAC,CAAA;IACtF,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAqB,CAAA;IACvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,EAA4B,CAAA;IAE5D,MAAM,MAAM,GAAG,WAAW,CACtB,KAAK,EAAE,GAAG,IAAkC,EAAyB,EAAE;QACnE,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;QACxD,CAAC;QACD,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAiB,CAAA;QAC5C,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,oBAAoB,CAAC,CAAA;QAChE,CAAC;QACD,SAAS,CAAC,SAAS,CAAC,CAAA;QACpB,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAiB,CAAA;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAA;YACb,SAAS,CAAC,SAAS,CAAC,CAAA;YACpB,MAAM,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,CAAA;YACzB,OAAO,IAAoB,CAAA;QAC/B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,CAAA;YAClB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBACzB,QAAQ,CAAC,KAAK,CAAC,CAAA;gBACf,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YAC5B,CAAC;YACD,kCAAkC;YAClC,MAAM,KAAK,CAAA;QACf,CAAC;gBAAS,CAAC;YACP,SAAS,CAAC,MAAM,CAAC,CAAA;QACrB,CAAC;IACL,CAAC,EACD,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAC9B,CAAA;IACD,OAAO;QACH,6BAA6B;QAC7B,MAAM;QACN,uCAAuC;QACvC,IAAI;QACJ,0DAA0D;QAC1D,KAAK;QACL,qCAAqC;QACrC,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,wCAAwC;QACxC,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,sCAAsC;QACtC,OAAO,EAAE,MAAM,KAAK,OAAO;KAC9B,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTownsSync.js","sourceRoot":"","sources":["../../../src/internals/useTownsSync.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AACZ,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/internals/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAI,KAA4B,EAA8B,EAAE;IAC5F,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAA;IAChB,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,KAAK,CAAA;IAChB,CAAC;IACD,OAAO,QAAQ,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAA;AAC/C,CAAC,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Space, assert } from '@towns-labs/sdk';
|
|
3
|
+
import { useAction } from './internals/useAction';
|
|
4
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
5
|
+
import { getRoom } from './utils';
|
|
6
|
+
/**
|
|
7
|
+
* Hook to redact any message in a channel if you're an admin.
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ### Redact a message
|
|
11
|
+
*
|
|
12
|
+
* You can use `adminRedact` to redact a message in a stream.
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { useAdminRedact } from '@towns-labs/react-sdk'
|
|
15
|
+
*
|
|
16
|
+
* const { adminRedact } = useAdminRedact(streamId)
|
|
17
|
+
* adminRedact({ eventId: messageEventId })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Redact a message reaction
|
|
21
|
+
*
|
|
22
|
+
* You can also use `redact` to redact a message reaction in a stream.
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { useRedact } from '@towns-labs/react-sdk'
|
|
25
|
+
*
|
|
26
|
+
* const { redact } = useRedact(streamId)
|
|
27
|
+
* redact({ eventId: reactionEventId })
|
|
28
|
+
* ```
|
|
29
|
+
* @param streamId - The id of the stream to redact the message in.
|
|
30
|
+
* @param config - Configuration options for the action.
|
|
31
|
+
* @returns The `redact` action and its loading state.
|
|
32
|
+
*/
|
|
33
|
+
export const useAdminRedact = (streamId, config) => {
|
|
34
|
+
const sync = useSyncAgent();
|
|
35
|
+
const room = getRoom(sync, streamId);
|
|
36
|
+
assert(!(room instanceof Space), 'Spaces dont have timeline to redact');
|
|
37
|
+
const { action: adminRedact, ...rest } = useAction(room, 'adminRedact', config);
|
|
38
|
+
return {
|
|
39
|
+
adminRedact,
|
|
40
|
+
...rest,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=useAdminRedact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAdminRedact.js","sourceRoot":"","sources":["../../src/useAdminRedact.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAW,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,MAA6C,EAAE,EAAE;IAC9F,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACpC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,EAAE,qCAAqC,CAAC,CAAA;IACvE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,CAAC,CAAA;IAE/E,OAAO;QACH,WAAW;QACX,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { connectTownsWithBearerToken, signAndConnect } from './connectTowns';
|
|
3
|
+
import { useTownsSync } from './internals/useTownsSync';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for managing the connection to the sync agent
|
|
6
|
+
*
|
|
7
|
+
* @example You can connect the Sync Agent to Towns Protocol using a Bearer Token or using a Signer.
|
|
8
|
+
*
|
|
9
|
+
* ### Bearer Token
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useAgentConnection } from '@towns-labs/react-sdk'
|
|
12
|
+
* import { townsEnv } from '@towns-labs/sdk'
|
|
13
|
+
* import { useState } from 'react'
|
|
14
|
+
*
|
|
15
|
+
* const townsConfig = townsEnv().makeTownsConfig('beta')
|
|
16
|
+
*
|
|
17
|
+
* const Login = () => {
|
|
18
|
+
* const { connectUsingBearerToken, isAgentConnecting, isAgentConnected } = useAgentConnection()
|
|
19
|
+
* const [bearerToken, setBearerToken] = useState('')
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <>
|
|
23
|
+
* <input value={bearerToken} onChange={(e) => setBearerToken(e.target.value)} />
|
|
24
|
+
* <button onClick={() => connectUsingBearerToken(bearerToken, { townsConfig })}>
|
|
25
|
+
* Login
|
|
26
|
+
* </button>
|
|
27
|
+
* {isAgentConnecting && <span>Connecting... ⏳</span>}
|
|
28
|
+
* {isAgentConnected && <span>Connected ✅</span>}
|
|
29
|
+
* </>
|
|
30
|
+
* )
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ### Signer
|
|
35
|
+
*
|
|
36
|
+
* If you're using Wagmi and Viem, you can use the [`useEthersSigner`](https://wagmi.sh/react/guides/ethers#usage-1) hook to get an ethers.js v5 Signer from a Viem Wallet Client.
|
|
37
|
+
*
|
|
38
|
+
* ```tsx
|
|
39
|
+
* import { useAgentConnection } from '@towns-labs/react-sdk'
|
|
40
|
+
* import { townsEnv } from '@towns-labs/sdk'
|
|
41
|
+
* import { useEthersSigner } from './utils/viem-to-ethers'
|
|
42
|
+
*
|
|
43
|
+
* const townsConfig = townsEnv().makeTownsConfig('beta')
|
|
44
|
+
*
|
|
45
|
+
* const Login = () => {
|
|
46
|
+
* const { connect, isAgentConnecting, isAgentConnected } = useAgentConnection()
|
|
47
|
+
* const signer = useEthersSigner()
|
|
48
|
+
*
|
|
49
|
+
* return (
|
|
50
|
+
* <>
|
|
51
|
+
* <button onClick={async () => {
|
|
52
|
+
* if (!signer) {
|
|
53
|
+
* return
|
|
54
|
+
* }
|
|
55
|
+
* connect(signer, { townsConfig })
|
|
56
|
+
* }}>
|
|
57
|
+
* Login
|
|
58
|
+
* </button>
|
|
59
|
+
* {isAgentConnecting && <span>Connecting... ⏳</span>}
|
|
60
|
+
* {isAgentConnected && <span>Connected ✅</span>}
|
|
61
|
+
* </>
|
|
62
|
+
* )
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @returns The connection state and methods (connect, connectUsingBearerToken, disconnect)
|
|
67
|
+
*/
|
|
68
|
+
export const useAgentConnection = () => {
|
|
69
|
+
const [isAgentConnecting, setConnecting] = useState(false);
|
|
70
|
+
const towns = useTownsSync();
|
|
71
|
+
const connect = useCallback(async (signer, config) => {
|
|
72
|
+
if (towns?.syncAgent) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const mergedConfig = {
|
|
76
|
+
...config,
|
|
77
|
+
...towns?.config,
|
|
78
|
+
onTokenExpired: () => {
|
|
79
|
+
towns?.config?.onTokenExpired?.();
|
|
80
|
+
towns?.setSyncAgent(undefined);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
setConnecting(true);
|
|
84
|
+
return signAndConnect(signer, mergedConfig)
|
|
85
|
+
.then((syncAgent) => {
|
|
86
|
+
towns?.setSyncAgent(syncAgent);
|
|
87
|
+
return syncAgent;
|
|
88
|
+
})
|
|
89
|
+
.finally(() => setConnecting(false));
|
|
90
|
+
}, [towns]);
|
|
91
|
+
const connectUsingBearerToken = useCallback(async (bearerToken, config) => {
|
|
92
|
+
if (towns?.syncAgent) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const mergedConfig = {
|
|
96
|
+
...config,
|
|
97
|
+
...towns?.config,
|
|
98
|
+
onTokenExpired: () => {
|
|
99
|
+
towns?.config?.onTokenExpired?.();
|
|
100
|
+
towns?.setSyncAgent(undefined);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
setConnecting(true);
|
|
104
|
+
return connectTownsWithBearerToken(bearerToken, mergedConfig)
|
|
105
|
+
.then((syncAgent) => {
|
|
106
|
+
towns?.setSyncAgent(syncAgent);
|
|
107
|
+
return syncAgent;
|
|
108
|
+
})
|
|
109
|
+
.finally(() => setConnecting(false));
|
|
110
|
+
}, [towns]);
|
|
111
|
+
const disconnect = useCallback(() => towns?.setSyncAgent(undefined), [towns]);
|
|
112
|
+
const isAgentConnected = useMemo(() => !!towns?.syncAgent, [towns]);
|
|
113
|
+
return {
|
|
114
|
+
/** Connect to Towns Protocol using a Signer */
|
|
115
|
+
connect,
|
|
116
|
+
/** Connect to Towns Protocol using a Bearer Token */
|
|
117
|
+
connectUsingBearerToken,
|
|
118
|
+
/** Disconnect from Towns Protocol */
|
|
119
|
+
disconnect,
|
|
120
|
+
/** Whether the agent is currently connecting */
|
|
121
|
+
isAgentConnecting,
|
|
122
|
+
/** Whether the agent is connected */
|
|
123
|
+
isAgentConnected,
|
|
124
|
+
/** The environment of the current connection (beta, omega, alpha, local_dev, etc.) */
|
|
125
|
+
env: towns?.syncAgent?.config.townsConfig.environmentId,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=useAgentConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgentConnection.js","sourceRoot":"","sources":["../../src/useAgentConnection.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
4
|
+
import { useObservable } from './useObservable';
|
|
5
|
+
/**
|
|
6
|
+
* Hook to get data about a channel.
|
|
7
|
+
* You can use this hook to get channel metadata and if the user has joined the channel.
|
|
8
|
+
* @param spaceId - The id of the space the channel belongs to.
|
|
9
|
+
* @param channelId - The id of the channel to get data about.
|
|
10
|
+
* @param config - Configuration options for the observable.
|
|
11
|
+
* @returns The ChannelModel data.
|
|
12
|
+
*/
|
|
13
|
+
export const useChannel = (spaceId, channelId, config) => {
|
|
14
|
+
const sync = useSyncAgent();
|
|
15
|
+
const channel = useMemo(() => sync.spaces.getSpace(spaceId).getChannel(channelId), [sync.spaces, spaceId, channelId]);
|
|
16
|
+
return useObservable(channel, config);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=useChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChannel.js","sourceRoot":"","sources":["../../src/useChannel.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAyB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEtE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACtB,OAAe,EACf,SAAiB,EACjB,MAAiD,EACnD,EAAE;IACA,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,OAAO,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EACzD,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CACpC,CAAA;IACD,OAAO,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AACzC,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useAction } from './internals/useAction';
|
|
4
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
5
|
+
/**
|
|
6
|
+
* Hook to create a channel.
|
|
7
|
+
* @param config - Configuration options for the action.
|
|
8
|
+
* @returns The `createChannel` action and its loading state.
|
|
9
|
+
*/
|
|
10
|
+
export const useCreateChannel = (spaceId, config) => {
|
|
11
|
+
const sync = useSyncAgent();
|
|
12
|
+
const space = useMemo(() => sync.spaces.getSpace(spaceId), [spaceId, sync.spaces]);
|
|
13
|
+
const { action: createChannel, ...rest } = useAction(space, 'createChannel', config);
|
|
14
|
+
return {
|
|
15
|
+
/**
|
|
16
|
+
* Action to create a channel.
|
|
17
|
+
* @param name - The name of the channel to create.
|
|
18
|
+
* @param signer - The signer to use to create the channel.
|
|
19
|
+
*/
|
|
20
|
+
createChannel,
|
|
21
|
+
...rest,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useCreateChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateChannel.js","sourceRoot":"","sources":["../../src/useCreateChannel.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,OAAe,EACf,MAA6C,EAC/C,EAAE;IACA,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAClF,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAA;IAEpF,OAAO;QACH;;;;WAIG;QACH,aAAa;QACb,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAction } from './internals/useAction';
|
|
3
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
4
|
+
/**
|
|
5
|
+
* A hook that allows you to create a new direct message (DM).
|
|
6
|
+
* @param config - The action config.
|
|
7
|
+
* @returns An object containing the `createDM` action and the rest of the action result.
|
|
8
|
+
*/
|
|
9
|
+
export const useCreateDm = (config) => {
|
|
10
|
+
const sync = useSyncAgent();
|
|
11
|
+
const { action: createDM, ...rest } = useAction(sync.dms, 'createDM', config);
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new DM.
|
|
15
|
+
* @param userId - The `userId` of the user to create a DM with.
|
|
16
|
+
* @returns A promise that resolves to the result of the create operation.
|
|
17
|
+
*/
|
|
18
|
+
createDM,
|
|
19
|
+
...rest,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useCreateDm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateDm.js","sourceRoot":"","sources":["../../src/useCreateDm.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAsC,EAAE,EAAE;IAClE,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;IAE7E,OAAO;QACH;;;;WAIG;QACH,QAAQ;QACR,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAction } from './internals/useAction';
|
|
3
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
4
|
+
/**
|
|
5
|
+
* A hook that allows you to create a new group direct message (GDM).
|
|
6
|
+
* @param config - The action config.
|
|
7
|
+
* @returns An object containing the `createGDM` action and the rest of the action result.
|
|
8
|
+
*/
|
|
9
|
+
export const useCreateGdm = (config) => {
|
|
10
|
+
const sync = useSyncAgent();
|
|
11
|
+
const { action: createGDM, ...rest } = useAction(sync.gdms, 'createGDM', config);
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new GDM.
|
|
15
|
+
* @param userIds - The `userIds` of the users to invite to the GDM.
|
|
16
|
+
* @returns A promise that resolves to the result of the create operation.
|
|
17
|
+
*/
|
|
18
|
+
createGDM,
|
|
19
|
+
...rest,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useCreateGdm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateGdm.js","sourceRoot":"","sources":["../../src/useCreateGdm.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAwC,EAAE,EAAE;IACrE,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;IAEhF,OAAO;QACH;;;;WAIG;QACH,SAAS;QACT,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useAction } from './internals/useAction';
|
|
3
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
4
|
+
/**
|
|
5
|
+
* Hook to create a space.
|
|
6
|
+
* @param config - Configuration options for the action.
|
|
7
|
+
* @returns The `createSpace` action and its loading state.
|
|
8
|
+
*/
|
|
9
|
+
export const useCreateSpace = (config = {}) => {
|
|
10
|
+
const sync = useSyncAgent();
|
|
11
|
+
const { action: createSpace, ...rest } = useAction(sync.spaces, 'createSpace', config);
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Action to create a space.
|
|
15
|
+
* @param opts - Options for the create space action.
|
|
16
|
+
* @param signer - The signer used to create the space.
|
|
17
|
+
*/
|
|
18
|
+
createSpace,
|
|
19
|
+
...rest,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useCreateSpace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateSpace.js","sourceRoot":"","sources":["../../src/useCreateSpace.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAA8C,EAAE,EAAE,EAAE;IAC/E,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAAA;IAEtF,OAAO;QACH;;;;WAIG;QACH,WAAW;QACX,GAAG,IAAI;KACV,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useSyncAgent } from './useSyncAgent';
|
|
3
|
+
import { useObservable } from './useObservable';
|
|
4
|
+
/**
|
|
5
|
+
* Hook to get the data of a DM.
|
|
6
|
+
* You can use this hook to get DM metadata and if the user has joined the DM.
|
|
7
|
+
* @param streamId - The id of the DM to get the data of.
|
|
8
|
+
* @param config - Configuration options for the observable.
|
|
9
|
+
* @returns The DmModel of the DM.
|
|
10
|
+
*/
|
|
11
|
+
export const useDm = (streamId, config) => {
|
|
12
|
+
const sync = useSyncAgent();
|
|
13
|
+
const dm = useMemo(() => sync.dms.getDm(streamId), [streamId, sync]);
|
|
14
|
+
return useObservable(dm, config);
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useDm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDm.js","sourceRoot":"","sources":["../../src/useDm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAyB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEtE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE,MAA2C,EAAE,EAAE;IACnF,MAAM,IAAI,GAAG,YAAY,EAAE,CAAA;IAC3B,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;IACpE,OAAO,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;AACpC,CAAC,CAAA"}
|