@secondlayer/cli 1.6.1 → 1.6.3
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 +37 -32
- package/dist/cli.js.map +5 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -12433,22 +12433,26 @@ function parseContractId(contractId) {
|
|
|
12433
12433
|
|
|
12434
12434
|
// src/utils/api.ts
|
|
12435
12435
|
class StacksApiClient {
|
|
12436
|
-
static hasWarnedAboutApiKey = false;
|
|
12437
12436
|
baseUrl;
|
|
12438
12437
|
headers;
|
|
12439
|
-
|
|
12440
|
-
constructor(network = "mainnet", apiKey, apiUrl) {
|
|
12441
|
-
|
|
12442
|
-
this.
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
` + " Get a free Hiro key at: https://platform.hiro.so/");
|
|
12449
|
-
StacksApiClient.hasWarnedAboutApiKey = true;
|
|
12438
|
+
useProxy;
|
|
12439
|
+
constructor(network = "mainnet", apiKey, apiUrl, slApiUrl) {
|
|
12440
|
+
this.useProxy = !apiUrl && network !== "devnet";
|
|
12441
|
+
if (this.useProxy) {
|
|
12442
|
+
this.baseUrl = slApiUrl || "";
|
|
12443
|
+
this.headers = {};
|
|
12444
|
+
} else {
|
|
12445
|
+
this.baseUrl = apiUrl || process.env.STACKS_NODE_RPC_URL || "http://localhost:3999";
|
|
12446
|
+
this.headers = apiKey ? { "x-api-key": apiKey } : {};
|
|
12450
12447
|
}
|
|
12451
12448
|
}
|
|
12449
|
+
async ensureProxy() {
|
|
12450
|
+
if (!this.useProxy || this.baseUrl)
|
|
12451
|
+
return;
|
|
12452
|
+
const config = await loadConfig();
|
|
12453
|
+
this.baseUrl = resolveApiUrl(config);
|
|
12454
|
+
this.headers = authHeaders(config);
|
|
12455
|
+
}
|
|
12452
12456
|
async fetchWithErrorHandling(url, resourceType, resourceId) {
|
|
12453
12457
|
try {
|
|
12454
12458
|
const response2 = await gotWithRetry(url, {
|
|
@@ -12457,30 +12461,38 @@ class StacksApiClient {
|
|
|
12457
12461
|
});
|
|
12458
12462
|
return response2.body;
|
|
12459
12463
|
} catch (error2) {
|
|
12464
|
+
if (error2.response?.statusCode === 401) {
|
|
12465
|
+
throw new Error("Authentication required. Run: secondlayer auth login");
|
|
12466
|
+
}
|
|
12460
12467
|
if (error2.response?.statusCode === 404) {
|
|
12461
12468
|
throw new Error(`${resourceType} not found: ${resourceId}`);
|
|
12462
12469
|
}
|
|
12463
|
-
if (error2.response?.statusCode === 429) {
|
|
12464
|
-
throw new Error("Rate limited. Please provide an API key in your config.");
|
|
12465
|
-
}
|
|
12466
12470
|
throw new Error(`Failed to fetch ${resourceType.toLowerCase()}: ${error2.message}`);
|
|
12467
12471
|
}
|
|
12468
12472
|
}
|
|
12469
12473
|
async getContractInfo(contractId) {
|
|
12474
|
+
await this.ensureProxy();
|
|
12475
|
+
if (this.useProxy) {
|
|
12476
|
+
const url2 = `${this.baseUrl}/api/node/contracts/${contractId}/abi`;
|
|
12477
|
+
return this.fetchWithErrorHandling(url2, "Contract", contractId);
|
|
12478
|
+
}
|
|
12470
12479
|
const { address, contractName } = parseContractId(contractId);
|
|
12471
12480
|
const url = `${this.baseUrl}/v2/contracts/interface/${address}/${contractName}`;
|
|
12472
12481
|
return this.fetchWithErrorHandling(url, "Contract", contractId);
|
|
12473
12482
|
}
|
|
12474
12483
|
async getContractSource(contractId) {
|
|
12475
12484
|
const { address, contractName } = parseContractId(contractId);
|
|
12476
|
-
const
|
|
12485
|
+
const rpcUrl = process.env.STACKS_NODE_RPC_URL || this.baseUrl;
|
|
12486
|
+
const url = `${rpcUrl}/v2/contracts/source/${address}/${contractName}`;
|
|
12477
12487
|
const data = await this.fetchWithErrorHandling(url, "Contract source", contractId);
|
|
12478
12488
|
return data.source;
|
|
12479
12489
|
}
|
|
12480
12490
|
}
|
|
12481
|
-
var gotWithRetry
|
|
12491
|
+
var gotWithRetry;
|
|
12482
12492
|
var init_api = __esm(() => {
|
|
12483
12493
|
init_source3();
|
|
12494
|
+
init_config();
|
|
12495
|
+
init_api_client();
|
|
12484
12496
|
gotWithRetry = source_default2.extend({
|
|
12485
12497
|
timeout: { request: 30000 },
|
|
12486
12498
|
retry: {
|
|
@@ -12490,11 +12502,6 @@ var init_api = __esm(() => {
|
|
|
12490
12502
|
calculateDelay: ({ attemptCount }) => attemptCount * 1000
|
|
12491
12503
|
}
|
|
12492
12504
|
});
|
|
12493
|
-
HIRO_URLS = {
|
|
12494
|
-
mainnet: "https://api.hiro.so",
|
|
12495
|
-
testnet: "https://api.testnet.hiro.so",
|
|
12496
|
-
devnet: "http://localhost:3999"
|
|
12497
|
-
};
|
|
12498
12505
|
});
|
|
12499
12506
|
|
|
12500
12507
|
// src/utils/network.ts
|
|
@@ -32275,7 +32282,7 @@ function deriveContractName(filePath) {
|
|
|
32275
32282
|
const basename = path10.basename(filePath, ".clar");
|
|
32276
32283
|
return basename.replace(/[-_](.)/g, (_2, char) => char.toUpperCase()).replace(/^(.)/, (_2, char) => char.toLowerCase()).replace(/^\d/, "_$&");
|
|
32277
32284
|
}
|
|
32278
|
-
async function buildConfigFromInputs(parsedInputs, outPath, apiKey, defaultAddress
|
|
32285
|
+
async function buildConfigFromInputs(parsedInputs, outPath, apiKey, defaultAddress) {
|
|
32279
32286
|
const contracts = [];
|
|
32280
32287
|
const deployer = defaultAddress || DEFAULT_DEVNET_ADDRESS;
|
|
32281
32288
|
if (parsedInputs.files.length > 0 && !defaultAddress) {
|
|
@@ -32297,7 +32304,7 @@ async function buildConfigFromInputs(parsedInputs, outPath, apiKey, defaultAddre
|
|
|
32297
32304
|
const { address, contractName } = parseContractId(contractId);
|
|
32298
32305
|
const network = inferNetwork(address) ?? "mainnet";
|
|
32299
32306
|
try {
|
|
32300
|
-
const apiClient = new StacksApiClient(network, apiKey
|
|
32307
|
+
const apiClient = new StacksApiClient(network, apiKey);
|
|
32301
32308
|
const contractInfo = await apiClient.getContractInfo(contractId);
|
|
32302
32309
|
const abi = parseApiResponse(contractInfo);
|
|
32303
32310
|
const name = toCamelCase7(contractName);
|
|
@@ -32340,8 +32347,7 @@ No .clar files or contract addresses matched the provided inputs`));
|
|
|
32340
32347
|
process.exit(1);
|
|
32341
32348
|
}
|
|
32342
32349
|
const apiKey = options3.apiKey || process.env.HIRO_API_KEY;
|
|
32343
|
-
|
|
32344
|
-
config = await buildConfigFromInputs(parsedInputs, options3.out, apiKey, undefined, cliConfig.nodeRpcUrl);
|
|
32350
|
+
config = await buildConfigFromInputs(parsedInputs, options3.out, apiKey);
|
|
32345
32351
|
} else {
|
|
32346
32352
|
config = await loadConfig2(options3.config);
|
|
32347
32353
|
}
|
|
@@ -32470,7 +32476,6 @@ var import_fast_glob, DEFAULT_DEVNET_ADDRESS = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZ
|
|
|
32470
32476
|
var init_generate = __esm(() => {
|
|
32471
32477
|
init_source4();
|
|
32472
32478
|
init_config2();
|
|
32473
|
-
init_config();
|
|
32474
32479
|
init_api();
|
|
32475
32480
|
init_clarity();
|
|
32476
32481
|
init_contract();
|
|
@@ -32547,7 +32552,7 @@ var {
|
|
|
32547
32552
|
// package.json
|
|
32548
32553
|
var package_default = {
|
|
32549
32554
|
name: "@secondlayer/cli",
|
|
32550
|
-
version: "1.6.
|
|
32555
|
+
version: "1.6.3",
|
|
32551
32556
|
description: "CLI for streams, subgraphs, and real-time blockchain indexing on Stacks",
|
|
32552
32557
|
type: "module",
|
|
32553
32558
|
bin: {
|
|
@@ -35407,11 +35412,12 @@ Stopped watching.`);
|
|
|
35407
35412
|
write: false
|
|
35408
35413
|
});
|
|
35409
35414
|
const handlerCode = new TextDecoder().decode(buildResult.outputFiles[0].contents);
|
|
35415
|
+
const { sourceKey } = await import("@secondlayer/subgraphs");
|
|
35410
35416
|
const result = await deploySubgraphApi({
|
|
35411
35417
|
name: def.name,
|
|
35412
35418
|
version: def.version,
|
|
35413
35419
|
description: def.description,
|
|
35414
|
-
sources: def.sources,
|
|
35420
|
+
sources: def.sources.map(sourceKey),
|
|
35415
35421
|
schema: def.schema,
|
|
35416
35422
|
handlerCode,
|
|
35417
35423
|
reindex: options2.reindex
|
|
@@ -35596,10 +35602,9 @@ ${rows.length} row(s)`));
|
|
|
35596
35602
|
}
|
|
35597
35603
|
const outPath = resolve(options2.output);
|
|
35598
35604
|
const network = inferNetwork(contractAddress) ?? "mainnet";
|
|
35599
|
-
const config = await loadConfig();
|
|
35600
35605
|
const apiKey = options2.apiKey ?? process.env.HIRO_API_KEY;
|
|
35601
35606
|
info(`Fetching ABI for ${contractAddress}...`);
|
|
35602
|
-
const client = new StacksApiClient(network, apiKey
|
|
35607
|
+
const client = new StacksApiClient(network, apiKey);
|
|
35603
35608
|
const contractInfo = await client.getContractInfo(contractAddress);
|
|
35604
35609
|
const abi = parseApiResponse(contractInfo);
|
|
35605
35610
|
info(`Generating scaffold...`);
|
|
@@ -36778,5 +36783,5 @@ registerWhoamiCommand(program);
|
|
|
36778
36783
|
registerReceiverCommand(program);
|
|
36779
36784
|
program.parse();
|
|
36780
36785
|
|
|
36781
|
-
//# debugId=
|
|
36786
|
+
//# debugId=02594D245228FE5164756E2164756E21
|
|
36782
36787
|
//# sourceMappingURL=cli.js.map
|