@secondlayer/cli 8.6.4 → 8.7.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 CHANGED
@@ -30,8 +30,11 @@ export SL_API_KEY=sk-sl_xxxxxxxx
30
30
  source (and exits non-zero when not logged in). The global `--api-key` /
31
31
  `--api-url` flags (and `SL_API_KEY` / `SL_API_URL`) apply to every command.
32
32
 
33
- During open beta, reads are public (no key needed). Writes — deploying or
34
- managing subgraphs and subscriptions — require a session or an `sk-sl_` key.
33
+ During open beta, reads are public (no key needed) — for subgraphs that means
34
+ **public** subgraphs only (managed deploys default public; BYO deploys and all
35
+ pre-existing subgraphs are private, readable with your key). Writes — deploying,
36
+ publishing, or managing subgraphs and subscriptions — require a session or an
37
+ `sk-sl_` key.
35
38
 
36
39
  ## Quickstart
37
40
 
@@ -86,7 +89,8 @@ scoped reads and cannot mint (403). Minted keys inherit your plan's tier.
86
89
  |---|---|
87
90
  | `sl subgraphs create <name>` | Scaffold a definition file |
88
91
  | `sl subgraphs scaffold <SP...::contract> [-o <path>] [--no-install]` | Generate a subgraph from a deployed contract |
89
- | `sl subgraphs deploy <file> [--start-block <n>]` | Deploy; `--start-block` overrides the definition |
92
+ | `sl subgraphs deploy <file> [--start-block <n>] [--visibility public\|private]` | Deploy; `--start-block` overrides the definition. Managed deploys default `public`, BYO default `private` |
93
+ | `sl subgraphs publish <name>` / `unpublish <name>` | Flip visibility; publish claims the global public name (409 `PUBLIC_NAME_TAKEN` if claimed) |
90
94
  | `sl subgraphs dev <file>` | Watch + hot-redeploy |
91
95
  | `sl subgraphs query <name> <table>` | Query a table with filters, sort, pagination |
92
96
  | `sl subgraphs list` / `status <name>` / `gaps <name>` | Inspect deployments |
package/dist/cli.js CHANGED
@@ -31811,7 +31811,7 @@ var {
31811
31811
  // package.json
31812
31812
  var package_default = {
31813
31813
  name: "@secondlayer/cli",
31814
- version: "8.6.4",
31814
+ version: "8.7.0",
31815
31815
  repository: {
31816
31816
  type: "git",
31817
31817
  url: "git+https://github.com/ryanwaits/secondlayer.git",
@@ -31861,9 +31861,9 @@ var package_default = {
31861
31861
  "@inquirer/prompts": "^8.2.0",
31862
31862
  "@secondlayer/bundler": "^0.3.7",
31863
31863
  "@secondlayer/scaffold": "^1.2.0",
31864
- "@secondlayer/sdk": "^6.19.0",
31865
- "@secondlayer/shared": "^6.28.1",
31866
- "@secondlayer/stacks": "^2.4.0",
31864
+ "@secondlayer/sdk": "^6.20.0",
31865
+ "@secondlayer/shared": "^6.29.0",
31866
+ "@secondlayer/stacks": "^2.5.0",
31867
31867
  "@secondlayer/subgraphs": "^3.10.0",
31868
31868
  "@biomejs/js-api": "^0.7.0",
31869
31869
  "@biomejs/wasm-nodejs": "^1.9.0",
@@ -32026,6 +32026,12 @@ async function deleteSubgraphApi(name, options) {
32026
32026
  async function deploySubgraphApi(data) {
32027
32027
  return (await getPlatformClient()).subgraphs.deploy(data);
32028
32028
  }
32029
+ async function publishSubgraphApi(name) {
32030
+ return (await getPlatformClient()).subgraphs.publish(name);
32031
+ }
32032
+ async function unpublishSubgraphApi(name) {
32033
+ return (await getPlatformClient()).subgraphs.unpublish(name);
32034
+ }
32029
32035
  async function querySubgraphTable(name, table, params = {}) {
32030
32036
  return (await getPlatformClient()).subgraphs.queryTable(name, table, params);
32031
32037
  }
@@ -34595,8 +34601,8 @@ function sip010Balances(name) {
34595
34601
  * source filter.
34596
34602
  *
34597
34603
  * Query examples once deployed:
34598
- * GET /api/subgraphs/${name}/balances?_search=SP1...
34599
- * GET /api/subgraphs/${name}/balances?holder=SP1...
34604
+ * GET /v1/subgraphs/${name}/balances?_search=SP1...
34605
+ * GET /v1/subgraphs/${name}/balances?holder=SP1...
34600
34606
  */
34601
34607
  export default defineSubgraph({
34602
34608
  name: "${name}",
@@ -34672,8 +34678,8 @@ function sbtcFlows(name) {
34672
34678
  * Source contract: sbtc-registry (mainnet).
34673
34679
  *
34674
34680
  * Query examples once deployed:
34675
- * GET /api/subgraphs/${name}/flows?topic=completed-deposit
34676
- * GET /api/subgraphs/${name}/flows?topic=withdrawal-create
34681
+ * GET /v1/subgraphs/${name}/flows?topic=completed-deposit
34682
+ * GET /v1/subgraphs/${name}/flows?topic=withdrawal-create
34677
34683
  */
34678
34684
  export default defineSubgraph({
34679
34685
  name: "${name}",
@@ -34743,8 +34749,8 @@ function poxStacking(name) {
34743
34749
  * the dataset shows one possible shape.
34744
34750
  *
34745
34751
  * Query examples once deployed:
34746
- * GET /api/subgraphs/${name}/calls?function_name=stack-stx
34747
- * GET /api/subgraphs/${name}/calls?caller=SP1...
34752
+ * GET /v1/subgraphs/${name}/calls?function_name=stack-stx
34753
+ * GET /v1/subgraphs/${name}/calls?caller=SP1...
34748
34754
  */
34749
34755
  export default defineSubgraph({
34750
34756
  name: "${name}",
@@ -34794,8 +34800,8 @@ function bnsNames(name) {
34794
34800
  * Source: BNS-V2 print events (topic-discriminated payloads).
34795
34801
  *
34796
34802
  * Query examples once deployed:
34797
- * GET /api/subgraphs/${name}/names?owner=SP1...
34798
- * GET /api/subgraphs/${name}/names?_search=alice
34803
+ * GET /v1/subgraphs/${name}/names?owner=SP1...
34804
+ * GET /v1/subgraphs/${name}/names?_search=alice
34799
34805
  */
34800
34806
  export default defineSubgraph({
34801
34807
  name: "${name}",
@@ -34907,6 +34913,13 @@ function parseStartBlockOption(value) {
34907
34913
  }
34908
34914
  return parsed;
34909
34915
  }
34916
+ function parseVisibilityOption(value) {
34917
+ if (value === undefined)
34918
+ return;
34919
+ if (value === "public" || value === "private")
34920
+ return value;
34921
+ throw new Error('--visibility must be "public" or "private"');
34922
+ }
34910
34923
  function parseSubgraphSpecFormat(value) {
34911
34924
  const format = value ?? "openapi";
34912
34925
  if (format === "openapi" || format === "agent" || format === "markdown") {
@@ -35266,7 +35279,7 @@ Stopped watching.`);
35266
35279
  });
35267
35280
  await new Promise(() => {});
35268
35281
  });
35269
- subgraphs.command("deploy <file>").alias("update").description("Deploy a subgraph definition file (alias: update — deploy is create-or-update)").option("--start-block <n>", "Override the subgraph definition startBlock for this deploy").option("--dry-run", "Validate and preview deploy without writing changes").option("-y, --yes", "Skip the reindex confirmation prompt").option("--database-url <url>", "BYO data plane: write the subgraph's schema/rows to your own Postgres. With --dry-run, prints the DDL + grant script and verifies the connection.").option("--strict", "Run `tsc --noEmit` against the handler before deploy (slower; catches TS type errors)").action(async (file, options2) => {
35282
+ subgraphs.command("deploy <file>").alias("update").description("Deploy a subgraph definition file (alias: update — deploy is create-or-update)").option("--start-block <n>", "Override the subgraph definition startBlock for this deploy").option("--dry-run", "Validate and preview deploy without writing changes").option("-y, --yes", "Skip the reindex confirmation prompt").option("--database-url <url>", "BYO data plane: write the subgraph's schema/rows to your own Postgres. With --dry-run, prints the DDL + grant script and verifies the connection.").option("--strict", "Run `tsc --noEmit` against the handler before deploy (slower; catches TS type errors)").option("--visibility <visibility>", "Read visibility: public (anon /v1 reads, global name claim) or private (your key only). Defaults: managed → public, BYO → private.").action(async (file, options2) => {
35270
35283
  try {
35271
35284
  const absPath = resolve2(file);
35272
35285
  const config = await loadConfig();
@@ -35274,6 +35287,16 @@ Stopped watching.`);
35274
35287
  await requireAuth();
35275
35288
  }
35276
35289
  const dryRun = options2.dryRun;
35290
+ const visibility = parseVisibilityOption(options2.visibility);
35291
+ if (visibility === "public" && options2.databaseUrl && !options2.yes) {
35292
+ const confirmed = await confirm3({
35293
+ message: "⚠ Public BYO subgraph: anonymous reads will query YOUR database. Continue?"
35294
+ });
35295
+ if (!confirmed) {
35296
+ info("Aborted.");
35297
+ process.exit(0);
35298
+ }
35299
+ }
35277
35300
  const startBlock = parseStartBlockOption(options2.startBlock);
35278
35301
  if (startBlock !== undefined) {
35279
35302
  warn(`--start-block ${startBlock} overrides the definition's startBlock for this deploy.`);
@@ -35321,16 +35344,22 @@ Stopped watching.`);
35321
35344
  handlerCode,
35322
35345
  sourceCode: source,
35323
35346
  ...deployStartBlock !== undefined ? { startBlock: deployStartBlock } : {},
35324
- ...options2.databaseUrl ? { databaseUrl: options2.databaseUrl } : {}
35347
+ ...options2.databaseUrl ? { databaseUrl: options2.databaseUrl } : {},
35348
+ ...visibility ? { visibility } : {}
35325
35349
  });
35326
35350
  const printDeployFooter = async () => {
35327
35351
  try {
35328
35352
  const { apiUrl } = await resolveAuth();
35329
35353
  const baseUrl = deriveBaseUrl(apiUrl);
35330
35354
  const firstTable = Object.keys(effectiveDef.schema ?? {})[0];
35355
+ const isPublic = result.visibility === "public";
35331
35356
  info(` Dashboard: ${baseUrl}/platform/subgraphs/${effectiveDef.name}`);
35332
- if (firstTable) {
35357
+ if (isPublic && firstTable) {
35358
+ info(` Read: ${apiUrl}/v1/subgraphs/${effectiveDef.name}/${firstTable}`);
35359
+ info(` Share: ${apiUrl}/v1/subgraphs/${effectiveDef.name} (public — no key needed)`);
35360
+ } else if (firstTable) {
35333
35361
  info(` REST: ${apiUrl}/api/subgraphs/${effectiveDef.name}/${firstTable}`);
35362
+ info(` Publish: sl subgraphs publish ${effectiveDef.name} (open anon /v1 reads)`);
35334
35363
  }
35335
35364
  info(` Watch: sl subgraphs status ${effectiveDef.name}`);
35336
35365
  } catch {}
@@ -35795,6 +35824,33 @@ ${rows.length} row(s)`));
35795
35824
  handleApiError(err, "delete subgraph");
35796
35825
  }
35797
35826
  });
35827
+ subgraphs.command("publish <name>").description("Make a subgraph publicly readable on /v1/subgraphs/<name> (claims the name globally, no key needed to read)").action(async (name) => {
35828
+ try {
35829
+ await requireAuth();
35830
+ const result = await publishSubgraphApi(name);
35831
+ success(`Subgraph "${name}" is now public`);
35832
+ try {
35833
+ const { apiUrl } = await resolveAuth();
35834
+ info(` Share: ${apiUrl}${result.url} (no key needed)`);
35835
+ } catch {}
35836
+ } catch (err) {
35837
+ const status2 = err?.status;
35838
+ if (status2 === 409) {
35839
+ error(`Public name "${name}" is already taken by another account. Rename the subgraph (redeploy under a new name) or keep it private.`);
35840
+ process.exit(1);
35841
+ }
35842
+ handleApiError(err, "publish subgraph");
35843
+ }
35844
+ });
35845
+ subgraphs.command("unpublish <name>").description("Make a subgraph private again — reads require your API key, the public name claim is released").action(async (name) => {
35846
+ try {
35847
+ await requireAuth();
35848
+ await unpublishSubgraphApi(name);
35849
+ success(`Subgraph "${name}" is now private (reads need your key)`);
35850
+ } catch (err) {
35851
+ handleApiError(err, "unpublish subgraph");
35852
+ }
35853
+ });
35798
35854
  subgraphs.command("scaffold [contractAddress]").description("Scaffold a defineSubgraph() file from a contract or trait").option("-o, --output <path>", "Output file path (required)").option("-k, --api-key <key>", "Stacks node API key for direct RPC URLs").option("--functions <names>", "Comma-separated public functions to index as typed contract_call tables").option("--trait <std>", "Scaffold a trait-scoped source (sip-009|sip-010|sip-013) — no contract needed").option("--no-install", "Skip bun install after writing package.json").addHelpText("after", `
35799
35855
  Examples:
35800
35856
  $ sl subgraphs scaffold SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft -o subgraphs/apes.ts
@@ -37916,5 +37972,5 @@ registerAccountCommand(program);
37916
37972
  registerKeysCommand(program);
37917
37973
  program.parse();
37918
37974
 
37919
- //# debugId=D852EB907B2A586864756E2164756E21
37975
+ //# debugId=5C2D0497F3EEA0AA64756E2164756E21
37920
37976
  //# sourceMappingURL=cli.js.map