intor 1.0.21 → 1.0.22
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 +2 -5
- package/dist/config/index.d.cts +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +2 -5
- package/dist/index.cjs +28 -24
- package/dist/index.js +28 -24
- package/dist/middleware/index.cjs +2 -2
- package/dist/middleware/index.js +2 -2
- package/dist/next/index.cjs +32 -29
- package/dist/next/index.d.cts +3 -1
- package/dist/next/index.d.ts +3 -1
- package/dist/next/index.js +32 -30
- package/package.json +1 -1
package/dist/config/index.cjs
CHANGED
|
@@ -23,13 +23,11 @@ var __spreadValues = (a, b) => {
|
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
24
|
var initializeLogger = ({
|
|
25
25
|
id,
|
|
26
|
-
scope,
|
|
27
26
|
loggerOptions
|
|
28
27
|
}) => {
|
|
29
28
|
const logger = logry.logry(__spreadValues({
|
|
30
29
|
id,
|
|
31
|
-
level: loggerOptions == null ? void 0 : loggerOptions.level
|
|
32
|
-
scope
|
|
30
|
+
level: loggerOptions == null ? void 0 : loggerOptions.level
|
|
33
31
|
}, loggerOptions));
|
|
34
32
|
return logger;
|
|
35
33
|
};
|
|
@@ -206,8 +204,7 @@ var defineIntorConfig = (config) => {
|
|
|
206
204
|
const id = config.id || `ID${Math.random().toString(36).slice(2, 6)}`;
|
|
207
205
|
const logger = initializeLogger({
|
|
208
206
|
id,
|
|
209
|
-
loggerOptions: config.logger,
|
|
210
|
-
scope: "defineIntorConfig"
|
|
207
|
+
loggerOptions: __spreadProps(__spreadValues({}, config.logger), { scope: "defineIntorConfig" })
|
|
211
208
|
});
|
|
212
209
|
const supportedLocales = validateSupportedLocales({ config });
|
|
213
210
|
const defaultLocale = validateDefaultLocale({ config, supportedLocales });
|
package/dist/config/index.d.cts
CHANGED
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -21,13 +21,11 @@ var __spreadValues = (a, b) => {
|
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
22
|
var initializeLogger = ({
|
|
23
23
|
id,
|
|
24
|
-
scope,
|
|
25
24
|
loggerOptions
|
|
26
25
|
}) => {
|
|
27
26
|
const logger = logry(__spreadValues({
|
|
28
27
|
id,
|
|
29
|
-
level: loggerOptions == null ? void 0 : loggerOptions.level
|
|
30
|
-
scope
|
|
28
|
+
level: loggerOptions == null ? void 0 : loggerOptions.level
|
|
31
29
|
}, loggerOptions));
|
|
32
30
|
return logger;
|
|
33
31
|
};
|
|
@@ -204,8 +202,7 @@ var defineIntorConfig = (config) => {
|
|
|
204
202
|
const id = config.id || `ID${Math.random().toString(36).slice(2, 6)}`;
|
|
205
203
|
const logger = initializeLogger({
|
|
206
204
|
id,
|
|
207
|
-
loggerOptions: config.logger,
|
|
208
|
-
scope: "defineIntorConfig"
|
|
205
|
+
loggerOptions: __spreadProps(__spreadValues({}, config.logger), { scope: "defineIntorConfig" })
|
|
209
206
|
});
|
|
210
207
|
const supportedLocales = validateSupportedLocales({ config });
|
|
211
208
|
const defaultLocale = validateDefaultLocale({ config, supportedLocales });
|
package/dist/index.cjs
CHANGED
|
@@ -58,7 +58,7 @@ var IntorErrorCode = /* @__PURE__ */ ((IntorErrorCode2) => {
|
|
|
58
58
|
})(IntorErrorCode || {});
|
|
59
59
|
|
|
60
60
|
// src/adapters/next-client/constants/header-key-constants.ts
|
|
61
|
-
var
|
|
61
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
62
62
|
|
|
63
63
|
// src/shared/utils/locale/normalize-locale.ts
|
|
64
64
|
var normalizeLocale = (locale = "", supportedLocales = []) => {
|
|
@@ -116,28 +116,27 @@ var nextClientRuntime = async ({
|
|
|
116
116
|
config
|
|
117
117
|
}) => {
|
|
118
118
|
var _a;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
119
|
+
const cookiesStore = await headers.cookies();
|
|
120
|
+
const headersStore = await headers.headers();
|
|
121
|
+
const logger = logry.logry({ id: config.id, scope: "nextClientRuntime" });
|
|
123
122
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
124
|
-
let locale
|
|
123
|
+
let locale;
|
|
125
124
|
if (!cookie.disabled) {
|
|
126
|
-
const localeFromCookie = (_a =
|
|
125
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
127
126
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
128
127
|
if (locale) {
|
|
129
|
-
|
|
128
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
133
|
-
const aLHeader =
|
|
132
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
134
133
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
135
134
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
136
|
-
|
|
135
|
+
logger.debug("Get locale from browser:", { locale });
|
|
137
136
|
}
|
|
138
|
-
const pathname =
|
|
137
|
+
const pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
139
138
|
if (pathname) {
|
|
140
|
-
|
|
139
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
141
140
|
}
|
|
142
141
|
return {
|
|
143
142
|
locale: locale || defaultLocale,
|
|
@@ -149,34 +148,39 @@ var nextServerRuntime = async ({
|
|
|
149
148
|
request
|
|
150
149
|
}) => {
|
|
151
150
|
var _a;
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
151
|
+
const cookiesStore = await headers.cookies();
|
|
152
|
+
const headersStore = await headers.headers();
|
|
153
|
+
const logger = logry.logry({ id: config.id, scope: "nextServerRuntime" });
|
|
156
154
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
157
|
-
let locale
|
|
155
|
+
let locale;
|
|
158
156
|
if (!cookie.disabled) {
|
|
159
|
-
const localeFromCookie = (_a =
|
|
157
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
160
158
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
161
159
|
if (locale) {
|
|
162
|
-
|
|
160
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
163
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
166
|
-
const aLHeader =
|
|
164
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
167
165
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
168
166
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
169
|
-
|
|
167
|
+
logger.debug("Get locale from browser:", { locale });
|
|
170
168
|
}
|
|
171
169
|
let pathname = "";
|
|
172
170
|
if (request && typeof request === "object" && "nextUrl" in request) {
|
|
173
171
|
pathname = request.nextUrl.pathname;
|
|
174
172
|
if (pathname) {
|
|
175
|
-
|
|
173
|
+
logger.debug("Get pathname from next request:", { pathname });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!pathname) {
|
|
177
|
+
pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
178
|
+
if (pathname) {
|
|
179
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
182
|
if (!cookie.disabled && cookie.autoSetCookie) {
|
|
179
|
-
|
|
183
|
+
cookiesStore.set(__spreadProps(__spreadValues({
|
|
180
184
|
name: cookie.name,
|
|
181
185
|
value: locale || defaultLocale
|
|
182
186
|
}, cookie.domain ? { domain: cookie.domain } : {}), {
|
|
@@ -186,7 +190,7 @@ var nextServerRuntime = async ({
|
|
|
186
190
|
secure: cookie.secure,
|
|
187
191
|
sameSite: cookie.sameSite
|
|
188
192
|
}));
|
|
189
|
-
|
|
193
|
+
logger.debug("Set locale to cookie:", {
|
|
190
194
|
cookie: { name: cookie.name, value: locale || defaultLocale }
|
|
191
195
|
});
|
|
192
196
|
}
|
package/dist/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var IntorErrorCode = /* @__PURE__ */ ((IntorErrorCode2) => {
|
|
|
50
50
|
})(IntorErrorCode || {});
|
|
51
51
|
|
|
52
52
|
// src/adapters/next-client/constants/header-key-constants.ts
|
|
53
|
-
var
|
|
53
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
54
54
|
|
|
55
55
|
// src/shared/utils/locale/normalize-locale.ts
|
|
56
56
|
var normalizeLocale = (locale = "", supportedLocales = []) => {
|
|
@@ -108,28 +108,27 @@ var nextClientRuntime = async ({
|
|
|
108
108
|
config
|
|
109
109
|
}) => {
|
|
110
110
|
var _a;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
111
|
+
const cookiesStore = await cookies();
|
|
112
|
+
const headersStore = await headers();
|
|
113
|
+
const logger = logry({ id: config.id, scope: "nextClientRuntime" });
|
|
115
114
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
116
|
-
let locale
|
|
115
|
+
let locale;
|
|
117
116
|
if (!cookie.disabled) {
|
|
118
|
-
const localeFromCookie = (_a =
|
|
117
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
119
118
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
120
119
|
if (locale) {
|
|
121
|
-
|
|
120
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
125
|
-
const aLHeader =
|
|
124
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
126
125
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
127
126
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
128
|
-
|
|
127
|
+
logger.debug("Get locale from browser:", { locale });
|
|
129
128
|
}
|
|
130
|
-
const pathname =
|
|
129
|
+
const pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
131
130
|
if (pathname) {
|
|
132
|
-
|
|
131
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
133
132
|
}
|
|
134
133
|
return {
|
|
135
134
|
locale: locale || defaultLocale,
|
|
@@ -141,34 +140,39 @@ var nextServerRuntime = async ({
|
|
|
141
140
|
request
|
|
142
141
|
}) => {
|
|
143
142
|
var _a;
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
143
|
+
const cookiesStore = await cookies();
|
|
144
|
+
const headersStore = await headers();
|
|
145
|
+
const logger = logry({ id: config.id, scope: "nextServerRuntime" });
|
|
148
146
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
149
|
-
let locale
|
|
147
|
+
let locale;
|
|
150
148
|
if (!cookie.disabled) {
|
|
151
|
-
const localeFromCookie = (_a =
|
|
149
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
152
150
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
153
151
|
if (locale) {
|
|
154
|
-
|
|
152
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
155
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
158
|
-
const aLHeader =
|
|
156
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
159
157
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
160
158
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
161
|
-
|
|
159
|
+
logger.debug("Get locale from browser:", { locale });
|
|
162
160
|
}
|
|
163
161
|
let pathname = "";
|
|
164
162
|
if (request && typeof request === "object" && "nextUrl" in request) {
|
|
165
163
|
pathname = request.nextUrl.pathname;
|
|
166
164
|
if (pathname) {
|
|
167
|
-
|
|
165
|
+
logger.debug("Get pathname from next request:", { pathname });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!pathname) {
|
|
169
|
+
pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
170
|
+
if (pathname) {
|
|
171
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
if (!cookie.disabled && cookie.autoSetCookie) {
|
|
171
|
-
|
|
175
|
+
cookiesStore.set(__spreadProps(__spreadValues({
|
|
172
176
|
name: cookie.name,
|
|
173
177
|
value: locale || defaultLocale
|
|
174
178
|
}, cookie.domain ? { domain: cookie.domain } : {}), {
|
|
@@ -178,7 +182,7 @@ var nextServerRuntime = async ({
|
|
|
178
182
|
secure: cookie.secure,
|
|
179
183
|
sameSite: cookie.sameSite
|
|
180
184
|
}));
|
|
181
|
-
|
|
185
|
+
logger.debug("Set locale to cookie:", {
|
|
182
186
|
cookie: { name: cookie.name, value: locale || defaultLocale }
|
|
183
187
|
});
|
|
184
188
|
}
|
|
@@ -50,13 +50,13 @@ function setLocaleCookieEdge({
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// src/adapters/next-client/constants/header-key-constants.ts
|
|
53
|
-
var
|
|
53
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
54
54
|
|
|
55
55
|
// src/adapters/next-client/routing/utils/set-pathname-header.ts
|
|
56
56
|
var setPathnameHeader = ({
|
|
57
57
|
request,
|
|
58
58
|
response,
|
|
59
|
-
key =
|
|
59
|
+
key = DEFAULT_PATHNAME_HEADER_NAME
|
|
60
60
|
}) => {
|
|
61
61
|
const pathname = request.nextUrl.pathname;
|
|
62
62
|
response.headers.set(key, pathname);
|
package/dist/middleware/index.js
CHANGED
|
@@ -48,13 +48,13 @@ function setLocaleCookieEdge({
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/adapters/next-client/constants/header-key-constants.ts
|
|
51
|
-
var
|
|
51
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
52
52
|
|
|
53
53
|
// src/adapters/next-client/routing/utils/set-pathname-header.ts
|
|
54
54
|
var setPathnameHeader = ({
|
|
55
55
|
request,
|
|
56
56
|
response,
|
|
57
|
-
key =
|
|
57
|
+
key = DEFAULT_PATHNAME_HEADER_NAME
|
|
58
58
|
}) => {
|
|
59
59
|
const pathname = request.nextUrl.pathname;
|
|
60
60
|
response.headers.set(key, pathname);
|
package/dist/next/index.cjs
CHANGED
|
@@ -52,6 +52,9 @@ var __objRest = (source, exclude) => {
|
|
|
52
52
|
return target;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
// src/adapters/next-client/constants/header-key-constants.ts
|
|
56
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
57
|
+
|
|
55
58
|
// src/shared/utils/locale/normalize-locale.ts
|
|
56
59
|
var normalizeLocale = (locale = "", supportedLocales = []) => {
|
|
57
60
|
if (!locale || supportedLocales.length === 0) return void 0;
|
|
@@ -109,34 +112,39 @@ var nextServerRuntime = async ({
|
|
|
109
112
|
request
|
|
110
113
|
}) => {
|
|
111
114
|
var _a;
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
115
|
+
const cookiesStore = await headers.cookies();
|
|
116
|
+
const headersStore = await headers.headers();
|
|
117
|
+
const logger = logry.logry({ id: config.id, scope: "nextServerRuntime" });
|
|
116
118
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
117
|
-
let locale
|
|
119
|
+
let locale;
|
|
118
120
|
if (!cookie.disabled) {
|
|
119
|
-
const localeFromCookie = (_a =
|
|
121
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
120
122
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
121
123
|
if (locale) {
|
|
122
|
-
|
|
124
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
126
|
-
const aLHeader =
|
|
128
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
127
129
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
128
130
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
129
|
-
|
|
131
|
+
logger.debug("Get locale from browser:", { locale });
|
|
130
132
|
}
|
|
131
133
|
let pathname = "";
|
|
132
134
|
if (request && typeof request === "object" && "nextUrl" in request) {
|
|
133
135
|
pathname = request.nextUrl.pathname;
|
|
134
136
|
if (pathname) {
|
|
135
|
-
|
|
137
|
+
logger.debug("Get pathname from next request:", { pathname });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!pathname) {
|
|
141
|
+
pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
142
|
+
if (pathname) {
|
|
143
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
if (!cookie.disabled && cookie.autoSetCookie) {
|
|
139
|
-
|
|
147
|
+
cookiesStore.set(__spreadProps(__spreadValues({
|
|
140
148
|
name: cookie.name,
|
|
141
149
|
value: locale || defaultLocale
|
|
142
150
|
}, cookie.domain ? { domain: cookie.domain } : {}), {
|
|
@@ -146,7 +154,7 @@ var nextServerRuntime = async ({
|
|
|
146
154
|
secure: cookie.secure,
|
|
147
155
|
sameSite: cookie.sameSite
|
|
148
156
|
}));
|
|
149
|
-
|
|
157
|
+
logger.debug("Set locale to cookie:", {
|
|
150
158
|
cookie: { name: cookie.name, value: locale || defaultLocale }
|
|
151
159
|
});
|
|
152
160
|
}
|
|
@@ -167,37 +175,31 @@ var IntorError = class extends Error {
|
|
|
167
175
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
168
176
|
}
|
|
169
177
|
};
|
|
170
|
-
|
|
171
|
-
// src/adapters/next-client/constants/header-key-constants.ts
|
|
172
|
-
var DEFAULT_PATHNAME_HEADER_KEY = "x-intor-pathname";
|
|
173
|
-
|
|
174
|
-
// src/adapters/next-client/next-client-runtime/next-client-runtime.ts
|
|
175
178
|
var nextClientRuntime = async ({
|
|
176
179
|
config
|
|
177
180
|
}) => {
|
|
178
181
|
var _a;
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
182
|
+
const cookiesStore = await headers.cookies();
|
|
183
|
+
const headersStore = await headers.headers();
|
|
184
|
+
const logger = logry.logry({ id: config.id, scope: "nextClientRuntime" });
|
|
183
185
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
184
|
-
let locale
|
|
186
|
+
let locale;
|
|
185
187
|
if (!cookie.disabled) {
|
|
186
|
-
const localeFromCookie = (_a =
|
|
188
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
187
189
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
188
190
|
if (locale) {
|
|
189
|
-
|
|
191
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
193
|
-
const aLHeader =
|
|
195
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
194
196
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
195
197
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
196
|
-
|
|
198
|
+
logger.debug("Get locale from browser:", { locale });
|
|
197
199
|
}
|
|
198
|
-
const pathname =
|
|
200
|
+
const pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
199
201
|
if (pathname) {
|
|
200
|
-
|
|
202
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
201
203
|
}
|
|
202
204
|
return {
|
|
203
205
|
locale: locale || defaultLocale,
|
|
@@ -1398,7 +1400,7 @@ function setLocaleCookieEdge({
|
|
|
1398
1400
|
var setPathnameHeader = ({
|
|
1399
1401
|
request,
|
|
1400
1402
|
response,
|
|
1401
|
-
key =
|
|
1403
|
+
key = DEFAULT_PATHNAME_HEADER_NAME
|
|
1402
1404
|
}) => {
|
|
1403
1405
|
const pathname = request.nextUrl.pathname;
|
|
1404
1406
|
response.headers.set(key, pathname);
|
|
@@ -1734,6 +1736,7 @@ var useRouter = () => {
|
|
|
1734
1736
|
|
|
1735
1737
|
exports.IntorProvider = IntorProvider;
|
|
1736
1738
|
exports.Link = Link;
|
|
1739
|
+
exports.PATHNAME_HEADER_NAME = DEFAULT_PATHNAME_HEADER_NAME;
|
|
1737
1740
|
exports.TranslateHandlersProvider = TranslateHandlersProvider;
|
|
1738
1741
|
exports.createIntor = createIntor;
|
|
1739
1742
|
exports.intorMiddleware = intorMiddleware;
|
package/dist/next/index.d.cts
CHANGED
|
@@ -207,4 +207,6 @@ declare const useRouter: () => {
|
|
|
207
207
|
}) => void;
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
declare const DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
211
|
+
|
|
212
|
+
export { IntorProvider, Link, DEFAULT_PATHNAME_HEADER_NAME as PATHNAME_HEADER_NAME, TranslateHandlersProvider, createIntor, intorMiddleware, useIntor, useIntorConfig, useIntorLocale, useIntorMessages, useIntorTranslator, usePathname, useRouter, useTranslateHandlers };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -207,4 +207,6 @@ declare const useRouter: () => {
|
|
|
207
207
|
}) => void;
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
declare const DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
211
|
+
|
|
212
|
+
export { IntorProvider, Link, DEFAULT_PATHNAME_HEADER_NAME as PATHNAME_HEADER_NAME, TranslateHandlersProvider, createIntor, intorMiddleware, useIntor, useIntorConfig, useIntorLocale, useIntorMessages, useIntorTranslator, usePathname, useRouter, useTranslateHandlers };
|
package/dist/next/index.js
CHANGED
|
@@ -42,6 +42,9 @@ var __objRest = (source, exclude) => {
|
|
|
42
42
|
return target;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
// src/adapters/next-client/constants/header-key-constants.ts
|
|
46
|
+
var DEFAULT_PATHNAME_HEADER_NAME = "x-intor-pathname";
|
|
47
|
+
|
|
45
48
|
// src/shared/utils/locale/normalize-locale.ts
|
|
46
49
|
var normalizeLocale = (locale = "", supportedLocales = []) => {
|
|
47
50
|
if (!locale || supportedLocales.length === 0) return void 0;
|
|
@@ -99,34 +102,39 @@ var nextServerRuntime = async ({
|
|
|
99
102
|
request
|
|
100
103
|
}) => {
|
|
101
104
|
var _a;
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
105
|
+
const cookiesStore = await cookies();
|
|
106
|
+
const headersStore = await headers();
|
|
107
|
+
const logger = logry({ id: config.id, scope: "nextServerRuntime" });
|
|
106
108
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
107
|
-
let locale
|
|
109
|
+
let locale;
|
|
108
110
|
if (!cookie.disabled) {
|
|
109
|
-
const localeFromCookie = (_a =
|
|
111
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
110
112
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
111
113
|
if (locale) {
|
|
112
|
-
|
|
114
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
116
|
-
const aLHeader =
|
|
118
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
117
119
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
118
120
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
119
|
-
|
|
121
|
+
logger.debug("Get locale from browser:", { locale });
|
|
120
122
|
}
|
|
121
123
|
let pathname = "";
|
|
122
124
|
if (request && typeof request === "object" && "nextUrl" in request) {
|
|
123
125
|
pathname = request.nextUrl.pathname;
|
|
124
126
|
if (pathname) {
|
|
125
|
-
|
|
127
|
+
logger.debug("Get pathname from next request:", { pathname });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!pathname) {
|
|
131
|
+
pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
132
|
+
if (pathname) {
|
|
133
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
if (!cookie.disabled && cookie.autoSetCookie) {
|
|
129
|
-
|
|
137
|
+
cookiesStore.set(__spreadProps(__spreadValues({
|
|
130
138
|
name: cookie.name,
|
|
131
139
|
value: locale || defaultLocale
|
|
132
140
|
}, cookie.domain ? { domain: cookie.domain } : {}), {
|
|
@@ -136,7 +144,7 @@ var nextServerRuntime = async ({
|
|
|
136
144
|
secure: cookie.secure,
|
|
137
145
|
sameSite: cookie.sameSite
|
|
138
146
|
}));
|
|
139
|
-
|
|
147
|
+
logger.debug("Set locale to cookie:", {
|
|
140
148
|
cookie: { name: cookie.name, value: locale || defaultLocale }
|
|
141
149
|
});
|
|
142
150
|
}
|
|
@@ -157,37 +165,31 @@ var IntorError = class extends Error {
|
|
|
157
165
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
158
166
|
}
|
|
159
167
|
};
|
|
160
|
-
|
|
161
|
-
// src/adapters/next-client/constants/header-key-constants.ts
|
|
162
|
-
var DEFAULT_PATHNAME_HEADER_KEY = "x-intor-pathname";
|
|
163
|
-
|
|
164
|
-
// src/adapters/next-client/next-client-runtime/next-client-runtime.ts
|
|
165
168
|
var nextClientRuntime = async ({
|
|
166
169
|
config
|
|
167
170
|
}) => {
|
|
168
171
|
var _a;
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
172
|
+
const cookiesStore = await cookies();
|
|
173
|
+
const headersStore = await headers();
|
|
174
|
+
const logger = logry({ id: config.id, scope: "nextClientRuntime" });
|
|
173
175
|
const { defaultLocale, supportedLocales = [], cookie, routing } = config;
|
|
174
|
-
let locale
|
|
176
|
+
let locale;
|
|
175
177
|
if (!cookie.disabled) {
|
|
176
|
-
const localeFromCookie = (_a =
|
|
178
|
+
const localeFromCookie = (_a = cookiesStore.get(cookie.name)) == null ? void 0 : _a.value;
|
|
177
179
|
locale = normalizeLocale(localeFromCookie, supportedLocales);
|
|
178
180
|
if (locale) {
|
|
179
|
-
|
|
181
|
+
logger.debug("Get locale from cookie:", { locale });
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
if (!locale && routing.firstVisit.localeSource === "browser") {
|
|
183
|
-
const aLHeader =
|
|
185
|
+
const aLHeader = headersStore.get("accept-language") || void 0;
|
|
184
186
|
const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
|
|
185
187
|
locale = normalizeLocale(preferredLocale, supportedLocales);
|
|
186
|
-
|
|
188
|
+
logger.debug("Get locale from browser:", { locale });
|
|
187
189
|
}
|
|
188
|
-
const pathname =
|
|
190
|
+
const pathname = headersStore.get(DEFAULT_PATHNAME_HEADER_NAME);
|
|
189
191
|
if (pathname) {
|
|
190
|
-
|
|
192
|
+
logger.debug("Get pathname from next headers:", { pathname });
|
|
191
193
|
}
|
|
192
194
|
return {
|
|
193
195
|
locale: locale || defaultLocale,
|
|
@@ -1388,7 +1390,7 @@ function setLocaleCookieEdge({
|
|
|
1388
1390
|
var setPathnameHeader = ({
|
|
1389
1391
|
request,
|
|
1390
1392
|
response,
|
|
1391
|
-
key =
|
|
1393
|
+
key = DEFAULT_PATHNAME_HEADER_NAME
|
|
1392
1394
|
}) => {
|
|
1393
1395
|
const pathname = request.nextUrl.pathname;
|
|
1394
1396
|
response.headers.set(key, pathname);
|
|
@@ -1722,4 +1724,4 @@ var useRouter = () => {
|
|
|
1722
1724
|
}, rest);
|
|
1723
1725
|
};
|
|
1724
1726
|
|
|
1725
|
-
export { IntorProvider, Link, TranslateHandlersProvider, createIntor, intorMiddleware, useIntor, useIntorConfig, useIntorLocale, useIntorMessages, useIntorTranslator, usePathname, useRouter, useTranslateHandlers };
|
|
1727
|
+
export { IntorProvider, Link, DEFAULT_PATHNAME_HEADER_NAME as PATHNAME_HEADER_NAME, TranslateHandlersProvider, createIntor, intorMiddleware, useIntor, useIntorConfig, useIntorLocale, useIntorMessages, useIntorTranslator, usePathname, useRouter, useTranslateHandlers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "A modular and extensible i18n core designed for TypeScript and JavaScript projects. Intor enables custom translation logic with support for both frontend and backend environments, featuring runtime configuration, caching, adapters, and message loaders.",
|
|
5
5
|
"author": "Yiming Liao",
|
|
6
6
|
"license": "MIT",
|