Skip to content

Commit

Permalink
feat: translate descriptions and add dataPath
Browse files Browse the repository at this point in the history
  • Loading branch information
DTrombett committed Apr 17, 2023
1 parent aac801c commit 512ec45
Show file tree
Hide file tree
Showing 68 changed files with 420 additions and 349 deletions.
239 changes: 124 additions & 115 deletions src/Client.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/api/aggiornaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { APIResponse, Client } from "..";
import { apiRequest, formatDate } from "..";

/**
* Aggiorna la data dell'ultimo aggiornamento.
* @param client - The client
* Aggiorna la data per la dashboard.
* @param client - Il client
*/
export const aggiornaData = async (client: Client) => {
const { body } = await apiRequest<APIResponse>(
Expand Down
9 changes: 5 additions & 4 deletions src/api/downloadAllegato.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { apiRequest } from "..";

/**
* Ottieni il link per scaricare un allegato della bacheca.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns Il link
*/
export const downloadAllegato = async (
client: Client,
options: {
uid: string;
id: string;
}
) => {
const { body } = await apiRequest<APIDownloadAllegato>(
Expand All @@ -18,7 +19,7 @@ export const downloadAllegato = async (
{
method: "POST",
body: {
uid: options.uid,
uid: options.id,
},
}
);
Expand Down
11 changes: 6 additions & 5 deletions src/api/downloadAllegatoStudente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { apiRequest } from "..";

/**
* Ottieni il link per scaricare un allegato della bacheca alunno.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns Il link
*/
export const downloadAllegatoStudente = async (
client: Client,
options: {
uid: string;
id: string;
profileId: string;
}
) => {
const { body } = await apiRequest<APIDownloadAllegato>(
Expand All @@ -19,8 +20,8 @@ export const downloadAllegatoStudente = async (
{
method: "POST",
body: {
uid: options.uid,
pkScheda: options.id,
uid: options.id,
pkScheda: options.profileId,
},
}
);
Expand Down
73 changes: 30 additions & 43 deletions src/api/getCode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { URL } from "node:url";
import { request } from "undici";
import type { BasicCredentials } from "..";
import { clientId, randomString } from "..";
import type { Credentials } from "..";
import { clientId, generateLoginLink } from "..";

const baseHeaders = {
"accept":
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"accept-encoding": "gzip, deflate, br",
"sec-fetch-dest": "document",
Expand All @@ -14,45 +14,32 @@ const baseHeaders = {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.29 Safari/537.36",
} as const;
const redirectUri = encodeURIComponent(
"it.argosoft.didup.famiglia.new://login-callback"
);
const scopes = encodeURIComponent("openid offline profile user.roles argo");

/**
* Get the code for the login.
* @param codeChallenge - The code challenge to use
* @returns The code to use for the login
* Ottieni il codice per il login.
* @param credentials - Le credenziali per l'accesso
* @returns I dati del codice da usare
*/
export const getCode = async (
codeChallenge: string,
credentials: BasicCredentials
) => {
const { headers, statusCode } = await request(
`https://auth.portaleargo.it/oauth2/auth?redirect_uri=${redirectUri}&client_id=${clientId}&response_type=code&prompt=login&state=${randomString(
22
)}&nonce=${randomString(
22
)}&scope=${scopes}&code_challenge=${codeChallenge}&code_challenge_method=S256`,
{
headers: {
...baseHeaders,
"sec-fetch-site": "none",
},
method: "GET",
}
);
const url = headers.location;
export const getCode = async (credentials: Credentials) => {
const url = generateLoginLink();
const { headers, statusCode } = await request(url.url, {
headers: {
...baseHeaders,
"sec-fetch-site": "none",
},
method: "GET",
});
const link = headers.location;
const cookies: string[] = [];
let cookieHeaders = headers["set-cookie"];

if (typeof url !== "string")
if (typeof link !== "string")
throw new TypeError(
`Auth request returned an invalid redirect url with status code ${statusCode}`
);
if (typeof cookieHeaders === "string") cookieHeaders = [cookieHeaders];
for (const c of cookieHeaders ?? []) cookies.push(c.split(";")[0]);
const challenge = new URL(url).searchParams.get("login_challenge")!;
const challenge = new URL(link).searchParams.get("login_challenge")!;
const {
headers: { location },
statusCode: status,
Expand All @@ -61,11 +48,11 @@ export const getCode = async (
headers: {
...baseHeaders,
"cache-control": "max-age=0",
"connection": "keep-alive",
connection: "keep-alive",
"content-type": "application/x-www-form-urlencoded",
"host": "www.portaleargo.it",
"origin": "https://www.portaleargo.it",
"referer": url,
host: "www.portaleargo.it",
origin: "https://www.portaleargo.it",
referer: link,
"sec-fetch-site": "same-origin",
},
method: "POST",
Expand All @@ -81,8 +68,8 @@ export const getCode = async (
headers: {
...baseHeaders,
"cache-control": "max-age=0",
"cookie": cookies.join("; "),
"referer": "https://www.portaleargo.it/",
cookie: cookies.join("; "),
referer: "https://www.portaleargo.it/",
"sec-fetch-site": "same-site",
},
method: "GET",
Expand All @@ -103,9 +90,9 @@ export const getCode = async (
headers: {
...baseHeaders,
"cache-control": "max-age=0",
"connection": "keep-alive",
"host": "www.portaleargo.it",
"referer": "https://www.portaleargo.it/",
connection: "keep-alive",
host: "www.portaleargo.it",
referer: "https://www.portaleargo.it/",
"sec-fetch-site": "same-site",
},
method: "GET",
Expand All @@ -122,8 +109,8 @@ export const getCode = async (
headers: {
...baseHeaders,
"cache-control": "max-age=0",
"cookie": cookies.join("; "),
"referer": "https://www.portaleargo.it/",
cookie: cookies.join("; "),
referer: "https://www.portaleargo.it/",
"sec-fetch-site": "same-site",
},
method: "GET",
Expand All @@ -137,5 +124,5 @@ export const getCode = async (

if (code == null)
throw new TypeError(`Invalid code returned by API: ${finalRedirect}`);
return code;
return { ...url, code };
};
11 changes: 6 additions & 5 deletions src/api/getCorsiRecupero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ import { CorsiRecupero, apiRequest } from "..";

/**
* Ottieni i dati dei corsi di recupero dello studente.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getCorsiRecupero = async <T extends CorsiRecupero>(
client: Client,
options: {
id: string;
profileId: string;
old?: T;
}
) => {
const { body } = await apiRequest<APICorsiRecupero>("corsirecupero", client, {
method: "POST",
body: {
pkScheda: options.id,
pkScheda: options.profileId,
},
});

if (!body.success) throw new Error(body.msg!);
return (options.old?.patch(body.data) ??
new CorsiRecupero(body.data, client, options.id)) as T;
new CorsiRecupero(body.data, client, options.profileId)) as T;
};
9 changes: 5 additions & 4 deletions src/api/getCurriculum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import { Curriculum, apiRequest } from "..";

/**
* Ottieni il curriculum dello studente.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getCurriculum = async (
client: Client,
options: {
id: string;
profileId: string;
}
) => {
const { body } = await apiRequest<APICurriculum>("curriculumalunno", client, {
method: "POST",
body: {
pkScheda: options.id,
pkScheda: options.profileId,
},
});

Expand Down
11 changes: 6 additions & 5 deletions src/api/getDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { APIDashboard, Client } from "..";
import { Dashboard, apiRequest, formatDate, writeToFile } from "..";

/**
* Fetch all the data for the authenticated user.
* @param client - The client
* @param options - Additional options for the request
* @returns All the data for the user
* Ottieni la dashboard dello studente.
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getDashboard = async (
client: Client,
Expand All @@ -30,6 +30,7 @@ export const getDashboard = async (
client.dashboard?.patch(body.data.dati[0]) ??
new Dashboard(body.data.dati[0], client);

void writeToFile("dashboard", value);
if (client.dataPath !== undefined)
void writeToFile("dashboard", value, client.dataPath);
return value;
};
3 changes: 2 additions & 1 deletion src/api/getDettagliProfilo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { DettagliProfilo, apiRequest } from "..";

/**
* Ottieni i dettagli del profilo dello studente.
* @param client - The client
* @param client - Il client
* @returns I dati
*/
export const getDettagliProfilo = async <T extends DettagliProfilo>(
client: Client,
Expand Down
5 changes: 3 additions & 2 deletions src/api/getOrarioGiornaliero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Orario, apiRequest, formatDate } from "..";

/**
* Ottieni l'orario giornaliero.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getOrarioGiornaliero = async (
client: Client,
Expand Down
9 changes: 5 additions & 4 deletions src/api/getPCTOData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import { apiRequest } from "..";

/**
* Ottieni i dati del PCTO dello studente.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getPCTOData = async (
client: Client,
options: {
id: string;
profileId: string;
}
) => {
const { body } = await apiRequest<APIPCTO>("pcto", client, {
method: "POST",
body: {
pkScheda: options.id,
pkScheda: options.profileId,
},
});

Expand Down
6 changes: 4 additions & 2 deletions src/api/getProfilo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Profilo, apiRequest, writeToFile } from "..";

/**
* Ottieni i dati riguardo il profilo dell'utente.
* @param client - The client
* @param client - Il client
* @returns I dati
*/
export const getProfilo = async (client: Client) => {
const { body } = await apiRequest<APIProfilo>("profilo", client, {});
Expand All @@ -12,6 +13,7 @@ export const getProfilo = async (client: Client) => {
const value =
client.profile?.patch(body.data) ?? new Profilo(body.data, client);

void writeToFile("profile", value);
if (client.dataPath !== undefined)
void writeToFile("profile", value, client.dataPath);
return value;
};
4 changes: 3 additions & 1 deletion src/api/getRicevimenti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Ricevimenti, apiRequest } from "..";

/**
* Ottieni i dati riguardo i ricevimenti dello studente.
* @param client - The client
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getRicevimenti = async <T extends Ricevimenti>(
client: Client,
Expand Down
9 changes: 5 additions & 4 deletions src/api/getStoricoBacheca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import { EventoBacheca, apiRequest, handleOperation } from "..";

/**
* Ottieni lo storico della bacheca.
* @param client - The client
* @param options - Additional options for the request
* @param client - Il client
* @param options - Altre opzioni della richiesta
* @returns I dati
*/
export const getStoricoBacheca = async (
client: Client,
options: {
id: string;
profileId: string;
}
) => {
const { body } = await apiRequest<APIBacheca>("storicobacheca", client, {
method: "POST",
body: {
pkScheda: options.id,
pkScheda: options.profileId,
},
});

Expand Down
Loading

0 comments on commit 512ec45

Please sign in to comment.