diff --git a/examples/node/.eslintrc.js b/examples/node/.eslintrc.js new file mode 100644 index 0000000000..5112816ccb --- /dev/null +++ b/examples/node/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + root: true, + extends: ['@lens-protocol/eslint-config'], + parser: '@typescript-eslint/parser', + parserOptions: { + project: ['./tsconfig.json'], + tsconfigRootDir: __dirname, + }, + rules: { + 'no-console': 'off', + '@typescript-eslint/no-floating-promises': 'off', + }, +}; diff --git a/examples/node/package.json b/examples/node/package.json index 1aafacc0ae..2c60971e41 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -4,7 +4,14 @@ "private": true, "description": "", "scripts": { - "ts-node": "ts-node" + "ts-node": "ts-node", + "eslint:fix": "pnpm run eslint --fix", + "eslint": "eslint scripts", + "lint": "pnpm run prettier && pnpm run eslint && pnpm run tsc", + "lint:fix": "pnpm run prettier:fix && pnpm run eslint:fix && pnpm run tsc", + "prettier:fix": "prettier --write .", + "prettier": "prettier --check .", + "tsc": "tsc --noEmit" }, "keywords": [], "author": "", @@ -18,9 +25,13 @@ "viem": "^1.0.0" }, "devDependencies": { + "@lens-protocol/eslint-config": "workspace:*", + "@lens-protocol/prettier-config": "workspace:*", "@types/node": "^18.15.11", "@types/uuid": "^9.0.0", + "prettier": "^2.8.4", "ts-node": "^10.9.1", "typescript": "^4.9.5" - } + }, + "prettier": "@lens-protocol/prettier-config" } diff --git a/examples/node/scripts/authenticate.ts b/examples/node/scripts/authenticate.ts index acc66e3f70..5ac89d4887 100644 --- a/examples/node/scripts/authenticate.ts +++ b/examples/node/scripts/authenticate.ts @@ -1,37 +1,36 @@ -import { LensClient, development } from "@lens-protocol/client"; -import { setupWallet } from "./shared/setupWallet"; +import { LensClient, development } from '@lens-protocol/client'; + +import { setupWallet } from './shared/setupWallet'; async function main() { - const lensClient = new LensClient({ + const client = new LensClient({ environment: development, - storage: { - getItem: async (key: string) => { - const value = localStorage.getItem(key); - return localStorage.getItem(key); - }, - setItem: async (key: string, value: string) => { - localStorage.setItem(key, value); - }, - removeItem: async (key: string) => { - localStorage.removeItem(key); - }, - }, }); const wallet = setupWallet(); const address = await wallet.getAddress(); - const challenge = await lensClient.authentication.generateChallenge(address); - const signature = await wallet.signMessage(challenge); + const ownedProfiles = await client.profile.fetchAll({ where: { ownedBy: [address] } }); + + if (ownedProfiles.items.length === 0) { + throw new Error(`You don't have any profiles, create one first`); + } + + const { id, text } = await client.authentication.generateChallenge({ + profileId: ownedProfiles.items[0].id, + address, + }); + + const signature = await wallet.signMessage(text); - await lensClient.authentication.authenticate(address, signature); + await client.authentication.authenticate({ id, signature }); - const accessTokenResult = await lensClient.authentication.getAccessToken(); + const accessTokenResult = await client.authentication.getAccessToken(); const accessToken = accessTokenResult.unwrap(); - console.log(`Is LensClient authenticated? `, await lensClient.authentication.isAuthenticated()); + console.log(`Is LensClient authenticated? `, await client.authentication.isAuthenticated()); console.log(`Access token: `, accessToken); - console.log(`Is access token valid? `, await lensClient.authentication.verify(accessToken)); + console.log(`Is access token valid? `, await client.authentication.verify(accessToken)); } main(); diff --git a/examples/node/scripts/bookmarks.ts b/examples/node/scripts/bookmarks.ts deleted file mode 100644 index 8954c87018..0000000000 --- a/examples/node/scripts/bookmarks.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { isRelaySuccess, LensClient, ProfileFragment } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "./shared/getAuthenticatedClient"; -import { setupWallet } from "./shared/setupWallet"; - -async function createProfile(client: LensClient): Promise { - const handle = Date.now().toString(); - - console.log(`Creating ${handle}.test...`); - - const profileCreateResult = await client.profile.create({ handle, to: "EVM_ADDRESS" }); - - if (!isRelaySuccess(profileCreateResult)) { - console.log(`Something went wrong`, profileCreateResult); - return; - } - - console.log(`Waiting for the transaction ${profileCreateResult.txHash} to be indexed...`); - await client.transaction.waitUntilComplete({ txId: profileCreateResult.txId }); - - return client.profile.fetch({ handle: `${handle}.test` }); -} - -async function main() { - // setup - const wallet = setupWallet(); - const address = await wallet.getAddress(); - const client = await getAuthenticatedClientFromEthersWallet(wallet); - - const profile = await createProfile(client); - - // const before = await client.bookmarks.fetch({ profileId: profile.id }); - - // console.log(`Initial ${profile.handle} bookmarks: `, before.items.length); - - // const addResult = await client.bookmarks.add({ - // profileId: profile.id, - // publicationId: "0x0635-0x0f", - // }); - - // if (addResult.isFailure()) { - // console.log(`Something went wrong`, addResult.unwrap()); - // return; - // } - - // const after = await client.bookmarks.fetch({ profileId: profile.id }); - - // console.log(`${profile.handle} bookmarks after adding one: `, after.items.length); - - // const removeResult = await client.bookmarks.remove({ - // profileId: profile.id, - // publicationId: "0x0635-0x0f", - // }); - - // if (removeResult.isFailure()) { - // console.log(`Something went wrong`, removeResult.unwrap()); - // return; - // } - - // const ultimately = await client.bookmarks.fetch({ profileId: profile.id }); - - // console.log(`${profile.handle} bookmarks after removing one: `, ultimately.items.length); -} - -main(); diff --git a/examples/node/scripts/explore/exploreProfiles.ts b/examples/node/scripts/explore/exploreProfiles.ts index de57a670ad..ad2f9982be 100644 --- a/examples/node/scripts/explore/exploreProfiles.ts +++ b/examples/node/scripts/explore/exploreProfiles.ts @@ -1,4 +1,4 @@ -import { ExploreProfileOrderBy, LensClient, development } from "@lens-protocol/client"; +import { ExploreProfileOrderBy, LensClient, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -12,7 +12,7 @@ async function main() { const mostPostsThisYear = await lensClient.explore.profiles({ orderBy: ExploreProfileOrderBy.MostPosts, where: { - since: "2023-01-01T00:00:00.000Z", + since: '2023-01-01T00:00:00.000Z', }, }); diff --git a/examples/node/scripts/explore/explorePublications.ts b/examples/node/scripts/explore/explorePublications.ts index 1490addd35..26d9607819 100644 --- a/examples/node/scripts/explore/explorePublications.ts +++ b/examples/node/scripts/explore/explorePublications.ts @@ -3,7 +3,7 @@ import { ExplorePublicationsOrderByType, LensClient, development, -} from "@lens-protocol/client"; +} from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -16,7 +16,6 @@ async function main() { const topCommented = await lensClient.explore.publications({ orderBy: ExplorePublicationsOrderByType.TopCommented, - limit: 10, }); const highestMirroredPosts = await lensClient.explore.publications({ @@ -28,12 +27,10 @@ async function main() { const topCollected = await lensClient.explore.publications({ orderBy: ExplorePublicationsOrderByType.TopCollectedOpenAction, - limit: 10, }); const curatedProfiles = await lensClient.explore.publications({ orderBy: ExplorePublicationsOrderByType.LensCurated, - limit: 10, }); console.log(JSON.stringify(latestPublications, null, 2)); diff --git a/examples/node/scripts/follow/followProfileUsingLensProfileManager.ts b/examples/node/scripts/follow/followProfileUsingLensProfileManager.ts index 0c733b6194..d66148284f 100644 --- a/examples/node/scripts/follow/followProfileUsingLensProfileManager.ts +++ b/examples/node/scripts/follow/followProfileUsingLensProfileManager.ts @@ -1,12 +1,13 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); - const recommendedProfiles = await lensClient.profile.recommendations({ for: "YOUR_PROFILE_ID" }); + const recommendedProfiles = await lensClient.profile.recommendations({ for: 'YOUR_PROFILE_ID' }); console.log( `First 3 recommended profiles`, @@ -14,20 +15,20 @@ async function main() { id: p.id, handle: p.handle, isFollowedByMe: p.operations.isFollowedByMe, - })) + })), ); const result = await lensClient.profile.follow({ follow: [ { - profileId: "PROFILE_TO_FOLLOW_ID", + profileId: 'PROFILE_TO_FOLLOW_ID', }, ], }); console.log( - `Follow of ${recommendedProfiles[0].id} triggered with through the Lens Profile Manager: `, - result.unwrap() + `Follow of ${recommendedProfiles.items[0].id} triggered with through the Lens Profile Manager: `, + result.unwrap(), ); const followResultValue = result.unwrap(); diff --git a/examples/node/scripts/follow/followProfileViaTypedData.ts b/examples/node/scripts/follow/followProfileViaTypedData.ts index ec9f98e135..6f23df22e6 100644 --- a/examples/node/scripts/follow/followProfileViaTypedData.ts +++ b/examples/node/scripts/follow/followProfileViaTypedData.ts @@ -1,15 +1,16 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); - const following = await lensClient.profile.following({ for: "PROFILE_TO_UNFOLLOW_ID" }); + const following = await lensClient.profile.following({ for: 'PROFILE_TO_UNFOLLOW_ID' }); const result = await lensClient.profile.createUnfollowTypedData({ - unfollow: [following[1].id], + unfollow: [following.items[1].id], }); const data = result.unwrap(); @@ -17,7 +18,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( data.typedData.domain, data.typedData.types, - data.typedData.value + data.typedData.value, ); const broadcastResult = await lensClient.transaction.broadcastOnChain({ @@ -33,7 +34,7 @@ async function main() { } console.log( - `Transaction to follow ${following[1].id} was successfuly broadcasted with txId ${followBroadcastResultValue.txId}` + `Transaction to follow ${following.items[1].id} was successfuly broadcasted with txId ${followBroadcastResultValue.txId}`, ); // wait for follow to be indexed diff --git a/examples/node/scripts/follow/followers.ts b/examples/node/scripts/follow/followers.ts index 83705f30b2..e2e55a5693 100644 --- a/examples/node/scripts/follow/followers.ts +++ b/examples/node/scripts/follow/followers.ts @@ -1,17 +1,17 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const result = await lensClient.profile.followers({ - of: "PROFILE_ID", + of: 'PROFILE_ID', }); console.log( `Followers:`, - result.items.map((p) => p.handle) + result.items.map((p) => p.handle), ); } diff --git a/examples/node/scripts/follow/following.ts b/examples/node/scripts/follow/following.ts index dce4f67bb3..e9d46803b6 100644 --- a/examples/node/scripts/follow/following.ts +++ b/examples/node/scripts/follow/following.ts @@ -1,17 +1,17 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const result = await lensClient.profile.following({ - for: "PROFILE_ID", + for: 'PROFILE_ID', }); console.log( `Following:`, - result.items.map((p) => p.handle) + result.items.map((p) => p.handle), ); } diff --git a/examples/node/scripts/follow/isFollowedByMe.ts b/examples/node/scripts/follow/isFollowedByMe.ts deleted file mode 100644 index 29ec483a9b..0000000000 --- a/examples/node/scripts/follow/isFollowedByMe.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; - -async function main() { - const wallet = setupWallet(); - const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); - - const { isFollowedByMe } = await lensClient.profile.fetch({ - profileId: "PROFILE_ID", - }); - - console.log({ isFollowedByMe }); -} - -main(); diff --git a/examples/node/scripts/follow/setProfileFollowModuleViaLensProfileManager.ts b/examples/node/scripts/follow/setProfileFollowModuleViaLensProfileManager.ts index 9822033979..3e80d01618 100644 --- a/examples/node/scripts/follow/setProfileFollowModuleViaLensProfileManager.ts +++ b/examples/node/scripts/follow/setProfileFollowModuleViaLensProfileManager.ts @@ -1,6 +1,7 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -42,7 +43,7 @@ async function main() { const followModuleResultValue = result.unwrap(); if (!isRelaySuccess(followModuleResultValue)) { - throw new Error("Failed to set follow module"); + throw new Error('Failed to set follow module'); } await lensClient.transaction.waitUntilComplete({ txId: followModuleResultValue.txId }); diff --git a/examples/node/scripts/follow/setProfileFollowModuleViaTypedData.ts b/examples/node/scripts/follow/setProfileFollowModuleViaTypedData.ts index 08135ece43..9e132a2ca8 100644 --- a/examples/node/scripts/follow/setProfileFollowModuleViaTypedData.ts +++ b/examples/node/scripts/follow/setProfileFollowModuleViaTypedData.ts @@ -1,6 +1,7 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -44,7 +45,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( data.typedData.domain, data.typedData.types, - data.typedData.value + data.typedData.value, ); const broadcastResult = await lensClient.transaction.broadcastOnChain({ @@ -60,7 +61,7 @@ async function main() { } console.log( - `Profile follow module sucessfully set and successfully broadcasted with txId ${followBroadcastResultValue.txId}` + `Profile follow module sucessfully set and successfully broadcasted with txId ${followBroadcastResultValue.txId}`, ); // wait for follow to be indexed diff --git a/examples/node/scripts/follow/unfollowProfileUsingLensProfileManager.ts b/examples/node/scripts/follow/unfollowProfileUsingLensProfileManager.ts index bb2d69bc28..2cafc18f7f 100644 --- a/examples/node/scripts/follow/unfollowProfileUsingLensProfileManager.ts +++ b/examples/node/scripts/follow/unfollowProfileUsingLensProfileManager.ts @@ -1,20 +1,21 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); - const following = await lensClient.profile.following({ for: "PROFILE_ID" }); + const following = await lensClient.profile.following({ for: 'PROFILE_ID' }); const result = await lensClient.profile.unfollow({ unfollow: [following.items[0].id], }); console.log( - `Follow of ${following[0].id} triggered with through the Lens Profile Manager: `, - result.unwrap() + `Follow of ${following.items[0].id} triggered with through the Lens Profile Manager: `, + result.unwrap(), ); const unfollowResultValue = result.unwrap(); diff --git a/examples/node/scripts/follow/unfollowProfileViaTypedData.ts b/examples/node/scripts/follow/unfollowProfileViaTypedData.ts index 9b5ebc6624..3e8fd35010 100644 --- a/examples/node/scripts/follow/unfollowProfileViaTypedData.ts +++ b/examples/node/scripts/follow/unfollowProfileViaTypedData.ts @@ -1,15 +1,15 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; -import { signAndBroadcast } from "../shared/signAndBroadcast"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); - const following = await lensClient.profile.following({ for: "PROFILE_ID" }); + const following = await lensClient.profile.following({ for: 'PROFILE_ID' }); - const profileToUnfollowId = following[0].id; + const profileToUnfollowId = following.items[0].id; const followTypedDataResult = await lensClient.profile.createUnfollowTypedData({ unfollow: [profileToUnfollowId], @@ -20,7 +20,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( data.typedData.domain, data.typedData.types, - data.typedData.value + data.typedData.value, ); const broadcastResult = await lensClient.transaction.broadcastOnChain({ @@ -36,7 +36,7 @@ async function main() { } console.log( - `Transaction to follow ${profileToUnfollowId} was successfuly broadcasted with txId ${followBroadcastResultValue.txId}` + `Transaction to follow ${profileToUnfollowId} was successfuly broadcasted with txId ${followBroadcastResultValue.txId}`, ); // wait for follow to be indexed @@ -51,7 +51,7 @@ async function main() { console.log(`Just followed profile`, { id: justFollowedProfile.id, handle: justFollowedProfile.handle, - isFollowedByMe: justFollowedProfile.isFollowedByMe, + isFollowedByMe: justFollowedProfile.operations.isFollowedByMe, }); } diff --git a/examples/node/scripts/modules.ts b/examples/node/scripts/modules.ts deleted file mode 100644 index e8adfc1513..0000000000 --- a/examples/node/scripts/modules.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { CollectModules, FollowModules, ReferenceModules } from "@lens-protocol/client"; -import { getAuthenticatedClient } from "./shared/getAuthenticatedClient"; -import { setupWallet } from "./shared/setupWallet"; - -async function main() { - const wallet = setupWallet(); - const lensClient = await getAuthenticatedClient(wallet); - - const currenciesResult = await lensClient.modules.fetchEnabledCurrencies(); - const currencies = currenciesResult.unwrap(); - - console.log("Enabled currencies: ", currencies.map((c) => c.symbol).join(", ")); - - const modulesResult = await lensClient.modules.fetchEnabled(); - const modules = modulesResult.unwrap(); - - console.log( - "\nEnabled collect modules: ", - modules.collectModules.map((m) => m.moduleName).join(", ") - ); - console.log( - "\nEnabled follow modules: ", - modules.followModules.map((m) => m.moduleName).join(", ") - ); - console.log( - "\nEnabled reference modules: ", - modules.referenceModules.map((m) => m.moduleName).join(", ") - ); - - const allowanceResult = await lensClient.modules.approvedAllowanceAmount({ - currencies: currencies.map((c) => c.address), - collectModules: [CollectModules.LimitedFeeCollectModule], - followModules: [FollowModules.FeeFollowModule], - referenceModules: [ReferenceModules.FollowerOnlyReferenceModule], - }); - - console.log("\nApproved allowance amount: ", allowanceResult.unwrap()); - - const approvalDataResult = await lensClient.modules.generateCurrencyApprovalData({ - currency: currencies[0].address, - value: "10", - collectModule: CollectModules.LimitedFeeCollectModule, - }); - - console.log("\nApproval data: ", approvalDataResult.unwrap()); -} - -main(); diff --git a/examples/node/scripts/nfts.ts b/examples/node/scripts/nfts.ts deleted file mode 100644 index 4df7d3e0e8..0000000000 --- a/examples/node/scripts/nfts.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { getActiveProfile } from "./shared/getActiveProfile"; -import { getAuthenticatedClient } from "./shared/getAuthenticatedClient"; -import { setupWallet } from "./shared/setupWallet"; - -async function main() { - const wallet = setupWallet(); - const address = await wallet.getAddress(); - const lensClient = await getAuthenticatedClient(wallet); - const profile = await getActiveProfile(lensClient, address); - const profileId = profile.id; - - const allNfts = await lensClient.nfts.fetch({ - chainIds: [80001], - ownerAddress: profile.ownedBy, - }); - - const nftsForGallery = allNfts.items.slice(0, 3).map((i) => ({ - contractAddress: i.contractAddress, - tokenId: i.tokenId, - chainId: i.chainId, - })); - - console.log("First 3 of your NFTs: ", nftsForGallery); - - const createGalleryResult = await lensClient.nfts.createGallery({ - profileId, - name: "test gallery", - items: nftsForGallery, - }); - - console.log("Gallery created with result: ", createGalleryResult); - - const fetchGalleriesResult = await lensClient.nfts.fetchGalleries({ - profileId, - }); - - console.log("Your NFT galleries: ", fetchGalleriesResult); -} - -main(); diff --git a/examples/node/scripts/pagination.ts b/examples/node/scripts/pagination.ts deleted file mode 100644 index 334b1ebc8d..0000000000 --- a/examples/node/scripts/pagination.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { LensClient, PublicationTypes, development } from "@lens-protocol/client"; - -async function main() { - const lensClient = new LensClient({ - environment: development, - }); - - const profileId = "0x53a8"; - - console.log(`Fetching all publications of profile: ${profileId} \n`); - - const pagination = await lensClient.publication.fetchAll({ - publicationTypes: [PublicationTypes.Post], - profileId, - limit: 2, - }); - - const publications = pagination.items; // first page items - - while (pagination.pageInfo.next) { - console.log(`Fetching page for cursor: ${pagination.pageInfo.next}`); - - const nextPage = await pagination.next(); - publications.push(...nextPage.items); - } - - console.log( - `\nAll publications of profile: ${profileId}`, - publications.map((i) => ({ - id: i.id, - })) - ); -} - -main(); diff --git a/examples/node/scripts/profile/changeProfileManagers.ts b/examples/node/scripts/profile/changeProfileManagers.ts index 75ae90eac1..e288cdc4b7 100644 --- a/examples/node/scripts/profile/changeProfileManagers.ts +++ b/examples/node/scripts/profile/changeProfileManagers.ts @@ -1,6 +1,7 @@ -import { ChangeProfileManagerActionType } from "@lens-protocol/client/src/graphql/types.generated"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { ChangeProfileManagerActionType, isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -11,7 +12,7 @@ async function main() { changeManagers: [ { action: ChangeProfileManagerActionType.Add, - address: "0x0000000000", + address: '0x0000000000', }, ], }); @@ -22,7 +23,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( typedData.domain, typedData.types, - typedData.value + typedData.value, ); // broadcast onchain @@ -33,13 +34,13 @@ async function main() { const onchainRelayResult = broadcastOnchainResult.unwrap(); - if (onchainRelayResult.__typename === "RelayError") { - console.log(`Something went wrong`); + if (!isRelaySuccess(onchainRelayResult)) { + console.log(`Something went wrong`, onchainRelayResult); return; } console.log( - `Successfully changed profile managers with transaction with id ${onchainRelayResult}, txHash: ${onchainRelayResult.txHash}` + `Successfully changed profile managers with transaction with id ${onchainRelayResult.txId}, txHash: ${onchainRelayResult.txHash}`, ); } diff --git a/examples/node/scripts/profile/checkIfProfileManagerIsEnabled.ts b/examples/node/scripts/profile/checkIfProfileManagerIsEnabled.ts index 7351492251..cf5d934414 100644 --- a/examples/node/scripts/profile/checkIfProfileManagerIsEnabled.ts +++ b/examples/node/scripts/profile/checkIfProfileManagerIsEnabled.ts @@ -1,18 +1,18 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const profile = await lensClient.profile.fetch({ - profileId: ["your-profile-id"], + profileId: 'your-profile-id', }); if (profile.gasless.enabled) { - console.log("Profile manager is enabled"); + console.log('Profile manager is enabled'); } else { - console.log("Profile manager is disabled"); + console.log('Profile manager is disabled'); } } diff --git a/examples/node/scripts/profile/createProfile.ts b/examples/node/scripts/profile/createProfile.ts index 08da8069d1..251d2c248d 100644 --- a/examples/node/scripts/profile/createProfile.ts +++ b/examples/node/scripts/profile/createProfile.ts @@ -1,6 +1,7 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -13,23 +14,20 @@ async function main() { const profileCreateResult = await lensClient.profile.create({ handle: handle, - to: "YOUR_EVM_ADDRESS", + to: 'YOUR_EVM_ADDRESS', }); - // profileCreateResult is a Result object - const profileCreateResultValue = profileCreateResult.unwrap(); - - if (!isRelaySuccess(profileCreateResultValue)) { - console.log(`Something went wrong`, profileCreateResultValue); + if (!isRelaySuccess(profileCreateResult)) { + console.log(`Something went wrong`, profileCreateResult); return; } console.log( - `Transaction to create a new profile with handle "${handle}" was successfuly broadcasted with txId ${profileCreateResultValue.txId}` + `Transaction to create a new profile with handle "${handle}" was successfuly broadcasted with txId ${profileCreateResult.txId}`, ); console.log(`Waiting for the transaction to be indexed...`); - await lensClient.transaction.waitUntilComplete({ txId: profileCreateResultValue.txId }); + await lensClient.transaction.waitUntilComplete({ txId: profileCreateResult.txId }); const allOwnedProfiles = await lensClient.profile.fetchAll({ where: { @@ -39,7 +37,7 @@ async function main() { console.log( `All owned profiles: `, - allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })) + allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })), ); const newProfile = allOwnedProfiles.items.find((item) => item.handle === `${handle}.test`); diff --git a/examples/node/scripts/profile/fetchProfile.ts b/examples/node/scripts/profile/fetchProfile.ts index 84343c7e3d..60325b2ecd 100644 --- a/examples/node/scripts/profile/fetchProfile.ts +++ b/examples/node/scripts/profile/fetchProfile.ts @@ -1,4 +1,4 @@ -import { LensClient, development } from "@lens-protocol/client"; +import { LensClient, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -7,14 +7,14 @@ async function main() { // by id const profileById = await lensClient.profile.fetch({ - profileId: "0x0635", + profileId: '0x0635', }); console.log(`Profile fetched by id: `, { id: profileById.id, handle: profileById.handle }); // by handle const profileByHandle = await lensClient.profile.fetch({ - handle: "lensprotocol.test", + handle: 'lensprotocol.test', }); console.log(`Profile fetched by handle: `, { diff --git a/examples/node/scripts/profile/fetchProfiles.ts b/examples/node/scripts/profile/fetchProfiles.ts index 5496af5eff..9adf6955d8 100644 --- a/examples/node/scripts/profile/fetchProfiles.ts +++ b/examples/node/scripts/profile/fetchProfiles.ts @@ -1,4 +1,4 @@ -import { LensClient, development } from "@lens-protocol/client"; +import { LensClient, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -7,63 +7,63 @@ async function main() { // by list of profile ids const profilesById = await lensClient.profile.fetchAll({ - where: { profileIds: ["0x0635"] }, + where: { profileIds: ['0x0635'] }, }); console.log( `Profiles fetched by ids: `, - profilesById.items.map((i) => ({ id: i.id, handle: i.handle })) + profilesById.items.map((i) => ({ id: i.id, handle: i.handle })), ); // by wallet address profiles are owned by - const address = "0xe3D871d389BF78c091E29deCe83200E9d6B2B0C2"; + const address = '0xe3D871d389BF78c091E29deCe83200E9d6B2B0C2'; const allOwnedProfiles = await lensClient.profile.fetchAll({ where: { ownedBy: [address] }, }); console.log( `Profiles owned by address: ${address}: `, - allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })) + allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })), ); // by a list of Lens handles const profilesByHandle = await lensClient.profile.fetchAll({ - where: { handles: ["lensprotocol.test"] }, + where: { handles: ['lensprotocol.test'] }, }); console.log( `Profiles fetched by handles: `, - profilesByHandle.items.map((i) => ({ id: i.id, handle: i.handle })) + profilesByHandle.items.map((i) => ({ id: i.id, handle: i.handle })), ); // by which profiles have mirrored a publication const profilesWhoMirroredPublicationId = await lensClient.profile.fetchAll({ - where: { whoMirroredPublication: "0x0635-0x0f" }, + where: { whoMirroredPublication: '0x0635-0x0f' }, }); console.log( `Profiles who mirrored publication: `, - profilesWhoMirroredPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })) + profilesWhoMirroredPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })), ); // by which profiles have quoted a publication const profilesWhoQuotedPublicationId = await lensClient.profile.fetchAll({ - where: { whoQuotedPublication: "0x0635-0x0f" }, + where: { whoQuotedPublication: '0x0635-0x0f' }, }); console.log( `Profiles who quoted publication: `, - profilesWhoQuotedPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })) + profilesWhoQuotedPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })), ); // by which profiles have commented on a publication const profilesWhoCommentedPublicationId = await lensClient.profile.fetchAll({ - where: { whoCommentedOn: "0x0635-0x0f" }, + where: { whoCommentedOn: '0x0635-0x0f' }, }); console.log( `Profiles who commented publication: `, - profilesWhoCommentedPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })) + profilesWhoCommentedPublicationId.items.map((i) => ({ id: i.id, handle: i.handle })), ); } diff --git a/examples/node/scripts/profile/interests.ts b/examples/node/scripts/profile/interests.ts index 3e89805316..2e0b0029e4 100644 --- a/examples/node/scripts/profile/interests.ts +++ b/examples/node/scripts/profile/interests.ts @@ -1,4 +1,4 @@ -import { LensClient, development } from "@lens-protocol/client"; +import { LensClient, ProfileInterestTypes, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -7,19 +7,19 @@ async function main() { // add interests await lensClient.profile.addInterests({ - interests: ["TECHNOLOGY", "HEALTH_FITNESS__EXERCISE"], + interests: [ProfileInterestTypes.Technology, ProfileInterestTypes.HealthFitnessExercise], }); // fetch all interests const { interests } = await lensClient.profile.fetch({ - profileId: "PROFILE_ID", + profileId: 'PROFILE_ID', }); console.log(`Profile interests`, interests); // remove interests await lensClient.profile.removeInterests({ - interests: ["HEALTH_FITNESS__EXERCISE"], + interests: [ProfileInterestTypes.Technology], }); } diff --git a/examples/node/scripts/profile/profileRecommendations.ts b/examples/node/scripts/profile/profileRecommendations.ts index 1f52ddfaa0..7f2a47bfd8 100644 --- a/examples/node/scripts/profile/profileRecommendations.ts +++ b/examples/node/scripts/profile/profileRecommendations.ts @@ -1,5 +1,5 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -7,12 +7,12 @@ async function main() { // fetch recommendations for a profile id const recommendedProfiles = await lensClient.profile.recommendations({ - for: "PROFILE_ID", + for: 'PROFILE_ID', }); console.log( `Recommended profiles: `, - recommendedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })) + recommendedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })), ); // dismiss one of the recommendations @@ -23,12 +23,12 @@ async function main() { // and fetch recommendations again const newRecommendedProfiles = await lensClient.profile.recommendations({ - for: "PROFILE_ID", + for: 'PROFILE_ID', }); console.log( `Recommended profiles after dismissing: `, - newRecommendedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })) + newRecommendedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })), ); } diff --git a/examples/node/scripts/profile/profileStats.ts b/examples/node/scripts/profile/profileStats.ts index 83b7b7dc21..6e06eb62d2 100644 --- a/examples/node/scripts/profile/profileStats.ts +++ b/examples/node/scripts/profile/profileStats.ts @@ -1,53 +1,62 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; import { CustomFiltersType, OpenActionCategoryType, OpenActionModuleType, -} from "@lens-protocol/client/src/graphql/types.generated"; +} from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); // stats across the whole protocol - const protocolWideStats = await lensClient.profile.stats({ profileId: "PROFILE_ID" }); + const protocolWideStats = await lensClient.profile.stats({ profileId: 'PROFILE_ID' }); + + console.log('Result: ', protocolWideStats); // stats for a specified apps const statsForSpecifiedApps = await lensClient.profile.stats( { - profileId: "PROFILE_ID", + profileId: 'PROFILE_ID', }, - { profileStatsArg: { forApps: ["APP_ID", "ANOTHER_APP_ID"] } } + { profileStatsArg: { forApps: ['APP_ID', 'ANOTHER_APP_ID'] } }, ); + console.log('Result: ', statsForSpecifiedApps); + // filter open actions const filteredOpenActions = await lensClient.profile.stats( { - profileId: "PROFILE_ID", + profileId: 'PROFILE_ID', }, { profileStatsCountOpenActionArgs: { anyOf: [ { - address: "0x00", + address: '0x00', type: OpenActionModuleType.SimpleCollectOpenActionModule, category: OpenActionCategoryType.Collect, }, ], }, - } + }, ); + console.log('Result: ', filteredOpenActions); + // stats for a specified app and with custom filters const customFilteredStats = await lensClient.profile.stats( { - profileId: "PROFILE_ID", + profileId: 'PROFILE_ID', }, { - profileStatsArg: { forApps: ["APP_ID"], customFilters: [CustomFiltersType.Gardeners] }, - } + profileStatsArg: { forApps: ['APP_ID'], customFilters: [CustomFiltersType.Gardeners] }, + }, ); + + console.log('Result: ', customFilteredStats); } main(); diff --git a/examples/node/scripts/profile/setProfileMetadataViaLensManager.ts b/examples/node/scripts/profile/setProfileMetadataViaLensManager.ts index a2bdc444dc..f0bbd6570d 100644 --- a/examples/node/scripts/profile/setProfileMetadataViaLensManager.ts +++ b/examples/node/scripts/profile/setProfileMetadataViaLensManager.ts @@ -1,13 +1,14 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const result = await lensClient.profile.setProfileMetadata({ - metadataURI: "metadata-uri", + metadataURI: 'metadata-uri', }); const data = result.unwrap(); diff --git a/examples/node/scripts/profile/setProfileMetadataViaTypedData.ts b/examples/node/scripts/profile/setProfileMetadataViaTypedData.ts index 58ad811579..eeff99bddf 100644 --- a/examples/node/scripts/profile/setProfileMetadataViaTypedData.ts +++ b/examples/node/scripts/profile/setProfileMetadataViaTypedData.ts @@ -1,14 +1,14 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; -import { LensTransactionStatusType } from "@lens-protocol/client/src/graphql/types.generated"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const typedDataResult = await lensClient.profile.createOnChainSetProfileMetadataTypedData({ - metadataURI: "your-metadata-uri", + metadataURI: 'your-metadata-uri', }); // typedDataResult is a Result object @@ -18,7 +18,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( data.typedData.domain, data.typedData.types, - data.typedData.value + data.typedData.value, ); // broadcast diff --git a/examples/node/scripts/publication/commentOnChain.ts b/examples/node/scripts/publication/commentOnChain.ts index a30c936ec0..2289a8c670 100644 --- a/examples/node/scripts/publication/commentOnChain.ts +++ b/examples/node/scripts/publication/commentOnChain.ts @@ -1,14 +1,15 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.commentOnChain({ - commentOn: "0x123-0x456", - contentURI: "ipfs://Qm...", // or arweave + commentOn: '0x123-0x456', + contentURI: 'ipfs://Qm...', // or arweave }); const resultValue = result.unwrap(); diff --git a/examples/node/scripts/publication/createMomokaPostTypedData.ts b/examples/node/scripts/publication/createMomokaPostTypedData.ts index c9a5cbf691..cfea65d6a6 100644 --- a/examples/node/scripts/publication/createMomokaPostTypedData.ts +++ b/examples/node/scripts/publication/createMomokaPostTypedData.ts @@ -1,13 +1,14 @@ -import { isCreateMomokaPublicationResult } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isCreateMomokaPublicationResult } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const lensClient = await getAuthenticatedClientFromEthersWallet(wallet); const typedDataResult = await lensClient.publication.createMomokaPostTypedData({ - contentURI: "ipfs://Qm...", // or arweave + contentURI: 'ipfs://Qm...', // or arweave }); const { id, typedData } = typedDataResult.unwrap(); @@ -16,7 +17,7 @@ async function main() { const signedTypedData = await wallet._signTypedData( typedData.domain, typedData.types, - typedData.value + typedData.value, ); const broadcastResult = await lensClient.transaction.broadcastOnMomoka({ diff --git a/examples/node/scripts/publication/createOnChainPostTypedData.ts b/examples/node/scripts/publication/createOnChainPostTypedData.ts index e1c2b6d9fd..604d09dc3a 100644 --- a/examples/node/scripts/publication/createOnChainPostTypedData.ts +++ b/examples/node/scripts/publication/createOnChainPostTypedData.ts @@ -1,4 +1,5 @@ import { isRelaySuccess } from '@lens-protocol/client'; + import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; import { setupWallet } from '../shared/setupWallet'; diff --git a/examples/node/scripts/publication/fetchAll.ts b/examples/node/scripts/publication/fetchAll.ts index 890d43b589..728d3c3bc2 100644 --- a/examples/node/scripts/publication/fetchAll.ts +++ b/examples/node/scripts/publication/fetchAll.ts @@ -1,11 +1,11 @@ -import { LensClient, development, isPostPublication } from "@lens-protocol/client"; +import { LensClient, development, isPostPublication } from '@lens-protocol/client'; async function main() { const client = new LensClient({ environment: development, }); - const profileId = "0x0635"; + const profileId = '0x0635'; const result = await client.publication.fetchAll({ where: { from: [profileId], @@ -16,7 +16,7 @@ async function main() { `All publications from profileId ${profileId}: `, result.items.map((p) => ({ id: p.id, - })) + })), ); const posts = result.items.filter(isPostPublication); @@ -29,8 +29,8 @@ async function main() { metadata: i.metadata, })), null, - 2 - ) + 2, + ), ); } diff --git a/examples/node/scripts/publication/hide.ts b/examples/node/scripts/publication/hide.ts index 2ea61a291c..96444034a3 100644 --- a/examples/node/scripts/publication/hide.ts +++ b/examples/node/scripts/publication/hide.ts @@ -1,5 +1,5 @@ -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); @@ -9,7 +9,7 @@ async function main() { // hide one of them const result = await client.publication.hide({ - for: "0x014e-0x0a", + for: '0x014e-0x0a', }); console.log(`Publication was hidden: `, result); diff --git a/examples/node/scripts/publication/mirrorOnChain.ts b/examples/node/scripts/publication/mirrorOnChain.ts index c2c6d435f6..3e2c15413c 100644 --- a/examples/node/scripts/publication/mirrorOnChain.ts +++ b/examples/node/scripts/publication/mirrorOnChain.ts @@ -1,13 +1,14 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.mirrorOnChain({ - mirrorOn: "0x123-0x456", + mirrorOn: '0x123-0x456', }); const resultValue = result.unwrap(); diff --git a/examples/node/scripts/publication/postOnChain.ts b/examples/node/scripts/publication/postOnChain.ts index 2a476806fb..6f5f720936 100644 --- a/examples/node/scripts/publication/postOnChain.ts +++ b/examples/node/scripts/publication/postOnChain.ts @@ -1,13 +1,14 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.postOnChain({ - contentURI: "ipfs://Qm...", // or arweave + contentURI: 'ipfs://Qm...', // or arweave referenceModule: { followerOnlyReferenceModule: false, // anybody can comment or mirror }, diff --git a/examples/node/scripts/publication/postOnMomoka.ts b/examples/node/scripts/publication/postOnMomoka.ts index e876e93864..371ec40822 100644 --- a/examples/node/scripts/publication/postOnMomoka.ts +++ b/examples/node/scripts/publication/postOnMomoka.ts @@ -1,13 +1,14 @@ -import { isCreateMomokaPublicationResult } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isCreateMomokaPublicationResult } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.postOnMomoka({ - contentURI: "ipfs://Qm...", // or arweave + contentURI: 'ipfs://Qm...', // or arweave }); const resultValue = result.unwrap(); diff --git a/examples/node/scripts/publication/quoteOnChain.ts b/examples/node/scripts/publication/quoteOnChain.ts index 2256d22bfd..bd50463bd5 100644 --- a/examples/node/scripts/publication/quoteOnChain.ts +++ b/examples/node/scripts/publication/quoteOnChain.ts @@ -1,14 +1,15 @@ -import { isRelaySuccess } from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +import { isRelaySuccess } from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.quoteOnChain({ - quoteOn: "0x123-0x456", - contentURI: "ipfs://Qm...", // or arweave + quoteOn: '0x123-0x456', + contentURI: 'ipfs://Qm...', // or arweave }); const resultValue = result.unwrap(); diff --git a/examples/node/scripts/publication/reactions/addReaction.ts b/examples/node/scripts/publication/reactions/addReaction.ts index 93d3f3b9a9..d18af13ca2 100644 --- a/examples/node/scripts/publication/reactions/addReaction.ts +++ b/examples/node/scripts/publication/reactions/addReaction.ts @@ -1,4 +1,4 @@ -import { LensClient, PublicationReactionType, development } from "@lens-protocol/client"; +import { LensClient, PublicationReactionType, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -7,7 +7,7 @@ async function main() { const feedResult = await lensClient.feed.fetch({ where: { - for: "PROFILE_ID", + for: 'PROFILE_ID', }, }); @@ -22,7 +22,7 @@ async function main() { // add reaction await lensClient.publication.reactions.add({ - for: "PUBLICATION_ID", + for: 'PUBLICATION_ID', reaction: PublicationReactionType.Upvote, }); diff --git a/examples/node/scripts/publication/reactions/fetch.ts b/examples/node/scripts/publication/reactions/fetch.ts index 2d5a48242b..6a8266771a 100644 --- a/examples/node/scripts/publication/reactions/fetch.ts +++ b/examples/node/scripts/publication/reactions/fetch.ts @@ -1,4 +1,4 @@ -import { LensClient, LimitType, PublicationReactionType, development } from "@lens-protocol/client"; +import { LensClient, LimitType, PublicationReactionType, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -6,21 +6,21 @@ async function main() { }); const profilesWhoReacted = await lensClient.publication.reactions.fetch({ - for: "PUBLICATION_ID", + for: 'PUBLICATION_ID', limit: LimitType.TwentyFive, }); console.log( - `Profiles who reacted to publication: ${JSON.stringify(profilesWhoReacted, null, 2)}` + `Profiles who reacted to publication: ${JSON.stringify(profilesWhoReacted, null, 2)}`, ); await lensClient.publication.reactions.add({ - for: "PUBLICATION_ID", + for: 'PUBLICATION_ID', reaction: PublicationReactionType.Upvote, }); const profilesWhoReactedAfterUpvote = await lensClient.publication.reactions.fetch({ - for: "PUBLICATION_ID", + for: 'PUBLICATION_ID', limit: LimitType.TwentyFive, }); @@ -28,8 +28,8 @@ async function main() { `Profiles who reacted to publication after upvote: ${JSON.stringify( profilesWhoReactedAfterUpvote, null, - 2 - )}` + 2, + )}`, ); } diff --git a/examples/node/scripts/publication/reactions/removeReaction.ts b/examples/node/scripts/publication/reactions/removeReaction.ts index 25540642db..c2a500f90d 100644 --- a/examples/node/scripts/publication/reactions/removeReaction.ts +++ b/examples/node/scripts/publication/reactions/removeReaction.ts @@ -1,4 +1,4 @@ -import { LensClient, PublicationReactionType, development } from "@lens-protocol/client"; +import { LensClient, PublicationReactionType, development } from '@lens-protocol/client'; async function main() { const lensClient = new LensClient({ @@ -7,7 +7,7 @@ async function main() { const feedResult = await lensClient.feed.fetch({ where: { - for: "PROFILE_ID", + for: 'PROFILE_ID', }, }); @@ -22,7 +22,7 @@ async function main() { // add reaction await lensClient.publication.reactions.remove({ - for: "PUBLICATION_ID", + for: 'PUBLICATION_ID', reaction: PublicationReactionType.Upvote, }); diff --git a/examples/node/scripts/publication/report.ts b/examples/node/scripts/publication/report.ts index 5131cf25c2..34a263ee84 100644 --- a/examples/node/scripts/publication/report.ts +++ b/examples/node/scripts/publication/report.ts @@ -1,23 +1,24 @@ import { PublicationReportingReason, PublicationReportingSpamSubreason, -} from "@lens-protocol/client"; -import { getAuthenticatedClientFromEthersWallet } from "../shared/getAuthenticatedClient"; -import { setupWallet } from "../shared/setupWallet"; +} from '@lens-protocol/client'; + +import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient'; +import { setupWallet } from '../shared/setupWallet'; async function main() { const wallet = setupWallet(); const client = await getAuthenticatedClientFromEthersWallet(wallet); const result = await client.publication.report({ - for: "0x014e-0x0a", + for: '0x014e-0x0a', reason: { spamReason: { reason: PublicationReportingReason.Spam, subreason: PublicationReportingSpamSubreason.FakeEngagement, }, }, - additionalComments: "comment", + additionalComments: 'comment', }); console.log(`Publication was hidden: `, result); diff --git a/examples/node/scripts/publication/stats.ts b/examples/node/scripts/publication/stats.ts index 0e611c93d9..c781ed57c1 100644 --- a/examples/node/scripts/publication/stats.ts +++ b/examples/node/scripts/publication/stats.ts @@ -1,4 +1,4 @@ -import { LensClient, development } from "@lens-protocol/client"; +import { LensClient, development } from '@lens-protocol/client'; async function main() { const client = new LensClient({ @@ -7,7 +7,7 @@ async function main() { const result = await client.publication.stats({ request: { - for: "0x123", + for: '0x123', }, }); diff --git a/examples/node/scripts/publication/tags.ts b/examples/node/scripts/publication/tags.ts index b8c0e9d4f0..5f225924c5 100644 --- a/examples/node/scripts/publication/tags.ts +++ b/examples/node/scripts/publication/tags.ts @@ -1,4 +1,4 @@ -import { LensClient, development } from "@lens-protocol/client"; +import { LensClient, development } from '@lens-protocol/client'; async function main() { const client = new LensClient({ diff --git a/examples/node/scripts/publication/validateMetadata.ts b/examples/node/scripts/publication/validateMetadata.ts index 878d83585f..a46ed3ebb9 100644 --- a/examples/node/scripts/publication/validateMetadata.ts +++ b/examples/node/scripts/publication/validateMetadata.ts @@ -1,12 +1,11 @@ -import { LensClient, development } from "@lens-protocol/client"; -import { buildPublicationMetadata } from "../shared/buildPublicationMetadata"; +import { LensClient, development } from '@lens-protocol/client'; async function main() { const client = new LensClient({ environment: development, }); - const metadata = buildPublicationMetadata(); + const metadata = {}; const result = await client.publication.validateMetadata(metadata); diff --git a/examples/node/scripts/shared/buildPublicationMetadata.ts b/examples/node/scripts/shared/buildPublicationMetadata.ts deleted file mode 100644 index 673369d120..0000000000 --- a/examples/node/scripts/shared/buildPublicationMetadata.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - PublicationMainFocus, - PublicationMetadataDisplayTypes, - PublicationMetadataV2Input, -} from "@lens-protocol/client"; -import { v4 } from "uuid"; - -export function buildPublicationMetadata( - meta: Partial = {} -): PublicationMetadataV2Input { - return { - appId: "lenster", - attributes: [ - { - displayType: PublicationMetadataDisplayTypes.String, - traitType: "Created with", - value: "LensClient SDK", - }, - ], - content: "Post created with LensClient SDK", - description: "Description of the post created with LensClient SDK", - locale: "en-US", - mainContentFocus: PublicationMainFocus.TextOnly, - metadata_id: v4(), - name: "Post created with LensClient SDK", - tags: ["lens-sdk"], - version: "2.0.0", - ...meta, - }; -} diff --git a/examples/node/scripts/shared/getActiveProfile.ts b/examples/node/scripts/shared/getActiveProfile.ts deleted file mode 100644 index daf7cf874d..0000000000 --- a/examples/node/scripts/shared/getActiveProfile.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { LensClient, ProfileFragment } from "@lens-protocol/client"; - -export async function getActiveProfile( - client: LensClient, - walletAddress: string -): Promise { - const ownedProfiles = await client.profile.fetchAll({ - ownedBy: [walletAddress], - limit: 1, - }); - - if (ownedProfiles.items.length === 0) { - throw new Error(`You don't have any profiles, create one first`); - } - - return ownedProfiles.items[0]; -} diff --git a/examples/node/scripts/shared/getAuthenticatedClient.ts b/examples/node/scripts/shared/getAuthenticatedClient.ts index 487ec61cfb..73e4655e23 100644 --- a/examples/node/scripts/shared/getAuthenticatedClient.ts +++ b/examples/node/scripts/shared/getAuthenticatedClient.ts @@ -1,6 +1,6 @@ -import { LensClient, development } from "@lens-protocol/client"; -import { Wallet } from "ethers"; -import { WalletClient } from "viem"; +import { LensClient, development } from '@lens-protocol/client'; +import { Wallet } from 'ethers'; +import { WalletClient } from 'viem'; export async function getAuthenticatedClientFromEthersWallet(wallet: Wallet): Promise { const lensClient = new LensClient({ @@ -11,7 +11,7 @@ export async function getAuthenticatedClientFromEthersWallet(wallet: Wallet): Pr const { id, text } = await lensClient.authentication.generateChallenge({ address, - profileId: "0x001", + profileId: '0x001', }); const signature = await wallet.signMessage(text); @@ -29,7 +29,7 @@ export async function getAuthenticatedClientFromViemWalletClient(walletClient: W const { id, text } = await lensClient.authentication.generateChallenge({ address, - profileId: "0x001", + profileId: '0x001', }); const signature = await walletClient.signMessage({ account: address, message: text }); @@ -37,13 +37,3 @@ export async function getAuthenticatedClientFromViemWalletClient(walletClient: W return lensClient; } - -export async function refreshJWT(accessToken: string) { - const lensClient = new LensClient({ - environment: development, - }); - - const newAccessToken = await lensClient.authentication.getAccessToken(); - - return newAccessToken; -} diff --git a/examples/node/scripts/shared/setupWallet.ts b/examples/node/scripts/shared/setupWallet.ts index 536c1587bd..a78414bb01 100644 --- a/examples/node/scripts/shared/setupWallet.ts +++ b/examples/node/scripts/shared/setupWallet.ts @@ -1,11 +1,11 @@ -import * as dotenv from "dotenv"; -import { Wallet } from "ethers"; +import * as dotenv from 'dotenv'; +import { Wallet } from 'ethers'; dotenv.config(); export function setupWallet(): Wallet { if (!process.env.WALLET_PRIVATE_KEY) { - throw new Error("Private key is not defined in .env file"); + throw new Error('Private key is not defined in .env file'); } return new Wallet(process.env.WALLET_PRIVATE_KEY); diff --git a/examples/node/scripts/shared/signAndBroadcast.ts b/examples/node/scripts/shared/signAndBroadcast.ts index f1d0d68050..538bad873f 100644 --- a/examples/node/scripts/shared/signAndBroadcast.ts +++ b/examples/node/scripts/shared/signAndBroadcast.ts @@ -1,18 +1,17 @@ -import { LensClient, Result } from "@lens-protocol/client"; -import { Wallet } from "ethers"; +import { IEquatableError, LensClient, Result, TypedDataResponse } from '@lens-protocol/client'; +import { Wallet } from 'ethers'; -export async function signAndBroadcast( - client: LensClient, - wallet: Wallet, - result: Result -) { +export async function signAndBroadcast< + T extends TypedDataResponse, + E extends IEquatableError, +>(client: LensClient, wallet: Wallet, result: Result) { const data = result.unwrap(); // sign with the wallet const signedTypedData = await wallet._signTypedData( data.typedData.domain, data.typedData.types, - data.typedData.value + data.typedData.value, ); const broadcastResult = await client.transaction.broadcastOnChain({ diff --git a/examples/node/scripts/shared/uploadWithBundlr.ts b/examples/node/scripts/shared/uploadWithBundlr.ts deleted file mode 100644 index 842e3b4878..0000000000 --- a/examples/node/scripts/shared/uploadWithBundlr.ts +++ /dev/null @@ -1,27 +0,0 @@ -import Bundlr from "@bundlr-network/client"; -import { walletPrivateKey } from "./setupWallet"; - -export async function uploadWithBundlr(data: { [key: string]: unknown }): Promise { - const bundlr = new Bundlr("https://devnet.bundlr.network", "matic", walletPrivateKey, { - providerUrl: "https://rpc-mumbai.maticvigil.com/", - }); - - const atomicBalance = await bundlr.getLoadedBalance(); - const balance = bundlr.utils.unitConverter(atomicBalance); - - console.log(`Bundlr balance for wallet ${bundlr.address} is ${balance.toString()} MUMBAI MATIC`); - - // fund bundlr balance if empty - if (balance.eq(0)) { - console.log("Trying to fund your Bundlr balance with 0.1 MUMBAI MATIC"); - - await bundlr.fund(0.1e18); // 0.1 MUMBAI MATIC - } - - const serialized = JSON.stringify(data); - const tx = await bundlr.upload(serialized, { - tags: [{ name: "Content-Type", value: "application/json" }], - }); - - return `https://arweave.net/${tx.id}`; -} diff --git a/examples/node/scripts/verifyToken.ts b/examples/node/scripts/verifyToken.ts deleted file mode 100644 index 00d164f9d4..0000000000 --- a/examples/node/scripts/verifyToken.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { LensClient, development } from "@lens-protocol/client"; - -async function main() { - const lensClient = new LensClient({ - environment: development, - }); - - const accessToken = "YOUR_ACCESS_TOKEN"; - - const isVerified = await lensClient.authentication.verify(accessToken); - - console.log(`Token is ${isVerified ? "valid" : "invalid"}`); -} - -main(); diff --git a/examples/node/tsconfig.json b/examples/node/tsconfig.json index 9b4132cb28..37226effbe 100644 --- a/examples/node/tsconfig.json +++ b/examples/node/tsconfig.json @@ -1,11 +1,12 @@ { - "ts-node": { - "transpileOnly": true - }, + "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "module": "NodeNext", "target": "ESNext", "moduleResolution": "NodeNext" }, - "include": ["scripts"] + "include": ["./scripts"], + "ts-node": { + "transpileOnly": true + } } diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 9c95e4df4c..8e916039ab 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -75,4 +75,11 @@ export { PublicationReportingReason, PublicationReportingSensitiveSubreason, PublicationReportingSpamSubreason, + PublicationMetadataMainFocusType, + PublicationMarketplaceMetadataAttributeDisplayType, + ChangeProfileManagerActionType, + ProfileInterestTypes, + CustomFiltersType, + OpenActionCategoryType, + OpenActionModuleType, } from './graphql/types.generated'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c6a8b98cf..cc929eaab1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: false + excludeLinksFromLockfile: false + overrides: ganache: 7.7.4 @@ -108,12 +112,21 @@ importers: specifier: ^1.0.0 version: 1.0.0(typescript@4.9.5) devDependencies: + '@lens-protocol/eslint-config': + specifier: workspace:* + version: link:../../packages/eslint-config + '@lens-protocol/prettier-config': + specifier: workspace:* + version: link:../../packages/prettier-config '@types/node': specifier: ^18.15.11 version: 18.15.11 '@types/uuid': specifier: ^9.0.0 version: 9.0.0 + prettier: + specifier: ^2.8.4 + version: 2.8.4 ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@18.15.11)(typescript@4.9.5) @@ -4114,7 +4127,7 @@ packages: fs-extra: 7.0.1 lodash.startcase: 4.4.0 outdent: 0.5.0 - prettier: 2.8.4 + prettier: 2.8.8 resolve-from: 5.0.0 semver: 5.7.1 dev: true @@ -4282,7 +4295,7 @@ packages: '@changesets/types': 5.2.1 fs-extra: 7.0.1 human-id: 1.0.2 - prettier: 2.8.4 + prettier: 2.8.8 dev: true /@coinbase/wallet-sdk@3.6.6: @@ -21307,7 +21320,3 @@ packages: dependencies: react: 18.2.0 use-sync-external-store: 1.2.0(react@18.2.0) - -settings: - autoInstallPeers: false - excludeLinksFromLockfile: false