@guren/core 1.5.1 → 1.5.2
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.js +11 -20
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -21,22 +21,7 @@ import {
|
|
|
21
21
|
import { Model } from "@guren/orm";
|
|
22
22
|
|
|
23
23
|
// src/store-utils.ts
|
|
24
|
-
|
|
25
|
-
if (value == null) return null;
|
|
26
|
-
if (value instanceof Date) return value;
|
|
27
|
-
if (typeof value === "number") return new Date(value);
|
|
28
|
-
if (typeof value === "string") {
|
|
29
|
-
const date = new Date(/^\d+$/.test(value) ? Number(value) : value);
|
|
30
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
31
|
-
}
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
function isExpired(value, now = Date.now()) {
|
|
35
|
-
const date = toDate(value);
|
|
36
|
-
if (date === null) return true;
|
|
37
|
-
const time = date.getTime();
|
|
38
|
-
return Number.isNaN(time) || time <= now;
|
|
39
|
-
}
|
|
24
|
+
import { isExpired, toDate, toOptionalExpiry } from "@guren/server/support/expiry";
|
|
40
25
|
function decodeJsonColumn(value, fallback) {
|
|
41
26
|
if (typeof value === "string") {
|
|
42
27
|
try {
|
|
@@ -93,17 +78,23 @@ var DatabaseApiTokenStore = class {
|
|
|
93
78
|
// bypass model casts, and cast-based writes would fight drizzle column modes
|
|
94
79
|
// (Date → ISO string breaks timestamp columns; json-stringify double-encodes jsonb).
|
|
95
80
|
deserialize(record) {
|
|
96
|
-
const abilities = record.abilities;
|
|
81
|
+
const abilities = decodeJsonColumn(record.abilities, []);
|
|
97
82
|
return {
|
|
98
83
|
id: String(record.id),
|
|
99
84
|
name: String(record.name),
|
|
100
85
|
hashedToken: String(record.hashedToken),
|
|
101
86
|
userId: typeof record.userId === "bigint" ? record.userId.toString() : record.userId,
|
|
102
87
|
// Corrupt text degrades to no abilities (deny-by-default) instead of
|
|
103
|
-
// throwing on every verification of the affected token.
|
|
104
|
-
|
|
88
|
+
// throwing on every verification of the affected token. A value that
|
|
89
|
+
// decodes to something other than a list of strings degrades the same
|
|
90
|
+
// way: `tokenCan` would otherwise run `String.prototype.includes` on it,
|
|
91
|
+
// so a stored `'"*"'` would grant every ability.
|
|
92
|
+
abilities: Array.isArray(abilities) ? abilities.filter((ability) => typeof ability === "string") : [],
|
|
105
93
|
lastUsedAt: toDate(record.lastUsedAt),
|
|
106
|
-
|
|
94
|
+
// Null means "never expires"; a present-but-unparseable value means a
|
|
95
|
+
// malformed row, which must not read as immortal (`verifyApiToken`
|
|
96
|
+
// skips its expiry check entirely when this is null).
|
|
97
|
+
expiresAt: toOptionalExpiry(record.expiresAt),
|
|
107
98
|
createdAt: toDate(record.createdAt) ?? /* @__PURE__ */ new Date(0)
|
|
108
99
|
};
|
|
109
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"typecheck": "tsc --noEmit"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@guren/cli": "^2.
|
|
64
|
-
"@guren/orm": "^2.2.
|
|
65
|
-
"@guren/server": "^2.
|
|
63
|
+
"@guren/cli": "^2.3.0",
|
|
64
|
+
"@guren/orm": "^2.2.1",
|
|
65
|
+
"@guren/server": "^2.3.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^20.14.10",
|