@gauts/auth 0.2.2 → 0.3.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/README.md +465 -438
- package/SECURITY.md +44 -1
- package/dist/adapters/hono/index.d.ts +33 -19
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +134 -55
- package/dist/adapters/hono/index.js.map +1 -1
- package/dist/adapters/next/index.d.ts +24 -0
- package/dist/adapters/next/index.d.ts.map +1 -0
- package/dist/adapters/next/index.js +93 -0
- package/dist/adapters/next/index.js.map +1 -0
- package/dist/adapters/prisma/index.d.ts +12 -4
- package/dist/adapters/prisma/index.d.ts.map +1 -1
- package/dist/adapters/prisma/index.js +95 -9
- package/dist/adapters/prisma/index.js.map +1 -1
- package/dist/auth.d.ts +8 -6
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +7 -9
- package/dist/auth.js.map +1 -1
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -1
- package/dist/client/index.js.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -7
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/session/cache.d.ts +32 -0
- package/dist/session/cache.d.ts.map +1 -0
- package/dist/session/cache.js +136 -0
- package/dist/session/cache.js.map +1 -0
- package/dist/session/cookie.d.ts +15 -0
- package/dist/session/cookie.d.ts.map +1 -0
- package/dist/session/cookie.js +31 -0
- package/dist/session/cookie.js.map +1 -0
- package/dist/session/guards.d.ts +6 -0
- package/dist/session/guards.d.ts.map +1 -0
- package/dist/session/guards.js +23 -0
- package/dist/session/guards.js.map +1 -0
- package/dist/session/service.d.ts +2 -3
- package/dist/session/service.d.ts.map +1 -1
- package/dist/session/service.js +117 -162
- package/dist/session/service.js.map +1 -1
- package/dist/session/types.d.ts +47 -58
- package/dist/session/types.d.ts.map +1 -1
- package/package.json +9 -10
- package/dist/adapters/redis/index.d.ts +0 -11
- package/dist/adapters/redis/index.d.ts.map +0 -1
- package/dist/adapters/redis/index.js +0 -62
- package/dist/adapters/redis/index.js.map +0 -1
- package/dist/session/schema.d.ts +0 -5
- package/dist/session/schema.d.ts.map +0 -1
- package/dist/session/schema.js +0 -56
- package/dist/session/schema.js.map +0 -1
package/dist/session/types.d.ts
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
1
|
import type { SessionClient, SessionClientInput } from "../client/index.js";
|
|
2
|
-
export type
|
|
3
|
-
|
|
2
|
+
export type AuthUser = {
|
|
3
|
+
id: string;
|
|
4
|
+
role: string;
|
|
5
|
+
status: string;
|
|
6
|
+
};
|
|
7
|
+
export type AuthAccount = {
|
|
8
|
+
email: string;
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
role: string;
|
|
12
|
+
status: string;
|
|
13
|
+
timezone: string | null;
|
|
14
|
+
user: AuthUser;
|
|
15
|
+
};
|
|
16
|
+
export type SessionRecord = {
|
|
4
17
|
account_id: string;
|
|
5
|
-
|
|
6
|
-
created_at:
|
|
7
|
-
|
|
8
|
-
expires_at: string;
|
|
18
|
+
agent: string | null;
|
|
19
|
+
created_at: Date;
|
|
20
|
+
expires_at: Date;
|
|
9
21
|
id: string;
|
|
10
|
-
|
|
22
|
+
ip: string | null;
|
|
23
|
+
platform: string | null;
|
|
24
|
+
revoked_at: Date | null;
|
|
25
|
+
token_hash: string;
|
|
26
|
+
updated_at: Date | null;
|
|
11
27
|
};
|
|
12
|
-
export type
|
|
28
|
+
export type AuthSessionRecord = SessionRecord & {
|
|
29
|
+
account: AuthAccount;
|
|
30
|
+
allowed: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type CreateSessionRecord = Omit<SessionRecord, "revoked_at" | "updated_at">;
|
|
33
|
+
export type ActiveSession = Omit<SessionRecord, "token_hash">;
|
|
34
|
+
export type Session = {
|
|
13
35
|
account_id: string;
|
|
14
36
|
client: SessionClient;
|
|
15
37
|
created_at: Date;
|
|
16
|
-
data: TData;
|
|
17
38
|
expires_at: Date;
|
|
18
39
|
id: string;
|
|
19
|
-
|
|
40
|
+
renew_at: Date;
|
|
20
41
|
};
|
|
21
|
-
export type CreatedSession
|
|
22
|
-
|
|
42
|
+
export type CreatedSession = {
|
|
43
|
+
account: AuthAccount;
|
|
44
|
+
session: Session;
|
|
23
45
|
token: string;
|
|
46
|
+
user: AuthUser;
|
|
47
|
+
};
|
|
48
|
+
export type ResolvedSession = {
|
|
49
|
+
account: AuthAccount;
|
|
50
|
+
session: Session;
|
|
51
|
+
user: AuthUser;
|
|
24
52
|
};
|
|
25
|
-
export type
|
|
53
|
+
export type RenewedSession = ResolvedSession & {
|
|
26
54
|
renewed: boolean;
|
|
27
|
-
session: Session<TData>;
|
|
28
55
|
};
|
|
29
|
-
export type CreateSession
|
|
56
|
+
export type CreateSession = {
|
|
30
57
|
account_id: string;
|
|
31
58
|
client: SessionClientInput;
|
|
32
|
-
data: TData;
|
|
33
59
|
};
|
|
34
60
|
export type SessionInput = {
|
|
35
61
|
client: SessionClientInput;
|
|
36
62
|
token: string;
|
|
37
63
|
};
|
|
38
|
-
export type SessionRecord = {
|
|
39
|
-
account_id: string;
|
|
40
|
-
agent: string | null;
|
|
41
|
-
created_at: Date;
|
|
42
|
-
expires_at: Date;
|
|
43
|
-
id: string;
|
|
44
|
-
ip: string | null;
|
|
45
|
-
platform: string | null;
|
|
46
|
-
revoked_at: Date | null;
|
|
47
|
-
token_hash: string;
|
|
48
|
-
updated_at: Date | null;
|
|
49
|
-
};
|
|
50
|
-
export type CreateSessionRecord = Omit<SessionRecord, "revoked_at" | "updated_at">;
|
|
51
|
-
export type ActiveSession = Omit<SessionRecord, "token_hash">;
|
|
52
64
|
export type DbAdapter = {
|
|
53
65
|
create(session: CreateSessionRecord): Promise<void>;
|
|
54
66
|
find(input: {
|
|
@@ -59,6 +71,7 @@ export type DbAdapter = {
|
|
|
59
71
|
account_id: string;
|
|
60
72
|
now: Date;
|
|
61
73
|
}): Promise<SessionRecord[]>;
|
|
74
|
+
findToken(token_hash: string): Promise<AuthSessionRecord | null>;
|
|
62
75
|
revoke(input: {
|
|
63
76
|
revoked_at: Date;
|
|
64
77
|
session_ids: string[];
|
|
@@ -69,40 +82,16 @@ export type DbAdapter = {
|
|
|
69
82
|
updated_at: Date;
|
|
70
83
|
}): Promise<void>;
|
|
71
84
|
};
|
|
72
|
-
export type
|
|
73
|
-
create(input:
|
|
74
|
-
token_hash: string;
|
|
75
|
-
ttl: number;
|
|
76
|
-
value: string;
|
|
77
|
-
}): Promise<void>;
|
|
78
|
-
delete(token_hashes: string[]): Promise<void>;
|
|
79
|
-
exists(token_hashes: string[]): Promise<boolean[]>;
|
|
80
|
-
get(token_hash: string): Promise<string | null>;
|
|
81
|
-
getMany(token_hashes: string[]): Promise<(string | null)[]>;
|
|
82
|
-
keep(input: {
|
|
83
|
-
token_hash: string;
|
|
84
|
-
value: string;
|
|
85
|
-
}): Promise<boolean>;
|
|
86
|
-
update(input: {
|
|
87
|
-
token_hash: string;
|
|
88
|
-
ttl: number;
|
|
89
|
-
value: string;
|
|
90
|
-
}): Promise<boolean>;
|
|
91
|
-
};
|
|
92
|
-
export type SessionService<TData extends object> = {
|
|
93
|
-
create(input: CreateSession<TData>): Promise<CreatedSession<TData>>;
|
|
85
|
+
export type SessionService = {
|
|
86
|
+
create(input: CreateSession): Promise<CreatedSession>;
|
|
94
87
|
list(account_id: string): Promise<ActiveSession[]>;
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
renew(input: SessionInput): Promise<RenewedSession | null>;
|
|
89
|
+
resolve(input: SessionInput): Promise<ResolvedSession | null>;
|
|
97
90
|
revoke(input: {
|
|
98
91
|
account_id: string;
|
|
99
92
|
session_id: string;
|
|
100
93
|
}): Promise<string[]>;
|
|
101
94
|
revokeAccount(account_id: string): Promise<string[]>;
|
|
102
95
|
revokeToken(token: string): Promise<string[]>;
|
|
103
|
-
sync(input: {
|
|
104
|
-
account_id: string;
|
|
105
|
-
data: TData;
|
|
106
|
-
}): Promise<void>;
|
|
107
96
|
};
|
|
108
97
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/session/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,MAAM,MAAM,QAAQ,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE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AM,EAAE,CAAC,CAAC;IAC7E,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gauts/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Framework-agnostic password and server-side session authentication for Node.js.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "GVALFER",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"argon2",
|
|
18
18
|
"bcrypt",
|
|
19
19
|
"hono",
|
|
20
|
-
"
|
|
20
|
+
"nextjs",
|
|
21
21
|
"session"
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
@@ -36,10 +36,6 @@
|
|
|
36
36
|
"types": "./dist/index.d.ts",
|
|
37
37
|
"import": "./dist/index.js"
|
|
38
38
|
},
|
|
39
|
-
"./redis": {
|
|
40
|
-
"types": "./dist/adapters/redis/index.d.ts",
|
|
41
|
-
"import": "./dist/adapters/redis/index.js"
|
|
42
|
-
},
|
|
43
39
|
"./prisma": {
|
|
44
40
|
"types": "./dist/adapters/prisma/index.d.ts",
|
|
45
41
|
"import": "./dist/adapters/prisma/index.js"
|
|
@@ -47,6 +43,10 @@
|
|
|
47
43
|
"./hono": {
|
|
48
44
|
"types": "./dist/adapters/hono/index.d.ts",
|
|
49
45
|
"import": "./dist/adapters/hono/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./next": {
|
|
48
|
+
"types": "./dist/adapters/next/index.d.ts",
|
|
49
|
+
"import": "./dist/adapters/next/index.js"
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"typecheck:example": "npm run build && tsc -p examples/hono/tsconfig.json",
|
|
57
57
|
"lint": "eslint src tests examples",
|
|
58
58
|
"test": "node --import tsx --test tests/**/*.test.ts",
|
|
59
|
-
"test:redis": "node --import tsx --test tests/redis.integration.test.ts",
|
|
60
59
|
"check": "npm run build && npm run lint && npm run typecheck && npm test",
|
|
61
60
|
"prepack": "npm run check"
|
|
62
61
|
},
|
|
@@ -69,13 +68,13 @@
|
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
70
|
"hono": "^4.13.0",
|
|
72
|
-
"
|
|
71
|
+
"next": ">=15.0.0"
|
|
73
72
|
},
|
|
74
73
|
"peerDependenciesMeta": {
|
|
75
74
|
"hono": {
|
|
76
75
|
"optional": true
|
|
77
76
|
},
|
|
78
|
-
"
|
|
77
|
+
"next": {
|
|
79
78
|
"optional": true
|
|
80
79
|
}
|
|
81
80
|
},
|
|
@@ -85,7 +84,7 @@
|
|
|
85
84
|
"eslint": "^9.39.5",
|
|
86
85
|
"globals": "^16.5.0",
|
|
87
86
|
"hono": "^4.13.0",
|
|
88
|
-
"
|
|
87
|
+
"next": "^16.2.12",
|
|
89
88
|
"tsx": "^4.23.0",
|
|
90
89
|
"typescript": "^5.9.3",
|
|
91
90
|
"typescript-eslint": "^8.66.0"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { RedisClientType } from "redis";
|
|
2
|
-
import type { RedisAdapter } from "../../session/types.js";
|
|
3
|
-
export type RedisAdapterConfig = {
|
|
4
|
-
prefix?: string;
|
|
5
|
-
};
|
|
6
|
-
export type RedisAdapterInput = {
|
|
7
|
-
client: RedisClientType;
|
|
8
|
-
config?: RedisAdapterConfig;
|
|
9
|
-
};
|
|
10
|
-
export declare const createRedisAdapter: ({ client, config }: RedisAdapterInput) => RedisAdapter;
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,MAAM,kBAAkB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AAgBF,eAAO,MAAM,kBAAkB,GAAI,oBAAyB,iBAAiB,KAAG,YA4D/E,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createError } from "../../errors.js";
|
|
2
|
-
const getPrefix = (input) => {
|
|
3
|
-
const candidate = input?.trim();
|
|
4
|
-
const prefix = candidate?.length ? candidate : "gauts:auth";
|
|
5
|
-
if (prefix.length > 128 || !/^[A-Za-z0-9:_-]+$/.test(prefix)) {
|
|
6
|
-
throw createError({
|
|
7
|
-
code: "AUTH_CONFIG_INVALID",
|
|
8
|
-
message: "Redis key prefix is invalid.",
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
return prefix.replace(/:+$/g, "");
|
|
12
|
-
};
|
|
13
|
-
export const createRedisAdapter = ({ client, config = {} }) => {
|
|
14
|
-
const prefix = getPrefix(config.prefix);
|
|
15
|
-
const getKey = (token_hash) => `${prefix}:session:${token_hash}`;
|
|
16
|
-
return {
|
|
17
|
-
create: async ({ token_hash, ttl, value }) => {
|
|
18
|
-
const result = await client.set(getKey(token_hash), value, {
|
|
19
|
-
EX: ttl,
|
|
20
|
-
NX: true,
|
|
21
|
-
});
|
|
22
|
-
if (result !== "OK") {
|
|
23
|
-
throw new Error("Redis session key already exists.");
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
get: async (token_hash) => {
|
|
27
|
-
return client.get(getKey(token_hash));
|
|
28
|
-
},
|
|
29
|
-
getMany: async (token_hashes) => {
|
|
30
|
-
return token_hashes.length === 0
|
|
31
|
-
? []
|
|
32
|
-
: client.mGet(token_hashes.map((token_hash) => getKey(token_hash)));
|
|
33
|
-
},
|
|
34
|
-
update: async ({ token_hash, ttl, value }) => {
|
|
35
|
-
const result = await client.set(getKey(token_hash), value, {
|
|
36
|
-
EX: ttl,
|
|
37
|
-
XX: true,
|
|
38
|
-
});
|
|
39
|
-
return result === "OK";
|
|
40
|
-
},
|
|
41
|
-
keep: async ({ token_hash, value }) => {
|
|
42
|
-
const result = await client.set(getKey(token_hash), value, {
|
|
43
|
-
KEEPTTL: true,
|
|
44
|
-
XX: true,
|
|
45
|
-
});
|
|
46
|
-
return result === "OK";
|
|
47
|
-
},
|
|
48
|
-
delete: async (token_hashes) => {
|
|
49
|
-
if (token_hashes.length > 0) {
|
|
50
|
-
await client.del(token_hashes.map((token_hash) => getKey(token_hash)));
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
exists: async (token_hashes) => {
|
|
54
|
-
if (token_hashes.length === 0) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
const values = await client.mGet(token_hashes.map((token_hash) => getKey(token_hash)));
|
|
58
|
-
return values.map((value) => value !== null);
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/redis/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAY9C,MAAM,SAAS,GAAG,CAAC,KAAc,EAAU,EAAE;IACzC,MAAM,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAE5D,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG,I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K,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;QACjD,CAAC;KACJ,CAAC;AACN,CAAC,CAAC"}
|
package/dist/session/schema.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Session, StoredSession } from "./types.js";
|
|
2
|
-
export declare const encodeSession: <TData extends object>(session: StoredSession<TData>) => string;
|
|
3
|
-
export declare const parseSession: <TData extends object>(raw: string) => StoredSession<TData> | null;
|
|
4
|
-
export declare const toSession: <TData extends object>(stored: StoredSession<TData>) => Session<TData>;
|
|
5
|
-
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/session/schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAsBzD,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,MAAM,EAAE,SAAS,aAAa,CAAC,KAAK,CAAC,KAAG,MAUnF,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,KAAK,SAAS,MAAM,EAAE,KAAK,MAAM,KAAG,aAAa,CAAC,KAAK,CAAC,GAAG,IAuBvF,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,KAAK,SAAS,MAAM,EAAE,QAAQ,aAAa,CAAC,KAAK,CAAC,KAAG,OAAO,CAAC,KAAK,CAQ1F,CAAC"}
|
package/dist/session/schema.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { createError } from "../errors.js";
|
|
2
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
-
const isNullableString = (value) => {
|
|
4
|
-
return typeof value === "string" || value === null;
|
|
5
|
-
};
|
|
6
|
-
const isDateString = (value) => {
|
|
7
|
-
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
8
|
-
};
|
|
9
|
-
const isClient = (value) => {
|
|
10
|
-
return (isRecord(value) &&
|
|
11
|
-
isNullableString(value.agent) &&
|
|
12
|
-
isNullableString(value.ip) &&
|
|
13
|
-
isNullableString(value.platform));
|
|
14
|
-
};
|
|
15
|
-
export const encodeSession = (session) => {
|
|
16
|
-
try {
|
|
17
|
-
return JSON.stringify(session);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
throw createError({
|
|
21
|
-
cause: error,
|
|
22
|
-
code: "SESSION_DATA_INVALID",
|
|
23
|
-
message: "Session data must be JSON serializable.",
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export const parseSession = (raw) => {
|
|
28
|
-
let value;
|
|
29
|
-
try {
|
|
30
|
-
value = JSON.parse(raw);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
if (!isRecord(value) ||
|
|
36
|
-
typeof value.id !== "string" ||
|
|
37
|
-
typeof value.account_id !== "string" ||
|
|
38
|
-
!isRecord(value.data) ||
|
|
39
|
-
!isClient(value.client) ||
|
|
40
|
-
!isDateString(value.created_at) ||
|
|
41
|
-
!isDateString(value.touched_at) ||
|
|
42
|
-
!isDateString(value.expires_at)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return value;
|
|
46
|
-
};
|
|
47
|
-
export const toSession = (stored) => ({
|
|
48
|
-
account_id: stored.account_id,
|
|
49
|
-
client: stored.client,
|
|
50
|
-
created_at: new Date(stored.created_at),
|
|
51
|
-
data: stored.data,
|
|
52
|
-
expires_at: new Date(stored.expires_at),
|
|
53
|
-
id: stored.id,
|
|
54
|
-
touched_at: new Date(stored.touched_at),
|
|
55
|
-
});
|
|
56
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/session/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,MA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