Skip to content
Open
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
4 changes: 4 additions & 0 deletions poc-frappe-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
coverage/
.env
40 changes: 40 additions & 0 deletions poc-frappe-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Typed Frappe API Client (PoC)

This directory contains the Proof of Concept (PoC) for Issue #18: **Typed Frappe API Client and Secure Authentication Layer**.

## Overview

This module provides a centralized, type-safe way to communicate with the Frappe LMS backend. It focuses on:
1. **Secure Credential Handling**: Abstract interface for `api_key:api_secret` storage.
2. **Request Interceptors**: Automatic injection of Authorization headers.
3. **Response Interceptors**: Centralized handling of `401/403` unauthorized errors.
4. **TypeScript Models**: Strongly typed DocTypes (Course, Lesson, User).

## Architecture

```mermaid
graph LR
App[React Native UI] --> Client[FrappeClient]
Client --> Axios[Axios Instance]
Axios --> Interceptor[Auth Interceptor]
Interceptor --> Storage[AuthService / Keychain]
Axios --> API[Frappe REST API]
```

## Setup & Testing

1. Install dependencies:
```bash
cd poc-frappe-api
npm install
```
2. Run unit tests:
```bash
npm test
```

## Key Files
- `src/models/index.ts`: TypeScript interfaces for LMS resources.
- `src/AuthService.ts`: Credential management logic.
- `src/FrappeClient.ts`: Main API client with interceptors.
- `tests/FrappeClient.test.ts`: Interceptor and error handling tests.
11 changes: 11 additions & 0 deletions poc-frappe-api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { createDefaultPreset } = require("ts-jest");

const tsJestTransformCfg = createDefaultPreset().transform;

/** @type {import("jest").Config} **/
module.exports = {
testEnvironment: "node",
transform: {
...tsJestTransformCfg,
},
};
Loading