-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as izly from "../src"; | ||
import { read } from "./_persisted-session"; | ||
|
||
void async function main () { | ||
const identification = await read(); | ||
|
||
const payments = await izly.operations(identification, izly.OperationKind.Payment, 5); | ||
const topup = await izly.operations(identification, izly.OperationKind.TopUp, 5); | ||
|
||
console.info("- Payments -"); | ||
for (const payment of payments) { | ||
const priceAsString = `${payment.amount.toPrecision(3)} EUR`; | ||
console.info(payment.date.toLocaleString("fr-FR"), "paid", priceAsString); | ||
} | ||
|
||
console.info("- Top-up -"); | ||
for (const operation of topup) { | ||
const priceAsString = `${operation.amount.toPrecision(3)} EUR`; | ||
console.info(operation.date.toLocaleString("fr-FR"), "received", priceAsString); | ||
} | ||
}(); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { defaultFetcher, type Fetcher, type Request } from "@literate.ink/utilities"; | ||
import { CLIENT_TYPE, SERVICE_VERSION } from "~/core/constants"; | ||
import { decodeFormattedDate } from "~/decoders/date"; | ||
import type { Identification, Operation } from "~/models"; | ||
|
||
export const OperationKind = { | ||
TopUp: 0, | ||
Transfer: 1, | ||
Payment: 2 | ||
} as const; | ||
|
||
export type OperationKind = typeof OperationKind[keyof typeof OperationKind]; | ||
|
||
/** | ||
* @returns a list of the last operations | ||
*/ | ||
export const operations = async (identification: Identification, kind: OperationKind, limit = 15, fetcher: Fetcher = defaultFetcher): Promise<Array<Operation>> => { | ||
// transactionGroup=2 means history of operations | ||
const url = new URL(`https://rest.izly.fr/Service/PublicService.svc/rest/GetHomePageOperations?transactionGroup=${kind}&top=${limit}`); | ||
const request: Request = { | ||
url, | ||
headers: { | ||
version: "2.0", | ||
channel: "AIZ", | ||
format: "T", | ||
model: "A", | ||
clientVersion: SERVICE_VERSION, | ||
smoneyClientType: CLIENT_TYPE, | ||
language: "fr", | ||
userId: identification.identifier, | ||
sessionId: identification.sessionID, | ||
"Authorization": `Bearer ${identification.accessToken}` | ||
} | ||
}; | ||
|
||
const response = await fetcher(request); | ||
const json = JSON.parse(response.content); | ||
|
||
return json.GetHomePageOperationsResult.Result.map((operation: any) => ({ | ||
id: operation.Id, | ||
amount: operation.Amount, | ||
date: decodeFormattedDate(operation.Date), | ||
isCredit: operation.IsCredit, | ||
message: operation.Message as string | null, | ||
type: operation.OperationType, | ||
status: operation.Status | ||
} as Operation)); | ||
}; | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const decodeFormattedDate = (date: string) => new Date(parseInt(date.substring(6, date.length - 2).split("+")[0])); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type Operation = Readonly<{ | ||
id: number | ||
amount: number | ||
date: Date | ||
isCredit: boolean | ||
message: string | null | ||
type: 2 | 7 | ||
status: number | ||
}>; | ||
|
||
// TODO: not sure what "type" means here, is it an enum ? | ||
|
||
// on operation 0: | ||
// "Message": "Carte bancaire", | ||
// "OperationType": 7 | ||
|
||
// on operation 2: | ||
// "Message": null, | ||
// "OperationType": 2, |