inkwire-client 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ export interface SeoPayload {
2
+ title?: string;
3
+ description?: string;
4
+ image_url?: string;
5
+ noindex?: boolean;
6
+ }
1
7
  export interface PostPayload {
2
8
  external_id: string;
3
9
  title: string;
@@ -7,6 +13,7 @@ export interface PostPayload {
7
13
  tags?: string[];
8
14
  cover_image_url?: string;
9
15
  canonical_url?: string;
16
+ seo?: SeoPayload;
10
17
  author?: {
11
18
  name?: string;
12
19
  email?: string;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
- "name": "inkwire-client", "version": "0.1.0", "type": "module",
2
+ "name": "inkwire-client", "version": "0.2.0", "type": "module",
3
3
  "description": "Client SDK for publishing posts to an Inkwire receiver (idempotent, retrying, typed errors).",
4
4
  "license": "MIT",
5
5
  "repository": { "type": "git", "url": "https://github.com/etugrand/inkwire.git", "directory": "inkwire/clients/node" },
6
6
  "main": "dist/index.js", "types": "dist/index.d.ts",
7
- "files": ["dist"],
7
+ "files": ["dist/*.js", "dist/*.d.ts"],
8
8
  "scripts": { "build": "tsc", "test": "vitest run" },
9
9
  "devDependencies": { "vitest": "^2.1.0", "typescript": "^5.5.0" }
10
10
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- import { it, expect, vi, afterEach } from "vitest";
2
- import { publish } from "../index";
3
- const ok = (body) => new Response(JSON.stringify(body), { status: 200, headers: { "inkwire-version": "1" } });
4
- afterEach(() => vi.restoreAllMocks());
5
- it("publishes and returns the result", async () => {
6
- vi.stubGlobal("fetch", vi.fn(async () => ok({ id: "1", external_id: "e", url: "u", slug: "s", status: "published", created: true })));
7
- const r = await publish("https://site.test", "k", { external_id: "e", title: "T", markdown: "x", status: "published" });
8
- expect(r).toMatchObject({ id: "1", created: true });
9
- const call = fetch.mock.calls[0];
10
- expect(call[1].headers.authorization).toBe("Bearer k");
11
- expect(call[1].headers["idempotency-key"]).toBe("e");
12
- });
13
- it("retries on 500 then succeeds", async () => {
14
- const fetchMock = vi.fn()
15
- .mockResolvedValueOnce(new Response("{}", { status: 500 }))
16
- .mockResolvedValueOnce(ok({ id: "1", external_id: "e", url: "u", slug: "s", status: "draft", created: true }));
17
- vi.stubGlobal("fetch", fetchMock);
18
- const r = await publish("https://site.test", "k", { external_id: "e", title: "T", markdown: "x" }, { retries: 2 });
19
- expect(r.id).toBe("1");
20
- expect(fetchMock).toHaveBeenCalledTimes(2);
21
- });
22
- it("throws typed error on 401 without retrying", async () => {
23
- const fetchMock = vi.fn(async () => new Response(JSON.stringify({ error: { code: "unauthorized", message: "no" } }), { status: 401 }));
24
- vi.stubGlobal("fetch", fetchMock);
25
- await expect(publish("https://site.test", "bad", { external_id: "e", title: "T", markdown: "x" }))
26
- .rejects.toMatchObject({ code: "unauthorized" });
27
- expect(fetchMock).toHaveBeenCalledTimes(1);
28
- });
29
- it("retries: 0 still makes one attempt and throws typed error", async () => {
30
- const fetchMock = vi.fn(async () => new Response(JSON.stringify({ error: { code: "server_error", message: "oops" } }), { status: 500 }));
31
- vi.stubGlobal("fetch", fetchMock);
32
- await expect(publish("https://site.test", "k", { external_id: "e", title: "T", markdown: "x" }, { retries: 0 }))
33
- .rejects.toMatchObject({ code: "server_error", httpStatus: 500 });
34
- expect(fetchMock).toHaveBeenCalledTimes(1);
35
- });