@apostra/sdk 0.0.0-stage → 0.37.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,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './generated/client.js';
2
+ export { operations, version } from './generated/metadata.js';
3
+ export type { AdcpError, JsonValue } from './generated/types.gen.js';
4
+ export * from './transport.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './generated/client.js';
2
+ export { operations, version } from './generated/metadata.js';
3
+ export * from './transport.js';
@@ -0,0 +1,142 @@
1
+ import type { OperationTypes } from './generated/client.js';
2
+ import { type OperationId, operations } from './generated/metadata.js';
3
+ import type { AdcpError, InFlightReceipt, OpenCampaignsPageSuccessPageHumanHandoffRequired } from './generated/types.gen.js';
4
+ export type TokenProvider = () => string | Promise<string>;
5
+ export type M2mTokenProviderOptions = {
6
+ clientId: string;
7
+ clientSecret: string;
8
+ scope: string | string[];
9
+ /** Override fetch for testing or an application-owned HTTP implementation. */
10
+ fetch?: typeof globalThis.fetch;
11
+ /** Deadline for an M2M token refresh. Defaults to 30 seconds. */
12
+ timeoutMs?: number;
13
+ };
14
+ export type ClientOptions = {
15
+ /** Supply exactly one credential source. Providers own acquisition/refresh. */
16
+ apiKey?: string;
17
+ accessToken?: string;
18
+ tokenProvider?: TokenProvider;
19
+ accountId?: string;
20
+ baseUrl?: string;
21
+ fetch?: typeof globalThis.fetch;
22
+ timeoutMs?: number;
23
+ /** Retry transient read failures and caller-keyed writes this many times. */
24
+ maxRetries?: number;
25
+ };
26
+ export type RequestOptions = {
27
+ accountId?: string;
28
+ /** Required by generated write methods. Never generated or replaced by the SDK. */
29
+ idempotencyKey?: string;
30
+ signal?: AbortSignal;
31
+ timeoutMs?: number;
32
+ };
33
+ export type WriteRequestOptions = RequestOptions & {
34
+ idempotencyKey: string;
35
+ };
36
+ type WriteOperationId = {
37
+ [O in OperationId]: (typeof operations)[O]['idempotencyKey'] extends true ? O : never;
38
+ }[OperationId];
39
+ type ReadOperationId = Exclude<OperationId, WriteOperationId>;
40
+ export type ResponseDetails<T> = {
41
+ data: T;
42
+ status: number;
43
+ headers: Headers;
44
+ requestId: string | null;
45
+ };
46
+ export type HumanHandoff = Pick<OpenCampaignsPageSuccessPageHumanHandoffRequired, 'kind' | 'url' | 'expiresAt' | 'resume'>;
47
+ export type ApostraErrorCode = 'UNAUTHENTICATED' | 'AUTHENTICATION_FAILED' | 'ACCESS_DENIED' | 'NOT_FOUND' | 'CONFLICT' | 'RATE_LIMITED' | 'VALIDATION_FAILED' | (string & {});
48
+ type Recovery = 'transient' | 'correctable' | 'terminal';
49
+ export declare class ApostraError extends Error {
50
+ readonly status: number;
51
+ readonly error: AdcpError;
52
+ readonly requestId: string | null;
53
+ readonly code: ApostraErrorCode;
54
+ readonly recovery: Recovery;
55
+ readonly retryAfter: number | null;
56
+ readonly retryable: boolean;
57
+ constructor(status: number, error: AdcpError, requestId: string | null);
58
+ }
59
+ export declare class AuthenticationError extends ApostraError {
60
+ }
61
+ export declare class PermissionError extends ApostraError {
62
+ }
63
+ export declare class NotFoundError extends ApostraError {
64
+ }
65
+ export declare class ConflictError extends ApostraError {
66
+ }
67
+ export declare class RateLimitError extends ApostraError {
68
+ }
69
+ export declare class ValidationError extends ApostraError {
70
+ }
71
+ /** @deprecated This compatibility export is never thrown by the transport. */
72
+ export declare class UnsupportedCapabilityError extends Error {
73
+ }
74
+ export declare class ConnectionError extends Error {
75
+ readonly code: "CONNECTION_ERROR";
76
+ readonly recovery: "transient";
77
+ readonly retryAfter: null;
78
+ readonly retryable = true;
79
+ readonly requestId: null;
80
+ constructor(cause: unknown);
81
+ }
82
+ export declare class TimeoutError extends Error {
83
+ readonly code: "TIMEOUT";
84
+ readonly recovery: "transient";
85
+ readonly retryAfter: null;
86
+ readonly retryable = true;
87
+ readonly requestId: null;
88
+ constructor(cause: unknown);
89
+ }
90
+ export declare class ProtocolError extends Error {
91
+ readonly status: number;
92
+ readonly requestId: string | null;
93
+ constructor(status: number, requestId: string | null);
94
+ }
95
+ /**
96
+ * The server accepted a write but cannot yet honestly report its completion.
97
+ *
98
+ * Callers retain the original operation-specific idempotency key; the SDK
99
+ * never makes another request or creates a replacement key.
100
+ */
101
+ export declare class InFlightReceiptError extends Error {
102
+ readonly requestId: string | null;
103
+ readonly retryAfterMs: number | null;
104
+ readonly receipt: InFlightReceipt;
105
+ readonly status = 202;
106
+ constructor(requestId: string | null, retryAfterMs: number | null, receipt: InFlightReceipt);
107
+ }
108
+ /**
109
+ * Acquire and cache an OAuth client-credentials token for server-side use.
110
+ *
111
+ * The returned provider performs one refresh for concurrent callers and refreshes
112
+ * 60 seconds before expiry. It never persists or logs a client secret or token.
113
+ */
114
+ export declare function m2mTokenProvider({ clientId: rawClientId, clientSecret: rawClientSecret, scope: rawScope, fetch: suppliedFetch, timeoutMs: rawTimeoutMs, }: M2mTokenProviderOptions): TokenProvider;
115
+ export declare class Transport {
116
+ #private;
117
+ constructor(options?: ClientOptions);
118
+ protected request<T>(operation: OperationId, input: object, options?: RequestOptions): Promise<T>;
119
+ /** Typed dispatch for CLI reuse, including response headers. */
120
+ requestDetailed<O extends WriteOperationId>(operation: O, input: OperationTypes[O]['input'], options: WriteRequestOptions): Promise<ResponseDetails<OperationTypes[O]['result']>>;
121
+ requestDetailed<O extends ReadOperationId>(operation: O, input: OperationTypes[O]['input'], options?: RequestOptions): Promise<ResponseDetails<OperationTypes[O]['result']>>;
122
+ private perform;
123
+ }
124
+ /** Re-invoke a caller-owned keyed write until an in-flight receipt settles. */
125
+ export declare function settle<T>(run: (signal: AbortSignal) => Promise<T>, options?: {
126
+ signal?: AbortSignal;
127
+ timeoutMs?: number;
128
+ }): Promise<T>;
129
+ /** Visit pages while preserving the exact caller-owned query and cursor rules. */
130
+ export declare function paginate<T>(read: (cursor: string | undefined, signal?: AbortSignal) => Promise<T>, next: (page: T) => string | null | undefined, signal?: AbortSignal): AsyncGenerator<T>;
131
+ /** The caller supplies the contract's status predicate and keeps idempotency keys stable. */
132
+ export declare function poll<T>(read: (signal: AbortSignal) => Promise<T>, complete: (result: T) => boolean, options: {
133
+ signal: AbortSignal;
134
+ intervalMs?: number;
135
+ }): Promise<T>;
136
+ /** Return an actionable human handoff, or null when no supported URL is present. */
137
+ export declare function getHandoff(result: {
138
+ humanHandoff?: unknown;
139
+ } | null | undefined): HumanHandoff | null;
140
+ /** Pass only a handoff returned by getHandoff; headless calls simply return its URL. */
141
+ export declare function openHandoff(handoff: HumanHandoff | string, opener?: (url: string) => void | Promise<void>): Promise<string>;
142
+ export {};