@easy-cms/next 0.40.0 → 0.42.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/index.d.ts +2 -1
- package/dist/index.js +7 -42
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Config, EasyCMS, AuthUser } from '@easy-cms/core';
|
|
|
3
3
|
type Handler = (request: Request) => Promise<Response>;
|
|
4
4
|
/**
|
|
5
5
|
* The Easy CMS Local API for this server, typed from your config. Use it in Server
|
|
6
|
-
* Components, Route Handlers and Server Actions. The instance survives hot reloads
|
|
6
|
+
* Components, Route Handlers and Server Actions. The instance survives hot reloads, and is the
|
|
7
|
+
* same for every server layer, which Next.js each bundles the config into.
|
|
7
8
|
*/
|
|
8
9
|
declare function getEasyCMS<const C extends Config>(config: C): Promise<EasyCMS<C>>;
|
|
9
10
|
interface RouteHandlerOptions {
|
package/dist/index.js
CHANGED
|
@@ -2,43 +2,17 @@
|
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
3
|
import { createRequire } from "module";
|
|
4
4
|
import { dirname, join } from "path";
|
|
5
|
-
import { APP_DIR,
|
|
5
|
+
import { APP_DIR, adminHandlerFor, SHELL_FILE } from "@easy-cms/admin";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
createEasyCMS,
|
|
9
|
-
createRestHandler,
|
|
10
|
-
readCookie,
|
|
7
|
+
createApiHandler,
|
|
11
8
|
resolveConfig,
|
|
12
|
-
|
|
9
|
+
sharedEasyCMS
|
|
13
10
|
} from "@easy-cms/core";
|
|
14
|
-
var KEY = /* @__PURE__ */ Symbol.for("easy-cms.next");
|
|
15
|
-
var store = globalThis;
|
|
16
11
|
function getEasyCMS(config) {
|
|
17
|
-
|
|
18
|
-
const signature = configSignature(config);
|
|
19
|
-
if (cached?.signature === signature) return cached.promise;
|
|
20
|
-
if (cached) void cached.promise.then((cms) => cms.destroy()).catch(() => {
|
|
21
|
-
});
|
|
22
|
-
const promise = createEasyCMS(config);
|
|
23
|
-
store[KEY] = { signature, promise };
|
|
24
|
-
promise.catch(() => {
|
|
25
|
-
if (store[KEY]?.promise === promise) delete store[KEY];
|
|
26
|
-
});
|
|
27
|
-
return promise;
|
|
12
|
+
return sharedEasyCMS(config);
|
|
28
13
|
}
|
|
29
14
|
function createRouteHandlers(config, options = {}) {
|
|
30
|
-
const
|
|
31
|
-
const handle = async (request) => {
|
|
32
|
-
const cms = await getEasyCMS(config);
|
|
33
|
-
let handler = handlers.get(cms);
|
|
34
|
-
if (!handler) {
|
|
35
|
-
handler = createRestHandler(cms, {
|
|
36
|
-
getClientIp: (r) => options.trustProxy ? r.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || void 0 : void 0
|
|
37
|
-
});
|
|
38
|
-
handlers.set(cms, handler);
|
|
39
|
-
}
|
|
40
|
-
return handler(request);
|
|
41
|
-
};
|
|
15
|
+
const handle = createApiHandler(config, { trustProxy: options.trustProxy === true });
|
|
42
16
|
return {
|
|
43
17
|
GET: handle,
|
|
44
18
|
HEAD: handle,
|
|
@@ -53,11 +27,7 @@ function createAdminRouteHandlers(config, options = {}) {
|
|
|
53
27
|
let handler;
|
|
54
28
|
const handle = async (request) => {
|
|
55
29
|
handler ??= resolveConfig(config).then(
|
|
56
|
-
(resolved) =>
|
|
57
|
-
basePath: resolved.admin.path,
|
|
58
|
-
apiPath: resolved.routes.api,
|
|
59
|
-
locale: resolved.admin.locale,
|
|
60
|
-
brand: resolved.admin.brand,
|
|
30
|
+
(resolved) => adminHandlerFor(resolved, {
|
|
61
31
|
// The site is this Next.js app.
|
|
62
32
|
siteUrl: resolved.admin.siteUrl || "/",
|
|
63
33
|
appDir: options.appDir ?? adminAppDir(),
|
|
@@ -71,13 +41,8 @@ function createAdminRouteHandlers(config, options = {}) {
|
|
|
71
41
|
}
|
|
72
42
|
async function getEasyCMSUser(config) {
|
|
73
43
|
const { headers } = await import("next/headers.js");
|
|
74
|
-
const all = await headers();
|
|
75
44
|
const cms = await getEasyCMS(config);
|
|
76
|
-
|
|
77
|
-
if (authorization?.startsWith("Bearer ")) return cms.auth.verify(authorization.slice(7).trim());
|
|
78
|
-
const cookie = all.get("cookie");
|
|
79
|
-
const token = cookie ? readCookie(new Request("http://x", { headers: { cookie } }), SESSION_COOKIE) : void 0;
|
|
80
|
-
return cms.auth.verify(token);
|
|
45
|
+
return cms.auth.userFromHeaders(await headers());
|
|
81
46
|
}
|
|
82
47
|
function adminAppDir() {
|
|
83
48
|
if (existsSync(join(APP_DIR, SHELL_FILE))) return APP_DIR;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Next.js adapter for Easy CMS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"node": ">=22.12"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@easy-cms/admin": "^0.
|
|
29
|
+
"@easy-cms/admin": "^0.42.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"next": ">=15.0.0",
|
|
33
33
|
"react": ">=19.0.0",
|
|
34
|
-
"@easy-cms/core": "^0.
|
|
34
|
+
"@easy-cms/core": "^0.42.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^19.2.0",
|
|
38
38
|
"next": "^16.3.6",
|
|
39
39
|
"react": "^19.2.0",
|
|
40
|
-
"@easy-cms/core": "^0.
|
|
41
|
-
"@easy-cms/db-sqlite": "^0.
|
|
40
|
+
"@easy-cms/core": "^0.42.0",
|
|
41
|
+
"@easy-cms/db-sqlite": "^0.42.0"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|