@poap-xyz/poaps
Advanced tools
Comparing version 0.1.6 to 0.1.7-beta-v3
@@ -1,7 +0,6 @@ | ||
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers'; | ||
import { CompassProvider, TokensApiProvider, Transaction } from '@poap-xyz/providers'; | ||
import { POAP } from './domain/Poap'; | ||
import { POAPReservation } from './domain/POAPReservation'; | ||
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types'; | ||
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils'; | ||
import { PoapMintStatus } from './types/response'; | ||
import { EmailReservationInput, FetchPoapsInput, PoapMintStatus, WalletMintInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
export declare class PoapsClient { | ||
@@ -12,10 +11,10 @@ private compassProvider; | ||
fetch(input: FetchPoapsInput): Promise<PaginatedResult<POAP>>; | ||
private getSecretCode; | ||
getMintCode(mintCode: string): Promise<PoapMintStatus>; | ||
getMintStatus(queueUid: string): Promise<MintingStatus>; | ||
waitMintStatus(queueUid: string, mintCode: string): Promise<void>; | ||
getMintTransaction(qrHash: string): Promise<Transaction | null>; | ||
waitMintStatus(mintCode: string): Promise<void>; | ||
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>; | ||
mintAsync(input: WalletMintInput): Promise<string>; | ||
mintAsync(input: WalletMintInput): Promise<void>; | ||
mintSync(input: WalletMintInput): Promise<POAP>; | ||
emailReservation(input: EmailReservationInput): Promise<POAPReservation>; | ||
private getSecretCode; | ||
} |
import { TokensApiProvider } from '@poap-xyz/providers'; | ||
import { RetryableTask } from './RetryableTask'; | ||
export declare class MintChecker extends RetryableTask { | ||
private queueUid; | ||
private mintCode; | ||
constructor(queueUid: string, tokensApiProvider: TokensApiProvider, mintCode: string); | ||
constructor(tokensApiProvider: TokensApiProvider, mintCode: string); | ||
checkMintStatus(): Promise<void>; | ||
private shouldRetry; | ||
private handleErrorStatus; | ||
checkMintStatus(): Promise<void>; | ||
} |
@@ -1,7 +0,6 @@ | ||
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers'; | ||
import { CompassProvider, TokensApiProvider, Transaction } from '@poap-xyz/providers'; | ||
import { POAP } from './domain/Poap'; | ||
import { POAPReservation } from './domain/POAPReservation'; | ||
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types'; | ||
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils'; | ||
import { PoapMintStatus } from './types/response'; | ||
import { EmailReservationInput, FetchPoapsInput, PoapMintStatus, WalletMintInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
export declare class PoapsClient { | ||
@@ -12,10 +11,10 @@ private compassProvider; | ||
fetch(input: FetchPoapsInput): Promise<PaginatedResult<POAP>>; | ||
private getSecretCode; | ||
getMintCode(mintCode: string): Promise<PoapMintStatus>; | ||
getMintStatus(queueUid: string): Promise<MintingStatus>; | ||
waitMintStatus(queueUid: string, mintCode: string): Promise<void>; | ||
getMintTransaction(qrHash: string): Promise<Transaction | null>; | ||
waitMintStatus(mintCode: string): Promise<void>; | ||
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>; | ||
mintAsync(input: WalletMintInput): Promise<string>; | ||
mintAsync(input: WalletMintInput): Promise<void>; | ||
mintSync(input: WalletMintInput): Promise<POAP>; | ||
emailReservation(input: EmailReservationInput): Promise<POAPReservation>; | ||
private getSecretCode; | ||
} |
import { TokensApiProvider } from '@poap-xyz/providers'; | ||
import { RetryableTask } from './RetryableTask'; | ||
export declare class MintChecker extends RetryableTask { | ||
private queueUid; | ||
private mintCode; | ||
constructor(queueUid: string, tokensApiProvider: TokensApiProvider, mintCode: string); | ||
constructor(tokensApiProvider: TokensApiProvider, mintCode: string); | ||
checkMintStatus(): Promise<void>; | ||
private shouldRetry; | ||
private handleErrorStatus; | ||
checkMintStatus(): Promise<void>; | ||
} |
@@ -71,9 +71,9 @@ (function (global, factory) { | ||
var MintingStatus; | ||
(function (MintingStatus) { | ||
MintingStatus["PENDING"] = "PENDING"; | ||
MintingStatus["IN_PROCESS"] = "IN_PROCESS"; | ||
MintingStatus["FINISH"] = "FINISH"; | ||
MintingStatus["FINISH_WITH_ERROR"] = "FINISH_WITH_ERROR"; | ||
})(MintingStatus || (MintingStatus = {})); | ||
var TransactionRequestStatus; | ||
(function (TransactionRequestStatus) { | ||
TransactionRequestStatus["PENDING"] = "PENDING"; | ||
TransactionRequestStatus["IN_PROCESS"] = "IN_PROCESS"; | ||
TransactionRequestStatus["FINISH"] = "FINISH"; | ||
TransactionRequestStatus["FINISH_WITH_ERROR"] = "FINISH_WITH_ERROR"; | ||
})(TransactionRequestStatus || (TransactionRequestStatus = {})); | ||
@@ -149,2 +149,17 @@ var Chain; | ||
var TransactionStatus; | ||
(function (TransactionStatus) { | ||
TransactionStatus["pending"] = "pending"; | ||
TransactionStatus["passed"] = "passed"; | ||
TransactionStatus["failed"] = "failed"; | ||
TransactionStatus["waiting"] = "waiting_tx"; | ||
})(TransactionStatus || (TransactionStatus = {})); | ||
var MediaStatus; | ||
(function (MediaStatus) { | ||
MediaStatus["INVALID"] = "INVALID"; | ||
MediaStatus["PROCESSED"] = "PROCESSED"; | ||
MediaStatus["IN_PROCESS"] = "IN_PROCESS"; | ||
})(MediaStatus || (MediaStatus = {})); | ||
class FinishedWithError extends Error { | ||
@@ -180,31 +195,31 @@ constructor(error, code) { | ||
class MintChecker extends RetryableTask { | ||
constructor(queueUid, tokensApiProvider, mintCode) { | ||
constructor(tokensApiProvider, mintCode) { | ||
super(tokensApiProvider); | ||
this.queueUid = queueUid; | ||
this.mintCode = mintCode; | ||
} | ||
shouldRetry(status) { | ||
return (status === MintingStatus.IN_PROCESS || status === MintingStatus.PENDING); | ||
} | ||
handleErrorStatus(mintStatusResponse, mintCode) { | ||
var _a, _b; | ||
if (mintStatusResponse.status === MintingStatus.FINISH_WITH_ERROR && | ||
((_a = mintStatusResponse.result) === null || _a === void 0 ? void 0 : _a.error)) { | ||
throw new FinishedWithError((_b = mintStatusResponse.result) === null || _b === void 0 ? void 0 : _b.error, mintCode); | ||
} | ||
} | ||
async checkMintStatus() { | ||
try { | ||
const mintStatusResponse = await this.tokensApiProvider.mintStatus(this.queueUid); | ||
if (this.shouldRetry(mintStatusResponse.status)) { | ||
const transaction = await this.tokensApiProvider.getMintTransaction(this.mintCode); | ||
if (this.shouldRetry(transaction)) { | ||
await this.backoffAndRetry(() => this.checkMintStatus()); | ||
} | ||
else { | ||
this.handleErrorStatus(mintStatusResponse, this.mintCode); | ||
this.handleErrorStatus(transaction, this.mintCode); | ||
} | ||
} | ||
catch (e) { | ||
if (e instanceof FinishedWithError) { | ||
throw e; | ||
} | ||
await this.backoffAndRetry(() => this.checkMintStatus()); | ||
} | ||
} | ||
shouldRetry(transaction) { | ||
return !transaction || transaction.status === TransactionStatus.pending; | ||
} | ||
handleErrorStatus(transaction, mintCode) { | ||
if ((transaction === null || transaction === void 0 ? void 0 : transaction.status) === TransactionStatus.failed) { | ||
throw new FinishedWithError('The Transaction associated with this mint failed', mintCode); | ||
} | ||
} | ||
} | ||
@@ -273,12 +288,2 @@ | ||
} | ||
async getSecretCode(mintCode) { | ||
const getCodeResponse = await this.getMintCode(mintCode); | ||
if (getCodeResponse.minted == true) { | ||
throw new CodeAlreadyMintedError(mintCode); | ||
} | ||
if (getCodeResponse.isActive == false) { | ||
throw new CodeExpiredError(mintCode); | ||
} | ||
return getCodeResponse.secretCode; | ||
} | ||
async getMintCode(mintCode) { | ||
@@ -294,8 +299,7 @@ var _a; | ||
} | ||
async getMintStatus(queueUid) { | ||
const mintStatusResponse = await this.tokensApiProvider.mintStatus(queueUid); | ||
return mintStatusResponse.status; | ||
async getMintTransaction(qrHash) { | ||
return await this.tokensApiProvider.getMintTransaction(qrHash); | ||
} | ||
async waitMintStatus(queueUid, mintCode) { | ||
const checker = new MintChecker(queueUid, this.tokensApiProvider, mintCode); | ||
async waitMintStatus(mintCode) { | ||
const checker = new MintChecker(this.tokensApiProvider, mintCode); | ||
await checker.checkMintStatus(); | ||
@@ -309,3 +313,3 @@ } | ||
const secretCode = await this.getSecretCode(input.mintCode); | ||
const response = await this.tokensApiProvider.postMintCode({ | ||
await this.tokensApiProvider.postMintCode({ | ||
address: input.address, | ||
@@ -316,7 +320,6 @@ qr_hash: input.mintCode, | ||
}); | ||
return response.queue_uid; | ||
} | ||
async mintSync(input) { | ||
const queueUid = await this.mintAsync(input); | ||
await this.waitMintStatus(queueUid, input.mintCode); | ||
await this.mintAsync(input); | ||
await this.waitMintStatus(input.mintCode); | ||
const getCodeResponse = await this.waitPoapIndexed(input.mintCode); | ||
@@ -349,2 +352,12 @@ return (await this.fetch({ | ||
} | ||
async getSecretCode(mintCode) { | ||
const getCodeResponse = await this.getMintCode(mintCode); | ||
if (getCodeResponse.minted) { | ||
throw new CodeAlreadyMintedError(mintCode); | ||
} | ||
if (!getCodeResponse.isActive) { | ||
throw new CodeExpiredError(mintCode); | ||
} | ||
return getCodeResponse.secretCode; | ||
} | ||
} | ||
@@ -351,0 +364,0 @@ |
@@ -1,7 +0,6 @@ | ||
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers'; | ||
import { CompassProvider, TokensApiProvider, Transaction } from '@poap-xyz/providers'; | ||
import { POAP } from './domain/Poap'; | ||
import { POAPReservation } from './domain/POAPReservation'; | ||
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types'; | ||
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils'; | ||
import { PoapMintStatus } from './types/response'; | ||
import { EmailReservationInput, FetchPoapsInput, PoapMintStatus, WalletMintInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
export declare class PoapsClient { | ||
@@ -12,10 +11,10 @@ private compassProvider; | ||
fetch(input: FetchPoapsInput): Promise<PaginatedResult<POAP>>; | ||
private getSecretCode; | ||
getMintCode(mintCode: string): Promise<PoapMintStatus>; | ||
getMintStatus(queueUid: string): Promise<MintingStatus>; | ||
waitMintStatus(queueUid: string, mintCode: string): Promise<void>; | ||
getMintTransaction(qrHash: string): Promise<Transaction | null>; | ||
waitMintStatus(mintCode: string): Promise<void>; | ||
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>; | ||
mintAsync(input: WalletMintInput): Promise<string>; | ||
mintAsync(input: WalletMintInput): Promise<void>; | ||
mintSync(input: WalletMintInput): Promise<POAP>; | ||
emailReservation(input: EmailReservationInput): Promise<POAPReservation>; | ||
private getSecretCode; | ||
} |
import { TokensApiProvider } from '@poap-xyz/providers'; | ||
import { RetryableTask } from './RetryableTask'; | ||
export declare class MintChecker extends RetryableTask { | ||
private queueUid; | ||
private mintCode; | ||
constructor(queueUid: string, tokensApiProvider: TokensApiProvider, mintCode: string); | ||
constructor(tokensApiProvider: TokensApiProvider, mintCode: string); | ||
checkMintStatus(): Promise<void>; | ||
private shouldRetry; | ||
private handleErrorStatus; | ||
checkMintStatus(): Promise<void>; | ||
} |
{ | ||
"name": "@poap-xyz/poaps", | ||
"version": "0.1.6", | ||
"version": "0.1.7-beta-v3", | ||
"description": "Poaps module for the poap.js library", | ||
@@ -29,8 +29,9 @@ "main": "dist/cjs/index.cjs", | ||
"dependencies": { | ||
"@poap-xyz/providers": "0.1.6", | ||
"@poap-xyz/utils": "0.1.6" | ||
"@poap-xyz/providers": "0.1.7-beta-v3", | ||
"@poap-xyz/utils": "0.1.7-beta-v3" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
}, | ||
"stableVersion": "0.1.7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
217917
1534
+ Added@poap-xyz/providers@0.1.7-beta-v3(transitive)
+ Added@poap-xyz/utils@0.1.7-beta-v3(transitive)
- Removed@poap-xyz/providers@0.1.6(transitive)
- Removed@poap-xyz/utils@0.1.6(transitive)