@poap-xyz/drops
Advanced tools
Comparing version
@@ -0,1 +1,3 @@ | ||
import { DropResponse as ProviderDropResponse } from '@poap-xyz/providers'; | ||
import { DropResponse } from '../types/DropResponse'; | ||
export declare class Drop { | ||
@@ -25,2 +27,4 @@ id: number; | ||
emailReservationCount: number; | ||
static fromCompass(response: DropResponse): Drop; | ||
static fromProvider(response: ProviderDropResponse): Drop; | ||
constructor(properties: DropProperties); | ||
@@ -30,3 +34,3 @@ getTotalMinted(): number; | ||
} | ||
export interface SerializableDrop { | ||
interface SerializableDrop { | ||
id: number; | ||
@@ -50,9 +54,9 @@ fancyId: string; | ||
createdDate: string; | ||
expiryDate: string; | ||
endDate: string; | ||
poapCount: number; | ||
transferCount: number; | ||
emailReservationCount: number; | ||
expiryDate: string; | ||
endDate: string; | ||
} | ||
export interface DropProperties { | ||
interface DropProperties { | ||
id: number; | ||
@@ -82,1 +86,2 @@ fancyId: string; | ||
} | ||
export {}; |
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, SearchDropsInput, UpdateDropsInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { CreateDropsInput } from './types/CreateDropsInput'; | ||
import { UpdateDropsInput } from './types/UpdateDropsInput'; | ||
import { FetchDropsInput } from './types/FetchDropsInput'; | ||
import { SearchDropsInput } from './types/SearchDropsInput'; | ||
export declare class DropsClient { | ||
@@ -13,6 +16,2 @@ private compassProvider; | ||
update(input: UpdateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
private mapDrop; | ||
} |
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'; |
@@ -1,2 +0,1 @@ | ||
import { DropImageResponse } from './DropImageResponse'; | ||
export interface DropResponse { | ||
@@ -33,3 +32,8 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image: { | ||
gateways: Array<{ | ||
type: 'CROP' | 'ORIGINAL'; | ||
url: string; | ||
}>; | ||
}; | ||
} |
@@ -0,1 +1,3 @@ | ||
import { DropResponse as ProviderDropResponse } from '@poap-xyz/providers'; | ||
import { DropResponse } from '../types/DropResponse'; | ||
export declare class Drop { | ||
@@ -25,2 +27,4 @@ id: number; | ||
emailReservationCount: number; | ||
static fromCompass(response: DropResponse): Drop; | ||
static fromProvider(response: ProviderDropResponse): Drop; | ||
constructor(properties: DropProperties); | ||
@@ -30,3 +34,3 @@ getTotalMinted(): number; | ||
} | ||
export interface SerializableDrop { | ||
interface SerializableDrop { | ||
id: number; | ||
@@ -50,9 +54,9 @@ fancyId: string; | ||
createdDate: string; | ||
expiryDate: string; | ||
endDate: string; | ||
poapCount: number; | ||
transferCount: number; | ||
emailReservationCount: number; | ||
expiryDate: string; | ||
endDate: string; | ||
} | ||
export interface DropProperties { | ||
interface DropProperties { | ||
id: number; | ||
@@ -82,1 +86,2 @@ fancyId: string; | ||
} | ||
export {}; |
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, SearchDropsInput, UpdateDropsInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { CreateDropsInput } from './types/CreateDropsInput'; | ||
import { UpdateDropsInput } from './types/UpdateDropsInput'; | ||
import { FetchDropsInput } from './types/FetchDropsInput'; | ||
import { SearchDropsInput } from './types/SearchDropsInput'; | ||
export declare class DropsClient { | ||
@@ -13,6 +16,2 @@ private compassProvider; | ||
update(input: UpdateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
private mapDrop; | ||
} |
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'; |
@@ -1,2 +0,1 @@ | ||
import { DropImageResponse } from './DropImageResponse'; | ||
export interface DropResponse { | ||
@@ -33,3 +32,8 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image: { | ||
gateways: Array<{ | ||
type: 'CROP' | 'ORIGINAL'; | ||
url: string; | ||
}>; | ||
}; | ||
} |
@@ -0,1 +1,3 @@ | ||
import { DropResponse as ProviderDropResponse } from '@poap-xyz/providers'; | ||
import { DropResponse } from '../types/DropResponse'; | ||
export declare class Drop { | ||
@@ -25,2 +27,4 @@ id: number; | ||
emailReservationCount: number; | ||
static fromCompass(response: DropResponse): Drop; | ||
static fromProvider(response: ProviderDropResponse): Drop; | ||
constructor(properties: DropProperties); | ||
@@ -30,3 +34,3 @@ getTotalMinted(): number; | ||
} | ||
export interface SerializableDrop { | ||
interface SerializableDrop { | ||
id: number; | ||
@@ -50,9 +54,9 @@ fancyId: string; | ||
createdDate: string; | ||
expiryDate: string; | ||
endDate: string; | ||
poapCount: number; | ||
transferCount: number; | ||
emailReservationCount: number; | ||
expiryDate: string; | ||
endDate: string; | ||
} | ||
export interface DropProperties { | ||
interface DropProperties { | ||
id: number; | ||
@@ -82,1 +86,2 @@ fancyId: string; | ||
} | ||
export {}; |
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, SearchDropsInput, UpdateDropsInput } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
import { CreateDropsInput } from './types/CreateDropsInput'; | ||
import { UpdateDropsInput } from './types/UpdateDropsInput'; | ||
import { FetchDropsInput } from './types/FetchDropsInput'; | ||
import { SearchDropsInput } from './types/SearchDropsInput'; | ||
export declare class DropsClient { | ||
@@ -13,6 +16,2 @@ private compassProvider; | ||
update(input: UpdateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
private mapDrop; | ||
} |
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'; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@poap-xyz/drops"] = {})); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@poap-xyz/drops"] = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
class Drop { | ||
constructor(properties) { | ||
this.id = properties.id; | ||
this.fancyId = properties.fancyId; | ||
this.name = properties.name; | ||
this.description = properties.description; | ||
this.city = properties.city; | ||
this.country = properties.country; | ||
this.channel = properties.channel; | ||
this.platform = properties.platform; | ||
this.locationType = properties.locationType; | ||
this.dropUrl = properties.dropUrl; | ||
this.imageUrl = properties.imageUrl; | ||
this.originalImageUrl = properties.originalImageUrl; | ||
this.animationUrl = properties.animationUrl; | ||
this.year = properties.year; | ||
this.startDate = properties.startDate; | ||
this.timezone = properties.timezone; | ||
this.private = properties.private; | ||
this.createdDate = properties.createdDate; | ||
this.poapCount = properties.poapCount; | ||
this.transferCount = properties.transferCount; | ||
this.emailReservationCount = properties.emailReservationCount; | ||
this.expiryDate = properties.expiryDate; | ||
this.endDate = properties.endDate; | ||
} | ||
getTotalMinted() { | ||
return this.poapCount + this.emailReservationCount; | ||
} | ||
toSerializableObject() { | ||
return { | ||
id: this.id, | ||
fancyId: this.fancyId, | ||
name: this.name, | ||
description: this.description, | ||
city: this.city, | ||
country: this.country, | ||
channel: this.channel, | ||
platform: this.platform, | ||
locationType: this.locationType, | ||
dropUrl: this.dropUrl, | ||
imageUrl: this.imageUrl, | ||
originalImageUrl: this.originalImageUrl, | ||
animationUrl: this.animationUrl, | ||
year: this.year, | ||
timezone: this.timezone, | ||
private: this.private, | ||
startDate: this.startDate.toISOString(), | ||
createdDate: this.createdDate.toISOString(), | ||
poapCount: this.poapCount, | ||
transferCount: this.transferCount, | ||
emailReservationCount: this.emailReservationCount, | ||
expiryDate: this.expiryDate.toISOString(), | ||
endDate: this.endDate.toISOString(), | ||
}; | ||
} | ||
} | ||
class PaginatedResult { | ||
constructor(items, nextCursor) { | ||
this.items = items; | ||
this.nextCursor = nextCursor; | ||
} | ||
} | ||
const PAGINATED_DROPS_QUERY = ` | ||
var Order; | ||
(function (Order) { | ||
Order["ASC"] = "asc"; | ||
Order["DESC"] = "desc"; | ||
})(Order || (Order = {})); | ||
var Chain; | ||
(function (Chain) { | ||
Chain["Ethereum"] = "mainnet"; | ||
Chain["Gnosis"] = "xdai"; | ||
})(Chain || (Chain = {})); | ||
var TransactionRequestStatus; | ||
(function (TransactionRequestStatus) { | ||
TransactionRequestStatus["PENDING"] = "PENDING"; | ||
TransactionRequestStatus["IN_PROCESS"] = "IN_PROCESS"; | ||
TransactionRequestStatus["FINISH"] = "FINISH"; | ||
TransactionRequestStatus["FINISH_WITH_ERROR"] = "FINISH_WITH_ERROR"; | ||
})(TransactionRequestStatus || (TransactionRequestStatus = {})); | ||
function nextCursor(length, limit, offset) { | ||
const endIndex = offset + length; | ||
return endIndex < offset + limit ? null : endIndex; | ||
} | ||
function createField(keys, value) { | ||
return keys.split('.').reduceRight((prev, key) => ({ | ||
[key]: prev, | ||
}), value); | ||
} | ||
function createLikeFilter(key, value) { | ||
return value | ||
? createField(key, { _ilike: `%${value}%` }) | ||
: {}; | ||
} | ||
function createBoolFilter(key, value) { | ||
return typeof value === 'boolean' | ||
? createField(key, { | ||
_eq: value ? 'true' : 'false', | ||
}) | ||
: {}; | ||
} | ||
function createInFilter(key, values) { | ||
return values && values.length > 0 | ||
? createField(key, { _in: values }) | ||
: {}; | ||
} | ||
function createBetweenFilter(key, from, to) { | ||
const betweenFilter = {}; | ||
if (from) { | ||
betweenFilter._gte = from; | ||
} | ||
if (to) { | ||
betweenFilter._lte = to; | ||
} | ||
return from || to | ||
? createField(key, betweenFilter) | ||
: {}; | ||
} | ||
function createOrderBy(key, value) { | ||
return key && value ? createField(key, value) : {}; | ||
} | ||
function removeSpecialCharacters(str) { | ||
return str.replace(/[^a-zA-Z0-9 ]/g, ''); | ||
} | ||
function isNumeric(value, allowNegative = false) { | ||
if (typeof value === 'string') { | ||
return (allowNegative ? /^-?\d+$/ : /^\d+$/).test(value); | ||
} | ||
if (typeof value === 'number') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
class Drop { | ||
static fromCompass(response) { | ||
const images = 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), | ||
}); | ||
} | ||
static fromProvider(response) { | ||
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, | ||
}); | ||
} | ||
constructor(properties) { | ||
this.id = properties.id; | ||
this.fancyId = properties.fancyId; | ||
this.name = properties.name; | ||
this.description = properties.description; | ||
this.city = properties.city; | ||
this.country = properties.country; | ||
this.channel = properties.channel; | ||
this.platform = properties.platform; | ||
this.locationType = properties.locationType; | ||
this.dropUrl = properties.dropUrl; | ||
this.imageUrl = properties.imageUrl; | ||
this.originalImageUrl = properties.originalImageUrl; | ||
this.animationUrl = properties.animationUrl; | ||
this.year = properties.year; | ||
this.startDate = properties.startDate; | ||
this.timezone = properties.timezone; | ||
this.private = properties.private; | ||
this.createdDate = properties.createdDate; | ||
this.poapCount = properties.poapCount; | ||
this.transferCount = properties.transferCount; | ||
this.emailReservationCount = properties.emailReservationCount; | ||
this.expiryDate = properties.expiryDate; | ||
this.endDate = properties.endDate; | ||
} | ||
getTotalMinted() { | ||
return this.poapCount + this.emailReservationCount; | ||
} | ||
toSerializableObject() { | ||
return { | ||
id: this.id, | ||
fancyId: this.fancyId, | ||
name: this.name, | ||
description: this.description, | ||
city: this.city, | ||
country: this.country, | ||
channel: this.channel, | ||
platform: this.platform, | ||
locationType: this.locationType, | ||
dropUrl: this.dropUrl, | ||
imageUrl: this.imageUrl, | ||
originalImageUrl: this.originalImageUrl, | ||
animationUrl: this.animationUrl, | ||
year: this.year, | ||
timezone: this.timezone, | ||
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, | ||
}; | ||
} | ||
} | ||
const PAGINATED_DROPS_QUERY = ` | ||
query PaginatedDrops( | ||
@@ -113,89 +260,3 @@ $limit: Int! | ||
class PaginatedResult { | ||
constructor(items, nextCursor) { | ||
this.items = items; | ||
this.nextCursor = nextCursor; | ||
} | ||
} | ||
var Order; | ||
(function (Order) { | ||
Order["ASC"] = "asc"; | ||
Order["DESC"] = "desc"; | ||
})(Order || (Order = {})); | ||
var Chain; | ||
(function (Chain) { | ||
Chain["Ethereum"] = "mainnet"; | ||
Chain["Gnosis"] = "xdai"; | ||
})(Chain || (Chain = {})); | ||
var TransactionRequestStatus; | ||
(function (TransactionRequestStatus) { | ||
TransactionRequestStatus["PENDING"] = "PENDING"; | ||
TransactionRequestStatus["IN_PROCESS"] = "IN_PROCESS"; | ||
TransactionRequestStatus["FINISH"] = "FINISH"; | ||
TransactionRequestStatus["FINISH_WITH_ERROR"] = "FINISH_WITH_ERROR"; | ||
})(TransactionRequestStatus || (TransactionRequestStatus = {})); | ||
function nextCursor(length, limit, offset) { | ||
const endIndex = offset + length; | ||
return endIndex < offset + limit ? null : endIndex; | ||
} | ||
function createField(keys, value) { | ||
return keys.split('.').reduceRight((prev, key) => ({ | ||
[key]: prev, | ||
}), value); | ||
} | ||
function createLikeFilter(key, value) { | ||
return value | ||
? createField(key, { _ilike: `%${value}%` }) | ||
: {}; | ||
} | ||
function createBoolFilter(key, value) { | ||
return typeof value === 'boolean' | ||
? createField(key, { | ||
_eq: value ? 'true' : 'false', | ||
}) | ||
: {}; | ||
} | ||
function createInFilter(key, values) { | ||
return values && values.length > 0 | ||
? createField(key, { _in: values }) | ||
: {}; | ||
} | ||
function createBetweenFilter(key, from, to) { | ||
const betweenFilter = {}; | ||
if (from) { | ||
betweenFilter._gte = from; | ||
} | ||
if (to) { | ||
betweenFilter._lte = to; | ||
} | ||
return from || to | ||
? createField(key, betweenFilter) | ||
: {}; | ||
} | ||
function createOrderBy(key, value) { | ||
return key && value ? createField(key, value) : {}; | ||
} | ||
function removeSpecialCharacters(str) { | ||
return str.replace(/[^a-zA-Z0-9 ]/g, ''); | ||
} | ||
function isNumeric(value, allowNegative = false) { | ||
if (typeof value === 'string') { | ||
return (allowNegative ? /^-?\d+$/ : /^\d+$/).test(value); | ||
} | ||
if (typeof value === 'number') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
const SEARCH_DROPS_QUERY = ` | ||
const SEARCH_DROPS_QUERY = ` | ||
query SearchDrops( | ||
@@ -253,167 +314,93 @@ $limit: Int! | ||
class DropsClient { | ||
constructor(compassProvider, dropApiProvider) { | ||
this.compassProvider = compassProvider; | ||
this.dropApiProvider = dropApiProvider; | ||
} | ||
async fetch(input) { | ||
const { limit, offset, name, sortField, sortDir, from, to, ids, isPrivate, } = input; | ||
const variables = { | ||
limit, | ||
offset, | ||
orderBy: createOrderBy(sortField, sortDir), | ||
where: { | ||
...createBoolFilter('private', isPrivate), | ||
...createLikeFilter('name', name), | ||
...createBetweenFilter('created_date', from, to), | ||
...createInFilter('id', ids), | ||
}, | ||
}; | ||
const { data } = await this.compassProvider.request(PAGINATED_DROPS_QUERY, variables); | ||
const drops = data.drops.map((drop) => this.mapDrop(drop)); | ||
return new PaginatedResult(drops, nextCursor(drops.length, limit, offset)); | ||
} | ||
async search(input) { | ||
const { search, offset, limit } = input; | ||
if (!search) { | ||
return new PaginatedResult([], null); | ||
} | ||
const variables = { | ||
limit, | ||
offset, | ||
...(isNumeric(search) && { orderBy: { id: Order.ASC } }), | ||
args: { | ||
search: removeSpecialCharacters(search), | ||
}, | ||
}; | ||
const { data } = await this.compassProvider.request(SEARCH_DROPS_QUERY, variables); | ||
const drops = data.search_drops.map((drop) => this.mapDrop(drop)); | ||
return new PaginatedResult(drops, nextCursor(drops.length, limit, offset)); | ||
} | ||
async create(input) { | ||
const repsonse = await this.dropApiProvider.createDrop({ | ||
name: input.name, | ||
description: input.description, | ||
city: input.city, | ||
country: input.country, | ||
start_date: input.startDate, | ||
end_date: input.endDate, | ||
expiry_date: input.expiryDate, | ||
event_url: input.eventUrl, | ||
virtual_event: input.virtualEvent, | ||
image: input.image, | ||
filename: input.filename, | ||
contentType: input.contentType, | ||
secret_code: input.secretCode, | ||
event_template_id: input.eventTemplateId, | ||
email: input.email, | ||
requested_codes: input.requestedCodes, | ||
private_event: input.privateEvent, | ||
}); | ||
return this.formatDrop(repsonse); | ||
} | ||
async update(input) { | ||
const repsonse = await this.dropApiProvider.updateDrop({ | ||
name: input.name, | ||
description: input.description, | ||
country: input.country, | ||
city: input.city, | ||
start_date: input.startDate, | ||
end_date: input.endDate, | ||
expiry_date: input.expiryDate, | ||
event_url: input.eventUrl, | ||
virtual_event: input.virtualEvent, | ||
private_event: input.privateEvent, | ||
event_template_id: input.eventTemplateId, | ||
secret_code: input.secretCode, | ||
}); | ||
return this.formatDrop(repsonse); | ||
} | ||
formatDrop(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, | ||
}); | ||
} | ||
computeDropImages(drop) { | ||
const dropImage = this.mapDropImage(drop.drop_image); | ||
return { | ||
imageUrl: (dropImage === null || dropImage === void 0 ? void 0 : dropImage.crop) || drop.image_url, | ||
originalImageUrl: (dropImage === null || dropImage === void 0 ? void 0 : dropImage.original) || drop.image_url, | ||
}; | ||
} | ||
mapDropImage(response) { | ||
if (!response) | ||
return response; | ||
const images = response.gateways.reduce((acc, gateway) => ({ ...acc, [gateway.type.toLowerCase()]: gateway.url }), {}); | ||
return { ...images }; | ||
} | ||
mapDrop(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), | ||
}); | ||
} | ||
} | ||
class DropsClient { | ||
constructor(compassProvider, dropApiProvider) { | ||
this.compassProvider = compassProvider; | ||
this.dropApiProvider = dropApiProvider; | ||
} | ||
async fetch(input) { | ||
const { limit, offset, name, sortField, sortDir, from, to, ids, isPrivate, } = input; | ||
const variables = { | ||
limit, | ||
offset, | ||
orderBy: createOrderBy(sortField, sortDir), | ||
where: { | ||
...createBoolFilter('private', isPrivate), | ||
...createLikeFilter('name', name), | ||
...createBetweenFilter('created_date', from, to), | ||
...createInFilter('id', ids), | ||
}, | ||
}; | ||
const { data } = await this.compassProvider.request(PAGINATED_DROPS_QUERY, variables); | ||
const drops = data.drops.map((drop) => Drop.fromCompass(drop)); | ||
return new PaginatedResult(drops, nextCursor(drops.length, limit, offset)); | ||
} | ||
async search(input) { | ||
const { search, offset, limit } = input; | ||
if (!search) { | ||
return new PaginatedResult([], null); | ||
} | ||
const variables = { | ||
limit, | ||
offset, | ||
...(isNumeric(search) && { orderBy: { id: Order.ASC } }), | ||
args: { | ||
search: removeSpecialCharacters(search), | ||
}, | ||
}; | ||
const { data } = await this.compassProvider.request(SEARCH_DROPS_QUERY, variables); | ||
const drops = data.search_drops.map((drop) => Drop.fromCompass(drop)); | ||
return new PaginatedResult(drops, nextCursor(drops.length, limit, offset)); | ||
} | ||
async create(input) { | ||
const repsonse = await this.dropApiProvider.createDrop({ | ||
name: input.name, | ||
description: input.description, | ||
city: input.city, | ||
country: input.country, | ||
start_date: input.startDate, | ||
end_date: input.endDate, | ||
expiry_date: input.expiryDate, | ||
event_url: input.eventUrl, | ||
virtual_event: input.virtualEvent, | ||
image: input.image, | ||
filename: input.filename, | ||
contentType: input.contentType, | ||
secret_code: input.secretCode, | ||
event_template_id: input.eventTemplateId, | ||
email: input.email, | ||
requested_codes: input.requestedCodes, | ||
private_event: input.privateEvent, | ||
}); | ||
return Drop.fromProvider(repsonse); | ||
} | ||
async update(input) { | ||
const repsonse = await this.dropApiProvider.updateDrop({ | ||
name: input.name, | ||
description: input.description, | ||
country: input.country, | ||
city: input.city, | ||
start_date: input.startDate, | ||
end_date: input.endDate, | ||
expiry_date: input.expiryDate, | ||
event_url: input.eventUrl, | ||
virtual_event: input.virtualEvent, | ||
private_event: input.privateEvent, | ||
event_template_id: input.eventTemplateId, | ||
secret_code: input.secretCode, | ||
}); | ||
return Drop.fromProvider(repsonse); | ||
} | ||
} | ||
exports.DropsSortFields = void 0; | ||
(function (DropsSortFields) { | ||
DropsSortFields["Name"] = "name"; | ||
DropsSortFields["Id"] = "id"; | ||
DropsSortFields["StartDate"] = "start_date"; | ||
})(exports.DropsSortFields || (exports.DropsSortFields = {})); | ||
exports.DropsSortFields = void 0; | ||
(function (DropsSortFields) { | ||
DropsSortFields["Name"] = "name"; | ||
DropsSortFields["Id"] = "id"; | ||
DropsSortFields["StartDate"] = "start_date"; | ||
})(exports.DropsSortFields || (exports.DropsSortFields = {})); | ||
exports.Drop = Drop; | ||
exports.DropsClient = DropsClient; | ||
exports.Drop = Drop; | ||
exports.DropsClient = DropsClient; | ||
})); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,1 @@ | ||
import { DropImageResponse } from './DropImageResponse'; | ||
export interface DropResponse { | ||
@@ -33,3 +32,8 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image: { | ||
gateways: Array<{ | ||
type: 'CROP' | 'ORIGINAL'; | ||
url: string; | ||
}>; | ||
}; | ||
} |
{ | ||
"name": "@poap-xyz/drops", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Drops module for the poap.js library", | ||
@@ -32,5 +32,5 @@ "main": "dist/cjs/index.cjs", | ||
"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" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175208
-2.91%43
-6.52%1818
-1.3%+ Added
+ Added
- Removed
- Removed
Updated
Updated