@secondlayer/sdk 6.15.0 → 6.17.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/dist/index.d.ts +158 -3
- package/dist/index.js +125 -10
- package/dist/index.js.map +9 -8
- package/dist/streams/index.js +20 -1
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +134 -2
- package/dist/subgraphs/index.js +123 -10
- package/dist/subgraphs/index.js.map +9 -8
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -156,6 +156,17 @@ interface CreateApiKeyResponse {
|
|
|
156
156
|
tier: string | null;
|
|
157
157
|
createdAt: string;
|
|
158
158
|
}
|
|
159
|
+
/** A key as seen by {@link ApiKeys.list} — metadata only, never the plaintext. */
|
|
160
|
+
interface ApiKeySummary {
|
|
161
|
+
id: string;
|
|
162
|
+
prefix: string;
|
|
163
|
+
name: string | null;
|
|
164
|
+
status: "active" | "revoked";
|
|
165
|
+
product: string;
|
|
166
|
+
tier: string | null;
|
|
167
|
+
createdAt: string;
|
|
168
|
+
lastUsedAt: string | null;
|
|
169
|
+
}
|
|
159
170
|
declare class ApiKeys extends BaseClient {
|
|
160
171
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
161
172
|
/**
|
|
@@ -164,6 +175,18 @@ declare class ApiKeys extends BaseClient {
|
|
|
164
175
|
* only once.
|
|
165
176
|
*/
|
|
166
177
|
create(params?: CreateApiKeyParams): Promise<CreateApiKeyResponse>;
|
|
178
|
+
/**
|
|
179
|
+
* List the account's keys (metadata only — no plaintext). Requires an
|
|
180
|
+
* account-level (owner) key or a dashboard session.
|
|
181
|
+
*/
|
|
182
|
+
list(): Promise<{
|
|
183
|
+
keys: ApiKeySummary[]
|
|
184
|
+
}>;
|
|
185
|
+
/** Revoke a key by id. Existing requests with that key stop working. */
|
|
186
|
+
revoke(id: string): Promise<{
|
|
187
|
+
revoked: true
|
|
188
|
+
id: string
|
|
189
|
+
}>;
|
|
167
190
|
}
|
|
168
191
|
/**
|
|
169
192
|
* Typed client for the contract-discovery API (`GET /v1/contracts`).
|
|
@@ -289,13 +312,26 @@ declare const CURSOR_SLUGS: Record<string, {
|
|
|
289
312
|
rowKey: string
|
|
290
313
|
}>;
|
|
291
314
|
declare class Datasets extends BaseClient {
|
|
315
|
+
private catalogPromise?;
|
|
292
316
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
293
317
|
/** Dataset catalog + freshness (the discovery endpoint). */
|
|
294
318
|
listDatasets(): Promise<unknown>;
|
|
295
319
|
/**
|
|
320
|
+
* Generic read by slug for ANY catalog dataset — cursor or bespoke. Resolves
|
|
321
|
+
* the slug against the live `/v1/datasets` catalog (so datasets added
|
|
322
|
+
* server-side work with no SDK change), issues the GET, and normalizes the
|
|
323
|
+
* response into a uniform `{ rows, next_cursor, tip }` envelope. Single-object
|
|
324
|
+
* datasets (bns/resolve, network-health/summary) come back as 0-or-1 rows.
|
|
325
|
+
* Accepts both family (`sbtc-events`) and path (`sbtc/events`) slug forms.
|
|
326
|
+
* Prefer this over {@link query} unless you specifically need cursor-only
|
|
327
|
+
* semantics.
|
|
328
|
+
*/
|
|
329
|
+
get(slug: string, params?: Record<string, unknown>): Promise<CursorEnvelope>;
|
|
330
|
+
/**
|
|
296
331
|
* Generic cursor query by slug — used by the CLI. Params are passed through as
|
|
297
332
|
* REST query keys (snake_case), so callers can use the documented filter names
|
|
298
|
-
* directly. Throws for non-cursor (bespoke) datasets
|
|
333
|
+
* directly. Throws for non-cursor (bespoke) datasets — use {@link get} for
|
|
334
|
+
* those (and for slugs added to the catalog after this SDK was built).
|
|
299
335
|
*/
|
|
300
336
|
query(slug: string, params?: Record<string, unknown>): Promise<CursorEnvelope>;
|
|
301
337
|
readonly stxTransfers: CursorDataset<StxTransfersParams>;
|
|
@@ -328,7 +364,15 @@ declare class Datasets extends BaseClient {
|
|
|
328
364
|
networkHealth(): Promise<{
|
|
329
365
|
summary: DatasetRow
|
|
330
366
|
}>;
|
|
331
|
-
private
|
|
367
|
+
private requestPath;
|
|
368
|
+
/** Resolve a slug → relative path + row key. Known cursor slugs take a
|
|
369
|
+
* network-free fast path; anything else is matched against the live catalog
|
|
370
|
+
* by family name or path tail. */
|
|
371
|
+
private resolveDataset;
|
|
372
|
+
/** Fetch + cache the catalog families. Caches the in-flight promise so
|
|
373
|
+
* concurrent first-calls share one request; no TTL — agent sessions are
|
|
374
|
+
* short-lived, and a new client picks up newly added datasets. */
|
|
375
|
+
private loadCatalog;
|
|
332
376
|
/** Map camelCase filter fields to snake_case query keys (dropping pagination
|
|
333
377
|
* controls) and build the canonical query suffix. */
|
|
334
378
|
private paramsToQuery;
|
|
@@ -903,6 +947,76 @@ declare class Index extends BaseClient {
|
|
|
903
947
|
private getMempoolTx;
|
|
904
948
|
private walkMempool;
|
|
905
949
|
}
|
|
950
|
+
/**
|
|
951
|
+
* Typed client for project management (`/api/projects/*`).
|
|
952
|
+
*
|
|
953
|
+
* Projects are the account-scoped containers for work. Every method requires an
|
|
954
|
+
* account-level (owner) API key or a dashboard session — scoped read keys are
|
|
955
|
+
* rejected. Team mutations (invite/remove/role) are intentionally not exposed
|
|
956
|
+
* here; only the read view ({@link Projects.team}) is.
|
|
957
|
+
*/
|
|
958
|
+
interface Project {
|
|
959
|
+
id: string;
|
|
960
|
+
name: string;
|
|
961
|
+
slug: string;
|
|
962
|
+
network: string;
|
|
963
|
+
nodeRpc: string | null;
|
|
964
|
+
settings: Record<string, unknown> | null;
|
|
965
|
+
createdAt: string;
|
|
966
|
+
updatedAt: string;
|
|
967
|
+
}
|
|
968
|
+
interface ProjectTeamMember {
|
|
969
|
+
id: string;
|
|
970
|
+
role: string;
|
|
971
|
+
email: string;
|
|
972
|
+
displayName: string | null;
|
|
973
|
+
avatarUrl: string | null;
|
|
974
|
+
createdAt: string;
|
|
975
|
+
}
|
|
976
|
+
interface ProjectInvitation {
|
|
977
|
+
id: string;
|
|
978
|
+
email: string;
|
|
979
|
+
role: string;
|
|
980
|
+
expiresAt: string;
|
|
981
|
+
createdAt: string;
|
|
982
|
+
}
|
|
983
|
+
interface ProjectTeam {
|
|
984
|
+
members: ProjectTeamMember[];
|
|
985
|
+
invitations: ProjectInvitation[];
|
|
986
|
+
}
|
|
987
|
+
interface CreateProjectParams {
|
|
988
|
+
name: string;
|
|
989
|
+
slug?: string;
|
|
990
|
+
network?: string;
|
|
991
|
+
nodeRpc?: string;
|
|
992
|
+
}
|
|
993
|
+
interface UpdateProjectParams {
|
|
994
|
+
name?: string;
|
|
995
|
+
/** Rename the project's URL slug. */
|
|
996
|
+
slug?: string;
|
|
997
|
+
network?: string;
|
|
998
|
+
nodeRpc?: string;
|
|
999
|
+
settings?: Record<string, unknown>;
|
|
1000
|
+
}
|
|
1001
|
+
declare class Projects extends BaseClient {
|
|
1002
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
1003
|
+
/** All projects owned by the account, newest-relevant first. */
|
|
1004
|
+
list(): Promise<{
|
|
1005
|
+
projects: Project[]
|
|
1006
|
+
}>;
|
|
1007
|
+
/** A single project by slug. */
|
|
1008
|
+
get(slug: string): Promise<Project>;
|
|
1009
|
+
/** Create a project. The creator is added as the project owner. */
|
|
1010
|
+
create(params: CreateProjectParams): Promise<Project>;
|
|
1011
|
+
/** Update a project's name, slug (rename), network, RPC, or settings. */
|
|
1012
|
+
update(slug: string, patch: UpdateProjectParams): Promise<Project>;
|
|
1013
|
+
/** Delete a project. The account's last remaining project cannot be deleted. */
|
|
1014
|
+
delete(slug: string): Promise<{
|
|
1015
|
+
ok: true
|
|
1016
|
+
}>;
|
|
1017
|
+
/** Team members and pending invitations for a project. */
|
|
1018
|
+
team(slug: string): Promise<ProjectTeam>;
|
|
1019
|
+
}
|
|
906
1020
|
import { StreamsEventType } from "@secondlayer/shared";
|
|
907
1021
|
/** A Clarity value as Streams serves it: the canonical hex string, a typed
|
|
908
1022
|
* object carrying that hex (`{ hex }`), or a decoded Clarity-JSON object.
|
|
@@ -1320,6 +1434,19 @@ interface ContextAccount {
|
|
|
1320
1434
|
email: string;
|
|
1321
1435
|
plan: string;
|
|
1322
1436
|
}
|
|
1437
|
+
/** Compact project view for {@link ContextSnapshot}. */
|
|
1438
|
+
interface ContextProject {
|
|
1439
|
+
name: string;
|
|
1440
|
+
slug: string;
|
|
1441
|
+
network: string;
|
|
1442
|
+
}
|
|
1443
|
+
/** Compact API-key view for {@link ContextSnapshot} — never the plaintext. */
|
|
1444
|
+
interface ContextApiKey {
|
|
1445
|
+
prefix: string;
|
|
1446
|
+
name: string | null;
|
|
1447
|
+
status: string;
|
|
1448
|
+
product: string;
|
|
1449
|
+
}
|
|
1323
1450
|
interface ActiveSubgraphOperation {
|
|
1324
1451
|
subgraph: string;
|
|
1325
1452
|
operationId: string;
|
|
@@ -1341,6 +1468,10 @@ interface ContextSnapshot {
|
|
|
1341
1468
|
count: number
|
|
1342
1469
|
byStatus: Record<string, number>
|
|
1343
1470
|
} | null;
|
|
1471
|
+
/** The account's projects (null when unreadable — e.g. a scoped key). */
|
|
1472
|
+
projects: ContextProject[] | null;
|
|
1473
|
+
/** The account's API keys, metadata only (null when unreadable). */
|
|
1474
|
+
apiKeys: ContextApiKey[] | null;
|
|
1344
1475
|
/** In-flight reindex operations (bounded to subgraphs reporting `reindexing`). */
|
|
1345
1476
|
activeOperations: ActiveSubgraphOperation[] | null;
|
|
1346
1477
|
}
|
|
@@ -1352,6 +1483,7 @@ declare class SecondLayer extends BaseClient {
|
|
|
1352
1483
|
readonly subgraphs: Subgraphs;
|
|
1353
1484
|
readonly subscriptions: Subscriptions;
|
|
1354
1485
|
readonly apiKeys: ApiKeys;
|
|
1486
|
+
readonly projects: Projects;
|
|
1355
1487
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
1356
1488
|
/**
|
|
1357
1489
|
* Assemble a {@link ContextSnapshot} — the same orientation an MCP agent reads
|
|
@@ -1699,6 +1831,7 @@ declare const Cursor: {
|
|
|
1699
1831
|
};
|
|
1700
1832
|
type DecodedEventRow = DecodedFtTransfer | DecodedNftTransfer | DecodedStxTransfer | DecodedStxMint | DecodedStxBurn | DecodedStxLock | DecodedFtMint | DecodedFtBurn | DecodedNftMint | DecodedNftBurn | DecodedPrint;
|
|
1701
1833
|
import { SubgraphAgentSchema as SubgraphAgentSchema3, SubgraphSpecFormat as SubgraphSpecFormat2, SubgraphSpecOptions as SubgraphSpecOptions3 } from "@secondlayer/shared/subgraphs/spec";
|
|
1834
|
+
import { ByoBreakingChangeDetails } from "@secondlayer/shared/errors";
|
|
1702
1835
|
/**
|
|
1703
1836
|
* Error thrown by {@link SecondLayer} when an API request fails.
|
|
1704
1837
|
* Includes the HTTP status code for programmatic error handling.
|
|
@@ -1732,6 +1865,28 @@ declare class VersionConflictError extends ApiError {
|
|
|
1732
1865
|
expectedVersion: string;
|
|
1733
1866
|
constructor(currentVersion: string, expectedVersion: string, message?: string);
|
|
1734
1867
|
}
|
|
1868
|
+
/**
|
|
1869
|
+
* Thrown when a BYO subgraph deploy is refused for a breaking schema change.
|
|
1870
|
+
* The deploy did NOT run — `details.plan` carries the DROP + rebuild DDL to run
|
|
1871
|
+
* manually on your own database, plus the breaking `reasons` and the `diff`.
|
|
1872
|
+
*
|
|
1873
|
+
* @example
|
|
1874
|
+
* ```ts
|
|
1875
|
+
* try {
|
|
1876
|
+
* await client.subgraphs.deploy(bundle);
|
|
1877
|
+
* } catch (err) {
|
|
1878
|
+
* if (err instanceof ByoBreakingChangeError) {
|
|
1879
|
+
* console.log(err.details.plan.dropStatement);
|
|
1880
|
+
* console.log(err.details.plan.statements.join(";
|
|
1881
|
+
"));
|
|
1882
|
+
* }
|
|
1883
|
+
* }
|
|
1884
|
+
* ```
|
|
1885
|
+
*/
|
|
1886
|
+
declare class ByoBreakingChangeError extends ApiError {
|
|
1887
|
+
readonly details: ByoBreakingChangeDetails;
|
|
1888
|
+
constructor(message: string, details: ByoBreakingChangeDetails);
|
|
1889
|
+
}
|
|
1735
1890
|
import { StandardWebhooksHeaders } from "@secondlayer/shared/crypto/standard-webhooks";
|
|
1736
1891
|
type HeaderLookup = (name: string) => string | null | undefined;
|
|
1737
1892
|
type WebhookHeaderInput = HeaderLookup | StandardWebhooksHeaders | Record<string, string | string[] | undefined> | {
|
|
@@ -1926,4 +2081,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
1926
2081
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
1927
2082
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
1928
2083
|
declare function decodeClarityValue(hex: string): unknown;
|
|
1929
|
-
export { verifyWebhookSignature, verifyTransactionProof, verifySecondlayerSignature, trigger, toJsonSafe, 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, createStreamsClient, 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, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StackingWalkParams, StackingListParams, StackingEnvelope, SecondLayerOptions, SecondLayer, ScopedKeyProduct, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStackingAction, IndexReorg, 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 };
|
|
2084
|
+
export { verifyWebhookSignature, verifyTransactionProof, verifySecondlayerSignature, trigger, toJsonSafe, 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, createStreamsClient, 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, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StackingWalkParams, StackingListParams, StackingEnvelope, SecondLayerOptions, SecondLayer, ScopedKeyProduct, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, Pox4CallsParams, NftTransfersWalkParams, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStackingAction, IndexReorg, 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, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ChainTriggerType, ChainTrigger, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, CURSOR_SLUGS, ByoBreakingChangeError, ByoBreakingChangeDetails, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,22 @@ class VersionConflictError extends ApiError {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
class ByoBreakingChangeError extends ApiError {
|
|
27
|
+
details;
|
|
28
|
+
constructor(message, details) {
|
|
29
|
+
super(422, message, details, "BYO_BREAKING_CHANGE");
|
|
30
|
+
this.name = "ByoBreakingChangeError";
|
|
31
|
+
this.details = details;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function isByoBreakingDetails(x) {
|
|
35
|
+
if (!x || typeof x !== "object")
|
|
36
|
+
return false;
|
|
37
|
+
const d = x;
|
|
38
|
+
const plan = d.plan;
|
|
39
|
+
return Array.isArray(d.reasons) && !!plan && typeof plan === "object" && typeof plan.dropStatement === "string";
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
// src/base.ts
|
|
27
43
|
var DEFAULT_BASE_URL = "https://api.secondlayer.tools";
|
|
28
44
|
function buildQuery(params) {
|
|
@@ -123,6 +139,9 @@ class BaseClient {
|
|
|
123
139
|
if (errorBody)
|
|
124
140
|
message = errorBody;
|
|
125
141
|
}
|
|
142
|
+
if (response.status === 422 && code === "BYO_BREAKING_CHANGE" && parsedBody && typeof parsedBody === "object" && isByoBreakingDetails(parsedBody.details)) {
|
|
143
|
+
throw new ByoBreakingChangeError(message, parsedBody.details);
|
|
144
|
+
}
|
|
126
145
|
throw new ApiError(response.status, message, parsedBody, code);
|
|
127
146
|
}
|
|
128
147
|
return response;
|
|
@@ -376,6 +395,12 @@ class ApiKeys extends BaseClient {
|
|
|
376
395
|
name: params.name
|
|
377
396
|
});
|
|
378
397
|
}
|
|
398
|
+
list() {
|
|
399
|
+
return this.request("GET", "/api/keys");
|
|
400
|
+
}
|
|
401
|
+
revoke(id) {
|
|
402
|
+
return this.request("DELETE", `/api/keys/${id}`);
|
|
403
|
+
}
|
|
379
404
|
}
|
|
380
405
|
|
|
381
406
|
// src/contracts/client.ts
|
|
@@ -422,20 +447,35 @@ var CURSOR_SLUGS = {
|
|
|
422
447
|
rowKey: "events"
|
|
423
448
|
}
|
|
424
449
|
};
|
|
450
|
+
function catalogPathTail(path) {
|
|
451
|
+
return path.replace(/^\/?v1\/datasets\//, "").replace(/^\/+/, "");
|
|
452
|
+
}
|
|
425
453
|
|
|
426
454
|
class Datasets extends BaseClient {
|
|
455
|
+
catalogPromise;
|
|
427
456
|
constructor(options = {}) {
|
|
428
457
|
super(options);
|
|
429
458
|
}
|
|
430
459
|
listDatasets() {
|
|
431
460
|
return this.request("GET", "/v1/datasets");
|
|
432
461
|
}
|
|
462
|
+
async get(slug, params = {}) {
|
|
463
|
+
const { path, rowKey } = await this.resolveDataset(slug);
|
|
464
|
+
const env = await this.requestPath(path, this.paramsToQuery(params));
|
|
465
|
+
const value = env[rowKey];
|
|
466
|
+
const rows = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
467
|
+
return {
|
|
468
|
+
rows,
|
|
469
|
+
next_cursor: env.next_cursor ?? null,
|
|
470
|
+
tip: env.tip
|
|
471
|
+
};
|
|
472
|
+
}
|
|
433
473
|
async query(slug, params = {}) {
|
|
434
474
|
const d = CURSOR_SLUGS[slug];
|
|
435
475
|
if (!d) {
|
|
436
476
|
throw new Error(`unknown cursor dataset "${slug}" (use one of: ${Object.keys(CURSOR_SLUGS).join(", ")})`);
|
|
437
477
|
}
|
|
438
|
-
const env = await this.
|
|
478
|
+
const env = await this.requestPath(d.path, this.paramsToQuery(params));
|
|
439
479
|
return {
|
|
440
480
|
rows: env[d.rowKey] ?? [],
|
|
441
481
|
next_cursor: env.next_cursor ?? null,
|
|
@@ -452,7 +492,7 @@ class Datasets extends BaseClient {
|
|
|
452
492
|
bnsNamespaceEvents = this.cursorDataset("bns/namespace-events", "events");
|
|
453
493
|
bnsMarketplaceEvents = this.cursorDataset("bns/marketplace-events", "events");
|
|
454
494
|
bnsNames(params = {}) {
|
|
455
|
-
return this.
|
|
495
|
+
return this.requestPath("bns/names", buildQuery({
|
|
456
496
|
namespace: params.namespace,
|
|
457
497
|
owner: params.owner,
|
|
458
498
|
limit: params.limit,
|
|
@@ -460,17 +500,40 @@ class Datasets extends BaseClient {
|
|
|
460
500
|
}));
|
|
461
501
|
}
|
|
462
502
|
bnsNamespaces() {
|
|
463
|
-
return this.
|
|
503
|
+
return this.requestPath("bns/namespaces", "");
|
|
464
504
|
}
|
|
465
505
|
bnsResolve(fqn) {
|
|
466
|
-
return this.
|
|
506
|
+
return this.requestPath("bns/resolve", buildQuery({ fqn }));
|
|
467
507
|
}
|
|
468
508
|
networkHealth() {
|
|
469
|
-
return this.
|
|
509
|
+
return this.requestPath("network-health/summary", "");
|
|
470
510
|
}
|
|
471
|
-
|
|
511
|
+
requestPath(path, query) {
|
|
472
512
|
return this.request("GET", `/v1/datasets/${path}${query}`);
|
|
473
513
|
}
|
|
514
|
+
async resolveDataset(slug) {
|
|
515
|
+
const cursor = CURSOR_SLUGS[slug];
|
|
516
|
+
if (cursor)
|
|
517
|
+
return { path: cursor.path, rowKey: cursor.rowKey };
|
|
518
|
+
const families = await this.loadCatalog();
|
|
519
|
+
const tail = catalogPathTail(slug);
|
|
520
|
+
const match = families.find((f) => f.family === slug || catalogPathTail(f.path) === tail);
|
|
521
|
+
if (!match) {
|
|
522
|
+
throw new Error(`unknown dataset "${slug}" (available: ${families.map((f) => f.family).join(", ")})`);
|
|
523
|
+
}
|
|
524
|
+
return { path: catalogPathTail(match.path), rowKey: match.row_key };
|
|
525
|
+
}
|
|
526
|
+
loadCatalog() {
|
|
527
|
+
this.catalogPromise ??= (async () => {
|
|
528
|
+
const raw = await this.listDatasets();
|
|
529
|
+
const families = raw.families;
|
|
530
|
+
if (!Array.isArray(families)) {
|
|
531
|
+
throw new Error("dataset catalog response missing families[]");
|
|
532
|
+
}
|
|
533
|
+
return families;
|
|
534
|
+
})();
|
|
535
|
+
return this.catalogPromise;
|
|
536
|
+
}
|
|
474
537
|
paramsToQuery(params) {
|
|
475
538
|
const mapped = {};
|
|
476
539
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -482,7 +545,7 @@ class Datasets extends BaseClient {
|
|
|
482
545
|
}
|
|
483
546
|
cursorDataset(path, rowKey) {
|
|
484
547
|
const list = async (params = {}) => {
|
|
485
|
-
const envelope = await this.
|
|
548
|
+
const envelope = await this.requestPath(path, this.paramsToQuery(params));
|
|
486
549
|
return {
|
|
487
550
|
rows: envelope[rowKey] ?? [],
|
|
488
551
|
next_cursor: envelope.next_cursor ?? null,
|
|
@@ -925,6 +988,31 @@ class Index extends BaseClient {
|
|
|
925
988
|
}
|
|
926
989
|
}
|
|
927
990
|
|
|
991
|
+
// src/projects/client.ts
|
|
992
|
+
class Projects extends BaseClient {
|
|
993
|
+
constructor(options = {}) {
|
|
994
|
+
super(options);
|
|
995
|
+
}
|
|
996
|
+
list() {
|
|
997
|
+
return this.request("GET", "/api/projects");
|
|
998
|
+
}
|
|
999
|
+
get(slug) {
|
|
1000
|
+
return this.request("GET", `/api/projects/${slug}`);
|
|
1001
|
+
}
|
|
1002
|
+
create(params) {
|
|
1003
|
+
return this.request("POST", "/api/projects", params);
|
|
1004
|
+
}
|
|
1005
|
+
update(slug, patch) {
|
|
1006
|
+
return this.request("PATCH", `/api/projects/${slug}`, patch);
|
|
1007
|
+
}
|
|
1008
|
+
delete(slug) {
|
|
1009
|
+
return this.request("DELETE", `/api/projects/${slug}`);
|
|
1010
|
+
}
|
|
1011
|
+
team(slug) {
|
|
1012
|
+
return this.request("GET", `/api/projects/${slug}/team`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
928
1016
|
// src/streams/client.ts
|
|
929
1017
|
import { ed25519 as ed255192 } from "@secondlayer/shared";
|
|
930
1018
|
|
|
@@ -1603,6 +1691,7 @@ class SecondLayer extends BaseClient {
|
|
|
1603
1691
|
subgraphs;
|
|
1604
1692
|
subscriptions;
|
|
1605
1693
|
apiKeys;
|
|
1694
|
+
projects;
|
|
1606
1695
|
constructor(options = {}) {
|
|
1607
1696
|
super(options);
|
|
1608
1697
|
this.streams = createStreamsClient({
|
|
@@ -1616,15 +1705,26 @@ class SecondLayer extends BaseClient {
|
|
|
1616
1705
|
this.subgraphs = new Subgraphs(options);
|
|
1617
1706
|
this.subscriptions = new Subscriptions(options);
|
|
1618
1707
|
this.apiKeys = new ApiKeys(options);
|
|
1708
|
+
this.projects = new Projects(options);
|
|
1619
1709
|
}
|
|
1620
1710
|
async context() {
|
|
1621
1711
|
const safe = (p) => p.then((v) => v).catch(() => null);
|
|
1622
|
-
const [
|
|
1712
|
+
const [
|
|
1713
|
+
account,
|
|
1714
|
+
streamsTip,
|
|
1715
|
+
indexEnv,
|
|
1716
|
+
subgraphsRes,
|
|
1717
|
+
subscriptionsRes,
|
|
1718
|
+
projectsRes,
|
|
1719
|
+
apiKeysRes
|
|
1720
|
+
] = await Promise.all([
|
|
1623
1721
|
safe(this.request("GET", "/api/accounts/me")),
|
|
1624
1722
|
safe(this.streams.tip()),
|
|
1625
1723
|
safe(this.index.canonical.list({ limit: 1 })),
|
|
1626
1724
|
safe(this.subgraphs.list()),
|
|
1627
|
-
safe(this.subscriptions.list())
|
|
1725
|
+
safe(this.subscriptions.list()),
|
|
1726
|
+
safe(this.projects.list()),
|
|
1727
|
+
safe(this.apiKeys.list())
|
|
1628
1728
|
]);
|
|
1629
1729
|
const subgraphs = subgraphsRes?.data ?? null;
|
|
1630
1730
|
let subscriptions = null;
|
|
@@ -1650,12 +1750,25 @@ class SecondLayer extends BaseClient {
|
|
|
1650
1750
|
}));
|
|
1651
1751
|
activeOperations = probed.filter((o) => o !== null);
|
|
1652
1752
|
}
|
|
1753
|
+
const projects = projectsRes ? projectsRes.projects.map((p) => ({
|
|
1754
|
+
name: p.name,
|
|
1755
|
+
slug: p.slug,
|
|
1756
|
+
network: p.network
|
|
1757
|
+
})) : null;
|
|
1758
|
+
const apiKeys = apiKeysRes ? apiKeysRes.keys.map((k) => ({
|
|
1759
|
+
prefix: k.prefix,
|
|
1760
|
+
name: k.name,
|
|
1761
|
+
status: k.status,
|
|
1762
|
+
product: k.product
|
|
1763
|
+
})) : null;
|
|
1653
1764
|
return {
|
|
1654
1765
|
account,
|
|
1655
1766
|
streamsTip,
|
|
1656
1767
|
indexTip: indexEnv?.tip ?? null,
|
|
1657
1768
|
subgraphs,
|
|
1658
1769
|
subscriptions,
|
|
1770
|
+
projects,
|
|
1771
|
+
apiKeys,
|
|
1659
1772
|
activeOperations
|
|
1660
1773
|
};
|
|
1661
1774
|
}
|
|
@@ -2118,15 +2231,17 @@ export {
|
|
|
2118
2231
|
StreamsServerError,
|
|
2119
2232
|
SecondLayer,
|
|
2120
2233
|
RateLimitError,
|
|
2234
|
+
Projects,
|
|
2121
2235
|
Index,
|
|
2122
2236
|
Datasets,
|
|
2123
2237
|
Cursor,
|
|
2124
2238
|
Contracts,
|
|
2125
2239
|
CURSOR_SLUGS,
|
|
2240
|
+
ByoBreakingChangeError,
|
|
2126
2241
|
AuthError,
|
|
2127
2242
|
ApiKeys,
|
|
2128
2243
|
ApiError
|
|
2129
2244
|
};
|
|
2130
2245
|
|
|
2131
|
-
//# debugId=
|
|
2246
|
+
//# debugId=8B8F4DFD96F5A43C64756E2164756E21
|
|
2132
2247
|
//# sourceMappingURL=index.js.map
|