@zpdf/sdk 0.0.0-stage → 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.
@@ -0,0 +1,263 @@
1
+ import { FetchLike, HttpRequest, RequestOptions } from "./http.js";
2
+ import { ListResult } from "./pagination.js";
3
+ import type { ApiInfo, Asset, AssetUploadParams, BillingStatus, Business, CheckoutLink, Deleted, Document, DocumentGenerateParams, DocumentGetParams, DocumentListParams, DocumentPromoteParams, DocumentRegenerateParams, DocumentValidation, Engine, Event, EventListParams, Example, ExampleFile, ExampleSummary, Key, KeyCreateParams, KeyUpdateParams, ListParams, Member, ShareLink, ShareLinkCreateParams, SignupComplete, SignupStarted, SignupVerifyParams, TemplateListParams, TemplateSaveParams, TemplateUpdateParams, TemplateVersion, TemplateVersionEntry, TemplateVersionSummary, TemplateWithVersion, Template, Usage, WebhookEndpoint, WebhookEndpointCreateParams, WebhookEndpointUpdateParams } from "./types.js";
4
+ /** The zpdf API. Override with `baseUrl` or the `ZPDF_API` environment variable. */
5
+ export declare const DEFAULT_BASE_URL: string;
6
+ export interface ZPDFOptions {
7
+ /** A secret key, `zp_sk_…`. Default: the `ZPDF_API_KEY` environment variable, then `ZPDF_SECRET_KEY`. */
8
+ apiKey?: string;
9
+ /** The API base URL ending in `/v1`. Default: `ZPDF_API`, then `DEFAULT_BASE_URL`. */
10
+ baseUrl?: string;
11
+ /** A `fetch` to use instead of the global one. */
12
+ fetch?: FetchLike;
13
+ /** Retries of network errors, 429 and 5xx. Default 2. */
14
+ maxRetries?: number;
15
+ /** Per attempt, in milliseconds. Default 60000 (a render is limited to 30 seconds). */
16
+ timeoutMs?: number;
17
+ }
18
+ type Send = <T>(request: HttpRequest) => Promise<T>;
19
+ /** Create a business and its first key. No key needed. */
20
+ declare class Signup {
21
+ private readonly send;
22
+ constructor(send: Send);
23
+ /** `POST /signup`: emails a 6-digit code to the address. */
24
+ start(params: {
25
+ email: string;
26
+ }, options?: RequestOptions): Promise<SignupStarted>;
27
+ /** `POST /signup/verify`: trades the code for the business and a secret key, shown once. */
28
+ verify(params: SignupVerifyParams, options?: RequestOptions): Promise<SignupComplete>;
29
+ }
30
+ /** The example templates. No key needed. */
31
+ declare class Examples {
32
+ private readonly send;
33
+ constructor(send: Send);
34
+ /** `GET /examples`: by key. Await for one page, or iterate for every example. */
35
+ list(params?: ListParams, options?: RequestOptions): ListResult<ExampleSummary>;
36
+ /** `GET /examples/{key}`: the example's HTML, CSS and inputs in one object. */
37
+ get(key: string, options?: RequestOptions): Promise<Example>;
38
+ /** `GET /examples/{key}/{file}`: one of the example's files, as text. */
39
+ file(key: string, file: ExampleFile, options?: RequestOptions): Promise<string>;
40
+ }
41
+ declare class Templates {
42
+ private readonly send;
43
+ constructor(send: Send);
44
+ /**
45
+ * `PUT /templates/{key}`: saves a new version, checks it and renders its
46
+ * example. Identical content returns the existing version. If anything is
47
+ * wrong nothing is saved, and the error's `problems` lists every fault.
48
+ * A field the API does not take is refused with `parameter_unknown`.
49
+ */
50
+ save(key: string, params: TemplateSaveParams, options?: RequestOptions): Promise<TemplateWithVersion>;
51
+ /** `GET /templates`: by key. Await for one page, or iterate for every template. */
52
+ list(params?: TemplateListParams, options?: RequestOptions): ListResult<Template>;
53
+ /** `GET /templates/{key}`: the current version (or `version`) with files, inputs, regions and the changelog. */
54
+ get(key: string, params?: {
55
+ version?: number;
56
+ }, options?: RequestOptions): Promise<TemplateWithVersion & {
57
+ versions: TemplateVersionEntry[];
58
+ }>;
59
+ /** `PATCH /templates/{key}`: move `current_version`, rename, archive. */
60
+ update(key: string, params: TemplateUpdateParams, options?: RequestOptions): Promise<TemplateWithVersion>;
61
+ }
62
+ /** The versions of a template: each save and each promote makes one, and none ever changes. */
63
+ declare class TemplateVersions {
64
+ private readonly send;
65
+ constructor(send: Send);
66
+ /** `GET /templates/{key}/versions`: summaries, newest first. Await for one page, or iterate for every version. */
67
+ list(key: string, params?: ListParams, options?: RequestOptions): ListResult<TemplateVersionSummary>;
68
+ /** `GET /templates/{key}/versions/{number}`: one version in full, with its files, inputs, regions and example. */
69
+ get(key: string, number: number, options?: RequestOptions): Promise<TemplateVersion>;
70
+ }
71
+ declare class Documents {
72
+ private readonly send;
73
+ private readonly fetchBytes;
74
+ constructor(send: Send, fetchBytes: (url: string, options?: RequestOptions) => Promise<Uint8Array>);
75
+ /**
76
+ * `POST /documents`: generates a PDF from a template and data, with
77
+ * optional overrides. Answers when the PDF is stored.
78
+ */
79
+ generate(params: DocumentGenerateParams, options?: RequestOptions): Promise<Document>;
80
+ /**
81
+ * `POST /documents/validate`: every check short of rendering, on the body
82
+ * `generate` takes. Makes no document and counts against no limit. A
83
+ * request that would fail throws the error `generate` would throw.
84
+ */
85
+ validate(params: DocumentGenerateParams, options?: RequestOptions): Promise<DocumentValidation>;
86
+ /** `GET /documents`: newest first. Await for one page, or iterate for every document. */
87
+ list(params?: DocumentListParams, options?: RequestOptions): ListResult<Document>;
88
+ /** `GET /documents/{id}`: the record with its data and fresh URLs. */
89
+ get(id: string, params?: DocumentGetParams, options?: RequestOptions): Promise<Document>;
90
+ /** `GET /documents/{id}/file`: the PDF's bytes. */
91
+ download(id: string, options?: RequestOptions): Promise<Uint8Array>;
92
+ /** The PNG of one page (1-based), read from the document's signed `page_images` URL. */
93
+ pageImage(document: Pick<Document, "page_images">, page?: number, options?: RequestOptions): Promise<Uint8Array>;
94
+ /** `DELETE /documents/{id}`: erases the PDF, images, data and overrides. A stub remains. */
95
+ delete(id: string, options?: RequestOptions): Promise<Document>;
96
+ /**
97
+ * `POST /documents/{id}/regenerate`: renders again from the record and
98
+ * returns a new document. With no params the bytes reproduce the original
99
+ * (`reproduced: true`); `data` or `overrides` replace that part only.
100
+ */
101
+ regenerate(id: string, params?: DocumentRegenerateParams, options?: RequestOptions): Promise<Document>;
102
+ /** `POST /documents/{id}/promote`: saves the document's template (version plus overrides) as the next version. */
103
+ promote(id: string, params?: DocumentPromoteParams, options?: RequestOptions): Promise<TemplateWithVersion>;
104
+ }
105
+ declare class ShareLinks {
106
+ private readonly send;
107
+ constructor(send: Send);
108
+ /**
109
+ * `POST /documents/{id}/share_links`: a public page for one PDF. `url` is
110
+ * returned here only. Repeating the call with the same `idempotencyKey`
111
+ * and params within 24 hours returns the same link with its `url`.
112
+ */
113
+ create(documentId: string, params?: ShareLinkCreateParams, options?: RequestOptions): Promise<ShareLink>;
114
+ /** `GET /documents/{id}/share_links`: newest first. Await for one page, or iterate for every link. */
115
+ list(documentId: string, params?: ListParams, options?: RequestOptions): ListResult<ShareLink>;
116
+ /** `DELETE /share_links/{id}`: the link stops working at once. */
117
+ revoke(id: string, options?: RequestOptions): Promise<ShareLink>;
118
+ }
119
+ declare class Assets {
120
+ private readonly send;
121
+ constructor(send: Send);
122
+ /** `POST /assets`: stores an image or font under a name. The same bytes return the same asset. */
123
+ upload(params: AssetUploadParams, options?: RequestOptions): Promise<Asset>;
124
+ /** `GET /assets`: newest first. Await for one page, or iterate for every asset. */
125
+ list(params?: ListParams, options?: RequestOptions): ListResult<Asset>;
126
+ /** `GET /assets/{id or name}` */
127
+ get(idOrName: string, options?: RequestOptions): Promise<Asset>;
128
+ /** `DELETE /assets/{id or name}`. Refused with `asset_in_use` while a current version uses it. */
129
+ delete(idOrName: string, options?: RequestOptions): Promise<Deleted<"asset">>;
130
+ }
131
+ declare class WebhookEndpoints {
132
+ private readonly send;
133
+ constructor(send: Send);
134
+ /**
135
+ * `POST /webhook_endpoints`: registers the business's endpoint and sends
136
+ * it an `endpoint.verification` challenge. `secret` is returned here
137
+ * only. Repeating the call with the same `idempotencyKey` and params
138
+ * within 24 hours returns the same endpoint with its `secret`.
139
+ */
140
+ create(params: WebhookEndpointCreateParams, options?: RequestOptions): Promise<WebhookEndpoint>;
141
+ /** `GET /webhook_endpoints`: newest first. Await for one page, or iterate for every endpoint. */
142
+ list(params?: ListParams, options?: RequestOptions): ListResult<WebhookEndpoint>;
143
+ /** `POST /webhook_endpoints/{id}/verify`: sends a new challenge. */
144
+ verify(id: string, options?: RequestOptions): Promise<WebhookEndpoint>;
145
+ /**
146
+ * `PATCH /webhook_endpoints/{id}`: changes the URL, the events sent, or
147
+ * both. The signing secret stays. A new URL makes the endpoint
148
+ * `unverified` and is sent a challenge at once; `status` in the answer
149
+ * says whether it echoed it. Changing the events alone sends nothing.
150
+ */
151
+ update(id: string, params: WebhookEndpointUpdateParams, options?: RequestOptions): Promise<WebhookEndpoint>;
152
+ /** `DELETE /webhook_endpoints/{id}` */
153
+ delete(id: string, options?: RequestOptions): Promise<Deleted<"webhook_endpoint">>;
154
+ }
155
+ declare class Events {
156
+ private readonly send;
157
+ constructor(send: Send);
158
+ /** `GET /events`: the log, newest first. Await for one page, or iterate for every event. */
159
+ list(params?: EventListParams, options?: RequestOptions): ListResult<Event>;
160
+ }
161
+ declare class Keys {
162
+ private readonly send;
163
+ constructor(send: Send);
164
+ /** `GET /keys`: newest first, never with secrets. Await for one page, or iterate for every key. */
165
+ list(params?: ListParams, options?: RequestOptions): ListResult<Key>;
166
+ /**
167
+ * `POST /keys`: a new secret key. `secret` is returned here only.
168
+ * Repeating the call with the same `idempotencyKey` and params within 24
169
+ * hours returns the same key with its `secret`.
170
+ */
171
+ create(params?: KeyCreateParams, options?: RequestOptions): Promise<Key>;
172
+ /** `PATCH /keys/{id}`: renames an active key. Its secret does not change and is not returned. */
173
+ update(id: string, params: KeyUpdateParams, options?: RequestOptions): Promise<Key>;
174
+ /** `DELETE /keys/{id}`: the key stops working at once. */
175
+ revoke(id: string, options?: RequestOptions): Promise<Key>;
176
+ }
177
+ declare class BusinessResource {
178
+ private readonly send;
179
+ constructor(send: Send);
180
+ /** `GET /business`: the business, its plan and limits. */
181
+ get(options?: RequestOptions): Promise<Business>;
182
+ }
183
+ declare class UsageResource {
184
+ private readonly send;
185
+ constructor(send: Send);
186
+ /** `GET /usage`: this month's documents, pages, storage and share links. */
187
+ get(options?: RequestOptions): Promise<Usage>;
188
+ }
189
+ declare class Billing {
190
+ private readonly send;
191
+ constructor(send: Send);
192
+ /**
193
+ * `GET /billing`: the plan status. The plan and why (`state`), this
194
+ * month's documents against the allowance and when the count resets,
195
+ * the paid period's end, whether a cancellation is pending, and whether
196
+ * zpdf is charging at all (`billing_enabled`).
197
+ */
198
+ get(options?: RequestOptions): Promise<BillingStatus>;
199
+ /**
200
+ * `POST /billing/checkout`: the link an owner of the business opens to
201
+ * move it to the paid plan. The link carries no authority: it opens the
202
+ * console, where the owner signs in and pays. Answers
203
+ * `billing_unavailable` while zpdf is not charging, `plan_already_paid`
204
+ * for a business on the paid plan and `payment_past_due` for one whose
205
+ * payment is failing.
206
+ *
207
+ * Cancelling and resuming are done by an owner signed in to the console
208
+ * (`manage_url` in the plan status); the API refuses a secret key on
209
+ * those with `owner_session_required`.
210
+ */
211
+ checkout(options?: RequestOptions): Promise<CheckoutLink>;
212
+ }
213
+ declare class Members {
214
+ private readonly send;
215
+ constructor(send: Send);
216
+ /**
217
+ * `GET /members`: active members oldest first, then pending invitations.
218
+ * Await for one page, or iterate for every member.
219
+ *
220
+ * Inviting, changing a role and removing a member are done by an owner
221
+ * signed in to the console. The API refuses a secret key on those three
222
+ * operations with `owner_session_required`.
223
+ */
224
+ list(params?: ListParams, options?: RequestOptions): ListResult<Member>;
225
+ }
226
+ /**
227
+ * The zpdf client.
228
+ *
229
+ * const zpdf = new ZPDF({ apiKey: process.env.ZPDF_API_KEY })
230
+ * const document = await zpdf.documents.generate({ template: "invoice", data })
231
+ * const pdf = await zpdf.documents.download(document.id)
232
+ */
233
+ export declare class ZPDF {
234
+ readonly baseUrl: string;
235
+ readonly signup: Signup;
236
+ readonly examples: Examples;
237
+ readonly templates: Templates;
238
+ readonly templateVersions: TemplateVersions;
239
+ readonly documents: Documents;
240
+ readonly shareLinks: ShareLinks;
241
+ readonly assets: Assets;
242
+ readonly webhookEndpoints: WebhookEndpoints;
243
+ readonly events: Events;
244
+ readonly keys: Keys;
245
+ readonly business: BusinessResource;
246
+ readonly usage: UsageResource;
247
+ readonly billing: Billing;
248
+ readonly members: Members;
249
+ private readonly config;
250
+ constructor(options?: ZPDFOptions);
251
+ /** `GET /`: the API's version, docs address and plans. No key needed. */
252
+ info(options?: RequestOptions): Promise<ApiInfo>;
253
+ /** `GET /engine`: the browser build and font set that renders documents. No key needed. */
254
+ engine(options?: RequestOptions): Promise<Engine>;
255
+ /**
256
+ * Reads a signed URL (`download_url`, a `page_images` entry, a share
257
+ * link's `/file`) to bytes. The key is not sent: the URL is the permission.
258
+ * A URL past its time throws `ZPDFError` `url_expired`; a share link that
259
+ * is expired, revoked or unknown throws `share_link_unavailable`.
260
+ */
261
+ fetchFile(url: string, options?: RequestOptions): Promise<Uint8Array>;
262
+ }
263
+ export {};