|
| 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