Skip to content

Conversation

@roderik
Copy link
Member

@roderik roderik commented Oct 1, 2024

Summary by Sourcery

Add a new JavaScript client to the SettleMint SDK, enabling integration with SettleMint services. Update the build process to publish the SDK package to npm and enhance the configuration schema by removing an unnecessary field. Include documentation for the new package.

New Features:

  • Introduce a new JavaScript client for the SettleMint SDK, providing a structured way to interact with various SettleMint services such as blockchain networks, nodes, middleware, integration tools, storage, private keys, insights, and custom deployments.

Enhancements:

  • Remove the 'framework' field from the main configuration schema, simplifying the configuration structure.

Build:

  • Add a new step in the GitHub Actions workflow to publish the JavaScript SDK package to npm, ensuring the package is publicly accessible.

Documentation:

  • Add a README file for the JavaScript package, providing an overview of the SettleMint SDK, links to documentation, and other resources.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 1, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new JavaScript client for the SettleMint SDK. The changes include adding new files for the client implementation, schemas, and configuration, as well as updating the build workflow to publish the new JS package.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Cache
    participant API
    Client->>Cache: Check for cached data
    alt Data in cache
        Cache-->>Client: Return cached data
    else Data not in cache
        Client->>API: Fetch data
        API-->>Client: Return data
        Client->>Cache: Store data in cache
    end
Loading

File-Level Changes

Change Details Files
Implement new JavaScript client for SettleMint SDK
  • Create main client file with resource handlers
  • Implement caching mechanism for API responses
  • Add schemas for platform return values
  • Create shared schema definitions
  • Implement validation utility
  • Define client environment schema
packages/js/src/settlemint.ts
packages/js/src/helpers/cache.ts
packages/js/src/schemas/platform-return-values.ts
packages/js/src/schemas/shared.ts
packages/js/src/schemas/validator.ts
packages/js/src/schemas/settlemint-client-env.ts
Update build workflow to publish new JS package
  • Add step to publish SDK JS package using npm-publish action
.github/workflows/build.yml
Add configuration files for TypeScript and build tools
  • Create tsconfig.json for TypeScript configuration
  • Add tsup.config.ts for build configuration
  • Include knip.json for dependency management
packages/js/tsconfig.json
packages/js/tsup.config.ts
packages/js/knip.json
Add README for the new JS package
  • Create README.md with package information and badges
packages/js/README.md
Remove 'framework' field from ConfigSchema
  • Delete 'framework' property from ConfigSchema object
packages/config/src/schemas.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the feat New feature label Oct 1, 2024
@github-actions
Copy link

github-actions bot commented Oct 1, 2024

📦 Packages

Package Version
SDK Cli @settlemint/sdk-cli@0.4.31-pr83fc356
SDK Config @settlemint/sdk-config@0.4.31-pr83fc356
SDK Next @settlemint/sdk-next@0.4.31-pr83fc356

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @roderik - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the cache size and TTL in DEFAULT_OPTIONS configurable for more flexibility.
  • Please provide context for the removal of the 'framework' field from ConfigSchema. Are there any implications for existing code?
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 2 issues found

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

token: ${{ secrets.NPM_TOKEN }}
package: ./packages/js/package.json
access: public
provenance: false
Copy link
Contributor

Choose a reason for hiding this comment

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

🚨 suggestion (security): Consider enabling provenance for enhanced package security

Enabling provenance can provide better security guarantees for your published package. If there's a specific reason for disabling it, please document this decision.

Suggested change
provenance: false
provenance: true

@@ -0,0 +1,144 @@
import { EthereumAddressSchema, EthereumPublicKeySchema } from "@/schemas/shared";
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider splitting schemas into separate files for better maintainability

As the number of schemas grows, it might be beneficial to split them into separate files based on their functionality or domain. This could improve readability and make maintenance easier.

import { EthereumAddressSchema, EthereumPublicKeySchema } from "@/schemas/ethereum";
import { UniqueNameSchema, UrlSchema } from "./shared";
import { z } from "zod";

}

// biome-ignore lint/suspicious/noExplicitAny: the setters and getters handle the type safety
const cacheStore: Map<string, CacheEntry<any>> = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider using a more robust caching solution for production

While the current implementation is a good start, for a production-grade SDK, consider using a well-tested caching library or implementing a more sophisticated caching strategy. This could include features like persistence across sessions or distributed caching for multi-instance deployments.

import NodeCache from 'node-cache';

const cacheStore = new NodeCache({
  stdTTL: 600, // 10 minutes default TTL
  checkperiod: 120, // Check for expired keys every 2 minutes
  useClones: false, // For better performance
});

<br />
</div>

## Getting started
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (documentation): Consider adding content to the 'Getting started' section

This section could include basic installation instructions, a simple usage example, or links to more detailed guides.

## Getting started

### Installation
```bash
npm install @your-package-name

Basic usage

import { someFunction } from '@your-package-name';

// Use the package
someFunction();

For more detailed guides, see our documentation.

<div align="center">
<a href="https://console.settlemint.com/documentation/">Documentation</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://discord.com/invite/Mt5yqFrey9">Discord</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (documentation): Consider using a permanent Discord invite link

If possible, it might be beneficial to use a permanent invite link specific to the SettleMint community. This ensures the link won't expire.

Suggested change
<a href="https://discord.com/invite/Mt5yqFrey9">Discord</a>
<a href="https://discord.gg/settlemint">Discord</a>

Comment on lines 76 to 99
const resources = {
blockchainNetwork: createResourceHandler<BlockchainNetworkReturnValue>(
"blockchain-network",
BlockchainNetworkReturnValueSchema,
),
blockchainNode: createResourceHandler<BlockchainNodeReturnValue>(
"blockchain-node",
BlockchainNodeReturnValueSchema,
),
middleware: createResourceHandler<MiddlewareReturnValue>("middleware", MiddlewareReturnValueSchema),
integrationTool: createResourceHandler<IntegrationToolReturnValue>(
"integration-tool",
IntegrationToolReturnValueSchema,
),
storage: createResourceHandler<StorageReturnValue>("storage", StorageReturnValueSchema),
privateKey: createResourceHandler<PrivateKeyReturnValue>("private-key", PrivateKeyReturnValueSchema),
insights: createResourceHandler<InsightsReturnValue>("insights", InsightsReturnValueSchema),
customDeployment: createResourceHandler<CustomDeploymentReturnValue>(
"custom-deployment",
CustomDeploymentReturnValueSchema,
),
};

return resources;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Suggested change
const resources = {
blockchainNetwork: createResourceHandler<BlockchainNetworkReturnValue>(
"blockchain-network",
BlockchainNetworkReturnValueSchema,
),
blockchainNode: createResourceHandler<BlockchainNodeReturnValue>(
"blockchain-node",
BlockchainNodeReturnValueSchema,
),
middleware: createResourceHandler<MiddlewareReturnValue>("middleware", MiddlewareReturnValueSchema),
integrationTool: createResourceHandler<IntegrationToolReturnValue>(
"integration-tool",
IntegrationToolReturnValueSchema,
),
storage: createResourceHandler<StorageReturnValue>("storage", StorageReturnValueSchema),
privateKey: createResourceHandler<PrivateKeyReturnValue>("private-key", PrivateKeyReturnValueSchema),
insights: createResourceHandler<InsightsReturnValue>("insights", InsightsReturnValueSchema),
customDeployment: createResourceHandler<CustomDeploymentReturnValue>(
"custom-deployment",
CustomDeploymentReturnValueSchema,
),
};
return resources;
return {
blockchainNetwork: createResourceHandler<BlockchainNetworkReturnValue>(
"blockchain-network",
BlockchainNetworkReturnValueSchema,
),
blockchainNode: createResourceHandler<BlockchainNodeReturnValue>(
"blockchain-node",
BlockchainNodeReturnValueSchema,
),
middleware: createResourceHandler<MiddlewareReturnValue>("middleware", MiddlewareReturnValueSchema),
integrationTool: createResourceHandler<IntegrationToolReturnValue>(
"integration-tool",
IntegrationToolReturnValueSchema,
),
storage: createResourceHandler<StorageReturnValue>("storage", StorageReturnValueSchema),
privateKey: createResourceHandler<PrivateKeyReturnValue>("private-key", PrivateKeyReturnValueSchema),
insights: createResourceHandler<InsightsReturnValue>("insights", InsightsReturnValueSchema),
customDeployment: createResourceHandler<CustomDeploymentReturnValue>(
"custom-deployment",
CustomDeploymentReturnValueSchema,
),
};


ExplanationSomething that we often see in people's code is assigning to a result variable
and then immediately returning it.

Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.

Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.

@roderik roderik merged commit e4b2620 into main Oct 2, 2024
@roderik roderik deleted the feat/simplify branch October 2, 2024 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants