esigncomply 0.0.0-stage → 1.0.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.
@@ -0,0 +1,75 @@
1
+ import { type Result } from "./errors";
2
+ /**
3
+ * The HTTP core every resource uses (spec 13.1): authentication, the host for
4
+ * the key's region, idempotency keys, version pinning, retries and the
5
+ * `{ data, error }` result. Nothing in here throws.
6
+ */
7
+ export interface EsignComplyOptions {
8
+ /**
9
+ * API base URL including `/v1`. Default: the host for the region in the key,
10
+ * or the `ESIGNCOMPLY_API_URL` environment variable when it is set.
11
+ */
12
+ baseUrl?: string;
13
+ /** Sent as `Esign-Comply-Version` on every request. Default: the version the key is pinned to. */
14
+ apiVersion?: string;
15
+ /** A fetch implementation. Default: the global one. */
16
+ fetch?: typeof globalThis.fetch;
17
+ /** Retries after the first attempt. Default 2. */
18
+ maxRetries?: number;
19
+ /** Per-attempt timeout in milliseconds. Default 60,000. */
20
+ timeoutMs?: number;
21
+ }
22
+ /** Options accepted by individual calls. */
23
+ export interface RequestOptions {
24
+ /**
25
+ * Sent as `Idempotency-Key` (accepted on every POST, kept for 24 hours). A
26
+ * repeat with the same key and body returns the original response. It also
27
+ * lets the SDK retry the call safely after a network error or a 5xx.
28
+ */
29
+ idempotencyKey?: string;
30
+ /** Overrides `Esign-Comply-Version` for this call. */
31
+ apiVersion?: string;
32
+ signal?: AbortSignal;
33
+ }
34
+ export type QueryValue = string | number | boolean | null | undefined | Array<string | number>;
35
+ export type Query = Record<string, QueryValue>;
36
+ export interface RawRequest {
37
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
38
+ /** Path under the base URL, e.g. `/sessions`. */
39
+ path: string;
40
+ query?: object;
41
+ body?: unknown;
42
+ options?: RequestOptions;
43
+ /** Authenticate with this token instead of the API key (a session client token). */
44
+ token?: string;
45
+ }
46
+ export interface BinaryResponse {
47
+ bytes: Uint8Array;
48
+ contentType: string;
49
+ /** From `Content-Disposition`, when the API named the file. */
50
+ filename?: string;
51
+ }
52
+ /** The API base URL for a key: the region code in the key selects the host (spec 13.1 "Key formats"). */
53
+ export declare function baseUrlForKey(apiKey: string): string;
54
+ export declare function keyMode(apiKey: string): "test" | "live" | null;
55
+ export declare class HttpClient {
56
+ readonly baseUrl: string;
57
+ readonly apiKey: string;
58
+ private readonly apiVersion;
59
+ private readonly fetchImpl;
60
+ private readonly maxRetries;
61
+ private readonly timeoutMs;
62
+ private readonly sleep;
63
+ constructor(apiKey: string | undefined, options?: EsignComplyOptions);
64
+ /** A JSON request. */
65
+ request<T>(req: RawRequest): Promise<Result<T>>;
66
+ /** A request whose successful response is a file. */
67
+ requestBinary(req: RawRequest): Promise<Result<BinaryResponse>>;
68
+ /** A request that may answer with JSON or with a file, depending on the content type. */
69
+ requestEither<T>(req: RawRequest): Promise<Result<T | BinaryResponse>>;
70
+ /** Fetch a URL outside the API (a signed download or upload URL). The API key is never sent. */
71
+ external(url: string, init: RequestInit, context: string): Promise<Result<Response>>;
72
+ private send;
73
+ private attempt;
74
+ private read;
75
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The error every SDK method returns instead of throwing (spec 13.1 "Errors",
3
+ * 13.9). Branch on `type` first and treat a `code` you do not know as its
4
+ * `type`: new codes can be added at any time (BC-3, BC-4).
5
+ */
6
+ /** A known value, or any other string the API may add later (BC-3). */
7
+ export type Open<T extends string> = T | (string & {});
8
+ export type EscErrorType = Open<"invalid_request_error" | "authentication_error" | "permission_error" | "conflict_error" | "ceremony_error" | "conformance_error" | "quota_error" | "billing_error" | "rate_limit_error" | "api_error">;
9
+ export type EscErrorCode = Open<"invalid_request" | "jurisdiction_unknown" | "missing_api_key" | "invalid_api_key" | "client_token_expired" | "domain_not_verified" | "domain_mismatch" | "insufficient_permission" | "plan_feature_unavailable" | "signer_certificates_disabled" | "not_found" | "subject_not_found" | "idempotency_conflict" | "step_out_of_order" | "session_not_active" | "domain_already_registered" | "record_not_timestamped" | "baseline_unchanged" | "rollback_unavailable" | "region_mismatch" | "steps_incomplete" | "conformance_failed" | "render_mismatch" | "document_type_excluded" | "verification_failed" | "version_not_published" | "jurisdiction_not_enabled" | "signer_region_required" | "jurisdiction_fact_required" | "certificate_set_too_large" | "certificate_field_unavailable" | "file_type_refused" | "file_hash_mismatch" | "file_too_large" | "quota_exhausted" | "quota_exceeded" | "certificate_charge_unconfirmed" | "certificate_spend_limit_reached" | "payment_method_required" | "storage_limit_reached" | "rate_limit_exceeded" | "test_quota_exceeded" | "internal_error" | "service_unavailable" | "certificate_verification_failed" | "network_error" | "invalid_response" | "webhook_signature_missing" | "webhook_timestamp_out_of_tolerance" | "webhook_signature_invalid" | "webhook_payload_invalid">;
10
+ export interface EscError {
11
+ type: EscErrorType;
12
+ code: EscErrorCode;
13
+ message: string;
14
+ /** The request field that caused the error, when there is exactly one. */
15
+ param?: string;
16
+ /** Present on `steps_incomplete` and `step_out_of_order`. */
17
+ missing_steps?: string[];
18
+ /** Rule ID that produced the error, for matching to a prompt instruction. */
19
+ rule?: string;
20
+ /** Present on `certificate_charge_unconfirmed`: what the request would cost. */
21
+ quote?: Record<string, unknown>;
22
+ /** Conformance findings behind the error. */
23
+ findings?: unknown[];
24
+ doc_url?: string;
25
+ /** Value of `X-Request-Id`. Quote it to support. */
26
+ request_id?: string;
27
+ /** HTTP status. 0 when no response was received or the error was raised by the SDK. */
28
+ status: number;
29
+ /** Seconds from the `Retry-After` header, when the API sent one. */
30
+ retry_after?: number;
31
+ /** Any further machine-readable detail the API attached. */
32
+ [detail: string]: unknown;
33
+ }
34
+ /** What every method resolves to. Exactly one of `data` and `error` is null. */
35
+ export type Result<T> = {
36
+ data: T;
37
+ error: null;
38
+ } | {
39
+ data: null;
40
+ error: EscError;
41
+ };
42
+ export declare function ok<T>(data: T): Result<T>;
43
+ export declare function fail<T = never>(error: EscError): Result<T>;
44
+ /** Map an error response to an EscError. `body` is the parsed JSON, or undefined when the body was not JSON. */
45
+ export declare function errorFromResponse(status: number, body: unknown, headers: {
46
+ requestId: string | null;
47
+ retryAfter: number | null;
48
+ }): EscError;
49
+ export declare function networkError(err: unknown, context: string): EscError;
@@ -0,0 +1,95 @@
1
+ import { type EsignComplyOptions, type RawRequest } from "./client";
2
+ import type { Result } from "./errors";
3
+ import { ApiKeys, Conformance, Domains, Prompts, UsageResource } from "./resources/account";
4
+ import { Certificates } from "./resources/certificates";
5
+ import { Documents } from "./resources/documents";
6
+ import { Guidance } from "./resources/guidance";
7
+ import { Jurisdictions } from "./resources/jurisdictions";
8
+ import { Profiles } from "./resources/profiles";
9
+ import { Records } from "./resources/records";
10
+ import { Sessions } from "./resources/sessions";
11
+ import { Signers } from "./resources/signers";
12
+ import { Files, Supplements } from "./resources/supplements";
13
+ import { Webhooks } from "./resources/webhooks";
14
+ import type { VerificationResult } from "./types";
15
+ /**
16
+ * Server SDK for Esign Comply.
17
+ *
18
+ * ```ts
19
+ * import { EsignComply } from "esigncomply";
20
+ * const esc = new EsignComply(process.env.ESIGNCOMPLY_API_KEY!);
21
+ *
22
+ * const { data: session, error } = await esc.sessions.create({ … }, { idempotencyKey });
23
+ * if (error) { … }
24
+ * ```
25
+ *
26
+ * Every method resolves to `{ data, error }` and never throws (spec 13.11).
27
+ * The one exception is the constructor, which refuses to run in a browser:
28
+ * API keys are secret and server-only. The browser gets a session client
29
+ * token from `sessions.create`, nothing else.
30
+ */
31
+ export declare class EsignComply {
32
+ readonly documents: Documents;
33
+ readonly profiles: Profiles;
34
+ readonly jurisdictions: Jurisdictions;
35
+ readonly sessions: Sessions;
36
+ readonly records: Records;
37
+ readonly certificates: Certificates;
38
+ readonly supplements: Supplements;
39
+ readonly files: Files;
40
+ readonly guidance: Guidance;
41
+ readonly signers: Signers;
42
+ readonly webhooks: Webhooks;
43
+ readonly usage: UsageResource;
44
+ readonly conformance: Conformance;
45
+ readonly prompts: Prompts;
46
+ readonly domains: Domains;
47
+ readonly apiKeys: ApiKeys;
48
+ private readonly client;
49
+ /**
50
+ * @param apiKey A secret key (`esc_test_us_…`, `esc_live_eu_…`). Default: the `ESIGNCOMPLY_API_KEY` environment variable.
51
+ * The region code in the key selects the API host.
52
+ */
53
+ constructor(apiKey?: string, options?: EsignComplyOptions);
54
+ /** The API base URL in use, e.g. `https://api.eu.esigncomply.com/v1`. */
55
+ get baseUrl(): string;
56
+ /**
57
+ * Ask the API whether a record matches its seal. Pass one of:
58
+ *
59
+ * - the full signed receipt (a compact JWS, three dot-separated parts), sent
60
+ * as `receipt`: anyone holding it may ask;
61
+ * - a record hash (`sha256:…`, or the 64 hexadecimal digits alone), sent as `record_hash`;
62
+ * - a record ID (`rec_…`), sent as `record_id`.
63
+ *
64
+ * A hash or an ID is answered only for a record of the domain and
65
+ * environment of the secret key this client was created with. The answer is
66
+ * proof status only: an ID or hash alone never reveals that a record exists
67
+ * (10.7).
68
+ *
69
+ * To verify without the API at all, use `esigncomply-verify`.
70
+ */
71
+ verify(receiptOrHash: string): Promise<Result<VerificationResult>>;
72
+ /**
73
+ * Call an endpoint this SDK version has no method for. Same contract as
74
+ * every other method: resolves to `{ data, error }`, never throws.
75
+ *
76
+ * `token` authenticates with a session client token instead of the API key,
77
+ * which is how a server reports the steps of a `server_only` session.
78
+ */
79
+ request<T = unknown>(method: RawRequest["method"], path: string, params?: {
80
+ query?: object;
81
+ body?: unknown;
82
+ idempotencyKey?: string;
83
+ apiVersion?: string;
84
+ token?: string;
85
+ signal?: AbortSignal;
86
+ }): Promise<Result<T>>;
87
+ }
88
+ export default EsignComply;
89
+ export { baseUrlForKey } from "./client";
90
+ export type { BinaryResponse, EsignComplyOptions, RequestOptions } from "./client";
91
+ export type { EscError, EscErrorCode, EscErrorType, Open, Result } from "./errors";
92
+ export { verifyWebhookSignature } from "./resources/webhooks";
93
+ export type { HeadersLike, WebhookVerifyOptions } from "./resources/webhooks";
94
+ export { VERSION } from "./version";
95
+ export type * from "./types";