@fedify/vocab 2.4.0-pr.936.41 → 2.5.0-dev.2271
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/deno.json +1 -1
- package/dist/mod.cjs +31412 -8807
- package/dist/mod.d.cts +4599 -6
- package/dist/mod.d.ts +4599 -6
- package/dist/mod.js +31305 -8707
- package/dist-tests/actor-NlmVfaZI.mjs +276 -0
- package/dist-tests/actor.test.mjs +55 -49
- package/dist-tests/{actor-MBpzF3-D.mjs → esm-DxaxLS8O.mjs} +15 -211
- package/dist-tests/gateway.test.mjs +1906 -0
- package/dist-tests/lookup-BUL82PQy.mjs +480 -0
- package/dist-tests/lookup.test.mjs +10 -268
- package/dist-tests/object.yaml +15 -0
- package/dist-tests/portable-lookup.test.mjs +653 -0
- package/dist-tests/signed-representation.test.mjs +189 -0
- package/dist-tests/translation.test.mjs +404 -0
- package/dist-tests/translation.yaml +91 -0
- package/dist-tests/type.test.mjs +2 -2
- package/dist-tests/{vocab-Bjwctrxn.mjs → vocab-hNQYgnUG.mjs} +31068 -8752
- package/dist-tests/vocab.test.mjs +677 -10
- package/package.json +5 -5
- package/src/__snapshots__/vocab.test.ts.snap +291 -15
- package/src/actor.test.ts +41 -40
- package/src/actor.ts +120 -1
- package/src/gateway.test.ts +2637 -0
- package/src/lookup.test.ts +6 -5
- package/src/lookup.ts +460 -33
- package/src/mod.ts +9 -0
- package/src/object.yaml +15 -0
- package/src/portable-lookup.test.ts +889 -0
- package/src/preprocessors.ts +1 -1
- package/src/signed-representation.test.ts +277 -0
- package/src/translation.test.ts +518 -0
- package/src/translation.yaml +91 -0
- package/src/vocab.test.ts +914 -5
- /package/dist-tests/{type-_BlsfT3S.mjs → type-BMdjm4Eg.mjs} +0 -0
- /package/dist-tests/{utils-CQjrpUkt.mjs → utils-Df2odC27.mjs} +0 -0
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import "temporal-polyfill";
|
|
2
2
|
globalThis.addEventListener = () => {};
|
|
3
|
-
import {
|
|
4
|
-
import { t as getTypeId } from "./type-_BlsfT3S.mjs";
|
|
5
|
-
import { lookupWebFinger } from "@fedify/webfinger";
|
|
6
|
-
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
7
|
-
import { domainToASCII, domainToUnicode } from "node:url";
|
|
3
|
+
import { $ as __toESM, Z as __commonJSMin } from "./vocab-hNQYgnUG.mjs";
|
|
8
4
|
//#endregion
|
|
9
5
|
//#region ../../node_modules/.pnpm/regexparam@3.0.0/node_modules/regexparam/dist/index.mjs
|
|
10
6
|
var import_glob_to_regexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -110,27 +106,27 @@ function parse(input, loose) {
|
|
|
110
106
|
}
|
|
111
107
|
//#endregion
|
|
112
108
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/TypeDescriptor.js
|
|
113
|
-
const valueTypes = new Set([
|
|
109
|
+
const valueTypes = /* @__PURE__ */ new Set([
|
|
114
110
|
"boolean",
|
|
115
111
|
"number",
|
|
116
112
|
"null",
|
|
117
113
|
"string",
|
|
118
114
|
"undefined"
|
|
119
115
|
]);
|
|
120
|
-
const referenceTypes = new Set([
|
|
116
|
+
const referenceTypes = /* @__PURE__ */ new Set([
|
|
121
117
|
"array",
|
|
122
118
|
"function",
|
|
123
119
|
"object",
|
|
124
120
|
"symbol"
|
|
125
121
|
]);
|
|
126
|
-
const detectableTypes = new Set([
|
|
122
|
+
const detectableTypes = /* @__PURE__ */ new Set([
|
|
127
123
|
"boolean",
|
|
128
124
|
"function",
|
|
129
125
|
"number",
|
|
130
126
|
"string",
|
|
131
127
|
"symbol"
|
|
132
128
|
]);
|
|
133
|
-
const typeConstructors = new Set([
|
|
129
|
+
const typeConstructors = /* @__PURE__ */ new Set([
|
|
134
130
|
Boolean,
|
|
135
131
|
Number,
|
|
136
132
|
String
|
|
@@ -201,7 +197,7 @@ var TypeDescriptor = class TypeDescriptor {
|
|
|
201
197
|
};
|
|
202
198
|
//#endregion
|
|
203
199
|
//#region ../../node_modules/.pnpm/fetch-mock@12.6.0/node_modules/fetch-mock/dist/esm/IsSubsetOf.js
|
|
204
|
-
const allowedTypes = new Set([
|
|
200
|
+
const allowedTypes = /* @__PURE__ */ new Set([
|
|
205
201
|
"array",
|
|
206
202
|
"object",
|
|
207
203
|
"function",
|
|
@@ -693,7 +689,14 @@ var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
|
693
689
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
694
690
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
695
691
|
};
|
|
696
|
-
var _Route_instances
|
|
692
|
+
var _Route_instances;
|
|
693
|
+
var _a;
|
|
694
|
+
var _Route_responseSubscriptions;
|
|
695
|
+
var _Route_validate;
|
|
696
|
+
var _Route_sanitize;
|
|
697
|
+
var _Route_generateMatcher;
|
|
698
|
+
var _Route_limit;
|
|
699
|
+
var _Route_delayResponse;
|
|
697
700
|
var RouteConfigWrapper = class {
|
|
698
701
|
constructor(config) {
|
|
699
702
|
Object.assign(this, config);
|
|
@@ -1204,203 +1207,4 @@ var esm_default = new class FetchMock {
|
|
|
1204
1207
|
}
|
|
1205
1208
|
}({ ...defaultFetchMockConfig });
|
|
1206
1209
|
//#endregion
|
|
1207
|
-
|
|
1208
|
-
var name = "@fedify/vocab";
|
|
1209
|
-
var version = "2.4.0-pr.936.41+59c7432c";
|
|
1210
|
-
//#endregion
|
|
1211
|
-
//#region src/actor.ts
|
|
1212
|
-
const ACTOR_DISCOVERY_HISTOGRAM_BUCKETS = [
|
|
1213
|
-
5,
|
|
1214
|
-
10,
|
|
1215
|
-
25,
|
|
1216
|
-
50,
|
|
1217
|
-
75,
|
|
1218
|
-
100,
|
|
1219
|
-
250,
|
|
1220
|
-
500,
|
|
1221
|
-
750,
|
|
1222
|
-
1e3,
|
|
1223
|
-
2500,
|
|
1224
|
-
5e3,
|
|
1225
|
-
7500,
|
|
1226
|
-
1e4
|
|
1227
|
-
];
|
|
1228
|
-
const actorDiscoveryInstruments = /* @__PURE__ */ new WeakMap();
|
|
1229
|
-
function getActorDiscoveryInstruments(meterProvider) {
|
|
1230
|
-
let instruments = actorDiscoveryInstruments.get(meterProvider);
|
|
1231
|
-
if (instruments == null) {
|
|
1232
|
-
const meter = meterProvider.getMeter(name, version);
|
|
1233
|
-
instruments = {
|
|
1234
|
-
discovery: meter.createCounter("activitypub.actor.discovery", {
|
|
1235
|
-
description: "Actor handle discovery attempts via getActorHandle(), classified by terminal outcome.",
|
|
1236
|
-
unit: "{discovery}"
|
|
1237
|
-
}),
|
|
1238
|
-
discoveryDuration: meter.createHistogram("activitypub.actor.discovery.duration", {
|
|
1239
|
-
description: "Duration of getActorHandle() actor discovery calls.",
|
|
1240
|
-
unit: "ms",
|
|
1241
|
-
advice: { explicitBucketBoundaries: [...ACTOR_DISCOVERY_HISTOGRAM_BUCKETS] }
|
|
1242
|
-
})
|
|
1243
|
-
};
|
|
1244
|
-
actorDiscoveryInstruments.set(meterProvider, instruments);
|
|
1245
|
-
}
|
|
1246
|
-
return instruments;
|
|
1247
|
-
}
|
|
1248
|
-
function getActorDiscoveryRemoteHost(actor) {
|
|
1249
|
-
const id = actor instanceof URL ? actor : actor.id;
|
|
1250
|
-
if (id == null) return void 0;
|
|
1251
|
-
return id.host === "" ? void 0 : id.host;
|
|
1252
|
-
}
|
|
1253
|
-
var ActorHandleNotFoundError = class extends TypeError {
|
|
1254
|
-
constructor() {
|
|
1255
|
-
super("Actor does not have enough information to get the handle.");
|
|
1256
|
-
this.name = "ActorHandleNotFoundError";
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
/**
|
|
1260
|
-
* Checks if the given object is an {@link Actor}.
|
|
1261
|
-
* @param object The object to check.
|
|
1262
|
-
* @returns `true` if the given object is an {@link Actor}.
|
|
1263
|
-
*/
|
|
1264
|
-
function isActor(object) {
|
|
1265
|
-
return object instanceof Application || object instanceof Group || object instanceof Organization || object instanceof Person || object instanceof Service;
|
|
1266
|
-
}
|
|
1267
|
-
/**
|
|
1268
|
-
* Gets the type name of the given actor.
|
|
1269
|
-
* @param actor The actor to get the type name of.
|
|
1270
|
-
* @returns The type name of the given actor.
|
|
1271
|
-
*/
|
|
1272
|
-
function getActorTypeName(actor) {
|
|
1273
|
-
if (actor instanceof Application) return "Application";
|
|
1274
|
-
else if (actor instanceof Group) return "Group";
|
|
1275
|
-
else if (actor instanceof Organization) return "Organization";
|
|
1276
|
-
else if (actor instanceof Person) return "Person";
|
|
1277
|
-
else if (actor instanceof Service) return "Service";
|
|
1278
|
-
throw new Error("Unknown actor type.");
|
|
1279
|
-
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Gets the actor class by the given type name.
|
|
1282
|
-
* @param typeName The type name to get the actor class by.
|
|
1283
|
-
* @returns The actor class by the given type name.
|
|
1284
|
-
*/
|
|
1285
|
-
function getActorClassByTypeName(typeName) {
|
|
1286
|
-
switch (typeName) {
|
|
1287
|
-
case "Application": return Application;
|
|
1288
|
-
case "Group": return Group;
|
|
1289
|
-
case "Organization": return Organization;
|
|
1290
|
-
case "Person": return Person;
|
|
1291
|
-
case "Service": return Service;
|
|
1292
|
-
}
|
|
1293
|
-
throw new Error("Unknown actor type name.");
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Gets the actor handle, of the form `@username@domain`, from the given actor
|
|
1297
|
-
* or an actor URI.
|
|
1298
|
-
*
|
|
1299
|
-
* @example
|
|
1300
|
-
* ``` typescript
|
|
1301
|
-
* // Get the handle of an actor object:
|
|
1302
|
-
* await getActorHandle(
|
|
1303
|
-
* new Person({ id: new URL("https://fosstodon.org/users/hongminhee") })
|
|
1304
|
-
* );
|
|
1305
|
-
*
|
|
1306
|
-
* // Get the handle of an actor URI:
|
|
1307
|
-
* await getActorHandle(new URL("https://fosstodon.org/users/hongminhee"));
|
|
1308
|
-
* ```
|
|
1309
|
-
*
|
|
1310
|
-
* @param actor The actor or actor URI to get the handle from.
|
|
1311
|
-
* @param options The extra options for getting the actor handle.
|
|
1312
|
-
* @returns The actor handle. It starts with `@` and is followed by the
|
|
1313
|
-
* username and domain, separated by `@` by default (it can be
|
|
1314
|
-
* customized with the options).
|
|
1315
|
-
* @throws {TypeError} If the actor does not have enough information to get the
|
|
1316
|
-
* handle.
|
|
1317
|
-
* @since 0.4.0
|
|
1318
|
-
*/
|
|
1319
|
-
async function getActorHandle(actor, options = {}) {
|
|
1320
|
-
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("activitypub.get_actor_handle", async (span) => {
|
|
1321
|
-
if (isActor(actor)) {
|
|
1322
|
-
if (actor.id != null) span.setAttribute("activitypub.actor.id", actor.id.href);
|
|
1323
|
-
span.setAttribute("activitypub.actor.type", getTypeId(actor).href);
|
|
1324
|
-
}
|
|
1325
|
-
const meterProvider = options.meterProvider;
|
|
1326
|
-
const start = meterProvider == null ? 0 : performance.now();
|
|
1327
|
-
let result = "error";
|
|
1328
|
-
try {
|
|
1329
|
-
const handle = await getActorHandleInternal(actor, options);
|
|
1330
|
-
result = "resolved";
|
|
1331
|
-
return handle;
|
|
1332
|
-
} catch (error) {
|
|
1333
|
-
result = error instanceof ActorHandleNotFoundError ? "not_found" : "error";
|
|
1334
|
-
span.setStatus({
|
|
1335
|
-
code: SpanStatusCode.ERROR,
|
|
1336
|
-
message: String(error)
|
|
1337
|
-
});
|
|
1338
|
-
throw error;
|
|
1339
|
-
} finally {
|
|
1340
|
-
if (meterProvider != null) {
|
|
1341
|
-
const attributes = { "activitypub.actor.discovery.result": result };
|
|
1342
|
-
const host = getActorDiscoveryRemoteHost(actor);
|
|
1343
|
-
if (host != null) attributes["activitypub.remote.host"] = host;
|
|
1344
|
-
const instruments = getActorDiscoveryInstruments(meterProvider);
|
|
1345
|
-
instruments.discovery.add(1, attributes);
|
|
1346
|
-
instruments.discoveryDuration.record(Math.max(0, performance.now() - start), attributes);
|
|
1347
|
-
}
|
|
1348
|
-
span.end();
|
|
1349
|
-
}
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
async function getActorHandleInternal(actor, options = {}) {
|
|
1353
|
-
const actorId = actor instanceof URL ? actor : actor.id;
|
|
1354
|
-
if (actorId != null) {
|
|
1355
|
-
const result = await lookupWebFinger(actorId, {
|
|
1356
|
-
userAgent: options.userAgent,
|
|
1357
|
-
tracerProvider: options.tracerProvider,
|
|
1358
|
-
meterProvider: options.meterProvider
|
|
1359
|
-
});
|
|
1360
|
-
if (result != null) {
|
|
1361
|
-
const aliases = [...result.aliases ?? []];
|
|
1362
|
-
if (result.subject != null) aliases.unshift(result.subject);
|
|
1363
|
-
for (const alias of aliases) {
|
|
1364
|
-
const match = alias.match(/^acct:([^@]+)@([^@]+)$/);
|
|
1365
|
-
if (match != null) {
|
|
1366
|
-
if (new URL(`https://${match[2]}/`).hostname !== actorId.hostname && !await verifyCrossOriginActorHandle(actorId.href, alias, options.userAgent, options.tracerProvider, options.meterProvider)) continue;
|
|
1367
|
-
return normalizeActorHandle(`@${match[1]}@${match[2]}`, options);
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
if (!(actor instanceof URL) && actor.preferredUsername != null && actor.id != null) return normalizeActorHandle(`@${actor.preferredUsername}@${actor.id.host}`, options);
|
|
1373
|
-
throw new ActorHandleNotFoundError();
|
|
1374
|
-
}
|
|
1375
|
-
async function verifyCrossOriginActorHandle(actorId, alias, userAgent, tracerProvider, meterProvider) {
|
|
1376
|
-
const response = await lookupWebFinger(alias, {
|
|
1377
|
-
userAgent,
|
|
1378
|
-
tracerProvider,
|
|
1379
|
-
meterProvider
|
|
1380
|
-
});
|
|
1381
|
-
if (response == null) return false;
|
|
1382
|
-
for (const alias of response.aliases ?? []) if (new URL(alias).href === actorId) return true;
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Normalizes the given actor handle.
|
|
1387
|
-
* @param handle The full handle of the actor to normalize.
|
|
1388
|
-
* @param options The options for normalizing the actor handle.
|
|
1389
|
-
* @returns The normalized actor handle.
|
|
1390
|
-
* @throws {TypeError} If the actor handle is invalid.
|
|
1391
|
-
* @since 0.9.0
|
|
1392
|
-
*/
|
|
1393
|
-
function normalizeActorHandle(handle, options = {}) {
|
|
1394
|
-
handle = handle.replace(/^@/, "");
|
|
1395
|
-
const atPos = handle.indexOf("@");
|
|
1396
|
-
if (atPos < 1) throw new TypeError("Invalid actor handle.");
|
|
1397
|
-
let domain = handle.substring(atPos + 1);
|
|
1398
|
-
if (domain.length < 1 || domain.includes("@")) throw new TypeError("Invalid actor handle.");
|
|
1399
|
-
domain = domain.toLowerCase();
|
|
1400
|
-
domain = options.punycode ? domainToASCII(domain) : domainToUnicode(domain);
|
|
1401
|
-
domain = domain.toLowerCase();
|
|
1402
|
-
const user = handle.substring(0, atPos);
|
|
1403
|
-
return options.trimLeadingAt ? `${user}@${domain}` : `@${user}@${domain}`;
|
|
1404
|
-
}
|
|
1405
|
-
//#endregion
|
|
1406
|
-
export { normalizeActorHandle as a, esm_default as c, isActor as i, getActorHandle as n, name as o, getActorTypeName as r, version as s, getActorClassByTypeName as t };
|
|
1210
|
+
export { esm_default as t };
|