"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processActivityPubHttpUnicast = void 0;
const tslib_1 = require("tslib");
const send_1 = require("../../activitypub/send");
const logger_1 = require("../../../helpers/logger");
const requests_1 = require("../../../helpers/requests");
const actor_follow_health_cache_1 = require("../../actor-follow-health-cache");
function processActivityPubHttpUnicast(job) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        logger_1.logger.info('Processing ActivityPub unicast in job %s.', job.id);
        const payload = job.data;
        const uri = payload.uri;
        const body = yield (0, send_1.computeBody)(payload);
        const httpSignatureOptions = yield (0, send_1.buildSignedRequestOptions)(payload);
        const options = {
            method: 'POST',
            json: body,
            httpSignature: httpSignatureOptions,
            headers: (0, send_1.buildGlobalHeaders)(body)
        };
        try {
            yield (0, requests_1.doRequest)(uri, options);
            actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth([uri], []);
        }
        catch (err) {
            actor_follow_health_cache_1.ActorFollowHealthCache.Instance.updateActorFollowsHealth([], [uri]);
            throw err;
        }
    });
}
exports.processActivityPubHttpUnicast = processActivityPubHttpUnicast;
//# sourceMappingURL=activitypub-http-unicast.js.map