@pageweaver/sdk 0.1.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/http.js ADDED
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpClient = void 0;
4
+ const errors_1 = require("./errors");
5
+ const DEFAULT_BASE_URL = "https://api.pageweaver.io";
6
+ const DEFAULT_TIMEOUT_MS = 30_000;
7
+ /**
8
+ * Thin fetch wrapper: attaches the API key, serializes JSON, applies a timeout, and maps
9
+ * non-2xx responses to {@link PageWeaverApiError} and transport failures to
10
+ * {@link PageWeaverConnectionError}. Every resource is built on this.
11
+ */
12
+ class HttpClient {
13
+ apiKey;
14
+ baseUrl;
15
+ timeoutMs;
16
+ fetchImpl;
17
+ constructor(opts) {
18
+ if (!opts.apiKey)
19
+ throw new errors_1.PageWeaverConnectionError("An `apiKey` is required.");
20
+ this.apiKey = opts.apiKey;
21
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
22
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
23
+ const globalFetch = globalThis.fetch;
24
+ const resolved = opts.fetch ?? globalFetch;
25
+ if (!resolved) {
26
+ throw new errors_1.PageWeaverConnectionError("No global `fetch` is available. Use Node 18+ or pass a `fetch` implementation.");
27
+ }
28
+ this.fetchImpl = resolved;
29
+ }
30
+ /** Perform a request and parse a JSON response into `T`. */
31
+ async json(method, path, init = {}) {
32
+ const res = await this.send(method, path, init);
33
+ if (res.status === 204)
34
+ return undefined;
35
+ const text = await res.text();
36
+ return (text ? JSON.parse(text) : undefined);
37
+ }
38
+ /** Perform a request and return the raw response body as bytes (for PDF downloads). */
39
+ async bytes(method, path, init = {}) {
40
+ const res = await this.send(method, path, init);
41
+ const buf = await res.arrayBuffer();
42
+ return new Uint8Array(buf);
43
+ }
44
+ /** Fetch an absolute URL (e.g. a signed download URL) and return its bytes. */
45
+ async fetchUrlBytes(url, signal) {
46
+ const { controller, done } = this.withTimeout(signal);
47
+ try {
48
+ const res = await this.fetchImpl(url, { method: "GET", signal: controller.signal });
49
+ if (!res.ok) {
50
+ throw new errors_1.PageWeaverApiError({
51
+ status: res.status,
52
+ message: `Failed to download from ${url}: ${res.status}`,
53
+ body: await safeText(res),
54
+ });
55
+ }
56
+ return new Uint8Array(await res.arrayBuffer());
57
+ }
58
+ catch (err) {
59
+ throw this.wrapTransport(err);
60
+ }
61
+ finally {
62
+ done();
63
+ }
64
+ }
65
+ async send(method, path, init) {
66
+ const url = this.baseUrl + path + buildQuery(init.query);
67
+ const headers = { accept: "application/json", ...init.headers };
68
+ if (!init.noAuth)
69
+ headers["x-api-key"] = this.apiKey;
70
+ let body;
71
+ if (init.body !== undefined) {
72
+ headers["content-type"] = "application/json";
73
+ body = JSON.stringify(init.body);
74
+ }
75
+ const { controller, done } = this.withTimeout(init.signal);
76
+ let res;
77
+ try {
78
+ res = await this.fetchImpl(url, { method, headers, body, signal: controller.signal });
79
+ }
80
+ catch (err) {
81
+ throw this.wrapTransport(err);
82
+ }
83
+ finally {
84
+ done();
85
+ }
86
+ if (!res.ok)
87
+ throw await toApiError(res);
88
+ return res;
89
+ }
90
+ /** Compose a timeout AbortController with an optional caller-supplied signal. */
91
+ withTimeout(signal) {
92
+ const controller = new AbortController();
93
+ const onAbort = () => controller.abort();
94
+ if (signal) {
95
+ if (signal.aborted)
96
+ controller.abort();
97
+ else
98
+ signal.addEventListener("abort", onAbort, { once: true });
99
+ }
100
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
101
+ return {
102
+ controller,
103
+ done: () => {
104
+ clearTimeout(timer);
105
+ signal?.removeEventListener("abort", onAbort);
106
+ },
107
+ };
108
+ }
109
+ wrapTransport(err) {
110
+ if (err instanceof errors_1.PageWeaverApiError)
111
+ throw err;
112
+ const aborted = err instanceof Error && err.name === "AbortError";
113
+ return new errors_1.PageWeaverConnectionError(aborted ? `Request timed out after ${this.timeoutMs}ms.` : `Request failed: ${describe(err)}`, err);
114
+ }
115
+ }
116
+ exports.HttpClient = HttpClient;
117
+ function buildQuery(query) {
118
+ if (!query)
119
+ return "";
120
+ const params = new URLSearchParams();
121
+ for (const [key, value] of Object.entries(query)) {
122
+ if (value !== undefined && value !== "")
123
+ params.set(key, String(value));
124
+ }
125
+ const qs = params.toString();
126
+ return qs ? `?${qs}` : "";
127
+ }
128
+ async function toApiError(res) {
129
+ const raw = await safeText(res);
130
+ let body = raw;
131
+ try {
132
+ body = raw ? JSON.parse(raw) : undefined;
133
+ }
134
+ catch {
135
+ // Non-JSON body: keep the raw text.
136
+ }
137
+ const record = (body ?? {});
138
+ const message = (typeof record.message === "string" && record.message) ||
139
+ (Array.isArray(record.message) && record.message.join(", ")) ||
140
+ `Request failed with status ${res.status}`;
141
+ return new errors_1.PageWeaverApiError({
142
+ status: res.status,
143
+ message,
144
+ code: typeof record.code === "string" ? record.code : undefined,
145
+ errors: record.errors,
146
+ body,
147
+ });
148
+ }
149
+ async function safeText(res) {
150
+ try {
151
+ return await res.text();
152
+ }
153
+ catch {
154
+ return "";
155
+ }
156
+ }
157
+ function describe(err) {
158
+ if (err instanceof Error)
159
+ return err.message;
160
+ return String(err);
161
+ }
162
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";;;AAAA,qCAAyE;AAwBzE,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AACrD,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC;;;;GAIG;AACH,MAAa,UAAU;IACJ,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,SAAS,CAAY;IAEtC,YAAY,IAAuB;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,kCAAyB,CAAC,0BAA0B,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAA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,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,oCAAoC;IACtC,CAAC;IACD,MAAM,MAAM,GAAG,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAC;IACvD,MAAM,OAAO,GACX,CAAC,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC;QACtD,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,8BAA8B,GAAG,CAAC,MAAM,EAAE,CAAC;IAC7C,OAAO,IAAI,2BAAkB,CAAC;QAC5B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO;QACP,IAAI,EAAE,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAC/D,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,IAAI;KACL,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,GAAa;IACnC,IAAI,CAAC;QACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,GAAY;IAC5B,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAC7C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { PageWeaver, type PageWeaverOptions } from "./client";
2
+ export type { FetchLike } from "./http";
3
+ export { DocumentsResource, type WaitOptions, type DownloadOptions } from "./documents";
4
+ export { TemplatesResource } from "./templates";
5
+ export { SchemasResource } from "./schemas";
6
+ export { UsageResource } from "./usage";
7
+ export { PageWeaverError, PageWeaverApiError, PageWeaverConnectionError, PageWeaverTimeoutError, PageWeaverDocumentFailedError, } from "./errors";
8
+ export { verifyWebhook, verifyWebhookSignature, signWebhookBody, isDocumentEvent, isBatchEvent, PageWeaverWebhookSignatureError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_TIMESTAMP_HEADER, type VerifyWebhookOptions, type WebhookPayload, type DocumentWebhookPayload, type BatchWebhookPayload, type WebhookEventName, type DocumentWebhookEventName, type BatchWebhookEventName, } from "./webhooks";
9
+ export type { DocumentStatus, RenderOptions, PageOptions, RenderingOptions, MetadataOptions, BandOptions, WatermarkOptions, StructureOptions, LocalizationOptions, SecurityOptions, PdfSecurityOptions, PdfPermissions, DownloadSecurityOptions, CreateDocumentParams, CreateFromTemplateParams, CreateFromInlineParams, CreateDocumentResult, DownloadInfo, Document, DocumentListItem, ListDocumentsParams, DocumentPage, TemplateSummary, Template, TemplateVersionSummary, SchemaSummary, Schema, SchemaVersionSummary, Usage, } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // @pageweaver/sdk — official TypeScript client for the PageWeaver PDF generation API.
3
+ // Server-side (Node 18+): uses the global `fetch` and `node:crypto` for webhook verification.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.WEBHOOK_TIMESTAMP_HEADER = exports.WEBHOOK_EVENT_HEADER = exports.WEBHOOK_SIGNATURE_HEADER = exports.PageWeaverWebhookSignatureError = exports.isBatchEvent = exports.isDocumentEvent = exports.signWebhookBody = exports.verifyWebhookSignature = exports.verifyWebhook = exports.PageWeaverDocumentFailedError = exports.PageWeaverTimeoutError = exports.PageWeaverConnectionError = exports.PageWeaverApiError = exports.PageWeaverError = exports.UsageResource = exports.SchemasResource = exports.TemplatesResource = exports.DocumentsResource = exports.PageWeaver = void 0;
6
+ var client_1 = require("./client");
7
+ Object.defineProperty(exports, "PageWeaver", { enumerable: true, get: function () { return client_1.PageWeaver; } });
8
+ var documents_1 = require("./documents");
9
+ Object.defineProperty(exports, "DocumentsResource", { enumerable: true, get: function () { return documents_1.DocumentsResource; } });
10
+ var templates_1 = require("./templates");
11
+ Object.defineProperty(exports, "TemplatesResource", { enumerable: true, get: function () { return templates_1.TemplatesResource; } });
12
+ var schemas_1 = require("./schemas");
13
+ Object.defineProperty(exports, "SchemasResource", { enumerable: true, get: function () { return schemas_1.SchemasResource; } });
14
+ var usage_1 = require("./usage");
15
+ Object.defineProperty(exports, "UsageResource", { enumerable: true, get: function () { return usage_1.UsageResource; } });
16
+ var errors_1 = require("./errors");
17
+ Object.defineProperty(exports, "PageWeaverError", { enumerable: true, get: function () { return errors_1.PageWeaverError; } });
18
+ Object.defineProperty(exports, "PageWeaverApiError", { enumerable: true, get: function () { return errors_1.PageWeaverApiError; } });
19
+ Object.defineProperty(exports, "PageWeaverConnectionError", { enumerable: true, get: function () { return errors_1.PageWeaverConnectionError; } });
20
+ Object.defineProperty(exports, "PageWeaverTimeoutError", { enumerable: true, get: function () { return errors_1.PageWeaverTimeoutError; } });
21
+ Object.defineProperty(exports, "PageWeaverDocumentFailedError", { enumerable: true, get: function () { return errors_1.PageWeaverDocumentFailedError; } });
22
+ var webhooks_1 = require("./webhooks");
23
+ Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_1.verifyWebhook; } });
24
+ Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return webhooks_1.verifyWebhookSignature; } });
25
+ Object.defineProperty(exports, "signWebhookBody", { enumerable: true, get: function () { return webhooks_1.signWebhookBody; } });
26
+ Object.defineProperty(exports, "isDocumentEvent", { enumerable: true, get: function () { return webhooks_1.isDocumentEvent; } });
27
+ Object.defineProperty(exports, "isBatchEvent", { enumerable: true, get: function () { return webhooks_1.isBatchEvent; } });
28
+ Object.defineProperty(exports, "PageWeaverWebhookSignatureError", { enumerable: true, get: function () { return webhooks_1.PageWeaverWebhookSignatureError; } });
29
+ Object.defineProperty(exports, "WEBHOOK_SIGNATURE_HEADER", { enumerable: true, get: function () { return webhooks_1.WEBHOOK_SIGNATURE_HEADER; } });
30
+ Object.defineProperty(exports, "WEBHOOK_EVENT_HEADER", { enumerable: true, get: function () { return webhooks_1.WEBHOOK_EVENT_HEADER; } });
31
+ Object.defineProperty(exports, "WEBHOOK_TIMESTAMP_HEADER", { enumerable: true, get: function () { return webhooks_1.WEBHOOK_TIMESTAMP_HEADER; } });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;AACtF,8FAA8F;;;AAE9F,mCAA8D;AAArD,oGAAA,UAAU,OAAA;AAGnB,yCAAwF;AAA/E,8GAAA,iBAAiB,OAAA;AAC1B,yCAAgD;AAAvC,8GAAA,iBAAiB,OAAA;AAC1B,qCAA4C;AAAnC,0GAAA,eAAe,OAAA;AACxB,iCAAwC;AAA/B,sGAAA,aAAa,OAAA;AAEtB,mCAMkB;AALhB,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,mHAAA,yBAAyB,OAAA;AACzB,gHAAA,sBAAsB,OAAA;AACtB,uHAAA,6BAA6B,OAAA;AAG/B,uCAiBoB;AAhBlB,yGAAA,aAAa,OAAA;AACb,kHAAA,sBAAsB,OAAA;AACtB,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,wGAAA,YAAY,OAAA;AACZ,2HAAA,+BAA+B,OAAA;AAC/B,oHAAA,wBAAwB,OAAA;AACxB,gHAAA,oBAAoB,OAAA;AACpB,oHAAA,wBAAwB,OAAA"}
@@ -0,0 +1,19 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { Schema, SchemaSummary, SchemaVersionSummary } from "./types";
3
+ /** Read-only discovery of the JSON Schemas your payloads validate against. */
4
+ export declare class SchemasResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ /** All schemas owned by the key's account, newest-updated first. */
8
+ list(signal?: AbortSignal): Promise<SchemaSummary[]>;
9
+ /**
10
+ * A schema's published JSON Schema plus a derived sample, for the latest published version or a
11
+ * specific `version`.
12
+ */
13
+ get(id: string, opts?: {
14
+ version?: number;
15
+ signal?: AbortSignal;
16
+ }): Promise<Schema>;
17
+ /** A schema's published version history (newest first). Pin any via `schemaVersion` on create. */
18
+ versions(id: string, signal?: AbortSignal): Promise<SchemaVersionSummary[]>;
19
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemasResource = void 0;
4
+ /** Read-only discovery of the JSON Schemas your payloads validate against. */
5
+ class SchemasResource {
6
+ http;
7
+ constructor(http) {
8
+ this.http = http;
9
+ }
10
+ /** All schemas owned by the key's account, newest-updated first. */
11
+ list(signal) {
12
+ return this.http.json("GET", "/v1/schemas", { signal });
13
+ }
14
+ /**
15
+ * A schema's published JSON Schema plus a derived sample, for the latest published version or a
16
+ * specific `version`.
17
+ */
18
+ get(id, opts = {}) {
19
+ return this.http.json("GET", `/v1/schemas/${encodeURIComponent(id)}`, {
20
+ query: { version: opts.version },
21
+ signal: opts.signal,
22
+ });
23
+ }
24
+ /** A schema's published version history (newest first). Pin any via `schemaVersion` on create. */
25
+ versions(id, signal) {
26
+ return this.http.json("GET", `/v1/schemas/${encodeURIComponent(id)}/versions`, { signal });
27
+ }
28
+ }
29
+ exports.SchemasResource = SchemasResource;
30
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":";;;AAGA,8EAA8E;AAC9E,MAAa,eAAe;IACG;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,oEAAoE;IACpE,IAAI,CAAC,MAAoB;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAkB,KAAK,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,EAAU,EAAE,OAAmD,EAAE;QACnE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAS,KAAK,EAAE,eAAe,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5E,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;IAED,kGAAkG;IAClG,QAAQ,CAAC,EAAU,EAAE,MAAoB;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CACnB,KAAK,EACL,eAAe,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAChD,EAAE,MAAM,EAAE,CACX,CAAC;IACJ,CAAC;CACF;AA3BD,0CA2BC"}
@@ -0,0 +1,13 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { Template, TemplateSummary, TemplateVersionSummary } from "./types";
3
+ /** Read-only discovery of your published templates and their pinnable versions. */
4
+ export declare class TemplatesResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ /** All templates owned by the key's account, newest-updated first. */
8
+ list(signal?: AbortSignal): Promise<TemplateSummary[]>;
9
+ /** One template's metadata (name, current version, associated schema, authoring mode). */
10
+ get(id: string, signal?: AbortSignal): Promise<Template>;
11
+ /** A template's published version history (newest first). Pin any via `version` on create. */
12
+ versions(id: string, signal?: AbortSignal): Promise<TemplateVersionSummary[]>;
13
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemplatesResource = void 0;
4
+ /** Read-only discovery of your published templates and their pinnable versions. */
5
+ class TemplatesResource {
6
+ http;
7
+ constructor(http) {
8
+ this.http = http;
9
+ }
10
+ /** All templates owned by the key's account, newest-updated first. */
11
+ list(signal) {
12
+ return this.http.json("GET", "/v1/templates", { signal });
13
+ }
14
+ /** One template's metadata (name, current version, associated schema, authoring mode). */
15
+ get(id, signal) {
16
+ return this.http.json("GET", `/v1/templates/${encodeURIComponent(id)}`, { signal });
17
+ }
18
+ /** A template's published version history (newest first). Pin any via `version` on create. */
19
+ versions(id, signal) {
20
+ return this.http.json("GET", `/v1/templates/${encodeURIComponent(id)}/versions`, { signal });
21
+ }
22
+ }
23
+ exports.TemplatesResource = TemplatesResource;
24
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":";;;AAGA,mFAAmF;AACnF,MAAa,iBAAiB;IACC;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,sEAAsE;IACtE,IAAI,CAAC,MAAoB;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAoB,KAAK,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,0FAA0F;IAC1F,GAAG,CAAC,EAAU,EAAE,MAAoB;QAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAW,KAAK,EAAE,iBAAiB,kBAAkB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,8FAA8F;IAC9F,QAAQ,CAAC,EAAU,EAAE,MAAoB;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CACnB,KAAK,EACL,iBAAiB,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAClD,EAAE,MAAM,EAAE,CACX,CAAC;IACJ,CAAC;CACF;AArBD,8CAqBC"}
@@ -0,0 +1,270 @@
1
+ /** A terminal or in-flight document status. */
2
+ export type DocumentStatus = "queued" | "rendering" | "done" | "failed";
3
+ export interface PageOptions {
4
+ /** Standard paper size, e.g. "A4" or "Letter". */
5
+ size?: string;
6
+ /** Page orientation (requires `size`). */
7
+ orientation?: "portrait" | "landscape";
8
+ /** CSS margin shorthand: 1-4 space-separated lengths (mm/cm/in/px/pt), e.g. "18mm". */
9
+ margin?: string;
10
+ /** Render scale, 0.1 to 2.0. */
11
+ scale?: number;
12
+ }
13
+ export interface RenderingOptions {
14
+ /** CSS media type Chromium emulates. */
15
+ media?: "screen" | "print";
16
+ /** Print background graphics/colours. */
17
+ printBackground?: boolean;
18
+ /** Transparent background (implies printBackground). */
19
+ omitBackground?: boolean;
20
+ /** Collapse the whole document onto one tall page. */
21
+ singlePage?: boolean;
22
+ /** Honour the document's CSS @page size over the API paper params. */
23
+ preferCssPageSize?: boolean;
24
+ /** Pages to print, e.g. "1-3,5". Empty means all. */
25
+ pageRanges?: string;
26
+ }
27
+ export interface MetadataOptions {
28
+ /** PDF Title (also the header/footer {{title}}). Liquid tokens resolve. */
29
+ title?: string;
30
+ author?: string;
31
+ subject?: string;
32
+ keywords?: string;
33
+ creator?: string;
34
+ }
35
+ /** A running header or footer band. Slots accept literal text plus {{field}} / {{@page}} tokens. */
36
+ export interface BandOptions {
37
+ /** Show the band. Omitting it while any slot has text auto-enables it. */
38
+ enabled?: boolean;
39
+ left?: string;
40
+ /** e.g. "Page {{@page}} of {{@pages}}". */
41
+ center?: string;
42
+ right?: string;
43
+ fontSizePt?: number;
44
+ /** Hex or CSS colour name. */
45
+ color?: string;
46
+ }
47
+ export interface WatermarkOptions {
48
+ /** Watermark text (empty means off). Tokens resolve. */
49
+ text?: string;
50
+ /** Pages to mark, e.g. "1-3". Empty means all. */
51
+ pages?: string;
52
+ fontSizePt?: number;
53
+ color?: string;
54
+ /** Opacity 0 to 1. */
55
+ opacity?: number;
56
+ /** Rotation in degrees, 0 to 360. */
57
+ rotation?: number;
58
+ }
59
+ export interface StructureOptions {
60
+ /** Emit PDF bookmarks/outline from the document headings. */
61
+ outline?: boolean;
62
+ /** Emit a tagged (accessible) PDF structure. */
63
+ taggedPdf?: boolean;
64
+ }
65
+ export interface LocalizationOptions {
66
+ /** BCP-47 locale for date/number/currency formatting, e.g. "de-DE". */
67
+ locale?: string;
68
+ /** IANA time zone, e.g. "Europe/Berlin". */
69
+ timeZone?: string;
70
+ /** ISO 4217 currency, e.g. "EUR". */
71
+ currency?: string;
72
+ }
73
+ export interface PdfPermissions {
74
+ printing?: boolean;
75
+ copying?: boolean;
76
+ modifying?: boolean;
77
+ annotating?: boolean;
78
+ fillingForms?: boolean;
79
+ assembling?: boolean;
80
+ }
81
+ export interface PdfSecurityOptions {
82
+ /** Password required to open the PDF (PDF-level encryption). */
83
+ userPassword?: string;
84
+ /** Owner password for full permissions. */
85
+ ownerPassword?: string;
86
+ permissions?: PdfPermissions;
87
+ }
88
+ /**
89
+ * Download protection: a password that gates streaming the document from the PageWeaver
90
+ * download endpoint, separate from the PDF's own open-password.
91
+ */
92
+ export interface DownloadSecurityOptions {
93
+ /** Enable the download password. */
94
+ enabled?: boolean;
95
+ /** The password recipients must supply to fetch the PDF. */
96
+ password?: string;
97
+ /** Generate a strong random download password (returned in the response). */
98
+ generate?: boolean;
99
+ }
100
+ export interface SecurityOptions {
101
+ pdf?: PdfSecurityOptions;
102
+ download?: DownloadSecurityOptions;
103
+ }
104
+ /**
105
+ * The single nested per-render `options` block. Every field is layered on the template
106
+ * version's frozen settings for this render only. Unknown keys are rejected by the API (400).
107
+ */
108
+ export interface RenderOptions {
109
+ page?: PageOptions;
110
+ rendering?: RenderingOptions;
111
+ metadata?: MetadataOptions;
112
+ header?: BandOptions;
113
+ footer?: BandOptions;
114
+ watermark?: WatermarkOptions;
115
+ structure?: StructureOptions;
116
+ localization?: LocalizationOptions;
117
+ security?: SecurityOptions;
118
+ }
119
+ interface CreateDocumentCommon {
120
+ /** Data merged into the template/HTML via Liquid. */
121
+ payload?: Record<string, unknown>;
122
+ /** Per-render option overrides, nested under this one key. */
123
+ options?: RenderOptions;
124
+ /**
125
+ * A unique token you generate per document so a retried request returns the original
126
+ * document instead of creating a duplicate. Sent as the `Idempotency-Key` header.
127
+ */
128
+ idempotencyKey?: string;
129
+ /** HTTPS URL to receive a signed webhook POST when the document reaches a terminal state. */
130
+ callbackUrl?: string;
131
+ }
132
+ /** Render a published template. */
133
+ export interface CreateFromTemplateParams extends CreateDocumentCommon {
134
+ /** Template id (or the built-in "sample-invoice"). */
135
+ templateId: string;
136
+ /** Data merged into the template. Required and validated against the template's schema. */
137
+ payload: Record<string, unknown>;
138
+ /** Pin a published template version; defaults to the template's latest. */
139
+ version?: number;
140
+ /** Validate against this schema instead of the one the template pins (account-owned). */
141
+ schemaId?: string;
142
+ /** Pin a published schema version (requires `schemaId`); defaults to that schema's latest. */
143
+ schemaVersion?: number;
144
+ html?: never;
145
+ css?: never;
146
+ }
147
+ /** Render raw inline HTML with no template. No external images, stylesheets, or JavaScript. */
148
+ export interface CreateFromInlineParams extends CreateDocumentCommon {
149
+ /** Raw HTML to convert. May use Liquid tokens and reference account image assets by name. */
150
+ html: string;
151
+ /** CSS applied to the inline HTML (injected as a <style>). */
152
+ css?: string;
153
+ templateId?: never;
154
+ version?: never;
155
+ schemaId?: never;
156
+ schemaVersion?: never;
157
+ }
158
+ export type CreateDocumentParams = CreateFromTemplateParams | CreateFromInlineParams;
159
+ /** The owner-visible download block, present when a document is download-protected. */
160
+ export interface DownloadInfo {
161
+ protected: boolean;
162
+ requiresPassword: boolean;
163
+ /** The plaintext download password, returned only to the authenticated owner. */
164
+ password?: string;
165
+ /** A short-lived signed URL (unprotected), or the content endpoint URL (protected). */
166
+ url?: string;
167
+ }
168
+ /** The `202` body from creating (or idempotently returning) a document. */
169
+ export interface CreateDocumentResult {
170
+ id: string;
171
+ status: DocumentStatus;
172
+ /** Null for an inline render (it had no template). */
173
+ version: number | null;
174
+ download?: DownloadInfo;
175
+ }
176
+ /** The `GET /v1/documents/:id` body. */
177
+ export interface Document {
178
+ id: string;
179
+ status: DocumentStatus;
180
+ version: number | null;
181
+ download?: DownloadInfo;
182
+ /** Present when `status` is "failed". */
183
+ error?: string;
184
+ /** The per-render options the document was created with; null if none. */
185
+ appliedOptions?: Record<string, unknown> | null;
186
+ }
187
+ /** One row in the document history list. */
188
+ export interface DocumentListItem {
189
+ id: string;
190
+ templateId: string | null;
191
+ version: number | null;
192
+ status: DocumentStatus;
193
+ source: string;
194
+ pages: number | null;
195
+ bytes: number | null;
196
+ /** ISO 8601 timestamp. */
197
+ createdAt: string;
198
+ finishedAt: string | null;
199
+ pdfAvailable: boolean;
200
+ pdfExpiresAt: string | null;
201
+ error: string | null;
202
+ }
203
+ export interface ListDocumentsParams {
204
+ status?: DocumentStatus;
205
+ templateId?: string;
206
+ cursor?: string;
207
+ /** 1 to 100, default 25. */
208
+ limit?: number;
209
+ }
210
+ export interface DocumentPage {
211
+ items: DocumentListItem[];
212
+ /** Pass to the next `list` call to fetch the following page; null when there are no more. */
213
+ nextCursor: string | null;
214
+ }
215
+ export interface TemplateSummary {
216
+ id: string;
217
+ name: string;
218
+ description: string | null;
219
+ /** 0 for a template that has never been published (not yet renderable). */
220
+ currentVersion: number;
221
+ /** ISO 8601 timestamp. */
222
+ updatedAt: string;
223
+ }
224
+ export interface Template extends TemplateSummary {
225
+ editorMode: string;
226
+ schemaId: string | null;
227
+ schemaVersion: number | null;
228
+ }
229
+ export interface TemplateVersionSummary {
230
+ version: number;
231
+ note: string | null;
232
+ /** ISO 8601 timestamp. */
233
+ publishedAt: string;
234
+ derivedFromVersion: number | null;
235
+ }
236
+ export interface SchemaSummary {
237
+ id: string;
238
+ name: string;
239
+ description: string | null;
240
+ /** ISO 8601 timestamp. */
241
+ updatedAt: string;
242
+ }
243
+ export interface Schema {
244
+ id: string;
245
+ name: string;
246
+ description: string | null;
247
+ version: number;
248
+ /** The published JSON Schema (as a JSON value). */
249
+ schema: unknown;
250
+ /** A derived sample payload conforming to the schema. */
251
+ sample: unknown;
252
+ }
253
+ export interface SchemaVersionSummary {
254
+ version: number;
255
+ note: string | null;
256
+ /** ISO 8601 timestamp. */
257
+ publishedAt: string;
258
+ }
259
+ export interface Usage {
260
+ /** The billing period label, e.g. "2026-08". */
261
+ period: string;
262
+ /** Billable API document pages consumed this period. */
263
+ pages: number;
264
+ /** Monthly page allowance for the plan. */
265
+ limit: number;
266
+ /** Editor PDF-preview pages consumed this period (a separate budget). */
267
+ previewPages: number;
268
+ previewLimit: number;
269
+ }
270
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // Request/response shapes for the PageWeaver public API (`/v1/*`), hand-mirrored from the
3
+ // server DTOs so the SDK stays self-contained (no dependency on the internal workspace
4
+ // packages, which are private and unpublishable). Keep these in sync with:
5
+ // apps/api/src/renders/dto/create-render.dto.ts (RenderOptions + CreateRenderDto)
6
+ // apps/api/src/renders/renders.service.ts (Create/Document/List result shapes)
7
+ // apps/api/src/templates/templates.service.ts (discovery shapes)
8
+ // apps/api/src/schemas/schemas.service.ts
9
+ // A drift-guard test against a captured openapi.json is a good future addition.
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,0FAA0F;AAC1F,uFAAuF;AACvF,2EAA2E;AAC3E,sFAAsF;AACtF,0FAA0F;AAC1F,wEAAwE;AACxE,4CAA4C;AAC5C,gFAAgF"}
@@ -0,0 +1,9 @@
1
+ import type { HttpClient } from "./http";
2
+ import type { Usage } from "./types";
3
+ /** Your page consumption against the plan quota for the current billing period. */
4
+ export declare class UsageResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ /** Current-period usage: billable document pages and editor preview pages, with their limits. */
8
+ get(signal?: AbortSignal): Promise<Usage>;
9
+ }
package/dist/usage.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsageResource = void 0;
4
+ /** Your page consumption against the plan quota for the current billing period. */
5
+ class UsageResource {
6
+ http;
7
+ constructor(http) {
8
+ this.http = http;
9
+ }
10
+ /** Current-period usage: billable document pages and editor preview pages, with their limits. */
11
+ get(signal) {
12
+ return this.http.json("GET", "/v1/usage", { signal });
13
+ }
14
+ }
15
+ exports.UsageResource = UsageResource;
16
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":";;;AAGA,mFAAmF;AACnF,MAAa,aAAa;IACK;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,iGAAiG;IACjG,GAAG,CAAC,MAAoB;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAQ,KAAK,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF;AAPD,sCAOC"}