diff --git a/docs/.nvmrc b/docs/.nvmrc new file mode 100644 index 00000000..0828ab79 --- /dev/null +++ b/docs/.nvmrc @@ -0,0 +1 @@ +v18 \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 5ae76bd4..a3d6f2ed 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/docs/pages/packages/poaps.mdx b/docs/pages/packages/poaps.mdx index 2a2591e9..aa49a16d 100644 --- a/docs/pages/packages/poaps.mdx +++ b/docs/pages/packages/poaps.mdx @@ -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) diff --git a/docs/pages/packages/poaps/Errors.mdx b/docs/pages/packages/poaps/Errors.mdx new file mode 100644 index 00000000..81a8ca91 --- /dev/null +++ b/docs/pages/packages/poaps/Errors.mdx @@ -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: 'example@example.com', +}; + +// 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(); +``` diff --git a/docs/pages/packages/poaps/Inputs.mdx b/docs/pages/packages/poaps/Inputs.mdx new file mode 100644 index 00000000..b7e9338e --- /dev/null +++ b/docs/pages/packages/poaps/Inputs.mdx @@ -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; +} +``` diff --git a/docs/pages/packages/poaps/POAP.mdx b/docs/pages/packages/poaps/POAP.mdx new file mode 100644 index 00000000..1c992e1c --- /dev/null +++ b/docs/pages/packages/poaps/POAP.mdx @@ -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. diff --git a/docs/pages/packages/poaps/POAPReservation.mdx b/docs/pages/packages/poaps/POAPReservation.mdx new file mode 100644 index 00000000..43aaf115 --- /dev/null +++ b/docs/pages/packages/poaps/POAPReservation.mdx @@ -0,0 +1,51 @@ +# POAPReservation + +## Description + +The `POAPReservation` class represents a reservation of a POAP token associated with an email address. This class encapsulates details about the event for which the POAP token is reserved. + +## Constructor + +```typescript +constructor(properties: POAPReservationProperties) +``` + +Creates a new instance of the `POAPReservation` class with the specified properties. + +### Parameters + +- `properties` (`POAPReservationProperties`): An object containing all necessary properties to initialize the `POAPReservation` instance. + +## Properties + +| Property | Type | Description | +| ------------- | -------- | ------------------------------------------------------------------------------- | +| `email` | `string` | The email address where the POAP token is reserved. | +| `dropId` | `number` | The identifier of the drop associated with the POAP reservation. | +| `imageUrl` | `string` | The URL of the image representing the POAP reservation or the associated event. | +| `city` | `string` | The city where the associated event took place. | +| `country` | `string` | The country where the associated event took place. | +| `description` | `string` | A description of the associated event or the POAP reservation. | +| `startDate` | `Date` | The start date of the associated event. | +| `endDate` | `Date` | The end date of the associated event. | +| `name` | `string` | The name of the associated event or the POAP reservation. | + +## POAPReservationProperties Interface + +The `POAPReservationProperties` interface defines the shape of the object required by the constructor of the `POAPReservation` class. + +```typescript +interface POAPReservationProperties { + email: string; + dropId: number; + imageUrl: string; + city: string; + country: string; + description: string; + startDate: Date; + name: string; + endDate: Date; +} +``` + +Each property in the `POAPReservationProperties` interface corresponds to a property in the `POAPReservation` class, and their descriptions are as mentioned above in the Properties section. diff --git a/docs/pages/packages/poaps/PoapsClient.mdx b/docs/pages/packages/poaps/PoapsClient.mdx new file mode 100644 index 00000000..4f34789a --- /dev/null +++ b/docs/pages/packages/poaps/PoapsClient.mdx @@ -0,0 +1,201 @@ +# PoapsClient + +## Description + +`PoapsClient` is a class representing a client for interacting with POAPs . + +## Constructor + +```typescript +constructor( + private compassProvider: CompassProvider, + private tokensApiProvider: TokensApiProvider +) +``` + +- `compassProvider` (`CompassProvider`): The provider for the POAP compass API. +- `tokensApiProvider` (`TokensApiProvider`): The provider for the Tokens API. + +## Methods + +### `fetch` + +```typescript +async fetch(input: FetchPoapsInput): Promise> +``` + +Fetches a list of [`POAP`](/packages/poaps/POAP) tokens based on the given input criteria. + +#### Parameters + +- `input` ([`FetchPoapsInput`](/packages/poaps/Inputs#fetchpoapsinput)): Criteria for fetching POAP tokens. + +#### Returns + +A promise that resolves to a paginated list of [`POAP`](/packages/poaps/POAP) tokens. + +### `getSecretCode` + +```typescript +private async getSecretCode(mintCode: string): Promise +``` + +Retrieves the secret code associated with a POAP code. + +#### Parameters + +- `mintCode` (`string`): The POAP code for which to get the secret. + +#### Returns + +A promise that resolves to the associated secret code. + +#### Throws + +- [`CodeAlreadyMintedError`](/packages/poaps/Errors#codeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](/packages/poaps/Errors#codeExpiredError): Thrown when the POAP code is expired. + +### `getMintCode` + +```typescript +async getMintCode(mintCode: string): Promise +``` + +Retrieves mint code details for a specific Mint Code. + +#### Parameters + +- `mintCode` (`string`): The Mint Code for which to get the mint code. + +#### Returns + +A promise that resolves to the mint code details, [`PoapMintStatus`](/packages/poaps/responses/PoapMintStatus). + +### `getMintStatus` + +```typescript +async getMintStatus(queueUid: string): Promise +``` + +Fetches the current status of a mint based on its unique ID. + +#### Parameters + +- `queueUid` (`string`): The unique ID of the mint. + +#### Returns + +A promise that resolves to the current status of the mint. + +### `waitMintStatus` + +```typescript +async waitMintStatus(queueUid: string, mintCode: string): Promise +``` + +Awaits until the mint's status changes from 'IN_PROCESS' or 'PENDING'. + +#### Parameters + +- `queueUid` (`string`): The unique ID of the mint. +- `mintCode` (`string`): The Mint Code for the mint. + +#### Returns + +A promise that resolves when the mint's status changes. + +### `waitPoapIndexed` + +```typescript +async waitPoapIndexed(mintCode: string): Promise +``` + +Awaits until a specific POAP, identified by its Mint Code, is indexed on our database. + +#### Parameters + +- `mintCode` (`string`): The Mint Code identifying the POAP to be indexed. + +#### Returns + +A promise that resolves to details of the indexed POAP, [`PoapMintStatus`](/packages/poaps/responses/PoapMintStatus). + +### `mintAsync` + +```typescript +async mintAsync(input: WalletMintInput): Promise +``` + +Begins an asynchronous mint process and provides a unique queue ID in return. + +#### Parameters + +- `input` ([`WalletMintInput`](/packages/poaps/Inputs#walletmintinput)): Details required for the mint. + +#### Returns + +A promise that resolves to a unique queue ID for the initiated mint. + +#### Throws + +- [`CodeAlreadyMintedError`](/packages/poaps/Errors#codeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](/packages/poaps/Errors#codeExpiredError): Thrown when the POAP code is expired. + +### `mintSync` + +```typescript +async mintSync(input: WalletMintInput): Promise +``` + +Starts a synchronous mint process. + +#### Parameters + +- `input` ([`WalletMintInput`](/packages/poaps/Inputs#walletmintinput)): Details needed for the mint. + +#### Returns + +A promise that resolves to the associated [`POAP`](/packages/poaps/POAP) upon successful mint completion. + +#### Throws + +- [`CodeAlreadyMintedError`](/packages/poaps/Errors#codeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](/packages/poaps/Errors#codeExpiredError): Thrown when the POAP code is expired. +- [`FinishedWithError`](/packages/poaps/Errors#finishedWithError): Thrown when a minting operation encounters an error. + +### `emailReservation` + +```typescript +async emailReservation( + input: EmailReservationInput +): Promise +``` + +Reserves a POAP to an email address and provides reservation details. + +#### Parameters + +- `input` ([`EmailReservationInput`](/packages/poaps/Inputs#emailreservationinput)): Information for the reservation. + +#### Returns + +A promise that resolves to the reservation details of the [`POAPReservation`](/packages/poaps/POAPReservation). + +#### Throws + +- [`CodeAlreadyMintedError`](/packages/poaps/Errors#codeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](/packages/poaps/Errors#codeExpiredError): Thrown when the POAP code is expired. + +## Related Types + +- [`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) diff --git a/docs/pages/packages/poaps/Responses.mdx b/docs/pages/packages/poaps/Responses.mdx new file mode 100644 index 00000000..fe9906a9 --- /dev/null +++ b/docs/pages/packages/poaps/Responses.mdx @@ -0,0 +1,27 @@ +# Responses Documentation + +This section documents the response types defined for managing and interacting with POAPs . + +## PoapMintStatus + +The `PoapMintStatus` interface represents the status of a minting operation for a POAP token. + +```typescript +export interface PoapMintStatus { + minted: boolean; + isActive: boolean; + secretCode: string; + poapId: number; +} +``` + +### Properties + +| Property | Type | Description | +| ------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------- | +| `minted` | `boolean` | Indicates whether the POAP token has been minted. | +| `isActive` | `boolean` | Indicates whether the mint code is active. | +| `secretCode` | `string` | The secret code associated with the minting operation. This code is required to mint a POAP token to a wallet. | +| `poapId` | `number` | The identifier of the minted POAP token. This ID is unique to each POAP token and can be used to fetch further details about the token. | + +The `PoapMintStatus` interface is crucial for understanding the result of a minting operation, providing essential information about the mint status, and the details of the minted POAP token. diff --git a/docs/pages/packages/poaps/_meta.json b/docs/pages/packages/poaps/_meta.json new file mode 100644 index 00000000..b2930375 --- /dev/null +++ b/docs/pages/packages/poaps/_meta.json @@ -0,0 +1,8 @@ +{ + "Errors": "Errors", + "Inputs": "Inputs", + "POAP": "POAP", + "POAPReservation": "POAP Reservation", + "PoapsClient": "POAPs Client", + "Responses": "Responses" +} diff --git a/examples/poaps/backend/src/index.ts b/examples/poaps/backend/src/index.ts index 54f004a5..779dbf8b 100644 --- a/examples/poaps/backend/src/index.ts +++ b/examples/poaps/backend/src/index.ts @@ -33,31 +33,31 @@ async function main(): Promise { ), }), ); - // Multiple Poaps + // Multiple POAPs await measurePerformance( () => fetch_multiple_poaps(client), 'fetch_multiple_poaps', ); - // One Poap by id + // One POAP by id await measurePerformance( () => fetch_single_poap(client), 'fetch_single_poap', ); - // Multiple Poaps by collector + // Multiple POAPs by collector await measurePerformance( () => fetch_multiple_poaps_by_collector(client), 'fetch_multiple_poaps_by_collector', ); - // Multiple Poaps by drop + // Multiple POAPs by drop await measurePerformance( () => fetch_multiple_poaps_by_drop_id(client), 'fetch_multiple_poaps_by_drop_id', ); - // mint Sync Poap + // mint Sync POAP await measurePerformance(() => mint_sync_poap(client), 'mint_sync_poap'); - // mint Async Poap + // mint Async POAP await measurePerformance(() => mint_async_poap(client), 'mint_async_poap'); - // Email Reservation Poap + // Email Reservation POAP await measurePerformance( () => email_reservation_poap(client), 'email_reservation_poap', diff --git a/examples/poaps/backend/src/methods/mint_async_poap.ts b/examples/poaps/backend/src/methods/mint_async_poap.ts index 55f74483..d12ee59e 100644 --- a/examples/poaps/backend/src/methods/mint_async_poap.ts +++ b/examples/poaps/backend/src/methods/mint_async_poap.ts @@ -2,7 +2,7 @@ import { PoapsClient } from '@poap-xyz/poaps'; import { handleError } from '../utils/handleError'; /** - * Attempts to mint a POAP (Proof of Attendance Protocol) token asynchronously based on a predefined QR hash and address. + * Attempts to mint a POAP token asynchronously based on a predefined Mint Code and address. * After successfully minting, the function fetches and logs the details of the minted POAP. * In the event of an error during the process, the error is captured and managed by a separate utility function. * @@ -24,7 +24,7 @@ export const mint_async_poap = async (client: PoapsClient): Promise => { // Wait for the mint's status to transition from 'IN_PROCESS' or 'PENDING' states await client.waitMintStatus(queueUid, 'your_mint_code'); - // Wait for the minted POAP to be indexed and fetch the mint code information related to the QR hash + // Wait for the minted POAP to be indexed and fetch the mint code information related to the Mint Code const getMintCodeResponse = await client.waitPoapIndexed('your_mint_code'); // Retrieve and log the specifics of the minted POAP diff --git a/packages/poaps/README.md b/packages/poaps/README.md index 2a2591e9..9f722a9f 100644 --- a/packages/poaps/README.md +++ b/packages/poaps/README.md @@ -2,49 +2,81 @@ [![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`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/PoapsClient.md) +- [`POAP`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAP.md) +- [`POAPReservation`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAPReservation.md) +- [`FetchPoapsInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/FetchPoapsInput) +- [`PoapMintStatus`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/responses.md/PoapMintStatus) +- [`PoapsSortFields`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/PoapsSortFields) +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError) +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError) +- [`FinishedWithError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/FinishedWithError) diff --git a/packages/poaps/docs/Errors.md b/packages/poaps/docs/Errors.md new file mode 100644 index 00000000..81a8ca91 --- /dev/null +++ b/packages/poaps/docs/Errors.md @@ -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: 'example@example.com', +}; + +// 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(); +``` diff --git a/packages/poaps/docs/Inputs.md b/packages/poaps/docs/Inputs.md new file mode 100644 index 00000000..b7e9338e --- /dev/null +++ b/packages/poaps/docs/Inputs.md @@ -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; +} +``` diff --git a/packages/poaps/docs/POAP.md b/packages/poaps/docs/POAP.md new file mode 100644 index 00000000..1c992e1c --- /dev/null +++ b/packages/poaps/docs/POAP.md @@ -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. diff --git a/packages/poaps/docs/POAPReservation.md b/packages/poaps/docs/POAPReservation.md new file mode 100644 index 00000000..43aaf115 --- /dev/null +++ b/packages/poaps/docs/POAPReservation.md @@ -0,0 +1,51 @@ +# POAPReservation + +## Description + +The `POAPReservation` class represents a reservation of a POAP token associated with an email address. This class encapsulates details about the event for which the POAP token is reserved. + +## Constructor + +```typescript +constructor(properties: POAPReservationProperties) +``` + +Creates a new instance of the `POAPReservation` class with the specified properties. + +### Parameters + +- `properties` (`POAPReservationProperties`): An object containing all necessary properties to initialize the `POAPReservation` instance. + +## Properties + +| Property | Type | Description | +| ------------- | -------- | ------------------------------------------------------------------------------- | +| `email` | `string` | The email address where the POAP token is reserved. | +| `dropId` | `number` | The identifier of the drop associated with the POAP reservation. | +| `imageUrl` | `string` | The URL of the image representing the POAP reservation or the associated event. | +| `city` | `string` | The city where the associated event took place. | +| `country` | `string` | The country where the associated event took place. | +| `description` | `string` | A description of the associated event or the POAP reservation. | +| `startDate` | `Date` | The start date of the associated event. | +| `endDate` | `Date` | The end date of the associated event. | +| `name` | `string` | The name of the associated event or the POAP reservation. | + +## POAPReservationProperties Interface + +The `POAPReservationProperties` interface defines the shape of the object required by the constructor of the `POAPReservation` class. + +```typescript +interface POAPReservationProperties { + email: string; + dropId: number; + imageUrl: string; + city: string; + country: string; + description: string; + startDate: Date; + name: string; + endDate: Date; +} +``` + +Each property in the `POAPReservationProperties` interface corresponds to a property in the `POAPReservation` class, and their descriptions are as mentioned above in the Properties section. diff --git a/packages/poaps/docs/PoapsClient.md b/packages/poaps/docs/PoapsClient.md new file mode 100644 index 00000000..0afe6473 --- /dev/null +++ b/packages/poaps/docs/PoapsClient.md @@ -0,0 +1,201 @@ +# PoapsClient + +## Description + +`PoapsClient` is a class representing a client for interacting with POAPs . + +## Constructor + +```typescript +constructor( + private compassProvider: CompassProvider, + private tokensApiProvider: TokensApiProvider +) +``` + +- `compassProvider` (`CompassProvider`): The provider for the POAP compass API. +- `tokensApiProvider` (`TokensApiProvider`): The provider for the Tokens API. + +## Methods + +### `fetch` + +```typescript +async fetch(input: FetchPoapsInput): Promise> +``` + +Fetches a list of [`POAP`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAP.md) tokens based on the given input criteria. + +#### Parameters + +- `input` ([`FetchPoapsInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/FetchPoapsInput)): Criteria for fetching POAP tokens. + +#### Returns + +A promise that resolves to a paginated list of [`POAP`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAP.md) tokens. + +### `getSecretCode` + +```typescript +private async getSecretCode(mintCode: string): Promise +``` + +Retrieves the secret code associated with a POAP code. + +#### Parameters + +- `mintCode` (`string`): The POAP code for which to get the secret. + +#### Returns + +A promise that resolves to the associated secret code. + +#### Throws + +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError): Thrown when the POAP code is expired. + +### `getMintCode` + +```typescript +async getMintCode(mintCode: string): Promise +``` + +Retrieves mint code details for a specific Mint Code. + +#### Parameters + +- `mintCode` (`string`): The Mint Code for which to get the mint code. + +#### Returns + +A promise that resolves to the mint code details, [`PoapMintStatus`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/responses.md/PoapMintStatus). + +### `getMintStatus` + +```typescript +async getMintStatus(queueUid: string): Promise +``` + +Fetches the current status of a mint based on its unique ID. + +#### Parameters + +- `queueUid` (`string`): The unique ID of the mint. + +#### Returns + +A promise that resolves to the current status of the mint. + +### `waitMintStatus` + +```typescript +async waitMintStatus(queueUid: string, mintCode: string): Promise +``` + +Awaits until the mint's status changes from 'IN_PROCESS' or 'PENDING'. + +#### Parameters + +- `queueUid` (`string`): The unique ID of the mint. +- `mintCode` (`string`): The Mint Code for the mint. + +#### Returns + +A promise that resolves when the mint's status changes. + +### `waitPoapIndexed` + +```typescript +async waitPoapIndexed(mintCode: string): Promise +``` + +Awaits until a specific POAP, identified by its Mint Code, is indexed on our database. + +#### Parameters + +- `mintCode` (`string`): The Mint Code identifying the POAP to be indexed. + +#### Returns + +A promise that resolves to details of the indexed POAP, [`PoapMintStatus`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/responses.md/PoapMintStatus). + +### `mintAsync` + +```typescript +async mintAsync(input: WalletMintInput): Promise +``` + +Begins an asynchronous mint process and provides a unique queue ID in return. + +#### Parameters + +- `input` ([`WalletMintInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/WalletMintInput)): Details required for the mint. + +#### Returns + +A promise that resolves to a unique queue ID for the initiated mint. + +#### Throws + +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError): Thrown when the POAP code is expired. + +### `mintSync` + +```typescript +async mintSync(input: WalletMintInput): Promise +``` + +Starts a synchronous mint process. + +#### Parameters + +- `input` ([`WalletMintInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/WalletMintInput)): Details needed for the mint. + +#### Returns + +A promise that resolves to the associated [`POAP`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAP.md) upon successful mint completion. + +#### Throws + +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError): Thrown when the POAP code is expired. +- [`FinishedWithError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/FinishedWithError): Thrown when a minting operation encounters an error. + +### `emailReservation` + +```typescript +async emailReservation( + input: EmailReservationInput +): Promise +``` + +Reserves a POAP to an email address and provides reservation details. + +#### Parameters + +- `input` ([`EmailReservationInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/EmailReservationInput)): Information for the reservation. + +#### Returns + +A promise that resolves to the reservation details of the [`POAPReservation`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAPReservation.md). + +#### Throws + +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError): Thrown when the POAP code has already been minted. +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError): Thrown when the POAP code is expired. + +## Related Types + +- [`PoapsClient`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/PoapsClient.md) +- [`POAP`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAP.md) +- [`POAPReservation`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/POAPReservation.md) +- [`FetchPoapsInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/FetchPoapsInput) +- [`WalletMintInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/WalletMintInput) +- [`EmailReservationInput`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/EmailReservationInput) +- [`PoapMintStatus`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/responses.md/PoapMintStatus) +- [`PoapsSortFields`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/inputs.md/PoapsSortFields) +- [`CodeAlreadyMintedError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeAlreadyMintedError) +- [`CodeExpiredError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/CodeExpiredError) +- [`FinishedWithError`](https://github.com/poap-xyz/poap.js/tree/main/packages/poaps/docs/errors.md/FinishedWithError) diff --git a/packages/poaps/docs/Responses.md b/packages/poaps/docs/Responses.md new file mode 100644 index 00000000..fe9906a9 --- /dev/null +++ b/packages/poaps/docs/Responses.md @@ -0,0 +1,27 @@ +# Responses Documentation + +This section documents the response types defined for managing and interacting with POAPs . + +## PoapMintStatus + +The `PoapMintStatus` interface represents the status of a minting operation for a POAP token. + +```typescript +export interface PoapMintStatus { + minted: boolean; + isActive: boolean; + secretCode: string; + poapId: number; +} +``` + +### Properties + +| Property | Type | Description | +| ------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------- | +| `minted` | `boolean` | Indicates whether the POAP token has been minted. | +| `isActive` | `boolean` | Indicates whether the mint code is active. | +| `secretCode` | `string` | The secret code associated with the minting operation. This code is required to mint a POAP token to a wallet. | +| `poapId` | `number` | The identifier of the minted POAP token. This ID is unique to each POAP token and can be used to fetch further details about the token. | + +The `PoapMintStatus` interface is crucial for understanding the result of a minting operation, providing essential information about the mint status, and the details of the minted POAP token. diff --git a/packages/poaps/src/PoapsClient.ts b/packages/poaps/src/PoapsClient.ts index 697cdf4a..f77d8ff5 100644 --- a/packages/poaps/src/PoapsClient.ts +++ b/packages/poaps/src/PoapsClient.ts @@ -24,7 +24,7 @@ import { PoapIndexed } from './utils/PoapIndexed'; import { PoapMintStatus } from './types/response'; /** - * Represents a client for interacting with POAPs (Proof of Attendance Protocol tokens). + * Represents a client for interacting with POAPs . * @class */ export class PoapsClient { @@ -128,9 +128,9 @@ export class PoapsClient { } /** - * Retrieves mint code details for a specific QR hash. + * Retrieves mint code details for a specific Mint Code. * @async - * @param {string} mintCode - The QR hash for which to get the mint code. + * @param {string} mintCode - The Mint Code for which to get the mint code. * @returns {Promise} The mint code details. */ async getMintCode(mintCode: string): Promise { @@ -168,9 +168,9 @@ export class PoapsClient { } /** - * Awaits until a specific POAP, identified by its QR hash, is indexed. + * Awaits until a specific POAP, identified by its Mint Code, is indexed on our database. * @async - * @param {string} mintCode - The QR hash identifying the POAP to be indexed. + * @param {string} mintCode - The Mint Code identifying the POAP to be indexed. * @returns {Promise} Details of the indexed POAP. */ async waitPoapIndexed(mintCode: string): Promise { @@ -223,7 +223,7 @@ export class PoapsClient { } /** - * Reserves a POAP against an email address and provides reservation details. + * Reserves a POAP to an email address and provides reservation details. * @async * @param {EmailReservationInput} input - Information for the reservation. * @returns {Promise} The reservation details of the POAP. diff --git a/packages/poaps/src/types/input.ts b/packages/poaps/src/types/input.ts index c4096b85..15e331dc 100644 --- a/packages/poaps/src/types/input.ts +++ b/packages/poaps/src/types/input.ts @@ -1,20 +1,20 @@ import { Order, Chain, PaginationInput } from '@poap-xyz/utils'; /** - * Enum to define available fields for sorting Poaps. + * Enum to define available fields for sorting POAPs. * * @export * @enum {string} */ export enum PoapsSortFields { - /** Represents sorting by the date when a Poap was minted. */ + /** Represents sorting by the date when a POAP was minted. */ MintedOn = 'minted_on', - /** Represents sorting by the ID of a Poap. */ + /** Represents sorting by the ID of a POAP. */ Id = 'id', } /** - * Represents the input fields for fetching Poaps. + * Represents the input fields for fetching POAPs. * This interface extends `PaginationInput` to provide pagination capability. * * @export @@ -22,15 +22,15 @@ export enum PoapsSortFields { * @extends {PaginationInput} */ export interface FetchPoapsInput extends PaginationInput { - /** Optional filter for the name of a Poap. */ + /** Optional filter for the name of a POAP. */ name?: string; - /** Optional filter for the blockchain chain of a Poap. */ + /** Optional filter for the blockchain chain of a POAP. */ chain?: Chain; - /** Optional filter for the start date when a Poap was minted. */ + /** Optional filter for the start date when a POAP was minted. */ mintedDateFrom?: string; - /** Optional filter for the end date when a Poap was minted. */ + /** Optional filter for the end date when a POAP was minted. */ mintedDateTo?: string; - /** Optional filter for specific Poap IDs. */ + /** Optional filter for specific POAP IDs. */ ids?: number[]; /** Optional filter for the collector's address. */ collectorAddress?: string; @@ -40,12 +40,12 @@ export interface FetchPoapsInput extends PaginationInput { sortField?: PoapsSortFields; /** Direction in which to sort the results. */ sortDir?: Order; - /** Filter to include/exclude Poaps with zero addresses. */ + /** Filter to include/exclude POAPs with zero addresses. */ filterByZeroAddress?: boolean; } /** - * Represents the input fields required to mint a Poap for a wallet. + * Represents the input fields required to mint a POAP for a wallet. * * @export * @interface WalletMintInput @@ -56,7 +56,7 @@ export interface WalletMintInput { } /** - * Represents the input fields required to reserve a Poap via email. + * Represents the input fields required to reserve a POAP via email. * * @export * @interface EmailReservationInput diff --git a/packages/poaps/src/utils/MintChecker.ts b/packages/poaps/src/utils/MintChecker.ts index a779c505..db426e98 100644 --- a/packages/poaps/src/utils/MintChecker.ts +++ b/packages/poaps/src/utils/MintChecker.ts @@ -4,7 +4,7 @@ import { FinishedWithError } from '../errors/FinishedWithError'; import { RetryableTask } from './RetryableTask'; /** - * A utility class designed to continually check the status of a Poap token mint. + * A utility class designed to continually check the status of a POAP token mint. * If a mint is still pending or in process, it implements a backoff retry mechanism. */ export class MintChecker extends RetryableTask { diff --git a/packages/poaps/src/utils/PoapIndexed.ts b/packages/poaps/src/utils/PoapIndexed.ts index 6db58535..fc7e7c9d 100644 --- a/packages/poaps/src/utils/PoapIndexed.ts +++ b/packages/poaps/src/utils/PoapIndexed.ts @@ -6,7 +6,7 @@ import { PoapMintStatus } from '../types'; * @class PoapIndexed * @extends {RetryableTask} * - * Represents a utility class designed to periodically check if a POAP (Proof of Attendance Protocol) token is indexed. + * Represents a utility class designed to periodically check if a POAP token is indexed on our database. * This class extends `RetryableTask` to utilize its backoff retry mechanism in case the token hasn't been indexed yet. */ export class PoapIndexed extends RetryableTask { @@ -15,7 +15,7 @@ export class PoapIndexed extends RetryableTask { /** * Creates an instance of the PoapIndexed class. * - * @param {string} mintCode - A unique QR hash representing the token. + * @param {string} mintCode - A unique Mint Code representing the token. * @param {TokensApiProvider} tokensApiProvider - An instance of the TokensApiProvider used to check the indexing status of the token. */ constructor(mintCode: string, tokensApiProvider: TokensApiProvider) { @@ -24,7 +24,7 @@ export class PoapIndexed extends RetryableTask { } /** - * Periodically checks if the POAP token, represented by its QR hash, is indexed. + * Periodically checks if the POAP token, represented by its Mint Code, is indexed on our database. * This method will continue retrying with an increasing delay until either the token is indexed or it reaches the maximum allowed retries. * * @returns {Promise} A promise that either resolves with the indexed token's mint code response or rejects due to reaching the max retry limit. diff --git a/packages/providers/src/core/PoapCompass/PoapCompass.ts b/packages/providers/src/core/PoapCompass/PoapCompass.ts index d20259da..3af7fac6 100644 --- a/packages/providers/src/core/PoapCompass/PoapCompass.ts +++ b/packages/providers/src/core/PoapCompass/PoapCompass.ts @@ -5,7 +5,7 @@ import { CompassProvider } from '../../ports/CompassProvider/CompassProvider'; const DEFAULT_COMPASS_BASE_URL = 'https://public.compass.poap.tech/v1/graphql'; /** - * A class that implements the `CompassProvider` interface for fetching data from the Poap API. + * A class that implements the `CompassProvider` interface for fetching data from the POAP API. * @class * @implements {CompassProvider} */ @@ -24,7 +24,7 @@ export class PoapCompass implements CompassProvider { } /** - * Fetches data from the Poap GraphQL API. + * Fetches data from the POAP GraphQL API. * * @async * @private @@ -92,8 +92,8 @@ export class PoapCompass implements CompassProvider { /** * Configuration interface for the PoapCompass class. * @interface - * @property {string} apiKey - The API key to use for requests to the Poap API. - * @property {string} [baseUrl] - Optional base URL for the Poap API. If not provided, a default will be used. + * @property {string} apiKey - The API key to use for requests to the POAP API. + * @property {string} [baseUrl] - Optional base URL for the POAP API. If not provided, a default will be used. */ export interface PoapCompassConfig { apiKey: string; diff --git a/packages/providers/src/core/PoapDropApi/PoapDropApi.ts b/packages/providers/src/core/PoapDropApi/PoapDropApi.ts index 88329796..59d32c8b 100644 --- a/packages/providers/src/core/PoapDropApi/PoapDropApi.ts +++ b/packages/providers/src/core/PoapDropApi/PoapDropApi.ts @@ -11,7 +11,7 @@ import { const DEFAULT_DROP_BASE_URL = 'https://api.poap.tech'; /** - * A class that implements the `DropApiProvider` interface for interacting with the Poap Drop API. + * A class that implements the `DropApiProvider` interface for interacting with the POAP Drop API. * * @class * @implements {DropApiProvider} @@ -32,7 +32,7 @@ export class PoapDropApi implements DropApiProvider { } /** - * Creates a new drop on the Poap Drop API. + * Creates a new drop on the POAP Drop API. * * @async * @function @@ -59,7 +59,7 @@ export class PoapDropApi implements DropApiProvider { } /** - * Updates an existing drop on the Poap Drop API. + * Updates an existing drop on the POAP Drop API. * * @async * @function @@ -79,7 +79,7 @@ export class PoapDropApi implements DropApiProvider { // TODO: Change variable type any to a more specific type /** - * Sends a secure HTTP request to the Poap Drop API. + * Sends a secure HTTP request to the POAP Drop API. * * @async * @private diff --git a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts index 8e10efb8..77dcec01 100644 --- a/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts +++ b/packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts @@ -12,7 +12,7 @@ import { TokensApiProvider } from './../../ports/TokensApiProvider/TokensApiProv const DEFAULT_DROP_BASE_URL = 'https://api.poap.tech'; /** - * Represents the main interface to interact with the Poap Drop API. + * Represents the main interface to interact with the POAP Drop API. * * @export * @class PoapTokenApi @@ -44,7 +44,7 @@ export class PoapTokenApi implements TokensApiProvider { /** * Retrieves the mint code details. * - * @param {string} code - The unique QR hash for the mint. + * @param {string} code - The unique Mint Code for the mint. * @returns {Promise} Details of the mint code. */ async getMintCode(code: string): Promise { @@ -93,7 +93,7 @@ export class PoapTokenApi implements TokensApiProvider { } /** - * Sends a secure HTTP request to the Poap API with proper headers. + * Sends a secure HTTP request to the POAP API with proper headers. * * @private * @template R - Type of the expected response data.