@cobre-npm/library-portal-core 0.64.0 → 0.65.0
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
|
@@ -706,12 +706,14 @@ import {
|
|
|
706
706
|
import {
|
|
707
707
|
getFinancialInstitutions, queryFinancialInstitutions,
|
|
708
708
|
type FinancialInstitution, type FinancialInstitutionGeo,
|
|
709
|
-
type
|
|
709
|
+
type FinancialInstitutionCatalog, type FinancialInstitutionOption, type FinancialInstitutionQuery,
|
|
710
|
+
type FinancialInstitutionScope,
|
|
710
711
|
} from "@cobre-npm/library-portal-core/financialInstitutions"
|
|
711
712
|
|
|
712
713
|
getFinancialInstitutions("en").pr_col_1007 // { code: "pr_col_1007", rawCode: "1007", geo: "col", label: "Bancolombia" }
|
|
713
714
|
queryFinancialInstitutions({ lang: "en", geo: "col" }) // FinancialInstitutionOption[] → every COL institution
|
|
714
715
|
queryFinancialInstitutions({ lang: "en", geo: "col", scope: "checkout" }) // → only the COL ones the checkout offers
|
|
716
|
+
getFinancialInstitutions("en")[`pr_col_${bankCode}`]?.label ?? bankCode // bankCode: string from an API payload, no cast
|
|
715
717
|
```
|
|
716
718
|
|
|
717
719
|
- **institutions** (i18n): `getFinancialInstitutions(lang)`; each record carries `code`, `rawCode`, `geo`
|
|
@@ -728,6 +730,11 @@ queryFinancialInstitutions({ lang: "en", geo: "col", scope: "checkout" }) // →
|
|
|
728
730
|
- `scope` (`"checkout"`, optional on the record) marks the subset of institutions the checkout offers for PSE.
|
|
729
731
|
Unlike `scope` in `currencies` it has **no default**: leaving it out returns the whole catalog, and
|
|
730
732
|
`scope: "checkout"` narrows it. An institution without `scope` is not offered in the checkout.
|
|
733
|
+
- `getFinancialInstitutions(lang)` is also indexable by a plain `string`, for codes that arrive from a payload
|
|
734
|
+
(`pr_<geo>_<rawCode>` built from a bare bank code): a known code stays non-optional, any other
|
|
735
|
+
string reads as `FinancialInstitutionOption | undefined`, so an unknown code is handled with `?.` and no cast.
|
|
736
|
+
The catch is `Object.values(getFinancialInstitutions(lang))`, which is then typed
|
|
737
|
+
`(FinancialInstitutionOption | undefined)[]`: for a list use `queryFinancialInstitutions`.
|
|
731
738
|
- Bank names have no real translation between `en` and `es-mex`: `es-mex` keeps the name as published by
|
|
732
739
|
the source (accented characters included, e.g. `"Banco de Bogotá"`), `en` is the same string with
|
|
733
740
|
special Spanish characters stripped (`"Banco de Bogota"`) rather than left untranslated with accents.
|
|
@@ -4,11 +4,18 @@ import type { CatalogQuery } from "../../utils/catalog-query.utils";
|
|
|
4
4
|
export type FinancialInstitutionOption = FinancialInstitutionRecord & {
|
|
5
5
|
label: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* The catalog by code. Indexed by a plain string (e.g. a code from an API payload) instead of a known code,
|
|
9
|
+
* the lookup is `FinancialInstitutionOption | undefined`, so an unknown code needs no cast to be handled.
|
|
10
|
+
*/
|
|
11
|
+
export interface FinancialInstitutionCatalog extends Record<FinancialInstitution, FinancialInstitutionOption> {
|
|
12
|
+
[code: string]: FinancialInstitutionOption | undefined;
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* The catalog indexed by code (same shape as FINANCIAL_INSTITUTIONS), each record enriched
|
|
9
|
-
* with its label for the given language. Access by code directly
|
|
16
|
+
* with its label for the given language. Access by code directly; for a list use `queryFinancialInstitutions`.
|
|
10
17
|
*/
|
|
11
|
-
export declare const getFinancialInstitutions: (lang: Locale) =>
|
|
18
|
+
export declare const getFinancialInstitutions: (lang: Locale) => FinancialInstitutionCatalog;
|
|
12
19
|
/** `lang` is required (i18n domain, no default) and travels inside the query object, never positional. */
|
|
13
20
|
export type FinancialInstitutionQuery = CatalogQuery<FinancialInstitutionRecord> & {
|
|
14
21
|
lang: Locale;
|
|
@@ -9,11 +9,8 @@ const en_json_1 = __importDefault(require("../locales/en.json"));
|
|
|
9
9
|
const es_mex_json_1 = __importDefault(require("../locales/es-mex.json"));
|
|
10
10
|
const catalog_query_utils_1 = require("../../utils/catalog-query.utils");
|
|
11
11
|
const locales = { en: en_json_1.default, "es-mex": es_mex_json_1.default };
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* with its label for the given language. Access by code directly, or Object.values for a list.
|
|
15
|
-
*/
|
|
16
|
-
const getFinancialInstitutions = (lang) => {
|
|
12
|
+
// Built with the strict type so `queryFinancialInstitutions` lists it without the string index signature.
|
|
13
|
+
const buildFinancialInstitutions = (lang) => {
|
|
17
14
|
const locale = locales[lang];
|
|
18
15
|
const result = {};
|
|
19
16
|
for (const record of Object.values(catalog_1.FINANCIAL_INSTITUTIONS)) {
|
|
@@ -21,11 +18,15 @@ const getFinancialInstitutions = (lang) => {
|
|
|
21
18
|
}
|
|
22
19
|
return result;
|
|
23
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The catalog indexed by code (same shape as FINANCIAL_INSTITUTIONS), each record enriched
|
|
23
|
+
* with its label for the given language. Access by code directly; for a list use `queryFinancialInstitutions`.
|
|
24
|
+
*/
|
|
25
|
+
const getFinancialInstitutions = (lang) => buildFinancialInstitutions(lang);
|
|
24
26
|
exports.getFinancialInstitutions = getFinancialInstitutions;
|
|
25
27
|
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
26
28
|
const queryFinancialInstitutions = (query) => {
|
|
27
29
|
const { lang, ...criteria } = query;
|
|
28
|
-
|
|
29
|
-
return Object.values(institutions).filter(institution => (0, catalog_query_utils_1.matchesQuery)(institution, criteria));
|
|
30
|
+
return Object.values(buildFinancialInstitutions(lang)).filter(institution => (0, catalog_query_utils_1.matchesQuery)(institution, criteria));
|
|
30
31
|
};
|
|
31
32
|
exports.queryFinancialInstitutions = queryFinancialInstitutions;
|
|
@@ -3,11 +3,8 @@ import enLocale from "../locales/en.json";
|
|
|
3
3
|
import esMexLocale from "../locales/es-mex.json";
|
|
4
4
|
import { matchesQuery } from "../../utils/catalog-query.utils";
|
|
5
5
|
const locales = { en: enLocale, "es-mex": esMexLocale };
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* with its label for the given language. Access by code directly, or Object.values for a list.
|
|
9
|
-
*/
|
|
10
|
-
export const getFinancialInstitutions = (lang) => {
|
|
6
|
+
// Built with the strict type so `queryFinancialInstitutions` lists it without the string index signature.
|
|
7
|
+
const buildFinancialInstitutions = (lang) => {
|
|
11
8
|
const locale = locales[lang];
|
|
12
9
|
const result = {};
|
|
13
10
|
for (const record of Object.values(FINANCIAL_INSTITUTIONS)) {
|
|
@@ -15,9 +12,13 @@ export const getFinancialInstitutions = (lang) => {
|
|
|
15
12
|
}
|
|
16
13
|
return result;
|
|
17
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* The catalog indexed by code (same shape as FINANCIAL_INSTITUTIONS), each record enriched
|
|
17
|
+
* with its label for the given language. Access by code directly; for a list use `queryFinancialInstitutions`.
|
|
18
|
+
*/
|
|
19
|
+
export const getFinancialInstitutions = (lang) => buildFinancialInstitutions(lang);
|
|
18
20
|
/** The catalog as a list, narrowed by the query — see `matchesQuery` for the matching rules. */
|
|
19
21
|
export const queryFinancialInstitutions = (query) => {
|
|
20
22
|
const { lang, ...criteria } = query;
|
|
21
|
-
|
|
22
|
-
return Object.values(institutions).filter(institution => matchesQuery(institution, criteria));
|
|
23
|
+
return Object.values(buildFinancialInstitutions(lang)).filter(institution => matchesQuery(institution, criteria));
|
|
23
24
|
};
|