Skip to content

Commit

Permalink
POAP Package documentation updated (#66)
Browse files Browse the repository at this point in the history
* Adding new documentation

* Adding new documentation

* Adding new documentation

* Adding new documentation

* Adding new documentation

* Adding new documentation

* Adding new documentation

* Adding new documentation

* Deleted unused reference to protocol and put all poap to POAP

* Added link to docuemntation

* Added link to docuemntation

* Added link to docuemntation

* Adding new documentation

* Adding new documentation
  • Loading branch information
rlajous authored Oct 5, 2023
1 parent c23696e commit 45060a7
Show file tree
Hide file tree
Showing 26 changed files with 1,268 additions and 71 deletions.
1 change: 1 addition & 0 deletions docs/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# POAP.js Documentation Website

This is a documentation website for POAP.js, a library for integrating with the POAP (Proof of Attendance Protocol) platform in JavaScript applications.
This is a documentation website for POAP.js, a library for integrating with the POAP platform in JavaScript applications.

## Getting Started

Expand Down
62 changes: 48 additions & 14 deletions docs/pages/packages/poaps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,83 @@

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

`@poap-xyz/poaps` is a package to fetch information about POAPs tokens, their on-chain data, their related drop and metadata.
`@poap-xyz/poaps` is a JavaScript library providing an interface for interacting with POAPs , making it easy to fetch information about POAP tokens like their on-chain data, their related drop information and metadata.

## Features

- Fetch a single POAP token,
- Search over minted POAPs by their collector or the drop they belong.
- Fetch one or multiple POAP tokens at once.
- Search over minted POAPs by their collector or the drop they belong to.
- Mint POAPs synchronously or asynchronously mint processes.
- Reserve a POAP to an email address.
- Obtain mint status, POAP indexed status, and more.

## Installation

This package doesn't require any additional dependencies for installation.

### NPM

```bash
npm install @poap-xyz/poaps @poap-xyz/utils @poap-xyz/providers axios form-data
npm install @poap-xyz/poaps
```

### Yarn

```bash
yarn add @poap-xyz/poaps @poap-xyz/utils @poap-xyz/providers axios form-data
yarn add @poap-xyz/poaps
```

## Usage

```javascript
import { PoapsClient } from '@poap-xyz/poaps';
import { PoapCompass } from '@poap-xyz/providers';

const client = new PoapsClient(new PoapCompass('you_api_key'));

import { PoapsClient } from '@poap-xyz/poaps';
import {
AuthenticationProviderHttp,
PoapCompass,
PoapTokenApi,
} from '@poap-xyz/providers';

// Create a new instance of PoapsClient
const client = new PoapsClient(
new PoapCompass({
apiKey: 'YOUR_COMPASS_API_KEY',
}),
new PoapTokenApi({
apiKey: 'YOUR_POAP_TOKEN_API_KEY',
authenticationProvider: new AuthenticationProviderHttp(
'YOUR_CLIENT_ID',
'YOUR_CLIENT_SECRET',
),
}),
);
```

## Documentation

For more detailed documentation, please visit [this link](https://documentation.poap.tech/docs).
Detailed documentation for each class, method, and type exported by this package can be found in the [PoapsClient Documentation](#poapsclient-documentation-section).

## Examples

For example scripts and usage, please check the [examples](https://github.com/poap-xyz/poap.js/tree/main/examples).
For example scripts and usage, please check the [examples](https://github.com/poap-xyz/poap.js/tree/main/examples) directory in the GitHub repository.

## Contributing

We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines.
We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines on how to get involved.

## License

@poap-xyz/drops is released under the [MIT License](https://opensource.org/licenses/MIT).
@poap-xyz/poaps is released under the [MIT License](https://opensource.org/licenses/MIT).

## Exports

- [`PoapsClient`](/packages/poaps/PoapsClient)
- [`POAP`](/packages/poaps/POAP)
- [`POAPReservation`](/packages/poaps/POAPReservation)
- [`FetchPoapsInput`](/packages/poaps/Inputs#fetchpoapsinput)
- [`WalletMintInput`](/packages/poaps/Inputs#walletmintinput)
- [`EmailReservationInput`](/packages/poaps/Inputs#emailreservationinput)
- [`PoapMintStatus`](/packages/poaps/responses/PoapMintStatus)
- [`PoapsSortFields`](/packages/poaps/Inputs#PoapsSortFields)
- [`CodeAlreadyMintedError`](/packages/poaps/Errors#codeAlreadyMintedError)
- [`CodeExpiredError`](/packages/poaps/Errors#codeExpiredError)
- [`FinishedWithError`](/packages/poaps/Errors#finishedWithError)
141 changes: 141 additions & 0 deletions docs/pages/packages/poaps/Errors.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Error Handling Documentation

This section documents the custom error classes defined for handling specific error scenarios while interacting with POAP tokens.

## CodeAlreadyMintedError

The `CodeAlreadyMintedError` class is thrown when an attempt is made to mint a POAP token using a mint code that has already been used.

```typescript
export class CodeAlreadyMintedError extends Error {
constructor(code: string) {
super(`Code: '${code}' already minted `);
}
}
```

## CodeExpiredError

The `CodeExpiredError` class is thrown when an attempt is made to use a mint code that has expired.

```typescript
export class CodeExpiredError extends Error {
constructor(code: string) {
super(`Code: '${code}', has been expired`);
}
}
```

## FinishedWithError

The `FinishedWithError` class is thrown when a minting operation encounters an error.

```typescript
export class FinishedWithError extends Error {
constructor(error: string, code: string) {
super(
`Code: '${code}', finished with error: '${error}', please try again later `,
);
}
}
```

## Usage

These custom error classes allow for more precise error handling and better debugging, by providing specific error messages based on the type of error encountered. They extend the native JavaScript `Error` class and can be used in a similar manner, with the added benefit of POAP-specific error messages.

### Example Usage

Below are examples demonstrating how one might use the `PoapsClient` class along with the custom error handling.

```typescript
// Importing necessary classes and error types
import {
PoapsClient,
WalletMintInput,
EmailReservationInput,
} from '@poap-xyz/poap-client';
import {
CodeAlreadyMintedError,
CodeExpiredError,
FinishedWithError,
} from '@poap-xyz/poap-errors';

// Initializing the PoapsClient with providers
const poapsClient = new PoapsClient(compassProvider, tokensApiProvider);

// Defining the WalletMintInput
const walletMintInput: WalletMintInput = {
mintCode: 'some-mint-code',
address: '0x1234567890abcdef1234567890abcdef12345678',
};

// Defining the EmailReservationInput
const emailReservationInput: EmailReservationInput = {
mintCode: 'some-other-mint-code',
email: '[email protected]',
};

// Attempting to mint a POAP token synchronously
async function mintPoap() {
try {
const poap = await poapsClient.mintSync(walletMintInput);
console.log('POAP minted successfully:', poap);
} catch (error) {
if (error instanceof FinishedWithError) {
console.error('Error concluding the mint process:', error.message);
// Action: Notify the user about the error and suggest retrying later.
} else {
console.error('An unknown error occurred:', error.message);
// Action: Log the error and notify the user of a general error.
}
}
}

// Attempting to get the secret code for a mint code
async function getSecret() {
try {
const secretCode = await poapsClient.getSecretCode(
walletMintInput.mintCode,
);
console.log('Secret code retrieved:', secretCode);
} catch (error) {
if (error instanceof CodeAlreadyMintedError) {
console.error('This mint code has already been used:', error.message);
// Action: Notify the user that the mint code has already been used.
} else if (error instanceof CodeExpiredError) {
console.error('This mint code has expired:', error.message);
// Action: Notify the user that the mint code has expired.
} else {
console.error('An unknown error occurred:', error.message);
// Action: Log the error and notify the user of a general error.
}
}
}

// Attempting to reserve a POAP via email
async function reservePoap() {
try {
const reservation = await poapsClient.emailReservation(
emailReservationInput,
);
console.log('POAP reserved successfully:', reservation);
} catch (error) {
if (error instanceof CodeAlreadyMintedError) {
console.error('This mint code has already been used:', error.message);
// Action: Notify the user that the mint code has already been used.
} else if (error instanceof CodeExpiredError) {
console.error('This mint code has expired:', error.message);
// Action: Notify the user that the mint code has expired.
} else {
console.error('An unknown error occurred:', error.message);
// Action: Log the error and notify the user of a general error.
}
}
}

// Executing the mintPoap, getSecret, and reservePoap functions
mintPoap();
getSecret();
reservePoap();
```
84 changes: 84 additions & 0 deletions docs/pages/packages/poaps/Inputs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Input Types Documentation

This section documents the input types used to fetch and manage POAPs .

## PoapsSortFields

The `PoapsSortFields` enumeration defines the available fields by which POAPs can be sorted.

| Property | Value | Description |
| ---------- | ----------- | ------------------------------------------------------ |
| `MintedOn` | `minted_on` | Represents sorting by the date when a POAP was minted. |
| `Id` | `id` | Represents sorting by the ID of a POAP. |

```typescript
export enum PoapsSortFields {
MintedOn = 'minted_on',
Id = 'id',
}
```

## FetchPoapsInput

The `FetchPoapsInput` interface represents the input fields for fetching POAPs and extends `PaginationInput` to provide pagination capability.

| Property | Type | Description |
| --------------------- | ------------------ | ---------------------------------------------------------- |
| `name` | `string?` | Optional filter for the name of a POAP. |
| `chain` | `Chain?` | Optional filter for the blockchain chain of a POAP. |
| `mintedDateFrom` | `string?` | Optional filter for the start date when a POAP was minted. |
| `mintedDateTo` | `string?` | Optional filter for the end date when a POAP was minted. |
| `ids` | `number[]?` | Optional filter for specific POAP IDs. |
| `collectorAddress` | `string?` | Optional filter for the collector's address. |
| `dropId` | `number?` | Optional filter for a specific drop ID. |
| `sortField` | `PoapsSortFields?` | Field by which to sort the results. |
| `sortDir` | `Order?` | Direction in which to sort the results. |
| `filterByZeroAddress` | `boolean?` | Filter to include/exclude POAPs with zero addresses. |

```typescript
export interface FetchPoapsInput extends PaginationInput {
name?: string;
chain?: Chain;
mintedDateFrom?: string;
mintedDateTo?: string;
ids?: number[];
collectorAddress?: string;
dropId?: number;
sortField?: PoapsSortFields;
sortDir?: Order;
filterByZeroAddress?: boolean;
}
```

## WalletMintInput

The `WalletMintInput` interface represents the input fields required to mint a POAP for an Ethereum wallet address.

| Property | Type | Description |
| ---------- | -------- | ---------------------------------------------- |
| `mintCode` | `string` | The mint code for the POAP. |
| `address` | `string` | The address of the wallet to mint the POAP to. |

```typescript
export interface WalletMintInput {
mintCode: string;
address: string;
```
## EmailReservationInput
The `EmailReservationInput` interface represents the input fields required to reserve a POAP via email.
| Property | Type | Description |
| ----------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mintCode` | `string` | The mint code for the POAP, essential for identifying the specific POAP being reserved. |
| `email` | `string` | The email address for reserving the POAP, where the reservation confirmation and next steps will be sent. |
| `sendEmail` | `boolean?` | Optional field to specify whether to send an email notification. If set to true or omitted, an email containing the next steps will be sent to the provided email address. If set to false, no email will be sent, although the POAP is still reserved. |
```typescript
export interface EmailReservationInput {
mintCode: string;
email: string;
sendEmail?: boolean;
}
```
57 changes: 57 additions & 0 deletions docs/pages/packages/poaps/POAP.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# POAP

## Description

The `POAP` class represents a POAP token with various attributes pertaining to the token itself, the drop it's associated with, and its ownership details.

## Constructor

```typescript
constructor(properties: PoapProperties)
```

Creates a new instance of the `POAP` class with specified properties.

### Parameters

- `properties` (`PoapProperties`): An object containing all necessary properties to initialize the `POAP` instance.

## Properties

| Property | Type | Description |
| ------------------ | -------- | ------------------------------------------------------------------------ |
| `id` | `number` | The unique identifier of the POAP token. |
| `collectorAddress` | `string` | The address of the collector owning the POAP token. |
| `transferCount` | `number` | The number of times the POAP token has been transferred. |
| `mintedOn` | `Date` | The date and time when the POAP token was minted. |
| `dropId` | `number` | The identifier of the drop associated with the POAP token. |
| `imageUrl` | `string` | The URL of the image representing the POAP token or the associated drop. |
| `city` | `string` | The city where the associated drop took place. |
| `country` | `string` | The country where the associated drop took place. |
| `description` | `string` | A description of the associated drop or the POAP token. |
| `startDate` | `Date` | The start date of the associated drop. |
| `endDate` | `Date` | The end date of the associated drop. |
| `name` | `string` | The name of the associated drop. |

## PoapProperties Interface

The `PoapProperties` interface defines the shape of the object required by the constructor of the `POAP` class.

```typescript
interface PoapProperties {
id: number;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
startDate: Date;
name: string;
endDate: Date;
}
```

Each property in the `PoapProperties` interface corresponds to a property in the `POAP` class, and their descriptions are as mentioned above in the Properties section.
Loading

0 comments on commit 45060a7

Please sign in to comment.