@dxos/react-client 2.29.2-dev.e924fb34 → 2.29.2-dev.f64f2a6f
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/.rush/temp/package-deps_build.json +9 -6
- package/.rush/temp/package-deps_build:test.json +9 -6
- package/.rush/temp/package-deps_prerelease.json +9 -6
- package/.rush/temp/shrinkwrap-deps.json +73 -1
- package/dist/src/hooks/index.d.ts +1 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +1 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/invitations/useHaloInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useHaloInvitations.js.map +1 -1
- package/dist/src/hooks/invitations/useInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/useInvitations.js.map +1 -1
- package/dist/src/hooks/invitations/usePartyInvitations.d.ts.map +1 -1
- package/dist/src/hooks/invitations/usePartyInvitations.js +1 -2
- package/dist/src/hooks/invitations/usePartyInvitations.js.map +1 -1
- package/dist/src/hooks/ipfs/index.d.ts +3 -0
- package/dist/src/hooks/ipfs/index.d.ts.map +1 -0
- package/dist/src/hooks/ipfs/index.js +18 -0
- package/dist/src/hooks/ipfs/index.js.map +1 -0
- package/dist/src/hooks/ipfs/useIpfsClient.d.ts +17 -0
- package/dist/src/hooks/ipfs/useIpfsClient.d.ts.map +1 -0
- package/dist/src/hooks/ipfs/useIpfsClient.js +41 -0
- package/dist/src/hooks/ipfs/useIpfsClient.js.map +1 -0
- package/dist/src/hooks/ipfs/useIpfsFiles.d.ts +19 -0
- package/dist/src/hooks/ipfs/useIpfsFiles.d.ts.map +1 -0
- package/dist/src/hooks/ipfs/useIpfsFiles.js +48 -0
- package/dist/src/hooks/ipfs/useIpfsFiles.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dxos-react-client-2.29.2-dev.f64f2a6f.tgz +0 -0
- package/out/book/esbuild-server-book.js +216179 -0
- package/out/book/index.html +14 -0
- package/package.json +24 -23
- package/src/hooks/index.ts +1 -0
- package/src/hooks/invitations/useHaloInvitations.ts +2 -2
- package/src/hooks/invitations/useInvitations.ts +1 -0
- package/src/hooks/invitations/usePartyInvitations.ts +1 -2
- package/src/hooks/ipfs/index.ts +6 -0
- package/src/hooks/ipfs/useIpfsClient.ts +36 -0
- package/src/hooks/ipfs/useIpfsFiles.ts +59 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<link rel="stylesheet" href="esbuild-server-book.css">
|
|
8
|
+
<title>ESBuild-Server Book</title>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id='root'></div>
|
|
12
|
+
<script src='esbuild-server-book.js'></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "2.29.2-dev.
|
|
3
|
+
"version": "2.29.2-dev.f64f2a6f",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "DXOS.org",
|
|
7
7
|
"main": "dist/src/index.js",
|
|
8
8
|
"types": "dist/src/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"book": "toolchain book",
|
|
11
|
+
"build": "toolchain build",
|
|
12
|
+
"build:book": "toolchain build:book",
|
|
13
|
+
"build:test": "toolchain build:test",
|
|
14
|
+
"lint": "toolchain lint",
|
|
15
|
+
"test": "toolchain test"
|
|
16
|
+
},
|
|
9
17
|
"dependencies": {
|
|
10
|
-
"@dxos/async": "
|
|
11
|
-
"@dxos/bot-factory-client": "
|
|
12
|
-
"@dxos/client": "
|
|
13
|
-
"@dxos/config": "
|
|
14
|
-
"@dxos/credentials": "
|
|
15
|
-
"@dxos/crypto": "
|
|
16
|
-
"@dxos/debug": "
|
|
17
|
-
"@dxos/echo-db": "
|
|
18
|
-
"@dxos/network-manager": "
|
|
19
|
-
"@dxos/util": "
|
|
18
|
+
"@dxos/async": "workspace:*",
|
|
19
|
+
"@dxos/bot-factory-client": "workspace:*",
|
|
20
|
+
"@dxos/client": "workspace:*",
|
|
21
|
+
"@dxos/config": "workspace:*",
|
|
22
|
+
"@dxos/credentials": "workspace:*",
|
|
23
|
+
"@dxos/crypto": "workspace:*",
|
|
24
|
+
"@dxos/debug": "workspace:*",
|
|
25
|
+
"@dxos/echo-db": "workspace:*",
|
|
26
|
+
"@dxos/network-manager": "workspace:*",
|
|
27
|
+
"@dxos/util": "workspace:*",
|
|
20
28
|
"assert": "^2.0.0",
|
|
21
29
|
"debug": "^4.3.3",
|
|
30
|
+
"ipfs-http-client": "~56.0.1",
|
|
22
31
|
"use-subscription": "^1.4.1"
|
|
23
32
|
},
|
|
24
33
|
"devDependencies": {
|
|
25
34
|
"@dxos/esbuild-plugins": "~2.28.7",
|
|
26
35
|
"@dxos/eslint-plugin": "~1.0.27",
|
|
27
|
-
"@dxos/protocols-toolchain": "
|
|
36
|
+
"@dxos/protocols-toolchain": "workspace:*",
|
|
28
37
|
"@mui/material": "^5.4.2",
|
|
29
38
|
"@testing-library/react": "^11.0.4",
|
|
30
39
|
"@testing-library/react-hooks": "5.1.2",
|
|
@@ -39,6 +48,7 @@
|
|
|
39
48
|
"expect": "~27.0.2",
|
|
40
49
|
"fork-ts-checker-webpack-plugin": "~6.2.5",
|
|
41
50
|
"level-js": "^5.0.2",
|
|
51
|
+
"node-fetch": "^2.6.0",
|
|
42
52
|
"react": "^17.0.2",
|
|
43
53
|
"react-dom": "^17.0.2",
|
|
44
54
|
"react-test-renderer": "^17.0.2",
|
|
@@ -54,14 +64,5 @@
|
|
|
54
64
|
"jsdom": true,
|
|
55
65
|
"forceCloseTests": true,
|
|
56
66
|
"testingFramework": "mocha"
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
"book": "toolchain book",
|
|
60
|
-
"build": "toolchain build",
|
|
61
|
-
"build:book": "toolchain build:book",
|
|
62
|
-
"build:test": "toolchain build:test",
|
|
63
|
-
"lint": "toolchain lint",
|
|
64
|
-
"test": "toolchain test"
|
|
65
|
-
},
|
|
66
|
-
"readme": "# @dxos/react-client\n\nA react implementation of the DXOS Client APIs.\n\n## Install\n\n```bash\ngit clone git@github.com:dxos/protocols.git\ncd protocols\nrush update\nrush build\n\ncd packages/sdk/demos\nrushx book\n```\n\n## Usage\n\nThe snippet below illustrates a self-contained DXOS application that uses providers to create the client and instantiate a user profile.\n\n```javascript\nimport { useClient, ClientProvider, ProfileInitializer } from '@dxos/react-client';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => {\n const client = useClient();\n\n return (\n <pre>{JSON.stringify(client.info())}</pre>\n );\n};\n\nconst Root = () => (\n <ClientProvider>\n <ProfileInitializer>\n <App />\n </ProfileInitializer>\n </ClientProvider>\n);\n\nReactDOM.render(<Root/>, document.getElementById('root'));\n```\n\n## Storybooks\n\nThe [HALO Invitation Story](./stories/halo-invitations.stories.tsx) demonstrates multiple clients (devices) joining the same HALO.\n\nhttps://user-images.githubusercontent.com/3523355/137532718-a21f1f27-9854-4c0b-831a-e9ff92feac49.mov\n\nThe [Party Invitation Story](./stories/party-invitations.stories.tsx) demonstrates multiple clients creating and sharing parties.\n\nhttps://user-images.githubusercontent.com/3523355/137532717-e77395dc-96f9-4e4b-8f67-e6bd026a3abe.mov\n\n\n## Contributing\n\nPRs accepted.\n\n## License\n\nAGPL-3.0 © DXOS\n"
|
|
67
|
-
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Client
|
|
5
|
+
import { Client } from '@dxos/client';
|
|
6
6
|
|
|
7
7
|
import { useInvitations } from './useInvitations';
|
|
8
8
|
|
|
9
9
|
export const useHaloInvitations = (client: Client) => {
|
|
10
|
-
return useInvitations(
|
|
10
|
+
return useInvitations(client.halo.invitationProxy);
|
|
11
11
|
};
|
|
@@ -11,6 +11,7 @@ export const useInvitations = (invitationProxy: InvitationProxy | undefined) =>
|
|
|
11
11
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
setInvitations(invitationProxy?.activeInvitations ?? []);
|
|
14
|
+
|
|
14
15
|
return invitationProxy?.invitationsUpdate.on(() => {
|
|
15
16
|
setInvitations([...invitationProxy.activeInvitations]);
|
|
16
17
|
});
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { PartyProxy } from '@dxos/client';
|
|
6
5
|
import { PublicKey } from '@dxos/crypto';
|
|
7
6
|
|
|
8
7
|
import { useParty } from '../echo-queries';
|
|
@@ -10,5 +9,5 @@ import { useInvitations } from './useInvitations';
|
|
|
10
9
|
|
|
11
10
|
export const usePartyInvitations = (partyKey?: PublicKey) => {
|
|
12
11
|
const party = useParty(partyKey);
|
|
13
|
-
return useInvitations(
|
|
12
|
+
return useInvitations(party?.invitationProxy);
|
|
14
13
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { CID, create } from 'ipfs-http-client';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Return URL to IPFS resource on local gateway.
|
|
11
|
+
* @param gateway
|
|
12
|
+
* @param cid
|
|
13
|
+
* @param filename
|
|
14
|
+
*/
|
|
15
|
+
export const getIpfsUrl = (gateway: string, cid: CID, filename?: string) => {
|
|
16
|
+
const args = filename ? [`filename=${encodeURI(filename)}`] : [];
|
|
17
|
+
return path.join(gateway, String(cid), '?', args.join('&'));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* https://www.npmjs.com/package/ipfs-http-client#example
|
|
22
|
+
* NOTE: We need to run our own servers to enable CORS.
|
|
23
|
+
* Ports
|
|
24
|
+
* - 8001 Gateway
|
|
25
|
+
* - 5001 API
|
|
26
|
+
*/
|
|
27
|
+
// TODO(kaplanski): Factor out IPFS related functionality to its own package.
|
|
28
|
+
export const useIpfsClient = (url?: string) => {
|
|
29
|
+
return useMemo(() => {
|
|
30
|
+
if (!url) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return create({ url });
|
|
35
|
+
}, [url]);
|
|
36
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { CID, IPFSHTTPClient } from 'ipfs-http-client';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Party } from '@dxos/client';
|
|
9
|
+
|
|
10
|
+
import { useSelection } from '../echo-selections';
|
|
11
|
+
|
|
12
|
+
export type IPFSFile = {
|
|
13
|
+
filename?: string
|
|
14
|
+
cid: CID
|
|
15
|
+
size?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a list of mapped IPFS files.
|
|
20
|
+
* @param party
|
|
21
|
+
* @param type
|
|
22
|
+
*/
|
|
23
|
+
export const useIpfsFiles = (party: Party | undefined, type: string) => {
|
|
24
|
+
// TODO(burdon): Schema definitions for types?
|
|
25
|
+
// TODO(burdon): Use reducer to do mapping?
|
|
26
|
+
const items = useSelection(party?.select().filter({ type }));
|
|
27
|
+
|
|
28
|
+
const files: IPFSFile[] = useMemo(() => items?.map(item => ({
|
|
29
|
+
filename: item.model.getProperty('filename'),
|
|
30
|
+
cid: item.model.getProperty('cid'),
|
|
31
|
+
size: item.model.getProperty('size')
|
|
32
|
+
})), [items]) ?? [];
|
|
33
|
+
|
|
34
|
+
return files;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// TODO(wittjosiah): This is not returning IPFSFiles.
|
|
38
|
+
export const uploadFilesToIpfs = async (
|
|
39
|
+
ipfsClient: IPFSHTTPClient,
|
|
40
|
+
files: File[],
|
|
41
|
+
onError?: (error: Error) => void
|
|
42
|
+
) => {
|
|
43
|
+
return await Promise.all(files.map(async (file) => {
|
|
44
|
+
// https://docs.ipfs.io/reference/js/api
|
|
45
|
+
// https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client
|
|
46
|
+
try {
|
|
47
|
+
const { cid, path, size } = await ipfsClient.add(file);
|
|
48
|
+
await ipfsClient.pin.add(cid);
|
|
49
|
+
// TODO(kaplanski): path is CID v0. cid is CID v1. Current default is v0, but will be updated to v1 in the future. We'll need to update to support v1.
|
|
50
|
+
return {
|
|
51
|
+
cid: path,
|
|
52
|
+
size,
|
|
53
|
+
filename: file.name
|
|
54
|
+
};
|
|
55
|
+
} catch (err) {
|
|
56
|
+
onError?.(err instanceof Error ? err : new Error(err as string)); // TODO(burdon): Generalize.
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
};
|