Sync Node SDK with Go SDK: add missing types, credentials functions, and client getters
Some checks failed
Build and Test / build (16.x) (push) Failing after 15s
Build and Test / build (20.x) (push) Failing after 14s
Build and Test / build (18.x) (push) Failing after 16s

- Add remote field to SmartContractCreateRequest
- Add GrpcConnectionInfo interface and field on SmartContract
- Add addChain, setDefault, deleteChain credential functions
- Add getPublicId, getAuthKeyId, getEndpoint client accessors
- Fix expandPath to handle both $VAR and ${VAR} env var formats
- Improve saveConfig with better yaml.dump options and _rawContent tracking
This commit is contained in:
2026-03-17 10:50:43 -04:00
parent 5c7770be70
commit e6f95bc165
3 changed files with 82 additions and 5 deletions

View File

@@ -177,6 +177,27 @@ export class DragonchainClient {
});
}
/**
* Returns the public ID
*/
public getPublicId(): string {
return this.publicId;
}
/**
* Returns the auth key ID
*/
public getAuthKeyId(): string {
return this.authKeyId;
}
/**
* Returns the base URL endpoint
*/
public getEndpoint(): string {
return this.baseURL;
}
/**
* Performs a GET request
*/

View File

@@ -19,19 +19,23 @@ export interface ChainConfig {
}
/**
* Complete configuration structure
* Complete configuration structure.
* The _rawContent field stores the original YAML for re-saving unmodified configs.
*/
export interface Config {
default: string;
chains: ChainConfig[];
/** @internal Original YAML content, used to preserve formatting on re-save */
_rawContent?: string;
}
/**
* Expands file paths with home directory and environment variables
*/
function expandPath(filePath: string): string {
// Expand environment variables
let expanded = filePath.replace(/\$\{([^}]+)\}/g, (_, variable: string) => {
// Expand environment variables: ${VAR} and $VAR formats
let expanded = filePath.replace(/\$\{([^}]+)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_, braced, bare) => {
const variable = braced || bare;
return process.env[variable] || '';
});
@@ -62,6 +66,9 @@ export function loadConfig(filePath: string): Config {
throw new Error('Invalid config: missing or invalid chains array');
}
// Store raw content for formatting preservation on re-save
config._rawContent = fileContent;
return config;
}
@@ -75,6 +82,9 @@ export function loadConfigFromString(yamlContent: string): Config {
throw new Error('Invalid config: missing or invalid chains array');
}
// Store raw content for formatting preservation on re-save
config._rawContent = yamlContent;
return config;
}
@@ -100,10 +110,49 @@ export function listChains(config: Config): string[] {
}
/**
* Saves configuration to a YAML file
* Adds a chain configuration to the config
*/
export function addChain(config: Config, chain: ChainConfig): void {
config.chains.push(chain);
delete config._rawContent;
}
/**
* Sets the default chain by public ID
*/
export function setDefault(config: Config, publicId: string): void {
config.default = publicId;
delete config._rawContent;
}
/**
* Deletes a chain configuration by public ID.
* Throws if attempting to delete the default chain.
*/
export function deleteChain(config: Config, publicId: string): void {
if (publicId === config.default) {
throw new Error('cannot delete default chain');
}
config.chains = config.chains.filter((chain) => chain.publicId !== publicId);
delete config._rawContent;
}
/**
* Saves configuration to a YAML file.
* Strips internal _rawContent before serializing.
*/
export function saveConfig(config: Config, filePath: string): void {
const expandedPath = expandPath(filePath);
const yamlContent = yaml.dump(config);
// Strip internal field before dumping
const { _rawContent, ...configData } = config;
const yamlContent = yaml.dump(configData, {
lineWidth: -1, // No line wrapping
noRefs: true, // No YAML references
quotingType: "'", // Prefer single quotes
forceQuotes: false,
});
fs.writeFileSync(expandedPath, yamlContent, 'utf8');
}

View File

@@ -84,6 +84,7 @@ export interface SmartContractCreateRequest {
executionOrder: string;
environmentVariables?: Record<string, string>;
secrets?: Record<string, string>;
remote?: boolean;
}
export interface SmartContractUpdateRequest {
@@ -100,6 +101,11 @@ export interface SmartContractExecutionInfo {
executableHash?: string;
}
export interface GrpcConnectionInfo {
address: string;
apiKey?: string;
}
export interface SmartContract {
id: string;
created: number;
@@ -111,6 +117,7 @@ export interface SmartContract {
executionInfo?: SmartContractExecutionInfo;
envVars: Record<string, string>;
secrets: string[];
grpcConnectionInfo?: GrpcConnectionInfo;
}
// Block Types