fix: identify correct offer for when teshin has 2 kuva offers up #797

Merged
Sainan merged 1 commits from teshin into main 2025-01-17 05:43:09 -08:00
Owner

Closes #738, as otherwise the rotation is actually already handled by the client. We just need to use the ItemId it gives us.

Closes #738, as otherwise the rotation is actually already handled by the client. We just need to use the ItemId it gives us.
coderabbitai[bot] commented 2025-01-17 04:23:33 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces modifications to the purchase service and purchase types to enhance the handling of vendor-specific purchases. In the purchaseService.ts, a new error handling mechanism is implemented for vendor purchases, with more explicit checks for vendor manifest and offer existence. The changes include throwing specific errors for unknown vendor IDs and offers.

In the purchaseTypes.ts, two new optional properties are added to the IPurchaseParams interface: ExtraPurchaseInfoJson and IsWeekly, both specifically designed for Source 7 purchases. These additions provide more flexibility in handling purchase-related information, particularly for specific source types.

Assessment against linked issues

Objective Addressed Explanation
Support for Steel Path Honors weekly rotating offers [#738]
Implement mechanism for weekly offer tracking

The changes appear to directly support the implementation of rotating offers at Steel Path Honors by introducing the IsWeekly and ExtraPurchaseInfoJson properties, which can be used to track and process weekly offer mechanics.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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.

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.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces modifications to the purchase service and purchase types to enhance the handling of vendor-specific purchases. In the `purchaseService.ts`, a new error handling mechanism is implemented for vendor purchases, with more explicit checks for vendor manifest and offer existence. The changes include throwing specific errors for unknown vendor IDs and offers. In the `purchaseTypes.ts`, two new optional properties are added to the `IPurchaseParams` interface: `ExtraPurchaseInfoJson` and `IsWeekly`, both specifically designed for Source 7 purchases. These additions provide more flexibility in handling purchase-related information, particularly for specific source types. ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------|-----------|-------------| | Support for Steel Path Honors weekly rotating offers [#738] | ✅ | | | Implement mechanism for weekly offer tracking | ✅ | | The changes appear to directly support the implementation of rotating offers at Steel Path Honors by introducing the `IsWeekly` and `ExtraPurchaseInfoJson` properties, which can be used to track and process weekly offer mechanics. <!-- walkthrough_end --> <!-- internal state start --> <!-- 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 --> <!-- internal state end --> <!-- finishing_touch_checkbox_start --> ## Finishing Touches - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings (Beta) <!-- finishing_touch_checkbox_end --> <!-- tips_start --> --- 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? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#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. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-17 04:30:22 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/types/purchaseTypes.ts (1)

20-21: LGTM! Consider enhancing the documentation.

The new fields align well with the PR objectives. The types are appropriate for their intended use.

Consider adding more detailed JSDoc comments to explain:

  • The expected JSON structure in ExtraPurchaseInfoJson
  • The impact of IsWeekly on the purchase behavior
-    ExtraPurchaseInfoJson?: string; // for Source 7
-    IsWeekly?: boolean; // for Source 7
+    /** JSON string containing ItemId for vendor offer identification. Expected format: { ItemId: string }
+     * @example '{"ItemId": "507f1f77bcf86cd799439011"}'
+     */
+    ExtraPurchaseInfoJson?: string;
+    /** Indicates if this is a weekly vendor offer */
+    IsWeekly?: boolean;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3d2345894 and e9a75db593.

📒 Files selected for processing (2)
  • src/services/purchaseService.ts (1 hunks)
  • src/types/purchaseTypes.ts (1 hunks)
🔇 Additional comments (2)
src/services/purchaseService.ts (2)

52-54: LGTM! Improved error handling for unknown vendors.

The explicit error for unknown vendor IDs enhances debugging capabilities.


56-58: Verify handling of multiple Kuva offers.

The changes look good for identifying the correct offer. Let's verify the implementation handles multiple Kuva offers correctly.

Run this script to check for multiple offer scenarios in the codebase:

Verification successful

Multiple Kuva offer handling verified

The implementation correctly handles multiple Kuva offers through precise ItemId matching, as evidenced by vendor manifests containing multiple Kuva items (e.g., TeshinHardMode and DuviriAcrithis vendors). The find() method with ItemId matching ensures the correct offer is selected even when multiple Kuva items exist in the manifest.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for test cases or configurations handling multiple Kuva offers
# Look for test files related to vendor purchases
fd -e ts -e js test.*purchase

# Look for vendor-related configuration or test data
rg -l "VendorInfo|ItemManifest|Kuva" --type json

# Look for Source 7 related test cases
rg "Source.*7.*vendor" -A 5 -B 5

Length of output: 2576


Script:

#!/bin/bash
# Check vendor manifests for Kuva items and multiple offer patterns
rg -i "kuva" static/fixed_responses/getVendorInfo/*.json

# Look for purchase service implementation
ast-grep --pattern 'class PurchaseService {
  $$$
}'

# Search for any Kuva-related purchase handling
rg -i "kuva.*purchase|purchase.*kuva" -A 5 -B 5

Length of output: 3256

**Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>src/types/purchaseTypes.ts (1)</summary><blockquote> `20-21`: **LGTM! Consider enhancing the documentation.** The new fields align well with the PR objectives. The types are appropriate for their intended use. Consider adding more detailed JSDoc comments to explain: - The expected JSON structure in `ExtraPurchaseInfoJson` - The impact of `IsWeekly` on the purchase behavior ```diff - ExtraPurchaseInfoJson?: string; // for Source 7 - IsWeekly?: boolean; // for Source 7 + /** JSON string containing ItemId for vendor offer identification. Expected format: { ItemId: string } + * @example '{"ItemId": "507f1f77bcf86cd799439011"}' + */ + ExtraPurchaseInfoJson?: string; + /** Indicates if this is a weekly vendor offer */ + IsWeekly?: boolean; ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b3d234589496ee2f1174eaee80574dfa8c702aaa and e9a75db593f3d299cfac51fe32a34a5223014939. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/services/purchaseService.ts` (1 hunks) * `src/types/purchaseTypes.ts` (1 hunks) </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>src/services/purchaseService.ts (2)</summary> `52-54`: **LGTM! Improved error handling for unknown vendors.** The explicit error for unknown vendor IDs enhances debugging capabilities. --- `56-58`: **Verify handling of multiple Kuva offers.** The changes look good for identifying the correct offer. Let's verify the implementation handles multiple Kuva offers correctly. Run this script to check for multiple offer scenarios in the codebase: <details> <summary>✅ Verification successful</summary> <!-- [monologue] [task verify_kuva_offers_2/2] [observations] 1. Found multiple vendor manifests containing Kuva items: - TeshinHardModeVendorManifest.json (2 offers) - RadioLegionIntermission11VendorManifest.json (1 offer) - HubsIronwakeDondaVendorManifest.json (1 offer) - DuviriAcrithisVendorManifest.json (2 offers) - ArchimedeanVendorManifest.json (1 offer) 2. The StoreItem path is consistent: "/Lotus/StoreItems/Types/Items/MiscItems/Kuva" 3. Multiple vendors have multiple Kuva offers in their manifests [analysis] 1. The implementation uses manifest.VendorInfo.ItemManifest.find() which correctly handles multiple offers 2. The ItemId matching ensures the correct offer is selected even when multiple Kuva items exist 3. The error handling is appropriate for cases where the specific offer isn't found [actions] Generate verification response as the implementation correctly handles multiple Kuva offers --> **Multiple Kuva offer handling verified** The implementation correctly handles multiple Kuva offers through precise ItemId matching, as evidenced by vendor manifests containing multiple Kuva items (e.g., TeshinHardMode and DuviriAcrithis vendors). The find() method with ItemId matching ensures the correct offer is selected even when multiple Kuva items exist in the manifest. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Check for test cases or configurations handling multiple Kuva offers # Look for test files related to vendor purchases fd -e ts -e js test.*purchase # Look for vendor-related configuration or test data rg -l "VendorInfo|ItemManifest|Kuva" --type json # Look for Source 7 related test cases rg "Source.*7.*vendor" -A 5 -B 5 ``` Length of output: 2576 --- Script: ```shell #!/bin/bash # Check vendor manifests for Kuva items and multiple offer patterns rg -i "kuva" static/fixed_responses/getVendorInfo/*.json # Look for purchase service implementation ast-grep --pattern 'class PurchaseService { $$$ }' # Search for any Kuva-related purchase handling rg -i "kuva.*purchase|purchase.*kuva" -A 5 -B 5 ``` Length of output: 3256 </details> </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-17 04:30:22 -08:00
Author
Owner

🛠️ Refactor suggestion

Add error handling for JSON parsing and type validation.

The current implementation might throw unclear errors if the JSON is malformed or doesn't contain ItemId.

Consider this safer implementation:

-        const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }).ItemId;
+        let extraInfo: unknown;
+        try {
+            extraInfo = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!);
+        } catch (e) {
+            throw new Error(`Invalid ExtraPurchaseInfoJson: ${e.message}`);
+        }
+        
+        if (!extraInfo || typeof extraInfo !== 'object' || !('ItemId' in extraInfo) || typeof extraInfo.ItemId !== 'string') {
+            throw new Error('ExtraPurchaseInfoJson must contain an ItemId string');
+        }
+        
+        const { ItemId } = extraInfo;
📝 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.

        let extraInfo: unknown;
        try {
            extraInfo = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!);
        } catch (e) {
            throw new Error(`Invalid ExtraPurchaseInfoJson: ${e.message}`);
        }
        
        if (!extraInfo || typeof extraInfo !== 'object' || !('ItemId' in extraInfo) || typeof extraInfo.ItemId !== 'string') {
            throw new Error('ExtraPurchaseInfoJson must contain an ItemId string');
        }
        
        const { ItemId } = extraInfo;
        const offer = manifest.VendorInfo.ItemManifest.find(x => x.Id.$oid == ItemId);
        if (!offer) {
            throw new Error(`unknown vendor offer: ${ItemId}`);
        }
        purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier;
_:hammer_and_wrench: Refactor suggestion_ **Add error handling for JSON parsing and type validation.** The current implementation might throw unclear errors if the JSON is malformed or doesn't contain ItemId. Consider this safer implementation: ```diff - const ItemId = (JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!) as { ItemId: string }).ItemId; + let extraInfo: unknown; + try { + extraInfo = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!); + } catch (e) { + throw new Error(`Invalid ExtraPurchaseInfoJson: ${e.message}`); + } + + if (!extraInfo || typeof extraInfo !== 'object' || !('ItemId' in extraInfo) || typeof extraInfo.ItemId !== 'string') { + throw new Error('ExtraPurchaseInfoJson must contain an ItemId string'); + } + + const { ItemId } = extraInfo; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **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. `````suggestion let extraInfo: unknown; try { extraInfo = JSON.parse(purchaseRequest.PurchaseParams.ExtraPurchaseInfoJson!); } catch (e) { throw new Error(`Invalid ExtraPurchaseInfoJson: ${e.message}`); } if (!extraInfo || typeof extraInfo !== 'object' || !('ItemId' in extraInfo) || typeof extraInfo.ItemId !== 'string') { throw new Error('ExtraPurchaseInfoJson must contain an ItemId string'); } const { ItemId } = extraInfo; const offer = manifest.VendorInfo.ItemManifest.find(x => x.Id.$oid == ItemId); if (!offer) { throw new Error(`unknown vendor offer: ${ItemId}`); } purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.