const urlJoin = require('url-join'); const { PodCollectionsHandlerMixin, PodResourcesHandlerMixin } = require('@activitypods/app'); const CONFIG = require('../config/config'); const { neverThrowingMatcher, verifiedEmit } = require('./emitted-activity'); const { guardedCreateAndAttach } = require('./collection-attach'); // Attaches an `apods:contacts` collection (and a WAC group of the same members) to the `as:Profile` // a user creates, as the platform's collection handler does — with two differences that keep the // webhook a hint (see emitted-activity.js): // - the handler runs only for a Create `verifiedEmit` accepts: re-read from the pod as the app, // attributed to the owner of the outbox the webhook fired on, its object an `as:Profile` of that // owner's pod, re-read too. The mixin's handler would act on the object embedded in the // (unauthenticated) webhook body, attributed to the activity's self-declared `actor`; // - `createAndAttach` creates no WAC group when nothing was attached (collection-attach.js). module.exports = { name: 'contacts', mixins: [PodCollectionsHandlerMixin], settings: { shapeTreeUri: urlJoin(CONFIG.SHAPE_REPOSITORY_URL, 'shapetrees/as/Profile'), attachPredicate: 'http://activitypods.org/ns/core#contacts', collectionOptions: { ordered: false, summary: 'Festipod contacts' }, createWacGroup: true }, // Replaces the mixin's whole map (moleculer does not merge a custom schema key). The mixin's // update and delete handlers are left out on purpose: they never matched here (they require an // `onUpdate` this service does not have). activities: { create: { match: neverThrowingMatcher(PodResourcesHandlerMixin.activities.create.match), onEmit: verifiedEmit( 'Create', async function (ctx, { object }, actorUri) { await this.onCreate(ctx, object, actorUri); }, { objectType: 'Profile' } ) } }, actions: { createAndAttach: guardedCreateAndAttach } };