Skip to content

Commit

Permalink
feat: converts to ESM package (#52)
Browse files Browse the repository at this point in the history
* fix: revamp readme

* fix: commitlint .mjs

* fix: docs, introduce tsup

* fix: remove buffer dependency

* chore: increment version

* fix: bundle dependencies
  • Loading branch information
elliotBraem authored Oct 25, 2024
1 parent 3e64f59 commit 741193b
Show file tree
Hide file tree
Showing 43 changed files with 6,255 additions and 5,720 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ dist
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*

### JetBrains template
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc.js → .lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
export default {
'**/*.{js,json,ts}': (filenames) => `prettier --write ${filenames.join(' ')}`,
};
151 changes: 61 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
<h1 align="center">
NEAR Social SDK
</h1>
<!-- markdownlint-disable MD014 -->
<!-- markdownlint-disable MD033 -->
<!-- markdownlint-disable MD041 -->
<!-- markdownlint-disable MD029 -->

<p align="center">
<a href="https://github.com/NEARBuilders/near-social-js/releases/latest">
<img alt="GitHub Release" src="https://img.shields.io/github/v/release/NEARBuilders/near-social-js?&logo=github">
</a>
<a href="https://github.com/NEARBuilders/near-social-js/releases/latest">
<img alt="GitHub Release Date - Published At" src="https://img.shields.io/github/release-date/NEARBuilders/near-social-js?logo=github">
</a>
</p>

<p align="center">
<a href="https://github.com/NEARBuilders/near-social-js/releases">
<img alt="GitHub Pre-release" src="https://img.shields.io/github/v/release/NEARBuilders/near-social-js?include_prereleases&label=pre-release&logo=github">
</a>
<a href="https://github.com/NEARBuilders/near-social-js/releases">
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github">
</a>
</p>

<p align="center">
<a href="https://github.com/NEARBuilders/near-social-js/blob/main/LICENSE">
<img alt="GitHub License" src="https://img.shields.io/github/license/NEARBuilders/near-social-js">
</a>
</p>
<div align="center">

<h1 style="font-size: 2.5rem; font-weight: bold;">near-social-js</h1>
<p align="center">
<a href="https://npmjs.com/package/@builddao/near-social-js" target="_blank">
<img src="https://img.shields.io/npm/v/%40builddao%2Fnear-social-js?logo=npm" alt="npm" />
Expand All @@ -35,68 +15,65 @@
</a>
</p>

<p align="center">
A JavaScript SDK for interacting with the social contract (social.near) with helper functions for typical social features.
</p>

### Table of contents

* [1. Overview](#-1-overview)
* [2. Documentation](#-2-documentation)
* [3. Development](#-3-development)
* [3.1. Requirements](#31-requirements)
* [3.2. Setup](#32-setup)
* [3.3. Build](#33-build)
* [4. Appendix](#-4-appendix)
* [4.1. Useful Commands](#41-useful-commands)
* [4.2. Social Contract](#42-social-contract)
* [5. How To Contribute](#-5-how-to-contribute)
* [6. License](#-6-license)
<p>
<strong>Typescript SDK for interacting with the social contract (social.near)</strong>
</p>

## 🔭 1. Overview
</div>

TBC...
<details>
<summary>Table of Contents</summary>

<sup>[Back to top ^][table-of-contents]</sup>
- [Getting Started](#getting-started)
- [Installing dependencies](#installing-dependencies)
- [Running the app](#running-the-app)
- [Building for production](#building-for-production)
- [Running tests](#running-tests)
- [Contributing](#contributing)

## 📚 2. Documentation
</details>

For full documentation, please see [here][documentation].
## Getting Started

<sup>[Back to top ^][table-of-contents]</sup>
### Installing dependencies

## 🛠 3. Development
```bash
yarn install
```

### 3.1. Requirements
### Running the app

* Install [Node v18.20.2+][node]
* Install [Yarn v1.22.5+][yarn]
First, run the development server:

<sup>[Back to top ^][table-of-contents]</sup>
```bash
yarn run dev
```

### 3.2. Setup
### Building for production

1. Install the dependencies:
```bash
$ yarn install
yarn run build
```

<sup>[Back to top ^][table-of-contents]</sup>
### Running tests

### 3.3. Build

* To build simply run:
```bash
$ yarn build
yarn run test
```

The above command will compile the Typescript source code into a `dist/` directory.
See the full [testing guide](./playwright-tests/README.md).

<sup>[Back to top ^][table-of-contents]</sup>
## Appendix

## 📑 4. Appendix
### Social Contract

| Network | Account ID | Link |
|---------|-----------------------|------------------------------------------------------------------------------------------------------------------------|
| Mainnet | `social.near` | [https://nearblocks.io/address/social.near](https://nearblocks.io/address/social.near) |
| Testnet | `v1.social08.testnet` | [https://testnet.nearblocks.io/address/v1.social08.testnet](https://testnet.nearblocks.io/address/v1.social08.testnet) |

### 4.1. Useful Commands

### Useful Commands

| Command | Description |
|-------------------|------------------------------------------------------------------------------------|
Expand All @@ -107,36 +84,30 @@ The above command will compile the Typescript source code into a `dist/` directo
| `yarn lint` | Runs the linter on `.js` and `.ts` files. |
| `yarn node:start` | Starts up a NEAR development node in a background process. |
| `yarn node:start` | Stops the NEAR development node that was started in `yarn node:start`. |
| `yarn prettier` | Runs the prettier on `.js` and `.ts` files. |
| `yarn fmt` | Runs prettier on `.js` and `.ts` files. |
| `yarn test` | Starts a NEAR development node and runs the tests. |

<sup>[Back to top ^][table-of-contents]</sup>

### 4.2. Social Contract

| Network | Account ID | Link |
|---------|-----------------------|------------------------------------------------------------------------------------------------------------------------|
| Mainnet | `social.near` | [https://nearblocks.io/address/social.near](https://nearblocks.io/address/social.near) |
| Testnet | `v1.social08.testnet` | [https://testnet.nearblocks.io/address/v1.social08.testnet](https://testnet.nearblocks.io/address/v1.social08.testnet) |

<sup>[Back to top ^][table-of-contents]</sup>

## 👏 5. How To Contribute

Please read the [**Contributing Guide**][contribute] to learn about the development process.

<sup>[Back to top ^][table-of-contents]</sup>

## 📄 6. License

Please refer to the [LICENSE][license] file.

<sup>[Back to top ^][table-of-contents]</sup>

<!-- Links -->
[contribute]: ./CONTRIBUTING.md
[documentation]: https://nearbuilders.github.io/near-social-js
[license]: ./LICENSE
[node]: https://nodejs.org/en/
[table-of-contents]: #table-of-contents
[yarn]: https://yarnpkg.com/


## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you're interested in contributing to this project, please read the [contribution guide](./CONTRIBUTING).

<div align="right">
<a href="https://nearbuilders.org" target="_blank">
<img
src="https://builders.mypinata.cloud/ipfs/QmWt1Nm47rypXFEamgeuadkvZendaUvAkcgJ3vtYf1rBFj"
alt="Near Builders"
height="40"
/>
</a>
</div>
2 changes: 1 addition & 1 deletion commitlint.config.js → commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
Expand Down
63 changes: 11 additions & 52 deletions docs/advanced/fetching-indexed-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,58 +46,17 @@ A promise that resolves to an array of matched indexed values, ordered by blockH

### Basic Usage

<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}>
<TabItem value="javascript-via-package-manager">

```js
const { Social } = require('@builddao/near-social-js');

const social = new Social();
const result = await social.index({
action: 'like',
key: 'post-123',
});

console.log(result);
```

</TabItem>
<TabItem value="javascript-via-cdn">

```js
var social = new NEARSocialSDK();

social.index({
action: 'like',
key: 'post-123',
}).then((result) => {
console.log(result);
});
```

</TabItem>
<TabItem value="typescript">

```typescript
import { Social } from '@builddao/near-social-js';

const social = new Social();
const result = await social.index({
action: 'like',
key: 'post-123',
});

console.log(result);
```

</TabItem>
</Tabs>
```typescript
import { Social } from '@builddao/near-social-js';

const social = new Social();
const result = await social.index({
action: 'like',
key: 'post-123',
});

console.log(result);
```

### Advanced Usage

Expand Down
95 changes: 19 additions & 76 deletions docs/advanced/granting-write-permission.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,25 @@ Accounts can grant write permission to other accounts for a set of keys.

## Granting an account write permission

<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}>
<TabItem value="javascript-via-package-manager">

```js
const { Social } = require('@builddao/near-social-js');

const social = new Social();
const transaction = await social.grantWritePermission({
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
});

// ...sign the returned transaction and post to the network
*/
```

</TabItem>
<TabItem value="javascript-via-cdn">

```js
var social = new NEARSocialSDK();

social.grantWritePermission({
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url'
]
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
```

</TabItem>
<TabItem value="typescript">

```typescript
import { Social } from '@builddao/near-social-js';

const social = new Social();
const transaction = await social.grantWritePermission({
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
});

// ...sign the returned transaction and post to the network
*/
```

</TabItem>
</Tabs>
```typescript
import { Social } from '@builddao/near-social-js';

const social = new Social();
const transaction = await social.grantWritePermission({
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
});

// ...sign the returned transaction and post to the network
*/
```

:::caution

Expand Down
Loading

0 comments on commit 741193b

Please sign in to comment.