|
1 | 1 | ## Tasks Data Module |
2 | 2 |
|
3 | | -(under construction) |
| 3 | +To use this Solid Data Module you need an authenticated fetch function. In Node.JS, when working against a CSS or Pivot server such as solidcommnunity.net, you can use [css-authn](https://www.npmjs.com/package/css-authn#usage) for this. In the browser, you can use [Inrupt Solid Client](https://docs.inrupt.com/developer-tools/javascript/client-libraries/authentication/). |
| 4 | + |
| 5 | + |
| 6 | +### Usage |
| 7 | +Set up a typescript project, install [solid-data-module-tasks](https://www.npmjs.com/package/solid-data-module-tasks) from NPM, and create a `.env` file like this: |
| 8 | +```env |
| 9 | +SOLID_SERVER=https://solidcommunity.net |
| 10 | +SOLID_EMAIL=michielbdejong@users.css.pod |
| 11 | +SOLID_PASSWORD=... |
| 12 | +``` |
| 13 | + |
| 14 | +Make sure there is a Solid OS issue tracker at `trackerUrl`. You can create this through the web interface of Pivot. |
| 15 | + |
| 16 | +Then save, build and run the following TypeScript file: |
| 17 | +```ts |
| 18 | +import 'dotenv/config'; |
| 19 | +import { v7 } from 'css-authn'; |
| 20 | +import { fetchTracker, Interpretation, addIssue, addComment } from 'solid-data-module-tasks'; |
| 21 | + |
| 22 | +const authenticatedFetch = await v7.getAuthenticatedFetch({ |
| 23 | + email: process.env.SOLID_EMAIL, |
| 24 | + password: process.env.SOLID_PASSWORD, |
| 25 | + provider: process.env.SOLID_SERVER, |
| 26 | +}); |
| 27 | +const trackerUrl = 'https://michielbdejong.solidcommunity.net/tasks/index.ttl#this'; |
| 28 | +const localState: Interpretation = await fetchTracker(trackerUrl, authenticatedFetch); |
| 29 | +const issueUri = await addIssue(localState, { |
| 30 | + title: 'Use the Solid Data Module for Tasks', |
| 31 | + description: 'Solid app devs should not be rolling their own task tracker access code.', |
| 32 | +}, authenticatedFetch); |
| 33 | +const newComment = { |
| 34 | + issueUri, |
| 35 | + author: 'https://michielbdejong.solidcommunity.net/profile/card#me', |
| 36 | + text: `I totally agree at ${new Date().toUTCString()}`, |
| 37 | +}; |
| 38 | +const commentUri = await addComment(localState, newComment, authenticatedFetch); |
| 39 | +console.log(commentUri); |
| 40 | +``` |
| 41 | + |
| 42 | +This will result in an issue and a comment being created in that tracker: |
| 43 | + |
0 commit comments