@secondlayer/sdk 6.16.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 +135 -3
- package/dist/index.js +105 -10
- package/dist/index.js.map +7 -6
- package/dist/subgraphs/index.d.ts +134 -2
- package/dist/subgraphs/index.js +104 -10
- package/dist/subgraphs/index.js.map +7 -6
- package/package.json +1 -1
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
|
|
@@ -1949,4 +2081,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
1949
2081
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
1950
2082
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
1951
2083
|
declare function decodeClarityValue(hex: string): unknown;
|
|
1952
|
-
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, ByoBreakingChangeError, ByoBreakingChangeDetails, 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
|
@@ -395,6 +395,12 @@ class ApiKeys extends BaseClient {
|
|
|
395
395
|
name: params.name
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
|
+
list() {
|
|
399
|
+
return this.request("GET", "/api/keys");
|
|
400
|
+
}
|
|
401
|
+
revoke(id) {
|
|
402
|
+
return this.request("DELETE", `/api/keys/${id}`);
|
|
403
|
+
}
|
|
398
404
|
}
|
|
399
405
|
|
|
400
406
|
// src/contracts/client.ts
|
|
@@ -441,20 +447,35 @@ var CURSOR_SLUGS = {
|
|
|
441
447
|
rowKey: "events"
|
|
442
448
|
}
|
|
443
449
|
};
|
|
450
|
+
function catalogPathTail(path) {
|
|
451
|
+
return path.replace(/^\/?v1\/datasets\//, "").replace(/^\/+/, "");
|
|
452
|
+
}
|
|
444
453
|
|
|
445
454
|
class Datasets extends BaseClient {
|
|
455
|
+
catalogPromise;
|
|
446
456
|
constructor(options = {}) {
|
|
447
457
|
super(options);
|
|
448
458
|
}
|
|
449
459
|
listDatasets() {
|
|
450
460
|
return this.request("GET", "/v1/datasets");
|
|
451
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
|
+
}
|
|
452
473
|
async query(slug, params = {}) {
|
|
453
474
|
const d = CURSOR_SLUGS[slug];
|
|
454
475
|
if (!d) {
|
|
455
476
|
throw new Error(`unknown cursor dataset "${slug}" (use one of: ${Object.keys(CURSOR_SLUGS).join(", ")})`);
|
|
456
477
|
}
|
|
457
|
-
const env = await this.
|
|
478
|
+
const env = await this.requestPath(d.path, this.paramsToQuery(params));
|
|
458
479
|
return {
|
|
459
480
|
rows: env[d.rowKey] ?? [],
|
|
460
481
|
next_cursor: env.next_cursor ?? null,
|
|
@@ -471,7 +492,7 @@ class Datasets extends BaseClient {
|
|
|
471
492
|
bnsNamespaceEvents = this.cursorDataset("bns/namespace-events", "events");
|
|
472
493
|
bnsMarketplaceEvents = this.cursorDataset("bns/marketplace-events", "events");
|
|
473
494
|
bnsNames(params = {}) {
|
|
474
|
-
return this.
|
|
495
|
+
return this.requestPath("bns/names", buildQuery({
|
|
475
496
|
namespace: params.namespace,
|
|
476
497
|
owner: params.owner,
|
|
477
498
|
limit: params.limit,
|
|
@@ -479,17 +500,40 @@ class Datasets extends BaseClient {
|
|
|
479
500
|
}));
|
|
480
501
|
}
|
|
481
502
|
bnsNamespaces() {
|
|
482
|
-
return this.
|
|
503
|
+
return this.requestPath("bns/namespaces", "");
|
|
483
504
|
}
|
|
484
505
|
bnsResolve(fqn) {
|
|
485
|
-
return this.
|
|
506
|
+
return this.requestPath("bns/resolve", buildQuery({ fqn }));
|
|
486
507
|
}
|
|
487
508
|
networkHealth() {
|
|
488
|
-
return this.
|
|
509
|
+
return this.requestPath("network-health/summary", "");
|
|
489
510
|
}
|
|
490
|
-
|
|
511
|
+
requestPath(path, query) {
|
|
491
512
|
return this.request("GET", `/v1/datasets/${path}${query}`);
|
|
492
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
|
+
}
|
|
493
537
|
paramsToQuery(params) {
|
|
494
538
|
const mapped = {};
|
|
495
539
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -501,7 +545,7 @@ class Datasets extends BaseClient {
|
|
|
501
545
|
}
|
|
502
546
|
cursorDataset(path, rowKey) {
|
|
503
547
|
const list = async (params = {}) => {
|
|
504
|
-
const envelope = await this.
|
|
548
|
+
const envelope = await this.requestPath(path, this.paramsToQuery(params));
|
|
505
549
|
return {
|
|
506
550
|
rows: envelope[rowKey] ?? [],
|
|
507
551
|
next_cursor: envelope.next_cursor ?? null,
|
|
@@ -944,6 +988,31 @@ class Index extends BaseClient {
|
|
|
944
988
|
}
|
|
945
989
|
}
|
|
946
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
|
+
|
|
947
1016
|
// src/streams/client.ts
|
|
948
1017
|
import { ed25519 as ed255192 } from "@secondlayer/shared";
|
|
949
1018
|
|
|
@@ -1622,6 +1691,7 @@ class SecondLayer extends BaseClient {
|
|
|
1622
1691
|
subgraphs;
|
|
1623
1692
|
subscriptions;
|
|
1624
1693
|
apiKeys;
|
|
1694
|
+
projects;
|
|
1625
1695
|
constructor(options = {}) {
|
|
1626
1696
|
super(options);
|
|
1627
1697
|
this.streams = createStreamsClient({
|
|
@@ -1635,15 +1705,26 @@ class SecondLayer extends BaseClient {
|
|
|
1635
1705
|
this.subgraphs = new Subgraphs(options);
|
|
1636
1706
|
this.subscriptions = new Subscriptions(options);
|
|
1637
1707
|
this.apiKeys = new ApiKeys(options);
|
|
1708
|
+
this.projects = new Projects(options);
|
|
1638
1709
|
}
|
|
1639
1710
|
async context() {
|
|
1640
1711
|
const safe = (p) => p.then((v) => v).catch(() => null);
|
|
1641
|
-
const [
|
|
1712
|
+
const [
|
|
1713
|
+
account,
|
|
1714
|
+
streamsTip,
|
|
1715
|
+
indexEnv,
|
|
1716
|
+
subgraphsRes,
|
|
1717
|
+
subscriptionsRes,
|
|
1718
|
+
projectsRes,
|
|
1719
|
+
apiKeysRes
|
|
1720
|
+
] = await Promise.all([
|
|
1642
1721
|
safe(this.request("GET", "/api/accounts/me")),
|
|
1643
1722
|
safe(this.streams.tip()),
|
|
1644
1723
|
safe(this.index.canonical.list({ limit: 1 })),
|
|
1645
1724
|
safe(this.subgraphs.list()),
|
|
1646
|
-
safe(this.subscriptions.list())
|
|
1725
|
+
safe(this.subscriptions.list()),
|
|
1726
|
+
safe(this.projects.list()),
|
|
1727
|
+
safe(this.apiKeys.list())
|
|
1647
1728
|
]);
|
|
1648
1729
|
const subgraphs = subgraphsRes?.data ?? null;
|
|
1649
1730
|
let subscriptions = null;
|
|
@@ -1669,12 +1750,25 @@ class SecondLayer extends BaseClient {
|
|
|
1669
1750
|
}));
|
|
1670
1751
|
activeOperations = probed.filter((o) => o !== null);
|
|
1671
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;
|
|
1672
1764
|
return {
|
|
1673
1765
|
account,
|
|
1674
1766
|
streamsTip,
|
|
1675
1767
|
indexTip: indexEnv?.tip ?? null,
|
|
1676
1768
|
subgraphs,
|
|
1677
1769
|
subscriptions,
|
|
1770
|
+
projects,
|
|
1771
|
+
apiKeys,
|
|
1678
1772
|
activeOperations
|
|
1679
1773
|
};
|
|
1680
1774
|
}
|
|
@@ -2137,6 +2231,7 @@ export {
|
|
|
2137
2231
|
StreamsServerError,
|
|
2138
2232
|
SecondLayer,
|
|
2139
2233
|
RateLimitError,
|
|
2234
|
+
Projects,
|
|
2140
2235
|
Index,
|
|
2141
2236
|
Datasets,
|
|
2142
2237
|
Cursor,
|
|
@@ -2148,5 +2243,5 @@ export {
|
|
|
2148
2243
|
ApiError
|
|
2149
2244
|
};
|
|
2150
2245
|
|
|
2151
|
-
//# debugId=
|
|
2246
|
+
//# debugId=8B8F4DFD96F5A43C64756E2164756E21
|
|
2152
2247
|
//# sourceMappingURL=index.js.map
|