@secondlayer/sdk 6.16.0 → 6.18.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.
@@ -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.get(d.path, this.paramsToQuery(params));
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.get("bns/names", buildQuery({
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.get("bns/namespaces", "");
503
+ return this.requestPath("bns/namespaces", "");
483
504
  }
484
505
  bnsResolve(fqn) {
485
- return this.get("bns/resolve", buildQuery({ fqn }));
506
+ return this.requestPath("bns/resolve", buildQuery({ fqn }));
486
507
  }
487
508
  networkHealth() {
488
- return this.get("network-health/summary", "");
509
+ return this.requestPath("network-health/summary", "");
489
510
  }
490
- get(path, query) {
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.get(path, this.paramsToQuery(params));
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,
@@ -549,6 +593,9 @@ class Index extends BaseClient {
549
593
  usage() {
550
594
  return this.request("GET", "/v1/index/usage");
551
595
  }
596
+ discover() {
597
+ return this.request("GET", "/v1/index");
598
+ }
552
599
  ftTransfers = {
553
600
  list: (params = {}) => this.listFtTransfers(params),
554
601
  walk: (params = {}) => this.walkFtTransfers(params)
@@ -674,7 +721,8 @@ class Index extends BaseClient {
674
721
  sender: params.sender,
675
722
  recipient: params.recipient,
676
723
  from_height: params.fromHeight,
677
- to_height: params.toHeight
724
+ to_height: params.toHeight,
725
+ trait: params.trait
678
726
  })}`);
679
727
  }
680
728
  async* walkEvents(params) {
@@ -711,7 +759,8 @@ class Index extends BaseClient {
711
759
  function_name: params.functionName,
712
760
  sender: params.sender,
713
761
  from_height: params.fromHeight,
714
- to_height: params.toHeight
762
+ to_height: params.toHeight,
763
+ trait: params.trait
715
764
  })}`);
716
765
  }
717
766
  async* walkContractCalls(params = {}) {
@@ -944,6 +993,31 @@ class Index extends BaseClient {
944
993
  }
945
994
  }
946
995
 
996
+ // src/projects/client.ts
997
+ class Projects extends BaseClient {
998
+ constructor(options = {}) {
999
+ super(options);
1000
+ }
1001
+ list() {
1002
+ return this.request("GET", "/api/projects");
1003
+ }
1004
+ get(slug) {
1005
+ return this.request("GET", `/api/projects/${slug}`);
1006
+ }
1007
+ create(params) {
1008
+ return this.request("POST", "/api/projects", params);
1009
+ }
1010
+ update(slug, patch) {
1011
+ return this.request("PATCH", `/api/projects/${slug}`, patch);
1012
+ }
1013
+ delete(slug) {
1014
+ return this.request("DELETE", `/api/projects/${slug}`);
1015
+ }
1016
+ team(slug) {
1017
+ return this.request("GET", `/api/projects/${slug}/team`);
1018
+ }
1019
+ }
1020
+
947
1021
  // src/streams/client.ts
948
1022
  import { ed25519 as ed255192 } from "@secondlayer/shared";
949
1023
 
@@ -1622,12 +1696,14 @@ class SecondLayer extends BaseClient {
1622
1696
  subgraphs;
1623
1697
  subscriptions;
1624
1698
  apiKeys;
1699
+ projects;
1625
1700
  constructor(options = {}) {
1626
1701
  super(options);
1627
1702
  this.streams = createStreamsClient({
1628
1703
  apiKey: options.apiKey ?? "",
1629
1704
  baseUrl: options.baseUrl,
1630
- fetchImpl: options.fetchImpl
1705
+ fetchImpl: options.fetchImpl,
1706
+ dumpsBaseUrl: options.dumpsBaseUrl
1631
1707
  });
1632
1708
  this.index = new Index(options);
1633
1709
  this.datasets = new Datasets(options);
@@ -1635,15 +1711,26 @@ class SecondLayer extends BaseClient {
1635
1711
  this.subgraphs = new Subgraphs(options);
1636
1712
  this.subscriptions = new Subscriptions(options);
1637
1713
  this.apiKeys = new ApiKeys(options);
1714
+ this.projects = new Projects(options);
1638
1715
  }
1639
1716
  async context() {
1640
1717
  const safe = (p) => p.then((v) => v).catch(() => null);
1641
- const [account, streamsTip, indexEnv, subgraphsRes, subscriptionsRes] = await Promise.all([
1718
+ const [
1719
+ account,
1720
+ streamsTip,
1721
+ indexEnv,
1722
+ subgraphsRes,
1723
+ subscriptionsRes,
1724
+ projectsRes,
1725
+ apiKeysRes
1726
+ ] = await Promise.all([
1642
1727
  safe(this.request("GET", "/api/accounts/me")),
1643
1728
  safe(this.streams.tip()),
1644
1729
  safe(this.index.canonical.list({ limit: 1 })),
1645
1730
  safe(this.subgraphs.list()),
1646
- safe(this.subscriptions.list())
1731
+ safe(this.subscriptions.list()),
1732
+ safe(this.projects.list()),
1733
+ safe(this.apiKeys.list())
1647
1734
  ]);
1648
1735
  const subgraphs = subgraphsRes?.data ?? null;
1649
1736
  let subscriptions = null;
@@ -1669,12 +1756,25 @@ class SecondLayer extends BaseClient {
1669
1756
  }));
1670
1757
  activeOperations = probed.filter((o) => o !== null);
1671
1758
  }
1759
+ const projects = projectsRes ? projectsRes.projects.map((p) => ({
1760
+ name: p.name,
1761
+ slug: p.slug,
1762
+ network: p.network
1763
+ })) : null;
1764
+ const apiKeys = apiKeysRes ? apiKeysRes.keys.map((k) => ({
1765
+ prefix: k.prefix,
1766
+ name: k.name,
1767
+ status: k.status,
1768
+ product: k.product
1769
+ })) : null;
1672
1770
  return {
1673
1771
  account,
1674
1772
  streamsTip,
1675
1773
  indexTip: indexEnv?.tip ?? null,
1676
1774
  subgraphs,
1677
1775
  subscriptions,
1776
+ projects,
1777
+ apiKeys,
1678
1778
  activeOperations
1679
1779
  };
1680
1780
  }
@@ -1695,5 +1795,5 @@ export {
1695
1795
  Subgraphs
1696
1796
  };
1697
1797
 
1698
- //# debugId=4CC7A5C19CBAC4F064756E2164756E21
1798
+ //# debugId=A5185B837644857464756E2164756E21
1699
1799
  //# sourceMappingURL=index.js.map