@fedify/fedify 0.9.0-dev.172 → 0.9.0-dev.173
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.
Potentially problematic release.
This version of @fedify/fedify might be problematic. Click here for more details.
- package/CHANGES.md +11 -0
- package/esm/vocab/actor.js +31 -5
- package/package.json +1 -1
- package/types/vocab/actor.d.ts +28 -2
- package/types/vocab/actor.d.ts.map +1 -1
package/CHANGES.md
CHANGED
@@ -12,6 +12,17 @@ To be released.
|
|
12
12
|
|
13
13
|
- Added `Emoji` class to Activity Vocabulary API. [[#48]]
|
14
14
|
|
15
|
+
- Added an actor handle normalization function.
|
16
|
+
|
17
|
+
- Added `normalizeActorHandle()` function.
|
18
|
+
- Added `NormalizeActorHandleOptions` interface.
|
19
|
+
- The `getActorHandle()` function now guarantees that the returned
|
20
|
+
actor handle is normalized.
|
21
|
+
- Added the second optional parameter to `getActorHandle()` function.
|
22
|
+
- The return type of `getActorHandle()` function became
|
23
|
+
``Promise<`@${string}@${string}` | `${string}@${string}`>``
|
24
|
+
(was ``Promise<`@${string}@${string}`>``).
|
25
|
+
|
15
26
|
- Added more log messages using the [LogTape] library. Currently the below
|
16
27
|
logger categories are used:
|
17
28
|
|
package/esm/vocab/actor.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { toASCII, toUnicode } from "node:punycode";
|
1
2
|
import { lookupWebFinger } from "../webfinger/lookup.js";
|
2
3
|
import { Application, Group, Organization, Person, Service } from "./vocab.js";
|
3
4
|
/**
|
@@ -66,13 +67,15 @@ export function getActorClassByTypeName(typeName) {
|
|
66
67
|
* ```
|
67
68
|
*
|
68
69
|
* @param actor The actor or actor URI to get the handle from.
|
70
|
+
* @param options The options for normalizing the actor handle.
|
69
71
|
* @returns The actor handle. It starts with `@` and is followed by the
|
70
|
-
* username and domain, separated by
|
72
|
+
* username and domain, separated by `@` by default (it can be
|
73
|
+
* customized with the options).
|
71
74
|
* @throws {TypeError} If the actor does not have enough information to get the
|
72
75
|
* handle.
|
73
76
|
* @since 0.4.0
|
74
77
|
*/
|
75
|
-
export async function getActorHandle(actor) {
|
78
|
+
export async function getActorHandle(actor, options = {}) {
|
76
79
|
const actorId = actor instanceof URL ? actor : actor.id;
|
77
80
|
if (actorId != null) {
|
78
81
|
const result = await lookupWebFinger(actorId);
|
@@ -82,14 +85,37 @@ export async function getActorHandle(actor) {
|
|
82
85
|
aliases.unshift(result.subject);
|
83
86
|
for (const alias of aliases) {
|
84
87
|
const match = alias.match(/^acct:([^@]+)@([^@]+)$/);
|
85
|
-
if (match != null)
|
86
|
-
return `@${match[1]}@${match[2]}
|
88
|
+
if (match != null) {
|
89
|
+
return normalizeActorHandle(`@${match[1]}@${match[2]}`, options);
|
90
|
+
}
|
87
91
|
}
|
88
92
|
}
|
89
93
|
}
|
90
94
|
if (!(actor instanceof URL) && actor.preferredUsername != null &&
|
91
95
|
actor.id != null) {
|
92
|
-
return `@${actor.preferredUsername}@${actor.id.host}
|
96
|
+
return normalizeActorHandle(`@${actor.preferredUsername}@${actor.id.host}`, options);
|
93
97
|
}
|
94
98
|
throw new TypeError("Actor does not have enough information to get the handle.");
|
95
99
|
}
|
100
|
+
/**
|
101
|
+
* Normalizes the given actor handle.
|
102
|
+
* @param handle The full handle of the actor to normalize.
|
103
|
+
* @param options The options for normalizing the actor handle.
|
104
|
+
* @returns The normalized actor handle.
|
105
|
+
* @throws {TypeError} If the actor handle is invalid.
|
106
|
+
*/
|
107
|
+
export function normalizeActorHandle(handle, options = {}) {
|
108
|
+
handle = handle.replace(/^@/, "");
|
109
|
+
const atPos = handle.indexOf("@");
|
110
|
+
if (atPos < 1)
|
111
|
+
throw new TypeError("Invalid actor handle.");
|
112
|
+
let domain = handle.substring(atPos + 1);
|
113
|
+
if (domain.length < 1 || domain.includes("@")) {
|
114
|
+
throw new TypeError("Invalid actor handle.");
|
115
|
+
}
|
116
|
+
domain = domain.toLowerCase();
|
117
|
+
domain = options.punycode ? toASCII(domain) : toUnicode(domain);
|
118
|
+
domain = domain.toLowerCase();
|
119
|
+
const user = handle.substring(0, atPos);
|
120
|
+
return options.trimLeadingAt ? `${user}@${domain}` : `@${user}@${domain}`;
|
121
|
+
}
|
package/package.json
CHANGED
package/types/vocab/actor.d.ts
CHANGED
@@ -43,13 +43,39 @@ export declare function getActorClassByTypeName(typeName: ActorTypeName): typeof
|
|
43
43
|
* ```
|
44
44
|
*
|
45
45
|
* @param actor The actor or actor URI to get the handle from.
|
46
|
+
* @param options The options for normalizing the actor handle.
|
46
47
|
* @returns The actor handle. It starts with `@` and is followed by the
|
47
|
-
* username and domain, separated by
|
48
|
+
* username and domain, separated by `@` by default (it can be
|
49
|
+
* customized with the options).
|
48
50
|
* @throws {TypeError} If the actor does not have enough information to get the
|
49
51
|
* handle.
|
50
52
|
* @since 0.4.0
|
51
53
|
*/
|
52
|
-
export declare function getActorHandle(actor: Actor | URL): Promise<`@${string}@${string}`>;
|
54
|
+
export declare function getActorHandle(actor: Actor | URL, options?: NormalizeActorHandleOptions): Promise<`@${string}@${string}` | `${string}@${string}`>;
|
55
|
+
/**
|
56
|
+
* Options for {@link normalizeActorHandle}.
|
57
|
+
* @since 0.9.0
|
58
|
+
*/
|
59
|
+
export interface NormalizeActorHandleOptions {
|
60
|
+
/**
|
61
|
+
* Whether to trim the leading `@` from the actor handle. Turned off by
|
62
|
+
* default.
|
63
|
+
*/
|
64
|
+
trimLeadingAt?: boolean;
|
65
|
+
/**
|
66
|
+
* Whether to convert the domain part of the actor handle to punycode, if it
|
67
|
+
* is an internationalized domain name. Turned off by default.
|
68
|
+
*/
|
69
|
+
punycode?: boolean;
|
70
|
+
}
|
71
|
+
/**
|
72
|
+
* Normalizes the given actor handle.
|
73
|
+
* @param handle The full handle of the actor to normalize.
|
74
|
+
* @param options The options for normalizing the actor handle.
|
75
|
+
* @returns The normalized actor handle.
|
76
|
+
* @throws {TypeError} If the actor handle is invalid.
|
77
|
+
*/
|
78
|
+
export declare function normalizeActorHandle(handle: string, options?: NormalizeActorHandleOptions): `@${string}@${string}` | `${string}@${string}`;
|
53
79
|
/**
|
54
80
|
* The object that can be a recipient of an activity.
|
55
81
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../src/vocab/actor.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../src/vocab/actor.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,KAAK,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,KAAK,CAQxD;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,OAAO,GACP,cAAc,GACd,QAAQ,GACR,SAAS,CAAC;AAEd;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,GACX,aAAa,CAOf;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,aAAa,GAErB,OAAO,WAAW,GAClB,OAAO,KAAK,GACZ,OAAO,YAAY,GACnB,OAAO,MAAM,GACb,OAAO,OAAO,CAcjB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,KAAK,GAAG,GAAG,EAClB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,IAAI,MAAM,IAAI,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CA2BzD;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAAgC,GACxC,IAAI,MAAM,IAAI,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAahD;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB;;WAEG;QACH,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;KACzB,GAAG,IAAI,CAAC;CACV"}
|