Skip to content

Commit

Permalink
fix(get): add support for tokens module
Browse files Browse the repository at this point in the history
  • Loading branch information
reinierl committed Jan 15, 2023
1 parent 73c85bc commit 01894c9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 42 deletions.
12 changes: 9 additions & 3 deletions src/ocpi-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ export const sessions: OcpiModule<"sessions"> = {
export const tariffs: OcpiModule<"tariffs"> = {
name: "tariffs",
};
export const tokens: OcpiModule<"tokens"> = {
name: "tokens",
};

// as opposed to the INPUT_PARTY_ID_REGEX, defined in login.ts, which is more
// lenient in order to be more suitable for human input
export const SESSION_PARTY_ID_REGEX = /^[A-Z]{2}[A-Z0-9]{3}$/;

export function getModuleByName(moduleName: string): OcpiModule<any> | null {
return (
[cdrs, locations, sessions, tariffs].find((m) => m.name === moduleName) ??
null
[cdrs, locations, sessions, tariffs, tokens].find(
(m) => m.name === moduleName
) ?? null
);
}

Expand Down Expand Up @@ -317,7 +321,9 @@ async function pullPageOfData<N extends ModuleID>(
? sess.partyId
: undefined;

const moduleUrl = sess.endpoints.find((ep) => ep.identifier === module.name);
const moduleUrl = sess.endpoints.find(
(ep) => ep.identifier === module.name && ep.role !== "RECEIVER"
);

if (moduleUrl) {
return ocpiRequest(
Expand Down
18 changes: 18 additions & 0 deletions src/privacy/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ export const chargingPeriodDescriptor: PrivacyDescriptor = {
tariff_id: "pass",
};

export const energyMixDescriptor: PrivacyDescriptor = {
is_green_energy: "na",
energy_sources: [
{
source: "na",
percentage: "na",
},
],
environ_impact: [
{
category: "na",
amount: "na",
},
],
supplier_name: "na",
energy_product_name: "na",
};

export const privateDisplayTextDescriptor: PrivacyDescriptor = {
language: "na",
text: "na",
Expand Down
3 changes: 2 additions & 1 deletion src/privacy/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { locationDescriptor } from "./location";
import { sessionDescriptor } from "./session";
import { cdrDescriptor } from "./cdr";
import { tariffDescriptor } from "./tariff";
import { tokenDescriptor } from "./token";

export type PrivacyDescriptor =
| ObjectDescriptor
Expand All @@ -27,7 +28,7 @@ export const modulePrivacyDescriptors: Record<
locations: locationDescriptor,
sessions: sessionDescriptor,
tariffs: tariffDescriptor,
tokens: null,
tokens: tokenDescriptor,
};

interface UnrecognizedPropertyError extends Error {
Expand Down
19 changes: 1 addition & 18 deletions src/privacy/location.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrivacyDescriptor } from "./filter";
import { energyMixDescriptor } from "./common";

const geoLocationDescriptor: PrivacyDescriptor = {
latitude: "na",
Expand All @@ -24,24 +25,6 @@ const passedImageDescriptor: PrivacyDescriptor = {
height: "pass",
};

const energyMixDescriptor: PrivacyDescriptor = {
is_green_energy: "na",
energy_sources: [
{
source: "na",
percentage: "na",
},
],
environ_impact: [
{
category: "na",
amount: "na",
},
],
supplier_name: "na",
energy_product_name: "na",
};

const displayTextDescriptor: PrivacyDescriptor = {
language: "na",
text: "na",
Expand Down
26 changes: 6 additions & 20 deletions src/privacy/tariff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { privateDisplayTextDescriptor, privatePriceDescriptor } from "./common";
import {
energyMixDescriptor,
privateDisplayTextDescriptor,
privatePriceDescriptor,
} from "./common";
import { PrivacyDescriptor } from "./filter";

const priceComponentDescriptor: PrivacyDescriptor = {
Expand Down Expand Up @@ -43,24 +47,6 @@ export const tariffDescriptor: PrivacyDescriptor = {
elements: [tariffElementDescriptor],
start_date_time: "na",
end_date_time: "na",
energy_mix: [
{
is_green_energy: "pass",
energy_sources: [
{
source: "pass",
percentage: "pass",
},
],
environ_impact: [
{
category: "pass",
amount: "pass",
},
],
supplier_name: "na",
energy_product_name: "na",
},
],
energy_mix: [energyMixDescriptor],
last_updated: "na",
};
24 changes: 24 additions & 0 deletions src/privacy/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PrivacyDescriptor } from "./filter";

const energyContractDescriptor: PrivacyDescriptor = {
supplier_name: "na",
contract_id: "na",
};

export const tokenDescriptor: PrivacyDescriptor = {
country_code: "pass",
party_id: "pass",
uid: "na",
type: "pass",
auth_id: "na",
contract_id: "na",
visual_number: "na",
issuer: "pass",
group_id: "na",
valid: "na",
whitelist: "pass",
language: "na",
default_profile_type: "na",
energy_contract: energyContractDescriptor,
last_updated: "na",
};

0 comments on commit 01894c9

Please sign in to comment.