@better-i18n/next 0.1.0 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-i18n/next",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Better-i18n Next.js integration",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,6 +32,10 @@
32
32
  "types": "./src/middleware.ts",
33
33
  "default": "./src/middleware.ts"
34
34
  },
35
+ "./proxy": {
36
+ "types": "./src/proxy.ts",
37
+ "default": "./src/proxy.ts"
38
+ },
35
39
  "./package.json": "./package.json"
36
40
  },
37
41
  "files": [
package/src/client.ts CHANGED
@@ -26,7 +26,7 @@ type ClientCacheEntry = {
26
26
  const clientCache = new Map<string, ClientCacheEntry>();
27
27
 
28
28
  const getCacheKey = (config: I18nConfig) =>
29
- `${config.cdnBaseUrl || "https://cdn.better-i18n.com"}|${config.workspaceId}|${config.projectSlug}`;
29
+ `${config.cdnBaseUrl || "https://cdn.better-i18n.com"}|${config.project}`;
30
30
 
31
31
  const fetchManifestLanguages = async (
32
32
  config: I18nConfig,
@@ -62,8 +62,7 @@ export const useManifestLanguages = (
62
62
  const normalized = useMemo(
63
63
  () => normalizeConfig(config),
64
64
  [
65
- config.workspaceId,
66
- config.projectSlug,
65
+ config.project,
67
66
  config.defaultLocale,
68
67
  config.cdnBaseUrl,
69
68
  config.localePrefix,
package/src/config.ts CHANGED
@@ -1,20 +1,37 @@
1
- import type { I18nConfig, NormalizedConfig } from "./types";
1
+ import type { I18nConfig, NormalizedConfig, ParsedProject } from "./types";
2
2
 
3
3
  const DEFAULT_CDN_BASE_URL = "https://cdn.better-i18n.com";
4
4
 
5
- export const normalizeConfig = (config: I18nConfig): NormalizedConfig => {
6
- if (!config.workspaceId?.trim()) {
7
- throw new Error("[better-i18n] workspaceId is required");
5
+ /**
6
+ * Parse project string "org/slug" into workspaceId and projectSlug
7
+ */
8
+ export const parseProject = (project: string): ParsedProject => {
9
+ const parts = project.split("/");
10
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
11
+ throw new Error(
12
+ `[better-i18n] Invalid project format "${project}". Expected "org/project" (e.g., "carna/landing")`
13
+ );
8
14
  }
9
- if (!config.projectSlug?.trim()) {
10
- throw new Error("[better-i18n] projectSlug is required");
15
+ return {
16
+ workspaceId: parts[0],
17
+ projectSlug: parts[1],
18
+ };
19
+ };
20
+
21
+ export const normalizeConfig = (config: I18nConfig): NormalizedConfig => {
22
+ if (!config.project?.trim()) {
23
+ throw new Error("[better-i18n] project is required");
11
24
  }
12
25
  if (!config.defaultLocale?.trim()) {
13
26
  throw new Error("[better-i18n] defaultLocale is required");
14
27
  }
15
28
 
29
+ const { workspaceId, projectSlug } = parseProject(config.project);
30
+
16
31
  return {
17
32
  ...config,
33
+ workspaceId,
34
+ projectSlug,
18
35
  cdnBaseUrl: config.cdnBaseUrl?.replace(/\/$/, "") || DEFAULT_CDN_BASE_URL,
19
36
  localePrefix: config.localePrefix ?? "as-needed",
20
37
  manifestCacheTtlMs: config.manifestCacheTtlMs ?? 5 * 60 * 1000,
package/src/core.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { normalizeConfig, getProjectBaseUrl } from "./config";
1
+ import { getProjectBaseUrl, normalizeConfig } from "./config";
2
2
  import { createLogger } from "./logger";
3
3
  import { extractLanguages } from "./manifest";
4
4
  import type {
@@ -18,7 +18,7 @@ type ManifestCacheEntry = {
18
18
  const manifestCache = new Map<string, ManifestCacheEntry>();
19
19
 
20
20
  const buildCacheKey = (config: NormalizedConfig) =>
21
- `${config.cdnBaseUrl}|${config.workspaceId}|${config.projectSlug}`;
21
+ `${config.cdnBaseUrl}|${config.project}`;
22
22
 
23
23
  const withRevalidate = (
24
24
  init: NextFetchRequestInit,
package/src/proxy.ts ADDED
@@ -0,0 +1 @@
1
+ export { createI18nProxy } from "./middleware";
package/src/types.ts CHANGED
@@ -5,8 +5,8 @@ export type LocalePrefix = "as-needed" | "always" | "never";
5
5
  export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
6
6
 
7
7
  export interface I18nConfig {
8
- workspaceId: string;
9
- projectSlug: string;
8
+ /** Project identifier in format "org/project" (e.g., "carna/landing") */
9
+ project: string;
10
10
  defaultLocale: string;
11
11
  cdnBaseUrl?: string;
12
12
  localePrefix?: LocalePrefix;
@@ -18,7 +18,13 @@ export interface I18nConfig {
18
18
  fetch?: typeof fetch;
19
19
  }
20
20
 
21
- export interface NormalizedConfig extends I18nConfig {
21
+ /** Parsed project identifier */
22
+ export interface ParsedProject {
23
+ workspaceId: string;
24
+ projectSlug: string;
25
+ }
26
+
27
+ export interface NormalizedConfig extends I18nConfig, ParsedProject {
22
28
  cdnBaseUrl: string;
23
29
  localePrefix: LocalePrefix;
24
30
  }