@guren/core 1.5.0 → 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.d.ts CHANGED
@@ -141,7 +141,7 @@ declare class DatabaseSessionStore implements SessionStore {
141
141
  *
142
142
  * Pass the Drizzle table for your `oauth_states` schema. Column property
143
143
  * names must match `stateHash` (text primary key), `provider`,
144
- * `redirectTo`, and `expiresAt`:
144
+ * `redirectTo`, `expiresAt`, and `binding`:
145
145
  *
146
146
  * ```ts
147
147
  * export const oauthStates = sqliteTable('oauth_states', {
@@ -149,9 +149,14 @@ declare class DatabaseSessionStore implements SessionStore {
149
149
  * provider: text('provider').notNull(),
150
150
  * redirectTo: text('redirect_to'),
151
151
  * expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
152
+ * binding: text('binding'),
152
153
  * })
153
154
  * ```
154
155
  *
156
+ * `binding` is required for `authorize({ bindTo })` to survive the round trip
157
+ * to the provider. Without the column the store cannot persist it, and every
158
+ * bound state comes back unbound.
159
+ *
155
160
  * @example
156
161
  * ```ts
157
162
  * import { createOAuthManager, DatabaseOAuthStateStore } from '@guren/core'
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
- function toDate(value) {
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
- abilities: decodeJsonColumn(abilities, []),
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
- expiresAt: toDate(record.expiresAt),
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
  }
@@ -194,7 +185,9 @@ var DatabaseOAuthStateStore = class {
194
185
  stateHash,
195
186
  provider: payload.provider,
196
187
  redirectTo: payload.redirectTo ?? null,
197
- expiresAt: payload.expiresAt
188
+ expiresAt: payload.expiresAt,
189
+ // Persisted, not derived: an unbound state verifies for any browser.
190
+ binding: payload.binding ?? null
198
191
  });
199
192
  }
200
193
  async find(stateHash) {
@@ -267,7 +260,8 @@ function mapRecordToPayload(record) {
267
260
  provider: String(record.provider),
268
261
  redirectTo: record.redirectTo == null ? void 0 : String(record.redirectTo),
269
262
  // fetchLive's isExpired check guarantees this parses.
270
- expiresAt: toDate(record.expiresAt)
263
+ expiresAt: toDate(record.expiresAt),
264
+ binding: record.binding == null ? void 0 : String(record.binding)
271
265
  };
272
266
  }
273
267
  function deleteRemovedRow(result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/core",
3
- "version": "1.5.0",
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.0.0",
64
- "@guren/orm": "^2.0.0",
65
- "@guren/server": "^2.0.0"
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",