Skip to content

Commit 1dfa2c0

Browse files
devangb3cjcchen
andauthored
Add ResShare file-sharing toolkit under ecosystem/tools (#240)
* Fix covery test (#246) * fix ut * fix ut * Add implementation of ResShare Toolkit - Created core files including `README.md`, `package.json`, and configuration for Jest testing. - Implemented main client functionality in `src/index.js` and modularized authentication, file handling, and sharing features in respective modules. - Added example scripts for basic usage and advanced scenarios. - Included a `.gitignore` file to exclude unnecessary files from version control. - Established a testing framework with initial unit tests for client functionality. * Document ResShare SDK in READMEs * Add Apache headers to ResShare toolkit files --------- Co-authored-by: cjcchen <ickchenjunchao@gmail.com>
1 parent 30ca97e commit 1dfa2c0

16 files changed

Lines changed: 1240 additions & 9 deletions

File tree

.bazelversion

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
6.0.0
22

3-

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Beyond the core NexRes engine, ResilientDB ships with a rich ecosystem of tools
8888
- **Core Node (NexRes)**: High-throughput, BFT-replicated state machine that orders and executes transactions with strong consistency and durability.
8989
- **APIs (GraphQL & REST)**: ResilientDB exposes HTTP and GraphQL services for committing and querying transactions, making it easy to integrate with web backends, data services, and AI workflows.
9090
- **ResVault (Wallet & Extension)**: Browser extension wallet that manages keys, lets users authenticate, and approve transactions from web apps, tying writes on-chain to user-controlled identities.
91-
- **SDKs & ORMs**: Language-specific libraries (e.g., Python ORM, Rust SDK, ResVault SDK) that provide higher-level APIs for modeling assets, talking to GraphQL/REST, and wiring ResVault into applications.
91+
- **SDKs & ORMs**: Language-specific libraries and client toolkits (e.g., Python ORM, Rust SDK, ResVault SDK, ResShare SDK) that provide higher-level APIs for modeling assets, talking to GraphQL/REST, and wiring ResilientDB services into applications.
9292
- **Monitoring (ResLens & dashboards)**: Monitoring UIs and middleware (ResLens stack) that surface cluster health, performance metrics, and profiling data for running deployments.
9393
- **Deployment Tooling (Orbit, Ansible, Docker)**: Tools and playbooks for bringing up ResilientDB clusters and supporting services (GraphQL, Nginx, etc.) on local and cloud environments using Docker, Ansible, and the Orbit desktop deployer.
9494

@@ -144,6 +144,7 @@ incubator-resilientdb/
144144
│ └── tools/ # Dev and app tools
145145
│ ├── create-resilient-app/ # App scaffolding CLI
146146
│ ├── drawing-lib/ # Shared drawing widget
147+
│ ├── reshare-lib/ # ResShare SDK
147148
│ └── resvault/ # ResVault wallet extension
148149
├── executor/ # Transaction execution engine
149150
│ ├── common/ # Common execution utilities
@@ -537,4 +538,3 @@ ResilientDB includes a built‑in smart contract service that lets you deploy an
537538
In addition, you can use the **Key‑Value interfaces** to query or update associated balances via `get_balance` and `set_balance` commands when needed.
538539

539540
For a full, step‑by‑step tutorial (including example JSON files, commands, and responses), see **[Getting Started with Smart Contract on ResilientDB](https://blog.resilientdb.com/2025/02/14/GettingStartedSmartContract.html)**.
540-

ecosystem/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ecosystem/
5555
└── tools/
5656
├── create-resilient-app/
5757
├── drawing-lib/
58+
├── reshare-lib/ # ResShare SDK
5859
└── resvault/
5960
```
6061

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
node_modules/
19+
coverage/
20+
examples/out/*
21+
!examples/out/.gitkeep
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# ResShare Toolkit
21+
22+
**License**: Apache-2.0
23+
24+
Universal JavaScript toolkit for ResShare file-sharing APIs. This toolkit provides a modular client for authentication, file and folder operations, and share management.
25+
26+
## Features
27+
28+
- Authentication helpers (`signup`, `login`, `logout`, `status`, `deleteUser`)
29+
- File operations (`createFolder`, `upload`, `deleteItem`, `download`, `downloadZip`)
30+
- Share operations (`share`, `list`, `remove`)
31+
- Cookie-aware sessions for Node.js and browser clients
32+
- Retry and timeout handling with normalized API errors
33+
34+
## Project Structure
35+
36+
```
37+
reshare-lib/
38+
├── src/
39+
│ ├── index.js
40+
│ └── modules/
41+
│ ├── auth.js
42+
│ ├── files.js
43+
│ └── shares.js
44+
├── examples/
45+
│ ├── basic-usage.js
46+
│ └── advanced-demo.js
47+
├── tests/
48+
│ └── unit/
49+
├── README.md
50+
├── jest.config.cjs
51+
└── package.json
52+
```
53+
54+
## Installation
55+
56+
This toolkit is part of the Apache ResilientDB repository and is not published as a standalone package yet.
57+
58+
```bash
59+
# From repository root
60+
npm install ./ecosystem/tools/reshare-lib
61+
```
62+
63+
## Quick Start
64+
65+
```javascript
66+
import ResShareToolkitClient from 'resshare-toolkit';
67+
68+
const client = new ResShareToolkitClient({
69+
baseUrl: 'http://localhost:5000'
70+
});
71+
72+
await client.auth.login({ username: 'alice', password: 'secret' });
73+
await client.files.createFolder('docs');
74+
```
75+
76+
## API Overview
77+
78+
### Client Initialization
79+
80+
```javascript
81+
const client = new ResShareToolkitClient({
82+
baseUrl: 'http://localhost:5000',
83+
apiPrefix: '', // Optional path prefix (for example: /api/v1)
84+
timeout: 30000, // Request timeout in milliseconds
85+
retries: 2, // Request retries
86+
credentials: 'include', // Fetch credentials mode
87+
onAuthExpired: async () => '' // Optional token refresh callback
88+
});
89+
```
90+
91+
### Auth Module
92+
93+
- `client.auth.login({ username, password })`
94+
- `client.auth.signup({ username, password })`
95+
- `client.auth.logout()`
96+
- `client.auth.status()`
97+
- `client.auth.deleteUser({ password })`
98+
99+
### Files Module
100+
101+
- `client.files.createFolder(path)`
102+
- `client.files.upload({ file, path, skipProcessing, filename })`
103+
- `client.files.deleteItem({ path, deleteInRoot })`
104+
- `client.files.download({ path, isShared })`
105+
- `client.files.downloadZip({ path, isShared })`
106+
107+
### Shares Module
108+
109+
- `client.shares.share({ target, path, node })`
110+
- `client.shares.list()`
111+
- `client.shares.remove({ combinedPath, fromUser, path })`
112+
113+
## Error Handling
114+
115+
All failed requests throw `ApiError` with:
116+
117+
- `status`: HTTP status code
118+
- `body`: parsed response payload
119+
120+
```javascript
121+
import ResShareToolkitClient, { ApiError } from 'resshare-toolkit';
122+
123+
const client = new ResShareToolkitClient({ baseUrl: 'http://localhost:5000' });
124+
125+
try {
126+
await client.files.createFolder('docs');
127+
} catch (error) {
128+
if (error instanceof ApiError) {
129+
console.error(error.status, error.getUserMessage());
130+
}
131+
}
132+
```
133+
134+
## Examples
135+
136+
```bash
137+
node ecosystem/tools/reshare-lib/examples/basic-usage.js
138+
node ecosystem/tools/reshare-lib/examples/advanced-demo.js
139+
```
140+
141+
`advanced-demo.js` writes outputs to `ecosystem/tools/reshare-lib/examples/out/` during execution.
142+
143+
## Testing
144+
145+
```bash
146+
cd ecosystem/tools/reshare-lib
147+
npm test
148+
```
149+
150+
## Backend Requirements
151+
152+
The toolkit expects a ResShare-compatible backend exposing endpoints used by:
153+
154+
- `/login`, `/signup`, `/logout`, `/auth-status`, `/delete-user`
155+
- `/create-folder`, `/upload`, `/delete`, `/download`, `/download-zip`
156+
- `/share`, `/shared`
157+
158+
Configure `baseUrl` and optional `apiPrefix` to match your deployment.
159+
160+
## License
161+
162+
Licensed to the Apache Software Foundation (ASF) under the Apache License, Version 2.0.

0 commit comments

Comments
 (0)