inkwire-client 0.2.0 → 0.3.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 +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,6 +13,6 @@ const result = await publish("https://blog.example.com", "your-api-key", {
|
|
|
13
13
|
});
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
`publish(baseUrl, apiKey, payload, opts?)` upserts by `external_id`, retries on `429`/5xx with backoff, and throws `InkwireClientError` (`code`, `message`, `httpStatus`) on failure.
|
|
16
|
+
`publish(baseUrl, apiKey, payload, opts?)` upserts by `external_id`, retries on `429`/5xx with backoff, and throws `InkwireClientError` (`code`, `message`, `httpStatus`) on failure. Pass `opts.fetch` to send through your own fetch, for example an SSRF-guarded one when the site URL comes from your users.
|
|
17
17
|
|
|
18
18
|
See the [protocol spec](https://github.com/etugrand/inkwire/blob/master/inkwire/SPEC.md) for the full payload shape.
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,12 @@ export declare class InkwireClientError extends Error {
|
|
|
34
34
|
httpStatus: number;
|
|
35
35
|
constructor(code: string, message: string, httpStatus: number);
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export interface PublishOptions {
|
|
38
38
|
retries?: number;
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The fetch to send with (default: global fetch). A server that publishes to user-supplied
|
|
41
|
+
* site URLs should pass an SSRF-guarded fetch that refuses internal hosts on every redirect hop.
|
|
42
|
+
*/
|
|
43
|
+
fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
44
|
+
}
|
|
45
|
+
export declare function publish(baseUrl: string, apiKey: string, payload: PostPayload, opts?: PublishOptions): Promise<PublishResult>;
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,11 @@ export class InkwireClientError extends Error {
|
|
|
10
10
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
11
11
|
export async function publish(baseUrl, apiKey, payload, opts = {}) {
|
|
12
12
|
const retries = Math.max(1, opts.retries ?? 3);
|
|
13
|
+
const send = opts.fetch ?? fetch;
|
|
13
14
|
const url = `${baseUrl.replace(/\/$/, "")}/api/posts`;
|
|
14
15
|
let lastErr;
|
|
15
16
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
16
|
-
const res = await
|
|
17
|
+
const res = await send(url, {
|
|
17
18
|
method: "POST",
|
|
18
19
|
headers: {
|
|
19
20
|
"content-type": "application/json",
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "inkwire-client", "version": "0.
|
|
2
|
+
"name": "inkwire-client", "version": "0.3.0", "type": "module",
|
|
3
3
|
"description": "Client SDK for publishing posts to an Inkwire receiver (idempotent, retrying, typed errors).",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"repository": { "type": "git", "url": "https://github.com/etugrand/inkwire.git", "directory": "inkwire/clients/node" },
|
|
5
|
+
"repository": { "type": "git", "url": "git+https://github.com/etugrand/inkwire.git", "directory": "inkwire/clients/node" },
|
|
6
6
|
"main": "dist/index.js", "types": "dist/index.d.ts",
|
|
7
7
|
"files": ["dist/*.js", "dist/*.d.ts"],
|
|
8
8
|
"scripts": { "build": "tsc", "test": "vitest run" },
|