Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poap-xyz/poaps

Package Overview
Dependencies
Maintainers
4
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poap-xyz/poaps - npm Package Compare versions

Comparing version 0.0.38 to 0.0.39

dist/cjs/domain/POAPReservation.d.ts

28

dist/cjs/domain/Poap.d.ts
export declare class POAP {
id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
end_date: Date;
startDate: Date;
endDate: Date;
name: string;

@@ -18,13 +18,13 @@ constructor(properties: PoapProperties);

id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
startDate: Date;
name: string;
end_date: Date;
endDate: Date;
}
export { PoapsSortFields, FetchPoapsInput } from './types/input';
export { PoapMintStatus } from './types/response';
export { PoapsClient } from './PoapsClient';
export { POAP } from './domain/Poap';
export { POAPReservation } from './domain/POAPReservation';
export { FinishedWithError } from './errors/FinishedWithError';
export { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError';
export { CodeExpiredError } from './errors/CodeExpiredError';

@@ -1,9 +0,20 @@

import { CompassProvider } from '@poap-xyz/providers';
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers';
import { POAP } from './domain/Poap';
import { FetchPoapsInput } from './types';
import { PaginatedResult } from '@poap-xyz/utils';
import { POAPReservation } from './domain/POAPReservation';
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types';
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils';
import { PoapMintStatus } from './types/response';
export declare class PoapsClient {
private CompassProvider;
constructor(CompassProvider: CompassProvider);
private compassProvider;
private tokensApiProvider;
constructor(compassProvider: CompassProvider, tokensApiProvider: TokensApiProvider);
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>;
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>;
mintAsync(input: WalletMintInput): Promise<string>;
mintSync(input: WalletMintInput): Promise<POAP>;
emailReservation(input: EmailReservationInput): Promise<POAPReservation>;
}
export * from './input';
export * from './response';

@@ -9,10 +9,19 @@ import { Order, Chain, PaginationInput } from '@poap-xyz/utils';

chain?: Chain;
minted_date_from?: string;
minted_date_to?: string;
mintedDateFrom?: string;
mintedDateTo?: string;
ids?: number[];
collector_address?: string;
drop_id?: number;
sort_field?: PoapsSortFields;
sort_dir?: Order;
filter_by_zero_address?: boolean;
collectorAddress?: string;
dropId?: number;
sortField?: PoapsSortFields;
sortDir?: Order;
filterByZeroAddress?: boolean;
}
export interface WalletMintInput {
mintCode: string;
address: string;
}
export interface EmailReservationInput {
mintCode: string;
email: string;
sendEmail?: boolean;
}
export declare class POAP {
id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
end_date: Date;
startDate: Date;
endDate: Date;
name: string;

@@ -18,13 +18,13 @@ constructor(properties: PoapProperties);

id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
startDate: Date;
name: string;
end_date: Date;
endDate: Date;
}
export { PoapsSortFields, FetchPoapsInput } from './types/input';
export { PoapMintStatus } from './types/response';
export { PoapsClient } from './PoapsClient';
export { POAP } from './domain/Poap';
export { POAPReservation } from './domain/POAPReservation';
export { FinishedWithError } from './errors/FinishedWithError';
export { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError';
export { CodeExpiredError } from './errors/CodeExpiredError';

@@ -1,9 +0,20 @@

import { CompassProvider } from '@poap-xyz/providers';
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers';
import { POAP } from './domain/Poap';
import { FetchPoapsInput } from './types';
import { PaginatedResult } from '@poap-xyz/utils';
import { POAPReservation } from './domain/POAPReservation';
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types';
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils';
import { PoapMintStatus } from './types/response';
export declare class PoapsClient {
private CompassProvider;
constructor(CompassProvider: CompassProvider);
private compassProvider;
private tokensApiProvider;
constructor(compassProvider: CompassProvider, tokensApiProvider: TokensApiProvider);
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>;
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>;
mintAsync(input: WalletMintInput): Promise<string>;
mintSync(input: WalletMintInput): Promise<POAP>;
emailReservation(input: EmailReservationInput): Promise<POAPReservation>;
}
export * from './input';
export * from './response';

@@ -9,10 +9,19 @@ import { Order, Chain, PaginationInput } from '@poap-xyz/utils';

chain?: Chain;
minted_date_from?: string;
minted_date_to?: string;
mintedDateFrom?: string;
mintedDateTo?: string;
ids?: number[];
collector_address?: string;
drop_id?: number;
sort_field?: PoapsSortFields;
sort_dir?: Order;
filter_by_zero_address?: boolean;
collectorAddress?: string;
dropId?: number;
sortField?: PoapsSortFields;
sortDir?: Order;
filterByZeroAddress?: boolean;
}
export interface WalletMintInput {
mintCode: string;
address: string;
}
export interface EmailReservationInput {
mintCode: string;
email: string;
sendEmail?: boolean;
}
export declare class POAP {
id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
end_date: Date;
startDate: Date;
endDate: Date;
name: string;

@@ -18,13 +18,13 @@ constructor(properties: PoapProperties);

id: number;
collector_address: string;
transfer_count: number;
minted_on: Date;
drop_id: number;
image_url: string;
collectorAddress: string;
transferCount: number;
mintedOn: Date;
dropId: number;
imageUrl: string;
city: string;
country: string;
description: string;
start_date: Date;
startDate: Date;
name: string;
end_date: Date;
endDate: Date;
}
export { PoapsSortFields, FetchPoapsInput } from './types/input';
export { PoapMintStatus } from './types/response';
export { PoapsClient } from './PoapsClient';
export { POAP } from './domain/Poap';
export { POAPReservation } from './domain/POAPReservation';
export { FinishedWithError } from './errors/FinishedWithError';
export { CodeAlreadyMintedError } from './errors/CodeAlreadyMintedError';
export { CodeExpiredError } from './errors/CodeExpiredError';

@@ -16,12 +16,12 @@ (function (global, factory) {

this.id = properties.id;
this.collector_address = properties.collector_address;
this.minted_on = properties.minted_on;
this.drop_id = properties.drop_id;
this.transfer_count = properties.transfer_count;
this.image_url = properties.image_url;
this.collectorAddress = properties.collectorAddress;
this.mintedOn = properties.mintedOn;
this.dropId = properties.dropId;
this.transferCount = properties.transferCount;
this.imageUrl = properties.imageUrl;
this.city = properties.city;
this.country = properties.country;
this.description = properties.description;
this.start_date = properties.start_date;
this.end_date = properties.end_date;
this.startDate = properties.startDate;
this.endDate = properties.endDate;
this.name = properties.name;

@@ -31,2 +31,16 @@ }

class POAPReservation {
constructor(properties) {
this.email = properties.email;
this.dropId = properties.dropId;
this.imageUrl = properties.imageUrl;
this.city = properties.city;
this.country = properties.country;
this.description = properties.description;
this.startDate = properties.startDate;
this.endDate = properties.endDate;
this.name = properties.name;
}
}
const PAGINATED_POAPS_QUERY = `

@@ -59,2 +73,10 @@ query PaginatedPoaps(

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 Chain;

@@ -83,3 +105,3 @@ (function (Chain) {

}
function creatUndefinedOrder(key, value) {
function createUndefinedOrder(key, value) {
return key && value ? { [key]: value } : {};

@@ -118,33 +140,132 @@ }

class CodeAlreadyMintedError extends Error {
constructor(code) {
super(`Code: '${code}' already minted `);
}
}
class CodeExpiredError extends Error {
constructor(code) {
super(`Code: '${code}', has been expired`);
}
}
class FinishedWithError extends Error {
constructor(error, code) {
super(`Code: '${code}', finished with error: '${error}', please try again later `);
}
}
const MAX_RETRIES = 20;
const INITIAL_DELAY = 1000;
const BACKOFF_FACTOR = 1.2;
class RetryableTask {
constructor(tokensApiProvider) {
this.retries = 0;
this.delay = INITIAL_DELAY;
this.tokensApiProvider = tokensApiProvider;
}
backoffAndRetry(callback) {
if (this.retries >= MAX_RETRIES) {
throw new Error('Max retries reached');
}
this.retries++;
this.delay *= BACKOFF_FACTOR;
return new Promise((resolve, reject) => {
setTimeout(() => {
callback().then(resolve, reject);
}, this.delay);
});
}
}
class MintChecker extends RetryableTask {
constructor(queueUid, 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)) {
await this.backoffAndRetry(() => this.checkMintStatus());
}
else {
this.handleErrorStatus(mintStatusResponse, this.mintCode);
}
}
catch (e) {
await this.backoffAndRetry(() => this.checkMintStatus());
}
}
}
class PoapIndexed extends RetryableTask {
constructor(mintCode, tokensApiProvider) {
super(tokensApiProvider);
this.mintCode = mintCode;
}
async waitPoapIndexed() {
var _a;
let response = await this.tokensApiProvider.getMintCode(this.mintCode);
while (response.result == null) {
response = await this.backoffAndRetry(() => this.tokensApiProvider.getMintCode(this.mintCode));
}
return {
minted: response.claimed,
isActive: response.is_active,
secretCode: response.secret,
poapId: (_a = response.result) === null || _a === void 0 ? void 0 : _a.token,
};
}
}
class PoapsClient {
constructor(CompassProvider) {
this.CompassProvider = CompassProvider;
constructor(compassProvider, tokensApiProvider) {
this.compassProvider = compassProvider;
this.tokensApiProvider = tokensApiProvider;
}
async fetch(input) {
const { limit, offset, chain, collector_address, minted_date_from, minted_date_to, ids, drop_id, sort_field, sort_dir, filter_by_zero_address = true, } = input;
const { limit, offset, chain, collectorAddress, mintedDateFrom, mintedDateTo, ids, dropId, sortField, sortDir, filterByZeroAddress = true, } = input;
const variables = {
limit,
offset,
orderBy: creatUndefinedOrder(sort_field, sort_dir),
orderBy: createUndefinedOrder(sortField, sortDir),
where: {
...creatAddressFilter('collector_address', filter_by_zero_address, collector_address),
...creatAddressFilter('collector_address', filterByZeroAddress, collectorAddress),
...creatEqFilter('chain', chain),
...creatEqFilter('drop_id', drop_id),
...createBetweenFilter('minted_on', minted_date_from, minted_date_to),
...creatEqFilter('drop_id', dropId),
...createBetweenFilter('minted_on', mintedDateFrom, mintedDateTo),
...createInFilter('id', ids),
},
};
const { data } = await this.CompassProvider.request(PAGINATED_POAPS_QUERY, variables);
const { data } = await this.compassProvider.request(PAGINATED_POAPS_QUERY, variables);
const poaps = data.poaps.map((poap) => {
const { drop } = poap;
const minted_on = new Date(0);
minted_on.setUTCSeconds(poap.minted_on);
const mintedOn = new Date(0);
mintedOn.setUTCSeconds(poap.minted_on);
return new POAP({
...poap,
...drop,
id: Number(poap.id),
minted_on,
drop_id: Number(poap.drop_id),
start_date: new Date(drop.start_date),
end_date: new Date(drop.end_date),
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),
});

@@ -154,5 +275,81 @@ });

}
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) {
var _a;
const getMintCodeRaw = await this.tokensApiProvider.getMintCode(mintCode);
return {
minted: getMintCodeRaw.claimed,
isActive: getMintCodeRaw.is_active,
secretCode: getMintCodeRaw.secret,
poapId: (_a = getMintCodeRaw.result) === null || _a === void 0 ? void 0 : _a.token,
};
}
async getMintStatus(queueUid) {
const mintStatusResponse = await this.tokensApiProvider.mintStatus(queueUid);
return mintStatusResponse.status;
}
async waitMintStatus(queueUid, mintCode) {
const checker = new MintChecker(queueUid, this.tokensApiProvider, mintCode);
await checker.checkMintStatus();
}
async waitPoapIndexed(mintCode) {
const checker = new PoapIndexed(mintCode, this.tokensApiProvider);
return await checker.waitPoapIndexed();
}
async mintAsync(input) {
const secretCode = await this.getSecretCode(input.mintCode);
const response = await this.tokensApiProvider.postMintCode({
address: input.address,
qr_hash: input.mintCode,
secret: secretCode,
sendEmail: false,
});
return response.queue_uid;
}
async mintSync(input) {
const queueUid = await this.mintAsync(input);
await this.waitMintStatus(queueUid, input.mintCode);
const getCodeResponse = await this.waitPoapIndexed(input.mintCode);
return (await this.fetch({
limit: 1,
offset: 0,
ids: [getCodeResponse.poapId],
})).items[0];
}
async emailReservation(input) {
const secretCode = await this.getSecretCode(input.mintCode);
const response = await this.tokensApiProvider.postMintCode({
address: input.email,
qr_hash: input.mintCode,
secret: secretCode,
sendEmail: input.sendEmail || true,
});
return new POAPReservation({
email: input.email,
dropId: response.event.id,
imageUrl: response.event.image_url,
city: response.event.city,
country: response.event.country,
description: response.event.description,
startDate: new Date(response.event.start_date),
endDate: new Date(response.event.end_date),
name: response.event.name,
});
}
}
exports.CodeAlreadyMintedError = CodeAlreadyMintedError;
exports.CodeExpiredError = CodeExpiredError;
exports.FinishedWithError = FinishedWithError;
exports.POAP = POAP;
exports.POAPReservation = POAPReservation;
exports.PoapsClient = PoapsClient;

@@ -159,0 +356,0 @@

@@ -1,9 +0,20 @@

import { CompassProvider } from '@poap-xyz/providers';
import { CompassProvider, TokensApiProvider } from '@poap-xyz/providers';
import { POAP } from './domain/Poap';
import { FetchPoapsInput } from './types';
import { PaginatedResult } from '@poap-xyz/utils';
import { POAPReservation } from './domain/POAPReservation';
import { FetchPoapsInput, EmailReservationInput, WalletMintInput } from './types';
import { PaginatedResult, MintingStatus } from '@poap-xyz/utils';
import { PoapMintStatus } from './types/response';
export declare class PoapsClient {
private CompassProvider;
constructor(CompassProvider: CompassProvider);
private compassProvider;
private tokensApiProvider;
constructor(compassProvider: CompassProvider, tokensApiProvider: TokensApiProvider);
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>;
waitPoapIndexed(mintCode: string): Promise<PoapMintStatus>;
mintAsync(input: WalletMintInput): Promise<string>;
mintSync(input: WalletMintInput): Promise<POAP>;
emailReservation(input: EmailReservationInput): Promise<POAPReservation>;
}
export * from './input';
export * from './response';

@@ -9,10 +9,19 @@ import { Order, Chain, PaginationInput } from '@poap-xyz/utils';

chain?: Chain;
minted_date_from?: string;
minted_date_to?: string;
mintedDateFrom?: string;
mintedDateTo?: string;
ids?: number[];
collector_address?: string;
drop_id?: number;
sort_field?: PoapsSortFields;
sort_dir?: Order;
filter_by_zero_address?: boolean;
collectorAddress?: string;
dropId?: number;
sortField?: PoapsSortFields;
sortDir?: Order;
filterByZeroAddress?: boolean;
}
export interface WalletMintInput {
mintCode: string;
address: string;
}
export interface EmailReservationInput {
mintCode: string;
email: string;
sendEmail?: boolean;
}
{
"name": "@poap-xyz/poaps",
"version": "0.0.38",
"version": "0.0.39",
"description": "Poaps module for the poap.js library",

@@ -29,5 +29,5 @@ "main": "dist/cjs/index.cjs",

"dependencies": {
"@poap-xyz/providers": "0.0.38",
"@poap-xyz/utils": "0.0.38"
"@poap-xyz/providers": "0.0.39",
"@poap-xyz/utils": "0.0.39"
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc