@openpeepshq/core 0.26.0 → 0.28.0
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/db/pg/filters/posts.d.ts +4 -0
- package/dist/db/pg/filters/posts.js +5 -1
- package/dist/db/pg/map/filters.js +1 -0
- package/dist/db/pg/map/registry.js +7 -1
- package/dist/db/pg/queries/activity.js +23 -3
- package/dist/db/pg/queries/derived.js +2 -2
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +1 -0
- package/dist/db/pg/schema/documents.d.ts +17 -0
- package/dist/db/pg/schema/documents.js +6 -0
- package/dist/db/pg/schema/index.d.ts +17 -0
- package/dist/db/pg/sql/0019_posts_published_at.sql +6 -0
- package/dist/db/pg/sql/meta/0019_snapshot.json +4690 -0
- package/dist/db/pg/sql/meta/0022_snapshot.json +29 -2
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +1 -0
- package/dist/federation/activities.d.ts +25 -0
- package/dist/federation/activities.js +31 -1
- package/dist/federation/discovery.d.ts +70 -0
- package/dist/federation/discovery.js +155 -0
- package/dist/federation/index.d.ts +2 -1
- package/dist/federation/index.js +2 -1
- package/dist/federation/notes.js +2 -2
- package/dist/posts/finders.d.ts +6 -0
- package/dist/posts/finders.js +16 -0
- package/dist/posts/helpers/index.js +2 -0
- package/dist/posts/mapping.d.ts +14 -0
- package/dist/posts/mapping.js +3 -0
- package/dist/posts/mutations.d.ts +9 -0
- package/dist/posts/mutations.js +84 -5
- package/dist/profiles/blocks.d.ts +11 -0
- package/dist/profiles/blocks.js +11 -0
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/mutations.js +1 -0
- package/dist/stats/mapping.d.ts +1 -0
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "4a5587e2-755d-42e0-a8e0-4940132dbb19",
|
|
3
|
-
"prevId": "
|
|
3
|
+
"prevId": "cbe40fa6-6a27-404d-82fd-48551e54d6d2",
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
6
6
|
"tables": {
|
|
@@ -899,6 +899,12 @@
|
|
|
899
899
|
"type": "timestamp with time zone",
|
|
900
900
|
"primaryKey": false,
|
|
901
901
|
"notNull": false
|
|
902
|
+
},
|
|
903
|
+
"published_at": {
|
|
904
|
+
"name": "published_at",
|
|
905
|
+
"type": "timestamp with time zone",
|
|
906
|
+
"primaryKey": false,
|
|
907
|
+
"notNull": false
|
|
902
908
|
}
|
|
903
909
|
},
|
|
904
910
|
"indexes": {
|
|
@@ -1050,6 +1056,27 @@
|
|
|
1050
1056
|
"concurrently": false,
|
|
1051
1057
|
"method": "btree",
|
|
1052
1058
|
"with": {}
|
|
1059
|
+
},
|
|
1060
|
+
"posts_creator_published_idx": {
|
|
1061
|
+
"name": "posts_creator_published_idx",
|
|
1062
|
+
"columns": [
|
|
1063
|
+
{
|
|
1064
|
+
"expression": "creator_id",
|
|
1065
|
+
"isExpression": false,
|
|
1066
|
+
"asc": true,
|
|
1067
|
+
"nulls": "last"
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
"expression": "published_at",
|
|
1071
|
+
"isExpression": false,
|
|
1072
|
+
"asc": true,
|
|
1073
|
+
"nulls": "last"
|
|
1074
|
+
}
|
|
1075
|
+
],
|
|
1076
|
+
"isUnique": false,
|
|
1077
|
+
"concurrently": false,
|
|
1078
|
+
"method": "btree",
|
|
1079
|
+
"with": {}
|
|
1053
1080
|
}
|
|
1054
1081
|
},
|
|
1055
1082
|
"foreignKeys": {},
|
|
@@ -4698,4 +4725,4 @@
|
|
|
4698
4725
|
"schemas": {},
|
|
4699
4726
|
"tables": {}
|
|
4700
4727
|
}
|
|
4701
|
-
}
|
|
4728
|
+
}
|
|
@@ -135,6 +135,13 @@
|
|
|
135
135
|
"tag": "0018_add_calendar_feed_tokens",
|
|
136
136
|
"breakpoints": true
|
|
137
137
|
},
|
|
138
|
+
{
|
|
139
|
+
"idx": 19,
|
|
140
|
+
"version": "7",
|
|
141
|
+
"when": 1795336252623,
|
|
142
|
+
"tag": "0019_posts_published_at",
|
|
143
|
+
"breakpoints": true
|
|
144
|
+
},
|
|
138
145
|
{
|
|
139
146
|
"idx": 22,
|
|
140
147
|
"version": "7",
|
|
@@ -143,4 +150,4 @@
|
|
|
143
150
|
"breakpoints": true
|
|
144
151
|
}
|
|
145
152
|
]
|
|
146
|
-
}
|
|
153
|
+
}
|
package/dist/events/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type CoreEvents = {
|
|
|
5
5
|
postCreated: (post: PostWithMeta) => void;
|
|
6
6
|
jamRecordingCompleted: (recording: JamRecordingWithMeta) => void;
|
|
7
7
|
followCreated: (follower: Profile, followed: Profile) => void;
|
|
8
|
+
/** Follow edge removed (unfollow). Federation reacts by sending Undo(Follow) for outbound follows only. */
|
|
9
|
+
followDeleted: (follower: Profile, followed: Profile) => void;
|
|
8
10
|
notificationCreated: (notification: Notification) => void;
|
|
9
11
|
reactionCreated: (profile: Profile, post: PostWithMeta, data: ReactionData) => void;
|
|
10
12
|
entryCreated: (profile: Profile, post: PostWithMeta, data: EntryData) => void;
|
package/dist/events/index.js
CHANGED
|
@@ -15,3 +15,28 @@ export declare const findApActivityByUri: (uri: string) => Promise<{
|
|
|
15
15
|
direction: string;
|
|
16
16
|
createdAt: string;
|
|
17
17
|
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The outbound Follow activity we currently have live for this (actor,
|
|
20
|
+
* object) pair, if any. `objectUri` is stored as the *target* actor URI for
|
|
21
|
+
* Follow rows (the followee), so this is the idempotency key for outbound
|
|
22
|
+
* follows and the "we followed them" marker for outbound Undos.
|
|
23
|
+
*
|
|
24
|
+
* The row's lifecycle mirrors the follow edge: it is written when we send a
|
|
25
|
+
* Follow and deleted when the edge goes away (`federateUnfollow` after the
|
|
26
|
+
* Undo), so a re-follow after an unfollow must re-send instead of being
|
|
27
|
+
* swallowed by a stale row (#241 review #1).
|
|
28
|
+
*/
|
|
29
|
+
export declare const findOutboundFollow: (actorUri: string, objectUri: string) => Promise<{
|
|
30
|
+
uri: string;
|
|
31
|
+
type: string;
|
|
32
|
+
actorUri: string;
|
|
33
|
+
objectUri: string | null;
|
|
34
|
+
direction: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Drop the recorded outbound Follow for this (actor, object) pair — the
|
|
39
|
+
* ledger half of a live unfollow, so the pair can be re-followed and re-sent
|
|
40
|
+
* (#241 review #1). Idempotent: deleting nothing is fine.
|
|
41
|
+
*/
|
|
42
|
+
export declare const deleteOutboundFollow: (actorUri: string, objectUri: string) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { eq } from 'drizzle-orm';
|
|
1
|
+
import { and, eq } from 'drizzle-orm';
|
|
2
2
|
import { pgDb } from '../db/pg/client.js';
|
|
3
3
|
import { apActivities } from '../db/pg/schema/documents.js';
|
|
4
4
|
export const recordApActivity = async (activity) => {
|
|
@@ -23,3 +23,33 @@ export const findApActivityByUri = async (uri) => {
|
|
|
23
23
|
.limit(1);
|
|
24
24
|
return row;
|
|
25
25
|
};
|
|
26
|
+
const outboundFollowWhere = (actorUri, objectUri) => and(eq(apActivities.type, 'Follow'), eq(apActivities.actorUri, actorUri), eq(apActivities.objectUri, objectUri), eq(apActivities.direction, 'out'));
|
|
27
|
+
/**
|
|
28
|
+
* The outbound Follow activity we currently have live for this (actor,
|
|
29
|
+
* object) pair, if any. `objectUri` is stored as the *target* actor URI for
|
|
30
|
+
* Follow rows (the followee), so this is the idempotency key for outbound
|
|
31
|
+
* follows and the "we followed them" marker for outbound Undos.
|
|
32
|
+
*
|
|
33
|
+
* The row's lifecycle mirrors the follow edge: it is written when we send a
|
|
34
|
+
* Follow and deleted when the edge goes away (`federateUnfollow` after the
|
|
35
|
+
* Undo), so a re-follow after an unfollow must re-send instead of being
|
|
36
|
+
* swallowed by a stale row (#241 review #1).
|
|
37
|
+
*/
|
|
38
|
+
export const findOutboundFollow = async (actorUri, objectUri) => {
|
|
39
|
+
const db = pgDb();
|
|
40
|
+
const [row] = await db
|
|
41
|
+
.select()
|
|
42
|
+
.from(apActivities)
|
|
43
|
+
.where(outboundFollowWhere(actorUri, objectUri))
|
|
44
|
+
.limit(1);
|
|
45
|
+
return row;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Drop the recorded outbound Follow for this (actor, object) pair — the
|
|
49
|
+
* ledger half of a live unfollow, so the pair can be re-followed and re-sent
|
|
50
|
+
* (#241 review #1). Idempotent: deleting nothing is fine.
|
|
51
|
+
*/
|
|
52
|
+
export const deleteOutboundFollow = async (actorUri, objectUri) => {
|
|
53
|
+
const db = pgDb();
|
|
54
|
+
await db.delete(apActivities).where(outboundFollowWhere(actorUri, objectUri));
|
|
55
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote-actor discovery for outbound follows (#241).
|
|
3
|
+
*
|
|
4
|
+
* Resolves a `user@domain` / `@user@domain` handle (via WebFinger) or an
|
|
5
|
+
* `https` actor URL into a `federated` profile row, so a local user can
|
|
6
|
+
* initiate a follow of an account that has never interacted with the
|
|
7
|
+
* instance. Pure `fetch`, no new dependency.
|
|
8
|
+
*/
|
|
9
|
+
import type { ProfileWithMeta } from '@openpeepshq/common/types';
|
|
10
|
+
import { type RemoteActorInput } from './actors';
|
|
11
|
+
/**
|
|
12
|
+
* Extract the first non-empty string from a value that may be a plain string
|
|
13
|
+
* or an ActivityStreams LanguageMap (`{ "en": "hi" }`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const asText: (value: unknown) => string | undefined;
|
|
16
|
+
/** Coerce to an `http(s)` URL, or `undefined` if it isn't one. */
|
|
17
|
+
export declare const asHttpUrl: (value: string | null | undefined) => URL | undefined;
|
|
18
|
+
type ParsedQuery = {
|
|
19
|
+
kind: 'handle';
|
|
20
|
+
user: string;
|
|
21
|
+
domain: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'url';
|
|
24
|
+
url: string;
|
|
25
|
+
} | null;
|
|
26
|
+
/**
|
|
27
|
+
* Split a discovery query. Accepts `user@domain`, `@user@domain`, or an
|
|
28
|
+
* `http(s)` actor URL. Returns `null` when nothing sensible can be parsed.
|
|
29
|
+
*/
|
|
30
|
+
export declare const parseRemoteAccountQuery: (query: string) => ParsedQuery;
|
|
31
|
+
type ActorDoc = {
|
|
32
|
+
id?: string;
|
|
33
|
+
preferredUsername?: unknown;
|
|
34
|
+
name?: unknown;
|
|
35
|
+
summary?: unknown;
|
|
36
|
+
inbox?: unknown;
|
|
37
|
+
endpoints?: {
|
|
38
|
+
sharedInbox?: unknown;
|
|
39
|
+
};
|
|
40
|
+
publicKey?: {
|
|
41
|
+
id?: unknown;
|
|
42
|
+
owner?: unknown;
|
|
43
|
+
publicKeyPem?: unknown;
|
|
44
|
+
};
|
|
45
|
+
icon?: {
|
|
46
|
+
url?: unknown;
|
|
47
|
+
} | {
|
|
48
|
+
url?: unknown;
|
|
49
|
+
}[];
|
|
50
|
+
image?: {
|
|
51
|
+
url?: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
url?: unknown;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Map a raw ActivityStreams actor document onto the `RemoteActorInput` shape
|
|
58
|
+
* consumed by {@link upsertRemoteActor}. Pure — no I/O.
|
|
59
|
+
*/
|
|
60
|
+
export declare const actorDocToRemoteInput: (doc: ActorDoc) => RemoteActorInput | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve `query` to a `federated` profile, upserting the remote actor if it
|
|
63
|
+
* isn't already known. Returns `undefined` when the host is not on the
|
|
64
|
+
* allowlist, WebFinger finds no `self` link, the actor can't be resolved, or
|
|
65
|
+
* the actor has no inbox (unfederatable) — the caller maps this to a 404.
|
|
66
|
+
* Network/timeout/redirect failures propagate so the caller can surface them
|
|
67
|
+
* as a 5xx.
|
|
68
|
+
*/
|
|
69
|
+
export declare const resolveRemoteAccount: (query: string) => Promise<ProfileWithMeta | undefined>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { config } from '../config/index.js';
|
|
2
|
+
import { federatedHandleFrom, upsertRemoteActor, } from './actors.js';
|
|
3
|
+
import { peerHostAllowed } from './peers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Extract the first non-empty string from a value that may be a plain string
|
|
6
|
+
* or an ActivityStreams LanguageMap (`{ "en": "hi" }`).
|
|
7
|
+
*/
|
|
8
|
+
export const asText = (value) => {
|
|
9
|
+
if (value == null)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (typeof value === 'string')
|
|
12
|
+
return value.length > 0 ? value : undefined;
|
|
13
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
14
|
+
for (const entry of Object.values(value)) {
|
|
15
|
+
if (typeof entry === 'string' && entry.length > 0)
|
|
16
|
+
return entry;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const text = String(value);
|
|
21
|
+
return text.length > 0 ? text : undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Coerce to an `http(s)` URL, or `undefined` if it isn't one. */
|
|
24
|
+
export const asHttpUrl = (value) => {
|
|
25
|
+
if (!value)
|
|
26
|
+
return undefined;
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(value);
|
|
29
|
+
return url.protocol === 'http:' || url.protocol === 'https:'
|
|
30
|
+
? url
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Split a discovery query. Accepts `user@domain`, `@user@domain`, or an
|
|
39
|
+
* `http(s)` actor URL. Returns `null` when nothing sensible can be parsed.
|
|
40
|
+
*/
|
|
41
|
+
export const parseRemoteAccountQuery = (query) => {
|
|
42
|
+
const trimmed = query.trim();
|
|
43
|
+
if (!trimmed)
|
|
44
|
+
return null;
|
|
45
|
+
const httpUrl = asHttpUrl(trimmed);
|
|
46
|
+
if (httpUrl)
|
|
47
|
+
return { kind: 'url', url: httpUrl.href };
|
|
48
|
+
const bare = trimmed.replace(/^@/, '');
|
|
49
|
+
const at = bare.lastIndexOf('@');
|
|
50
|
+
if (at <= 0 || at === bare.length - 1)
|
|
51
|
+
return null;
|
|
52
|
+
const user = bare.slice(0, at).trim();
|
|
53
|
+
const domain = bare
|
|
54
|
+
.slice(at + 1)
|
|
55
|
+
.trim()
|
|
56
|
+
.toLowerCase()
|
|
57
|
+
.replace(/\.$/, '');
|
|
58
|
+
if (!user || !domain)
|
|
59
|
+
return null;
|
|
60
|
+
return { kind: 'handle', user, domain };
|
|
61
|
+
};
|
|
62
|
+
const firstImageUrl = (icon) => {
|
|
63
|
+
if (!icon)
|
|
64
|
+
return undefined;
|
|
65
|
+
const list = Array.isArray(icon) ? icon : [icon];
|
|
66
|
+
for (const entry of list) {
|
|
67
|
+
const url = asHttpUrl(asText(entry?.url));
|
|
68
|
+
if (url)
|
|
69
|
+
return url.href;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Map a raw ActivityStreams actor document onto the `RemoteActorInput` shape
|
|
75
|
+
* consumed by {@link upsertRemoteActor}. Pure — no I/O.
|
|
76
|
+
*/
|
|
77
|
+
export const actorDocToRemoteInput = (doc) => {
|
|
78
|
+
const uri = asHttpUrl(asText(doc.id));
|
|
79
|
+
if (!uri)
|
|
80
|
+
return undefined;
|
|
81
|
+
return {
|
|
82
|
+
uri: uri.href,
|
|
83
|
+
handle: federatedHandleFrom(asText(doc.preferredUsername), uri.href),
|
|
84
|
+
domain: uri.hostname.toLowerCase().replace(/\.$/, ''),
|
|
85
|
+
inboxUrl: asText(doc.inbox) ?? null,
|
|
86
|
+
sharedInboxUrl: asText(doc.endpoints?.sharedInbox) ?? null,
|
|
87
|
+
publicKeyPem: asText(doc.publicKey?.publicKeyPem) ?? null,
|
|
88
|
+
displayName: asText(doc.name),
|
|
89
|
+
bio: asText(doc.summary),
|
|
90
|
+
avatar: firstImageUrl(doc.icon ?? doc.image) ?? null,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const requestTimeout = async () => (await config()).activityPub.federation.requestTimeout;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve `query` to a `federated` profile, upserting the remote actor if it
|
|
96
|
+
* isn't already known. Returns `undefined` when the host is not on the
|
|
97
|
+
* allowlist, WebFinger finds no `self` link, the actor can't be resolved, or
|
|
98
|
+
* the actor has no inbox (unfederatable) — the caller maps this to a 404.
|
|
99
|
+
* Network/timeout/redirect failures propagate so the caller can surface them
|
|
100
|
+
* as a 5xx.
|
|
101
|
+
*/
|
|
102
|
+
export const resolveRemoteAccount = async (query) => {
|
|
103
|
+
const parsed = parseRemoteAccountQuery(query);
|
|
104
|
+
if (!parsed)
|
|
105
|
+
return undefined;
|
|
106
|
+
let actorUrl;
|
|
107
|
+
if (parsed.kind === 'handle') {
|
|
108
|
+
const { user, domain } = parsed;
|
|
109
|
+
// Gate on a URL, not the bare domain: `peerHostAllowed` resolves the
|
|
110
|
+
// host via `hostnameOf` (`new URL`), which throws on a scheme-less
|
|
111
|
+
// string and would deny every allowlisted host (review #1).
|
|
112
|
+
if (!(await peerHostAllowed(new URL(`https://${domain}/`))))
|
|
113
|
+
return undefined;
|
|
114
|
+
const timeoutMs = await requestTimeout();
|
|
115
|
+
const webfingerUrl = `https://${domain}/.well-known/webfinger?resource=acct:${user}@${domain}`;
|
|
116
|
+
const webfinger = await fetch(webfingerUrl, {
|
|
117
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
118
|
+
// No redirect-following: a 302 away from the allowlisted host (e.g. to
|
|
119
|
+
// an internal address) must not bypass `peerHostAllowed` mid-flight
|
|
120
|
+
// (#241 review #5). Redirects throw and surface as a 5xx.
|
|
121
|
+
redirect: 'error',
|
|
122
|
+
});
|
|
123
|
+
if (!webfinger.ok)
|
|
124
|
+
return undefined;
|
|
125
|
+
const body = (await webfinger.json());
|
|
126
|
+
const selfLink = body.links?.find((link) => link.rel === 'self' && link.type === 'application/activity+json');
|
|
127
|
+
actorUrl = asHttpUrl(selfLink?.href);
|
|
128
|
+
if (!actorUrl)
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
actorUrl = new URL(parsed.url);
|
|
133
|
+
}
|
|
134
|
+
// Pass the URL itself, not `hostnameOf(actorUrl)`: `peerHostAllowed`
|
|
135
|
+
// re-runs `hostnameOf` internally, and a bare hostname string would be
|
|
136
|
+
// rejected again (review #1).
|
|
137
|
+
if (!(await peerHostAllowed(actorUrl)))
|
|
138
|
+
return undefined;
|
|
139
|
+
const timeoutMs = await requestTimeout();
|
|
140
|
+
const actorRes = await fetch(actorUrl.href, {
|
|
141
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
142
|
+
headers: { Accept: 'application/activity+json, application/ld+json' },
|
|
143
|
+
redirect: 'error',
|
|
144
|
+
});
|
|
145
|
+
if (!actorRes.ok)
|
|
146
|
+
return undefined;
|
|
147
|
+
const doc = (await actorRes.json());
|
|
148
|
+
const input = actorDocToRemoteInput(doc);
|
|
149
|
+
// An actor without an inbox can't receive the outbound Follow, so following
|
|
150
|
+
// it would federate nothing. Treat it as unresolvable (404) rather than
|
|
151
|
+
// upserting a profile row that can never be federated to (#241 review #6).
|
|
152
|
+
if (!input || !input.inboxUrl)
|
|
153
|
+
return undefined;
|
|
154
|
+
return upsertRemoteActor(input);
|
|
155
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { findApActivityByUri, recordApActivity } from './activities';
|
|
1
|
+
export { deleteOutboundFollow, findApActivityByUri, findOutboundFollow, recordApActivity, } from './activities';
|
|
2
2
|
export type { ApActivity, ApActivityDirection } from './activities';
|
|
3
3
|
export { federatedHandleFrom, findLocalActorIdByHandle, loadLocalActor, loadLocalActorKeys, upsertRemoteActor, } from './actors';
|
|
4
4
|
export type { LocalActor, LocalActorKeys, RemoteActorInput } from './actors';
|
|
@@ -9,3 +9,4 @@ export { loadPublicNote } from './notes';
|
|
|
9
9
|
export type { PublicNote } from './notes';
|
|
10
10
|
export { federationIsActive, hostnameOf, peerHostAllowed } from './peers';
|
|
11
11
|
export { findProfileByHandleAndDomain, findProfileByUri } from './profiles';
|
|
12
|
+
export { actorDocToRemoteInput, asHttpUrl, asText, parseRemoteAccountQuery, resolveRemoteAccount, } from './discovery';
|
package/dist/federation/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { findApActivityByUri, recordApActivity } from './activities.js';
|
|
1
|
+
export { deleteOutboundFollow, findApActivityByUri, findOutboundFollow, recordApActivity, } from './activities.js';
|
|
2
2
|
export { federatedHandleFrom, findLocalActorIdByHandle, loadLocalActor, loadLocalActorKeys, upsertRemoteActor, } from './actors.js';
|
|
3
3
|
export { ACCEPT_PATH, ACTOR_INBOX_PATH, ACTOR_PATH, CREATE_PATH, FOLLOWERS_PATH, NOTE_PATH, SHARED_INBOX_PATH, acceptActivityUri, actorUri, backfillLocalFederationIdentities, createActivityUri, federationOrigin, generateActorKeyPair, localActorScalars, localObjectScalars, objectUri, } from './identity.js';
|
|
4
4
|
export { ingestIncomingFollow, ingestIncomingUnfollow, listFederatedFollowerRecipients, withoutBlockedRecipients, } from './ingest.js';
|
|
5
5
|
export { loadPublicNote } from './notes.js';
|
|
6
6
|
export { federationIsActive, hostnameOf, peerHostAllowed } from './peers.js';
|
|
7
7
|
export { findProfileByHandleAndDomain, findProfileByUri } from './profiles.js';
|
|
8
|
+
export { actorDocToRemoteInput, asHttpUrl, asText, parseRemoteAccountQuery, resolveRemoteAccount, } from './discovery.js';
|
package/dist/federation/notes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { and, eq, isNull } from 'drizzle-orm';
|
|
1
|
+
import { and, eq, isNotNull, isNull } from 'drizzle-orm';
|
|
2
2
|
import { pgDb } from '../db/pg/client.js';
|
|
3
3
|
import { posts } from '../db/pg/schema/documents.js';
|
|
4
4
|
export const loadPublicNote = async (postId) => {
|
|
@@ -15,7 +15,7 @@ export const loadPublicNote = async (postId) => {
|
|
|
15
15
|
deletedAt: posts.deletedAt,
|
|
16
16
|
})
|
|
17
17
|
.from(posts)
|
|
18
|
-
.where(and(eq(posts.id, postId), isNull(posts.deletedAt)))
|
|
18
|
+
.where(and(eq(posts.id, postId), isNull(posts.deletedAt), isNotNull(posts.publishedAt)))
|
|
19
19
|
.limit(1);
|
|
20
20
|
if (!row || row.type !== 'note' || row.visibility !== 'public')
|
|
21
21
|
return null;
|
package/dist/posts/finders.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export declare const findPost: (id: string, authData?: AuthorizationData) => Pro
|
|
|
13
13
|
* an unscoped profile-scoped lookup (matches any creator).
|
|
14
14
|
*/
|
|
15
15
|
export declare const findPostBySlug: (slug: string, profileHandle?: string, instanceScoped?: boolean) => Promise<PostWithMeta | null>;
|
|
16
|
+
/** The author's unpublished drafts, most-recently-edited first. */
|
|
17
|
+
export declare const listMyDrafts: (profile: ProfileWithMeta, options?: {
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
}) => Promise<PostWithMeta[]>;
|
|
16
21
|
/** Lean post load for capability checks (no nested reply/repost). */
|
|
17
22
|
export declare const findPostsForAuth: (ids: string[], authData?: AuthorizationData) => Promise<PostWithMeta[]>;
|
|
18
23
|
export declare const postContext: (authData: AuthorizationData, id: string, depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => Promise<PostWithMeta[]>;
|
|
@@ -269,6 +274,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
|
|
|
269
274
|
categoryPath?: string[] | undefined;
|
|
270
275
|
url?: string | undefined;
|
|
271
276
|
} | undefined;
|
|
277
|
+
publishedAt?: string | null | undefined;
|
|
272
278
|
}, DbPost, DbPost>;
|
|
273
279
|
export declare const listPosts: (authData: AuthorizationData, { start, limit, filter, }?: {
|
|
274
280
|
start?: string;
|
package/dist/posts/finders.js
CHANGED
|
@@ -91,6 +91,22 @@ export const findPostBySlug = async (slug, profileHandle, instanceScoped) => {
|
|
|
91
91
|
const post = await transformPost(row);
|
|
92
92
|
return hideBlockedAuthorPost(post, undefined) ?? null;
|
|
93
93
|
};
|
|
94
|
+
/** The author's unpublished drafts, most-recently-edited first. */
|
|
95
|
+
export const listMyDrafts = async (profile, options = {}) => {
|
|
96
|
+
const { limit = 100, offset = 0 } = options;
|
|
97
|
+
const mapping = postsMappingForProfile(profile)
|
|
98
|
+
.removeDefaultFilter()
|
|
99
|
+
.filter(postFilters.drafts())
|
|
100
|
+
.filter(postFilters.creatorId(profile.id))
|
|
101
|
+
// "Newest" = most-recently-edited (updatedAt, not createdAt), so a draft
|
|
102
|
+
// bubbles to the top after an edit — matching how the feed orders posts.
|
|
103
|
+
.sort(sorts.updatedAtDesc);
|
|
104
|
+
return toFilteredPostsList(mapping, {
|
|
105
|
+
authData: { profile, scopes: [] },
|
|
106
|
+
limit,
|
|
107
|
+
offset,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
94
110
|
/** Lean post load for capability checks (no nested reply/repost). */
|
|
95
111
|
export const findPostsForAuth = async (ids, authData) => {
|
|
96
112
|
if (ids.length === 0)
|
|
@@ -126,6 +126,8 @@ export const transformPost = async (post, currentProfile, options = {}) => {
|
|
|
126
126
|
const latestReplies = (await Promise.all(preview.replies.map((reply) => transformPost(reply, currentProfile, nested)))).filter((reply) => !!reply.profile);
|
|
127
127
|
return {
|
|
128
128
|
...post,
|
|
129
|
+
publishedAt: post.publishedAt ?? undefined,
|
|
130
|
+
isDraft: post.publishedAt == null,
|
|
129
131
|
data: post.data ? normalizePostDataFromDb(post.data) : post.data,
|
|
130
132
|
seen: currentProfile ? post.seen : undefined,
|
|
131
133
|
replyTo: post.replyTo
|
package/dist/posts/mapping.d.ts
CHANGED
|
@@ -249,6 +249,7 @@ export declare const threadPreviewMappingForProfile: (profile?: {
|
|
|
249
249
|
categoryPath?: string[] | undefined;
|
|
250
250
|
url?: string | undefined;
|
|
251
251
|
} | undefined;
|
|
252
|
+
publishedAt?: string | null | undefined;
|
|
252
253
|
}, DbPost, DbPost>;
|
|
253
254
|
export declare const repostRelation: RelationWithMapping<DbBasePost>;
|
|
254
255
|
export declare const repostRelationForProfile: (profile?: {
|
|
@@ -499,6 +500,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
499
500
|
categoryPath?: string[] | undefined;
|
|
500
501
|
url?: string | undefined;
|
|
501
502
|
} | undefined;
|
|
503
|
+
publishedAt?: string | null | undefined;
|
|
502
504
|
}, {
|
|
503
505
|
createdAt: string;
|
|
504
506
|
updatedAt: string;
|
|
@@ -744,6 +746,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
744
746
|
categoryPath?: string[] | undefined;
|
|
745
747
|
url?: string | undefined;
|
|
746
748
|
} | undefined;
|
|
749
|
+
publishedAt?: string | null | undefined;
|
|
747
750
|
} & {
|
|
748
751
|
id: string;
|
|
749
752
|
} & {
|
|
@@ -993,6 +996,7 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
993
996
|
categoryPath?: string[] | undefined;
|
|
994
997
|
url?: string | undefined;
|
|
995
998
|
} | undefined;
|
|
999
|
+
publishedAt?: string | null | undefined;
|
|
996
1000
|
} & {
|
|
997
1001
|
id: string;
|
|
998
1002
|
} & {
|
|
@@ -1239,6 +1243,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1239
1243
|
categoryPath?: string[] | undefined;
|
|
1240
1244
|
url?: string | undefined;
|
|
1241
1245
|
} | undefined;
|
|
1246
|
+
publishedAt?: string | null | undefined;
|
|
1242
1247
|
}, {
|
|
1243
1248
|
createdAt: string;
|
|
1244
1249
|
updatedAt: string;
|
|
@@ -1484,6 +1489,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1484
1489
|
categoryPath?: string[] | undefined;
|
|
1485
1490
|
url?: string | undefined;
|
|
1486
1491
|
} | undefined;
|
|
1492
|
+
publishedAt?: string | null | undefined;
|
|
1487
1493
|
} & {
|
|
1488
1494
|
id: string;
|
|
1489
1495
|
} & {
|
|
@@ -1733,6 +1739,7 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1733
1739
|
categoryPath?: string[] | undefined;
|
|
1734
1740
|
url?: string | undefined;
|
|
1735
1741
|
} | undefined;
|
|
1742
|
+
publishedAt?: string | null | undefined;
|
|
1736
1743
|
} & {
|
|
1737
1744
|
id: string;
|
|
1738
1745
|
} & {
|
|
@@ -1979,6 +1986,7 @@ export declare const postsMapping: Mapping<{
|
|
|
1979
1986
|
categoryPath?: string[] | undefined;
|
|
1980
1987
|
url?: string | undefined;
|
|
1981
1988
|
} | undefined;
|
|
1989
|
+
publishedAt?: string | null | undefined;
|
|
1982
1990
|
}, DbPost, DbPost>;
|
|
1983
1991
|
/** Auth / mark-seen: post graph without nested replyTo/repost hydrate. */
|
|
1984
1992
|
export declare const postsAuthMapping: Mapping<{
|
|
@@ -2222,6 +2230,7 @@ export declare const postsAuthMapping: Mapping<{
|
|
|
2222
2230
|
categoryPath?: string[] | undefined;
|
|
2223
2231
|
url?: string | undefined;
|
|
2224
2232
|
} | undefined;
|
|
2233
|
+
publishedAt?: string | null | undefined;
|
|
2225
2234
|
}, DbPost, DbPost>;
|
|
2226
2235
|
export declare const postsMappingForProfile: (profile?: {
|
|
2227
2236
|
id: string;
|
|
@@ -2466,6 +2475,7 @@ export declare const postsMappingForProfile: (profile?: {
|
|
|
2466
2475
|
categoryPath?: string[] | undefined;
|
|
2467
2476
|
url?: string | undefined;
|
|
2468
2477
|
} | undefined;
|
|
2478
|
+
publishedAt?: string | null | undefined;
|
|
2469
2479
|
}, DbPost, DbPost>;
|
|
2470
2480
|
export declare const postContextMappingForProfile: (profile?: {
|
|
2471
2481
|
id: string;
|
|
@@ -2710,6 +2720,7 @@ export declare const postContextMappingForProfile: (profile?: {
|
|
|
2710
2720
|
categoryPath?: string[] | undefined;
|
|
2711
2721
|
url?: string | undefined;
|
|
2712
2722
|
} | undefined;
|
|
2723
|
+
publishedAt?: string | null | undefined;
|
|
2713
2724
|
}, DbPost, DbPost>;
|
|
2714
2725
|
export declare const contextRelation: (depth: number, direction: "ancestors" | "descendents", contextMapping?: Mapping<DbPost>) => RelationWithMapping<DbPost>;
|
|
2715
2726
|
export declare const conversationLeavesMapping: Mapping<{
|
|
@@ -2953,6 +2964,7 @@ export declare const conversationLeavesMapping: Mapping<{
|
|
|
2953
2964
|
categoryPath?: string[] | undefined;
|
|
2954
2965
|
url?: string | undefined;
|
|
2955
2966
|
} | undefined;
|
|
2967
|
+
publishedAt?: string | null | undefined;
|
|
2956
2968
|
}, DbPost, DbPost>;
|
|
2957
2969
|
export declare const conversationLeavesMappingForProfile: (profile?: {
|
|
2958
2970
|
id: string;
|
|
@@ -3197,6 +3209,7 @@ export declare const conversationLeavesMappingForProfile: (profile?: {
|
|
|
3197
3209
|
categoryPath?: string[] | undefined;
|
|
3198
3210
|
url?: string | undefined;
|
|
3199
3211
|
} | undefined;
|
|
3212
|
+
publishedAt?: string | null | undefined;
|
|
3200
3213
|
}, DbPost, DbPost>;
|
|
3201
3214
|
export declare const postIdsMapping: Mapping<{
|
|
3202
3215
|
type: "resource" | "note" | "question" | "event" | "article";
|
|
@@ -3439,6 +3452,7 @@ export declare const postIdsMapping: Mapping<{
|
|
|
3439
3452
|
categoryPath?: string[] | undefined;
|
|
3440
3453
|
url?: string | undefined;
|
|
3441
3454
|
} | undefined;
|
|
3455
|
+
publishedAt?: string | null | undefined;
|
|
3442
3456
|
}, {
|
|
3443
3457
|
id: string;
|
|
3444
3458
|
}, {
|
package/dist/posts/mapping.js
CHANGED
|
@@ -113,6 +113,9 @@ const basePostFilterRelations = [
|
|
|
113
113
|
const preFilterMapData = {
|
|
114
114
|
collection: 'posts',
|
|
115
115
|
softDelete: true,
|
|
116
|
+
// Drafts (unpublished) are excluded from every shared post query by default.
|
|
117
|
+
// The drafts finder opts out via `removeDefaultFilter()`.
|
|
118
|
+
defaultFilter: postFilters.published(),
|
|
116
119
|
};
|
|
117
120
|
const basePostMapData = {
|
|
118
121
|
...preFilterMapData,
|
|
@@ -7,7 +7,16 @@ export declare const createPost: (data: PostDataUnion, profile: Profile & {
|
|
|
7
7
|
repostId?: string;
|
|
8
8
|
audience?: Profile[] | null;
|
|
9
9
|
groupId?: string | null;
|
|
10
|
+
draft?: boolean;
|
|
10
11
|
}) => Promise<PostWithMeta>;
|
|
12
|
+
/**
|
|
13
|
+
* Publishes a draft post. Validates that the caller is the author and that
|
|
14
|
+
* the post is still unpublished (422 if already published, 403 otherwise);
|
|
15
|
+
* sets `published_at` and fires the shared publish-time side effects once.
|
|
16
|
+
* The intended-visibility re-check (Q4) lives in the UI's publish guard,
|
|
17
|
+
* not here.
|
|
18
|
+
*/
|
|
19
|
+
export declare const publishPost: (post: PostWithMeta, profile: Profile) => Promise<PostWithMeta>;
|
|
11
20
|
export declare const updatePost: (post: PostWithMeta, profile: Profile & {
|
|
12
21
|
roles?: Role[];
|
|
13
22
|
}, data: PostDataUnion) => Promise<PostWithMeta>;
|