From e0ddbf86d9952adb61746467276482e123cf6869 Mon Sep 17 00:00:00 2001 From: Lautaro Petaccio Date: Thu, 31 Mar 2022 09:51:42 -0300 Subject: [PATCH 1/2] feat: Add catalyst content hash --- package-lock.json | 6 ++-- package.json | 2 +- spec/mocks/items.ts | 15 ++++++---- spec/mocks/peer.ts | 41 +++++++++++++++++++------- src/Item/Item.router.spec.ts | 15 ++++------ src/Item/Item.service.ts | 17 ++++++++--- src/Item/Item.types.ts | 21 ++------------ src/Item/hashes.ts | 44 +++++++++++++++------------- src/ethereum/api/Bridge.ts | 21 +++++++++----- src/ethereum/api/peer.ts | 56 ++++++------------------------------ 10 files changed, 114 insertions(+), 124 deletions(-) diff --git a/package-lock.json b/package-lock.json index 63b2df19..c0240e0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -537,9 +537,9 @@ } }, "@dcl/schemas": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/@dcl/schemas/-/schemas-3.10.0.tgz", - "integrity": "sha512-MMlFQ65pfDpcnXztpowieRk/Y7m01nM0WNg1ACSlKdo0GH1JrYikDPq4VuRCP7LWMDpoWVSGRdH0fJ0YvC5TzQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@dcl/schemas/-/schemas-4.1.0.tgz", + "integrity": "sha512-NCKWoK1KtrMlsP0hRM/4Btb4+o48gpi6ZCaEyDnDLYwuCJcApXISB3qaQY/FzdKuyfx6C3MEbjeCGZbhlEIhpQ==", "requires": { "ajv": "^7.1.0" } diff --git a/package.json b/package.json index 5c2ab1f1..e422c7f9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "@apollo/client": "^3.3.9", "@dcl/hashing": "^1.1.0", - "@dcl/schemas": "^3.10.0", + "@dcl/schemas": "^4.1.0", "@ethersproject/solidity": "^5.0.9", "@types/escape-html": "0.0.20", "@types/express": "^4.17.11", diff --git a/spec/mocks/items.ts b/spec/mocks/items.ts index bc949e7c..a17273be 100644 --- a/spec/mocks/items.ts +++ b/spec/mocks/items.ts @@ -1,6 +1,6 @@ import { constants } from 'ethers' +import { ThirdPartyWearable } from '@dcl/schemas' import { v4 as uuidv4 } from 'uuid' -import { Wearable } from '../../src/ethereum/api/peer' import { ItemFragment, ThirdPartyItemFragment, @@ -19,6 +19,7 @@ import { buildTPItemURN } from '../../src/Item/utils' import { CollectionAttributes } from '../../src/Collection' import { WearableBodyShape } from '../../src/Item/wearable/types' import { isTPCollection } from '../../src/utils/urn' +import { CatalystItem } from '../../src/ethereum/api/peer' import { dbCollectionMock, dbTPCollectionMock } from './collections' export type ResultItem = Omit & { @@ -29,7 +30,7 @@ export type ResultItem = Omit & { export function toResultItem( itemAttributes: ItemAttributes, itemFragment?: ItemFragment, - catalystItem?: Wearable, + catalystItem?: CatalystItem, dbCollection?: CollectionAttributes ): ResultItem { const hasURN = @@ -55,6 +56,7 @@ export function toResultItem( ? Number(itemFragment?.totalSupply) : 0, content_hash: itemFragment?.contentHash || null, + catalyst_content_hash: null, } delete (resultItem as Omit & { urn_suffix: unknown @@ -73,7 +75,8 @@ export function asResultItem(item: ItemAttributes): ResultItem { export function toResultTPItem( itemAttributes: ItemAttributes, - dbCollection?: CollectionAttributes + dbCollection?: CollectionAttributes, + catalystItem?: ThirdPartyWearable ): ResultItem { const hasURN = itemAttributes.urn_suffix && dbCollection && isTPCollection(dbCollection) @@ -96,7 +99,10 @@ export function toResultTPItem( total_supply: 0, price: '0', beneficiary: constants.AddressZero, - content_hash: '', + content_hash: null, + catalyst_content_hash: catalystItem + ? catalystItem?.merkleProof.entityHash + : null, } delete (resultItem as Omit & { urn_suffix: unknown @@ -115,7 +121,6 @@ export const dbItemMock: ItemAttributes = { collection_id: dbCollectionMock.id, blockchain_item_id: '0', price: '', - content_hash: '', beneficiary: '', rarity: ItemRarity.COMMON, type: ItemType.WEARABLE, diff --git a/spec/mocks/peer.ts b/spec/mocks/peer.ts index b58f127b..58a15770 100644 --- a/spec/mocks/peer.ts +++ b/spec/mocks/peer.ts @@ -1,3 +1,11 @@ +import { + Rarity, + ThirdPartyWearable, + StandardWearable, + WearableCategory, + WearableRepresentation, + I18N, +} from '@dcl/schemas' import { ItemRarity } from '../../src/Item' import { dbCollectionMock } from './collections' import { @@ -6,28 +14,41 @@ import { thirdPartyItemFragmentMock, } from './items' -export const wearableMock = { +export const wearableMock: StandardWearable = { id: itemFragmentMock.urn, name: dbItemMock.name, description: dbItemMock.description, collectionAddress: dbCollectionMock.contract_address!, - rarity: ItemRarity.COMMON, + rarity: (ItemRarity.COMMON as unknown) as Rarity, + i18n: [{ code: 'en', text: dbItemMock.name }] as I18N[], image: '', thumbnail: '', metrics: dbItemMock.metrics, - contents: {}, data: { - representations: [], - replaces: [], - hides: [], + category: WearableCategory.HAT, + representations: [] as WearableRepresentation[], + replaces: [] as WearableCategory[], + hides: [] as WearableCategory[], tags: [], }, - createdAt: dbItemMock.created_at.getTime(), - updatedAt: dbItemMock.updated_at.getTime(), } -export const tpWearableMock = { +export const tpWearableMock: ThirdPartyWearable = { ...wearableMock, id: thirdPartyItemFragmentMock.urn, - collectionAddress: '', + merkleProof: { + proof: [], + index: 0, + hashingKeys: [ + 'id', + 'name', + 'description', + 'data', + 'image', + 'thumbnail', + 'metrics', + 'contents', + ], + entityHash: 'someHash', + }, } diff --git a/src/Item/Item.router.spec.ts b/src/Item/Item.router.spec.ts index c22a0691..e9dddc40 100644 --- a/src/Item/Item.router.spec.ts +++ b/src/Item/Item.router.spec.ts @@ -1,3 +1,4 @@ +import { StandardWearable, ThirdPartyWearable } from '@dcl/schemas' import supertest from 'supertest' import { v4 as uuidv4 } from 'uuid' import { Wallet } from 'ethers' @@ -38,7 +39,7 @@ import { ItemCuration, ItemCurationAttributes } from '../Curation/ItemCuration' import { CurationStatus } from '../Curation' import { Collection } from '../Collection/Collection.model' import { collectionAPI } from '../ethereum/api/collection' -import { peerAPI, Wearable } from '../ethereum/api/peer' +import { CatalystItem, peerAPI } from '../ethereum/api/peer' import { ItemFragment } from '../ethereum/api/fragments' import { STATUS_CODES } from '../common/HTTPError' import { Bridge } from '../ethereum/api/Bridge' @@ -69,7 +70,7 @@ jest.mock('./Item.model') function mockItemConsolidation( itemsAttributes: ItemAttributes[], - wearables: Wearable[] + wearables: CatalystItem[] ) { ;(Item.findByBlockchainIdsAndContractAddresses as jest.Mock).mockResolvedValueOnce( itemsAttributes @@ -95,8 +96,8 @@ describe('Item router', () => { let resultItemNotPublished: ResultItem let resultTPItemNotPublished: ResultItem let resultTPItemPublished: ResultItem - let wearable: Wearable - let tpWearable: Wearable + let wearable: StandardWearable + let tpWearable: ThirdPartyWearable let itemFragment: ItemFragment let url: string @@ -110,7 +111,6 @@ describe('Item router', () => { tpWearable = { ...tpWearableMock, id: thirdPartyItemFragmentMock.urn, - collectionAddress: '', } dbItemNotPublished = { ...dbItem, @@ -130,7 +130,7 @@ describe('Item router', () => { } dbItemCuration = { ...itemCurationMock, item_id: dbTPItemPublished.id } resultingItem = toResultItem(dbItem, itemFragment, wearable) - resultingTPItem = toResultTPItem(dbTPItem, dbTPCollectionMock) + resultingTPItem = toResultTPItem(dbTPItem, dbTPCollectionMock, tpWearable) resultItemNotPublished = asResultItem(dbItemNotPublished) resultTPItemNotPublished = asResultItem(dbTPItemNotPublished) // no itemCuration & no catalyst, should be regular Item resultTPItemPublished = { @@ -255,9 +255,6 @@ describe('Item router', () => { ;(collectionAPI.fetchItems as jest.Mock).mockResolvedValueOnce([ itemFragment, ]) - ;(thirdPartyAPI.fetchItems as jest.Mock).mockResolvedValueOnce([ - thirdPartyItemFragmentMock, - ]) ;(Collection.findByIds as jest.Mock).mockResolvedValueOnce([ dbTPCollectionMock, ]) // for third parties diff --git a/src/Item/Item.service.ts b/src/Item/Item.service.ts index 7cb710c1..fa676cd6 100644 --- a/src/Item/Item.service.ts +++ b/src/Item/Item.service.ts @@ -1,3 +1,4 @@ +import { StandardWearable, ThirdPartyWearable } from '@dcl/schemas' import { Collection, CollectionAttributes, @@ -221,7 +222,9 @@ export class ItemService { ? Bridge.mergeTPCollection(collection, lastItemCuration) : collection - const catalystItems = await peerAPI.fetchWearables([urn]) + const catalystItems = await peerAPI.fetchWearables([ + urn, + ]) if (catalystItems.length > 0) { item = Bridge.mergeTPItem(dbItem, collection, catalystItems[0]) } @@ -260,7 +263,9 @@ export class ItemService { collection = Bridge.mergeCollection(dbCollection, remoteCollection) if (remoteItem) { - const [catalystItem] = await peerAPI.fetchWearables([remoteItem.urn]) + const [catalystItem] = await peerAPI.fetchWearables( + [remoteItem.urn] + ) item = Bridge.mergeItem( dbItem, remoteItem, @@ -548,7 +553,9 @@ export class ItemService { ) // Check if the new URN is not already in use - const [wearable] = await peerAPI.fetchWearables([itemURN]) + const [wearable] = await peerAPI.fetchWearables([ + itemURN, + ]) if (wearable) { throw new ThirdPartyItemAlreadyPublishedError( item.id, @@ -573,7 +580,9 @@ export class ItemService { ) // Check if the chosen URN is already in use - const [wearable] = await peerAPI.fetchWearables([itemURN]) + const [wearable] = await peerAPI.fetchWearables([ + itemURN, + ]) if (wearable) { throw new ThirdPartyItemAlreadyPublishedError( item.id, diff --git a/src/Item/Item.types.ts b/src/Item/Item.types.ts index 5c55444b..ed55c3f5 100644 --- a/src/Item/Item.types.ts +++ b/src/Item/Item.types.ts @@ -1,4 +1,3 @@ -import { Wearable } from '../ethereum/api/peer' import { ItemCurationAttributes } from '../Curation/ItemCuration' import { MetricsAttributes } from '../Metrics' import { Cheque } from '../SlotUsageCheque' @@ -35,7 +34,6 @@ export type ItemAttributes = { eth_address: string collection_id: string | null blockchain_item_id: string | null - content_hash: string | null local_content_hash: string | null price: string | null beneficiary?: string | null @@ -64,9 +62,11 @@ export type FullItem = Omit & { in_catalyst: boolean total_supply: number content_hash: string | null + catalyst_content_hash: string | null } -export type DBItemApprovalData = Pick +export type DBItemApprovalData = Pick & + Pick export type ItemApprovalData = { cheque: Cheque @@ -76,18 +76,3 @@ export type ItemApprovalData = { > chequeWasConsumed: boolean } - -type BaseWearableEntityMetadata = Omit< - Wearable, - 'createdAt' | 'updatedAt' | 'collectionAddress' | 'rarity' -> & { - i18n: { code: string; text: string }[] - emoteDataV0?: { loop: boolean } -} - -export type TPWearableEntityMetadata = BaseWearableEntityMetadata & { - content: ItemContents -} - -export type StandardWearableEntityMetadata = BaseWearableEntityMetadata & - Pick diff --git a/src/Item/hashes.ts b/src/Item/hashes.ts index a672a031..bbfad3e3 100644 --- a/src/Item/hashes.ts +++ b/src/Item/hashes.ts @@ -2,16 +2,20 @@ import { calculateMultipleHashesADR32LegacyQmHash, keccak256Hash, } from '@dcl/hashing' +import { + Locale, + WearableCategory, + WearableRepresentation, + ThirdPartyWearable, + StandardWearable, + Rarity, + I18N, +} from '@dcl/schemas' import { CollectionAttributes } from '../Collection' import { isStandardItemPublished } from '../ItemAndCollection/utils' import { getDecentralandItemURN, isTPCollection } from '../utils/urn' import { EmoteCategory, EmoteData } from './emote/types' -import { - StandardWearableEntityMetadata, - ItemAttributes, - TPWearableEntityMetadata, - ItemType, -} from './Item.types' +import { ItemAttributes, ItemType } from './Item.types' import { buildTPItemURN, isTPItem } from './utils' const THUMBNAIL_PATH = 'thumbnail.png' @@ -20,26 +24,26 @@ const IMAGE_PATH = 'image.png' function buildStandardWearableEntityMetadata( item: ItemAttributes, collection: CollectionAttributes -): StandardWearableEntityMetadata { +): StandardWearable & { emoteDataV0?: { loop: boolean } } { if (!isStandardItemPublished(item, collection)) { throw new Error( "The item's collection must be published to build its metadata" ) } - const entity: StandardWearableEntityMetadata = { + const entity: StandardWearable & { emoteDataV0?: { loop: boolean } } = { id: getDecentralandItemURN(item, collection.contract_address!), name: item.name, description: item.description, collectionAddress: collection.contract_address!, - rarity: item.rarity!, - i18n: [{ code: 'en', text: item.name }], + rarity: (item.rarity! as unknown) as Rarity, + i18n: [{ code: 'en', text: item.name }] as I18N[], data: { - replaces: item.data.replaces, - hides: item.data.hides, + replaces: item.data.replaces as WearableCategory[], + hides: item.data.hides as WearableCategory[], tags: item.data.tags, - category: item.data.category, - representations: item.data.representations, + category: item.data.category as WearableCategory, + representations: item.data.representations as WearableRepresentation[], }, image: IMAGE_PATH, thumbnail: THUMBNAIL_PATH, @@ -58,7 +62,7 @@ function buildStandardWearableEntityMetadata( function buildTPWearableEntityMetadata( item: ItemAttributes, collection: CollectionAttributes -): TPWearableEntityMetadata { +): Omit { return { id: buildTPItemURN( collection.third_party_id!, @@ -67,13 +71,13 @@ function buildTPWearableEntityMetadata( ), name: item.name, description: item.description, - i18n: [{ code: 'en', text: item.name }], + i18n: [{ code: Locale.EN, text: item.name }], data: { - replaces: item.data.replaces, - hides: item.data.hides, + replaces: item.data.replaces as WearableCategory[], + hides: item.data.hides as WearableCategory[], tags: item.data.tags, - category: item.data.category, - representations: item.data.representations, + category: item.data.category as WearableCategory, + representations: item.data.representations as WearableRepresentation[], }, image: IMAGE_PATH, thumbnail: THUMBNAIL_PATH, diff --git a/src/ethereum/api/Bridge.ts b/src/ethereum/api/Bridge.ts index a3c1e337..cb507dde 100644 --- a/src/ethereum/api/Bridge.ts +++ b/src/ethereum/api/Bridge.ts @@ -1,3 +1,4 @@ +import { StandardWearable, ThirdPartyWearable } from '@dcl/schemas' import { constants } from 'ethers' import { utils } from 'decentraland-commons' import { @@ -15,7 +16,7 @@ import { } from '../../Curation/ItemCuration' import { ItemFragment, CollectionFragment } from './fragments' import { collectionAPI } from './collection' -import { peerAPI, Wearable } from './peer' +import { CatalystItem, peerAPI } from './peer' export class Bridge { /** @@ -85,7 +86,7 @@ export class Bridge { itemsByURN[urn] = item } - const tpCatalystItems = await peerAPI.fetchWearables( + const tpCatalystItems = await peerAPI.fetchWearables( Object.keys(itemsByURN) ) @@ -127,7 +128,7 @@ export class Bridge { static mergeTPItem( dbItem: ItemAttributes, dbCollection: ThirdPartyCollectionAttributes, - catalystItem?: Wearable + catalystItem?: ThirdPartyWearable ): FullItem { const data = dbItem.data const category = data.category @@ -154,8 +155,10 @@ export class Bridge { is_published: true, // For now, items are always approved. Rejecting (or disabling) items will be done at the record level, for all collections that apply. is_approved: !!catalystItem, - // TODO: This will be resolved when we tackle #394 - content_hash: '', + content_hash: null, + catalyst_content_hash: catalystItem + ? catalystItem.merkleProof.entityHash + : null, data: { ...data, category, @@ -246,7 +249,9 @@ export class Bridge { const [dbResults, catalystItems] = await Promise.all([ Collection.findByIds(collectionIds), - peerAPI.fetchWearables(remoteItems.map((item) => item.urn)), + peerAPI.fetchWearables( + remoteItems.map((item) => item.urn) + ), ]) // Reduce it to a map for fast lookup @@ -342,7 +347,7 @@ export class Bridge { dbItem: ItemAttributes, remoteItem: ItemFragment, remoteCollection: CollectionFragment, - catalystItem?: Wearable + catalystItem?: CatalystItem ): FullItem { const { wearable } = remoteItem.metadata @@ -373,6 +378,7 @@ export class Bridge { blockchain_item_id: remoteItem.blockchainId, total_supply: Number(remoteItem.totalSupply), content_hash: remoteItem.contentHash || null, + catalyst_content_hash: null, data: { ...data, category, @@ -401,6 +407,7 @@ export class Bridge { is_approved: false, is_published: false, content_hash: null, + catalyst_content_hash: null, total_supply: 0, }, ['urn_suffix'] diff --git a/src/ethereum/api/peer.ts b/src/ethereum/api/peer.ts index bd30238c..1b0cd03a 100644 --- a/src/ethereum/api/peer.ts +++ b/src/ethereum/api/peer.ts @@ -1,51 +1,27 @@ import fetch from 'isomorphic-fetch' +import { StandardWearable, ThirdPartyWearable } from '@dcl/schemas' import { ILoggerComponent } from '@well-known-components/interfaces' import { createConsoleLogComponent } from '@well-known-components/logger' import { env } from 'decentraland-commons' import { LambdasClient } from 'dcl-catalyst-client' import { AuthLink } from 'dcl-crypto' -import { WearableData, WearableRepresentation } from '../../Item/wearable/types' -import { ItemRarity } from '../../Item' -import { MetricsAttributes } from '../../Metrics' import { logExecutionTime } from '../../utils/logging' export const THUMBNAIL_PATH = 'thumbnail.png' -export type Wearable = { - id: string - name: string - description: string - collectionAddress: string - rarity: ItemRarity - image: string - thumbnail: string - metrics: MetricsAttributes - data: WearableData - createdAt: number - updatedAt: number -} - -export type PeerRepresentation = Omit & { - contents: { key: string; url: string }[] -} -export type PeerData = Omit & { - representations: PeerRepresentation[] -} - -export type PeerWearable = Omit & { - data: PeerData -} - export type ValidateSignatureResponse = { valid: boolean ownerAddress: string error?: string } + export type SignatureBody = { authChain: AuthLink[] timestamp: string } +export type CatalystItem = StandardWearable | ThirdPartyWearable + export const PEER_URL = env.get('PEER_URL', '') export class PeerAPI { @@ -80,31 +56,17 @@ export class PeerAPI { return result } - async fetchWearables(urns: string[]): Promise { - const wearables: PeerWearable[] = await logExecutionTime( + async fetchWearables(urns: string[]): Promise { + return logExecutionTime( () => urns.length > 0 - ? this.lambdasClient.fetchWearables({ wearableIds: urns }) + ? (this.lambdasClient.fetchWearables({ + wearableIds: urns, + }) as Promise) : [], this.logger, 'Wearables Fetch' ) - return wearables.map((wearable) => this.toWearable(wearable)) - } - - private toWearable(peerWearable: PeerWearable): Wearable { - return { - ...peerWearable, - data: { - ...peerWearable.data, - representations: [ - ...peerWearable.data.representations.map((representation) => ({ - ...representation, - contents: representation.contents.map((content) => content.key), - })), - ], - }, - } } } From cf3ac66067f5aab4777531fdffa4b6436e7dc0d7 Mon Sep 17 00:00:00 2001 From: Lautaro Petaccio Date: Thu, 31 Mar 2022 12:29:25 -0300 Subject: [PATCH 2/2] fix: Remove old third party item fetches --- spec/mocks/items.ts | 32 +----------- spec/mocks/peer.ts | 8 +-- src/Curation/Curation.router.spec.ts | 2 +- src/Item/Item.router.spec.ts | 5 -- src/ethereum/api/fragments.ts | 54 ------------------- src/ethereum/api/thirdParty.ts | 78 ---------------------------- 6 files changed, 4 insertions(+), 175 deletions(-) diff --git a/spec/mocks/items.ts b/spec/mocks/items.ts index a17273be..242fc520 100644 --- a/spec/mocks/items.ts +++ b/spec/mocks/items.ts @@ -1,11 +1,7 @@ import { constants } from 'ethers' import { ThirdPartyWearable } from '@dcl/schemas' import { v4 as uuidv4 } from 'uuid' -import { - ItemFragment, - ThirdPartyItemFragment, - ThirdPartyItemMetadataType, -} from '../../src/ethereum/api/fragments' +import { ItemFragment } from '../../src/ethereum/api/fragments' import { Bridge } from '../../src/ethereum/api/Bridge' import { FullItem, @@ -189,32 +185,6 @@ export const itemFragmentMock = { contentHash: '', } -export const thirdPartyItemFragmentMock: ThirdPartyItemFragment = { - urn: buildTPItemURN( - dbTPCollectionMock.third_party_id, - dbTPCollectionMock.urn_suffix, - dbTPItemMock.urn_suffix - ), - blockchainItemId: '1', - contentHash: '', - isApproved: true, - metadata: { - type: ThirdPartyItemMetadataType.third_party_v1, - itemWearable: { - name: 'Fragment Name', - description: null, - category: null, - bodyShapes: null, - }, - }, - thirdParty: { - id: dbTPCollectionMock.third_party_id, - }, - reviewedAt: toUnixTimestamp(dbTPCollectionMock.reviewed_at!), - updatedAt: toUnixTimestamp(dbTPCollectionMock.updated_at), - createdAt: toUnixTimestamp(dbTPCollectionMock.created_at), -} - export function convertItemDatesToISO( item: T ): Omit & { diff --git a/spec/mocks/peer.ts b/spec/mocks/peer.ts index 58a15770..06c9b113 100644 --- a/spec/mocks/peer.ts +++ b/spec/mocks/peer.ts @@ -8,11 +8,7 @@ import { } from '@dcl/schemas' import { ItemRarity } from '../../src/Item' import { dbCollectionMock } from './collections' -import { - dbItemMock, - itemFragmentMock, - thirdPartyItemFragmentMock, -} from './items' +import { dbItemMock, itemFragmentMock } from './items' export const wearableMock: StandardWearable = { id: itemFragmentMock.urn, @@ -35,7 +31,7 @@ export const wearableMock: StandardWearable = { export const tpWearableMock: ThirdPartyWearable = { ...wearableMock, - id: thirdPartyItemFragmentMock.urn, + id: dbCollectionMock.contract_address + '-' + dbItemMock.blockchain_item_id, merkleProof: { proof: [], index: 0, diff --git a/src/Curation/Curation.router.spec.ts b/src/Curation/Curation.router.spec.ts index 15314e13..64d3b2e8 100644 --- a/src/Curation/Curation.router.spec.ts +++ b/src/Curation/Curation.router.spec.ts @@ -4,7 +4,7 @@ import { dbCollectionMock, dbTPCollectionMock, } from '../../spec/mocks/collections' -import { dbItemMock, thirdPartyItemFragmentMock } from '../../spec/mocks/items' +import { dbItemMock } from '../../spec/mocks/items' import { thirdPartyAPI } from '../ethereum/api/thirdParty' import { collectionAPI } from '../ethereum/api/collection' import { toUnixTimestamp } from '../utils/parse' diff --git a/src/Item/Item.router.spec.ts b/src/Item/Item.router.spec.ts index e9dddc40..1a9ae6a6 100644 --- a/src/Item/Item.router.spec.ts +++ b/src/Item/Item.router.spec.ts @@ -24,7 +24,6 @@ import { dbItemMock, dbTPItemMock, itemFragmentMock, - thirdPartyItemFragmentMock, ResultItem, toResultItem, toResultTPItem, @@ -110,7 +109,6 @@ describe('Item router', () => { } tpWearable = { ...tpWearableMock, - id: thirdPartyItemFragmentMock.urn, } dbItemNotPublished = { ...dbItem, @@ -304,9 +302,6 @@ describe('Item router', () => { ;(thirdPartyAPI.fetchThirdPartiesByManager as jest.Mock).mockResolvedValueOnce( [thirdPartyFragmentMock] ) - ;(thirdPartyAPI.fetchItemsByThirdParties as jest.Mock).mockResolvedValueOnce( - [thirdPartyItemFragmentMock] - ) ;(collectionAPI.fetchItemsByAuthorizedUser as jest.Mock).mockResolvedValueOnce( [itemFragment] ) diff --git a/src/ethereum/api/fragments.ts b/src/ethereum/api/fragments.ts index b4d591db..280f8150 100644 --- a/src/ethereum/api/fragments.ts +++ b/src/ethereum/api/fragments.ts @@ -65,29 +65,6 @@ export const thirdPartyFragment = () => gql` } ` -export const thirdPartyItemFragment = () => gql` - fragment thirdPartyItemFragment on Item { - urn - blockchainItemId - contentHash - isApproved - reviewedAt - updatedAt - createdAt - metadata { - itemWearable { - name - description - category - bodyShapes - } - } - thirdParty { - id - } - } -` - export const accountFragment = () => gql` fragment accountFragment on Account { id @@ -169,37 +146,11 @@ export type ThirdPartyFragment = { metadata: ThirdPartyMetadata } -type ThirdPartyItemWearableMetadata = { - name: string | null - description: string | null - category: WearableCategory | null - bodyShapes: BodyShape[] | null -} - -export type ThirdPartyItemFragment = { - urn: string - blockchainItemId: string - contentHash: string - isApproved: boolean - reviewedAt: string - updatedAt: string - createdAt: string - metadata: ThirdPartyItemMetadata - thirdParty: { - id: string - } -} - export type ThirdPartyMetadata = { type: ThirdPartyMetadataType thirdParty: { name: string; description: string } | null } -type ThirdPartyItemMetadata = { - type: ThirdPartyItemMetadataType | undefined - itemWearable: ThirdPartyItemWearableMetadata -} - export enum ThirdPartyMetadataType { THIRD_PARTY_V1 = 'third_party_v1', } @@ -209,11 +160,6 @@ export enum ThirdPartyItemMetadataType { item_wearable_v1 = 'item_wearable_v1', } -enum BodyShape { - BaseMale, - BaseFemale, -} - export type AccountFragment = { id: string address: string diff --git a/src/ethereum/api/thirdParty.ts b/src/ethereum/api/thirdParty.ts index a98a9af9..a337a00f 100644 --- a/src/ethereum/api/thirdParty.ts +++ b/src/ethereum/api/thirdParty.ts @@ -3,8 +3,6 @@ import { env } from 'decentraland-commons' import { thirdPartyFragment, ThirdPartyFragment, - ThirdPartyItemFragment, - thirdPartyItemFragment, tiersFragment, TierFragment, ReceiptFragment, @@ -36,24 +34,6 @@ const getThirdPartiesByManagerQuery = () => gql` ${thirdPartyFragment()} ` -const getItemsQuery = () => gql` - query getItems { - items { - ...thirdPartyItemFragment - } - } - ${thirdPartyItemFragment()} -` - -const getItemsByThirdPartyIdsQuery = () => gql` - query getItemsByThirdPartyIds(${PAGINATION_VARIABLES}, $thirdPartiesIds: [String!]) { - items(${PAGINATION_ARGUMENTS}, where: { thirdParty_in: $thirdPartiesIds }) { - ...thirdPartyItemFragment - } - } - ${thirdPartyItemFragment()} -` - const getThirdPartyMaxItems = () => gql` query getThirdPartyAvailableSlots($thirdPartyId: String!) { thirdParties(where: { id: $thirdPartyId }) { @@ -62,23 +42,6 @@ const getThirdPartyMaxItems = () => gql` } ` -const getItemsByCollectionQuery = () => gql` - query getItemsByCollection(${PAGINATION_VARIABLES}, $thirdPartiesId: String!, $collectionId: String!) { - items(${PAGINATION_ARGUMENTS}, where: { thirdParty: $thirdPartiesId, searchCollectionId: $collectionId }) { - ...thirdPartyItemFragment - } - } - ${thirdPartyFragment()} -` - -const getItemQuery = () => gql` - query getThirdPartyItem($urn: String) { - items(first: 1, where: { urn: $urn }) { - ...thirdPartyItemFragment - } - } -` - const isManagerQuery = () => gql` query isManager($thirdPartyId: String!, $managers: [String!]) { thirdParties( @@ -88,7 +51,6 @@ const isManagerQuery = () => gql` id } } - ${thirdPartyItemFragment()} ` const getTiersQuery = () => gql` @@ -132,25 +94,6 @@ export class ThirdPartyAPI extends BaseGraphAPI { }) } - fetchItemsByThirdParties = async ( - thirdPartyIds: string[] - ): Promise => { - return this.paginate(['items'], { - query: getItemsByThirdPartyIdsQuery(), - variables: { thirdPartyIds }, - }) - } - - fetchItemsByCollection = async ( - thirdPartyId: string, - collectionId: string - ): Promise => { - return this.paginate(['items'], { - query: getItemsByCollectionQuery(), - variables: { thirdPartyId, collectionId }, - }) - } - fetchReceiptById = async ( hash: string ): Promise => { @@ -176,27 +119,6 @@ export class ThirdPartyAPI extends BaseGraphAPI { return Number(thirdParties[0].maxItems) } - fetchItems = async (): Promise => { - return this.paginate(['items'], { - query: getItemsQuery(), - }) - } - - fetchItem = async ( - urn: string - ): Promise => { - const { - data: { items = [] }, - } = await this.query<{ - items: ThirdPartyItemFragment[] - }>({ - query: getItemQuery(), - variables: { urn }, - }) - - return items[0] - } - isManager = async ( thirdPartyId: string, manager: string