@secondlayer/sdk 3.4.0 → 3.5.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 CHANGED
@@ -19,28 +19,48 @@ const sl = new SecondLayer({
19
19
  });
20
20
  ```
21
21
 
22
+ ## Mental model
23
+
24
+ - `sl.streams` reads raw ordered L1 events from Stacks Streams.
25
+ - `sl.index` reads decoded L2 FT/NFT transfer events from Stacks Index.
26
+ - `sl.subgraphs` reads app-specific L3 tables from Stacks Subgraphs.
27
+
22
28
  ## Stacks Streams
23
29
 
24
- Typed HTTP client.
30
+ Typed L1 HTTP client.
25
31
 
26
32
  `sk-sl_streams_status_public` is a public, non-secret Free-tier key used by the
27
33
  Second Layer status page. Production apps should use their own Streams API key.
28
34
 
35
+ ```typescript
36
+ const tip = await sl.streams.tip();
37
+ const page = await sl.streams.events.list({
38
+ types: ["ft_transfer"],
39
+ contractId: "SP...sbtc-token",
40
+ limit: 10,
41
+ });
42
+
43
+ console.log({ tip, firstCursor: page.events[0]?.cursor });
44
+ ```
45
+
46
+ `createStreamsClient` remains available for focused Streams-only consumers:
47
+
29
48
  ```typescript
30
49
  import { createStreamsClient } from "@secondlayer/sdk";
31
50
 
32
- const client = createStreamsClient({
51
+ const streams = createStreamsClient({
33
52
  apiKey: process.env.SECONDLAYER_API_KEY!,
34
- baseUrl: process.env.SECONDLAYER_API_URL,
35
53
  });
54
+ ```
36
55
 
37
- const tip = await client.tip();
38
- const page = await client.events.list({
39
- types: ["ft_transfer"],
40
- limit: 10,
41
- });
56
+ Convenience reads:
42
57
 
43
- console.log({ tip, firstCursor: page.events[0]?.cursor });
58
+ ```typescript
59
+ await sl.streams.canonical(182431);
60
+ await sl.streams.events.byTxId("0x...");
61
+ await sl.streams.blocks.events(182431);
62
+ await sl.streams.blocks.events("0xindex-block-hash");
63
+ await sl.streams.reorgs.list({ since: "2026-05-03T00:00:00.000Z" });
44
64
  ```
45
65
 
46
66
  Checkpointed consumer.
@@ -120,9 +140,37 @@ the decoder. Decoders throw when the event type or payload is malformed. Add new
120
140
  helpers beside `src/streams/ft-transfer.ts` and export them through
121
141
  `src/streams/index.ts`.
122
142
 
123
- ## Subgraphs
143
+ ## Stacks Index
124
144
 
125
- Deploy and query subgraphs (custom indexers).
145
+ Decoded L2 transfer events.
146
+
147
+ ```typescript
148
+ const ftPage = await sl.index.ftTransfers.list({
149
+ contractId: "SP...sbtc-token",
150
+ sender: "SP...",
151
+ limit: 100,
152
+ });
153
+
154
+ const nftPage = await sl.index.nftTransfers.list({
155
+ assetIdentifier: "SP...collection::token",
156
+ recipient: "SP...",
157
+ });
158
+ ```
159
+
160
+ Backfill with SDK walkers:
161
+
162
+ ```typescript
163
+ for await (const transfer of sl.index.ftTransfers.walk({
164
+ fromHeight: 0,
165
+ batchSize: 500,
166
+ })) {
167
+ console.log(transfer.cursor, transfer.amount);
168
+ }
169
+ ```
170
+
171
+ ## Stacks Subgraphs
172
+
173
+ Deploy and query app-specific L3 tables.
126
174
 
127
175
  ```typescript
128
176
  // List
@@ -138,6 +186,15 @@ const rows = await sl.subgraphs.queryTable("my-subgraph", "transfers", {
138
186
  limit: 50,
139
187
  });
140
188
 
189
+ const { count } = await sl.subgraphs.queryTableCount(
190
+ "my-subgraph",
191
+ "transfers",
192
+ );
193
+
194
+ const spec = await sl.subgraphs.openapi("my-subgraph");
195
+ const source = await sl.subgraphs.getSource("my-subgraph");
196
+ const gaps = await sl.subgraphs.gaps("my-subgraph");
197
+
141
198
  // Deploy
142
199
  const result = await sl.subgraphs.deploy({ name, sources, schema, handlerCode });
143
200
  ```
package/dist/index.d.ts CHANGED
@@ -2,11 +2,14 @@ import { ReindexResponse, SubgraphDetail, SubgraphGapsResponse, SubgraphQueryPar
2
2
  import { DeploySubgraphRequest, DeploySubgraphResponse } from "@secondlayer/shared/schemas/subgraphs";
3
3
  import { SubgraphAgentSchema, SubgraphSpecOptions } from "@secondlayer/shared/subgraphs/spec";
4
4
  import { InferSubgraphClient } from "@secondlayer/subgraphs";
5
+ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
5
6
  interface SecondLayerOptions {
6
7
  /** Base URL of the Secondlayer API (trailing slashes are stripped). */
7
8
  baseUrl: string;
8
9
  /** Bearer token for authenticated requests. */
9
10
  apiKey?: string;
11
+ /** Fetch implementation. Tests and edge runtimes can provide their own. */
12
+ fetchImpl?: FetchLike;
10
13
  /** Deploy origin label sent as `x-sl-origin` (telemetry). Defaults to `cli`. */
11
14
  origin?: "cli" | "mcp" | "session";
12
15
  }
@@ -188,59 +191,6 @@ declare class Index extends BaseClient {
188
191
  private walkFtTransfers;
189
192
  private walkNftTransfers;
190
193
  }
191
- import { CreateSubscriptionRequest, CreateSubscriptionResponse, DeadRow, DeliveryRow, ReplayResult, RotateSecretResponse, SubscriptionDetail, SubscriptionSummary, UpdateSubscriptionRequest } from "@secondlayer/shared/schemas/subscriptions";
192
- import { CreateSubscriptionRequest as CreateSubscriptionRequest2, CreateSubscriptionResponse as CreateSubscriptionResponse2, DeadRow as DeadRow2, DeliveryRow as DeliveryRow2, ReplayResult as ReplayResult2, RotateSecretResponse as RotateSecretResponse2, SubscriptionDetail as SubscriptionDetail2, SubscriptionFormat, SubscriptionRuntime, SubscriptionStatus, SubscriptionSummary as SubscriptionSummary2, UpdateSubscriptionRequest as UpdateSubscriptionRequest2 } from "@secondlayer/shared/schemas/subscriptions";
193
- declare class Subscriptions extends BaseClient {
194
- list(): Promise<{
195
- data: SubscriptionSummary[]
196
- }>;
197
- get(id: string): Promise<SubscriptionDetail>;
198
- create(input: CreateSubscriptionRequest): Promise<CreateSubscriptionResponse>;
199
- update(id: string, patch: UpdateSubscriptionRequest): Promise<SubscriptionDetail>;
200
- pause(id: string): Promise<SubscriptionDetail>;
201
- resume(id: string): Promise<SubscriptionDetail>;
202
- delete(id: string): Promise<{
203
- ok: true
204
- }>;
205
- rotateSecret(id: string): Promise<RotateSecretResponse>;
206
- recentDeliveries(id: string): Promise<{
207
- data: DeliveryRow[]
208
- }>;
209
- replay(id: string, range: {
210
- fromBlock: number
211
- toBlock: number
212
- }): Promise<ReplayResult>;
213
- dead(id: string): Promise<{
214
- data: DeadRow[]
215
- }>;
216
- requeueDead(id: string, outboxId: string): Promise<{
217
- ok: true
218
- }>;
219
- }
220
- declare class SecondLayer extends BaseClient {
221
- readonly index: Index;
222
- readonly subgraphs: Subgraphs;
223
- readonly subscriptions: Subscriptions;
224
- constructor(options?: Partial<SecondLayerOptions>);
225
- }
226
- /**
227
- * Returns a typed client for a subgraph defined with `defineSubgraph()`.
228
- *
229
- * Accepts a plain options object, a `SecondLayer` instance, or a `Subgraphs` instance.
230
- *
231
- * @example
232
- * ```ts
233
- * import mySubgraph from './subgraphs/my-subgraph'
234
- * import { getSubgraph } from '@secondlayer/sdk'
235
- *
236
- * const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })
237
- * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })
238
- * ```
239
- */
240
- declare function getSubgraph<T extends {
241
- name: string
242
- schema: Record<string, unknown>
243
- }>(def: T, options?: Partial<SecondLayerOptions> | SecondLayer | Subgraphs): InferSubgraphClient2<T>;
244
194
  declare const STREAMS_EVENT_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "print"];
245
195
  type StreamsEventType = (typeof STREAMS_EVENT_TYPES)[number];
246
196
  type StreamsEventPayload = Record<string, unknown>;
@@ -263,6 +213,13 @@ type StreamsTip = {
263
213
  burn_block_height: number
264
214
  lag_seconds: number
265
215
  };
216
+ type StreamsCanonicalBlock = {
217
+ block_height: number
218
+ index_block_hash: string
219
+ burn_block_height: number
220
+ burn_block_hash: string | null
221
+ is_canonical: true
222
+ };
266
223
  type StreamsReorg = {
267
224
  detected_at: string
268
225
  fork_point_height: number
@@ -278,16 +235,27 @@ type StreamsEventsEnvelope = {
278
235
  tip: StreamsTip
279
236
  reorgs: StreamsReorg[]
280
237
  };
238
+ type StreamsEventsListEnvelope = Omit<StreamsEventsEnvelope, "next_cursor">;
239
+ type StreamsReorgsListParams = {
240
+ since: string
241
+ limit?: number
242
+ };
243
+ type StreamsReorgsListEnvelope = {
244
+ reorgs: StreamsReorg[]
245
+ next_since: string | null
246
+ };
281
247
  type StreamsEventsListParams = {
282
248
  cursor?: string | null
283
249
  fromHeight?: number
284
250
  toHeight?: number
285
251
  types?: readonly StreamsEventType[]
252
+ contractId?: string
286
253
  limit?: number
287
254
  };
288
255
  type StreamsEventsStreamParams = {
289
256
  fromCursor?: string | null
290
257
  types?: readonly StreamsEventType[]
258
+ contractId?: string
291
259
  batchSize?: number
292
260
  emptyBackoffMs?: number
293
261
  maxPages?: number
@@ -298,6 +266,7 @@ type StreamsEventsConsumeParams = {
298
266
  fromCursor?: string | null
299
267
  mode?: "tail" | "bounded"
300
268
  types?: readonly StreamsEventType[]
269
+ contractId?: string
301
270
  batchSize?: number
302
271
  onBatch: (events: StreamsEvent[], envelope: StreamsEventsEnvelope) => Promise<string | null | undefined> | string | null | undefined
303
272
  emptyBackoffMs?: number
@@ -310,10 +279,11 @@ type StreamsEventsConsumeResult = {
310
279
  pages: number
311
280
  emptyPolls: number
312
281
  };
313
- type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
282
+ type FetchLike2 = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
314
283
  type StreamsClient = {
315
284
  events: {
316
285
  list(params?: StreamsEventsListParams): Promise<StreamsEventsEnvelope>
286
+ byTxId(txId: string): Promise<StreamsEventsListEnvelope>
317
287
  /**
318
288
  * Pull pages from Streams and call `onBatch` after each page.
319
289
  *
@@ -333,12 +303,73 @@ type StreamsClient = {
333
303
  */
334
304
  stream(params?: StreamsEventsStreamParams): AsyncIterable<StreamsEvent>
335
305
  }
306
+ blocks: {
307
+ events(heightOrHash: number | string): Promise<StreamsEventsListEnvelope>
308
+ }
309
+ reorgs: {
310
+ list(params: StreamsReorgsListParams): Promise<StreamsReorgsListEnvelope>
311
+ }
312
+ canonical(height: number): Promise<StreamsCanonicalBlock>
336
313
  tip(): Promise<StreamsTip>
337
314
  };
315
+ import { CreateSubscriptionRequest, CreateSubscriptionResponse, DeadRow, DeliveryRow, ReplayResult, RotateSecretResponse, SubscriptionDetail, SubscriptionSummary, UpdateSubscriptionRequest } from "@secondlayer/shared/schemas/subscriptions";
316
+ import { CreateSubscriptionRequest as CreateSubscriptionRequest2, CreateSubscriptionResponse as CreateSubscriptionResponse2, DeadRow as DeadRow2, DeliveryRow as DeliveryRow2, ReplayResult as ReplayResult2, RotateSecretResponse as RotateSecretResponse2, SubscriptionDetail as SubscriptionDetail2, SubscriptionFormat, SubscriptionRuntime, SubscriptionStatus, SubscriptionSummary as SubscriptionSummary2, UpdateSubscriptionRequest as UpdateSubscriptionRequest2 } from "@secondlayer/shared/schemas/subscriptions";
317
+ declare class Subscriptions extends BaseClient {
318
+ list(): Promise<{
319
+ data: SubscriptionSummary[]
320
+ }>;
321
+ get(id: string): Promise<SubscriptionDetail>;
322
+ create(input: CreateSubscriptionRequest): Promise<CreateSubscriptionResponse>;
323
+ update(id: string, patch: UpdateSubscriptionRequest): Promise<SubscriptionDetail>;
324
+ pause(id: string): Promise<SubscriptionDetail>;
325
+ resume(id: string): Promise<SubscriptionDetail>;
326
+ delete(id: string): Promise<{
327
+ ok: true
328
+ }>;
329
+ rotateSecret(id: string): Promise<RotateSecretResponse>;
330
+ recentDeliveries(id: string): Promise<{
331
+ data: DeliveryRow[]
332
+ }>;
333
+ replay(id: string, range: {
334
+ fromBlock: number
335
+ toBlock: number
336
+ }): Promise<ReplayResult>;
337
+ dead(id: string): Promise<{
338
+ data: DeadRow[]
339
+ }>;
340
+ requeueDead(id: string, outboxId: string): Promise<{
341
+ ok: true
342
+ }>;
343
+ }
344
+ declare class SecondLayer extends BaseClient {
345
+ readonly streams: StreamsClient;
346
+ readonly index: Index;
347
+ readonly subgraphs: Subgraphs;
348
+ readonly subscriptions: Subscriptions;
349
+ constructor(options?: Partial<SecondLayerOptions>);
350
+ }
351
+ /**
352
+ * Returns a typed client for a subgraph defined with `defineSubgraph()`.
353
+ *
354
+ * Accepts a plain options object, a `SecondLayer` instance, or a `Subgraphs` instance.
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * import mySubgraph from './subgraphs/my-subgraph'
359
+ * import { getSubgraph } from '@secondlayer/sdk'
360
+ *
361
+ * const client = getSubgraph(mySubgraph, { apiKey: 'sl_...' })
362
+ * const rows = await client.transfers.findMany({ where: { sender: 'SP...' } })
363
+ * ```
364
+ */
365
+ declare function getSubgraph<T extends {
366
+ name: string
367
+ schema: Record<string, unknown>
368
+ }>(def: T, options?: Partial<SecondLayerOptions> | SecondLayer | Subgraphs): InferSubgraphClient2<T>;
338
369
  type CreateStreamsClientOptions = {
339
370
  apiKey: string
340
371
  baseUrl?: string
341
- fetchImpl?: FetchLike
372
+ fetchImpl?: FetchLike2
342
373
  };
343
374
  declare function createStreamsClient(options: CreateStreamsClientOptions): StreamsClient;
344
375
  declare class AuthError extends Error {
@@ -483,4 +514,4 @@ declare class VersionConflictError extends ApiError {
483
514
  * ```
484
515
  */
485
516
  declare function verifyWebhookSignature(rawBody: string, signatureHeader: string, secret: string, toleranceSeconds?: number): boolean;
486
- export { verifyWebhookSignature, isNftTransfer, isFtTransfer, getSubgraph, decodeNftTransfer, decodeFtTransfer, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsServerError, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsClient, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, IndexTip, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike, DeliveryRow2 as DeliveryRow, DecodedNftTransferPayload, DecodedNftTransfer, DecodedFtTransferPayload, DecodedFtTransfer, DecodedEventRow, DeadRow2 as DeadRow, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, AuthError, ApiError };
517
+ export { verifyWebhookSignature, isNftTransfer, isFtTransfer, getSubgraph, decodeNftTransfer, decodeFtTransfer, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsClient, StreamsCanonicalBlock, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, IndexTip, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, DeliveryRow2 as DeliveryRow, DecodedNftTransferPayload, DecodedNftTransfer, DecodedFtTransferPayload, DecodedFtTransfer, DecodedEventRow, DeadRow2 as DeadRow, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, AuthError, ApiError };
package/dist/index.js CHANGED
@@ -381,69 +381,6 @@ class Index extends BaseClient {
381
381
  }
382
382
  }
383
383
 
384
- // src/subscriptions/client.ts
385
- class Subscriptions extends BaseClient {
386
- async list() {
387
- return this.request("GET", "/api/subscriptions");
388
- }
389
- async get(id) {
390
- return this.request("GET", `/api/subscriptions/${id}`);
391
- }
392
- async create(input) {
393
- return this.request("POST", "/api/subscriptions", input);
394
- }
395
- async update(id, patch) {
396
- return this.request("PATCH", `/api/subscriptions/${id}`, patch);
397
- }
398
- async pause(id) {
399
- return this.request("POST", `/api/subscriptions/${id}/pause`);
400
- }
401
- async resume(id) {
402
- return this.request("POST", `/api/subscriptions/${id}/resume`);
403
- }
404
- async delete(id) {
405
- return this.request("DELETE", `/api/subscriptions/${id}`);
406
- }
407
- async rotateSecret(id) {
408
- return this.request("POST", `/api/subscriptions/${id}/rotate-secret`);
409
- }
410
- async recentDeliveries(id) {
411
- return this.request("GET", `/api/subscriptions/${id}/deliveries`);
412
- }
413
- async replay(id, range) {
414
- return this.request("POST", `/api/subscriptions/${id}/replay`, range);
415
- }
416
- async dead(id) {
417
- return this.request("GET", `/api/subscriptions/${id}/dead`);
418
- }
419
- async requeueDead(id, outboxId) {
420
- return this.request("POST", `/api/subscriptions/${id}/dead/${outboxId}/requeue`);
421
- }
422
- }
423
-
424
- // src/client.ts
425
- class SecondLayer extends BaseClient {
426
- index;
427
- subgraphs;
428
- subscriptions;
429
- constructor(options = {}) {
430
- super(options);
431
- this.index = new Index(options);
432
- this.subgraphs = new Subgraphs(options);
433
- this.subscriptions = new Subscriptions(options);
434
- }
435
- }
436
-
437
- // src/subgraphs/get-subgraph.ts
438
- function getSubgraph(def, options = {}) {
439
- if (options instanceof Subgraphs) {
440
- return options.typed(def);
441
- }
442
- if (options instanceof SecondLayer) {
443
- return options.subgraphs.typed(def);
444
- }
445
- return new Subgraphs(options).typed(def);
446
- }
447
384
  // src/streams/consumer.ts
448
385
  async function defaultSleep(ms, signal) {
449
386
  if (signal?.aborted)
@@ -471,7 +408,8 @@ async function consumeStreamsEvents(opts) {
471
408
  const envelope = await opts.fetchEvents({
472
409
  cursor,
473
410
  limit: opts.batchSize,
474
- types: opts.types
411
+ types: opts.types,
412
+ contractId: opts.contractId
475
413
  });
476
414
  pages++;
477
415
  const returnedCursor = await opts.onBatch(envelope.events, envelope);
@@ -505,7 +443,8 @@ async function* streamStreamsEvents(opts) {
505
443
  const envelope = await opts.fetchEvents({
506
444
  cursor,
507
445
  limit: opts.batchSize,
508
- types: opts.types
446
+ types: opts.types,
447
+ contractId: opts.contractId
509
448
  });
510
449
  pages++;
511
450
  for (const event of envelope.events) {
@@ -630,9 +569,10 @@ function createStreamsClient(options) {
630
569
  const fetchEvents = async ({
631
570
  cursor,
632
571
  limit,
633
- types
572
+ types,
573
+ contractId
634
574
  }) => {
635
- return listEvents({ cursor, limit, types });
575
+ return listEvents({ cursor, limit, types, contractId });
636
576
  };
637
577
  async function listEvents(params = {}) {
638
578
  const searchParams = new URLSearchParams;
@@ -640,6 +580,7 @@ function createStreamsClient(options) {
640
580
  appendSearchParam2(searchParams, "from_height", params.fromHeight);
641
581
  appendSearchParam2(searchParams, "to_height", params.toHeight);
642
582
  appendSearchParam2(searchParams, "limit", params.limit);
583
+ appendSearchParam2(searchParams, "contract_id", params.contractId);
643
584
  if (params.types?.length) {
644
585
  searchParams.set("types", params.types.join(","));
645
586
  }
@@ -649,11 +590,15 @@ function createStreamsClient(options) {
649
590
  return {
650
591
  events: {
651
592
  list: listEvents,
593
+ byTxId(txId) {
594
+ return request(`/v1/streams/events/${encodeURIComponent(txId)}`);
595
+ },
652
596
  consume(params) {
653
597
  return consumeStreamsEvents({
654
598
  fromCursor: params.fromCursor,
655
599
  mode: params.mode,
656
600
  types: params.types,
601
+ contractId: params.contractId,
657
602
  batchSize: params.batchSize ?? 100,
658
603
  fetchEvents,
659
604
  onBatch: params.onBatch,
@@ -667,6 +612,7 @@ function createStreamsClient(options) {
667
612
  return streamStreamsEvents({
668
613
  fromCursor: params.fromCursor,
669
614
  types: params.types,
615
+ contractId: params.contractId,
670
616
  batchSize: params.batchSize ?? 100,
671
617
  emptyBackoffMs: params.emptyBackoffMs,
672
618
  maxPages: params.maxPages,
@@ -676,11 +622,98 @@ function createStreamsClient(options) {
676
622
  });
677
623
  }
678
624
  },
625
+ blocks: {
626
+ events(heightOrHash) {
627
+ return request(`/v1/streams/blocks/${encodeURIComponent(String(heightOrHash))}/events`);
628
+ }
629
+ },
630
+ reorgs: {
631
+ list(params) {
632
+ const searchParams = new URLSearchParams;
633
+ appendSearchParam2(searchParams, "since", params.since);
634
+ appendSearchParam2(searchParams, "limit", params.limit);
635
+ const query = searchParams.toString();
636
+ return request(`/v1/streams/reorgs${query ? `?${query}` : ""}`);
637
+ }
638
+ },
639
+ canonical(height) {
640
+ return request(`/v1/streams/canonical/${height}`);
641
+ },
679
642
  tip() {
680
643
  return request("/v1/streams/tip");
681
644
  }
682
645
  };
683
646
  }
647
+
648
+ // src/subscriptions/client.ts
649
+ class Subscriptions extends BaseClient {
650
+ async list() {
651
+ return this.request("GET", "/api/subscriptions");
652
+ }
653
+ async get(id) {
654
+ return this.request("GET", `/api/subscriptions/${id}`);
655
+ }
656
+ async create(input) {
657
+ return this.request("POST", "/api/subscriptions", input);
658
+ }
659
+ async update(id, patch) {
660
+ return this.request("PATCH", `/api/subscriptions/${id}`, patch);
661
+ }
662
+ async pause(id) {
663
+ return this.request("POST", `/api/subscriptions/${id}/pause`);
664
+ }
665
+ async resume(id) {
666
+ return this.request("POST", `/api/subscriptions/${id}/resume`);
667
+ }
668
+ async delete(id) {
669
+ return this.request("DELETE", `/api/subscriptions/${id}`);
670
+ }
671
+ async rotateSecret(id) {
672
+ return this.request("POST", `/api/subscriptions/${id}/rotate-secret`);
673
+ }
674
+ async recentDeliveries(id) {
675
+ return this.request("GET", `/api/subscriptions/${id}/deliveries`);
676
+ }
677
+ async replay(id, range) {
678
+ return this.request("POST", `/api/subscriptions/${id}/replay`, range);
679
+ }
680
+ async dead(id) {
681
+ return this.request("GET", `/api/subscriptions/${id}/dead`);
682
+ }
683
+ async requeueDead(id, outboxId) {
684
+ return this.request("POST", `/api/subscriptions/${id}/dead/${outboxId}/requeue`);
685
+ }
686
+ }
687
+
688
+ // src/client.ts
689
+ class SecondLayer extends BaseClient {
690
+ streams;
691
+ index;
692
+ subgraphs;
693
+ subscriptions;
694
+ constructor(options = {}) {
695
+ super(options);
696
+ this.streams = createStreamsClient({
697
+ apiKey: options.apiKey ?? "",
698
+ baseUrl: options.baseUrl,
699
+ fetchImpl: options.fetchImpl
700
+ });
701
+ this.index = new Index(options);
702
+ this.subgraphs = new Subgraphs(options);
703
+ this.subscriptions = new Subscriptions(options);
704
+ }
705
+ }
706
+
707
+ // src/subgraphs/get-subgraph.ts
708
+ function getSubgraph(def, options = {}) {
709
+ if (options instanceof Subgraphs) {
710
+ return options.typed(def);
711
+ }
712
+ if (options instanceof SecondLayer) {
713
+ return options.subgraphs.typed(def);
714
+ }
715
+ return new Subgraphs(options).typed(def);
716
+ }
684
717
  // src/streams/ft-transfer.ts
685
718
  function requireString(payload, field) {
686
719
  const value = payload[field];
@@ -832,5 +865,5 @@ export {
832
865
  ApiError
833
866
  };
834
867
 
835
- //# debugId=2771C8998C150B3F64756E2164756E21
868
+ //# debugId=B2B1ED63B1AB801664756E2164756E21
836
869
  //# sourceMappingURL=index.js.map