Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce get_account functions from Social DB contract #50

Open
wants to merge 4 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ body:
label: Version
description: What version of the software are you running?
options:
- 1.1.0
- 1.0.1
- 1.0.0
validations:
Expand Down
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# [1.1.0](https://github.com/NEARBuilders/near-social-js/compare/v1.0.1...v1.1.0) (2024-08-19)


### Features

* wallet support for frontend apps and API server methods ([#43](https://github.com/NEARBuilders/near-social-js/issues/43)) ([83bb3a6](https://github.com/NEARBuilders/near-social-js/commit/83bb3a6c4610a28bb4599a5be1ce2278a82ca989)), closes [#35](https://github.com/NEARBuilders/near-social-js/issues/35) [#35](https://github.com/NEARBuilders/near-social-js/issues/35) [#38](https://github.com/NEARBuilders/near-social-js/issues/38) [#38](https://github.com/NEARBuilders/near-social-js/issues/38) [#40](https://github.com/NEARBuilders/near-social-js/issues/40) [#40](https://github.com/NEARBuilders/near-social-js/issues/40) [#33](https://github.com/NEARBuilders/near-social-js/issues/33) [#33](https://github.com/NEARBuilders/near-social-js/issues/33) [#42](https://github.com/NEARBuilders/near-social-js/issues/42) [#42](https://github.com/NEARBuilders/near-social-js/issues/42)

# [1.1.0-beta.5](https://github.com/NEARBuilders/near-social-js/compare/v1.1.0-beta.4...v1.1.0-beta.5) (2024-08-05)


### Features

* aded transformActions utility and exposed all utils ([#42](https://github.com/NEARBuilders/near-social-js/issues/42)) ([bfc9072](https://github.com/NEARBuilders/near-social-js/commit/bfc90720035d9e686469e95bf25ef0cc17c79c4b))

# [1.1.0-beta.4](https://github.com/NEARBuilders/near-social-js/compare/v1.1.0-beta.3...v1.1.0-beta.4) (2024-08-01)


### Features

* adding api server support for read methods ([#33](https://github.com/NEARBuilders/near-social-js/issues/33)) ([dc53b30](https://github.com/NEARBuilders/near-social-js/commit/dc53b30af3ade611a4e8d29316dfc56f77dc8791))

# [1.1.0-beta.3](https://github.com/NEARBuilders/near-social-js/compare/v1.1.0-beta.2...v1.1.0-beta.3) (2024-07-30)


### Bug Fixes

* required deposit fix when available storage is higher than needed ([#40](https://github.com/NEARBuilders/near-social-js/issues/40)) ([99f9e8d](https://github.com/NEARBuilders/near-social-js/commit/99f9e8de55d5410ff34f553348d978fe075e6fbf))

# [1.1.0-beta.2](https://github.com/NEARBuilders/near-social-js/compare/v1.1.0-beta.1...v1.1.0-beta.2) (2024-07-25)


### Features

* remove near-api-js account object dependency from change functions ([#38](https://github.com/NEARBuilders/near-social-js/issues/38)) ([134e463](https://github.com/NEARBuilders/near-social-js/commit/134e4638341febdaf945fe8412479172421332d3))

# [1.1.0-beta.1](https://github.com/NEARBuilders/near-social-js/compare/v1.0.1...v1.1.0-beta.1) (2024-07-24)


### Features

* **wip:** removed signer from viewMethods by dropping NAJ account.ViewFunction ([#35](https://github.com/NEARBuilders/near-social-js/issues/35)) ([a57edc4](https://github.com/NEARBuilders/near-social-js/commit/a57edc42bee279abc1f3925acd130cba29cd239a))

## [1.0.1](https://github.com/NEARBuilders/near-social-js/compare/v1.0.0...v1.0.1) (2024-07-05)


Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<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
">
<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>

Expand Down
160 changes: 160 additions & 0 deletions docs/advanced/fetching-indexed-data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TOCInline from '@theme/TOCInline';

# Fetching Indexed Data

## Overview

The `index` function in the Social SDK allows you to retrieve indexed values based on specified criteria from the Social API server. This function is crucial for efficient lookups of social interactions or custom indexed data, supporting various filtering, ordering, and pagination options.

:::note

The `index` function is only available through the API server and does not have an RPC version.

:::

## Function Signature

```typescript
public async index({
action,
key,
accountId,
order,
limit,
from,
}: IIndexOptions): Promise<Record<string, unknown>>
```

### Parameters

- `action`: The index_type from the standard (e.g., 'like' in the path 'index/like').
- `key`: Can be either a string or an object:
- If string: The inner indexed value from the standard.
- If object: Can include properties like type, path, and blockHeight.
- `accountId` (optional): A string or array of account IDs to filter values.
- `order` (optional): The order of results. Either 'asc' or 'desc'. Default is 'asc'.
- `limit` (optional): The number of values to return. Default is 100.
- `from` (optional): The starting point for fetching results. Defaults to 0 or Max depending on order.

### Return Value

A promise that resolves to an array of matched indexed values, ordered by blockHeight.

## Usage Examples

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

### Advanced Usage

You can use additional options to customize the behavior of the `index` function:

```typescript
const result = await social.index({
action: 'follow',
key: 'alice.near',
accountId: ['bob.near', 'charlie.near'],
order: 'desc',
limit: '50',
from: 100,
});
```

This example retrieves the last 50 'follow' actions for 'alice.near', starting from the 100th most recent entry, and only includes actions by 'bob.near' and 'charlie.near'.

## Use Cases

The `index` function is particularly useful for:

1. Fetching all 'like' actions for a specific post:
```typescript
const likes = await social.index({
action: 'like',
key: {
type: 'social',
path: 'efiz.near/post/main',
blockHeight: 124692995,//blockHeight of the post
},
});
```

2. Retrieving recent 'follow' actions for a user:
```typescript
const result = await social.index({
action: 'graph',
key: 'follow',
order: 'desc',
accountId: 'alice.near',
limit: '10',
});
```

3. Querying custom indexed data based on application-specific schemas:
```typescript
const customData = await social.index({
action: 'custom-action',
key: 'app-specific-key',
});
```

By leveraging the `index` function, you can build efficient and scalable features in your NEAR Social applications, such as activity feeds, trending content algorithms, or custom data aggregations.

:::tip

Combine the `index` function with `get` and `keys` for comprehensive data retrieval strategies in your application.

:::
81 changes: 28 additions & 53 deletions docs/advanced/granting-write-permission.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```js
const { Social } = require('@builddao/near-social-js');

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});

// ...sign the returned transaction and post to the network
Expand All @@ -56,41 +53,22 @@ Accounts can grant write permission to other accounts for a set of keys.
<TabItem value="javascript-via-cdn">

```js
var accessKeys;
var grantee;
var granter;
var social;

nearConnection.account('alice.near')
.then((_granter) => {
granter = _granter;

return nearConnection.account('bob.near');
})
.then((_grantee) => {
grantee = _grantee;

return granter.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
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>
Expand All @@ -99,20 +77,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```typescript
import { Social } from '@builddao/near-social-js';

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
account: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});

// ...sign the returned transaction and post to the network
Expand All @@ -124,12 +99,12 @@ Accounts can grant write permission to other accounts for a set of keys.

:::caution

If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../../api-reference/errors#invalidaccountiderror) is thrown.
If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../api-reference/errors#invalidaccountiderror) is thrown.

:::

:::caution

If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../../api-reference/errors#keynotallowederror) is thrown.
If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../api-reference/errors#keynotallowederror) is thrown.

:::
1 change: 1 addition & 0 deletions docs/advanced/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Advanced

* [Reading Data](advanced/reading-data)
* [Fetching Indexed Data](advanced/fetching-indexed-data)
* [Storing Data](advanced/storing-data)
* [Granting Write Permission](advanced/granting-write-permission)
* [Storage Deposit/Withdrawal](advanced/storage-deposit-withdraw)
Loading