@secondlayer/sdk 6.54.1 → 8.0.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/README.md +3 -7
- package/dist/index.d.ts +10 -740
- package/dist/index.js +41 -623
- package/dist/index.js.map +14 -22
- package/dist/sinks/bun-sqlite.js +2 -24
- package/dist/sinks/bun-sqlite.js.map +3 -3
- package/dist/sinks/core.js +2 -24
- package/dist/sinks/core.js.map +3 -3
- package/dist/sinks/drizzle.js +2 -24
- package/dist/sinks/drizzle.js.map +3 -3
- package/dist/sinks/kysely.js +2 -24
- package/dist/sinks/kysely.js.map +3 -3
- package/dist/streams/index.d.ts +9 -378
- package/dist/streams/index.js +35 -309
- package/dist/streams/index.js.map +9 -15
- package/dist/streams/rows.d.ts +2 -355
- package/dist/streams/rows.js +26 -280
- package/dist/streams/rows.js.map +4 -10
- package/dist/subgraphs/index.d.ts +1 -294
- package/dist/subgraphs/index.js +10 -174
- package/dist/subgraphs/index.js.map +10 -13
- package/package.json +4 -8
- package/dist/x402.d.ts +0 -160
- package/dist/x402.js +0 -531
- package/dist/x402.js.map +0 -12
package/dist/index.d.ts
CHANGED
|
@@ -122,21 +122,6 @@ declare class Subgraphs extends BaseClient {
|
|
|
122
122
|
message: string;
|
|
123
123
|
}>;
|
|
124
124
|
/**
|
|
125
|
-
* Publish: claim the name in the global public namespace and open anon
|
|
126
|
-
* reads on /v1/subgraphs/:name. 409 PUBLIC_NAME_TAKEN if another account
|
|
127
|
-
* holds the public name.
|
|
128
|
-
*/
|
|
129
|
-
publish(name: string): Promise<{
|
|
130
|
-
name: string;
|
|
131
|
-
visibility: "public";
|
|
132
|
-
url: string;
|
|
133
|
-
}>;
|
|
134
|
-
/** Make reads private again (owning account's bearer key required). */
|
|
135
|
-
unpublish(name: string): Promise<{
|
|
136
|
-
name: string;
|
|
137
|
-
visibility: "private";
|
|
138
|
-
}>;
|
|
139
|
-
/**
|
|
140
125
|
* Open /v1 read: cursor-paginated rows. Anon works for public subgraphs;
|
|
141
126
|
* pass an apiKey on the client for private ones. Resume with the returned
|
|
142
127
|
* `next_cursor`.
|
|
@@ -186,63 +171,6 @@ declare class Subgraphs extends BaseClient {
|
|
|
186
171
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
187
172
|
import { SubgraphSummary as SubgraphSummary2 } from "@secondlayer/shared/schemas";
|
|
188
173
|
/**
|
|
189
|
-
* Typed client for the agent-reachable key mint (`POST /v1/api-keys`).
|
|
190
|
-
*
|
|
191
|
-
* Lets a headless agent self-provision a SCOPED `streams`/`index` read key
|
|
192
|
-
* without the dashboard. Requires an owner credential — an account-level API
|
|
193
|
-
* key (or a dashboard session). The minted key is always scoped (never an
|
|
194
|
-
* account/superkey) and inherits the account plan's tier.
|
|
195
|
-
*/
|
|
196
|
-
/** Scope of a minted read key. */
|
|
197
|
-
type ScopedKeyProduct = "streams" | "index";
|
|
198
|
-
interface CreateApiKeyParams {
|
|
199
|
-
/** Scope of the minted key. Defaults to "streams". */
|
|
200
|
-
product?: ScopedKeyProduct;
|
|
201
|
-
/** Optional human-readable label for the key. */
|
|
202
|
-
name?: string;
|
|
203
|
-
}
|
|
204
|
-
interface CreateApiKeyResponse {
|
|
205
|
-
/** Plaintext key — returned ONCE. Store it now; only its hash is persisted. */
|
|
206
|
-
key: string;
|
|
207
|
-
prefix: string;
|
|
208
|
-
id: string;
|
|
209
|
-
product: string;
|
|
210
|
-
tier: string | null;
|
|
211
|
-
createdAt: string;
|
|
212
|
-
}
|
|
213
|
-
/** A key as seen by {@link ApiKeys.list} — metadata only, never the plaintext. */
|
|
214
|
-
interface ApiKeySummary {
|
|
215
|
-
id: string;
|
|
216
|
-
prefix: string;
|
|
217
|
-
name: string | null;
|
|
218
|
-
status: "active" | "revoked";
|
|
219
|
-
product: string;
|
|
220
|
-
tier: string | null;
|
|
221
|
-
createdAt: string;
|
|
222
|
-
lastUsedAt: string | null;
|
|
223
|
-
}
|
|
224
|
-
declare class ApiKeys extends BaseClient {
|
|
225
|
-
constructor(options?: Partial<SecondLayerOptions>);
|
|
226
|
-
/**
|
|
227
|
-
* Mint a new scoped read key. The configured `apiKey` must be an
|
|
228
|
-
* account-level (owner) key; the plaintext `key` in the response is shown
|
|
229
|
-
* only once.
|
|
230
|
-
*/
|
|
231
|
-
create(params?: CreateApiKeyParams): Promise<CreateApiKeyResponse>;
|
|
232
|
-
/**
|
|
233
|
-
* List the account's keys (metadata only — no plaintext). Requires an
|
|
234
|
-
* account-level (owner) key or a dashboard session.
|
|
235
|
-
*/
|
|
236
|
-
list(): Promise<{
|
|
237
|
-
keys: ApiKeySummary[];
|
|
238
|
-
}>;
|
|
239
|
-
/** Revoke a key by id. Existing requests with that key stop working. */
|
|
240
|
-
revoke(id: string): Promise<{
|
|
241
|
-
revoked: true;
|
|
242
|
-
id: string;
|
|
243
|
-
}>;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
174
|
* Typed client for the contract-discovery API (`GET /v1/contracts`).
|
|
247
175
|
*
|
|
248
176
|
* "Find all contracts conforming to a trait" — backed by the contract registry:
|
|
@@ -499,114 +427,8 @@ type SinkTx<S> = S extends ConsumerSink<infer Tx> ? Tx : never;
|
|
|
499
427
|
type WithSinkTx<TTx> = [TTx] extends [never] ? unknown : {
|
|
500
428
|
tx: TTx;
|
|
501
429
|
};
|
|
502
|
-
import { StreamsEventType } from "@secondlayer/shared";
|
|
503
|
-
|
|
504
|
-
* object carrying that hex (`{ hex }`), or a decoded Clarity-JSON object.
|
|
505
|
-
* Decode helpers (`decodeNftTransfer`, etc.) resolve it to a concrete value. */
|
|
506
|
-
type StreamsClarityValue = string | {
|
|
507
|
-
hex: string;
|
|
508
|
-
} | Record<string, unknown>;
|
|
509
|
-
type StxTransferPayload = {
|
|
510
|
-
sender: string;
|
|
511
|
-
recipient: string;
|
|
512
|
-
amount: string;
|
|
513
|
-
memo?: string;
|
|
514
|
-
};
|
|
515
|
-
type StxMintPayload = {
|
|
516
|
-
recipient: string;
|
|
517
|
-
amount: string;
|
|
518
|
-
};
|
|
519
|
-
type StxBurnPayload = {
|
|
520
|
-
sender: string;
|
|
521
|
-
amount: string;
|
|
522
|
-
};
|
|
523
|
-
type StxLockPayload = {
|
|
524
|
-
locked_address: string;
|
|
525
|
-
locked_amount: string;
|
|
526
|
-
unlock_height: string;
|
|
527
|
-
};
|
|
528
|
-
type FtTransferPayload = {
|
|
529
|
-
asset_identifier: string;
|
|
530
|
-
sender: string;
|
|
531
|
-
recipient: string;
|
|
532
|
-
amount: string;
|
|
533
|
-
};
|
|
534
|
-
type FtMintPayload = {
|
|
535
|
-
asset_identifier: string;
|
|
536
|
-
recipient: string;
|
|
537
|
-
amount: string;
|
|
538
|
-
};
|
|
539
|
-
type FtBurnPayload = {
|
|
540
|
-
asset_identifier: string;
|
|
541
|
-
sender: string;
|
|
542
|
-
amount: string;
|
|
543
|
-
};
|
|
544
|
-
type NftTransferPayload = {
|
|
545
|
-
asset_identifier: string;
|
|
546
|
-
sender: string;
|
|
547
|
-
recipient: string;
|
|
548
|
-
value: StreamsClarityValue;
|
|
549
|
-
/** Canonical serialized hex of `value`, when the stream carries it. */
|
|
550
|
-
raw_value?: string;
|
|
551
|
-
};
|
|
552
|
-
type NftMintPayload = {
|
|
553
|
-
asset_identifier: string;
|
|
554
|
-
recipient: string;
|
|
555
|
-
value: StreamsClarityValue;
|
|
556
|
-
raw_value?: string;
|
|
557
|
-
};
|
|
558
|
-
type NftBurnPayload = {
|
|
559
|
-
asset_identifier: string;
|
|
560
|
-
sender: string;
|
|
561
|
-
value: StreamsClarityValue;
|
|
562
|
-
raw_value?: string;
|
|
563
|
-
};
|
|
564
|
-
type PrintPayload = {
|
|
565
|
-
contract_id?: string | null;
|
|
566
|
-
topic?: string;
|
|
567
|
-
value?: unknown;
|
|
568
|
-
raw_value?: string;
|
|
569
|
-
};
|
|
570
|
-
/** Union of every Streams payload shape, discriminated by `event_type` on the
|
|
571
|
-
* parent `StreamsEvent`. */
|
|
572
|
-
type StreamsEventPayload = StxTransferPayload | StxMintPayload | StxBurnPayload | StxLockPayload | FtTransferPayload | FtMintPayload | FtBurnPayload | NftTransferPayload | NftMintPayload | NftBurnPayload | PrintPayload;
|
|
573
|
-
type StreamsEventBase = {
|
|
574
|
-
/**
|
|
575
|
-
* Globally unique, monotonic position of this event (`<block>:<index>`). Use
|
|
576
|
-
* it as the primary key of your projection rows — replaying a batch then
|
|
577
|
-
* upserts cleanly. Don't synthesize your own id from `tx_id`/`event_index`.
|
|
578
|
-
*/
|
|
579
|
-
cursor: string;
|
|
580
|
-
block_height: number;
|
|
581
|
-
block_hash: string;
|
|
582
|
-
burn_block_height: number;
|
|
583
|
-
tx_id: string;
|
|
584
|
-
tx_index: number;
|
|
585
|
-
event_index: number;
|
|
586
|
-
contract_id: string | null;
|
|
587
|
-
ts: string;
|
|
588
|
-
/**
|
|
589
|
-
* True when this event's block is past the finality boundary (immutable).
|
|
590
|
-
* Optional for back-compat; the API always sets it on Streams responses.
|
|
591
|
-
*/
|
|
592
|
-
finalized?: boolean;
|
|
593
|
-
/**
|
|
594
|
-
* Labels whose filter group this event satisfied, present only when the
|
|
595
|
-
* request used a labelled `filters` map. The SDK dispatches on it for you
|
|
596
|
-
* (`on.<label>`), so handlers rarely read it directly.
|
|
597
|
-
*/
|
|
598
|
-
matched?: string[];
|
|
599
|
-
};
|
|
600
|
-
type StreamsEventOf<
|
|
601
|
-
T extends StreamsEventType,
|
|
602
|
-
P
|
|
603
|
-
> = StreamsEventBase & {
|
|
604
|
-
event_type: T;
|
|
605
|
-
payload: P;
|
|
606
|
-
};
|
|
607
|
-
/** A raw Streams event. Discriminated on `event_type`, so `event.payload`
|
|
608
|
-
* narrows to the matching payload shape once the type is checked. */
|
|
609
|
-
type StreamsEvent = StreamsEventOf<"stx_transfer", StxTransferPayload> | StreamsEventOf<"stx_mint", StxMintPayload> | StreamsEventOf<"stx_burn", StxBurnPayload> | StreamsEventOf<"stx_lock", StxLockPayload> | StreamsEventOf<"ft_transfer", FtTransferPayload> | StreamsEventOf<"ft_mint", FtMintPayload> | StreamsEventOf<"ft_burn", FtBurnPayload> | StreamsEventOf<"nft_transfer", NftTransferPayload> | StreamsEventOf<"nft_mint", NftMintPayload> | StreamsEventOf<"nft_burn", NftBurnPayload> | StreamsEventOf<"print", PrintPayload>;
|
|
430
|
+
import { StreamsEvent, StreamsEventType } from "@secondlayer/shared/streams-rows";
|
|
431
|
+
import { StreamsEventPayload } from "@secondlayer/shared/streams-rows";
|
|
610
432
|
type StreamsTip = {
|
|
611
433
|
block_height: number;
|
|
612
434
|
block_hash: string;
|
|
@@ -1103,20 +925,6 @@ type StreamsClient = {
|
|
|
1103
925
|
dumps: StreamsDumps;
|
|
1104
926
|
canonical(height: number): Promise<StreamsCanonicalBlock>;
|
|
1105
927
|
tip(): Promise<StreamsTip>;
|
|
1106
|
-
/** Your own Streams consumption (events today + this month) and tier limits. */
|
|
1107
|
-
usage(): Promise<StreamsUsage>;
|
|
1108
|
-
};
|
|
1109
|
-
type StreamsUsage = {
|
|
1110
|
-
product: "streams";
|
|
1111
|
-
tier: string;
|
|
1112
|
-
limits: {
|
|
1113
|
-
rate_limit_per_second: number | null;
|
|
1114
|
-
retention_days: number | null;
|
|
1115
|
-
};
|
|
1116
|
-
usage: {
|
|
1117
|
-
events_today: number;
|
|
1118
|
-
events_this_month: number;
|
|
1119
|
-
};
|
|
1120
928
|
};
|
|
1121
929
|
type Sleep = (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
1122
930
|
/** Options shared by both consume loops' page-fetch retry. Vocabulary matches
|
|
@@ -1270,17 +1078,6 @@ type IndexReorg = {
|
|
|
1270
1078
|
*/
|
|
1271
1079
|
new_canonical_tip: string;
|
|
1272
1080
|
};
|
|
1273
|
-
type IndexUsage = {
|
|
1274
|
-
product: "index";
|
|
1275
|
-
tier: string;
|
|
1276
|
-
limits: {
|
|
1277
|
-
rate_limit_per_second: number | null;
|
|
1278
|
-
};
|
|
1279
|
-
usage: {
|
|
1280
|
-
decoded_events_today: number;
|
|
1281
|
-
decoded_events_this_month: number;
|
|
1282
|
-
};
|
|
1283
|
-
};
|
|
1284
1081
|
type FtTransfer = {
|
|
1285
1082
|
cursor: string;
|
|
1286
1083
|
block_height: number;
|
|
@@ -2375,8 +2172,6 @@ type IndexDiscovery = {
|
|
|
2375
2172
|
};
|
|
2376
2173
|
declare class Index extends BaseClient {
|
|
2377
2174
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
2378
|
-
/** Your own Index consumption (decoded events today + this month) and tier limits. */
|
|
2379
|
-
usage(): Promise<IndexUsage>;
|
|
2380
2175
|
/**
|
|
2381
2176
|
* Index discovery doc — the live vocabulary: every endpoint, each event type's
|
|
2382
2177
|
* columns, allowed/equality filters, and required-non-null fields. Read this to
|
|
@@ -2505,76 +2300,6 @@ declare class Index extends BaseClient {
|
|
|
2505
2300
|
private walkPoxCycles;
|
|
2506
2301
|
private getPoxCycle;
|
|
2507
2302
|
}
|
|
2508
|
-
/**
|
|
2509
|
-
* Typed client for project management (`/api/projects/*`).
|
|
2510
|
-
*
|
|
2511
|
-
* Projects are the account-scoped containers for work. Every method requires an
|
|
2512
|
-
* account-level (owner) API key or a dashboard session — scoped read keys are
|
|
2513
|
-
* rejected. Team mutations (invite/remove/role) are intentionally not exposed
|
|
2514
|
-
* here; only the read view ({@link Projects.team}) is.
|
|
2515
|
-
*/
|
|
2516
|
-
interface Project {
|
|
2517
|
-
id: string;
|
|
2518
|
-
name: string;
|
|
2519
|
-
slug: string;
|
|
2520
|
-
network: string;
|
|
2521
|
-
nodeRpc: string | null;
|
|
2522
|
-
settings: Record<string, unknown> | null;
|
|
2523
|
-
createdAt: string;
|
|
2524
|
-
updatedAt: string;
|
|
2525
|
-
}
|
|
2526
|
-
interface ProjectTeamMember {
|
|
2527
|
-
id: string;
|
|
2528
|
-
role: string;
|
|
2529
|
-
email: string;
|
|
2530
|
-
displayName: string | null;
|
|
2531
|
-
avatarUrl: string | null;
|
|
2532
|
-
createdAt: string;
|
|
2533
|
-
}
|
|
2534
|
-
interface ProjectInvitation {
|
|
2535
|
-
id: string;
|
|
2536
|
-
email: string;
|
|
2537
|
-
role: string;
|
|
2538
|
-
expiresAt: string;
|
|
2539
|
-
createdAt: string;
|
|
2540
|
-
}
|
|
2541
|
-
interface ProjectTeam {
|
|
2542
|
-
members: ProjectTeamMember[];
|
|
2543
|
-
invitations: ProjectInvitation[];
|
|
2544
|
-
}
|
|
2545
|
-
interface CreateProjectParams {
|
|
2546
|
-
name: string;
|
|
2547
|
-
slug?: string;
|
|
2548
|
-
network?: string;
|
|
2549
|
-
nodeRpc?: string;
|
|
2550
|
-
}
|
|
2551
|
-
interface UpdateProjectParams {
|
|
2552
|
-
name?: string;
|
|
2553
|
-
/** Rename the project's URL slug. */
|
|
2554
|
-
slug?: string;
|
|
2555
|
-
network?: string;
|
|
2556
|
-
nodeRpc?: string;
|
|
2557
|
-
settings?: Record<string, unknown>;
|
|
2558
|
-
}
|
|
2559
|
-
declare class Projects extends BaseClient {
|
|
2560
|
-
constructor(options?: Partial<SecondLayerOptions>);
|
|
2561
|
-
/** All projects owned by the account, newest-relevant first. */
|
|
2562
|
-
list(): Promise<{
|
|
2563
|
-
projects: Project[];
|
|
2564
|
-
}>;
|
|
2565
|
-
/** A single project by slug. */
|
|
2566
|
-
get(slug: string): Promise<Project>;
|
|
2567
|
-
/** Create a project. The creator is added as the project owner. */
|
|
2568
|
-
create(params: CreateProjectParams): Promise<Project>;
|
|
2569
|
-
/** Update a project's name, slug (rename), network, RPC, or settings. */
|
|
2570
|
-
update(slug: string, patch: UpdateProjectParams): Promise<Project>;
|
|
2571
|
-
/** Delete a project. The account's last remaining project cannot be deleted. */
|
|
2572
|
-
delete(slug: string): Promise<{
|
|
2573
|
-
ok: true;
|
|
2574
|
-
}>;
|
|
2575
|
-
/** Team members and pending invitations for a project. */
|
|
2576
|
-
team(slug: string): Promise<ProjectTeam>;
|
|
2577
|
-
}
|
|
2578
2303
|
import { CreateSubscriptionRequest, CreateSubscriptionResponse, DeadRow, DeliveryRow, ReplayResult, RotateSecretResponse, SubscriptionDetail, SubscriptionSummary, SubscriptionTestResult, UpdateSubscriptionRequest } from "@secondlayer/shared/schemas/subscriptions";
|
|
2579
2304
|
import { ChainTrigger, ChainTriggerType, CreateSubscriptionRequest as CreateSubscriptionRequest2, CreateSubscriptionResponse as CreateSubscriptionResponse2, DeadRow as DeadRow2, DeliveryRow as DeliveryRow2, ReplayResult as ReplayResult2, RotateSecretResponse as RotateSecretResponse2, SubscriptionDetail as SubscriptionDetail2, SubscriptionFormat, SubscriptionKind, SubscriptionRuntime, SubscriptionStatus, SubscriptionSummary as SubscriptionSummary2, UpdateSubscriptionRequest as UpdateSubscriptionRequest2 } from "@secondlayer/shared/schemas/subscriptions";
|
|
2580
2305
|
import { trigger } from "@secondlayer/shared/schemas/subscriptions";
|
|
@@ -2611,20 +2336,6 @@ declare class Subscriptions extends BaseClient {
|
|
|
2611
2336
|
}
|
|
2612
2337
|
interface ContextAccount {
|
|
2613
2338
|
email: string;
|
|
2614
|
-
plan: string;
|
|
2615
|
-
}
|
|
2616
|
-
/** Compact project view for {@link ContextSnapshot}. */
|
|
2617
|
-
interface ContextProject {
|
|
2618
|
-
name: string;
|
|
2619
|
-
slug: string;
|
|
2620
|
-
network: string;
|
|
2621
|
-
}
|
|
2622
|
-
/** Compact API-key view for {@link ContextSnapshot} — never the plaintext. */
|
|
2623
|
-
interface ContextApiKey {
|
|
2624
|
-
prefix: string;
|
|
2625
|
-
name: string | null;
|
|
2626
|
-
status: string;
|
|
2627
|
-
product: string;
|
|
2628
2339
|
}
|
|
2629
2340
|
interface ActiveSubgraphOperation {
|
|
2630
2341
|
subgraph: string;
|
|
@@ -2647,10 +2358,6 @@ interface ContextSnapshot {
|
|
|
2647
2358
|
count: number;
|
|
2648
2359
|
byStatus: Record<string, number>;
|
|
2649
2360
|
} | null;
|
|
2650
|
-
/** The account's projects (null when unreadable — e.g. a scoped key). */
|
|
2651
|
-
projects: ContextProject[] | null;
|
|
2652
|
-
/** The account's API keys, metadata only (null when unreadable). */
|
|
2653
|
-
apiKeys: ContextApiKey[] | null;
|
|
2654
2361
|
/** In-flight reindex operations (bounded to subgraphs reporting `reindexing`). */
|
|
2655
2362
|
activeOperations: ActiveSubgraphOperation[] | null;
|
|
2656
2363
|
}
|
|
@@ -2660,8 +2367,6 @@ declare class SecondLayer extends BaseClient {
|
|
|
2660
2367
|
readonly contracts: Contracts;
|
|
2661
2368
|
readonly subgraphs: Subgraphs;
|
|
2662
2369
|
readonly subscriptions: Subscriptions;
|
|
2663
|
-
readonly apiKeys: ApiKeys;
|
|
2664
|
-
readonly projects: Projects;
|
|
2665
2370
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
2666
2371
|
/**
|
|
2667
2372
|
* Assemble a {@link ContextSnapshot} — the same orientation an MCP agent reads
|
|
@@ -2758,12 +2463,11 @@ declare function createStreamsClient(options: CreateStreamsClientOptions): Strea
|
|
|
2758
2463
|
* appears in your code at all.
|
|
2759
2464
|
*/
|
|
2760
2465
|
declare function decode(event: StreamsEvent): IndexEvent;
|
|
2761
|
-
import { ByoBreakingChangeDetails } from "@secondlayer/shared/errors";
|
|
2762
2466
|
/** Options accepted by every error in the family. */
|
|
2763
2467
|
interface SecondLayerErrorOptions {
|
|
2764
2468
|
cause?: Error;
|
|
2765
2469
|
details?: string;
|
|
2766
|
-
/** Stable machine-readable code (e.g. `UPGRADE_REQUIRED
|
|
2470
|
+
/** Stable machine-readable code (e.g. `UPGRADE_REQUIRED`). */
|
|
2767
2471
|
code?: string;
|
|
2768
2472
|
/** Docs page that explains this failure and its fix. */
|
|
2769
2473
|
docsUrl?: string;
|
|
@@ -2778,10 +2482,9 @@ interface SecondLayerErrorOptions {
|
|
|
2778
2482
|
* Root of the SDK error family. Implements the same protocol as `BaseError`
|
|
2779
2483
|
* in `@secondlayer/stacks` (`shortMessage`, `cause`, `toJSON`) so a failed
|
|
2780
2484
|
* chain read and a failed platform read serialize and introspect identically.
|
|
2781
|
-
* It intentionally does NOT extend that class: `
|
|
2782
|
-
*
|
|
2783
|
-
*
|
|
2784
|
-
* under per-package bundling anyway (match on `code`/`name` across packages).
|
|
2485
|
+
* It intentionally does NOT extend that class: cross-package `instanceof` is
|
|
2486
|
+
* unreliable under per-package bundling anyway (match on `code`/`name` across
|
|
2487
|
+
* packages).
|
|
2785
2488
|
*
|
|
2786
2489
|
* `retryable` is the signal the consume loops act on: 429/5xx/network are
|
|
2787
2490
|
* retryable, 4xx and body-serialization failures are not.
|
|
@@ -2863,29 +2566,6 @@ declare class VersionConflictError extends ApiError {
|
|
|
2863
2566
|
expectedVersion: string;
|
|
2864
2567
|
constructor(currentVersion: string, expectedVersion: string, message?: string);
|
|
2865
2568
|
}
|
|
2866
|
-
/**
|
|
2867
|
-
* Thrown when a BYO subgraph deploy is refused for a breaking schema change.
|
|
2868
|
-
* The deploy did NOT run — `details.plan` carries the DROP + rebuild DDL to run
|
|
2869
|
-
* manually on your own database, plus the breaking `reasons` and the `diff`.
|
|
2870
|
-
* The same DDL is surfaced on `metaMessages`, so a bare `console.error(err)`
|
|
2871
|
-
* already shows the operator what to run.
|
|
2872
|
-
*
|
|
2873
|
-
* @example
|
|
2874
|
-
* ```ts
|
|
2875
|
-
* try {
|
|
2876
|
-
* await client.subgraphs.deploy(bundle);
|
|
2877
|
-
* } catch (err) {
|
|
2878
|
-
* if (err instanceof ByoBreakingChangeError) {
|
|
2879
|
-
* console.log(err.details.plan.dropStatement);
|
|
2880
|
-
* console.log(err.details.plan.statements.join(";\n"));
|
|
2881
|
-
* }
|
|
2882
|
-
* }
|
|
2883
|
-
* ```
|
|
2884
|
-
*/
|
|
2885
|
-
declare class ByoBreakingChangeError extends ApiError {
|
|
2886
|
-
readonly details: ByoBreakingChangeDetails;
|
|
2887
|
-
constructor(message: string, details: ByoBreakingChangeDetails);
|
|
2888
|
-
}
|
|
2889
2569
|
/** Thrown on a 5xx from the Streams API. `retryable`. */
|
|
2890
2570
|
declare class StreamsServerError extends ApiError {
|
|
2891
2571
|
constructor(message: string, status: number, body?: unknown);
|
|
@@ -2894,255 +2574,8 @@ declare class StreamsServerError extends ApiError {
|
|
|
2894
2574
|
declare class StreamsSignatureError extends SecondLayerError {
|
|
2895
2575
|
constructor(message?: string);
|
|
2896
2576
|
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
}>;
|
|
2900
|
-
type DecodedFtTransferPayload = {
|
|
2901
|
-
asset_identifier: string;
|
|
2902
|
-
contract_id: string;
|
|
2903
|
-
token_name: string | null;
|
|
2904
|
-
sender: string;
|
|
2905
|
-
recipient: string;
|
|
2906
|
-
amount: string;
|
|
2907
|
-
};
|
|
2908
|
-
type DecodedFtTransfer = {
|
|
2909
|
-
cursor: string;
|
|
2910
|
-
block_height: number;
|
|
2911
|
-
tx_id: string;
|
|
2912
|
-
tx_index: number;
|
|
2913
|
-
event_index: number;
|
|
2914
|
-
event_type: "ft_transfer";
|
|
2915
|
-
decoded_payload: DecodedFtTransferPayload;
|
|
2916
|
-
source_cursor: string;
|
|
2917
|
-
};
|
|
2918
|
-
declare function isFtTransfer(event: StreamsEvent): event is FtTransferEvent;
|
|
2919
|
-
declare function decodeFtTransfer(event: StreamsEvent): DecodedFtTransfer;
|
|
2920
|
-
type NftTransferEvent = Extract<StreamsEvent, {
|
|
2921
|
-
event_type: "nft_transfer";
|
|
2922
|
-
}>;
|
|
2923
|
-
type DecodedNftTransferPayload = {
|
|
2924
|
-
asset_identifier: string;
|
|
2925
|
-
contract_id: string;
|
|
2926
|
-
token_name: string | null;
|
|
2927
|
-
sender: string;
|
|
2928
|
-
recipient: string;
|
|
2929
|
-
value: string;
|
|
2930
|
-
};
|
|
2931
|
-
type DecodedNftTransfer = {
|
|
2932
|
-
cursor: string;
|
|
2933
|
-
block_height: number;
|
|
2934
|
-
tx_id: string;
|
|
2935
|
-
tx_index: number;
|
|
2936
|
-
event_index: number;
|
|
2937
|
-
event_type: "nft_transfer";
|
|
2938
|
-
decoded_payload: DecodedNftTransferPayload;
|
|
2939
|
-
source_cursor: string;
|
|
2940
|
-
};
|
|
2941
|
-
declare function isNftTransfer(event: StreamsEvent): event is NftTransferEvent;
|
|
2942
|
-
declare function decodeNftTransfer(event: StreamsEvent): DecodedNftTransfer;
|
|
2943
|
-
type DecodedStxTransferPayload = {
|
|
2944
|
-
sender: string;
|
|
2945
|
-
recipient: string;
|
|
2946
|
-
amount: string;
|
|
2947
|
-
memo: string | null;
|
|
2948
|
-
};
|
|
2949
|
-
type DecodedStxTransfer = {
|
|
2950
|
-
cursor: string;
|
|
2951
|
-
block_height: number;
|
|
2952
|
-
tx_id: string;
|
|
2953
|
-
tx_index: number;
|
|
2954
|
-
event_index: number;
|
|
2955
|
-
event_type: "stx_transfer";
|
|
2956
|
-
decoded_payload: DecodedStxTransferPayload;
|
|
2957
|
-
source_cursor: string;
|
|
2958
|
-
};
|
|
2959
|
-
type DecodedStxMintPayload = {
|
|
2960
|
-
recipient: string;
|
|
2961
|
-
amount: string;
|
|
2962
|
-
};
|
|
2963
|
-
type DecodedStxMint = {
|
|
2964
|
-
cursor: string;
|
|
2965
|
-
block_height: number;
|
|
2966
|
-
tx_id: string;
|
|
2967
|
-
tx_index: number;
|
|
2968
|
-
event_index: number;
|
|
2969
|
-
event_type: "stx_mint";
|
|
2970
|
-
decoded_payload: DecodedStxMintPayload;
|
|
2971
|
-
source_cursor: string;
|
|
2972
|
-
};
|
|
2973
|
-
type DecodedStxBurnPayload = {
|
|
2974
|
-
sender: string;
|
|
2975
|
-
amount: string;
|
|
2976
|
-
};
|
|
2977
|
-
type DecodedStxBurn = {
|
|
2978
|
-
cursor: string;
|
|
2979
|
-
block_height: number;
|
|
2980
|
-
tx_id: string;
|
|
2981
|
-
tx_index: number;
|
|
2982
|
-
event_index: number;
|
|
2983
|
-
event_type: "stx_burn";
|
|
2984
|
-
decoded_payload: DecodedStxBurnPayload;
|
|
2985
|
-
source_cursor: string;
|
|
2986
|
-
};
|
|
2987
|
-
declare function isStxTransfer(event: StreamsEvent): event is StreamsEvent & {
|
|
2988
|
-
event_type: "stx_transfer";
|
|
2989
|
-
};
|
|
2990
|
-
declare function decodeStxTransfer(event: StreamsEvent): DecodedStxTransfer;
|
|
2991
|
-
declare function isStxMint(event: StreamsEvent): event is StreamsEvent & {
|
|
2992
|
-
event_type: "stx_mint";
|
|
2993
|
-
};
|
|
2994
|
-
declare function decodeStxMint(event: StreamsEvent): DecodedStxMint;
|
|
2995
|
-
declare function isStxBurn(event: StreamsEvent): event is StreamsEvent & {
|
|
2996
|
-
event_type: "stx_burn";
|
|
2997
|
-
};
|
|
2998
|
-
declare function decodeStxBurn(event: StreamsEvent): DecodedStxBurn;
|
|
2999
|
-
type DecodedStxLockPayload = {
|
|
3000
|
-
sender: string;
|
|
3001
|
-
amount: string;
|
|
3002
|
-
payload: {
|
|
3003
|
-
unlock_height: string | null;
|
|
3004
|
-
};
|
|
3005
|
-
};
|
|
3006
|
-
type DecodedStxLock = {
|
|
3007
|
-
cursor: string;
|
|
3008
|
-
block_height: number;
|
|
3009
|
-
tx_id: string;
|
|
3010
|
-
tx_index: number;
|
|
3011
|
-
event_index: number;
|
|
3012
|
-
event_type: "stx_lock";
|
|
3013
|
-
decoded_payload: DecodedStxLockPayload;
|
|
3014
|
-
source_cursor: string;
|
|
3015
|
-
};
|
|
3016
|
-
declare function isStxLock(event: StreamsEvent): event is StreamsEvent & {
|
|
3017
|
-
event_type: "stx_lock";
|
|
3018
|
-
};
|
|
3019
|
-
declare function decodeStxLock(event: StreamsEvent): DecodedStxLock;
|
|
3020
|
-
type DecodedFtMintPayload = {
|
|
3021
|
-
asset_identifier: string;
|
|
3022
|
-
contract_id: string;
|
|
3023
|
-
token_name: string | null;
|
|
3024
|
-
recipient: string;
|
|
3025
|
-
amount: string;
|
|
3026
|
-
};
|
|
3027
|
-
type DecodedFtMint = {
|
|
3028
|
-
cursor: string;
|
|
3029
|
-
block_height: number;
|
|
3030
|
-
tx_id: string;
|
|
3031
|
-
tx_index: number;
|
|
3032
|
-
event_index: number;
|
|
3033
|
-
event_type: "ft_mint";
|
|
3034
|
-
decoded_payload: DecodedFtMintPayload;
|
|
3035
|
-
source_cursor: string;
|
|
3036
|
-
};
|
|
3037
|
-
type DecodedFtBurnPayload = {
|
|
3038
|
-
asset_identifier: string;
|
|
3039
|
-
contract_id: string;
|
|
3040
|
-
token_name: string | null;
|
|
3041
|
-
sender: string;
|
|
3042
|
-
amount: string;
|
|
3043
|
-
};
|
|
3044
|
-
type DecodedFtBurn = {
|
|
3045
|
-
cursor: string;
|
|
3046
|
-
block_height: number;
|
|
3047
|
-
tx_id: string;
|
|
3048
|
-
tx_index: number;
|
|
3049
|
-
event_index: number;
|
|
3050
|
-
event_type: "ft_burn";
|
|
3051
|
-
decoded_payload: DecodedFtBurnPayload;
|
|
3052
|
-
source_cursor: string;
|
|
3053
|
-
};
|
|
3054
|
-
type DecodedNftMintPayload = {
|
|
3055
|
-
asset_identifier: string;
|
|
3056
|
-
contract_id: string;
|
|
3057
|
-
token_name: string | null;
|
|
3058
|
-
recipient: string;
|
|
3059
|
-
value: string;
|
|
3060
|
-
};
|
|
3061
|
-
type DecodedNftMint = {
|
|
3062
|
-
cursor: string;
|
|
3063
|
-
block_height: number;
|
|
3064
|
-
tx_id: string;
|
|
3065
|
-
tx_index: number;
|
|
3066
|
-
event_index: number;
|
|
3067
|
-
event_type: "nft_mint";
|
|
3068
|
-
decoded_payload: DecodedNftMintPayload;
|
|
3069
|
-
source_cursor: string;
|
|
3070
|
-
};
|
|
3071
|
-
type DecodedNftBurnPayload = {
|
|
3072
|
-
asset_identifier: string;
|
|
3073
|
-
contract_id: string;
|
|
3074
|
-
token_name: string | null;
|
|
3075
|
-
sender: string;
|
|
3076
|
-
value: string;
|
|
3077
|
-
};
|
|
3078
|
-
type DecodedNftBurn = {
|
|
3079
|
-
cursor: string;
|
|
3080
|
-
block_height: number;
|
|
3081
|
-
tx_id: string;
|
|
3082
|
-
tx_index: number;
|
|
3083
|
-
event_index: number;
|
|
3084
|
-
event_type: "nft_burn";
|
|
3085
|
-
decoded_payload: DecodedNftBurnPayload;
|
|
3086
|
-
source_cursor: string;
|
|
3087
|
-
};
|
|
3088
|
-
declare function isFtMint(event: StreamsEvent): event is StreamsEvent & {
|
|
3089
|
-
event_type: "ft_mint";
|
|
3090
|
-
};
|
|
3091
|
-
declare function decodeFtMint(event: StreamsEvent): DecodedFtMint;
|
|
3092
|
-
declare function isFtBurn(event: StreamsEvent): event is StreamsEvent & {
|
|
3093
|
-
event_type: "ft_burn";
|
|
3094
|
-
};
|
|
3095
|
-
declare function decodeFtBurn(event: StreamsEvent): DecodedFtBurn;
|
|
3096
|
-
declare function isNftMint(event: StreamsEvent): event is StreamsEvent & {
|
|
3097
|
-
event_type: "nft_mint";
|
|
3098
|
-
};
|
|
3099
|
-
declare function decodeNftMint(event: StreamsEvent): DecodedNftMint;
|
|
3100
|
-
declare function isNftBurn(event: StreamsEvent): event is StreamsEvent & {
|
|
3101
|
-
event_type: "nft_burn";
|
|
3102
|
-
};
|
|
3103
|
-
declare function decodeNftBurn(event: StreamsEvent): DecodedNftBurn;
|
|
3104
|
-
/** Decoded form of a Clarity `print` event:
|
|
3105
|
-
* - `topic`: the print topic, when the contract emits a `{ topic, ... }` tuple
|
|
3106
|
-
* - `value`: the Clarity value decoded to JSON (uints as strings, buffers as
|
|
3107
|
-
* `0x…` hex, tuples as objects)
|
|
3108
|
-
* - `raw_value`: the canonical serialized hex, for byte-exact consumers */
|
|
3109
|
-
type DecodedPrintValue = {
|
|
3110
|
-
topic: string | null;
|
|
3111
|
-
value: unknown;
|
|
3112
|
-
raw_value: string | null;
|
|
3113
|
-
};
|
|
3114
|
-
type DecodedPrintPayload = {
|
|
3115
|
-
contract_id: string | null;
|
|
3116
|
-
payload: DecodedPrintValue;
|
|
3117
|
-
};
|
|
3118
|
-
type DecodedPrint = {
|
|
3119
|
-
cursor: string;
|
|
3120
|
-
block_height: number;
|
|
3121
|
-
tx_id: string;
|
|
3122
|
-
tx_index: number;
|
|
3123
|
-
event_index: number;
|
|
3124
|
-
event_type: "print";
|
|
3125
|
-
decoded_payload: DecodedPrintPayload;
|
|
3126
|
-
source_cursor: string;
|
|
3127
|
-
};
|
|
3128
|
-
declare function isPrint(event: StreamsEvent): event is StreamsEvent & {
|
|
3129
|
-
event_type: "print";
|
|
3130
|
-
};
|
|
3131
|
-
declare function decodePrint(event: StreamsEvent): DecodedPrint;
|
|
3132
|
-
/** Superset of the columns the decoded_events table holds. Every decoded
|
|
3133
|
-
* event's `decoded_payload` is assignable to this, so the indexer's writer
|
|
3134
|
-
* can map columns generically instead of per-event-type. */
|
|
3135
|
-
type DecodedEventColumns = {
|
|
3136
|
-
contract_id?: string | null;
|
|
3137
|
-
asset_identifier?: string | null;
|
|
3138
|
-
sender?: string | null;
|
|
3139
|
-
recipient?: string | null;
|
|
3140
|
-
amount?: string | null;
|
|
3141
|
-
value?: string | null;
|
|
3142
|
-
memo?: string | null;
|
|
3143
|
-
/** JSONB overflow for non-flat types (e.g. print's decoded value). */
|
|
3144
|
-
payload?: unknown;
|
|
3145
|
-
};
|
|
2577
|
+
import { decodeFtTransfer, isFtTransfer, decodeNftTransfer, isNftTransfer, decodeStxBurn, decodeStxLock, decodeStxMint, decodeStxTransfer, isStxBurn, isStxLock, isStxMint, isStxTransfer, decodeFtBurn, decodeFtMint, decodeNftBurn, decodeNftMint, isFtBurn, isFtMint, isNftBurn, isNftMint, decodePrint, isPrint } from "@secondlayer/shared/streams-rows";
|
|
2578
|
+
import { DecodedEventColumns, DecodedEventRow, DecodedFtBurn, DecodedFtBurnPayload, DecodedFtMint, DecodedFtMintPayload, DecodedFtTransfer, DecodedFtTransferPayload, DecodedNftBurn, DecodedNftBurnPayload, DecodedNftMint, DecodedNftMintPayload, DecodedNftTransfer, DecodedNftTransferPayload, DecodedPrint, DecodedPrintPayload, DecodedPrintValue, DecodedStxBurn, DecodedStxBurnPayload, DecodedStxLock, DecodedStxLockPayload, DecodedStxMint, DecodedStxMintPayload, DecodedStxTransfer, DecodedStxTransferPayload, FtTransferEvent, FtTransferPayload as FtTransferPayload2, NftTransferEvent, NftTransferPayload as NftTransferPayload2 } from "@secondlayer/shared/streams-rows";
|
|
3146
2579
|
/**
|
|
3147
2580
|
* Helpers for Streams cursors. A cursor is the opaque `<block>:<index>` string
|
|
3148
2581
|
* that marks a position in the event stream; treat the format as an
|
|
@@ -3173,164 +2606,6 @@ declare const Cursor: {
|
|
|
3173
2606
|
eventIndex: number;
|
|
3174
2607
|
};
|
|
3175
2608
|
};
|
|
3176
|
-
type DecodedEventRow = DecodedFtTransfer | DecodedNftTransfer | DecodedStxTransfer | DecodedStxMint | DecodedStxBurn | DecodedStxLock | DecodedFtMint | DecodedFtBurn | DecodedNftMint | DecodedNftBurn | DecodedPrint;
|
|
3177
|
-
import { X402TokenSymbol } from "@secondlayer/shared/x402";
|
|
3178
|
-
import { LocalAccount } from "@secondlayer/stacks/accounts";
|
|
3179
|
-
import { StacksChain } from "@secondlayer/stacks/chains";
|
|
3180
|
-
/**
|
|
3181
|
-
* Client for the x402 pay-per-request rail. Turns a 402 challenge into a signed
|
|
3182
|
-
* `PAYMENT-SIGNATURE` and retries — gasless (the agent signs origin-only; the
|
|
3183
|
-
* facilitator sponsors the STX fee) and accountless (no key/Stripe/session).
|
|
3184
|
-
*
|
|
3185
|
-
* Three layers:
|
|
3186
|
-
* - `withX402(fetch, opts)` — drop-in fetch that auto-pays on 402.
|
|
3187
|
-
* - `createX402Client(opts)` — `.get/.post` returning `{ data, payment }`.
|
|
3188
|
-
* - `buildSignedX402Payment` / `readX402Challenge` — primitives for custom transports.
|
|
3189
|
-
*/
|
|
3190
|
-
type X402Accept = {
|
|
3191
|
-
scheme: "exact";
|
|
3192
|
-
network: string;
|
|
3193
|
-
asset: string;
|
|
3194
|
-
/** Atomic units. */
|
|
3195
|
-
amount: string;
|
|
3196
|
-
payTo: string;
|
|
3197
|
-
maxTimeoutSeconds: number;
|
|
3198
|
-
extra: {
|
|
3199
|
-
nonce: string;
|
|
3200
|
-
};
|
|
3201
|
-
};
|
|
3202
|
-
type X402Challenge = {
|
|
3203
|
-
x402Version: number;
|
|
3204
|
-
accepts: X402Accept[];
|
|
3205
|
-
error?: string;
|
|
3206
|
-
};
|
|
3207
|
-
/** Decoded `PAYMENT-RESPONSE` settlement receipt. */
|
|
3208
|
-
type X402Receipt = {
|
|
3209
|
-
success: boolean;
|
|
3210
|
-
/** Settlement tier: `optimistic` (served on broadcast-accept, reconciled
|
|
3211
|
-
* async) or `confirmed` (canonical). Absent on older deployments. */
|
|
3212
|
-
state?: "optimistic" | "confirmed";
|
|
3213
|
-
txid: string;
|
|
3214
|
-
payer: string;
|
|
3215
|
-
network: string;
|
|
3216
|
-
};
|
|
3217
|
-
/** Bitcoin-native first — sBTC is the compelling micropay asset; USDCx the
|
|
3218
|
-
* dollar peg; STX the fallback. Override via `preferAssets`. */
|
|
3219
|
-
declare const DEFAULT_PREFER_ASSETS: X402TokenSymbol[];
|
|
3220
|
-
/** Thrown when no offered asset is within the caller's spend guard / preferences. */
|
|
3221
|
-
declare class X402SpendGuardError extends Error {
|
|
3222
|
-
constructor(message: string);
|
|
3223
|
-
}
|
|
3224
|
-
/** Read the x402 challenge from a 402 response — prefer the wire header, fall
|
|
3225
|
-
* back to the JSON body. */
|
|
3226
|
-
declare function readX402Challenge(res: Response): Promise<X402Challenge | null>;
|
|
3227
|
-
/** Read the settlement receipt from a paid 200 response. */
|
|
3228
|
-
declare function readX402Receipt(res: Response): X402Receipt | null;
|
|
3229
|
-
type SelectOfferOptions = {
|
|
3230
|
-
preferAssets?: X402TokenSymbol[];
|
|
3231
|
-
maxAmountPerCall?: Partial<Record<X402TokenSymbol, bigint>>;
|
|
3232
|
-
};
|
|
3233
|
-
/** Choose an `accepts[]` entry by preference order, skipping any that exceed the
|
|
3234
|
-
* per-asset spend cap. Throws {@link X402SpendGuardError} if none qualify. */
|
|
3235
|
-
declare function selectOffer(challenge: X402Challenge, opts?: SelectOfferOptions): {
|
|
3236
|
-
accept: X402Accept;
|
|
3237
|
-
symbol: X402TokenSymbol;
|
|
3238
|
-
};
|
|
3239
|
-
/** Fetch the payer account's next nonce from a Stacks node (`/v2/accounts`). */
|
|
3240
|
-
declare function resolveAccountNonce(address: string, nodeUrl?: string): Promise<number>;
|
|
3241
|
-
type BuildSignedX402PaymentOptions = {
|
|
3242
|
-
challenge: X402Challenge;
|
|
3243
|
-
account: LocalAccount;
|
|
3244
|
-
/** The payer account's next nonce. */
|
|
3245
|
-
accountNonce: bigint | number | string;
|
|
3246
|
-
/** Preferred asset string (e.g. an sBTC/USDCx id). Defaults to the first offer. */
|
|
3247
|
-
asset?: string;
|
|
3248
|
-
chain?: StacksChain;
|
|
3249
|
-
};
|
|
3250
|
-
/** Build a signed, base64 `PAYMENT-SIGNATURE` header for one `accepts[]` entry. */
|
|
3251
|
-
declare function buildSignedX402Payment(opts: BuildSignedX402PaymentOptions): Promise<{
|
|
3252
|
-
header: string;
|
|
3253
|
-
accept: X402Accept;
|
|
3254
|
-
}>;
|
|
3255
|
-
type WithX402Options = SelectOfferOptions & {
|
|
3256
|
-
account: LocalAccount;
|
|
3257
|
-
/** Prepaid-credit token (PAYMENT-BALANCE) from a prior deposit — calls
|
|
3258
|
-
* debit the tab server-side instead of settling on-chain per call. */
|
|
3259
|
-
balanceToken?: string;
|
|
3260
|
-
/** Autonomous treasury policy: when the tab's remaining balance (read from
|
|
3261
|
-
* X-BALANCE-REMAINING-USD) drops below `whenBelow`, deposit `usd` more in
|
|
3262
|
-
* the background (one on-chain payment) and adopt the fresh token. */
|
|
3263
|
-
topUp?: {
|
|
3264
|
-
usd: number;
|
|
3265
|
-
whenBelow: number;
|
|
3266
|
-
};
|
|
3267
|
-
/** Override the payer nonce; auto-resolved from `nodeUrl` when omitted. */
|
|
3268
|
-
accountNonce?: bigint | number | string;
|
|
3269
|
-
/** Node for auto-nonce lookup. Defaults to {@link DEFAULT_NONCE_NODE_URL}. */
|
|
3270
|
-
nodeUrl?: string;
|
|
3271
|
-
chain?: StacksChain;
|
|
3272
|
-
/** Fired just before the paid retry (the call then blocks on confirmed-tier
|
|
3273
|
-
* settle, or returns near-instantly on an optimistic surface). */
|
|
3274
|
-
onSettling?: (info: {
|
|
3275
|
-
asset: string;
|
|
3276
|
-
amount: string;
|
|
3277
|
-
}) => void;
|
|
3278
|
-
/** Abort the paid retry after this long. */
|
|
3279
|
-
timeoutMs?: number;
|
|
3280
|
-
};
|
|
3281
|
-
type X402Fetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
3282
|
-
/**
|
|
3283
|
-
* Wrap a `fetch` so requests transparently pay on 402: select an offer (by
|
|
3284
|
-
* `preferAssets` + `maxAmountPerCall`), resolve the nonce, sign origin-only, and
|
|
3285
|
-
* retry once with `PAYMENT-SIGNATURE`. Returns the final `Response` (read the
|
|
3286
|
-
* receipt with {@link readX402Receipt}).
|
|
3287
|
-
*
|
|
3288
|
-
* @example
|
|
3289
|
-
* const x402fetch = withX402(fetch, { account });
|
|
3290
|
-
* const res = await x402fetch("http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer");
|
|
3291
|
-
*/
|
|
3292
|
-
declare function withX402(baseFetch: typeof fetch, opts: WithX402Options): X402Fetch;
|
|
3293
|
-
type X402ClientOptions = WithX402Options & {
|
|
3294
|
-
/** Instance API. Defaults to {@link resolveBaseUrl}. */
|
|
3295
|
-
baseUrl?: string;
|
|
3296
|
-
/** Override the underlying fetch (tests). */
|
|
3297
|
-
fetch?: typeof fetch;
|
|
3298
|
-
};
|
|
3299
|
-
type X402Result<T = unknown> = {
|
|
3300
|
-
data: T;
|
|
3301
|
-
/** Settlement receipt, or null if the response carried none. */
|
|
3302
|
-
payment: X402Receipt | null;
|
|
3303
|
-
response: Response;
|
|
3304
|
-
};
|
|
3305
|
-
type X402Client = {
|
|
3306
|
-
get<T = unknown>(path: string, o?: {
|
|
3307
|
-
query?: Record<string, string>;
|
|
3308
|
-
}): Promise<X402Result<T>>;
|
|
3309
|
-
post<T = unknown>(path: string, o?: {
|
|
3310
|
-
body?: unknown;
|
|
3311
|
-
}): Promise<X402Result<T>>;
|
|
3312
|
-
};
|
|
3313
|
-
/**
|
|
3314
|
-
* A small client over {@link withX402}: `.get/.post` against `baseUrl`, returning
|
|
3315
|
-
* parsed JSON plus the settlement receipt.
|
|
3316
|
-
*
|
|
3317
|
-
* @example
|
|
3318
|
-
* const sl = createX402Client({ account, baseUrl: "http://127.0.0.1:3800" });
|
|
3319
|
-
* const { data, payment } = await sl.get("/v1/index/events", { query: { event_type: "ft_transfer" } });
|
|
3320
|
-
*/
|
|
3321
|
-
declare function createX402Client(opts: X402ClientOptions): X402Client;
|
|
3322
|
-
/** Caller-supplied fetch that re-runs the request with the given extra headers. */
|
|
3323
|
-
type X402FetchFn = (extraHeaders: Record<string, string>) => Promise<Response>;
|
|
3324
|
-
type PayAndRetryOptions = Omit<WithX402Options, never> & {
|
|
3325
|
-
/** Required here (use `withX402` for auto-nonce). */
|
|
3326
|
-
accountNonce: bigint | number | string;
|
|
3327
|
-
};
|
|
3328
|
-
/**
|
|
3329
|
-
* Low-level: run a request via a caller-controlled fetch; if it 402s, pay and
|
|
3330
|
-
* retry once. Prefer {@link withX402} for the common case (it auto-resolves the
|
|
3331
|
-
* nonce + selects the asset). Kept for custom transports.
|
|
3332
|
-
*/
|
|
3333
|
-
declare function payAndRetry(doFetch: X402FetchFn, opts: PayAndRetryOptions): Promise<Response>;
|
|
3334
2609
|
import { SubgraphAgentSchema as SubgraphAgentSchema3, SubgraphSpecFormat as SubgraphSpecFormat2, SubgraphSpecOptions as SubgraphSpecOptions3 } from "@secondlayer/shared/subgraphs/spec";
|
|
3335
2610
|
/**
|
|
3336
2611
|
* The two pieces every "deploy a consumer" guide leaves out, packaged:
|
|
@@ -3530,10 +2805,5 @@ declare function verifySecondlayerSignature(rawBody: string, headers: WebhookHea
|
|
|
3530
2805
|
*/
|
|
3531
2806
|
declare function decodeChainWebhook(rawBody: string): ChainWebhookDelivery;
|
|
3532
2807
|
import { RewardSet as RewardSet2 } from "@secondlayer/shared/node/consensus";
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
declare function toJsonSafe(value: unknown): unknown;
|
|
3536
|
-
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
3537
|
-
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
3538
|
-
declare function decodeClarityValue(hex: string): unknown;
|
|
3539
|
-
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, selectOffer, resolveBaseUrl, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, decode, createX402Client, createStreamsClient, consumerHealth, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WithSinkTx, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SinkTx, SelectOfferOptions, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic2 as SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, LOCAL_API_URL, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEventFields, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, IndexAlwaysFields, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerSink, ConsumerHealth, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
|
2808
|
+
import { decodeClarityValue, toJsonSafe } from "@secondlayer/shared/streams-rows";
|
|
2809
|
+
export { verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, shutdownSignal, resolveBaseUrl, resolveApiKey, parseRetryAfter, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, decode, createStreamsClient, consumerHealth, consumeIndexFeed, WithSinkTx, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SinkTx, SecondLayerOptions, SecondLayerErrorOptions, SecondLayerError, SecondLayer, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic2 as SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload2 as NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, LOCAL_API_URL, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEventFields, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, IndexAlwaysFields, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload2 as FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextAccount, ConsumerSink, ConsumerHealth, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiError, ActiveSubgraphOperation };
|