Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli tool to setup the sdk and circle console #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

krzysu
Copy link
Contributor

@krzysu krzysu commented Dec 8, 2024

If somebody hasn't configured their circle console yet, please try this cli tool with

yarn dev --api-key TEST_API_KEY:[your_api_key]

Base automatically changed from circle-webapp-2 to main December 9, 2024 12:29
@krzysu krzysu force-pushed the sdk-setup-cli branch 3 times, most recently from 9f04775 to cb3cab0 Compare December 9, 2024 12:34
@krzysu krzysu requested review from jdevcs, avkos, danforbes and Muhammad-Altabba and removed request for jdevcs December 9, 2024 12:35
Copy link
Contributor

@danforbes danforbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of questions, but otherwise looks great - great documentation!

return false;
} catch (error) {
console.error('Error checking existing configuration:', error);
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this throw and propagate the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simply a check to verify if the file exists and contains the expected environment variables. It throws an error if the file doesn’t exist, which is fine for detecting the file’s presence. While reviewing this, I discovered another issue: the environment variable name was incorrect (CIRCLE_APP_ID instead of CIRCLE_API_KEY). I’ve fixed that.

In summary, this error doesn’t need to be propagated since its sole purpose is to check for the file’s existence.

Comment on lines 45 to 48
async initializeSdk(apiKey: string, secret: string): Promise<CircleSdk> {
console.log('Initializing Circle SDK...');
return new CircleSdk(apiKey, secret);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be async and return a Promise? Is this method even really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for context, that was my late night experiment with using AI agent to build something useful and I thought simple CLI tool is a good task for that 😄 . So I wasn't very strict with the results. I'm cleaning this up now, thanks for the review!

let envContent = '';
if (fs.existsSync(this.options.envPath)) {
envContent = fs.readFileSync(this.options.envPath, 'utf-8');
// Remove existing Circle config if any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that what we'd want to do in this situation? I guess this goes along with the comment I left regarding the checkExistingConfig function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid removing anything from local user settings. Instead, notify the user that the configuration failed and suggest checking the Circle console. I spent a significant amount of time investigating whether Circle configuration can be removed, but found no option to do so. The only available actions are rotating keys or resetting the cipher, both of which are not possible via the API.

@@ -2,8 +2,15 @@
"name": "web3-circle-sdk",
"version": "0.1.0",
"description": "Web3 Circle SDK",
"type": "module",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avkos can we have the sdk build and export setup for esm and cjs done asap (in main branch) as that impacts consuming it by other packages? I'm using only esm and I think we should aim to make ESM the default and commonjs as a fallback for legacy use. what do you think? cc @Muhammad-Altabba @jdevcs

@krzysu
Copy link
Contributor Author

krzysu commented Dec 10, 2024

@danforbes Alright, I think this PR is ready. I’ve tested detecting the .env file and writing a new one. The only step I couldn’t test is registerCiphertext and storing the recovery file (with the recovery content), as my Circle account is already set up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants