feat: implement typed frappe api client and secure auth poc (#18)#21
Open
rohansaini-02 wants to merge 1 commit into
Open
feat: implement typed frappe api client and secure auth poc (#18)#21rohansaini-02 wants to merge 1 commit into
rohansaini-02 wants to merge 1 commit into
Conversation
dba5c33 to
481fc7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implementation of a standalone Typed Frappe API Client and Secure Authentication Layer (Proof of Concept). This module provides a centralized, secure, and type-safe mechanism for the React Native app to communicate with the Frappe LMS backend, setting the foundation for all future network interactions.
Related Issue
Closes #18
Problem Statement
TAP Buddy requires a robust way to interact with the Frappe LMS backend. A naive approach of making raw HTTP calls throughout the app leads to duplicated authentication logic, inconsistent error handling, and fragile data structures. We need a centralized client that handles
api_key:api_secretinjection, manages token expiration, and provides strict TypeScript models for our core entities (Users, Courses, Lessons).Changes Made
poc-frappe-apias a standalone TypeScript package to ensure core networking logic is independently reviewable and testable.FrappeClientImplementation: Built a robust Axios wrapper with built-in interceptors.AuthServiceinterface to manage credentials (designed to be backed byreact-native-keychainin production).Authorizationheader to all outgoing requests.401 Unauthorizederrors globally and clear compromised credentials.LMSCourse,LMSLesson,UserProfile, etc.) to enforce data consistency.Technical Decisions
IAuthService), the client remains decoupled from React Native specifics, allowing this PoC to be tested in a pure Node environment while being 100% production-ready for the final app.Architectural Rationale: Why #18 precedes #14 (DIKSHA)
I deliberately prioritized this API Client (#18) before tackling the DIKSHA Content Interoperability (#14) for the following reasons:
Testing Performed
clearCredentialsworkflow.Results
A secure, typed, and reusable API layer that serves as the foundation for all future LMS-related network calls. This effectively de-risks the communication layer of the application.
Checklist
Architecture Diagram
sequenceDiagram participant App as React Native App participant Client as FrappeClient participant Auth as AuthService (Keychain) participant API as Frappe LMS Backend %% Request Flow App->>Client: getCourses() / getProfile() Note over Client: Request Interceptor triggers Client->>Auth: getCredentials() Auth-->>Client: Returns { apiKey, apiSecret } Note over Client: Injects "Authorization: token key:secret" Client->>API: HTTP Request %% Success Flow alt 200 OK API-->>Client: Response Data Client-->>App: Strongly Typed Object (LMSCourse[]) %% Error Flow else 401 / 403 Unauthorized API-->>Client: 401 Unauthorized Note over Client: Response Interceptor triggers Client->>Auth: clearCredentials() Client-->>App: Throws Error end