@poap-xyz/drops
Advanced tools
Comparing version 0.1.3 to 0.1.4-beta-v1
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput } from './types'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput, DropImage } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
@@ -9,2 +9,3 @@ export declare class DropsClient { | ||
constructor(compassProvider: CompassProvider, dropApiProvider: DropApiProvider); | ||
fetchDropImage(id: number): Promise<DropImage | undefined>; | ||
fetch(input: FetchDropsInput): Promise<PaginatedResult<Drop>>; | ||
@@ -14,4 +15,3 @@ create(input: CreateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
} |
export * from './PaginatedDrop'; | ||
export * from './DropImage'; |
@@ -1,10 +0,3 @@ | ||
import { DropImageGatewayType } from '../types/dropImage'; | ||
import { DropImageGatewaysResponse } from './DropImage'; | ||
export declare const PAGINATED_DROPS_QUERY = "\n query PaginatedDrops(\n $limit: Int!\n $offset: Int!\n $orderBy: [drops_order_by!]\n $where: drops_bool_exp\n ) {\n drops(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {\n id\n fancy_id\n name\n description\n city\n country\n channel\n platform\n location_type\n drop_url\n image_url\n animation_url\n year\n start_date\n timezone\n private\n created_date\n expiry_date\n end_date\n stats_by_chain_aggregate {\n aggregate {\n sum {\n transfer_count\n poap_count\n }\n }\n }\n email_claims_stats {\n total\n }\n drop_image {\n gateways {\n type\n url\n }\n }\n }\n }\n"; | ||
export interface DropImageGatewayResponse { | ||
type: DropImageGatewayType; | ||
url: string; | ||
} | ||
export interface DropImageResponse { | ||
gateways: Array<DropImageGatewayResponse>; | ||
} | ||
export interface DropResponse { | ||
@@ -41,3 +34,3 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image?: DropImageGatewaysResponse; | ||
} | ||
@@ -44,0 +37,0 @@ export interface PaginatedDropsResponse { |
@@ -6,4 +6,4 @@ export declare enum DropImageGatewayType { | ||
export interface DropImage { | ||
original?: string; | ||
crop?: string; | ||
imageUrl: string; | ||
originalImageUrl: string; | ||
} |
export * from './input'; | ||
export * from './dropImage'; |
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput } from './types'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput, DropImage } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
@@ -9,2 +9,3 @@ export declare class DropsClient { | ||
constructor(compassProvider: CompassProvider, dropApiProvider: DropApiProvider); | ||
fetchDropImage(id: number): Promise<DropImage | undefined>; | ||
fetch(input: FetchDropsInput): Promise<PaginatedResult<Drop>>; | ||
@@ -14,4 +15,3 @@ create(input: CreateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
} |
export * from './PaginatedDrop'; | ||
export * from './DropImage'; |
@@ -1,10 +0,3 @@ | ||
import { DropImageGatewayType } from '../types/dropImage'; | ||
import { DropImageGatewaysResponse } from './DropImage'; | ||
export declare const PAGINATED_DROPS_QUERY = "\n query PaginatedDrops(\n $limit: Int!\n $offset: Int!\n $orderBy: [drops_order_by!]\n $where: drops_bool_exp\n ) {\n drops(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {\n id\n fancy_id\n name\n description\n city\n country\n channel\n platform\n location_type\n drop_url\n image_url\n animation_url\n year\n start_date\n timezone\n private\n created_date\n expiry_date\n end_date\n stats_by_chain_aggregate {\n aggregate {\n sum {\n transfer_count\n poap_count\n }\n }\n }\n email_claims_stats {\n total\n }\n drop_image {\n gateways {\n type\n url\n }\n }\n }\n }\n"; | ||
export interface DropImageGatewayResponse { | ||
type: DropImageGatewayType; | ||
url: string; | ||
} | ||
export interface DropImageResponse { | ||
gateways: Array<DropImageGatewayResponse>; | ||
} | ||
export interface DropResponse { | ||
@@ -41,3 +34,3 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image?: DropImageGatewaysResponse; | ||
} | ||
@@ -44,0 +37,0 @@ export interface PaginatedDropsResponse { |
@@ -6,4 +6,4 @@ export declare enum DropImageGatewayType { | ||
export interface DropImage { | ||
original?: string; | ||
crop?: string; | ||
imageUrl: string; | ||
originalImageUrl: string; | ||
} |
export * from './input'; | ||
export * from './dropImage'; |
import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; | ||
import { Drop } from './domain/Drop'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput } from './types'; | ||
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput, DropImage } from './types'; | ||
import { PaginatedResult } from '@poap-xyz/utils'; | ||
@@ -9,2 +9,3 @@ export declare class DropsClient { | ||
constructor(compassProvider: CompassProvider, dropApiProvider: DropApiProvider); | ||
fetchDropImage(id: number): Promise<DropImage | undefined>; | ||
fetch(input: FetchDropsInput): Promise<PaginatedResult<Drop>>; | ||
@@ -14,4 +15,3 @@ create(input: CreateDropsInput): Promise<Drop>; | ||
private formatDrop; | ||
private computeDropImages; | ||
private mapDropImage; | ||
} |
@@ -113,2 +113,29 @@ (function (global, factory) { | ||
const DROP_IMAGE_QUERY = ` | ||
query PaginatedDrops($id: Int!) { | ||
drops(where: { id: { _eq: $id } }) { | ||
image_url | ||
drop_image { | ||
gateways { | ||
type | ||
url | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
exports.DropsSortFields = void 0; | ||
(function (DropsSortFields) { | ||
DropsSortFields["Name"] = "name"; | ||
DropsSortFields["Id"] = "id"; | ||
DropsSortFields["StartDate"] = "start_date"; | ||
})(exports.DropsSortFields || (exports.DropsSortFields = {})); | ||
var DropImageGatewayType; | ||
(function (DropImageGatewayType) { | ||
DropImageGatewayType["CROP"] = "CROP"; | ||
DropImageGatewayType["ORIGINAL"] = "ORIGINAL"; | ||
})(DropImageGatewayType || (DropImageGatewayType = {})); | ||
var MintingStatus; | ||
@@ -175,2 +202,6 @@ (function (MintingStatus) { | ||
} | ||
async fetchDropImage(id) { | ||
const { data } = await this.compassProvider.request(DROP_IMAGE_QUERY, { id }); | ||
return this.mapDropImage(data.drops[0]); | ||
} | ||
async fetch(input) { | ||
@@ -191,3 +222,3 @@ const { limit, offset, name, sortField, sortDir, from, to, ids, isPrivate, } = input; | ||
const drops = data.drops.map((drop) => { | ||
const { imageUrl, originalImageUrl } = this.computeDropImages(drop); | ||
const dropImage = this.mapDropImage(drop); | ||
return new Drop({ | ||
@@ -204,4 +235,2 @@ id: Number(drop.id), | ||
dropUrl: drop.drop_url, | ||
imageUrl, | ||
originalImageUrl, | ||
animationUrl: drop.animation_url, | ||
@@ -224,2 +253,3 @@ year: Number(drop.year), | ||
endDate: new Date(drop.end_date), | ||
...dropImage, | ||
}); | ||
@@ -230,3 +260,3 @@ }); | ||
async create(input) { | ||
const repsonse = await this.dropApiProvider.createDrop({ | ||
const response = await this.dropApiProvider.createDrop({ | ||
name: input.name, | ||
@@ -250,3 +280,3 @@ description: input.description, | ||
}); | ||
return this.formatDrop(repsonse); | ||
return this.formatDrop(response); | ||
} | ||
@@ -297,24 +327,12 @@ async update(input) { | ||
} | ||
computeDropImages(drop) { | ||
const dropImage = this.mapDropImage(drop.drop_image); | ||
mapDropImage(drop) { | ||
var _a, _b; | ||
const images = (_b = (_a = drop.drop_image) === null || _a === void 0 ? void 0 : _a.gateways) === null || _b === void 0 ? void 0 : _b.reduce((acc, gateway) => ({ ...acc, [gateway.type]: gateway.url }), {}); | ||
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, | ||
originalImageUrl: (images === null || images === void 0 ? void 0 : images[DropImageGatewayType.ORIGINAL]) || drop.image_url, | ||
imageUrl: (images === null || images === void 0 ? void 0 : images[DropImageGatewayType.CROP]) || drop.image_url, | ||
}; | ||
} | ||
mapDropImage(response) { | ||
if (!response) | ||
return response; | ||
const images = response.gateways.reduce((acc, gateway) => ({ ...acc, [gateway.type.toLowerCase()]: gateway.url }), {}); | ||
return { ...images }; | ||
} | ||
} | ||
exports.DropsSortFields = void 0; | ||
(function (DropsSortFields) { | ||
DropsSortFields["Name"] = "name"; | ||
DropsSortFields["Id"] = "id"; | ||
DropsSortFields["StartDate"] = "start_date"; | ||
})(exports.DropsSortFields || (exports.DropsSortFields = {})); | ||
exports.Drop = Drop; | ||
@@ -321,0 +339,0 @@ exports.DropsClient = DropsClient; |
export * from './PaginatedDrop'; | ||
export * from './DropImage'; |
@@ -1,10 +0,3 @@ | ||
import { DropImageGatewayType } from '../types/dropImage'; | ||
import { DropImageGatewaysResponse } from './DropImage'; | ||
export declare const PAGINATED_DROPS_QUERY = "\n query PaginatedDrops(\n $limit: Int!\n $offset: Int!\n $orderBy: [drops_order_by!]\n $where: drops_bool_exp\n ) {\n drops(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {\n id\n fancy_id\n name\n description\n city\n country\n channel\n platform\n location_type\n drop_url\n image_url\n animation_url\n year\n start_date\n timezone\n private\n created_date\n expiry_date\n end_date\n stats_by_chain_aggregate {\n aggregate {\n sum {\n transfer_count\n poap_count\n }\n }\n }\n email_claims_stats {\n total\n }\n drop_image {\n gateways {\n type\n url\n }\n }\n }\n }\n"; | ||
export interface DropImageGatewayResponse { | ||
type: DropImageGatewayType; | ||
url: string; | ||
} | ||
export interface DropImageResponse { | ||
gateways: Array<DropImageGatewayResponse>; | ||
} | ||
export interface DropResponse { | ||
@@ -41,3 +34,3 @@ id: number; | ||
}; | ||
drop_image?: DropImageResponse; | ||
drop_image?: DropImageGatewaysResponse; | ||
} | ||
@@ -44,0 +37,0 @@ export interface PaginatedDropsResponse { |
@@ -6,4 +6,4 @@ export declare enum DropImageGatewayType { | ||
export interface DropImage { | ||
original?: string; | ||
crop?: string; | ||
imageUrl: string; | ||
originalImageUrl: string; | ||
} |
export * from './input'; | ||
export * from './dropImage'; |
{ | ||
"name": "@poap-xyz/drops", | ||
"version": "0.1.3", | ||
"version": "0.1.4-beta-v1", | ||
"description": "Drops module for the poap.js library", | ||
@@ -34,3 +34,4 @@ "main": "dist/cjs/index.cjs", | ||
"@poap-xyz/utils": "0.1.0" | ||
} | ||
}, | ||
"stableVersion": "0.1.4" | ||
} |
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
136913
35
1560