@secondlayer/cli 7.0.0 → 8.0.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/cli.js CHANGED
@@ -32354,7 +32354,7 @@ var {
32354
32354
  // package.json
32355
32355
  var package_default = {
32356
32356
  name: "@secondlayer/cli",
32357
- version: "7.0.0",
32357
+ version: "8.0.0",
32358
32358
  repository: {
32359
32359
  type: "git",
32360
32360
  url: "git+https://github.com/ryanwaits/secondlayer.git",
@@ -33386,7 +33386,7 @@ async function createSubscription(name, opts) {
33386
33386
  let sl = null;
33387
33387
  if (!opts.skipApi) {
33388
33388
  try {
33389
- sl = await getSubscriptionClient(opts);
33389
+ sl = await getSubscriptionClient();
33390
33390
  await validateSubscriptionTargetFromApi(sl, {
33391
33391
  subgraphName: subgraph,
33392
33392
  tableName: table,
@@ -33418,7 +33418,7 @@ async function createSubscription(name, opts) {
33418
33418
  if (!opts.skipApi) {
33419
33419
  try {
33420
33420
  if (!sl)
33421
- sl = await getSubscriptionClient(opts);
33421
+ sl = await getSubscriptionClient();
33422
33422
  const res = await sl.subscriptions.create({
33423
33423
  name,
33424
33424
  subgraphName: subgraph,
@@ -33490,39 +33490,12 @@ SIGNING_SECRET=${signingSecret}
33490
33490
  success(`Done. Next:
33491
33491
  ${dashboardLine}${pausedLine}${runHint}`);
33492
33492
  }
33493
- function resolveSubscriptionClientConfig(opts, env = process.env, resolved) {
33494
- const needsResolvedKey = !opts.serviceKey && !env.SL_SERVICE_KEY;
33495
- const needsResolvedUrl = !opts.baseUrl && !env.SL_API_URL;
33496
- if ((needsResolvedKey || needsResolvedUrl) && !resolved) {
33497
- return { needsTenantResolution: true };
33498
- }
33499
- const apiKey = opts.serviceKey ?? env.SL_SERVICE_KEY ?? resolved?.ephemeralKey;
33500
- const baseUrl = opts.baseUrl ?? env.SL_API_URL ?? resolved?.apiUrl;
33501
- if (!apiKey) {
33502
- throw new Error("No service key available. Run `sl login` from an active project or pass --service-key.");
33503
- }
33504
- if (!baseUrl) {
33505
- throw new Error("No API URL available. Run `sl login` or pass --base-url.");
33506
- }
33507
- return { needsTenantResolution: false, baseUrl, apiKey };
33508
- }
33509
- async function getSubscriptionClient(opts) {
33510
- const config = resolveSubscriptionClientConfig(opts);
33511
- if (!config.needsTenantResolution) {
33512
- return new SecondLayer2({ baseUrl: config.baseUrl, apiKey: config.apiKey });
33513
- }
33514
- const resolved = await resolveAuth();
33515
- const resolvedConfig = resolveSubscriptionClientConfig(opts, process.env, resolved);
33516
- if (resolvedConfig.needsTenantResolution) {
33517
- throw new Error("Could not resolve credentials — run `sl login`.");
33518
- }
33519
- return new SecondLayer2({
33520
- baseUrl: resolvedConfig.baseUrl,
33521
- apiKey: resolvedConfig.apiKey
33522
- });
33493
+ async function getSubscriptionClient() {
33494
+ const { apiUrl, ephemeralKey } = await resolveAuth();
33495
+ return new SecondLayer2({ baseUrl: apiUrl, apiKey: ephemeralKey });
33523
33496
  }
33524
33497
  function addSubscriptionScaffold(parent, commandSpec, opts) {
33525
- parent.command(commandSpec).description(opts.description).option("-r, --runtime <runtime>", "inngest | trigger | cloudflare | node").option("-s, --subgraph <name>", "Subgraph to subscribe to").option("-t, --table <name>", "Table to subscribe to").option("-u, --url <url>", "Webhook URL").option("--auth-token <token>", "Bearer token for receiver API auth").option("--filter <kv...>", "Filter as key=value (supports .eq/.neq/.gt/.gte/.lt/.lte suffixes)").option("--service-key <key>", "SL_SERVICE_KEY override").option("--base-url <url>", "SL_API_URL override").option("--skip-api", "Copy template only, don't call the API").option("--no-scaffold", "Skip the local runtime template directory (webhook-only setups)").addHelpText("after", `
33498
+ parent.command(commandSpec).description(opts.description).option("-r, --runtime <runtime>", "inngest | trigger | cloudflare | node").option("-s, --subgraph <name>", "Subgraph to subscribe to").option("-t, --table <name>", "Table to subscribe to").option("-u, --url <url>", "Webhook URL").option("--auth-token <token>", "Bearer token for receiver API auth").option("--filter <kv...>", "Filter as key=value (supports .eq/.neq/.gt/.gte/.lt/.lte suffixes)").option("--skip-api", "Copy template only, don't call the API").option("--no-scaffold", "Skip the local runtime template directory (webhook-only setups)").addHelpText("after", `
33526
33499
  Examples:
33527
33500
  $ ${opts.examplePrefix} my-sub -s my-graph -t transfers -u https://example.com/webhook
33528
33501
  $ ${opts.examplePrefix} my-sub -s my-graph -t balances -r inngest --filter amount.gte=1000`).action(async (name, options) => {
@@ -33537,9 +33510,6 @@ function addSubscriptionsCreateCommand(subscriptions) {
33537
33510
  }
33538
33511
 
33539
33512
  // src/commands/subscriptions.ts
33540
- function commonOptions(cmd) {
33541
- return cmd.option("--service-key <key>", "SL_SERVICE_KEY override").option("--base-url <url>", "SL_API_URL override");
33542
- }
33543
33513
  function parseIntegerOption(value, name, min) {
33544
33514
  if (value === undefined)
33545
33515
  return;
@@ -33892,11 +33862,11 @@ async function confirmOrExit(message, yes) {
33892
33862
  return true;
33893
33863
  }
33894
33864
  function registerSubscriptionsCommand(program2) {
33895
- const subscriptions = commonOptions(program2.command("subscriptions").alias("subs").description("Manage subgraph table subscriptions"));
33865
+ const subscriptions = program2.command("subscriptions").alias("subs").description("Manage subgraph table subscriptions");
33896
33866
  addSubscriptionsCreateCommand(subscriptions);
33897
- commonOptions(subscriptions.command("list").alias("ls").description("List subscriptions").option("--json", "Output as JSON")).action(async (options) => {
33867
+ subscriptions.command("list").alias("ls").description("List subscriptions").option("--json", "Output as JSON").action(async (options) => {
33898
33868
  try {
33899
- const client = await getSubscriptionClient(options);
33869
+ const client = await getSubscriptionClient();
33900
33870
  const { data } = await client.subscriptions.list();
33901
33871
  if (options.json) {
33902
33872
  printJson(data);
@@ -33920,9 +33890,9 @@ ${data.length} subscription(s) total`));
33920
33890
  handleApiError(err, "list subscriptions");
33921
33891
  }
33922
33892
  });
33923
- commonOptions(subscriptions.command("get <idOrName>").description("Show subscription details").option("--json", "Output as JSON")).action(async (idOrName, options) => {
33893
+ subscriptions.command("get <idOrName>").description("Show subscription details").option("--json", "Output as JSON").action(async (idOrName, options) => {
33924
33894
  try {
33925
- const client = await getSubscriptionClient(options);
33895
+ const client = await getSubscriptionClient();
33926
33896
  const { detail } = await resolveSubscriptionRef(client, idOrName);
33927
33897
  if (options.json)
33928
33898
  printJson(detail);
@@ -33932,13 +33902,13 @@ ${data.length} subscription(s) total`));
33932
33902
  handleApiError(err, "get subscription");
33933
33903
  }
33934
33904
  });
33935
- commonOptions(subscriptions.command("update <idOrName>").description("Update subscription config").option("--name <name>", "Rename subscription").option("--url <url>", "Webhook URL").option("--auth-token <token>", "Set bearer token auth config").option("--format <format>", "standard-webhooks | inngest | trigger | cloudflare | cloudevents | raw").option("--runtime <runtime>", "inngest | trigger | cloudflare | node | none").option("--filter <kv...>", "Filter as key=value (supports .eq/.neq/.gt/.gte/.lt/.lte suffixes)").option("--clear-filter", "Replace filter with {}").option("--max-retries <n>", "Maximum delivery retries").option("--timeout-ms <n>", "Delivery timeout in milliseconds").option("--concurrency <n>", "Per-subscription delivery concurrency").option("--json", "Output as JSON").addHelpText("after", `
33905
+ subscriptions.command("update <idOrName>").description("Update subscription config").option("--name <name>", "Rename subscription").option("--url <url>", "Webhook URL").option("--auth-token <token>", "Set bearer token auth config").option("--format <format>", "standard-webhooks | inngest | trigger | cloudflare | cloudevents | raw").option("--runtime <runtime>", "inngest | trigger | cloudflare | node | none").option("--filter <kv...>", "Filter as key=value (supports .eq/.neq/.gt/.gte/.lt/.lte suffixes)").option("--clear-filter", "Replace filter with {}").option("--max-retries <n>", "Maximum delivery retries").option("--timeout-ms <n>", "Delivery timeout in milliseconds").option("--concurrency <n>", "Per-subscription delivery concurrency").option("--json", "Output as JSON").addHelpText("after", `
33936
33906
  Examples:
33937
33907
  $ sl subscriptions update my-sub --url https://example.com/hook
33938
33908
  $ sl subscriptions update my-sub --filter amount.gte=1000 --max-retries 5
33939
- $ sl subscriptions update my-sub --clear-filter`)).action(async (idOrName, options) => {
33909
+ $ sl subscriptions update my-sub --clear-filter`).action(async (idOrName, options) => {
33940
33910
  try {
33941
- const client = await getSubscriptionClient(options);
33911
+ const client = await getSubscriptionClient();
33942
33912
  const patch = buildUpdatePatch(options);
33943
33913
  const { id, detail } = await resolveSubscriptionRef(client, idOrName);
33944
33914
  if (patch.filter !== undefined) {
@@ -33958,9 +33928,9 @@ Examples:
33958
33928
  }
33959
33929
  });
33960
33930
  for (const action of ["pause", "resume"]) {
33961
- commonOptions(subscriptions.command(`${action} <idOrName>`).description(`${action === "pause" ? "Pause" : "Resume"} a subscription`).option("--json", "Output as JSON")).action(async (idOrName, options) => {
33931
+ subscriptions.command(`${action} <idOrName>`).description(`${action === "pause" ? "Pause" : "Resume"} a subscription`).option("--json", "Output as JSON").action(async (idOrName, options) => {
33962
33932
  try {
33963
- const client = await getSubscriptionClient(options);
33933
+ const client = await getSubscriptionClient();
33964
33934
  const { id } = await resolveSubscriptionRef(client, idOrName);
33965
33935
  const updated = await client.subscriptions[action](id);
33966
33936
  if (options.json)
@@ -33972,9 +33942,9 @@ Examples:
33972
33942
  }
33973
33943
  });
33974
33944
  }
33975
- commonOptions(subscriptions.command("delete <idOrName>").alias("rm").description("Delete a subscription").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON")).action(async (idOrName, options) => {
33945
+ subscriptions.command("delete <idOrName>").alias("rm").description("Delete a subscription").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").action(async (idOrName, options) => {
33976
33946
  try {
33977
- const client = await getSubscriptionClient(options);
33947
+ const client = await getSubscriptionClient();
33978
33948
  let resolved = null;
33979
33949
  try {
33980
33950
  resolved = await resolveSubscriptionRef(client, idOrName);
@@ -34003,9 +33973,9 @@ Examples:
34003
33973
  handleApiError(err, "delete subscription");
34004
33974
  }
34005
33975
  });
34006
- commonOptions(subscriptions.command("rotate-secret <idOrName>").description("Rotate the signing secret").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON")).action(async (idOrName, options) => {
33976
+ subscriptions.command("rotate-secret <idOrName>").description("Rotate the signing secret").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").action(async (idOrName, options) => {
34007
33977
  try {
34008
- const client = await getSubscriptionClient(options);
33978
+ const client = await getSubscriptionClient();
34009
33979
  const { id, detail } = await resolveSubscriptionRef(client, idOrName);
34010
33980
  const ok = await confirmOrExit(`Rotate signing secret for "${detail.name}"? Existing receivers using the old secret will fail verification.`, options.yes);
34011
33981
  if (!ok)
@@ -34021,9 +33991,9 @@ Examples:
34021
33991
  handleApiError(err, "rotate subscription secret");
34022
33992
  }
34023
33993
  });
34024
- commonOptions(subscriptions.command("deliveries <idOrName>").description("Show recent delivery attempts").option("--json", "Output as JSON")).action(async (idOrName, options) => {
33994
+ subscriptions.command("deliveries <idOrName>").description("Show recent delivery attempts").option("--json", "Output as JSON").action(async (idOrName, options) => {
34025
33995
  try {
34026
- const client = await getSubscriptionClient(options);
33996
+ const client = await getSubscriptionClient();
34027
33997
  const { id } = await resolveSubscriptionRef(client, idOrName);
34028
33998
  const { data } = await client.subscriptions.recentDeliveries(id);
34029
33999
  if (options.json)
@@ -34034,9 +34004,9 @@ Examples:
34034
34004
  handleApiError(err, "list subscription deliveries");
34035
34005
  }
34036
34006
  });
34037
- commonOptions(subscriptions.command("dead <idOrName>").description("Show dead-letter outbox rows").option("--json", "Output as JSON")).action(async (idOrName, options) => {
34007
+ subscriptions.command("dead <idOrName>").description("Show dead-letter outbox rows").option("--json", "Output as JSON").action(async (idOrName, options) => {
34038
34008
  try {
34039
- const client = await getSubscriptionClient(options);
34009
+ const client = await getSubscriptionClient();
34040
34010
  const { id } = await resolveSubscriptionRef(client, idOrName);
34041
34011
  const { data } = await client.subscriptions.dead(id);
34042
34012
  if (options.json)
@@ -34047,9 +34017,9 @@ Examples:
34047
34017
  handleApiError(err, "list dead-letter rows");
34048
34018
  }
34049
34019
  });
34050
- commonOptions(subscriptions.command("requeue <idOrName> <outboxId>").description("Requeue one dead-letter row").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON")).action(async (idOrName, outboxId, options) => {
34020
+ subscriptions.command("requeue <idOrName> <outboxId>").description("Requeue one dead-letter row").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").action(async (idOrName, outboxId, options) => {
34051
34021
  try {
34052
- const client = await getSubscriptionClient(options);
34022
+ const client = await getSubscriptionClient();
34053
34023
  const { id, detail } = await resolveSubscriptionRef(client, idOrName);
34054
34024
  const ok = await confirmOrExit(`Requeue ${outboxId} for "${detail.name}"?`, options.yes);
34055
34025
  if (!ok)
@@ -34063,16 +34033,16 @@ Examples:
34063
34033
  handleApiError(err, "requeue dead-letter row");
34064
34034
  }
34065
34035
  });
34066
- commonOptions(subscriptions.command("replay <idOrName>").description("Replay a block range").requiredOption("--from-block <n>", "Start block height").requiredOption("--to-block <n>", "End block height").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").addHelpText("after", `
34036
+ subscriptions.command("replay <idOrName>").description("Replay a block range").requiredOption("--from-block <n>", "Start block height").requiredOption("--to-block <n>", "End block height").option("-y, --yes", "Skip confirmation").option("--json", "Output as JSON").addHelpText("after", `
34067
34037
  Examples:
34068
- $ sl subscriptions replay my-sub --from-block 150000 --to-block 160000 -y`)).action(async (idOrName, options) => {
34038
+ $ sl subscriptions replay my-sub --from-block 150000 --to-block 160000 -y`).action(async (idOrName, options) => {
34069
34039
  try {
34070
34040
  const fromBlock = requireIntegerOption(options.fromBlock, "--from-block");
34071
34041
  const toBlock = requireIntegerOption(options.toBlock, "--to-block");
34072
34042
  if (fromBlock > toBlock) {
34073
34043
  throw new Error("--from-block must be <= --to-block");
34074
34044
  }
34075
- const client = await getSubscriptionClient(options);
34045
+ const client = await getSubscriptionClient();
34076
34046
  const { id, detail } = await resolveSubscriptionRef(client, idOrName);
34077
34047
  const ok = await confirmOrExit(`Replay ${detail.name} from block ${fromBlock} to ${toBlock}?`, options.yes);
34078
34048
  if (!ok)
@@ -34091,9 +34061,9 @@ Examples:
34091
34061
  handleApiError(err, "replay subscription");
34092
34062
  }
34093
34063
  });
34094
- commonOptions(subscriptions.command("doctor <idOrName>").description("Diagnose subscription health and next steps").option("--json", "Output as JSON")).action(async (idOrName, options) => {
34064
+ subscriptions.command("doctor <idOrName>").description("Diagnose subscription health and next steps").option("--json", "Output as JSON").action(async (idOrName, options) => {
34095
34065
  try {
34096
- const client = await getSubscriptionClient(options);
34066
+ const client = await getSubscriptionClient();
34097
34067
  const { id, detail } = await resolveSubscriptionRef(client, idOrName);
34098
34068
  const [deliveries, dead, subgraph] = await Promise.allSettled([
34099
34069
  client.subscriptions.recentDeliveries(id),
@@ -34114,10 +34084,10 @@ Examples:
34114
34084
  handleApiError(err, "diagnose subscription");
34115
34085
  }
34116
34086
  });
34117
- commonOptions(subscriptions.command("test <idOrName>").description("Build and optionally POST a signed Standard Webhooks fixture").option("--signing-secret <secret>", "Signing secret override").option("--post", "POST the fixture to the subscription URL").option("--json", "Output as JSON")).action(async (idOrName, options) => {
34087
+ subscriptions.command("test <idOrName>").description("Build and optionally POST a signed Standard Webhooks fixture").option("--signing-secret <secret>", "Signing secret override").option("--post", "POST the fixture to the subscription URL").option("--json", "Output as JSON").action(async (idOrName, options) => {
34118
34088
  try {
34119
34089
  const signingSecret = resolveSigningSecret(options);
34120
- const client = await getSubscriptionClient(options);
34090
+ const client = await getSubscriptionClient();
34121
34091
  const { detail } = await resolveSubscriptionRef(client, idOrName);
34122
34092
  const subgraph = await client.subgraphs.get(detail.subgraphName).catch(() => null);
34123
34093
  const row = await representativeRow(client, detail, subgraph);
@@ -35676,8 +35646,8 @@ function registerSubgraphsCommand(program2) {
35676
35646
  const subgraphs = program2.command("subgraphs").description("Manage materialized subgraphs");
35677
35647
  subgraphs.command("create <name>").description("Create a new subgraph definition file").option("--template <slug>", `Foundation Dataset starter (one of: ${SUBGRAPH_TEMPLATE_SLUGS.join(", ")})`).addHelpText("after", `
35678
35648
  Examples:
35679
- $ sl subgraphs new my-graph
35680
- $ sl subgraphs new token-balances --template sip-010-balances`).action(async (name, opts) => {
35649
+ $ sl subgraphs create my-graph
35650
+ $ sl subgraphs create token-balances --template sip-010-balances`).action(async (name, opts) => {
35681
35651
  const slug = opts.template ?? "basic";
35682
35652
  if (!SUBGRAPH_TEMPLATE_SLUGS.includes(slug)) {
35683
35653
  error(`Unknown template "${opts.template}". Available templates:
@@ -38043,5 +38013,5 @@ program.commandsGroup("Account:");
38043
38013
  registerAccountCommand(program);
38044
38014
  program.parse();
38045
38015
 
38046
- //# debugId=E63D3732E427AF4164756E2164756E21
38016
+ //# debugId=A5BC51D23BA9DE7264756E2164756E21
38047
38017
  //# sourceMappingURL=cli.js.map