diff --git a/backend/src/activitypub/ActivityPub.ts b/backend/src/activitypub/ActivityPub.ts index 7ecc9d3fe..5f2bcd8ea 100644 --- a/backend/src/activitypub/ActivityPub.ts +++ b/backend/src/activitypub/ActivityPub.ts @@ -11,11 +11,15 @@ import { v4 as uuid } from 'uuid' import CONFIG from '../config' const debug = require('debug')('ea') -let activityPub = null +let activityPub: any = null export { activityPub } export default class ActivityPub { + endpoint: any + dataSource: any + collections: any + host: any constructor(activityPubEndpointUri, internalGraphQlUri) { this.endpoint = activityPubEndpointUri this.dataSource = new NitroDataSource(internalGraphQlUri) @@ -211,16 +215,16 @@ export default class ActivityPub { // serve the rest activity.to.map(async (recipient) => { debug('serve rest') - const actorObject = await this.getActorObject(recipient) + const actorObject: any = await this.getActorObject(recipient) return this.trySend(activity, fromName, new URL(recipient).host, actorObject.inbox) }) } else if (typeof activity.to === 'string') { debug('is string') - const actorObject = await this.getActorObject(activity.to) + const actorObject: any = await this.getActorObject(activity.to) return this.trySend(activity, fromName, new URL(activity.to).host, actorObject.inbox) } else if (Array.isArray(activity.to)) { activity.to.map(async (recipient) => { - const actorObject = await this.getActorObject(recipient) + const actorObject: any = await this.getActorObject(recipient) return this.trySend(activity, fromName, new URL(recipient).host, actorObject.inbox) }) } @@ -231,7 +235,7 @@ export default class ActivityPub { return await signAndSend(activity, fromName, host, url) } catch (e) { if (tries > 0) { - setTimeout(function () { + setTimeout(() => { return this.trySend(activity, fromName, host, url, --tries) }, 20000) } diff --git a/backend/src/activitypub/Collections.ts b/backend/src/activitypub/Collections.ts index 4040468cf..c0fd6dd71 100644 --- a/backend/src/activitypub/Collections.ts +++ b/backend/src/activitypub/Collections.ts @@ -1,4 +1,5 @@ export default class Collections { + dataSource: any constructor(dataSource) { this.dataSource = dataSource } diff --git a/backend/src/activitypub/NitroDataSource.ts b/backend/src/activitypub/NitroDataSource.ts index 476c91439..88b9ae5e9 100644 --- a/backend/src/activitypub/NitroDataSource.ts +++ b/backend/src/activitypub/NitroDataSource.ts @@ -17,15 +17,17 @@ import trunc from 'trunc-html' const debug = require('debug')('ea:datasource') export default class NitroDataSource { + uri: any + client: any constructor(uri) { this.uri = uri - const defaultOptions = { + const defaultOptions: any = { query: { fetchPolicy: 'network-only', errorPolicy: 'all', }, } - const link = createHttpLink({ uri: this.uri, fetch: fetch }) // eslint-disable-line + const link = createHttpLink({ uri: this.uri, fetch: fetch } as any) // eslint-disable-line const cache = new InMemoryCache() const authLink = setContext((_, { headers }) => { // generate the authentication token (maybe from env? Which user?) @@ -95,7 +97,7 @@ export default class NitroDataSource { const followers = actor.followedBy const followersCount = actor.followedByCount - const followersCollection = createOrderedCollectionPage(slug, 'followers') + const followersCollection: any = createOrderedCollectionPage(slug, 'followers') followersCollection.totalItems = followersCount debug(`followers = ${JSON.stringify(followers, null, 2)}`) await Promise.all( @@ -157,7 +159,7 @@ export default class NitroDataSource { const following = actor.following const followingCount = actor.followingCount - const followingCollection = createOrderedCollectionPage(slug, 'following') + const followingCollection: any = createOrderedCollectionPage(slug, 'following') followingCollection.totalItems = followingCount await Promise.all( @@ -235,7 +237,7 @@ export default class NitroDataSource { const actor = result.data.User[0] const posts = actor.contributions - const outboxCollection = createOrderedCollectionPage(slug, 'outbox') + const outboxCollection: any = createOrderedCollectionPage(slug, 'outbox') outboxCollection.totalItems = posts.length await Promise.all( posts.map(async (post) => { diff --git a/backend/src/activitypub/routes/index.ts b/backend/src/activitypub/routes/index.ts index 00ba7c22d..dc34da3ab 100644 --- a/backend/src/activitypub/routes/index.ts +++ b/backend/src/activitypub/routes/index.ts @@ -11,8 +11,8 @@ export default function () { cors(), express.json({ type: ['application/activity+json', 'application/ld+json', 'application/json'], - }), - express.urlencoded({ extended: true }), + }) as any, + express.urlencoded({ extended: true }) as any, user, ) router.use( @@ -20,8 +20,8 @@ export default function () { cors(), express.json({ type: ['application/activity+json', 'application/ld+json', 'application/json'], - }), - express.urlencoded({ extended: true }), + }) as any, + express.urlencoded({ extended: true }) as any, verify, inbox, ) diff --git a/backend/src/activitypub/routes/webfinger.ts b/backend/src/activitypub/routes/webfinger.ts index 6b8f3e14c..894314f7b 100644 --- a/backend/src/activitypub/routes/webfinger.ts +++ b/backend/src/activitypub/routes/webfinger.ts @@ -54,6 +54,6 @@ export async function handler(req, res) { export default function () { const router = express.Router() - router.use('/webfinger', cors(), express.urlencoded({ extended: true }), handler) + router.use('/webfinger', cors(), express.urlencoded({ extended: true }) as any, handler) return router } diff --git a/backend/src/activitypub/security/index.ts b/backend/src/activitypub/security/index.ts index 399bc7d9b..271aa5995 100644 --- a/backend/src/activitypub/security/index.ts +++ b/backend/src/activitypub/security/index.ts @@ -8,7 +8,7 @@ const debug = require('debug')('ea:security') // TODO Does this reference a local config? Why? // dotenv.config({ path: resolve('src', 'activitypub', '.env') }) -export function generateRsaKeyPair(options = {}) { +export function generateRsaKeyPair(options: any = {}) { const { passphrase = CONFIG.PRIVATE_KEY_PASSPHRASE } = options return crypto.generateKeyPairSync('rsa', { modulusLength: 4096, diff --git a/backend/src/activitypub/utils/activity.ts b/backend/src/activitypub/utils/activity.ts index 2199361d8..3d85d7f08 100644 --- a/backend/src/activitypub/utils/activity.ts +++ b/backend/src/activitypub/utils/activity.ts @@ -100,18 +100,19 @@ export async function getActorId(name) { // } export function isPublicAddressed(postObject) { + const result: { to: any[]} = { to: []} if (typeof postObject.to === 'string') { - postObject.to = [postObject.to] + result.to = [postObject.to] } if (typeof postObject === 'string') { - postObject.to = [postObject] + result.to = [postObject] } if (Array.isArray(postObject)) { - postObject.to = postObject + result.to = postObject } return ( - postObject.to.includes('Public') || - postObject.to.includes('as:Public') || - postObject.to.includes('https://www.w3.org/ns/activitystreams#Public') + result.to.includes('Public') || + result.to.includes('as:Public') || + result.to.includes('https://www.w3.org/ns/activitystreams#Public') ) } diff --git a/backend/src/activitypub/utils/index.ts b/backend/src/activitypub/utils/index.ts index aa3ff2101..360125f73 100644 --- a/backend/src/activitypub/utils/index.ts +++ b/backend/src/activitypub/utils/index.ts @@ -101,7 +101,7 @@ export function signAndSend(activity, fromName, targetDomain, url) { } else { debug('Response Headers:', JSON.stringify(response.headers, null, 2)) debug('Response Body:', JSON.stringify(response.body, null, 2)) - resolve() + resolve(response) } }, )