intor 1.0.10 → 1.0.11

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/index.cjs CHANGED
@@ -43,6 +43,7 @@ var initializeLogger = ({
43
43
  level: loggerOptions == null ? void 0 : loggerOptions.level,
44
44
  scope
45
45
  }, loggerOptions));
46
+ console.log(loggerOptions);
46
47
  return logger;
47
48
  };
48
49
 
@@ -350,6 +351,57 @@ var nextClientRuntime = async ({
350
351
  pathname: pathname || ""
351
352
  };
352
353
  };
354
+ var nextServerRuntime = async ({
355
+ config,
356
+ request
357
+ }) => {
358
+ var _a;
359
+ const logger = logry.logry({
360
+ id: config.id,
361
+ scope: "nextServerRuntime"
362
+ });
363
+ const { defaultLocale, supportedLocales = [], cookie, routing } = config;
364
+ let locale = void 0;
365
+ if (!cookie.disabled) {
366
+ const localeFromCookie = (_a = (await headers.cookies()).get(cookie.name)) == null ? void 0 : _a.value;
367
+ locale = normalizeLocale(localeFromCookie, supportedLocales);
368
+ if (locale) {
369
+ void logger.debug("Get locale from cookie:", { locale });
370
+ }
371
+ }
372
+ if (!locale && routing.firstVisit.localeSource === "browser") {
373
+ const aLHeader = (await headers.headers()).get("accept-language") || void 0;
374
+ const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
375
+ locale = normalizeLocale(preferredLocale, supportedLocales);
376
+ void logger.debug("Get locale from browser:", { locale });
377
+ }
378
+ let pathname = "";
379
+ if (request && typeof request === "object" && "nextUrl" in request) {
380
+ pathname = request.nextUrl.pathname;
381
+ if (pathname) {
382
+ void logger.debug("Get pathname from next request:", { pathname });
383
+ }
384
+ }
385
+ if (!cookie.disabled && cookie.autoSetCookie) {
386
+ (await headers.cookies()).set(__spreadProps(__spreadValues({
387
+ name: cookie.name,
388
+ value: locale || defaultLocale
389
+ }, cookie.domain ? { domain: cookie.domain } : {}), {
390
+ path: cookie.path,
391
+ maxAge: cookie.maxAge,
392
+ httpOnly: cookie.httpOnly,
393
+ secure: cookie.secure,
394
+ sameSite: cookie.sameSite
395
+ }));
396
+ void logger.debug("Set locale to cookie:", {
397
+ cookie: { name: cookie.name, value: locale || defaultLocale }
398
+ });
399
+ }
400
+ return {
401
+ locale: locale || defaultLocale,
402
+ pathname: pathname || ""
403
+ };
404
+ };
353
405
 
354
406
  // src/modules/intor-adapter/resolve-adapter-runtime-loader.ts
355
407
  var resolceAdapterRuntimeLoader = async ({
@@ -360,7 +412,7 @@ var resolceAdapterRuntimeLoader = async ({
360
412
  if (adapter === "next-client") {
361
413
  loadedRuntime = nextClientRuntime;
362
414
  } else if (adapter === "next-server") {
363
- loadedRuntime = nextClientRuntime;
415
+ loadedRuntime = nextServerRuntime;
364
416
  }
365
417
  return loadedRuntime;
366
418
  };
package/dist/index.d.cts CHANGED
@@ -117,7 +117,7 @@ type IntorOptions = {
117
117
  translateHandlers?: TranslateHandlers;
118
118
  };
119
119
  type IntorNextClientClientResult = IntorRuntimeResult;
120
- type IntorNextServerServerResult = Translator<LocaleNamespaceMessages>;
120
+ type IntorNextServerServerResult = Translator<unknown>;
121
121
  type IntorResult = IntorNextClientClientResult & IntorNextServerServerResult;
122
122
 
123
123
  /**
package/dist/index.d.ts CHANGED
@@ -117,7 +117,7 @@ type IntorOptions = {
117
117
  translateHandlers?: TranslateHandlers;
118
118
  };
119
119
  type IntorNextClientClientResult = IntorRuntimeResult;
120
- type IntorNextServerServerResult = Translator<LocaleNamespaceMessages>;
120
+ type IntorNextServerServerResult = Translator<unknown>;
121
121
  type IntorResult = IntorNextClientClientResult & IntorNextServerServerResult;
122
122
 
123
123
  /**
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ var initializeLogger = ({
35
35
  level: loggerOptions == null ? void 0 : loggerOptions.level,
36
36
  scope
37
37
  }, loggerOptions));
38
+ console.log(loggerOptions);
38
39
  return logger;
39
40
  };
40
41
 
@@ -342,6 +343,57 @@ var nextClientRuntime = async ({
342
343
  pathname: pathname || ""
343
344
  };
344
345
  };
346
+ var nextServerRuntime = async ({
347
+ config,
348
+ request
349
+ }) => {
350
+ var _a;
351
+ const logger = logry({
352
+ id: config.id,
353
+ scope: "nextServerRuntime"
354
+ });
355
+ const { defaultLocale, supportedLocales = [], cookie, routing } = config;
356
+ let locale = void 0;
357
+ if (!cookie.disabled) {
358
+ const localeFromCookie = (_a = (await cookies()).get(cookie.name)) == null ? void 0 : _a.value;
359
+ locale = normalizeLocale(localeFromCookie, supportedLocales);
360
+ if (locale) {
361
+ void logger.debug("Get locale from cookie:", { locale });
362
+ }
363
+ }
364
+ if (!locale && routing.firstVisit.localeSource === "browser") {
365
+ const aLHeader = (await headers()).get("accept-language") || void 0;
366
+ const preferredLocale = resolvePreferredLocale(aLHeader, supportedLocales);
367
+ locale = normalizeLocale(preferredLocale, supportedLocales);
368
+ void logger.debug("Get locale from browser:", { locale });
369
+ }
370
+ let pathname = "";
371
+ if (request && typeof request === "object" && "nextUrl" in request) {
372
+ pathname = request.nextUrl.pathname;
373
+ if (pathname) {
374
+ void logger.debug("Get pathname from next request:", { pathname });
375
+ }
376
+ }
377
+ if (!cookie.disabled && cookie.autoSetCookie) {
378
+ (await cookies()).set(__spreadProps(__spreadValues({
379
+ name: cookie.name,
380
+ value: locale || defaultLocale
381
+ }, cookie.domain ? { domain: cookie.domain } : {}), {
382
+ path: cookie.path,
383
+ maxAge: cookie.maxAge,
384
+ httpOnly: cookie.httpOnly,
385
+ secure: cookie.secure,
386
+ sameSite: cookie.sameSite
387
+ }));
388
+ void logger.debug("Set locale to cookie:", {
389
+ cookie: { name: cookie.name, value: locale || defaultLocale }
390
+ });
391
+ }
392
+ return {
393
+ locale: locale || defaultLocale,
394
+ pathname: pathname || ""
395
+ };
396
+ };
345
397
 
346
398
  // src/modules/intor-adapter/resolve-adapter-runtime-loader.ts
347
399
  var resolceAdapterRuntimeLoader = async ({
@@ -352,7 +404,7 @@ var resolceAdapterRuntimeLoader = async ({
352
404
  if (adapter === "next-client") {
353
405
  loadedRuntime = nextClientRuntime;
354
406
  } else if (adapter === "next-server") {
355
- loadedRuntime = nextClientRuntime;
407
+ loadedRuntime = nextServerRuntime;
356
408
  }
357
409
  return loadedRuntime;
358
410
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
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",