@evanp/activitypub-bot 0.28.3 → 0.28.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,7 +105,10 @@ export class ActivityPubClient {
105
105
  }
106
106
  const json = await res.json()
107
107
  const obj = await as2.import(json)
108
- return obj
108
+ const resolved = (URL.parse(url).hash)
109
+ ? this.#resolveObject(obj, url)
110
+ : obj
111
+ return resolved
109
112
  }
110
113
 
111
114
  async post (url, obj, username) {
@@ -220,4 +223,37 @@ export class ActivityPubClient {
220
223
  json.object.object = 'https://www.w3.org/ns/activitystreams#Public'
221
224
  }
222
225
  }
226
+
227
+ #resolveObject (obj, url, visited = new Set()) {
228
+ if (obj.id && obj.id === url) {
229
+ return obj
230
+ }
231
+
232
+ if (obj.id) {
233
+ if (visited.has(obj.id)) {
234
+ return null
235
+ }
236
+ visited.add(obj.id)
237
+ }
238
+
239
+ for (const key of obj) {
240
+ if (key === '@type' || key === '@id') continue
241
+
242
+ const val = obj.get(key)
243
+
244
+ if (val == null || typeof val[Symbol.iterator] !== 'function') {
245
+ continue
246
+ }
247
+
248
+ for (const item of val) {
249
+ if (item instanceof as2.models.Base) {
250
+ const found = this.#resolveObject(item, url, visited)
251
+ if (found) {
252
+ return found
253
+ }
254
+ }
255
+ }
256
+ }
257
+ return null
258
+ }
223
259
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.28.3",
3
+ "version": "0.28.4",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",