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/README.md +5 -5
- 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 +38 -70
- package/dist/feed.d.ts.map +1 -1
- package/dist/feed.js +123 -566
- package/dist/feed.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- 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 +11 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +13 -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/discovery.ts +6 -0
- package/src/errors.ts +1 -1
- package/src/feed.ts +128 -598
- package/src/index.ts +0 -1
- package/src/mentions.ts +2 -3
- package/src/session.ts +15 -1
- package/src/version.ts +1 -1
package/src/index.ts
CHANGED
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
|
@@ -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.
|
|
1
|
+
export const VERSION = '0.8.0'
|