@productcraft/core 0.3.0 → 0.4.1
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 +55 -15
- package/dist/index.cjs +832 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +397 -13
- package/dist/index.d.ts +397 -13
- package/dist/index.js +797 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { Middleware, Client } from 'openapi-fetch';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `paths` types from its own `_generated.d.ts`. The class delegates
|
|
9
|
-
* wire I/O to `openapi-fetch`, but exposes a Stripe-style ergonomic
|
|
10
|
-
* surface where callers reach for `pc.mail.messages.send(...)` rather
|
|
11
|
-
* than the underlying `client.POST("/v1/...")` shape.
|
|
12
|
-
*
|
|
13
|
-
* v0 ships only the underlying `client` (named `client` on each
|
|
14
|
-
* surface) — every endpoint is reachable through it. Ergonomic
|
|
15
|
-
* resource surfaces land in v0.1+ as we hand-roll them.
|
|
4
|
+
* The 0.x primitives: credential types, environment helpers, base URLs
|
|
5
|
+
* and the `openapi-fetch` client builder behind every product's
|
|
6
|
+
* `.client` escape hatch. Kept exported for compatibility; new code
|
|
7
|
+
* goes through `APIClient` (see `client.ts`).
|
|
16
8
|
*/
|
|
17
9
|
|
|
18
10
|
/**
|
|
@@ -94,7 +86,399 @@ declare function authMiddleware(auth: PCAuth | undefined): Middleware;
|
|
|
94
86
|
*
|
|
95
87
|
* When `config.auth` is omitted the client falls back to
|
|
96
88
|
* `PRODUCTCRAFT_API_KEY` (see `resolveAuth`).
|
|
89
|
+
*
|
|
90
|
+
* @deprecated Build the runtime with `new APIClient(options, baseUrl)`
|
|
91
|
+
* and take the typed escape hatch from `createOpenAPIClient<paths>(apiClient)`,
|
|
92
|
+
* which shares its credential and base URL. Kept for the 0.x product
|
|
93
|
+
* packages; removed no earlier than core 2.0.
|
|
97
94
|
*/
|
|
98
95
|
declare function makeClient<TPaths extends object>(defaultBaseUrl: string, config?: PCClientConfig): Client<TPaths>;
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
/**
|
|
98
|
+
* The error hierarchy every ProductCraft SDK throws.
|
|
99
|
+
*
|
|
100
|
+
* Every class is branded with `Symbol.for("productcraft.error.<Name>")`
|
|
101
|
+
* and answers `instanceof` through `static [Symbol.hasInstance]`, so a
|
|
102
|
+
* check like `err instanceof NotFoundError` holds even when the error
|
|
103
|
+
* was thrown by the CJS build and the check runs against the ESM build,
|
|
104
|
+
* or when two copies of `@productcraft/core` are installed.
|
|
105
|
+
*/
|
|
106
|
+
/** Base URL of the public error-code catalogue. */
|
|
107
|
+
declare const ERROR_DOCS_URL = "https://productcraft.co/docs/errors";
|
|
108
|
+
/** A string-literal union that also accepts values this SDK version does not know. */
|
|
109
|
+
type OpenEnum<T extends string> = T | (string & {});
|
|
110
|
+
/** One invalid request field, from the error envelope's `errors` list. */
|
|
111
|
+
interface ErrorParam {
|
|
112
|
+
/** The request field, e.g. `to` or `domains[0].name`. */
|
|
113
|
+
param: string;
|
|
114
|
+
message: string;
|
|
115
|
+
code?: string;
|
|
116
|
+
}
|
|
117
|
+
/** Base class of every error the SDK throws. */
|
|
118
|
+
declare class ProductCraftError extends Error {
|
|
119
|
+
static readonly brandName: string;
|
|
120
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
121
|
+
constructor(message: string, options?: {
|
|
122
|
+
cause?: unknown;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/** The client was configured in a way that cannot work (missing `workspaceId`, a key in a browser, ...). */
|
|
126
|
+
declare class ConfigurationError extends ProductCraftError {
|
|
127
|
+
static readonly brandName: string;
|
|
128
|
+
}
|
|
129
|
+
/** A webhook payload failed signature or timestamp verification. */
|
|
130
|
+
declare class WebhookVerificationError extends ProductCraftError {
|
|
131
|
+
static readonly brandName: string;
|
|
132
|
+
}
|
|
133
|
+
/** The request never produced an HTTP response (DNS, TLS, reset connection, ...). */
|
|
134
|
+
declare class APIConnectionError extends ProductCraftError {
|
|
135
|
+
static readonly brandName: string;
|
|
136
|
+
constructor(message?: string, options?: {
|
|
137
|
+
cause?: unknown;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** An attempt (or a poll) ran past its timeout. */
|
|
141
|
+
declare class APITimeoutError extends APIConnectionError {
|
|
142
|
+
static readonly brandName: string;
|
|
143
|
+
constructor(message?: string, options?: {
|
|
144
|
+
cause?: unknown;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** The caller's `AbortSignal` fired. Never retried. */
|
|
148
|
+
declare class APIUserAbortError extends ProductCraftError {
|
|
149
|
+
static readonly brandName: string;
|
|
150
|
+
constructor(message?: string, options?: {
|
|
151
|
+
cause?: unknown;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** A non-2xx HTTP response. Subclassed by status. */
|
|
155
|
+
declare class APIError extends ProductCraftError {
|
|
156
|
+
static readonly brandName: string;
|
|
157
|
+
/** HTTP status of the response. */
|
|
158
|
+
readonly status: number;
|
|
159
|
+
/** Stable, machine-readable code from the error envelope (branch on this, not on `message`). */
|
|
160
|
+
readonly code: string | undefined;
|
|
161
|
+
/** Per-field validation errors from the envelope's `errors`; empty when absent. */
|
|
162
|
+
readonly errors: ErrorParam[];
|
|
163
|
+
/** The envelope's route-specific `details` object (e.g. `{ fqdn, reason }`), when present. */
|
|
164
|
+
readonly details: Record<string, unknown> | undefined;
|
|
165
|
+
/** `https://productcraft.co/docs/errors#<code>`, when there is a code. */
|
|
166
|
+
readonly docUrl: string | undefined;
|
|
167
|
+
/** `X-Request-Id` response header, else the envelope's `request_id`. Quote it to support. */
|
|
168
|
+
readonly requestId: string | undefined;
|
|
169
|
+
/** Response headers. */
|
|
170
|
+
readonly headers: Headers;
|
|
171
|
+
/** Parsed response body (JSON when it parses, otherwise the text). */
|
|
172
|
+
readonly body: unknown;
|
|
173
|
+
constructor(status: number, body: unknown, headers: Headers, message?: string);
|
|
174
|
+
/** Build the right subclass for a status and envelope. */
|
|
175
|
+
static generate(status: number, body: unknown, headers: Headers): APIError;
|
|
176
|
+
}
|
|
177
|
+
declare class BadRequestError extends APIError {
|
|
178
|
+
static readonly brandName: string;
|
|
179
|
+
}
|
|
180
|
+
declare class AuthenticationError extends APIError {
|
|
181
|
+
static readonly brandName: string;
|
|
182
|
+
}
|
|
183
|
+
declare class PermissionDeniedError extends APIError {
|
|
184
|
+
static readonly brandName: string;
|
|
185
|
+
}
|
|
186
|
+
declare class NotFoundError extends APIError {
|
|
187
|
+
static readonly brandName: string;
|
|
188
|
+
}
|
|
189
|
+
declare class ConflictError extends APIError {
|
|
190
|
+
static readonly brandName: string;
|
|
191
|
+
}
|
|
192
|
+
/** 409 `IDEMPOTENCY_KEY_REUSE`: the same Idempotency-Key was sent with a different body. */
|
|
193
|
+
declare class IdempotencyKeyReuseError extends ConflictError {
|
|
194
|
+
static readonly brandName: string;
|
|
195
|
+
}
|
|
196
|
+
declare class UnprocessableEntityError extends APIError {
|
|
197
|
+
static readonly brandName: string;
|
|
198
|
+
}
|
|
199
|
+
/** 429. `retryAfter` is the server's `Retry-After`, in seconds, when sent. */
|
|
200
|
+
declare class RateLimitError extends APIError {
|
|
201
|
+
static readonly brandName: string;
|
|
202
|
+
readonly retryAfter: number | undefined;
|
|
203
|
+
constructor(status: number, body: unknown, headers: Headers, message?: string);
|
|
204
|
+
}
|
|
205
|
+
/** Any 5xx. */
|
|
206
|
+
declare class InternalServerError extends APIError {
|
|
207
|
+
static readonly brandName: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Milliseconds the server asked us to wait: `retry-after-ms`, else
|
|
211
|
+
* `Retry-After` as seconds or an HTTP date. `undefined` when absent or
|
|
212
|
+
* unparseable; negative dates clamp to 0.
|
|
213
|
+
*/
|
|
214
|
+
declare function parseRetryAfterMs(headers: Headers, now: number): number | undefined;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* `APIPromise`: what every SDK method returns. Await it for the parsed
|
|
218
|
+
* body, or call `.withResponse()` / `.asResponse()` for the HTTP layer.
|
|
219
|
+
*/
|
|
220
|
+
/** Metadata attached (non-enumerable) to every object an SDK method returns. */
|
|
221
|
+
interface LastResponse {
|
|
222
|
+
requestId: string | undefined;
|
|
223
|
+
status: number;
|
|
224
|
+
headers: Headers;
|
|
225
|
+
}
|
|
226
|
+
/** Parsed `X-RateLimit-*` headers. Fields are `undefined` when the header is absent. */
|
|
227
|
+
interface RateLimitInfo {
|
|
228
|
+
limit: number | undefined;
|
|
229
|
+
remaining: number | undefined;
|
|
230
|
+
/** As sent by the server (seconds until reset, or a unix timestamp, per API). */
|
|
231
|
+
reset: number | undefined;
|
|
232
|
+
}
|
|
233
|
+
interface WithResponse<T> {
|
|
234
|
+
data: T;
|
|
235
|
+
response: Response;
|
|
236
|
+
requestId: string | undefined;
|
|
237
|
+
rateLimit: RateLimitInfo | undefined;
|
|
238
|
+
}
|
|
239
|
+
/** What the transport hands to an `APIPromise`: a successful response plus how to parse it. */
|
|
240
|
+
interface RawResult {
|
|
241
|
+
response: Response;
|
|
242
|
+
requestId: string | undefined;
|
|
243
|
+
}
|
|
244
|
+
declare function parseRateLimit(headers: Headers): RateLimitInfo | undefined;
|
|
245
|
+
/** Attach `lastResponse` to an object without it showing up in `JSON.stringify`, spreads or `Object.keys`. */
|
|
246
|
+
declare function attachLastResponse<T>(data: T, meta: LastResponse): T;
|
|
247
|
+
declare class APIPromise<T> extends Promise<T> {
|
|
248
|
+
#private;
|
|
249
|
+
constructor(raw: Promise<RawResult>, parse: (raw: RawResult) => Promise<T>);
|
|
250
|
+
static get [Symbol.species](): PromiseConstructor;
|
|
251
|
+
/** The parsed body plus the `Response`, request id and rate-limit headers. */
|
|
252
|
+
withResponse(): Promise<WithResponse<T>>;
|
|
253
|
+
/** The raw `Response`, body unread. Use instead of awaiting (the body can only be read once). */
|
|
254
|
+
asResponse(): Promise<Response>;
|
|
255
|
+
then<R1 = T, R2 = never>(onfulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null, onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
|
|
256
|
+
catch<R = never>(onrejected?: ((reason: unknown) => R | PromiseLike<R>) | null): Promise<T | R>;
|
|
257
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Cursor pagination over the uniform `{ data, pagination: { next_cursor, has_more } }` shape.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
/** The wire shape of every paginated list response. */
|
|
265
|
+
interface PageResponse<Item> {
|
|
266
|
+
data: Item[];
|
|
267
|
+
pagination?: {
|
|
268
|
+
next_cursor?: string | null;
|
|
269
|
+
has_more?: boolean;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/** One page of a list. `await`ing a list call gives you this. */
|
|
273
|
+
declare class Page<Item> {
|
|
274
|
+
#private;
|
|
275
|
+
readonly data: Item[];
|
|
276
|
+
readonly has_more: boolean;
|
|
277
|
+
readonly next_cursor: string | null;
|
|
278
|
+
readonly lastResponse: LastResponse;
|
|
279
|
+
constructor(body: PageResponse<Item>, fetchPage: (cursor: string) => PagePromise<Item>);
|
|
280
|
+
hasNextPage(): boolean;
|
|
281
|
+
/** Fetch the following page. Throws when there is none (check `hasNextPage()` first). */
|
|
282
|
+
getNextPage(): PagePromise<Item>;
|
|
283
|
+
/** The wire shape, so `JSON.stringify(page)` matches the API response. */
|
|
284
|
+
toJSON(): PageResponse<Item>;
|
|
285
|
+
}
|
|
286
|
+
interface ToArrayOptions {
|
|
287
|
+
/** Required cap on how many items to collect across pages. `limit` stays the page size. */
|
|
288
|
+
maxItems: number;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Returned by paginated list methods. `await` it for the first `Page`;
|
|
292
|
+
* `for await` over it for every item across pages; `.pages()` for pages.
|
|
293
|
+
*/
|
|
294
|
+
declare class PagePromise<Item> extends APIPromise<Page<Item>> implements AsyncIterable<Item> {
|
|
295
|
+
constructor(raw: Promise<RawResult>, parse: (raw: RawResult) => Promise<Page<Item>>);
|
|
296
|
+
/** Iterate pages, starting with this one. */
|
|
297
|
+
pages(): AsyncGenerator<Page<Item>, void, undefined>;
|
|
298
|
+
[Symbol.asyncIterator](): AsyncGenerator<Item, void, undefined>;
|
|
299
|
+
/** Collect items across pages, stopping at `maxItems`. */
|
|
300
|
+
toArray(options: ToArrayOptions): Promise<Item[]>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Webhook signature verification, shared by every product.
|
|
305
|
+
*
|
|
306
|
+
* Two schemes are accepted:
|
|
307
|
+
*
|
|
308
|
+
* - **Standard Webhooks** (`webhook-id`, `webhook-timestamp`,
|
|
309
|
+
* `webhook-signature: v1,<base64> [v1,<base64> ...]`), HMAC-SHA256 over
|
|
310
|
+
* `<id>.<timestamp>.<body>`. A `whsec_` secret is base64 key bytes; any
|
|
311
|
+
* other secret is used as its UTF-8 bytes (Mail secrets minted before
|
|
312
|
+
* Standard Webhooks support).
|
|
313
|
+
* - **Legacy** `X-<Product>-Signature: t=<unix>,v1=<hex>`, HMAC-SHA256
|
|
314
|
+
* over `<t>.<body>` with the secret's UTF-8 bytes (Auth audit sink,
|
|
315
|
+
* Trawl, Social, Mail's first scheme).
|
|
316
|
+
*
|
|
317
|
+
* Uses `crypto.subtle` only (Node 20.3+, Bun, Deno, edge) and compares in
|
|
318
|
+
* constant time.
|
|
319
|
+
*/
|
|
320
|
+
/** Node `IncomingHttpHeaders`, a Fetch `Headers`, or any plain header record. */
|
|
321
|
+
type WebhookHeaders = Headers | Record<string, string | string[] | undefined> | Iterable<[string, string]>;
|
|
322
|
+
/** The raw request body, exactly as received. Never a parsed object. */
|
|
323
|
+
type WebhookPayload = string | Uint8Array | ArrayBuffer;
|
|
324
|
+
interface VerifyWebhookParams {
|
|
325
|
+
payload: WebhookPayload;
|
|
326
|
+
headers: WebhookHeaders;
|
|
327
|
+
/** One secret, or several (Mail: default, per-domain and endpoint secrets; rotation). */
|
|
328
|
+
secret: string | readonly string[];
|
|
329
|
+
/** Maximum age (and clock skew) of the timestamp, in seconds. Default 300. */
|
|
330
|
+
toleranceSeconds?: number;
|
|
331
|
+
/** Override "now" (ms since epoch), for tests. */
|
|
332
|
+
now?: number;
|
|
333
|
+
}
|
|
334
|
+
/** Lower-case header lookup over every supported header shape. */
|
|
335
|
+
declare function normalizeHeaders(headers: WebhookHeaders): Map<string, string>;
|
|
336
|
+
/** Constant-time comparison of two byte strings (length is not secret). */
|
|
337
|
+
declare function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Verify a webhook's signature and timestamp, then return the parsed
|
|
340
|
+
* JSON payload. Throws `WebhookVerificationError` on any failure.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* const event = await verifyWebhook({ payload: rawBody, headers: req.headers, secret: process.env.WEBHOOK_SECRET! });
|
|
344
|
+
*/
|
|
345
|
+
declare function verifyWebhook<T = unknown>(params: VerifyWebhookParams): Promise<T>;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* `APIClient`: the hand-written runtime every generated resource method
|
|
349
|
+
* calls. Nothing per-endpoint lives here (docs/sdk-standard.md section 4).
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
353
|
+
type LogLevel = "off" | "warn" | "debug";
|
|
354
|
+
/** Anything with pino- or console-shaped methods. */
|
|
355
|
+
interface Logger {
|
|
356
|
+
debug(...args: unknown[]): void;
|
|
357
|
+
info(...args: unknown[]): void;
|
|
358
|
+
warn(...args: unknown[]): void;
|
|
359
|
+
error(...args: unknown[]): void;
|
|
360
|
+
}
|
|
361
|
+
interface ClientOptions {
|
|
362
|
+
/** Workspace API key (`pcft_live_…`). Falls back to `PRODUCTCRAFT_API_KEY`. Shorthand for `auth: { type: "apiKey", key }`. */
|
|
363
|
+
apiKey?: string;
|
|
364
|
+
/** Explicit credential (API key, bearer token or cookie). Wins over `apiKey`. */
|
|
365
|
+
auth?: PCAuth;
|
|
366
|
+
/** Override the product's base URL. */
|
|
367
|
+
baseUrl?: string;
|
|
368
|
+
/**
|
|
369
|
+
* Default `{workspace_id}`. Falls back to `PRODUCTCRAFT_WORKSPACE_ID`, then (workspace API keys only)
|
|
370
|
+
* one cached `GET /v1/api-keys/self` lookup per process.
|
|
371
|
+
*/
|
|
372
|
+
workspaceId?: string;
|
|
373
|
+
/** Per-attempt timeout in ms. Default 60 000. */
|
|
374
|
+
timeout?: number;
|
|
375
|
+
/** Retries after the first attempt. Default 2. */
|
|
376
|
+
maxRetries?: number;
|
|
377
|
+
/** Custom `fetch` (custom transports, tracing). Defaults to the global `fetch`. */
|
|
378
|
+
fetch?: typeof fetch;
|
|
379
|
+
/** Headers sent on every request. */
|
|
380
|
+
defaultHeaders?: Record<string, string>;
|
|
381
|
+
/** Allow a workspace API key in a browser. Leaks the key to anyone who loads the page. */
|
|
382
|
+
dangerouslyAllowBrowser?: boolean;
|
|
383
|
+
/** `off` (default), `warn` or `debug`. Falls back to `PRODUCTCRAFT_LOG`. */
|
|
384
|
+
logLevel?: LogLevel;
|
|
385
|
+
/** Where log lines go. Default `console`. Never receives headers or bodies. */
|
|
386
|
+
logger?: Logger;
|
|
387
|
+
/** Default secret(s) for `webhooks.unwrap`. */
|
|
388
|
+
webhookSecret?: string | readonly string[];
|
|
389
|
+
/** Platform-auth host used for the workspace lookup. */
|
|
390
|
+
platformAuthBaseUrl?: string;
|
|
391
|
+
}
|
|
392
|
+
/** Per-request options: always the last argument of an SDK method. */
|
|
393
|
+
interface RequestOptions {
|
|
394
|
+
/** Overrides the automatic Idempotency-Key (and makes a POST/PATCH retryable). */
|
|
395
|
+
idempotencyKey?: string;
|
|
396
|
+
/** Per-attempt timeout in ms. */
|
|
397
|
+
timeout?: number;
|
|
398
|
+
maxRetries?: number;
|
|
399
|
+
headers?: Record<string, string | undefined>;
|
|
400
|
+
signal?: AbortSignal;
|
|
401
|
+
/** `{workspace_id}` for this call (bearer tokens that span workspaces). */
|
|
402
|
+
workspaceId?: string;
|
|
403
|
+
fetch?: typeof fetch;
|
|
404
|
+
}
|
|
405
|
+
/** What a generated method hands to `request()`. */
|
|
406
|
+
interface RequestSpec {
|
|
407
|
+
method: HTTPMethod;
|
|
408
|
+
/** Path template, e.g. `/v1/workspaces/{workspace_id}/domains/{id}`. */
|
|
409
|
+
path: string;
|
|
410
|
+
pathParams?: Record<string, string | number | undefined>;
|
|
411
|
+
query?: Record<string, unknown>;
|
|
412
|
+
body?: unknown;
|
|
413
|
+
headers?: Record<string, string | undefined>;
|
|
414
|
+
/** The spec declares an `Idempotency-Key` header on this operation. */
|
|
415
|
+
idempotent?: boolean;
|
|
416
|
+
/** The success response is not JSON: resolve to the raw `Response`. */
|
|
417
|
+
raw?: boolean;
|
|
418
|
+
/** Keyless, browser-safe route: send no credential. */
|
|
419
|
+
public?: boolean;
|
|
420
|
+
}
|
|
421
|
+
interface PollConfig {
|
|
422
|
+
/** Field whose value decides completion, e.g. `status`. */
|
|
423
|
+
field: string;
|
|
424
|
+
/** Values that end the poll. */
|
|
425
|
+
terminal: readonly string[];
|
|
426
|
+
}
|
|
427
|
+
interface PollOptions extends RequestOptions {
|
|
428
|
+
/** Delay between polls in ms, unless the server sends `Retry-After`. Default 2 000. */
|
|
429
|
+
intervalMs?: number;
|
|
430
|
+
/** Give up after this many ms. Default 300 000. */
|
|
431
|
+
timeoutMs?: number;
|
|
432
|
+
}
|
|
433
|
+
/** Identifies the product package in `User-Agent`. */
|
|
434
|
+
interface SDKIdentity {
|
|
435
|
+
name: string;
|
|
436
|
+
version: string;
|
|
437
|
+
}
|
|
438
|
+
declare const DEFAULT_TIMEOUT_MS = 60000;
|
|
439
|
+
declare const DEFAULT_MAX_RETRIES = 2;
|
|
440
|
+
/** Retry-After above this fails fast instead of waiting. */
|
|
441
|
+
declare const MAX_RETRY_AFTER_MS = 60000;
|
|
442
|
+
declare const PC_WORKSPACE_ID_ENV = "PRODUCTCRAFT_WORKSPACE_ID";
|
|
443
|
+
declare const PC_LOG_ENV = "PRODUCTCRAFT_LOG";
|
|
444
|
+
/** Full-jitter exponential backoff: random in [0, min(8 s, 0.5 s * 2^attempt)). */
|
|
445
|
+
declare function backoffMs(attempt: number): number;
|
|
446
|
+
/**
|
|
447
|
+
* The typed `openapi-fetch` escape hatch (`.client` on every product), over
|
|
448
|
+
* the same credential and base URL as `api`. It does not retry.
|
|
449
|
+
* A standalone function so bundles that never use it leave openapi-fetch out.
|
|
450
|
+
*/
|
|
451
|
+
declare function createOpenAPIClient<TPaths extends object>(api: APIClient): Client<TPaths>;
|
|
452
|
+
/** Clears the per-process workspace lookup cache. For tests. */
|
|
453
|
+
declare function _resetWorkspaceCache(): void;
|
|
454
|
+
declare class APIClient {
|
|
455
|
+
#private;
|
|
456
|
+
readonly baseUrl: string;
|
|
457
|
+
/** The resolved credential. Non-enumerable, so logging the client does not print the key. */
|
|
458
|
+
readonly auth: PCAuth | undefined;
|
|
459
|
+
readonly workspaceId: string | undefined;
|
|
460
|
+
readonly timeout: number;
|
|
461
|
+
readonly maxRetries: number;
|
|
462
|
+
readonly webhookSecret: string | readonly string[] | undefined;
|
|
463
|
+
constructor(options: ClientOptions | undefined, defaultBaseUrl: string, sdk?: SDKIdentity);
|
|
464
|
+
/** Send one logical API call (with retries). Resolves to the parsed body. */
|
|
465
|
+
request<T>(spec: RequestSpec, options?: RequestOptions): APIPromise<T>;
|
|
466
|
+
/** A paginated list call. `await` for one page, `for await` for every item. */
|
|
467
|
+
list<Item>(spec: RequestSpec, options?: RequestOptions): PagePromise<Item>;
|
|
468
|
+
/** Retrieve repeatedly until `config.field` reaches a terminal value. */
|
|
469
|
+
poll<T>(spec: RequestSpec, config: PollConfig, options?: PollOptions): Promise<T>;
|
|
470
|
+
/** Create, then poll the created object to a terminal state. */
|
|
471
|
+
createAndPoll<T>(createSpec: RequestSpec, retrieveSpec: (created: T) => RequestSpec, config: PollConfig, options?: PollOptions): Promise<T>;
|
|
472
|
+
/** Verify a webhook with the given secret, the client's `webhookSecret`, or `envVar`. */
|
|
473
|
+
unwrapWebhook<T = unknown>(params: {
|
|
474
|
+
payload: WebhookPayload;
|
|
475
|
+
headers: WebhookHeaders;
|
|
476
|
+
secret?: string | readonly string[];
|
|
477
|
+
toleranceSeconds?: number;
|
|
478
|
+
}, envVar?: string): Promise<T>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** This package's version, injected at build time from package.json. */
|
|
482
|
+
declare const CORE_VERSION: string;
|
|
483
|
+
|
|
484
|
+
export { APIClient, APIConnectionError, APIError, APIPromise, APITimeoutError, APIUserAbortError, AuthenticationError, BadRequestError, CORE_VERSION, type ClientOptions, ConfigurationError, ConflictError, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, ERROR_DOCS_URL, type ErrorParam, type HTTPMethod, IdempotencyKeyReuseError, InternalServerError, type LastResponse, type LogLevel, type Logger, MAX_RETRY_AFTER_MS, NotFoundError, type OpenEnum, type PCAuth, type PCClientConfig, PC_API_KEY_ENV, PC_AUTH_APP_ENV, PC_BASE_URL, PC_LOG_ENV, PC_WORKSPACE_ID_ENV, Page, PagePromise, type PageResponse, PermissionDeniedError, type PollConfig, type PollOptions, ProductCraftError, RateLimitError, type RateLimitInfo, type RawResult, type RequestOptions, type RequestSpec, type SDKIdentity, type ToArrayOptions, UnprocessableEntityError, type VerifyWebhookParams, type WebhookHeaders, type WebhookPayload, WebhookVerificationError, type WithResponse, _resetWorkspaceCache, attachLastResponse, authMiddleware, backoffMs, createOpenAPIClient, makeClient, normalizeHeaders, parseRateLimit, parseRetryAfterMs, readEnv, resolveAuth, timingSafeEqual, verifyWebhook };
|