@secondlayer/cli 0.3.10 → 1.1.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 CHANGED
@@ -16,7 +16,7 @@ interface ContractSource {
16
16
  */
17
17
  name?: string;
18
18
  }
19
- interface StacksConfig {
19
+ interface SecondLayerConfig {
20
20
  /**
21
21
  * Contracts to generate interfaces for (optional - plugins can provide these)
22
22
  */
@@ -57,7 +57,7 @@ interface ResolvedContract {
57
57
  /**
58
58
  * Core plugin interface that all plugins must implement
59
59
  */
60
- interface StacksCodegenPlugin {
60
+ interface SecondLayerPlugin {
61
61
  /** Plugin name (should be unique) */
62
62
  name: string;
63
63
  /** Plugin version */
@@ -80,13 +80,13 @@ interface StacksCodegenPlugin {
80
80
  /**
81
81
  * User configuration (before plugin transformations)
82
82
  */
83
- type UserConfig = StacksConfig;
83
+ type UserConfig = SecondLayerConfig;
84
84
  /**
85
85
  * Resolved configuration (after plugin transformations)
86
86
  */
87
- interface ResolvedConfig extends StacksConfig {
87
+ interface ResolvedConfig extends SecondLayerConfig {
88
88
  /** Resolved plugins array */
89
- plugins: StacksCodegenPlugin[];
89
+ plugins: SecondLayerPlugin[];
90
90
  }
91
91
  /**
92
92
  * Contract configuration that can be transformed by plugins
@@ -187,7 +187,7 @@ interface PluginUtils {
187
187
  /**
188
188
  * Plugin factory function type for creating plugins with options
189
189
  */
190
- type PluginFactory<TOptions = any> = (options?: TOptions) => StacksCodegenPlugin;
190
+ type PluginFactory<TOptions = any> = (options?: TOptions) => SecondLayerPlugin;
191
191
  /**
192
192
  * Plugin options base interface
193
193
  */
@@ -224,11 +224,11 @@ declare class PluginManager {
224
224
  /**
225
225
  * Register a plugin
226
226
  */
227
- register(plugin: StacksCodegenPlugin): void;
227
+ register(plugin: SecondLayerPlugin): void;
228
228
  /**
229
229
  * Get all registered plugins
230
230
  */
231
- getPlugins(): StacksCodegenPlugin[];
231
+ getPlugins(): SecondLayerPlugin[];
232
232
  /**
233
233
  * Transform user config through all plugins
234
234
  */
@@ -240,7 +240,7 @@ declare class PluginManager {
240
240
  /**
241
241
  * Execute lifecycle hooks
242
242
  */
243
- executeHook(hookName: keyof StacksCodegenPlugin, context: any): Promise<void>;
243
+ executeHook(hookName: keyof SecondLayerPlugin, context: any): Promise<void>;
244
244
  /**
245
245
  * Execute generation phase with full context
246
246
  */
@@ -303,6 +303,8 @@ interface ActionsPluginOptions {
303
303
  excludeFunctions?: string[];
304
304
  /** Enable debug output */
305
305
  debug?: boolean;
306
+ /** Environment variable name for default sender key (default: "STX_SENDER_KEY") */
307
+ senderKeyEnv?: string;
306
308
  }
307
309
  /**
308
310
  * Actions plugin factory
@@ -352,5 +354,5 @@ declare function filterByOptions<T extends {
352
354
  /**
353
355
  * Utility function to create a simple plugin
354
356
  */
355
- declare function createPlugin(name: string, version: string, implementation: Partial<StacksCodegenPlugin>): StacksCodegenPlugin;
356
- export { testing, react, hasClarinetProject, filterByOptions, createPlugin, clarinet, actions, TestingPluginOptions, StacksCodegenPlugin, ReactPluginOptions, PluginUtils, PluginOptions, PluginManager, PluginFactory, PluginContext, Logger, GenerateContext, ClarinetPluginOptions, BasePluginOptions, ActionsPluginOptions };
357
+ declare function createPlugin(name: string, version: string, implementation: Partial<SecondLayerPlugin>): SecondLayerPlugin;
358
+ export { testing, react, hasClarinetProject, filterByOptions, createPlugin, clarinet, actions, TestingPluginOptions, SecondLayerPlugin, ReactPluginOptions, PluginUtils, PluginOptions, PluginManager, PluginFactory, PluginContext, Logger, GenerateContext, ClarinetPluginOptions, BasePluginOptions, ActionsPluginOptions };
package/dist/index.js CHANGED
@@ -1174,6 +1174,7 @@ function generateReadHelpers(contract, options) {
1174
1174
  function generateWriteHelpers(contract, options) {
1175
1175
  const { abi, name } = contract;
1176
1176
  const functions = abi.functions || [];
1177
+ const envVarName = options.senderKeyEnv ?? "STX_SENDER_KEY";
1177
1178
  const publicFunctions = functions.filter((f) => f.access === "public");
1178
1179
  if (publicFunctions.length === 0) {
1179
1180
  return "";
@@ -1194,8 +1195,7 @@ function generateWriteHelpers(contract, options) {
1194
1195
  const methodName = toCamelCase4(func.name);
1195
1196
  const argsSignature = generateArgsSignature(func.args);
1196
1197
  const clarityArgs = generateClarityArgs(func.args, name);
1197
- return `async ${methodName}(${argsSignature}options: {
1198
- senderKey: string;
1198
+ return `async ${methodName}(${argsSignature}senderKey?: string, options?: {
1199
1199
  network?: 'mainnet' | 'testnet' | 'devnet';
1200
1200
  fee?: string | number | undefined;
1201
1201
  nonce?: bigint;
@@ -1203,14 +1203,18 @@ function generateWriteHelpers(contract, options) {
1203
1203
  postConditions?: PostCondition[];
1204
1204
  validateWithAbi?: boolean;
1205
1205
  }) {
1206
- const { senderKey, network = 'mainnet', ...txOptions } = options;
1207
-
1206
+ const resolvedSenderKey = senderKey ?? process.env.${envVarName};
1207
+ if (!resolvedSenderKey) {
1208
+ throw new Error('senderKey required: pass as argument or set ${envVarName} env var');
1209
+ }
1210
+ const { network = 'mainnet', ...txOptions } = options ?? {};
1211
+
1208
1212
  return await makeContractCall({
1209
1213
  contractAddress: '${contract.address}',
1210
1214
  contractName: '${contract.contractName}',
1211
1215
  functionName: '${func.name}',
1212
1216
  functionArgs: [${clarityArgs}],
1213
- senderKey,
1217
+ senderKey: resolvedSenderKey,
1214
1218
  network,
1215
1219
  validateWithAbi: true,
1216
1220
  ...txOptions
@@ -1331,16 +1335,16 @@ ${indentedHelpersCode}
1331
1335
  init_format();
1332
1336
  async function generateProvider() {
1333
1337
  const code = `/**
1334
- * Generated Stacks React Provider
1338
+ * Generated SecondLayer React Provider
1335
1339
  * DO NOT EDIT MANUALLY
1336
1340
  */
1337
1341
 
1338
1342
  import React, { createContext, useContext } from 'react'
1339
1343
 
1340
1344
  /**
1341
- * Stacks configuration interface
1345
+ * SecondLayer configuration interface
1342
1346
  */
1343
- export interface StacksReactConfig {
1347
+ export interface SecondLayerReactConfig {
1344
1348
  /**
1345
1349
  * Network to use for API calls
1346
1350
  */
@@ -1365,21 +1369,21 @@ export interface StacksReactConfig {
1365
1369
  /**
1366
1370
  * Provider component props
1367
1371
  */
1368
- export interface StacksProviderProps {
1372
+ export interface SecondLayerProviderProps {
1369
1373
  children: React.ReactNode
1370
- config: StacksReactConfig
1374
+ config: SecondLayerReactConfig
1371
1375
  }
1372
1376
 
1373
1377
  /**
1374
- * React context for Stacks configuration
1378
+ * React context for SecondLayer configuration
1375
1379
  */
1376
- const StacksContext = createContext<StacksReactConfig | undefined>(undefined)
1377
- StacksContext.displayName = 'StacksContext'
1380
+ const SecondLayerContext = createContext<SecondLayerReactConfig | undefined>(undefined)
1381
+ SecondLayerContext.displayName = 'SecondLayerContext'
1378
1382
 
1379
1383
  /**
1380
- * Create a Stacks React configuration with defaults
1384
+ * Create a SecondLayer React configuration with defaults
1381
1385
  */
1382
- export function createStacksConfig(config: StacksReactConfig): StacksReactConfig {
1386
+ export function createSecondLayerConfig(config: SecondLayerReactConfig): SecondLayerReactConfig {
1383
1387
  return {
1384
1388
  network: config.network,
1385
1389
  apiKey: config.apiKey,
@@ -1389,31 +1393,31 @@ export function createStacksConfig(config: StacksReactConfig): StacksReactConfig
1389
1393
  }
1390
1394
 
1391
1395
  /**
1392
- * Provider component that makes Stacks configuration available to hooks
1396
+ * Provider component that makes SecondLayer configuration available to hooks
1393
1397
  */
1394
- export function StacksProvider({ children, config }: StacksProviderProps) {
1395
- const resolvedConfig = createStacksConfig(config)
1398
+ export function SecondLayerProvider({ children, config }: SecondLayerProviderProps) {
1399
+ const resolvedConfig = createSecondLayerConfig(config)
1396
1400
 
1397
1401
  return (
1398
- <StacksContext.Provider value={resolvedConfig}>
1402
+ <SecondLayerContext.Provider value={resolvedConfig}>
1399
1403
  {children}
1400
- </StacksContext.Provider>
1404
+ </SecondLayerContext.Provider>
1401
1405
  )
1402
1406
  }
1403
1407
 
1404
1408
  /**
1405
- * Hook to access the Stacks configuration
1409
+ * Hook to access the SecondLayer configuration
1406
1410
  */
1407
- export function useStacksConfig(): StacksReactConfig {
1408
- const context = useContext(StacksContext)
1409
-
1411
+ export function useSecondLayerConfig(): SecondLayerReactConfig {
1412
+ const context = useContext(SecondLayerContext)
1413
+
1410
1414
  if (context === undefined) {
1411
1415
  throw new Error(
1412
- 'useStacksConfig must be used within a StacksProvider. ' +
1413
- 'Make sure to wrap your app with <StacksProvider config={{...}}>'
1416
+ 'useSecondLayerConfig must be used within a SecondLayerProvider. ' +
1417
+ 'Make sure to wrap your app with <SecondLayerProvider config={{...}}>'
1414
1418
  )
1415
1419
  }
1416
-
1420
+
1417
1421
  return context
1418
1422
  }`;
1419
1423
  return formatCode(code);
@@ -1440,7 +1444,7 @@ async function generateGenericHooks(excludeList = []) {
1440
1444
  const hooksToGenerate = GENERIC_HOOKS.filter((hookName) => !excludeList.includes(hookName));
1441
1445
  const imports = `import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
1442
1446
  import { useState, useCallback } from 'react'
1443
- import { useStacksConfig } from './provider'
1447
+ import { useSecondLayerConfig } from './provider'
1444
1448
  import { connect, disconnect, isConnected, request, openContractCall as stacksOpenContractCall, openSTXTransfer, openSignatureRequestPopup, openContractDeploy } from '@stacks/connect'
1445
1449
  import { Cl, validateStacksAddress } from '@stacks/transactions'
1446
1450
  import type { PostCondition } from '@stacks/transactions'
@@ -1490,7 +1494,7 @@ function generateGenericHook(hookName) {
1490
1494
  switch (hookName) {
1491
1495
  case "useAccount":
1492
1496
  return `export function useAccount() {
1493
- const config = useStacksConfig()
1497
+ const config = useSecondLayerConfig()
1494
1498
 
1495
1499
  return useQuery({
1496
1500
  queryKey: ['stacks-account', config.network],
@@ -1633,7 +1637,7 @@ function generateGenericHook(hookName) {
1633
1637
  }`;
1634
1638
  case "useNetwork":
1635
1639
  return `export function useNetwork() {
1636
- const config = useStacksConfig()
1640
+ const config = useSecondLayerConfig()
1637
1641
 
1638
1642
  return useQuery({
1639
1643
  queryKey: ['stacks-network', config.network],
@@ -1660,7 +1664,7 @@ function generateGenericHook(hookName) {
1660
1664
  }`;
1661
1665
  case "useContract":
1662
1666
  return `export function useContract() {
1663
- const config = useStacksConfig()
1667
+ const config = useSecondLayerConfig()
1664
1668
  const queryClient = useQueryClient()
1665
1669
  const [isRequestPending, setIsRequestPending] = useState(false)
1666
1670
 
@@ -1955,7 +1959,7 @@ function generateGenericHook(hookName) {
1955
1959
  network?: 'mainnet' | 'testnet' | 'devnet';
1956
1960
  enabled?: boolean;
1957
1961
  }) {
1958
- const config = useStacksConfig()
1962
+ const config = useSecondLayerConfig()
1959
1963
 
1960
1964
  return useQuery<TResult>({
1961
1965
  queryKey: ['read-contract', params.contractAddress, params.contractName, params.functionName, params.args, params.network || config.network],
@@ -1993,7 +1997,7 @@ function generateGenericHook(hookName) {
1993
1997
  }`;
1994
1998
  case "useTransaction":
1995
1999
  return `export function useTransaction(txId?: string) {
1996
- const config = useStacksConfig()
2000
+ const config = useSecondLayerConfig()
1997
2001
 
1998
2002
  return useQuery({
1999
2003
  queryKey: ['transaction', txId, config.network],
@@ -2007,7 +2011,7 @@ function generateGenericHook(hookName) {
2007
2011
  }`;
2008
2012
  case "useBlock":
2009
2013
  return `export function useBlock(height?: number) {
2010
- const config = useStacksConfig()
2014
+ const config = useSecondLayerConfig()
2011
2015
 
2012
2016
  return useQuery({
2013
2017
  queryKey: ['block', height, config.network],
@@ -2021,7 +2025,7 @@ function generateGenericHook(hookName) {
2021
2025
  }`;
2022
2026
  case "useAccountTransactions":
2023
2027
  return `export function useAccountTransactions(address?: string) {
2024
- const config = useStacksConfig()
2028
+ const config = useSecondLayerConfig()
2025
2029
 
2026
2030
  return useQuery({
2027
2031
  queryKey: ['account-transactions', address, config.network],
@@ -2035,7 +2039,7 @@ function generateGenericHook(hookName) {
2035
2039
  }`;
2036
2040
  case "useWaitForTransaction":
2037
2041
  return `export function useWaitForTransaction(txId?: string) {
2038
- const config = useStacksConfig()
2042
+ const config = useSecondLayerConfig()
2039
2043
 
2040
2044
  return useQuery({
2041
2045
  queryKey: ['wait-for-transaction', txId, config.network],
@@ -2059,7 +2063,7 @@ function generateGenericHook(hookName) {
2059
2063
  }`;
2060
2064
  case "useOpenSTXTransfer":
2061
2065
  return `export function useOpenSTXTransfer() {
2062
- const config = useStacksConfig()
2066
+ const config = useSecondLayerConfig()
2063
2067
  const queryClient = useQueryClient()
2064
2068
 
2065
2069
  const mutation = useMutation({
@@ -2125,7 +2129,7 @@ function generateGenericHook(hookName) {
2125
2129
  }`;
2126
2130
  case "useSignMessage":
2127
2131
  return `export function useSignMessage() {
2128
- const config = useStacksConfig()
2132
+ const config = useSecondLayerConfig()
2129
2133
 
2130
2134
  const mutation = useMutation({
2131
2135
  mutationFn: async (params: {
@@ -2180,7 +2184,7 @@ function generateGenericHook(hookName) {
2180
2184
  }`;
2181
2185
  case "useDeployContract":
2182
2186
  return `export function useDeployContract() {
2183
- const config = useStacksConfig()
2187
+ const config = useSecondLayerConfig()
2184
2188
  const queryClient = useQueryClient()
2185
2189
 
2186
2190
  const mutation = useMutation({
@@ -2299,7 +2303,7 @@ function generateObjectArgs(args) {
2299
2303
  async function generateContractHooks(contracts, excludeList = []) {
2300
2304
  const imports = `import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
2301
2305
  import { useCallback } from 'react'
2302
- import { useStacksConfig } from './provider'
2306
+ import { useSecondLayerConfig } from './provider'
2303
2307
  import { request, openContractCall as stacksOpenContractCall } from '@stacks/connect'
2304
2308
  import type { PostCondition } from '@stacks/transactions'
2305
2309
  import { ${contracts.map((c) => c.name).join(", ")} } from './contracts'`;
@@ -2375,7 +2379,7 @@ function generateReadHook(func, contractName) {
2375
2379
  const enabledParam = func.args.length > 0 ? ", options?: { enabled?: boolean }" : "options?: { enabled?: boolean }";
2376
2380
  const returnType = clarityTypeToTS(func.outputs);
2377
2381
  return `export function ${hookName}(${argsSignature}${enabledParam}) {
2378
- const config = useStacksConfig()
2382
+ const config = useSecondLayerConfig()
2379
2383
 
2380
2384
  return useQuery<${returnType}>({
2381
2385
  queryKey: ['${func.name}', ${contractName}.address, ${generateQueryKeyArgs(func.args)}],
@@ -2392,7 +2396,7 @@ function generateWriteHook(func, contractName) {
2392
2396
  const hookName = `use${capitalize(contractName)}${capitalize(toCamelCase5(func.name))}`;
2393
2397
  const argsType = generateArgsType(func.args);
2394
2398
  return `export function ${hookName}() {
2395
- const config = useStacksConfig()
2399
+ const config = useSecondLayerConfig()
2396
2400
  const queryClient = useQueryClient()
2397
2401
 
2398
2402
  const mutation = useMutation({
@@ -2485,7 +2489,7 @@ function generateMapHook(map, contractVarName, _address, _contractName) {
2485
2489
  const keyType = clarityTypeToTS(map.key);
2486
2490
  const valueType = clarityTypeToTS(map.value);
2487
2491
  return `export function ${hookName}(key: ${keyType}, options?: { enabled?: boolean }) {
2488
- const config = useStacksConfig()
2492
+ const config = useSecondLayerConfig()
2489
2493
 
2490
2494
  return useQuery<${valueType} | null>({
2491
2495
  queryKey: ['${contractVarName}', '${map.name}', 'map', key, config.network],
@@ -2500,7 +2504,7 @@ function generateVarHook(variable, contractVarName, _address, _contractName) {
2500
2504
  const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase5(variable.name))}`;
2501
2505
  const valueType = clarityTypeToTS(variable.type);
2502
2506
  return `export function ${hookName}(options?: { enabled?: boolean }) {
2503
- const config = useStacksConfig()
2507
+ const config = useSecondLayerConfig()
2504
2508
 
2505
2509
  return useQuery<${valueType}>({
2506
2510
  queryKey: ['${contractVarName}', '${variable.name}', 'var', config.network],
@@ -2515,7 +2519,7 @@ function generateConstantHook(constant, contractVarName, _address, _contractName
2515
2519
  const hookName = `use${capitalize(contractVarName)}${capitalize(toCamelCase5(constant.name))}`;
2516
2520
  const valueType = clarityTypeToTS(constant.type);
2517
2521
  return `export function ${hookName}(options?: { enabled?: boolean }) {
2518
- const config = useStacksConfig()
2522
+ const config = useSecondLayerConfig()
2519
2523
 
2520
2524
  return useQuery<${valueType}>({
2521
2525
  queryKey: ['${contractVarName}', '${constant.name}', 'constant', config.network],
@@ -2979,5 +2983,5 @@ export {
2979
2983
  PluginManager
2980
2984
  };
2981
2985
 
2982
- //# debugId=FE7B5594AE67250064756E2164756E21
2986
+ //# debugId=DBBDDA8E89A55EA464756E2164756E21
2983
2987
  //# sourceMappingURL=index.js.map