@intlayer/config 1.2.1 → 2.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.
Files changed (64) hide show
  1. package/dist/cjs/client.cjs.map +1 -1
  2. package/dist/cjs/client.d.ts +1 -1
  3. package/dist/cjs/configFile/buildConfigurationFields.cjs +20 -1
  4. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
  5. package/dist/cjs/defaultValues/editor.cjs +29 -0
  6. package/dist/cjs/defaultValues/editor.cjs.map +1 -0
  7. package/dist/cjs/defaultValues/editor.d.ts +3 -0
  8. package/dist/cjs/defaultValues/internationalization.cjs +5 -2
  9. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
  10. package/dist/cjs/defaultValues/internationalization.d.ts +3 -1
  11. package/dist/cjs/envVariables/extractEnvVariable/next.cjs +6 -1
  12. package/dist/cjs/envVariables/extractEnvVariable/next.cjs.map +1 -1
  13. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs +6 -1
  14. package/dist/cjs/envVariables/extractEnvVariable/react_app.cjs.map +1 -1
  15. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs +6 -1
  16. package/dist/cjs/envVariables/extractEnvVariable/undefined_platform.cjs.map +1 -1
  17. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs +6 -1
  18. package/dist/cjs/envVariables/extractEnvVariable/vite.cjs.map +1 -1
  19. package/dist/cjs/envVariables/formatEnvVariable.cjs +2 -1
  20. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -1
  21. package/dist/cjs/envVariables/getConfiguration.cjs +9 -1
  22. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -1
  23. package/dist/cjs/index.cjs.map +1 -1
  24. package/dist/cjs/index.d.ts +1 -1
  25. package/dist/cjs/types/config.cjs.map +1 -1
  26. package/dist/cjs/types/config.d.ts +32 -1
  27. package/dist/esm/client.d.mts +1 -1
  28. package/dist/esm/client.mjs.map +1 -1
  29. package/dist/esm/configFile/buildConfigurationFields.mjs +25 -2
  30. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
  31. package/dist/esm/defaultValues/editor.d.mts +3 -0
  32. package/dist/esm/defaultValues/editor.mjs +5 -0
  33. package/dist/esm/defaultValues/editor.mjs.map +1 -0
  34. package/dist/esm/defaultValues/internationalization.d.mts +3 -1
  35. package/dist/esm/defaultValues/internationalization.mjs +3 -1
  36. package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
  37. package/dist/esm/envVariables/extractEnvVariable/next.mjs +6 -1
  38. package/dist/esm/envVariables/extractEnvVariable/next.mjs.map +1 -1
  39. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs +6 -1
  40. package/dist/esm/envVariables/extractEnvVariable/react_app.mjs.map +1 -1
  41. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs +6 -1
  42. package/dist/esm/envVariables/extractEnvVariable/undefined_platform.mjs.map +1 -1
  43. package/dist/esm/envVariables/extractEnvVariable/vite.mjs +6 -1
  44. package/dist/esm/envVariables/extractEnvVariable/vite.mjs.map +1 -1
  45. package/dist/esm/envVariables/formatEnvVariable.mjs +2 -1
  46. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -1
  47. package/dist/esm/envVariables/getConfiguration.mjs +9 -1
  48. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -1
  49. package/dist/esm/index.d.mts +1 -1
  50. package/dist/esm/index.mjs.map +1 -1
  51. package/dist/esm/types/config.d.mts +32 -1
  52. package/package.json +2 -2
  53. package/src/client.ts +4 -4
  54. package/src/configFile/buildConfigurationFields.ts +30 -1
  55. package/src/defaultValues/editor.ts +1 -0
  56. package/src/defaultValues/internationalization.ts +3 -0
  57. package/src/envVariables/extractEnvVariable/next.ts +7 -0
  58. package/src/envVariables/extractEnvVariable/react_app.ts +7 -0
  59. package/src/envVariables/extractEnvVariable/undefined_platform.ts +7 -0
  60. package/src/envVariables/extractEnvVariable/vite.ts +7 -0
  61. package/src/envVariables/formatEnvVariable.ts +1 -0
  62. package/src/envVariables/getConfiguration.ts +10 -0
  63. package/src/index.ts +1 -0
  64. package/src/types/config.ts +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/config",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "description": "Shared configuration package for IntLayer - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
6
6
  "keywords": [
@@ -57,7 +57,7 @@
57
57
  "@types/node": "^20.12.7",
58
58
  "esbuild": "^0.20.2",
59
59
  "swc-loader": "^0.2.6",
60
- "intlayer": "^1.2.1"
60
+ "intlayer": "^2.0.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rimraf": "5.0.5",
package/src/client.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export type {
2
2
  CustomIntlayerConfig,
3
- PatternsContentConfig as FixedIntlayerConfig,
3
+ PatternsContentConfig,
4
4
  IntlayerConfig,
5
- BaseContentConfig as NotDerivedConfiguration,
6
- BaseDerivedConfig as BaseDirDerivedConfiguration,
7
- ResultDirDerivedConfig as ResultDirDerivedConfiguration,
5
+ BaseContentConfig,
6
+ BaseDerivedConfig,
7
+ ResultDirDerivedConfig,
8
8
  } from './types/config';
9
9
  export type { LocalesValues } from './types/locales';
10
10
  export { Locales } from './types/locales';
@@ -1,5 +1,9 @@
1
1
  import { join } from 'path';
2
- import { DEFAULT_LOCALE, LOCALES } from '../defaultValues/internationalization';
2
+ import {
3
+ DEFAULT_LOCALE,
4
+ LOCALES,
5
+ STRICT_MODE,
6
+ } from '../defaultValues/internationalization';
3
7
  import {
4
8
  BASE_PATH,
5
9
  COOKIE_NAME,
@@ -30,6 +34,7 @@ import type {
30
34
  MiddlewareConfig,
31
35
  BaseContentConfig,
32
36
  ResultDirDerivedConfig,
37
+ EditorConfig,
33
38
  } from '../types/config';
34
39
  import type { GetConfigurationOptions } from './getConfiguration';
35
40
 
@@ -48,6 +53,16 @@ const buildInternationalizationFields = (
48
53
  */
49
54
  locales: customConfiguration?.locales ?? LOCALES,
50
55
 
56
+ /**
57
+ * Ensure strong implementations of internationalized content using typescript.
58
+ * - If set to "strict", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
59
+ * - If set to "required_only", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.
60
+ * - If set to "loose", the translation `t` function will accept any existing locale.
61
+ *
62
+ * Default: "required_only"
63
+ */
64
+ strictMode: customConfiguration?.strictMode ?? STRICT_MODE,
65
+
51
66
  /**
52
67
  * Default locale of the application for fallback
53
68
  *
@@ -447,6 +462,17 @@ const buildContentFields = (
447
462
  };
448
463
  };
449
464
 
465
+ const buildEditorFields = (
466
+ customConfiguration?: Partial<EditorConfig>
467
+ ): EditorConfig => ({
468
+ /**
469
+ * Port of the editor server
470
+ *
471
+ * Default: 4000
472
+ */
473
+ port: customConfiguration?.port ?? 4000,
474
+ });
475
+
450
476
  /**
451
477
  * Build the configuration fields by merging the default values with the custom configuration
452
478
  */
@@ -464,10 +490,13 @@ export const buildConfigurationFields = (
464
490
 
465
491
  const contentConfig = buildContentFields(customConfiguration?.content);
466
492
 
493
+ const editorConfig = buildEditorFields(customConfiguration?.editor);
494
+
467
495
  storedConfiguration = {
468
496
  internationalization: internationalizationConfig,
469
497
  middleware: middlewareConfig,
470
498
  content: contentConfig,
499
+ editor: editorConfig,
471
500
  };
472
501
 
473
502
  return storedConfiguration;
@@ -0,0 +1 @@
1
+ export const PORT = 4000;
@@ -1,5 +1,8 @@
1
+ import type { StrictMode } from '../types/config';
1
2
  import { Locales } from '../types/locales';
2
3
 
3
4
  export const LOCALES: Locales[] = [Locales.ENGLISH];
4
5
 
5
6
  export const DEFAULT_LOCALE: Locales = Locales.ENGLISH;
7
+
8
+ export const STRICT_MODE: StrictMode = 'required_only';
@@ -2,12 +2,14 @@ import type {
2
2
  InternationalizationConfig,
3
3
  MiddlewareConfig,
4
4
  ContentConfig,
5
+ EditorConfig,
5
6
  } from '../../types/config';
6
7
  import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
8
 
8
9
  export const extractNextEnvVariable = (): IntlayerConfigEnvVariable => {
9
10
  const internationalization: ReplaceValue<InternationalizationConfig> = {
10
11
  locales: process.env.NEXT_PUBLIC_INTLAYER_LOCALES,
12
+ strictMode: process.env.NEXT_PUBLIC_INTLAYER_STRICT_MODE,
11
13
  defaultLocale: process.env.NEXT_PUBLIC_INTLAYER_DEFAULT_LOCALE,
12
14
  };
13
15
 
@@ -49,9 +51,14 @@ export const extractNextEnvVariable = (): IntlayerConfigEnvVariable => {
49
51
  dictionaryOutput: process.env.NEXT_PUBLIC_INTLAYER_DICTIONARY_OUTPUT,
50
52
  };
51
53
 
54
+ const editor: ReplaceValue<EditorConfig> = {
55
+ port: process.env.NEXT_PUBLIC_INTLAYER_PORT,
56
+ };
57
+
52
58
  return {
53
59
  internationalization,
54
60
  middleware,
55
61
  content,
62
+ editor,
56
63
  };
57
64
  };
@@ -2,12 +2,14 @@ import type {
2
2
  InternationalizationConfig,
3
3
  MiddlewareConfig,
4
4
  ContentConfig,
5
+ EditorConfig,
5
6
  } from '../../types/config';
6
7
  import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
8
 
8
9
  export const extractReactAppEnvVariable = (): IntlayerConfigEnvVariable => {
9
10
  const internationalization: ReplaceValue<InternationalizationConfig> = {
10
11
  locales: process.env.REACT_APP_INTLAYER_LOCALES,
12
+ strictMode: process.env.REACT_APP_INTLAYER_STRICT_MODE,
11
13
  defaultLocale: process.env.REACT_APP_INTLAYER_DEFAULT_LOCALE,
12
14
  };
13
15
 
@@ -49,9 +51,14 @@ export const extractReactAppEnvVariable = (): IntlayerConfigEnvVariable => {
49
51
  dictionaryOutput: process.env.REACT_APP_INTLAYER_DICTIONARY_OUTPUT,
50
52
  };
51
53
 
54
+ const editor: ReplaceValue<EditorConfig> = {
55
+ port: process.env.REACT_APP_INTLAYER_PORT,
56
+ };
57
+
52
58
  return {
53
59
  internationalization,
54
60
  middleware,
55
61
  content,
62
+ editor,
56
63
  };
57
64
  };
@@ -2,12 +2,14 @@ import type {
2
2
  InternationalizationConfig,
3
3
  MiddlewareConfig,
4
4
  ContentConfig,
5
+ EditorConfig,
5
6
  } from '../../types/config';
6
7
  import type { ReplaceValue, IntlayerConfigEnvVariable } from './types';
7
8
 
8
9
  export const extractEmptyEnvVariable = (): IntlayerConfigEnvVariable => {
9
10
  const internationalization: ReplaceValue<InternationalizationConfig> = {
10
11
  locales: undefined,
12
+ strictMode: undefined,
11
13
  defaultLocale: undefined,
12
14
  };
13
15
 
@@ -44,9 +46,14 @@ export const extractEmptyEnvVariable = (): IntlayerConfigEnvVariable => {
44
46
  dictionaryOutput: undefined,
45
47
  };
46
48
 
49
+ const editor: ReplaceValue<EditorConfig> = {
50
+ port: undefined,
51
+ };
52
+
47
53
  return {
48
54
  internationalization,
49
55
  middleware,
50
56
  content,
57
+ editor,
51
58
  };
52
59
  };
@@ -2,6 +2,7 @@ import type {
2
2
  InternationalizationConfig,
3
3
  MiddlewareConfig,
4
4
  ContentConfig,
5
+ EditorConfig,
5
6
  } from '../../types/config';
6
7
  import type { IntlayerConfigEnvVariable, ReplaceValue } from './types';
7
8
  import { extractEmptyEnvVariable } from './undefined_platform';
@@ -16,6 +17,7 @@ export const extractViteEnvVariable = (): IntlayerConfigEnvVariable => {
16
17
 
17
18
  const internationalization: ReplaceValue<InternationalizationConfig> = {
18
19
  locales: import.meta.env.VITE_INTLAYER_LOCALES,
20
+ strictMode: import.meta.env.VITE_INTLAYER_STRICT_MODE,
19
21
  defaultLocale: import.meta.env.VITE_INTLAYER_DEFAULT_LOCALE,
20
22
  };
21
23
 
@@ -57,9 +59,14 @@ export const extractViteEnvVariable = (): IntlayerConfigEnvVariable => {
57
59
  dictionaryOutput: import.meta.env.VITE_INTLAYER_DICTIONARY_OUTPUT,
58
60
  };
59
61
 
62
+ const editor: ReplaceValue<EditorConfig> = {
63
+ port: import.meta.env.VITE_INTLAYER_PORT,
64
+ };
65
+
60
66
  return {
61
67
  internationalization,
62
68
  middleware,
63
69
  content,
70
+ editor,
64
71
  };
65
72
  };
@@ -26,6 +26,7 @@ export const formatEnvVariable = (
26
26
  ...intlayerConfig.content,
27
27
  ...intlayerConfig.internationalization,
28
28
  ...intlayerConfig.middleware,
29
+ ...intlayerConfig.editor,
29
30
  })) {
30
31
  if (typeof value === 'string') {
31
32
  env[formatEnvName(key, prefix)] = value;
@@ -5,6 +5,7 @@ import type {
5
5
  IntlayerConfig,
6
6
  MiddlewareConfig,
7
7
  ServerSetCookieRule,
8
+ StrictMode,
8
9
  } from '../types/config';
9
10
  import type { Locales } from '../types/locales';
10
11
  import { extractEnvVariable } from './extractEnvVariable/index';
@@ -20,6 +21,10 @@ export const getConfiguration = (): IntlayerConfig => {
20
21
 
21
22
  const intlayerIntlConfiguration: InternationalizationConfig = {
22
23
  locales: getEnvValue<Locales>(env.internationalization.locales, 'array')!,
24
+ strictMode: getEnvValue<StrictMode>(
25
+ env.internationalization.strictMode,
26
+ 'string'
27
+ )!,
23
28
  defaultLocale: getEnvValue<Locales>(
24
29
  env?.internationalization.defaultLocale,
25
30
  'string'
@@ -89,10 +94,15 @@ export const getConfiguration = (): IntlayerConfig => {
89
94
  )!,
90
95
  };
91
96
 
97
+ const intlayerEditorConfiguration = {
98
+ port: getEnvValue(env.editor.port, 'number')!,
99
+ };
100
+
92
101
  const intlayerConfiguration: IntlayerConfig = {
93
102
  internationalization: intlayerIntlConfiguration,
94
103
  middleware: intlayerMiddlewareConfiguration,
95
104
  content: intlayerContentConfiguration,
105
+ editor: intlayerEditorConfiguration,
96
106
  };
97
107
 
98
108
  return intlayerConfiguration;
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export type {
10
10
  ResultDirDerivedConfig,
11
11
  PatternsContentConfig,
12
12
  ContentConfig,
13
+ StrictMode,
13
14
  IntlayerConfig,
14
15
  } from './types/config';
15
16
  export type { LocalesValues } from './types/locales';
@@ -1,5 +1,7 @@
1
1
  import type { Locales } from './locales';
2
2
 
3
+ export type StrictMode = 'strict' | 'required_only' | 'loose';
4
+
3
5
  /**
4
6
  * Configuration for internationalization settings
5
7
  */
@@ -13,6 +15,15 @@ export type InternationalizationConfig = {
13
15
  */
14
16
  locales: Locales[];
15
17
 
18
+ /**
19
+ * Ensure strong implementations of internationalized content using typescript.
20
+ * - If set to "strict", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
21
+ * - If set to "required_only", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.
22
+ * - If set to "loose", the translation `t` function will accept any existing locale.
23
+ *
24
+ * Default: "required_only"
25
+ */
26
+ strictMode: StrictMode;
16
27
  /**
17
28
  * Default locale of the application for fallback
18
29
  *
@@ -84,6 +95,20 @@ export type MiddlewareConfig = {
84
95
  noPrefix: boolean;
85
96
  };
86
97
 
98
+ /**
99
+ * Configuration for intlayer editor
100
+ */
101
+ export type EditorConfig = {
102
+ /**
103
+ * Port number for the editor server
104
+ *
105
+ * Default: 4000
106
+ *
107
+ * The port number where the editor server runs.
108
+ */
109
+ port: number;
110
+ };
111
+
87
112
  /**
88
113
  * Custom configuration that can be provided to override default settings
89
114
  */
@@ -102,6 +127,11 @@ export type CustomIntlayerConfig = {
102
127
  * Custom content configuration
103
128
  */
104
129
  content?: Partial<ContentConfig>;
130
+
131
+ /**
132
+ * Custom editor configuration
133
+ */
134
+ editor?: Partial<EditorConfig>;
105
135
  };
106
136
 
107
137
  /**
@@ -122,6 +152,11 @@ export type IntlayerConfig = {
122
152
  * Content configuration
123
153
  */
124
154
  content: ContentConfig;
155
+
156
+ /**
157
+ * Intlayer editor configuration
158
+ */
159
+ editor: EditorConfig;
125
160
  };
126
161
 
127
162
  /**