@open-charging-cloud/chargy-core 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -101,7 +101,7 @@ npx playwright install chromium
101
101
 
102
102
 
103
103
  ```bash
104
- npm version 0.6.2 --no-git-tag-version
104
+ npm version 0.6.4 --no-git-tag-version
105
105
  npm run verify
106
106
  npm pack --dry-run
107
107
  npm pack
@@ -17993,39 +17993,53 @@ var Chargy = class {
17993
17993
  this.showPKIDetails = ShowPKIDetails;
17994
17994
  this.validationRules = validationRules;
17995
17995
  }
17996
- SetUILanguages(UILanguages) {
17997
- this.uiLanguages = this.NormalizeUILanguages(UILanguages);
17996
+ fileNameWithoutExtension(fileName) {
17997
+ const lastSeparator = Math.max(fileName.lastIndexOf("/"), fileName.lastIndexOf("\\"));
17998
+ const lastDot = fileName.lastIndexOf(".");
17999
+ if (lastDot > lastSeparator)
18000
+ return fileName.substring(0, lastDot);
18001
+ return fileName;
17998
18002
  }
17999
- NormalizeUILanguages(UILanguages) {
18000
- const languages = new Array();
18001
- for (const language of UILanguages) {
18002
- const normalized = language.trim();
18003
- if (normalized.length > 0 && !languages.includes(normalized)) {
18004
- languages.push(normalized);
18003
+ tryExtractChargeTransparencyTextFromURL(qrText) {
18004
+ if (!qrText.startsWith("http://") && !qrText.startsWith("https://"))
18005
+ return qrText;
18006
+ try {
18007
+ const url = new URL(qrText);
18008
+ const candidates = [
18009
+ url.hash.startsWith("#") ? url.hash.substring(1) : url.hash,
18010
+ url.searchParams.get("data"),
18011
+ url.searchParams.get("content"),
18012
+ url.searchParams.get("ctr"),
18013
+ url.searchParams.get("record"),
18014
+ url.searchParams.get("payload"),
18015
+ url.searchParams.get("q")
18016
+ ];
18017
+ for (const candidate of candidates) {
18018
+ const decodedCandidate = candidate != null ? decodeURIComponent(candidate).trim() : "";
18019
+ if (decodedCandidate.startsWith("<?xml") || decodedCandidate.startsWith("<values") || decodedCandidate.startsWith("{") || decodedCandidate.startsWith("[") || decodedCandidate.startsWith("OCMF") || decodedCandidate.startsWith("AP;")) {
18020
+ return decodedCandidate;
18021
+ }
18005
18022
  }
18023
+ } catch {
18024
+ console.log("Invalid URL in QR code: " + qrText);
18006
18025
  }
18007
- return languages.length > 0 ? languages : ["en"];
18026
+ return qrText;
18008
18027
  }
18009
- FindBestMultilanguageText(Text) {
18010
- for (const language of this.uiLanguages) {
18011
- const localLanguage = Text[language];
18012
- if (localLanguage !== void 0)
18013
- return localLanguage;
18028
+ tryExtractSignedDataTextFromXML(qrText) {
18029
+ const trimmedQRCodeText = qrText.trim();
18030
+ if (!trimmedQRCodeText.startsWith("<?xml") && !trimmedQRCodeText.startsWith("<"))
18031
+ return qrText;
18032
+ try {
18033
+ const xmlDocument = new DOMParser().parseFromString(trimmedQRCodeText, "text/xml");
18034
+ const signedDataValues = getElementsByLocalName(xmlDocument, "signedData").filter((signedData) => (signedData.getAttribute("format") ?? "").trim().toLowerCase() === "alfen").map((signedData) => signedData.textContent.trim()).filter((signedData) => signedData.startsWith("AP;"));
18035
+ if (signedDataValues.length > 0)
18036
+ return signedDataValues.join("\n");
18037
+ } catch {
18038
+ console.log("Error parsing XML content from QR code: " + qrText);
18014
18039
  }
18015
- const english = Text["en"];
18016
- if (english !== void 0)
18017
- return english;
18018
- return Object.values(Text).find((value) => value !== void 0);
18019
- }
18020
- CompleteMultilanguageText(Text, fallbackText) {
18021
- const result = {
18022
- ...Text ?? {}
18023
- };
18024
- const fallback = this.FindBestMultilanguageText(result) ?? fallbackText;
18025
- for (const language of this.uiLanguages)
18026
- result[language] ??= fallback;
18027
- return result;
18040
+ return qrText;
18028
18041
  }
18042
+ //#region Public key methods...
18029
18043
  PublicKeyIdFromFileName(fileName) {
18030
18044
  return (fileName.includes(".") ? fileName.substring(0, fileName.indexOf(".")) : fileName).replace(/[-_]?public[-_]?key/i, "");
18031
18045
  }
@@ -18108,66 +18122,13 @@ var Chargy = class {
18108
18122
  return textContent.replace(/\s+/g, "");
18109
18123
  return void 0;
18110
18124
  }
18125
+ //#endregion
18126
+ //#region QR code image files...
18111
18127
  isSupportedQRCodeImageFile(fileInfo, mimeType) {
18112
18128
  const mimeTypeToCheck = (mimeType ?? fileInfo.type ?? "").toLowerCase();
18113
18129
  const fileName = fileInfo.name.toLowerCase();
18114
18130
  return mimeTypeToCheck === "image/png" || mimeTypeToCheck === "image/jpeg" || mimeTypeToCheck === "image/jpg" || mimeTypeToCheck === "image/gif" || mimeTypeToCheck === "image/webp" || mimeTypeToCheck === "image/bmp" || mimeTypeToCheck === "image/svg+xml" || fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".gif") || fileName.endsWith(".webp") || fileName.endsWith(".bmp") || fileName.endsWith(".svg");
18115
18131
  }
18116
- fileNameWithoutExtension(fileName) {
18117
- const lastSeparator = Math.max(fileName.lastIndexOf("/"), fileName.lastIndexOf("\\"));
18118
- const lastDot = fileName.lastIndexOf(".");
18119
- if (lastDot > lastSeparator)
18120
- return fileName.substring(0, lastDot);
18121
- return fileName;
18122
- }
18123
- textFileNameForQRCodeContent(fileName, qrText) {
18124
- const trimmedQRCodeText = qrText.trimStart();
18125
- const baseFileName = this.fileNameWithoutExtension(fileName);
18126
- if (trimmedQRCodeText.startsWith("<?xml") || trimmedQRCodeText.startsWith("<"))
18127
- return baseFileName + ".xml";
18128
- if (trimmedQRCodeText.startsWith("{") || trimmedQRCodeText.startsWith("["))
18129
- return baseFileName + ".json";
18130
- return baseFileName + ".txt";
18131
- }
18132
- tryExtractChargeTransparencyTextFromURL(qrText) {
18133
- if (!qrText.startsWith("http://") && !qrText.startsWith("https://"))
18134
- return qrText;
18135
- try {
18136
- const url = new URL(qrText);
18137
- const candidates = [
18138
- url.hash.startsWith("#") ? url.hash.substring(1) : url.hash,
18139
- url.searchParams.get("data"),
18140
- url.searchParams.get("content"),
18141
- url.searchParams.get("ctr"),
18142
- url.searchParams.get("record"),
18143
- url.searchParams.get("payload"),
18144
- url.searchParams.get("q")
18145
- ];
18146
- for (const candidate of candidates) {
18147
- const decodedCandidate = candidate != null ? decodeURIComponent(candidate).trim() : "";
18148
- if (decodedCandidate.startsWith("<?xml") || decodedCandidate.startsWith("<values") || decodedCandidate.startsWith("{") || decodedCandidate.startsWith("[") || decodedCandidate.startsWith("OCMF") || decodedCandidate.startsWith("AP;")) {
18149
- return decodedCandidate;
18150
- }
18151
- }
18152
- } catch {
18153
- console.log("Invalid URL in QR code: " + qrText);
18154
- }
18155
- return qrText;
18156
- }
18157
- tryExtractSignedDataTextFromXML(qrText) {
18158
- const trimmedQRCodeText = qrText.trim();
18159
- if (!trimmedQRCodeText.startsWith("<?xml") && !trimmedQRCodeText.startsWith("<"))
18160
- return qrText;
18161
- try {
18162
- const xmlDocument = new DOMParser().parseFromString(trimmedQRCodeText, "text/xml");
18163
- const signedDataValues = getElementsByLocalName(xmlDocument, "signedData").filter((signedData) => (signedData.getAttribute("format") ?? "").trim().toLowerCase() === "alfen").map((signedData) => signedData.textContent.trim()).filter((signedData) => signedData.startsWith("AP;"));
18164
- if (signedDataValues.length > 0)
18165
- return signedDataValues.join("\n");
18166
- } catch {
18167
- console.log("Error parsing XML content from QR code: " + qrText);
18168
- }
18169
- return qrText;
18170
- }
18171
18132
  async expandQRCodeImageFiles(FileInfos) {
18172
18133
  const expandedFileInfos = new Array();
18173
18134
  for (const fileInfo of FileInfos) {
@@ -18199,7 +18160,50 @@ var Chargy = class {
18199
18160
  }
18200
18161
  return expandedFileInfos;
18201
18162
  }
18202
- //#region GetLocalizedMessages...
18163
+ textFileNameForQRCodeContent(fileName, qrText) {
18164
+ const trimmedQRCodeText = qrText.trimStart();
18165
+ const baseFileName = this.fileNameWithoutExtension(fileName);
18166
+ if (trimmedQRCodeText.startsWith("<?xml") || trimmedQRCodeText.startsWith("<"))
18167
+ return baseFileName + ".xml";
18168
+ if (trimmedQRCodeText.startsWith("{") || trimmedQRCodeText.startsWith("["))
18169
+ return baseFileName + ".json";
18170
+ return baseFileName + ".txt";
18171
+ }
18172
+ //#endregion
18173
+ //#region i18n...
18174
+ SetUILanguages(UILanguages) {
18175
+ this.uiLanguages = this.NormalizeUILanguages(UILanguages);
18176
+ }
18177
+ NormalizeUILanguages(UILanguages) {
18178
+ const languages = new Array();
18179
+ for (const language of UILanguages) {
18180
+ const normalized = language.trim();
18181
+ if (normalized.length > 0 && !languages.includes(normalized)) {
18182
+ languages.push(normalized);
18183
+ }
18184
+ }
18185
+ return languages.length > 0 ? languages : ["en"];
18186
+ }
18187
+ FindBestMultilanguageText(Text) {
18188
+ for (const language of this.uiLanguages) {
18189
+ const localLanguage = Text[language];
18190
+ if (localLanguage !== void 0)
18191
+ return localLanguage;
18192
+ }
18193
+ const english = Text["en"];
18194
+ if (english !== void 0)
18195
+ return english;
18196
+ return Object.values(Text).find((value) => value !== void 0);
18197
+ }
18198
+ CompleteMultilanguageText(Text, fallbackText) {
18199
+ const result = {
18200
+ ...Text ?? {}
18201
+ };
18202
+ const fallback = this.FindBestMultilanguageText(result) ?? fallbackText;
18203
+ for (const language of this.uiLanguages)
18204
+ result[language] ??= fallback;
18205
+ return result;
18206
+ }
18203
18207
  GetLocalizedMessage(Text) {
18204
18208
  const multiLanguage = this.i18n[Text];
18205
18209
  if (multiLanguage !== void 0) {
@@ -18233,6 +18237,11 @@ var Chargy = class {
18233
18237
  }
18234
18238
  return this.CompleteMultilanguageText(parameterizedText, Text.replace("%p", String(Parameter)));
18235
18239
  }
18240
+ GetLocalizedText(data) {
18241
+ if (data == null)
18242
+ return void 0;
18243
+ return this.FindBestMultilanguageText(data);
18244
+ }
18236
18245
  //#endregion
18237
18246
  //#region GetDevices...
18238
18247
  GetChargingPool = (Id) => {
@@ -18464,7 +18473,6 @@ var Chargy = class {
18464
18473
  } while (archiveFound);
18465
18474
  return expandedFileInfos;
18466
18475
  }
18467
- //#endregion
18468
18476
  async extractArchive(fileName, data, mimeType) {
18469
18477
  const archiveData = this.toUint8Array(data);
18470
18478
  if (mimeType === "application/zip")
@@ -18603,6 +18611,7 @@ var Chargy = class {
18603
18611
  const value = this.readTarString(data, offset, length).replace(/\0/g, "").trim();
18604
18612
  return value.length > 0 ? parseInt(value, 8) : 0;
18605
18613
  }
18614
+ //#endregion
18606
18615
  //#region DetectAndConvertContentFormat(FileInfos)
18607
18616
  async DetectAndConvertContentFormat(FileInfos) {
18608
18617
  if (FileInfos.length == 0) return {