@shware/security 0.4.3
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/README.md +1 -0
- package/dist/auth/index.cjs +158 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +27 -0
- package/dist/auth/index.d.ts +27 -0
- package/dist/auth/index.mjs +129 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/auth/types.cjs +19 -0
- package/dist/auth/types.cjs.map +1 -0
- package/dist/auth/types.d.cts +25 -0
- package/dist/auth/types.d.ts +25 -0
- package/dist/auth/types.mjs +1 -0
- package/dist/auth/types.mjs.map +1 -0
- package/dist/core/index.cjs +19 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +17 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.mjs +1 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oauth2/client.cjs +110 -0
- package/dist/oauth2/client.cjs.map +1 -0
- package/dist/oauth2/client.d.cts +39 -0
- package/dist/oauth2/client.d.ts +39 -0
- package/dist/oauth2/client.mjs +74 -0
- package/dist/oauth2/client.mjs.map +1 -0
- package/dist/oauth2/error.cjs +54 -0
- package/dist/oauth2/error.cjs.map +1 -0
- package/dist/oauth2/error.d.cts +11 -0
- package/dist/oauth2/error.d.ts +11 -0
- package/dist/oauth2/error.mjs +28 -0
- package/dist/oauth2/error.mjs.map +1 -0
- package/dist/oauth2/provider/apple.cjs +85 -0
- package/dist/oauth2/provider/apple.cjs.map +1 -0
- package/dist/oauth2/provider/apple.d.cts +31 -0
- package/dist/oauth2/provider/apple.d.ts +31 -0
- package/dist/oauth2/provider/apple.mjs +50 -0
- package/dist/oauth2/provider/apple.mjs.map +1 -0
- package/dist/oauth2/provider/common.cjs +159 -0
- package/dist/oauth2/provider/common.cjs.map +1 -0
- package/dist/oauth2/provider/common.d.cts +38 -0
- package/dist/oauth2/provider/common.d.ts +38 -0
- package/dist/oauth2/provider/common.mjs +119 -0
- package/dist/oauth2/provider/common.mjs.map +1 -0
- package/dist/oauth2/provider/facebook.cjs +106 -0
- package/dist/oauth2/provider/facebook.cjs.map +1 -0
- package/dist/oauth2/provider/facebook.d.cts +29 -0
- package/dist/oauth2/provider/facebook.d.ts +29 -0
- package/dist/oauth2/provider/facebook.mjs +71 -0
- package/dist/oauth2/provider/facebook.mjs.map +1 -0
- package/dist/oauth2/provider/github.cjs +101 -0
- package/dist/oauth2/provider/github.cjs.map +1 -0
- package/dist/oauth2/provider/github.d.cts +51 -0
- package/dist/oauth2/provider/github.d.ts +51 -0
- package/dist/oauth2/provider/github.mjs +66 -0
- package/dist/oauth2/provider/github.mjs.map +1 -0
- package/dist/oauth2/provider/google.cjs +91 -0
- package/dist/oauth2/provider/google.cjs.map +1 -0
- package/dist/oauth2/provider/google.d.cts +35 -0
- package/dist/oauth2/provider/google.d.ts +35 -0
- package/dist/oauth2/provider/google.mjs +56 -0
- package/dist/oauth2/provider/google.mjs.map +1 -0
- package/dist/oauth2/provider/index.cjs +43 -0
- package/dist/oauth2/provider/index.cjs.map +1 -0
- package/dist/oauth2/provider/index.d.cts +6 -0
- package/dist/oauth2/provider/index.d.ts +6 -0
- package/dist/oauth2/provider/index.mjs +14 -0
- package/dist/oauth2/provider/index.mjs.map +1 -0
- package/dist/oauth2/provider/x.cjs +126 -0
- package/dist/oauth2/provider/x.cjs.map +1 -0
- package/dist/oauth2/provider/x.d.cts +60 -0
- package/dist/oauth2/provider/x.d.ts +60 -0
- package/dist/oauth2/provider/x.mjs +97 -0
- package/dist/oauth2/provider/x.mjs.map +1 -0
- package/dist/oauth2/schema.cjs +2 -0
- package/dist/oauth2/schema.cjs.map +1 -0
- package/dist/oauth2/schema.d.cts +2 -0
- package/dist/oauth2/schema.d.ts +2 -0
- package/dist/oauth2/schema.mjs +1 -0
- package/dist/oauth2/schema.mjs.map +1 -0
- package/dist/oauth2/types.cjs +19 -0
- package/dist/oauth2/types.cjs.map +1 -0
- package/dist/oauth2/types.d.cts +138 -0
- package/dist/oauth2/types.d.ts +138 -0
- package/dist/oauth2/types.mjs +1 -0
- package/dist/oauth2/types.mjs.map +1 -0
- package/dist/oidc/index.cjs +39 -0
- package/dist/oidc/index.cjs.map +1 -0
- package/dist/oidc/index.d.cts +10 -0
- package/dist/oidc/index.d.ts +10 -0
- package/dist/oidc/index.mjs +14 -0
- package/dist/oidc/index.mjs.map +1 -0
- package/dist/session/__test__/redis-session.test.cjs +94 -0
- package/dist/session/__test__/redis-session.test.cjs.map +1 -0
- package/dist/session/__test__/redis-session.test.d.cts +2 -0
- package/dist/session/__test__/redis-session.test.d.ts +2 -0
- package/dist/session/__test__/redis-session.test.mjs +70 -0
- package/dist/session/__test__/redis-session.test.mjs.map +1 -0
- package/dist/session/index.cjs +33 -0
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +4 -0
- package/dist/session/index.d.ts +4 -0
- package/dist/session/index.mjs +7 -0
- package/dist/session/index.mjs.map +1 -0
- package/dist/session/redis-session.cjs +403 -0
- package/dist/session/redis-session.cjs.map +1 -0
- package/dist/session/redis-session.d.cts +73 -0
- package/dist/session/redis-session.d.ts +73 -0
- package/dist/session/redis-session.mjs +377 -0
- package/dist/session/redis-session.mjs.map +1 -0
- package/dist/session/types.cjs +19 -0
- package/dist/session/types.cjs.map +1 -0
- package/dist/session/types.d.cts +39 -0
- package/dist/session/types.d.ts +39 -0
- package/dist/session/types.mjs +1 -0
- package/dist/session/types.mjs.map +1 -0
- package/dist/utils/http.cjs +63 -0
- package/dist/utils/http.cjs.map +1 -0
- package/dist/utils/http.d.cts +17 -0
- package/dist/utils/http.d.ts +17 -0
- package/dist/utils/http.mjs +34 -0
- package/dist/utils/http.mjs.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/utils/http.ts
|
|
2
|
+
import { parse, serialize } from "cookie";
|
|
3
|
+
import { match } from "path-to-regexp";
|
|
4
|
+
function getCookie(request, name) {
|
|
5
|
+
const cookie = request.headers.get("Cookie");
|
|
6
|
+
if (!cookie) return void 0;
|
|
7
|
+
const parsed = parse(cookie);
|
|
8
|
+
return parsed[name];
|
|
9
|
+
}
|
|
10
|
+
function setCookie(response, name, value, options) {
|
|
11
|
+
response.headers.append("Set-Cookie", serialize(name, value, options));
|
|
12
|
+
}
|
|
13
|
+
function deleteCookie(response, name, options) {
|
|
14
|
+
response.headers.append("Set-Cookie", serialize(name, "", { ...options, maxAge: 0 }));
|
|
15
|
+
}
|
|
16
|
+
function param(request, path) {
|
|
17
|
+
const url = new URL(request.url);
|
|
18
|
+
const fn = match(path);
|
|
19
|
+
const result = fn(url.pathname);
|
|
20
|
+
if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);
|
|
21
|
+
return result.params;
|
|
22
|
+
}
|
|
23
|
+
function query(request) {
|
|
24
|
+
const params = new URLSearchParams(request.url);
|
|
25
|
+
return Object.fromEntries(params.entries());
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
deleteCookie,
|
|
29
|
+
getCookie,
|
|
30
|
+
param,
|
|
31
|
+
query,
|
|
32
|
+
setCookie
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=http.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/http.ts"],"sourcesContent":["import { parse, serialize, type SerializeOptions } from 'cookie';\nimport { match } from 'path-to-regexp';\n\nexport type CookieOptions = Omit<SerializeOptions, 'encode'>;\n\nexport function getCookie(request: Request, name: string): string | undefined {\n const cookie = request.headers.get('Cookie');\n if (!cookie) return undefined;\n const parsed = parse(cookie);\n return parsed[name];\n}\n\nexport function setCookie(\n response: Response,\n name: string,\n value: string,\n options?: SerializeOptions\n) {\n response.headers.append('Set-Cookie', serialize(name, value, options));\n}\n\nexport function deleteCookie(response: Response, name: string, options?: SerializeOptions) {\n response.headers.append('Set-Cookie', serialize(name, '', { ...options, maxAge: 0 }));\n}\n\ntype PathParam<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`\n ? { [K in Param]: string } & PathParam<Rest>\n : T extends `${string}:${infer Param}`\n ? { [K in Param]: string }\n : {};\n\nexport function param<P extends string>(request: Request, path: P): PathParam<P> {\n const url = new URL(request.url);\n const fn = match(path);\n const result = fn(url.pathname);\n if (!result) throw new Error(`Path not matched: ${url.pathname}, path: ${path}`);\n return result.params as PathParam<P>;\n}\n\nexport function query(request: Request) {\n const params = new URLSearchParams(request.url);\n return Object.fromEntries(params.entries());\n}\n"],"mappings":";AAAA,SAAS,OAAO,iBAAwC;AACxD,SAAS,aAAa;AAIf,SAAS,UAAU,SAAkB,MAAkC;AAC5E,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,SAAS,MAAM,MAAM;AAC3B,SAAO,OAAO,IAAI;AACpB;AAEO,SAAS,UACd,UACA,MACA,OACA,SACA;AACA,WAAS,QAAQ,OAAO,cAAc,UAAU,MAAM,OAAO,OAAO,CAAC;AACvE;AAEO,SAAS,aAAa,UAAoB,MAAc,SAA4B;AACzF,WAAS,QAAQ,OAAO,cAAc,UAAU,MAAM,IAAI,EAAE,GAAG,SAAS,QAAQ,EAAE,CAAC,CAAC;AACtF;AAQO,SAAS,MAAwB,SAAkB,MAAuB;AAC/E,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,QAAM,KAAK,MAAM,IAAI;AACrB,QAAM,SAAS,GAAG,IAAI,QAAQ;AAC9B,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB,IAAI,QAAQ,WAAW,IAAI,EAAE;AAC/E,SAAO,OAAO;AAChB;AAEO,SAAS,MAAM,SAAkB;AACtC,QAAM,SAAS,IAAI,gBAAgB,QAAQ,GAAG;AAC9C,SAAO,OAAO,YAAY,OAAO,QAAQ,CAAC;AAC5C;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shware/security",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "tsc --watch",
|
|
8
|
+
"build": "tsup",
|
|
9
|
+
"test": "jest"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./oauth2/provider": {
|
|
18
|
+
"types": "./dist/oauth2/provider/index.d.ts",
|
|
19
|
+
"import": "./dist/oauth2/provider/index.mjs",
|
|
20
|
+
"require": "./dist/oauth2/provider/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^29.5.14",
|
|
28
|
+
"@types/jsonwebtoken": "^9.0.9",
|
|
29
|
+
"@types/node": "^22.13.13",
|
|
30
|
+
"jest": "^29.7.0",
|
|
31
|
+
"ts-jest": "^29.3.0",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "5.5.4"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"cookie": "^1.0.2",
|
|
37
|
+
"ioredis": "^5.6.0",
|
|
38
|
+
"jsonwebtoken": "^9.0.2",
|
|
39
|
+
"path-to-regexp": "^8.2.0",
|
|
40
|
+
"tiny-invariant": "^1.3.3",
|
|
41
|
+
"undici": "^7.5.0",
|
|
42
|
+
"zod": "^3.24.2"
|
|
43
|
+
}
|
|
44
|
+
}
|