Skip to content

[Map Local] #3 Map Local Service Logic #207

@NghiaTranUIT

Description

@NghiaTranUIT

Description

⚠️ Ping @NghiaTranUIT for the MapLocalService and RuleStorageService as a code reference 👍

Acceptance Criteria

  • Save a MapLocalEntry as an Array. We don't need to support Tree View (Folder Mode) like the macOS.
  • Implement the MapLocalService and RuleStorageService
  • MapLocalService must be subclassed from RuleStorageService
  • RuleStorageService can be reused for other debugging tools, such as BlockListService, BreakpointService because they are sharing the same logic
  • The data is saved under App Data Directory. Don't save it in AppConfig.

RuleStorageService

RuleStorageService class will have matching fun, which accepts a Request.

    func matching(_ url: String, request: Request) -> T? {
        guard isEnabled,
            !entries.isEmpty else { return nil }
        return entries.first(where: { $0.matching(url, request: request) })
    }
  • It passes the logic to check which rule is matching to each Entry (In this case, it's the Map Local Entry)

Mapping Logic: ToolService class

  • Implement the ToolService class.
  • As soon as the Request in the Flow is created -> We pass it through the ToolService to determine which Tool is executed.
  • ToolService would check all available debugging tools, e.g. Block List, White List, Breakpoint, Map Local

Mapping Logic: Change the Response

  • ✅ Important Logic: If a flow is matched with Map Local (check by the ToolService) -> Make sure the Flow never goes to the real Server -> The Server will return a Response (which is built by the MapLocalServer)
  • It enables the Mock API feature from the Map Local Tool -> Read ticket for further information.

✅ How to test (Happy case on macOS)

  1. Use Insomnia: Make a real API call to httpbin.org
  2. The new request appears on the main view
  3. Right Click -> Tools -> Map Local
  4. Automatically create a Map Local Rule -> Open the Editor -> The Editor must show the body of the httpbin.org
  5. Go back to the Insomnia app -> Make an API again -> At this point: The API is a success and we can see the body.
  6. Back Proxyman app -> Map Local Editor -> Try to edit the Status Code, Header, Body -> Save -> Go to Insomnia -> New Response data is displayed.

✅ How to test (Happy case on iPhone)

  1. Set up Proxyman with your iPhone properly. Download the Product Hunt iOS app.
  2. Use the Product Hunt iOS app -> Load the Home View
  3. The new request appears on the main view
  4. Right Click -> Tools -> Map Local
  5. Automatically create a Map Local Rule -> The Editor must show the real Response Raw Message
  6. Try to edit the Name Product on the Response Body.
  7. Go back to the Product Hunt iOS app -> Pull to request on the Home Screen -> Make sure the UI is changed with the new Name Product.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request✅ DoneTicket is resolved

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions