Skip to content

Commit

Permalink
docs: add readme and license
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolu89 committed Jul 17, 2023
1 parent cd65302 commit 94e4f4f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 11 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Nostr-one

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
83 changes: 72 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,79 @@
# Vue 3 + TypeScript + Vite
# `<nostr-one />`

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
The `<nostr-one>` custom element is a reusable web component that provides a simple way to integrate with the Nostr [NIP 98](https://github.com/nostr-protocol/nips/blob/master/98.md) HTTP Auth. It can be used in any web project that supports custom elements.

## Recommended IDE Setup
## Installation

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
```bash
npm install nostr-one
```

## Type Support For `.vue` Imports in TS
```js
import "nostr-one";
```

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
## Usage

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
To use the `<nostr-one>` custom element in your web project, you can include it in your HTML file and configure it using attributes:

1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
```html
<nostr-one
login-url="https://example.com/login"
http-method="post"
></nostr-one>
```

In this example, we configure the component using the `login-url` and `http-method` attributes. These attributes correspond to the options you can pass to the `NostrOne` class constructor.

You can also configure the component using JavaScript:

```html
<nostr-one id="nostr-one"></nostr-one>
<script>
const nostrOne = document.getElementById('nostr-one');
nostrOne.loginUrl = 'https://example.com/login';
nostrOne.httpMethod = 'post';
nostrOne.onSuccess = function(data) {
console.log('Success:', data);
};
nostrOne.onError = function(error) {
console.error('Error:', error);
};
nostrOne.onClick = function(eventB64) {
console.log('Click:', eventB64);
};
</script>
```

In this example, we use JavaScript to configure the component after it has been added to the DOM. We access the component using its `id` attribute and set its properties using JavaScript.

## API

The `<nostr-one>` custom element has the following properties:

### `loginUrl` required

The URL to use for the Nostr API login endpoint.

### `httpMethod`

The HTTP method to use for the Nostr API login request.
Accepts `get` and `post`
Default to `post`

### `onSuccess`

A callback function to be called when the Nostr API login request succeeds. The function is passed the response data as an argument.

### `onError`

A callback function to be called when the Nostr API login request fails. The function is passed the error object as an argument.

### `onClick`

⚠️ If used, the component will not send the HTTP request automatically.\
A callback function to be called when the user clicks on the component. The function is passed the event data as a base64-encoded string.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

0 comments on commit 94e4f4f

Please sign in to comment.