major fixes
This commit is contained in:
parent
55b9b469df
commit
65548f96c7
|
@ -1,3 +1,4 @@
|
|||
node_modules/
|
||||
lerna-debug.log
|
||||
.vscode
|
||||
.vscode
|
||||
dist/
|
|
@ -3663,6 +3663,12 @@
|
|||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/@types/isomorphic-fetch": {
|
||||
"version": "0.0.36",
|
||||
"resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.36.tgz",
|
||||
"integrity": "sha512-ulw4d+vW1HKn4oErSmNN2HYEcHGq0N1C5exlrMM0CRqX1UUpFhGb5lwiom5j9KN3LBJJDLRmYIZz1ghm7FIzZw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.11",
|
||||
"dev": true,
|
||||
|
@ -11447,6 +11453,15 @@
|
|||
"node": ">=12.20"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript-bundle": {
|
||||
"version": "1.0.18",
|
||||
"resolved": "https://registry.npmjs.org/typescript-bundle/-/typescript-bundle-1.0.18.tgz",
|
||||
"integrity": "sha512-ZtzMZPzW3bnL4c+jBjgSHxlnW9TdWQjFS5RLk4k0YJb85zv78rdslf13mKXUgHZjTeEyO8R59IQ4WqSdlEXhAw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc-bundle": "tsc-bundle"
|
||||
}
|
||||
},
|
||||
"node_modules/uc.micro": {
|
||||
"version": "1.0.6",
|
||||
"license": "MIT",
|
||||
|
@ -12045,11 +12060,13 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/formidable": "^2.0.5",
|
||||
"@types/isomorphic-fetch": "^0.0.36",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
},
|
||||
"packages/crypto-node": {
|
||||
|
@ -12251,23 +12268,22 @@
|
|||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
},
|
||||
"packages/types": {
|
||||
"name": "@activity-kit/types",
|
||||
"version": "0.4.56",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"formidable": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsonld": "^1.5.9",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
},
|
||||
"packages/utilities": {
|
||||
|
@ -12285,7 +12301,8 @@
|
|||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -8,7 +8,7 @@ export async function createUser(
|
|||
preferredUsername,
|
||||
}: {
|
||||
email: string;
|
||||
password?: string;
|
||||
password: string;
|
||||
preferredUsername: string;
|
||||
},
|
||||
) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { Core } from '.';
|
||||
export declare function broadcast(this: Core, activity: AP.Activity, actor: AP.Actor): Promise<unknown>;
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
"use strict";
|
||||
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 publicActivity = (0, utilities_1.cleanProps)((0, utilities_1.applyContext)(activity));
|
||||
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);
|
||||
console.log({
|
||||
recipients,
|
||||
});
|
||||
const results = await Promise.all(recipients.map(async (recipient) => {
|
||||
return await this.signAndSendToForeignActorInbox(recipient, actor, publicActivity);
|
||||
}));
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":";;;AAEA,uDAAmE;AAO5D,KAAK,UAAU,SAAS,CAE7B,QAAqB,EACrB,KAAe;IAEf,MAAM,cAAc,GAAG,IAAA,sBAAU,EAAC,IAAA,wBAAY,EAAc,QAAQ,CAAC,CAAC,CAAC;IAEvE,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,OAAO,CAAC,GAAG,CAAC;QACV,UAAU;KACX,CAAC,CAAC;IAEH,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,8BA4BC"}
|
||||
{"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,8BA4BC"}
|
|
@ -1,3 +1,3 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function expandCollection(this: Core, collection: AP.EitherCollectionReference): Promise<null | AP.EitherCollection>;
|
||||
import { Core } from '.';
|
||||
export declare function expandCollection(this: Core, collection: AP.EitherCollectionReference): Promise<AP.EitherCollection | null>;
|
||||
|
|
|
@ -1,62 +1,31 @@
|
|||
"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.expandCollection = 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 expandCollection(collection) {
|
||||
const id = (0, utilities_1.getId)(collection);
|
||||
if (!id) {
|
||||
if (!type_utilities_1.guard.isApCollection(collection)) {
|
||||
return null;
|
||||
}
|
||||
const foundEntity = await this.queryById(id);
|
||||
if (!foundEntity) {
|
||||
return null;
|
||||
const items = this.getCollectionItems(collection);
|
||||
const expandedItems = await Promise.all(items.map(async (item) => {
|
||||
var _a;
|
||||
if (type_utilities_1.guard.isApEntity(item)) {
|
||||
return item;
|
||||
}
|
||||
return (_a = (await this.queryById(item))) !== null && _a !== void 0 ? _a : item;
|
||||
}));
|
||||
if (type_utilities_1.guard.isArray(collection.orderedItems) &&
|
||||
collection.orderedItems.length) {
|
||||
return {
|
||||
...collection,
|
||||
orderedItems: expandedItems,
|
||||
};
|
||||
}
|
||||
if (type_utilities_1.guard.isTypeOf(foundEntity, AP.CollectionTypes)) {
|
||||
const items = await this.getCollectionItems(foundEntity);
|
||||
if (!items) {
|
||||
return foundEntity;
|
||||
}
|
||||
if (Array.isArray(foundEntity.type)
|
||||
? foundEntity.type.includes(AP.CollectionTypes.ORDERED_COLLECTION)
|
||||
: foundEntity.type === AP.CollectionTypes.ORDERED_COLLECTION) {
|
||||
return {
|
||||
...foundEntity,
|
||||
orderedItems: items,
|
||||
};
|
||||
}
|
||||
if (Array.isArray(foundEntity.type)
|
||||
? foundEntity.type.includes(AP.CollectionTypes.COLLECTION)
|
||||
: foundEntity.type === AP.CollectionTypes.COLLECTION) {
|
||||
return {
|
||||
...foundEntity,
|
||||
items,
|
||||
};
|
||||
}
|
||||
else if (type_utilities_1.guard.isArray(collection.items) && collection.items.length) {
|
||||
return {
|
||||
...collection,
|
||||
items: expandedItems,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"expandCollection.js","sourceRoot":"","sources":["../src/expandCollection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAqD;AACrD,uDAAgD;AAEzC,KAAK,UAAU,gBAAgB,CAEpC,UAAwC;IAExC,MAAM,EAAE,GAAG,IAAA,iBAAK,EAAC,UAAU,CAAC,CAAC;IAE7B,IAAI,CAAC,EAAE,EAAE;QACP,OAAO,IAAI,CAAC;KACb;IAED,MAAM,WAA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C,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CACrC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;;QACvB,IAAI,sBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC1B,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAA,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,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,IAAI,CAAC;AACd,CAAC;AApCD,4CAoCC"}
|
|
@ -1,71 +1,45 @@
|
|||
"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.expandEntity = 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");
|
||||
const selfReferentialKeys = [
|
||||
'@context',
|
||||
'_id',
|
||||
'id',
|
||||
'type',
|
||||
'url',
|
||||
'href',
|
||||
'publicKey',
|
||||
];
|
||||
async function expandEntity(entity) {
|
||||
const expandEntry = async (key, value) => {
|
||||
if (key === '_id' ||
|
||||
key === 'id' ||
|
||||
key === 'url' ||
|
||||
key === 'type' ||
|
||||
key === '@context' ||
|
||||
key === 'publicKey') {
|
||||
return value;
|
||||
}
|
||||
else if (value instanceof URL) {
|
||||
if (value.toString() === utilities_1.PUBLIC_ACTOR) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
const foundEntity = await this.queryById(value);
|
||||
return foundEntity ?? value;
|
||||
}
|
||||
catch (error) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
return await Promise.all(value.map(async (item) => await expandEntry('', item)));
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
const expanded = {};
|
||||
for (const [key, value] of Object.entries(entity)) {
|
||||
expanded[key] = await expandEntry(key, value);
|
||||
}
|
||||
if (type_utilities_1.guard.isTypeOf(expanded, AP.AllTypes)) {
|
||||
return expanded;
|
||||
}
|
||||
return null;
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isApEntity(await expandObject.bind(this)(entity))) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
exports.expandEntity = expandEntity;
|
||||
async function expandObject(object) {
|
||||
const expanded = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
expanded[key] = await expandEntry.bind(this)([key, value]);
|
||||
}
|
||||
return expanded;
|
||||
}
|
||||
async function expandEntry(entry) {
|
||||
const [key, value] = entry;
|
||||
if (selfReferentialKeys.includes(key)) {
|
||||
return value;
|
||||
}
|
||||
if (type_utilities_1.guard.isArray(value)) {
|
||||
return await Promise.all(value.map(async (item) => await expandEntry.bind(this)([key, item])));
|
||||
}
|
||||
if (type_utilities_1.guard.isPlainObject(value)) {
|
||||
return await expandObject.bind(this)(value);
|
||||
}
|
||||
if (type_utilities_1.guard.isUrl(value)) {
|
||||
const foundEntity = type_utilities_1.cast.isApEntity(await this.queryById(value));
|
||||
if (foundEntity) {
|
||||
return foundEntity;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//# sourceMappingURL=expandEntity.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"expandEntity.js","sourceRoot":"","sources":["../src/expandEntity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAqD;AACrD,uDAAuD;AAEhD,KAAK,UAAU,YAAY,CAEhC,MAAiB;IAEjB,MAAM,WAAW,GAAG,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACxD,IACE,GAAG,KAAK,KAAK;YACb,GAAG,KAAK,IAAI;YACZ,GAAG,KAAK,KAAK;YACb,GAAG,KAAK,MAAM;YACd,GAAG,KAAK,UAAU;YAClB,GAAG,KAAK,WAAW,EACnB;YACA,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,KAAK,YAAY,GAAG,EAAE;YAC/B,IAAI,KAAK,CAAC,QAAQ,EAAE,KAAK,wBAAY,EAAE;gBACrC,OAAO,KAAK,CAAC;aACd;iBAAM;gBACL,IAAI;oBACF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAA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? (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.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 getContentType = async (url) => {
|
||||
const response = await this.fetch(url.toString(), { method: 'HEAD' });
|
||||
return response.headers.get('Content-Type');
|
||||
};
|
||||
const isJsonLdContentType = async (url) => {
|
||||
const contentType = await getContentType(url);
|
||||
if (!contentType) {
|
||||
return false;
|
||||
}
|
||||
return (contentType.includes(utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE) ||
|
||||
contentType.includes(utilities_1.LINKED_DATA_CONTENT_TYPE) ||
|
||||
contentType.includes(utilities_1.JSON_CONTENT_TYPE));
|
||||
};
|
||||
if (!(await isJsonLdContentType(id))) {
|
||||
const isJsonLdContentType = await getIsJsonLdContentType.bind(this)(id);
|
||||
if (!isJsonLdContentType) {
|
||||
return null;
|
||||
}
|
||||
const actor = await this.findOne('entity', {
|
||||
preferredUsername: 'bot',
|
||||
});
|
||||
type_utilities_1.assert.isApActor(actor);
|
||||
const actorId = (0, utilities_1.getId)(actor);
|
||||
type_utilities_1.assert.exists(actorId);
|
||||
const { dateHeader, signatureHeader } = await this.getHttpSignature(id, actorId, await this.getPrivateKey(actor));
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 1250);
|
||||
const fetchedEntity = await this.fetch(id.toString(), {
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
[utilities_1.ACCEPT_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
date: dateHeader,
|
||||
signature: signatureHeader,
|
||||
},
|
||||
})
|
||||
.then(async (response) => {
|
||||
clearTimeout(timeout);
|
||||
if (response.status === 200) {
|
||||
return await response.json();
|
||||
}
|
||||
else if (response.status === 410) {
|
||||
const data = await response.json();
|
||||
if ('@context' in data) {
|
||||
console.log('Likely a Tombstone?');
|
||||
return data;
|
||||
}
|
||||
else {
|
||||
throw new Error('Not found, but not a tombstone.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('Found but not 200 or 404.', response.status, id.toString());
|
||||
throw new Error(`Unexpected status code ${response.status}`);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
clearTimeout(timeout);
|
||||
console.log(String(error));
|
||||
return null;
|
||||
});
|
||||
if (fetchedEntity) {
|
||||
const convertedEntity = (0, utilities_1.convertJsonToEntity)(fetchedEntity);
|
||||
const botActor = await getBotActor.bind(this)();
|
||||
type_utilities_1.assert.exists(botActor);
|
||||
const botActorId = (0, utilities_1.getId)(botActor);
|
||||
type_utilities_1.assert.exists(botActorId);
|
||||
const { dateHeader, signatureHeader } = await this.getHttpSignature(id, botActorId, await this.getPrivateKey(botActor));
|
||||
const headers = {
|
||||
date: dateHeader,
|
||||
signature: signatureHeader,
|
||||
};
|
||||
const fetchedJson = await fetchJsonByUrl.bind(this)(id, headers);
|
||||
if (fetchedJson) {
|
||||
const convertedEntity = (0, utilities_1.convertJsonToEntity)(fetchedJson);
|
||||
if (convertedEntity) {
|
||||
const entity = (0, utilities_1.compressEntity)(convertedEntity);
|
||||
if (entity) {
|
||||
|
@ -75,4 +55,69 @@ async function fetchEntityById(id) {
|
|||
return null;
|
||||
}
|
||||
exports.fetchEntityById = fetchEntityById;
|
||||
async function fetchJsonByUrl(url, headers) {
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 1250);
|
||||
const config = {
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
...headers,
|
||||
[utilities_1.ACCEPT_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
},
|
||||
};
|
||||
async function handleResponse(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) {
|
||||
return data;
|
||||
}
|
||||
else {
|
||||
return {
|
||||
'@context': utilities_1.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) {
|
||||
clearTimeout(timeout);
|
||||
console.log(`${error}`);
|
||||
return null;
|
||||
}
|
||||
return await this.fetch(url.href, config)
|
||||
.then(handleResponse)
|
||||
.catch(handleError);
|
||||
}
|
||||
async function getContentType(url) {
|
||||
const { headers } = await this.fetch(url.toString(), { method: 'HEAD' });
|
||||
return headers.get('Content-Type');
|
||||
}
|
||||
async function getIsJsonLdContentType(url) {
|
||||
const contentType = await getContentType.bind(this)(url);
|
||||
if (!contentType) {
|
||||
return false;
|
||||
}
|
||||
return (contentType.includes(utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE) ||
|
||||
contentType.includes(utilities_1.LINKED_DATA_CONTENT_TYPE) ||
|
||||
contentType.includes(utilities_1.JSON_CONTENT_TYPE));
|
||||
}
|
||||
async function getBotActor() {
|
||||
var _a;
|
||||
const botActor = await this.findOne('entity', {
|
||||
preferredUsername: utilities_1.SERVER_ACTOR_USERNAME,
|
||||
});
|
||||
return (_a = type_utilities_1.cast.isApActor(botActor)) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
//# sourceMappingURL=fetchEntityById.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"fetchEntityById.js","sourceRoot":"","sources":["../src/fetchEntityById.ts"],"names":[],"mappings":";;;AAEA,iEAAsD;AACtD,uDAQiC;AAE1B,KAAK,UAAU,eAAe,CAEnC,EAAO;IAEP,MAAM,cAAc,GAAG,KAAK,EAAE,GAAQ,EAA0B,EAAE;QAChE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAAG,KAAK,EAAE,GAAQ,EAAoB,EAAE;QAC/D,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,CACL,WAAW,CAAC,QAAQ,CAAC,wCAA4B,CAAC;YAClD,WAAW,CAAC,QAAQ,CAAC,oCAAwB,CAAC;YAC9C,WAAW,CAAC,QAAQ,CAAC,6BAAiB,CAAC,CACxC,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,CAAC,CAAC,MAAM,mBAAmB,CAAC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AACxB,CAAC;AAED,KAAK,UAAU,cAAc,CAAa,GAAQ;IAChD,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,CAAa,GAAQ;IACxD,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"}
|
|
@ -4,7 +4,7 @@ exports.findEntityById = void 0;
|
|||
const utilities_1 = require("@activity-kit/utilities");
|
||||
async function findEntityById(id) {
|
||||
const collectionName = (0, utilities_1.getCollectionNameByUrl)(id);
|
||||
return await this.findOne(collectionName, { id: id.toString() });
|
||||
return await this.findOne(collectionName, { id: id.href });
|
||||
}
|
||||
exports.findEntityById = findEntityById;
|
||||
//# sourceMappingURL=findEntityById.js.map
|
|
@ -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,QAAQ,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAPD,wCAOC"}
|
||||
{"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"}
|
|
@ -1,3 +1,3 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { Core } from '.';
|
||||
export declare function getActorByUserId(this: Core, userId: string): Promise<AP.Actor | null>;
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getActorByUserId = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
async function getActorByUserId(userId) {
|
||||
if (!userId) {
|
||||
return null;
|
||||
}
|
||||
const preferredUsername = await this.findStringValueById('username', userId);
|
||||
const user = await this.findOne('entity', { preferredUsername });
|
||||
if (user && 'preferredUsername' in user) {
|
||||
return user;
|
||||
if (!type_utilities_1.guard.isApActor(user)) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return user;
|
||||
}
|
||||
exports.getActorByUserId = getActorByUserId;
|
||||
//# sourceMappingURL=getActorByUserId.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getActorByUserId.js","sourceRoot":"","sources":["../src/getActorByUserId.ts"],"names":[],"mappings":";;;AAGO,KAAK,UAAU,gBAAgB,CAEpC,MAAc;IAEd,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;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,IAAI,IAAI,mBAAmB,IAAI,IAAI,EAAE;QACvC,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAjBD,4CAiBC"}
|
||||
{"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"}
|
|
@ -1,3 +1,3 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function getCollectionItems(this: Core, entity: AP.Collection | AP.OrderedCollection): Promise<AP.EntityReference[]>;
|
||||
import { Core } from '.';
|
||||
export declare function getCollectionItems(this: Core, entity: AP.Collection | AP.OrderedCollection): AP.EntityReference[];
|
||||
|
|
|
@ -1,61 +1,22 @@
|
|||
"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.getCollectionItems = 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 getCollectionItems(entity) {
|
||||
try {
|
||||
type_utilities_1.assert.isApCollection(entity);
|
||||
const collectionItems = entity.orderedItems || entity.items;
|
||||
if (!Array.isArray(collectionItems)) {
|
||||
return [];
|
||||
}
|
||||
const result = [];
|
||||
for (const item of collectionItems) {
|
||||
if (item instanceof URL) {
|
||||
const foundItem = await this.queryById(item);
|
||||
result.push(foundItem
|
||||
? await this.expandEntity(foundItem)
|
||||
: {
|
||||
id: item,
|
||||
type: AP.CoreObjectTypes.TOMBSTONE,
|
||||
content: 'Not found',
|
||||
});
|
||||
}
|
||||
else if (!Array.isArray(item)) {
|
||||
const foundItem = await this.queryById((0, utilities_1.getId)(item));
|
||||
result.push(foundItem ?? item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
function getCollectionItems(entity) {
|
||||
const collectionItems = [];
|
||||
if (type_utilities_1.guard.isArray(entity.orderedItems) && entity.orderedItems.length) {
|
||||
const orderedItems = entity.orderedItems.filter((item) => {
|
||||
return type_utilities_1.guard.isApEntity(item) || type_utilities_1.guard.isUrl(item);
|
||||
});
|
||||
collectionItems.push(...orderedItems);
|
||||
}
|
||||
catch (error) {
|
||||
return [];
|
||||
else if (type_utilities_1.guard.isArray(entity.items) && entity.items.length) {
|
||||
const items = entity.items.filter((item) => {
|
||||
return type_utilities_1.guard.isApEntity(item) || type_utilities_1.guard.isUrl(item);
|
||||
});
|
||||
collectionItems.push(...items);
|
||||
}
|
||||
return collectionItems;
|
||||
}
|
||||
exports.getCollectionItems = getCollectionItems;
|
||||
//# sourceMappingURL=getCollectionItems.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getCollectionItems.js","sourceRoot":"","sources":["../src/getCollectionItems.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAsD;AACtD,uDAAgD;AAEzC,KAAK,UAAU,kBAAkB,CAEtC,MAA4C;IAE5C,IAAI;QACF,uBAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAE9B,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,KAAK,CAAC;QAE5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE;YACnC,OAAO,EAAE,CAAC;SACX;QAED,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE;YAClC,IAAI,IAAI,YAAY,GAAG,EAAE;gBACvB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAE7C,MAAM,CAAC,IAAI,CACT,SAAS;oBACP,CAAC,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC;oBACpC,C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U,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"}
|
|
@ -28,47 +28,40 @@ 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 collectionItems = [];
|
||||
try {
|
||||
type_utilities_1.assert.isApCollection(collection);
|
||||
const firstCollectionPageId = (0, utilities_1.getId)(collection.first);
|
||||
if (firstCollectionPageId) {
|
||||
const firstCollectionPage = await this.queryById(firstCollectionPageId);
|
||||
try {
|
||||
type_utilities_1.assert.isApTypeOf(firstCollectionPage, AP.CollectionPageTypes);
|
||||
let nextCollectionPage = firstCollectionPage;
|
||||
while (nextCollectionPage) {
|
||||
try {
|
||||
type_utilities_1.assert.isApTypeOf(nextCollectionPage, AP.CollectionPageTypes);
|
||||
const collectionPageItems = nextCollectionPage.orderedItems || nextCollectionPage.items;
|
||||
type_utilities_1.assert.isArray(collectionPageItems);
|
||||
collectionItems.push(collectionPageItems);
|
||||
const nextCollectionPageId = (0, utilities_1.getId)(nextCollectionPage.next);
|
||||
type_utilities_1.assert.exists(nextCollectionPageId);
|
||||
const potentialNextCollectionPage = await this.queryById(nextCollectionPageId);
|
||||
type_utilities_1.assert.isApTypeOf(potentialNextCollectionPage, AP.CollectionPageTypes);
|
||||
nextCollectionPage = potentialNextCollectionPage;
|
||||
}
|
||||
catch (error) {
|
||||
nextCollectionPage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) { }
|
||||
const firstCollectionPageId = (0, utilities_1.getId)(collection.first);
|
||||
if (!firstCollectionPageId) {
|
||||
if (type_utilities_1.guard.isArray(collection.orderedItems)) {
|
||||
return collection.orderedItems;
|
||||
}
|
||||
else {
|
||||
if (Array.isArray(collection.orderedItems)) {
|
||||
collectionItems.push(collection.orderedItems);
|
||||
}
|
||||
else if (Array.isArray(collection.items)) {
|
||||
collectionItems.push(collection.items);
|
||||
}
|
||||
if (type_utilities_1.guard.isArray(collection.items)) {
|
||||
return collection.items;
|
||||
}
|
||||
return collectionItems.flat();
|
||||
}
|
||||
catch (error) {
|
||||
return [];
|
||||
}
|
||||
const firstCollectionPage = await this.queryById(firstCollectionPageId);
|
||||
if (!type_utilities_1.guard.isApTypeOf(firstCollectionPage, AP.CollectionPageTypes)) {
|
||||
return [];
|
||||
}
|
||||
const collectionItems = [];
|
||||
let nextCollectionPage = firstCollectionPage;
|
||||
while (nextCollectionPage) {
|
||||
if (type_utilities_1.guard.isArray(nextCollectionPage.orderedItems)) {
|
||||
collectionItems.push(nextCollectionPage.orderedItems);
|
||||
}
|
||||
if (type_utilities_1.guard.isArray(nextCollectionPage.items)) {
|
||||
collectionItems.push(nextCollectionPage.items);
|
||||
}
|
||||
const nextPageId = (0, utilities_1.getId)(nextCollectionPage.next);
|
||||
if (!type_utilities_1.guard.exists(nextPageId)) {
|
||||
break;
|
||||
}
|
||||
const nextPage = await this.queryById(nextPageId);
|
||||
if (!type_utilities_1.guard.isApTypeOf(nextPage, AP.CollectionPageTypes)) {
|
||||
break;
|
||||
}
|
||||
nextCollectionPage = nextPage;
|
||||
}
|
||||
return collectionItems.flat();
|
||||
}
|
||||
exports.getPaginatedCollectionItems = getPaginatedCollectionItems;
|
||||
//# sourceMappingURL=getPaginatedCollectionItems.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getPaginatedCollectionItems.js","sourceRoot":"","sources":["../src/getPaginatedCollectionItems.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAsD;AACtD,uDAAgD;AAEzC,KAAK,UAAU,2BAA2B,CAE/C,UAAgD;IAEhD,MAAM,eAAe,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e,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;aAC/C;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;gBAC1C,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aACxC;SACF;QAED,OAAO,eAAe,CAAC,IAAI,EAAE,CAAC;KAC/B;IAAC,OAAO,KAAK,EAAE;QAGd,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAtED,kEAsEC"}
|
||||
{"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;IAEnD,IAAI,kBAAkB,GAAG,mBAAmB,CAAC;IAE7C,OAAO,kBAAkB,EAAE;QACzB,IAAI,sBAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE;YAClD,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;SACvD;QAED,IAAI,sBAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;YAC3C,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SAChD;QAED,MAAM,UAAU,GAAG,IAAA,iBAAK,EAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAElD,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;YAC7B,MAAM;SACP;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAElD,IACE,CAAC,sBAAK,CAAC,UAAU,CAAoB,QAAQ,EAAE,EAAE,CAAC,mBAAmB,CAAC,EACtE;YACA,MAAM;SACP;QAED,kBAAkB,GAAG,QAAQ,CAAC;KAC/B;IAED,OAAO,eAAe,CAAC,IAAI,EAAE,CAAC;AAChC,CAAC;AA9DD,kEA8DC"}
|
|
@ -1,4 +1,4 @@
|
|||
/// <reference types="node" />
|
||||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function getRecipientInboxUrls(this: Core, activity: AP.Activity, actor: AP.Actor, inboxesOnly?: boolean): Promise<URL[]>;
|
||||
import { Core } from '.';
|
||||
export declare function getRecipientInboxUrls(this: Core, activity: AP.Activity, actor: AP.Actor, inboxesOnly?: boolean): Promise<import("url").URL[]>;
|
||||
|
|
|
@ -5,30 +5,32 @@ 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) => {
|
||||
try {
|
||||
if (recipientUrl.toString() === (0, utilities_1.getId)(actor).toString()) {
|
||||
return [];
|
||||
}
|
||||
const foundEntity = await this.fetchEntityById(recipientUrl);
|
||||
type_utilities_1.assert.isApActor(foundEntity);
|
||||
if (!inboxesOnly) {
|
||||
if (foundEntity.endpoints) {
|
||||
if (foundEntity.endpoints.sharedInbox instanceof URL) {
|
||||
return [foundEntity.endpoints.sharedInbox];
|
||||
}
|
||||
}
|
||||
}
|
||||
const inboxId = (0, utilities_1.getId)(foundEntity.inbox);
|
||||
if (inboxId instanceof URL) {
|
||||
return [inboxId];
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return [];
|
||||
}
|
||||
}))).flat();
|
||||
return (0, utilities_1.deduplicateUrls)(recipientInboxUrls);
|
||||
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
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getRecipientInboxUrls.js","sourceRoot":"","sources":["../src/getRecipientInboxUrls.ts"],"names":[],"mappings":";;;AAEA,iEAAsD;AACtD,uDAAiE;AAE1D,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,CACzB,MAAM,OAAO,CAAC,GAAG,CACf,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACvC,IAAI;YACF,IAAI,YAAY,CAAC,QAAQ,EAAE,KAAK,IAAA,iBAAK,EAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACvD,OAAO,EAAE,CAAC;aACX;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YAE7D,uBAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAE9B,IAAI,CAAC,WAAW,EAAE;gBAChB,IAAI,WAAW,CAAC,SAAS,EAAE;oBACzB,IAAI,WAAW,CAAC,SAAS,CAAC,WAAW,YAAY,GAAG,EAAE;wBACpD,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;qBAC5C;iBACF;aACF;YAED,MAAM,OAAO,GAAG,IAAA,iBAAK,EAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEzC,IAAI,OAAO,YAAY,GAAG,EAAE;gBAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;aAClB;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,EAAE,CAAC;SACX;IACH,CAAC,CAAC,CACH,CACF,CAAC,IAAI,EAAE,CAAC;IAET,OAAO,IAAA,2BAAe,EAAC,kBAAkB,CAAC,CAAC;AAC7C,CAAC;AAzCD,sDAyCC"}
|
||||
{"version":3,"file":"getRecipientInboxUrls.js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,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"}
|
|
@ -1,95 +1,69 @@
|
|||
"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.getRecipientUrls = 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 getRecipientUrls(activity) {
|
||||
const mentions = ('object' in activity && 'tag' in activity.object
|
||||
? (0, utilities_1.getArray)(activity.object.tag)
|
||||
: []).filter((entity) => {
|
||||
try {
|
||||
type_utilities_1.assert.isApType(entity, AP.LinkTypes.MENTION);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const tags = type_utilities_1.guard.isApCoreObject(activity.object) && activity.object.tag
|
||||
? getArray(activity.object.tag)
|
||||
: [];
|
||||
const mentions = tags.map(utilities_1.getId).filter(type_utilities_1.guard.isUrl);
|
||||
const recipients = [
|
||||
...(0, utilities_1.getArray)(activity.to),
|
||||
...(0, utilities_1.getArray)(activity.cc),
|
||||
...(0, utilities_1.getArray)(activity.bto),
|
||||
...(0, utilities_1.getArray)(activity.bcc),
|
||||
...(0, utilities_1.getArray)(activity.audience),
|
||||
...getArray(activity.to),
|
||||
...getArray(activity.cc),
|
||||
...getArray(activity.bto),
|
||||
...getArray(activity.bcc),
|
||||
...getArray(activity.audience),
|
||||
...mentions,
|
||||
].flat();
|
||||
const recipientIds = recipients
|
||||
.map((recipient) => (0, utilities_1.getId)(recipient))
|
||||
.filter((recipientUrl) => `${recipientUrl}` !== utilities_1.PUBLIC_ACTOR);
|
||||
const actorUrls = (await Promise.all(recipientIds.map(async (recipientId) => {
|
||||
const foundRecipient = await this.queryById(recipientId);
|
||||
if (!foundRecipient) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
type_utilities_1.assert.isApActor(foundRecipient);
|
||||
const actorUrl = (0, utilities_1.getId)(foundRecipient);
|
||||
if (actorUrl instanceof URL) {
|
||||
return [actorUrl];
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
try {
|
||||
type_utilities_1.assert.isApCollection(foundRecipient);
|
||||
const collectionItems = await this.getPaginatedCollectionItems(foundRecipient);
|
||||
console.log([collectionItems]);
|
||||
const actorsInCollection = [];
|
||||
for (const collectionItem of collectionItems) {
|
||||
try {
|
||||
const collectionItemId = (0, utilities_1.getId)(collectionItem);
|
||||
type_utilities_1.assert.exists(collectionItemId);
|
||||
const expandedCollectionItem = await this.queryById(collectionItemId);
|
||||
type_utilities_1.assert.isApActor(expandedCollectionItem);
|
||||
const actorUrl = (0, utilities_1.getId)(expandedCollectionItem);
|
||||
if (actorUrl instanceof URL) {
|
||||
actorsInCollection.push(actorUrl);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
}
|
||||
return actorsInCollection;
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
return [];
|
||||
}))).flat();
|
||||
return (0, utilities_1.deduplicateUrls)(actorUrls);
|
||||
.map(utilities_1.getId)
|
||||
.filter(type_utilities_1.guard.isUrl)
|
||||
.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);
|
||||
if (!foundRecipient) {
|
||||
return [];
|
||||
}
|
||||
if (type_utilities_1.guard.isApActor(foundRecipient)) {
|
||||
const actorUrl = (0, utilities_1.getId)(foundRecipient);
|
||||
if (type_utilities_1.guard.isUrl(actorUrl)) {
|
||||
return [actorUrl];
|
||||
}
|
||||
}
|
||||
if (type_utilities_1.guard.isApCollection(foundRecipient)) {
|
||||
const collectionItems = await this.getPaginatedCollectionItems(foundRecipient);
|
||||
const actorsInCollection = [];
|
||||
for (const collectionItem of collectionItems) {
|
||||
const collectionItemId = (0, utilities_1.getId)(collectionItem);
|
||||
if (!type_utilities_1.guard.isUrl(collectionItemId)) {
|
||||
continue;
|
||||
}
|
||||
const expandedCollectionItem = await this.queryById(collectionItemId);
|
||||
if (!type_utilities_1.guard.isApActor(expandedCollectionItem)) {
|
||||
continue;
|
||||
}
|
||||
const actorUrl = (0, utilities_1.getId)(expandedCollectionItem);
|
||||
if (!type_utilities_1.guard.isUrl(actorUrl)) {
|
||||
continue;
|
||||
}
|
||||
actorsInCollection.push(actorUrl);
|
||||
}
|
||||
return actorsInCollection;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function getArray(items) {
|
||||
if (!items) {
|
||||
return [];
|
||||
}
|
||||
const array = type_utilities_1.guard.isArray(items) ? items : [items];
|
||||
return array.filter((item) => {
|
||||
return type_utilities_1.guard.isApEntity(item) || type_utilities_1.guard.isUrl(item);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=getRecipientUrls.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getRecipientUrls.js","sourceRoot":"","sources":["../src/getRecipientUrls.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA0C;AAC1C,iEAAsD;AACtD,uDAKiC;AAE1B,KAAK,UAAU,gBAAgB,CAEpC,QAAqB;IAErB,MAAM,QAAQ,GAAG,CACf,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM;QAC9C,CAAC,CAAC,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;QACnD,CAAC,CAAC,EAAE,CACP,CAAC,MAAM,CAAC,CAAC,MAA0B,EAAE,EAAE;QACtC,IAAI;YACF,uBAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC;SACb;QAAC,MAAM;YACN,OAAO,KAAK,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG;QACjB,GAAG,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,EAAE,CAAC;QAC5C,GAAG,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,EAAE,CAAC;QAC5C,GAAG,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,GAAG,CAAC;QAC7C,GAAG,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,GAAG,CAAC;QAC7C,GAAG,IAAA,oBAAQ,EAAqB,QAAQ,CAAC,QAAQ,CAAC;QAClD,GAAG,QAAQ;KACZ,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,YAAY,GAAG,UAAU;SA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AI,CAAC,sBAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE;gBAC5C,SAAS;aACV;YAED,MAAM,QAAQ,GAAG,IAAA,iBAAK,EAAC,sBAAsB,CAAC,CAAC;YAE/C,IAAI,CAAC,sBAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBAC1B,SAAS;aACV;YAED,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACnC;QAED,OAAO,kBAAkB,CAAC;KAC3B;IAED,OAAO,EAAE,CAAC;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"}
|
|
@ -1,3 +1,3 @@
|
|||
import { Core } from '.';
|
||||
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>;
|
||||
|
|
|
@ -4,7 +4,9 @@ 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) {
|
||||
type_utilities_1.assert.isArray(actor.streams);
|
||||
if (!actor.streams) {
|
||||
return null;
|
||||
}
|
||||
const streams = await Promise.all(actor.streams.map(async (stream) => {
|
||||
const streamId = (0, utilities_1.getId)(stream);
|
||||
if (!streamId) {
|
||||
|
@ -13,15 +15,11 @@ const getStreamByName = async function (actor, name) {
|
|||
return await this.queryById(streamId);
|
||||
}));
|
||||
for (const stream of streams) {
|
||||
try {
|
||||
type_utilities_1.assert.isApCollection(stream);
|
||||
if (type_utilities_1.guard.isApCollection(stream)) {
|
||||
if (stream.name === name) {
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"getStreamByName.js","sourceRoot":"","sources":["../src/getStreamByName.ts"],"names":[],"mappings":";;;AAEA,iEAAsD;AACtD,uDAAgD;AAEzC,MAAM,eAAe,GAAG,KAAK,WAElC,KAAe,EACf,IAAY;IAEZ,uBAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE9B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAuB,EAAE,EAAE;QAClD,MAAM,QAAQ,GAAG,IAAA,iBAAK,EAAC,MAAM,CAAC,CAAC;QAE/B,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI;YACF,uBAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAE9B,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;gBACxB,OAAO,MAAM,CAAC;aACf;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM;SACP;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAhCW,QAAA,eAAe,mBAgC1B"}
|
||||
{"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,CAAC,QAAQ,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QAED,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,sBAAK,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE;YAChC,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;gBACxB,OAAO,MAAM,CAAC;aACf;SACF;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA9BW,QAAA,eAAe,mBA8B1B"}
|
|
@ -20,32 +20,25 @@ const getRecipientUrls_1 = require("./getRecipientUrls");
|
|||
const getRecipientInboxUrls_1 = require("./getRecipientInboxUrls");
|
||||
const signAndSendToForeignActorInbox_1 = require("./signAndSendToForeignActorInbox");
|
||||
class Core {
|
||||
fetch;
|
||||
initializeDb;
|
||||
findAll;
|
||||
findOne;
|
||||
findStringIdByValue;
|
||||
findStringValueById;
|
||||
insertItem;
|
||||
removeItem;
|
||||
insertOrderedItem;
|
||||
removeOrderedItem;
|
||||
saveEntity;
|
||||
saveString;
|
||||
getTokenByUserId;
|
||||
createUser;
|
||||
getUserIdByToken;
|
||||
authenticatePassword;
|
||||
generateKeyPair;
|
||||
getHttpSignature;
|
||||
hashPassword;
|
||||
randomBytes;
|
||||
upload;
|
||||
getGuid;
|
||||
constructor(adapters) {
|
||||
this.fetch = adapters.fetch ?? isomorphic_fetch_1.default;
|
||||
var _a;
|
||||
this.findEntityById = findEntityById_1.findEntityById;
|
||||
this.getActorByUserId = getActorByUserId_1.getActorByUserId;
|
||||
this.getPrivateKey = getPrivateKey_1.getPrivateKey;
|
||||
this.getStreamByName = getStreamByName_1.getStreamByName;
|
||||
this.fetchEntityById = fetchEntityById_1.fetchEntityById;
|
||||
this.queryById = queryById_1.queryById;
|
||||
this.expandEntity = expandEntity_1.expandEntity;
|
||||
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.fetch = (_a = adapters.fetch) !== null && _a !== void 0 ? _a : isomorphic_fetch_1.default;
|
||||
if (adapters.db.initializeDb) {
|
||||
this.initializeDb = async () => await adapters.db.initializeDb?.();
|
||||
this.initializeDb = async () => { var _a, _b; return await ((_b = (_a = adapters.db).initializeDb) === null || _b === void 0 ? void 0 : _b.call(_a)); };
|
||||
}
|
||||
this.findAll = async (collection, matchingObject) => await adapters.db.findAll(collection, matchingObject);
|
||||
this.findOne = async (collection, matchingObject, options) => await adapters.db.findOne(collection, matchingObject, options);
|
||||
|
@ -72,20 +65,6 @@ class Core {
|
|||
this.authenticatePassword = async (email, password) => await adapters.auth.authenticatePassword(email, password);
|
||||
this.upload = async (file) => await adapters.storage.upload(file);
|
||||
}
|
||||
findEntityById = findEntityById_1.findEntityById;
|
||||
getActorByUserId = getActorByUserId_1.getActorByUserId;
|
||||
getPrivateKey = getPrivateKey_1.getPrivateKey;
|
||||
getStreamByName = getStreamByName_1.getStreamByName;
|
||||
fetchEntityById = fetchEntityById_1.fetchEntityById;
|
||||
queryById = queryById_1.queryById;
|
||||
expandEntity = expandEntity_1.expandEntity;
|
||||
getCollectionItems = getCollectionItems_1.getCollectionItems;
|
||||
getPaginatedCollectionItems = getPaginatedCollectionItems_1.getPaginatedCollectionItems;
|
||||
expandCollection = expandCollection_1.expandCollection;
|
||||
getRecipientInboxUrls = getRecipientInboxUrls_1.getRecipientInboxUrls;
|
||||
getRecipientUrls = getRecipientUrls_1.getRecipientUrls;
|
||||
broadcast = broadcast_1.broadcast;
|
||||
signAndSendToForeignActorInbox = signAndSendToForeignActorInbox_1.signAndSendToForeignActorInbox;
|
||||
}
|
||||
exports.Core = Core;
|
||||
var adapters_1 = require("./adapters");
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wEAAqC;AAYrC,qDAAkD;AAClD,uDAAoD;AACpD,2CAAwC;AACxC,iDAA8C;AAC9C,mDAAgD;AAChD,6DAA0D;AAC1D,+EAA4E;AAC5E,yDAAsD;AACtD,yDAAsD;AACtD,uDAAoD;AACpD,2CAAwC;AACxC,yDAAsD;AACtD,mEAAgE;AAChE,qFAAkF;AAElF,MAAa,IAAI;IACf,KAAK,CAAgB;IAErB,YAAY,CAA6B;IACzC,OAAO,CAAuB;IAC9B,OAAO,CAAuB;IAC9B,mBAAmB,CAAmC;IACtD,mBAAmB,CAAmC;IACtD,UAAU,CAA0B;IACpC,UAAU,CAA0B;IACpC,iBAAiB,CAAiC;IAClD,iBAAiB,CAAiC;IAClD,UAAU,CAA0B;IACpC,UAAU,CAA0B;IAEpC,gBAAgB,CAAkC;IAClD,UAAU,CAA4B;IACtC,gBAAgB,CAAkC;IAClD,oBAAoB,CAAsC;IAE1D,eAAe,CAAmC;IAClD,gBAAgB,CAAoC;IACpD,YAAY,CAAgC;IAC5C,WAAW,CAA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,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;CA2BF;AA3JD,oBA2JC;AAED,uCAUoB;AANlB,qGAAA,SAAS,OAAA"}
|
|
@ -34,7 +34,10 @@ async function queryById(id) {
|
|||
const fetchedEntity = await this.fetchEntityById(id);
|
||||
if (!fetchedEntity ||
|
||||
type_utilities_1.guard.isApType(fetchedEntity, AP.ExtendedObjectTypes.TOMBSTONE)) {
|
||||
return this.findEntityById(id);
|
||||
const foundEntity = await this.findEntityById(id);
|
||||
if (foundEntity) {
|
||||
return foundEntity;
|
||||
}
|
||||
}
|
||||
return fetchedEntity;
|
||||
}
|
||||
|
|
|
@ -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,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AArBD,8BAqBC"}
|
||||
{"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"}
|
|
@ -1,14 +1,17 @@
|
|||
"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.toString());
|
||||
const convertedActivity = (0, utilities_1.convertEntityToJson)(activity);
|
||||
const { dateHeader, digestHeader, signatureHeader } = await this.getHttpSignature(foreignActorInbox, actor.id, await this.getPrivateKey(actor), convertedActivity);
|
||||
return await this.fetch(foreignActorInbox.toString(), {
|
||||
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(convertedActivity),
|
||||
body: JSON.stringify(plainActivity),
|
||||
headers: {
|
||||
[utilities_1.CONTENT_TYPE_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
[utilities_1.ACCEPT_HEADER]: utilities_1.ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"signAndSendToForeignActorInbox.js","sourceRoot":"","sources":["../src/signAndSendToForeignActorInbox.ts"],"names":[],"mappings":";;;AACA,uDAKiC;AAG1B,KAAK,UAAU,8BAA8B,CAElD,iBAAsB,EACtB,KAAe,EACf,QAAqB;IAErB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE3D,MAAM,iBAAiB,GAAG,IAAA,+BAAmB,EAAC,QAAQ,CAAC,CAAC;IACxD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,GACjD,MAAM,IAAI,CAAC,gBAAgB,CACzB,iBAAiB,EACjB,KAAK,CAAC,EAAE,EACR,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CA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AAiB,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"}
|
|
@ -21,8 +21,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "node .build.js",
|
||||
"format": "prettier --config .prettierrc \"**/*.ts\" --write",
|
||||
"lint": "eslint src/**/*.ts"
|
||||
"build:bundle": "tsc-bundle tsconfig.json --outFile dist/bundle.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/michaelcpuckett/activitypub-core/issues"
|
||||
|
@ -35,11 +34,13 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/formidable": "^2.0.5",
|
||||
"@types/isomorphic-fetch": "^0.0.36",
|
||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
},
|
||||
"gitHead": "94cd24962ff1406bc137c1ac244f960286d6cac0"
|
||||
}
|
||||
|
|
|
@ -43,12 +43,12 @@ export type CoreLibrary = AuthAdapter &
|
|||
queryById: (this: CoreLibrary, id: URL) => Promise<AP.Entity | null>;
|
||||
expandEntity: (
|
||||
this: CoreLibrary,
|
||||
originalEntity: AP.Entity,
|
||||
) => Promise<AP.Entity>;
|
||||
entity: AP.Entity,
|
||||
) => Promise<AP.Entity | null>;
|
||||
getCollectionItems: (
|
||||
this: CoreLibrary,
|
||||
entity: AP.Collection | AP.OrderedCollection,
|
||||
) => Promise<AP.EntityReference[]>;
|
||||
) => AP.EntityReference[];
|
||||
getPaginatedCollectionItems: (
|
||||
this: CoreLibrary,
|
||||
collection: AP.Collection | AP.OrderedCollection,
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { applyContext, cleanProps } 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*
|
||||
*/
|
||||
|
||||
export async function broadcast(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
activity: AP.Activity,
|
||||
actor: AP.Actor,
|
||||
): Promise<unknown> {
|
||||
const publicActivity = cleanProps(applyContext<AP.Activity>(activity));
|
||||
const entity = applyContext<AP.Entity>(activity);
|
||||
|
||||
assert.isApActivity(entity);
|
||||
|
||||
const publicActivity = cleanProps(entity);
|
||||
|
||||
if (!('actor' in publicActivity)) {
|
||||
throw new Error('Not an activity?');
|
||||
|
@ -20,10 +26,6 @@ export async function broadcast(
|
|||
|
||||
const recipients = await this.getRecipientInboxUrls(activity, actor);
|
||||
|
||||
console.log({
|
||||
recipients,
|
||||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
recipients.map(async (recipient) => {
|
||||
return await this.signAndSendToForeignActorInbox(
|
||||
|
|
|
@ -1,52 +1,41 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { getId } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function expandCollection(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
collection: AP.EitherCollectionReference,
|
||||
): Promise<null | AP.EitherCollection> {
|
||||
const id = getId(collection);
|
||||
|
||||
if (!id) {
|
||||
): Promise<AP.EitherCollection | null> {
|
||||
if (!guard.isApCollection(collection)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const foundEntity = await this.queryById(id);
|
||||
const items = this.getCollectionItems(collection);
|
||||
|
||||
if (!foundEntity) {
|
||||
return null;
|
||||
}
|
||||
const expandedItems = await Promise.all(
|
||||
items.map(async (item) => {
|
||||
if (guard.isApEntity(item)) {
|
||||
return item;
|
||||
}
|
||||
|
||||
if (guard.isTypeOf<AP.EitherCollection>(foundEntity, AP.CollectionTypes)) {
|
||||
const items = await this.getCollectionItems(foundEntity);
|
||||
return (await this.queryById(item)) ?? item;
|
||||
}),
|
||||
);
|
||||
|
||||
if (!items) {
|
||||
return foundEntity;
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(foundEntity.type)
|
||||
? foundEntity.type.includes(AP.CollectionTypes.ORDERED_COLLECTION)
|
||||
: foundEntity.type === AP.CollectionTypes.ORDERED_COLLECTION
|
||||
) {
|
||||
return {
|
||||
...foundEntity,
|
||||
orderedItems: items,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(foundEntity.type)
|
||||
? foundEntity.type.includes(AP.CollectionTypes.COLLECTION)
|
||||
: foundEntity.type === AP.CollectionTypes.COLLECTION
|
||||
) {
|
||||
return {
|
||||
...foundEntity,
|
||||
items,
|
||||
};
|
||||
}
|
||||
if (
|
||||
guard.isArray(collection.orderedItems) &&
|
||||
collection.orderedItems.length
|
||||
) {
|
||||
return {
|
||||
...collection,
|
||||
orderedItems: expandedItems,
|
||||
};
|
||||
} else if (guard.isArray(collection.items) && collection.items.length) {
|
||||
return {
|
||||
...collection,
|
||||
items: expandedItems,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -1,52 +1,65 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { PUBLIC_ACTOR } from '@activity-kit/utilities';
|
||||
import { cast, guard } from '@activity-kit/type-utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
const selfReferentialKeys = [
|
||||
'@context',
|
||||
'_id',
|
||||
'id',
|
||||
'type',
|
||||
'url',
|
||||
'href',
|
||||
'publicKey',
|
||||
];
|
||||
|
||||
export async function expandEntity(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
entity: AP.Entity,
|
||||
): Promise<AP.Entity | null> {
|
||||
const expandEntry = async (key: string, value: unknown) => {
|
||||
if (
|
||||
key === '_id' ||
|
||||
key === 'id' ||
|
||||
key === 'url' ||
|
||||
key === 'type' ||
|
||||
key === '@context' ||
|
||||
key === 'publicKey'
|
||||
) {
|
||||
return value;
|
||||
} else if (value instanceof URL) {
|
||||
if (value.toString() === PUBLIC_ACTOR) {
|
||||
return value;
|
||||
} else {
|
||||
try {
|
||||
const foundEntity = await this.queryById(value);
|
||||
|
||||
return foundEntity ?? value;
|
||||
} catch (error) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
} else if (Array.isArray(value)) {
|
||||
return await Promise.all(
|
||||
value.map(async (item) => await expandEntry('', item)),
|
||||
);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
return cast.isApEntity(await expandObject.bind(this)(entity)) ?? null;
|
||||
}
|
||||
|
||||
async function expandObject(
|
||||
this: CoreLibrary,
|
||||
object: Record<string, unknown>,
|
||||
) {
|
||||
const expanded: Record<string, unknown> = {};
|
||||
|
||||
for (const [key, value] of Object.entries(entity)) {
|
||||
expanded[key] = await expandEntry(key, value);
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
expanded[key] = await expandEntry.bind(this)([key, value]);
|
||||
}
|
||||
|
||||
if (guard.isTypeOf<AP.Entity>(expanded, AP.AllTypes)) {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
return null;
|
||||
return expanded;
|
||||
}
|
||||
|
||||
async function expandEntry(
|
||||
this: CoreLibrary,
|
||||
entry: [key: string, value: unknown],
|
||||
): Promise<unknown> {
|
||||
const [key, value] = entry;
|
||||
|
||||
if (selfReferentialKeys.includes(key)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (guard.isArray(value)) {
|
||||
return await Promise.all(
|
||||
value.map(async (item) => await expandEntry.bind(this)([key, item])),
|
||||
);
|
||||
}
|
||||
|
||||
if (guard.isPlainObject(value)) {
|
||||
return await expandObject.bind(this)(value);
|
||||
}
|
||||
|
||||
if (guard.isUrl(value)) {
|
||||
const foundEntity = cast.isApEntity(await this.queryById(value));
|
||||
|
||||
if (foundEntity) {
|
||||
return foundEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { cast, assert } from '@activity-kit/type-utilities';
|
||||
import {
|
||||
ACCEPT_HEADER,
|
||||
ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
|
@ -9,97 +8,45 @@ import {
|
|||
LINKED_DATA_CONTENT_TYPE,
|
||||
JSON_CONTENT_TYPE,
|
||||
getId,
|
||||
SERVER_ACTOR_USERNAME,
|
||||
ACTIVITYSTREAMS_CONTEXT,
|
||||
} from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function fetchEntityById(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
id: URL,
|
||||
): Promise<AP.Entity | null> {
|
||||
const getContentType = async (url: URL): Promise<string | null> => {
|
||||
const response = await this.fetch(url.toString(), { method: 'HEAD' });
|
||||
return response.headers.get('Content-Type');
|
||||
};
|
||||
const isJsonLdContentType = await getIsJsonLdContentType.bind(this)(id);
|
||||
|
||||
const isJsonLdContentType = async (url: URL): Promise<boolean> => {
|
||||
const contentType = await getContentType(url);
|
||||
if (!contentType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
contentType.includes(ACTIVITYSTREAMS_CONTENT_TYPE) ||
|
||||
contentType.includes(LINKED_DATA_CONTENT_TYPE) ||
|
||||
contentType.includes(JSON_CONTENT_TYPE)
|
||||
);
|
||||
};
|
||||
|
||||
if (!(await isJsonLdContentType(id))) {
|
||||
if (!isJsonLdContentType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Send HTTP Signature for Mastodon in secure mode.
|
||||
const actor = await this.findOne('entity', {
|
||||
preferredUsername: 'bot',
|
||||
});
|
||||
const botActor = await getBotActor.bind(this)();
|
||||
|
||||
assert.isApActor(actor);
|
||||
assert.exists(botActor);
|
||||
|
||||
const actorId = getId(actor);
|
||||
const botActorId = getId(botActor);
|
||||
|
||||
assert.exists(actorId);
|
||||
assert.exists(botActorId);
|
||||
|
||||
const { dateHeader, signatureHeader } = await this.getHttpSignature(
|
||||
id,
|
||||
actorId,
|
||||
await this.getPrivateKey(actor),
|
||||
botActorId,
|
||||
await this.getPrivateKey(botActor),
|
||||
);
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 1250);
|
||||
const headers = {
|
||||
date: dateHeader,
|
||||
signature: signatureHeader,
|
||||
};
|
||||
|
||||
// GET requests (eg. to th e inbox) MUST be made with an Accept header of
|
||||
// `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`
|
||||
const fetchedEntity: Record<string, unknown> | null = await this.fetch(
|
||||
id.toString(),
|
||||
{
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
date: dateHeader,
|
||||
signature: signatureHeader,
|
||||
},
|
||||
},
|
||||
)
|
||||
.then(async (response) => {
|
||||
clearTimeout(timeout);
|
||||
if (response.status === 200) {
|
||||
return await response.json();
|
||||
} else if (response.status === 410) {
|
||||
const data = await response.json();
|
||||
const fetchedJson = await fetchJsonByUrl.bind(this)(id, headers);
|
||||
|
||||
if ('@context' in data) {
|
||||
console.log('Likely a Tombstone?');
|
||||
return data;
|
||||
} else {
|
||||
throw new Error('Not found, but not a tombstone.');
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
'Found but not 200 or 404.',
|
||||
response.status,
|
||||
id.toString(),
|
||||
);
|
||||
throw new Error(`Unexpected status code ${response.status}`);
|
||||
}
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
clearTimeout(timeout);
|
||||
console.log(String(error));
|
||||
return null;
|
||||
});
|
||||
|
||||
if (fetchedEntity) {
|
||||
const convertedEntity = convertJsonToEntity(fetchedEntity);
|
||||
if (fetchedJson) {
|
||||
const convertedEntity = convertJsonToEntity(fetchedJson);
|
||||
|
||||
if (convertedEntity) {
|
||||
const entity = compressEntity(convertedEntity);
|
||||
|
@ -113,3 +60,100 @@ export async function fetchEntityById(
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
async function getContentType(
|
||||
this: CoreLibrary,
|
||||
url: URL,
|
||||
): Promise<string | null> {
|
||||
const { headers } = await this.fetch(url.toString(), { method: 'HEAD' });
|
||||
return headers.get('Content-Type');
|
||||
}
|
||||
|
||||
async function getIsJsonLdContentType(
|
||||
this: CoreLibrary,
|
||||
url: URL,
|
||||
): Promise<boolean> {
|
||||
const contentType = await getContentType.bind(this)(url);
|
||||
|
||||
if (!contentType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
contentType.includes(ACTIVITYSTREAMS_CONTENT_TYPE) ||
|
||||
contentType.includes(LINKED_DATA_CONTENT_TYPE) ||
|
||||
contentType.includes(JSON_CONTENT_TYPE)
|
||||
);
|
||||
}
|
||||
|
||||
async function getBotActor(this: CoreLibrary) {
|
||||
const botActor = await this.findOne('entity', {
|
||||
preferredUsername: SERVER_ACTOR_USERNAME,
|
||||
});
|
||||
|
||||
return cast.isApActor(botActor) ?? null;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { getCollectionNameByUrl } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function findEntityById(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
id: URL,
|
||||
): Promise<AP.Entity | null> {
|
||||
const collectionName = getCollectionNameByUrl(id);
|
||||
|
||||
return await this.findOne(collectionName, { id: id.toString() });
|
||||
return await this.findOne(collectionName, { id: id.href });
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function getActorByUserId(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
userId: string,
|
||||
): Promise<AP.Actor | null> {
|
||||
if (!userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const preferredUsername = await this.findStringValueById('username', userId);
|
||||
|
||||
const user = await this.findOne('entity', { preferredUsername });
|
||||
|
||||
if (user && 'preferredUsername' in user) {
|
||||
return user;
|
||||
if (!guard.isApActor(user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
return user;
|
||||
}
|
||||
|
|
|
@ -1,45 +1,27 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { getId } from '@activity-kit/utilities';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
|
||||
export async function getCollectionItems(
|
||||
this: Core,
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export function getCollectionItems(
|
||||
this: CoreLibrary,
|
||||
entity: AP.Collection | AP.OrderedCollection,
|
||||
): Promise<AP.EntityReference[]> {
|
||||
try {
|
||||
assert.isApCollection(entity);
|
||||
): AP.EntityReference[] {
|
||||
const collectionItems: AP.EntityReference[] = [];
|
||||
|
||||
const collectionItems = entity.orderedItems || entity.items;
|
||||
if (guard.isArray(entity.orderedItems) && entity.orderedItems.length) {
|
||||
const orderedItems = entity.orderedItems.filter((item) => {
|
||||
return guard.isApEntity(item) || guard.isUrl(item);
|
||||
});
|
||||
|
||||
if (!Array.isArray(collectionItems)) {
|
||||
return [];
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
||||
const result: AP.EntityReference[] = [];
|
||||
|
||||
for (const item of collectionItems) {
|
||||
if (item instanceof URL) {
|
||||
const foundItem = await this.queryById(item);
|
||||
|
||||
result.push(
|
||||
foundItem
|
||||
? await this.expandEntity(foundItem)
|
||||
: {
|
||||
id: item,
|
||||
type: AP.CoreObjectTypes.TOMBSTONE,
|
||||
content: 'Not found',
|
||||
},
|
||||
);
|
||||
} else if (!Array.isArray(item)) {
|
||||
const foundItem = await this.queryById(getId(item));
|
||||
|
||||
result.push(foundItem ?? item);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
return [];
|
||||
collectionItems.push(...items);
|
||||
}
|
||||
|
||||
return collectionItems;
|
||||
}
|
||||
|
|
|
@ -1,76 +1,69 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { getId } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function getPaginatedCollectionItems(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
collection: AP.Collection | AP.OrderedCollection,
|
||||
): Promise<AP.EntityReference[]> {
|
||||
const collectionItems: AP.EntityReference[][] = [];
|
||||
const firstCollectionPageId = getId(collection.first);
|
||||
|
||||
try {
|
||||
assert.isApCollection(collection);
|
||||
if (!firstCollectionPageId) {
|
||||
// TODO .getArray()
|
||||
|
||||
const firstCollectionPageId = getId(collection.first);
|
||||
|
||||
if (firstCollectionPageId) {
|
||||
const firstCollectionPage = await this.queryById(firstCollectionPageId);
|
||||
|
||||
try {
|
||||
assert.isApTypeOf<AP.EitherCollectionPage>(
|
||||
firstCollectionPage,
|
||||
AP.CollectionPageTypes,
|
||||
);
|
||||
|
||||
let nextCollectionPage: AP.EitherCollectionPage | null =
|
||||
firstCollectionPage;
|
||||
|
||||
while (nextCollectionPage) {
|
||||
try {
|
||||
assert.isApTypeOf<AP.EitherCollectionPage>(
|
||||
nextCollectionPage,
|
||||
AP.CollectionPageTypes,
|
||||
);
|
||||
|
||||
const collectionPageItems =
|
||||
nextCollectionPage.orderedItems || nextCollectionPage.items;
|
||||
|
||||
assert.isArray(collectionPageItems);
|
||||
|
||||
collectionItems.push(collectionPageItems);
|
||||
|
||||
const nextCollectionPageId = getId(nextCollectionPage.next);
|
||||
|
||||
assert.exists(nextCollectionPageId);
|
||||
|
||||
const potentialNextCollectionPage = await this.queryById(
|
||||
nextCollectionPageId,
|
||||
);
|
||||
|
||||
assert.isApTypeOf<AP.EitherCollectionPage>(
|
||||
potentialNextCollectionPage,
|
||||
AP.CollectionPageTypes,
|
||||
);
|
||||
|
||||
nextCollectionPage = potentialNextCollectionPage;
|
||||
} catch (error) {
|
||||
nextCollectionPage = null;
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
} else {
|
||||
if (Array.isArray(collection.orderedItems)) {
|
||||
collectionItems.push(collection.orderedItems);
|
||||
} else if (Array.isArray(collection.items)) {
|
||||
collectionItems.push(collection.items);
|
||||
}
|
||||
if (guard.isArray(collection.orderedItems)) {
|
||||
return collection.orderedItems;
|
||||
}
|
||||
|
||||
return collectionItems.flat();
|
||||
} catch (error) {
|
||||
// Not a Collection.
|
||||
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);
|
||||
|
||||
if (
|
||||
!guard.isApTypeOf<AP.CollectionPage>(nextPage, AP.CollectionPageTypes)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
nextCollectionPage = nextPage;
|
||||
}
|
||||
|
||||
return collectionItems.flat();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
|
||||
export async function getPrivateKey(this: Core, actor: AP.Actor) {
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function getPrivateKey(this: CoreLibrary, actor: AP.Actor) {
|
||||
if (!actor.preferredUsername) {
|
||||
throw new Error('Actor has no `preferredUsername`.');
|
||||
}
|
||||
|
|
|
@ -1,47 +1,55 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { deduplicateUrls, getId } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function getRecipientInboxUrls(
|
||||
this: Core,
|
||||
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) => {
|
||||
try {
|
||||
if (recipientUrl.toString() === getId(actor).toString()) {
|
||||
return [];
|
||||
}
|
||||
const recipientInboxUrls = await Promise.all(
|
||||
recipientUrls.map(async (recipientUrl) => {
|
||||
return await mapRecipientUrl.bind(this)(recipientUrl, actor, inboxesOnly);
|
||||
}),
|
||||
);
|
||||
|
||||
const foundEntity = await this.fetchEntityById(recipientUrl);
|
||||
|
||||
assert.isApActor(foundEntity);
|
||||
|
||||
if (!inboxesOnly) {
|
||||
if (foundEntity.endpoints) {
|
||||
if (foundEntity.endpoints.sharedInbox instanceof URL) {
|
||||
return [foundEntity.endpoints.sharedInbox];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const inboxId = getId(foundEntity.inbox);
|
||||
|
||||
if (inboxId instanceof URL) {
|
||||
return [inboxId];
|
||||
}
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}),
|
||||
)
|
||||
).flat();
|
||||
|
||||
return deduplicateUrls(recipientInboxUrls);
|
||||
return deduplicateUrls(recipientInboxUrls.flat().filter(guard.isUrl));
|
||||
}
|
||||
|
||||
async function mapRecipientUrl(
|
||||
this: CoreLibrary,
|
||||
recipientUrl: URL,
|
||||
actor: AP.Actor,
|
||||
inboxesOnly?: boolean,
|
||||
) {
|
||||
if (recipientUrl.href === getId(actor)?.href) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const foundEntity = await this.fetchEntityById(recipientUrl);
|
||||
|
||||
if (!guard.isApActor(foundEntity)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!inboxesOnly) {
|
||||
if (foundEntity.endpoints) {
|
||||
if (guard.isUrl(foundEntity.endpoints.sharedInbox)) {
|
||||
return [foundEntity.endpoints.sharedInbox];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const inboxId = getId(foundEntity.inbox);
|
||||
|
||||
if (guard.isUrl(inboxId)) {
|
||||
return [inboxId];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -1,106 +1,101 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import {
|
||||
getId,
|
||||
PUBLIC_ACTOR,
|
||||
deduplicateUrls,
|
||||
getArray,
|
||||
} from '@activity-kit/utilities';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { getId, PUBLIC_ACTOR, deduplicateUrls } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function getRecipientUrls(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
activity: AP.Activity,
|
||||
): Promise<URL[]> {
|
||||
const mentions = (
|
||||
'object' in activity && 'tag' in activity.object
|
||||
? getArray<AP.EntityReference>(activity.object.tag)
|
||||
: []
|
||||
).filter((entity: AP.EntityReference) => {
|
||||
try {
|
||||
assert.isApType(entity, AP.LinkTypes.MENTION);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const tags =
|
||||
guard.isApCoreObject(activity.object) && activity.object.tag
|
||||
? getArray(activity.object.tag)
|
||||
: [];
|
||||
const mentions = tags.map(getId).filter(guard.isUrl);
|
||||
|
||||
const recipients = [
|
||||
...getArray<AP.EntityReference>(activity.to),
|
||||
...getArray<AP.EntityReference>(activity.cc),
|
||||
...getArray<AP.EntityReference>(activity.bto),
|
||||
...getArray<AP.EntityReference>(activity.bcc),
|
||||
...getArray<AP.EntityReference>(activity.audience),
|
||||
...getArray(activity.to),
|
||||
...getArray(activity.cc),
|
||||
...getArray(activity.bto),
|
||||
...getArray(activity.bcc),
|
||||
...getArray(activity.audience),
|
||||
...mentions,
|
||||
].flat();
|
||||
|
||||
const recipientIds = recipients
|
||||
.map((recipient) => getId(recipient))
|
||||
.filter((recipientUrl) => `${recipientUrl}` !== PUBLIC_ACTOR);
|
||||
.map(getId)
|
||||
.filter(guard.isUrl)
|
||||
.filter((recipientUrl) => recipientUrl.href !== PUBLIC_ACTOR);
|
||||
|
||||
const actorUrls = (
|
||||
await Promise.all<URL[]>(
|
||||
recipientIds.map(async (recipientId) => {
|
||||
const foundRecipient = await this.queryById(recipientId);
|
||||
const actorUrls = await Promise.all(recipientIds.map(getActorIds.bind(this)));
|
||||
|
||||
if (!foundRecipient) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
assert.isApActor(foundRecipient);
|
||||
|
||||
const actorUrl = getId(foundRecipient);
|
||||
|
||||
if (actorUrl instanceof URL) {
|
||||
return [actorUrl];
|
||||
}
|
||||
} catch (error) {
|
||||
// Not an Actor.
|
||||
}
|
||||
|
||||
try {
|
||||
assert.isApCollection(foundRecipient);
|
||||
|
||||
const collectionItems = await this.getPaginatedCollectionItems(
|
||||
foundRecipient,
|
||||
);
|
||||
|
||||
console.log([collectionItems]);
|
||||
|
||||
const actorsInCollection = [];
|
||||
|
||||
for (const collectionItem of collectionItems) {
|
||||
try {
|
||||
const collectionItemId = getId(collectionItem);
|
||||
|
||||
assert.exists(collectionItemId);
|
||||
|
||||
const expandedCollectionItem = await this.queryById(
|
||||
collectionItemId,
|
||||
);
|
||||
|
||||
assert.isApActor(expandedCollectionItem);
|
||||
|
||||
const actorUrl = getId(expandedCollectionItem);
|
||||
|
||||
if (actorUrl instanceof URL) {
|
||||
actorsInCollection.push(actorUrl);
|
||||
}
|
||||
} catch (error) {
|
||||
// Not an Actor.
|
||||
}
|
||||
}
|
||||
|
||||
return actorsInCollection;
|
||||
} catch (error) {
|
||||
// Not a Collection.
|
||||
}
|
||||
|
||||
return [];
|
||||
}),
|
||||
)
|
||||
).flat();
|
||||
|
||||
return deduplicateUrls(actorUrls);
|
||||
return deduplicateUrls(actorUrls.flat());
|
||||
}
|
||||
|
||||
async function getActorIds(
|
||||
this: CoreLibrary,
|
||||
recipientId: URL,
|
||||
): Promise<URL[]> {
|
||||
const foundRecipient = await this.queryById(recipientId);
|
||||
|
||||
if (!foundRecipient) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (guard.isApActor(foundRecipient)) {
|
||||
const actorUrl = getId(foundRecipient);
|
||||
|
||||
if (guard.isUrl(actorUrl)) {
|
||||
return [actorUrl];
|
||||
}
|
||||
}
|
||||
|
||||
if (guard.isApCollection(foundRecipient)) {
|
||||
const collectionItems = await this.getPaginatedCollectionItems(
|
||||
foundRecipient,
|
||||
);
|
||||
|
||||
const actorsInCollection: URL[] = [];
|
||||
|
||||
for (const collectionItem of collectionItems) {
|
||||
const collectionItemId = getId(collectionItem);
|
||||
|
||||
if (!guard.isUrl(collectionItemId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const expandedCollectionItem = await this.queryById(collectionItemId);
|
||||
|
||||
if (!guard.isApActor(expandedCollectionItem)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const actorUrl = getId(expandedCollectionItem);
|
||||
|
||||
if (!guard.isUrl(actorUrl)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
actorsInCollection.push(actorUrl);
|
||||
}
|
||||
|
||||
return actorsInCollection;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function getArray(
|
||||
items: null | undefined | AP.OrArray<AP.EntityReference>,
|
||||
): AP.EntityReference[] {
|
||||
if (!items) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const array = guard.isArray(items) ? items : [items];
|
||||
|
||||
return array.filter((item) => {
|
||||
return guard.isApEntity(item) || guard.isUrl(item);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { getId } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export const getStreamByName = async function (
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
actor: AP.Actor,
|
||||
name: string,
|
||||
): Promise<AP.EitherCollection | null> {
|
||||
assert.isArray(actor.streams);
|
||||
if (!actor.streams) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const streams = await Promise.all(
|
||||
actor.streams.map(async (stream: AP.Entity | URL) => {
|
||||
actor.streams.map(async (stream: AP.EntityReference) => {
|
||||
const streamId = getId(stream);
|
||||
|
||||
if (!streamId) {
|
||||
|
@ -23,14 +26,10 @@ export const getStreamByName = async function (
|
|||
);
|
||||
|
||||
for (const stream of streams) {
|
||||
try {
|
||||
assert.isApCollection(stream);
|
||||
|
||||
if (guard.isApCollection(stream)) {
|
||||
if (stream.name === name) {
|
||||
return stream;
|
||||
}
|
||||
} catch (error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import fetch from 'isomorphic-fetch';
|
||||
|
||||
import {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Core } from '.';
|
||||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { isLocal } from '@activity-kit/utilities';
|
||||
|
||||
import { CoreLibrary } from './adapters';
|
||||
|
||||
export async function queryById(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
id: URL,
|
||||
): Promise<AP.Entity | null> {
|
||||
if (isLocal(id)) {
|
||||
|
@ -20,7 +21,11 @@ export async function queryById(
|
|||
AP.ExtendedObjectTypes.TOMBSTONE,
|
||||
)
|
||||
) {
|
||||
return this.findEntityById(id);
|
||||
const foundEntity = await this.findEntityById(id);
|
||||
|
||||
if (foundEntity) {
|
||||
return foundEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return fetchedEntity;
|
||||
|
|
|
@ -1,33 +1,41 @@
|
|||
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 { Core } from '.';
|
||||
|
||||
import { CoreLibrary } from '.';
|
||||
|
||||
export async function signAndSendToForeignActorInbox(
|
||||
this: Core,
|
||||
this: CoreLibrary,
|
||||
foreignActorInbox: URL,
|
||||
actor: AP.Actor,
|
||||
activity: AP.Activity,
|
||||
): Promise<unknown> {
|
||||
console.log('SENDING TO...', foreignActorInbox.toString());
|
||||
console.log('SENDING TO...', foreignActorInbox.href);
|
||||
|
||||
const actorId = getId(actor);
|
||||
|
||||
assert.exists(actorId);
|
||||
|
||||
const plainActivity = convertEntityToJson(activity);
|
||||
|
||||
const convertedActivity = convertEntityToJson(activity);
|
||||
const { dateHeader, digestHeader, signatureHeader } =
|
||||
await this.getHttpSignature(
|
||||
foreignActorInbox,
|
||||
actor.id,
|
||||
actorId,
|
||||
await this.getPrivateKey(actor),
|
||||
convertedActivity,
|
||||
plainActivity,
|
||||
);
|
||||
|
||||
// send
|
||||
return await this.fetch(foreignActorInbox.toString(), {
|
||||
return await this.fetch(foreignActorInbox.href, {
|
||||
method: 'post',
|
||||
body: JSON.stringify(convertedActivity),
|
||||
body: JSON.stringify(plainActivity),
|
||||
headers: {
|
||||
[CONTENT_TYPE_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
[ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE,
|
||||
|
@ -35,7 +43,7 @@ export async function signAndSendToForeignActorInbox(
|
|||
Date: dateHeader,
|
||||
Digest: digestHeader,
|
||||
Signature: signatureHeader,
|
||||
},
|
||||
} as Record<string, string>,
|
||||
}).catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
|
|
|
@ -3,25 +3,24 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
"jsx": "react",
|
||||
"target": "ES2018",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
"ES2018"
|
||||
],
|
||||
"outDir": "./lib"
|
||||
"outDir": "./lib/"
|
||||
},
|
||||
"exclude": [
|
||||
"./node_modules",
|
||||
"../../node_modules"
|
||||
],
|
||||
"include": [
|
||||
"src/index.ts"
|
||||
"./src/"
|
||||
]
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import { assert } from '@activity-kit/type-utilities';
|
||||
|
||||
import { InboxPostEndpoint } from '.';
|
||||
|
||||
export async function getActors(this: InboxPostEndpoint) {
|
||||
export async function getActors(this: InboxPostEndpoint): Promise<AP.Actor[]> {
|
||||
const actor = await this.core.findOne('entity', {
|
||||
inbox: this.url.href,
|
||||
});
|
||||
|
||||
if (!actor || !actor.id || !('inbox' in actor)) {
|
||||
throw new Error('No actor with this inbox.');
|
||||
}
|
||||
assert.isApActor(actor);
|
||||
|
||||
return [actor];
|
||||
}
|
||||
|
|
|
@ -1,75 +1,7 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { getArray, getId } from '@activity-kit/utilities';
|
||||
import { InboxPostEndpoint } from '.';
|
||||
|
||||
// TODO: Check with Spec.
|
||||
|
||||
export async function shouldForwardActivity(this: InboxPostEndpoint) {
|
||||
if (!this.activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!guard.isTypeOf<AP.Activity>(this.activity, AP.ActivityTypes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const activity = this.activity as AP.Activity;
|
||||
|
||||
const to = getArray<AP.EntityReference>(activity.to);
|
||||
const cc = getArray<AP.EntityReference>(activity.cc);
|
||||
const audience = getArray<AP.EntityReference>(activity.audience);
|
||||
|
||||
const addressees = [...to, ...cc, ...audience];
|
||||
|
||||
for (const addressee of addressees) {
|
||||
const addresseeId = getId(addressee);
|
||||
|
||||
if (!addresseeId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const foundItem = await this.core.findEntityById(addresseeId);
|
||||
|
||||
if (!foundItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
guard.isApType<AP.Collection>(foundItem, AP.CollectionTypes.COLLECTION) ||
|
||||
guard.isApType<AP.OrderedCollection>(
|
||||
foundItem,
|
||||
AP.CollectionTypes.ORDERED_COLLECTION,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const inReplyTo = getArray<AP.EntityReference>(activity.inReplyTo);
|
||||
const object =
|
||||
'object' in activity ? getArray<AP.EntityReference>(activity.object) : [];
|
||||
const target =
|
||||
'target' in activity ? getArray<AP.EntityReference>(activity.target) : [];
|
||||
const tag = getArray<AP.EntityReference>(activity.tag);
|
||||
|
||||
const objects = [...inReplyTo, ...object, ...target, ...tag];
|
||||
|
||||
for (const object of objects) {
|
||||
const objectId = getId(object);
|
||||
|
||||
if (!objectId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const foundItem = await this.core.findEntityById(objectId);
|
||||
|
||||
if (!foundItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (foundItem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": ["plugin:@typescript-eslint/recommended"],
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/// <reference types="node" />
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function exists(value: unknown): asserts value is string | number | object;
|
||||
export declare function exists(value: unknown): asserts value is string | number | object | boolean;
|
||||
export declare function isObject(value: unknown): asserts value is object;
|
||||
export declare function isPlainObject(value: unknown): asserts value is Record<string, unknown>;
|
||||
export declare function isString(value: unknown): asserts value is string;
|
||||
export declare function isNumber(value: unknown): asserts value is number;
|
||||
export declare function isBoolean(value: unknown): asserts value is boolean;
|
||||
export declare function isDate(value: unknown): asserts value is Date;
|
||||
export declare function isUrl(value: unknown): asserts value is URL;
|
||||
export declare function isArray(value: unknown): asserts value is Array<unknown>;
|
||||
|
|
|
@ -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.isString = exports.isObject = exports.exists = void 0;
|
||||
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;
|
||||
const guard = __importStar(require("./guard"));
|
||||
function exists(value) {
|
||||
if (!guard.exists(value)) {
|
||||
|
@ -37,6 +37,12 @@ function isObject(value) {
|
|||
}
|
||||
}
|
||||
exports.isObject = isObject;
|
||||
function isPlainObject(value) {
|
||||
if (!guard.isPlainObject(value)) {
|
||||
throw new Error(`"${value}" is not a plain object.`);
|
||||
}
|
||||
}
|
||||
exports.isPlainObject = isPlainObject;
|
||||
function isString(value) {
|
||||
if (!guard.isString(value)) {
|
||||
throw new Error(`"${value}" is not a string.`);
|
||||
|
@ -49,6 +55,12 @@ function isNumber(value) {
|
|||
}
|
||||
}
|
||||
exports.isNumber = isNumber;
|
||||
function isBoolean(value) {
|
||||
if (!guard.isBoolean(value)) {
|
||||
throw new Error(`"${value}" is not a boolean.`);
|
||||
}
|
||||
}
|
||||
exports.isBoolean = isBoolean;
|
||||
function isDate(value) {
|
||||
if (!guard.isDate(value)) {
|
||||
throw new Error(`"${value}" is not a Date object.`);
|
||||
|
|
|
@ -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;IACrC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,CAAC,CAAC;KACjD;AACH,CAAC;AAJD,4BAIC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,4BAIC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,4BAIC;AAED,SAAgB,MAAM,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,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CAAC;AAPD,4BAOC;AAED,SAAgB,UAAU,CACxB,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"}
|
|
@ -1,8 +1,10 @@
|
|||
/// <reference types="node" />
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function exists(value: unknown): string | number | object | undefined;
|
||||
export declare function exists(value: unknown): string | number | boolean | object | undefined;
|
||||
export declare function isObject(value: unknown): object | undefined;
|
||||
export declare function isPlainObject(value: unknown): Record<string, unknown> | undefined;
|
||||
export declare function isString(value: unknown): string | undefined;
|
||||
export declare function isBoolean(value: unknown): boolean | undefined;
|
||||
export declare function isNumber(value: unknown): number | undefined;
|
||||
export declare function isDate(value: unknown): Date | undefined;
|
||||
export declare function isUrl(value: unknown): URL | undefined;
|
||||
|
|
|
@ -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.isString = exports.isObject = exports.exists = void 0;
|
||||
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;
|
||||
const guard = __importStar(require("./guard"));
|
||||
function exists(value) {
|
||||
return guard.exists(value) ? value : undefined;
|
||||
|
@ -33,10 +33,18 @@ function isObject(value) {
|
|||
return guard.isObject(value) ? value : undefined;
|
||||
}
|
||||
exports.isObject = isObject;
|
||||
function isPlainObject(value) {
|
||||
return guard.isPlainObject(value) ? value : undefined;
|
||||
}
|
||||
exports.isPlainObject = isPlainObject;
|
||||
function isString(value) {
|
||||
return guard.isString(value) ? value : undefined;
|
||||
}
|
||||
exports.isString = isString;
|
||||
function isBoolean(value) {
|
||||
return guard.isBoolean(value) ? value : undefined;
|
||||
}
|
||||
exports.isBoolean = isBoolean;
|
||||
function isNumber(value) {
|
||||
return guard.isNumber(value) ? value : undefined;
|
||||
}
|
||||
|
|
|
@ -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,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,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;IACnC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,C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AC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC;AAJD,wCAIC;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"}
|
|
@ -1,9 +1,11 @@
|
|||
/// <reference types="node" />
|
||||
import * as AP from '@activity-kit/types';
|
||||
export declare function exists(value: unknown): value is string | number | object;
|
||||
export declare function exists(value: unknown): value is string | number | object | boolean;
|
||||
export declare function isObject(value: unknown): value is object;
|
||||
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
||||
export declare function isString(value: unknown): value is string;
|
||||
export declare function isNumber(value: unknown): value is number;
|
||||
export declare function isBoolean(value: unknown): value is boolean;
|
||||
export declare function isDate(value: unknown): value is Date;
|
||||
export declare function isUrl(value: unknown): value is URL;
|
||||
export declare function isArray(value: unknown): value is Array<unknown>;
|
||||
|
|
|
@ -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.isString = exports.isObject = exports.exists = void 0;
|
||||
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;
|
||||
const narrow = __importStar(require("./narrow"));
|
||||
function exists(value) {
|
||||
return narrow.exists(value);
|
||||
|
@ -33,6 +33,10 @@ function isObject(value) {
|
|||
return narrow.isObject(value);
|
||||
}
|
||||
exports.isObject = isObject;
|
||||
function isPlainObject(value) {
|
||||
return narrow.isPlainObject(value);
|
||||
}
|
||||
exports.isPlainObject = isPlainObject;
|
||||
function isString(value) {
|
||||
return narrow.isString(value);
|
||||
}
|
||||
|
@ -41,6 +45,10 @@ function isNumber(value) {
|
|||
return narrow.isNumber(value);
|
||||
}
|
||||
exports.isNumber = isNumber;
|
||||
function isBoolean(value) {
|
||||
return narrow.isBoolean(value);
|
||||
}
|
||||
exports.isBoolean = isBoolean;
|
||||
function isDate(value) {
|
||||
return narrow.isDate(value);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAAmC;AAEnC,SAAgB,MAAM,CAAC,KAAc;IACnC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAFD,wBAEC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAFD,4BAEC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;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AK,CAAC,CAAC;AACtC,CAAC;AAJD,wCAIC;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"}
|
|
@ -1,8 +1,10 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
export declare function exists(value: unknown): boolean;
|
||||
export declare function isObject(value: unknown): boolean;
|
||||
export declare function isPlainObject(value: unknown): boolean;
|
||||
export declare function isString(value: unknown): boolean;
|
||||
export declare function isNumber(value: unknown): boolean;
|
||||
export declare function isBoolean(value: unknown): boolean;
|
||||
export declare function isDate(value: unknown): boolean;
|
||||
export declare function isUrl(value: unknown): boolean;
|
||||
export declare function isArray(value: unknown): boolean;
|
||||
|
|
|
@ -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.isString = exports.isObject = exports.exists = void 0;
|
||||
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;
|
||||
const AP = __importStar(require("@activity-kit/types"));
|
||||
function isType(entity, type) {
|
||||
if (!entity || typeof entity !== 'object') {
|
||||
|
@ -38,13 +38,18 @@ function isTypeOf(entity, types) {
|
|||
return Object.values(types).some((type) => isType(entity, type));
|
||||
}
|
||||
function exists(value) {
|
||||
return (['string', 'number', 'object'].includes(typeof value) && value !== null);
|
||||
return (['string', 'number', 'object', 'boolean'].includes(typeof value) &&
|
||||
value !== null);
|
||||
}
|
||||
exports.exists = exists;
|
||||
function isObject(value) {
|
||||
return typeof value === 'object' && value !== null;
|
||||
}
|
||||
exports.isObject = isObject;
|
||||
function isPlainObject(value) {
|
||||
return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
|
||||
}
|
||||
exports.isPlainObject = isPlainObject;
|
||||
function isString(value) {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
@ -53,6 +58,10 @@ function isNumber(value) {
|
|||
return typeof value === 'number' && !isNaN(value);
|
||||
}
|
||||
exports.isNumber = isNumber;
|
||||
function isBoolean(value) {
|
||||
return typeof value === 'boolean';
|
||||
}
|
||||
exports.isBoolean = isBoolean;
|
||||
function isDate(value) {
|
||||
return value instanceof Date;
|
||||
}
|
||||
|
|
|
@ -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,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,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAI,KAAK,EAAE,UAAU,CAAC,CAAC;AAC7D,CAAC;AALD,gCAKC"}
|
|
@ -3,7 +3,6 @@
|
|||
"version": "0.4.56",
|
||||
"description": "> TODO: description",
|
||||
"author": "Michael Puckett <michaelcpuckett@gmail.com>",
|
||||
"homepage": "https://github.com/michaelcpuckett/activitypub-core#readme",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"directories": {
|
||||
|
@ -17,8 +16,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "node .build.js",
|
||||
"format": "prettier --config .prettierrc \"**/*.ts\" --write",
|
||||
"lint": "eslint activitypub/**/*.ts"
|
||||
"build:bundle": "tsc-bundle tsconfig.json --outFile dist/bundle.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@activity-kit/types": "^0.4.56"
|
||||
|
@ -28,6 +26,7 @@
|
|||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as guard from './guard';
|
|||
|
||||
export function exists(
|
||||
value: unknown,
|
||||
): asserts value is string | number | object {
|
||||
): asserts value is string | number | object | boolean {
|
||||
if (!guard.exists(value)) {
|
||||
throw new Error(`"${value}" is undefined or null.`);
|
||||
}
|
||||
|
@ -15,6 +15,14 @@ export function isObject(value: unknown): asserts value is object {
|
|||
}
|
||||
}
|
||||
|
||||
export function isPlainObject(
|
||||
value: unknown,
|
||||
): asserts value is Record<string, unknown> {
|
||||
if (!guard.isPlainObject(value)) {
|
||||
throw new Error(`"${value}" is not a plain object.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function isString(value: unknown): asserts value is string {
|
||||
if (!guard.isString(value)) {
|
||||
throw new Error(`"${value}" is not a string.`);
|
||||
|
@ -27,6 +35,12 @@ export function isNumber(value: unknown): asserts value is number {
|
|||
}
|
||||
}
|
||||
|
||||
export function isBoolean(value: unknown): asserts value is boolean {
|
||||
if (!guard.isBoolean(value)) {
|
||||
throw new Error(`"${value}" is not a boolean.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function isDate(value: unknown): asserts value is Date {
|
||||
if (!guard.isDate(value)) {
|
||||
throw new Error(`"${value}" is not a Date object.`);
|
||||
|
|
|
@ -9,10 +9,18 @@ export function isObject(value: unknown) {
|
|||
return guard.isObject(value) ? value : undefined;
|
||||
}
|
||||
|
||||
export function isPlainObject(value: unknown) {
|
||||
return guard.isPlainObject(value) ? value : undefined;
|
||||
}
|
||||
|
||||
export function isString(value: unknown) {
|
||||
return guard.isString(value) ? value : undefined;
|
||||
}
|
||||
|
||||
export function isBoolean(value: unknown) {
|
||||
return guard.isBoolean(value) ? value : undefined;
|
||||
}
|
||||
|
||||
export function isNumber(value: unknown) {
|
||||
return guard.isNumber(value) ? value : undefined;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import * as narrow from './narrow';
|
||||
|
||||
export function exists(value: unknown): value is string | number | object {
|
||||
export function exists(
|
||||
value: unknown,
|
||||
): value is string | number | object | boolean {
|
||||
return narrow.exists(value);
|
||||
}
|
||||
|
||||
|
@ -9,6 +11,12 @@ export function isObject(value: unknown): value is object {
|
|||
return narrow.isObject(value);
|
||||
}
|
||||
|
||||
export function isPlainObject(
|
||||
value: unknown,
|
||||
): value is Record<string, unknown> {
|
||||
return narrow.isPlainObject(value);
|
||||
}
|
||||
|
||||
export function isString(value: unknown): value is string {
|
||||
return narrow.isString(value);
|
||||
}
|
||||
|
@ -17,6 +25,10 @@ export function isNumber(value: unknown): value is number {
|
|||
return narrow.isNumber(value);
|
||||
}
|
||||
|
||||
export function isBoolean(value: unknown): value is boolean {
|
||||
return narrow.isBoolean(value);
|
||||
}
|
||||
|
||||
export function isDate(value: unknown): value is Date {
|
||||
return narrow.isDate(value);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ function isTypeOf<T extends AP.Entity>(
|
|||
|
||||
export function exists(value: unknown) {
|
||||
return (
|
||||
['string', 'number', 'object'].includes(typeof value) && value !== null
|
||||
['string', 'number', 'object', 'boolean'].includes(typeof value) &&
|
||||
value !== null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -29,6 +30,10 @@ export function isObject(value: unknown) {
|
|||
return typeof value === 'object' && value !== null;
|
||||
}
|
||||
|
||||
export function isPlainObject(value: unknown) {
|
||||
return isObject(value) && Object.getPrototypeOf(value) === Object.prototype;
|
||||
}
|
||||
|
||||
export function isString(value: unknown) {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
@ -37,6 +42,10 @@ export function isNumber(value: unknown) {
|
|||
return typeof value === 'number' && !isNaN(value);
|
||||
}
|
||||
|
||||
export function isBoolean(value: unknown) {
|
||||
return typeof value === 'boolean';
|
||||
}
|
||||
|
||||
export function isDate(value: unknown) {
|
||||
return value instanceof Date;
|
||||
}
|
||||
|
|
|
@ -3,25 +3,24 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
"jsx": "react",
|
||||
"target": "ES2018",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
"ES2018"
|
||||
],
|
||||
"outDir": "./lib"
|
||||
"outDir": "./lib/"
|
||||
},
|
||||
"exclude": [
|
||||
"./node_modules",
|
||||
"../../node_modules"
|
||||
],
|
||||
"include": [
|
||||
"src/index.ts"
|
||||
"./src/"
|
||||
]
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": ["plugin:@typescript-eslint/recommended"],
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
/// <reference types="node" />
|
||||
import { TypeOrArrayWithType, AnyType } from '../util/const';
|
||||
import { ContextDefinition } from 'jsonld';
|
||||
import { TypeOrArrayWithType, AnyType, OrArray } from '../util';
|
||||
export type BaseEntity<T extends AnyType> = {
|
||||
'@context'?: URL | URL[] | ContextDefinition;
|
||||
'@context'?: OrArray<URL | Record<string, URL>>;
|
||||
id?: URL | null;
|
||||
type: T | TypeOrArrayWithType<T>;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@activity-kit/types",
|
||||
"version": "0.4.56",
|
||||
"description": "> TODO: description",
|
||||
"description": "Types representing the ActivityPub data model",
|
||||
"author": "Michael Puckett <michaelcpuckett@gmail.com>",
|
||||
"homepage": "",
|
||||
"license": "MIT",
|
||||
|
@ -16,9 +16,9 @@
|
|||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"build": "node .build.js",
|
||||
"format": "prettier --config .prettierrc \"**/*.ts\" --write",
|
||||
"lint": "eslint activitypub/**/*.ts"
|
||||
"build:bundle": "tsc-bundle tsconfig.json --outFile dist/bundle.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsonld": "^1.5.9",
|
||||
|
@ -26,10 +26,8 @@
|
|||
"@typescript-eslint/parser": "^5.40.0",
|
||||
"eslint": "^8.25.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-bundle": "^1.0.18"
|
||||
},
|
||||
"gitHead": "94cd24962ff1406bc137c1ac244f960286d6cac0",
|
||||
"dependencies": {
|
||||
"formidable": "^2.1.1"
|
||||
}
|
||||
"gitHead": "94cd24962ff1406bc137c1ac244f960286d6cac0"
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { TypeOrArrayWithType, AnyType } from '../util/const';
|
||||
import { ContextDefinition } from 'jsonld';
|
||||
import { TypeOrArrayWithType, AnyType, OrArray } from '../util';
|
||||
|
||||
export type BaseEntity<T extends AnyType> = {
|
||||
'@context'?: URL | URL[] | ContextDefinition;
|
||||
'@context'?: OrArray<URL | Record<string, URL>>;
|
||||
// Activity Pub allows null.
|
||||
id?: URL | null;
|
||||
type: T | TypeOrArrayWithType<T>;
|
||||
|
|
|
@ -3,25 +3,24 @@
|
|||
"strict": true,
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
"jsx": "react",
|
||||
"target": "ES2018",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
"ES2018"
|
||||
],
|
||||
"outDir": "./lib"
|
||||
"outDir": "./lib/"
|
||||
},
|
||||
"exclude": [
|
||||
"./node_modules",
|
||||
"../../node_modules"
|
||||
],
|
||||
"include": [
|
||||
"src/index.ts"
|
||||
"./src/"
|
||||
]
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": ["plugin:@typescript-eslint/recommended"],
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
export declare function applyContext<T>(entity: AP.Entity): T;
|
||||
export declare function applyContext<T>(entity: AP.Entity): T | undefined;
|
||||
|
|
|
@ -28,8 +28,7 @@ const AP = __importStar(require("@activity-kit/types"));
|
|||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
const globals_1 = require("./globals");
|
||||
function applyContext(entity) {
|
||||
type_utilities_1.assert.isApEntity(entity);
|
||||
if (type_utilities_1.guard.isTypeOf(entity, AP.ActorTypes)) {
|
||||
if (type_utilities_1.guard.isApTypeOf(entity, AP.ActorTypes)) {
|
||||
if (!entity['@context']) {
|
||||
entity['@context'] = [
|
||||
new URL(globals_1.ACTIVITYSTREAMS_CONTEXT),
|
||||
|
@ -43,7 +42,7 @@ function applyContext(entity) {
|
|||
}
|
||||
return entity;
|
||||
}
|
||||
if (type_utilities_1.guard.isTypeOf(entity, AP.AllTypes)) {
|
||||
if (type_utilities_1.guard.isApTypeOf(entity, AP.AllTypes)) {
|
||||
if (!entity['@context']) {
|
||||
entity['@context'] = new URL(globals_1.ACTIVITYSTREAMS_CONTEXT);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"applyContext.js","sourceRoot":"","sources":["../src/applyContext.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,iEAA6D;AAC7D,uCAA2E;AAE3E,SAAgB,YAAY,CAAI,MAAiB;IAC/C,uBAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAE1B,IAAI,sBAAK,CAAC,QAAQ,CAAe,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE;QACvD,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,y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}
|
|
@ -3,69 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.compressEntity = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
function compressEntity(entity) {
|
||||
const object = {};
|
||||
for (const key of Object.keys(entity)) {
|
||||
if (typeof key === 'string') {
|
||||
object[key] = entity[key];
|
||||
}
|
||||
}
|
||||
const compressed = compressObject(object);
|
||||
try {
|
||||
type_utilities_1.assert.isApEntity(compressed);
|
||||
return compressed;
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isApEntity(compressObject(entity))) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
exports.compressEntity = compressEntity;
|
||||
function compressObject(object) {
|
||||
const compressed = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
compressed[key] = compressItem(value);
|
||||
compressed[key] = compressUnknown(value);
|
||||
}
|
||||
return compressed;
|
||||
}
|
||||
function compressItem(item) {
|
||||
if (item instanceof URL || item instanceof Date || typeof item === 'string') {
|
||||
function compressUnknown(item) {
|
||||
if (!type_utilities_1.guard.exists(item)) {
|
||||
return item;
|
||||
}
|
||||
else if (Array.isArray(item)) {
|
||||
return item.map(compressItem);
|
||||
if (type_utilities_1.guard.isArray(item)) {
|
||||
return item.map(compressUnknown);
|
||||
}
|
||||
else if (item && typeof item === 'object') {
|
||||
if ('id' in item && item.id instanceof URL) {
|
||||
return item.id;
|
||||
}
|
||||
else if ('href' in item && item.href instanceof URL) {
|
||||
return item.href;
|
||||
}
|
||||
else if ('url' in item) {
|
||||
if (item.url instanceof URL) {
|
||||
return item.url;
|
||||
}
|
||||
else if (typeof item.url === 'object' &&
|
||||
item.url !== null &&
|
||||
'href' in item.url &&
|
||||
item.url.href instanceof URL) {
|
||||
return item.url.href;
|
||||
}
|
||||
else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const object = {};
|
||||
for (const objectKey of Object.keys(item)) {
|
||||
if (typeof objectKey === 'string') {
|
||||
object[objectKey] = item[objectKey];
|
||||
}
|
||||
}
|
||||
return compressObject(object);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const entity = type_utilities_1.cast.isApEntity(item);
|
||||
if (!entity) {
|
||||
return item;
|
||||
}
|
||||
if ('id' in entity && type_utilities_1.guard.isUrl(entity.id)) {
|
||||
return entity.id;
|
||||
}
|
||||
if ('url' in entity && type_utilities_1.guard.isUrl(entity.url)) {
|
||||
return entity.url;
|
||||
}
|
||||
if ('href' in entity && type_utilities_1.guard.isUrl(entity.href)) {
|
||||
return entity.href;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
//# sourceMappingURL=compressEntity.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"compressEntity.js","sourceRoot":"","sources":["../src/compressEntity.ts"],"names":[],"mappings":";;;AACA,iEAAsD;AAEtD,SAAgB,cAAc,CAAC,MAAiB;IAC9C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SAC3B;KACF;IAED,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAE1C,IAAI;QACF,uBAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC9B,OAAO,UAAU,CAAC;KACnB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AAjBD,wCAiBC;AAED,SAAS,cAAc,CAAC,MAA+B;IACrD,MAAM,UAAU,GAA4B,EAAE,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,UAAU,CAAC,GAAG,CA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CAAC,EAAE;QAC9C,OAAO,MAAM,CAAC,GAAG,CAAC;KACnB;IAED,IAAI,MAAM,IAAI,MAAM,IAAI,sBAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QAChD,OAAO,MAAM,CAAC,IAAI,CAAC;KACpB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@ -1,35 +1,35 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.convertEntityToJson = void 0;
|
||||
const type_utilities_1 = require("@activity-kit/type-utilities");
|
||||
function convertEntityToJson(object) {
|
||||
return convertObject(object);
|
||||
var _a;
|
||||
return (_a = type_utilities_1.cast.isPlainObject(convertObject(object))) !== null && _a !== void 0 ? _a : {};
|
||||
}
|
||||
exports.convertEntityToJson = convertEntityToJson;
|
||||
function convertObject(object) {
|
||||
const converted = {};
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
converted[key] = convertItem(value);
|
||||
converted[key] = convertUnknown(value);
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
function convertItem(item) {
|
||||
if (item instanceof URL || item instanceof Date) {
|
||||
return item.toString();
|
||||
function convertUnknown(value) {
|
||||
if (!type_utilities_1.guard.exists(value)) {
|
||||
return value;
|
||||
}
|
||||
else if (Array.isArray(item)) {
|
||||
return item.map(convertItem);
|
||||
if (type_utilities_1.guard.isArray(value)) {
|
||||
return value.map(convertUnknown);
|
||||
}
|
||||
else if (item && typeof item === 'object') {
|
||||
const object = {};
|
||||
for (const objectKey of Object.keys(item)) {
|
||||
if (typeof objectKey === 'string') {
|
||||
object[objectKey] = item[objectKey];
|
||||
}
|
||||
}
|
||||
return convertObject(object);
|
||||
if (type_utilities_1.guard.isPlainObject(value)) {
|
||||
return convertObject(value);
|
||||
}
|
||||
else {
|
||||
return item;
|
||||
if (type_utilities_1.guard.isDate(value)) {
|
||||
return value.toISOString();
|
||||
}
|
||||
if (type_utilities_1.guard.isObject(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
//# sourceMappingURL=convertEntityToJson.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"convertEntityToJson.js","sourceRoot":"","sources":["../src/convertEntityToJson.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CACjC,MAAiB;IAEjB,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAJD,kDAIC;AAED,SAAS,aAAa,CAAC,MAA2C;IAChE,MAAM,SAAS,GAA4B,EAAE,CAAC;IAE9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;KACrC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,IAAI,IAAI,YAAY,GAAG,IAAI,IAAI,YAAY,IAAI,EAAE;QAC/C,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;KACxB;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;KAC9B;SAAM,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC3C,MAAM,MAAM,GAA4B,EAAE,CAAC;QAE3C,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACzC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;gBACjC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;aACrC;SACF;QAED,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;KAC9B;SAAM;QACL,OAAO,IAAI,CAAC;KACb;AACH,CAAC"}
|
||||
{"version":3,"file":"convertEntityToJson.js","sourceRoot":"","sources":["../src/convertEntityToJson.ts"],"names":[],"mappings":";;;AACA,iEAA2D;AAE3D,SAAgB,mBAAmB,CACjC,MAAiB;;IAEjB,OAAO,MAAA,qBAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,mCAAI,EAAE,CAAC;AACzD,CAAC;AAJD,kDAIC;AAED,SAAS,aAAa,CACpB,MAA+B;IAE/B,MAAM,SAAS,GAA4B,EAAE,CAAC;IAE9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjD,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;KACxC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,sBAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,IAAI,sBAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KAClC;IAED,IAAI,sBAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QAC9B,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;KAC7B;IAED,IAAI,sBAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;KAC5B;IAED,IAAI,sBAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@ -3848,10 +3848,13 @@ const CONTEXT_DEFINITIONS = {
|
|||
},
|
||||
};
|
||||
const customLoader = async (url, callback) => {
|
||||
if (!nodeDocumentLoader) {
|
||||
throw new Error('nodeDocumentLoader is not defined');
|
||||
}
|
||||
const contextUrl = Object.keys(CONTEXT_DEFINITIONS).find((key) => key === url);
|
||||
if (contextUrl) {
|
||||
return {
|
||||
contextUrl: null,
|
||||
contextUrl: undefined,
|
||||
document: {
|
||||
'@context': CONTEXT_DEFINITIONS[contextUrl],
|
||||
},
|
||||
|
@ -3862,6 +3865,7 @@ const customLoader = async (url, callback) => {
|
|||
};
|
||||
const ctx = CONTEXT_DEFINITIONS[globals_1.ACTIVITYSTREAMS_CONTEXT];
|
||||
const convertJsonLdToEntity = async (document) => {
|
||||
var _a;
|
||||
const result = await jsonld.compact(document, ctx, {
|
||||
documentLoader: customLoader,
|
||||
});
|
||||
|
@ -3873,7 +3877,7 @@ const convertJsonLdToEntity = async (document) => {
|
|||
if (!converted) {
|
||||
return null;
|
||||
}
|
||||
return (0, applyContext_1.applyContext)(converted);
|
||||
return (_a = (0, applyContext_1.applyContext)(converted)) !== null && _a !== void 0 ? _a : null;
|
||||
};
|
||||
exports.convertJsonLdToEntity = convertJsonLdToEntity;
|
||||
//# sourceMappingURL=convertJsonLdToEntity.js.map
|
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue