From b7864a2c743402427026615016b76d9ddfa306f4 Mon Sep 17 00:00:00 2001 From: Robin Gagnon Date: Mon, 21 Oct 2024 08:43:54 -0500 Subject: [PATCH] refactor: Adapt Moments package to POAP Moments API v2 (#139) --- docs/pages/changelog.mdx | 9 +++ docs/pages/packages/moments.mdx | 1 - docs/pages/packages/moments/FetchMoments.mdx | 2 +- docs/pages/packages/moments/UpdateMoment.mdx | 12 ---- docs/pages/packages/moments/UploadMoments.mdx | 9 +-- docs/pages/packages/moments/_meta.json | 3 +- packages/drops/package.json | 4 +- packages/moments/README.md | 3 +- packages/moments/package.json | 4 +- .../moments/src/client/MomentsClient.spec.ts | 56 ++++--------------- packages/moments/src/client/MomentsClient.ts | 20 +------ .../dtos/create/CreateAndUploadInput.ts | 23 +++----- .../src/client/dtos/create/CreateInput.ts | 22 +++----- .../client/dtos/fetch/FetchMomentsInput.ts | 6 -- .../client/dtos/fetch/MomentsSortFields.ts | 2 - .../src/client/dtos/patch/PatchInput.ts | 8 --- packages/moments/src/domain/Moment.ts | 40 ++++--------- .../moments/src/queries/PaginatedMoments.ts | 14 ++--- packages/providers/package.json | 2 +- .../src/core/PoapMomentsApi/PoapMomentsApi.ts | 17 ------ .../MomentsApiProvider/MomentsApiProvider.ts | 11 ---- .../types/CreateMomentInput.ts | 17 ++---- .../types/CreateMomentResponse.ts | 30 +++------- .../types/PatchMomentInput.ts | 10 ---- .../providers/test/PoapMomentsApi.spec.ts | 54 +++--------------- yarn.lock | 6 +- 26 files changed, 91 insertions(+), 294 deletions(-) delete mode 100644 docs/pages/packages/moments/UpdateMoment.mdx delete mode 100644 packages/moments/src/client/dtos/patch/PatchInput.ts delete mode 100644 packages/providers/src/ports/MomentsApiProvider/types/PatchMomentInput.ts diff --git a/docs/pages/changelog.mdx b/docs/pages/changelog.mdx index 09fd72a3..81fe7a4c 100644 --- a/docs/pages/changelog.mdx +++ b/docs/pages/changelog.mdx @@ -20,3 +20,12 @@ - `createMoment` does not upload media beforehand anymore. Use `createMomentAndUploadMedia` instead. - For compass requests, the fetch signal is not a parameter of the `PoapCompass.request` method anymore, it must be given through the new `options` parameter: `compass.request(url, { variables }, { signal })`. + +## 0.7.0 + +- `dropId` has been changed to `dropIds` on the Moment type. It is now an array of 0 to multiple numerical IDs. + - This change is reflected in both the Moment creation input and the Moment response during creation or fetching. +- The CID is no longer a property of the Moment type. +- The token ID is no longer a property of the Moment type. +- `patchMoment` is no longer a method of the Moments client. +- It is no longer possible to order fetched Moments by token ID or drop ID. diff --git a/docs/pages/packages/moments.mdx b/docs/pages/packages/moments.mdx index aab02d34..f080eb68 100644 --- a/docs/pages/packages/moments.mdx +++ b/docs/pages/packages/moments.mdx @@ -7,7 +7,6 @@ ## Features - Create a Moment attached to a Drop or a specific POAP -- Update a Moment - Fetch multiple Moments - Fetch a single Moment diff --git a/docs/pages/packages/moments/FetchMoments.mdx b/docs/pages/packages/moments/FetchMoments.mdx index aee6ec99..b2d5bf00 100644 --- a/docs/pages/packages/moments/FetchMoments.mdx +++ b/docs/pages/packages/moments/FetchMoments.mdx @@ -19,7 +19,7 @@ const paginatedMoments: PaginatedResult = await client.fetch({ ### By Drop The list can be filtered by one or more Drops by giving `drop_ids` list with the -Drop IDs. Also, the list can be sorted by `id`, `created`, `tokenId` or `dropId`. +Drop IDs. Also, the list can be sorted by `id` or `created`. ```typescript import { Moment } from '@poap-xyz/moments'; diff --git a/docs/pages/packages/moments/UpdateMoment.mdx b/docs/pages/packages/moments/UpdateMoment.mdx deleted file mode 100644 index ab5121c0..00000000 --- a/docs/pages/packages/moments/UpdateMoment.mdx +++ /dev/null @@ -1,12 +0,0 @@ -# Update Moment - -## Update CID - -```typescript -const momentId = 'b08fad41-7154-499f-88f9-abea66ceab48'; -const cid = '0001-7ce5368171cc3d988157d7dab3d313d7bd43de3e-365e5b83699adce0825021d011f1bf73bd5ef9369d06e49645afbea2ef34f54e0557c1d4742c8bd6d1f7a02be4aa483c03888af0aa143d5aa7351e2baaf931231c.moment'; - -await client.patchMoment(momentId, { - cid, -}); -``` diff --git a/docs/pages/packages/moments/UploadMoments.mdx b/docs/pages/packages/moments/UploadMoments.mdx index 1c4b7fbe..dbda4874 100644 --- a/docs/pages/packages/moments/UploadMoments.mdx +++ b/docs/pages/packages/moments/UploadMoments.mdx @@ -17,14 +17,9 @@ const mimeType = mime.getType('path/to/poap-moment.png'); // Upload it. const moment: Moment = await client.createMomentAndUploadMedia({ /** - * Moments are associated with a Drop. + * Drops to be associated to the Moment. */ - dropId: 110148, - - /** - * The Token ID related to the moment (optional). - */ - tokenId: 6568008, + dropIds: [110148], /** * Who is uploading the moment. diff --git a/docs/pages/packages/moments/_meta.json b/docs/pages/packages/moments/_meta.json index 9a8b38e8..60031dba 100644 --- a/docs/pages/packages/moments/_meta.json +++ b/docs/pages/packages/moments/_meta.json @@ -1,5 +1,4 @@ { "FetchMoments": "Fetch Moments", - "UploadMoments": "Upload Moments", - "UpdateMoment": "Update Moment" + "UploadMoments": "Upload Moments" } diff --git a/packages/drops/package.json b/packages/drops/package.json index 6181de40..a5f1d6e9 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/drops", - "version": "0.5.5", + "version": "0.5.6", "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.6.0", + "@poap-xyz/providers": "0.7.0", "@poap-xyz/utils": "0.5.5" } } diff --git a/packages/moments/README.md b/packages/moments/README.md index 7aedfb2f..dfc08957 100644 --- a/packages/moments/README.md +++ b/packages/moments/README.md @@ -45,8 +45,7 @@ const client = new MomentsClient( ); const input: CreateMomentInput = { - dropId: 110148, - tokenId: 6568008, // Optional: The Token ID related to the moment + dropIds: [110148], media: [{ fileBinary: await fs.promises.readFile('src/assets/poap.png'), fileType: 'image/png', diff --git a/packages/moments/package.json b/packages/moments/package.json index 33cbdc40..098079a0 100644 --- a/packages/moments/package.json +++ b/packages/moments/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/moments", - "version": "0.6.0", + "version": "0.7.0", "description": "Moments 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/providers": "0.5.5", + "@poap-xyz/providers": "0.7.0", "@poap-xyz/utils": "0.5.5", "uuid": "^9.0.0" }, diff --git a/packages/moments/src/client/MomentsClient.spec.ts b/packages/moments/src/client/MomentsClient.spec.ts index 7fa6c47c..8adf50b1 100644 --- a/packages/moments/src/client/MomentsClient.spec.ts +++ b/packages/moments/src/client/MomentsClient.spec.ts @@ -4,13 +4,11 @@ import { MomentsClient } from './MomentsClient'; import { CreateMomentInput } from './dtos/create/CreateInput'; import { CreateSteps } from './dtos/create/CreateSteps'; import { v4 } from 'uuid'; -import { PatchMomentInput } from './dtos/patch/PatchInput'; import { CreateAndUploadMomentInput } from './dtos/create/CreateAndUploadInput'; describe('MomentsClient', () => { const MOMENT_ID = 'this-is-a-moment-id'; - const DROP_ID = 420; - const TOKEN_ID = 69; + const DROP_IDS = [420]; const AUTHOR = '0x7CE5368171cC3D988157d7dab3D313d7bd43de3e'; const FILE_1 = Buffer.from('This is the file 1'); const FILE_1_TYPE = 'image/png'; @@ -18,8 +16,6 @@ describe('MomentsClient', () => { const FILE_2_TYPE = 'image/jpeg'; const MEDIA_UPLOAD_URL = 'this-is-a-media-upload-url'; const DESCRIPTION = 'This is a description'; - const MOMENT_CID = - '0001-7ce5368171cc3d988157d7dab3d313d7bd43de3e-365e5b83699adce0825021d011f1bf73bd5ef9369d06e49645afbea2ef34f54e0557c1d4742c8bd6d1f7a02be4aa483c03888af0aa143d5aa7351e2baaf931231c.moment'; const MEDIAS_TO_CREATE = [ { fileBinary: FILE_1, @@ -53,8 +49,7 @@ describe('MomentsClient', () => { compassProviderMocked, ); const inputs: CreateAndUploadMomentInput = { - dropId: DROP_ID, - tokenId: TOKEN_ID, + dropIds: DROP_IDS, media: MEDIAS_TO_CREATE, author: AUTHOR, onStepUpdate, @@ -63,9 +58,9 @@ describe('MomentsClient', () => { poapMomentsAPIMocked.createMoment.mockResolvedValue({ id: MOMENT_ID, author: AUTHOR, - createdOn: new Date(), - dropId: DROP_ID, - tokenId: TOKEN_ID, + createdOn: new Date().toISOString(), + dropIds: DROP_IDS, + description: DESCRIPTION, }); const mediaKeys: string[] = []; poapMomentsAPIMocked.getSignedUrl.mockImplementation(async () => { @@ -78,8 +73,7 @@ describe('MomentsClient', () => { }); const EXPECTED_MOMENT_CREATE_INPUT = { - dropId: DROP_ID, - tokenId: TOKEN_ID, + dropIds: DROP_IDS, author: AUTHOR, description: DESCRIPTION, mediaKeys, @@ -91,8 +85,7 @@ describe('MomentsClient', () => { // THEN expect(moment.id).toBe(MOMENT_ID); expect(moment.author).toBe(AUTHOR); - expect(moment.dropId).toBe(DROP_ID); - expect(moment.tokenId).toBe(TOKEN_ID); + expect(moment.dropIds).toBe(DROP_IDS); expect(poapMomentsAPIMocked.createMoment).toHaveBeenCalledWith( EXPECTED_MOMENT_CREATE_INPUT, ); @@ -124,8 +117,7 @@ describe('MomentsClient', () => { compassProviderMocked, ); const inputs: CreateMomentInput = { - dropId: DROP_ID, - tokenId: TOKEN_ID, + dropIds: DROP_IDS, mediaKeys: MEDIA_KEYS, author: AUTHOR, onStepUpdate, @@ -134,14 +126,12 @@ describe('MomentsClient', () => { poapMomentsAPIMocked.createMoment.mockResolvedValue({ id: MOMENT_ID, author: AUTHOR, - createdOn: new Date(), - dropId: DROP_ID, - tokenId: TOKEN_ID, + createdOn: new Date().toISOString(), + dropIds: DROP_IDS, }); const EXPECTED_MOMENT_CREATE_INPUT = { - dropId: DROP_ID, - tokenId: TOKEN_ID, + dropIds: DROP_IDS, author: AUTHOR, description: DESCRIPTION, mediaKeys: MEDIA_KEYS, @@ -153,8 +143,7 @@ describe('MomentsClient', () => { // THEN expect(moment.id).toBe(MOMENT_ID); expect(moment.author).toBe(AUTHOR); - expect(moment.dropId).toBe(DROP_ID); - expect(moment.tokenId).toBe(TOKEN_ID); + expect(moment.dropIds).toBe(DROP_IDS); expect(poapMomentsAPIMocked.createMoment).toHaveBeenCalledWith( EXPECTED_MOMENT_CREATE_INPUT, ); @@ -164,25 +153,4 @@ describe('MomentsClient', () => { expect(onStepUpdate).toHaveBeenCalledTimes(2); }); }); - describe('updateMoment', () => { - it('should update a moment', async () => { - // GIVEN - const client = new MomentsClient( - poapMomentsAPIMocked, - compassProviderMocked, - ); - const input: PatchMomentInput = { - cid: MOMENT_CID, - }; - poapMomentsAPIMocked.patchMoment.mockResolvedValue(); - - // WHEN - await client.patchMoment(MOMENT_ID, input); - - // THEN - expect(poapMomentsAPIMocked.patchMoment).toHaveBeenCalledWith(MOMENT_ID, { - cid: MOMENT_CID, - }); - }); - }); }); diff --git a/packages/moments/src/client/MomentsClient.ts b/packages/moments/src/client/MomentsClient.ts index 1cd2f139..a389b4d8 100644 --- a/packages/moments/src/client/MomentsClient.ts +++ b/packages/moments/src/client/MomentsClient.ts @@ -17,7 +17,6 @@ import { import { CreateMedia } from './dtos/create/CreateMedia'; import { CreateMomentInput } from './dtos/create/CreateInput'; import { CreateSteps } from './dtos/create/CreateSteps'; -import { PatchMomentInput } from './dtos/patch/PatchInput'; import { FetchMomentsInput } from './dtos/fetch/FetchMomentsInput'; import { MomentsSortFields } from './dtos/fetch/MomentsSortFields'; import { CreateAndUploadMomentInput } from './dtos/create/CreateAndUploadInput'; @@ -57,9 +56,8 @@ export class MomentsClient { public async createMoment(input: CreateMomentInput): Promise { void input.onStepUpdate?.(CreateSteps.UPLOADING_MOMENT); const response = await this.poapMomentsApi.createMoment({ - dropId: input.dropId, + dropIds: input.dropIds, author: input.author, - tokenId: input.tokenId, description: input.description, mediaKeys: input.mediaKeys || [], }); @@ -142,14 +140,11 @@ export class MomentsClient { offset, id, createdOrder, - token_id, drop_ids, from, to, author, idOrder, - tokenIdOrder, - dropIdOrder, }: FetchMomentsInput): Promise> { const variables: MomentsQueryVariables = { limit, @@ -159,18 +154,9 @@ export class MomentsClient { MomentsSortFields.StartDate, createdOrder, ), - ...createOrderBy( - MomentsSortFields.TokenId, - tokenIdOrder, - ), - ...createOrderBy( - MomentsSortFields.DropId, - dropIdOrder, - ), ...createOrderBy(MomentsSortFields.Id, idOrder), }, where: { - ...createEqFilter('token_id', token_id), ...createInFilter('drop_id', drop_ids), ...createLikeFilter('author', author), ...createBetweenFilter('created_on', from, to), @@ -194,8 +180,4 @@ export class MomentsClient { return result; } - - public async patchMoment(id: string, input: PatchMomentInput): Promise { - await this.poapMomentsApi.patchMoment(id, input); - } } diff --git a/packages/moments/src/client/dtos/create/CreateAndUploadInput.ts b/packages/moments/src/client/dtos/create/CreateAndUploadInput.ts index 27ef4fe6..711d219a 100644 --- a/packages/moments/src/client/dtos/create/CreateAndUploadInput.ts +++ b/packages/moments/src/client/dtos/create/CreateAndUploadInput.ts @@ -1,25 +1,20 @@ import { CreateSteps } from './CreateSteps'; import { CreateMedia } from './CreateMedia'; -/** - * Interface representing the input needed to create a moment and upload media in one action. - * @interface - * @property {number} dropId - The ID of the drop related to the moment. - * @property {number} [tokenId] - The ID of the token related to the moment (optional). - * @property {string} author - The author of the moment. An Ethereum address. - * @property {string} description - The description of the moment (optional). - * @property {string} timeOut - The amount of time to wait until media is processed. - * @property {(step: CreateSteps) => void | Promise} [onStepUpdate] - Optional callback function to be called when the step changes. - * @property {(progress: number) => void | Promise} [onFileProgress] - Optional callback function to be called when the file upload progress change - progress is a number between 0 and 1. - * @property {CreateMedia[]} media - The media to be uploaded. - */ +/** Interface representing the input needed to create a moment and upload media in one action. */ export interface CreateAndUploadMomentInput { + /** The author of the moment. An Ethereum address. */ author: string; + /** The description of the moment. */ description?: string; - dropId: number; - tokenId?: number; + /** The IDs of the drops to associate to the moment. */ + dropIds: number[]; + /** The amount of time to wait until media is processed. */ timeOut?: number; + /** Callback function to be called when the progress step changes. */ onStepUpdate?: (step: CreateSteps) => void | Promise; + /** Callback function to be called when the file upload progress change - progress is a number between 0 and 1. */ onFileUploadProgress?: (progress: number) => void | Promise; + /** The media to be uploaded and attached to the Moment. */ media?: CreateMedia[]; } diff --git a/packages/moments/src/client/dtos/create/CreateInput.ts b/packages/moments/src/client/dtos/create/CreateInput.ts index 3c602988..7243ec15 100644 --- a/packages/moments/src/client/dtos/create/CreateInput.ts +++ b/packages/moments/src/client/dtos/create/CreateInput.ts @@ -1,23 +1,17 @@ import { CreateSteps } from './CreateSteps'; -/** - * Interface representing the input needed to create a moment. - * @interface - * @property {number} dropId - The ID of the drop related to the moment. - * @property {number} [tokenId] - The ID of the token related to the moment (optional). - * @property {string} author - The author of the moment. An Ethereum address. - * @property {string} description - The description of the moment (optional). - * @property {string} timeOut - The amount of time to wait until media is processed. - * @property {(step: CreateSteps) => void | Promise} [onStepUpdate] - Optional callback function to be called when the step changes. - * @property {(progress: number) => void | Promise} [onFileProgress] - Optional callback function to be called when the file upload progress change - progress is a number between 0 and 1. - * @property {string[]} mediaKeys - The media keys previously uploaded to attach to the Moment. - */ +/** Interface representing the input needed to create a moment. */ export interface CreateMomentInput { + /** The author of the moment. An Ethereum address. */ author: string; + /** The description of the moment. */ description?: string; - dropId: number; - tokenId?: number; + /** The IDs of the drops to associate to the moment. */ + dropIds: number[]; + /** The amount of time to wait until media is processed. */ timeOut?: number; + /** Callback function to be called when the step changes. */ onStepUpdate?: (step: CreateSteps) => void | Promise; + /** The media keys previously uploaded to attach to the Moment. */ mediaKeys?: string[]; } diff --git a/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts b/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts index eac4fec2..aa7ea1e5 100644 --- a/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts +++ b/packages/moments/src/client/dtos/fetch/FetchMomentsInput.ts @@ -6,25 +6,19 @@ import { Order, PaginationInput } from '@poap-xyz/utils'; * @property {number} limit - The maximum number of moments to fetch. * @property {number} offset - The number of moments to skip before starting to fetch. * @property {string} [createdOrder] - The order to use for sorting by creation time (optional). - * @property {string} [tokenIdOrder] - The order to use for sorting by token ID (optional). - * @property {string} [dropIdOrder] - The order to use for sorting by drop ID (optional). * @property {string} [idOrder] - The order to use for sorting by moment ID (optional). * @property {string} [author] - The author of the moments to fetch (optional). * @property {string} [from] - The start date for filtering moments by creation time (optional). * @property {string} [to] - The end date for filtering moments by creation time (optional). * @property {string} [id] - The moment ID to fetch (optional). - * @property {number} [token_id] - The token ID to filter moments by (optional). * @property {number} [drop_id] - The drop ID to filter moments by (optional). */ export interface FetchMomentsInput extends PaginationInput { createdOrder?: Order; - tokenIdOrder?: Order; - dropIdOrder?: Order; idOrder?: Order; author?: string; from?: string; to?: string; id?: string; - token_id?: number; drop_ids?: number[]; } diff --git a/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts b/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts index 94fe0f59..30064bfa 100644 --- a/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts +++ b/packages/moments/src/client/dtos/fetch/MomentsSortFields.ts @@ -6,7 +6,5 @@ */ export enum MomentsSortFields { StartDate = 'start_date', - TokenId = 'token_id', - DropId = 'drop_id', Id = 'id', } diff --git a/packages/moments/src/client/dtos/patch/PatchInput.ts b/packages/moments/src/client/dtos/patch/PatchInput.ts deleted file mode 100644 index 8f19df6f..00000000 --- a/packages/moments/src/client/dtos/patch/PatchInput.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Interface representing the input needed to patch a moment. - * @interface - * @property {string} cid - The cid of the moment in Registry. - */ -export interface PatchMomentInput { - cid?: string; -} diff --git a/packages/moments/src/domain/Moment.ts b/packages/moments/src/domain/Moment.ts index 158bb28e..8432a646 100644 --- a/packages/moments/src/domain/Moment.ts +++ b/packages/moments/src/domain/Moment.ts @@ -21,34 +21,22 @@ export class Moment { public readonly createdOn: Date; /** - * The drop ID related to the moment. + * The drop IDs associated with the moment. */ - public readonly dropId: number; - - /** - * The token ID related to the moment (optional). - */ - public readonly tokenId?: number; + public readonly dropIds: number[]; /** * The description of the moment. */ - public readonly description?: string; - - /** - * The cid of the moment in Registry - */ - public readonly cid?: string; + public readonly description: string | null; public static fromCompass(response: MomentResponse): Moment { return new Moment( response.id, response.author, new Date(response.created_on), - response.drop_id, - response.token_id, + response.drops.map((drop) => drop.drop_id), response.description, - response.cid, ); } @@ -56,11 +44,9 @@ export class Moment { return new Moment( response.id, response.author, - response.createdOn, - response.dropId, - response.tokenId, - response.description, - response.cid, + new Date(response.createdOn), + response.dropIds || [], + response.description || null, ); } @@ -68,17 +54,13 @@ export class Moment { id: string, author: string, createdOn: Date, - dropId: number, - tokenId?: number, - description?: string, - cid?: string, + dropIds: number[], + description: string | null, ) { this.id = id; this.author = author; this.createdOn = createdOn; - this.dropId = dropId; - this.tokenId = tokenId; - this.description = description; - this.cid = cid; + this.dropIds = dropIds || []; + this.description = description || null; } } diff --git a/packages/moments/src/queries/PaginatedMoments.ts b/packages/moments/src/queries/PaginatedMoments.ts index 4269bf13..88814cf1 100644 --- a/packages/moments/src/queries/PaginatedMoments.ts +++ b/packages/moments/src/queries/PaginatedMoments.ts @@ -4,7 +4,7 @@ import { PaginatedVariables, } from '@poap-xyz/utils'; -export const PAGINATED_MOMENTS_QUERY = ` +export const PAGINATED_MOMENTS_QUERY = /* GraphQL */ ` query PaginatedMoments( $limit: Int! $offset: Int! @@ -14,11 +14,11 @@ export const PAGINATED_MOMENTS_QUERY = ` moments(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) { author created_on - drop_id + drops { + drop_id + } id - token_id description - cid } } `; @@ -26,11 +26,9 @@ export const PAGINATED_MOMENTS_QUERY = ` export interface MomentResponse { author: string; created_on: string; - drop_id: number; + drops: { drop_id: number }[]; id: string; - token_id: number; - description?: string; - cid?: string; + description: string | null; } export interface MomentsQueryResponse { diff --git a/packages/providers/package.json b/packages/providers/package.json index 7809b708..d51b1c3f 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.6.0", + "version": "0.7.0", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", diff --git a/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts b/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts index 3fe8fb01..6db77867 100644 --- a/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts +++ b/packages/providers/src/core/PoapMomentsApi/PoapMomentsApi.ts @@ -2,7 +2,6 @@ import axios, { AxiosError } from 'axios'; import { InvalidMediaError } from '../../ports/MomentsApiProvider/errors/InvalidMediaError'; import { CreateMomentResponse } from '../../ports/MomentsApiProvider/types/CreateMomentResponse'; import { CreateMomentInput } from '../../ports/MomentsApiProvider/types/CreateMomentInput'; -import { PatchMomentInput } from '../../ports/MomentsApiProvider/types/PatchMomentInput'; import { MomentsApiProvider } from '../../ports/MomentsApiProvider/MomentsApiProvider'; import { AuthenticationProvider } from '../../ports/AuthenticationProvider/AuthenticationProvider'; import { MediaStatus } from '../../ports/MomentsApiProvider/types/MediaStatus'; @@ -165,22 +164,6 @@ export class PoapMomentsApi implements MomentsApiProvider { } } - /** - * Update a moment using the provided input - * @param {string} id - The moment id - * @param {PatchMomentInput} input - The input for updating a moment - */ - public async patchMoment(id: string, input: PatchMomentInput): Promise { - await fetch(`${this.baseUrl}/moments/${id}`, { - method: 'PATCH', - body: JSON.stringify(input), - headers: { - 'Content-Type': 'application/json', - Authorization: await this.getAuthorizationToken(), - }, - }); - } - private async getAuthorizationToken(): Promise { if (!this.authenticationProvider) { throw new Error( diff --git a/packages/providers/src/ports/MomentsApiProvider/MomentsApiProvider.ts b/packages/providers/src/ports/MomentsApiProvider/MomentsApiProvider.ts index d6f213af..039e4cb5 100644 --- a/packages/providers/src/ports/MomentsApiProvider/MomentsApiProvider.ts +++ b/packages/providers/src/ports/MomentsApiProvider/MomentsApiProvider.ts @@ -1,6 +1,5 @@ import { CreateMomentInput } from './types/CreateMomentInput'; import { CreateMomentResponse } from './types/CreateMomentResponse'; -import { PatchMomentInput } from './types/PatchMomentInput'; import { MediaStatus } from './types/MediaStatus'; /** @@ -56,14 +55,4 @@ export interface MomentsApiProvider { * @returns {Promise} - A Promise that resolves with the media processing status */ fetchMediaStatus(mediaKey: string): Promise; - - /** - * Updates a moment on the API. - * @async - * @function - * @name MomentsApiProvider#patchMoment - * @param {string} id - The Moment id. - * @param {PatchMomentInput} input - The input data for updating a moment. - */ - patchMoment(id: string, input: PatchMomentInput): Promise; } diff --git a/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentInput.ts b/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentInput.ts index 33a61856..5784b704 100644 --- a/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentInput.ts +++ b/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentInput.ts @@ -1,16 +1,11 @@ -/** - * Object describing the input required to create a Moment - * @typedef {Object} CreateMomentInput - * @property {number} dropId - The ID of the Drop associated with the Moment - * @property {string} author - The author of the Moment. An Ethereum address. - * @property {string[]} mediaKeys - The media keys associated with the Moment - * @property {number} [tokenId] - The ID of the Token associated with the Moment (optional) - * @property {string} [description] - The description of the Moment (optional) - */ +/** Object describing the input required to create a Moment */ export interface CreateMomentInput { - dropId: number; + /** The IDs of the Drops to associate with the Moment */ + dropIds: number[]; + /** The author of the Moment. An Ethereum address. */ author: string; + /** The media keys associated with the Moment */ mediaKeys: string[]; - tokenId?: number; + /** The description of the Moment (optional) */ description?: string; } diff --git a/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentResponse.ts b/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentResponse.ts index 432550e8..c2a1c5aa 100644 --- a/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentResponse.ts +++ b/packages/providers/src/ports/MomentsApiProvider/types/CreateMomentResponse.ts @@ -1,33 +1,19 @@ export interface CreateMomentResponse { + /** The Moment ID. */ id: string; - /** - * The author of the moment (for now only ETH accounts). - */ + /** The author of the moment (for now only ETH accounts). */ author: string; - /** - * When the moment was received on the API. - */ - createdOn: Date; + /** When the moment was received on the API. */ + createdOn: string; - /** - * The drop ID related to the moment. - */ - dropId: number; + /** The drop IDs associated to the moment. */ + dropIds: number[]; - /** - * The token ID related to the moment (optional). - */ - tokenId?: number; - - /** - * The description of the moment. - */ + /** The description of the moment. */ description?: string; - /** - * The cid of the moment in Registry. - */ + /** The cid of the moment in Registry. */ cid?: string; } diff --git a/packages/providers/src/ports/MomentsApiProvider/types/PatchMomentInput.ts b/packages/providers/src/ports/MomentsApiProvider/types/PatchMomentInput.ts deleted file mode 100644 index aa28d405..00000000 --- a/packages/providers/src/ports/MomentsApiProvider/types/PatchMomentInput.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Object describing the input required to update a Moment. - * @typedef {Object} PatchMomentInput - * @property {string} cid - The cid of the moment in Registry under the format: - * {--.} allows you to fetch and verify the - * content of the moment in Registry. - */ -export interface PatchMomentInput { - cid?: string; -} diff --git a/packages/providers/test/PoapMomentsApi.spec.ts b/packages/providers/test/PoapMomentsApi.spec.ts index 6c87c167..2ac286f4 100644 --- a/packages/providers/test/PoapMomentsApi.spec.ts +++ b/packages/providers/test/PoapMomentsApi.spec.ts @@ -6,6 +6,7 @@ import { InvalidMediaError } from '../src/ports/MomentsApiProvider/errors/Invali import { mock, MockProxy } from 'jest-mock-extended'; import { MediaStatus } from '../src/ports/MomentsApiProvider/types/MediaStatus'; import { CreateMomentInput } from '../src/ports/MomentsApiProvider/types/CreateMomentInput'; +import { CreateMomentResponse } from '../src/ports/MomentsApiProvider/types/CreateMomentResponse'; import { enableFetchMocks } from 'jest-fetch-mock'; enableFetchMocks(); @@ -15,7 +16,7 @@ describe('PoapMomentsApi', () => { let api: PoapMomentsApi; let authenticationProviderMocked: MockProxy; - let axiosMocked; + let axiosMocked: MockAdapter; beforeEach(() => { authenticationProviderMocked = mock(); @@ -98,28 +99,26 @@ describe('PoapMomentsApi', () => { .onGet(`${BASE_URL}/media/${mediaKey}`) .reply(200, invalidMediaResponse); - await expect( - api.waitForMediaProcessing(mediaKey, 5000), - ).rejects.toThrowError(InvalidMediaError); + await expect(api.waitForMediaProcessing(mediaKey, 5000)).rejects.toThrow( + InvalidMediaError, + ); }); }); describe('createMoment', () => { const createMomentInput: CreateMomentInput = { - dropId: 1, + dropIds: [1], author: '0x1234', mediaKeys: ['mock-media-key'], - tokenId: 1000, description: 'This is a test description', }; it('should create a moment successfully', async () => { - const mockResponse = { + const mockResponse: CreateMomentResponse = { id: '1', author: '0x1234', createdOn: '2023-01-01T00:00:00.000Z', - dropId: 1, - tokenId: 1000, + dropIds: [1], description: 'This is a test description', }; @@ -134,41 +133,4 @@ describe('PoapMomentsApi', () => { await expect(api.createMoment(createMomentInput)).rejects.toThrow(); }); }); - - describe('patchMoment', () => { - const id = '1'; - const patchMomentInput = { - cid: '0001-7ce5368171cc3d988157d7dab3d313d7bd43de3e-365e5b83699adce0825021d011f1bf73bd5ef9369d06e49645afbea2ef34f54e0557c1d4742c8bd6d1f7a02be4aa483c03888af0aa143d5aa7351e2baaf931231c.moment', - }; - - it('should call fetch with correct parameters for PATCH request', async () => { - fetchMock.mockOnce(() => - Promise.resolve({ - ok: true, - status: 200, - body: JSON.stringify({}), - }), - ); - - const result = await api.patchMoment(id, patchMomentInput); - - expect(result).toBe(undefined); - expect(fetch).toHaveBeenCalledWith( - `${BASE_URL}/moments/${id}`, - { - method: 'PATCH', - body: JSON.stringify(patchMomentInput), - headers: { - 'Content-Type': 'application/json', - Authorization: expect.any(String), - }, - } - ); - }); - - it('should throw error when AuthenticationProvider is not provided', async () => { - api = new PoapMomentsApi({}); - await expect(api.patchMoment(id, patchMomentInput)).rejects.toThrow(); - }); - }); }); diff --git a/yarn.lock b/yarn.lock index 73814d50..6eee51c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -884,7 +884,7 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/drops@workspace:packages/drops" dependencies: - "@poap-xyz/providers": 0.6.0 + "@poap-xyz/providers": 0.7.0 "@poap-xyz/utils": 0.5.5 languageName: unknown linkType: soft @@ -901,7 +901,7 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/moments@workspace:packages/moments" dependencies: - "@poap-xyz/providers": 0.5.5 + "@poap-xyz/providers": 0.7.0 "@poap-xyz/utils": 0.5.5 "@types/uuid": ^9.0.2 uuid: ^9.0.0 @@ -917,7 +917,7 @@ __metadata: languageName: unknown linkType: soft -"@poap-xyz/providers@0.6.0, @poap-xyz/providers@workspace:packages/providers": +"@poap-xyz/providers@0.7.0, @poap-xyz/providers@workspace:packages/providers": version: 0.0.0-use.local resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: