@evanp/activitypub-bot 0.45.2 → 0.45.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.
- package/CHANGELOG.md +12 -0
- package/lib/botcontext.js +9 -1
- package/lib/distributionworker.js +7 -0
- package/lib/requestthrottler.js +12 -1
- package/lib/worker.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,18 @@ and this project adheres to
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.45.4] - 2026-04-26
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Retry throttled deliveries
|
|
17
|
+
|
|
18
|
+
## [0.45.3] - 2026-04-24
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Correct summary for Announce activities
|
|
23
|
+
|
|
12
24
|
## [0.45.2] - 2026-04-24
|
|
13
25
|
|
|
14
26
|
### Fixed
|
package/lib/botcontext.js
CHANGED
|
@@ -10,6 +10,8 @@ const AS2_TYPES = [
|
|
|
10
10
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
|
11
11
|
]
|
|
12
12
|
|
|
13
|
+
const AS2_NS = 'https://www.w3.org/ns/activitystreams#'
|
|
14
|
+
|
|
13
15
|
const WF_NS = 'https://purl.archive.org/socialweb/webfinger#'
|
|
14
16
|
|
|
15
17
|
const THREAD_PROP = 'https://purl.archive.org/socialweb/thread#thread'
|
|
@@ -558,7 +560,13 @@ export class BotContext {
|
|
|
558
560
|
} else if (obj.summary) {
|
|
559
561
|
return obj.summary.get()
|
|
560
562
|
} else if (obj.type) {
|
|
561
|
-
|
|
563
|
+
const type = (Array.isArray(obj.type))
|
|
564
|
+
? obj.type[0]
|
|
565
|
+
: obj.type
|
|
566
|
+
const shortType = (type.startsWith(AS2_NS))
|
|
567
|
+
? type.slice(AS2_NS.length)
|
|
568
|
+
: type
|
|
569
|
+
return `a(n) ${shortType}`
|
|
562
570
|
} else {
|
|
563
571
|
return 'an object'
|
|
564
572
|
}
|
|
@@ -2,6 +2,7 @@ import assert from 'node:assert'
|
|
|
2
2
|
|
|
3
3
|
import as2 from './activitystreams.js'
|
|
4
4
|
import { Worker, RecoverableError } from './worker.js'
|
|
5
|
+
import { ThrottleError } from './requestthrottler.js'
|
|
5
6
|
|
|
6
7
|
export class DistributionWorker extends Worker {
|
|
7
8
|
static #MAX_ATTEMPTS = 21 // ~24 days
|
|
@@ -21,6 +22,12 @@ export class DistributionWorker extends Worker {
|
|
|
21
22
|
this._logger.info({ activity: activity.id, inbox }, 'Delivered activity')
|
|
22
23
|
} catch (err) {
|
|
23
24
|
if (!err.status) {
|
|
25
|
+
if (err instanceof ThrottleError) {
|
|
26
|
+
this._logger.warn(
|
|
27
|
+
{ err, activity: activity.id, inbox },
|
|
28
|
+
'Throttled delivery, waiting to retry')
|
|
29
|
+
throw new RecoverableError(err.message, err.waitTime)
|
|
30
|
+
}
|
|
24
31
|
this._logger.warn(
|
|
25
32
|
{ err, activity: activity.id, inbox },
|
|
26
33
|
'Could not deliver activity and no HTTP status available')
|
package/lib/requestthrottler.js
CHANGED
|
@@ -3,6 +3,14 @@ import assert from 'node:assert'
|
|
|
3
3
|
|
|
4
4
|
const BETA = 0.75
|
|
5
5
|
|
|
6
|
+
export class ThrottleError extends Error {
|
|
7
|
+
constructor (message, waitTime) {
|
|
8
|
+
super(message)
|
|
9
|
+
this.name = this.constructor.name
|
|
10
|
+
this.waitTime = waitTime
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
export class RequestThrottler {
|
|
7
15
|
#connection
|
|
8
16
|
#logger
|
|
@@ -19,7 +27,10 @@ export class RequestThrottler {
|
|
|
19
27
|
assert.strictEqual(typeof maxWaitTime, 'number')
|
|
20
28
|
const waitTime = await this.#getWaitTime(host, maxWaitTime)
|
|
21
29
|
if (waitTime > maxWaitTime) {
|
|
22
|
-
throw new
|
|
30
|
+
throw new ThrottleError(
|
|
31
|
+
`Wait time is too long; ${waitTime} > ${maxWaitTime}`,
|
|
32
|
+
waitTime
|
|
33
|
+
)
|
|
23
34
|
}
|
|
24
35
|
if (waitTime > 0) {
|
|
25
36
|
await this.#decrement(host)
|
package/lib/worker.js
CHANGED
|
@@ -2,7 +2,12 @@ import assert from 'node:assert'
|
|
|
2
2
|
import { nanoid } from 'nanoid'
|
|
3
3
|
|
|
4
4
|
export class RecoverableError extends Error {
|
|
5
|
-
delay
|
|
5
|
+
delay
|
|
6
|
+
constructor (message, delay = 1000) {
|
|
7
|
+
super(message)
|
|
8
|
+
this.name = this.constructor.name
|
|
9
|
+
this.delay = delay
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
export class Worker {
|