From 68a1aa53c4ac893622badbfb4a9fd499a593c5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Nicol=C3=A1s=20Negro=20Caino?= Date: Wed, 17 Jul 2024 10:41:27 -0300 Subject: [PATCH] Do not remove special characters in Drop search query and drop_image possibly null (#133) * testing do not remove special chars * Remove removeSepecialCharacters * Bump version * handle drop_image null --- packages/drops/package.json | 6 ++-- packages/drops/src/DropsClient.ts | 15 ++++----- packages/drops/src/domain/Drop.ts | 32 ++++++++++++------- packages/drops/src/types/DropResponse.ts | 2 +- packages/moments/package.json | 6 ++-- packages/poaps/package.json | 6 ++-- packages/providers/package.json | 4 +-- packages/utils/package.json | 2 +- packages/utils/src/format/index.ts | 1 - .../src/format/removeSpecialCharacters.ts | 10 ------ yarn.lock | 18 +++++------ 11 files changed, 50 insertions(+), 52 deletions(-) delete mode 100644 packages/utils/src/format/removeSpecialCharacters.ts diff --git a/packages/drops/package.json b/packages/drops/package.json index 61a6533b..dbf33f4b 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/drops", - "version": "0.5.4", + "version": "0.5.5", "description": "Drops module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -29,7 +29,7 @@ "node": ">=18" }, "dependencies": { - "@poap-xyz/providers": "0.5.4", - "@poap-xyz/utils": "0.5.4" + "@poap-xyz/providers": "0.5.5", + "@poap-xyz/utils": "0.5.5" } } diff --git a/packages/drops/src/DropsClient.ts b/packages/drops/src/DropsClient.ts index a2c102a8..88ae0448 100644 --- a/packages/drops/src/DropsClient.ts +++ b/packages/drops/src/DropsClient.ts @@ -1,15 +1,14 @@ import { CompassProvider, DropApiProvider } from '@poap-xyz/providers'; import { - PaginatedResult, - nextCursor, createBetweenFilter, - createInFilter, - Order, - isNumeric, - removeSpecialCharacters, - createOrderBy, createBoolFilter, + createInFilter, createLikeFilter, + createOrderBy, + isNumeric, + nextCursor, + Order, + PaginatedResult, toPOAPDate, } from '@poap-xyz/utils'; import { Drop } from './domain/Drop'; @@ -116,7 +115,7 @@ export class DropsClient { offset, ...(isNumeric(search) && { orderBy: { id: Order.ASC } }), args: { - search: removeSpecialCharacters(search), + search, }, }; diff --git a/packages/drops/src/domain/Drop.ts b/packages/drops/src/domain/Drop.ts index d5aaec77..d2572efe 100644 --- a/packages/drops/src/domain/Drop.ts +++ b/packages/drops/src/domain/Drop.ts @@ -27,17 +27,7 @@ export class Drop { emailReservationCount: number; public static fromCompass(response: DropResponse): Drop { - const images: { crop: string; original: string } = - response.drop_image.gateways.reduce( - (images, gateway) => ({ - ...images, - [gateway.type.toLowerCase()]: gateway.url, - }), - { - crop: response.image_url, - original: response.image_url, - }, - ); + const images = Drop.getDropImageFromCompass(response); return new Drop({ id: Number(response.id), @@ -70,6 +60,26 @@ export class Drop { }); } + private static getDropImageFromCompass(response: DropResponse): { + crop: string; + original: string; + } { + const defaultImage = { + crop: response.image_url, + original: response.image_url, + }; + + return ( + response.drop_image?.gateways.reduce( + (images, gateway) => ({ + ...images, + [gateway.type.toLowerCase()]: gateway.url, + }), + defaultImage, + ) || defaultImage + ); + } + public static fromProvider(response: ProviderDropResponse): Drop { return new Drop({ id: response.id, diff --git a/packages/drops/src/types/DropResponse.ts b/packages/drops/src/types/DropResponse.ts index f34e492a..0c336937 100644 --- a/packages/drops/src/types/DropResponse.ts +++ b/packages/drops/src/types/DropResponse.ts @@ -34,5 +34,5 @@ export interface DropResponse { type: 'CROP' | 'ORIGINAL'; url: string; }>; - }; + } | null; } diff --git a/packages/moments/package.json b/packages/moments/package.json index 2a23b380..ca3b6282 100644 --- a/packages/moments/package.json +++ b/packages/moments/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/moments", - "version": "0.5.4", + "version": "0.5.5", "description": "Moments module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.5.4", - "@poap-xyz/utils": "0.5.4", + "@poap-xyz/providers": "0.5.5", + "@poap-xyz/utils": "0.5.5", "uuid": "^9.0.0" }, "engines": { diff --git a/packages/poaps/package.json b/packages/poaps/package.json index 39249e40..c4d74e0a 100644 --- a/packages/poaps/package.json +++ b/packages/poaps/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poaps", - "version": "0.5.4", + "version": "0.5.5", "description": "Poaps module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,8 +26,8 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/providers": "0.5.4", - "@poap-xyz/utils": "0.5.4" + "@poap-xyz/providers": "0.5.5", + "@poap-xyz/utils": "0.5.5" }, "engines": { "node": ">=18" diff --git a/packages/providers/package.json b/packages/providers/package.json index da1aff44..2a1af24c 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.5.4", + "version": "0.5.5", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", @@ -26,7 +26,7 @@ "build": "rollup -c --bundleConfigAsCjs" }, "dependencies": { - "@poap-xyz/utils": "0.5.4", + "@poap-xyz/utils": "0.5.5", "axios": "^1.6.8", "lodash.chunk": "^4.2.0" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 4f057347..a86f9628 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/utils", - "version": "0.5.4", + "version": "0.5.5", "description": "Utils module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", diff --git a/packages/utils/src/format/index.ts b/packages/utils/src/format/index.ts index dbf78c49..34c8b7a3 100644 --- a/packages/utils/src/format/index.ts +++ b/packages/utils/src/format/index.ts @@ -1,2 +1 @@ -export * from './removeSpecialCharacters'; export * from './toPOAPDate'; diff --git a/packages/utils/src/format/removeSpecialCharacters.ts b/packages/utils/src/format/removeSpecialCharacters.ts deleted file mode 100644 index 74d07a0e..00000000 --- a/packages/utils/src/format/removeSpecialCharacters.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Removes all special characters from a given string, leaving only alphanumeric - * characters and spaces. - * - * @param {string} str - The string from which to remove special characters. - * @returns {string} The cleaned string with only alphanumeric characters and spaces. - */ -export function removeSpecialCharacters(str: string): string { - return str.replace(/[^a-zA-Z0-9 ]/g, ''); -} diff --git a/yarn.lock b/yarn.lock index 0b3111b0..262a1e80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -884,8 +884,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/drops@workspace:packages/drops" dependencies: - "@poap-xyz/providers": 0.5.4 - "@poap-xyz/utils": 0.5.4 + "@poap-xyz/providers": 0.5.5 + "@poap-xyz/utils": 0.5.5 languageName: unknown linkType: soft @@ -901,8 +901,8 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/moments@workspace:packages/moments" dependencies: - "@poap-xyz/providers": 0.5.4 - "@poap-xyz/utils": 0.5.4 + "@poap-xyz/providers": 0.5.5 + "@poap-xyz/utils": 0.5.5 "@types/uuid": ^9.0.2 uuid: ^9.0.0 languageName: unknown @@ -912,16 +912,16 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/poaps@workspace:packages/poaps" dependencies: - "@poap-xyz/providers": 0.5.4 - "@poap-xyz/utils": 0.5.4 + "@poap-xyz/providers": 0.5.5 + "@poap-xyz/utils": 0.5.5 languageName: unknown linkType: soft -"@poap-xyz/providers@0.5.4, @poap-xyz/providers@workspace:packages/providers": +"@poap-xyz/providers@0.5.5, @poap-xyz/providers@workspace:packages/providers": version: 0.0.0-use.local resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: - "@poap-xyz/utils": 0.5.4 + "@poap-xyz/utils": 0.5.5 axios: ^1.6.8 axios-mock-adapter: ^1.21.4 jest-fetch-mock: ^3.0.3 @@ -929,7 +929,7 @@ __metadata: languageName: unknown linkType: soft -"@poap-xyz/utils@0.5.4, @poap-xyz/utils@workspace:packages/utils": +"@poap-xyz/utils@0.5.5, @poap-xyz/utils@workspace:packages/utils": version: 0.0.0-use.local resolution: "@poap-xyz/utils@workspace:packages/utils" languageName: unknown