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

Refactor types and exports #128

Merged
merged 12 commits into from
Jun 27, 2024
5 changes: 5 additions & 0 deletions docs/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
- Compass throws errors on malformed requests/queries.
- Fetch moments order must be value from enum `Order` instead of string.
- Rename POAP client fetch prop `filterByZeroAddress` to `filterZeroAddress`.

## 0.5.0

- Packages do not export input types anymore.
- Drop properties are not exported anymore.
20 changes: 9 additions & 11 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
>
> **Warning**
>
> [!WARNING]
>
> The POAP SDK is still in active initial development phase. Anything MAY change at any time.
>
>
> This is a Developer Preview aimed primarily at existing integrators so to gather early feedback.
> Documentation is in progress.
>
>
> This product is in development and is not intended to be used in a production environment.
>
> If you want to collaborate and leave us feedback you can do it so [here](https://github.com/poap-xyz/poap.js/discussions/19)

>
> If you want to collaborate and leave us feedback you can do it so [here](https://github.com/poap-xyz/poap.js/discussions/19).

# Introduction

Expand All @@ -19,23 +17,23 @@ Welcome! We're excited you're here!

You're on your way to building an awesome integration! Here's some of the things you'll want to check out.

**Overview**
## Overview

POAP is a public good, built on behalf of every human, to empower the individual with a reliable system for preserving memories and recognizing contributions to the collective happiness and well-being of the people around them.

Developers are the unsung heroes behind this public good. While POAP Inc builds the tech, developers build the vibrant ecosystem of applications that connect communities and create new avenues for curated participation.

POAP is curated ecosystem for the preservation of memories. The platform provides the infrastructure for issuers to mint and distribute digital collectables that mark life’s most memorable moments.

#### What is POAP?
## What is POAP?

POAP is a protocol for the preservation of memories as digital records, minted as non-fungible tokens on the blockchain under the ERC-721 standard.

The POAP platform offers numerous functionalities exposed through an API. Everyone is free to use POAP's API to obtain information regarding POAPs minted, drops created, etc.

Additionally, you can use the API to create your applications on top of POAP by automating POAP distributions. For this, you will need API authorization tokens. Please refer to [Authentication](https://documentation.poap.tech/docs/authentication) for more information on requesting authorization tokens.

[Learn more about POAP](https://poap.zendesk.com/hc/en-us/articles/9494654007437-What-Is-POAP-)
[Learn more about POAP](https://poap.zendesk.com/hc/en-us/articles/9494654007437-What-Is-POAP-).

Before using our API, we suggest a quick read through our [Help Center](https://poap.zendesk.com/hc/en-us) in order to better understand the POAP ecosystem.

Expand Down
20 changes: 10 additions & 10 deletions docs/pages/packages/drops.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @poap-xyz/drops
# `@poap-xyz/drops`

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

@poap-xyz/drops is a package to interact with POAP Drops.
`@poap-xyz/drops` is a package to interact with POAP Drops.

## Features

Expand All @@ -28,14 +28,14 @@ yarn add @poap-xyz/drops @poap-xyz/utils @poap-xyz/providers axios

## Usage

```javascript
import { DropsClient } from '@poap-xyz/drops';
import { PoapCompass, PoapDropApi } from '@poap-xyz/providers';
```typescript
import { DropsClient } from '@poap-xyz/drops';
import { PoapCompass, PoapDropApi } from '@poap-xyz/providers';

const client = new DropsClient(
new PoapCompass('you_api_key'),
new PoapDropApi('your_api_key'),
);
const client = new DropsClient(
new PoapCompass('YOUR_COMPASS_API_KEY'),
new PoapDropApi('YOUR_POAP_API_KEY'),
);
```

## Documentation
Expand All @@ -52,4 +52,4 @@ We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines.

## License

@poap-xyz/drops is released under the [MIT License](https://opensource.org/licenses/MIT).
`@poap-xyz/drops` is released under the [MIT License](https://opensource.org/licenses/MIT).
4 changes: 2 additions & 2 deletions docs/pages/packages/frames.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @poap-xyz/frames
# `@poap-xyz/frames`

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

@poap-xyz/frames is a package to ease the use of [Farcaster Frames](https://docs.farcaster.xyz/learn/what-is-farcaster/frames).
`@poap-xyz/frames` is a package to ease the use of [Farcaster Frames](https://docs.farcaster.xyz/learn/what-is-farcaster/frames).

## Features

Expand Down
27 changes: 7 additions & 20 deletions docs/pages/packages/moments.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# @poap-xyz/moments
# `@poap-xyz/moments`

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

@poap-xyz/moments is a package to interact with POAP Moments.
`@poap-xyz/moments` is a package to interact with POAP Moments.

## Features

Expand All @@ -27,27 +27,14 @@ yarn add @poap-xyz/moments @poap-xyz/utils @poap-xyz/providers axios

## Usage

```javascript
import { MomentsClient, createMomentInput, Moment } from '@poap-xyz/moments';
```typescript
import { MomentsClient } from '@poap-xyz/moments';
import { PoapCompass, PoapMomentsApi } from '@poap-xyz/providers';
import fs from 'fs';

const client = new MomentsClient(
new PoapMomentsApi('your_api_key'),
new PoapCompass('your_api_key'),
new PoapMomentsApi('YOUR_MOMENTS_API_KEY'),
new PoapCompass('YOUR_COMPASS_API_KEY'),
);

const input: createMomentInput = {
dropId: 110148,
/**
* The Token ID related to the moment (Optional)
*/
tokenId: 6568008,
file: await fs.promises.readFile('src/assets/poap.png'),
author: '0x82AB2941Cf555CED5ad7Ed232a5B5f6083815FBC',
mimeType: 'image/png',
};
const moment: Moment = await client.createMoment(input);
```

## Documentation
Expand All @@ -64,4 +51,4 @@ We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines.

## License

@poap-xyz/moments is released under the [MIT License](https://opensource.org/licenses/MIT).
`@poap-xyz/moments` is released under the [MIT License](https://opensource.org/licenses/MIT).
22 changes: 22 additions & 0 deletions docs/pages/packages/moments/UploadMoments.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Upload Moments

A moment can contain an image and/or text. With `MomentsClient` is easy to
upload an image and create it as a moment associated with a Drop or a POAP.

## From Node.js

```typescript
import fsPromises from 'fs/promises';
import { Moment } from '@poap-xyz/moments';

const moment: Moment = await client.createMoment({
dropId: 110148,
/**
* The Token ID related to the moment (Optional)
*/
tokenId: 6568008,
mimeType: 'image/png',
file: await fsPromises.readFile('path/to/file.png'),
author: '0x82AB2941Cf555CED5ad7Ed232a5B5f6083815FBC',
});
```
3 changes: 3 additions & 0 deletions docs/pages/packages/moments/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"UploadMoments": "Upload Moments"
}
22 changes: 4 additions & 18 deletions docs/pages/packages/poaps.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @poap-xyz/poaps
# `@poap-xyz/poaps`

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

Expand Down Expand Up @@ -30,7 +30,7 @@ yarn add @poap-xyz/poaps

## Usage

```javascript
```typescript
import { PoapsClient } from '@poap-xyz/poaps';
import {
AuthenticationProviderHttp,
Expand All @@ -55,7 +55,7 @@ const client = new PoapsClient(

## Documentation

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

## Examples

Expand All @@ -67,18 +67,4 @@ We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines o

## License

@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)
`@poap-xyz/poaps` is released under the [MIT License](https://opensource.org/licenses/MIT).
154 changes: 24 additions & 130 deletions docs/pages/packages/poaps/Errors.mdx
Original file line number Diff line number Diff line change
@@ -1,141 +1,35 @@
# Error Handling Documentation
# Error Handling

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

Below are examples demonstrating how one might use the `PoapsClient` class along with the custom error handling.
Below example demonstrates 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.
}
import { FinishedWithError } from '@poap-xyz/poaps';

try {
const poap = await client.mintSync({
mintCode: 'some-mint-code',
address: '0x1234567890abcdef1234567890abcdef12345678',
});
console.info('POAP minted successfully', poap);
} catch (error: unknown) {
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 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();
```
Loading