Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
10 changes: 7 additions & 3 deletions packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { printAsciiArt, printCancel, printIntro, printNote, printOutro, printSpinner } from "@/lib/cli-message";
import { createMinioS3Client } from "@/lib/codegen/minio";
import { Command } from "@commander-js/extra-typings";
import {
loadSettleMintApplicationConfig,
Expand Down Expand Up @@ -66,7 +67,7 @@ export function codegenCommand(): Command {

const envCfg = loadSettleMintEnvironmentConfig();

const { portalRest, portalGql, thegraphGql, hasuraGql, nodeJsonRpc, nodeJsonRpcDeploy } = appCfg;
const { portalRest, portalGql, thegraphGql, hasuraGql, nodeJsonRpc, nodeJsonRpcDeploy, minio } = appCfg;

await printSpinner({
startMessage: "Generating SettleMint SDK",
Expand Down Expand Up @@ -116,12 +117,15 @@ export function codegenCommand(): Command {
settleMintDir,
framework: cfg.framework,
type: "hasura",
gqlUrl: process.env.LOCAL_HASURA ?? hasuraGql,
gqlUrl: hasuraGql,
personalAccessToken: envCfg.SETTLEMINT_PAT_TOKEN,
hasuraAdminSecret: envCfg.SETTLEMINT_HASURA_GQL_ADMIN_SECRET,
}),
);
}
if (minio) {
sdkParts.push(createMinioS3Client());
}
if (nodeJsonRpc || nodeJsonRpcDeploy) {
sdkParts.push(
createChainConfig({
Expand Down Expand Up @@ -165,7 +169,7 @@ export function codegenCommand(): Command {
import { sdkGenerator, type ViemConfig, type WagmiConfig } from "@settlemint/sdk-next/browser";
${importLines.filter((line) => line.trim() !== "").join("\n")}

export const connectSettlemint = (config: {viem?: ViemConfig, wagmi: WagmiConfig}) => (${JSON.stringify(
export const connectSettlemint = (config: {viem?: ViemConfig, wagmi: WagmiConfig, minio?: {endPoint: string}}) => (${JSON.stringify(
settlemintObject,
null,
2,
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/lib/codegen/minio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function createMinioS3Client() {
return {
importLine: "",
sdkLine: {
minio: "sdkGenerator.createMinioS3Client({...config?.minio}),",
},
};
}
3 changes: 2 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
},
"devDependencies": {},
"dependencies": {
"@rainbow-me/rainbowkit": "^2",
"@rainbow-me/rainbowkit": "^2.1.7",
"@settlemint/sdk-config": "workspace:*",
"abitype": "^1",
"graphql-request": "^7",
"graphql-tag": "^2",
"minio": "^8.0.1",
"openapi-fetch": "^0.12",
"path-to-regexp": "^7",
"viem": "^2",
Expand Down
11 changes: 11 additions & 0 deletions packages/next/src/browser/sdk/plugins/minio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Client } from "minio";

export function createMinioS3Client({ endPoint }: { endPoint: string }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (review_instructions): Consider adding error handling for potential connection issues.

While the code is functional, it might be beneficial to add error handling to manage potential connection failures or invalid credentials. This would improve the robustness of the function.

export function createMinioS3Client({ endPoint }: { endPoint: string }): Promise<Client> {
  return new Promise((resolve, reject) => {
    try {
      const client = new Client({
        endPoint: endPoint,
        // ... other configuration options
      });
      resolve(client);
    } catch (error) {
      reject(new Error(`Failed to create Minio S3 client: ${error.message}`));
    }
  });
}
Review instructions:

Path patterns: **/*.ts

Instructions:

  • You always use the latest version of NodeJS, Bun, React, NestJS and NextJS, and you are familiar with the latest features and best practices.
  • Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.
  • Focus on readability over being performant, but performance is important.

return new Client({
endPoint: endPoint,
port: 443,
useSSL: true,
Comment on lines +6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Make port and SSL settings configurable

The hardcoded port and SSL settings might not be flexible enough for all use cases. Consider making these configurable by accepting them as parameters or reading from configuration.

export function createMinioS3Client({ endPoint, port = 443, useSSL = true }: { endPoint: string; port?: number; useSSL?: boolean }) {
  return new Client({
    endPoint: endPoint,
    port,
    useSSL,
    accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY ?? "",
    secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY ?? "",

accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY ?? "",
secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY ?? "",
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (review_instructions): Consider adding validation for required environment variables.

It's a good practice to validate that these environment variables are set before using them. If they're required for the client to function correctly, you might want to throw an error if they're not present.

const accessKey = process.env.SETTLEMINT_MINIO_ACCESS_KEY;
const secretKey = process.env.SETTLEMINT_MINIO_SECRET_KEY;

if (!accessKey || !secretKey) {
  throw new Error('Minio access key and secret key are required');
}

accessKey: accessKey,
secretKey: secretKey,
Review instructions:

Path patterns: **/*.ts

Instructions:

  • You always use the latest version of NodeJS, Bun, React, NestJS and NextJS, and you are familiar with the latest features and best practices.
  • Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.
  • Focus on readability over being performant, but performance is important.

});
}
2 changes: 2 additions & 0 deletions packages/next/src/browser/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createGraphqlClient } from "@/browser/sdk/plugins/graphql";
import { createPortalRestClient } from "@/browser/sdk/plugins/portal";
import { createViemPublicClient, createViemWalletClient } from "@/browser/sdk/plugins/viem";
import { createWagmiConfig } from "@/browser/sdk/plugins/wagmi";
import { createMinioS3Client } from "./plugins/minio";

/**
* A collection of functions for generating various SDK components.
Expand All @@ -16,4 +17,5 @@ export const sdkGenerator = {
createViemPublicClient,
createViemWalletClient,
createWagmiConfig,
createMinioS3Client,
} as const;
2 changes: 1 addition & 1 deletion packages/next/src/node/next/with-settlemint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function generateRewrites(cfg: ApplicationConfig): Rewrite[] {
{
condition: cfg.hasuraGql,
source: "/proxy/hasura/graphql",
destination: process.env.LOCAL_HASURA ?? cfg.hasuraGql,
destination: cfg.hasuraGql,
},
{ condition: cfg.portalRest, source: "/proxy/portal/rest/:path*", destination: `${cfg.portalRest}/:path*` },
{ condition: cfg.portalGql, source: "/proxy/portal/graphql", destination: cfg.portalGql },
Expand Down