@cedarjs/server-store 0.0.4
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/serverStore.d.ts +24 -0
- package/dist/serverStore.d.ts.map +1 -0
- package/dist/serverStore.js +83 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cedar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import type { ServerAuthState } from '@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js' with { 'resolution-mode': 'import' };
|
|
3
|
+
import { CookieJar } from '@cedarjs/cookie-jar';
|
|
4
|
+
export interface ServerStore extends Map<string, any> {
|
|
5
|
+
}
|
|
6
|
+
type InitPerReqMapParams = {
|
|
7
|
+
headers: Headers | Record<string, string>;
|
|
8
|
+
fullUrl: string;
|
|
9
|
+
serverAuthState?: ServerAuthState;
|
|
10
|
+
};
|
|
11
|
+
export declare const createServerStorage: () => AsyncLocalStorage<ServerStore>;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* This function just creates a Map, that you pass to
|
|
15
|
+
* serverStorage.run(MAP_HERE, () => { ... })
|
|
16
|
+
*/
|
|
17
|
+
export declare const createPerRequestMap: ({ headers, fullUrl, serverAuthState, }: InitPerReqMapParams) => Map<any, any>;
|
|
18
|
+
export declare const getRequestCookies: () => CookieJar;
|
|
19
|
+
export declare const getRequestHeaders: () => Headers;
|
|
20
|
+
export declare const getAuthState: () => ServerAuthState;
|
|
21
|
+
export declare const getLocation: () => URL;
|
|
22
|
+
export declare const setServerAuthState: (authState: ServerAuthState) => void;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=serverStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverStore.d.ts","sourceRoot":"","sources":["../src/serverStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAC,OAAO,iBAAiB,EAAE,QAAQ,EAAE,CAAA;AACjI,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAG/C,MAAM,WAAW,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;CAAG;AAIxD,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,eAAe,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,mBAAmB,sCAI/B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,2CAI7B,mBAAmB,kBAarB,CAAA;AAYD,eAAO,MAAM,iBAAiB,QAAO,SAIpC,CAAA;AAID,eAAO,MAAM,iBAAiB,QAAO,OAEpC,CAAA;AAED,eAAO,MAAM,YAAY,QAAO,eAE/B,CAAA;AAED,eAAO,MAAM,WAAW,QAAO,GAE9B,CAAA;AAED,eAAO,MAAM,kBAAkB,cAAe,eAAe,SAG5D,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var serverStore_exports = {};
|
|
20
|
+
__export(serverStore_exports, {
|
|
21
|
+
createPerRequestMap: () => createPerRequestMap,
|
|
22
|
+
createServerStorage: () => createServerStorage,
|
|
23
|
+
getAuthState: () => getAuthState,
|
|
24
|
+
getLocation: () => getLocation,
|
|
25
|
+
getRequestCookies: () => getRequestCookies,
|
|
26
|
+
getRequestHeaders: () => getRequestHeaders,
|
|
27
|
+
setServerAuthState: () => setServerAuthState
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(serverStore_exports);
|
|
30
|
+
var import_async_hooks = require("async_hooks");
|
|
31
|
+
var import_cookie_jar = require("@cedarjs/cookie-jar");
|
|
32
|
+
let PER_REQ_STORAGE;
|
|
33
|
+
const createServerStorage = () => {
|
|
34
|
+
PER_REQ_STORAGE = new import_async_hooks.AsyncLocalStorage();
|
|
35
|
+
return PER_REQ_STORAGE;
|
|
36
|
+
};
|
|
37
|
+
const createPerRequestMap = ({
|
|
38
|
+
headers,
|
|
39
|
+
fullUrl,
|
|
40
|
+
serverAuthState
|
|
41
|
+
}) => {
|
|
42
|
+
const reqStore = /* @__PURE__ */ new Map();
|
|
43
|
+
const headersObj = new Headers(headers);
|
|
44
|
+
reqStore.set("headers", headersObj);
|
|
45
|
+
reqStore.set("fullUrl", fullUrl);
|
|
46
|
+
if (serverAuthState) {
|
|
47
|
+
reqStore.set("serverAuthState", serverAuthState);
|
|
48
|
+
}
|
|
49
|
+
return reqStore;
|
|
50
|
+
};
|
|
51
|
+
const getStore = () => {
|
|
52
|
+
if (!PER_REQ_STORAGE) {
|
|
53
|
+
throw new Error("Server store not initialized");
|
|
54
|
+
}
|
|
55
|
+
return PER_REQ_STORAGE.getStore();
|
|
56
|
+
};
|
|
57
|
+
const getRequestCookies = () => {
|
|
58
|
+
const headers = getRequestHeaders();
|
|
59
|
+
return new import_cookie_jar.CookieJar(headers.get("cookie"));
|
|
60
|
+
};
|
|
61
|
+
const getRequestHeaders = () => {
|
|
62
|
+
return getStore()?.get("headers");
|
|
63
|
+
};
|
|
64
|
+
const getAuthState = () => {
|
|
65
|
+
return getStore()?.get("serverAuthState");
|
|
66
|
+
};
|
|
67
|
+
const getLocation = () => {
|
|
68
|
+
return new URL(getStore()?.get("fullUrl"));
|
|
69
|
+
};
|
|
70
|
+
const setServerAuthState = (authState) => {
|
|
71
|
+
const store = getStore();
|
|
72
|
+
store?.set("serverAuthState", authState);
|
|
73
|
+
};
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
createPerRequestMap,
|
|
77
|
+
createServerStorage,
|
|
78
|
+
getAuthState,
|
|
79
|
+
getLocation,
|
|
80
|
+
getRequestCookies,
|
|
81
|
+
getRequestHeaders,
|
|
82
|
+
setServerAuthState
|
|
83
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cedarjs/server-store",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
7
|
+
"directory": "packages/server-store"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "commonjs",
|
|
11
|
+
"exports": {
|
|
12
|
+
"types": "./dist/serverStore.d.ts",
|
|
13
|
+
"default": "./dist/serverStore.js"
|
|
14
|
+
},
|
|
15
|
+
"types": "./dist/serverStore.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsx ./build.mts && run build:types",
|
|
21
|
+
"build:pack": "yarn pack -o cedar-server-store.tgz",
|
|
22
|
+
"build:types": "tsc --build --verbose"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@cedarjs/auth": "0.0.4",
|
|
26
|
+
"@cedarjs/cookie-jar": "0.0.4",
|
|
27
|
+
"esbuild": "0.25.0",
|
|
28
|
+
"fast-glob": "3.3.2",
|
|
29
|
+
"fs-extra": "11.2.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@cedarjs/framework-tools": "0.0.4",
|
|
33
|
+
"@types/fs-extra": "11.0.4",
|
|
34
|
+
"tsx": "4.19.3",
|
|
35
|
+
"typescript": "5.6.2"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "5b4f77f985bd86ee31ee7338312627accf0cb85b"
|
|
41
|
+
}
|