Skip to content
New issue

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

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

Already on GitHub? # to your account

New Components - bitbadges #15405

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

trevormil
Copy link

@trevormil trevormil commented Jan 25, 2025

WHY

Add common BitBadges actions (complete claim, add to store) to the already implemented BitBadges integration on the site.

Summary by CodeRabbit

  • New Features
    • Added "Complete Claim" functionality for BitBadges.
    • Enables users to complete claims through the application.
    • Supports claim completion with optional user details.
    • Provides error handling for claim submission process.

Copy link

vercel bot commented Jan 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Feb 4, 2025 1:53am

Copy link

vercel bot commented Jan 25, 2025

@trevormil is attempting to deploy a commit to the Pipedreamers Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

Warning

Rate limit exceeded

@trevormil has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6ffa698 and a9bde5d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/bitbadges/actions/add-to-dynamic-store.mjs (1 hunks)
  • components/bitbadges/actions/complete-claim.mjs (1 hunks)

Walkthrough

A new feature for completing BitBadges claims has been introduced across two new action files. The implementation allows users to complete claims by sending POST requests to the BitBadges API. The actions support various input parameters like dynamicDataId, dataSecret, address, id, email, and username. These actions provide a mechanism to interact with the BitBadges platform, enabling claim completion through a standardized interface with error handling and validation.

Changes

File Change Summary
components/bitbadges/actions/add-to-dynamic-store.mjs, components/bitbadges/actions/complete-claim.mjs Added new "Complete Claim" action in both files with API request handling, input validation, and error management for claim completion

Suggested labels

ai-assisted

Suggested reviewers

  • michelle0927

Poem

🐰 A Rabbit's Ode to BitBadge Claims

Hop, hop, through digital plains,
Claiming badges without any pains,
API calls swift and bright,
Validation holding errors tight,
BitBadges dancing in the light! 🏅


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dylburger dylburger added the User submitted Submitted by a user label Jan 25, 2025
@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
components/bitbadges/actions/complete-claim.mjs (1)

12-16: Consider using structured input instead of hyphen-separated string.

The claimInfo property combines multiple values into a hyphen-separated string, which is prone to errors and harder to validate. Consider using separate properties for better type safety and validation.

-    claimInfo: {
-      type: "string",
-      label: "Claim Info",
-      description: "Claim details passed as a string in the format \"claimId-passwordPluginId-password\"",
-    },
+    claimId: {
+      type: "string",
+      label: "Claim ID",
+      description: "The unique identifier of the claim",
+    },
+    passwordPluginId: {
+      type: "string",
+      label: "Password Plugin ID",
+      description: "The identifier of the password plugin",
+    },
+    password: {
+      type: "string",
+      label: "Password",
+      description: "The password for the claim",
+      secret: true,
+    },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 427b0bf and eca358d.

📒 Files selected for processing (2)
  • components/bitbadges/actions/add-to-dynamic-store.mjs (1 hunks)
  • components/bitbadges/actions/complete-claim.mjs (1 hunks)
🔇 Additional comments (1)
components/bitbadges/actions/complete-claim.mjs (1)

17-21: Add address format validation.

The address property should include format validation to ensure valid BitBadges addresses are provided.

Could you provide the expected format for BitBadges addresses? This would help in implementing proper validation.

Comment on lines 64 to 75
const result = response;

// Note: This means a successful trigger (add to queue), not a claim completion
// You can use the claimAttemptId to poll
return {
success: true,
claimAttemptId: result.claimAttemptId || "",
currentTimestamp: Date.now(),
};
} catch (error) {
throw new Error(`Failed to complete claim: ${error.message}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance response handling and error management.

The current implementation has several areas for improvement:

  • No validation of the response structure
  • Error messages might expose sensitive information
  • No retry mechanism for transient failures
-      const result = response;
+      // Validate response structure
+      if (!response?.claimAttemptId) {
+        throw new Error("Invalid response: missing claimAttemptId");
+      }
+
+      const result = {
+        success: true,
+        claimAttemptId: response.claimAttemptId,
+        currentTimestamp: Date.now(),
+      };
+
+      $.export("result", result);
+      return result;
     } catch (error) {
-      throw new Error(`Failed to complete claim: ${error.message}`);
+      // Sanitize error message
+      const safeMessage = "Failed to complete claim. Please try again later.";
+      $.export("error", {
+        message: safeMessage,
+        code: error.response?.status,
+        timestamp: Date.now(),
+      });
+      throw new Error(safeMessage);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const result = response;
// Note: This means a successful trigger (add to queue), not a claim completion
// You can use the claimAttemptId to poll
return {
success: true,
claimAttemptId: result.claimAttemptId || "",
currentTimestamp: Date.now(),
};
} catch (error) {
throw new Error(`Failed to complete claim: ${error.message}`);
}
// Validate response structure
if (!response?.claimAttemptId) {
throw new Error("Invalid response: missing claimAttemptId");
}
const result = {
success: true,
claimAttemptId: response.claimAttemptId,
currentTimestamp: Date.now(),
};
return result;
} catch (error) {
// Sanitize error message
const safeMessage = "Failed to complete claim. Please try again later.";
throw new Error(safeMessage);
}

Comment on lines 54 to 69
try {
await axios($, {
method: "POST",
url: `https://api.bitbadges.io/api/v0/bin-actions/add/${this.dynamicDataId}/${this.dataSecret}`,
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"x-api-key": this.bitbadges.$auth.api_key,
},
data: {
address: this.address,
id: this.id,
email: this.email,
username: this.username,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve request construction and payload handling.

The current implementation has several areas for improvement in how the request is constructed and how data is sent.

+    // Filter out undefined values from payload
+    const data = Object.entries({
+      address: this.address,
+      id: this.id,
+      email: this.email,
+      username: this.username,
+    }).reduce((acc, [key, value]) => {
+      if (value !== undefined) {
+        acc[key] = value;
+      }
+      return acc;
+    }, {});
+
+    const endpoint = new URL(
+      `bin-actions/add/${encodeURIComponent(this.dynamicDataId)}/${encodeURIComponent(this.dataSecret)}`,
+      "https://api.bitbadges.io/api/v0/"
+    ).toString();
+
     await axios($, {
       method: "POST",
-      url: `https://api.bitbadges.io/api/v0/bin-actions/add/${this.dynamicDataId}/${this.dataSecret}`,
+      url: endpoint,
       headers: {
         "Content-Type": "application/json",
         "Accept": "application/json",
         "x-api-key": this.bitbadges.$auth.api_key,
+        "Content-Length": Buffer.from(JSON.stringify(data)).length.toString(),
       },
-      data: {
-        address: this.address,
-        id: this.id,
-        email: this.email,
-        username: this.username,
-      },
+      data,

Committable suggestion skipped: line range outside the PR's diff.

trevormil and others added 6 commits February 3, 2025 20:06
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
components/bitbadges/actions/add-to-dynamic-store.mjs (1)

71-80: Optimize response handling and avoid data duplication.

The current implementation:

  1. Creates and exports the same data structure twice
  2. Lacks response validation
-      // Validate successful response
-      const result = {
-        success: true,
-        timestamp: Date.now(),
-      };
-      $.export("result", result);
-      return {
-        success: true,
-        timestamp: Date.now(),
-      };
+      const result = {
+        success: true,
+        timestamp: Date.now(),
+        dynamicDataId: this.dynamicDataId,
+        addedFields: Object.keys(data),
+      };
+      $.export("result", result);
+      return result;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eca358d and d1e4fb2.

📒 Files selected for processing (2)
  • components/bitbadges/actions/add-to-dynamic-store.mjs (1 hunks)
  • components/bitbadges/actions/complete-claim.mjs (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
components/bitbadges/actions/complete-claim.mjs

[error] 37-37: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 40-40: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 44-44: Shouldn't redeclare 'claimId'. Consider to delete it or rename it.

'claimId' is defined here:

(lint/suspicious/noRedeclare)


[error] 45-45: Shouldn't redeclare 'passwordPluginId'. Consider to delete it or rename it.

'passwordPluginId' is defined here:

(lint/suspicious/noRedeclare)


[error] 46-46: Shouldn't redeclare 'password'. Consider to delete it or rename it.

'password' is defined here:

(lint/suspicious/noRedeclare)

🔇 Additional comments (1)
components/bitbadges/actions/complete-claim.mjs (1)

74-82: 🛠️ Refactor suggestion

Enhance response validation and success criteria.

The current implementation:

  1. Lacks response structure validation
  2. Uses an empty string fallback for claimAttemptId
  3. Doesn't clearly distinguish between queue addition and claim completion
-      const result = response;
+      // Validate response structure
+      if (!response?.claimAttemptId) {
+        throw new Error("Invalid response: missing claimAttemptId");
+      }
+
+      const result = {
+        success: true,
+        status: "queued", // Indicate that this is a queue addition
+        claimAttemptId: response.claimAttemptId,
+        currentTimestamp: Date.now(),
+      };
+
+      $.export("result", result);
       return {
         success: true,
-        claimAttemptId: result.claimAttemptId || "",
+        status: "queued",
+        claimAttemptId: result.claimAttemptId,
         currentTimestamp: Date.now(),
       };

Likely invalid or redundant comment.

Comment on lines 44 to 46
const claimId = details[0];
const passwordPluginId = details[1];
const password = details[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove redundant variable declarations.

These variables are already declared through destructuring in line 36. Remove these redundant declarations to fix the "no redeclare" errors.

-    const claimId = details[0];
-    const passwordPluginId = details[1];
-    const password = details[2];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const claimId = details[0];
const passwordPluginId = details[1];
const password = details[2];
🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: Shouldn't redeclare 'claimId'. Consider to delete it or rename it.

'claimId' is defined here:

(lint/suspicious/noRedeclare)


[error] 45-45: Shouldn't redeclare 'passwordPluginId'. Consider to delete it or rename it.

'passwordPluginId' is defined here:

(lint/suspicious/noRedeclare)


[error] 46-46: Shouldn't redeclare 'password'. Consider to delete it or rename it.

'password' is defined here:

(lint/suspicious/noRedeclare)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
components/bitbadges/actions/add-to-dynamic-store.mjs (2)

53-65: Optimize validation logic.

The current validation works but can be simplified using Object.values().some().

-      const storeFields = {
-        address: this.address,
-        id: this.id,
-        email: this.email,
-        username: this.username,
-      };
-
-      if (!Object.values(storeFields).some((value) => value !== undefined)) {
+      if (!Object.values({
+        address: this.address,
+        id: this.id,
+        email: this.email,
+        username: this.username,
+      }).some(Boolean)) {

94-114: Consider adding error logging.

While the error handling is good, adding logging would help with debugging.

     } catch (error) {
       // Sanitize and structure error information
       const errorInfo = {
         message: "Failed to add to dynamic store. Please try again later.",
         code: error.response?.status,
         timestamp: Date.now(),
       };
+      // Log error details for debugging
+      console.error("BitBadges API Error:", {
+        status: error.response?.status,
+        data: error.response?.data,
+        timestamp: Date.now(),
+      });
       $.export("error", errorInfo);
       throw new Error(errorInfo.message);
     }
components/bitbadges/actions/complete-claim.mjs (1)

56-76: Enhance claim info validation.

While the current validation is good, it could be more robust.

     const details = this.claimInfo.split("-");
-    if (details.length !== 3 || !details.every((part) => part.trim())) {
+    if (!this.claimInfo || details.length !== 3 || !details.every((part) => part.trim())) {
       throw new Error(
         "Invalid claim details: each part must be non-empty",
       );
     }

     // Sanitize and validate each part
     const [
       claimId,
       passwordPluginId,
       password,
     ] = details.map((part) =>
       part.trim());
+    
+    // Enforce maximum length constraints
+    const MAX_LENGTH = 100;
+    if ([claimId, passwordPluginId, password].some(part => part.length > MAX_LENGTH)) {
+      throw new Error("One or more parts exceed maximum length");
+    }
+    
     if (!/^[a-zA-Z0-9-_]+$/.test(claimId)) {
       throw new Error("Invalid claim ID format");
     }
     if (!/^[a-zA-Z0-9-_]+$/.test(passwordPluginId)) {
       throw new Error("Invalid password plugin ID format");
     }
+    // Ensure password meets minimum requirements
+    if (password.length < 8) {
+      throw new Error("Password must be at least 8 characters long");
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1e4fb2 and 6ffa698.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/bitbadges/actions/add-to-dynamic-store.mjs (1 hunks)
  • components/bitbadges/actions/complete-claim.mjs (1 hunks)
🔇 Additional comments (2)
components/bitbadges/actions/add-to-dynamic-store.mjs (1)

79-93: Well-implemented request construction!

Good use of:

  • URL constructor for safe parameter encoding
  • Proper headers setup
  • API key authentication
components/bitbadges/actions/complete-claim.mjs (1)

94-119: 🛠️ Refactor suggestion

Enhance error handling and reporting.

The current error handling could be more informative while maintaining security.

     try {
       const response = await axios($, {
         method: "post",
         url: endpoint,
         headers: {
           "Content-Type": "application/json",
           "Accept": "application/json",
           "x-api-key": `${this.bitbadges.$auth.api_key}`,
         },
         data,
       });
       // Validate response structure
       if (!response?.claimAttemptId) {
         throw new Error("Invalid response: missing claimAttemptId");
       }
       const result = {
         success: true,
         claimAttemptId: response.claimAttemptId,
         currentTimestamp: Date.now(),
       };
+      $.export("result", result);
       return result;
     } catch (error) {
-      // Sanitize error message
-      const safeMessage = "Failed to complete claim. Please try again later.";
-      throw new Error(safeMessage);
+      // Structure and sanitize error information
+      const errorInfo = {
+        message: "Failed to complete claim. Please try again later.",
+        code: error.response?.status || 500,
+        timestamp: Date.now(),
+      };
+      
+      // Log detailed error for debugging
+      console.error("BitBadges Claim Error:", {
+        status: error.response?.status,
+        data: error.response?.data,
+        timestamp: Date.now(),
+      });
+      
+      $.export("error", errorInfo);
+      throw new Error(errorInfo.message);
     }

Likely invalid or redundant comment.

Comment on lines 10 to 52
props: {
app,
dynamicDataId: {
type: "string",
label: "Dynamic Data ID",
description: "The dynamic data store ID to add to.",
optional: false,
},
dataSecret: {
type: "string",
label: "Data Secret",
description: "The data secret of the dynamic data store.",
optional: false,
},
address: {
type: "string",
label: "Address",
description:
"The address to add to the dynamic data store. Only applicable if it is an address store.",
optional: true,
},
id: {
type: "string",
label: "ID",
description:
"The ID to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
email: {
type: "string",
label: "Email",
description:
"The email to add to the dynamic data store. Only applicable if it is an email store.",
optional: true,
},
username: {
type: "string",
label: "Username",
description:
"The username to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add comprehensive input validation for props.

While the props are well-defined, additional validation would improve data integrity:

  1. Email format validation
  2. Address format validation (for blockchain addresses)
  3. ID format validation

Add a validateProps method to validate inputs:

 props: {
   // ... existing props ...
+  validateProps() {
+    // Validate email format if provided
+    if (this.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
+      throw new Error("Invalid email format");
+    }
+    
+    // Validate blockchain address format if provided
+    if (this.address && !/^0x[a-fA-F0-9]{40}$/.test(this.address)) {
+      throw new Error("Invalid blockchain address format");
+    }
+    
+    // Validate ID format if provided
+    if (this.id && !/^[a-zA-Z0-9-_]+$/.test(this.id)) {
+      throw new Error("Invalid ID format");
+    }
+    
+    return true;
+  },
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
props: {
app,
dynamicDataId: {
type: "string",
label: "Dynamic Data ID",
description: "The dynamic data store ID to add to.",
optional: false,
},
dataSecret: {
type: "string",
label: "Data Secret",
description: "The data secret of the dynamic data store.",
optional: false,
},
address: {
type: "string",
label: "Address",
description:
"The address to add to the dynamic data store. Only applicable if it is an address store.",
optional: true,
},
id: {
type: "string",
label: "ID",
description:
"The ID to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
email: {
type: "string",
label: "Email",
description:
"The email to add to the dynamic data store. Only applicable if it is an email store.",
optional: true,
},
username: {
type: "string",
label: "Username",
description:
"The username to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
},
props: {
app,
dynamicDataId: {
type: "string",
label: "Dynamic Data ID",
description: "The dynamic data store ID to add to.",
optional: false,
},
dataSecret: {
type: "string",
label: "Data Secret",
description: "The data secret of the dynamic data store.",
optional: false,
},
address: {
type: "string",
label: "Address",
description:
"The address to add to the dynamic data store. Only applicable if it is an address store.",
optional: true,
},
id: {
type: "string",
label: "ID",
description:
"The ID to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
email: {
type: "string",
label: "Email",
description:
"The email to add to the dynamic data store. Only applicable if it is an email store.",
optional: true,
},
username: {
type: "string",
label: "Username",
description:
"The username to add to the dynamic data store. Only applicable if it is a socials store.",
optional: true,
},
validateProps() {
// Validate email format if provided
if (this.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
throw new Error("Invalid email format");
}
// Validate blockchain address format if provided
if (this.address && !/^0x[a-fA-F0-9]{40}$/.test(this.address)) {
throw new Error("Invalid blockchain address format");
}
// Validate ID format if provided
if (this.id && !/^[a-zA-Z0-9-_]+$/.test(this.id)) {
throw new Error("Invalid ID format");
}
return true;
},
},

Comment on lines 29 to 53
validateProps() {
const storeFields = {
address: this.address,
id: this.id,
email: this.email,
username: this.username,
};

const providedFields = Object.entries(storeFields)
.filter(([
,
value,
]) => value !== undefined);

if (providedFields.length === 0) {
throw new Error("At least one store-specific field (address, id, email, or username) must be provided");
}

// Add email format validation
if (this.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
throw new Error("Invalid email format");
}

return true;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove invalid validateProps method.

The validateProps method references props (id, email, username) that are not defined in this component. This appears to be incorrectly copied from add-to-dynamic-store.mjs.

Remove the entire validateProps method as it's not applicable to this component's props.

-    validateProps() {
-      const storeFields = {
-        address: this.address,
-        id: this.id,
-        email: this.email,
-        username: this.username,
-      };
-
-      const providedFields = Object.entries(storeFields)
-        .filter(([
-          ,
-          value,
-        ]) => value !== undefined);
-
-      if (providedFields.length === 0) {
-        throw new Error("At least one store-specific field (address, id, email, or username) must be provided");
-      }
-
-      // Add email format validation
-      if (this.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
-        throw new Error("Invalid email format");
-      }
-
-      return true;
-    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
validateProps() {
const storeFields = {
address: this.address,
id: this.id,
email: this.email,
username: this.username,
};
const providedFields = Object.entries(storeFields)
.filter(([
,
value,
]) => value !== undefined);
if (providedFields.length === 0) {
throw new Error("At least one store-specific field (address, id, email, or username) must be provided");
}
// Add email format validation
if (this.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
throw new Error("Invalid email format");
}
return true;
},

@trevormil trevormil changed the title Add BitBadges preconfigured actions New Components - bitbadges Feb 4, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
User submitted Submitted by a user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants