Skip to content

Commit

Permalink
Merge pull request #9 from PapillonApp/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
tom-theret authored Mar 10, 2024
2 parents db7cac4 + d0dc787 commit ae07e0a
Show file tree
Hide file tree
Showing 35 changed files with 1,464 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
}],
"@stylistic/semi": ["error", "always"]
},
"ignorePatterns": ["src/**/*.js", "src/*.js", "*.js", "src/types", "dist", "*.d.ts"]
"ignorePatterns": ["src/**/*.js", "src/*.js", "*.js", "src/types", "dist", "*.d.ts", "tests", "examples"]
}
16 changes: 16 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ jobs:

- name: Build code
run: npm run build:solo
# tests:
# name: Execute jest tests
# runs-on: ubuntu-latest
# permissions:
# contents: read
# security-events: write
# actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Setup Environnement
# run: npm install
#
# - name: Run test script
# run: npm run test
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Transpile typescript code
run: npm run build:solo
- name: Publish package on NPM 📦
run: npm publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ dist
.tern-port

# Generated javascript files
index.js
index.*j*
index.d*
src/**/*.js
src/**/*.j*
src/**/*.d*
dist/
/package-lock.json
/examples/*.js
/examples/*.d.ts
/examples/*.d.ts.map
/examples/*.js.map

# Editor configs (les dossiers de config on les commit pas: y'a rien d'essentiel dedans !)
.idea
.vscode
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Versions

- (**1.0.3**: abandonnée: pas de sens de ce système de version.)
- **0.1.0**: Projet initial en **javasciript**
- **0.2.0**: Réécriture en **typescript**
- **1.0.0**: Quand le module sera stable

## 0.2.5

- Ajout de la fonction `getFileBase64()` pour récupérer un fichier en base64
- Ajout de `getBase64()` dans la classe `Menu`

## 0.2.4

- Ajout des téléchargements
- Ajout des commandes
- Support de nouvelles erreurs
- Meilleur support du token permanent

## 0.2.3

- Erreur `526`
- POC commandes
- Module Esidoc

## 0.2.2

- NPM organisation configured
- Added permanent token support (`renewToken()`)

## 0.2.1

- Reconfiguration du `tsconfig.json` pour build correctement et publier sur **NPM**
23 changes: 23 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: Papillon Ecoledirecte Core
message: 'If you use this software, please cite it as below.'
type: software
authors:
- family-names: Linise
given-names: Vince
email: [email protected]
- name: les contributeurs de Papillon
repository-code: 'https://github.com/papillonapp/papillon-ed-core'
url: 'https://getpapillon.xyz'
abstract: >-
A typed wrapper for Ecoledirecte's private API written in
Typescript.
keywords:
- ecoledirecte
- papillon
license: GPL-3.0
version: 0.2.4
date-released: '2024-03-10'
206 changes: 178 additions & 28 deletions DOCUMENTATION.md

Large diffs are not rendered by default.

683 changes: 674 additions & 9 deletions LICENSE

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,35 @@ Le module est exporté vers NPM, il doit donc respecter les règles de codage de
- [x] Lister
- [ ] Rejoindre (pas testé)
- [ ] Quitter (pas testé)
- [ ] ??? (récupérer membres, docs, et autres...)
- [x] Agenda
- [x] Lister les discussions
- [ ] Cloud
- [x] Lister les membres
- [ ] Cloud
- [ ] Téléchargement de fichiers (`/telechargement.awp`)

## Documentation
Voir le fichier [`DOCUMENTATION.md`](DOCUMENTATION.md)

## Licence

Cette base de code est distribuée par Papillon, sous la licence [CeCill V2.1](LICENSE).
Cette base de code est distribuée par Papillon, sous la licence [**GPLv3**](LICENSE).

```text
papillon-ed-core Copyright (C) 2024 Vince Linise <[email protected]> et les contributeurs.
This program comes with ABSOLUTELY NO WARRANTY; see license for details.
This is free software, and you are welcome to redistribute it
under certain conditions; see license for details.
```

Elle est maintenue et développée par ses contributeurs : [LeMaitre](https://github.com/LeMaitre4523), [LeGeek](https://github.com/LeGeek01), [LucHack](https://github.com/lucas-luchack), [Azgar](https://github.com/azgaresncf), [Yann](https://github.com/yannouuuu), [Diego Finocchiaro](https://github.com/diegofino15) et [Armand Camponovo](https://github.com/camarm-dev)

## Attributions

- Les types (`src/types`), réadaptés par [Armand Camponovo](https://github.com/camarm-dev/ecoledirecte-api-types), originellement [a2br/ecoledirecte-api-types](https://github.com/a2br/ecoledirecte-api-types): _**_Aucune licence spécifiée_**_
- Certains autres types proviennent de [EduWireApps/ecoledirecte-api-docs](https://github.com/EduWireApps/ecoledirecte-api-docs): _**Aucune licence spécifiée**_
- Les types (`src/types`), réadaptés par [Armand Camponovo](https://github.com/camarm-dev/ecoledirecte-api-types), originellement [a2br/ecoledirecte-api-types](https://github.com/a2br/ecoledirecte-api-types) par [Anatole Debierre](https://github.com/a2br): licence [ISC](https://github.com/camarm-dev/ecoledirecte-api-types/blob/main/LICENSE)
- Certains autres types proviennent de [EduWireApps/ecoledirecte-api-docs](https://github.com/EduWireApps/ecoledirecte-api-docs), par [MaitreRouge](https://github.com/MaitreRouge): **Aucune licence spécifiée**

## Release

> [!CAUTION]
> Avant chaque release, mettre à jour `version` dans `package.json` et les champs `version` et `date-released` dans `citation.cff`
12 changes: 12 additions & 0 deletions TODOS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# TODOS

Fichier informatif à l'égard des développeurs.

## Liste

- [x] Publier sur **NPM**
- [ ] **Modifier** le `package.json` sur [PapillonApp/Papillon](https://github.com/papillonapp/papillon-ed-core), comme ci-dessous
```diff
- "papillon-ed-core": "github:papillonapp/papillon-ed-core",
+ "papillon-ed-core": "@Papillon/papillon-ed-core",
```
16 changes: 16 additions & 0 deletions examples/homeworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { login, ED } from "./login";

// Exemple de l'EDT

login().then(() => {
ED.homeworks.fetch().then(homeworks => {
console.log("Devoirs:");
Object.keys(homeworks).forEach(key => {
console.log(`\tPour le ${key}:`);
const work = homeworks[key];
work.forEach(subject => {
console.log(`\t\tDevoirs en ${subject.matiere} (${subject.codeMatiere}), donné le ${subject.donneLe}. ${subject.effectue ? "Effectué": "Non effectué"}, ${subject.interrogation ? "interrogation prévue": "pas d'interrogation"} et ${subject.rendreEnLigne ? "documents à rendre en ligne": "rien à rendre en ligne"}.`);
});
});
});
});
10 changes: 9 additions & 1 deletion examples/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {EDCore} from "../index";
import {studentAccount} from "~/types";
import { v4 as uuidv4 } from "uuid";

export const ED = new EDCore();

export async function login() {
await ED.auth.login("username", "password");
await ED.auth.login("jean", "jean%", uuidv4()).then(() => {
const account = ED.student as studentAccount;
console.log(`Logged in as ${account.particule} ${account.prenom} ${account.nom}`);
}).catch(err => {
console.error(`Failed to login: Error ${err.code}: ${err.message}`);
process.exit();
});
}
11 changes: 10 additions & 1 deletion examples/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ login().then(() => {
ED.timeline.fetch().then(timeline => {
console.log("Timeline personnelle:");
timeline.forEach(event => {
console.log(`\t${event.date} (${event.titre}).`);
console.log(`\t${event.titre}, ${event.date} (${event.soustitre}, ${event.contenu}).`);
});
});
ED.timeline.fetchCommonTimeline().then(data => {
console.log("Timeline commune:");
data.postits.forEach(postit => {
console.log(`\t[POSTIT] ${postit.contenu} par ${postit.auteur.particule} ${postit.auteur.nom}`);
});
data.evenements.forEach(event => {
console.log(`\t[EVENT] "${event.libelle}" ${event.description} du ${event.dateDebut} à ${event.heureDebut} au ${event.dateFin} à ${event.heureFin}`);
});
});
});
4 changes: 2 additions & 2 deletions examples/timetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { login, ED } from "./login";
login().then(() => {
// La date doit être donnée en YYYY-MM-DD
const today = new Date();
const todayDate = `${today.getFullYear()}-${today.getMonth()}-${today.getDate()}`;
const todayDate = `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`;
ED.timetable.fetchByDay(todayDate).then(timetable => {
console.log("Emploi du temps d'aujourd'hui:");
Object.keys(timetable).forEach(key => {
const matiere = timetable[key];
console.log(`\t${matiere.matiere} (${matiere.codeMatiere}), de ${matiere.start_date} à ${matiere.end_date} en salle ${matiere.classe}.`);
console.log(`\t${matiere.text ? matiere.text: matiere.matiere} (${matiere.codeMatiere}) avec ${matiere.prof ? matiere.prof: "pas de prof"}, de ${matiere.start_date} à ${matiere.end_date} en salle ${matiere.salle ? matiere.salle: "pas de salle"}.`);
});
});
});
4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "ts-jest",
"testEnvironment": "node"
}
35 changes: 21 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"name": "papillon-ed-core",
"version": "1.0.3",
"name": "@papillonapp/ed-core",
"version": "0.2.5",
"description": "API EcoleDirecte pour PapillonApp (c)",
"main": "index.js",
"types": "index.d.ts",
"module": "index.mjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"lint": "eslint --no-eslintrc -c .eslintrc.json .",
"lint:fix": "eslint --no-eslintrc -c .eslintrc.json --fix .",
"build": "npm run lint && tspc --project tsconfig.json",
"build:solo": "tspc --project tsconfig.json"
"build": "npm run lint && npm run build:solo",
"build:solo": "tsc && tsc-alias"
},
"engines": {
"node": "18"
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/PapillonApp/Papillon-ED-Core.git"
},
"author": "@PapillonApp",
"license": "CeCill V2.1",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/PapillonApp/Papillon-ED-Core/issues"
},
Expand All @@ -32,21 +35,25 @@
],
"devDependencies": {
"@stylistic/eslint-plugin": "^1.5.3",
"@types/jest": "^29.5.12",
"@typescript-eslint/parser": "^6.18.0",
"eslint": "^8.56.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"typescript": "^5.3.3",
"typescript-transform-path-rewrite": "^1.3.0"
},
"dependencies": {
"jest": "^29.7.0",
"remove": "^0.1.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"ts-patch": "^3.1.2",
"tsc-alias": "^1.8.8",
"tsconfig-paths": "^4.2.0",
"typescript-transform-paths": "^3.4.6"
"typescript": "^5.3.3"
},
"dependencies": {
"@types/uuid": "^9.0.8",
"uuid": "^9.0.1"
}
}
33 changes: 29 additions & 4 deletions src/Request.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import { API } from "./constants";
import {Session} from "./session";
import {SESSION_EXPIRED, TOKEN_INVALID, UNAUTHORIZED, WRONG_CREDENTIALS, INVALID_API_URL} from "~/errors";
import {
SESSION_EXPIRED,
TOKEN_INVALID,
UNAUTHORIZED,
WRONG_CREDENTIALS,
INVALID_API_URL,
OBJECT_NOT_FOUND, INVALID_BODY
} from "~/errors";
import {RequestOptions} from "~/utils/types/requests";
import {response} from "~/types/v3/responses/default/responses";

class Request {

session: Session;
ua: string;
requestOptions: RequestOptions;

constructor(session: Session) {
this.session = session;
this.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36";
this.requestOptions = {
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded"
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "EDMOBILE"
}
};
}

async blob(url: string, body: string) {
if(this.session.isLoggedIn) this.requestOptions.headers["X-token"] = this.session._token;
const finalUrl = API + url;
return await fetch(finalUrl, {
method: "POST",
headers: this.requestOptions.headers,
body: body
}).then(response => response.blob());
}

async post(url: string, body: string) {
if(this.session.isLoggedIn) this.requestOptions.headers["X-token"] = this.session._token;
const finalUrl = API + url;
Expand All @@ -36,15 +52,24 @@ class Request {
if (response.code == 525) {
throw SESSION_EXPIRED.drop();
}
if (response.code == 526) {
throw SESSION_EXPIRED.drop();
}
if (response.code == 520) {
throw TOKEN_INVALID.drop();
}
if (response.code == 505) {
throw WRONG_CREDENTIALS.drop();
}
if (response.code == 512) {
throw INVALID_BODY.drop();
}
if (response.code == 403) {
throw UNAUTHORIZED.drop(response.message);
}
if (response.code == 210) {
throw OBJECT_NOT_FOUND.drop(response.message);
}
return response;
}) as Promise<response>;
}
Expand Down
Loading

0 comments on commit ae07e0a

Please sign in to comment.