regions-config 1.0.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 ADDED
@@ -0,0 +1,202 @@
1
+ # @iati/regions-config
2
+
3
+ Paquete de configuración de regiones para las aplicaciones de IATI. Proporciona la configuración completa de cada región (zona horaria, tipos de documento, métodos de pago, links de footer, países a redirigir, etc.) junto con utilidades tipadas para acceder a ella.
4
+
5
+ > ℹ️ Esta config la consumen los proyectos de purchase-funnel-widget y purchase-funnel (iati-backoffice-monorepo)
6
+
7
+ ## Regiones disponibles
8
+
9
+ | Clave | `regionCode` | Descripción |
10
+ | --------- | ------------ | ----------------------------- |
11
+ | `es` | `es-ES` | España |
12
+ | `commx` | `es-MX` | México |
13
+ | `comeneu` | `en-EU` | Internacional Europa (EN) |
14
+ | `comen` | `en-ROW` | Internacional resto del mundo |
15
+ | `it` | `it-IT` | Italia |
16
+ | `pt` | `pt-PT` | Portugal |
17
+ | `comco` | `es-CO` | Colombia |
18
+ | `compe` | `es-PE` | Perú |
19
+
20
+ ## Instalación
21
+
22
+ ```bash
23
+ npm install @iati/regions-config
24
+ # o
25
+ pnpm add @iati/regions-config
26
+ ```
27
+
28
+ El paquete tiene acceso restringido (`publishConfig.access: "restricted"`). Asegúrate de estar autenticado en npm con una cuenta con permisos sobre el scope `@iati`:
29
+
30
+ ```bash
31
+ npm login --scope=@iati
32
+ ```
33
+
34
+ ### Uso dentro del monorepo
35
+
36
+ Si lo consumes desde otra app o paquete del mismo workspace, puedes apuntar directamente a la versión local:
37
+
38
+ ```json
39
+ {
40
+ "dependencies": {
41
+ "@iati/regions-config": "workspace:*"
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `regionsConfig`
49
+
50
+ Objeto con la configuración completa de todas las regiones, ya validada con Zod.
51
+
52
+ ```ts
53
+ import { regionsConfig } from '@iati/regions-config';
54
+
55
+ const spain = regionsConfig['es'];
56
+ console.log(spain.regionCode); // 'es-ES'
57
+ ```
58
+
59
+ ---
60
+
61
+ ### `getRegionConfig(name: string): RegionConfig`
62
+
63
+ Obtiene la configuración de una región a partir de su clave (elimina guiones y barras del nombre). Esto se usa generalmente para recuperar la config con la property **short_name** que viene del backend en el endpoint de **commons (commons.site.short_name)**
64
+
65
+ ```ts
66
+ import { getRegionConfig } from '@iati/regions-config';
67
+
68
+ const config = getRegionConfig('com/co'); // equivalente a regionsConfig['comco']
69
+ ```
70
+
71
+ ---
72
+
73
+ ### `getRegionConfigById(id: number): RegionConfig`
74
+
75
+ Obtiene la configuración de una región por su `id` numérico. Lanza un error si no se encuentra.
76
+
77
+ ```ts
78
+ import { getRegionConfigById } from '@iati/regions-config';
79
+
80
+ const config = getRegionConfigById(1); // región España
81
+ ```
82
+
83
+ ---
84
+
85
+ ### `getRegionConfigByRegionCode(regionCode: RegionCode): RegionConfig`
86
+
87
+ Obtiene la configuración de una región por su `regionCode`. Lanza un error si el código no existe.
88
+
89
+ ```ts
90
+ import { getRegionConfigByRegionCode } from '@iati/regions-config';
91
+
92
+ const config = getRegionConfigByRegionCode('es-ES');
93
+ ```
94
+
95
+ ---
96
+
97
+ ### `validateRegion(region: RegionCode): void`
98
+
99
+ Valida que un `regionCode` sea válido. Lanza un error si no corresponde a ninguna región configurada.
100
+
101
+ ```ts
102
+ import { validateRegion } from '@iati/regions-config';
103
+
104
+ validateRegion('es-ES'); // OK
105
+ validateRegion('xx-XX'); // Error: Invalid region: xx-XX
106
+ ```
107
+
108
+ ---
109
+
110
+ ### `resolveDocumentTypeOptions(...): DocumentTypeOption[]`
111
+
112
+ Resuelve las opciones de tipo de documento en función del país de origen del usuario (local o extranjero).
113
+
114
+ ```ts
115
+ import { resolveDocumentTypeOptions } from '@iati/regions-config';
116
+
117
+ const options = resolveDocumentTypeOptions(
118
+ config.documentTypeOptions,
119
+ config.documentTypeOptionsByOrigin,
120
+ originCountryId,
121
+ siteCountryId,
122
+ );
123
+ ```
124
+
125
+ Si `documentTypeOptionsByOrigin` no está definido, devuelve el array `documentTypeOptions` base.
126
+
127
+ ---
128
+
129
+ ## Tipos principales
130
+
131
+ ```ts
132
+ type RegionConfig = {
133
+ id: number;
134
+ gtmId: string; // Formato: GTM-XXXXXXX
135
+ regionCode: 'es-ES' | 'es-MX' | 'en-EU' | 'en-ROW' | 'it-IT' | 'pt-PT' | 'es-CO' | 'es-PE';
136
+ timeZone: string;
137
+ dateFormat: string;
138
+ footer: Array<{ href: string; label: string }>;
139
+ documentTypeOptions: Array<{ label: string; value: string }>;
140
+ documentTypeOptionsByOrigin?: DocumentTypeOptionsByOrigin;
141
+ paymentCardTypes: Array<{ id: number; name: string; imagePath: string }>;
142
+ countriesToRedirect?: CountriesToRedirectMap;
143
+ regionsToGroup?: RegionToGroup[];
144
+ regionUrls?: { staging: string; production: string };
145
+ webSitePath?: string;
146
+ };
147
+ ```
148
+
149
+ ## Constantes exportadas
150
+
151
+ | Constante | Descripción |
152
+ | --------------------------- | --------------------------------------- |
153
+ | `GROUP_REGIONS` | IDs numéricos de los grupos de regiones |
154
+ | `EUROPE_COUNTRIES` | Array de IDs de países europeos |
155
+ | `US_CANADA_COUNTRIES` | Array de IDs de EE.UU. y Canadá |
156
+ | `US_CANADA_JAPAN_COUNTRIES` | Array de IDs de EE.UU., Canadá y Japón |
157
+ | `WORLD_COUNTRIES` | Array de IDs del resto del mundo |
158
+
159
+ ## Estructura del paquete
160
+
161
+ ```
162
+ src/
163
+ ├── const.ts # Constantes de países y grupos de regiones
164
+ ├── index.ts # Punto de entrada y re-exports
165
+ ├── regionsConfig.ts # Construcción del objeto de configuración
166
+ ├── domain/
167
+ │ └── RegionConfigSchema.ts # Schema Zod y tipos TypeScript
168
+ ├── regions/
169
+ │ ├── es.json # Config España
170
+ │ ├── commx.json # Config México
171
+ │ ├── comeneu.json # Config Internacional Europa
172
+ │ ├── comen.json # Config Internacional resto del mundo
173
+ │ ├── it.json # Config Italia
174
+ │ ├── pt.json # Config Portugal
175
+ │ ├── comco.json # Config Colombia
176
+ │ ├── compe.json # Config Perú
177
+ │ └── index.ts
178
+ ├── utils/
179
+ │ ├── getRegionConfig.ts
180
+ │ ├── getRegionConfigById.ts
181
+ │ ├── getRegionConfigByRegionCode.ts
182
+ │ └── resolveDocumentTypeOptions.ts
183
+ └── validators/
184
+ └── validateRegion.ts
185
+ ```
186
+
187
+ ## Scripts
188
+
189
+ ```bash
190
+ # Compilar el paquete
191
+ pnpm build
192
+
193
+ # Modo watch (desarrollo)
194
+ pnpm dev
195
+
196
+ # Limpiar artefactos
197
+ pnpm clean
198
+ ```
199
+
200
+ ## Validación
201
+
202
+ La configuración de cada región es validada en tiempo de build con **Zod** (`RegionConfigSchema`). Cualquier JSON de región mal formado lanzará un error de validación al importar el paquete.
@@ -0,0 +1,294 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const GROUP_REGIONS: Record<string, number>;
4
+ declare const EUROPE_COUNTRIES: number[];
5
+ declare const US_CANADA_JAPAN_COUNTRIES: number[];
6
+ declare const US_CANADA_COUNTRIES: number[];
7
+ declare const WORLD_COUNTRIES: number[];
8
+
9
+ type DocumentTypeOption = {
10
+ label: string;
11
+ value: string;
12
+ };
13
+ type DocumentTypeOptionsByOrigin = {
14
+ local: Array<DocumentTypeOption>;
15
+ foreign: Array<DocumentTypeOption>;
16
+ };
17
+ type RedirectCountry = {
18
+ countryId: string;
19
+ name?: string;
20
+ };
21
+ type RedirectGroup = {
22
+ label: string;
23
+ countries: Array<RedirectCountry>;
24
+ };
25
+ type CountryToRedirect = {
26
+ countryId: string;
27
+ countryRegion: string;
28
+ regionLabel: string;
29
+ name?: string;
30
+ };
31
+ type RegionToGroup = {
32
+ priority: 'high' | 'medium' | 'low';
33
+ countries: number[];
34
+ regionId: number;
35
+ };
36
+ type PaymentCardType = {
37
+ id: number;
38
+ name: string;
39
+ imagePath: string;
40
+ };
41
+ declare const RegionConfigSchema: z.ZodObject<{
42
+ id: z.ZodNumber;
43
+ gtmId: z.ZodString;
44
+ countriesToRedirect: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
45
+ label: z.ZodString;
46
+ countries: z.ZodArray<z.ZodObject<{
47
+ countryId: z.ZodString;
48
+ name: z.ZodOptional<z.ZodString>;
49
+ }, "strip", z.ZodTypeAny, {
50
+ countryId: string;
51
+ name?: string | undefined;
52
+ }, {
53
+ countryId: string;
54
+ name?: string | undefined;
55
+ }>, "many">;
56
+ }, "strip", z.ZodTypeAny, {
57
+ label: string;
58
+ countries: {
59
+ countryId: string;
60
+ name?: string | undefined;
61
+ }[];
62
+ }, {
63
+ label: string;
64
+ countries: {
65
+ countryId: string;
66
+ name?: string | undefined;
67
+ }[];
68
+ }>>>;
69
+ regionUrls: z.ZodOptional<z.ZodObject<{
70
+ staging: z.ZodString;
71
+ production: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ staging: string;
74
+ production: string;
75
+ }, {
76
+ staging: string;
77
+ production: string;
78
+ }>>;
79
+ timeZone: z.ZodString;
80
+ regionsToGroup: z.ZodOptional<z.ZodArray<z.ZodObject<{
81
+ priority: z.ZodEnum<["high", "medium", "low"]>;
82
+ countries: z.ZodArray<z.ZodNumber, "many">;
83
+ regionId: z.ZodNumber;
84
+ }, "strip", z.ZodTypeAny, {
85
+ countries: number[];
86
+ priority: "high" | "medium" | "low";
87
+ regionId: number;
88
+ }, {
89
+ countries: number[];
90
+ priority: "high" | "medium" | "low";
91
+ regionId: number;
92
+ }>, "many">>;
93
+ footer: z.ZodArray<z.ZodObject<{
94
+ href: z.ZodString;
95
+ label: z.ZodString;
96
+ }, "strip", z.ZodTypeAny, {
97
+ label: string;
98
+ href: string;
99
+ }, {
100
+ label: string;
101
+ href: string;
102
+ }>, "many">;
103
+ documentTypeOptions: z.ZodArray<z.ZodObject<{
104
+ label: z.ZodString;
105
+ value: z.ZodString;
106
+ }, "strip", z.ZodTypeAny, {
107
+ value: string;
108
+ label: string;
109
+ }, {
110
+ value: string;
111
+ label: string;
112
+ }>, "many">;
113
+ documentTypeOptionsByOrigin: z.ZodOptional<z.ZodObject<{
114
+ local: z.ZodArray<z.ZodObject<{
115
+ label: z.ZodString;
116
+ value: z.ZodString;
117
+ }, "strip", z.ZodTypeAny, {
118
+ value: string;
119
+ label: string;
120
+ }, {
121
+ value: string;
122
+ label: string;
123
+ }>, "many">;
124
+ foreign: z.ZodArray<z.ZodObject<{
125
+ label: z.ZodString;
126
+ value: z.ZodString;
127
+ }, "strip", z.ZodTypeAny, {
128
+ value: string;
129
+ label: string;
130
+ }, {
131
+ value: string;
132
+ label: string;
133
+ }>, "many">;
134
+ }, "strip", z.ZodTypeAny, {
135
+ local: {
136
+ value: string;
137
+ label: string;
138
+ }[];
139
+ foreign: {
140
+ value: string;
141
+ label: string;
142
+ }[];
143
+ }, {
144
+ local: {
145
+ value: string;
146
+ label: string;
147
+ }[];
148
+ foreign: {
149
+ value: string;
150
+ label: string;
151
+ }[];
152
+ }>>;
153
+ dateFormat: z.ZodString;
154
+ regionCode: z.ZodEnum<["es-ES", "es-MX", "en-EU", "en-ROW", "it-IT", "pt-PT", "es-CO", "es-PE"]>;
155
+ paymentCardTypes: z.ZodArray<z.ZodObject<{
156
+ id: z.ZodNumber;
157
+ name: z.ZodString;
158
+ imagePath: z.ZodString;
159
+ }, "strip", z.ZodTypeAny, {
160
+ id: number;
161
+ name: string;
162
+ imagePath: string;
163
+ }, {
164
+ id: number;
165
+ name: string;
166
+ imagePath: string;
167
+ }>, "many">;
168
+ webSitePath: z.ZodOptional<z.ZodString>;
169
+ }, "strict", z.ZodTypeAny, {
170
+ id: number;
171
+ gtmId: string;
172
+ timeZone: string;
173
+ footer: {
174
+ label: string;
175
+ href: string;
176
+ }[];
177
+ documentTypeOptions: {
178
+ value: string;
179
+ label: string;
180
+ }[];
181
+ dateFormat: string;
182
+ regionCode: "es-ES" | "es-MX" | "en-EU" | "en-ROW" | "it-IT" | "pt-PT" | "es-CO" | "es-PE";
183
+ paymentCardTypes: {
184
+ id: number;
185
+ name: string;
186
+ imagePath: string;
187
+ }[];
188
+ countriesToRedirect?: Record<string, {
189
+ label: string;
190
+ countries: {
191
+ countryId: string;
192
+ name?: string | undefined;
193
+ }[];
194
+ }> | undefined;
195
+ regionUrls?: {
196
+ staging: string;
197
+ production: string;
198
+ } | undefined;
199
+ regionsToGroup?: {
200
+ countries: number[];
201
+ priority: "high" | "medium" | "low";
202
+ regionId: number;
203
+ }[] | undefined;
204
+ documentTypeOptionsByOrigin?: {
205
+ local: {
206
+ value: string;
207
+ label: string;
208
+ }[];
209
+ foreign: {
210
+ value: string;
211
+ label: string;
212
+ }[];
213
+ } | undefined;
214
+ webSitePath?: string | undefined;
215
+ }, {
216
+ id: number;
217
+ gtmId: string;
218
+ timeZone: string;
219
+ footer: {
220
+ label: string;
221
+ href: string;
222
+ }[];
223
+ documentTypeOptions: {
224
+ value: string;
225
+ label: string;
226
+ }[];
227
+ dateFormat: string;
228
+ regionCode: "es-ES" | "es-MX" | "en-EU" | "en-ROW" | "it-IT" | "pt-PT" | "es-CO" | "es-PE";
229
+ paymentCardTypes: {
230
+ id: number;
231
+ name: string;
232
+ imagePath: string;
233
+ }[];
234
+ countriesToRedirect?: Record<string, {
235
+ label: string;
236
+ countries: {
237
+ countryId: string;
238
+ name?: string | undefined;
239
+ }[];
240
+ }> | undefined;
241
+ regionUrls?: {
242
+ staging: string;
243
+ production: string;
244
+ } | undefined;
245
+ regionsToGroup?: {
246
+ countries: number[];
247
+ priority: "high" | "medium" | "low";
248
+ regionId: number;
249
+ }[] | undefined;
250
+ documentTypeOptionsByOrigin?: {
251
+ local: {
252
+ value: string;
253
+ label: string;
254
+ }[];
255
+ foreign: {
256
+ value: string;
257
+ label: string;
258
+ }[];
259
+ } | undefined;
260
+ webSitePath?: string | undefined;
261
+ }>;
262
+ type CountriesToRedirectMap = Record<string, RedirectGroup>;
263
+ type RegionConfig = Omit<z.infer<typeof RegionConfigSchema>, 'countriesToRedirect'> & {
264
+ countriesToRedirect?: CountriesToRedirectMap;
265
+ };
266
+ type RegionsConfig = {
267
+ [key: string]: RegionConfig;
268
+ };
269
+ type RegionConfigJson = Omit<RegionConfig, 'regionsToGroup' | 'footer' | 'regionCode'> & {
270
+ regionCode: string;
271
+ regionsToGroup?: Array<{
272
+ priority: string;
273
+ countries: string;
274
+ regionId: string;
275
+ }>;
276
+ footer: Array<{
277
+ href: string;
278
+ label: string;
279
+ }>;
280
+ };
281
+
282
+ declare const regionsConfig: RegionsConfig;
283
+
284
+ declare const getRegionConfig: (name: string) => RegionConfig;
285
+
286
+ declare const getRegionConfigById: (id: number) => RegionConfig;
287
+
288
+ declare const getRegionConfigByRegionCode: (regionCode: RegionConfig["regionCode"]) => RegionConfig;
289
+
290
+ declare const resolveDocumentTypeOptions: (documentTypeOptions: Array<DocumentTypeOption>, documentTypeOptionsByOrigin?: DocumentTypeOptionsByOrigin, originCountryId?: string | number, siteCountryId?: number) => Array<DocumentTypeOption>;
291
+
292
+ declare const validateRegion: (region: RegionConfig["regionCode"]) => void;
293
+
294
+ export { type CountriesToRedirectMap, type CountryToRedirect, type DocumentTypeOption, type DocumentTypeOptionsByOrigin, EUROPE_COUNTRIES, GROUP_REGIONS, type PaymentCardType, type RedirectCountry, type RedirectGroup, type RegionConfig, type RegionConfigJson, RegionConfigSchema, type RegionToGroup, type RegionsConfig, US_CANADA_COUNTRIES, US_CANADA_JAPAN_COUNTRIES, WORLD_COUNTRIES, getRegionConfig, getRegionConfigById, getRegionConfigByRegionCode, regionsConfig, resolveDocumentTypeOptions, validateRegion };