@easy-cms/nuxt 0.41.0 → 0.43.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/runtime/cms.d.ts +2 -2
- package/dist/runtime/cms.js +3 -22
- package/dist/runtime/handler.js +6 -13
- package/package.json +5 -5
package/dist/runtime/cms.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Config, EasyCMS, AuthUser } from '@easy-cms/core';
|
|
|
2
2
|
import { H3Event } from 'h3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Returns the Easy CMS instance for this server, creating it on first use.
|
|
6
|
-
*
|
|
5
|
+
* Returns the Easy CMS instance for this server, creating it on first use. A config that changed
|
|
6
|
+
* (dev HMR) closes the old instance and makes a new one.
|
|
7
7
|
*/
|
|
8
8
|
declare function getEasyCMS(config: Config): Promise<EasyCMS>;
|
|
9
9
|
/** The logged-in Easy CMS user for a request (session cookie or Bearer token), or `null`. */
|
package/dist/runtime/cms.js
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createEasyCMS,
|
|
3
|
-
readCookie,
|
|
4
|
-
SESSION_COOKIE
|
|
5
|
-
} from "@easy-cms/core";
|
|
1
|
+
import { sharedEasyCMS } from "@easy-cms/core";
|
|
6
2
|
import { getRequestHeader } from "h3";
|
|
7
|
-
const KEY = /* @__PURE__ */ Symbol.for("easy-cms.nuxt");
|
|
8
|
-
const store = globalThis;
|
|
9
3
|
function getEasyCMS(config) {
|
|
10
|
-
|
|
11
|
-
if (cached?.config === config) return cached.promise;
|
|
12
|
-
if (cached) void cached.promise.then((cms) => cms.destroy()).catch(() => {
|
|
13
|
-
});
|
|
14
|
-
const promise = createEasyCMS(config);
|
|
15
|
-
store[KEY] = { config, promise };
|
|
16
|
-
promise.catch(() => {
|
|
17
|
-
if (store[KEY]?.promise === promise) delete store[KEY];
|
|
18
|
-
});
|
|
19
|
-
return promise;
|
|
4
|
+
return sharedEasyCMS(config);
|
|
20
5
|
}
|
|
21
6
|
async function getEasyCMSUser(config, event) {
|
|
22
7
|
const cms = await getEasyCMS(config);
|
|
23
|
-
|
|
24
|
-
if (authorization?.startsWith("Bearer ")) return cms.auth.verify(authorization.slice(7).trim());
|
|
25
|
-
const cookie = getRequestHeader(event, "cookie");
|
|
26
|
-
const token = cookie ? readCookie(new Request("http://x", { headers: { cookie } }), SESSION_COOKIE) : void 0;
|
|
27
|
-
return cms.auth.verify(token);
|
|
8
|
+
return cms.auth.userFromHeaders({ get: (name) => getRequestHeader(event, name) });
|
|
28
9
|
}
|
|
29
10
|
export {
|
|
30
11
|
getEasyCMS,
|
package/dist/runtime/handler.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createApiHandler } from "@easy-cms/core";
|
|
2
2
|
import { defineEventHandler, getRequestIP, sendWebResponse, toWebRequest } from "h3";
|
|
3
|
-
import { getEasyCMS } from "./cms.js";
|
|
4
3
|
function createHandler(config, options) {
|
|
5
|
-
const handlers = /* @__PURE__ */ new WeakMap();
|
|
6
4
|
const clientIps = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const api = createApiHandler(config, {
|
|
6
|
+
basePath: options.basePath,
|
|
7
|
+
getClientIp: (request) => clientIps.get(request)
|
|
8
|
+
});
|
|
7
9
|
return defineEventHandler(async (event) => {
|
|
8
|
-
const cms = await getEasyCMS(config);
|
|
9
|
-
let handler = handlers.get(cms);
|
|
10
|
-
if (!handler) {
|
|
11
|
-
handler = createRestHandler(cms, {
|
|
12
|
-
basePath: options.basePath,
|
|
13
|
-
getClientIp: (r) => clientIps.get(r)
|
|
14
|
-
});
|
|
15
|
-
handlers.set(cms, handler);
|
|
16
|
-
}
|
|
17
10
|
const request = toWebRequest(event);
|
|
18
11
|
clientIps.set(request, getRequestIP(event, { xForwardedFor: options.trustProxy }));
|
|
19
|
-
return sendWebResponse(event, await
|
|
12
|
+
return sendWebResponse(event, await api(request));
|
|
20
13
|
});
|
|
21
14
|
}
|
|
22
15
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Nuxt module for Easy CMS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@nuxt/kit": "^4.5.2",
|
|
22
22
|
"h3": "^1.15.11",
|
|
23
|
-
"@easy-cms/admin": "^0.
|
|
23
|
+
"@easy-cms/admin": "^0.43.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"nuxt": "^4.0.0",
|
|
27
|
-
"@easy-cms/core": "^0.
|
|
27
|
+
"@easy-cms/core": "^0.43.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@nuxt/schema": "^4.5.2",
|
|
31
31
|
"@nuxt/test-utils": "^4.3.2",
|
|
32
32
|
"nuxt": "^4.5.2",
|
|
33
33
|
"vue": "^3.5.0",
|
|
34
|
-
"@easy-cms/core": "^0.
|
|
35
|
-
"@easy-cms/db-sqlite": "^0.
|
|
34
|
+
"@easy-cms/core": "^0.43.0",
|
|
35
|
+
"@easy-cms/db-sqlite": "^0.43.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|