@evanp/activitypub-bot 0.39.2 → 0.39.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.
@@ -160,15 +160,17 @@ export class ActivityPubClient {
160
160
  }
161
161
  this.#logger.debug({ headers }, 'Sending headers')
162
162
  const method = 'GET'
163
- this.#logger.debug({ url: baseUrl }, 'Signing GET request')
164
163
  let storedPolicy, lastPolicy
165
164
  if (sign) {
165
+ this.#logger.debug({ url: baseUrl }, 'Signing GET request')
166
166
  storedPolicy = await this.#policyStorage.get(parsed.origin)
167
167
  if (!storedPolicy || storedPolicy === SignaturePolicyStorage.RFC9421) {
168
+ this.#logger.debug({ origin: parsed.origin, storedPolicy }, 'Signing with RFC 9421')
168
169
  lastPolicy = SignaturePolicyStorage.RFC9421
169
170
  const sigHeaders = await this.#messageSign({ username, url: baseUrl, method, headers })
170
171
  Object.assign(headers, sigHeaders || {})
171
172
  } else if (storedPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
173
+ this.#logger.debug({ origin: parsed.origin, storedPolicy }, 'Signing with draft-cavage-12')
172
174
  lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
173
175
  headers.signature =
174
176
  await this.#sign({ username, url: baseUrl, method, headers })
@@ -190,6 +192,10 @@ export class ActivityPubClient {
190
192
  if ([401, 403].includes(res.status) &&
191
193
  sign &&
192
194
  !storedPolicy) {
195
+ const body = await res.text()
196
+ this.#logger.debug(
197
+ { url, status: res.status, body, headers: res.headers },
198
+ 'Authentication error; retrying with draft-cavage-12 signature')
193
199
  lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
194
200
  delete headers['signature-input']
195
201
  headers.signature =
@@ -285,6 +291,9 @@ export class ActivityPubClient {
285
291
  let lastPolicy
286
292
  const storedPolicy = await this.#policyStorage.get(parsed.origin)
287
293
  if (!storedPolicy || storedPolicy === SignaturePolicyStorage.RFC9421) {
294
+ this.#logger.debug(
295
+ { origin: parsed.origin, storedPolicy }, 'Signing with RFC9421'
296
+ )
288
297
  lastPolicy = SignaturePolicyStorage.RFC9421
289
298
  headers = {
290
299
  ...baseHeaders,
@@ -293,6 +302,9 @@ export class ActivityPubClient {
293
302
  const sigHeaders = await this.#messageSign({ username, url, method, headers })
294
303
  Object.assign(headers, sigHeaders || {})
295
304
  } else if (storedPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
305
+ this.#logger.debug(
306
+ { origin: parsed.origin, storedPolicy }, 'Signing with draft-cavage-12'
307
+ )
296
308
  lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
297
309
  headers = {
298
310
  ...baseHeaders,
@@ -315,6 +327,11 @@ export class ActivityPubClient {
315
327
  }
316
328
  )
317
329
  if ([401, 403].includes(res.status) && !storedPolicy) {
330
+ const body = await res.text()
331
+ this.#logger.debug(
332
+ { url, status: res.status, body, headers: res.headers },
333
+ 'Authentication error; retrying with draft-cavage-12 signature'
334
+ )
318
335
  lastPolicy = SignaturePolicyStorage.DRAFT_CAVAGE_12
319
336
  headers = {
320
337
  ...baseHeaders,
@@ -334,10 +351,15 @@ export class ActivityPubClient {
334
351
  await this.#limiter.update(hostname, res.headers)
335
352
  this.#logger.debug({ url }, 'Done fetching POST')
336
353
  if (res.status < 200 || res.status > 299) {
354
+ const body = await res.text()
355
+ this.#logger.debug(
356
+ { url, status: res.status, body, headers: res.headers },
357
+ 'Error posting to url'
358
+ )
337
359
  throw new ActivityPubClientError(
338
360
  res.status,
339
361
  `Could not post to ${url}`,
340
- { url, method, headers: res.headers }
362
+ { url, method, headers: res.headers, body }
341
363
  )
342
364
  }
343
365
  if (!storedPolicy && lastPolicy) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.39.2",
3
+ "version": "0.39.4",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",