@drfed/graphql 0.2.0-dev.639 → 0.2.0-dev.651
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/README.md +16 -98
- package/dist/{actor-BJvviz6Q.mjs → actor-B1FAD_C_.mjs} +2 -4
- package/dist/actor-B1FAD_C_.mjs.map +1 -0
- package/dist/actor.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/object.d.mts.map +1 -1
- package/dist/object.mjs +4 -2
- package/dist/object.mjs.map +1 -1
- package/dist/{schema-ZeV-COPn.mjs → schema-f-SnZVb9.mjs} +2 -2
- package/dist/{schema-ZeV-COPn.mjs.map → schema-f-SnZVb9.mjs.map} +1 -1
- package/dist/schema.mjs +1 -1
- package/package.json +8 -8
- package/dist/actor-BJvviz6Q.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -90,16 +90,8 @@ A failed mail receipt or a provider exception keeps this response unchanged;
|
|
|
90
90
|
operators receive a fixed outcome diagnostic without provider error text or
|
|
91
91
|
message IDs. Users can request another link if mail does not arrive.
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
options. `trackOperation` keeps resolver work registered until the provider
|
|
96
|
-
settles, including a provider that ignores cancellation after the HTTP response
|
|
97
|
-
ends. The runtime owner must drain these operations before closing resources;
|
|
98
|
-
passing a signal alone does not guarantee that a transport stops.
|
|
99
|
-
See [Yoga execution cancellation] for the distinction between canceling an
|
|
100
|
-
HTTP response and stopping resolver work.
|
|
101
|
-
|
|
102
|
-
[Yoga execution cancellation]: https://the-guild.dev/graphql/yoga-server/docs/features/execution-cancellation
|
|
93
|
+
For shutdown integration when embedding Yoga, see
|
|
94
|
+
[runtime ownership](#runtime-ownership).
|
|
103
95
|
|
|
104
96
|
|
|
105
97
|
Activity deliveries
|
|
@@ -125,91 +117,18 @@ one activity's deliveries span instances, `Activity.deliveries` leaves out,
|
|
|
125
117
|
before paging, those of instances the viewer may not read, rather than failing
|
|
126
118
|
on them.
|
|
127
119
|
|
|
128
|
-
Wrap the federation HTTP surface with `createInboundRecorder` from
|
|
129
|
-
[`@drfed/federation`], passing a federation made by `createFederation` from
|
|
130
|
-
the same package and the root origin. Every inbox `POST`
|
|
131
|
-
is recorded, whether or not its body is JSON; recording errors never replace
|
|
132
|
-
federation responses. A request Fedify throws on is recorded too, with the
|
|
133
|
-
exception in `error` and no `statusCode`, and the exception is thrown again.
|
|
134
|
-
An inbound delivery keeps:
|
|
135
|
-
|
|
136
|
-
- The request as received: `rawBody` (or `rawBodyBase64` when the body is not
|
|
137
|
-
valid UTF-8), `requestHeaders`, and `requestUrl`. `payload` is the body
|
|
138
|
-
parsed as JSON for querying, and is `null` when it does not parse or
|
|
139
|
-
holds U+0000 or an unpaired surrogate, which PostgreSQL cannot store.
|
|
140
|
-
`cookie` headers are dropped, and `authorization` is kept only for the
|
|
141
|
-
`Signature` scheme.
|
|
142
|
-
- `inboxUrl`, the canonical IRI of the inbox, however the request spelled its
|
|
143
|
-
host or scheme.
|
|
144
|
-
- `verificationMechanism` and `verificationResult` summarize Fedify's
|
|
145
|
-
`onRequestFinished()` report, independently of OpenTelemetry sampling.
|
|
146
|
-
DrFed verifies nothing again. The result is `unattempted` when no
|
|
147
|
-
signature check ran before a preparation or parsing failure, and
|
|
148
|
-
`unobserved` when the report is missing or observation fails.
|
|
149
|
-
- The report can contain several attempts and keys; the delivery retains
|
|
150
|
-
one representative check. Root activity evaluations take precedence over
|
|
151
|
-
embedded portable objects. An authenticating attempt wins, followed by
|
|
152
|
-
the last cryptographically successful evaluation, including an attribution
|
|
153
|
-
refusal, then the last meaningful failed evaluation. A partly invalid
|
|
154
|
-
proof set remains `invalid_signature` or `key_fetch_error`.
|
|
155
|
-
- `key_fetch_error` comes from an explicit fetch failure. `error` includes
|
|
156
|
-
`keyFetchError:` and the HTTP status or the original error's name and
|
|
157
|
-
message, including for cached failures. A document with no usable key
|
|
158
|
-
that Fedify reports as `invalidSignature` is `invalid_signature`.
|
|
159
|
-
- A valid signature or proof can still fail authentication. Linked Data
|
|
160
|
-
Signatures with the wrong owner and Object Integrity Proofs with uncovered
|
|
161
|
-
attributions remain `verified` with `status` `rejected`. `error` records
|
|
162
|
-
Fedify's attribution, ownership, nonce or proof-policy reason. Other
|
|
163
|
-
refusals and processing failures use the completion report's reason;
|
|
164
|
-
exceptions retain the original thrown value's description.
|
|
165
|
-
- `verificationKey` is the actual successful key of the selected check, or
|
|
166
|
-
its last tried key on failure, including when refreshing a cached key
|
|
167
|
-
fails. Its history uses the key snapshot's ID, falling back to a valid
|
|
168
|
-
declared key ID when the snapshot has none. `signedKeyIri` is the HTTP
|
|
169
|
-
signature's declaration, preferring the successful check when several
|
|
170
|
-
HTTP signatures were evaluated. It may differ from the history ID or
|
|
171
|
-
refer to a mechanism that did not authenticate the request. Malformed
|
|
172
|
-
declarations remain in the raw request.
|
|
173
|
-
- `status`, which follows the response Fedify gave: `received` when the inbox
|
|
174
|
-
listener ran, `acknowledged` when the request was answered 2xx without it
|
|
175
|
-
(a duplicate, for instance), `rejected` when a verified activity was
|
|
176
|
-
refused or its handling threw, and `unverified` otherwise. With an inbox
|
|
177
|
-
queue, a delivery is
|
|
178
|
-
`acknowledged` when the request is answered and becomes `received` once the
|
|
179
|
-
queue worker runs the listener; the queued message carries its delivery ID.
|
|
180
|
-
|
|
181
120
|
`KeyVersion.firstSeen` and `lastSeen` are DrFed observation times, not remote
|
|
182
121
|
rotation times or evidence of continuous use. `Key` and `KeyVersion` hold
|
|
183
122
|
public material only and are readable by any authenticated viewer.
|
|
184
123
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
inbox
|
|
193
|
-
`diagnostics_channel`, and the causes of network errors. When the inbox
|
|
194
|
-
redirects a delivery, the status is the one the redirects ended with, whether
|
|
195
|
-
Fedify followed them, as it does when it signs the request, or `fetch()` did.
|
|
196
|
-
With a message queue, `createFederation` observes Fedify's outbox worker, and
|
|
197
|
-
each queued message carries the delivery it belongs to. A delivery becomes
|
|
198
|
-
`sent` when Fedify reports `activitypub.activity.sent` for its inbox, stays
|
|
199
|
-
`failed` while it is retried, and ends `permanently_failed`, or `abandoned`
|
|
200
|
-
when Fedify measures it abandoned after its retries ran out. A delivery Fedify
|
|
201
|
-
returns from without sending to the inbox, or without enqueuing a message to
|
|
202
|
-
it, is `permanently_failed` with no attempt, since Fedify makes none. The
|
|
203
|
-
queue is handed to Fedify as one without native retries, so that every retry
|
|
204
|
-
follows Fedify's policy and is recorded. Activity resource persistence (#88),
|
|
205
|
-
retention policies, and the activity-log UI (#13) are separate.
|
|
206
|
-
|
|
207
|
-
URL fields hold only values that parse as URLs, and no text field holds
|
|
208
|
-
U+0000; anything else a remote server sent stays in `rawBody` and
|
|
209
|
-
`requestHeaders`, and in `payload` when PostgreSQL can store it. `error` and
|
|
210
|
-
`responseBody` keep what a remote server answered with U+FFFD for each U+0000.
|
|
211
|
-
Deliveries are ordered by `created`, which for an inbound delivery is when the
|
|
212
|
-
request arrived; `completed` is when DrFed answered it.
|
|
124
|
+
Recording requires the federation recorder and outbound delivery wrapper. See
|
|
125
|
+
[activity delivery internals] for the raw request fields,
|
|
126
|
+
verification and status semantics, key observations, and queued delivery
|
|
127
|
+
attempts. The [inbox persistence internals]
|
|
128
|
+
explain how accepted deliveries acquire stored resources.
|
|
129
|
+
|
|
130
|
+
[activity delivery internals]: https://drfed.org/internals/activity-deliveries
|
|
131
|
+
[inbox persistence internals]: https://drfed.org/internals/inbox-persistence
|
|
213
132
|
|
|
214
133
|
|
|
215
134
|
Moved exports
|
|
@@ -245,11 +164,10 @@ for users who need the schema from their installed version.
|
|
|
245
164
|
Runtime ownership
|
|
246
165
|
-----------------
|
|
247
166
|
|
|
248
|
-
`createYogaServer()
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
callers that omit the callback retain the existing behavior.
|
|
167
|
+
When embedding `createYogaServer()`, pass `shutdownSignal` and `trackOperation`
|
|
168
|
+
if the runtime closes database or mail resources on shutdown. Cancellation
|
|
169
|
+
alone does not mean resolver work has stopped. See [runtime lifecycle internals]
|
|
170
|
+
for context loading, resolver tracking, the callback contract and draining
|
|
171
|
+
order.
|
|
254
172
|
|
|
255
|
-
[
|
|
173
|
+
[runtime lifecycle internals]: https://drfed.org/internals/runtime-lifecycle
|
|
@@ -64,9 +64,7 @@ async function resolveResource(viewer, row) {
|
|
|
64
64
|
}) == null) return null;
|
|
65
65
|
if (row.kind === "unknown") return null;
|
|
66
66
|
const where = { id: row.id };
|
|
67
|
-
|
|
68
|
-
if (result == null) throw new Error(`Missing ${row.kind} record for ${row.iri}.`);
|
|
69
|
-
return result;
|
|
67
|
+
return (row.kind === "actor" ? await db.query.actors.findFirst({ where }) : row.kind === "object" ? await db.query.objects.findFirst({ where }) : row.kind === "activity" ? await db.query.activities.findFirst({ where }) : await db.query.collections.findFirst({ where })) ?? null;
|
|
70
68
|
}
|
|
71
69
|
function registerAddressingFields(table) {
|
|
72
70
|
for (const property of schema.addressingPropertyEnum.enumValues) builder.drizzleObjectField(table, property, (t) => t.field({
|
|
@@ -597,4 +595,4 @@ builder.drizzleObjectField("instances", "actors", (t) => t.connection({
|
|
|
597
595
|
//#endregion
|
|
598
596
|
export { ResourceDetail as a, ActivityType as i, LocalActor as n, registerAddressingFields as o, Activity as r, Actor as t };
|
|
599
597
|
|
|
600
|
-
//# sourceMappingURL=actor-
|
|
598
|
+
//# sourceMappingURL=actor-B1FAD_C_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-B1FAD_C_.mjs","names":["and","eq","uuid"],"sources":["../src/resource.ts","../src/actor.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { activitySelection, objectSelection } from \"@drfed/federation/object\";\nimport { schema } from \"@drfed/models\";\nimport type { Resource as ResourceRow } from \"@drfed/models/schema\";\nimport { type Uuid, validateUuid } from \"@drfed/models/uuid\";\nimport { PothosValidationError } from \"@pothos/core\";\nimport { resolveCursorConnection } from \"@pothos/plugin-relay\";\nimport { type SQL, type SQLWrapper, and, eq, sql } from \"drizzle-orm\";\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport {\n classificationAuthor,\n classificationInput,\n classifyMastodon,\n classifyMisskey,\n} from \"./classification.ts\";\nimport {\n type Viewer,\n isReadableResource,\n readableResource,\n} from \"./readable.ts\";\n\nexport const ResourceKind = builder.enumType(\"ResourceKind\", {\n values: schema.resourceKindEnum.enumValues,\n});\nexport const ResourceDetail = builder.unionType(\"ResourceDetail\", {\n types: () => [Activity, Collection],\n resolveType: async (value, ctx) => {\n const { id } = value as { id: Uuid };\n const row = await ctx.db.query.resources.findFirst({ where: { id } });\n if (row == null || row.kind === \"unknown\") {\n throw new Error(\"Missing typed resource.\");\n }\n return (\n {\n actor: \"Actor\",\n object: \"Object\",\n activity: \"Activity\",\n collection: \"Collection\",\n } as const\n )[row.kind];\n },\n});\nconst ResourceRef = builder.drizzleNode(\"resources\", {\n name: \"Resource\",\n id: { column: (row) => row.id },\n fields: (t) => ({\n iri: t.expose(\"iri\", { type: \"URL\" }),\n kind: t.expose(\"kind\", { type: ResourceKind }),\n detail: t.field({\n type: ResourceDetail,\n nullable: true,\n description:\n \"Typed details, or null while unknown, when the typed row or its author/owner is deleted, or when the viewer may not read it.\",\n select: { columns: { id: true, iri: true, kind: true } },\n resolve: (row, _, ctx) => resolveResource(ctx, row),\n }),\n }),\n});\nexport const Resource: DrFedObjectRef = ResourceRef;\n\n/**\n * Loads the typed record so union fragments see the complete entity.\n * @returns The typed entity, or null when it or its author is deleted, or when\n * the viewer may not read it.\n */\nexport async function resolveResource(\n viewer: Viewer,\n row: ResourceRow,\n): Promise<{ id: Uuid } | null> {\n const { db } = viewer;\n const visible = await db.query.resources.findFirst({\n where: {\n id: row.id,\n RAW: (table) =>\n and(visibleResource(table.id), readableResource(viewer, table.id))!,\n },\n columns: { id: true },\n });\n if (visible == null) return null;\n if (row.kind === \"unknown\") return null;\n const where = { id: row.id };\n const result =\n row.kind === \"actor\"\n ? await db.query.actors.findFirst({ where })\n : row.kind === \"object\"\n ? await db.query.objects.findFirst({ where })\n : row.kind === \"activity\"\n ? await db.query.activities.findFirst({ where })\n : await db.query.collections.findFirst({ where });\n // Generic revision-backed resources have no legacy typed details yet.\n return result ?? null;\n}\n\nexport function registerAddressingFields(\n table: \"objects\" | \"activities\",\n): void {\n for (const property of schema.addressingPropertyEnum.enumValues) {\n builder.drizzleObjectField(table, property, (t) =>\n t.field({\n type: [Resource],\n description: `Stored ${property} occurrences, in original order including duplicates.`,\n select: { columns: { id: true } },\n resolve: async (row, _, ctx) =>\n (\n await ctx.db.query.addressing.findMany({\n where: { sourceId: row.id, property },\n orderBy: { position: \"asc\" },\n with: { targetResource: true },\n })\n ).map((entry) => entry.targetResource),\n }),\n );\n }\n}\n\nconst CollectionType = builder.enumType(\"CollectionType\", {\n values: schema.collectionTypeEnum.enumValues,\n});\nconst CollectionRef = builder.drizzleNode(\"collections\", {\n name: \"Collection\",\n select: {\n columns: { id: true },\n with: { ownerActor: { columns: { deleted: true } } },\n },\n id: { column: (row) => row.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n type: t.expose(\"type\", { type: CollectionType }),\n owner: t.relation(\"ownerActor\", {\n nullable: true,\n query: { where: { deleted: { isNull: true } } },\n }),\n declaredTotalItems: t.exposeInt(\"totalItems\", {\n nullable: true,\n description:\n \"The `totalItems` reported by the collection document. It can differ from the locally observed count and is null for local collections. Unlike `totalCount` and `items`, this value is not recalculated when deleted actors, deleted objects, or resources authored by deleted actors are excluded.\",\n }),\n totalCount: t.int({\n description:\n \"The number of locally stored, visible members. It can differ from `declaredTotalItems`. Deleted actors, deleted objects, resources authored by deleted actors, and resources the viewer may not read are excluded from this count and `items`.\",\n select: { columns: { id: true } },\n resolve: (row, _, ctx) =>\n ctx.db.$count(\n schema.collectionItems,\n and(\n eq(schema.collectionItems.collectionId, row.id),\n visibleResource(schema.collectionItems.itemId),\n readableResource(ctx, schema.collectionItems.itemId),\n ),\n ),\n }),\n items: t.connection({\n type: Resource,\n description:\n \"The locally stored, visible members. Deleted actors, deleted objects, resources authored by deleted actors, and resources the viewer may not read are excluded from this connection and `totalCount`.\",\n select: { columns: { id: true } },\n resolve: (row, args, ctx) => {\n const positions = new Map<Uuid, number | null>();\n return resolveCursorConnection<Promise<ResourceRow[]>>(\n {\n args,\n toCursor: (item: ResourceRow) => {\n if (!positions.has(item.id)) {\n throw new Error(\"Missing collection item position.\");\n }\n return encodeCollectionCursor({\n position: positions.get(item.id)!,\n itemId: item.id,\n });\n },\n },\n async ({ before, after, limit, inverted }) => {\n const parsedBefore =\n before == null ? undefined : parseCollectionCursor(before);\n const parsedAfter =\n after == null ? undefined : parseCollectionCursor(after);\n const items = await ctx.db.query.collectionItems.findMany({\n where: {\n collectionId: row.id,\n RAW: (table) =>\n and(\n visibleResource(table.itemId),\n readableResource(ctx, table.itemId),\n collectionCursorPredicate(\n table.position,\n table.itemId,\n parsedBefore,\n parsedAfter,\n ),\n )!,\n },\n orderBy: collectionItemsOrder(inverted),\n limit,\n with: { item: true },\n });\n for (const item of items) {\n positions.set(item.itemId, item.position);\n }\n return items.map((item) => item.item);\n },\n );\n },\n }),\n }),\n});\nexport const Collection: DrFedObjectRef = CollectionRef;\n\ninterface CollectionCursor {\n position: number | null;\n itemId: Uuid;\n}\n\nconst BASE64_PATTERN =\n /^(?:[A-Za-z\\d+/]{4})*(?:[A-Za-z\\d+/]{2}==|[A-Za-z\\d+/]{3}=)?$/u;\n\nfunction encodeCollectionCursor(cursor: CollectionCursor): string {\n return Buffer.from(JSON.stringify([cursor.position, cursor.itemId])).toString(\n \"base64\",\n );\n}\n\nfunction parseCollectionCursor(cursor: string): CollectionCursor {\n if (cursor === \"\" || !BASE64_PATTERN.test(cursor)) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n const decoded = Buffer.from(cursor, \"base64\");\n if (decoded.toString(\"base64\") !== cursor) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n let value: unknown;\n try {\n value = JSON.parse(decoded.toString(\"utf8\"));\n } catch {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n if (!Array.isArray(value) || value.length !== 2) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n const [position, itemId] = value;\n if (\n (position !== null &&\n (!Number.isInteger(position) ||\n position < -2_147_483_648 ||\n position > 2_147_483_647)) ||\n !validateUuid(itemId)\n ) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n return { position, itemId };\n}\n\nfunction collectionCursorPredicate(\n positionColumn: SQLWrapper,\n itemIdColumn: SQLWrapper,\n before?: CollectionCursor,\n after?: CollectionCursor,\n): SQL | undefined {\n return and(\n after == null\n ? undefined\n : after.position == null\n ? sql`${positionColumn} is null and ${itemIdColumn} > ${after.itemId}`\n : sql`(\n ${positionColumn} > ${after.position}\n or (${positionColumn} = ${after.position} and ${itemIdColumn} > ${after.itemId})\n or ${positionColumn} is null\n )`,\n before == null\n ? undefined\n : before.position == null\n ? sql`(\n ${positionColumn} is not null\n or (${positionColumn} is null and ${itemIdColumn} < ${before.itemId})\n )`\n : sql`(\n ${positionColumn} < ${before.position}\n or (${positionColumn} = ${before.position} and ${itemIdColumn} < ${before.itemId})\n )`,\n );\n}\n\nfunction collectionItemsOrder(inverted: boolean): {\n position: \"asc\" | \"desc\";\n itemId: \"asc\" | \"desc\";\n} {\n // The keyset predicates rely on PostgreSQL's default ASC NULLS LAST and\n // DESC NULLS FIRST ordering.\n const direction = inverted ? \"desc\" : \"asc\";\n return { position: direction, itemId: direction };\n}\n\nconst Implementation = builder.enumType(\"Implementation\", {\n values: [\"MASTODON\", \"MISSKEY\"] as const,\n});\nconst ExpectedClassification = builder.objectRef<\n ReturnType<typeof classifyMastodon>\n>(\"ExpectedClassification\");\nExpectedClassification.implement({\n description:\n \"Expected classification; actual access depends on receiver state and policy.\",\n fields: (t) => ({\n implementation: t.expose(\"implementation\", { type: Implementation }),\n version: t.exposeString(\"version\"),\n classification: t.exposeString(\"classification\"),\n reason: t.exposeString(\"reason\"),\n }),\n});\nexport const ActivityType = builder.enumType(\"ActivityType\", {\n values: schema.activityTypeEnum.enumValues,\n});\nconst ActivityRef = builder.drizzleNode(\"activities\", {\n name: \"Activity\",\n description:\n \"Represents an ActivityPub activity. An activity of a local actor is \" +\n \"readable whatever its addressing. One of a remote actor is readable \" +\n \"only when it is addressed to the public, by members of the local \" +\n \"instances that received it, and by administrators; otherwise it is \" +\n \"left out as if it did not exist.\",\n select: {\n columns: { id: true },\n with: { actor: { columns: { deleted: true } } },\n },\n id: { column: (row) => row.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n type: t.expose(\"type\", { type: ActivityType }),\n actor: t.relation(\"actor\"),\n object: t.field({\n type: Resource,\n nullable: true,\n description:\n \"The resource the activity acts on, or null when there is none or \" +\n \"the viewer may not read it.\",\n select: { with: { object: true } },\n resolve: async (row, _, ctx) =>\n row.object != null && (await isReadableResource(ctx, row.object.id))\n ? row.object\n : null,\n }),\n expectedClassifications: t.field({\n type: [ExpectedClassification],\n description:\n \"Expected classifications for this activity and its Object. Empty if the object is absent, hidden, or not an Object.\",\n select: { columns: { id: true } },\n resolve: async (activity, _, ctx) => {\n const row = await ctx.db.query.activities.findFirst({\n where: { id: activity.id },\n with: activitySelection,\n });\n // As hidden from this viewer as `object` is, its addressing included.\n if (\n row?.objectId == null ||\n !(await isReadableResource(ctx, row.objectId))\n ) {\n return [];\n }\n const object = await ctx.db.query.objects.findFirst({\n where: {\n id: row.objectId,\n deleted: { isNull: true },\n actor: { deleted: { isNull: true } },\n },\n with: {\n ...objectSelection,\n actor: {\n with: {\n resource: true,\n collectionReferences: {\n with: { collection: { with: { resource: true } } },\n },\n },\n },\n },\n });\n if (object == null) return [];\n const addressing = classificationInput(object);\n const input = classificationInput(row);\n const author = classificationAuthor(object.actor);\n return [\n classifyMastodon(addressing, input, author),\n classifyMisskey(addressing, input, author),\n ];\n },\n }),\n published: t.expose(\"published\", { type: \"DateTime\" }),\n document: t.expose(\"document\", { type: \"JSON\", nullable: true }),\n }),\n});\nexport const Activity: DrFedObjectRef = ActivityRef;\nregisterAddressingFields(\"activities\");\n\n/**\n * Excludes deleted actors and objects, including resources authored or\n * owned by deleted actors.\n * @returns A predicate for a resource ID in an outer query.\n */\nfunction visibleResource(id: SQLWrapper): SQL {\n return sql`not exists (\n select 1 from ${schema.actors}\n where ${schema.actors.id} = ${id} and ${schema.actors.deleted} is not null\n ) and not exists (\n select 1 from ${schema.objects}\n join ${schema.actors} on ${schema.actors.id} = ${schema.objects.actorId}\n where ${schema.objects.id} = ${id}\n and (${schema.objects.deleted} is not null or ${schema.actors.deleted} is not null)\n ) and not exists (\n select 1 from ${schema.activities}\n join ${schema.actors} on ${schema.actors.id} = ${schema.activities.actorId}\n where ${schema.activities.id} = ${id} and ${schema.actors.deleted} is not null\n ) and not exists (\n select 1 from ${schema.collections}\n join ${schema.actors} on ${schema.actors.id} = ${schema.collections.ownerActorId}\n where ${schema.collections.id} = ${id} and ${schema.actors.deleted} is not null\n )`;\n}\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable max-lines-per-function eslint/max-lines\n\n// Keep dependent database writes and observations sequential.\n// oxlint-disable no-await-in-loop\n\nimport { enqueueActorKeyGeneration } from \"@drfed/federation\";\nimport { type Database, promoteResource, schema } from \"@drfed/models\";\nimport { type CollectionRole, actorTypeEnum } from \"@drfed/models/schema\";\nimport { type Uuid, uuidV7 as uuid } from \"@drfed/models/uuid\";\nimport { faker } from \"@faker-js/faker\";\nimport type { Context } from \"@fedify/fedify\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport type { PgInsertValue } from \"drizzle-orm/pg-core\";\nimport { and, eq, gt, isNotNull, isNull } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { Instance } from \"./instance.ts\";\nimport { Collection, ResourceDetail } from \"./resource.ts\";\n\nconst ActorType = builder.enumType(\"ActorType\", {\n values: actorTypeEnum.enumValues,\n});\n\nconst ACTOR_TYPES_DOC = actorTypeEnum.enumValues\n .map((t) => `\\`${t}\\``)\n .join(\" | \");\n\nasync function resolveActorCollection(\n db: Database,\n actorId: Uuid,\n role: CollectionRole,\n) {\n const reference = await db.query.actorCollectionReferences.findFirst({\n where: { actorId, role },\n with: {\n collection: {\n with: { ownerActor: { columns: { deleted: true } } },\n },\n },\n });\n const collection = reference?.collection;\n return collection?.ownerActor?.deleted == null ? (collection ?? null) : null;\n}\n\nconst USERNAME_DOC =\n \"The username of the `Actor`. A remote actor's is its \" +\n \"`preferredUsername` as received, which is null when it has none and \" +\n \"need not be unique.\";\n\nconst ActorRef = builder.drizzleNode(\"actors\", {\n name: \"Actor\",\n description: \"Represents an `Actor` in the DrFed platform.\",\n id: {\n column: ({ id }) => id,\n description: \"The unique identifier of the `Actor`.\",\n },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the `Actor`.\",\n }),\n handle: t.field({\n type: \"String\",\n nullable: true,\n description:\n \"The handle of the `Actor`, its `username` and its `Instance`'s \" +\n \"host. For a remote actor, this is not a verified WebFinger \" +\n \"address. Null when `username` is.\",\n select: {\n columns: { username: true },\n with: { instance: { columns: { host: true } } },\n },\n resolve: ({ instance, username }) =>\n username == null ? null : `@${username}@${instance.host}`,\n }),\n type: t.expose(\"type\", {\n type: ActorType,\n description: `The type of the \\`Actor\\`: ${ACTOR_TYPES_DOC}`,\n }),\n username: t.exposeString(\"username\", {\n nullable: true,\n description: USERNAME_DOC,\n }),\n instance: t.relation(\"instance\", {\n description: \"The `Instance` that the `Actor` belongs to.\",\n }),\n local: t.relation(\"localActor\", {\n nullable: true,\n description: \"The local details of the `Actor`, or null if it is remote.\",\n }),\n inboxUrl: t.expose(\"inboxUrl\", {\n type: \"URL\",\n description: \"The inbox URL of the `Actor`.\",\n }),\n outbox: t.field({\n type: Collection,\n nullable: true,\n description:\n \"The stored outbox collection. For local actors, it contains every stored `Create` activity regardless of addressing and retains activities whose objects are deleted so their recorded history remains inspectable. The ActivityPub outbox serves only activities with Public addressing whose objects are not deleted.\",\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"outbox\"),\n }),\n avatarUrl: t.expose(\"avatarUrl\", {\n type: \"URL\",\n description: \"The avatar URL of the `Actor`.\",\n nullable: true,\n }),\n followers: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"followers\"),\n }),\n following: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"following\"),\n }),\n headerUrl: t.expose(\"headerUrl\", {\n type: \"URL\",\n description: \"The header URL of the `Actor`.\",\n nullable: true,\n }),\n profileUrl: t.expose(\"profileUrl\", {\n type: \"URL\",\n description: \"The profile URL of the `Actor`.\",\n nullable: true,\n }),\n featured: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"featured\"),\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description: \"The creation date/time of the `Actor`.\",\n }),\n }),\n});\n\nexport const Actor: DrFedObjectRef = ActorRef;\nResourceDetail.addTypes([Actor]);\n\nconst LocalActorRef = builder.drizzleNode(\"localActors\", {\n name: \"LocalActor\",\n select: {\n columns: { id: true },\n with: { actor: { columns: { deleted: true } } },\n },\n description: \"Represents the local details of an `Actor`.\",\n id: {\n column: ({ id }) => id,\n description: \"The unique identifier of the local actor details.\",\n },\n fields: (t) => ({\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the local actor details.\",\n }),\n avatar: t.exposeString(\"avatar\", {\n nullable: true,\n description: \"The profile image of the actor.\",\n }),\n header: t.exposeString(\"header\", {\n nullable: true,\n description: \"The profile banner image of the actor.\",\n }),\n }),\n});\n\nexport const LocalActor: DrFedObjectRef = LocalActorRef;\n\ninterface CreateActorsSuccess {\n readonly actors: readonly (typeof ActorRef.$inferType)[];\n}\n\nconst CreateActorsSuccessRef = builder.objectRef<CreateActorsSuccess>(\n \"CreateActorsSuccess\",\n);\n\nCreateActorsSuccessRef.implement({\n fields: (t) => ({\n actors: t.field({\n type: [ActorRef],\n resolve: ({ actors }) => actors,\n }),\n }),\n});\n\nconst INVALID_SIZE = \"InvalidSize\" as const;\nconst INSTANCE_NOT_FOUND = \"InstanceNotFound\" as const;\nconst INVALID_INSTANCE_HOST = \"InvalidInstanceHost\" as const;\nconst TOO_MANY_ACTORS = \"TooManyActors\" as const;\nconst CreateActorsErrors = [\n INVALID_SIZE,\n INSTANCE_NOT_FOUND,\n INVALID_INSTANCE_HOST,\n TOO_MANY_ACTORS,\n] as const;\n\nconst CreateActorsErrorType = builder.enumType(\"CreateActorsErrorType\", {\n values: CreateActorsErrors,\n});\n\ninterface CreateActorsError {\n readonly type: typeof CreateActorsErrorType.$inferType;\n readonly message: string;\n}\n\nconst CreateActorsErrorRef =\n builder.objectRef<CreateActorsError>(\"CreateActorsError\");\n\nCreateActorsErrorRef.implement({\n description: \"Represents an error that occurred while creating an `Actor`.\",\n fields: (t) => ({\n type: t.expose(\"type\", {\n type: CreateActorsErrorType,\n description:\n \"The type of the error. Use this for programmatic error handling.\",\n }),\n message: t.exposeString(\"message\", {\n description:\n \"A human-readable message describing the error. \" +\n \"Don't use this for programmatic error handling, \" +\n \"use the `type` field instead.\",\n }),\n }),\n});\n\nconst CreateActorsResult = builder.unionType(\"CreateActorsResult\", {\n types: [CreateActorsSuccessRef, CreateActorsErrorRef],\n resolveType(value) {\n if (\"message\" in value) return CreateActorsErrorRef;\n return CreateActorsSuccessRef;\n },\n});\n\nbuilder.mutationFields((t) => ({\n generateActors: t.field({\n type: CreateActorsResult,\n description: \"Create actors.\",\n authScopes: { authenticated: true },\n args: {\n instance: t.arg.globalID({\n for: Instance,\n required: true,\n description: \"The ID of the target instance\",\n }),\n size: t.arg({\n type: \"Int\",\n required: true,\n description: \"How many actors to generate\",\n }),\n },\n async resolve(_query, { instance: { id: instanceId }, size }, ctx) {\n if (size < 1) {\n return {\n type: INVALID_SIZE,\n message: `${size} is too small. At least 1 or more.`,\n };\n }\n if (ctx.account == null) {\n // Note that the following error is not expected to be thrown,\n // because the `authScopes` option above should prevent this resolver\n throw new Error(\"You must be authenticated to create actors.\");\n }\n const { account } = ctx;\n // Relay decodes global IDs as strings; Instance uses UUID identifiers.\n const targetInstanceId = instanceId as Uuid;\n\n let createdOrigin: URL | undefined;\n const result = await ctx.db.transaction(async (tx) => {\n // Find the instance that the account is included\n const [instance] = await tx\n .select({\n host: schema.instances.host,\n maxActors: schema.localInstances.maxActors,\n })\n .from(schema.instanceMembers)\n .for(\"update\", { of: schema.localInstances })\n .innerJoin(\n schema.instances,\n eq(schema.instanceMembers.instanceId, schema.instances.id),\n )\n .innerJoin(\n schema.localInstances,\n eq(schema.instances.localId, schema.localInstances.id),\n )\n .where(\n and(\n eq(schema.instanceMembers.accountId, account.id),\n gt(schema.localInstances.expires, Temporal.Now.instant()),\n eq(schema.instances.id, targetInstanceId),\n isNotNull(schema.instanceMembers.accepted),\n ),\n )\n .limit(1);\n if (instance == null) {\n return {\n type: INSTANCE_NOT_FOUND,\n message: \"Can't find the instance.\",\n };\n }\n // Read the stored authority rather than recomposing it from the\n // slug, so that actor URIs cannot drift from the instance the rest of\n // the fediverse already knows.\n const { host, maxActors } = instance;\n const instanceUrl = `${ctx.rootOrigin.protocol}//${host}`;\n // Stored authorities can outlive the runtime that accepted them.\n if (!URL.canParse(instanceUrl)) {\n return {\n type: INVALID_INSTANCE_HOST,\n message:\n `The instance host ${JSON.stringify(host)} cannot be parsed by ` +\n \"this server. Contact the server administrator.\",\n };\n }\n const currActors = await tx.$count(\n schema.actors,\n eq(schema.actors.instanceId, targetInstanceId),\n );\n\n if (size + currActors > maxActors) {\n return {\n type: TOO_MANY_ACTORS,\n message: `${size} is too big. The maximum number of actors of ${\n host\n } is ${maxActors} and the current number of actors is ${\n currActors\n }.`,\n };\n }\n // Create actors\n createdOrigin = new URL(instanceUrl);\n const fedCtx = ctx.federation.createContext(\n new URL(instanceUrl),\n undefined,\n );\n const ids = Array.from({ length: size }, () => ({ id: uuid() }));\n await tx.insert(schema.localActors).values(ids);\n const createdActors = [];\n for (const { id } of ids) {\n const actor = await promoteResource(\n tx,\n fedCtx.getActorUri(id).href,\n \"actor\",\n async (inner, resource) => {\n for (let attempt = 0; attempt < 10; attempt += 1) {\n const [createdActor] = await inner\n .insert(schema.actors)\n .values(generateActor(resource.id, targetInstanceId, fedCtx))\n .onConflictDoNothing({\n target: [schema.actors.username, schema.actors.instanceId],\n // Only the partial index of local actors' usernames.\n where: isNotNull(schema.actors.localId),\n })\n .returning();\n if (createdActor != null) {\n return createdActor;\n }\n }\n throw new Error(\"Actor insertion returned no row.\");\n },\n id,\n );\n for (const [role, iri] of [\n [\"followers\", fedCtx.getFollowersUri(id).href],\n [\"following\", fedCtx.getFollowingUri(id).href],\n [\"featured\", fedCtx.getFeaturedUri(id).href],\n [\"outbox\", fedCtx.getOutboxUri(id).href],\n ] as const) {\n await promoteResource(\n tx,\n iri,\n \"collection\",\n async (inner, resource) => {\n await inner.insert(schema.collections).values({\n id: resource.id,\n type: \"OrderedCollection\",\n ownerActorId: actor.id,\n });\n await inner.insert(schema.actorCollectionReferences).values({\n actorId: actor.id,\n role,\n collectionId: resource.id,\n });\n },\n );\n }\n createdActors.push(actor);\n }\n return { actors: createdActors };\n });\n if (\"actors\" in result && createdOrigin != null) {\n await enqueueActorKeyGeneration(\n ctx.federation.createContext(createdOrigin, undefined),\n result.actors.map((actor) => actor.id),\n );\n }\n return result;\n },\n }),\n}));\n\nfunction generateActor(\n id: Uuid,\n instanceId: Uuid,\n fedCtx: Context<unknown>,\n): PgInsertValue<typeof schema.actors> {\n const username = faker.internet\n .username()\n .toLowerCase()\n .replace(/[^a-z0-9_]/gu, \"_\");\n\n return {\n id,\n localId: id,\n username,\n instanceId,\n type: \"Person\",\n inboxUrl: fedCtx.getInboxUri(id).href,\n profileUrl: new URL(`/@${username}`, fedCtx.origin).href,\n };\n}\n\nconst actorsConnection = drizzleConnectionHelpers(builder, \"actors\", {\n query: { orderBy: { created: \"desc\", id: \"desc\" } },\n});\n\nbuilder.drizzleObjectField(\"instances\", \"actors\", (t) =>\n t.connection(\n {\n type: Actor,\n description: \"The `Actor`s that belong to the `Instance`.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n actors: actorsConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve(instance, args, ctx) {\n return {\n ...actorsConnection.resolve(instance.actors, args, ctx, instance),\n totalCount() {\n return ctx.db.$count(\n schema.actors,\n and(\n eq(schema.actors.instanceId, instance.id),\n isNull(schema.actors.deleted),\n ),\n );\n },\n };\n },\n },\n {\n fields(fb) {\n return {\n totalCount: fb.int({\n description:\n \"The total number of `Actor`s that belong to the `Instance`.\",\n resolve(connection) {\n return connection.totalCount();\n },\n }),\n };\n },\n },\n {\n fields(fb) {\n return {\n created: fb.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The date/time when the `Actor` was added to the `Instance`.\",\n }),\n type: fb.expose(\"type\", {\n type: ActorType,\n description: `The type of the \\`Actor\\`: ${ACTOR_TYPES_DOC}`,\n }),\n username: fb.exposeString(\"username\", {\n nullable: true,\n description: USERNAME_DOC,\n }),\n };\n },\n },\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,eAAe,QAAQ,SAAS,gBAAgB,EAC3D,QAAQ,OAAO,iBAAiB,WAClC,CAAC;AACD,MAAa,iBAAiB,QAAQ,UAAU,kBAAkB;CAChE,aAAa,CAAC,UAAU,UAAU;CAClC,aAAa,OAAO,OAAO,QAAQ;EACjC,MAAM,EAAE,OAAO;EACf,MAAM,MAAM,MAAM,IAAI,GAAG,MAAM,UAAU,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;EACpE,IAAI,OAAO,QAAQ,IAAI,SAAS,WAC9B,MAAM,IAAI,MAAM,yBAAyB;EAE3C,OACE;GACE,OAAO;GACP,QAAQ;GACR,UAAU;GACV,YAAY;EACd,EACA,IAAI;CACR;AACF,CAAC;AAiBD,MAAa,WAhBO,QAAQ,YAAY,aAAa;CACnD,MAAM;CACN,IAAI,EAAE,SAAS,QAAQ,IAAI,GAAG;CAC9B,SAA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ACF;AAEA,MAAM,mBAAmB,yBAAyB,SAAS,UAAU,EACnE,OAAO,EAAE,SAAS;CAAE,SAAS;CAAQ,IAAI;AAAO,EAAE,EACpD,CAAC;AAED,QAAQ,mBAAmB,aAAa,WAAW,MACjD,EAAE,WACA;CACE,MAAM;CACN,aAAa;CACb,OAAO,MAAM,KAAK,iBAAiB;EACjC,OAAO,EACL,MAAM,EACJ,QAAQ,iBAAiB,SAAS,MAAM,KAAK,eAAe,EAC9D,EACF;CACF;CACA,QAAQ,UAAU,MAAM,KAAK;EAC3B,OAAO;GACL,GAAG,iBAAiB,QAAQ,SAAS,QAAQ,MAAM,KAAK,QAAQ;GAChE,aAAa;IACX,OAAO,IAAI,GAAG,OACZ,OAAO,QACP,IACE,GAAG,OAAO,OAAO,YAAY,SAAS,EAAE,GACxC,OAAO,OAAO,OAAO,OAAO,CAC9B,CACF;GACF;EACF;CACF;AACF,GACA,EACE,OAAO,IAAI;CACT,OAAO,EACL,YAAY,GAAG,IAAI;EACjB,aACE;EACF,QAAQ,YAAY;GAClB,OAAO,WAAW,WAAW;EAC/B;CACF,CAAC,EACH;AACF,EACF,GACA,EACE,OAAO,IAAI;CACT,OAAO;EACL,SAAS,GAAG,OAAO,WAAW;GAC5B,MAAM;GACN,aACE;EACJ,CAAC;EACD,MAAM,GAAG,OAAO,QAAQ;GACtB,MAAM;GACN,aAAa,8BAA8B;EAC7C,CAAC;EACD,UAAU,GAAG,aAAa,YAAY;GACpC,UAAU;GACV,aAAa;EACf,CAAC;CACH;AACF,EACF,CACF,CACF"}
|
package/dist/actor.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as Actor, n as LocalActor } from "./actor-
|
|
1
|
+
export { t as Actor, n as LocalActor } from "./actor-B1FAD_C_.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as hashSecret, t as schema } from "./schema-
|
|
1
|
+
import { n as hashSecret, t as schema } from "./schema-f-SnZVb9.mjs";
|
|
2
2
|
import { canonicalHostname } from "@drfed/federation/origin";
|
|
3
3
|
import { getYogaLogger } from "@logtape/graphql-yoga";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
package/dist/object.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.mts","names":[],"sources":["../src/object.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"object.d.mts","names":[],"sources":["../src/object.ts"],"mappings":";;cA4Ia,mBAAmB"}
|
package/dist/object.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as builder } from "./builder-BLioFAdv.mjs";
|
|
2
2
|
import { a as readableResource } from "./readable-CSN0MPlO.mjs";
|
|
3
|
-
import { a as ResourceDetail, i as ActivityType, o as registerAddressingFields, r as Activity, t as Actor } from "./actor-
|
|
3
|
+
import { a as ResourceDetail, i as ActivityType, o as registerAddressingFields, r as Activity, t as Actor } from "./actor-B1FAD_C_.mjs";
|
|
4
4
|
import { objectTypeEnum } from "@drfed/models/schema";
|
|
5
5
|
import { drizzleConnectionHelpers } from "@pothos/plugin-drizzle";
|
|
6
|
-
import { addActorCollectionItem, ensureResource, lockActorCollection, promoteResource, schema, storeAddressing } from "@drfed/models";
|
|
6
|
+
import { addActorCollectionItem, captureLegacyResourceRevision, ensureResource, lockActorCollection, promoteResource, schema, storeAddressing } from "@drfed/models";
|
|
7
7
|
import { uuidV7, validateUuid } from "@drfed/models/uuid";
|
|
8
8
|
import { and, eq, gt, isNotNull, isNull } from "drizzle-orm";
|
|
9
9
|
import { activitySelection, objectSelection, toCreate, toObject } from "@drfed/federation/object";
|
|
@@ -300,6 +300,8 @@ builder.mutationFields((t) => ({ createObject: t.field({
|
|
|
300
300
|
...asDocument(await toCreate(fedCtx, storedActivity).toJsonLd()),
|
|
301
301
|
...addressing
|
|
302
302
|
} }).where(eq(schema.activities.id, activityId));
|
|
303
|
+
await captureLegacyResourceRevision(tx, object.id);
|
|
304
|
+
await captureLegacyResourceRevision(tx, activityId);
|
|
303
305
|
return {
|
|
304
306
|
...object,
|
|
305
307
|
actor: storedObject.actor,
|
package/dist/object.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.mjs","names":["uuid","APObject"],"sources":["../src/object.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport {\n activitySelection,\n objectSelection,\n toCreate,\n toObject,\n} from \"@drfed/federation/object\";\nimport {\n addActorCollectionItem,\n ensureResource,\n lockActorCollection,\n promoteResource,\n schema,\n storeAddressing,\n} from \"@drfed/models\";\nimport { objectTypeEnum } from \"@drfed/models/schema\";\nimport { uuidV7 as uuid, validateUuid } from \"@drfed/models/uuid\";\nimport { Object as APObject, Create } from \"@fedify/vocab\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport { and, eq, gt, isNotNull, isNull } from \"drizzle-orm\";\n\nimport { Actor } from \"./actor.ts\";\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { readableResource } from \"./readable.ts\";\nimport {\n Activity,\n ActivityType,\n ResourceDetail,\n registerAddressingFields,\n} from \"./resource.ts\";\n\nconst ObjectType = builder.enumType(\"ObjectType\", {\n values: objectTypeEnum.enumValues,\n});\nconst AddressingInput = builder.inputType(\"AddressingInput\", {\n fields: (t) => ({\n to: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n cc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bto: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bcc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n audience: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n }),\n});\nconst ObjectRef = builder.drizzleNode(\"objects\", {\n name: \"Object\",\n select: {\n columns: { id: true, deleted: true },\n with: { actor: { columns: { deleted: true } } },\n },\n description:\n \"Represents an ActivityPub object authored by an `Actor`. An object of \" +\n \"a local actor is readable whatever its addressing. One of a remote \" +\n \"actor is readable only when it or the activity it was received in is \" +\n \"addressed to the public, by members of the local instances that \" +\n \"received that activity and the object as stored with it, and by \" +\n \"administrators; otherwise it is left out as if it did not exist.\",\n id: {\n column: ({ id }) => id,\n description: \"The Relay global ID of the object.\",\n },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the ActivityPub Object.\",\n }),\n url: t.expose(\"url\", {\n type: \"URL\",\n nullable: true,\n description: \"The human-readable page URL, if available.\",\n }),\n type: t.expose(\"type\", {\n type: ObjectType,\n description: \"The ActivityStreams vocabulary type: Note or Article.\",\n }),\n actor: t.relation(\"actor\", {\n description: \"The actor that authored the object.\",\n }),\n document: t.expose(\"document\", {\n type: \"JSON\",\n nullable: true,\n description:\n \"The JSON-LD document of the object. For a remote object embedded in the Create that delivered it, the object as received; null when it was not found within the first 64 places of that document, in which case the document of the Create, reachable through activities, holds it as received.\",\n }),\n name: t.exposeString(\"name\", {\n nullable: true,\n description: \"The optional title of the object.\",\n }),\n summary: t.exposeString(\"summary\", {\n nullable: true,\n description: \"The optional summary or content warning.\",\n }),\n contentHtml: t.exposeString(\"contentHtml\", {\n description:\n \"HTML preserved verbatim. Clients must sanitize it before browser rendering.\",\n }),\n language: t.exposeString(\"language\", {\n nullable: true,\n description:\n \"The canonical BCP 47 tag used for contentMap, if specified.\",\n }),\n sensitive: t.exposeBoolean(\"sensitive\", {\n description: \"Whether the content is marked sensitive.\",\n }),\n published: t.expose(\"published\", {\n type: \"DateTime\",\n description: \"The ActivityStreams publication time.\",\n }),\n updated: t.expose(\"updated\", {\n type: \"DateTime\",\n description: \"The time the stored object was last updated.\",\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The time the object was stored in DrFed, distinct from its publication time.\",\n }),\n }),\n});\nexport const ActivityPubObject: DrFedObjectRef = ObjectRef;\nResourceDetail.addTypes([ActivityPubObject]);\nregisterAddressingFields(\"objects\");\n\nconst activitiesConnection = drizzleConnectionHelpers(builder, \"activities\", {\n query: (\n args: {\n type?: typeof schema.activities.$inferSelect.type | null;\n },\n ctx,\n ) => ({\n where: {\n actor: { deleted: { isNull: true } },\n ...(args.type == null ? {} : { type: args.type }),\n RAW: (table) => readableResource(ctx, table.id),\n },\n orderBy: { published: \"asc\", id: \"asc\" },\n }),\n});\nbuilder.drizzleObjectField(\"objects\", \"activities\", (t) =>\n t.connection({\n type: Activity,\n args: { type: t.arg({ type: ActivityType }) },\n description:\n \"Activities referencing this object that the viewer may read, optionally filtered by type. Excludes deleted authors; ordered by published ASC, id ASC.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n activities: activitiesConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve: (object, args, ctx) =>\n activitiesConnection.resolve(object.activities, args, ctx, object),\n }),\n);\n\nconst objectsConnection = drizzleConnectionHelpers(builder, \"objects\", {\n query: (_, ctx) => ({\n where: { RAW: (table) => readableResource(ctx, table.id) },\n orderBy: { published: \"desc\", id: \"desc\" },\n }),\n});\nbuilder.drizzleObjectField(\"actors\", \"objects\", (t) =>\n t.connection(\n {\n type: ActivityPubObject,\n description:\n \"Non-deleted objects the viewer may read, newest publication first. A local actor's objects are readable whatever their addressing; see `Object` for a remote actor's.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n objects: objectsConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve(actor, args, ctx) {\n return {\n ...objectsConnection.resolve(actor.objects, args, ctx, actor),\n totalCount() {\n return ctx.db.$count(\n schema.objects,\n and(\n eq(schema.objects.actorId, actor.id),\n isNull(schema.objects.deleted),\n readableResource(ctx, schema.objects.id),\n ),\n );\n },\n };\n },\n },\n {\n name: \"ObjectConnection\",\n fields: (fb) => ({\n totalCount: fb.int({\n description:\n \"The number of non-deleted objects authored by this actor that the viewer may read.\",\n resolve: (connection) => connection.totalCount(),\n }),\n }),\n },\n { name: \"ObjectEdge\" },\n ),\n);\n\nconst CreateObjectErrorType = builder.enumType(\"CreateObjectErrorType\", {\n values: [\n \"ActorNotFound\",\n \"InvalidContent\",\n \"InvalidInstanceHost\",\n \"InvalidLanguage\",\n ] as const,\n});\ninterface CreateObjectError {\n readonly type: typeof CreateObjectErrorType.$inferType;\n readonly message: string;\n}\nconst CreateObjectErrorRef =\n builder.objectRef<CreateObjectError>(\"CreateObjectError\");\nCreateObjectErrorRef.implement({\n fields: (t) => ({\n type: t.expose(\"type\", {\n type: CreateObjectErrorType,\n description:\n \"The type of the error. Use this for programmatic error handling.\",\n }),\n message: t.exposeString(\"message\", {\n description:\n \"A human-readable message describing the error. \" +\n \"Don't use this for programmatic error handling, \" +\n \"use the `type` field instead.\",\n }),\n }),\n});\nconst CreateObjectResult = builder.unionType(\"CreateObjectResult\", {\n types: [ObjectRef, CreateObjectErrorRef],\n resolveType: (value) =>\n \"message\" in value ? CreateObjectErrorRef : ObjectRef,\n});\nconst actorNotFound: CreateObjectError = {\n type: \"ActorNotFound\",\n message: \"Can't find the actor.\",\n};\n\nbuilder.mutationFields((t) => ({\n createObject: t.field({\n type: CreateObjectResult,\n description:\n \"Create a local ActivityPub object without delivering it to remote servers.\",\n authScopes: { authenticated: true },\n args: {\n actor: t.arg.globalID({\n for: Actor,\n required: true,\n description:\n \"The local author actor ID. The viewer must be an accepted instance member.\",\n }),\n type: t.arg({\n type: ObjectType,\n required: true,\n defaultValue: \"Note\",\n description: \"The ActivityStreams object type to create.\",\n }),\n contentHtml: t.arg.string({\n required: true,\n description:\n \"Non-empty HTML stored verbatim; browser clients must sanitize it before rendering.\",\n }),\n name: t.arg.string({\n description:\n \"Optional title. Empty or whitespace-only values are stored as null.\",\n }),\n summary: t.arg.string({\n description:\n \"Optional summary or content warning. Empty or whitespace-only values are stored as null.\",\n }),\n language: t.arg.string({\n description:\n \"A BCP 47 language tag, canonicalized and limited to 35 characters.\",\n }),\n sensitive: t.arg.boolean({\n required: true,\n defaultValue: false,\n description: \"Whether to mark the content as sensitive.\",\n }),\n addressing: t.arg({\n type: AddressingInput,\n required: true,\n description:\n \"Explicit addressing preserved in order, including duplicates. Empty lists are allowed.\",\n }),\n },\n async resolve(\n _parent,\n { actor: { id: actorId }, language, addressing, ...input },\n ctx,\n ) {\n if (input.contentHtml.trim() === \"\") {\n return {\n type: \"InvalidContent\" as const,\n message: \"Content must not be empty.\",\n };\n }\n let canonicalLanguage: string | null = null;\n if (language != null) {\n try {\n canonicalLanguage = Intl.getCanonicalLocales(language)[0] ?? null;\n if (canonicalLanguage == null || canonicalLanguage.length > 35) {\n throw new RangeError(\"Language tag is too long.\");\n }\n } catch (error) {\n if (!(error instanceof RangeError)) throw error;\n return {\n type: \"InvalidLanguage\" as const,\n message:\n \"Language must be a valid BCP 47 tag of at most 35 characters.\",\n };\n }\n }\n const { account } = ctx;\n if (account == null) {\n throw new Error(\"You must be authenticated to create objects.\");\n }\n if (!validateUuid(actorId)) return actorNotFound;\n // Keep host validation and resource creation under the same actor lock.\n return await ctx.db.transaction(async (tx) => {\n const [actor] = await tx\n .select({ id: schema.actors.id, host: schema.instances.host })\n .from(schema.actors)\n .for(\"update\", { of: schema.actors })\n .innerJoin(\n schema.instances,\n eq(schema.actors.instanceId, schema.instances.id),\n )\n .innerJoin(\n schema.localInstances,\n eq(schema.instances.localId, schema.localInstances.id),\n )\n .innerJoin(\n schema.instanceMembers,\n eq(schema.instanceMembers.instanceId, schema.instances.id),\n )\n .where(\n and(\n eq(schema.actors.id, actorId),\n isNotNull(schema.actors.localId),\n isNull(schema.actors.deleted),\n gt(schema.localInstances.expires, Temporal.Now.instant()),\n eq(schema.instanceMembers.accountId, account.id),\n isNotNull(schema.instanceMembers.accepted),\n ),\n )\n .limit(1);\n if (actor == null) return actorNotFound;\n const instanceUrl = `${ctx.rootOrigin.protocol}//${actor.host}`;\n // Stored authorities can outlive the runtime that accepted them.\n if (!URL.canParse(instanceUrl)) {\n return {\n type: \"InvalidInstanceHost\" as const,\n message:\n `The instance host ${JSON.stringify(actor.host)} cannot be ` +\n \"parsed by this server. Contact the server administrator.\",\n };\n }\n await lockActorCollection(tx, actorId, \"outbox\");\n const published = Temporal.Now.instant();\n const id = uuid();\n const fedCtx = ctx.federation.createContext(\n new URL(instanceUrl),\n undefined,\n );\n const iri = fedCtx.getObjectUri(APObject, {\n identifier: actorId,\n id,\n }).href;\n const activityId = uuid();\n const activityIri = fedCtx.getObjectUri(Create, {\n id: activityId,\n }).href;\n await ensureResource(tx, activityIri, activityId);\n const object = await promoteResource(\n tx,\n iri,\n \"object\",\n async (inner, resource) => {\n const [row] = await inner\n .insert(schema.objects)\n .values({\n ...input,\n name: normalizeOptionalText(input.name),\n summary: normalizeOptionalText(input.summary),\n id: resource.id,\n actorId,\n activityId,\n language: canonicalLanguage,\n published,\n })\n .returning();\n if (row == null) {\n throw new Error(\"Object insertion returned no row.\");\n }\n return row;\n },\n id,\n );\n await storeAddressing(tx, object.id, addressing);\n await promoteResource(\n tx,\n activityIri,\n \"activity\",\n async (inner, resource) => {\n await inner.insert(schema.activities).values({\n id: resource.id,\n type: \"Create\",\n actorId,\n objectId: object.id,\n published: object.published,\n });\n await storeAddressing(inner, resource.id, addressing);\n await addActorCollectionItem(inner, actorId, \"outbox\", resource.id);\n },\n activityId,\n );\n const storedObject = await tx.query.objects.findFirst({\n where: { id: object.id },\n with: objectSelection,\n });\n const storedActivity = await tx.query.activities.findFirst({\n where: { id: activityId },\n with: activitySelection,\n });\n if (storedObject == null || storedActivity == null) {\n throw new Error(\"Missing newly created resource.\");\n }\n // Preserve blind recipients in the local snapshot; serving strips them.\n const snapshot = {\n ...asDocument(await toObject(fedCtx, storedObject).toJsonLd()),\n ...addressing,\n };\n await tx\n .update(schema.objects)\n .set({ document: snapshot, updated: object.updated })\n .where(eq(schema.objects.id, object.id));\n await tx\n .update(schema.activities)\n .set({\n document: {\n ...asDocument(await toCreate(fedCtx, storedActivity).toJsonLd()),\n ...addressing,\n },\n })\n .where(eq(schema.activities.id, activityId));\n return { ...object, actor: storedObject.actor, document: snapshot };\n });\n },\n }),\n}));\n\nfunction normalizeOptionalText(\n value: string | null | undefined,\n): string | null {\n return value == null || value.trim() === \"\" ? null : value;\n}\n\nfunction asDocument(value: unknown): Record<string, unknown> {\n if (value == null || typeof value !== \"object\" || Array.isArray(value)) {\n throw new TypeError(\"Expected a JSON-LD object.\");\n }\n return value as Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;;;AA8CA,MAAM,aAAa,QAAQ,SAAS,cAAc,EAChD,QAAQ,eAAe,WACzB,CAAC;AACD,MAAM,kBAAkB,QAAQ,UAAU,mBAAmB,EAC3D,SAAS,OAAO;CACd,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,KAAK,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAChE,KAAK,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAChE,UAAU,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;AACvE,GACF,CAAC;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AAM,KAAK,MAAM,KAAK,OAAO;AACvD;AAEA,SAAS,WAAW,OAAyC;CAC3D,IAAI,SAAS,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACnE,MAAM,IAAI,UAAU,4BAA4B;CAElD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"object.mjs","names":["uuid","APObject"],"sources":["../src/object.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport {\n activitySelection,\n objectSelection,\n toCreate,\n toObject,\n} from \"@drfed/federation/object\";\nimport {\n addActorCollectionItem,\n captureLegacyResourceRevision,\n ensureResource,\n lockActorCollection,\n promoteResource,\n schema,\n storeAddressing,\n} from \"@drfed/models\";\nimport { objectTypeEnum } from \"@drfed/models/schema\";\nimport { uuidV7 as uuid, validateUuid } from \"@drfed/models/uuid\";\nimport { Object as APObject, Create } from \"@fedify/vocab\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport { and, eq, gt, isNotNull, isNull } from \"drizzle-orm\";\n\nimport { Actor } from \"./actor.ts\";\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { readableResource } from \"./readable.ts\";\nimport {\n Activity,\n ActivityType,\n ResourceDetail,\n registerAddressingFields,\n} from \"./resource.ts\";\n\nconst ObjectType = builder.enumType(\"ObjectType\", {\n values: objectTypeEnum.enumValues,\n});\nconst AddressingInput = builder.inputType(\"AddressingInput\", {\n fields: (t) => ({\n to: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n cc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bto: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n bcc: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n audience: t.field({ type: [\"URL\"], required: true, defaultValue: [] }),\n }),\n});\nconst ObjectRef = builder.drizzleNode(\"objects\", {\n name: \"Object\",\n select: {\n columns: { id: true, deleted: true },\n with: { actor: { columns: { deleted: true } } },\n },\n description:\n \"Represents an ActivityPub object authored by an `Actor`. An object of \" +\n \"a local actor is readable whatever its addressing. One of a remote \" +\n \"actor is readable only when it or the activity it was received in is \" +\n \"addressed to the public, by members of the local instances that \" +\n \"received that activity and the object as stored with it, and by \" +\n \"administrators; otherwise it is left out as if it did not exist.\",\n id: {\n column: ({ id }) => id,\n description: \"The Relay global ID of the object.\",\n },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the ActivityPub Object.\",\n }),\n url: t.expose(\"url\", {\n type: \"URL\",\n nullable: true,\n description: \"The human-readable page URL, if available.\",\n }),\n type: t.expose(\"type\", {\n type: ObjectType,\n description: \"The ActivityStreams vocabulary type: Note or Article.\",\n }),\n actor: t.relation(\"actor\", {\n description: \"The actor that authored the object.\",\n }),\n document: t.expose(\"document\", {\n type: \"JSON\",\n nullable: true,\n description:\n \"The JSON-LD document of the object. For a remote object embedded in the Create that delivered it, the object as received; null when it was not found within the first 64 places of that document, in which case the document of the Create, reachable through activities, holds it as received.\",\n }),\n name: t.exposeString(\"name\", {\n nullable: true,\n description: \"The optional title of the object.\",\n }),\n summary: t.exposeString(\"summary\", {\n nullable: true,\n description: \"The optional summary or content warning.\",\n }),\n contentHtml: t.exposeString(\"contentHtml\", {\n description:\n \"HTML preserved verbatim. Clients must sanitize it before browser rendering.\",\n }),\n language: t.exposeString(\"language\", {\n nullable: true,\n description:\n \"The canonical BCP 47 tag used for contentMap, if specified.\",\n }),\n sensitive: t.exposeBoolean(\"sensitive\", {\n description: \"Whether the content is marked sensitive.\",\n }),\n published: t.expose(\"published\", {\n type: \"DateTime\",\n description: \"The ActivityStreams publication time.\",\n }),\n updated: t.expose(\"updated\", {\n type: \"DateTime\",\n description: \"The time the stored object was last updated.\",\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The time the object was stored in DrFed, distinct from its publication time.\",\n }),\n }),\n});\nexport const ActivityPubObject: DrFedObjectRef = ObjectRef;\nResourceDetail.addTypes([ActivityPubObject]);\nregisterAddressingFields(\"objects\");\n\nconst activitiesConnection = drizzleConnectionHelpers(builder, \"activities\", {\n query: (\n args: {\n type?: typeof schema.activities.$inferSelect.type | null;\n },\n ctx,\n ) => ({\n where: {\n actor: { deleted: { isNull: true } },\n ...(args.type == null ? {} : { type: args.type }),\n RAW: (table) => readableResource(ctx, table.id),\n },\n orderBy: { published: \"asc\", id: \"asc\" },\n }),\n});\nbuilder.drizzleObjectField(\"objects\", \"activities\", (t) =>\n t.connection({\n type: Activity,\n args: { type: t.arg({ type: ActivityType }) },\n description:\n \"Activities referencing this object that the viewer may read, optionally filtered by type. Excludes deleted authors; ordered by published ASC, id ASC.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n activities: activitiesConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve: (object, args, ctx) =>\n activitiesConnection.resolve(object.activities, args, ctx, object),\n }),\n);\n\nconst objectsConnection = drizzleConnectionHelpers(builder, \"objects\", {\n query: (_, ctx) => ({\n where: { RAW: (table) => readableResource(ctx, table.id) },\n orderBy: { published: \"desc\", id: \"desc\" },\n }),\n});\nbuilder.drizzleObjectField(\"actors\", \"objects\", (t) =>\n t.connection(\n {\n type: ActivityPubObject,\n description:\n \"Non-deleted objects the viewer may read, newest publication first. A local actor's objects are readable whatever their addressing; see `Object` for a remote actor's.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n objects: objectsConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve(actor, args, ctx) {\n return {\n ...objectsConnection.resolve(actor.objects, args, ctx, actor),\n totalCount() {\n return ctx.db.$count(\n schema.objects,\n and(\n eq(schema.objects.actorId, actor.id),\n isNull(schema.objects.deleted),\n readableResource(ctx, schema.objects.id),\n ),\n );\n },\n };\n },\n },\n {\n name: \"ObjectConnection\",\n fields: (fb) => ({\n totalCount: fb.int({\n description:\n \"The number of non-deleted objects authored by this actor that the viewer may read.\",\n resolve: (connection) => connection.totalCount(),\n }),\n }),\n },\n { name: \"ObjectEdge\" },\n ),\n);\n\nconst CreateObjectErrorType = builder.enumType(\"CreateObjectErrorType\", {\n values: [\n \"ActorNotFound\",\n \"InvalidContent\",\n \"InvalidInstanceHost\",\n \"InvalidLanguage\",\n ] as const,\n});\ninterface CreateObjectError {\n readonly type: typeof CreateObjectErrorType.$inferType;\n readonly message: string;\n}\nconst CreateObjectErrorRef =\n builder.objectRef<CreateObjectError>(\"CreateObjectError\");\nCreateObjectErrorRef.implement({\n fields: (t) => ({\n type: t.expose(\"type\", {\n type: CreateObjectErrorType,\n description:\n \"The type of the error. Use this for programmatic error handling.\",\n }),\n message: t.exposeString(\"message\", {\n description:\n \"A human-readable message describing the error. \" +\n \"Don't use this for programmatic error handling, \" +\n \"use the `type` field instead.\",\n }),\n }),\n});\nconst CreateObjectResult = builder.unionType(\"CreateObjectResult\", {\n types: [ObjectRef, CreateObjectErrorRef],\n resolveType: (value) =>\n \"message\" in value ? CreateObjectErrorRef : ObjectRef,\n});\nconst actorNotFound: CreateObjectError = {\n type: \"ActorNotFound\",\n message: \"Can't find the actor.\",\n};\n\nbuilder.mutationFields((t) => ({\n createObject: t.field({\n type: CreateObjectResult,\n description:\n \"Create a local ActivityPub object without delivering it to remote servers.\",\n authScopes: { authenticated: true },\n args: {\n actor: t.arg.globalID({\n for: Actor,\n required: true,\n description:\n \"The local author actor ID. The viewer must be an accepted instance member.\",\n }),\n type: t.arg({\n type: ObjectType,\n required: true,\n defaultValue: \"Note\",\n description: \"The ActivityStreams object type to create.\",\n }),\n contentHtml: t.arg.string({\n required: true,\n description:\n \"Non-empty HTML stored verbatim; browser clients must sanitize it before rendering.\",\n }),\n name: t.arg.string({\n description:\n \"Optional title. Empty or whitespace-only values are stored as null.\",\n }),\n summary: t.arg.string({\n description:\n \"Optional summary or content warning. Empty or whitespace-only values are stored as null.\",\n }),\n language: t.arg.string({\n description:\n \"A BCP 47 language tag, canonicalized and limited to 35 characters.\",\n }),\n sensitive: t.arg.boolean({\n required: true,\n defaultValue: false,\n description: \"Whether to mark the content as sensitive.\",\n }),\n addressing: t.arg({\n type: AddressingInput,\n required: true,\n description:\n \"Explicit addressing preserved in order, including duplicates. Empty lists are allowed.\",\n }),\n },\n async resolve(\n _parent,\n { actor: { id: actorId }, language, addressing, ...input },\n ctx,\n ) {\n if (input.contentHtml.trim() === \"\") {\n return {\n type: \"InvalidContent\" as const,\n message: \"Content must not be empty.\",\n };\n }\n let canonicalLanguage: string | null = null;\n if (language != null) {\n try {\n canonicalLanguage = Intl.getCanonicalLocales(language)[0] ?? null;\n if (canonicalLanguage == null || canonicalLanguage.length > 35) {\n throw new RangeError(\"Language tag is too long.\");\n }\n } catch (error) {\n if (!(error instanceof RangeError)) throw error;\n return {\n type: \"InvalidLanguage\" as const,\n message:\n \"Language must be a valid BCP 47 tag of at most 35 characters.\",\n };\n }\n }\n const { account } = ctx;\n if (account == null) {\n throw new Error(\"You must be authenticated to create objects.\");\n }\n if (!validateUuid(actorId)) return actorNotFound;\n // Keep host validation and resource creation under the same actor lock.\n return await ctx.db.transaction(async (tx) => {\n const [actor] = await tx\n .select({ id: schema.actors.id, host: schema.instances.host })\n .from(schema.actors)\n .for(\"update\", { of: schema.actors })\n .innerJoin(\n schema.instances,\n eq(schema.actors.instanceId, schema.instances.id),\n )\n .innerJoin(\n schema.localInstances,\n eq(schema.instances.localId, schema.localInstances.id),\n )\n .innerJoin(\n schema.instanceMembers,\n eq(schema.instanceMembers.instanceId, schema.instances.id),\n )\n .where(\n and(\n eq(schema.actors.id, actorId),\n isNotNull(schema.actors.localId),\n isNull(schema.actors.deleted),\n gt(schema.localInstances.expires, Temporal.Now.instant()),\n eq(schema.instanceMembers.accountId, account.id),\n isNotNull(schema.instanceMembers.accepted),\n ),\n )\n .limit(1);\n if (actor == null) return actorNotFound;\n const instanceUrl = `${ctx.rootOrigin.protocol}//${actor.host}`;\n // Stored authorities can outlive the runtime that accepted them.\n if (!URL.canParse(instanceUrl)) {\n return {\n type: \"InvalidInstanceHost\" as const,\n message:\n `The instance host ${JSON.stringify(actor.host)} cannot be ` +\n \"parsed by this server. Contact the server administrator.\",\n };\n }\n await lockActorCollection(tx, actorId, \"outbox\");\n const published = Temporal.Now.instant();\n const id = uuid();\n const fedCtx = ctx.federation.createContext(\n new URL(instanceUrl),\n undefined,\n );\n const iri = fedCtx.getObjectUri(APObject, {\n identifier: actorId,\n id,\n }).href;\n const activityId = uuid();\n const activityIri = fedCtx.getObjectUri(Create, {\n id: activityId,\n }).href;\n await ensureResource(tx, activityIri, activityId);\n const object = await promoteResource(\n tx,\n iri,\n \"object\",\n async (inner, resource) => {\n const [row] = await inner\n .insert(schema.objects)\n .values({\n ...input,\n name: normalizeOptionalText(input.name),\n summary: normalizeOptionalText(input.summary),\n id: resource.id,\n actorId,\n activityId,\n language: canonicalLanguage,\n published,\n })\n .returning();\n if (row == null) {\n throw new Error(\"Object insertion returned no row.\");\n }\n return row;\n },\n id,\n );\n await storeAddressing(tx, object.id, addressing);\n await promoteResource(\n tx,\n activityIri,\n \"activity\",\n async (inner, resource) => {\n await inner.insert(schema.activities).values({\n id: resource.id,\n type: \"Create\",\n actorId,\n objectId: object.id,\n published: object.published,\n });\n await storeAddressing(inner, resource.id, addressing);\n await addActorCollectionItem(inner, actorId, \"outbox\", resource.id);\n },\n activityId,\n );\n const storedObject = await tx.query.objects.findFirst({\n where: { id: object.id },\n with: objectSelection,\n });\n const storedActivity = await tx.query.activities.findFirst({\n where: { id: activityId },\n with: activitySelection,\n });\n if (storedObject == null || storedActivity == null) {\n throw new Error(\"Missing newly created resource.\");\n }\n // Preserve blind recipients in the local snapshot; serving strips them.\n const snapshot = {\n ...asDocument(await toObject(fedCtx, storedObject).toJsonLd()),\n ...addressing,\n };\n await tx\n .update(schema.objects)\n .set({ document: snapshot, updated: object.updated })\n .where(eq(schema.objects.id, object.id));\n await tx\n .update(schema.activities)\n .set({\n document: {\n ...asDocument(await toCreate(fedCtx, storedActivity).toJsonLd()),\n ...addressing,\n },\n })\n .where(eq(schema.activities.id, activityId));\n await captureLegacyResourceRevision(tx, object.id);\n await captureLegacyResourceRevision(tx, activityId);\n return { ...object, actor: storedObject.actor, document: snapshot };\n });\n },\n }),\n}));\n\nfunction normalizeOptionalText(\n value: string | null | undefined,\n): string | null {\n return value == null || value.trim() === \"\" ? null : value;\n}\n\nfunction asDocument(value: unknown): Record<string, unknown> {\n if (value == null || typeof value !== \"object\" || Array.isArray(value)) {\n throw new TypeError(\"Expected a JSON-LD object.\");\n }\n return value as Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;;;AA+CA,MAAM,aAAa,QAAQ,SAAS,cAAc,EAChD,QAAQ,eAAe,WACzB,CAAC;AACD,MAAM,kBAAkB,QAAQ,UAAU,mBAAmB,EAC3D,SAAS,OAAO;CACd,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,IAAI,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAC/D,KAAK,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAAE,CAAC;CAChE,KAAK,EAAE,MAAM;EAAE,MAAM,CAAC,KAAK;EAAG,UAAU;EAAM,cAAc,CAAC;CAA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EAAE;GACjD,MAAM,8BAA8B,IAAI,UAAU;GAClD,OAAO;IAAE,GAAG;IAAQ,OAAO,aAAa;IAAO,UAAU;GAAS;EACpE,CAAC;CACH;AACF,CAAC,EACH,EAAE;AAEF,SAAS,sBACP,OACe;CACf,OAAO,SAAS,QAAQ,MAAM,KAAK,MAAM,KAAK,OAAO;AACvD;AAEA,SAAS,WAAW,OAAyC;CAC3D,IAAI,SAAS,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACnE,MAAM,IAAI,UAAU,4BAA4B;CAElD,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as builder } from "./builder-BLioFAdv.mjs";
|
|
2
2
|
import "./instance.mjs";
|
|
3
3
|
import "./account.mjs";
|
|
4
|
-
import "./actor-
|
|
4
|
+
import "./actor-B1FAD_C_.mjs";
|
|
5
5
|
import "./object.mjs";
|
|
6
6
|
import "./activity-delivery/entry.mjs";
|
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -272,4 +272,4 @@ const schema$1 = builder.toSchema();
|
|
|
272
272
|
//#endregion
|
|
273
273
|
export { hashSecret as n, schema$1 as t };
|
|
274
274
|
|
|
275
|
-
//# sourceMappingURL=schema-
|
|
275
|
+
//# sourceMappingURL=schema-f-SnZVb9.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-ZeV-COPn.mjs","names":["schema"],"sources":["../src/auth/hash.ts","../src/auth/expand.ts","../src/auth/mail.ts","../src/auth/magic-link.ts","../src/auth/challenge.ts","../src/auth/revoke.ts","../src/auth/entry.ts","../src/key.ts","../src/schema.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n// oxlint-disable func-names func-style id-length\n\n// oxlint-disable no-magic-numbers\nconst BASE36_CHAR = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// It's not strictly uniform random sampling, but it's negligible enough.\nexport const generateBase36Code = (len: number): string =>\n Array.from(\n // Choose `Uint16Array` cause `2 ** 16 % 36 = 16`\n // It's greater than `2 ** 8 % 36 = 2 ** 32 % 36 = 4`.\n crypto.getRandomValues(new Uint16Array(len)),\n (num) => BASE36_CHAR[num % BASE36_CHAR.length],\n ).join(\"\");\n\nexport const hashSecret = async (raw: string): Promise<string> =>\n new Uint8Array(\n await crypto.subtle.digest(\"SHA-256\", textEncoder.encode(raw)),\n ).toHex();\n\nconst textEncoder = new TextEncoder();\n\nconst ACCESS_TOKEN_BYTES = 32;\n\nexport const generateAccessToken = (): string =>\n crypto.getRandomValues(new Uint8Array(ACCESS_TOKEN_BYTES)).toBase64({\n alphabet: \"base64url\",\n omitPadding: true,\n });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { Template } from \"@fedify/uri-template\";\nimport { GraphQLError } from \"graphql\";\n\nexport interface ExpandVerifyUrlParams {\n template: Template;\n challengeId: `${string}-${string}-${string}-${string}-${string}`;\n code: string;\n loginOrigins: ReadonlySet<string>;\n}\n\nexport default function expandVerifyUrl({\n template,\n challengeId,\n code,\n loginOrigins,\n}: ExpandVerifyUrlParams): string {\n assertVariable(template, \"challengeId\");\n assertVariable(template, \"code\");\n\n let url: URL;\n try {\n url = new URL(template.expand({ challengeId, code }));\n } catch {\n throw invalidVerifyUrl(\n \"Verify URL template must expand to an absolute URL.\",\n );\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw invalidVerifyUrl(\"Verify URL must use HTTP or HTTPS.\");\n }\n if (!loginOrigins.has(url.origin)) {\n throw invalidVerifyUrl(`Verify URL origin is not allowed: ${url.origin}.`);\n }\n return url.href;\n}\n\nfunction assertVariable(template: Template, name: string): void {\n const found = template.tokens.some(\n (token) =>\n token.kind === \"expression\" &&\n token.vars.some(\n (variable) => variable.name === name && variable.prefix == null,\n ),\n );\n if (!found) {\n throw invalidVerifyUrl(`Verify URL template must include {${name}}.`);\n }\n}\n\nconst invalidVerifyUrl = (message: string) =>\n new GraphQLError(message, { extensions: { code: \"BAD_USER_INPUT\" } });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { getLogger } from \"@logtape/logtape\";\nimport { type MessageContent, type Receipt, createMessage } from \"@upyo/core\";\n\nimport type { UserContext } from \"../builder.ts\";\n\n/** Send login mail without exposing non-cancellation provider failures. */\nexport async function sendMail(\n to: string,\n loginUrl: string,\n ctx: UserContext,\n): Promise<void> {\n const signal = ctx.operationSignal ?? ctx.request.signal;\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n try {\n const receipt = await ctx.mailer.send(\n createMessage({\n from: ctx.emailFrom,\n to,\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n subject: \"Sign in to DrFed\",\n content: renderLoginEmail(loginUrl),\n }),\n { signal },\n );\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logReceipt(receipt);\n } catch {\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"exception\" });\n }\n}\n\nconst renderLoginEmail = (loginUrl: string): MessageContent => ({\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n text: `Hello, Welcome to DrFed! If you request to login to DrFed, please visit:\n\nopen ${loginUrl}\n\nOtherwise, please just ignore this mail.`,\n});\n\nexport function logReceipt(receipt: Receipt<string>): void {\n if (receipt.successful) {\n logger.debug(\"Login mail delivery succeeded.\", { outcome: \"sent\" });\n return;\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"failed\" });\n}\n\nconst logger = getLogger([\"drfed\", \"graphql\", \"auth\"]);\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { schema } from \"@drfed/models\";\nimport { type Uuid, uuidV7 } from \"@drfed/models/uuid\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\nimport expandVerifyUrl from \"./expand.ts\";\nimport { generateBase36Code } from \"./hash.ts\";\nimport { sendMail } from \"./mail.ts\";\n\ninterface LoginChallengeShape {\n readonly challengeId: Uuid;\n}\n\nconst LoginChallengeRef = builder\n .objectRef<LoginChallengeShape>(\"LoginChallenge\")\n .implement({\n description: \"An email login challenge.\",\n fields: (t) => ({\n challengeId: t.expose(\"challengeId\", {\n type: \"UUID\",\n description: \"The public identifier of the login challenge.\",\n }),\n }),\n });\n\nbuilder.mutationFields((t) => ({\n loginByEmail: t.field({\n type: LoginChallengeRef,\n description:\n \"Send a magic link without revealing whether the account exists.\",\n args: {\n email: t.arg({\n type: \"Email\",\n required: true,\n description: \"The email address of the `Account`.\",\n }),\n verifyUrl: t.arg({\n type: \"URITemplate\",\n required: true,\n description:\n \"Use {challengeId} and {code} variables. \" +\n \"The URL's origin must be in the server's login allowlist.\",\n }),\n },\n async resolve(_root, { email, verifyUrl }, ctx) {\n const challengeId = uuidV7();\n const code = generateBase36Code(schema.LOGIN_CHALLENGE_CODE_LENGTH);\n const loginUrl = expandVerifyUrl({\n challengeId,\n code,\n loginOrigins: ctx.loginOrigins,\n template: verifyUrl,\n });\n const account = await findAccount(email, ctx);\n if (account == null) {\n // Return an ID even for an unknown account to prevent account\n // enumeration. Consider mailing in a worker to prevent timing attacks.\n return { challengeId };\n }\n const verifier = {\n challengeId,\n code,\n };\n\n await insertChallenge(account.id, verifier, ctx);\n // Do not check the email was sent. Instructs users to request a resend if\n // the email does not arrive after a few minutes at the web page.\n await sendMail(account.email, loginUrl, ctx);\n\n return { challengeId };\n },\n }),\n}));\n\nconst findAccount = async (email: string, ctx: UserContext) =>\n await ctx.db.query.accounts.findFirst({\n where: { email },\n });\n\nconst insertChallenge = async (\n accountId: Uuid,\n { challengeId, code }: { challengeId: Uuid; code: string },\n ctx: UserContext,\n) =>\n await ctx.db.insert(schema.loginChallenges).values({\n id: challengeId,\n accountId,\n code,\n });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { Buffer } from \"node:buffer\";\nimport { timingSafeEqual } from \"node:crypto\";\n\nimport type { Database } from \"@drfed/models\";\nimport {\n LoginChallengeError,\n consumeLoginChallenge,\n findLoginChallenge,\n} from \"@drfed/models/login\";\nimport { sessions } from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\n\nimport builder from \"../builder.ts\";\nimport { generateAccessToken, hashSecret } from \"./hash.ts\";\n\nconst SessionRef = builder.drizzleObject(\"sessions\", {\n name: \"Session\",\n fields: (t) => ({\n id: t.expose(\"id\", { type: \"UUID\" }),\n accessToken: t.string({\n nullable: true,\n resolve(session) {\n const accessToken =\n \"accessToken\" in session ? session.accessToken : null;\n return typeof accessToken === \"string\" ? accessToken : null;\n },\n }),\n // The only `Session` a client can obtain is the one `completeLoginChallenge`\n // just created for it, and `Session` is not a `Node`, so the account behind\n // a session is always the viewer's own. Granting `ownAccount` here lets\n // the login response carry the viewer's private fields even though the\n // request that produced it had no session yet.\n account: t.relation(\"account\", { grantScopes: [\"ownAccount\"] }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n expires: t.expose(\"expires\", { type: \"DateTime\" }),\n }),\n});\n\nbuilder.mutationFields((t) => ({\n completeLoginChallenge: t.drizzleField({\n type: SessionRef,\n nullable: true,\n description: \"Complete login challenge.\",\n args: {\n challengeId: t.arg({ type: \"UUID\", required: true }),\n code: t.arg({ type: \"String\", required: true }),\n },\n async resolve(query, _root, { challengeId, code }, ctx) {\n try {\n const now = Temporal.Now.instant();\n const row = await findLoginChallenge(ctx.db, challengeId, now);\n const id = crypto.randomUUID();\n const accessToken = generateAccessToken();\n const accessHash = await hashSecret(accessToken);\n\n const providedCode = Buffer.from(code.toLowerCase());\n const expectedCode = Buffer.from(row.code);\n if (\n providedCode.length !== expectedCode.length ||\n !timingSafeEqual(providedCode, expectedCode)\n ) {\n throw new LoginChallengeError(\"The provided code does not match.\");\n }\n await ctx.db.transaction(async (tx) => {\n await consumeLoginChallenge(tx, row.id, now);\n await insertSession(id, row.accountId, accessHash, tx);\n });\n\n const session = await ctx.db.query.sessions.findFirst(\n query({ where: { id } }),\n );\n return session == null ? null : { ...session, accessToken };\n } catch (error) {\n if (error instanceof LoginChallengeError) {\n return null;\n }\n throw error;\n }\n },\n }),\n}));\n\nconst insertSession = async (\n id: Uuid,\n accountId: Uuid,\n tokenHash: string,\n tx: Database,\n) => await tx.insert(sessions).values({ id, accountId, tokenHash });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { sessions } from \"@drfed/models/schema\";\nimport { eq } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\n\nbuilder.mutationFields((t) => ({\n revokeSession: t.field({\n type: LogoutSuccessRef,\n description: \"Revokes a session. Return always `revoke: true`.\",\n authScopes: {\n authenticated: true,\n },\n async resolve(_query, _, ctx) {\n const sessionId = ctx.session?.id;\n if (sessionId) {\n await deleteSession(ctx);\n }\n // Return always true to prevent brute-force attack.\n return { revoke: true };\n },\n }),\n}));\n\ninterface LogoutSuccessShape {\n revoke: boolean;\n}\n\nconst LogoutSuccessRef = builder\n .objectRef<LogoutSuccessShape>(\"LogoutSuccess\")\n .implement({\n description: \"The session revoked.\",\n fields: (t) => ({\n revoke: t.expose(\"revoke\", {\n type: \"Boolean\",\n description: \"Revoking status.\",\n }),\n }),\n });\n\nconst deleteSession = (ctx: UserContext) =>\n ctx.db.delete(sessions).where(eq(sessions.id, ctx.session!.id));\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable import/no-unassigned-import\nimport \"./magic-link.ts\";\nimport \"./challenge.ts\";\nimport \"./revoke.ts\";\nimport builder from \"../builder.ts\";\n\nbuilder.queryFields((t) => ({\n viewer: t.drizzleField({\n type: \"accounts\",\n nullable: true,\n description: \"`Account` if authorized, else `null`\",\n resolve: (query, _root, _args, ctx) =>\n ctx.session == null\n ? null\n : ctx.db.query.accounts.findFirst(\n query({ where: { id: ctx.session.accountId } }),\n ),\n }),\n}));\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\n\nconst KeyRef = builder.drizzleNode(\"keys\", {\n name: \"Key\",\n description:\n \"A remote public key, identified by its IRI. Readable by any \" +\n \"authenticated viewer, since it holds public material only.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (key) => key.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n iri: t.expose(\"iri\", { type: \"URL\" }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n versions: t.relatedConnection(\"versions\", {\n description: \"The observed versions of the key, oldest first.\",\n query: { orderBy: { firstSeen: \"asc\", id: \"asc\" } },\n }),\n }),\n});\nexport const Key: DrFedObjectRef = KeyRef;\nconst observationDescription =\n \"DrFed observation time, not the remote key rotation time; \" +\n \"does not imply continuous use between observations.\";\nconst KeyVersionRef = builder.drizzleNode(\"keyVersions\", {\n name: \"KeyVersion\",\n description:\n \"Immutable public key material observed under a `Key`. Readable by \" +\n \"any authenticated viewer.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (version) => version.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n key: t.relation(\"key\"),\n publicKey: t.expose(\"publicKey\", { type: \"JSON\" }),\n fingerprint: t.exposeString(\"fingerprint\"),\n firstSeen: t.expose(\"firstSeen\", {\n type: \"DateTime\",\n description: `First ${observationDescription}`,\n }),\n lastSeen: t.expose(\"lastSeen\", {\n type: \"DateTime\",\n description: `Last ${observationDescription}`,\n }),\n }),\n});\nexport const KeyVersion: DrFedObjectRef = KeyVersionRef;\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n// oxlint-disable import/no-unassigned-import\nimport \"./account.ts\";\nimport \"./instance.ts\";\nimport \"./auth/entry.ts\";\nimport \"./actor.ts\";\nimport \"./object.ts\";\nimport \"./activity-delivery/entry.ts\";\nimport \"./key.ts\";\nimport builder from \"./builder.ts\";\n\nbuilder.queryType({});\nbuilder.mutationType({});\n\nexport const schema = builder.toSchema();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,cAAc;AAGpB,MAAa,sBAAsB,QACjC,MAAM,KAGJ,OAAO,gBAAgB,IAAI,YAAY,GAAG,CAAC,IAC1C,QAAQ,YAAY,MAAM,GAC7B,CAAC,CAAC,KAAK,EAAE;AAEX,MAAa,aAAa,OAAO,QAC/B,IAAI,WACF,MAAM,OAAO,OAAO,OAAO,WAAW,YAAY,OAAO,GAAG,CAAC,CAC/D,CAAC,CAAC,MAAM;AAEV,MAAM,cAAc,IAAI,YAAY;AAEpC,MAAM,qBAAqB;AAE3B,MAAa,4BACX,OAAO,gBAAgB,IAAI,WAAW,kBAAkB,CAAC,CAAC,CAAC,SAAS;CAClE,UAAU;CACV,aAAa;AACf,CAAC;;;AChBH,SAAwB,gBAAgB,EACtC,UACA,aACA,MACA,gBACgC;CAChC,eAAe,UAAU,aAAa;CACtC,eAAe,UAAU,MAAM;CAE/B,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,SAAS,OAAO;GAAE;GAAa;EAAK,CAAC,CAAC;CACtD,QAAQ;EACN,MAAM,iBACJ,qDACF;CACF;CAEA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,MAAM,iBAAiB,oCAAoC;CAE7D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AAM,EAAE,MAAM,OAAO,CAAC;EACrC,KAAK,EAAE,OAAO,OAAO,EAAE,MAAM,MAAM,CAAC;EACpC,SAAS,EAAE,OAAO,WAAW,EAAE,MAAM,WAAW,CAAC;EACjD,UAAU,EAAE,kBAAkB,YAAY;GACxC,aAAa;GACb,OAAO,EAAE,SAAS;IAAE,WAAW;IAAO,IAAI;GAAM,EAAE;EACpD,CAAC;CACH;AACF,CAAC;AAED,MAAM,yBACJ;AAEoB,QAAQ,YAAY,eAAe;CACvD,MAAM;CACN,aACE;CAEF,YAAY,EAAE,eAAe,KAAK;CAClC,iBAAiB;CACjB,IAAI,EAAE,SAAS,YAAY,QAAQ,GAAG;CACtC,SAAS,OAAO;EACd,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,OAAO,CAAC;EACrC,KAAK,EAAE,SAAS,KAAK;EACrB,WAAW,EAAE,OAAO,aAAa,EAAE,MAAM,OAAO,CAAC;EACjD,aAAa,EAAE,aAAa,aAAa;EACzC,WAAW,EAAE,OAAO,aAAa;GAC/B,MAAM;GACN,aAAa,SAAS;EACxB,CAAC;EACD,UAAU,EAAE,OAAO,YAAY;GAC7B,MAAM;GACN,aAAa,QAAQ;EACvB,CAAC;CACH;AACF,CAAC;;;ACrCD,QAAQ,UAAU,CAAC,CAAC;AACpB,QAAQ,aAAa,CAAC,CAAC;AAEvB,MAAaA,WAAS,QAAQ,SAAS"}
|
|
1
|
+
{"version":3,"file":"schema-f-SnZVb9.mjs","names":["schema"],"sources":["../src/auth/hash.ts","../src/auth/expand.ts","../src/auth/mail.ts","../src/auth/magic-link.ts","../src/auth/challenge.ts","../src/auth/revoke.ts","../src/auth/entry.ts","../src/key.ts","../src/schema.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n// oxlint-disable func-names func-style id-length\n\n// oxlint-disable no-magic-numbers\nconst BASE36_CHAR = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// It's not strictly uniform random sampling, but it's negligible enough.\nexport const generateBase36Code = (len: number): string =>\n Array.from(\n // Choose `Uint16Array` cause `2 ** 16 % 36 = 16`\n // It's greater than `2 ** 8 % 36 = 2 ** 32 % 36 = 4`.\n crypto.getRandomValues(new Uint16Array(len)),\n (num) => BASE36_CHAR[num % BASE36_CHAR.length],\n ).join(\"\");\n\nexport const hashSecret = async (raw: string): Promise<string> =>\n new Uint8Array(\n await crypto.subtle.digest(\"SHA-256\", textEncoder.encode(raw)),\n ).toHex();\n\nconst textEncoder = new TextEncoder();\n\nconst ACCESS_TOKEN_BYTES = 32;\n\nexport const generateAccessToken = (): string =>\n crypto.getRandomValues(new Uint8Array(ACCESS_TOKEN_BYTES)).toBase64({\n alphabet: \"base64url\",\n omitPadding: true,\n });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { Template } from \"@fedify/uri-template\";\nimport { GraphQLError } from \"graphql\";\n\nexport interface ExpandVerifyUrlParams {\n template: Template;\n challengeId: `${string}-${string}-${string}-${string}-${string}`;\n code: string;\n loginOrigins: ReadonlySet<string>;\n}\n\nexport default function expandVerifyUrl({\n template,\n challengeId,\n code,\n loginOrigins,\n}: ExpandVerifyUrlParams): string {\n assertVariable(template, \"challengeId\");\n assertVariable(template, \"code\");\n\n let url: URL;\n try {\n url = new URL(template.expand({ challengeId, code }));\n } catch {\n throw invalidVerifyUrl(\n \"Verify URL template must expand to an absolute URL.\",\n );\n }\n\n if (url.protocol !== \"https:\" && url.protocol !== \"http:\") {\n throw invalidVerifyUrl(\"Verify URL must use HTTP or HTTPS.\");\n }\n if (!loginOrigins.has(url.origin)) {\n throw invalidVerifyUrl(`Verify URL origin is not allowed: ${url.origin}.`);\n }\n return url.href;\n}\n\nfunction assertVariable(template: Template, name: string): void {\n const found = template.tokens.some(\n (token) =>\n token.kind === \"expression\" &&\n token.vars.some(\n (variable) => variable.name === name && variable.prefix == null,\n ),\n );\n if (!found) {\n throw invalidVerifyUrl(`Verify URL template must include {${name}}.`);\n }\n}\n\nconst invalidVerifyUrl = (message: string) =>\n new GraphQLError(message, { extensions: { code: \"BAD_USER_INPUT\" } });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { getLogger } from \"@logtape/logtape\";\nimport { type MessageContent, type Receipt, createMessage } from \"@upyo/core\";\n\nimport type { UserContext } from \"../builder.ts\";\n\n/** Send login mail without exposing non-cancellation provider failures. */\nexport async function sendMail(\n to: string,\n loginUrl: string,\n ctx: UserContext,\n): Promise<void> {\n const signal = ctx.operationSignal ?? ctx.request.signal;\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n try {\n const receipt = await ctx.mailer.send(\n createMessage({\n from: ctx.emailFrom,\n to,\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n subject: \"Sign in to DrFed\",\n content: renderLoginEmail(loginUrl),\n }),\n { signal },\n );\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logReceipt(receipt);\n } catch {\n if (signal.aborted) {\n throw new DOMException(\"Mail sending cancelled.\", \"AbortError\");\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"exception\" });\n }\n}\n\nconst renderLoginEmail = (loginUrl: string): MessageContent => ({\n // FIXME: https://github.com/fedify-dev/drfed/issues/35\n text: `Hello, Welcome to DrFed! If you request to login to DrFed, please visit:\n\nopen ${loginUrl}\n\nOtherwise, please just ignore this mail.`,\n});\n\nexport function logReceipt(receipt: Receipt<string>): void {\n if (receipt.successful) {\n logger.debug(\"Login mail delivery succeeded.\", { outcome: \"sent\" });\n return;\n }\n logger.warn(\"Login mail delivery failed.\", { outcome: \"failed\" });\n}\n\nconst logger = getLogger([\"drfed\", \"graphql\", \"auth\"]);\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { schema } from \"@drfed/models\";\nimport { type Uuid, uuidV7 } from \"@drfed/models/uuid\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\nimport expandVerifyUrl from \"./expand.ts\";\nimport { generateBase36Code } from \"./hash.ts\";\nimport { sendMail } from \"./mail.ts\";\n\ninterface LoginChallengeShape {\n readonly challengeId: Uuid;\n}\n\nconst LoginChallengeRef = builder\n .objectRef<LoginChallengeShape>(\"LoginChallenge\")\n .implement({\n description: \"An email login challenge.\",\n fields: (t) => ({\n challengeId: t.expose(\"challengeId\", {\n type: \"UUID\",\n description: \"The public identifier of the login challenge.\",\n }),\n }),\n });\n\nbuilder.mutationFields((t) => ({\n loginByEmail: t.field({\n type: LoginChallengeRef,\n description:\n \"Send a magic link without revealing whether the account exists.\",\n args: {\n email: t.arg({\n type: \"Email\",\n required: true,\n description: \"The email address of the `Account`.\",\n }),\n verifyUrl: t.arg({\n type: \"URITemplate\",\n required: true,\n description:\n \"Use {challengeId} and {code} variables. \" +\n \"The URL's origin must be in the server's login allowlist.\",\n }),\n },\n async resolve(_root, { email, verifyUrl }, ctx) {\n const challengeId = uuidV7();\n const code = generateBase36Code(schema.LOGIN_CHALLENGE_CODE_LENGTH);\n const loginUrl = expandVerifyUrl({\n challengeId,\n code,\n loginOrigins: ctx.loginOrigins,\n template: verifyUrl,\n });\n const account = await findAccount(email, ctx);\n if (account == null) {\n // Return an ID even for an unknown account to prevent account\n // enumeration. Consider mailing in a worker to prevent timing attacks.\n return { challengeId };\n }\n const verifier = {\n challengeId,\n code,\n };\n\n await insertChallenge(account.id, verifier, ctx);\n // Do not check the email was sent. Instructs users to request a resend if\n // the email does not arrive after a few minutes at the web page.\n await sendMail(account.email, loginUrl, ctx);\n\n return { challengeId };\n },\n }),\n}));\n\nconst findAccount = async (email: string, ctx: UserContext) =>\n await ctx.db.query.accounts.findFirst({\n where: { email },\n });\n\nconst insertChallenge = async (\n accountId: Uuid,\n { challengeId, code }: { challengeId: Uuid; code: string },\n ctx: UserContext,\n) =>\n await ctx.db.insert(schema.loginChallenges).values({\n id: challengeId,\n accountId,\n code,\n });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { Buffer } from \"node:buffer\";\nimport { timingSafeEqual } from \"node:crypto\";\n\nimport type { Database } from \"@drfed/models\";\nimport {\n LoginChallengeError,\n consumeLoginChallenge,\n findLoginChallenge,\n} from \"@drfed/models/login\";\nimport { sessions } from \"@drfed/models/schema\";\nimport type { Uuid } from \"@drfed/models/uuid\";\n\nimport builder from \"../builder.ts\";\nimport { generateAccessToken, hashSecret } from \"./hash.ts\";\n\nconst SessionRef = builder.drizzleObject(\"sessions\", {\n name: \"Session\",\n fields: (t) => ({\n id: t.expose(\"id\", { type: \"UUID\" }),\n accessToken: t.string({\n nullable: true,\n resolve(session) {\n const accessToken =\n \"accessToken\" in session ? session.accessToken : null;\n return typeof accessToken === \"string\" ? accessToken : null;\n },\n }),\n // The only `Session` a client can obtain is the one `completeLoginChallenge`\n // just created for it, and `Session` is not a `Node`, so the account behind\n // a session is always the viewer's own. Granting `ownAccount` here lets\n // the login response carry the viewer's private fields even though the\n // request that produced it had no session yet.\n account: t.relation(\"account\", { grantScopes: [\"ownAccount\"] }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n expires: t.expose(\"expires\", { type: \"DateTime\" }),\n }),\n});\n\nbuilder.mutationFields((t) => ({\n completeLoginChallenge: t.drizzleField({\n type: SessionRef,\n nullable: true,\n description: \"Complete login challenge.\",\n args: {\n challengeId: t.arg({ type: \"UUID\", required: true }),\n code: t.arg({ type: \"String\", required: true }),\n },\n async resolve(query, _root, { challengeId, code }, ctx) {\n try {\n const now = Temporal.Now.instant();\n const row = await findLoginChallenge(ctx.db, challengeId, now);\n const id = crypto.randomUUID();\n const accessToken = generateAccessToken();\n const accessHash = await hashSecret(accessToken);\n\n const providedCode = Buffer.from(code.toLowerCase());\n const expectedCode = Buffer.from(row.code);\n if (\n providedCode.length !== expectedCode.length ||\n !timingSafeEqual(providedCode, expectedCode)\n ) {\n throw new LoginChallengeError(\"The provided code does not match.\");\n }\n await ctx.db.transaction(async (tx) => {\n await consumeLoginChallenge(tx, row.id, now);\n await insertSession(id, row.accountId, accessHash, tx);\n });\n\n const session = await ctx.db.query.sessions.findFirst(\n query({ where: { id } }),\n );\n return session == null ? null : { ...session, accessToken };\n } catch (error) {\n if (error instanceof LoginChallengeError) {\n return null;\n }\n throw error;\n }\n },\n }),\n}));\n\nconst insertSession = async (\n id: Uuid,\n accountId: Uuid,\n tokenHash: string,\n tx: Database,\n) => await tx.insert(sessions).values({ id, accountId, tokenHash });\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable no-magic-numbers\n\nimport { sessions } from \"@drfed/models/schema\";\nimport { eq } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type UserContext } from \"../builder.ts\";\n\nbuilder.mutationFields((t) => ({\n revokeSession: t.field({\n type: LogoutSuccessRef,\n description: \"Revokes a session. Return always `revoke: true`.\",\n authScopes: {\n authenticated: true,\n },\n async resolve(_query, _, ctx) {\n const sessionId = ctx.session?.id;\n if (sessionId) {\n await deleteSession(ctx);\n }\n // Return always true to prevent brute-force attack.\n return { revoke: true };\n },\n }),\n}));\n\ninterface LogoutSuccessShape {\n revoke: boolean;\n}\n\nconst LogoutSuccessRef = builder\n .objectRef<LogoutSuccessShape>(\"LogoutSuccess\")\n .implement({\n description: \"The session revoked.\",\n fields: (t) => ({\n revoke: t.expose(\"revoke\", {\n type: \"Boolean\",\n description: \"Revoking status.\",\n }),\n }),\n });\n\nconst deleteSession = (ctx: UserContext) =>\n ctx.db.delete(sessions).where(eq(sessions.id, ctx.session!.id));\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable import/no-unassigned-import\nimport \"./magic-link.ts\";\nimport \"./challenge.ts\";\nimport \"./revoke.ts\";\nimport builder from \"../builder.ts\";\n\nbuilder.queryFields((t) => ({\n viewer: t.drizzleField({\n type: \"accounts\",\n nullable: true,\n description: \"`Account` if authorized, else `null`\",\n resolve: (query, _root, _args, ctx) =>\n ctx.session == null\n ? null\n : ctx.db.query.accounts.findFirst(\n query({ where: { id: ctx.session.accountId } }),\n ),\n }),\n}));\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\n\nconst KeyRef = builder.drizzleNode(\"keys\", {\n name: \"Key\",\n description:\n \"A remote public key, identified by its IRI. Readable by any \" +\n \"authenticated viewer, since it holds public material only.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (key) => key.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n iri: t.expose(\"iri\", { type: \"URL\" }),\n created: t.expose(\"created\", { type: \"DateTime\" }),\n versions: t.relatedConnection(\"versions\", {\n description: \"The observed versions of the key, oldest first.\",\n query: { orderBy: { firstSeen: \"asc\", id: \"asc\" } },\n }),\n }),\n});\nexport const Key: DrFedObjectRef = KeyRef;\nconst observationDescription =\n \"DrFed observation time, not the remote key rotation time; \" +\n \"does not imply continuous use between observations.\";\nconst KeyVersionRef = builder.drizzleNode(\"keyVersions\", {\n name: \"KeyVersion\",\n description:\n \"Immutable public key material observed under a `Key`. Readable by \" +\n \"any authenticated viewer.\",\n authScopes: { authenticated: true },\n runScopesOnType: true,\n id: { column: (version) => version.id },\n fields: (t) => ({\n uuid: t.expose(\"id\", { type: \"UUID\" }),\n key: t.relation(\"key\"),\n publicKey: t.expose(\"publicKey\", { type: \"JSON\" }),\n fingerprint: t.exposeString(\"fingerprint\"),\n firstSeen: t.expose(\"firstSeen\", {\n type: \"DateTime\",\n description: `First ${observationDescription}`,\n }),\n lastSeen: t.expose(\"lastSeen\", {\n type: \"DateTime\",\n description: `Last ${observationDescription}`,\n }),\n }),\n});\nexport const KeyVersion: DrFedObjectRef = KeyVersionRef;\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n// oxlint-disable import/no-unassigned-import\nimport \"./account.ts\";\nimport \"./instance.ts\";\nimport \"./auth/entry.ts\";\nimport \"./actor.ts\";\nimport \"./object.ts\";\nimport \"./activity-delivery/entry.ts\";\nimport \"./key.ts\";\nimport builder from \"./builder.ts\";\n\nbuilder.queryType({});\nbuilder.mutationType({});\n\nexport const schema = builder.toSchema();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,cAAc;AAGpB,MAAa,sBAAsB,QACjC,MAAM,KAGJ,OAAO,gBAAgB,IAAI,YAAY,GAAG,CAAC,IAC1C,QAAQ,YAAY,MAAM,GAC7B,CAAC,CAAC,KAAK,EAAE;AAEX,MAAa,aAAa,OAAO,QAC/B,IAAI,WACF,MAAM,OAAO,OAAO,OAAO,WAAW,YAAY,OAAO,GAAG,CAAC,CAC/D,CAAC,CAAC,MAAM;AAEV,MAAM,cAAc,IAAI,YAAY;AAEpC,MAAM,qBAAqB;AAE3B,MAAa,4BACX,OAAO,gBAAgB,IAAI,WAAW,kBAAkB,CAAC,CAAC,CAAC,SAAS;CAClE,UAAU;CACV,aAAa;AACf,CAAC;;;AChBH,SAAwB,gBAAgB,EACtC,UACA,aACA,MACA,gBACgC;CAChC,eAAe,UAAU,aAAa;CACtC,eAAe,UAAU,MAAM;CAE/B,IAAI;CACJ,IAAI;EACF,MAAM,IAAI,IAAI,SAAS,OAAO;GAAE;GAAa;EAAK,CAAC,CAAC;CACtD,QAAQ;EACN,MAAM,iBACJ,qDACF;CACF;CAEA,IAAI,IAAI,aAAa,YAAY,IAAI,aAAa,SAChD,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AAO;EACd,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,OAAO,CAAC;EACrC,KAAK,EAAE,OAAO,OAAO,EAAE,MAAM,MAAM,CAAC;EACpC,SAAS,EAAE,OAAO,WAAW,EAAE,MAAM,WAAW,CAAC;EACjD,UAAU,EAAE,kBAAkB,YAAY;GACxC,aAAa;GACb,OAAO,EAAE,SAAS;IAAE,WAAW;IAAO,IAAI;GAAM,EAAE;EACpD,CAAC;CACH;AACF,CAAC;AAED,MAAM,yBACJ;AAEoB,QAAQ,YAAY,eAAe;CACvD,MAAM;CACN,aACE;CAEF,YAAY,EAAE,eAAe,KAAK;CAClC,iBAAiB;CACjB,IAAI,EAAE,SAAS,YAAY,QAAQ,GAAG;CACtC,SAAS,OAAO;EACd,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,OAAO,CAAC;EACrC,KAAK,EAAE,SAAS,KAAK;EACrB,WAAW,EAAE,OAAO,aAAa,EAAE,MAAM,OAAO,CAAC;EACjD,aAAa,EAAE,aAAa,aAAa;EACzC,WAAW,EAAE,OAAO,aAAa;GAC/B,MAAM;GACN,aAAa,SAAS;EACxB,CAAC;EACD,UAAU,EAAE,OAAO,YAAY;GAC7B,MAAM;GACN,aAAa,QAAQ;EACvB,CAAC;CACH;AACF,CAAC;;;ACrCD,QAAQ,UAAU,CAAC,CAAC;AACpB,QAAQ,aAAa,CAAC,CAAC;AAEvB,MAAaA,WAAS,QAAQ,SAAS"}
|
package/dist/schema.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schema } from "./schema-
|
|
1
|
+
export { t as schema } from "./schema-f-SnZVb9.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drfed/graphql",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.651",
|
|
4
4
|
"description": "A GraphQL server for DrFed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ActivityPub",
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
"typescript": "^7.0.2"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@drfed/federation": "0.2.0-dev.
|
|
113
|
-
"@drfed/models": "0.2.0-dev.
|
|
112
|
+
"@drfed/federation": "0.2.0-dev.651",
|
|
113
|
+
"@drfed/models": "0.2.0-dev.651",
|
|
114
114
|
"@faker-js/faker": "^10.5.0",
|
|
115
115
|
"@fedify/uri-template": "^2.3.1",
|
|
116
116
|
"@fedify/fedify": "2.4.3",
|
|
@@ -140,13 +140,13 @@
|
|
|
140
140
|
},
|
|
141
141
|
"drfedBuild": {
|
|
142
142
|
"enabled": true,
|
|
143
|
-
"version": "0.2.0-dev.
|
|
144
|
-
"fullVersion": "0.2.0-dev.
|
|
143
|
+
"version": "0.2.0-dev.651",
|
|
144
|
+
"fullVersion": "0.2.0-dev.651+af640f3f",
|
|
145
145
|
"baseVersion": "0.2.0",
|
|
146
146
|
"channel": "dev",
|
|
147
|
-
"sha": "
|
|
148
|
-
"runNumber": "
|
|
149
|
-
"runId": "
|
|
147
|
+
"sha": "af640f3ff3c8e043e1550041bc8f79e32248486c",
|
|
148
|
+
"runNumber": "651",
|
|
149
|
+
"runId": "40699609579",
|
|
150
150
|
"ref": "refs/heads/main",
|
|
151
151
|
"workflow": ".github/workflows/main.yaml"
|
|
152
152
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actor-BJvviz6Q.mjs","names":["and","eq","uuid"],"sources":["../src/resource.ts","../src/actor.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { activitySelection, objectSelection } from \"@drfed/federation/object\";\nimport { schema } from \"@drfed/models\";\nimport type { Resource as ResourceRow } from \"@drfed/models/schema\";\nimport { type Uuid, validateUuid } from \"@drfed/models/uuid\";\nimport { PothosValidationError } from \"@pothos/core\";\nimport { resolveCursorConnection } from \"@pothos/plugin-relay\";\nimport { type SQL, type SQLWrapper, and, eq, sql } from \"drizzle-orm\";\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport {\n classificationAuthor,\n classificationInput,\n classifyMastodon,\n classifyMisskey,\n} from \"./classification.ts\";\nimport {\n type Viewer,\n isReadableResource,\n readableResource,\n} from \"./readable.ts\";\n\nexport const ResourceKind = builder.enumType(\"ResourceKind\", {\n values: schema.resourceKindEnum.enumValues,\n});\nexport const ResourceDetail = builder.unionType(\"ResourceDetail\", {\n types: () => [Activity, Collection],\n resolveType: async (value, ctx) => {\n const { id } = value as { id: Uuid };\n const row = await ctx.db.query.resources.findFirst({ where: { id } });\n if (row == null || row.kind === \"unknown\") {\n throw new Error(\"Missing typed resource.\");\n }\n return (\n {\n actor: \"Actor\",\n object: \"Object\",\n activity: \"Activity\",\n collection: \"Collection\",\n } as const\n )[row.kind];\n },\n});\nconst ResourceRef = builder.drizzleNode(\"resources\", {\n name: \"Resource\",\n id: { column: (row) => row.id },\n fields: (t) => ({\n iri: t.expose(\"iri\", { type: \"URL\" }),\n kind: t.expose(\"kind\", { type: ResourceKind }),\n detail: t.field({\n type: ResourceDetail,\n nullable: true,\n description:\n \"Typed details, or null while unknown, when the typed row or its author/owner is deleted, or when the viewer may not read it.\",\n select: { columns: { id: true, iri: true, kind: true } },\n resolve: (row, _, ctx) => resolveResource(ctx, row),\n }),\n }),\n});\nexport const Resource: DrFedObjectRef = ResourceRef;\n\n/**\n * Loads the typed record so union fragments see the complete entity.\n * @returns The typed entity, or null when it or its author is deleted, or when\n * the viewer may not read it.\n */\nexport async function resolveResource(\n viewer: Viewer,\n row: ResourceRow,\n): Promise<{ id: Uuid } | null> {\n const { db } = viewer;\n const visible = await db.query.resources.findFirst({\n where: {\n id: row.id,\n RAW: (table) =>\n and(visibleResource(table.id), readableResource(viewer, table.id))!,\n },\n columns: { id: true },\n });\n if (visible == null) return null;\n if (row.kind === \"unknown\") return null;\n const where = { id: row.id };\n const result =\n row.kind === \"actor\"\n ? await db.query.actors.findFirst({ where })\n : row.kind === \"object\"\n ? await db.query.objects.findFirst({ where })\n : row.kind === \"activity\"\n ? await db.query.activities.findFirst({ where })\n : await db.query.collections.findFirst({ where });\n if (result == null) {\n throw new Error(`Missing ${row.kind} record for ${row.iri}.`);\n }\n return result;\n}\n\nexport function registerAddressingFields(\n table: \"objects\" | \"activities\",\n): void {\n for (const property of schema.addressingPropertyEnum.enumValues) {\n builder.drizzleObjectField(table, property, (t) =>\n t.field({\n type: [Resource],\n description: `Stored ${property} occurrences, in original order including duplicates.`,\n select: { columns: { id: true } },\n resolve: async (row, _, ctx) =>\n (\n await ctx.db.query.addressing.findMany({\n where: { sourceId: row.id, property },\n orderBy: { position: \"asc\" },\n with: { targetResource: true },\n })\n ).map((entry) => entry.targetResource),\n }),\n );\n }\n}\n\nconst CollectionType = builder.enumType(\"CollectionType\", {\n values: schema.collectionTypeEnum.enumValues,\n});\nconst CollectionRef = builder.drizzleNode(\"collections\", {\n name: \"Collection\",\n select: {\n columns: { id: true },\n with: { ownerActor: { columns: { deleted: true } } },\n },\n id: { column: (row) => row.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n type: t.expose(\"type\", { type: CollectionType }),\n owner: t.relation(\"ownerActor\", {\n nullable: true,\n query: { where: { deleted: { isNull: true } } },\n }),\n declaredTotalItems: t.exposeInt(\"totalItems\", {\n nullable: true,\n description:\n \"The `totalItems` reported by the collection document. It can differ from the locally observed count and is null for local collections. Unlike `totalCount` and `items`, this value is not recalculated when deleted actors, deleted objects, or resources authored by deleted actors are excluded.\",\n }),\n totalCount: t.int({\n description:\n \"The number of locally stored, visible members. It can differ from `declaredTotalItems`. Deleted actors, deleted objects, resources authored by deleted actors, and resources the viewer may not read are excluded from this count and `items`.\",\n select: { columns: { id: true } },\n resolve: (row, _, ctx) =>\n ctx.db.$count(\n schema.collectionItems,\n and(\n eq(schema.collectionItems.collectionId, row.id),\n visibleResource(schema.collectionItems.itemId),\n readableResource(ctx, schema.collectionItems.itemId),\n ),\n ),\n }),\n items: t.connection({\n type: Resource,\n description:\n \"The locally stored, visible members. Deleted actors, deleted objects, resources authored by deleted actors, and resources the viewer may not read are excluded from this connection and `totalCount`.\",\n select: { columns: { id: true } },\n resolve: (row, args, ctx) => {\n const positions = new Map<Uuid, number | null>();\n return resolveCursorConnection<Promise<ResourceRow[]>>(\n {\n args,\n toCursor: (item: ResourceRow) => {\n if (!positions.has(item.id)) {\n throw new Error(\"Missing collection item position.\");\n }\n return encodeCollectionCursor({\n position: positions.get(item.id)!,\n itemId: item.id,\n });\n },\n },\n async ({ before, after, limit, inverted }) => {\n const parsedBefore =\n before == null ? undefined : parseCollectionCursor(before);\n const parsedAfter =\n after == null ? undefined : parseCollectionCursor(after);\n const items = await ctx.db.query.collectionItems.findMany({\n where: {\n collectionId: row.id,\n RAW: (table) =>\n and(\n visibleResource(table.itemId),\n readableResource(ctx, table.itemId),\n collectionCursorPredicate(\n table.position,\n table.itemId,\n parsedBefore,\n parsedAfter,\n ),\n )!,\n },\n orderBy: collectionItemsOrder(inverted),\n limit,\n with: { item: true },\n });\n for (const item of items) {\n positions.set(item.itemId, item.position);\n }\n return items.map((item) => item.item);\n },\n );\n },\n }),\n }),\n});\nexport const Collection: DrFedObjectRef = CollectionRef;\n\ninterface CollectionCursor {\n position: number | null;\n itemId: Uuid;\n}\n\nconst BASE64_PATTERN =\n /^(?:[A-Za-z\\d+/]{4})*(?:[A-Za-z\\d+/]{2}==|[A-Za-z\\d+/]{3}=)?$/u;\n\nfunction encodeCollectionCursor(cursor: CollectionCursor): string {\n return Buffer.from(JSON.stringify([cursor.position, cursor.itemId])).toString(\n \"base64\",\n );\n}\n\nfunction parseCollectionCursor(cursor: string): CollectionCursor {\n if (cursor === \"\" || !BASE64_PATTERN.test(cursor)) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n const decoded = Buffer.from(cursor, \"base64\");\n if (decoded.toString(\"base64\") !== cursor) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n let value: unknown;\n try {\n value = JSON.parse(decoded.toString(\"utf8\"));\n } catch {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n if (!Array.isArray(value) || value.length !== 2) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n const [position, itemId] = value;\n if (\n (position !== null &&\n (!Number.isInteger(position) ||\n position < -2_147_483_648 ||\n position > 2_147_483_647)) ||\n !validateUuid(itemId)\n ) {\n throw new PothosValidationError(\"Invalid collection cursor.\");\n }\n return { position, itemId };\n}\n\nfunction collectionCursorPredicate(\n positionColumn: SQLWrapper,\n itemIdColumn: SQLWrapper,\n before?: CollectionCursor,\n after?: CollectionCursor,\n): SQL | undefined {\n return and(\n after == null\n ? undefined\n : after.position == null\n ? sql`${positionColumn} is null and ${itemIdColumn} > ${after.itemId}`\n : sql`(\n ${positionColumn} > ${after.position}\n or (${positionColumn} = ${after.position} and ${itemIdColumn} > ${after.itemId})\n or ${positionColumn} is null\n )`,\n before == null\n ? undefined\n : before.position == null\n ? sql`(\n ${positionColumn} is not null\n or (${positionColumn} is null and ${itemIdColumn} < ${before.itemId})\n )`\n : sql`(\n ${positionColumn} < ${before.position}\n or (${positionColumn} = ${before.position} and ${itemIdColumn} < ${before.itemId})\n )`,\n );\n}\n\nfunction collectionItemsOrder(inverted: boolean): {\n position: \"asc\" | \"desc\";\n itemId: \"asc\" | \"desc\";\n} {\n // The keyset predicates rely on PostgreSQL's default ASC NULLS LAST and\n // DESC NULLS FIRST ordering.\n const direction = inverted ? \"desc\" : \"asc\";\n return { position: direction, itemId: direction };\n}\n\nconst Implementation = builder.enumType(\"Implementation\", {\n values: [\"MASTODON\", \"MISSKEY\"] as const,\n});\nconst ExpectedClassification = builder.objectRef<\n ReturnType<typeof classifyMastodon>\n>(\"ExpectedClassification\");\nExpectedClassification.implement({\n description:\n \"Expected classification; actual access depends on receiver state and policy.\",\n fields: (t) => ({\n implementation: t.expose(\"implementation\", { type: Implementation }),\n version: t.exposeString(\"version\"),\n classification: t.exposeString(\"classification\"),\n reason: t.exposeString(\"reason\"),\n }),\n});\nexport const ActivityType = builder.enumType(\"ActivityType\", {\n values: schema.activityTypeEnum.enumValues,\n});\nconst ActivityRef = builder.drizzleNode(\"activities\", {\n name: \"Activity\",\n description:\n \"Represents an ActivityPub activity. An activity of a local actor is \" +\n \"readable whatever its addressing. One of a remote actor is readable \" +\n \"only when it is addressed to the public, by members of the local \" +\n \"instances that received it, and by administrators; otherwise it is \" +\n \"left out as if it did not exist.\",\n select: {\n columns: { id: true },\n with: { actor: { columns: { deleted: true } } },\n },\n id: { column: (row) => row.id },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n type: t.expose(\"type\", { type: ActivityType }),\n actor: t.relation(\"actor\"),\n object: t.field({\n type: Resource,\n nullable: true,\n description:\n \"The resource the activity acts on, or null when there is none or \" +\n \"the viewer may not read it.\",\n select: { with: { object: true } },\n resolve: async (row, _, ctx) =>\n row.object != null && (await isReadableResource(ctx, row.object.id))\n ? row.object\n : null,\n }),\n expectedClassifications: t.field({\n type: [ExpectedClassification],\n description:\n \"Expected classifications for this activity and its Object. Empty if the object is absent, hidden, or not an Object.\",\n select: { columns: { id: true } },\n resolve: async (activity, _, ctx) => {\n const row = await ctx.db.query.activities.findFirst({\n where: { id: activity.id },\n with: activitySelection,\n });\n // As hidden from this viewer as `object` is, its addressing included.\n if (\n row?.objectId == null ||\n !(await isReadableResource(ctx, row.objectId))\n ) {\n return [];\n }\n const object = await ctx.db.query.objects.findFirst({\n where: {\n id: row.objectId,\n deleted: { isNull: true },\n actor: { deleted: { isNull: true } },\n },\n with: {\n ...objectSelection,\n actor: {\n with: {\n resource: true,\n collectionReferences: {\n with: { collection: { with: { resource: true } } },\n },\n },\n },\n },\n });\n if (object == null) return [];\n const addressing = classificationInput(object);\n const input = classificationInput(row);\n const author = classificationAuthor(object.actor);\n return [\n classifyMastodon(addressing, input, author),\n classifyMisskey(addressing, input, author),\n ];\n },\n }),\n published: t.expose(\"published\", { type: \"DateTime\" }),\n document: t.expose(\"document\", { type: \"JSON\", nullable: true }),\n }),\n});\nexport const Activity: DrFedObjectRef = ActivityRef;\nregisterAddressingFields(\"activities\");\n\n/**\n * Excludes deleted actors and objects, including resources authored or\n * owned by deleted actors.\n * @returns A predicate for a resource ID in an outer query.\n */\nfunction visibleResource(id: SQLWrapper): SQL {\n return sql`not exists (\n select 1 from ${schema.actors}\n where ${schema.actors.id} = ${id} and ${schema.actors.deleted} is not null\n ) and not exists (\n select 1 from ${schema.objects}\n join ${schema.actors} on ${schema.actors.id} = ${schema.objects.actorId}\n where ${schema.objects.id} = ${id}\n and (${schema.objects.deleted} is not null or ${schema.actors.deleted} is not null)\n ) and not exists (\n select 1 from ${schema.activities}\n join ${schema.actors} on ${schema.actors.id} = ${schema.activities.actorId}\n where ${schema.activities.id} = ${id} and ${schema.actors.deleted} is not null\n ) and not exists (\n select 1 from ${schema.collections}\n join ${schema.actors} on ${schema.actors.id} = ${schema.collections.ownerActorId}\n where ${schema.collections.id} = ${id} and ${schema.actors.deleted} is not null\n )`;\n}\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\n// oxlint-disable max-lines-per-function eslint/max-lines\n\n// Keep dependent database writes and observations sequential.\n// oxlint-disable no-await-in-loop\n\nimport { enqueueActorKeyGeneration } from \"@drfed/federation\";\nimport { type Database, promoteResource, schema } from \"@drfed/models\";\nimport { type CollectionRole, actorTypeEnum } from \"@drfed/models/schema\";\nimport { type Uuid, uuidV7 as uuid } from \"@drfed/models/uuid\";\nimport { faker } from \"@faker-js/faker\";\nimport type { Context } from \"@fedify/fedify\";\nimport { drizzleConnectionHelpers } from \"@pothos/plugin-drizzle\";\nimport type { PgInsertValue } from \"drizzle-orm/pg-core\";\nimport { and, eq, gt, isNotNull, isNull } from \"drizzle-orm/sql/expressions\";\n\nimport builder, { type DrFedObjectRef } from \"./builder.ts\";\nimport { Instance } from \"./instance.ts\";\nimport { Collection, ResourceDetail } from \"./resource.ts\";\n\nconst ActorType = builder.enumType(\"ActorType\", {\n values: actorTypeEnum.enumValues,\n});\n\nconst ACTOR_TYPES_DOC = actorTypeEnum.enumValues\n .map((t) => `\\`${t}\\``)\n .join(\" | \");\n\nasync function resolveActorCollection(\n db: Database,\n actorId: Uuid,\n role: CollectionRole,\n) {\n const reference = await db.query.actorCollectionReferences.findFirst({\n where: { actorId, role },\n with: {\n collection: {\n with: { ownerActor: { columns: { deleted: true } } },\n },\n },\n });\n const collection = reference?.collection;\n return collection?.ownerActor?.deleted == null ? (collection ?? null) : null;\n}\n\nconst USERNAME_DOC =\n \"The username of the `Actor`. A remote actor's is its \" +\n \"`preferredUsername` as received, which is null when it has none and \" +\n \"need not be unique.\";\n\nconst ActorRef = builder.drizzleNode(\"actors\", {\n name: \"Actor\",\n description: \"Represents an `Actor` in the DrFed platform.\",\n id: {\n column: ({ id }) => id,\n description: \"The unique identifier of the `Actor`.\",\n },\n fields: (t) => ({\n resource: t.relation(\"resource\"),\n iri: t.field({\n type: \"URL\",\n select: { with: { resource: true } },\n resolve: (row) => row.resource.iri,\n }),\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the `Actor`.\",\n }),\n handle: t.field({\n type: \"String\",\n nullable: true,\n description:\n \"The handle of the `Actor`, its `username` and its `Instance`'s \" +\n \"host. For a remote actor, this is not a verified WebFinger \" +\n \"address. Null when `username` is.\",\n select: {\n columns: { username: true },\n with: { instance: { columns: { host: true } } },\n },\n resolve: ({ instance, username }) =>\n username == null ? null : `@${username}@${instance.host}`,\n }),\n type: t.expose(\"type\", {\n type: ActorType,\n description: `The type of the \\`Actor\\`: ${ACTOR_TYPES_DOC}`,\n }),\n username: t.exposeString(\"username\", {\n nullable: true,\n description: USERNAME_DOC,\n }),\n instance: t.relation(\"instance\", {\n description: \"The `Instance` that the `Actor` belongs to.\",\n }),\n local: t.relation(\"localActor\", {\n nullable: true,\n description: \"The local details of the `Actor`, or null if it is remote.\",\n }),\n inboxUrl: t.expose(\"inboxUrl\", {\n type: \"URL\",\n description: \"The inbox URL of the `Actor`.\",\n }),\n outbox: t.field({\n type: Collection,\n nullable: true,\n description:\n \"The stored outbox collection. For local actors, it contains every stored `Create` activity regardless of addressing and retains activities whose objects are deleted so their recorded history remains inspectable. The ActivityPub outbox serves only activities with Public addressing whose objects are not deleted.\",\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"outbox\"),\n }),\n avatarUrl: t.expose(\"avatarUrl\", {\n type: \"URL\",\n description: \"The avatar URL of the `Actor`.\",\n nullable: true,\n }),\n followers: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"followers\"),\n }),\n following: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"following\"),\n }),\n headerUrl: t.expose(\"headerUrl\", {\n type: \"URL\",\n description: \"The header URL of the `Actor`.\",\n nullable: true,\n }),\n profileUrl: t.expose(\"profileUrl\", {\n type: \"URL\",\n description: \"The profile URL of the `Actor`.\",\n nullable: true,\n }),\n featured: t.field({\n type: Collection,\n nullable: true,\n select: { columns: { id: true } },\n resolve: (actor, _, ctx) =>\n resolveActorCollection(ctx.db, actor.id, \"featured\"),\n }),\n created: t.expose(\"created\", {\n type: \"DateTime\",\n description: \"The creation date/time of the `Actor`.\",\n }),\n }),\n});\n\nexport const Actor: DrFedObjectRef = ActorRef;\nResourceDetail.addTypes([Actor]);\n\nconst LocalActorRef = builder.drizzleNode(\"localActors\", {\n name: \"LocalActor\",\n select: {\n columns: { id: true },\n with: { actor: { columns: { deleted: true } } },\n },\n description: \"Represents the local details of an `Actor`.\",\n id: {\n column: ({ id }) => id,\n description: \"The unique identifier of the local actor details.\",\n },\n fields: (t) => ({\n uuid: t.expose(\"id\", {\n type: \"UUID\",\n description: \"The UUID of the local actor details.\",\n }),\n avatar: t.exposeString(\"avatar\", {\n nullable: true,\n description: \"The profile image of the actor.\",\n }),\n header: t.exposeString(\"header\", {\n nullable: true,\n description: \"The profile banner image of the actor.\",\n }),\n }),\n});\n\nexport const LocalActor: DrFedObjectRef = LocalActorRef;\n\ninterface CreateActorsSuccess {\n readonly actors: readonly (typeof ActorRef.$inferType)[];\n}\n\nconst CreateActorsSuccessRef = builder.objectRef<CreateActorsSuccess>(\n \"CreateActorsSuccess\",\n);\n\nCreateActorsSuccessRef.implement({\n fields: (t) => ({\n actors: t.field({\n type: [ActorRef],\n resolve: ({ actors }) => actors,\n }),\n }),\n});\n\nconst INVALID_SIZE = \"InvalidSize\" as const;\nconst INSTANCE_NOT_FOUND = \"InstanceNotFound\" as const;\nconst INVALID_INSTANCE_HOST = \"InvalidInstanceHost\" as const;\nconst TOO_MANY_ACTORS = \"TooManyActors\" as const;\nconst CreateActorsErrors = [\n INVALID_SIZE,\n INSTANCE_NOT_FOUND,\n INVALID_INSTANCE_HOST,\n TOO_MANY_ACTORS,\n] as const;\n\nconst CreateActorsErrorType = builder.enumType(\"CreateActorsErrorType\", {\n values: CreateActorsErrors,\n});\n\ninterface CreateActorsError {\n readonly type: typeof CreateActorsErrorType.$inferType;\n readonly message: string;\n}\n\nconst CreateActorsErrorRef =\n builder.objectRef<CreateActorsError>(\"CreateActorsError\");\n\nCreateActorsErrorRef.implement({\n description: \"Represents an error that occurred while creating an `Actor`.\",\n fields: (t) => ({\n type: t.expose(\"type\", {\n type: CreateActorsErrorType,\n description:\n \"The type of the error. Use this for programmatic error handling.\",\n }),\n message: t.exposeString(\"message\", {\n description:\n \"A human-readable message describing the error. \" +\n \"Don't use this for programmatic error handling, \" +\n \"use the `type` field instead.\",\n }),\n }),\n});\n\nconst CreateActorsResult = builder.unionType(\"CreateActorsResult\", {\n types: [CreateActorsSuccessRef, CreateActorsErrorRef],\n resolveType(value) {\n if (\"message\" in value) return CreateActorsErrorRef;\n return CreateActorsSuccessRef;\n },\n});\n\nbuilder.mutationFields((t) => ({\n generateActors: t.field({\n type: CreateActorsResult,\n description: \"Create actors.\",\n authScopes: { authenticated: true },\n args: {\n instance: t.arg.globalID({\n for: Instance,\n required: true,\n description: \"The ID of the target instance\",\n }),\n size: t.arg({\n type: \"Int\",\n required: true,\n description: \"How many actors to generate\",\n }),\n },\n async resolve(_query, { instance: { id: instanceId }, size }, ctx) {\n if (size < 1) {\n return {\n type: INVALID_SIZE,\n message: `${size} is too small. At least 1 or more.`,\n };\n }\n if (ctx.account == null) {\n // Note that the following error is not expected to be thrown,\n // because the `authScopes` option above should prevent this resolver\n throw new Error(\"You must be authenticated to create actors.\");\n }\n const { account } = ctx;\n // Relay decodes global IDs as strings; Instance uses UUID identifiers.\n const targetInstanceId = instanceId as Uuid;\n\n let createdOrigin: URL | undefined;\n const result = await ctx.db.transaction(async (tx) => {\n // Find the instance that the account is included\n const [instance] = await tx\n .select({\n host: schema.instances.host,\n maxActors: schema.localInstances.maxActors,\n })\n .from(schema.instanceMembers)\n .for(\"update\", { of: schema.localInstances })\n .innerJoin(\n schema.instances,\n eq(schema.instanceMembers.instanceId, schema.instances.id),\n )\n .innerJoin(\n schema.localInstances,\n eq(schema.instances.localId, schema.localInstances.id),\n )\n .where(\n and(\n eq(schema.instanceMembers.accountId, account.id),\n gt(schema.localInstances.expires, Temporal.Now.instant()),\n eq(schema.instances.id, targetInstanceId),\n isNotNull(schema.instanceMembers.accepted),\n ),\n )\n .limit(1);\n if (instance == null) {\n return {\n type: INSTANCE_NOT_FOUND,\n message: \"Can't find the instance.\",\n };\n }\n // Read the stored authority rather than recomposing it from the\n // slug, so that actor URIs cannot drift from the instance the rest of\n // the fediverse already knows.\n const { host, maxActors } = instance;\n const instanceUrl = `${ctx.rootOrigin.protocol}//${host}`;\n // Stored authorities can outlive the runtime that accepted them.\n if (!URL.canParse(instanceUrl)) {\n return {\n type: INVALID_INSTANCE_HOST,\n message:\n `The instance host ${JSON.stringify(host)} cannot be parsed by ` +\n \"this server. Contact the server administrator.\",\n };\n }\n const currActors = await tx.$count(\n schema.actors,\n eq(schema.actors.instanceId, targetInstanceId),\n );\n\n if (size + currActors > maxActors) {\n return {\n type: TOO_MANY_ACTORS,\n message: `${size} is too big. The maximum number of actors of ${\n host\n } is ${maxActors} and the current number of actors is ${\n currActors\n }.`,\n };\n }\n // Create actors\n createdOrigin = new URL(instanceUrl);\n const fedCtx = ctx.federation.createContext(\n new URL(instanceUrl),\n undefined,\n );\n const ids = Array.from({ length: size }, () => ({ id: uuid() }));\n await tx.insert(schema.localActors).values(ids);\n const createdActors = [];\n for (const { id } of ids) {\n const actor = await promoteResource(\n tx,\n fedCtx.getActorUri(id).href,\n \"actor\",\n async (inner, resource) => {\n for (let attempt = 0; attempt < 10; attempt += 1) {\n const [createdActor] = await inner\n .insert(schema.actors)\n .values(generateActor(resource.id, targetInstanceId, fedCtx))\n .onConflictDoNothing({\n target: [schema.actors.username, schema.actors.instanceId],\n // Only the partial index of local actors' usernames.\n where: isNotNull(schema.actors.localId),\n })\n .returning();\n if (createdActor != null) {\n return createdActor;\n }\n }\n throw new Error(\"Actor insertion returned no row.\");\n },\n id,\n );\n for (const [role, iri] of [\n [\"followers\", fedCtx.getFollowersUri(id).href],\n [\"following\", fedCtx.getFollowingUri(id).href],\n [\"featured\", fedCtx.getFeaturedUri(id).href],\n [\"outbox\", fedCtx.getOutboxUri(id).href],\n ] as const) {\n await promoteResource(\n tx,\n iri,\n \"collection\",\n async (inner, resource) => {\n await inner.insert(schema.collections).values({\n id: resource.id,\n type: \"OrderedCollection\",\n ownerActorId: actor.id,\n });\n await inner.insert(schema.actorCollectionReferences).values({\n actorId: actor.id,\n role,\n collectionId: resource.id,\n });\n },\n );\n }\n createdActors.push(actor);\n }\n return { actors: createdActors };\n });\n if (\"actors\" in result && createdOrigin != null) {\n await enqueueActorKeyGeneration(\n ctx.federation.createContext(createdOrigin, undefined),\n result.actors.map((actor) => actor.id),\n );\n }\n return result;\n },\n }),\n}));\n\nfunction generateActor(\n id: Uuid,\n instanceId: Uuid,\n fedCtx: Context<unknown>,\n): PgInsertValue<typeof schema.actors> {\n const username = faker.internet\n .username()\n .toLowerCase()\n .replace(/[^a-z0-9_]/gu, \"_\");\n\n return {\n id,\n localId: id,\n username,\n instanceId,\n type: \"Person\",\n inboxUrl: fedCtx.getInboxUri(id).href,\n profileUrl: new URL(`/@${username}`, fedCtx.origin).href,\n };\n}\n\nconst actorsConnection = drizzleConnectionHelpers(builder, \"actors\", {\n query: { orderBy: { created: \"desc\", id: \"desc\" } },\n});\n\nbuilder.drizzleObjectField(\"instances\", \"actors\", (t) =>\n t.connection(\n {\n type: Actor,\n description: \"The `Actor`s that belong to the `Instance`.\",\n select(args, ctx, nestedSelection) {\n return {\n with: {\n actors: actorsConnection.getQuery(args, ctx, nestedSelection),\n },\n };\n },\n resolve(instance, args, ctx) {\n return {\n ...actorsConnection.resolve(instance.actors, args, ctx, instance),\n totalCount() {\n return ctx.db.$count(\n schema.actors,\n and(\n eq(schema.actors.instanceId, instance.id),\n isNull(schema.actors.deleted),\n ),\n );\n },\n };\n },\n },\n {\n fields(fb) {\n return {\n totalCount: fb.int({\n description:\n \"The total number of `Actor`s that belong to the `Instance`.\",\n resolve(connection) {\n return connection.totalCount();\n },\n }),\n };\n },\n },\n {\n fields(fb) {\n return {\n created: fb.expose(\"created\", {\n type: \"DateTime\",\n description:\n \"The date/time when the `Actor` was added to the `Instance`.\",\n }),\n type: fb.expose(\"type\", {\n type: ActorType,\n description: `The type of the \\`Actor\\`: ${ACTOR_TYPES_DOC}`,\n }),\n username: fb.exposeString(\"username\", {\n nullable: true,\n description: USERNAME_DOC,\n }),\n };\n },\n },\n ),\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,eAAe,QAAQ,SAAS,gBAAgB,EAC3D,QAAQ,OAAO,iBAAiB,WAClC,CAAC;AACD,MAAa,iBAAiB,QAAQ,UAAU,kBAAkB;CAChE,aAAa,CAAC,UAAU,UAAU;CAClC,aAAa,OAAO,OAAO,QAAQ;EACjC,MAAM,EAAE,OAAO;EACf,MAAM,MAAM,MAAM,IAAI,GAAG,MAAM,UAAU,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;EACpE,IAAI,OAAO,QAAQ,IAAI,SAAS,WAC9B,MAAM,IAAI,MAAM,yBAAyB;EAE3C,OACE;GACE,OAAO;GACP,QAAQ;GACR,UAAU;GACV,YAAY;EACd,EACA,IAAI;CACR;AACF,CAAC;AAiBD,MAAa,WAhBO,QAAQ,YAAY,aAAa;CACnD,MAAM;CACN,IAAI,EAAE,SAAS,QAAQ,IAAI,GAAG;CAC9B,SAAS,OAAO;EACd,KAAK,EAAE,OAAO,OAAO,EAAE,MAAM,MAAM,CAAC;EACpC,MAAM,EAAE,OAA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