intor 1.0.39 → 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.
@@ -1,21 +1,19 @@
1
- import { logry } from 'logry/edge';
1
+ // src/modules/config/constants/cache.constants.ts
2
+ var DEFAULT_CACHE_OPTIONS = {
3
+ enabled: process.env.NODE_ENV === "production",
4
+ ttl: 60 * 60 * 1e3
5
+ // 1 hour
6
+ };
2
7
 
3
- // src/modules/intor-config/initialize-logger.ts
4
- var initializeLogger = ({
5
- id,
6
- scope,
7
- loggerOptions
8
- }) => {
9
- const logger = logry({
10
- id,
11
- level: loggerOptions?.level,
12
- scope,
13
- ...loggerOptions
14
- });
15
- return logger;
8
+ // src/modules/config/resolvers/resolve-cache-options.ts
9
+ var resolveCacheOptions = (cache) => {
10
+ return {
11
+ ...DEFAULT_CACHE_OPTIONS,
12
+ ...cache
13
+ };
16
14
  };
17
15
 
18
- // src/modules/intor-config/constants/cookie-options-constants.ts
16
+ // src/modules/config/constants/cookie.constants.ts
19
17
  var DEFAULT_COOKIE_OPTIONS = {
20
18
  disabled: false,
21
19
  autoSetCookie: true,
@@ -29,7 +27,7 @@ var DEFAULT_COOKIE_OPTIONS = {
29
27
  sameSite: "lax"
30
28
  };
31
29
 
32
- // src/modules/intor-config/resolvers/resolve-cookie-options.ts
30
+ // src/modules/config/resolvers/resolve-cookie-options.ts
33
31
  var resolveCookieOptions = (cookie = {}) => {
34
32
  return {
35
33
  ...DEFAULT_COOKIE_OPTIONS,
@@ -37,12 +35,8 @@ var resolveCookieOptions = (cookie = {}) => {
37
35
  };
38
36
  };
39
37
 
40
- // src/modules/intor-config/resolvers/resolve-fallback-locales.ts
41
- var resolveFallbackLocales = ({
42
- config,
43
- supportedLocales,
44
- logger
45
- }) => {
38
+ // src/modules/config/resolvers/resolve-fallback-locales.ts
39
+ var resolveFallbackLocales = (config, supportedLocales) => {
46
40
  const { defaultLocale, fallbackLocales } = config;
47
41
  if (!fallbackLocales || typeof fallbackLocales !== "object") {
48
42
  return {};
@@ -66,7 +60,7 @@ var resolveFallbackLocales = ({
66
60
  }
67
61
  }
68
62
  for (const [locale, invalids] of invalidFallbackMap.entries()) {
69
- logger.warn(
63
+ console.warn(
70
64
  `Invalid fallback locales for "${locale}"`,
71
65
  { invalids: [...invalids] },
72
66
  { scope: "resolveFallbackLocales" }
@@ -75,17 +69,9 @@ var resolveFallbackLocales = ({
75
69
  return validMap;
76
70
  };
77
71
 
78
- // src/modules/intor-config/constants/prefix-placeholder-constants.ts
79
- var DEFAULT_PREFIX_PLACEHOLDER = "{{locale}}";
80
-
81
- // src/modules/intor-config/resolvers/resolve-prefix-placeholder.ts
82
- var resolvePrefixPlaceholder = (input) => {
83
- return input?.replace(/\//g, "") || DEFAULT_PREFIX_PLACEHOLDER;
84
- };
85
-
86
- // src/modules/intor-config/constants/routing-options-constants.ts
72
+ // src/modules/config/constants/routing.constants.ts
87
73
  var DEFAULT_ROUTING_OPTIONS = {
88
- prefix: "all",
74
+ prefix: "none",
89
75
  firstVisit: {
90
76
  localeSource: "browser",
91
77
  redirect: true
@@ -95,9 +81,6 @@ var DEFAULT_ROUTING_OPTIONS = {
95
81
 
96
82
  // src/shared/utils/pathname/normalize-pathname.ts
97
83
  var normalizePathname = (rawPathname, options = {}) => {
98
- if (typeof rawPathname !== "string") {
99
- throw new TypeError("Expected rawPathname to be a string");
100
- }
101
84
  const length = rawPathname.length;
102
85
  let start = 0;
103
86
  let end = length - 1;
@@ -127,7 +110,7 @@ var normalizePathname = (rawPathname, options = {}) => {
127
110
  return result || "/";
128
111
  };
129
112
 
130
- // src/modules/intor-config/resolvers/resolve-routing-options.ts
113
+ // src/modules/config/resolvers/resolve-routing-options.ts
131
114
  var resolveRoutingOptions = (routing = {}) => {
132
115
  return {
133
116
  ...DEFAULT_ROUTING_OPTIONS,
@@ -140,7 +123,7 @@ var resolveRoutingOptions = (routing = {}) => {
140
123
  };
141
124
  };
142
125
 
143
- // src/modules/intor-error/intor-error.ts
126
+ // src/shared/error/intor-error.ts
144
127
  var IntorError = class extends Error {
145
128
  constructor({ message, code, id }) {
146
129
  const fullMessage = id ? `[${id}] ${message}` : message;
@@ -152,11 +135,8 @@ var IntorError = class extends Error {
152
135
  }
153
136
  };
154
137
 
155
- // src/modules/intor-config/validators/validate-default-locale.ts
156
- var validateDefaultLocale = ({
157
- config,
158
- supportedLocales
159
- }) => {
138
+ // src/modules/config/validators/validate-default-locale.ts
139
+ var validateDefaultLocale = (config, supportedLocales) => {
160
140
  const { id, defaultLocale } = config;
161
141
  if (!defaultLocale) {
162
142
  throw new IntorError({
@@ -165,7 +145,7 @@ var validateDefaultLocale = ({
165
145
  message: `The defaultLocale is undefined`
166
146
  });
167
147
  }
168
- if (!supportedLocales?.includes(defaultLocale)) {
148
+ if (!supportedLocales.includes(defaultLocale)) {
169
149
  throw new IntorError({
170
150
  id,
171
151
  code: "INTOR_UNSUPPORTED_DEFAULT_LOCALE" /* UNSUPPORTED_DEFAULT_LOCALE */,
@@ -175,59 +155,41 @@ var validateDefaultLocale = ({
175
155
  return defaultLocale;
176
156
  };
177
157
 
178
- // src/modules/intor-config/validators/validate-supported-locales.ts
179
- var validateSupportedLocales = ({
180
- config
181
- }) => {
182
- const { id, loaderOptions, supportedLocales } = config;
183
- if (loaderOptions && !supportedLocales) {
158
+ // src/modules/config/validators/validate-supported-locales.ts
159
+ var validateSupportedLocales = (config) => {
160
+ const { id, loader, supportedLocales } = config;
161
+ if (loader && !supportedLocales) {
184
162
  throw new IntorError({
185
163
  id,
186
164
  code: "INTOR_MISSING_SUPPORTED_LOCALES" /* MISSING_SUPPORTED_LOCALES */,
187
- message: `"supportedLocales" is required when using loaderOptions, but it is missing.`
165
+ message: `"supportedLocales" is required when using loader, but it is missing.`
188
166
  });
189
167
  }
190
168
  return supportedLocales || Object.keys(config.messages || {});
191
169
  };
192
170
 
193
- // src/modules/intor-config/define-intor-config.ts
171
+ // src/modules/config/define-intor-config.ts
194
172
  var defineIntorConfig = (config) => {
195
173
  const id = config.id || `ID${Math.random().toString(36).slice(2, 6)}`;
196
- const logger = initializeLogger({
197
- id,
198
- loggerOptions: config.logger,
199
- scope: "defineIntorConfig"
200
- });
201
- const supportedLocales = validateSupportedLocales({ config });
202
- const defaultLocale = validateDefaultLocale({ config, supportedLocales });
203
- const resolvedFallbackLocales = resolveFallbackLocales({
204
- config,
205
- supportedLocales,
206
- logger
207
- });
208
- const resolvedCookieOptions = resolveCookieOptions(config.cookie);
209
- const resolvedRoutingOptions = resolveRoutingOptions(config.routing);
210
- const resolvedPrefixPlaceHolder = resolvePrefixPlaceholder(
211
- config.prefixPlaceHolder
212
- );
174
+ const supportedLocales = validateSupportedLocales(config);
175
+ const defaultLocale = validateDefaultLocale(config, supportedLocales);
176
+ const fallbackLocales = resolveFallbackLocales(config, supportedLocales);
177
+ const cookie = resolveCookieOptions(config.cookie);
178
+ const routing = resolveRoutingOptions(config.routing);
179
+ const cache = resolveCacheOptions(config.cache);
213
180
  return {
214
181
  id,
215
182
  messages: config.messages,
216
- // Optional
217
- loaderOptions: config.loaderOptions,
218
- // Optional
183
+ loader: config.loader,
219
184
  defaultLocale,
220
- // Validated
221
185
  supportedLocales,
222
- // Validated
223
- fallbackLocales: resolvedFallbackLocales,
186
+ fallbackLocales,
224
187
  translator: config.translator,
225
- cookie: resolvedCookieOptions,
226
- routing: resolvedRoutingOptions,
227
- adapter: config.adapter || "next-client",
188
+ cookie,
189
+ routing,
228
190
  logger: config.logger,
229
- prefixPlaceHolder: resolvedPrefixPlaceHolder
191
+ cache
230
192
  };
231
193
  };
232
194
 
233
- export { defineIntorConfig };
195
+ export { DEFAULT_CACHE_OPTIONS, DEFAULT_COOKIE_OPTIONS, DEFAULT_ROUTING_OPTIONS, defineIntorConfig };