pups-client 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -10
- package/dist/comments.d.ts +92 -0
- package/dist/comments.d.ts.map +1 -0
- package/dist/comments.js +203 -0
- package/dist/comments.js.map +1 -0
- package/dist/discovery.d.ts +5 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +1 -0
- package/dist/discovery.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/feed.d.ts +40 -70
- package/dist/feed.d.ts.map +1 -1
- package/dist/feed.js +125 -566
- package/dist/feed.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +2 -2
- package/dist/mentions.js.map +1 -1
- package/dist/session.d.ts +17 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +22 -0
- package/dist/session.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/comments.ts +247 -0
- package/src/discovery.ts +6 -0
- package/src/errors.ts +1 -1
- package/src/feed.ts +130 -598
- package/src/index.ts +2 -1
- package/src/mentions.ts +2 -3
- package/src/session.ts +25 -1
- package/src/version.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -32,7 +32,6 @@ export type {
|
|
|
32
32
|
FeedSetup,
|
|
33
33
|
FeedState,
|
|
34
34
|
ItemArchive,
|
|
35
|
-
ItemMarker,
|
|
36
35
|
MentionChoice,
|
|
37
36
|
MediaInput,
|
|
38
37
|
MediaResult,
|
|
@@ -42,6 +41,8 @@ export type {
|
|
|
42
41
|
PupsMarker,
|
|
43
42
|
} from './feed.js'
|
|
44
43
|
export { HostMetaEditor } from './host-meta.js'
|
|
44
|
+
export { PupsComments, commentFeedPath } from './comments.js'
|
|
45
|
+
export type { CommentChanges, CommentInput, CommentResult } from './comments.js'
|
|
45
46
|
export { MENTION_REL, Mentions } from './mentions.js'
|
|
46
47
|
export type { Delivery, DeliveryStatus, FoundItem, MentionReport, MentionSource, MentionsOptions, PlannedMention, PostChange, PostMentions, Submission, SubmissionStatus } from './mentions.js'
|
|
47
48
|
export { accountHost, findHandles, handleText, itemHandles, visibleText } from './handles.js'
|
package/src/mentions.ts
CHANGED
|
@@ -151,9 +151,8 @@ function splitRef(ref: string): [string, string | undefined] {
|
|
|
151
151
|
return [ref.slice(0, at), id]
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
/** A field of a feed's RFC-13 `_archive
|
|
155
|
-
const archiveField = (doc: Record<string, unknown>, key: string): unknown =>
|
|
156
|
-
(isObject(doc._archive) ? doc._archive[key] : undefined) ?? (isObject(doc._pups) ? doc._pups[key] : undefined)
|
|
154
|
+
/** A field of a feed's RFC-13 `_archive`. */
|
|
155
|
+
const archiveField = (doc: Record<string, unknown>, key: string): unknown => isObject(doc._archive) ? doc._archive[key] : undefined
|
|
157
156
|
|
|
158
157
|
/**
|
|
159
158
|
* Sends webmentions: RFC-11 mentions to the domains a post names or answers, found through their `host-meta.json`,
|
package/src/session.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PupsComments } from './comments.js'
|
|
1
2
|
import { discover, type PupsServer } from './discovery.js'
|
|
2
3
|
import { errorFromResponse, isPupsError, PupsError } from './errors.js'
|
|
3
4
|
import { listFeeds, PupsFeed, type FeedLink, type FeedOptions } from './feed.js'
|
|
@@ -100,6 +101,7 @@ export class PupsSession {
|
|
|
100
101
|
/** Edits `host-meta.json` through the server's host-meta endpoint. */
|
|
101
102
|
readonly hostMeta: HostMetaEditor
|
|
102
103
|
#mentions?: Mentions
|
|
104
|
+
#comments?: PupsComments
|
|
103
105
|
/** @internal */
|
|
104
106
|
readonly _tokens: TokenManager
|
|
105
107
|
readonly #ctx: SessionContext
|
|
@@ -129,6 +131,14 @@ export class PupsSession {
|
|
|
129
131
|
return this.#mentions ??= new Mentions({ fetch: this.#ctx.fetch, me: this.me })
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The owner's comments and posts to discussion groups (RFC-4 submissions), kept in comment feeds in the app's own
|
|
136
|
+
* directory, never in a feed for readers (RFC-7 "Comment feeds"). Needs the `appdata` scope.
|
|
137
|
+
*/
|
|
138
|
+
get comments(): PupsComments {
|
|
139
|
+
return this.#comments ??= new PupsComments(this)
|
|
140
|
+
}
|
|
141
|
+
|
|
132
142
|
/** The server configuration, pinned at login. */
|
|
133
143
|
get server(): PupsServer {
|
|
134
144
|
return this._tokens.record.server
|
|
@@ -317,6 +327,20 @@ export class PupsSession {
|
|
|
317
327
|
}
|
|
318
328
|
}
|
|
319
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Sends a JSON value with POST to a file at `storage_base` (through the POST fallback with `method=POST`, if the
|
|
332
|
+
* server declares one): how apps send single items to a kept feed (RFC-7 "Posting items").
|
|
333
|
+
* @returns the status and the JSON body of the response.
|
|
334
|
+
*/
|
|
335
|
+
async post(path: string, value: JsonBody, options: { signal?: AbortSignal } = {}): Promise<{ status: number; body: unknown }> {
|
|
336
|
+
const absolute = this.#checkWritable(path)
|
|
337
|
+
const data = new TextEncoder().encode(JSON.stringify(value))
|
|
338
|
+
if (data.byteLength > this.server.maxUploadBytes)
|
|
339
|
+
throw new PupsError('too_large', `The request has ${data.byteLength} bytes; the server accepts at most ${this.server.maxUploadBytes}.`)
|
|
340
|
+
const response = await this.#write('POST', absolute, { 'Content-Type': 'application/json' }, data, options.signal)
|
|
341
|
+
return { status: response.status, body: await response.json() }
|
|
342
|
+
}
|
|
343
|
+
|
|
320
344
|
/**
|
|
321
345
|
* Deletes a file, if `ifMatch` is given only if it is unchanged since that ETag.
|
|
322
346
|
* @throws {PupsError} `not_found` if the file doesn't exist; `precondition_failed` if it changed.
|
|
@@ -428,7 +452,7 @@ export class PupsSession {
|
|
|
428
452
|
}
|
|
429
453
|
|
|
430
454
|
/** Sends a write to `storage_base`, or through the POST fallback if the server declares `post_endpoint`. */
|
|
431
|
-
async #write(method: 'PUT' | 'DELETE', path: string, headers: Record<string, string>, body: Blob | Uint8Array<ArrayBuffer> | undefined, signal?: AbortSignal) {
|
|
455
|
+
async #write(method: 'PUT' | 'DELETE' | 'POST', path: string, headers: Record<string, string>, body: Blob | Uint8Array<ArrayBuffer> | undefined, signal?: AbortSignal) {
|
|
432
456
|
const { postEndpoint } = this.server
|
|
433
457
|
const url = postEndpoint
|
|
434
458
|
? `${postEndpoint}${postEndpoint.includes('?') ? '&' : '?'}method=${method}&path=${encodeURIComponent(path)}`
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.8.0'
|