@secondlayer/sdk 6.7.0 → 6.9.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 +48 -3
- package/dist/index.d.ts +125 -4
- package/dist/index.js +76 -15
- package/dist/index.js.map +10 -9
- package/dist/streams/index.d.ts +16 -3
- package/dist/streams/index.js +7 -14
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +122 -2
- package/dist/subgraphs/index.js +71 -2
- package/dist/subgraphs/index.js.map +9 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -243,14 +243,19 @@ const result = await sl.subgraphs.deploy({ name, sources, schema, handlerCode })
|
|
|
243
243
|
|
|
244
244
|
## Subscriptions
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
Signed HTTP webhooks. Subscriptions are polymorphic — pick one kind:
|
|
247
|
+
|
|
248
|
+
- **subgraph** — fires on rows written to a deployed subgraph table.
|
|
249
|
+
- **chain** — fires on raw chain events with no subgraph. Forward-looking: it
|
|
250
|
+
starts at the chain tip and never backfills. The turnkey "webhook on a
|
|
251
|
+
contract / event / function / trait".
|
|
247
252
|
|
|
248
253
|
```typescript
|
|
249
254
|
// List / get
|
|
250
255
|
const { data } = await sl.subscriptions.list();
|
|
251
256
|
const sub = await sl.subscriptions.get(id);
|
|
252
257
|
|
|
253
|
-
// Create — sink a subgraph table to a signed
|
|
258
|
+
// Create a SUBGRAPH subscription — sink a subgraph table to a signed endpoint.
|
|
254
259
|
// `signingSecret` is returned ONCE; store it in the receiver's env.
|
|
255
260
|
const { subscription, signingSecret } = await sl.subscriptions.create({
|
|
256
261
|
name: "whale-alerts",
|
|
@@ -259,8 +264,48 @@ const { subscription, signingSecret } = await sl.subscriptions.create({
|
|
|
259
264
|
url: "https://example.com/hooks/transfers",
|
|
260
265
|
format: "standard-webhooks", // or inngest | trigger | cloudflare | cloudevents | raw
|
|
261
266
|
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Chain subscriptions
|
|
270
|
+
|
|
271
|
+
Pass `triggers` instead of `subgraphName`/`tableName`. The `trigger.*` builders
|
|
272
|
+
are optional sugar — you can also pass raw objects (e.g.
|
|
273
|
+
`{ type: "contract_call", contractId: "SP....amm", functionName: "swap-*" }`).
|
|
274
|
+
All string fields accept `*` wildcards; `trait` scopes to contracts conforming
|
|
275
|
+
to a SIP/trait (e.g. `"sip-010"`); amounts are non-negative integer strings
|
|
276
|
+
(uint128-safe) or numbers.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { SecondLayer, trigger } from "@secondlayer/sdk";
|
|
280
|
+
|
|
281
|
+
const sl = new SecondLayer({ apiKey: "sk-sl_..." });
|
|
282
|
+
|
|
283
|
+
const { subscription, signingSecret } = await sl.subscriptions.create({
|
|
284
|
+
name: "amm-swaps",
|
|
285
|
+
url: "https://my-app.com/webhook",
|
|
286
|
+
triggers: [
|
|
287
|
+
trigger.contractCall({ contractId: "SP....amm", functionName: "swap-*" }),
|
|
288
|
+
trigger.ftTransfer({ trait: "sip-010", minAmount: "1000000" }),
|
|
289
|
+
],
|
|
290
|
+
});
|
|
291
|
+
```
|
|
262
292
|
|
|
263
|
-
|
|
293
|
+
One builder per event type:
|
|
294
|
+
`trigger.stxTransfer` / `stxMint` / `stxBurn` / `stxLock`,
|
|
295
|
+
`trigger.ftTransfer` / `ftMint` / `ftBurn`,
|
|
296
|
+
`trigger.nftTransfer` / `nftMint` / `nftBurn`,
|
|
297
|
+
`trigger.contractCall`, `trigger.contractDeploy`, `trigger.printEvent`.
|
|
298
|
+
|
|
299
|
+
Delivery envelope (chain subs only): each apply is `chain.{type}.apply` with
|
|
300
|
+
body `{ action: "apply", block_hash, block_height, tx_id, canonical, trigger,
|
|
301
|
+
event }`. On reorg you get `chain.reorg.rollback` with `{ action: "rollback",
|
|
302
|
+
fork_point_height, orphaned: [{ tx_id, event }] }`. Delivery is at-least-once: a
|
|
303
|
+
tx surviving a reorg re-delivers an apply under its new `block_hash`, so key
|
|
304
|
+
consumer state on `(tx_id, block_hash)`. Per-subscription HMAC signing (Standard
|
|
305
|
+
Webhooks) is unchanged for both kinds.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// Lifecycle (both kinds)
|
|
264
309
|
await sl.subscriptions.update(id, { filter: { amount: { gte: "1000000" } } });
|
|
265
310
|
await sl.subscriptions.pause(id);
|
|
266
311
|
await sl.subscriptions.resume(id);
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,23 @@ interface SubgraphSource {
|
|
|
31
31
|
reason?: string;
|
|
32
32
|
updatedAt: string;
|
|
33
33
|
}
|
|
34
|
+
/** Status of a tracked reindex/backfill operation (poll until terminal). */
|
|
35
|
+
interface SubgraphOperationStatus {
|
|
36
|
+
id: string;
|
|
37
|
+
subgraphName: string;
|
|
38
|
+
kind: "reindex" | "backfill";
|
|
39
|
+
status: "queued" | "running" | "completed" | "failed" | "cancelled";
|
|
40
|
+
fromBlock: number | null;
|
|
41
|
+
toBlock: number | null;
|
|
42
|
+
processedBlocks: number | null;
|
|
43
|
+
/** 0–1 fraction; null when no denominator is known yet. 1 when completed. */
|
|
44
|
+
progress: number | null;
|
|
45
|
+
error: string | null;
|
|
46
|
+
startedAt: string | null;
|
|
47
|
+
finishedAt: string | null;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
}
|
|
34
51
|
interface BundleSubgraphResponse {
|
|
35
52
|
ok: true;
|
|
36
53
|
name: string;
|
|
@@ -73,6 +90,13 @@ declare class Subgraphs extends BaseClient {
|
|
|
73
90
|
}): Promise<{
|
|
74
91
|
message: string
|
|
75
92
|
}>;
|
|
93
|
+
/** Recent reindex/backfill operations for a subgraph, newest first. */
|
|
94
|
+
operations(name: string): Promise<{
|
|
95
|
+
operations: SubgraphOperationStatus[]
|
|
96
|
+
}>;
|
|
97
|
+
/** Status of a single operation (poll the `operationId` returned by
|
|
98
|
+
* reindex/backfill/stop until `status` is terminal). */
|
|
99
|
+
getOperation(name: string, operationId: string): Promise<SubgraphOperationStatus>;
|
|
76
100
|
deploy(data: DeploySubgraphRequest): Promise<DeploySubgraphResponse>;
|
|
77
101
|
getSource(name: string): Promise<SubgraphSource>;
|
|
78
102
|
/**
|
|
@@ -105,6 +129,41 @@ declare class Subgraphs extends BaseClient {
|
|
|
105
129
|
private createTableClient;
|
|
106
130
|
}
|
|
107
131
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
132
|
+
import { SubgraphSummary as SubgraphSummary2 } from "@secondlayer/shared/schemas";
|
|
133
|
+
/**
|
|
134
|
+
* Typed client for the agent-reachable key mint (`POST /v1/api-keys`).
|
|
135
|
+
*
|
|
136
|
+
* Lets a headless agent self-provision a SCOPED `streams`/`index` read key
|
|
137
|
+
* without the dashboard. Requires an owner credential — an account-level API
|
|
138
|
+
* key (or a dashboard session). The minted key is always scoped (never an
|
|
139
|
+
* account/superkey) and inherits the account plan's tier.
|
|
140
|
+
*/
|
|
141
|
+
/** Scope of a minted read key. */
|
|
142
|
+
type ScopedKeyProduct = "streams" | "index";
|
|
143
|
+
interface CreateApiKeyParams {
|
|
144
|
+
/** Scope of the minted key. Defaults to "streams". */
|
|
145
|
+
product?: ScopedKeyProduct;
|
|
146
|
+
/** Optional human-readable label for the key. */
|
|
147
|
+
name?: string;
|
|
148
|
+
}
|
|
149
|
+
interface CreateApiKeyResponse {
|
|
150
|
+
/** Plaintext key — returned ONCE. Store it now; only its hash is persisted. */
|
|
151
|
+
key: string;
|
|
152
|
+
prefix: string;
|
|
153
|
+
id: string;
|
|
154
|
+
product: string;
|
|
155
|
+
tier: string | null;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
}
|
|
158
|
+
declare class ApiKeys extends BaseClient {
|
|
159
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
160
|
+
/**
|
|
161
|
+
* Mint a new scoped read key. The configured `apiKey` must be an
|
|
162
|
+
* account-level (owner) key; the plaintext `key` in the response is shown
|
|
163
|
+
* only once.
|
|
164
|
+
*/
|
|
165
|
+
create(params?: CreateApiKeyParams): Promise<CreateApiKeyResponse>;
|
|
166
|
+
}
|
|
108
167
|
/**
|
|
109
168
|
* Typed client for the contract-discovery API (`GET /v1/contracts`).
|
|
110
169
|
*
|
|
@@ -278,6 +337,17 @@ type IndexTip = {
|
|
|
278
337
|
block_height: number
|
|
279
338
|
lag_seconds: number
|
|
280
339
|
};
|
|
340
|
+
type IndexUsage = {
|
|
341
|
+
product: "index"
|
|
342
|
+
tier: string
|
|
343
|
+
limits: {
|
|
344
|
+
rate_limit_per_second: number | null
|
|
345
|
+
}
|
|
346
|
+
usage: {
|
|
347
|
+
decoded_events_today: number
|
|
348
|
+
decoded_events_this_month: number
|
|
349
|
+
}
|
|
350
|
+
};
|
|
281
351
|
type FtTransfer = {
|
|
282
352
|
cursor: string
|
|
283
353
|
block_height: number
|
|
@@ -737,6 +807,8 @@ type MempoolWalkParams = Omit<MempoolListParams, "limit"> & {
|
|
|
737
807
|
};
|
|
738
808
|
declare class Index extends BaseClient {
|
|
739
809
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
810
|
+
/** Your own Index consumption (decoded events today + this month) and tier limits. */
|
|
811
|
+
usage(): Promise<IndexUsage>;
|
|
740
812
|
readonly ftTransfers: {
|
|
741
813
|
list: (params?: FtTransfersListParams) => Promise<FtTransfersEnvelope>
|
|
742
814
|
walk: (params?: FtTransfersWalkParams) => AsyncIterable<FtTransfer>
|
|
@@ -808,8 +880,7 @@ declare class Index extends BaseClient {
|
|
|
808
880
|
private getMempoolTx;
|
|
809
881
|
private walkMempool;
|
|
810
882
|
}
|
|
811
|
-
|
|
812
|
-
type StreamsEventType = (typeof STREAMS_EVENT_TYPES)[number];
|
|
883
|
+
import { StreamsEventType } from "@secondlayer/shared";
|
|
813
884
|
/** A Clarity value as Streams serves it: the canonical hex string, a typed
|
|
814
885
|
* object carrying that hex (`{ hex }`), or a decoded Clarity-JSON object.
|
|
815
886
|
* Decode helpers (`decodeNftTransfer`, etc.) resolve it to a concrete value. */
|
|
@@ -1137,9 +1208,24 @@ type StreamsClient = {
|
|
|
1137
1208
|
dumps: StreamsDumps
|
|
1138
1209
|
canonical(height: number): Promise<StreamsCanonicalBlock>
|
|
1139
1210
|
tip(): Promise<StreamsTip>
|
|
1211
|
+
/** Your own Streams consumption (events today + this month) and tier limits. */
|
|
1212
|
+
usage(): Promise<StreamsUsage>
|
|
1213
|
+
};
|
|
1214
|
+
type StreamsUsage = {
|
|
1215
|
+
product: "streams"
|
|
1216
|
+
tier: string
|
|
1217
|
+
limits: {
|
|
1218
|
+
rate_limit_per_second: number | null
|
|
1219
|
+
retention_days: number | null
|
|
1220
|
+
}
|
|
1221
|
+
usage: {
|
|
1222
|
+
events_today: number
|
|
1223
|
+
events_this_month: number
|
|
1224
|
+
}
|
|
1140
1225
|
};
|
|
1141
1226
|
import { CreateSubscriptionRequest, CreateSubscriptionResponse, DeadRow, DeliveryRow, ReplayResult, RotateSecretResponse, SubscriptionDetail, SubscriptionSummary, UpdateSubscriptionRequest } from "@secondlayer/shared/schemas/subscriptions";
|
|
1142
|
-
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";
|
|
1227
|
+
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";
|
|
1228
|
+
import { trigger } from "@secondlayer/shared/schemas/subscriptions";
|
|
1143
1229
|
declare class Subscriptions extends BaseClient {
|
|
1144
1230
|
list(): Promise<{
|
|
1145
1231
|
data: SubscriptionSummary[]
|
|
@@ -1167,6 +1253,34 @@ declare class Subscriptions extends BaseClient {
|
|
|
1167
1253
|
ok: true
|
|
1168
1254
|
}>;
|
|
1169
1255
|
}
|
|
1256
|
+
interface ContextAccount {
|
|
1257
|
+
email: string;
|
|
1258
|
+
plan: string;
|
|
1259
|
+
}
|
|
1260
|
+
interface ActiveSubgraphOperation {
|
|
1261
|
+
subgraph: string;
|
|
1262
|
+
operationId: string;
|
|
1263
|
+
kind: SubgraphOperationStatus["kind"];
|
|
1264
|
+
status: SubgraphOperationStatus["status"];
|
|
1265
|
+
progress: number | null;
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* A point-in-time orientation snapshot for an agent: who you are, the live tips,
|
|
1269
|
+
* and what you own. Each field is `null` when it couldn't be read (e.g. no key,
|
|
1270
|
+
* or a free-tier key for a Build+ surface) so the snapshot never throws.
|
|
1271
|
+
*/
|
|
1272
|
+
interface ContextSnapshot {
|
|
1273
|
+
account: ContextAccount | null;
|
|
1274
|
+
streamsTip: StreamsTip | null;
|
|
1275
|
+
indexTip: IndexTip | null;
|
|
1276
|
+
subgraphs: SubgraphSummary2[] | null;
|
|
1277
|
+
subscriptions: {
|
|
1278
|
+
count: number
|
|
1279
|
+
byStatus: Record<string, number>
|
|
1280
|
+
} | null;
|
|
1281
|
+
/** In-flight reindex operations (bounded to subgraphs reporting `reindexing`). */
|
|
1282
|
+
activeOperations: ActiveSubgraphOperation[] | null;
|
|
1283
|
+
}
|
|
1170
1284
|
declare class SecondLayer extends BaseClient {
|
|
1171
1285
|
readonly streams: StreamsClient;
|
|
1172
1286
|
readonly index: Index;
|
|
@@ -1174,7 +1288,14 @@ declare class SecondLayer extends BaseClient {
|
|
|
1174
1288
|
readonly contracts: Contracts;
|
|
1175
1289
|
readonly subgraphs: Subgraphs;
|
|
1176
1290
|
readonly subscriptions: Subscriptions;
|
|
1291
|
+
readonly apiKeys: ApiKeys;
|
|
1177
1292
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
1293
|
+
/**
|
|
1294
|
+
* Assemble a {@link ContextSnapshot} — the same orientation an MCP agent reads
|
|
1295
|
+
* from `secondlayer://context`, but available to any SDK/CLI consumer. Reads
|
|
1296
|
+
* run concurrently and degrade to `null` per field on failure.
|
|
1297
|
+
*/
|
|
1298
|
+
context(): Promise<ContextSnapshot>;
|
|
1178
1299
|
}
|
|
1179
1300
|
/**
|
|
1180
1301
|
* Returns a typed client for a subgraph defined with `defineSubgraph()`.
|
|
@@ -1624,4 +1745,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
1624
1745
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
1625
1746
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
1626
1747
|
declare function decodeClarityValue(hex: string): unknown;
|
|
1627
|
-
export { verifyWebhookSignature, toJsonSafe, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StackingWalkParams, StackingListParams, StackingEnvelope, SecondLayerOptions, SecondLayer, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexTransaction, IndexTip, IndexStackingAction, IndexPostCondition, IndexMempoolTransaction, IndexEventType, IndexEvent, IndexContractCall, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, 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, Datasets, DatasetRow, CursorListParams, CursorEnvelope, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, CURSOR_SLUGS, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiError };
|
|
1748
|
+
export { verifyWebhookSignature, trigger, toJsonSafe, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, createStreamsClient, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, 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, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StackingWalkParams, StackingListParams, StackingEnvelope, SecondLayerOptions, SecondLayer, ScopedKeyProduct, RotateSecretResponse2 as RotateSecretResponse, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStackingAction, IndexPostCondition, IndexMempoolTransaction, IndexEventType, IndexEvent, IndexContractCall, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, 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, Datasets, DatasetRow, CursorListParams, CursorEnvelope, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContextSnapshot, ContextAccount, ChainTriggerType, ChainTrigger, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, CURSOR_SLUGS, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiError, ActiveSubgraphOperation };
|
package/dist/index.js
CHANGED
|
@@ -242,6 +242,12 @@ class Subgraphs extends BaseClient {
|
|
|
242
242
|
const qs = options?.force ? "?force=true" : "";
|
|
243
243
|
return this.request("DELETE", `/api/subgraphs/${name}${qs}`);
|
|
244
244
|
}
|
|
245
|
+
async operations(name) {
|
|
246
|
+
return this.request("GET", `/api/subgraphs/${name}/operations`);
|
|
247
|
+
}
|
|
248
|
+
async getOperation(name, operationId) {
|
|
249
|
+
return this.request("GET", `/api/subgraphs/${name}/operations/${operationId}`);
|
|
250
|
+
}
|
|
245
251
|
async deploy(data) {
|
|
246
252
|
return this.request("POST", "/api/subgraphs", data);
|
|
247
253
|
}
|
|
@@ -324,6 +330,19 @@ class Subgraphs extends BaseClient {
|
|
|
324
330
|
};
|
|
325
331
|
}
|
|
326
332
|
}
|
|
333
|
+
// src/api-keys/client.ts
|
|
334
|
+
class ApiKeys extends BaseClient {
|
|
335
|
+
constructor(options = {}) {
|
|
336
|
+
super(options);
|
|
337
|
+
}
|
|
338
|
+
create(params = {}) {
|
|
339
|
+
return this.request("POST", "/v1/api-keys", {
|
|
340
|
+
product: params.product,
|
|
341
|
+
name: params.name
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
327
346
|
// src/contracts/client.ts
|
|
328
347
|
class Contracts extends BaseClient {
|
|
329
348
|
constructor(options = {}) {
|
|
@@ -473,6 +492,9 @@ class Index extends BaseClient {
|
|
|
473
492
|
constructor(options = {}) {
|
|
474
493
|
super(options);
|
|
475
494
|
}
|
|
495
|
+
usage() {
|
|
496
|
+
return this.request("GET", "/v1/index/usage");
|
|
497
|
+
}
|
|
476
498
|
ftTransfers = {
|
|
477
499
|
list: (params = {}) => this.listFtTransfers(params),
|
|
478
500
|
walk: (params = {}) => this.walkFtTransfers(params)
|
|
@@ -1331,12 +1353,15 @@ function createStreamsClient(options) {
|
|
|
1331
1353
|
},
|
|
1332
1354
|
tip() {
|
|
1333
1355
|
return request("/v1/streams/tip");
|
|
1356
|
+
},
|
|
1357
|
+
usage() {
|
|
1358
|
+
return request("/v1/streams/usage");
|
|
1334
1359
|
}
|
|
1335
1360
|
};
|
|
1336
1361
|
}
|
|
1337
1362
|
|
|
1338
1363
|
// src/subscriptions/client.ts
|
|
1339
|
-
import {
|
|
1364
|
+
import { trigger } from "@secondlayer/shared/schemas/subscriptions";
|
|
1340
1365
|
|
|
1341
1366
|
class Subscriptions extends BaseClient {
|
|
1342
1367
|
async list() {
|
|
@@ -1385,6 +1410,7 @@ class SecondLayer extends BaseClient {
|
|
|
1385
1410
|
contracts;
|
|
1386
1411
|
subgraphs;
|
|
1387
1412
|
subscriptions;
|
|
1413
|
+
apiKeys;
|
|
1388
1414
|
constructor(options = {}) {
|
|
1389
1415
|
super(options);
|
|
1390
1416
|
this.streams = createStreamsClient({
|
|
@@ -1397,6 +1423,49 @@ class SecondLayer extends BaseClient {
|
|
|
1397
1423
|
this.contracts = new Contracts(options);
|
|
1398
1424
|
this.subgraphs = new Subgraphs(options);
|
|
1399
1425
|
this.subscriptions = new Subscriptions(options);
|
|
1426
|
+
this.apiKeys = new ApiKeys(options);
|
|
1427
|
+
}
|
|
1428
|
+
async context() {
|
|
1429
|
+
const safe = (p) => p.then((v) => v).catch(() => null);
|
|
1430
|
+
const [account, streamsTip, indexEnv, subgraphsRes, subscriptionsRes] = await Promise.all([
|
|
1431
|
+
safe(this.request("GET", "/api/accounts/me")),
|
|
1432
|
+
safe(this.streams.tip()),
|
|
1433
|
+
safe(this.index.canonical.list({ limit: 1 })),
|
|
1434
|
+
safe(this.subgraphs.list()),
|
|
1435
|
+
safe(this.subscriptions.list())
|
|
1436
|
+
]);
|
|
1437
|
+
const subgraphs = subgraphsRes?.data ?? null;
|
|
1438
|
+
let subscriptions = null;
|
|
1439
|
+
if (subscriptionsRes) {
|
|
1440
|
+
const byStatus = {};
|
|
1441
|
+
for (const s of subscriptionsRes.data) {
|
|
1442
|
+
byStatus[s.status] = (byStatus[s.status] ?? 0) + 1;
|
|
1443
|
+
}
|
|
1444
|
+
subscriptions = { count: subscriptionsRes.data.length, byStatus };
|
|
1445
|
+
}
|
|
1446
|
+
let activeOperations = null;
|
|
1447
|
+
if (subgraphs) {
|
|
1448
|
+
const probed = await Promise.all(subgraphs.filter((s) => s.status === "reindexing").map(async (s) => {
|
|
1449
|
+
const res = await safe(this.subgraphs.operations(s.name));
|
|
1450
|
+
const op = res?.operations.find((o) => o.status === "queued" || o.status === "running");
|
|
1451
|
+
return op ? {
|
|
1452
|
+
subgraph: s.name,
|
|
1453
|
+
operationId: op.id,
|
|
1454
|
+
kind: op.kind,
|
|
1455
|
+
status: op.status,
|
|
1456
|
+
progress: op.progress
|
|
1457
|
+
} : null;
|
|
1458
|
+
}));
|
|
1459
|
+
activeOperations = probed.filter((o) => o !== null);
|
|
1460
|
+
}
|
|
1461
|
+
return {
|
|
1462
|
+
account,
|
|
1463
|
+
streamsTip,
|
|
1464
|
+
indexTip: indexEnv?.tip ?? null,
|
|
1465
|
+
subgraphs,
|
|
1466
|
+
subscriptions,
|
|
1467
|
+
activeOperations
|
|
1468
|
+
};
|
|
1400
1469
|
}
|
|
1401
1470
|
}
|
|
1402
1471
|
|
|
@@ -1690,19 +1759,9 @@ function decodePrint(event) {
|
|
|
1690
1759
|
});
|
|
1691
1760
|
}
|
|
1692
1761
|
// src/streams/types.ts
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
"stx_burn",
|
|
1697
|
-
"stx_lock",
|
|
1698
|
-
"ft_transfer",
|
|
1699
|
-
"ft_mint",
|
|
1700
|
-
"ft_burn",
|
|
1701
|
-
"nft_transfer",
|
|
1702
|
-
"nft_mint",
|
|
1703
|
-
"nft_burn",
|
|
1704
|
-
"print"
|
|
1705
|
-
];
|
|
1762
|
+
import {
|
|
1763
|
+
STREAMS_EVENT_TYPES
|
|
1764
|
+
} from "@secondlayer/shared";
|
|
1706
1765
|
// src/webhooks.ts
|
|
1707
1766
|
import {
|
|
1708
1767
|
verify
|
|
@@ -1748,6 +1807,7 @@ function verifyWebhookSignature(rawBody, headers, secret, toleranceSeconds = 300
|
|
|
1748
1807
|
}
|
|
1749
1808
|
export {
|
|
1750
1809
|
verifyWebhookSignature,
|
|
1810
|
+
trigger,
|
|
1751
1811
|
toJsonSafe,
|
|
1752
1812
|
isStxTransfer,
|
|
1753
1813
|
isStxMint,
|
|
@@ -1788,8 +1848,9 @@ export {
|
|
|
1788
1848
|
Contracts,
|
|
1789
1849
|
CURSOR_SLUGS,
|
|
1790
1850
|
AuthError,
|
|
1851
|
+
ApiKeys,
|
|
1791
1852
|
ApiError
|
|
1792
1853
|
};
|
|
1793
1854
|
|
|
1794
|
-
//# debugId=
|
|
1855
|
+
//# debugId=209F8CDE1560C10F64756E2164756E21
|
|
1795
1856
|
//# sourceMappingURL=index.js.map
|