This commit is contained in:
Michael Puckett 2023-07-30 23:10:46 -04:00
parent 65548f96c7
commit f530d8b0d2
106 changed files with 1020 additions and 891 deletions

View File

@ -27,12 +27,10 @@ export type CoreLibrary = AuthAdapter & DbAdapter & StorageAdapter & CryptoAdapt
getStreamByName: (this: CoreLibrary, actor: AP.Actor, name: string) => Promise<AP.EitherCollection | null>;
fetchEntityById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
queryById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
expandEntity: (this: CoreLibrary, originalEntity: AP.Entity) => Promise<AP.Entity>;
getCollectionItems: (this: CoreLibrary, entity: AP.Collection | AP.OrderedCollection) => Promise<AP.EntityReference[]>;
expandEntity: (this: CoreLibrary, entity: AP.Entity) => Promise<AP.Entity>;
getCollectionItems: (this: CoreLibrary, entity: AP.Collection | AP.OrderedCollection) => AP.EntityReference[];
getPaginatedCollectionItems: (this: CoreLibrary, collection: AP.Collection | AP.OrderedCollection) => Promise<AP.EntityReference[]>;
expandCollection: (this: CoreLibrary, collection: AP.EitherCollectionReference) => Promise<null | AP.EitherCollection>;
getRecipientInboxUrls: (this: CoreLibrary, activity: AP.Activity, actor: AP.Actor, inboxesOnly?: boolean) => Promise<URL[]>;
expandCollection: (this: CoreLibrary, collection: AP.EitherCollection) => Promise<AP.EitherCollection>;
getRecipientUrls: (this: CoreLibrary, activity: AP.Activity) => Promise<URL[]>;
broadcast: (this: CoreLibrary, activity: AP.Activity, actor: AP.Actor) => Promise<unknown>;
signAndSendToForeignActorInbox: (this: CoreLibrary, foreignActorInbox: URL, actor: AP.Actor, activity: AP.Activity) => Promise<unknown>;
};

View File

@ -1,3 +1,2 @@
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function broadcast(this: Core, activity: AP.Activity, actor: AP.Actor): Promise<unknown>;
import { CoreLibrary } from './adapters';
export declare const broadcast: CoreLibrary['broadcast'];

View File

@ -3,18 +3,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.broadcast = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function broadcast(activity, actor) {
const entity = (0, utilities_1.applyContext)(activity);
type_utilities_1.assert.isApActivity(entity);
const publicActivity = (0, utilities_1.cleanProps)(entity);
if (!('actor' in publicActivity)) {
throw new Error('Not an activity?');
}
const recipients = await this.getRecipientInboxUrls(activity, actor);
const results = await Promise.all(recipients.map(async (recipient) => {
return await this.signAndSendToForeignActorInbox(recipient, actor, publicActivity);
}));
return results;
}
const broadcast = async function broadcast(activity, actor) {
const publicActivity = (0, utilities_1.convertEntityToJson)((0, utilities_1.cleanProps)((0, utilities_1.applyContext)(activity)));
const recipients = await getRecipientInboxUrls.bind(this)(activity, actor);
const send = async (recipient) => {
return await signAndSendToForeignActorInbox.bind(this)(recipient, actor, publicActivity);
};
return Object.fromEntries(await Promise.all(recipients.map(send.bind(this))));
};
exports.broadcast = broadcast;
async function signAndSendToForeignActorInbox(foreignActorInbox, actor, plainEntity) {
const actorId = (0, utilities_1.getId)(actor);
type_utilities_1.assert.exists(actorId);
const privateKey = await this.getPrivateKey(actor);
const { dateHeader, digestHeader, signatureHeader } = await this.getHttpSignature(foreignActorInbox, actorId, privateKey, plainEntity);
if (!digestHeader || !dateHeader || !signatureHeader) {
throw new Error('Failed to sign Activity');
}
const headers = {
[utilities_1.CONTENT_TYPE_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
[utilities_1.ACCEPT_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
Host: foreignActorInbox.hostname,
Date: dateHeader,
Digest: digestHeader,
Signature: signatureHeader,
};
const statusCode = await this.fetch(foreignActorInbox.href, {
method: 'post',
body: JSON.stringify(plainEntity),
headers,
})
.then(async (res) => {
return res.status;
})
.catch(() => {
return 0;
});
return [foreignActorInbox.href, statusCode];
}
async function getRecipientInboxUrls(activity, actor) {
const recipientUrls = await this.getRecipientUrls(activity);
const extractUrl = async (recipientUrl) => {
var _a;
if (recipientUrl.href === ((_a = (0, utilities_1.getId)(actor)) === null || _a === void 0 ? void 0 : _a.href)) {
return null;
}
const foundEntity = await this.fetchEntityById(recipientUrl);
if (!type_utilities_1.guard.isApActor(foundEntity)) {
return null;
}
if (foundEntity.endpoints) {
if (type_utilities_1.guard.isUrl(foundEntity.endpoints.sharedInbox)) {
return foundEntity.endpoints.sharedInbox;
}
}
return (0, utilities_1.getId)(foundEntity.inbox);
};
const recipientInboxUrls = await Promise.all(recipientUrls.map(extractUrl));
const filteredUrls = recipientInboxUrls.filter(type_utilities_1.guard.isUrl);
return (0, utilities_1.deduplicateUrls)(filteredUrls);
}
//# sourceMappingURL=broadcast.js.map

View File

@ -1 +1 @@
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":";;;AACA,iEAAsD;AACtD,uDAAmE;AAS5D,KAAK,UAAU,SAAS,CAE7B,QAAqB,EACrB,KAAe;IAEf,MAAM,MAAM,GAAG,IAAA,wBAAY,EAAY,QAAQ,CAAC,CAAC;IAEjD,uBAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAE5B,MAAM,cAAc,GAAG,IAAA,sBAAU,EAAC,MAAM,CAAC,CAAC;IAE1C,IAAI,CAAC,CAAC,OAAO,IAAI,cAAc,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KACrC;IAED,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAErE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACjC,OAAO,MAAM,IAAI,CAAC,8BAA8B,CAC9C,SAAS,EACT,KAAK,EACL,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AA5BD,8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YACzB,IAAI,sBAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;gBAClD,OAAO,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC;aAC1C;SACF;QAED,OAAO,IAAA,iBAAK,EAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;IAEF,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;IAE5E,MAAM,YAAY,GAAG,kBAAkB,CAAC,MAAM,CAAC,sBAAK,CAAC,KAAK,CAAC,CAAC;IAE5D,OAAO,IAAA,2BAAe,EAAC,YAAY,CAAC,CAAC;AACvC,CAAC"}

View File

@ -1,3 +1,2 @@
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function expandCollection(this: Core, collection: AP.EitherCollectionReference): Promise<AP.EitherCollection | null>;
import { CoreLibrary } from './adapters';
export declare const expandCollection: CoreLibrary['expandCollection'];

View File

@ -2,10 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.expandCollection = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
async function expandCollection(collection) {
if (!type_utilities_1.guard.isApCollection(collection)) {
return null;
}
const expandCollection = async function expandCollection(collection) {
const items = this.getCollectionItems(collection);
const expandedItems = await Promise.all(items.map(async (item) => {
var _a;
@ -27,7 +24,7 @@ async function expandCollection(collection) {
items: expandedItems,
};
}
return null;
}
return collection;
};
exports.expandCollection = expandCollection;
//# sourceMappingURL=expandCollection.js.map

View File

@ -1 +1 @@
{"version":3,"file":"expandCollection.js","sourceRoot":"","sources":["../src/expandCollection.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAI9C,KAAK,UAAU,gBAAgB,CAEpC,UAAwC;IAExC,IAAI,CAAC,sBAAK,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QACrC,OAAO,IAAI,CAAC;KACb;IAED,MAAM,KAAK,GAAG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AAC,mCAAI,IAAI,CAAC;IAC9C,CAAC,CAAC,CACH,CAAC;IAEF,IACE,sBAAK,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC;QACtC,UAAU,CAAC,YAAY,CAAC,MAAM,EAC9B;QACA,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,aAAa;SAC5B,CAAC;KACH;SAAM,IAAI,sBAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE;QACrE,OAAO;YACL,GAAG,UAAU;YACb,KAAK,EAAE,aAAa;SACrB,CAAC;KACH;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAjCS,QAAA,gBAAgB,oBAiCzB"}

View File

@ -1,3 +1,2 @@
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function expandEntity(this: Core, entity: AP.Entity): Promise<AP.Entity | null>;
import { CoreLibrary } from './adapters';
export declare const expandEntity: CoreLibrary['expandEntity'];

View File

@ -11,10 +11,10 @@ const selfReferentialKeys = [
'href',
'publicKey',
];
async function expandEntity(entity) {
const expandEntity = async function expandEntity(entity) {
var _a;
return (_a = type_utilities_1.cast.isApEntity(await expandObject.bind(this)(entity))) !== null && _a !== void 0 ? _a : null;
}
return (_a = type_utilities_1.cast.isApEntity(await expandObject.bind(this)(entity))) !== null && _a !== void 0 ? _a : entity;
};
exports.expandEntity = expandEntity;
async function expandObject(object) {
const expanded = {};

View File

@ -1 +1 @@
{"version":3,"file":"expandEntity.js","sourceRoot":"","sources":["../src/expandEntity.ts"],"names":[],"mappings":";;;AAEA,iEAA2D;AAE3D,MAAM,mBAAmB,GAAG;IAC1B,UAAU;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,WAAW;CACZ,CAAC;AAEK,KAAK,UAAU,YAAY,CAAa,MAAiB;;IAC9D,OAAO,MAAA,qBAAI,CAAC,UAAU,CAAC,MAAM,YAAY,CAAC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AE,IAAI,CAAC,CAAC,CAAC,CACrE,CAAC;KACH;IAED,IAAI,sBAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QAC9B,OAAO,MAAM,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;KAC7C;IAED,IAAI,sBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,WAAW,GAAG,qBAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAEjE,IAAI,WAAW,EAAE;YACf,OAAO,WAAW,CAAC;SACpB;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}

View File

@ -1,4 +1,2 @@
/// <reference types="node" />
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function fetchEntityById(this: Core, id: URL): Promise<AP.Entity | null>;
import { CoreLibrary } from './adapters';
export declare const fetchEntityById: CoreLibrary['fetchEntityById'];

View File

@ -27,7 +27,7 @@ exports.fetchEntityById = void 0;
const AP = __importStar(require("@activity-kit/types"));
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function fetchEntityById(id) {
const fetchEntityById = async function fetchEntityById(id) {
const isJsonLdContentType = await getIsJsonLdContentType.bind(this)(id);
if (!isJsonLdContentType) {
return null;
@ -53,7 +53,7 @@ async function fetchEntityById(id) {
}
}
return null;
}
};
exports.fetchEntityById = fetchEntityById;
async function fetchJsonByUrl(url, headers) {
const controller = new AbortController();

View File

@ -1 +1 @@
{"version":3,"file":"fetchEntityById.js","sourceRoot":"","sources":["../src/fetchEntityById.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAA4D;AAC5D,uDAUiC;AAE1B,KAAK,UAAU,eAAe,CAEnC,EAAO;IAEP,MAAM,mBAAmB,GAAG,MAAM,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE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AE,MAAM,CAAC;SACtC,IAAI,CAAC,cAAc,CAAC;SACpB,KAAK,CAAC,WAAW,CAAC,CAAC;AACxB,CAAC;AAED,KAAK,UAAU,cAAc,CAE3B,GAAQ;IAER,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACrC,CAAC;AAED,KAAK,UAAU,sBAAsB,CAEnC,GAAQ;IAER,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAEzD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CACL,WAAW,CAAC,QAAQ,CAAC,wCAA4B,CAAC;QAClD,WAAW,CAAC,QAAQ,CAAC,oCAAwB,CAAC;QAC9C,WAAW,CAAC,QAAQ,CAAC,6BAAiB,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,WAAW;;IACxB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QAC5C,iBAAiB,EAAE,iCAAqB;KACzC,CAAC,CAAC;IAEH,OAAO,MAAA,qBAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,mCAAI,IAAI,CAAC;AAC1C,CAAC"}

View File

@ -1,4 +1,2 @@
/// <reference types="node" />
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function findEntityById(this: Core, id: URL): Promise<AP.Entity | null>;
import { CoreLibrary } from './adapters';
export declare const findEntityById: CoreLibrary['fetchEntityById'];

View File

@ -2,9 +2,9 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.findEntityById = void 0;
const utilities_1 = require("@activity-kit/utilities");
async function findEntityById(id) {
const findEntityById = async function findEntityById(id) {
const collectionName = (0, utilities_1.getCollectionNameByUrl)(id);
return await this.findOne(collectionName, { id: id.href });
}
};
exports.findEntityById = findEntityById;
//# sourceMappingURL=findEntityById.js.map

View File

@ -1 +1 @@
{"version":3,"file":"findEntityById.js","sourceRoot":"","sources":["../src/findEntityById.ts"],"names":[],"mappings":";;;AAEA,uDAAiE;AAE1D,KAAK,UAAU,cAAc,CAElC,EAAO;IAEP,MAAM,cAAc,GAAG,IAAA,kCAAsB,EAAC,EAAE,CAAC,CAAC;IAElD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC;AAPD,wCAOC"}
{"version":3,"file":"findEntityById.js","sourceRoot":"","sources":["../src/findEntityById.ts"],"names":[],"mappings":";;;AACA,uDAAiE;AAI1D,MAAM,cAAc,GACzB,KAAK,UAAU,cAAc,CAE3B,EAAO;IAEP,MAAM,cAAc,GAAG,IAAA,kCAAsB,EAAC,EAAE,CAAC,CAAC;IAElD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC;AARS,QAAA,cAAc,kBAQvB"}

View File

@ -1,3 +1,2 @@
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function getActorByUserId(this: Core, userId: string): Promise<AP.Actor | null>;
import { CoreLibrary } from './adapters';
export declare const getActorByUserId: CoreLibrary['getActorByUserId'];

View File

@ -2,13 +2,13 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActorByUserId = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
async function getActorByUserId(userId) {
const getActorByUserId = async function getActorByUserId(userId) {
const preferredUsername = await this.findStringValueById('username', userId);
const user = await this.findOne('entity', { preferredUsername });
if (!type_utilities_1.guard.isApActor(user)) {
return null;
}
return user;
}
};
exports.getActorByUserId = getActorByUserId;
//# sourceMappingURL=getActorByUserId.js.map

View File

@ -1 +1 @@
{"version":3,"file":"getActorByUserId.js","sourceRoot":"","sources":["../src/getActorByUserId.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAI9C,KAAK,UAAU,gBAAgB,CAEpC,MAAc;IAEd,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAE7E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAEjE,IAAI,CAAC,sBAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QAC1B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAbD,4CAaC"}
{"version":3,"file":"getActorByUserId.js","sourceRoot":"","sources":["../src/getActorByUserId.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAI9C,MAAM,gBAAgB,GAC3B,KAAK,UAAU,gBAAgB,CAE7B,MAAc;IAEd,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,mBAAmB,CACtD,UAAU,EACV,MAAM,CACP,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAEjE,IAAI,CAAC,sBAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QAC1B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAjBS,QAAA,gBAAgB,oBAiBzB"}

View File

@ -1,3 +1,2 @@
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function getCollectionItems(this: Core, entity: AP.Collection | AP.OrderedCollection): AP.EntityReference[];
import { CoreLibrary } from './adapters';
export declare const getCollectionItems: CoreLibrary['getCollectionItems'];

View File

@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCollectionItems = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
function getCollectionItems(entity) {
const getCollectionItems = function getCollectionItems(entity) {
const collectionItems = [];
if (type_utilities_1.guard.isArray(entity.orderedItems) && entity.orderedItems.length) {
const orderedItems = entity.orderedItems.filter((item) => {
@ -17,6 +17,6 @@ function getCollectionItems(entity) {
collectionItems.push(...items);
}
return collectionItems;
}
};
exports.getCollectionItems = getCollectionItems;
//# sourceMappingURL=getCollectionItems.js.map

View File

@ -1 +1 @@
{"version":3,"file":"getCollectionItems.js","sourceRoot":"","sources":["../src/getCollectionItems.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAIrD,SAAgB,kBAAkB,CAEhC,MAA4C;IAE5C,MAAM,eAAe,GAAyB,EAAE,CAAC;IAEjD,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;QACpE,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACvD,OAAO,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;KACvC;SAAM,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;QAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACzC,OAAO,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,eAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;KAChC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AArBD,gDAqBC"}
{"version":3,"file":"getCollectionItems.js","sourceRoot":"","sources":["../src/getCollectionItems.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AAI9C,MAAM,kBAAkB,GAC7B,SAAS,kBAAkB,CAEzB,MAA2B;IAE3B,MAAM,eAAe,GAAyB,EAAE,CAAC;IAEjD,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;QACpE,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACvD,OAAO,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,eAAe,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;KACvC;SAAM,IAAI,sBAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;QAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACzC,OAAO,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,eAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;KAChC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAtBS,QAAA,kBAAkB,sBAsB3B"}

View File

@ -1,3 +1,2 @@
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function getPaginatedCollectionItems(this: Core, collection: AP.Collection | AP.OrderedCollection): Promise<AP.EntityReference[]>;
import { CoreLibrary } from './adapters';
export declare const getPaginatedCollectionItems: CoreLibrary['getPaginatedCollectionItems'];

View File

@ -27,7 +27,7 @@ exports.getPaginatedCollectionItems = void 0;
const AP = __importStar(require("@activity-kit/types"));
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function getPaginatedCollectionItems(collection) {
const getPaginatedCollectionItems = async function getPaginatedCollectionItems(collection) {
const firstCollectionPageId = (0, utilities_1.getId)(collection.first);
if (!firstCollectionPageId) {
if (type_utilities_1.guard.isArray(collection.orderedItems)) {
@ -62,6 +62,6 @@ async function getPaginatedCollectionItems(collection) {
nextCollectionPage = nextPage;
}
return collectionItems.flat();
}
};
exports.getPaginatedCollectionItems = getPaginatedCollectionItems;
//# sourceMappingURL=getPaginatedCollectionItems.js.map

View File

@ -1 +1 @@
{"version":3,"file":"getPaginatedCollectionItems.js","sourceRoot":"","sources":["../src/getPaginatedCollectionItems.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAqD;AACrD,uDAAgD;AAEzC,KAAK,UAAU,2BAA2B,CAE/C,UAAgD;IAEhD,MAAM,qBAAqB,GAAG,IAAA,iBAAK,EAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAEtD,IAAI,CAAC,qBAAqB,EAAE;QAG1B,IAAI,sBAAK,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;YAC1C,OAAO,UAAU,CAAC,YAAY,CAAC;SAChC;QAED,IAAI,sBAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YACnC,OAAO,UAAU,CAAC,KAAK,CAAC;SACzB;QAED,OAAO,EAAE,CAAC;KACX;IAED,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAExE,IACE,CAAC,sBAAK,CAAC,UAAU,CACf,mBAAmB,EACnB,EAAE,CAAC,mBAAmB,CACvB,EACD;QACA,OAAO,EAAE,CAAC;KACX;IAED,MAAM,eAAe,GAA2B,EAAE,CAAC;I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ateKey(this: Core, actor: AP.Actor): Promise<string>;
import { CoreLibrary } from './adapters';
export declare const getPrivateKey: CoreLibrary['getPrivateKey'];

View File

@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPrivateKey = void 0;
async function getPrivateKey(actor) {
const getPrivateKey = async function getPrivateKey(actor) {
if (!actor.preferredUsername) {
throw new Error('Actor has no `preferredUsername`.');
}
@ -11,6 +11,6 @@ async function getPrivateKey(actor) {
throw new Error('Private key not found for this Actor.');
}
return privateKey;
}
};
exports.getPrivateKey = getPrivateKey;
//# sourceMappingURL=getPrivateKey.js.map

View File

@ -1 +1 @@
{"version":3,"file":"getPrivateKey.js","sourceRoot":"","sources":["../src/getPrivateKey.ts"],"names":[],"mappings":";;;AAGO,KAAK,UAAU,aAAa,CAAa,KAAe;IAC7D,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAC3C,UAAU,EACV,KAAK,CAAC,iBAAiB,CACxB,CAAC;IAEF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAjBD,sCAiBC"}
{"version":3,"file":"getPrivateKey.js","sourceRoot":"","sources":["../src/getPrivateKey.ts"],"names":[],"mappings":";;;AAIO,MAAM,aAAa,GACxB,KAAK,UAAU,aAAa,CAE1B,KAAe;IAEf,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAC3C,UAAU,EACV,KAAK,CAAC,iBAAiB,CACxB,CAAC;IAEF,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAExE,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;KAC1D;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AArBS,QAAA,aAAa,iBAqBtB"}

View File

@ -1,4 +0,0 @@
/// <reference types="node" />
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function getRecipientInboxUrls(this: Core, activity: AP.Activity, actor: AP.Actor, inboxesOnly?: boolean): Promise<import("url").URL[]>;

View File

@ -1,36 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRecipientInboxUrls = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function getRecipientInboxUrls(activity, actor, inboxesOnly) {
const recipientUrls = await this.getRecipientUrls(activity);
const recipientInboxUrls = await Promise.all(recipientUrls.map(async (recipientUrl) => {
return await mapRecipientUrl.bind(this)(recipientUrl, actor, inboxesOnly);
}));
return (0, utilities_1.deduplicateUrls)(recipientInboxUrls.flat().filter(type_utilities_1.guard.isUrl));
}
exports.getRecipientInboxUrls = getRecipientInboxUrls;
async function mapRecipientUrl(recipientUrl, actor, inboxesOnly) {
var _a;
if (recipientUrl.href === ((_a = (0, utilities_1.getId)(actor)) === null || _a === void 0 ? void 0 : _a.href)) {
return [];
}
const foundEntity = await this.fetchEntityById(recipientUrl);
if (!type_utilities_1.guard.isApActor(foundEntity)) {
return [];
}
if (!inboxesOnly) {
if (foundEntity.endpoints) {
if (type_utilities_1.guard.isUrl(foundEntity.endpoints.sharedInbox)) {
return [foundEntity.endpoints.sharedInbox];
}
}
}
const inboxId = (0, utilities_1.getId)(foundEntity.inbox);
if (type_utilities_1.guard.isUrl(inboxId)) {
return [inboxId];
}
return [];
}
//# sourceMappingURL=getRecipientInboxUrls.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"getRecipientInboxUrls.js","sourceRoot":"","sources":["../src/getRecipientInboxUrls.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,uDAAiE;AAI1D,KAAK,UAAU,qBAAqB,CAEzC,QAAqB,EACrB,KAAe,EACf,WAAqB;IAErB,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE5D,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,GAAG,CAC1C,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACvC,OAAO,MAAM,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5E,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,IAAA,2BAAe,EAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,sBAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACxE,CAAC;AAfD,sDAeC;AAED,KAAK,UAAU,eAAe,CAE5B,YAAiB,EACjB,KAAe,EACf,WAAqB;;IAErB,IAAI,YAAY,CAAC,IAAI,MAAK,MAAA,IAAA,iBAAK,EAAC,KAAK,CAAC,0CAAE,IAAI,CAAA,EAAE;QAC5C,OAAO,EAAE,CAAC;KACX;IAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAE7D,IAAI,CAAC,sBAAK,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;QACjC,OAAO,EAAE,CAAC;KACX;IAED,IAAI,CAAC,WAAW,EAAE;QAChB,IAAI,WAAW,CAAC,SAAS,EAAE;YACzB,IAAI,sBAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;gBAClD,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;aAC5C;SACF;KACF;IAED,MAAM,OAAO,GAAG,IAAA,iBAAK,EAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAEzC,IAAI,sBAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QACxB,OAAO,CAAC,OAAO,CAAC,CAAC;KAClB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}

View File

@ -1,4 +1,2 @@
/// <reference types="node" />
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function getRecipientUrls(this: Core, activity: AP.Activity): Promise<URL[]>;
import { CoreLibrary } from './adapters';
export declare const getRecipientUrls: CoreLibrary['getRecipientUrls'];

View File

@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.getRecipientUrls = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function getRecipientUrls(activity) {
const getRecipientUrls = async function getRecipientUrls(activity) {
const tags = type_utilities_1.guard.isApCoreObject(activity.object) && activity.object.tag
? getArray(activity.object.tag)
: [];
@ -22,7 +22,7 @@ async function getRecipientUrls(activity) {
.filter((recipientUrl) => recipientUrl.href !== utilities_1.PUBLIC_ACTOR);
const actorUrls = await Promise.all(recipientIds.map(getActorIds.bind(this)));
return (0, utilities_1.deduplicateUrls)(actorUrls.flat());
}
};
exports.getRecipientUrls = getRecipientUrls;
async function getActorIds(recipientId) {
const foundRecipient = await this.queryById(recipientId);

View File

@ -1 +1 @@
{"version":3,"file":"getRecipientUrls.js","sourceRoot":"","sources":["../src/getRecipientUrls.ts"],"names":[],"mappings":";;;AAEA,iEAAqD;AACrD,uDAA+E;AAExE,KAAK,UAAU,gBAAgB,CAEpC,QAAqB;IAErB,MAAM,IAAI,GACR,sBAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG;QAC1D,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG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;AACZ,CAAC;AAED,SAAS,QAAQ,CACf,KAAwD;IAExD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IAED,MAAM,KAAK,GAAG,sBAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAErD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,OAAO,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,sBAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC"}

View File

@ -1,3 +1,2 @@
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare const getStreamByName: (this: Core, actor: AP.Actor, name: string) => Promise<AP.EitherCollection | null>;
import { CoreLibrary } from './adapters';
export declare const getStreamByName: CoreLibrary['getStreamByName'];

View File

@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.getStreamByName = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
const getStreamByName = async function (actor, name) {
const getStreamByName = async function getStreamByName(actor, name) {
if (!actor.streams) {
return null;
}

View File

@ -1 +1 @@
{"version":3,"file":"getStreamByName.js","sourceRoot":"","sources":["../src/getStreamByName.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,uDAAgD;AAIzC,MAAM,eAAe,GAAG,KAAK,WAElC,KAAe,EACf,IAAY;IAEZ,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAA0B,EAAE,EAAE;QACrD,MAAM,QAAQ,GAAG,IAAA,iBAAK,EAAC,MAAM,CAAC,CAAC;QAE/B,IAAI,CA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 +1,6 @@
/// <reference types="node" />
import * as AP from '@activity-kit/types';
import { AuthAdapter, CryptoAdapter, DbAdapter, FetchPolyfill, StorageAdapter, CoreLibrary } from './adapters';
import { findEntityById } from './findEntityById';
import { fetchEntityById } from './fetchEntityById';
import { queryById } from './queryById';
import { expandEntity } from './expandEntity';
import { getPrivateKey } from './getPrivateKey';
import { getCollectionItems } from './getCollectionItems';
import { getPaginatedCollectionItems } from './getPaginatedCollectionItems';
import { expandCollection } from './expandCollection';
import { getActorByUserId } from './getActorByUserId';
import { broadcast } from './broadcast';
import { getRecipientUrls } from './getRecipientUrls';
import { getRecipientInboxUrls } from './getRecipientInboxUrls';
import { signAndSendToForeignActorInbox } from './signAndSendToForeignActorInbox';
export declare class Core implements CoreLibrary {
fetch: FetchPolyfill;
initializeDb?: DbAdapter['initializeDb'];
@ -42,19 +31,17 @@ export declare class Core implements CoreLibrary {
db: DbAdapter;
fetch?: FetchPolyfill;
});
findEntityById: typeof findEntityById;
getActorByUserId: typeof getActorByUserId;
getPrivateKey: typeof getPrivateKey;
getStreamByName: (this: Core, actor: import("@activity-kit/types").Actor, name: string) => Promise<import("@activity-kit/types").EitherCollection | null>;
fetchEntityById: typeof fetchEntityById;
queryById: typeof queryById;
expandEntity: typeof expandEntity;
getCollectionItems: typeof getCollectionItems;
getPaginatedCollectionItems: typeof getPaginatedCollectionItems;
expandCollection: typeof expandCollection;
getRecipientInboxUrls: typeof getRecipientInboxUrls;
getRecipientUrls: typeof getRecipientUrls;
broadcast: typeof broadcast;
signAndSendToForeignActorInbox: typeof signAndSendToForeignActorInbox;
findEntityById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
getActorByUserId: (this: CoreLibrary, userId: string) => Promise<AP.Actor | null>;
getPrivateKey: (this: CoreLibrary, actor: AP.Actor) => Promise<string>;
getStreamByName: (this: CoreLibrary, actor: AP.Actor, name: string) => Promise<AP.EitherCollection | null>;
fetchEntityById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
queryById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
expandEntity: (this: CoreLibrary, entity: AP.Entity) => Promise<AP.Entity>;
getCollectionItems: (this: CoreLibrary, entity: AP.Collection | AP.OrderedCollection) => AP.EntityReference[];
getPaginatedCollectionItems: (this: CoreLibrary, collection: AP.Collection | AP.OrderedCollection) => Promise<AP.EntityReference[]>;
expandCollection: (this: CoreLibrary, collection: AP.EitherCollection) => Promise<AP.EitherCollection>;
broadcast: (this: CoreLibrary, activity: AP.Activity, actor: AP.Actor) => Promise<unknown>;
getRecipientUrls: (this: CoreLibrary, activity: AP.Activity) => Promise<URL[]>;
}
export { AuthAdapter, CryptoAdapter, DbAdapter, DbOptions, FetchPolyfill, StorageAdapter, CoreLibrary, Plugin, Routes, } from './adapters';

View File

@ -17,8 +17,6 @@ const getActorByUserId_1 = require("./getActorByUserId");
const getStreamByName_1 = require("./getStreamByName");
const broadcast_1 = require("./broadcast");
const getRecipientUrls_1 = require("./getRecipientUrls");
const getRecipientInboxUrls_1 = require("./getRecipientInboxUrls");
const signAndSendToForeignActorInbox_1 = require("./signAndSendToForeignActorInbox");
class Core {
constructor(adapters) {
var _a;
@ -32,10 +30,8 @@ class Core {
this.getCollectionItems = getCollectionItems_1.getCollectionItems;
this.getPaginatedCollectionItems = getPaginatedCollectionItems_1.getPaginatedCollectionItems;
this.expandCollection = expandCollection_1.expandCollection;
this.getRecipientInboxUrls = getRecipientInboxUrls_1.getRecipientInboxUrls;
this.getRecipientUrls = getRecipientUrls_1.getRecipientUrls;
this.broadcast = broadcast_1.broadcast;
this.signAndSendToForeignActorInbox = signAndSendToForeignActorInbox_1.signAndSendToForeignActorInbox;
this.getRecipientUrls = getRecipientUrls_1.getRecipientUrls;
this.fetch = (_a = adapters.fetch) !== null && _a !== void 0 ? _a : isomorphic_fetch_1.default;
if (adapters.db.initializeDb) {
this.initializeDb = async () => { var _a, _b; return await ((_b = (_a = adapters.db).initializeDb) === null || _b === void 0 ? void 0 : _b.call(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C,CAAC;QAEnD,IAAI,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAEjE,IAAI,CAAC,gBAAgB,GAAG,KAAK,EAAE,MAAM,EAAE,EAAE,CACvC,MAAM,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAE/C,IAAI,CAAC,UAAU,GAAG,KAAK,EAAE,EACvB,KAAK,EACL,QAAQ,EACR,iBAAiB,GAKlB,EAAE,EAAE,CACH,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;YAC7B,KAAK;YACL,QAAQ;YACR,iBAAiB;SAClB,CAAC,CAAC;QAEL,IAAI,CAAC,gBAAgB,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CACtC,MAAM,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAE9C,IAAI,CAAC,oBAAoB,GAAG,KAAK,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE,CACpE,MAAM,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE5D,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;CAyBF;AAzJD,oBAyJC;AAED,uCAUoB;AANlB,qGAAA,SAAS,OAAA"}

View File

@ -1,4 +1,2 @@
/// <reference types="node" />
import { Core } from '.';
import * as AP from '@activity-kit/types';
export declare function queryById(this: Core, id: URL): Promise<AP.Entity | null>;
import { CoreLibrary } from './adapters';
export declare const queryById: CoreLibrary['queryById'];

View File

@ -27,7 +27,7 @@ exports.queryById = void 0;
const AP = __importStar(require("@activity-kit/types"));
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function queryById(id) {
const queryById = async function queryById(id) {
if ((0, utilities_1.isLocal)(id)) {
return await this.findEntityById(id);
}
@ -40,6 +40,6 @@ async function queryById(id) {
}
}
return fetchedEntity;
}
};
exports.queryById = queryById;
//# sourceMappingURL=queryById.js.map

View File

@ -1 +1 @@
{"version":3,"file":"queryById.js","sourceRoot":"","sources":["../src/queryById.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAqD;AACrD,uDAAkD;AAE3C,KAAK,UAAU,SAAS,CAE7B,EAAO;IAEP,IAAI,IAAA,mBAAO,EAAC,EAAE,CAAC,EAAE;QACf,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;KACtC;IAED,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAErD,IACE,CAAC,aAAa;QACd,sBAAK,CAAC,QAAQ,CACZ,aAAa,EACb,EAAE,CAAC,mBAAmB,CAAC,SAAS,CACjC,EACD;QACA,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QAElD,IAAI,WAAW,EAAE;YACf,OAAO,WAAW,CAAC;SACpB;KACF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAzBD,8BAyBC"}
{"version":3,"file":"queryById.js","sourceRoot":"","sources":["../src/queryById.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,iEAAqD;AACrD,uDAAkD;AAI3C,MAAM,SAAS,GAA6B,KAAK,UAAU,SAAS,CAEzE,EAAO;IAEP,IAAI,IAAA,mBAAO,EAAC,EAAE,CAAC,EAAE;QACf,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;KACtC;IAED,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAErD,IACE,CAAC,aAAa;QACd,sBAAK,CAAC,QAAQ,CACZ,aAAa,EACb,EAAE,CAAC,mBAAmB,CAAC,SAAS,CACjC,EACD;QACA,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QAElD,IAAI,WAAW,EAAE;YACf,OAAO,WAAW,CAAC;SACpB;KACF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAzBW,QAAA,SAAS,aAyBpB"}

View File

@ -1,4 +0,0 @@
/// <reference types="node" />
import * as AP from '@activity-kit/types';
import { Core } from '.';
export declare function signAndSendToForeignActorInbox(this: Core, foreignActorInbox: URL, actor: AP.Actor, activity: AP.Activity): Promise<unknown>;

View File

@ -1,28 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.signAndSendToForeignActorInbox = void 0;
const type_utilities_1 = require("@activity-kit/type-utilities");
const utilities_1 = require("@activity-kit/utilities");
async function signAndSendToForeignActorInbox(foreignActorInbox, actor, activity) {
console.log('SENDING TO...', foreignActorInbox.href);
const actorId = (0, utilities_1.getId)(actor);
type_utilities_1.assert.exists(actorId);
const plainActivity = (0, utilities_1.convertEntityToJson)(activity);
const { dateHeader, digestHeader, signatureHeader } = await this.getHttpSignature(foreignActorInbox, actorId, await this.getPrivateKey(actor), plainActivity);
return await this.fetch(foreignActorInbox.href, {
method: 'post',
body: JSON.stringify(plainActivity),
headers: {
[utilities_1.CONTENT_TYPE_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
[utilities_1.ACCEPT_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
Host: foreignActorInbox.hostname,
Date: dateHeader,
Digest: digestHeader,
Signature: signatureHeader,
},
}).catch((error) => {
console.log(error);
});
}
exports.signAndSendToForeignActorInbox = signAndSendToForeignActorInbox;
//# sourceMappingURL=signAndSendToForeignActorInbox.js.map

View File

@ -1 +0,0 @@
{"version":3,"file":"signAndSendToForeignActorInbox.js","sourceRoot":"","sources":["../src/signAndSendToForeignActorInbox.ts"],"names":[],"mappings":";;;AACA,iEAAsD;AACtD,uDAMiC;AAI1B,KAAK,UAAU,8BAA8B,CAElD,iBAAsB,EACtB,KAAe,EACf,QAAqB;IAErB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAErD,MAAM,OAAO,GAAG,IAAA,iBAAK,EAAC,KAAK,CAAC,CAAC;IAE7B,uBAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEvB,MAAM,aAAa,GAAG,IAAA,+BAAmB,EAAC,QAAQ,CAAC,CAAC;IAEpD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,GACjD,MAAM,IAAI,CAAC,gBAAgB,CACzB,iBAAiB,EACjB,OAAO,EACP,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAC/B,aAAa,CACd,CAAC;IAGJ,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAC9C,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;QACnC,OAAO,EAAE;YACP,CAAC,+BAAmB,CAAC,EAAE,wCAA4B;YACnD,CAAC,yBAAa,CAAC,EAAE,wCAA4B;YAC7C,IAAI,EAAE,iBAAiB,CAAC,QAAQ;YAChC,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE,eAAe;SACD;KAC5B,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACjB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC;AArCD,wEAqCC"}

View File

@ -12,6 +12,9 @@
"files": [
"lib"
],
"engine": {
"node": ">=18.0.0"
},
"publishConfig": {
"access": "public"
},

View File

@ -27,8 +27,10 @@ declare class Headers {
declare type BodyInit = Blob | ArrayBufferView | ArrayBuffer | string;
declare type ResponseBodyInit = BodyInit;
interface Body {
export interface Body {
readonly bodyUsed: boolean;
readonly status: number;
readonly url: string;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
json(): Promise<JSON>;

View File

@ -33,7 +33,6 @@ export type CoreLibrary = AuthAdapter &
this: CoreLibrary,
userId: string,
) => Promise<AP.Actor | null>;
getPrivateKey: (this: CoreLibrary, actor: AP.Actor) => Promise<string>;
getStreamByName: (
this: CoreLibrary,
actor: AP.Actor,
@ -41,28 +40,15 @@ export type CoreLibrary = AuthAdapter &
) => Promise<AP.EitherCollection | null>;
fetchEntityById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
queryById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
expandEntity: (
this: CoreLibrary,
entity: AP.Entity,
) => Promise<AP.Entity | null>;
getCollectionItems: (
this: CoreLibrary,
entity: AP.Collection | AP.OrderedCollection,
) => AP.EntityReference[];
expandEntity: (this: CoreLibrary, entity: AP.Entity) => Promise<AP.Entity>;
getPaginatedCollectionItems: (
this: CoreLibrary,
collection: AP.Collection | AP.OrderedCollection,
) => Promise<AP.EntityReference[]>;
expandCollection: (
this: CoreLibrary,
collection: AP.EitherCollectionReference,
) => Promise<null | AP.EitherCollection>;
getRecipientInboxUrls: (
this: CoreLibrary,
activity: AP.Activity,
actor: AP.Actor,
inboxesOnly?: boolean,
) => Promise<URL[]>;
collection: AP.EitherCollection,
) => Promise<AP.EitherCollection>;
getRecipientUrls: (
this: CoreLibrary,
activity: AP.Activity,
@ -72,10 +58,4 @@ export type CoreLibrary = AuthAdapter &
activity: AP.Activity,
actor: AP.Actor,
) => Promise<unknown>;
signAndSendToForeignActorInbox: (
this: CoreLibrary,
foreignActorInbox: URL,
actor: AP.Actor,
activity: AP.Activity,
) => Promise<unknown>;
};

View File

@ -1,40 +1,153 @@
import * as AP from '@activity-kit/types';
import { assert } from '@activity-kit/type-utilities';
import { applyContext, cleanProps } from '@activity-kit/utilities';
import { guard, assert } from '@activity-kit/type-utilities';
import {
deduplicateUrls,
applyContext,
cleanProps,
CONTENT_TYPE_HEADER,
ACTIVITYSTREAMS_CONTENT_TYPE,
ACCEPT_HEADER,
convertEntityToJson,
getId,
} from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
/**
* [x] Removes the `bto` and `bcc` properties from Objects before delivery
* (`outbox:removes-bto-and-bcc`) *MUST*
* Send an Activity to all of its recipients on behalf of an Actor.
*
* @returns A record of each URL and the HTTP status code of the response.
*/
export async function broadcast(
export const broadcast: CoreLibrary['broadcast'] = async function broadcast(
this: CoreLibrary,
activity: AP.Activity,
actor: AP.Actor,
): Promise<unknown> {
const entity = applyContext<AP.Entity>(activity);
): Promise<Record<string, number>> {
const activityWithContext = applyContext(activity);
const cleanedActivity = cleanProps(activityWithContext);
const plainEntity = convertEntityToJson(cleanedActivity);
const recipientInboxUrls = await getRecipientInboxUrls.bind(this)(
activity,
actor,
);
const sendToRecipient = (recipientInboxUrl: URL) =>
signAndSendToInboxUrl.call(this, recipientInboxUrl, actor, plainEntity);
const promises = recipientInboxUrls.map(sendToRecipient);
const resultEntries = await Promise.all(promises);
assert.isApActivity(entity);
return Object.fromEntries(resultEntries);
};
const publicActivity = cleanProps(entity);
/**
* Send to a single recipient on behalf of an Actor.
*
* @returns A tuple of the recipient's inbox URL and the HTTP status code of the
* response.
*/
async function signAndSendToInboxUrl(
this: CoreLibrary,
foreignActorInbox: URL,
actor: AP.Actor,
plainEntity: Record<string, unknown>,
): Promise<[string, number]> {
const actorId = getId(actor);
if (!('actor' in publicActivity)) {
throw new Error('Not an activity?');
assert.exists(actorId);
const privateKey = await getPrivateKey.bind(this)(actor);
const { dateHeader, digestHeader, signatureHeader } =
await this.getHttpSignature(
foreignActorInbox,
actorId,
privateKey,
plainEntity,
);
if (!digestHeader || !dateHeader || !signatureHeader) {
throw new Error('Failed to sign Activity');
}
const recipients = await this.getRecipientInboxUrls(activity, actor);
const headers = {
[CONTENT_TYPE_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
Host: foreignActorInbox.hostname,
Date: dateHeader,
Digest: digestHeader,
Signature: signatureHeader,
};
const results = await Promise.all(
recipients.map(async (recipient) => {
return await this.signAndSendToForeignActorInbox(
recipient,
actor,
publicActivity,
);
}),
const statusCode = await this.fetch(foreignActorInbox.href, {
method: 'post',
body: JSON.stringify(plainEntity),
headers,
})
.then(async (res) => {
return res.status;
})
.catch(() => {
return 0;
});
return [foreignActorInbox.href, statusCode];
}
/**
* Get the inbox URLs of all recipients of an Activity.
*/
async function getRecipientInboxUrls(
this: CoreLibrary,
activity: AP.Activity,
actor: AP.Actor,
): Promise<URL[]> {
const recipientUrls = await this.getRecipientUrls(activity);
const extractUrl = async (recipientUrl: URL): Promise<URL | null> => {
if (recipientUrl.href === getId(actor)?.href) {
return null;
}
const foundEntity = await this.fetchEntityById(recipientUrl);
if (!guard.isApActor(foundEntity)) {
return null;
}
if (foundEntity.endpoints) {
if (guard.isUrl(foundEntity.endpoints.sharedInbox)) {
return foundEntity.endpoints.sharedInbox;
}
}
return getId(foundEntity.inbox);
};
const recipientInboxUrls = await Promise.all(recipientUrls.map(extractUrl));
const filteredUrls = recipientInboxUrls.filter(guard.isUrl);
return deduplicateUrls(filteredUrls);
}
/**
* Get the private key of an Actor.
*/
async function getPrivateKey(
this: CoreLibrary,
actor: AP.Actor,
): Promise<string> {
if (!actor.preferredUsername) {
return '';
}
const userId = await this.findStringIdByValue(
'username',
actor.preferredUsername,
);
return results;
if (!userId) {
return '';
}
return await this.findStringValueById('privateKey', userId);
}

View File

@ -3,40 +3,63 @@ import { guard } from '@activity-kit/type-utilities';
import { CoreLibrary } from './adapters';
export async function expandCollection(
this: CoreLibrary,
collection: AP.EitherCollectionReference,
): Promise<AP.EitherCollection | null> {
if (!guard.isApCollection(collection)) {
return null;
}
const items = this.getCollectionItems(collection);
const expandedItems = await Promise.all(
items.map(async (item) => {
if (guard.isApEntity(item)) {
return item;
}
return (await this.queryById(item)) ?? item;
}),
);
if (
guard.isArray(collection.orderedItems) &&
collection.orderedItems.length
) {
return {
/**
* Given a Collection or OrderedCollection, convert its item/orderedItem
* references to be full entities.
*
* @returns A Promise that resolves to the expanded Collection.
*/
export const expandCollection: CoreLibrary['expandCollection'] =
async function expandCollection(
this: CoreLibrary,
collection: AP.EitherCollection,
): Promise<AP.EitherCollection> {
const expandedCollection = {
...collection,
orderedItems: expandedItems,
};
} else if (guard.isArray(collection.items) && collection.items.length) {
return {
...collection,
items: expandedItems,
};
}
return null;
if (isArray(collection.orderedItems)) {
const expandPromises = collection.orderedItems
.filter(isEntityReference)
.map(query.bind(this));
const expanded = await Promise.all(expandPromises);
expandedCollection.orderedItems = expanded;
}
if (isArray(collection.items)) {
const expandPromises = collection.items
.filter(isEntityReference)
.map(query.bind(this));
const expanded = await Promise.all(expandPromises);
expandedCollection.items = expanded;
}
return expandedCollection;
};
function isEntityReference(value: unknown): boolean {
return guard.isApEntity(value) || guard.isUrl(value);
}
function isArray(
items: AP.OrArray<AP.EntityReference> | undefined,
): items is Array<AP.Entity> {
return guard.isArray(items) && items.length > 0;
}
async function query(
this: CoreLibrary,
item: AP.EntityReference,
): Promise<AP.EntityReference> {
if (guard.isApEntity(item)) {
return item;
}
const cachedItem = await this.queryById(item);
return cachedItem ?? item;
}

View File

@ -3,6 +3,9 @@ import { cast, guard } from '@activity-kit/type-utilities';
import { CoreLibrary } from './adapters';
/**
* Keys that should not be expanded.
*/
const selfReferentialKeys = [
'@context',
'_id',
@ -13,17 +16,27 @@ const selfReferentialKeys = [
'publicKey',
];
export async function expandEntity(
this: CoreLibrary,
entity: AP.Entity,
): Promise<AP.Entity | null> {
return cast.isApEntity(await expandObject.bind(this)(entity)) ?? null;
}
/**
* Convert an Entity to a full object, expanding any references to other
* Entities.
*
* @returns A Promise that resolves to the expanded Entity.
*/
export const expandEntity: CoreLibrary['expandEntity'] =
async function expandEntity(
this: CoreLibrary,
entity: AP.Entity,
): Promise<AP.Entity> {
return cast.isApEntity(await expandObject.bind(this)(entity)) ?? entity;
};
/**
* Expand all references in an object.
*/
async function expandObject(
this: CoreLibrary,
object: Record<string, unknown>,
) {
): Promise<Record<string, unknown>> {
const expanded: Record<string, unknown> = {};
for (const [key, value] of Object.entries(object)) {
@ -33,6 +46,10 @@ async function expandObject(
return expanded;
}
/**
* Expand a single entry in an object, which may be a reference to another
* Entity.
*/
async function expandEntry(
this: CoreLibrary,
entry: [key: string, value: unknown],

View File

@ -10,129 +10,162 @@ import {
getId,
SERVER_ACTOR_USERNAME,
ACTIVITYSTREAMS_CONTEXT,
CONTENT_TYPE_HEADER,
} from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
import { Body } from './adapters/FetchPolyfill';
export async function fetchEntityById(
this: CoreLibrary,
id: URL,
): Promise<AP.Entity | null> {
const isJsonLdContentType = await getIsJsonLdContentType.bind(this)(id);
/**
* Fetch an Entity by its URL.
*
* @returns The fetched Entity or null if the URL does not represent an Entity.
*/
export const fetchEntityById: CoreLibrary['fetchEntityById'] =
async function fetchEntityById(
this: CoreLibrary,
id: URL,
): Promise<AP.Entity | null> {
const isJsonLdContentType = await getIsJsonLdContentType.bind(this)(id);
if (!isJsonLdContentType) {
return null;
}
if (!isJsonLdContentType) {
return null;
}
const botActor = await getBotActor.bind(this)();
const botActor = await getBotActor.bind(this)();
assert.exists(botActor);
assert.exists(botActor);
const botActorId = getId(botActor);
const botActorId = getId(botActor);
assert.exists(botActorId);
assert.exists(botActorId);
const { dateHeader, signatureHeader } = await this.getHttpSignature(
id,
botActorId,
await this.getPrivateKey(botActor),
);
const privateKey = await getPrivateKey.bind(this)(botActor);
const headers = {
date: dateHeader,
signature: signatureHeader,
};
assert.exists(privateKey);
const fetchedJson = await fetchJsonByUrl.bind(this)(id, headers);
const { dateHeader, signatureHeader } = await this.getHttpSignature(
id,
botActorId,
privateKey,
);
const headers = {
date: dateHeader,
signature: signatureHeader,
};
const fetchedJson = await fetchJsonByUrl.bind(this)(id, headers);
if (!fetchedJson) {
return null;
}
if (fetchedJson) {
const convertedEntity = convertJsonToEntity(fetchedJson);
if (convertedEntity) {
const entity = compressEntity(convertedEntity);
if (entity) {
await this.saveEntity(entity);
return entity;
}
if (!convertedEntity) {
return null;
}
}
return null;
}
const entity = compressEntity(convertedEntity);
if (!entity) {
return null;
}
await this.saveEntity(entity);
return entity;
};
/**
* Fetch a JSON object from a URL using the provided headers.
*/
async function fetchJsonByUrl(
this: CoreLibrary,
url: URL,
headers: Record<string, string>,
): Promise<Record<string, unknown> | null> {
type Response = Awaited<ReturnType<(typeof this)['fetch']>>;
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 1250);
const config = {
signal: controller.signal,
headers: {
...headers,
// GET requests (eg. to the inbox) MUST be made with an Accept header of
// `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
},
};
async function handleResponse(response: Response) {
clearTimeout(timeout);
const data = await response.json();
if (response.status === 200) {
return data;
}
if (response.status === 400 || response.status === 410) {
if ('@context' in data) {
// Likely a tombstone
return data;
} else {
// Return a tombstone
return {
'@context': ACTIVITYSTREAMS_CONTEXT,
type: AP.ExtendedObjectTypes.TOMBSTONE,
id: url.href,
url: url.href,
};
}
}
if (response.status >= 500) {
console.log('Server error.', response.status, url.href);
return null;
}
console.log('Unexpected status code.', response.status, url.href);
return data;
}
async function handleError(error: Error) {
clearTimeout(timeout);
console.log(`${error}`);
return null;
}
return await this.fetch(url.href, config)
.then(handleResponse)
.catch(handleError);
}
/**
* Handle a response from a fetch request.
*/
async function handleResponse(
response: Body,
): Promise<Record<string, unknown> | null> {
const data = cast.isPlainObject(await response.json()) ?? null;
if (!data) {
return null;
}
if (response.status === 200) {
return data;
}
if (response.status === 400 || response.status === 410) {
if ('@context' in data) {
// Likely a tombstone
return data;
} else {
// Return a tombstone
return {
'@context': ACTIVITYSTREAMS_CONTEXT,
type: AP.ExtendedObjectTypes.TOMBSTONE,
id: response.url,
url: response.url,
};
}
}
if (response.status >= 500) {
return null;
}
return data;
}
/**
* Handle an error from a fetch request.
*/
async function handleError(error: Error) {
console.log(`${error}`);
return null;
}
/**
* Get the content type of a URL.
*
* A HEAD request is used to determine if a URL is a JSON-LD object.
*/
async function getContentType(
this: CoreLibrary,
url: URL,
): Promise<string | null> {
const { headers } = await this.fetch(url.toString(), { method: 'HEAD' });
return headers.get('Content-Type');
const response = await this.fetch(url.toString(), {
method: 'HEAD',
headers: {
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
},
});
return response.headers.get(CONTENT_TYPE_HEADER) ?? null;
}
/**
* Check if a URL returns a content type that represent a JSON-LD object.
*/
async function getIsJsonLdContentType(
this: CoreLibrary,
url: URL,
@ -150,6 +183,12 @@ async function getIsJsonLdContentType(
);
}
/**
* Get the server Actor.
*
* Mastodon in secure mode requires that all requests include a signature of the
* Actor that is making the request. We use the server Actor.
*/
async function getBotActor(this: CoreLibrary) {
const botActor = await this.findOne('entity', {
preferredUsername: SERVER_ACTOR_USERNAME,
@ -157,3 +196,26 @@ async function getBotActor(this: CoreLibrary) {
return cast.isApActor(botActor) ?? null;
}
/**
* Get the private key of an Actor.
*/
async function getPrivateKey(
this: CoreLibrary,
actor: AP.Actor,
): Promise<string> {
if (!actor.preferredUsername) {
return '';
}
const userId = await this.findStringIdByValue(
'username',
actor.preferredUsername,
);
if (!userId) {
return '';
}
return await this.findStringValueById('privateKey', userId);
}

View File

@ -3,11 +3,12 @@ import { getCollectionNameByUrl } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export async function findEntityById(
this: CoreLibrary,
id: URL,
): Promise<AP.Entity | null> {
const collectionName = getCollectionNameByUrl(id);
export const findEntityById: CoreLibrary['fetchEntityById'] =
async function findEntityById(
this: CoreLibrary,
id: URL,
): Promise<AP.Entity | null> {
const collectionName = getCollectionNameByUrl(id);
return await this.findOne(collectionName, { id: id.href });
}
return await this.findOne(collectionName, { id: id.href });
};

View File

@ -3,17 +3,21 @@ import { guard } from '@activity-kit/type-utilities';
import { CoreLibrary } from './adapters';
export async function getActorByUserId(
this: CoreLibrary,
userId: string,
): Promise<AP.Actor | null> {
const preferredUsername = await this.findStringValueById('username', userId);
export const getActorByUserId: CoreLibrary['getActorByUserId'] =
async function getActorByUserId(
this: CoreLibrary,
userId: string,
): Promise<AP.Actor | null> {
const preferredUsername = await this.findStringValueById(
'username',
userId,
);
const user = await this.findOne('entity', { preferredUsername });
const user = await this.findOne('entity', { preferredUsername });
if (!guard.isApActor(user)) {
return null;
}
if (!guard.isApActor(user)) {
return null;
}
return user;
}
return user;
};

View File

@ -3,25 +3,26 @@ import { guard } from '@activity-kit/type-utilities';
import { CoreLibrary } from './adapters';
export function getCollectionItems(
this: CoreLibrary,
entity: AP.Collection | AP.OrderedCollection,
): AP.EntityReference[] {
const collectionItems: AP.EntityReference[] = [];
export const getCollectionItems: CoreLibrary['getCollectionItems'] =
function getCollectionItems(
this: CoreLibrary,
entity: AP.EitherCollection,
): AP.EntityReference[] {
const collectionItems: AP.EntityReference[] = [];
if (guard.isArray(entity.orderedItems) && entity.orderedItems.length) {
const orderedItems = entity.orderedItems.filter((item) => {
return guard.isApEntity(item) || guard.isUrl(item);
});
if (guard.isArray(entity.orderedItems) && entity.orderedItems.length) {
const orderedItems = entity.orderedItems.filter((item) => {
return guard.isApEntity(item) || guard.isUrl(item);
});
collectionItems.push(...orderedItems);
} else if (guard.isArray(entity.items) && entity.items.length) {
const items = entity.items.filter((item) => {
return guard.isApEntity(item) || guard.isUrl(item);
});
collectionItems.push(...orderedItems);
} else if (guard.isArray(entity.items) && entity.items.length) {
const items = entity.items.filter((item) => {
return guard.isApEntity(item) || guard.isUrl(item);
});
collectionItems.push(...items);
}
collectionItems.push(...items);
}
return collectionItems;
}
return collectionItems;
};

View File

@ -4,66 +4,67 @@ import { getId } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export async function getPaginatedCollectionItems(
this: CoreLibrary,
collection: AP.Collection | AP.OrderedCollection,
): Promise<AP.EntityReference[]> {
const firstCollectionPageId = getId(collection.first);
export const getPaginatedCollectionItems: CoreLibrary['getPaginatedCollectionItems'] =
async function getPaginatedCollectionItems(
this: CoreLibrary,
collection: AP.EitherCollection,
): Promise<AP.EntityReference[]> {
const firstCollectionPageId = getId(collection.first);
if (!firstCollectionPageId) {
// TODO .getArray()
if (!firstCollectionPageId) {
// TODO .getArray()
if (guard.isArray(collection.orderedItems)) {
return collection.orderedItems;
if (guard.isArray(collection.orderedItems)) {
return collection.orderedItems;
}
if (guard.isArray(collection.items)) {
return collection.items;
}
return [];
}
if (guard.isArray(collection.items)) {
return collection.items;
}
return [];
}
const firstCollectionPage = await this.queryById(firstCollectionPageId);
if (
!guard.isApTypeOf<AP.CollectionPage>(
firstCollectionPage,
AP.CollectionPageTypes,
)
) {
return [];
}
const collectionItems: AP.EntityReference[][] = [];
let nextCollectionPage = firstCollectionPage;
while (nextCollectionPage) {
if (guard.isArray(nextCollectionPage.orderedItems)) {
collectionItems.push(nextCollectionPage.orderedItems);
}
if (guard.isArray(nextCollectionPage.items)) {
collectionItems.push(nextCollectionPage.items);
}
const nextPageId = getId(nextCollectionPage.next);
if (!guard.exists(nextPageId)) {
break;
}
const nextPage = await this.queryById(nextPageId);
const firstCollectionPage = await this.queryById(firstCollectionPageId);
if (
!guard.isApTypeOf<AP.CollectionPage>(nextPage, AP.CollectionPageTypes)
!guard.isApTypeOf<AP.CollectionPage>(
firstCollectionPage,
AP.CollectionPageTypes,
)
) {
break;
return [];
}
nextCollectionPage = nextPage;
}
const collectionItems: AP.EntityReference[][] = [];
return collectionItems.flat();
}
let nextCollectionPage = firstCollectionPage;
while (nextCollectionPage) {
if (guard.isArray(nextCollectionPage.orderedItems)) {
collectionItems.push(nextCollectionPage.orderedItems);
}
if (guard.isArray(nextCollectionPage.items)) {
collectionItems.push(nextCollectionPage.items);
}
const nextPageId = getId(nextCollectionPage.next);
if (!guard.exists(nextPageId)) {
break;
}
const nextPage = await this.queryById(nextPageId);
if (
!guard.isApTypeOf<AP.CollectionPage>(nextPage, AP.CollectionPageTypes)
) {
break;
}
nextCollectionPage = nextPage;
}
return collectionItems.flat();
};

View File

@ -1,22 +0,0 @@
import * as AP from '@activity-kit/types';
import { CoreLibrary } from './adapters';
export async function getPrivateKey(this: CoreLibrary, actor: AP.Actor) {
if (!actor.preferredUsername) {
throw new Error('Actor has no `preferredUsername`.');
}
const userId = await this.findStringIdByValue(
'username',
actor.preferredUsername,
);
const privateKey = await this.findStringValueById('privateKey', userId);
if (!privateKey) {
throw new Error('Private key not found for this Actor.');
}
return privateKey;
}

View File

@ -4,22 +4,27 @@ import { deduplicateUrls, getId } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export async function getRecipientInboxUrls(
this: CoreLibrary,
activity: AP.Activity,
actor: AP.Actor,
inboxesOnly?: boolean,
) {
const recipientUrls = await this.getRecipientUrls(activity);
export const getRecipientInboxUrls: CoreLibrary['getRecipientInboxUrls'] =
async function getRecipientInboxUrls(
this: CoreLibrary,
activity: AP.Activity,
actor: AP.Actor,
inboxesOnly?: boolean,
): Promise<URL[]> {
const recipientUrls = await this.getRecipientUrls(activity);
const recipientInboxUrls = await Promise.all(
recipientUrls.map(async (recipientUrl) => {
return await mapRecipientUrl.bind(this)(recipientUrl, actor, inboxesOnly);
}),
);
const recipientInboxUrls = await Promise.all(
recipientUrls.map(async (recipientUrl) => {
return await mapRecipientUrl.bind(this)(
recipientUrl,
actor,
inboxesOnly,
);
}),
);
return deduplicateUrls(recipientInboxUrls.flat().filter(guard.isUrl));
}
return deduplicateUrls(recipientInboxUrls.flat().filter(guard.isUrl));
};
async function mapRecipientUrl(
this: CoreLibrary,

View File

@ -4,34 +4,37 @@ import { getId, PUBLIC_ACTOR, deduplicateUrls } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export async function getRecipientUrls(
this: CoreLibrary,
activity: AP.Activity,
): Promise<URL[]> {
const tags =
guard.isApCoreObject(activity.object) && activity.object.tag
? getArray(activity.object.tag)
: [];
const mentions = tags.map(getId).filter(guard.isUrl);
export const getRecipientUrls: CoreLibrary['getRecipientUrls'] =
async function getRecipientUrls(
this: CoreLibrary,
activity: AP.Activity,
): Promise<URL[]> {
const tags =
guard.isApCoreObject(activity.object) && activity.object.tag
? getArray(activity.object.tag)
: [];
const mentions = tags.map(getId).filter(guard.isUrl);
const recipients = [
...getArray(activity.to),
...getArray(activity.cc),
...getArray(activity.bto),
...getArray(activity.bcc),
...getArray(activity.audience),
...mentions,
].flat();
const recipients = [
...getArray(activity.to),
...getArray(activity.cc),
...getArray(activity.bto),
...getArray(activity.bcc),
...getArray(activity.audience),
...mentions,
].flat();
const recipientIds = recipients
.map(getId)
.filter(guard.isUrl)
.filter((recipientUrl) => recipientUrl.href !== PUBLIC_ACTOR);
const recipientIds = recipients
.map(getId)
.filter(guard.isUrl)
.filter((recipientUrl) => recipientUrl.href !== PUBLIC_ACTOR);
const actorUrls = await Promise.all(recipientIds.map(getActorIds.bind(this)));
const actorUrls = await Promise.all(
recipientIds.map(getActorIds.bind(this)),
);
return deduplicateUrls(actorUrls.flat());
}
return deduplicateUrls(actorUrls.flat());
};
async function getActorIds(
this: CoreLibrary,

View File

@ -4,34 +4,35 @@ import { getId } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export const getStreamByName = async function (
this: CoreLibrary,
actor: AP.Actor,
name: string,
): Promise<AP.EitherCollection | null> {
if (!actor.streams) {
return null;
}
export const getStreamByName: CoreLibrary['getStreamByName'] =
async function getStreamByName(
this: CoreLibrary,
actor: AP.Actor,
name: string,
): Promise<AP.EitherCollection | null> {
if (!actor.streams) {
return null;
}
const streams = await Promise.all(
actor.streams.map(async (stream: AP.EntityReference) => {
const streamId = getId(stream);
const streams = await Promise.all(
actor.streams.map(async (stream: AP.EntityReference) => {
const streamId = getId(stream);
if (!streamId) {
return null;
}
if (!streamId) {
return null;
}
return await this.queryById(streamId);
}),
);
return await this.queryById(streamId);
}),
);
for (const stream of streams) {
if (guard.isApCollection(stream)) {
if (stream.name === name) {
return stream;
for (const stream of streams) {
if (guard.isApCollection(stream)) {
if (stream.name === name) {
return stream;
}
}
}
}
return null;
};
return null;
};

View File

@ -15,16 +15,12 @@ import { findEntityById } from './findEntityById';
import { fetchEntityById } from './fetchEntityById';
import { queryById } from './queryById';
import { expandEntity } from './expandEntity';
import { getPrivateKey } from './getPrivateKey';
import { getCollectionItems } from './getCollectionItems';
import { getPaginatedCollectionItems } from './getPaginatedCollectionItems';
import { expandCollection } from './expandCollection';
import { getActorByUserId } from './getActorByUserId';
import { getStreamByName } from './getStreamByName';
import { broadcast } from './broadcast';
import { getRecipientUrls } from './getRecipientUrls';
import { getRecipientInboxUrls } from './getRecipientInboxUrls';
import { signAndSendToForeignActorInbox } from './signAndSendToForeignActorInbox';
export class Core implements CoreLibrary {
fetch: FetchPolyfill;
@ -160,7 +156,6 @@ export class Core implements CoreLibrary {
public findEntityById = findEntityById;
public getActorByUserId = getActorByUserId;
public getPrivateKey = getPrivateKey;
public getStreamByName = getStreamByName;
// Fetch.
@ -171,16 +166,13 @@ export class Core implements CoreLibrary {
// Expand.
public expandEntity = expandEntity;
public getCollectionItems = getCollectionItems;
public getPaginatedCollectionItems = getPaginatedCollectionItems;
public expandCollection = expandCollection;
// Broadcast Server-to-Server.
public getRecipientInboxUrls = getRecipientInboxUrls;
public getRecipientUrls = getRecipientUrls;
public broadcast = broadcast;
public signAndSendToForeignActorInbox = signAndSendToForeignActorInbox;
public getRecipientUrls = getRecipientUrls;
}
export {

View File

@ -4,7 +4,7 @@ import { isLocal } from '@activity-kit/utilities';
import { CoreLibrary } from './adapters';
export async function queryById(
export const queryById: CoreLibrary['queryById'] = async function queryById(
this: CoreLibrary,
id: URL,
): Promise<AP.Entity | null> {
@ -29,4 +29,4 @@ export async function queryById(
}
return fetchedEntity;
}
};

View File

@ -1,50 +0,0 @@
import * as AP from '@activity-kit/types';
import { assert } from '@activity-kit/type-utilities';
import {
CONTENT_TYPE_HEADER,
ACTIVITYSTREAMS_CONTENT_TYPE,
ACCEPT_HEADER,
convertEntityToJson,
getId,
} from '@activity-kit/utilities';
import { CoreLibrary } from '.';
export async function signAndSendToForeignActorInbox(
this: CoreLibrary,
foreignActorInbox: URL,
actor: AP.Actor,
activity: AP.Activity,
): Promise<unknown> {
console.log('SENDING TO...', foreignActorInbox.href);
const actorId = getId(actor);
assert.exists(actorId);
const plainActivity = convertEntityToJson(activity);
const { dateHeader, digestHeader, signatureHeader } =
await this.getHttpSignature(
foreignActorInbox,
actorId,
await this.getPrivateKey(actor),
plainActivity,
);
// send
return await this.fetch(foreignActorInbox.href, {
method: 'post',
body: JSON.stringify(plainActivity),
headers: {
[CONTENT_TYPE_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
Host: foreignActorInbox.hostname,
Date: dateHeader,
Digest: digestHeader,
Signature: signatureHeader,
} as Record<string, string>,
}).catch((error) => {
console.log(error);
});
}

View File

@ -90,7 +90,7 @@ export async function saveEntity(this: SqliteDbAdapter, entity: AP.Entity) {
radius: null,
units: null,
describes: null,
...convertEntityToJson(cleanProps(applyContext<AP.Entity>(entity))),
...convertEntityToJson(cleanProps(applyContext(entity))),
_id,
};

View File

@ -1,6 +1,10 @@
import * as AP from '@activity-kit/types';
import { EntityGetEndpoint } from '.';
export declare function handleFoundEntity(this: EntityGetEndpoint, entity: AP.Entity, render: (...args: unknown[]) => Promise<string>): Promise<{
statusCode: number;
body: string;
export declare function handleFoundEntity(
this: EntityGetEndpoint,
entity: AP.Entity,
render: (entity: AP.Entity) => Promise<string>,
): Promise<{
statusCode: number;
body: string;
}>;

View File

@ -0,0 +1,137 @@
import * as AP from '@activity-kit/types';
import { guard } from '@activity-kit/type-utilities';
import { Result } from '../types';
import { EntityGetEndpoint } from '.';
// TODO: Move to config.
const ITEMS_PER_COLLECTION_PAGE = 50;
export async function handleFoundCollectionPage(
this: EntityGetEndpoint,
entity: AP.EitherCollectionPage,
render: (entity: AP.Entity) => Promise<string>,
): Promise<Result> {
// Treat as CollectionPage.
const hasPage = this.url.href.includes('/page/');
const pageParts = this.url.href.split('/page/');
const getPageUrl = (page: number) =>
new URL(
`${this.url.pathname === '/' ? '' : this.url.pathname}/page/${page}`,
this.url.origin,
);
const page = pageParts[1];
const currentPage = page ? Number(page) : 1;
const firstItemIndex = (currentPage - 1) * ITEMS_PER_COLLECTION_PAGE;
const startIndex = firstItemIndex + 1;
if (!hasPage) {
const limitedItems = getCollectionItems(entity).slice(
firstItemIndex,
firstItemIndex + ITEMS_PER_COLLECTION_PAGE,
);
const items = expandItems(limitedItems);
const collectionPage = {
...entity,
id: getPageUrl(currentPage),
url: getPageUrl(currentPage),
partOf: baseUrl,
first: getPageUrl(1),
last: getPageUrl(lastPageIndex),
...(currentPage > 1
? {
prev: getPageUrl(currentPage - 1),
}
: null),
...(currentPage < lastPageIndex
? {
next: getPageUrl(currentPage + 1),
}
: null),
};
if (isOrderedCollection) {
const orderedCollectionPageEntity: AP.OrderedCollectionPage = {
...collectionPage,
type: AP.CollectionPageTypes.ORDERED_COLLECTION_PAGE,
orderedItems: items,
startIndex,
};
return this.handleFoundEntity(orderedCollectionPageEntity, render);
}
const collectionPageEntity: AP.CollectionPage = {
...collectionPage,
type: AP.CollectionPageTypes.COLLECTION_PAGE,
items: items,
};
return this.handleFoundEntity(collectionPageEntity, render);
}
function expandItems(
objects: Array<unknown>,
): Array<AP.Object | AP.Link | AP.Mention> {
return objects.map((object) => {
if (guard.isApLink(object)) {
return object;
}
if (guard.isApMention(object)) {
return object;
}
if (guard.isApObject(object)) {
return {
...object,
id: getId(object),
url: new URL(getId(object)),
};
}
return object;
});
}
function getCollectionItems(collection: AP.EitherCollection) {
if (guard.isArray(collection.orderedItems)) {
return collection.orderedItems;
}
if (guard.isArray(collection.items)) {
return collection.items;
}
return [];
}
function foo() {
const items: AP.Entity[] = [];
for (const item of limitedItems) {
if (guard.isApTransitiveActivity(item)) {
const objectId = getId(item.object);
if (objectId) {
const object = await this.core.findEntityById(objectId);
if (object) {
item.object = object;
}
}
}
if (guard.isApEntity(item)) {
items.push(item);
}
}
return items;
}

View File

@ -4,45 +4,28 @@ import {
cleanProps,
convertEntityToJson,
} from '@activity-kit/utilities';
import { guard } from '@activity-kit/type-utilities';
import { Result } from '../types';
import { EntityGetEndpoint } from '.';
export async function handleFoundEntity(
this: EntityGetEndpoint,
entity: AP.Entity,
render: (...args: unknown[]) => Promise<string>,
) {
render: (entity: AP.Entity) => Promise<string>,
): Promise<Result> {
if (this.returnHtml) {
const expandedEntity = await this.core.expandEntity(entity);
if (guard.isTypeOf<AP.Actor>(expandedEntity, AP.ActorTypes)) {
const outbox = await this.core.expandCollection(expandedEntity.outbox);
if (
guard.isApType<AP.OrderedCollection>(
outbox,
AP.CollectionTypes.ORDERED_COLLECTION,
)
) {
expandedEntity.outbox = outbox;
}
}
return {
statusCode: 200,
body: await render({
entity: expandedEntity,
}),
};
} else {
const json = convertEntityToJson(
cleanProps(applyContext<AP.Entity>(entity)),
);
return {
statusCode: 200,
body: JSON.stringify(json),
body: await render(expandedEntity),
};
}
const json = convertEntityToJson(cleanProps(applyContext(entity)));
return {
statusCode: 200,
body: JSON.stringify(json),
};
}

View File

@ -0,0 +1,8 @@
export async function handleNotFound() {
return {
statusCode: 404,
body: JSON.stringify({
error: 'Not found.',
}),
};
}

View File

@ -1,5 +1,8 @@
import { CoreLibrary } from '@activity-kit/core';
import { handleNotFound } from './handleNotFound';
import { handleFoundEntity } from './handleFoundEntity';
import { handleFoundCollection } from './handleFoundCollection';
import { handleFoundCollectionPage } from './handleFoundCollectionPage';
import { respond } from './respond';
export class EntityGetEndpoint {
@ -14,28 +17,13 @@ export class EntityGetEndpoint {
},
) {
this.url = options.url;
this.returnHtml = options.returnHtml;
this.returnHtml = options.returnHtml ?? false;
}
protected handleNotFound = handleNotFound;
protected handleFoundEntity = handleFoundEntity;
protected handleBadRequest() {
return {
statusCode: 500,
body: JSON.stringify({
error: 'Bad request',
}),
};
}
protected handleNotFound() {
return {
statusCode: 404,
body: JSON.stringify({
error: 'Not found',
}),
};
}
protected handleFoundCollection = handleFoundCollection;
protected handleFoundCollectionPage = handleFoundCollectionPage;
public respond = respond;
}

View File

@ -1,164 +1,81 @@
import * as AP from '@activity-kit/types';
import { guard, assert } from '@activity-kit/type-utilities';
import { guard } from '@activity-kit/type-utilities';
import { Result } from '../types';
import { EntityGetEndpoint } from '.';
// TODO: Move to config.
const ITEMS_PER_COLLECTION_PAGE = 50;
export async function respond(
this: EntityGetEndpoint,
render: (args: { entity: AP.Entity }) => Promise<string>,
): Promise<{
statusCode: number;
contentType?: string;
body: string;
}> {
render: (entity: AP.Entity) => Promise<string>,
): Promise<Result> {
const hasPage = this.url.href.includes('/page/');
const pageParts = this.url.href.split('/page/');
const baseUrl = hasPage ? new URL(pageParts[0]) : this.url;
const entity = await this.core.findEntityById(baseUrl);
try {
assert.isApEntity(entity);
} catch (error) {
return this.handleNotFound();
if (!entity || !guard.isApEntity(entity)) {
return await this.handleNotFound();
}
if (
!guard.isTypeOf<AP.EitherCollection>(entity, AP.CollectionTypes) &&
!guard.isTypeOf<AP.EitherCollectionPage>(entity, AP.CollectionPageTypes)
) {
return this.handleFoundEntity(entity, render);
if (guard.isApCollection(entity)) {
return handleCollection.bind(this)(entity, render);
}
assert.isApCollection(entity);
const totalItems = Number(entity.totalItems);
return await this.handleFoundEntity(entity, render);
}
async function handleCollection(
this: EntityGetEndpoint,
entity: AP.EitherCollection,
render: (entity: AP.Entity) => Promise<string>,
): Promise<Result> {
const hasPage = this.url.href.includes('/page/');
const totalItems = entity.totalItems ?? 0;
const lastPageIndex = Math.max(
1,
Math.ceil(totalItems / ITEMS_PER_COLLECTION_PAGE),
);
const isOrderedCollection = guard.isApType<AP.OrderedCollection>(
entity,
AP.CollectionTypes.ORDERED_COLLECTION,
);
const getPageUrl = (page: number) =>
new URL(
`${this.url.pathname === '/' ? '' : this.url.pathname}/page/${page}`,
this.url.origin,
);
// Treat as a Collection.
const page = pageParts[1];
const currentPage = page ? Number(page) : 1;
const firstItemIndex = (currentPage - 1) * ITEMS_PER_COLLECTION_PAGE;
const startIndex = firstItemIndex + 1;
if (!hasPage) {
assert.isApCollection(entity);
delete entity.orderedItems;
delete entity.items;
const collectionEntity = {
...entity,
first: getPageUrl(1),
last: getPageUrl(lastPageIndex),
};
return this.handleFoundEntity(collectionEntity, render);
}
// Treat as CollectionPage.
const expandedCollection = await this.core.expandCollection(entity);
const expandedItems = (() => {
if (
Array.isArray(expandedCollection.type)
? expandedCollection.type.includes(
AP.CollectionTypes.ORDERED_COLLECTION,
)
: expandedCollection.type === AP.CollectionTypes.ORDERED_COLLECTION
) {
return expandedCollection.orderedItems;
}
if (
Array.isArray(expandedCollection.type)
? expandedCollection.type.includes(AP.CollectionTypes.COLLECTION)
: expandedCollection.type === AP.CollectionTypes.COLLECTION
) {
return expandedCollection.items;
}
})();
assert.isArray(expandedItems);
const limitedItems = expandedItems.slice(
firstItemIndex,
firstItemIndex + ITEMS_PER_COLLECTION_PAGE,
);
const items: AP.Entity[] = [];
for (const item of limitedItems) {
if (item && !(item instanceof URL)) {
if (
guard.isTypeOf<AP.Activity>(item, AP.ActivityTypes) &&
'object' in item &&
item.object instanceof URL
) {
const object = await this.core.findEntityById(item.object);
if (object) {
item.object = object;
}
}
items.push(item);
}
}
const collectionPage = {
const collectionEntity = {
...entity,
id: getPageUrl(currentPage),
url: getPageUrl(currentPage),
partOf: baseUrl,
first: getPageUrl(1),
last: getPageUrl(lastPageIndex),
...(currentPage > 1
? {
prev: getPageUrl(currentPage - 1),
}
: null),
...(currentPage < lastPageIndex
? {
next: getPageUrl(currentPage + 1),
}
: null),
totalItems,
first: getPageUrl.bind(this)(1),
last: getPageUrl.bind(this)(lastPageIndex),
};
if (isOrderedCollection) {
if (!hasPage) {
delete collectionEntity.orderedItems;
delete collectionEntity.items;
return await this.handleFoundCollection(collectionEntity, render);
}
if (guard.isApType(entity, AP.CollectionTypes.ORDERED_COLLECTION)) {
const orderedCollectionPageEntity: AP.OrderedCollectionPage = {
...collectionPage,
...collectionEntity,
type: AP.CollectionPageTypes.ORDERED_COLLECTION_PAGE,
orderedItems: items,
startIndex,
};
return this.handleFoundEntity(orderedCollectionPageEntity, render);
return await this.handleFoundCollectionPage(
orderedCollectionPageEntity,
render,
);
}
const collectionPageEntity: AP.CollectionPage = {
...collectionPage,
...collectionEntity,
type: AP.CollectionPageTypes.COLLECTION_PAGE,
items: items,
};
return this.handleFoundEntity(collectionPageEntity, render);
return await this.handleFoundCollectionPage(collectionPageEntity, render);
}
function getPageUrl(this: EntityGetEndpoint, page: number) {
const pathname = this.url.pathname === '/' ? '' : this.url.pathname;
const pageUrl = `${pathname}/page/${page}`;
return new URL(pageUrl, this.url.origin);
}

View File

@ -60,9 +60,7 @@ export const respond = async function (
) {
this.res.setHeader(CONTENT_TYPE_HEADER, ACTIVITYSTREAMS_CONTENT_TYPE);
this.res.write(
JSON.stringify(
convertEntityToJson(cleanProps(applyContext<AP.Actor>(actor))),
),
JSON.stringify(convertEntityToJson(cleanProps(applyContext(actor)))),
);
} else {
this.res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE);

View File

@ -97,7 +97,7 @@ export async function handleFollow(
)}`;
const publishedDate = new Date();
const acceptActivity = applyContext<AP.Accept>({
const acceptActivity = applyContext({
id: new URL(acceptActivityId),
url: new URL(acceptActivityId),
type: AP.ActivityTypes.ACCEPT,

View File

@ -64,7 +64,7 @@ export async function handleCreate(
})}`,
);
const objectReplies = applyContext<AP.OrderedCollection>({
const objectReplies = applyContext({
id: objectRepliesId,
url: objectRepliesId,
name: 'Replies',
@ -83,7 +83,7 @@ export async function handleCreate(
})}`,
);
const objectLikes = applyContext<AP.OrderedCollection>({
const objectLikes = applyContext({
id: objectLikesId,
url: objectLikesId,
name: 'Likes',
@ -102,7 +102,7 @@ export async function handleCreate(
})}`,
);
const objectShares = applyContext<AP.OrderedCollection>({
const objectShares = applyContext({
id: objectSharesId,
url: objectSharesId,
name: 'Shares',

View File

@ -18,9 +18,9 @@ export async function wrapInActivity(
const actorId = getId(this.actor);
assert.exists(actorId);
assert.isUrl(actorId);
return applyContext<AP.Create>(
return applyContext(
this.combineAddresses({
id,
url: id,

View File

@ -0,0 +1,5 @@
export interface Result {
statusCode: number;
contentType?: string;
body: string;
}

View File

@ -51,7 +51,7 @@ export async function parseBody(this: UploadMediaPostEndpoint) {
})}`,
);
const object = applyContext<AP.ExtendedObject>({
const object = applyContext({
to: new URL(PUBLIC_ACTOR),
type: getType(this.file.mimetype),
mediaType: this.file.mimetype,
@ -60,7 +60,7 @@ export async function parseBody(this: UploadMediaPostEndpoint) {
attributedTo: this.actor.id,
});
const activity = applyContext<AP.Create>({
const activity = applyContext({
to: new URL(PUBLIC_ACTOR),
type: AP.ActivityTypes.CREATE,
id: activityId,

View File

@ -26,7 +26,7 @@ export async function saveActivity(this: UploadMediaPostEndpoint) {
entityRoute,
});
const objectReplies = applyContext<AP.Collection>({
const objectReplies = applyContext({
id: objectRepliesId,
url: objectRepliesId,
name: 'Replies',
@ -40,7 +40,7 @@ export async function saveActivity(this: UploadMediaPostEndpoint) {
entityRoute,
});
const objectLikes = applyContext<AP.OrderedCollection>({
const objectLikes = applyContext({
id: objectLikesId,
url: objectLikesId,
name: 'Likes',
@ -54,7 +54,7 @@ export async function saveActivity(this: UploadMediaPostEndpoint) {
entityRoute,
});
const objectShares = applyContext<AP.OrderedCollection>({
const objectShares = applyContext({
id: objectSharesId,
url: objectSharesId,
name: 'Shares',

View File

@ -31,7 +31,7 @@ export async function createServerActor(this: UserPostEndpoint) {
entityRoute,
});
const botInbox = applyContext<AP.OrderedCollection>({
const botInbox = applyContext({
id: inboxId,
url: inboxId,
type: AP.CollectionTypes.ORDERED_COLLECTION,
@ -45,7 +45,7 @@ export async function createServerActor(this: UserPostEndpoint) {
entityRoute,
});
const botOutbox = applyContext<AP.OrderedCollection>({
const botOutbox = applyContext({
id: outboxId,
url: outboxId,
type: AP.CollectionTypes.ORDERED_COLLECTION,
@ -59,7 +59,7 @@ export async function createServerActor(this: UserPostEndpoint) {
entityRoute,
});
const botFollowers = applyContext<AP.Collection>({
const botFollowers = applyContext({
id: followersId,
url: followersId,
name: 'Followers',
@ -74,7 +74,7 @@ export async function createServerActor(this: UserPostEndpoint) {
entityRoute,
});
const botFollowing = applyContext<AP.Collection>({
const botFollowing = applyContext({
id: followingId,
url: followingId,
name: 'Following',
@ -89,7 +89,7 @@ export async function createServerActor(this: UserPostEndpoint) {
entityRoute,
});
const botHashtags = applyContext<AP.Collection>({
const botHashtags = applyContext({
id: hashtagsId,
url: hashtagsId,
name: 'Hashtags',
@ -100,7 +100,7 @@ export async function createServerActor(this: UserPostEndpoint) {
published: publishedDate,
});
const botActor = applyContext<AP.Actor>({
const botActor = applyContext({
id: userId,
url: userId,
type: AP.ActorTypes.APPLICATION,

View File

@ -42,7 +42,7 @@ export async function createUserActor(
entityRoute,
});
const userInbox = applyContext<AP.OrderedCollection>({
const userInbox = applyContext({
id: inboxId,
url: inboxId,
name: 'Inbox',
@ -57,7 +57,7 @@ export async function createUserActor(
entityRoute,
});
const userOutbox = applyContext<AP.OrderedCollection>({
const userOutbox = applyContext({
id: outboxId,
url: outboxId,
name: 'Outbox',
@ -72,7 +72,7 @@ export async function createUserActor(
entityRoute,
});
const userFollowers = applyContext<AP.Collection>({
const userFollowers = applyContext({
id: followersId,
url: followersId,
name: 'Followers',
@ -87,7 +87,7 @@ export async function createUserActor(
entityRoute,
});
const userFollowing = applyContext<AP.Collection>({
const userFollowing = applyContext({
id: followingId,
url: followingId,
name: 'Following',
@ -102,7 +102,7 @@ export async function createUserActor(
entityRoute,
});
const userLiked = applyContext<AP.OrderedCollection>({
const userLiked = applyContext({
id: likedId,
url: likedId,
name: 'Liked',
@ -118,7 +118,7 @@ export async function createUserActor(
slug: 'shared',
});
const userShared = applyContext<AP.OrderedCollection>({
const userShared = applyContext({
id: sharedId,
url: sharedId,
name: 'Shared',
@ -134,7 +134,7 @@ export async function createUserActor(
slug: 'blocks',
});
const userBlocks = applyContext<AP.Collection>({
const userBlocks = applyContext({
id: blocksId,
url: blocksId,
name: 'Blocks',
@ -150,7 +150,7 @@ export async function createUserActor(
slug: 'requests',
});
const userRequests = applyContext<AP.Collection>({
const userRequests = applyContext({
id: userRequestsId,
url: userRequestsId,
name: 'Requests',
@ -166,7 +166,7 @@ export async function createUserActor(
slug: 'lists',
});
const userLists = applyContext<AP.Collection>({
const userLists = applyContext({
id: userListsId,
url: userListsId,
name: 'Lists',
@ -184,7 +184,7 @@ export async function createUserActor(
slug: 'bookmarks',
});
const userBookmarks = applyContext<AP.OrderedCollection>({
const userBookmarks = applyContext({
id: userBookmarksId,
url: userBookmarksId,
name: 'Bookmarks',
@ -256,7 +256,7 @@ export async function createUserActor(
guid: await this.core.getGuid(),
});
const createActorActivity = applyContext<AP.Create>({
const createActorActivity = applyContext({
id: createActorActivityId,
url: createActorActivityId,
type: AP.ActivityTypes.CREATE,
@ -299,7 +299,7 @@ export async function createUserActor(
declaredStreams.push(
this.core.saveEntity(
applyContext<AP.OrderedCollection>({
applyContext({
type: AP.CollectionTypes.ORDERED_COLLECTION,
totalItems: 0,
attributedTo: userId,

View File

@ -20,7 +20,8 @@ export declare function isApActivity(value: unknown): asserts value is AP.Activi
export declare function isApCoreObject(value: unknown): asserts value is AP.CoreObject;
export declare function isApExtendedObject(value: unknown): asserts value is AP.ExtendedObject;
export declare function isApActor(value: unknown): asserts value is AP.Actor;
export declare function isApCollection(value: unknown): asserts value is AP.Collection | AP.OrderedCollection;
export declare function isApCollection(value: unknown): asserts value is AP.EitherCollection;
export declare function isApCollectionPage(value: unknown): asserts value is AP.EitherCollectionPage;
export declare function isApTransitiveActivity(value: unknown): asserts value is AP.TransitiveActivity<AP.AnyTransitiveActivityType>;
export declare function isApType<T extends AP.Entity>(value: unknown, type: string): asserts value is T;
export declare function isApTypeOf<T extends AP.Entity>(value: unknown, comparison: Record<string, string>): asserts value is T;

View File

@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollectionPage = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
const guard = __importStar(require("./guard"));
function exists(value) {
if (!guard.exists(value)) {
@ -127,6 +127,12 @@ function isApCollection(value) {
}
}
exports.isApCollection = isApCollection;
function isApCollectionPage(value) {
if (!guard.isApCollectionPage(value)) {
throw new Error(`"${value}" is not a CollectionPage`);
}
}
exports.isApCollectionPage = isApCollectionPage;
function isApTransitiveActivity(value) {
if (!guard.isApTransitiveActivity(value)) {
throw new Error(`"${value}" is not a Transitive Activity`);

View File

@ -1 +1 @@
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AAEjC,SAAgB,MAAM,CACpB,KAAc;IAEd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,yBAAyB,CAAC,CAAC;KACrD;AACH,CAAC;AAND,wBAMC;AAED,SAAgB,QAAQ,CAAC,KAAc;IAC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KAAc,EACd,UAAkC;IAElC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAI,KAAK,EAAE,UAAU,CAAC,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,qCAAqC,CAAC,CAAC;KACjE;AACH,CAAC;AAPD,gCAOC"}

View File

@ -21,6 +21,7 @@ export declare function isApCoreObject(value: unknown): AP.CoreObject | undefine
export declare function isApExtendedObject(value: unknown): AP.ExtendedObject | undefined;
export declare function isApActor(value: unknown): AP.Actor | undefined;
export declare function isApCollection(value: unknown): AP.EitherCollection | undefined;
export declare function isApCollectionPage(value: unknown): AP.EitherCollectionPage | undefined;
export declare function isApTransitiveActivity(value: unknown): AP.TransitiveActivity<AP.AnyTransitiveActivityType> | undefined;
export declare function isApType<T extends AP.Entity>(value: unknown, type: string): T | undefined;
export declare function isApTypeOf<T extends AP.Entity>(value: unknown, comparison: Record<string, string>): T | undefined;

View File

@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isNumber = exports.isBoolean = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollectionPage = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isNumber = exports.isBoolean = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
const guard = __importStar(require("./guard"));
function exists(value) {
return guard.exists(value) ? value : undefined;
@ -93,6 +93,10 @@ function isApCollection(value) {
return guard.isApCollection(value) ? value : undefined;
}
exports.isApCollection = isApCollection;
function isApCollectionPage(value) {
return guard.isApCollectionPage(value) ? value : undefined;
}
exports.isApCollectionPage = isApCollectionPage;
function isApTransitiveActivity(value) {
return guard.isApTransitiveActivity(value) ? value : undefined;
}

View File

@ -1 +1 @@
{"version":3,"file":"cast.js","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AAEjC,SAAgB,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAFD,wBAEC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC;AAFD,sCAEC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAFD,8BAEC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,MAAM,CAAC,KAAc;IAC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K,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC;AAJD,wCAIC;AAED,SAAgB,kBAAkB,CAChC,KAAc;IAEd,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC;AAJD,gDAIC;AAED,SAAgB,sBAAsB,CACpC,KAAc;IAEd,OAAO,KAAK,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAJD,wDAIC;AAED,SAAgB,QAAQ,CACtB,KAAc,EACd,IAAY;IAEZ,OAAO,KAAK,CAAC,QAAQ,CAAI,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5D,CAAC;AALD,4BAKC;AAED,SAAgB,UAAU,CACxB,KAAc,EACd,UAAkC;IAElC,OAAO,KAAK,CAAC,UAAU,CAAI,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC;AALD,gCAKC"}

View File

@ -20,7 +20,8 @@ export declare function isApActivity(value: unknown): value is AP.Activity;
export declare function isApCoreObject(value: unknown): value is AP.CoreObject;
export declare function isApExtendedObject(value: unknown): value is AP.ExtendedObject;
export declare function isApActor(value: unknown): value is AP.Actor;
export declare function isApCollection(value: unknown): value is AP.Collection | AP.OrderedCollection;
export declare function isApCollection(value: unknown): value is AP.EitherCollection;
export declare function isApCollectionPage(value: unknown): value is AP.EitherCollectionPage;
export declare function isApTransitiveActivity(value: unknown): value is AP.TransitiveActivity<AP.AnyTransitiveActivityType>;
export declare function isApType<T extends AP.Entity>(value: unknown, type: string): value is T;
export declare function isApTypeOf<T extends AP.Entity>(value: unknown, comparison: Record<string, string>): value is T;

View File

@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollectionPage = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
const narrow = __importStar(require("./narrow"));
function exists(value) {
return narrow.exists(value);
@ -93,6 +93,10 @@ function isApCollection(value) {
return narrow.isApCollection(value);
}
exports.isApCollection = isApCollection;
function isApCollectionPage(value) {
return narrow.isApCollectionPage(value);
}
exports.isApCollectionPage = isApCollectionPage;
function isApTransitiveActivity(value) {
return narrow.isApTransitiveActivity(value);
}

View File

@ -1 +1 @@
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAAmC;AAEnC,SAAgB,MAAM,CACpB,KAAc;IAEd,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAJD,wBAIC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAFD,4BAEC;AAED,SAAgB,aAAa,CAC3B,KAAc;IAEd,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAJD,sCAIC;AAED,SAA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C;AAED,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AAFD,8BAEC;AAED,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAFD,wCAEC;AAED,SAAgB,kBAAkB,CAChC,KAAc;IAEd,OAAO,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAJD,gDAIC;AAED,SAAgB,sBAAsB,CACpC,KAAc;IAEd,OAAO,MAAM,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAJD,wDAIC;AAED,SAAgB,QAAQ,CACtB,KAAc,EACd,IAAY;IAEZ,OAAO,MAAM,CAAC,QAAQ,CAAI,KAAK,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AALD,4BAKC;AAED,SAAgB,UAAU,CACxB,KAAc,EACd,UAAkC;IAElC,OAAO,MAAM,CAAC,UAAU,CAAI,KAAK,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AALD,gCAKC"}

View File

@ -16,6 +16,7 @@ export declare function isApCoreObject(value: unknown): boolean;
export declare function isApExtendedObject(value: unknown): boolean;
export declare function isApActor(value: unknown): boolean;
export declare function isApCollection(value: unknown): boolean;
export declare function isApCollectionPage(value: unknown): boolean;
export declare function isApTransitiveActivity(value: unknown): boolean;
export declare function isApType<T extends AP.Entity>(value: unknown, type: string): boolean;
export declare function isApTypeOf<T extends AP.Entity>(value: unknown, comparison: Record<string, string>): boolean;

View File

@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
exports.isApTypeOf = exports.isApType = exports.isApTransitiveActivity = exports.isApCollectionPage = exports.isApCollection = exports.isApActor = exports.isApExtendedObject = exports.isApCoreObject = exports.isApActivity = exports.isApEntity = exports.hasApType = exports.hasType = exports.isArray = exports.isUrl = exports.isDate = exports.isBoolean = exports.isNumber = exports.isString = exports.isPlainObject = exports.isObject = exports.exists = void 0;
const AP = __importStar(require("@activity-kit/types"));
function isType(entity, type) {
if (!entity || typeof entity !== 'object') {
@ -108,6 +108,11 @@ function isApCollection(value) {
isTypeOf(value, AP.CollectionTypes));
}
exports.isApCollection = isApCollection;
function isApCollectionPage(value) {
return (isApEntity(value) &&
isTypeOf(value, AP.CollectionPageTypes));
}
exports.isApCollectionPage = isApCollectionPage;
function isApTransitiveActivity(value) {
return (typeof value === 'object' &&
value !== null &&

View File

@ -1 +1 @@
{"version":3,"file":"narrow.js","sourceRoot":"","sources":["../src/narrow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAE1C,SAAS,MAAM,CAAsB,MAAe,EAAE,IAAY;IAChE,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QACzC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,UAAU,GAAuB,MAAY,CAAC,IAAI,CAAC;IAEzD,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAC9B,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC3B,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;AAC1B,CAAC;AAED,SAAS,QAAQ,CACf,MAAe,EACf,KAA6B;IAE7B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAI,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC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,CAAC;AAPD,wDAOC;AAED,SAAgB,QAAQ,CAAsB,KAAc,EAAE,IAAY;IACxE,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,MAAM,CAAI,KAAK,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAFD,4BAEC;AAED,SAAgB,UAAU,CACxB,KAAc,EACd,UAAkC;IAElC,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAI,KAAK,EAAE,UAAU,CAAC,CAAC;AAC7D,CAAC;AALD,gCAKC"}

View File

@ -109,12 +109,20 @@ export function isApActor(value: unknown): asserts value is AP.Actor {
export function isApCollection(
value: unknown,
): asserts value is AP.Collection | AP.OrderedCollection {
): asserts value is AP.EitherCollection {
if (!guard.isApCollection(value)) {
throw new Error(`"${value}" is not a Collection`);
}
}
export function isApCollectionPage(
value: unknown,
): asserts value is AP.EitherCollectionPage {
if (!guard.isApCollectionPage(value)) {
throw new Error(`"${value}" is not a CollectionPage`);
}
}
export function isApTransitiveActivity(
value: unknown,
): asserts value is AP.TransitiveActivity<AP.AnyTransitiveActivityType> {

View File

@ -77,6 +77,12 @@ export function isApCollection(
return guard.isApCollection(value) ? value : undefined;
}
export function isApCollectionPage(
value: unknown,
): AP.EitherCollectionPage | undefined {
return guard.isApCollectionPage(value) ? value : undefined;
}
export function isApTransitiveActivity(
value: unknown,
): AP.TransitiveActivity<AP.AnyTransitiveActivityType> | undefined {

View File

@ -71,12 +71,16 @@ export function isApActor(value: unknown): value is AP.Actor {
return narrow.isApActor(value);
}
export function isApCollection(
value: unknown,
): value is AP.Collection | AP.OrderedCollection {
export function isApCollection(value: unknown): value is AP.EitherCollection {
return narrow.isApCollection(value);
}
export function isApCollectionPage(
value: unknown,
): value is AP.EitherCollectionPage {
return narrow.isApCollectionPage(value);
}
export function isApTransitiveActivity(
value: unknown,
): value is AP.TransitiveActivity<AP.AnyTransitiveActivityType> {

View File

@ -98,6 +98,13 @@ export function isApCollection(value: unknown) {
);
}
export function isApCollectionPage(value: unknown) {
return (
isApEntity(value) &&
isTypeOf<AP.EitherCollectionPage>(value, AP.CollectionPageTypes)
);
}
export function isApTransitiveActivity(value: unknown) {
return (
typeof value === 'object' &&

View File

@ -1,2 +1,2 @@
import * as AP from '@activity-kit/types';
export declare function applyContext<T>(entity: AP.Entity): T | undefined;
export declare function applyContext(entity: AP.Entity): AP.Entity;

View File

@ -1,35 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyContext = void 0;
const AP = __importStar(require("@activity-kit/types"));
const type_utilities_1 = require("@activity-kit/type-utilities");
const globals_1 = require("./globals");
function applyContext(entity) {
if (type_utilities_1.guard.isApTypeOf(entity, AP.ActorTypes)) {
if (!entity['@context']) {
if (!entity['@context']) {
if (type_utilities_1.guard.isApActor(entity)) {
entity['@context'] = [
new URL(globals_1.ACTIVITYSTREAMS_CONTEXT),
new URL(globals_1.W3ID_SECURITY_CONTEXT),
@ -40,14 +16,11 @@ function applyContext(entity) {
},
];
}
return entity;
}
if (type_utilities_1.guard.isApTypeOf(entity, AP.AllTypes)) {
if (!entity['@context']) {
else {
entity['@context'] = new URL(globals_1.ACTIVITYSTREAMS_CONTEXT);
}
return entity;
}
return entity;
}
exports.applyContext = applyContext;
//# sourceMappingURL=applyContext.js.map

View File

@ -1 +1 @@
{"version":3,"file":"applyContext.js","sourceRoot":"","sources":["../src/applyContext.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,iEAAqD;AACrD,uCAA2E;AAE3E,SAAgB,YAAY,CAAI,MAAiB;IAC/C,IAAI,sBAAK,CAAC,UAAU,CAAe,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE;QACzD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;YACvB,MAAM,CAAC,UAAU,CAAC,GAAG;gBACnB,IAAI,GAAG,CAAC,iCAAuB,CAAC;gBAChC,IAAI,GAAG,CAAC,+BAAqB,CAAC;gBAC9B;oBACE,sBAAsB,EAAE,IAAI,GAAG,CAAC,kCAAkC,CAAC;oBACnE,cAAc,EAAE,IAAI,GAAG,CAAC,0BAA0B,CAAC;oBACnD,aAAa,EAAE,IAAI,GAAG,CAAC,yBAAyB,CAAC;iBAClD;aACF,CAAC;SACH;QAED,OAAO,MAAM,CAAC;KACf;IAED,IAAI,sBAAK,CAAC,UAAU,CAAgB,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE;QACxD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;YACvB,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,iCAAuB,CAAC,CAAC;SACvD;QAED,OAAO,MAAM,CAAC;KACf;AACH,CAAC;AAxBD,oCAwBC"}
{"version":3,"file":"applyContext.js","sourceRoot":"","sources":["../src/applyContext.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,uCAA2E;AAE3E,SAAgB,YAAY,CAAC,MAAiB;IAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACvB,IAAI,sBAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;YAC3B,MAAM,CAAC,UAAU,CAAC,GAAG;gBACnB,IAAI,GAAG,CAAC,iCAAuB,CAAC;gBAChC,IAAI,GAAG,CAAC,+BAAqB,CAAC;gBAC9B;oBACE,sBAAsB,EAAE,IAAI,GAAG,CAAC,kCAAkC,CAAC;oBACnE,cAAc,EAAE,IAAI,GAAG,CAAC,0BAA0B,CAAC;oBACnD,aAAa,EAAE,IAAI,GAAG,CAAC,yBAAyB,CAAC;iBAClD;aACF,CAAC;SACH;aAAM;YACL,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,iCAAuB,CAAC,CAAC;SACvD;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,oCAkBC"}

View File

@ -2,14 +2,14 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanProps = void 0;
function cleanProps(entity) {
const result = { ...entity };
if ('bto' in result) {
delete result.bto;
const cleanedEntity = { ...entity };
if ('bto' in cleanedEntity) {
delete cleanedEntity.bto;
}
if ('bcc' in result) {
delete result.bcc;
if ('bcc' in cleanedEntity) {
delete cleanedEntity.bcc;
}
return result;
return cleanedEntity;
}
exports.cleanProps = cleanProps;
//# sourceMappingURL=cleanProps.js.map

Some files were not shown because too many files have changed in this diff Show More