Skip to content

Commit

Permalink
feat: eslint for examples/node
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Sep 13, 2023
1 parent a61c4db commit 529b46c
Show file tree
Hide file tree
Showing 54 changed files with 291 additions and 535 deletions.
13 changes: 13 additions & 0 deletions examples/node/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
15 changes: 13 additions & 2 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -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"
}
41 changes: 20 additions & 21 deletions examples/node/scripts/authenticate.ts
Original file line number Diff line number Diff line change
@@ -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();
64 changes: 0 additions & 64 deletions examples/node/scripts/bookmarks.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/node/scripts/explore/exploreProfiles.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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',
},
});

Expand Down
5 changes: 1 addition & 4 deletions examples/node/scripts/explore/explorePublications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ExplorePublicationsOrderByType,
LensClient,
development,
} from "@lens-protocol/client";
} from '@lens-protocol/client';

async function main() {
const lensClient = new LensClient({
Expand All @@ -16,7 +16,6 @@ async function main() {

const topCommented = await lensClient.explore.publications({
orderBy: ExplorePublicationsOrderByType.TopCommented,
limit: 10,
});

const highestMirroredPosts = await lensClient.explore.publications({
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
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`,
recommendedProfiles.items.slice(0, 3).map((p) => ({
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();
Expand Down
15 changes: 8 additions & 7 deletions examples/node/scripts/follow/followProfileViaTypedData.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
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();

const signedTypedData = await wallet._signTypedData(
data.typedData.domain,
data.typedData.types,
data.typedData.value
data.typedData.value,
);

const broadcastResult = await lensClient.transaction.broadcastOnChain({
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/node/scripts/follow/followers.ts
Original file line number Diff line number Diff line change
@@ -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),
);
}

Expand Down
8 changes: 4 additions & 4 deletions examples/node/scripts/follow/following.ts
Original file line number Diff line number Diff line change
@@ -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),
);
}

Expand Down
15 changes: 0 additions & 15 deletions examples/node/scripts/follow/isFollowedByMe.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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 });
Expand Down
Loading

0 comments on commit 529b46c

Please sign in to comment.