pups-client 0.7.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/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,
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`, or of `_pups` in feeds of earlier drafts (RFC-13 "Earlier drafts"). */
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
@@ -327,6 +327,20 @@ export class PupsSession {
327
327
  }
328
328
  }
329
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
+
330
344
  /**
331
345
  * Deletes a file, if `ifMatch` is given only if it is unchanged since that ETag.
332
346
  * @throws {PupsError} `not_found` if the file doesn't exist; `precondition_failed` if it changed.
@@ -438,7 +452,7 @@ export class PupsSession {
438
452
  }
439
453
 
440
454
  /** Sends a write to `storage_base`, or through the POST fallback if the server declares `post_endpoint`. */
441
- 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) {
442
456
  const { postEndpoint } = this.server
443
457
  const url = postEndpoint
444
458
  ? `${postEndpoint}${postEndpoint.includes('?') ? '&' : '?'}method=${method}&path=${encodeURIComponent(path)}`
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.7.0'
1
+ export const VERSION = '0.8.0'