diff --git a/docs/pages/changelog.mdx b/docs/pages/changelog.mdx index 812a0cd4..fc59c3de 100644 --- a/docs/pages/changelog.mdx +++ b/docs/pages/changelog.mdx @@ -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. diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index 827d0aac..6ea23f4a 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -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 @@ -19,7 +17,7 @@ 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. @@ -27,7 +25,7 @@ Developers are the unsung heroes behind this public good. While POAP Inc builds 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. @@ -35,7 +33,7 @@ The POAP platform offers numerous functionalities exposed through an API. Everyo 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. diff --git a/docs/pages/packages/drops.mdx b/docs/pages/packages/drops.mdx index d58a9c6c..63c78948 100644 --- a/docs/pages/packages/drops.mdx +++ b/docs/pages/packages/drops.mdx @@ -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 @@ -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 @@ -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). diff --git a/docs/pages/packages/frames.mdx b/docs/pages/packages/frames.mdx index 135cd7d2..95214c93 100644 --- a/docs/pages/packages/frames.mdx +++ b/docs/pages/packages/frames.mdx @@ -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 diff --git a/docs/pages/packages/moments.mdx b/docs/pages/packages/moments.mdx index 8db96f12..aab02d34 100644 --- a/docs/pages/packages/moments.mdx +++ b/docs/pages/packages/moments.mdx @@ -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 @@ -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 @@ -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). diff --git a/docs/pages/packages/moments/UploadMoments.mdx b/docs/pages/packages/moments/UploadMoments.mdx new file mode 100644 index 00000000..0cf1df55 --- /dev/null +++ b/docs/pages/packages/moments/UploadMoments.mdx @@ -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', +}); +``` diff --git a/docs/pages/packages/moments/_meta.json b/docs/pages/packages/moments/_meta.json new file mode 100644 index 00000000..c059eaa8 --- /dev/null +++ b/docs/pages/packages/moments/_meta.json @@ -0,0 +1,3 @@ +{ + "UploadMoments": "Upload Moments" +} diff --git a/docs/pages/packages/poaps.mdx b/docs/pages/packages/poaps.mdx index aa49a16d..1dbba244 100644 --- a/docs/pages/packages/poaps.mdx +++ b/docs/pages/packages/poaps.mdx @@ -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) @@ -30,7 +30,7 @@ yarn add @poap-xyz/poaps ## Usage -```javascript +```typescript import { PoapsClient } from '@poap-xyz/poaps'; import { AuthenticationProviderHttp, @@ -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 @@ -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). diff --git a/docs/pages/packages/poaps/Errors.mdx b/docs/pages/packages/poaps/Errors.mdx index 81a8ca91..b9cb10a5 100644 --- a/docs/pages/packages/poaps/Errors.mdx +++ b/docs/pages/packages/poaps/Errors.mdx @@ -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: '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. - } +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(); ``` diff --git a/docs/pages/packages/poaps/Inputs.mdx b/docs/pages/packages/poaps/Inputs.mdx deleted file mode 100644 index b7e9338e..00000000 --- a/docs/pages/packages/poaps/Inputs.mdx +++ /dev/null @@ -1,84 +0,0 @@ -# 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 deleted file mode 100644 index 1c992e1c..00000000 --- a/docs/pages/packages/poaps/POAP.mdx +++ /dev/null @@ -1,57 +0,0 @@ -# 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 deleted file mode 100644 index 43aaf115..00000000 --- a/docs/pages/packages/poaps/POAPReservation.mdx +++ /dev/null @@ -1,51 +0,0 @@ -# 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 deleted file mode 100644 index 4f34789a..00000000 --- a/docs/pages/packages/poaps/PoapsClient.mdx +++ /dev/null @@ -1,201 +0,0 @@ -# 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 deleted file mode 100644 index fe9906a9..00000000 --- a/docs/pages/packages/poaps/Responses.mdx +++ /dev/null @@ -1,27 +0,0 @@ -# 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 index b2930375..0f3f9d36 100644 --- a/docs/pages/packages/poaps/_meta.json +++ b/docs/pages/packages/poaps/_meta.json @@ -1,8 +1,3 @@ { - "Errors": "Errors", - "Inputs": "Inputs", - "POAP": "POAP", - "POAPReservation": "POAP Reservation", - "PoapsClient": "POAPs Client", - "Responses": "Responses" + "Errors": "Error Handling" } diff --git a/docs/pages/packages/providers.mdx b/docs/pages/packages/providers.mdx index ad5870ab..1c7f0046 100644 --- a/docs/pages/packages/providers.mdx +++ b/docs/pages/packages/providers.mdx @@ -1,8 +1,8 @@ -# @poap-xyz/providers +# `@poap-xyz/providers` [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) -@poap-xyz/providers is a package to use POAP providers that let you interact with POAPs APIs. Also you can make your own provider by extending the interfaces. +`@poap-xyz/providers` is a package to use POAP providers that let you interact with POAPs APIs. Also you can make your own provider by extending the interfaces. ## Features @@ -37,4 +37,4 @@ We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines. ## License -@poap-xyz/providers is released under the [MIT License](https://opensource.org/licenses/MIT). +`@poap-xyz/providers` is released under the [MIT License](https://opensource.org/licenses/MIT). diff --git a/docs/pages/packages/utils.mdx b/docs/pages/packages/utils.mdx index f1b51d9a..bcab808c 100644 --- a/docs/pages/packages/utils.mdx +++ b/docs/pages/packages/utils.mdx @@ -1,8 +1,8 @@ -# @poap-xyz/utils +# `@poap-xyz/utils` [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) -@poap-xyz/utils is a package that contains auxiliar functions. +`@poap-xyz/utils` is a package that contains auxiliar functions. ## Features @@ -37,4 +37,4 @@ We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines. ## License -@poap-xyz/utils is released under the [MIT License](https://opensource.org/licenses/MIT). +`@poap-xyz/utils` is released under the [MIT License](https://opensource.org/licenses/MIT). diff --git a/packages/drops/package.json b/packages/drops/package.json index 54525ec3..e2e7a733 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/drops", - "version": "0.4.0", + "version": "0.5.0", "description": "Drops module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,7 +29,7 @@ "node": ">=18" }, "dependencies": { - "@poap-xyz/providers": "0.4.0", - "@poap-xyz/utils": "0.4.0" + "@poap-xyz/providers": "0.5.0", + "@poap-xyz/utils": "0.5.0" } } diff --git a/packages/drops/src/DropsClient.ts b/packages/drops/src/DropsClient.ts index 392ee4a3..67337bff 100644 --- a/packages/drops/src/DropsClient.ts +++ b/packages/drops/src/DropsClient.ts @@ -1,23 +1,4 @@ -import { - CompassProvider, - DropApiProvider, - DropResponse as ProviderDropResponse, -} from '@poap-xyz/providers'; -import { Drop } from './domain/Drop'; -import { - PAGINATED_DROPS_QUERY, - PaginatedDropsResponse, - PaginatedDropsVariables, -} from './queries/PaginatedDrop'; -import { - CreateDropsInput, - DropImageResponse, - DropResponse, - DropsSortFields, - FetchDropsInput, - SearchDropsInput, - UpdateDropsInput, -} from './types'; +import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; import { PaginatedResult, nextCursor, @@ -30,12 +11,23 @@ import { createBoolFilter, createLikeFilter, } from '@poap-xyz/utils'; -import { DropImage } from './types/dropImage'; +import { Drop } from './domain/Drop'; +import { + PAGINATED_DROPS_QUERY, + PaginatedDropsResponse, + PaginatedDropsVariables, +} from './queries/PaginatedDrop'; import { SEARCH_DROPS_QUERY, SearchDropsResponse, SearchDropsVariables, } from './queries/SearchDrops'; +import { DropResponse } from './types/DropResponse'; +import { DropsSortFields } from './types/DropsSortFields'; +import { CreateDropsInput } from './types/CreateDropsInput'; +import { UpdateDropsInput } from './types/UpdateDropsInput'; +import { FetchDropsInput } from './types/FetchDropsInput'; +import { SearchDropsInput } from './types/SearchDropsInput'; /** * Represents a client for working with POAP drops. @@ -94,7 +86,7 @@ export class DropsClient { >(PAGINATED_DROPS_QUERY, variables); const drops = data.drops.map( - (drop: DropResponse): Drop => this.mapDrop(drop), + (drop: DropResponse): Drop => Drop.fromCompass(drop), ); return new PaginatedResult( @@ -133,7 +125,7 @@ export class DropsClient { >(SEARCH_DROPS_QUERY, variables); const drops = data.search_drops.map( - (drop: DropResponse): Drop => this.mapDrop(drop), + (drop: DropResponse): Drop => Drop.fromCompass(drop), ); return new PaginatedResult( @@ -170,7 +162,7 @@ export class DropsClient { requested_codes: input.requestedCodes, private_event: input.privateEvent, }); - return this.formatDrop(repsonse); + return Drop.fromProvider(repsonse); } /** @@ -196,92 +188,6 @@ export class DropsClient { event_template_id: input.eventTemplateId, secret_code: input.secretCode, }); - return this.formatDrop(repsonse); - } - - private formatDrop(drop: ProviderDropResponse): Drop { - return new Drop({ - id: drop.id, - fancyId: drop.fancy_id, - name: drop.name, - description: drop.description, - city: drop.city, - country: drop.country, - channel: drop.channel, - platform: drop.platform, - locationType: drop.location_type, - dropUrl: drop.event_url, - imageUrl: drop.image_url, - originalImageUrl: drop.image_url, - animationUrl: drop.animation_url, - year: drop.year, - startDate: new Date(drop.start_date), - timezone: drop.timezone, - private: drop.private_event, - createdDate: new Date(drop.created_date), - expiryDate: new Date(drop.expiry_date), - endDate: new Date(drop.end_date), - transferCount: 0, - poapCount: 0, - emailReservationCount: 0, - }); - } - - private computeDropImages(drop: DropResponse): { - imageUrl: string; - originalImageUrl: string; - } { - const dropImage = this.mapDropImage(drop.drop_image); - return { - imageUrl: dropImage?.crop || drop.image_url, - originalImageUrl: dropImage?.original || drop.image_url, - }; - } - - private mapDropImage(response?: DropImageResponse): DropImage | undefined { - if (!response) return response; - - const images = response.gateways.reduce( - (acc, gateway) => ({ ...acc, [gateway.type.toLowerCase()]: gateway.url }), - {}, - ); - - return { ...images }; - } - - private mapDrop(drop: DropResponse): Drop { - const { imageUrl, originalImageUrl } = this.computeDropImages(drop); - - return new Drop({ - id: Number(drop.id), - fancyId: drop.fancy_id, - name: drop.name, - description: drop.description, - city: drop.city, - country: drop.country, - channel: drop.channel, - platform: drop.platform, - locationType: drop.location_type, - dropUrl: drop.drop_url, - imageUrl, - originalImageUrl, - animationUrl: drop.animation_url, - year: Number(drop.year), - startDate: new Date(drop.start_date), - timezone: drop.timezone, - private: drop.private, - createdDate: new Date(drop.created_date), - poapCount: drop.stats_by_chain_aggregate.aggregate.sum - ? Number(drop.stats_by_chain_aggregate.aggregate.sum.poap_count) - : 0, - transferCount: drop.stats_by_chain_aggregate.aggregate.sum - ? Number(drop.stats_by_chain_aggregate.aggregate.sum.transfer_count) - : 0, - emailReservationCount: drop.email_claims_stats - ? Number(drop.email_claims_stats.total) - : 0, - expiryDate: new Date(drop.expiry_date), - endDate: new Date(drop.end_date), - }); + return Drop.fromProvider(repsonse); } } diff --git a/packages/drops/src/domain/Drop.ts b/packages/drops/src/domain/Drop.ts index c4913839..02290426 100644 --- a/packages/drops/src/domain/Drop.ts +++ b/packages/drops/src/domain/Drop.ts @@ -1,4 +1,6 @@ -/* eslint-disable max-statements */ +import { DropResponse as ProviderDropResponse } from '@poap-xyz/providers'; +import { DropResponse } from '../types/DropResponse'; + export class Drop { id: number; fancyId: string; @@ -24,6 +26,79 @@ export class Drop { transferCount: number; emailReservationCount: number; + public static fromCompass(response: DropResponse): Drop { + const images: { crop: string; original: string } = + response.drop_image.gateways.reduce( + (images, gateway) => ({ + ...images, + [gateway.type.toLowerCase()]: gateway.url, + }), + { + crop: response.image_url, + original: response.image_url, + }, + ); + + return new Drop({ + id: Number(response.id), + fancyId: response.fancy_id, + name: response.name, + description: response.description, + city: response.city, + country: response.country, + channel: response.channel, + platform: response.platform, + locationType: response.location_type, + dropUrl: response.drop_url, + imageUrl: images.crop, + originalImageUrl: images.original, + animationUrl: response.animation_url, + year: Number(response.year), + startDate: new Date(response.start_date), + timezone: response.timezone, + private: response.private, + createdDate: new Date(response.created_date), + expiryDate: new Date(response.expiry_date), + endDate: new Date(response.end_date), + poapCount: Number( + response.stats_by_chain_aggregate.aggregate.sum.poap_count, + ), + transferCount: Number( + response.stats_by_chain_aggregate.aggregate.sum.transfer_count, + ), + emailReservationCount: Number(response.email_claims_stats.total), + }); + } + + public static fromProvider(response: ProviderDropResponse): Drop { + return new Drop({ + id: response.id, + fancyId: response.fancy_id, + name: response.name, + description: response.description, + city: response.city, + country: response.country, + channel: response.channel, + platform: response.platform, + locationType: response.location_type, + dropUrl: response.event_url, + imageUrl: response.image_url, + originalImageUrl: response.image_url, + animationUrl: response.animation_url, + year: response.year, + startDate: new Date(response.start_date), + timezone: response.timezone, + private: response.private_event, + createdDate: new Date(response.created_date), + expiryDate: new Date(response.expiry_date), + endDate: new Date(response.end_date), + transferCount: 0, + poapCount: 0, + emailReservationCount: 0, + }); + } + + // eslint-disable-next-line max-statements constructor(properties: DropProperties) { this.id = properties.id; this.fancyId = properties.fancyId; @@ -74,16 +149,16 @@ export class Drop { private: this.private, startDate: this.startDate.toISOString(), createdDate: this.createdDate.toISOString(), + expiryDate: this.expiryDate.toISOString(), + endDate: this.endDate.toISOString(), poapCount: this.poapCount, transferCount: this.transferCount, emailReservationCount: this.emailReservationCount, - expiryDate: this.expiryDate.toISOString(), - endDate: this.endDate.toISOString(), }; } } -export interface SerializableDrop { +interface SerializableDrop { id: number; fancyId: string; name: string; @@ -102,14 +177,14 @@ export interface SerializableDrop { private: boolean; startDate: string; // ISO String representation of Date createdDate: string; // ISO String representation of Date + expiryDate: string; // ISO String representation of Date + endDate: string; // ISO String representation of Date poapCount: number; transferCount: number; emailReservationCount: number; - expiryDate: string; // ISO String representation of Date - endDate: string; // ISO String representation of Date } -export interface DropProperties { +interface DropProperties { id: number; fancyId: string; name: string; diff --git a/packages/drops/src/index.ts b/packages/drops/src/index.ts index 5fd44bb1..5647dca2 100644 --- a/packages/drops/src/index.ts +++ b/packages/drops/src/index.ts @@ -1,8 +1,3 @@ export { DropsClient } from './DropsClient'; -export { Drop, DropProperties, SerializableDrop } from './domain/Drop'; -export { - FetchDropsInput, - CreateDropsInput, - UpdateDropsInput, - DropsSortFields, -} from './types'; +export { Drop } from './domain/Drop'; +export { DropsSortFields } from './types/DropsSortFields'; diff --git a/packages/drops/src/queries/index.ts b/packages/drops/src/queries/index.ts deleted file mode 100644 index 36a9e766..00000000 --- a/packages/drops/src/queries/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PaginatedDrop'; diff --git a/packages/drops/src/types/input.ts b/packages/drops/src/types/CreateDropsInput.ts similarity index 50% rename from packages/drops/src/types/input.ts rename to packages/drops/src/types/CreateDropsInput.ts index 61eb98a3..8ca18aa0 100644 --- a/packages/drops/src/types/input.ts +++ b/packages/drops/src/types/CreateDropsInput.ts @@ -1,21 +1,3 @@ -import { Order, PaginationInput } from '@poap-xyz/utils'; - -export enum DropsSortFields { - Name = 'name', - Id = 'id', - StartDate = 'start_date', -} - -export interface FetchDropsInput extends PaginationInput { - name?: string; - sortField?: DropsSortFields; - sortDir?: Order; - from?: string; - to?: string; - ids?: number[]; - isPrivate?: boolean; -} - export interface CreateDropsInput { name: string; description: string; @@ -35,5 +17,3 @@ export interface CreateDropsInput { requestedCodes?: number; privateEvent?: boolean; } - -export type UpdateDropsInput = CreateDropsInput; diff --git a/packages/drops/src/types/DropImageResponse.ts b/packages/drops/src/types/DropImageResponse.ts deleted file mode 100644 index 5de23371..00000000 --- a/packages/drops/src/types/DropImageResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { DropImageGatewayType } from './dropImage'; - -interface DropImageGatewayResponse { - type: DropImageGatewayType; - url: string; -} - -export interface DropImageResponse { - gateways: Array; -} diff --git a/packages/drops/src/types/DropResponse.ts b/packages/drops/src/types/DropResponse.ts index 0284b1e2..629156db 100644 --- a/packages/drops/src/types/DropResponse.ts +++ b/packages/drops/src/types/DropResponse.ts @@ -1,5 +1,3 @@ -import { DropImageResponse } from './DropImageResponse'; - export interface DropResponse { id: number; fancy_id: string; @@ -31,5 +29,10 @@ export interface DropResponse { email_claims_stats: { total: number; }; - drop_image?: DropImageResponse; + drop_image: { + gateways: Array<{ + type: 'CROP' | 'ORIGINAL'; + url: string; + }>; + }; } diff --git a/packages/drops/src/types/DropsSortFields.ts b/packages/drops/src/types/DropsSortFields.ts new file mode 100644 index 00000000..dddfae48 --- /dev/null +++ b/packages/drops/src/types/DropsSortFields.ts @@ -0,0 +1,5 @@ +export enum DropsSortFields { + Name = 'name', + Id = 'id', + StartDate = 'start_date', +} diff --git a/packages/drops/src/types/FetchDropsInput.ts b/packages/drops/src/types/FetchDropsInput.ts new file mode 100644 index 00000000..43477fd5 --- /dev/null +++ b/packages/drops/src/types/FetchDropsInput.ts @@ -0,0 +1,12 @@ +import { Order, PaginationInput } from '@poap-xyz/utils'; +import { DropsSortFields } from './DropsSortFields'; + +export interface FetchDropsInput extends PaginationInput { + name?: string; + sortField?: DropsSortFields; + sortDir?: Order; + from?: string; + to?: string; + ids?: number[]; + isPrivate?: boolean; +} diff --git a/packages/drops/src/types/UpdateDropsInput.ts b/packages/drops/src/types/UpdateDropsInput.ts new file mode 100644 index 00000000..5e0556da --- /dev/null +++ b/packages/drops/src/types/UpdateDropsInput.ts @@ -0,0 +1,19 @@ +export interface UpdateDropsInput { + name: string; + description: string; + city: string; + country: string; + startDate: string; + endDate: string; + expiryDate: string; + eventUrl: string; + virtualEvent: boolean; + image: Blob; + filename: string; + contentType: string; + secretCode: string; + eventTemplateId?: number | null; + email: string; + requestedCodes?: number; + privateEvent?: boolean; +} diff --git a/packages/drops/src/types/dropImage.ts b/packages/drops/src/types/dropImage.ts deleted file mode 100644 index 1f50e795..00000000 --- a/packages/drops/src/types/dropImage.ts +++ /dev/null @@ -1,9 +0,0 @@ -export enum DropImageGatewayType { - CROP = 'CROP', - ORIGINAL = 'ORIGINAL', -} - -export interface DropImage { - original?: string; - crop?: string; -} diff --git a/packages/drops/src/types/index.ts b/packages/drops/src/types/index.ts deleted file mode 100644 index c2f59ef7..00000000 --- a/packages/drops/src/types/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './input'; -export * from './DropImageResponse'; -export * from './DropResponse'; -export * from './SearchDropsInput'; diff --git a/packages/moments/package.json b/packages/moments/package.json index c5ebd9a7..903accb9 100644 --- a/packages/moments/package.json +++ b/packages/moments/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/moments", - "version": "0.4.0", + "version": "0.5.0", "description": "Moments module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.4.0", - "@poap-xyz/utils": "0.4.0", + "@poap-xyz/providers": "0.5.0", + "@poap-xyz/utils": "0.5.0", "uuid": "^9.0.0" }, "engines": { diff --git a/packages/moments/src/client/MomentsClient.ts b/packages/moments/src/client/MomentsClient.ts index b32c1be9..9daf487a 100644 --- a/packages/moments/src/client/MomentsClient.ts +++ b/packages/moments/src/client/MomentsClient.ts @@ -10,19 +10,16 @@ import { } from '@poap-xyz/utils'; import { Moment } from '../domain/Moment'; import { - MomentResponse, MomentsQueryResponse, MomentsQueryVariables, PAGINATED_MOMENTS_QUERY, -} from '../queries'; +} from '../queries/PaginatedMoments'; +import { CreateMedia } from './dtos/create/CreateMedia'; import { CreateMomentInput } from './dtos/create/CreateInput'; import { CreateSteps } from './dtos/create/CreateSteps'; -import { - FetchMomentsInput, - MomentsSortFields, -} from './dtos/fetch/FetchMomentsInput'; -import { CreateMedia } from './dtos/create/CreateMedia'; import { PatchMomentInput } from './dtos/patch/PatchInput'; +import { FetchMomentsInput } from './dtos/fetch/FetchMomentsInput'; +import { MomentsSortFields } from './dtos/fetch/MomentsSortFields'; export class MomentsClient { constructor( @@ -57,19 +54,12 @@ export class MomentsClient { description: input.description, mediaKeys, }); - void input.onStepUpdate?.(CreateSteps.FINISHED); - return new Moment( - response.id, - response.author, - response.createdOn, - response.dropId, - response.tokenId, - response.description, - response.cid, - ); + + return Moment.fromCreated(response); } + // eslint-disable-next-line max-statements private async uploadMedias( mediaArray: CreateMedia[], onStepUpdate?: (step: CreateSteps) => void | Promise, @@ -125,17 +115,15 @@ export class MomentsClient { timeOut?: number, ): Promise { const { url, key } = await this.poapMomentsApi.getSignedUrl(); + await this.poapMomentsApi.uploadFile( media.fileBinary, url, media.fileType, onFileUploadProgress, ); - try { - await this.poapMomentsApi.waitForMediaProcessing(key, timeOut); - } catch (error) { - throw error; - } + + await this.poapMomentsApi.waitForMediaProcessing(key, timeOut); return key; } @@ -186,8 +174,8 @@ export class MomentsClient { MomentsQueryVariables >(PAGINATED_MOMENTS_QUERY, variables); - const momentsResponse: Moment[] = response.data.moments.map( - this.getMomentFromMomentResponse, + const momentsResponse: Moment[] = response.data.moments.map((moment) => + Moment.fromCompass(moment), ); const result = new PaginatedResult( @@ -201,16 +189,4 @@ export class MomentsClient { public async patchMoment(id: string, input: PatchMomentInput): Promise { await this.poapMomentsApi.patchMoment(id, input); } - - private getMomentFromMomentResponse(momentResponse: MomentResponse): Moment { - return new Moment( - momentResponse.id, - momentResponse.author, - new Date(momentResponse.created_on), - momentResponse.drop_id, - momentResponse.token_id, - momentResponse.description, - momentResponse.cid, - ); - } } diff --git a/packages/moments/src/client/MomentsClientFactory/MomentsClientFactory.ts b/packages/moments/src/client/MomentsClientFactory/MomentsClientFactory.ts index fba9a7ef..d9089a41 100644 --- a/packages/moments/src/client/MomentsClientFactory/MomentsClientFactory.ts +++ b/packages/moments/src/client/MomentsClientFactory/MomentsClientFactory.ts @@ -1,10 +1,10 @@ -import { MomentsClient } from 'moments'; import { AuthenticationProvider, AuthenticationProviderHttp, PoapCompass, PoapMomentsApi, } from '@poap-xyz/providers'; +import { MomentsClient } from '../MomentsClient'; import { GetMomentsDefaultClientOptions } from './options/GetMomentsDefaultClientOptions'; export class MomentsClientFactory { diff --git a/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts b/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts index da00b187..eac4fec2 100644 --- a/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts +++ b/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts @@ -1,18 +1,5 @@ import { Order, PaginationInput } from '@poap-xyz/utils'; -/** - * Enum to define available fields for sorting Moments. - * - * @export - * @enum {string} - */ -export enum MomentsSortFields { - StartDate = 'start_date', - TokenId = 'token_id', - DropId = 'drop_id', - Id = 'id', -} - /** * Interface representing the input needed to fetch moments. * @interface diff --git a/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts b/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts new file mode 100644 index 00000000..94fe0f59 --- /dev/null +++ b/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts @@ -0,0 +1,12 @@ +/** + * Enum to define available fields for sorting Moments. + * + * @export + * @enum {string} + */ +export enum MomentsSortFields { + StartDate = 'start_date', + TokenId = 'token_id', + DropId = 'drop_id', + Id = 'id', +} diff --git a/packages/moments/src/domain/Moment.ts b/packages/moments/src/domain/Moment.ts index 37dede43..158bb28e 100644 --- a/packages/moments/src/domain/Moment.ts +++ b/packages/moments/src/domain/Moment.ts @@ -1,3 +1,6 @@ +import { CreateMomentResponse } from '@poap-xyz/providers'; +import { MomentResponse } from '../queries/PaginatedMoments'; + /** * Represents a moment. */ @@ -37,6 +40,30 @@ export class Moment { */ public readonly cid?: string; + public static fromCompass(response: MomentResponse): Moment { + return new Moment( + response.id, + response.author, + new Date(response.created_on), + response.drop_id, + response.token_id, + response.description, + response.cid, + ); + } + + public static fromCreated(response: CreateMomentResponse): Moment { + return new Moment( + response.id, + response.author, + response.createdOn, + response.dropId, + response.tokenId, + response.description, + response.cid, + ); + } + constructor( id: string, author: string, diff --git a/packages/moments/src/index.ts b/packages/moments/src/index.ts index 0acc1e49..6cc19e62 100644 --- a/packages/moments/src/index.ts +++ b/packages/moments/src/index.ts @@ -1,7 +1,4 @@ export { Moment } from './domain/Moment'; export { MomentsClient } from './client/MomentsClient'; -export { CreateMomentInput } from './client/dtos/create/CreateInput'; -export { PatchMomentInput } from './client/dtos/patch/PatchInput'; -export { CreateSteps } from './client/dtos/create/CreateSteps'; -export { FetchMomentsInput } from './client/dtos/fetch/FetchMomentsInput'; export { MomentsClientFactory } from './client/MomentsClientFactory/MomentsClientFactory'; +export { CreateSteps } from './client/dtos/create/CreateSteps'; diff --git a/packages/moments/src/queries/index.ts b/packages/moments/src/queries/index.ts deleted file mode 100644 index 932d5404..00000000 --- a/packages/moments/src/queries/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PaginatedMoments'; diff --git a/packages/poaps/docs/Errors.md b/packages/poaps/docs/Errors.md deleted file mode 100644 index 81a8ca91..00000000 --- a/packages/poaps/docs/Errors.md +++ /dev/null @@ -1,141 +0,0 @@ -# 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 deleted file mode 100644 index b7e9338e..00000000 --- a/packages/poaps/docs/Inputs.md +++ /dev/null @@ -1,84 +0,0 @@ -# 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 deleted file mode 100644 index 1c992e1c..00000000 --- a/packages/poaps/docs/POAP.md +++ /dev/null @@ -1,57 +0,0 @@ -# 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 deleted file mode 100644 index 43aaf115..00000000 --- a/packages/poaps/docs/POAPReservation.md +++ /dev/null @@ -1,51 +0,0 @@ -# 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 deleted file mode 100644 index 0afe6473..00000000 --- a/packages/poaps/docs/PoapsClient.md +++ /dev/null @@ -1,201 +0,0 @@ -# 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 deleted file mode 100644 index fe9906a9..00000000 --- a/packages/poaps/docs/Responses.md +++ /dev/null @@ -1,27 +0,0 @@ -# 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/package.json b/packages/poaps/package.json index 8cadba18..32d37e67 100644 --- a/packages/poaps/package.json +++ b/packages/poaps/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poaps", - "version": "0.4.0", + "version": "0.5.0", "description": "Poaps module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.4.0", - "@poap-xyz/utils": "0.4.0" + "@poap-xyz/providers": "0.5.0", + "@poap-xyz/utils": "0.5.0" }, "engines": { "node": ">=18" diff --git a/packages/poaps/src/PoapsClient.ts b/packages/poaps/src/PoapsClient.ts index 0e6e7eba..0518c076 100644 --- a/packages/poaps/src/PoapsClient.ts +++ b/packages/poaps/src/PoapsClient.ts @@ -3,20 +3,6 @@ import { TokensApiProvider, Transaction, } from '@poap-xyz/providers'; -import { POAP } from './domain/Poap'; -import { POAPReservation } from './domain/POAPReservation'; -import { - PAGINATED_POAPS_QUERY, - PaginatedPoapsResponse, - PaginatedPoapsVariables, -} from './queries'; -import { - EmailReservationInput, - FetchPoapsInput, - PoapMintStatus, - PoapsSortFields, - WalletMintInput, -} from './types'; import { createAddressFilter, createBetweenFilter, @@ -27,18 +13,32 @@ import { nextCursor, PaginatedResult, } from '@poap-xyz/utils'; +import { POAP } from './domain/POAP'; +import { POAPReservation } from './domain/POAPReservation'; +import { + PAGINATED_POAPS_QUERY, + PaginatedPoapsResponse, + PaginatedPoapsVariables, +} from './queries/PaginatedPoaps'; +import { FetchPoapsInput } from './types/FetchPoapsInput'; +import { PoapsSortFields } from './types/PoapsSortFields'; +import { PoapMintStatus } from './types/PoapMintStatus'; +import { WalletMintInput } from './types/WalletMintInput'; +import { EmailReservationInput } from './types/EmailReservationInput'; import { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError'; import { CodeExpiredError } from './errors/CodeExpiredError'; import { MintChecker } from './utils/MintChecker'; import { PoapIndexed } from './utils/PoapIndexed'; /** - * Represents a client for interacting with POAPs . + * Represents a client for interacting with POAPs. + * * @class */ export class PoapsClient { /** * Initializes a new instance of the PoapsClient. + * * @param {CompassProvider} compassProvider - The provider for the POAP compass API. * @param {TokensApiProvider} tokensApiProvider - The provider for the Tokens API. */ @@ -49,6 +49,7 @@ export class PoapsClient { /** * Fetches a list of POAP tokens based on the given input criteria. + * * @async * @param {FetchPoapsInput} input - Criteria for fetching POAP tokens. * @returns {Promise>} A paginated list of POAP tokens. @@ -94,25 +95,7 @@ export class PoapsClient { PaginatedPoapsVariables >(PAGINATED_POAPS_QUERY, variables); - const poaps = data.poaps.map((poap) => { - const { drop } = poap; - const mintedOn = new Date(0); - mintedOn.setUTCSeconds(poap.minted_on); - return new POAP({ - id: Number(poap.id), - collectorAddress: poap.collector_address, - transferCount: poap.transfer_count, - mintedOn, - dropId: Number(poap.drop_id), - imageUrl: drop.image_url, - city: drop.city, - country: drop.country, - description: drop.description, - startDate: new Date(drop.start_date), - name: drop.name, - endDate: new Date(drop.end_date), - }); - }); + const poaps = data.poaps.map((poap) => POAP.fromCompass(poap)); return new PaginatedResult( poaps, @@ -122,6 +105,7 @@ export class PoapsClient { /** * Retrieves mint code details for a specific Mint Code. + * * @async * @param {string} mintCode - The Mint Code for which to get the mint code. * @returns {Promise} The Mint status. @@ -150,6 +134,7 @@ export class PoapsClient { /** * Awaits until we have a final Transaction status for a specific Mint Code. + * * @async * @returns {Promise} * @param mintCode - The Mint Code @@ -161,17 +146,19 @@ export class PoapsClient { /** * Awaits until a specific POAP, identified by its Mint Code, is indexed on our database. + * * @async * @param {string} mintCode - The Mint Code identifying the POAP to be indexed. * @returns {Promise} - The status of the POAP mint. */ public async waitPoapIndexed(mintCode: string): Promise { - const checker = new PoapIndexed(mintCode, this.tokensApiProvider); + const checker = new PoapIndexed(this.tokensApiProvider, mintCode); return await checker.waitPoapIndexed(); } /** * Begins an asynchronous mint process and provides a unique queue ID in return. + * * @async * @param {WalletMintInput} input - Details required for the mint. */ @@ -190,6 +177,7 @@ export class PoapsClient { * Starts a synchronous mint process. The method waits for the mint to be processed and then * fetches the associated POAP. It combines the asynchronous mint and subsequent status checking * into a synchronous process for ease of use. + * * @async * @param {WalletMintInput} input - Details needed for the mint. * @returns {Promise} The associated POAP upon successful mint completion. @@ -213,6 +201,7 @@ export class PoapsClient { /** * 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. @@ -244,6 +233,7 @@ export class PoapsClient { /** * Retrieves the secret code associated with a POAP code. + * * @async * @param {string} mintCode - The POAP code for which to get the secret. * @returns {Promise} The associated secret code. diff --git a/packages/poaps/src/domain/Poap.ts b/packages/poaps/src/domain/POAP.ts similarity index 56% rename from packages/poaps/src/domain/Poap.ts rename to packages/poaps/src/domain/POAP.ts index a0baea33..00f96290 100644 --- a/packages/poaps/src/domain/Poap.ts +++ b/packages/poaps/src/domain/POAP.ts @@ -1,4 +1,5 @@ -/* eslint-disable max-statements */ +import { PoapsResponse } from '../queries/PaginatedPoaps'; + export class POAP { id: number; collectorAddress: string; @@ -13,6 +14,27 @@ export class POAP { endDate: Date; name: string; + public static fromCompass(response: PoapsResponse): POAP { + const mintedOn = new Date(0); + mintedOn.setUTCSeconds(response.minted_on); + + return new POAP({ + id: Number(response.id), + collectorAddress: response.collector_address, + transferCount: response.transfer_count, + mintedOn, + dropId: Number(response.drop_id), + imageUrl: response.drop.image_url, + city: response.drop.city, + country: response.drop.country, + description: response.drop.description, + startDate: new Date(response.drop.start_date), + endDate: new Date(response.drop.end_date), + name: response.drop.name, + }); + } + + // eslint-disable-next-line max-statements constructor(properties: PoapProperties) { this.id = properties.id; this.collectorAddress = properties.collectorAddress; @@ -29,7 +51,7 @@ export class POAP { } } -export interface PoapProperties { +interface PoapProperties { id: number; collectorAddress: string; transferCount: number; @@ -40,6 +62,6 @@ export interface PoapProperties { country: string; description: string; startDate: Date; - name: string; endDate: Date; + name: string; } diff --git a/packages/poaps/src/domain/POAPReservation.ts b/packages/poaps/src/domain/POAPReservation.ts index ac9e082a..95186369 100644 --- a/packages/poaps/src/domain/POAPReservation.ts +++ b/packages/poaps/src/domain/POAPReservation.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-statements */ export class POAPReservation { email: string; dropId: number; @@ -23,7 +22,7 @@ export class POAPReservation { } } -export interface POAPReservationProperties { +interface POAPReservationProperties { email: string; dropId: number; imageUrl: string; diff --git a/packages/poaps/src/index.ts b/packages/poaps/src/index.ts index faf13e1c..d5cf75e0 100644 --- a/packages/poaps/src/index.ts +++ b/packages/poaps/src/index.ts @@ -1,7 +1,7 @@ -export { PoapsSortFields, FetchPoapsInput } from './types/input'; -export { PoapMintStatus } from './types/response'; +export { PoapsSortFields } from './types/PoapsSortFields'; +export { PoapMintStatus } from './types/PoapMintStatus'; export { PoapsClient } from './PoapsClient'; -export { POAP } from './domain/Poap'; +export { POAP } from './domain/POAP'; export { POAPReservation } from './domain/POAPReservation'; export { FinishedWithError } from './errors/FinishedWithError'; export { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError'; diff --git a/packages/poaps/src/queries/index.ts b/packages/poaps/src/queries/index.ts deleted file mode 100644 index a655c4a3..00000000 --- a/packages/poaps/src/queries/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './PaginatedPoaps'; diff --git a/packages/poaps/src/types/EmailReservationInput.ts b/packages/poaps/src/types/EmailReservationInput.ts new file mode 100644 index 00000000..acac880e --- /dev/null +++ b/packages/poaps/src/types/EmailReservationInput.ts @@ -0,0 +1,11 @@ +/** + * Represents the input fields required to reserve a POAP via email. + * + * @export + * @interface EmailReservationInput + */ +export interface EmailReservationInput { + mintCode: string; + email: string; + sendEmail?: boolean; +} diff --git a/packages/poaps/src/types/input.ts b/packages/poaps/src/types/FetchPoapsInput.ts similarity index 62% rename from packages/poaps/src/types/input.ts rename to packages/poaps/src/types/FetchPoapsInput.ts index 5d306d0f..dcc8aabb 100644 --- a/packages/poaps/src/types/input.ts +++ b/packages/poaps/src/types/FetchPoapsInput.ts @@ -1,17 +1,5 @@ import { Order, Chain, PaginationInput } from '@poap-xyz/utils'; - -/** - * Enum to define available fields for sorting POAPs. - * - * @export - * @enum {string} - */ -export enum PoapsSortFields { - /** Represents sorting by the date when a POAP was minted. */ - MintedOn = 'minted_on', - /** Represents sorting by the ID of a POAP. */ - Id = 'id', -} +import { PoapsSortFields } from './PoapsSortFields'; /** * Represents the input fields for fetching POAPs. @@ -45,26 +33,3 @@ export interface FetchPoapsInput extends PaginationInput { /** Filter out dead addresses? */ filterDeadAddress?: boolean; } - -/** - * Represents the input fields required to mint a POAP for a wallet. - * - * @export - * @interface WalletMintInput - */ -export interface WalletMintInput { - mintCode: string; - address: string; -} - -/** - * Represents the input fields required to reserve a POAP via email. - * - * @export - * @interface EmailReservationInput - */ -export interface EmailReservationInput { - mintCode: string; - email: string; - sendEmail?: boolean; -} diff --git a/packages/poaps/src/types/response.ts b/packages/poaps/src/types/PoapMintStatus.ts similarity index 100% rename from packages/poaps/src/types/response.ts rename to packages/poaps/src/types/PoapMintStatus.ts diff --git a/packages/poaps/src/types/PoapsSortFields.ts b/packages/poaps/src/types/PoapsSortFields.ts new file mode 100644 index 00000000..e8c5d332 --- /dev/null +++ b/packages/poaps/src/types/PoapsSortFields.ts @@ -0,0 +1,12 @@ +/** + * Enum to define available fields for sorting POAPs. + * + * @export + * @enum {string} + */ +export enum PoapsSortFields { + /** Represents sorting by the date when a POAP was minted. */ + MintedOn = 'minted_on', + /** Represents sorting by the ID of a POAP. */ + Id = 'id', +} diff --git a/packages/poaps/src/types/WalletMintInput.ts b/packages/poaps/src/types/WalletMintInput.ts new file mode 100644 index 00000000..49b974c9 --- /dev/null +++ b/packages/poaps/src/types/WalletMintInput.ts @@ -0,0 +1,10 @@ +/** + * Represents the input fields required to mint a POAP for a wallet. + * + * @export + * @interface WalletMintInput + */ +export interface WalletMintInput { + mintCode: string; + address: string; +} diff --git a/packages/poaps/src/types/index.ts b/packages/poaps/src/types/index.ts deleted file mode 100644 index eccece42..00000000 --- a/packages/poaps/src/types/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './input'; -export * from './response'; diff --git a/packages/poaps/src/utils/PoapIndexed.ts b/packages/poaps/src/utils/PoapIndexed.ts index fc7e7c9d..427bc33f 100644 --- a/packages/poaps/src/utils/PoapIndexed.ts +++ b/packages/poaps/src/utils/PoapIndexed.ts @@ -1,6 +1,6 @@ import { TokensApiProvider } from '@poap-xyz/providers'; import { RetryableTask } from './RetryableTask'; -import { PoapMintStatus } from '../types'; +import { PoapMintStatus } from '../types/PoapMintStatus'; /** * @class PoapIndexed @@ -15,10 +15,10 @@ export class PoapIndexed extends RetryableTask { /** * Creates an instance of the PoapIndexed class. * - * @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. + * @param {string} mintCode - A unique Mint Code representing the token. */ - constructor(mintCode: string, tokensApiProvider: TokensApiProvider) { + constructor(tokensApiProvider: TokensApiProvider, mintCode: string) { super(tokensApiProvider); this.mintCode = mintCode; } diff --git a/packages/providers/package.json b/packages/providers/package.json index 089fa2fc..414072b5 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.4.0", + "version": "0.5.0", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,7 +26,7 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/utils": "0.4.0", + "@poap-xyz/utils": "0.5.0", "axios": "^1.6.8", "lodash.chunk": "^4.2.0" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 12839631..21ebabe4 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/utils", - "version": "0.4.0", + "version": "0.5.0", "description": "Utils module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", diff --git a/yarn.lock b/yarn.lock index 4c48476c..2fe25dbf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -884,8 +884,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/drops@workspace:packages/drops" dependencies: - "@poap-xyz/providers": 0.4.0 - "@poap-xyz/utils": 0.4.0 + "@poap-xyz/providers": 0.5.0 + "@poap-xyz/utils": 0.5.0 languageName: unknown linkType: soft @@ -901,8 +901,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/moments@workspace:packages/moments" dependencies: - "@poap-xyz/providers": 0.4.0 - "@poap-xyz/utils": 0.4.0 + "@poap-xyz/providers": 0.5.0 + "@poap-xyz/utils": 0.5.0 "@types/uuid": ^9.0.2 uuid: ^9.0.0 languageName: unknown @@ -912,16 +912,16 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/poaps@workspace:packages/poaps" dependencies: - "@poap-xyz/providers": 0.4.0 - "@poap-xyz/utils": 0.4.0 + "@poap-xyz/providers": 0.5.0 + "@poap-xyz/utils": 0.5.0 languageName: unknown linkType: soft -"@poap-xyz/providers@*, @poap-xyz/providers@0.4.0, @poap-xyz/providers@workspace:packages/providers": +"@poap-xyz/providers@*, @poap-xyz/providers@0.5.0, @poap-xyz/providers@workspace:packages/providers": version: 0.0.0-use.local resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: - "@poap-xyz/utils": 0.4.0 + "@poap-xyz/utils": 0.5.0 axios: ^1.6.8 axios-mock-adapter: ^1.21.4 jest-fetch-mock: ^3.0.3 @@ -929,7 +929,7 @@ __metadata: languageName: unknown linkType: soft -"@poap-xyz/utils@*, @poap-xyz/utils@0.4.0, @poap-xyz/utils@workspace:packages/utils": +"@poap-xyz/utils@*, @poap-xyz/utils@0.5.0, @poap-xyz/utils@workspace:packages/utils": version: 0.0.0-use.local resolution: "@poap-xyz/utils@workspace:packages/utils" languageName: unknown