@fedify/testing 2.1.30 → 2.1.31

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/dist/mod.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  let _fedify_vocab = require("@fedify/vocab");
4
+ let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
5
+ let _opentelemetry_api = require("@opentelemetry/api");
4
6
  let _fedify_fedify_federation = require("@fedify/fedify/federation");
5
7
  let es_toolkit = require("es-toolkit");
6
8
  let node_assert_strict = require("node:assert/strict");
@@ -206,9 +208,11 @@ var MockFederation = class {
206
208
  inboxListeners = /* @__PURE__ */ new Map();
207
209
  contextData;
208
210
  receivedActivities = [];
211
+ documentLoader;
209
212
  constructor(options = {}) {
210
213
  this.options = options;
211
214
  this.contextData = options.contextData;
215
+ if (options.allowPrivateAddress === true) this.documentLoader = (0, _fedify_vocab_runtime.getDocumentLoader)({ allowPrivateAddress: true });
212
216
  }
213
217
  setNodeInfoDispatcher(path, dispatcher) {
214
218
  this.nodeInfoDispatcher = dispatcher;
@@ -357,7 +361,10 @@ var MockFederation = class {
357
361
  return new MockContext({
358
362
  url: baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest,
359
363
  data: contextData,
360
- federation: mockFederation
364
+ federation: mockFederation,
365
+ documentLoader: this.documentLoader,
366
+ contextLoader: this.documentLoader,
367
+ tracerProvider: this.documentLoader == null ? void 0 : this.options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()
361
368
  });
362
369
  }
363
370
  async fetch(request, options) {
@@ -377,10 +384,18 @@ var MockFederation = class {
377
384
  const typeName = activity.constructor.name;
378
385
  const listeners = this.inboxListeners.get(typeName) || [];
379
386
  if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
387
+ const receivedActivity = listeners.length > 0 && this.documentLoader != null ? activity.clone({}, {
388
+ documentLoader: this.documentLoader,
389
+ contextLoader: this.documentLoader
390
+ }) : activity;
391
+ if (receivedActivity !== activity) Reflect.set(receivedActivity, "_cachedJsonLd", Reflect.get(activity, "_cachedJsonLd"));
380
392
  for (const listener of listeners) await listener(createInboxContext({
381
393
  data: this.contextData,
382
- federation: this
383
- }), activity);
394
+ federation: this,
395
+ documentLoader: this.documentLoader,
396
+ contextLoader: this.documentLoader,
397
+ tracerProvider: this.documentLoader == null ? void 0 : this.options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()
398
+ }), receivedActivity);
384
399
  }
385
400
  /**
386
401
  * Clears all sent activities from the mock federation.
package/dist/mod.d.cts CHANGED
@@ -122,6 +122,14 @@ interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "c
122
122
  declare function createFederation<TContextData>(options?: {
123
123
  contextData?: TContextData;
124
124
  origin?: string;
125
+ /**
126
+ * Use HTTP document loading for received activities and contexts created by
127
+ * this federation, allowing private addresses such as localhost.
128
+ * If false or omitted, contexts retain their no-op mock loaders and
129
+ * received activities retain their own loaders.
130
+ * @since 2.0.35
131
+ */
132
+ allowPrivateAddress?: boolean;
125
133
  tracerProvider?: any;
126
134
  }): TestFederation<TContextData>;
127
135
  //#endregion
package/dist/mod.d.ts CHANGED
@@ -122,6 +122,14 @@ interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "c
122
122
  declare function createFederation<TContextData>(options?: {
123
123
  contextData?: TContextData;
124
124
  origin?: string;
125
+ /**
126
+ * Use HTTP document loading for received activities and contexts created by
127
+ * this federation, allowing private addresses such as localhost.
128
+ * If false or omitted, contexts retain their no-op mock loaders and
129
+ * received activities retain their own loaders.
130
+ * @since 2.0.35
131
+ */
132
+ allowPrivateAddress?: boolean;
125
133
  tracerProvider?: any;
126
134
  }): TestFederation<TContextData>;
127
135
  //#endregion
package/dist/mod.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { CryptographicKey, Multikey, lookupObject, traverseCollection } from "@fedify/vocab";
3
+ import { getDocumentLoader } from "@fedify/vocab-runtime";
4
+ import { trace } from "@opentelemetry/api";
3
5
  import { RouterError } from "@fedify/fedify/federation";
4
6
  import { delay } from "es-toolkit";
5
7
  import { deepStrictEqual, ok, strictEqual } from "node:assert/strict";
@@ -205,9 +207,11 @@ var MockFederation = class {
205
207
  inboxListeners = /* @__PURE__ */ new Map();
206
208
  contextData;
207
209
  receivedActivities = [];
210
+ documentLoader;
208
211
  constructor(options = {}) {
209
212
  this.options = options;
210
213
  this.contextData = options.contextData;
214
+ if (options.allowPrivateAddress === true) this.documentLoader = getDocumentLoader({ allowPrivateAddress: true });
211
215
  }
212
216
  setNodeInfoDispatcher(path, dispatcher) {
213
217
  this.nodeInfoDispatcher = dispatcher;
@@ -356,7 +360,10 @@ var MockFederation = class {
356
360
  return new MockContext({
357
361
  url: baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest,
358
362
  data: contextData,
359
- federation: mockFederation
363
+ federation: mockFederation,
364
+ documentLoader: this.documentLoader,
365
+ contextLoader: this.documentLoader,
366
+ tracerProvider: this.documentLoader == null ? void 0 : this.options.tracerProvider ?? trace.getTracerProvider()
360
367
  });
361
368
  }
362
369
  async fetch(request, options) {
@@ -376,10 +383,18 @@ var MockFederation = class {
376
383
  const typeName = activity.constructor.name;
377
384
  const listeners = this.inboxListeners.get(typeName) || [];
378
385
  if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
386
+ const receivedActivity = listeners.length > 0 && this.documentLoader != null ? activity.clone({}, {
387
+ documentLoader: this.documentLoader,
388
+ contextLoader: this.documentLoader
389
+ }) : activity;
390
+ if (receivedActivity !== activity) Reflect.set(receivedActivity, "_cachedJsonLd", Reflect.get(activity, "_cachedJsonLd"));
379
391
  for (const listener of listeners) await listener(createInboxContext({
380
392
  data: this.contextData,
381
- federation: this
382
- }), activity);
393
+ federation: this,
394
+ documentLoader: this.documentLoader,
395
+ contextLoader: this.documentLoader,
396
+ tracerProvider: this.documentLoader == null ? void 0 : this.options.tracerProvider ?? trace.getTracerProvider()
397
+ }), receivedActivity);
383
398
  }
384
399
  /**
385
400
  * Clears all sent activities from the mock federation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/testing",
3
- "version": "2.1.30",
3
+ "version": "2.1.31",
4
4
  "description": "Testing utilities for Fedify applications",
5
5
  "keywords": [
6
6
  "fedify",
@@ -50,20 +50,21 @@
50
50
  "package.json"
51
51
  ],
52
52
  "peerDependencies": {
53
- "@fedify/fedify": "^2.1.30"
53
+ "@fedify/fedify": "^2.1.31"
54
54
  },
55
55
  "dependencies": {
56
- "es-toolkit": "1.43.0"
56
+ "@js-temporal/polyfill": "^0.5.1",
57
+ "@opentelemetry/api": "~1.9.0",
58
+ "es-toolkit": "1.43.0",
59
+ "@fedify/vocab": "^2.1.31",
60
+ "@fedify/vocab-runtime": "^2.1.31"
57
61
  },
58
62
  "devDependencies": {
59
- "@js-temporal/polyfill": "^0.5.1",
60
63
  "@std/assert": "npm:@jsr/std__assert@^1.0.13",
61
64
  "@std/async": "npm:@jsr/std__async@^1.0.13",
62
65
  "tsdown": "^0.21.6",
63
66
  "typescript": "^6.0.0",
64
- "@fedify/fixture": "^2.0.0",
65
- "@fedify/vocab": "^2.1.30",
66
- "@fedify/vocab-runtime": "^2.1.30"
67
+ "@fedify/fixture": "^2.0.0"
67
68
  },
68
69
  "scripts": {
69
70
  "build:self": "tsdown",