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.
- package/dist/config/index.cjs +44 -79
- package/dist/config/index.d.cts +69 -36
- package/dist/config/index.d.ts +69 -36
- package/dist/config/index.js +42 -80
- package/dist/index.cjs +482 -540
- package/dist/index.d.cts +163 -139
- package/dist/index.d.ts +163 -139
- package/dist/index.js +475 -537
- package/dist/next/index.cjs +399 -359
- package/dist/next/index.d.cts +82 -113
- package/dist/next/index.d.ts +82 -113
- package/dist/next/index.js +396 -351
- package/dist/next/middleware/index.cjs +79 -93
- package/dist/next/middleware/index.d.cts +59 -28
- package/dist/next/middleware/index.d.ts +59 -28
- package/dist/next/middleware/index.js +79 -93
- package/dist/next/server/index.cjs +886 -0
- package/dist/next/server/index.d.cts +149 -0
- package/dist/next/server/index.d.ts +149 -0
- package/dist/next/server/index.js +875 -0
- package/package.json +9 -12
- package/exports/next/provider/intor-provider.tsx +0 -25
- package/exports/next/provider/translate-handlers-provider.tsx +0 -19
package/dist/config/index.cjs
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/modules/config/constants/cache.constants.ts
|
|
4
|
+
var DEFAULT_CACHE_OPTIONS = {
|
|
5
|
+
enabled: process.env.NODE_ENV === "production",
|
|
6
|
+
ttl: 60 * 60 * 1e3
|
|
7
|
+
// 1 hour
|
|
8
|
+
};
|
|
4
9
|
|
|
5
|
-
// src/modules/
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const logger = edge.logry({
|
|
12
|
-
id,
|
|
13
|
-
level: loggerOptions?.level,
|
|
14
|
-
scope,
|
|
15
|
-
...loggerOptions
|
|
16
|
-
});
|
|
17
|
-
return logger;
|
|
10
|
+
// src/modules/config/resolvers/resolve-cache-options.ts
|
|
11
|
+
var resolveCacheOptions = (cache) => {
|
|
12
|
+
return {
|
|
13
|
+
...DEFAULT_CACHE_OPTIONS,
|
|
14
|
+
...cache
|
|
15
|
+
};
|
|
18
16
|
};
|
|
19
17
|
|
|
20
|
-
// src/modules/
|
|
18
|
+
// src/modules/config/constants/cookie.constants.ts
|
|
21
19
|
var DEFAULT_COOKIE_OPTIONS = {
|
|
22
20
|
disabled: false,
|
|
23
21
|
autoSetCookie: true,
|
|
@@ -31,7 +29,7 @@ var DEFAULT_COOKIE_OPTIONS = {
|
|
|
31
29
|
sameSite: "lax"
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
// src/modules/
|
|
32
|
+
// src/modules/config/resolvers/resolve-cookie-options.ts
|
|
35
33
|
var resolveCookieOptions = (cookie = {}) => {
|
|
36
34
|
return {
|
|
37
35
|
...DEFAULT_COOKIE_OPTIONS,
|
|
@@ -39,12 +37,8 @@ var resolveCookieOptions = (cookie = {}) => {
|
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
// src/modules/
|
|
43
|
-
var resolveFallbackLocales = ({
|
|
44
|
-
config,
|
|
45
|
-
supportedLocales,
|
|
46
|
-
logger
|
|
47
|
-
}) => {
|
|
40
|
+
// src/modules/config/resolvers/resolve-fallback-locales.ts
|
|
41
|
+
var resolveFallbackLocales = (config, supportedLocales) => {
|
|
48
42
|
const { defaultLocale, fallbackLocales } = config;
|
|
49
43
|
if (!fallbackLocales || typeof fallbackLocales !== "object") {
|
|
50
44
|
return {};
|
|
@@ -68,7 +62,7 @@ var resolveFallbackLocales = ({
|
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
for (const [locale, invalids] of invalidFallbackMap.entries()) {
|
|
71
|
-
|
|
65
|
+
console.warn(
|
|
72
66
|
`Invalid fallback locales for "${locale}"`,
|
|
73
67
|
{ invalids: [...invalids] },
|
|
74
68
|
{ scope: "resolveFallbackLocales" }
|
|
@@ -77,17 +71,9 @@ var resolveFallbackLocales = ({
|
|
|
77
71
|
return validMap;
|
|
78
72
|
};
|
|
79
73
|
|
|
80
|
-
// src/modules/
|
|
81
|
-
var DEFAULT_PREFIX_PLACEHOLDER = "{{locale}}";
|
|
82
|
-
|
|
83
|
-
// src/modules/intor-config/resolvers/resolve-prefix-placeholder.ts
|
|
84
|
-
var resolvePrefixPlaceholder = (input) => {
|
|
85
|
-
return input?.replace(/\//g, "") || DEFAULT_PREFIX_PLACEHOLDER;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// src/modules/intor-config/constants/routing-options-constants.ts
|
|
74
|
+
// src/modules/config/constants/routing.constants.ts
|
|
89
75
|
var DEFAULT_ROUTING_OPTIONS = {
|
|
90
|
-
prefix: "
|
|
76
|
+
prefix: "none",
|
|
91
77
|
firstVisit: {
|
|
92
78
|
localeSource: "browser",
|
|
93
79
|
redirect: true
|
|
@@ -97,9 +83,6 @@ var DEFAULT_ROUTING_OPTIONS = {
|
|
|
97
83
|
|
|
98
84
|
// src/shared/utils/pathname/normalize-pathname.ts
|
|
99
85
|
var normalizePathname = (rawPathname, options = {}) => {
|
|
100
|
-
if (typeof rawPathname !== "string") {
|
|
101
|
-
throw new TypeError("Expected rawPathname to be a string");
|
|
102
|
-
}
|
|
103
86
|
const length = rawPathname.length;
|
|
104
87
|
let start = 0;
|
|
105
88
|
let end = length - 1;
|
|
@@ -129,7 +112,7 @@ var normalizePathname = (rawPathname, options = {}) => {
|
|
|
129
112
|
return result || "/";
|
|
130
113
|
};
|
|
131
114
|
|
|
132
|
-
// src/modules/
|
|
115
|
+
// src/modules/config/resolvers/resolve-routing-options.ts
|
|
133
116
|
var resolveRoutingOptions = (routing = {}) => {
|
|
134
117
|
return {
|
|
135
118
|
...DEFAULT_ROUTING_OPTIONS,
|
|
@@ -142,7 +125,7 @@ var resolveRoutingOptions = (routing = {}) => {
|
|
|
142
125
|
};
|
|
143
126
|
};
|
|
144
127
|
|
|
145
|
-
// src/
|
|
128
|
+
// src/shared/error/intor-error.ts
|
|
146
129
|
var IntorError = class extends Error {
|
|
147
130
|
constructor({ message, code, id }) {
|
|
148
131
|
const fullMessage = id ? `[${id}] ${message}` : message;
|
|
@@ -154,11 +137,8 @@ var IntorError = class extends Error {
|
|
|
154
137
|
}
|
|
155
138
|
};
|
|
156
139
|
|
|
157
|
-
// src/modules/
|
|
158
|
-
var validateDefaultLocale = ({
|
|
159
|
-
config,
|
|
160
|
-
supportedLocales
|
|
161
|
-
}) => {
|
|
140
|
+
// src/modules/config/validators/validate-default-locale.ts
|
|
141
|
+
var validateDefaultLocale = (config, supportedLocales) => {
|
|
162
142
|
const { id, defaultLocale } = config;
|
|
163
143
|
if (!defaultLocale) {
|
|
164
144
|
throw new IntorError({
|
|
@@ -167,7 +147,7 @@ var validateDefaultLocale = ({
|
|
|
167
147
|
message: `The defaultLocale is undefined`
|
|
168
148
|
});
|
|
169
149
|
}
|
|
170
|
-
if (!supportedLocales
|
|
150
|
+
if (!supportedLocales.includes(defaultLocale)) {
|
|
171
151
|
throw new IntorError({
|
|
172
152
|
id,
|
|
173
153
|
code: "INTOR_UNSUPPORTED_DEFAULT_LOCALE" /* UNSUPPORTED_DEFAULT_LOCALE */,
|
|
@@ -177,59 +157,44 @@ var validateDefaultLocale = ({
|
|
|
177
157
|
return defaultLocale;
|
|
178
158
|
};
|
|
179
159
|
|
|
180
|
-
// src/modules/
|
|
181
|
-
var validateSupportedLocales = ({
|
|
182
|
-
config
|
|
183
|
-
|
|
184
|
-
const { id, loaderOptions, supportedLocales } = config;
|
|
185
|
-
if (loaderOptions && !supportedLocales) {
|
|
160
|
+
// src/modules/config/validators/validate-supported-locales.ts
|
|
161
|
+
var validateSupportedLocales = (config) => {
|
|
162
|
+
const { id, loader, supportedLocales } = config;
|
|
163
|
+
if (loader && !supportedLocales) {
|
|
186
164
|
throw new IntorError({
|
|
187
165
|
id,
|
|
188
166
|
code: "INTOR_MISSING_SUPPORTED_LOCALES" /* MISSING_SUPPORTED_LOCALES */,
|
|
189
|
-
message: `"supportedLocales" is required when using
|
|
167
|
+
message: `"supportedLocales" is required when using loader, but it is missing.`
|
|
190
168
|
});
|
|
191
169
|
}
|
|
192
170
|
return supportedLocales || Object.keys(config.messages || {});
|
|
193
171
|
};
|
|
194
172
|
|
|
195
|
-
// src/modules/
|
|
173
|
+
// src/modules/config/define-intor-config.ts
|
|
196
174
|
var defineIntorConfig = (config) => {
|
|
197
175
|
const id = config.id || `ID${Math.random().toString(36).slice(2, 6)}`;
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const defaultLocale = validateDefaultLocale({ config, supportedLocales });
|
|
205
|
-
const resolvedFallbackLocales = resolveFallbackLocales({
|
|
206
|
-
config,
|
|
207
|
-
supportedLocales,
|
|
208
|
-
logger
|
|
209
|
-
});
|
|
210
|
-
const resolvedCookieOptions = resolveCookieOptions(config.cookie);
|
|
211
|
-
const resolvedRoutingOptions = resolveRoutingOptions(config.routing);
|
|
212
|
-
const resolvedPrefixPlaceHolder = resolvePrefixPlaceholder(
|
|
213
|
-
config.prefixPlaceHolder
|
|
214
|
-
);
|
|
176
|
+
const supportedLocales = validateSupportedLocales(config);
|
|
177
|
+
const defaultLocale = validateDefaultLocale(config, supportedLocales);
|
|
178
|
+
const fallbackLocales = resolveFallbackLocales(config, supportedLocales);
|
|
179
|
+
const cookie = resolveCookieOptions(config.cookie);
|
|
180
|
+
const routing = resolveRoutingOptions(config.routing);
|
|
181
|
+
const cache = resolveCacheOptions(config.cache);
|
|
215
182
|
return {
|
|
216
183
|
id,
|
|
217
184
|
messages: config.messages,
|
|
218
|
-
|
|
219
|
-
loaderOptions: config.loaderOptions,
|
|
220
|
-
// Optional
|
|
185
|
+
loader: config.loader,
|
|
221
186
|
defaultLocale,
|
|
222
|
-
// Validated
|
|
223
187
|
supportedLocales,
|
|
224
|
-
|
|
225
|
-
fallbackLocales: resolvedFallbackLocales,
|
|
188
|
+
fallbackLocales,
|
|
226
189
|
translator: config.translator,
|
|
227
|
-
cookie
|
|
228
|
-
routing
|
|
229
|
-
adapter: config.adapter || "next-client",
|
|
190
|
+
cookie,
|
|
191
|
+
routing,
|
|
230
192
|
logger: config.logger,
|
|
231
|
-
|
|
193
|
+
cache
|
|
232
194
|
};
|
|
233
195
|
};
|
|
234
196
|
|
|
197
|
+
exports.DEFAULT_CACHE_OPTIONS = DEFAULT_CACHE_OPTIONS;
|
|
198
|
+
exports.DEFAULT_COOKIE_OPTIONS = DEFAULT_COOKIE_OPTIONS;
|
|
199
|
+
exports.DEFAULT_ROUTING_OPTIONS = DEFAULT_ROUTING_OPTIONS;
|
|
235
200
|
exports.defineIntorConfig = defineIntorConfig;
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
2
|
import { Locale, LocaleNamespaceMessages, FallbackLocalesMap } from 'intor-translator';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type CookieRawOptions = {
|
|
5
|
+
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
5
6
|
disabled?: boolean;
|
|
7
|
+
/** Allow the system to automatically set cookies - default: true */
|
|
6
8
|
autoSetCookie?: boolean;
|
|
9
|
+
/** default: "intor.i18n.locale" */
|
|
7
10
|
name?: string;
|
|
8
|
-
|
|
9
|
-
path?: string;
|
|
11
|
+
/** default: null */
|
|
10
12
|
domain?: string | null;
|
|
11
|
-
|
|
13
|
+
/** default: "/" */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** default: 60 * 60 * 24 * 365 (365 days) */
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
/** default: false */
|
|
12
18
|
httpOnly?: boolean;
|
|
19
|
+
/** default: process.env.NODE_ENV !== "development" */
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
/** default: lax */
|
|
13
22
|
sameSite?: "lax" | "strict" | "none";
|
|
14
23
|
};
|
|
15
|
-
type
|
|
24
|
+
type CookieResolvedOptions = Required<Omit<CookieRawOptions, "domain">> & {
|
|
16
25
|
domain: string | null;
|
|
17
26
|
};
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* default: ["ui", "meta"],
|
|
32
|
+
* "/auth": ["auth", "admin"],
|
|
33
|
+
* }
|
|
34
|
+
* // When pathname is "/" => namespaces: ["ui", "meta"]
|
|
35
|
+
* // When pathname is "/auth" => namespaces: ["ui", "meta", "auth", "admin"]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
22
38
|
type RouteNamespaces = {
|
|
23
39
|
[key: string]: string[];
|
|
24
40
|
} | {
|
|
25
41
|
[key: string]: string[];
|
|
26
42
|
default: string[];
|
|
27
43
|
};
|
|
44
|
+
interface ApiHeaders {
|
|
45
|
+
authorization?: string;
|
|
46
|
+
"x-api-key"?: string;
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
}
|
|
28
49
|
type BaseLoaderOptions = {
|
|
29
50
|
basePath?: string;
|
|
30
51
|
namespaces?: string[];
|
|
@@ -38,71 +59,83 @@ type ImportLoader = BaseLoaderOptions & {
|
|
|
38
59
|
type ApiLoader = BaseLoaderOptions & {
|
|
39
60
|
type: "api";
|
|
40
61
|
apiUrl: string;
|
|
62
|
+
apiHeaders?: ApiHeaders;
|
|
41
63
|
fullReload?: boolean;
|
|
42
64
|
};
|
|
43
65
|
type LoaderOptions = ImportLoader | ApiLoader;
|
|
44
66
|
|
|
45
|
-
type
|
|
67
|
+
type LoggerOptions = {
|
|
46
68
|
level?: Level;
|
|
47
69
|
normalizerConfig?: NormalizerConfig;
|
|
48
70
|
formatterConfig?: FormatterConfig;
|
|
49
71
|
preset?: LoggerPreset;
|
|
50
72
|
};
|
|
51
|
-
type ResolvedLoggerOptions = InitLoggerOptions;
|
|
52
73
|
|
|
53
74
|
declare const routingPrefix: readonly ["none", "all", "except-default"];
|
|
54
75
|
declare const routingFirstVisitLocaleSource: readonly ["default", "browser"];
|
|
55
|
-
type
|
|
76
|
+
type RoutingRawOptions = {
|
|
77
|
+
/** default: "none" */
|
|
56
78
|
prefix?: (typeof routingPrefix)[number];
|
|
57
79
|
firstVisit?: {
|
|
80
|
+
/** default: "browser" */
|
|
58
81
|
localeSource?: (typeof routingFirstVisitLocaleSource)[number];
|
|
82
|
+
/** default: true */
|
|
59
83
|
redirect?: boolean;
|
|
60
84
|
};
|
|
85
|
+
/** default: "" */
|
|
61
86
|
basePath?: string;
|
|
62
87
|
};
|
|
63
|
-
type
|
|
88
|
+
type RoutingResolvedOptions = Required<RoutingRawOptions>;
|
|
89
|
+
|
|
90
|
+
type CacheRawOptions = {
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
/** default: 60\*60\*1000 (1 hour) */
|
|
93
|
+
ttl?: number;
|
|
94
|
+
};
|
|
95
|
+
type CacheResolvedOptions = Required<CacheRawOptions>;
|
|
64
96
|
|
|
65
|
-
type
|
|
97
|
+
type TranslatorOptions = {
|
|
66
98
|
loadingMessage?: string;
|
|
67
99
|
placeholder?: string;
|
|
68
100
|
};
|
|
69
101
|
|
|
70
|
-
type
|
|
71
|
-
|
|
102
|
+
type WithoutLoader = {
|
|
103
|
+
loader?: undefined;
|
|
72
104
|
supportedLocales?: readonly Locale[];
|
|
73
105
|
};
|
|
74
|
-
type
|
|
75
|
-
|
|
106
|
+
type WithLoader = {
|
|
107
|
+
loader: LoaderOptions;
|
|
76
108
|
supportedLocales: readonly Locale[];
|
|
77
109
|
};
|
|
78
|
-
type
|
|
110
|
+
type IntorRawConfig = (WithLoader | WithoutLoader) & {
|
|
79
111
|
readonly id?: string;
|
|
80
112
|
readonly messages?: LocaleNamespaceMessages;
|
|
81
113
|
readonly defaultLocale: Locale;
|
|
82
114
|
readonly fallbackLocales?: FallbackLocalesMap;
|
|
83
|
-
readonly translator?:
|
|
84
|
-
readonly cookie?:
|
|
85
|
-
readonly routing?:
|
|
86
|
-
readonly
|
|
87
|
-
readonly
|
|
88
|
-
readonly prefixPlaceHolder?: string;
|
|
115
|
+
readonly translator?: TranslatorOptions;
|
|
116
|
+
readonly cookie?: CookieRawOptions;
|
|
117
|
+
readonly routing?: RoutingRawOptions;
|
|
118
|
+
readonly logger?: LoggerOptions;
|
|
119
|
+
readonly cache?: CacheRawOptions;
|
|
89
120
|
};
|
|
90
|
-
type IntorResolvedConfig = (
|
|
121
|
+
type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
|
|
91
122
|
readonly id: string;
|
|
92
123
|
readonly messages?: LocaleNamespaceMessages;
|
|
93
124
|
readonly defaultLocale: Locale;
|
|
94
125
|
readonly fallbackLocales: FallbackLocalesMap;
|
|
95
|
-
readonly translator?:
|
|
96
|
-
readonly cookie:
|
|
97
|
-
readonly routing:
|
|
98
|
-
readonly
|
|
99
|
-
readonly
|
|
100
|
-
readonly prefixPlaceHolder: string;
|
|
126
|
+
readonly translator?: TranslatorOptions;
|
|
127
|
+
readonly cookie: CookieResolvedOptions;
|
|
128
|
+
readonly routing: RoutingResolvedOptions;
|
|
129
|
+
readonly logger?: LoggerOptions;
|
|
130
|
+
readonly cache: CacheResolvedOptions;
|
|
101
131
|
};
|
|
102
132
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
declare const defineIntorConfig: (config: IntorRawConfig) => IntorResolvedConfig;
|
|
134
|
+
|
|
135
|
+
declare const DEFAULT_CACHE_OPTIONS: CacheResolvedOptions;
|
|
136
|
+
|
|
137
|
+
declare const DEFAULT_COOKIE_OPTIONS: CookieResolvedOptions;
|
|
138
|
+
|
|
139
|
+
declare const DEFAULT_ROUTING_OPTIONS: RoutingResolvedOptions;
|
|
107
140
|
|
|
108
|
-
export { defineIntorConfig };
|
|
141
|
+
export { DEFAULT_CACHE_OPTIONS, DEFAULT_COOKIE_OPTIONS, DEFAULT_ROUTING_OPTIONS, type IntorRawConfig, type IntorResolvedConfig, defineIntorConfig };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
|
|
2
2
|
import { Locale, LocaleNamespaceMessages, FallbackLocalesMap } from 'intor-translator';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type CookieRawOptions = {
|
|
5
|
+
/** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
|
|
5
6
|
disabled?: boolean;
|
|
7
|
+
/** Allow the system to automatically set cookies - default: true */
|
|
6
8
|
autoSetCookie?: boolean;
|
|
9
|
+
/** default: "intor.i18n.locale" */
|
|
7
10
|
name?: string;
|
|
8
|
-
|
|
9
|
-
path?: string;
|
|
11
|
+
/** default: null */
|
|
10
12
|
domain?: string | null;
|
|
11
|
-
|
|
13
|
+
/** default: "/" */
|
|
14
|
+
path?: string;
|
|
15
|
+
/** default: 60 * 60 * 24 * 365 (365 days) */
|
|
16
|
+
maxAge?: number;
|
|
17
|
+
/** default: false */
|
|
12
18
|
httpOnly?: boolean;
|
|
19
|
+
/** default: process.env.NODE_ENV !== "development" */
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
/** default: lax */
|
|
13
22
|
sameSite?: "lax" | "strict" | "none";
|
|
14
23
|
};
|
|
15
|
-
type
|
|
24
|
+
type CookieResolvedOptions = Required<Omit<CookieRawOptions, "domain">> & {
|
|
16
25
|
domain: string | null;
|
|
17
26
|
};
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* default: ["ui", "meta"],
|
|
32
|
+
* "/auth": ["auth", "admin"],
|
|
33
|
+
* }
|
|
34
|
+
* // When pathname is "/" => namespaces: ["ui", "meta"]
|
|
35
|
+
* // When pathname is "/auth" => namespaces: ["ui", "meta", "auth", "admin"]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
22
38
|
type RouteNamespaces = {
|
|
23
39
|
[key: string]: string[];
|
|
24
40
|
} | {
|
|
25
41
|
[key: string]: string[];
|
|
26
42
|
default: string[];
|
|
27
43
|
};
|
|
44
|
+
interface ApiHeaders {
|
|
45
|
+
authorization?: string;
|
|
46
|
+
"x-api-key"?: string;
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
}
|
|
28
49
|
type BaseLoaderOptions = {
|
|
29
50
|
basePath?: string;
|
|
30
51
|
namespaces?: string[];
|
|
@@ -38,71 +59,83 @@ type ImportLoader = BaseLoaderOptions & {
|
|
|
38
59
|
type ApiLoader = BaseLoaderOptions & {
|
|
39
60
|
type: "api";
|
|
40
61
|
apiUrl: string;
|
|
62
|
+
apiHeaders?: ApiHeaders;
|
|
41
63
|
fullReload?: boolean;
|
|
42
64
|
};
|
|
43
65
|
type LoaderOptions = ImportLoader | ApiLoader;
|
|
44
66
|
|
|
45
|
-
type
|
|
67
|
+
type LoggerOptions = {
|
|
46
68
|
level?: Level;
|
|
47
69
|
normalizerConfig?: NormalizerConfig;
|
|
48
70
|
formatterConfig?: FormatterConfig;
|
|
49
71
|
preset?: LoggerPreset;
|
|
50
72
|
};
|
|
51
|
-
type ResolvedLoggerOptions = InitLoggerOptions;
|
|
52
73
|
|
|
53
74
|
declare const routingPrefix: readonly ["none", "all", "except-default"];
|
|
54
75
|
declare const routingFirstVisitLocaleSource: readonly ["default", "browser"];
|
|
55
|
-
type
|
|
76
|
+
type RoutingRawOptions = {
|
|
77
|
+
/** default: "none" */
|
|
56
78
|
prefix?: (typeof routingPrefix)[number];
|
|
57
79
|
firstVisit?: {
|
|
80
|
+
/** default: "browser" */
|
|
58
81
|
localeSource?: (typeof routingFirstVisitLocaleSource)[number];
|
|
82
|
+
/** default: true */
|
|
59
83
|
redirect?: boolean;
|
|
60
84
|
};
|
|
85
|
+
/** default: "" */
|
|
61
86
|
basePath?: string;
|
|
62
87
|
};
|
|
63
|
-
type
|
|
88
|
+
type RoutingResolvedOptions = Required<RoutingRawOptions>;
|
|
89
|
+
|
|
90
|
+
type CacheRawOptions = {
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
/** default: 60\*60\*1000 (1 hour) */
|
|
93
|
+
ttl?: number;
|
|
94
|
+
};
|
|
95
|
+
type CacheResolvedOptions = Required<CacheRawOptions>;
|
|
64
96
|
|
|
65
|
-
type
|
|
97
|
+
type TranslatorOptions = {
|
|
66
98
|
loadingMessage?: string;
|
|
67
99
|
placeholder?: string;
|
|
68
100
|
};
|
|
69
101
|
|
|
70
|
-
type
|
|
71
|
-
|
|
102
|
+
type WithoutLoader = {
|
|
103
|
+
loader?: undefined;
|
|
72
104
|
supportedLocales?: readonly Locale[];
|
|
73
105
|
};
|
|
74
|
-
type
|
|
75
|
-
|
|
106
|
+
type WithLoader = {
|
|
107
|
+
loader: LoaderOptions;
|
|
76
108
|
supportedLocales: readonly Locale[];
|
|
77
109
|
};
|
|
78
|
-
type
|
|
110
|
+
type IntorRawConfig = (WithLoader | WithoutLoader) & {
|
|
79
111
|
readonly id?: string;
|
|
80
112
|
readonly messages?: LocaleNamespaceMessages;
|
|
81
113
|
readonly defaultLocale: Locale;
|
|
82
114
|
readonly fallbackLocales?: FallbackLocalesMap;
|
|
83
|
-
readonly translator?:
|
|
84
|
-
readonly cookie?:
|
|
85
|
-
readonly routing?:
|
|
86
|
-
readonly
|
|
87
|
-
readonly
|
|
88
|
-
readonly prefixPlaceHolder?: string;
|
|
115
|
+
readonly translator?: TranslatorOptions;
|
|
116
|
+
readonly cookie?: CookieRawOptions;
|
|
117
|
+
readonly routing?: RoutingRawOptions;
|
|
118
|
+
readonly logger?: LoggerOptions;
|
|
119
|
+
readonly cache?: CacheRawOptions;
|
|
89
120
|
};
|
|
90
|
-
type IntorResolvedConfig = (
|
|
121
|
+
type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
|
|
91
122
|
readonly id: string;
|
|
92
123
|
readonly messages?: LocaleNamespaceMessages;
|
|
93
124
|
readonly defaultLocale: Locale;
|
|
94
125
|
readonly fallbackLocales: FallbackLocalesMap;
|
|
95
|
-
readonly translator?:
|
|
96
|
-
readonly cookie:
|
|
97
|
-
readonly routing:
|
|
98
|
-
readonly
|
|
99
|
-
readonly
|
|
100
|
-
readonly prefixPlaceHolder: string;
|
|
126
|
+
readonly translator?: TranslatorOptions;
|
|
127
|
+
readonly cookie: CookieResolvedOptions;
|
|
128
|
+
readonly routing: RoutingResolvedOptions;
|
|
129
|
+
readonly logger?: LoggerOptions;
|
|
130
|
+
readonly cache: CacheResolvedOptions;
|
|
101
131
|
};
|
|
102
132
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
declare const defineIntorConfig: (config: IntorRawConfig) => IntorResolvedConfig;
|
|
134
|
+
|
|
135
|
+
declare const DEFAULT_CACHE_OPTIONS: CacheResolvedOptions;
|
|
136
|
+
|
|
137
|
+
declare const DEFAULT_COOKIE_OPTIONS: CookieResolvedOptions;
|
|
138
|
+
|
|
139
|
+
declare const DEFAULT_ROUTING_OPTIONS: RoutingResolvedOptions;
|
|
107
140
|
|
|
108
|
-
export { defineIntorConfig };
|
|
141
|
+
export { DEFAULT_CACHE_OPTIONS, DEFAULT_COOKIE_OPTIONS, DEFAULT_ROUTING_OPTIONS, type IntorRawConfig, type IntorResolvedConfig, defineIntorConfig };
|