diff --git a/packages/client/src/consts/config.ts b/packages/client/src/consts/config.ts index 0a489a0e19..7e2fb657d7 100644 --- a/packages/client/src/consts/config.ts +++ b/packages/client/src/consts/config.ts @@ -1,6 +1,16 @@ import { IStorageProvider } from '@lens-protocol/storage'; import { Environment } from './environments'; +import { MediaTransform } from './media'; + +/** + * The media transforms configuration. + */ +export type MediaTransformsConfig = { + publication?: MediaTransform; + profilePicture?: MediaTransform; + profileCover?: MediaTransform; +}; /** * LensClient configuration @@ -14,4 +24,13 @@ export type LensConfig = { * The storage provider to use. */ storage?: IStorageProvider; + + /** + * Media returned from the publication and profile queries can be transformed + * to sizes needed by the SDK consuming application. + * To overwrite default transformation values, provide a `mediaTransforms` object. + * + * @see {@link MediaTransformsConfig} for more information + */ + mediaTransforms?: MediaTransformsConfig; }; diff --git a/packages/client/src/consts/defaults.ts b/packages/client/src/consts/defaults.ts deleted file mode 100644 index 2659f07d31..0000000000 --- a/packages/client/src/consts/defaults.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { MediaTransformParams } from '../graphql/types.generated'; - -export const defaultMediaTransformParams: MediaTransformParams = { - width: 'auto', - height: 'auto', - keepAspectRatio: true, -}; diff --git a/packages/client/src/consts/media.ts b/packages/client/src/consts/media.ts new file mode 100644 index 0000000000..bf8723bf2c --- /dev/null +++ b/packages/client/src/consts/media.ts @@ -0,0 +1,34 @@ +type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'; + +type Percentage = `100%` | `${Digit}${Digit}%` | `${Digit}%`; + +type Pixel = + | `${Digit}${Digit}${Digit}${Digit}px` + | `${Digit}${Digit}${Digit}px` + | `${Digit}${Digit}px`; + +export type ImageSizeTransform = Pixel | Percentage | 'auto'; + +export type MediaTransform = { + /** + * Set the transformed image's width. You can use specific size in + * pixels eg. 100px, a percentage eg. 50% or set as 'auto' to be set automatically. + * + * @defaultValue 'auto' + */ + width?: ImageSizeTransform; + /** + * Set the transformed image's height. You can use specific size in + * pixels eg. 100px, a percentage eg. 50% or set as 'auto' to be set automatically. + * + * @defaultValue 'auto' + */ + height?: ImageSizeTransform; + /** + * Set if you want to keep the image's original aspect ratio. + * If explicitly set to false, the image will stretch based on the width and height values. + * + * @defaultValue true + */ + keepAspectRatio?: boolean; +}; diff --git a/packages/client/src/explore/Explore.ts b/packages/client/src/explore/Explore.ts index ee411030ff..597a745e09 100644 --- a/packages/client/src/explore/Explore.ts +++ b/packages/client/src/explore/Explore.ts @@ -1,15 +1,15 @@ import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { ProfileFragment } from '../graphql/fragments.generated'; import type { PublicationFragment } from '../graphql/types'; -import type { - ExploreProfilesRequest, - ExplorePublicationRequest, - MediaTransformParams, -} from '../graphql/types.generated'; -import { buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders } from '../helpers'; +import type { ExploreProfilesRequest, ExplorePublicationRequest } from '../graphql/types.generated'; +import { + buildMediaTransformsFromConfig, + buildPaginatedQueryResult, + PaginatedResult, + provideAuthHeaders, +} from '../helpers'; import { getSdk, Sdk } from './graphql/explore.generated'; /** @@ -21,7 +21,7 @@ export class Explore { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -33,7 +33,6 @@ export class Explore { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Array of {@link PublicationFragment} wrapped in {@link PaginatedResult} * * @example @@ -48,7 +47,6 @@ export class Explore { async publications( request: ExplorePublicationRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -56,7 +54,7 @@ export class Explore { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -71,7 +69,6 @@ export class Explore { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Array of {@link ProfileFragment} wrapped in {@link PaginatedResult} * * @example @@ -86,7 +83,6 @@ export class Explore { async profiles( request: ExploreProfilesRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -94,7 +90,7 @@ export class Explore { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/explore/graphql/explore.generated.ts b/packages/client/src/explore/graphql/explore.generated.ts index ea0b5c82fa..5bb6bbe1f2 100644 --- a/packages/client/src/explore/graphql/explore.generated.ts +++ b/packages/client/src/explore/graphql/explore.generated.ts @@ -34,7 +34,9 @@ import { export type ExplorePublicationsQueryVariables = Types.Exact<{ request: Types.ExplorePublicationRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ExplorePublicationsQuery = { @@ -47,7 +49,8 @@ export type ExplorePublicationsQuery = { export type ExploreProfilesQueryVariables = Types.Exact<{ request: Types.ExploreProfilesRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ExploreProfilesQuery = { @@ -58,7 +61,9 @@ export const ExplorePublicationsDocument = gql` query ExplorePublications( $request: ExplorePublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: explorePublications(request: $request) { items { @@ -86,7 +91,8 @@ export const ExploreProfilesDocument = gql` query ExploreProfiles( $request: ExploreProfilesRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: exploreProfiles(request: $request) { items { diff --git a/packages/client/src/explore/graphql/explore.graphql b/packages/client/src/explore/graphql/explore.graphql index fc68349b1f..4fc47d94c9 100644 --- a/packages/client/src/explore/graphql/explore.graphql +++ b/packages/client/src/explore/graphql/explore.graphql @@ -1,7 +1,9 @@ query ExplorePublications( $request: ExplorePublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: explorePublications(request: $request) { items { @@ -26,7 +28,8 @@ query ExplorePublications( query ExploreProfiles( $request: ExploreProfilesRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: exploreProfiles(request: $request) { items { diff --git a/packages/client/src/feed/Feed.ts b/packages/client/src/feed/Feed.ts index 2877d6598e..015f1b0405 100644 --- a/packages/client/src/feed/Feed.ts +++ b/packages/client/src/feed/Feed.ts @@ -2,16 +2,16 @@ import type { PromiseResult } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { PublicationFragment } from '../graphql/types'; -import type { - FeedHighlightsRequest, - FeedRequest, - MediaTransformParams, -} from '../graphql/types.generated'; -import { buildPaginatedQueryResult, PaginatedResult, requireAuthHeaders } from '../helpers'; +import type { FeedHighlightsRequest, FeedRequest } from '../graphql/types.generated'; +import { + buildMediaTransformsFromConfig, + buildPaginatedQueryResult, + PaginatedResult, + requireAuthHeaders, +} from '../helpers'; import { FeedItemFragment, getSdk, Sdk } from './graphql/feed.generated'; /** @@ -23,7 +23,7 @@ export class Feed { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication: Authentication) { + constructor(private readonly config: LensConfig, authentication: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -37,7 +37,6 @@ export class Feed { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns {@link PromiseResult} with array of {@link FeedItemFragment} wrapped in {@link PaginatedResult} * * @example @@ -50,7 +49,6 @@ export class Feed { async fetch( request: FeedRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): PromiseResult< PaginatedResult, CredentialsExpiredError | NotAuthenticatedError @@ -61,7 +59,7 @@ export class Feed { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -78,7 +76,6 @@ export class Feed { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns {@link PromiseResult} with array of {@link PublicationFragment} wrapped in {@link PaginatedResult} * * @example @@ -91,7 +88,6 @@ export class Feed { async fetchHighlights( request: FeedHighlightsRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): PromiseResult< PaginatedResult, CredentialsExpiredError | NotAuthenticatedError @@ -102,7 +98,7 @@ export class Feed { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/feed/graphql/feed.generated.ts b/packages/client/src/feed/graphql/feed.generated.ts index 09eda0507c..5f2a648d18 100644 --- a/packages/client/src/feed/graphql/feed.generated.ts +++ b/packages/client/src/feed/graphql/feed.generated.ts @@ -68,7 +68,9 @@ export type FeedItemFragment = { export type FeedQueryVariables = Types.Exact<{ request: Types.FeedRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type FeedQuery = { @@ -78,7 +80,9 @@ export type FeedQuery = { export type FeedHighlightsQueryVariables = Types.Exact<{ request: Types.FeedHighlightsRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type FeedHighlightsQuery = { @@ -168,7 +172,9 @@ export const FeedDocument = gql` query Feed( $request: FeedRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: feed(request: $request) { items { @@ -186,7 +192,9 @@ export const FeedHighlightsDocument = gql` query FeedHighlights( $request: FeedHighlightsRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: feedHighlights(request: $request) { items { diff --git a/packages/client/src/feed/graphql/feed.graphql b/packages/client/src/feed/graphql/feed.graphql index 67a3b77ce9..a66ec7845b 100644 --- a/packages/client/src/feed/graphql/feed.graphql +++ b/packages/client/src/feed/graphql/feed.graphql @@ -63,7 +63,9 @@ fragment FeedItem on FeedItem { query Feed( $request: FeedRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: feed(request: $request) { items { @@ -78,7 +80,9 @@ query Feed( query FeedHighlights( $request: FeedHighlightsRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: feedHighlights(request: $request) { items { diff --git a/packages/client/src/graphql/fragments.generated.ts b/packages/client/src/graphql/fragments.generated.ts index 9118866e68..619cc6de00 100644 --- a/packages/client/src/graphql/fragments.generated.ts +++ b/packages/client/src/graphql/fragments.generated.ts @@ -46,7 +46,7 @@ export type ProfileFieldsFragment = { isFollowedByMe: boolean; isFollowing: boolean; picture: - | MediaSetFragment + | ProfilePictureSetFragment | { __typename: 'NftImage'; contractAddress: string; @@ -56,7 +56,7 @@ export type ProfileFieldsFragment = { } | null; coverPicture: - | MediaSetFragment + | ProfileCoverSetFragment | { __typename: 'NftImage'; contractAddress: string; @@ -218,7 +218,23 @@ export type MediaFragment = { url: string; }; -export type MediaSetFragment = { +export type PublicationMediaSetFragment = { + __typename: 'MediaSet'; + onChain: MediaFragment; + original: MediaFragment; + optimized: MediaFragment | null; + transformed: MediaFragment | null; +}; + +export type ProfilePictureSetFragment = { + __typename: 'MediaSet'; + onChain: MediaFragment; + original: MediaFragment; + optimized: MediaFragment | null; + transformed: MediaFragment | null; +}; + +export type ProfileCoverSetFragment = { __typename: 'MediaSet'; onChain: MediaFragment; original: MediaFragment; @@ -237,7 +253,7 @@ export type MetadataFragment = { mainContentFocus: Types.PublicationMainFocus; name: string | null; tags: Array; - media: Array; + media: Array; attributes: Array; }; @@ -422,8 +438,26 @@ export const MediaFragmentDoc = gql` url } `; -export const MediaSetFragmentDoc = gql` - fragment MediaSet on MediaSet { +export const ProfilePictureSetFragmentDoc = gql` + fragment ProfilePictureSet on MediaSet { + __typename + onChain { + ...Media + } + original { + ...Media + } + optimized { + ...Media + } + transformed(params: $mediaTransformProfilePicture) { + ...Media + } + } + ${MediaFragmentDoc} +`; +export const ProfileCoverSetFragmentDoc = gql` + fragment ProfileCoverSet on MediaSet { __typename onChain { ...Media @@ -434,7 +468,7 @@ export const MediaSetFragmentDoc = gql` optimized { ...Media } - transformed(params: $mediaTransformParams) { + transformed(params: $mediaTransformProfileCover) { ...Media } } @@ -505,7 +539,7 @@ export const ProfileFieldsFragmentDoc = gql` verified } ... on MediaSet { - ...MediaSet + ...ProfilePictureSet } } coverPicture { @@ -517,7 +551,7 @@ export const ProfileFieldsFragmentDoc = gql` verified } ... on MediaSet { - ...MediaSet + ...ProfileCoverSet } } stats { @@ -551,7 +585,8 @@ export const ProfileFieldsFragmentDoc = gql` isFollowedByMe(isFinalisedOnChain: true) isFollowing(who: $observerId) } - ${MediaSetFragmentDoc} + ${ProfilePictureSetFragmentDoc} + ${ProfileCoverSetFragmentDoc} ${FeeFollowModuleSettingsFragmentDoc} ${ProfileFollowModuleSettingsFragmentDoc} ${RevertFollowModuleSettingsFragmentDoc} @@ -592,6 +627,24 @@ export const SimplePublicationStatsFragmentDoc = gql` totalBookmarks } `; +export const PublicationMediaSetFragmentDoc = gql` + fragment PublicationMediaSet on MediaSet { + __typename + onChain { + ...Media + } + original { + ...Media + } + optimized { + ...Media + } + transformed(params: $mediaTransformPublication) { + ...Media + } + } + ${MediaFragmentDoc} +`; export const MetadataAttributeOutputFragmentDoc = gql` fragment MetadataAttributeOutput on MetadataAttributeOutput { __typename @@ -611,14 +664,14 @@ export const MetadataFragmentDoc = gql` mainContentFocus name media { - ...MediaSet + ...PublicationMediaSet } attributes { ...MetadataAttributeOutput } tags } - ${MediaSetFragmentDoc} + ${PublicationMediaSetFragmentDoc} ${MetadataAttributeOutputFragmentDoc} `; export const WalletFragmentDoc = gql` diff --git a/packages/client/src/graphql/fragments.graphql b/packages/client/src/graphql/fragments.graphql index f6e18c719b..a9a5eadd9d 100644 --- a/packages/client/src/graphql/fragments.graphql +++ b/packages/client/src/graphql/fragments.graphql @@ -48,7 +48,7 @@ fragment ProfileFields on Profile { } ... on MediaSet { - ...MediaSet + ...ProfilePictureSet } } @@ -62,7 +62,7 @@ fragment ProfileFields on Profile { } ... on MediaSet { - ...MediaSet + ...ProfileCoverSet } } @@ -274,7 +274,7 @@ fragment Media on Media { url } -fragment MediaSet on MediaSet { +fragment PublicationMediaSet on MediaSet { __typename onChain { ...Media @@ -285,7 +285,39 @@ fragment MediaSet on MediaSet { optimized { ...Media } - transformed(params: $mediaTransformParams) { + transformed(params: $mediaTransformPublication) { + ...Media + } +} + +fragment ProfilePictureSet on MediaSet { + __typename + onChain { + ...Media + } + original { + ...Media + } + optimized { + ...Media + } + transformed(params: $mediaTransformProfilePicture) { + ...Media + } +} + +fragment ProfileCoverSet on MediaSet { + __typename + onChain { + ...Media + } + original { + ...Media + } + optimized { + ...Media + } + transformed(params: $mediaTransformProfileCover) { ...Media } } @@ -301,7 +333,7 @@ fragment Metadata on MetadataOutput { mainContentFocus name media { - ...MediaSet + ...PublicationMediaSet } attributes { ...MetadataAttributeOutput diff --git a/packages/client/src/helpers/buildPaginatedQueryResult.spec.ts b/packages/client/src/helpers/buildPaginatedQueryResult.spec.ts index 4769373f29..c5d5a76650 100644 --- a/packages/client/src/helpers/buildPaginatedQueryResult.spec.ts +++ b/packages/client/src/helpers/buildPaginatedQueryResult.spec.ts @@ -1,7 +1,6 @@ import { GraphQLClient } from 'graphql-request'; import { buildTestEnvironment } from '../__helpers__'; -import { defaultMediaTransformParams } from '../consts/defaults'; import { getSdk } from '../profile/graphql/profile.generated'; import { buildPaginatedQueryResult } from './buildPaginatedQueryResult'; @@ -15,7 +14,6 @@ describe('Given a paginated query function and the paginated query result helper const res = await sdk.Profiles({ request: currRequest, observerId: undefined, - mediaTransformParams: defaultMediaTransformParams, }); return res.data.result; @@ -32,7 +30,6 @@ describe('Given a paginated query function and the paginated query result helper const res = await sdk.Profiles({ request: currRequest, observerId: undefined, - mediaTransformParams: defaultMediaTransformParams, }); return res.data.result; @@ -57,7 +54,6 @@ describe('Given a paginated query function and the paginated query result helper const res = await sdk.Profiles({ request: currRequest, observerId: undefined, - mediaTransformParams: defaultMediaTransformParams, }); return res.data.result; diff --git a/packages/client/src/helpers/index.ts b/packages/client/src/helpers/index.ts index cdeb3be931..41c52787e4 100644 --- a/packages/client/src/helpers/index.ts +++ b/packages/client/src/helpers/index.ts @@ -1,4 +1,5 @@ export * from './buildPaginatedQueryResult'; +export * from './mediaTransforms'; +export * from './poll'; export * from './provideAuthHeaders'; export * from './requireAuthHeaders'; -export * from './poll'; diff --git a/packages/client/src/helpers/mediaTransforms.ts b/packages/client/src/helpers/mediaTransforms.ts new file mode 100644 index 0000000000..738b4eb073 --- /dev/null +++ b/packages/client/src/helpers/mediaTransforms.ts @@ -0,0 +1,9 @@ +import { MediaTransformsConfig } from '../consts/config'; + +export function buildMediaTransformsFromConfig(config: MediaTransformsConfig = {}) { + return { + mediaTransformPublication: config.publication, + mediaTransformProfilePicture: config.profilePicture, + mediaTransformProfileCover: config.profileCover, + }; +} diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index b47858e4cb..6bed92c7bf 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -35,8 +35,9 @@ export type { export type { IStorageProvider } from '@lens-protocol/storage'; export type { Environment } from './consts/environments'; -export type { LensConfig } from './consts/config'; +export type { LensConfig, MediaTransformsConfig } from './consts/config'; export type { TypedData, TypedDataResponse } from './consts/types'; +export type { ImageSizeTransform, MediaTransform } from './consts/media'; export type { PublicationFragment } from './graphql/types'; export type { PaginatedResult, PaginatedQueryData } from './helpers/buildPaginatedQueryResult'; @@ -59,7 +60,6 @@ export type { LimitedFeeCollectModuleSettingsFragment, LimitedTimedFeeCollectModuleSettingsFragment, MediaFragment, - MediaSetFragment, MetadataAttributeOutputFragment, MetadataFragment, MirrorBaseFragment, @@ -67,15 +67,18 @@ export type { ModuleFeeAmountFragment, MultirecipientFeeCollectModuleSettingsFragment, PostFragment, + ProfileCoverSetFragment, + ProfileFieldsFragment, ProfileFollowModuleSettingsFragment, ProfileFragment, - ProfileFieldsFragment, + ProfilePictureSetFragment, + PublicationMediaSetFragment, RelayerResultFragment, RelayErrorFragment, RevertCollectModuleSettingsFragment, RevertFollowModuleSettingsFragment, - SimplePublicationStatsFragment, SimpleCollectModuleSettingsFragment, + SimplePublicationStatsFragment, TimedFeeCollectModuleSettingsFragment, UnknownFollowModuleSettingsFragment, WalletFragment, @@ -133,7 +136,6 @@ export type { IllegalReasonInputParams, LimitedFeeCollectModuleParams, LimitedTimedFeeCollectModuleParams, - MediaTransformParams, ModuleFeeAmountParams, ModuleFeeParams, MultirecipientFeeCollectModuleParams, diff --git a/packages/client/src/notifications/Notifications.ts b/packages/client/src/notifications/Notifications.ts index 6e0025b674..d359132188 100644 --- a/packages/client/src/notifications/Notifications.ts +++ b/packages/client/src/notifications/Notifications.ts @@ -2,11 +2,15 @@ import type { PromiseResult } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; -import type { MediaTransformParams, NotificationRequest } from '../graphql/types.generated'; -import { PaginatedResult, buildPaginatedQueryResult, requireAuthHeaders } from '../helpers'; +import type { NotificationRequest } from '../graphql/types.generated'; +import { + PaginatedResult, + buildMediaTransformsFromConfig, + buildPaginatedQueryResult, + requireAuthHeaders, +} from '../helpers'; import { getSdk, NewCollectNotificationFragment, @@ -35,7 +39,7 @@ export class Notifications { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication: Authentication) { + constructor(private readonly config: LensConfig, authentication: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -49,7 +53,6 @@ export class Notifications { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns {@link PromiseResult} with array of {@link NotificationFragment} wrapped in {@link PaginatedResult} * * @example @@ -62,7 +65,6 @@ export class Notifications { async fetch( request: NotificationRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): PromiseResult< PaginatedResult, CredentialsExpiredError | NotAuthenticatedError @@ -73,7 +75,7 @@ export class Notifications { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/notifications/graphql/notifications.generated.ts b/packages/client/src/notifications/graphql/notifications.generated.ts index 214d20aa68..ebecac3fe0 100644 --- a/packages/client/src/notifications/graphql/notifications.generated.ts +++ b/packages/client/src/notifications/graphql/notifications.generated.ts @@ -72,7 +72,9 @@ export type NewReactionNotificationFragment = { export type NotificationsQueryVariables = Types.Exact<{ request: Types.NotificationRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type NotificationsQuery = { @@ -209,7 +211,9 @@ export const NotificationsDocument = gql` query Notifications( $request: NotificationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: notifications(request: $request) { items { diff --git a/packages/client/src/notifications/graphql/notifications.graphql b/packages/client/src/notifications/graphql/notifications.graphql index d936d167f5..9a526681b2 100644 --- a/packages/client/src/notifications/graphql/notifications.graphql +++ b/packages/client/src/notifications/graphql/notifications.graphql @@ -97,7 +97,9 @@ fragment NewReactionNotification on NewReactionNotification { query Notifications( $request: NotificationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: notifications(request: $request) { items { diff --git a/packages/client/src/profile/Profile.ts b/packages/client/src/profile/Profile.ts index 911cd5e045..9e439cf1df 100644 --- a/packages/client/src/profile/Profile.ts +++ b/packages/client/src/profile/Profile.ts @@ -2,7 +2,6 @@ import type { PromiseResult } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { @@ -28,7 +27,6 @@ import type { FollowersRequest, FollowingRequest, FollowRequest, - MediaTransformParams, MutualFollowersProfilesQueryRequest, PendingApprovalFollowsRequest, ProfileGuardianRequest, @@ -42,6 +40,7 @@ import type { UpdateProfileImageRequest, } from '../graphql/types.generated'; import { + buildMediaTransformsFromConfig, buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders, @@ -72,7 +71,7 @@ export class Profile { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -84,7 +83,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Profile or null if not found * * @example @@ -95,14 +93,13 @@ export class Profile { async fetch( request: SingleProfileQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise { return provideAuthHeaders(this.authentication, async (headers) => { const result = await this.sdk.Profile( { request, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -145,7 +142,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Profiles wrapped in {@link PaginatedResult} * * @example @@ -158,7 +154,6 @@ export class Profile { async fetchAll( request: ProfileQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -166,7 +161,7 @@ export class Profile { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -181,7 +176,6 @@ export class Profile { * * @param options - Optional options for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Array of recommended profiles * * @example @@ -192,14 +186,13 @@ export class Profile { async allRecommended( options: RecommendedProfileOptions = {}, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise { return provideAuthHeaders(this.authentication, async (headers) => { const result = await this.sdk.RecommendedProfiles( { options, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -234,7 +227,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Profiles wrapped in {@link PaginatedResult} * * @example @@ -248,7 +240,6 @@ export class Profile { async mutualFollowers( request: MutualFollowersProfilesQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -256,7 +247,7 @@ export class Profile { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -306,7 +297,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Profiles wrapped in {@link PaginatedResult} * * @example @@ -319,7 +309,6 @@ export class Profile { async allFollowing( request: FollowingRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -327,7 +316,7 @@ export class Profile { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -342,7 +331,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Wallets with default profiles wrapped in {@link PaginatedResult} * * @example @@ -355,7 +343,6 @@ export class Profile { async allFollowers( request: FollowersRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -363,7 +350,7 @@ export class Profile { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -850,7 +837,6 @@ export class Profile { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Profiles wrapped in {@link PaginatedResult} * * @example @@ -861,7 +847,6 @@ export class Profile { async pendingApprovalFollows( request: PendingApprovalFollowsRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): PromiseResult< PaginatedResult, CredentialsExpiredError | NotAuthenticatedError @@ -872,7 +857,7 @@ export class Profile { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/profile/graphql/profile.generated.ts b/packages/client/src/profile/graphql/profile.generated.ts index 1453595e7b..a58d3429eb 100644 --- a/packages/client/src/profile/graphql/profile.generated.ts +++ b/packages/client/src/profile/graphql/profile.generated.ts @@ -32,7 +32,8 @@ import { export type ProfileQueryVariables = Types.Exact<{ request: Types.SingleProfileQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ProfileQuery = { result: ProfileFragment | null }; @@ -62,7 +63,8 @@ export type ProfileStatsQuery = { result: { stats: ProfileStatsFragment } | null export type ProfilesQueryVariables = Types.Exact<{ request: Types.ProfileQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ProfilesQuery = { @@ -72,7 +74,8 @@ export type ProfilesQuery = { export type RecommendedProfilesQueryVariables = Types.Exact<{ options: Types.RecommendedProfileOptions; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type RecommendedProfilesQuery = { result: Array }; @@ -80,7 +83,8 @@ export type RecommendedProfilesQuery = { result: Array }; export type MutualFollowersProfilesQueryVariables = Types.Exact<{ request: Types.MutualFollowersProfilesQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type MutualFollowersProfilesQuery = { @@ -104,7 +108,8 @@ export type DoesFollowQuery = { export type FollowingQueryVariables = Types.Exact<{ request: Types.FollowingRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type FollowingQuery = { @@ -114,7 +119,8 @@ export type FollowingQuery = { export type FollowersQueryVariables = Types.Exact<{ request: Types.FollowersRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type FollowersQuery = { @@ -136,7 +142,8 @@ export type FollowerNftOwnedTokenIdsQuery = { export type PendingApprovalFollowsQueryVariables = Types.Exact<{ request: Types.PendingApprovalFollowsRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type PendingApprovalFollowsQuery = { @@ -622,7 +629,8 @@ export const ProfileDocument = gql` query Profile( $request: SingleProfileQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profile(request: $request) { ...Profile @@ -644,7 +652,8 @@ export const ProfilesDocument = gql` query Profiles( $request: ProfileQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profiles(request: $request) { items { @@ -662,7 +671,8 @@ export const RecommendedProfilesDocument = gql` query RecommendedProfiles( $options: RecommendedProfileOptions! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: recommendedProfiles(options: $options) { ...Profile @@ -674,7 +684,8 @@ export const MutualFollowersProfilesDocument = gql` query MutualFollowersProfiles( $request: MutualFollowersProfilesQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: mutualFollowersProfiles(request: $request) { items { @@ -703,7 +714,8 @@ export const FollowingDocument = gql` query Following( $request: FollowingRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: following(request: $request) { items { @@ -721,7 +733,8 @@ export const FollowersDocument = gql` query Followers( $request: FollowersRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: followers(request: $request) { items { @@ -748,7 +761,8 @@ export const PendingApprovalFollowsDocument = gql` query PendingApprovalFollows( $request: PendingApprovalFollowsRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: pendingApprovalFollows(request: $request) { items { diff --git a/packages/client/src/profile/graphql/profile.graphql b/packages/client/src/profile/graphql/profile.graphql index a2454b17a1..f8880cb556 100644 --- a/packages/client/src/profile/graphql/profile.graphql +++ b/packages/client/src/profile/graphql/profile.graphql @@ -2,7 +2,8 @@ query Profile( $request: SingleProfileQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profile(request: $request) { ...Profile @@ -36,7 +37,8 @@ query ProfileStats($request: SingleProfileQueryRequest!, $sources: [Sources!]!) query Profiles( $request: ProfileQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profiles(request: $request) { items { @@ -52,7 +54,8 @@ query Profiles( query RecommendedProfiles( $options: RecommendedProfileOptions! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: recommendedProfiles(options: $options) { ...Profile @@ -62,7 +65,8 @@ query RecommendedProfiles( query MutualFollowersProfiles( $request: MutualFollowersProfilesQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: mutualFollowersProfiles(request: $request) { items { @@ -88,7 +92,8 @@ query DoesFollow($request: DoesFollowRequest!) { query Following( $request: FollowingRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: following(request: $request) { items { @@ -104,7 +109,8 @@ query Following( query Followers( $request: FollowersRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: followers(request: $request) { items { @@ -128,7 +134,8 @@ query FollowerNftOwnedTokenIds($request: FollowerNftOwnedTokenIdsRequest!) { query PendingApprovalFollows( $request: PendingApprovalFollowsRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: pendingApprovalFollows(request: $request) { items { diff --git a/packages/client/src/publication/Publication.ts b/packages/client/src/publication/Publication.ts index 2fd1e32cd3..498890ee43 100644 --- a/packages/client/src/publication/Publication.ts +++ b/packages/client/src/publication/Publication.ts @@ -2,7 +2,6 @@ import type { PromiseResult } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { @@ -24,7 +23,6 @@ import type { CreatePublicPostRequest, GetPublicationMetadataStatusRequest, HidePublicationRequest, - MediaTransformParams, ProfilePublicationsForSaleRequest, PublicationMetadataStatus, PublicationMetadataV2Input, @@ -37,6 +35,7 @@ import type { WhoCollectedPublicationRequest, } from '../graphql/types.generated'; import { + buildMediaTransformsFromConfig, buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders, @@ -72,7 +71,7 @@ export class Publication { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -84,7 +83,6 @@ export class Publication { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Publication or null if not found * * @example @@ -97,14 +95,13 @@ export class Publication { async fetch( request: PublicationQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise { return provideAuthHeaders(this.authentication, async (headers) => { const result = await this.sdk.Publication( { request, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -200,7 +197,6 @@ export class Publication { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Publications wrapped in {@link PaginatedResult} * * @example @@ -213,7 +209,6 @@ export class Publication { async fetchAll( request: PublicationsQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -221,7 +216,7 @@ export class Publication { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -236,7 +231,6 @@ export class Publication { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Wallets wrapped in {@link PaginatedResult} * * @example @@ -249,7 +243,6 @@ export class Publication { async allWalletsWhoCollected( request: WhoCollectedPublicationRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -257,7 +250,7 @@ export class Publication { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -272,7 +265,6 @@ export class Publication { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Publications wrapped in {@link PaginatedResult} * * @example @@ -285,7 +277,6 @@ export class Publication { async allForSale( request: ProfilePublicationsForSaleRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -293,7 +284,7 @@ export class Publication { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/publication/graphql/publication.generated.ts b/packages/client/src/publication/graphql/publication.generated.ts index bdf4bb4414..e891dc332f 100644 --- a/packages/client/src/publication/graphql/publication.generated.ts +++ b/packages/client/src/publication/graphql/publication.generated.ts @@ -122,7 +122,9 @@ export type CreateCollectTypedDataFragment = { export type PublicationQueryVariables = Types.Exact<{ request: Types.PublicationQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type PublicationQuery = { result: CommentFragment | MirrorFragment | PostFragment | null }; @@ -143,7 +145,9 @@ export type PublicationStatsQuery = { export type PublicationsQueryVariables = Types.Exact<{ request: Types.PublicationsQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type PublicationsQuery = { @@ -168,7 +172,8 @@ export type ValidatePublicationMetadataQuery = { export type WhoCollectedPublicationQueryVariables = Types.Exact<{ request: Types.WhoCollectedPublicationRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type WhoCollectedPublicationQuery = { @@ -178,7 +183,9 @@ export type WhoCollectedPublicationQuery = { export type ProfilePublicationsForSaleQueryVariables = Types.Exact<{ request: Types.ProfilePublicationsForSaleRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ProfilePublicationsForSaleQuery = { @@ -461,7 +468,9 @@ export const PublicationDocument = gql` query Publication( $request: PublicationQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publication(request: $request) { ... on Post { @@ -505,7 +514,9 @@ export const PublicationsDocument = gql` query Publications( $request: PublicationsQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publications(request: $request) { items { @@ -542,7 +553,8 @@ export const WhoCollectedPublicationDocument = gql` query WhoCollectedPublication( $request: WhoCollectedPublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: whoCollectedPublication(request: $request) { items { @@ -560,7 +572,9 @@ export const ProfilePublicationsForSaleDocument = gql` query ProfilePublicationsForSale( $request: ProfilePublicationsForSaleRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profilePublicationsForSale(request: $request) { items { diff --git a/packages/client/src/publication/graphql/publication.graphql b/packages/client/src/publication/graphql/publication.graphql index 7ac9a48165..58fcb4c9ec 100644 --- a/packages/client/src/publication/graphql/publication.graphql +++ b/packages/client/src/publication/graphql/publication.graphql @@ -132,7 +132,9 @@ fragment CreateCollectTypedData on CreateCollectBroadcastItemResult { query Publication( $request: PublicationQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publication(request: $request) { ... on Post { @@ -174,7 +176,9 @@ query PublicationStats($request: PublicationQueryRequest!, $sources: [Sources!]! query Publications( $request: PublicationsQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publications(request: $request) { items { @@ -207,7 +211,8 @@ query ValidatePublicationMetadata($metadata: PublicationMetadataV2Input!) { query WhoCollectedPublication( $request: WhoCollectedPublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: whoCollectedPublication(request: $request) { items { @@ -223,7 +228,9 @@ query WhoCollectedPublication( query ProfilePublicationsForSale( $request: ProfilePublicationsForSaleRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profilePublicationsForSale(request: $request) { items { diff --git a/packages/client/src/reactions/Reactions.ts b/packages/client/src/reactions/Reactions.ts index 28a739f12c..9c69676c68 100644 --- a/packages/client/src/reactions/Reactions.ts +++ b/packages/client/src/reactions/Reactions.ts @@ -2,15 +2,11 @@ import type { PromiseResult } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; -import type { - MediaTransformParams, - ReactionRequest, - WhoReactedPublicationRequest, -} from '../graphql/types.generated'; +import type { ReactionRequest, WhoReactedPublicationRequest } from '../graphql/types.generated'; import { + buildMediaTransformsFromConfig, buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders, @@ -27,7 +23,7 @@ export class Reactions { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -94,7 +90,6 @@ export class Reactions { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Array of {@link WhoReactedResultFragment} wrapped in {@link PaginatedResult} * * @example @@ -107,7 +102,6 @@ export class Reactions { async toPublication( request: WhoReactedPublicationRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -115,7 +109,7 @@ export class Reactions { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/reactions/graphql/reactions.generated.ts b/packages/client/src/reactions/graphql/reactions.generated.ts index 56ad1ae6c9..88097ef130 100644 --- a/packages/client/src/reactions/graphql/reactions.generated.ts +++ b/packages/client/src/reactions/graphql/reactions.generated.ts @@ -52,7 +52,8 @@ export type WhoReactedResultFragment = { export type WhoReactedPublicationQueryVariables = Types.Exact<{ request: Types.WhoReactedPublicationRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type WhoReactedPublicationQuery = { @@ -85,7 +86,8 @@ export const WhoReactedPublicationDocument = gql` query WhoReactedPublication( $request: WhoReactedPublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: whoReactedPublication(request: $request) { items { diff --git a/packages/client/src/reactions/graphql/reactions.graphql b/packages/client/src/reactions/graphql/reactions.graphql index 3e58817e26..f06f00fce6 100644 --- a/packages/client/src/reactions/graphql/reactions.graphql +++ b/packages/client/src/reactions/graphql/reactions.graphql @@ -19,7 +19,8 @@ fragment WhoReactedResult on WhoReactedResult { query WhoReactedPublication( $request: WhoReactedPublicationRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: whoReactedPublication(request: $request) { items { diff --git a/packages/client/src/revenue/Revenue.ts b/packages/client/src/revenue/Revenue.ts index 8c3dc36a1a..40647ba266 100644 --- a/packages/client/src/revenue/Revenue.ts +++ b/packages/client/src/revenue/Revenue.ts @@ -1,14 +1,17 @@ import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { - MediaTransformParams, ProfileFollowRevenueQueryRequest, ProfilePublicationRevenueQueryRequest, PublicationRevenueQueryRequest, } from '../graphql/types.generated'; -import { buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders } from '../helpers'; +import { + buildMediaTransformsFromConfig, + buildPaginatedQueryResult, + PaginatedResult, + provideAuthHeaders, +} from '../helpers'; import { getSdk, PublicationRevenueFragment, @@ -25,7 +28,7 @@ export class Revenue { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -38,7 +41,6 @@ export class Revenue { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Array of {@link PublicationRevenueFragment} wrapped in {@link PaginatedResult} * * @example @@ -51,7 +53,6 @@ export class Revenue { async profilePublication( request: ProfilePublicationRevenueQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise> { return provideAuthHeaders(this.authentication, async (headers) => { return buildPaginatedQueryResult(async (currRequest) => { @@ -59,7 +60,7 @@ export class Revenue { { request: currRequest, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); @@ -102,7 +103,6 @@ export class Revenue { * * @param request - Request object for the query * @param observerId - Optional id of a profile that is the observer for this request - * @param mediaTransformParams - Optional media transform params if you want to optimize media in the response * @returns Publication revenue * * @example @@ -115,14 +115,13 @@ export class Revenue { async publication( request: PublicationRevenueQueryRequest, observerId?: string, - mediaTransformParams: MediaTransformParams = defaultMediaTransformParams, ): Promise { return provideAuthHeaders(this.authentication, async (headers) => { const result = await this.sdk.PublicationRevenue( { request, observerId, - mediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }, headers, ); diff --git a/packages/client/src/revenue/graphql/revenue.generated.ts b/packages/client/src/revenue/graphql/revenue.generated.ts index b3d0fbcdf8..26b9de0781 100644 --- a/packages/client/src/revenue/graphql/revenue.generated.ts +++ b/packages/client/src/revenue/graphql/revenue.generated.ts @@ -24,7 +24,9 @@ import { export type ProfilePublicationRevenueQueryVariables = Types.Exact<{ request: Types.ProfilePublicationRevenueQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type ProfilePublicationRevenueQuery = { @@ -34,7 +36,9 @@ export type ProfilePublicationRevenueQuery = { export type PublicationRevenueQueryVariables = Types.Exact<{ request: Types.PublicationRevenueQueryRequest; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type PublicationRevenueQuery = { result: PublicationRevenueFragment | null }; @@ -92,7 +96,9 @@ export const ProfilePublicationRevenueDocument = gql` query ProfilePublicationRevenue( $request: ProfilePublicationRevenueQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profilePublicationRevenue(request: $request) { items { @@ -110,7 +116,9 @@ export const PublicationRevenueDocument = gql` query PublicationRevenue( $request: PublicationRevenueQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publicationRevenue(request: $request) { ...PublicationRevenue diff --git a/packages/client/src/revenue/graphql/revenue.graphql b/packages/client/src/revenue/graphql/revenue.graphql index 8b3dea8ca0..98cddffd1b 100644 --- a/packages/client/src/revenue/graphql/revenue.graphql +++ b/packages/client/src/revenue/graphql/revenue.graphql @@ -1,7 +1,9 @@ query ProfilePublicationRevenue( $request: ProfilePublicationRevenueQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: profilePublicationRevenue(request: $request) { items { @@ -17,7 +19,9 @@ query ProfilePublicationRevenue( query PublicationRevenue( $request: PublicationRevenueQueryRequest! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: publicationRevenue(request: $request) { ...PublicationRevenue diff --git a/packages/client/src/search/Search.ts b/packages/client/src/search/Search.ts index ce9cb880fc..21391c73b4 100644 --- a/packages/client/src/search/Search.ts +++ b/packages/client/src/search/Search.ts @@ -2,15 +2,18 @@ import { Prettify, invariant } from '@lens-protocol/shared-kernel'; import type { Authentication } from '../authentication'; import type { LensConfig } from '../consts/config'; -import { defaultMediaTransformParams } from '../consts/defaults'; import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient'; import type { CommentFragment, PostFragment, ProfileFragment, } from '../graphql/fragments.generated'; -import { MediaTransformParams } from '../graphql/types.generated'; -import { buildPaginatedQueryResult, PaginatedResult, provideAuthHeaders } from '../helpers'; +import { + buildMediaTransformsFromConfig, + buildPaginatedQueryResult, + PaginatedResult, + provideAuthHeaders, +} from '../helpers'; import { getSdk, Sdk, @@ -19,15 +22,17 @@ import { } from './graphql/search.generated'; export type SearchProfilesQuery = Prettify< - Omit & { - mediaTransformParams?: MediaTransformParams; - } + Omit< + SearchProfilesQueryVariables, + 'mediaTransformPublication' | 'mediaTransformProfilePicture' | 'mediaTransformProfileCover' + > >; export type SearchPublicationsQuery = Prettify< - Omit & { - mediaTransformParams?: MediaTransformParams; - } + Omit< + SearchPublicationsQueryVariables, + 'mediaTransformPublication' | 'mediaTransformProfilePicture' | 'mediaTransformProfileCover' + > >; /** @@ -39,7 +44,7 @@ export class Search { private readonly authentication: Authentication | undefined; private readonly sdk: Sdk; - constructor(config: LensConfig, authentication?: Authentication) { + constructor(private readonly config: LensConfig, authentication?: Authentication) { const client = new FetchGraphQLClient(config.environment.gqlEndpoint); this.sdk = getSdk(client); @@ -62,7 +67,7 @@ export class Search { async profiles(request: SearchProfilesQuery): Promise> { const actualRequest = { ...request, - mediaTransformParams: request.mediaTransformParams ?? defaultMediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }; return provideAuthHeaders(this.authentication, async (headers) => { @@ -98,7 +103,7 @@ export class Search { ): Promise> { const actualRequest = { ...request, - mediaTransformParams: request.mediaTransformParams ?? defaultMediaTransformParams, + ...buildMediaTransformsFromConfig(this.config.mediaTransforms), }; return provideAuthHeaders(this.authentication, async (headers) => { diff --git a/packages/client/src/search/graphql/search.generated.ts b/packages/client/src/search/graphql/search.generated.ts index e1675bccd3..a9bc2107e4 100644 --- a/packages/client/src/search/graphql/search.generated.ts +++ b/packages/client/src/search/graphql/search.generated.ts @@ -37,7 +37,9 @@ export type SearchPublicationsQueryVariables = Types.Exact<{ query: Types.Scalars['Search']; sources?: Types.InputMaybe | Types.Scalars['Sources']>; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformPublication?: Types.InputMaybe; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type SearchPublicationsQuery = { @@ -55,7 +57,8 @@ export type SearchProfilesQueryVariables = Types.Exact<{ cursor?: Types.InputMaybe; query: Types.Scalars['Search']; observerId?: Types.InputMaybe; - mediaTransformParams: Types.MediaTransformParams; + mediaTransformProfilePicture?: Types.InputMaybe; + mediaTransformProfileCover?: Types.InputMaybe; }>; export type SearchProfilesQuery = { @@ -75,7 +78,9 @@ export const SearchPublicationsDocument = gql` $query: Search! $sources: [Sources!] $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: search( request: { @@ -115,7 +120,8 @@ export const SearchProfilesDocument = gql` $cursor: Cursor $query: Search! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: search(request: { query: $query, type: PROFILE, limit: $limit, cursor: $cursor }) { ... on ProfileSearchResult { diff --git a/packages/client/src/search/graphql/search.graphql b/packages/client/src/search/graphql/search.graphql index f0f6b33d2b..d96e774295 100644 --- a/packages/client/src/search/graphql/search.graphql +++ b/packages/client/src/search/graphql/search.graphql @@ -4,7 +4,9 @@ query SearchPublications( $query: Search! $sources: [Sources!] $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformPublication: MediaTransformParams = {} + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: search( request: { query: $query, type: PUBLICATION, limit: $limit, cursor: $cursor, sources: $sources } @@ -35,7 +37,8 @@ query SearchProfiles( $cursor: Cursor $query: Search! $observerId: ProfileId - $mediaTransformParams: MediaTransformParams! + $mediaTransformProfilePicture: MediaTransformParams = {} + $mediaTransformProfileCover: MediaTransformParams = {} ) { result: search(request: { query: $query, type: PROFILE, limit: $limit, cursor: $cursor }) { ... on ProfileSearchResult {