From 4f2a52ca79c328471262f849a02dd1c889e7ce5f Mon Sep 17 00:00:00 2001 From: Michael Puckett Date: Fri, 14 Oct 2022 21:47:00 -0400 Subject: [PATCH] fix sharedInbox --- .eslintrc.json | 3 + LICENSE | 9 + package-lock.json | 556 +++++++++--------- .../activitypub-core-delivery/.prettierrc | 6 + .../signAndSendToForeignActorInbox.ts | 1 - .../lib/broadcast.d.ts | 6 +- .../lib/broadcast.js | 3 +- .../lib/broadcast.js.map | 2 +- .../lib/getPrivateKey.d.ts | 5 +- .../lib/getRecipientInboxUrls.d.ts | 6 +- .../lib/getRecipientsList.d.ts | 5 +- .../activitypub-core-delivery/lib/index.d.ts | 16 +- .../lib/signAndSendToForeignActorInbox.d.ts | 7 +- .../activitypub-core-delivery/package.json | 4 +- .../src/broadcast.ts | 4 +- .../src/signAndSendToForeignActorInbox.ts | 2 +- .../lib/credentials.d.ts | 3 + .../lib/credentials.js | 16 + .../lib/credentials.js.map | 1 + .../activitypub-core-example-2/lib/index.d.ts | 1 + .../activitypub-core-example-2/lib/index.js | 46 ++ .../lib/index.js.map | 1 + .../.prettierrc | 6 + .../lib/index.d.ts | 34 +- .../lib/index.js | 5 + .../lib/index.js.map | 2 +- .../package.json | 4 +- .../src/index.ts | 238 +++++--- .../.prettierrc | 6 + .../lib/pages/EntityPage/Activity.d.ts | 9 +- .../lib/pages/EntityPage/Actor.d.ts | 9 +- .../lib/pages/EntityPage/Collection.d.ts | 12 +- .../lib/pages/EntityPage/CollectionPage.d.ts | 6 +- .../lib/pages/EntityPage/Link.d.ts | 4 +- .../lib/pages/EntityPage/Note.d.ts | 9 +- .../lib/pages/EntityPage/Object.d.ts | 9 +- .../pages/EntityPage/OrderedCollection.d.ts | 9 +- .../EntityPage/OrderedCollectionPage.d.ts | 6 +- .../lib/pages/EntityPage/index.d.ts | 9 +- .../lib/pages/HomePage/CreateForm.d.ts | 9 +- .../lib/pages/HomePage/Sidebar.d.ts | 4 +- .../lib/pages/HomePage/Welcome.d.ts | 9 +- .../lib/pages/HomePage/index.d.ts | 2 +- .../package.json | 4 +- .../src/index.ts | 2 +- packages/activitypub-core-mongodb/.prettierrc | 6 + .../__tests__/expandCollection.ts | 6 +- .../__tests__/expandEntity.ts | 8 +- .../__tests__/fetchEntityById.ts | 6 +- .../__tests__/getCollectionItems.ts | 6 +- .../__tests__/mockDatabaseService.ts | 8 +- .../__tests__/queryById.ts | 6 +- .../__tests__/saveEntity.ts | 4 +- .../lib/expandCollection.d.ts | 5 +- .../lib/expandEntity.d.ts | 5 +- .../lib/fetchEntityById.d.ts | 5 +- .../activitypub-core-mongodb/lib/findAll.d.ts | 8 +- .../lib/findEntityById.d.ts | 5 +- .../activitypub-core-mongodb/lib/findOne.d.ts | 8 +- .../lib/findStringIdByValue.d.ts | 6 +- .../lib/findStringValueById.d.ts | 6 +- .../lib/getActorByToken.d.ts | 6 +- .../lib/getAuthenticatedUserIdByToken.d.ts | 6 +- .../lib/getCollectionItems.d.ts | 5 +- .../activitypub-core-mongodb/lib/index.d.ts | 51 +- .../activitypub-core-mongodb/lib/insert.d.ts | 24 +- .../lib/queryById.d.ts | 5 +- .../lib/saveEntity.d.ts | 5 +- .../lib/saveString.d.ts | 7 +- .../activitypub-core-mongodb/package.json | 4 +- .../src/fetchEntityById.ts | 13 +- .../src/getAuthenticatedUserIdByToken.ts | 18 +- .../src/getCollectionItems.ts | 15 +- .../activitypub-core-mongodb/src/index.ts | 4 +- .../src/saveEntity.ts | 7 +- packages/activitypub-core-types/.prettierrc | 6 + .../activitypub/Extended/Collection.ts | 4 +- .../activitypub/Extended/ExtendedObject.ts | 4 +- packages/activitypub-core-types/index.ts | 2 +- .../lib/activitypub/Core/CoreObject.d.ts | 73 +-- .../lib/activitypub/Core/Entity.d.ts | 6 +- .../lib/activitypub/Core/Link.d.ts | 22 +- .../lib/activitypub/Core/index.d.ts | 9 +- .../lib/activitypub/Extended/Activity.d.ts | 108 ++-- .../lib/activitypub/Extended/Actor.d.ts | 69 ++- .../lib/activitypub/Extended/Collection.d.ts | 44 +- .../activitypub/Extended/ExtendedObject.d.ts | 66 ++- .../lib/activitypub/Extended/index.d.ts | 72 ++- .../lib/activitypub/index.d.ts | 89 ++- .../lib/activitypub/util/const.d.ts | 358 +++++------ .../lib/activitypub/util/values.d.ts | 2 +- .../activitypub-core-types/lib/index.d.ts | 38 +- packages/activitypub-core-types/package.json | 4 +- .../activitypub-core-utilities/.prettierrc | 6 + .../__tests__/compressEntity.ts | 6 +- .../__tests__/convertStringsToUrls.ts | 14 +- .../__tests__/convertUrlsToStrings.ts | 14 +- .../__tests__/getId.ts | 2 +- .../lib/addContext.d.ts | 2 +- .../lib/convertFromJsonLd.d.ts | 4 +- .../lib/convertStringsToUrls.d.ts | 2 +- .../lib/generateKeyPair.d.ts | 4 +- .../activitypub-core-utilities/lib/getId.d.ts | 4 +- .../lib/getTypedEntity.d.ts | 47 +- .../lib/globals.d.ts | 27 +- .../lib/parseStream.d.ts | 4 +- .../lib/streamToString.d.ts | 4 +- .../activitypub-core-utilities/package.json | 6 +- .../src/combineAddresses.ts | 36 +- .../src/compressEntity.ts | 18 +- .../src/convertStringsToUrls.ts | 6 +- .../src/convertUrlsToStrings.ts | 2 +- .../activitypub-core-utilities/src/globals.ts | 5 +- .../src/parseStream.ts | 14 +- .../src/stringifyWithContext.ts | 8 +- packages/activitypub-core/.prettierrc | 6 + packages/activitypub-core/__tests__/box.ts | 17 +- packages/activitypub-core/__tests__/data.ts | 46 +- packages/activitypub-core/__tests__/entity.ts | 18 +- packages/activitypub-core/__tests__/home.ts | 6 +- .../__tests__/mockDatabaseService.ts | 2 +- .../__tests__/outbox/get_html.ts | 6 +- .../__tests__/outbox/get_json.ts | 6 +- .../activitypub-core/lib/entity/index.d.ts | 15 +- packages/activitypub-core/lib/entity/index.js | 3 +- .../activitypub-core/lib/entity/index.js.map | 2 +- packages/activitypub-core/lib/home/index.d.ts | 35 +- packages/activitypub-core/lib/home/index.js | 2 +- .../activitypub-core/lib/home/index.js.map | 2 +- .../activitypub-core/lib/inbox/accept.d.ts | 5 +- .../activitypub-core/lib/inbox/announce.d.ts | 5 +- .../activitypub-core/lib/inbox/follow.d.ts | 6 +- .../activitypub-core/lib/inbox/index.d.ts | 67 ++- packages/activitypub-core/lib/inbox/like.d.ts | 5 +- .../lib/inbox/shouldForwardActivity.d.ts | 6 +- packages/activitypub-core/lib/index.d.ts | 1 + packages/activitypub-core/lib/index.js | 4 +- packages/activitypub-core/lib/index.js.map | 2 +- packages/activitypub-core/lib/outbox/add.d.ts | 5 +- .../activitypub-core/lib/outbox/announce.d.ts | 5 +- .../activitypub-core/lib/outbox/create.d.ts | 5 +- .../activitypub-core/lib/outbox/delete.d.ts | 5 +- .../activitypub-core/lib/outbox/index.d.ts | 67 ++- .../activitypub-core/lib/outbox/like.d.ts | 5 +- .../activitypub-core/lib/outbox/remove.d.ts | 5 +- .../lib/outbox/undo/index.d.ts | 6 +- .../lib/outbox/undo/undoAnnounce.d.ts | 5 +- .../lib/outbox/undo/undoLike.d.ts | 5 +- .../activitypub-core/lib/outbox/update.d.ts | 5 +- .../lib/sharedInbox/index.d.ts | 18 + .../activitypub-core/lib/sharedInbox/index.js | 119 ++++ .../lib/sharedInbox/index.js.map | 1 + .../lib/user/createServerActor.d.ts | 4 +- .../lib/user/createUserActor.d.ts | 7 +- packages/activitypub-core/lib/user/index.d.ts | 13 +- packages/activitypub-core/package.json | 4 +- packages/activitypub-core/src/entity/index.ts | 6 +- packages/activitypub-core/src/home/index.ts | 28 +- packages/activitypub-core/src/inbox/follow.ts | 6 +- packages/activitypub-core/src/inbox/index.ts | 2 +- packages/activitypub-core/src/index.ts | 3 +- .../activitypub-core/src/outbox/create.ts | 11 +- packages/activitypub-core/src/outbox/index.ts | 11 +- packages/activitypub-core/src/outbox/like.ts | 5 +- .../activitypub-core/src/outbox/update.ts | 4 +- .../activitypub-core/src/sharedInbox/index.ts | 2 +- .../src/user/createServerActor.ts | 10 +- .../src/user/createUserActor.ts | 69 ++- packages/activitypub-core/src/user/index.ts | 56 +- 169 files changed, 2158 insertions(+), 1195 deletions(-) create mode 100644 .eslintrc.json create mode 100644 LICENSE create mode 100644 packages/activitypub-core-delivery/.prettierrc create mode 100644 packages/activitypub-core-example-2/lib/credentials.d.ts create mode 100644 packages/activitypub-core-example-2/lib/credentials.js create mode 100644 packages/activitypub-core-example-2/lib/credentials.js.map create mode 100644 packages/activitypub-core-example-2/lib/index.d.ts create mode 100644 packages/activitypub-core-example-2/lib/index.js create mode 100644 packages/activitypub-core-example-2/lib/index.js.map create mode 100644 packages/activitypub-core-express-middleware/.prettierrc create mode 100644 packages/activitypub-core-jsx-components/.prettierrc create mode 100644 packages/activitypub-core-mongodb/.prettierrc create mode 100644 packages/activitypub-core-types/.prettierrc create mode 100644 packages/activitypub-core-utilities/.prettierrc create mode 100644 packages/activitypub-core/.prettierrc create mode 100644 packages/activitypub-core/lib/sharedInbox/index.d.ts create mode 100644 packages/activitypub-core/lib/sharedInbox/index.js create mode 100644 packages/activitypub-core/lib/sharedInbox/index.js.map diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..bffb357a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..b130ce7e --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright © 2022 Michael Puckett + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ce849817..96db79c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4005,6 +4005,10 @@ "resolved": "packages/activitypub-core-delivery", "link": true }, + "node_modules/activitypub-core-example-2": { + "resolved": "packages/activitypub-core-example-2", + "link": true + }, "node_modules/activitypub-core-example-mongodb-express-jsx": { "resolved": "packages/activitypub-core-example-mongodb-express-jsx", "link": true @@ -11063,6 +11067,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.1.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.1.2.tgz", @@ -13775,12 +13794,12 @@ } }, "packages/activitypub-core": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-delivery": "^0.0.43", - "activitypub-core-types": "^0.0.42", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "cookie": "^0.5.0", "firebase-admin": "^11.1.0", "http": "^0.0.1-security", @@ -13797,16 +13816,17 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } }, "packages/activitypub-core-delivery": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "isomorphic-fetch": "^3.0.0" }, "devDependencies": { @@ -13814,15 +13834,11 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } }, - "packages/activitypub-core-delivery/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "packages/activitypub-core-delivery/node_modules/dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -13832,15 +13848,120 @@ "node": ">=12" } }, - "packages/activitypub-core-example-mongodb-express-jsx": { - "version": "0.0.51", + "packages/activitypub-core-example-2": { + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-delivery": "^0.0.51", - "activitypub-core-express-middleware": "^0.0.51", - "activitypub-core-jsx-components": "^0.0.51", - "activitypub-core-types": "^0.0.51", - "activitypub-core-utilities": "^0.0.51", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-express-middleware": "^0.0.54", + "activitypub-core-jsx-components": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", + "firebase-admin": "^11.1.0", + "react": "^16.14.0", + "react-server": "^0.8.1" + }, + "devDependencies": { + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "ts-node": "^10.9.1" + } + }, + "packages/activitypub-core-example-2/node_modules/cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha512-+IJOX0OqlHCszo2mBUq+SrEbCj6w7Kpffqx60zYbPTFaO4+yYgRjHwcZNpWvaTylDHaV7PPmBHzSecZiMhtPgw==", + "engines": { + "node": ">= 0.6" + } + }, + "packages/activitypub-core-example-2/node_modules/eventemitter3": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", + "integrity": "sha512-jLN68Dx5kyFHaePoXWPsCGW5qdyZQtLYHkxkg02/Mz6g0kYpDx4FyP6XfArhQdlOC4b8Mv+EMxPo/8La7Tzghg==" + }, + "packages/activitypub-core-example-2/node_modules/q": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.4.1.tgz", + "integrity": "sha512-/CdEdaw49VZVmyIDGUQKDDT53c7qBkO6g5CefWz91Ae+l4+cRtcDYwMTXh6me4O8TMldeGHG3N2Bl84V78Ywbg==", + "engines": { + "node": ">=0.6.0", + "teleport": ">=0.2.0" + } + }, + "packages/activitypub-core-example-2/node_modules/react": { + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", + "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", + "dependencies": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "packages/activitypub-core-example-2/node_modules/react-dom": { + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", + "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2", + "scheduler": "^0.19.1" + }, + "peerDependencies": { + "react": "^16.14.0" + } + }, + "packages/activitypub-core-example-2/node_modules/react-server": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/react-server/-/react-server-0.8.1.tgz", + "integrity": "sha512-1l0IAUF1sd5pK2Y6aResnH/47N9CPza3dQdA0e/pdYRYn8I9sZpsc9PBc+//xOcq+CHh/TU6JX9pBHQ25BC1tA==", + "dependencies": { + "body-parser": "^1.15.2", + "cls-q": "1.1.0", + "cookie": "^0.3.1", + "cookie-parser": "1.4.3", + "eventemitter3": "^2.0.2", + "express-state": "^1.4.0", + "flab": "^0.6.3", + "lodash": "^4.16.4", + "mobile-detect": "^1.3.5", + "q": "1.4.1", + "querystring": "0.2.0", + "request-local-storage": "^1.2.0", + "routr": "^2.1.0", + "winston": "^2.3.0" + }, + "peerDependencies": { + "react": "~0.14.9 || ^15.3.0 || ^16.0.0", + "react-dom": "~0.14.9 || ^15.3.0 || ^16.0.0", + "superagent": "1.8.4" + } + }, + "packages/activitypub-core-example-2/node_modules/scheduler": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", + "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1" + } + }, + "packages/activitypub-core-example-mongodb-express-jsx": { + "version": "0.0.54", + "license": "MIT", + "dependencies": { + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-express-middleware": "^0.0.54", + "activitypub-core-jsx-components": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "firebase-admin": "^11.1.0", "react": "^16.14.0", "react-server": "^0.8.1" @@ -13975,72 +14096,44 @@ } }, "packages/activitypub-core-express-middleware": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core": "^0.0.51", - "activitypub-core-delivery": "^0.0.41", - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core": "^0.0.54", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "express": "^4.18.2", "firebase-admin": "^11.1.0", "http": "^0.0.1-security" }, "devDependencies": { + "prettier": "^2.7.1", "ts-node": "^10.9.1" } }, - "packages/activitypub-core-express-middleware/node_modules/activitypub-core-delivery": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.41.tgz", - "integrity": "sha512-4e6WAKNX204/Jk302g3gv1shFQUzYsxmrP4v5PthfDkxnPpn/I+yPb32YRe2oZcV/j3wD7C/580Uq7OfXiyIqQ==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - } - }, - "packages/activitypub-core-express-middleware/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, - "packages/activitypub-core-express-middleware/node_modules/activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - } - }, "packages/activitypub-core-jsx-components": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "firebase": "^9.12.0", "react": "^18.2.0" }, "devDependencies": { "@types/react": "^18.0.21", + "prettier": "^2.7.1", "ts-node": "^10.9.1" } }, - "packages/activitypub-core-jsx-components/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "packages/activitypub-core-mongodb": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-delivery": "^0.0.41", - "activitypub-core-types": "^0.0.41", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "firebase-admin": "^11.1.0", "mongodb": "^4.10.0" }, @@ -14048,48 +14141,11 @@ "@types/jest": "^29.1.2", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } }, - "packages/activitypub-core-mongodb/node_modules/activitypub-core-delivery": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.41.tgz", - "integrity": "sha512-4e6WAKNX204/Jk302g3gv1shFQUzYsxmrP4v5PthfDkxnPpn/I+yPb32YRe2oZcV/j3wD7C/580Uq7OfXiyIqQ==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - } - }, - "packages/activitypub-core-mongodb/node_modules/activitypub-core-delivery/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, - "packages/activitypub-core-mongodb/node_modules/activitypub-core-types": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.41.tgz", - "integrity": "sha512-kIaJ6Jxwc1BeeO7j/Xm//070L07dckLPd/Qs3SkaJ02ytBunI1XbkSqFReSXRNd9UUYUS47XPAfd5BbHAPUU0w==", - "dependencies": { - "activitypub-core-utilities": "^0.0.40" - } - }, - "packages/activitypub-core-mongodb/node_modules/activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - } - }, - "packages/activitypub-core-mongodb/node_modules/activitypub-core-utilities/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "packages/activitypub-core-mongodb/node_modules/dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -14100,17 +14156,18 @@ } }, "packages/activitypub-core-types": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "devDependencies": { + "prettier": "^2.7.1", "ts-node": "^10.9.1" } }, "packages/activitypub-core-utilities": { - "version": "0.0.51", + "version": "0.0.54", "license": "MIT", "dependencies": { - "activitypub-core-types": "^0.0.40", + "activitypub-core-types": "^0.0.54", "jsonld": "^8.1.0", "superjson": "^1.10.1" }, @@ -14119,15 +14176,11 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } }, - "packages/activitypub-core-utilities/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "packages/activitypub-core-utilities/node_modules/dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -14137,36 +14190,6 @@ "node": ">=12" } }, - "packages/activitypub-core/node_modules/activitypub-core-delivery": { - "version": "0.0.43", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.43.tgz", - "integrity": "sha512-1SpZONwEvH5IR+hG6Rv7zDgfCLkdqhJ2drLYyUzfC8cPqLoxP8jOwFSd9wuqkzu6CDkxs46Viq0ZqQinjKUXLA==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - } - }, - "packages/activitypub-core/node_modules/activitypub-core-delivery/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, - "packages/activitypub-core/node_modules/activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "dependencies": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - } - }, - "packages/activitypub-core/node_modules/activitypub-core-utilities/node_modules/activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "packages/activitypub-core/node_modules/dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -17389,9 +17412,9 @@ "@types/isomorphic-fetch": "^0.0.36", "@types/jest": "^29.1.2", "@types/jsonld": "^1.5.6", - "activitypub-core-delivery": "^0.0.43", - "activitypub-core-types": "^0.0.42", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "cookie": "^0.5.0", "dotenv": "^16.0.3", "firebase-admin": "^11.1.0", @@ -17401,45 +17424,12 @@ "jsonld": "^8.1.0", "mongodb": "^4.10.0", "next": "^12.3.1", + "prettier": "*", "superjson": "^1.10.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" }, "dependencies": { - "activitypub-core-delivery": { - "version": "0.0.43", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.43.tgz", - "integrity": "sha512-1SpZONwEvH5IR+hG6Rv7zDgfCLkdqhJ2drLYyUzfC8cPqLoxP8jOwFSd9wuqkzu6CDkxs46Viq0ZqQinjKUXLA==", - "requires": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - }, - "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - } - } - }, - "activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "requires": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - }, - "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - } - } - }, "dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -17453,20 +17443,16 @@ "requires": { "@types/jest": "^29.1.2", "@types/jsonld": "^1.5.6", - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "dotenv": "^16.0.3", "isomorphic-fetch": "^3.0.0", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" }, "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -17475,16 +17461,102 @@ } } }, + "activitypub-core-example-2": { + "version": "file:packages/activitypub-core-example-2", + "requires": { + "@types/react": "^18.0.21", + "@types/react-dom": "^18.0.6", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-express-middleware": "^0.0.54", + "activitypub-core-jsx-components": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", + "firebase-admin": "^11.1.0", + "react": "^16.14.0", + "react-server": "^0.8.1", + "ts-node": "^10.9.1" + }, + "dependencies": { + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha512-+IJOX0OqlHCszo2mBUq+SrEbCj6w7Kpffqx60zYbPTFaO4+yYgRjHwcZNpWvaTylDHaV7PPmBHzSecZiMhtPgw==" + }, + "eventemitter3": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", + "integrity": "sha512-jLN68Dx5kyFHaePoXWPsCGW5qdyZQtLYHkxkg02/Mz6g0kYpDx4FyP6XfArhQdlOC4b8Mv+EMxPo/8La7Tzghg==" + }, + "q": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.4.1.tgz", + "integrity": "sha512-/CdEdaw49VZVmyIDGUQKDDT53c7qBkO6g5CefWz91Ae+l4+cRtcDYwMTXh6me4O8TMldeGHG3N2Bl84V78Ywbg==" + }, + "react": { + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", + "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2" + } + }, + "react-dom": { + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", + "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", + "peer": true, + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1", + "prop-types": "^15.6.2", + "scheduler": "^0.19.1" + } + }, + "react-server": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/react-server/-/react-server-0.8.1.tgz", + "integrity": "sha512-1l0IAUF1sd5pK2Y6aResnH/47N9CPza3dQdA0e/pdYRYn8I9sZpsc9PBc+//xOcq+CHh/TU6JX9pBHQ25BC1tA==", + "requires": { + "body-parser": "^1.15.2", + "cls-q": "1.1.0", + "cookie": "^0.3.1", + "cookie-parser": "1.4.3", + "eventemitter3": "^2.0.2", + "express-state": "^1.4.0", + "flab": "^0.6.3", + "lodash": "^4.16.4", + "mobile-detect": "^1.3.5", + "q": "1.4.1", + "querystring": "0.2.0", + "request-local-storage": "^1.2.0", + "routr": "^2.1.0", + "winston": "^2.3.0" + } + }, + "scheduler": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", + "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "peer": true, + "requires": { + "loose-envify": "^1.1.0", + "object-assign": "^4.1.1" + } + } + } + }, "activitypub-core-example-mongodb-express-jsx": { "version": "file:packages/activitypub-core-example-mongodb-express-jsx", "requires": { "@types/react": "^18.0.21", "@types/react-dom": "^18.0.6", - "activitypub-core-delivery": "^0.0.51", - "activitypub-core-express-middleware": "^0.0.51", - "activitypub-core-jsx-components": "^0.0.51", - "activitypub-core-types": "^0.0.51", - "activitypub-core-utilities": "^0.0.51", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-express-middleware": "^0.0.54", + "activitypub-core-jsx-components": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "firebase-admin": "^11.1.0", "react": "^16.14.0", "react-server": "^0.8.1", @@ -17564,118 +17636,45 @@ "activitypub-core-express-middleware": { "version": "file:packages/activitypub-core-express-middleware", "requires": { - "activitypub-core": "^0.0.51", - "activitypub-core-delivery": "^0.0.41", - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core": "^0.0.54", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "express": "^4.18.2", "firebase-admin": "^11.1.0", "http": "^0.0.1-security", + "prettier": "^2.7.1", "ts-node": "^10.9.1" - }, - "dependencies": { - "activitypub-core-delivery": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.41.tgz", - "integrity": "sha512-4e6WAKNX204/Jk302g3gv1shFQUzYsxmrP4v5PthfDkxnPpn/I+yPb32YRe2oZcV/j3wD7C/580Uq7OfXiyIqQ==", - "requires": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - } - }, - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, - "activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "requires": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - } - } } }, "activitypub-core-jsx-components": { "version": "file:packages/activitypub-core-jsx-components", "requires": { "@types/react": "^18.0.21", - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "firebase": "^9.12.0", + "prettier": "^2.7.1", "react": "^18.2.0", "ts-node": "^10.9.1" - }, - "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - } } }, "activitypub-core-mongodb": { "version": "file:packages/activitypub-core-mongodb", "requires": { "@types/jest": "^29.1.2", - "activitypub-core-delivery": "^0.0.41", - "activitypub-core-types": "^0.0.41", - "activitypub-core-utilities": "^0.0.40", + "activitypub-core-delivery": "^0.0.54", + "activitypub-core-types": "^0.0.54", + "activitypub-core-utilities": "^0.0.54", "dotenv": "^16.0.3", "firebase-admin": "^11.1.0", "jest": "^29.1.2", "mongodb": "^4.10.0", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" }, "dependencies": { - "activitypub-core-delivery": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-delivery/-/activitypub-core-delivery-0.0.41.tgz", - "integrity": "sha512-4e6WAKNX204/Jk302g3gv1shFQUzYsxmrP4v5PthfDkxnPpn/I+yPb32YRe2oZcV/j3wD7C/580Uq7OfXiyIqQ==", - "requires": { - "activitypub-core-types": "^0.0.40", - "activitypub-core-utilities": "^0.0.40", - "isomorphic-fetch": "^3.0.0" - }, - "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - } - } - }, - "activitypub-core-types": { - "version": "0.0.41", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.41.tgz", - "integrity": "sha512-kIaJ6Jxwc1BeeO7j/Xm//070L07dckLPd/Qs3SkaJ02ytBunI1XbkSqFReSXRNd9UUYUS47XPAfd5BbHAPUU0w==", - "requires": { - "activitypub-core-utilities": "^0.0.40" - } - }, - "activitypub-core-utilities": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-utilities/-/activitypub-core-utilities-0.0.40.tgz", - "integrity": "sha512-aGwj93MH2F5fl6QCiFD6vdwLEb5nfl5uN2RMXncX2hNweCX1fqh9es0p2it2W1OPzkeEFDziEwpEV5C8hwJ1oA==", - "requires": { - "activitypub-core-types": "^0.0.40", - "jsonld": "^8.1.0", - "superjson": "^1.10.1" - }, - "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - } - } - }, "dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -17687,6 +17686,7 @@ "activitypub-core-types": { "version": "file:packages/activitypub-core-types", "requires": { + "prettier": "^2.7.1", "ts-node": "^10.9.1" } }, @@ -17695,20 +17695,16 @@ "requires": { "@types/jest": "^29.1.2", "@types/jsonld": "^1.5.6", - "activitypub-core-types": "^0.0.40", + "activitypub-core-types": "^0.0.54", "dotenv": "^16.0.3", "jest": "^29.1.2", "jsonld": "^8.1.0", + "prettier": "^2.7.1", "superjson": "^1.10.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" }, "dependencies": { - "activitypub-core-types": { - "version": "0.0.40", - "resolved": "https://registry.npmjs.org/activitypub-core-types/-/activitypub-core-types-0.0.40.tgz", - "integrity": "sha512-DwbhWt87m951/c6wxThpREQBWiu2bs0QXOvs5VqHM03iLLgjAG+CxMdg2mbEAuR1dSiMYg6KU/dtemJHqNTX0A==" - }, "dotenv": { "version": "16.0.3", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", @@ -23113,6 +23109,12 @@ "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==", "optional": true }, + "prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true + }, "pretty-format": { "version": "29.1.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.1.2.tgz", diff --git a/packages/activitypub-core-delivery/.prettierrc b/packages/activitypub-core-delivery/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-delivery/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-delivery/__x_tests__/signAndSendToForeignActorInbox.ts b/packages/activitypub-core-delivery/__x_tests__/signAndSendToForeignActorInbox.ts index dfe7b732..1d42c2d9 100644 --- a/packages/activitypub-core-delivery/__x_tests__/signAndSendToForeignActorInbox.ts +++ b/packages/activitypub-core-delivery/__x_tests__/signAndSendToForeignActorInbox.ts @@ -3,7 +3,6 @@ import { AP } from 'activitypub-core-types'; import { generateKeyPair } from 'activitypub-core-utilities'; import { DeliveryService } from '../src'; - describe('DeliveryService', () => { describe('signAndSendToForeignActorInbox', () => { const fetch = jest.fn(async () => { diff --git a/packages/activitypub-core-delivery/lib/broadcast.d.ts b/packages/activitypub-core-delivery/lib/broadcast.d.ts index feb46d8d..284d608c 100644 --- a/packages/activitypub-core-delivery/lib/broadcast.d.ts +++ b/packages/activitypub-core-delivery/lib/broadcast.d.ts @@ -1,3 +1,7 @@ import { DeliveryService } from '.'; import { AP } from 'activitypub-core-types'; -export declare function broadcast(this: DeliveryService, activity: AP.Activity, actor: AP.Actor): Promise; +export declare function broadcast( + this: DeliveryService, + activity: AP.Activity, + actor: AP.Actor, +): Promise; diff --git a/packages/activitypub-core-delivery/lib/broadcast.js b/packages/activitypub-core-delivery/lib/broadcast.js index dcee6af5..ecf91910 100644 --- a/packages/activitypub-core-delivery/lib/broadcast.js +++ b/packages/activitypub-core-delivery/lib/broadcast.js @@ -10,9 +10,10 @@ async function broadcast(activity, actor) { throw new Error('Not an activity?'); } const recipients = await this.getRecipientInboxUrls(activity, actor); - return await Promise.all(recipients.map(async (recipient) => { + const results = await Promise.all(recipients.map(async (recipient) => { return await this.signAndSendToForeignActorInbox(recipient, actor, publicActivity); })); + return results; } exports.broadcast = broadcast; //# sourceMappingURL=broadcast.js.map \ No newline at end of file diff --git a/packages/activitypub-core-delivery/lib/broadcast.js.map b/packages/activitypub-core-delivery/lib/broadcast.js.map index 45f31cdb..2acfa5a1 100644 --- a/packages/activitypub-core-delivery/lib/broadcast.js.map +++ b/packages/activitypub-core-delivery/lib/broadcast.js.map @@ -1 +1 @@ -{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":";;;AAEA,2EAAwD;AACxD,2EAAwD;AACxD,2EAA4D;AAMrD,KAAK,UAAU,SAAS,CAE7B,QAAqB,EACrB,KAAe;IAEf,MAAM,cAAc,GAAG,IAAA,uCAAU,EAAC,IAAA,uCAAU,EAAC,IAAA,2CAAc,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExE,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,MAAM,OAAO,CAAC,GAAG,CACtB,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;AACJ,CAAC;AAtBD,8BAsBC"} \ No newline at end of file +{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../src/broadcast.ts"],"names":[],"mappings":";;;AAEA,2EAAwD;AACxD,2EAAwD;AACxD,2EAA4D;AAMrD,KAAK,UAAU,SAAS,CAE7B,QAAqB,EACrB,KAAe;IAEf,MAAM,cAAc,GAAG,IAAA,uCAAU,EAAC,IAAA,uCAAU,EAAC,IAAA,2CAAc,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExE,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;IAEpE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,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;AAxBD,8BAwBC"} \ No newline at end of file diff --git a/packages/activitypub-core-delivery/lib/getPrivateKey.d.ts b/packages/activitypub-core-delivery/lib/getPrivateKey.d.ts index 174ef2f8..a9e327b8 100644 --- a/packages/activitypub-core-delivery/lib/getPrivateKey.d.ts +++ b/packages/activitypub-core-delivery/lib/getPrivateKey.d.ts @@ -1,3 +1,6 @@ import { DeliveryService } from '.'; import { AP } from 'activitypub-core-types'; -export declare function getPrivateKey(this: DeliveryService, actor: AP.Actor): Promise; +export declare function getPrivateKey( + this: DeliveryService, + actor: AP.Actor, +): Promise; diff --git a/packages/activitypub-core-delivery/lib/getRecipientInboxUrls.d.ts b/packages/activitypub-core-delivery/lib/getRecipientInboxUrls.d.ts index 7a730363..3fe901b2 100644 --- a/packages/activitypub-core-delivery/lib/getRecipientInboxUrls.d.ts +++ b/packages/activitypub-core-delivery/lib/getRecipientInboxUrls.d.ts @@ -1,4 +1,8 @@ /// import { DeliveryService } from '.'; import { AP } from 'activitypub-core-types'; -export declare function getRecipientInboxUrls(this: DeliveryService, activity: AP.Activity, actor: AP.Actor): Promise; +export declare function getRecipientInboxUrls( + this: DeliveryService, + activity: AP.Activity, + actor: AP.Actor, +): Promise; diff --git a/packages/activitypub-core-delivery/lib/getRecipientsList.d.ts b/packages/activitypub-core-delivery/lib/getRecipientsList.d.ts index 834e1b00..4181aa7f 100644 --- a/packages/activitypub-core-delivery/lib/getRecipientsList.d.ts +++ b/packages/activitypub-core-delivery/lib/getRecipientsList.d.ts @@ -1,4 +1,7 @@ /// import { AP } from 'activitypub-core-types'; import { DeliveryService } from '.'; -export declare function getRecipientsList(this: DeliveryService, to: AP.EntityReference | AP.EntityReference[]): Promise; +export declare function getRecipientsList( + this: DeliveryService, + to: AP.EntityReference | AP.EntityReference[], +): Promise; diff --git a/packages/activitypub-core-delivery/lib/index.d.ts b/packages/activitypub-core-delivery/lib/index.d.ts index 86ec5f1b..b29a14a4 100644 --- a/packages/activitypub-core-delivery/lib/index.d.ts +++ b/packages/activitypub-core-delivery/lib/index.d.ts @@ -5,12 +5,12 @@ import { getRecipientInboxUrls } from './getRecipientInboxUrls'; import { getRecipientsList } from './getRecipientsList'; import { signAndSendToForeignActorInbox } from './signAndSendToForeignActorInbox'; export declare class DeliveryService { - databaseService: Database; - fetch: Function; - constructor(databaseService: Database, fetchFn?: Function); - getPrivateKey: typeof getPrivateKey; - signAndSendToForeignActorInbox: typeof signAndSendToForeignActorInbox; - broadcast: typeof broadcast; - getRecipientInboxUrls: typeof getRecipientInboxUrls; - getRecipientsList: typeof getRecipientsList; + databaseService: Database; + fetch: Function; + constructor(databaseService: Database, fetchFn?: Function); + getPrivateKey: typeof getPrivateKey; + signAndSendToForeignActorInbox: typeof signAndSendToForeignActorInbox; + broadcast: typeof broadcast; + getRecipientInboxUrls: typeof getRecipientInboxUrls; + getRecipientsList: typeof getRecipientsList; } diff --git a/packages/activitypub-core-delivery/lib/signAndSendToForeignActorInbox.d.ts b/packages/activitypub-core-delivery/lib/signAndSendToForeignActorInbox.d.ts index fd8065a1..816e0174 100644 --- a/packages/activitypub-core-delivery/lib/signAndSendToForeignActorInbox.d.ts +++ b/packages/activitypub-core-delivery/lib/signAndSendToForeignActorInbox.d.ts @@ -1,4 +1,9 @@ /// import { AP } from 'activitypub-core-types'; import { DeliveryService } from '.'; -export declare function signAndSendToForeignActorInbox(this: DeliveryService, foreignActorInbox: URL, actor: AP.Actor, activity: AP.Activity): Promise; +export declare function signAndSendToForeignActorInbox( + this: DeliveryService, + foreignActorInbox: URL, + actor: AP.Actor, + activity: AP.Activity, +): Promise; diff --git a/packages/activitypub-core-delivery/package.json b/packages/activitypub-core-delivery/package.json index 5b7a4a77..9a6482cd 100644 --- a/packages/activitypub-core-delivery/package.json +++ b/packages/activitypub-core-delivery/package.json @@ -20,7 +20,8 @@ "scripts": { "tsc": "tsc --project tsconfig.json", "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js", - "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch" + "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "bugs": { "url": "https://github.com/michaelcpuckett/activitypub-core/issues" @@ -35,6 +36,7 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } diff --git a/packages/activitypub-core-delivery/src/broadcast.ts b/packages/activitypub-core-delivery/src/broadcast.ts index c34f92b3..6a6fa961 100644 --- a/packages/activitypub-core-delivery/src/broadcast.ts +++ b/packages/activitypub-core-delivery/src/broadcast.ts @@ -21,7 +21,7 @@ export async function broadcast( const recipients = await this.getRecipientInboxUrls(activity, actor); - return await Promise.all( + const results = await Promise.all( recipients.map(async (recipient) => { return await this.signAndSendToForeignActorInbox( recipient, @@ -30,4 +30,6 @@ export async function broadcast( ); }), ); + + return results; } diff --git a/packages/activitypub-core-delivery/src/signAndSendToForeignActorInbox.ts b/packages/activitypub-core-delivery/src/signAndSendToForeignActorInbox.ts index 88866f66..7958d1fa 100644 --- a/packages/activitypub-core-delivery/src/signAndSendToForeignActorInbox.ts +++ b/packages/activitypub-core-delivery/src/signAndSendToForeignActorInbox.ts @@ -3,7 +3,7 @@ import * as crypto from 'crypto'; import { CONTENT_TYPE_HEADER, ACTIVITYSTREAMS_CONTENT_TYPE, - ACCEPT_HEADER + ACCEPT_HEADER, } from 'activitypub-core-utilities'; import { DeliveryService } from '.'; diff --git a/packages/activitypub-core-example-2/lib/credentials.d.ts b/packages/activitypub-core-example-2/lib/credentials.d.ts new file mode 100644 index 00000000..67686753 --- /dev/null +++ b/packages/activitypub-core-example-2/lib/credentials.d.ts @@ -0,0 +1,3 @@ +import { ServiceAccount } from 'firebase-admin'; +declare const _default: ServiceAccount; +export default _default; diff --git a/packages/activitypub-core-example-2/lib/credentials.js b/packages/activitypub-core-example-2/lib/credentials.js new file mode 100644 index 00000000..1157b815 --- /dev/null +++ b/packages/activitypub-core-example-2/lib/credentials.js @@ -0,0 +1,16 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const serviceAccount = { + type: 'service_account', + project_id: 'socialweb-id', + private_key_id: 'a80ec37ff2f96f01a5aa4177af90e090bb48343f', + private_key: '-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC6dRuTSRujvUiR\npWlwwoqb/2yRpmLcLIg/kBbUBnRCYiwRHPvOtUwKFCgHXOqAuumZIC+yr84Cb0lI\nFCnRYUqqUYPBAi4uoUDNYJX16zGrTtSPLIdJoeuRPQ493RmRpXNK28Yz6VGCmEsl\nB3LdZ9ATMh5mnHx9I13uVStPG5X9YULU/vOpPwJRa7HRnvEixBP4cQMAUk+5nXpi\nQebryZ6/C2wOcD1JB8gFUegklLQ76BPZZK/U7Nh9u9nAzA5c5FMmmklv+nZxSpMR\nB7cBKXzgM/uoT4R8Vgh18vJpTnGktENDLA9US5wZrkQXwkzKEmuib1/Wv3rJEdON\noLuO4MJRAgMBAAECggEAD6G7wxhQ9zmU45OriFGMT1HAUgxR+MV0Ur02EhEhyWLz\nm30DkKvbCR6cJdSLWxQl0LmbEMRJECPbpUL+J9ib6uAp8edzObjjzD65s8PuW79L\nILRfTzQCTMstQ3si0UwT+LBTfeH5/GnfeuY/TK05tjJFzDJ4WVa6tugbA7x7UaJO\nCmpyNy3KTLltxbgou/2vEnx/glwqzeHW6PJYV2eJcVGmfg6xVFDR49YtxgeeZlC+\nD4XMKuEQuGhJ77+zcgIudCie7IOWDq/ejDsjDYNiZBKTiBkYTfnXe1tYM93Qf09p\nDwjZw39ElXfbChDcwZHKESMoUe68U1XKJQmNQLQKNQKBgQDt2vcTiubcXbQK1utw\n4XXe04MACuAnkZyQWlEOnGiqOsXjD5vF94147nPkAHkz8XZjpFMcH5R9d8rJ5DvM\nkN2/vBJwSPzSRBuPlJSNJfWVg+v0aBb8blQpF3a/zZ9Ih8RU8f70MHw6zTKO3wEh\ntFEu5EyMbdE2cgLX0djCMLMoUwKBgQDIrmcFXTrNmjVejPYT0zt1Y4JdhwzO9WN8\nDKKGAbKUFykzFziD6eS/+GBbMu/ap3Qb8zkiPMAbVsfnZrLt1WSQev1+LhiHueoz\nHZG3MMZKEhspZ0yQPIAyd49+DHSDd6yt63OMmCMO4yFm0vfMto30bt6/OxCMNwcm\nGFR0lIYGSwKBgQCQ/7s/np2+GSF4uiwtVESW4jop/HdJp+rZ1TU0wwTLQakBErLT\nrGYCIttjUyaQE9MoSzSfIGFVW4G0Mf6CZo3IJM7YxKXbSMnEbb9hjJJ540IkbJAW\nsut7YWJy6tb/UETPw/a4xhX1gsIfdrMp6NLU0zgXI5s2pao2BycsuqN9IQKBgCt1\nGPogZkt/yW7gN6mzZHzXP7PhOvTWTuTeF5PNak6HdXSK4sIuNEseDj+xmB9Rg+NJ\nmGXBohhJgqCprLW0MELZX2ujr8w0hnLrRFLXTRldMmSU6g+SCnDjUz+IkvKlR8+h\n3TPk/jKLHQCXTvIV1kfIepQOxlaW1AV7304fm6ZhAoGBAKIa5MUGzrK8SYGawwrV\nExDDr4oV/Fq9HZRMY0xWa2PshYEqGFB4FLc+rl6/SLTzxDehwYqXsqkLfqm2xjCf\nP1rFBnJsQhoxNQ1+b51sI+8dftrFJ7zEz7NAZ2YWtXqtu5gGyzf3qIeTkLxTpVTO\naqLRlxdKtEp0TMizftnlVl6R\n-----END PRIVATE KEY-----\n', + client_email: 'firebase-adminsdk-o0j5x@socialweb-id.iam.gserviceaccount.com', + client_id: '110281511136422720421', + auth_uri: 'https://accounts.google.com/o/oauth2/auth', + token_uri: 'https://oauth2.googleapis.com/token', + auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', + client_x509_cert_url: 'https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-o0j5x%40socialweb-id.iam.gserviceaccount.com', +}; +exports.default = serviceAccount; +//# sourceMappingURL=credentials.js.map \ No newline at end of file diff --git a/packages/activitypub-core-example-2/lib/credentials.js.map b/packages/activitypub-core-example-2/lib/credentials.js.map new file mode 100644 index 00000000..81a1479a --- /dev/null +++ b/packages/activitypub-core-example-2/lib/credentials.js.map @@ -0,0 +1 @@ +{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":";;AAEA,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,iBAAiB;IACvB,UAAU,EAAE,cAAc;IAC1B,cAAc,EAAE,0CAA0C;IAC1D,WAAW,EACT,ssDAAssD;IACxsD,YAAY,EAAE,8DAA8D;IAC5E,SAAS,EAAE,uBAAuB;IAClC,QAAQ,EAAE,2CAA2C;IACrD,SAAS,EAAE,qCAAqC;IAChD,2BAA2B,EAAE,4CAA4C;IACzE,oBAAoB,EAClB,kHAAkH;CACrH,CAAC;AAEF,kBAAe,cAAgC,CAAC"} \ No newline at end of file diff --git a/packages/activitypub-core-example-2/lib/index.d.ts b/packages/activitypub-core-example-2/lib/index.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/packages/activitypub-core-example-2/lib/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/packages/activitypub-core-example-2/lib/index.js b/packages/activitypub-core-example-2/lib/index.js new file mode 100644 index 00000000..a1c05a33 --- /dev/null +++ b/packages/activitypub-core-example-2/lib/index.js @@ -0,0 +1,46 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_1 = __importDefault(require("react")); +const express_1 = __importDefault(require("express")); +const activitypub_core_express_middleware_1 = require("activitypub-core-express-middleware"); +const activitypub_core_jsx_components_1 = require("activitypub-core-jsx-components"); +const server_1 = require("react-dom/server"); +const credentials_1 = __importDefault(require("./credentials")); +const activitypub_core_mongodb_1 = require("activitypub-core-mongodb"); +const activitypub_core_delivery_1 = require("activitypub-core-delivery"); +(async () => { + const app = (0, express_1.default)(); + const databaseService = await new activitypub_core_mongodb_1.MongoDatabaseService().connect(); + const deliveryService = new activitypub_core_delivery_1.DeliveryService(databaseService); + app.use(express_1.default.static('node_modules/activitypub-core-jsx-components/static')); + app.use((0, activitypub_core_express_middleware_1.activityPub)({ + renderIndex: async () => { + return ` + + ${(0, server_1.renderToString)(react_1.default.createElement(activitypub_core_jsx_components_1.IndexPage, null))}`; + }, + renderEntity: async ({ entity, actor }) => { + return ` + + ${(0, server_1.renderToString)(react_1.default.createElement(activitypub_core_jsx_components_1.EntityPage, { entity: entity, actor: actor }))} + `; + }, + renderHome: async ({ actor }) => { + return ` + + ${(0, server_1.renderToString)(react_1.default.createElement(activitypub_core_jsx_components_1.HomePage, { actor: actor }))} + `; + }, + }, { + databaseService, + deliveryService, + serviceAccount: credentials_1.default + })); + app.listen(process.env.PORT ?? 3001, () => { + console.log('Running...'); + }); +})(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/activitypub-core-example-2/lib/index.js.map b/packages/activitypub-core-example-2/lib/index.js.map new file mode 100644 index 00000000..ad9c3027 --- /dev/null +++ b/packages/activitypub-core-example-2/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,sDAA8B;AAC9B,6FAAkE;AAClE,qFAAkF;AAClF,6CAAkD;AAClD,gEAA2C;AAC3C,uEAAgE;AAChE,yEAA4D;AAE5D,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;IACtB,MAAM,eAAe,GAAG,MAAM,IAAI,+CAAoB,EAAE,CAAC,OAAO,EAAE,CAAC;IACnE,MAAM,eAAe,GAAG,IAAI,2CAAe,CAAC,eAAe,CAAC,CAAC;IAE7D,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,qDAAqD,CAAC,CAAC,CAAC;IAC/E,GAAG,CAAC,GAAG,CAAC,IAAA,iDAAW,EAAC;QAClB,WAAW,EAAE,KAAK,IAAI,EAAE;YACtB,OAAO;;UAEH,IAAA,uBAAc,EAAC,8BAAC,2CAAS,OAAG,CAAC,EAAE,CAAC;QACtC,CAAC;QACD,YAAY,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;YACxC,OAAO;;UAEH,IAAA,uBAAc,EAAC,8BAAC,4CAAU,IAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;OAC/D,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YAC9B,OAAO;;UAEH,IAAA,uBAAc,EAAC,8BAAC,0CAAQ,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;OAC7C,CAAC;QACJ,CAAC;KACF,EAAE;QACD,eAAe;QACf,eAAe;QACf,cAAc,EAAd,qBAAc;KACf,CAAC,CAAC,CAAC;IAEJ,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE;QACxC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"} \ No newline at end of file diff --git a/packages/activitypub-core-express-middleware/.prettierrc b/packages/activitypub-core-express-middleware/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-express-middleware/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-express-middleware/lib/index.d.ts b/packages/activitypub-core-express-middleware/lib/index.d.ts index d70a96c1..376325f6 100644 --- a/packages/activitypub-core-express-middleware/lib/index.d.ts +++ b/packages/activitypub-core-express-middleware/lib/index.d.ts @@ -4,17 +4,33 @@ import { AP } from 'activitypub-core-types'; import type { ServiceAccount } from 'firebase-admin'; import { DeliveryService } from 'activitypub-core-delivery'; import type { Database } from 'activitypub-core-types/index'; -export declare const activityPub: ({ renderIndex, renderHome, renderEntity, }: { +export declare const activityPub: ( + { + renderIndex, + renderHome, + renderEntity, + }: { renderIndex: () => Promise; - renderHome: ({ actor }: { - actor: AP.Actor; + renderHome: ({ actor }: { actor: AP.Actor }) => Promise; + renderEntity: ({ + entity, + actor, + }: { + entity: AP.Entity; + actor?: AP.Actor; }) => Promise; - renderEntity: ({ entity, actor }: { - entity: AP.Entity; - actor?: AP.Actor; - }) => Promise; -}, { serviceAccount, databaseService, deliveryService, }: { + }, + { + serviceAccount, + databaseService, + deliveryService, + }: { serviceAccount: ServiceAccount; databaseService: Database; deliveryService: DeliveryService; -}) => (req: IncomingMessage, res: ServerResponse, next: NextFunction) => Promise; + }, +) => ( + req: IncomingMessage, + res: ServerResponse, + next: NextFunction, +) => Promise; diff --git a/packages/activitypub-core-express-middleware/lib/index.js b/packages/activitypub-core-express-middleware/lib/index.js index 88b4b709..03c43cc3 100644 --- a/packages/activitypub-core-express-middleware/lib/index.js +++ b/packages/activitypub-core-express-middleware/lib/index.js @@ -9,6 +9,11 @@ const activityPub = ({ renderIndex, renderHome, renderEntity, }, { serviceAccoun next(); return; } + if (req.url === '/sharedInbox' && req.method === 'POST') { + await (0, activitypub_core_1.sharedInboxHandler)(req, res, databaseService, deliveryService); + next(); + return; + } if (req.url.startsWith('/actor/') && req.url.endsWith('/inbox')) { const result = await (0, activitypub_core_1.inboxHandler)(req, res, serviceAccount, databaseService, deliveryService); if (result.props && Object.keys(result.props).length) { diff --git a/packages/activitypub-core-express-middleware/lib/index.js.map b/packages/activitypub-core-express-middleware/lib/index.js.map index 4ed82d9e..4e3fd275 100644 --- a/packages/activitypub-core-express-middleware/lib/index.js.map +++ b/packages/activitypub-core-express-middleware/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,uDAAkH;AAKlH,2EAA0G;AAEnG,MAAM,WAAW,GAAG,CAAC,EAC1B,WA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C,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE;YACpD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,SAAS,CAAC,gDAAmB,EAAE,8CAAiB,CAAC,CAAC;YACtD,GAAG,CAAC,KAAK,CAAC,MAAM,YAAY,CAAC,IAAA,iDAAoB,EAAC,MAAM,CAAC,KAAK,CAAwD,CAAC,CAAC,CAAC;YACzH,GAAG,CAAC,GAAG,EAAE,CAAC;YACV,OAAO;SACR;QAED,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;QACrB,GAAG,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;KACR;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAxGW,QAAA,WAAW,eAwGtB"} \ No newline at end of file diff --git a/packages/activitypub-core-express-middleware/package.json b/packages/activitypub-core-express-middleware/package.json index 35b38f0a..0636013e 100644 --- a/packages/activitypub-core-express-middleware/package.json +++ b/packages/activitypub-core-express-middleware/package.json @@ -13,11 +13,13 @@ "lib" ], "devDependencies": { + "prettier": "^2.7.1", "ts-node": "^10.9.1" }, "scripts": { "tsc": "tsc --project tsconfig.json", - "dev": "ts-node ./src/index.ts" + "dev": "ts-node ./src/index.ts", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "dependencies": { "activitypub-core": "^0.0.54", diff --git a/packages/activitypub-core-express-middleware/src/index.ts b/packages/activitypub-core-express-middleware/src/index.ts index 35fca07f..310074e2 100644 --- a/packages/activitypub-core-express-middleware/src/index.ts +++ b/packages/activitypub-core-express-middleware/src/index.ts @@ -1,73 +1,119 @@ import type { NextFunction } from 'express'; import type { IncomingMessage, ServerResponse } from 'http'; -import { userPostHandler, homeGetHandler, entityGetHandler, outboxHandler, inboxHandler } from 'activitypub-core'; +import { + userPostHandler, + homeGetHandler, + entityGetHandler, + outboxHandler, + inboxHandler, + sharedInboxHandler, +} from 'activitypub-core'; import { AP } from 'activitypub-core-types'; import type { ServiceAccount } from 'firebase-admin'; import { DeliveryService } from 'activitypub-core-delivery'; import type { Database } from 'activitypub-core-types/index'; -import { CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE, convertStringsToUrls } from 'activitypub-core-utilities'; +import { + CONTENT_TYPE_HEADER, + HTML_CONTENT_TYPE, + convertStringsToUrls, +} from 'activitypub-core-utilities'; -export const activityPub = ({ - renderIndex, - renderHome, - renderEntity, -}: { - renderIndex: () => Promise, - renderHome: ({ actor }: { actor: AP.Actor }) => Promise, - renderEntity: ({ entity, actor }: { entity: AP.Entity; actor?: AP.Actor; }) => Promise, -}, { - serviceAccount, - databaseService, - deliveryService, -}: { - serviceAccount: ServiceAccount, - databaseService: Database, - deliveryService: DeliveryService, -}) => async (req: IncomingMessage, res: ServerResponse, next: NextFunction) => { - if (req.url === '/user' && req.method === 'POST') { - await userPostHandler(req, res, serviceAccount, databaseService); - next(); - return; - } - - if (req.url.startsWith('/actor/') && req.url.endsWith('/inbox')) { - const result = await inboxHandler(req, res, serviceAccount, databaseService, deliveryService); - - if (result.props && Object.keys(result.props).length) { - res.statusCode = 200; - res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); - res.write(await renderEntity(convertStringsToUrls(result.props) as unknown as { entity: AP.Entity; actor?: AP.Actor; })); - res.end(); +export const activityPub = + ( + { + renderIndex, + renderHome, + renderEntity, + }: { + renderIndex: () => Promise; + renderHome: ({ actor }: { actor: AP.Actor }) => Promise; + renderEntity: ({ + entity, + actor, + }: { + entity: AP.Entity; + actor?: AP.Actor; + }) => Promise; + }, + { + serviceAccount, + databaseService, + deliveryService, + }: { + serviceAccount: ServiceAccount; + databaseService: Database; + deliveryService: DeliveryService; + }, + ) => + async (req: IncomingMessage, res: ServerResponse, next: NextFunction) => { + if (req.url === '/user' && req.method === 'POST') { + await userPostHandler(req, res, serviceAccount, databaseService); + next(); + return; } - return; - } - if (req.url.startsWith('/actor/') && req.url.endsWith('/outbox')) { - const result = await outboxHandler(req, res, serviceAccount, databaseService, deliveryService); - if (result.props && Object.keys(result.props).length && 'entity' in result.props) { - res.statusCode = 200; - res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); - res.write(await renderEntity({ - entity: convertStringsToUrls(result.props.entity as unknown as { [key: string]: unknown }) as AP.Entity, - actor: convertStringsToUrls(result.props.actor as unknown as { [key: string]: unknown }) as AP.Actor, - })); - res.end(); + if (req.url === '/sharedInbox' && req.method === 'POST') { + await sharedInboxHandler(req, res, databaseService, deliveryService); + next(); + return; } - return; - } - if (req.url === '/' && req.method === 'GET') { - res.statusCode = 200; - res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); - res.write(await renderIndex()); - res.end(); - return; - } + if (req.url.startsWith('/actor/') && req.url.endsWith('/inbox')) { + const result = await inboxHandler( + req, + res, + serviceAccount, + databaseService, + deliveryService, + ); - if (req.url === '/home' && req.method === 'GET') { - const result = await homeGetHandler(req, res, serviceAccount, databaseService); + if (result.props && Object.keys(result.props).length) { + res.statusCode = 200; + res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); + res.write( + await renderEntity( + convertStringsToUrls(result.props) as unknown as { + entity: AP.Entity; + actor?: AP.Actor; + }, + ), + ); + res.end(); + } + return; + } - if (result.redirect) { + if (req.url.startsWith('/actor/') && req.url.endsWith('/outbox')) { + const result = await outboxHandler( + req, + res, + serviceAccount, + databaseService, + deliveryService, + ); + if ( + result.props && + Object.keys(result.props).length && + 'entity' in result.props + ) { + res.statusCode = 200; + res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); + res.write( + await renderEntity({ + entity: convertStringsToUrls( + result.props.entity as unknown as { [key: string]: unknown }, + ) as AP.Entity, + actor: convertStringsToUrls( + result.props.actor as unknown as { [key: string]: unknown }, + ) as AP.Actor, + }), + ); + res.end(); + } + return; + } + + if (req.url === '/' && req.method === 'GET') { res.statusCode = 200; res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); res.write(await renderIndex()); @@ -75,34 +121,70 @@ export const activityPub = ({ return; } - if (result.props && Object.keys(result.props).length) { - res.statusCode = 200; - res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); - res.write(await renderHome(convertStringsToUrls(result.props) as { actor: AP.Actor })); + if (req.url === '/home' && req.method === 'GET') { + const result = await homeGetHandler( + req, + res, + serviceAccount, + databaseService, + ); + + if (result.redirect) { + res.statusCode = 200; + res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); + res.write(await renderIndex()); + res.end(); + return; + } + + if (result.props && Object.keys(result.props).length) { + res.statusCode = 200; + res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); + res.write( + await renderHome( + convertStringsToUrls(result.props) as { actor: AP.Actor }, + ), + ); + res.end(); + return; + } + + res.statusCode = 500; res.end(); return; } - res.statusCode = 500; - res.end(); - return; - } + if ( + req.url.startsWith('/object/') || + req.url.startsWith('/actor/') || + req.url.startsWith('/activity/') + ) { + const result = await entityGetHandler( + req, + res, + serviceAccount, + databaseService, + ); - if (req.url.startsWith('/object/') || req.url.startsWith('/actor/') || req.url.startsWith('/activity/')) { - const result = await entityGetHandler(req, res, serviceAccount, databaseService); + if (result.props && Object.keys(result.props).length) { + res.statusCode = 200; + res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); + res.write( + await renderEntity( + convertStringsToUrls(result.props) as unknown as { + entity: AP.Entity; + actor?: AP.Actor; + }, + ), + ); + res.end(); + return; + } - if (result.props && Object.keys(result.props).length) { - res.statusCode = 200; - res.setHeader(CONTENT_TYPE_HEADER, HTML_CONTENT_TYPE); - res.write(await renderEntity(convertStringsToUrls(result.props) as unknown as { entity: AP.Entity; actor?: AP.Actor; })); + res.statusCode = 500; res.end(); return; } - res.statusCode = 500; - res.end(); - return; - } - - next(); -}; \ No newline at end of file + next(); + }; diff --git a/packages/activitypub-core-jsx-components/.prettierrc b/packages/activitypub-core-jsx-components/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-jsx-components/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Activity.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Activity.d.ts index a295e9a3..6e304c4c 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Activity.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Activity.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function ActivityEntity({ activity, headingLevel }: { - activity: AP.Activity; - headingLevel: number; +export declare function ActivityEntity({ + activity, + headingLevel, +}: { + activity: AP.Activity; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Actor.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Actor.d.ts index b116046a..9f316696 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Actor.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Actor.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function ActorEntity({ actor, headingLevel }: { - actor: AP.Actor; - headingLevel: number; +export declare function ActorEntity({ + actor, + headingLevel, +}: { + actor: AP.Actor; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Collection.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Collection.d.ts index e54aa8d6..31de4101 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Collection.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Collection.d.ts @@ -1,7 +1,11 @@ /// import { AP } from 'activitypub-core-types'; -export declare function CollectionEntity({ collection, actor, headingLevel }: { - collection: AP.Collection; - actor: AP.Actor; - headingLevel: number; +export declare function CollectionEntity({ + collection, + actor, + headingLevel, +}: { + collection: AP.Collection; + actor: AP.Actor; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/CollectionPage.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/CollectionPage.d.ts index 4a046704..fc6f2f6a 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/CollectionPage.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/CollectionPage.d.ts @@ -1,5 +1,7 @@ /// import { AP } from 'activitypub-core-types'; -export declare function CollectionPageEntity({ collectionPage }: { - collectionPage: AP.CollectionPage; +export declare function CollectionPageEntity({ + collectionPage, +}: { + collectionPage: AP.CollectionPage; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Link.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Link.d.ts index 6a4f49ca..3aca884a 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Link.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Link.d.ts @@ -1,5 +1,3 @@ /// import { AP } from 'activitypub-core-types'; -export declare function LinkEntity({ link }: { - link: AP.Link; -}): JSX.Element; +export declare function LinkEntity({ link }: { link: AP.Link }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Note.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Note.d.ts index f14932e8..9ba89f94 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Note.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Note.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function NoteEntity({ note, headingLevel }: { - note: AP.Note; - headingLevel: number; +export declare function NoteEntity({ + note, + headingLevel, +}: { + note: AP.Note; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Object.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Object.d.ts index 6d6cf635..f9ec0082 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Object.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/Object.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function ObjectEntity({ object, headingLevel }: { - object: AP.ExtendedObject; - headingLevel: number; +export declare function ObjectEntity({ + object, + headingLevel, +}: { + object: AP.ExtendedObject; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollection.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollection.d.ts index a7a1338b..2d331fd3 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollection.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollection.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function OrderedCollectionEntity({ collection, headingLevel }: { - collection: AP.OrderedCollection; - headingLevel: number; +export declare function OrderedCollectionEntity({ + collection, + headingLevel, +}: { + collection: AP.OrderedCollection; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollectionPage.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollectionPage.d.ts index 5482d55f..d5a42063 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollectionPage.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/OrderedCollectionPage.d.ts @@ -1,5 +1,7 @@ /// import { AP } from 'activitypub-core-types'; -export declare function OrderedCollectionPageEntity({ orderedCollectionPage }: { - orderedCollectionPage: AP.OrderedCollectionPage; +export declare function OrderedCollectionPageEntity({ + orderedCollectionPage, +}: { + orderedCollectionPage: AP.OrderedCollectionPage; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/index.d.ts b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/index.d.ts index 5b61a32b..51350d51 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/EntityPage/index.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/EntityPage/index.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function EntityPage({ entity, actor, }: { - entity: AP.Entity; - actor?: AP.Actor; +export declare function EntityPage({ + entity, + actor, +}: { + entity: AP.Entity; + actor?: AP.Actor; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/HomePage/CreateForm.d.ts b/packages/activitypub-core-jsx-components/lib/pages/HomePage/CreateForm.d.ts index 2fe9eea3..d175a64a 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/HomePage/CreateForm.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/HomePage/CreateForm.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function CreateForm({ actor, headingLevel }: { - actor: AP.Actor; - headingLevel: number; +export declare function CreateForm({ + actor, + headingLevel, +}: { + actor: AP.Actor; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/HomePage/Sidebar.d.ts b/packages/activitypub-core-jsx-components/lib/pages/HomePage/Sidebar.d.ts index a380c60f..07524d94 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/HomePage/Sidebar.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/HomePage/Sidebar.d.ts @@ -1,5 +1,3 @@ /// import { AP } from 'activitypub-core-types'; -export declare function Sidebar({ actor }: { - actor?: AP.Actor; -}): JSX.Element; +export declare function Sidebar({ actor }: { actor?: AP.Actor }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/HomePage/Welcome.d.ts b/packages/activitypub-core-jsx-components/lib/pages/HomePage/Welcome.d.ts index 1ad7032a..10074f75 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/HomePage/Welcome.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/HomePage/Welcome.d.ts @@ -1,6 +1,9 @@ /// import { AP } from 'activitypub-core-types'; -export declare function Welcome({ actor, headingLevel }: { - actor: AP.Actor; - headingLevel: number; +export declare function Welcome({ + actor, + headingLevel, +}: { + actor: AP.Actor; + headingLevel: number; }): JSX.Element; diff --git a/packages/activitypub-core-jsx-components/lib/pages/HomePage/index.d.ts b/packages/activitypub-core-jsx-components/lib/pages/HomePage/index.d.ts index 05016878..bc5ff950 100644 --- a/packages/activitypub-core-jsx-components/lib/pages/HomePage/index.d.ts +++ b/packages/activitypub-core-jsx-components/lib/pages/HomePage/index.d.ts @@ -1,7 +1,7 @@ /// import { AP } from 'activitypub-core-types'; declare type Data = { - actor: AP.Actor; + actor: AP.Actor; }; export declare function HomePage({ actor }: Data): JSX.Element; export {}; diff --git a/packages/activitypub-core-jsx-components/package.json b/packages/activitypub-core-jsx-components/package.json index 6853defe..32a8ccf4 100644 --- a/packages/activitypub-core-jsx-components/package.json +++ b/packages/activitypub-core-jsx-components/package.json @@ -16,10 +16,12 @@ ], "scripts": { "tsc": "tsc --project tsconfig.json", - "dev": "ts-node ./src/index.ts" + "dev": "ts-node ./src/index.ts", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "devDependencies": { "@types/react": "^18.0.21", + "prettier": "^2.7.1", "ts-node": "^10.9.1" }, "dependencies": { diff --git a/packages/activitypub-core-jsx-components/src/index.ts b/packages/activitypub-core-jsx-components/src/index.ts index dbe37b50..f44e1761 100644 --- a/packages/activitypub-core-jsx-components/src/index.ts +++ b/packages/activitypub-core-jsx-components/src/index.ts @@ -1,3 +1,3 @@ export { EntityPage } from './pages/EntityPage/index'; export { HomePage } from './pages/HomePage/index'; -export { IndexPage } from './pages/IndexPage'; \ No newline at end of file +export { IndexPage } from './pages/IndexPage'; diff --git a/packages/activitypub-core-mongodb/.prettierrc b/packages/activitypub-core-mongodb/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-mongodb/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-mongodb/__tests__/expandCollection.ts b/packages/activitypub-core-mongodb/__tests__/expandCollection.ts index 83d43702..007696d8 100644 --- a/packages/activitypub-core-mongodb/__tests__/expandCollection.ts +++ b/packages/activitypub-core-mongodb/__tests__/expandCollection.ts @@ -36,7 +36,7 @@ describe('DatabaseService', () => { if (matchingObject._id === collection1Url) { return { _id: collection1Url, - ...JSON.parse(JSON.stringify(collection1Result)) + ...JSON.parse(JSON.stringify(collection1Result)), }; } @@ -50,8 +50,8 @@ describe('DatabaseService', () => { if (matchingObject._id === item2Url) { return { _id: item2Url, - ...JSON.parse(JSON.stringify(item2Result)) - } + ...JSON.parse(JSON.stringify(item2Result)), + }; } return null; diff --git a/packages/activitypub-core-mongodb/__tests__/expandEntity.ts b/packages/activitypub-core-mongodb/__tests__/expandEntity.ts index a371e49b..8774a452 100644 --- a/packages/activitypub-core-mongodb/__tests__/expandEntity.ts +++ b/packages/activitypub-core-mongodb/__tests__/expandEntity.ts @@ -9,7 +9,7 @@ describe('DatabaseService', () => { const actor1Url = 'https://test.com/actor/123'; const object1Url = 'https://test.com/object/123'; const activity1: AP.Create = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(activity1Url), url: new URL(activity1Url), type: 'Create', @@ -17,7 +17,7 @@ describe('DatabaseService', () => { object: new URL(object1Url), }; const actor1: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1Url), url: new URL(actor1Url), type: 'Person', @@ -25,14 +25,14 @@ describe('DatabaseService', () => { outbox: new URL(`${actor1Url}/outbox`), }; const object1: AP.Note = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(object1Url), url: new URL(object1Url), type: 'Note', content: 'Test', }; const activity1Result: AP.Create = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(activity1Url), url: new URL(activity1Url), type: 'Create', diff --git a/packages/activitypub-core-mongodb/__tests__/fetchEntityById.ts b/packages/activitypub-core-mongodb/__tests__/fetchEntityById.ts index 0f13e2dc..893c1570 100644 --- a/packages/activitypub-core-mongodb/__tests__/fetchEntityById.ts +++ b/packages/activitypub-core-mongodb/__tests__/fetchEntityById.ts @@ -6,7 +6,7 @@ describe('DatabaseService', () => { describe('fetchEntityById', () => { const actor1Url = 'https://foreign.test.com/456'; const actor1Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL('https://foreign.test.com/456'), url: new URL('https://foreign.test.com/456'), type: 'Person', @@ -24,8 +24,8 @@ describe('DatabaseService', () => { } return null; - } - } + }, + }; }, }); diff --git a/packages/activitypub-core-mongodb/__tests__/getCollectionItems.ts b/packages/activitypub-core-mongodb/__tests__/getCollectionItems.ts index 10f9e11d..76957008 100644 --- a/packages/activitypub-core-mongodb/__tests__/getCollectionItems.ts +++ b/packages/activitypub-core-mongodb/__tests__/getCollectionItems.ts @@ -7,7 +7,7 @@ describe('DatabaseService', () => { describe('getCollectionItems', () => { const item1Url = 'https://test.com/activity/456'; const item1Result: AP.Note = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(item1Url), url: new URL(item1Url), type: 'Note', @@ -15,7 +15,7 @@ describe('DatabaseService', () => { }; const item2Url = 'https://test.com/activity/789'; const item2Result: AP.Document = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(item2Url), url: new URL(item2Url), type: 'Document', @@ -24,7 +24,7 @@ describe('DatabaseService', () => { const collection1Url = 'https://test.com/activity/123'; const collection1Result: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', diff --git a/packages/activitypub-core-mongodb/__tests__/mockDatabaseService.ts b/packages/activitypub-core-mongodb/__tests__/mockDatabaseService.ts index d274f878..5dd557a7 100644 --- a/packages/activitypub-core-mongodb/__tests__/mockDatabaseService.ts +++ b/packages/activitypub-core-mongodb/__tests__/mockDatabaseService.ts @@ -19,11 +19,7 @@ export function mockDatabaseService({ fetchResponder?: (request: Request) => unknown; }) { const mockDbInstance = { - collection: jest.fn( - () => - db ?? { - }, - ), + collection: jest.fn(() => db ?? {}), } as unknown as Db; const fetchMock = @@ -32,7 +28,7 @@ export function mockDatabaseService({ json: fetchResponder(request), })); - let ExtendedDatabase = class extends MongoDatabase { }; + let ExtendedDatabase = class extends MongoDatabase {}; if (getActorByToken) { const ExtendedDatabase2 = class extends ExtendedDatabase { diff --git a/packages/activitypub-core-mongodb/__tests__/queryById.ts b/packages/activitypub-core-mongodb/__tests__/queryById.ts index 64c6248d..f93ccf78 100644 --- a/packages/activitypub-core-mongodb/__tests__/queryById.ts +++ b/packages/activitypub-core-mongodb/__tests__/queryById.ts @@ -7,7 +7,7 @@ describe('DatabaseService', () => { describe('queryById', () => { const object1Url = 'https://test.com/object/123'; const object1Result: AP.Note = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(object1Url), url: new URL(object1Url), type: 'Note', @@ -26,8 +26,8 @@ describe('DatabaseService', () => { } return null; - } - } + }, + }; }, }); diff --git a/packages/activitypub-core-mongodb/__tests__/saveEntity.ts b/packages/activitypub-core-mongodb/__tests__/saveEntity.ts index 288ecaab..b6aed17b 100644 --- a/packages/activitypub-core-mongodb/__tests__/saveEntity.ts +++ b/packages/activitypub-core-mongodb/__tests__/saveEntity.ts @@ -8,7 +8,7 @@ describe('DatabaseService', () => { const date = new Date('2022-01-01'); const object1Url = 'https://test.com/object/123'; const object1: AP.Note = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(object1Url), url: new URL(object1Url), type: 'Note', @@ -17,7 +17,7 @@ describe('DatabaseService', () => { }; const object1Result = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: object1Url, url: object1Url, type: 'Note', diff --git a/packages/activitypub-core-mongodb/lib/expandCollection.d.ts b/packages/activitypub-core-mongodb/lib/expandCollection.d.ts index 36544480..836946a7 100644 --- a/packages/activitypub-core-mongodb/lib/expandCollection.d.ts +++ b/packages/activitypub-core-mongodb/lib/expandCollection.d.ts @@ -1,3 +1,6 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function expandCollection(this: MongoDatabase, collection: AP.EitherCollectionReference): Promise; +export declare function expandCollection( + this: MongoDatabase, + collection: AP.EitherCollectionReference, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/expandEntity.d.ts b/packages/activitypub-core-mongodb/lib/expandEntity.d.ts index f08ed59d..694a549c 100644 --- a/packages/activitypub-core-mongodb/lib/expandEntity.d.ts +++ b/packages/activitypub-core-mongodb/lib/expandEntity.d.ts @@ -1,3 +1,6 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function expandEntity(this: MongoDatabase, originalEntity: AP.Entity): Promise; +export declare function expandEntity( + this: MongoDatabase, + originalEntity: AP.Entity, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/fetchEntityById.d.ts b/packages/activitypub-core-mongodb/lib/fetchEntityById.d.ts index ea8cdee4..a673ac8d 100644 --- a/packages/activitypub-core-mongodb/lib/fetchEntityById.d.ts +++ b/packages/activitypub-core-mongodb/lib/fetchEntityById.d.ts @@ -1,4 +1,7 @@ /// import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function fetchEntityById(this: MongoDatabase, id: URL): Promise; +export declare function fetchEntityById( + this: MongoDatabase, + id: URL, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/findAll.d.ts b/packages/activitypub-core-mongodb/lib/findAll.d.ts index e166945b..38476dba 100644 --- a/packages/activitypub-core-mongodb/lib/findAll.d.ts +++ b/packages/activitypub-core-mongodb/lib/findAll.d.ts @@ -1,5 +1,9 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function findAll(this: MongoDatabase, collection: string, matchingObject: { +export declare function findAll( + this: MongoDatabase, + collection: string, + matchingObject: { [key: string]: unknown; -}): Promise; + }, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/findEntityById.d.ts b/packages/activitypub-core-mongodb/lib/findEntityById.d.ts index 7b6bb0d2..a31b96fd 100644 --- a/packages/activitypub-core-mongodb/lib/findEntityById.d.ts +++ b/packages/activitypub-core-mongodb/lib/findEntityById.d.ts @@ -1,4 +1,7 @@ /// import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function findEntityById(this: MongoDatabase, id: URL): Promise; +export declare function findEntityById( + this: MongoDatabase, + id: URL, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/findOne.d.ts b/packages/activitypub-core-mongodb/lib/findOne.d.ts index 1905b2d7..9ffdff65 100644 --- a/packages/activitypub-core-mongodb/lib/findOne.d.ts +++ b/packages/activitypub-core-mongodb/lib/findOne.d.ts @@ -1,5 +1,9 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function findOne(this: MongoDatabase, collection: string, matchingObject: { +export declare function findOne( + this: MongoDatabase, + collection: string, + matchingObject: { [key: string]: unknown; -}): Promise; + }, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/findStringIdByValue.d.ts b/packages/activitypub-core-mongodb/lib/findStringIdByValue.d.ts index 37a5cef2..2babff3f 100644 --- a/packages/activitypub-core-mongodb/lib/findStringIdByValue.d.ts +++ b/packages/activitypub-core-mongodb/lib/findStringIdByValue.d.ts @@ -1,2 +1,6 @@ import { MongoDatabase } from '.'; -export declare function findStringIdByValue(this: MongoDatabase, dbCollection: string, value: string): Promise; +export declare function findStringIdByValue( + this: MongoDatabase, + dbCollection: string, + value: string, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/findStringValueById.d.ts b/packages/activitypub-core-mongodb/lib/findStringValueById.d.ts index 0bf5c987..e8d635d3 100644 --- a/packages/activitypub-core-mongodb/lib/findStringValueById.d.ts +++ b/packages/activitypub-core-mongodb/lib/findStringValueById.d.ts @@ -1,2 +1,6 @@ import { MongoDatabase } from '.'; -export declare function findStringValueById(this: MongoDatabase, dbCollection: string, _id: string): Promise; +export declare function findStringValueById( + this: MongoDatabase, + dbCollection: string, + _id: string, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/getActorByToken.d.ts b/packages/activitypub-core-mongodb/lib/getActorByToken.d.ts index 03c1a869..67eee6ea 100644 --- a/packages/activitypub-core-mongodb/lib/getActorByToken.d.ts +++ b/packages/activitypub-core-mongodb/lib/getActorByToken.d.ts @@ -1,4 +1,8 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; import { ServiceAccount } from 'firebase-admin'; -export declare function getActorByToken(this: MongoDatabase, token: string, credentials: ServiceAccount): Promise; +export declare function getActorByToken( + this: MongoDatabase, + token: string, + credentials: ServiceAccount, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/getAuthenticatedUserIdByToken.d.ts b/packages/activitypub-core-mongodb/lib/getAuthenticatedUserIdByToken.d.ts index 8db4a4e6..fdac17d4 100644 --- a/packages/activitypub-core-mongodb/lib/getAuthenticatedUserIdByToken.d.ts +++ b/packages/activitypub-core-mongodb/lib/getAuthenticatedUserIdByToken.d.ts @@ -1,3 +1,7 @@ import { MongoDatabase } from '.'; import { ServiceAccount } from 'firebase-admin'; -export declare function getAuthenticatedUserIdByToken(this: MongoDatabase, token: string, serviceAccount: ServiceAccount): Promise; +export declare function getAuthenticatedUserIdByToken( + this: MongoDatabase, + token: string, + serviceAccount: ServiceAccount, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/getCollectionItems.d.ts b/packages/activitypub-core-mongodb/lib/getCollectionItems.d.ts index 88ac33ba..c5cb4153 100644 --- a/packages/activitypub-core-mongodb/lib/getCollectionItems.d.ts +++ b/packages/activitypub-core-mongodb/lib/getCollectionItems.d.ts @@ -1,4 +1,7 @@ /// import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function getCollectionItems(this: MongoDatabase, entity: URL | AP.Collection | AP.OrderedCollection): Promise; +export declare function getCollectionItems( + this: MongoDatabase, + entity: URL | AP.Collection | AP.OrderedCollection, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/index.d.ts b/packages/activitypub-core-mongodb/lib/index.d.ts index 3ae25f3f..acedde6a 100644 --- a/packages/activitypub-core-mongodb/lib/index.d.ts +++ b/packages/activitypub-core-mongodb/lib/index.d.ts @@ -5,7 +5,12 @@ import { findStringValueById } from './findStringValueById'; import { findStringIdByValue } from './findStringIdByValue'; import { saveEntity } from './saveEntity'; import { saveString } from './saveString'; -import { insertItem, removeOrderedItem, insertOrderedItem, removeItem } from './insert'; +import { + insertItem, + removeOrderedItem, + insertOrderedItem, + removeItem, +} from './insert'; import { fetchEntityById } from './fetchEntityById'; import { queryById } from './queryById'; import { expandEntity } from './expandEntity'; @@ -16,28 +21,28 @@ import { getAuthenticatedUserIdByToken } from './getAuthenticatedUserIdByToken'; import { getActorByToken } from './getActorByToken'; import type { Database, DatabaseService } from 'activitypub-core-types/index'; export declare class MongoDatabase implements Database { - db: Db; - fetch: Function; - constructor(db: Db, fetchFn?: Function); - findOne: typeof findOne; - findAll: typeof findAll; - findEntityById: typeof findEntityById; - findStringValueById: typeof findStringValueById; - findStringIdByValue: typeof findStringIdByValue; - getAuthenticatedUserIdByToken: typeof getAuthenticatedUserIdByToken; - getActorByToken: typeof getActorByToken; - saveEntity: typeof saveEntity; - saveString: typeof saveString; - insertItem: typeof insertItem; - removeItem: typeof removeItem; - insertOrderedItem: typeof insertOrderedItem; - removeOrderedItem: typeof removeOrderedItem; - fetchEntityById: typeof fetchEntityById; - queryById: typeof queryById; - expandEntity: typeof expandEntity; - getCollectionItems: typeof getCollectionItems; - expandCollection: typeof expandCollection; + db: Db; + fetch: Function; + constructor(db: Db, fetchFn?: Function); + findOne: typeof findOne; + findAll: typeof findAll; + findEntityById: typeof findEntityById; + findStringValueById: typeof findStringValueById; + findStringIdByValue: typeof findStringIdByValue; + getAuthenticatedUserIdByToken: typeof getAuthenticatedUserIdByToken; + getActorByToken: typeof getActorByToken; + saveEntity: typeof saveEntity; + saveString: typeof saveString; + insertItem: typeof insertItem; + removeItem: typeof removeItem; + insertOrderedItem: typeof insertOrderedItem; + removeOrderedItem: typeof removeOrderedItem; + fetchEntityById: typeof fetchEntityById; + queryById: typeof queryById; + expandEntity: typeof expandEntity; + getCollectionItems: typeof getCollectionItems; + expandCollection: typeof expandCollection; } export declare class MongoDatabaseService implements DatabaseService { - connect(): Promise; + connect(): Promise; } diff --git a/packages/activitypub-core-mongodb/lib/insert.d.ts b/packages/activitypub-core-mongodb/lib/insert.d.ts index f6b3f0f2..e38128fa 100644 --- a/packages/activitypub-core-mongodb/lib/insert.d.ts +++ b/packages/activitypub-core-mongodb/lib/insert.d.ts @@ -1,6 +1,22 @@ /// import { MongoDatabase } from '.'; -export declare function insertOrderedItem(this: MongoDatabase, path: URL, url: URL): Promise; -export declare function removeOrderedItem(this: MongoDatabase, path: URL, url: URL): Promise; -export declare function insertItem(this: MongoDatabase, path: URL, url: URL): Promise; -export declare function removeItem(this: MongoDatabase, path: URL, url: URL): Promise; +export declare function insertOrderedItem( + this: MongoDatabase, + path: URL, + url: URL, +): Promise; +export declare function removeOrderedItem( + this: MongoDatabase, + path: URL, + url: URL, +): Promise; +export declare function insertItem( + this: MongoDatabase, + path: URL, + url: URL, +): Promise; +export declare function removeItem( + this: MongoDatabase, + path: URL, + url: URL, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/queryById.d.ts b/packages/activitypub-core-mongodb/lib/queryById.d.ts index af04e929..3b046bfc 100644 --- a/packages/activitypub-core-mongodb/lib/queryById.d.ts +++ b/packages/activitypub-core-mongodb/lib/queryById.d.ts @@ -1,4 +1,7 @@ /// import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function queryById(this: MongoDatabase, id: URL): Promise; +export declare function queryById( + this: MongoDatabase, + id: URL, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/saveEntity.d.ts b/packages/activitypub-core-mongodb/lib/saveEntity.d.ts index c411a621..cb8105bf 100644 --- a/packages/activitypub-core-mongodb/lib/saveEntity.d.ts +++ b/packages/activitypub-core-mongodb/lib/saveEntity.d.ts @@ -1,3 +1,6 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -export declare function saveEntity(this: MongoDatabase, entity: AP.Entity): Promise; +export declare function saveEntity( + this: MongoDatabase, + entity: AP.Entity, +): Promise; diff --git a/packages/activitypub-core-mongodb/lib/saveString.d.ts b/packages/activitypub-core-mongodb/lib/saveString.d.ts index 48083a16..4ab90c74 100644 --- a/packages/activitypub-core-mongodb/lib/saveString.d.ts +++ b/packages/activitypub-core-mongodb/lib/saveString.d.ts @@ -1,2 +1,7 @@ import { MongoDatabase } from '.'; -export declare function saveString(this: MongoDatabase, dbCollection: string, _id: string, value: string): Promise; +export declare function saveString( + this: MongoDatabase, + dbCollection: string, + _id: string, + value: string, +): Promise; diff --git a/packages/activitypub-core-mongodb/package.json b/packages/activitypub-core-mongodb/package.json index 6c569dd3..0317af86 100644 --- a/packages/activitypub-core-mongodb/package.json +++ b/packages/activitypub-core-mongodb/package.json @@ -20,7 +20,8 @@ "scripts": { "tsc": "tsc --project tsconfig.json", "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js", - "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch" + "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "bugs": { "url": "https://github.com/michaelcpuckett/activitypub-core/issues" @@ -36,6 +37,7 @@ "@types/jest": "^29.1.2", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } diff --git a/packages/activitypub-core-mongodb/src/fetchEntityById.ts b/packages/activitypub-core-mongodb/src/fetchEntityById.ts index 9066db6c..146053f2 100644 --- a/packages/activitypub-core-mongodb/src/fetchEntityById.ts +++ b/packages/activitypub-core-mongodb/src/fetchEntityById.ts @@ -24,13 +24,12 @@ export async function fetchEntityById( [CONTENT_TYPE_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE, [ACCEPT_HEADER]: ACTIVITYSTREAMS_CONTENT_TYPE, }, - }, - ) - .then(async (response: { - json: () => Promise<{ [key: string]: unknown }> - }) => { - return await response.json(); - }) + }) + .then( + async (response: { json: () => Promise<{ [key: string]: unknown }> }) => { + return await response.json(); + }, + ) .catch((error: unknown) => { console.log(String(error)); return null; diff --git a/packages/activitypub-core-mongodb/src/getAuthenticatedUserIdByToken.ts b/packages/activitypub-core-mongodb/src/getAuthenticatedUserIdByToken.ts index 10043db7..e1fde4e8 100644 --- a/packages/activitypub-core-mongodb/src/getAuthenticatedUserIdByToken.ts +++ b/packages/activitypub-core-mongodb/src/getAuthenticatedUserIdByToken.ts @@ -19,15 +19,15 @@ export async function getAuthenticatedUserIdByToken( const user = !token ? null : await firebaseAdmin - .auth() - .verifyIdToken(token) - .then(async (userCredential) => { - return userCredential ?? null; - }) - .catch((error: unknown) => { - console.error(String(error)); - return null; - }); + .auth() + .verifyIdToken(token) + .then(async (userCredential) => { + return userCredential ?? null; + }) + .catch((error: unknown) => { + console.error(String(error)); + return null; + }); if (!user?.uid) { return null; diff --git a/packages/activitypub-core-mongodb/src/getCollectionItems.ts b/packages/activitypub-core-mongodb/src/getCollectionItems.ts index 762be712..6a3076b8 100644 --- a/packages/activitypub-core-mongodb/src/getCollectionItems.ts +++ b/packages/activitypub-core-mongodb/src/getCollectionItems.ts @@ -50,18 +50,17 @@ export async function getCollectionItems( const foundEntity = await this.queryById(item); result.push( - foundEntity ? await this.expandEntity(foundEntity) : { - type: AP.CoreObjectTypes.TOMBSTONE, - content: 'Not found', - }, + foundEntity + ? await this.expandEntity(foundEntity) + : { + type: AP.CoreObjectTypes.TOMBSTONE, + content: 'Not found', + }, ); - } else if (!Array.isArray(item) && item.id instanceof URL) { const foundEntity = await this.queryById(item.id); - result.push( - foundEntity ?? item - ); + result.push(foundEntity ?? item); } } diff --git a/packages/activitypub-core-mongodb/src/index.ts b/packages/activitypub-core-mongodb/src/index.ts index 53c92dba..377002ad 100644 --- a/packages/activitypub-core-mongodb/src/index.ts +++ b/packages/activitypub-core-mongodb/src/index.ts @@ -68,7 +68,7 @@ export class MongoDatabase implements Database { public expandEntity = expandEntity; public getCollectionItems = getCollectionItems; public expandCollection = expandCollection; -}; +} export class MongoDatabaseService implements DatabaseService { async connect() { @@ -79,4 +79,4 @@ export class MongoDatabaseService implements DatabaseService { const db = client.db(DB_NAME); return new MongoDatabase(db, fetch); } -} \ No newline at end of file +} diff --git a/packages/activitypub-core-mongodb/src/saveEntity.ts b/packages/activitypub-core-mongodb/src/saveEntity.ts index 400684a9..925c28bd 100644 --- a/packages/activitypub-core-mongodb/src/saveEntity.ts +++ b/packages/activitypub-core-mongodb/src/saveEntity.ts @@ -1,6 +1,11 @@ import { MongoDatabase } from '.'; import { AP } from 'activitypub-core-types'; -import { addContext, cleanProps, convertUrlsToStrings, getCollectionNameByUrl } from 'activitypub-core-utilities'; +import { + addContext, + cleanProps, + convertUrlsToStrings, + getCollectionNameByUrl, +} from 'activitypub-core-utilities'; export async function saveEntity(this: MongoDatabase, entity: AP.Entity) { if (!entity.id) { diff --git a/packages/activitypub-core-types/.prettierrc b/packages/activitypub-core-types/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-types/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-types/activitypub/Extended/Collection.ts b/packages/activitypub-core-types/activitypub/Extended/Collection.ts index 0abcd7db..21c5134a 100644 --- a/packages/activitypub-core-types/activitypub/Extended/Collection.ts +++ b/packages/activitypub-core-types/activitypub/Extended/Collection.ts @@ -5,8 +5,8 @@ import { Link } from '../Core/Link'; type BaseCollection = BaseCoreObject & { type: - | typeof CollectionTypes[keyof typeof CollectionTypes] - | typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; + | typeof CollectionTypes[keyof typeof CollectionTypes] + | typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; totalItems?: number; items?: EntityReference | EntityReference[]; current?: URL | CollectionPage | Link; diff --git a/packages/activitypub-core-types/activitypub/Extended/ExtendedObject.ts b/packages/activitypub-core-types/activitypub/Extended/ExtendedObject.ts index 12966690..509c4c33 100644 --- a/packages/activitypub-core-types/activitypub/Extended/ExtendedObject.ts +++ b/packages/activitypub-core-types/activitypub/Extended/ExtendedObject.ts @@ -9,8 +9,8 @@ type BaseExtendedObject = BaseCoreObject & { export type Tombstone = BaseExtendedObject & { type: typeof ExtendedObjectTypes.TOMBSTONE; formerType?: - | typeof AllTypes[keyof typeof AllTypes] - | Array; + | typeof AllTypes[keyof typeof AllTypes] + | Array; deleted?: Date; }; diff --git a/packages/activitypub-core-types/index.ts b/packages/activitypub-core-types/index.ts index 3ea6fb27..93240192 100644 --- a/packages/activitypub-core-types/index.ts +++ b/packages/activitypub-core-types/index.ts @@ -23,4 +23,4 @@ export type Database = { export interface DatabaseService { connect(): Promise; -}; +} diff --git a/packages/activitypub-core-types/lib/activitypub/Core/CoreObject.d.ts b/packages/activitypub-core-types/lib/activitypub/Core/CoreObject.d.ts index ec96b82d..eff4a034 100644 --- a/packages/activitypub-core-types/lib/activitypub/Core/CoreObject.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Core/CoreObject.d.ts @@ -4,42 +4,45 @@ import type { EntityReference } from '.'; import type { StringReferenceMap } from '../util/values'; import type { ImageReference } from '../Extended/ExtendedObject'; import type { LinkReference } from './Link'; -import type { CollectionReference, OrderedCollectionReference } from '../Extended/Collection'; +import type { + CollectionReference, + OrderedCollectionReference, +} from '../Extended/Collection'; export interface BaseCoreObject extends BaseEntity { - type: typeof CoreObjectTypes[keyof typeof CoreObjectTypes]; - attachment?: EntityReference | EntityReference[]; - attributedTo?: EntityReference | EntityReference[]; - audience?: EntityReference | EntityReference[]; - bcc?: EntityReference | EntityReference[]; - bto?: EntityReference | EntityReference[]; - cc?: EntityReference | EntityReference[]; + type: typeof CoreObjectTypes[keyof typeof CoreObjectTypes]; + attachment?: EntityReference | EntityReference[]; + attributedTo?: EntityReference | EntityReference[]; + audience?: EntityReference | EntityReference[]; + bcc?: EntityReference | EntityReference[]; + bto?: EntityReference | EntityReference[]; + cc?: EntityReference | EntityReference[]; + content?: string; + contentMap?: StringReferenceMap; + context?: EntityReference | EntityReference[]; + duration?: string; + endTime?: Date; + generator?: EntityReference | EntityReference[]; + icon?: ImageReference | ImageReference[] | LinkReference | LinkReference[]; + image?: ImageReference | ImageReference[] | LinkReference | LinkReference[]; + inReplyTo?: EntityReference | EntityReference[]; + location?: EntityReference | EntityReference[]; + mediaType?: string; + name?: string; + nameMap?: StringReferenceMap; + preview?: EntityReference | EntityReference[]; + published?: Date; + replies?: CollectionReference; + startTime?: Date; + summary?: string; + summaryMap?: StringReferenceMap; + tag?: EntityReference | EntityReference[]; + to?: EntityReference | EntityReference[]; + updated?: Date; + url?: LinkReference | LinkReference[]; + likes?: OrderedCollectionReference; + shares?: OrderedCollectionReference; + source?: { content?: string; contentMap?: StringReferenceMap; - context?: EntityReference | EntityReference[]; - duration?: string; - endTime?: Date; - generator?: EntityReference | EntityReference[]; - icon?: ImageReference | ImageReference[] | LinkReference | LinkReference[]; - image?: ImageReference | ImageReference[] | LinkReference | LinkReference[]; - inReplyTo?: EntityReference | EntityReference[]; - location?: EntityReference | EntityReference[]; - mediaType?: string; - name?: string; - nameMap?: StringReferenceMap; - preview?: EntityReference | EntityReference[]; - published?: Date; - replies?: CollectionReference; - startTime?: Date; - summary?: string; - summaryMap?: StringReferenceMap; - tag?: EntityReference | EntityReference[]; - to?: EntityReference | EntityReference[]; - updated?: Date; - url?: LinkReference | LinkReference[]; - likes?: OrderedCollectionReference; - shares?: OrderedCollectionReference; - source?: { - content?: string; - contentMap?: StringReferenceMap; - }; + }; } diff --git a/packages/activitypub-core-types/lib/activitypub/Core/Entity.d.ts b/packages/activitypub-core-types/lib/activitypub/Core/Entity.d.ts index 2d60b015..abedaf21 100644 --- a/packages/activitypub-core-types/lib/activitypub/Core/Entity.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Core/Entity.d.ts @@ -1,7 +1,7 @@ /// import { AllTypes } from '../util/const'; export declare type BaseEntity = { - '@context'?: URL | URL[] | unknown; - id?: URL | null; - type: typeof AllTypes[keyof typeof AllTypes]; + '@context'?: URL | URL[] | unknown; + id?: URL | null; + type: typeof AllTypes[keyof typeof AllTypes]; }; diff --git a/packages/activitypub-core-types/lib/activitypub/Core/Link.d.ts b/packages/activitypub-core-types/lib/activitypub/Core/Link.d.ts index ce2e5c91..c9313226 100644 --- a/packages/activitypub-core-types/lib/activitypub/Core/Link.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Core/Link.d.ts @@ -4,19 +4,19 @@ import { LinkTypes } from '../util/const'; import { StringReferenceMap } from '../util/values'; import { EntityReference } from '.'; export interface BaseLink extends BaseEntity { - type: typeof LinkTypes[keyof typeof LinkTypes]; - height?: number; - href?: URL; - hrefLang?: string; - mediaType?: string; - name?: string; - nameMap?: StringReferenceMap; - preview?: EntityReference | EntityReference[]; - rel?: string | string[]; - width?: number; + type: typeof LinkTypes[keyof typeof LinkTypes]; + height?: number; + href?: URL; + hrefLang?: string; + mediaType?: string; + name?: string; + nameMap?: StringReferenceMap; + preview?: EntityReference | EntityReference[]; + rel?: string | string[]; + width?: number; } export interface Mention extends BaseLink { - type: typeof LinkTypes.MENTION; + type: typeof LinkTypes.MENTION; } export declare type Link = BaseLink | Mention; export declare type LinkReference = URL | Link; diff --git a/packages/activitypub-core-types/lib/activitypub/Core/index.d.ts b/packages/activitypub-core-types/lib/activitypub/Core/index.d.ts index d864163d..49a6b869 100644 --- a/packages/activitypub-core-types/lib/activitypub/Core/index.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Core/index.d.ts @@ -6,7 +6,14 @@ import { Activity } from '../Extended/Activity'; import { Collection, OrderedCollection } from '../Extended/Collection'; import { CollectionPage, OrderedCollectionPage } from '../Extended/Collection'; export type { Link, LinkReference, Mention } from './Link'; -export declare type CoreObject = ExtendedObject | Actor | Activity | Collection | OrderedCollection | CollectionPage | OrderedCollectionPage; +export declare type CoreObject = + | ExtendedObject + | Actor + | Activity + | Collection + | OrderedCollection + | CollectionPage + | OrderedCollectionPage; export declare type CoreObjectReference = URL | CoreObject; export declare type Entity = CoreObject | Link; export declare type EntityReference = URL | CoreObject | Link; diff --git a/packages/activitypub-core-types/lib/activitypub/Extended/Activity.d.ts b/packages/activitypub-core-types/lib/activitypub/Extended/Activity.d.ts index 8c872096..3865c3e3 100644 --- a/packages/activitypub-core-types/lib/activitypub/Extended/Activity.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Extended/Activity.d.ts @@ -3,105 +3,133 @@ import { BaseCoreObject } from '../Core/CoreObject'; import { ActivityTypes } from '../util/const'; import { EntityReference } from '../Core'; declare type BaseActivity = BaseCoreObject & { - type: typeof ActivityTypes[keyof typeof ActivityTypes]; - actor: EntityReference | EntityReference[]; - object?: EntityReference | EntityReference[]; - target?: EntityReference | EntityReference[]; - result?: EntityReference | EntityReference[]; - origin?: EntityReference | EntityReference[]; - instrument?: EntityReference | EntityReference[]; + type: typeof ActivityTypes[keyof typeof ActivityTypes]; + actor: EntityReference | EntityReference[]; + object?: EntityReference | EntityReference[]; + target?: EntityReference | EntityReference[]; + result?: EntityReference | EntityReference[]; + origin?: EntityReference | EntityReference[]; + instrument?: EntityReference | EntityReference[]; }; export declare type IntransitiveActivity = Omit; export declare type TransitiveActivity = BaseActivity & { - object: EntityReference | EntityReference[]; + object: EntityReference | EntityReference[]; }; export declare type Accept = BaseActivity & { - type: typeof ActivityTypes.ACCEPT; + type: typeof ActivityTypes.ACCEPT; }; export declare type TentativeAccept = Accept & { - type: typeof ActivityTypes.TENTATIVE_ACCEPT; + type: typeof ActivityTypes.TENTATIVE_ACCEPT; }; export declare type Add = BaseActivity & { - type: typeof ActivityTypes.ADD; + type: typeof ActivityTypes.ADD; }; export declare type Arrive = IntransitiveActivity & { - type: typeof ActivityTypes.ARRIVE; + type: typeof ActivityTypes.ARRIVE; }; export declare type Create = BaseActivity & { - type: typeof ActivityTypes.CREATE; + type: typeof ActivityTypes.CREATE; }; export declare type Delete = BaseActivity & { - type: typeof ActivityTypes.DELETE; + type: typeof ActivityTypes.DELETE; }; export declare type Follow = BaseActivity & { - type: typeof ActivityTypes.FOLLOW; + type: typeof ActivityTypes.FOLLOW; }; export declare type Ignore = BaseActivity & { - type: typeof ActivityTypes.IGNORE; + type: typeof ActivityTypes.IGNORE; }; export declare type Join = BaseActivity & { - type: typeof ActivityTypes.JOIN; + type: typeof ActivityTypes.JOIN; }; export declare type Leave = BaseActivity & { - type: typeof ActivityTypes.LEAVE; + type: typeof ActivityTypes.LEAVE; }; export declare type Like = BaseActivity & { - type: typeof ActivityTypes.LIKE; + type: typeof ActivityTypes.LIKE; }; export declare type Offer = BaseActivity & { - type: typeof ActivityTypes.OFFER; + type: typeof ActivityTypes.OFFER; }; export declare type Invite = Offer & { - type: typeof ActivityTypes.INVITE; + type: typeof ActivityTypes.INVITE; }; export declare type Reject = BaseActivity & { - type: typeof ActivityTypes.REJECT; + type: typeof ActivityTypes.REJECT; }; export declare type TentativeReject = Reject & { - type: typeof ActivityTypes.TENTATIVE_REJECT; + type: typeof ActivityTypes.TENTATIVE_REJECT; }; export declare type Remove = BaseActivity & { - type: typeof ActivityTypes.REMOVE; + type: typeof ActivityTypes.REMOVE; }; export declare type Undo = BaseActivity & { - type: typeof ActivityTypes.UNDO; + type: typeof ActivityTypes.UNDO; }; export declare type Update = BaseActivity & { - type: typeof ActivityTypes.UPDATE; + type: typeof ActivityTypes.UPDATE; }; export declare type View = BaseActivity & { - type: typeof ActivityTypes.VIEW; + type: typeof ActivityTypes.VIEW; }; export declare type Listen = BaseActivity & { - type: typeof ActivityTypes.LISTEN; + type: typeof ActivityTypes.LISTEN; }; export declare type Read = BaseActivity & { - type: typeof ActivityTypes.READ; + type: typeof ActivityTypes.READ; }; export declare type Move = BaseActivity & { - type: typeof ActivityTypes.MOVE; + type: typeof ActivityTypes.MOVE; }; export declare type Travel = IntransitiveActivity & { - type: typeof ActivityTypes.TRAVEL; + type: typeof ActivityTypes.TRAVEL; }; export declare type Announce = BaseActivity & { - type: typeof ActivityTypes.ANNOUNCE; + type: typeof ActivityTypes.ANNOUNCE; }; export declare type Block = Ignore & { - type: typeof ActivityTypes.BLOCK; + type: typeof ActivityTypes.BLOCK; }; export declare type Flag = BaseActivity & { - type: typeof ActivityTypes.FLAG; + type: typeof ActivityTypes.FLAG; }; export declare type Dislike = BaseActivity & { - type: typeof ActivityTypes.DISLIKE; + type: typeof ActivityTypes.DISLIKE; }; export declare type Question = IntransitiveActivity & { - type: typeof ActivityTypes.QUESTION; - oneOf: EntityReference | EntityReference[]; - anyOf: EntityReference | EntityReference[]; - closed: EntityReference | Date | boolean; + type: typeof ActivityTypes.QUESTION; + oneOf: EntityReference | EntityReference[]; + anyOf: EntityReference | EntityReference[]; + closed: EntityReference | Date | boolean; }; -export declare type Activity = Accept | Follow | Delete | Create | Arrive | Add | Offer | Like | Leave | Ignore | Join | Reject | Invite | TentativeReject | TentativeAccept | View | Update | Undo | Remove | Read | Listen | Move | Travel | Announce | Block | Flag | Dislike | Question; +export declare type Activity = + | Accept + | Follow + | Delete + | Create + | Arrive + | Add + | Offer + | Like + | Leave + | Ignore + | Join + | Reject + | Invite + | TentativeReject + | TentativeAccept + | View + | Update + | Undo + | Remove + | Read + | Listen + | Move + | Travel + | Announce + | Block + | Flag + | Dislike + | Question; export declare type ActivityReference = URL | Activity; export {}; diff --git a/packages/activitypub-core-types/lib/activitypub/Extended/Actor.d.ts b/packages/activitypub-core-types/lib/activitypub/Extended/Actor.d.ts index ae22d240..3c0af25c 100644 --- a/packages/activitypub-core-types/lib/activitypub/Extended/Actor.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Extended/Actor.d.ts @@ -1,48 +1,57 @@ /// import { BaseCoreObject } from '../Core/CoreObject'; import { ActorTypes } from '../util/const'; -import { CollectionReference, EitherCollectionReference, OrderedCollectionReference } from './Collection'; +import { + CollectionReference, + EitherCollectionReference, + OrderedCollectionReference, +} from './Collection'; import { StringReferenceMap } from '../util/values'; declare type BaseActor = BaseCoreObject & { - type: typeof ActorTypes[keyof typeof ActorTypes]; - inbox: OrderedCollectionReference; - outbox: OrderedCollectionReference; - following?: CollectionReference; - followers?: CollectionReference; - liked?: EitherCollectionReference; - preferredUsername?: string; - preferredUsernameMap?: StringReferenceMap; - streams?: EitherCollectionReference[]; - endpoints?: { - [key: string]: URL | string | undefined; - proxyUrl?: URL; - oauthAuthorizationEndpoint?: string; - oauthTokenEndpoint?: string; - provideClientKey?: string; - signClientKey?: string; - sharedInbox?: URL; - }; - publicKey?: { - id: string; - owner: string; - publicKeyPem: string; - }; + type: typeof ActorTypes[keyof typeof ActorTypes]; + inbox: OrderedCollectionReference; + outbox: OrderedCollectionReference; + following?: CollectionReference; + followers?: CollectionReference; + liked?: EitherCollectionReference; + preferredUsername?: string; + preferredUsernameMap?: StringReferenceMap; + streams?: EitherCollectionReference[]; + endpoints?: { + [key: string]: URL | string | undefined; + proxyUrl?: URL; + oauthAuthorizationEndpoint?: string; + oauthTokenEndpoint?: string; + provideClientKey?: string; + signClientKey?: string; + sharedInbox?: URL; + }; + publicKey?: { + id: string; + owner: string; + publicKeyPem: string; + }; }; export declare type Application = BaseActor & { - type: typeof ActorTypes.APPLICATION; + type: typeof ActorTypes.APPLICATION; }; export declare type Person = BaseActor & { - type: typeof ActorTypes.PERSON; + type: typeof ActorTypes.PERSON; }; export declare type Group = BaseActor & { - type: typeof ActorTypes.GROUP; + type: typeof ActorTypes.GROUP; }; export declare type Service = BaseActor & { - type: typeof ActorTypes.SERVICE; + type: typeof ActorTypes.SERVICE; }; export declare type Organization = BaseActor & { - type: typeof ActorTypes.ORGANIZATION; + type: typeof ActorTypes.ORGANIZATION; }; -export declare type Actor = Application | Service | Group | Organization | Person; +export declare type Actor = + | Application + | Service + | Group + | Organization + | Person; export declare type ActorReference = URL | Actor; export {}; diff --git a/packages/activitypub-core-types/lib/activitypub/Extended/Collection.d.ts b/packages/activitypub-core-types/lib/activitypub/Extended/Collection.d.ts index f41be646..afb746d0 100644 --- a/packages/activitypub-core-types/lib/activitypub/Extended/Collection.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Extended/Collection.d.ts @@ -4,40 +4,46 @@ import { BaseCoreObject } from '../Core/CoreObject'; import { EntityReference } from '../Core'; import { Link } from '../Core/Link'; declare type BaseCollection = BaseCoreObject & { - type: typeof CollectionTypes[keyof typeof CollectionTypes] | typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; - totalItems?: number; - items?: EntityReference | EntityReference[]; - current?: URL | CollectionPage | Link; - first?: URL | CollectionPage | Link; - last?: URL | CollectionPage | Link; + type: + | typeof CollectionTypes[keyof typeof CollectionTypes] + | typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; + totalItems?: number; + items?: EntityReference | EntityReference[]; + current?: URL | CollectionPage | Link; + first?: URL | CollectionPage | Link; + last?: URL | CollectionPage | Link; }; export declare type Collection = BaseCollection & { - type: typeof CollectionTypes.COLLECTION; + type: typeof CollectionTypes.COLLECTION; }; export declare type OrderedCollection = BaseCollection & { - type: typeof CollectionTypes.ORDERED_COLLECTION; - orderedItems?: EntityReference | EntityReference[]; + type: typeof CollectionTypes.ORDERED_COLLECTION; + orderedItems?: EntityReference | EntityReference[]; }; declare type BaseCollectionPage = BaseCollection & { - type: typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; - current?: URL | CollectionPage | Link; - first?: URL | CollectionPage | Link; - last?: URL | CollectionPage | Link; + type: typeof CollectionPageTypes[keyof typeof CollectionPageTypes]; + current?: URL | CollectionPage | Link; + first?: URL | CollectionPage | Link; + last?: URL | CollectionPage | Link; }; export declare type CollectionPage = BaseCollectionPage & { - type: typeof CollectionPageTypes.COLLECTION_PAGE; + type: typeof CollectionPageTypes.COLLECTION_PAGE; }; export declare type OrderedCollectionPage = BaseCollectionPage & { - type: typeof CollectionPageTypes.ORDERED_COLLECTION_PAGE; - startIndex?: number; - orderedItems?: EntityReference | EntityReference[]; + type: typeof CollectionPageTypes.ORDERED_COLLECTION_PAGE; + startIndex?: number; + orderedItems?: EntityReference | EntityReference[]; }; export declare type CollectionReference = URL | Collection; export declare type OrderedCollectionReference = URL | OrderedCollection; export declare type CollectionPageReference = URL | CollectionPage; -export declare type OrderedCollectionPageReference = URL | OrderedCollectionPage; +export declare type OrderedCollectionPageReference = + | URL + | OrderedCollectionPage; export declare type EitherCollection = Collection | OrderedCollection; -export declare type EitherCollectionPage = CollectionPage | OrderedCollectionPage; +export declare type EitherCollectionPage = + | CollectionPage + | OrderedCollectionPage; export declare type EitherCollectionReference = URL | EitherCollection; export declare type EitherCollectionPageReference = URL | EitherCollectionPage; export {}; diff --git a/packages/activitypub-core-types/lib/activitypub/Extended/ExtendedObject.d.ts b/packages/activitypub-core-types/lib/activitypub/Extended/ExtendedObject.d.ts index 243b3897..e8deba73 100644 --- a/packages/activitypub-core-types/lib/activitypub/Extended/ExtendedObject.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Extended/ExtendedObject.d.ts @@ -3,57 +3,71 @@ import { AllTypes, ExtendedObjectTypes } from '../util/const'; import { BaseCoreObject } from '../Core/CoreObject'; import { EntityReference, CoreObjectReference } from '../Core'; declare type BaseExtendedObject = BaseCoreObject & { - type: typeof ExtendedObjectTypes[keyof typeof ExtendedObjectTypes]; + type: typeof ExtendedObjectTypes[keyof typeof ExtendedObjectTypes]; }; export declare type Tombstone = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.TOMBSTONE; - formerType?: typeof AllTypes[keyof typeof AllTypes] | Array; - deleted?: Date; + type: typeof ExtendedObjectTypes.TOMBSTONE; + formerType?: + | typeof AllTypes[keyof typeof AllTypes] + | Array; + deleted?: Date; }; export declare type Relationship = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.RELATIONSHIP; - subject?: EntityReference; - object?: EntityReference | EntityReference[]; - relationship?: CoreObjectReference; + type: typeof ExtendedObjectTypes.RELATIONSHIP; + subject?: EntityReference; + object?: EntityReference | EntityReference[]; + relationship?: CoreObjectReference; }; export declare type Article = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.ARTICLE; + type: typeof ExtendedObjectTypes.ARTICLE; }; export declare type Note = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.NOTE; + type: typeof ExtendedObjectTypes.NOTE; }; export declare type Page = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.PAGE; + type: typeof ExtendedObjectTypes.PAGE; }; export declare type Event = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.EVENT; + type: typeof ExtendedObjectTypes.EVENT; }; export declare type Place = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.PLACE; - accuracy?: number; - altitude?: number; - latitude?: number; - longitude?: number; - radius?: number; - units?: string; + type: typeof ExtendedObjectTypes.PLACE; + accuracy?: number; + altitude?: number; + latitude?: number; + longitude?: number; + radius?: number; + units?: string; }; export declare type Document = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.DOCUMENT; + type: typeof ExtendedObjectTypes.DOCUMENT; }; export declare type Image = Document & { - type: typeof ExtendedObjectTypes.IMAGE; + type: typeof ExtendedObjectTypes.IMAGE; }; export declare type Audio = Document & { - type: typeof ExtendedObjectTypes.IMAGE; + type: typeof ExtendedObjectTypes.IMAGE; }; export declare type Video = Document & { - type: typeof ExtendedObjectTypes.IMAGE; + type: typeof ExtendedObjectTypes.IMAGE; }; export declare type Profile = BaseExtendedObject & { - type: typeof ExtendedObjectTypes.PROFILE; - describes?: CoreObjectReference; + type: typeof ExtendedObjectTypes.PROFILE; + describes?: CoreObjectReference; }; -export declare type ExtendedObject = Article | Event | Note | Page | Place | Relationship | Tombstone | Profile | Video | Document | Audio | Image; +export declare type ExtendedObject = + | Article + | Event + | Note + | Page + | Place + | Relationship + | Tombstone + | Profile + | Video + | Document + | Audio + | Image; export declare type ExtendedObjectReference = URL | ExtendedObject; export declare type ImageReference = URL | Image; export {}; diff --git a/packages/activitypub-core-types/lib/activitypub/Extended/index.d.ts b/packages/activitypub-core-types/lib/activitypub/Extended/index.d.ts index 70c3de32..330e1578 100644 --- a/packages/activitypub-core-types/lib/activitypub/Extended/index.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/Extended/index.d.ts @@ -1,10 +1,72 @@ -export type { Activity, ActivityReference, IntransitiveActivity, TransitiveActivity, Accept, Follow, Delete, Create, Arrive, Add, Offer, Like, Leave, Ignore, Join, Reject, Invite, TentativeReject, TentativeAccept, View, Update, Undo, Remove, Read, Listen, Move, Travel, Announce, Block, Flag, Dislike, Question, } from './Activity'; -export type { Actor, ActorReference, Person, Service, Group, Organization, Application, } from './Actor'; -export type { ExtendedObject, ExtendedObjectReference, Article, Event, Note, Page, Place, Relationship, Tombstone, Profile, Video, Document, Audio, Image, } from './ExtendedObject'; +export type { + Activity, + ActivityReference, + IntransitiveActivity, + TransitiveActivity, + Accept, + Follow, + Delete, + Create, + Arrive, + Add, + Offer, + Like, + Leave, + Ignore, + Join, + Reject, + Invite, + TentativeReject, + TentativeAccept, + View, + Update, + Undo, + Remove, + Read, + Listen, + Move, + Travel, + Announce, + Block, + Flag, + Dislike, + Question, +} from './Activity'; +export type { + Actor, + ActorReference, + Person, + Service, + Group, + Organization, + Application, +} from './Actor'; +export type { + ExtendedObject, + ExtendedObjectReference, + Article, + Event, + Note, + Page, + Place, + Relationship, + Tombstone, + Profile, + Video, + Document, + Audio, + Image, +} from './ExtendedObject'; export type { Collection, CollectionReference } from './Collection'; -export type { OrderedCollection, OrderedCollectionReference, } from './Collection'; +export type { + OrderedCollection, + OrderedCollectionReference, +} from './Collection'; export type { CollectionPage, CollectionPageReference } from './Collection'; -export type { OrderedCollectionPage, OrderedCollectionPageReference, } from './Collection'; +export type { + OrderedCollectionPage, + OrderedCollectionPageReference, +} from './Collection'; export type { EitherCollection } from './Collection'; export type { EitherCollectionReference } from './Collection'; export type { EitherCollectionPage } from './Collection'; diff --git a/packages/activitypub-core-types/lib/activitypub/index.d.ts b/packages/activitypub-core-types/lib/activitypub/index.d.ts index 040e6c3a..f23d3f91 100644 --- a/packages/activitypub-core-types/lib/activitypub/index.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/index.d.ts @@ -1,12 +1,89 @@ -export { CoreObjectTypes, LinkTypes, TransitiveActivityTypes, IntransitiveActivityTypes, ActivityTypes, ActorTypes, ExtendedObjectTypes, CollectionTypes, CollectionPageTypes, AllTypes, } from './util/const'; -export type { Entity, EntityReference, CoreObject, CoreObjectReference, Link, LinkReference, } from './Core'; -export type { Activity, ActivityReference, IntransitiveActivity, TransitiveActivity, Accept, Follow, Delete, Create, Arrive, Add, Offer, Like, Leave, Ignore, Join, Reject, Invite, TentativeReject, TentativeAccept, View, Update, Undo, Remove, Read, Listen, Move, Travel, Announce, Block, Flag, Dislike, Question, } from './Extended'; -export type { Actor, ActorReference, Person, Service, Group, Organization, Application, } from './Extended'; -export type { ExtendedObject, ExtendedObjectReference, Article, Event, Note, Page, Place, Relationship, Tombstone, Profile, Video, Document, Audio, Image, } from './Extended'; +export { + CoreObjectTypes, + LinkTypes, + TransitiveActivityTypes, + IntransitiveActivityTypes, + ActivityTypes, + ActorTypes, + ExtendedObjectTypes, + CollectionTypes, + CollectionPageTypes, + AllTypes, +} from './util/const'; +export type { + Entity, + EntityReference, + CoreObject, + CoreObjectReference, + Link, + LinkReference, +} from './Core'; +export type { + Activity, + ActivityReference, + IntransitiveActivity, + TransitiveActivity, + Accept, + Follow, + Delete, + Create, + Arrive, + Add, + Offer, + Like, + Leave, + Ignore, + Join, + Reject, + Invite, + TentativeReject, + TentativeAccept, + View, + Update, + Undo, + Remove, + Read, + Listen, + Move, + Travel, + Announce, + Block, + Flag, + Dislike, + Question, +} from './Extended'; +export type { + Actor, + ActorReference, + Person, + Service, + Group, + Organization, + Application, +} from './Extended'; +export type { + ExtendedObject, + ExtendedObjectReference, + Article, + Event, + Note, + Page, + Place, + Relationship, + Tombstone, + Profile, + Video, + Document, + Audio, + Image, +} from './Extended'; export type { Collection, CollectionReference } from './Extended'; export type { OrderedCollection, OrderedCollectionReference } from './Extended'; export type { CollectionPage, CollectionPageReference } from './Extended'; -export type { OrderedCollectionPage, OrderedCollectionPageReference, } from './Extended'; +export type { + OrderedCollectionPage, + OrderedCollectionPageReference, +} from './Extended'; export type { EitherCollection } from './Extended'; export type { EitherCollectionReference } from './Extended'; export type { EitherCollectionPage } from './Extended'; diff --git a/packages/activitypub-core-types/lib/activitypub/util/const.d.ts b/packages/activitypub-core-types/lib/activitypub/util/const.d.ts index 925de513..8af330e7 100644 --- a/packages/activitypub-core-types/lib/activitypub/util/const.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/util/const.d.ts @@ -1,199 +1,199 @@ export declare const ExtendedObjectTypes: { - readonly ARTICLE: "Article"; - readonly AUDIO: "Audio"; - readonly DOCUMENT: "Document"; - readonly EVENT: "Event"; - readonly IMAGE: "Image"; - readonly NOTE: "Note"; - readonly PAGE: "Page"; - readonly PLACE: "Place"; - readonly PROFILE: "Profile"; - readonly RELATIONSHIP: "Relationship"; - readonly TOMBSTONE: "Tombstone"; - readonly VIDEO: "Video"; + readonly ARTICLE: 'Article'; + readonly AUDIO: 'Audio'; + readonly DOCUMENT: 'Document'; + readonly EVENT: 'Event'; + readonly IMAGE: 'Image'; + readonly NOTE: 'Note'; + readonly PAGE: 'Page'; + readonly PLACE: 'Place'; + readonly PROFILE: 'Profile'; + readonly RELATIONSHIP: 'Relationship'; + readonly TOMBSTONE: 'Tombstone'; + readonly VIDEO: 'Video'; }; export declare const LinkTypes: { - readonly LINK: "Link"; - readonly MENTION: "Mention"; + readonly LINK: 'Link'; + readonly MENTION: 'Mention'; }; export declare const ActorTypes: { - readonly APPLICATION: "Application"; - readonly GROUP: "Group"; - readonly ORGANIZATION: "Organization"; - readonly PERSON: "Person"; - readonly SERVICE: "Service"; + readonly APPLICATION: 'Application'; + readonly GROUP: 'Group'; + readonly ORGANIZATION: 'Organization'; + readonly PERSON: 'Person'; + readonly SERVICE: 'Service'; }; export declare const TransitiveActivityTypes: { - readonly ACCEPT: "Accept"; - readonly ADD: "Add"; - readonly ANNOUNCE: "Announce"; - readonly BLOCK: "Block"; - readonly IGNORE: "Ignore"; - readonly CREATE: "Create"; - readonly DELETE: "Delete"; - readonly DISLIKE: "Dislike"; - readonly FLAG: "Flag"; - readonly FOLLOW: "Follow"; - readonly INVITE: "Invite"; - readonly JOIN: "Join"; - readonly LEAVE: "Leave"; - readonly LIKE: "Like"; - readonly LISTEN: "Listen"; - readonly MOVE: "Move"; - readonly OFFER: "Offer"; - readonly READ: "Read"; - readonly REJECT: "Reject"; - readonly REMOVE: "Remove"; - readonly TENTATIVE_ACCEPT: "TentativeAccept"; - readonly TENTATIVE_REJECT: "TentativeReject"; - readonly UNDO: "Undo"; - readonly UPDATE: "Update"; - readonly VIEW: "View"; + readonly ACCEPT: 'Accept'; + readonly ADD: 'Add'; + readonly ANNOUNCE: 'Announce'; + readonly BLOCK: 'Block'; + readonly IGNORE: 'Ignore'; + readonly CREATE: 'Create'; + readonly DELETE: 'Delete'; + readonly DISLIKE: 'Dislike'; + readonly FLAG: 'Flag'; + readonly FOLLOW: 'Follow'; + readonly INVITE: 'Invite'; + readonly JOIN: 'Join'; + readonly LEAVE: 'Leave'; + readonly LIKE: 'Like'; + readonly LISTEN: 'Listen'; + readonly MOVE: 'Move'; + readonly OFFER: 'Offer'; + readonly READ: 'Read'; + readonly REJECT: 'Reject'; + readonly REMOVE: 'Remove'; + readonly TENTATIVE_ACCEPT: 'TentativeAccept'; + readonly TENTATIVE_REJECT: 'TentativeReject'; + readonly UNDO: 'Undo'; + readonly UPDATE: 'Update'; + readonly VIEW: 'View'; }; export declare const IntransitiveActivityTypes: { - readonly ARRIVE: "Arrive"; - readonly TRAVEL: "Travel"; - readonly QUESTION: "Question"; + readonly ARRIVE: 'Arrive'; + readonly TRAVEL: 'Travel'; + readonly QUESTION: 'Question'; }; export declare const ActivityTypes: { - readonly ARRIVE: "Arrive"; - readonly TRAVEL: "Travel"; - readonly QUESTION: "Question"; - readonly ACCEPT: "Accept"; - readonly ADD: "Add"; - readonly ANNOUNCE: "Announce"; - readonly BLOCK: "Block"; - readonly IGNORE: "Ignore"; - readonly CREATE: "Create"; - readonly DELETE: "Delete"; - readonly DISLIKE: "Dislike"; - readonly FLAG: "Flag"; - readonly FOLLOW: "Follow"; - readonly INVITE: "Invite"; - readonly JOIN: "Join"; - readonly LEAVE: "Leave"; - readonly LIKE: "Like"; - readonly LISTEN: "Listen"; - readonly MOVE: "Move"; - readonly OFFER: "Offer"; - readonly READ: "Read"; - readonly REJECT: "Reject"; - readonly REMOVE: "Remove"; - readonly TENTATIVE_ACCEPT: "TentativeAccept"; - readonly TENTATIVE_REJECT: "TentativeReject"; - readonly UNDO: "Undo"; - readonly UPDATE: "Update"; - readonly VIEW: "View"; + readonly ARRIVE: 'Arrive'; + readonly TRAVEL: 'Travel'; + readonly QUESTION: 'Question'; + readonly ACCEPT: 'Accept'; + readonly ADD: 'Add'; + readonly ANNOUNCE: 'Announce'; + readonly BLOCK: 'Block'; + readonly IGNORE: 'Ignore'; + readonly CREATE: 'Create'; + readonly DELETE: 'Delete'; + readonly DISLIKE: 'Dislike'; + readonly FLAG: 'Flag'; + readonly FOLLOW: 'Follow'; + readonly INVITE: 'Invite'; + readonly JOIN: 'Join'; + readonly LEAVE: 'Leave'; + readonly LIKE: 'Like'; + readonly LISTEN: 'Listen'; + readonly MOVE: 'Move'; + readonly OFFER: 'Offer'; + readonly READ: 'Read'; + readonly REJECT: 'Reject'; + readonly REMOVE: 'Remove'; + readonly TENTATIVE_ACCEPT: 'TentativeAccept'; + readonly TENTATIVE_REJECT: 'TentativeReject'; + readonly UNDO: 'Undo'; + readonly UPDATE: 'Update'; + readonly VIEW: 'View'; }; export declare const CollectionTypes: { - readonly COLLECTION: "Collection"; - readonly ORDERED_COLLECTION: "OrderedCollection"; + readonly COLLECTION: 'Collection'; + readonly ORDERED_COLLECTION: 'OrderedCollection'; }; export declare const CollectionPageTypes: { - readonly COLLECTION_PAGE: "CollectionPage"; - readonly ORDERED_COLLECTION_PAGE: "OrderedCollectionPage"; + readonly COLLECTION_PAGE: 'CollectionPage'; + readonly ORDERED_COLLECTION_PAGE: 'OrderedCollectionPage'; }; export declare const CoreObjectTypes: { - readonly COLLECTION_PAGE: "CollectionPage"; - readonly ORDERED_COLLECTION_PAGE: "OrderedCollectionPage"; - readonly COLLECTION: "Collection"; - readonly ORDERED_COLLECTION: "OrderedCollection"; - readonly ARRIVE: "Arrive"; - readonly TRAVEL: "Travel"; - readonly QUESTION: "Question"; - readonly ACCEPT: "Accept"; - readonly ADD: "Add"; - readonly ANNOUNCE: "Announce"; - readonly BLOCK: "Block"; - readonly IGNORE: "Ignore"; - readonly CREATE: "Create"; - readonly DELETE: "Delete"; - readonly DISLIKE: "Dislike"; - readonly FLAG: "Flag"; - readonly FOLLOW: "Follow"; - readonly INVITE: "Invite"; - readonly JOIN: "Join"; - readonly LEAVE: "Leave"; - readonly LIKE: "Like"; - readonly LISTEN: "Listen"; - readonly MOVE: "Move"; - readonly OFFER: "Offer"; - readonly READ: "Read"; - readonly REJECT: "Reject"; - readonly REMOVE: "Remove"; - readonly TENTATIVE_ACCEPT: "TentativeAccept"; - readonly TENTATIVE_REJECT: "TentativeReject"; - readonly UNDO: "Undo"; - readonly UPDATE: "Update"; - readonly VIEW: "View"; - readonly APPLICATION: "Application"; - readonly GROUP: "Group"; - readonly ORGANIZATION: "Organization"; - readonly PERSON: "Person"; - readonly SERVICE: "Service"; - readonly ARTICLE: "Article"; - readonly AUDIO: "Audio"; - readonly DOCUMENT: "Document"; - readonly EVENT: "Event"; - readonly IMAGE: "Image"; - readonly NOTE: "Note"; - readonly PAGE: "Page"; - readonly PLACE: "Place"; - readonly PROFILE: "Profile"; - readonly RELATIONSHIP: "Relationship"; - readonly TOMBSTONE: "Tombstone"; - readonly VIDEO: "Video"; + readonly COLLECTION_PAGE: 'CollectionPage'; + readonly ORDERED_COLLECTION_PAGE: 'OrderedCollectionPage'; + readonly COLLECTION: 'Collection'; + readonly ORDERED_COLLECTION: 'OrderedCollection'; + readonly ARRIVE: 'Arrive'; + readonly TRAVEL: 'Travel'; + readonly QUESTION: 'Question'; + readonly ACCEPT: 'Accept'; + readonly ADD: 'Add'; + readonly ANNOUNCE: 'Announce'; + readonly BLOCK: 'Block'; + readonly IGNORE: 'Ignore'; + readonly CREATE: 'Create'; + readonly DELETE: 'Delete'; + readonly DISLIKE: 'Dislike'; + readonly FLAG: 'Flag'; + readonly FOLLOW: 'Follow'; + readonly INVITE: 'Invite'; + readonly JOIN: 'Join'; + readonly LEAVE: 'Leave'; + readonly LIKE: 'Like'; + readonly LISTEN: 'Listen'; + readonly MOVE: 'Move'; + readonly OFFER: 'Offer'; + readonly READ: 'Read'; + readonly REJECT: 'Reject'; + readonly REMOVE: 'Remove'; + readonly TENTATIVE_ACCEPT: 'TentativeAccept'; + readonly TENTATIVE_REJECT: 'TentativeReject'; + readonly UNDO: 'Undo'; + readonly UPDATE: 'Update'; + readonly VIEW: 'View'; + readonly APPLICATION: 'Application'; + readonly GROUP: 'Group'; + readonly ORGANIZATION: 'Organization'; + readonly PERSON: 'Person'; + readonly SERVICE: 'Service'; + readonly ARTICLE: 'Article'; + readonly AUDIO: 'Audio'; + readonly DOCUMENT: 'Document'; + readonly EVENT: 'Event'; + readonly IMAGE: 'Image'; + readonly NOTE: 'Note'; + readonly PAGE: 'Page'; + readonly PLACE: 'Place'; + readonly PROFILE: 'Profile'; + readonly RELATIONSHIP: 'Relationship'; + readonly TOMBSTONE: 'Tombstone'; + readonly VIDEO: 'Video'; }; export declare const AllTypes: { - readonly LINK: "Link"; - readonly MENTION: "Mention"; - readonly COLLECTION_PAGE: "CollectionPage"; - readonly ORDERED_COLLECTION_PAGE: "OrderedCollectionPage"; - readonly COLLECTION: "Collection"; - readonly ORDERED_COLLECTION: "OrderedCollection"; - readonly ARRIVE: "Arrive"; - readonly TRAVEL: "Travel"; - readonly QUESTION: "Question"; - readonly ACCEPT: "Accept"; - readonly ADD: "Add"; - readonly ANNOUNCE: "Announce"; - readonly BLOCK: "Block"; - readonly IGNORE: "Ignore"; - readonly CREATE: "Create"; - readonly DELETE: "Delete"; - readonly DISLIKE: "Dislike"; - readonly FLAG: "Flag"; - readonly FOLLOW: "Follow"; - readonly INVITE: "Invite"; - readonly JOIN: "Join"; - readonly LEAVE: "Leave"; - readonly LIKE: "Like"; - readonly LISTEN: "Listen"; - readonly MOVE: "Move"; - readonly OFFER: "Offer"; - readonly READ: "Read"; - readonly REJECT: "Reject"; - readonly REMOVE: "Remove"; - readonly TENTATIVE_ACCEPT: "TentativeAccept"; - readonly TENTATIVE_REJECT: "TentativeReject"; - readonly UNDO: "Undo"; - readonly UPDATE: "Update"; - readonly VIEW: "View"; - readonly APPLICATION: "Application"; - readonly GROUP: "Group"; - readonly ORGANIZATION: "Organization"; - readonly PERSON: "Person"; - readonly SERVICE: "Service"; - readonly ARTICLE: "Article"; - readonly AUDIO: "Audio"; - readonly DOCUMENT: "Document"; - readonly EVENT: "Event"; - readonly IMAGE: "Image"; - readonly NOTE: "Note"; - readonly PAGE: "Page"; - readonly PLACE: "Place"; - readonly PROFILE: "Profile"; - readonly RELATIONSHIP: "Relationship"; - readonly TOMBSTONE: "Tombstone"; - readonly VIDEO: "Video"; + readonly LINK: 'Link'; + readonly MENTION: 'Mention'; + readonly COLLECTION_PAGE: 'CollectionPage'; + readonly ORDERED_COLLECTION_PAGE: 'OrderedCollectionPage'; + readonly COLLECTION: 'Collection'; + readonly ORDERED_COLLECTION: 'OrderedCollection'; + readonly ARRIVE: 'Arrive'; + readonly TRAVEL: 'Travel'; + readonly QUESTION: 'Question'; + readonly ACCEPT: 'Accept'; + readonly ADD: 'Add'; + readonly ANNOUNCE: 'Announce'; + readonly BLOCK: 'Block'; + readonly IGNORE: 'Ignore'; + readonly CREATE: 'Create'; + readonly DELETE: 'Delete'; + readonly DISLIKE: 'Dislike'; + readonly FLAG: 'Flag'; + readonly FOLLOW: 'Follow'; + readonly INVITE: 'Invite'; + readonly JOIN: 'Join'; + readonly LEAVE: 'Leave'; + readonly LIKE: 'Like'; + readonly LISTEN: 'Listen'; + readonly MOVE: 'Move'; + readonly OFFER: 'Offer'; + readonly READ: 'Read'; + readonly REJECT: 'Reject'; + readonly REMOVE: 'Remove'; + readonly TENTATIVE_ACCEPT: 'TentativeAccept'; + readonly TENTATIVE_REJECT: 'TentativeReject'; + readonly UNDO: 'Undo'; + readonly UPDATE: 'Update'; + readonly VIEW: 'View'; + readonly APPLICATION: 'Application'; + readonly GROUP: 'Group'; + readonly ORGANIZATION: 'Organization'; + readonly PERSON: 'Person'; + readonly SERVICE: 'Service'; + readonly ARTICLE: 'Article'; + readonly AUDIO: 'Audio'; + readonly DOCUMENT: 'Document'; + readonly EVENT: 'Event'; + readonly IMAGE: 'Image'; + readonly NOTE: 'Note'; + readonly PAGE: 'Page'; + readonly PLACE: 'Place'; + readonly PROFILE: 'Profile'; + readonly RELATIONSHIP: 'Relationship'; + readonly TOMBSTONE: 'Tombstone'; + readonly VIDEO: 'Video'; }; diff --git a/packages/activitypub-core-types/lib/activitypub/util/values.d.ts b/packages/activitypub-core-types/lib/activitypub/util/values.d.ts index d168bc37..1e33348b 100644 --- a/packages/activitypub-core-types/lib/activitypub/util/values.d.ts +++ b/packages/activitypub-core-types/lib/activitypub/util/values.d.ts @@ -1,3 +1,3 @@ export declare type StringReferenceMap = { - [key: string]: string; + [key: string]: string; }; diff --git a/packages/activitypub-core-types/lib/index.d.ts b/packages/activitypub-core-types/lib/index.d.ts index 24777ab6..cc0a1af1 100644 --- a/packages/activitypub-core-types/lib/index.d.ts +++ b/packages/activitypub-core-types/lib/index.d.ts @@ -1,24 +1,24 @@ export * as AP from './activitypub'; export declare type Database = { - expandCollection: Function; - expandEntity: Function; - fetchEntityById: Function; - findAll: Function; - findEntityById: Function; - findOne: Function; - findStringIdByValue: Function; - findStringValueById: Function; - getActorByToken: Function; - getAuthenticatedUserIdByToken: Function; - getCollectionItems: Function; - insertItem: Function; - removeItem: Function; - insertOrderedItem: Function; - removeOrderedItem: Function; - queryById: Function; - saveEntity: Function; - saveString: Function; + expandCollection: Function; + expandEntity: Function; + fetchEntityById: Function; + findAll: Function; + findEntityById: Function; + findOne: Function; + findStringIdByValue: Function; + findStringValueById: Function; + getActorByToken: Function; + getAuthenticatedUserIdByToken: Function; + getCollectionItems: Function; + insertItem: Function; + removeItem: Function; + insertOrderedItem: Function; + removeOrderedItem: Function; + queryById: Function; + saveEntity: Function; + saveString: Function; }; export interface DatabaseService { - connect(): Promise; + connect(): Promise; } diff --git a/packages/activitypub-core-types/package.json b/packages/activitypub-core-types/package.json index 14ca4420..2cb68df9 100644 --- a/packages/activitypub-core-types/package.json +++ b/packages/activitypub-core-types/package.json @@ -14,9 +14,11 @@ ], "scripts": { "tsc": "tsc --project tsconfig.json", - "dev": "ts-node ./src/index.ts" + "dev": "ts-node ./src/index.ts", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "devDependencies": { + "prettier": "^2.7.1", "ts-node": "^10.9.1" } } diff --git a/packages/activitypub-core-utilities/.prettierrc b/packages/activitypub-core-utilities/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core-utilities/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core-utilities/__tests__/compressEntity.ts b/packages/activitypub-core-utilities/__tests__/compressEntity.ts index d9bbb3d2..fb2cd9ad 100644 --- a/packages/activitypub-core-utilities/__tests__/compressEntity.ts +++ b/packages/activitypub-core-utilities/__tests__/compressEntity.ts @@ -6,7 +6,7 @@ describe('Utilities', () => { describe('compressEntity', () => { const actor1Url = `https://test.com/actor/123`; const actor1Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1Url), url: new URL(actor1Url), type: 'Person', @@ -17,7 +17,7 @@ describe('Utilities', () => { const object1Url = `https://test.com/actor/123`; const object1Result: AP.Note = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(object1Url), url: new URL(object1Url), type: 'Note', @@ -25,7 +25,7 @@ describe('Utilities', () => { }; const activity1Url = 'https://test.com/activity/456'; const activity1Result: AP.Create = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(activity1Url), url: new URL(activity1Url), type: 'Create', diff --git a/packages/activitypub-core-utilities/__tests__/convertStringsToUrls.ts b/packages/activitypub-core-utilities/__tests__/convertStringsToUrls.ts index 2c488af5..59ed852f 100644 --- a/packages/activitypub-core-utilities/__tests__/convertStringsToUrls.ts +++ b/packages/activitypub-core-utilities/__tests__/convertStringsToUrls.ts @@ -9,27 +9,21 @@ describe('utilities', () => { const item1Url = 'https://test.com/activity/456'; const item2Url = 'https://test.com/activity/789'; const collection1Result: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', totalItems: 1, - items: [ - new URL(item1Url), - new URL(item2Url), - ], + items: [new URL(item1Url), new URL(item2Url)], published: date, }; const collection1 = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: collection1Url, url: collection1Url, type: 'Collection', totalItems: 1, - items: [ - item1Url, - item2Url, - ], + items: [item1Url, item2Url], published: date.toISOString(), }; it('converts strings to URLS', async () => { diff --git a/packages/activitypub-core-utilities/__tests__/convertUrlsToStrings.ts b/packages/activitypub-core-utilities/__tests__/convertUrlsToStrings.ts index 13578b3a..7320101a 100644 --- a/packages/activitypub-core-utilities/__tests__/convertUrlsToStrings.ts +++ b/packages/activitypub-core-utilities/__tests__/convertUrlsToStrings.ts @@ -9,27 +9,21 @@ describe('utilities', () => { const item1Url = 'https://test.com/activity/456'; const item2Url = 'https://test.com/activity/789'; const collection1: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', totalItems: 1, - items: [ - new URL(item1Url), - new URL(item2Url), - ], + items: [new URL(item1Url), new URL(item2Url)], published: date, }; const collection1Result = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: collection1Url, url: collection1Url, type: 'Collection', totalItems: 1, - items: [ - item1Url, - item2Url, - ], + items: [item1Url, item2Url], published: date.toISOString(), }; it('converts', async () => { diff --git a/packages/activitypub-core-utilities/__tests__/getId.ts b/packages/activitypub-core-utilities/__tests__/getId.ts index 8d292f5d..407e627d 100644 --- a/packages/activitypub-core-utilities/__tests__/getId.ts +++ b/packages/activitypub-core-utilities/__tests__/getId.ts @@ -6,7 +6,7 @@ describe('utilities', () => { describe('getId', () => { const collection1Url = 'https://test.com/activity/123'; const collection1Result: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', diff --git a/packages/activitypub-core-utilities/lib/addContext.d.ts b/packages/activitypub-core-utilities/lib/addContext.d.ts index 0698d92e..3c6a723a 100644 --- a/packages/activitypub-core-utilities/lib/addContext.d.ts +++ b/packages/activitypub-core-utilities/lib/addContext.d.ts @@ -1,4 +1,4 @@ import { AP } from 'activitypub-core-types'; export declare function addContext(entity: AP.Entity): AP.Entity & { - '@context': unknown; + '@context': unknown; }; diff --git a/packages/activitypub-core-utilities/lib/convertFromJsonLd.d.ts b/packages/activitypub-core-utilities/lib/convertFromJsonLd.d.ts index 2c068fee..e168d11f 100644 --- a/packages/activitypub-core-utilities/lib/convertFromJsonLd.d.ts +++ b/packages/activitypub-core-utilities/lib/convertFromJsonLd.d.ts @@ -1,5 +1,5 @@ export declare const convertFromJsonLd: (entity: { - [key: string]: unknown; + [key: string]: unknown; }) => Promise<{ - [key: string]: unknown; + [key: string]: unknown; }>; diff --git a/packages/activitypub-core-utilities/lib/convertStringsToUrls.d.ts b/packages/activitypub-core-utilities/lib/convertStringsToUrls.d.ts index 494866e5..5f7b9830 100644 --- a/packages/activitypub-core-utilities/lib/convertStringsToUrls.d.ts +++ b/packages/activitypub-core-utilities/lib/convertStringsToUrls.d.ts @@ -1,4 +1,4 @@ import { AP } from 'activitypub-core-types'; export declare function convertStringsToUrls(originalEntity: { - [key: string]: unknown; + [key: string]: unknown; }): AP.Entity; diff --git a/packages/activitypub-core-utilities/lib/generateKeyPair.d.ts b/packages/activitypub-core-utilities/lib/generateKeyPair.d.ts index 86067b18..2e200387 100644 --- a/packages/activitypub-core-utilities/lib/generateKeyPair.d.ts +++ b/packages/activitypub-core-utilities/lib/generateKeyPair.d.ts @@ -1,4 +1,4 @@ export declare function generateKeyPair(): Promise<{ - privateKey: string; - publicKey: string; + privateKey: string; + publicKey: string; }>; diff --git a/packages/activitypub-core-utilities/lib/getId.d.ts b/packages/activitypub-core-utilities/lib/getId.d.ts index 4ee308b6..aa22bdba 100644 --- a/packages/activitypub-core-utilities/lib/getId.d.ts +++ b/packages/activitypub-core-utilities/lib/getId.d.ts @@ -1,3 +1,5 @@ /// import { AP } from 'activitypub-core-types'; -export declare const getId: (entity?: undefined | null | AP.EntityReference | AP.EntityReference[]) => URL | null; +export declare const getId: ( + entity?: undefined | null | AP.EntityReference | AP.EntityReference[], +) => URL | null; diff --git a/packages/activitypub-core-utilities/lib/getTypedEntity.d.ts b/packages/activitypub-core-utilities/lib/getTypedEntity.d.ts index 53194e00..2457622c 100644 --- a/packages/activitypub-core-utilities/lib/getTypedEntity.d.ts +++ b/packages/activitypub-core-utilities/lib/getTypedEntity.d.ts @@ -1,4 +1,47 @@ import { AP } from 'activitypub-core-types'; export declare const getTypedEntity: (entity: { - type: string; -}) => AP.Article | AP.Event | AP.Note | AP.Page | AP.Place | AP.Relationship | AP.Tombstone | AP.Profile | AP.Document | AP.Application | AP.Service | AP.Group | AP.Organization | AP.Person | AP.Accept | AP.Follow | AP.Delete | AP.Create | AP.Arrive | AP.Add | AP.Offer | AP.Like | AP.Leave | AP.Ignore | AP.Join | AP.Reject | AP.View | AP.Update | AP.Undo | AP.Remove | AP.Read | AP.Listen | AP.Move | AP.Travel | AP.Announce | AP.Flag | AP.Dislike | AP.Question | AP.Collection | AP.OrderedCollection | AP.CollectionPage | AP.OrderedCollectionPage | import("activitypub-core-types/lib/activitypub/Core/Link").BaseLink; + type: string; +}) => + | AP.Article + | AP.Event + | AP.Note + | AP.Page + | AP.Place + | AP.Relationship + | AP.Tombstone + | AP.Profile + | AP.Document + | AP.Application + | AP.Service + | AP.Group + | AP.Organization + | AP.Person + | AP.Accept + | AP.Follow + | AP.Delete + | AP.Create + | AP.Arrive + | AP.Add + | AP.Offer + | AP.Like + | AP.Leave + | AP.Ignore + | AP.Join + | AP.Reject + | AP.View + | AP.Update + | AP.Undo + | AP.Remove + | AP.Read + | AP.Listen + | AP.Move + | AP.Travel + | AP.Announce + | AP.Flag + | AP.Dislike + | AP.Question + | AP.Collection + | AP.OrderedCollection + | AP.CollectionPage + | AP.OrderedCollectionPage + | import('activitypub-core-types/lib/activitypub/Core/Link').BaseLink; diff --git a/packages/activitypub-core-utilities/lib/globals.d.ts b/packages/activitypub-core-utilities/lib/globals.d.ts index b9378d6e..d9207833 100644 --- a/packages/activitypub-core-utilities/lib/globals.d.ts +++ b/packages/activitypub-core-utilities/lib/globals.d.ts @@ -4,21 +4,24 @@ export declare const PROTOCOL: string; export declare const DB_NAME: string; export declare const LOCAL_DOMAIN: string; export declare const MONGO_CLIENT_URL: string; -export declare const CONTEXT = "@context"; -export declare const ACTIVITYSTREAMS_CONTEXT = "https://www.w3.org/ns/activitystreams#"; -export declare const W3ID_SECURITY_CONTEXT = "https://w3id.org/security/v1"; -export declare const RELATIONSHIP_CONTEXT = "http://purl.org/vocab/relationship/"; -export declare const CHANGESET_CONTEXT = "http://purl.org/vocab/changeset/schema#"; +export declare const CONTEXT = '@context'; +export declare const ACTIVITYSTREAMS_CONTEXT = + 'https://www.w3.org/ns/activitystreams#'; +export declare const W3ID_SECURITY_CONTEXT = 'https://w3id.org/security/v1'; +export declare const RELATIONSHIP_CONTEXT = + 'http://purl.org/vocab/relationship/'; +export declare const CHANGESET_CONTEXT = + 'http://purl.org/vocab/changeset/schema#'; export declare const PUBLIC_ACTOR: string; -export declare const LINKED_DATA_CONTENT_TYPE = "application/ld+json"; -export declare const SERVER_ACTOR_USERNAME = "bot"; +export declare const LINKED_DATA_CONTENT_TYPE = 'application/ld+json'; +export declare const SERVER_ACTOR_USERNAME = 'bot'; export declare const SERVER_ACTOR_ID: string; export declare const SHARED_INBOX_ID: string; -export declare const ACCEPT_HEADER = "Accept"; -export declare const CONTENT_TYPE_HEADER = "Content-Type"; +export declare const ACCEPT_HEADER = 'Accept'; +export declare const CONTENT_TYPE_HEADER = 'Content-Type'; export declare const ACTIVITYSTREAMS_CONTENT_TYPE_WITH_PROFILE: string; -export declare const ACTIVITYSTREAMS_CONTENT_TYPE = "application/activity+json"; -export declare const JSON_CONTENT_TYPE = "application/json"; -export declare const HTML_CONTENT_TYPE = "text/html"; +export declare const ACTIVITYSTREAMS_CONTENT_TYPE = 'application/activity+json'; +export declare const JSON_CONTENT_TYPE = 'application/json'; +export declare const HTML_CONTENT_TYPE = 'text/html'; export declare const USERNAME_REGEXP: RegExp; export declare const RESERVED_USERNAMES: string[]; diff --git a/packages/activitypub-core-utilities/lib/parseStream.d.ts b/packages/activitypub-core-utilities/lib/parseStream.d.ts index d48d1afa..065cff6a 100644 --- a/packages/activitypub-core-utilities/lib/parseStream.d.ts +++ b/packages/activitypub-core-utilities/lib/parseStream.d.ts @@ -1,4 +1,4 @@ /// -import { IncomingMessage } from "http"; -import { AP } from "activitypub-core-types"; +import { IncomingMessage } from 'http'; +import { AP } from 'activitypub-core-types'; export declare function parseStream(req: IncomingMessage): Promise; diff --git a/packages/activitypub-core-utilities/lib/streamToString.d.ts b/packages/activitypub-core-utilities/lib/streamToString.d.ts index 83c79325..f192698b 100644 --- a/packages/activitypub-core-utilities/lib/streamToString.d.ts +++ b/packages/activitypub-core-utilities/lib/streamToString.d.ts @@ -1,3 +1,5 @@ /// import { IncomingMessage } from 'http'; -export declare function streamToString(stream: IncomingMessage): Promise; +export declare function streamToString( + stream: IncomingMessage, +): Promise; diff --git a/packages/activitypub-core-utilities/package.json b/packages/activitypub-core-utilities/package.json index eda7292f..61d80c80 100644 --- a/packages/activitypub-core-utilities/package.json +++ b/packages/activitypub-core-utilities/package.json @@ -18,9 +18,10 @@ "url": "git+https://github.com/michaelcpuckett/activitypub-core.git" }, "scripts": { - "tsc": "tsc --project tsconfig.json", + "build": "tsc --project tsconfig.json", "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js", - "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch" + "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "bugs": { "url": "https://github.com/michaelcpuckett/activitypub-core/issues" @@ -35,6 +36,7 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } diff --git a/packages/activitypub-core-utilities/src/combineAddresses.ts b/packages/activitypub-core-utilities/src/combineAddresses.ts index b1f65f04..5c696710 100644 --- a/packages/activitypub-core-utilities/src/combineAddresses.ts +++ b/packages/activitypub-core-utilities/src/combineAddresses.ts @@ -13,48 +13,48 @@ export function combineAddresses(activity: AP.Activity): AP.Activity { const activityTo = Array.isArray(activity.to) ? activity.to : activity.to - ? [activity.to] - : []; + ? [activity.to] + : []; const activityCc = Array.isArray(activity.cc) ? activity.cc : activity.cc - ? [activity.cc] - : []; + ? [activity.cc] + : []; const activityBto = Array.isArray(activity.bto) ? activity.bto : activity.bto - ? [activity.bto] - : []; + ? [activity.bto] + : []; const activityBcc = Array.isArray(activity.bcc) ? activity.bcc : activity.bcc - ? [activity.bcc] - : []; + ? [activity.bcc] + : []; const activityAudience = Array.isArray(activity.audience) ? activity.audience : activity.audience - ? [activity.audience] - : []; + ? [activity.audience] + : []; const objectTo = Array.isArray(activity.object.to) ? activity.object.to : activity.object.to - ? [activity.object.to] - : []; + ? [activity.object.to] + : []; const objectCc = Array.isArray(activity.object.cc) ? activity.object.cc : activity.object.cc - ? [activity.object.cc] - : []; + ? [activity.object.cc] + : []; const objectBto = Array.isArray(activity.object.bto) ? activity.object.bto : activity.object.bto - ? [activity.object.bto] - : []; + ? [activity.object.bto] + : []; const objectBcc = Array.isArray(activity.object.bcc) ? activity.object.bcc : activity.object.bcc - ? [activity.object.bcc] - : []; + ? [activity.object.bcc] + : []; const objectAudience = Array.isArray(activity.object.audience) ? activity.object.audience ? activity.object.audience diff --git a/packages/activitypub-core-utilities/src/compressEntity.ts b/packages/activitypub-core-utilities/src/compressEntity.ts index 36e489d5..10164cfd 100644 --- a/packages/activitypub-core-utilities/src/compressEntity.ts +++ b/packages/activitypub-core-utilities/src/compressEntity.ts @@ -1,12 +1,14 @@ import { AP } from 'activitypub-core-types'; -export function compressEntity( - entity: AP.Entity, -): AP.Entity { +export function compressEntity(entity: AP.Entity): AP.Entity { const compressed: { [key: string]: unknown } = { ...entity }; for (const [key, value] of Object.entries(entity)) { - if (value instanceof URL || value instanceof Date || typeof value === 'string') { + if ( + value instanceof URL || + value instanceof Date || + typeof value === 'string' + ) { continue; } else if (Array.isArray(value)) { compressed[key] = compressArray(value); @@ -27,7 +29,11 @@ export function compressEntity( function compressArray(array: any[]) { return array.map((item) => { - if (item instanceof URL || item instanceof Date || typeof item === 'string') { + if ( + item instanceof URL || + item instanceof Date || + typeof item === 'string' + ) { return item; } else if (Array.isArray(item)) { return compressArray(item); @@ -41,4 +47,4 @@ function compressArray(array: any[]) { return item; } }); -} \ No newline at end of file +} diff --git a/packages/activitypub-core-utilities/src/convertStringsToUrls.ts b/packages/activitypub-core-utilities/src/convertStringsToUrls.ts index 26e41eac..8e322229 100644 --- a/packages/activitypub-core-utilities/src/convertStringsToUrls.ts +++ b/packages/activitypub-core-utilities/src/convertStringsToUrls.ts @@ -1,6 +1,8 @@ import { AP } from 'activitypub-core-types'; -export function convertStringsToUrls(originalEntity: { [key: string]: unknown }): AP.Entity { +export function convertStringsToUrls(originalEntity: { + [key: string]: unknown; +}): AP.Entity { const entity: { [key: string]: unknown } = { ...originalEntity }; for (const [key, value] of Object.entries(entity)) { @@ -25,7 +27,7 @@ export function convertStringsToUrls(originalEntity: { [key: string]: unknown }) } else if (value instanceof URL || value instanceof Date) { continue; } else if (Array.isArray(value)) { - entity[key] = value.map(item => { + entity[key] = value.map((item) => { if (typeof item === 'string') { try { return new URL(item); diff --git a/packages/activitypub-core-utilities/src/convertUrlsToStrings.ts b/packages/activitypub-core-utilities/src/convertUrlsToStrings.ts index e79b1b58..35cbbe6b 100644 --- a/packages/activitypub-core-utilities/src/convertUrlsToStrings.ts +++ b/packages/activitypub-core-utilities/src/convertUrlsToStrings.ts @@ -3,4 +3,4 @@ import { stringify } from 'superjson'; export const convertUrlsToStrings = (entity: AP.Entity): AP.Entity => { return JSON.parse(stringify(entity)).json; -} \ No newline at end of file +}; diff --git a/packages/activitypub-core-utilities/src/globals.ts b/packages/activitypub-core-utilities/src/globals.ts index 3dd5fd63..9a2cb2d6 100644 --- a/packages/activitypub-core-utilities/src/globals.ts +++ b/packages/activitypub-core-utilities/src/globals.ts @@ -2,8 +2,9 @@ export const PORT = Number(process.env.AP_PORT ?? 3000); export const LOCAL_HOSTNAME = process.env.AP_HOST_NAME ?? 'localhost'; export const PROTOCOL = process.env.AP_PROTOCOL ?? 'http:'; export const DB_NAME = process.env.AP_DB_NAME ?? 'activitypub'; -export const LOCAL_DOMAIN = `${PROTOCOL}//${LOCAL_HOSTNAME}${PORT === 80 ? '' : `:${PORT}` - }`; +export const LOCAL_DOMAIN = `${PROTOCOL}//${LOCAL_HOSTNAME}${ + PORT === 80 ? '' : `:${PORT}` +}`; export const MONGO_CLIENT_URL = process.env.AP_MONGO_CLIENT_URL ?? 'mongodb://localhost:27017'; export const CONTEXT = '@context'; diff --git a/packages/activitypub-core-utilities/src/parseStream.ts b/packages/activitypub-core-utilities/src/parseStream.ts index 4556434c..cf134645 100644 --- a/packages/activitypub-core-utilities/src/parseStream.ts +++ b/packages/activitypub-core-utilities/src/parseStream.ts @@ -1,8 +1,10 @@ -import { IncomingMessage } from "http"; -import { AP } from "activitypub-core-types"; -import { convertFromJsonLd } from "./convertFromJsonLd"; -import { streamToString } from "./streamToString"; +import { IncomingMessage } from 'http'; +import { AP } from 'activitypub-core-types'; +import { convertFromJsonLd } from './convertFromJsonLd'; +import { streamToString } from './streamToString'; export async function parseStream(req: IncomingMessage): Promise { - return await convertFromJsonLd(JSON.parse(await streamToString(req))) as AP.Entity; -} \ No newline at end of file + return (await convertFromJsonLd( + JSON.parse(await streamToString(req)), + )) as AP.Entity; +} diff --git a/packages/activitypub-core-utilities/src/stringifyWithContext.ts b/packages/activitypub-core-utilities/src/stringifyWithContext.ts index 69bd22c1..594e7d33 100644 --- a/packages/activitypub-core-utilities/src/stringifyWithContext.ts +++ b/packages/activitypub-core-utilities/src/stringifyWithContext.ts @@ -1,8 +1,8 @@ import { AP } from 'activitypub-core-types'; -import { addContext } from "./addContext"; -import { cleanProps } from "./cleanProps"; -import { convertUrlsToStrings } from "./convertUrlsToStrings"; +import { addContext } from './addContext'; +import { cleanProps } from './cleanProps'; +import { convertUrlsToStrings } from './convertUrlsToStrings'; export function stringifyWithContext(entity: AP.Entity) { return JSON.stringify(convertUrlsToStrings(addContext(cleanProps(entity)))); -} \ No newline at end of file +} diff --git a/packages/activitypub-core/.prettierrc b/packages/activitypub-core/.prettierrc new file mode 100644 index 00000000..e9c1315f --- /dev/null +++ b/packages/activitypub-core/.prettierrc @@ -0,0 +1,6 @@ +{ + "semi": true, + "trailingComma": "all", + "singleQuote": true, + "printWidth": 80 +} \ No newline at end of file diff --git a/packages/activitypub-core/__tests__/box.ts b/packages/activitypub-core/__tests__/box.ts index 2dbf9617..a1c44357 100644 --- a/packages/activitypub-core/__tests__/box.ts +++ b/packages/activitypub-core/__tests__/box.ts @@ -1,8 +1,10 @@ jest.mock('../../src/utilities/streamToString', () => { return { - streamToString: function streamToString(req: IncomingMessage & { - body: string; - }) { + streamToString: function streamToString( + req: IncomingMessage & { + body: string; + }, + ) { return req.body; }, }; @@ -319,9 +321,9 @@ const handleBox = async ( const deliveryService = new ExtendedDeliveryService(databaseService); - const setHeader = jest.fn(() => { }); - const write = jest.fn(() => { }); - const end = jest.fn(() => { }); + const setHeader = jest.fn(() => {}); + const write = jest.fn(() => {}); + const end = jest.fn(() => {}); const req: Partial = new IncomingMessage(new Socket()); @@ -333,7 +335,8 @@ const handleBox = async ( req.body = JSON.stringify(activity); const res: Partial = { - setHeader: setHeader as unknown as typeof ServerResponse.prototype.setHeader, + setHeader: + setHeader as unknown as typeof ServerResponse.prototype.setHeader, write: write as unknown as typeof ServerResponse.prototype.write, end: end as unknown as typeof ServerResponse.prototype.end, }; diff --git a/packages/activitypub-core/__tests__/data.ts b/packages/activitypub-core/__tests__/data.ts index c3ce6eda..c717882b 100644 --- a/packages/activitypub-core/__tests__/data.ts +++ b/packages/activitypub-core/__tests__/data.ts @@ -103,7 +103,7 @@ export const originalDeleteActivity: AP.Delete = { }; export const actor1Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1Url), url: new URL(actor1Url), type: 'Person', @@ -116,7 +116,7 @@ export const actor1Result: AP.Person = { }; export const actor1Inbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1InboxUrl), url: new URL(actor1InboxUrl), type: 'OrderedCollection', @@ -125,7 +125,7 @@ export const actor1Inbox: AP.OrderedCollection = { }; export const actor1Outbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1OutboxUrl), url: new URL(actor1OutboxUrl), type: 'OrderedCollection', @@ -134,7 +134,7 @@ export const actor1Outbox: AP.OrderedCollection = { }; export const actor1Following: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1FollowingUrl), url: new URL(actor1FollowingUrl), type: 'Collection', @@ -143,7 +143,7 @@ export const actor1Following: AP.Collection = { }; export const actor1Followers: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1FollowingUrl), url: new URL(actor1FollowingUrl), type: 'Collection', @@ -152,7 +152,7 @@ export const actor1Followers: AP.Collection = { }; export const actor2Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor2Url), url: new URL(actor2Url), type: 'Person', @@ -163,7 +163,7 @@ export const actor2Result: AP.Person = { }; export const actor2Inbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor2InboxUrl), url: new URL(actor2InboxUrl), type: 'OrderedCollection', @@ -172,7 +172,7 @@ export const actor2Inbox: AP.OrderedCollection = { }; export const actor2Outbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor2OutboxUrl), url: new URL(actor2OutboxUrl), type: 'OrderedCollection', @@ -181,7 +181,7 @@ export const actor2Outbox: AP.OrderedCollection = { }; export const actor2Following: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor2FollowingUrl), url: new URL(actor2FollowingUrl), type: 'Collection', @@ -190,7 +190,7 @@ export const actor2Following: AP.Collection = { }; export const actor2Followers: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor2FollowingUrl), url: new URL(actor2FollowingUrl), type: 'Collection', @@ -199,7 +199,7 @@ export const actor2Followers: AP.Collection = { }; export const actor3Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor3Url), url: new URL(actor3Url), type: 'Person', @@ -208,7 +208,7 @@ export const actor3Result: AP.Person = { }; export const actor5Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor5Url), url: new URL(actor5Url), type: 'Person', @@ -220,7 +220,7 @@ export const actor5Result: AP.Person = { }; export const actor3Inbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor3InboxUrl), url: new URL(actor3InboxUrl), type: 'OrderedCollection', @@ -229,7 +229,7 @@ export const actor3Inbox: AP.OrderedCollection = { }; export const actor3Outbox: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor3OutboxUrl), url: new URL(actor3OutboxUrl), type: 'OrderedCollection', @@ -238,7 +238,7 @@ export const actor3Outbox: AP.OrderedCollection = { }; export const actor4Result: AP.Person = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor4Url), url: new URL(actor4Url), type: 'Person', @@ -250,7 +250,7 @@ export const actor4Result: AP.Person = { }; export const actor1Shared: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1SharedUrl), url: new URL(actor1SharedUrl), name: 'Shared', @@ -260,7 +260,7 @@ export const actor1Shared: AP.OrderedCollection = { }; export const actor1Liked: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(actor1LikedUrl), url: new URL(actor1LikedUrl), name: 'Liked', @@ -270,7 +270,7 @@ export const actor1Liked: AP.OrderedCollection = { }; export const collection1: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', @@ -279,7 +279,7 @@ export const collection1: AP.Collection = { }; export const collection2: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(collection1Url), url: new URL(collection1Url), type: 'Collection', @@ -288,7 +288,7 @@ export const collection2: AP.Collection = { }; export const note1 = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(note1Url), url: new URL(note1Url), type: 'Note', @@ -296,7 +296,7 @@ export const note1 = { }; export const note2 = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(note2Url), url: new URL(note2Url), type: 'Note', @@ -307,7 +307,7 @@ export const note2 = { }; export const note2Likes = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(note2LikesUrl), url: new URL(note2LikesUrl), type: 'OrderedCollection', @@ -316,7 +316,7 @@ export const note2Likes = { }; export const note2Shares = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(note2SharesUrl), url: new URL(note2SharesUrl), type: 'OrderedCollection', diff --git a/packages/activitypub-core/__tests__/entity.ts b/packages/activitypub-core/__tests__/entity.ts index d41bfa95..7d12d68b 100644 --- a/packages/activitypub-core/__tests__/entity.ts +++ b/packages/activitypub-core/__tests__/entity.ts @@ -68,9 +68,9 @@ describe('Endpoints', () => { } as unknown as Db, }); - const setHeader = jest.fn(() => { }); - const write = jest.fn(() => { }); - const end = jest.fn(() => { }); + const setHeader = jest.fn(() => {}); + const write = jest.fn(() => {}); + const end = jest.fn(() => {}); it('works with accept application/json', async () => { const request: Partial = { @@ -84,7 +84,11 @@ describe('Endpoints', () => { write, end, }; - const data = await entityGetHandler(request as IncomingMessage, response as ServerResponse, databaseService); + const data = await entityGetHandler( + request as IncomingMessage, + response as ServerResponse, + databaseService, + ); expect(setHeader).toBeCalledWith( CONTENT_TYPE_HEADER, ACTIVITYSTREAMS_CONTENT_TYPE, @@ -112,7 +116,11 @@ describe('Endpoints', () => { write, end, }; - const data = await entityGetHandler(request as IncomingMessage, response as ServerResponse, databaseService); + const data = await entityGetHandler( + request as IncomingMessage, + response as ServerResponse, + databaseService, + ); expect(data.props).toStrictEqual({ entity: JSON.parse( JSON.stringify({ diff --git a/packages/activitypub-core/__tests__/home.ts b/packages/activitypub-core/__tests__/home.ts index 1cbf8084..17cba711 100644 --- a/packages/activitypub-core/__tests__/home.ts +++ b/packages/activitypub-core/__tests__/home.ts @@ -97,9 +97,9 @@ describe('Endpoints', () => { } as unknown as Db, }); - const setHeader = jest.fn(() => { }); - const write = jest.fn(() => { }); - const end = jest.fn(() => { }); + const setHeader = jest.fn(() => {}); + const write = jest.fn(() => {}); + const end = jest.fn(() => {}); it('works with text/html accept header', async () => { const request: Partial = { diff --git a/packages/activitypub-core/__tests__/mockDatabaseService.ts b/packages/activitypub-core/__tests__/mockDatabaseService.ts index f4df0784..29d8cf5b 100644 --- a/packages/activitypub-core/__tests__/mockDatabaseService.ts +++ b/packages/activitypub-core/__tests__/mockDatabaseService.ts @@ -35,7 +35,7 @@ export function mockDatabaseService({ json: fetchResponder(url, config), })); - let ExtendedDatabaseService = class extends DatabaseService { }; + let ExtendedDatabaseService = class extends DatabaseService {}; if (getActorByToken) { const ExtendedDatabaseService2 = class extends ExtendedDatabaseService { diff --git a/packages/activitypub-core/__tests__/outbox/get_html.ts b/packages/activitypub-core/__tests__/outbox/get_html.ts index 676ab7f9..7662e266 100644 --- a/packages/activitypub-core/__tests__/outbox/get_html.ts +++ b/packages/activitypub-core/__tests__/outbox/get_html.ts @@ -61,9 +61,9 @@ describe('Endpoints', () => { } as unknown as Db, }); - const setHeader = jest.fn(() => { }); - const write = jest.fn(() => { }); - const end = jest.fn(() => { }); + const setHeader = jest.fn(() => {}); + const write = jest.fn(() => {}); + const end = jest.fn(() => {}); const req: IncomingMessage = { url: data.actor1OutboxUrl.toString().split('https://test.com')[1], diff --git a/packages/activitypub-core/__tests__/outbox/get_json.ts b/packages/activitypub-core/__tests__/outbox/get_json.ts index 8ddf207e..1bd2ed7a 100644 --- a/packages/activitypub-core/__tests__/outbox/get_json.ts +++ b/packages/activitypub-core/__tests__/outbox/get_json.ts @@ -66,9 +66,9 @@ describe('Endpoints', () => { } as unknown as Db, }); - const setHeader = jest.fn(() => { }); - const write = jest.fn(() => { }); - const end = jest.fn(() => { }); + const setHeader = jest.fn(() => {}); + const write = jest.fn(() => {}); + const end = jest.fn(() => {}); const req: IncomingMessage = { url: data.actor1OutboxUrl.toString().split('https://test.com')[1], diff --git a/packages/activitypub-core/lib/entity/index.d.ts b/packages/activitypub-core/lib/entity/index.d.ts index bf5caf25..4b706bd4 100644 --- a/packages/activitypub-core/lib/entity/index.d.ts +++ b/packages/activitypub-core/lib/entity/index.d.ts @@ -3,9 +3,14 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; import type { IncomingMessage, ServerResponse } from 'http'; import { ServiceAccount } from 'firebase-admin'; -export declare function entityGetHandler(request: IncomingMessage, response: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database): Promise<{ - props?: { - entity?: AP.Entity; - actor?: AP.Actor; - }; +export declare function entityGetHandler( + request: IncomingMessage, + response: ServerResponse, + serviceAccount: ServiceAccount, + databaseService: Database, +): Promise<{ + props?: { + entity?: AP.Entity; + actor?: AP.Actor; + }; }>; diff --git a/packages/activitypub-core/lib/entity/index.js b/packages/activitypub-core/lib/entity/index.js index f73b5c87..c0b5625e 100644 --- a/packages/activitypub-core/lib/entity/index.js +++ b/packages/activitypub-core/lib/entity/index.js @@ -33,9 +33,8 @@ async function entityGetHandler(request, response, serviceAccount, databaseServi if (!request) { return handleBadRequest(); } - const cookies = cookie_1.default.parse(request.headers.cookie); + const cookies = cookie_1.default.parse(request.headers.cookie ?? ''); const actor = await databaseService.getActorByToken(cookies.__session ?? '', serviceAccount); - console.log('actor', actor); const url = new URL(`${activitypub_core_utilities_1.LOCAL_DOMAIN}${request.url}`); const foundEntity = await databaseService.findEntityById(url); if (!foundEntity) { diff --git a/packages/activitypub-core/lib/entity/index.js.map b/packages/activitypub-core/lib/entity/index.js.map index ef3cf7a8..4e86609a 100644 --- a/packages/activitypub-core/lib/entity/index.js.map +++ b/packages/activitypub-core/lib/entity/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;;;;AAAA,mEAA4C;AAC5C,2EAMoC;AACpC,2EAA4D;AAC5D,2EAAkE;AAClE,2EAAkE;AAClE,oDAA4B;AAKrB,KAAK,UAAU,gBAAgB,CACpC,OAAwB,EACxB,QAAwB,EACxB,cAA8B,EAC9B,eAAyB;IAEzB,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KACjC;IAED,MAAM,gBAAgB,GAAG,GAAG,EAAE;QAC5B,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,GAAG,EAAE;QAC1B,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5B,QAAQ,CAAC,GAAG,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,gBAAgB,EAAE,CAAC;KAC3B;IAED,MAAM,OAAO,GAAG,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,eAAe,CACjD,OAAO,CAAC,SAAS,IAAI,EAAE,EACvB,cAAc,CACf,CAAC;IAEF,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B,GAAG,MAAM,eAAe,CAAC,cAAc,CAChE,MAAM,CAAC,MAAM,CACd,CAAC;QAEF,IACE,qBAAqB;YACrB,qBAAqB,CAAC,IAAI,KAAK,2BAAE,CAAC,eAAe,CAAC,kBAAkB,EACpE;YACA,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,gBAAgB,CAC3D,qBAAqB,CACtB,CAAC;YAEF,IACE,cAAc;gBACd,cAAc,CAAC,IAAI,KAAK,2BAAE,CAAC,eAAe,CAAC,kBAAkB,EAC7D;gBACA,MAAM,CAAC,MAAM,GAAG,cAAc,CAAC;aAChC;SACF;KACF;IAED,IACE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,yDAA4B,CAAC;QAC9D,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,qDAAwB,CAAC;QAC1D,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,8CAAiB,CAAC,EACnD;QACA,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,cAAc,EAAE,CAAC;SACzB;QAED,QAAQ,CAAC,SAAS,CAAC,gDAAmB,EAAE,yDAA4B,CAAC,CAAC;QACtE,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;QAC1B,QAAQ,CAAC,KAAK,CAAC,IAAA,iDAAoB,EAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,QAAQ,CAAC,GAAG,EAAE,CAAC;QAEf,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;KACH;IAED,OAAO;QACL,KAAK,EAAE;YACL,MAAM,EAAE,IAAA,iDAAoB,EAAC,MAAM,CAAC;YACpC,KAAK,EAAE,IAAA,iDAAoB,EAAC,KAAK,CAAa;SAC/C;KACF,CAAC;AACJ,CAAC;AA5ID,4CA4IC"} \ No newline at end of file diff --git a/packages/activitypub-core/lib/home/index.d.ts b/packages/activitypub-core/lib/home/index.d.ts index b53f4a9d..35d3f85a 100644 --- a/packages/activitypub-core/lib/home/index.d.ts +++ b/packages/activitypub-core/lib/home/index.d.ts @@ -3,20 +3,29 @@ import { AP } from 'activitypub-core-types'; import { ServiceAccount } from 'firebase-admin'; import type { ServerResponse } from 'http'; import type { Database } from 'activitypub-core-types'; -export declare const homeGetHandler: (req: IncomingMessage, res: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, setup?: (data: { - props?: { +export declare const homeGetHandler: ( + req: IncomingMessage, + res: ServerResponse, + serviceAccount: ServiceAccount, + databaseService: Database, + setup?: ( + data: { + props?: { actor?: AP.Actor; - }; -}, databaseService: Database) => Promise<{ + }; + }, + databaseService: Database, + ) => Promise<{ props?: { - actor?: AP.Actor; - }; -}>) => Promise<{ - redirect?: { - permanent: Boolean; - destination: string; - }; - props?: { - actor?: AP.Actor; + actor?: AP.Actor; }; + }>, +) => Promise<{ + redirect?: { + permanent: Boolean; + destination: string; + }; + props?: { + actor?: AP.Actor; + }; }>; diff --git a/packages/activitypub-core/lib/home/index.js b/packages/activitypub-core/lib/home/index.js index c851325b..4b71db8c 100644 --- a/packages/activitypub-core/lib/home/index.js +++ b/packages/activitypub-core/lib/home/index.js @@ -8,7 +8,7 @@ const activitypub_core_types_1 = require("activitypub-core-types"); const activitypub_core_utilities_1 = require("activitypub-core-utilities"); const cookie_1 = __importDefault(require("cookie")); const homeGetHandler = async (req, res, serviceAccount, databaseService, setup) => { - const cookies = cookie_1.default.parse(req.headers.cookie); + const cookies = cookie_1.default.parse(req.headers.cookie ?? ''); const actor = await databaseService.getActorByToken(cookies.__session ?? '', serviceAccount); if (!actor) { return { diff --git a/packages/activitypub-core/lib/home/index.js.map b/packages/activitypub-core/lib/home/index.js.map index ff05ad1e..e58dec28 100644 --- a/packages/activitypub-core/lib/home/index.js.map +++ b/packages/activitypub-core/lib/home/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/home/index.ts"],"names":[],"mappings":";;;;;;AACA,mEAA4C;AAE5C,2EAAkE;AAClE,oDAA4B;AA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;SAC1D;KACF,CAAC;AACJ,CAAC,CAAC;AA5GW,QAAA,cAAc,kBA4GzB"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/home/index.ts"],"names":[],"mappings":";;;;;;AACA,mEAA4C;AAE5C,2EAAkE;AAClE,oDAA4B;AAIrB,MAAM,cAAc,GAAG,KAAK,EACjC,GAAoB,EACpB,GAAmB,EACnB,cAA8B,EAC9B,eAAyB,EACzB,KAG8C,EACsD,EAAE;IACtG,MAAM,OAAO,GAAG,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,eAAe,CACjD,OAAO,CAAC,SAAS,IAAI,EAAE,EACvB,cAAc,CACf,CAAC;IAEF,IAAI,CAAC,KAAK,EAAE;QACV,OAAO;YACL,QAAQ,EAAE;gBACR,SAAS,EAAE,KAAK;gBAChB,WAAW,EAAE,GAAG;aACjB;SACF,CAAC;KACH;IAED,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/B;IAED,MAAM,CACJ,KAAK,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACV,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpB,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC;QAC7C,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC;QAC9C,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QAC7E,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,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,CAAC;IAEF,IAAI,KAAK,EAAE;QACT,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;KAC3C;IAED,OAAO;QACL,KAAK,EAAE;YACL,KAAK,EAAE,IAAA,iDAAoB,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAa;SAC1D;KACF,CAAC;AACJ,CAAC,CAAC;AA5GW,QAAA,cAAc,kBA4GzB"} \ No newline at end of file diff --git a/packages/activitypub-core/lib/inbox/accept.d.ts b/packages/activitypub-core/lib/inbox/accept.d.ts index a072799e..cd2166c3 100644 --- a/packages/activitypub-core/lib/inbox/accept.d.ts +++ b/packages/activitypub-core/lib/inbox/accept.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleAccept(activity: AP.Accept, databaseService: Database): Promise; +export declare function handleAccept( + activity: AP.Accept, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/inbox/announce.d.ts b/packages/activitypub-core/lib/inbox/announce.d.ts index 6399016b..27b913dc 100644 --- a/packages/activitypub-core/lib/inbox/announce.d.ts +++ b/packages/activitypub-core/lib/inbox/announce.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleAnnounce(activity: AP.Announce, databaseService: Database): Promise; +export declare function handleAnnounce( + activity: AP.Announce, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/inbox/follow.d.ts b/packages/activitypub-core/lib/inbox/follow.d.ts index 1f118eeb..eb6dc090 100644 --- a/packages/activitypub-core/lib/inbox/follow.d.ts +++ b/packages/activitypub-core/lib/inbox/follow.d.ts @@ -1,4 +1,8 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; import { DeliveryService } from 'activitypub-core-delivery'; -export declare function handleFollow(activity: AP.Follow, databaseService: Database, deliveryService: DeliveryService): Promise; +export declare function handleFollow( + activity: AP.Follow, + databaseService: Database, + deliveryService: DeliveryService, +): Promise; diff --git a/packages/activitypub-core/lib/inbox/index.d.ts b/packages/activitypub-core/lib/inbox/index.d.ts index e064952c..3d8d6d18 100644 --- a/packages/activitypub-core/lib/inbox/index.d.ts +++ b/packages/activitypub-core/lib/inbox/index.d.ts @@ -4,11 +4,64 @@ import type { IncomingMessage, ServerResponse } from 'http'; import type { Database } from 'activitypub-core-types'; import { DeliveryService } from 'activitypub-core-delivery'; import { ServiceAccount } from 'firebase-admin'; -export declare function inboxHandler(req: IncomingMessage, res: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, deliveryService: DeliveryService): Promise<{ - props?: { - entity?: AP.OrderedCollection | import("activitypub-core-types/lib/activitypub/Core/Link").BaseLink | import("activitypub-core-types/lib/activitypub/Core").Mention | AP.Article | AP.Event | AP.Note | AP.Page | AP.Place | AP.Relationship | AP.Tombstone | AP.Profile | AP.Document | AP.Application | AP.Service | AP.Group | AP.Organization | AP.Person | AP.Accept | AP.Follow | AP.Delete | AP.Create | AP.Arrive | AP.Add | AP.Offer | AP.Like | AP.Leave | AP.Ignore | AP.Join | AP.Reject | AP.View | AP.Update | AP.Undo | AP.Remove | AP.Read | AP.Listen | AP.Move | AP.Travel | AP.Announce | AP.Flag | AP.Dislike | AP.Question | AP.Collection | AP.CollectionPage | AP.OrderedCollectionPage; +export declare function inboxHandler( + req: IncomingMessage, + res: ServerResponse, + serviceAccount: ServiceAccount, + databaseService: Database, + deliveryService: DeliveryService, +): Promise< + | { + props?: { + entity?: + | AP.OrderedCollection + | import('activitypub-core-types/lib/activitypub/Core/Link').BaseLink + | import('activitypub-core-types/lib/activitypub/Core').Mention + | AP.Article + | AP.Event + | AP.Note + | AP.Page + | AP.Place + | AP.Relationship + | AP.Tombstone + | AP.Profile + | AP.Document + | AP.Application + | AP.Service + | AP.Group + | AP.Organization + | AP.Person + | AP.Accept + | AP.Follow + | AP.Delete + | AP.Create + | AP.Arrive + | AP.Add + | AP.Offer + | AP.Like + | AP.Leave + | AP.Ignore + | AP.Join + | AP.Reject + | AP.View + | AP.Update + | AP.Undo + | AP.Remove + | AP.Read + | AP.Listen + | AP.Move + | AP.Travel + | AP.Announce + | AP.Flag + | AP.Dislike + | AP.Question + | AP.Collection + | AP.CollectionPage + | AP.OrderedCollectionPage; actor?: AP.Actor; - }; -} | { - props: {}; -}>; + }; + } + | { + props: {}; + } +>; diff --git a/packages/activitypub-core/lib/inbox/like.d.ts b/packages/activitypub-core/lib/inbox/like.d.ts index 8935b0d5..1246cca2 100644 --- a/packages/activitypub-core/lib/inbox/like.d.ts +++ b/packages/activitypub-core/lib/inbox/like.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleLike(activity: AP.Like, databaseService: Database): Promise; +export declare function handleLike( + activity: AP.Like, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/inbox/shouldForwardActivity.d.ts b/packages/activitypub-core/lib/inbox/shouldForwardActivity.d.ts index 1f658325..3ba0303a 100644 --- a/packages/activitypub-core/lib/inbox/shouldForwardActivity.d.ts +++ b/packages/activitypub-core/lib/inbox/shouldForwardActivity.d.ts @@ -1,3 +1,7 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function shouldForwardActivity(activity: AP.Activity, recipient: AP.Actor, databaseService: Database): Promise; +export declare function shouldForwardActivity( + activity: AP.Activity, + recipient: AP.Actor, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/index.d.ts b/packages/activitypub-core/lib/index.d.ts index 45b9a55a..b187d856 100644 --- a/packages/activitypub-core/lib/index.d.ts +++ b/packages/activitypub-core/lib/index.d.ts @@ -3,3 +3,4 @@ export { homeGetHandler } from './home'; export { entityGetHandler } from './entity'; export { outboxHandler } from './outbox'; export { inboxHandler } from './inbox'; +export { sharedInboxHandler } from './sharedInbox'; diff --git a/packages/activitypub-core/lib/index.js b/packages/activitypub-core/lib/index.js index 7841f057..de7bc24c 100644 --- a/packages/activitypub-core/lib/index.js +++ b/packages/activitypub-core/lib/index.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.inboxHandler = exports.outboxHandler = exports.entityGetHandler = exports.homeGetHandler = exports.userPostHandler = void 0; +exports.sharedInboxHandler = exports.inboxHandler = exports.outboxHandler = exports.entityGetHandler = exports.homeGetHandler = exports.userPostHandler = void 0; var user_1 = require("./user"); Object.defineProperty(exports, "userPostHandler", { enumerable: true, get: function () { return user_1.userPostHandler; } }); var home_1 = require("./home"); @@ -11,4 +11,6 @@ var outbox_1 = require("./outbox"); Object.defineProperty(exports, "outboxHandler", { enumerable: true, get: function () { return outbox_1.outboxHandler; } }); var inbox_1 = require("./inbox"); Object.defineProperty(exports, "inboxHandler", { enumerable: true, get: function () { return inbox_1.inboxHandler; } }); +var sharedInbox_1 = require("./sharedInbox"); +Object.defineProperty(exports, "sharedInboxHandler", { enumerable: true, get: function () { return sharedInbox_1.sharedInboxHandler; } }); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/activitypub-core/lib/index.js.map b/packages/activitypub-core/lib/index.js.map index 32574578..3a0a76c2 100644 --- a/packages/activitypub-core/lib/index.js.map +++ b/packages/activitypub-core/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAyC;AAAhC,uGAAA,eAAe,OAAA;AACxB,+BAAwC;AAA/B,sGAAA,cAAc,OAAA;AACvB,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA;AACzB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AACtB,iCAAuC;AAA9B,qGAAA,YAAY,OAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAyC;AAAhC,uGAAA,eAAe,OAAA;AACxB,+BAAwC;AAA/B,sGAAA,cAAc,OAAA;AACvB,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA;AACzB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AACtB,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,6CAAmD;AAA1C,iHAAA,kBAAkB,OAAA"} \ No newline at end of file diff --git a/packages/activitypub-core/lib/outbox/add.d.ts b/packages/activitypub-core/lib/outbox/add.d.ts index 8ca14330..f532ccb7 100644 --- a/packages/activitypub-core/lib/outbox/add.d.ts +++ b/packages/activitypub-core/lib/outbox/add.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleAdd(activity: AP.Add | AP.Remove, databaseService: Database): Promise; +export declare function handleAdd( + activity: AP.Add | AP.Remove, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/announce.d.ts b/packages/activitypub-core/lib/outbox/announce.d.ts index 6399016b..27b913dc 100644 --- a/packages/activitypub-core/lib/outbox/announce.d.ts +++ b/packages/activitypub-core/lib/outbox/announce.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleAnnounce(activity: AP.Announce, databaseService: Database): Promise; +export declare function handleAnnounce( + activity: AP.Announce, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/create.d.ts b/packages/activitypub-core/lib/outbox/create.d.ts index fc59a261..03111324 100644 --- a/packages/activitypub-core/lib/outbox/create.d.ts +++ b/packages/activitypub-core/lib/outbox/create.d.ts @@ -1,4 +1,7 @@ /// import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleCreate(activity: AP.Create | AP.Delete, databaseService: Database): Promise; +export declare function handleCreate( + activity: AP.Create | AP.Delete, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/delete.d.ts b/packages/activitypub-core/lib/outbox/delete.d.ts index 28b8db77..453b9584 100644 --- a/packages/activitypub-core/lib/outbox/delete.d.ts +++ b/packages/activitypub-core/lib/outbox/delete.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleDelete(activity: AP.Delete | AP.Create, databaseService: Database): Promise; +export declare function handleDelete( + activity: AP.Delete | AP.Create, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/index.d.ts b/packages/activitypub-core/lib/outbox/index.d.ts index 82ec9a42..d46520e4 100644 --- a/packages/activitypub-core/lib/outbox/index.d.ts +++ b/packages/activitypub-core/lib/outbox/index.d.ts @@ -4,11 +4,64 @@ import type { Database } from 'activitypub-core-types'; import type { IncomingMessage, ServerResponse } from 'http'; import { DeliveryService } from 'activitypub-core-delivery'; import { ServiceAccount } from 'firebase-admin'; -export declare function outboxHandler(req: IncomingMessage, res: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, deliveryService: DeliveryService): Promise<{ - props?: { - entity?: AP.OrderedCollection | import("activitypub-core-types/lib/activitypub/Core/Link").BaseLink | import("activitypub-core-types/lib/activitypub/Core").Mention | AP.Article | AP.Event | AP.Note | AP.Page | AP.Place | AP.Relationship | AP.Tombstone | AP.Profile | AP.Document | AP.Application | AP.Service | AP.Group | AP.Organization | AP.Person | AP.Accept | AP.Follow | AP.Delete | AP.Create | AP.Arrive | AP.Add | AP.Offer | AP.Like | AP.Leave | AP.Ignore | AP.Join | AP.Reject | AP.View | AP.Update | AP.Undo | AP.Remove | AP.Read | AP.Listen | AP.Move | AP.Travel | AP.Announce | AP.Flag | AP.Dislike | AP.Question | AP.Collection | AP.CollectionPage | AP.OrderedCollectionPage; +export declare function outboxHandler( + req: IncomingMessage, + res: ServerResponse, + serviceAccount: ServiceAccount, + databaseService: Database, + deliveryService: DeliveryService, +): Promise< + | { + props?: { + entity?: + | AP.OrderedCollection + | import('activitypub-core-types/lib/activitypub/Core/Link').BaseLink + | import('activitypub-core-types/lib/activitypub/Core').Mention + | AP.Article + | AP.Event + | AP.Note + | AP.Page + | AP.Place + | AP.Relationship + | AP.Tombstone + | AP.Profile + | AP.Document + | AP.Application + | AP.Service + | AP.Group + | AP.Organization + | AP.Person + | AP.Accept + | AP.Follow + | AP.Delete + | AP.Create + | AP.Arrive + | AP.Add + | AP.Offer + | AP.Like + | AP.Leave + | AP.Ignore + | AP.Join + | AP.Reject + | AP.View + | AP.Update + | AP.Undo + | AP.Remove + | AP.Read + | AP.Listen + | AP.Move + | AP.Travel + | AP.Announce + | AP.Flag + | AP.Dislike + | AP.Question + | AP.Collection + | AP.CollectionPage + | AP.OrderedCollectionPage; actor?: AP.Actor; - }; -} | { - props: {}; -}>; + }; + } + | { + props: {}; + } +>; diff --git a/packages/activitypub-core/lib/outbox/like.d.ts b/packages/activitypub-core/lib/outbox/like.d.ts index 8935b0d5..1246cca2 100644 --- a/packages/activitypub-core/lib/outbox/like.d.ts +++ b/packages/activitypub-core/lib/outbox/like.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleLike(activity: AP.Like, databaseService: Database): Promise; +export declare function handleLike( + activity: AP.Like, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/remove.d.ts b/packages/activitypub-core/lib/outbox/remove.d.ts index ba516177..aca54b74 100644 --- a/packages/activitypub-core/lib/outbox/remove.d.ts +++ b/packages/activitypub-core/lib/outbox/remove.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleRemove(activity: AP.Remove | AP.Add, databaseService: Database): Promise; +export declare function handleRemove( + activity: AP.Remove | AP.Add, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/undo/index.d.ts b/packages/activitypub-core/lib/outbox/undo/index.d.ts index 941bfa2b..b2ca4a41 100644 --- a/packages/activitypub-core/lib/outbox/undo/index.d.ts +++ b/packages/activitypub-core/lib/outbox/undo/index.d.ts @@ -1,3 +1,7 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleUndo(activity: AP.Undo, databaseService: Database, initiator: AP.Actor): Promise; +export declare function handleUndo( + activity: AP.Undo, + databaseService: Database, + initiator: AP.Actor, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/undo/undoAnnounce.d.ts b/packages/activitypub-core/lib/outbox/undo/undoAnnounce.d.ts index 577a592e..b022426c 100644 --- a/packages/activitypub-core/lib/outbox/undo/undoAnnounce.d.ts +++ b/packages/activitypub-core/lib/outbox/undo/undoAnnounce.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleUndoAnnounce(activity: AP.Announce, databaseService: Database): Promise; +export declare function handleUndoAnnounce( + activity: AP.Announce, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/undo/undoLike.d.ts b/packages/activitypub-core/lib/outbox/undo/undoLike.d.ts index 833f1db4..092a5933 100644 --- a/packages/activitypub-core/lib/outbox/undo/undoLike.d.ts +++ b/packages/activitypub-core/lib/outbox/undo/undoLike.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleUndoLike(activity: AP.Like, databaseService: Database): Promise; +export declare function handleUndoLike( + activity: AP.Like, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/outbox/update.d.ts b/packages/activitypub-core/lib/outbox/update.d.ts index 7e163912..8d73aa80 100644 --- a/packages/activitypub-core/lib/outbox/update.d.ts +++ b/packages/activitypub-core/lib/outbox/update.d.ts @@ -1,3 +1,6 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; -export declare function handleUpdate(activity: AP.Update, databaseService: Database): Promise; +export declare function handleUpdate( + activity: AP.Update, + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/sharedInbox/index.d.ts b/packages/activitypub-core/lib/sharedInbox/index.d.ts new file mode 100644 index 00000000..239eb25e --- /dev/null +++ b/packages/activitypub-core/lib/sharedInbox/index.d.ts @@ -0,0 +1,18 @@ +/// +/// +import type { IncomingMessage, ServerResponse } from 'http'; +import { AP } from 'activitypub-core-types'; +import type { Database } from 'activitypub-core-types'; +import { DeliveryService } from 'activitypub-core-delivery'; +export declare function sharedInboxHandler( + req: IncomingMessage, + res: ServerResponse, + databaseService: Database, + deliveryService: DeliveryService, +): Promise; +export declare function getRecipientInboxUrls( + activity: AP.Activity, + actor: AP.Actor, + databaseService: Database, + providedDeliveryService: DeliveryService, +): Promise; diff --git a/packages/activitypub-core/lib/sharedInbox/index.js b/packages/activitypub-core/lib/sharedInbox/index.js new file mode 100644 index 00000000..0b400971 --- /dev/null +++ b/packages/activitypub-core/lib/sharedInbox/index.js @@ -0,0 +1,119 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getRecipientInboxUrls = exports.sharedInboxHandler = void 0; +const activitypub_core_types_1 = require("activitypub-core-types"); +const accept_1 = require("../inbox/accept"); +const announce_1 = require("../inbox/announce"); +const follow_1 = require("../inbox/follow"); +const like_1 = require("../inbox/like"); +const activitypub_core_utilities_1 = require("activitypub-core-utilities"); +const activitypub_core_utilities_2 = require("activitypub-core-utilities"); +const activitypub_core_utilities_3 = require("activitypub-core-utilities"); +const activitypub_core_delivery_1 = require("activitypub-core-delivery"); +async function sharedInboxHandler(req, res, databaseService, deliveryService) { + if (!req || !res) { + throw new Error('No response object.'); + } + try { + const activity = await (0, activitypub_core_utilities_2.parseStream)(req); + if (!activity) { + throw new Error('Bad jsonld?'); + } + const activityId = activity.id; + if (!activityId) { + throw new Error('Activity does not have an ID?'); + } + if (!('actor' in activity)) { + throw new Error('Bad activity, no actor.'); + } + const actorId = (0, activitypub_core_utilities_1.getId)(activity.actor); + if (!actorId) { + throw new Error('Bad activity, no actor ID'); + } + const actor = await databaseService.queryById(actorId); + if (!actor) { + throw new Error('Bad activity, no actor'); + } + switch (activity.type) { + case activitypub_core_types_1.AP.ActivityTypes.LIKE: + await (0, like_1.handleLike)(activity, databaseService); + break; + case activitypub_core_types_1.AP.ActivityTypes.ANNOUNCE: + await (0, announce_1.handleAnnounce)(activity, databaseService); + break; + case activitypub_core_types_1.AP.ActivityTypes.ACCEPT: + await (0, accept_1.handleAccept)(activity, databaseService); + break; + case activitypub_core_types_1.AP.ActivityTypes.FOLLOW: + await (0, follow_1.handleFollow)(activity, databaseService, deliveryService); + break; + } + const recipientIds = await getRecipientInboxUrls(activity, actor, databaseService, deliveryService); + for (const recipientId of recipientIds) { + const recipient = (await databaseService.findEntityById(recipientId)); + if (!recipient) { + continue; + } + const recipientInboxId = (0, activitypub_core_utilities_1.getId)(recipient.inbox); + if (!recipientInboxId) { + continue; + } + await databaseService.insertOrderedItem(recipientInboxId, activityId); + } + await databaseService.saveEntity(activity); + res.statusCode = 200; + res.write((0, activitypub_core_utilities_3.stringifyWithContext)(activity)); + res.end(); + } + catch (error) { + console.log(error); + res.statusCode = 500; + res.write('Bad request'); + res.end(); + return; + } +} +exports.sharedInboxHandler = sharedInboxHandler; +async function getRecipientInboxUrls(activity, actor, databaseService, providedDeliveryService) { + const deliveryService = providedDeliveryService ?? new activitypub_core_delivery_1.DeliveryService(databaseService); + const recipients = [ + ...(activity.to + ? await deliveryService.getRecipientsList(activity.to) + : []), + ...(activity.cc + ? await deliveryService.getRecipientsList(activity.cc) + : []), + ...(activity.bto + ? await deliveryService.getRecipientsList(activity.bto) + : []), + ...(activity.bcc + ? await deliveryService.getRecipientsList(activity.bcc) + : []), + ...(activity.audience + ? await deliveryService.getRecipientsList(activity.audience) + : []), + ]; + const recipientInboxes = await Promise.all(recipients.map(async (recipient) => { + if (recipient.toString() === actor.id?.toString()) { + return null; + } + const foundThing = await databaseService.findEntityById(recipient); + if (!foundThing) { + return null; + } + if (typeof foundThing === 'object' && + 'inbox' in foundThing && + foundThing.inbox) { + return foundThing.id; + } + })); + const recipientIds = []; + for (const recipientInbox of recipientInboxes) { + if (recipientInbox instanceof URL) { + recipientIds.push(recipientInbox); + } + } + return [...new Set(recipientIds)]; +} +exports.getRecipientInboxUrls = getRecipientInboxUrls; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/activitypub-core/lib/sharedInbox/index.js.map b/packages/activitypub-core/lib/sharedInbox/index.js.map new file mode 100644 index 00000000..a7b4e968 --- /dev/null +++ b/packages/activitypub-core/lib/sharedInbox/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sharedInbox/index.ts"],"names":[],"mappings":";;;AACA,mEAA4C;AAC5C,4CAA+C;AAC/C,gDAAmD;AACnD,4CAA+C;AAC/C,wCAA2C;AAC3C,2EAAmD;AACnD,2EAAyD;AACzD,2EAAkE;AAElE,yEAA4D;AAErD,KAAK,UAAU,kBAAkB,CACtC,GAAoB,EACpB,GAAmB,EACnB,eAAyB,EACzB,eAAgC;IAEhC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,IAAA,wCAAW,EAAC,GAAG,CAAC,CAAC;QAExC,IAAI,CAAC,QAAQ,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;SAChC;QAED,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC;QAE/B,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,MAAM,OAAO,GAAG,IAAA,kCAAK,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;QAED,MAAM,KAAK,GAAG,MAAM,eAAe,C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,EAAE,CAAC;KACR,CAAC;IAEF,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,GAAG,CACxC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACjC,IAAI,SAAS,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE;YACjD,OAAO,IAAI,CAAC;SACb;QAED,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAEnE,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,IACE,OAAO,UAAU,KAAK,QAAQ;YAC9B,OAAO,IAAI,UAAU;YACrB,UAAU,CAAC,KAAK,EAChB;YACA,OAAO,UAAU,CAAC,EAAE,CAAC;SACtB;IACH,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,YAAY,GAAU,EAAE,CAAC;IAE/B,KAAK,MAAM,cAAc,IAAI,gBAAgB,EAAE;QAC7C,IAAI,cAAc,YAAY,GAAG,EAAE;YACjC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACnC;KACF;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;AACpC,CAAC;AA1DD,sDA0DC"} \ No newline at end of file diff --git a/packages/activitypub-core/lib/user/createServerActor.d.ts b/packages/activitypub-core/lib/user/createServerActor.d.ts index 0a1c39ad..5caa3cea 100644 --- a/packages/activitypub-core/lib/user/createServerActor.d.ts +++ b/packages/activitypub-core/lib/user/createServerActor.d.ts @@ -1,2 +1,4 @@ import type { Database } from 'activitypub-core-types'; -export declare function createServerActor(databaseService: Database): Promise; +export declare function createServerActor( + databaseService: Database, +): Promise; diff --git a/packages/activitypub-core/lib/user/createUserActor.d.ts b/packages/activitypub-core/lib/user/createUserActor.d.ts index e68623f2..6b05a976 100644 --- a/packages/activitypub-core/lib/user/createUserActor.d.ts +++ b/packages/activitypub-core/lib/user/createUserActor.d.ts @@ -1,7 +1,10 @@ import type { Database } from 'activitypub-core-types'; -export declare function createUserActor(databaseService: Database, user: { +export declare function createUserActor( + databaseService: Database, + user: { uid: string; email: string; name: string; preferredUsername: string; -}): Promise; + }, +): Promise; diff --git a/packages/activitypub-core/lib/user/index.d.ts b/packages/activitypub-core/lib/user/index.d.ts index d4a11a49..60168adc 100644 --- a/packages/activitypub-core/lib/user/index.d.ts +++ b/packages/activitypub-core/lib/user/index.d.ts @@ -3,6 +3,15 @@ import { ServiceAccount } from 'firebase-admin'; import { AP } from 'activitypub-core-types'; import type { IncomingMessage, ServerResponse } from 'http'; import type { Database } from 'activitypub-core-types'; -export declare function userPostHandler(req: IncomingMessage, res: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, setup?: (actor: AP.Entity, databaseService: Database) => Promise<{ +export declare function userPostHandler( + req: IncomingMessage, + res: ServerResponse, + serviceAccount: ServiceAccount, + databaseService: Database, + setup?: ( + actor: AP.Entity, + databaseService: Database, + ) => Promise<{ actor: AP.Actor; -}>): Promise; + }>, +): Promise; diff --git a/packages/activitypub-core/package.json b/packages/activitypub-core/package.json index 6487e56c..d83c318a 100644 --- a/packages/activitypub-core/package.json +++ b/packages/activitypub-core/package.json @@ -16,7 +16,8 @@ "scripts": { "tsc": "tsc --project tsconfig.json", "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js", - "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch" + "dev": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch", + "format": "prettier --config .prettierrc \"**/*.ts\" --write" }, "dependencies": { "activitypub-core-delivery": "^0.0.54", @@ -38,6 +39,7 @@ "@types/jsonld": "^1.5.6", "dotenv": "^16.0.3", "jest": "^29.1.2", + "prettier": "^2.7.1", "ts-jest": "^29.0.3", "typescript": "^4.8.4" } diff --git a/packages/activitypub-core/src/entity/index.ts b/packages/activitypub-core/src/entity/index.ts index b16a0deb..541fb30f 100644 --- a/packages/activitypub-core/src/entity/index.ts +++ b/packages/activitypub-core/src/entity/index.ts @@ -19,7 +19,7 @@ export async function entityGetHandler( response: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, -): Promise<{ props?: { entity?: AP.Entity; actor?: AP.Actor; } }> { +): Promise<{ props?: { entity?: AP.Entity; actor?: AP.Actor } }> { if (!response) { throw new Error('Bad request.'); } @@ -46,15 +46,13 @@ export async function entityGetHandler( return handleBadRequest(); } - const cookies = cookie.parse(request.headers.cookie); + const cookies = cookie.parse(request.headers.cookie ?? ''); const actor = await databaseService.getActorByToken( cookies.__session ?? '', serviceAccount, ); - console.log('actor', actor); - // TODO authorize foundEntity posts by actor. const url = new URL(`${LOCAL_DOMAIN}${request.url}`); diff --git a/packages/activitypub-core/src/home/index.ts b/packages/activitypub-core/src/home/index.ts index 247be503..6acd7cd9 100644 --- a/packages/activitypub-core/src/home/index.ts +++ b/packages/activitypub-core/src/home/index.ts @@ -15,8 +15,11 @@ export const homeGetHandler = async ( data: { props?: { actor?: AP.Actor } }, databaseService: Database, ) => Promise<{ props?: { actor?: AP.Actor } }>, -): Promise<{ redirect?: { permanent: Boolean; destination: string; }; props?: { actor?: AP.Actor } }> => { - const cookies = cookie.parse(req.headers.cookie); +): Promise<{ + redirect?: { permanent: Boolean; destination: string }; + props?: { actor?: AP.Actor }; +}> => { + const cookies = cookie.parse(req.headers.cookie ?? ''); const actor = await databaseService.getActorByToken( cookies.__session ?? '', @@ -36,16 +39,15 @@ export const homeGetHandler = async ( throw new Error('Bad actor.'); } - const [ - inbox, - outbox, - followers, - following, - ] = await Promise.all([ + const [inbox, outbox, followers, following] = await Promise.all([ databaseService.expandCollection(actor.inbox), databaseService.expandCollection(actor.outbox), - ...actor.followers ? [databaseService.expandCollection(actor.followers)] : [], - ...actor.following ? [databaseService.expandCollection(actor.following)] : [], + ...(actor.followers + ? [databaseService.expandCollection(actor.followers)] + : []), + ...(actor.following + ? [databaseService.expandCollection(actor.following)] + : []), ]); if (!inbox || !outbox) { @@ -97,12 +99,12 @@ export const homeGetHandler = async ( let data: { props?: { - actor?: AP.Actor - } + actor?: AP.Actor; + }; } = { props: { actor, - } + }, }; if (setup) { diff --git a/packages/activitypub-core/src/inbox/follow.ts b/packages/activitypub-core/src/inbox/follow.ts index 74040c2d..0ab6af83 100644 --- a/packages/activitypub-core/src/inbox/follow.ts +++ b/packages/activitypub-core/src/inbox/follow.ts @@ -68,7 +68,7 @@ export async function handleFollow( const publishedDate = new Date(); const acceptActivityReplies: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${acceptActivityId}/replies`), url: new URL(`${acceptActivityId}/replies`), name: 'Replies', @@ -79,7 +79,7 @@ export async function handleFollow( }; const acceptActivityLikes = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${acceptActivityId}/likes`), url: new URL(`${acceptActivityId}/likes`), name: 'Likes', @@ -90,7 +90,7 @@ export async function handleFollow( }; const acceptActivityShares = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${acceptActivityId}/shares`), url: new URL(`${acceptActivityId}/shares`), name: 'Likes', diff --git a/packages/activitypub-core/src/inbox/index.ts b/packages/activitypub-core/src/inbox/index.ts index 3ff8d7c5..88a629a0 100644 --- a/packages/activitypub-core/src/inbox/index.ts +++ b/packages/activitypub-core/src/inbox/index.ts @@ -1,5 +1,5 @@ import { AP } from 'activitypub-core-types'; -import { LOCAL_DOMAIN } from 'activitypub-core-utilities' +import { LOCAL_DOMAIN } from 'activitypub-core-utilities'; import type { IncomingMessage, ServerResponse } from 'http'; import { entityGetHandler } from '../entity'; import { handleAccept } from './accept'; diff --git a/packages/activitypub-core/src/index.ts b/packages/activitypub-core/src/index.ts index d973b2fa..b187d856 100644 --- a/packages/activitypub-core/src/index.ts +++ b/packages/activitypub-core/src/index.ts @@ -2,4 +2,5 @@ export { userPostHandler } from './user'; export { homeGetHandler } from './home'; export { entityGetHandler } from './entity'; export { outboxHandler } from './outbox'; -export { inboxHandler } from './inbox'; \ No newline at end of file +export { inboxHandler } from './inbox'; +export { sharedInboxHandler } from './sharedInbox'; diff --git a/packages/activitypub-core/src/outbox/create.ts b/packages/activitypub-core/src/outbox/create.ts index 76a02177..26be35b2 100644 --- a/packages/activitypub-core/src/outbox/create.ts +++ b/packages/activitypub-core/src/outbox/create.ts @@ -1,5 +1,8 @@ import { AP } from 'activitypub-core-types'; -import { ACTIVITYSTREAMS_CONTEXT, getTypedEntity } from 'activitypub-core-utilities'; +import { + ACTIVITYSTREAMS_CONTEXT, + getTypedEntity, +} from 'activitypub-core-utilities'; import { LOCAL_DOMAIN } from 'activitypub-core-utilities'; import { getGuid } from 'activitypub-core-utilities'; import type { Database } from 'activitypub-core-types'; @@ -42,7 +45,7 @@ export async function handleCreate( const publishedDate = new Date(); const objectReplies: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${object.id.toString()}/replies`), url: new URL(`${object.id.toString()}/replies`), name: 'Replies', @@ -53,7 +56,7 @@ export async function handleCreate( }; const objectLikes: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${object.id.toString()}/likes`), url: new URL(`${object.id.toString()}/likes`), name: 'Likes', @@ -64,7 +67,7 @@ export async function handleCreate( }; const objectShares: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${object.id.toString()}/shares`), url: new URL(`${object.id.toString()}/shares`), name: 'Shares', diff --git a/packages/activitypub-core/src/outbox/index.ts b/packages/activitypub-core/src/outbox/index.ts index 19c4a118..9034c279 100644 --- a/packages/activitypub-core/src/outbox/index.ts +++ b/packages/activitypub-core/src/outbox/index.ts @@ -1,7 +1,10 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; import type { IncomingMessage, ServerResponse } from 'http'; -import { ACTIVITYSTREAMS_CONTEXT, LOCAL_DOMAIN } from 'activitypub-core-utilities'; +import { + ACTIVITYSTREAMS_CONTEXT, + LOCAL_DOMAIN, +} from 'activitypub-core-utilities'; import { entityGetHandler } from '../entity'; import { handleDelete } from './delete'; import { handleCreate } from './create'; @@ -123,7 +126,7 @@ async function handleOutboxPost( // Attach replies, likes, and shares. const activityReplies: AP.Collection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${activityToSaveId.toString()}/replies`), url: new URL(`${activityToSaveId.toString()}/replies`), name: 'Replies', @@ -134,7 +137,7 @@ async function handleOutboxPost( }; const activityLikes: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${activityToSaveId.toString()}/likes`), url: new URL(`${activityToSaveId.toString()}/likes`), name: 'Likes', @@ -145,7 +148,7 @@ async function handleOutboxPost( }; const activityShares: AP.OrderedCollection = { - "@context": new URL(ACTIVITYSTREAMS_CONTEXT), + '@context': new URL(ACTIVITYSTREAMS_CONTEXT), id: new URL(`${activityToSaveId.toString()}/shares`), url: new URL(`${activityToSaveId.toString()}/shares`), name: 'Shares', diff --git a/packages/activitypub-core/src/outbox/like.ts b/packages/activitypub-core/src/outbox/like.ts index 3675f9b3..ccfc0370 100644 --- a/packages/activitypub-core/src/outbox/like.ts +++ b/packages/activitypub-core/src/outbox/like.ts @@ -2,10 +2,7 @@ import { AP } from 'activitypub-core-types'; import type { Database } from 'activitypub-core-types'; import { getId } from 'activitypub-core-utilities'; -export async function handleLike( - activity: AP.Like, - databaseService: Database, -) { +export async function handleLike(activity: AP.Like, databaseService: Database) { if (!activity.id) { throw new Error('Bad request 6'); } diff --git a/packages/activitypub-core/src/outbox/update.ts b/packages/activitypub-core/src/outbox/update.ts index b5b85c7d..b2939dc0 100644 --- a/packages/activitypub-core/src/outbox/update.ts +++ b/packages/activitypub-core/src/outbox/update.ts @@ -51,8 +51,8 @@ export async function handleUpdate( ...activity.object, ...(objectToUpdate.type !== 'Link' && objectToUpdate.type !== 'Mention' ? { - updated: new Date(), - } + updated: new Date(), + } : null), }; diff --git a/packages/activitypub-core/src/sharedInbox/index.ts b/packages/activitypub-core/src/sharedInbox/index.ts index 45e50280..3b5d7d53 100644 --- a/packages/activitypub-core/src/sharedInbox/index.ts +++ b/packages/activitypub-core/src/sharedInbox/index.ts @@ -10,7 +10,7 @@ import { stringifyWithContext } from 'activitypub-core-utilities'; import type { Database } from 'activitypub-core-types'; import { DeliveryService } from 'activitypub-core-delivery'; -export async function sharedInboxPostHandler( +export async function sharedInboxHandler( req: IncomingMessage, res: ServerResponse, databaseService: Database, diff --git a/packages/activitypub-core/src/user/createServerActor.ts b/packages/activitypub-core/src/user/createServerActor.ts index 407c0e55..735641ef 100644 --- a/packages/activitypub-core/src/user/createServerActor.ts +++ b/packages/activitypub-core/src/user/createServerActor.ts @@ -14,7 +14,7 @@ export async function createServerActor(databaseService: Database) { const publishedDate = new Date(); const botInbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${SERVER_ACTOR_ID}/inbox`), url: new URL(`${SERVER_ACTOR_ID}/inbox`), type: AP.CollectionTypes.ORDERED_COLLECTION, @@ -24,7 +24,7 @@ export async function createServerActor(databaseService: Database) { }; const botOutbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${SERVER_ACTOR_ID}/outbox`), url: new URL(`${SERVER_ACTOR_ID}/outbox`), type: AP.CollectionTypes.ORDERED_COLLECTION, @@ -34,7 +34,7 @@ export async function createServerActor(databaseService: Database) { }; const botFollowers: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${SERVER_ACTOR_ID}/followers`), url: new URL(`${SERVER_ACTOR_ID}/followers`), name: 'Followers', @@ -45,7 +45,7 @@ export async function createServerActor(databaseService: Database) { }; const botFollowing: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${SERVER_ACTOR_ID}/following`), url: new URL(`${SERVER_ACTOR_ID}/following`), name: 'Following', @@ -56,7 +56,7 @@ export async function createServerActor(databaseService: Database) { }; const botActor: AP.Actor = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(SERVER_ACTOR_ID), url: new URL(SERVER_ACTOR_ID), type: AP.ActorTypes.APPLICATION, diff --git a/packages/activitypub-core/src/user/createUserActor.ts b/packages/activitypub-core/src/user/createUserActor.ts index 614b778d..f84f528e 100644 --- a/packages/activitypub-core/src/user/createUserActor.ts +++ b/packages/activitypub-core/src/user/createUserActor.ts @@ -1,6 +1,10 @@ import { ACTIVITYSTREAMS_CONTEXT, getGuid } from 'activitypub-core-utilities'; import { generateKeyPair } from 'activitypub-core-utilities'; -import { LOCAL_DOMAIN, SERVER_ACTOR_ID, SHARED_INBOX_ID } from 'activitypub-core-utilities'; +import { + LOCAL_DOMAIN, + SERVER_ACTOR_ID, + SHARED_INBOX_ID, +} from 'activitypub-core-utilities'; import type { Database } from 'activitypub-core-types'; import { AP } from 'activitypub-core-types'; @@ -14,7 +18,7 @@ export async function createUserActor( const publishedDate = new Date(); const userInbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/inbox`), url: new URL(`${id}/inbox`), name: 'Inbox', @@ -25,7 +29,7 @@ export async function createUserActor( }; const userOutbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/outbox`), url: new URL(`${id}/outbox`), name: 'Outbox', @@ -36,7 +40,7 @@ export async function createUserActor( }; const userFollowers: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/followers`), url: new URL(`${id}/followers`), name: 'Followers', @@ -47,7 +51,7 @@ export async function createUserActor( }; const userFollowing: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/following`), url: new URL(`${id}/following`), name: 'Following', @@ -58,7 +62,7 @@ export async function createUserActor( }; const userLiked: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/liked`), url: new URL(`${id}/liked`), name: 'Liked', @@ -69,7 +73,7 @@ export async function createUserActor( }; const userShared: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/shared`), url: new URL(`${id}/shared`), name: 'Shared', @@ -80,7 +84,7 @@ export async function createUserActor( }; const userBlocked: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/blocked`), url: new URL(`${id}/blocked`), name: 'Blocked', @@ -91,7 +95,7 @@ export async function createUserActor( }; const userGroups: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/groups`), url: new URL(`${id}/groups`), name: 'Groups', @@ -102,7 +106,7 @@ export async function createUserActor( }; const userReplies: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/replies`), url: new URL(`${id}/replies`), name: 'Replies', @@ -113,7 +117,7 @@ export async function createUserActor( }; const userLikes: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/likes`), url: new URL(`${id}/likes`), name: 'Likes', @@ -124,7 +128,7 @@ export async function createUserActor( }; const userShares: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/shares`), url: new URL(`${id}/shares`), name: 'Shares', @@ -135,7 +139,7 @@ export async function createUserActor( }; const userBookmarks: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${id}/bookmarks`), url: new URL(`${id}/bookmarks`), name: 'Bookmarks', @@ -146,7 +150,7 @@ export async function createUserActor( }; const userActor: AP.Actor = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(id), url: new URL(id), type: AP.ActorTypes.PERSON, @@ -160,12 +164,7 @@ export async function createUserActor( replies: userReplies.id, likes: userLikes.id, shares: userShares.id, - streams: [ - userShared.id, - userBlocked.id, - userGroups.id, - userBookmarks.id - ], + streams: [userShared.id, userBlocked.id, userGroups.id, userBookmarks.id], endpoints: { sharedInbox: new URL(SHARED_INBOX_ID), }, @@ -180,7 +179,7 @@ export async function createUserActor( const createActorActivityId = `${LOCAL_DOMAIN}/activity/${getGuid()}`; const createActorActivityReplies: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createActorActivityId}/replies`), url: new URL(`${createActorActivityId}/replies`), name: 'Replies', @@ -191,7 +190,7 @@ export async function createUserActor( }; const createActorActivityLikes: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createActorActivityId}/likes`), url: new URL(`${createActorActivityId}/likes`), name: 'Likes', @@ -202,7 +201,7 @@ export async function createUserActor( }; const createActorActivityShares: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createActorActivityId}/shares`), url: new URL(`${createActorActivityId}/shares`), name: 'Shares', @@ -213,7 +212,7 @@ export async function createUserActor( }; const createActorActivity: AP.Create = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(createActorActivityId), url: new URL(createActorActivityId), type: AP.ActivityTypes.CREATE, @@ -251,7 +250,7 @@ export async function createUserActor( const friendsGroupId = `${id}/groups/friends`; const friendsGroupInbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/inbox`), url: new URL(`${friendsGroupId}/inbox`), name: 'Inbox', @@ -261,7 +260,7 @@ export async function createUserActor( }; const friendsGroupOutbox: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/outbox`), url: new URL(`${friendsGroupId}/outbox`), name: 'Outbox', @@ -271,7 +270,7 @@ export async function createUserActor( }; const friendsGroupReplies: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/likes`), url: new URL(`${friendsGroupId}/likes`), name: 'Likes', @@ -281,7 +280,7 @@ export async function createUserActor( }; const friendsGroupLikes: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/likes`), url: new URL(`${friendsGroupId}/likes`), name: 'Likes', @@ -291,7 +290,7 @@ export async function createUserActor( }; const friendsGroupShares: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/shares`), url: new URL(`${friendsGroupId}/shares`), name: 'Shares', @@ -301,7 +300,7 @@ export async function createUserActor( }; const friendsGroupMembers: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${friendsGroupId}/members`), url: new URL(`${friendsGroupId}/members`), name: 'Members', @@ -311,7 +310,7 @@ export async function createUserActor( }; const friendsGroupActor: AP.Actor = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(friendsGroupId), url: new URL(friendsGroupId), type: AP.ActorTypes.GROUP, @@ -333,7 +332,7 @@ export async function createUserActor( const createFriendsGroupActorActivityId = `${LOCAL_DOMAIN}/activity/${getGuid()}`; const createFriendsGroupActivityReplies: AP.Collection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createFriendsGroupActorActivityId}/replies`), url: new URL(`${createFriendsGroupActorActivityId}/replies`), name: 'Replies', @@ -343,7 +342,7 @@ export async function createUserActor( }; const createFriendsGroupActivityLikes: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createFriendsGroupActorActivityId}/likes`), url: new URL(`${createFriendsGroupActorActivityId}/likes`), name: 'Likes', @@ -353,7 +352,7 @@ export async function createUserActor( }; const createFriendsGroupActivityShares: AP.OrderedCollection = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(`${createFriendsGroupActorActivityId}/shares`), url: new URL(`${createFriendsGroupActorActivityId}/shares`), name: 'Shares', @@ -363,7 +362,7 @@ export async function createUserActor( }; const createFriendsGroupActorActivity: AP.Create = { - "@context": ACTIVITYSTREAMS_CONTEXT, + '@context': ACTIVITYSTREAMS_CONTEXT, id: new URL(createFriendsGroupActorActivityId), url: new URL(createFriendsGroupActorActivityId), type: AP.ActivityTypes.CREATE, diff --git a/packages/activitypub-core/src/user/index.ts b/packages/activitypub-core/src/user/index.ts index ca1a0918..83a9303b 100644 --- a/packages/activitypub-core/src/user/index.ts +++ b/packages/activitypub-core/src/user/index.ts @@ -1,34 +1,42 @@ import * as firebaseAdmin from 'firebase-admin'; import { AppOptions, ServiceAccount } from 'firebase-admin'; -import { RESERVED_USERNAMES, SERVER_ACTOR_USERNAME } from 'activitypub-core-utilities'; +import { + RESERVED_USERNAMES, + SERVER_ACTOR_USERNAME, +} from 'activitypub-core-utilities'; import { createServerActor } from './createServerActor'; import { createUserActor } from './createUserActor'; import { AP } from 'activitypub-core-types'; import type { IncomingMessage, ServerResponse } from 'http'; import type { Database } from 'activitypub-core-types'; -export async function userPostHandler(req: IncomingMessage, res: ServerResponse, +export async function userPostHandler( + req: IncomingMessage, + res: ServerResponse, serviceAccount: ServiceAccount, databaseService: Database, setup?: ( actor: AP.Entity, databaseService: Database, - ) => Promise<{ actor: AP.Actor }>) { - const body: { [key: string]: string } = await new Promise((resolve, reject) => { - let data = ''; + ) => Promise<{ actor: AP.Actor }>, +) { + const body: { [key: string]: string } = await new Promise( + (resolve, reject) => { + let data = ''; - req.on('data', function (chunk) { - data += chunk; - }); + req.on('data', function (chunk) { + data += chunk; + }); - req.on('end', function () { - resolve(JSON.parse(data)); - }); + req.on('end', function () { + resolve(JSON.parse(data)); + }); - req.on('error', function () { - reject('Failed to make an OAuth request'); - }); - }); + req.on('error', function () { + reject('Failed to make an OAuth request'); + }); + }, + ); const { email, password, name, preferredUsername } = body; @@ -38,9 +46,11 @@ export async function userPostHandler(req: IncomingMessage, res: ServerResponse, if (isUsernameTaken || RESERVED_USERNAMES.includes(preferredUsername)) { res.statusCode = 409; - res.write(JSON.stringify({ - error: 'Username Taken.' - })); + res.write( + JSON.stringify({ + error: 'Username Taken.', + }), + ); res.end(); return; } @@ -88,9 +98,11 @@ export async function userPostHandler(req: IncomingMessage, res: ServerResponse, } res.statusCode = 200; - res.write(JSON.stringify({ - success: true - })); + res.write( + JSON.stringify({ + success: true, + }), + ); res.end(); return; -}; +}