Skip to content

Commit

Permalink
docs(docusaurus): Update API refs
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Mar 26, 2024
1 parent cac346d commit fcd7bf3
Show file tree
Hide file tree
Showing 12 changed files with 2,168 additions and 1,943 deletions.
11 changes: 11 additions & 0 deletions doc-site/docs/FAQs/migrate-to-1.3.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: migrate
title: migrate to 1.3
order: 1
---

1. Remove `zkCryptoUrl` params when `Client` initializing. [PR: simply offchainauth (ED25519)](https://github.com/bnb-chain/greenfield-js-sdk/pull/489)

2. `bucket.createBucket` and `object.createObject` 's params changes. [PR: remove approval when create bucket / object](https://github.com/bnb-chain/greenfield-js-sdk/pull/498)

3. `object.uploadObject` 's params changes. [PR: upload object](https://github.com/bnb-chain/greenfield-js-sdk/pull/500)
11 changes: 0 additions & 11 deletions doc-site/docs/FAQs/migrate.mdx

This file was deleted.

68 changes: 11 additions & 57 deletions doc-site/docs/api/bucket.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,23 @@ for creating bucket and sends the createBucket transaction to the Greenfield.
| bucketName | bucket name |
| creator | creator account address |
| visibility | [VisibilityType](/types/visibility) |
| chargedReadQuota | defines the traffic quota that you read from primary sp |
| spInfo | primary sp address |
| chargedReadQuota | [Long](/types/long)defines the traffic quota that you read from primary sp |
| primarySpAddress | primary sp address |
| paymentAddress | payment address |
| tags | defines a list of tags which will be set to the bucket |
| authType | [AuthType](/client/sp-client#authtype) |


<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
```js
const tx = await client.bucket.createBucket(
{
bucketName: 'bucket_name',
creator: address,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
chargedReadQuota: '0',
spInfo: {
primarySpAddress: 'primary_sp_address',
},
creator: '0x...',
visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ,
chargedReadQuota: Long.fromString('0'),
primarySpAddress: '0x....',
paymentAddress: address,
tags: {
tags: [],
},
},
// highlight-start
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
// highlight-end
);
```

</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```js
const createBucketTx = await client.bucket.createBucket(
{
bucketName: bucketName,
creator: ACCOUNT_ADDRESS,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
chargedReadQuota: '0',
spInfo: {
primarySpAddress: spInfo.primarySpAddress,
},
paymentAddress: ACCOUNT_ADDRESS,
},
// highlight-start
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
// highlight-end
}
);
```

</TabItem>
</Tabs>

## deleteBucket <ApiTypes type="Tx" />

Send DeleteBucket msg to greenfield chain and return txn hash.
Expand All @@ -90,7 +44,7 @@ Send DeleteBucket msg to greenfield chain and return txn hash.
| bucketName | The name of the bucket to be deleted |
| operator | operator account address |

```jsx title="Browser | Nodejs"
```js
const tx = await client.bucket.deleteBucket({
bucketName: bucketName,
operator: address,
Expand All @@ -110,7 +64,7 @@ Delete the bucket policy of the principal.
| principalAddr | Principal define the roles that can grant permissions |
| principalType | PrincipalType refers to the identity type of system users or entities. |

```jsx title="Browser | Nodejs"
```js
const tx = await client.bucket.deleteBucketPolicy(
address,
bucketName,
Expand All @@ -129,7 +83,7 @@ This API is used to get bucket meta by bucket name.
| ---------- | ----------- |
| bucketName | bucket name |

```jsx title="Browser | Nodejs"
```js
const bucketInfo = await client.bucket.getBucketMeta({
bucketName,
});
Expand Down
3 changes: 2 additions & 1 deletion doc-site/docs/api/group.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ await client.group.updateGroupExtra({

<Tx />

## updateGroupMember <ApiTypes type="Tx" />
## updateGroupMember
<!-- <ApiTypes type="Tx" /> -->

Update a group by adding or removing members. The sender can be the group owner or any individual
account(Principle) that has been granted permission by the group owner.
Expand Down
114 changes: 19 additions & 95 deletions doc-site/docs/api/object.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Send `CancelCreateObject` txn to greenfield chain.
| bucketName | the name of the bucket |
| objectName | the name of the object |

<!-- <Tx /> -->

## createFolder <ApiTypes type="Storage Provider" /> <ApiTypes type="Tx" />

Expand All @@ -27,132 +26,57 @@ Send create empty object txn to greenfield chain.
| params | description |
| ---------- | -------------------------------------- |
| bucketName | bucket name |
| objectName | object name |
| objectName | folder name, end with `/` |
| creator | the creator of object |
| tags | defines a list of tags which will be set to the object |
| authType | [AuthType](/client/sp-client#authtype) |
| visibility | [VisibilityType](/types/visibility) |
| redundancyType | [RedundancyType](/types/redundancy) |

<Tabs groupId="example">
<TabItem value="Browser" label="Browser">

```jsx
const tx = await client.object.createFolder(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName + '/',
creator: address,
tags: {
tags: [],
},
},
// highlight-start
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
// highlight-end
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
}
);
```

</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```js
const tx = await client.object.createFolder(
{
bucketName: bucketName,
objectName: objectName + '/',
creator: ACCOUNT_ADDRESS,
},
// highlight-start
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
// highlight-end
);
```

</TabItem>
</Tabs>

<Tx />

## createObject <ApiTypes type="Storage Provider" /> <ApiTypes type="Tx" />
## createObject

<!-- <ApiTypes type="Storage Provider" /> <ApiTypes type="Tx" /> -->

Get approval of creating object and send createObject txn to greenfield chain.
Creating object and send createObject txn to greenfield chain.

| params | description |
| --------------- | ----------------------------------------------------------------------- |
| bucketName | bucket name |
| objectName | object name |
| creator | the creator of object |
| visibility | [VisibilityType](/types/visibility) |
| fileType | [file type](https://developer.mozilla.org/en-US/docs/Web/API/File/type) |
| contentType | [file type](https://developer.mozilla.org/en-US/docs/Web/API/File/type) |
| redundancyType | [RedundancyType](/types/redundancy) |
| authType | [AuthType](/client/sp-client#authtype) |
| contentLength | file content length |
| expectCheckSums | file's expectCheckSums |
| tags | defines a list of tags which will be set to the object |

<Tabs groupId="example">
<TabItem value="Browser" label="Browser">
| payloadSize | file content [Long](/types/long)length |
| expectChecksums | file's expectChecksums |

```jsx
// https://github.com/bnb-chain/greenfield-js-sdk/blob/main/examples/nextjs/src/components/object/create/index.tsx#L76-L95
const tx = await client.object.createObject(
{
bucketName: 'bucket_name',
objectName: 'object_name',
creator: '0x...',
visibility: 'VISIBILITY_TYPE_PRIVATE',
fileType: 'json',
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength: 13311,
expectCheckSums: JSON.parse(expectCheckSums),
tags: {
tags: [],
},
},
// highlight-start
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
address,
},
// highlight-end
visibility: VisibilityType.VISIBILITY_TYPE_PRIVATE,
contentType: 'json',
redundancyType: RedundancyType.REDUNDANCY_EC_TYPE,
payloadSize: Long.fromInt(13311),
expectCheckSums: expectCheckSums.map((x) => bytesFromBase64(x)),
}
);
```
</TabItem>
<TabItem value="Nodejs" label="Nodejs">

```js
// https://github.com/bnb-chain/greenfield-js-sdk/blob/main/examples/nodejs/cases/storage.js#L61-L76
const tx = await client.object.createObject(
{
bucketName: bucketName,
objectName: objectName,
creator: ACCOUNT_ADDRESS,
visibility: 'VISIBILITY_TYPE_PRIVATE',
fileType: fileType,
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength,
expectCheckSums: JSON.parse(expectCheckSums),
},
// highlight-start
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
},
// highlight-end
);
```

</TabItem>
</Tabs>

<Tx />

Expand Down
15 changes: 0 additions & 15 deletions doc-site/docs/client/greenfield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ title: 'Greenfield Client'
sidebar_position: 1
---

# Create Greenfield Client

| params | description |
| -------------- | ------------------- |
Expand All @@ -13,23 +12,9 @@ sidebar_position: 1

```js
import { Client } from '@bnb-chain/greenfield-js-sdk';

// Node.js
const client = Client.create(GRPC_URL, GREEN_CHAIN_ID);

// Browser
const client = Client.create(GRPC_URL, String(GREEN_CHAIN_ID), {
zkCryptoUrl:
'https://unpkg.com/@bnb-chain/[email protected]/dist/node/zk-crypto.wasm',
});
```

:::tip

The browser needs to load wasm manually.

:::

The JS SDK consists of two parts:

- Chain: https://docs.bnbchain.org/greenfield-docs/docs/api/blockchain-rest
Expand Down
3 changes: 1 addition & 2 deletions doc-site/docs/constants/msg-type-url.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ title: Message Type URL

The specific type urls you want look up. Leave empty to get all entries.

More details:
https://github.com/bnb-chain/greenfield-js-sdk/blob/alpha/packages/js-sdk/src/constants/typeUrl.ts
More details: [typeUrl](https://github.com/bnb-chain/greenfield-js-sdk/blob/alpha/packages/js-sdk/src/constants/typeUrl.ts)
15 changes: 10 additions & 5 deletions doc-site/docs/getting-started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ slug: /

You can find some package documentation below:

| Package | Description | Version |
| Package | Description | Version |
| --- | --- | --- |
| [@bnb-chain/greenfield-js-sdk](https://github.com/bnb-chain/greenfield-js-sdk/tree/main/packages/js-sdk/README.md) | A client library for Greenfield Chain | [![npm](https://img.shields.io/npm/v/%40bnb-chain%2Fgreenfield-js-sdk?color=blue)](https://www.npmjs.com/package/@bnb-chain/greenfield-js-sdk) |
| [@bnb-chain/reed-solomon](https://github.com/bnb-chain/greenfield-js-sdk/tree/main/packages/reed-solomon) | calculate file's `checksums` | [![npm](https://img.shields.io/npm/v/%40bnb-chain%2Freed-solomon?color=blue)](https://www.npmjs.com/package/@bnb-chain/reed-solomon) |
| [@bnb-chain/greenfield-zk-crypto](https://github.com/bnb-chain/greenfield-js-sdk/tree/main/packages/zk-crypto/README.md) | WASM module about sign crypto | [![npm](https://img.shields.io/npm/v/%40bnb-chain%2Fgreenfield-zk-crypto?color=blue)](https://www.npmjs.com/package/@bnb-chain/greenfield-zk-crypto) |
| [@bnb-chain/create-gnfd-app](https://github.com/bnb-chain/greenfield-js-sdk/tree/main/packages/create-gnfd-app/README.md) | Create Greenfield App Quickly | [![npm](https://img.shields.io/npm/v/%40bnb-chain%2Fcreate-gnfd-app?color=blue)](https://www.npmjs.com/package/@bnb-chain/create-gnfd-app) |

## Playground

* [Browser](https://codesandbox.io/p/github/rrr523/greenfield-nextjs-template/main?import=true)
<!-- TODO: after upgrade SDK version -->
<!-- * [Nodejs](https://codesandbox.io/p/devbox/nodejs-greenfield-js-sdk-demo-wd5zft) -->

## Online Examples

* [Nextjs](https://codesandbox.io/p/github/rrr523/greenfield-nextjs-template/main)
* [Create React App](https://codesandbox.io/p/github/rrr523/greenfield-cra-template/main)
* [Nextjs](https://codesandbox.io/p/github/rrr523/greenfield-nextjs-template/main?import=true)
* [Vite](https://codesandbox.io/p/github/rrr523/greenfield-vite-template/main)
* [Create React App](https://codesandbox.io/p/github/rrr523/greenfield-cra-template/main?import=true)

## Supported JS environments

Expand All @@ -36,7 +41,7 @@ You can find some package documentation below:
```

2. Build package:

```bash
> pnpm run build
```

6 changes: 6 additions & 0 deletions doc-site/docs/types/long.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: long
title: Long
---

[long](https://www.npmjs.com/package/long): Bignumber
Loading

0 comments on commit fcd7bf3

Please sign in to comment.